1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
6 #include "e1000_82575.h"
8 #include "e1000_base.h"
9 #include "e1000_manage.h"
12 * e1000_acquire_phy_base - Acquire rights to access PHY
13 * @hw: pointer to the HW structure
15 * Acquire access rights to the correct PHY.
17 s32 e1000_acquire_phy_base(struct e1000_hw *hw)
19 u16 mask = E1000_SWFW_PHY0_SM;
21 DEBUGFUNC("e1000_acquire_phy_base");
23 if (hw->bus.func == E1000_FUNC_1)
24 mask = E1000_SWFW_PHY1_SM;
25 else if (hw->bus.func == E1000_FUNC_2)
26 mask = E1000_SWFW_PHY2_SM;
27 else if (hw->bus.func == E1000_FUNC_3)
28 mask = E1000_SWFW_PHY3_SM;
30 return hw->mac.ops.acquire_swfw_sync(hw, mask);
34 * e1000_release_phy_base - Release rights to access PHY
35 * @hw: pointer to the HW structure
37 * A wrapper to release access rights to the correct PHY.
39 void e1000_release_phy_base(struct e1000_hw *hw)
41 u16 mask = E1000_SWFW_PHY0_SM;
43 DEBUGFUNC("e1000_release_phy_base");
45 if (hw->bus.func == E1000_FUNC_1)
46 mask = E1000_SWFW_PHY1_SM;
47 else if (hw->bus.func == E1000_FUNC_2)
48 mask = E1000_SWFW_PHY2_SM;
49 else if (hw->bus.func == E1000_FUNC_3)
50 mask = E1000_SWFW_PHY3_SM;
52 hw->mac.ops.release_swfw_sync(hw, mask);
56 * e1000_init_hw_base - Initialize hardware
57 * @hw: pointer to the HW structure
59 * This inits the hardware readying it for operation.
61 s32 e1000_init_hw_base(struct e1000_hw *hw)
63 struct e1000_mac_info *mac = &hw->mac;
65 u16 i, rar_count = mac->rar_entry_count;
67 DEBUGFUNC("e1000_init_hw_base");
69 /* Setup the receive address */
70 e1000_init_rx_addrs_generic(hw, rar_count);
72 /* Zero out the Multicast HASH table */
73 DEBUGOUT("Zeroing the MTA\n");
74 for (i = 0; i < mac->mta_reg_count; i++)
75 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
77 /* Zero out the Unicast HASH table */
78 DEBUGOUT("Zeroing the UTA\n");
79 for (i = 0; i < mac->uta_reg_count; i++)
80 E1000_WRITE_REG_ARRAY(hw, E1000_UTA, i, 0);
82 /* Setup link and flow control */
83 ret_val = mac->ops.setup_link(hw);
85 /* Clear all of the statistics registers (clear on read). It is
86 * important that we do this after we have tried to establish link
87 * because the symbol error count will increment wildly if there
90 e1000_clear_hw_cntrs_base_generic(hw);
96 * e1000_power_down_phy_copper_base - Remove link during PHY power down
97 * @hw: pointer to the HW structure
99 * In the case of a PHY power down to save power, or to turn off link during a
100 * driver unload, or wake on lan is not enabled, remove the link.
102 void e1000_power_down_phy_copper_base(struct e1000_hw *hw)
104 struct e1000_phy_info *phy = &hw->phy;
106 if (!(phy->ops.check_reset_block))
109 /* If the management interface is not enabled, then power down */
110 if (phy->ops.check_reset_block(hw))
111 e1000_power_down_phy_copper(hw);
115 * e1000_rx_fifo_flush_base - Clean Rx FIFO after Rx enable
116 * @hw: pointer to the HW structure
118 * After Rx enable, if manageability is enabled then there is likely some
119 * bad data at the start of the FIFO and possibly in the DMA FIFO. This
120 * function clears the FIFOs and flushes any packets that came in as Rx was
123 void e1000_rx_fifo_flush_base(struct e1000_hw *hw)
125 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
128 DEBUGFUNC("e1000_rx_fifo_flush_base");
130 /* disable IPv6 options as per hardware errata */
131 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
132 rfctl |= E1000_RFCTL_IPV6_EX_DIS;
133 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
135 if (!(E1000_READ_REG(hw, E1000_MANC) & E1000_MANC_RCV_TCO_EN))
138 /* Disable all Rx queues */
139 for (i = 0; i < 4; i++) {
140 rxdctl[i] = E1000_READ_REG(hw, E1000_RXDCTL(i));
141 E1000_WRITE_REG(hw, E1000_RXDCTL(i),
142 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
144 /* Poll all queues to verify they have shut down */
145 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
148 for (i = 0; i < 4; i++)
149 rx_enabled |= E1000_READ_REG(hw, E1000_RXDCTL(i));
150 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
155 DEBUGOUT("Queue disable timed out after 10ms\n");
157 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
158 * incoming packets are rejected. Set enable and wait 2ms so that
159 * any packet that was coming in as RCTL.EN was set is flushed
161 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
163 rlpml = E1000_READ_REG(hw, E1000_RLPML);
164 E1000_WRITE_REG(hw, E1000_RLPML, 0);
166 rctl = E1000_READ_REG(hw, E1000_RCTL);
167 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
168 temp_rctl |= E1000_RCTL_LPE;
170 E1000_WRITE_REG(hw, E1000_RCTL, temp_rctl);
171 E1000_WRITE_REG(hw, E1000_RCTL, temp_rctl | E1000_RCTL_EN);
172 E1000_WRITE_FLUSH(hw);
175 /* Enable Rx queues that were previously enabled and restore our
178 for (i = 0; i < 4; i++)
179 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl[i]);
180 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
181 E1000_WRITE_FLUSH(hw);
183 E1000_WRITE_REG(hw, E1000_RLPML, rlpml);
184 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
186 /* Flush receive errors generated by workaround */
187 E1000_READ_REG(hw, E1000_ROC);
188 E1000_READ_REG(hw, E1000_RNBC);
189 E1000_READ_REG(hw, E1000_MPC);