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,
96 HINIC_MGMT_CMD_SET_VF_RANDOM_ID = 0x61,
101 enum hinic_mgmt_cb_state {
102 HINIC_MGMT_CB_ENABLED = BIT(0),
103 HINIC_MGMT_CB_RUNNING = BIT(1),
106 struct hinic_recv_msg {
110 struct completion recv_done;
113 enum hinic_mod_type mod;
114 int async_mgmt_to_pf;
120 struct hinic_mgmt_cb {
121 void (*cb)(void *handle, u8 cmd,
122 void *buf_in, u16 in_size,
123 void *buf_out, u16 *out_size);
129 struct hinic_pf_to_mgmt {
130 struct hinic_hwif *hwif;
131 struct hinic_hwdev *hwdev;
132 struct semaphore sync_msg_lock;
137 struct hinic_recv_msg recv_resp_msg_from_mgmt;
138 struct hinic_recv_msg recv_msg_from_mgmt;
140 struct hinic_api_cmd_chain *cmd_chain[HINIC_API_CMD_MAX];
142 struct hinic_mgmt_cb mgmt_cb[HINIC_MOD_MAX];
144 struct workqueue_struct *workq;
147 struct hinic_mgmt_msg_handle_work {
148 struct work_struct work;
149 struct hinic_pf_to_mgmt *pf_to_mgmt;
154 enum hinic_mod_type mod;
157 int async_mgmt_to_pf;
160 void hinic_register_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
161 enum hinic_mod_type mod,
163 void (*callback)(void *handle,
164 u8 cmd, void *buf_in,
165 u16 in_size, void *buf_out,
168 void hinic_unregister_mgmt_msg_cb(struct hinic_pf_to_mgmt *pf_to_mgmt,
169 enum hinic_mod_type mod);
171 int hinic_msg_to_mgmt(struct hinic_pf_to_mgmt *pf_to_mgmt,
172 enum hinic_mod_type mod, u8 cmd,
173 void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
174 enum hinic_mgmt_msg_type sync);
176 int hinic_pf_to_mgmt_init(struct hinic_pf_to_mgmt *pf_to_mgmt,
177 struct hinic_hwif *hwif);
179 void hinic_pf_to_mgmt_free(struct hinic_pf_to_mgmt *pf_to_mgmt);