ice_main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018, Intel Corporation. */
  3. /* Intel(R) Ethernet Connection E800 Series Linux Driver */
  4. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  5. #include "ice.h"
  6. #define DRV_VERSION "ice-0.0.1-k"
  7. #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
  8. static const char ice_drv_ver[] = DRV_VERSION;
  9. static const char ice_driver_string[] = DRV_SUMMARY;
  10. static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
  11. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  12. MODULE_DESCRIPTION(DRV_SUMMARY);
  13. MODULE_LICENSE("GPL");
  14. MODULE_VERSION(DRV_VERSION);
  15. static int debug = -1;
  16. module_param(debug, int, 0644);
  17. MODULE_PARM_DESC(debug, "netif message level (0=none,...,0x7FFF=all)");
  18. /**
  19. * ice_probe - Device initialization routine
  20. * @pdev: PCI device information struct
  21. * @ent: entry in ice_pci_tbl
  22. *
  23. * Returns 0 on success, negative on failure
  24. */
  25. static int ice_probe(struct pci_dev *pdev,
  26. const struct pci_device_id __always_unused *ent)
  27. {
  28. struct ice_pf *pf;
  29. struct ice_hw *hw;
  30. int err;
  31. /* this driver uses devres, see Documentation/driver-model/devres.txt */
  32. err = pcim_enable_device(pdev);
  33. if (err)
  34. return err;
  35. err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
  36. if (err) {
  37. dev_err(&pdev->dev, "I/O map error %d\n", err);
  38. return err;
  39. }
  40. pf = devm_kzalloc(&pdev->dev, sizeof(*pf), GFP_KERNEL);
  41. if (!pf)
  42. return -ENOMEM;
  43. /* set up for high or low dma */
  44. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  45. if (err)
  46. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  47. if (err) {
  48. dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
  49. return err;
  50. }
  51. pci_enable_pcie_error_reporting(pdev);
  52. pci_set_master(pdev);
  53. pf->pdev = pdev;
  54. pci_set_drvdata(pdev, pf);
  55. set_bit(__ICE_DOWN, pf->state);
  56. hw = &pf->hw;
  57. hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
  58. hw->back = pf;
  59. hw->vendor_id = pdev->vendor;
  60. hw->device_id = pdev->device;
  61. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  62. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  63. hw->subsystem_device_id = pdev->subsystem_device;
  64. hw->bus.device = PCI_SLOT(pdev->devfn);
  65. hw->bus.func = PCI_FUNC(pdev->devfn);
  66. pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
  67. return 0;
  68. }
  69. /**
  70. * ice_remove - Device removal routine
  71. * @pdev: PCI device information struct
  72. */
  73. static void ice_remove(struct pci_dev *pdev)
  74. {
  75. struct ice_pf *pf = pci_get_drvdata(pdev);
  76. if (!pf)
  77. return;
  78. set_bit(__ICE_DOWN, pf->state);
  79. pci_disable_pcie_error_reporting(pdev);
  80. }
  81. /* ice_pci_tbl - PCI Device ID Table
  82. *
  83. * Wildcard entries (PCI_ANY_ID) should come last
  84. * Last entry must be all 0s
  85. *
  86. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  87. * Class, Class Mask, private data (not used) }
  88. */
  89. static const struct pci_device_id ice_pci_tbl[] = {
  90. { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_BACKPLANE), 0 },
  91. { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_QSFP), 0 },
  92. { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_SFP), 0 },
  93. { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_10G_BASE_T), 0 },
  94. { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_SGMII), 0 },
  95. /* required last entry */
  96. { 0, }
  97. };
  98. MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
  99. static struct pci_driver ice_driver = {
  100. .name = KBUILD_MODNAME,
  101. .id_table = ice_pci_tbl,
  102. .probe = ice_probe,
  103. .remove = ice_remove,
  104. };
  105. /**
  106. * ice_module_init - Driver registration routine
  107. *
  108. * ice_module_init is the first routine called when the driver is
  109. * loaded. All it does is register with the PCI subsystem.
  110. */
  111. static int __init ice_module_init(void)
  112. {
  113. int status;
  114. pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
  115. pr_info("%s\n", ice_copyright);
  116. status = pci_register_driver(&ice_driver);
  117. if (status)
  118. pr_err("failed to register pci driver, err %d\n", status);
  119. return status;
  120. }
  121. module_init(ice_module_init);
  122. /**
  123. * ice_module_exit - Driver exit cleanup routine
  124. *
  125. * ice_module_exit is called just before the driver is removed
  126. * from memory.
  127. */
  128. static void __exit ice_module_exit(void)
  129. {
  130. pci_unregister_driver(&ice_driver);
  131. pr_info("module unloaded\n");
  132. }
  133. module_exit(ice_module_exit);