xref: /linux/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2016-2017 Hisilicon Limited. */
3 
4 #ifndef __HCLGE_MBX_H
5 #define __HCLGE_MBX_H
6 #include <linux/init.h>
7 #include <linux/mutex.h>
8 #include <linux/types.h>
9 
10 enum HCLGE_MBX_OPCODE {
11 	HCLGE_MBX_RESET = 0x01,		/* (VF -> PF) assert reset */
12 	HCLGE_MBX_ASSERTING_RESET,	/* (PF -> VF) PF is asserting reset */
13 	HCLGE_MBX_SET_UNICAST,		/* (VF -> PF) set UC addr */
14 	HCLGE_MBX_SET_MULTICAST,	/* (VF -> PF) set MC addr */
15 	HCLGE_MBX_SET_VLAN,		/* (VF -> PF) set VLAN */
16 	HCLGE_MBX_MAP_RING_TO_VECTOR,	/* (VF -> PF) map ring-to-vector */
17 	HCLGE_MBX_UNMAP_RING_TO_VECTOR,	/* (VF -> PF) unamp ring-to-vector */
18 	HCLGE_MBX_SET_PROMISC_MODE,	/* (VF -> PF) set promiscuous mode */
19 	HCLGE_MBX_SET_MACVLAN,		/* (VF -> PF) set unicast filter */
20 	HCLGE_MBX_API_NEGOTIATE,	/* (VF -> PF) negotiate API version */
21 	HCLGE_MBX_GET_QINFO,		/* (VF -> PF) get queue config */
22 	HCLGE_MBX_GET_QDEPTH,		/* (VF -> PF) get queue depth */
23 	HCLGE_MBX_GET_BASIC_INFO,	/* (VF -> PF) get basic info */
24 	HCLGE_MBX_GET_RETA,		/* (VF -> PF) get RETA */
25 	HCLGE_MBX_GET_RSS_KEY,		/* (VF -> PF) get RSS key */
26 	HCLGE_MBX_GET_MAC_ADDR,		/* (VF -> PF) get MAC addr */
27 	HCLGE_MBX_PF_VF_RESP,		/* (PF -> VF) generate response to VF */
28 	HCLGE_MBX_GET_BDNUM,		/* (VF -> PF) get BD num */
29 	HCLGE_MBX_GET_BUFSIZE,		/* (VF -> PF) get buffer size */
30 	HCLGE_MBX_GET_STREAMID,		/* (VF -> PF) get stream id */
31 	HCLGE_MBX_SET_AESTART,		/* (VF -> PF) start ae */
32 	HCLGE_MBX_SET_TSOSTATS,		/* (VF -> PF) get tso stats */
33 	HCLGE_MBX_LINK_STAT_CHANGE,	/* (PF -> VF) link status has changed */
34 	HCLGE_MBX_GET_BASE_CONFIG,	/* (VF -> PF) get config */
35 	HCLGE_MBX_BIND_FUNC_QUEUE,	/* (VF -> PF) bind function and queue */
36 	HCLGE_MBX_GET_LINK_STATUS,	/* (VF -> PF) get link status */
37 	HCLGE_MBX_QUEUE_RESET,		/* (VF -> PF) reset queue */
38 	HCLGE_MBX_KEEP_ALIVE,		/* (VF -> PF) send keep alive cmd */
39 	HCLGE_MBX_SET_ALIVE,		/* (VF -> PF) set alive state */
40 	HCLGE_MBX_SET_MTU,		/* (VF -> PF) set mtu */
41 	HCLGE_MBX_GET_QID_IN_PF,	/* (VF -> PF) get queue id in pf */
42 	HCLGE_MBX_LINK_STAT_MODE,	/* (PF -> VF) link mode has changed */
43 	HCLGE_MBX_GET_LINK_MODE,	/* (VF -> PF) get the link mode of pf */
44 	HCLGE_MBX_PUSH_VLAN_INFO,	/* (PF -> VF) push port base vlan */
45 	HCLGE_MBX_GET_MEDIA_TYPE,       /* (VF -> PF) get media type */
46 	HCLGE_MBX_PUSH_PROMISC_INFO,	/* (PF -> VF) push vf promisc info */
47 	HCLGE_MBX_VF_UNINIT,            /* (VF -> PF) vf is unintializing */
48 	HCLGE_MBX_HANDLE_VF_TBL,	/* (VF -> PF) store/clear hw table */
49 	HCLGE_MBX_GET_RING_VECTOR_MAP,	/* (VF -> PF) get ring-to-vector map */
50 
51 	HCLGE_MBX_GET_VF_FLR_STATUS = 200, /* (M7 -> PF) get vf flr status */
52 	HCLGE_MBX_PUSH_LINK_STATUS,	/* (M7 -> PF) get port link status */
53 	HCLGE_MBX_NCSI_ERROR,		/* (M7 -> PF) receive a NCSI error */
54 };
55 
56 /* below are per-VF mac-vlan subcodes */
57 enum hclge_mbx_mac_vlan_subcode {
58 	HCLGE_MBX_MAC_VLAN_UC_MODIFY = 0,	/* modify UC mac addr */
59 	HCLGE_MBX_MAC_VLAN_UC_ADD,		/* add a new UC mac addr */
60 	HCLGE_MBX_MAC_VLAN_UC_REMOVE,		/* remove a new UC mac addr */
61 	HCLGE_MBX_MAC_VLAN_MC_MODIFY,		/* modify MC mac addr */
62 	HCLGE_MBX_MAC_VLAN_MC_ADD,		/* add new MC mac addr */
63 	HCLGE_MBX_MAC_VLAN_MC_REMOVE,		/* remove MC mac addr */
64 };
65 
66 /* below are per-VF vlan cfg subcodes */
67 enum hclge_mbx_vlan_cfg_subcode {
68 	HCLGE_MBX_VLAN_FILTER = 0,	/* set vlan filter */
69 	HCLGE_MBX_VLAN_TX_OFF_CFG,	/* set tx side vlan offload */
70 	HCLGE_MBX_VLAN_RX_OFF_CFG,	/* set rx side vlan offload */
71 	HCLGE_MBX_PORT_BASE_VLAN_CFG,	/* set port based vlan configuration */
72 	HCLGE_MBX_GET_PORT_BASE_VLAN_STATE,	/* get port based vlan state */
73 	HCLGE_MBX_ENABLE_VLAN_FILTER,
74 };
75 
76 enum hclge_mbx_tbl_cfg_subcode {
77 	HCLGE_MBX_VPORT_LIST_CLEAR,
78 };
79 
80 #define HCLGE_MBX_MAX_MSG_SIZE	14
81 #define HCLGE_MBX_MAX_RESP_DATA_SIZE	8U
82 #define HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM	4
83 
84 #define HCLGE_RESET_SCHED_TIMEOUT	(3 * HZ)
85 #define HCLGE_MBX_SCHED_TIMEOUT	(HZ / 2)
86 
87 struct hclge_ring_chain_param {
88 	u8 ring_type;
89 	u8 tqp_index;
90 	u8 int_gl_index;
91 };
92 
93 struct hclge_basic_info {
94 	u8 hw_tc_map;
95 	u8 rsv;
96 	__le16 mbx_api_version;
97 	__le32 pf_caps;
98 };
99 
100 struct hclgevf_mbx_resp_status {
101 	struct mutex mbx_mutex; /* protects against contending sync cmd resp */
102 	u32 origin_mbx_msg;
103 	bool received_resp;
104 	int resp_status;
105 	u16 match_id;
106 	u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE];
107 };
108 
109 struct hclge_respond_to_vf_msg {
110 	int status;
111 	u8 data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
112 	u16 len;
113 };
114 
115 struct hclge_vf_to_pf_msg {
116 	u8 code;
117 	union {
118 		struct {
119 			u8 subcode;
120 			u8 data[HCLGE_MBX_MAX_MSG_SIZE];
121 		};
122 		struct {
123 			u8 en_bc;
124 			u8 en_uc;
125 			u8 en_mc;
126 			u8 en_limit_promisc;
127 		};
128 		struct {
129 			u8 vector_id;
130 			u8 ring_num;
131 			struct hclge_ring_chain_param
132 				param[HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM];
133 		};
134 	};
135 };
136 
137 struct hclge_pf_to_vf_msg {
138 	__le16 code;
139 	union {
140 		/* used for mbx response */
141 		struct {
142 			__le16 vf_mbx_msg_code;
143 			__le16 vf_mbx_msg_subcode;
144 			__le16 resp_status;
145 			u8 resp_data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
146 		};
147 		/* used for general mbx */
148 		struct {
149 			u8 msg_data[HCLGE_MBX_MAX_MSG_SIZE];
150 		};
151 	};
152 };
153 
154 struct hclge_mbx_vf_to_pf_cmd {
155 	u8 rsv;
156 	u8 mbx_src_vfid; /* Auto filled by IMP */
157 	u8 mbx_need_resp;
158 	u8 rsv1[1];
159 	u8 msg_len;
160 	u8 rsv2;
161 	__le16 match_id;
162 	struct hclge_vf_to_pf_msg msg;
163 };
164 
165 #define HCLGE_MBX_NEED_RESP_B		0
166 
167 struct hclge_mbx_pf_to_vf_cmd {
168 	u8 dest_vfid;
169 	u8 rsv[3];
170 	u8 msg_len;
171 	u8 rsv1;
172 	__le16 match_id;
173 	struct hclge_pf_to_vf_msg msg;
174 };
175 
176 struct hclge_vf_rst_cmd {
177 	u8 dest_vfid;
178 	u8 vf_rst;
179 	u8 rsv[22];
180 };
181 
182 #pragma pack(1)
183 struct hclge_mbx_link_status {
184 	__le16 link_status;
185 	__le32 speed;
186 	__le16 duplex;
187 	u8 flag;
188 };
189 
190 struct hclge_mbx_link_mode {
191 	__le16 idx;
192 	__le64 link_mode;
193 };
194 
195 struct hclge_mbx_port_base_vlan {
196 	__le16 state;
197 	__le16 vlan_proto;
198 	__le16 qos;
199 	__le16 vlan_tag;
200 };
201 
202 struct hclge_mbx_vf_queue_info {
203 	__le16 num_tqps;
204 	__le16 rss_size;
205 	__le16 rx_buf_len;
206 };
207 
208 struct hclge_mbx_vf_queue_depth {
209 	__le16 num_tx_desc;
210 	__le16 num_rx_desc;
211 };
212 
213 struct hclge_mbx_vlan_filter {
214 	u8 is_kill;
215 	__le16 vlan_id;
216 	__le16 proto;
217 };
218 
219 struct hclge_mbx_mtu_info {
220 	__le32 mtu;
221 };
222 
223 #pragma pack()
224 
225 /* used by VF to store the received Async responses from PF */
226 struct hclgevf_mbx_arq_ring {
227 #define HCLGE_MBX_MAX_ARQ_MSG_SIZE	8
228 #define HCLGE_MBX_MAX_ARQ_MSG_NUM	1024
229 	struct hclgevf_dev *hdev;
230 	u32 head;
231 	u32 tail;
232 	atomic_t count;
233 	__le16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
234 };
235 
236 struct hclge_dev;
237 
238 #define HCLGE_MBX_OPCODE_MAX 256
239 struct hclge_mbx_ops_param {
240 	struct hclge_vport *vport;
241 	struct hclge_mbx_vf_to_pf_cmd *req;
242 	struct hclge_respond_to_vf_msg *resp_msg;
243 };
244 
245 typedef int (*hclge_mbx_ops_fn)(struct hclge_mbx_ops_param *param);
246 
247 #define hclge_mbx_ring_ptr_move_crq(crq) \
248 	(crq->next_to_use = (crq->next_to_use + 1) % crq->desc_num)
249 #define hclge_mbx_tail_ptr_move_arq(arq) \
250 		(arq.tail = (arq.tail + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
251 #define hclge_mbx_head_ptr_move_arq(arq) \
252 		(arq.head = (arq.head + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
253 
254 /* PF immediately push link status to VFs when link status changed */
255 #define HCLGE_MBX_PUSH_LINK_STATUS_EN			BIT(0)
256 #endif
257