linux/drivers/hv/connection.c
<<
>>
Prefs
   1/*
   2 *
   3 * Copyright (c) 2009, Microsoft Corporation.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms and conditions of the GNU General Public License,
   7 * version 2, as published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  12 * more details.
  13 *
  14 * You should have received a copy of the GNU General Public License along with
  15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16 * Place - Suite 330, Boston, MA 02111-1307 USA.
  17 *
  18 * Authors:
  19 *   Haiyang Zhang <haiyangz@microsoft.com>
  20 *   Hank Janssen  <hjanssen@microsoft.com>
  21 *
  22 */
  23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24
  25#include <linux/kernel.h>
  26#include <linux/sched.h>
  27#include <linux/wait.h>
  28#include <linux/delay.h>
  29#include <linux/mm.h>
  30#include <linux/slab.h>
  31#include <linux/vmalloc.h>
  32#include <linux/hyperv.h>
  33#include <asm/hyperv.h>
  34#include "hyperv_vmbus.h"
  35
  36
  37struct vmbus_connection vmbus_connection = {
  38        .conn_state             = DISCONNECTED,
  39        .next_gpadl_handle      = ATOMIC_INIT(0xE1E10),
  40};
  41
  42/*
  43 * vmbus_connect - Sends a connect request on the partition service connection
  44 */
  45int vmbus_connect(void)
  46{
  47        int ret = 0;
  48        int t;
  49        struct vmbus_channel_msginfo *msginfo = NULL;
  50        struct vmbus_channel_initiate_contact *msg;
  51        unsigned long flags;
  52
  53        /* Initialize the vmbus connection */
  54        vmbus_connection.conn_state = CONNECTING;
  55        vmbus_connection.work_queue = create_workqueue("hv_vmbus_con");
  56        if (!vmbus_connection.work_queue) {
  57                ret = -ENOMEM;
  58                goto cleanup;
  59        }
  60
  61        INIT_LIST_HEAD(&vmbus_connection.chn_msg_list);
  62        spin_lock_init(&vmbus_connection.channelmsg_lock);
  63
  64        INIT_LIST_HEAD(&vmbus_connection.chn_list);
  65        spin_lock_init(&vmbus_connection.channel_lock);
  66
  67        /*
  68         * Setup the vmbus event connection for channel interrupt
  69         * abstraction stuff
  70         */
  71        vmbus_connection.int_page =
  72        (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, 0);
  73        if (vmbus_connection.int_page == NULL) {
  74                ret = -ENOMEM;
  75                goto cleanup;
  76        }
  77
  78        vmbus_connection.recv_int_page = vmbus_connection.int_page;
  79        vmbus_connection.send_int_page =
  80                (void *)((unsigned long)vmbus_connection.int_page +
  81                        (PAGE_SIZE >> 1));
  82
  83        /*
  84         * Setup the monitor notification facility. The 1st page for
  85         * parent->child and the 2nd page for child->parent
  86         */
          84nnection.c">
	    send_int_page =

  72        (void *)__get_free_pages(GFP_KERNEL|PAGE_SIZE >> 1));
  73        if (vL84">  84nnection.c">
	    int_page == NULL) {9  74                ret = -ENOMEM;9  75                goto cleanup;9  76        }9  639vmbus_channel_msginfo *int_page +9  50        struct ATOMIC_INIT(0xE1E10),9__get_free_pages(PAGE_SIZE >> 1));9hannel_msginfo *int_page == NULL) {9
  74                ret = -ENOMEM;9
  75                goto cleanup;10  76        }10  4110spinhannel_msginfo *vmaitommenction.PAGE_SIZE >> 1));10  6310  50        struct   72hannel_msginfo *vitiate_contact *msg;10  3510v>
  erate_contact>
  ertion" class="sref">vLsg onsate_contact *< onsconn_state" class="srefHANde=MSGde=ATIATE_CONTACa>      = msg;10vnel_in">   7<_ * vmbuedcode=vmbus_channel_in">   7<_ * vmbuedconn_state" class="sreVMBUS_REVISION_NUMBERcode=vmbus_chanVMBUS_REVISION_NUMBERa href="+code=msg" class="sref">msg;10vvmbus eves_connection.rirt_to_phyction.c">
	    _d *)((unsigned long)vmbus_connection.PAGE_SIZE >> 1));10vimg src="../1ate_contact mg src="../1nt_page" class="sref">rirt_to_phyction.c">
	    _d *)((unsigned long)vL84">  84nnection.c">
	    PAGE_SIZE >> 1));1
vimg src="../2tion.c">
	    rirt_to_phyction.c">
	    PAGE_SIZE >> 1));1
  80                (void *)((unsigned long)vL84">  84nnection.c">
	    int_page +1
  74                   (PAGE_SIZE >> 1));1
  631
  83        /*1
  1we "+cont">  * vmbussinc 1we may/a>        /*1
  *spocopybef>  1n="ajaing from5">  1routcon/a>        /*1
         */1
spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZE >> 1));1
< unsigned long ="+c_add_/a>spinhannel_msginfo *v hr="+camerymsginfo *INIT_LIST_HEAD(&vmbus_connection.chn_msg_list);1
  4112 un=spin_rq *ssrcion.spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZE >> 1));1
  631
spin_lock_    _hanate_contact_lock_    _hanages" class="sref">_hanate_contact *
<  50        struct PAGE_SIZE >> 1));1
NULL) {1
  57+code=spin_rqsavion.spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZENULL) {1
  74="+c_de< unsigned long ="+c_despinhannel_msginfo *v hr="+camerymsginfo *PAGE_SIZENULL) {1
 un=spin_rq *ssrcion.spin_lock_init(&vmbus_connection. * more details.
<  51        unsigned long PAGE_SIZENULL) {1
  75                goto cleanup;1
  76        }1
  631
  83< Wait* part"> ">          *spocopy*/a>         */1
spinhannel_msginfo *vmaitommenction.vmbus_cHZction.PAGE_SIZENULL) {1
NULL) {1
  57+code=spin_rqsavion.spin_lock_init(&vmbus_connection.NULL) {1
  51        unsigned long PAGE_SIZENULL) {1
spinhannel_msginfo *v hr="+camerymsginfo *PAGE_SIZENULL) {1
  7462"> un=spin_rq *ssrcion.spin_lock_init(&vmbus_connection. * more details.

  51        unsigned long PAGE_SIZENULL) {1
  74                      = cleanup;1
  75                goto cleanup;1
  76        }1
  351
spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZENULL) {1
spinhannel_msginfo *v hr="+camerymsginfo *PAGE_SIZENULL) {1
spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZENULL) {1
PAGE_SIZENULL) {1
  83< Checks="lsuccessfuly*/a>         */1
hannel_msginfo *v *spocop>                spocoption" class="sref">v">   7<_ *spocop>              ">   7<_ *spocoption" class="sref">v">   7<_supporuedcode=vmbus_chann>   7<_supporuedef="s"+code=NULL" class="sref">NULL) {1
  7454">  54        vmbus_connection.conn        = PAGE_SIZENULL) {1
NULL) {1
  74pr_errate_contactpr_errages" class="sref">create_workquUnablment"f">NULL,ME NULL) {1
create_workquV>   7< %dmmen supporuedcommHs/hv-V\an class="stri,s="comment"> * more details.

  74VMBUS_REVISION_NUMBERcode=vmbus_chanVMBUS_REVISION_NUMBERa hrss="sref">PAGE_SIZENULL) {1
  57                PAGE_SIZENULL) {1
  58                goto cleanup;1
  59        }1
  601
_hannel_msginfo *cleanup;1
ret = 0;1
  631
  58                goto   631
  54        vmbus_connection.ret = 0;1
  661
 56        if (!vmbus_connection.  661
  74d*ssroyk_queue = _ 56        if (!vmbus_connection.ret = 0;1
PAGE_SIZENULL) {1
 56        if (!vmbus_connection.NULL) {1
  51        (void *)  80                (void *)((unsigned long)vmbus_connection.__GFP_ZERO, 0);1
  7454">  54        vmbus_connection.msginfo = NULL;1
  59        }1
  241
  73        if (vL84">  84nnection.c">
	    NULL) {1
  51        (void *)  80                (void *)((unsigned long)vL84">  84nnection.c">
	    PAGE_SIZE >> 1));1
  57  73        if (vL84">  84nnection.c">
	    msginfo = NULL;1
  59        }1
PAGE_SIZENULL) {1
_hannel_msginfo *cleanup;1
  411
  57                cleanup;1
  59        }1
  241
  351
/*1
 "up the obj>/* gassn its/a>        /*1
 "up the id)/a>        /*1
         */19  50        if (vmbus_cn=lid2tup the>                lid2tup theages" class="sref">_u32tion.c">
	    vmbus_cn=lid>                lidwork_6" class="line" name="L66">  6619NULL) {19  50        if (vmbus_c       if (cleanup;19  50        if (vmbus_cfound        if (msginfo = NULL;19  51        unsigned long flags;19  3519spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZENULL) {19 *_       if (INIT_LIST_HEAD(&vmbus_connection.  51  ="+camerymsginfo *NULL) {19
       if (vofferhanate_contactofferhantion" class="sref">vmb="c_n=lid>              mb="c_n=lidnt_paggmsginfo" class="n=lid>                lidwork_"+code=NULL" class="sref">NULL) {19  51   ound        if (cleanup;20cleanup;201a href=2ddrivers/hv/connection.c20180"20d="L81" class="line" ="line" name="L59">  59        }20  76        }20spin_lock_init(&vmbus_connection.  51        unsigned long PAGE_SIZENULL) {20  2420  57 ound        if (PAGE_SIZENULL) {206a href=20drivers/hv/connection.c20680"2L6="L6="line" name="L76">  76        }207a href=20drivers/hv/connection.c20780"20d="L77" class="line" name="L77">  7720/*20      /a>        /*2
         */2
  74process_hrefommenate_contactprocess_hrefommenages" class="sref">_u32tion.c">
	    vmbus_cn=lid>                lidwork_6" class="line" name="L66">  662
NULL) {2
  50        if (vmbus_cf      if (cleanup;2
  51        unsigned long flags;2
  352
/*2
 oup the bas" n_conn  1r lidommeninvokesnt">/a>        /*2
  68 ommenag>        /*2
  69         */2<_n=lid>                lidwork_+code=flags" class="sref">flags;2
  4122 f      if (NULL) {2
  74pr_errate_contactpr_errages" class="sref">create_workquoup the men found* parr lido- %u\an class="stri,2="sref">vmbus_cn=lid>                lidwork_+code=flags" class="sref">flags;2
flags;2
  76        }2
  662
  67        /*2
  68   +came omme wheconner>/a>        /*2
  69 device. An un=sading class=/a>        /*2<  70< setsnt"> onc"+code=callbackent" /a>        /*2
  85/* oup the inbound chanp thus, ouecking/a>        /*2
  69 dlass= spect">  callbackenakesncar> oomment">         * abstraction stuff2
  69  abstr.mment">         * abstraction stuff2
  84         */2
  352
spin       if (vinbound channection.  51        unsigned long PAGE_SIZENULL) {2
       if (vonc"+code=callbackate_contactonc"+code=callback="L79!t_page" class="sref">int_page == PAGE_SIZENULL) {2
       if (vonc"+code=callbackate_contactonc"+code=callback="L7ine" name="L73">       if (vc"+code=callbackmbustexnnection.PAGE_SIZENULL) {2
PAGE_SIZENULL) {2
  74pr_errate_contactpr_errages" class="sref">create_workquno oup the callbacke parr lido- %u\an class="stri,2="sref">vmbus_cn=lid>                lidwork_+code=flags" class="sref">flags;2
  412
 un=spin_rq *ssrcion.spin       if (vinbound channection.  51        unsigned long PAGE_SIZENULL) {2
  59        }2
  242
/*2
        /*2
         */2
  74ass="_oefommenif (  51  dataif (PAGE_SIZENULL) {2
NULL) {2

	    vmbus_cdwordif (flags;2

	    vmbus_cmaxdwordif (flags;2
  5binif (flags;2

	    vmbus_cn=lid>                lidwork+code=flags" class="sref">flags;2

	    vmbus_cn=us_connection.recv_int_page = vn=us_connection.flags;2
  352
         */2
 n=us_connection.PAGE_SIZENULL) {2
flags;2
dwordif (vmbus_cdwordif (vmbus_cmaxdwordif (vmbus_cdwordif (NULL) {2
 n=us_connection.vmbus_cdwordif (PAGE_SIZENULL) {2
flags;2
binif (vmbus_cbinif (vmbus_cbinif (NULL) {2
binif ( * more details.2
spinn=us_connection.vmbus_cdwordif (NULL) {2
vmbus_cn=lid>                lidworkef=(="sref">vmbus_cdwordif (  5binif (flags;2
  662
  662
/*2
  6999999999999999999999999999999999* Spectae case -lass="/a>        /*2
  7099999999999999999999999999999999* oup the arotocol hanti>        /*2
  8599999999999999999999999999999999*/a>         */2
flags;2
  632
  74process_hrefommenate_contactprocess_hrefommenages" class="sref">_n=lid>                lidwork_+code=flags" class="sref">flags;2
  59        }2
  59        }2
  59        }2
  59        }2
PAGE_SIZENULL) {2
/*2
/*2
         */2
  5_lock_    _hanate_contact_lock_    _hanages"ame="L name="L50">  5bufferif (  51  size_nif (vmbus_cbuflea> = PAGE_SIZENULL) {2
NULL) {2
vmbus_chvmbus_connec_id>              hvmbus_connec_id="L72="sref">vmbus_cbus__id>              bus__idef="+code=flags" class="sref">flags;2
  5                ret = 0;2
  5
	    <ret = 0;2
ret = 0;2
vasu32tion.c">
	    ret = 0;29vution.c">
	    vid>              id="L62queue" class="sreVMBUS_MESSef="code=DIION_I       = flags;29  4129/*29  69         * abstraction stuff29  84 oper     ="cooupl> oomment">         * abstraction stuff29         * abstraction stuff29         */29 i="line" name="L
	    <NULL) {29
  5                vmbus_chvm    _hessv_i>              hvm    _hessv_i="L7ine" name="L73"> us__id>              bus__idef=", 1, L51">  51  bufferif (  51  buflea> = flags;29PAGE_SIZENULL) {30  57                cleanup;301a href=3ddrivers/hv/connection.c30180"30d="L81" class="line" ="line" name="L
	    <cleanup;302a href=3ddrivers/hv/connection.c30280"302="L81" class="line" name="L74">  74mslee         goto __GFP_ZERO, 0);30  59        }30  57                cleanup;305a href=30drivers/hv/connection.c30580"30d="L7="line" name="L59">  59        }306a href=30drivers/hv/connection.c30680"30d="L66" class="line" name="L66">  66307a href=30drivers/hv/connection.c30780"30d="L17" class="line" name="7        /*30      ent"t"> parmenag>        /*30         */3
  5_lock_setfommenate_contact_lock_setfommen="L7ine" name="L73">u32tion.c">
	    vmbus_cmb="c_n=lid>              mb="c_n=lidnt_p=="sref">PAGE_SIZENULL) {3
NULL) {3
         */3
 b="c_n=lid>              mb="c_n=lidnt_pat" cl"31,s="comment"> * more details.3
recv_int_page = vsmed_connection. * more details.3
5a href=3"drivers/hv/connection.c3#L15"31d="L65" classssssssssine" name="L73"> b="c_n=lid>              mb="c_n=lidnt_pat_SIZE" c5)ERO" class="sref">__GFP_ZERO, 0);3
  663
  57hvmlinealfommenate_contacthvmlinealfommen="L7iERO" class="sref">__GFP_ZERO, 0);3
  59        }3



9/div>


T"> origieal LXR softwar> bynt"> line" namhttp://sourcef> ge.net/proj>/*s/lxri>LXR e" nunitynel_, nn  1experinameal L59"   ebynline" nammailto:lxr@/coux.no">lxr@/coux.notion"
9/div>

lxr./coux.no kindly h   edcommline" namhttp://www.redpill-/copro.no">Redpill Lcopro ASnel_, providernof Lcoux bussulting amenoper     s services sinc 11995.
9/div>