fm10k.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /* Intel Ethernet Switch Host Interface Driver
  2. * Copyright(c) 2013 - 2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  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 _FM10K_H_
  21. #define _FM10K_H_
  22. #include <linux/types.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/rtnetlink.h>
  25. #include <linux/if_vlan.h>
  26. #include <linux/pci.h>
  27. #include <linux/net_tstamp.h>
  28. #include <linux/clocksource.h>
  29. #include <linux/ptp_clock_kernel.h>
  30. #include "fm10k_pf.h"
  31. #include "fm10k_vf.h"
  32. #define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */
  33. #define MAX_QUEUES FM10K_MAX_QUEUES_PF
  34. #define FM10K_MIN_RXD 128
  35. #define FM10K_MAX_RXD 4096
  36. #define FM10K_DEFAULT_RXD 256
  37. #define FM10K_MIN_TXD 128
  38. #define FM10K_MAX_TXD 4096
  39. #define FM10K_DEFAULT_TXD 256
  40. #define FM10K_DEFAULT_TX_WORK 256
  41. #define FM10K_RXBUFFER_256 256
  42. #define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256
  43. #define FM10K_RXBUFFER_2048 2048
  44. #define FM10K_RX_BUFSZ FM10K_RXBUFFER_2048
  45. /* How many Rx Buffers do we bundle into one write to the hardware ? */
  46. #define FM10K_RX_BUFFER_WRITE 16 /* Must be power of 2 */
  47. #define FM10K_MAX_STATIONS 63
  48. struct fm10k_l2_accel {
  49. int size;
  50. u16 count;
  51. u16 dglort;
  52. struct rcu_head rcu;
  53. struct net_device *macvlan[0];
  54. };
  55. enum fm10k_ring_state_t {
  56. __FM10K_TX_DETECT_HANG,
  57. __FM10K_HANG_CHECK_ARMED,
  58. };
  59. #define check_for_tx_hang(ring) \
  60. test_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
  61. #define set_check_for_tx_hang(ring) \
  62. set_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
  63. #define clear_check_for_tx_hang(ring) \
  64. clear_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
  65. struct fm10k_tx_buffer {
  66. struct fm10k_tx_desc *next_to_watch;
  67. struct sk_buff *skb;
  68. unsigned int bytecount;
  69. u16 gso_segs;
  70. u16 tx_flags;
  71. DEFINE_DMA_UNMAP_ADDR(dma);
  72. DEFINE_DMA_UNMAP_LEN(len);
  73. };
  74. struct fm10k_rx_buffer {
  75. dma_addr_t dma;
  76. struct page *page;
  77. u32 page_offset;
  78. };
  79. struct fm10k_queue_stats {
  80. u64 packets;
  81. u64 bytes;
  82. };
  83. struct fm10k_tx_queue_stats {
  84. u64 restart_queue;
  85. u64 csum_err;
  86. u64 tx_busy;
  87. u64 tx_done_old;
  88. };
  89. struct fm10k_rx_queue_stats {
  90. u64 alloc_failed;
  91. u64 csum_err;
  92. u64 errors;
  93. };
  94. struct fm10k_ring {
  95. struct fm10k_q_vector *q_vector;/* backpointer to host q_vector */
  96. struct net_device *netdev; /* netdev ring belongs to */
  97. struct device *dev; /* device for DMA mapping */
  98. struct fm10k_l2_accel __rcu *l2_accel; /* L2 acceleration list */
  99. void *desc; /* descriptor ring memory */
  100. union {
  101. struct fm10k_tx_buffer *tx_buffer;
  102. struct fm10k_rx_buffer *rx_buffer;
  103. };
  104. u32 __iomem *tail;
  105. unsigned long state;
  106. dma_addr_t dma; /* phys. address of descriptor ring */
  107. unsigned int size; /* length in bytes */
  108. u8 queue_index; /* needed for queue management */
  109. u8 reg_idx; /* holds the special value that gets
  110. * the hardware register offset
  111. * associated with this ring, which is
  112. * different for DCB and RSS modes
  113. */
  114. u8 qos_pc; /* priority class of queue */
  115. u16 vid; /* default vlan ID of queue */
  116. u16 count; /* amount of descriptors */
  117. u16 next_to_alloc;
  118. u16 next_to_use;
  119. u16 next_to_clean;
  120. struct fm10k_queue_stats stats;
  121. struct u64_stats_sync syncp;
  122. union {
  123. /* Tx */
  124. struct fm10k_tx_queue_stats tx_stats;
  125. /* Rx */
  126. struct {
  127. struct fm10k_rx_queue_stats rx_stats;
  128. struct sk_buff *skb;
  129. };
  130. };
  131. } ____cacheline_internodealigned_in_smp;
  132. struct fm10k_ring_container {
  133. struct fm10k_ring *ring; /* pointer to linked list of rings */
  134. unsigned int total_bytes; /* total bytes processed this int */
  135. unsigned int total_packets; /* total packets processed this int */
  136. u16 work_limit; /* total work allowed per interrupt */
  137. u16 itr; /* interrupt throttle rate value */
  138. u8 count; /* total number of rings in vector */
  139. };
  140. #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */
  141. #define FM10K_ITR_10K 100 /* 100us */
  142. #define FM10K_ITR_20K 50 /* 50us */
  143. #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */
  144. #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
  145. static inline struct netdev_queue *txring_txq(const struct fm10k_ring *ring)
  146. {
  147. return &ring->netdev->_tx[ring->queue_index];
  148. }
  149. /* iterator for handling rings in ring container */
  150. #define fm10k_for_each_ring(pos, head) \
  151. for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;)
  152. #define MAX_Q_VECTORS 256
  153. #define MIN_Q_VECTORS 1
  154. enum fm10k_non_q_vectors {
  155. FM10K_MBX_VECTOR,
  156. #define NON_Q_VECTORS_VF NON_Q_VECTORS_PF
  157. NON_Q_VECTORS_PF
  158. };
  159. #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
  160. NON_Q_VECTORS_PF : \
  161. NON_Q_VECTORS_VF)
  162. #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
  163. struct fm10k_q_vector {
  164. struct fm10k_intfc *interface;
  165. u32 __iomem *itr; /* pointer to ITR register for this vector */
  166. u16 v_idx; /* index of q_vector within interface array */
  167. struct fm10k_ring_container rx, tx;
  168. struct napi_struct napi;
  169. char name[IFNAMSIZ + 9];
  170. #ifdef CONFIG_DEBUG_FS
  171. struct dentry *dbg_q_vector;
  172. #endif /* CONFIG_DEBUG_FS */
  173. struct rcu_head rcu; /* to avoid race with update stats on free */
  174. /* for dynamic allocation of rings associated with this q_vector */
  175. struct fm10k_ring ring[0] ____cacheline_internodealigned_in_smp;
  176. };
  177. enum fm10k_ring_f_enum {
  178. RING_F_RSS,
  179. RING_F_QOS,
  180. RING_F_ARRAY_SIZE /* must be last in enum set */
  181. };
  182. struct fm10k_ring_feature {
  183. u16 limit; /* upper limit on feature indices */
  184. u16 indices; /* current value of indices */
  185. u16 mask; /* Mask used for feature to ring mapping */
  186. u16 offset; /* offset to start of feature */
  187. };
  188. struct fm10k_iov_data {
  189. unsigned int num_vfs;
  190. unsigned int next_vf_mbx;
  191. struct rcu_head rcu;
  192. struct fm10k_vf_info vf_info[0];
  193. };
  194. #define fm10k_vxlan_port_for_each(vp, intfc) \
  195. list_for_each_entry(vp, &(intfc)->vxlan_port, list)
  196. struct fm10k_vxlan_port {
  197. struct list_head list;
  198. sa_family_t sa_family;
  199. __be16 port;
  200. };
  201. /* one work queue for entire driver */
  202. extern struct workqueue_struct *fm10k_workqueue;
  203. struct fm10k_intfc {
  204. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  205. struct net_device *netdev;
  206. struct fm10k_l2_accel *l2_accel; /* pointer to L2 acceleration list */
  207. struct pci_dev *pdev;
  208. unsigned long state;
  209. u32 flags;
  210. #define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0)
  211. #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1)
  212. #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2)
  213. #define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3)
  214. #define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4)
  215. int xcast_mode;
  216. /* Tx fast path data */
  217. int num_tx_queues;
  218. u16 tx_itr;
  219. /* Rx fast path data */
  220. int num_rx_queues;
  221. u16 rx_itr;
  222. /* TX */
  223. struct fm10k_ring *tx_ring[MAX_QUEUES] ____cacheline_aligned_in_smp;
  224. u64 restart_queue;
  225. u64 tx_busy;
  226. u64 tx_csum_errors;
  227. u64 alloc_failed;
  228. u64 rx_csum_errors;
  229. u64 tx_bytes_nic;
  230. u64 tx_packets_nic;
  231. u64 rx_bytes_nic;
  232. u64 rx_packets_nic;
  233. u64 rx_drops_nic;
  234. u64 rx_overrun_pf;
  235. u64 rx_overrun_vf;
  236. u32 tx_timeout_count;
  237. /* RX */
  238. struct fm10k_ring *rx_ring[MAX_QUEUES];
  239. /* Queueing vectors */
  240. struct fm10k_q_vector *q_vector[MAX_Q_VECTORS];
  241. struct msix_entry *msix_entries;
  242. int num_q_vectors; /* current number of q_vectors for device */
  243. struct fm10k_ring_feature ring_feature[RING_F_ARRAY_SIZE];
  244. /* SR-IOV information management structure */
  245. struct fm10k_iov_data *iov_data;
  246. struct fm10k_hw_stats stats;
  247. struct fm10k_hw hw;
  248. u32 __iomem *uc_addr;
  249. u32 __iomem *sw_addr;
  250. u16 msg_enable;
  251. u16 tx_ring_count;
  252. u16 rx_ring_count;
  253. struct timer_list service_timer;
  254. struct work_struct service_task;
  255. unsigned long next_stats_update;
  256. unsigned long next_tx_hang_check;
  257. unsigned long last_reset;
  258. unsigned long link_down_event;
  259. bool host_ready;
  260. u32 reta[FM10K_RETA_SIZE];
  261. u32 rssrk[FM10K_RSSRK_SIZE];
  262. /* VXLAN port tracking information */
  263. struct list_head vxlan_port;
  264. #ifdef CONFIG_DEBUG_FS
  265. struct dentry *dbg_intfc;
  266. #endif /* CONFIG_DEBUG_FS */
  267. struct ptp_clock_info ptp_caps;
  268. struct ptp_clock *ptp_clock;
  269. struct sk_buff_head ts_tx_skb_queue;
  270. u32 tx_hwtstamp_timeouts;
  271. struct hwtstamp_config ts_config;
  272. /* We are unable to actually adjust the clock beyond the frequency
  273. * value. Once the clock is started there is no resetting it. As
  274. * such we maintain a separate offset from the actual hardware clock
  275. * to allow for offset adjustment.
  276. */
  277. s64 ptp_adjust;
  278. rwlock_t systime_lock;
  279. #ifdef CONFIG_DCB
  280. u8 pfc_en;
  281. #endif
  282. u8 rx_pause;
  283. /* GLORT resources in use by PF */
  284. u16 glort;
  285. u16 glort_count;
  286. /* VLAN ID for updating multicast/unicast lists */
  287. u16 vid;
  288. };
  289. enum fm10k_state_t {
  290. __FM10K_RESETTING,
  291. __FM10K_DOWN,
  292. __FM10K_SERVICE_SCHED,
  293. __FM10K_SERVICE_DISABLE,
  294. __FM10K_MBX_LOCK,
  295. __FM10K_LINK_DOWN,
  296. };
  297. static inline void fm10k_mbx_lock(struct fm10k_intfc *interface)
  298. {
  299. /* busy loop if we cannot obtain the lock as some calls
  300. * such as ndo_set_rx_mode may be made in atomic context
  301. */
  302. while (test_and_set_bit(__FM10K_MBX_LOCK, &interface->state))
  303. udelay(20);
  304. }
  305. static inline void fm10k_mbx_unlock(struct fm10k_intfc *interface)
  306. {
  307. /* flush memory to make sure state is correct */
  308. smp_mb__before_atomic();
  309. clear_bit(__FM10K_MBX_LOCK, &interface->state);
  310. }
  311. static inline int fm10k_mbx_trylock(struct fm10k_intfc *interface)
  312. {
  313. return !test_and_set_bit(__FM10K_MBX_LOCK, &interface->state);
  314. }
  315. /* fm10k_test_staterr - test bits in Rx descriptor status and error fields */
  316. static inline __le32 fm10k_test_staterr(union fm10k_rx_desc *rx_desc,
  317. const u32 stat_err_bits)
  318. {
  319. return rx_desc->d.staterr & cpu_to_le32(stat_err_bits);
  320. }
  321. /* fm10k_desc_unused - calculate if we have unused descriptors */
  322. static inline u16 fm10k_desc_unused(struct fm10k_ring *ring)
  323. {
  324. s16 unused = ring->next_to_clean - ring->next_to_use - 1;
  325. return likely(unused < 0) ? unused + ring->count : unused;
  326. }
  327. #define FM10K_TX_DESC(R, i) \
  328. (&(((struct fm10k_tx_desc *)((R)->desc))[i]))
  329. #define FM10K_RX_DESC(R, i) \
  330. (&(((union fm10k_rx_desc *)((R)->desc))[i]))
  331. #define FM10K_MAX_TXD_PWR 14
  332. #define FM10K_MAX_DATA_PER_TXD (1 << FM10K_MAX_TXD_PWR)
  333. /* Tx Descriptors needed, worst case */
  334. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD)
  335. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  336. enum fm10k_tx_flags {
  337. /* Tx offload flags */
  338. FM10K_TX_FLAGS_CSUM = 0x01,
  339. };
  340. /* This structure is stored as little endian values as that is the native
  341. * format of the Rx descriptor. The ordering of these fields is reversed
  342. * from the actual ftag header to allow for a single bswap to take care
  343. * of placing all of the values in network order
  344. */
  345. union fm10k_ftag_info {
  346. __le64 ftag;
  347. struct {
  348. /* dglort and sglort combined into a single 32bit desc read */
  349. __le32 glort;
  350. /* upper 16 bits of vlan are reserved 0 for swpri_type_user */
  351. __le32 vlan;
  352. } d;
  353. struct {
  354. __le16 dglort;
  355. __le16 sglort;
  356. __le16 vlan;
  357. __le16 swpri_type_user;
  358. } w;
  359. };
  360. struct fm10k_cb {
  361. union {
  362. __le64 tstamp;
  363. unsigned long ts_tx_timeout;
  364. };
  365. union fm10k_ftag_info fi;
  366. };
  367. #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb)
  368. /* main */
  369. extern char fm10k_driver_name[];
  370. extern const char fm10k_driver_version[];
  371. int fm10k_init_queueing_scheme(struct fm10k_intfc *interface);
  372. void fm10k_clear_queueing_scheme(struct fm10k_intfc *interface);
  373. __be16 fm10k_tx_encap_offload(struct sk_buff *skb);
  374. netdev_tx_t fm10k_xmit_frame_ring(struct sk_buff *skb,
  375. struct fm10k_ring *tx_ring);
  376. void fm10k_tx_timeout_reset(struct fm10k_intfc *interface);
  377. bool fm10k_check_tx_hang(struct fm10k_ring *tx_ring);
  378. void fm10k_alloc_rx_buffers(struct fm10k_ring *rx_ring, u16 cleaned_count);
  379. /* PCI */
  380. void fm10k_mbx_free_irq(struct fm10k_intfc *);
  381. int fm10k_mbx_request_irq(struct fm10k_intfc *);
  382. void fm10k_qv_free_irq(struct fm10k_intfc *interface);
  383. int fm10k_qv_request_irq(struct fm10k_intfc *interface);
  384. int fm10k_register_pci_driver(void);
  385. void fm10k_unregister_pci_driver(void);
  386. void fm10k_up(struct fm10k_intfc *interface);
  387. void fm10k_down(struct fm10k_intfc *interface);
  388. void fm10k_update_stats(struct fm10k_intfc *interface);
  389. void fm10k_service_event_schedule(struct fm10k_intfc *interface);
  390. void fm10k_update_rx_drop_en(struct fm10k_intfc *interface);
  391. #ifdef CONFIG_NET_POLL_CONTROLLER
  392. void fm10k_netpoll(struct net_device *netdev);
  393. #endif
  394. /* Netdev */
  395. struct net_device *fm10k_alloc_netdev(void);
  396. int fm10k_setup_rx_resources(struct fm10k_ring *);
  397. int fm10k_setup_tx_resources(struct fm10k_ring *);
  398. void fm10k_free_rx_resources(struct fm10k_ring *);
  399. void fm10k_free_tx_resources(struct fm10k_ring *);
  400. void fm10k_clean_all_rx_rings(struct fm10k_intfc *);
  401. void fm10k_clean_all_tx_rings(struct fm10k_intfc *);
  402. void fm10k_unmap_and_free_tx_resource(struct fm10k_ring *,
  403. struct fm10k_tx_buffer *);
  404. void fm10k_restore_rx_state(struct fm10k_intfc *);
  405. void fm10k_reset_rx_state(struct fm10k_intfc *);
  406. int fm10k_setup_tc(struct net_device *dev, u8 tc);
  407. int fm10k_open(struct net_device *netdev);
  408. int fm10k_close(struct net_device *netdev);
  409. /* Ethtool */
  410. void fm10k_set_ethtool_ops(struct net_device *dev);
  411. /* IOV */
  412. s32 fm10k_iov_event(struct fm10k_intfc *interface);
  413. s32 fm10k_iov_mbx(struct fm10k_intfc *interface);
  414. void fm10k_iov_suspend(struct pci_dev *pdev);
  415. int fm10k_iov_resume(struct pci_dev *pdev);
  416. void fm10k_iov_disable(struct pci_dev *pdev);
  417. int fm10k_iov_configure(struct pci_dev *pdev, int num_vfs);
  418. s32 fm10k_iov_update_pvid(struct fm10k_intfc *interface, u16 glort, u16 pvid);
  419. int fm10k_ndo_set_vf_mac(struct net_device *netdev, int vf_idx, u8 *mac);
  420. int fm10k_ndo_set_vf_vlan(struct net_device *netdev,
  421. int vf_idx, u16 vid, u8 qos);
  422. int fm10k_ndo_set_vf_bw(struct net_device *netdev, int vf_idx, int rate,
  423. int unused);
  424. int fm10k_ndo_get_vf_config(struct net_device *netdev,
  425. int vf_idx, struct ifla_vf_info *ivi);
  426. /* DebugFS */
  427. #ifdef CONFIG_DEBUG_FS
  428. void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector);
  429. void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector);
  430. void fm10k_dbg_intfc_init(struct fm10k_intfc *interface);
  431. void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface);
  432. void fm10k_dbg_init(void);
  433. void fm10k_dbg_exit(void);
  434. #else
  435. static inline void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector) {}
  436. static inline void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector) {}
  437. static inline void fm10k_dbg_intfc_init(struct fm10k_intfc *interface) {}
  438. static inline void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface) {}
  439. static inline void fm10k_dbg_init(void) {}
  440. static inline void fm10k_dbg_exit(void) {}
  441. #endif /* CONFIG_DEBUG_FS */
  442. /* Time Stamping */
  443. void fm10k_systime_to_hwtstamp(struct fm10k_intfc *interface,
  444. struct skb_shared_hwtstamps *hwtstamp,
  445. u64 systime);
  446. void fm10k_ts_tx_enqueue(struct fm10k_intfc *interface, struct sk_buff *skb);
  447. void fm10k_ts_tx_hwtstamp(struct fm10k_intfc *interface, __le16 dglort,
  448. u64 systime);
  449. void fm10k_ts_reset(struct fm10k_intfc *interface);
  450. void fm10k_ts_init(struct fm10k_intfc *interface);
  451. void fm10k_ts_tx_subtask(struct fm10k_intfc *interface);
  452. void fm10k_ptp_register(struct fm10k_intfc *interface);
  453. void fm10k_ptp_unregister(struct fm10k_intfc *interface);
  454. int fm10k_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
  455. int fm10k_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
  456. /* DCB */
  457. void fm10k_dcbnl_set_ops(struct net_device *dev);
  458. #endif /* _FM10K_H_ */