Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.15 1119 lines 33 kB view raw
1/******************************************************************************* 2 * 3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver 4 * Copyright(c) 2013 - 2014 Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * The full GNU General Public License is included in this distribution in 19 * the file called "COPYING". 20 * 21 * Contact Information: 22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 24 * 25 ******************************************************************************/ 26 27#include "i40evf.h" 28#include "i40e_prototype.h" 29#include "i40evf_client.h" 30 31/* busy wait delay in msec */ 32#define I40EVF_BUSY_WAIT_DELAY 10 33#define I40EVF_BUSY_WAIT_COUNT 50 34 35/** 36 * i40evf_send_pf_msg 37 * @adapter: adapter structure 38 * @op: virtual channel opcode 39 * @msg: pointer to message buffer 40 * @len: message length 41 * 42 * Send message to PF and print status if failure. 43 **/ 44static int i40evf_send_pf_msg(struct i40evf_adapter *adapter, 45 enum virtchnl_ops op, u8 *msg, u16 len) 46{ 47 struct i40e_hw *hw = &adapter->hw; 48 i40e_status err; 49 50 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) 51 return 0; /* nothing to see here, move along */ 52 53 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL); 54 if (err) 55 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n", 56 op, i40evf_stat_str(hw, err), 57 i40evf_aq_str(hw, hw->aq.asq_last_status)); 58 return err; 59} 60 61/** 62 * i40evf_send_api_ver 63 * @adapter: adapter structure 64 * 65 * Send API version admin queue message to the PF. The reply is not checked 66 * in this function. Returns 0 if the message was successfully 67 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. 68 **/ 69int i40evf_send_api_ver(struct i40evf_adapter *adapter) 70{ 71 struct virtchnl_version_info vvi; 72 73 vvi.major = VIRTCHNL_VERSION_MAJOR; 74 vvi.minor = VIRTCHNL_VERSION_MINOR; 75 76 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi, 77 sizeof(vvi)); 78} 79 80/** 81 * i40evf_verify_api_ver 82 * @adapter: adapter structure 83 * 84 * Compare API versions with the PF. Must be called after admin queue is 85 * initialized. Returns 0 if API versions match, -EIO if they do not, 86 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors 87 * from the firmware are propagated. 88 **/ 89int i40evf_verify_api_ver(struct i40evf_adapter *adapter) 90{ 91 struct virtchnl_version_info *pf_vvi; 92 struct i40e_hw *hw = &adapter->hw; 93 struct i40e_arq_event_info event; 94 enum virtchnl_ops op; 95 i40e_status err; 96 97 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; 98 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 99 if (!event.msg_buf) { 100 err = -ENOMEM; 101 goto out; 102 } 103 104 while (1) { 105 err = i40evf_clean_arq_element(hw, &event, NULL); 106 /* When the AQ is empty, i40evf_clean_arq_element will return 107 * nonzero and this loop will terminate. 108 */ 109 if (err) 110 goto out_alloc; 111 op = 112 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); 113 if (op == VIRTCHNL_OP_VERSION) 114 break; 115 } 116 117 118 err = (i40e_status)le32_to_cpu(event.desc.cookie_low); 119 if (err) 120 goto out_alloc; 121 122 if (op != VIRTCHNL_OP_VERSION) { 123 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n", 124 op); 125 err = -EIO; 126 goto out_alloc; 127 } 128 129 pf_vvi = (struct virtchnl_version_info *)event.msg_buf; 130 adapter->pf_version = *pf_vvi; 131 132 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) || 133 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) && 134 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR))) 135 err = -EIO; 136 137out_alloc: 138 kfree(event.msg_buf); 139out: 140 return err; 141} 142 143/** 144 * i40evf_send_vf_config_msg 145 * @adapter: adapter structure 146 * 147 * Send VF configuration request admin queue message to the PF. The reply 148 * is not checked in this function. Returns 0 if the message was 149 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. 150 **/ 151int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter) 152{ 153 u32 caps; 154 155 caps = VIRTCHNL_VF_OFFLOAD_L2 | 156 VIRTCHNL_VF_OFFLOAD_RSS_PF | 157 VIRTCHNL_VF_OFFLOAD_RSS_AQ | 158 VIRTCHNL_VF_OFFLOAD_RSS_REG | 159 VIRTCHNL_VF_OFFLOAD_VLAN | 160 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | 161 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 | 162 VIRTCHNL_VF_OFFLOAD_ENCAP | 163 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM | 164 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES; 165 166 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES; 167 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG; 168 if (PF_IS_V11(adapter)) 169 return i40evf_send_pf_msg(adapter, 170 VIRTCHNL_OP_GET_VF_RESOURCES, 171 (u8 *)&caps, sizeof(caps)); 172 else 173 return i40evf_send_pf_msg(adapter, 174 VIRTCHNL_OP_GET_VF_RESOURCES, 175 NULL, 0); 176} 177 178/** 179 * i40evf_get_vf_config 180 * @hw: pointer to the hardware structure 181 * @len: length of buffer 182 * 183 * Get VF configuration from PF and populate hw structure. Must be called after 184 * admin queue is initialized. Busy waits until response is received from PF, 185 * with maximum timeout. Response from PF is returned in the buffer for further 186 * processing by the caller. 187 **/ 188int i40evf_get_vf_config(struct i40evf_adapter *adapter) 189{ 190 struct i40e_hw *hw = &adapter->hw; 191 struct i40e_arq_event_info event; 192 enum virtchnl_ops op; 193 i40e_status err; 194 u16 len; 195 196 len = sizeof(struct virtchnl_vf_resource) + 197 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource); 198 event.buf_len = len; 199 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 200 if (!event.msg_buf) { 201 err = -ENOMEM; 202 goto out; 203 } 204 205 while (1) { 206 /* When the AQ is empty, i40evf_clean_arq_element will return 207 * nonzero and this loop will terminate. 208 */ 209 err = i40evf_clean_arq_element(hw, &event, NULL); 210 if (err) 211 goto out_alloc; 212 op = 213 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); 214 if (op == VIRTCHNL_OP_GET_VF_RESOURCES) 215 break; 216 } 217 218 err = (i40e_status)le32_to_cpu(event.desc.cookie_low); 219 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len)); 220 221 i40e_vf_parse_hw_config(hw, adapter->vf_res); 222out_alloc: 223 kfree(event.msg_buf); 224out: 225 return err; 226} 227 228/** 229 * i40evf_configure_queues 230 * @adapter: adapter structure 231 * 232 * Request that the PF set up our (previously allocated) queues. 233 **/ 234void i40evf_configure_queues(struct i40evf_adapter *adapter) 235{ 236 struct virtchnl_vsi_queue_config_info *vqci; 237 struct virtchnl_queue_pair_info *vqpi; 238 int pairs = adapter->num_active_queues; 239 int i, len, max_frame = I40E_MAX_RXBUFFER; 240 241 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 242 /* bail because we already have a command pending */ 243 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n", 244 adapter->current_op); 245 return; 246 } 247 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES; 248 len = sizeof(struct virtchnl_vsi_queue_config_info) + 249 (sizeof(struct virtchnl_queue_pair_info) * pairs); 250 vqci = kzalloc(len, GFP_KERNEL); 251 if (!vqci) 252 return; 253 254 /* Limit maximum frame size when jumbo frames is not enabled */ 255 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) && 256 (adapter->netdev->mtu <= ETH_DATA_LEN)) 257 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN; 258 259 vqci->vsi_id = adapter->vsi_res->vsi_id; 260 vqci->num_queue_pairs = pairs; 261 vqpi = vqci->qpair; 262 /* Size check is not needed here - HW max is 16 queue pairs, and we 263 * can fit info for 31 of them into the AQ buffer before it overflows. 264 */ 265 for (i = 0; i < pairs; i++) { 266 vqpi->txq.vsi_id = vqci->vsi_id; 267 vqpi->txq.queue_id = i; 268 vqpi->txq.ring_len = adapter->tx_rings[i].count; 269 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma; 270 vqpi->rxq.vsi_id = vqci->vsi_id; 271 vqpi->rxq.queue_id = i; 272 vqpi->rxq.ring_len = adapter->rx_rings[i].count; 273 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; 274 vqpi->rxq.max_pkt_size = max_frame; 275 vqpi->rxq.databuffer_size = 276 ALIGN(adapter->rx_rings[i].rx_buf_len, 277 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); 278 vqpi++; 279 } 280 281 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES; 282 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES, 283 (u8 *)vqci, len); 284 kfree(vqci); 285} 286 287/** 288 * i40evf_enable_queues 289 * @adapter: adapter structure 290 * 291 * Request that the PF enable all of our queues. 292 **/ 293void i40evf_enable_queues(struct i40evf_adapter *adapter) 294{ 295 struct virtchnl_queue_select vqs; 296 297 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 298 /* bail because we already have a command pending */ 299 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n", 300 adapter->current_op); 301 return; 302 } 303 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES; 304 vqs.vsi_id = adapter->vsi_res->vsi_id; 305 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 306 vqs.rx_queues = vqs.tx_queues; 307 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES; 308 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES, 309 (u8 *)&vqs, sizeof(vqs)); 310} 311 312/** 313 * i40evf_disable_queues 314 * @adapter: adapter structure 315 * 316 * Request that the PF disable all of our queues. 317 **/ 318void i40evf_disable_queues(struct i40evf_adapter *adapter) 319{ 320 struct virtchnl_queue_select vqs; 321 322 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 323 /* bail because we already have a command pending */ 324 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n", 325 adapter->current_op); 326 return; 327 } 328 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES; 329 vqs.vsi_id = adapter->vsi_res->vsi_id; 330 vqs.tx_queues = BIT(adapter->num_active_queues) - 1; 331 vqs.rx_queues = vqs.tx_queues; 332 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES; 333 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES, 334 (u8 *)&vqs, sizeof(vqs)); 335} 336 337/** 338 * i40evf_map_queues 339 * @adapter: adapter structure 340 * 341 * Request that the PF map queues to interrupt vectors. Misc causes, including 342 * admin queue, are always mapped to vector 0. 343 **/ 344void i40evf_map_queues(struct i40evf_adapter *adapter) 345{ 346 struct virtchnl_irq_map_info *vimi; 347 int v_idx, q_vectors, len; 348 struct i40e_q_vector *q_vector; 349 350 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 351 /* bail because we already have a command pending */ 352 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n", 353 adapter->current_op); 354 return; 355 } 356 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP; 357 358 q_vectors = adapter->num_msix_vectors - NONQ_VECS; 359 360 len = sizeof(struct virtchnl_irq_map_info) + 361 (adapter->num_msix_vectors * 362 sizeof(struct virtchnl_vector_map)); 363 vimi = kzalloc(len, GFP_KERNEL); 364 if (!vimi) 365 return; 366 367 vimi->num_vectors = adapter->num_msix_vectors; 368 /* Queue vectors first */ 369 for (v_idx = 0; v_idx < q_vectors; v_idx++) { 370 q_vector = adapter->q_vectors + v_idx; 371 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; 372 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS; 373 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask; 374 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask; 375 } 376 /* Misc vector last - this is only for AdminQ messages */ 377 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; 378 vimi->vecmap[v_idx].vector_id = 0; 379 vimi->vecmap[v_idx].txq_map = 0; 380 vimi->vecmap[v_idx].rxq_map = 0; 381 382 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS; 383 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP, 384 (u8 *)vimi, len); 385 kfree(vimi); 386} 387 388/** 389 * i40evf_request_queues 390 * @adapter: adapter structure 391 * @num: number of requested queues 392 * 393 * We get a default number of queues from the PF. This enables us to request a 394 * different number. Returns 0 on success, negative on failure 395 **/ 396int i40evf_request_queues(struct i40evf_adapter *adapter, int num) 397{ 398 struct virtchnl_vf_res_request vfres; 399 400 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 401 /* bail because we already have a command pending */ 402 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n", 403 adapter->current_op); 404 return -EBUSY; 405 } 406 407 vfres.num_queue_pairs = num; 408 409 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES; 410 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED; 411 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES, 412 (u8 *)&vfres, sizeof(vfres)); 413} 414 415/** 416 * i40evf_add_ether_addrs 417 * @adapter: adapter structure 418 * @addrs: the MAC address filters to add (contiguous) 419 * @count: number of filters 420 * 421 * Request that the PF add one or more addresses to our filters. 422 **/ 423void i40evf_add_ether_addrs(struct i40evf_adapter *adapter) 424{ 425 struct virtchnl_ether_addr_list *veal; 426 int len, i = 0, count = 0; 427 struct i40evf_mac_filter *f; 428 bool more = false; 429 430 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 431 /* bail because we already have a command pending */ 432 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", 433 adapter->current_op); 434 return; 435 } 436 list_for_each_entry(f, &adapter->mac_filter_list, list) { 437 if (f->add) 438 count++; 439 } 440 if (!count) { 441 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; 442 return; 443 } 444 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR; 445 446 len = sizeof(struct virtchnl_ether_addr_list) + 447 (count * sizeof(struct virtchnl_ether_addr)); 448 if (len > I40EVF_MAX_AQ_BUF_SIZE) { 449 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n"); 450 count = (I40EVF_MAX_AQ_BUF_SIZE - 451 sizeof(struct virtchnl_ether_addr_list)) / 452 sizeof(struct virtchnl_ether_addr); 453 len = sizeof(struct virtchnl_ether_addr_list) + 454 (count * sizeof(struct virtchnl_ether_addr)); 455 more = true; 456 } 457 458 veal = kzalloc(len, GFP_KERNEL); 459 if (!veal) 460 return; 461 462 veal->vsi_id = adapter->vsi_res->vsi_id; 463 veal->num_elements = count; 464 list_for_each_entry(f, &adapter->mac_filter_list, list) { 465 if (f->add) { 466 ether_addr_copy(veal->list[i].addr, f->macaddr); 467 i++; 468 f->add = false; 469 if (i == count) 470 break; 471 } 472 } 473 if (!more) 474 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; 475 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, 476 (u8 *)veal, len); 477 kfree(veal); 478} 479 480/** 481 * i40evf_del_ether_addrs 482 * @adapter: adapter structure 483 * @addrs: the MAC address filters to remove (contiguous) 484 * @count: number of filtes 485 * 486 * Request that the PF remove one or more addresses from our filters. 487 **/ 488void i40evf_del_ether_addrs(struct i40evf_adapter *adapter) 489{ 490 struct virtchnl_ether_addr_list *veal; 491 struct i40evf_mac_filter *f, *ftmp; 492 int len, i = 0, count = 0; 493 bool more = false; 494 495 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 496 /* bail because we already have a command pending */ 497 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n", 498 adapter->current_op); 499 return; 500 } 501 list_for_each_entry(f, &adapter->mac_filter_list, list) { 502 if (f->remove) 503 count++; 504 } 505 if (!count) { 506 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; 507 return; 508 } 509 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR; 510 511 len = sizeof(struct virtchnl_ether_addr_list) + 512 (count * sizeof(struct virtchnl_ether_addr)); 513 if (len > I40EVF_MAX_AQ_BUF_SIZE) { 514 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n"); 515 count = (I40EVF_MAX_AQ_BUF_SIZE - 516 sizeof(struct virtchnl_ether_addr_list)) / 517 sizeof(struct virtchnl_ether_addr); 518 len = sizeof(struct virtchnl_ether_addr_list) + 519 (count * sizeof(struct virtchnl_ether_addr)); 520 more = true; 521 } 522 veal = kzalloc(len, GFP_KERNEL); 523 if (!veal) 524 return; 525 526 veal->vsi_id = adapter->vsi_res->vsi_id; 527 veal->num_elements = count; 528 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 529 if (f->remove) { 530 ether_addr_copy(veal->list[i].addr, f->macaddr); 531 i++; 532 list_del(&f->list); 533 kfree(f); 534 if (i == count) 535 break; 536 } 537 } 538 if (!more) 539 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; 540 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, 541 (u8 *)veal, len); 542 kfree(veal); 543} 544 545/** 546 * i40evf_add_vlans 547 * @adapter: adapter structure 548 * @vlans: the VLANs to add 549 * @count: number of VLANs 550 * 551 * Request that the PF add one or more VLAN filters to our VSI. 552 **/ 553void i40evf_add_vlans(struct i40evf_adapter *adapter) 554{ 555 struct virtchnl_vlan_filter_list *vvfl; 556 int len, i = 0, count = 0; 557 struct i40evf_vlan_filter *f; 558 bool more = false; 559 560 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 561 /* bail because we already have a command pending */ 562 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n", 563 adapter->current_op); 564 return; 565 } 566 567 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 568 if (f->add) 569 count++; 570 } 571 if (!count) { 572 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; 573 return; 574 } 575 adapter->current_op = VIRTCHNL_OP_ADD_VLAN; 576 577 len = sizeof(struct virtchnl_vlan_filter_list) + 578 (count * sizeof(u16)); 579 if (len > I40EVF_MAX_AQ_BUF_SIZE) { 580 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n"); 581 count = (I40EVF_MAX_AQ_BUF_SIZE - 582 sizeof(struct virtchnl_vlan_filter_list)) / 583 sizeof(u16); 584 len = sizeof(struct virtchnl_vlan_filter_list) + 585 (count * sizeof(u16)); 586 more = true; 587 } 588 vvfl = kzalloc(len, GFP_KERNEL); 589 if (!vvfl) 590 return; 591 592 vvfl->vsi_id = adapter->vsi_res->vsi_id; 593 vvfl->num_elements = count; 594 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 595 if (f->add) { 596 vvfl->vlan_id[i] = f->vlan; 597 i++; 598 f->add = false; 599 if (i == count) 600 break; 601 } 602 } 603 if (!more) 604 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; 605 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); 606 kfree(vvfl); 607} 608 609/** 610 * i40evf_del_vlans 611 * @adapter: adapter structure 612 * @vlans: the VLANs to remove 613 * @count: number of VLANs 614 * 615 * Request that the PF remove one or more VLAN filters from our VSI. 616 **/ 617void i40evf_del_vlans(struct i40evf_adapter *adapter) 618{ 619 struct virtchnl_vlan_filter_list *vvfl; 620 struct i40evf_vlan_filter *f, *ftmp; 621 int len, i = 0, count = 0; 622 bool more = false; 623 624 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 625 /* bail because we already have a command pending */ 626 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n", 627 adapter->current_op); 628 return; 629 } 630 631 list_for_each_entry(f, &adapter->vlan_filter_list, list) { 632 if (f->remove) 633 count++; 634 } 635 if (!count) { 636 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; 637 return; 638 } 639 adapter->current_op = VIRTCHNL_OP_DEL_VLAN; 640 641 len = sizeof(struct virtchnl_vlan_filter_list) + 642 (count * sizeof(u16)); 643 if (len > I40EVF_MAX_AQ_BUF_SIZE) { 644 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n"); 645 count = (I40EVF_MAX_AQ_BUF_SIZE - 646 sizeof(struct virtchnl_vlan_filter_list)) / 647 sizeof(u16); 648 len = sizeof(struct virtchnl_vlan_filter_list) + 649 (count * sizeof(u16)); 650 more = true; 651 } 652 vvfl = kzalloc(len, GFP_KERNEL); 653 if (!vvfl) 654 return; 655 656 vvfl->vsi_id = adapter->vsi_res->vsi_id; 657 vvfl->num_elements = count; 658 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { 659 if (f->remove) { 660 vvfl->vlan_id[i] = f->vlan; 661 i++; 662 list_del(&f->list); 663 kfree(f); 664 if (i == count) 665 break; 666 } 667 } 668 if (!more) 669 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; 670 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); 671 kfree(vvfl); 672} 673 674/** 675 * i40evf_set_promiscuous 676 * @adapter: adapter structure 677 * @flags: bitmask to control unicast/multicast promiscuous. 678 * 679 * Request that the PF enable promiscuous mode for our VSI. 680 **/ 681void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags) 682{ 683 struct virtchnl_promisc_info vpi; 684 int promisc_all; 685 686 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 687 /* bail because we already have a command pending */ 688 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n", 689 adapter->current_op); 690 return; 691 } 692 693 promisc_all = FLAG_VF_UNICAST_PROMISC | 694 FLAG_VF_MULTICAST_PROMISC; 695 if ((flags & promisc_all) == promisc_all) { 696 adapter->flags |= I40EVF_FLAG_PROMISC_ON; 697 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC; 698 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n"); 699 } 700 701 if (flags & FLAG_VF_MULTICAST_PROMISC) { 702 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON; 703 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI; 704 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n"); 705 } 706 707 if (!flags) { 708 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON; 709 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC; 710 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n"); 711 } 712 713 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; 714 vpi.vsi_id = adapter->vsi_res->vsi_id; 715 vpi.flags = flags; 716 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, 717 (u8 *)&vpi, sizeof(vpi)); 718} 719 720/** 721 * i40evf_request_stats 722 * @adapter: adapter structure 723 * 724 * Request VSI statistics from PF. 725 **/ 726void i40evf_request_stats(struct i40evf_adapter *adapter) 727{ 728 struct virtchnl_queue_select vqs; 729 730 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 731 /* no error message, this isn't crucial */ 732 return; 733 } 734 adapter->current_op = VIRTCHNL_OP_GET_STATS; 735 vqs.vsi_id = adapter->vsi_res->vsi_id; 736 /* queue maps are ignored for this message - only the vsi is used */ 737 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, 738 (u8 *)&vqs, sizeof(vqs))) 739 /* if the request failed, don't lock out others */ 740 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 741} 742 743/** 744 * i40evf_get_hena 745 * @adapter: adapter structure 746 * 747 * Request hash enable capabilities from PF 748 **/ 749void i40evf_get_hena(struct i40evf_adapter *adapter) 750{ 751 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 752 /* bail because we already have a command pending */ 753 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n", 754 adapter->current_op); 755 return; 756 } 757 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS; 758 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA; 759 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, 760 NULL, 0); 761} 762 763/** 764 * i40evf_set_hena 765 * @adapter: adapter structure 766 * 767 * Request the PF to set our RSS hash capabilities 768 **/ 769void i40evf_set_hena(struct i40evf_adapter *adapter) 770{ 771 struct virtchnl_rss_hena vrh; 772 773 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 774 /* bail because we already have a command pending */ 775 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n", 776 adapter->current_op); 777 return; 778 } 779 vrh.hena = adapter->hena; 780 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA; 781 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA; 782 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, 783 (u8 *)&vrh, sizeof(vrh)); 784} 785 786/** 787 * i40evf_set_rss_key 788 * @adapter: adapter structure 789 * 790 * Request the PF to set our RSS hash key 791 **/ 792void i40evf_set_rss_key(struct i40evf_adapter *adapter) 793{ 794 struct virtchnl_rss_key *vrk; 795 int len; 796 797 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 798 /* bail because we already have a command pending */ 799 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n", 800 adapter->current_op); 801 return; 802 } 803 len = sizeof(struct virtchnl_rss_key) + 804 (adapter->rss_key_size * sizeof(u8)) - 1; 805 vrk = kzalloc(len, GFP_KERNEL); 806 if (!vrk) 807 return; 808 vrk->vsi_id = adapter->vsi.id; 809 vrk->key_len = adapter->rss_key_size; 810 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size); 811 812 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY; 813 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY; 814 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, 815 (u8 *)vrk, len); 816 kfree(vrk); 817} 818 819/** 820 * i40evf_set_rss_lut 821 * @adapter: adapter structure 822 * 823 * Request the PF to set our RSS lookup table 824 **/ 825void i40evf_set_rss_lut(struct i40evf_adapter *adapter) 826{ 827 struct virtchnl_rss_lut *vrl; 828 int len; 829 830 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 831 /* bail because we already have a command pending */ 832 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n", 833 adapter->current_op); 834 return; 835 } 836 len = sizeof(struct virtchnl_rss_lut) + 837 (adapter->rss_lut_size * sizeof(u8)) - 1; 838 vrl = kzalloc(len, GFP_KERNEL); 839 if (!vrl) 840 return; 841 vrl->vsi_id = adapter->vsi.id; 842 vrl->lut_entries = adapter->rss_lut_size; 843 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size); 844 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT; 845 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT; 846 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, 847 (u8 *)vrl, len); 848 kfree(vrl); 849} 850 851/** 852 * i40evf_enable_vlan_stripping 853 * @adapter: adapter structure 854 * 855 * Request VLAN header stripping to be enabled 856 **/ 857void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter) 858{ 859 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 860 /* bail because we already have a command pending */ 861 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n", 862 adapter->current_op); 863 return; 864 } 865 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING; 866 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; 867 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, 868 NULL, 0); 869} 870 871/** 872 * i40evf_disable_vlan_stripping 873 * @adapter: adapter structure 874 * 875 * Request VLAN header stripping to be disabled 876 **/ 877void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter) 878{ 879 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { 880 /* bail because we already have a command pending */ 881 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n", 882 adapter->current_op); 883 return; 884 } 885 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING; 886 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; 887 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 888 NULL, 0); 889} 890 891/** 892 * i40evf_print_link_message - print link up or down 893 * @adapter: adapter structure 894 * 895 * Log a message telling the world of our wonderous link status 896 */ 897static void i40evf_print_link_message(struct i40evf_adapter *adapter) 898{ 899 struct net_device *netdev = adapter->netdev; 900 char *speed = "Unknown "; 901 902 if (!adapter->link_up) { 903 netdev_info(netdev, "NIC Link is Down\n"); 904 return; 905 } 906 907 switch (adapter->link_speed) { 908 case I40E_LINK_SPEED_40GB: 909 speed = "40 G"; 910 break; 911 case I40E_LINK_SPEED_25GB: 912 speed = "25 G"; 913 break; 914 case I40E_LINK_SPEED_20GB: 915 speed = "20 G"; 916 break; 917 case I40E_LINK_SPEED_10GB: 918 speed = "10 G"; 919 break; 920 case I40E_LINK_SPEED_1GB: 921 speed = "1000 M"; 922 break; 923 case I40E_LINK_SPEED_100MB: 924 speed = "100 M"; 925 break; 926 default: 927 break; 928 } 929 930 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed); 931} 932 933/** 934 * i40evf_request_reset 935 * @adapter: adapter structure 936 * 937 * Request that the PF reset this VF. No response is expected. 938 **/ 939void i40evf_request_reset(struct i40evf_adapter *adapter) 940{ 941 /* Don't check CURRENT_OP - this is always higher priority */ 942 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0); 943 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 944} 945 946/** 947 * i40evf_virtchnl_completion 948 * @adapter: adapter structure 949 * @v_opcode: opcode sent by PF 950 * @v_retval: retval sent by PF 951 * @msg: message sent by PF 952 * @msglen: message length 953 * 954 * Asynchronous completion function for admin queue messages. Rather than busy 955 * wait, we fire off our requests and assume that no errors will be returned. 956 * This function handles the reply messages. 957 **/ 958void i40evf_virtchnl_completion(struct i40evf_adapter *adapter, 959 enum virtchnl_ops v_opcode, 960 i40e_status v_retval, 961 u8 *msg, u16 msglen) 962{ 963 struct net_device *netdev = adapter->netdev; 964 965 if (v_opcode == VIRTCHNL_OP_EVENT) { 966 struct virtchnl_pf_event *vpe = 967 (struct virtchnl_pf_event *)msg; 968 switch (vpe->event) { 969 case VIRTCHNL_EVENT_LINK_CHANGE: 970 adapter->link_speed = 971 vpe->event_data.link_event.link_speed; 972 if (adapter->link_up != 973 vpe->event_data.link_event.link_status) { 974 adapter->link_up = 975 vpe->event_data.link_event.link_status; 976 if (adapter->link_up) { 977 netif_tx_start_all_queues(netdev); 978 netif_carrier_on(netdev); 979 } else { 980 netif_tx_stop_all_queues(netdev); 981 netif_carrier_off(netdev); 982 } 983 i40evf_print_link_message(adapter); 984 } 985 break; 986 case VIRTCHNL_EVENT_RESET_IMPENDING: 987 dev_info(&adapter->pdev->dev, "PF reset warning received\n"); 988 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) { 989 adapter->flags |= I40EVF_FLAG_RESET_PENDING; 990 dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); 991 schedule_work(&adapter->reset_task); 992 } 993 break; 994 default: 995 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n", 996 vpe->event); 997 break; 998 } 999 return; 1000 } 1001 if (v_retval) { 1002 switch (v_opcode) { 1003 case VIRTCHNL_OP_ADD_VLAN: 1004 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n", 1005 i40evf_stat_str(&adapter->hw, v_retval)); 1006 break; 1007 case VIRTCHNL_OP_ADD_ETH_ADDR: 1008 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n", 1009 i40evf_stat_str(&adapter->hw, v_retval)); 1010 break; 1011 case VIRTCHNL_OP_DEL_VLAN: 1012 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n", 1013 i40evf_stat_str(&adapter->hw, v_retval)); 1014 break; 1015 case VIRTCHNL_OP_DEL_ETH_ADDR: 1016 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", 1017 i40evf_stat_str(&adapter->hw, v_retval)); 1018 break; 1019 default: 1020 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n", 1021 v_retval, 1022 i40evf_stat_str(&adapter->hw, v_retval), 1023 v_opcode); 1024 } 1025 } 1026 switch (v_opcode) { 1027 case VIRTCHNL_OP_GET_STATS: { 1028 struct i40e_eth_stats *stats = 1029 (struct i40e_eth_stats *)msg; 1030 netdev->stats.rx_packets = stats->rx_unicast + 1031 stats->rx_multicast + 1032 stats->rx_broadcast; 1033 netdev->stats.tx_packets = stats->tx_unicast + 1034 stats->tx_multicast + 1035 stats->tx_broadcast; 1036 netdev->stats.rx_bytes = stats->rx_bytes; 1037 netdev->stats.tx_bytes = stats->tx_bytes; 1038 netdev->stats.tx_errors = stats->tx_errors; 1039 netdev->stats.rx_dropped = stats->rx_discards; 1040 netdev->stats.tx_dropped = stats->tx_discards; 1041 adapter->current_stats = *stats; 1042 } 1043 break; 1044 case VIRTCHNL_OP_GET_VF_RESOURCES: { 1045 u16 len = sizeof(struct virtchnl_vf_resource) + 1046 I40E_MAX_VF_VSI * 1047 sizeof(struct virtchnl_vsi_resource); 1048 memcpy(adapter->vf_res, msg, min(msglen, len)); 1049 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res); 1050 /* restore current mac address */ 1051 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); 1052 i40evf_process_config(adapter); 1053 } 1054 break; 1055 case VIRTCHNL_OP_ENABLE_QUEUES: 1056 /* enable transmits */ 1057 i40evf_irq_enable(adapter, true); 1058 break; 1059 case VIRTCHNL_OP_DISABLE_QUEUES: 1060 i40evf_free_all_tx_resources(adapter); 1061 i40evf_free_all_rx_resources(adapter); 1062 if (adapter->state == __I40EVF_DOWN_PENDING) { 1063 adapter->state = __I40EVF_DOWN; 1064 wake_up(&adapter->down_waitqueue); 1065 } 1066 break; 1067 case VIRTCHNL_OP_VERSION: 1068 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1069 /* Don't display an error if we get these out of sequence. 1070 * If the firmware needed to get kicked, we'll get these and 1071 * it's no problem. 1072 */ 1073 if (v_opcode != adapter->current_op) 1074 return; 1075 break; 1076 case VIRTCHNL_OP_IWARP: 1077 /* Gobble zero-length replies from the PF. They indicate that 1078 * a previous message was received OK, and the client doesn't 1079 * care about that. 1080 */ 1081 if (msglen && CLIENT_ENABLED(adapter)) 1082 i40evf_notify_client_message(&adapter->vsi, 1083 msg, msglen); 1084 break; 1085 1086 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 1087 adapter->client_pending &= 1088 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP)); 1089 break; 1090 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: { 1091 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg; 1092 if (msglen == sizeof(*vrh)) 1093 adapter->hena = vrh->hena; 1094 else 1095 dev_warn(&adapter->pdev->dev, 1096 "Invalid message %d from PF\n", v_opcode); 1097 } 1098 break; 1099 case VIRTCHNL_OP_REQUEST_QUEUES: { 1100 struct virtchnl_vf_res_request *vfres = 1101 (struct virtchnl_vf_res_request *)msg; 1102 if (vfres->num_queue_pairs != adapter->num_req_queues) { 1103 dev_info(&adapter->pdev->dev, 1104 "Requested %d queues, PF can support %d\n", 1105 adapter->num_req_queues, 1106 vfres->num_queue_pairs); 1107 adapter->num_req_queues = 0; 1108 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED; 1109 } 1110 } 1111 break; 1112 default: 1113 if (adapter->current_op && (v_opcode != adapter->current_op)) 1114 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n", 1115 adapter->current_op, v_opcode); 1116 break; 1117 } /* switch v_opcode */ 1118 adapter->current_op = VIRTCHNL_OP_UNKNOWN; 1119}