win-pvdrivers

changeset 223:26f8a3615539

GSO receive is now mostly working, but seems to break after a while. Still getting occasional crashes on driver load.
author James Harper <james.harper@bendigoit.com.au>
date Tue Mar 25 14:06:35 2008 +1100 (2008-03-25)
parents d37e4b226919
children 0e71aec16493
files common.inc xennet/xennet_rx.c
line diff
     1.1 --- a/common.inc	Tue Mar 25 08:24:41 2008 +1100
     1.2 +++ b/common.inc	Tue Mar 25 14:06:35 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.5.72
     1.5 +VERSION=0.8.5.74
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/xennet/xennet_rx.c	Tue Mar 25 08:24:41 2008 +1100
     2.2 +++ b/xennet/xennet_rx.c	Tue Mar 25 14:06:35 2008 +1100
     2.3 @@ -214,6 +214,34 @@ XenNet_ParseHeader(
     2.4  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
     2.5  }
     2.6  
     2.7 +static VOID
     2.8 +XenNet_SumIpHeader(
     2.9 +  struct xennet_info *xi,  
    2.10 +  PNDIS_PACKET packet
    2.11 +)
    2.12 +{
    2.13 +  PMDL mdl;
    2.14 +  UINT total_length;
    2.15 +  UINT buffer_length;
    2.16 +  PUCHAR buffer;
    2.17 +  ULONG csum = 0;
    2.18 +  USHORT i;
    2.19 +
    2.20 +  NdisGetFirstBufferFromPacketSafe(packet, &mdl, &buffer, &buffer_length, &total_length, NormalPagePriority);
    2.21 +
    2.22 +  buffer[XN_HDR_SIZE + 10] = 0;
    2.23 +  buffer[XN_HDR_SIZE + 11] = 0;
    2.24 +  for (i = 0; i < xi->rxpi.ip4_header_length; i += 2)
    2.25 +  {
    2.26 +    csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + i]);
    2.27 +  }
    2.28 +  while (csum & 0xFFFF0000)
    2.29 +    csum = (csum & 0xFFFF) + (csum >> 16);
    2.30 +  csum = ~csum;
    2.31 +  SET_NET_USHORT(buffer[XN_HDR_SIZE + 10], csum);
    2.32 +}
    2.33 +
    2.34 +
    2.35  /*
    2.36   Windows appears to insist that the checksum on received packets is correct, and won't
    2.37   believe us when we lie about it, which happens when the packet is generated on the
    2.38 @@ -221,7 +249,7 @@ XenNet_ParseHeader(
    2.39   This is only for TCP and UDP packets. IP checksums appear to be correct anyways.
    2.40  */
    2.41  static VOID
    2.42 -XenNet_SumPacket(
    2.43 +XenNet_SumTcpPacket(
    2.44    struct xennet_info *xi,  
    2.45    PNDIS_PACKET packet
    2.46  )
    2.47 @@ -252,15 +280,15 @@ XenNet_SumPacket(
    2.48    ASSERT((USHORT)(xi->rxpi.ip4_length + XN_HDR_SIZE) == xi->rxpi.total_length);
    2.49  
    2.50    remaining = xi->rxpi.ip4_length - xi->rxpi.ip4_header_length - xi->rxpi.tcp_header_length;
    2.51 -  // TODO: pre-calc a sum of the header...
    2.52 -  pre_csum = 0;
    2.53 -  pre_csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 12]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 14]);
    2.54 -  pre_csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 16]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 18]);
    2.55 -  pre_csum += ((USHORT)buffer[XN_HDR_SIZE + 9]);
    2.56 +  csum = 0;
    2.57 +  csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 12]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 14]); // seq
    2.58 +  csum += GET_NET_USHORT(buffer[XN_HDR_SIZE + 16]) + GET_NET_USHORT(buffer[XN_HDR_SIZE + 18]); // ack
    2.59 +  csum += ((USHORT)buffer[XN_HDR_SIZE + 9]);
    2.60  
    2.61 -  remaining = xi->rxpi.ip4_length - xi->rxpi.ip4_header_length;
    2.62 +  // can't use ip4_length here as we might have split the packet up
    2.63 +  remaining = GET_NET_USHORT(buffer[XN_HDR_SIZE + 2]) - xi->rxpi.ip4_header_length;
    2.64  
    2.65 -  csum = pre_csum + remaining;
    2.66 +  csum += remaining;
    2.67  
    2.68    for (buffer_offset = i = XN_HDR_SIZE + xi->rxpi.ip4_header_length; i < total_length - 1; i += 2, buffer_offset += 2)
    2.69    {
    2.70 @@ -388,6 +416,7 @@ XenNet_MakePacket(
    2.71      } while (out_remaining != 0 && in_buffer != NULL);
    2.72      //length = xi->rxpi.mss - out_remaining;
    2.73      NdisChainBufferAtBack(packet, out_mdl);
    2.74 +    XenNet_SumIpHeader(xi, packet);
    2.75      NDIS_SET_PACKET_STATUS(packet, NDIS_STATUS_SUCCESS);
    2.76    }
    2.77  
    2.78 @@ -429,7 +458,7 @@ XenNet_MakePackets(
    2.79    case 17:  // UDP
    2.80      packets[*packet_count_p] = XenNet_MakePacket(xi);
    2.81      if (xi->rxpi.csum_calc_required)
    2.82 -      XenNet_SumPacket(xi, packets[*packet_count_p]);
    2.83 +      XenNet_SumTcpPacket(xi, packets[*packet_count_p]);
    2.84      (*packet_count_p)++;
    2.85      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (TCP/UDP)\n"));
    2.86      return;
    2.87 @@ -450,7 +479,7 @@ XenNet_MakePackets(
    2.88    {
    2.89      KdPrint((__DRIVER_NAME "     tcp_remaining = %d\n", xi->rxpi.tcp_remaining));
    2.90      packets[*packet_count_p] = XenNet_MakePacket(xi);
    2.91 -    XenNet_SumPacket(xi, packets[*packet_count_p]);
    2.92 +    XenNet_SumTcpPacket(xi, packets[*packet_count_p]);
    2.93      (*packet_count_p)++;
    2.94    }
    2.95    KdPrint((__DRIVER_NAME "     tcp_remaining = %d\n", xi->rxpi.tcp_remaining));