diff options
Diffstat (limited to 'drivers/net/ethernet/intel/igc/igc_main.c')
-rw-r--r-- | drivers/net/ethernet/intel/igc/igc_main.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 753749ce5ae0..6a881753f5ce 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c | |||
@@ -30,6 +30,69 @@ static const struct pci_device_id igc_pci_tbl[] = { | |||
30 | 30 | ||
31 | MODULE_DEVICE_TABLE(pci, igc_pci_tbl); | 31 | MODULE_DEVICE_TABLE(pci, igc_pci_tbl); |
32 | 32 | ||
33 | /* forward declaration */ | ||
34 | static int igc_sw_init(struct igc_adapter *); | ||
35 | |||
36 | /* PCIe configuration access */ | ||
37 | void igc_read_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value) | ||
38 | { | ||
39 | struct igc_adapter *adapter = hw->back; | ||
40 | |||
41 | pci_read_config_word(adapter->pdev, reg, value); | ||
42 | } | ||
43 | |||
44 | void igc_write_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value) | ||
45 | { | ||
46 | struct igc_adapter *adapter = hw->back; | ||
47 | |||
48 | pci_write_config_word(adapter->pdev, reg, *value); | ||
49 | } | ||
50 | |||
51 | s32 igc_read_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value) | ||
52 | { | ||
53 | struct igc_adapter *adapter = hw->back; | ||
54 | u16 cap_offset; | ||
55 | |||
56 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); | ||
57 | if (!cap_offset) | ||
58 | return -IGC_ERR_CONFIG; | ||
59 | |||
60 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); | ||
61 | |||
62 | return IGC_SUCCESS; | ||
63 | } | ||
64 | |||
65 | s32 igc_write_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value) | ||
66 | { | ||
67 | struct igc_adapter *adapter = hw->back; | ||
68 | u16 cap_offset; | ||
69 | |||
70 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); | ||
71 | if (!cap_offset) | ||
72 | return -IGC_ERR_CONFIG; | ||
73 | |||
74 | pci_write_config_word(adapter->pdev, cap_offset + reg, *value); | ||
75 | |||
76 | return IGC_SUCCESS; | ||
77 | } | ||
78 | |||
79 | u32 igc_rd32(struct igc_hw *hw, u32 reg) | ||
80 | { | ||
81 | u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr); | ||
82 | u32 value = 0; | ||
83 | |||
84 | if (IGC_REMOVED(hw_addr)) | ||
85 | return ~value; | ||
86 | |||
87 | value = readl(&hw_addr[reg]); | ||
88 | |||
89 | /* reads should not return all F's */ | ||
90 | if (!(~value) && (!reg || !(~readl(hw_addr)))) | ||
91 | hw->hw_addr = NULL; | ||
92 | |||
93 | return value; | ||
94 | } | ||
95 | |||
33 | /** | 96 | /** |
34 | * igc_probe - Device Initialization Routine | 97 | * igc_probe - Device Initialization Routine |
35 | * @pdev: PCI device information struct | 98 | * @pdev: PCI device information struct |
@@ -44,6 +107,7 @@ MODULE_DEVICE_TABLE(pci, igc_pci_tbl); | |||
44 | static int igc_probe(struct pci_dev *pdev, | 107 | static int igc_probe(struct pci_dev *pdev, |
45 | const struct pci_device_id *ent) | 108 | const struct pci_device_id *ent) |
46 | { | 109 | { |
110 | struct igc_adapter *adapter; | ||
47 | int err, pci_using_dac; | 111 | int err, pci_using_dac; |
48 | 112 | ||
49 | err = pci_enable_device_mem(pdev); | 113 | err = pci_enable_device_mem(pdev); |
@@ -78,8 +142,15 @@ static int igc_probe(struct pci_dev *pdev, | |||
78 | 142 | ||
79 | pci_set_master(pdev); | 143 | pci_set_master(pdev); |
80 | err = pci_save_state(pdev); | 144 | err = pci_save_state(pdev); |
145 | |||
146 | /* setup the private structure */ | ||
147 | err = igc_sw_init(adapter); | ||
148 | if (err) | ||
149 | goto err_sw_init; | ||
150 | |||
81 | return 0; | 151 | return 0; |
82 | 152 | ||
153 | err_sw_init: | ||
83 | err_pci_reg: | 154 | err_pci_reg: |
84 | err_dma: | 155 | err_dma: |
85 | pci_disable_device(pdev); | 156 | pci_disable_device(pdev); |
@@ -111,6 +182,33 @@ static struct pci_driver igc_driver = { | |||
111 | }; | 182 | }; |
112 | 183 | ||
113 | /** | 184 | /** |
185 | * igc_sw_init - Initialize general software structures (struct igc_adapter) | ||
186 | * @adapter: board private structure to initialize | ||
187 | * | ||
188 | * igc_sw_init initializes the Adapter private data structure. | ||
189 | * Fields are initialized based on PCI device information and | ||
190 | * OS network device settings (MTU size). | ||
191 | */ | ||
192 | static int igc_sw_init(struct igc_adapter *adapter) | ||
193 | { | ||
194 | struct pci_dev *pdev = adapter->pdev; | ||
195 | struct igc_hw *hw = &adapter->hw; | ||
196 | |||
197 | /* PCI config space info */ | ||
198 | |||
199 | hw->vendor_id = pdev->vendor; | ||
200 | hw->device_id = pdev->device; | ||
201 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | ||
202 | hw->subsystem_device_id = pdev->subsystem_device; | ||
203 | |||
204 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | ||
205 | |||
206 | pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | /** | ||
114 | * igc_init_module - Driver Registration Routine | 212 | * igc_init_module - Driver Registration Routine |
115 | * | 213 | * |
116 | * igc_init_module is the first routine called when the driver is | 214 | * igc_init_module is the first routine called when the driver is |