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