500b88461fac6b45c063c44ba6e4f58423a50352
[dpdk.git] / drivers / net / ice / base / ice_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2019
3  */
4
5 #ifndef _ICE_TYPE_H_
6 #define _ICE_TYPE_H_
7
8 #define ETH_ALEN        6
9
10 #define ETH_HEADER_LEN  14
11
12 #define BIT(a) (1UL << (a))
13 #define BIT_ULL(a) (1ULL << (a))
14
15 #define BITS_PER_BYTE   8
16
17 #ifndef _FORCE_
18 #define _FORCE_
19 #endif
20
21 #define ICE_BYTES_PER_WORD      2
22 #define ICE_BYTES_PER_DWORD     4
23 #define ICE_MAX_TRAFFIC_CLASS   8
24
25 /**
26  * ROUND_UP - round up to next arbitrary multiple (not a power of 2)
27  * @a: value to round up
28  * @b: arbitrary multiple
29  *
30  * Round up to the next multiple of the arbitrary b.
31  * Note, when b is a power of 2 use ICE_ALIGN() instead.
32  */
33 #define ROUND_UP(a, b)  ((b) * DIVIDE_AND_ROUND_UP((a), (b)))
34
35 #define MIN_T(_t, _a, _b)       min((_t)(_a), (_t)(_b))
36
37 #define IS_ASCII(_ch)   ((_ch) < 0x80)
38
39 #include "ice_status.h"
40 #include "ice_hw_autogen.h"
41 #include "ice_devids.h"
42 #include "ice_osdep.h"
43 #include "ice_bitops.h" /* Must come before ice_controlq.h */
44 #include "ice_controlq.h"
45 #include "ice_lan_tx_rx.h"
46 #include "ice_flex_type.h"
47 #include "ice_protocol_type.h"
48
49 /**
50  * ice_is_pow2 - check if integer value is a power of 2
51  * @val: unsigned integer to be validated
52  */
53 static inline bool ice_is_pow2(u64 val)
54 {
55         return (val && !(val & (val - 1)));
56 }
57
58 /**
59  * ice_ilog2 - Calculates integer log base 2 of a number
60  * @n: number on which to perform operation
61  */
62 static inline int ice_ilog2(u64 n)
63 {
64         int i;
65
66         for (i = 63; i >= 0; i--)
67                 if (((u64)1 << i) & n)
68                         return i;
69
70         return -1;
71 }
72
73 static inline bool ice_is_tc_ena(ice_bitmap_t bitmap, u8 tc)
74 {
75         return ice_is_bit_set(&bitmap, tc);
76 }
77
78 #define DIV_64BIT(n, d) ((n) / (d))
79
80 static inline u64 round_up_64bit(u64 a, u32 b)
81 {
82         return DIV_64BIT(((a) + (b) / 2), (b));
83 }
84
85 static inline u32 ice_round_to_num(u32 N, u32 R)
86 {
87         return ((((N) % (R)) < ((R) / 2)) ? (((N) / (R)) * (R)) :
88                 ((((N) + (R) - 1) / (R)) * (R)));
89 }
90
91 /* Driver always calls main vsi_handle first */
92 #define ICE_MAIN_VSI_HANDLE             0
93
94 /* Switch from ms to the 1usec global time (this is the GTIME resolution) */
95 #define ICE_MS_TO_GTIME(time)           ((time) * 1000)
96
97 /* Data type manipulation macros. */
98 #define ICE_HI_DWORD(x)         ((u32)((((x) >> 16) >> 16) & 0xFFFFFFFF))
99 #define ICE_LO_DWORD(x)         ((u32)((x) & 0xFFFFFFFF))
100 #define ICE_HI_WORD(x)          ((u16)(((x) >> 16) & 0xFFFF))
101
102 /* debug masks - set these bits in hw->debug_mask to control output */
103 #define ICE_DBG_TRACE           BIT_ULL(0) /* for function-trace only */
104 #define ICE_DBG_INIT            BIT_ULL(1)
105 #define ICE_DBG_RELEASE         BIT_ULL(2)
106 #define ICE_DBG_FW_LOG          BIT_ULL(3)
107 #define ICE_DBG_LINK            BIT_ULL(4)
108 #define ICE_DBG_PHY             BIT_ULL(5)
109 #define ICE_DBG_QCTX            BIT_ULL(6)
110 #define ICE_DBG_NVM             BIT_ULL(7)
111 #define ICE_DBG_LAN             BIT_ULL(8)
112 #define ICE_DBG_FLOW            BIT_ULL(9)
113 #define ICE_DBG_DCB             BIT_ULL(10)
114 #define ICE_DBG_DIAG            BIT_ULL(11)
115 #define ICE_DBG_FD              BIT_ULL(12)
116 #define ICE_DBG_SW              BIT_ULL(13)
117 #define ICE_DBG_SCHED           BIT_ULL(14)
118
119 #define ICE_DBG_PKG             BIT_ULL(16)
120 #define ICE_DBG_RES             BIT_ULL(17)
121 #define ICE_DBG_AQ_MSG          BIT_ULL(24)
122 #define ICE_DBG_AQ_DESC         BIT_ULL(25)
123 #define ICE_DBG_AQ_DESC_BUF     BIT_ULL(26)
124 #define ICE_DBG_AQ_CMD          BIT_ULL(27)
125 #define ICE_DBG_AQ              (ICE_DBG_AQ_MSG         | \
126                                  ICE_DBG_AQ_DESC        | \
127                                  ICE_DBG_AQ_DESC_BUF    | \
128                                  ICE_DBG_AQ_CMD)
129
130 #define ICE_DBG_USER            BIT_ULL(31)
131 #define ICE_DBG_ALL             0xFFFFFFFFFFFFFFFFULL
132
133 #ifndef __ALWAYS_UNUSED
134 #define __ALWAYS_UNUSED
135 #endif
136
137 #define IS_ETHER_ADDR_EQUAL(addr1, addr2) \
138         (((bool)((((u16 *)(addr1))[0] == ((u16 *)(addr2))[0]))) && \
139          ((bool)((((u16 *)(addr1))[1] == ((u16 *)(addr2))[1]))) && \
140          ((bool)((((u16 *)(addr1))[2] == ((u16 *)(addr2))[2]))))
141
142 enum ice_aq_res_ids {
143         ICE_NVM_RES_ID = 1,
144         ICE_SPD_RES_ID,
145         ICE_CHANGE_LOCK_RES_ID,
146         ICE_GLOBAL_CFG_LOCK_RES_ID
147 };
148
149 /* FW update timeout definitions are in milliseconds */
150 #define ICE_NVM_TIMEOUT                 180000
151 #define ICE_CHANGE_LOCK_TIMEOUT         1000
152 #define ICE_GLOBAL_CFG_LOCK_TIMEOUT     3000
153
154 enum ice_aq_res_access_type {
155         ICE_RES_READ = 1,
156         ICE_RES_WRITE
157 };
158
159 struct ice_driver_ver {
160         u8 major_ver;
161         u8 minor_ver;
162         u8 build_ver;
163         u8 subbuild_ver;
164         u8 driver_string[32];
165 };
166
167 enum ice_fc_mode {
168         ICE_FC_NONE = 0,
169         ICE_FC_RX_PAUSE,
170         ICE_FC_TX_PAUSE,
171         ICE_FC_FULL,
172         ICE_FC_PFC,
173         ICE_FC_DFLT
174 };
175
176 enum ice_phy_cache_mode {
177         ICE_FC_MODE = 0,
178         ICE_SPEED_MODE,
179         ICE_FEC_MODE
180 };
181
182 enum ice_fec_mode {
183         ICE_FEC_NONE = 0,
184         ICE_FEC_RS,
185         ICE_FEC_BASER,
186         ICE_FEC_AUTO
187 };
188
189 struct ice_phy_cache_mode_data {
190         union {
191                 enum ice_fec_mode curr_user_fec_req;
192                 enum ice_fc_mode curr_user_fc_req;
193                 u16 curr_user_speed_req;
194         } data;
195 };
196
197 enum ice_set_fc_aq_failures {
198         ICE_SET_FC_AQ_FAIL_NONE = 0,
199         ICE_SET_FC_AQ_FAIL_GET,
200         ICE_SET_FC_AQ_FAIL_SET,
201         ICE_SET_FC_AQ_FAIL_UPDATE
202 };
203
204 /* These are structs for managing the hardware information and the operations */
205 /* MAC types */
206 enum ice_mac_type {
207         ICE_MAC_UNKNOWN = 0,
208         ICE_MAC_GENERIC,
209 };
210
211 /* Media Types */
212 enum ice_media_type {
213         ICE_MEDIA_UNKNOWN = 0,
214         ICE_MEDIA_FIBER,
215         ICE_MEDIA_BASET,
216         ICE_MEDIA_BACKPLANE,
217         ICE_MEDIA_DA,
218 };
219
220 /* Software VSI types. */
221 enum ice_vsi_type {
222         ICE_VSI_PF = 0,
223         ICE_VSI_CTRL = 3,       /* equates to ICE_VSI_PF with 1 queue pair */
224         ICE_VSI_LB = 6,
225 };
226
227 struct ice_link_status {
228         /* Refer to ice_aq_phy_type for bits definition */
229         u64 phy_type_low;
230         u64 phy_type_high;
231         u8 topo_media_conflict;
232         u16 max_frame_size;
233         u16 link_speed;
234         u16 req_speeds;
235         u8 lse_ena;     /* Link Status Event notification */
236         u8 link_info;
237         u8 an_info;
238         u8 ext_info;
239         u8 fec_info;
240         u8 pacing;
241         /* Refer to #define from module_type[ICE_MODULE_TYPE_TOTAL_BYTE] of
242          * ice_aqc_get_phy_caps structure
243          */
244         u8 module_type[ICE_MODULE_TYPE_TOTAL_BYTE];
245 };
246
247 /* Different data queue types: These are mainly for SW consumption. */
248 enum ice_q {
249         ICE_DATA_Q_DOORBELL,
250         ICE_DATA_Q_CMPL,
251         ICE_DATA_Q_QUANTA,
252         ICE_DATA_Q_RX,
253         ICE_DATA_Q_TX,
254 };
255
256 /* Different reset sources for which a disable queue AQ call has to be made in
257  * order to clean the Tx scheduler as a part of the reset
258  */
259 enum ice_disq_rst_src {
260         ICE_NO_RESET = 0,
261         ICE_VM_RESET,
262 };
263
264 /* PHY info such as phy_type, etc... */
265 struct ice_phy_info {
266         struct ice_link_status link_info;
267         struct ice_link_status link_info_old;
268         u64 phy_type_low;
269         u64 phy_type_high;
270         enum ice_media_type media_type;
271         u8 get_link_info;
272         /* Please refer to struct ice_aqc_get_link_status_data to get
273          * detail of enable bit in curr_user_speed_req
274          */
275         u16 curr_user_speed_req;
276         enum ice_fec_mode curr_user_fec_req;
277         enum ice_fc_mode curr_user_fc_req;
278         struct ice_aqc_set_phy_cfg_data curr_user_phy_cfg;
279 };
280
281 #define ICE_MAX_NUM_MIRROR_RULES        64
282
283 /* protocol enumeration for filters */
284 enum ice_fltr_ptype {
285         /* NONE - used for undef/error */
286         ICE_FLTR_PTYPE_NONF_NONE = 0,
287         ICE_FLTR_PTYPE_NONF_IPV4_UDP,
288         ICE_FLTR_PTYPE_NONF_IPV4_TCP,
289         ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
290         ICE_FLTR_PTYPE_NONF_IPV4_OTHER,
291         ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP,
292         ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP,
293         ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP,
294         ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER,
295         ICE_FLTR_PTYPE_FRAG_IPV4,
296         ICE_FLTR_PTYPE_NONF_IPV6_UDP,
297         ICE_FLTR_PTYPE_NONF_IPV6_TCP,
298         ICE_FLTR_PTYPE_NONF_IPV6_SCTP,
299         ICE_FLTR_PTYPE_NONF_IPV6_OTHER,
300         ICE_FLTR_PTYPE_MAX,
301 };
302
303 enum ice_fd_hw_seg {
304         ICE_FD_HW_SEG_NON_TUN = 0,
305         ICE_FD_HW_SEG_TUN,
306         ICE_FD_HW_SEG_MAX,
307 };
308
309 /* 2 VSI = 1 ICE_VSI_PF + 1 ICE_VSI_CTRL */
310 #define ICE_MAX_FDIR_VSI_PER_FILTER     2
311
312 struct ice_fd_hw_prof {
313         struct ice_flow_seg_info *fdir_seg[ICE_FD_HW_SEG_MAX];
314         int cnt;
315         u64 entry_h[ICE_MAX_FDIR_VSI_PER_FILTER][ICE_FD_HW_SEG_MAX];
316         u16 vsi_h[ICE_MAX_FDIR_VSI_PER_FILTER];
317 };
318
319 /* Common HW capabilities for SW use */
320 struct ice_hw_common_caps {
321         /* Write CSR protection */
322         u64 wr_csr_prot;
323         u32 switching_mode;
324         /* switching mode supported - EVB switching (including cloud) */
325 #define ICE_NVM_IMAGE_TYPE_EVB          0x0
326
327         /* Manageablity mode & supported protocols over MCTP */
328         u32 mgmt_mode;
329 #define ICE_MGMT_MODE_PASS_THRU_MODE_M          0xF
330 #define ICE_MGMT_MODE_CTL_INTERFACE_M           0xF0
331 #define ICE_MGMT_MODE_REDIR_SB_INTERFACE_M      0xF00
332
333         u32 mgmt_protocols_mctp;
334 #define ICE_MGMT_MODE_PROTO_RSVD        BIT(0)
335 #define ICE_MGMT_MODE_PROTO_PLDM        BIT(1)
336 #define ICE_MGMT_MODE_PROTO_OEM         BIT(2)
337 #define ICE_MGMT_MODE_PROTO_NC_SI       BIT(3)
338
339         u32 os2bmc;
340         u32 valid_functions;
341         /* DCB capabilities */
342         u32 active_tc_bitmap;
343         u32 maxtc;
344
345         /* RSS related capabilities */
346         u32 rss_table_size;             /* 512 for PFs and 64 for VFs */
347         u32 rss_table_entry_width;      /* RSS Entry width in bits */
348
349         /* Tx/Rx queues */
350         u32 num_rxq;                    /* Number/Total Rx queues */
351         u32 rxq_first_id;               /* First queue ID for Rx queues */
352         u32 num_txq;                    /* Number/Total Tx queues */
353         u32 txq_first_id;               /* First queue ID for Tx queues */
354
355         /* MSI-X vectors */
356         u32 num_msix_vectors;
357         u32 msix_vector_first_id;
358
359         /* Max MTU for function or device */
360         u32 max_mtu;
361
362         /* WOL related */
363         u32 num_wol_proxy_fltr;
364         u32 wol_proxy_vsi_seid;
365
366         /* LED/SDP pin count */
367         u32 led_pin_num;
368         u32 sdp_pin_num;
369
370         /* LED/SDP - Supports up to 12 LED pins and 8 SDP signals */
371 #define ICE_MAX_SUPPORTED_GPIO_LED      12
372 #define ICE_MAX_SUPPORTED_GPIO_SDP      8
373         u8 led[ICE_MAX_SUPPORTED_GPIO_LED];
374         u8 sdp[ICE_MAX_SUPPORTED_GPIO_SDP];
375
376         /* EVB capabilities */
377         u8 evb_802_1_qbg;               /* Edge Virtual Bridging */
378         u8 evb_802_1_qbh;               /* Bridge Port Extension */
379
380         u8 dcb;
381         u8 iscsi;
382         u8 mgmt_cem;
383
384         /* WoL and APM support */
385 #define ICE_WOL_SUPPORT_M               BIT(0)
386 #define ICE_ACPI_PROG_MTHD_M            BIT(1)
387 #define ICE_PROXY_SUPPORT_M             BIT(2)
388         u8 apm_wol_support;
389         u8 acpi_prog_mthd;
390         u8 proxy_support;
391 };
392
393 /* Function specific capabilities */
394 struct ice_hw_func_caps {
395         struct ice_hw_common_caps common_cap;
396         u32 guar_num_vsi;
397         u32 fd_fltr_guar;               /* Number of filters guaranteed */
398         u32 fd_fltr_best_effort;        /* Number of best effort filters */
399 };
400
401 /* Device wide capabilities */
402 struct ice_hw_dev_caps {
403         struct ice_hw_common_caps common_cap;
404         u32 num_vsi_allocd_to_host;     /* Excluding EMP VSI */
405         u32 num_flow_director_fltr;     /* Number of FD filters available */
406         u32 num_funcs;
407 };
408
409 /* Information about MAC such as address, etc... */
410 struct ice_mac_info {
411         u8 lan_addr[ETH_ALEN];
412         u8 perm_addr[ETH_ALEN];
413         u8 port_addr[ETH_ALEN];
414         u8 wol_addr[ETH_ALEN];
415 };
416
417 /* PCI bus types */
418 enum ice_bus_type {
419         ice_bus_unknown = 0,
420         ice_bus_pci_express,
421         ice_bus_embedded, /* Is device Embedded versus card */
422         ice_bus_reserved
423 };
424
425 /* PCI bus speeds */
426 enum ice_pcie_bus_speed {
427         ice_pcie_speed_unknown  = 0xff,
428         ice_pcie_speed_2_5GT    = 0x14,
429         ice_pcie_speed_5_0GT    = 0x15,
430         ice_pcie_speed_8_0GT    = 0x16,
431         ice_pcie_speed_16_0GT   = 0x17
432 };
433
434 /* PCI bus widths */
435 enum ice_pcie_link_width {
436         ice_pcie_lnk_width_resrv        = 0x00,
437         ice_pcie_lnk_x1                 = 0x01,
438         ice_pcie_lnk_x2                 = 0x02,
439         ice_pcie_lnk_x4                 = 0x04,
440         ice_pcie_lnk_x8                 = 0x08,
441         ice_pcie_lnk_x12                = 0x0C,
442         ice_pcie_lnk_x16                = 0x10,
443         ice_pcie_lnk_x32                = 0x20,
444         ice_pcie_lnk_width_unknown      = 0xff,
445 };
446
447 /* Reset types used to determine which kind of reset was requested. These
448  * defines match what the RESET_TYPE field of the GLGEN_RSTAT register.
449  * ICE_RESET_PFR does not match any RESET_TYPE field in the GLGEN_RSTAT register
450  * because its reset source is different than the other types listed.
451  */
452 enum ice_reset_req {
453         ICE_RESET_POR   = 0,
454         ICE_RESET_INVAL = 0,
455         ICE_RESET_CORER = 1,
456         ICE_RESET_GLOBR = 2,
457         ICE_RESET_EMPR  = 3,
458         ICE_RESET_PFR   = 4,
459 };
460
461 /* Bus parameters */
462 struct ice_bus_info {
463         enum ice_pcie_bus_speed speed;
464         enum ice_pcie_link_width width;
465         enum ice_bus_type type;
466         u16 domain_num;
467         u16 device;
468         u8 func;
469         u8 bus_num;
470 };
471
472 /* Flow control (FC) parameters */
473 struct ice_fc_info {
474         enum ice_fc_mode current_mode;  /* FC mode in effect */
475         enum ice_fc_mode req_mode;      /* FC mode requested by caller */
476 };
477
478 /* NVM Information */
479 struct ice_nvm_info {
480         u32 eetrack;                    /* NVM data version */
481         u32 oem_ver;                    /* OEM version info */
482         u16 sr_words;                   /* Shadow RAM size in words */
483         u16 ver;                        /* dev starter version */
484         u8 blank_nvm_mode;              /* is NVM empty (no FW present)*/
485 };
486
487 #define ICE_NVM_VER_LEN 32
488
489 /* Max number of port to queue branches w.r.t topology */
490 #define ICE_TXSCHED_MAX_BRANCHES ICE_MAX_TRAFFIC_CLASS
491
492 #define ice_for_each_traffic_class(_i)  \
493         for ((_i) = 0; (_i) < ICE_MAX_TRAFFIC_CLASS; (_i)++)
494
495 /* ICE_DFLT_AGG_ID means that all new VM(s)/VSI node connects
496  * to driver defined policy for default aggregator
497  */
498 #define ICE_INVAL_TEID 0xFFFFFFFF
499 #define ICE_DFLT_AGG_ID 0
500
501 struct ice_sched_node {
502         struct ice_sched_node *parent;
503         struct ice_sched_node *sibling; /* next sibling in the same layer */
504         struct ice_sched_node **children;
505         struct ice_aqc_txsched_elem_data info;
506         u32 agg_id;                     /* aggregator group ID */
507         u16 vsi_handle;
508         u8 in_use;                      /* suspended or in use */
509         u8 tx_sched_layer;              /* Logical Layer (1-9) */
510         u8 num_children;
511         u8 tc_num;
512         u8 owner;
513 #define ICE_SCHED_NODE_OWNER_LAN        0
514 #define ICE_SCHED_NODE_OWNER_AE         1
515 #define ICE_SCHED_NODE_OWNER_RDMA       2
516 };
517
518 /* Access Macros for Tx Sched Elements data */
519 #define ICE_TXSCHED_GET_NODE_TEID(x) LE32_TO_CPU((x)->info.node_teid)
520 #define ICE_TXSCHED_GET_PARENT_TEID(x) LE32_TO_CPU((x)->info.parent_teid)
521 #define ICE_TXSCHED_GET_CIR_RL_ID(x)    \
522         LE16_TO_CPU((x)->info.cir_bw.bw_profile_idx)
523 #define ICE_TXSCHED_GET_EIR_RL_ID(x)    \
524         LE16_TO_CPU((x)->info.eir_bw.bw_profile_idx)
525 #define ICE_TXSCHED_GET_SRL_ID(x) LE16_TO_CPU((x)->info.srl_id)
526 #define ICE_TXSCHED_GET_CIR_BWALLOC(x)  \
527         LE16_TO_CPU((x)->info.cir_bw.bw_alloc)
528 #define ICE_TXSCHED_GET_EIR_BWALLOC(x)  \
529         LE16_TO_CPU((x)->info.eir_bw.bw_alloc)
530
531 struct ice_sched_rl_profle {
532         u32 rate; /* In Kbps */
533         struct ice_aqc_rl_profile_elem info;
534 };
535
536 /* The aggregator type determines if identifier is for a VSI group,
537  * aggregator group, aggregator of queues, or queue group.
538  */
539 enum ice_agg_type {
540         ICE_AGG_TYPE_UNKNOWN = 0,
541         ICE_AGG_TYPE_TC,
542         ICE_AGG_TYPE_AGG, /* aggregator */
543         ICE_AGG_TYPE_VSI,
544         ICE_AGG_TYPE_QG,
545         ICE_AGG_TYPE_Q
546 };
547
548 /* Rate limit types */
549 enum ice_rl_type {
550         ICE_UNKNOWN_BW = 0,
551         ICE_MIN_BW,             /* for CIR profile */
552         ICE_MAX_BW,             /* for EIR profile */
553         ICE_SHARED_BW           /* for shared profile */
554 };
555
556 #define ICE_SCHED_MIN_BW                500             /* in Kbps */
557 #define ICE_SCHED_MAX_BW                100000000       /* in Kbps */
558 #define ICE_SCHED_DFLT_BW               0xFFFFFFFF      /* unlimited */
559 #define ICE_SCHED_NO_PRIORITY           0
560 #define ICE_SCHED_NO_BW_WT              0
561 #define ICE_SCHED_DFLT_RL_PROF_ID       0
562 #define ICE_SCHED_NO_SHARED_RL_PROF_ID  0xFFFF
563 #define ICE_SCHED_DFLT_BW_WT            1
564 #define ICE_SCHED_INVAL_PROF_ID         0xFFFF
565 #define ICE_SCHED_DFLT_BURST_SIZE       (15 * 1024)     /* in bytes (15k) */
566
567 /* Access Macros for Tx Sched RL Profile data */
568 #define ICE_TXSCHED_GET_RL_PROF_ID(p) LE16_TO_CPU((p)->info.profile_id)
569 #define ICE_TXSCHED_GET_RL_MBS(p) LE16_TO_CPU((p)->info.max_burst_size)
570 #define ICE_TXSCHED_GET_RL_MULTIPLIER(p) LE16_TO_CPU((p)->info.rl_multiply)
571 #define ICE_TXSCHED_GET_RL_WAKEUP_MV(p) LE16_TO_CPU((p)->info.wake_up_calc)
572 #define ICE_TXSCHED_GET_RL_ENCODE(p) LE16_TO_CPU((p)->info.rl_encode)
573
574 /* The following tree example shows the naming conventions followed under
575  * ice_port_info struct for default scheduler tree topology.
576  *
577  *                 A tree on a port
578  *                       *                ---> root node
579  *        (TC0)/  /  /  / \  \  \  \(TC7) ---> num_branches (range:1- 8)
580  *            *  *  *  *   *  *  *  *     |
581  *           /                            |
582  *          *                             |
583  *         /                              |-> num_elements (range:1 - 9)
584  *        *                               |   implies num_of_layers
585  *       /                                |
586  *   (a)*                                 |
587  *
588  *  (a) is the last_node_teid(not of type Leaf). A leaf node is created under
589  *  (a) as child node where queues get added, add Tx/Rx queue admin commands;
590  *  need TEID of (a) to add queues.
591  *
592  *  This tree
593  *       -> has 8 branches (one for each TC)
594  *       -> First branch (TC0) has 4 elements
595  *       -> has 4 layers
596  *       -> (a) is the topmost layer node created by firmware on branch 0
597  *
598  *  Note: Above asterisk tree covers only basic terminology and scenario.
599  *  Refer to the documentation for more info.
600  */
601
602  /* Data structure for saving BW information */
603 enum ice_bw_type {
604         ICE_BW_TYPE_PRIO,
605         ICE_BW_TYPE_CIR,
606         ICE_BW_TYPE_CIR_WT,
607         ICE_BW_TYPE_EIR,
608         ICE_BW_TYPE_EIR_WT,
609         ICE_BW_TYPE_SHARED,
610         ICE_BW_TYPE_CNT         /* This must be last */
611 };
612
613 struct ice_bw {
614         u32 bw;
615         u16 bw_alloc;
616 };
617
618 struct ice_bw_type_info {
619         ice_declare_bitmap(bw_t_bitmap, ICE_BW_TYPE_CNT);
620         u8 generic;
621         struct ice_bw cir_bw;
622         struct ice_bw eir_bw;
623         u32 shared_bw;
624 };
625
626 /* VSI queue context structure for given TC */
627 struct ice_q_ctx {
628         u16  q_handle;
629         u32  q_teid;
630         /* bw_t_info saves queue BW information */
631         struct ice_bw_type_info bw_t_info;
632 };
633
634 /* VSI type list entry to locate corresponding VSI/aggregator nodes */
635 struct ice_sched_vsi_info {
636         struct ice_sched_node *vsi_node[ICE_MAX_TRAFFIC_CLASS];
637         struct ice_sched_node *ag_node[ICE_MAX_TRAFFIC_CLASS];
638         u16 max_lanq[ICE_MAX_TRAFFIC_CLASS];
639         /* bw_t_info saves VSI BW information */
640         struct ice_bw_type_info bw_t_info[ICE_MAX_TRAFFIC_CLASS];
641 };
642
643 /* CEE or IEEE 802.1Qaz ETS Configuration data */
644 struct ice_dcb_ets_cfg {
645         u8 willing;
646         u8 cbs;
647         u8 maxtcs;
648         u8 prio_table[ICE_MAX_TRAFFIC_CLASS];
649         u8 tcbwtable[ICE_MAX_TRAFFIC_CLASS];
650         u8 tsatable[ICE_MAX_TRAFFIC_CLASS];
651 };
652
653 /* CEE or IEEE 802.1Qaz PFC Configuration data */
654 struct ice_dcb_pfc_cfg {
655         u8 willing;
656         u8 mbc;
657         u8 pfccap;
658         u8 pfcena;
659 };
660
661 /* CEE or IEEE 802.1Qaz Application Priority data */
662 struct ice_dcb_app_priority_table {
663         u16 prot_id;
664         u8 priority;
665         u8 selector;
666 };
667
668 #define ICE_MAX_USER_PRIORITY   8
669 #define ICE_DCBX_MAX_APPS       32
670 #define ICE_LLDPDU_SIZE         1500
671 #define ICE_TLV_STATUS_OPER     0x1
672 #define ICE_TLV_STATUS_SYNC     0x2
673 #define ICE_TLV_STATUS_ERR      0x4
674 #define ICE_APP_PROT_ID_FCOE    0x8906
675 #define ICE_APP_PROT_ID_ISCSI   0x0cbc
676 #define ICE_APP_PROT_ID_FIP     0x8914
677 #define ICE_APP_SEL_ETHTYPE     0x1
678 #define ICE_APP_SEL_TCPIP       0x2
679 #define ICE_CEE_APP_SEL_ETHTYPE 0x0
680 #define ICE_CEE_APP_SEL_TCPIP   0x1
681
682 struct ice_dcbx_cfg {
683         u32 numapps;
684         u32 tlv_status; /* CEE mode TLV status */
685         struct ice_dcb_ets_cfg etscfg;
686         struct ice_dcb_ets_cfg etsrec;
687         struct ice_dcb_pfc_cfg pfc;
688         struct ice_dcb_app_priority_table app[ICE_DCBX_MAX_APPS];
689         u8 dcbx_mode;
690 #define ICE_DCBX_MODE_CEE       0x1
691 #define ICE_DCBX_MODE_IEEE      0x2
692         u8 app_mode;
693 #define ICE_DCBX_APPS_NON_WILLING       0x1
694 };
695
696 struct ice_port_info {
697         struct ice_sched_node *root;    /* Root Node per Port */
698         struct ice_hw *hw;              /* back pointer to HW instance */
699         u32 last_node_teid;             /* scheduler last node info */
700         u16 sw_id;                      /* Initial switch ID belongs to port */
701         u16 pf_vf_num;
702         u8 port_state;
703 #define ICE_SCHED_PORT_STATE_INIT       0x0
704 #define ICE_SCHED_PORT_STATE_READY      0x1
705         u8 lport;
706 #define ICE_LPORT_MASK                  0xff
707         u16 dflt_tx_vsi_rule_id;
708         u16 dflt_tx_vsi_num;
709         u16 dflt_rx_vsi_rule_id;
710         u16 dflt_rx_vsi_num;
711         struct ice_fc_info fc;
712         struct ice_mac_info mac;
713         struct ice_phy_info phy;
714         struct ice_lock sched_lock;     /* protect access to TXSched tree */
715         struct ice_sched_node *
716                 sib_head[ICE_MAX_TRAFFIC_CLASS][ICE_AQC_TOPO_MAX_LEVEL_NUM];
717         /* List contain profile ID(s) and other params per layer */
718         struct LIST_HEAD_TYPE rl_prof_list[ICE_AQC_TOPO_MAX_LEVEL_NUM];
719         struct ice_bw_type_info tc_node_bw_t_info[ICE_MAX_TRAFFIC_CLASS];
720         struct ice_dcbx_cfg local_dcbx_cfg;     /* Oper/Local Cfg */
721         /* DCBX info */
722         struct ice_dcbx_cfg remote_dcbx_cfg;    /* Peer Cfg */
723         struct ice_dcbx_cfg desired_dcbx_cfg;   /* CEE Desired Cfg */
724         /* LLDP/DCBX Status */
725         u8 dcbx_status:3;               /* see ICE_DCBX_STATUS_DIS */
726         u8 is_sw_lldp:1;
727         u8 is_vf:1;
728 };
729
730 struct ice_switch_info {
731         struct LIST_HEAD_TYPE vsi_list_map_head;
732         struct ice_sw_recipe *recp_list;
733 };
734
735 /* Port hardware description */
736 struct ice_hw {
737         u8 *hw_addr;
738         void *back;
739         struct ice_aqc_layer_props *layer_info;
740         struct ice_port_info *port_info;
741         /* 2D Array for each Tx Sched RL Profile type */
742         struct ice_sched_rl_profile **cir_profiles;
743         struct ice_sched_rl_profile **eir_profiles;
744         struct ice_sched_rl_profile **srl_profiles;
745         u64 debug_mask;         /* BITMAP for debug mask */
746         enum ice_mac_type mac_type;
747
748         u16 fd_ctr_base;        /* FD counter base index */
749         /* pci info */
750         u16 device_id;
751         u16 vendor_id;
752         u16 subsystem_device_id;
753         u16 subsystem_vendor_id;
754         u8 revision_id;
755
756         u8 pf_id;               /* device profile info */
757
758         u16 max_burst_size;     /* driver sets this value */
759
760         /* Tx Scheduler values */
761         u16 num_tx_sched_layers;
762         u16 num_tx_sched_phys_layers;
763         u8 flattened_layers;
764         u8 max_cgds;
765         u8 sw_entry_point_layer;
766         u16 max_children[ICE_AQC_TOPO_MAX_LEVEL_NUM];
767         struct LIST_HEAD_TYPE agg_list; /* lists all aggregator */
768         struct ice_vsi_ctx *vsi_ctx[ICE_MAX_VSI];
769         u8 evb_veb;             /* true for VEB, false for VEPA */
770         u8 reset_ongoing;       /* true if HW is in reset, false otherwise */
771         struct ice_bus_info bus;
772         struct ice_nvm_info nvm;
773         struct ice_hw_dev_caps dev_caps;        /* device capabilities */
774         struct ice_hw_func_caps func_caps;      /* function capabilities */
775
776         struct ice_switch_info *switch_info;    /* switch filter lists */
777
778         /* Control Queue info */
779         struct ice_ctl_q_info adminq;
780         struct ice_ctl_q_info mailboxq;
781
782         u8 api_branch;          /* API branch version */
783         u8 api_maj_ver;         /* API major version */
784         u8 api_min_ver;         /* API minor version */
785         u8 api_patch;           /* API patch version */
786         u8 fw_branch;           /* firmware branch version */
787         u8 fw_maj_ver;          /* firmware major version */
788         u8 fw_min_ver;          /* firmware minor version */
789         u8 fw_patch;            /* firmware patch version */
790         u32 fw_build;           /* firmware build number */
791
792 /* Device max aggregate bandwidths corresponding to the GL_PWR_MODE_CTL
793  * register. Used for determining the ITR/INTRL granularity during
794  * initialization.
795  */
796 #define ICE_MAX_AGG_BW_200G     0x0
797 #define ICE_MAX_AGG_BW_100G     0X1
798 #define ICE_MAX_AGG_BW_50G      0x2
799 #define ICE_MAX_AGG_BW_25G      0x3
800         /* ITR granularity for different speeds */
801 #define ICE_ITR_GRAN_ABOVE_25   2
802 #define ICE_ITR_GRAN_MAX_25     4
803         /* ITR granularity in 1 us */
804         u8 itr_gran;
805         /* INTRL granularity for different speeds */
806 #define ICE_INTRL_GRAN_ABOVE_25 4
807 #define ICE_INTRL_GRAN_MAX_25   8
808         /* INTRL granularity in 1 us */
809         u8 intrl_gran;
810
811         u8 ucast_shared;        /* true if VSIs can share unicast addr */
812
813         /* Active package version (currently active) */
814         struct ice_pkg_ver active_pkg_ver;
815         u8 active_pkg_name[ICE_PKG_NAME_SIZE];
816         u8 active_pkg_in_nvm;
817
818         enum ice_aq_err pkg_dwnld_status;
819
820         /* Driver's package ver - (from the Metadata seg) */
821         struct ice_pkg_ver pkg_ver;
822         u8 pkg_name[ICE_PKG_NAME_SIZE];
823
824         /* Driver's Ice package version (from the Ice seg) */
825         struct ice_pkg_ver ice_pkg_ver;
826         u8 ice_pkg_name[ICE_PKG_NAME_SIZE];
827
828         /* Pointer to the ice segment */
829         struct ice_seg *seg;
830
831         /* Pointer to allocated copy of pkg memory */
832         u8 *pkg_copy;
833         u32 pkg_size;
834
835         /* tunneling info */
836         struct ice_tunnel_table tnl;
837
838 #define ICE_PKG_FILENAME        "package_file"
839 #define ICE_PKG_FILENAME_EXT    "pkg"
840 #define ICE_PKG_FILE_MAJ_VER    1
841 #define ICE_PKG_FILE_MIN_VER    0
842
843         /* HW block tables */
844         struct ice_blk_info blk[ICE_BLK_COUNT];
845         struct ice_lock fl_profs_locks[ICE_BLK_COUNT];  /* lock fltr profiles */
846         struct LIST_HEAD_TYPE fl_profs[ICE_BLK_COUNT];
847         /* Flow Director filter info */
848         int fdir_active_fltr;
849
850         struct ice_lock fdir_fltr_lock; /* protect Flow Director */
851         struct LIST_HEAD_TYPE fdir_list_head;
852
853         /* Book-keeping of side-band filter count per flow-type.
854          * This is used to detect and handle input set changes for
855          * respective flow-type.
856          */
857         u16 fdir_fltr_cnt[ICE_FLTR_PTYPE_MAX];
858
859         struct ice_fd_hw_prof **fdir_prof;
860         ice_declare_bitmap(fdir_perfect_fltr, ICE_FLTR_PTYPE_MAX);
861         struct ice_lock rss_locks;      /* protect RSS configuration */
862         struct LIST_HEAD_TYPE rss_list_head;
863 };
864
865 /* Statistics collected by each port, VSI, VEB, and S-channel */
866 struct ice_eth_stats {
867         u64 rx_bytes;                   /* gorc */
868         u64 rx_unicast;                 /* uprc */
869         u64 rx_multicast;               /* mprc */
870         u64 rx_broadcast;               /* bprc */
871         u64 rx_discards;                /* rdpc */
872         u64 rx_unknown_protocol;        /* rupp */
873         u64 tx_bytes;                   /* gotc */
874         u64 tx_unicast;                 /* uptc */
875         u64 tx_multicast;               /* mptc */
876         u64 tx_broadcast;               /* bptc */
877         u64 tx_discards;                /* tdpc */
878         u64 tx_errors;                  /* tepc */
879         u64 rx_no_desc;                 /* repc */
880         u64 rx_errors;                  /* repc */
881 };
882
883 #define ICE_MAX_UP      8
884
885 /* Statistics collected per VEB per User Priority (UP) for up to 8 UPs */
886 struct ice_veb_up_stats {
887         u64 up_rx_pkts[ICE_MAX_UP];
888         u64 up_rx_bytes[ICE_MAX_UP];
889         u64 up_tx_pkts[ICE_MAX_UP];
890         u64 up_tx_bytes[ICE_MAX_UP];
891 };
892
893 /* Statistics collected by the MAC */
894 struct ice_hw_port_stats {
895         /* eth stats collected by the port */
896         struct ice_eth_stats eth;
897         /* additional port specific stats */
898         u64 tx_dropped_link_down;       /* tdold */
899         u64 crc_errors;                 /* crcerrs */
900         u64 illegal_bytes;              /* illerrc */
901         u64 error_bytes;                /* errbc */
902         u64 mac_local_faults;           /* mlfc */
903         u64 mac_remote_faults;          /* mrfc */
904         u64 rx_len_errors;              /* rlec */
905         u64 link_xon_rx;                /* lxonrxc */
906         u64 link_xoff_rx;               /* lxoffrxc */
907         u64 link_xon_tx;                /* lxontxc */
908         u64 link_xoff_tx;               /* lxofftxc */
909         u64 priority_xon_rx[8];         /* pxonrxc[8] */
910         u64 priority_xoff_rx[8];        /* pxoffrxc[8] */
911         u64 priority_xon_tx[8];         /* pxontxc[8] */
912         u64 priority_xoff_tx[8];        /* pxofftxc[8] */
913         u64 priority_xon_2_xoff[8];     /* pxon2offc[8] */
914         u64 rx_size_64;                 /* prc64 */
915         u64 rx_size_127;                /* prc127 */
916         u64 rx_size_255;                /* prc255 */
917         u64 rx_size_511;                /* prc511 */
918         u64 rx_size_1023;               /* prc1023 */
919         u64 rx_size_1522;               /* prc1522 */
920         u64 rx_size_big;                /* prc9522 */
921         u64 rx_undersize;               /* ruc */
922         u64 rx_fragments;               /* rfc */
923         u64 rx_oversize;                /* roc */
924         u64 rx_jabber;                  /* rjc */
925         u64 tx_size_64;                 /* ptc64 */
926         u64 tx_size_127;                /* ptc127 */
927         u64 tx_size_255;                /* ptc255 */
928         u64 tx_size_511;                /* ptc511 */
929         u64 tx_size_1023;               /* ptc1023 */
930         u64 tx_size_1522;               /* ptc1522 */
931         u64 tx_size_big;                /* ptc9522 */
932         u64 mac_short_pkt_dropped;      /* mspdc */
933         /* flow director stats */
934         u32 fd_sb_status;
935         u64 fd_sb_match;
936 };
937
938 enum ice_sw_fwd_act_type {
939         ICE_FWD_TO_VSI = 0,
940         ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
941         ICE_FWD_TO_Q,
942         ICE_FWD_TO_QGRP,
943         ICE_DROP_PACKET,
944         ICE_INVAL_ACT
945 };
946
947 /* Checksum and Shadow RAM pointers */
948 #define ICE_SR_NVM_CTRL_WORD                    0x00
949 #define ICE_SR_PHY_ANALOG_PTR                   0x04
950 #define ICE_SR_OPTION_ROM_PTR                   0x05
951 #define ICE_SR_RO_PCIR_REGS_AUTO_LOAD_PTR       0x06
952 #define ICE_SR_AUTO_GENERATED_POINTERS_PTR      0x07
953 #define ICE_SR_PCIR_REGS_AUTO_LOAD_PTR          0x08
954 #define ICE_SR_EMP_GLOBAL_MODULE_PTR            0x09
955 #define ICE_SR_EMP_IMAGE_PTR                    0x0B
956 #define ICE_SR_PE_IMAGE_PTR                     0x0C
957 #define ICE_SR_CSR_PROTECTED_LIST_PTR           0x0D
958 #define ICE_SR_MNG_CFG_PTR                      0x0E
959 #define ICE_SR_EMP_MODULE_PTR                   0x0F
960 #define ICE_SR_PBA_BLOCK_PTR                    0x16
961 #define ICE_SR_BOOT_CFG_PTR                     0x132
962 #define ICE_SR_NVM_WOL_CFG                      0x19
963 #define ICE_NVM_OEM_VER_OFF                     0x02
964 #define ICE_SR_NVM_DEV_STARTER_VER              0x18
965 #define ICE_SR_ALTERNATE_SAN_MAC_ADDR_PTR       0x27
966 #define ICE_SR_PERMANENT_SAN_MAC_ADDR_PTR       0x28
967 #define ICE_SR_NVM_MAP_VER                      0x29
968 #define ICE_SR_NVM_IMAGE_VER                    0x2A
969 #define ICE_SR_NVM_STRUCTURE_VER                0x2B
970 #define ICE_SR_NVM_EETRACK_LO                   0x2D
971 #define ICE_SR_NVM_EETRACK_HI                   0x2E
972 #define ICE_NVM_VER_LO_SHIFT                    0
973 #define ICE_NVM_VER_LO_MASK                     (0xff << ICE_NVM_VER_LO_SHIFT)
974 #define ICE_NVM_VER_HI_SHIFT                    12
975 #define ICE_NVM_VER_HI_MASK                     (0xf << ICE_NVM_VER_HI_SHIFT)
976 #define ICE_OEM_EETRACK_ID                      0xffffffff
977 #define ICE_OEM_VER_PATCH_SHIFT                 0
978 #define ICE_OEM_VER_PATCH_MASK          (0xff << ICE_OEM_VER_PATCH_SHIFT)
979 #define ICE_OEM_VER_BUILD_SHIFT                 8
980 #define ICE_OEM_VER_BUILD_MASK          (0xffff << ICE_OEM_VER_BUILD_SHIFT)
981 #define ICE_OEM_VER_SHIFT                       24
982 #define ICE_OEM_VER_MASK                        (0xff << ICE_OEM_VER_SHIFT)
983 #define ICE_SR_VPD_PTR                          0x2F
984 #define ICE_SR_PXE_SETUP_PTR                    0x30
985 #define ICE_SR_PXE_CFG_CUST_OPTIONS_PTR         0x31
986 #define ICE_SR_NVM_ORIGINAL_EETRACK_LO          0x34
987 #define ICE_SR_NVM_ORIGINAL_EETRACK_HI          0x35
988 #define ICE_SR_VLAN_CFG_PTR                     0x37
989 #define ICE_SR_POR_REGS_AUTO_LOAD_PTR           0x38
990 #define ICE_SR_EMPR_REGS_AUTO_LOAD_PTR          0x3A
991 #define ICE_SR_GLOBR_REGS_AUTO_LOAD_PTR         0x3B
992 #define ICE_SR_CORER_REGS_AUTO_LOAD_PTR         0x3C
993 #define ICE_SR_PHY_CFG_SCRIPT_PTR               0x3D
994 #define ICE_SR_PCIE_ALT_AUTO_LOAD_PTR           0x3E
995 #define ICE_SR_SW_CHECKSUM_WORD                 0x3F
996 #define ICE_SR_PFA_PTR                          0x40
997 #define ICE_SR_1ST_SCRATCH_PAD_PTR              0x41
998 #define ICE_SR_1ST_NVM_BANK_PTR                 0x42
999 #define ICE_SR_NVM_BANK_SIZE                    0x43
1000 #define ICE_SR_1ND_OROM_BANK_PTR                0x44
1001 #define ICE_SR_OROM_BANK_SIZE                   0x45
1002 #define ICE_SR_NETLIST_BANK_PTR                 0x46
1003 #define ICE_SR_NETLIST_BANK_SIZE                0x47
1004 #define ICE_SR_EMP_SR_SETTINGS_PTR              0x48
1005 #define ICE_SR_CONFIGURATION_METADATA_PTR       0x4D
1006 #define ICE_SR_IMMEDIATE_VALUES_PTR             0x4E
1007 #define ICE_SR_POR_REGISTERS_AUTOLOAD_PTR       0x118
1008
1009 /* Auxiliary field, mask and shift definition for Shadow RAM and NVM Flash */
1010 #define ICE_SR_VPD_SIZE_WORDS           512
1011 #define ICE_SR_PCIE_ALT_SIZE_WORDS      512
1012 #define ICE_SR_CTRL_WORD_1_S            0x06
1013 #define ICE_SR_CTRL_WORD_1_M            (0x03 << ICE_SR_CTRL_WORD_1_S)
1014
1015 /* Shadow RAM related */
1016 #define ICE_SR_SECTOR_SIZE_IN_WORDS     0x800
1017 #define ICE_SR_BUF_ALIGNMENT            4096
1018 #define ICE_SR_WORDS_IN_1KB             512
1019 /* Checksum should be calculated such that after adding all the words,
1020  * including the checksum word itself, the sum should be 0xBABA.
1021  */
1022 #define ICE_SR_SW_CHECKSUM_BASE         0xBABA
1023
1024 #define ICE_PBA_FLAG_DFLT               0xFAFA
1025 /* Hash redirection LUT for VSI - maximum array size */
1026 #define ICE_VSIQF_HLUT_ARRAY_SIZE       ((VSIQF_HLUT_MAX_INDEX + 1) * 4)
1027
1028 /*
1029  * Defines for values in the VF_PE_DB_SIZE bits in the GLPCI_LBARCTRL register.
1030  * This is needed to determine the BAR0 space for the VFs
1031  */
1032 #define GLPCI_LBARCTRL_VF_PE_DB_SIZE_0KB 0x0
1033 #define GLPCI_LBARCTRL_VF_PE_DB_SIZE_8KB 0x1
1034 #define GLPCI_LBARCTRL_VF_PE_DB_SIZE_64KB 0x2
1035
1036 #endif /* _ICE_TYPE_H_ */