vmxnet3_int.h 12 KB

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