1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
10 #include <linux/pci.h>
11 #include <linux/types.h>
12 #include <linux/bitops.h>
13 #include <net/devlink.h>
15 #include "hinic_hw_if.h"
16 #include "hinic_hw_eqs.h"
17 #include "hinic_hw_mgmt.h"
18 #include "hinic_hw_qp.h"
19 #include "hinic_hw_io.h"
20 #include "hinic_hw_mbox.h"
22 #define HINIC_MAX_QPS 32
24 #define HINIC_MGMT_NUM_MSG_CMD (HINIC_MGMT_MSG_CMD_MAX - \
25 HINIC_MGMT_MSG_CMD_BASE)
27 #define HINIC_PF_SET_VF_ALREADY 0x4
28 #define HINIC_MGMT_STATUS_EXIST 0x6
29 #define HINIC_MGMT_CMD_UNSUPPORTED 0xFF
31 #define HINIC_CMD_VER_FUNC_ID 2
40 enum hw_ioctxt_set_cmdq_depth
{
41 HW_IOCTXT_SET_CMDQ_DEPTH_DEFAULT
,
42 HW_IOCTXT_SET_CMDQ_DEPTH_ENABLE
,
46 HINIC_PORT_CMD_VF_REGISTER
= 0x0,
47 HINIC_PORT_CMD_VF_UNREGISTER
= 0x1,
49 HINIC_PORT_CMD_CHANGE_MTU
= 2,
51 HINIC_PORT_CMD_ADD_VLAN
= 3,
52 HINIC_PORT_CMD_DEL_VLAN
= 4,
54 HINIC_PORT_CMD_SET_PFC
= 5,
56 HINIC_PORT_CMD_SET_MAC
= 9,
57 HINIC_PORT_CMD_GET_MAC
= 10,
58 HINIC_PORT_CMD_DEL_MAC
= 11,
60 HINIC_PORT_CMD_SET_RX_MODE
= 12,
62 HINIC_PORT_CMD_GET_PAUSE_INFO
= 20,
63 HINIC_PORT_CMD_SET_PAUSE_INFO
= 21,
65 HINIC_PORT_CMD_GET_LINK_STATE
= 24,
67 HINIC_PORT_CMD_SET_LRO
= 25,
69 HINIC_PORT_CMD_SET_RX_CSUM
= 26,
71 HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD
= 27,
73 HINIC_PORT_CMD_GET_PORT_STATISTICS
= 28,
75 HINIC_PORT_CMD_CLEAR_PORT_STATISTICS
= 29,
77 HINIC_PORT_CMD_GET_VPORT_STAT
= 30,
79 HINIC_PORT_CMD_CLEAN_VPORT_STAT
= 31,
81 HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL
= 37,
83 HINIC_PORT_CMD_SET_PORT_STATE
= 41,
85 HINIC_PORT_CMD_SET_RSS_TEMPLATE_TBL
= 43,
87 HINIC_PORT_CMD_GET_RSS_TEMPLATE_TBL
= 44,
89 HINIC_PORT_CMD_SET_RSS_HASH_ENGINE
= 45,
91 HINIC_PORT_CMD_GET_RSS_HASH_ENGINE
= 46,
93 HINIC_PORT_CMD_GET_RSS_CTX_TBL
= 47,
95 HINIC_PORT_CMD_SET_RSS_CTX_TBL
= 48,
97 HINIC_PORT_CMD_RSS_TEMP_MGR
= 49,
99 HINIC_PORT_CMD_RD_LINE_TBL
= 57,
101 HINIC_PORT_CMD_RSS_CFG
= 66,
103 HINIC_PORT_CMD_FWCTXT_INIT
= 69,
105 HINIC_PORT_CMD_GET_LOOPBACK_MODE
= 72,
106 HINIC_PORT_CMD_SET_LOOPBACK_MODE
,
108 HINIC_PORT_CMD_ENABLE_SPOOFCHK
= 78,
110 HINIC_PORT_CMD_GET_MGMT_VERSION
= 88,
112 HINIC_PORT_CMD_SET_FUNC_STATE
= 93,
114 HINIC_PORT_CMD_GET_GLOBAL_QPN
= 102,
116 HINIC_PORT_CMD_SET_VF_RATE
= 105,
118 HINIC_PORT_CMD_SET_VF_VLAN
= 106,
120 HINIC_PORT_CMD_CLR_VF_VLAN
,
122 HINIC_PORT_CMD_SET_TSO
= 112,
124 HINIC_PORT_CMD_UPDATE_FW
= 114,
126 HINIC_PORT_CMD_SET_RQ_IQ_MAP
= 115,
128 HINIC_PORT_CMD_LINK_STATUS_REPORT
= 160,
130 HINIC_PORT_CMD_UPDATE_MAC
= 164,
132 HINIC_PORT_CMD_GET_CAP
= 170,
134 HINIC_PORT_CMD_GET_LINK_MODE
= 217,
136 HINIC_PORT_CMD_SET_SPEED
= 218,
138 HINIC_PORT_CMD_SET_AUTONEG
= 219,
140 HINIC_PORT_CMD_GET_STD_SFP_INFO
= 240,
142 HINIC_PORT_CMD_SET_LRO_TIMER
= 244,
144 HINIC_PORT_CMD_SET_VF_MAX_MIN_RATE
= 249,
146 HINIC_PORT_CMD_GET_SFP_ABS
= 251,
149 /* cmd of mgmt CPU message for HILINK module */
150 enum hinic_hilink_cmd
{
151 HINIC_HILINK_CMD_GET_LINK_INFO
= 0x3,
152 HINIC_HILINK_CMD_SET_LINK_SETTINGS
= 0x8,
155 enum hinic_ucode_cmd
{
156 HINIC_UCODE_CMD_MODIFY_QUEUE_CONTEXT
= 0,
157 HINIC_UCODE_CMD_CLEAN_QUEUE_CONTEXT
,
158 HINIC_UCODE_CMD_ARM_SQ
,
159 HINIC_UCODE_CMD_ARM_RQ
,
160 HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE
,
161 HINIC_UCODE_CMD_SET_RSS_CONTEXT_TABLE
,
162 HINIC_UCODE_CMD_GET_RSS_INDIR_TABLE
,
163 HINIC_UCODE_CMD_GET_RSS_CONTEXT_TABLE
,
164 HINIC_UCODE_CMD_SET_IQ_ENABLE
,
165 HINIC_UCODE_CMD_SET_RQ_FLUSH
= 10
168 #define NIC_RSS_CMD_TEMP_ALLOC 0x01
169 #define NIC_RSS_CMD_TEMP_FREE 0x02
171 enum hinic_mgmt_msg_cmd
{
172 HINIC_MGMT_MSG_CMD_BASE
= 0xA0,
174 HINIC_MGMT_MSG_CMD_LINK_STATUS
= 0xA0,
176 HINIC_MGMT_MSG_CMD_CABLE_PLUG_EVENT
= 0xE5,
177 HINIC_MGMT_MSG_CMD_LINK_ERR_EVENT
= 0xE6,
179 HINIC_MGMT_MSG_CMD_MAX
,
182 enum hinic_cb_state
{
183 HINIC_CB_ENABLED
= BIT(0),
184 HINIC_CB_RUNNING
= BIT(1),
187 enum hinic_res_state
{
189 HINIC_RES_ACTIVE
= 1,
192 struct hinic_cmd_fw_ctxt
{
203 struct hinic_cmd_hw_ioctxt
{
225 struct hinic_cmd_io_status
{
236 struct hinic_cmd_clear_io_res
{
246 struct hinic_cmd_set_res_state
{
257 struct hinic_ceq_ctrl_reg
{
268 struct hinic_cmd_base_qpn
{
277 struct hinic_cmd_hw_ci
{
296 struct hinic_cmd_l2nic_reset
{
305 struct hinic_msix_config
{
313 u8 coalesce_timer_cnt
;
320 struct hinic_set_random_id
{
331 struct hinic_board_info
{
350 struct hinic_comm_board_info
{
355 struct hinic_board_info info
;
361 struct hinic_hwif
*hwif
;
362 struct msix_entry
*msix_entries
;
364 struct hinic_aeqs aeqs
;
365 struct hinic_func_to_io func_to_io
;
366 struct hinic_mbox_func_to_func
*func_to_func
;
368 struct hinic_cap nic_cap
;
370 struct hinic_devlink_priv
*devlink_dev
;
373 struct hinic_nic_cb
{
374 void (*handler
)(void *handle
, void *buf_in
,
375 u16 in_size
, void *buf_out
,
379 unsigned long cb_state
;
382 #define HINIC_COMM_SELF_CMD_MAX 4
384 typedef void (*comm_mgmt_self_msg_proc
)(void *handle
, void *buf_in
, u16 in_size
,
385 void *buf_out
, u16
*out_size
);
387 struct comm_mgmt_self_msg_sub_info
{
389 comm_mgmt_self_msg_proc proc
;
392 struct comm_mgmt_self_msg_info
{
394 struct comm_mgmt_self_msg_sub_info info
[HINIC_COMM_SELF_CMD_MAX
];
397 struct hinic_pfhwdev
{
398 struct hinic_hwdev hwdev
;
400 struct hinic_pf_to_mgmt pf_to_mgmt
;
402 struct hinic_nic_cb nic_cb
[HINIC_MGMT_NUM_MSG_CMD
];
404 struct comm_mgmt_self_msg_info proc
;
407 struct hinic_dev_cap
{
426 union hinic_fault_hw_mgmt
{
428 /* valid only type == FAULT_TYPE_CHIP */
435 /* func_id valid only if err_level == FAULT_LEVEL_SERIOUS_FLR */
440 /* valid only if type == FAULT_TYPE_UCODE */
451 /* valid only if type == FAULT_TYPE_MEM_RD_TIMEOUT ||
452 * FAULT_TYPE_MEM_WR_TIMEOUT
461 /* valid only if type == FAULT_TYPE_REG_RD_TIMEOUT ||
462 * FAULT_TYPE_REG_WR_TIMEOUT
472 /* 0: read; 1: write */
483 struct hinic_fault_event
{
487 union hinic_fault_hw_mgmt event
;
490 struct hinic_cmd_fault_event
{
495 struct hinic_fault_event event
;
498 enum hinic_fault_type
{
501 FAULT_TYPE_MEM_RD_TIMEOUT
,
502 FAULT_TYPE_MEM_WR_TIMEOUT
,
503 FAULT_TYPE_REG_RD_TIMEOUT
,
504 FAULT_TYPE_REG_WR_TIMEOUT
,
505 FAULT_TYPE_PHY_FAULT
,
509 enum hinic_fault_err_level
{
511 FAULT_LEVEL_SERIOUS_RESET
,
512 FAULT_LEVEL_SERIOUS_FLR
,
514 FAULT_LEVEL_SUGGESTION
,
518 struct hinic_mgmt_watchdog_info
{
544 void hinic_hwdev_cb_register(struct hinic_hwdev
*hwdev
,
545 enum hinic_mgmt_msg_cmd cmd
, void *handle
,
546 void (*handler
)(void *handle
, void *buf_in
,
547 u16 in_size
, void *buf_out
,
550 void hinic_hwdev_cb_unregister(struct hinic_hwdev
*hwdev
,
551 enum hinic_mgmt_msg_cmd cmd
);
553 int hinic_port_msg_cmd(struct hinic_hwdev
*hwdev
, enum hinic_port_cmd cmd
,
554 void *buf_in
, u16 in_size
, void *buf_out
,
557 int hinic_hilink_msg_cmd(struct hinic_hwdev
*hwdev
, enum hinic_hilink_cmd cmd
,
558 void *buf_in
, u16 in_size
, void *buf_out
,
561 int hinic_hwdev_ifup(struct hinic_hwdev
*hwdev
, u16 sq_depth
, u16 rq_depth
);
563 void hinic_hwdev_ifdown(struct hinic_hwdev
*hwdev
);
565 struct hinic_hwdev
*hinic_init_hwdev(struct pci_dev
*pdev
, struct devlink
*devlink
);
567 void hinic_free_hwdev(struct hinic_hwdev
*hwdev
);
569 int hinic_hwdev_max_num_qps(struct hinic_hwdev
*hwdev
);
571 int hinic_hwdev_num_qps(struct hinic_hwdev
*hwdev
);
573 struct hinic_sq
*hinic_hwdev_get_sq(struct hinic_hwdev
*hwdev
, int i
);
575 struct hinic_rq
*hinic_hwdev_get_rq(struct hinic_hwdev
*hwdev
, int i
);
577 int hinic_hwdev_msix_cnt_set(struct hinic_hwdev
*hwdev
, u16 msix_index
);
579 int hinic_hwdev_msix_set(struct hinic_hwdev
*hwdev
, u16 msix_index
,
580 u8 pending_limit
, u8 coalesc_timer
,
581 u8 lli_timer_cfg
, u8 lli_credit_limit
,
584 int hinic_hwdev_hw_ci_addr_set(struct hinic_hwdev
*hwdev
, struct hinic_sq
*sq
,
585 u8 pending_limit
, u8 coalesc_timer
);
587 void hinic_hwdev_set_msix_state(struct hinic_hwdev
*hwdev
, u16 msix_index
,
588 enum hinic_msix_state flag
);
590 int hinic_get_interrupt_cfg(struct hinic_hwdev
*hwdev
,
591 struct hinic_msix_config
*interrupt_info
);
593 int hinic_set_interrupt_cfg(struct hinic_hwdev
*hwdev
,
594 struct hinic_msix_config
*interrupt_info
);
596 int hinic_get_board_info(struct hinic_hwdev
*hwdev
,
597 struct hinic_comm_board_info
*board_info
);