~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to modules/linux/vmxnet/vmxnet.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *
17
17
 *********************************************************/
18
18
 
19
 
/* 
 
19
/*
20
20
 * vmxnet.c: A virtual network driver for VMware.
21
21
 */
22
22
#include "driver-config.h"
25
25
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
26
26
#include <linux/moduleparam.h>
27
27
#endif
28
 
   
 
28
 
29
29
#include "compat_slab.h"
30
30
#include "compat_spinlock.h"
31
31
#include "compat_pci.h"
54
54
#include "net.h"
55
55
#include "vmxnet_version.h"
56
56
 
57
 
#ifdef BPF_SUPPORT_ENABLED
58
 
#include "bpf_meta.h"
59
 
#include "compat_highmem.h"
60
 
#endif
61
 
 
62
57
static int vmxnet_debug = 1;
63
58
 
64
 
#define VMXNET_WATCHDOG_TIMEOUT (5 * HZ) 
 
59
#define VMXNET_WATCHDOG_TIMEOUT (5 * HZ)
65
60
 
66
61
#if defined(CONFIG_NET_POLL_CONTROLLER) || defined(HAVE_POLL_CONTROLLER)
67
62
#define VMW_HAVE_POLL_CONTROLLER
70
65
static int vmxnet_open(struct net_device *dev);
71
66
static int vmxnet_start_tx(struct sk_buff *skb, struct net_device *dev);
72
67
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
73
 
static compat_irqreturn_t vmxnet_interrupt(int irq, void *dev_id, 
 
68
static compat_irqreturn_t vmxnet_interrupt(int irq, void *dev_id,
74
69
                                           struct pt_regs * regs);
75
70
#else
76
71
static compat_irqreturn_t vmxnet_interrupt(int irq, void *dev_id);
103
98
#endif
104
99
 
105
100
#if defined(MAX_SKB_FRAGS) && ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,18) ) && ( LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 0) )
106
 
#define VMXNET_DO_ZERO_COPY 
 
101
#define VMXNET_DO_ZERO_COPY
107
102
#endif
108
103
 
109
104
#ifdef VMXNET_DO_ZERO_COPY
112
107
#include <linux/in.h>
113
108
#include <linux/tcp.h>
114
109
 
115
 
/* 
 
110
/*
116
111
 * Tx buffer size that we need for copying header
117
112
 * max header is: 14(ip) + 4(vlan) + ip (60) + tcp(60) = 138
118
113
 * round it up to the power of 2
119
 
 */ 
 
114
 */
120
115
#define TX_PKT_HEADER_SIZE      256
121
116
 
122
117
/* Constants used for Zero Copy Tx */
149
144
 
150
145
#if defined(NETIF_F_GSO) /* 2.6.18 and upwards */
151
146
#define VMXNET_SKB_MSS(skb) skb_shinfo(skb)->gso_size
152
 
#else 
 
147
#else
153
148
#define VMXNET_SKB_MSS(skb) skb_shinfo(skb)->tso_size
154
149
#endif
155
150
#endif
158
153
 
159
154
#ifdef VMXNET_DEBUG
160
155
#define VMXNET_LOG(msg...) printk(KERN_ERR msg)
161
 
#else 
 
156
#else
162
157
#define VMXNET_LOG(msg...)
163
158
#endif // VMXNET_DEBUG
164
159
 
207
202
#endif
208
203
 
209
204
 
 
205
#ifdef SET_ETHTOOL_OPS
 
206
/*
 
207
 *----------------------------------------------------------------------------
 
208
 *
 
209
 * vmxnet_get_settings --
 
210
 *
 
211
 *      Get device-specific settings.
 
212
 *
 
213
 * Results:
 
214
 *      0 on success, errno on failure.
 
215
 *
 
216
 * Side effects:
 
217
 *      None.
 
218
 *
 
219
 *----------------------------------------------------------------------------
 
220
 */
 
221
 
 
222
static int
 
223
vmxnet_get_settings(struct net_device *dev,
 
224
                    struct ethtool_cmd *ecmd)
 
225
{
 
226
   ecmd->supported = SUPPORTED_1000baseT_Full | SUPPORTED_TP;
 
227
   ecmd->advertising = ADVERTISED_TP;
 
228
   ecmd->port = PORT_TP;
 
229
   ecmd->transceiver = XCVR_INTERNAL;
 
230
 
 
231
   if (netif_carrier_ok(dev)) {
 
232
      ecmd->speed = 1000;
 
233
      ecmd->duplex = DUPLEX_FULL;
 
234
   } else {
 
235
      ecmd->speed = -1;
 
236
      ecmd->duplex = -1;
 
237
   }
 
238
   return 0;
 
239
}
 
240
 
 
241
 
 
242
/*
 
243
 *----------------------------------------------------------------------------
 
244
 *
 
245
 * vmxnet_get_drvinfo --
 
246
 *
 
247
 *      Ethtool callback to return driver information
 
248
 *
 
249
 * Results:
 
250
 *      None.
 
251
 *
 
252
 * Side effects:
 
253
 *      Updates *drvinfo
 
254
 *
 
255
 *----------------------------------------------------------------------------
 
256
 */
 
257
 
 
258
static void
 
259
vmxnet_get_drvinfo(struct net_device *dev,
 
260
                   struct ethtool_drvinfo *drvinfo)
 
261
{
 
262
   struct Vmxnet_Private *lp = dev->priv;
 
263
 
 
264
   strncpy(drvinfo->driver, vmxnet_driver.name, sizeof(drvinfo->driver));
 
265
   drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
 
266
 
 
267
   strncpy(drvinfo->version, VMXNET_DRIVER_VERSION_STRING,
 
268
           sizeof(drvinfo->version));
 
269
   drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
 
270
 
 
271
   strncpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
 
272
   drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
 
273
 
 
274
   strncpy(drvinfo->bus_info, compat_pci_name(lp->pdev), ETHTOOL_BUSINFO_LEN);
 
275
}
 
276
 
 
277
 
 
278
/*
 
279
 *----------------------------------------------------------------------------
 
280
 *
 
281
 *  vmxnet_set_tso --
 
282
 *
 
283
 *    Ethtool handler to set TSO. If the data is non-zero, TSO is
 
284
 *    enabled. Othewrise, it is disabled.
 
285
 *
 
286
 *  Results:
 
287
 *    0 if successful, error code otherwise.
 
288
 *
 
289
 *  Side effects:
 
290
 *    None.
 
291
 *
 
292
 *----------------------------------------------------------------------------
 
293
 */
 
294
 
 
295
#ifdef VMXNET_DO_TSO
 
296
static int
 
297
vmxnet_set_tso(struct net_device *dev, u32 data)
 
298
{
 
299
   if (data) {
 
300
      struct Vmxnet_Private *lp = (struct Vmxnet_Private *)dev->priv;
 
301
 
 
302
      if (!lp->tso) {
 
303
         return -EINVAL;
 
304
      }
 
305
      dev->features |= NETIF_F_TSO;
 
306
   } else {
 
307
      dev->features &= ~NETIF_F_TSO;
 
308
   }
 
309
   return 0;
 
310
}
 
311
#endif
 
312
 
 
313
 
 
314
static struct ethtool_ops
 
315
vmxnet_ethtool_ops = {
 
316
   .get_settings        = vmxnet_get_settings,
 
317
   .get_drvinfo         = vmxnet_get_drvinfo,
 
318
   .get_link            = ethtool_op_get_link,
 
319
   .get_sg              = ethtool_op_get_sg,
 
320
   .set_sg              = ethtool_op_set_sg,
 
321
#ifdef VMXNET_DO_TSO
 
322
   .get_tso             = ethtool_op_get_tso,
 
323
   .set_tso             = vmxnet_set_tso,
 
324
#endif
 
325
};
 
326
 
 
327
 
 
328
#else   /* !defined(SET_ETHTOOL_OPS) */
 
329
 
 
330
 
210
331
/*
211
332
 *----------------------------------------------------------------------------
212
333
 *
295
416
   value.data = (dev->features & NETIF_F_TSO) ? 1 : 0;
296
417
   if (copy_to_user(addr, &value, sizeof(value))) {
297
418
       return -EFAULT;
298
 
   } 
 
419
   }
299
420
   return 0;
300
421
}
301
422
#endif
326
447
   if (copy_from_user(&value, addr, sizeof(value))) {
327
448
      return -EFAULT;
328
449
   }
329
 
   
 
450
 
330
451
   if (value.data) {
331
452
      struct Vmxnet_Private *lp = (struct Vmxnet_Private *)dev->priv;
332
453
 
346
467
 *----------------------------------------------------------------------------
347
468
 *
348
469
 *  vmxnet_ethtool_ioctl --
349
 
 * 
 
470
 *
350
471
 *    Handler for ethtool ioctl calls.
351
472
 *
352
473
 *  Results:
378
499
#endif
379
500
#ifdef VMXNET_DO_TSO
380
501
      case ETHTOOL_GTSO:
381
 
         return vmxnet_get_tso(dev, ifr->ifr_data);         
 
502
         return vmxnet_get_tso(dev, ifr->ifr_data);
382
503
      case ETHTOOL_STSO:
383
504
         return vmxnet_set_tso(dev, ifr->ifr_data);
384
505
#endif
419
540
   printk(KERN_DEBUG" ioctl operation %d not supported\n", cmd);
420
541
   return -EOPNOTSUPP;
421
542
}
 
543
#endif /* SET_ETHTOOL_OPS */
422
544
 
423
545
 
424
546
/*
583
705
   unsigned int irq_line;
584
706
   /* VMware's version of the magic number */
585
707
   unsigned int low_vmware_version;
586
 
   unsigned int numRxBuffers, numRxBuffers2;
 
708
   unsigned int numRxBuffers, numRxBuffers2, maxNumRxBuffers, defNumRxBuffers;
587
709
   unsigned int numTxBuffers, maxNumTxBuffers, defNumTxBuffers;
588
710
   Bool morphed = FALSE;
 
711
   Bool enhanced = FALSE;
589
712
   int i;
590
713
   unsigned int driverDataSize;
591
714
 
771
894
 
772
895
#ifdef VMXNET_DO_TSO
773
896
   if ((lp->capabilities & VMNET_CAP_TSO) &&
774
 
       (lp->capabilities & (VMNET_CAP_IP4_CSUM | VMNET_CAP_HW_CSUM)) && 
 
897
       (lp->capabilities & (VMNET_CAP_IP4_CSUM | VMNET_CAP_HW_CSUM)) &&
775
898
       // tso only makes sense if we have hw csum offload
776
899
       lp->chainTx && lp->zeroCopyTx &&
777
900
       lp->features & VMXNET_FEATURE_TSO) {
788
911
#endif
789
912
#endif
790
913
 
791
 
#ifdef BPF_SUPPORT_ENABLED
792
 
    if(lp->capabilities & VMNET_CAP_BPF && 
793
 
       lp->features & VMXNET_FEATURE_BPF) {
794
 
       dev->features |= NETIF_F_BPF;
795
 
       printk(" bpf");
796
 
    }    
797
 
#endif
798
 
 
799
 
 
800
 
 
801
914
   printk("\n");
802
915
 
803
 
   /* determine rx/tx ring sizes */
 
916
   /* check if this is enhanced vmxnet device */
 
917
   if ((lp->features & VMXNET_FEATURE_TSO) && 
 
918
       (lp->features & VMXNET_FEATURE_JUMBO_FRAME)) {
 
919
        enhanced = TRUE;
 
920
   }
 
921
 
 
922
   /* determine rx/tx ring sizes */ 
 
923
   if (enhanced) {
 
924
      maxNumRxBuffers = ENHANCED_VMXNET2_MAX_NUM_RX_BUFFERS;
 
925
      defNumRxBuffers = ENHANCED_VMXNET2_DEFAULT_NUM_RX_BUFFERS;
 
926
   } else {
 
927
      maxNumRxBuffers = VMXNET2_MAX_NUM_RX_BUFFERS;
 
928
      defNumRxBuffers = VMXNET2_DEFAULT_NUM_RX_BUFFERS;
 
929
   }
 
930
 
804
931
   outl(VMXNET_CMD_GET_NUM_RX_BUFFERS, dev->base_addr + VMXNET_COMMAND_ADDR);
805
932
   numRxBuffers = inl(dev->base_addr + VMXNET_COMMAND_ADDR);
806
 
   if (numRxBuffers == 0 || numRxBuffers > VMXNET2_MAX_NUM_RX_BUFFERS) {
807
 
      numRxBuffers = VMXNET2_DEFAULT_NUM_RX_BUFFERS;
 
933
   if (numRxBuffers == 0 || numRxBuffers > maxNumRxBuffers) {
 
934
      numRxBuffers = defNumRxBuffers;
808
935
   }
809
936
 
810
937
   if (lp->jumboFrame || lp->lpd) {
811
938
      numRxBuffers2 = numRxBuffers * 4;
 
939
      if (numRxBuffers2 > VMXNET2_MAX_NUM_RX_BUFFERS2) {
 
940
         numRxBuffers2 = VMXNET2_MAX_NUM_RX_BUFFERS2;
 
941
      }
812
942
   } else {
813
943
      numRxBuffers2 = 1;
814
944
   }
815
945
 
 
946
   printk("numRxBuffers = %d, numRxBuffers2 = %d\n", numRxBuffers, numRxBuffers2);
816
947
   if (lp->tso || lp->jumboFrame) {
817
948
      maxNumTxBuffers = VMXNET2_MAX_NUM_TX_BUFFERS_TSO;
818
949
      defNumTxBuffers = VMXNET2_DEFAULT_NUM_TX_BUFFERS_TSO;
829
960
 
830
961
   driverDataSize =
831
962
            sizeof(Vmxnet2_DriverData) +
832
 
            (numRxBuffers + numRxBuffers2) * sizeof(Vmxnet2_RxRingEntry) + 
 
963
            (numRxBuffers + numRxBuffers2) * sizeof(Vmxnet2_RxRingEntry) +
833
964
            numTxBuffers * sizeof(Vmxnet2_TxRingEntry);
834
965
   VMXNET_LOG("vmxnet: numRxBuffers=((%d+%d)*%d) numTxBuffers=(%d*%d) driverDataSize=%d\n",
835
966
              numRxBuffers, numRxBuffers2, (uint32)sizeof(Vmxnet2_RxRingEntry),
890
1021
 
891
1022
   if (lp->partialHeaderCopyEnabled) {
892
1023
      unsigned int txBufferSize;
893
 
      
 
1024
 
894
1025
      txBufferSize = numTxBuffers * TX_PKT_HEADER_SIZE;
895
1026
      lp->txBufferStartRaw = kmalloc(txBufferSize + PAGE_SIZE,
896
1027
                                     GFP_DMA | GFP_KERNEL);
897
1028
      if (lp->txBufferStartRaw) {
898
 
         lp->txBufferStart = (char*)((unsigned long)(lp->txBufferStartRaw + PAGE_SIZE - 1) & 
 
1029
         lp->txBufferStart = (char*)((unsigned long)(lp->txBufferStartRaw + PAGE_SIZE - 1) &
899
1030
                                     (unsigned long)~(PAGE_SIZE - 1));
900
 
         lp->dd->txBufferPhysStart = virt_to_phys(lp->txBufferStart); 
 
1031
         lp->dd->txBufferPhysStart = virt_to_phys(lp->txBufferStart);
901
1032
         lp->dd->txBufferPhysLength = txBufferSize;
902
1033
         lp->dd->txPktMaxSize = TX_PKT_HEADER_SIZE;
903
1034
      } else {
927
1058
 
928
1059
   /* Do this after ether_setup(), which sets the default value. */
929
1060
   dev->set_mac_address = &vmxnet_set_mac_address;
 
1061
 
 
1062
#ifdef SET_ETHTOOL_OPS
 
1063
   SET_ETHTOOL_OPS(dev, &vmxnet_ethtool_ops);
 
1064
#else
930
1065
   dev->do_ioctl = vmxnet_ioctl;
 
1066
#endif
931
1067
 
932
1068
   COMPAT_SET_MODULE_OWNER(dev);
933
1069
   COMPAT_SET_NETDEV_DEV(dev, &pdev->dev);
1070
1206
   dd->rxRingOffset = offset;
1071
1207
   lp->rxRing = (Vmxnet2_RxRingEntry *)((uintptr_t)dd + offset);
1072
1208
   offset += lp->numRxBuffers * sizeof(Vmxnet2_RxRingEntry);
1073
 
   
 
1209
 
1074
1210
   dd->rxRingLength2 = lp->numRxBuffers2;
1075
1211
   dd->rxRingOffset2 = offset;
1076
1212
   lp->rxRing2 = (Vmxnet2_RxRingEntry *)((uintptr_t)dd + offset);
1081
1217
   lp->txRing = (Vmxnet2_TxRingEntry *)((uintptr_t)dd + offset);
1082
1218
   offset += lp->numTxBuffers * sizeof(Vmxnet2_TxRingEntry);
1083
1219
 
1084
 
   VMXNET_LOG("vmxnet_init_ring: offset=%"FMT64"d length=%d\n", 
 
1220
   VMXNET_LOG("vmxnet_init_ring: offset=%"FMT64"d length=%d\n",
1085
1221
              (uint64)offset, dd->length);
1086
1222
 
1087
1223
   for (i = 0; i < lp->numRxBuffers; i++) {
1126
1262
            return -ENOMEM;
1127
1263
         }
1128
1264
 
1129
 
         lp->rxRing2[i].paddr = pci_map_page(pdev, lp->rxPages[i], 0, 
 
1265
         lp->rxRing2[i].paddr = pci_map_page(pdev, lp->rxPages[i], 0,
1130
1266
                                             PAGE_SIZE, PCI_DMA_FROMDEVICE);
1131
1267
         lp->rxRing2[i].bufferLength = PAGE_SIZE;
1132
1268
         lp->rxRing2[i].actualLength = 0;
1133
1269
         lp->rxRing2[i].ownership = VMXNET2_OWNERSHIP_NIC_FRAG;
1134
1270
      }
1135
 
   } else 
 
1271
   } else
1136
1272
#endif
1137
1273
   {
1138
1274
      // dummy rxRing2 tacked on to the end, with a single unusable entry
1236
1372
 *
1237
1373
 * vmxnet_unmap_buf  --
1238
1374
 *
1239
 
 *      Unmap the PAs of the tx entry that we pinned for DMA. 
 
1375
 *      Unmap the PAs of the tx entry that we pinned for DMA.
1240
1376
 *
1241
1377
 * Results:
1242
1378
 *      None.
1247
1383
 */
1248
1384
 
1249
1385
void
1250
 
vmxnet_unmap_buf(struct sk_buff *skb, 
 
1386
vmxnet_unmap_buf(struct sk_buff *skb,
1251
1387
                 struct Vmxnet2_TxBuf *tb,
1252
1388
                 Vmxnet2_TxRingEntry *xre,
1253
1389
                 struct pci_dev *pdev)
1281
1417
 *
1282
1418
 * vmxnet_map_pkt  --
1283
1419
 *
1284
 
 *      Map the buffers/pages that we need for DMA and populate the SG. 
 
1420
 *      Map the buffers/pages that we need for DMA and populate the SG.
1285
1421
 *
1286
1422
 *      "offset" indicates the position inside the pkt where mapping should start.
1287
1423
 *      "startSgIdx" indicates the first free sg slot of the first tx entry
1288
1424
 *      (pointed to by txDriverNext).
1289
1425
 *
1290
1426
 *      The caller should guarantee the first tx has at least one sg slot
1291
 
 *      available. The caller should also ensure that enough tx entries are 
1292
 
 *      available for this pkt. 
1293
 
 *      
 
1427
 *      available. The caller should also ensure that enough tx entries are
 
1428
 *      available for this pkt.
 
1429
 *
1294
1430
 * Results:
1295
1431
 *      None.
1296
1432
 *
1297
1433
 * Side effects:
1298
 
 *      1. Ownership of all tx entries used (EXCEPT the 1st one) are updated. 
1299
 
 *         The only flag set is VMXNET2_TX_MORE if needed. caller is 
 
1434
 *      1. Ownership of all tx entries used (EXCEPT the 1st one) are updated.
 
1435
 *         The only flag set is VMXNET2_TX_MORE if needed. caller is
1300
1436
 *         responsible to set up other flags after this call returns.
1301
1437
 *      2. lp->dd->numTxPending is updated
1302
1438
 *      3. txBufInfo corresponding to used tx entries (including the 1st one)
1303
1439
 *         are updated
1304
 
 *      4. txDriverNext is advanced accordingly 
 
1440
 *      4. txDriverNext is advanced accordingly
1305
1441
 *
1306
1442
 *-----------------------------------------------------------------------------
1307
1443
 */
1308
1444
 
1309
1445
void
1310
 
vmxnet_map_pkt(struct sk_buff *skb, 
1311
 
               int offset, 
 
1446
vmxnet_map_pkt(struct sk_buff *skb,
 
1447
               int offset,
1312
1448
               struct Vmxnet_Private *lp,
1313
1449
               int startSgIdx)
1314
1450
{
1318
1454
   Vmxnet2_TxRingEntry *xre;
1319
1455
   struct Vmxnet2_TxBuf *tb;
1320
1456
   dma_addr_t dma;
1321
 
  
 
1457
 
1322
1458
   VMXNET_ASSERT(startSgIdx < VMXNET2_SG_DEFAULT_LENGTH);
1323
1459
 
1324
1460
   lp->numTxPending ++;
1329
1465
      tb->sgForLinear = -1;
1330
1466
      tb->firstSgForFrag = nextSg;
1331
1467
   } else if (offset < skb_headlen(skb)) {
1332
 
      /* we need to map some of the non-frag data. */ 
1333
 
      dma = pci_map_single(lp->pdev, 
1334
 
                           skb->data + offset, 
1335
 
                           skb_headlen(skb) - offset, 
 
1468
      /* we need to map some of the non-frag data. */
 
1469
      dma = pci_map_single(lp->pdev,
 
1470
                           skb->data + offset,
 
1471
                           skb_headlen(skb) - offset,
1336
1472
                           PCI_DMA_TODEVICE);
1337
1473
      VMXNET_FILL_SG(xre->sg.sg[nextSg], dma, skb_headlen(skb) - offset);
1338
 
      VMXNET_LOG("vmxnet_map_pkt: txRing[%u].sg[%d] -> data %p offset %u size %u\n", 
 
1474
      VMXNET_LOG("vmxnet_map_pkt: txRing[%u].sg[%d] -> data %p offset %u size %u\n",
1339
1475
                 dd->txDriverNext, nextSg, skb->data, offset, skb_headlen(skb) - offset);
1340
1476
      tb->sgForLinear = nextSg++;
1341
1477
      tb->firstSgForFrag = nextSg;
1348
1484
 
1349
1485
      for ( ; nextFrag < skb_shinfo(skb)->nr_frags; nextFrag++){
1350
1486
         frag = &skb_shinfo(skb)->frags[nextFrag];
1351
 
         
1352
 
         // skip those frags that are completely copied 
 
1487
 
 
1488
         // skip those frags that are completely copied
1353
1489
         if (offset >= frag->size){
1354
1490
            offset -= frag->size;
1355
1491
         } else {
1364
1500
                       dd->txDriverNext, nextSg, nextFrag, offset, frag->size - offset);
1365
1501
            nextSg++;
1366
1502
            nextFrag++;
1367
 
            
 
1503
 
1368
1504
            break;
1369
1505
         }
1370
1506
      }
1373
1509
   // map the remaining frags, we might need to use additional tx entries
1374
1510
   for ( ; nextFrag < skb_shinfo(skb)->nr_frags; nextFrag++) {
1375
1511
      frag = &skb_shinfo(skb)->frags[nextFrag];
1376
 
      dma = pci_map_page(lp->pdev, 
 
1512
      dma = pci_map_page(lp->pdev,
1377
1513
                         frag->page,
1378
1514
                         frag->page_offset,
1379
1515
                         frag->size,
1380
1516
                         PCI_DMA_TODEVICE);
1381
 
      
 
1517
 
1382
1518
      if (nextSg == VMXNET2_SG_DEFAULT_LENGTH) {
1383
1519
         xre->flags = VMXNET2_TX_MORE;
1384
1520
         xre->sg.length = VMXNET2_SG_DEFAULT_LENGTH;
1385
1521
         tb->skb = skb;
1386
1522
         tb->eop = 0;
1387
 
         
1388
 
         // move to the next tx entry 
 
1523
 
 
1524
         // move to the next tx entry
1389
1525
         VMXNET_INC(dd->txDriverNext, dd->txRingLength);
1390
1526
         xre = &lp->txRing[dd->txDriverNext];
1391
1527
         tb = &lp->txBufInfo[dd->txDriverNext];
1392
1528
 
1393
1529
         // the new tx entry must be available
1394
 
         VMXNET_ASSERT(xre->ownership == VMXNET2_OWNERSHIP_DRIVER && tb->skb == NULL); 
 
1530
         VMXNET_ASSERT(xre->ownership == VMXNET2_OWNERSHIP_DRIVER && tb->skb == NULL);
1395
1531
 
1396
 
         /* 
1397
 
          * we change it even before the sg are populated but this is 
 
1532
         /*
 
1533
          * we change it even before the sg are populated but this is
1398
1534
          * fine, because the first tx entry's ownership is not
1399
1535
          * changed yet
1400
1536
          */
1517
1653
#ifdef VMXNET_DO_ZERO_COPY
1518
1654
   if (lp->zeroCopyTx) {
1519
1655
      int txEntries, sgCount;
1520
 
      unsigned int headerSize;         
1521
 
   
 
1656
      unsigned int headerSize;
 
1657
 
1522
1658
      /* conservatively estimate the # of tx entries needed in the worse case */
1523
1659
      sgCount = (lp->partialHeaderCopyEnabled ? 2 : 1) + skb_shinfo(skb)->nr_frags;
1524
1660
      txEntries = (sgCount + VMXNET2_SG_DEFAULT_LENGTH - 1) / VMXNET2_SG_DEFAULT_LENGTH;
1525
1661
 
1526
1662
      if (UNLIKELY(!lp->chainTx && txEntries > 1)) {
1527
 
         /* 
 
1663
         /*
1528
1664
          * rare case, no tx desc chaining support but the pkt need more than 1
1529
1665
          * tx entry, linearize it
1530
 
          */ 
 
1666
          */
1531
1667
         if (compat_skb_linearize(skb) != 0) {
1532
1668
            VMXNET_LOG("vmxnet_tx: skb_linearize failed\n");
1533
1669
            compat_dev_kfree_skb(skb, FREE_WRITE);
1537
1673
         txEntries = 1;
1538
1674
      }
1539
1675
 
1540
 
      VMXNET_LOG("\n%d(%d) bytes, %d frags, %d tx entries\n", skb->len, 
 
1676
      VMXNET_LOG("\n%d(%d) bytes, %d frags, %d tx entries\n", skb->len,
1541
1677
                 skb_headlen(skb), skb_shinfo(skb)->nr_frags, txEntries);
1542
1678
 
1543
1679
      spin_lock_irqsave(&lp->txLock, flags);
1552
1688
         VMXNET_LOG("queue stopped\n");
1553
1689
         return VMXNET_STOP_TRANSMIT;
1554
1690
      }
1555
 
    
 
1691
 
1556
1692
      /* copy protocol headers if needed */
1557
1693
      if (LIKELY(lp->partialHeaderCopyEnabled)) {
1558
1694
         unsigned int pos = dd->txDriverNext * dd->txPktMaxSize;
1637
1773
               }
1638
1774
            }
1639
1775
         }
1640
 
             
 
1776
 
1641
1777
         if (skb_copy_bits(skb, 0, header, headerSize) != 0) {
1642
1778
            compat_dev_kfree_skb(skb, FREE_WRITE);
1643
1779
            spin_unlock_irqrestore(&lp->txLock, flags);
1679
1815
         spin_unlock_irqrestore(&lp->txLock, flags);
1680
1816
         return VMXNET_STOP_TRANSMIT;
1681
1817
      }
1682
 
     
 
1818
 
1683
1819
      lp->numTxPending ++;
1684
1820
 
1685
1821
      xre->sg.sg[0].addrLow = virt_to_bus(skb->data);
1703
1839
   if (skb->ip_summed == VM_TX_CHECKSUM_PARTIAL) {
1704
1840
      xre->flags |= VMXNET2_TX_HW_XSUM | VMXNET2_TX_CAN_KEEP;
1705
1841
   } else {
1706
 
      xre->flags |= VMXNET2_TX_CAN_KEEP;         
 
1842
      xre->flags |= VMXNET2_TX_CAN_KEEP;
1707
1843
   }
1708
1844
   if (lp->numTxPending > dd->txRingLength - 5) {
1709
1845
      xre->flags |= VMXNET2_TX_RING_LOW;
1811
1947
 * vmxnet_rx_frags --
1812
1948
 *
1813
1949
 *    get data from the 2nd rx ring and append the frags to the skb. Multiple
1814
 
 *    rx entries in the 2nd rx ring are processed until the one with 
 
1950
 *    rx entries in the 2nd rx ring are processed until the one with
1815
1951
 *    VMXNET2_RX_FRAG_EOP set.
1816
1952
 *
1817
1953
 * Result:
1840
1976
      rre2 = &lp->rxRing2[dd->rxDriverNext2];
1841
1977
      flags = rre2->flags;
1842
1978
      VMXNET_ASSERT(rre2->ownership == VMXNET2_OWNERSHIP_DRIVER_FRAG);
1843
 
      
 
1979
 
1844
1980
      if (rre2->actualLength > 0) {
1845
1981
         newPage = alloc_page(GFP_ATOMIC);
1846
1982
         if (UNLIKELY(newPage == NULL)) {
1878
2014
   skb_shinfo(skb)->nr_frags = numFrags;
1879
2015
   skb->len += skb->data_len;
1880
2016
   skb->truesize += skb->data_len;
1881
 
   VMXNET_LOG("vmxnet_rx: %dB from rxRing[%d](%dB)+rxRing2[%d, %d)(%dB)\n", 
1882
 
              skb->len, dd->rxDriverNext, skb_headlen(skb), 
 
2017
   VMXNET_LOG("vmxnet_rx: %dB from rxRing[%d](%dB)+rxRing2[%d, %d)(%dB)\n",
 
2018
              skb->len, dd->rxDriverNext, skb_headlen(skb),
1883
2019
              firstFrag, dd->rxDriverNext2, skb->data_len);
1884
2020
   return 0;
1885
2021
}
1906
2042
   Vmxnet_Private *lp = (Vmxnet_Private *)dev->priv;
1907
2043
   Vmxnet2_DriverData *dd = lp->dd;
1908
2044
 
1909
 
#ifdef BPF_SUPPORT_ENABLED
1910
 
   struct BPF_MetaData *meta = NULL;
1911
 
#endif
1912
 
 
1913
2045
   if (!lp->devOpen) {
1914
2046
      return 0;
1915
2047
   }
1942
2074
#ifdef VMXNET_DO_ZERO_COPY
1943
2075
         if (rre->flags & VMXNET2_RX_WITH_FRAG) {
1944
2076
            vmxnet_drop_frags(lp);
1945
 
         } 
 
2077
         }
1946
2078
#endif
1947
2079
         lp->stats.rx_errors++;
1948
2080
         goto next_pkt;
1973
2105
          *  is stripped, such frames become ETH_MIN_FRAME_LEN - 4. (PR106153)
1974
2106
          */
1975
2107
         if (skb->len != 0) {
1976
 
            printk(KERN_DEBUG "%s: Runt pkt (%d bytes) entry %d!\n", dev->name, 
 
2108
            printk(KERN_DEBUG "%s: Runt pkt (%d bytes) entry %d!\n", dev->name,
1977
2109
                   skb->len, dd->rxDriverNext);
1978
2110
         }
1979
2111
         lp->stats.rx_errors++;
1981
2113
         if (rre->flags & VMXNET2_RX_HW_XSUM_OK) {
1982
2114
            skb->ip_summed = CHECKSUM_UNNECESSARY;
1983
2115
         }
1984
 
#ifdef BPF_SUPPORT_ENABLED
1985
 
         
1986
 
         meta = (struct BPF_MetaData *)skb->cb;
1987
 
 
1988
 
         if(rre->flags & VMXNET2_RX_BPF_TRAILER) {
1989
 
            char *vaddr;
1990
 
            int numFrags = skb_shinfo(skb)->nr_frags;
1991
 
            
1992
 
            if (numFrags > 0) {
1993
 
 
1994
 
               /* If fragments are present, the trailer is present in the
1995
 
                * last fragement. Map it and remove the trailer 
1996
 
                */
1997
 
               vaddr = kmap_atomic(skb_shinfo(skb)->frags[numFrags - 1].page,
1998
 
                                   KM_USER0);
1999
 
               if (vaddr) {
2000
 
 
2001
 
                  memcpy(meta->bpfSnapLens, 
2002
 
                         vaddr + skb_shinfo(skb)->frags[numFrags-1].size, 
2003
 
                         sizeof meta->bpfSnapLens);
2004
 
                  kunmap_atomic((struct page *)vaddr, KM_USER0);
2005
 
 
2006
 
               } else  {
2007
 
                  printk(KERN_ERR"Error mapping Last Fragment of Packet\n");
2008
 
                  /* Act as if there was no bpf trailer at all*/
2009
 
                  meta->controlByte = 0;
2010
 
                  goto error;
2011
 
               }
2012
 
            } else { 
2013
 
 
2014
 
               /* The trailer is present in the linear data array */
2015
 
 
2016
 
               vaddr = (char *)skb->data;
2017
 
 
2018
 
               memcpy(meta->bpfSnapLens, vaddr + skb->len,
2019
 
                      sizeof meta->bpfSnapLens);
2020
 
            }
2021
 
 
2022
 
            meta->controlByte |= VMXNET_BPF_PROCESSED;
2023
 
 
2024
 
         } else {
2025
 
            meta->controlByte = 0;
2026
 
         }
2027
 
error:
2028
 
#endif
2029
2116
 
2030
2117
         skb->dev = dev;
2031
2118
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
2179
2266
   spin_lock_irqsave(&lp->txLock, flags);
2180
2267
   if (lp->numTxPending > 0) {
2181
2268
      //Wait absurdly long (2sec) for all the pending packets to be returned.
2182
 
      printk(KERN_DEBUG "vmxnet_close: Pending tx = %d\n", lp->numTxPending); 
 
2269
      printk(KERN_DEBUG "vmxnet_close: Pending tx = %d\n", lp->numTxPending);
2183
2270
      for (i = 0; i < 200 && lp->numTxPending > 0; i++) {
2184
2271
         outl(VMXNET_CMD_CHECK_TX_DONE, dev->base_addr + VMXNET_COMMAND_ADDR);
2185
2272
         udelay(10000);
2198
2285
      }
2199
2286
   }
2200
2287
   spin_unlock_irqrestore(&lp->txLock, flags);
2201
 
   
 
2288
 
2202
2289
   outl(0, ioaddr + VMXNET_INIT_ADDR);
2203
2290
 
2204
2291
   free_irq(dev->irq, dev);
2247
2334
 *
2248
2335
 *-----------------------------------------------------------------------------
2249
2336
 */
2250
 
static int 
 
2337
static int
2251
2338
vmxnet_load_multicast (struct net_device *dev)
2252
2339
{
2253
2340
    Vmxnet_Private *lp = (Vmxnet_Private *) dev->priv;
2307
2394
 *
2308
2395
 *-----------------------------------------------------------------------------
2309
2396
 */
2310
 
static void 
 
2397
static void
2311
2398
vmxnet_set_multicast_list(struct net_device *dev)
2312
2399
{
2313
2400
   unsigned int ioaddr = dev->base_addr;
2334
2421
         lp->dd->ifflags |= VMXNET_IFF_MULTICAST;
2335
2422
      }
2336
2423
   }
2337
 
   outl(VMXNET_CMD_UPDATE_LADRF, ioaddr + VMXNET_COMMAND_ADDR);        
 
2424
   outl(VMXNET_CMD_UPDATE_LADRF, ioaddr + VMXNET_COMMAND_ADDR);
2338
2425
 
2339
2426
   outl(VMXNET_CMD_UPDATE_IFF, ioaddr + VMXNET_COMMAND_ADDR);
2340
2427
}