vmxnet3_int.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; version 2 of the License and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more
  14. * details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * The full GNU General Public License is included in this distribution in
  21. * the file called "COPYING".
  22. *
  23. * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
  24. *
  25. */
  26. #ifndef _VMXNET3_INT_H
  27. #define _VMXNET3_INT_H
  28. #include <linux/bitops.h>
  29. #include <linux/ethtool.h>
  30. #include <linux/delay.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/pci.h>
  33. #include <linux/compiler.h>
  34. #include <linux/slab.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/ioport.h>
  37. #include <linux/highmem.h>
  38. #include <linux/init.h>
  39. #include <linux/timer.h>
  40. #include <linux/skbuff.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/uaccess.h>
  44. #include <asm/dma.h>
  45. #include <asm/page.h>
  46. #include <linux/tcp.h>
  47. #include <linux/udp.h>
  48. #include <linux/ip.h>
  49. #include <linux/ipv6.h>
  50. #include <linux/in.h>
  51. #include <linux/etherdevice.h>
  52. #include <asm/checksum.h>
  53. #include <linux/if_vlan.h>
  54. #include <linux/if_arp.h>
  55. #include <linux/inetdevice.h>
  56. #include <linux/log2.h>
  57. #include "vmxnet3_defs.h"
  58. #ifdef DEBUG
  59. # define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI(debug)"
  60. #else
  61. # define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI"
  62. #endif
  63. /*
  64. * Version numbers
  65. */
  66. #define VMXNET3_DRIVER_VERSION_STRING "1.1.29.0-k"
  67. /* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */
  68. #define VMXNET3_DRIVER_VERSION_NUM 0x01011D00
  69. #if defined(CONFIG_PCI_MSI)
  70. /* RSS only makes sense if MSI-X is supported. */
  71. #define VMXNET3_RSS
  72. #endif
  73. /*
  74. * Capabilities
  75. */
  76. enum {
  77. VMNET_CAP_SG = 0x0001, /* Can do scatter-gather transmits. */
  78. VMNET_CAP_IP4_CSUM = 0x0002, /* Can checksum only TCP/UDP over
  79. * IPv4 */
  80. VMNET_CAP_HW_CSUM = 0x0004, /* Can checksum all packets. */
  81. VMNET_CAP_HIGH_DMA = 0x0008, /* Can DMA to high memory. */
  82. VMNET_CAP_TOE = 0x0010, /* Supports TCP/IP offload. */
  83. VMNET_CAP_TSO = 0x0020, /* Supports TCP Segmentation
  84. * offload */
  85. VMNET_CAP_SW_TSO = 0x0040, /* Supports SW TCP Segmentation */
  86. VMNET_CAP_VMXNET_APROM = 0x0080, /* Vmxnet APROM support */
  87. VMNET_CAP_HW_TX_VLAN = 0x0100, /* Can we do VLAN tagging in HW */
  88. VMNET_CAP_HW_RX_VLAN = 0x0200, /* Can we do VLAN untagging in HW */
  89. VMNET_CAP_SW_VLAN = 0x0400, /* VLAN tagging/untagging in SW */
  90. VMNET_CAP_WAKE_PCKT_RCV = 0x0800, /* Can wake on network packet recv? */
  91. VMNET_CAP_ENABLE_INT_INLINE = 0x1000, /* Enable Interrupt Inline */
  92. VMNET_CAP_ENABLE_HEADER_COPY = 0x2000, /* copy header for vmkernel */
  93. VMNET_CAP_TX_CHAIN = 0x4000, /* Guest can use multiple tx entries
  94. * for a pkt */
  95. VMNET_CAP_RX_CHAIN = 0x8000, /* pkt can span multiple rx entries */
  96. VMNET_CAP_LPD = 0x10000, /* large pkt delivery */
  97. VMNET_CAP_BPF = 0x20000, /* BPF Support in VMXNET Virtual HW*/
  98. VMNET_CAP_SG_SPAN_PAGES = 0x40000, /* Scatter-gather can span multiple*/
  99. /* pages transmits */
  100. VMNET_CAP_IP6_CSUM = 0x80000, /* Can do IPv6 csum offload. */
  101. VMNET_CAP_TSO6 = 0x100000, /* TSO seg. offload for IPv6 pkts. */
  102. VMNET_CAP_TSO256k = 0x200000, /* Can do TSO seg offload for */
  103. /* pkts up to 256kB. */
  104. VMNET_CAP_UPT = 0x400000 /* Support UPT */
  105. };
  106. /*
  107. * PCI vendor and device IDs.
  108. */
  109. #define PCI_VENDOR_ID_VMWARE 0x15AD
  110. #define PCI_DEVICE_ID_VMWARE_VMXNET3 0x07B0
  111. #define MAX_ETHERNET_CARDS 10
  112. #define MAX_PCI_PASSTHRU_DEVICE 6
  113. struct vmxnet3_cmd_ring {
  114. union Vmxnet3_GenericDesc *base;
  115. u32 size;
  116. u32 next2fill;
  117. u32 next2comp;
  118. u8 gen;
  119. dma_addr_t basePA;
  120. };
  121. static inline void
  122. vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
  123. {
  124. ring->next2fill++;
  125. if (unlikely(ring->next2fill == ring->size)) {
  126. ring->next2fill = 0;
  127. VMXNET3_FLIP_RING_GEN(ring->gen);
  128. }
  129. }
  130. static inline void
  131. vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
  132. {
  133. VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
  134. }
  135. static inline int
  136. vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
  137. {
  138. return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
  139. ring->next2comp - ring->next2fill - 1;
  140. }
  141. struct vmxnet3_comp_ring {
  142. union Vmxnet3_GenericDesc *base;
  143. u32 size;
  144. u32 next2proc;
  145. u8 gen;
  146. u8 intr_idx;
  147. dma_addr_t basePA;
  148. };
  149. static inline void
  150. vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
  151. {
  152. ring->next2proc++;
  153. if (unlikely(ring->next2proc == ring->size)) {
  154. ring->next2proc = 0;
  155. VMXNET3_FLIP_RING_GEN(ring->gen);
  156. }
  157. }
  158. struct vmxnet3_tx_data_ring {
  159. struct Vmxnet3_TxDataDesc *base;
  160. u32 size;
  161. dma_addr_t basePA;
  162. };
  163. enum vmxnet3_buf_map_type {
  164. VMXNET3_MAP_INVALID = 0,
  165. VMXNET3_MAP_NONE,
  166. VMXNET3_MAP_SINGLE,
  167. VMXNET3_MAP_PAGE,
  168. };
  169. struct vmxnet3_tx_buf_info {
  170. u32 map_type;
  171. u16 len;
  172. u16 sop_idx;
  173. dma_addr_t dma_addr;
  174. struct sk_buff *skb;
  175. };
  176. struct vmxnet3_tq_driver_stats {
  177. u64 drop_total; /* # of pkts dropped by the driver, the
  178. * counters below track droppings due to
  179. * different reasons
  180. */
  181. u64 drop_too_many_frags;
  182. u64 drop_oversized_hdr;
  183. u64 drop_hdr_inspect_err;
  184. u64 drop_tso;
  185. u64 tx_ring_full;
  186. u64 linearized; /* # of pkts linearized */
  187. u64 copy_skb_header; /* # of times we have to copy skb header */
  188. u64 oversized_hdr;
  189. };
  190. struct vmxnet3_tx_ctx {
  191. bool ipv4;
  192. u16 mss;
  193. u32 eth_ip_hdr_size; /* only valid for pkts requesting tso or csum
  194. * offloading
  195. */
  196. u32 l4_hdr_size; /* only valid if mss != 0 */
  197. u32 copy_size; /* # of bytes copied into the data ring */
  198. union Vmxnet3_GenericDesc *sop_txd;
  199. union Vmxnet3_GenericDesc *eop_txd;
  200. };
  201. struct vmxnet3_tx_queue {
  202. char name[IFNAMSIZ+8]; /* To identify interrupt */
  203. struct vmxnet3_adapter *adapter;
  204. spinlock_t tx_lock;
  205. struct vmxnet3_cmd_ring tx_ring;
  206. struct vmxnet3_tx_buf_info *buf_info;
  207. struct vmxnet3_tx_data_ring data_ring;
  208. struct vmxnet3_comp_ring comp_ring;
  209. struct Vmxnet3_TxQueueCtrl *shared;
  210. struct vmxnet3_tq_driver_stats stats;
  211. bool stopped;
  212. int num_stop; /* # of times the queue is
  213. * stopped */
  214. int qid;
  215. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  216. enum vmxnet3_rx_buf_type {
  217. VMXNET3_RX_BUF_NONE = 0,
  218. VMXNET3_RX_BUF_SKB = 1,
  219. VMXNET3_RX_BUF_PAGE = 2
  220. };
  221. struct vmxnet3_rx_buf_info {
  222. enum vmxnet3_rx_buf_type buf_type;
  223. u16 len;
  224. union {
  225. struct sk_buff *skb;
  226. struct page *page;
  227. };
  228. dma_addr_t dma_addr;
  229. };
  230. struct vmxnet3_rx_ctx {
  231. struct sk_buff *skb;
  232. u32 sop_idx;
  233. };
  234. struct vmxnet3_rq_driver_stats {
  235. u64 drop_total;
  236. u64 drop_err;
  237. u64 drop_fcs;
  238. u64 rx_buf_alloc_failure;
  239. };
  240. struct vmxnet3_rx_queue {
  241. char name[IFNAMSIZ + 8]; /* To identify interrupt */
  242. struct vmxnet3_adapter *adapter;
  243. struct napi_struct napi;
  244. struct vmxnet3_cmd_ring rx_ring[2];
  245. struct vmxnet3_comp_ring comp_ring;
  246. struct vmxnet3_rx_ctx rx_ctx;
  247. u32 qid; /* rqID in RCD for buffer from 1st ring */
  248. u32 qid2; /* rqID in RCD for buffer from 2nd ring */
  249. u32 uncommitted[2]; /* # of buffers allocated since last RXPROD
  250. * update */
  251. struct vmxnet3_rx_buf_info *buf_info[2];
  252. struct Vmxnet3_RxQueueCtrl *shared;
  253. struct vmxnet3_rq_driver_stats stats;
  254. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  255. #define VMXNET3_DEVICE_MAX_TX_QUEUES 8
  256. #define VMXNET3_DEVICE_MAX_RX_QUEUES 8 /* Keep this value as a power of 2 */
  257. /* Should be less than UPT1_RSS_MAX_IND_TABLE_SIZE */
  258. #define VMXNET3_RSS_IND_TABLE_SIZE (VMXNET3_DEVICE_MAX_RX_QUEUES * 4)
  259. #define VMXNET3_LINUX_MAX_MSIX_VECT (VMXNET3_DEVICE_MAX_TX_QUEUES + \
  260. VMXNET3_DEVICE_MAX_RX_QUEUES + 1)
  261. #define VMXNET3_LINUX_MIN_MSIX_VECT 2 /* 1 for tx-rx pair and 1 for event */
  262. struct vmxnet3_intr {
  263. enum vmxnet3_intr_mask_mode mask_mode;
  264. enum vmxnet3_intr_type type; /* MSI-X, MSI, or INTx? */
  265. u8 num_intrs; /* # of intr vectors */
  266. u8 event_intr_idx; /* idx of the intr vector for event */
  267. u8 mod_levels[VMXNET3_LINUX_MAX_MSIX_VECT]; /* moderation level */
  268. char event_msi_vector_name[IFNAMSIZ+11];
  269. #ifdef CONFIG_PCI_MSI
  270. struct msix_entry msix_entries[VMXNET3_LINUX_MAX_MSIX_VECT];
  271. #endif
  272. };
  273. /* Interrupt sharing schemes, share_intr */
  274. #define VMXNET3_INTR_BUDDYSHARE 0 /* Corresponding tx,rx queues share irq */
  275. #define VMXNET3_INTR_TXSHARE 1 /* All tx queues share one irq */
  276. #define VMXNET3_INTR_DONTSHARE 2 /* each queue has its own irq */
  277. #define VMXNET3_STATE_BIT_RESETTING 0
  278. #define VMXNET3_STATE_BIT_QUIESCED 1
  279. struct vmxnet3_adapter {
  280. struct vmxnet3_tx_queue tx_queue[VMXNET3_DEVICE_MAX_TX_QUEUES];
  281. struct vmxnet3_rx_queue rx_queue[VMXNET3_DEVICE_MAX_RX_QUEUES];
  282. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  283. struct vmxnet3_intr intr;
  284. spinlock_t cmd_lock;
  285. struct Vmxnet3_DriverShared *shared;
  286. struct Vmxnet3_PMConf *pm_conf;
  287. struct Vmxnet3_TxQueueDesc *tqd_start; /* all tx queue desc */
  288. struct Vmxnet3_RxQueueDesc *rqd_start; /* all rx queue desc */
  289. struct net_device *netdev;
  290. struct pci_dev *pdev;
  291. u8 __iomem *hw_addr0; /* for BAR 0 */
  292. u8 __iomem *hw_addr1; /* for BAR 1 */
  293. #ifdef VMXNET3_RSS
  294. struct UPT1_RSSConf *rss_conf;
  295. bool rss;
  296. #endif
  297. u32 num_rx_queues;
  298. u32 num_tx_queues;
  299. /* rx buffer related */
  300. unsigned skb_buf_size;
  301. int rx_buf_per_pkt; /* only apply to the 1st ring */
  302. dma_addr_t shared_pa;
  303. dma_addr_t queue_desc_pa;
  304. /* Wake-on-LAN */
  305. u32 wol;
  306. /* Link speed */
  307. u32 link_speed; /* in mbps */
  308. u64 tx_timeout_count;
  309. struct work_struct work;
  310. unsigned long state; /* VMXNET3_STATE_BIT_xxx */
  311. int dev_number;
  312. int share_intr;
  313. };
  314. #define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
  315. writel((val), (adapter)->hw_addr0 + (reg))
  316. #define VMXNET3_READ_BAR0_REG(adapter, reg) \
  317. readl((adapter)->hw_addr0 + (reg))
  318. #define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
  319. writel((val), (adapter)->hw_addr1 + (reg))
  320. #define VMXNET3_READ_BAR1_REG(adapter, reg) \
  321. readl((adapter)->hw_addr1 + (reg))
  322. #define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
  323. #define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
  324. ((rq)->rx_ring[ring_idx].size >> 3)
  325. #define VMXNET3_GET_ADDR_LO(dma) ((u32)(dma))
  326. #define VMXNET3_GET_ADDR_HI(dma) ((u32)(((u64)(dma)) >> 32))
  327. /* must be a multiple of VMXNET3_RING_SIZE_ALIGN */
  328. #define VMXNET3_DEF_TX_RING_SIZE 512
  329. #define VMXNET3_DEF_RX_RING_SIZE 256
  330. #define VMXNET3_MAX_ETH_HDR_SIZE 22
  331. #define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)
  332. int
  333. vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter);
  334. int
  335. vmxnet3_activate_dev(struct vmxnet3_adapter *adapter);
  336. void
  337. vmxnet3_force_close(struct vmxnet3_adapter *adapter);
  338. void
  339. vmxnet3_reset_dev(struct vmxnet3_adapter *adapter);
  340. void
  341. vmxnet3_tq_destroy_all(struct vmxnet3_adapter *adapter);
  342. void
  343. vmxnet3_rq_destroy_all(struct vmxnet3_adapter *adapter);
  344. int
  345. vmxnet3_set_features(struct net_device *netdev, netdev_features_t features);
  346. int
  347. vmxnet3_create_queues(struct vmxnet3_adapter *adapter,
  348. u32 tx_ring_size, u32 rx_ring_size, u32 rx_ring2_size);
  349. extern void vmxnet3_set_ethtool_ops(struct net_device *netdev);
  350. extern struct rtnl_link_stats64 *
  351. vmxnet3_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
  352. extern char vmxnet3_driver_name[];
  353. #endif