win-pvdrivers

changeset 44:01f874217465

xennet: tx and rx both work!
author Andy Grover <andy.grover@oracle.com>
date Thu Dec 13 12:30:19 2007 -0800 (2007-12-13)
parents 59691f2a99f6
children cc2c13724f45
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Wed Dec 12 16:58:09 2007 -0800
     1.2 +++ b/xennet/xennet.c	Thu Dec 13 12:30:19 2007 -0800
     1.3 @@ -164,7 +164,7 @@ AllocatePages(int Pages)
     1.4    PHYSICAL_ADDRESS Align;
     1.5    PMDL Mdl;
     1.6  
     1.7 -  KdPrint((__DRIVER_NAME " --> Allocate Pages\n"));
     1.8 +  // KdPrint((__DRIVER_NAME " --> Allocate Pages\n"));
     1.9  
    1.10    Min.QuadPart = 0;
    1.11    Max.QuadPart = 0xFFFFFFFF;
    1.12 @@ -172,7 +172,7 @@ AllocatePages(int Pages)
    1.13  
    1.14    Mdl = MmAllocatePagesForMdl(Min, Max, Align, Pages * PAGE_SIZE);
    1.15  
    1.16 -  KdPrint((__DRIVER_NAME " <-- Allocate Pages (mdl = %08x)\n", Mdl));
    1.17 +  // KdPrint((__DRIVER_NAME " <-- Allocate Pages (mdl = %08x)\n", Mdl));
    1.18  
    1.19    return Mdl;
    1.20  }
    1.21 @@ -252,31 +252,33 @@ XenNet_AllocRXBuffers(struct xennet_info
    1.22    grant_ref_t ref;
    1.23    netif_rx_request_t *req;
    1.24    NDIS_STATUS status;
    1.25 -  PMDL pmdl;
    1.26    PVOID start;
    1.27  
    1.28 -  if (!xi->connected)
    1.29 -    return NDIS_STATUS_FAILURE;
    1.30 -
    1.31    batch_target = xi->rx_target - (req_prod - xi->rx.rsp_cons);
    1.32    for (i = 0; i < batch_target; i++)
    1.33    {
    1.34      /*
    1.35       * Allocate a packet, page, and buffer. Hook them up.
    1.36       */
    1.37 +    status = NdisAllocateMemoryWithTag(&start, PAGE_SIZE, XENNET_POOL_TAG);
    1.38 +    if (status != NDIS_STATUS_SUCCESS)
    1.39 +    {
    1.40 +      KdPrint(("NdisAllocateMemoryWithTag Failed! status = 0x%x\n", status));
    1.41 +      break;
    1.42 +    }
    1.43 +    NdisAllocateBuffer(&status, &buffer, xi->buffer_pool, start, PAGE_SIZE);
    1.44 +    if (status != NDIS_STATUS_SUCCESS)
    1.45 +    {
    1.46 +      KdPrint(("NdisAllocateBuffer Failed! status = 0x%x\n", status));
    1.47 +      NdisFreeMemory(start, 0, 0);
    1.48 +      break;
    1.49 +    }
    1.50      NdisAllocatePacket(&status, &packet, xi->packet_pool);
    1.51      if (status != NDIS_STATUS_SUCCESS)
    1.52      {
    1.53        KdPrint(("NdisAllocatePacket Failed! status = 0x%x\n", status));
    1.54 -      break;
    1.55 -    }
    1.56 -    pmdl = AllocatePage();
    1.57 -    start = MmGetSystemAddressForMdlSafe(pmdl, NormalPagePriority);
    1.58 -    NdisAllocateBuffer(&status, &buffer, xi->buffer_pool, start, PAGE_SIZE);
    1.59 -    if (status != NDIS_STATUS_SUCCESS)
    1.60 -    {
    1.61 -      KdPrint(("NdisAllocateBuffer Failed! status = 0x%x\n", status));
    1.62 -      /* TODO: free mdl, page, packet here */
    1.63 +      NdisFreeMemory(start, 0, 0);
    1.64 +      NdisFreeBuffer(buffer);
    1.65        break;
    1.66      }
    1.67      NdisChainBufferAtBack(packet, buffer);
    1.68 @@ -286,9 +288,10 @@ XenNet_AllocRXBuffers(struct xennet_info
    1.69      ASSERT(!xi->rx_pkts[id]);
    1.70      xi->rx_pkts[id] = packet;
    1.71      req = RING_GET_REQUEST(&xi->rx, req_prod + i);
    1.72 +    /* an NDIS_BUFFER is just a MDL, so we can get its pfn array */
    1.73      ref = xi->GntTblInterface.GrantAccess(
    1.74        xi->GntTblInterface.InterfaceHeader.Context, 0,
    1.75 -      *MmGetMdlPfnArray(pmdl), FALSE);
    1.76 +      *MmGetMdlPfnArray(buffer), FALSE);
    1.77      ASSERT((signed short)ref >= 0);
    1.78      xi->grant_rx_ref[id] = ref;
    1.79  
    1.80 @@ -499,7 +502,6 @@ XenNet_BackEndStateHandler(char *Path, P
    1.81      xi->XenBusInterface.EndTransaction(xi->XenBusInterface.InterfaceHeader.Context,
    1.82        xbt, 0, &retry);
    1.83  
    1.84 -    /* TODO: prepare tx and rx rings */
    1.85      XenNet_AllocRXBuffers(xi);
    1.86  
    1.87      KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    1.88 @@ -985,13 +987,20 @@ XenNet_ReturnPacket(
    1.89    IN PNDIS_PACKET Packet
    1.90    )
    1.91  {
    1.92 -  struct xennet_info *xi = MiniportAdapterContext;
    1.93 +  PNDIS_BUFFER buffer;
    1.94 +  PVOID buff_va;
    1.95 +  UINT buff_len;
    1.96 +  UINT tot_buff_len;
    1.97  
    1.98 -  xi;
    1.99 -  UNREFERENCED_PARAMETER(Packet);
   1.100 -  /* free memory page */
   1.101 -  /* free buffer */
   1.102 -  /* free packet */
   1.103 +  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   1.104 +
   1.105 +  NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
   1.106 +    &tot_buff_len, NormalPagePriority);
   1.107 +  ASSERT(buff_len == tot_buff_len);
   1.108 +
   1.109 +  NdisFreeMemory(buff_va, 0, 0);
   1.110 +  NdisFreeBuffer(buffer);
   1.111 +  NdisFreePacket(Packet);
   1.112  
   1.113    KdPrint((__FUNCTION__ " called\n"));
   1.114  }
   1.115 @@ -1054,7 +1063,6 @@ XenNet_SendPackets(
   1.116    UINT i;
   1.117    struct netif_tx_request *tx;
   1.118    unsigned short id;
   1.119 -  PFN_NUMBER pfn;
   1.120    int notify;
   1.121    PMDL pmdl;
   1.122    UINT pkt_size;
   1.123 @@ -1075,10 +1083,9 @@ XenNet_SendPackets(
   1.124        NdisMSendComplete(xi, curr_packet, NDIS_STATUS_FAILURE);
   1.125        break;
   1.126      }
   1.127 -    pfn = *MmGetMdlPfnArray(pmdl);
   1.128 +    *((PMDL *)curr_packet->MiniportReservedEx) = pmdl;
   1.129  
   1.130      id = get_id_from_freelist(xi->tx_pkts);
   1.131 -    *((PMDL *)curr_packet->MiniportReservedEx) = pmdl;
   1.132      xi->tx_pkts[id] = curr_packet;
   1.133  
   1.134      tx = RING_GET_REQUEST(&xi->tx, xi->tx.req_prod_pvt);
   1.135 @@ -1086,7 +1093,7 @@ XenNet_SendPackets(
   1.136      tx->gref = xi->GntTblInterface.GrantAccess(
   1.137        xi->GntTblInterface.InterfaceHeader.Context,
   1.138        0,
   1.139 -      pfn,
   1.140 +      *MmGetMdlPfnArray(pmdl),
   1.141        TRUE);
   1.142      xi->grant_tx_ref[id] = tx->gref;
   1.143      tx->offset = 0;