vmxnet3_int.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2016, 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: 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/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 <linux/log2.h>
  56. #include "vmxnet3_defs.h"
  57. #ifdef DEBUG
  58. # define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI(debug)"
  59. #else
  60. # define VMXNET3_DRIVER_VERSION_REPORT VMXNET3_DRIVER_VERSION_STRING"-NAPI"
  61. #endif
  62. /*
  63. * Version numbers
  64. */
  65. #define VMXNET3_DRIVER_VERSION_STRING "1.4.17.0-k"
  66. /* Each byte of this 32-bit integer encodes a version number in
  67. * VMXNET3_DRIVER_VERSION_STRING.
  68. */
  69. #define VMXNET3_DRIVER_VERSION_NUM 0x01041100
  70. #if defined(CONFIG_PCI_MSI)
  71. /* RSS only makes sense if MSI-X is supported. */
  72. #define VMXNET3_RSS
  73. #endif
  74. #define VMXNET3_REV_3 2 /* Vmxnet3 Rev. 3 */
  75. #define VMXNET3_REV_2 1 /* Vmxnet3 Rev. 2 */
  76. #define VMXNET3_REV_1 0 /* Vmxnet3 Rev. 1 */
  77. /*
  78. * Capabilities
  79. */
  80. enum {
  81. VMNET_CAP_SG = 0x0001, /* Can do scatter-gather transmits. */
  82. VMNET_CAP_IP4_CSUM = 0x0002, /* Can checksum only TCP/UDP over
  83. * IPv4 */
  84. VMNET_CAP_HW_CSUM = 0x0004, /* Can checksum all packets. */
  85. VMNET_CAP_HIGH_DMA = 0x0008, /* Can DMA to high memory. */
  86. VMNET_CAP_TOE = 0x0010, /* Supports TCP/IP offload. */
  87. VMNET_CAP_TSO = 0x0020, /* Supports TCP Segmentation
  88. * offload */
  89. VMNET_CAP_SW_TSO = 0x0040, /* Supports SW TCP Segmentation */
  90. VMNET_CAP_VMXNET_APROM = 0x0080, /* Vmxnet APROM support */
  91. VMNET_CAP_HW_TX_VLAN = 0x0100, /* Can we do VLAN tagging in HW */
  92. VMNET_CAP_HW_RX_VLAN = 0x0200, /* Can we do VLAN untagging in HW */
  93. VMNET_CAP_SW_VLAN = 0x0400, /* VLAN tagging/untagging in SW */
  94. VMNET_CAP_WAKE_PCKT_RCV = 0x0800, /* Can wake on network packet recv? */
  95. VMNET_CAP_ENABLE_INT_INLINE = 0x1000, /* Enable Interrupt Inline */
  96. VMNET_CAP_ENABLE_HEADER_COPY = 0x2000, /* copy header for vmkernel */
  97. VMNET_CAP_TX_CHAIN = 0x4000, /* Guest can use multiple tx entries
  98. * for a pkt */
  99. VMNET_CAP_RX_CHAIN = 0x8000, /* pkt can span multiple rx entries */
  100. VMNET_CAP_LPD = 0x10000, /* large pkt delivery */
  101. VMNET_CAP_BPF = 0x20000, /* BPF Support in VMXNET Virtual HW*/
  102. VMNET_CAP_SG_SPAN_PAGES = 0x40000, /* Scatter-gather can span multiple*/
  103. /* pages transmits */
  104. VMNET_CAP_IP6_CSUM = 0x80000, /* Can do IPv6 csum offload. */
  105. VMNET_CAP_TSO6 = 0x100000, /* TSO seg. offload for IPv6 pkts. */
  106. VMNET_CAP_TSO256k = 0x200000, /* Can do TSO seg offload for */
  107. /* pkts up to 256kB. */
  108. VMNET_CAP_UPT = 0x400000 /* Support UPT */
  109. };
  110. /*
  111. * Maximum devices supported.
  112. */
  113. #define MAX_ETHERNET_CARDS 10
  114. #define MAX_PCI_PASSTHRU_DEVICE 6
  115. struct vmxnet3_cmd_ring {
  116. union Vmxnet3_GenericDesc *base;
  117. u32 size;
  118. u32 next2fill;
  119. u32 next2comp;
  120. u8 gen;
  121. dma_addr_t basePA;
  122. };
  123. static inline void
  124. vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
  125. {
  126. ring->next2fill++;
  127. if (unlikely(ring->next2fill == ring->size)) {
  128. ring->next2fill = 0;
  129. VMXNET3_FLIP_RING_GEN(ring->gen);
  130. }
  131. }
  132. static inline void
  133. vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
  134. {
  135. VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
  136. }
  137. static inline int
  138. vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
  139. {
  140. return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
  141. ring->next2comp - ring->next2fill - 1;
  142. }
  143. struct vmxnet3_comp_ring {
  144. union Vmxnet3_GenericDesc *base;
  145. u32 size;
  146. u32 next2proc;
  147. u8 gen;
  148. u8 intr_idx;
  149. dma_addr_t basePA;
  150. };
  151. static inline void
  152. vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
  153. {
  154. ring->next2proc++;
  155. if (unlikely(ring->next2proc == ring->size)) {
  156. ring->next2proc = 0;
  157. VMXNET3_FLIP_RING_GEN(ring->gen);
  158. }
  159. }
  160. struct vmxnet3_tx_data_ring {
  161. struct Vmxnet3_TxDataDesc *base;
  162. u32 size;
  163. dma_addr_t basePA;
  164. };
  165. enum vmxnet3_buf_map_type {
  166. VMXNET3_MAP_INVALID = 0,
  167. VMXNET3_MAP_NONE,
  168. VMXNET3_MAP_SINGLE,
  169. VMXNET3_MAP_PAGE,
  170. };
  171. struct vmxnet3_tx_buf_info {
  172. u32 map_type;
  173. u16 len;
  174. u16 sop_idx;
  175. dma_addr_t dma_addr;
  176. struct sk_buff *skb;
  177. };
  178. struct vmxnet3_tq_driver_stats {
  179. u64 drop_total; /* # of pkts dropped by the driver, the
  180. * counters below track droppings due to
  181. * different reasons
  182. */
  183. u64 drop_too_many_frags;
  184. u64 drop_oversized_hdr;
  185. u64 drop_hdr_inspect_err;
  186. u64 drop_tso;
  187. u64 tx_ring_full;
  188. u64 linearized; /* # of pkts linearized */
  189. u64 copy_skb_header; /* # of times we have to copy skb header */
  190. u64 oversized_hdr;
  191. };
  192. struct vmxnet3_tx_ctx {
  193. bool ipv4;
  194. bool ipv6;
  195. u16 mss;
  196. u32 eth_ip_hdr_size; /* only valid for pkts requesting tso or csum
  197. * offloading
  198. */
  199. u32 l4_hdr_size; /* only valid if mss != 0 */
  200. u32 copy_size; /* # of bytes copied into the data ring */
  201. union Vmxnet3_GenericDesc *sop_txd;
  202. union Vmxnet3_GenericDesc *eop_txd;
  203. };
  204. struct vmxnet3_tx_queue {
  205. char name[IFNAMSIZ+8]; /* To identify interrupt */
  206. struct vmxnet3_adapter *adapter;
  207. spinlock_t tx_lock;
  208. struct vmxnet3_cmd_ring tx_ring;
  209. struct vmxnet3_tx_buf_info *buf_info;
  210. dma_addr_t buf_info_pa;
  211. struct vmxnet3_tx_data_ring data_ring;
  212. struct vmxnet3_comp_ring comp_ring;
  213. struct Vmxnet3_TxQueueCtrl *shared;
  214. struct vmxnet3_tq_driver_stats stats;
  215. bool stopped;
  216. int num_stop; /* # of times the queue is
  217. * stopped */
  218. int qid;
  219. u16 txdata_desc_size;
  220. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  221. enum vmxnet3_rx_buf_type {
  222. VMXNET3_RX_BUF_NONE = 0,
  223. VMXNET3_RX_BUF_SKB = 1,
  224. VMXNET3_RX_BUF_PAGE = 2
  225. };
  226. struct vmxnet3_rx_buf_info {
  227. enum vmxnet3_rx_buf_type buf_type;
  228. u16 len;
  229. union {
  230. struct sk_buff *skb;
  231. struct page *page;
  232. };
  233. dma_addr_t dma_addr;
  234. };
  235. struct vmxnet3_rx_ctx {
  236. struct sk_buff *skb;
  237. u32 sop_idx;
  238. };
  239. struct vmxnet3_rq_driver_stats {
  240. u64 drop_total;
  241. u64 drop_err;
  242. u64 drop_fcs;
  243. u64 rx_buf_alloc_failure;
  244. };
  245. struct vmxnet3_rx_data_ring {
  246. Vmxnet3_RxDataDesc *base;
  247. dma_addr_t basePA;
  248. u16 desc_size;
  249. };
  250. struct vmxnet3_rx_queue {
  251. char name[IFNAMSIZ + 8]; /* To identify interrupt */
  252. struct vmxnet3_adapter *adapter;
  253. struct napi_struct napi;
  254. struct vmxnet3_cmd_ring rx_ring[2];
  255. struct vmxnet3_rx_data_ring data_ring;
  256. struct vmxnet3_comp_ring comp_ring;
  257. struct vmxnet3_rx_ctx rx_ctx;
  258. u32 qid; /* rqID in RCD for buffer from 1st ring */
  259. u32 qid2; /* rqID in RCD for buffer from 2nd ring */
  260. u32 dataRingQid; /* rqID in RCD for buffer from data ring */
  261. struct vmxnet3_rx_buf_info *buf_info[2];
  262. dma_addr_t buf_info_pa;
  263. struct Vmxnet3_RxQueueCtrl *shared;
  264. struct vmxnet3_rq_driver_stats stats;
  265. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  266. #define VMXNET3_DEVICE_MAX_TX_QUEUES 8
  267. #define VMXNET3_DEVICE_MAX_RX_QUEUES 8 /* Keep this value as a power of 2 */
  268. /* Should be less than UPT1_RSS_MAX_IND_TABLE_SIZE */
  269. #define VMXNET3_RSS_IND_TABLE_SIZE (VMXNET3_DEVICE_MAX_RX_QUEUES * 4)
  270. #define VMXNET3_LINUX_MAX_MSIX_VECT (VMXNET3_DEVICE_MAX_TX_QUEUES + \
  271. VMXNET3_DEVICE_MAX_RX_QUEUES + 1)
  272. #define VMXNET3_LINUX_MIN_MSIX_VECT 2 /* 1 for tx-rx pair and 1 for event */
  273. struct vmxnet3_intr {
  274. enum vmxnet3_intr_mask_mode mask_mode;
  275. enum vmxnet3_intr_type type; /* MSI-X, MSI, or INTx? */
  276. u8 num_intrs; /* # of intr vectors */
  277. u8 event_intr_idx; /* idx of the intr vector for event */
  278. u8 mod_levels[VMXNET3_LINUX_MAX_MSIX_VECT]; /* moderation level */
  279. char event_msi_vector_name[IFNAMSIZ+17];
  280. #ifdef CONFIG_PCI_MSI
  281. struct msix_entry msix_entries[VMXNET3_LINUX_MAX_MSIX_VECT];
  282. #endif
  283. };
  284. /* Interrupt sharing schemes, share_intr */
  285. #define VMXNET3_INTR_BUDDYSHARE 0 /* Corresponding tx,rx queues share irq */
  286. #define VMXNET3_INTR_TXSHARE 1 /* All tx queues share one irq */
  287. #define VMXNET3_INTR_DONTSHARE 2 /* each queue has its own irq */
  288. #define VMXNET3_STATE_BIT_RESETTING 0
  289. #define VMXNET3_STATE_BIT_QUIESCED 1
  290. struct vmxnet3_adapter {
  291. struct vmxnet3_tx_queue tx_queue[VMXNET3_DEVICE_MAX_TX_QUEUES];
  292. struct vmxnet3_rx_queue rx_queue[VMXNET3_DEVICE_MAX_RX_QUEUES];
  293. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  294. struct vmxnet3_intr intr;
  295. spinlock_t cmd_lock;
  296. struct Vmxnet3_DriverShared *shared;
  297. struct Vmxnet3_PMConf *pm_conf;
  298. struct Vmxnet3_TxQueueDesc *tqd_start; /* all tx queue desc */
  299. struct Vmxnet3_RxQueueDesc *rqd_start; /* all rx queue desc */
  300. struct net_device *netdev;
  301. struct pci_dev *pdev;
  302. u8 __iomem *hw_addr0; /* for BAR 0 */
  303. u8 __iomem *hw_addr1; /* for BAR 1 */
  304. u8 version;
  305. #ifdef VMXNET3_RSS
  306. struct UPT1_RSSConf *rss_conf;
  307. bool rss;
  308. #endif
  309. u32 num_rx_queues;
  310. u32 num_tx_queues;
  311. /* rx buffer related */
  312. unsigned skb_buf_size;
  313. int rx_buf_per_pkt; /* only apply to the 1st ring */
  314. dma_addr_t shared_pa;
  315. dma_addr_t queue_desc_pa;
  316. dma_addr_t coal_conf_pa;
  317. /* Wake-on-LAN */
  318. u32 wol;
  319. /* Link speed */
  320. u32 link_speed; /* in mbps */
  321. u64 tx_timeout_count;
  322. /* Ring sizes */
  323. u32 tx_ring_size;
  324. u32 rx_ring_size;
  325. u32 rx_ring2_size;
  326. /* Size of buffer in the data ring */
  327. u16 txdata_desc_size;
  328. u16 rxdata_desc_size;
  329. bool rxdataring_enabled;
  330. struct work_struct work;
  331. unsigned long state; /* VMXNET3_STATE_BIT_xxx */
  332. int share_intr;
  333. struct Vmxnet3_CoalesceScheme *coal_conf;
  334. bool default_coal_mode;
  335. dma_addr_t adapter_pa;
  336. dma_addr_t pm_conf_pa;
  337. dma_addr_t rss_conf_pa;
  338. };
  339. #define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
  340. writel((val), (adapter)->hw_addr0 + (reg))
  341. #define VMXNET3_READ_BAR0_REG(adapter, reg) \
  342. readl((adapter)->hw_addr0 + (reg))
  343. #define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
  344. writel((val), (adapter)->hw_addr1 + (reg))
  345. #define VMXNET3_READ_BAR1_REG(adapter, reg) \
  346. readl((adapter)->hw_addr1 + (reg))
  347. #define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
  348. #define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
  349. ((rq)->rx_ring[ring_idx].size >> 3)
  350. #define VMXNET3_GET_ADDR_LO(dma) ((u32)(dma))
  351. #define VMXNET3_GET_ADDR_HI(dma) ((u32)(((u64)(dma)) >> 32))
  352. #define VMXNET3_VERSION_GE_2(adapter) \
  353. (adapter->version >= VMXNET3_REV_2 + 1)
  354. #define VMXNET3_VERSION_GE_3(adapter) \
  355. (adapter->version >= VMXNET3_REV_3 + 1)
  356. /* must be a multiple of VMXNET3_RING_SIZE_ALIGN */
  357. #define VMXNET3_DEF_TX_RING_SIZE 512
  358. #define VMXNET3_DEF_RX_RING_SIZE 1024
  359. #define VMXNET3_DEF_RX_RING2_SIZE 256
  360. #define VMXNET3_DEF_RXDATA_DESC_SIZE 128
  361. #define VMXNET3_MAX_ETH_HDR_SIZE 22
  362. #define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)
  363. #define VMXNET3_GET_RING_IDX(adapter, rqID) \
  364. ((rqID >= adapter->num_rx_queues && \
  365. rqID < 2 * adapter->num_rx_queues) ? 1 : 0) \
  366. #define VMXNET3_RX_DATA_RING(adapter, rqID) \
  367. (rqID >= 2 * adapter->num_rx_queues && \
  368. rqID < 3 * adapter->num_rx_queues) \
  369. #define VMXNET3_COAL_STATIC_DEFAULT_DEPTH 64
  370. #define VMXNET3_COAL_RBC_RATE(usecs) (1000000 / usecs)
  371. #define VMXNET3_COAL_RBC_USECS(rbc_rate) (1000000 / rbc_rate)
  372. int
  373. vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter);
  374. int
  375. vmxnet3_activate_dev(struct vmxnet3_adapter *adapter);
  376. void
  377. vmxnet3_force_close(struct vmxnet3_adapter *adapter);
  378. void
  379. vmxnet3_reset_dev(struct vmxnet3_adapter *adapter);
  380. void
  381. vmxnet3_tq_destroy_all(struct vmxnet3_adapter *adapter);
  382. void
  383. vmxnet3_rq_destroy_all(struct vmxnet3_adapter *adapter);
  384. netdev_features_t
  385. vmxnet3_fix_features(struct net_device *netdev, netdev_features_t features);
  386. int
  387. vmxnet3_set_features(struct net_device *netdev, netdev_features_t features);
  388. int
  389. vmxnet3_create_queues(struct vmxnet3_adapter *adapter,
  390. u32 tx_ring_size, u32 rx_ring_size, u32 rx_ring2_size,
  391. u16 txdata_desc_size, u16 rxdata_desc_size);
  392. void vmxnet3_set_ethtool_ops(struct net_device *netdev);
  393. void vmxnet3_get_stats64(struct net_device *dev,
  394. struct rtnl_link_stats64 *stats);
  395. extern char vmxnet3_driver_name[];
  396. #endif