win-pvdrivers

changeset 51:a1a6a68d8ab8

xennet: add support for pkt stats
author Andy Grover <andy.grover@oracle.com>
date Mon Dec 17 14:01:27 2007 -0800 (2007-12-17)
parents 5cd75aeb77cb
children 05f63c07888b
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Fri Dec 14 14:03:23 2007 -0800
     1.2 +++ b/xennet/xennet.c	Mon Dec 17 14:01:27 2007 -0800
     1.3 @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  #include <io/xenbus.h>
     1.5  #include "xennet.h"
     1.6  
     1.7 +/* Xen macros use these, so they need to be redefined to Win equivs */
     1.8  #define wmb() KeMemoryBarrier()
     1.9  #define mb() KeMemoryBarrier()
    1.10  
    1.11 @@ -101,6 +102,13 @@ struct xennet_info
    1.12  
    1.13    NDIS_HANDLE packet_pool;
    1.14    NDIS_HANDLE buffer_pool;
    1.15 +
    1.16 +  /* stats */
    1.17 +  ULONG64 stat_tx_ok;
    1.18 +  ULONG64 stat_rx_ok;
    1.19 +  ULONG64 stat_tx_error;
    1.20 +  ULONG64 stat_rx_error;
    1.21 +  ULONG64 stat_rx_no_buffer;
    1.22  };
    1.23  
    1.24  /* This function copied from linux's lib/vsprintf.c, see it for attribution */
    1.25 @@ -209,6 +217,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    1.26        MmFreePagesFromMdl(pmdl);
    1.27        IoFreeMdl(pmdl);
    1.28  
    1.29 +      xi->stat_tx_ok++;
    1.30        NdisMSendComplete(xi->adapter_handle, pkt, NDIS_STATUS_SUCCESS);
    1.31      }
    1.32  
    1.33 @@ -224,7 +233,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    1.34       */
    1.35      xi->tx.sring->rsp_event =
    1.36        prod + ((xi->tx.sring->req_prod - prod) >> 1) + 1;
    1.37 -    mb();
    1.38 +    KeMemoryBarrier();
    1.39    } while ((cons == prod) && (prod != xi->tx.sring->rsp_prod));
    1.40  
    1.41    /* if queued packets, send them now?
    1.42 @@ -341,6 +350,7 @@ XenNet_RxBufferCheck(struct xennet_info 
    1.43        /* just indicate 1 packet for now */
    1.44        packets[0] = pkt;
    1.45  
    1.46 +      xi->stat_rx_ok++;
    1.47        NdisMIndicateReceivePacket(xi->adapter_handle, packets, 1);
    1.48      }
    1.49  
    1.50 @@ -356,7 +366,7 @@ XenNet_RxBufferCheck(struct xennet_info 
    1.51       */
    1.52      xi->rx.sring->rsp_event =
    1.53        prod + ((xi->rx.sring->req_prod - prod) >> 1) + 1;
    1.54 -    mb();
    1.55 +    KeMemoryBarrier();
    1.56    } while ((cons == prod) && (prod != xi->rx.sring->rsp_prod));
    1.57  
    1.58    /* Give netback more buffers */
    1.59 @@ -502,15 +512,10 @@ XenNet_BackEndStateHandler(char *Path, P
    1.60  
    1.61    case XenbusStateInitialised:
    1.62      KdPrint((__DRIVER_NAME "     Backend State Changed to Initialised\n"));
    1.63 -    // create the device
    1.64      break;
    1.65  
    1.66    case XenbusStateConnected:
    1.67      KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
    1.68 -
    1.69 -    /* do more stuff here */
    1.70 -
    1.71 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    1.72      break;
    1.73  
    1.74    case XenbusStateClosing:
    1.75 @@ -619,7 +624,7 @@ XenNet_Init(
    1.76    NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
    1.77      &xi->lower_do, NULL, NULL);
    1.78  
    1.79 -  /* Initialise {tx,rx}_pkts as a free chain containing every entry. */
    1.80 +  /* Initialize tx_pkts as a free chain containing every entry. */
    1.81    for (i = 0; i <= NET_TX_RING_SIZE; i++) {
    1.82      xi->tx_pkts[i] = (void *)((unsigned long) i+1);
    1.83      xi->grant_tx_ref[i] = GRANT_INVALID_REF;
    1.84 @@ -779,6 +784,7 @@ err:
    1.85  
    1.86  NDIS_OID supported_oids[] =
    1.87  {
    1.88 +  /* general OIDs */
    1.89    OID_GEN_SUPPORTED_LIST,
    1.90    OID_GEN_HARDWARE_STATUS,
    1.91    OID_GEN_MEDIA_SUPPORTED,
    1.92 @@ -799,6 +805,13 @@ NDIS_OID supported_oids[] =
    1.93    OID_GEN_MAC_OPTIONS,
    1.94    OID_GEN_MEDIA_CONNECT_STATUS,
    1.95    OID_GEN_MAXIMUM_SEND_PACKETS,
    1.96 +  /* stats */
    1.97 +  OID_GEN_XMIT_OK,
    1.98 +  OID_GEN_RCV_OK,
    1.99 +  OID_GEN_XMIT_ERROR,
   1.100 +  OID_GEN_RCV_ERROR,
   1.101 +  OID_GEN_RCV_NO_BUFFER, 
   1.102 +  /* media-specific OIDs */
   1.103    OID_802_3_PERMANENT_ADDRESS,
   1.104    OID_802_3_CURRENT_ADDRESS,
   1.105    OID_802_3_MULTICAST_LIST,
   1.106 @@ -816,9 +829,9 @@ XenNet_QueryInformation(
   1.107  {
   1.108    struct xennet_info *xi = MiniportAdapterContext;
   1.109    UCHAR vendor_desc[] = XN_VENDOR_DESC;
   1.110 -  ULONG temp_data;
   1.111 +  ULONG64 temp_data;
   1.112    PVOID data = &temp_data;
   1.113 -  UINT len = sizeof(temp_data);
   1.114 +  UINT len = 4;
   1.115    NDIS_STATUS status = NDIS_STATUS_SUCCESS;
   1.116  
   1.117    switch(Oid)
   1.118 @@ -896,6 +909,26 @@ XenNet_QueryInformation(
   1.119      case OID_GEN_MAXIMUM_SEND_PACKETS:
   1.120        temp_data = XN_MAX_SEND_PKTS;
   1.121        break;
   1.122 +    case OID_GEN_XMIT_OK:
   1.123 +      temp_data = xi->stat_tx_ok;
   1.124 +      len = sizeof(ULONG64);
   1.125 +      break;
   1.126 +    case OID_GEN_RCV_OK:
   1.127 +      temp_data = xi->stat_rx_ok;
   1.128 +      len = sizeof(ULONG64);
   1.129 +      break;
   1.130 +    case OID_GEN_XMIT_ERROR:
   1.131 +      temp_data = xi->stat_tx_error;
   1.132 +      len = sizeof(ULONG64);
   1.133 +      break;
   1.134 +    case OID_GEN_RCV_ERROR:
   1.135 +      temp_data = xi->stat_rx_error;
   1.136 +      len = sizeof(ULONG64);
   1.137 +      break;
   1.138 +    case OID_GEN_RCV_NO_BUFFER:
   1.139 +      temp_data = xi->stat_rx_no_buffer;
   1.140 +      len = sizeof(ULONG64);
   1.141 +      break;
   1.142      case OID_802_3_PERMANENT_ADDRESS:
   1.143        data = xi->perm_mac_addr;
   1.144        len = ETH_ALEN;
   1.145 @@ -932,7 +965,7 @@ XenNet_QueryInformation(
   1.146      NdisMoveMemory(InformationBuffer, data, len);
   1.147    }
   1.148  
   1.149 -  KdPrint(("Got OID 0x%x\n", Oid));
   1.150 +  //KdPrint(("Got OID 0x%x\n", Oid));
   1.151  
   1.152    return status;
   1.153  }
   1.154 @@ -1031,8 +1064,6 @@ XenNet_SendPackets(
   1.155    PMDL pmdl;
   1.156    UINT pkt_size;
   1.157  
   1.158 -  KdPrint((__FUNCTION__ " called, sending %d pkts\n", NumberOfPackets));
   1.159 -
   1.160    for (i = 0; i < NumberOfPackets; i++)
   1.161    {
   1.162      curr_packet = PacketArray[i];
   1.163 @@ -1040,6 +1071,8 @@ XenNet_SendPackets(
   1.164  
   1.165      NdisQueryPacket(curr_packet, NULL, NULL, NULL, &pkt_size);
   1.166  
   1.167 +    KdPrint(("sending pkt, len %d\n", pkt_size));
   1.168 +
   1.169      pmdl = XenNet_Linearize(curr_packet);
   1.170      if (!pmdl)
   1.171      {