igc_main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #include <linux/module.h>
  4. #include <linux/types.h>
  5. #include "igc.h"
  6. #include "igc_hw.h"
  7. #define DRV_VERSION "0.0.1-k"
  8. #define DRV_SUMMARY "Intel(R) 2.5G Ethernet Linux Driver"
  9. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  10. MODULE_DESCRIPTION(DRV_SUMMARY);
  11. MODULE_LICENSE("GPL v2");
  12. MODULE_VERSION(DRV_VERSION);
  13. char igc_driver_name[] = "igc";
  14. char igc_driver_version[] = DRV_VERSION;
  15. static const char igc_driver_string[] = DRV_SUMMARY;
  16. static const char igc_copyright[] =
  17. "Copyright(c) 2018 Intel Corporation.";
  18. static const struct pci_device_id igc_pci_tbl[] = {
  19. { PCI_VDEVICE(INTEL, IGC_DEV_ID_I225_LM) },
  20. { PCI_VDEVICE(INTEL, IGC_DEV_ID_I225_V) },
  21. /* required last entry */
  22. {0, }
  23. };
  24. MODULE_DEVICE_TABLE(pci, igc_pci_tbl);
  25. /**
  26. * igc_probe - Device Initialization Routine
  27. * @pdev: PCI device information struct
  28. * @ent: entry in igc_pci_tbl
  29. *
  30. * Returns 0 on success, negative on failure
  31. *
  32. * igc_probe initializes an adapter identified by a pci_dev structure.
  33. * The OS initialization, configuring the adapter private structure,
  34. * and a hardware reset occur.
  35. */
  36. static int igc_probe(struct pci_dev *pdev,
  37. const struct pci_device_id *ent)
  38. {
  39. int err, pci_using_dac;
  40. err = pci_enable_device_mem(pdev);
  41. if (err)
  42. return err;
  43. pci_using_dac = 0;
  44. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  45. if (!err) {
  46. err = dma_set_coherent_mask(&pdev->dev,
  47. DMA_BIT_MASK(64));
  48. if (!err)
  49. pci_using_dac = 1;
  50. } else {
  51. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  52. if (err) {
  53. err = dma_set_coherent_mask(&pdev->dev,
  54. DMA_BIT_MASK(32));
  55. if (err) {
  56. IGC_ERR("Wrong DMA configuration, aborting\n");
  57. goto err_dma;
  58. }
  59. }
  60. }
  61. err = pci_request_selected_regions(pdev,
  62. pci_select_bars(pdev,
  63. IORESOURCE_MEM),
  64. igc_driver_name);
  65. if (err)
  66. goto err_pci_reg;
  67. pci_set_master(pdev);
  68. err = pci_save_state(pdev);
  69. return 0;
  70. err_pci_reg:
  71. err_dma:
  72. pci_disable_device(pdev);
  73. return err;
  74. }
  75. /**
  76. * igc_remove - Device Removal Routine
  77. * @pdev: PCI device information struct
  78. *
  79. * igc_remove is called by the PCI subsystem to alert the driver
  80. * that it should release a PCI device. This could be caused by a
  81. * Hot-Plug event, or because the driver is going to be removed from
  82. * memory.
  83. */
  84. static void igc_remove(struct pci_dev *pdev)
  85. {
  86. pci_release_selected_regions(pdev,
  87. pci_select_bars(pdev, IORESOURCE_MEM));
  88. pci_disable_device(pdev);
  89. }
  90. static struct pci_driver igc_driver = {
  91. .name = igc_driver_name,
  92. .id_table = igc_pci_tbl,
  93. .probe = igc_probe,
  94. .remove = igc_remove,
  95. };
  96. /**
  97. * igc_init_module - Driver Registration Routine
  98. *
  99. * igc_init_module is the first routine called when the driver is
  100. * loaded. All it does is register with the PCI subsystem.
  101. */
  102. static int __init igc_init_module(void)
  103. {
  104. int ret;
  105. pr_info("%s - version %s\n",
  106. igc_driver_string, igc_driver_version);
  107. pr_info("%s\n", igc_copyright);
  108. ret = pci_register_driver(&igc_driver);
  109. return ret;
  110. }
  111. module_init(igc_init_module);
  112. /**
  113. * igc_exit_module - Driver Exit Cleanup Routine
  114. *
  115. * igc_exit_module is called just before the driver is removed
  116. * from memory.
  117. */
  118. static void __exit igc_exit_module(void)
  119. {
  120. pci_unregister_driver(&igc_driver);
  121. }
  122. module_exit(igc_exit_module);
  123. /* igc_main.c */