1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
7 #ifndef HINIC_HW_MGMT_H
8 #define HINIC_HW_MGMT_H
10 #include <linux/types.h>
11 #include <linux/semaphore.h>
12 #include <linux/completion.h>
13 #include <linux/bitops.h>
15 #include "hinic_hw_if.h"
16 #include "hinic_hw_api_cmd.h"
18 #define HINIC_MSG_HEADER_MSG_LEN_SHIFT 0
19 #define HINIC_MSG_HEADER_MODULE_SHIFT 11
20 #define HINIC_MSG_HEADER_SEG_LEN_SHIFT 16
21 #define HINIC_MSG_HEADER_NO_ACK_SHIFT 22
22 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_SHIFT 23
23 #define HINIC_MSG_HEADER_SEQID_SHIFT 24
24 #define HINIC_MSG_HEADER_LAST_SHIFT 30
25 #define HINIC_MSG_HEADER_DIRECTION_SHIFT 31
26 #define HINIC_MSG_HEADER_CMD_SHIFT 32
27 #define HINIC_MSG_HEADER_ZEROS_SHIFT 40
28 #define HINIC_MSG_HEADER_PCI_INTF_SHIFT 48
29 #define HINIC_MSG_HEADER_PF_IDX_SHIFT 50
30 #define HINIC_MSG_HEADER_MSG_ID_SHIFT 54
32 #define HINIC_MSG_HEADER_MSG_LEN_MASK 0x7FF
33 #define HINIC_MSG_HEADER_MODULE_MASK 0x1F
34 #define HINIC_MSG_HEADER_SEG_LEN_MASK 0x3F
35 #define HINIC_MSG_HEADER_NO_ACK_MASK 0x1
36 #define HINIC_MSG_HEADER_ASYNC_MGMT_TO_PF_MASK 0x1
37 #define HINIC_MSG_HEADER_SEQID_MASK 0x3F
38 #define HINIC_MSG_HEADER_LAST_MASK 0x1
39 #define HINIC_MSG_HEADER_DIRECTION_MASK 0x1
40 #define HINIC_MSG_HEADER_CMD_MASK 0xFF
41 #define HINIC_MSG_HEADER_ZEROS_MASK 0xFF
42 #define HINIC_MSG_HEADER_PCI_INTF_MASK 0x3
43 #define HINIC_MSG_HEADER_PF_IDX_MASK 0xF
44 #define HINIC_MSG_HEADER_MSG_ID_MASK 0x3FF
46 #define HINIC_MSG_HEADER_SET(val, member) \
47 ((u64)((val) & HINIC_MSG_HEADER_##member##_MASK) << \
48 HINIC_MSG_HEADER_##member##_SHIFT)
50 #define HINIC_MSG_HEADER_GET(val, member) \
51 (((val) >> HINIC_MSG_HEADER_##member##_SHIFT) & \
52 HINIC_MSG_HEADER_##member##_MASK)
54 enum hinic_mgmt_msg_type {
55 HINIC_MGMT_MSG_SYNC = 1,
59 HINIC_CFG_NIC_CAP = 0,
63 HINIC_COMM_CMD_START_FLR = 0x1,
64 HINIC_COMM_CMD_IO_STATUS_GET = 0x3,
65 HINIC_COMM_CMD_DMA_ATTR_SET = 0x4,
67 HINIC_COMM_CMD_CMDQ_CTXT_SET = 0x10,
68 HINIC_COMM_CMD_CMDQ_CTXT_GET = 0x11,
70 HINIC_COMM_CMD_HWCTXT_SET = 0x12,
71 HINIC_COMM_CMD_HWCTXT_GET = 0x13,
73 HINIC_COMM_CMD_SQ_HI_CI_SET = 0x14,
75 HINIC_COMM_CMD_RES_STATE_SET = 0x24,
77 HINIC_COMM_CMD_IO_RES_CLEAR = 0x29,
79 HINIC_COMM_CMD_CEQ_CTRL_REG_WR_BY_UP = 0x33,
81 HINIC_COMM_CMD_MSI_CTRL_REG_WR_BY_UP,
82 HINIC_COMM_CMD_MSI_CTRL_REG_RD_BY_UP,
84 HINIC_COMM_CMD_FAULT_REPORT = 0x37,
86 HINIC_COMM_CMD_SET_LED_STATUS = 0x4a,
88 HINIC_COMM_CMD_L2NIC_RESET = 0x4b,
90 HINIC_COMM_CMD_PAGESIZE_SET = 0x50,
92 HINIC_COMM_CMD_GET_BOARD_INFO = 0x52,
94 HINIC_COMM_CMD_WATCHDOG_INFO = 0x56,
99 enum hinic_mgmt_cb_state {
100 HINIC_MGMT_CB_ENABLED = BIT(0),
101 HINIC_MGMT_CB_RUNNING = BIT(1),
104 struct hinic_recv_msg {
108 struct completion recv_done;
111 enum hinic_mod_type mod;
112 int async_mgmt_to_pf;
118 struct hinic_mgmt_cb {
119 void (*cb)(void *handle, u8 cmd,
120 void *buf_in, u16 in_size,
121 void *buf_out, u16 *out_size);
127 struct hinic_pf_to_mgmt {
128 struct hinic_hwif *hwif;
129 struct hinic_hwdev *hwdev;
130 struct semaphore sync_msg_lock;
135 struct hinic_recv_msg recv_resp_msg_from_mgmt;
136 struct hinic_recv_msg recv_msg_from_mgmt;
138 struct hinic_api_cmd_chain *cmd_chain[HINIC_API_CMD_MAX];
140 struct hinic_mgmt_cb mgmt_cb[HINIC_MOD_MAX];
142 struct workqueue_struct *workq;
145 struct hinic_mgmt_msg_handle_work {
146 struct work_struct work;
147 struct hinic_pf_to_mgmt *pf_to_mgmt;
152 enum hinic_mod_type mod;
155 int async_mgmt_to_pf;
158 void hinic_register_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
159 enum hinic_mod_type mod,
161 void (*callback)(void *handle,
162 u8 cmd, void *buf_in,
163 u16 in_size, void *buf_out,
166 void hinic_unregister_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
167 enum hinic_mod_type mod);
169 int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
170 enum hinic_mod_type mod, u8 cmd,
171 void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
172 enum hinic_mgmt_msg_type sync);
174 int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt *pf_to_mgmt,
175 struct hinic_hwif *hwif);
177 void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt *pf_to_mgmt);