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 VIRTCHNL_VF_OFFLOAD_USO | 144 VIRTCHNL_VF_OFFLOAD_FDIR_PF | 145 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF | 146 VIRTCHNL_VF_CAP_ADV_LINK_SPEED; 147 148 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES; 149 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG; 150 if (PF_IS_V11(adapter)) 151 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 152 (u8 *)&caps, sizeof(caps)); 153 else 154 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 155 NULL, 0); 156 } 157 158 /** 159 * iavf_validate_num_queues 160 * @adapter: adapter structure 161 * 162 * Validate that the number of queues the PF has sent in 163 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle. 164 **/ 165 static void iavf_validate_num_queues(struct iavf_adapter *adapter) 166 { 167 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) { 168 struct virtchnl_vsi_resource *vsi_res; 169 int i; 170 171 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n", 172 adapter->vf_res->num_queue_pairs, 173 IAVF_MAX_REQ_QUEUES); 174 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n", 175 IAVF_MAX_REQ_QUEUES); 176 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 177 for (i = 0; i < adapter->vf_res->num_vsis; i++) { 178 vsi_res = &adapter->vf_res->vsi_res[i]; 179 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 180 } 181 } 182 } 183 184 /** 185 * iavf_get_vf_config 186 * @adapter: private adapter structure 187 * 188 * Get VF configuration from PF and populate hw structure. Must be called after 189 * admin queue is initialized. Busy waits until response is received from PF, 190 * with maximum timeout. Response from PF is returned in the buffer for further 191 * processing by the caller. 192 **/ 193 int iavf_get_vf_config(struct iavf_adapter *adapter) 194 { 195 struct iavf_hw *hw = &adapter->hw; 196 struct iavf_arq_event_info event; 197 enum virtchnl_ops op; 198 enum iavf_status err; 199 u16 len; 200 201 len = sizeof(struct virtchnl_vf_resource) + 202 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource); 203 event.buf_len = len; 204 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 205 if (!event.msg_buf) { 206 err = -ENOMEM; 207 goto out; 208 } 209 210 while (1) { 211 /* When the AQ is empty, iavf_clean_arq_element will return 212 * nonzero and this loop will terminate. 213 */ 214 err = iavf_clean_arq_element(hw, &event, NULL); 215 if (err) 216 goto out_alloc; 217 op = 218 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); 219 if (op == VIRTCHNL_OP_GET_VF_RESOURCES) 220 break; 221 } 222 223 err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low); 224 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); 225 226 /* some PFs send more queues than we should have so validate that 227 * we aren't getting too many queues 228 */ 229 if (!err) 230 iavf_validate_num_queues(adapter); 231 iavf_vf_parse_hw_config(hw, adapter->vf_res); 232 out_alloc: 233 kfree(event.msg_buf); 234 out: 235 return err; 236 } 237 238 /** 239 * iavf_configure_queues 240 * @adapter: adapter structure 241 * 242 * Request that the PF set up our (previously allocated) queues. 243 **/ 244 void iavf_configure_queues(struct iavf_adapter *adapter) 245 { 246 struct virtchnl_vsi_queue_config_info *vqci; 247 struct virtchnl_queue_pair_info *vqpi; 248 int pairs = adapter->num_active_queues; 249 int i, max_frame = IAVF_MAX_RXBUFFER; 250 size_t len; 251 252 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 253 /* bail because we already have a command pending */ 254 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", 255 adapter->current_op); 256 return; 257 } 258 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES; 259 len = struct_size(vqci, qpair, pairs); 260 vqci = kzalloc(len, GFP_KERNEL); 261 if (!vqci) 262 return; 263 264 /* Limit maximum frame size when jumbo frames is not enabled */ 265 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) && 266 (adapter->netdev->mtu <= ETH_DATA_LEN)) 267 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN; 268 269 vqci->vsi_id = adapter->vsi_res->vsi_id; 270 vqci->num_queue_pairs = pairs; 271 vqpi = vqci->qpair; 272 /* Size check is not needed here - HW max is 16 queue pairs, and we 273 * can fit info for 31 of them into the AQ buffer before it overflows. 274 */ 275 for (i = 0; i < pairs; i++) { 276 vqpi->txq.vsi_id = vqci->vsi_id; 277 vqpi->txq.queue_id = i; 278 vqpi->txq.ring_len = adapter->tx_rings[i].count; 279 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma; 280 vqpi->rxq.vsi_id = vqci->vsi_id; 281 vqpi->rxq.queue_id = i; 282 vqpi->rxq.ring_len = adapter->rx_rings[i].count; 283 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; 284 vqpi->rxq.max_pkt_size = max_frame; 285 vqpi->rxq.databuffer_size = 286 ALIGN(adapter->rx_rings[i].rx_buf_len, 287 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT)); 288 vqpi++; 289 } 290 291 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES; 292 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES, 293 (u8 *)vqci, len); 294 kfree(vqci); 295 } 296 297 /** 298 * iavf_enable_queues 299 * @adapter: adapter structure 300 * 301 * Request that the PF enable all of our queues. 302 **/ 303 void iavf_enable_queues(struct iavf_adapter *adapter) 304 { 305 struct virtchnl_queue_select vqs; 306 307 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 308 /* bail because we already have a command pending */ 309 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", 310 adapter->current_op); 311 return; 312 } 313 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES; 314 vqs.vsi_id = adapter->vsi_res->vsi_id; 315 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 316 vqs.rx_queues = vqs.tx_queues; 317 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES; 318 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES, 319 (u8 *)&vqs, sizeof(vqs)); 320 } 321 322 /** 323 * iavf_disable_queues 324 * @adapter: adapter structure 325 * 326 * Request that the PF disable all of our queues. 327 **/ 328 void iavf_disable_queues(struct iavf_adapter *adapter) 329 { 330 struct virtchnl_queue_select vqs; 331 332 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 333 /* bail because we already have a command pending */ 334 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", 335 adapter->current_op); 336 return; 337 } 338 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES; 339 vqs.vsi_id = adapter->vsi_res->vsi_id; 340 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 341 vqs.rx_queues = vqs.tx_queues; 342 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES; 343 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES, 344 (u8 *)&vqs, sizeof(vqs)); 345 } 346 347 /** 348 * iavf_map_queues 349 * @adapter: adapter structure 350 * 351 * Request that the PF map queues to interrupt vectors. Misc causes, including 352 * admin queue, are always mapped to vector 0. 353 **/ 354 void iavf_map_queues(struct iavf_adapter *adapter) 355 { 356 struct virtchnl_irq_map_info *vimi; 357 struct virtchnl_vector_map *vecmap; 358 struct iavf_q_vector *q_vector; 359 int v_idx, q_vectors; 360 size_t len; 361 362 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 363 /* bail because we already have a command pending */ 364 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", 365 adapter->current_op); 366 return; 367 } 368 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP; 369 370 q_vectors = adapter->num_msix_vectors - NONQ_VECS; 371 372 len = struct_size(vimi, vecmap, adapter->num_msix_vectors); 373 vimi = kzalloc(len, GFP_KERNEL); 374 if (!vimi) 375 return; 376 377 vimi->num_vectors = adapter->num_msix_vectors; 378 /* Queue vectors first */ 379 for (v_idx = 0; v_idx < q_vectors; v_idx++) { 380 q_vector = &adapter->q_vectors[v_idx]; 381 vecmap = &vimi->vecmap[v_idx]; 382 383 vecmap->vsi_id = adapter->vsi_res->vsi_id; 384 vecmap->vector_id = v_idx + NONQ_VECS; 385 vecmap->txq_map = q_vector->ring_mask; 386 vecmap->rxq_map = q_vector->ring_mask; 387 vecmap->rxitr_idx = IAVF_RX_ITR; 388 vecmap->txitr_idx = IAVF_TX_ITR; 389 } 390 /* Misc vector last - this is only for AdminQ messages */ 391 vecmap = &vimi->vecmap[v_idx]; 392 vecmap->vsi_id = adapter->vsi_res->vsi_id; 393 vecmap->vector_id = 0; 394 vecmap->txq_map = 0; 395 vecmap->rxq_map = 0; 396 397 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS; 398 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP, 399 (u8 *)vimi, len); 400 kfree(vimi); 401 } 402 403 /** 404 * iavf_add_ether_addrs 405 * @adapter: adapter structure 406 * 407 * Request that the PF add one or more addresses to our filters. 408 **/ 409 void iavf_add_ether_addrs(struct iavf_adapter *adapter) 410 { 411 struct virtchnl_ether_addr_list *veal; 412 struct iavf_mac_filter *f; 413 int i = 0, count = 0; 414 bool more = false; 415 size_t len; 416 417 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 418 /* bail because we already have a command pending */ 419 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", 420 adapter->current_op); 421 return; 422 } 423 424 spin_lock_bh(&adapter->mac_vlan_list_lock); 425 426 list_for_each_entry(f, &adapter->mac_filter_list, list) { 427 if (f->add) 428 count++; 429 } 430 if (!count) { 431 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 432 spin_unlock_bh(&adapter->mac_vlan_list_lock); 433 return; 434 } 435 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR; 436 437 len = struct_size(veal, list, count); 438 if (len > IAVF_MAX_AQ_BUF_SIZE) { 439 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n"); 440 count = (IAVF_MAX_AQ_BUF_SIZE - 441 sizeof(struct virtchnl_ether_addr_list)) / 442 sizeof(struct virtchnl_ether_addr); 443 len = struct_size(veal, list, count); 444 more = true; 445 } 446 447 veal = kzalloc(len, GFP_ATOMIC); 448 if (!veal) { 449 spin_unlock_bh(&adapter->mac_vlan_list_lock); 450 return; 451 } 452 453 veal->vsi_id = adapter->vsi_res->vsi_id; 454 veal->num_elements = count; 455 list_for_each_entry(f, &adapter->mac_filter_list, list) { 456 if (f->add) { 457 ether_addr_copy(veal->list[i].addr, f->macaddr); 458 i++; 459 f->add = false; 460 if (i == count) 461 break; 462 } 463 } 464 if (!more) 465 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 466 467 spin_unlock_bh(&adapter->mac_vlan_list_lock); 468 469 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len); 470 kfree(veal); 471 } 472 473 /** 474 * iavf_del_ether_addrs 475 * @adapter: adapter structure 476 * 477 * Request that the PF remove one or more addresses from our filters. 478 **/ 479 void iavf_del_ether_addrs(struct iavf_adapter *adapter) 480 { 481 struct virtchnl_ether_addr_list *veal; 482 struct iavf_mac_filter *f, *ftmp; 483 int i = 0, count = 0; 484 bool more = false; 485 size_t len; 486 487 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 488 /* bail because we already have a command pending */ 489 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", 490 adapter->current_op); 491 return; 492 } 493 494 spin_lock_bh(&adapter->mac_vlan_list_lock); 495 496 list_for_each_entry(f, &adapter->mac_filter_list, list) { 497 if (f->remove) 498 count++; 499 } 500 if (!count) { 501 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 502 spin_unlock_bh(&adapter->mac_vlan_list_lock); 503 return; 504 } 505 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR; 506 507 len = struct_size(veal, list, count); 508 if (len > IAVF_MAX_AQ_BUF_SIZE) { 509 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n"); 510 count = (IAVF_MAX_AQ_BUF_SIZE - 511 sizeof(struct virtchnl_ether_addr_list)) / 512 sizeof(struct virtchnl_ether_addr); 513 len = struct_size(veal, list, count); 514 more = true; 515 } 516 veal = kzalloc(len, GFP_ATOMIC); 517 if (!veal) { 518 spin_unlock_bh(&adapter->mac_vlan_list_lock); 519 return; 520 } 521 522 veal->vsi_id = adapter->vsi_res->vsi_id; 523 veal->num_elements = count; 524 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 525 if (f->remove) { 526 ether_addr_copy(veal->list[i].addr, f->macaddr); 527 i++; 528 list_del(&f->list); 529 kfree(f); 530 if (i == count) 531 break; 532 } 533 } 534 if (!more) 535 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 536 537 spin_unlock_bh(&adapter->mac_vlan_list_lock); 538 539 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len); 540 kfree(veal); 541 } 542 543 /** 544 * iavf_add_vlans 545 * @adapter: adapter structure 546 * 547 * Request that the PF add one or more VLAN filters to our VSI. 548 **/ 549 void iavf_add_vlans(struct iavf_adapter *adapter) 550 { 551 struct virtchnl_vlan_filter_list *vvfl; 552 int len, i = 0, count = 0; 553 struct iavf_vlan_filter *f; 554 bool more = false; 555 556 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 557 /* bail because we already have a command pending */ 558 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", 559 adapter->current_op); 560 return; 561 } 562 563 spin_lock_bh(&adapter->mac_vlan_list_lock); 564 565 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 566 if (f->add) 567 count++; 568 } 569 if (!count) { 570 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 571 spin_unlock_bh(&adapter->mac_vlan_list_lock); 572 return; 573 } 574 adapter->current_op = VIRTCHNL_OP_ADD_VLAN; 575 576 len = sizeof(struct virtchnl_vlan_filter_list) + 577 (count * sizeof(u16)); 578 if (len > IAVF_MAX_AQ_BUF_SIZE) { 579 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 580 count = (IAVF_MAX_AQ_BUF_SIZE - 581 sizeof(struct virtchnl_vlan_filter_list)) / 582 sizeof(u16); 583 len = sizeof(struct virtchnl_vlan_filter_list) + 584 (count * sizeof(u16)); 585 more = true; 586 } 587 vvfl = kzalloc(len, GFP_ATOMIC); 588 if (!vvfl) { 589 spin_unlock_bh(&adapter->mac_vlan_list_lock); 590 return; 591 } 592 593 vvfl->vsi_id = adapter->vsi_res->vsi_id; 594 vvfl->num_elements = count; 595 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 596 if (f->add) { 597 vvfl->vlan_id[i] = f->vlan; 598 i++; 599 f->add = false; 600 if (i == count) 601 break; 602 } 603 } 604 if (!more) 605 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 606 607 spin_unlock_bh(&adapter->mac_vlan_list_lock); 608 609 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); 610 kfree(vvfl); 611 } 612 613 /** 614 * iavf_del_vlans 615 * @adapter: adapter structure 616 * 617 * Request that the PF remove one or more VLAN filters from our VSI. 618 **/ 619 void iavf_del_vlans(struct iavf_adapter *adapter) 620 { 621 struct virtchnl_vlan_filter_list *vvfl; 622 struct iavf_vlan_filter *f, *ftmp; 623 int len, i = 0, count = 0; 624 bool more = false; 625 626 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 627 /* bail because we already have a command pending */ 628 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", 629 adapter->current_op); 630 return; 631 } 632 633 spin_lock_bh(&adapter->mac_vlan_list_lock); 634 635 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 636 if (f->remove) 637 count++; 638 } 639 if (!count) { 640 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 641 spin_unlock_bh(&adapter->mac_vlan_list_lock); 642 return; 643 } 644 adapter->current_op = VIRTCHNL_OP_DEL_VLAN; 645 646 len = sizeof(struct virtchnl_vlan_filter_list) + 647 (count * sizeof(u16)); 648 if (len > IAVF_MAX_AQ_BUF_SIZE) { 649 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n"); 650 count = (IAVF_MAX_AQ_BUF_SIZE - 651 sizeof(struct virtchnl_vlan_filter_list)) / 652 sizeof(u16); 653 len = sizeof(struct virtchnl_vlan_filter_list) + 654 (count * sizeof(u16)); 655 more = true; 656 } 657 vvfl = kzalloc(len, GFP_ATOMIC); 658 if (!vvfl) { 659 spin_unlock_bh(&adapter->mac_vlan_list_lock); 660 return; 661 } 662 663 vvfl->vsi_id = adapter->vsi_res->vsi_id; 664 vvfl->num_elements = count; 665 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 666 if (f->remove) { 667 vvfl->vlan_id[i] = f->vlan; 668 i++; 669 list_del(&f->list); 670 kfree(f); 671 if (i == count) 672 break; 673 } 674 } 675 if (!more) 676 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 677 678 spin_unlock_bh(&adapter->mac_vlan_list_lock); 679 680 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); 681 kfree(vvfl); 682 } 683 684 /** 685 * iavf_set_promiscuous 686 * @adapter: adapter structure 687 * @flags: bitmask to control unicast/multicast promiscuous. 688 * 689 * Request that the PF enable promiscuous mode for our VSI. 690 **/ 691 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags) 692 { 693 struct virtchnl_promisc_info vpi; 694 int promisc_all; 695 696 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 697 /* bail because we already have a command pending */ 698 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", 699 adapter->current_op); 700 return; 701 } 702 703 promisc_all = FLAG_VF_UNICAST_PROMISC | 704 FLAG_VF_MULTICAST_PROMISC; 705 if ((flags & promisc_all) == promisc_all) { 706 adapter->flags |= IAVF_FLAG_PROMISC_ON; 707 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC; 708 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n"); 709 } 710 711 if (flags & FLAG_VF_MULTICAST_PROMISC) { 712 adapter->flags |= IAVF_FLAG_ALLMULTI_ON; 713 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI; 714 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n"); 715 } 716 717 if (!flags) { 718 adapter->flags &= ~(IAVF_FLAG_PROMISC_ON | 719 IAVF_FLAG_ALLMULTI_ON); 720 adapter->aq_required &= ~(IAVF_FLAG_AQ_RELEASE_PROMISC | 721 IAVF_FLAG_AQ_RELEASE_ALLMULTI); 722 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n"); 723 } 724 725 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; 726 vpi.vsi_id = adapter->vsi_res->vsi_id; 727 vpi.flags = flags; 728 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 729 (u8 *)&vpi, sizeof(vpi)); 730 } 731 732 /** 733 * iavf_request_stats 734 * @adapter: adapter structure 735 * 736 * Request VSI statistics from PF. 737 **/ 738 void iavf_request_stats(struct iavf_adapter *adapter) 739 { 740 struct virtchnl_queue_select vqs; 741 742 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 743 /* no error message, this isn't crucial */ 744 return; 745 } 746 adapter->current_op = VIRTCHNL_OP_GET_STATS; 747 vqs.vsi_id = adapter->vsi_res->vsi_id; 748 /* queue maps are ignored for this message - only the vsi is used */ 749 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs, 750 sizeof(vqs))) 751 /* if the request failed, don't lock out others */ 752 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 753 } 754 755 /** 756 * iavf_get_hena 757 * @adapter: adapter structure 758 * 759 * Request hash enable capabilities from PF 760 **/ 761 void iavf_get_hena(struct iavf_adapter *adapter) 762 { 763 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 764 /* bail because we already have a command pending */ 765 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n", 766 adapter->current_op); 767 return; 768 } 769 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS; 770 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA; 771 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0); 772 } 773 774 /** 775 * iavf_set_hena 776 * @adapter: adapter structure 777 * 778 * Request the PF to set our RSS hash capabilities 779 **/ 780 void iavf_set_hena(struct iavf_adapter *adapter) 781 { 782 struct virtchnl_rss_hena vrh; 783 784 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 785 /* bail because we already have a command pending */ 786 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n", 787 adapter->current_op); 788 return; 789 } 790 vrh.hena = adapter->hena; 791 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA; 792 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA; 793 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh, 794 sizeof(vrh)); 795 } 796 797 /** 798 * iavf_set_rss_key 799 * @adapter: adapter structure 800 * 801 * Request the PF to set our RSS hash key 802 **/ 803 void iavf_set_rss_key(struct iavf_adapter *adapter) 804 { 805 struct virtchnl_rss_key *vrk; 806 int len; 807 808 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 809 /* bail because we already have a command pending */ 810 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n", 811 adapter->current_op); 812 return; 813 } 814 len = sizeof(struct virtchnl_rss_key) + 815 (adapter->rss_key_size * sizeof(u8)) - 1; 816 vrk = kzalloc(len, GFP_KERNEL); 817 if (!vrk) 818 return; 819 vrk->vsi_id = adapter->vsi.id; 820 vrk->key_len = adapter->rss_key_size; 821 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size); 822 823 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY; 824 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY; 825 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len); 826 kfree(vrk); 827 } 828 829 /** 830 * iavf_set_rss_lut 831 * @adapter: adapter structure 832 * 833 * Request the PF to set our RSS lookup table 834 **/ 835 void iavf_set_rss_lut(struct iavf_adapter *adapter) 836 { 837 struct virtchnl_rss_lut *vrl; 838 int len; 839 840 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 841 /* bail because we already have a command pending */ 842 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n", 843 adapter->current_op); 844 return; 845 } 846 len = sizeof(struct virtchnl_rss_lut) + 847 (adapter->rss_lut_size * sizeof(u8)) - 1; 848 vrl = kzalloc(len, GFP_KERNEL); 849 if (!vrl) 850 return; 851 vrl->vsi_id = adapter->vsi.id; 852 vrl->lut_entries = adapter->rss_lut_size; 853 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size); 854 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT; 855 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT; 856 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len); 857 kfree(vrl); 858 } 859 860 /** 861 * iavf_enable_vlan_stripping 862 * @adapter: adapter structure 863 * 864 * Request VLAN header stripping to be enabled 865 **/ 866 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter) 867 { 868 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 869 /* bail because we already have a command pending */ 870 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n", 871 adapter->current_op); 872 return; 873 } 874 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING; 875 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; 876 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0); 877 } 878 879 /** 880 * iavf_disable_vlan_stripping 881 * @adapter: adapter structure 882 * 883 * Request VLAN header stripping to be disabled 884 **/ 885 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter) 886 { 887 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 888 /* bail because we already have a command pending */ 889 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n", 890 adapter->current_op); 891 return; 892 } 893 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING; 894 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; 895 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0); 896 } 897 898 #define IAVF_MAX_SPEED_STRLEN 13 899 900 /** 901 * iavf_print_link_message - print link up or down 902 * @adapter: adapter structure 903 * 904 * Log a message telling the world of our wonderous link status 905 */ 906 static void iavf_print_link_message(struct iavf_adapter *adapter) 907 { 908 struct net_device *netdev = adapter->netdev; 909 int link_speed_mbps; 910 char *speed; 911 912 if (!adapter->link_up) { 913 netdev_info(netdev, "NIC Link is Down\n"); 914 return; 915 } 916 917 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL); 918 if (!speed) 919 return; 920 921 if (ADV_LINK_SUPPORT(adapter)) { 922 link_speed_mbps = adapter->link_speed_mbps; 923 goto print_link_msg; 924 } 925 926 switch (adapter->link_speed) { 927 case VIRTCHNL_LINK_SPEED_40GB: 928 link_speed_mbps = SPEED_40000; 929 break; 930 case VIRTCHNL_LINK_SPEED_25GB: 931 link_speed_mbps = SPEED_25000; 932 break; 933 case VIRTCHNL_LINK_SPEED_20GB: 934 link_speed_mbps = SPEED_20000; 935 break; 936 case VIRTCHNL_LINK_SPEED_10GB: 937 link_speed_mbps = SPEED_10000; 938 break; 939 case VIRTCHNL_LINK_SPEED_5GB: 940 link_speed_mbps = SPEED_5000; 941 break; 942 case VIRTCHNL_LINK_SPEED_2_5GB: 943 link_speed_mbps = SPEED_2500; 944 break; 945 case VIRTCHNL_LINK_SPEED_1GB: 946 link_speed_mbps = SPEED_1000; 947 break; 948 case VIRTCHNL_LINK_SPEED_100MB: 949 link_speed_mbps = SPEED_100; 950 break; 951 default: 952 link_speed_mbps = SPEED_UNKNOWN; 953 break; 954 } 955 956 print_link_msg: 957 if (link_speed_mbps > SPEED_1000) { 958 if (link_speed_mbps == SPEED_2500) 959 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps"); 960 else 961 /* convert to Gbps inline */ 962 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s", 963 link_speed_mbps / 1000, "Gbps"); 964 } else if (link_speed_mbps == SPEED_UNKNOWN) { 965 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps"); 966 } else { 967 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%u %s", 968 link_speed_mbps, "Mbps"); 969 } 970 971 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed); 972 kfree(speed); 973 } 974 975 /** 976 * iavf_get_vpe_link_status 977 * @adapter: adapter structure 978 * @vpe: virtchnl_pf_event structure 979 * 980 * Helper function for determining the link status 981 **/ 982 static bool 983 iavf_get_vpe_link_status(struct iavf_adapter *adapter, 984 struct virtchnl_pf_event *vpe) 985 { 986 if (ADV_LINK_SUPPORT(adapter)) 987 return vpe->event_data.link_event_adv.link_status; 988 else 989 return vpe->event_data.link_event.link_status; 990 } 991 992 /** 993 * iavf_set_adapter_link_speed_from_vpe 994 * @adapter: adapter structure for which we are setting the link speed 995 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting 996 * 997 * Helper function for setting iavf_adapter link speed 998 **/ 999 static void 1000 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter, 1001 struct virtchnl_pf_event *vpe) 1002 { 1003 if (ADV_LINK_SUPPORT(adapter)) 1004 adapter->link_speed_mbps = 1005 vpe->event_data.link_event_adv.link_speed; 1006 else 1007 adapter->link_speed = vpe->event_data.link_event.link_speed; 1008 } 1009 1010 /** 1011 * iavf_enable_channels 1012 * @adapter: adapter structure 1013 * 1014 * Request that the PF enable channels as specified by 1015 * the user via tc tool. 1016 **/ 1017 void iavf_enable_channels(struct iavf_adapter *adapter) 1018 { 1019 struct virtchnl_tc_info *vti = NULL; 1020 size_t len; 1021 int i; 1022 1023 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1024 /* bail because we already have a command pending */ 1025 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 1026 adapter->current_op); 1027 return; 1028 } 1029 1030 len = struct_size(vti, list, adapter->num_tc - 1); 1031 vti = kzalloc(len, GFP_KERNEL); 1032 if (!vti) 1033 return; 1034 vti->num_tc = adapter->num_tc; 1035 for (i = 0; i < vti->num_tc; i++) { 1036 vti->list[i].count = adapter->ch_config.ch_info[i].count; 1037 vti->list[i].offset = adapter->ch_config.ch_info[i].offset; 1038 vti->list[i].pad = 0; 1039 vti->list[i].max_tx_rate = 1040 adapter->ch_config.ch_info[i].max_tx_rate; 1041 } 1042 1043 adapter->ch_config.state = __IAVF_TC_RUNNING; 1044 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 1045 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS; 1046 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS; 1047 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len); 1048 kfree(vti); 1049 } 1050 1051 /** 1052 * iavf_disable_channels 1053 * @adapter: adapter structure 1054 * 1055 * Request that the PF disable channels that are configured 1056 **/ 1057 void iavf_disable_channels(struct iavf_adapter *adapter) 1058 { 1059 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1060 /* bail because we already have a command pending */ 1061 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 1062 adapter->current_op); 1063 return; 1064 } 1065 1066 adapter->ch_config.state = __IAVF_TC_INVALID; 1067 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 1068 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS; 1069 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS; 1070 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0); 1071 } 1072 1073 /** 1074 * iavf_print_cloud_filter 1075 * @adapter: adapter structure 1076 * @f: cloud filter to print 1077 * 1078 * Print the cloud filter 1079 **/ 1080 static void iavf_print_cloud_filter(struct iavf_adapter *adapter, 1081 struct virtchnl_filter *f) 1082 { 1083 switch (f->flow_type) { 1084 case VIRTCHNL_TCP_V4_FLOW: 1085 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", 1086 &f->data.tcp_spec.dst_mac, 1087 &f->data.tcp_spec.src_mac, 1088 ntohs(f->data.tcp_spec.vlan_id), 1089 &f->data.tcp_spec.dst_ip[0], 1090 &f->data.tcp_spec.src_ip[0], 1091 ntohs(f->data.tcp_spec.dst_port), 1092 ntohs(f->data.tcp_spec.src_port)); 1093 break; 1094 case VIRTCHNL_TCP_V6_FLOW: 1095 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", 1096 &f->data.tcp_spec.dst_mac, 1097 &f->data.tcp_spec.src_mac, 1098 ntohs(f->data.tcp_spec.vlan_id), 1099 &f->data.tcp_spec.dst_ip, 1100 &f->data.tcp_spec.src_ip, 1101 ntohs(f->data.tcp_spec.dst_port), 1102 ntohs(f->data.tcp_spec.src_port)); 1103 break; 1104 } 1105 } 1106 1107 /** 1108 * iavf_add_cloud_filter 1109 * @adapter: adapter structure 1110 * 1111 * Request that the PF add cloud filters as specified 1112 * by the user via tc tool. 1113 **/ 1114 void iavf_add_cloud_filter(struct iavf_adapter *adapter) 1115 { 1116 struct iavf_cloud_filter *cf; 1117 struct virtchnl_filter *f; 1118 int len = 0, count = 0; 1119 1120 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1121 /* bail because we already have a command pending */ 1122 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n", 1123 adapter->current_op); 1124 return; 1125 } 1126 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1127 if (cf->add) { 1128 count++; 1129 break; 1130 } 1131 } 1132 if (!count) { 1133 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER; 1134 return; 1135 } 1136 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER; 1137 1138 len = sizeof(struct virtchnl_filter); 1139 f = kzalloc(len, GFP_KERNEL); 1140 if (!f) 1141 return; 1142 1143 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1144 if (cf->add) { 1145 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1146 cf->add = false; 1147 cf->state = __IAVF_CF_ADD_PENDING; 1148 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER, 1149 (u8 *)f, len); 1150 } 1151 } 1152 kfree(f); 1153 } 1154 1155 /** 1156 * iavf_del_cloud_filter 1157 * @adapter: adapter structure 1158 * 1159 * Request that the PF delete cloud filters as specified 1160 * by the user via tc tool. 1161 **/ 1162 void iavf_del_cloud_filter(struct iavf_adapter *adapter) 1163 { 1164 struct iavf_cloud_filter *cf, *cftmp; 1165 struct virtchnl_filter *f; 1166 int len = 0, count = 0; 1167 1168 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1169 /* bail because we already have a command pending */ 1170 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n", 1171 adapter->current_op); 1172 return; 1173 } 1174 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1175 if (cf->del) { 1176 count++; 1177 break; 1178 } 1179 } 1180 if (!count) { 1181 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER; 1182 return; 1183 } 1184 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER; 1185 1186 len = sizeof(struct virtchnl_filter); 1187 f = kzalloc(len, GFP_KERNEL); 1188 if (!f) 1189 return; 1190 1191 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) { 1192 if (cf->del) { 1193 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1194 cf->del = false; 1195 cf->state = __IAVF_CF_DEL_PENDING; 1196 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER, 1197 (u8 *)f, len); 1198 } 1199 } 1200 kfree(f); 1201 } 1202 1203 /** 1204 * iavf_add_fdir_filter 1205 * @adapter: the VF adapter structure 1206 * 1207 * Request that the PF add Flow Director filters as specified 1208 * by the user via ethtool. 1209 **/ 1210 void iavf_add_fdir_filter(struct iavf_adapter *adapter) 1211 { 1212 struct iavf_fdir_fltr *fdir; 1213 struct virtchnl_fdir_add *f; 1214 bool process_fltr = false; 1215 int len; 1216 1217 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1218 /* bail because we already have a command pending */ 1219 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n", 1220 adapter->current_op); 1221 return; 1222 } 1223 1224 len = sizeof(struct virtchnl_fdir_add); 1225 f = kzalloc(len, GFP_KERNEL); 1226 if (!f) 1227 return; 1228 1229 spin_lock_bh(&adapter->fdir_fltr_lock); 1230 list_for_each_entry(fdir, &adapter->fdir_list_head, list) { 1231 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) { 1232 process_fltr = true; 1233 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING; 1234 memcpy(f, &fdir->vc_add_msg, len); 1235 break; 1236 } 1237 } 1238 spin_unlock_bh(&adapter->fdir_fltr_lock); 1239 1240 if (!process_fltr) { 1241 /* prevent iavf_add_fdir_filter() from being called when there 1242 * are no filters to add 1243 */ 1244 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER; 1245 kfree(f); 1246 return; 1247 } 1248 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER; 1249 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len); 1250 kfree(f); 1251 } 1252 1253 /** 1254 * iavf_del_fdir_filter 1255 * @adapter: the VF adapter structure 1256 * 1257 * Request that the PF delete Flow Director filters as specified 1258 * by the user via ethtool. 1259 **/ 1260 void iavf_del_fdir_filter(struct iavf_adapter *adapter) 1261 { 1262 struct iavf_fdir_fltr *fdir; 1263 struct virtchnl_fdir_del f; 1264 bool process_fltr = false; 1265 int len; 1266 1267 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1268 /* bail because we already have a command pending */ 1269 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n", 1270 adapter->current_op); 1271 return; 1272 } 1273 1274 len = sizeof(struct virtchnl_fdir_del); 1275 1276 spin_lock_bh(&adapter->fdir_fltr_lock); 1277 list_for_each_entry(fdir, &adapter->fdir_list_head, list) { 1278 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) { 1279 process_fltr = true; 1280 memset(&f, 0, len); 1281 f.vsi_id = fdir->vc_add_msg.vsi_id; 1282 f.flow_id = fdir->flow_id; 1283 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING; 1284 break; 1285 } 1286 } 1287 spin_unlock_bh(&adapter->fdir_fltr_lock); 1288 1289 if (!process_fltr) { 1290 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER; 1291 return; 1292 } 1293 1294 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER; 1295 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len); 1296 } 1297 1298 /** 1299 * iavf_add_adv_rss_cfg 1300 * @adapter: the VF adapter structure 1301 * 1302 * Request that the PF add RSS configuration as specified 1303 * by the user via ethtool. 1304 **/ 1305 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter) 1306 { 1307 struct virtchnl_rss_cfg *rss_cfg; 1308 struct iavf_adv_rss *rss; 1309 bool process_rss = false; 1310 int len; 1311 1312 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1313 /* bail because we already have a command pending */ 1314 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n", 1315 adapter->current_op); 1316 return; 1317 } 1318 1319 len = sizeof(struct virtchnl_rss_cfg); 1320 rss_cfg = kzalloc(len, GFP_KERNEL); 1321 if (!rss_cfg) 1322 return; 1323 1324 spin_lock_bh(&adapter->adv_rss_lock); 1325 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 1326 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) { 1327 process_rss = true; 1328 rss->state = IAVF_ADV_RSS_ADD_PENDING; 1329 memcpy(rss_cfg, &rss->cfg_msg, len); 1330 iavf_print_adv_rss_cfg(adapter, rss, 1331 "Input set change for", 1332 "is pending"); 1333 break; 1334 } 1335 } 1336 spin_unlock_bh(&adapter->adv_rss_lock); 1337 1338 if (process_rss) { 1339 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG; 1340 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG, 1341 (u8 *)rss_cfg, len); 1342 } else { 1343 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG; 1344 } 1345 1346 kfree(rss_cfg); 1347 } 1348 1349 /** 1350 * iavf_del_adv_rss_cfg 1351 * @adapter: the VF adapter structure 1352 * 1353 * Request that the PF delete RSS configuration as specified 1354 * by the user via ethtool. 1355 **/ 1356 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter) 1357 { 1358 struct virtchnl_rss_cfg *rss_cfg; 1359 struct iavf_adv_rss *rss; 1360 bool process_rss = false; 1361 int len; 1362 1363 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1364 /* bail because we already have a command pending */ 1365 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n", 1366 adapter->current_op); 1367 return; 1368 } 1369 1370 len = sizeof(struct virtchnl_rss_cfg); 1371 rss_cfg = kzalloc(len, GFP_KERNEL); 1372 if (!rss_cfg) 1373 return; 1374 1375 spin_lock_bh(&adapter->adv_rss_lock); 1376 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 1377 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) { 1378 process_rss = true; 1379 rss->state = IAVF_ADV_RSS_DEL_PENDING; 1380 memcpy(rss_cfg, &rss->cfg_msg, len); 1381 break; 1382 } 1383 } 1384 spin_unlock_bh(&adapter->adv_rss_lock); 1385 1386 if (process_rss) { 1387 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG; 1388 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG, 1389 (u8 *)rss_cfg, len); 1390 } else { 1391 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG; 1392 } 1393 1394 kfree(rss_cfg); 1395 } 1396 1397 /** 1398 * iavf_request_reset 1399 * @adapter: adapter structure 1400 * 1401 * Request that the PF reset this VF. No response is expected. 1402 **/ 1403 void iavf_request_reset(struct iavf_adapter *adapter) 1404 { 1405 /* Don't check CURRENT_OP - this is always higher priority */ 1406 iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0); 1407 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1408 } 1409 1410 /** 1411 * iavf_virtchnl_completion 1412 * @adapter: adapter structure 1413 * @v_opcode: opcode sent by PF 1414 * @v_retval: retval sent by PF 1415 * @msg: message sent by PF 1416 * @msglen: message length 1417 * 1418 * Asynchronous completion function for admin queue messages. Rather than busy 1419 * wait, we fire off our requests and assume that no errors will be returned. 1420 * This function handles the reply messages. 1421 **/ 1422 void iavf_virtchnl_completion(struct iavf_adapter *adapter, 1423 enum virtchnl_ops v_opcode, 1424 enum iavf_status v_retval, u8 *msg, u16 msglen) 1425 { 1426 struct net_device *netdev = adapter->netdev; 1427 1428 if (v_opcode == VIRTCHNL_OP_EVENT) { 1429 struct virtchnl_pf_event *vpe = 1430 (struct virtchnl_pf_event *)msg; 1431 bool link_up = iavf_get_vpe_link_status(adapter, vpe); 1432 1433 switch (vpe->event) { 1434 case VIRTCHNL_EVENT_LINK_CHANGE: 1435 iavf_set_adapter_link_speed_from_vpe(adapter, vpe); 1436 1437 /* we've already got the right link status, bail */ 1438 if (adapter->link_up == link_up) 1439 break; 1440 1441 if (link_up) { 1442 /* If we get link up message and start queues 1443 * before our queues are configured it will 1444 * trigger a TX hang. In that case, just ignore 1445 * the link status message,we'll get another one 1446 * after we enable queues and actually prepared 1447 * to send traffic. 1448 */ 1449 if (adapter->state != __IAVF_RUNNING) 1450 break; 1451 1452 /* For ADq enabled VF, we reconfigure VSIs and 1453 * re-allocate queues. Hence wait till all 1454 * queues are enabled. 1455 */ 1456 if (adapter->flags & 1457 IAVF_FLAG_QUEUES_DISABLED) 1458 break; 1459 } 1460 1461 adapter->link_up = link_up; 1462 if (link_up) { 1463 netif_tx_start_all_queues(netdev); 1464 netif_carrier_on(netdev); 1465 } else { 1466 netif_tx_stop_all_queues(netdev); 1467 netif_carrier_off(netdev); 1468 } 1469 iavf_print_link_message(adapter); 1470 break; 1471 case VIRTCHNL_EVENT_RESET_IMPENDING: 1472 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n"); 1473 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) { 1474 adapter->flags |= IAVF_FLAG_RESET_PENDING; 1475 dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); 1476 queue_work(iavf_wq, &adapter->reset_task); 1477 } 1478 break; 1479 default: 1480 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", 1481 vpe->event); 1482 break; 1483 } 1484 return; 1485 } 1486 if (v_retval) { 1487 switch (v_opcode) { 1488 case VIRTCHNL_OP_ADD_VLAN: 1489 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", 1490 iavf_stat_str(&adapter->hw, v_retval)); 1491 break; 1492 case VIRTCHNL_OP_ADD_ETH_ADDR: 1493 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", 1494 iavf_stat_str(&adapter->hw, v_retval)); 1495 /* restore administratively set MAC address */ 1496 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 1497 break; 1498 case VIRTCHNL_OP_DEL_VLAN: 1499 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", 1500 iavf_stat_str(&adapter->hw, v_retval)); 1501 break; 1502 case VIRTCHNL_OP_DEL_ETH_ADDR: 1503 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", 1504 iavf_stat_str(&adapter->hw, v_retval)); 1505 break; 1506 case VIRTCHNL_OP_ENABLE_CHANNELS: 1507 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n", 1508 iavf_stat_str(&adapter->hw, v_retval)); 1509 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1510 adapter->ch_config.state = __IAVF_TC_INVALID; 1511 netdev_reset_tc(netdev); 1512 netif_tx_start_all_queues(netdev); 1513 break; 1514 case VIRTCHNL_OP_DISABLE_CHANNELS: 1515 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n", 1516 iavf_stat_str(&adapter->hw, v_retval)); 1517 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1518 adapter->ch_config.state = __IAVF_TC_RUNNING; 1519 netif_tx_start_all_queues(netdev); 1520 break; 1521 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 1522 struct iavf_cloud_filter *cf, *cftmp; 1523 1524 list_for_each_entry_safe(cf, cftmp, 1525 &adapter->cloud_filter_list, 1526 list) { 1527 if (cf->state == __IAVF_CF_ADD_PENDING) { 1528 cf->state = __IAVF_CF_INVALID; 1529 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n", 1530 iavf_stat_str(&adapter->hw, 1531 v_retval)); 1532 iavf_print_cloud_filter(adapter, 1533 &cf->f); 1534 list_del(&cf->list); 1535 kfree(cf); 1536 adapter->num_cloud_filters--; 1537 } 1538 } 1539 } 1540 break; 1541 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 1542 struct iavf_cloud_filter *cf; 1543 1544 list_for_each_entry(cf, &adapter->cloud_filter_list, 1545 list) { 1546 if (cf->state == __IAVF_CF_DEL_PENDING) { 1547 cf->state = __IAVF_CF_ACTIVE; 1548 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n", 1549 iavf_stat_str(&adapter->hw, 1550 v_retval)); 1551 iavf_print_cloud_filter(adapter, 1552 &cf->f); 1553 } 1554 } 1555 } 1556 break; 1557 case VIRTCHNL_OP_ADD_FDIR_FILTER: { 1558 struct iavf_fdir_fltr *fdir, *fdir_tmp; 1559 1560 spin_lock_bh(&adapter->fdir_fltr_lock); 1561 list_for_each_entry_safe(fdir, fdir_tmp, 1562 &adapter->fdir_list_head, 1563 list) { 1564 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) { 1565 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n", 1566 iavf_stat_str(&adapter->hw, 1567 v_retval)); 1568 iavf_print_fdir_fltr(adapter, fdir); 1569 if (msglen) 1570 dev_err(&adapter->pdev->dev, 1571 "%s\n", msg); 1572 list_del(&fdir->list); 1573 kfree(fdir); 1574 adapter->fdir_active_fltr--; 1575 } 1576 } 1577 spin_unlock_bh(&adapter->fdir_fltr_lock); 1578 } 1579 break; 1580 case VIRTCHNL_OP_DEL_FDIR_FILTER: { 1581 struct iavf_fdir_fltr *fdir; 1582 1583 spin_lock_bh(&adapter->fdir_fltr_lock); 1584 list_for_each_entry(fdir, &adapter->fdir_list_head, 1585 list) { 1586 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) { 1587 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 1588 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n", 1589 iavf_stat_str(&adapter->hw, 1590 v_retval)); 1591 iavf_print_fdir_fltr(adapter, fdir); 1592 } 1593 } 1594 spin_unlock_bh(&adapter->fdir_fltr_lock); 1595 } 1596 break; 1597 case VIRTCHNL_OP_ADD_RSS_CFG: { 1598 struct iavf_adv_rss *rss, *rss_tmp; 1599 1600 spin_lock_bh(&adapter->adv_rss_lock); 1601 list_for_each_entry_safe(rss, rss_tmp, 1602 &adapter->adv_rss_list_head, 1603 list) { 1604 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) { 1605 iavf_print_adv_rss_cfg(adapter, rss, 1606 "Failed to change the input set for", 1607 NULL); 1608 list_del(&rss->list); 1609 kfree(rss); 1610 } 1611 } 1612 spin_unlock_bh(&adapter->adv_rss_lock); 1613 } 1614 break; 1615 case VIRTCHNL_OP_DEL_RSS_CFG: { 1616 struct iavf_adv_rss *rss; 1617 1618 spin_lock_bh(&adapter->adv_rss_lock); 1619 list_for_each_entry(rss, &adapter->adv_rss_list_head, 1620 list) { 1621 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) { 1622 rss->state = IAVF_ADV_RSS_ACTIVE; 1623 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n", 1624 iavf_stat_str(&adapter->hw, 1625 v_retval)); 1626 } 1627 } 1628 spin_unlock_bh(&adapter->adv_rss_lock); 1629 } 1630 break; 1631 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 1632 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 1633 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n"); 1634 break; 1635 default: 1636 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", 1637 v_retval, iavf_stat_str(&adapter->hw, v_retval), 1638 v_opcode); 1639 } 1640 } 1641 switch (v_opcode) { 1642 case VIRTCHNL_OP_ADD_ETH_ADDR: { 1643 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr)) 1644 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); 1645 } 1646 break; 1647 case VIRTCHNL_OP_GET_STATS: { 1648 struct iavf_eth_stats *stats = 1649 (struct iavf_eth_stats *)msg; 1650 netdev->stats.rx_packets = stats->rx_unicast + 1651 stats->rx_multicast + 1652 stats->rx_broadcast; 1653 netdev->stats.tx_packets = stats->tx_unicast + 1654 stats->tx_multicast + 1655 stats->tx_broadcast; 1656 netdev->stats.rx_bytes = stats->rx_bytes; 1657 netdev->stats.tx_bytes = stats->tx_bytes; 1658 netdev->stats.tx_errors = stats->tx_errors; 1659 netdev->stats.rx_dropped = stats->rx_discards; 1660 netdev->stats.tx_dropped = stats->tx_discards; 1661 adapter->current_stats = *stats; 1662 } 1663 break; 1664 case VIRTCHNL_OP_GET_VF_RESOURCES: { 1665 u16 len = sizeof(struct virtchnl_vf_resource) + 1666 IAVF_MAX_VF_VSI * 1667 sizeof(struct virtchnl_vsi_resource); 1668 memcpy(adapter->vf_res, msg, min(msglen, len)); 1669 iavf_validate_num_queues(adapter); 1670 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res); 1671 if (is_zero_ether_addr(adapter->hw.mac.addr)) { 1672 /* restore current mac address */ 1673 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 1674 } else { 1675 /* refresh current mac address if changed */ 1676 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); 1677 ether_addr_copy(netdev->perm_addr, 1678 adapter->hw.mac.addr); 1679 } 1680 spin_lock_bh(&adapter->mac_vlan_list_lock); 1681 iavf_add_filter(adapter, adapter->hw.mac.addr); 1682 spin_unlock_bh(&adapter->mac_vlan_list_lock); 1683 iavf_process_config(adapter); 1684 } 1685 break; 1686 case VIRTCHNL_OP_ENABLE_QUEUES: 1687 /* enable transmits */ 1688 iavf_irq_enable(adapter, true); 1689 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED; 1690 break; 1691 case VIRTCHNL_OP_DISABLE_QUEUES: 1692 iavf_free_all_tx_resources(adapter); 1693 iavf_free_all_rx_resources(adapter); 1694 if (adapter->state == __IAVF_DOWN_PENDING) { 1695 adapter->state = __IAVF_DOWN; 1696 wake_up(&adapter->down_waitqueue); 1697 } 1698 break; 1699 case VIRTCHNL_OP_VERSION: 1700 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1701 /* Don't display an error if we get these out of sequence. 1702 * If the firmware needed to get kicked, we'll get these and 1703 * it's no problem. 1704 */ 1705 if (v_opcode != adapter->current_op) 1706 return; 1707 break; 1708 case VIRTCHNL_OP_IWARP: 1709 /* Gobble zero-length replies from the PF. They indicate that 1710 * a previous message was received OK, and the client doesn't 1711 * care about that. 1712 */ 1713 if (msglen && CLIENT_ENABLED(adapter)) 1714 iavf_notify_client_message(&adapter->vsi, msg, msglen); 1715 break; 1716 1717 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 1718 adapter->client_pending &= 1719 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP)); 1720 break; 1721 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: { 1722 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg; 1723 1724 if (msglen == sizeof(*vrh)) 1725 adapter->hena = vrh->hena; 1726 else 1727 dev_warn(&adapter->pdev->dev, 1728 "Invalid message %d from PF\n", v_opcode); 1729 } 1730 break; 1731 case VIRTCHNL_OP_REQUEST_QUEUES: { 1732 struct virtchnl_vf_res_request *vfres = 1733 (struct virtchnl_vf_res_request *)msg; 1734 1735 if (vfres->num_queue_pairs != adapter->num_req_queues) { 1736 dev_info(&adapter->pdev->dev, 1737 "Requested %d queues, PF can support %d\n", 1738 adapter->num_req_queues, 1739 vfres->num_queue_pairs); 1740 adapter->num_req_queues = 0; 1741 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1742 } 1743 } 1744 break; 1745 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 1746 struct iavf_cloud_filter *cf; 1747 1748 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1749 if (cf->state == __IAVF_CF_ADD_PENDING) 1750 cf->state = __IAVF_CF_ACTIVE; 1751 } 1752 } 1753 break; 1754 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 1755 struct iavf_cloud_filter *cf, *cftmp; 1756 1757 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, 1758 list) { 1759 if (cf->state == __IAVF_CF_DEL_PENDING) { 1760 cf->state = __IAVF_CF_INVALID; 1761 list_del(&cf->list); 1762 kfree(cf); 1763 adapter->num_cloud_filters--; 1764 } 1765 } 1766 } 1767 break; 1768 case VIRTCHNL_OP_ADD_FDIR_FILTER: { 1769 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg; 1770 struct iavf_fdir_fltr *fdir, *fdir_tmp; 1771 1772 spin_lock_bh(&adapter->fdir_fltr_lock); 1773 list_for_each_entry_safe(fdir, fdir_tmp, 1774 &adapter->fdir_list_head, 1775 list) { 1776 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) { 1777 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) { 1778 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n", 1779 fdir->loc); 1780 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 1781 fdir->flow_id = add_fltr->flow_id; 1782 } else { 1783 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n", 1784 add_fltr->status); 1785 iavf_print_fdir_fltr(adapter, fdir); 1786 list_del(&fdir->list); 1787 kfree(fdir); 1788 adapter->fdir_active_fltr--; 1789 } 1790 } 1791 } 1792 spin_unlock_bh(&adapter->fdir_fltr_lock); 1793 } 1794 break; 1795 case VIRTCHNL_OP_DEL_FDIR_FILTER: { 1796 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg; 1797 struct iavf_fdir_fltr *fdir, *fdir_tmp; 1798 1799 spin_lock_bh(&adapter->fdir_fltr_lock); 1800 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head, 1801 list) { 1802 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) { 1803 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) { 1804 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n", 1805 fdir->loc); 1806 list_del(&fdir->list); 1807 kfree(fdir); 1808 adapter->fdir_active_fltr--; 1809 } else { 1810 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 1811 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n", 1812 del_fltr->status); 1813 iavf_print_fdir_fltr(adapter, fdir); 1814 } 1815 } 1816 } 1817 spin_unlock_bh(&adapter->fdir_fltr_lock); 1818 } 1819 break; 1820 case VIRTCHNL_OP_ADD_RSS_CFG: { 1821 struct iavf_adv_rss *rss; 1822 1823 spin_lock_bh(&adapter->adv_rss_lock); 1824 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 1825 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) { 1826 iavf_print_adv_rss_cfg(adapter, rss, 1827 "Input set change for", 1828 "successful"); 1829 rss->state = IAVF_ADV_RSS_ACTIVE; 1830 } 1831 } 1832 spin_unlock_bh(&adapter->adv_rss_lock); 1833 } 1834 break; 1835 case VIRTCHNL_OP_DEL_RSS_CFG: { 1836 struct iavf_adv_rss *rss, *rss_tmp; 1837 1838 spin_lock_bh(&adapter->adv_rss_lock); 1839 list_for_each_entry_safe(rss, rss_tmp, 1840 &adapter->adv_rss_list_head, list) { 1841 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) { 1842 list_del(&rss->list); 1843 kfree(rss); 1844 } 1845 } 1846 spin_unlock_bh(&adapter->adv_rss_lock); 1847 } 1848 break; 1849 default: 1850 if (adapter->current_op && (v_opcode != adapter->current_op)) 1851 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", 1852 adapter->current_op, v_opcode); 1853 break; 1854 } /* switch v_opcode */ 1855 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1856 } 1857