ice.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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/firmware.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/compiler.h>
  12. #include <linux/etherdevice.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/cpumask.h>
  15. #include <linux/rtnetlink.h>
  16. #include <linux/if_vlan.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/pci.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/wait.h>
  21. #include <linux/aer.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/timer.h>
  25. #include <linux/delay.h>
  26. #include <linux/bitmap.h>
  27. #include <linux/log2.h>
  28. #include <linux/ip.h>
  29. #include <linux/sctp.h>
  30. #include <linux/ipv6.h>
  31. #include <linux/pkt_sched.h>
  32. #include <linux/if_bridge.h>
  33. #include <linux/ctype.h>
  34. #include <linux/bpf.h>
  35. #include <linux/btf.h>
  36. #include <linux/auxiliary_bus.h>
  37. #include <linux/avf/virtchnl.h>
  38. #include <linux/cpu_rmap.h>
  39. #include <linux/dim.h>
  40. #include <net/pkt_cls.h>
  41. #include <net/tc_act/tc_mirred.h>
  42. #include <net/tc_act/tc_gact.h>
  43. #include <net/ip.h>
  44. #include <net/devlink.h>
  45. #include <net/ipv6.h>
  46. #include <net/xdp_sock.h>
  47. #include <net/xdp_sock_drv.h>
  48. #include <net/geneve.h>
  49. #include <net/gre.h>
  50. #include <net/udp_tunnel.h>
  51. #include <net/vxlan.h>
  52. #include <net/gtp.h>
  53. #include <linux/ppp_defs.h>
  54. #include "ice_devids.h"
  55. #include "ice_type.h"
  56. #include "ice_txrx.h"
  57. #include "ice_dcb.h"
  58. #include "ice_switch.h"
  59. #include "ice_common.h"
  60. #include "ice_flow.h"
  61. #include "ice_sched.h"
  62. #include "ice_idc_int.h"
  63. #include "ice_sriov.h"
  64. #include "ice_vf_mbx.h"
  65. #include "ice_ptp.h"
  66. #include "ice_fdir.h"
  67. #include "ice_xsk.h"
  68. #include "ice_arfs.h"
  69. #include "ice_repr.h"
  70. #include "ice_eswitch.h"
  71. #include "ice_lag.h"
  72. #include "ice_vsi_vlan_ops.h"
  73. #include "ice_gnss.h"
  74. #define ICE_BAR0 0
  75. #define ICE_REQ_DESC_MULTIPLE 32
  76. #define ICE_MIN_NUM_DESC 64
  77. #define ICE_MAX_NUM_DESC 8160
  78. #define ICE_DFLT_MIN_RX_DESC 512
  79. #define ICE_DFLT_NUM_TX_DESC 256
  80. #define ICE_DFLT_NUM_RX_DESC 2048
  81. #define ICE_DFLT_TRAFFIC_CLASS BIT(0)
  82. #define ICE_INT_NAME_STR_LEN (IFNAMSIZ + 16)
  83. #define ICE_AQ_LEN 192
  84. #define ICE_MBXSQ_LEN 64
  85. #define ICE_SBQ_LEN 64
  86. #define ICE_MIN_LAN_TXRX_MSIX 1
  87. #define ICE_MIN_LAN_OICR_MSIX 1
  88. #define ICE_MIN_MSIX (ICE_MIN_LAN_TXRX_MSIX + ICE_MIN_LAN_OICR_MSIX)
  89. #define ICE_FDIR_MSIX 2
  90. #define ICE_RDMA_NUM_AEQ_MSIX 4
  91. #define ICE_MIN_RDMA_MSIX 2
  92. #define ICE_ESWITCH_MSIX 1
  93. #define ICE_NO_VSI 0xffff
  94. #define ICE_VSI_MAP_CONTIG 0
  95. #define ICE_VSI_MAP_SCATTER 1
  96. #define ICE_MAX_SCATTER_TXQS 16
  97. #define ICE_MAX_SCATTER_RXQS 16
  98. #define ICE_Q_WAIT_RETRY_LIMIT 10
  99. #define ICE_Q_WAIT_MAX_RETRY (5 * ICE_Q_WAIT_RETRY_LIMIT)
  100. #define ICE_MAX_LG_RSS_QS 256
  101. #define ICE_RES_VALID_BIT 0x8000
  102. #define ICE_RES_MISC_VEC_ID (ICE_RES_VALID_BIT - 1)
  103. #define ICE_RES_RDMA_VEC_ID (ICE_RES_MISC_VEC_ID - 1)
  104. /* All VF control VSIs share the same IRQ, so assign a unique ID for them */
  105. #define ICE_RES_VF_CTRL_VEC_ID (ICE_RES_RDMA_VEC_ID - 1)
  106. #define ICE_INVAL_Q_INDEX 0xffff
  107. #define ICE_MAX_RXQS_PER_TC 256 /* Used when setting VSI context per TC Rx queues */
  108. #define ICE_CHNL_START_TC 1
  109. #define ICE_MAX_RESET_WAIT 20
  110. #define ICE_VSIQF_HKEY_ARRAY_SIZE ((VSIQF_HKEY_MAX_INDEX + 1) * 4)
  111. #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  112. #define ICE_MAX_MTU (ICE_AQ_SET_MAC_FRAME_SIZE_MAX - ICE_ETH_PKT_HDR_PAD)
  113. #define ICE_UP_TABLE_TRANSLATE(val, i) \
  114. (((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  115. ICE_AQ_VSI_UP_TABLE_UP##i##_M)
  116. #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
  117. #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
  118. #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
  119. #define ICE_TX_FDIRDESC(R, i) (&(((struct ice_fltr_desc *)((R)->desc))[i]))
  120. /* Minimum BW limit is 500 Kbps for any scheduler node */
  121. #define ICE_MIN_BW_LIMIT 500
  122. /* User can specify BW in either Kbit/Mbit/Gbit and OS converts it in bytes.
  123. * use it to convert user specified BW limit into Kbps
  124. */
  125. #define ICE_BW_KBPS_DIVISOR 125
  126. /* Macro for each VSI in a PF */
  127. #define ice_for_each_vsi(pf, i) \
  128. for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
  129. /* Macros for each Tx/Xdp/Rx ring in a VSI */
  130. #define ice_for_each_txq(vsi, i) \
  131. for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
  132. #define ice_for_each_xdp_txq(vsi, i) \
  133. for ((i) = 0; (i) < (vsi)->num_xdp_txq; (i)++)
  134. #define ice_for_each_rxq(vsi, i) \
  135. for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
  136. /* Macros for each allocated Tx/Rx ring whether used or not in a VSI */
  137. #define ice_for_each_alloc_txq(vsi, i) \
  138. for ((i) = 0; (i) < (vsi)->alloc_txq; (i)++)
  139. #define ice_for_each_alloc_rxq(vsi, i) \
  140. for ((i) = 0; (i) < (vsi)->alloc_rxq; (i)++)
  141. #define ice_for_each_q_vector(vsi, i) \
  142. for ((i) = 0; (i) < (vsi)->num_q_vectors; (i)++)
  143. #define ice_for_each_chnl_tc(i) \
  144. for ((i) = ICE_CHNL_START_TC; (i) < ICE_CHNL_MAX_TC; (i)++)
  145. #define ICE_UCAST_PROMISC_BITS (ICE_PROMISC_UCAST_TX | ICE_PROMISC_UCAST_RX)
  146. #define ICE_UCAST_VLAN_PROMISC_BITS (ICE_PROMISC_UCAST_TX | \
  147. ICE_PROMISC_UCAST_RX | \
  148. ICE_PROMISC_VLAN_TX | \
  149. ICE_PROMISC_VLAN_RX)
  150. #define ICE_MCAST_PROMISC_BITS (ICE_PROMISC_MCAST_TX | ICE_PROMISC_MCAST_RX)
  151. #define ICE_MCAST_VLAN_PROMISC_BITS (ICE_PROMISC_MCAST_TX | \
  152. ICE_PROMISC_MCAST_RX | \
  153. ICE_PROMISC_VLAN_TX | \
  154. ICE_PROMISC_VLAN_RX)
  155. #define ice_pf_to_dev(pf) (&((pf)->pdev->dev))
  156. enum ice_feature {
  157. ICE_F_DSCP,
  158. ICE_F_PTP_EXTTS,
  159. ICE_F_SMA_CTRL,
  160. ICE_F_GNSS,
  161. ICE_F_MAX
  162. };
  163. DECLARE_STATIC_KEY_FALSE(ice_xdp_locking_key);
  164. struct ice_channel {
  165. struct list_head list;
  166. u8 type;
  167. u16 sw_id;
  168. u16 base_q;
  169. u16 num_rxq;
  170. u16 num_txq;
  171. u16 vsi_num;
  172. u8 ena_tc;
  173. struct ice_aqc_vsi_props info;
  174. u64 max_tx_rate;
  175. u64 min_tx_rate;
  176. atomic_t num_sb_fltr;
  177. struct ice_vsi *ch_vsi;
  178. };
  179. struct ice_txq_meta {
  180. u32 q_teid; /* Tx-scheduler element identifier */
  181. u16 q_id; /* Entry in VSI's txq_map bitmap */
  182. u16 q_handle; /* Relative index of Tx queue within TC */
  183. u16 vsi_idx; /* VSI index that Tx queue belongs to */
  184. u8 tc; /* TC number that Tx queue belongs to */
  185. };
  186. struct ice_tc_info {
  187. u16 qoffset;
  188. u16 qcount_tx;
  189. u16 qcount_rx;
  190. u8 netdev_tc;
  191. };
  192. struct ice_tc_cfg {
  193. u8 numtc; /* Total number of enabled TCs */
  194. u16 ena_tc; /* Tx map */
  195. struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
  196. };
  197. struct ice_res_tracker {
  198. u16 num_entries;
  199. u16 end;
  200. u16 list[];
  201. };
  202. struct ice_qs_cfg {
  203. struct mutex *qs_mutex; /* will be assigned to &pf->avail_q_mutex */
  204. unsigned long *pf_map;
  205. unsigned long pf_map_size;
  206. unsigned int q_count;
  207. unsigned int scatter_count;
  208. u16 *vsi_map;
  209. u16 vsi_map_offset;
  210. u8 mapping_mode;
  211. };
  212. struct ice_sw {
  213. struct ice_pf *pf;
  214. u16 sw_id; /* switch ID for this switch */
  215. u16 bridge_mode; /* VEB/VEPA/Port Virtualizer */
  216. };
  217. enum ice_pf_state {
  218. ICE_TESTING,
  219. ICE_DOWN,
  220. ICE_NEEDS_RESTART,
  221. ICE_PREPARED_FOR_RESET, /* set by driver when prepared */
  222. ICE_RESET_OICR_RECV, /* set by driver after rcv reset OICR */
  223. ICE_PFR_REQ, /* set by driver */
  224. ICE_CORER_REQ, /* set by driver */
  225. ICE_GLOBR_REQ, /* set by driver */
  226. ICE_CORER_RECV, /* set by OICR handler */
  227. ICE_GLOBR_RECV, /* set by OICR handler */
  228. ICE_EMPR_RECV, /* set by OICR handler */
  229. ICE_SUSPENDED, /* set on module remove path */
  230. ICE_RESET_FAILED, /* set by reset/rebuild */
  231. /* When checking for the PF to be in a nominal operating state, the
  232. * bits that are grouped at the beginning of the list need to be
  233. * checked. Bits occurring before ICE_STATE_NOMINAL_CHECK_BITS will
  234. * be checked. If you need to add a bit into consideration for nominal
  235. * operating state, it must be added before
  236. * ICE_STATE_NOMINAL_CHECK_BITS. Do not move this entry's position
  237. * without appropriate consideration.
  238. */
  239. ICE_STATE_NOMINAL_CHECK_BITS,
  240. ICE_ADMINQ_EVENT_PENDING,
  241. ICE_MAILBOXQ_EVENT_PENDING,
  242. ICE_SIDEBANDQ_EVENT_PENDING,
  243. ICE_MDD_EVENT_PENDING,
  244. ICE_VFLR_EVENT_PENDING,
  245. ICE_FLTR_OVERFLOW_PROMISC,
  246. ICE_VF_DIS,
  247. ICE_CFG_BUSY,
  248. ICE_SERVICE_SCHED,
  249. ICE_SERVICE_DIS,
  250. ICE_FD_FLUSH_REQ,
  251. ICE_OICR_INTR_DIS, /* Global OICR interrupt disabled */
  252. ICE_MDD_VF_PRINT_PENDING, /* set when MDD event handle */
  253. ICE_VF_RESETS_DISABLED, /* disable resets during ice_remove */
  254. ICE_LINK_DEFAULT_OVERRIDE_PENDING,
  255. ICE_PHY_INIT_COMPLETE,
  256. ICE_FD_VF_FLUSH_CTX, /* set at FD Rx IRQ or timeout */
  257. ICE_AUX_ERR_PENDING,
  258. ICE_STATE_NBITS /* must be last */
  259. };
  260. enum ice_vsi_state {
  261. ICE_VSI_DOWN,
  262. ICE_VSI_NEEDS_RESTART,
  263. ICE_VSI_NETDEV_ALLOCD,
  264. ICE_VSI_NETDEV_REGISTERED,
  265. ICE_VSI_UMAC_FLTR_CHANGED,
  266. ICE_VSI_MMAC_FLTR_CHANGED,
  267. ICE_VSI_PROMISC_CHANGED,
  268. ICE_VSI_STATE_NBITS /* must be last */
  269. };
  270. /* struct that defines a VSI, associated with a dev */
  271. struct ice_vsi {
  272. struct net_device *netdev;
  273. struct ice_sw *vsw; /* switch this VSI is on */
  274. struct ice_pf *back; /* back pointer to PF */
  275. struct ice_port_info *port_info; /* back pointer to port_info */
  276. struct ice_rx_ring **rx_rings; /* Rx ring array */
  277. struct ice_tx_ring **tx_rings; /* Tx ring array */
  278. struct ice_q_vector **q_vectors; /* q_vector array */
  279. irqreturn_t (*irq_handler)(int irq, void *data);
  280. u64 tx_linearize;
  281. DECLARE_BITMAP(state, ICE_VSI_STATE_NBITS);
  282. unsigned int current_netdev_flags;
  283. u32 tx_restart;
  284. u32 tx_busy;
  285. u32 rx_buf_failed;
  286. u32 rx_page_failed;
  287. u16 num_q_vectors;
  288. u16 base_vector; /* IRQ base for OS reserved vectors */
  289. enum ice_vsi_type type;
  290. u16 vsi_num; /* HW (absolute) index of this VSI */
  291. u16 idx; /* software index in pf->vsi[] */
  292. struct ice_vf *vf; /* VF associated with this VSI */
  293. u16 ethtype; /* Ethernet protocol for pause frame */
  294. u16 num_gfltr;
  295. u16 num_bfltr;
  296. /* RSS config */
  297. u16 rss_table_size; /* HW RSS table size */
  298. u16 rss_size; /* Allocated RSS queues */
  299. u8 *rss_hkey_user; /* User configured hash keys */
  300. u8 *rss_lut_user; /* User configured lookup table entries */
  301. u8 rss_lut_type; /* used to configure Get/Set RSS LUT AQ call */
  302. /* aRFS members only allocated for the PF VSI */
  303. #define ICE_MAX_ARFS_LIST 1024
  304. #define ICE_ARFS_LST_MASK (ICE_MAX_ARFS_LIST - 1)
  305. struct hlist_head *arfs_fltr_list;
  306. struct ice_arfs_active_fltr_cntrs *arfs_fltr_cntrs;
  307. spinlock_t arfs_lock; /* protects aRFS hash table and filter state */
  308. atomic_t *arfs_last_fltr_id;
  309. u16 max_frame;
  310. u16 rx_buf_len;
  311. struct ice_aqc_vsi_props info; /* VSI properties */
  312. /* VSI stats */
  313. struct rtnl_link_stats64 net_stats;
  314. struct ice_eth_stats eth_stats;
  315. struct ice_eth_stats eth_stats_prev;
  316. struct list_head tmp_sync_list; /* MAC filters to be synced */
  317. struct list_head tmp_unsync_list; /* MAC filters to be unsynced */
  318. u8 irqs_ready:1;
  319. u8 current_isup:1; /* Sync 'link up' logging */
  320. u8 stat_offsets_loaded:1;
  321. struct ice_vsi_vlan_ops inner_vlan_ops;
  322. struct ice_vsi_vlan_ops outer_vlan_ops;
  323. u16 num_vlan;
  324. /* queue information */
  325. u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  326. u8 rx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  327. u16 *txq_map; /* index in pf->avail_txqs */
  328. u16 *rxq_map; /* index in pf->avail_rxqs */
  329. u16 alloc_txq; /* Allocated Tx queues */
  330. u16 num_txq; /* Used Tx queues */
  331. u16 alloc_rxq; /* Allocated Rx queues */
  332. u16 num_rxq; /* Used Rx queues */
  333. u16 req_txq; /* User requested Tx queues */
  334. u16 req_rxq; /* User requested Rx queues */
  335. u16 num_rx_desc;
  336. u16 num_tx_desc;
  337. u16 qset_handle[ICE_MAX_TRAFFIC_CLASS];
  338. struct ice_tc_cfg tc_cfg;
  339. struct bpf_prog *xdp_prog;
  340. struct ice_tx_ring **xdp_rings; /* XDP ring array */
  341. unsigned long *af_xdp_zc_qps; /* tracks AF_XDP ZC enabled qps */
  342. u16 num_xdp_txq; /* Used XDP queues */
  343. u8 xdp_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
  344. struct net_device **target_netdevs;
  345. struct tc_mqprio_qopt_offload mqprio_qopt; /* queue parameters */
  346. /* Channel Specific Fields */
  347. struct ice_vsi *tc_map_vsi[ICE_CHNL_MAX_TC];
  348. u16 cnt_q_avail;
  349. u16 next_base_q; /* next queue to be used for channel setup */
  350. struct list_head ch_list;
  351. u16 num_chnl_rxq;
  352. u16 num_chnl_txq;
  353. u16 ch_rss_size;
  354. u16 num_chnl_fltr;
  355. /* store away rss size info before configuring ADQ channels so that,
  356. * it can be used after tc-qdisc delete, to get back RSS setting as
  357. * they were before
  358. */
  359. u16 orig_rss_size;
  360. /* this keeps tracks of all enabled TC with and without DCB
  361. * and inclusive of ADQ, vsi->mqprio_opt keeps track of queue
  362. * information
  363. */
  364. u8 all_numtc;
  365. u16 all_enatc;
  366. /* store away TC info, to be used for rebuild logic */
  367. u8 old_numtc;
  368. u16 old_ena_tc;
  369. struct ice_channel *ch;
  370. /* setup back reference, to which aggregator node this VSI
  371. * corresponds to
  372. */
  373. struct ice_agg_node *agg_node;
  374. } ____cacheline_internodealigned_in_smp;
  375. /* struct that defines an interrupt vector */
  376. struct ice_q_vector {
  377. struct ice_vsi *vsi;
  378. u16 v_idx; /* index in the vsi->q_vector array. */
  379. u16 reg_idx;
  380. u8 num_ring_rx; /* total number of Rx rings in vector */
  381. u8 num_ring_tx; /* total number of Tx rings in vector */
  382. u8 wb_on_itr:1; /* if true, WB on ITR is enabled */
  383. /* in usecs, need to use ice_intrl_to_usecs_reg() before writing this
  384. * value to the device
  385. */
  386. u8 intrl;
  387. struct napi_struct napi;
  388. struct ice_ring_container rx;
  389. struct ice_ring_container tx;
  390. cpumask_t affinity_mask;
  391. struct irq_affinity_notify affinity_notify;
  392. struct ice_channel *ch;
  393. char name[ICE_INT_NAME_STR_LEN];
  394. u16 total_events; /* net_dim(): number of interrupts processed */
  395. } ____cacheline_internodealigned_in_smp;
  396. enum ice_pf_flags {
  397. ICE_FLAG_FLTR_SYNC,
  398. ICE_FLAG_RDMA_ENA,
  399. ICE_FLAG_RSS_ENA,
  400. ICE_FLAG_SRIOV_ENA,
  401. ICE_FLAG_SRIOV_CAPABLE,
  402. ICE_FLAG_DCB_CAPABLE,
  403. ICE_FLAG_DCB_ENA,
  404. ICE_FLAG_FD_ENA,
  405. ICE_FLAG_PTP_SUPPORTED, /* PTP is supported by NVM */
  406. ICE_FLAG_PTP, /* PTP is enabled by software */
  407. ICE_FLAG_ADV_FEATURES,
  408. ICE_FLAG_TC_MQPRIO, /* support for Multi queue TC */
  409. ICE_FLAG_CLS_FLOWER,
  410. ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA,
  411. ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA,
  412. ICE_FLAG_NO_MEDIA,
  413. ICE_FLAG_FW_LLDP_AGENT,
  414. ICE_FLAG_MOD_POWER_UNSUPPORTED,
  415. ICE_FLAG_PHY_FW_LOAD_FAILED,
  416. ICE_FLAG_ETHTOOL_CTXT, /* set when ethtool holds RTNL lock */
  417. ICE_FLAG_LEGACY_RX,
  418. ICE_FLAG_VF_TRUE_PROMISC_ENA,
  419. ICE_FLAG_MDD_AUTO_RESET_VF,
  420. ICE_FLAG_VF_VLAN_PRUNING,
  421. ICE_FLAG_LINK_LENIENT_MODE_ENA,
  422. ICE_FLAG_PLUG_AUX_DEV,
  423. ICE_FLAG_UNPLUG_AUX_DEV,
  424. ICE_FLAG_MTU_CHANGED,
  425. ICE_FLAG_GNSS, /* GNSS successfully initialized */
  426. ICE_PF_FLAGS_NBITS /* must be last */
  427. };
  428. enum ice_misc_thread_tasks {
  429. ICE_MISC_THREAD_EXTTS_EVENT,
  430. ICE_MISC_THREAD_TX_TSTAMP,
  431. ICE_MISC_THREAD_NBITS /* must be last */
  432. };
  433. struct ice_switchdev_info {
  434. struct ice_vsi *control_vsi;
  435. struct ice_vsi *uplink_vsi;
  436. bool is_running;
  437. };
  438. struct ice_agg_node {
  439. u32 agg_id;
  440. #define ICE_MAX_VSIS_IN_AGG_NODE 64
  441. u32 num_vsis;
  442. u8 valid;
  443. };
  444. struct ice_pf {
  445. struct pci_dev *pdev;
  446. struct devlink_region *nvm_region;
  447. struct devlink_region *sram_region;
  448. struct devlink_region *devcaps_region;
  449. /* devlink port data */
  450. struct devlink_port devlink_port;
  451. /* OS reserved IRQ details */
  452. struct msix_entry *msix_entries;
  453. struct ice_res_tracker *irq_tracker;
  454. /* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
  455. * number of MSIX vectors needed for all SR-IOV VFs from the number of
  456. * MSIX vectors allowed on this PF.
  457. */
  458. u16 sriov_base_vector;
  459. u16 ctrl_vsi_idx; /* control VSI index in pf->vsi array */
  460. struct ice_vsi **vsi; /* VSIs created by the driver */
  461. struct ice_sw *first_sw; /* first switch created by firmware */
  462. u16 eswitch_mode; /* current mode of eswitch */
  463. struct ice_vfs vfs;
  464. DECLARE_BITMAP(features, ICE_F_MAX);
  465. DECLARE_BITMAP(state, ICE_STATE_NBITS);
  466. DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
  467. DECLARE_BITMAP(misc_thread, ICE_MISC_THREAD_NBITS);
  468. unsigned long *avail_txqs; /* bitmap to track PF Tx queue usage */
  469. unsigned long *avail_rxqs; /* bitmap to track PF Rx queue usage */
  470. unsigned long serv_tmr_period;
  471. unsigned long serv_tmr_prev;
  472. struct timer_list serv_tmr;
  473. struct work_struct serv_task;
  474. struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
  475. struct mutex sw_mutex; /* lock for protecting VSI alloc flow */
  476. struct mutex tc_mutex; /* lock to protect TC changes */
  477. struct mutex adev_mutex; /* lock to protect aux device access */
  478. u32 msg_enable;
  479. struct ice_ptp ptp;
  480. struct tty_driver *ice_gnss_tty_driver;
  481. struct tty_port *gnss_tty_port[ICE_GNSS_TTY_MINOR_DEVICES];
  482. struct gnss_serial *gnss_serial[ICE_GNSS_TTY_MINOR_DEVICES];
  483. u16 num_rdma_msix; /* Total MSIX vectors for RDMA driver */
  484. u16 rdma_base_vector;
  485. /* spinlock to protect the AdminQ wait list */
  486. spinlock_t aq_wait_lock;
  487. struct hlist_head aq_wait_list;
  488. wait_queue_head_t aq_wait_queue;
  489. bool fw_emp_reset_disabled;
  490. wait_queue_head_t reset_wait_queue;
  491. u32 hw_csum_rx_error;
  492. u32 oicr_err_reg;
  493. u16 oicr_idx; /* Other interrupt cause MSIX vector index */
  494. u16 num_avail_sw_msix; /* remaining MSIX SW vectors left unclaimed */
  495. u16 max_pf_txqs; /* Total Tx queues PF wide */
  496. u16 max_pf_rxqs; /* Total Rx queues PF wide */
  497. u16 num_lan_msix; /* Total MSIX vectors for base driver */
  498. u16 num_lan_tx; /* num LAN Tx queues setup */
  499. u16 num_lan_rx; /* num LAN Rx queues setup */
  500. u16 next_vsi; /* Next free slot in pf->vsi[] - 0-based! */
  501. u16 num_alloc_vsi;
  502. u16 corer_count; /* Core reset count */
  503. u16 globr_count; /* Global reset count */
  504. u16 empr_count; /* EMP reset count */
  505. u16 pfr_count; /* PF reset count */
  506. u8 wol_ena : 1; /* software state of WoL */
  507. u32 wakeup_reason; /* last wakeup reason */
  508. struct ice_hw_port_stats stats;
  509. struct ice_hw_port_stats stats_prev;
  510. struct ice_hw hw;
  511. u8 stat_prev_loaded:1; /* has previous stats been loaded */
  512. u8 rdma_mode;
  513. u16 dcbx_cap;
  514. u32 tx_timeout_count;
  515. unsigned long tx_timeout_last_recovery;
  516. u32 tx_timeout_recovery_level;
  517. char int_name[ICE_INT_NAME_STR_LEN];
  518. struct auxiliary_device *adev;
  519. int aux_idx;
  520. u32 sw_int_count;
  521. /* count of tc_flower filters specific to channel (aka where filter
  522. * action is "hw_tc <tc_num>")
  523. */
  524. u16 num_dmac_chnl_fltrs;
  525. struct hlist_head tc_flower_fltr_list;
  526. __le64 nvm_phy_type_lo; /* NVM PHY type low */
  527. __le64 nvm_phy_type_hi; /* NVM PHY type high */
  528. struct ice_link_default_override_tlv link_dflt_override;
  529. struct ice_lag *lag; /* Link Aggregation information */
  530. struct ice_switchdev_info switchdev;
  531. #define ICE_INVALID_AGG_NODE_ID 0
  532. #define ICE_PF_AGG_NODE_ID_START 1
  533. #define ICE_MAX_PF_AGG_NODES 32
  534. struct ice_agg_node pf_agg_node[ICE_MAX_PF_AGG_NODES];
  535. #define ICE_VF_AGG_NODE_ID_START 65
  536. #define ICE_MAX_VF_AGG_NODES 32
  537. struct ice_agg_node vf_agg_node[ICE_MAX_VF_AGG_NODES];
  538. };
  539. struct ice_netdev_priv {
  540. struct ice_vsi *vsi;
  541. struct ice_repr *repr;
  542. /* indirect block callbacks on registered higher level devices
  543. * (e.g. tunnel devices)
  544. *
  545. * tc_indr_block_cb_priv_list is used to look up indirect callback
  546. * private data
  547. */
  548. struct list_head tc_indr_block_priv_list;
  549. };
  550. /**
  551. * ice_vector_ch_enabled
  552. * @qv: pointer to q_vector, can be NULL
  553. *
  554. * This function returns true if vector is channel enabled otherwise false
  555. */
  556. static inline bool ice_vector_ch_enabled(struct ice_q_vector *qv)
  557. {
  558. return !!qv->ch; /* Enable it to run with TC */
  559. }
  560. /**
  561. * ice_irq_dynamic_ena - Enable default interrupt generation settings
  562. * @hw: pointer to HW struct
  563. * @vsi: pointer to VSI struct, can be NULL
  564. * @q_vector: pointer to q_vector, can be NULL
  565. */
  566. static inline void
  567. ice_irq_dynamic_ena(struct ice_hw *hw, struct ice_vsi *vsi,
  568. struct ice_q_vector *q_vector)
  569. {
  570. u32 vector = (vsi && q_vector) ? q_vector->reg_idx :
  571. ((struct ice_pf *)hw->back)->oicr_idx;
  572. int itr = ICE_ITR_NONE;
  573. u32 val;
  574. /* clear the PBA here, as this function is meant to clean out all
  575. * previous interrupts and enable the interrupt
  576. */
  577. val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
  578. (itr << GLINT_DYN_CTL_ITR_INDX_S);
  579. if (vsi)
  580. if (test_bit(ICE_VSI_DOWN, vsi->state))
  581. return;
  582. wr32(hw, GLINT_DYN_CTL(vector), val);
  583. }
  584. /**
  585. * ice_netdev_to_pf - Retrieve the PF struct associated with a netdev
  586. * @netdev: pointer to the netdev struct
  587. */
  588. static inline struct ice_pf *ice_netdev_to_pf(struct net_device *netdev)
  589. {
  590. struct ice_netdev_priv *np = netdev_priv(netdev);
  591. return np->vsi->back;
  592. }
  593. static inline bool ice_is_xdp_ena_vsi(struct ice_vsi *vsi)
  594. {
  595. return !!READ_ONCE(vsi->xdp_prog);
  596. }
  597. static inline void ice_set_ring_xdp(struct ice_tx_ring *ring)
  598. {
  599. ring->flags |= ICE_TX_FLAGS_RING_XDP;
  600. }
  601. /**
  602. * ice_xsk_pool - get XSK buffer pool bound to a ring
  603. * @ring: Rx ring to use
  604. *
  605. * Returns a pointer to xsk_buff_pool structure if there is a buffer pool
  606. * present, NULL otherwise.
  607. */
  608. static inline struct xsk_buff_pool *ice_xsk_pool(struct ice_rx_ring *ring)
  609. {
  610. struct ice_vsi *vsi = ring->vsi;
  611. u16 qid = ring->q_index;
  612. if (!ice_is_xdp_ena_vsi(vsi) || !test_bit(qid, vsi->af_xdp_zc_qps))
  613. return NULL;
  614. return xsk_get_pool_from_qid(vsi->netdev, qid);
  615. }
  616. /**
  617. * ice_tx_xsk_pool - assign XSK buff pool to XDP ring
  618. * @vsi: pointer to VSI
  619. * @qid: index of a queue to look at XSK buff pool presence
  620. *
  621. * Sets XSK buff pool pointer on XDP ring.
  622. *
  623. * XDP ring is picked from Rx ring, whereas Rx ring is picked based on provided
  624. * queue id. Reason for doing so is that queue vectors might have assigned more
  625. * than one XDP ring, e.g. when user reduced the queue count on netdev; Rx ring
  626. * carries a pointer to one of these XDP rings for its own purposes, such as
  627. * handling XDP_TX action, therefore we can piggyback here on the
  628. * rx_ring->xdp_ring assignment that was done during XDP rings initialization.
  629. */
  630. static inline void ice_tx_xsk_pool(struct ice_vsi *vsi, u16 qid)
  631. {
  632. struct ice_tx_ring *ring;
  633. ring = vsi->rx_rings[qid]->xdp_ring;
  634. if (!ring)
  635. return;
  636. if (!ice_is_xdp_ena_vsi(vsi) || !test_bit(qid, vsi->af_xdp_zc_qps)) {
  637. ring->xsk_pool = NULL;
  638. return;
  639. }
  640. ring->xsk_pool = xsk_get_pool_from_qid(vsi->netdev, qid);
  641. }
  642. /**
  643. * ice_get_main_vsi - Get the PF VSI
  644. * @pf: PF instance
  645. *
  646. * returns pf->vsi[0], which by definition is the PF VSI
  647. */
  648. static inline struct ice_vsi *ice_get_main_vsi(struct ice_pf *pf)
  649. {
  650. if (pf->vsi)
  651. return pf->vsi[0];
  652. return NULL;
  653. }
  654. /**
  655. * ice_get_netdev_priv_vsi - return VSI associated with netdev priv.
  656. * @np: private netdev structure
  657. */
  658. static inline struct ice_vsi *ice_get_netdev_priv_vsi(struct ice_netdev_priv *np)
  659. {
  660. /* In case of port representor return source port VSI. */
  661. if (np->repr)
  662. return np->repr->src_vsi;
  663. else
  664. return np->vsi;
  665. }
  666. /**
  667. * ice_get_ctrl_vsi - Get the control VSI
  668. * @pf: PF instance
  669. */
  670. static inline struct ice_vsi *ice_get_ctrl_vsi(struct ice_pf *pf)
  671. {
  672. /* if pf->ctrl_vsi_idx is ICE_NO_VSI, control VSI was not set up */
  673. if (!pf->vsi || pf->ctrl_vsi_idx == ICE_NO_VSI)
  674. return NULL;
  675. return pf->vsi[pf->ctrl_vsi_idx];
  676. }
  677. /**
  678. * ice_find_vsi - Find the VSI from VSI ID
  679. * @pf: The PF pointer to search in
  680. * @vsi_num: The VSI ID to search for
  681. */
  682. static inline struct ice_vsi *ice_find_vsi(struct ice_pf *pf, u16 vsi_num)
  683. {
  684. int i;
  685. ice_for_each_vsi(pf, i)
  686. if (pf->vsi[i] && pf->vsi[i]->vsi_num == vsi_num)
  687. return pf->vsi[i];
  688. return NULL;
  689. }
  690. /**
  691. * ice_is_switchdev_running - check if switchdev is configured
  692. * @pf: pointer to PF structure
  693. *
  694. * Returns true if eswitch mode is set to DEVLINK_ESWITCH_MODE_SWITCHDEV
  695. * and switchdev is configured, false otherwise.
  696. */
  697. static inline bool ice_is_switchdev_running(struct ice_pf *pf)
  698. {
  699. return pf->switchdev.is_running;
  700. }
  701. /**
  702. * ice_set_sriov_cap - enable SRIOV in PF flags
  703. * @pf: PF struct
  704. */
  705. static inline void ice_set_sriov_cap(struct ice_pf *pf)
  706. {
  707. if (pf->hw.func_caps.common_cap.sr_iov_1_1)
  708. set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
  709. }
  710. /**
  711. * ice_clear_sriov_cap - disable SRIOV in PF flags
  712. * @pf: PF struct
  713. */
  714. static inline void ice_clear_sriov_cap(struct ice_pf *pf)
  715. {
  716. clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
  717. }
  718. #define ICE_FD_STAT_CTR_BLOCK_COUNT 256
  719. #define ICE_FD_STAT_PF_IDX(base_idx) \
  720. ((base_idx) * ICE_FD_STAT_CTR_BLOCK_COUNT)
  721. #define ICE_FD_SB_STAT_IDX(base_idx) ICE_FD_STAT_PF_IDX(base_idx)
  722. #define ICE_FD_STAT_CH 1
  723. #define ICE_FD_CH_STAT_IDX(base_idx) \
  724. (ICE_FD_STAT_PF_IDX(base_idx) + ICE_FD_STAT_CH)
  725. /**
  726. * ice_is_adq_active - any active ADQs
  727. * @pf: pointer to PF
  728. *
  729. * This function returns true if there are any ADQs configured (which is
  730. * determined by looking at VSI type (which should be VSI_PF), numtc, and
  731. * TC_MQPRIO flag) otherwise return false
  732. */
  733. static inline bool ice_is_adq_active(struct ice_pf *pf)
  734. {
  735. struct ice_vsi *vsi;
  736. vsi = ice_get_main_vsi(pf);
  737. if (!vsi)
  738. return false;
  739. /* is ADQ configured */
  740. if (vsi->tc_cfg.numtc > ICE_CHNL_START_TC &&
  741. test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
  742. return true;
  743. return false;
  744. }
  745. bool netif_is_ice(struct net_device *dev);
  746. int ice_vsi_setup_tx_rings(struct ice_vsi *vsi);
  747. int ice_vsi_setup_rx_rings(struct ice_vsi *vsi);
  748. int ice_vsi_open_ctrl(struct ice_vsi *vsi);
  749. int ice_vsi_open(struct ice_vsi *vsi);
  750. void ice_set_ethtool_ops(struct net_device *netdev);
  751. void ice_set_ethtool_repr_ops(struct net_device *netdev);
  752. void ice_set_ethtool_safe_mode_ops(struct net_device *netdev);
  753. u16 ice_get_avail_txq_count(struct ice_pf *pf);
  754. u16 ice_get_avail_rxq_count(struct ice_pf *pf);
  755. int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx, bool locked);
  756. void ice_update_vsi_stats(struct ice_vsi *vsi);
  757. void ice_update_pf_stats(struct ice_pf *pf);
  758. void
  759. ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp,
  760. struct ice_q_stats stats, u64 *pkts, u64 *bytes);
  761. int ice_up(struct ice_vsi *vsi);
  762. int ice_down(struct ice_vsi *vsi);
  763. int ice_down_up(struct ice_vsi *vsi);
  764. int ice_vsi_cfg(struct ice_vsi *vsi);
  765. struct ice_vsi *ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi);
  766. int ice_vsi_determine_xdp_res(struct ice_vsi *vsi);
  767. int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog);
  768. int ice_destroy_xdp_rings(struct ice_vsi *vsi);
  769. int
  770. ice_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
  771. u32 flags);
  772. int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size);
  773. int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size);
  774. int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed);
  775. int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed);
  776. void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
  777. int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset);
  778. void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
  779. int ice_plug_aux_dev(struct ice_pf *pf);
  780. void ice_unplug_aux_dev(struct ice_pf *pf);
  781. int ice_init_rdma(struct ice_pf *pf);
  782. const char *ice_aq_str(enum ice_aq_err aq_err);
  783. bool ice_is_wol_supported(struct ice_hw *hw);
  784. void ice_fdir_del_all_fltrs(struct ice_vsi *vsi);
  785. int
  786. ice_fdir_write_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, bool add,
  787. bool is_tun);
  788. void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena);
  789. int ice_add_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd);
  790. int ice_del_fdir_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd);
  791. int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd);
  792. int
  793. ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd,
  794. u32 *rule_locs);
  795. void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx);
  796. void ice_fdir_release_flows(struct ice_hw *hw);
  797. void ice_fdir_replay_flows(struct ice_hw *hw);
  798. void ice_fdir_replay_fltrs(struct ice_pf *pf);
  799. int ice_fdir_create_dflt_rules(struct ice_pf *pf);
  800. int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout,
  801. struct ice_rq_event_info *event);
  802. int ice_open(struct net_device *netdev);
  803. int ice_open_internal(struct net_device *netdev);
  804. int ice_stop(struct net_device *netdev);
  805. void ice_service_task_schedule(struct ice_pf *pf);
  806. /**
  807. * ice_set_rdma_cap - enable RDMA support
  808. * @pf: PF struct
  809. */
  810. static inline void ice_set_rdma_cap(struct ice_pf *pf)
  811. {
  812. if (pf->hw.func_caps.common_cap.rdma && pf->num_rdma_msix) {
  813. set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
  814. set_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags);
  815. }
  816. }
  817. /**
  818. * ice_clear_rdma_cap - disable RDMA support
  819. * @pf: PF struct
  820. */
  821. static inline void ice_clear_rdma_cap(struct ice_pf *pf)
  822. {
  823. /* defer unplug to service task to avoid RTNL lock and
  824. * clear PLUG bit so that pending plugs don't interfere
  825. */
  826. clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags);
  827. set_bit(ICE_FLAG_UNPLUG_AUX_DEV, pf->flags);
  828. clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
  829. }
  830. #endif /* _ICE_H_ */