ice.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2018, Intel Corporation. */
  3. #ifndef _ICE_H_
  4. #define _ICE_H_
  5. #include <linux/types.h>
  6. #include <linux/errno.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/compiler.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/rtnetlink.h>
  15. #include <linux/if_vlan.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/pci.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/aer.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/ethtool.h>
  22. #include <linux/timer.h>
  23. #include <linux/delay.h>
  24. #include <linux/bitmap.h>
  25. #include <linux/log2.h>
  26. #include <linux/ip.h>
  27. #include <linux/ipv6.h>
  28. #include <linux/if_bridge.h>
  29. #include <net/ipv6.h>
  30. #include "ice_devids.h"
  31. #include "ice_type.h"
  32. #include "ice_txrx.h"
  33. #include "ice_switch.h"
  34. #include "ice_common.h"
  35. #include "ice_sched.h"
  36. extern const char ice_drv_ver[];
  37. #define ICE_BAR0 0
  38. #define ICE_DFLT_NUM_DESC 128
  39. #define ICE_MIN_NUM_DESC 8
  40. #define ICE_MAX_NUM_DESC 8160
  41. #define ICE_REQ_DESC_MULTIPLE 32
  42. #define ICE_DFLT_TRAFFIC_CLASS BIT(0)
  43. #define ICE_INT_NAME_STR_LEN (IFNAMSIZ + 16)
  44. #define ICE_ETHTOOL_FWVER_LEN 32
  45. #define ICE_AQ_LEN 64
  46. #define ICE_MIN_MSIX 2
  47. #define ICE_NO_VSI 0xffff
  48. #define ICE_MAX_VSI_ALLOC 130
  49. #define ICE_MAX_TXQS 2048
  50. #define ICE_MAX_RXQS 2048
  51. #define ICE_VSI_MAP_CONTIG 0
  52. #define ICE_VSI_MAP_SCATTER 1
  53. #define ICE_MAX_SCATTER_TXQS 16
  54. #define ICE_MAX_SCATTER_RXQS 16
  55. #define ICE_Q_WAIT_RETRY_LIMIT 10
  56. #define ICE_Q_WAIT_MAX_RETRY (5 * ICE_Q_WAIT_RETRY_LIMIT)
  57. #define ICE_MAX_LG_RSS_QS 256
  58. #define ICE_MAX_SMALL_RSS_QS 8
  59. #define ICE_RES_VALID_BIT 0x8000
  60. #define ICE_RES_MISC_VEC_ID (ICE_RES_VALID_BIT - 1)
  61. #define ICE_INVAL_Q_INDEX 0xffff
  62. #define ICE_VSIQF_HKEY_ARRAY_SIZE ((VSIQF_HKEY_MAX_INDEX + 1) * 4)
  63. #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  64. #define ICE_MAX_MTU (ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
  65. ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)
  66. #define ICE_UP_TABLE_TRANSLATE(val, i) \
  67. (((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  68. ICE_AQ_VSI_UP_TABLE_UP##i##_M)
  69. #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
  70. #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
  71. #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
  72. /* Macro for each VSI in a PF */
  73. #define ice_for_each_vsi(pf, i) \
  74. for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
  75. /* Macros for each tx/rx ring in a VSI */
  76. #define ice_for_each_txq(vsi, i) \
  77. for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
  78. #define ice_for_each_rxq(vsi, i) \
  79. for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
  80. /* Macros for each allocated tx/rx ring whether used or not in a VSI */
  81. #define ice_for_each_alloc_txq(vsi, i) \
  82. for ((i) = 0; (i) < (vsi)->alloc_txq; (i)++)
  83. #define ice_for_each_alloc_rxq(vsi, i) \
  84. for ((i) = 0; (i) < (vsi)->alloc_rxq; (i)++)
  85. struct ice_tc_info {
  86. u16 qoffset;
  87. u16 qcount;
  88. };
  89. struct ice_tc_cfg {
  90. u8 numtc; /* Total number of enabled TCs */
  91. u8 ena_tc; /* TX map */
  92. struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
  93. };
  94. struct ice_res_tracker {
  95. u16 num_entries;
  96. u16 search_hint;
  97. u16 list[1];
  98. };
  99. struct ice_sw {
  100. struct ice_pf *pf;
  101. u16 sw_id; /* switch ID for this switch */
  102. u16 bridge_mode; /* VEB/VEPA/Port Virtualizer */
  103. };
  104. enum ice_state {
  105. __ICE_DOWN,
  106. __ICE_NEEDS_RESTART,
  107. __ICE_RESET_RECOVERY_PENDING, /* set by driver when reset starts */
  108. __ICE_PFR_REQ, /* set by driver and peers */
  109. __ICE_CORER_REQ, /* set by driver and peers */
  110. __ICE_GLOBR_REQ, /* set by driver and peers */
  111. __ICE_CORER_RECV, /* set by OICR handler */
  112. __ICE_GLOBR_RECV, /* set by OICR handler */
  113. __ICE_EMPR_RECV, /* set by OICR handler */
  114. __ICE_SUSPENDED, /* set on module remove path */
  115. __ICE_RESET_FAILED, /* set by reset/rebuild */
  116. __ICE_ADMINQ_EVENT_PENDING,
  117. __ICE_FLTR_OVERFLOW_PROMISC,
  118. __ICE_CFG_BUSY,
  119. __ICE_SERVICE_SCHED,
  120. __ICE_STATE_NBITS /* must be last */
  121. };
  122. enum ice_vsi_flags {
  123. ICE_VSI_FLAG_UMAC_FLTR_CHANGED,
  124. ICE_VSI_FLAG_MMAC_FLTR_CHANGED,
  125. ICE_VSI_FLAG_VLAN_FLTR_CHANGED,
  126. ICE_VSI_FLAG_PROMISC_CHANGED,
  127. ICE_VSI_FLAG_NBITS /* must be last */
  128. };
  129. /* struct that defines a VSI, associated with a dev */
  130. struct ice_vsi {
  131. struct net_device *netdev;
  132. struct ice_sw *vsw; /* switch this VSI is on */
  133. struct ice_pf *back; /* back pointer to PF */
  134. struct ice_port_info *port_info; /* back pointer to port_info */
  135. struct ice_ring **rx_rings; /* rx ring array */
  136. struct ice_ring **tx_rings; /* tx ring array */
  137. struct ice_q_vector **q_vectors; /* q_vector array */
  138. irqreturn_t (*irq_handler)(int irq, void *data);
  139. u64 tx_linearize;
  140. DECLARE_BITMAP(state, __ICE_STATE_NBITS);
  141. DECLARE_BITMAP(flags, ICE_VSI_FLAG_NBITS);
  142. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  143. unsigned int current_netdev_flags;
  144. u32 tx_restart;
  145. u32 tx_busy;
  146. u32 rx_buf_failed;
  147. u32 rx_page_failed;
  148. int num_q_vectors;
  149. int base_vector;
  150. enum ice_vsi_type type;
  151. u16 vsi_num; /* HW (absolute) index of this VSI */
  152. u16 idx; /* software index in pf->vsi[] */
  153. /* Interrupt thresholds */
  154. u16 work_lmt;
  155. /* RSS config */
  156. u16 rss_table_size; /* HW RSS table size */
  157. u16 rss_size; /* Allocated RSS queues */
  158. u8 *rss_hkey_user; /* User configured hash keys */
  159. u8 *rss_lut_user; /* User configured lookup table entries */
  160. u8 rss_lut_type; /* used to configure Get/Set RSS LUT AQ call */
  161. u16 max_frame;
  162. u16 rx_buf_len;
  163. struct ice_aqc_vsi_props info; /* VSI properties */
  164. /* VSI stats */
  165. struct rtnl_link_stats64 net_stats;
  166. struct ice_eth_stats eth_stats;
  167. struct ice_eth_stats eth_stats_prev;
  168. struct list_head tmp_sync_list; /* MAC filters to be synced */
  169. struct list_head tmp_unsync_list; /* MAC filters to be unsynced */
  170. u8 irqs_ready;
  171. u8 current_isup; /* Sync 'link up' logging */
  172. u8 stat_offsets_loaded;
  173. /* queue information */
  174. u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  175. u8 rx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  176. u16 txq_map[ICE_MAX_TXQS]; /* index in pf->avail_txqs */
  177. u16 rxq_map[ICE_MAX_RXQS]; /* index in pf->avail_rxqs */
  178. u16 alloc_txq; /* Allocated Tx queues */
  179. u16 num_txq; /* Used Tx queues */
  180. u16 alloc_rxq; /* Allocated Rx queues */
  181. u16 num_rxq; /* Used Rx queues */
  182. u16 num_desc;
  183. struct ice_tc_cfg tc_cfg;
  184. } ____cacheline_internodealigned_in_smp;
  185. /* struct that defines an interrupt vector */
  186. struct ice_q_vector {
  187. struct ice_vsi *vsi;
  188. cpumask_t affinity_mask;
  189. struct napi_struct napi;
  190. struct ice_ring_container rx;
  191. struct ice_ring_container tx;
  192. struct irq_affinity_notify affinity_notify;
  193. u16 v_idx; /* index in the vsi->q_vector array. */
  194. u8 num_ring_tx; /* total number of tx rings in vector */
  195. u8 num_ring_rx; /* total number of rx rings in vector */
  196. char name[ICE_INT_NAME_STR_LEN];
  197. } ____cacheline_internodealigned_in_smp;
  198. enum ice_pf_flags {
  199. ICE_FLAG_MSIX_ENA,
  200. ICE_FLAG_FLTR_SYNC,
  201. ICE_FLAG_RSS_ENA,
  202. ICE_PF_FLAGS_NBITS /* must be last */
  203. };
  204. struct ice_pf {
  205. struct pci_dev *pdev;
  206. struct msix_entry *msix_entries;
  207. struct ice_res_tracker *irq_tracker;
  208. struct ice_vsi **vsi; /* VSIs created by the driver */
  209. struct ice_sw *first_sw; /* first switch created by firmware */
  210. DECLARE_BITMAP(state, __ICE_STATE_NBITS);
  211. DECLARE_BITMAP(avail_txqs, ICE_MAX_TXQS);
  212. DECLARE_BITMAP(avail_rxqs, ICE_MAX_RXQS);
  213. DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
  214. unsigned long serv_tmr_period;
  215. unsigned long serv_tmr_prev;
  216. struct timer_list serv_tmr;
  217. struct work_struct serv_task;
  218. struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
  219. struct mutex sw_mutex; /* lock for protecting VSI alloc flow */
  220. u32 msg_enable;
  221. u32 hw_csum_rx_error;
  222. u32 oicr_idx; /* Other interrupt cause vector index */
  223. u32 num_lan_msix; /* Total MSIX vectors for base driver */
  224. u32 num_avail_msix; /* remaining MSIX vectors left unclaimed */
  225. u16 num_lan_tx; /* num lan tx queues setup */
  226. u16 num_lan_rx; /* num lan rx queues setup */
  227. u16 q_left_tx; /* remaining num tx queues left unclaimed */
  228. u16 q_left_rx; /* remaining num rx queues left unclaimed */
  229. u16 next_vsi; /* Next free slot in pf->vsi[] - 0-based! */
  230. u16 num_alloc_vsi;
  231. u16 corer_count; /* Core reset count */
  232. u16 globr_count; /* Global reset count */
  233. u16 empr_count; /* EMP reset count */
  234. u16 pfr_count; /* PF reset count */
  235. struct ice_hw_port_stats stats;
  236. struct ice_hw_port_stats stats_prev;
  237. struct ice_hw hw;
  238. u8 stat_prev_loaded; /* has previous stats been loaded */
  239. char int_name[ICE_INT_NAME_STR_LEN];
  240. };
  241. struct ice_netdev_priv {
  242. struct ice_vsi *vsi;
  243. };
  244. /**
  245. * ice_irq_dynamic_ena - Enable default interrupt generation settings
  246. * @hw: pointer to hw struct
  247. * @vsi: pointer to vsi struct, can be NULL
  248. * @q_vector: pointer to q_vector, can be NULL
  249. */
  250. static inline void ice_irq_dynamic_ena(struct ice_hw *hw, struct ice_vsi *vsi,
  251. struct ice_q_vector *q_vector)
  252. {
  253. u32 vector = (vsi && q_vector) ? vsi->base_vector + q_vector->v_idx :
  254. ((struct ice_pf *)hw->back)->oicr_idx;
  255. int itr = ICE_ITR_NONE;
  256. u32 val;
  257. /* clear the PBA here, as this function is meant to clean out all
  258. * previous interrupts and enable the interrupt
  259. */
  260. val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
  261. (itr << GLINT_DYN_CTL_ITR_INDX_S);
  262. if (vsi)
  263. if (test_bit(__ICE_DOWN, vsi->state))
  264. return;
  265. wr32(hw, GLINT_DYN_CTL(vector), val);
  266. }
  267. static inline void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
  268. {
  269. vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
  270. vsi->tc_cfg.numtc = 1;
  271. }
  272. void ice_set_ethtool_ops(struct net_device *netdev);
  273. int ice_up(struct ice_vsi *vsi);
  274. int ice_down(struct ice_vsi *vsi);
  275. int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  276. int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  277. void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
  278. void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
  279. #endif /* _ICE_H_ */