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