1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018 Intel Corporation */
4 #include <linux/delay.h>
13 * igc_set_pcie_completion_timeout - set pci-e completion timeout
14 * @hw: pointer to the HW structure
16 static s32 igc_set_pcie_completion_timeout(struct igc_hw *hw)
18 u32 gcr = rd32(IGC_GCR);
22 /* only take action if timeout value is defaulted to 0 */
23 if (gcr & IGC_GCR_CMPL_TMOUT_MASK)
26 /* if capabilities version is type 1 we can write the
27 * timeout of 10ms to 200ms through the GCR register
29 if (!(gcr & IGC_GCR_CAP_VER2)) {
30 gcr |= IGC_GCR_CMPL_TMOUT_10ms;
34 /* for version 2 capabilities we need to write the config space
35 * directly in order to set the completion timeout value for
38 ret_val = igc_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
43 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
45 ret_val = igc_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
48 /* disable completion timeout resend */
49 gcr &= ~IGC_GCR_CMPL_TMOUT_RESEND;
57 * igc_check_for_link_base - Check for link
58 * @hw: pointer to the HW structure
60 * If sgmii is enabled, then use the pcs register to determine link, otherwise
61 * use the generic interface for determining link.
63 static s32 igc_check_for_link_base(struct igc_hw *hw)
67 ret_val = igc_check_for_copper_link(hw);
73 * igc_reset_hw_base - Reset hardware
74 * @hw: pointer to the HW structure
76 * This resets the hardware into a known state. This is a
77 * function pointer entry point called by the api module.
79 static s32 igc_reset_hw_base(struct igc_hw *hw)
84 /* Prevent the PCI-E bus from sticking if there is no TLP connection
85 * on the last TLP read/write transaction when MAC is reset.
87 ret_val = igc_disable_pcie_master(hw);
89 hw_dbg("PCI-E Master disable polling has failed.\n");
91 /* set the completion timeout for interface */
92 ret_val = igc_set_pcie_completion_timeout(hw);
94 hw_dbg("PCI-E Set completion timeout has failed.\n");
96 hw_dbg("Masking off all interrupts\n");
97 wr32(IGC_IMC, 0xffffffff);
100 wr32(IGC_TCTL, IGC_TCTL_PSP);
103 usleep_range(10000, 20000);
105 ctrl = rd32(IGC_CTRL);
107 hw_dbg("Issuing a global reset to MAC\n");
108 wr32(IGC_CTRL, ctrl | IGC_CTRL_RST);
110 ret_val = igc_get_auto_rd_done(hw);
112 /* When auto config read does not complete, do not
113 * return with an error. This can happen in situations
114 * where there is no eeprom and prevents getting link.
116 hw_dbg("Auto Read Done did not complete\n");
119 /* Clear any pending interrupt events. */
120 wr32(IGC_IMC, 0xffffffff);
127 * igc_get_phy_id_base - Retrieve PHY addr and id
128 * @hw: pointer to the HW structure
130 * Retrieves the PHY address and ID for both PHY's which do and do not use
133 static s32 igc_get_phy_id_base(struct igc_hw *hw)
137 ret_val = igc_get_phy_id(hw);
143 * igc_init_nvm_params_base - Init NVM func ptrs.
144 * @hw: pointer to the HW structure
146 static s32 igc_init_nvm_params_base(struct igc_hw *hw)
148 struct igc_nvm_info *nvm = &hw->nvm;
149 u32 eecd = rd32(IGC_EECD);
152 size = (u16)((eecd & IGC_EECD_SIZE_EX_MASK) >>
153 IGC_EECD_SIZE_EX_SHIFT);
155 /* Added to a constant, "size" becomes the left-shift value
156 * for setting word_size.
158 size += NVM_WORD_SIZE_BASE_SHIFT;
160 /* Just in case size is out of range, cap it to the largest
161 * EEPROM size supported
166 nvm->word_size = BIT(size);
167 nvm->opcode_bits = 8;
170 nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
171 nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
174 if (nvm->word_size == BIT(15))
175 nvm->page_size = 128;
181 * igc_setup_copper_link_base - Configure copper link settings
182 * @hw: pointer to the HW structure
184 * Configures the link for auto-neg or forced speed and duplex. Then we check
185 * for link, once link is established calls to configure collision distance
186 * and flow control are called.
188 static s32 igc_setup_copper_link_base(struct igc_hw *hw)
193 ctrl = rd32(IGC_CTRL);
194 ctrl |= IGC_CTRL_SLU;
195 ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
196 wr32(IGC_CTRL, ctrl);
198 ret_val = igc_setup_copper_link(hw);
204 * igc_init_mac_params_base - Init MAC func ptrs.
205 * @hw: pointer to the HW structure
207 static s32 igc_init_mac_params_base(struct igc_hw *hw)
209 struct igc_dev_spec_base *dev_spec = &hw->dev_spec._base;
210 struct igc_mac_info *mac = &hw->mac;
212 /* Set mta register count */
213 mac->mta_reg_count = 128;
214 mac->rar_entry_count = IGC_RAR_ENTRIES;
217 mac->ops.reset_hw = igc_reset_hw_base;
219 mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
220 mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
222 /* Allow a single clear of the SW semaphore on I225 */
223 if (mac->type == igc_i225)
224 dev_spec->clear_semaphore_once = true;
226 /* physical interface link setup */
227 mac->ops.setup_physical_interface = igc_setup_copper_link_base;
233 * igc_init_phy_params_base - Init PHY func ptrs.
234 * @hw: pointer to the HW structure
236 static s32 igc_init_phy_params_base(struct igc_hw *hw)
238 struct igc_phy_info *phy = &hw->phy;
241 if (hw->phy.media_type != igc_media_type_copper) {
242 phy->type = igc_phy_none;
246 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;
247 phy->reset_delay_us = 100;
250 hw->bus.func = (rd32(IGC_STATUS) & IGC_STATUS_FUNC_MASK) >>
251 IGC_STATUS_FUNC_SHIFT;
253 /* Make sure the PHY is in a good state. Several people have reported
254 * firmware leaving the PHY's page select register set to something
255 * other than the default of zero, which causes the PHY ID read to
256 * access something other than the intended register.
258 ret_val = hw->phy.ops.reset(hw);
260 hw_dbg("Error resetting the PHY.\n");
264 ret_val = igc_get_phy_id_base(hw);
268 igc_check_for_link_base(hw);
270 /* Verify phy id and set remaining function pointers */
273 phy->type = igc_phy_i225;
276 ret_val = -IGC_ERR_PHY;
284 static s32 igc_get_invariants_base(struct igc_hw *hw)
286 struct igc_mac_info *mac = &hw->mac;
289 switch (hw->device_id) {
290 case IGC_DEV_ID_I225_LM:
291 case IGC_DEV_ID_I225_V:
292 mac->type = igc_i225;
295 return -IGC_ERR_MAC_INIT;
298 hw->phy.media_type = igc_media_type_copper;
300 /* mac initialization and operations */
301 ret_val = igc_init_mac_params_base(hw);
305 /* NVM initialization */
306 ret_val = igc_init_nvm_params_base(hw);
307 switch (hw->mac.type) {
309 ret_val = igc_init_nvm_params_i225(hw);
315 /* setup PHY parameters */
316 ret_val = igc_init_phy_params_base(hw);
325 * igc_acquire_phy_base - Acquire rights to access PHY
326 * @hw: pointer to the HW structure
328 * Acquire access rights to the correct PHY. This is a
329 * function pointer entry point called by the api module.
331 static s32 igc_acquire_phy_base(struct igc_hw *hw)
333 u16 mask = IGC_SWFW_PHY0_SM;
335 return hw->mac.ops.acquire_swfw_sync(hw, mask);
339 * igc_release_phy_base - Release rights to access PHY
340 * @hw: pointer to the HW structure
342 * A wrapper to release access rights to the correct PHY. This is a
343 * function pointer entry point called by the api module.
345 static void igc_release_phy_base(struct igc_hw *hw)
347 u16 mask = IGC_SWFW_PHY0_SM;
349 hw->mac.ops.release_swfw_sync(hw, mask);
353 * igc_get_link_up_info_base - Get link speed/duplex info
354 * @hw: pointer to the HW structure
355 * @speed: stores the current speed
356 * @duplex: stores the current duplex
358 * This is a wrapper function, if using the serial gigabit media independent
359 * interface, use PCS to retrieve the link speed and duplex information.
360 * Otherwise, use the generic function to get the link speed and duplex info.
362 static s32 igc_get_link_up_info_base(struct igc_hw *hw, u16 *speed,
367 ret_val = igc_get_speed_and_duplex_copper(hw, speed, duplex);
373 * igc_init_hw_base - Initialize hardware
374 * @hw: pointer to the HW structure
376 * This inits the hardware readying it for operation.
378 static s32 igc_init_hw_base(struct igc_hw *hw)
380 struct igc_mac_info *mac = &hw->mac;
381 u16 i, rar_count = mac->rar_entry_count;
384 /* Setup the receive address */
385 igc_init_rx_addrs(hw, rar_count);
387 /* Zero out the Multicast HASH table */
388 hw_dbg("Zeroing the MTA\n");
389 for (i = 0; i < mac->mta_reg_count; i++)
390 array_wr32(IGC_MTA, i, 0);
392 /* Zero out the Unicast HASH table */
393 hw_dbg("Zeroing the UTA\n");
394 for (i = 0; i < mac->uta_reg_count; i++)
395 array_wr32(IGC_UTA, i, 0);
397 /* Setup link and flow control */
398 ret_val = igc_setup_link(hw);
400 /* Clear all of the statistics registers (clear on read). It is
401 * important that we do this after we have tried to establish link
402 * because the symbol error count will increment wildly if there
405 igc_clear_hw_cntrs_base(hw);
411 * igc_read_mac_addr_base - Read device MAC address
412 * @hw: pointer to the HW structure
414 static s32 igc_read_mac_addr_base(struct igc_hw *hw)
418 ret_val = igc_read_mac_addr(hw);
424 * igc_power_down_phy_copper_base - Remove link during PHY power down
425 * @hw: pointer to the HW structure
427 * In the case of a PHY power down to save power, or to turn off link during a
428 * driver unload, or wake on lan is not enabled, remove the link.
430 void igc_power_down_phy_copper_base(struct igc_hw *hw)
432 /* If the management interface is not enabled, then power down */
433 if (!(igc_enable_mng_pass_thru(hw) || igc_check_reset_block(hw)))
434 igc_power_down_phy_copper(hw);
438 * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
439 * @hw: pointer to the HW structure
441 * After Rx enable, if manageability is enabled then there is likely some
442 * bad data at the start of the fifo and possibly in the DMA fifo. This
443 * function clears the fifos and flushes any packets that came in as rx was
446 void igc_rx_fifo_flush_base(struct igc_hw *hw)
448 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
451 /* disable IPv6 options as per hardware errata */
452 rfctl = rd32(IGC_RFCTL);
453 rfctl |= IGC_RFCTL_IPV6_EX_DIS;
454 wr32(IGC_RFCTL, rfctl);
456 if (!(rd32(IGC_MANC) & IGC_MANC_RCV_TCO_EN))
459 /* Disable all Rx queues */
460 for (i = 0; i < 4; i++) {
461 rxdctl[i] = rd32(IGC_RXDCTL(i));
463 rxdctl[i] & ~IGC_RXDCTL_QUEUE_ENABLE);
465 /* Poll all queues to verify they have shut down */
466 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
467 usleep_range(1000, 2000);
469 for (i = 0; i < 4; i++)
470 rx_enabled |= rd32(IGC_RXDCTL(i));
471 if (!(rx_enabled & IGC_RXDCTL_QUEUE_ENABLE))
476 pr_debug("Queue disable timed out after 10ms\n");
478 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
479 * incoming packets are rejected. Set enable and wait 2ms so that
480 * any packet that was coming in as RCTL.EN was set is flushed
482 wr32(IGC_RFCTL, rfctl & ~IGC_RFCTL_LEF);
484 rlpml = rd32(IGC_RLPML);
487 rctl = rd32(IGC_RCTL);
488 temp_rctl = rctl & ~(IGC_RCTL_EN | IGC_RCTL_SBP);
489 temp_rctl |= IGC_RCTL_LPE;
491 wr32(IGC_RCTL, temp_rctl);
492 wr32(IGC_RCTL, temp_rctl | IGC_RCTL_EN);
494 usleep_range(2000, 3000);
496 /* Enable Rx queues that were previously enabled and restore our
499 for (i = 0; i < 4; i++)
500 wr32(IGC_RXDCTL(i), rxdctl[i]);
501 wr32(IGC_RCTL, rctl);
504 wr32(IGC_RLPML, rlpml);
505 wr32(IGC_RFCTL, rfctl);
507 /* Flush receive errors generated by workaround */
513 static struct igc_mac_operations igc_mac_ops_base = {
514 .init_hw = igc_init_hw_base,
515 .check_for_link = igc_check_for_link_base,
516 .rar_set = igc_rar_set,
517 .read_mac_addr = igc_read_mac_addr_base,
518 .get_speed_and_duplex = igc_get_link_up_info_base,
521 static const struct igc_phy_operations igc_phy_ops_base = {
522 .acquire = igc_acquire_phy_base,
523 .release = igc_release_phy_base,
524 .reset = igc_phy_hw_reset,
525 .read_reg = igc_read_phy_reg_gpy,
526 .write_reg = igc_write_phy_reg_gpy,
529 const struct igc_info igc_base_info = {
530 .get_invariants = igc_get_invariants_base,
531 .mac_ops = &igc_mac_ops_base,
532 .phy_ops = &igc_phy_ops_base,