12089cedbe56704b762605c8b8dc4920266221e5
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k_pci.c
1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
21 #include <linux/module.h>
22
23 #include "fm10k.h"
24
25 /**
26 * fm10k_pci_tbl - PCI Device ID Table
27 *
28 * Wildcard entries (PCI_ANY_ID) should come last
29 * Last entry must be all 0s
30 *
31 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
32 * Class, Class Mask, private data (not used) }
33 */
34 static const struct pci_device_id fm10k_pci_tbl[] = {
35 { PCI_VDEVICE(INTEL, FM10K_DEV_ID_PF) },
36 /* required last entry */
37 { 0, }
38 };
39 MODULE_DEVICE_TABLE(pci, fm10k_pci_tbl);
40
41 /**
42 * fm10k_probe - Device Initialization Routine
43 * @pdev: PCI device information struct
44 * @ent: entry in fm10k_pci_tbl
45 *
46 * Returns 0 on success, negative on failure
47 *
48 * fm10k_probe initializes an interface identified by a pci_dev structure.
49 * The OS initialization, configuring of the interface private structure,
50 * and a hardware reset occur.
51 **/
52 static int fm10k_probe(struct pci_dev *pdev,
53 const struct pci_device_id *ent)
54 {
55 int err;
56 u64 dma_mask;
57
58 err = pci_enable_device_mem(pdev);
59 if (err)
60 return err;
61
62 /* By default fm10k only supports a 48 bit DMA mask */
63 dma_mask = DMA_BIT_MASK(48) | dma_get_required_mask(&pdev->dev);
64
65 if ((dma_mask <= DMA_BIT_MASK(32)) ||
66 dma_set_mask_and_coherent(&pdev->dev, dma_mask)) {
67 dma_mask &= DMA_BIT_MASK(32);
68
69 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
70 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
71 if (err) {
72 err = dma_set_coherent_mask(&pdev->dev,
73 DMA_BIT_MASK(32));
74 if (err) {
75 dev_err(&pdev->dev,
76 "No usable DMA configuration, aborting\n");
77 goto err_dma;
78 }
79 }
80 }
81
82 err = pci_request_selected_regions(pdev,
83 pci_select_bars(pdev,
84 IORESOURCE_MEM),
85 fm10k_driver_name);
86 if (err) {
87 dev_err(&pdev->dev,
88 "pci_request_selected_regions failed 0x%x\n", err);
89 goto err_pci_reg;
90 }
91
92 pci_set_master(pdev);
93 pci_save_state(pdev);
94
95 return 0;
96
97 err_pci_reg:
98 err_dma:
99 pci_disable_device(pdev);
100 return err;
101 }
102
103 /**
104 * fm10k_remove - Device Removal Routine
105 * @pdev: PCI device information struct
106 *
107 * fm10k_remove is called by the PCI subsystem to alert the driver
108 * that it should release a PCI device. The could be caused by a
109 * Hot-Plug event, or because the driver is going to be removed from
110 * memory.
111 **/
112 static void fm10k_remove(struct pci_dev *pdev)
113 {
114 pci_release_selected_regions(pdev,
115 pci_select_bars(pdev, IORESOURCE_MEM));
116
117 pci_disable_device(pdev);
118 }
119
120 static struct pci_driver fm10k_driver = {
121 .name = fm10k_driver_name,
122 .id_table = fm10k_pci_tbl,
123 .probe = fm10k_probe,
124 .remove = fm10k_remove,
125 };
126
127 /**
128 * fm10k_register_pci_driver - register driver interface
129 *
130 * This funciton is called on module load in order to register the driver.
131 **/
132 int fm10k_register_pci_driver(void)
133 {
134 return pci_register_driver(&fm10k_driver);
135 }
136
137 /**
138 * fm10k_unregister_pci_driver - unregister driver interface
139 *
140 * This funciton is called on module unload in order to remove the driver.
141 **/
142 void fm10k_unregister_pci_driver(void)
143 {
144 pci_unregister_driver(&fm10k_driver);
145 }
This page took 0.037751 seconds and 4 git commands to generate.