Loading...
1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2/* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017 QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
5 */
6
7#ifndef _QED_H
8#define _QED_H
9
10#include <linux/types.h>
11#include <linux/io.h>
12#include <linux/delay.h>
13#include <linux/firmware.h>
14#include <linux/interrupt.h>
15#include <linux/list.h>
16#include <linux/mutex.h>
17#include <linux/pci.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20#include <linux/workqueue.h>
21#include <linux/zlib.h>
22#include <linux/hashtable.h>
23#include <linux/qed/qed_if.h>
24#include "qed_debug.h"
25#include "qed_hsi.h"
26#include "qed_dbg_hsi.h"
27#include "qed_mfw_hsi.h"
28
29extern const struct qed_common_ops qed_common_ops_pass;
30
31#define STORM_FW_VERSION \
32 ((FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | \
33 (FW_REVISION_VERSION << 8) | FW_ENGINEERING_VERSION)
34
35#define MAX_HWFNS_PER_DEVICE (4)
36#define NAME_SIZE 16
37#define VER_SIZE 16
38
39#define QED_WFQ_UNIT 100
40
41#define QED_WID_SIZE (1024)
42#define QED_MIN_WIDS (4)
43#define QED_PF_DEMS_SIZE (4)
44
45#define QED_LLH_DONT_CARE 0
46
47/* cau states */
48enum qed_coalescing_mode {
49 QED_COAL_MODE_DISABLE,
50 QED_COAL_MODE_ENABLE
51};
52
53enum qed_nvm_cmd {
54 QED_PUT_FILE_BEGIN = DRV_MSG_CODE_NVM_PUT_FILE_BEGIN,
55 QED_PUT_FILE_DATA = DRV_MSG_CODE_NVM_PUT_FILE_DATA,
56 QED_NVM_WRITE_NVRAM = DRV_MSG_CODE_NVM_WRITE_NVRAM,
57 QED_GET_MCP_NVM_RESP = 0xFFFFFF00
58};
59
60struct qed_eth_cb_ops;
61struct qed_dev_info;
62union qed_mcp_protocol_stats;
63enum qed_mcp_protocol_type;
64enum qed_mfw_tlv_type;
65union qed_mfw_tlv_data;
66
67/* helpers */
68#define QED_MFW_GET_FIELD(name, field) \
69 (((name) & (field ## _MASK)) >> (field ## _SHIFT))
70
71#define QED_MFW_SET_FIELD(name, field, value) \
72 do { \
73 (name) &= ~(field ## _MASK); \
74 (name) |= (((value) << (field ## _SHIFT)) & (field ## _MASK));\
75 } while (0)
76
77static inline u32 qed_db_addr(u32 cid, u32 DEMS)
78{
79 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
80 (cid * QED_PF_DEMS_SIZE);
81
82 return db_addr;
83}
84
85static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
86{
87 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
88 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
89
90 return db_addr;
91}
92
93#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
94 ((sizeof(type_name) + (u32)(1 << ((p_hwfn)->cdev->cache_shift)) - 1) & \
95 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
96
97#define for_each_hwfn(cdev, i) for (i = 0; i < (cdev)->num_hwfns; i++)
98
99#define D_TRINE(val, cond1, cond2, true1, true2, def) \
100 ((val) == (cond1) ? true1 : \
101 ((val) == (cond2) ? true2 : def))
102
103/* forward */
104struct qed_ptt_pool;
105struct qed_spq;
106struct qed_sb_info;
107struct qed_sb_attn_info;
108struct qed_cxt_mngr;
109struct qed_sb_sp_info;
110struct qed_ll2_info;
111struct qed_mcp_info;
112struct qed_llh_info;
113
114struct qed_rt_data {
115 u32 *init_val;
116 bool *b_valid;
117};
118
119enum qed_tunn_mode {
120 QED_MODE_L2GENEVE_TUNN,
121 QED_MODE_IPGENEVE_TUNN,
122 QED_MODE_L2GRE_TUNN,
123 QED_MODE_IPGRE_TUNN,
124 QED_MODE_VXLAN_TUNN,
125};
126
127enum qed_tunn_clss {
128 QED_TUNN_CLSS_MAC_VLAN,
129 QED_TUNN_CLSS_MAC_VNI,
130 QED_TUNN_CLSS_INNER_MAC_VLAN,
131 QED_TUNN_CLSS_INNER_MAC_VNI,
132 QED_TUNN_CLSS_MAC_VLAN_DUAL_STAGE,
133 MAX_QED_TUNN_CLSS,
134};
135
136struct qed_tunn_update_type {
137 bool b_update_mode;
138 bool b_mode_enabled;
139 enum qed_tunn_clss tun_cls;
140};
141
142struct qed_tunn_update_udp_port {
143 bool b_update_port;
144 u16 port;
145};
146
147struct qed_tunnel_info {
148 struct qed_tunn_update_type vxlan;
149 struct qed_tunn_update_type l2_geneve;
150 struct qed_tunn_update_type ip_geneve;
151 struct qed_tunn_update_type l2_gre;
152 struct qed_tunn_update_type ip_gre;
153
154 struct qed_tunn_update_udp_port vxlan_port;
155 struct qed_tunn_update_udp_port geneve_port;
156
157 bool b_update_rx_cls;
158 bool b_update_tx_cls;
159};
160
161struct qed_tunn_start_params {
162 unsigned long tunn_mode;
163 u16 vxlan_udp_port;
164 u16 geneve_udp_port;
165 u8 update_vxlan_udp_port;
166 u8 update_geneve_udp_port;
167 u8 tunn_clss_vxlan;
168 u8 tunn_clss_l2geneve;
169 u8 tunn_clss_ipgeneve;
170 u8 tunn_clss_l2gre;
171 u8 tunn_clss_ipgre;
172};
173
174struct qed_tunn_update_params {
175 unsigned long tunn_mode_update_mask;
176 unsigned long tunn_mode;
177 u16 vxlan_udp_port;
178 u16 geneve_udp_port;
179 u8 update_rx_pf_clss;
180 u8 update_tx_pf_clss;
181 u8 update_vxlan_udp_port;
182 u8 update_geneve_udp_port;
183 u8 tunn_clss_vxlan;
184 u8 tunn_clss_l2geneve;
185 u8 tunn_clss_ipgeneve;
186 u8 tunn_clss_l2gre;
187 u8 tunn_clss_ipgre;
188};
189
190/* The PCI personality is not quite synonymous to protocol ID:
191 * 1. All personalities need CORE connections
192 * 2. The Ethernet personality may support also the RoCE/iWARP protocol
193 */
194enum qed_pci_personality {
195 QED_PCI_ETH,
196 QED_PCI_FCOE,
197 QED_PCI_ISCSI,
198 QED_PCI_NVMETCP,
199 QED_PCI_ETH_ROCE,
200 QED_PCI_ETH_IWARP,
201 QED_PCI_ETH_RDMA,
202 QED_PCI_DEFAULT, /* default in shmem */
203};
204
205/* All VFs are symmetric, all counters are PF + all VFs */
206struct qed_qm_iids {
207 u32 cids;
208 u32 vf_cids;
209 u32 tids;
210};
211
212/* HW / FW resources, output of features supported below, most information
213 * is received from MFW.
214 */
215enum qed_resources {
216 QED_SB,
217 QED_L2_QUEUE,
218 QED_VPORT,
219 QED_RSS_ENG,
220 QED_PQ,
221 QED_RL,
222 QED_MAC,
223 QED_VLAN,
224 QED_RDMA_CNQ_RAM,
225 QED_ILT,
226 QED_LL2_RAM_QUEUE,
227 QED_LL2_CTX_QUEUE,
228 QED_CMDQS_CQS,
229 QED_RDMA_STATS_QUEUE,
230 QED_BDQ,
231 QED_MAX_RESC,
232};
233
234enum QED_FEATURE {
235 QED_PF_L2_QUE,
236 QED_VF,
237 QED_RDMA_CNQ,
238 QED_NVMETCP_CQ,
239 QED_ISCSI_CQ,
240 QED_FCOE_CQ,
241 QED_VF_L2_QUE,
242 QED_MAX_FEATURES,
243};
244
245enum qed_dev_cap {
246 QED_DEV_CAP_ETH,
247 QED_DEV_CAP_FCOE,
248 QED_DEV_CAP_ISCSI,
249 QED_DEV_CAP_ROCE,
250 QED_DEV_CAP_IWARP,
251};
252
253enum qed_wol_support {
254 QED_WOL_SUPPORT_NONE,
255 QED_WOL_SUPPORT_PME,
256};
257
258enum qed_db_rec_exec {
259 DB_REC_DRY_RUN,
260 DB_REC_REAL_DEAL,
261 DB_REC_ONCE,
262};
263
264struct qed_hw_info {
265 /* PCI personality */
266 enum qed_pci_personality personality;
267#define QED_IS_RDMA_PERSONALITY(dev) \
268 ((dev)->hw_info.personality == QED_PCI_ETH_ROCE || \
269 (dev)->hw_info.personality == QED_PCI_ETH_IWARP || \
270 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
271#define QED_IS_ROCE_PERSONALITY(dev) \
272 ((dev)->hw_info.personality == QED_PCI_ETH_ROCE || \
273 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
274#define QED_IS_IWARP_PERSONALITY(dev) \
275 ((dev)->hw_info.personality == QED_PCI_ETH_IWARP || \
276 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
277#define QED_IS_L2_PERSONALITY(dev) \
278 ((dev)->hw_info.personality == QED_PCI_ETH || \
279 QED_IS_RDMA_PERSONALITY(dev))
280#define QED_IS_FCOE_PERSONALITY(dev) \
281 ((dev)->hw_info.personality == QED_PCI_FCOE)
282#define QED_IS_ISCSI_PERSONALITY(dev) \
283 ((dev)->hw_info.personality == QED_PCI_ISCSI)
284#define QED_IS_NVMETCP_PERSONALITY(dev) \
285 ((dev)->hw_info.personality == QED_PCI_NVMETCP)
286
287 /* Resource Allocation scheme results */
288 u32 resc_start[QED_MAX_RESC];
289 u32 resc_num[QED_MAX_RESC];
290#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
291#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
292#define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
293 RESC_NUM(_p_hwfn, resc))
294
295 u32 feat_num[QED_MAX_FEATURES];
296#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
297
298 /* Amount of traffic classes HW supports */
299 u8 num_hw_tc;
300
301 /* Amount of TCs which should be active according to DCBx or upper
302 * layer driver configuration.
303 */
304 u8 num_active_tc;
305
306 u8 offload_tc;
307 bool offload_tc_set;
308
309 bool multi_tc_roce_en;
310#define IS_QED_MULTI_TC_ROCE(p_hwfn) ((p_hwfn)->hw_info.multi_tc_roce_en)
311
312 u32 concrete_fid;
313 u16 opaque_fid;
314 u16 ovlan;
315 u32 part_num[4];
316
317 unsigned char hw_mac_addr[ETH_ALEN];
318 u64 node_wwn;
319 u64 port_wwn;
320
321 u16 num_fcoe_conns;
322
323 struct qed_igu_info *p_igu_info;
324
325 u32 hw_mode;
326 unsigned long device_capabilities;
327 u16 mtu;
328
329 enum qed_wol_support b_wol_support;
330};
331
332/* maximun size of read/write commands (HW limit) */
333#define DMAE_MAX_RW_SIZE 0x2000
334
335struct qed_dmae_info {
336 /* Mutex for synchronizing access to functions */
337 struct mutex mutex;
338
339 u8 channel;
340
341 dma_addr_t completion_word_phys_addr;
342
343 /* The memory location where the DMAE writes the completion
344 * value when an operation is finished on this context.
345 */
346 u32 *p_completion_word;
347
348 dma_addr_t intermediate_buffer_phys_addr;
349
350 /* An intermediate buffer for DMAE operations that use virtual
351 * addresses - data is DMA'd to/from this buffer and then
352 * memcpy'd to/from the virtual address
353 */
354 u32 *p_intermediate_buffer;
355
356 dma_addr_t dmae_cmd_phys_addr;
357 struct dmae_cmd *p_dmae_cmd;
358};
359
360struct qed_wfq_data {
361 /* when feature is configured for at least 1 vport */
362 u32 min_speed;
363 bool configured;
364};
365
366struct qed_qm_info {
367 struct init_qm_pq_params *qm_pq_params;
368 struct init_qm_vport_params *qm_vport_params;
369 struct init_qm_port_params *qm_port_params;
370 u16 start_pq;
371 u8 start_vport;
372 u16 pure_lb_pq;
373 u16 first_ofld_pq;
374 u16 first_llt_pq;
375 u16 pure_ack_pq;
376 u16 ooo_pq;
377 u16 first_vf_pq;
378 u16 first_mcos_pq;
379 u16 first_rl_pq;
380 u16 num_pqs;
381 u16 num_vf_pqs;
382 u8 num_vports;
383 u8 max_phys_tcs_per_port;
384 u8 ooo_tc;
385 bool pf_rl_en;
386 bool pf_wfq_en;
387 bool vport_rl_en;
388 bool vport_wfq_en;
389 u8 pf_wfq;
390 u32 pf_rl;
391 struct qed_wfq_data *wfq_data;
392 u8 num_pf_rls;
393};
394
395#define QED_OVERFLOW_BIT 1
396
397struct qed_db_recovery_info {
398 struct list_head list;
399
400 /* Lock to protect the doorbell recovery mechanism list */
401 spinlock_t lock;
402 bool dorq_attn;
403 u32 db_recovery_counter;
404 unsigned long overflow;
405};
406
407struct storm_stats {
408 u32 address;
409 u32 len;
410};
411
412struct qed_storm_stats {
413 struct storm_stats mstats;
414 struct storm_stats pstats;
415 struct storm_stats tstats;
416 struct storm_stats ustats;
417};
418
419struct qed_fw_data {
420 struct fw_ver_info *fw_ver_info;
421 const u8 *modes_tree_buf;
422 union init_op *init_ops;
423 const u32 *arr_data;
424 const u32 *fw_overlays;
425 u32 fw_overlays_len;
426 u32 init_ops_size;
427};
428
429enum qed_mf_mode_bit {
430 /* Supports PF-classification based on tag */
431 QED_MF_OVLAN_CLSS,
432
433 /* Supports PF-classification based on MAC */
434 QED_MF_LLH_MAC_CLSS,
435
436 /* Supports PF-classification based on protocol type */
437 QED_MF_LLH_PROTO_CLSS,
438
439 /* Requires a default PF to be set */
440 QED_MF_NEED_DEF_PF,
441
442 /* Allow LL2 to multicast/broadcast */
443 QED_MF_LL2_NON_UNICAST,
444
445 /* Allow Cross-PF [& child VFs] Tx-switching */
446 QED_MF_INTER_PF_SWITCH,
447
448 /* Unified Fabtic Port support enabled */
449 QED_MF_UFP_SPECIFIC,
450
451 /* Disable Accelerated Receive Flow Steering (aRFS) */
452 QED_MF_DISABLE_ARFS,
453
454 /* Use vlan for steering */
455 QED_MF_8021Q_TAGGING,
456
457 /* Use stag for steering */
458 QED_MF_8021AD_TAGGING,
459
460 /* Allow DSCP to TC mapping */
461 QED_MF_DSCP_TO_TC_MAP,
462
463 /* Do not insert a vlan tag with id 0 */
464 QED_MF_DONT_ADD_VLAN0_TAG,
465};
466
467enum qed_ufp_mode {
468 QED_UFP_MODE_ETS,
469 QED_UFP_MODE_VNIC_BW,
470 QED_UFP_MODE_UNKNOWN
471};
472
473enum qed_ufp_pri_type {
474 QED_UFP_PRI_OS,
475 QED_UFP_PRI_VNIC,
476 QED_UFP_PRI_UNKNOWN
477};
478
479struct qed_ufp_info {
480 enum qed_ufp_pri_type pri_type;
481 enum qed_ufp_mode mode;
482 u8 tc;
483};
484
485enum BAR_ID {
486 BAR_ID_0, /* used for GRC */
487 BAR_ID_1 /* Used for doorbells */
488};
489
490struct qed_nvm_image_info {
491 u32 num_images;
492 struct bist_nvm_image_att *image_att;
493 bool valid;
494};
495
496enum qed_hsi_def_type {
497 QED_HSI_DEF_MAX_NUM_VFS,
498 QED_HSI_DEF_MAX_NUM_L2_QUEUES,
499 QED_HSI_DEF_MAX_NUM_PORTS,
500 QED_HSI_DEF_MAX_SB_PER_PATH,
501 QED_HSI_DEF_MAX_NUM_PFS,
502 QED_HSI_DEF_MAX_NUM_VPORTS,
503 QED_HSI_DEF_NUM_ETH_RSS_ENGINE,
504 QED_HSI_DEF_MAX_QM_TX_QUEUES,
505 QED_HSI_DEF_NUM_PXP_ILT_RECORDS,
506 QED_HSI_DEF_NUM_RDMA_STATISTIC_COUNTERS,
507 QED_HSI_DEF_MAX_QM_GLOBAL_RLS,
508 QED_HSI_DEF_MAX_PBF_CMD_LINES,
509 QED_HSI_DEF_MAX_BTB_BLOCKS,
510 QED_NUM_HSI_DEFS
511};
512
513struct qed_simd_fp_handler {
514 void *token;
515 void (*func)(void *cookie);
516};
517
518enum qed_slowpath_wq_flag {
519 QED_SLOWPATH_MFW_TLV_REQ,
520 QED_SLOWPATH_PERIODIC_DB_REC,
521};
522
523struct qed_hwfn {
524 struct qed_dev *cdev;
525 u8 my_id; /* ID inside the PF */
526#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
527 u8 rel_pf_id; /* Relative to engine*/
528 u8 abs_pf_id;
529#define QED_PATH_ID(_p_hwfn) \
530 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
531 u8 port_id;
532 bool b_active;
533
534 u32 dp_module;
535 u8 dp_level;
536 char name[NAME_SIZE];
537
538 bool hw_init_done;
539
540 u8 num_funcs_on_engine;
541 u8 enabled_func_idx;
542
543 /* BAR access */
544 void __iomem *regview;
545 void __iomem *doorbells;
546 u64 db_phys_addr;
547 unsigned long db_size;
548
549 /* PTT pool */
550 struct qed_ptt_pool *p_ptt_pool;
551
552 /* HW info */
553 struct qed_hw_info hw_info;
554
555 /* rt_array (for init-tool) */
556 struct qed_rt_data rt_data;
557
558 /* SPQ */
559 struct qed_spq *p_spq;
560
561 /* EQ */
562 struct qed_eq *p_eq;
563
564 /* Consolidate Q*/
565 struct qed_consq *p_consq;
566
567 /* Slow-Path definitions */
568 struct tasklet_struct sp_dpc;
569 bool b_sp_dpc_enabled;
570
571 struct qed_ptt *p_main_ptt;
572 struct qed_ptt *p_dpc_ptt;
573
574 /* PTP will be used only by the leading function.
575 * Usage of all PTP-apis should be synchronized as result.
576 */
577 struct qed_ptt *p_ptp_ptt;
578
579 struct qed_sb_sp_info *p_sp_sb;
580 struct qed_sb_attn_info *p_sb_attn;
581
582 /* Protocol related */
583 bool using_ll2;
584 struct qed_ll2_info *p_ll2_info;
585 struct qed_ooo_info *p_ooo_info;
586 struct qed_rdma_info *p_rdma_info;
587 struct qed_iscsi_info *p_iscsi_info;
588 struct qed_nvmetcp_info *p_nvmetcp_info;
589 struct qed_fcoe_info *p_fcoe_info;
590 struct qed_pf_params pf_params;
591
592 bool b_rdma_enabled_in_prs;
593 u32 rdma_prs_search_reg;
594
595 struct qed_cxt_mngr *p_cxt_mngr;
596
597 /* Flag indicating whether interrupts are enabled or not*/
598 bool b_int_enabled;
599 bool b_int_requested;
600
601 /* True if the driver requests for the link */
602 bool b_drv_link_init;
603
604 struct qed_vf_iov *vf_iov_info;
605 struct qed_pf_iov *pf_iov_info;
606 struct qed_mcp_info *mcp_info;
607
608 struct qed_dcbx_info *p_dcbx_info;
609
610 struct qed_ufp_info ufp_info;
611
612 struct qed_dmae_info dmae_info;
613
614 /* QM init */
615 struct qed_qm_info qm_info;
616 struct qed_storm_stats storm_stats;
617
618 /* Buffer for unzipping firmware data */
619 void *unzip_buf;
620
621 struct dbg_tools_data dbg_info;
622 void *dbg_user_info;
623 struct virt_mem_desc dbg_arrays[MAX_BIN_DBG_BUFFER_TYPE];
624
625 /* PWM region specific data */
626 u16 wid_count;
627 u32 dpi_size;
628 u32 dpi_count;
629
630 /* This is used to calculate the doorbell address */
631 u32 dpi_start_offset;
632
633 /* If one of the following is set then EDPM shouldn't be used */
634 u8 dcbx_no_edpm;
635 u8 db_bar_no_edpm;
636
637 /* L2-related */
638 struct qed_l2_info *p_l2_info;
639
640 /* Mechanism for recovering from doorbell drop */
641 struct qed_db_recovery_info db_recovery_info;
642
643 /* Nvm images number and attributes */
644 struct qed_nvm_image_info nvm_info;
645
646 struct phys_mem_desc *fw_overlay_mem;
647 struct qed_ptt *p_arfs_ptt;
648
649 struct qed_simd_fp_handler simd_proto_handler[64];
650
651#ifdef CONFIG_QED_SRIOV
652 struct workqueue_struct *iov_wq;
653 struct delayed_work iov_task;
654 unsigned long iov_task_flags;
655#endif
656 struct z_stream_s *stream;
657 bool slowpath_wq_active;
658 struct workqueue_struct *slowpath_wq;
659 struct delayed_work slowpath_task;
660 unsigned long slowpath_task_flags;
661 u32 periodic_db_rec_count;
662};
663
664struct pci_params {
665 int pm_cap;
666
667 unsigned long mem_start;
668 unsigned long mem_end;
669 unsigned int irq;
670 u8 pf_num;
671};
672
673struct qed_int_param {
674 u32 int_mode;
675 u8 num_vectors;
676 u8 min_msix_cnt; /* for minimal functionality */
677};
678
679struct qed_int_params {
680 struct qed_int_param in;
681 struct qed_int_param out;
682 struct msix_entry *msix_table;
683 bool fp_initialized;
684 u8 fp_msix_base;
685 u8 fp_msix_cnt;
686 u8 rdma_msix_base;
687 u8 rdma_msix_cnt;
688};
689
690struct qed_dbg_feature {
691 struct dentry *dentry;
692 u8 *dump_buf;
693 u32 buf_size;
694 u32 dumped_dwords;
695};
696
697struct qed_dev {
698 u32 dp_module;
699 u8 dp_level;
700 char name[NAME_SIZE];
701
702 enum qed_dev_type type;
703 /* Translate type/revision combo into the proper conditions */
704#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
705#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && CHIP_REV_IS_B0(dev))
706#define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
707#define QED_IS_K2(dev) QED_IS_AH(dev)
708
709 u16 vendor_id;
710
711 u16 device_id;
712#define QED_DEV_ID_MASK 0xff00
713#define QED_DEV_ID_MASK_BB 0x1600
714#define QED_DEV_ID_MASK_AH 0x8000
715
716 u16 chip_num;
717#define CHIP_NUM_MASK 0xffff
718#define CHIP_NUM_SHIFT 16
719
720 u16 chip_rev;
721#define CHIP_REV_MASK 0xf
722#define CHIP_REV_SHIFT 12
723#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
724
725 u16 chip_metal;
726#define CHIP_METAL_MASK 0xff
727#define CHIP_METAL_SHIFT 4
728
729 u16 chip_bond_id;
730#define CHIP_BOND_ID_MASK 0xf
731#define CHIP_BOND_ID_SHIFT 0
732
733 u8 num_engines;
734 u8 num_ports;
735 u8 num_ports_in_engine;
736 u8 num_funcs_in_port;
737
738 u8 path_id;
739
740 unsigned long mf_bits;
741
742 int pcie_width;
743 int pcie_speed;
744
745 /* Add MF related configuration */
746 u8 mcp_rev;
747 u8 boot_mode;
748
749 /* WoL related configurations */
750 u8 wol_config;
751 u8 wol_mac[ETH_ALEN];
752
753 u32 int_mode;
754 enum qed_coalescing_mode int_coalescing_mode;
755 u16 rx_coalesce_usecs;
756 u16 tx_coalesce_usecs;
757
758 /* Start Bar offset of first hwfn */
759 void __iomem *regview;
760 void __iomem *doorbells;
761 u64 db_phys_addr;
762 unsigned long db_size;
763
764 /* PCI */
765 u8 cache_shift;
766
767 /* Init */
768 const u32 *iro_arr;
769#define IRO ((const struct iro *)p_hwfn->cdev->iro_arr)
770
771 /* HW functions */
772 u8 num_hwfns;
773 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
774
775 /* Engine affinity */
776 u8 l2_affin_hint;
777 u8 fir_affin;
778 u8 iwarp_affin;
779
780 /* SRIOV */
781 struct qed_hw_sriov_info *p_iov_info;
782#define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
783 struct qed_tunnel_info tunnel;
784 bool b_is_vf;
785 u32 drv_type;
786 struct qed_eth_stats *reset_stats;
787 struct qed_fw_data *fw_data;
788
789 u32 mcp_nvm_resp;
790
791 /* Recovery */
792 bool recov_in_prog;
793
794 /* Indicates whether should prevent attentions from being reasserted */
795 bool attn_clr_en;
796
797 /* LLH info */
798 u8 ppfid_bitmap;
799 struct qed_llh_info *p_llh_info;
800
801 /* Linux specific here */
802 struct qed_dev_info common_dev_info;
803 struct qede_dev *edev;
804 struct pci_dev *pdev;
805 u32 flags;
806#define QED_FLAG_STORAGE_STARTED (BIT(0))
807 int msg_enable;
808
809 struct pci_params pci_params;
810
811 struct qed_int_params int_params;
812
813 u8 protocol;
814#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
815#define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
816
817 /* Callbacks to protocol driver */
818 union {
819 struct qed_common_cb_ops *common;
820 struct qed_eth_cb_ops *eth;
821 struct qed_fcoe_cb_ops *fcoe;
822 struct qed_iscsi_cb_ops *iscsi;
823 struct qed_nvmetcp_cb_ops *nvmetcp;
824 } protocol_ops;
825 void *ops_cookie;
826
827#ifdef CONFIG_QED_LL2
828 struct qed_cb_ll2_info *ll2;
829 u8 ll2_mac_address[ETH_ALEN];
830#endif
831 struct qed_dbg_feature dbg_features[DBG_FEATURE_NUM];
832 u8 engine_for_debug;
833 bool disable_ilt_dump;
834 bool dbg_bin_dump;
835
836 DECLARE_HASHTABLE(connections, 10);
837 const struct firmware *firmware;
838
839 bool print_dbg_data;
840
841 u32 rdma_max_sge;
842 u32 rdma_max_inline;
843 u32 rdma_max_srq_sge;
844 u16 tunn_feature_mask;
845
846 bool iwarp_cmt;
847};
848
849u32 qed_get_hsi_def_val(struct qed_dev *cdev, enum qed_hsi_def_type type);
850
851#define NUM_OF_VFS(dev) \
852 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_NUM_VFS)
853#define NUM_OF_L2_QUEUES(dev) \
854 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_NUM_L2_QUEUES)
855#define NUM_OF_PORTS(dev) \
856 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_NUM_PORTS)
857#define NUM_OF_SBS(dev) \
858 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_SB_PER_PATH)
859#define NUM_OF_ENG_PFS(dev) \
860 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_NUM_PFS)
861#define NUM_OF_VPORTS(dev) \
862 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_NUM_VPORTS)
863#define NUM_OF_RSS_ENGINES(dev) \
864 qed_get_hsi_def_val(dev, QED_HSI_DEF_NUM_ETH_RSS_ENGINE)
865#define NUM_OF_QM_TX_QUEUES(dev) \
866 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_QM_TX_QUEUES)
867#define NUM_OF_PXP_ILT_RECORDS(dev) \
868 qed_get_hsi_def_val(dev, QED_HSI_DEF_NUM_PXP_ILT_RECORDS)
869#define NUM_OF_RDMA_STATISTIC_COUNTERS(dev) \
870 qed_get_hsi_def_val(dev, QED_HSI_DEF_NUM_RDMA_STATISTIC_COUNTERS)
871#define NUM_OF_QM_GLOBAL_RLS(dev) \
872 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_QM_GLOBAL_RLS)
873#define NUM_OF_PBF_CMD_LINES(dev) \
874 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_PBF_CMD_LINES)
875#define NUM_OF_BTB_BLOCKS(dev) \
876 qed_get_hsi_def_val(dev, QED_HSI_DEF_MAX_BTB_BLOCKS)
877
878/**
879 * qed_concrete_to_sw_fid(): Get the sw function id from
880 * the concrete value.
881 *
882 * @cdev: Qed dev pointer.
883 * @concrete_fid: Concrete fid.
884 *
885 * Return: inline u8.
886 */
887static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
888 u32 concrete_fid)
889{
890 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
891 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
892 u8 vf_valid = GET_FIELD(concrete_fid,
893 PXP_CONCRETE_FID_VFVALID);
894 u8 sw_fid;
895
896 if (vf_valid)
897 sw_fid = vfid + MAX_NUM_PFS;
898 else
899 sw_fid = pfid;
900
901 return sw_fid;
902}
903
904#define PKT_LB_TC 9
905
906int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
907void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
908 struct qed_ptt *p_ptt,
909 u32 min_pf_rate);
910
911void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
912void qed_set_fw_mac_addr(__le16 *fw_msb,
913 __le16 *fw_mid, __le16 *fw_lsb, u8 *mac);
914
915#define QED_LEADING_HWFN(dev) (&(dev)->hwfns[0])
916#define QED_IS_CMT(dev) ((dev)->num_hwfns > 1)
917/* Macros for getting the engine-affinitized hwfn (FIR: fcoe,iscsi,roce) */
918#define QED_FIR_AFFIN_HWFN(dev) (&(dev)->hwfns[dev->fir_affin])
919#define QED_IWARP_AFFIN_HWFN(dev) (&(dev)->hwfns[dev->iwarp_affin])
920#define QED_AFFIN_HWFN(dev) \
921 (QED_IS_IWARP_PERSONALITY(QED_LEADING_HWFN(dev)) ? \
922 QED_IWARP_AFFIN_HWFN(dev) : QED_FIR_AFFIN_HWFN(dev))
923#define QED_AFFIN_HWFN_IDX(dev) (IS_LEAD_HWFN(QED_AFFIN_HWFN(dev)) ? 0 : 1)
924
925/* Flags for indication of required queues */
926#define PQ_FLAGS_RLS (BIT(0))
927#define PQ_FLAGS_MCOS (BIT(1))
928#define PQ_FLAGS_LB (BIT(2))
929#define PQ_FLAGS_OOO (BIT(3))
930#define PQ_FLAGS_ACK (BIT(4))
931#define PQ_FLAGS_OFLD (BIT(5))
932#define PQ_FLAGS_VFS (BIT(6))
933#define PQ_FLAGS_LLT (BIT(7))
934#define PQ_FLAGS_MTC (BIT(8))
935
936/* physical queue index for cm context initialization */
937u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags);
938u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc);
939u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf);
940u16 qed_get_cm_pq_idx_ofld_mtc(struct qed_hwfn *p_hwfn, u8 tc);
941u16 qed_get_cm_pq_idx_llt_mtc(struct qed_hwfn *p_hwfn, u8 tc);
942
943/* doorbell recovery mechanism */
944void qed_db_recovery_dp(struct qed_hwfn *p_hwfn);
945void qed_db_recovery_execute(struct qed_hwfn *p_hwfn);
946bool qed_edpm_enabled(struct qed_hwfn *p_hwfn);
947
948#define GET_GTT_REG_ADDR(__base, __offset, __idx) \
949 ((__base) + __offset ## _GTT_OFFSET((__idx)))
950
951#define GET_GTT_BDQ_REG_ADDR(__base, __offset, __idx, __bdq_idx) \
952 ((__base) + __offset ## _GTT_OFFSET((__idx), (__bdq_idx)))
953
954/* Other Linux specific common definitions */
955#define DP_NAME(cdev) ((cdev)->name)
956
957#define REG_ADDR(cdev, offset) ((void __iomem *)((u8 __iomem *)\
958 ((cdev)->regview) + \
959 (offset)))
960
961#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
962#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
963#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
964
965#define DOORBELL(cdev, db_addr, val) \
966 writel((u32)val, (void __iomem *)((u8 __iomem *)\
967 ((cdev)->doorbells) + (db_addr)))
968
969#define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
970 qed_device_num_ports((_p_hwfn)->cdev))
971int qed_device_num_ports(struct qed_dev *cdev);
972
973/* Prototypes */
974int qed_fill_dev_info(struct qed_dev *cdev,
975 struct qed_dev_info *dev_info);
976void qed_link_update(struct qed_hwfn *hwfn, struct qed_ptt *ptt);
977void qed_bw_update(struct qed_hwfn *hwfn, struct qed_ptt *ptt);
978u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
979 u32 input_len, u8 *input_buf,
980 u32 max_size, u8 *unzip_buf);
981int qed_recovery_process(struct qed_dev *cdev);
982void qed_schedule_recovery_handler(struct qed_hwfn *p_hwfn);
983void qed_hw_error_occurred(struct qed_hwfn *p_hwfn,
984 enum qed_hw_err_type err_type);
985void qed_get_protocol_stats(struct qed_dev *cdev,
986 enum qed_mcp_protocol_type type,
987 union qed_mcp_protocol_stats *stats);
988int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
989void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn);
990int qed_mfw_tlv_req(struct qed_hwfn *hwfn);
991
992int qed_mfw_fill_tlv_data(struct qed_hwfn *hwfn,
993 enum qed_mfw_tlv_type type,
994 union qed_mfw_tlv_data *tlv_data);
995
996void qed_hw_info_set_offload_tc(struct qed_hw_info *p_info, u8 tc);
997
998void qed_periodic_db_rec_start(struct qed_hwfn *p_hwfn);
999
1000int qed_llh_add_src_tcp_port_filter(struct qed_dev *cdev, u16 src_port);
1001int qed_llh_add_dst_tcp_port_filter(struct qed_dev *cdev, u16 dest_port);
1002void qed_llh_remove_src_tcp_port_filter(struct qed_dev *cdev, u16 src_port);
1003void qed_llh_remove_dst_tcp_port_filter(struct qed_dev *cdev, u16 src_port);
1004void qed_llh_clear_all_filters(struct qed_dev *cdev);
1005unsigned long qed_get_epoch_time(void);
1006#endif /* _QED_H */
1/* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _QED_H
34#define _QED_H
35
36#include <linux/types.h>
37#include <linux/io.h>
38#include <linux/delay.h>
39#include <linux/firmware.h>
40#include <linux/interrupt.h>
41#include <linux/list.h>
42#include <linux/mutex.h>
43#include <linux/pci.h>
44#include <linux/slab.h>
45#include <linux/string.h>
46#include <linux/workqueue.h>
47#include <linux/zlib.h>
48#include <linux/hashtable.h>
49#include <linux/qed/qed_if.h>
50#include "qed_debug.h"
51#include "qed_hsi.h"
52
53extern const struct qed_common_ops qed_common_ops_pass;
54
55#define QED_MAJOR_VERSION 8
56#define QED_MINOR_VERSION 33
57#define QED_REVISION_VERSION 0
58#define QED_ENGINEERING_VERSION 20
59
60#define QED_VERSION \
61 ((QED_MAJOR_VERSION << 24) | (QED_MINOR_VERSION << 16) | \
62 (QED_REVISION_VERSION << 8) | QED_ENGINEERING_VERSION)
63
64#define STORM_FW_VERSION \
65 ((FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | \
66 (FW_REVISION_VERSION << 8) | FW_ENGINEERING_VERSION)
67
68#define MAX_HWFNS_PER_DEVICE (4)
69#define NAME_SIZE 16
70#define VER_SIZE 16
71
72#define QED_WFQ_UNIT 100
73
74#define QED_WID_SIZE (1024)
75#define QED_MIN_WIDS (4)
76#define QED_PF_DEMS_SIZE (4)
77
78/* cau states */
79enum qed_coalescing_mode {
80 QED_COAL_MODE_DISABLE,
81 QED_COAL_MODE_ENABLE
82};
83
84enum qed_nvm_cmd {
85 QED_PUT_FILE_BEGIN = DRV_MSG_CODE_NVM_PUT_FILE_BEGIN,
86 QED_PUT_FILE_DATA = DRV_MSG_CODE_NVM_PUT_FILE_DATA,
87 QED_NVM_WRITE_NVRAM = DRV_MSG_CODE_NVM_WRITE_NVRAM,
88 QED_GET_MCP_NVM_RESP = 0xFFFFFF00
89};
90
91struct qed_eth_cb_ops;
92struct qed_dev_info;
93union qed_mcp_protocol_stats;
94enum qed_mcp_protocol_type;
95
96/* helpers */
97#define QED_MFW_GET_FIELD(name, field) \
98 (((name) & (field ## _MASK)) >> (field ## _SHIFT))
99
100#define QED_MFW_SET_FIELD(name, field, value) \
101 do { \
102 (name) &= ~(field ## _MASK); \
103 (name) |= (((value) << (field ## _SHIFT)) & (field ## _MASK));\
104 } while (0)
105
106static inline u32 qed_db_addr(u32 cid, u32 DEMS)
107{
108 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
109 (cid * QED_PF_DEMS_SIZE);
110
111 return db_addr;
112}
113
114static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
115{
116 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
117 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
118
119 return db_addr;
120}
121
122#define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
123 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
124 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
125
126#define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
127
128#define D_TRINE(val, cond1, cond2, true1, true2, def) \
129 (val == (cond1) ? true1 : \
130 (val == (cond2) ? true2 : def))
131
132/* forward */
133struct qed_ptt_pool;
134struct qed_spq;
135struct qed_sb_info;
136struct qed_sb_attn_info;
137struct qed_cxt_mngr;
138struct qed_sb_sp_info;
139struct qed_ll2_info;
140struct qed_mcp_info;
141
142struct qed_rt_data {
143 u32 *init_val;
144 bool *b_valid;
145};
146
147enum qed_tunn_mode {
148 QED_MODE_L2GENEVE_TUNN,
149 QED_MODE_IPGENEVE_TUNN,
150 QED_MODE_L2GRE_TUNN,
151 QED_MODE_IPGRE_TUNN,
152 QED_MODE_VXLAN_TUNN,
153};
154
155enum qed_tunn_clss {
156 QED_TUNN_CLSS_MAC_VLAN,
157 QED_TUNN_CLSS_MAC_VNI,
158 QED_TUNN_CLSS_INNER_MAC_VLAN,
159 QED_TUNN_CLSS_INNER_MAC_VNI,
160 QED_TUNN_CLSS_MAC_VLAN_DUAL_STAGE,
161 MAX_QED_TUNN_CLSS,
162};
163
164struct qed_tunn_update_type {
165 bool b_update_mode;
166 bool b_mode_enabled;
167 enum qed_tunn_clss tun_cls;
168};
169
170struct qed_tunn_update_udp_port {
171 bool b_update_port;
172 u16 port;
173};
174
175struct qed_tunnel_info {
176 struct qed_tunn_update_type vxlan;
177 struct qed_tunn_update_type l2_geneve;
178 struct qed_tunn_update_type ip_geneve;
179 struct qed_tunn_update_type l2_gre;
180 struct qed_tunn_update_type ip_gre;
181
182 struct qed_tunn_update_udp_port vxlan_port;
183 struct qed_tunn_update_udp_port geneve_port;
184
185 bool b_update_rx_cls;
186 bool b_update_tx_cls;
187};
188
189struct qed_tunn_start_params {
190 unsigned long tunn_mode;
191 u16 vxlan_udp_port;
192 u16 geneve_udp_port;
193 u8 update_vxlan_udp_port;
194 u8 update_geneve_udp_port;
195 u8 tunn_clss_vxlan;
196 u8 tunn_clss_l2geneve;
197 u8 tunn_clss_ipgeneve;
198 u8 tunn_clss_l2gre;
199 u8 tunn_clss_ipgre;
200};
201
202struct qed_tunn_update_params {
203 unsigned long tunn_mode_update_mask;
204 unsigned long tunn_mode;
205 u16 vxlan_udp_port;
206 u16 geneve_udp_port;
207 u8 update_rx_pf_clss;
208 u8 update_tx_pf_clss;
209 u8 update_vxlan_udp_port;
210 u8 update_geneve_udp_port;
211 u8 tunn_clss_vxlan;
212 u8 tunn_clss_l2geneve;
213 u8 tunn_clss_ipgeneve;
214 u8 tunn_clss_l2gre;
215 u8 tunn_clss_ipgre;
216};
217
218/* The PCI personality is not quite synonymous to protocol ID:
219 * 1. All personalities need CORE connections
220 * 2. The Ethernet personality may support also the RoCE/iWARP protocol
221 */
222enum qed_pci_personality {
223 QED_PCI_ETH,
224 QED_PCI_FCOE,
225 QED_PCI_ISCSI,
226 QED_PCI_ETH_ROCE,
227 QED_PCI_ETH_IWARP,
228 QED_PCI_ETH_RDMA,
229 QED_PCI_DEFAULT, /* default in shmem */
230};
231
232/* All VFs are symmetric, all counters are PF + all VFs */
233struct qed_qm_iids {
234 u32 cids;
235 u32 vf_cids;
236 u32 tids;
237};
238
239/* HW / FW resources, output of features supported below, most information
240 * is received from MFW.
241 */
242enum qed_resources {
243 QED_SB,
244 QED_L2_QUEUE,
245 QED_VPORT,
246 QED_RSS_ENG,
247 QED_PQ,
248 QED_RL,
249 QED_MAC,
250 QED_VLAN,
251 QED_RDMA_CNQ_RAM,
252 QED_ILT,
253 QED_LL2_QUEUE,
254 QED_CMDQS_CQS,
255 QED_RDMA_STATS_QUEUE,
256 QED_BDQ,
257 QED_MAX_RESC,
258};
259
260enum QED_FEATURE {
261 QED_PF_L2_QUE,
262 QED_VF,
263 QED_RDMA_CNQ,
264 QED_ISCSI_CQ,
265 QED_FCOE_CQ,
266 QED_VF_L2_QUE,
267 QED_MAX_FEATURES,
268};
269
270enum QED_PORT_MODE {
271 QED_PORT_MODE_DE_2X40G,
272 QED_PORT_MODE_DE_2X50G,
273 QED_PORT_MODE_DE_1X100G,
274 QED_PORT_MODE_DE_4X10G_F,
275 QED_PORT_MODE_DE_4X10G_E,
276 QED_PORT_MODE_DE_4X20G,
277 QED_PORT_MODE_DE_1X40G,
278 QED_PORT_MODE_DE_2X25G,
279 QED_PORT_MODE_DE_1X25G,
280 QED_PORT_MODE_DE_4X25G,
281 QED_PORT_MODE_DE_2X10G,
282};
283
284enum qed_dev_cap {
285 QED_DEV_CAP_ETH,
286 QED_DEV_CAP_FCOE,
287 QED_DEV_CAP_ISCSI,
288 QED_DEV_CAP_ROCE,
289 QED_DEV_CAP_IWARP,
290};
291
292enum qed_wol_support {
293 QED_WOL_SUPPORT_NONE,
294 QED_WOL_SUPPORT_PME,
295};
296
297struct qed_hw_info {
298 /* PCI personality */
299 enum qed_pci_personality personality;
300#define QED_IS_RDMA_PERSONALITY(dev) \
301 ((dev)->hw_info.personality == QED_PCI_ETH_ROCE || \
302 (dev)->hw_info.personality == QED_PCI_ETH_IWARP || \
303 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
304#define QED_IS_ROCE_PERSONALITY(dev) \
305 ((dev)->hw_info.personality == QED_PCI_ETH_ROCE || \
306 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
307#define QED_IS_IWARP_PERSONALITY(dev) \
308 ((dev)->hw_info.personality == QED_PCI_ETH_IWARP || \
309 (dev)->hw_info.personality == QED_PCI_ETH_RDMA)
310#define QED_IS_L2_PERSONALITY(dev) \
311 ((dev)->hw_info.personality == QED_PCI_ETH || \
312 QED_IS_RDMA_PERSONALITY(dev))
313#define QED_IS_FCOE_PERSONALITY(dev) \
314 ((dev)->hw_info.personality == QED_PCI_FCOE)
315#define QED_IS_ISCSI_PERSONALITY(dev) \
316 ((dev)->hw_info.personality == QED_PCI_ISCSI)
317
318 /* Resource Allocation scheme results */
319 u32 resc_start[QED_MAX_RESC];
320 u32 resc_num[QED_MAX_RESC];
321 u32 feat_num[QED_MAX_FEATURES];
322
323#define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
324#define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
325#define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
326 RESC_NUM(_p_hwfn, resc))
327#define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
328
329 /* Amount of traffic classes HW supports */
330 u8 num_hw_tc;
331
332 /* Amount of TCs which should be active according to DCBx or upper
333 * layer driver configuration.
334 */
335 u8 num_active_tc;
336 u8 offload_tc;
337
338 u32 concrete_fid;
339 u16 opaque_fid;
340 u16 ovlan;
341 u32 part_num[4];
342
343 unsigned char hw_mac_addr[ETH_ALEN];
344 u64 node_wwn;
345 u64 port_wwn;
346
347 u16 num_fcoe_conns;
348
349 struct qed_igu_info *p_igu_info;
350
351 u32 port_mode;
352 u32 hw_mode;
353 unsigned long device_capabilities;
354 u16 mtu;
355
356 enum qed_wol_support b_wol_support;
357};
358
359/* maximun size of read/write commands (HW limit) */
360#define DMAE_MAX_RW_SIZE 0x2000
361
362struct qed_dmae_info {
363 /* Mutex for synchronizing access to functions */
364 struct mutex mutex;
365
366 u8 channel;
367
368 dma_addr_t completion_word_phys_addr;
369
370 /* The memory location where the DMAE writes the completion
371 * value when an operation is finished on this context.
372 */
373 u32 *p_completion_word;
374
375 dma_addr_t intermediate_buffer_phys_addr;
376
377 /* An intermediate buffer for DMAE operations that use virtual
378 * addresses - data is DMA'd to/from this buffer and then
379 * memcpy'd to/from the virtual address
380 */
381 u32 *p_intermediate_buffer;
382
383 dma_addr_t dmae_cmd_phys_addr;
384 struct dmae_cmd *p_dmae_cmd;
385};
386
387struct qed_wfq_data {
388 /* when feature is configured for at least 1 vport */
389 u32 min_speed;
390 bool configured;
391};
392
393struct qed_qm_info {
394 struct init_qm_pq_params *qm_pq_params;
395 struct init_qm_vport_params *qm_vport_params;
396 struct init_qm_port_params *qm_port_params;
397 u16 start_pq;
398 u8 start_vport;
399 u16 pure_lb_pq;
400 u16 offload_pq;
401 u16 low_latency_pq;
402 u16 pure_ack_pq;
403 u16 ooo_pq;
404 u16 first_vf_pq;
405 u16 first_mcos_pq;
406 u16 first_rl_pq;
407 u16 num_pqs;
408 u16 num_vf_pqs;
409 u8 num_vports;
410 u8 max_phys_tcs_per_port;
411 u8 ooo_tc;
412 bool pf_rl_en;
413 bool pf_wfq_en;
414 bool vport_rl_en;
415 bool vport_wfq_en;
416 u8 pf_wfq;
417 u32 pf_rl;
418 struct qed_wfq_data *wfq_data;
419 u8 num_pf_rls;
420};
421
422struct storm_stats {
423 u32 address;
424 u32 len;
425};
426
427struct qed_storm_stats {
428 struct storm_stats mstats;
429 struct storm_stats pstats;
430 struct storm_stats tstats;
431 struct storm_stats ustats;
432};
433
434struct qed_fw_data {
435 struct fw_ver_info *fw_ver_info;
436 const u8 *modes_tree_buf;
437 union init_op *init_ops;
438 const u32 *arr_data;
439 u32 init_ops_size;
440};
441
442enum BAR_ID {
443 BAR_ID_0, /* used for GRC */
444 BAR_ID_1 /* Used for doorbells */
445};
446
447struct qed_nvm_image_info {
448 u32 num_images;
449 struct bist_nvm_image_att *image_att;
450};
451
452#define DRV_MODULE_VERSION \
453 __stringify(QED_MAJOR_VERSION) "." \
454 __stringify(QED_MINOR_VERSION) "." \
455 __stringify(QED_REVISION_VERSION) "." \
456 __stringify(QED_ENGINEERING_VERSION)
457
458struct qed_simd_fp_handler {
459 void *token;
460 void (*func)(void *);
461};
462
463struct qed_hwfn {
464 struct qed_dev *cdev;
465 u8 my_id; /* ID inside the PF */
466#define IS_LEAD_HWFN(edev) (!((edev)->my_id))
467 u8 rel_pf_id; /* Relative to engine*/
468 u8 abs_pf_id;
469#define QED_PATH_ID(_p_hwfn) \
470 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
471 u8 port_id;
472 bool b_active;
473
474 u32 dp_module;
475 u8 dp_level;
476 char name[NAME_SIZE];
477
478 bool first_on_engine;
479 bool hw_init_done;
480
481 u8 num_funcs_on_engine;
482 u8 enabled_func_idx;
483
484 /* BAR access */
485 void __iomem *regview;
486 void __iomem *doorbells;
487 u64 db_phys_addr;
488 unsigned long db_size;
489
490 /* PTT pool */
491 struct qed_ptt_pool *p_ptt_pool;
492
493 /* HW info */
494 struct qed_hw_info hw_info;
495
496 /* rt_array (for init-tool) */
497 struct qed_rt_data rt_data;
498
499 /* SPQ */
500 struct qed_spq *p_spq;
501
502 /* EQ */
503 struct qed_eq *p_eq;
504
505 /* Consolidate Q*/
506 struct qed_consq *p_consq;
507
508 /* Slow-Path definitions */
509 struct tasklet_struct *sp_dpc;
510 bool b_sp_dpc_enabled;
511
512 struct qed_ptt *p_main_ptt;
513 struct qed_ptt *p_dpc_ptt;
514
515 /* PTP will be used only by the leading function.
516 * Usage of all PTP-apis should be synchronized as result.
517 */
518 struct qed_ptt *p_ptp_ptt;
519
520 struct qed_sb_sp_info *p_sp_sb;
521 struct qed_sb_attn_info *p_sb_attn;
522
523 /* Protocol related */
524 bool using_ll2;
525 struct qed_ll2_info *p_ll2_info;
526 struct qed_ooo_info *p_ooo_info;
527 struct qed_rdma_info *p_rdma_info;
528 struct qed_iscsi_info *p_iscsi_info;
529 struct qed_fcoe_info *p_fcoe_info;
530 struct qed_pf_params pf_params;
531
532 bool b_rdma_enabled_in_prs;
533 u32 rdma_prs_search_reg;
534
535 struct qed_cxt_mngr *p_cxt_mngr;
536
537 /* Flag indicating whether interrupts are enabled or not*/
538 bool b_int_enabled;
539 bool b_int_requested;
540
541 /* True if the driver requests for the link */
542 bool b_drv_link_init;
543
544 struct qed_vf_iov *vf_iov_info;
545 struct qed_pf_iov *pf_iov_info;
546 struct qed_mcp_info *mcp_info;
547
548 struct qed_dcbx_info *p_dcbx_info;
549
550 struct qed_dmae_info dmae_info;
551
552 /* QM init */
553 struct qed_qm_info qm_info;
554 struct qed_storm_stats storm_stats;
555
556 /* Buffer for unzipping firmware data */
557 void *unzip_buf;
558
559 struct dbg_tools_data dbg_info;
560
561 /* PWM region specific data */
562 u16 wid_count;
563 u32 dpi_size;
564 u32 dpi_count;
565
566 /* This is used to calculate the doorbell address */
567 u32 dpi_start_offset;
568
569 /* If one of the following is set then EDPM shouldn't be used */
570 u8 dcbx_no_edpm;
571 u8 db_bar_no_edpm;
572
573 /* L2-related */
574 struct qed_l2_info *p_l2_info;
575
576 /* Nvm images number and attributes */
577 struct qed_nvm_image_info nvm_info;
578
579 struct qed_ptt *p_arfs_ptt;
580
581 struct qed_simd_fp_handler simd_proto_handler[64];
582
583#ifdef CONFIG_QED_SRIOV
584 struct workqueue_struct *iov_wq;
585 struct delayed_work iov_task;
586 unsigned long iov_task_flags;
587#endif
588
589 struct z_stream_s *stream;
590};
591
592struct pci_params {
593 int pm_cap;
594
595 unsigned long mem_start;
596 unsigned long mem_end;
597 unsigned int irq;
598 u8 pf_num;
599};
600
601struct qed_int_param {
602 u32 int_mode;
603 u8 num_vectors;
604 u8 min_msix_cnt; /* for minimal functionality */
605};
606
607struct qed_int_params {
608 struct qed_int_param in;
609 struct qed_int_param out;
610 struct msix_entry *msix_table;
611 bool fp_initialized;
612 u8 fp_msix_base;
613 u8 fp_msix_cnt;
614 u8 rdma_msix_base;
615 u8 rdma_msix_cnt;
616};
617
618struct qed_dbg_feature {
619 struct dentry *dentry;
620 u8 *dump_buf;
621 u32 buf_size;
622 u32 dumped_dwords;
623};
624
625struct qed_dbg_params {
626 struct qed_dbg_feature features[DBG_FEATURE_NUM];
627 u8 engine_for_debug;
628 bool print_data;
629};
630
631struct qed_dev {
632 u32 dp_module;
633 u8 dp_level;
634 char name[NAME_SIZE];
635
636 enum qed_dev_type type;
637/* Translate type/revision combo into the proper conditions */
638#define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
639#define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
640 CHIP_REV_IS_B0(dev))
641#define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
642#define QED_IS_K2(dev) QED_IS_AH(dev)
643
644 u16 vendor_id;
645 u16 device_id;
646#define QED_DEV_ID_MASK 0xff00
647#define QED_DEV_ID_MASK_BB 0x1600
648#define QED_DEV_ID_MASK_AH 0x8000
649
650 u16 chip_num;
651#define CHIP_NUM_MASK 0xffff
652#define CHIP_NUM_SHIFT 16
653
654 u16 chip_rev;
655#define CHIP_REV_MASK 0xf
656#define CHIP_REV_SHIFT 12
657#define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
658
659 u16 chip_metal;
660#define CHIP_METAL_MASK 0xff
661#define CHIP_METAL_SHIFT 4
662
663 u16 chip_bond_id;
664#define CHIP_BOND_ID_MASK 0xf
665#define CHIP_BOND_ID_SHIFT 0
666
667 u8 num_engines;
668 u8 num_ports_in_engine;
669 u8 num_funcs_in_port;
670
671 u8 path_id;
672 enum qed_mf_mode mf_mode;
673#define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
674#define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
675#define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
676
677 int pcie_width;
678 int pcie_speed;
679
680 /* Add MF related configuration */
681 u8 mcp_rev;
682 u8 boot_mode;
683
684 /* WoL related configurations */
685 u8 wol_config;
686 u8 wol_mac[ETH_ALEN];
687
688 u32 int_mode;
689 enum qed_coalescing_mode int_coalescing_mode;
690 u16 rx_coalesce_usecs;
691 u16 tx_coalesce_usecs;
692
693 /* Start Bar offset of first hwfn */
694 void __iomem *regview;
695 void __iomem *doorbells;
696 u64 db_phys_addr;
697 unsigned long db_size;
698
699 /* PCI */
700 u8 cache_shift;
701
702 /* Init */
703 const struct iro *iro_arr;
704#define IRO (p_hwfn->cdev->iro_arr)
705
706 /* HW functions */
707 u8 num_hwfns;
708 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
709
710 /* SRIOV */
711 struct qed_hw_sriov_info *p_iov_info;
712#define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
713 struct qed_tunnel_info tunnel;
714 bool b_is_vf;
715 u32 drv_type;
716 struct qed_eth_stats *reset_stats;
717 struct qed_fw_data *fw_data;
718
719 u32 mcp_nvm_resp;
720
721 /* Linux specific here */
722 struct qede_dev *edev;
723 struct pci_dev *pdev;
724 u32 flags;
725#define QED_FLAG_STORAGE_STARTED (BIT(0))
726 int msg_enable;
727
728 struct pci_params pci_params;
729
730 struct qed_int_params int_params;
731
732 u8 protocol;
733#define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
734#define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
735
736 /* Callbacks to protocol driver */
737 union {
738 struct qed_common_cb_ops *common;
739 struct qed_eth_cb_ops *eth;
740 struct qed_fcoe_cb_ops *fcoe;
741 struct qed_iscsi_cb_ops *iscsi;
742 } protocol_ops;
743 void *ops_cookie;
744
745 struct qed_dbg_params dbg_params;
746
747#ifdef CONFIG_QED_LL2
748 struct qed_cb_ll2_info *ll2;
749 u8 ll2_mac_address[ETH_ALEN];
750#endif
751 DECLARE_HASHTABLE(connections, 10);
752 const struct firmware *firmware;
753
754 u32 rdma_max_sge;
755 u32 rdma_max_inline;
756 u32 rdma_max_srq_sge;
757 u16 tunn_feature_mask;
758};
759
760#define NUM_OF_VFS(dev) (QED_IS_BB(dev) ? MAX_NUM_VFS_BB \
761 : MAX_NUM_VFS_K2)
762#define NUM_OF_L2_QUEUES(dev) (QED_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
763 : MAX_NUM_L2_QUEUES_K2)
764#define NUM_OF_PORTS(dev) (QED_IS_BB(dev) ? MAX_NUM_PORTS_BB \
765 : MAX_NUM_PORTS_K2)
766#define NUM_OF_SBS(dev) (QED_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
767 : MAX_SB_PER_PATH_K2)
768#define NUM_OF_ENG_PFS(dev) (QED_IS_BB(dev) ? MAX_NUM_PFS_BB \
769 : MAX_NUM_PFS_K2)
770
771/**
772 * @brief qed_concrete_to_sw_fid - get the sw function id from
773 * the concrete value.
774 *
775 * @param concrete_fid
776 *
777 * @return inline u8
778 */
779static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
780 u32 concrete_fid)
781{
782 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
783 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
784 u8 vf_valid = GET_FIELD(concrete_fid,
785 PXP_CONCRETE_FID_VFVALID);
786 u8 sw_fid;
787
788 if (vf_valid)
789 sw_fid = vfid + MAX_NUM_PFS;
790 else
791 sw_fid = pfid;
792
793 return sw_fid;
794}
795
796#define PKT_LB_TC 9
797#define MAX_NUM_VOQS_E4 20
798
799int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
800void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
801 struct qed_ptt *p_ptt,
802 u32 min_pf_rate);
803
804void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
805int qed_device_num_engines(struct qed_dev *cdev);
806int qed_device_get_port_id(struct qed_dev *cdev);
807void qed_set_fw_mac_addr(__le16 *fw_msb,
808 __le16 *fw_mid, __le16 *fw_lsb, u8 *mac);
809
810#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
811
812/* Flags for indication of required queues */
813#define PQ_FLAGS_RLS (BIT(0))
814#define PQ_FLAGS_MCOS (BIT(1))
815#define PQ_FLAGS_LB (BIT(2))
816#define PQ_FLAGS_OOO (BIT(3))
817#define PQ_FLAGS_ACK (BIT(4))
818#define PQ_FLAGS_OFLD (BIT(5))
819#define PQ_FLAGS_VFS (BIT(6))
820#define PQ_FLAGS_LLT (BIT(7))
821
822/* physical queue index for cm context intialization */
823u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags);
824u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc);
825u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf);
826
827#define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
828
829/* Other Linux specific common definitions */
830#define DP_NAME(cdev) ((cdev)->name)
831
832#define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
833 (cdev->regview) + \
834 (offset))
835
836#define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
837#define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
838#define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
839
840#define DOORBELL(cdev, db_addr, val) \
841 writel((u32)val, (void __iomem *)((u8 __iomem *)\
842 (cdev->doorbells) + (db_addr)))
843
844/* Prototypes */
845int qed_fill_dev_info(struct qed_dev *cdev,
846 struct qed_dev_info *dev_info);
847void qed_link_update(struct qed_hwfn *hwfn);
848u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
849 u32 input_len, u8 *input_buf,
850 u32 max_size, u8 *unzip_buf);
851void qed_get_protocol_stats(struct qed_dev *cdev,
852 enum qed_mcp_protocol_type type,
853 union qed_mcp_protocol_stats *stats);
854int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
855void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn);
856
857#endif /* _QED_H */