ixgbevf.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2015 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, see <http://www.gnu.org/licenses/>.
  13. The full GNU General Public License is included in this distribution in
  14. the file called "COPYING".
  15. Contact Information:
  16. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. *******************************************************************************/
  19. #ifndef _IXGBEVF_H_
  20. #define _IXGBEVF_H_
  21. #include <linux/types.h>
  22. #include <linux/bitops.h>
  23. #include <linux/timer.h>
  24. #include <linux/io.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/u64_stats_sync.h>
  28. #include "vf.h"
  29. #ifdef CONFIG_NET_RX_BUSY_POLL
  30. #include <net/busy_poll.h>
  31. #define BP_EXTENDED_STATS
  32. #endif
  33. #define IXGBE_MAX_TXD_PWR 14
  34. #define IXGBE_MAX_DATA_PER_TXD BIT(IXGBE_MAX_TXD_PWR)
  35. /* Tx Descriptors needed, worst case */
  36. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
  37. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  38. /* wrapper around a pointer to a socket buffer,
  39. * so a DMA handle can be stored along with the buffer
  40. */
  41. struct ixgbevf_tx_buffer {
  42. union ixgbe_adv_tx_desc *next_to_watch;
  43. unsigned long time_stamp;
  44. struct sk_buff *skb;
  45. unsigned int bytecount;
  46. unsigned short gso_segs;
  47. __be16 protocol;
  48. DEFINE_DMA_UNMAP_ADDR(dma);
  49. DEFINE_DMA_UNMAP_LEN(len);
  50. u32 tx_flags;
  51. };
  52. struct ixgbevf_rx_buffer {
  53. dma_addr_t dma;
  54. struct page *page;
  55. unsigned int page_offset;
  56. };
  57. struct ixgbevf_stats {
  58. u64 packets;
  59. u64 bytes;
  60. #ifdef BP_EXTENDED_STATS
  61. u64 yields;
  62. u64 misses;
  63. u64 cleaned;
  64. #endif
  65. };
  66. struct ixgbevf_tx_queue_stats {
  67. u64 restart_queue;
  68. u64 tx_busy;
  69. u64 tx_done_old;
  70. };
  71. struct ixgbevf_rx_queue_stats {
  72. u64 alloc_rx_page_failed;
  73. u64 alloc_rx_buff_failed;
  74. u64 csum_err;
  75. };
  76. enum ixgbevf_ring_state_t {
  77. __IXGBEVF_TX_DETECT_HANG,
  78. __IXGBEVF_HANG_CHECK_ARMED,
  79. };
  80. #define check_for_tx_hang(ring) \
  81. test_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  82. #define set_check_for_tx_hang(ring) \
  83. set_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  84. #define clear_check_for_tx_hang(ring) \
  85. clear_bit(__IXGBEVF_TX_DETECT_HANG, &(ring)->state)
  86. struct ixgbevf_ring {
  87. struct ixgbevf_ring *next;
  88. struct net_device *netdev;
  89. struct device *dev;
  90. void *desc; /* descriptor ring memory */
  91. dma_addr_t dma; /* phys. address of descriptor ring */
  92. unsigned int size; /* length in bytes */
  93. u16 count; /* amount of descriptors */
  94. u16 next_to_use;
  95. u16 next_to_clean;
  96. u16 next_to_alloc;
  97. union {
  98. struct ixgbevf_tx_buffer *tx_buffer_info;
  99. struct ixgbevf_rx_buffer *rx_buffer_info;
  100. };
  101. unsigned long state;
  102. struct ixgbevf_stats stats;
  103. struct u64_stats_sync syncp;
  104. union {
  105. struct ixgbevf_tx_queue_stats tx_stats;
  106. struct ixgbevf_rx_queue_stats rx_stats;
  107. };
  108. u64 hw_csum_rx_error;
  109. u8 __iomem *tail;
  110. struct sk_buff *skb;
  111. /* holds the special value that gets the hardware register offset
  112. * associated with this ring, which is different for DCB and RSS modes
  113. */
  114. u16 reg_idx;
  115. int queue_index; /* needed for multiqueue queue management */
  116. };
  117. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  118. #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  119. #define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES
  120. #define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES
  121. #define IXGBEVF_MAX_RSS_QUEUES 2
  122. #define IXGBEVF_82599_RETA_SIZE 128 /* 128 entries */
  123. #define IXGBEVF_X550_VFRETA_SIZE 64 /* 64 entries */
  124. #define IXGBEVF_RSS_HASH_KEY_SIZE 40
  125. #define IXGBEVF_VFRSSRK_REGS 10 /* 10 registers for RSS key */
  126. #define IXGBEVF_DEFAULT_TXD 1024
  127. #define IXGBEVF_DEFAULT_RXD 512
  128. #define IXGBEVF_MAX_TXD 4096
  129. #define IXGBEVF_MIN_TXD 64
  130. #define IXGBEVF_MAX_RXD 4096
  131. #define IXGBEVF_MIN_RXD 64
  132. /* Supported Rx Buffer Sizes */
  133. #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
  134. #define IXGBEVF_RXBUFFER_2048 2048
  135. #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
  136. #define IXGBEVF_RX_BUFSZ IXGBEVF_RXBUFFER_2048
  137. #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
  138. #define IXGBE_TX_FLAGS_CSUM BIT(0)
  139. #define IXGBE_TX_FLAGS_VLAN BIT(1)
  140. #define IXGBE_TX_FLAGS_TSO BIT(2)
  141. #define IXGBE_TX_FLAGS_IPV4 BIT(3)
  142. #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
  143. #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
  144. #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
  145. struct ixgbevf_ring_container {
  146. struct ixgbevf_ring *ring; /* pointer to linked list of rings */
  147. unsigned int total_bytes; /* total bytes processed this int */
  148. unsigned int total_packets; /* total packets processed this int */
  149. u8 count; /* total number of rings in vector */
  150. u8 itr; /* current ITR setting for ring */
  151. };
  152. /* iterator for handling rings in ring container */
  153. #define ixgbevf_for_each_ring(pos, head) \
  154. for (pos = (head).ring; pos != NULL; pos = pos->next)
  155. /* MAX_MSIX_Q_VECTORS of these are allocated,
  156. * but we only use one per queue-specific vector.
  157. */
  158. struct ixgbevf_q_vector {
  159. struct ixgbevf_adapter *adapter;
  160. /* index of q_vector within array, also used for finding the bit in
  161. * EICR and friends that represents the vector for this ring
  162. */
  163. u16 v_idx;
  164. u16 itr; /* Interrupt throttle rate written to EITR */
  165. struct napi_struct napi;
  166. struct ixgbevf_ring_container rx, tx;
  167. char name[IFNAMSIZ + 9];
  168. #ifdef CONFIG_NET_RX_BUSY_POLL
  169. unsigned int state;
  170. #define IXGBEVF_QV_STATE_IDLE 0
  171. #define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */
  172. #define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */
  173. #define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */
  174. #define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
  175. #define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
  176. #define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */
  177. #define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */
  178. #define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | \
  179. IXGBEVF_QV_STATE_POLL_YIELD)
  180. #define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | \
  181. IXGBEVF_QV_STATE_POLL_YIELD)
  182. spinlock_t lock;
  183. #endif /* CONFIG_NET_RX_BUSY_POLL */
  184. };
  185. #ifdef CONFIG_NET_RX_BUSY_POLL
  186. static inline void ixgbevf_qv_init_lock(struct ixgbevf_q_vector *q_vector)
  187. {
  188. spin_lock_init(&q_vector->lock);
  189. q_vector->state = IXGBEVF_QV_STATE_IDLE;
  190. }
  191. /* called from the device poll routine to get ownership of a q_vector */
  192. static inline bool ixgbevf_qv_lock_napi(struct ixgbevf_q_vector *q_vector)
  193. {
  194. int rc = true;
  195. spin_lock_bh(&q_vector->lock);
  196. if (q_vector->state & IXGBEVF_QV_LOCKED) {
  197. WARN_ON(q_vector->state & IXGBEVF_QV_STATE_NAPI);
  198. q_vector->state |= IXGBEVF_QV_STATE_NAPI_YIELD;
  199. rc = false;
  200. #ifdef BP_EXTENDED_STATS
  201. q_vector->tx.ring->stats.yields++;
  202. #endif
  203. } else {
  204. /* we don't care if someone yielded */
  205. q_vector->state = IXGBEVF_QV_STATE_NAPI;
  206. }
  207. spin_unlock_bh(&q_vector->lock);
  208. return rc;
  209. }
  210. /* returns true is someone tried to get the qv while napi had it */
  211. static inline bool ixgbevf_qv_unlock_napi(struct ixgbevf_q_vector *q_vector)
  212. {
  213. int rc = false;
  214. spin_lock_bh(&q_vector->lock);
  215. WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_POLL |
  216. IXGBEVF_QV_STATE_NAPI_YIELD));
  217. if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
  218. rc = true;
  219. /* reset state to idle, unless QV is disabled */
  220. q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
  221. spin_unlock_bh(&q_vector->lock);
  222. return rc;
  223. }
  224. /* called from ixgbevf_low_latency_poll() */
  225. static inline bool ixgbevf_qv_lock_poll(struct ixgbevf_q_vector *q_vector)
  226. {
  227. int rc = true;
  228. spin_lock_bh(&q_vector->lock);
  229. if ((q_vector->state & IXGBEVF_QV_LOCKED)) {
  230. q_vector->state |= IXGBEVF_QV_STATE_POLL_YIELD;
  231. rc = false;
  232. #ifdef BP_EXTENDED_STATS
  233. q_vector->rx.ring->stats.yields++;
  234. #endif
  235. } else {
  236. /* preserve yield marks */
  237. q_vector->state |= IXGBEVF_QV_STATE_POLL;
  238. }
  239. spin_unlock_bh(&q_vector->lock);
  240. return rc;
  241. }
  242. /* returns true if someone tried to get the qv while it was locked */
  243. static inline bool ixgbevf_qv_unlock_poll(struct ixgbevf_q_vector *q_vector)
  244. {
  245. int rc = false;
  246. spin_lock_bh(&q_vector->lock);
  247. WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_NAPI));
  248. if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
  249. rc = true;
  250. /* reset state to idle, unless QV is disabled */
  251. q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
  252. spin_unlock_bh(&q_vector->lock);
  253. return rc;
  254. }
  255. /* true if a socket is polling, even if it did not get the lock */
  256. static inline bool ixgbevf_qv_busy_polling(struct ixgbevf_q_vector *q_vector)
  257. {
  258. WARN_ON(!(q_vector->state & IXGBEVF_QV_OWNED));
  259. return q_vector->state & IXGBEVF_QV_USER_PEND;
  260. }
  261. /* false if QV is currently owned */
  262. static inline bool ixgbevf_qv_disable(struct ixgbevf_q_vector *q_vector)
  263. {
  264. int rc = true;
  265. spin_lock_bh(&q_vector->lock);
  266. if (q_vector->state & IXGBEVF_QV_OWNED)
  267. rc = false;
  268. q_vector->state |= IXGBEVF_QV_STATE_DISABLED;
  269. spin_unlock_bh(&q_vector->lock);
  270. return rc;
  271. }
  272. #endif /* CONFIG_NET_RX_BUSY_POLL */
  273. /* microsecond values for various ITR rates shifted by 2 to fit itr register
  274. * with the first 3 bits reserved 0
  275. */
  276. #define IXGBE_MIN_RSC_ITR 24
  277. #define IXGBE_100K_ITR 40
  278. #define IXGBE_20K_ITR 200
  279. #define IXGBE_12K_ITR 336
  280. /* Helper macros to switch between ints/sec and what the register uses.
  281. * And yes, it's the same math going both ways. The lowest value
  282. * supported by all of the ixgbe hardware is 8.
  283. */
  284. #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
  285. ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
  286. #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
  287. /* ixgbevf_test_staterr - tests bits in Rx descriptor status and error fields */
  288. static inline __le32 ixgbevf_test_staterr(union ixgbe_adv_rx_desc *rx_desc,
  289. const u32 stat_err_bits)
  290. {
  291. return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
  292. }
  293. static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
  294. {
  295. u16 ntc = ring->next_to_clean;
  296. u16 ntu = ring->next_to_use;
  297. return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
  298. }
  299. static inline void ixgbevf_write_tail(struct ixgbevf_ring *ring, u32 value)
  300. {
  301. writel(value, ring->tail);
  302. }
  303. #define IXGBEVF_RX_DESC(R, i) \
  304. (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
  305. #define IXGBEVF_TX_DESC(R, i) \
  306. (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
  307. #define IXGBEVF_TX_CTXTDESC(R, i) \
  308. (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
  309. #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
  310. #define OTHER_VECTOR 1
  311. #define NON_Q_VECTORS (OTHER_VECTOR)
  312. #define MAX_MSIX_Q_VECTORS 2
  313. #define MIN_MSIX_Q_VECTORS 1
  314. #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
  315. /* board specific private data structure */
  316. struct ixgbevf_adapter {
  317. /* this field must be first, see ixgbevf_process_skb_fields */
  318. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  319. struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
  320. /* Interrupt Throttle Rate */
  321. u16 rx_itr_setting;
  322. u16 tx_itr_setting;
  323. /* interrupt masks */
  324. u32 eims_enable_mask;
  325. u32 eims_other;
  326. /* TX */
  327. int num_tx_queues;
  328. struct ixgbevf_ring *tx_ring[MAX_TX_QUEUES]; /* One per active queue */
  329. u64 restart_queue;
  330. u32 tx_timeout_count;
  331. /* RX */
  332. int num_rx_queues;
  333. struct ixgbevf_ring *rx_ring[MAX_TX_QUEUES]; /* One per active queue */
  334. u64 hw_csum_rx_error;
  335. u64 hw_rx_no_dma_resources;
  336. int num_msix_vectors;
  337. u32 alloc_rx_page_failed;
  338. u32 alloc_rx_buff_failed;
  339. struct msix_entry *msix_entries;
  340. /* OS defined structs */
  341. struct net_device *netdev;
  342. struct pci_dev *pdev;
  343. /* structs defined in ixgbe_vf.h */
  344. struct ixgbe_hw hw;
  345. u16 msg_enable;
  346. /* Interrupt Throttle Rate */
  347. u32 eitr_param;
  348. struct ixgbevf_hw_stats stats;
  349. unsigned long state;
  350. u64 tx_busy;
  351. unsigned int tx_ring_count;
  352. unsigned int rx_ring_count;
  353. u8 __iomem *io_addr; /* Mainly for iounmap use */
  354. u32 link_speed;
  355. bool link_up;
  356. struct timer_list service_timer;
  357. struct work_struct service_task;
  358. spinlock_t mbx_lock;
  359. unsigned long last_reset;
  360. u32 rss_key[IXGBEVF_VFRSSRK_REGS];
  361. u8 rss_indir_tbl[IXGBEVF_X550_VFRETA_SIZE];
  362. };
  363. enum ixbgevf_state_t {
  364. __IXGBEVF_TESTING,
  365. __IXGBEVF_RESETTING,
  366. __IXGBEVF_DOWN,
  367. __IXGBEVF_DISABLED,
  368. __IXGBEVF_REMOVING,
  369. __IXGBEVF_SERVICE_SCHED,
  370. __IXGBEVF_SERVICE_INITED,
  371. __IXGBEVF_RESET_REQUESTED,
  372. __IXGBEVF_QUEUE_RESET_REQUESTED,
  373. };
  374. enum ixgbevf_boards {
  375. board_82599_vf,
  376. board_82599_vf_hv,
  377. board_X540_vf,
  378. board_X540_vf_hv,
  379. board_X550_vf,
  380. board_X550_vf_hv,
  381. board_X550EM_x_vf,
  382. board_X550EM_x_vf_hv,
  383. board_x550em_a_vf,
  384. };
  385. enum ixgbevf_xcast_modes {
  386. IXGBEVF_XCAST_MODE_NONE = 0,
  387. IXGBEVF_XCAST_MODE_MULTI,
  388. IXGBEVF_XCAST_MODE_ALLMULTI,
  389. };
  390. extern const struct ixgbevf_info ixgbevf_82599_vf_info;
  391. extern const struct ixgbevf_info ixgbevf_X540_vf_info;
  392. extern const struct ixgbevf_info ixgbevf_X550_vf_info;
  393. extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
  394. extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
  395. extern const struct ixgbevf_info ixgbevf_x550em_a_vf_info;
  396. extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
  397. extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
  398. extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
  399. extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
  400. extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
  401. /* needed by ethtool.c */
  402. extern const char ixgbevf_driver_name[];
  403. extern const char ixgbevf_driver_version[];
  404. int ixgbevf_open(struct net_device *netdev);
  405. int ixgbevf_close(struct net_device *netdev);
  406. void ixgbevf_up(struct ixgbevf_adapter *adapter);
  407. void ixgbevf_down(struct ixgbevf_adapter *adapter);
  408. void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
  409. void ixgbevf_reset(struct ixgbevf_adapter *adapter);
  410. void ixgbevf_set_ethtool_ops(struct net_device *netdev);
  411. int ixgbevf_setup_rx_resources(struct ixgbevf_ring *);
  412. int ixgbevf_setup_tx_resources(struct ixgbevf_ring *);
  413. void ixgbevf_free_rx_resources(struct ixgbevf_ring *);
  414. void ixgbevf_free_tx_resources(struct ixgbevf_ring *);
  415. void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
  416. int ethtool_ioctl(struct ifreq *ifr);
  417. extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
  418. void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
  419. void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
  420. #define ixgbevf_hw_to_netdev(hw) \
  421. (((struct ixgbevf_adapter *)(hw)->back)->netdev)
  422. #define hw_dbg(hw, format, arg...) \
  423. netdev_dbg(ixgbevf_hw_to_netdev(hw), format, ## arg)
  424. #endif /* _IXGBEVF_H_ */