1 // SPDX-License-Identifier: GPL-2.0 2 /* Marvell OcteonTx2 RVU Virtual Function ethernet driver */ 3 4 #include <linux/etherdevice.h> 5 #include <linux/module.h> 6 #include <linux/pci.h> 7 8 #include "otx2_common.h" 9 #include "otx2_reg.h" 10 #include "cn10k.h" 11 12 #define DRV_NAME "rvu_nicvf" 13 #define DRV_STRING "Marvell RVU NIC Virtual Function Driver" 14 15 static const struct pci_device_id otx2_vf_id_table[] = { 16 { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_AFVF) }, 17 { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_VF) }, 18 { } 19 }; 20 21 MODULE_AUTHOR("Sunil Goutham <sgoutham@marvell.com>"); 22 MODULE_DESCRIPTION(DRV_STRING); 23 MODULE_LICENSE("GPL v2"); 24 MODULE_DEVICE_TABLE(pci, otx2_vf_id_table); 25 26 /* RVU VF Interrupt Vector Enumeration */ 27 enum { 28 RVU_VF_INT_VEC_MBOX = 0x0, 29 }; 30 31 static void otx2vf_process_vfaf_mbox_msg(struct otx2_nic *vf, 32 struct mbox_msghdr *msg) 33 { 34 if (msg->id >= MBOX_MSG_MAX) { 35 dev_err(vf->dev, 36 "Mbox msg with unknown ID %d\n", msg->id); 37 return; 38 } 39 40 if (msg->sig != OTX2_MBOX_RSP_SIG) { 41 dev_err(vf->dev, 42 "Mbox msg with wrong signature %x, ID %d\n", 43 msg->sig, msg->id); 44 return; 45 } 46 47 if (msg->rc == MBOX_MSG_INVALID) { 48 dev_err(vf->dev, 49 "PF/AF says the sent msg(s) %d were invalid\n", 50 msg->id); 51 return; 52 } 53 54 switch (msg->id) { 55 case MBOX_MSG_READY: 56 vf->pcifunc = msg->pcifunc; 57 break; 58 case MBOX_MSG_MSIX_OFFSET: 59 mbox_handler_msix_offset(vf, (struct msix_offset_rsp *)msg); 60 break; 61 case MBOX_MSG_NPA_LF_ALLOC: 62 mbox_handler_npa_lf_alloc(vf, (struct npa_lf_alloc_rsp *)msg); 63 break; 64 case MBOX_MSG_NIX_LF_ALLOC: 65 mbox_handler_nix_lf_alloc(vf, (struct nix_lf_alloc_rsp *)msg); 66 break; 67 case MBOX_MSG_NIX_TXSCH_ALLOC: 68 mbox_handler_nix_txsch_alloc(vf, 69 (struct nix_txsch_alloc_rsp *)msg); 70 break; 71 case MBOX_MSG_NIX_BP_ENABLE: 72 mbox_handler_nix_bp_enable(vf, (struct nix_bp_cfg_rsp *)msg); 73 break; 74 default: 75 if (msg->rc) 76 dev_err(vf->dev, 77 "Mbox msg response has err %d, ID %d\n", 78 msg->rc, msg->id); 79 } 80 } 81 82 static void otx2vf_vfaf_mbox_handler(struct work_struct *work) 83 { 84 struct otx2_mbox_dev *mdev; 85 struct mbox_hdr *rsp_hdr; 86 struct mbox_msghdr *msg; 87 struct otx2_mbox *mbox; 88 struct mbox *af_mbox; 89 int offset, id; 90 91 af_mbox = container_of(work, struct mbox, mbox_wrk); 92 mbox = &af_mbox->mbox; 93 mdev = &mbox->dev[0]; 94 rsp_hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start); 95 if (af_mbox->num_msgs == 0) 96 return; 97 offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN); 98 99 for (id = 0; id < af_mbox->num_msgs; id++) { 100 msg = (struct mbox_msghdr *)(mdev->mbase + offset); 101 otx2vf_process_vfaf_mbox_msg(af_mbox->pfvf, msg); 102 offset = mbox->rx_start + msg->next_msgoff; 103 if (mdev->msgs_acked == (af_mbox->num_msgs - 1)) 104 __otx2_mbox_reset(mbox, 0); 105 mdev->msgs_acked++; 106 } 107 } 108 109 static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf, 110 struct mbox_msghdr *req) 111 { 112 struct msg_rsp *rsp; 113 int err; 114 115 /* Check if valid, if not reply with a invalid msg */ 116 if (req->sig != OTX2_MBOX_REQ_SIG) { 117 otx2_reply_invalid_msg(&vf->mbox.mbox_up, 0, 0, req->id); 118 return -ENODEV; 119 } 120 121 switch (req->id) { 122 case MBOX_MSG_CGX_LINK_EVENT: 123 rsp = (struct msg_rsp *)otx2_mbox_alloc_msg( 124 &vf->mbox.mbox_up, 0, 125 sizeof(struct msg_rsp)); 126 if (!rsp) 127 return -ENOMEM; 128 129 rsp->hdr.id = MBOX_MSG_CGX_LINK_EVENT; 130 rsp->hdr.sig = OTX2_MBOX_RSP_SIG; 131 rsp->hdr.pcifunc = 0; 132 rsp->hdr.rc = 0; 133 err = otx2_mbox_up_handler_cgx_link_event( 134 vf, (struct cgx_link_info_msg *)req, rsp); 135 return err; 136 default: 137 otx2_reply_invalid_msg(&vf->mbox.mbox_up, 0, 0, req->id); 138 return -ENODEV; 139 } 140 return 0; 141 } 142 143 static void otx2vf_vfaf_mbox_up_handler(struct work_struct *work) 144 { 145 struct otx2_mbox_dev *mdev; 146 struct mbox_hdr *rsp_hdr; 147 struct mbox_msghdr *msg; 148 struct otx2_mbox *mbox; 149 struct mbox *vf_mbox; 150 struct otx2_nic *vf; 151 int offset, id; 152 153 vf_mbox = container_of(work, struct mbox, mbox_up_wrk); 154 vf = vf_mbox->pfvf; 155 mbox = &vf_mbox->mbox_up; 156 mdev = &mbox->dev[0]; 157 158 rsp_hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start); 159 if (vf_mbox->up_num_msgs == 0) 160 return; 161 162 offset = mbox->rx_start + ALIGN(sizeof(*rsp_hdr), MBOX_MSG_ALIGN); 163 164 for (id = 0; id < vf_mbox->up_num_msgs; id++) { 165 msg = (struct mbox_msghdr *)(mdev->mbase + offset); 166 otx2vf_process_mbox_msg_up(vf, msg); 167 offset = mbox->rx_start + msg->next_msgoff; 168 } 169 170 otx2_mbox_msg_send(mbox, 0); 171 } 172 173 static irqreturn_t otx2vf_vfaf_mbox_intr_handler(int irq, void *vf_irq) 174 { 175 struct otx2_nic *vf = (struct otx2_nic *)vf_irq; 176 struct otx2_mbox_dev *mdev; 177 struct otx2_mbox *mbox; 178 struct mbox_hdr *hdr; 179 180 /* Clear the IRQ */ 181 otx2_write64(vf, RVU_VF_INT, BIT_ULL(0)); 182 183 /* Read latest mbox data */ 184 smp_rmb(); 185 186 /* Check for PF => VF response messages */ 187 mbox = &vf->mbox.mbox; 188 mdev = &mbox->dev[0]; 189 otx2_sync_mbox_bbuf(mbox, 0); 190 191 trace_otx2_msg_interrupt(mbox->pdev, "PF to VF", BIT_ULL(0)); 192 193 hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start); 194 if (hdr->num_msgs) { 195 vf->mbox.num_msgs = hdr->num_msgs; 196 hdr->num_msgs = 0; 197 memset(mbox->hwbase + mbox->rx_start, 0, 198 ALIGN(sizeof(struct mbox_hdr), sizeof(u64))); 199 queue_work(vf->mbox_wq, &vf->mbox.mbox_wrk); 200 } 201 /* Check for PF => VF notification messages */ 202 mbox = &vf->mbox.mbox_up; 203 mdev = &mbox->dev[0]; 204 otx2_sync_mbox_bbuf(mbox, 0); 205 206 hdr = (struct mbox_hdr *)(mdev->mbase + mbox->rx_start); 207 if (hdr->num_msgs) { 208 vf->mbox.up_num_msgs = hdr->num_msgs; 209 hdr->num_msgs = 0; 210 memset(mbox->hwbase + mbox->rx_start, 0, 211 ALIGN(sizeof(struct mbox_hdr), sizeof(u64))); 212 queue_work(vf->mbox_wq, &vf->mbox.mbox_up_wrk); 213 } 214 215 return IRQ_HANDLED; 216 } 217 218 static void otx2vf_disable_mbox_intr(struct otx2_nic *vf) 219 { 220 int vector = pci_irq_vector(vf->pdev, RVU_VF_INT_VEC_MBOX); 221 222 /* Disable VF => PF mailbox IRQ */ 223 otx2_write64(vf, RVU_VF_INT_ENA_W1C, BIT_ULL(0)); 224 free_irq(vector, vf); 225 } 226 227 static int otx2vf_register_mbox_intr(struct otx2_nic *vf, bool probe_pf) 228 { 229 struct otx2_hw *hw = &vf->hw; 230 struct msg_req *req; 231 char *irq_name; 232 int err; 233 234 /* Register mailbox interrupt handler */ 235 irq_name = &hw->irq_name[RVU_VF_INT_VEC_MBOX * NAME_SIZE]; 236 snprintf(irq_name, NAME_SIZE, "RVUVFAF Mbox"); 237 err = request_irq(pci_irq_vector(vf->pdev, RVU_VF_INT_VEC_MBOX), 238 otx2vf_vfaf_mbox_intr_handler, 0, irq_name, vf); 239 if (err) { 240 dev_err(vf->dev, 241 "RVUPF: IRQ registration failed for VFAF mbox irq\n"); 242 return err; 243 } 244 245 /* Enable mailbox interrupt for msgs coming from PF. 246 * First clear to avoid spurious interrupts, if any. 247 */ 248 otx2_write64(vf, RVU_VF_INT, BIT_ULL(0)); 249 otx2_write64(vf, RVU_VF_INT_ENA_W1S, BIT_ULL(0)); 250 251 if (!probe_pf) 252 return 0; 253 254 /* Check mailbox communication with PF */ 255 req = otx2_mbox_alloc_msg_ready(&vf->mbox); 256 if (!req) { 257 otx2vf_disable_mbox_intr(vf); 258 return -ENOMEM; 259 } 260 261 err = otx2_sync_mbox_msg(&vf->mbox); 262 if (err) { 263 dev_warn(vf->dev, 264 "AF not responding to mailbox, deferring probe\n"); 265 otx2vf_disable_mbox_intr(vf); 266 return -EPROBE_DEFER; 267 } 268 return 0; 269 } 270 271 static void otx2vf_vfaf_mbox_destroy(struct otx2_nic *vf) 272 { 273 struct mbox *mbox = &vf->mbox; 274 275 if (vf->mbox_wq) { 276 flush_workqueue(vf->mbox_wq); 277 destroy_workqueue(vf->mbox_wq); 278 vf->mbox_wq = NULL; 279 } 280 281 if (mbox->mbox.hwbase && !test_bit(CN10K_MBOX, &vf->hw.cap_flag)) 282 iounmap((void __iomem *)mbox->mbox.hwbase); 283 284 otx2_mbox_destroy(&mbox->mbox); 285 otx2_mbox_destroy(&mbox->mbox_up); 286 } 287 288 static int otx2vf_vfaf_mbox_init(struct otx2_nic *vf) 289 { 290 struct mbox *mbox = &vf->mbox; 291 void __iomem *hwbase; 292 int err; 293 294 mbox->pfvf = vf; 295 vf->mbox_wq = alloc_workqueue("otx2_vfaf_mailbox", 296 WQ_UNBOUND | WQ_HIGHPRI | 297 WQ_MEM_RECLAIM, 1); 298 if (!vf->mbox_wq) 299 return -ENOMEM; 300 301 if (test_bit(CN10K_MBOX, &vf->hw.cap_flag)) { 302 /* For cn10k platform, VF mailbox region is in its BAR2 303 * register space 304 */ 305 hwbase = vf->reg_base + RVU_VF_MBOX_REGION; 306 } else { 307 /* Mailbox is a reserved memory (in RAM) region shared between 308 * admin function (i.e PF0) and this VF, shouldn't be mapped as 309 * device memory to allow unaligned accesses. 310 */ 311 hwbase = ioremap_wc(pci_resource_start(vf->pdev, 312 PCI_MBOX_BAR_NUM), 313 pci_resource_len(vf->pdev, 314 PCI_MBOX_BAR_NUM)); 315 if (!hwbase) { 316 dev_err(vf->dev, "Unable to map VFAF mailbox region\n"); 317 err = -ENOMEM; 318 goto exit; 319 } 320 } 321 322 err = otx2_mbox_init(&mbox->mbox, hwbase, vf->pdev, vf->reg_base, 323 MBOX_DIR_VFPF, 1); 324 if (err) 325 goto exit; 326 327 err = otx2_mbox_init(&mbox->mbox_up, hwbase, vf->pdev, vf->reg_base, 328 MBOX_DIR_VFPF_UP, 1); 329 if (err) 330 goto exit; 331 332 err = otx2_mbox_bbuf_init(mbox, vf->pdev); 333 if (err) 334 goto exit; 335 336 INIT_WORK(&mbox->mbox_wrk, otx2vf_vfaf_mbox_handler); 337 INIT_WORK(&mbox->mbox_up_wrk, otx2vf_vfaf_mbox_up_handler); 338 mutex_init(&mbox->lock); 339 340 return 0; 341 exit: 342 if (hwbase && !test_bit(CN10K_MBOX, &vf->hw.cap_flag)) 343 iounmap(hwbase); 344 destroy_workqueue(vf->mbox_wq); 345 return err; 346 } 347 348 static int otx2vf_open(struct net_device *netdev) 349 { 350 struct otx2_nic *vf; 351 int err; 352 353 err = otx2_open(netdev); 354 if (err) 355 return err; 356 357 /* LBKs do not receive link events so tell everyone we are up here */ 358 vf = netdev_priv(netdev); 359 if (is_otx2_lbkvf(vf->pdev)) { 360 pr_info("%s NIC Link is UP\n", netdev->name); 361 netif_carrier_on(netdev); 362 netif_tx_start_all_queues(netdev); 363 } 364 365 return 0; 366 } 367 368 static int otx2vf_stop(struct net_device *netdev) 369 { 370 return otx2_stop(netdev); 371 } 372 373 static netdev_tx_t otx2vf_xmit(struct sk_buff *skb, struct net_device *netdev) 374 { 375 struct otx2_nic *vf = netdev_priv(netdev); 376 int qidx = skb_get_queue_mapping(skb); 377 struct otx2_snd_queue *sq; 378 struct netdev_queue *txq; 379 380 sq = &vf->qset.sq[qidx]; 381 txq = netdev_get_tx_queue(netdev, qidx); 382 383 if (!otx2_sq_append_skb(netdev, sq, skb, qidx)) { 384 netif_tx_stop_queue(txq); 385 386 /* Check again, incase SQBs got freed up */ 387 smp_mb(); 388 if (((sq->num_sqbs - *sq->aura_fc_addr) * sq->sqe_per_sqb) 389 > sq->sqe_thresh) 390 netif_tx_wake_queue(txq); 391 392 return NETDEV_TX_BUSY; 393 } 394 395 return NETDEV_TX_OK; 396 } 397 398 static void otx2vf_set_rx_mode(struct net_device *netdev) 399 { 400 struct otx2_nic *vf = netdev_priv(netdev); 401 402 queue_work(vf->otx2_wq, &vf->rx_mode_work); 403 } 404 405 static void otx2vf_do_set_rx_mode(struct work_struct *work) 406 { 407 struct otx2_nic *vf = container_of(work, struct otx2_nic, rx_mode_work); 408 struct net_device *netdev = vf->netdev; 409 unsigned int flags = netdev->flags; 410 struct nix_rx_mode *req; 411 412 mutex_lock(&vf->mbox.lock); 413 414 req = otx2_mbox_alloc_msg_nix_set_rx_mode(&vf->mbox); 415 if (!req) { 416 mutex_unlock(&vf->mbox.lock); 417 return; 418 } 419 420 req->mode = NIX_RX_MODE_UCAST; 421 422 if (flags & IFF_PROMISC) 423 req->mode |= NIX_RX_MODE_PROMISC; 424 if (flags & (IFF_ALLMULTI | IFF_MULTICAST)) 425 req->mode |= NIX_RX_MODE_ALLMULTI; 426 427 req->mode |= NIX_RX_MODE_USE_MCE; 428 429 otx2_sync_mbox_msg(&vf->mbox); 430 431 mutex_unlock(&vf->mbox.lock); 432 } 433 434 static int otx2vf_change_mtu(struct net_device *netdev, int new_mtu) 435 { 436 bool if_up = netif_running(netdev); 437 int err = 0; 438 439 if (if_up) 440 otx2vf_stop(netdev); 441 442 netdev_info(netdev, "Changing MTU from %d to %d\n", 443 netdev->mtu, new_mtu); 444 netdev->mtu = new_mtu; 445 446 if (if_up) 447 err = otx2vf_open(netdev); 448 449 return err; 450 } 451 452 static void otx2vf_reset_task(struct work_struct *work) 453 { 454 struct otx2_nic *vf = container_of(work, struct otx2_nic, reset_task); 455 456 rtnl_lock(); 457 458 if (netif_running(vf->netdev)) { 459 otx2vf_stop(vf->netdev); 460 vf->reset_count++; 461 otx2vf_open(vf->netdev); 462 } 463 464 rtnl_unlock(); 465 } 466 467 static int otx2vf_set_features(struct net_device *netdev, 468 netdev_features_t features) 469 { 470 netdev_features_t changed = features ^ netdev->features; 471 bool ntuple_enabled = !!(features & NETIF_F_NTUPLE); 472 struct otx2_nic *vf = netdev_priv(netdev); 473 474 if (changed & NETIF_F_NTUPLE) { 475 if (!ntuple_enabled) { 476 otx2_mcam_flow_del(vf); 477 return 0; 478 } 479 480 if (!otx2_get_maxflows(vf->flow_cfg)) { 481 netdev_err(netdev, 482 "Can't enable NTUPLE, MCAM entries not allocated\n"); 483 return -EINVAL; 484 } 485 } 486 return 0; 487 } 488 489 static const struct net_device_ops otx2vf_netdev_ops = { 490 .ndo_open = otx2vf_open, 491 .ndo_stop = otx2vf_stop, 492 .ndo_start_xmit = otx2vf_xmit, 493 .ndo_set_rx_mode = otx2vf_set_rx_mode, 494 .ndo_set_mac_address = otx2_set_mac_address, 495 .ndo_change_mtu = otx2vf_change_mtu, 496 .ndo_set_features = otx2vf_set_features, 497 .ndo_get_stats64 = otx2_get_stats64, 498 .ndo_tx_timeout = otx2_tx_timeout, 499 }; 500 501 static int otx2_wq_init(struct otx2_nic *vf) 502 { 503 vf->otx2_wq = create_singlethread_workqueue("otx2vf_wq"); 504 if (!vf->otx2_wq) 505 return -ENOMEM; 506 507 INIT_WORK(&vf->rx_mode_work, otx2vf_do_set_rx_mode); 508 INIT_WORK(&vf->reset_task, otx2vf_reset_task); 509 return 0; 510 } 511 512 static int otx2vf_realloc_msix_vectors(struct otx2_nic *vf) 513 { 514 struct otx2_hw *hw = &vf->hw; 515 int num_vec, err; 516 517 num_vec = hw->nix_msixoff; 518 num_vec += NIX_LF_CINT_VEC_START + hw->max_queues; 519 520 otx2vf_disable_mbox_intr(vf); 521 pci_free_irq_vectors(hw->pdev); 522 err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX); 523 if (err < 0) { 524 dev_err(vf->dev, "%s: Failed to realloc %d IRQ vectors\n", 525 __func__, num_vec); 526 return err; 527 } 528 529 return otx2vf_register_mbox_intr(vf, false); 530 } 531 532 static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) 533 { 534 int num_vec = pci_msix_vec_count(pdev); 535 struct device *dev = &pdev->dev; 536 struct net_device *netdev; 537 struct otx2_nic *vf; 538 struct otx2_hw *hw; 539 int err, qcount; 540 541 err = pcim_enable_device(pdev); 542 if (err) { 543 dev_err(dev, "Failed to enable PCI device\n"); 544 return err; 545 } 546 547 err = pci_request_regions(pdev, DRV_NAME); 548 if (err) { 549 dev_err(dev, "PCI request regions failed 0x%x\n", err); 550 return err; 551 } 552 553 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); 554 if (err) { 555 dev_err(dev, "DMA mask config failed, abort\n"); 556 goto err_release_regions; 557 } 558 559 pci_set_master(pdev); 560 561 qcount = num_online_cpus(); 562 netdev = alloc_etherdev_mqs(sizeof(*vf), qcount, qcount); 563 if (!netdev) { 564 err = -ENOMEM; 565 goto err_release_regions; 566 } 567 568 pci_set_drvdata(pdev, netdev); 569 SET_NETDEV_DEV(netdev, &pdev->dev); 570 vf = netdev_priv(netdev); 571 vf->netdev = netdev; 572 vf->pdev = pdev; 573 vf->dev = dev; 574 vf->iommu_domain = iommu_get_domain_for_dev(dev); 575 576 vf->flags |= OTX2_FLAG_INTF_DOWN; 577 hw = &vf->hw; 578 hw->pdev = vf->pdev; 579 hw->rx_queues = qcount; 580 hw->tx_queues = qcount; 581 hw->max_queues = qcount; 582 583 hw->irq_name = devm_kmalloc_array(&hw->pdev->dev, num_vec, NAME_SIZE, 584 GFP_KERNEL); 585 if (!hw->irq_name) { 586 err = -ENOMEM; 587 goto err_free_netdev; 588 } 589 590 hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec, 591 sizeof(cpumask_var_t), GFP_KERNEL); 592 if (!hw->affinity_mask) { 593 err = -ENOMEM; 594 goto err_free_netdev; 595 } 596 597 err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX); 598 if (err < 0) { 599 dev_err(dev, "%s: Failed to alloc %d IRQ vectors\n", 600 __func__, num_vec); 601 goto err_free_netdev; 602 } 603 604 vf->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0); 605 if (!vf->reg_base) { 606 dev_err(dev, "Unable to map physical function CSRs, aborting\n"); 607 err = -ENOMEM; 608 goto err_free_irq_vectors; 609 } 610 611 otx2_setup_dev_hw_settings(vf); 612 /* Init VF <=> PF mailbox stuff */ 613 err = otx2vf_vfaf_mbox_init(vf); 614 if (err) 615 goto err_free_irq_vectors; 616 617 /* Register mailbox interrupt */ 618 err = otx2vf_register_mbox_intr(vf, true); 619 if (err) 620 goto err_mbox_destroy; 621 622 /* Request AF to attach NPA and LIX LFs to this AF */ 623 err = otx2_attach_npa_nix(vf); 624 if (err) 625 goto err_disable_mbox_intr; 626 627 err = otx2vf_realloc_msix_vectors(vf); 628 if (err) 629 goto err_mbox_destroy; 630 631 err = otx2_set_real_num_queues(netdev, qcount, qcount); 632 if (err) 633 goto err_detach_rsrc; 634 635 err = cn10k_lmtst_init(vf); 636 if (err) 637 goto err_detach_rsrc; 638 639 /* Assign default mac address */ 640 otx2_get_mac_from_af(netdev); 641 642 netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | 643 NETIF_F_IPV6_CSUM | NETIF_F_RXHASH | 644 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | 645 NETIF_F_GSO_UDP_L4; 646 netdev->features = netdev->hw_features; 647 /* Support TSO on tag interface */ 648 netdev->vlan_features |= netdev->features; 649 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | 650 NETIF_F_HW_VLAN_STAG_TX; 651 netdev->features |= netdev->hw_features; 652 653 netdev->hw_features |= NETIF_F_NTUPLE; 654 netdev->hw_features |= NETIF_F_RXALL; 655 656 netdev->gso_max_segs = OTX2_MAX_GSO_SEGS; 657 netdev->watchdog_timeo = OTX2_TX_TIMEOUT; 658 659 netdev->netdev_ops = &otx2vf_netdev_ops; 660 661 netdev->min_mtu = OTX2_MIN_MTU; 662 netdev->max_mtu = otx2_get_max_mtu(vf); 663 664 /* To distinguish, for LBK VFs set netdev name explicitly */ 665 if (is_otx2_lbkvf(vf->pdev)) { 666 int n; 667 668 n = (vf->pcifunc >> RVU_PFVF_FUNC_SHIFT) & RVU_PFVF_FUNC_MASK; 669 /* Need to subtract 1 to get proper VF number */ 670 n -= 1; 671 snprintf(netdev->name, sizeof(netdev->name), "lbk%d", n); 672 } 673 674 err = register_netdev(netdev); 675 if (err) { 676 dev_err(dev, "Failed to register netdevice\n"); 677 goto err_detach_rsrc; 678 } 679 680 err = otx2_wq_init(vf); 681 if (err) 682 goto err_unreg_netdev; 683 684 otx2vf_set_ethtool_ops(netdev); 685 686 err = otx2vf_mcam_flow_init(vf); 687 if (err) 688 goto err_unreg_netdev; 689 690 err = otx2_register_dl(vf); 691 if (err) 692 goto err_unreg_netdev; 693 694 /* Enable pause frames by default */ 695 vf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED; 696 vf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED; 697 698 return 0; 699 700 err_unreg_netdev: 701 unregister_netdev(netdev); 702 err_detach_rsrc: 703 if (test_bit(CN10K_LMTST, &vf->hw.cap_flag)) 704 qmem_free(vf->dev, vf->dync_lmt); 705 otx2_detach_resources(&vf->mbox); 706 err_disable_mbox_intr: 707 otx2vf_disable_mbox_intr(vf); 708 err_mbox_destroy: 709 otx2vf_vfaf_mbox_destroy(vf); 710 err_free_irq_vectors: 711 pci_free_irq_vectors(hw->pdev); 712 err_free_netdev: 713 pci_set_drvdata(pdev, NULL); 714 free_netdev(netdev); 715 err_release_regions: 716 pci_release_regions(pdev); 717 return err; 718 } 719 720 static void otx2vf_remove(struct pci_dev *pdev) 721 { 722 struct net_device *netdev = pci_get_drvdata(pdev); 723 struct otx2_nic *vf; 724 725 if (!netdev) 726 return; 727 728 vf = netdev_priv(netdev); 729 730 cancel_work_sync(&vf->reset_task); 731 otx2_unregister_dl(vf); 732 unregister_netdev(netdev); 733 if (vf->otx2_wq) 734 destroy_workqueue(vf->otx2_wq); 735 otx2vf_disable_mbox_intr(vf); 736 otx2_detach_resources(&vf->mbox); 737 if (test_bit(CN10K_LMTST, &vf->hw.cap_flag)) 738 qmem_free(vf->dev, vf->dync_lmt); 739 otx2vf_vfaf_mbox_destroy(vf); 740 pci_free_irq_vectors(vf->pdev); 741 pci_set_drvdata(pdev, NULL); 742 free_netdev(netdev); 743 744 pci_release_regions(pdev); 745 } 746 747 static struct pci_driver otx2vf_driver = { 748 .name = DRV_NAME, 749 .id_table = otx2_vf_id_table, 750 .probe = otx2vf_probe, 751 .remove = otx2vf_remove, 752 .shutdown = otx2vf_remove, 753 }; 754 755 static int __init otx2vf_init_module(void) 756 { 757 pr_info("%s: %s\n", DRV_NAME, DRV_STRING); 758 759 return pci_register_driver(&otx2vf_driver); 760 } 761 762 static void __exit otx2vf_cleanup_module(void) 763 { 764 pci_unregister_driver(&otx2vf_driver); 765 } 766 767 module_init(otx2vf_init_module); 768 module_exit(otx2vf_cleanup_module); 769