55
55
#include "vmxnet_version.h"
57
#ifdef BPF_SUPPORT_ENABLED
59
#include "compat_highmem.h"
62
57
static int vmxnet_debug = 1;
64
#define VMXNET_WATCHDOG_TIMEOUT (5 * HZ)
59
#define VMXNET_WATCHDOG_TIMEOUT (5 * HZ)
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);
76
71
static compat_irqreturn_t vmxnet_interrupt(int irq, void *dev_id);
205
#ifdef SET_ETHTOOL_OPS
207
*----------------------------------------------------------------------------
209
* vmxnet_get_settings --
211
* Get device-specific settings.
214
* 0 on success, errno on failure.
219
*----------------------------------------------------------------------------
223
vmxnet_get_settings(struct net_device *dev,
224
struct ethtool_cmd *ecmd)
226
ecmd->supported = SUPPORTED_1000baseT_Full | SUPPORTED_TP;
227
ecmd->advertising = ADVERTISED_TP;
228
ecmd->port = PORT_TP;
229
ecmd->transceiver = XCVR_INTERNAL;
231
if (netif_carrier_ok(dev)) {
233
ecmd->duplex = DUPLEX_FULL;
243
*----------------------------------------------------------------------------
245
* vmxnet_get_drvinfo --
247
* Ethtool callback to return driver information
255
*----------------------------------------------------------------------------
259
vmxnet_get_drvinfo(struct net_device *dev,
260
struct ethtool_drvinfo *drvinfo)
262
struct Vmxnet_Private *lp = dev->priv;
264
strncpy(drvinfo->driver, vmxnet_driver.name, sizeof(drvinfo->driver));
265
drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
267
strncpy(drvinfo->version, VMXNET_DRIVER_VERSION_STRING,
268
sizeof(drvinfo->version));
269
drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
271
strncpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
272
drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
274
strncpy(drvinfo->bus_info, compat_pci_name(lp->pdev), ETHTOOL_BUSINFO_LEN);
279
*----------------------------------------------------------------------------
283
* Ethtool handler to set TSO. If the data is non-zero, TSO is
284
* enabled. Othewrise, it is disabled.
287
* 0 if successful, error code otherwise.
292
*----------------------------------------------------------------------------
297
vmxnet_set_tso(struct net_device *dev, u32 data)
300
struct Vmxnet_Private *lp = (struct Vmxnet_Private *)dev->priv;
305
dev->features |= NETIF_F_TSO;
307
dev->features &= ~NETIF_F_TSO;
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,
322
.get_tso = ethtool_op_get_tso,
323
.set_tso = vmxnet_set_tso,
328
#else /* !defined(SET_ETHTOOL_OPS) */
211
332
*----------------------------------------------------------------------------
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;
590
713
unsigned int driverDataSize;
791
#ifdef BPF_SUPPORT_ENABLED
792
if(lp->capabilities & VMNET_CAP_BPF &&
793
lp->features & VMXNET_FEATURE_BPF) {
794
dev->features |= NETIF_F_BPF;
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)) {
922
/* determine rx/tx ring sizes */
924
maxNumRxBuffers = ENHANCED_VMXNET2_MAX_NUM_RX_BUFFERS;
925
defNumRxBuffers = ENHANCED_VMXNET2_DEFAULT_NUM_RX_BUFFERS;
927
maxNumRxBuffers = VMXNET2_MAX_NUM_RX_BUFFERS;
928
defNumRxBuffers = VMXNET2_DEFAULT_NUM_RX_BUFFERS;
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;
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;
813
943
numRxBuffers2 = 1;
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;
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),
891
1022
if (lp->partialHeaderCopyEnabled) {
892
1023
unsigned int txBufferSize;
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;
1126
1262
return -ENOMEM;
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;
1138
1274
// dummy rxRing2 tacked on to the end, with a single unusable entry
1282
1418
* vmxnet_map_pkt --
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.
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).
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.
1427
* available. The caller should also ensure that enough tx entries are
1428
* available for this pkt.
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)
1304
* 4. txDriverNext is advanced accordingly
1440
* 4. txDriverNext is advanced accordingly
1306
1442
*-----------------------------------------------------------------------------
1310
vmxnet_map_pkt(struct sk_buff *skb,
1446
vmxnet_map_pkt(struct sk_buff *skb,
1312
1448
struct Vmxnet_Private *lp,
1313
1449
int startSgIdx)
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,
1335
skb_headlen(skb) - offset,
1468
/* we need to map some of the non-frag data. */
1469
dma = pci_map_single(lp->pdev,
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;
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,
1378
1514
frag->page_offset,
1380
1516
PCI_DMA_TODEVICE);
1382
1518
if (nextSg == VMXNET2_SG_DEFAULT_LENGTH) {
1383
1519
xre->flags = VMXNET2_TX_MORE;
1384
1520
xre->sg.length = VMXNET2_SG_DEFAULT_LENGTH;
1388
// move to the next tx entry
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];
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);
1397
* we change it even before the sg are populated but this is
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
1517
1653
#ifdef VMXNET_DO_ZERO_COPY
1518
1654
if (lp->zeroCopyTx) {
1519
1655
int txEntries, sgCount;
1520
unsigned int headerSize;
1656
unsigned int headerSize;
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;
1526
1662
if (UNLIKELY(!lp->chainTx && txEntries > 1)) {
1528
1664
* rare case, no tx desc chaining support but the pkt need more than 1
1529
1665
* tx entry, linearize it
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);
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);
1543
1679
spin_lock_irqsave(&lp->txLock, flags);
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);
1981
2113
if (rre->flags & VMXNET2_RX_HW_XSUM_OK) {
1982
2114
skb->ip_summed = CHECKSUM_UNNECESSARY;
1984
#ifdef BPF_SUPPORT_ENABLED
1986
meta = (struct BPF_MetaData *)skb->cb;
1988
if(rre->flags & VMXNET2_RX_BPF_TRAILER) {
1990
int numFrags = skb_shinfo(skb)->nr_frags;
1994
/* If fragments are present, the trailer is present in the
1995
* last fragement. Map it and remove the trailer
1997
vaddr = kmap_atomic(skb_shinfo(skb)->frags[numFrags - 1].page,
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);
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;
2014
/* The trailer is present in the linear data array */
2016
vaddr = (char *)skb->data;
2018
memcpy(meta->bpfSnapLens, vaddr + skb->len,
2019
sizeof meta->bpfSnapLens);
2022
meta->controlByte |= VMXNET_BPF_PROCESSED;
2025
meta->controlByte = 0;
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);