win-pvdrivers

changeset 23:e4f0a0a21488

xennet: flesh out initialization more

move code from xennet_init to backendstatehandler
properly report connected state to ndis
copy perm mac addr to curr mac addr
author Andy Grover <andy@groveronline.com>
date Fri Nov 30 11:45:00 2007 -0800 (2007-11-30)
parents 2e1ad5552529
children bc0ea67acebb
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Fri Nov 30 10:21:12 2007 -0800
     1.2 +++ b/xennet/xennet.c	Fri Nov 30 11:45:00 2007 -0800
     1.3 @@ -43,6 +43,7 @@ struct xennet_info
     1.4    WCHAR name[NAME_SIZE];
     1.5    NDIS_HANDLE adapter_handle;
     1.6    ULONG packet_filter;
     1.7 +  int connected;
     1.8    UINT8 perm_mac_addr[ETH_ALEN];
     1.9    UINT8 curr_mac_addr[ETH_ALEN];
    1.10  
    1.11 @@ -162,6 +163,10 @@ XenNet_BackEndStateHandler(char *Path, P
    1.12    struct xennet_info *xi = Data;
    1.13    char *Value;
    1.14    int be_state;
    1.15 +  char TmpPath[128];
    1.16 +  xenbus_transaction_t xbt = 0;
    1.17 +  int retry = 0;
    1.18 +  char *err;
    1.19  
    1.20    xi->XenBusInterface.Read(xi->XenBusInterface.InterfaceHeader.Context,
    1.21      XBT_NIL, Path, &Value);
    1.22 @@ -181,9 +186,101 @@ XenNet_BackEndStateHandler(char *Path, P
    1.23    case XenbusStateInitWait:
    1.24      KdPrint((__DRIVER_NAME "     Backend State Changed to InitWait\n"));  
    1.25  
    1.26 -    /* do stuff here */
    1.27 +    xi->event_channel = xi->EvtChnInterface.AllocUnbound(
    1.28 +      xi->EvtChnInterface.InterfaceHeader.Context, 0);  
    1.29 +    xi->EvtChnInterface.Bind(xi->EvtChnInterface.InterfaceHeader.Context,
    1.30 +      xi->event_channel, XenNet_Interrupt, xi);
    1.31 +
    1.32 +    /* TODO: must free pages in MDL as well as MDL using MmFreePagesFromMdl and ExFreePool */
    1.33 +    // or, allocate mem and then get mdl, then free mdl
    1.34 +    xi->tx_mdl = AllocatePage();
    1.35 +    xi->tx_pgs = MmMapLockedPagesSpecifyCache(xi->tx_mdl, KernelMode, MmNonCached,
    1.36 +      NULL, FALSE, NormalPagePriority);
    1.37 +    SHARED_RING_INIT(xi->tx_pgs);
    1.38 +    FRONT_RING_INIT(&xi->tx, xi->tx_pgs, PAGE_SIZE);
    1.39 +    xi->tx_ring_ref = xi->GntTblInterface.GrantAccess(
    1.40 +      xi->GntTblInterface.InterfaceHeader.Context, 0,
    1.41 +      *MmGetMdlPfnArray(xi->tx_mdl), FALSE);
    1.42 +
    1.43 +    xi->rx_mdl = AllocatePage();
    1.44 +    xi->rx_pgs = MmMapLockedPagesSpecifyCache(xi->rx_mdl, KernelMode, MmNonCached,
    1.45 +      NULL, FALSE, NormalPagePriority);
    1.46 +    SHARED_RING_INIT(xi->rx_pgs);
    1.47 +    FRONT_RING_INIT(&xi->rx, xi->rx_pgs, PAGE_SIZE);
    1.48 +    xi->rx_ring_ref = xi->GntTblInterface.GrantAccess(
    1.49 +      xi->GntTblInterface.InterfaceHeader.Context, 0,
    1.50 +      *MmGetMdlPfnArray(xi->rx_mdl), FALSE);
    1.51 +
    1.52 +    xi->XenBusInterface.StartTransaction(xi->XenBusInterface.InterfaceHeader.Context,
    1.53 +      &xbt);
    1.54 +
    1.55 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/tx-ring-ref", xi->Path);
    1.56 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.57 +      XBT_NIL, TmpPath, "%d", xi->tx_ring_ref);
    1.58 +    if (err)
    1.59 +      goto trouble;
    1.60 +
    1.61 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/rx-ring-ref", xi->Path);
    1.62 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.63 +      XBT_NIL, TmpPath, "%d", xi->rx_ring_ref);
    1.64 +    if (err)
    1.65 +      goto trouble;
    1.66 +
    1.67 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/event-channel", xi->Path);
    1.68 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.69 +      XBT_NIL, TmpPath, "%d", xi->event_channel);
    1.70 +    if (err)
    1.71 +      goto trouble;
    1.72 +
    1.73 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/request-rx-copy", xi->Path);
    1.74 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.75 +      XBT_NIL, TmpPath, "%d", 1);
    1.76 +    if (err)
    1.77 +      goto trouble;
    1.78 +
    1.79 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/feature-rx-notify",
    1.80 +      xi->Path);
    1.81 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.82 +      XBT_NIL, TmpPath, "%d", 1);
    1.83 +    if (err)
    1.84 +      goto trouble;
    1.85 +
    1.86 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
    1.87 +      "%s/feature-no-csum-offload", xi->Path);
    1.88 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.89 +      XBT_NIL, TmpPath, "%d", 1);
    1.90 +    if (err)
    1.91 +      goto trouble;
    1.92 +
    1.93 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
    1.94 +      "%s/feature-sg", xi->Path);
    1.95 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
    1.96 +      XBT_NIL, TmpPath, "%d", 0);
    1.97 +    if (err)
    1.98 +      goto trouble;
    1.99 +
   1.100 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
   1.101 +      "%s/feature-gso-tcpv4", xi->Path);
   1.102 +    err = xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
   1.103 +      XBT_NIL, TmpPath, "%d", 0);
   1.104 +    if (err)
   1.105 +      goto trouble;
   1.106 +
   1.107 +    /* commit transaction */
   1.108 +    xi->XenBusInterface.EndTransaction(xi->XenBusInterface.InterfaceHeader.Context,
   1.109 +      xbt, 0, &retry);
   1.110 +
   1.111 +    /* TODO: prepare tx and rx rings */
   1.112  
   1.113      KdPrint((__DRIVER_NAME "     Set Frontend state to Initialised\n"));
   1.114 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->Path);
   1.115 +    xi->XenBusInterface.Printf(xi->XenBusInterface.InterfaceHeader.Context,
   1.116 +      XBT_NIL, TmpPath, "%d", XenbusStateInitialised);
   1.117 +
   1.118 +    /* send fake arp? */
   1.119 +
   1.120 +    xi->connected = TRUE;
   1.121 +
   1.122      break;
   1.123  
   1.124    case XenbusStateInitialised:
   1.125 @@ -212,6 +309,11 @@ XenNet_BackEndStateHandler(char *Path, P
   1.126      break;
   1.127    }
   1.128  
   1.129 +trouble:
   1.130 +  KdPrint((__DRIVER_NAME __FUNCTION__ ": Should never happen!\n"));
   1.131 +  xi->XenBusInterface.EndTransaction(xi->XenBusInterface.InterfaceHeader.Context,
   1.132 +    xbt, 1, &retry);
   1.133 +
   1.134  }
   1.135  
   1.136  
   1.137 @@ -343,31 +445,6 @@ XenNet_Init(
   1.138      goto err;
   1.139    }
   1.140  
   1.141 -  xi->event_channel = xi->EvtChnInterface.AllocUnbound(
   1.142 -    xi->EvtChnInterface.InterfaceHeader.Context, 0);  
   1.143 -  xi->EvtChnInterface.Bind(xi->EvtChnInterface.InterfaceHeader.Context,
   1.144 -    xi->event_channel, XenNet_Interrupt, xi);
   1.145 -
   1.146 -  /* TODO: must free pages in MDL as well as MDL using MmFreePagesFromMdl and ExFreePool */
   1.147 -  // or, allocate mem and then get mdl, then free mdl
   1.148 -  xi->tx_mdl = AllocatePage();
   1.149 -  xi->tx_pgs = MmMapLockedPagesSpecifyCache(xi->tx_mdl, KernelMode, MmNonCached,
   1.150 -    NULL, FALSE, NormalPagePriority);
   1.151 -  SHARED_RING_INIT(xi->tx_pgs);
   1.152 -  FRONT_RING_INIT(&xi->tx, xi->tx_pgs, PAGE_SIZE);
   1.153 -  xi->tx_ring_ref = xi->GntTblInterface.GrantAccess(
   1.154 -    xi->GntTblInterface.InterfaceHeader.Context, 0,
   1.155 -    *MmGetMdlPfnArray(xi->tx_mdl), FALSE);
   1.156 - 
   1.157 -  xi->rx_mdl = AllocatePage();
   1.158 -  xi->rx_pgs = MmMapLockedPagesSpecifyCache(xi->rx_mdl, KernelMode, MmNonCached,
   1.159 -    NULL, FALSE, NormalPagePriority);
   1.160 -  SHARED_RING_INIT(xi->rx_pgs);
   1.161 -  FRONT_RING_INIT(&xi->rx, xi->rx_pgs, PAGE_SIZE);
   1.162 -  xi->rx_ring_ref = xi->GntTblInterface.GrantAccess(
   1.163 -    xi->GntTblInterface.InterfaceHeader.Context, 0,
   1.164 -    *MmGetMdlPfnArray(xi->rx_mdl), FALSE);
   1.165 -
   1.166    msg = xi->XenBusInterface.List(xi->EvtChnInterface.InterfaceHeader.Context,
   1.167      XBT_NIL, "device/vif", &vif_devs);
   1.168    if (msg)
   1.169 @@ -405,8 +482,7 @@ XenNet_Init(
   1.170      ExFreePool(Value);
   1.171  
   1.172      /* Add watch on backend state */
   1.173 -    RtlStringCbCopyA(TmpPath, ARRAY_SIZE(TmpPath), xi->BackendPath);
   1.174 -    RtlStringCbCatA(TmpPath, ARRAY_SIZE(TmpPath), "/state");
   1.175 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   1.176      xi->XenBusInterface.AddWatch(xi->XenBusInterface.InterfaceHeader.Context,
   1.177        XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   1.178  
   1.179 @@ -436,6 +512,7 @@ XenNet_Init(
   1.180          }
   1.181          s = e + 1;
   1.182        }
   1.183 +      memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   1.184      }
   1.185      ExFreePool(Value);
   1.186  
   1.187 @@ -559,8 +636,10 @@ XenNet_QueryInformation(
   1.188          NDIS_MAC_OPTION_NO_LOOPBACK;
   1.189        break;
   1.190      case OID_GEN_MEDIA_CONNECT_STATUS:
   1.191 -      /* how can we not be connected?? */
   1.192 -      temp_data = NdisMediaStateConnected;
   1.193 +      if (xi->connected)
   1.194 +        temp_data = NdisMediaStateConnected;
   1.195 +      else
   1.196 +        temp_data = NdisMediaStateDisconnected;
   1.197        break;
   1.198      case OID_GEN_MAXIMUM_SEND_PACKETS:
   1.199        temp_data = XN_MAX_SEND_PKTS;