vmxnet3_int.h 11 KB

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