1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018 Intel Corporation */
4 #include <linux/delay.h>
13 * igc_reset_hw_base - Reset hardware
14 * @hw: pointer to the HW structure
16 * This resets the hardware into a known state. This is a
17 * function pointer entry point called by the api module.
19 static s32
igc_reset_hw_base(struct igc_hw
*hw
)
24 /* Prevent the PCI-E bus from sticking if there is no TLP connection
25 * on the last TLP read/write transaction when MAC is reset.
27 ret_val
= igc_disable_pcie_master(hw
);
29 hw_dbg("PCI-E Master disable polling has failed\n");
31 hw_dbg("Masking off all interrupts\n");
32 wr32(IGC_IMC
, 0xffffffff);
35 wr32(IGC_TCTL
, IGC_TCTL_PSP
);
38 usleep_range(10000, 20000);
40 ctrl
= rd32(IGC_CTRL
);
42 hw_dbg("Issuing a global reset to MAC\n");
43 wr32(IGC_CTRL
, ctrl
| IGC_CTRL_DEV_RST
);
45 ret_val
= igc_get_auto_rd_done(hw
);
47 /* When auto config read does not complete, do not
48 * return with an error. This can happen in situations
49 * where there is no eeprom and prevents getting link.
51 hw_dbg("Auto Read Done did not complete\n");
54 /* Clear any pending interrupt events. */
55 wr32(IGC_IMC
, 0xffffffff);
62 * igc_init_nvm_params_base - Init NVM func ptrs.
63 * @hw: pointer to the HW structure
65 static s32
igc_init_nvm_params_base(struct igc_hw
*hw
)
67 struct igc_nvm_info
*nvm
= &hw
->nvm
;
68 u32 eecd
= rd32(IGC_EECD
);
71 size
= (u16
)((eecd
& IGC_EECD_SIZE_EX_MASK
) >>
72 IGC_EECD_SIZE_EX_SHIFT
);
74 /* Added to a constant, "size" becomes the left-shift value
75 * for setting word_size.
77 size
+= NVM_WORD_SIZE_BASE_SHIFT
;
79 /* Just in case size is out of range, cap it to the largest
80 * EEPROM size supported
85 nvm
->type
= igc_nvm_eeprom_spi
;
86 nvm
->word_size
= BIT(size
);
90 nvm
->page_size
= eecd
& IGC_EECD_ADDR_BITS
? 32 : 8;
91 nvm
->address_bits
= eecd
& IGC_EECD_ADDR_BITS
?
94 if (nvm
->word_size
== BIT(15))
101 * igc_setup_copper_link_base - Configure copper link settings
102 * @hw: pointer to the HW structure
104 * Configures the link for auto-neg or forced speed and duplex. Then we check
105 * for link, once link is established calls to configure collision distance
106 * and flow control are called.
108 static s32
igc_setup_copper_link_base(struct igc_hw
*hw
)
113 ctrl
= rd32(IGC_CTRL
);
114 ctrl
|= IGC_CTRL_SLU
;
115 ctrl
&= ~(IGC_CTRL_FRCSPD
| IGC_CTRL_FRCDPX
);
116 wr32(IGC_CTRL
, ctrl
);
118 ret_val
= igc_setup_copper_link(hw
);
124 * igc_init_mac_params_base - Init MAC func ptrs.
125 * @hw: pointer to the HW structure
127 static s32
igc_init_mac_params_base(struct igc_hw
*hw
)
129 struct igc_dev_spec_base
*dev_spec
= &hw
->dev_spec
._base
;
130 struct igc_mac_info
*mac
= &hw
->mac
;
132 /* Set mta register count */
133 mac
->mta_reg_count
= 128;
134 mac
->rar_entry_count
= IGC_RAR_ENTRIES
;
137 mac
->ops
.reset_hw
= igc_reset_hw_base
;
139 mac
->ops
.acquire_swfw_sync
= igc_acquire_swfw_sync_i225
;
140 mac
->ops
.release_swfw_sync
= igc_release_swfw_sync_i225
;
142 /* Allow a single clear of the SW semaphore on I225 */
143 if (mac
->type
== igc_i225
)
144 dev_spec
->clear_semaphore_once
= true;
146 /* physical interface link setup */
147 mac
->ops
.setup_physical_interface
= igc_setup_copper_link_base
;
153 * igc_init_phy_params_base - Init PHY func ptrs.
154 * @hw: pointer to the HW structure
156 static s32
igc_init_phy_params_base(struct igc_hw
*hw
)
158 struct igc_phy_info
*phy
= &hw
->phy
;
161 if (hw
->phy
.media_type
!= igc_media_type_copper
) {
162 phy
->type
= igc_phy_none
;
166 phy
->autoneg_mask
= AUTONEG_ADVERTISE_SPEED_DEFAULT_2500
;
167 phy
->reset_delay_us
= 100;
170 hw
->bus
.func
= (rd32(IGC_STATUS
) & IGC_STATUS_FUNC_MASK
) >>
171 IGC_STATUS_FUNC_SHIFT
;
173 /* Make sure the PHY is in a good state. Several people have reported
174 * firmware leaving the PHY's page select register set to something
175 * other than the default of zero, which causes the PHY ID read to
176 * access something other than the intended register.
178 ret_val
= hw
->phy
.ops
.reset(hw
);
180 hw_dbg("Error resetting the PHY\n");
184 ret_val
= igc_get_phy_id(hw
);
188 igc_check_for_copper_link(hw
);
190 /* Verify phy id and set remaining function pointers */
193 phy
->type
= igc_phy_i225
;
196 ret_val
= -IGC_ERR_PHY
;
204 static s32
igc_get_invariants_base(struct igc_hw
*hw
)
206 struct igc_mac_info
*mac
= &hw
->mac
;
209 switch (hw
->device_id
) {
210 case IGC_DEV_ID_I225_LM
:
211 case IGC_DEV_ID_I225_V
:
212 case IGC_DEV_ID_I225_I
:
213 case IGC_DEV_ID_I220_V
:
214 case IGC_DEV_ID_I225_K
:
215 case IGC_DEV_ID_I225_K2
:
216 case IGC_DEV_ID_I226_K
:
217 case IGC_DEV_ID_I225_LMVP
:
218 case IGC_DEV_ID_I225_IT
:
219 case IGC_DEV_ID_I226_LM
:
220 case IGC_DEV_ID_I226_V
:
221 case IGC_DEV_ID_I226_IT
:
222 case IGC_DEV_ID_I221_V
:
223 case IGC_DEV_ID_I226_BLANK_NVM
:
224 case IGC_DEV_ID_I225_BLANK_NVM
:
225 mac
->type
= igc_i225
;
228 return -IGC_ERR_MAC_INIT
;
231 hw
->phy
.media_type
= igc_media_type_copper
;
233 /* mac initialization and operations */
234 ret_val
= igc_init_mac_params_base(hw
);
238 /* NVM initialization */
239 ret_val
= igc_init_nvm_params_base(hw
);
240 switch (hw
->mac
.type
) {
242 ret_val
= igc_init_nvm_params_i225(hw
);
248 /* setup PHY parameters */
249 ret_val
= igc_init_phy_params_base(hw
);
258 * igc_acquire_phy_base - Acquire rights to access PHY
259 * @hw: pointer to the HW structure
261 * Acquire access rights to the correct PHY. This is a
262 * function pointer entry point called by the api module.
264 static s32
igc_acquire_phy_base(struct igc_hw
*hw
)
266 u16 mask
= IGC_SWFW_PHY0_SM
;
268 return hw
->mac
.ops
.acquire_swfw_sync(hw
, mask
);
272 * igc_release_phy_base - Release rights to access PHY
273 * @hw: pointer to the HW structure
275 * A wrapper to release access rights to the correct PHY. This is a
276 * function pointer entry point called by the api module.
278 static void igc_release_phy_base(struct igc_hw
*hw
)
280 u16 mask
= IGC_SWFW_PHY0_SM
;
282 hw
->mac
.ops
.release_swfw_sync(hw
, mask
);
286 * igc_init_hw_base - Initialize hardware
287 * @hw: pointer to the HW structure
289 * This inits the hardware readying it for operation.
291 static s32
igc_init_hw_base(struct igc_hw
*hw
)
293 struct igc_mac_info
*mac
= &hw
->mac
;
294 u16 i
, rar_count
= mac
->rar_entry_count
;
297 /* Setup the receive address */
298 igc_init_rx_addrs(hw
, rar_count
);
300 /* Zero out the Multicast HASH table */
301 hw_dbg("Zeroing the MTA\n");
302 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
303 array_wr32(IGC_MTA
, i
, 0);
305 /* Zero out the Unicast HASH table */
306 hw_dbg("Zeroing the UTA\n");
307 for (i
= 0; i
< mac
->uta_reg_count
; i
++)
308 array_wr32(IGC_UTA
, i
, 0);
310 /* Setup link and flow control */
311 ret_val
= igc_setup_link(hw
);
313 /* Clear all of the statistics registers (clear on read). It is
314 * important that we do this after we have tried to establish link
315 * because the symbol error count will increment wildly if there
318 igc_clear_hw_cntrs_base(hw
);
324 * igc_power_down_phy_copper_base - Remove link during PHY power down
325 * @hw: pointer to the HW structure
327 * In the case of a PHY power down to save power, or to turn off link during a
328 * driver unload, or wake on lan is not enabled, remove the link.
330 void igc_power_down_phy_copper_base(struct igc_hw
*hw
)
332 /* If the management interface is not enabled, then power down */
333 if (!(igc_enable_mng_pass_thru(hw
) || igc_check_reset_block(hw
)))
334 igc_power_down_phy_copper(hw
);
338 * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
339 * @hw: pointer to the HW structure
341 * After Rx enable, if manageability is enabled then there is likely some
342 * bad data at the start of the fifo and possibly in the DMA fifo. This
343 * function clears the fifos and flushes any packets that came in as rx was
346 void igc_rx_fifo_flush_base(struct igc_hw
*hw
)
348 u32 rctl
, rlpml
, rxdctl
[4], rfctl
, temp_rctl
, rx_enabled
;
351 /* disable IPv6 options as per hardware errata */
352 rfctl
= rd32(IGC_RFCTL
);
353 rfctl
|= IGC_RFCTL_IPV6_EX_DIS
;
354 wr32(IGC_RFCTL
, rfctl
);
356 if (!(rd32(IGC_MANC
) & IGC_MANC_RCV_TCO_EN
))
359 /* Disable all Rx queues */
360 for (i
= 0; i
< 4; i
++) {
361 rxdctl
[i
] = rd32(IGC_RXDCTL(i
));
363 rxdctl
[i
] & ~IGC_RXDCTL_QUEUE_ENABLE
);
365 /* Poll all queues to verify they have shut down */
366 for (ms_wait
= 0; ms_wait
< 10; ms_wait
++) {
367 usleep_range(1000, 2000);
369 for (i
= 0; i
< 4; i
++)
370 rx_enabled
|= rd32(IGC_RXDCTL(i
));
371 if (!(rx_enabled
& IGC_RXDCTL_QUEUE_ENABLE
))
376 hw_dbg("Queue disable timed out after 10ms\n");
378 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
379 * incoming packets are rejected. Set enable and wait 2ms so that
380 * any packet that was coming in as RCTL.EN was set is flushed
382 wr32(IGC_RFCTL
, rfctl
& ~IGC_RFCTL_LEF
);
384 rlpml
= rd32(IGC_RLPML
);
387 rctl
= rd32(IGC_RCTL
);
388 temp_rctl
= rctl
& ~(IGC_RCTL_EN
| IGC_RCTL_SBP
);
389 temp_rctl
|= IGC_RCTL_LPE
;
391 wr32(IGC_RCTL
, temp_rctl
);
392 wr32(IGC_RCTL
, temp_rctl
| IGC_RCTL_EN
);
394 usleep_range(2000, 3000);
396 /* Enable Rx queues that were previously enabled and restore our
399 for (i
= 0; i
< 4; i
++)
400 wr32(IGC_RXDCTL(i
), rxdctl
[i
]);
401 wr32(IGC_RCTL
, rctl
);
404 wr32(IGC_RLPML
, rlpml
);
405 wr32(IGC_RFCTL
, rfctl
);
407 /* Flush receive errors generated by workaround */
413 static struct igc_mac_operations igc_mac_ops_base
= {
414 .init_hw
= igc_init_hw_base
,
415 .check_for_link
= igc_check_for_copper_link
,
416 .rar_set
= igc_rar_set
,
417 .read_mac_addr
= igc_read_mac_addr
,
418 .get_speed_and_duplex
= igc_get_speed_and_duplex_copper
,
421 static const struct igc_phy_operations igc_phy_ops_base
= {
422 .acquire
= igc_acquire_phy_base
,
423 .release
= igc_release_phy_base
,
424 .reset
= igc_phy_hw_reset
,
425 .read_reg
= igc_read_phy_reg_gpy
,
426 .write_reg
= igc_write_phy_reg_gpy
,
429 const struct igc_info igc_base_info
= {
430 .get_invariants
= igc_get_invariants_base
,
431 .mac_ops
= &igc_mac_ops_base
,
432 .phy_ops
= &igc_phy_ops_base
,