win-pvdrivers

changeset 222:d37e4b226919

Almost working - rx offload packet splitting is working but not yet calculating checksums correctly. There may still be an occasional crash on init too from xennet_oid...
author James Harper <james.harper@bendigoit.com.au>
date Tue Mar 25 08:24:41 2008 +1100 (2008-03-25)
parents 03fcf506d609
children 26f8a3615539
files common.inc xennet/xennet_oid.c xennet/xennet_rx.c
line diff
     1.1 --- a/common.inc	Mon Mar 24 13:06:06 2008 +1100
     1.2 +++ b/common.inc	Tue Mar 25 08:24:41 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.5.59
     1.5 +VERSION=0.8.5.72
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/xennet/xennet_oid.c	Mon Mar 24 13:06:06 2008 +1100
     2.2 +++ b/xennet/xennet_oid.c	Tue Mar 25 08:24:41 2008 +1100
     2.3 @@ -211,8 +211,11 @@ XenNet_QueryInformation(
     2.4  
     2.5        len = sizeof(NDIS_TASK_OFFLOAD_HEADER);
     2.6  
     2.7 -      len += FIELD_OFFSET(NDIS_TASK_OFFLOAD, TaskBuffer)
     2.8 -        + sizeof(NDIS_TASK_TCP_IP_CHECKSUM);
     2.9 +      if (xi->config_csum)
    2.10 +      {
    2.11 +        len += FIELD_OFFSET(NDIS_TASK_OFFLOAD, TaskBuffer)
    2.12 +          + sizeof(NDIS_TASK_TCP_IP_CHECKSUM);
    2.13 +      }
    2.14  
    2.15        if (xi->config_gso)
    2.16        {
    2.17 @@ -224,8 +227,11 @@ XenNet_QueryInformation(
    2.18        {
    2.19            break;
    2.20        }
    2.21 +      KdPrint(("InformationBuffer = %p\n", InformationBuffer));
    2.22 +      KdPrint(("len = %d\n", len));
    2.23  
    2.24        ntoh = (PNDIS_TASK_OFFLOAD_HEADER)InformationBuffer;
    2.25 +      KdPrint(("ntoh = %p\n", ntoh));
    2.26        if (ntoh->Version != NDIS_TASK_OFFLOAD_VERSION
    2.27          || ntoh->Size != sizeof(*ntoh)
    2.28          || ntoh->EncapsulationFormat.Encapsulation != IEEE_802_3_Encapsulation)
    2.29 @@ -238,6 +244,7 @@ XenNet_QueryInformation(
    2.30  
    2.31        if (xi->config_csum)
    2.32        {
    2.33 +        KdPrint(("config_csum enabled\n"));
    2.34          if (ntoh->OffsetFirstTask == 0)
    2.35          {
    2.36            ntoh->OffsetFirstTask = ntoh->Size;
    2.37 @@ -249,6 +256,7 @@ XenNet_QueryInformation(
    2.38              + nto->TaskBufferLength;
    2.39            nto = (PNDIS_TASK_OFFLOAD)((PCHAR)(nto) + nto->OffsetNextTask);
    2.40          }
    2.41 +        KdPrint(("nto = %p\n", nto));
    2.42          /* fill in first nto */
    2.43          nto->Version = NDIS_TASK_OFFLOAD_VERSION;
    2.44          nto->Size = sizeof(NDIS_TASK_OFFLOAD);
    2.45 @@ -278,6 +286,7 @@ XenNet_QueryInformation(
    2.46        }
    2.47        if (xi->config_gso)
    2.48        {
    2.49 +        KdPrint(("config_gso enabled\n"));
    2.50          if (ntoh->OffsetFirstTask == 0)
    2.51          {
    2.52            ntoh->OffsetFirstTask = ntoh->Size;
    2.53 @@ -289,6 +298,7 @@ XenNet_QueryInformation(
    2.54              + nto->TaskBufferLength;
    2.55            nto = (PNDIS_TASK_OFFLOAD)((PCHAR)(nto) + nto->OffsetNextTask);
    2.56          }
    2.57 +        KdPrint(("nto = %p\n", nto));
    2.58    
    2.59          /* fill in second nto */
    2.60          nto->Version = NDIS_TASK_OFFLOAD_VERSION;
     3.1 --- a/xennet/xennet_rx.c	Mon Mar 24 13:06:06 2008 +1100
     3.2 +++ b/xennet/xennet_rx.c	Tue Mar 25 08:24:41 2008 +1100
     3.3 @@ -147,8 +147,12 @@ XenNet_RxBufferAlloc(struct xennet_info 
     3.4  
     3.5  #define __NET_USHORT_BYTE_0(x) ((USHORT)(x & 0xFF))
     3.6  #define __NET_USHORT_BYTE_1(x) ((USHORT)((PUCHAR)&x)[1] & 0xFF)
     3.7 -#define NET_USHORT(x) ((__NET_USHORT_BYTE_0(x) << 8) | __NET_USHORT_BYTE_1(x))
     3.8 -#define NET_ULONG(x) ((NET_USHORT(x) << 16) | NET_USHORT(((PUCHAR)&x)[2]))
     3.9 +
    3.10 +#define GET_NET_USHORT(x) ((__NET_USHORT_BYTE_0(x) << 8) | __NET_USHORT_BYTE_1(x))
    3.11 +#define SET_NET_USHORT(y, x) *((USHORT *)&(y)) = ((__NET_USHORT_BYTE_0(x) << 8) | __NET_USHORT_BYTE_1(x))
    3.12 +
    3.13 +#define GET_NET_ULONG(x) ((GET_NET_USHORT(x) << 16) | GET_NET_USHORT(((PUCHAR)&x)[2]))
    3.14 +#define SET_NET_ULONG(y, x) *((ULONG *)&(y)) = ((GET_NET_USHORT(x) << 16) | GET_NET_USHORT(((PUCHAR)&x)[2]))
    3.15  
    3.16  static VOID
    3.17  XenNet_ParseHeader(
    3.18 @@ -170,7 +174,7 @@ XenNet_ParseHeader(
    3.19      return;
    3.20    }
    3.21    
    3.22 -  switch (NET_USHORT(xi->rxpi.header[12])) // L2 protocol field
    3.23 +  switch (GET_NET_USHORT(xi->rxpi.header[12])) // L2 protocol field
    3.24    {
    3.25    case 0x0800:
    3.26      xi->rxpi.ip_version = (xi->rxpi.header[XN_HDR_SIZE + 0] & 0xF0) >> 4;
    3.27 @@ -200,11 +204,11 @@ XenNet_ParseHeader(
    3.28    default:
    3.29      return;
    3.30    }
    3.31 -  xi->rxpi.ip4_length = NET_USHORT(xi->rxpi.header[XN_HDR_SIZE + 2]);
    3.32 +  xi->rxpi.ip4_length = GET_NET_USHORT(xi->rxpi.header[XN_HDR_SIZE + 2]);
    3.33    xi->rxpi.tcp_header_length = (xi->rxpi.header[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 12] & 0xf0) >> 2;
    3.34 -  xi->rxpi.tcp_length = xi->rxpi.ip4_length - xi->rxpi.tcp_header_length;
    3.35 +  xi->rxpi.tcp_length = xi->rxpi.ip4_length - xi->rxpi.ip4_header_length - xi->rxpi.tcp_header_length;
    3.36    xi->rxpi.tcp_remaining = xi->rxpi.tcp_length;
    3.37 -  xi->rxpi.tcp_seq = NET_ULONG(xi->rxpi.header[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4]);
    3.38 +  xi->rxpi.tcp_seq = GET_NET_ULONG(xi->rxpi.header[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4]);
    3.39    if (xi->rxpi.mss > 0 && xi->rxpi.tcp_length > xi->rxpi.mss)
    3.40      xi->rxpi.split_required = TRUE;
    3.41  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.42 @@ -250,8 +254,8 @@ XenNet_SumPacket(
    3.43    remaining = xi->rxpi.ip4_length - xi->rxpi.ip4_header_length - xi->rxpi.tcp_header_length;
    3.44    // TODO: pre-calc a sum of the header...
    3.45    pre_csum = 0;
    3.46 -  pre_csum += NET_USHORT(buffer[XN_HDR_SIZE + 12]) + NET_USHORT(buffer[XN_HDR_SIZE + 14]);
    3.47 -  pre_csum += NET_USHORT(buffer[XN_HDR_SIZE + 16]) + NET_USHORT(buffer[XN_HDR_SIZE + 18]);
    3.48 +  pre_csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 12]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 14]);
    3.49 +  pre_csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 16]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 18]);
    3.50    pre_csum += ((USHORT)buffer[XN_HDR_SIZE + 9]);
    3.51  
    3.52    remaining = xi->rxpi.ip4_length - xi->rxpi.ip4_header_length;
    3.53 @@ -288,8 +292,8 @@ XenNet_SumPacket(
    3.54          NdisQueryBufferSafe(mdl, &buffer, &buffer_length, NormalPagePriority);
    3.55          buffer_offset = 0;
    3.56        }
    3.57 -      csum += NET_USHORT(buffer[buffer_offset]);
    3.58 -//KdPrint((__DRIVER_NAME "     %04X\n", NET_USHORT(buffer[buffer_offset])));
    3.59 +      csum += GET_NET_USHORT(buffer[buffer_offset]);
    3.60 +//KdPrint((__DRIVER_NAME "     %04X\n", GET_NET_USHORT(buffer[buffer_offset])));
    3.61      }
    3.62    }
    3.63    if (i != total_length) // last odd byte
    3.64 @@ -299,7 +303,7 @@ XenNet_SumPacket(
    3.65    }
    3.66    while (csum & 0xFFFF0000)
    3.67      csum = (csum & 0xFFFF) + (csum >> 16);
    3.68 -  *csum_ptr = (USHORT)~NET_USHORT(csum);
    3.69 +  *csum_ptr = (USHORT)~GET_NET_USHORT(csum);
    3.70  
    3.71    KdPrint((__DRIVER_NAME "     csum = %04x\n", *csum_ptr));
    3.72  
    3.73 @@ -320,6 +324,8 @@ XenNet_GetData(
    3.74  
    3.75    *length = min(req_length, MmGetMdlByteCount(mdl) - xi->rxpi.curr_mdl_offset);
    3.76  
    3.77 +  KdPrint((__DRIVER_NAME "     req_length = %d, length = %d\n", req_length, *length));
    3.78 +
    3.79    xi->rxpi.curr_mdl_offset += *length;
    3.80    if (xi->rxpi.curr_mdl_offset == MmGetMdlByteCount(mdl))
    3.81    {
    3.82 @@ -344,6 +350,7 @@ XenNet_MakePacket(
    3.83    USHORT out_offset;
    3.84    USHORT out_remaining;
    3.85    USHORT length;
    3.86 +  USHORT new_ip4_length;
    3.87    NDIS_STATUS status;
    3.88    int i;
    3.89  
    3.90 @@ -361,15 +368,15 @@ XenNet_MakePacket(
    3.91    }
    3.92    else
    3.93    {
    3.94 -    KdPrint((__DRIVER_NAME "     splitting packet\n"));
    3.95      out_mdl = get_page_from_freelist(xi);
    3.96      out_buffer = MmGetMdlVirtualAddress(out_mdl);
    3.97      out_offset = XN_HDR_SIZE + xi->rxpi.ip4_header_length + xi->rxpi.tcp_header_length;
    3.98      out_remaining = min(xi->rxpi.mss, xi->rxpi.tcp_remaining);
    3.99      NdisAdjustBufferLength(out_mdl, out_offset + out_remaining);
   3.100      memcpy(out_buffer, xi->rxpi.header, out_offset);
   3.101 -    out_buffer[XN_HDR_SIZE + 2] = NET_USHORT(out_remaining);
   3.102 -    *((PULONG)&out_buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4]) = NET_ULONG(xi->rxpi.tcp_seq);
   3.103 +    new_ip4_length = out_remaining + xi->rxpi.ip4_header_length + xi->rxpi.tcp_header_length;
   3.104 +    SET_NET_USHORT(out_buffer[XN_HDR_SIZE + 2], new_ip4_length);
   3.105 +    SET_NET_ULONG(out_buffer[XN_HDR_SIZE + xi->rxpi.ip4_header_length + 4], xi->rxpi.tcp_seq);
   3.106      xi->rxpi.tcp_seq += out_remaining;
   3.107      xi->rxpi.tcp_remaining -= out_remaining;
   3.108      do 
   3.109 @@ -383,7 +390,8 @@ XenNet_MakePacket(
   3.110      NdisChainBufferAtBack(packet, out_mdl);
   3.111      NDIS_SET_PACKET_STATUS(packet, NDIS_STATUS_SUCCESS);
   3.112    }
   3.113 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.114 +
   3.115 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (%p)\n", packet));
   3.116    return packet;
   3.117  }
   3.118  
   3.119 @@ -409,7 +417,7 @@ XenNet_MakePackets(
   3.120    ULONG total_in_remaining;
   3.121    ULONG buffer_in_remaining;
   3.122  
   3.123 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   3.124 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "(packets = %p, packet_count = %d)\n", packets, *packet_count_p));
   3.125  
   3.126    XenNet_ParseHeader(xi);
   3.127    switch (xi->rxpi.ip_proto)
   3.128 @@ -431,6 +439,7 @@ XenNet_MakePackets(
   3.129      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (Other)\n"));
   3.130      return;
   3.131    }
   3.132 +  KdPrint((__DRIVER_NAME "     splitting packet\n"));
   3.133    xi->rxpi.tcp_remaining = xi->rxpi.tcp_length;
   3.134    if (MmGetMdlByteCount(xi->rxpi.mdls[0]) > XN_HDR_SIZE + xi->rxpi.ip4_header_length + xi->rxpi.tcp_header_length)
   3.135      xi->rxpi.curr_mdl_offset = XN_HDR_SIZE + xi->rxpi.ip4_header_length + xi->rxpi.tcp_header_length;
   3.136 @@ -439,14 +448,16 @@ XenNet_MakePackets(
   3.137  
   3.138    while (xi->rxpi.tcp_remaining)
   3.139    {
   3.140 +    KdPrint((__DRIVER_NAME "     tcp_remaining = %d\n", xi->rxpi.tcp_remaining));
   3.141      packets[*packet_count_p] = XenNet_MakePacket(xi);
   3.142      XenNet_SumPacket(xi, packets[*packet_count_p]);
   3.143      (*packet_count_p)++;
   3.144    }
   3.145 +  KdPrint((__DRIVER_NAME "     tcp_remaining = %d\n", xi->rxpi.tcp_remaining));
   3.146    // TODO: restore psh status to last packet
   3.147    for (i = 0; i < mdl_count; i++)
   3.148    {
   3.149 -    NdisAdjustBufferLength(mdl, PAGE_SIZE);
   3.150 +    NdisAdjustBufferLength(mdls[i], PAGE_SIZE);
   3.151      put_page_on_freelist(xi, mdls[i]);
   3.152    }
   3.153    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (split)\n"));
   3.154 @@ -551,7 +562,6 @@ XenNet_RxBufferCheck(struct xennet_info 
   3.155        {
   3.156          XenNet_MakePackets(xi, packets, &packet_count);
   3.157          RtlZeroMemory(&xi->rxpi, sizeof(xi->rxpi));
   3.158 -        packet_count++;
   3.159        }
   3.160      }
   3.161      xi->rx.rsp_cons = prod;
   3.162 @@ -603,7 +613,7 @@ XenNet_ReturnPacket(
   3.163    LARGE_INTEGER tsc, dummy;
   3.164  #endif
   3.165  
   3.166 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   3.167 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (%p)\n", Packet));
   3.168  
   3.169  #if defined(XEN_PROFILE)
   3.170    tsc = KeQueryPerformanceCounter(&dummy);