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