~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to modules/linux/vmxnet3/vmxnet3_drv.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-10-18 12:28:19 UTC
  • mfrom: (1.1.7 upstream) (2.4.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091018122819-00vqew6m0ztpqcqp
Tags: 2009.10.15-201664-1
MergingĀ upstreamĀ versionĀ 2009.10.15-201664.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
#include <linux/if_arp.h>
65
65
#include <linux/inetdevice.h>
66
66
 
 
67
#ifdef CONFIG_COMPAT
 
68
#ifndef HAVE_UNLOCKED_IOCTL
 
69
#include <linux/ioctl32.h>
 
70
#endif
 
71
#endif
 
72
 
67
73
#include "vm_basic_types.h"
68
74
#include "vmnet_def.h"
69
75
#include "vm_device_version.h"
149
155
static int enable_shm[VMXNET3_SHM_MAX_DEVICES + 1] =
150
156
   { [0 ... VMXNET3_SHM_MAX_DEVICES] = -1 };
151
157
static char *shm_disclaimer = NULL;
152
 
#define VMXNET3_SHM_DISCLAIMER "IReallyWantThisModeIAmAVMSafePartner"
 
158
static int correct_shm_disclaimer;
 
159
#define VMXNET3_SHM_DISCLAIMER "IReallyWantThisModeIAmAVMwarePartner"
153
160
 
154
161
/*
155
162
 *----------------------------------------------------------------------------
909
916
      memcpy(tdd->data,
910
917
             virt,
911
918
             ctx->copy_size);
912
 
      kunmap(virt);
 
919
      kunmap(VMXNET3_SHM_IDX2PAGE(adapter->shm, VMXNET3_SHM_SKB_GETIDX(skb)));
913
920
   }
914
921
   VMXNET3_LOG("copy %u bytes to dataRing[%u]\n",
915
922
               ctx->copy_size, tq->tx_ring.next2fill);
1016
1023
               tq->stats.drop_too_many_frags++;
1017
1024
               goto drop_pkt;
1018
1025
            }
1019
 
         }
1020
 
 
1021
 
         /* non-tso pkts must not use more than VMXNET3_MAX_TXD_PER_PKT entries */
1022
 
         if (compat_skb_linearize(skb) != 0) {
1023
 
            tq->stats.drop_too_many_frags++;
1024
 
            goto drop_pkt;
1025
 
         }
1026
 
         tq->stats.linearized++;
1027
 
 
1028
 
         /* recalculate the # of descriptors to use */
1029
 
         count = VMXNET3_TXD_NEEDED(vmxnet3_skb_headlen(adapter, skb)) + 1;
 
1026
         } else {
 
1027
            /* non-tso pkts must not use more than VMXNET3_MAX_TXD_PER_PKT entries */
 
1028
            if (compat_skb_linearize(skb) != 0) {
 
1029
               tq->stats.drop_too_many_frags++;
 
1030
               goto drop_pkt;
 
1031
            }
 
1032
            tq->stats.linearized++;
 
1033
 
 
1034
            /* recalculate the # of descriptors to use */
 
1035
            count = VMXNET3_TXD_NEEDED(vmxnet3_skb_headlen(adapter, skb)) + 1;
 
1036
         }
1030
1037
      }
1031
1038
   }
1032
1039
 
1670
1677
 *
1671
1678
 * vmxnet3_rx_error --
1672
1679
 *
1673
 
 *    called when ERR bit is set for a received pkt
 
1680
 *    called when ERR bit is set for a received pkt. The desc and the associated 
 
1681
 *    rx buffer have not been processed yet.
1674
1682
 *
1675
1683
 * Result:
1676
1684
 *    none
1677
1685
 *
1678
1686
 * Side-effects:
1679
1687
 *    1. up the stat counters
1680
 
 *    2. free the pkt
 
1688
 *    2. free the skb if needed
1681
1689
 *    3. reset ctx->skb
1682
1690
 *
1683
1691
 *----------------------------------------------------------------------------
1695
1703
   }
1696
1704
   rq->stats.drop_total++;
1697
1705
 
1698
 
   vmxnet3_dev_kfree_skb_irq(adapter, ctx->skb);
 
1706
   /* 
 
1707
    * We do not unmap and chain the rx buffer to the skb.
 
1708
    * We basically pretend this buffer is not used and will be recycled
 
1709
    * by vmxnet3_rq_alloc_rx_buf()
 
1710
    */
 
1711
 
 
1712
   /* 
 
1713
    * ctx->skb may be NULL if this is the first and the only one
 
1714
    * desc for the pkt
 
1715
    */
 
1716
   if (ctx->skb) {
 
1717
      vmxnet3_dev_kfree_skb_irq(adapter, ctx->skb);
 
1718
   }
1699
1719
   ctx->skb = NULL;
1700
1720
}
1701
1721
 
1754
1774
      VMXNET3_ASSERT(rcd->len <= rxd->len);
1755
1775
      VMXNET3_ASSERT(rxd->addr == rbi->dma_addr && rxd->len == rbi->len);
1756
1776
 
 
1777
      if (UNLIKELY(rcd->eop && rcd->err)) {
 
1778
         vmxnet3_rx_error(rq, rcd, ctx, adapter);
 
1779
         goto rcd_done;
 
1780
      }
 
1781
 
1757
1782
      if (rcd->sop) { /* first buf of the pkt */
1758
1783
         VMXNET3_ASSERT(rxd->btype == VMXNET3_RXD_BTYPE_HEAD &&
1759
1784
                        rcd->rqID == rq->qid);
1793
1818
               rbi->page = NULL;
1794
1819
            }
1795
1820
         } else {
1796
 
            /* the only time a non-SOP buffer is type 0 is when it's EOP and
1797
 
             * error flag is raised
 
1821
            /* 
 
1822
             * The only time a non-SOP buffer is type 0 is when it's EOP and
 
1823
             * error flag is raised, which has already been handled.
1798
1824
             */
1799
 
            if (UNLIKELY(rcd->err && rcd->eop)) {
1800
 
               /* pretend this buffer is skipped by the device.
1801
 
                * dont chain it and don't reset rbi->skb to NULL
1802
 
                */
1803
 
               VMXNET3_LOG("Err EOP is type 0 from ring[%u].rxd[%u]\n", ring_idx, idx);
1804
 
            } else {
1805
 
               /* bug in the device */
1806
 
               VMXNET3_ASSERT(FALSE);
1807
 
            }
 
1825
            VMXNET3_ASSERT(FALSE);
1808
1826
         }
1809
1827
      }
1810
1828
 
1811
1829
      skb = ctx->skb;
1812
1830
      if (rcd->eop) {
1813
 
         if (UNLIKELY(rcd->err)) {
1814
 
            vmxnet3_rx_error(rq, rcd, ctx, adapter);
1815
 
            goto rcd_done;
1816
 
         }
1817
 
 
1818
1831
         if (adapter->is_shm) {
1819
1832
            vmxnet3_shm_rx_skb(adapter, skb);
1820
1833
 
2461
2474
 *----------------------------------------------------------------------------
2462
2475
 */
2463
2476
 
2464
 
static int
 
2477
int
2465
2478
vmxnet3_activate_dev(struct vmxnet3_adapter *adapter)
2466
2479
{
2467
2480
   int err;
2566
2579
 *----------------------------------------------------------------------------
2567
2580
 */
2568
2581
 
2569
 
static int
 
2582
int
2570
2583
vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter)
2571
2584
{
2572
2585
   if (test_and_set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state)) {
2683
2696
   }
2684
2697
 
2685
2698
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 6)
2686
 
   if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
2687
 
      if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
 
2699
   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
 
2700
      if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
2688
2701
         printk(KERN_ERR "pci_set_consistent_dma_mask failed for adapter %s\n",
2689
2702
                compat_pci_name(pdev));
2690
2703
         err = -EIO;
2692
2705
      }
2693
2706
      *dma64 = TRUE;
2694
2707
   } else {
2695
 
      if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
 
2708
      if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
2696
2709
         printk(KERN_ERR "pci_set_dma_mask failed for adapter %s\n",
2697
2710
                compat_pci_name(pdev));
2698
2711
         err = -EIO;
3008
3021
   vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
3009
3022
   vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
3010
3023
queue_err:
3011
 
   vmxnet3_shm_close(adapter);
 
3024
   if (adapter->is_shm) {
 
3025
     vmxnet3_shm_close(adapter);
 
3026
   }
3012
3027
shm_err:
3013
3028
   return err;
3014
3029
}
3060
3075
 *
3061
3076
 *----------------------------------------------------------------------------
3062
3077
 */
3063
 
static void
 
3078
void
3064
3079
vmxnet3_force_close(struct vmxnet3_adapter *adapter)
3065
3080
{
3066
3081
   /* 
4183
4198
{
4184
4199
   struct vmxnet3_adapter *adapter;
4185
4200
   
4186
 
   adapter = COMPAT_WORK_GET_DATA(data, struct vmxnet3_adapter);
 
4201
   adapter = COMPAT_WORK_GET_DATA(data, struct vmxnet3_adapter, work);
4187
4202
   
4188
4203
   /* if another thread is resetting the device, no need to proceed */
4189
4204
   if (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state)) {
4320
4335
   adapter->is_shm = FALSE;
4321
4336
   if (adapter->dev_number < VMXNET3_SHM_MAX_DEVICES) {
4322
4337
      if (enable_shm[adapter->dev_number] == 1) {
4323
 
         if (shm_disclaimer == NULL ||
4324
 
             strncmp(shm_disclaimer, VMXNET3_SHM_DISCLAIMER,
4325
 
                     strlen(VMXNET3_SHM_DISCLAIMER)) != 0) {
 
4338
         if (!correct_shm_disclaimer) {
4326
4339
            printk(KERN_ERR "Did not activate shm, disclaimer missing\n");
4327
4340
         } else {
4328
4341
            adapter->is_shm = TRUE;
4471
4484
   }
4472
4485
 
4473
4486
   vmxnet3_disable_all_intrs(adapter);
 
4487
   vmxnet3_free_irqs(adapter);
 
4488
   vmxnet3_free_intr_resources(adapter);
4474
4489
   netif_device_detach(netdev);
4475
4490
   netif_stop_queue(netdev);
4476
4491
 
4601
4616
   pci_enable_wake(pdev, PCI_D0, 0);
4602
4617
 
4603
4618
   VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_UPDATE_PMCFG);
 
4619
   vmxnet3_alloc_intr_resources(adapter);
 
4620
   vmxnet3_request_irqs(adapter);
4604
4621
   vmxnet3_enable_all_intrs(adapter);
4605
4622
 
4606
4623
   return 0;
4629
4646
vmxnet3_init_module(void)
4630
4647
{
4631
4648
   printk(KERN_INFO "%s - version %s\n", VMXNET3_DRIVER_DESC, VMXNET3_DRIVER_VERSION_REPORT);
 
4649
 
 
4650
   correct_shm_disclaimer = shm_disclaimer &&
 
4651
      (strncmp(shm_disclaimer, VMXNET3_SHM_DISCLAIMER, strlen(VMXNET3_SHM_DISCLAIMER)) == 0);
 
4652
 
 
4653
#ifdef CONFIG_COMPAT
 
4654
#ifndef HAVE_UNLOCKED_IOCTL
 
4655
   if (correct_shm_disclaimer) {
 
4656
      register_ioctl32_conversion(SHM_IOCTL_TX, NULL);
 
4657
      register_ioctl32_conversion(SHM_IOCTL_ALLOC_ONE, NULL);
 
4658
      register_ioctl32_conversion(SHM_IOCTL_ALLOC_MANY, NULL);
 
4659
      register_ioctl32_conversion(SHM_IOCTL_ALLOC_ONE_AND_MANY, NULL);
 
4660
      register_ioctl32_conversion(SHM_IOCTL_FREE_ONE, NULL);
 
4661
   }
 
4662
#endif
 
4663
#endif
4632
4664
   return pci_register_driver(&vmxnet3_driver);
4633
4665
}
4634
4666
 
4652
4684
static void
4653
4685
vmxnet3_exit_module(void)
4654
4686
{
 
4687
#ifdef CONFIG_COMPAT
 
4688
#ifndef HAVE_UNLOCKED_IOCTL
 
4689
   if (correct_shm_disclaimer) {
 
4690
      unregister_ioctl32_conversion(SHM_IOCTL_TX);
 
4691
      unregister_ioctl32_conversion(SHM_IOCTL_ALLOC_ONE);
 
4692
      unregister_ioctl32_conversion(SHM_IOCTL_ALLOC_MANY);
 
4693
      unregister_ioctl32_conversion(SHM_IOCTL_ALLOC_ONE_AND_MANY);
 
4694
      unregister_ioctl32_conversion(SHM_IOCTL_FREE_ONE);
 
4695
   }
 
4696
#endif
 
4697
#endif
4655
4698
   pci_unregister_driver(&vmxnet3_driver);
4656
4699
}
4657
4700