ice.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 <linux/avf/virtchnl.h>
  30. #include <net/ipv6.h>
  31. #include "ice_devids.h"
  32. #include "ice_type.h"
  33. #include "ice_txrx.h"
  34. #include "ice_switch.h"
  35. #include "ice_common.h"
  36. #include "ice_sched.h"
  37. #include "ice_virtchnl_pf.h"
  38. #include "ice_sriov.h"
  39. extern const char ice_drv_ver[];
  40. #define ICE_BAR0 0
  41. #define ICE_DFLT_NUM_DESC 128
  42. #define ICE_REQ_DESC_MULTIPLE 32
  43. #define ICE_MIN_NUM_DESC ICE_REQ_DESC_MULTIPLE
  44. #define ICE_MAX_NUM_DESC 8160
  45. #define ICE_DFLT_TRAFFIC_CLASS BIT(0)
  46. #define ICE_INT_NAME_STR_LEN (IFNAMSIZ + 16)
  47. #define ICE_ETHTOOL_FWVER_LEN 32
  48. #define ICE_AQ_LEN 64
  49. #define ICE_MBXQ_LEN 64
  50. #define ICE_MIN_MSIX 2
  51. #define ICE_NO_VSI 0xffff
  52. #define ICE_MAX_VSI_ALLOC 130
  53. #define ICE_MAX_TXQS 2048
  54. #define ICE_MAX_RXQS 2048
  55. #define ICE_VSI_MAP_CONTIG 0
  56. #define ICE_VSI_MAP_SCATTER 1
  57. #define ICE_MAX_SCATTER_TXQS 16
  58. #define ICE_MAX_SCATTER_RXQS 16
  59. #define ICE_Q_WAIT_RETRY_LIMIT 10
  60. #define ICE_Q_WAIT_MAX_RETRY (5 * ICE_Q_WAIT_RETRY_LIMIT)
  61. #define ICE_MAX_LG_RSS_QS 256
  62. #define ICE_MAX_SMALL_RSS_QS 8
  63. #define ICE_RES_VALID_BIT 0x8000
  64. #define ICE_RES_MISC_VEC_ID (ICE_RES_VALID_BIT - 1)
  65. #define ICE_INVAL_Q_INDEX 0xffff
  66. #define ICE_INVAL_VFID 256
  67. #define ICE_MAX_VF_COUNT 256
  68. #define ICE_MAX_QS_PER_VF 256
  69. #define ICE_MIN_QS_PER_VF 1
  70. #define ICE_DFLT_QS_PER_VF 4
  71. #define ICE_MAX_BASE_QS_PER_VF 16
  72. #define ICE_MAX_INTR_PER_VF 65
  73. #define ICE_MIN_INTR_PER_VF (ICE_MIN_QS_PER_VF + 1)
  74. #define ICE_DFLT_INTR_PER_VF (ICE_DFLT_QS_PER_VF + 1)
  75. #define ICE_VSIQF_HKEY_ARRAY_SIZE ((VSIQF_HKEY_MAX_INDEX + 1) * 4)
  76. #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  77. #define ICE_MAX_MTU (ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
  78. ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)
  79. #define ICE_UP_TABLE_TRANSLATE(val, i) \
  80. (((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  81. ICE_AQ_VSI_UP_TABLE_UP##i##_M)
  82. #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
  83. #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
  84. #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
  85. /* Macro for each VSI in a PF */
  86. #define ice_for_each_vsi(pf, i) \
  87. for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
  88. /* Macros for each tx/rx ring in a VSI */
  89. #define ice_for_each_txq(vsi, i) \
  90. for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
  91. #define ice_for_each_rxq(vsi, i) \
  92. for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
  93. /* Macros for each allocated tx/rx ring whether used or not in a VSI */
  94. #define ice_for_each_alloc_txq(vsi, i) \
  95. for ((i) = 0; (i) < (vsi)->alloc_txq; (i)++)
  96. #define ice_for_each_alloc_rxq(vsi, i) \
  97. for ((i) = 0; (i) < (vsi)->alloc_rxq; (i)++)
  98. struct ice_tc_info {
  99. u16 qoffset;
  100. u16 qcount;
  101. };
  102. struct ice_tc_cfg {
  103. u8 numtc; /* Total number of enabled TCs */
  104. u8 ena_tc; /* TX map */
  105. struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
  106. };
  107. struct ice_res_tracker {
  108. u16 num_entries;
  109. u16 search_hint;
  110. u16 list[1];
  111. };
  112. struct ice_sw {
  113. struct ice_pf *pf;
  114. u16 sw_id; /* switch ID for this switch */
  115. u16 bridge_mode; /* VEB/VEPA/Port Virtualizer */
  116. };
  117. enum ice_state {
  118. __ICE_DOWN,
  119. __ICE_NEEDS_RESTART,
  120. __ICE_PREPARED_FOR_RESET, /* set by driver when prepared */
  121. __ICE_RESET_OICR_RECV, /* set by driver after rcv reset OICR */
  122. __ICE_PFR_REQ, /* set by driver and peers */
  123. __ICE_CORER_REQ, /* set by driver and peers */
  124. __ICE_GLOBR_REQ, /* set by driver and peers */
  125. __ICE_CORER_RECV, /* set by OICR handler */
  126. __ICE_GLOBR_RECV, /* set by OICR handler */
  127. __ICE_EMPR_RECV, /* set by OICR handler */
  128. __ICE_SUSPENDED, /* set on module remove path */
  129. __ICE_RESET_FAILED, /* set by reset/rebuild */
  130. /* When checking for the PF to be in a nominal operating state, the
  131. * bits that are grouped at the beginning of the list need to be
  132. * checked. Bits occurring before __ICE_STATE_NOMINAL_CHECK_BITS will
  133. * be checked. If you need to add a bit into consideration for nominal
  134. * operating state, it must be added before
  135. * __ICE_STATE_NOMINAL_CHECK_BITS. Do not move this entry's position
  136. * without appropriate consideration.
  137. */
  138. __ICE_STATE_NOMINAL_CHECK_BITS,
  139. __ICE_ADMINQ_EVENT_PENDING,
  140. __ICE_MAILBOXQ_EVENT_PENDING,
  141. __ICE_MDD_EVENT_PENDING,
  142. __ICE_VFLR_EVENT_PENDING,
  143. __ICE_FLTR_OVERFLOW_PROMISC,
  144. __ICE_VF_DIS,
  145. __ICE_CFG_BUSY,
  146. __ICE_SERVICE_SCHED,
  147. __ICE_SERVICE_DIS,
  148. __ICE_STATE_NBITS /* must be last */
  149. };
  150. enum ice_vsi_flags {
  151. ICE_VSI_FLAG_UMAC_FLTR_CHANGED,
  152. ICE_VSI_FLAG_MMAC_FLTR_CHANGED,
  153. ICE_VSI_FLAG_VLAN_FLTR_CHANGED,
  154. ICE_VSI_FLAG_PROMISC_CHANGED,
  155. ICE_VSI_FLAG_NBITS /* must be last */
  156. };
  157. /* struct that defines a VSI, associated with a dev */
  158. struct ice_vsi {
  159. struct net_device *netdev;
  160. struct ice_sw *vsw; /* switch this VSI is on */
  161. struct ice_pf *back; /* back pointer to PF */
  162. struct ice_port_info *port_info; /* back pointer to port_info */
  163. struct ice_ring **rx_rings; /* rx ring array */
  164. struct ice_ring **tx_rings; /* tx ring array */
  165. struct ice_q_vector **q_vectors; /* q_vector array */
  166. irqreturn_t (*irq_handler)(int irq, void *data);
  167. u64 tx_linearize;
  168. DECLARE_BITMAP(state, __ICE_STATE_NBITS);
  169. DECLARE_BITMAP(flags, ICE_VSI_FLAG_NBITS);
  170. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  171. unsigned int current_netdev_flags;
  172. u32 tx_restart;
  173. u32 tx_busy;
  174. u32 rx_buf_failed;
  175. u32 rx_page_failed;
  176. int num_q_vectors;
  177. int sw_base_vector; /* Irq base for OS reserved vectors */
  178. int hw_base_vector; /* HW (absolute) index of a vector */
  179. enum ice_vsi_type type;
  180. u16 vsi_num; /* HW (absolute) index of this VSI */
  181. u16 idx; /* software index in pf->vsi[] */
  182. /* Interrupt thresholds */
  183. u16 work_lmt;
  184. s16 vf_id; /* VF ID for SR-IOV VSIs */
  185. /* RSS config */
  186. u16 rss_table_size; /* HW RSS table size */
  187. u16 rss_size; /* Allocated RSS queues */
  188. u8 *rss_hkey_user; /* User configured hash keys */
  189. u8 *rss_lut_user; /* User configured lookup table entries */
  190. u8 rss_lut_type; /* used to configure Get/Set RSS LUT AQ call */
  191. u16 max_frame;
  192. u16 rx_buf_len;
  193. struct ice_aqc_vsi_props info; /* VSI properties */
  194. /* VSI stats */
  195. struct rtnl_link_stats64 net_stats;
  196. struct ice_eth_stats eth_stats;
  197. struct ice_eth_stats eth_stats_prev;
  198. struct list_head tmp_sync_list; /* MAC filters to be synced */
  199. struct list_head tmp_unsync_list; /* MAC filters to be unsynced */
  200. u8 irqs_ready;
  201. u8 current_isup; /* Sync 'link up' logging */
  202. u8 stat_offsets_loaded;
  203. /* queue information */
  204. u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  205. u8 rx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  206. u16 txq_map[ICE_MAX_TXQS]; /* index in pf->avail_txqs */
  207. u16 rxq_map[ICE_MAX_RXQS]; /* index in pf->avail_rxqs */
  208. u16 alloc_txq; /* Allocated Tx queues */
  209. u16 num_txq; /* Used Tx queues */
  210. u16 alloc_rxq; /* Allocated Rx queues */
  211. u16 num_rxq; /* Used Rx queues */
  212. u16 num_desc;
  213. struct ice_tc_cfg tc_cfg;
  214. } ____cacheline_internodealigned_in_smp;
  215. /* struct that defines an interrupt vector */
  216. struct ice_q_vector {
  217. struct ice_vsi *vsi;
  218. cpumask_t affinity_mask;
  219. struct napi_struct napi;
  220. struct ice_ring_container rx;
  221. struct ice_ring_container tx;
  222. struct irq_affinity_notify affinity_notify;
  223. u16 v_idx; /* index in the vsi->q_vector array. */
  224. u8 num_ring_tx; /* total number of tx rings in vector */
  225. u8 num_ring_rx; /* total number of rx rings in vector */
  226. char name[ICE_INT_NAME_STR_LEN];
  227. /* in usecs, need to use ice_intrl_to_usecs_reg() before writing this
  228. * value to the device
  229. */
  230. u8 intrl;
  231. } ____cacheline_internodealigned_in_smp;
  232. enum ice_pf_flags {
  233. ICE_FLAG_MSIX_ENA,
  234. ICE_FLAG_FLTR_SYNC,
  235. ICE_FLAG_RSS_ENA,
  236. ICE_FLAG_SRIOV_ENA,
  237. ICE_FLAG_SRIOV_CAPABLE,
  238. ICE_PF_FLAGS_NBITS /* must be last */
  239. };
  240. struct ice_pf {
  241. struct pci_dev *pdev;
  242. /* OS reserved IRQ details */
  243. struct msix_entry *msix_entries;
  244. struct ice_res_tracker *sw_irq_tracker;
  245. /* HW reserved Interrupts for this PF */
  246. struct ice_res_tracker *hw_irq_tracker;
  247. struct ice_vsi **vsi; /* VSIs created by the driver */
  248. struct ice_sw *first_sw; /* first switch created by firmware */
  249. /* Virtchnl/SR-IOV config info */
  250. struct ice_vf *vf;
  251. int num_alloc_vfs; /* actual number of VFs allocated */
  252. u16 num_vfs_supported; /* num VFs supported for this PF */
  253. u16 num_vf_qps; /* num queue pairs per VF */
  254. u16 num_vf_msix; /* num vectors per VF */
  255. DECLARE_BITMAP(state, __ICE_STATE_NBITS);
  256. DECLARE_BITMAP(avail_txqs, ICE_MAX_TXQS);
  257. DECLARE_BITMAP(avail_rxqs, ICE_MAX_RXQS);
  258. DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
  259. unsigned long serv_tmr_period;
  260. unsigned long serv_tmr_prev;
  261. struct timer_list serv_tmr;
  262. struct work_struct serv_task;
  263. struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
  264. struct mutex sw_mutex; /* lock for protecting VSI alloc flow */
  265. u32 msg_enable;
  266. u32 hw_csum_rx_error;
  267. u32 sw_oicr_idx; /* Other interrupt cause SW vector index */
  268. u32 num_avail_sw_msix; /* remaining MSIX SW vectors left unclaimed */
  269. u32 hw_oicr_idx; /* Other interrupt cause vector HW index */
  270. u32 num_avail_hw_msix; /* remaining HW MSIX vectors left unclaimed */
  271. u32 num_lan_msix; /* Total MSIX vectors for base driver */
  272. u16 num_lan_tx; /* num lan tx queues setup */
  273. u16 num_lan_rx; /* num lan rx queues setup */
  274. u16 q_left_tx; /* remaining num tx queues left unclaimed */
  275. u16 q_left_rx; /* remaining num rx queues left unclaimed */
  276. u16 next_vsi; /* Next free slot in pf->vsi[] - 0-based! */
  277. u16 num_alloc_vsi;
  278. u16 corer_count; /* Core reset count */
  279. u16 globr_count; /* Global reset count */
  280. u16 empr_count; /* EMP reset count */
  281. u16 pfr_count; /* PF reset count */
  282. struct ice_hw_port_stats stats;
  283. struct ice_hw_port_stats stats_prev;
  284. struct ice_hw hw;
  285. u8 stat_prev_loaded; /* has previous stats been loaded */
  286. u32 tx_timeout_count;
  287. unsigned long tx_timeout_last_recovery;
  288. u32 tx_timeout_recovery_level;
  289. char int_name[ICE_INT_NAME_STR_LEN];
  290. };
  291. struct ice_netdev_priv {
  292. struct ice_vsi *vsi;
  293. };
  294. /**
  295. * ice_irq_dynamic_ena - Enable default interrupt generation settings
  296. * @hw: pointer to hw struct
  297. * @vsi: pointer to vsi struct, can be NULL
  298. * @q_vector: pointer to q_vector, can be NULL
  299. */
  300. static inline void ice_irq_dynamic_ena(struct ice_hw *hw, struct ice_vsi *vsi,
  301. struct ice_q_vector *q_vector)
  302. {
  303. u32 vector = (vsi && q_vector) ? vsi->hw_base_vector + q_vector->v_idx :
  304. ((struct ice_pf *)hw->back)->hw_oicr_idx;
  305. int itr = ICE_ITR_NONE;
  306. u32 val;
  307. /* clear the PBA here, as this function is meant to clean out all
  308. * previous interrupts and enable the interrupt
  309. */
  310. val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
  311. (itr << GLINT_DYN_CTL_ITR_INDX_S);
  312. if (vsi)
  313. if (test_bit(__ICE_DOWN, vsi->state))
  314. return;
  315. wr32(hw, GLINT_DYN_CTL(vector), val);
  316. }
  317. static inline void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
  318. {
  319. vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
  320. vsi->tc_cfg.numtc = 1;
  321. }
  322. void ice_set_ethtool_ops(struct net_device *netdev);
  323. int ice_up(struct ice_vsi *vsi);
  324. int ice_down(struct ice_vsi *vsi);
  325. int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  326. int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
  327. void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
  328. void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
  329. #endif /* _ICE_H_ */