igc_i225.c revision 1.2 1 1.2 rin /* $NetBSD: igc_i225.c,v 1.2 2023/10/04 07:35:27 rin Exp $ */
2 1.1 rin /* $OpenBSD: igc_i225.c,v 1.4 2023/02/03 11:31:52 mbuhl Exp $ */
3 1.1 rin /*-
4 1.1 rin * Copyright 2021 Intel Corp
5 1.1 rin * Copyright 2021 Rubicon Communications, LLC (Netgate)
6 1.1 rin * SPDX-License-Identifier: BSD-3-Clause
7 1.1 rin */
8 1.1 rin
9 1.2 rin #include <sys/cdefs.h>
10 1.2 rin __KERNEL_RCSID(0, "$NetBSD: igc_i225.c,v 1.2 2023/10/04 07:35:27 rin Exp $");
11 1.2 rin
12 1.2 rin #include <dev/pci/igc/igc_api.h>
13 1.1 rin
14 1.1 rin int igc_init_nvm_params_i225(struct igc_hw *);
15 1.1 rin int igc_init_mac_params_i225(struct igc_hw *);
16 1.1 rin int igc_init_phy_params_i225(struct igc_hw *);
17 1.1 rin int igc_reset_hw_i225(struct igc_hw *);
18 1.1 rin int igc_acquire_nvm_i225(struct igc_hw *);
19 1.1 rin void igc_release_nvm_i225(struct igc_hw *);
20 1.1 rin int igc_get_hw_semaphore_i225(struct igc_hw *);
21 1.1 rin int __igc_write_nvm_srwr(struct igc_hw *, uint16_t, uint16_t, uint16_t *);
22 1.1 rin int igc_pool_flash_update_done_i225(struct igc_hw *);
23 1.1 rin
24 1.1 rin /**
25 1.1 rin * igc_init_nvm_params_i225 - Init NVM func ptrs.
26 1.1 rin * @hw: pointer to the HW structure
27 1.1 rin **/
28 1.1 rin int
29 1.1 rin igc_init_nvm_params_i225(struct igc_hw *hw)
30 1.1 rin {
31 1.1 rin struct igc_nvm_info *nvm = &hw->nvm;
32 1.1 rin uint32_t eecd = IGC_READ_REG(hw, IGC_EECD);
33 1.1 rin uint16_t size;
34 1.1 rin
35 1.1 rin DEBUGFUNC("igc_init_nvm_params_i225");
36 1.1 rin
37 1.1 rin size = (uint16_t)((eecd & IGC_EECD_SIZE_EX_MASK) >>
38 1.1 rin IGC_EECD_SIZE_EX_SHIFT);
39 1.1 rin /*
40 1.1 rin * Added to a constant, "size" becomes the left-shift value
41 1.1 rin * for setting word_size.
42 1.1 rin */
43 1.1 rin size += NVM_WORD_SIZE_BASE_SHIFT;
44 1.1 rin
45 1.1 rin /* Just in case size is out of range, cap it to the largest
46 1.1 rin * EEPROM size supported.
47 1.1 rin */
48 1.1 rin if (size > 15)
49 1.1 rin size = 15;
50 1.1 rin
51 1.1 rin nvm->word_size = 1 << size;
52 1.1 rin nvm->opcode_bits = 8;
53 1.1 rin nvm->delay_usec = 1;
54 1.1 rin nvm->type = igc_nvm_eeprom_spi;
55 1.1 rin
56 1.1 rin nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
57 1.1 rin nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ? 16 : 8;
58 1.1 rin
59 1.1 rin if (nvm->word_size == (1 << 15))
60 1.1 rin nvm->page_size = 128;
61 1.1 rin
62 1.1 rin nvm->ops.acquire = igc_acquire_nvm_i225;
63 1.1 rin nvm->ops.release = igc_release_nvm_i225;
64 1.1 rin if (igc_get_flash_presence_i225(hw)) {
65 1.1 rin hw->nvm.type = igc_nvm_flash_hw;
66 1.1 rin nvm->ops.read = igc_read_nvm_srrd_i225;
67 1.1 rin nvm->ops.write = igc_write_nvm_srwr_i225;
68 1.1 rin nvm->ops.validate = igc_validate_nvm_checksum_i225;
69 1.1 rin nvm->ops.update = igc_update_nvm_checksum_i225;
70 1.1 rin } else {
71 1.1 rin hw->nvm.type = igc_nvm_invm;
72 1.1 rin nvm->ops.write = igc_null_write_nvm;
73 1.1 rin nvm->ops.validate = igc_null_ops_generic;
74 1.1 rin nvm->ops.update = igc_null_ops_generic;
75 1.1 rin }
76 1.1 rin
77 1.1 rin return IGC_SUCCESS;
78 1.1 rin }
79 1.1 rin
80 1.1 rin /**
81 1.1 rin * igc_init_mac_params_i225 - Init MAC func ptrs.
82 1.1 rin * @hw: pointer to the HW structure
83 1.1 rin **/
84 1.1 rin int
85 1.1 rin igc_init_mac_params_i225(struct igc_hw *hw)
86 1.1 rin {
87 1.1 rin struct igc_mac_info *mac = &hw->mac;
88 1.1 rin struct igc_dev_spec_i225 *dev_spec = &hw->dev_spec._i225;
89 1.1 rin
90 1.1 rin DEBUGFUNC("igc_init_mac_params_i225");
91 1.1 rin
92 1.1 rin /* Initialize function pointer */
93 1.1 rin igc_init_mac_ops_generic(hw);
94 1.1 rin
95 1.1 rin /* Set media type */
96 1.1 rin hw->phy.media_type = igc_media_type_copper;
97 1.1 rin /* Set mta register count */
98 1.1 rin mac->mta_reg_count = 128;
99 1.1 rin /* Set rar entry count */
100 1.1 rin mac->rar_entry_count = IGC_RAR_ENTRIES_BASE;
101 1.1 rin
102 1.1 rin /* reset */
103 1.1 rin mac->ops.reset_hw = igc_reset_hw_i225;
104 1.1 rin /* hw initialization */
105 1.1 rin mac->ops.init_hw = igc_init_hw_i225;
106 1.1 rin /* link setup */
107 1.1 rin mac->ops.setup_link = igc_setup_link_generic;
108 1.1 rin /* check for link */
109 1.1 rin mac->ops.check_for_link = igc_check_for_link_i225;
110 1.1 rin /* link info */
111 1.1 rin mac->ops.get_link_up_info = igc_get_speed_and_duplex_copper_generic;
112 1.1 rin /* acquire SW_FW sync */
113 1.1 rin mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
114 1.1 rin /* release SW_FW sync */
115 1.1 rin mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
116 1.1 rin
117 1.1 rin /* Allow a single clear of the SW semaphore on I225 */
118 1.1 rin dev_spec->clear_semaphore_once = true;
119 1.1 rin mac->ops.setup_physical_interface = igc_setup_copper_link_i225;
120 1.1 rin
121 1.1 rin /* Set if part includes ASF firmware */
122 1.1 rin mac->asf_firmware_present = true;
123 1.1 rin
124 1.1 rin /* multicast address update */
125 1.1 rin mac->ops.update_mc_addr_list = igc_update_mc_addr_list_generic;
126 1.1 rin
127 1.1 rin mac->ops.write_vfta = igc_write_vfta_generic;
128 1.1 rin
129 1.1 rin return IGC_SUCCESS;
130 1.1 rin }
131 1.1 rin
132 1.1 rin /**
133 1.1 rin * igc_init_phy_params_i225 - Init PHY func ptrs.
134 1.1 rin * @hw: pointer to the HW structure
135 1.1 rin **/
136 1.1 rin int
137 1.1 rin igc_init_phy_params_i225(struct igc_hw *hw)
138 1.1 rin {
139 1.1 rin struct igc_phy_info *phy = &hw->phy;
140 1.1 rin int ret_val = IGC_SUCCESS;
141 1.1 rin
142 1.1 rin DEBUGFUNC("igc_init_phy_params_i225");
143 1.1 rin
144 1.1 rin if (hw->phy.media_type != igc_media_type_copper) {
145 1.1 rin phy->type = igc_phy_none;
146 1.1 rin goto out;
147 1.1 rin }
148 1.1 rin
149 1.1 rin phy->ops.power_up = igc_power_up_phy_copper;
150 1.1 rin phy->ops.power_down = igc_power_down_phy_copper_base;
151 1.1 rin phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;
152 1.1 rin phy->reset_delay_us = 100;
153 1.1 rin phy->ops.acquire = igc_acquire_phy_base;
154 1.1 rin phy->ops.check_reset_block = igc_check_reset_block_generic;
155 1.1 rin phy->ops.release = igc_release_phy_base;
156 1.1 rin phy->ops.reset = igc_phy_hw_reset_generic;
157 1.1 rin phy->ops.read_reg = igc_read_phy_reg_gpy;
158 1.1 rin phy->ops.write_reg = igc_write_phy_reg_gpy;
159 1.1 rin
160 1.1 rin /* Make sure the PHY is in a good state. Several people have reported
161 1.1 rin * firmware leaving the PHY's page select register set to something
162 1.1 rin * other than the default of zero, which causes the PHY ID read to
163 1.1 rin * access something other than the intended register.
164 1.1 rin */
165 1.1 rin ret_val = hw->phy.ops.reset(hw);
166 1.1 rin if (ret_val)
167 1.1 rin goto out;
168 1.1 rin
169 1.1 rin ret_val = igc_get_phy_id(hw);
170 1.1 rin phy->type = igc_phy_i225;
171 1.1 rin
172 1.1 rin out:
173 1.1 rin return ret_val;
174 1.1 rin }
175 1.1 rin
176 1.1 rin /**
177 1.1 rin * igc_reset_hw_i225 - Reset hardware
178 1.1 rin * @hw: pointer to the HW structure
179 1.1 rin *
180 1.1 rin * This resets the hardware into a known state.
181 1.1 rin **/
182 1.1 rin int
183 1.1 rin igc_reset_hw_i225(struct igc_hw *hw)
184 1.1 rin {
185 1.1 rin uint32_t ctrl;
186 1.1 rin int ret_val;
187 1.1 rin
188 1.1 rin DEBUGFUNC("igc_reset_hw_i225");
189 1.1 rin
190 1.1 rin /*
191 1.1 rin * Prevent the PCI-E bus from sticking if there is no TLP connection
192 1.1 rin * on the last TLP read/write transaction when MAC is reset.
193 1.1 rin */
194 1.1 rin ret_val = igc_disable_pcie_master_generic(hw);
195 1.1 rin if (ret_val)
196 1.1 rin DEBUGOUT("PCI-E Master disable polling has failed.\n");
197 1.1 rin
198 1.1 rin DEBUGOUT("Masking off all interrupts\n");
199 1.1 rin IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
200 1.1 rin
201 1.1 rin IGC_WRITE_REG(hw, IGC_RCTL, 0);
202 1.1 rin IGC_WRITE_REG(hw, IGC_TCTL, IGC_TCTL_PSP);
203 1.1 rin IGC_WRITE_FLUSH(hw);
204 1.1 rin
205 1.1 rin msec_delay(10);
206 1.1 rin
207 1.1 rin ctrl = IGC_READ_REG(hw, IGC_CTRL);
208 1.1 rin
209 1.1 rin DEBUGOUT("Issuing a global reset to MAC\n");
210 1.1 rin IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_DEV_RST);
211 1.1 rin
212 1.1 rin ret_val = igc_get_auto_rd_done_generic(hw);
213 1.1 rin if (ret_val) {
214 1.1 rin /*
215 1.1 rin * When auto config read does not complete, do not
216 1.1 rin * return with an error. This can happen in situations
217 1.1 rin * where there is no eeprom and prevents getting link.
218 1.1 rin */
219 1.1 rin DEBUGOUT("Auto Read Done did not complete\n");
220 1.1 rin }
221 1.1 rin
222 1.1 rin /* Clear any pending interrupt events. */
223 1.1 rin IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
224 1.1 rin IGC_READ_REG(hw, IGC_ICR);
225 1.1 rin
226 1.1 rin /* Install any alternate MAC address into RAR0 */
227 1.1 rin ret_val = igc_check_alt_mac_addr_generic(hw);
228 1.1 rin
229 1.1 rin return ret_val;
230 1.1 rin }
231 1.1 rin
232 1.1 rin /* igc_acquire_nvm_i225 - Request for access to EEPROM
233 1.1 rin * @hw: pointer to the HW structure
234 1.1 rin *
235 1.1 rin * Acquire the necessary semaphores for exclusive access to the EEPROM.
236 1.1 rin * Set the EEPROM access request bit and wait for EEPROM access grant bit.
237 1.1 rin * Return successful if access grant bit set, else clear the request for
238 1.1 rin * EEPROM access and return -IGC_ERR_NVM (-1).
239 1.1 rin */
240 1.1 rin int
241 1.1 rin igc_acquire_nvm_i225(struct igc_hw *hw)
242 1.1 rin {
243 1.1 rin int ret_val;
244 1.1 rin
245 1.1 rin DEBUGFUNC("igc_acquire_nvm_i225");
246 1.1 rin
247 1.1 rin ret_val = igc_acquire_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
248 1.1 rin
249 1.1 rin return ret_val;
250 1.1 rin }
251 1.1 rin
252 1.1 rin /* igc_release_nvm_i225 - Release exclusive access to EEPROM
253 1.1 rin * @hw: pointer to the HW structure
254 1.1 rin *
255 1.1 rin * Stop any current commands to the EEPROM and clear the EEPROM request bit,
256 1.1 rin * then release the semaphores acquired.
257 1.1 rin */
258 1.1 rin void
259 1.1 rin igc_release_nvm_i225(struct igc_hw *hw)
260 1.1 rin {
261 1.1 rin DEBUGFUNC("igc_release_nvm_i225");
262 1.1 rin
263 1.1 rin igc_release_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
264 1.1 rin }
265 1.1 rin
266 1.1 rin /* igc_acquire_swfw_sync_i225 - Acquire SW/FW semaphore
267 1.1 rin * @hw: pointer to the HW structure
268 1.1 rin * @mask: specifies which semaphore to acquire
269 1.1 rin *
270 1.1 rin * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
271 1.1 rin * will also specify which port we're acquiring the lock for.
272 1.1 rin */
273 1.1 rin int
274 1.1 rin igc_acquire_swfw_sync_i225(struct igc_hw *hw, uint16_t mask)
275 1.1 rin {
276 1.1 rin uint32_t swfw_sync;
277 1.1 rin uint32_t swmask = mask;
278 1.1 rin uint32_t fwmask = mask << 16;
279 1.1 rin int ret_val = IGC_SUCCESS;
280 1.1 rin int i = 0, timeout = 200; /* FIXME: find real value to use here */
281 1.1 rin
282 1.1 rin DEBUGFUNC("igc_acquire_swfw_sync_i225");
283 1.1 rin
284 1.1 rin while (i < timeout) {
285 1.1 rin if (igc_get_hw_semaphore_i225(hw)) {
286 1.1 rin ret_val = -IGC_ERR_SWFW_SYNC;
287 1.1 rin goto out;
288 1.1 rin }
289 1.1 rin
290 1.1 rin swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
291 1.1 rin if (!(swfw_sync & (fwmask | swmask)))
292 1.1 rin break;
293 1.1 rin
294 1.1 rin /* Firmware currently using resource (fwmask)
295 1.1 rin * or other software thread using resource (swmask)
296 1.1 rin */
297 1.1 rin igc_put_hw_semaphore_generic(hw);
298 1.1 rin msec_delay(5);
299 1.1 rin i++;
300 1.1 rin }
301 1.1 rin
302 1.1 rin if (i == timeout) {
303 1.1 rin DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
304 1.1 rin ret_val = -IGC_ERR_SWFW_SYNC;
305 1.1 rin goto out;
306 1.1 rin }
307 1.1 rin
308 1.1 rin swfw_sync |= swmask;
309 1.1 rin IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
310 1.1 rin
311 1.1 rin igc_put_hw_semaphore_generic(hw);
312 1.1 rin
313 1.1 rin out:
314 1.1 rin return ret_val;
315 1.1 rin }
316 1.1 rin
317 1.1 rin /* igc_release_swfw_sync_i225 - Release SW/FW semaphore
318 1.1 rin * @hw: pointer to the HW structure
319 1.1 rin * @mask: specifies which semaphore to acquire
320 1.1 rin *
321 1.1 rin * Release the SW/FW semaphore used to access the PHY or NVM. The mask
322 1.1 rin * will also specify which port we're releasing the lock for.
323 1.1 rin */
324 1.1 rin void
325 1.1 rin igc_release_swfw_sync_i225(struct igc_hw *hw, uint16_t mask)
326 1.1 rin {
327 1.1 rin uint32_t swfw_sync;
328 1.1 rin
329 1.1 rin DEBUGFUNC("igc_release_swfw_sync_i225");
330 1.1 rin
331 1.1 rin while (igc_get_hw_semaphore_i225(hw) != IGC_SUCCESS)
332 1.1 rin ; /* Empty */
333 1.1 rin
334 1.1 rin swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
335 1.1 rin swfw_sync &= ~mask;
336 1.1 rin IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
337 1.1 rin
338 1.1 rin igc_put_hw_semaphore_generic(hw);
339 1.1 rin }
340 1.1 rin
341 1.1 rin /*
342 1.1 rin * igc_setup_copper_link_i225 - Configure copper link settings
343 1.1 rin * @hw: pointer to the HW structure
344 1.1 rin *
345 1.1 rin * Configures the link for auto-neg or forced speed and duplex. Then we check
346 1.1 rin * for link, once link is established calls to configure collision distance
347 1.1 rin * and flow control are called.
348 1.1 rin */
349 1.1 rin int
350 1.1 rin igc_setup_copper_link_i225(struct igc_hw *hw)
351 1.1 rin {
352 1.1 rin uint32_t ctrl, phpm_reg;
353 1.1 rin int ret_val;
354 1.1 rin
355 1.1 rin DEBUGFUNC("igc_setup_copper_link_i225");
356 1.1 rin
357 1.1 rin ctrl = IGC_READ_REG(hw, IGC_CTRL);
358 1.1 rin ctrl |= IGC_CTRL_SLU;
359 1.1 rin ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
360 1.1 rin IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
361 1.1 rin
362 1.1 rin phpm_reg = IGC_READ_REG(hw, IGC_I225_PHPM);
363 1.1 rin phpm_reg &= ~IGC_I225_PHPM_GO_LINKD;
364 1.1 rin IGC_WRITE_REG(hw, IGC_I225_PHPM, phpm_reg);
365 1.1 rin
366 1.1 rin ret_val = igc_setup_copper_link_generic(hw);
367 1.1 rin
368 1.1 rin return ret_val;
369 1.1 rin }
370 1.1 rin
371 1.1 rin /* igc_get_hw_semaphore_i225 - Acquire hardware semaphore
372 1.1 rin * @hw: pointer to the HW structure
373 1.1 rin *
374 1.1 rin * Acquire the HW semaphore to access the PHY or NVM
375 1.1 rin */
376 1.1 rin int
377 1.1 rin igc_get_hw_semaphore_i225(struct igc_hw *hw)
378 1.1 rin {
379 1.1 rin uint32_t swsm;
380 1.1 rin int timeout = hw->nvm.word_size + 1;
381 1.1 rin int i = 0;
382 1.1 rin
383 1.1 rin DEBUGFUNC("igc_get_hw_semaphore_i225");
384 1.1 rin
385 1.1 rin /* Get the SW semaphore */
386 1.1 rin while (i < timeout) {
387 1.1 rin swsm = IGC_READ_REG(hw, IGC_SWSM);
388 1.1 rin if (!(swsm & IGC_SWSM_SMBI))
389 1.1 rin break;
390 1.1 rin
391 1.1 rin DELAY(50);
392 1.1 rin i++;
393 1.1 rin }
394 1.1 rin
395 1.1 rin if (i == timeout) {
396 1.1 rin /* In rare circumstances, the SW semaphore may already be held
397 1.1 rin * unintentionally. Clear the semaphore once before giving up.
398 1.1 rin */
399 1.1 rin if (hw->dev_spec._i225.clear_semaphore_once) {
400 1.1 rin hw->dev_spec._i225.clear_semaphore_once = false;
401 1.1 rin igc_put_hw_semaphore_generic(hw);
402 1.1 rin for (i = 0; i < timeout; i++) {
403 1.1 rin swsm = IGC_READ_REG(hw, IGC_SWSM);
404 1.1 rin if (!(swsm & IGC_SWSM_SMBI))
405 1.1 rin break;
406 1.1 rin
407 1.1 rin DELAY(50);
408 1.1 rin }
409 1.1 rin }
410 1.1 rin
411 1.1 rin /* If we do not have the semaphore here, we have to give up. */
412 1.1 rin if (i == timeout) {
413 1.1 rin DEBUGOUT("Driver can't access device -\n");
414 1.1 rin DEBUGOUT("SMBI bit is set.\n");
415 1.1 rin return -IGC_ERR_NVM;
416 1.1 rin }
417 1.1 rin }
418 1.1 rin
419 1.1 rin /* Get the FW semaphore. */
420 1.1 rin for (i = 0; i < timeout; i++) {
421 1.1 rin swsm = IGC_READ_REG(hw, IGC_SWSM);
422 1.1 rin IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);
423 1.1 rin
424 1.1 rin /* Semaphore acquired if bit latched */
425 1.1 rin if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
426 1.1 rin break;
427 1.1 rin
428 1.1 rin DELAY(50);
429 1.1 rin }
430 1.1 rin
431 1.1 rin if (i == timeout) {
432 1.1 rin /* Release semaphores */
433 1.1 rin igc_put_hw_semaphore_generic(hw);
434 1.1 rin DEBUGOUT("Driver can't access the NVM\n");
435 1.1 rin return -IGC_ERR_NVM;
436 1.1 rin }
437 1.1 rin
438 1.1 rin return IGC_SUCCESS;
439 1.1 rin }
440 1.1 rin
441 1.1 rin /* igc_read_nvm_srrd_i225 - Reads Shadow Ram using EERD register
442 1.1 rin * @hw: pointer to the HW structure
443 1.1 rin * @offset: offset of word in the Shadow Ram to read
444 1.1 rin * @words: number of words to read
445 1.1 rin * @data: word read from the Shadow Ram
446 1.1 rin *
447 1.1 rin * Reads a 16 bit word from the Shadow Ram using the EERD register.
448 1.1 rin * Uses necessary synchronization semaphores.
449 1.1 rin */
450 1.1 rin int
451 1.1 rin igc_read_nvm_srrd_i225(struct igc_hw *hw, uint16_t offset, uint16_t words,
452 1.1 rin uint16_t *data)
453 1.1 rin {
454 1.1 rin uint16_t i, count;
455 1.1 rin int status = IGC_SUCCESS;
456 1.1 rin
457 1.1 rin DEBUGFUNC("igc_read_nvm_srrd_i225");
458 1.1 rin
459 1.1 rin /* We cannot hold synchronization semaphores for too long,
460 1.1 rin * because of forceful takeover procedure. However it is more efficient
461 1.1 rin * to read in bursts than synchronizing access for each word.
462 1.1 rin */
463 1.1 rin for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
464 1.1 rin count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
465 1.1 rin IGC_EERD_EEWR_MAX_COUNT : (words - i);
466 1.1 rin if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
467 1.1 rin status = igc_read_nvm_eerd(hw, offset, count, data + i);
468 1.1 rin hw->nvm.ops.release(hw);
469 1.1 rin } else {
470 1.1 rin status = IGC_ERR_SWFW_SYNC;
471 1.1 rin }
472 1.1 rin
473 1.1 rin if (status != IGC_SUCCESS)
474 1.1 rin break;
475 1.1 rin }
476 1.1 rin
477 1.1 rin return status;
478 1.1 rin }
479 1.1 rin
480 1.1 rin /* igc_write_nvm_srwr_i225 - Write to Shadow RAM using EEWR
481 1.1 rin * @hw: pointer to the HW structure
482 1.1 rin * @offset: offset within the Shadow RAM to be written to
483 1.1 rin * @words: number of words to write
484 1.1 rin * @data: 16 bit word(s) to be written to the Shadow RAM
485 1.1 rin *
486 1.1 rin * Writes data to Shadow RAM at offset using EEWR register.
487 1.1 rin *
488 1.1 rin * If igc_update_nvm_checksum is not called after this function , the
489 1.1 rin * data will not be committed to FLASH and also Shadow RAM will most likely
490 1.1 rin * contain an invalid checksum.
491 1.1 rin *
492 1.1 rin * If error code is returned, data and Shadow RAM may be inconsistent - buffer
493 1.1 rin * partially written.
494 1.1 rin */
495 1.1 rin int
496 1.1 rin igc_write_nvm_srwr_i225(struct igc_hw *hw, uint16_t offset, uint16_t words,
497 1.1 rin uint16_t *data)
498 1.1 rin {
499 1.1 rin uint16_t i, count;
500 1.1 rin int status = IGC_SUCCESS;
501 1.1 rin
502 1.1 rin DEBUGFUNC("igc_write_nvm_srwr_i225");
503 1.1 rin
504 1.1 rin /* We cannot hold synchronization semaphores for too long,
505 1.1 rin * because of forceful takeover procedure. However it is more efficient
506 1.1 rin * to write in bursts than synchronizing access for each word.
507 1.1 rin */
508 1.1 rin for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
509 1.1 rin count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
510 1.1 rin IGC_EERD_EEWR_MAX_COUNT : (words - i);
511 1.1 rin if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
512 1.1 rin status = __igc_write_nvm_srwr(hw, offset, count,
513 1.1 rin data + i);
514 1.1 rin hw->nvm.ops.release(hw);
515 1.1 rin } else
516 1.1 rin status = IGC_ERR_SWFW_SYNC;
517 1.1 rin
518 1.1 rin if (status != IGC_SUCCESS)
519 1.1 rin break;
520 1.1 rin }
521 1.1 rin
522 1.1 rin return status;
523 1.1 rin }
524 1.1 rin
525 1.1 rin /* __igc_write_nvm_srwr - Write to Shadow Ram using EEWR
526 1.1 rin * @hw: pointer to the HW structure
527 1.1 rin * @offset: offset within the Shadow Ram to be written to
528 1.1 rin * @words: number of words to write
529 1.1 rin * @data: 16 bit word(s) to be written to the Shadow Ram
530 1.1 rin *
531 1.1 rin * Writes data to Shadow Ram at offset using EEWR register.
532 1.1 rin *
533 1.1 rin * If igc_update_nvm_checksum is not called after this function , the
534 1.1 rin * Shadow Ram will most likely contain an invalid checksum.
535 1.1 rin */
536 1.1 rin int
537 1.1 rin __igc_write_nvm_srwr(struct igc_hw *hw, uint16_t offset, uint16_t words,
538 1.1 rin uint16_t *data)
539 1.1 rin {
540 1.1 rin struct igc_nvm_info *nvm = &hw->nvm;
541 1.1 rin uint32_t i, k, eewr = 0;
542 1.1 rin uint32_t attempts = 100000;
543 1.1 rin int ret_val = IGC_SUCCESS;
544 1.1 rin
545 1.1 rin DEBUGFUNC("__igc_write_nvm_srwr");
546 1.1 rin
547 1.1 rin /* A check for invalid values: offset too large, too many words,
548 1.1 rin * too many words for the offset, and not enough words.
549 1.1 rin */
550 1.1 rin if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
551 1.1 rin (words == 0)) {
552 1.1 rin DEBUGOUT("nvm parameter(s) out of bounds\n");
553 1.1 rin ret_val = -IGC_ERR_NVM;
554 1.1 rin goto out;
555 1.1 rin }
556 1.1 rin
557 1.1 rin for (i = 0; i < words; i++) {
558 1.1 rin eewr = ((offset + i) << IGC_NVM_RW_ADDR_SHIFT) |
559 1.1 rin (data[i] << IGC_NVM_RW_REG_DATA) | IGC_NVM_RW_REG_START;
560 1.1 rin
561 1.1 rin IGC_WRITE_REG(hw, IGC_SRWR, eewr);
562 1.1 rin
563 1.1 rin for (k = 0; k < attempts; k++) {
564 1.1 rin if (IGC_NVM_RW_REG_DONE & IGC_READ_REG(hw, IGC_SRWR)) {
565 1.1 rin ret_val = IGC_SUCCESS;
566 1.1 rin break;
567 1.1 rin }
568 1.1 rin DELAY(5);
569 1.1 rin }
570 1.1 rin
571 1.1 rin if (ret_val != IGC_SUCCESS) {
572 1.1 rin DEBUGOUT("Shadow RAM write EEWR timed out\n");
573 1.1 rin break;
574 1.1 rin }
575 1.1 rin }
576 1.1 rin
577 1.1 rin out:
578 1.1 rin return ret_val;
579 1.1 rin }
580 1.1 rin
581 1.1 rin /* igc_validate_nvm_checksum_i225 - Validate EEPROM checksum
582 1.1 rin * @hw: pointer to the HW structure
583 1.1 rin *
584 1.1 rin * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
585 1.1 rin * and then verifies that the sum of the EEPROM is equal to 0xBABA.
586 1.1 rin */
587 1.1 rin int
588 1.1 rin igc_validate_nvm_checksum_i225(struct igc_hw *hw)
589 1.1 rin {
590 1.1 rin int status = IGC_SUCCESS;
591 1.1 rin int (*read_op_ptr)(struct igc_hw *, uint16_t, uint16_t, uint16_t *);
592 1.1 rin
593 1.1 rin DEBUGFUNC("igc_validate_nvm_checksum_i225");
594 1.1 rin
595 1.1 rin if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
596 1.1 rin /* Replace the read function with semaphore grabbing with
597 1.1 rin * the one that skips this for a while.
598 1.1 rin * We have semaphore taken already here.
599 1.1 rin */
600 1.1 rin read_op_ptr = hw->nvm.ops.read;
601 1.1 rin hw->nvm.ops.read = igc_read_nvm_eerd;
602 1.1 rin
603 1.1 rin status = igc_validate_nvm_checksum_generic(hw);
604 1.1 rin
605 1.1 rin /* Revert original read operation. */
606 1.1 rin hw->nvm.ops.read = read_op_ptr;
607 1.1 rin
608 1.1 rin hw->nvm.ops.release(hw);
609 1.1 rin } else {
610 1.1 rin status = IGC_ERR_SWFW_SYNC;
611 1.1 rin }
612 1.1 rin
613 1.1 rin return status;
614 1.1 rin }
615 1.1 rin
616 1.1 rin /* igc_update_nvm_checksum_i225 - Update EEPROM checksum
617 1.1 rin * @hw: pointer to the HW structure
618 1.1 rin *
619 1.1 rin * Updates the EEPROM checksum by reading/adding each word of the EEPROM
620 1.1 rin * up to the checksum. Then calculates the EEPROM checksum and writes the
621 1.1 rin * value to the EEPROM. Next commit EEPROM data onto the Flash.
622 1.1 rin */
623 1.1 rin int
624 1.1 rin igc_update_nvm_checksum_i225(struct igc_hw *hw)
625 1.1 rin {
626 1.1 rin uint16_t checksum = 0;
627 1.1 rin uint16_t i, nvm_data;
628 1.1 rin int ret_val;
629 1.1 rin
630 1.1 rin DEBUGFUNC("igc_update_nvm_checksum_i225");
631 1.1 rin
632 1.1 rin /* Read the first word from the EEPROM. If this times out or fails, do
633 1.1 rin * not continue or we could be in for a very long wait while every
634 1.1 rin * EEPROM read fails
635 1.1 rin */
636 1.1 rin ret_val = igc_read_nvm_eerd(hw, 0, 1, &nvm_data);
637 1.1 rin if (ret_val != IGC_SUCCESS) {
638 1.1 rin DEBUGOUT("EEPROM read failed\n");
639 1.1 rin goto out;
640 1.1 rin }
641 1.1 rin
642 1.1 rin if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
643 1.1 rin /* Do not use hw->nvm.ops.write, hw->nvm.ops.read
644 1.1 rin * because we do not want to take the synchronization
645 1.1 rin * semaphores twice here.
646 1.1 rin */
647 1.1 rin
648 1.1 rin for (i = 0; i < NVM_CHECKSUM_REG; i++) {
649 1.1 rin ret_val = igc_read_nvm_eerd(hw, i, 1, &nvm_data);
650 1.1 rin if (ret_val) {
651 1.1 rin hw->nvm.ops.release(hw);
652 1.1 rin DEBUGOUT("NVM Read Error while updating\n");
653 1.1 rin DEBUGOUT("checksum.\n");
654 1.1 rin goto out;
655 1.1 rin }
656 1.1 rin checksum += nvm_data;
657 1.1 rin }
658 1.1 rin checksum = (uint16_t)NVM_SUM - checksum;
659 1.1 rin ret_val = __igc_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
660 1.1 rin &checksum);
661 1.1 rin if (ret_val != IGC_SUCCESS) {
662 1.1 rin hw->nvm.ops.release(hw);
663 1.1 rin DEBUGOUT("NVM Write Error while updating checksum.\n");
664 1.1 rin goto out;
665 1.1 rin }
666 1.1 rin
667 1.1 rin hw->nvm.ops.release(hw);
668 1.1 rin
669 1.1 rin ret_val = igc_update_flash_i225(hw);
670 1.1 rin } else {
671 1.1 rin ret_val = IGC_ERR_SWFW_SYNC;
672 1.1 rin }
673 1.1 rin out:
674 1.1 rin return ret_val;
675 1.1 rin }
676 1.1 rin
677 1.1 rin /* igc_get_flash_presence_i225 - Check if flash device is detected.
678 1.1 rin * @hw: pointer to the HW structure
679 1.1 rin */
680 1.1 rin bool
681 1.1 rin igc_get_flash_presence_i225(struct igc_hw *hw)
682 1.1 rin {
683 1.1 rin uint32_t eec = 0;
684 1.1 rin bool ret_val = false;
685 1.1 rin
686 1.1 rin DEBUGFUNC("igc_get_flash_presence_i225");
687 1.1 rin
688 1.1 rin eec = IGC_READ_REG(hw, IGC_EECD);
689 1.1 rin
690 1.1 rin if (eec & IGC_EECD_FLASH_DETECTED_I225)
691 1.1 rin ret_val = true;
692 1.1 rin
693 1.1 rin return ret_val;
694 1.1 rin }
695 1.1 rin
696 1.1 rin /* igc_set_flsw_flash_burst_counter_i225 - sets FLSW NVM Burst
697 1.1 rin * Counter in FLSWCNT register.
698 1.1 rin *
699 1.1 rin * @hw: pointer to the HW structure
700 1.1 rin * @burst_counter: size in bytes of the Flash burst to read or write
701 1.1 rin */
702 1.1 rin int
703 1.1 rin igc_set_flsw_flash_burst_counter_i225(struct igc_hw *hw, uint32_t burst_counter)
704 1.1 rin {
705 1.1 rin int ret_val = IGC_SUCCESS;
706 1.1 rin
707 1.1 rin DEBUGFUNC("igc_set_flsw_flash_burst_counter_i225");
708 1.1 rin
709 1.1 rin /* Validate input data */
710 1.1 rin if (burst_counter < IGC_I225_SHADOW_RAM_SIZE) {
711 1.1 rin /* Write FLSWCNT - burst counter */
712 1.1 rin IGC_WRITE_REG(hw, IGC_I225_FLSWCNT, burst_counter);
713 1.1 rin } else {
714 1.1 rin ret_val = IGC_ERR_INVALID_ARGUMENT;
715 1.1 rin }
716 1.1 rin
717 1.1 rin return ret_val;
718 1.1 rin }
719 1.1 rin
720 1.1 rin
721 1.1 rin /* igc_write_erase_flash_command_i225 - write/erase to a sector
722 1.1 rin * region on a given address.
723 1.1 rin *
724 1.1 rin * @hw: pointer to the HW structure
725 1.1 rin * @opcode: opcode to be used for the write command
726 1.1 rin * @address: the offset to write into the FLASH image
727 1.1 rin */
728 1.1 rin int
729 1.1 rin igc_write_erase_flash_command_i225(struct igc_hw *hw, uint32_t opcode,
730 1.1 rin uint32_t address)
731 1.1 rin {
732 1.1 rin uint32_t flswctl = 0;
733 1.1 rin int timeout = IGC_NVM_GRANT_ATTEMPTS;
734 1.1 rin int ret_val = IGC_SUCCESS;
735 1.1 rin
736 1.1 rin DEBUGFUNC("igc_write_erase_flash_command_i225");
737 1.1 rin
738 1.1 rin flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
739 1.1 rin /* Polling done bit on FLSWCTL register */
740 1.1 rin while (timeout) {
741 1.1 rin if (flswctl & IGC_FLSWCTL_DONE)
742 1.1 rin break;
743 1.1 rin DELAY(5);
744 1.1 rin flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
745 1.1 rin timeout--;
746 1.1 rin }
747 1.1 rin
748 1.1 rin if (!timeout) {
749 1.1 rin DEBUGOUT("Flash transaction was not done\n");
750 1.1 rin return -IGC_ERR_NVM;
751 1.1 rin }
752 1.1 rin
753 1.1 rin /* Build and issue command on FLSWCTL register */
754 1.1 rin flswctl = address | opcode;
755 1.1 rin IGC_WRITE_REG(hw, IGC_I225_FLSWCTL, flswctl);
756 1.1 rin
757 1.1 rin /* Check if issued command is valid on FLSWCTL register */
758 1.1 rin flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
759 1.1 rin if (!(flswctl & IGC_FLSWCTL_CMDV)) {
760 1.1 rin DEBUGOUT("Write flash command failed\n");
761 1.1 rin ret_val = IGC_ERR_INVALID_ARGUMENT;
762 1.1 rin }
763 1.1 rin
764 1.1 rin return ret_val;
765 1.1 rin }
766 1.1 rin
767 1.1 rin /* igc_update_flash_i225 - Commit EEPROM to the flash
768 1.1 rin * if fw_valid_bit is set, FW is active. setting FLUPD bit in EEC
769 1.1 rin * register makes the FW load the internal shadow RAM into the flash.
770 1.1 rin * Otherwise, fw_valid_bit is 0. if FL_SECU.block_prtotected_sw = 0
771 1.1 rin * then FW is not active so the SW is responsible shadow RAM dump.
772 1.1 rin *
773 1.1 rin * @hw: pointer to the HW structure
774 1.1 rin */
775 1.1 rin int
776 1.1 rin igc_update_flash_i225(struct igc_hw *hw)
777 1.1 rin {
778 1.1 rin uint32_t block_sw_protect = 1;
779 1.1 rin uint32_t i, flup, fw_valid_bit;
780 1.1 rin uint16_t current_offset;
781 1.1 rin uint16_t base_address = 0x0;
782 1.1 rin uint16_t current_offset_data = 0;
783 1.1 rin int ret_val = 0;
784 1.1 rin
785 1.1 rin DEBUGFUNC("igc_update_flash_i225");
786 1.1 rin
787 1.1 rin block_sw_protect = IGC_READ_REG(hw, IGC_I225_FLSECU) &
788 1.1 rin IGC_FLSECU_BLK_SW_ACCESS_I225;
789 1.1 rin
790 1.1 rin fw_valid_bit = IGC_READ_REG(hw, IGC_FWSM) & IGC_FWSM_FW_VALID_I225;
791 1.1 rin if (fw_valid_bit) {
792 1.1 rin ret_val = igc_pool_flash_update_done_i225(hw);
793 1.1 rin if (ret_val == -IGC_ERR_NVM) {
794 1.1 rin DEBUGOUT("Flash update time out\n");
795 1.1 rin goto out;
796 1.1 rin }
797 1.1 rin
798 1.1 rin flup = IGC_READ_REG(hw, IGC_EECD) | IGC_EECD_FLUPD_I225;
799 1.1 rin IGC_WRITE_REG(hw, IGC_EECD, flup);
800 1.1 rin
801 1.1 rin ret_val = igc_pool_flash_update_done_i225(hw);
802 1.1 rin if (ret_val == IGC_SUCCESS)
803 1.1 rin DEBUGOUT("Flash update complete\n");
804 1.1 rin else
805 1.1 rin DEBUGOUT("Flash update time out\n");
806 1.1 rin } else if (!block_sw_protect) {
807 1.1 rin /* FW is not active and security protection is disabled.
808 1.1 rin * therefore, SW is in charge of shadow RAM dump.
809 1.1 rin * Check which sector is valid. if sector 0 is valid,
810 1.1 rin * base address remains 0x0. otherwise, sector 1 is
811 1.1 rin * valid and its base address is 0x1000
812 1.1 rin */
813 1.1 rin if (IGC_READ_REG(hw, IGC_EECD) & IGC_EECD_SEC1VAL_I225)
814 1.1 rin base_address = 0x1000;
815 1.1 rin
816 1.1 rin /* Valid sector erase */
817 1.1 rin ret_val = igc_write_erase_flash_command_i225(hw,
818 1.1 rin IGC_I225_ERASE_CMD_OPCODE, base_address);
819 1.1 rin if (!ret_val) {
820 1.1 rin DEBUGOUT("Sector erase failed\n");
821 1.1 rin goto out;
822 1.1 rin }
823 1.1 rin
824 1.1 rin current_offset = base_address;
825 1.1 rin
826 1.1 rin /* Write */
827 1.1 rin for (i = 0; i < IGC_I225_SHADOW_RAM_SIZE / 2; i++) {
828 1.1 rin /* Set burst write length */
829 1.1 rin ret_val = igc_set_flsw_flash_burst_counter_i225(hw,
830 1.1 rin 0x2);
831 1.1 rin if (ret_val != IGC_SUCCESS)
832 1.1 rin break;
833 1.1 rin
834 1.1 rin /* Set address and opcode */
835 1.1 rin ret_val = igc_write_erase_flash_command_i225(hw,
836 1.1 rin IGC_I225_WRITE_CMD_OPCODE, 2 * current_offset);
837 1.1 rin if (ret_val != IGC_SUCCESS)
838 1.1 rin break;
839 1.1 rin
840 1.1 rin ret_val = igc_read_nvm_eerd(hw, current_offset, 1,
841 1.1 rin ¤t_offset_data);
842 1.1 rin if (ret_val) {
843 1.1 rin DEBUGOUT("Failed to read from EEPROM\n");
844 1.1 rin goto out;
845 1.1 rin }
846 1.1 rin
847 1.1 rin /* Write CurrentOffseData to FLSWDATA register */
848 1.1 rin IGC_WRITE_REG(hw, IGC_I225_FLSWDATA,
849 1.1 rin current_offset_data);
850 1.1 rin current_offset++;
851 1.1 rin
852 1.1 rin /* Wait till operation has finished */
853 1.1 rin ret_val = igc_poll_eerd_eewr_done(hw,
854 1.1 rin IGC_NVM_POLL_READ);
855 1.1 rin if (ret_val)
856 1.1 rin break;
857 1.1 rin
858 1.1 rin DELAY(1000);
859 1.1 rin }
860 1.1 rin }
861 1.1 rin out:
862 1.1 rin return ret_val;
863 1.1 rin }
864 1.1 rin
865 1.1 rin /* igc_pool_flash_update_done_i225 - Pool FLUDONE status.
866 1.1 rin * @hw: pointer to the HW structure
867 1.1 rin */
868 1.1 rin int
869 1.1 rin igc_pool_flash_update_done_i225(struct igc_hw *hw)
870 1.1 rin {
871 1.1 rin uint32_t i, reg;
872 1.1 rin int ret_val = -IGC_ERR_NVM;
873 1.1 rin
874 1.1 rin DEBUGFUNC("igc_pool_flash_update_done_i225");
875 1.1 rin
876 1.1 rin for (i = 0; i < IGC_FLUDONE_ATTEMPTS; i++) {
877 1.1 rin reg = IGC_READ_REG(hw, IGC_EECD);
878 1.1 rin if (reg & IGC_EECD_FLUDONE_I225) {
879 1.1 rin ret_val = IGC_SUCCESS;
880 1.1 rin break;
881 1.1 rin }
882 1.1 rin DELAY(5);
883 1.1 rin }
884 1.1 rin
885 1.1 rin return ret_val;
886 1.1 rin }
887 1.1 rin
888 1.1 rin /* igc_set_ltr_i225 - Set Latency Tolerance Reporting thresholds.
889 1.1 rin * @hw: pointer to the HW structure
890 1.1 rin * @link: bool indicating link status
891 1.1 rin *
892 1.1 rin * Set the LTR thresholds based on the link speed (Mbps), EEE, and DMAC
893 1.1 rin * settings, otherwise specify that there is no LTR requirement.
894 1.1 rin */
895 1.1 rin int
896 1.1 rin igc_set_ltr_i225(struct igc_hw *hw, bool link)
897 1.1 rin {
898 1.1 rin uint16_t speed, duplex;
899 1.1 rin uint32_t tw_system, ltrc, ltrv, ltr_min, ltr_max, scale_min, scale_max;
900 1.1 rin int size;
901 1.1 rin
902 1.1 rin DEBUGFUNC("igc_set_ltr_i225");
903 1.1 rin
904 1.1 rin /* If we do not have link, LTR thresholds are zero. */
905 1.1 rin if (link) {
906 1.1 rin hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
907 1.1 rin
908 1.1 rin /* Check if using copper interface with EEE enabled or if the
909 1.1 rin * link speed is 10 Mbps.
910 1.1 rin */
911 1.1 rin if ((hw->phy.media_type == igc_media_type_copper) &&
912 1.1 rin !(hw->dev_spec._i225.eee_disable) &&
913 1.1 rin (speed != SPEED_10)) {
914 1.1 rin /* EEE enabled, so send LTRMAX threshold. */
915 1.1 rin ltrc = IGC_READ_REG(hw, IGC_LTRC) | IGC_LTRC_EEEMS_EN;
916 1.1 rin IGC_WRITE_REG(hw, IGC_LTRC, ltrc);
917 1.1 rin
918 1.1 rin /* Calculate tw_system (nsec). */
919 1.1 rin if (speed == SPEED_100) {
920 1.1 rin tw_system = ((IGC_READ_REG(hw, IGC_EEE_SU) &
921 1.1 rin IGC_TW_SYSTEM_100_MASK) >>
922 1.1 rin IGC_TW_SYSTEM_100_SHIFT) * 500;
923 1.1 rin } else {
924 1.1 rin tw_system = (IGC_READ_REG(hw, IGC_EEE_SU) &
925 1.1 rin IGC_TW_SYSTEM_1000_MASK) * 500;
926 1.1 rin }
927 1.1 rin } else {
928 1.1 rin tw_system = 0;
929 1.1 rin }
930 1.1 rin
931 1.1 rin /* Get the Rx packet buffer size. */
932 1.1 rin size = IGC_READ_REG(hw, IGC_RXPBS) & IGC_RXPBS_SIZE_I225_MASK;
933 1.1 rin
934 1.1 rin /* Calculations vary based on DMAC settings. */
935 1.1 rin if (IGC_READ_REG(hw, IGC_DMACR) & IGC_DMACR_DMAC_EN) {
936 1.1 rin size -= (IGC_READ_REG(hw, IGC_DMACR) &
937 1.1 rin IGC_DMACR_DMACTHR_MASK) >> IGC_DMACR_DMACTHR_SHIFT;
938 1.1 rin /* Convert size to bits. */
939 1.1 rin size *= 1024 * 8;
940 1.1 rin } else {
941 1.1 rin /* Convert size to bytes, subtract the MTU, and then
942 1.1 rin * convert the size to bits.
943 1.1 rin */
944 1.1 rin size *= 1024;
945 1.1 rin size -= hw->dev_spec._i225.mtu;
946 1.1 rin size *= 8;
947 1.1 rin }
948 1.1 rin
949 1.1 rin if (size < 0) {
950 1.1 rin DEBUGOUT1("Invalid effective Rx buffer size %d\n",
951 1.1 rin size);
952 1.1 rin return -IGC_ERR_CONFIG;
953 1.1 rin }
954 1.1 rin
955 1.1 rin /* Calculate the thresholds. Since speed is in Mbps, simplify
956 1.1 rin * the calculation by multiplying size/speed by 1000 for result
957 1.1 rin * to be in nsec before dividing by the scale in nsec. Set the
958 1.1 rin * scale such that the LTR threshold fits in the register.
959 1.1 rin */
960 1.1 rin ltr_min = (1000 * size) / speed;
961 1.1 rin ltr_max = ltr_min + tw_system;
962 1.1 rin scale_min = (ltr_min / 1024) < 1024 ? IGC_LTRMINV_SCALE_1024 :
963 1.1 rin IGC_LTRMINV_SCALE_32768;
964 1.1 rin scale_max = (ltr_max / 1024) < 1024 ? IGC_LTRMAXV_SCALE_1024 :
965 1.1 rin IGC_LTRMAXV_SCALE_32768;
966 1.1 rin ltr_min /= scale_min == IGC_LTRMINV_SCALE_1024 ? 1024 : 32768;
967 1.1 rin ltr_max /= scale_max == IGC_LTRMAXV_SCALE_1024 ? 1024 : 32768;
968 1.1 rin
969 1.1 rin /* Only write the LTR thresholds if they differ from before. */
970 1.1 rin ltrv = IGC_READ_REG(hw, IGC_LTRMINV);
971 1.1 rin if (ltr_min != (ltrv & IGC_LTRMINV_LTRV_MASK)) {
972 1.1 rin ltrv = IGC_LTRMINV_LSNP_REQ | ltr_min |
973 1.1 rin (scale_min << IGC_LTRMINV_SCALE_SHIFT);
974 1.1 rin IGC_WRITE_REG(hw, IGC_LTRMINV, ltrv);
975 1.1 rin }
976 1.1 rin
977 1.1 rin ltrv = IGC_READ_REG(hw, IGC_LTRMAXV);
978 1.1 rin if (ltr_max != (ltrv & IGC_LTRMAXV_LTRV_MASK)) {
979 1.1 rin ltrv = IGC_LTRMAXV_LSNP_REQ | ltr_max |
980 1.1 rin (scale_min << IGC_LTRMAXV_SCALE_SHIFT);
981 1.1 rin IGC_WRITE_REG(hw, IGC_LTRMAXV, ltrv);
982 1.1 rin }
983 1.1 rin }
984 1.1 rin
985 1.1 rin return IGC_SUCCESS;
986 1.1 rin }
987 1.1 rin
988 1.1 rin /* igc_check_for_link_i225 - Check for link
989 1.1 rin * @hw: pointer to the HW structure
990 1.1 rin *
991 1.1 rin * Checks to see of the link status of the hardware has changed. If a
992 1.1 rin * change in link status has been detected, then we read the PHY registers
993 1.1 rin * to get the current speed/duplex if link exists.
994 1.1 rin */
995 1.1 rin int
996 1.1 rin igc_check_for_link_i225(struct igc_hw *hw)
997 1.1 rin {
998 1.1 rin struct igc_mac_info *mac = &hw->mac;
999 1.1 rin int ret_val;
1000 1.1 rin bool link = false;
1001 1.1 rin
1002 1.1 rin DEBUGFUNC("igc_check_for_link_i225");
1003 1.1 rin
1004 1.1 rin /* We only want to go out to the PHY registers to see if
1005 1.1 rin * Auto-Neg has completed and/or if our link status has
1006 1.1 rin * changed. The get_link_status flag is set upon receiving
1007 1.1 rin * a Link Status Change or Rx Sequence Error interrupt.
1008 1.1 rin */
1009 1.1 rin if (!mac->get_link_status) {
1010 1.1 rin ret_val = IGC_SUCCESS;
1011 1.1 rin goto out;
1012 1.1 rin }
1013 1.1 rin
1014 1.1 rin /* First we want to see if the MII Status Register reports
1015 1.1 rin * link. If so, then we want to get the current speed/duplex
1016 1.1 rin * of the PHY.
1017 1.1 rin */
1018 1.1 rin ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
1019 1.1 rin if (ret_val)
1020 1.1 rin goto out;
1021 1.1 rin
1022 1.1 rin if (!link)
1023 1.1 rin goto out; /* No link detected */
1024 1.1 rin
1025 1.1 rin /* First we want to see if the MII Status Register reports
1026 1.1 rin * link. If so, then we want to get the current speed/duplex
1027 1.1 rin * of the PHY.
1028 1.1 rin */
1029 1.1 rin ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
1030 1.1 rin if (ret_val)
1031 1.1 rin goto out;
1032 1.1 rin
1033 1.1 rin if (!link)
1034 1.1 rin goto out; /* No link detected */
1035 1.1 rin
1036 1.1 rin mac->get_link_status = false;
1037 1.1 rin
1038 1.1 rin /* Check if there was DownShift, must be checked
1039 1.1 rin * immediately after link-up
1040 1.1 rin */
1041 1.1 rin igc_check_downshift_generic(hw);
1042 1.1 rin
1043 1.1 rin /* If we are forcing speed/duplex, then we simply return since
1044 1.1 rin * we have already determined whether we have link or not.
1045 1.1 rin */
1046 1.1 rin if (!mac->autoneg)
1047 1.1 rin goto out;
1048 1.1 rin
1049 1.1 rin /* Auto-Neg is enabled. Auto Speed Detection takes care
1050 1.1 rin * of MAC speed/duplex configuration. So we only need to
1051 1.1 rin * configure Collision Distance in the MAC.
1052 1.1 rin */
1053 1.1 rin mac->ops.config_collision_dist(hw);
1054 1.1 rin
1055 1.1 rin /* Configure Flow Control now that Auto-Neg has completed.
1056 1.1 rin * First, we need to restore the desired flow control
1057 1.1 rin * settings because we may have had to re-autoneg with a
1058 1.1 rin * different link partner.
1059 1.1 rin */
1060 1.1 rin ret_val = igc_config_fc_after_link_up_generic(hw);
1061 1.1 rin if (ret_val)
1062 1.1 rin DEBUGOUT("Error configuring flow control\n");
1063 1.1 rin out:
1064 1.1 rin /* Now that we are aware of our link settings, we can set the LTR
1065 1.1 rin * thresholds.
1066 1.1 rin */
1067 1.1 rin ret_val = igc_set_ltr_i225(hw, link);
1068 1.1 rin
1069 1.1 rin return ret_val;
1070 1.1 rin }
1071 1.1 rin
1072 1.1 rin /* igc_init_function_pointers_i225 - Init func ptrs.
1073 1.1 rin * @hw: pointer to the HW structure
1074 1.1 rin *
1075 1.1 rin * Called to initialize all function pointers and parameters.
1076 1.1 rin */
1077 1.1 rin void
1078 1.1 rin igc_init_function_pointers_i225(struct igc_hw *hw)
1079 1.1 rin {
1080 1.1 rin igc_init_mac_ops_generic(hw);
1081 1.1 rin igc_init_phy_ops_generic(hw);
1082 1.1 rin igc_init_nvm_ops_generic(hw);
1083 1.1 rin hw->mac.ops.init_params = igc_init_mac_params_i225;
1084 1.1 rin hw->nvm.ops.init_params = igc_init_nvm_params_i225;
1085 1.1 rin hw->phy.ops.init_params = igc_init_phy_params_i225;
1086 1.1 rin }
1087 1.1 rin
1088 1.1 rin /* igc_init_hw_i225 - Init hw for I225
1089 1.1 rin * @hw: pointer to the HW structure
1090 1.1 rin *
1091 1.1 rin * Called to initialize hw for i225 hw family.
1092 1.1 rin */
1093 1.1 rin int
1094 1.1 rin igc_init_hw_i225(struct igc_hw *hw)
1095 1.1 rin {
1096 1.1 rin int ret_val;
1097 1.1 rin
1098 1.1 rin DEBUGFUNC("igc_init_hw_i225");
1099 1.1 rin
1100 1.1 rin ret_val = igc_init_hw_base(hw);
1101 1.1 rin return ret_val;
1102 1.1 rin }
1103 1.1 rin
1104 1.1 rin /**
1105 1.1 rin * igc_set_eee_i225 - Enable/disable EEE support
1106 1.1 rin * @hw: pointer to the HW structure
1107 1.1 rin * @adv2p5G: boolean flag enabling 2.5G EEE advertisement
1108 1.1 rin * @adv1G: boolean flag enabling 1G EEE advertisement
1109 1.1 rin * @adv100M: boolean flag enabling 100M EEE advertisement
1110 1.1 rin *
1111 1.1 rin * Enable/disable EEE based on setting in dev_spec structure.
1112 1.1 rin *
1113 1.1 rin **/
1114 1.1 rin int
1115 1.1 rin igc_set_eee_i225(struct igc_hw *hw, bool adv2p5G, bool adv1G,
1116 1.1 rin bool adv100M)
1117 1.1 rin {
1118 1.1 rin uint32_t ipcnfg, eeer;
1119 1.1 rin
1120 1.1 rin DEBUGFUNC("igc_set_eee_i225");
1121 1.1 rin
1122 1.1 rin if (hw->mac.type != igc_i225 ||
1123 1.1 rin hw->phy.media_type != igc_media_type_copper)
1124 1.1 rin goto out;
1125 1.1 rin ipcnfg = IGC_READ_REG(hw, IGC_IPCNFG);
1126 1.1 rin eeer = IGC_READ_REG(hw, IGC_EEER);
1127 1.1 rin
1128 1.1 rin /* enable or disable per user setting */
1129 1.1 rin if (!(hw->dev_spec._i225.eee_disable)) {
1130 1.1 rin uint32_t eee_su = IGC_READ_REG(hw, IGC_EEE_SU);
1131 1.1 rin
1132 1.1 rin if (adv100M)
1133 1.1 rin ipcnfg |= IGC_IPCNFG_EEE_100M_AN;
1134 1.1 rin else
1135 1.1 rin ipcnfg &= ~IGC_IPCNFG_EEE_100M_AN;
1136 1.1 rin
1137 1.1 rin if (adv1G)
1138 1.1 rin ipcnfg |= IGC_IPCNFG_EEE_1G_AN;
1139 1.1 rin else
1140 1.1 rin ipcnfg &= ~IGC_IPCNFG_EEE_1G_AN;
1141 1.1 rin
1142 1.1 rin if (adv2p5G)
1143 1.1 rin ipcnfg |= IGC_IPCNFG_EEE_2_5G_AN;
1144 1.1 rin else
1145 1.1 rin ipcnfg &= ~IGC_IPCNFG_EEE_2_5G_AN;
1146 1.1 rin
1147 1.1 rin eeer |= (IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
1148 1.1 rin IGC_EEER_LPI_FC);
1149 1.1 rin
1150 1.1 rin /* This bit should not be set in normal operation. */
1151 1.1 rin if (eee_su & IGC_EEE_SU_LPI_CLK_STP)
1152 1.1 rin DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
1153 1.1 rin } else {
1154 1.1 rin ipcnfg &= ~(IGC_IPCNFG_EEE_2_5G_AN | IGC_IPCNFG_EEE_1G_AN |
1155 1.1 rin IGC_IPCNFG_EEE_100M_AN);
1156 1.1 rin eeer &= ~(IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
1157 1.1 rin IGC_EEER_LPI_FC);
1158 1.1 rin }
1159 1.1 rin IGC_WRITE_REG(hw, IGC_IPCNFG, ipcnfg);
1160 1.1 rin IGC_WRITE_REG(hw, IGC_EEER, eeer);
1161 1.1 rin IGC_READ_REG(hw, IGC_IPCNFG);
1162 1.1 rin IGC_READ_REG(hw, IGC_EEER);
1163 1.1 rin out:
1164 1.1 rin
1165 1.1 rin return IGC_SUCCESS;
1166 1.1 rin }
1167