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>
37 #include <linux/interrupt.h>
38 #include <linux/netdevice.h>
39 #include <linux/pci.h>
40 #include <linux/skbuff.h>
41 #include <asm/byteorder.h>
43 #include <linux/compiler.h>
44 #include <linux/kernel.h>
45 #include <linux/list.h>
46 #include <linux/slab.h>
47 #include <linux/qed/common_hsi.h>
48 #include <linux/qed/qed_chain.h>
49 #include <linux/io-64-nonatomic-lo-hi.h>
51 enum dcbx_protocol_type {
55 DCBX_PROTOCOL_ROCE_V2,
57 DCBX_MAX_PROTOCOL_TYPE
60 #define QED_ROCE_PROTOCOL_INDEX (3)
62 #define QED_LLDP_CHASSIS_ID_STAT_LEN 4
63 #define QED_LLDP_PORT_ID_STAT_LEN 4
64 #define QED_DCBX_MAX_APP_PROTOCOL 32
65 #define QED_MAX_PFC_PRIORITIES 8
66 #define QED_DCBX_DSCP_SIZE 64
68 struct qed_dcbx_lldp_remote {
69 u32 peer_chassis_id[QED_LLDP_CHASSIS_ID_STAT_LEN];
70 u32 peer_port_id[QED_LLDP_PORT_ID_STAT_LEN];
77 struct qed_dcbx_lldp_local {
78 u32 local_chassis_id[QED_LLDP_CHASSIS_ID_STAT_LEN];
79 u32 local_port_id[QED_LLDP_PORT_ID_STAT_LEN];
82 struct qed_dcbx_app_prio {
90 struct qed_dbcx_pfc_params {
93 u8 prio[QED_MAX_PFC_PRIORITIES];
97 enum qed_dcbx_sf_ieee_type {
98 QED_DCBX_SF_IEEE_ETHTYPE,
99 QED_DCBX_SF_IEEE_TCP_PORT,
100 QED_DCBX_SF_IEEE_UDP_PORT,
101 QED_DCBX_SF_IEEE_TCP_UDP_PORT
104 struct qed_app_entry {
106 enum qed_dcbx_sf_ieee_type sf_ieee;
110 enum dcbx_protocol_type proto_type;
113 struct qed_dcbx_params {
114 struct qed_app_entry app_entry[QED_DCBX_MAX_APP_PROTOCOL];
123 u8 ets_pri_tc_tbl[QED_MAX_PFC_PRIORITIES];
124 u8 ets_tc_bw_tbl[QED_MAX_PFC_PRIORITIES];
125 u8 ets_tc_tsa_tbl[QED_MAX_PFC_PRIORITIES];
126 struct qed_dbcx_pfc_params pfc;
130 struct qed_dcbx_admin_params {
131 struct qed_dcbx_params params;
135 struct qed_dcbx_remote_params {
136 struct qed_dcbx_params params;
140 struct qed_dcbx_operational_params {
141 struct qed_dcbx_app_prio app_prio;
142 struct qed_dcbx_params params;
151 struct qed_dcbx_get {
152 struct qed_dcbx_operational_params operational;
153 struct qed_dcbx_lldp_remote lldp_remote;
154 struct qed_dcbx_lldp_local lldp_local;
155 struct qed_dcbx_remote_params remote;
156 struct qed_dcbx_admin_params local;
159 enum qed_nvm_images {
160 QED_NVM_IMAGE_ISCSI_CFG,
161 QED_NVM_IMAGE_FCOE_CFG,
163 QED_NVM_IMAGE_NVM_CFG1,
164 QED_NVM_IMAGE_DEFAULT_CFG,
165 QED_NVM_IMAGE_NVM_META,
168 struct qed_link_eee_params {
170 #define QED_EEE_1G_ADV BIT(0)
171 #define QED_EEE_10G_ADV BIT(1)
173 /* Capabilities are represented using QED_EEE_*_ADV values */
186 struct qed_mfw_tlv_eth {
188 bool lso_maxoff_size_set;
190 bool lso_minseg_size_set;
194 bool tx_descr_size_set;
196 bool rx_descr_size_set;
200 bool tcp4_offloads_set;
202 bool tcp6_offloads_set;
204 bool tx_descr_qdepth_set;
206 bool rx_descr_qdepth_set;
208 #define QED_MFW_TLV_IOV_OFFLOAD_NONE (0)
209 #define QED_MFW_TLV_IOV_OFFLOAD_MULTIQUEUE (1)
210 #define QED_MFW_TLV_IOV_OFFLOAD_VEB (2)
211 #define QED_MFW_TLV_IOV_OFFLOAD_VEPA (3)
212 bool iov_offload_set;
218 bool num_txqs_full_set;
220 bool num_rxqs_full_set;
223 #define QED_MFW_TLV_TIME_SIZE 14
224 struct qed_mfw_tlv_time {
234 struct qed_mfw_tlv_fcoe {
236 bool scsi_timeout_set;
250 bool num_npiv_ids_set;
252 bool switch_name_set;
254 bool switch_portnum_set;
256 bool switch_portid_set;
258 bool vendor_name_set;
260 bool switch_model_set;
261 u8 switch_fw_version[8];
262 bool switch_fw_version_set;
268 #define QED_MFW_TLV_PORT_STATE_OFFLINE (0)
269 #define QED_MFW_TLV_PORT_STATE_LOOP (1)
270 #define QED_MFW_TLV_PORT_STATE_P2P (2)
271 #define QED_MFW_TLV_PORT_STATE_FABRIC (3)
273 u16 fip_tx_descr_size;
274 bool fip_tx_descr_size_set;
275 u16 fip_rx_descr_size;
276 bool fip_rx_descr_size_set;
278 bool link_failures_set;
279 u8 fcoe_boot_progress;
280 bool fcoe_boot_progress_set;
286 bool fcoe_txq_depth_set;
288 bool fcoe_rxq_depth_set;
290 bool fcoe_rx_frames_set;
292 bool fcoe_rx_bytes_set;
294 bool fcoe_tx_frames_set;
296 bool fcoe_tx_bytes_set;
299 u32 crc_err_src_fcid[5];
300 bool crc_err_src_fcid_set[5];
301 struct qed_mfw_tlv_time crc_err[5];
307 bool primtive_err_set;
309 bool disparity_err_set;
310 u16 code_violation_err;
311 bool code_violation_err_set;
313 bool flogi_param_set[4];
314 struct qed_mfw_tlv_time flogi_tstamp;
315 u32 flogi_acc_param[4];
316 bool flogi_acc_param_set[4];
317 struct qed_mfw_tlv_time flogi_acc_tstamp;
320 struct qed_mfw_tlv_time flogi_rjt_tstamp;
333 u32 plogi_dst_fcid[5];
334 bool plogi_dst_fcid_set[5];
335 struct qed_mfw_tlv_time plogi_tstamp[5];
336 u32 plogi_acc_src_fcid[5];
337 bool plogi_acc_src_fcid_set[5];
338 struct qed_mfw_tlv_time plogi_acc_tstamp[5];
345 u32 plogo_src_fcid[5];
346 bool plogo_src_fcid_set[5];
347 struct qed_mfw_tlv_time plogo_tstamp[5];
359 bool rx_abts_acc_set;
361 bool rx_abts_rjt_set;
362 u32 abts_dst_fcid[5];
363 bool abts_dst_fcid_set[5];
364 struct qed_mfw_tlv_time abts_tstamp[5];
367 u32 rx_rscn_nport[4];
368 bool rx_rscn_nport_set[4];
372 bool abort_task_sets_set;
396 bool scsi_cond_met_set;
401 u8 scsi_inter_cond_met;
402 bool scsi_inter_cond_met_set;
403 u8 scsi_rsv_conflicts;
404 bool scsi_rsv_conflicts_set;
406 bool scsi_tsk_full_set;
408 bool scsi_aca_active_set;
410 bool scsi_tsk_abort_set;
412 bool scsi_rx_chk_set[5];
413 struct qed_mfw_tlv_time scsi_chk_tstamp[5];
416 struct qed_mfw_tlv_iscsi {
418 bool target_llmnr_set;
420 bool header_digest_set;
422 bool data_digest_set;
424 #define QED_MFW_TLV_AUTH_METHOD_NONE (1)
425 #define QED_MFW_TLV_AUTH_METHOD_CHAP (2)
426 #define QED_MFW_TLV_AUTH_METHOD_MUTUAL_CHAP (3)
427 bool auth_method_set;
428 u16 boot_taget_portal;
429 bool boot_taget_portal_set;
433 bool tx_desc_size_set;
435 bool rx_desc_size_set;
437 bool boot_progress_set;
439 bool tx_desc_qdepth_set;
441 bool rx_desc_qdepth_set;
452 enum qed_db_rec_width {
457 enum qed_db_rec_space {
462 #define DIRECT_REG_WR(reg_addr, val) writel((u32)val, \
463 (void __iomem *)(reg_addr))
465 #define DIRECT_REG_RD(reg_addr) readl((void __iomem *)(reg_addr))
467 #define DIRECT_REG_WR64(reg_addr, val) writeq((u64)val, \
468 (void __iomem *)(reg_addr))
470 #define QED_COALESCE_MAX 0x1FF
471 #define QED_DEFAULT_RX_USECS 12
472 #define QED_DEFAULT_TX_USECS 48
477 struct qed_eth_pf_params {
478 /* The following parameters are used during HW-init
479 * and these parameters need to be passed as arguments
480 * to update_pf_params routine invoked before slowpath start
484 /* per-VF number of CIDs */
486 #define ETH_PF_PARAMS_VF_CONS_DEFAULT (32)
488 /* To enable arfs, previous to HW-init a positive number needs to be
489 * set [as filters require allocated searcher ILT memory].
490 * This will set the maximal number of configured steering-filters.
492 u32 num_arfs_filters;
495 struct qed_fcoe_pf_params {
496 /* The following parameters are used during protocol-init */
497 u64 glbl_q_params_addr;
498 u64 bdq_pbl_base_addr[2];
500 /* The following parameters are used during HW-init
501 * and these parameters need to be passed as arguments
502 * to update_pf_params routine invoked before slowpath start
507 /* The following parameters are used during protocol-init */
508 u16 sq_num_pbl_pages;
511 u16 cmdq_num_entries;
512 u16 rq_buffer_log_size;
515 u16 bdq_xoff_threshold[2];
516 u16 bdq_xon_threshold[2];
518 u8 num_cqs; /* num of global CQs */
524 u8 bdq_pbl_num_entries[2];
527 /* Most of the the parameters below are described in the FW iSCSI / TCP HSI */
528 struct qed_iscsi_pf_params {
529 u64 glbl_q_params_addr;
530 u64 bdq_pbl_base_addr[3];
532 u16 cmdq_num_entries;
536 /* The following parameters are used during HW-init
537 * and these parameters need to be passed as arguments
538 * to update_pf_params routine invoked before slowpath start
543 /* The following parameters are used during protocol-init */
544 u16 half_way_close_timeout;
545 u16 bdq_xoff_threshold[3];
546 u16 bdq_xon_threshold[3];
547 u16 cmdq_xoff_threshold;
548 u16 cmdq_xon_threshold;
551 u8 num_sq_pages_in_ring;
552 u8 num_r2tq_pages_in_ring;
553 u8 num_uhq_pages_in_ring;
565 u8 soc_num_of_blocks_log;
566 u8 bdq_pbl_num_entries[3];
569 struct qed_rdma_pf_params {
570 /* Supplied to QED during resource allocation (may affect the ILT and
573 u32 min_dpis; /* number of requested DPIs */
574 u32 num_qps; /* number of requested Queue Pairs */
575 u32 num_srqs; /* number of requested SRQ */
576 u8 roce_edpm_mode; /* see QED_ROCE_EDPM_MODE_ENABLE */
577 u8 gl_pi; /* protocol index */
579 /* Will allocate rate limiters to be used with QPs */
583 struct qed_pf_params {
584 struct qed_eth_pf_params eth_pf_params;
585 struct qed_fcoe_pf_params fcoe_pf_params;
586 struct qed_iscsi_pf_params iscsi_pf_params;
587 struct qed_rdma_pf_params rdma_pf_params;
598 struct status_block_e4 *sb_virt;
600 u32 sb_ack; /* Last given ack */
602 void __iomem *igu_addr;
604 #define QED_SB_INFO_INIT 0x1
605 #define QED_SB_INFO_SETUP 0x2
607 struct qed_dev *cdev;
610 enum qed_hw_err_type {
612 QED_HW_ERR_MFW_RESP_FAIL,
614 QED_HW_ERR_DMAE_FAIL,
615 QED_HW_ERR_RAMROD_FAIL,
616 QED_HW_ERR_FW_ASSERT,
625 struct qed_dev_info {
626 unsigned long pci_mem_start;
627 unsigned long pci_mem_end;
628 unsigned int pci_irq;
641 #define QED_MFW_VERSION_0_MASK 0x000000FF
642 #define QED_MFW_VERSION_0_OFFSET 0
643 #define QED_MFW_VERSION_1_MASK 0x0000FF00
644 #define QED_MFW_VERSION_1_OFFSET 8
645 #define QED_MFW_VERSION_2_MASK 0x00FF0000
646 #define QED_MFW_VERSION_2_OFFSET 16
647 #define QED_MFW_VERSION_3_MASK 0xFF000000
648 #define QED_MFW_VERSION_3_OFFSET 24
651 bool b_inter_pf_switch;
661 #define QED_MBI_VERSION_0_MASK 0x000000FF
662 #define QED_MBI_VERSION_0_OFFSET 0
663 #define QED_MBI_VERSION_1_MASK 0x0000FF00
664 #define QED_MBI_VERSION_1_OFFSET 8
665 #define QED_MBI_VERSION_2_MASK 0x00FF0000
666 #define QED_MBI_VERSION_2_OFFSET 16
668 enum qed_dev_type dev_type;
670 /* Output parameters for qede */
679 QED_SB_TYPE_L2_QUEUE,
690 enum qed_link_mode_bits {
691 QED_LM_FIBRE_BIT = BIT(0),
692 QED_LM_Autoneg_BIT = BIT(1),
693 QED_LM_Asym_Pause_BIT = BIT(2),
694 QED_LM_Pause_BIT = BIT(3),
695 QED_LM_1000baseT_Full_BIT = BIT(4),
696 QED_LM_10000baseT_Full_BIT = BIT(5),
697 QED_LM_10000baseKR_Full_BIT = BIT(6),
698 QED_LM_20000baseKR2_Full_BIT = BIT(7),
699 QED_LM_25000baseKR_Full_BIT = BIT(8),
700 QED_LM_40000baseLR4_Full_BIT = BIT(9),
701 QED_LM_50000baseKR2_Full_BIT = BIT(10),
702 QED_LM_100000baseKR4_Full_BIT = BIT(11),
703 QED_LM_TP_BIT = BIT(12),
704 QED_LM_Backplane_BIT = BIT(13),
705 QED_LM_1000baseKX_Full_BIT = BIT(14),
706 QED_LM_10000baseKX4_Full_BIT = BIT(15),
707 QED_LM_10000baseR_FEC_BIT = BIT(16),
708 QED_LM_40000baseKR4_Full_BIT = BIT(17),
709 QED_LM_40000baseCR4_Full_BIT = BIT(18),
710 QED_LM_40000baseSR4_Full_BIT = BIT(19),
711 QED_LM_25000baseCR_Full_BIT = BIT(20),
712 QED_LM_25000baseSR_Full_BIT = BIT(21),
713 QED_LM_50000baseCR2_Full_BIT = BIT(22),
714 QED_LM_100000baseSR4_Full_BIT = BIT(23),
715 QED_LM_100000baseCR4_Full_BIT = BIT(24),
716 QED_LM_100000baseLR4_ER4_Full_BIT = BIT(25),
717 QED_LM_50000baseSR2_Full_BIT = BIT(26),
718 QED_LM_1000baseX_Full_BIT = BIT(27),
719 QED_LM_10000baseCR_Full_BIT = BIT(28),
720 QED_LM_10000baseSR_Full_BIT = BIT(29),
721 QED_LM_10000baseLR_Full_BIT = BIT(30),
722 QED_LM_10000baseLRM_Full_BIT = BIT(31),
726 struct qed_link_params {
729 #define QED_LINK_OVERRIDE_SPEED_AUTONEG BIT(0)
730 #define QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS BIT(1)
731 #define QED_LINK_OVERRIDE_SPEED_FORCED_SPEED BIT(2)
732 #define QED_LINK_OVERRIDE_PAUSE_CONFIG BIT(3)
733 #define QED_LINK_OVERRIDE_LOOPBACK_MODE BIT(4)
734 #define QED_LINK_OVERRIDE_EEE_CONFIG BIT(5)
739 #define QED_LINK_PAUSE_AUTONEG_ENABLE BIT(0)
740 #define QED_LINK_PAUSE_RX_ENABLE BIT(1)
741 #define QED_LINK_PAUSE_TX_ENABLE BIT(2)
743 #define QED_LINK_LOOPBACK_NONE BIT(0)
744 #define QED_LINK_LOOPBACK_INT_PHY BIT(1)
745 #define QED_LINK_LOOPBACK_EXT_PHY BIT(2)
746 #define QED_LINK_LOOPBACK_EXT BIT(3)
747 #define QED_LINK_LOOPBACK_MAC BIT(4)
749 struct qed_link_eee_params eee;
752 struct qed_link_output {
755 /* In QED_LM_* defs */
760 u32 speed; /* In Mb/s */
761 u8 duplex; /* In DUPLEX defs */
762 u8 port; /* In PORT defs */
766 /* EEE - capability & param */
770 struct qed_link_eee_params eee;
773 struct qed_probe_params {
774 enum qed_protocol protocol;
781 #define QED_DRV_VER_STR_SIZE 12
782 struct qed_slowpath_params {
788 u8 name[QED_DRV_VER_STR_SIZE];
791 #define ILT_PAGE_SIZE_TCFC 0x8000 /* 32KB */
793 struct qed_int_info {
794 struct msix_entry *msix;
797 /* This should be updated by the protocol driver */
801 struct qed_generic_tlvs {
802 #define QED_TLV_IP_CSUM BIT(0)
803 #define QED_TLV_LSO BIT(1)
805 #define QED_TLV_MAC_COUNT 3
806 u8 mac[QED_TLV_MAC_COUNT][ETH_ALEN];
809 #define QED_I2C_DEV_ADDR_A0 0xA0
810 #define QED_I2C_DEV_ADDR_A2 0xA2
812 #define QED_NVM_SIGNATURE 0x12435687
814 enum qed_nvm_flash_cmd {
815 QED_NVM_FLASH_CMD_FILE_DATA = 0x2,
816 QED_NVM_FLASH_CMD_FILE_START = 0x3,
817 QED_NVM_FLASH_CMD_NVM_CHANGE = 0x4,
818 QED_NVM_FLASH_CMD_NVM_CFG_ID = 0x5,
819 QED_NVM_FLASH_CMD_NVM_MAX,
822 struct qed_common_cb_ops {
823 void (*arfs_filter_op)(void *dev, void *fltr, u8 fw_rc);
824 void (*link_update)(void *dev, struct qed_link_output *link);
825 void (*schedule_recovery_handler)(void *dev);
826 void (*schedule_hw_err_handler)(void *dev,
827 enum qed_hw_err_type err_type);
828 void (*dcbx_aen)(void *dev, struct qed_dcbx_get *get, u32 mib_type);
829 void (*get_generic_tlv_data)(void *dev, struct qed_generic_tlvs *data);
830 void (*get_protocol_tlv_data)(void *dev, void *data);
831 void (*bw_update)(void *dev);
834 struct qed_selftest_ops {
836 * @brief selftest_interrupt - Perform interrupt test
840 * @return 0 on success, error otherwise.
842 int (*selftest_interrupt)(struct qed_dev *cdev);
845 * @brief selftest_memory - Perform memory test
849 * @return 0 on success, error otherwise.
851 int (*selftest_memory)(struct qed_dev *cdev);
854 * @brief selftest_register - Perform register test
858 * @return 0 on success, error otherwise.
860 int (*selftest_register)(struct qed_dev *cdev);
863 * @brief selftest_clock - Perform clock test
867 * @return 0 on success, error otherwise.
869 int (*selftest_clock)(struct qed_dev *cdev);
872 * @brief selftest_nvram - Perform nvram test
876 * @return 0 on success, error otherwise.
878 int (*selftest_nvram) (struct qed_dev *cdev);
881 struct qed_common_ops {
882 struct qed_selftest_ops *selftest;
884 struct qed_dev* (*probe)(struct pci_dev *dev,
885 struct qed_probe_params *params);
887 void (*remove)(struct qed_dev *cdev);
889 int (*set_power_state)(struct qed_dev *cdev,
892 void (*set_name) (struct qed_dev *cdev, char name[]);
894 /* Client drivers need to make this call before slowpath_start.
895 * PF params required for the call before slowpath_start is
896 * documented within the qed_pf_params structure definition.
898 void (*update_pf_params)(struct qed_dev *cdev,
899 struct qed_pf_params *params);
900 int (*slowpath_start)(struct qed_dev *cdev,
901 struct qed_slowpath_params *params);
903 int (*slowpath_stop)(struct qed_dev *cdev);
905 /* Requests to use `cnt' interrupts for fastpath.
906 * upon success, returns number of interrupts allocated for fastpath.
908 int (*set_fp_int)(struct qed_dev *cdev,
911 /* Fills `info' with pointers required for utilizing interrupts */
912 int (*get_fp_int)(struct qed_dev *cdev,
913 struct qed_int_info *info);
915 u32 (*sb_init)(struct qed_dev *cdev,
916 struct qed_sb_info *sb_info,
918 dma_addr_t sb_phy_addr,
920 enum qed_sb_type type);
922 u32 (*sb_release)(struct qed_dev *cdev,
923 struct qed_sb_info *sb_info,
925 enum qed_sb_type type);
927 void (*simd_handler_config)(struct qed_dev *cdev,
930 void (*handler)(void *));
932 void (*simd_handler_clean)(struct qed_dev *cdev,
934 int (*dbg_grc)(struct qed_dev *cdev,
935 void *buffer, u32 *num_dumped_bytes);
937 int (*dbg_grc_size)(struct qed_dev *cdev);
939 int (*dbg_all_data) (struct qed_dev *cdev, void *buffer);
941 int (*dbg_all_data_size) (struct qed_dev *cdev);
944 * @brief can_link_change - can the instance change the link or not
948 * @return true if link-change is allowed, false otherwise.
950 bool (*can_link_change)(struct qed_dev *cdev);
953 * @brief set_link - set links according to params
956 * @param params - values used to override the default link configuration
958 * @return 0 on success, error otherwise.
960 int (*set_link)(struct qed_dev *cdev,
961 struct qed_link_params *params);
964 * @brief get_link - returns the current link state.
967 * @param if_link - structure to be filled with current link configuration.
969 void (*get_link)(struct qed_dev *cdev,
970 struct qed_link_output *if_link);
973 * @brief - drains chip in case Tx completions fail to arrive due to pause.
977 int (*drain)(struct qed_dev *cdev);
980 * @brief update_msglvl - update module debug level
986 void (*update_msglvl)(struct qed_dev *cdev,
990 int (*chain_alloc)(struct qed_dev *cdev,
991 enum qed_chain_use_mode intended_use,
992 enum qed_chain_mode mode,
993 enum qed_chain_cnt_type cnt_type,
996 struct qed_chain *p_chain,
997 struct qed_chain_ext_pbl *ext_pbl);
999 void (*chain_free)(struct qed_dev *cdev,
1000 struct qed_chain *p_chain);
1003 * @brief nvm_flash - Flash nvm data.
1006 * @param name - file containing the data
1008 * @return 0 on success, error otherwise.
1010 int (*nvm_flash)(struct qed_dev *cdev, const char *name);
1013 * @brief nvm_get_image - reads an entire image from nvram
1016 * @param type - type of the request nvram image
1017 * @param buf - preallocated buffer to fill with the image
1018 * @param len - length of the allocated buffer
1020 * @return 0 on success, error otherwise
1022 int (*nvm_get_image)(struct qed_dev *cdev,
1023 enum qed_nvm_images type, u8 *buf, u16 len);
1026 * @brief set_coalesce - Configure Rx coalesce value in usec
1029 * @param rx_coal - Rx coalesce value in usec
1030 * @param tx_coal - Tx coalesce value in usec
1031 * @param qid - Queue index
1032 * @param sb_id - Status Block Id
1034 * @return 0 on success, error otherwise.
1036 int (*set_coalesce)(struct qed_dev *cdev,
1037 u16 rx_coal, u16 tx_coal, void *handle);
1040 * @brief set_led - Configure LED mode
1043 * @param mode - LED mode
1045 * @return 0 on success, error otherwise.
1047 int (*set_led)(struct qed_dev *cdev,
1048 enum qed_led_mode mode);
1051 * @brief attn_clr_enable - Prevent attentions from being reasserted
1056 void (*attn_clr_enable)(struct qed_dev *cdev, bool clr_enable);
1059 * @brief db_recovery_add - add doorbell information to the doorbell
1060 * recovery mechanism.
1063 * @param db_addr - doorbell address
1064 * @param db_data - address of where db_data is stored
1065 * @param db_is_32b - doorbell is 32b pr 64b
1066 * @param db_is_user - doorbell recovery addresses are user or kernel space
1068 int (*db_recovery_add)(struct qed_dev *cdev,
1069 void __iomem *db_addr,
1071 enum qed_db_rec_width db_width,
1072 enum qed_db_rec_space db_space);
1075 * @brief db_recovery_del - remove doorbell information from the doorbell
1076 * recovery mechanism. db_data serves as key (db_addr is not unique).
1079 * @param db_addr - doorbell address
1080 * @param db_data - address where db_data is stored. Serves as key for the
1083 int (*db_recovery_del)(struct qed_dev *cdev,
1084 void __iomem *db_addr, void *db_data);
1087 * @brief recovery_process - Trigger a recovery process
1091 * @return 0 on success, error otherwise.
1093 int (*recovery_process)(struct qed_dev *cdev);
1096 * @brief recovery_prolog - Execute the prolog operations of a recovery process
1100 * @return 0 on success, error otherwise.
1102 int (*recovery_prolog)(struct qed_dev *cdev);
1105 * @brief update_drv_state - API to inform the change in the driver state.
1111 int (*update_drv_state)(struct qed_dev *cdev, bool active);
1114 * @brief update_mac - API to inform the change in the mac address
1120 int (*update_mac)(struct qed_dev *cdev, u8 *mac);
1123 * @brief update_mtu - API to inform the change in the mtu
1129 int (*update_mtu)(struct qed_dev *cdev, u16 mtu);
1132 * @brief update_wol - update of changes in the WoL configuration
1135 * @param enabled - true iff WoL should be enabled.
1137 int (*update_wol) (struct qed_dev *cdev, bool enabled);
1140 * @brief read_module_eeprom
1143 * @param buf - buffer
1144 * @param dev_addr - PHY device memory region
1145 * @param offset - offset into eeprom contents to be read
1146 * @param len - buffer length, i.e., max bytes to be read
1148 int (*read_module_eeprom)(struct qed_dev *cdev,
1149 char *buf, u8 dev_addr, u32 offset, u32 len);
1152 * @brief get_affin_hwfn_idx
1156 u8 (*get_affin_hwfn_idx)(struct qed_dev *cdev);
1159 * @brief read_nvm_cfg - Read NVM config attribute value.
1161 * @param buf - buffer
1162 * @param cmd - NVM CFG command id
1163 * @param entity_id - Entity id
1166 int (*read_nvm_cfg)(struct qed_dev *cdev, u8 **buf, u32 cmd,
1169 * @brief read_nvm_cfg - Read NVM config attribute value.
1171 * @param cmd - NVM CFG command id
1173 * @return config id length, 0 on error.
1175 int (*read_nvm_cfg_len)(struct qed_dev *cdev, u32 cmd);
1178 * @brief set_grc_config - Configure value for grc config id.
1180 * @param cfg_id - grc config id
1181 * @param val - grc config value
1184 int (*set_grc_config)(struct qed_dev *cdev, u32 cfg_id, u32 val);
1187 #define MASK_FIELD(_name, _value) \
1188 ((_value) &= (_name ## _MASK))
1190 #define FIELD_VALUE(_name, _value) \
1191 ((_value & _name ## _MASK) << _name ## _SHIFT)
1193 #define SET_FIELD(value, name, flag) \
1195 (value) &= ~(name ## _MASK << name ## _SHIFT); \
1196 (value) |= (((u64)flag) << (name ## _SHIFT)); \
1199 #define GET_FIELD(value, name) \
1200 (((value) >> (name ## _SHIFT)) & name ## _MASK)
1202 #define GET_MFW_FIELD(name, field) \
1203 (((name) & (field ## _MASK)) >> (field ## _OFFSET))
1205 #define SET_MFW_FIELD(name, field, value) \
1207 (name) &= ~(field ## _MASK); \
1208 (name) |= (((value) << (field ## _OFFSET)) & (field ## _MASK));\
1211 #define DB_ADDR_SHIFT(addr) ((addr) << DB_PWM_ADDR_OFFSET_SHIFT)
1213 /* Debug print definitions */
1214 #define DP_ERR(cdev, fmt, ...) \
1216 pr_err("[%s:%d(%s)]" fmt, \
1217 __func__, __LINE__, \
1218 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1222 #define DP_NOTICE(cdev, fmt, ...) \
1224 if (unlikely((cdev)->dp_level <= QED_LEVEL_NOTICE)) { \
1225 pr_notice("[%s:%d(%s)]" fmt, \
1226 __func__, __LINE__, \
1227 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1233 #define DP_INFO(cdev, fmt, ...) \
1235 if (unlikely((cdev)->dp_level <= QED_LEVEL_INFO)) { \
1236 pr_notice("[%s:%d(%s)]" fmt, \
1237 __func__, __LINE__, \
1238 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1243 #define DP_VERBOSE(cdev, module, fmt, ...) \
1245 if (unlikely(((cdev)->dp_level <= QED_LEVEL_VERBOSE) && \
1246 ((cdev)->dp_module & module))) { \
1247 pr_notice("[%s:%d(%s)]" fmt, \
1248 __func__, __LINE__, \
1249 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1255 QED_LEVEL_VERBOSE = 0x0,
1256 QED_LEVEL_INFO = 0x1,
1257 QED_LEVEL_NOTICE = 0x2,
1258 QED_LEVEL_ERR = 0x3,
1261 #define QED_LOG_LEVEL_SHIFT (30)
1262 #define QED_LOG_VERBOSE_MASK (0x3fffffff)
1263 #define QED_LOG_INFO_MASK (0x40000000)
1264 #define QED_LOG_NOTICE_MASK (0x80000000)
1267 QED_MSG_SPQ = 0x10000,
1268 QED_MSG_STATS = 0x20000,
1269 QED_MSG_DCB = 0x40000,
1270 QED_MSG_IOV = 0x80000,
1271 QED_MSG_SP = 0x100000,
1272 QED_MSG_STORAGE = 0x200000,
1273 QED_MSG_CXT = 0x800000,
1274 QED_MSG_LL2 = 0x1000000,
1275 QED_MSG_ILT = 0x2000000,
1276 QED_MSG_RDMA = 0x4000000,
1277 QED_MSG_DEBUG = 0x8000000,
1278 /* to be added...up to 0x8000000 */
1287 struct qed_eth_stats_common {
1288 u64 no_buff_discards;
1289 u64 packet_too_big_discard;
1297 u64 mftag_filter_discards;
1298 u64 mac_filter_discards;
1299 u64 gft_filter_drop;
1306 u64 tx_err_drop_pkts;
1307 u64 tpa_coalesced_pkts;
1308 u64 tpa_coalesced_events;
1310 u64 tpa_not_coalesced_pkts;
1311 u64 tpa_coalesced_bytes;
1314 u64 rx_64_byte_packets;
1315 u64 rx_65_to_127_byte_packets;
1316 u64 rx_128_to_255_byte_packets;
1317 u64 rx_256_to_511_byte_packets;
1318 u64 rx_512_to_1023_byte_packets;
1319 u64 rx_1024_to_1518_byte_packets;
1321 u64 rx_mac_crtl_frames;
1322 u64 rx_pause_frames;
1324 u64 rx_align_errors;
1325 u64 rx_carrier_errors;
1326 u64 rx_oversize_packets;
1328 u64 rx_undersize_packets;
1330 u64 tx_64_byte_packets;
1331 u64 tx_65_to_127_byte_packets;
1332 u64 tx_128_to_255_byte_packets;
1333 u64 tx_256_to_511_byte_packets;
1334 u64 tx_512_to_1023_byte_packets;
1335 u64 tx_1024_to_1518_byte_packets;
1336 u64 tx_pause_frames;
1341 u64 rx_mac_uc_packets;
1342 u64 rx_mac_mc_packets;
1343 u64 rx_mac_bc_packets;
1344 u64 rx_mac_frames_ok;
1346 u64 tx_mac_uc_packets;
1347 u64 tx_mac_mc_packets;
1348 u64 tx_mac_bc_packets;
1349 u64 tx_mac_ctrl_frames;
1350 u64 link_change_count;
1353 struct qed_eth_stats_bb {
1354 u64 rx_1519_to_1522_byte_packets;
1355 u64 rx_1519_to_2047_byte_packets;
1356 u64 rx_2048_to_4095_byte_packets;
1357 u64 rx_4096_to_9216_byte_packets;
1358 u64 rx_9217_to_16383_byte_packets;
1359 u64 tx_1519_to_2047_byte_packets;
1360 u64 tx_2048_to_4095_byte_packets;
1361 u64 tx_4096_to_9216_byte_packets;
1362 u64 tx_9217_to_16383_byte_packets;
1363 u64 tx_lpi_entry_count;
1364 u64 tx_total_collisions;
1367 struct qed_eth_stats_ah {
1368 u64 rx_1519_to_max_byte_packets;
1369 u64 tx_1519_to_max_byte_packets;
1372 struct qed_eth_stats {
1373 struct qed_eth_stats_common common;
1376 struct qed_eth_stats_bb bb;
1377 struct qed_eth_stats_ah ah;
1381 #define QED_SB_IDX 0x0002
1384 #define TX_PI(tc) (RX_PI + 1 + tc)
1386 struct qed_sb_cnt_info {
1387 /* Original, current, and free SBs for PF */
1392 /* Original, current and free SBS for child VFs */
1398 static inline u16 qed_sb_update_sb_idx(struct qed_sb_info *sb_info)
1403 prod = le32_to_cpu(sb_info->sb_virt->prod_index) &
1404 STATUS_BLOCK_E4_PROD_INDEX_MASK;
1405 if (sb_info->sb_ack != prod) {
1406 sb_info->sb_ack = prod;
1416 * @brief This function creates an update command for interrupts that is
1417 * written to the IGU.
1419 * @param sb_info - This is the structure allocated and
1420 * initialized per status block. Assumption is
1421 * that it was initialized using qed_sb_init
1422 * @param int_cmd - Enable/Disable/Nop
1423 * @param upd_flg - whether igu consumer should be
1426 * @return inline void
1428 static inline void qed_sb_ack(struct qed_sb_info *sb_info,
1429 enum igu_int_cmd int_cmd,
1432 struct igu_prod_cons_update igu_ack = { 0 };
1434 igu_ack.sb_id_and_flags =
1435 ((sb_info->sb_ack << IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT) |
1436 (upd_flg << IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT) |
1437 (int_cmd << IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT) |
1438 (IGU_SEG_ACCESS_REG <<
1439 IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT));
1441 DIRECT_REG_WR(sb_info->igu_addr, igu_ack.sb_id_and_flags);
1443 /* Both segments (interrupts & acks) are written to same place address;
1444 * Need to guarantee all commands will be received (in-order) by HW.
1449 static inline void __internal_ram_wr(void *p_hwfn,
1457 for (i = 0; i < size / sizeof(*data); i++)
1458 DIRECT_REG_WR(&((u32 __iomem *)addr)[i], data[i]);
1461 static inline void internal_ram_wr(void __iomem *addr,
1465 __internal_ram_wr(NULL, addr, size, data);
1471 QED_RSS_IPV4_TCP = 0x4,
1472 QED_RSS_IPV6_TCP = 0x8,
1473 QED_RSS_IPV4_UDP = 0x10,
1474 QED_RSS_IPV6_UDP = 0x20,
1477 #define QED_RSS_IND_TABLE_SIZE 128
1478 #define QED_RSS_KEY_SIZE 10 /* size in 32b chunks */