1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2013 - 2018 Intel Corporation. */ 3 4 #include "iavf.h" 5 #include "iavf_prototype.h" 6 #include "iavf_client.h" 7 8 /* busy wait delay in msec */ 9 #define IAVF_BUSY_WAIT_DELAY 10 10 #define IAVF_BUSY_WAIT_COUNT 50 11 12 /** 13 * iavf_send_pf_msg 14 * @adapter: adapter structure 15 * @op: virtual channel opcode 16 * @msg: pointer to message buffer 17 * @len: message length 18 * 19 * Send message to PF and print status if failure. 20 **/ 21 static int iavf_send_pf_msg(struct iavf_adapter *adapter, 22 enum virtchnl_ops op, u8 *msg, u16 len) 23 { 24 struct iavf_hw *hw = &adapter->hw; 25 enum iavf_status err; 26 27 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) 28 return 0; /* nothing to see here, move along */ 29 30 err = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL); 31 if (err) 32 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n", 33 op, iavf_stat_str(hw, err), 34 iavf_aq_str(hw, hw->aq.asq_last_status)); 35 return err; 36 } 37 38 /** 39 * iavf_send_api_ver 40 * @adapter: adapter structure 41 * 42 * Send API version admin queue message to the PF. The reply is not checked 43 * in this function. Returns 0 if the message was successfully 44 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not. 45 **/ 46 int iavf_send_api_ver(struct iavf_adapter *adapter) 47 { 48 struct virtchnl_version_info vvi; 49 50 vvi.major = VIRTCHNL_VERSION_MAJOR; 51 vvi.minor = VIRTCHNL_VERSION_MINOR; 52 53 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi, 54 sizeof(vvi)); 55 } 56 57 /** 58 * iavf_verify_api_ver 59 * @adapter: adapter structure 60 * 61 * Compare API versions with the PF. Must be called after admin queue is 62 * initialized. Returns 0 if API versions match, -EIO if they do not, 63 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors 64 * from the firmware are propagated. 65 **/ 66 int iavf_verify_api_ver(struct iavf_adapter *adapter) 67 { 68 struct virtchnl_version_info *pf_vvi; 69 struct iavf_hw *hw = &adapter->hw; 70 struct iavf_arq_event_info event; 71 enum virtchnl_ops op; 72 enum iavf_status err; 73 74 event.buf_len = IAVF_MAX_AQ_BUF_SIZE; 75 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 76 if (!event.msg_buf) { 77 err = -ENOMEM; 78 goto out; 79 } 80 81 while (1) { 82 err = iavf_clean_arq_element(hw, &event, NULL); 83 /* When the AQ is empty, iavf_clean_arq_element will return 84 * nonzero and this loop will terminate. 85 */ 86 if (err) 87 goto out_alloc; 88 op = 89 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); 90 if (op == VIRTCHNL_OP_VERSION) 91 break; 92 } 93 94 95 err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low); 96 if (err) 97 goto out_alloc; 98 99 if (op != VIRTCHNL_OP_VERSION) { 100 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n", 101 op); 102 err = -EIO; 103 goto out_alloc; 104 } 105 106 pf_vvi = (struct virtchnl_version_info *)event.msg_buf; 107 adapter->pf_version = *pf_vvi; 108 109 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) || 110 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) && 111 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR))) 112 err = -EIO; 113 114 out_alloc: 115 kfree(event.msg_buf); 116 out: 117 return err; 118 } 119 120 /** 121 * iavf_send_vf_config_msg 122 * @adapter: adapter structure 123 * 124 * Send VF configuration request admin queue message to the PF. The reply 125 * is not checked in this function. Returns 0 if the message was 126 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not. 127 **/ 128 int iavf_send_vf_config_msg(struct iavf_adapter *adapter) 129 { 130 u32 caps; 131 132 caps = VIRTCHNL_VF_OFFLOAD_L2 | 133 VIRTCHNL_VF_OFFLOAD_RSS_PF | 134 VIRTCHNL_VF_OFFLOAD_RSS_AQ | 135 VIRTCHNL_VF_OFFLOAD_RSS_REG | 136 VIRTCHNL_VF_OFFLOAD_VLAN | 137 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | 138 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 | 139 VIRTCHNL_VF_OFFLOAD_ENCAP | 140 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM | 141 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES | 142 VIRTCHNL_VF_OFFLOAD_ADQ; 143 144 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES; 145 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG; 146 if (PF_IS_V11(adapter)) 147 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 148 (u8 *)&caps, sizeof(caps)); 149 else 150 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 151 NULL, 0); 152 } 153 154 /** 155 * iavf_validate_num_queues 156 * @adapter: adapter structure 157 * 158 * Validate that the number of queues the PF has sent in 159 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle. 160 **/ 161 static void iavf_validate_num_queues(struct iavf_adapter *adapter) 162 { 163 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) { 164 struct virtchnl_vsi_resource *vsi_res; 165 int i; 166 167 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n", 168 adapter->vf_res->num_queue_pairs, 169 IAVF_MAX_REQ_QUEUES); 170 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n", 171 IAVF_MAX_REQ_QUEUES); 172 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 173 for (i = 0; i < adapter->vf_res->num_vsis; i++) { 174 vsi_res = &adapter->vf_res->vsi_res[i]; 175 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 176 } 177 } 178 } 179 180 /** 181 * iavf_get_vf_config 182 * @adapter: private adapter structure 183 * 184 * Get VF configuration from PF and populate hw structure. Must be called after 185 * admin queue is initialized. Busy waits until response is received from PF, 186 * with maximum timeout. Response from PF is returned in the buffer for further 187 * processing by the caller. 188 **/ 189 int iavf_get_vf_config(struct iavf_adapter *adapter) 190 { 191 struct iavf_hw *hw = &adapter->hw; 192 struct iavf_arq_event_info event; 193 enum virtchnl_ops op; 194 enum iavf_status err; 195 u16 len; 196 197 len = sizeof(struct virtchnl_vf_resource) + 198 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource); 199 event.buf_len = len; 200 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 201 if (!event.msg_buf) { 202 err = -ENOMEM; 203 goto out; 204 } 205 206 while (1) { 207 /* When the AQ is empty, iavf_clean_arq_element will return 208 * nonzero and this loop will terminate. 209 */ 210 err = iavf_clean_arq_element(hw, &event, NULL); 211 if (err) 212 goto out_alloc; 213 op = 214 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); 215 if (op == VIRTCHNL_OP_GET_VF_RESOURCES) 216 break; 217 } 218 219 err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low); 220 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); 221 222 /* some PFs send more queues than we should have so validate that 223 * we aren't getting too many queues 224 */ 225 if (!err) 226 iavf_validate_num_queues(adapter); 227 iavf_vf_parse_hw_config(hw, adapter->vf_res); 228 out_alloc: 229 kfree(event.msg_buf); 230 out: 231 return err; 232 } 233 234 /** 235 * iavf_configure_queues 236 * @adapter: adapter structure 237 * 238 * Request that the PF set up our (previously allocated) queues. 239 **/ 240 void iavf_configure_queues(struct iavf_adapter *adapter) 241 { 242 struct virtchnl_vsi_queue_config_info *vqci; 243 struct virtchnl_queue_pair_info *vqpi; 244 int pairs = adapter->num_active_queues; 245 int i, max_frame = IAVF_MAX_RXBUFFER; 246 size_t len; 247 248 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 249 /* bail because we already have a command pending */ 250 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", 251 adapter->current_op); 252 return; 253 } 254 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES; 255 len = struct_size(vqci, qpair, pairs); 256 vqci = kzalloc(len, GFP_KERNEL); 257 if (!vqci) 258 return; 259 260 /* Limit maximum frame size when jumbo frames is not enabled */ 261 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) && 262 (adapter->netdev->mtu <= ETH_DATA_LEN)) 263 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN; 264 265 vqci->vsi_id = adapter->vsi_res->vsi_id; 266 vqci->num_queue_pairs = pairs; 267 vqpi = vqci->qpair; 268 /* Size check is not needed here - HW max is 16 queue pairs, and we 269 * can fit info for 31 of them into the AQ buffer before it overflows. 270 */ 271 for (i = 0; i < pairs; i++) { 272 vqpi->txq.vsi_id = vqci->vsi_id; 273 vqpi->txq.queue_id = i; 274 vqpi->txq.ring_len = adapter->tx_rings[i].count; 275 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma; 276 vqpi->rxq.vsi_id = vqci->vsi_id; 277 vqpi->rxq.queue_id = i; 278 vqpi->rxq.ring_len = adapter->rx_rings[i].count; 279 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; 280 vqpi->rxq.max_pkt_size = max_frame; 281 vqpi->rxq.databuffer_size = 282 ALIGN(adapter->rx_rings[i].rx_buf_len, 283 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT)); 284 vqpi++; 285 } 286 287 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES; 288 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES, 289 (u8 *)vqci, len); 290 kfree(vqci); 291 } 292 293 /** 294 * iavf_enable_queues 295 * @adapter: adapter structure 296 * 297 * Request that the PF enable all of our queues. 298 **/ 299 void iavf_enable_queues(struct iavf_adapter *adapter) 300 { 301 struct virtchnl_queue_select vqs; 302 303 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 304 /* bail because we already have a command pending */ 305 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", 306 adapter->current_op); 307 return; 308 } 309 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES; 310 vqs.vsi_id = adapter->vsi_res->vsi_id; 311 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 312 vqs.rx_queues = vqs.tx_queues; 313 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES; 314 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES, 315 (u8 *)&vqs, sizeof(vqs)); 316 } 317 318 /** 319 * iavf_disable_queues 320 * @adapter: adapter structure 321 * 322 * Request that the PF disable all of our queues. 323 **/ 324 void iavf_disable_queues(struct iavf_adapter *adapter) 325 { 326 struct virtchnl_queue_select vqs; 327 328 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 329 /* bail because we already have a command pending */ 330 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", 331 adapter->current_op); 332 return; 333 } 334 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES; 335 vqs.vsi_id = adapter->vsi_res->vsi_id; 336 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 337 vqs.rx_queues = vqs.tx_queues; 338 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES; 339 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES, 340 (u8 *)&vqs, sizeof(vqs)); 341 } 342 343 /** 344 * iavf_map_queues 345 * @adapter: adapter structure 346 * 347 * Request that the PF map queues to interrupt vectors. Misc causes, including 348 * admin queue, are always mapped to vector 0. 349 **/ 350 void iavf_map_queues(struct iavf_adapter *adapter) 351 { 352 struct virtchnl_irq_map_info *vimi; 353 struct virtchnl_vector_map *vecmap; 354 struct iavf_q_vector *q_vector; 355 int v_idx, q_vectors; 356 size_t len; 357 358 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 359 /* bail because we already have a command pending */ 360 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", 361 adapter->current_op); 362 return; 363 } 364 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP; 365 366 q_vectors = adapter->num_msix_vectors - NONQ_VECS; 367 368 len = struct_size(vimi, vecmap, adapter->num_msix_vectors); 369 vimi = kzalloc(len, GFP_KERNEL); 370 if (!vimi) 371 return; 372 373 vimi->num_vectors = adapter->num_msix_vectors; 374 /* Queue vectors first */ 375 for (v_idx = 0; v_idx < q_vectors; v_idx++) { 376 q_vector = &adapter->q_vectors[v_idx]; 377 vecmap = &vimi->vecmap[v_idx]; 378 379 vecmap->vsi_id = adapter->vsi_res->vsi_id; 380 vecmap->vector_id = v_idx + NONQ_VECS; 381 vecmap->txq_map = q_vector->ring_mask; 382 vecmap->rxq_map = q_vector->ring_mask; 383 vecmap->rxitr_idx = IAVF_RX_ITR; 384 vecmap->txitr_idx = IAVF_TX_ITR; 385 } 386 /* Misc vector last - this is only for AdminQ messages */ 387 vecmap = &vimi->vecmap[v_idx]; 388 vecmap->vsi_id = adapter->vsi_res->vsi_id; 389 vecmap->vector_id = 0; 390 vecmap->txq_map = 0; 391 vecmap->rxq_map = 0; 392 393 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS; 394 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP, 395 (u8 *)vimi, len); 396 kfree(vimi); 397 } 398 399 /** 400 * iavf_request_queues 401 * @adapter: adapter structure 402 * @num: number of requested queues 403 * 404 * We get a default number of queues from the PF. This enables us to request a 405 * different number. Returns 0 on success, negative on failure 406 **/ 407 int iavf_request_queues(struct iavf_adapter *adapter, int num) 408 { 409 struct virtchnl_vf_res_request vfres; 410 411 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 412 /* bail because we already have a command pending */ 413 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n", 414 adapter->current_op); 415 return -EBUSY; 416 } 417 418 vfres.num_queue_pairs = min_t(int, num, num_online_cpus()); 419 420 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES; 421 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 422 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES, 423 (u8 *)&vfres, sizeof(vfres)); 424 } 425 426 /** 427 * iavf_add_ether_addrs 428 * @adapter: adapter structure 429 * 430 * Request that the PF add one or more addresses to our filters. 431 **/ 432 void iavf_add_ether_addrs(struct iavf_adapter *adapter) 433 { 434 struct virtchnl_ether_addr_list *veal; 435 struct iavf_mac_filter *f; 436 int i = 0, count = 0; 437 bool more = false; 438 size_t len; 439 440 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 441 /* bail because we already have a command pending */ 442 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", 443 adapter->current_op); 444 return; 445 } 446 447 spin_lock_bh(&adapter->mac_vlan_list_lock); 448 449 list_for_each_entry(f, &adapter->mac_filter_list, list) { 450 if (f->add) 451 count++; 452 } 453 if (!count) { 454 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 455 spin_unlock_bh(&adapter->mac_vlan_list_lock); 456 return; 457 } 458 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR; 459 460 len = struct_size(veal, list, count); 461 if (len > IAVF_MAX_AQ_BUF_SIZE) { 462 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n"); 463 count = (IAVF_MAX_AQ_BUF_SIZE - 464 sizeof(struct virtchnl_ether_addr_list)) / 465 sizeof(struct virtchnl_ether_addr); 466 len = struct_size(veal, list, count); 467 more = true; 468 } 469 470 veal = kzalloc(len, GFP_ATOMIC); 471 if (!veal) { 472 spin_unlock_bh(&adapter->mac_vlan_list_lock); 473 return; 474 } 475 476 veal->vsi_id = adapter->vsi_res->vsi_id; 477 veal->num_elements = count; 478 list_for_each_entry(f, &adapter->mac_filter_list, list) { 479 if (f->add) { 480 ether_addr_copy(veal->list[i].addr, f->macaddr); 481 i++; 482 f->add = false; 483 if (i == count) 484 break; 485 } 486 } 487 if (!more) 488 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 489 490 spin_unlock_bh(&adapter->mac_vlan_list_lock); 491 492 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len); 493 kfree(veal); 494 } 495 496 /** 497 * iavf_del_ether_addrs 498 * @adapter: adapter structure 499 * 500 * Request that the PF remove one or more addresses from our filters. 501 **/ 502 void iavf_del_ether_addrs(struct iavf_adapter *adapter) 503 { 504 struct virtchnl_ether_addr_list *veal; 505 struct iavf_mac_filter *f, *ftmp; 506 int i = 0, count = 0; 507 bool more = false; 508 size_t len; 509 510 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 511 /* bail because we already have a command pending */ 512 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", 513 adapter->current_op); 514 return; 515 } 516 517 spin_lock_bh(&adapter->mac_vlan_list_lock); 518 519 list_for_each_entry(f, &adapter->mac_filter_list, list) { 520 if (f->remove) 521 count++; 522 } 523 if (!count) { 524 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 525 spin_unlock_bh(&adapter->mac_vlan_list_lock); 526 return; 527 } 528 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR; 529 530 len = struct_size(veal, list, count); 531 if (len > IAVF_MAX_AQ_BUF_SIZE) { 532 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n"); 533 count = (IAVF_MAX_AQ_BUF_SIZE - 534 sizeof(struct virtchnl_ether_addr_list)) / 535 sizeof(struct virtchnl_ether_addr); 536 len = struct_size(veal, list, count); 537 more = true; 538 } 539 veal = kzalloc(len, GFP_ATOMIC); 540 if (!veal) { 541 spin_unlock_bh(&adapter->mac_vlan_list_lock); 542 return; 543 } 544 545 veal->vsi_id = adapter->vsi_res->vsi_id; 546 veal->num_elements = count; 547 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 548 if (f->remove) { 549 ether_addr_copy(veal->list[i].addr, f->macaddr); 550 i++; 551 list_del(&f->list); 552 kfree(f); 553 if (i == count) 554 break; 555 } 556 } 557 if (!more) 558 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 559 560 spin_unlock_bh(&adapter->mac_vlan_list_lock); 561 562 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len); 563 kfree(veal); 564 } 565 566 /** 567 * iavf_add_vlans 568 * @adapter: adapter structure 569 * 570 * Request that the PF add one or more VLAN filters to our VSI. 571 **/ 572 void iavf_add_vlans(struct iavf_adapter *adapter) 573 { 574 struct virtchnl_vlan_filter_list *vvfl; 575 int len, i = 0, count = 0; 576 struct iavf_vlan_filter *f; 577 bool more = false; 578 579 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 580 /* bail because we already have a command pending */ 581 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", 582 adapter->current_op); 583 return; 584 } 585 586 spin_lock_bh(&adapter->mac_vlan_list_lock); 587 588 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 589 if (f->add) 590 count++; 591 } 592 if (!count) { 593 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 594 spin_unlock_bh(&adapter->mac_vlan_list_lock); 595 return; 596 } 597 adapter->current_op = VIRTCHNL_OP_ADD_VLAN; 598 599 len = sizeof(struct virtchnl_vlan_filter_list) + 600 (count * sizeof(u16)); 601 if (len > IAVF_MAX_AQ_BUF_SIZE) { 602 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 603 count = (IAVF_MAX_AQ_BUF_SIZE - 604 sizeof(struct virtchnl_vlan_filter_list)) / 605 sizeof(u16); 606 len = sizeof(struct virtchnl_vlan_filter_list) + 607 (count * sizeof(u16)); 608 more = true; 609 } 610 vvfl = kzalloc(len, GFP_ATOMIC); 611 if (!vvfl) { 612 spin_unlock_bh(&adapter->mac_vlan_list_lock); 613 return; 614 } 615 616 vvfl->vsi_id = adapter->vsi_res->vsi_id; 617 vvfl->num_elements = count; 618 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 619 if (f->add) { 620 vvfl->vlan_id[i] = f->vlan; 621 i++; 622 f->add = false; 623 if (i == count) 624 break; 625 } 626 } 627 if (!more) 628 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 629 630 spin_unlock_bh(&adapter->mac_vlan_list_lock); 631 632 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); 633 kfree(vvfl); 634 } 635 636 /** 637 * iavf_del_vlans 638 * @adapter: adapter structure 639 * 640 * Request that the PF remove one or more VLAN filters from our VSI. 641 **/ 642 void iavf_del_vlans(struct iavf_adapter *adapter) 643 { 644 struct virtchnl_vlan_filter_list *vvfl; 645 struct iavf_vlan_filter *f, *ftmp; 646 int len, i = 0, count = 0; 647 bool more = false; 648 649 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 650 /* bail because we already have a command pending */ 651 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", 652 adapter->current_op); 653 return; 654 } 655 656 spin_lock_bh(&adapter->mac_vlan_list_lock); 657 658 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 659 if (f->remove) 660 count++; 661 } 662 if (!count) { 663 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 664 spin_unlock_bh(&adapter->mac_vlan_list_lock); 665 return; 666 } 667 adapter->current_op = VIRTCHNL_OP_DEL_VLAN; 668 669 len = sizeof(struct virtchnl_vlan_filter_list) + 670 (count * sizeof(u16)); 671 if (len > IAVF_MAX_AQ_BUF_SIZE) { 672 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n"); 673 count = (IAVF_MAX_AQ_BUF_SIZE - 674 sizeof(struct virtchnl_vlan_filter_list)) / 675 sizeof(u16); 676 len = sizeof(struct virtchnl_vlan_filter_list) + 677 (count * sizeof(u16)); 678 more = true; 679 } 680 vvfl = kzalloc(len, GFP_ATOMIC); 681 if (!vvfl) { 682 spin_unlock_bh(&adapter->mac_vlan_list_lock); 683 return; 684 } 685 686 vvfl->vsi_id = adapter->vsi_res->vsi_id; 687 vvfl->num_elements = count; 688 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 689 if (f->remove) { 690 vvfl->vlan_id[i] = f->vlan; 691 i++; 692 list_del(&f->list); 693 kfree(f); 694 if (i == count) 695 break; 696 } 697 } 698 if (!more) 699 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 700 701 spin_unlock_bh(&adapter->mac_vlan_list_lock); 702 703 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); 704 kfree(vvfl); 705 } 706 707 /** 708 * iavf_set_promiscuous 709 * @adapter: adapter structure 710 * @flags: bitmask to control unicast/multicast promiscuous. 711 * 712 * Request that the PF enable promiscuous mode for our VSI. 713 **/ 714 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags) 715 { 716 struct virtchnl_promisc_info vpi; 717 int promisc_all; 718 719 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 720 /* bail because we already have a command pending */ 721 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", 722 adapter->current_op); 723 return; 724 } 725 726 promisc_all = FLAG_VF_UNICAST_PROMISC | 727 FLAG_VF_MULTICAST_PROMISC; 728 if ((flags & promisc_all) == promisc_all) { 729 adapter->flags |= IAVF_FLAG_PROMISC_ON; 730 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC; 731 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n"); 732 } 733 734 if (flags & FLAG_VF_MULTICAST_PROMISC) { 735 adapter->flags |= IAVF_FLAG_ALLMULTI_ON; 736 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI; 737 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n"); 738 } 739 740 if (!flags) { 741 adapter->flags &= ~(IAVF_FLAG_PROMISC_ON | 742 IAVF_FLAG_ALLMULTI_ON); 743 adapter->aq_required &= ~(IAVF_FLAG_AQ_RELEASE_PROMISC | 744 IAVF_FLAG_AQ_RELEASE_ALLMULTI); 745 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n"); 746 } 747 748 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; 749 vpi.vsi_id = adapter->vsi_res->vsi_id; 750 vpi.flags = flags; 751 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 752 (u8 *)&vpi, sizeof(vpi)); 753 } 754 755 /** 756 * iavf_request_stats 757 * @adapter: adapter structure 758 * 759 * Request VSI statistics from PF. 760 **/ 761 void iavf_request_stats(struct iavf_adapter *adapter) 762 { 763 struct virtchnl_queue_select vqs; 764 765 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 766 /* no error message, this isn't crucial */ 767 return; 768 } 769 adapter->current_op = VIRTCHNL_OP_GET_STATS; 770 vqs.vsi_id = adapter->vsi_res->vsi_id; 771 /* queue maps are ignored for this message - only the vsi is used */ 772 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs, 773 sizeof(vqs))) 774 /* if the request failed, don't lock out others */ 775 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 776 } 777 778 /** 779 * iavf_get_hena 780 * @adapter: adapter structure 781 * 782 * Request hash enable capabilities from PF 783 **/ 784 void iavf_get_hena(struct iavf_adapter *adapter) 785 { 786 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 787 /* bail because we already have a command pending */ 788 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n", 789 adapter->current_op); 790 return; 791 } 792 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS; 793 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA; 794 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0); 795 } 796 797 /** 798 * iavf_set_hena 799 * @adapter: adapter structure 800 * 801 * Request the PF to set our RSS hash capabilities 802 **/ 803 void iavf_set_hena(struct iavf_adapter *adapter) 804 { 805 struct virtchnl_rss_hena vrh; 806 807 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 808 /* bail because we already have a command pending */ 809 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n", 810 adapter->current_op); 811 return; 812 } 813 vrh.hena = adapter->hena; 814 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA; 815 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA; 816 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh, 817 sizeof(vrh)); 818 } 819 820 /** 821 * iavf_set_rss_key 822 * @adapter: adapter structure 823 * 824 * Request the PF to set our RSS hash key 825 **/ 826 void iavf_set_rss_key(struct iavf_adapter *adapter) 827 { 828 struct virtchnl_rss_key *vrk; 829 int len; 830 831 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 832 /* bail because we already have a command pending */ 833 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n", 834 adapter->current_op); 835 return; 836 } 837 len = sizeof(struct virtchnl_rss_key) + 838 (adapter->rss_key_size * sizeof(u8)) - 1; 839 vrk = kzalloc(len, GFP_KERNEL); 840 if (!vrk) 841 return; 842 vrk->vsi_id = adapter->vsi.id; 843 vrk->key_len = adapter->rss_key_size; 844 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size); 845 846 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY; 847 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY; 848 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len); 849 kfree(vrk); 850 } 851 852 /** 853 * iavf_set_rss_lut 854 * @adapter: adapter structure 855 * 856 * Request the PF to set our RSS lookup table 857 **/ 858 void iavf_set_rss_lut(struct iavf_adapter *adapter) 859 { 860 struct virtchnl_rss_lut *vrl; 861 int len; 862 863 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 864 /* bail because we already have a command pending */ 865 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n", 866 adapter->current_op); 867 return; 868 } 869 len = sizeof(struct virtchnl_rss_lut) + 870 (adapter->rss_lut_size * sizeof(u8)) - 1; 871 vrl = kzalloc(len, GFP_KERNEL); 872 if (!vrl) 873 return; 874 vrl->vsi_id = adapter->vsi.id; 875 vrl->lut_entries = adapter->rss_lut_size; 876 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size); 877 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT; 878 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT; 879 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len); 880 kfree(vrl); 881 } 882 883 /** 884 * iavf_enable_vlan_stripping 885 * @adapter: adapter structure 886 * 887 * Request VLAN header stripping to be enabled 888 **/ 889 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter) 890 { 891 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 892 /* bail because we already have a command pending */ 893 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n", 894 adapter->current_op); 895 return; 896 } 897 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING; 898 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; 899 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0); 900 } 901 902 /** 903 * iavf_disable_vlan_stripping 904 * @adapter: adapter structure 905 * 906 * Request VLAN header stripping to be disabled 907 **/ 908 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter) 909 { 910 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 911 /* bail because we already have a command pending */ 912 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n", 913 adapter->current_op); 914 return; 915 } 916 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING; 917 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; 918 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0); 919 } 920 921 /** 922 * iavf_print_link_message - print link up or down 923 * @adapter: adapter structure 924 * 925 * Log a message telling the world of our wonderous link status 926 */ 927 static void iavf_print_link_message(struct iavf_adapter *adapter) 928 { 929 struct net_device *netdev = adapter->netdev; 930 char *speed = "Unknown "; 931 932 if (!adapter->link_up) { 933 netdev_info(netdev, "NIC Link is Down\n"); 934 return; 935 } 936 937 switch (adapter->link_speed) { 938 case IAVF_LINK_SPEED_40GB: 939 speed = "40 G"; 940 break; 941 case IAVF_LINK_SPEED_25GB: 942 speed = "25 G"; 943 break; 944 case IAVF_LINK_SPEED_20GB: 945 speed = "20 G"; 946 break; 947 case IAVF_LINK_SPEED_10GB: 948 speed = "10 G"; 949 break; 950 case IAVF_LINK_SPEED_1GB: 951 speed = "1000 M"; 952 break; 953 case IAVF_LINK_SPEED_100MB: 954 speed = "100 M"; 955 break; 956 default: 957 break; 958 } 959 960 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed); 961 } 962 963 /** 964 * iavf_enable_channel 965 * @adapter: adapter structure 966 * 967 * Request that the PF enable channels as specified by 968 * the user via tc tool. 969 **/ 970 void iavf_enable_channels(struct iavf_adapter *adapter) 971 { 972 struct virtchnl_tc_info *vti = NULL; 973 size_t len; 974 int i; 975 976 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 977 /* bail because we already have a command pending */ 978 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 979 adapter->current_op); 980 return; 981 } 982 983 len = struct_size(vti, list, adapter->num_tc - 1); 984 vti = kzalloc(len, GFP_KERNEL); 985 if (!vti) 986 return; 987 vti->num_tc = adapter->num_tc; 988 for (i = 0; i < vti->num_tc; i++) { 989 vti->list[i].count = adapter->ch_config.ch_info[i].count; 990 vti->list[i].offset = adapter->ch_config.ch_info[i].offset; 991 vti->list[i].pad = 0; 992 vti->list[i].max_tx_rate = 993 adapter->ch_config.ch_info[i].max_tx_rate; 994 } 995 996 adapter->ch_config.state = __IAVF_TC_RUNNING; 997 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 998 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS; 999 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS; 1000 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len); 1001 kfree(vti); 1002 } 1003 1004 /** 1005 * iavf_disable_channel 1006 * @adapter: adapter structure 1007 * 1008 * Request that the PF disable channels that are configured 1009 **/ 1010 void iavf_disable_channels(struct iavf_adapter *adapter) 1011 { 1012 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1013 /* bail because we already have a command pending */ 1014 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 1015 adapter->current_op); 1016 return; 1017 } 1018 1019 adapter->ch_config.state = __IAVF_TC_INVALID; 1020 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 1021 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS; 1022 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS; 1023 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0); 1024 } 1025 1026 /** 1027 * iavf_print_cloud_filter 1028 * @adapter: adapter structure 1029 * @f: cloud filter to print 1030 * 1031 * Print the cloud filter 1032 **/ 1033 static void iavf_print_cloud_filter(struct iavf_adapter *adapter, 1034 struct virtchnl_filter *f) 1035 { 1036 switch (f->flow_type) { 1037 case VIRTCHNL_TCP_V4_FLOW: 1038 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n", 1039 &f->data.tcp_spec.dst_mac, 1040 &f->data.tcp_spec.src_mac, 1041 ntohs(f->data.tcp_spec.vlan_id), 1042 &f->data.tcp_spec.dst_ip[0], 1043 &f->data.tcp_spec.src_ip[0], 1044 ntohs(f->data.tcp_spec.dst_port), 1045 ntohs(f->data.tcp_spec.src_port)); 1046 break; 1047 case VIRTCHNL_TCP_V6_FLOW: 1048 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n", 1049 &f->data.tcp_spec.dst_mac, 1050 &f->data.tcp_spec.src_mac, 1051 ntohs(f->data.tcp_spec.vlan_id), 1052 &f->data.tcp_spec.dst_ip, 1053 &f->data.tcp_spec.src_ip, 1054 ntohs(f->data.tcp_spec.dst_port), 1055 ntohs(f->data.tcp_spec.src_port)); 1056 break; 1057 } 1058 } 1059 1060 /** 1061 * iavf_add_cloud_filter 1062 * @adapter: adapter structure 1063 * 1064 * Request that the PF add cloud filters as specified 1065 * by the user via tc tool. 1066 **/ 1067 void iavf_add_cloud_filter(struct iavf_adapter *adapter) 1068 { 1069 struct iavf_cloud_filter *cf; 1070 struct virtchnl_filter *f; 1071 int len = 0, count = 0; 1072 1073 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1074 /* bail because we already have a command pending */ 1075 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n", 1076 adapter->current_op); 1077 return; 1078 } 1079 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1080 if (cf->add) { 1081 count++; 1082 break; 1083 } 1084 } 1085 if (!count) { 1086 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER; 1087 return; 1088 } 1089 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER; 1090 1091 len = sizeof(struct virtchnl_filter); 1092 f = kzalloc(len, GFP_KERNEL); 1093 if (!f) 1094 return; 1095 1096 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1097 if (cf->add) { 1098 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1099 cf->add = false; 1100 cf->state = __IAVF_CF_ADD_PENDING; 1101 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER, 1102 (u8 *)f, len); 1103 } 1104 } 1105 kfree(f); 1106 } 1107 1108 /** 1109 * iavf_del_cloud_filter 1110 * @adapter: adapter structure 1111 * 1112 * Request that the PF delete cloud filters as specified 1113 * by the user via tc tool. 1114 **/ 1115 void iavf_del_cloud_filter(struct iavf_adapter *adapter) 1116 { 1117 struct iavf_cloud_filter *cf, *cftmp; 1118 struct virtchnl_filter *f; 1119 int len = 0, count = 0; 1120 1121 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1122 /* bail because we already have a command pending */ 1123 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n", 1124 adapter->current_op); 1125 return; 1126 } 1127 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1128 if (cf->del) { 1129 count++; 1130 break; 1131 } 1132 } 1133 if (!count) { 1134 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER; 1135 return; 1136 } 1137 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER; 1138 1139 len = sizeof(struct virtchnl_filter); 1140 f = kzalloc(len, GFP_KERNEL); 1141 if (!f) 1142 return; 1143 1144 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) { 1145 if (cf->del) { 1146 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1147 cf->del = false; 1148 cf->state = __IAVF_CF_DEL_PENDING; 1149 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER, 1150 (u8 *)f, len); 1151 } 1152 } 1153 kfree(f); 1154 } 1155 1156 /** 1157 * iavf_request_reset 1158 * @adapter: adapter structure 1159 * 1160 * Request that the PF reset this VF. No response is expected. 1161 **/ 1162 void iavf_request_reset(struct iavf_adapter *adapter) 1163 { 1164 /* Don't check CURRENT_OP - this is always higher priority */ 1165 iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0); 1166 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1167 } 1168 1169 /** 1170 * iavf_virtchnl_completion 1171 * @adapter: adapter structure 1172 * @v_opcode: opcode sent by PF 1173 * @v_retval: retval sent by PF 1174 * @msg: message sent by PF 1175 * @msglen: message length 1176 * 1177 * Asynchronous completion function for admin queue messages. Rather than busy 1178 * wait, we fire off our requests and assume that no errors will be returned. 1179 * This function handles the reply messages. 1180 **/ 1181 void iavf_virtchnl_completion(struct iavf_adapter *adapter, 1182 enum virtchnl_ops v_opcode, 1183 enum iavf_status v_retval, u8 *msg, u16 msglen) 1184 { 1185 struct net_device *netdev = adapter->netdev; 1186 1187 if (v_opcode == VIRTCHNL_OP_EVENT) { 1188 struct virtchnl_pf_event *vpe = 1189 (struct virtchnl_pf_event *)msg; 1190 bool link_up = vpe->event_data.link_event.link_status; 1191 1192 switch (vpe->event) { 1193 case VIRTCHNL_EVENT_LINK_CHANGE: 1194 adapter->link_speed = 1195 vpe->event_data.link_event.link_speed; 1196 1197 /* we've already got the right link status, bail */ 1198 if (adapter->link_up == link_up) 1199 break; 1200 1201 if (link_up) { 1202 /* If we get link up message and start queues 1203 * before our queues are configured it will 1204 * trigger a TX hang. In that case, just ignore 1205 * the link status message,we'll get another one 1206 * after we enable queues and actually prepared 1207 * to send traffic. 1208 */ 1209 if (adapter->state != __IAVF_RUNNING) 1210 break; 1211 1212 /* For ADq enabled VF, we reconfigure VSIs and 1213 * re-allocate queues. Hence wait till all 1214 * queues are enabled. 1215 */ 1216 if (adapter->flags & 1217 IAVF_FLAG_QUEUES_DISABLED) 1218 break; 1219 } 1220 1221 adapter->link_up = link_up; 1222 if (link_up) { 1223 netif_tx_start_all_queues(netdev); 1224 netif_carrier_on(netdev); 1225 } else { 1226 netif_tx_stop_all_queues(netdev); 1227 netif_carrier_off(netdev); 1228 } 1229 iavf_print_link_message(adapter); 1230 break; 1231 case VIRTCHNL_EVENT_RESET_IMPENDING: 1232 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n"); 1233 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) { 1234 adapter->flags |= IAVF_FLAG_RESET_PENDING; 1235 dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); 1236 queue_work(iavf_wq, &adapter->reset_task); 1237 } 1238 break; 1239 default: 1240 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", 1241 vpe->event); 1242 break; 1243 } 1244 return; 1245 } 1246 if (v_retval) { 1247 switch (v_opcode) { 1248 case VIRTCHNL_OP_ADD_VLAN: 1249 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", 1250 iavf_stat_str(&adapter->hw, v_retval)); 1251 break; 1252 case VIRTCHNL_OP_ADD_ETH_ADDR: 1253 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", 1254 iavf_stat_str(&adapter->hw, v_retval)); 1255 break; 1256 case VIRTCHNL_OP_DEL_VLAN: 1257 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", 1258 iavf_stat_str(&adapter->hw, v_retval)); 1259 break; 1260 case VIRTCHNL_OP_DEL_ETH_ADDR: 1261 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", 1262 iavf_stat_str(&adapter->hw, v_retval)); 1263 break; 1264 case VIRTCHNL_OP_ENABLE_CHANNELS: 1265 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n", 1266 iavf_stat_str(&adapter->hw, v_retval)); 1267 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1268 adapter->ch_config.state = __IAVF_TC_INVALID; 1269 netdev_reset_tc(netdev); 1270 netif_tx_start_all_queues(netdev); 1271 break; 1272 case VIRTCHNL_OP_DISABLE_CHANNELS: 1273 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n", 1274 iavf_stat_str(&adapter->hw, v_retval)); 1275 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1276 adapter->ch_config.state = __IAVF_TC_RUNNING; 1277 netif_tx_start_all_queues(netdev); 1278 break; 1279 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 1280 struct iavf_cloud_filter *cf, *cftmp; 1281 1282 list_for_each_entry_safe(cf, cftmp, 1283 &adapter->cloud_filter_list, 1284 list) { 1285 if (cf->state == __IAVF_CF_ADD_PENDING) { 1286 cf->state = __IAVF_CF_INVALID; 1287 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n", 1288 iavf_stat_str(&adapter->hw, 1289 v_retval)); 1290 iavf_print_cloud_filter(adapter, 1291 &cf->f); 1292 list_del(&cf->list); 1293 kfree(cf); 1294 adapter->num_cloud_filters--; 1295 } 1296 } 1297 } 1298 break; 1299 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 1300 struct iavf_cloud_filter *cf; 1301 1302 list_for_each_entry(cf, &adapter->cloud_filter_list, 1303 list) { 1304 if (cf->state == __IAVF_CF_DEL_PENDING) { 1305 cf->state = __IAVF_CF_ACTIVE; 1306 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n", 1307 iavf_stat_str(&adapter->hw, 1308 v_retval)); 1309 iavf_print_cloud_filter(adapter, 1310 &cf->f); 1311 } 1312 } 1313 } 1314 break; 1315 default: 1316 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", 1317 v_retval, iavf_stat_str(&adapter->hw, v_retval), 1318 v_opcode); 1319 } 1320 } 1321 switch (v_opcode) { 1322 case VIRTCHNL_OP_GET_STATS: { 1323 struct iavf_eth_stats *stats = 1324 (struct iavf_eth_stats *)msg; 1325 netdev->stats.rx_packets = stats->rx_unicast + 1326 stats->rx_multicast + 1327 stats->rx_broadcast; 1328 netdev->stats.tx_packets = stats->tx_unicast + 1329 stats->tx_multicast + 1330 stats->tx_broadcast; 1331 netdev->stats.rx_bytes = stats->rx_bytes; 1332 netdev->stats.tx_bytes = stats->tx_bytes; 1333 netdev->stats.tx_errors = stats->tx_errors; 1334 netdev->stats.rx_dropped = stats->rx_discards; 1335 netdev->stats.tx_dropped = stats->tx_discards; 1336 adapter->current_stats = *stats; 1337 } 1338 break; 1339 case VIRTCHNL_OP_GET_VF_RESOURCES: { 1340 u16 len = sizeof(struct virtchnl_vf_resource) + 1341 IAVF_MAX_VF_VSI * 1342 sizeof(struct virtchnl_vsi_resource); 1343 memcpy(adapter->vf_res, msg, min(msglen, len)); 1344 iavf_validate_num_queues(adapter); 1345 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res); 1346 if (is_zero_ether_addr(adapter->hw.mac.addr)) { 1347 /* restore current mac address */ 1348 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 1349 } else { 1350 /* refresh current mac address if changed */ 1351 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); 1352 ether_addr_copy(netdev->perm_addr, 1353 adapter->hw.mac.addr); 1354 } 1355 iavf_process_config(adapter); 1356 } 1357 break; 1358 case VIRTCHNL_OP_ENABLE_QUEUES: 1359 /* enable transmits */ 1360 iavf_irq_enable(adapter, true); 1361 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED; 1362 break; 1363 case VIRTCHNL_OP_DISABLE_QUEUES: 1364 iavf_free_all_tx_resources(adapter); 1365 iavf_free_all_rx_resources(adapter); 1366 if (adapter->state == __IAVF_DOWN_PENDING) { 1367 adapter->state = __IAVF_DOWN; 1368 wake_up(&adapter->down_waitqueue); 1369 } 1370 break; 1371 case VIRTCHNL_OP_VERSION: 1372 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1373 /* Don't display an error if we get these out of sequence. 1374 * If the firmware needed to get kicked, we'll get these and 1375 * it's no problem. 1376 */ 1377 if (v_opcode != adapter->current_op) 1378 return; 1379 break; 1380 case VIRTCHNL_OP_IWARP: 1381 /* Gobble zero-length replies from the PF. They indicate that 1382 * a previous message was received OK, and the client doesn't 1383 * care about that. 1384 */ 1385 if (msglen && CLIENT_ENABLED(adapter)) 1386 iavf_notify_client_message(&adapter->vsi, msg, msglen); 1387 break; 1388 1389 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 1390 adapter->client_pending &= 1391 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP)); 1392 break; 1393 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: { 1394 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg; 1395 1396 if (msglen == sizeof(*vrh)) 1397 adapter->hena = vrh->hena; 1398 else 1399 dev_warn(&adapter->pdev->dev, 1400 "Invalid message %d from PF\n", v_opcode); 1401 } 1402 break; 1403 case VIRTCHNL_OP_REQUEST_QUEUES: { 1404 struct virtchnl_vf_res_request *vfres = 1405 (struct virtchnl_vf_res_request *)msg; 1406 1407 if (vfres->num_queue_pairs != adapter->num_req_queues) { 1408 dev_info(&adapter->pdev->dev, 1409 "Requested %d queues, PF can support %d\n", 1410 adapter->num_req_queues, 1411 vfres->num_queue_pairs); 1412 adapter->num_req_queues = 0; 1413 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1414 } 1415 } 1416 break; 1417 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 1418 struct iavf_cloud_filter *cf; 1419 1420 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1421 if (cf->state == __IAVF_CF_ADD_PENDING) 1422 cf->state = __IAVF_CF_ACTIVE; 1423 } 1424 } 1425 break; 1426 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 1427 struct iavf_cloud_filter *cf, *cftmp; 1428 1429 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, 1430 list) { 1431 if (cf->state == __IAVF_CF_DEL_PENDING) { 1432 cf->state = __IAVF_CF_INVALID; 1433 list_del(&cf->list); 1434 kfree(cf); 1435 adapter->num_cloud_filters--; 1436 } 1437 } 1438 } 1439 break; 1440 default: 1441 if (adapter->current_op && (v_opcode != adapter->current_op)) 1442 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", 1443 adapter->current_op, v_opcode); 1444 break; 1445 } /* switch v_opcode */ 1446 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1447 } 1448