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(¶m, false, false, en_bc, vport->vport_id); 211 return hclge_cmd_set_promisc_mode(vport->back, ¶m); 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 { 217 const u8 *mac_addr = (const u8 *)(&mbx_req->msg[2]); 218 struct hclge_dev *hdev = vport->back; 219 int status; 220 221 if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_MODIFY) { 222 const u8 *old_addr = (const u8 *)(&mbx_req->msg[8]); 223 224 hclge_rm_uc_addr_common(vport, old_addr); 225 status = hclge_add_uc_addr_common(vport, mac_addr); 226 if (status) { 227 hclge_add_uc_addr_common(vport, old_addr); 228 } else { 229 hclge_rm_vport_mac_table(vport, mac_addr, 230 false, HCLGE_MAC_ADDR_UC); 231 hclge_add_vport_mac_table(vport, mac_addr, 232 HCLGE_MAC_ADDR_UC); 233 } 234 } else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_ADD) { 235 status = hclge_add_uc_addr_common(vport, mac_addr); 236 if (!status) 237 hclge_add_vport_mac_table(vport, mac_addr, 238 HCLGE_MAC_ADDR_UC); 239 } else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_REMOVE) { 240 status = hclge_rm_uc_addr_common(vport, mac_addr); 241 if (!status) 242 hclge_rm_vport_mac_table(vport, mac_addr, 243 false, HCLGE_MAC_ADDR_UC); 244 } else { 245 dev_err(&hdev->pdev->dev, 246 "failed to set unicast mac addr, unknown subcode %d\n", 247 mbx_req->msg[1]); 248 return -EIO; 249 } 250 251 if (mbx_req->mbx_need_resp & HCLGE_MBX_NEED_RESP_BIT) 252 hclge_gen_resp_to_vf(vport, mbx_req, status, NULL, 0); 253 254 return 0; 255 } 256 257 static int hclge_set_vf_mc_mac_addr(struct hclge_vport *vport, 258 struct hclge_mbx_vf_to_pf_cmd *mbx_req, 259 bool gen_resp) 260 { 261 const u8 *mac_addr = (const u8 *)(&mbx_req->msg[2]); 262 struct hclge_dev *hdev = vport->back; 263 u8 resp_len = 0; 264 u8 resp_data; 265 int status; 266 267 if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_MC_ADD) { 268 status = hclge_add_mc_addr_common(vport, mac_addr); 269 if (!status) 270 hclge_add_vport_mac_table(vport, mac_addr, 271 HCLGE_MAC_ADDR_MC); 272 } else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_MC_REMOVE) { 273 status = hclge_rm_mc_addr_common(vport, mac_addr); 274 if (!status) 275 hclge_rm_vport_mac_table(vport, mac_addr, 276 false, HCLGE_MAC_ADDR_MC); 277 } else { 278 dev_err(&hdev->pdev->dev, 279 "failed to set mcast mac addr, unknown subcode %d\n", 280 mbx_req->msg[1]); 281 return -EIO; 282 } 283 284 if (gen_resp) 285 hclge_gen_resp_to_vf(vport, mbx_req, status, 286 &resp_data, resp_len); 287 288 return 0; 289 } 290 291 int hclge_push_vf_port_base_vlan_info(struct hclge_vport *vport, u8 vfid, 292 u16 state, u16 vlan_tag, u16 qos, 293 u16 vlan_proto) 294 { 295 #define MSG_DATA_SIZE 8 296 297 u8 msg_data[MSG_DATA_SIZE]; 298 299 memcpy(&msg_data[0], &state, sizeof(u16)); 300 memcpy(&msg_data[2], &vlan_proto, sizeof(u16)); 301 memcpy(&msg_data[4], &qos, sizeof(u16)); 302 memcpy(&msg_data[6], &vlan_tag, sizeof(u16)); 303 304 return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data), 305 HLCGE_MBX_PUSH_VLAN_INFO, vfid); 306 } 307 308 static int hclge_set_vf_vlan_cfg(struct hclge_vport *vport, 309 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 310 { 311 int status = 0; 312 313 if (mbx_req->msg[1] == HCLGE_MBX_VLAN_FILTER) { 314 struct hnae3_handle *handle = &vport->nic; 315 u16 vlan, proto; 316 bool is_kill; 317 318 is_kill = !!mbx_req->msg[2]; 319 memcpy(&vlan, &mbx_req->msg[3], sizeof(vlan)); 320 memcpy(&proto, &mbx_req->msg[5], sizeof(proto)); 321 status = hclge_set_vlan_filter(handle, cpu_to_be16(proto), 322 vlan, is_kill); 323 } else if (mbx_req->msg[1] == HCLGE_MBX_VLAN_RX_OFF_CFG) { 324 struct hnae3_handle *handle = &vport->nic; 325 bool en = mbx_req->msg[2] ? true : false; 326 327 status = hclge_en_hw_strip_rxvtag(handle, en); 328 } else if (mbx_req->msg[1] == HCLGE_MBX_PORT_BASE_VLAN_CFG) { 329 struct hclge_vlan_info *vlan_info; 330 u16 *state; 331 332 state = (u16 *)&mbx_req->msg[2]; 333 vlan_info = (struct hclge_vlan_info *)&mbx_req->msg[4]; 334 status = hclge_update_port_base_vlan_cfg(vport, *state, 335 vlan_info); 336 } else if (mbx_req->msg[1] == HCLGE_MBX_GET_PORT_BASE_VLAN_STATE) { 337 u8 state; 338 339 state = vport->port_base_vlan_cfg.state; 340 status = hclge_gen_resp_to_vf(vport, mbx_req, 0, &state, 341 sizeof(u8)); 342 } 343 344 return status; 345 } 346 347 static int hclge_set_vf_alive(struct hclge_vport *vport, 348 struct hclge_mbx_vf_to_pf_cmd *mbx_req, 349 bool gen_resp) 350 { 351 bool alive = !!mbx_req->msg[2]; 352 int ret = 0; 353 354 if (alive) 355 ret = hclge_vport_start(vport); 356 else 357 hclge_vport_stop(vport); 358 359 return ret; 360 } 361 362 static int hclge_get_vf_tcinfo(struct hclge_vport *vport, 363 struct hclge_mbx_vf_to_pf_cmd *mbx_req, 364 bool gen_resp) 365 { 366 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo; 367 u8 vf_tc_map = 0; 368 int i, ret; 369 370 for (i = 0; i < kinfo->num_tc; i++) 371 vf_tc_map |= BIT(i); 372 373 ret = hclge_gen_resp_to_vf(vport, mbx_req, 0, &vf_tc_map, 374 sizeof(u8)); 375 376 return ret; 377 } 378 379 static int hclge_get_vf_queue_info(struct hclge_vport *vport, 380 struct hclge_mbx_vf_to_pf_cmd *mbx_req, 381 bool gen_resp) 382 { 383 #define HCLGE_TQPS_RSS_INFO_LEN 6 384 u8 resp_data[HCLGE_TQPS_RSS_INFO_LEN]; 385 struct hclge_dev *hdev = vport->back; 386 387 /* get the queue related info */ 388 memcpy(&resp_data[0], &vport->alloc_tqps, sizeof(u16)); 389 memcpy(&resp_data[2], &vport->nic.kinfo.rss_size, sizeof(u16)); 390 memcpy(&resp_data[4], &hdev->rx_buf_len, sizeof(u16)); 391 392 return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 393 HCLGE_TQPS_RSS_INFO_LEN); 394 } 395 396 static int hclge_get_vf_queue_depth(struct hclge_vport *vport, 397 struct hclge_mbx_vf_to_pf_cmd *mbx_req, 398 bool gen_resp) 399 { 400 #define HCLGE_TQPS_DEPTH_INFO_LEN 4 401 u8 resp_data[HCLGE_TQPS_DEPTH_INFO_LEN]; 402 struct hclge_dev *hdev = vport->back; 403 404 /* get the queue depth info */ 405 memcpy(&resp_data[0], &hdev->num_tx_desc, sizeof(u16)); 406 memcpy(&resp_data[2], &hdev->num_rx_desc, sizeof(u16)); 407 return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 408 HCLGE_TQPS_DEPTH_INFO_LEN); 409 } 410 411 static int hclge_get_vf_media_type(struct hclge_vport *vport, 412 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 413 { 414 struct hclge_dev *hdev = vport->back; 415 u8 resp_data[2]; 416 417 resp_data[0] = hdev->hw.mac.media_type; 418 resp_data[1] = hdev->hw.mac.module_type; 419 return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 420 sizeof(resp_data)); 421 } 422 423 static int hclge_get_link_info(struct hclge_vport *vport, 424 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 425 { 426 struct hclge_dev *hdev = vport->back; 427 u16 link_status; 428 u8 msg_data[8]; 429 u8 dest_vfid; 430 u16 duplex; 431 432 /* mac.link can only be 0 or 1 */ 433 link_status = (u16)hdev->hw.mac.link; 434 duplex = hdev->hw.mac.duplex; 435 memcpy(&msg_data[0], &link_status, sizeof(u16)); 436 memcpy(&msg_data[2], &hdev->hw.mac.speed, sizeof(u32)); 437 memcpy(&msg_data[6], &duplex, sizeof(u16)); 438 dest_vfid = mbx_req->mbx_src_vfid; 439 440 /* send this requested info to VF */ 441 return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data), 442 HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid); 443 } 444 445 static void hclge_get_link_mode(struct hclge_vport *vport, 446 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 447 { 448 #define HCLGE_SUPPORTED 1 449 struct hclge_dev *hdev = vport->back; 450 unsigned long advertising; 451 unsigned long supported; 452 unsigned long send_data; 453 u8 msg_data[10]; 454 u8 dest_vfid; 455 456 advertising = hdev->hw.mac.advertising[0]; 457 supported = hdev->hw.mac.supported[0]; 458 dest_vfid = mbx_req->mbx_src_vfid; 459 msg_data[0] = mbx_req->msg[2]; 460 461 send_data = msg_data[0] == HCLGE_SUPPORTED ? supported : advertising; 462 463 memcpy(&msg_data[2], &send_data, sizeof(unsigned long)); 464 hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data), 465 HCLGE_MBX_LINK_STAT_MODE, dest_vfid); 466 } 467 468 static void hclge_mbx_reset_vf_queue(struct hclge_vport *vport, 469 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 470 { 471 u16 queue_id; 472 473 memcpy(&queue_id, &mbx_req->msg[2], sizeof(queue_id)); 474 475 hclge_reset_vf_queue(vport, queue_id); 476 477 /* send response msg to VF after queue reset complete*/ 478 hclge_gen_resp_to_vf(vport, mbx_req, 0, NULL, 0); 479 } 480 481 static void hclge_reset_vf(struct hclge_vport *vport, 482 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 483 { 484 struct hclge_dev *hdev = vport->back; 485 int ret; 486 487 dev_warn(&hdev->pdev->dev, "PF received VF reset request from VF %d!", 488 vport->vport_id); 489 490 ret = hclge_func_reset_cmd(hdev, vport->vport_id); 491 hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0); 492 } 493 494 static void hclge_vf_keep_alive(struct hclge_vport *vport, 495 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 496 { 497 vport->last_active_jiffies = jiffies; 498 } 499 500 static int hclge_set_vf_mtu(struct hclge_vport *vport, 501 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 502 { 503 int ret; 504 u32 mtu; 505 506 memcpy(&mtu, &mbx_req->msg[2], sizeof(mtu)); 507 ret = hclge_set_vport_mtu(vport, mtu); 508 509 return hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0); 510 } 511 512 static int hclge_get_queue_id_in_pf(struct hclge_vport *vport, 513 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 514 { 515 u16 queue_id, qid_in_pf; 516 u8 resp_data[2]; 517 518 memcpy(&queue_id, &mbx_req->msg[2], sizeof(queue_id)); 519 qid_in_pf = hclge_covert_handle_qid_global(&vport->nic, queue_id); 520 memcpy(resp_data, &qid_in_pf, sizeof(qid_in_pf)); 521 522 return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 2); 523 } 524 525 static int hclge_get_rss_key(struct hclge_vport *vport, 526 struct hclge_mbx_vf_to_pf_cmd *mbx_req) 527 { 528 #define HCLGE_RSS_MBX_RESP_LEN 8 529 u8 resp_data[HCLGE_RSS_MBX_RESP_LEN]; 530 struct hclge_dev *hdev = vport->back; 531 u8 index; 532 533 index = mbx_req->msg[2]; 534 535 memcpy(&resp_data[0], 536 &hdev->vport[0].rss_hash_key[index * HCLGE_RSS_MBX_RESP_LEN], 537 HCLGE_RSS_MBX_RESP_LEN); 538 539 return hclge_gen_resp_to_vf(vport, mbx_req, 0, resp_data, 540 HCLGE_RSS_MBX_RESP_LEN); 541 } 542 543 static bool hclge_cmd_crq_empty(struct hclge_hw *hw) 544 { 545 u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG); 546 547 return tail == hw->cmq.crq.next_to_use; 548 } 549 550 void hclge_mbx_handler(struct hclge_dev *hdev) 551 { 552 struct hclge_cmq_ring *crq = &hdev->hw.cmq.crq; 553 struct hclge_mbx_vf_to_pf_cmd *req; 554 struct hclge_vport *vport; 555 struct hclge_desc *desc; 556 int ret, flag; 557 558 /* handle all the mailbox requests in the queue */ 559 while (!hclge_cmd_crq_empty(&hdev->hw)) { 560 if (test_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state)) { 561 dev_warn(&hdev->pdev->dev, 562 "command queue needs re-initializing\n"); 563 return; 564 } 565 566 desc = &crq->desc[crq->next_to_use]; 567 req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data; 568 569 flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); 570 if (unlikely(!hnae3_get_bit(flag, HCLGE_CMDQ_RX_OUTVLD_B))) { 571 dev_warn(&hdev->pdev->dev, 572 "dropped invalid mailbox message, code = %d\n", 573 req->msg[0]); 574 575 /* dropping/not processing this invalid message */ 576 crq->desc[crq->next_to_use].flag = 0; 577 hclge_mbx_ring_ptr_move_crq(crq); 578 continue; 579 } 580 581 vport = &hdev->vport[req->mbx_src_vfid]; 582 583 switch (req->msg[0]) { 584 case HCLGE_MBX_MAP_RING_TO_VECTOR: 585 ret = hclge_map_unmap_ring_to_vf_vector(vport, true, 586 req); 587 break; 588 case HCLGE_MBX_UNMAP_RING_TO_VECTOR: 589 ret = hclge_map_unmap_ring_to_vf_vector(vport, false, 590 req); 591 break; 592 case HCLGE_MBX_SET_PROMISC_MODE: 593 ret = hclge_set_vf_promisc_mode(vport, req); 594 if (ret) 595 dev_err(&hdev->pdev->dev, 596 "PF fail(%d) to set VF promisc mode\n", 597 ret); 598 break; 599 case HCLGE_MBX_SET_UNICAST: 600 ret = hclge_set_vf_uc_mac_addr(vport, req); 601 if (ret) 602 dev_err(&hdev->pdev->dev, 603 "PF fail(%d) to set VF UC MAC Addr\n", 604 ret); 605 break; 606 case HCLGE_MBX_SET_MULTICAST: 607 ret = hclge_set_vf_mc_mac_addr(vport, req, false); 608 if (ret) 609 dev_err(&hdev->pdev->dev, 610 "PF fail(%d) to set VF MC MAC Addr\n", 611 ret); 612 break; 613 case HCLGE_MBX_SET_VLAN: 614 ret = hclge_set_vf_vlan_cfg(vport, req); 615 if (ret) 616 dev_err(&hdev->pdev->dev, 617 "PF failed(%d) to config VF's VLAN\n", 618 ret); 619 break; 620 case HCLGE_MBX_SET_ALIVE: 621 ret = hclge_set_vf_alive(vport, req, false); 622 if (ret) 623 dev_err(&hdev->pdev->dev, 624 "PF failed(%d) to set VF's ALIVE\n", 625 ret); 626 break; 627 case HCLGE_MBX_GET_QINFO: 628 ret = hclge_get_vf_queue_info(vport, req, true); 629 if (ret) 630 dev_err(&hdev->pdev->dev, 631 "PF failed(%d) to get Q info for VF\n", 632 ret); 633 break; 634 case HCLGE_MBX_GET_QDEPTH: 635 ret = hclge_get_vf_queue_depth(vport, req, true); 636 if (ret) 637 dev_err(&hdev->pdev->dev, 638 "PF failed(%d) to get Q depth for VF\n", 639 ret); 640 break; 641 642 case HCLGE_MBX_GET_TCINFO: 643 ret = hclge_get_vf_tcinfo(vport, req, true); 644 if (ret) 645 dev_err(&hdev->pdev->dev, 646 "PF failed(%d) to get TC info for VF\n", 647 ret); 648 break; 649 case HCLGE_MBX_GET_LINK_STATUS: 650 ret = hclge_get_link_info(vport, req); 651 if (ret) 652 dev_err(&hdev->pdev->dev, 653 "PF fail(%d) to get link stat for VF\n", 654 ret); 655 break; 656 case HCLGE_MBX_QUEUE_RESET: 657 hclge_mbx_reset_vf_queue(vport, req); 658 break; 659 case HCLGE_MBX_RESET: 660 hclge_reset_vf(vport, req); 661 break; 662 case HCLGE_MBX_KEEP_ALIVE: 663 hclge_vf_keep_alive(vport, req); 664 break; 665 case HCLGE_MBX_SET_MTU: 666 ret = hclge_set_vf_mtu(vport, req); 667 if (ret) 668 dev_err(&hdev->pdev->dev, 669 "VF fail(%d) to set mtu\n", ret); 670 break; 671 case HCLGE_MBX_GET_QID_IN_PF: 672 ret = hclge_get_queue_id_in_pf(vport, req); 673 if (ret) 674 dev_err(&hdev->pdev->dev, 675 "PF failed(%d) to get qid for VF\n", 676 ret); 677 break; 678 case HCLGE_MBX_GET_RSS_KEY: 679 ret = hclge_get_rss_key(vport, req); 680 if (ret) 681 dev_err(&hdev->pdev->dev, 682 "PF fail(%d) to get rss key for VF\n", 683 ret); 684 break; 685 case HCLGE_MBX_GET_LINK_MODE: 686 hclge_get_link_mode(vport, req); 687 break; 688 case HCLGE_MBX_GET_VF_FLR_STATUS: 689 mutex_lock(&hdev->vport_cfg_mutex); 690 hclge_rm_vport_all_mac_table(vport, true, 691 HCLGE_MAC_ADDR_UC); 692 hclge_rm_vport_all_mac_table(vport, true, 693 HCLGE_MAC_ADDR_MC); 694 hclge_rm_vport_all_vlan_table(vport, true); 695 mutex_unlock(&hdev->vport_cfg_mutex); 696 break; 697 case HCLGE_MBX_GET_MEDIA_TYPE: 698 ret = hclge_get_vf_media_type(vport, req); 699 if (ret) 700 dev_err(&hdev->pdev->dev, 701 "PF fail(%d) to media type for VF\n", 702 ret); 703 break; 704 default: 705 dev_err(&hdev->pdev->dev, 706 "un-supported mailbox message, code = %d\n", 707 req->msg[0]); 708 break; 709 } 710 crq->desc[crq->next_to_use].flag = 0; 711 hclge_mbx_ring_ptr_move_crq(crq); 712 } 713 714 /* Write back CMDQ_RQ header pointer, M7 need this pointer */ 715 hclge_write_dev(&hdev->hw, HCLGE_NIC_CRQ_HEAD_REG, crq->next_to_use); 716 } 717