PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/vmxnet3/vmxnet3_int.h

https://github.com/jthornber/linux-2.6
C Header | 425 lines | 305 code | 66 blank | 54 comment | 4 complexity | fb5b60799d082a347856de340f2a3e28 MD5 | raw file
  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/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.3.5.0-k"
  66. /* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */
  67. #define VMXNET3_DRIVER_VERSION_NUM 0x01030500
  68. #if defined(CONFIG_PCI_MSI)
  69. /* RSS only makes sense if MSI-X is supported. */
  70. #define VMXNET3_RSS
  71. #endif
  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_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. bool ipv6;
  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. char name[IFNAMSIZ+8]; /* To identify interrupt */
  202. struct vmxnet3_adapter *adapter;
  203. spinlock_t tx_lock;
  204. struct vmxnet3_cmd_ring tx_ring;
  205. struct vmxnet3_tx_buf_info *buf_info;
  206. dma_addr_t buf_info_pa;
  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. struct vmxnet3_rx_buf_info *buf_info[2];
  250. dma_addr_t buf_info_pa;
  251. struct Vmxnet3_RxQueueCtrl *shared;
  252. struct vmxnet3_rq_driver_stats stats;
  253. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  254. #define VMXNET3_DEVICE_MAX_TX_QUEUES 8
  255. #define VMXNET3_DEVICE_MAX_RX_QUEUES 8 /* Keep this value as a power of 2 */
  256. /* Should be less than UPT1_RSS_MAX_IND_TABLE_SIZE */
  257. #define VMXNET3_RSS_IND_TABLE_SIZE (VMXNET3_DEVICE_MAX_RX_QUEUES * 4)
  258. #define VMXNET3_LINUX_MAX_MSIX_VECT (VMXNET3_DEVICE_MAX_TX_QUEUES + \
  259. VMXNET3_DEVICE_MAX_RX_QUEUES + 1)
  260. #define VMXNET3_LINUX_MIN_MSIX_VECT 2 /* 1 for tx-rx pair and 1 for event */
  261. struct vmxnet3_intr {
  262. enum vmxnet3_intr_mask_mode mask_mode;
  263. enum vmxnet3_intr_type type; /* MSI-X, MSI, or INTx? */
  264. u8 num_intrs; /* # of intr vectors */
  265. u8 event_intr_idx; /* idx of the intr vector for event */
  266. u8 mod_levels[VMXNET3_LINUX_MAX_MSIX_VECT]; /* moderation level */
  267. char event_msi_vector_name[IFNAMSIZ+11];
  268. #ifdef CONFIG_PCI_MSI
  269. struct msix_entry msix_entries[VMXNET3_LINUX_MAX_MSIX_VECT];
  270. #endif
  271. };
  272. /* Interrupt sharing schemes, share_intr */
  273. #define VMXNET3_INTR_BUDDYSHARE 0 /* Corresponding tx,rx queues share irq */
  274. #define VMXNET3_INTR_TXSHARE 1 /* All tx queues share one irq */
  275. #define VMXNET3_INTR_DONTSHARE 2 /* each queue has its own irq */
  276. #define VMXNET3_STATE_BIT_RESETTING 0
  277. #define VMXNET3_STATE_BIT_QUIESCED 1
  278. struct vmxnet3_adapter {
  279. struct vmxnet3_tx_queue tx_queue[VMXNET3_DEVICE_MAX_TX_QUEUES];
  280. struct vmxnet3_rx_queue rx_queue[VMXNET3_DEVICE_MAX_RX_QUEUES];
  281. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  282. struct vmxnet3_intr intr;
  283. spinlock_t cmd_lock;
  284. struct Vmxnet3_DriverShared *shared;
  285. struct Vmxnet3_PMConf *pm_conf;
  286. struct Vmxnet3_TxQueueDesc *tqd_start; /* all tx queue desc */
  287. struct Vmxnet3_RxQueueDesc *rqd_start; /* all rx queue desc */
  288. struct net_device *netdev;
  289. struct pci_dev *pdev;
  290. u8 __iomem *hw_addr0; /* for BAR 0 */
  291. u8 __iomem *hw_addr1; /* for BAR 1 */
  292. #ifdef VMXNET3_RSS
  293. struct UPT1_RSSConf *rss_conf;
  294. bool rss;
  295. #endif
  296. u32 num_rx_queues;
  297. u32 num_tx_queues;
  298. /* rx buffer related */
  299. unsigned skb_buf_size;
  300. int rx_buf_per_pkt; /* only apply to the 1st ring */
  301. dma_addr_t shared_pa;
  302. dma_addr_t queue_desc_pa;
  303. /* Wake-on-LAN */
  304. u32 wol;
  305. /* Link speed */
  306. u32 link_speed; /* in mbps */
  307. u64 tx_timeout_count;
  308. /* Ring sizes */
  309. u32 tx_ring_size;
  310. u32 rx_ring_size;
  311. u32 rx_ring2_size;
  312. struct work_struct work;
  313. unsigned long state; /* VMXNET3_STATE_BIT_xxx */
  314. int share_intr;
  315. dma_addr_t adapter_pa;
  316. dma_addr_t pm_conf_pa;
  317. dma_addr_t rss_conf_pa;
  318. };
  319. #define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
  320. writel((val), (adapter)->hw_addr0 + (reg))
  321. #define VMXNET3_READ_BAR0_REG(adapter, reg) \
  322. readl((adapter)->hw_addr0 + (reg))
  323. #define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
  324. writel((val), (adapter)->hw_addr1 + (reg))
  325. #define VMXNET3_READ_BAR1_REG(adapter, reg) \
  326. readl((adapter)->hw_addr1 + (reg))
  327. #define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
  328. #define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
  329. ((rq)->rx_ring[ring_idx].size >> 3)
  330. #define VMXNET3_GET_ADDR_LO(dma) ((u32)(dma))
  331. #define VMXNET3_GET_ADDR_HI(dma) ((u32)(((u64)(dma)) >> 32))
  332. /* must be a multiple of VMXNET3_RING_SIZE_ALIGN */
  333. #define VMXNET3_DEF_TX_RING_SIZE 512
  334. #define VMXNET3_DEF_RX_RING_SIZE 256
  335. #define VMXNET3_DEF_RX_RING2_SIZE 128
  336. #define VMXNET3_MAX_ETH_HDR_SIZE 22
  337. #define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)
  338. int
  339. vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter);
  340. int
  341. vmxnet3_activate_dev(struct vmxnet3_adapter *adapter);
  342. void
  343. vmxnet3_force_close(struct vmxnet3_adapter *adapter);
  344. void
  345. vmxnet3_reset_dev(struct vmxnet3_adapter *adapter);
  346. void
  347. vmxnet3_tq_destroy_all(struct vmxnet3_adapter *adapter);
  348. void
  349. vmxnet3_rq_destroy_all(struct vmxnet3_adapter *adapter);
  350. int
  351. vmxnet3_set_features(struct net_device *netdev, netdev_features_t features);
  352. int
  353. vmxnet3_create_queues(struct vmxnet3_adapter *adapter,
  354. u32 tx_ring_size, u32 rx_ring_size, u32 rx_ring2_size);
  355. void vmxnet3_set_ethtool_ops(struct net_device *netdev);
  356. struct rtnl_link_stats64 *
  357. vmxnet3_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
  358. extern char vmxnet3_driver_name[];
  359. #endif