1 /*
2 * Copyright (c) 2017-2018 Cavium, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #ifndef __ECORE_H
30 #define __ECORE_H
31
32 #include "ecore_status.h"
33 #include "ecore_hsi_common.h"
34 #include "ecore_hsi_debug_tools.h"
35 #include "ecore_hsi_init_func.h"
36 #include "ecore_hsi_init_tool.h"
37 #include "ecore_proto_if.h"
38 #include "mcp_public.h"
39
40 #define ECORE_MAJOR_VERSION 8
41 #define ECORE_MINOR_VERSION 33
42 #define ECORE_REVISION_VERSION 5
43 #define ECORE_ENGINEERING_VERSION 0
44
45 #define ECORE_VERSION \
46 ((ECORE_MAJOR_VERSION << 24) | (ECORE_MINOR_VERSION << 16) | \
47 (ECORE_REVISION_VERSION << 8) | ECORE_ENGINEERING_VERSION)
48
49 #define STORM_FW_VERSION \
50 ((FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | \
51 (FW_REVISION_VERSION << 8) | FW_ENGINEERING_VERSION)
52
53 #define MAX_HWFNS_PER_DEVICE 2
54 #define NAME_SIZE 16
55 #define ARRAY_DECL static const
56 #define ECORE_WFQ_UNIT 100
57
58 /* Constants */
59 #define ECORE_WID_SIZE (1024)
60 #define ECORE_MIN_WIDS (4)
61
62 /* Configurable */
63 #define ECORE_PF_DEMS_SIZE (4)
64
65 /* cau states */
66 enum ecore_coalescing_mode {
67 ECORE_COAL_MODE_DISABLE,
68 ECORE_COAL_MODE_ENABLE
69 };
70
71 enum ecore_nvm_cmd {
72 ECORE_PUT_FILE_BEGIN = DRV_MSG_CODE_NVM_PUT_FILE_BEGIN,
73 ECORE_PUT_FILE_DATA = DRV_MSG_CODE_NVM_PUT_FILE_DATA,
74 ECORE_NVM_READ_NVRAM = DRV_MSG_CODE_NVM_READ_NVRAM,
75 ECORE_NVM_WRITE_NVRAM = DRV_MSG_CODE_NVM_WRITE_NVRAM,
76 ECORE_NVM_DEL_FILE = DRV_MSG_CODE_NVM_DEL_FILE,
77 ECORE_EXT_PHY_FW_UPGRADE = DRV_MSG_CODE_EXT_PHY_FW_UPGRADE,
78 ECORE_NVM_SET_SECURE_MODE = DRV_MSG_CODE_SET_SECURE_MODE,
79 ECORE_PHY_RAW_READ = DRV_MSG_CODE_PHY_RAW_READ,
80 ECORE_PHY_RAW_WRITE = DRV_MSG_CODE_PHY_RAW_WRITE,
81 ECORE_PHY_CORE_READ = DRV_MSG_CODE_PHY_CORE_READ,
82 ECORE_PHY_CORE_WRITE = DRV_MSG_CODE_PHY_CORE_WRITE,
83 ECORE_ENCRYPT_PASSWORD = DRV_MSG_CODE_ENCRYPT_PASSWORD,
84 ECORE_GET_MCP_NVM_RESP = 0xFFFFFF00
85 };
86
87 #ifndef LINUX_REMOVE
88 #if !defined(CONFIG_ECORE_L2) && !defined(CONFIG_ECORE_ROCE) && \
89 !defined(CONFIG_ECORE_FCOE) && !defined(CONFIG_ECORE_ISCSI) && \
90 !defined(CONFIG_ECORE_IWARP)
91 #define CONFIG_ECORE_L2
92 #define CONFIG_ECORE_SRIOV
93 #define CONFIG_ECORE_ROCE
94 #define CONFIG_ECORE_IWARP
95 #define CONFIG_ECORE_FCOE
96 #define CONFIG_ECORE_ISCSI
97 #define CONFIG_ECORE_LL2
98 #endif
99 #endif
100
101 /* helpers */
102 #ifndef __EXTRACT__LINUX__IF__
103 #define MASK_FIELD(_name, _value) \
104 ((_value) &= (_name##_MASK))
105
106 #define FIELD_VALUE(_name, _value) \
107 ((_value & _name##_MASK) << _name##_SHIFT)
108
109 #define SET_FIELD(value, name, flag) \
110 do { \
111 (value) &= ~(name##_MASK << name##_SHIFT); \
112 (value) |= ((((u64)flag) & (u64)name##_MASK) << (name##_SHIFT));\
113 } while (0)
114
115 #define GET_FIELD(value, name) \
116 (((value) >> (name##_SHIFT)) & name##_MASK)
117
118 #define GET_MFW_FIELD(name, field) \
119 (((name) & (field ## _MASK)) >> (field ## _OFFSET))
120
121 #define SET_MFW_FIELD(name, field, value) \
122 do { \
123 (name) &= ~(field ## _MASK); \
124 (name) |= (((value) << (field ## _OFFSET)) & (field ## _MASK)); \
125 } while (0)
126 #endif
127
DB_ADDR(u32 cid,u32 DEMS)128 static OSAL_INLINE u32 DB_ADDR(u32 cid, u32 DEMS)
129 {
130 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
131 (cid * ECORE_PF_DEMS_SIZE);
132
133 return db_addr;
134 }
135
DB_ADDR_VF(u32 cid,u32 DEMS)136 static OSAL_INLINE u32 DB_ADDR_VF(u32 cid, u32 DEMS)
137 {
138 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
139 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
140
141 return db_addr;
142 }
143
144 #define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
145 ((sizeof(type_name) + (u32)(1<<(p_hwfn->p_dev->cache_shift))-1) & \
146 ~((1<<(p_hwfn->p_dev->cache_shift))-1))
147
148 #ifndef LINUX_REMOVE
149 #ifndef U64_HI
150 #define U64_HI(val) ((u32)(((u64)(val)) >> 32))
151 #endif
152
153 #ifndef U64_LO
154 #define U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
155 #endif
156 #endif
157
158 #ifndef __EXTRACT__LINUX__IF__
159 #ifndef UEFI
160 /* Debug print definitions */
161 #define DP_ERR(p_dev, fmt, ...) \
162 do { \
163 PRINT_ERR((p_dev)->dp_ctx, "[%s:%d(%s)]" fmt, \
164 __func__, __LINE__, \
165 (p_dev)->name ? (p_dev)->name : "", \
166 ##__VA_ARGS__); \
167 } while (0)
168
169 #define DP_NOTICE(p_dev, is_assert, fmt, ...) \
170 do { \
171 if (OSAL_UNLIKELY((p_dev)->dp_level <= ECORE_LEVEL_NOTICE)) { \
172 PRINT((p_dev)->dp_ctx, "[%s:%d(%s)]" fmt, \
173 __func__, __LINE__, \
174 (p_dev)->name ? (p_dev)->name : "", \
175 ##__VA_ARGS__); \
176 OSAL_ASSERT(!is_assert); \
177 } \
178 } while (0)
179
180 #define DP_INFO(p_dev, fmt, ...) \
181 do { \
182 if (OSAL_UNLIKELY((p_dev)->dp_level <= ECORE_LEVEL_INFO)) { \
183 PRINT((p_dev)->dp_ctx, "[%s:%d(%s)]" fmt, \
184 __func__, __LINE__, \
185 (p_dev)->name ? (p_dev)->name : "", \
186 ##__VA_ARGS__); \
187 } \
188 } while (0)
189
190 #define DP_VERBOSE(p_dev, module, fmt, ...) \
191 do { \
192 if (OSAL_UNLIKELY(((p_dev)->dp_level <= ECORE_LEVEL_VERBOSE) && \
193 ((p_dev)->dp_module & module))) { \
194 PRINT((p_dev)->dp_ctx, "[%s:%d(%s)]" fmt, \
195 __func__, __LINE__, \
196 (p_dev)->name ? (p_dev)->name : "", \
197 ##__VA_ARGS__); \
198 } \
199 } while (0)
200 #endif
201
202 enum DP_LEVEL {
203 ECORE_LEVEL_VERBOSE = 0x0,
204 ECORE_LEVEL_INFO = 0x1,
205 ECORE_LEVEL_NOTICE = 0x2,
206 ECORE_LEVEL_ERR = 0x3,
207 };
208
209 #define ECORE_LOG_LEVEL_SHIFT (30)
210 #define ECORE_LOG_VERBOSE_MASK (0x3fffffff)
211 #define ECORE_LOG_INFO_MASK (0x40000000)
212 #define ECORE_LOG_NOTICE_MASK (0x80000000)
213
214 enum DP_MODULE {
215 #ifndef LINUX_REMOVE
216 ECORE_MSG_DRV = 0x0001,
217 ECORE_MSG_PROBE = 0x0002,
218 ECORE_MSG_LINK = 0x0004,
219 ECORE_MSG_TIMER = 0x0008,
220 ECORE_MSG_IFDOWN = 0x0010,
221 ECORE_MSG_IFUP = 0x0020,
222 ECORE_MSG_RX_ERR = 0x0040,
223 ECORE_MSG_TX_ERR = 0x0080,
224 ECORE_MSG_TX_QUEUED = 0x0100,
225 ECORE_MSG_INTR = 0x0200,
226 ECORE_MSG_TX_DONE = 0x0400,
227 ECORE_MSG_RX_STATUS = 0x0800,
228 ECORE_MSG_PKTDATA = 0x1000,
229 ECORE_MSG_HW = 0x2000,
230 ECORE_MSG_WOL = 0x4000,
231 #endif
232 ECORE_MSG_SPQ = 0x10000,
233 ECORE_MSG_STATS = 0x20000,
234 ECORE_MSG_DCB = 0x40000,
235 ECORE_MSG_IOV = 0x80000,
236 ECORE_MSG_SP = 0x100000,
237 ECORE_MSG_STORAGE = 0x200000,
238 ECORE_MSG_OOO = 0x200000,
239 ECORE_MSG_CXT = 0x800000,
240 ECORE_MSG_LL2 = 0x1000000,
241 ECORE_MSG_ILT = 0x2000000,
242 ECORE_MSG_RDMA = 0x4000000,
243 ECORE_MSG_DEBUG = 0x8000000,
244 /* to be added...up to 0x8000000 */
245 };
246 #endif
247
248 #define for_each_hwfn(p_dev, i) for (i = 0; i < p_dev->num_hwfns; i++)
249
250 #define D_TRINE(val, cond1, cond2, true1, true2, def) \
251 (val == (cond1) ? true1 : \
252 (val == (cond2) ? true2 : def))
253
254 /* forward */
255 struct ecore_ptt_pool;
256 struct ecore_spq;
257 struct ecore_sb_info;
258 struct ecore_sb_attn_info;
259 struct ecore_cxt_mngr;
260 struct ecore_dma_mem;
261 struct ecore_sb_sp_info;
262 struct ecore_ll2_info;
263 struct ecore_l2_info;
264 struct ecore_igu_info;
265 struct ecore_mcp_info;
266 struct ecore_dcbx_info;
267 struct ecore_llh_info;
268
269 struct ecore_rt_data {
270 u32 *init_val;
271 bool *b_valid;
272 };
273
274 enum ecore_tunn_mode {
275 ECORE_MODE_L2GENEVE_TUNN,
276 ECORE_MODE_IPGENEVE_TUNN,
277 ECORE_MODE_L2GRE_TUNN,
278 ECORE_MODE_IPGRE_TUNN,
279 ECORE_MODE_VXLAN_TUNN,
280 };
281
282 enum ecore_tunn_clss {
283 ECORE_TUNN_CLSS_MAC_VLAN,
284 ECORE_TUNN_CLSS_MAC_VNI,
285 ECORE_TUNN_CLSS_INNER_MAC_VLAN,
286 ECORE_TUNN_CLSS_INNER_MAC_VNI,
287 ECORE_TUNN_CLSS_MAC_VLAN_DUAL_STAGE,
288 MAX_ECORE_TUNN_CLSS,
289 };
290
291 struct ecore_tunn_update_type {
292 bool b_update_mode;
293 bool b_mode_enabled;
294 enum ecore_tunn_clss tun_cls;
295 };
296
297 struct ecore_tunn_update_udp_port {
298 bool b_update_port;
299 u16 port;
300 };
301
302 struct ecore_tunnel_info {
303 struct ecore_tunn_update_type vxlan;
304 struct ecore_tunn_update_type l2_geneve;
305 struct ecore_tunn_update_type ip_geneve;
306 struct ecore_tunn_update_type l2_gre;
307 struct ecore_tunn_update_type ip_gre;
308
309 struct ecore_tunn_update_udp_port vxlan_port;
310 struct ecore_tunn_update_udp_port geneve_port;
311
312 bool b_update_rx_cls;
313 bool b_update_tx_cls;
314 };
315
316 /* The PCI personality is not quite synonymous to protocol ID:
317 * 1. All personalities need CORE connections
318 * 2. The Ethernet personality may support also the RoCE/iWARP protocol
319 */
320 enum ecore_pci_personality {
321 ECORE_PCI_ETH,
322 ECORE_PCI_FCOE,
323 ECORE_PCI_ISCSI,
324 ECORE_PCI_ETH_ROCE,
325 ECORE_PCI_ETH_IWARP,
326 ECORE_PCI_ETH_RDMA,
327 ECORE_PCI_DEFAULT /* default in shmem */
328 };
329
330 /* All VFs are symetric, all counters are PF + all VFs */
331 struct ecore_qm_iids {
332 u32 cids;
333 u32 vf_cids;
334 u32 tids;
335 };
336
337 /* The PCI relax ordering is either taken care by management FW or can be
338 * enable/disable by ecore client.
339 */
340 enum ecore_pci_rlx_odr {
341 ECORE_DEFAULT_RLX_ODR,
342 ECORE_ENABLE_RLX_ODR,
343 ECORE_DISABLE_RLX_ODR
344 };
345
346 #define MAX_PF_PER_PORT 8
347
348 /* HW / FW resources, output of features supported below, most information
349 * is received from MFW.
350 */
351 enum ecore_resources {
352 ECORE_L2_QUEUE,
353 ECORE_VPORT,
354 ECORE_RSS_ENG,
355 ECORE_PQ,
356 ECORE_RL,
357 ECORE_MAC,
358 ECORE_VLAN,
359 ECORE_RDMA_CNQ_RAM,
360 ECORE_ILT,
361 ECORE_LL2_QUEUE,
362 ECORE_CMDQS_CQS,
363 ECORE_RDMA_STATS_QUEUE,
364 ECORE_BDQ,
365
366 /* This is needed only internally for matching against the IGU.
367 * In case of legacy MFW, would be set to `0'.
368 */
369 ECORE_SB,
370
371 ECORE_MAX_RESC,
372 };
373
374 /* Features that require resources, given as input to the resource management
375 * algorithm, the output are the resources above
376 */
377 enum ecore_feature {
378 ECORE_PF_L2_QUE,
379 ECORE_PF_TC,
380 ECORE_VF,
381 ECORE_EXTRA_VF_QUE,
382 ECORE_VMQ,
383 ECORE_RDMA_CNQ,
384 ECORE_ISCSI_CQ,
385 ECORE_FCOE_CQ,
386 ECORE_VF_L2_QUE,
387 ECORE_MAX_FEATURES,
388 };
389
390 enum ecore_port_mode {
391 ECORE_PORT_MODE_DE_2X40G,
392 ECORE_PORT_MODE_DE_2X50G,
393 ECORE_PORT_MODE_DE_1X100G,
394 ECORE_PORT_MODE_DE_4X10G_F,
395 ECORE_PORT_MODE_DE_4X10G_E,
396 ECORE_PORT_MODE_DE_4X20G,
397 ECORE_PORT_MODE_DE_1X40G,
398 ECORE_PORT_MODE_DE_2X25G,
399 ECORE_PORT_MODE_DE_1X25G,
400 ECORE_PORT_MODE_DE_4X25G,
401 ECORE_PORT_MODE_DE_2X10G,
402 };
403
404 enum ecore_dev_cap {
405 ECORE_DEV_CAP_ETH,
406 ECORE_DEV_CAP_FCOE,
407 ECORE_DEV_CAP_ISCSI,
408 ECORE_DEV_CAP_ROCE,
409 ECORE_DEV_CAP_IWARP
410 };
411
412 #ifndef __EXTRACT__LINUX__IF__
413 enum ecore_hw_err_type {
414 ECORE_HW_ERR_FAN_FAIL,
415 ECORE_HW_ERR_MFW_RESP_FAIL,
416 ECORE_HW_ERR_HW_ATTN,
417 ECORE_HW_ERR_DMAE_FAIL,
418 ECORE_HW_ERR_RAMROD_FAIL,
419 ECORE_HW_ERR_FW_ASSERT,
420 };
421 #endif
422
423 enum ecore_wol_support {
424 ECORE_WOL_SUPPORT_NONE,
425 ECORE_WOL_SUPPORT_PME,
426 };
427
428 enum ecore_db_rec_exec {
429 DB_REC_DRY_RUN,
430 DB_REC_REAL_DEAL,
431 DB_REC_ONCE,
432 };
433
434 struct ecore_hw_info {
435 /* PCI personality */
436 enum ecore_pci_personality personality;
437 #define ECORE_IS_RDMA_PERSONALITY(dev) \
438 ((dev)->hw_info.personality == ECORE_PCI_ETH_ROCE || \
439 (dev)->hw_info.personality == ECORE_PCI_ETH_IWARP || \
440 (dev)->hw_info.personality == ECORE_PCI_ETH_RDMA)
441 #define ECORE_IS_ROCE_PERSONALITY(dev) \
442 ((dev)->hw_info.personality == ECORE_PCI_ETH_ROCE || \
443 (dev)->hw_info.personality == ECORE_PCI_ETH_RDMA)
444 #define ECORE_IS_IWARP_PERSONALITY(dev) \
445 ((dev)->hw_info.personality == ECORE_PCI_ETH_IWARP || \
446 (dev)->hw_info.personality == ECORE_PCI_ETH_RDMA)
447 #define ECORE_IS_L2_PERSONALITY(dev) \
448 ((dev)->hw_info.personality == ECORE_PCI_ETH || \
449 ECORE_IS_RDMA_PERSONALITY(dev))
450 #define ECORE_IS_FCOE_PERSONALITY(dev) \
451 ((dev)->hw_info.personality == ECORE_PCI_FCOE)
452 #define ECORE_IS_ISCSI_PERSONALITY(dev) \
453 ((dev)->hw_info.personality == ECORE_PCI_ISCSI)
454
455 /* Resource Allocation scheme results */
456 u32 resc_start[ECORE_MAX_RESC];
457 u32 resc_num[ECORE_MAX_RESC];
458 u32 feat_num[ECORE_MAX_FEATURES];
459
460 #define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
461 #define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
462 #define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
463 RESC_NUM(_p_hwfn, resc))
464 #define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
465
466 /* Amount of traffic classes HW supports */
467 u8 num_hw_tc;
468
469 /* Amount of TCs which should be active according to DCBx or upper layer driver configuration */
470 u8 num_active_tc;
471
472 /* The traffic class used by PF for it's offloaded protocol */
473 u8 offload_tc;
474
475 u32 concrete_fid;
476 u16 opaque_fid;
477 u16 ovlan;
478 u32 part_num[4];
479
480 #ifndef ETH_ALEN
481 #define ETH_ALEN 6 /* @@@ TBD - define somewhere else for Windows */
482 #endif
483 unsigned char hw_mac_addr[ETH_ALEN];
484
485 u16 num_iscsi_conns;
486 u16 num_fcoe_conns;
487
488 struct ecore_igu_info *p_igu_info;
489 /* Sriov */
490 u8 max_chains_per_vf;
491
492 u32 port_mode;
493 u32 hw_mode;
494 unsigned long device_capabilities;
495
496 #ifndef __EXTRACT__LINUX__THROW__
497 /* Default DCBX mode */
498 u8 dcbx_mode;
499 #endif
500
501 u16 mtu;
502
503 enum ecore_wol_support b_wol_support;
504 };
505
506 /* maximun size of read/write commands (HW limit) */
507 #define DMAE_MAX_RW_SIZE 0x2000
508
509 struct ecore_dmae_info {
510 /* Spinlock for synchronizing access to functions */
511 osal_spinlock_t lock;
512
513 bool b_mem_ready;
514
515 u8 channel;
516
517 dma_addr_t completion_word_phys_addr;
518
519 /* The memory location where the DMAE writes the completion
520 * value when an operation is finished on this context.
521 */
522 u32 *p_completion_word;
523
524 dma_addr_t intermediate_buffer_phys_addr;
525
526 /* An intermediate buffer for DMAE operations that use virtual
527 * addresses - data is DMA'd to/from this buffer and then
528 * memcpy'd to/from the virtual address
529 */
530 u32 *p_intermediate_buffer;
531
532 dma_addr_t dmae_cmd_phys_addr;
533 struct dmae_cmd *p_dmae_cmd;
534 };
535
536 struct ecore_wfq_data {
537 u32 default_min_speed; /* When wfq feature is not configured */
538 u32 min_speed; /* when feature is configured for any 1 vport */
539 bool configured;
540 };
541
542 struct ecore_qm_info {
543 struct init_qm_pq_params *qm_pq_params;
544 struct init_qm_vport_params *qm_vport_params;
545 struct init_qm_port_params *qm_port_params;
546 u16 start_pq;
547 u8 start_vport;
548 u16 pure_lb_pq;
549 u16 offload_pq;
550 u16 low_latency_pq;
551 u16 pure_ack_pq;
552 u16 ooo_pq;
553 u16 first_vf_pq;
554 u16 first_mcos_pq;
555 u16 first_rl_pq;
556 u16 num_pqs;
557 u16 num_vf_pqs;
558 u8 num_vports;
559 u8 max_phys_tcs_per_port;
560 u8 ooo_tc;
561 bool pf_rl_en;
562 bool pf_wfq_en;
563 bool vport_rl_en;
564 bool vport_wfq_en;
565 u8 pf_wfq;
566 u32 pf_rl;
567 struct ecore_wfq_data *wfq_data;
568 u8 num_pf_rls;
569 };
570
571 struct ecore_db_recovery_info {
572 osal_list_t list;
573 osal_spinlock_t lock;
574 u32 db_recovery_counter;
575 };
576
577 struct storm_stats {
578 u32 address;
579 u32 len;
580 };
581
582 struct ecore_fw_data {
583 #ifdef CONFIG_ECORE_BINARY_FW
584 struct fw_ver_info *fw_ver_info;
585 #endif
586 const u8 *modes_tree_buf;
587 union init_op *init_ops;
588 const u32 *arr_data;
589 u32 init_ops_size;
590 };
591
592 enum ecore_mf_mode_bit {
593 /* Supports PF-classification based on tag */
594 ECORE_MF_OVLAN_CLSS,
595
596 /* Supports PF-classification based on MAC */
597 ECORE_MF_LLH_MAC_CLSS,
598
599 /* Supports PF-classification based on protocol type */
600 ECORE_MF_LLH_PROTO_CLSS,
601
602 /* Requires a default PF to be set */
603 ECORE_MF_NEED_DEF_PF,
604
605 /* Allow LL2 to multicast/broadcast */
606 ECORE_MF_LL2_NON_UNICAST,
607
608 /* Allow Cross-PF [& child VFs] Tx-switching */
609 ECORE_MF_INTER_PF_SWITCH,
610
611 /* TODO - if we ever re-utilize any of this logic, we can rename */
612 ECORE_MF_UFP_SPECIFIC,
613
614 ECORE_MF_DISABLE_ARFS,
615
616 /* Use vlan for steering */
617 ECORE_MF_8021Q_TAGGING,
618
619 /* Use stag for steering */
620 ECORE_MF_8021AD_TAGGING,
621 };
622
623 enum ecore_ufp_mode {
624 ECORE_UFP_MODE_ETS,
625 ECORE_UFP_MODE_VNIC_BW,
626 ECORE_UFP_MODE_UNKNOWN
627 };
628
629 enum ecore_ufp_pri_type {
630 ECORE_UFP_PRI_OS,
631 ECORE_UFP_PRI_VNIC,
632 ECORE_UFP_PRI_UNKNOWN
633 };
634
635 struct ecore_ufp_info {
636 enum ecore_ufp_pri_type pri_type;
637 enum ecore_ufp_mode mode;
638 u8 tc;
639 };
640
641 enum BAR_ID {
642 BAR_ID_0, /* used for GRC */
643 BAR_ID_1 /* Used for doorbells */
644 };
645
646 struct ecore_hwfn {
647 struct ecore_dev *p_dev;
648 u8 my_id; /* ID inside the PF */
649 #define IS_LEAD_HWFN(edev) (!((edev)->my_id))
650 u8 rel_pf_id; /* Relative to engine*/
651 u8 abs_pf_id;
652 #define ECORE_PATH_ID(_p_hwfn) \
653 (ECORE_IS_BB((_p_hwfn)->p_dev) ? ((_p_hwfn)->abs_pf_id & 1) : 0)
654 u8 port_id;
655 bool b_active;
656
657 u32 dp_module;
658 u8 dp_level;
659 char name[NAME_SIZE];
660 void *dp_ctx;
661
662 bool hw_init_done;
663
664 u8 num_funcs_on_engine;
665 u8 enabled_func_idx;
666
667 /* BAR access */
668 void OSAL_IOMEM *regview;
669 void OSAL_IOMEM *doorbells;
670 u64 db_phys_addr;
671 unsigned long db_size;
672
673 #ifndef LINUX_REMOVE
674 u64 reg_offset;
675 u64 db_offset;
676 #endif
677
678 /* PTT pool */
679 struct ecore_ptt_pool *p_ptt_pool;
680
681 /* HW info */
682 struct ecore_hw_info hw_info;
683
684 /* rt_array (for init-tool) */
685 struct ecore_rt_data rt_data;
686
687 /* SPQ */
688 struct ecore_spq *p_spq;
689
690 /* EQ */
691 struct ecore_eq *p_eq;
692
693 /* Consolidate Q*/
694 struct ecore_consq *p_consq;
695
696 /* Slow-Path definitions */
697 osal_dpc_t sp_dpc;
698 bool b_sp_dpc_enabled;
699
700 struct ecore_ptt *p_main_ptt;
701 struct ecore_ptt *p_dpc_ptt;
702
703 /* PTP will be used only by the leading function.
704 * Usage of all PTP-apis should be synchronized as result.
705 */
706 struct ecore_ptt *p_ptp_ptt;
707
708 struct ecore_sb_sp_info *p_sp_sb;
709 struct ecore_sb_attn_info *p_sb_attn;
710
711 /* Protocol related */
712 bool using_ll2;
713 struct ecore_ll2_info *p_ll2_info;
714 struct ecore_ooo_info *p_ooo_info;
715 struct ecore_iscsi_info *p_iscsi_info;
716 struct ecore_fcoe_info *p_fcoe_info;
717 struct ecore_rdma_info *p_rdma_info;
718 struct ecore_pf_params pf_params;
719
720 bool b_rdma_enabled_in_prs;
721 u32 rdma_prs_search_reg;
722
723 struct ecore_cxt_mngr *p_cxt_mngr;
724
725 /* Flag indicating whether interrupts are enabled or not*/
726 bool b_int_enabled;
727 bool b_int_requested;
728
729 /* True if the driver requests for the link */
730 bool b_drv_link_init;
731
732 struct ecore_vf_iov *vf_iov_info;
733 struct ecore_pf_iov *pf_iov_info;
734 struct ecore_mcp_info *mcp_info;
735 struct ecore_dcbx_info *p_dcbx_info;
736 struct ecore_ufp_info ufp_info;
737
738 struct ecore_dmae_info dmae_info;
739
740 /* QM init */
741 struct ecore_qm_info qm_info;
742
743 /* Buffer for unzipping firmware data */
744 #ifdef CONFIG_ECORE_ZIPPED_FW
745 void *unzip_buf;
746 #endif
747
748 struct dbg_tools_data dbg_info;
749
750 /* PWM region specific data */
751 u16 wid_count;
752 u32 dpi_size;
753 u32 dpi_count;
754 u32 dpi_start_offset; /* this is used to
755 * calculate th
756 * doorbell address
757 */
758
759 /* If one of the following is set then EDPM shouldn't be used */
760 u8 dcbx_no_edpm;
761 u8 db_bar_no_edpm;
762
763 /* L2-related */
764 struct ecore_l2_info *p_l2_info;
765
766 /* Mechanism for recovering from doorbell drop */
767 struct ecore_db_recovery_info db_recovery_info;
768 };
769
770 #ifndef __EXTRACT__LINUX__THROW__
771 enum ecore_mf_mode {
772 ECORE_MF_DEFAULT,
773 ECORE_MF_OVLAN,
774 ECORE_MF_NPAR,
775 ECORE_MF_UFP,
776 };
777 #endif
778
779 #ifndef __EXTRACT__LINUX__IF__
780 enum ecore_dev_type {
781 ECORE_DEV_TYPE_BB,
782 ECORE_DEV_TYPE_AH,
783 ECORE_DEV_TYPE_E5,
784 };
785 #endif
786
787 struct ecore_dev {
788 u32 dp_module;
789 u8 dp_level;
790 char name[NAME_SIZE];
791 void *dp_ctx;
792 void *ha;
793
794 enum ecore_dev_type type;
795 /* Translate type/revision combo into the proper conditions */
796 #define ECORE_IS_BB(dev) ((dev)->type == ECORE_DEV_TYPE_BB)
797 #define ECORE_IS_BB_A0(dev) (ECORE_IS_BB(dev) && CHIP_REV_IS_A0(dev))
798 #ifndef ASIC_ONLY
799 #define ECORE_IS_BB_B0(dev) ((ECORE_IS_BB(dev) && CHIP_REV_IS_B0(dev)) || \
800 (CHIP_REV_IS_TEDIBEAR(dev)))
801 #else
802 #define ECORE_IS_BB_B0(dev) (ECORE_IS_BB(dev) && CHIP_REV_IS_B0(dev))
803 #endif
804 #define ECORE_IS_AH(dev) ((dev)->type == ECORE_DEV_TYPE_AH)
805 #define ECORE_IS_K2(dev) ECORE_IS_AH(dev)
806 #define ECORE_IS_E4(dev) (ECORE_IS_BB(dev) || ECORE_IS_AH(dev))
807 #define ECORE_IS_E5(dev) ((dev)->type == ECORE_DEV_TYPE_E5)
808
809 #define ECORE_E5_MISSING_CODE OSAL_BUILD_BUG_ON(false)
810
811 u16 vendor_id;
812 u16 device_id;
813 #define ECORE_DEV_ID_MASK 0xff00
814 #define ECORE_DEV_ID_MASK_BB 0x1600
815 #define ECORE_DEV_ID_MASK_AH 0x8000
816 #define ECORE_DEV_ID_MASK_E5 0x8100
817
818 u16 chip_num;
819 #define CHIP_NUM_MASK 0xffff
820 #define CHIP_NUM_SHIFT 0
821
822 u8 chip_rev;
823 #define CHIP_REV_MASK 0xf
824 #define CHIP_REV_SHIFT 0
825 #ifndef ASIC_ONLY
826 #define CHIP_REV_IS_TEDIBEAR(_p_dev) ((_p_dev)->chip_rev == 0x5)
827 #define CHIP_REV_IS_EMUL_A0(_p_dev) ((_p_dev)->chip_rev == 0xe)
828 #define CHIP_REV_IS_EMUL_B0(_p_dev) ((_p_dev)->chip_rev == 0xc)
829 #define CHIP_REV_IS_EMUL(_p_dev) \
830 (CHIP_REV_IS_EMUL_A0(_p_dev) || CHIP_REV_IS_EMUL_B0(_p_dev))
831 #define CHIP_REV_IS_FPGA_A0(_p_dev) ((_p_dev)->chip_rev == 0xf)
832 #define CHIP_REV_IS_FPGA_B0(_p_dev) ((_p_dev)->chip_rev == 0xd)
833 #define CHIP_REV_IS_FPGA(_p_dev) \
834 (CHIP_REV_IS_FPGA_A0(_p_dev) || CHIP_REV_IS_FPGA_B0(_p_dev))
835 #define CHIP_REV_IS_SLOW(_p_dev) \
836 (CHIP_REV_IS_EMUL(_p_dev) || CHIP_REV_IS_FPGA(_p_dev))
837 #define CHIP_REV_IS_A0(_p_dev) \
838 (CHIP_REV_IS_EMUL_A0(_p_dev) || CHIP_REV_IS_FPGA_A0(_p_dev) || \
839 (!(_p_dev)->chip_rev && !(_p_dev)->chip_metal))
840 #define CHIP_REV_IS_B0(_p_dev) \
841 (CHIP_REV_IS_EMUL_B0(_p_dev) || CHIP_REV_IS_FPGA_B0(_p_dev) || \
842 ((_p_dev)->chip_rev == 1 && !(_p_dev)->chip_metal))
843 #define CHIP_REV_IS_ASIC(_p_dev) !CHIP_REV_IS_SLOW(_p_dev)
844 #else
845 #define CHIP_REV_IS_A0(_p_dev) \
846 (!(_p_dev)->chip_rev && !(_p_dev)->chip_metal)
847 #define CHIP_REV_IS_B0(_p_dev) \
848 ((_p_dev)->chip_rev == 1 && !(_p_dev)->chip_metal)
849 #endif
850
851 u8 chip_metal;
852 #define CHIP_METAL_MASK 0xff
853 #define CHIP_METAL_SHIFT 0
854
855 u8 chip_bond_id;
856 #define CHIP_BOND_ID_MASK 0xff
857 #define CHIP_BOND_ID_SHIFT 0
858
859 u8 num_engines;
860 u8 num_ports;
861 u8 num_ports_in_engine;
862 u8 num_funcs_in_port;
863
864 u8 path_id;
865
866 unsigned long mf_bits;
867 #ifndef __EXTRACT__LINUX__THROW__
868 enum ecore_mf_mode mf_mode;
869 #define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->p_dev)->mf_mode == ECORE_MF_DEFAULT)
870 #define IS_MF_SI(_p_hwfn) (((_p_hwfn)->p_dev)->mf_mode == ECORE_MF_NPAR)
871 #define IS_MF_SD(_p_hwfn) (((_p_hwfn)->p_dev)->mf_mode == ECORE_MF_OVLAN)
872 #endif
873
874 int pcie_width;
875 int pcie_speed;
876
877 /* Add MF related configuration */
878 u8 mcp_rev;
879 u8 boot_mode;
880
881 /* WoL related configurations */
882 u8 wol_config;
883 u8 wol_mac[ETH_ALEN];
884
885 u32 int_mode;
886 enum ecore_coalescing_mode int_coalescing_mode;
887 u16 rx_coalesce_usecs;
888 u16 tx_coalesce_usecs;
889
890 /* Start Bar offset of first hwfn */
891 void OSAL_IOMEM *regview;
892 void OSAL_IOMEM *doorbells;
893 u64 db_phys_addr;
894 unsigned long db_size;
895
896 /* PCI */
897 u8 cache_shift;
898
899 /* Init */
900 const struct iro *iro_arr;
901 #define IRO (p_hwfn->p_dev->iro_arr)
902
903 /* HW functions */
904 u8 num_hwfns;
905 struct ecore_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
906 #define ECORE_LEADING_HWFN(dev) (&dev->hwfns[0])
907 #define ECORE_IS_CMT(dev) ((dev)->num_hwfns > 1)
908
909 /* Engine affinity */
910 u8 l2_affin_hint;
911 u8 fir_affin;
912 u8 iwarp_affin;
913 /* Macro for getting the engine-affinitized hwfn for FCoE/iSCSI/RoCE */
914 #define ECORE_FIR_AFFIN_HWFN(dev) (&dev->hwfns[dev->fir_affin])
915 /* Macro for getting the engine-affinitized hwfn for iWARP */
916 #define ECORE_IWARP_AFFIN_HWFN(dev) (&dev->hwfns[dev->iwarp_affin])
917 /* Generic macro for getting the engine-affinitized hwfn */
918 #define ECORE_AFFIN_HWFN(dev) \
919 (ECORE_IS_IWARP_PERSONALITY(ECORE_LEADING_HWFN(dev)) ? \
920 ECORE_IWARP_AFFIN_HWFN(dev) : \
921 ECORE_FIR_AFFIN_HWFN(dev))
922 /* Macro for getting the index (0/1) of the engine-affinitized hwfn */
923 #define ECORE_AFFIN_HWFN_IDX(dev) \
924 (IS_LEAD_HWFN(ECORE_AFFIN_HWFN(dev)) ? 0 : 1)
925
926 /* SRIOV */
927 struct ecore_hw_sriov_info *p_iov_info;
928 #define IS_ECORE_SRIOV(p_dev) (!!(p_dev)->p_iov_info)
929 struct ecore_tunnel_info tunnel;
930 bool b_is_vf;
931 bool b_dont_override_vf_msix;
932
933 u32 drv_type;
934
935 u32 rdma_max_sge;
936 u32 rdma_max_inline;
937 u32 rdma_max_srq_sge;
938 u8 ilt_page_size;
939
940 struct ecore_eth_stats *reset_stats;
941 struct ecore_fw_data *fw_data;
942
943 u32 mcp_nvm_resp;
944
945 /* Recovery */
946 bool recov_in_prog;
947
948 /* Indicates whether should prevent attentions from being reasserted */
949 bool attn_clr_en;
950
951 /* Indicates whether allowing the MFW to collect a crash dump */
952 bool allow_mdump;
953
954 /* Indicates if the reg_fifo is checked after any register access */
955 bool chk_reg_fifo;
956
957 #ifndef ASIC_ONLY
958 bool b_is_emul_full;
959 #endif
960 /* LLH info */
961 u8 ppfid_bitmap;
962 struct ecore_llh_info *p_llh_info;
963 };
964
965 #define NUM_OF_VFS(dev) (ECORE_IS_BB(dev) ? MAX_NUM_VFS_BB \
966 : MAX_NUM_VFS_K2)
967 #define NUM_OF_L2_QUEUES(dev) (ECORE_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
968 : MAX_NUM_L2_QUEUES_K2)
969 #define NUM_OF_PORTS(dev) (ECORE_IS_BB(dev) ? MAX_NUM_PORTS_BB \
970 : MAX_NUM_PORTS_K2)
971 #define NUM_OF_SBS(dev) (ECORE_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
972 : MAX_SB_PER_PATH_K2)
973 #define NUM_OF_ENG_PFS(dev) (ECORE_IS_BB(dev) ? MAX_NUM_PFS_BB \
974 : MAX_NUM_PFS_K2)
975
976 #ifndef LINUX_REMOVE
977 #define CRC8_TABLE_SIZE 256
978 #endif
979
980 /**
981 * @brief ecore_concrete_to_sw_fid - get the sw function id from
982 * the concrete value.
983 *
984 * @param concrete_fid
985 *
986 * @return OSAL_INLINE u8
987 */
ecore_concrete_to_sw_fid(u32 concrete_fid)988 static OSAL_INLINE u8 ecore_concrete_to_sw_fid(u32 concrete_fid)
989 {
990 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
991 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
992 u8 vf_valid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFVALID);
993 u8 sw_fid;
994
995 if (vf_valid)
996 sw_fid = vfid + MAX_NUM_PFS;
997 else
998 sw_fid = pfid;
999
1000 return sw_fid;
1001 }
1002
1003 #define PKT_LB_TC 9
1004 #define MAX_NUM_VOQS_E4 20
1005
1006 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate);
1007 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
1008 struct ecore_ptt *p_ptt,
1009 u32 min_pf_rate);
1010
1011 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw);
1012 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw);
1013 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
1014 int ecore_device_num_engines(struct ecore_dev *p_dev);
1015 int ecore_device_num_ports(struct ecore_dev *p_dev);
1016 void ecore_set_fw_mac_addr(__le16 *fw_msb, __le16 *fw_mid, __le16 *fw_lsb,
1017 u8 *mac);
1018
1019 /* Flags for indication of required queues */
1020 #define PQ_FLAGS_RLS (1 << 0)
1021 #define PQ_FLAGS_MCOS (1 << 1)
1022 #define PQ_FLAGS_LB (1 << 2)
1023 #define PQ_FLAGS_OOO (1 << 3)
1024 #define PQ_FLAGS_ACK (1 << 4)
1025 #define PQ_FLAGS_OFLD (1 << 5)
1026 #define PQ_FLAGS_VFS (1 << 6)
1027 #define PQ_FLAGS_LLT (1 << 7)
1028
1029 /* physical queue index for cm context intialization */
1030 u16 ecore_get_cm_pq_idx(struct ecore_hwfn *p_hwfn, u32 pq_flags);
1031 u16 ecore_get_cm_pq_idx_mcos(struct ecore_hwfn *p_hwfn, u8 tc);
1032 u16 ecore_get_cm_pq_idx_vf(struct ecore_hwfn *p_hwfn, u16 vf);
1033 u16 ecore_get_cm_pq_idx_rl(struct ecore_hwfn *p_hwfn, u8 qpid);
1034
1035 const char *ecore_hw_get_resc_name(enum ecore_resources res_id);
1036
1037 /* doorbell recovery mechanism */
1038 void ecore_db_recovery_dp(struct ecore_hwfn *p_hwfn);
1039 void ecore_db_recovery_execute(struct ecore_hwfn *p_hwfn,
1040 enum ecore_db_rec_exec db_exec);
1041
1042 /* amount of resources used in qm init */
1043 u8 ecore_init_qm_get_num_tcs(struct ecore_hwfn *p_hwfn);
1044 u16 ecore_init_qm_get_num_vfs(struct ecore_hwfn *p_hwfn);
1045 u16 ecore_init_qm_get_num_pf_rls(struct ecore_hwfn *p_hwfn);
1046 u16 ecore_init_qm_get_num_vports(struct ecore_hwfn *p_hwfn);
1047 u16 ecore_init_qm_get_num_pqs(struct ecore_hwfn *p_hwfn);
1048
1049 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
1050 ecore_device_num_ports((_p_hwfn)->p_dev))
1051
1052 /* The PFID<->PPFID calculation is based on the relative index of a PF on its
1053 * port. In BB there is a bug in the LLH in which the PPFID is actually engine
1054 * based, and thus it equals the PFID.
1055 */
1056 #define ECORE_PFID_BY_PPFID(_p_hwfn, abs_ppfid) \
1057 (ECORE_IS_BB((_p_hwfn)->p_dev) ? \
1058 (abs_ppfid) : \
1059 (abs_ppfid) * (_p_hwfn)->p_dev->num_ports_in_engine + \
1060 MFW_PORT(_p_hwfn))
1061 #define ECORE_PPFID_BY_PFID(_p_hwfn) \
1062 (ECORE_IS_BB((_p_hwfn)->p_dev) ? \
1063 (_p_hwfn)->rel_pf_id : \
1064 (_p_hwfn)->rel_pf_id / (_p_hwfn)->p_dev->num_ports_in_engine)
1065
1066 enum _ecore_status_t ecore_all_ppfids_wr(struct ecore_hwfn *p_hwfn,
1067 struct ecore_ptt *p_ptt, u32 addr,
1068 u32 val);
1069
1070 /* Utility functions for dumping the content of the NIG LLH filters */
1071 enum _ecore_status_t ecore_llh_dump_ppfid(struct ecore_dev *p_dev, u8 ppfid);
1072 enum _ecore_status_t ecore_llh_dump_all(struct ecore_dev *p_dev);
1073
1074 #endif /* __ECORE_H */
1075