ixgbe.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #ifndef _IXGBE_H_
  21. #define _IXGBE_H_
  22. #include <linux/bitops.h>
  23. #include <linux/types.h>
  24. #include <linux/pci.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/cpumask.h>
  27. #include <linux/aer.h>
  28. #include <linux/if_vlan.h>
  29. #include <linux/jiffies.h>
  30. #include <linux/clocksource.h>
  31. #include <linux/net_tstamp.h>
  32. #include <linux/ptp_clock_kernel.h>
  33. #include "ixgbe_type.h"
  34. #include "ixgbe_common.h"
  35. #include "ixgbe_dcb.h"
  36. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
  37. #define IXGBE_FCOE
  38. #include "ixgbe_fcoe.h"
  39. #endif /* CONFIG_FCOE or CONFIG_FCOE_MODULE */
  40. #ifdef CONFIG_IXGBE_DCA
  41. #include <linux/dca.h>
  42. #endif
  43. #include <net/busy_poll.h>
  44. #ifdef CONFIG_NET_RX_BUSY_POLL
  45. #define LL_EXTENDED_STATS
  46. #endif
  47. /* common prefix used by pr_<> macros */
  48. #undef pr_fmt
  49. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  50. /* TX/RX descriptor defines */
  51. #define IXGBE_DEFAULT_TXD 512
  52. #define IXGBE_DEFAULT_TX_WORK 256
  53. #define IXGBE_MAX_TXD 4096
  54. #define IXGBE_MIN_TXD 64
  55. #define IXGBE_DEFAULT_RXD 512
  56. #define IXGBE_MAX_RXD 4096
  57. #define IXGBE_MIN_RXD 64
  58. /* flow control */
  59. #define IXGBE_MIN_FCRTL 0x40
  60. #define IXGBE_MAX_FCRTL 0x7FF80
  61. #define IXGBE_MIN_FCRTH 0x600
  62. #define IXGBE_MAX_FCRTH 0x7FFF0
  63. #define IXGBE_DEFAULT_FCPAUSE 0xFFFF
  64. #define IXGBE_MIN_FCPAUSE 0
  65. #define IXGBE_MAX_FCPAUSE 0xFFFF
  66. /* Supported Rx Buffer Sizes */
  67. #define IXGBE_RXBUFFER_256 256 /* Used for skb receive header */
  68. #define IXGBE_RXBUFFER_2K 2048
  69. #define IXGBE_RXBUFFER_3K 3072
  70. #define IXGBE_RXBUFFER_4K 4096
  71. #define IXGBE_MAX_RXBUFFER 16384 /* largest size for a single descriptor */
  72. /*
  73. * NOTE: netdev_alloc_skb reserves up to 64 bytes, NET_IP_ALIGN means we
  74. * reserve 64 more, and skb_shared_info adds an additional 320 bytes more,
  75. * this adds up to 448 bytes of extra data.
  76. *
  77. * Since netdev_alloc_skb now allocates a page fragment we can use a value
  78. * of 256 and the resultant skb will have a truesize of 960 or less.
  79. */
  80. #define IXGBE_RX_HDR_SIZE IXGBE_RXBUFFER_256
  81. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  82. #define IXGBE_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  83. enum ixgbe_tx_flags {
  84. /* cmd_type flags */
  85. IXGBE_TX_FLAGS_HW_VLAN = 0x01,
  86. IXGBE_TX_FLAGS_TSO = 0x02,
  87. IXGBE_TX_FLAGS_TSTAMP = 0x04,
  88. /* olinfo flags */
  89. IXGBE_TX_FLAGS_CC = 0x08,
  90. IXGBE_TX_FLAGS_IPV4 = 0x10,
  91. IXGBE_TX_FLAGS_CSUM = 0x20,
  92. /* software defined flags */
  93. IXGBE_TX_FLAGS_SW_VLAN = 0x40,
  94. IXGBE_TX_FLAGS_FCOE = 0x80,
  95. };
  96. /* VLAN info */
  97. #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
  98. #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0xe0000000
  99. #define IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT 29
  100. #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
  101. #define IXGBE_MAX_VF_MC_ENTRIES 30
  102. #define IXGBE_MAX_VF_FUNCTIONS 64
  103. #define IXGBE_MAX_VFTA_ENTRIES 128
  104. #define MAX_EMULATION_MAC_ADDRS 16
  105. #define IXGBE_MAX_PF_MACVLANS 15
  106. #define VMDQ_P(p) ((p) + adapter->ring_feature[RING_F_VMDQ].offset)
  107. #define IXGBE_82599_VF_DEVICE_ID 0x10ED
  108. #define IXGBE_X540_VF_DEVICE_ID 0x1515
  109. struct vf_data_storage {
  110. unsigned char vf_mac_addresses[ETH_ALEN];
  111. u16 vf_mc_hashes[IXGBE_MAX_VF_MC_ENTRIES];
  112. u16 num_vf_mc_hashes;
  113. u16 default_vf_vlan_id;
  114. u16 vlans_enabled;
  115. bool clear_to_send;
  116. bool pf_set_mac;
  117. u16 pf_vlan; /* When set, guest VLAN config not allowed. */
  118. u16 pf_qos;
  119. u16 tx_rate;
  120. u16 vlan_count;
  121. u8 spoofchk_enabled;
  122. unsigned int vf_api;
  123. };
  124. struct vf_macvlans {
  125. struct list_head l;
  126. int vf;
  127. int rar_entry;
  128. bool free;
  129. bool is_macvlan;
  130. u8 vf_macvlan[ETH_ALEN];
  131. };
  132. #define IXGBE_MAX_TXD_PWR 14
  133. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  134. /* Tx Descriptors needed, worst case */
  135. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
  136. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  137. /* wrapper around a pointer to a socket buffer,
  138. * so a DMA handle can be stored along with the buffer */
  139. struct ixgbe_tx_buffer {
  140. union ixgbe_adv_tx_desc *next_to_watch;
  141. unsigned long time_stamp;
  142. struct sk_buff *skb;
  143. unsigned int bytecount;
  144. unsigned short gso_segs;
  145. __be16 protocol;
  146. DEFINE_DMA_UNMAP_ADDR(dma);
  147. DEFINE_DMA_UNMAP_LEN(len);
  148. u32 tx_flags;
  149. };
  150. struct ixgbe_rx_buffer {
  151. struct sk_buff *skb;
  152. dma_addr_t dma;
  153. struct page *page;
  154. unsigned int page_offset;
  155. };
  156. struct ixgbe_queue_stats {
  157. u64 packets;
  158. u64 bytes;
  159. #ifdef LL_EXTENDED_STATS
  160. u64 yields;
  161. u64 misses;
  162. u64 cleaned;
  163. #endif /* LL_EXTENDED_STATS */
  164. };
  165. struct ixgbe_tx_queue_stats {
  166. u64 restart_queue;
  167. u64 tx_busy;
  168. u64 tx_done_old;
  169. };
  170. struct ixgbe_rx_queue_stats {
  171. u64 rsc_count;
  172. u64 rsc_flush;
  173. u64 non_eop_descs;
  174. u64 alloc_rx_page_failed;
  175. u64 alloc_rx_buff_failed;
  176. u64 csum_err;
  177. };
  178. enum ixgbe_ring_state_t {
  179. __IXGBE_TX_FDIR_INIT_DONE,
  180. __IXGBE_TX_XPS_INIT_DONE,
  181. __IXGBE_TX_DETECT_HANG,
  182. __IXGBE_HANG_CHECK_ARMED,
  183. __IXGBE_RX_RSC_ENABLED,
  184. __IXGBE_RX_CSUM_UDP_ZERO_ERR,
  185. __IXGBE_RX_FCOE,
  186. };
  187. #define check_for_tx_hang(ring) \
  188. test_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state)
  189. #define set_check_for_tx_hang(ring) \
  190. set_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state)
  191. #define clear_check_for_tx_hang(ring) \
  192. clear_bit(__IXGBE_TX_DETECT_HANG, &(ring)->state)
  193. #define ring_is_rsc_enabled(ring) \
  194. test_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state)
  195. #define set_ring_rsc_enabled(ring) \
  196. set_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state)
  197. #define clear_ring_rsc_enabled(ring) \
  198. clear_bit(__IXGBE_RX_RSC_ENABLED, &(ring)->state)
  199. struct ixgbe_ring {
  200. struct ixgbe_ring *next; /* pointer to next ring in q_vector */
  201. struct ixgbe_q_vector *q_vector; /* backpointer to host q_vector */
  202. struct net_device *netdev; /* netdev ring belongs to */
  203. struct device *dev; /* device for DMA mapping */
  204. void *desc; /* descriptor ring memory */
  205. union {
  206. struct ixgbe_tx_buffer *tx_buffer_info;
  207. struct ixgbe_rx_buffer *rx_buffer_info;
  208. };
  209. unsigned long last_rx_timestamp;
  210. unsigned long state;
  211. u8 __iomem *tail;
  212. dma_addr_t dma; /* phys. address of descriptor ring */
  213. unsigned int size; /* length in bytes */
  214. u16 count; /* amount of descriptors */
  215. u8 queue_index; /* needed for multiqueue queue management */
  216. u8 reg_idx; /* holds the special value that gets
  217. * the hardware register offset
  218. * associated with this ring, which is
  219. * different for DCB and RSS modes
  220. */
  221. u16 next_to_use;
  222. u16 next_to_clean;
  223. union {
  224. u16 next_to_alloc;
  225. struct {
  226. u8 atr_sample_rate;
  227. u8 atr_count;
  228. };
  229. };
  230. u8 dcb_tc;
  231. struct ixgbe_queue_stats stats;
  232. struct u64_stats_sync syncp;
  233. union {
  234. struct ixgbe_tx_queue_stats tx_stats;
  235. struct ixgbe_rx_queue_stats rx_stats;
  236. };
  237. } ____cacheline_internodealigned_in_smp;
  238. enum ixgbe_ring_f_enum {
  239. RING_F_NONE = 0,
  240. RING_F_VMDQ, /* SR-IOV uses the same ring feature */
  241. RING_F_RSS,
  242. RING_F_FDIR,
  243. #ifdef IXGBE_FCOE
  244. RING_F_FCOE,
  245. #endif /* IXGBE_FCOE */
  246. RING_F_ARRAY_SIZE /* must be last in enum set */
  247. };
  248. #define IXGBE_MAX_RSS_INDICES 16
  249. #define IXGBE_MAX_VMDQ_INDICES 64
  250. #define IXGBE_MAX_FDIR_INDICES 63 /* based on q_vector limit */
  251. #define IXGBE_MAX_FCOE_INDICES 8
  252. #define MAX_RX_QUEUES (IXGBE_MAX_FDIR_INDICES + 1)
  253. #define MAX_TX_QUEUES (IXGBE_MAX_FDIR_INDICES + 1)
  254. struct ixgbe_ring_feature {
  255. u16 limit; /* upper limit on feature indices */
  256. u16 indices; /* current value of indices */
  257. u16 mask; /* Mask used for feature to ring mapping */
  258. u16 offset; /* offset to start of feature */
  259. } ____cacheline_internodealigned_in_smp;
  260. #define IXGBE_82599_VMDQ_8Q_MASK 0x78
  261. #define IXGBE_82599_VMDQ_4Q_MASK 0x7C
  262. #define IXGBE_82599_VMDQ_2Q_MASK 0x7E
  263. /*
  264. * FCoE requires that all Rx buffers be over 2200 bytes in length. Since
  265. * this is twice the size of a half page we need to double the page order
  266. * for FCoE enabled Rx queues.
  267. */
  268. static inline unsigned int ixgbe_rx_bufsz(struct ixgbe_ring *ring)
  269. {
  270. #ifdef IXGBE_FCOE
  271. if (test_bit(__IXGBE_RX_FCOE, &ring->state))
  272. return (PAGE_SIZE < 8192) ? IXGBE_RXBUFFER_4K :
  273. IXGBE_RXBUFFER_3K;
  274. #endif
  275. return IXGBE_RXBUFFER_2K;
  276. }
  277. static inline unsigned int ixgbe_rx_pg_order(struct ixgbe_ring *ring)
  278. {
  279. #ifdef IXGBE_FCOE
  280. if (test_bit(__IXGBE_RX_FCOE, &ring->state))
  281. return (PAGE_SIZE < 8192) ? 1 : 0;
  282. #endif
  283. return 0;
  284. }
  285. #define ixgbe_rx_pg_size(_ring) (PAGE_SIZE << ixgbe_rx_pg_order(_ring))
  286. struct ixgbe_ring_container {
  287. struct ixgbe_ring *ring; /* pointer to linked list of rings */
  288. unsigned int total_bytes; /* total bytes processed this int */
  289. unsigned int total_packets; /* total packets processed this int */
  290. u16 work_limit; /* total work allowed per interrupt */
  291. u8 count; /* total number of rings in vector */
  292. u8 itr; /* current ITR setting for ring */
  293. };
  294. /* iterator for handling rings in ring container */
  295. #define ixgbe_for_each_ring(pos, head) \
  296. for (pos = (head).ring; pos != NULL; pos = pos->next)
  297. #define MAX_RX_PACKET_BUFFERS ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) \
  298. ? 8 : 1)
  299. #define MAX_TX_PACKET_BUFFERS MAX_RX_PACKET_BUFFERS
  300. /* MAX_Q_VECTORS of these are allocated,
  301. * but we only use one per queue-specific vector.
  302. */
  303. struct ixgbe_q_vector {
  304. struct ixgbe_adapter *adapter;
  305. #ifdef CONFIG_IXGBE_DCA
  306. int cpu; /* CPU for DCA */
  307. #endif
  308. u16 v_idx; /* index of q_vector within array, also used for
  309. * finding the bit in EICR and friends that
  310. * represents the vector for this ring */
  311. u16 itr; /* Interrupt throttle rate written to EITR */
  312. struct ixgbe_ring_container rx, tx;
  313. struct napi_struct napi;
  314. cpumask_t affinity_mask;
  315. int numa_node;
  316. struct rcu_head rcu; /* to avoid race with update stats on free */
  317. char name[IFNAMSIZ + 9];
  318. #ifdef CONFIG_NET_RX_BUSY_POLL
  319. unsigned int state;
  320. #define IXGBE_QV_STATE_IDLE 0
  321. #define IXGBE_QV_STATE_NAPI 1 /* NAPI owns this QV */
  322. #define IXGBE_QV_STATE_POLL 2 /* poll owns this QV */
  323. #define IXGBE_QV_LOCKED (IXGBE_QV_STATE_NAPI | IXGBE_QV_STATE_POLL)
  324. #define IXGBE_QV_STATE_NAPI_YIELD 4 /* NAPI yielded this QV */
  325. #define IXGBE_QV_STATE_POLL_YIELD 8 /* poll yielded this QV */
  326. #define IXGBE_QV_YIELD (IXGBE_QV_STATE_NAPI_YIELD | IXGBE_QV_STATE_POLL_YIELD)
  327. #define IXGBE_QV_USER_PEND (IXGBE_QV_STATE_POLL | IXGBE_QV_STATE_POLL_YIELD)
  328. spinlock_t lock;
  329. #endif /* CONFIG_NET_RX_BUSY_POLL */
  330. /* for dynamic allocation of rings associated with this q_vector */
  331. struct ixgbe_ring ring[0] ____cacheline_internodealigned_in_smp;
  332. };
  333. #ifdef CONFIG_NET_RX_BUSY_POLL
  334. static inline void ixgbe_qv_init_lock(struct ixgbe_q_vector *q_vector)
  335. {
  336. spin_lock_init(&q_vector->lock);
  337. q_vector->state = IXGBE_QV_STATE_IDLE;
  338. }
  339. /* called from the device poll routine to get ownership of a q_vector */
  340. static inline bool ixgbe_qv_lock_napi(struct ixgbe_q_vector *q_vector)
  341. {
  342. int rc = true;
  343. spin_lock(&q_vector->lock);
  344. if (q_vector->state & IXGBE_QV_LOCKED) {
  345. WARN_ON(q_vector->state & IXGBE_QV_STATE_NAPI);
  346. q_vector->state |= IXGBE_QV_STATE_NAPI_YIELD;
  347. rc = false;
  348. #ifdef LL_EXTENDED_STATS
  349. q_vector->tx.ring->stats.yields++;
  350. #endif
  351. } else
  352. /* we don't care if someone yielded */
  353. q_vector->state = IXGBE_QV_STATE_NAPI;
  354. spin_unlock(&q_vector->lock);
  355. return rc;
  356. }
  357. /* returns true is someone tried to get the qv while napi had it */
  358. static inline bool ixgbe_qv_unlock_napi(struct ixgbe_q_vector *q_vector)
  359. {
  360. int rc = false;
  361. spin_lock(&q_vector->lock);
  362. WARN_ON(q_vector->state & (IXGBE_QV_STATE_POLL |
  363. IXGBE_QV_STATE_NAPI_YIELD));
  364. if (q_vector->state & IXGBE_QV_STATE_POLL_YIELD)
  365. rc = true;
  366. q_vector->state = IXGBE_QV_STATE_IDLE;
  367. spin_unlock(&q_vector->lock);
  368. return rc;
  369. }
  370. /* called from ixgbe_low_latency_poll() */
  371. static inline bool ixgbe_qv_lock_poll(struct ixgbe_q_vector *q_vector)
  372. {
  373. int rc = true;
  374. spin_lock_bh(&q_vector->lock);
  375. if ((q_vector->state & IXGBE_QV_LOCKED)) {
  376. q_vector->state |= IXGBE_QV_STATE_POLL_YIELD;
  377. rc = false;
  378. #ifdef LL_EXTENDED_STATS
  379. q_vector->rx.ring->stats.yields++;
  380. #endif
  381. } else
  382. /* preserve yield marks */
  383. q_vector->state |= IXGBE_QV_STATE_POLL;
  384. spin_unlock_bh(&q_vector->lock);
  385. return rc;
  386. }
  387. /* returns true if someone tried to get the qv while it was locked */
  388. static inline bool ixgbe_qv_unlock_poll(struct ixgbe_q_vector *q_vector)
  389. {
  390. int rc = false;
  391. spin_lock_bh(&q_vector->lock);
  392. WARN_ON(q_vector->state & (IXGBE_QV_STATE_NAPI));
  393. if (q_vector->state & IXGBE_QV_STATE_POLL_YIELD)
  394. rc = true;
  395. q_vector->state = IXGBE_QV_STATE_IDLE;
  396. spin_unlock_bh(&q_vector->lock);
  397. return rc;
  398. }
  399. /* true if a socket is polling, even if it did not get the lock */
  400. static inline bool ixgbe_qv_ll_polling(struct ixgbe_q_vector *q_vector)
  401. {
  402. WARN_ON(!(q_vector->state & IXGBE_QV_LOCKED));
  403. return q_vector->state & IXGBE_QV_USER_PEND;
  404. }
  405. #else /* CONFIG_NET_RX_BUSY_POLL */
  406. static inline void ixgbe_qv_init_lock(struct ixgbe_q_vector *q_vector)
  407. {
  408. }
  409. static inline bool ixgbe_qv_lock_napi(struct ixgbe_q_vector *q_vector)
  410. {
  411. return true;
  412. }
  413. static inline bool ixgbe_qv_unlock_napi(struct ixgbe_q_vector *q_vector)
  414. {
  415. return false;
  416. }
  417. static inline bool ixgbe_qv_lock_poll(struct ixgbe_q_vector *q_vector)
  418. {
  419. return false;
  420. }
  421. static inline bool ixgbe_qv_unlock_poll(struct ixgbe_q_vector *q_vector)
  422. {
  423. return false;
  424. }
  425. static inline bool ixgbe_qv_ll_polling(struct ixgbe_q_vector *q_vector)
  426. {
  427. return false;
  428. }
  429. #endif /* CONFIG_NET_RX_BUSY_POLL */
  430. #ifdef CONFIG_IXGBE_HWMON
  431. #define IXGBE_HWMON_TYPE_LOC 0
  432. #define IXGBE_HWMON_TYPE_TEMP 1
  433. #define IXGBE_HWMON_TYPE_CAUTION 2
  434. #define IXGBE_HWMON_TYPE_MAX 3
  435. struct hwmon_attr {
  436. struct device_attribute dev_attr;
  437. struct ixgbe_hw *hw;
  438. struct ixgbe_thermal_diode_data *sensor;
  439. char name[12];
  440. };
  441. struct hwmon_buff {
  442. struct device *device;
  443. struct hwmon_attr *hwmon_list;
  444. unsigned int n_hwmon;
  445. };
  446. #endif /* CONFIG_IXGBE_HWMON */
  447. /*
  448. * microsecond values for various ITR rates shifted by 2 to fit itr register
  449. * with the first 3 bits reserved 0
  450. */
  451. #define IXGBE_MIN_RSC_ITR 24
  452. #define IXGBE_100K_ITR 40
  453. #define IXGBE_20K_ITR 200
  454. #define IXGBE_10K_ITR 400
  455. #define IXGBE_8K_ITR 500
  456. /* ixgbe_test_staterr - tests bits in Rx descriptor status and error fields */
  457. static inline __le32 ixgbe_test_staterr(union ixgbe_adv_rx_desc *rx_desc,
  458. const u32 stat_err_bits)
  459. {
  460. return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
  461. }
  462. static inline u16 ixgbe_desc_unused(struct ixgbe_ring *ring)
  463. {
  464. u16 ntc = ring->next_to_clean;
  465. u16 ntu = ring->next_to_use;
  466. return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
  467. }
  468. #define IXGBE_RX_DESC(R, i) \
  469. (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
  470. #define IXGBE_TX_DESC(R, i) \
  471. (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
  472. #define IXGBE_TX_CTXTDESC(R, i) \
  473. (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
  474. #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
  475. #ifdef IXGBE_FCOE
  476. /* Use 3K as the baby jumbo frame size for FCoE */
  477. #define IXGBE_FCOE_JUMBO_FRAME_SIZE 3072
  478. #endif /* IXGBE_FCOE */
  479. #define OTHER_VECTOR 1
  480. #define NON_Q_VECTORS (OTHER_VECTOR)
  481. #define MAX_MSIX_VECTORS_82599 64
  482. #define MAX_Q_VECTORS_82599 64
  483. #define MAX_MSIX_VECTORS_82598 18
  484. #define MAX_Q_VECTORS_82598 16
  485. #define MAX_Q_VECTORS MAX_Q_VECTORS_82599
  486. #define MAX_MSIX_COUNT MAX_MSIX_VECTORS_82599
  487. #define MIN_MSIX_Q_VECTORS 1
  488. #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
  489. /* default to trying for four seconds */
  490. #define IXGBE_TRY_LINK_TIMEOUT (4 * HZ)
  491. /* board specific private data structure */
  492. struct ixgbe_adapter {
  493. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  494. /* OS defined structs */
  495. struct net_device *netdev;
  496. struct pci_dev *pdev;
  497. unsigned long state;
  498. /* Some features need tri-state capability,
  499. * thus the additional *_CAPABLE flags.
  500. */
  501. u32 flags;
  502. #define IXGBE_FLAG_MSI_CAPABLE (u32)(1 << 0)
  503. #define IXGBE_FLAG_MSI_ENABLED (u32)(1 << 1)
  504. #define IXGBE_FLAG_MSIX_CAPABLE (u32)(1 << 2)
  505. #define IXGBE_FLAG_MSIX_ENABLED (u32)(1 << 3)
  506. #define IXGBE_FLAG_RX_1BUF_CAPABLE (u32)(1 << 4)
  507. #define IXGBE_FLAG_RX_PS_CAPABLE (u32)(1 << 5)
  508. #define IXGBE_FLAG_RX_PS_ENABLED (u32)(1 << 6)
  509. #define IXGBE_FLAG_IN_NETPOLL (u32)(1 << 7)
  510. #define IXGBE_FLAG_DCA_ENABLED (u32)(1 << 8)
  511. #define IXGBE_FLAG_DCA_CAPABLE (u32)(1 << 9)
  512. #define IXGBE_FLAG_IMIR_ENABLED (u32)(1 << 10)
  513. #define IXGBE_FLAG_MQ_CAPABLE (u32)(1 << 11)
  514. #define IXGBE_FLAG_DCB_ENABLED (u32)(1 << 12)
  515. #define IXGBE_FLAG_VMDQ_CAPABLE (u32)(1 << 13)
  516. #define IXGBE_FLAG_VMDQ_ENABLED (u32)(1 << 14)
  517. #define IXGBE_FLAG_FAN_FAIL_CAPABLE (u32)(1 << 15)
  518. #define IXGBE_FLAG_NEED_LINK_UPDATE (u32)(1 << 16)
  519. #define IXGBE_FLAG_NEED_LINK_CONFIG (u32)(1 << 17)
  520. #define IXGBE_FLAG_FDIR_HASH_CAPABLE (u32)(1 << 18)
  521. #define IXGBE_FLAG_FDIR_PERFECT_CAPABLE (u32)(1 << 19)
  522. #define IXGBE_FLAG_FCOE_CAPABLE (u32)(1 << 20)
  523. #define IXGBE_FLAG_FCOE_ENABLED (u32)(1 << 21)
  524. #define IXGBE_FLAG_SRIOV_CAPABLE (u32)(1 << 22)
  525. #define IXGBE_FLAG_SRIOV_ENABLED (u32)(1 << 23)
  526. u32 flags2;
  527. #define IXGBE_FLAG2_RSC_CAPABLE (u32)(1 << 0)
  528. #define IXGBE_FLAG2_RSC_ENABLED (u32)(1 << 1)
  529. #define IXGBE_FLAG2_TEMP_SENSOR_CAPABLE (u32)(1 << 2)
  530. #define IXGBE_FLAG2_TEMP_SENSOR_EVENT (u32)(1 << 3)
  531. #define IXGBE_FLAG2_SEARCH_FOR_SFP (u32)(1 << 4)
  532. #define IXGBE_FLAG2_SFP_NEEDS_RESET (u32)(1 << 5)
  533. #define IXGBE_FLAG2_RESET_REQUESTED (u32)(1 << 6)
  534. #define IXGBE_FLAG2_FDIR_REQUIRES_REINIT (u32)(1 << 7)
  535. #define IXGBE_FLAG2_RSS_FIELD_IPV4_UDP (u32)(1 << 8)
  536. #define IXGBE_FLAG2_RSS_FIELD_IPV6_UDP (u32)(1 << 9)
  537. #define IXGBE_FLAG2_PTP_PPS_ENABLED (u32)(1 << 10)
  538. #define IXGBE_FLAG2_BRIDGE_MODE_VEB (u32)(1 << 11)
  539. /* Tx fast path data */
  540. int num_tx_queues;
  541. u16 tx_itr_setting;
  542. u16 tx_work_limit;
  543. /* Rx fast path data */
  544. int num_rx_queues;
  545. u16 rx_itr_setting;
  546. /* TX */
  547. struct ixgbe_ring *tx_ring[MAX_TX_QUEUES] ____cacheline_aligned_in_smp;
  548. u64 restart_queue;
  549. u64 lsc_int;
  550. u32 tx_timeout_count;
  551. /* RX */
  552. struct ixgbe_ring *rx_ring[MAX_RX_QUEUES];
  553. int num_rx_pools; /* == num_rx_queues in 82598 */
  554. int num_rx_queues_per_pool; /* 1 if 82598, can be many if 82599 */
  555. u64 hw_csum_rx_error;
  556. u64 hw_rx_no_dma_resources;
  557. u64 rsc_total_count;
  558. u64 rsc_total_flush;
  559. u64 non_eop_descs;
  560. u32 alloc_rx_page_failed;
  561. u32 alloc_rx_buff_failed;
  562. struct ixgbe_q_vector *q_vector[MAX_Q_VECTORS];
  563. /* DCB parameters */
  564. struct ieee_pfc *ixgbe_ieee_pfc;
  565. struct ieee_ets *ixgbe_ieee_ets;
  566. struct ixgbe_dcb_config dcb_cfg;
  567. struct ixgbe_dcb_config temp_dcb_cfg;
  568. u8 dcb_set_bitmap;
  569. u8 dcbx_cap;
  570. enum ixgbe_fc_mode last_lfc_mode;
  571. int num_q_vectors; /* current number of q_vectors for device */
  572. int max_q_vectors; /* true count of q_vectors for device */
  573. struct ixgbe_ring_feature ring_feature[RING_F_ARRAY_SIZE];
  574. struct msix_entry *msix_entries;
  575. u32 test_icr;
  576. struct ixgbe_ring test_tx_ring;
  577. struct ixgbe_ring test_rx_ring;
  578. /* structs defined in ixgbe_hw.h */
  579. struct ixgbe_hw hw;
  580. u16 msg_enable;
  581. struct ixgbe_hw_stats stats;
  582. u64 tx_busy;
  583. unsigned int tx_ring_count;
  584. unsigned int rx_ring_count;
  585. u32 link_speed;
  586. bool link_up;
  587. unsigned long link_check_timeout;
  588. struct timer_list service_timer;
  589. struct work_struct service_task;
  590. struct hlist_head fdir_filter_list;
  591. unsigned long fdir_overflow; /* number of times ATR was backed off */
  592. union ixgbe_atr_input fdir_mask;
  593. int fdir_filter_count;
  594. u32 fdir_pballoc;
  595. u32 atr_sample_rate;
  596. spinlock_t fdir_perfect_lock;
  597. #ifdef IXGBE_FCOE
  598. struct ixgbe_fcoe fcoe;
  599. #endif /* IXGBE_FCOE */
  600. u32 wol;
  601. u16 bd_number;
  602. u16 eeprom_verh;
  603. u16 eeprom_verl;
  604. u16 eeprom_cap;
  605. u32 interrupt_event;
  606. u32 led_reg;
  607. struct ptp_clock *ptp_clock;
  608. struct ptp_clock_info ptp_caps;
  609. struct work_struct ptp_tx_work;
  610. struct sk_buff *ptp_tx_skb;
  611. unsigned long ptp_tx_start;
  612. unsigned long last_overflow_check;
  613. unsigned long last_rx_ptp_check;
  614. spinlock_t tmreg_lock;
  615. struct cyclecounter cc;
  616. struct timecounter tc;
  617. u32 base_incval;
  618. /* SR-IOV */
  619. DECLARE_BITMAP(active_vfs, IXGBE_MAX_VF_FUNCTIONS);
  620. unsigned int num_vfs;
  621. struct vf_data_storage *vfinfo;
  622. int vf_rate_link_speed;
  623. struct vf_macvlans vf_mvs;
  624. struct vf_macvlans *mv_list;
  625. u32 timer_event_accumulator;
  626. u32 vferr_refcount;
  627. struct kobject *info_kobj;
  628. #ifdef CONFIG_IXGBE_HWMON
  629. struct hwmon_buff ixgbe_hwmon_buff;
  630. #endif /* CONFIG_IXGBE_HWMON */
  631. #ifdef CONFIG_DEBUG_FS
  632. struct dentry *ixgbe_dbg_adapter;
  633. #endif /*CONFIG_DEBUG_FS*/
  634. u8 default_up;
  635. };
  636. struct ixgbe_fdir_filter {
  637. struct hlist_node fdir_node;
  638. union ixgbe_atr_input filter;
  639. u16 sw_idx;
  640. u16 action;
  641. };
  642. enum ixgbe_state_t {
  643. __IXGBE_TESTING,
  644. __IXGBE_RESETTING,
  645. __IXGBE_DOWN,
  646. __IXGBE_SERVICE_SCHED,
  647. __IXGBE_IN_SFP_INIT,
  648. __IXGBE_PTP_RUNNING,
  649. };
  650. struct ixgbe_cb {
  651. union { /* Union defining head/tail partner */
  652. struct sk_buff *head;
  653. struct sk_buff *tail;
  654. };
  655. dma_addr_t dma;
  656. u16 append_cnt;
  657. bool page_released;
  658. };
  659. #define IXGBE_CB(skb) ((struct ixgbe_cb *)(skb)->cb)
  660. enum ixgbe_boards {
  661. board_82598,
  662. board_82599,
  663. board_X540,
  664. };
  665. extern struct ixgbe_info ixgbe_82598_info;
  666. extern struct ixgbe_info ixgbe_82599_info;
  667. extern struct ixgbe_info ixgbe_X540_info;
  668. #ifdef CONFIG_IXGBE_DCB
  669. extern const struct dcbnl_rtnl_ops dcbnl_ops;
  670. #endif
  671. extern char ixgbe_driver_name[];
  672. extern const char ixgbe_driver_version[];
  673. #ifdef IXGBE_FCOE
  674. extern char ixgbe_default_device_descr[];
  675. #endif /* IXGBE_FCOE */
  676. extern void ixgbe_up(struct ixgbe_adapter *adapter);
  677. extern void ixgbe_down(struct ixgbe_adapter *adapter);
  678. extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter);
  679. extern void ixgbe_reset(struct ixgbe_adapter *adapter);
  680. extern void ixgbe_set_ethtool_ops(struct net_device *netdev);
  681. extern int ixgbe_setup_rx_resources(struct ixgbe_ring *);
  682. extern int ixgbe_setup_tx_resources(struct ixgbe_ring *);
  683. extern void ixgbe_free_rx_resources(struct ixgbe_ring *);
  684. extern void ixgbe_free_tx_resources(struct ixgbe_ring *);
  685. extern void ixgbe_configure_rx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
  686. extern void ixgbe_configure_tx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
  687. extern void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  688. struct ixgbe_ring *);
  689. extern void ixgbe_update_stats(struct ixgbe_adapter *adapter);
  690. extern int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter);
  691. extern int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  692. u16 subdevice_id);
  693. extern void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter);
  694. extern netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *,
  695. struct ixgbe_adapter *,
  696. struct ixgbe_ring *);
  697. extern void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *,
  698. struct ixgbe_tx_buffer *);
  699. extern void ixgbe_alloc_rx_buffers(struct ixgbe_ring *, u16);
  700. extern void ixgbe_write_eitr(struct ixgbe_q_vector *);
  701. extern int ixgbe_poll(struct napi_struct *napi, int budget);
  702. extern int ethtool_ioctl(struct ifreq *ifr);
  703. extern s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw);
  704. extern s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl);
  705. extern s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl);
  706. extern s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  707. union ixgbe_atr_hash_dword input,
  708. union ixgbe_atr_hash_dword common,
  709. u8 queue);
  710. extern s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
  711. union ixgbe_atr_input *input_mask);
  712. extern s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
  713. union ixgbe_atr_input *input,
  714. u16 soft_id, u8 queue);
  715. extern s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
  716. union ixgbe_atr_input *input,
  717. u16 soft_id);
  718. extern void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
  719. union ixgbe_atr_input *mask);
  720. extern bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw);
  721. extern void ixgbe_set_rx_mode(struct net_device *netdev);
  722. #ifdef CONFIG_IXGBE_DCB
  723. extern void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter);
  724. #endif
  725. extern int ixgbe_setup_tc(struct net_device *dev, u8 tc);
  726. extern void ixgbe_tx_ctxtdesc(struct ixgbe_ring *, u32, u32, u32, u32);
  727. extern void ixgbe_do_reset(struct net_device *netdev);
  728. #ifdef CONFIG_IXGBE_HWMON
  729. extern void ixgbe_sysfs_exit(struct ixgbe_adapter *adapter);
  730. extern int ixgbe_sysfs_init(struct ixgbe_adapter *adapter);
  731. #endif /* CONFIG_IXGBE_HWMON */
  732. #ifdef IXGBE_FCOE
  733. extern void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter);
  734. extern int ixgbe_fso(struct ixgbe_ring *tx_ring,
  735. struct ixgbe_tx_buffer *first,
  736. u8 *hdr_len);
  737. extern int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
  738. union ixgbe_adv_rx_desc *rx_desc,
  739. struct sk_buff *skb);
  740. extern int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid,
  741. struct scatterlist *sgl, unsigned int sgc);
  742. extern int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid,
  743. struct scatterlist *sgl, unsigned int sgc);
  744. extern int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid);
  745. extern int ixgbe_setup_fcoe_ddp_resources(struct ixgbe_adapter *adapter);
  746. extern void ixgbe_free_fcoe_ddp_resources(struct ixgbe_adapter *adapter);
  747. extern int ixgbe_fcoe_enable(struct net_device *netdev);
  748. extern int ixgbe_fcoe_disable(struct net_device *netdev);
  749. #ifdef CONFIG_IXGBE_DCB
  750. extern u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter);
  751. extern u8 ixgbe_fcoe_setapp(struct ixgbe_adapter *adapter, u8 up);
  752. #endif /* CONFIG_IXGBE_DCB */
  753. extern int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
  754. extern int ixgbe_fcoe_get_hbainfo(struct net_device *netdev,
  755. struct netdev_fcoe_hbainfo *info);
  756. extern u8 ixgbe_fcoe_get_tc(struct ixgbe_adapter *adapter);
  757. #endif /* IXGBE_FCOE */
  758. #ifdef CONFIG_DEBUG_FS
  759. extern void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter);
  760. extern void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter);
  761. extern void ixgbe_dbg_init(void);
  762. extern void ixgbe_dbg_exit(void);
  763. #else
  764. static inline void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter) {}
  765. static inline void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter) {}
  766. static inline void ixgbe_dbg_init(void) {}
  767. static inline void ixgbe_dbg_exit(void) {}
  768. #endif /* CONFIG_DEBUG_FS */
  769. static inline struct netdev_queue *txring_txq(const struct ixgbe_ring *ring)
  770. {
  771. return netdev_get_tx_queue(ring->netdev, ring->queue_index);
  772. }
  773. extern void ixgbe_ptp_init(struct ixgbe_adapter *adapter);
  774. extern void ixgbe_ptp_stop(struct ixgbe_adapter *adapter);
  775. extern void ixgbe_ptp_overflow_check(struct ixgbe_adapter *adapter);
  776. extern void ixgbe_ptp_rx_hang(struct ixgbe_adapter *adapter);
  777. extern void __ixgbe_ptp_rx_hwtstamp(struct ixgbe_q_vector *q_vector,
  778. struct sk_buff *skb);
  779. static inline void ixgbe_ptp_rx_hwtstamp(struct ixgbe_ring *rx_ring,
  780. union ixgbe_adv_rx_desc *rx_desc,
  781. struct sk_buff *skb)
  782. {
  783. if (unlikely(!ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
  784. return;
  785. __ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, skb);
  786. /*
  787. * Update the last_rx_timestamp timer in order to enable watchdog check
  788. * for error case of latched timestamp on a dropped packet.
  789. */
  790. rx_ring->last_rx_timestamp = jiffies;
  791. }
  792. extern int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
  793. struct ifreq *ifr, int cmd);
  794. extern void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter);
  795. extern void ixgbe_ptp_reset(struct ixgbe_adapter *adapter);
  796. extern void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter, u32 eicr);
  797. #ifdef CONFIG_PCI_IOV
  798. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter);
  799. #endif
  800. #endif /* _IXGBE_H_ */