1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
36 #include <linux/types.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"
53 extern const struct qed_common_ops qed_common_ops_pass;
55 #define QED_MAJOR_VERSION 8
56 #define QED_MINOR_VERSION 10
57 #define QED_REVISION_VERSION 10
58 #define QED_ENGINEERING_VERSION 21
61 ((QED_MAJOR_VERSION << 24) | (QED_MINOR_VERSION << 16) | \
62 (QED_REVISION_VERSION << 8) | QED_ENGINEERING_VERSION)
64 #define STORM_FW_VERSION \
65 ((FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | \
66 (FW_REVISION_VERSION << 8) | FW_ENGINEERING_VERSION)
68 #define MAX_HWFNS_PER_DEVICE (4)
72 #define QED_WFQ_UNIT 100
74 #define ISCSI_BDQ_ID(_port_id) (_port_id)
75 #define FCOE_BDQ_ID(_port_id) ((_port_id) + 2)
76 #define QED_WID_SIZE (1024)
77 #define QED_PF_DEMS_SIZE (4)
80 enum qed_coalescing_mode {
81 QED_COAL_MODE_DISABLE,
85 struct qed_eth_cb_ops;
87 union qed_mcp_protocol_stats;
88 enum qed_mcp_protocol_type;
91 #define QED_MFW_GET_FIELD(name, field) \
92 (((name) & (field ## _MASK)) >> (field ## _SHIFT))
94 #define QED_MFW_SET_FIELD(name, field, value) \
96 (name) &= ~((field ## _MASK) << (field ## _SHIFT)); \
97 (name) |= (((value) << (field ## _SHIFT)) & (field ## _MASK));\
100 static inline u32 qed_db_addr(u32 cid, u32 DEMS)
102 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
103 (cid * QED_PF_DEMS_SIZE);
108 static inline u32 qed_db_addr_vf(u32 cid, u32 DEMS)
110 u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
111 FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
116 #define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
117 ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
118 ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
120 #define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
122 #define D_TRINE(val, cond1, cond2, true1, true2, def) \
123 (val == (cond1) ? true1 : \
124 (val == (cond2) ? true2 : def))
130 struct qed_sb_attn_info;
132 struct qed_sb_sp_info;
142 QED_MODE_L2GENEVE_TUNN,
143 QED_MODE_IPGENEVE_TUNN,
150 QED_TUNN_CLSS_MAC_VLAN,
151 QED_TUNN_CLSS_MAC_VNI,
152 QED_TUNN_CLSS_INNER_MAC_VLAN,
153 QED_TUNN_CLSS_INNER_MAC_VNI,
157 struct qed_tunn_start_params {
158 unsigned long tunn_mode;
161 u8 update_vxlan_udp_port;
162 u8 update_geneve_udp_port;
164 u8 tunn_clss_l2geneve;
165 u8 tunn_clss_ipgeneve;
170 struct qed_tunn_update_params {
171 unsigned long tunn_mode_update_mask;
172 unsigned long tunn_mode;
175 u8 update_rx_pf_clss;
176 u8 update_tx_pf_clss;
177 u8 update_vxlan_udp_port;
178 u8 update_geneve_udp_port;
180 u8 tunn_clss_l2geneve;
181 u8 tunn_clss_ipgeneve;
186 /* The PCI personality is not quite synonymous to protocol ID:
187 * 1. All personalities need CORE connections
188 * 2. The Ethernet personality may support also the RoCE protocol
190 enum qed_pci_personality {
195 QED_PCI_DEFAULT /* default in shmem */
198 /* All VFs are symmetric, all counters are PF + all VFs */
205 /* HW / FW resources, output of features supported below, most information
206 * is received from MFW.
221 QED_RDMA_STATS_QUEUE,
236 QED_PORT_MODE_DE_2X40G,
237 QED_PORT_MODE_DE_2X50G,
238 QED_PORT_MODE_DE_1X100G,
239 QED_PORT_MODE_DE_4X10G_F,
240 QED_PORT_MODE_DE_4X10G_E,
241 QED_PORT_MODE_DE_4X20G,
242 QED_PORT_MODE_DE_1X40G,
243 QED_PORT_MODE_DE_2X25G,
244 QED_PORT_MODE_DE_1X25G,
245 QED_PORT_MODE_DE_4X25G,
246 QED_PORT_MODE_DE_2X10G,
256 enum qed_wol_support {
257 QED_WOL_SUPPORT_NONE,
262 /* PCI personality */
263 enum qed_pci_personality personality;
265 /* Resource Allocation scheme results */
266 u32 resc_start[QED_MAX_RESC];
267 u32 resc_num[QED_MAX_RESC];
268 u32 feat_num[QED_MAX_FEATURES];
270 #define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
271 #define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
272 #define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
273 RESC_NUM(_p_hwfn, resc))
274 #define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
285 unsigned char hw_mac_addr[ETH_ALEN];
291 struct qed_igu_info *p_igu_info;
295 unsigned long device_capabilities;
298 enum qed_wol_support b_wol_support;
301 /* maximun size of read/write commands (HW limit) */
302 #define DMAE_MAX_RW_SIZE 0x2000
304 struct qed_dmae_info {
305 /* Mutex for synchronizing access to functions */
310 dma_addr_t completion_word_phys_addr;
312 /* The memory location where the DMAE writes the completion
313 * value when an operation is finished on this context.
315 u32 *p_completion_word;
317 dma_addr_t intermediate_buffer_phys_addr;
319 /* An intermediate buffer for DMAE operations that use virtual
320 * addresses - data is DMA'd to/from this buffer and then
321 * memcpy'd to/from the virtual address
323 u32 *p_intermediate_buffer;
325 dma_addr_t dmae_cmd_phys_addr;
326 struct dmae_cmd *p_dmae_cmd;
329 struct qed_wfq_data {
330 /* when feature is configured for at least 1 vport */
336 struct init_qm_pq_params *qm_pq_params;
337 struct init_qm_vport_params *qm_vport_params;
338 struct init_qm_port_params *qm_port_params;
349 u8 max_phys_tcs_per_port;
356 struct qed_wfq_data *wfq_data;
365 struct qed_storm_stats {
366 struct storm_stats mstats;
367 struct storm_stats pstats;
368 struct storm_stats tstats;
369 struct storm_stats ustats;
373 struct fw_ver_info *fw_ver_info;
374 const u8 *modes_tree_buf;
375 union init_op *init_ops;
380 #define DRV_MODULE_VERSION \
381 __stringify(QED_MAJOR_VERSION) "." \
382 __stringify(QED_MINOR_VERSION) "." \
383 __stringify(QED_REVISION_VERSION) "." \
384 __stringify(QED_ENGINEERING_VERSION)
386 struct qed_simd_fp_handler {
388 void (*func)(void *);
392 struct qed_dev *cdev;
393 u8 my_id; /* ID inside the PF */
394 #define IS_LEAD_HWFN(edev) (!((edev)->my_id))
395 u8 rel_pf_id; /* Relative to engine*/
397 #define QED_PATH_ID(_p_hwfn) \
398 (QED_IS_K2((_p_hwfn)->cdev) ? 0 : ((_p_hwfn)->abs_pf_id & 1))
404 char name[NAME_SIZE];
406 bool first_on_engine;
409 u8 num_funcs_on_engine;
413 void __iomem *regview;
414 void __iomem *doorbells;
416 unsigned long db_size;
419 struct qed_ptt_pool *p_ptt_pool;
422 struct qed_hw_info hw_info;
424 /* rt_array (for init-tool) */
425 struct qed_rt_data rt_data;
428 struct qed_spq *p_spq;
434 struct qed_consq *p_consq;
436 /* Slow-Path definitions */
437 struct tasklet_struct *sp_dpc;
438 bool b_sp_dpc_enabled;
440 struct qed_ptt *p_main_ptt;
441 struct qed_ptt *p_dpc_ptt;
443 struct qed_sb_sp_info *p_sp_sb;
444 struct qed_sb_attn_info *p_sb_attn;
446 /* Protocol related */
448 struct qed_ll2_info *p_ll2_info;
449 struct qed_ooo_info *p_ooo_info;
450 struct qed_rdma_info *p_rdma_info;
451 struct qed_iscsi_info *p_iscsi_info;
452 struct qed_fcoe_info *p_fcoe_info;
453 struct qed_pf_params pf_params;
455 bool b_rdma_enabled_in_prs;
456 u32 rdma_prs_search_reg;
458 /* Array of sb_info of all status blocks */
459 struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
462 struct qed_cxt_mngr *p_cxt_mngr;
464 /* Flag indicating whether interrupts are enabled or not*/
466 bool b_int_requested;
468 /* True if the driver requests for the link */
469 bool b_drv_link_init;
471 struct qed_vf_iov *vf_iov_info;
472 struct qed_pf_iov *pf_iov_info;
473 struct qed_mcp_info *mcp_info;
475 struct qed_dcbx_info *p_dcbx_info;
477 struct qed_dmae_info dmae_info;
480 struct qed_qm_info qm_info;
481 struct qed_storm_stats storm_stats;
483 /* Buffer for unzipping firmware data */
486 struct dbg_tools_data dbg_info;
488 /* PWM region specific data */
492 /* This is used to calculate the doorbell address */
493 u32 dpi_start_offset;
495 /* If one of the following is set then EDPM shouldn't be used */
499 /* p_ptp_ptt is valid for leading HWFN only */
500 struct qed_ptt *p_ptp_ptt;
501 struct qed_simd_fp_handler simd_proto_handler[64];
503 #ifdef CONFIG_QED_SRIOV
504 struct workqueue_struct *iov_wq;
505 struct delayed_work iov_task;
506 unsigned long iov_task_flags;
509 struct z_stream_s *stream;
510 struct qed_roce_ll2_info *ll2;
516 unsigned long mem_start;
517 unsigned long mem_end;
522 struct qed_int_param {
525 u8 min_msix_cnt; /* for minimal functionality */
528 struct qed_int_params {
529 struct qed_int_param in;
530 struct qed_int_param out;
531 struct msix_entry *msix_table;
539 struct qed_dbg_feature {
540 struct dentry *dentry;
546 struct qed_dbg_params {
547 struct qed_dbg_feature features[DBG_FEATURE_NUM];
555 char name[NAME_SIZE];
557 enum qed_dev_type type;
558 /* Translate type/revision combo into the proper conditions */
559 #define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
560 #define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
562 #define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
564 #define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
565 #define QED_IS_K2(dev) QED_IS_AH(dev)
567 #define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
568 QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
572 #define QED_DEV_ID_MASK 0xff00
573 #define QED_DEV_ID_MASK_BB 0x1600
574 #define QED_DEV_ID_MASK_AH 0x8000
577 #define CHIP_NUM_MASK 0xffff
578 #define CHIP_NUM_SHIFT 16
581 #define CHIP_REV_MASK 0xf
582 #define CHIP_REV_SHIFT 12
583 #define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
584 #define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
587 #define CHIP_METAL_MASK 0xff
588 #define CHIP_METAL_SHIFT 4
591 #define CHIP_BOND_ID_MASK 0xf
592 #define CHIP_BOND_ID_SHIFT 0
595 u8 num_ports_in_engines;
596 u8 num_funcs_in_port;
599 enum qed_mf_mode mf_mode;
600 #define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
601 #define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
602 #define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
606 u8 ver_str[VER_SIZE];
608 /* Add MF related configuration */
612 /* WoL related configurations */
614 u8 wol_mac[ETH_ALEN];
617 enum qed_coalescing_mode int_coalescing_mode;
618 u16 rx_coalesce_usecs;
619 u16 tx_coalesce_usecs;
621 /* Start Bar offset of first hwfn */
622 void __iomem *regview;
623 void __iomem *doorbells;
625 unsigned long db_size;
631 const struct iro *iro_arr;
632 #define IRO (p_hwfn->cdev->iro_arr)
636 struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
639 struct qed_hw_sriov_info *p_iov_info;
640 #define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
642 unsigned long tunn_mode;
646 struct qed_eth_stats *reset_stats;
647 struct qed_fw_data *fw_data;
651 /* Linux specific here */
652 struct qede_dev *edev;
653 struct pci_dev *pdev;
655 #define QED_FLAG_STORAGE_STARTED (BIT(0))
658 struct pci_params pci_params;
660 struct qed_int_params int_params;
663 #define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
664 #define IS_QED_FCOE_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_FCOE)
666 /* Callbacks to protocol driver */
668 struct qed_common_cb_ops *common;
669 struct qed_eth_cb_ops *eth;
670 struct qed_fcoe_cb_ops *fcoe;
671 struct qed_iscsi_cb_ops *iscsi;
675 struct qed_dbg_params dbg_params;
677 #ifdef CONFIG_QED_LL2
678 struct qed_cb_ll2_info *ll2;
679 u8 ll2_mac_address[ETH_ALEN];
681 DECLARE_HASHTABLE(connections, 10);
682 const struct firmware *firmware;
686 u32 rdma_max_srq_sge;
689 #define NUM_OF_VFS(dev) (QED_IS_BB(dev) ? MAX_NUM_VFS_BB \
691 #define NUM_OF_L2_QUEUES(dev) (QED_IS_BB(dev) ? MAX_NUM_L2_QUEUES_BB \
692 : MAX_NUM_L2_QUEUES_K2)
693 #define NUM_OF_PORTS(dev) (QED_IS_BB(dev) ? MAX_NUM_PORTS_BB \
695 #define NUM_OF_SBS(dev) (QED_IS_BB(dev) ? MAX_SB_PER_PATH_BB \
696 : MAX_SB_PER_PATH_K2)
697 #define NUM_OF_ENG_PFS(dev) (QED_IS_BB(dev) ? MAX_NUM_PFS_BB \
701 * @brief qed_concrete_to_sw_fid - get the sw function id from
702 * the concrete value.
704 * @param concrete_fid
708 static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
711 u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
712 u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
713 u8 vf_valid = GET_FIELD(concrete_fid,
714 PXP_CONCRETE_FID_VFVALID);
718 sw_fid = vfid + MAX_NUM_PFS;
728 int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
729 void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
730 struct qed_ptt *p_ptt,
733 void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
734 #define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
735 int qed_device_num_engines(struct qed_dev *cdev);
737 /* Other Linux specific common definitions */
738 #define DP_NAME(cdev) ((cdev)->name)
740 #define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
744 #define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
745 #define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
746 #define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
748 #define DOORBELL(cdev, db_addr, val) \
749 writel((u32)val, (void __iomem *)((u8 __iomem *)\
750 (cdev->doorbells) + (db_addr)))
753 int qed_fill_dev_info(struct qed_dev *cdev,
754 struct qed_dev_info *dev_info);
755 void qed_link_update(struct qed_hwfn *hwfn);
756 u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
757 u32 input_len, u8 *input_buf,
758 u32 max_size, u8 *unzip_buf);
759 void qed_get_protocol_stats(struct qed_dev *cdev,
760 enum qed_mcp_protocol_type type,
761 union qed_mcp_protocol_stats *stats);
762 int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
763 void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn);