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 int otx2vf_change_mtu(struct net_device *netdev, int new_mtu) 399 { 400 bool if_up = netif_running(netdev); 401 int err = 0; 402 403 if (if_up) 404 otx2vf_stop(netdev); 405 406 netdev_info(netdev, "Changing MTU from %d to %d\n", 407 netdev->mtu, new_mtu); 408 netdev->mtu = new_mtu; 409 410 if (if_up) 411 err = otx2vf_open(netdev); 412 413 return err; 414 } 415 416 static void otx2vf_reset_task(struct work_struct *work) 417 { 418 struct otx2_nic *vf = container_of(work, struct otx2_nic, reset_task); 419 420 rtnl_lock(); 421 422 if (netif_running(vf->netdev)) { 423 otx2vf_stop(vf->netdev); 424 vf->reset_count++; 425 otx2vf_open(vf->netdev); 426 } 427 428 rtnl_unlock(); 429 } 430 431 static const struct net_device_ops otx2vf_netdev_ops = { 432 .ndo_open = otx2vf_open, 433 .ndo_stop = otx2vf_stop, 434 .ndo_start_xmit = otx2vf_xmit, 435 .ndo_set_mac_address = otx2_set_mac_address, 436 .ndo_change_mtu = otx2vf_change_mtu, 437 .ndo_get_stats64 = otx2_get_stats64, 438 .ndo_tx_timeout = otx2_tx_timeout, 439 }; 440 441 static int otx2vf_realloc_msix_vectors(struct otx2_nic *vf) 442 { 443 struct otx2_hw *hw = &vf->hw; 444 int num_vec, err; 445 446 num_vec = hw->nix_msixoff; 447 num_vec += NIX_LF_CINT_VEC_START + hw->max_queues; 448 449 otx2vf_disable_mbox_intr(vf); 450 pci_free_irq_vectors(hw->pdev); 451 err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX); 452 if (err < 0) { 453 dev_err(vf->dev, "%s: Failed to realloc %d IRQ vectors\n", 454 __func__, num_vec); 455 return err; 456 } 457 458 return otx2vf_register_mbox_intr(vf, false); 459 } 460 461 static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) 462 { 463 int num_vec = pci_msix_vec_count(pdev); 464 struct device *dev = &pdev->dev; 465 struct net_device *netdev; 466 struct otx2_nic *vf; 467 struct otx2_hw *hw; 468 int err, qcount; 469 470 err = pcim_enable_device(pdev); 471 if (err) { 472 dev_err(dev, "Failed to enable PCI device\n"); 473 return err; 474 } 475 476 err = pci_request_regions(pdev, DRV_NAME); 477 if (err) { 478 dev_err(dev, "PCI request regions failed 0x%x\n", err); 479 return err; 480 } 481 482 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); 483 if (err) { 484 dev_err(dev, "DMA mask config failed, abort\n"); 485 goto err_release_regions; 486 } 487 488 pci_set_master(pdev); 489 490 qcount = num_online_cpus(); 491 netdev = alloc_etherdev_mqs(sizeof(*vf), qcount, qcount); 492 if (!netdev) { 493 err = -ENOMEM; 494 goto err_release_regions; 495 } 496 497 pci_set_drvdata(pdev, netdev); 498 SET_NETDEV_DEV(netdev, &pdev->dev); 499 vf = netdev_priv(netdev); 500 vf->netdev = netdev; 501 vf->pdev = pdev; 502 vf->dev = dev; 503 vf->iommu_domain = iommu_get_domain_for_dev(dev); 504 505 vf->flags |= OTX2_FLAG_INTF_DOWN; 506 hw = &vf->hw; 507 hw->pdev = vf->pdev; 508 hw->rx_queues = qcount; 509 hw->tx_queues = qcount; 510 hw->max_queues = qcount; 511 512 hw->irq_name = devm_kmalloc_array(&hw->pdev->dev, num_vec, NAME_SIZE, 513 GFP_KERNEL); 514 if (!hw->irq_name) { 515 err = -ENOMEM; 516 goto err_free_netdev; 517 } 518 519 hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec, 520 sizeof(cpumask_var_t), GFP_KERNEL); 521 if (!hw->affinity_mask) { 522 err = -ENOMEM; 523 goto err_free_netdev; 524 } 525 526 err = pci_alloc_irq_vectors(hw->pdev, num_vec, num_vec, PCI_IRQ_MSIX); 527 if (err < 0) { 528 dev_err(dev, "%s: Failed to alloc %d IRQ vectors\n", 529 __func__, num_vec); 530 goto err_free_netdev; 531 } 532 533 vf->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0); 534 if (!vf->reg_base) { 535 dev_err(dev, "Unable to map physical function CSRs, aborting\n"); 536 err = -ENOMEM; 537 goto err_free_irq_vectors; 538 } 539 540 otx2_setup_dev_hw_settings(vf); 541 /* Init VF <=> PF mailbox stuff */ 542 err = otx2vf_vfaf_mbox_init(vf); 543 if (err) 544 goto err_free_irq_vectors; 545 546 /* Register mailbox interrupt */ 547 err = otx2vf_register_mbox_intr(vf, true); 548 if (err) 549 goto err_mbox_destroy; 550 551 /* Request AF to attach NPA and LIX LFs to this AF */ 552 err = otx2_attach_npa_nix(vf); 553 if (err) 554 goto err_disable_mbox_intr; 555 556 err = otx2vf_realloc_msix_vectors(vf); 557 if (err) 558 goto err_mbox_destroy; 559 560 err = otx2_set_real_num_queues(netdev, qcount, qcount); 561 if (err) 562 goto err_detach_rsrc; 563 564 err = cn10k_vf_lmtst_init(vf); 565 if (err) 566 goto err_detach_rsrc; 567 568 /* Assign default mac address */ 569 otx2_get_mac_from_af(netdev); 570 571 netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | 572 NETIF_F_IPV6_CSUM | NETIF_F_RXHASH | 573 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | 574 NETIF_F_GSO_UDP_L4; 575 netdev->features = netdev->hw_features; 576 /* Support TSO on tag interface */ 577 netdev->vlan_features |= netdev->features; 578 netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | 579 NETIF_F_HW_VLAN_STAG_TX; 580 netdev->features |= netdev->hw_features; 581 582 netdev->gso_max_segs = OTX2_MAX_GSO_SEGS; 583 netdev->watchdog_timeo = OTX2_TX_TIMEOUT; 584 585 netdev->netdev_ops = &otx2vf_netdev_ops; 586 587 /* MTU range: 68 - 9190 */ 588 netdev->min_mtu = OTX2_MIN_MTU; 589 netdev->max_mtu = otx2_get_max_mtu(vf); 590 591 INIT_WORK(&vf->reset_task, otx2vf_reset_task); 592 593 /* To distinguish, for LBK VFs set netdev name explicitly */ 594 if (is_otx2_lbkvf(vf->pdev)) { 595 int n; 596 597 n = (vf->pcifunc >> RVU_PFVF_FUNC_SHIFT) & RVU_PFVF_FUNC_MASK; 598 /* Need to subtract 1 to get proper VF number */ 599 n -= 1; 600 snprintf(netdev->name, sizeof(netdev->name), "lbk%d", n); 601 } 602 603 err = register_netdev(netdev); 604 if (err) { 605 dev_err(dev, "Failed to register netdevice\n"); 606 goto err_detach_rsrc; 607 } 608 609 otx2vf_set_ethtool_ops(netdev); 610 611 /* Enable pause frames by default */ 612 vf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED; 613 vf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED; 614 615 return 0; 616 617 err_detach_rsrc: 618 if (hw->lmt_base) 619 iounmap(hw->lmt_base); 620 otx2_detach_resources(&vf->mbox); 621 err_disable_mbox_intr: 622 otx2vf_disable_mbox_intr(vf); 623 err_mbox_destroy: 624 otx2vf_vfaf_mbox_destroy(vf); 625 err_free_irq_vectors: 626 pci_free_irq_vectors(hw->pdev); 627 err_free_netdev: 628 pci_set_drvdata(pdev, NULL); 629 free_netdev(netdev); 630 err_release_regions: 631 pci_release_regions(pdev); 632 return err; 633 } 634 635 static void otx2vf_remove(struct pci_dev *pdev) 636 { 637 struct net_device *netdev = pci_get_drvdata(pdev); 638 struct otx2_nic *vf; 639 640 if (!netdev) 641 return; 642 643 vf = netdev_priv(netdev); 644 645 cancel_work_sync(&vf->reset_task); 646 unregister_netdev(netdev); 647 otx2vf_disable_mbox_intr(vf); 648 otx2_detach_resources(&vf->mbox); 649 650 if (vf->hw.lmt_base) 651 iounmap(vf->hw.lmt_base); 652 653 otx2vf_vfaf_mbox_destroy(vf); 654 pci_free_irq_vectors(vf->pdev); 655 pci_set_drvdata(pdev, NULL); 656 free_netdev(netdev); 657 658 pci_release_regions(pdev); 659 } 660 661 static struct pci_driver otx2vf_driver = { 662 .name = DRV_NAME, 663 .id_table = otx2_vf_id_table, 664 .probe = otx2vf_probe, 665 .remove = otx2vf_remove, 666 .shutdown = otx2vf_remove, 667 }; 668 669 static int __init otx2vf_init_module(void) 670 { 671 pr_info("%s: %s\n", DRV_NAME, DRV_STRING); 672 673 return pci_register_driver(&otx2vf_driver); 674 } 675 676 static void __exit otx2vf_cleanup_module(void) 677 { 678 pci_unregister_driver(&otx2vf_driver); 679 } 680 681 module_init(otx2vf_init_module); 682 module_exit(otx2vf_cleanup_module); 683