vmxnet3_int.h 11 KB

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