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 status; 26 27 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) 28 return 0; /* nothing to see here, move along */ 29 30 status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL); 31 if (status) 32 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n", 33 op, iavf_stat_str(hw, status), 34 iavf_aq_str(hw, hw->aq.asq_last_status)); 35 return iavf_status_to_errno(status); 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_poll_virtchnl_msg 59 * @hw: HW configuration structure 60 * @event: event to populate on success 61 * @op_to_poll: requested virtchnl op to poll for 62 * 63 * Initialize poll for virtchnl msg matching the requested_op. Returns 0 64 * if a message of the correct opcode is in the queue or an error code 65 * if no message matching the op code is waiting and other failures. 66 */ 67 static int 68 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event, 69 enum virtchnl_ops op_to_poll) 70 { 71 enum virtchnl_ops received_op; 72 enum iavf_status status; 73 u32 v_retval; 74 75 while (1) { 76 /* When the AQ is empty, iavf_clean_arq_element will return 77 * nonzero and this loop will terminate. 78 */ 79 status = iavf_clean_arq_element(hw, event, NULL); 80 if (status != IAVF_SUCCESS) 81 return iavf_status_to_errno(status); 82 received_op = 83 (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high); 84 if (op_to_poll == received_op) 85 break; 86 } 87 88 v_retval = le32_to_cpu(event->desc.cookie_low); 89 return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval); 90 } 91 92 /** 93 * iavf_verify_api_ver 94 * @adapter: adapter structure 95 * 96 * Compare API versions with the PF. Must be called after admin queue is 97 * initialized. Returns 0 if API versions match, -EIO if they do not, 98 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors 99 * from the firmware are propagated. 100 **/ 101 int iavf_verify_api_ver(struct iavf_adapter *adapter) 102 { 103 struct iavf_arq_event_info event; 104 int err; 105 106 event.buf_len = IAVF_MAX_AQ_BUF_SIZE; 107 event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL); 108 if (!event.msg_buf) 109 return -ENOMEM; 110 111 err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION); 112 if (!err) { 113 struct virtchnl_version_info *pf_vvi = 114 (struct virtchnl_version_info *)event.msg_buf; 115 adapter->pf_version = *pf_vvi; 116 117 if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR || 118 (pf_vvi->major == VIRTCHNL_VERSION_MAJOR && 119 pf_vvi->minor > VIRTCHNL_VERSION_MINOR)) 120 err = -EIO; 121 } 122 123 kfree(event.msg_buf); 124 125 return err; 126 } 127 128 /** 129 * iavf_send_vf_config_msg 130 * @adapter: adapter structure 131 * 132 * Send VF configuration request admin queue message to the PF. The reply 133 * is not checked in this function. Returns 0 if the message was 134 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not. 135 **/ 136 int iavf_send_vf_config_msg(struct iavf_adapter *adapter) 137 { 138 u32 caps; 139 140 caps = VIRTCHNL_VF_OFFLOAD_L2 | 141 VIRTCHNL_VF_OFFLOAD_RSS_PF | 142 VIRTCHNL_VF_OFFLOAD_RSS_AQ | 143 VIRTCHNL_VF_OFFLOAD_RSS_REG | 144 VIRTCHNL_VF_OFFLOAD_VLAN | 145 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | 146 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 | 147 VIRTCHNL_VF_OFFLOAD_ENCAP | 148 VIRTCHNL_VF_OFFLOAD_VLAN_V2 | 149 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM | 150 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES | 151 VIRTCHNL_VF_OFFLOAD_ADQ | 152 VIRTCHNL_VF_OFFLOAD_USO | 153 VIRTCHNL_VF_OFFLOAD_FDIR_PF | 154 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF | 155 VIRTCHNL_VF_CAP_ADV_LINK_SPEED; 156 157 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES; 158 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG; 159 if (PF_IS_V11(adapter)) 160 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 161 (u8 *)&caps, sizeof(caps)); 162 else 163 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES, 164 NULL, 0); 165 } 166 167 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter) 168 { 169 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS; 170 171 if (!VLAN_V2_ALLOWED(adapter)) 172 return -EOPNOTSUPP; 173 174 adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS; 175 176 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, 177 NULL, 0); 178 } 179 180 /** 181 * iavf_validate_num_queues 182 * @adapter: adapter structure 183 * 184 * Validate that the number of queues the PF has sent in 185 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle. 186 **/ 187 static void iavf_validate_num_queues(struct iavf_adapter *adapter) 188 { 189 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) { 190 struct virtchnl_vsi_resource *vsi_res; 191 int i; 192 193 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n", 194 adapter->vf_res->num_queue_pairs, 195 IAVF_MAX_REQ_QUEUES); 196 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n", 197 IAVF_MAX_REQ_QUEUES); 198 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 199 for (i = 0; i < adapter->vf_res->num_vsis; i++) { 200 vsi_res = &adapter->vf_res->vsi_res[i]; 201 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES; 202 } 203 } 204 } 205 206 /** 207 * iavf_get_vf_config 208 * @adapter: private adapter structure 209 * 210 * Get VF configuration from PF and populate hw structure. Must be called after 211 * admin queue is initialized. Busy waits until response is received from PF, 212 * with maximum timeout. Response from PF is returned in the buffer for further 213 * processing by the caller. 214 **/ 215 int iavf_get_vf_config(struct iavf_adapter *adapter) 216 { 217 struct iavf_hw *hw = &adapter->hw; 218 struct iavf_arq_event_info event; 219 u16 len; 220 int err; 221 222 len = sizeof(struct virtchnl_vf_resource) + 223 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource); 224 event.buf_len = len; 225 event.msg_buf = kzalloc(len, GFP_KERNEL); 226 if (!event.msg_buf) 227 return -ENOMEM; 228 229 err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES); 230 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); 231 232 /* some PFs send more queues than we should have so validate that 233 * we aren't getting too many queues 234 */ 235 if (!err) 236 iavf_validate_num_queues(adapter); 237 iavf_vf_parse_hw_config(hw, adapter->vf_res); 238 239 kfree(event.msg_buf); 240 241 return err; 242 } 243 244 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter) 245 { 246 struct iavf_arq_event_info event; 247 int err; 248 u16 len; 249 250 len = sizeof(struct virtchnl_vlan_caps); 251 event.buf_len = len; 252 event.msg_buf = kzalloc(len, GFP_KERNEL); 253 if (!event.msg_buf) 254 return -ENOMEM; 255 256 err = iavf_poll_virtchnl_msg(&adapter->hw, &event, 257 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS); 258 if (!err) 259 memcpy(&adapter->vlan_v2_caps, event.msg_buf, 260 min(event.msg_len, len)); 261 262 kfree(event.msg_buf); 263 264 return err; 265 } 266 267 /** 268 * iavf_configure_queues 269 * @adapter: adapter structure 270 * 271 * Request that the PF set up our (previously allocated) queues. 272 **/ 273 void iavf_configure_queues(struct iavf_adapter *adapter) 274 { 275 struct virtchnl_vsi_queue_config_info *vqci; 276 struct virtchnl_queue_pair_info *vqpi; 277 int pairs = adapter->num_active_queues; 278 int i, max_frame = IAVF_MAX_RXBUFFER; 279 size_t len; 280 281 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 282 /* bail because we already have a command pending */ 283 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", 284 adapter->current_op); 285 return; 286 } 287 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES; 288 len = struct_size(vqci, qpair, pairs); 289 vqci = kzalloc(len, GFP_KERNEL); 290 if (!vqci) 291 return; 292 293 /* Limit maximum frame size when jumbo frames is not enabled */ 294 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) && 295 (adapter->netdev->mtu <= ETH_DATA_LEN)) 296 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN; 297 298 vqci->vsi_id = adapter->vsi_res->vsi_id; 299 vqci->num_queue_pairs = pairs; 300 vqpi = vqci->qpair; 301 /* Size check is not needed here - HW max is 16 queue pairs, and we 302 * can fit info for 31 of them into the AQ buffer before it overflows. 303 */ 304 for (i = 0; i < pairs; i++) { 305 vqpi->txq.vsi_id = vqci->vsi_id; 306 vqpi->txq.queue_id = i; 307 vqpi->txq.ring_len = adapter->tx_rings[i].count; 308 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma; 309 vqpi->rxq.vsi_id = vqci->vsi_id; 310 vqpi->rxq.queue_id = i; 311 vqpi->rxq.ring_len = adapter->rx_rings[i].count; 312 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; 313 vqpi->rxq.max_pkt_size = max_frame; 314 vqpi->rxq.databuffer_size = 315 ALIGN(adapter->rx_rings[i].rx_buf_len, 316 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT)); 317 vqpi++; 318 } 319 320 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES; 321 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES, 322 (u8 *)vqci, len); 323 kfree(vqci); 324 } 325 326 /** 327 * iavf_enable_queues 328 * @adapter: adapter structure 329 * 330 * Request that the PF enable all of our queues. 331 **/ 332 void iavf_enable_queues(struct iavf_adapter *adapter) 333 { 334 struct virtchnl_queue_select vqs; 335 336 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 337 /* bail because we already have a command pending */ 338 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", 339 adapter->current_op); 340 return; 341 } 342 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES; 343 vqs.vsi_id = adapter->vsi_res->vsi_id; 344 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 345 vqs.rx_queues = vqs.tx_queues; 346 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES; 347 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES, 348 (u8 *)&vqs, sizeof(vqs)); 349 } 350 351 /** 352 * iavf_disable_queues 353 * @adapter: adapter structure 354 * 355 * Request that the PF disable all of our queues. 356 **/ 357 void iavf_disable_queues(struct iavf_adapter *adapter) 358 { 359 struct virtchnl_queue_select vqs; 360 361 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 362 /* bail because we already have a command pending */ 363 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", 364 adapter->current_op); 365 return; 366 } 367 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES; 368 vqs.vsi_id = adapter->vsi_res->vsi_id; 369 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 370 vqs.rx_queues = vqs.tx_queues; 371 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES; 372 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES, 373 (u8 *)&vqs, sizeof(vqs)); 374 } 375 376 /** 377 * iavf_map_queues 378 * @adapter: adapter structure 379 * 380 * Request that the PF map queues to interrupt vectors. Misc causes, including 381 * admin queue, are always mapped to vector 0. 382 **/ 383 void iavf_map_queues(struct iavf_adapter *adapter) 384 { 385 struct virtchnl_irq_map_info *vimi; 386 struct virtchnl_vector_map *vecmap; 387 struct iavf_q_vector *q_vector; 388 int v_idx, q_vectors; 389 size_t len; 390 391 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 392 /* bail because we already have a command pending */ 393 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", 394 adapter->current_op); 395 return; 396 } 397 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP; 398 399 q_vectors = adapter->num_msix_vectors - NONQ_VECS; 400 401 len = struct_size(vimi, vecmap, adapter->num_msix_vectors); 402 vimi = kzalloc(len, GFP_KERNEL); 403 if (!vimi) 404 return; 405 406 vimi->num_vectors = adapter->num_msix_vectors; 407 /* Queue vectors first */ 408 for (v_idx = 0; v_idx < q_vectors; v_idx++) { 409 q_vector = &adapter->q_vectors[v_idx]; 410 vecmap = &vimi->vecmap[v_idx]; 411 412 vecmap->vsi_id = adapter->vsi_res->vsi_id; 413 vecmap->vector_id = v_idx + NONQ_VECS; 414 vecmap->txq_map = q_vector->ring_mask; 415 vecmap->rxq_map = q_vector->ring_mask; 416 vecmap->rxitr_idx = IAVF_RX_ITR; 417 vecmap->txitr_idx = IAVF_TX_ITR; 418 } 419 /* Misc vector last - this is only for AdminQ messages */ 420 vecmap = &vimi->vecmap[v_idx]; 421 vecmap->vsi_id = adapter->vsi_res->vsi_id; 422 vecmap->vector_id = 0; 423 vecmap->txq_map = 0; 424 vecmap->rxq_map = 0; 425 426 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS; 427 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP, 428 (u8 *)vimi, len); 429 kfree(vimi); 430 } 431 432 /** 433 * iavf_set_mac_addr_type - Set the correct request type from the filter type 434 * @virtchnl_ether_addr: pointer to requested list element 435 * @filter: pointer to requested filter 436 **/ 437 static void 438 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr, 439 const struct iavf_mac_filter *filter) 440 { 441 virtchnl_ether_addr->type = filter->is_primary ? 442 VIRTCHNL_ETHER_ADDR_PRIMARY : 443 VIRTCHNL_ETHER_ADDR_EXTRA; 444 } 445 446 /** 447 * iavf_add_ether_addrs 448 * @adapter: adapter structure 449 * 450 * Request that the PF add one or more addresses to our filters. 451 **/ 452 void iavf_add_ether_addrs(struct iavf_adapter *adapter) 453 { 454 struct virtchnl_ether_addr_list *veal; 455 struct iavf_mac_filter *f; 456 int i = 0, count = 0; 457 bool more = false; 458 size_t len; 459 460 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 461 /* bail because we already have a command pending */ 462 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", 463 adapter->current_op); 464 return; 465 } 466 467 spin_lock_bh(&adapter->mac_vlan_list_lock); 468 469 list_for_each_entry(f, &adapter->mac_filter_list, list) { 470 if (f->add) 471 count++; 472 } 473 if (!count) { 474 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 475 spin_unlock_bh(&adapter->mac_vlan_list_lock); 476 return; 477 } 478 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR; 479 480 len = struct_size(veal, list, count); 481 if (len > IAVF_MAX_AQ_BUF_SIZE) { 482 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n"); 483 count = (IAVF_MAX_AQ_BUF_SIZE - 484 sizeof(struct virtchnl_ether_addr_list)) / 485 sizeof(struct virtchnl_ether_addr); 486 len = struct_size(veal, list, count); 487 more = true; 488 } 489 490 veal = kzalloc(len, GFP_ATOMIC); 491 if (!veal) { 492 spin_unlock_bh(&adapter->mac_vlan_list_lock); 493 return; 494 } 495 496 veal->vsi_id = adapter->vsi_res->vsi_id; 497 veal->num_elements = count; 498 list_for_each_entry(f, &adapter->mac_filter_list, list) { 499 if (f->add) { 500 ether_addr_copy(veal->list[i].addr, f->macaddr); 501 iavf_set_mac_addr_type(&veal->list[i], f); 502 i++; 503 f->add = false; 504 if (i == count) 505 break; 506 } 507 } 508 if (!more) 509 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; 510 511 spin_unlock_bh(&adapter->mac_vlan_list_lock); 512 513 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len); 514 kfree(veal); 515 } 516 517 /** 518 * iavf_del_ether_addrs 519 * @adapter: adapter structure 520 * 521 * Request that the PF remove one or more addresses from our filters. 522 **/ 523 void iavf_del_ether_addrs(struct iavf_adapter *adapter) 524 { 525 struct virtchnl_ether_addr_list *veal; 526 struct iavf_mac_filter *f, *ftmp; 527 int i = 0, count = 0; 528 bool more = false; 529 size_t len; 530 531 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 532 /* bail because we already have a command pending */ 533 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", 534 adapter->current_op); 535 return; 536 } 537 538 spin_lock_bh(&adapter->mac_vlan_list_lock); 539 540 list_for_each_entry(f, &adapter->mac_filter_list, list) { 541 if (f->remove) 542 count++; 543 } 544 if (!count) { 545 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 546 spin_unlock_bh(&adapter->mac_vlan_list_lock); 547 return; 548 } 549 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR; 550 551 len = struct_size(veal, list, count); 552 if (len > IAVF_MAX_AQ_BUF_SIZE) { 553 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n"); 554 count = (IAVF_MAX_AQ_BUF_SIZE - 555 sizeof(struct virtchnl_ether_addr_list)) / 556 sizeof(struct virtchnl_ether_addr); 557 len = struct_size(veal, list, count); 558 more = true; 559 } 560 veal = kzalloc(len, GFP_ATOMIC); 561 if (!veal) { 562 spin_unlock_bh(&adapter->mac_vlan_list_lock); 563 return; 564 } 565 566 veal->vsi_id = adapter->vsi_res->vsi_id; 567 veal->num_elements = count; 568 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 569 if (f->remove) { 570 ether_addr_copy(veal->list[i].addr, f->macaddr); 571 iavf_set_mac_addr_type(&veal->list[i], f); 572 i++; 573 list_del(&f->list); 574 kfree(f); 575 if (i == count) 576 break; 577 } 578 } 579 if (!more) 580 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER; 581 582 spin_unlock_bh(&adapter->mac_vlan_list_lock); 583 584 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len); 585 kfree(veal); 586 } 587 588 /** 589 * iavf_mac_add_ok 590 * @adapter: adapter structure 591 * 592 * Submit list of filters based on PF response. 593 **/ 594 static void iavf_mac_add_ok(struct iavf_adapter *adapter) 595 { 596 struct iavf_mac_filter *f, *ftmp; 597 598 spin_lock_bh(&adapter->mac_vlan_list_lock); 599 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 600 f->is_new_mac = false; 601 } 602 spin_unlock_bh(&adapter->mac_vlan_list_lock); 603 } 604 605 /** 606 * iavf_mac_add_reject 607 * @adapter: adapter structure 608 * 609 * Remove filters from list based on PF response. 610 **/ 611 static void iavf_mac_add_reject(struct iavf_adapter *adapter) 612 { 613 struct net_device *netdev = adapter->netdev; 614 struct iavf_mac_filter *f, *ftmp; 615 616 spin_lock_bh(&adapter->mac_vlan_list_lock); 617 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 618 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr)) 619 f->remove = false; 620 621 if (f->is_new_mac) { 622 list_del(&f->list); 623 kfree(f); 624 } 625 } 626 spin_unlock_bh(&adapter->mac_vlan_list_lock); 627 } 628 629 /** 630 * iavf_vlan_add_reject 631 * @adapter: adapter structure 632 * 633 * Remove VLAN filters from list based on PF response. 634 **/ 635 static void iavf_vlan_add_reject(struct iavf_adapter *adapter) 636 { 637 struct iavf_vlan_filter *f, *ftmp; 638 639 spin_lock_bh(&adapter->mac_vlan_list_lock); 640 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 641 if (f->is_new_vlan) { 642 if (f->vlan.tpid == ETH_P_8021Q) 643 clear_bit(f->vlan.vid, 644 adapter->vsi.active_cvlans); 645 else 646 clear_bit(f->vlan.vid, 647 adapter->vsi.active_svlans); 648 649 list_del(&f->list); 650 kfree(f); 651 } 652 } 653 spin_unlock_bh(&adapter->mac_vlan_list_lock); 654 } 655 656 /** 657 * iavf_add_vlans 658 * @adapter: adapter structure 659 * 660 * Request that the PF add one or more VLAN filters to our VSI. 661 **/ 662 void iavf_add_vlans(struct iavf_adapter *adapter) 663 { 664 int len, i = 0, count = 0; 665 struct iavf_vlan_filter *f; 666 bool more = false; 667 668 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 669 /* bail because we already have a command pending */ 670 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", 671 adapter->current_op); 672 return; 673 } 674 675 spin_lock_bh(&adapter->mac_vlan_list_lock); 676 677 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 678 if (f->add) 679 count++; 680 } 681 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) { 682 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 683 spin_unlock_bh(&adapter->mac_vlan_list_lock); 684 return; 685 } 686 687 if (VLAN_ALLOWED(adapter)) { 688 struct virtchnl_vlan_filter_list *vvfl; 689 690 adapter->current_op = VIRTCHNL_OP_ADD_VLAN; 691 692 len = sizeof(*vvfl) + (count * sizeof(u16)); 693 if (len > IAVF_MAX_AQ_BUF_SIZE) { 694 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 695 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) / 696 sizeof(u16); 697 len = sizeof(*vvfl) + (count * sizeof(u16)); 698 more = true; 699 } 700 vvfl = kzalloc(len, GFP_ATOMIC); 701 if (!vvfl) { 702 spin_unlock_bh(&adapter->mac_vlan_list_lock); 703 return; 704 } 705 706 vvfl->vsi_id = adapter->vsi_res->vsi_id; 707 vvfl->num_elements = count; 708 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 709 if (f->add) { 710 vvfl->vlan_id[i] = f->vlan.vid; 711 i++; 712 f->add = false; 713 f->is_new_vlan = true; 714 if (i == count) 715 break; 716 } 717 } 718 if (!more) 719 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 720 721 spin_unlock_bh(&adapter->mac_vlan_list_lock); 722 723 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); 724 kfree(vvfl); 725 } else { 726 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters; 727 u16 current_vlans = iavf_get_num_vlans_added(adapter); 728 struct virtchnl_vlan_filter_list_v2 *vvfl_v2; 729 730 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2; 731 732 if ((count + current_vlans) > max_vlans && 733 current_vlans < max_vlans) { 734 count = max_vlans - iavf_get_num_vlans_added(adapter); 735 more = true; 736 } 737 738 len = sizeof(*vvfl_v2) + ((count - 1) * 739 sizeof(struct virtchnl_vlan_filter)); 740 if (len > IAVF_MAX_AQ_BUF_SIZE) { 741 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 742 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) / 743 sizeof(struct virtchnl_vlan_filter); 744 len = sizeof(*vvfl_v2) + 745 ((count - 1) * 746 sizeof(struct virtchnl_vlan_filter)); 747 more = true; 748 } 749 750 vvfl_v2 = kzalloc(len, GFP_ATOMIC); 751 if (!vvfl_v2) { 752 spin_unlock_bh(&adapter->mac_vlan_list_lock); 753 return; 754 } 755 756 vvfl_v2->vport_id = adapter->vsi_res->vsi_id; 757 vvfl_v2->num_elements = count; 758 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 759 if (f->add) { 760 struct virtchnl_vlan_supported_caps *filtering_support = 761 &adapter->vlan_v2_caps.filtering.filtering_support; 762 struct virtchnl_vlan *vlan; 763 764 if (i == count) 765 break; 766 767 /* give priority over outer if it's enabled */ 768 if (filtering_support->outer) 769 vlan = &vvfl_v2->filters[i].outer; 770 else 771 vlan = &vvfl_v2->filters[i].inner; 772 773 vlan->tci = f->vlan.vid; 774 vlan->tpid = f->vlan.tpid; 775 776 i++; 777 f->add = false; 778 f->is_new_vlan = true; 779 } 780 } 781 782 if (!more) 783 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER; 784 785 spin_unlock_bh(&adapter->mac_vlan_list_lock); 786 787 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2, 788 (u8 *)vvfl_v2, len); 789 kfree(vvfl_v2); 790 } 791 } 792 793 /** 794 * iavf_del_vlans 795 * @adapter: adapter structure 796 * 797 * Request that the PF remove one or more VLAN filters from our VSI. 798 **/ 799 void iavf_del_vlans(struct iavf_adapter *adapter) 800 { 801 struct iavf_vlan_filter *f, *ftmp; 802 int len, i = 0, count = 0; 803 bool more = false; 804 805 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 806 /* bail because we already have a command pending */ 807 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", 808 adapter->current_op); 809 return; 810 } 811 812 spin_lock_bh(&adapter->mac_vlan_list_lock); 813 814 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 815 /* since VLAN capabilities are not allowed, we dont want to send 816 * a VLAN delete request because it will most likely fail and 817 * create unnecessary errors/noise, so just free the VLAN 818 * filters marked for removal to enable bailing out before 819 * sending a virtchnl message 820 */ 821 if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) { 822 list_del(&f->list); 823 kfree(f); 824 } else if (f->remove) { 825 count++; 826 } 827 } 828 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) { 829 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 830 spin_unlock_bh(&adapter->mac_vlan_list_lock); 831 return; 832 } 833 834 if (VLAN_ALLOWED(adapter)) { 835 struct virtchnl_vlan_filter_list *vvfl; 836 837 adapter->current_op = VIRTCHNL_OP_DEL_VLAN; 838 839 len = sizeof(*vvfl) + (count * sizeof(u16)); 840 if (len > IAVF_MAX_AQ_BUF_SIZE) { 841 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n"); 842 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) / 843 sizeof(u16); 844 len = sizeof(*vvfl) + (count * sizeof(u16)); 845 more = true; 846 } 847 vvfl = kzalloc(len, GFP_ATOMIC); 848 if (!vvfl) { 849 spin_unlock_bh(&adapter->mac_vlan_list_lock); 850 return; 851 } 852 853 vvfl->vsi_id = adapter->vsi_res->vsi_id; 854 vvfl->num_elements = count; 855 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 856 if (f->remove) { 857 vvfl->vlan_id[i] = f->vlan.vid; 858 i++; 859 list_del(&f->list); 860 kfree(f); 861 if (i == count) 862 break; 863 } 864 } 865 866 if (!more) 867 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 868 869 spin_unlock_bh(&adapter->mac_vlan_list_lock); 870 871 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); 872 kfree(vvfl); 873 } else { 874 struct virtchnl_vlan_filter_list_v2 *vvfl_v2; 875 876 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2; 877 878 len = sizeof(*vvfl_v2) + 879 ((count - 1) * sizeof(struct virtchnl_vlan_filter)); 880 if (len > IAVF_MAX_AQ_BUF_SIZE) { 881 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 882 count = (IAVF_MAX_AQ_BUF_SIZE - 883 sizeof(*vvfl_v2)) / 884 sizeof(struct virtchnl_vlan_filter); 885 len = sizeof(*vvfl_v2) + 886 ((count - 1) * 887 sizeof(struct virtchnl_vlan_filter)); 888 more = true; 889 } 890 891 vvfl_v2 = kzalloc(len, GFP_ATOMIC); 892 if (!vvfl_v2) { 893 spin_unlock_bh(&adapter->mac_vlan_list_lock); 894 return; 895 } 896 897 vvfl_v2->vport_id = adapter->vsi_res->vsi_id; 898 vvfl_v2->num_elements = count; 899 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 900 if (f->remove) { 901 struct virtchnl_vlan_supported_caps *filtering_support = 902 &adapter->vlan_v2_caps.filtering.filtering_support; 903 struct virtchnl_vlan *vlan; 904 905 /* give priority over outer if it's enabled */ 906 if (filtering_support->outer) 907 vlan = &vvfl_v2->filters[i].outer; 908 else 909 vlan = &vvfl_v2->filters[i].inner; 910 911 vlan->tci = f->vlan.vid; 912 vlan->tpid = f->vlan.tpid; 913 914 list_del(&f->list); 915 kfree(f); 916 i++; 917 if (i == count) 918 break; 919 } 920 } 921 922 if (!more) 923 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER; 924 925 spin_unlock_bh(&adapter->mac_vlan_list_lock); 926 927 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2, 928 (u8 *)vvfl_v2, len); 929 kfree(vvfl_v2); 930 } 931 } 932 933 /** 934 * iavf_set_promiscuous 935 * @adapter: adapter structure 936 * @flags: bitmask to control unicast/multicast promiscuous. 937 * 938 * Request that the PF enable promiscuous mode for our VSI. 939 **/ 940 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags) 941 { 942 struct virtchnl_promisc_info vpi; 943 int promisc_all; 944 945 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 946 /* bail because we already have a command pending */ 947 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", 948 adapter->current_op); 949 return; 950 } 951 952 promisc_all = FLAG_VF_UNICAST_PROMISC | 953 FLAG_VF_MULTICAST_PROMISC; 954 if ((flags & promisc_all) == promisc_all) { 955 adapter->flags |= IAVF_FLAG_PROMISC_ON; 956 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC; 957 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n"); 958 } 959 960 if (flags & FLAG_VF_MULTICAST_PROMISC) { 961 adapter->flags |= IAVF_FLAG_ALLMULTI_ON; 962 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI; 963 dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n", 964 adapter->netdev->name); 965 } 966 967 if (!flags) { 968 if (adapter->flags & IAVF_FLAG_PROMISC_ON) { 969 adapter->flags &= ~IAVF_FLAG_PROMISC_ON; 970 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC; 971 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n"); 972 } 973 974 if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) { 975 adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON; 976 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI; 977 dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n", 978 adapter->netdev->name); 979 } 980 } 981 982 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; 983 vpi.vsi_id = adapter->vsi_res->vsi_id; 984 vpi.flags = flags; 985 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 986 (u8 *)&vpi, sizeof(vpi)); 987 } 988 989 /** 990 * iavf_request_stats 991 * @adapter: adapter structure 992 * 993 * Request VSI statistics from PF. 994 **/ 995 void iavf_request_stats(struct iavf_adapter *adapter) 996 { 997 struct virtchnl_queue_select vqs; 998 999 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1000 /* no error message, this isn't crucial */ 1001 return; 1002 } 1003 1004 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS; 1005 adapter->current_op = VIRTCHNL_OP_GET_STATS; 1006 vqs.vsi_id = adapter->vsi_res->vsi_id; 1007 /* queue maps are ignored for this message - only the vsi is used */ 1008 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs, 1009 sizeof(vqs))) 1010 /* if the request failed, don't lock out others */ 1011 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1012 } 1013 1014 /** 1015 * iavf_get_hena 1016 * @adapter: adapter structure 1017 * 1018 * Request hash enable capabilities from PF 1019 **/ 1020 void iavf_get_hena(struct iavf_adapter *adapter) 1021 { 1022 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1023 /* bail because we already have a command pending */ 1024 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n", 1025 adapter->current_op); 1026 return; 1027 } 1028 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS; 1029 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA; 1030 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0); 1031 } 1032 1033 /** 1034 * iavf_set_hena 1035 * @adapter: adapter structure 1036 * 1037 * Request the PF to set our RSS hash capabilities 1038 **/ 1039 void iavf_set_hena(struct iavf_adapter *adapter) 1040 { 1041 struct virtchnl_rss_hena vrh; 1042 1043 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1044 /* bail because we already have a command pending */ 1045 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n", 1046 adapter->current_op); 1047 return; 1048 } 1049 vrh.hena = adapter->hena; 1050 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA; 1051 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA; 1052 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh, 1053 sizeof(vrh)); 1054 } 1055 1056 /** 1057 * iavf_set_rss_key 1058 * @adapter: adapter structure 1059 * 1060 * Request the PF to set our RSS hash key 1061 **/ 1062 void iavf_set_rss_key(struct iavf_adapter *adapter) 1063 { 1064 struct virtchnl_rss_key *vrk; 1065 int len; 1066 1067 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1068 /* bail because we already have a command pending */ 1069 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n", 1070 adapter->current_op); 1071 return; 1072 } 1073 len = sizeof(struct virtchnl_rss_key) + 1074 (adapter->rss_key_size * sizeof(u8)) - 1; 1075 vrk = kzalloc(len, GFP_KERNEL); 1076 if (!vrk) 1077 return; 1078 vrk->vsi_id = adapter->vsi.id; 1079 vrk->key_len = adapter->rss_key_size; 1080 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size); 1081 1082 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY; 1083 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY; 1084 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len); 1085 kfree(vrk); 1086 } 1087 1088 /** 1089 * iavf_set_rss_lut 1090 * @adapter: adapter structure 1091 * 1092 * Request the PF to set our RSS lookup table 1093 **/ 1094 void iavf_set_rss_lut(struct iavf_adapter *adapter) 1095 { 1096 struct virtchnl_rss_lut *vrl; 1097 int len; 1098 1099 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1100 /* bail because we already have a command pending */ 1101 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n", 1102 adapter->current_op); 1103 return; 1104 } 1105 len = sizeof(struct virtchnl_rss_lut) + 1106 (adapter->rss_lut_size * sizeof(u8)) - 1; 1107 vrl = kzalloc(len, GFP_KERNEL); 1108 if (!vrl) 1109 return; 1110 vrl->vsi_id = adapter->vsi.id; 1111 vrl->lut_entries = adapter->rss_lut_size; 1112 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size); 1113 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT; 1114 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT; 1115 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len); 1116 kfree(vrl); 1117 } 1118 1119 /** 1120 * iavf_enable_vlan_stripping 1121 * @adapter: adapter structure 1122 * 1123 * Request VLAN header stripping to be enabled 1124 **/ 1125 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter) 1126 { 1127 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1128 /* bail because we already have a command pending */ 1129 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n", 1130 adapter->current_op); 1131 return; 1132 } 1133 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING; 1134 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; 1135 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0); 1136 } 1137 1138 /** 1139 * iavf_disable_vlan_stripping 1140 * @adapter: adapter structure 1141 * 1142 * Request VLAN header stripping to be disabled 1143 **/ 1144 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter) 1145 { 1146 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1147 /* bail because we already have a command pending */ 1148 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n", 1149 adapter->current_op); 1150 return; 1151 } 1152 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING; 1153 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; 1154 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0); 1155 } 1156 1157 /** 1158 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype 1159 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.) 1160 */ 1161 static u32 iavf_tpid_to_vc_ethertype(u16 tpid) 1162 { 1163 switch (tpid) { 1164 case ETH_P_8021Q: 1165 return VIRTCHNL_VLAN_ETHERTYPE_8100; 1166 case ETH_P_8021AD: 1167 return VIRTCHNL_VLAN_ETHERTYPE_88A8; 1168 } 1169 1170 return 0; 1171 } 1172 1173 /** 1174 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message 1175 * @adapter: adapter structure 1176 * @msg: message structure used for updating offloads over virtchnl to update 1177 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.) 1178 * @offload_op: opcode used to determine which support structure to check 1179 */ 1180 static int 1181 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter, 1182 struct virtchnl_vlan_setting *msg, u16 tpid, 1183 enum virtchnl_ops offload_op) 1184 { 1185 struct virtchnl_vlan_supported_caps *offload_support; 1186 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid); 1187 1188 /* reference the correct offload support structure */ 1189 switch (offload_op) { 1190 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2: 1191 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2: 1192 offload_support = 1193 &adapter->vlan_v2_caps.offloads.stripping_support; 1194 break; 1195 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2: 1196 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2: 1197 offload_support = 1198 &adapter->vlan_v2_caps.offloads.insertion_support; 1199 break; 1200 default: 1201 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n", 1202 offload_op); 1203 return -EINVAL; 1204 } 1205 1206 /* make sure ethertype is supported */ 1207 if (offload_support->outer & vc_ethertype && 1208 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) { 1209 msg->outer_ethertype_setting = vc_ethertype; 1210 } else if (offload_support->inner & vc_ethertype && 1211 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) { 1212 msg->inner_ethertype_setting = vc_ethertype; 1213 } else { 1214 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n", 1215 offload_op, tpid); 1216 return -EINVAL; 1217 } 1218 1219 return 0; 1220 } 1221 1222 /** 1223 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request 1224 * @adapter: adapter structure 1225 * @tpid: VLAN TPID 1226 * @offload_op: opcode used to determine which AQ required bit to clear 1227 */ 1228 static void 1229 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid, 1230 enum virtchnl_ops offload_op) 1231 { 1232 switch (offload_op) { 1233 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2: 1234 if (tpid == ETH_P_8021Q) 1235 adapter->aq_required &= 1236 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING; 1237 else if (tpid == ETH_P_8021AD) 1238 adapter->aq_required &= 1239 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING; 1240 break; 1241 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2: 1242 if (tpid == ETH_P_8021Q) 1243 adapter->aq_required &= 1244 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING; 1245 else if (tpid == ETH_P_8021AD) 1246 adapter->aq_required &= 1247 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING; 1248 break; 1249 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2: 1250 if (tpid == ETH_P_8021Q) 1251 adapter->aq_required &= 1252 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION; 1253 else if (tpid == ETH_P_8021AD) 1254 adapter->aq_required &= 1255 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION; 1256 break; 1257 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2: 1258 if (tpid == ETH_P_8021Q) 1259 adapter->aq_required &= 1260 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION; 1261 else if (tpid == ETH_P_8021AD) 1262 adapter->aq_required &= 1263 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION; 1264 break; 1265 default: 1266 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n", 1267 offload_op); 1268 } 1269 } 1270 1271 /** 1272 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl 1273 * @adapter: adapter structure 1274 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8) 1275 * @offload_op: offload_op used to make the request over virtchnl 1276 */ 1277 static void 1278 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid, 1279 enum virtchnl_ops offload_op) 1280 { 1281 struct virtchnl_vlan_setting *msg; 1282 int len = sizeof(*msg); 1283 1284 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1285 /* bail because we already have a command pending */ 1286 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n", 1287 offload_op, adapter->current_op); 1288 return; 1289 } 1290 1291 adapter->current_op = offload_op; 1292 1293 msg = kzalloc(len, GFP_KERNEL); 1294 if (!msg) 1295 return; 1296 1297 msg->vport_id = adapter->vsi_res->vsi_id; 1298 1299 /* always clear to prevent unsupported and endless requests */ 1300 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op); 1301 1302 /* only send valid offload requests */ 1303 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op)) 1304 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len); 1305 else 1306 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1307 1308 kfree(msg); 1309 } 1310 1311 /** 1312 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping 1313 * @adapter: adapter structure 1314 * @tpid: VLAN TPID used to enable VLAN stripping 1315 */ 1316 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid) 1317 { 1318 iavf_send_vlan_offload_v2(adapter, tpid, 1319 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2); 1320 } 1321 1322 /** 1323 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping 1324 * @adapter: adapter structure 1325 * @tpid: VLAN TPID used to disable VLAN stripping 1326 */ 1327 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid) 1328 { 1329 iavf_send_vlan_offload_v2(adapter, tpid, 1330 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2); 1331 } 1332 1333 /** 1334 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion 1335 * @adapter: adapter structure 1336 * @tpid: VLAN TPID used to enable VLAN insertion 1337 */ 1338 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid) 1339 { 1340 iavf_send_vlan_offload_v2(adapter, tpid, 1341 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2); 1342 } 1343 1344 /** 1345 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion 1346 * @adapter: adapter structure 1347 * @tpid: VLAN TPID used to disable VLAN insertion 1348 */ 1349 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid) 1350 { 1351 iavf_send_vlan_offload_v2(adapter, tpid, 1352 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2); 1353 } 1354 1355 #define IAVF_MAX_SPEED_STRLEN 13 1356 1357 /** 1358 * iavf_print_link_message - print link up or down 1359 * @adapter: adapter structure 1360 * 1361 * Log a message telling the world of our wonderous link status 1362 */ 1363 static void iavf_print_link_message(struct iavf_adapter *adapter) 1364 { 1365 struct net_device *netdev = adapter->netdev; 1366 int link_speed_mbps; 1367 char *speed; 1368 1369 if (!adapter->link_up) { 1370 netdev_info(netdev, "NIC Link is Down\n"); 1371 return; 1372 } 1373 1374 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL); 1375 if (!speed) 1376 return; 1377 1378 if (ADV_LINK_SUPPORT(adapter)) { 1379 link_speed_mbps = adapter->link_speed_mbps; 1380 goto print_link_msg; 1381 } 1382 1383 switch (adapter->link_speed) { 1384 case VIRTCHNL_LINK_SPEED_40GB: 1385 link_speed_mbps = SPEED_40000; 1386 break; 1387 case VIRTCHNL_LINK_SPEED_25GB: 1388 link_speed_mbps = SPEED_25000; 1389 break; 1390 case VIRTCHNL_LINK_SPEED_20GB: 1391 link_speed_mbps = SPEED_20000; 1392 break; 1393 case VIRTCHNL_LINK_SPEED_10GB: 1394 link_speed_mbps = SPEED_10000; 1395 break; 1396 case VIRTCHNL_LINK_SPEED_5GB: 1397 link_speed_mbps = SPEED_5000; 1398 break; 1399 case VIRTCHNL_LINK_SPEED_2_5GB: 1400 link_speed_mbps = SPEED_2500; 1401 break; 1402 case VIRTCHNL_LINK_SPEED_1GB: 1403 link_speed_mbps = SPEED_1000; 1404 break; 1405 case VIRTCHNL_LINK_SPEED_100MB: 1406 link_speed_mbps = SPEED_100; 1407 break; 1408 default: 1409 link_speed_mbps = SPEED_UNKNOWN; 1410 break; 1411 } 1412 1413 print_link_msg: 1414 if (link_speed_mbps > SPEED_1000) { 1415 if (link_speed_mbps == SPEED_2500) 1416 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps"); 1417 else 1418 /* convert to Gbps inline */ 1419 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s", 1420 link_speed_mbps / 1000, "Gbps"); 1421 } else if (link_speed_mbps == SPEED_UNKNOWN) { 1422 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps"); 1423 } else { 1424 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s", 1425 link_speed_mbps, "Mbps"); 1426 } 1427 1428 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed); 1429 kfree(speed); 1430 } 1431 1432 /** 1433 * iavf_get_vpe_link_status 1434 * @adapter: adapter structure 1435 * @vpe: virtchnl_pf_event structure 1436 * 1437 * Helper function for determining the link status 1438 **/ 1439 static bool 1440 iavf_get_vpe_link_status(struct iavf_adapter *adapter, 1441 struct virtchnl_pf_event *vpe) 1442 { 1443 if (ADV_LINK_SUPPORT(adapter)) 1444 return vpe->event_data.link_event_adv.link_status; 1445 else 1446 return vpe->event_data.link_event.link_status; 1447 } 1448 1449 /** 1450 * iavf_set_adapter_link_speed_from_vpe 1451 * @adapter: adapter structure for which we are setting the link speed 1452 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting 1453 * 1454 * Helper function for setting iavf_adapter link speed 1455 **/ 1456 static void 1457 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter, 1458 struct virtchnl_pf_event *vpe) 1459 { 1460 if (ADV_LINK_SUPPORT(adapter)) 1461 adapter->link_speed_mbps = 1462 vpe->event_data.link_event_adv.link_speed; 1463 else 1464 adapter->link_speed = vpe->event_data.link_event.link_speed; 1465 } 1466 1467 /** 1468 * iavf_enable_channels 1469 * @adapter: adapter structure 1470 * 1471 * Request that the PF enable channels as specified by 1472 * the user via tc tool. 1473 **/ 1474 void iavf_enable_channels(struct iavf_adapter *adapter) 1475 { 1476 struct virtchnl_tc_info *vti = NULL; 1477 size_t len; 1478 int i; 1479 1480 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1481 /* bail because we already have a command pending */ 1482 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 1483 adapter->current_op); 1484 return; 1485 } 1486 1487 len = struct_size(vti, list, adapter->num_tc - 1); 1488 vti = kzalloc(len, GFP_KERNEL); 1489 if (!vti) 1490 return; 1491 vti->num_tc = adapter->num_tc; 1492 for (i = 0; i < vti->num_tc; i++) { 1493 vti->list[i].count = adapter->ch_config.ch_info[i].count; 1494 vti->list[i].offset = adapter->ch_config.ch_info[i].offset; 1495 vti->list[i].pad = 0; 1496 vti->list[i].max_tx_rate = 1497 adapter->ch_config.ch_info[i].max_tx_rate; 1498 } 1499 1500 adapter->ch_config.state = __IAVF_TC_RUNNING; 1501 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 1502 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS; 1503 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS; 1504 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len); 1505 kfree(vti); 1506 } 1507 1508 /** 1509 * iavf_disable_channels 1510 * @adapter: adapter structure 1511 * 1512 * Request that the PF disable channels that are configured 1513 **/ 1514 void iavf_disable_channels(struct iavf_adapter *adapter) 1515 { 1516 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1517 /* bail because we already have a command pending */ 1518 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n", 1519 adapter->current_op); 1520 return; 1521 } 1522 1523 adapter->ch_config.state = __IAVF_TC_INVALID; 1524 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; 1525 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS; 1526 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS; 1527 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0); 1528 } 1529 1530 /** 1531 * iavf_print_cloud_filter 1532 * @adapter: adapter structure 1533 * @f: cloud filter to print 1534 * 1535 * Print the cloud filter 1536 **/ 1537 static void iavf_print_cloud_filter(struct iavf_adapter *adapter, 1538 struct virtchnl_filter *f) 1539 { 1540 switch (f->flow_type) { 1541 case VIRTCHNL_TCP_V4_FLOW: 1542 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", 1543 &f->data.tcp_spec.dst_mac, 1544 &f->data.tcp_spec.src_mac, 1545 ntohs(f->data.tcp_spec.vlan_id), 1546 &f->data.tcp_spec.dst_ip[0], 1547 &f->data.tcp_spec.src_ip[0], 1548 ntohs(f->data.tcp_spec.dst_port), 1549 ntohs(f->data.tcp_spec.src_port)); 1550 break; 1551 case VIRTCHNL_TCP_V6_FLOW: 1552 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", 1553 &f->data.tcp_spec.dst_mac, 1554 &f->data.tcp_spec.src_mac, 1555 ntohs(f->data.tcp_spec.vlan_id), 1556 &f->data.tcp_spec.dst_ip, 1557 &f->data.tcp_spec.src_ip, 1558 ntohs(f->data.tcp_spec.dst_port), 1559 ntohs(f->data.tcp_spec.src_port)); 1560 break; 1561 } 1562 } 1563 1564 /** 1565 * iavf_add_cloud_filter 1566 * @adapter: adapter structure 1567 * 1568 * Request that the PF add cloud filters as specified 1569 * by the user via tc tool. 1570 **/ 1571 void iavf_add_cloud_filter(struct iavf_adapter *adapter) 1572 { 1573 struct iavf_cloud_filter *cf; 1574 struct virtchnl_filter *f; 1575 int len = 0, count = 0; 1576 1577 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1578 /* bail because we already have a command pending */ 1579 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n", 1580 adapter->current_op); 1581 return; 1582 } 1583 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1584 if (cf->add) { 1585 count++; 1586 break; 1587 } 1588 } 1589 if (!count) { 1590 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER; 1591 return; 1592 } 1593 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER; 1594 1595 len = sizeof(struct virtchnl_filter); 1596 f = kzalloc(len, GFP_KERNEL); 1597 if (!f) 1598 return; 1599 1600 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1601 if (cf->add) { 1602 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1603 cf->add = false; 1604 cf->state = __IAVF_CF_ADD_PENDING; 1605 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER, 1606 (u8 *)f, len); 1607 } 1608 } 1609 kfree(f); 1610 } 1611 1612 /** 1613 * iavf_del_cloud_filter 1614 * @adapter: adapter structure 1615 * 1616 * Request that the PF delete cloud filters as specified 1617 * by the user via tc tool. 1618 **/ 1619 void iavf_del_cloud_filter(struct iavf_adapter *adapter) 1620 { 1621 struct iavf_cloud_filter *cf, *cftmp; 1622 struct virtchnl_filter *f; 1623 int len = 0, count = 0; 1624 1625 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1626 /* bail because we already have a command pending */ 1627 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n", 1628 adapter->current_op); 1629 return; 1630 } 1631 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 1632 if (cf->del) { 1633 count++; 1634 break; 1635 } 1636 } 1637 if (!count) { 1638 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER; 1639 return; 1640 } 1641 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER; 1642 1643 len = sizeof(struct virtchnl_filter); 1644 f = kzalloc(len, GFP_KERNEL); 1645 if (!f) 1646 return; 1647 1648 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) { 1649 if (cf->del) { 1650 memcpy(f, &cf->f, sizeof(struct virtchnl_filter)); 1651 cf->del = false; 1652 cf->state = __IAVF_CF_DEL_PENDING; 1653 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER, 1654 (u8 *)f, len); 1655 } 1656 } 1657 kfree(f); 1658 } 1659 1660 /** 1661 * iavf_add_fdir_filter 1662 * @adapter: the VF adapter structure 1663 * 1664 * Request that the PF add Flow Director filters as specified 1665 * by the user via ethtool. 1666 **/ 1667 void iavf_add_fdir_filter(struct iavf_adapter *adapter) 1668 { 1669 struct iavf_fdir_fltr *fdir; 1670 struct virtchnl_fdir_add *f; 1671 bool process_fltr = false; 1672 int len; 1673 1674 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1675 /* bail because we already have a command pending */ 1676 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n", 1677 adapter->current_op); 1678 return; 1679 } 1680 1681 len = sizeof(struct virtchnl_fdir_add); 1682 f = kzalloc(len, GFP_KERNEL); 1683 if (!f) 1684 return; 1685 1686 spin_lock_bh(&adapter->fdir_fltr_lock); 1687 list_for_each_entry(fdir, &adapter->fdir_list_head, list) { 1688 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) { 1689 process_fltr = true; 1690 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING; 1691 memcpy(f, &fdir->vc_add_msg, len); 1692 break; 1693 } 1694 } 1695 spin_unlock_bh(&adapter->fdir_fltr_lock); 1696 1697 if (!process_fltr) { 1698 /* prevent iavf_add_fdir_filter() from being called when there 1699 * are no filters to add 1700 */ 1701 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER; 1702 kfree(f); 1703 return; 1704 } 1705 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER; 1706 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len); 1707 kfree(f); 1708 } 1709 1710 /** 1711 * iavf_del_fdir_filter 1712 * @adapter: the VF adapter structure 1713 * 1714 * Request that the PF delete Flow Director filters as specified 1715 * by the user via ethtool. 1716 **/ 1717 void iavf_del_fdir_filter(struct iavf_adapter *adapter) 1718 { 1719 struct iavf_fdir_fltr *fdir; 1720 struct virtchnl_fdir_del f; 1721 bool process_fltr = false; 1722 int len; 1723 1724 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1725 /* bail because we already have a command pending */ 1726 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n", 1727 adapter->current_op); 1728 return; 1729 } 1730 1731 len = sizeof(struct virtchnl_fdir_del); 1732 1733 spin_lock_bh(&adapter->fdir_fltr_lock); 1734 list_for_each_entry(fdir, &adapter->fdir_list_head, list) { 1735 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) { 1736 process_fltr = true; 1737 memset(&f, 0, len); 1738 f.vsi_id = fdir->vc_add_msg.vsi_id; 1739 f.flow_id = fdir->flow_id; 1740 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING; 1741 break; 1742 } 1743 } 1744 spin_unlock_bh(&adapter->fdir_fltr_lock); 1745 1746 if (!process_fltr) { 1747 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER; 1748 return; 1749 } 1750 1751 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER; 1752 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len); 1753 } 1754 1755 /** 1756 * iavf_add_adv_rss_cfg 1757 * @adapter: the VF adapter structure 1758 * 1759 * Request that the PF add RSS configuration as specified 1760 * by the user via ethtool. 1761 **/ 1762 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter) 1763 { 1764 struct virtchnl_rss_cfg *rss_cfg; 1765 struct iavf_adv_rss *rss; 1766 bool process_rss = false; 1767 int len; 1768 1769 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1770 /* bail because we already have a command pending */ 1771 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n", 1772 adapter->current_op); 1773 return; 1774 } 1775 1776 len = sizeof(struct virtchnl_rss_cfg); 1777 rss_cfg = kzalloc(len, GFP_KERNEL); 1778 if (!rss_cfg) 1779 return; 1780 1781 spin_lock_bh(&adapter->adv_rss_lock); 1782 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 1783 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) { 1784 process_rss = true; 1785 rss->state = IAVF_ADV_RSS_ADD_PENDING; 1786 memcpy(rss_cfg, &rss->cfg_msg, len); 1787 iavf_print_adv_rss_cfg(adapter, rss, 1788 "Input set change for", 1789 "is pending"); 1790 break; 1791 } 1792 } 1793 spin_unlock_bh(&adapter->adv_rss_lock); 1794 1795 if (process_rss) { 1796 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG; 1797 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG, 1798 (u8 *)rss_cfg, len); 1799 } else { 1800 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG; 1801 } 1802 1803 kfree(rss_cfg); 1804 } 1805 1806 /** 1807 * iavf_del_adv_rss_cfg 1808 * @adapter: the VF adapter structure 1809 * 1810 * Request that the PF delete RSS configuration as specified 1811 * by the user via ethtool. 1812 **/ 1813 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter) 1814 { 1815 struct virtchnl_rss_cfg *rss_cfg; 1816 struct iavf_adv_rss *rss; 1817 bool process_rss = false; 1818 int len; 1819 1820 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 1821 /* bail because we already have a command pending */ 1822 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n", 1823 adapter->current_op); 1824 return; 1825 } 1826 1827 len = sizeof(struct virtchnl_rss_cfg); 1828 rss_cfg = kzalloc(len, GFP_KERNEL); 1829 if (!rss_cfg) 1830 return; 1831 1832 spin_lock_bh(&adapter->adv_rss_lock); 1833 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 1834 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) { 1835 process_rss = true; 1836 rss->state = IAVF_ADV_RSS_DEL_PENDING; 1837 memcpy(rss_cfg, &rss->cfg_msg, len); 1838 break; 1839 } 1840 } 1841 spin_unlock_bh(&adapter->adv_rss_lock); 1842 1843 if (process_rss) { 1844 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG; 1845 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG, 1846 (u8 *)rss_cfg, len); 1847 } else { 1848 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG; 1849 } 1850 1851 kfree(rss_cfg); 1852 } 1853 1854 /** 1855 * iavf_request_reset 1856 * @adapter: adapter structure 1857 * 1858 * Request that the PF reset this VF. No response is expected. 1859 **/ 1860 int iavf_request_reset(struct iavf_adapter *adapter) 1861 { 1862 int err; 1863 /* Don't check CURRENT_OP - this is always higher priority */ 1864 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0); 1865 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1866 return err; 1867 } 1868 1869 /** 1870 * iavf_netdev_features_vlan_strip_set - update vlan strip status 1871 * @netdev: ptr to netdev being adjusted 1872 * @enable: enable or disable vlan strip 1873 * 1874 * Helper function to change vlan strip status in netdev->features. 1875 */ 1876 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev, 1877 const bool enable) 1878 { 1879 if (enable) 1880 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX; 1881 else 1882 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX; 1883 } 1884 1885 /** 1886 * iavf_virtchnl_completion 1887 * @adapter: adapter structure 1888 * @v_opcode: opcode sent by PF 1889 * @v_retval: retval sent by PF 1890 * @msg: message sent by PF 1891 * @msglen: message length 1892 * 1893 * Asynchronous completion function for admin queue messages. Rather than busy 1894 * wait, we fire off our requests and assume that no errors will be returned. 1895 * This function handles the reply messages. 1896 **/ 1897 void iavf_virtchnl_completion(struct iavf_adapter *adapter, 1898 enum virtchnl_ops v_opcode, 1899 enum iavf_status v_retval, u8 *msg, u16 msglen) 1900 { 1901 struct net_device *netdev = adapter->netdev; 1902 1903 if (v_opcode == VIRTCHNL_OP_EVENT) { 1904 struct virtchnl_pf_event *vpe = 1905 (struct virtchnl_pf_event *)msg; 1906 bool link_up = iavf_get_vpe_link_status(adapter, vpe); 1907 1908 switch (vpe->event) { 1909 case VIRTCHNL_EVENT_LINK_CHANGE: 1910 iavf_set_adapter_link_speed_from_vpe(adapter, vpe); 1911 1912 /* we've already got the right link status, bail */ 1913 if (adapter->link_up == link_up) 1914 break; 1915 1916 if (link_up) { 1917 /* If we get link up message and start queues 1918 * before our queues are configured it will 1919 * trigger a TX hang. In that case, just ignore 1920 * the link status message,we'll get another one 1921 * after we enable queues and actually prepared 1922 * to send traffic. 1923 */ 1924 if (adapter->state != __IAVF_RUNNING) 1925 break; 1926 1927 /* For ADq enabled VF, we reconfigure VSIs and 1928 * re-allocate queues. Hence wait till all 1929 * queues are enabled. 1930 */ 1931 if (adapter->flags & 1932 IAVF_FLAG_QUEUES_DISABLED) 1933 break; 1934 } 1935 1936 adapter->link_up = link_up; 1937 if (link_up) { 1938 netif_tx_start_all_queues(netdev); 1939 netif_carrier_on(netdev); 1940 } else { 1941 netif_tx_stop_all_queues(netdev); 1942 netif_carrier_off(netdev); 1943 } 1944 iavf_print_link_message(adapter); 1945 break; 1946 case VIRTCHNL_EVENT_RESET_IMPENDING: 1947 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n"); 1948 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) { 1949 adapter->flags |= IAVF_FLAG_RESET_PENDING; 1950 dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); 1951 queue_work(iavf_wq, &adapter->reset_task); 1952 } 1953 break; 1954 default: 1955 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", 1956 vpe->event); 1957 break; 1958 } 1959 return; 1960 } 1961 if (v_retval) { 1962 switch (v_opcode) { 1963 case VIRTCHNL_OP_ADD_VLAN: 1964 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", 1965 iavf_stat_str(&adapter->hw, v_retval)); 1966 break; 1967 case VIRTCHNL_OP_ADD_ETH_ADDR: 1968 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", 1969 iavf_stat_str(&adapter->hw, v_retval)); 1970 iavf_mac_add_reject(adapter); 1971 /* restore administratively set MAC address */ 1972 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 1973 break; 1974 case VIRTCHNL_OP_DEL_VLAN: 1975 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", 1976 iavf_stat_str(&adapter->hw, v_retval)); 1977 break; 1978 case VIRTCHNL_OP_DEL_ETH_ADDR: 1979 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", 1980 iavf_stat_str(&adapter->hw, v_retval)); 1981 break; 1982 case VIRTCHNL_OP_ENABLE_CHANNELS: 1983 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n", 1984 iavf_stat_str(&adapter->hw, v_retval)); 1985 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1986 adapter->ch_config.state = __IAVF_TC_INVALID; 1987 netdev_reset_tc(netdev); 1988 netif_tx_start_all_queues(netdev); 1989 break; 1990 case VIRTCHNL_OP_DISABLE_CHANNELS: 1991 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n", 1992 iavf_stat_str(&adapter->hw, v_retval)); 1993 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 1994 adapter->ch_config.state = __IAVF_TC_RUNNING; 1995 netif_tx_start_all_queues(netdev); 1996 break; 1997 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 1998 struct iavf_cloud_filter *cf, *cftmp; 1999 2000 list_for_each_entry_safe(cf, cftmp, 2001 &adapter->cloud_filter_list, 2002 list) { 2003 if (cf->state == __IAVF_CF_ADD_PENDING) { 2004 cf->state = __IAVF_CF_INVALID; 2005 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n", 2006 iavf_stat_str(&adapter->hw, 2007 v_retval)); 2008 iavf_print_cloud_filter(adapter, 2009 &cf->f); 2010 list_del(&cf->list); 2011 kfree(cf); 2012 adapter->num_cloud_filters--; 2013 } 2014 } 2015 } 2016 break; 2017 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 2018 struct iavf_cloud_filter *cf; 2019 2020 list_for_each_entry(cf, &adapter->cloud_filter_list, 2021 list) { 2022 if (cf->state == __IAVF_CF_DEL_PENDING) { 2023 cf->state = __IAVF_CF_ACTIVE; 2024 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n", 2025 iavf_stat_str(&adapter->hw, 2026 v_retval)); 2027 iavf_print_cloud_filter(adapter, 2028 &cf->f); 2029 } 2030 } 2031 } 2032 break; 2033 case VIRTCHNL_OP_ADD_FDIR_FILTER: { 2034 struct iavf_fdir_fltr *fdir, *fdir_tmp; 2035 2036 spin_lock_bh(&adapter->fdir_fltr_lock); 2037 list_for_each_entry_safe(fdir, fdir_tmp, 2038 &adapter->fdir_list_head, 2039 list) { 2040 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) { 2041 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n", 2042 iavf_stat_str(&adapter->hw, 2043 v_retval)); 2044 iavf_print_fdir_fltr(adapter, fdir); 2045 if (msglen) 2046 dev_err(&adapter->pdev->dev, 2047 "%s\n", msg); 2048 list_del(&fdir->list); 2049 kfree(fdir); 2050 adapter->fdir_active_fltr--; 2051 } 2052 } 2053 spin_unlock_bh(&adapter->fdir_fltr_lock); 2054 } 2055 break; 2056 case VIRTCHNL_OP_DEL_FDIR_FILTER: { 2057 struct iavf_fdir_fltr *fdir; 2058 2059 spin_lock_bh(&adapter->fdir_fltr_lock); 2060 list_for_each_entry(fdir, &adapter->fdir_list_head, 2061 list) { 2062 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) { 2063 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 2064 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n", 2065 iavf_stat_str(&adapter->hw, 2066 v_retval)); 2067 iavf_print_fdir_fltr(adapter, fdir); 2068 } 2069 } 2070 spin_unlock_bh(&adapter->fdir_fltr_lock); 2071 } 2072 break; 2073 case VIRTCHNL_OP_ADD_RSS_CFG: { 2074 struct iavf_adv_rss *rss, *rss_tmp; 2075 2076 spin_lock_bh(&adapter->adv_rss_lock); 2077 list_for_each_entry_safe(rss, rss_tmp, 2078 &adapter->adv_rss_list_head, 2079 list) { 2080 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) { 2081 iavf_print_adv_rss_cfg(adapter, rss, 2082 "Failed to change the input set for", 2083 NULL); 2084 list_del(&rss->list); 2085 kfree(rss); 2086 } 2087 } 2088 spin_unlock_bh(&adapter->adv_rss_lock); 2089 } 2090 break; 2091 case VIRTCHNL_OP_DEL_RSS_CFG: { 2092 struct iavf_adv_rss *rss; 2093 2094 spin_lock_bh(&adapter->adv_rss_lock); 2095 list_for_each_entry(rss, &adapter->adv_rss_list_head, 2096 list) { 2097 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) { 2098 rss->state = IAVF_ADV_RSS_ACTIVE; 2099 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n", 2100 iavf_stat_str(&adapter->hw, 2101 v_retval)); 2102 } 2103 } 2104 spin_unlock_bh(&adapter->adv_rss_lock); 2105 } 2106 break; 2107 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 2108 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n"); 2109 /* Vlan stripping could not be enabled by ethtool. 2110 * Disable it in netdev->features. 2111 */ 2112 iavf_netdev_features_vlan_strip_set(netdev, false); 2113 break; 2114 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 2115 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n"); 2116 /* Vlan stripping could not be disabled by ethtool. 2117 * Enable it in netdev->features. 2118 */ 2119 iavf_netdev_features_vlan_strip_set(netdev, true); 2120 break; 2121 case VIRTCHNL_OP_ADD_VLAN_V2: 2122 iavf_vlan_add_reject(adapter); 2123 dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", 2124 iavf_stat_str(&adapter->hw, v_retval)); 2125 break; 2126 default: 2127 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", 2128 v_retval, iavf_stat_str(&adapter->hw, v_retval), 2129 v_opcode); 2130 } 2131 } 2132 switch (v_opcode) { 2133 case VIRTCHNL_OP_ADD_ETH_ADDR: 2134 if (!v_retval) 2135 iavf_mac_add_ok(adapter); 2136 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr)) 2137 eth_hw_addr_set(netdev, adapter->hw.mac.addr); 2138 break; 2139 case VIRTCHNL_OP_GET_STATS: { 2140 struct iavf_eth_stats *stats = 2141 (struct iavf_eth_stats *)msg; 2142 netdev->stats.rx_packets = stats->rx_unicast + 2143 stats->rx_multicast + 2144 stats->rx_broadcast; 2145 netdev->stats.tx_packets = stats->tx_unicast + 2146 stats->tx_multicast + 2147 stats->tx_broadcast; 2148 netdev->stats.rx_bytes = stats->rx_bytes; 2149 netdev->stats.tx_bytes = stats->tx_bytes; 2150 netdev->stats.tx_errors = stats->tx_errors; 2151 netdev->stats.rx_dropped = stats->rx_discards; 2152 netdev->stats.tx_dropped = stats->tx_discards; 2153 adapter->current_stats = *stats; 2154 } 2155 break; 2156 case VIRTCHNL_OP_GET_VF_RESOURCES: { 2157 u16 len = sizeof(struct virtchnl_vf_resource) + 2158 IAVF_MAX_VF_VSI * 2159 sizeof(struct virtchnl_vsi_resource); 2160 memcpy(adapter->vf_res, msg, min(msglen, len)); 2161 iavf_validate_num_queues(adapter); 2162 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res); 2163 if (is_zero_ether_addr(adapter->hw.mac.addr)) { 2164 /* restore current mac address */ 2165 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 2166 } else { 2167 /* refresh current mac address if changed */ 2168 eth_hw_addr_set(netdev, adapter->hw.mac.addr); 2169 ether_addr_copy(netdev->perm_addr, 2170 adapter->hw.mac.addr); 2171 } 2172 spin_lock_bh(&adapter->mac_vlan_list_lock); 2173 iavf_add_filter(adapter, adapter->hw.mac.addr); 2174 2175 if (VLAN_ALLOWED(adapter)) { 2176 if (!list_empty(&adapter->vlan_filter_list)) { 2177 struct iavf_vlan_filter *vlf; 2178 2179 /* re-add all VLAN filters over virtchnl */ 2180 list_for_each_entry(vlf, 2181 &adapter->vlan_filter_list, 2182 list) 2183 vlf->add = true; 2184 2185 adapter->aq_required |= 2186 IAVF_FLAG_AQ_ADD_VLAN_FILTER; 2187 } 2188 } 2189 2190 spin_unlock_bh(&adapter->mac_vlan_list_lock); 2191 2192 iavf_parse_vf_resource_msg(adapter); 2193 2194 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the 2195 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish 2196 * configuration 2197 */ 2198 if (VLAN_V2_ALLOWED(adapter)) 2199 break; 2200 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2 2201 * wasn't successfully negotiated with the PF 2202 */ 2203 } 2204 fallthrough; 2205 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: { 2206 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS) 2207 memcpy(&adapter->vlan_v2_caps, msg, 2208 min_t(u16, msglen, 2209 sizeof(adapter->vlan_v2_caps))); 2210 2211 iavf_process_config(adapter); 2212 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES; 2213 } 2214 break; 2215 case VIRTCHNL_OP_ENABLE_QUEUES: 2216 /* enable transmits */ 2217 iavf_irq_enable(adapter, true); 2218 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED; 2219 break; 2220 case VIRTCHNL_OP_DISABLE_QUEUES: 2221 iavf_free_all_tx_resources(adapter); 2222 iavf_free_all_rx_resources(adapter); 2223 if (adapter->state == __IAVF_DOWN_PENDING) { 2224 iavf_change_state(adapter, __IAVF_DOWN); 2225 wake_up(&adapter->down_waitqueue); 2226 } 2227 break; 2228 case VIRTCHNL_OP_VERSION: 2229 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 2230 /* Don't display an error if we get these out of sequence. 2231 * If the firmware needed to get kicked, we'll get these and 2232 * it's no problem. 2233 */ 2234 if (v_opcode != adapter->current_op) 2235 return; 2236 break; 2237 case VIRTCHNL_OP_IWARP: 2238 /* Gobble zero-length replies from the PF. They indicate that 2239 * a previous message was received OK, and the client doesn't 2240 * care about that. 2241 */ 2242 if (msglen && CLIENT_ENABLED(adapter)) 2243 iavf_notify_client_message(&adapter->vsi, msg, msglen); 2244 break; 2245 2246 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 2247 adapter->client_pending &= 2248 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP)); 2249 break; 2250 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: { 2251 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg; 2252 2253 if (msglen == sizeof(*vrh)) 2254 adapter->hena = vrh->hena; 2255 else 2256 dev_warn(&adapter->pdev->dev, 2257 "Invalid message %d from PF\n", v_opcode); 2258 } 2259 break; 2260 case VIRTCHNL_OP_REQUEST_QUEUES: { 2261 struct virtchnl_vf_res_request *vfres = 2262 (struct virtchnl_vf_res_request *)msg; 2263 2264 if (vfres->num_queue_pairs != adapter->num_req_queues) { 2265 dev_info(&adapter->pdev->dev, 2266 "Requested %d queues, PF can support %d\n", 2267 adapter->num_req_queues, 2268 vfres->num_queue_pairs); 2269 adapter->num_req_queues = 0; 2270 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; 2271 } 2272 } 2273 break; 2274 case VIRTCHNL_OP_ADD_CLOUD_FILTER: { 2275 struct iavf_cloud_filter *cf; 2276 2277 list_for_each_entry(cf, &adapter->cloud_filter_list, list) { 2278 if (cf->state == __IAVF_CF_ADD_PENDING) 2279 cf->state = __IAVF_CF_ACTIVE; 2280 } 2281 } 2282 break; 2283 case VIRTCHNL_OP_DEL_CLOUD_FILTER: { 2284 struct iavf_cloud_filter *cf, *cftmp; 2285 2286 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, 2287 list) { 2288 if (cf->state == __IAVF_CF_DEL_PENDING) { 2289 cf->state = __IAVF_CF_INVALID; 2290 list_del(&cf->list); 2291 kfree(cf); 2292 adapter->num_cloud_filters--; 2293 } 2294 } 2295 } 2296 break; 2297 case VIRTCHNL_OP_ADD_FDIR_FILTER: { 2298 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg; 2299 struct iavf_fdir_fltr *fdir, *fdir_tmp; 2300 2301 spin_lock_bh(&adapter->fdir_fltr_lock); 2302 list_for_each_entry_safe(fdir, fdir_tmp, 2303 &adapter->fdir_list_head, 2304 list) { 2305 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) { 2306 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) { 2307 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n", 2308 fdir->loc); 2309 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 2310 fdir->flow_id = add_fltr->flow_id; 2311 } else { 2312 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n", 2313 add_fltr->status); 2314 iavf_print_fdir_fltr(adapter, fdir); 2315 list_del(&fdir->list); 2316 kfree(fdir); 2317 adapter->fdir_active_fltr--; 2318 } 2319 } 2320 } 2321 spin_unlock_bh(&adapter->fdir_fltr_lock); 2322 } 2323 break; 2324 case VIRTCHNL_OP_DEL_FDIR_FILTER: { 2325 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg; 2326 struct iavf_fdir_fltr *fdir, *fdir_tmp; 2327 2328 spin_lock_bh(&adapter->fdir_fltr_lock); 2329 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head, 2330 list) { 2331 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) { 2332 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) { 2333 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n", 2334 fdir->loc); 2335 list_del(&fdir->list); 2336 kfree(fdir); 2337 adapter->fdir_active_fltr--; 2338 } else { 2339 fdir->state = IAVF_FDIR_FLTR_ACTIVE; 2340 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n", 2341 del_fltr->status); 2342 iavf_print_fdir_fltr(adapter, fdir); 2343 } 2344 } 2345 } 2346 spin_unlock_bh(&adapter->fdir_fltr_lock); 2347 } 2348 break; 2349 case VIRTCHNL_OP_ADD_RSS_CFG: { 2350 struct iavf_adv_rss *rss; 2351 2352 spin_lock_bh(&adapter->adv_rss_lock); 2353 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) { 2354 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) { 2355 iavf_print_adv_rss_cfg(adapter, rss, 2356 "Input set change for", 2357 "successful"); 2358 rss->state = IAVF_ADV_RSS_ACTIVE; 2359 } 2360 } 2361 spin_unlock_bh(&adapter->adv_rss_lock); 2362 } 2363 break; 2364 case VIRTCHNL_OP_DEL_RSS_CFG: { 2365 struct iavf_adv_rss *rss, *rss_tmp; 2366 2367 spin_lock_bh(&adapter->adv_rss_lock); 2368 list_for_each_entry_safe(rss, rss_tmp, 2369 &adapter->adv_rss_list_head, list) { 2370 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) { 2371 list_del(&rss->list); 2372 kfree(rss); 2373 } 2374 } 2375 spin_unlock_bh(&adapter->adv_rss_lock); 2376 } 2377 break; 2378 case VIRTCHNL_OP_ADD_VLAN_V2: { 2379 struct iavf_vlan_filter *f; 2380 2381 spin_lock_bh(&adapter->mac_vlan_list_lock); 2382 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 2383 if (f->is_new_vlan) { 2384 f->is_new_vlan = false; 2385 if (f->vlan.tpid == ETH_P_8021Q) 2386 set_bit(f->vlan.vid, 2387 adapter->vsi.active_cvlans); 2388 else 2389 set_bit(f->vlan.vid, 2390 adapter->vsi.active_svlans); 2391 } 2392 } 2393 spin_unlock_bh(&adapter->mac_vlan_list_lock); 2394 } 2395 break; 2396 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 2397 /* PF enabled vlan strip on this VF. 2398 * Update netdev->features if needed to be in sync with ethtool. 2399 */ 2400 if (!v_retval) 2401 iavf_netdev_features_vlan_strip_set(netdev, true); 2402 break; 2403 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 2404 /* PF disabled vlan strip on this VF. 2405 * Update netdev->features if needed to be in sync with ethtool. 2406 */ 2407 if (!v_retval) 2408 iavf_netdev_features_vlan_strip_set(netdev, false); 2409 break; 2410 default: 2411 if (adapter->current_op && (v_opcode != adapter->current_op)) 2412 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", 2413 adapter->current_op, v_opcode); 2414 break; 2415 } /* switch v_opcode */ 2416 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 2417 } 2418