win-pvdrivers

changeset 185:e13475347e4a

Merge with head
author James Harper <james.harper@bendigoit.com.au>
date Wed Feb 13 23:27:00 2008 +1100 (2008-02-13)
parents 524ffdb246b6 f2774dbb6257
children 145b318c367c
files xenhide/xenhide.c
line diff
     1.1 --- a/common/include/public/io/netif.h	Wed Feb 13 23:25:32 2008 +1100
     1.2 +++ b/common/include/public/io/netif.h	Wed Feb 13 23:27:00 2008 +1100
     1.3 @@ -154,7 +154,7 @@ struct netif_rx_response {
     1.4      uint16_t id;
     1.5      uint16_t offset;       /* Offset in page of start of received packet  */
     1.6      uint16_t flags;        /* NETRXF_* */
     1.7 -    int16_t  status;       /* -ve: BLKIF_RSP_* ; +ve: Rx'ed pkt size. */
     1.8 +    int16_t  status;       /* -ve: NETIF_RSP_* ; +ve: Rx'ed pkt size. */
     1.9  };
    1.10  typedef struct netif_rx_response netif_rx_response_t;
    1.11  
     2.1 --- a/xennet/xennet.c	Wed Feb 13 23:25:32 2008 +1100
     2.2 +++ b/xennet/xennet.c	Wed Feb 13 23:27:00 2008 +1100
     2.3 @@ -84,7 +84,6 @@ struct xennet_info
     2.4  
     2.5    LIST_ENTRY tx_waiting_pkt_list;
     2.6    LIST_ENTRY rx_free_buf_list;
     2.7 -  LIST_ENTRY rx_free_pkt_list;
     2.8  
     2.9    struct netif_tx_front_ring tx;
    2.10    struct netif_rx_front_ring rx;
    2.11 @@ -312,6 +311,8 @@ XenNet_RxBufferAlloc(struct xennet_info 
    2.12    grant_ref_t ref;
    2.13    netif_rx_request_t *req;
    2.14    PLIST_ENTRY entry;
    2.15 +  buffer_entry_t *buffer_entry;
    2.16 +  NDIS_STATUS status;
    2.17  
    2.18  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.19  
    2.20 @@ -319,11 +320,27 @@ XenNet_RxBufferAlloc(struct xennet_info 
    2.21  
    2.22    for (i = 0; i < batch_target; i++)
    2.23    {
    2.24 +    /* reuse entries off the free buffer list, unless it's exhausted */
    2.25      entry = RemoveHeadList(&xi->rx_free_buf_list);
    2.26 -    if (entry == &xi->rx_free_buf_list)
    2.27 -      break;
    2.28 -    buffer = CONTAINING_RECORD(entry, buffer_entry_t, entry)->buffer;
    2.29 -    
    2.30 +    if (entry != &xi->rx_free_buf_list)
    2.31 +    {
    2.32 +      buffer = CONTAINING_RECORD(entry, buffer_entry_t, entry)->buffer;
    2.33 +    }
    2.34 +    else
    2.35 +    {
    2.36 +      status = NdisAllocateMemoryWithTag(&buffer_entry,
    2.37 +        sizeof(buffer_entry_t), XENNET_POOL_TAG);
    2.38 +      if (status != NDIS_STATUS_SUCCESS)
    2.39 +      {
    2.40 +        KdPrint(("NdisAllocateMemoryWithTag Failed! status = 0x%x\n", status));
    2.41 +        break;
    2.42 +      }
    2.43 +      NdisAllocateBuffer(&status, &buffer_entry->buffer, xi->buffer_pool,
    2.44 +        buffer_entry, sizeof(buffer_entry->data));
    2.45 +      ASSERT(status == NDIS_STATUS_SUCCESS); // should never fail
    2.46 +      buffer = buffer_entry->buffer;
    2.47 +    }
    2.48 +
    2.49      /* Give to netback */
    2.50      id = (unsigned short)(req_prod + i) & (NET_RX_RING_SIZE - 1);
    2.51      ASSERT(!xi->rx_buffers[id]);
    2.52 @@ -360,7 +377,6 @@ XenNet_RxBufferFree(struct xennet_info *
    2.53    int i;
    2.54    grant_ref_t ref;
    2.55    PNDIS_BUFFER buffer;
    2.56 -  PNDIS_PACKET packet;
    2.57    KIRQL OldIrql;
    2.58    PVOID buff_va;
    2.59    PLIST_ENTRY entry;
    2.60 @@ -399,12 +415,6 @@ XenNet_RxBufferFree(struct xennet_info *
    2.61      NdisFreeMemory(buff_va, 0, 0); // <= DISPATCH_LEVEL
    2.62    }
    2.63  
    2.64 -  while ((entry = RemoveHeadList(&xi->rx_free_pkt_list)) != &xi->rx_free_pkt_list)
    2.65 -  {
    2.66 -    packet = CONTAINING_RECORD(entry, NDIS_PACKET, MiniportReservedEx[sizeof(PVOID)]);
    2.67 -    NdisFreePacket(packet);
    2.68 -  }
    2.69 -
    2.70    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
    2.71  }
    2.72  
    2.73 @@ -416,16 +426,10 @@ XenNet_ReturnPacket(
    2.74  {
    2.75    struct xennet_info *xi = MiniportAdapterContext;
    2.76    PNDIS_BUFFER buffer;
    2.77 -//  PNDIS_BUFFER next_buffer;
    2.78 -  // PVOID buff_va;
    2.79 -  // UINT buff_len;
    2.80 -  UINT tot_buff_len;
    2.81    buffer_entry_t *buffer_entry;
    2.82  
    2.83  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.84  
    2.85 -  NdisQueryPacketLength(Packet, &tot_buff_len);
    2.86 -
    2.87    NdisUnchainBufferAtBack(Packet, &buffer);
    2.88    while (buffer)
    2.89    {
    2.90 @@ -435,8 +439,7 @@ XenNet_ReturnPacket(
    2.91      NdisUnchainBufferAtBack(Packet, &buffer);
    2.92    }
    2.93  
    2.94 -  NdisReinitializePacket(Packet);
    2.95 -  InsertTailList(&xi->rx_free_pkt_list, (PLIST_ENTRY)&Packet->MiniportReservedEx[sizeof(PVOID)]);
    2.96 +  NdisFreePacket(Packet);
    2.97    
    2.98    InterlockedDecrement(&xi->rx_outstanding);
    2.99  
   2.100 @@ -452,15 +455,14 @@ static NDIS_STATUS
   2.101  XenNet_RxBufferCheck(struct xennet_info *xi)
   2.102  {
   2.103    RING_IDX cons, prod;
   2.104 -  PLIST_ENTRY entry;
   2.105    PNDIS_PACKET packet = NULL;
   2.106    PNDIS_BUFFER buffer;
   2.107    int moretodo;
   2.108    KIRQL OldIrql;
   2.109    struct netif_rx_response *rxrsp = NULL;
   2.110    int more_frags = 0;
   2.111 -  UINT length;
   2.112 -
   2.113 +  NDIS_STATUS status;
   2.114 +  
   2.115  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.116  
   2.117    ASSERT(xi->connected);
   2.118 @@ -472,34 +474,31 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.119      KeMemoryBarrier(); /* Ensure we see responses up to 'rp'. */
   2.120  
   2.121      for (cons = xi->rx.rsp_cons; cons != prod; cons++) {
   2.122 +
   2.123        rxrsp = RING_GET_RESPONSE(&xi->rx, cons);
   2.124 -      ASSERT(rxrsp->status > 0);
   2.125 +      if (rxrsp->status <= 0
   2.126 +        || rxrsp->offset + rxrsp->status > PAGE_SIZE)
   2.127 +      {
   2.128 +        KdPrint((__DRIVER_NAME ": Error: rxrsp offset %d, size %d\n",
   2.129 +          rxrsp->offset, rxrsp->status));
   2.130 +        continue;
   2.131 +      }
   2.132  
   2.133        if (!more_frags) // handling the packet's 1st buffer
   2.134        {
   2.135 -        entry = RemoveHeadList(&xi->rx_free_pkt_list);
   2.136 -        ASSERT(entry != &xi->rx_free_pkt_list);
   2.137 -        packet = CONTAINING_RECORD(entry, NDIS_PACKET, MiniportReservedEx[sizeof(PVOID)]);
   2.138 +        NdisAllocatePacket(&status, &packet, xi->packet_pool);
   2.139 +        ASSERT(status == NDIS_STATUS_SUCCESS);
   2.140          NDIS_SET_PACKET_HEADER_SIZE(packet, XN_HDR_SIZE);
   2.141 -        NdisQueryPacketLength(packet, &length);
   2.142        }
   2.143  
   2.144        buffer = xi->rx_buffers[rxrsp->id];
   2.145        xi->rx_buffers[rxrsp->id] = NULL;
   2.146        NdisAdjustBufferLength(buffer, rxrsp->status);
   2.147        NdisChainBufferAtBack(packet, buffer);
   2.148 -      NdisQueryPacketLength(packet, &length);
   2.149        xi->XenInterface.GntTbl_EndAccess(xi->XenInterface.InterfaceHeader.Context,
   2.150          xi->grant_rx_ref[rxrsp->id]);
   2.151        xi->grant_rx_ref[rxrsp->id] = GRANT_INVALID_REF;
   2.152  
   2.153 -#if 0
   2.154 -      KdPrint((__DRIVER_NAME "     Flags = %sNETRXF_data_validated|%sNETRXF_csum_blank|%sNETRXF_more_data|%sNETRXF_extra_info\n",
   2.155 -        (rxrsp->flags&NETRXF_data_validated)?"":"!",
   2.156 -        (rxrsp->flags&NETRXF_csum_blank)?"":"!",
   2.157 -        (rxrsp->flags&NETRXF_more_data)?"":"!",
   2.158 -        (rxrsp->flags&NETRXF_extra_info)?"":"!"));
   2.159 -#endif
   2.160        ASSERT(!(rxrsp->flags & NETRXF_extra_info)); // not used on RX
   2.161  
   2.162        more_frags = rxrsp->flags & NETRXF_more_data;
   2.163 @@ -668,9 +667,6 @@ XenNet_Init(
   2.164    char *err;
   2.165    xenbus_transaction_t xbt = 0;
   2.166    KIRQL OldIrql;
   2.167 -  PNDIS_PACKET packet;
   2.168 -  buffer_entry_t *buffer_entry;
   2.169 -  PLIST_ENTRY entry;
   2.170  
   2.171    UNREFERENCED_PARAMETER(OpenErrorStatus);
   2.172    UNREFERENCED_PARAMETER(WrapperConfigurationContext);
   2.173 @@ -717,7 +713,6 @@ XenNet_Init(
   2.174    KeInitializeSpinLock(&xi->rx_lock);
   2.175  
   2.176    InitializeListHead(&xi->rx_free_buf_list);
   2.177 -  InitializeListHead(&xi->rx_free_pkt_list);
   2.178    InitializeListHead(&xi->tx_waiting_pkt_list);
   2.179    
   2.180    NdisAllocatePacketPool(&status, &xi->packet_pool, XN_RX_QUEUE_LEN,
   2.181 @@ -889,26 +884,7 @@ XenNet_Init(
   2.182    KdPrint((__DRIVER_NAME "     Connected\n"));
   2.183  
   2.184    KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
   2.185 -
   2.186 -  for (i = 0; i < XN_RX_QUEUE_LEN; i++)
   2.187 -  {
   2.188 -    status = NdisAllocateMemoryWithTag(&buffer_entry, sizeof(buffer_entry_t), XENNET_POOL_TAG);
   2.189 -    if (status != NDIS_STATUS_SUCCESS)
   2.190 -    {
   2.191 -      KdPrint(("NdisAllocateMemoryWithTag Failed! status = 0x%x\n", status));
   2.192 -      break;
   2.193 -    }
   2.194 -    NdisAllocateBuffer(&status, &buffer_entry->buffer, xi->buffer_pool, buffer_entry, sizeof(buffer_entry->data));
   2.195 -    ASSERT(status == NDIS_STATUS_SUCCESS); // should never fail
   2.196 -    InsertTailList(&xi->rx_free_buf_list, &buffer_entry->entry);
   2.197 -
   2.198 -    NdisAllocatePacket(&status, &packet, xi->packet_pool);
   2.199 -    entry = (PLIST_ENTRY)&packet->MiniportReservedEx[sizeof(PVOID)];
   2.200 -    InsertTailList(&xi->rx_free_pkt_list, entry);
   2.201 -  }
   2.202 -
   2.203    XenNet_RxBufferAlloc(xi);
   2.204 -
   2.205    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
   2.206  
   2.207    /* get mac address */
   2.208 @@ -1570,16 +1546,7 @@ XenNet_SendPackets(
   2.209    PLIST_ENTRY entry;
   2.210    KIRQL OldIrql;
   2.211  
   2.212 -#if 0
   2.213 -  for (i = 0; i < NumberOfPackets; i++)
   2.214 -  {
   2.215 -    curr_packet = PacketArray[i];
   2.216 -    NdisMSendComplete(xi->adapter_handle, curr_packet, NDIS_STATUS_FAILURE);
   2.217 -  }
   2.218 -  return;
   2.219 -#endif
   2.220 -
   2.221 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.222 +  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.223    for (i = 0; i < NumberOfPackets; i++)
   2.224    {
   2.225      curr_packet = PacketArray[i];
   2.226 @@ -1609,7 +1576,7 @@ XenNet_SendPackets(
   2.227      InterlockedIncrement(&xi->tx_outstanding);
   2.228    }
   2.229    XenNet_SendQueuedPackets(xi);
   2.230 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.231 +  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.232  }
   2.233  
   2.234  VOID
   2.235 @@ -1687,7 +1654,7 @@ XenNet_Halt(
   2.236      KeWaitForSingleObject(&xi->backend_state_change_event, Executive,
   2.237        KernelMode, FALSE, NULL);
   2.238  
   2.239 -  // this disables the interrupt
   2.240 +  // Disables the interrupt
   2.241    XenNet_Shutdown(xi);
   2.242  
   2.243    xi->connected = FALSE;
   2.244 @@ -1797,8 +1764,6 @@ DriverEntry(
   2.245    mini_chars.PnPEventNotifyHandler = XenNet_PnPEventNotify;
   2.246    mini_chars.AdapterShutdownHandler = XenNet_Shutdown;
   2.247  
   2.248 -  /* TODO: we don't have hardware, but we have "resources", so do we need to implement fns to handle this? */
   2.249 -
   2.250    /* set up upper-edge interface */
   2.251    status = NdisMRegisterMiniport(ndis_wrapper_handle, &mini_chars, sizeof(mini_chars));
   2.252    if (!NT_SUCCESS(status))
     3.1 --- a/xenvbd/xenvbd.c	Wed Feb 13 23:25:32 2008 +1100
     3.2 +++ b/xenvbd/xenvbd.c	Wed Feb 13 23:27:00 2008 +1100
     3.3 @@ -139,7 +139,6 @@ XenVbd_HwScsiInterruptTarget(PVOID Devic
     3.4    PXENVBD_TARGET_DATA TargetData = (PXENVBD_TARGET_DATA)DeviceExtension;
     3.5    PSCSI_REQUEST_BLOCK Srb;
     3.6    RING_IDX i, rp;
     3.7 -  int j;
     3.8    blkif_response_t *rep;
     3.9    int BlockCount;
    3.10    PXENVBD_DEVICE_DATA DeviceData = (PXENVBD_DEVICE_DATA)TargetData->DeviceData;
    3.11 @@ -155,8 +154,22 @@ XenVbd_HwScsiInterruptTarget(PVOID Devic
    3.12      {
    3.13        rep = XenVbd_GetResponse(TargetData, i);
    3.14  
    3.15 -//KdPrint((__DRIVER_NAME "     rep = %p\n", rep));
    3.16 -//KdPrint((__DRIVER_NAME "     rep->id = %d\n", rep->id));
    3.17 +      //KdPrint((__DRIVER_NAME "     rep = %p\n", rep));
    3.18 +      //KdPrint((__DRIVER_NAME "     rep->id = %d\n", rep->id));
    3.19 +
    3.20 +      /*
    3.21 +       * This code is to automatically detect if the backend is using the same
    3.22 +       * bit width or a different bit width to us. Later versions of Xen do this
    3.23 +       * via a xenstore value, but not all. That 0x0fffffff (notice
    3.24 +       * that the msb is not actually set, so we don't have any problems with
    3.25 +       * sign extending) is to signify the last entry on the right, which is
    3.26 +       * different under 32 and 64 bits, and that is why we set it up there.
    3.27 +
    3.28 +       * To do the detection, we put two initial entries on the ring, with an op
    3.29 +       * of 0xff (which is invalid). The first entry is mostly okay, but the
    3.30 +       * second will be grossly misaligned if the backend bit width is different,
    3.31 +       * and we detect this and switch frontend structures.
    3.32 +       */
    3.33        switch (TargetData->ring_detect_state)
    3.34        {
    3.35        case 0:
    3.36 @@ -833,9 +846,8 @@ XenVbd_PutSrbOnRing(PXENVBD_TARGET_DATA 
    3.37    //PUCHAR DataBuffer;
    3.38    int i;
    3.39    int BlockCount;
    3.40 -  PXENVBD_DEVICE_DATA DeviceData = (PXENVBD_DEVICE_DATA)TargetData->DeviceData;
    3.41    blkif_shadow_t *shadow;
    3.42 -  int id;
    3.43 +  uint64_t id;
    3.44  
    3.45  // can use SRB_STATUS_BUSY to push the SRB back to windows...
    3.46