Merge tag 'fuse-fixes-4.20-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / net / ethernet / intel / ice / ice_type.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 #ifndef _ICE_TYPE_H_
5 #define _ICE_TYPE_H_
6
7 #include "ice_status.h"
8 #include "ice_hw_autogen.h"
9 #include "ice_osdep.h"
10 #include "ice_controlq.h"
11 #include "ice_lan_tx_rx.h"
12
13 #define ICE_BYTES_PER_WORD      2
14 #define ICE_BYTES_PER_DWORD     4
15
16 static inline bool ice_is_tc_ena(u8 bitmap, u8 tc)
17 {
18         return test_bit(tc, (unsigned long *)&bitmap);
19 }
20
21 /* Driver always calls main vsi_handle first */
22 #define ICE_MAIN_VSI_HANDLE             0
23
24 /* debug masks - set these bits in hw->debug_mask to control output */
25 #define ICE_DBG_INIT            BIT_ULL(1)
26 #define ICE_DBG_LINK            BIT_ULL(4)
27 #define ICE_DBG_QCTX            BIT_ULL(6)
28 #define ICE_DBG_NVM             BIT_ULL(7)
29 #define ICE_DBG_LAN             BIT_ULL(8)
30 #define ICE_DBG_SW              BIT_ULL(13)
31 #define ICE_DBG_SCHED           BIT_ULL(14)
32 #define ICE_DBG_RES             BIT_ULL(17)
33 #define ICE_DBG_AQ_MSG          BIT_ULL(24)
34 #define ICE_DBG_AQ_CMD          BIT_ULL(27)
35 #define ICE_DBG_USER            BIT_ULL(31)
36
37 enum ice_aq_res_ids {
38         ICE_NVM_RES_ID = 1,
39         ICE_SPD_RES_ID,
40         ICE_CHANGE_LOCK_RES_ID,
41         ICE_GLOBAL_CFG_LOCK_RES_ID
42 };
43
44 /* FW update timeout definitions are in milliseconds */
45 #define ICE_NVM_TIMEOUT                 180000
46 #define ICE_CHANGE_LOCK_TIMEOUT         1000
47 #define ICE_GLOBAL_CFG_LOCK_TIMEOUT     3000
48
49 enum ice_aq_res_access_type {
50         ICE_RES_READ = 1,
51         ICE_RES_WRITE
52 };
53
54 enum ice_fc_mode {
55         ICE_FC_NONE = 0,
56         ICE_FC_RX_PAUSE,
57         ICE_FC_TX_PAUSE,
58         ICE_FC_FULL,
59         ICE_FC_PFC,
60         ICE_FC_DFLT
61 };
62
63 enum ice_set_fc_aq_failures {
64         ICE_SET_FC_AQ_FAIL_NONE = 0,
65         ICE_SET_FC_AQ_FAIL_GET,
66         ICE_SET_FC_AQ_FAIL_SET,
67         ICE_SET_FC_AQ_FAIL_UPDATE
68 };
69
70 /* Various MAC types */
71 enum ice_mac_type {
72         ICE_MAC_UNKNOWN = 0,
73         ICE_MAC_GENERIC,
74 };
75
76 /* Media Types */
77 enum ice_media_type {
78         ICE_MEDIA_UNKNOWN = 0,
79         ICE_MEDIA_FIBER,
80         ICE_MEDIA_BASET,
81         ICE_MEDIA_BACKPLANE,
82         ICE_MEDIA_DA,
83 };
84
85 enum ice_vsi_type {
86         ICE_VSI_PF = 0,
87         ICE_VSI_VF,
88 };
89
90 struct ice_link_status {
91         /* Refer to ice_aq_phy_type for bits definition */
92         u64 phy_type_low;
93         u16 max_frame_size;
94         u16 link_speed;
95         u16 req_speeds;
96         u8 lse_ena;     /* Link Status Event notification */
97         u8 link_info;
98         u8 an_info;
99         u8 ext_info;
100         u8 pacing;
101         /* Refer to #define from module_type[ICE_MODULE_TYPE_TOTAL_BYTE] of
102          * ice_aqc_get_phy_caps structure
103          */
104         u8 module_type[ICE_MODULE_TYPE_TOTAL_BYTE];
105 };
106
107 /* Different reset sources for which a disable queue AQ call has to be made in
108  * order to clean the TX scheduler as a part of the reset
109  */
110 enum ice_disq_rst_src {
111         ICE_NO_RESET = 0,
112         ICE_VM_RESET,
113         ICE_VF_RESET,
114 };
115
116 /* PHY info such as phy_type, etc... */
117 struct ice_phy_info {
118         struct ice_link_status link_info;
119         struct ice_link_status link_info_old;
120         u64 phy_type_low;
121         enum ice_media_type media_type;
122         u8 get_link_info;
123 };
124
125 /* Common HW capabilities for SW use */
126 struct ice_hw_common_caps {
127         /* TX/RX queues */
128         u16 num_rxq;            /* Number/Total RX queues */
129         u16 rxq_first_id;       /* First queue ID for RX queues */
130         u16 num_txq;            /* Number/Total TX queues */
131         u16 txq_first_id;       /* First queue ID for TX queues */
132
133         /* MSI-X vectors */
134         u16 num_msix_vectors;
135         u16 msix_vector_first_id;
136
137         /* Max MTU for function or device */
138         u16 max_mtu;
139
140         /* Virtualization support */
141         u8 sr_iov_1_1;                  /* SR-IOV enabled */
142
143         /* RSS related capabilities */
144         u16 rss_table_size;             /* 512 for PFs and 64 for VFs */
145         u8 rss_table_entry_width;       /* RSS Entry width in bits */
146 };
147
148 /* Function specific capabilities */
149 struct ice_hw_func_caps {
150         struct ice_hw_common_caps common_cap;
151         u32 num_allocd_vfs;             /* Number of allocated VFs */
152         u32 vf_base_id;                 /* Logical ID of the first VF */
153         u32 guaranteed_num_vsi;
154 };
155
156 /* Device wide capabilities */
157 struct ice_hw_dev_caps {
158         struct ice_hw_common_caps common_cap;
159         u32 num_vfs_exposed;            /* Total number of VFs exposed */
160         u32 num_vsi_allocd_to_host;     /* Excluding EMP VSI */
161 };
162
163 /* MAC info */
164 struct ice_mac_info {
165         u8 lan_addr[ETH_ALEN];
166         u8 perm_addr[ETH_ALEN];
167 };
168
169 /* Reset types used to determine which kind of reset was requested. These
170  * defines match what the RESET_TYPE field of the GLGEN_RSTAT register.
171  * ICE_RESET_PFR does not match any RESET_TYPE field in the GLGEN_RSTAT register
172  * because its reset source is different than the other types listed.
173  */
174 enum ice_reset_req {
175         ICE_RESET_POR   = 0,
176         ICE_RESET_INVAL = 0,
177         ICE_RESET_CORER = 1,
178         ICE_RESET_GLOBR = 2,
179         ICE_RESET_EMPR  = 3,
180         ICE_RESET_PFR   = 4,
181 };
182
183 /* Bus parameters */
184 struct ice_bus_info {
185         u16 device;
186         u8 func;
187 };
188
189 /* Flow control (FC) parameters */
190 struct ice_fc_info {
191         enum ice_fc_mode current_mode;  /* FC mode in effect */
192         enum ice_fc_mode req_mode;      /* FC mode requested by caller */
193 };
194
195 /* NVM Information */
196 struct ice_nvm_info {
197         u32 eetrack;              /* NVM data version */
198         u32 oem_ver;              /* OEM version info */
199         u16 sr_words;             /* Shadow RAM size in words */
200         u16 ver;                  /* NVM package version */
201         u8 blank_nvm_mode;        /* is NVM empty (no FW present) */
202 };
203
204 /* Max number of port to queue branches w.r.t topology */
205 #define ICE_MAX_TRAFFIC_CLASS 8
206 #define ICE_TXSCHED_MAX_BRANCHES ICE_MAX_TRAFFIC_CLASS
207
208 struct ice_sched_node {
209         struct ice_sched_node *parent;
210         struct ice_sched_node *sibling; /* next sibling in the same layer */
211         struct ice_sched_node **children;
212         struct ice_aqc_txsched_elem_data info;
213         u32 agg_id;                     /* aggregator group id */
214         u16 vsi_handle;
215         u8 in_use;                      /* suspended or in use */
216         u8 tx_sched_layer;              /* Logical Layer (1-9) */
217         u8 num_children;
218         u8 tc_num;
219         u8 owner;
220 #define ICE_SCHED_NODE_OWNER_LAN        0
221 };
222
223 /* Access Macros for Tx Sched Elements data */
224 #define ICE_TXSCHED_GET_NODE_TEID(x) le32_to_cpu((x)->info.node_teid)
225
226 /* The aggregator type determines if identifier is for a VSI group,
227  * aggregator group, aggregator of queues, or queue group.
228  */
229 enum ice_agg_type {
230         ICE_AGG_TYPE_UNKNOWN = 0,
231         ICE_AGG_TYPE_VSI,
232         ICE_AGG_TYPE_AGG, /* aggregator */
233         ICE_AGG_TYPE_Q,
234         ICE_AGG_TYPE_QG
235 };
236
237 #define ICE_SCHED_DFLT_RL_PROF_ID       0
238 #define ICE_SCHED_DFLT_BW_WT            1
239
240 /* vsi type list entry to locate corresponding vsi/ag nodes */
241 struct ice_sched_vsi_info {
242         struct ice_sched_node *vsi_node[ICE_MAX_TRAFFIC_CLASS];
243         struct ice_sched_node *ag_node[ICE_MAX_TRAFFIC_CLASS];
244         struct list_head list_entry;
245         u16 max_lanq[ICE_MAX_TRAFFIC_CLASS];
246         u16 vsi_id;
247 };
248
249 /* driver defines the policy */
250 struct ice_sched_tx_policy {
251         u16 max_num_vsis;
252         u8 max_num_lan_qs_per_tc[ICE_MAX_TRAFFIC_CLASS];
253         u8 rdma_ena;
254 };
255
256 struct ice_port_info {
257         struct ice_sched_node *root;    /* Root Node per Port */
258         struct ice_hw *hw;              /* back pointer to hw instance */
259         u32 last_node_teid;             /* scheduler last node info */
260         u16 sw_id;                      /* Initial switch ID belongs to port */
261         u16 pf_vf_num;
262         u8 port_state;
263 #define ICE_SCHED_PORT_STATE_INIT       0x0
264 #define ICE_SCHED_PORT_STATE_READY      0x1
265         u16 dflt_tx_vsi_rule_id;
266         u16 dflt_tx_vsi_num;
267         u16 dflt_rx_vsi_rule_id;
268         u16 dflt_rx_vsi_num;
269         struct ice_fc_info fc;
270         struct ice_mac_info mac;
271         struct ice_phy_info phy;
272         struct mutex sched_lock;        /* protect access to TXSched tree */
273         struct list_head agg_list;      /* lists all aggregator */
274         u8 lport;
275 #define ICE_LPORT_MASK          0xff
276         u8 is_vf;
277 };
278
279 struct ice_switch_info {
280         struct list_head vsi_list_map_head;
281         struct ice_sw_recipe *recp_list;
282 };
283
284 /* FW logging configuration */
285 struct ice_fw_log_evnt {
286         u8 cfg : 4;     /* New event enables to configure */
287         u8 cur : 4;     /* Current/active event enables */
288 };
289
290 struct ice_fw_log_cfg {
291         u8 cq_en : 1;    /* FW logging is enabled via the control queue */
292         u8 uart_en : 1;  /* FW logging is enabled via UART for all PFs */
293         u8 actv_evnts;   /* Cumulation of currently enabled log events */
294
295 #define ICE_FW_LOG_EVNT_INFO    (ICE_AQC_FW_LOG_INFO_EN >> ICE_AQC_FW_LOG_EN_S)
296 #define ICE_FW_LOG_EVNT_INIT    (ICE_AQC_FW_LOG_INIT_EN >> ICE_AQC_FW_LOG_EN_S)
297 #define ICE_FW_LOG_EVNT_FLOW    (ICE_AQC_FW_LOG_FLOW_EN >> ICE_AQC_FW_LOG_EN_S)
298 #define ICE_FW_LOG_EVNT_ERR     (ICE_AQC_FW_LOG_ERR_EN >> ICE_AQC_FW_LOG_EN_S)
299         struct ice_fw_log_evnt evnts[ICE_AQC_FW_LOG_ID_MAX];
300 };
301
302 /* Port hardware description */
303 struct ice_hw {
304         u8 __iomem *hw_addr;
305         void *back;
306         struct ice_aqc_layer_props *layer_info;
307         struct ice_port_info *port_info;
308         u64 debug_mask;         /* bitmap for debug mask */
309         enum ice_mac_type mac_type;
310
311         /* pci info */
312         u16 device_id;
313         u16 vendor_id;
314         u16 subsystem_device_id;
315         u16 subsystem_vendor_id;
316         u8 revision_id;
317
318         u8 pf_id;               /* device profile info */
319
320         /* TX Scheduler values */
321         u16 num_tx_sched_layers;
322         u16 num_tx_sched_phys_layers;
323         u8 flattened_layers;
324         u8 max_cgds;
325         u8 sw_entry_point_layer;
326         u16 max_children[ICE_AQC_TOPO_MAX_LEVEL_NUM];
327
328         struct ice_vsi_ctx *vsi_ctx[ICE_MAX_VSI];
329         u8 evb_veb;             /* true for VEB, false for VEPA */
330         u8 reset_ongoing;       /* true if hw is in reset, false otherwise */
331         struct ice_bus_info bus;
332         struct ice_nvm_info nvm;
333         struct ice_hw_dev_caps dev_caps;        /* device capabilities */
334         struct ice_hw_func_caps func_caps;      /* function capabilities */
335
336         struct ice_switch_info *switch_info;    /* switch filter lists */
337
338         /* Control Queue info */
339         struct ice_ctl_q_info adminq;
340         struct ice_ctl_q_info mailboxq;
341
342         u8 api_branch;          /* API branch version */
343         u8 api_maj_ver;         /* API major version */
344         u8 api_min_ver;         /* API minor version */
345         u8 api_patch;           /* API patch version */
346         u8 fw_branch;           /* firmware branch version */
347         u8 fw_maj_ver;          /* firmware major version */
348         u8 fw_min_ver;          /* firmware minor version */
349         u8 fw_patch;            /* firmware patch version */
350         u32 fw_build;           /* firmware build number */
351
352         struct ice_fw_log_cfg fw_log;
353
354 /* Device max aggregate bandwidths corresponding to the GL_PWR_MODE_CTL
355  * register. Used for determining the itr/intrl granularity during
356  * initialization.
357  */
358 #define ICE_MAX_AGG_BW_200G     0x0
359 #define ICE_MAX_AGG_BW_100G     0X1
360 #define ICE_MAX_AGG_BW_50G      0x2
361 #define ICE_MAX_AGG_BW_25G      0x3
362         /* ITR granularity for different speeds */
363 #define ICE_ITR_GRAN_ABOVE_25   2
364 #define ICE_ITR_GRAN_MAX_25     4
365         /* ITR granularity in 1 us */
366         u8 itr_gran;
367         /* INTRL granularity for different speeds */
368 #define ICE_INTRL_GRAN_ABOVE_25 4
369 #define ICE_INTRL_GRAN_MAX_25   8
370         /* INTRL granularity in 1 us */
371         u8 intrl_gran;
372
373         u8 ucast_shared;        /* true if VSIs can share unicast addr */
374
375 };
376
377 /* Statistics collected by each port, VSI, VEB, and S-channel */
378 struct ice_eth_stats {
379         u64 rx_bytes;                   /* gorc */
380         u64 rx_unicast;                 /* uprc */
381         u64 rx_multicast;               /* mprc */
382         u64 rx_broadcast;               /* bprc */
383         u64 rx_discards;                /* rdpc */
384         u64 rx_unknown_protocol;        /* rupp */
385         u64 tx_bytes;                   /* gotc */
386         u64 tx_unicast;                 /* uptc */
387         u64 tx_multicast;               /* mptc */
388         u64 tx_broadcast;               /* bptc */
389         u64 tx_discards;                /* tdpc */
390         u64 tx_errors;                  /* tepc */
391 };
392
393 /* Statistics collected by the MAC */
394 struct ice_hw_port_stats {
395         /* eth stats collected by the port */
396         struct ice_eth_stats eth;
397         /* additional port specific stats */
398         u64 tx_dropped_link_down;       /* tdold */
399         u64 crc_errors;                 /* crcerrs */
400         u64 illegal_bytes;              /* illerrc */
401         u64 error_bytes;                /* errbc */
402         u64 mac_local_faults;           /* mlfc */
403         u64 mac_remote_faults;          /* mrfc */
404         u64 rx_len_errors;              /* rlec */
405         u64 link_xon_rx;                /* lxonrxc */
406         u64 link_xoff_rx;               /* lxoffrxc */
407         u64 link_xon_tx;                /* lxontxc */
408         u64 link_xoff_tx;               /* lxofftxc */
409         u64 rx_size_64;                 /* prc64 */
410         u64 rx_size_127;                /* prc127 */
411         u64 rx_size_255;                /* prc255 */
412         u64 rx_size_511;                /* prc511 */
413         u64 rx_size_1023;               /* prc1023 */
414         u64 rx_size_1522;               /* prc1522 */
415         u64 rx_size_big;                /* prc9522 */
416         u64 rx_undersize;               /* ruc */
417         u64 rx_fragments;               /* rfc */
418         u64 rx_oversize;                /* roc */
419         u64 rx_jabber;                  /* rjc */
420         u64 tx_size_64;                 /* ptc64 */
421         u64 tx_size_127;                /* ptc127 */
422         u64 tx_size_255;                /* ptc255 */
423         u64 tx_size_511;                /* ptc511 */
424         u64 tx_size_1023;               /* ptc1023 */
425         u64 tx_size_1522;               /* ptc1522 */
426         u64 tx_size_big;                /* ptc9522 */
427 };
428
429 /* Checksum and Shadow RAM pointers */
430 #define ICE_SR_NVM_DEV_STARTER_VER      0x18
431 #define ICE_SR_NVM_EETRACK_LO           0x2D
432 #define ICE_SR_NVM_EETRACK_HI           0x2E
433 #define ICE_NVM_VER_LO_SHIFT            0
434 #define ICE_NVM_VER_LO_MASK             (0xff << ICE_NVM_VER_LO_SHIFT)
435 #define ICE_NVM_VER_HI_SHIFT            12
436 #define ICE_NVM_VER_HI_MASK             (0xf << ICE_NVM_VER_HI_SHIFT)
437 #define ICE_OEM_VER_PATCH_SHIFT         0
438 #define ICE_OEM_VER_PATCH_MASK          (0xff << ICE_OEM_VER_PATCH_SHIFT)
439 #define ICE_OEM_VER_BUILD_SHIFT         8
440 #define ICE_OEM_VER_BUILD_MASK          (0xffff << ICE_OEM_VER_BUILD_SHIFT)
441 #define ICE_OEM_VER_SHIFT               24
442 #define ICE_OEM_VER_MASK                (0xff << ICE_OEM_VER_SHIFT)
443 #define ICE_SR_SECTOR_SIZE_IN_WORDS     0x800
444 #define ICE_SR_WORDS_IN_1KB             512
445
446 /* Hash redirection LUT for VSI - maximum array size */
447 #define ICE_VSIQF_HLUT_ARRAY_SIZE       ((VSIQF_HLUT_MAX_INDEX + 1) * 4)
448
449 #endif /* _ICE_TYPE_H_ */