ef100.c (7e773594dada10f60c16c7085e0f0760122af8a7) ef100.c (98ff4c7c8ac7f5339aac6114105395fea19f992e)
1// SPDX-License-Identifier: GPL-2.0-only
2/****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2005-2018 Solarflare Communications Inc.
5 * Copyright 2019-2022 Xilinx Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published

--- 409 unchanged lines hidden (view full) ---

418}
419
420/* Final NIC shutdown
421 * This is called only at module unload (or hotplug removal). A PF can call
422 * this on its VFs to ensure they are unbound first.
423 */
424static void ef100_pci_remove(struct pci_dev *pci_dev)
425{
1// SPDX-License-Identifier: GPL-2.0-only
2/****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2005-2018 Solarflare Communications Inc.
5 * Copyright 2019-2022 Xilinx Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published

--- 409 unchanged lines hidden (view full) ---

418}
419
420/* Final NIC shutdown
421 * This is called only at module unload (or hotplug removal). A PF can call
422 * this on its VFs to ensure they are unbound first.
423 */
424static void ef100_pci_remove(struct pci_dev *pci_dev)
425{
426 struct efx_nic *efx = pci_get_drvdata(pci_dev);
426 struct efx_probe_data *probe_data;
427 struct efx_probe_data *probe_data;
427 struct efx_nic *efx;
428
428
429 efx = pci_get_drvdata(pci_dev);
430 if (!efx)
431 return;
432
429 if (!efx)
430 return;
431
433 rtnl_lock();
434 dev_close(efx->net_dev);
435 rtnl_unlock();
432 probe_data = container_of(efx, struct efx_probe_data, efx);
433 ef100_remove_netdev(probe_data);
436
434
437 /* Unregistering our netdev notifier triggers unbinding of TC indirect
438 * blocks, so we have to do it before PCI removal.
439 */
440 unregister_netdevice_notifier(&efx->netdev_notifier);
441#if defined(CONFIG_SFC_SRIOV)
442 if (!efx->type->is_vf)
443 efx_ef100_pci_sriov_disable(efx);
444#endif
445 ef100_remove(efx);
446 efx_fini_io(efx);
435 ef100_remove(efx);
436 efx_fini_io(efx);
447 netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
448
437
438 pci_dbg(pci_dev, "shutdown successful\n");
439
440 pci_disable_pcie_error_reporting(pci_dev);
441
449 pci_set_drvdata(pci_dev, NULL);
450 efx_fini_struct(efx);
442 pci_set_drvdata(pci_dev, NULL);
443 efx_fini_struct(efx);
451 free_netdev(efx->net_dev);
452 probe_data = container_of(efx, struct efx_probe_data, efx);
453 kfree(probe_data);
444 kfree(probe_data);
454
455 pci_disable_pcie_error_reporting(pci_dev);
456};
457
458static int ef100_pci_probe(struct pci_dev *pci_dev,
459 const struct pci_device_id *entry)
460{
445};
446
447static int ef100_pci_probe(struct pci_dev *pci_dev,
448 const struct pci_device_id *entry)
449{
461 struct efx_probe_data *probe_data, **probe_ptr;
462 struct ef100_func_ctl_window fcw = { 0 };
450 struct ef100_func_ctl_window fcw = { 0 };
463 struct net_device *net_dev;
451 struct efx_probe_data *probe_data;
464 struct efx_nic *efx;
465 int rc;
466
467 /* Allocate probe data and struct efx_nic */
468 probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL);
469 if (!probe_data)
470 return -ENOMEM;
471 probe_data->pci_dev = pci_dev;
472 efx = &probe_data->efx;
473
452 struct efx_nic *efx;
453 int rc;
454
455 /* Allocate probe data and struct efx_nic */
456 probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL);
457 if (!probe_data)
458 return -ENOMEM;
459 probe_data->pci_dev = pci_dev;
460 efx = &probe_data->efx;
461
474 /* Allocate and initialise a struct net_device */
475 net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES);
476 if (!net_dev)
477 return -ENOMEM;
478 probe_ptr = netdev_priv(net_dev);
479 *probe_ptr = probe_data;
480 efx->type = (const struct efx_nic_type *)entry->driver_data;
481
462 efx->type = (const struct efx_nic_type *)entry->driver_data;
463
464 efx->pci_dev = pci_dev;
482 pci_set_drvdata(pci_dev, efx);
465 pci_set_drvdata(pci_dev, efx);
483 SET_NETDEV_DEV(net_dev, &pci_dev->dev);
484 efx->net_dev = net_dev;
485 rc = efx_init_struct(efx, pci_dev);
486 if (rc)
487 goto fail;
488
466 rc = efx_init_struct(efx, pci_dev);
467 if (rc)
468 goto fail;
469
489 efx->mdio.dev = net_dev;
490 efx->vi_stride = EF100_DEFAULT_VI_STRIDE;
470 efx->vi_stride = EF100_DEFAULT_VI_STRIDE;
491 netif_info(efx, probe, efx->net_dev,
492 "Solarflare EF100 NIC detected\n");
471 pci_info(pci_dev, "Solarflare EF100 NIC detected\n");
493
494 rc = ef100_pci_find_func_ctrl_window(efx, &fcw);
495 if (rc) {
472
473 rc = ef100_pci_find_func_ctrl_window(efx, &fcw);
474 if (rc) {
496 netif_err(efx, probe, efx->net_dev,
497 "Error looking for ef100 function control window, rc=%d\n",
498 rc);
475 pci_err(pci_dev,
476 "Error looking for ef100 function control window, rc=%d\n",
477 rc);
499 goto fail;
500 }
501
502 if (!fcw.valid) {
503 /* Extended capability not found - use defaults. */
504 fcw.bar = EFX_EF100_PCI_DEFAULT_BAR;
505 fcw.offset = 0;
506 fcw.valid = true;
507 }
508
509 if (fcw.offset > pci_resource_len(efx->pci_dev, fcw.bar) - ESE_GZ_FCW_LEN) {
478 goto fail;
479 }
480
481 if (!fcw.valid) {
482 /* Extended capability not found - use defaults. */
483 fcw.bar = EFX_EF100_PCI_DEFAULT_BAR;
484 fcw.offset = 0;
485 fcw.valid = true;
486 }
487
488 if (fcw.offset > pci_resource_len(efx->pci_dev, fcw.bar) - ESE_GZ_FCW_LEN) {
510 netif_err(efx, probe, efx->net_dev,
511 "Func control window overruns BAR\n");
489 pci_err(pci_dev, "Func control window overruns BAR\n");
512 rc = -EIO;
513 goto fail;
514 }
515
516 /* Set up basic I/O (BAR mappings etc) */
517 rc = efx_init_io(efx, fcw.bar,
518 (dma_addr_t)DMA_BIT_MASK(ESF_GZ_TX_SEND_ADDR_WIDTH),
519 pci_resource_len(efx->pci_dev, fcw.bar));
520 if (rc)
521 goto fail;
522
523 efx->reg_base = fcw.offset;
524
490 rc = -EIO;
491 goto fail;
492 }
493
494 /* Set up basic I/O (BAR mappings etc) */
495 rc = efx_init_io(efx, fcw.bar,
496 (dma_addr_t)DMA_BIT_MASK(ESF_GZ_TX_SEND_ADDR_WIDTH),
497 pci_resource_len(efx->pci_dev, fcw.bar));
498 if (rc)
499 goto fail;
500
501 efx->reg_base = fcw.offset;
502
525 efx->netdev_notifier.notifier_call = ef100_netdev_event;
526 rc = register_netdevice_notifier(&efx->netdev_notifier);
527 if (rc) {
528 netif_err(efx, probe, efx->net_dev,
529 "Failed to register netdevice notifier, rc=%d\n", rc);
503 rc = efx->type->probe(efx);
504 if (rc)
530 goto fail;
505 goto fail;
531 }
532
506
533 rc = efx->type->probe(efx);
507 efx->state = STATE_PROBED;
508 rc = ef100_probe_netdev(probe_data);
534 if (rc)
535 goto fail;
536
509 if (rc)
510 goto fail;
511
537 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
512 pci_dbg(pci_dev, "initialisation successful\n");
538
539 return 0;
540
541fail:
542 ef100_pci_remove(pci_dev);
543 return rc;
544}
545

--- 38 unchanged lines hidden ---
513
514 return 0;
515
516fail:
517 ef100_pci_remove(pci_dev);
518 return rc;
519}
520

--- 38 unchanged lines hidden ---