xref: /openbmc/linux/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c (revision 023e41632e065d49bcbe31b3c4b336217f96a271)
1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2016-2017 Hisilicon Limited.
3 
4 #include "hclge_main.h"
5 #include "hclge_mbx.h"
6 #include "hnae3.h"
7 
8 /* hclge_gen_resp_to_vf: used to generate a synchronous response to VF when PF
9  * receives a mailbox message from VF.
10  * @vport: pointer to struct hclge_vport
11  * @vf_to_pf_req: pointer to hclge_mbx_vf_to_pf_cmd of the original mailbox
12  *		  message
13  * @resp_status: indicate to VF whether its request success(0) or failed.
14  */
15 static int hclge_gen_resp_to_vf(struct hclge_vport *vport,
16 				struct hclge_mbx_vf_to_pf_cmd *vf_to_pf_req,
17 				int resp_status,
18 				u8 *resp_data, u16 resp_data_len)
19 {
20 	struct hclge_mbx_pf_to_vf_cmd *resp_pf_to_vf;
21 	struct hclge_dev *hdev = vport->back;
22 	enum hclge_cmd_status status;
23 	struct hclge_desc desc;
24 
25 	resp_pf_to_vf = (struct hclge_mbx_pf_to_vf_cmd *)desc.data;
26 
27 	if (resp_data_len > HCLGE_MBX_MAX_RESP_DATA_SIZE) {
28 		dev_err(&hdev->pdev->dev,
29 			"PF fail to gen resp to VF len %d exceeds max len %d\n",
30 			resp_data_len,
31 			HCLGE_MBX_MAX_RESP_DATA_SIZE);
32 	}
33 
34 	hclge_cmd_setup_basic_desc(&desc, HCLGEVF_OPC_MBX_PF_TO_VF, false);
35 
36 	resp_pf_to_vf->dest_vfid = vf_to_pf_req->mbx_src_vfid;
37 	resp_pf_to_vf->msg_len = vf_to_pf_req->msg_len;
38 
39 	resp_pf_to_vf->msg[0] = HCLGE_MBX_PF_VF_RESP;
40 	resp_pf_to_vf->msg[1] = vf_to_pf_req->msg[0];
41 	resp_pf_to_vf->msg[2] = vf_to_pf_req->msg[1];
42 	resp_pf_to_vf->msg[3] = (resp_status == 0) ? 0 : 1;
43 
44 	if (resp_data && resp_data_len > 0)
45 		memcpy(&resp_pf_to_vf->msg[4], resp_data, resp_data_len);
46 
47 	status = hclge_cmd_send(&hdev->hw, &desc, 1);
48 	if (status)
49 		dev_err(&hdev->pdev->dev,
50 			"PF failed(=%d) to send response to VF\n", status);
51 
52 	return status;
53 }
54 
55 static int hclge_send_mbx_msg(struct hclge_vport *vport, u8 *msg, u16 msg_len,
56 			      u16 mbx_opcode, u8 dest_vfid)
57 {
58 	struct hclge_mbx_pf_to_vf_cmd *resp_pf_to_vf;
59 	struct hclge_dev *hdev = vport->back;
60 	enum hclge_cmd_status status;
61 	struct hclge_desc desc;
62 
63 	resp_pf_to_vf = (struct hclge_mbx_pf_to_vf_cmd *)desc.data;
64 
65 	hclge_cmd_setup_basic_desc(&desc, HCLGEVF_OPC_MBX_PF_TO_VF, false);
66 
67 	resp_pf_to_vf->dest_vfid = dest_vfid;
68 	resp_pf_to_vf->msg_len = msg_len;
69 	resp_pf_to_vf->msg[0] = mbx_opcode;
70 
71 	memcpy(&resp_pf_to_vf->msg[1], msg, msg_len);
72 
73 	status = hclge_cmd_send(&hdev->hw, &desc, 1);
74 	if (status)
75 		dev_err(&hdev->pdev->dev,
76 			"PF failed(=%d) to send mailbox message to VF\n",
77 			status);
78 
79 	return status;
80 }
81 
82 int hclge_inform_reset_assert_to_vf(struct hclge_vport *vport)
83 {
84 	struct hclge_dev *hdev = vport->back;
85 	enum hnae3_reset_type reset_type;
86 	u8 msg_data[2];
87 	u8 dest_vfid;
88 
89 	dest_vfid = (u8)vport->vport_id;
90 
91 	if (hdev->reset_type == HNAE3_FUNC_RESET)
92 		reset_type = HNAE3_VF_PF_FUNC_RESET;
93 	else if (hdev->reset_type == HNAE3_FLR_RESET)
94 		reset_type = HNAE3_VF_FULL_RESET;
95 	else
96 		return -EINVAL;
97 
98 	memcpy(&msg_data[0], &reset_type, sizeof(u16));
99 
100 	/* send this requested info to VF */
101 	return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data),
102 				  HCLGE_MBX_ASSERTING_RESET, dest_vfid);
103 }
104 
105 static void hclge_free_vector_ring_chain(struct hnae3_ring_chain_node *head)
106 {
107 	struct hnae3_ring_chain_node *chain_tmp, *chain;
108 
109 	chain = head->next;
110 
111 	while (chain) {
112 		chain_tmp = chain->next;
113 		kzfree(chain);
114 		chain = chain_tmp;
115 	}
116 }
117 
118 /* hclge_get_ring_chain_from_mbx: get ring type & tqp id & int_gl idx
119  * from mailbox message
120  * msg[0]: opcode
121  * msg[1]: <not relevant to this function>
122  * msg[2]: ring_num
123  * msg[3]: first ring type (TX|RX)
124  * msg[4]: first tqp id
125  * msg[5]: first int_gl idx
126  * msg[6] ~ msg[14]: other ring type, tqp id and int_gl idx
127  */
128 static int hclge_get_ring_chain_from_mbx(
129 			struct hclge_mbx_vf_to_pf_cmd *req,
130 			struct hnae3_ring_chain_node *ring_chain,
131 			struct hclge_vport *vport)
132 {
133 	struct hnae3_ring_chain_node *cur_chain, *new_chain;
134 	int ring_num;
135 	int i;
136 
137 	ring_num = req->msg[2];
138 
139 	if (ring_num > ((HCLGE_MBX_VF_MSG_DATA_NUM -
140 		HCLGE_MBX_RING_MAP_BASIC_MSG_NUM) /
141 		HCLGE_MBX_RING_NODE_VARIABLE_NUM))
142 		return -ENOMEM;
143 
144 	hnae3_set_bit(ring_chain->flag, HNAE3_RING_TYPE_B, req->msg[3]);
145 	ring_chain->tqp_index =
146 			hclge_get_queue_id(vport->nic.kinfo.tqp[req->msg[4]]);
147 	hnae3_set_field(ring_chain->int_gl_idx, HNAE3_RING_GL_IDX_M,
148 			HNAE3_RING_GL_IDX_S,
149 			req->msg[5]);
150 
151 	cur_chain = ring_chain;
152 
153 	for (i = 1; i < ring_num; i++) {
154 		new_chain = kzalloc(sizeof(*new_chain), GFP_KERNEL);
155 		if (!new_chain)
156 			goto err;
157 
158 		hnae3_set_bit(new_chain->flag, HNAE3_RING_TYPE_B,
159 			      req->msg[HCLGE_MBX_RING_NODE_VARIABLE_NUM * i +
160 			      HCLGE_MBX_RING_MAP_BASIC_MSG_NUM]);
161 
162 		new_chain->tqp_index =
163 		hclge_get_queue_id(vport->nic.kinfo.tqp
164 			[req->msg[HCLGE_MBX_RING_NODE_VARIABLE_NUM * i +
165 			HCLGE_MBX_RING_MAP_BASIC_MSG_NUM + 1]]);
166 
167 		hnae3_set_field(new_chain->int_gl_idx, HNAE3_RING_GL_IDX_M,
168 				HNAE3_RING_GL_IDX_S,
169 				req->msg[HCLGE_MBX_RING_NODE_VARIABLE_NUM * i +
170 				HCLGE_MBX_RING_MAP_BASIC_MSG_NUM + 2]);
171 
172 		cur_chain->next = new_chain;
173 		cur_chain = new_chain;
174 	}
175 
176 	return 0;
177 err:
178 	hclge_free_vector_ring_chain(ring_chain);
179 	return -ENOMEM;
180 }
181 
182 static int hclge_map_unmap_ring_to_vf_vector(struct hclge_vport *vport, bool en,
183 					     struct hclge_mbx_vf_to_pf_cmd *req)
184 {
185 	struct hnae3_ring_chain_node ring_chain;
186 	int vector_id = req->msg[1];
187 	int ret;
188 
189 	memset(&ring_chain, 0, sizeof(ring_chain));
190 	ret = hclge_get_ring_chain_from_mbx(req, &ring_chain, vport);
191 	if (ret)
192 		return ret;
193 
194 	ret = hclge_bind_ring_with_vector(vport, vector_id, en, &ring_chain);
195 	if (ret)
196 		return ret;
197 
198 	hclge_free_vector_ring_chain(&ring_chain);
199 
200 	return 0;
201 }
202 
203 static int hclge_set_vf_promisc_mode(struct hclge_vport *vport,
204 				     struct hclge_mbx_vf_to_pf_cmd *req)
205 {
206 	bool en_bc = req->msg[1] ? true : false;
207 	struct hclge_promisc_param param;
208 
209 	/* vf is not allowed to enable unicast/multicast broadcast */
210 	hclge_promisc_param_init(&param, false, false, en_bc, vport->vport_id);
211 	return hclge_cmd_set_promisc_mode(vport->back, &param);
212 }
213 
214 static int hclge_set_vf_uc_mac_addr(struct hclge_vport *vport,
215 				    struct hclge_mbx_vf_to_pf_cmd *mbx_req,
216 				    bool gen_resp)
217 {
218 	const u8 *mac_addr = (const u8 *)(&mbx_req->msg[2]);
219 	struct hclge_dev *hdev = vport->back;
220 	int status;
221 
222 	if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_MODIFY) {
223 		const u8 *old_addr = (const u8 *)(&mbx_req->msg[8]);
224 
225 		hclge_rm_uc_addr_common(vport, old_addr);
226 		status = hclge_add_uc_addr_common(vport, mac_addr);
227 		if (status) {
228 			hclge_add_uc_addr_common(vport, old_addr);
229 		} else {
230 			hclge_rm_vport_mac_table(vport, mac_addr,
231 						 false, HCLGE_MAC_ADDR_UC);
232 			hclge_add_vport_mac_table(vport, mac_addr,
233 						  HCLGE_MAC_ADDR_UC);
234 		}
235 	} else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_ADD) {
236 		status = hclge_add_uc_addr_common(vport, mac_addr);
237 		if (!status)
238 			hclge_add_vport_mac_table(vport, mac_addr,
239 						  HCLGE_MAC_ADDR_UC);
240 	} else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_REMOVE) {
241 		status = hclge_rm_uc_addr_common(vport, mac_addr);
242 		if (!status)
243 			hclge_rm_vport_mac_table(vport, mac_addr,
244 						 false, HCLGE_MAC_ADDR_UC);
245 	} else {
246 		dev_err(&hdev->pdev->dev,
247 			"failed to set unicast mac addr, unknown subcode %d\n",
248 			mbx_req->msg[1]);
249 		return -EIO;
250 	}
251 
252 	if (gen_resp)
253 		hclge_gen_resp_to_vf(vport, mbx_req, status, NULL, 0);
254 
255 	return 0;
256 }
257 
258 static int hclge_set_vf_mc_mac_addr(struct hclge_vport *vport,
259 				    struct hclge_mbx_vf_to_pf_cmd *mbx_req,
260 				    bool gen_resp)
261 {
262 	const u8 *mac_addr = (const u8 *)(&mbx_req->msg[2]);
263 	struct hclge_dev *hdev = vport->back;
264 	u8 resp_len = 0;
265 	u8 resp_data;
266 	int status;
267 
268 	if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_MC_ADD) {
269 		status = hclge_add_mc_addr_common(vport, mac_addr);
270 		if (!status)
271 			hclge_add_vport_mac_table(vport, mac_addr,
272 						  HCLGE_MAC_ADDR_MC);
273 	} else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_MC_REMOVE) {
274 		status = hclge_rm_mc_addr_common(vport, mac_addr);
275 		if (!status)
276 			hclge_rm_vport_mac_table(vport, mac_addr,
277 						 false, HCLGE_MAC_ADDR_MC);
278 	} else {
279 		dev_err(&hdev->pdev->dev,
280 			"failed to set mcast mac addr, unknown subcode %d\n",
281 			mbx_req->msg[1]);
282 		return -EIO;
283 	}
284 
285 	if (gen_resp)
286 		hclge_gen_resp_to_vf(vport, mbx_req, status,
287 				     &resp_data, resp_len);
288 
289 	return 0;
290 }
291 
292 static int hclge_set_vf_vlan_cfg(struct hclge_vport *vport,
293 				 struct hclge_mbx_vf_to_pf_cmd *mbx_req,
294 				 bool gen_resp)
295 {
296 	int status = 0;
297 
298 	if (mbx_req->msg[1] == HCLGE_MBX_VLAN_FILTER) {
299 		struct hnae3_handle *handle = &vport->nic;
300 		u16 vlan, proto;
301 		bool is_kill;
302 
303 		is_kill = !!mbx_req->msg[2];
304 		memcpy(&vlan, &mbx_req->msg[3], sizeof(vlan));
305 		memcpy(&proto, &mbx_req->msg[5], sizeof(proto));
306 		status = hclge_set_vlan_filter(handle, cpu_to_be16(proto),
307 					       vlan, is_kill);
308 		if (!status)
309 			is_kill ? hclge_rm_vport_vlan_table(vport, vlan, false)
310 			: hclge_add_vport_vlan_table(vport, vlan);
311 	} else if (mbx_req->msg[1] == HCLGE_MBX_VLAN_RX_OFF_CFG) {
312 		struct hnae3_handle *handle = &vport->nic;
313 		bool en = mbx_req->msg[2] ? true : false;
314 
315 		status = hclge_en_hw_strip_rxvtag(handle, en);
316 	}
317 
318 	if (gen_resp)
319 		status = hclge_gen_resp_to_vf(vport, mbx_req, status, NULL, 0);
320 
321 	return status;
322 }
323 
324 static int hclge_set_vf_alive(struct hclge_vport *vport,
325 			      struct hclge_mbx_vf_to_pf_cmd *mbx_req,
326 			      bool gen_resp)
327 {
328 	bool alive = !!mbx_req->msg[2];
329 	int ret = 0;
330 
331 	if (alive)
332 		ret = hclge_vport_start(vport);
333 	else
334 		hclge_vport_stop(vport);
335 
336 	return ret;
337 }
338 
339 static int hclge_get_vf_tcinfo(struct hclge_vport *vport,
340 			       struct hclge_mbx_vf_to_pf_cmd *mbx_req,
341 			       bool gen_resp)
342 {
343 	struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
344 	u8 vf_tc_map = 0;
345 	int i, ret;
346 
347 	for (i = 0; i < kinfo->num_tc; i++)
348 		vf_tc_map |= BIT(i);
349 
350 	ret = hclge_gen_resp_to_vf(vport, mbx_req, 0, &vf_tc_map,
351 				   sizeof(u8));
352 
353 	return ret;
354 }
355 
356 static int hclge_get_vf_queue_info(struct hclge_vport *vport,
357 				   struct hclge_mbx_vf_to_pf_cmd *mbx_req,
358 				   bool gen_resp)
359 {
360 #define HCLGE_TQPS_RSS_INFO_LEN		6
361 	u8 resp_data[HCLGE_TQPS_RSS_INFO_LEN];
362 	struct hclge_dev *hdev = vport->back;
363 
364 	/* get the queue related info */
365 	memcpy(&resp_data[0], &vport->alloc_tqps, sizeof(u16));
366 	memcpy(&resp_data[2], &vport->nic.kinfo.rss_size, sizeof(u16));
367 	memcpy(&resp_data[4], &hdev->rx_buf_len, sizeof(u16));
368 
369 	return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data,
370 				    HCLGE_TQPS_RSS_INFO_LEN);
371 }
372 
373 static int hclge_get_vf_queue_depth(struct hclge_vport *vport,
374 				    struct hclge_mbx_vf_to_pf_cmd *mbx_req,
375 				    bool gen_resp)
376 {
377 #define HCLGE_TQPS_DEPTH_INFO_LEN	4
378 	u8 resp_data[HCLGE_TQPS_DEPTH_INFO_LEN];
379 	struct hclge_dev *hdev = vport->back;
380 
381 	/* get the queue depth info */
382 	memcpy(&resp_data[0], &hdev->num_tx_desc, sizeof(u16));
383 	memcpy(&resp_data[2], &hdev->num_rx_desc, sizeof(u16));
384 	return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data,
385 				    HCLGE_TQPS_DEPTH_INFO_LEN);
386 }
387 
388 static int hclge_get_link_info(struct hclge_vport *vport,
389 			       struct hclge_mbx_vf_to_pf_cmd *mbx_req)
390 {
391 	struct hclge_dev *hdev = vport->back;
392 	u16 link_status;
393 	u8 msg_data[10];
394 	u16 media_type;
395 	u8 dest_vfid;
396 	u16 duplex;
397 
398 	/* mac.link can only be 0 or 1 */
399 	link_status = (u16)hdev->hw.mac.link;
400 	duplex = hdev->hw.mac.duplex;
401 	media_type = hdev->hw.mac.media_type;
402 	memcpy(&msg_data[0], &link_status, sizeof(u16));
403 	memcpy(&msg_data[2], &hdev->hw.mac.speed, sizeof(u32));
404 	memcpy(&msg_data[6], &duplex, sizeof(u16));
405 	memcpy(&msg_data[8], &media_type, sizeof(u16));
406 	dest_vfid = mbx_req->mbx_src_vfid;
407 
408 	/* send this requested info to VF */
409 	return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data),
410 				  HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid);
411 }
412 
413 static void hclge_get_link_mode(struct hclge_vport *vport,
414 				struct hclge_mbx_vf_to_pf_cmd *mbx_req)
415 {
416 #define HCLGE_SUPPORTED   1
417 	struct hclge_dev *hdev = vport->back;
418 	unsigned long advertising;
419 	unsigned long supported;
420 	unsigned long send_data;
421 	u8 msg_data[10];
422 	u8 dest_vfid;
423 
424 	advertising = hdev->hw.mac.advertising[0];
425 	supported = hdev->hw.mac.supported[0];
426 	dest_vfid = mbx_req->mbx_src_vfid;
427 	msg_data[0] = mbx_req->msg[2];
428 
429 	send_data = msg_data[0] == HCLGE_SUPPORTED ? supported : advertising;
430 
431 	memcpy(&msg_data[2], &send_data, sizeof(unsigned long));
432 	hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data),
433 			   HCLGE_MBX_LINK_STAT_MODE, dest_vfid);
434 }
435 
436 static void hclge_mbx_reset_vf_queue(struct hclge_vport *vport,
437 				     struct hclge_mbx_vf_to_pf_cmd *mbx_req)
438 {
439 	u16 queue_id;
440 
441 	memcpy(&queue_id, &mbx_req->msg[2], sizeof(queue_id));
442 
443 	hclge_reset_vf_queue(vport, queue_id);
444 
445 	/* send response msg to VF after queue reset complete*/
446 	hclge_gen_resp_to_vf(vport, mbx_req, 0, NULL, 0);
447 }
448 
449 static void hclge_reset_vf(struct hclge_vport *vport,
450 			   struct hclge_mbx_vf_to_pf_cmd *mbx_req)
451 {
452 	struct hclge_dev *hdev = vport->back;
453 	int ret;
454 
455 	dev_warn(&hdev->pdev->dev, "PF received VF reset request from VF %d!",
456 		 vport->vport_id);
457 
458 	ret = hclge_func_reset_cmd(hdev, vport->vport_id);
459 	hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0);
460 }
461 
462 static void hclge_vf_keep_alive(struct hclge_vport *vport,
463 				struct hclge_mbx_vf_to_pf_cmd *mbx_req)
464 {
465 	vport->last_active_jiffies = jiffies;
466 }
467 
468 static int hclge_set_vf_mtu(struct hclge_vport *vport,
469 			    struct hclge_mbx_vf_to_pf_cmd *mbx_req)
470 {
471 	int ret;
472 	u32 mtu;
473 
474 	memcpy(&mtu, &mbx_req->msg[2], sizeof(mtu));
475 	ret = hclge_set_vport_mtu(vport, mtu);
476 
477 	return hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0);
478 }
479 
480 static int hclge_get_queue_id_in_pf(struct hclge_vport *vport,
481 				    struct hclge_mbx_vf_to_pf_cmd *mbx_req)
482 {
483 	u16 queue_id, qid_in_pf;
484 	u8 resp_data[2];
485 
486 	memcpy(&queue_id, &mbx_req->msg[2], sizeof(queue_id));
487 	qid_in_pf = hclge_covert_handle_qid_global(&vport->nic, queue_id);
488 	memcpy(resp_data, &qid_in_pf, sizeof(qid_in_pf));
489 
490 	return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 2);
491 }
492 
493 static int hclge_get_rss_key(struct hclge_vport *vport,
494 			     struct hclge_mbx_vf_to_pf_cmd *mbx_req)
495 {
496 #define HCLGE_RSS_MBX_RESP_LEN	8
497 	u8 resp_data[HCLGE_RSS_MBX_RESP_LEN];
498 	struct hclge_dev *hdev = vport->back;
499 	u8 index;
500 
501 	index = mbx_req->msg[2];
502 
503 	memcpy(&resp_data[0],
504 	       &hdev->vport[0].rss_hash_key[index * HCLGE_RSS_MBX_RESP_LEN],
505 	       HCLGE_RSS_MBX_RESP_LEN);
506 
507 	return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data,
508 				    HCLGE_RSS_MBX_RESP_LEN);
509 }
510 
511 static bool hclge_cmd_crq_empty(struct hclge_hw *hw)
512 {
513 	u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG);
514 
515 	return tail == hw->cmq.crq.next_to_use;
516 }
517 
518 void hclge_mbx_handler(struct hclge_dev *hdev)
519 {
520 	struct hclge_cmq_ring *crq = &hdev->hw.cmq.crq;
521 	struct hclge_mbx_vf_to_pf_cmd *req;
522 	struct hclge_vport *vport;
523 	struct hclge_desc *desc;
524 	int ret, flag;
525 
526 	/* handle all the mailbox requests in the queue */
527 	while (!hclge_cmd_crq_empty(&hdev->hw)) {
528 		if (test_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state)) {
529 			dev_warn(&hdev->pdev->dev,
530 				 "command queue needs re-initializing\n");
531 			return;
532 		}
533 
534 		desc = &crq->desc[crq->next_to_use];
535 		req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data;
536 
537 		flag = le16_to_cpu(crq->desc[crq->next_to_use].flag);
538 		if (unlikely(!hnae3_get_bit(flag, HCLGE_CMDQ_RX_OUTVLD_B))) {
539 			dev_warn(&hdev->pdev->dev,
540 				 "dropped invalid mailbox message, code = %d\n",
541 				 req->msg[0]);
542 
543 			/* dropping/not processing this invalid message */
544 			crq->desc[crq->next_to_use].flag = 0;
545 			hclge_mbx_ring_ptr_move_crq(crq);
546 			continue;
547 		}
548 
549 		vport = &hdev->vport[req->mbx_src_vfid];
550 
551 		switch (req->msg[0]) {
552 		case HCLGE_MBX_MAP_RING_TO_VECTOR:
553 			ret = hclge_map_unmap_ring_to_vf_vector(vport, true,
554 								req);
555 			break;
556 		case HCLGE_MBX_UNMAP_RING_TO_VECTOR:
557 			ret = hclge_map_unmap_ring_to_vf_vector(vport, false,
558 								req);
559 			break;
560 		case HCLGE_MBX_SET_PROMISC_MODE:
561 			ret = hclge_set_vf_promisc_mode(vport, req);
562 			if (ret)
563 				dev_err(&hdev->pdev->dev,
564 					"PF fail(%d) to set VF promisc mode\n",
565 					ret);
566 			break;
567 		case HCLGE_MBX_SET_UNICAST:
568 			ret = hclge_set_vf_uc_mac_addr(vport, req, true);
569 			if (ret)
570 				dev_err(&hdev->pdev->dev,
571 					"PF fail(%d) to set VF UC MAC Addr\n",
572 					ret);
573 			break;
574 		case HCLGE_MBX_SET_MULTICAST:
575 			ret = hclge_set_vf_mc_mac_addr(vport, req, false);
576 			if (ret)
577 				dev_err(&hdev->pdev->dev,
578 					"PF fail(%d) to set VF MC MAC Addr\n",
579 					ret);
580 			break;
581 		case HCLGE_MBX_SET_VLAN:
582 			ret = hclge_set_vf_vlan_cfg(vport, req, false);
583 			if (ret)
584 				dev_err(&hdev->pdev->dev,
585 					"PF failed(%d) to config VF's VLAN\n",
586 					ret);
587 			break;
588 		case HCLGE_MBX_SET_ALIVE:
589 			ret = hclge_set_vf_alive(vport, req, false);
590 			if (ret)
591 				dev_err(&hdev->pdev->dev,
592 					"PF failed(%d) to set VF's ALIVE\n",
593 					ret);
594 			break;
595 		case HCLGE_MBX_GET_QINFO:
596 			ret = hclge_get_vf_queue_info(vport, req, true);
597 			if (ret)
598 				dev_err(&hdev->pdev->dev,
599 					"PF failed(%d) to get Q info for VF\n",
600 					ret);
601 			break;
602 		case HCLGE_MBX_GET_QDEPTH:
603 			ret = hclge_get_vf_queue_depth(vport, req, true);
604 			if (ret)
605 				dev_err(&hdev->pdev->dev,
606 					"PF failed(%d) to get Q depth for VF\n",
607 					ret);
608 			break;
609 
610 		case HCLGE_MBX_GET_TCINFO:
611 			ret = hclge_get_vf_tcinfo(vport, req, true);
612 			if (ret)
613 				dev_err(&hdev->pdev->dev,
614 					"PF failed(%d) to get TC info for VF\n",
615 					ret);
616 			break;
617 		case HCLGE_MBX_GET_LINK_STATUS:
618 			ret = hclge_get_link_info(vport, req);
619 			if (ret)
620 				dev_err(&hdev->pdev->dev,
621 					"PF fail(%d) to get link stat for VF\n",
622 					ret);
623 			break;
624 		case HCLGE_MBX_QUEUE_RESET:
625 			hclge_mbx_reset_vf_queue(vport, req);
626 			break;
627 		case HCLGE_MBX_RESET:
628 			hclge_reset_vf(vport, req);
629 			break;
630 		case HCLGE_MBX_KEEP_ALIVE:
631 			hclge_vf_keep_alive(vport, req);
632 			break;
633 		case HCLGE_MBX_SET_MTU:
634 			ret = hclge_set_vf_mtu(vport, req);
635 			if (ret)
636 				dev_err(&hdev->pdev->dev,
637 					"VF fail(%d) to set mtu\n", ret);
638 			break;
639 		case HCLGE_MBX_GET_QID_IN_PF:
640 			ret = hclge_get_queue_id_in_pf(vport, req);
641 			if (ret)
642 				dev_err(&hdev->pdev->dev,
643 					"PF failed(%d) to get qid for VF\n",
644 					ret);
645 			break;
646 		case HCLGE_MBX_GET_RSS_KEY:
647 			ret = hclge_get_rss_key(vport, req);
648 			if (ret)
649 				dev_err(&hdev->pdev->dev,
650 					"PF fail(%d) to get rss key for VF\n",
651 					ret);
652 			break;
653 		case HCLGE_MBX_GET_LINK_MODE:
654 			hclge_get_link_mode(vport, req);
655 			break;
656 		case HCLGE_MBX_GET_VF_FLR_STATUS:
657 			mutex_lock(&hdev->vport_cfg_mutex);
658 			hclge_rm_vport_all_mac_table(vport, true,
659 						     HCLGE_MAC_ADDR_UC);
660 			hclge_rm_vport_all_mac_table(vport, true,
661 						     HCLGE_MAC_ADDR_MC);
662 			hclge_rm_vport_all_vlan_table(vport, true);
663 			mutex_unlock(&hdev->vport_cfg_mutex);
664 			break;
665 		default:
666 			dev_err(&hdev->pdev->dev,
667 				"un-supported mailbox message, code = %d\n",
668 				req->msg[0]);
669 			break;
670 		}
671 		crq->desc[crq->next_to_use].flag = 0;
672 		hclge_mbx_ring_ptr_move_crq(crq);
673 	}
674 
675 	/* Write back CMDQ_RQ header pointer, M7 need this pointer */
676 	hclge_write_dev(&hdev->hw, HCLGE_NIC_CRQ_HEAD_REG, crq->next_to_use);
677 }
678