Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2020 Intel Corporation
3 : : */
4 : :
5 : : /*
6 : : * 82575EB Gigabit Network Connection
7 : : * 82575EB Gigabit Backplane Connection
8 : : * 82575GB Gigabit Network Connection
9 : : * 82576 Gigabit Network Connection
10 : : * 82576 Quad Port Gigabit Mezzanine Adapter
11 : : * 82580 Gigabit Network Connection
12 : : * I350 Gigabit Network Connection
13 : : */
14 : :
15 : : #include "e1000_api.h"
16 : : #include "e1000_i210.h"
17 : :
18 : : STATIC s32 e1000_init_phy_params_82575(struct e1000_hw *hw);
19 : : STATIC s32 e1000_init_mac_params_82575(struct e1000_hw *hw);
20 : : STATIC s32 e1000_acquire_nvm_82575(struct e1000_hw *hw);
21 : : STATIC void e1000_release_nvm_82575(struct e1000_hw *hw);
22 : : STATIC s32 e1000_check_for_link_82575(struct e1000_hw *hw);
23 : : STATIC s32 e1000_check_for_link_media_swap(struct e1000_hw *hw);
24 : : STATIC s32 e1000_get_cfg_done_82575(struct e1000_hw *hw);
25 : : STATIC s32 e1000_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
26 : : u16 *duplex);
27 : : STATIC s32 e1000_phy_hw_reset_sgmii_82575(struct e1000_hw *hw);
28 : : STATIC s32 e1000_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
29 : : u16 *data);
30 : : STATIC s32 e1000_reset_hw_82575(struct e1000_hw *hw);
31 : : STATIC s32 e1000_init_hw_82575(struct e1000_hw *hw);
32 : : STATIC s32 e1000_reset_hw_82580(struct e1000_hw *hw);
33 : : STATIC s32 e1000_read_phy_reg_82580(struct e1000_hw *hw,
34 : : u32 offset, u16 *data);
35 : : STATIC s32 e1000_write_phy_reg_82580(struct e1000_hw *hw,
36 : : u32 offset, u16 data);
37 : : STATIC s32 e1000_set_d0_lplu_state_82580(struct e1000_hw *hw,
38 : : bool active);
39 : : STATIC s32 e1000_set_d3_lplu_state_82580(struct e1000_hw *hw,
40 : : bool active);
41 : : STATIC s32 e1000_set_d0_lplu_state_82575(struct e1000_hw *hw,
42 : : bool active);
43 : : STATIC s32 e1000_setup_copper_link_82575(struct e1000_hw *hw);
44 : : STATIC s32 e1000_setup_serdes_link_82575(struct e1000_hw *hw);
45 : : STATIC s32 e1000_get_media_type_82575(struct e1000_hw *hw);
46 : : STATIC s32 e1000_set_sfp_media_type_82575(struct e1000_hw *hw);
47 : : STATIC s32 e1000_valid_led_default_82575(struct e1000_hw *hw, u16 *data);
48 : : STATIC s32 e1000_write_phy_reg_sgmii_82575(struct e1000_hw *hw,
49 : : u32 offset, u16 data);
50 : : STATIC void e1000_clear_hw_cntrs_82575(struct e1000_hw *hw);
51 : : STATIC s32 e1000_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask);
52 : : STATIC s32 e1000_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw,
53 : : u16 *speed, u16 *duplex);
54 : : STATIC s32 e1000_get_phy_id_82575(struct e1000_hw *hw);
55 : : STATIC void e1000_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask);
56 : : STATIC bool e1000_sgmii_active_82575(struct e1000_hw *hw);
57 : : STATIC s32 e1000_read_mac_addr_82575(struct e1000_hw *hw);
58 : : STATIC void e1000_config_collision_dist_82575(struct e1000_hw *hw);
59 : : STATIC void e1000_shutdown_serdes_link_82575(struct e1000_hw *hw);
60 : : STATIC void e1000_power_up_serdes_link_82575(struct e1000_hw *hw);
61 : : STATIC s32 e1000_set_pcie_completion_timeout(struct e1000_hw *hw);
62 : : STATIC s32 e1000_reset_mdicnfg_82580(struct e1000_hw *hw);
63 : : STATIC s32 e1000_validate_nvm_checksum_82580(struct e1000_hw *hw);
64 : : STATIC s32 e1000_update_nvm_checksum_82580(struct e1000_hw *hw);
65 : : STATIC s32 e1000_update_nvm_checksum_with_offset(struct e1000_hw *hw,
66 : : u16 offset);
67 : : STATIC s32 e1000_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
68 : : u16 offset);
69 : : STATIC s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw);
70 : : STATIC s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw);
71 : : STATIC void e1000_clear_vfta_i350(struct e1000_hw *hw);
72 : :
73 : : STATIC void e1000_i2c_start(struct e1000_hw *hw);
74 : : STATIC void e1000_i2c_stop(struct e1000_hw *hw);
75 : : STATIC void e1000_clock_in_i2c_byte(struct e1000_hw *hw, u8 *data);
76 : : STATIC s32 e1000_clock_out_i2c_byte(struct e1000_hw *hw, u8 data);
77 : : STATIC s32 e1000_get_i2c_ack(struct e1000_hw *hw);
78 : : STATIC void e1000_clock_in_i2c_bit(struct e1000_hw *hw, bool *data);
79 : : STATIC s32 e1000_clock_out_i2c_bit(struct e1000_hw *hw, bool data);
80 : : STATIC void e1000_raise_i2c_clk(struct e1000_hw *hw, u32 *i2cctl);
81 : : STATIC void e1000_lower_i2c_clk(struct e1000_hw *hw, u32 *i2cctl);
82 : : STATIC s32 e1000_set_i2c_data(struct e1000_hw *hw, u32 *i2cctl, bool data);
83 : : STATIC bool e1000_get_i2c_data(u32 *i2cctl);
84 : :
85 : : STATIC const u16 e1000_82580_rxpbs_table[] = {
86 : : 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
87 : : #define E1000_82580_RXPBS_TABLE_SIZE \
88 : : (sizeof(e1000_82580_rxpbs_table) / \
89 : : sizeof(e1000_82580_rxpbs_table[0]))
90 : :
91 : :
92 : : /**
93 : : * e1000_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
94 : : * @hw: pointer to the HW structure
95 : : *
96 : : * Called to determine if the I2C pins are being used for I2C or as an
97 : : * external MDIO interface since the two options are mutually exclusive.
98 : : **/
99 : 0 : STATIC bool e1000_sgmii_uses_mdio_82575(struct e1000_hw *hw)
100 : : {
101 : : u32 reg = 0;
102 : : bool ext_mdio = false;
103 : :
104 : 0 : DEBUGFUNC("e1000_sgmii_uses_mdio_82575");
105 : :
106 [ # # # ]: 0 : switch (hw->mac.type) {
107 : 0 : case e1000_82575:
108 : : case e1000_82576:
109 : 0 : reg = E1000_READ_REG(hw, E1000_MDIC);
110 : 0 : ext_mdio = !!(reg & E1000_MDIC_DEST);
111 : 0 : break;
112 : 0 : case e1000_82580:
113 : : case e1000_i350:
114 : : case e1000_i354:
115 : : case e1000_i210:
116 : : case e1000_i211:
117 : 0 : reg = E1000_READ_REG(hw, E1000_MDICNFG);
118 : 0 : ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
119 : 0 : break;
120 : : default:
121 : : break;
122 : : }
123 : 0 : return ext_mdio;
124 : : }
125 : :
126 : : /**
127 : : * e1000_init_phy_params_82575 - Initialize PHY function ptrs
128 : : * @hw: pointer to the HW structure
129 : : **/
130 : 0 : STATIC s32 e1000_init_phy_params_82575(struct e1000_hw *hw)
131 : : {
132 : : struct e1000_phy_info *phy = &hw->phy;
133 : : s32 ret_val = E1000_SUCCESS;
134 : : u32 ctrl_ext;
135 : :
136 : 0 : DEBUGFUNC("e1000_init_phy_params_82575");
137 : :
138 : 0 : phy->ops.read_i2c_byte = e1000_read_i2c_byte_generic;
139 : 0 : phy->ops.write_i2c_byte = e1000_write_i2c_byte_generic;
140 : :
141 [ # # ]: 0 : if (hw->phy.media_type != e1000_media_type_copper) {
142 : 0 : phy->type = e1000_phy_none;
143 : 0 : goto out;
144 : : }
145 : :
146 : 0 : phy->ops.power_up = e1000_power_up_phy_copper;
147 : 0 : phy->ops.power_down = e1000_power_down_phy_copper_base;
148 : :
149 : 0 : phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
150 : 0 : phy->reset_delay_us = 100;
151 : :
152 : 0 : phy->ops.acquire = e1000_acquire_phy_base;
153 : 0 : phy->ops.check_reset_block = e1000_check_reset_block_generic;
154 : 0 : phy->ops.commit = e1000_phy_sw_reset_generic;
155 : 0 : phy->ops.get_cfg_done = e1000_get_cfg_done_82575;
156 : 0 : phy->ops.release = e1000_release_phy_base;
157 : :
158 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
159 : :
160 : 0 : if (e1000_sgmii_active_82575(hw)) {
161 : 0 : phy->ops.reset = e1000_phy_hw_reset_sgmii_82575;
162 : 0 : ctrl_ext |= E1000_CTRL_I2C_ENA;
163 : : } else {
164 : 0 : phy->ops.reset = e1000_phy_hw_reset_generic;
165 : 0 : ctrl_ext &= ~E1000_CTRL_I2C_ENA;
166 : : }
167 : :
168 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
169 : 0 : e1000_reset_mdicnfg_82580(hw);
170 : :
171 [ # # ]: 0 : if (e1000_sgmii_active_82575(hw) && !e1000_sgmii_uses_mdio_82575(hw)) {
172 : 0 : phy->ops.read_reg = e1000_read_phy_reg_sgmii_82575;
173 : 0 : phy->ops.write_reg = e1000_write_phy_reg_sgmii_82575;
174 : : } else {
175 [ # # # ]: 0 : switch (hw->mac.type) {
176 : 0 : case e1000_82580:
177 : : case e1000_i350:
178 : : case e1000_i354:
179 : 0 : phy->ops.read_reg = e1000_read_phy_reg_82580;
180 : 0 : phy->ops.write_reg = e1000_write_phy_reg_82580;
181 : 0 : break;
182 : 0 : case e1000_i210:
183 : : case e1000_i211:
184 : 0 : phy->ops.read_reg = e1000_read_phy_reg_gs40g;
185 : 0 : phy->ops.write_reg = e1000_write_phy_reg_gs40g;
186 : 0 : break;
187 : 0 : default:
188 : 0 : phy->ops.read_reg = e1000_read_phy_reg_igp;
189 : 0 : phy->ops.write_reg = e1000_write_phy_reg_igp;
190 : : }
191 : : }
192 : :
193 : : /* Set phy->phy_addr and phy->id. */
194 : 0 : ret_val = e1000_get_phy_id_82575(hw);
195 : :
196 : : /* Verify phy id and set remaining function pointers */
197 [ # # # # : 0 : switch (phy->id) {
# # # ]
198 : 0 : case M88E1543_E_PHY_ID:
199 : : case M88E1512_E_PHY_ID:
200 : : case I347AT4_E_PHY_ID:
201 : : case M88E1112_E_PHY_ID:
202 : : case M88E1340M_E_PHY_ID:
203 : 0 : phy->type = e1000_phy_m88;
204 : 0 : phy->ops.check_polarity = e1000_check_polarity_m88;
205 : 0 : phy->ops.get_info = e1000_get_phy_info_m88;
206 : 0 : phy->ops.get_cable_length = e1000_get_cable_length_m88_gen2;
207 : 0 : phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
208 : 0 : break;
209 : 0 : case M88E1111_I_PHY_ID:
210 : 0 : phy->type = e1000_phy_m88;
211 : 0 : phy->ops.check_polarity = e1000_check_polarity_m88;
212 : 0 : phy->ops.get_info = e1000_get_phy_info_m88;
213 : 0 : phy->ops.get_cable_length = e1000_get_cable_length_m88;
214 : 0 : phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
215 : 0 : break;
216 : 0 : case IGP03E1000_E_PHY_ID:
217 : : case IGP04E1000_E_PHY_ID:
218 : 0 : phy->type = e1000_phy_igp_3;
219 : 0 : phy->ops.check_polarity = e1000_check_polarity_igp;
220 : 0 : phy->ops.get_info = e1000_get_phy_info_igp;
221 : 0 : phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
222 : 0 : phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82575;
223 : 0 : phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_generic;
224 : 0 : phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
225 : 0 : break;
226 : 0 : case I82580_I_PHY_ID:
227 : : case I350_I_PHY_ID:
228 : 0 : phy->type = e1000_phy_82580;
229 : 0 : phy->ops.check_polarity = e1000_check_polarity_82577;
230 : 0 : phy->ops.get_info = e1000_get_phy_info_82577;
231 : 0 : phy->ops.get_cable_length = e1000_get_cable_length_82577;
232 : 0 : phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82580;
233 : 0 : phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82580;
234 : 0 : phy->ops.force_speed_duplex =
235 : : e1000_phy_force_speed_duplex_82577;
236 : 0 : break;
237 : 0 : case I210_I_PHY_ID:
238 : 0 : phy->type = e1000_phy_i210;
239 : 0 : phy->ops.check_polarity = e1000_check_polarity_m88;
240 : 0 : phy->ops.get_info = e1000_get_phy_info_m88;
241 : 0 : phy->ops.get_cable_length = e1000_get_cable_length_m88_gen2;
242 : 0 : phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82580;
243 : 0 : phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82580;
244 : 0 : phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
245 : 0 : break;
246 : 0 : case BCM54616_E_PHY_ID:
247 : 0 : phy->type = e1000_phy_none;
248 : 0 : break;
249 : 0 : default:
250 : : ret_val = -E1000_ERR_PHY;
251 : 0 : goto out;
252 : : }
253 : :
254 : : /* Check if this PHY is configured for media swap. */
255 [ # # # # ]: 0 : switch (phy->id) {
256 : 0 : case M88E1112_E_PHY_ID:
257 : : {
258 : : u16 data;
259 : :
260 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 2);
261 [ # # ]: 0 : if (ret_val)
262 : 0 : goto out;
263 : 0 : ret_val = phy->ops.read_reg(hw, E1000_M88E1112_MAC_CTRL_1,
264 : : &data);
265 [ # # ]: 0 : if (ret_val)
266 : 0 : goto out;
267 : :
268 : 0 : data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
269 : : E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
270 [ # # ]: 0 : if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
271 : : data == E1000_M88E1112_AUTO_COPPER_BASEX)
272 : 0 : hw->mac.ops.check_for_link =
273 : : e1000_check_for_link_media_swap;
274 : 0 : break;
275 : : }
276 : 0 : case M88E1512_E_PHY_ID:
277 : : {
278 : 0 : ret_val = e1000_initialize_M88E1512_phy(hw);
279 : 0 : break;
280 : : }
281 : 0 : case M88E1543_E_PHY_ID:
282 : : {
283 : 0 : ret_val = e1000_initialize_M88E1543_phy(hw);
284 : 0 : break;
285 : : }
286 : 0 : default:
287 : 0 : goto out;
288 : : }
289 : :
290 : 0 : out:
291 : 0 : return ret_val;
292 : : }
293 : :
294 : : /**
295 : : * e1000_init_mac_params_82575 - Initialize MAC function ptrs
296 : : * @hw: pointer to the HW structure
297 : : **/
298 : 0 : STATIC s32 e1000_init_mac_params_82575(struct e1000_hw *hw)
299 : : {
300 : : struct e1000_mac_info *mac = &hw->mac;
301 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
302 : :
303 : 0 : DEBUGFUNC("e1000_init_mac_params_82575");
304 : :
305 : : /* Initialize function pointer */
306 : 0 : e1000_init_mac_ops_generic(hw);
307 : :
308 : : /* Derives media type */
309 : 0 : e1000_get_media_type_82575(hw);
310 : : /* Set MTA register count */
311 : 0 : mac->mta_reg_count = 128;
312 : : /* Set UTA register count */
313 [ # # ]: 0 : mac->uta_reg_count = (hw->mac.type == e1000_82575) ? 0 : 128;
314 : : /* Set RAR entry count */
315 : 0 : mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
316 [ # # ]: 0 : if (mac->type == e1000_82576)
317 : 0 : mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
318 [ # # ]: 0 : if (mac->type == e1000_82580)
319 : 0 : mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
320 [ # # ]: 0 : if (mac->type == e1000_i350 || mac->type == e1000_i354)
321 : 0 : mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
322 : :
323 : : /* Enable EEE default settings for EEE supported devices */
324 [ # # ]: 0 : if (mac->type >= e1000_i350)
325 : 0 : dev_spec->eee_disable = false;
326 : :
327 : : /* Allow a single clear of the SW semaphore on I210 and newer */
328 [ # # ]: 0 : if (mac->type >= e1000_i210)
329 : 0 : dev_spec->clear_semaphore_once = true;
330 : :
331 : : /* Set if part includes ASF firmware */
332 : 0 : mac->asf_firmware_present = true;
333 : : /* FWSM register */
334 : 0 : mac->has_fwsm = true;
335 : : /* ARC supported; valid only if manageability features are enabled. */
336 : 0 : mac->arc_subsystem_valid =
337 : 0 : !!(E1000_READ_REG(hw, E1000_FWSM) & E1000_FWSM_MODE_MASK);
338 : :
339 : : /* Function pointers */
340 : :
341 : : /* bus type/speed/width */
342 : 0 : mac->ops.get_bus_info = e1000_get_bus_info_pcie_generic;
343 : : /* reset */
344 [ # # ]: 0 : if (mac->type >= e1000_82580)
345 : 0 : mac->ops.reset_hw = e1000_reset_hw_82580;
346 : : else
347 : 0 : mac->ops.reset_hw = e1000_reset_hw_82575;
348 : : /* HW initialization */
349 [ # # ]: 0 : if ((mac->type == e1000_i210) || (mac->type == e1000_i211))
350 : 0 : mac->ops.init_hw = e1000_init_hw_i210;
351 : : else
352 : 0 : mac->ops.init_hw = e1000_init_hw_82575;
353 : : /* link setup */
354 : 0 : mac->ops.setup_link = e1000_setup_link_generic;
355 : : /* physical interface link setup */
356 : 0 : mac->ops.setup_physical_interface =
357 : 0 : (hw->phy.media_type == e1000_media_type_copper)
358 [ # # ]: 0 : ? e1000_setup_copper_link_82575 : e1000_setup_serdes_link_82575;
359 : : /* physical interface shutdown */
360 : 0 : mac->ops.shutdown_serdes = e1000_shutdown_serdes_link_82575;
361 : : /* physical interface power up */
362 : 0 : mac->ops.power_up_serdes = e1000_power_up_serdes_link_82575;
363 : : /* check for link */
364 : 0 : mac->ops.check_for_link = e1000_check_for_link_82575;
365 : : /* read mac address */
366 : 0 : mac->ops.read_mac_addr = e1000_read_mac_addr_82575;
367 : : /* configure collision distance */
368 : 0 : mac->ops.config_collision_dist = e1000_config_collision_dist_82575;
369 : : /* multicast address update */
370 : 0 : mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
371 [ # # # # ]: 0 : if (hw->mac.type == e1000_i350 || mac->type == e1000_i354) {
372 : : /* writing VFTA */
373 : 0 : mac->ops.write_vfta = e1000_write_vfta_i350;
374 : : /* clearing VFTA */
375 : 0 : mac->ops.clear_vfta = e1000_clear_vfta_i350;
376 : : } else {
377 : : /* writing VFTA */
378 : 0 : mac->ops.write_vfta = e1000_write_vfta_generic;
379 : : /* clearing VFTA */
380 : 0 : mac->ops.clear_vfta = e1000_clear_vfta_generic;
381 : : }
382 [ # # ]: 0 : if (hw->mac.type >= e1000_82580)
383 : 0 : mac->ops.validate_mdi_setting =
384 : : e1000_validate_mdi_setting_crossover_generic;
385 : : /* ID LED init */
386 : 0 : mac->ops.id_led_init = e1000_id_led_init_generic;
387 : : /* blink LED */
388 : 0 : mac->ops.blink_led = e1000_blink_led_generic;
389 : : /* setup LED */
390 : 0 : mac->ops.setup_led = e1000_setup_led_generic;
391 : : /* cleanup LED */
392 : 0 : mac->ops.cleanup_led = e1000_cleanup_led_generic;
393 : : /* turn on/off LED */
394 : 0 : mac->ops.led_on = e1000_led_on_generic;
395 : 0 : mac->ops.led_off = e1000_led_off_generic;
396 : : /* clear hardware counters */
397 : 0 : mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82575;
398 : : /* link info */
399 : 0 : mac->ops.get_link_up_info = e1000_get_link_up_info_82575;
400 : : /* acquire SW_FW sync */
401 : 0 : mac->ops.acquire_swfw_sync = e1000_acquire_swfw_sync_82575;
402 : : /* release SW_FW sync */
403 : 0 : mac->ops.release_swfw_sync = e1000_release_swfw_sync_82575;
404 [ # # ]: 0 : if (mac->type == e1000_i210 || mac->type == e1000_i211) {
405 : 0 : mac->ops.acquire_swfw_sync = e1000_acquire_swfw_sync_i210;
406 : 0 : mac->ops.release_swfw_sync = e1000_release_swfw_sync_i210;
407 : : }
408 : :
409 : : /* set lan id for port to determine which phy lock to use */
410 : 0 : hw->mac.ops.set_lan_id(hw);
411 : :
412 : 0 : return E1000_SUCCESS;
413 : : }
414 : :
415 : : /**
416 : : * e1000_init_nvm_params_82575 - Initialize NVM function ptrs
417 : : * @hw: pointer to the HW structure
418 : : **/
419 : 0 : s32 e1000_init_nvm_params_82575(struct e1000_hw *hw)
420 : : {
421 : : struct e1000_nvm_info *nvm = &hw->nvm;
422 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
423 : : u16 size;
424 : :
425 : 0 : DEBUGFUNC("e1000_init_nvm_params_82575");
426 : :
427 : 0 : size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
428 : : E1000_EECD_SIZE_EX_SHIFT);
429 : : /* Added to a constant, "size" becomes the left-shift value
430 : : * for setting word_size.
431 : : */
432 : 0 : size += NVM_WORD_SIZE_BASE_SHIFT;
433 : :
434 : : /* Just in case size is out of range, cap it to the largest
435 : : * EEPROM size supported
436 : : */
437 : : if (size > 15)
438 : : size = 15;
439 : :
440 : 0 : nvm->word_size = 1 << size;
441 [ # # ]: 0 : if (hw->mac.type < e1000_i210) {
442 : 0 : nvm->opcode_bits = 8;
443 : 0 : nvm->delay_usec = 1;
444 : :
445 [ # # # ]: 0 : switch (nvm->override) {
446 : 0 : case e1000_nvm_override_spi_large:
447 : 0 : nvm->page_size = 32;
448 : 0 : nvm->address_bits = 16;
449 : 0 : break;
450 : 0 : case e1000_nvm_override_spi_small:
451 : 0 : nvm->page_size = 8;
452 : 0 : nvm->address_bits = 8;
453 : 0 : break;
454 : 0 : default:
455 [ # # ]: 0 : nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
456 [ # # ]: 0 : nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
457 : : 16 : 8;
458 : 0 : break;
459 : : }
460 [ # # ]: 0 : if (nvm->word_size == (1 << 15))
461 : 0 : nvm->page_size = 128;
462 : :
463 : 0 : nvm->type = e1000_nvm_eeprom_spi;
464 : : } else {
465 : 0 : nvm->type = e1000_nvm_flash_hw;
466 : : }
467 : :
468 : : /* Function Pointers */
469 : 0 : nvm->ops.acquire = e1000_acquire_nvm_82575;
470 : 0 : nvm->ops.release = e1000_release_nvm_82575;
471 [ # # ]: 0 : if (nvm->word_size < (1 << 15))
472 : 0 : nvm->ops.read = e1000_read_nvm_eerd;
473 : : else
474 : 0 : nvm->ops.read = e1000_read_nvm_spi;
475 : :
476 : 0 : nvm->ops.write = e1000_write_nvm_spi;
477 : 0 : nvm->ops.validate = e1000_validate_nvm_checksum_generic;
478 : 0 : nvm->ops.update = e1000_update_nvm_checksum_generic;
479 : 0 : nvm->ops.valid_led_default = e1000_valid_led_default_82575;
480 : :
481 : : /* override generic family function pointers for specific descendants */
482 [ # # # ]: 0 : switch (hw->mac.type) {
483 : 0 : case e1000_82580:
484 : 0 : nvm->ops.validate = e1000_validate_nvm_checksum_82580;
485 : 0 : nvm->ops.update = e1000_update_nvm_checksum_82580;
486 : 0 : break;
487 : 0 : case e1000_i350:
488 : 0 : nvm->ops.validate = e1000_validate_nvm_checksum_i350;
489 : 0 : nvm->ops.update = e1000_update_nvm_checksum_i350;
490 : 0 : break;
491 : : default:
492 : : break;
493 : : }
494 : :
495 : 0 : return E1000_SUCCESS;
496 : : }
497 : :
498 : : /**
499 : : * e1000_init_function_pointers_82575 - Init func ptrs.
500 : : * @hw: pointer to the HW structure
501 : : *
502 : : * Called to initialize all function pointers and parameters.
503 : : **/
504 : 0 : void e1000_init_function_pointers_82575(struct e1000_hw *hw)
505 : : {
506 : 0 : DEBUGFUNC("e1000_init_function_pointers_82575");
507 : :
508 : 0 : hw->mac.ops.init_params = e1000_init_mac_params_82575;
509 : 0 : hw->nvm.ops.init_params = e1000_init_nvm_params_82575;
510 : 0 : hw->phy.ops.init_params = e1000_init_phy_params_82575;
511 : 0 : hw->mbx.ops.init_params = e1000_init_mbx_params_pf;
512 : 0 : }
513 : :
514 : : /**
515 : : * e1000_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
516 : : * @hw: pointer to the HW structure
517 : : * @offset: register offset to be read
518 : : * @data: pointer to the read data
519 : : *
520 : : * Reads the PHY register at offset using the serial gigabit media independent
521 : : * interface and stores the retrieved information in data.
522 : : **/
523 : 0 : STATIC s32 e1000_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
524 : : u16 *data)
525 : : {
526 : : s32 ret_val = -E1000_ERR_PARAM;
527 : :
528 : 0 : DEBUGFUNC("e1000_read_phy_reg_sgmii_82575");
529 : :
530 [ # # ]: 0 : if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
531 : 0 : DEBUGOUT1("PHY Address %u is out of range\n", offset);
532 : 0 : goto out;
533 : : }
534 : :
535 : 0 : ret_val = hw->phy.ops.acquire(hw);
536 [ # # ]: 0 : if (ret_val)
537 : 0 : goto out;
538 : :
539 : 0 : ret_val = e1000_read_phy_reg_i2c(hw, offset, data);
540 : :
541 : 0 : hw->phy.ops.release(hw);
542 : :
543 : 0 : out:
544 : 0 : return ret_val;
545 : : }
546 : :
547 : : /**
548 : : * e1000_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
549 : : * @hw: pointer to the HW structure
550 : : * @offset: register offset to write to
551 : : * @data: data to write at register offset
552 : : *
553 : : * Writes the data to PHY register at the offset using the serial gigabit
554 : : * media independent interface.
555 : : **/
556 : 0 : STATIC s32 e1000_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
557 : : u16 data)
558 : : {
559 : : s32 ret_val = -E1000_ERR_PARAM;
560 : :
561 : 0 : DEBUGFUNC("e1000_write_phy_reg_sgmii_82575");
562 : :
563 [ # # ]: 0 : if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
564 : 0 : DEBUGOUT1("PHY Address %d is out of range\n", offset);
565 : 0 : goto out;
566 : : }
567 : :
568 : 0 : ret_val = hw->phy.ops.acquire(hw);
569 [ # # ]: 0 : if (ret_val)
570 : 0 : goto out;
571 : :
572 : 0 : ret_val = e1000_write_phy_reg_i2c(hw, offset, data);
573 : :
574 : 0 : hw->phy.ops.release(hw);
575 : :
576 : 0 : out:
577 : 0 : return ret_val;
578 : : }
579 : :
580 : : /**
581 : : * e1000_get_phy_id_82575 - Retrieve PHY addr and id
582 : : * @hw: pointer to the HW structure
583 : : *
584 : : * Retrieves the PHY address and ID for both PHY's which do and do not use
585 : : * sgmi interface.
586 : : **/
587 : 0 : STATIC s32 e1000_get_phy_id_82575(struct e1000_hw *hw)
588 : : {
589 : : struct e1000_phy_info *phy = &hw->phy;
590 : : s32 ret_val = E1000_SUCCESS;
591 : : u16 phy_id;
592 : : u32 ctrl_ext;
593 : : u32 mdic;
594 : :
595 : 0 : DEBUGFUNC("e1000_get_phy_id_82575");
596 : :
597 : : /* some i354 devices need an extra read for phy id */
598 [ # # ]: 0 : if (hw->mac.type == e1000_i354)
599 : 0 : e1000_get_phy_id(hw);
600 : :
601 : : /*
602 : : * For SGMII PHYs, we try the list of possible addresses until
603 : : * we find one that works. For non-SGMII PHYs
604 : : * (e.g. integrated copper PHYs), an address of 1 should
605 : : * work. The result of this function should mean phy->phy_addr
606 : : * and phy->id are set correctly.
607 : : */
608 : 0 : if (!e1000_sgmii_active_82575(hw)) {
609 : 0 : phy->addr = 1;
610 : 0 : ret_val = e1000_get_phy_id(hw);
611 : 0 : goto out;
612 : : }
613 : :
614 [ # # ]: 0 : if (e1000_sgmii_uses_mdio_82575(hw)) {
615 [ # # # ]: 0 : switch (hw->mac.type) {
616 : 0 : case e1000_82575:
617 : : case e1000_82576:
618 : 0 : mdic = E1000_READ_REG(hw, E1000_MDIC);
619 : : mdic &= E1000_MDIC_PHY_MASK;
620 : 0 : phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
621 : 0 : break;
622 : 0 : case e1000_82580:
623 : : case e1000_i350:
624 : : case e1000_i354:
625 : : case e1000_i210:
626 : : case e1000_i211:
627 : 0 : mdic = E1000_READ_REG(hw, E1000_MDICNFG);
628 : : mdic &= E1000_MDICNFG_PHY_MASK;
629 : 0 : phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
630 : 0 : break;
631 : 0 : default:
632 : : ret_val = -E1000_ERR_PHY;
633 : 0 : goto out;
634 : : break;
635 : : }
636 : 0 : ret_val = e1000_get_phy_id(hw);
637 : 0 : goto out;
638 : : }
639 : :
640 : : /* Power on sgmii phy if it is disabled */
641 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
642 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
643 : : ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
644 : 0 : E1000_WRITE_FLUSH(hw);
645 : 0 : msec_delay(300);
646 : :
647 : : /*
648 : : * The address field in the I2CCMD register is 3 bits and 0 is invalid.
649 : : * Therefore, we need to test 1-7
650 : : */
651 [ # # ]: 0 : for (phy->addr = 1; phy->addr < 8; phy->addr++) {
652 : 0 : ret_val = e1000_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
653 [ # # ]: 0 : if (ret_val == E1000_SUCCESS) {
654 : 0 : DEBUGOUT2("Vendor ID 0x%08X read at address %u\n",
655 : : phy_id, phy->addr);
656 : : /*
657 : : * At the time of this writing, The M88 part is
658 : : * the only supported SGMII PHY product.
659 : : */
660 [ # # ]: 0 : if (phy_id == M88_VENDOR)
661 : : break;
662 : : } else {
663 : 0 : DEBUGOUT1("PHY address %u was unreadable\n",
664 : : phy->addr);
665 : : }
666 : : }
667 : :
668 : : /* A valid PHY type couldn't be found. */
669 [ # # ]: 0 : if (phy->addr == 8) {
670 : 0 : phy->addr = 0;
671 : : ret_val = -E1000_ERR_PHY;
672 : : } else {
673 : 0 : ret_val = e1000_get_phy_id(hw);
674 : : }
675 : :
676 : : /* restore previous sfp cage power state */
677 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
678 : :
679 : 0 : out:
680 : 0 : return ret_val;
681 : : }
682 : :
683 : : /**
684 : : * e1000_phy_hw_reset_sgmii_82575 - Performs a PHY reset
685 : : * @hw: pointer to the HW structure
686 : : *
687 : : * Resets the PHY using the serial gigabit media independent interface.
688 : : **/
689 : 0 : STATIC s32 e1000_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
690 : : {
691 : : s32 ret_val = E1000_SUCCESS;
692 : : struct e1000_phy_info *phy = &hw->phy;
693 : :
694 : 0 : DEBUGFUNC("e1000_phy_hw_reset_sgmii_82575");
695 : :
696 : : /*
697 : : * This isn't a true "hard" reset, but is the only reset
698 : : * available to us at this time.
699 : : */
700 : :
701 : 0 : DEBUGOUT("Soft resetting SGMII attached PHY...\n");
702 : :
703 [ # # ]: 0 : if (!(hw->phy.ops.write_reg))
704 : 0 : goto out;
705 : :
706 : : /*
707 : : * SFP documentation requires the following to configure the SPF module
708 : : * to work on SGMII. No further documentation is given.
709 : : */
710 : 0 : ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
711 [ # # ]: 0 : if (ret_val)
712 : 0 : goto out;
713 : :
714 : 0 : ret_val = hw->phy.ops.commit(hw);
715 [ # # ]: 0 : if (ret_val)
716 : 0 : goto out;
717 : :
718 [ # # ]: 0 : if (phy->id == M88E1512_E_PHY_ID)
719 : 0 : ret_val = e1000_initialize_M88E1512_phy(hw);
720 : 0 : out:
721 : 0 : return ret_val;
722 : : }
723 : :
724 : : /**
725 : : * e1000_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
726 : : * @hw: pointer to the HW structure
727 : : * @active: true to enable LPLU, false to disable
728 : : *
729 : : * Sets the LPLU D0 state according to the active flag. When
730 : : * activating LPLU this function also disables smart speed
731 : : * and vice versa. LPLU will not be activated unless the
732 : : * device autonegotiation advertisement meets standards of
733 : : * either 10 or 10/100 or 10/100/1000 at all duplexes.
734 : : * This is a function pointer entry point only called by
735 : : * PHY setup routines.
736 : : **/
737 : 0 : STATIC s32 e1000_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
738 : : {
739 : : struct e1000_phy_info *phy = &hw->phy;
740 : : s32 ret_val = E1000_SUCCESS;
741 : : u16 data;
742 : :
743 : 0 : DEBUGFUNC("e1000_set_d0_lplu_state_82575");
744 : :
745 [ # # ]: 0 : if (!(hw->phy.ops.read_reg))
746 : 0 : goto out;
747 : :
748 : 0 : ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
749 [ # # ]: 0 : if (ret_val)
750 : 0 : goto out;
751 : :
752 [ # # ]: 0 : if (active) {
753 : 0 : data |= IGP02E1000_PM_D0_LPLU;
754 : 0 : ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
755 : : data);
756 [ # # ]: 0 : if (ret_val)
757 : 0 : goto out;
758 : :
759 : : /* When LPLU is enabled, we should disable SmartSpeed */
760 : 0 : ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
761 : : &data);
762 : 0 : data &= ~IGP01E1000_PSCFR_SMART_SPEED;
763 : 0 : ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
764 : : data);
765 [ # # ]: 0 : if (ret_val)
766 : 0 : goto out;
767 : : } else {
768 : 0 : data &= ~IGP02E1000_PM_D0_LPLU;
769 : 0 : ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
770 : : data);
771 : : /*
772 : : * LPLU and SmartSpeed are mutually exclusive. LPLU is used
773 : : * during Dx states where the power conservation is most
774 : : * important. During driver activity we should enable
775 : : * SmartSpeed, so performance is maintained.
776 : : */
777 [ # # ]: 0 : if (phy->smart_speed == e1000_smart_speed_on) {
778 : 0 : ret_val = phy->ops.read_reg(hw,
779 : : IGP01E1000_PHY_PORT_CONFIG,
780 : : &data);
781 [ # # ]: 0 : if (ret_val)
782 : 0 : goto out;
783 : :
784 : 0 : data |= IGP01E1000_PSCFR_SMART_SPEED;
785 : 0 : ret_val = phy->ops.write_reg(hw,
786 : : IGP01E1000_PHY_PORT_CONFIG,
787 : : data);
788 [ # # ]: 0 : if (ret_val)
789 : 0 : goto out;
790 [ # # ]: 0 : } else if (phy->smart_speed == e1000_smart_speed_off) {
791 : 0 : ret_val = phy->ops.read_reg(hw,
792 : : IGP01E1000_PHY_PORT_CONFIG,
793 : : &data);
794 [ # # ]: 0 : if (ret_val)
795 : 0 : goto out;
796 : :
797 : 0 : data &= ~IGP01E1000_PSCFR_SMART_SPEED;
798 : 0 : ret_val = phy->ops.write_reg(hw,
799 : : IGP01E1000_PHY_PORT_CONFIG,
800 : : data);
801 [ # # ]: 0 : if (ret_val)
802 : 0 : goto out;
803 : : }
804 : : }
805 : :
806 : 0 : out:
807 : 0 : return ret_val;
808 : : }
809 : :
810 : : /**
811 : : * e1000_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
812 : : * @hw: pointer to the HW structure
813 : : * @active: true to enable LPLU, false to disable
814 : : *
815 : : * Sets the LPLU D0 state according to the active flag. When
816 : : * activating LPLU this function also disables smart speed
817 : : * and vice versa. LPLU will not be activated unless the
818 : : * device autonegotiation advertisement meets standards of
819 : : * either 10 or 10/100 or 10/100/1000 at all duplexes.
820 : : * This is a function pointer entry point only called by
821 : : * PHY setup routines.
822 : : **/
823 : 0 : STATIC s32 e1000_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
824 : : {
825 : : struct e1000_phy_info *phy = &hw->phy;
826 : : u32 data;
827 : :
828 : 0 : DEBUGFUNC("e1000_set_d0_lplu_state_82580");
829 : :
830 : 0 : data = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
831 : :
832 [ # # ]: 0 : if (active) {
833 : : data |= E1000_82580_PM_D0_LPLU;
834 : :
835 : : /* When LPLU is enabled, we should disable SmartSpeed */
836 : 0 : data &= ~E1000_82580_PM_SPD;
837 : : } else {
838 : 0 : data &= ~E1000_82580_PM_D0_LPLU;
839 : :
840 : : /*
841 : : * LPLU and SmartSpeed are mutually exclusive. LPLU is used
842 : : * during Dx states where the power conservation is most
843 : : * important. During driver activity we should enable
844 : : * SmartSpeed, so performance is maintained.
845 : : */
846 [ # # ]: 0 : if (phy->smart_speed == e1000_smart_speed_on)
847 : 0 : data |= E1000_82580_PM_SPD;
848 [ # # ]: 0 : else if (phy->smart_speed == e1000_smart_speed_off)
849 : 0 : data &= ~E1000_82580_PM_SPD;
850 : : }
851 : :
852 : 0 : E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, data);
853 : 0 : return E1000_SUCCESS;
854 : : }
855 : :
856 : : /**
857 : : * e1000_set_d3_lplu_state_82580 - Sets low power link up state for D3
858 : : * @hw: pointer to the HW structure
859 : : * @active: boolean used to enable/disable lplu
860 : : *
861 : : * Success returns 0, Failure returns 1
862 : : *
863 : : * The low power link up (lplu) state is set to the power management level D3
864 : : * and SmartSpeed is disabled when active is true, else clear lplu for D3
865 : : * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
866 : : * is used during Dx states where the power conservation is most important.
867 : : * During driver activity, SmartSpeed should be enabled so performance is
868 : : * maintained.
869 : : **/
870 : 0 : s32 e1000_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
871 : : {
872 : : struct e1000_phy_info *phy = &hw->phy;
873 : : u32 data;
874 : :
875 : 0 : DEBUGFUNC("e1000_set_d3_lplu_state_82580");
876 : :
877 : 0 : data = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
878 : :
879 [ # # ]: 0 : if (!active) {
880 : 0 : data &= ~E1000_82580_PM_D3_LPLU;
881 : : /*
882 : : * LPLU and SmartSpeed are mutually exclusive. LPLU is used
883 : : * during Dx states where the power conservation is most
884 : : * important. During driver activity we should enable
885 : : * SmartSpeed, so performance is maintained.
886 : : */
887 [ # # ]: 0 : if (phy->smart_speed == e1000_smart_speed_on)
888 : 0 : data |= E1000_82580_PM_SPD;
889 [ # # ]: 0 : else if (phy->smart_speed == e1000_smart_speed_off)
890 : 0 : data &= ~E1000_82580_PM_SPD;
891 [ # # ]: 0 : } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
892 [ # # ]: 0 : (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
893 : : (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
894 : : data |= E1000_82580_PM_D3_LPLU;
895 : : /* When LPLU is enabled, we should disable SmartSpeed */
896 : 0 : data &= ~E1000_82580_PM_SPD;
897 : : }
898 : :
899 : 0 : E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, data);
900 : 0 : return E1000_SUCCESS;
901 : : }
902 : :
903 : : /**
904 : : * e1000_acquire_nvm_82575 - Request for access to EEPROM
905 : : * @hw: pointer to the HW structure
906 : : *
907 : : * Acquire the necessary semaphores for exclusive access to the EEPROM.
908 : : * Set the EEPROM access request bit and wait for EEPROM access grant bit.
909 : : * Return successful if access grant bit set, else clear the request for
910 : : * EEPROM access and return -E1000_ERR_NVM (-1).
911 : : **/
912 : 0 : STATIC s32 e1000_acquire_nvm_82575(struct e1000_hw *hw)
913 : : {
914 : : s32 ret_val = E1000_SUCCESS;
915 : :
916 : 0 : DEBUGFUNC("e1000_acquire_nvm_82575");
917 : :
918 : 0 : ret_val = e1000_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
919 [ # # ]: 0 : if (ret_val)
920 : 0 : goto out;
921 : :
922 : : /*
923 : : * Check if there is some access
924 : : * error this access may hook on
925 : : */
926 [ # # ]: 0 : if (hw->mac.type == e1000_i350) {
927 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
928 [ # # ]: 0 : if (eecd & (E1000_EECD_BLOCKED | E1000_EECD_ABORT |
929 : : E1000_EECD_TIMEOUT)) {
930 : : /* Clear all access error flags */
931 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd |
932 : : E1000_EECD_ERROR_CLR);
933 : 0 : DEBUGOUT("Nvm bit banging access error detected and cleared.\n");
934 : : }
935 : : }
936 : :
937 [ # # ]: 0 : if (hw->mac.type == e1000_82580) {
938 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
939 [ # # ]: 0 : if (eecd & E1000_EECD_BLOCKED) {
940 : : /* Clear access error flag */
941 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd |
942 : : E1000_EECD_BLOCKED);
943 : 0 : DEBUGOUT("Nvm bit banging access error detected and cleared.\n");
944 : : }
945 : : }
946 : :
947 : 0 : ret_val = e1000_acquire_nvm_generic(hw);
948 [ # # ]: 0 : if (ret_val)
949 : 0 : e1000_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
950 : :
951 : 0 : out:
952 : 0 : return ret_val;
953 : : }
954 : :
955 : : /**
956 : : * e1000_release_nvm_82575 - Release exclusive access to EEPROM
957 : : * @hw: pointer to the HW structure
958 : : *
959 : : * Stop any current commands to the EEPROM and clear the EEPROM request bit,
960 : : * then release the semaphores acquired.
961 : : **/
962 : 0 : STATIC void e1000_release_nvm_82575(struct e1000_hw *hw)
963 : : {
964 : 0 : DEBUGFUNC("e1000_release_nvm_82575");
965 : :
966 : 0 : e1000_release_nvm_generic(hw);
967 : :
968 : 0 : e1000_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
969 : 0 : }
970 : :
971 : : /**
972 : : * e1000_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
973 : : * @hw: pointer to the HW structure
974 : : * @mask: specifies which semaphore to acquire
975 : : *
976 : : * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
977 : : * will also specify which port we're acquiring the lock for.
978 : : **/
979 : 0 : STATIC s32 e1000_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
980 : : {
981 : : u32 swfw_sync;
982 : 0 : u32 swmask = mask;
983 : 0 : u32 fwmask = mask << 16;
984 : : s32 ret_val = E1000_SUCCESS;
985 : : s32 i = 0, timeout = 200;
986 : :
987 : 0 : DEBUGFUNC("e1000_acquire_swfw_sync_82575");
988 : :
989 [ # # ]: 0 : while (i < timeout) {
990 [ # # ]: 0 : if (e1000_get_hw_semaphore_generic(hw)) {
991 : : ret_val = -E1000_ERR_SWFW_SYNC;
992 : 0 : goto out;
993 : : }
994 : :
995 : 0 : swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
996 [ # # ]: 0 : if (!(swfw_sync & (fwmask | swmask)))
997 : : break;
998 : :
999 : : /*
1000 : : * Firmware currently using resource (fwmask)
1001 : : * or other software thread using resource (swmask)
1002 : : */
1003 : 0 : e1000_put_hw_semaphore_generic(hw);
1004 : 0 : msec_delay_irq(5);
1005 : 0 : i++;
1006 : : }
1007 : :
1008 [ # # ]: 0 : if (i == timeout) {
1009 : 0 : DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1010 : : ret_val = -E1000_ERR_SWFW_SYNC;
1011 : 0 : goto out;
1012 : : }
1013 : :
1014 : 0 : swfw_sync |= swmask;
1015 : 0 : E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
1016 : :
1017 : 0 : e1000_put_hw_semaphore_generic(hw);
1018 : :
1019 : 0 : out:
1020 : 0 : return ret_val;
1021 : : }
1022 : :
1023 : : /**
1024 : : * e1000_release_swfw_sync_82575 - Release SW/FW semaphore
1025 : : * @hw: pointer to the HW structure
1026 : : * @mask: specifies which semaphore to acquire
1027 : : *
1028 : : * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1029 : : * will also specify which port we're releasing the lock for.
1030 : : **/
1031 : 0 : STATIC void e1000_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1032 : : {
1033 : : u32 swfw_sync;
1034 : :
1035 : 0 : DEBUGFUNC("e1000_release_swfw_sync_82575");
1036 : :
1037 [ # # ]: 0 : while (e1000_get_hw_semaphore_generic(hw) != E1000_SUCCESS)
1038 : : ; /* Empty */
1039 : :
1040 : 0 : swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
1041 : 0 : swfw_sync &= (u32)~mask;
1042 : 0 : E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
1043 : :
1044 : 0 : e1000_put_hw_semaphore_generic(hw);
1045 : 0 : }
1046 : :
1047 : : /**
1048 : : * e1000_get_cfg_done_82575 - Read config done bit
1049 : : * @hw: pointer to the HW structure
1050 : : *
1051 : : * Read the management control register for the config done bit for
1052 : : * completion status. NOTE: silicon which is EEPROM-less will fail trying
1053 : : * to read the config done bit, so an error is *ONLY* logged and returns
1054 : : * E1000_SUCCESS. If we were to return with error, EEPROM-less silicon
1055 : : * would not be able to be reset or change link.
1056 : : **/
1057 : 0 : STATIC s32 e1000_get_cfg_done_82575(struct e1000_hw *hw)
1058 : : {
1059 : : s32 timeout = PHY_CFG_TIMEOUT;
1060 : : u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1061 : :
1062 : 0 : DEBUGFUNC("e1000_get_cfg_done_82575");
1063 : :
1064 [ # # ]: 0 : if (hw->bus.func == E1000_FUNC_1)
1065 : : mask = E1000_NVM_CFG_DONE_PORT_1;
1066 [ # # ]: 0 : else if (hw->bus.func == E1000_FUNC_2)
1067 : : mask = E1000_NVM_CFG_DONE_PORT_2;
1068 [ # # ]: 0 : else if (hw->bus.func == E1000_FUNC_3)
1069 : : mask = E1000_NVM_CFG_DONE_PORT_3;
1070 [ # # ]: 0 : while (timeout) {
1071 [ # # ]: 0 : if (E1000_READ_REG(hw, E1000_EEMNGCTL) & mask)
1072 : : break;
1073 : 0 : msec_delay(1);
1074 : 0 : timeout--;
1075 : : }
1076 [ # # ]: 0 : if (!timeout)
1077 : 0 : DEBUGOUT("MNG configuration cycle has not completed.\n");
1078 : :
1079 : : /* If EEPROM is not marked present, init the PHY manually */
1080 [ # # ]: 0 : if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) &&
1081 [ # # ]: 0 : (hw->phy.type == e1000_phy_igp_3))
1082 : 0 : e1000_phy_init_script_igp3(hw);
1083 : :
1084 : 0 : return E1000_SUCCESS;
1085 : : }
1086 : :
1087 : : /**
1088 : : * e1000_get_link_up_info_82575 - Get link speed/duplex info
1089 : : * @hw: pointer to the HW structure
1090 : : * @speed: stores the current speed
1091 : : * @duplex: stores the current duplex
1092 : : *
1093 : : * This is a wrapper function, if using the serial gigabit media independent
1094 : : * interface, use PCS to retrieve the link speed and duplex information.
1095 : : * Otherwise, use the generic function to get the link speed and duplex info.
1096 : : **/
1097 : 0 : STATIC s32 e1000_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1098 : : u16 *duplex)
1099 : : {
1100 : : s32 ret_val;
1101 : :
1102 : 0 : DEBUGFUNC("e1000_get_link_up_info_82575");
1103 : :
1104 [ # # ]: 0 : if (hw->phy.media_type != e1000_media_type_copper)
1105 : 0 : ret_val = e1000_get_pcs_speed_and_duplex_82575(hw, speed,
1106 : : duplex);
1107 : : else
1108 : 0 : ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed,
1109 : : duplex);
1110 : :
1111 : 0 : return ret_val;
1112 : : }
1113 : :
1114 : : /**
1115 : : * e1000_check_for_link_82575 - Check for link
1116 : : * @hw: pointer to the HW structure
1117 : : *
1118 : : * If sgmii is enabled, then use the pcs register to determine link, otherwise
1119 : : * use the generic interface for determining link.
1120 : : **/
1121 : 0 : STATIC s32 e1000_check_for_link_82575(struct e1000_hw *hw)
1122 : : {
1123 : : s32 ret_val;
1124 : : u16 speed, duplex;
1125 : :
1126 : 0 : DEBUGFUNC("e1000_check_for_link_82575");
1127 : :
1128 [ # # ]: 0 : if (hw->phy.media_type != e1000_media_type_copper) {
1129 : 0 : ret_val = e1000_get_pcs_speed_and_duplex_82575(hw, &speed,
1130 : : &duplex);
1131 : : /*
1132 : : * Use this flag to determine if link needs to be checked or
1133 : : * not. If we have link clear the flag so that we do not
1134 : : * continue to check for link.
1135 : : */
1136 : 0 : hw->mac.get_link_status = !hw->mac.serdes_has_link;
1137 : :
1138 : : /*
1139 : : * Configure Flow Control now that Auto-Neg has completed.
1140 : : * First, we need to restore the desired flow control
1141 : : * settings because we may have had to re-autoneg with a
1142 : : * different link partner.
1143 : : */
1144 : 0 : ret_val = e1000_config_fc_after_link_up_generic(hw);
1145 [ # # ]: 0 : if (ret_val)
1146 : 0 : DEBUGOUT("Error configuring flow control\n");
1147 : : } else {
1148 : 0 : ret_val = e1000_check_for_copper_link_generic(hw);
1149 : : }
1150 : :
1151 : 0 : return ret_val;
1152 : : }
1153 : :
1154 : : /**
1155 : : * e1000_check_for_link_media_swap - Check which M88E1112 interface linked
1156 : : * @hw: pointer to the HW structure
1157 : : *
1158 : : * Poll the M88E1112 interfaces to see which interface achieved link.
1159 : : */
1160 : 0 : STATIC s32 e1000_check_for_link_media_swap(struct e1000_hw *hw)
1161 : : {
1162 : : struct e1000_phy_info *phy = &hw->phy;
1163 : : s32 ret_val;
1164 : : u16 data;
1165 : : u8 port = 0;
1166 : :
1167 : 0 : DEBUGFUNC("e1000_check_for_link_media_swap");
1168 : :
1169 : : /* Check for copper. */
1170 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1171 [ # # ]: 0 : if (ret_val)
1172 : : return ret_val;
1173 : :
1174 : 0 : ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1175 [ # # ]: 0 : if (ret_val)
1176 : : return ret_val;
1177 : :
1178 [ # # ]: 0 : if (data & E1000_M88E1112_STATUS_LINK)
1179 : : port = E1000_MEDIA_PORT_COPPER;
1180 : :
1181 : : /* Check for other. */
1182 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
1183 [ # # ]: 0 : if (ret_val)
1184 : : return ret_val;
1185 : :
1186 : 0 : ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1187 [ # # ]: 0 : if (ret_val)
1188 : : return ret_val;
1189 : :
1190 [ # # ]: 0 : if (data & E1000_M88E1112_STATUS_LINK)
1191 : : port = E1000_MEDIA_PORT_OTHER;
1192 : :
1193 : : /* Determine if a swap needs to happen. */
1194 [ # # # # ]: 0 : if (port && (hw->dev_spec._82575.media_port != port)) {
1195 : 0 : hw->dev_spec._82575.media_port = port;
1196 : 0 : hw->dev_spec._82575.media_changed = true;
1197 : : }
1198 : :
1199 [ # # ]: 0 : if (port == E1000_MEDIA_PORT_COPPER) {
1200 : : /* reset page to 0 */
1201 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1202 [ # # ]: 0 : if (ret_val)
1203 : : return ret_val;
1204 : 0 : e1000_check_for_link_82575(hw);
1205 : : } else {
1206 : 0 : e1000_check_for_link_82575(hw);
1207 : : /* reset page to 0 */
1208 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1209 [ # # ]: 0 : if (ret_val)
1210 : 0 : return ret_val;
1211 : : }
1212 : :
1213 : : return E1000_SUCCESS;
1214 : : }
1215 : :
1216 : : /**
1217 : : * e1000_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1218 : : * @hw: pointer to the HW structure
1219 : : **/
1220 : 0 : STATIC void e1000_power_up_serdes_link_82575(struct e1000_hw *hw)
1221 : : {
1222 : : u32 reg;
1223 : :
1224 : 0 : DEBUGFUNC("e1000_power_up_serdes_link_82575");
1225 : :
1226 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1227 : : !e1000_sgmii_active_82575(hw))
1228 : : return;
1229 : :
1230 : : /* Enable PCS to turn on link */
1231 : 0 : reg = E1000_READ_REG(hw, E1000_PCS_CFG0);
1232 : 0 : reg |= E1000_PCS_CFG_PCS_EN;
1233 : 0 : E1000_WRITE_REG(hw, E1000_PCS_CFG0, reg);
1234 : :
1235 : : /* Power up the laser */
1236 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1237 : 0 : reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1238 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1239 : :
1240 : : /* flush the write to verify completion */
1241 : 0 : E1000_WRITE_FLUSH(hw);
1242 : 0 : msec_delay(1);
1243 : : }
1244 : :
1245 : : /**
1246 : : * e1000_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
1247 : : * @hw: pointer to the HW structure
1248 : : * @speed: stores the current speed
1249 : : * @duplex: stores the current duplex
1250 : : *
1251 : : * Using the physical coding sub-layer (PCS), retrieve the current speed and
1252 : : * duplex, then store the values in the pointers provided.
1253 : : **/
1254 : 0 : STATIC s32 e1000_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw,
1255 : : u16 *speed, u16 *duplex)
1256 : : {
1257 : : struct e1000_mac_info *mac = &hw->mac;
1258 : : u32 pcs;
1259 : : u32 status;
1260 : :
1261 : 0 : DEBUGFUNC("e1000_get_pcs_speed_and_duplex_82575");
1262 : :
1263 : : /*
1264 : : * Read the PCS Status register for link state. For non-copper mode,
1265 : : * the status register is not accurate. The PCS status register is
1266 : : * used instead.
1267 : : */
1268 : 0 : pcs = E1000_READ_REG(hw, E1000_PCS_LSTAT);
1269 : :
1270 : : /*
1271 : : * The link up bit determines when link is up on autoneg.
1272 : : */
1273 [ # # ]: 0 : if (pcs & E1000_PCS_LSTS_LINK_OK) {
1274 : 0 : mac->serdes_has_link = true;
1275 : :
1276 : : /* Detect and store PCS speed */
1277 [ # # ]: 0 : if (pcs & E1000_PCS_LSTS_SPEED_1000)
1278 : 0 : *speed = SPEED_1000;
1279 [ # # ]: 0 : else if (pcs & E1000_PCS_LSTS_SPEED_100)
1280 : 0 : *speed = SPEED_100;
1281 : : else
1282 : 0 : *speed = SPEED_10;
1283 : :
1284 : : /* Detect and store PCS duplex */
1285 [ # # ]: 0 : if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
1286 : 0 : *duplex = FULL_DUPLEX;
1287 : : else
1288 : 0 : *duplex = HALF_DUPLEX;
1289 : :
1290 : : /* Check if it is an I354 2.5Gb backplane connection. */
1291 [ # # ]: 0 : if (mac->type == e1000_i354) {
1292 : 0 : status = E1000_READ_REG(hw, E1000_STATUS);
1293 [ # # ]: 0 : if ((status & E1000_STATUS_2P5_SKU) &&
1294 : : !(status & E1000_STATUS_2P5_SKU_OVER)) {
1295 : 0 : *speed = SPEED_2500;
1296 : 0 : *duplex = FULL_DUPLEX;
1297 : 0 : DEBUGOUT("2500 Mbs, ");
1298 : 0 : DEBUGOUT("Full Duplex\n");
1299 : : }
1300 : : }
1301 : :
1302 : : } else {
1303 : 0 : mac->serdes_has_link = false;
1304 : 0 : *speed = 0;
1305 : 0 : *duplex = 0;
1306 : : }
1307 : :
1308 : 0 : return E1000_SUCCESS;
1309 : : }
1310 : :
1311 : : /**
1312 : : * e1000_shutdown_serdes_link_82575 - Remove link during power down
1313 : : * @hw: pointer to the HW structure
1314 : : *
1315 : : * In the case of serdes shut down sfp and PCS on driver unload
1316 : : * when management pass thru is not enabled.
1317 : : **/
1318 : 0 : void e1000_shutdown_serdes_link_82575(struct e1000_hw *hw)
1319 : : {
1320 : : u32 reg;
1321 : :
1322 : 0 : DEBUGFUNC("e1000_shutdown_serdes_link_82575");
1323 : :
1324 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1325 : : !e1000_sgmii_active_82575(hw))
1326 : : return;
1327 : :
1328 [ # # ]: 0 : if (!e1000_enable_mng_pass_thru(hw)) {
1329 : : /* Disable PCS to turn off link */
1330 : 0 : reg = E1000_READ_REG(hw, E1000_PCS_CFG0);
1331 : 0 : reg &= ~E1000_PCS_CFG_PCS_EN;
1332 : 0 : E1000_WRITE_REG(hw, E1000_PCS_CFG0, reg);
1333 : :
1334 : : /* shutdown the laser */
1335 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1336 : 0 : reg |= E1000_CTRL_EXT_SDP3_DATA;
1337 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1338 : :
1339 : : /* flush the write to verify completion */
1340 : 0 : E1000_WRITE_FLUSH(hw);
1341 : 0 : msec_delay(1);
1342 : : }
1343 : :
1344 : : return;
1345 : : }
1346 : :
1347 : : /**
1348 : : * e1000_reset_hw_82575 - Reset hardware
1349 : : * @hw: pointer to the HW structure
1350 : : *
1351 : : * This resets the hardware into a known state.
1352 : : **/
1353 : 0 : STATIC s32 e1000_reset_hw_82575(struct e1000_hw *hw)
1354 : : {
1355 : : u32 ctrl;
1356 : : s32 ret_val;
1357 : :
1358 : 0 : DEBUGFUNC("e1000_reset_hw_82575");
1359 : :
1360 : : /*
1361 : : * Prevent the PCI-E bus from sticking if there is no TLP connection
1362 : : * on the last TLP read/write transaction when MAC is reset.
1363 : : */
1364 : 0 : ret_val = e1000_disable_pcie_master_generic(hw);
1365 [ # # ]: 0 : if (ret_val)
1366 : 0 : DEBUGOUT("PCI-E Master disable polling has failed.\n");
1367 : :
1368 : : /* set the completion timeout for interface */
1369 : 0 : ret_val = e1000_set_pcie_completion_timeout(hw);
1370 [ # # ]: 0 : if (ret_val)
1371 : 0 : DEBUGOUT("PCI-E Set completion timeout has failed.\n");
1372 : :
1373 : 0 : DEBUGOUT("Masking off all interrupts\n");
1374 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1375 : :
1376 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, 0);
1377 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
1378 : 0 : E1000_WRITE_FLUSH(hw);
1379 : :
1380 : 0 : msec_delay(10);
1381 : :
1382 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
1383 : :
1384 : 0 : DEBUGOUT("Issuing a global reset to MAC\n");
1385 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
1386 : :
1387 : 0 : ret_val = e1000_get_auto_rd_done_generic(hw);
1388 [ # # ]: 0 : if (ret_val) {
1389 : : /*
1390 : : * When auto config read does not complete, do not
1391 : : * return with an error. This can happen in situations
1392 : : * where there is no eeprom and prevents getting link.
1393 : : */
1394 : 0 : DEBUGOUT("Auto Read Done did not complete\n");
1395 : : }
1396 : :
1397 : : /* If EEPROM is not present, run manual init scripts */
1398 [ # # ]: 0 : if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES))
1399 : 0 : e1000_reset_init_script_82575(hw);
1400 : :
1401 : : /* Clear any pending interrupt events. */
1402 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1403 : 0 : E1000_READ_REG(hw, E1000_ICR);
1404 : :
1405 : : /* Install any alternate MAC address into RAR0 */
1406 : 0 : ret_val = e1000_check_alt_mac_addr_generic(hw);
1407 : :
1408 : 0 : return ret_val;
1409 : : }
1410 : :
1411 : : /**
1412 : : * e1000_init_hw_82575 - Initialize hardware
1413 : : * @hw: pointer to the HW structure
1414 : : *
1415 : : * This inits the hardware readying it for operation.
1416 : : **/
1417 : 0 : STATIC s32 e1000_init_hw_82575(struct e1000_hw *hw)
1418 : : {
1419 : : struct e1000_mac_info *mac = &hw->mac;
1420 : : s32 ret_val;
1421 : :
1422 : 0 : DEBUGFUNC("e1000_init_hw_82575");
1423 : :
1424 : : /* Initialize identification LED */
1425 : 0 : ret_val = mac->ops.id_led_init(hw);
1426 [ # # ]: 0 : if (ret_val) {
1427 : 0 : DEBUGOUT("Error initializing identification LED\n");
1428 : : /* This is not fatal and we should not stop init due to this */
1429 : : }
1430 : :
1431 : : /* Disabling VLAN filtering */
1432 : 0 : DEBUGOUT("Initializing the IEEE VLAN\n");
1433 : 0 : mac->ops.clear_vfta(hw);
1434 : :
1435 : 0 : ret_val = e1000_init_hw_base(hw);
1436 : :
1437 : : /* Set the default MTU size */
1438 : 0 : hw->dev_spec._82575.mtu = 1500;
1439 : :
1440 : : /* Clear all of the statistics registers (clear on read). It is
1441 : : * important that we do this after we have tried to establish link
1442 : : * because the symbol error count will increment wildly if there
1443 : : * is no link.
1444 : : */
1445 : 0 : e1000_clear_hw_cntrs_82575(hw);
1446 : :
1447 : 0 : return ret_val;
1448 : : }
1449 : : /**
1450 : : * e1000_setup_copper_link_82575 - Configure copper link settings
1451 : : * @hw: pointer to the HW structure
1452 : : *
1453 : : * Configures the link for auto-neg or forced speed and duplex. Then we check
1454 : : * for link, once link is established calls to configure collision distance
1455 : : * and flow control are called.
1456 : : **/
1457 : 0 : STATIC s32 e1000_setup_copper_link_82575(struct e1000_hw *hw)
1458 : : {
1459 : : u32 phpm_reg;
1460 : : s32 ret_val;
1461 : : u32 ctrl;
1462 : :
1463 : 0 : DEBUGFUNC("e1000_setup_copper_link_82575");
1464 : :
1465 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
1466 : : ctrl |= E1000_CTRL_SLU;
1467 : 0 : ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1468 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1469 : :
1470 : : /* Clear Go Link Disconnect bit on supported devices */
1471 [ # # ]: 0 : switch (hw->mac.type) {
1472 : 0 : case e1000_82580:
1473 : : case e1000_i350:
1474 : : case e1000_i210:
1475 : : case e1000_i211:
1476 : 0 : phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1477 : 0 : phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1478 : 0 : E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1479 : : break;
1480 : : default:
1481 : : break;
1482 : : }
1483 : :
1484 : 0 : ret_val = e1000_setup_serdes_link_82575(hw);
1485 [ # # ]: 0 : if (ret_val)
1486 : 0 : goto out;
1487 : :
1488 : 0 : if (e1000_sgmii_active_82575(hw)) {
1489 : : /* allow time for SFP cage time to power up phy */
1490 : 0 : msec_delay(300);
1491 : :
1492 : 0 : ret_val = hw->phy.ops.reset(hw);
1493 [ # # ]: 0 : if (ret_val) {
1494 : 0 : DEBUGOUT("Error resetting the PHY.\n");
1495 : 0 : goto out;
1496 : : }
1497 : : }
1498 [ # # # # ]: 0 : switch (hw->phy.type) {
1499 : 0 : case e1000_phy_i210:
1500 : : /* Fall through */
1501 : : case e1000_phy_m88:
1502 [ # # ]: 0 : switch (hw->phy.id) {
1503 : 0 : case I347AT4_E_PHY_ID:
1504 : : /* Fall through */
1505 : : case M88E1112_E_PHY_ID:
1506 : : /* Fall through */
1507 : : case M88E1340M_E_PHY_ID:
1508 : : /* Fall through */
1509 : : case M88E1543_E_PHY_ID:
1510 : : /* Fall through */
1511 : : case M88E1512_E_PHY_ID:
1512 : : /* Fall through */
1513 : : case I210_I_PHY_ID:
1514 : : /* Fall through */
1515 : 0 : ret_val = e1000_copper_link_setup_m88_gen2(hw);
1516 : 0 : break;
1517 : 0 : default:
1518 : 0 : ret_val = e1000_copper_link_setup_m88(hw);
1519 : 0 : break;
1520 : : }
1521 : : break;
1522 : 0 : case e1000_phy_igp_3:
1523 : 0 : ret_val = e1000_copper_link_setup_igp(hw);
1524 : 0 : break;
1525 : 0 : case e1000_phy_82580:
1526 : 0 : ret_val = e1000_copper_link_setup_82577(hw);
1527 : 0 : break;
1528 : : default:
1529 : : ret_val = -E1000_ERR_PHY;
1530 : : break;
1531 : : }
1532 : :
1533 [ # # ]: 0 : if (ret_val)
1534 : 0 : goto out;
1535 : :
1536 : 0 : ret_val = e1000_setup_copper_link_generic(hw);
1537 : 0 : out:
1538 : 0 : return ret_val;
1539 : : }
1540 : :
1541 : : /**
1542 : : * e1000_setup_serdes_link_82575 - Setup link for serdes
1543 : : * @hw: pointer to the HW structure
1544 : : *
1545 : : * Configure the physical coding sub-layer (PCS) link. The PCS link is
1546 : : * used on copper connections where the serialized gigabit media independent
1547 : : * interface (sgmii), or serdes fiber is being used. Configures the link
1548 : : * for auto-negotiation or forces speed/duplex.
1549 : : **/
1550 : 0 : STATIC s32 e1000_setup_serdes_link_82575(struct e1000_hw *hw)
1551 : : {
1552 : : u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
1553 : : bool pcs_autoneg;
1554 : : s32 ret_val = E1000_SUCCESS;
1555 : : u16 data;
1556 : :
1557 : 0 : DEBUGFUNC("e1000_setup_serdes_link_82575");
1558 : :
1559 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1560 : : !e1000_sgmii_active_82575(hw))
1561 : : return ret_val;
1562 : :
1563 : : /*
1564 : : * On the 82575, SerDes loopback mode persists until it is
1565 : : * explicitly turned off or a power cycle is performed. A read to
1566 : : * the register does not indicate its status. Therefore, we ensure
1567 : : * loopback mode is disabled during initialization.
1568 : : */
1569 : 0 : E1000_WRITE_REG(hw, E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1570 : :
1571 : : /* power on the sfp cage if present */
1572 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1573 : 0 : ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1574 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1575 : :
1576 : 0 : ctrl_reg = E1000_READ_REG(hw, E1000_CTRL);
1577 : 0 : ctrl_reg |= E1000_CTRL_SLU;
1578 : :
1579 : : /* set both sw defined pins on 82575/82576*/
1580 [ # # ]: 0 : if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576)
1581 : 0 : ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1582 : :
1583 : 0 : reg = E1000_READ_REG(hw, E1000_PCS_LCTL);
1584 : :
1585 : : /* default pcs_autoneg to the same setting as mac autoneg */
1586 : 0 : pcs_autoneg = hw->mac.autoneg;
1587 : :
1588 [ # # # ]: 0 : switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1589 : 0 : case E1000_CTRL_EXT_LINK_MODE_SGMII:
1590 : : /* sgmii mode lets the phy handle forcing speed/duplex */
1591 : : pcs_autoneg = true;
1592 : : /* autoneg time out should be disabled for SGMII mode */
1593 : 0 : reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1594 : 0 : break;
1595 : 0 : case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1596 : : /* disable PCS autoneg and support parallel detect only */
1597 : : pcs_autoneg = false;
1598 : : /* Fall through */
1599 : 0 : default:
1600 [ # # ]: 0 : if (hw->mac.type == e1000_82575 ||
1601 : : hw->mac.type == e1000_82576) {
1602 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1603 [ # # ]: 0 : if (ret_val) {
1604 : 0 : DEBUGOUT("NVM Read Error\n");
1605 : 0 : return ret_val;
1606 : : }
1607 : :
1608 [ # # ]: 0 : if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1609 : : pcs_autoneg = false;
1610 : : }
1611 : :
1612 : : /*
1613 : : * non-SGMII modes only supports a speed of 1000/Full for the
1614 : : * link so it is best to just force the MAC and let the pcs
1615 : : * link either autoneg or be forced to 1000/Full
1616 : : */
1617 : 0 : ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1618 : : E1000_CTRL_FD | E1000_CTRL_FRCDPX;
1619 : :
1620 : : /* set speed of 1000/Full if speed/duplex is forced */
1621 : 0 : reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1622 : 0 : break;
1623 : : }
1624 : :
1625 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl_reg);
1626 : :
1627 : : /*
1628 : : * New SerDes mode allows for forcing speed or autonegotiating speed
1629 : : * at 1gb. Autoneg should be default set by most drivers. This is the
1630 : : * mode that will be compatible with older link partners and switches.
1631 : : * However, both are supported by the hardware and some drivers/tools.
1632 : : */
1633 : 0 : reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1634 : : E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1635 : :
1636 [ # # ]: 0 : if (pcs_autoneg) {
1637 : : /* Set PCS register for autoneg */
1638 : : reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1639 : : E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
1640 : :
1641 : : /* Disable force flow control for autoneg */
1642 : 0 : reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1643 : :
1644 : : /* Configure flow control advertisement for autoneg */
1645 : 0 : anadv_reg = E1000_READ_REG(hw, E1000_PCS_ANADV);
1646 : 0 : anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1647 : :
1648 [ # # # ]: 0 : switch (hw->fc.requested_mode) {
1649 : 0 : case e1000_fc_full:
1650 : : case e1000_fc_rx_pause:
1651 : : anadv_reg |= E1000_TXCW_ASM_DIR;
1652 : 0 : anadv_reg |= E1000_TXCW_PAUSE;
1653 : 0 : break;
1654 : 0 : case e1000_fc_tx_pause:
1655 : 0 : anadv_reg |= E1000_TXCW_ASM_DIR;
1656 : 0 : break;
1657 : : default:
1658 : : break;
1659 : : }
1660 : :
1661 : 0 : E1000_WRITE_REG(hw, E1000_PCS_ANADV, anadv_reg);
1662 : :
1663 : 0 : DEBUGOUT1("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
1664 : : } else {
1665 : : /* Set PCS register for forced link */
1666 : : reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
1667 : :
1668 : : /* Force flow control for forced link */
1669 : 0 : reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1670 : :
1671 : 0 : DEBUGOUT1("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
1672 : : }
1673 : :
1674 : 0 : E1000_WRITE_REG(hw, E1000_PCS_LCTL, reg);
1675 : :
1676 [ # # ]: 0 : if (!pcs_autoneg && !e1000_sgmii_active_82575(hw))
1677 : 0 : e1000_force_mac_fc_generic(hw);
1678 : :
1679 : : return ret_val;
1680 : : }
1681 : :
1682 : : /**
1683 : : * e1000_get_media_type_82575 - derives current media type.
1684 : : * @hw: pointer to the HW structure
1685 : : *
1686 : : * The media type is chosen reflecting few settings.
1687 : : * The following are taken into account:
1688 : : * - link mode set in the current port Init Control Word #3
1689 : : * - current link mode settings in CSR register
1690 : : * - MDIO vs. I2C PHY control interface chosen
1691 : : * - SFP module media type
1692 : : **/
1693 : 0 : STATIC s32 e1000_get_media_type_82575(struct e1000_hw *hw)
1694 : : {
1695 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1696 : : s32 ret_val = E1000_SUCCESS;
1697 : : u32 ctrl_ext = 0;
1698 : : u32 link_mode = 0;
1699 : :
1700 : : /* Set internal phy as default */
1701 : 0 : dev_spec->sgmii_active = false;
1702 : 0 : dev_spec->module_plugged = false;
1703 : :
1704 : : /* Get CSR setting */
1705 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1706 : :
1707 : : /* extract link mode setting */
1708 : 0 : link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
1709 : :
1710 [ # # # # : 0 : switch (link_mode) {
# ]
1711 : 0 : case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1712 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1713 : 0 : break;
1714 : 0 : case E1000_CTRL_EXT_LINK_MODE_GMII:
1715 : 0 : hw->phy.media_type = e1000_media_type_copper;
1716 : 0 : break;
1717 : 0 : case E1000_CTRL_EXT_LINK_MODE_SGMII:
1718 : : /* Get phy control interface type set (MDIO vs. I2C)*/
1719 [ # # ]: 0 : if (e1000_sgmii_uses_mdio_82575(hw)) {
1720 : 0 : hw->phy.media_type = e1000_media_type_copper;
1721 : 0 : dev_spec->sgmii_active = true;
1722 : 0 : break;
1723 : : }
1724 : : /* Fall through for I2C based SGMII */
1725 : : /* Fall through */
1726 : : case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
1727 : : /* read media type from SFP EEPROM */
1728 : 0 : ret_val = e1000_set_sfp_media_type_82575(hw);
1729 [ # # ]: 0 : if ((ret_val != E1000_SUCCESS) ||
1730 [ # # ]: 0 : (hw->phy.media_type == e1000_media_type_unknown)) {
1731 : : /*
1732 : : * If media type was not identified then return media
1733 : : * type defined by the CTRL_EXT settings.
1734 : : */
1735 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1736 : :
1737 [ # # ]: 0 : if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
1738 : 0 : hw->phy.media_type = e1000_media_type_copper;
1739 : 0 : dev_spec->sgmii_active = true;
1740 : : }
1741 : :
1742 : : break;
1743 : : }
1744 : :
1745 : : /* do not change link mode for 100BaseFX */
1746 [ # # ]: 0 : if (dev_spec->eth_flags.e100_base_fx)
1747 : : break;
1748 : :
1749 : : /* change current link mode setting */
1750 : 0 : ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
1751 : :
1752 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper)
1753 : 0 : ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
1754 : : else
1755 : 0 : ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1756 : :
1757 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1758 : :
1759 : : break;
1760 : : }
1761 : :
1762 : 0 : return ret_val;
1763 : : }
1764 : :
1765 : : /**
1766 : : * e1000_set_sfp_media_type_82575 - derives SFP module media type.
1767 : : * @hw: pointer to the HW structure
1768 : : *
1769 : : * The media type is chosen based on SFP module.
1770 : : * compatibility flags retrieved from SFP ID EEPROM.
1771 : : **/
1772 : 0 : STATIC s32 e1000_set_sfp_media_type_82575(struct e1000_hw *hw)
1773 : : {
1774 : : s32 ret_val = E1000_ERR_CONFIG;
1775 : : u32 ctrl_ext = 0;
1776 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1777 : 0 : struct sfp_e1000_flags *eth_flags = &dev_spec->eth_flags;
1778 : 0 : u8 tranceiver_type = 0;
1779 : : s32 timeout = 3;
1780 : :
1781 : : /* Turn I2C interface ON and power on sfp cage */
1782 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1783 : 0 : ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1784 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
1785 : :
1786 : 0 : E1000_WRITE_FLUSH(hw);
1787 : :
1788 : : /* Read SFP module data */
1789 [ # # ]: 0 : while (timeout) {
1790 : 0 : ret_val = e1000_read_sfp_data_byte(hw,
1791 : : E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
1792 : : &tranceiver_type);
1793 [ # # ]: 0 : if (ret_val == E1000_SUCCESS)
1794 : : break;
1795 : 0 : msec_delay(100);
1796 : 0 : timeout--;
1797 : : }
1798 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
1799 : 0 : goto out;
1800 : :
1801 : 0 : ret_val = e1000_read_sfp_data_byte(hw,
1802 : : E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
1803 : : (u8 *)eth_flags);
1804 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
1805 : 0 : goto out;
1806 : :
1807 : : /* Check if there is some SFP module plugged and powered */
1808 [ # # ]: 0 : if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
1809 : : (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
1810 : 0 : dev_spec->module_plugged = true;
1811 [ # # ]: 0 : if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
1812 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1813 [ # # ]: 0 : } else if (eth_flags->e100_base_fx) {
1814 : 0 : dev_spec->sgmii_active = true;
1815 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1816 [ # # ]: 0 : } else if (eth_flags->e1000_base_t) {
1817 : 0 : dev_spec->sgmii_active = true;
1818 : 0 : hw->phy.media_type = e1000_media_type_copper;
1819 : : } else {
1820 : 0 : hw->phy.media_type = e1000_media_type_unknown;
1821 : 0 : DEBUGOUT("PHY module has not been recognized\n");
1822 : 0 : goto out;
1823 : : }
1824 : : } else {
1825 : 0 : hw->phy.media_type = e1000_media_type_unknown;
1826 : : }
1827 : : ret_val = E1000_SUCCESS;
1828 : 0 : out:
1829 : : /* Restore I2C interface setting */
1830 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1831 : 0 : return ret_val;
1832 : : }
1833 : :
1834 : : /**
1835 : : * e1000_valid_led_default_82575 - Verify a valid default LED config
1836 : : * @hw: pointer to the HW structure
1837 : : * @data: pointer to the NVM (EEPROM)
1838 : : *
1839 : : * Read the EEPROM for the current default LED configuration. If the
1840 : : * LED configuration is not valid, set to a valid LED configuration.
1841 : : **/
1842 : 0 : STATIC s32 e1000_valid_led_default_82575(struct e1000_hw *hw, u16 *data)
1843 : : {
1844 : : s32 ret_val;
1845 : :
1846 : 0 : DEBUGFUNC("e1000_valid_led_default_82575");
1847 : :
1848 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1849 [ # # ]: 0 : if (ret_val) {
1850 : 0 : DEBUGOUT("NVM Read Error\n");
1851 : 0 : goto out;
1852 : : }
1853 : :
1854 [ # # ]: 0 : if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1855 [ # # ]: 0 : switch (hw->phy.media_type) {
1856 : 0 : case e1000_media_type_internal_serdes:
1857 : 0 : *data = ID_LED_DEFAULT_82575_SERDES;
1858 : 0 : break;
1859 : 0 : case e1000_media_type_copper:
1860 : : default:
1861 : 0 : *data = ID_LED_DEFAULT;
1862 : 0 : break;
1863 : : }
1864 : : }
1865 : 0 : out:
1866 : 0 : return ret_val;
1867 : : }
1868 : :
1869 : : /**
1870 : : * e1000_sgmii_active_82575 - Return sgmii state
1871 : : * @hw: pointer to the HW structure
1872 : : *
1873 : : * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1874 : : * which can be enabled for use in the embedded applications. Simply
1875 : : * return the current state of the sgmii interface.
1876 : : **/
1877 : : STATIC bool e1000_sgmii_active_82575(struct e1000_hw *hw)
1878 : : {
1879 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1880 [ # # # # : 0 : return dev_spec->sgmii_active;
# # # # #
# # # # #
# # ]
1881 : : }
1882 : :
1883 : : /**
1884 : : * e1000_reset_init_script_82575 - Inits HW defaults after reset
1885 : : * @hw: pointer to the HW structure
1886 : : *
1887 : : * Inits recommended HW defaults after a reset when there is no EEPROM
1888 : : * detected. This is only for the 82575.
1889 : : **/
1890 : 0 : s32 e1000_reset_init_script_82575(struct e1000_hw *hw)
1891 : : {
1892 : 0 : DEBUGFUNC("e1000_reset_init_script_82575");
1893 : :
1894 [ # # ]: 0 : if (hw->mac.type == e1000_82575) {
1895 : 0 : DEBUGOUT("Running reset init script for 82575\n");
1896 : : /* SerDes configuration via SERDESCTRL */
1897 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x00, 0x0C);
1898 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x01, 0x78);
1899 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x1B, 0x23);
1900 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x23, 0x15);
1901 : :
1902 : : /* CCM configuration via CCMCTL register */
1903 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x14, 0x00);
1904 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x10, 0x00);
1905 : :
1906 : : /* PCIe lanes configuration */
1907 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x00, 0xEC);
1908 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x61, 0xDF);
1909 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x34, 0x05);
1910 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x2F, 0x81);
1911 : :
1912 : : /* PCIe PLL Configuration */
1913 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x02, 0x47);
1914 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x14, 0x00);
1915 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x10, 0x00);
1916 : : }
1917 : :
1918 : 0 : return E1000_SUCCESS;
1919 : : }
1920 : :
1921 : : /**
1922 : : * e1000_read_mac_addr_82575 - Read device MAC address
1923 : : * @hw: pointer to the HW structure
1924 : : **/
1925 : 0 : STATIC s32 e1000_read_mac_addr_82575(struct e1000_hw *hw)
1926 : : {
1927 : : s32 ret_val;
1928 : :
1929 : 0 : DEBUGFUNC("e1000_read_mac_addr_82575");
1930 : :
1931 : : /*
1932 : : * If there's an alternate MAC address place it in RAR0
1933 : : * so that it will override the Si installed default perm
1934 : : * address.
1935 : : */
1936 : 0 : ret_val = e1000_check_alt_mac_addr_generic(hw);
1937 [ # # ]: 0 : if (ret_val)
1938 : 0 : goto out;
1939 : :
1940 : 0 : ret_val = e1000_read_mac_addr_generic(hw);
1941 : :
1942 : 0 : out:
1943 : 0 : return ret_val;
1944 : : }
1945 : :
1946 : : /**
1947 : : * e1000_config_collision_dist_82575 - Configure collision distance
1948 : : * @hw: pointer to the HW structure
1949 : : *
1950 : : * Configures the collision distance to the default value and is used
1951 : : * during link setup.
1952 : : **/
1953 : 0 : STATIC void e1000_config_collision_dist_82575(struct e1000_hw *hw)
1954 : : {
1955 : : u32 tctl_ext;
1956 : :
1957 : 0 : DEBUGFUNC("e1000_config_collision_dist_82575");
1958 : :
1959 : 0 : tctl_ext = E1000_READ_REG(hw, E1000_TCTL_EXT);
1960 : :
1961 : 0 : tctl_ext &= ~E1000_TCTL_EXT_COLD;
1962 : 0 : tctl_ext |= E1000_COLLISION_DISTANCE << E1000_TCTL_EXT_COLD_SHIFT;
1963 : :
1964 : 0 : E1000_WRITE_REG(hw, E1000_TCTL_EXT, tctl_ext);
1965 : 0 : E1000_WRITE_FLUSH(hw);
1966 : 0 : }
1967 : :
1968 : : /**
1969 : : * e1000_clear_hw_cntrs_82575 - Clear device specific hardware counters
1970 : : * @hw: pointer to the HW structure
1971 : : *
1972 : : * Clears the hardware counters by reading the counter registers.
1973 : : **/
1974 : 0 : STATIC void e1000_clear_hw_cntrs_82575(struct e1000_hw *hw)
1975 : : {
1976 : 0 : DEBUGFUNC("e1000_clear_hw_cntrs_82575");
1977 : :
1978 : 0 : e1000_clear_hw_cntrs_base_generic(hw);
1979 : :
1980 : 0 : E1000_READ_REG(hw, E1000_PRC64);
1981 : 0 : E1000_READ_REG(hw, E1000_PRC127);
1982 : 0 : E1000_READ_REG(hw, E1000_PRC255);
1983 : 0 : E1000_READ_REG(hw, E1000_PRC511);
1984 : 0 : E1000_READ_REG(hw, E1000_PRC1023);
1985 : 0 : E1000_READ_REG(hw, E1000_PRC1522);
1986 : 0 : E1000_READ_REG(hw, E1000_PTC64);
1987 : 0 : E1000_READ_REG(hw, E1000_PTC127);
1988 : 0 : E1000_READ_REG(hw, E1000_PTC255);
1989 : 0 : E1000_READ_REG(hw, E1000_PTC511);
1990 : 0 : E1000_READ_REG(hw, E1000_PTC1023);
1991 : 0 : E1000_READ_REG(hw, E1000_PTC1522);
1992 : :
1993 : 0 : E1000_READ_REG(hw, E1000_ALGNERRC);
1994 : 0 : E1000_READ_REG(hw, E1000_RXERRC);
1995 : 0 : E1000_READ_REG(hw, E1000_TNCRS);
1996 : 0 : E1000_READ_REG(hw, E1000_CEXTERR);
1997 : 0 : E1000_READ_REG(hw, E1000_TSCTC);
1998 : 0 : E1000_READ_REG(hw, E1000_TSCTFC);
1999 : :
2000 : 0 : E1000_READ_REG(hw, E1000_MGTPRC);
2001 : 0 : E1000_READ_REG(hw, E1000_MGTPDC);
2002 : 0 : E1000_READ_REG(hw, E1000_MGTPTC);
2003 : :
2004 : 0 : E1000_READ_REG(hw, E1000_IAC);
2005 : 0 : E1000_READ_REG(hw, E1000_ICRXOC);
2006 : :
2007 : 0 : E1000_READ_REG(hw, E1000_ICRXPTC);
2008 : 0 : E1000_READ_REG(hw, E1000_ICRXATC);
2009 : 0 : E1000_READ_REG(hw, E1000_ICTXPTC);
2010 : 0 : E1000_READ_REG(hw, E1000_ICTXATC);
2011 : 0 : E1000_READ_REG(hw, E1000_ICTXQEC);
2012 : 0 : E1000_READ_REG(hw, E1000_ICTXQMTC);
2013 : 0 : E1000_READ_REG(hw, E1000_ICRXDMTC);
2014 : :
2015 : 0 : E1000_READ_REG(hw, E1000_CBTMPC);
2016 : 0 : E1000_READ_REG(hw, E1000_HTDPMC);
2017 : 0 : E1000_READ_REG(hw, E1000_CBRMPC);
2018 : 0 : E1000_READ_REG(hw, E1000_RPTHC);
2019 : 0 : E1000_READ_REG(hw, E1000_HGPTC);
2020 : 0 : E1000_READ_REG(hw, E1000_HTCBDPC);
2021 : 0 : E1000_READ_REG(hw, E1000_HGORCL);
2022 : 0 : E1000_READ_REG(hw, E1000_HGORCH);
2023 : 0 : E1000_READ_REG(hw, E1000_HGOTCL);
2024 : 0 : E1000_READ_REG(hw, E1000_HGOTCH);
2025 : 0 : E1000_READ_REG(hw, E1000_LENERRS);
2026 : :
2027 : : /* This register should not be read in copper configurations */
2028 [ # # # # ]: 0 : if ((hw->phy.media_type == e1000_media_type_internal_serdes) ||
2029 : : e1000_sgmii_active_82575(hw))
2030 : 0 : E1000_READ_REG(hw, E1000_SCVPC);
2031 : 0 : }
2032 : :
2033 : : /**
2034 : : * e1000_set_pcie_completion_timeout - set pci-e completion timeout
2035 : : * @hw: pointer to the HW structure
2036 : : *
2037 : : * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2038 : : * however the hardware default for these parts is 500us to 1ms which is less
2039 : : * than the 10ms recommended by the pci-e spec. To address this we need to
2040 : : * increase the value to either 10ms to 200ms for capability version 1 config,
2041 : : * or 16ms to 55ms for version 2.
2042 : : **/
2043 : 0 : STATIC s32 e1000_set_pcie_completion_timeout(struct e1000_hw *hw)
2044 : : {
2045 : 0 : u32 gcr = E1000_READ_REG(hw, E1000_GCR);
2046 : : s32 ret_val = E1000_SUCCESS;
2047 : : u16 pcie_devctl2;
2048 : :
2049 : : /* only take action if timeout value is defaulted to 0 */
2050 [ # # ]: 0 : if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2051 : 0 : goto out;
2052 : :
2053 : : /*
2054 : : * if capababilities version is type 1 we can write the
2055 : : * timeout of 10ms to 200ms through the GCR register
2056 : : */
2057 [ # # ]: 0 : if (!(gcr & E1000_GCR_CAP_VER2)) {
2058 : 0 : gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2059 : 0 : goto out;
2060 : : }
2061 : :
2062 : : /*
2063 : : * for version 2 capabilities we need to write the config space
2064 : : * directly in order to set the completion timeout value for
2065 : : * 16ms to 55ms
2066 : : */
2067 : 0 : ret_val = e1000_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2068 : : &pcie_devctl2);
2069 [ # # ]: 0 : if (ret_val)
2070 : 0 : goto out;
2071 : :
2072 : 0 : pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2073 : :
2074 : 0 : ret_val = e1000_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2075 : : &pcie_devctl2);
2076 : 0 : out:
2077 : : /* disable completion timeout resend */
2078 : 0 : gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2079 : :
2080 : 0 : E1000_WRITE_REG(hw, E1000_GCR, gcr);
2081 : 0 : return ret_val;
2082 : : }
2083 : :
2084 : : /**
2085 : : * e1000_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2086 : : * @hw: pointer to the hardware struct
2087 : : * @enable: state to enter, either enabled or disabled
2088 : : * @pf: Physical Function pool - do not set anti-spoofing for the PF
2089 : : *
2090 : : * enables/disables L2 switch anti-spoofing functionality.
2091 : : **/
2092 : 0 : void e1000_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2093 : : {
2094 : : u32 reg_val, reg_offset;
2095 : :
2096 [ # # # ]: 0 : switch (hw->mac.type) {
2097 : : case e1000_82576:
2098 : : reg_offset = E1000_DTXSWC;
2099 : : break;
2100 : 0 : case e1000_i350:
2101 : : case e1000_i354:
2102 : : reg_offset = E1000_TXSWC;
2103 : 0 : break;
2104 : : default:
2105 : : return;
2106 : : }
2107 : :
2108 : 0 : reg_val = E1000_READ_REG(hw, reg_offset);
2109 [ # # ]: 0 : if (enable) {
2110 : 0 : reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2111 : : E1000_DTXSWC_VLAN_SPOOF_MASK);
2112 : : /* The PF can spoof - it has to in order to
2113 : : * support emulation mode NICs
2114 : : */
2115 : 0 : reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2116 : : } else {
2117 : 0 : reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2118 : : E1000_DTXSWC_VLAN_SPOOF_MASK);
2119 : : }
2120 : 0 : E1000_WRITE_REG(hw, reg_offset, reg_val);
2121 : : }
2122 : :
2123 : : /**
2124 : : * e1000_vmdq_set_loopback_pf - enable or disable vmdq loopback
2125 : : * @hw: pointer to the hardware struct
2126 : : * @enable: state to enter, either enabled or disabled
2127 : : *
2128 : : * enables/disables L2 switch loopback functionality.
2129 : : **/
2130 : 0 : void e1000_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2131 : : {
2132 : : u32 dtxswc;
2133 : :
2134 [ # # # ]: 0 : switch (hw->mac.type) {
2135 : 0 : case e1000_82576:
2136 : 0 : dtxswc = E1000_READ_REG(hw, E1000_DTXSWC);
2137 [ # # ]: 0 : if (enable)
2138 : 0 : dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2139 : : else
2140 : 0 : dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2141 : 0 : E1000_WRITE_REG(hw, E1000_DTXSWC, dtxswc);
2142 : : break;
2143 : 0 : case e1000_i350:
2144 : : case e1000_i354:
2145 : 0 : dtxswc = E1000_READ_REG(hw, E1000_TXSWC);
2146 [ # # ]: 0 : if (enable)
2147 : 0 : dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2148 : : else
2149 : 0 : dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2150 : 0 : E1000_WRITE_REG(hw, E1000_TXSWC, dtxswc);
2151 : : break;
2152 : : default:
2153 : : /* Currently no other hardware supports loopback */
2154 : : break;
2155 : : }
2156 : :
2157 : :
2158 : 0 : }
2159 : :
2160 : : /**
2161 : : * e1000_vmdq_set_replication_pf - enable or disable vmdq replication
2162 : : * @hw: pointer to the hardware struct
2163 : : * @enable: state to enter, either enabled or disabled
2164 : : *
2165 : : * enables/disables replication of packets across multiple pools.
2166 : : **/
2167 : 0 : void e1000_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2168 : : {
2169 : 0 : u32 vt_ctl = E1000_READ_REG(hw, E1000_VT_CTL);
2170 : :
2171 [ # # ]: 0 : if (enable)
2172 : 0 : vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2173 : : else
2174 : 0 : vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2175 : :
2176 : 0 : E1000_WRITE_REG(hw, E1000_VT_CTL, vt_ctl);
2177 : 0 : }
2178 : :
2179 : : /**
2180 : : * e1000_read_phy_reg_82580 - Read 82580 MDI control register
2181 : : * @hw: pointer to the HW structure
2182 : : * @offset: register offset to be read
2183 : : * @data: pointer to the read data
2184 : : *
2185 : : * Reads the MDI control register in the PHY at offset and stores the
2186 : : * information read to data.
2187 : : **/
2188 : 0 : STATIC s32 e1000_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2189 : : {
2190 : : s32 ret_val;
2191 : :
2192 : 0 : DEBUGFUNC("e1000_read_phy_reg_82580");
2193 : :
2194 : 0 : ret_val = hw->phy.ops.acquire(hw);
2195 [ # # ]: 0 : if (ret_val)
2196 : 0 : goto out;
2197 : :
2198 : 0 : ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
2199 : :
2200 : 0 : hw->phy.ops.release(hw);
2201 : :
2202 : 0 : out:
2203 : 0 : return ret_val;
2204 : : }
2205 : :
2206 : : /**
2207 : : * e1000_write_phy_reg_82580 - Write 82580 MDI control register
2208 : : * @hw: pointer to the HW structure
2209 : : * @offset: register offset to write to
2210 : : * @data: data to write to register at offset
2211 : : *
2212 : : * Writes data to MDI control register in the PHY at offset.
2213 : : **/
2214 : 0 : STATIC s32 e1000_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2215 : : {
2216 : : s32 ret_val;
2217 : :
2218 : 0 : DEBUGFUNC("e1000_write_phy_reg_82580");
2219 : :
2220 : 0 : ret_val = hw->phy.ops.acquire(hw);
2221 [ # # ]: 0 : if (ret_val)
2222 : 0 : goto out;
2223 : :
2224 : 0 : ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
2225 : :
2226 : 0 : hw->phy.ops.release(hw);
2227 : :
2228 : 0 : out:
2229 : 0 : return ret_val;
2230 : : }
2231 : :
2232 : : /**
2233 : : * e1000_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2234 : : * @hw: pointer to the HW structure
2235 : : *
2236 : : * This resets the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2237 : : * the values found in the EEPROM. This addresses an issue in which these
2238 : : * bits are not restored from EEPROM after reset.
2239 : : **/
2240 : 0 : STATIC s32 e1000_reset_mdicnfg_82580(struct e1000_hw *hw)
2241 : : {
2242 : : s32 ret_val = E1000_SUCCESS;
2243 : : u32 mdicnfg;
2244 : 0 : u16 nvm_data = 0;
2245 : :
2246 : 0 : DEBUGFUNC("e1000_reset_mdicnfg_82580");
2247 : :
2248 [ # # ]: 0 : if (hw->mac.type != e1000_82580)
2249 : 0 : goto out;
2250 [ # # ]: 0 : if (!e1000_sgmii_active_82575(hw))
2251 : 0 : goto out;
2252 : :
2253 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2254 [ # # ]: 0 : NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2255 : : &nvm_data);
2256 [ # # ]: 0 : if (ret_val) {
2257 : 0 : DEBUGOUT("NVM Read Error\n");
2258 : 0 : goto out;
2259 : : }
2260 : :
2261 : 0 : mdicnfg = E1000_READ_REG(hw, E1000_MDICNFG);
2262 [ # # ]: 0 : if (nvm_data & NVM_WORD24_EXT_MDIO)
2263 : 0 : mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2264 [ # # ]: 0 : if (nvm_data & NVM_WORD24_COM_MDIO)
2265 : 0 : mdicnfg |= E1000_MDICNFG_COM_MDIO;
2266 : 0 : E1000_WRITE_REG(hw, E1000_MDICNFG, mdicnfg);
2267 : 0 : out:
2268 : 0 : return ret_val;
2269 : : }
2270 : :
2271 : : /**
2272 : : * e1000_reset_hw_82580 - Reset hardware
2273 : : * @hw: pointer to the HW structure
2274 : : *
2275 : : * This resets function or entire device (all ports, etc.)
2276 : : * to a known state.
2277 : : **/
2278 : 0 : STATIC s32 e1000_reset_hw_82580(struct e1000_hw *hw)
2279 : : {
2280 : : s32 ret_val = E1000_SUCCESS;
2281 : : /* BH SW mailbox bit in SW_FW_SYNC */
2282 : : u16 swmbsw_mask = E1000_SW_SYNCH_MB;
2283 : : u32 ctrl;
2284 : 0 : bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2285 : :
2286 : 0 : DEBUGFUNC("e1000_reset_hw_82580");
2287 : :
2288 : 0 : hw->dev_spec._82575.global_device_reset = false;
2289 : :
2290 : : /* 82580 does not reliably do global_device_reset due to hw errata */
2291 [ # # ]: 0 : if (hw->mac.type == e1000_82580)
2292 : : global_device_reset = false;
2293 : :
2294 : : /* Get current control state. */
2295 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
2296 : :
2297 : : /*
2298 : : * Prevent the PCI-E bus from sticking if there is no TLP connection
2299 : : * on the last TLP read/write transaction when MAC is reset.
2300 : : */
2301 : 0 : ret_val = e1000_disable_pcie_master_generic(hw);
2302 [ # # ]: 0 : if (ret_val)
2303 : 0 : DEBUGOUT("PCI-E Master disable polling has failed.\n");
2304 : :
2305 : 0 : DEBUGOUT("Masking off all interrupts\n");
2306 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2307 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, 0);
2308 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
2309 : 0 : E1000_WRITE_FLUSH(hw);
2310 : :
2311 : 0 : msec_delay(10);
2312 : :
2313 : : /* Determine whether or not a global dev reset is requested */
2314 [ # # # # ]: 0 : if (global_device_reset && hw->mac.ops.acquire_swfw_sync(hw,
2315 : : swmbsw_mask))
2316 : : global_device_reset = false;
2317 : :
2318 [ # # # # ]: 0 : if (global_device_reset && !(E1000_READ_REG(hw, E1000_STATUS) &
2319 : : E1000_STAT_DEV_RST_SET))
2320 : 0 : ctrl |= E1000_CTRL_DEV_RST;
2321 : : else
2322 : 0 : ctrl |= E1000_CTRL_RST;
2323 : :
2324 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2325 : :
2326 [ # # ]: 0 : switch (hw->device_id) {
2327 : : case E1000_DEV_ID_DH89XXCC_SGMII:
2328 : : break;
2329 : 0 : default:
2330 : 0 : E1000_WRITE_FLUSH(hw);
2331 : : break;
2332 : : }
2333 : :
2334 : : /* Add delay to insure DEV_RST or RST has time to complete */
2335 : 0 : msec_delay(5);
2336 : :
2337 : 0 : ret_val = e1000_get_auto_rd_done_generic(hw);
2338 [ # # ]: 0 : if (ret_val) {
2339 : : /*
2340 : : * When auto config read does not complete, do not
2341 : : * return with an error. This can happen in situations
2342 : : * where there is no eeprom and prevents getting link.
2343 : : */
2344 : 0 : DEBUGOUT("Auto Read Done did not complete\n");
2345 : : }
2346 : :
2347 : : /* clear global device reset status bit */
2348 : 0 : E1000_WRITE_REG(hw, E1000_STATUS, E1000_STAT_DEV_RST_SET);
2349 : :
2350 : : /* Clear any pending interrupt events. */
2351 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2352 : 0 : E1000_READ_REG(hw, E1000_ICR);
2353 : :
2354 : 0 : ret_val = e1000_reset_mdicnfg_82580(hw);
2355 [ # # ]: 0 : if (ret_val)
2356 : 0 : DEBUGOUT("Could not reset MDICNFG based on EEPROM\n");
2357 : :
2358 : : /* Install any alternate MAC address into RAR0 */
2359 : 0 : ret_val = e1000_check_alt_mac_addr_generic(hw);
2360 : :
2361 : : /* Release semaphore */
2362 [ # # ]: 0 : if (global_device_reset)
2363 : 0 : hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
2364 : :
2365 : 0 : return ret_val;
2366 : : }
2367 : :
2368 : : /**
2369 : : * e1000_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual Rx PBA size
2370 : : * @data: data received by reading RXPBS register
2371 : : *
2372 : : * The 82580 uses a table based approach for packet buffer allocation sizes.
2373 : : * This function converts the retrieved value into the correct table value
2374 : : * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2375 : : * 0x0 36 72 144 1 2 4 8 16
2376 : : * 0x8 35 70 140 rsv rsv rsv rsv rsv
2377 : : */
2378 : 0 : u16 e1000_rxpbs_adjust_82580(u32 data)
2379 : : {
2380 : : u16 ret_val = 0;
2381 : :
2382 [ # # ]: 0 : if (data < E1000_82580_RXPBS_TABLE_SIZE)
2383 : 0 : ret_val = e1000_82580_rxpbs_table[data];
2384 : :
2385 : 0 : return ret_val;
2386 : : }
2387 : :
2388 : : /**
2389 : : * e1000_validate_nvm_checksum_with_offset - Validate EEPROM
2390 : : * checksum
2391 : : * @hw: pointer to the HW structure
2392 : : * @offset: offset in words of the checksum protected region
2393 : : *
2394 : : * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2395 : : * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2396 : : **/
2397 : 0 : s32 e1000_validate_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2398 : : {
2399 : : s32 ret_val = E1000_SUCCESS;
2400 : : u16 checksum = 0;
2401 : : u16 i, nvm_data;
2402 : :
2403 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_with_offset");
2404 : :
2405 [ # # ]: 0 : for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2406 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2407 [ # # ]: 0 : if (ret_val) {
2408 : 0 : DEBUGOUT("NVM Read Error\n");
2409 : 0 : goto out;
2410 : : }
2411 : 0 : checksum += nvm_data;
2412 : : }
2413 : :
2414 [ # # ]: 0 : if (checksum != (u16) NVM_SUM) {
2415 : 0 : DEBUGOUT("NVM Checksum Invalid\n");
2416 : : ret_val = -E1000_ERR_NVM;
2417 : 0 : goto out;
2418 : : }
2419 : :
2420 : 0 : out:
2421 : 0 : return ret_val;
2422 : : }
2423 : :
2424 : : /**
2425 : : * e1000_update_nvm_checksum_with_offset - Update EEPROM
2426 : : * checksum
2427 : : * @hw: pointer to the HW structure
2428 : : * @offset: offset in words of the checksum protected region
2429 : : *
2430 : : * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2431 : : * up to the checksum. Then calculates the EEPROM checksum and writes the
2432 : : * value to the EEPROM.
2433 : : **/
2434 : 0 : s32 e1000_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2435 : : {
2436 : : s32 ret_val;
2437 : 0 : u16 checksum = 0;
2438 : : u16 i, nvm_data;
2439 : :
2440 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_with_offset");
2441 : :
2442 [ # # ]: 0 : for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2443 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2444 [ # # ]: 0 : if (ret_val) {
2445 : 0 : DEBUGOUT("NVM Read Error while updating checksum.\n");
2446 : 0 : goto out;
2447 : : }
2448 : 0 : checksum += nvm_data;
2449 : : }
2450 : 0 : checksum = (u16) NVM_SUM - checksum;
2451 : 0 : ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2452 : : &checksum);
2453 [ # # ]: 0 : if (ret_val)
2454 : 0 : DEBUGOUT("NVM Write Error while updating checksum.\n");
2455 : :
2456 : 0 : out:
2457 : 0 : return ret_val;
2458 : : }
2459 : :
2460 : : /**
2461 : : * e1000_validate_nvm_checksum_82580 - Validate EEPROM checksum
2462 : : * @hw: pointer to the HW structure
2463 : : *
2464 : : * Calculates the EEPROM section checksum by reading/adding each word of
2465 : : * the EEPROM and then verifies that the sum of the EEPROM is
2466 : : * equal to 0xBABA.
2467 : : **/
2468 : 0 : STATIC s32 e1000_validate_nvm_checksum_82580(struct e1000_hw *hw)
2469 : : {
2470 : : s32 ret_val;
2471 : : u16 eeprom_regions_count = 1;
2472 : : u16 j, nvm_data;
2473 : : u16 nvm_offset;
2474 : :
2475 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_82580");
2476 : :
2477 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2478 [ # # ]: 0 : if (ret_val) {
2479 : 0 : DEBUGOUT("NVM Read Error\n");
2480 : 0 : goto out;
2481 : : }
2482 : :
2483 [ # # ]: 0 : if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
2484 : : /* if chekcsums compatibility bit is set validate checksums
2485 : : * for all 4 ports. */
2486 : : eeprom_regions_count = 4;
2487 : : }
2488 : :
2489 [ # # ]: 0 : for (j = 0; j < eeprom_regions_count; j++) {
2490 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2491 : 0 : ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2492 : : nvm_offset);
2493 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2494 : 0 : goto out;
2495 : : }
2496 : :
2497 : 0 : out:
2498 : 0 : return ret_val;
2499 : : }
2500 : :
2501 : : /**
2502 : : * e1000_update_nvm_checksum_82580 - Update EEPROM checksum
2503 : : * @hw: pointer to the HW structure
2504 : : *
2505 : : * Updates the EEPROM section checksums for all 4 ports by reading/adding
2506 : : * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2507 : : * checksum and writes the value to the EEPROM.
2508 : : **/
2509 : 0 : STATIC s32 e1000_update_nvm_checksum_82580(struct e1000_hw *hw)
2510 : : {
2511 : : s32 ret_val;
2512 : : u16 j, nvm_data;
2513 : : u16 nvm_offset;
2514 : :
2515 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_82580");
2516 : :
2517 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2518 [ # # ]: 0 : if (ret_val) {
2519 : 0 : DEBUGOUT("NVM Read Error while updating checksum compatibility bit.\n");
2520 : 0 : goto out;
2521 : : }
2522 : :
2523 [ # # ]: 0 : if (!(nvm_data & NVM_COMPATIBILITY_BIT_MASK)) {
2524 : : /* set compatibility bit to validate checksums appropriately */
2525 : 0 : nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2526 : 0 : ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2527 : : &nvm_data);
2528 [ # # ]: 0 : if (ret_val) {
2529 : 0 : DEBUGOUT("NVM Write Error while updating checksum compatibility bit.\n");
2530 : 0 : goto out;
2531 : : }
2532 : : }
2533 : :
2534 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2535 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2536 : 0 : ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2537 [ # # ]: 0 : if (ret_val)
2538 : 0 : goto out;
2539 : : }
2540 : :
2541 : 0 : out:
2542 : 0 : return ret_val;
2543 : : }
2544 : :
2545 : : /**
2546 : : * e1000_validate_nvm_checksum_i350 - Validate EEPROM checksum
2547 : : * @hw: pointer to the HW structure
2548 : : *
2549 : : * Calculates the EEPROM section checksum by reading/adding each word of
2550 : : * the EEPROM and then verifies that the sum of the EEPROM is
2551 : : * equal to 0xBABA.
2552 : : **/
2553 : 0 : STATIC s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw)
2554 : : {
2555 : : s32 ret_val = E1000_SUCCESS;
2556 : : u16 j;
2557 : : u16 nvm_offset;
2558 : :
2559 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_i350");
2560 : :
2561 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2562 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2563 : 0 : ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2564 : : nvm_offset);
2565 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2566 : 0 : goto out;
2567 : : }
2568 : :
2569 : 0 : out:
2570 : 0 : return ret_val;
2571 : : }
2572 : :
2573 : : /**
2574 : : * e1000_update_nvm_checksum_i350 - Update EEPROM checksum
2575 : : * @hw: pointer to the HW structure
2576 : : *
2577 : : * Updates the EEPROM section checksums for all 4 ports by reading/adding
2578 : : * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2579 : : * checksum and writes the value to the EEPROM.
2580 : : **/
2581 : 0 : STATIC s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw)
2582 : : {
2583 : : s32 ret_val = E1000_SUCCESS;
2584 : : u16 j;
2585 : : u16 nvm_offset;
2586 : :
2587 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_i350");
2588 : :
2589 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2590 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2591 : 0 : ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2592 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2593 : 0 : goto out;
2594 : : }
2595 : :
2596 : 0 : out:
2597 : 0 : return ret_val;
2598 : : }
2599 : :
2600 : : /**
2601 : : * __e1000_access_emi_reg - Read/write EMI register
2602 : : * @hw: pointer to the HW structure
2603 : : * @address: EMI address to program
2604 : : * @data: pointer to value to read/write from/to the EMI address
2605 : : * @read: boolean flag to indicate read or write
2606 : : **/
2607 : 0 : STATIC s32 __e1000_access_emi_reg(struct e1000_hw *hw, u16 address,
2608 : : u16 *data, bool read)
2609 : : {
2610 : : s32 ret_val;
2611 : :
2612 : 0 : DEBUGFUNC("__e1000_access_emi_reg");
2613 : :
2614 : 0 : ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2615 [ # # ]: 0 : if (ret_val)
2616 : : return ret_val;
2617 : :
2618 [ # # ]: 0 : if (read)
2619 : 0 : ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2620 : : else
2621 : 0 : ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2622 : :
2623 : : return ret_val;
2624 : : }
2625 : :
2626 : : /**
2627 : : * e1000_read_emi_reg - Read Extended Management Interface register
2628 : : * @hw: pointer to the HW structure
2629 : : * @addr: EMI address to program
2630 : : * @data: value to be read from the EMI address
2631 : : **/
2632 : 0 : s32 e1000_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2633 : : {
2634 : 0 : DEBUGFUNC("e1000_read_emi_reg");
2635 : :
2636 : 0 : return __e1000_access_emi_reg(hw, addr, data, true);
2637 : : }
2638 : :
2639 : : /**
2640 : : * e1000_initialize_M88E1512_phy - Initialize M88E1512 PHY
2641 : : * @hw: pointer to the HW structure
2642 : : *
2643 : : * Initialize Marvell 1512 to work correctly with Avoton.
2644 : : **/
2645 : 0 : s32 e1000_initialize_M88E1512_phy(struct e1000_hw *hw)
2646 : : {
2647 : : struct e1000_phy_info *phy = &hw->phy;
2648 : : s32 ret_val = E1000_SUCCESS;
2649 : :
2650 : 0 : DEBUGFUNC("e1000_initialize_M88E1512_phy");
2651 : :
2652 : : /* Check if this is correct PHY. */
2653 [ # # ]: 0 : if (phy->id != M88E1512_E_PHY_ID)
2654 : 0 : goto out;
2655 : :
2656 : : /* Switch to PHY page 0xFF. */
2657 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2658 [ # # ]: 0 : if (ret_val)
2659 : 0 : goto out;
2660 : :
2661 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2662 [ # # ]: 0 : if (ret_val)
2663 : 0 : goto out;
2664 : :
2665 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2666 [ # # ]: 0 : if (ret_val)
2667 : 0 : goto out;
2668 : :
2669 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2670 [ # # ]: 0 : if (ret_val)
2671 : 0 : goto out;
2672 : :
2673 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2674 [ # # ]: 0 : if (ret_val)
2675 : 0 : goto out;
2676 : :
2677 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2678 [ # # ]: 0 : if (ret_val)
2679 : 0 : goto out;
2680 : :
2681 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2682 [ # # ]: 0 : if (ret_val)
2683 : 0 : goto out;
2684 : :
2685 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xCC0C);
2686 [ # # ]: 0 : if (ret_val)
2687 : 0 : goto out;
2688 : :
2689 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2690 [ # # ]: 0 : if (ret_val)
2691 : 0 : goto out;
2692 : :
2693 : : /* Switch to PHY page 0xFB. */
2694 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2695 [ # # ]: 0 : if (ret_val)
2696 : 0 : goto out;
2697 : :
2698 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x000D);
2699 [ # # ]: 0 : if (ret_val)
2700 : 0 : goto out;
2701 : :
2702 : : /* Switch to PHY page 0x12. */
2703 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2704 [ # # ]: 0 : if (ret_val)
2705 : 0 : goto out;
2706 : :
2707 : : /* Change mode to SGMII-to-Copper */
2708 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2709 [ # # ]: 0 : if (ret_val)
2710 : 0 : goto out;
2711 : :
2712 : : /* Return the PHY to page 0. */
2713 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2714 [ # # ]: 0 : if (ret_val)
2715 : 0 : goto out;
2716 : :
2717 : 0 : ret_val = phy->ops.commit(hw);
2718 [ # # ]: 0 : if (ret_val) {
2719 : 0 : DEBUGOUT("Error committing the PHY changes\n");
2720 : 0 : return ret_val;
2721 : : }
2722 : :
2723 : 0 : msec_delay(1000);
2724 : : out:
2725 : : return ret_val;
2726 : : }
2727 : :
2728 : : /**
2729 : : * e1000_initialize_M88E1543_phy - Initialize M88E1543 PHY
2730 : : * @hw: pointer to the HW structure
2731 : : *
2732 : : * Initialize Marvell 1543 to work correctly with Avoton.
2733 : : **/
2734 : 0 : s32 e1000_initialize_M88E1543_phy(struct e1000_hw *hw)
2735 : : {
2736 : : struct e1000_phy_info *phy = &hw->phy;
2737 : : s32 ret_val = E1000_SUCCESS;
2738 : :
2739 : 0 : DEBUGFUNC("e1000_initialize_M88E1543_phy");
2740 : :
2741 : : /* Check if this is correct PHY. */
2742 [ # # ]: 0 : if (phy->id != M88E1543_E_PHY_ID)
2743 : 0 : goto out;
2744 : :
2745 : : /* Switch to PHY page 0xFF. */
2746 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2747 [ # # ]: 0 : if (ret_val)
2748 : 0 : goto out;
2749 : :
2750 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2751 [ # # ]: 0 : if (ret_val)
2752 : 0 : goto out;
2753 : :
2754 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2755 [ # # ]: 0 : if (ret_val)
2756 : 0 : goto out;
2757 : :
2758 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2759 [ # # ]: 0 : if (ret_val)
2760 : 0 : goto out;
2761 : :
2762 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2763 [ # # ]: 0 : if (ret_val)
2764 : 0 : goto out;
2765 : :
2766 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2767 [ # # ]: 0 : if (ret_val)
2768 : 0 : goto out;
2769 : :
2770 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2771 [ # # ]: 0 : if (ret_val)
2772 : 0 : goto out;
2773 : :
2774 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xDC0C);
2775 [ # # ]: 0 : if (ret_val)
2776 : 0 : goto out;
2777 : :
2778 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2779 [ # # ]: 0 : if (ret_val)
2780 : 0 : goto out;
2781 : :
2782 : : /* Switch to PHY page 0xFB. */
2783 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2784 [ # # ]: 0 : if (ret_val)
2785 : 0 : goto out;
2786 : :
2787 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0xC00D);
2788 [ # # ]: 0 : if (ret_val)
2789 : 0 : goto out;
2790 : :
2791 : : /* Switch to PHY page 0x12. */
2792 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2793 [ # # ]: 0 : if (ret_val)
2794 : 0 : goto out;
2795 : :
2796 : : /* Change mode to SGMII-to-Copper */
2797 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2798 [ # # ]: 0 : if (ret_val)
2799 : 0 : goto out;
2800 : :
2801 : : /* Switch to PHY page 1. */
2802 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x1);
2803 [ # # ]: 0 : if (ret_val)
2804 : 0 : goto out;
2805 : :
2806 : : /* Change mode to 1000BASE-X/SGMII and autoneg enable; reset */
2807 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_FIBER_CTRL, 0x9140);
2808 [ # # ]: 0 : if (ret_val)
2809 : 0 : goto out;
2810 : :
2811 : : /* Return the PHY to page 0. */
2812 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2813 [ # # ]: 0 : if (ret_val)
2814 : 0 : goto out;
2815 : :
2816 : 0 : ret_val = phy->ops.commit(hw);
2817 [ # # ]: 0 : if (ret_val) {
2818 : 0 : DEBUGOUT("Error committing the PHY changes\n");
2819 : 0 : return ret_val;
2820 : : }
2821 : :
2822 : 0 : msec_delay(1000);
2823 : : out:
2824 : : return ret_val;
2825 : : }
2826 : :
2827 : : /**
2828 : : * e1000_set_eee_i350 - Enable/disable EEE support
2829 : : * @hw: pointer to the HW structure
2830 : : * @adv1G: boolean flag enabling 1G EEE advertisement
2831 : : * @adv100M: boolean flag enabling 100M EEE advertisement
2832 : : *
2833 : : * Enable/disable EEE based on setting in dev_spec structure.
2834 : : *
2835 : : **/
2836 : 0 : s32 e1000_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
2837 : : {
2838 : : u32 ipcnfg, eeer;
2839 : :
2840 : 0 : DEBUGFUNC("e1000_set_eee_i350");
2841 : :
2842 [ # # ]: 0 : if ((hw->mac.type < e1000_i350) ||
2843 [ # # ]: 0 : (hw->phy.media_type != e1000_media_type_copper))
2844 : 0 : goto out;
2845 : 0 : ipcnfg = E1000_READ_REG(hw, E1000_IPCNFG);
2846 : 0 : eeer = E1000_READ_REG(hw, E1000_EEER);
2847 : :
2848 : : /* enable or disable per user setting */
2849 [ # # ]: 0 : if (!(hw->dev_spec._82575.eee_disable)) {
2850 : 0 : u32 eee_su = E1000_READ_REG(hw, E1000_EEE_SU);
2851 : :
2852 [ # # ]: 0 : if (adv100M)
2853 : 0 : ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
2854 : : else
2855 : 0 : ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
2856 : :
2857 [ # # ]: 0 : if (adv1G)
2858 : 0 : ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
2859 : : else
2860 : 0 : ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
2861 : :
2862 : 0 : eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2863 : : E1000_EEER_LPI_FC);
2864 : :
2865 : : /* This bit should not be set in normal operation. */
2866 [ # # ]: 0 : if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2867 : 0 : DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
2868 : : } else {
2869 : 0 : ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2870 : 0 : eeer &= ~(E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2871 : : E1000_EEER_LPI_FC);
2872 : : }
2873 : 0 : E1000_WRITE_REG(hw, E1000_IPCNFG, ipcnfg);
2874 : 0 : E1000_WRITE_REG(hw, E1000_EEER, eeer);
2875 : 0 : E1000_READ_REG(hw, E1000_IPCNFG);
2876 : 0 : E1000_READ_REG(hw, E1000_EEER);
2877 : 0 : out:
2878 : :
2879 : 0 : return E1000_SUCCESS;
2880 : : }
2881 : :
2882 : : /**
2883 : : * e1000_set_eee_i354 - Enable/disable EEE support
2884 : : * @hw: pointer to the HW structure
2885 : : * @adv1G: boolean flag enabling 1G EEE advertisement
2886 : : * @adv100M: boolean flag enabling 100M EEE advertisement
2887 : : *
2888 : : * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2889 : : *
2890 : : **/
2891 : 0 : s32 e1000_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
2892 : : {
2893 : : struct e1000_phy_info *phy = &hw->phy;
2894 : : s32 ret_val = E1000_SUCCESS;
2895 : : u16 phy_data;
2896 : :
2897 : 0 : DEBUGFUNC("e1000_set_eee_i354");
2898 : :
2899 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_copper) ||
2900 [ # # ]: 0 : ((phy->id != M88E1543_E_PHY_ID) &&
2901 : : (phy->id != M88E1512_E_PHY_ID)))
2902 : 0 : goto out;
2903 : :
2904 [ # # ]: 0 : if (!hw->dev_spec._82575.eee_disable) {
2905 : : /* Switch to PHY page 18. */
2906 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
2907 [ # # ]: 0 : if (ret_val)
2908 : 0 : goto out;
2909 : :
2910 : 0 : ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2911 : : &phy_data);
2912 [ # # ]: 0 : if (ret_val)
2913 : 0 : goto out;
2914 : :
2915 : 0 : phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2916 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2917 : : phy_data);
2918 [ # # ]: 0 : if (ret_val)
2919 : 0 : goto out;
2920 : :
2921 : : /* Return the PHY to page 0. */
2922 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2923 [ # # ]: 0 : if (ret_val)
2924 : 0 : goto out;
2925 : :
2926 : : /* Turn on EEE advertisement. */
2927 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2928 : : E1000_EEE_ADV_DEV_I354,
2929 : : &phy_data);
2930 [ # # ]: 0 : if (ret_val)
2931 : 0 : goto out;
2932 : :
2933 [ # # ]: 0 : if (adv100M)
2934 : 0 : phy_data |= E1000_EEE_ADV_100_SUPPORTED;
2935 : : else
2936 : 0 : phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
2937 : :
2938 [ # # ]: 0 : if (adv1G)
2939 : 0 : phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
2940 : : else
2941 : 0 : phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
2942 : :
2943 : 0 : ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2944 : : E1000_EEE_ADV_DEV_I354,
2945 : : phy_data);
2946 : : } else {
2947 : : /* Turn off EEE advertisement. */
2948 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2949 : : E1000_EEE_ADV_DEV_I354,
2950 : : &phy_data);
2951 [ # # ]: 0 : if (ret_val)
2952 : 0 : goto out;
2953 : :
2954 : 0 : phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2955 : : E1000_EEE_ADV_1000_SUPPORTED);
2956 : 0 : ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2957 : : E1000_EEE_ADV_DEV_I354,
2958 : : phy_data);
2959 : : }
2960 : :
2961 : 0 : out:
2962 : 0 : return ret_val;
2963 : : }
2964 : :
2965 : : /**
2966 : : * e1000_get_eee_status_i354 - Get EEE status
2967 : : * @hw: pointer to the HW structure
2968 : : * @status: EEE status
2969 : : *
2970 : : * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2971 : : * been received.
2972 : : **/
2973 : 0 : s32 e1000_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2974 : : {
2975 : : struct e1000_phy_info *phy = &hw->phy;
2976 : : s32 ret_val = E1000_SUCCESS;
2977 : : u16 phy_data;
2978 : :
2979 : 0 : DEBUGFUNC("e1000_get_eee_status_i354");
2980 : :
2981 : : /* Check if EEE is supported on this device. */
2982 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_copper) ||
2983 [ # # ]: 0 : ((phy->id != M88E1543_E_PHY_ID) &&
2984 : : (phy->id != M88E1512_E_PHY_ID)))
2985 : 0 : goto out;
2986 : :
2987 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2988 : : E1000_PCS_STATUS_DEV_I354,
2989 : : &phy_data);
2990 [ # # ]: 0 : if (ret_val)
2991 : 0 : goto out;
2992 : :
2993 : 0 : *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2994 : 0 : E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2995 : :
2996 : 0 : out:
2997 : 0 : return ret_val;
2998 : : }
2999 : :
3000 : : /* Due to a hw errata, if the host tries to configure the VFTA register
3001 : : * while performing queries from the BMC or DMA, then the VFTA in some
3002 : : * cases won't be written.
3003 : : */
3004 : :
3005 : : /**
3006 : : * e1000_clear_vfta_i350 - Clear VLAN filter table
3007 : : * @hw: pointer to the HW structure
3008 : : *
3009 : : * Clears the register array which contains the VLAN filter table by
3010 : : * setting all the values to 0.
3011 : : **/
3012 : 0 : void e1000_clear_vfta_i350(struct e1000_hw *hw)
3013 : : {
3014 : : u32 offset;
3015 : : int i;
3016 : :
3017 : 0 : DEBUGFUNC("e1000_clear_vfta_350");
3018 : :
3019 [ # # ]: 0 : for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
3020 [ # # ]: 0 : for (i = 0; i < 10; i++)
3021 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
3022 : :
3023 : 0 : E1000_WRITE_FLUSH(hw);
3024 : : }
3025 : 0 : }
3026 : :
3027 : : /**
3028 : : * e1000_write_vfta_i350 - Write value to VLAN filter table
3029 : : * @hw: pointer to the HW structure
3030 : : * @offset: register offset in VLAN filter table
3031 : : * @value: register value written to VLAN filter table
3032 : : *
3033 : : * Writes value at the given offset in the register array which stores
3034 : : * the VLAN filter table.
3035 : : **/
3036 : 0 : void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
3037 : : {
3038 : : int i;
3039 : :
3040 : 0 : DEBUGFUNC("e1000_write_vfta_350");
3041 : :
3042 [ # # ]: 0 : for (i = 0; i < 10; i++)
3043 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
3044 : :
3045 : 0 : E1000_WRITE_FLUSH(hw);
3046 : 0 : }
3047 : :
3048 : :
3049 : : /**
3050 : : * e1000_set_i2c_bb - Enable I2C bit-bang
3051 : : * @hw: pointer to the HW structure
3052 : : *
3053 : : * Enable I2C bit-bang interface
3054 : : *
3055 : : **/
3056 : 0 : s32 e1000_set_i2c_bb(struct e1000_hw *hw)
3057 : : {
3058 : : s32 ret_val = E1000_SUCCESS;
3059 : : u32 ctrl_ext, i2cparams;
3060 : :
3061 : 0 : DEBUGFUNC("e1000_set_i2c_bb");
3062 : :
3063 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
3064 : 0 : ctrl_ext |= E1000_CTRL_I2C_ENA;
3065 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
3066 : 0 : E1000_WRITE_FLUSH(hw);
3067 : :
3068 : 0 : i2cparams = E1000_READ_REG(hw, E1000_I2CPARAMS);
3069 : : i2cparams |= E1000_I2CBB_EN;
3070 : : i2cparams |= E1000_I2C_DATA_OE_N;
3071 : 0 : i2cparams |= E1000_I2C_CLK_OE_N;
3072 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cparams);
3073 : 0 : E1000_WRITE_FLUSH(hw);
3074 : :
3075 : 0 : return ret_val;
3076 : : }
3077 : :
3078 : : /**
3079 : : * e1000_read_i2c_byte_generic - Reads 8 bit word over I2C
3080 : : * @hw: pointer to hardware structure
3081 : : * @byte_offset: byte offset to read
3082 : : * @dev_addr: device address
3083 : : * @data: value read
3084 : : *
3085 : : * Performs byte read operation over I2C interface at
3086 : : * a specified device address.
3087 : : **/
3088 : 0 : s32 e1000_read_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3089 : : u8 dev_addr, u8 *data)
3090 : : {
3091 : : s32 status = E1000_SUCCESS;
3092 : : u32 max_retry = 10;
3093 : : u32 retry = 1;
3094 : : u16 swfw_mask = 0;
3095 : :
3096 : : bool nack = true;
3097 : :
3098 : 0 : DEBUGFUNC("e1000_read_i2c_byte_generic");
3099 : :
3100 : : swfw_mask = E1000_SWFW_PHY0_SM;
3101 : :
3102 : : do {
3103 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
3104 : : != E1000_SUCCESS) {
3105 : : status = E1000_ERR_SWFW_SYNC;
3106 : 0 : goto read_byte_out;
3107 : : }
3108 : :
3109 : 0 : e1000_i2c_start(hw);
3110 : :
3111 : : /* Device Address and write indication */
3112 : 0 : status = e1000_clock_out_i2c_byte(hw, dev_addr);
3113 [ # # ]: 0 : if (status != E1000_SUCCESS)
3114 : 0 : goto fail;
3115 : :
3116 : 0 : status = e1000_get_i2c_ack(hw);
3117 [ # # ]: 0 : if (status != E1000_SUCCESS)
3118 : 0 : goto fail;
3119 : :
3120 : 0 : status = e1000_clock_out_i2c_byte(hw, byte_offset);
3121 [ # # ]: 0 : if (status != E1000_SUCCESS)
3122 : 0 : goto fail;
3123 : :
3124 : 0 : status = e1000_get_i2c_ack(hw);
3125 [ # # ]: 0 : if (status != E1000_SUCCESS)
3126 : 0 : goto fail;
3127 : :
3128 : 0 : e1000_i2c_start(hw);
3129 : :
3130 : : /* Device Address and read indication */
3131 : 0 : status = e1000_clock_out_i2c_byte(hw, (dev_addr | 0x1));
3132 [ # # ]: 0 : if (status != E1000_SUCCESS)
3133 : 0 : goto fail;
3134 : :
3135 : 0 : status = e1000_get_i2c_ack(hw);
3136 [ # # ]: 0 : if (status != E1000_SUCCESS)
3137 : 0 : goto fail;
3138 : :
3139 : 0 : e1000_clock_in_i2c_byte(hw, data);
3140 : :
3141 : 0 : status = e1000_clock_out_i2c_bit(hw, nack);
3142 [ # # ]: 0 : if (status != E1000_SUCCESS)
3143 : 0 : goto fail;
3144 : :
3145 : 0 : e1000_i2c_stop(hw);
3146 : 0 : break;
3147 : :
3148 : 0 : fail:
3149 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3150 : 0 : msec_delay(100);
3151 : 0 : e1000_i2c_bus_clear(hw);
3152 : 0 : retry++;
3153 [ # # ]: 0 : if (retry < max_retry)
3154 : 0 : DEBUGOUT("I2C byte read error - Retrying.\n");
3155 : : else
3156 : 0 : DEBUGOUT("I2C byte read error.\n");
3157 : :
3158 [ # # ]: 0 : } while (retry < max_retry);
3159 : :
3160 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3161 : :
3162 : 0 : read_byte_out:
3163 : :
3164 : 0 : return status;
3165 : : }
3166 : :
3167 : : /**
3168 : : * e1000_write_i2c_byte_generic - Writes 8 bit word over I2C
3169 : : * @hw: pointer to hardware structure
3170 : : * @byte_offset: byte offset to write
3171 : : * @dev_addr: device address
3172 : : * @data: value to write
3173 : : *
3174 : : * Performs byte write operation over I2C interface at
3175 : : * a specified device address.
3176 : : **/
3177 : 0 : s32 e1000_write_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3178 : : u8 dev_addr, u8 data)
3179 : : {
3180 : : s32 status = E1000_SUCCESS;
3181 : : u32 max_retry = 1;
3182 : : u32 retry = 0;
3183 : : u16 swfw_mask = 0;
3184 : :
3185 : 0 : DEBUGFUNC("e1000_write_i2c_byte_generic");
3186 : :
3187 : : swfw_mask = E1000_SWFW_PHY0_SM;
3188 : :
3189 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != E1000_SUCCESS) {
3190 : : status = E1000_ERR_SWFW_SYNC;
3191 : 0 : goto write_byte_out;
3192 : : }
3193 : :
3194 : : do {
3195 : 0 : e1000_i2c_start(hw);
3196 : :
3197 : 0 : status = e1000_clock_out_i2c_byte(hw, dev_addr);
3198 [ # # ]: 0 : if (status != E1000_SUCCESS)
3199 : 0 : goto fail;
3200 : :
3201 : 0 : status = e1000_get_i2c_ack(hw);
3202 [ # # ]: 0 : if (status != E1000_SUCCESS)
3203 : 0 : goto fail;
3204 : :
3205 : 0 : status = e1000_clock_out_i2c_byte(hw, byte_offset);
3206 [ # # ]: 0 : if (status != E1000_SUCCESS)
3207 : 0 : goto fail;
3208 : :
3209 : 0 : status = e1000_get_i2c_ack(hw);
3210 [ # # ]: 0 : if (status != E1000_SUCCESS)
3211 : 0 : goto fail;
3212 : :
3213 : 0 : status = e1000_clock_out_i2c_byte(hw, data);
3214 [ # # ]: 0 : if (status != E1000_SUCCESS)
3215 : 0 : goto fail;
3216 : :
3217 : 0 : status = e1000_get_i2c_ack(hw);
3218 [ # # ]: 0 : if (status != E1000_SUCCESS)
3219 : 0 : goto fail;
3220 : :
3221 : 0 : e1000_i2c_stop(hw);
3222 : 0 : break;
3223 : :
3224 : 0 : fail:
3225 : 0 : e1000_i2c_bus_clear(hw);
3226 : : retry++;
3227 : : if (retry < max_retry)
3228 : : DEBUGOUT("I2C byte write error - Retrying.\n");
3229 : : else
3230 : 0 : DEBUGOUT("I2C byte write error.\n");
3231 : : } while (retry < max_retry);
3232 : :
3233 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3234 : :
3235 : 0 : write_byte_out:
3236 : :
3237 : 0 : return status;
3238 : : }
3239 : :
3240 : : /**
3241 : : * e1000_i2c_start - Sets I2C start condition
3242 : : * @hw: pointer to hardware structure
3243 : : *
3244 : : * Sets I2C start condition (High -> Low on SDA while SCL is High)
3245 : : **/
3246 : 0 : STATIC void e1000_i2c_start(struct e1000_hw *hw)
3247 : : {
3248 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3249 : :
3250 : 0 : DEBUGFUNC("e1000_i2c_start");
3251 : :
3252 : : /* Start condition must begin with data and clock high */
3253 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3254 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3255 : :
3256 : : /* Setup time for start condition (4.7us) */
3257 : 0 : usec_delay(E1000_I2C_T_SU_STA);
3258 : :
3259 : 0 : e1000_set_i2c_data(hw, &i2cctl, 0);
3260 : :
3261 : : /* Hold time for start condition (4us) */
3262 : 0 : usec_delay(E1000_I2C_T_HD_STA);
3263 : :
3264 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3265 : :
3266 : : /* Minimum low period of clock is 4.7 us */
3267 : 0 : usec_delay(E1000_I2C_T_LOW);
3268 : :
3269 : 0 : }
3270 : :
3271 : : /**
3272 : : * e1000_i2c_stop - Sets I2C stop condition
3273 : : * @hw: pointer to hardware structure
3274 : : *
3275 : : * Sets I2C stop condition (Low -> High on SDA while SCL is High)
3276 : : **/
3277 : 0 : STATIC void e1000_i2c_stop(struct e1000_hw *hw)
3278 : : {
3279 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3280 : :
3281 : 0 : DEBUGFUNC("e1000_i2c_stop");
3282 : :
3283 : : /* Stop condition must begin with data low and clock high */
3284 : 0 : e1000_set_i2c_data(hw, &i2cctl, 0);
3285 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3286 : :
3287 : : /* Setup time for stop condition (4us) */
3288 : 0 : usec_delay(E1000_I2C_T_SU_STO);
3289 : :
3290 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3291 : :
3292 : : /* bus free time between stop and start (4.7us)*/
3293 : 0 : usec_delay(E1000_I2C_T_BUF);
3294 : 0 : }
3295 : :
3296 : : /**
3297 : : * e1000_clock_in_i2c_byte - Clocks in one byte via I2C
3298 : : * @hw: pointer to hardware structure
3299 : : * @data: data byte to clock in
3300 : : *
3301 : : * Clocks in one byte data via I2C data/clock
3302 : : **/
3303 : 0 : STATIC void e1000_clock_in_i2c_byte(struct e1000_hw *hw, u8 *data)
3304 : : {
3305 : : s32 i;
3306 : 0 : bool bit = 0;
3307 : :
3308 : 0 : DEBUGFUNC("e1000_clock_in_i2c_byte");
3309 : :
3310 : 0 : *data = 0;
3311 [ # # ]: 0 : for (i = 7; i >= 0; i--) {
3312 : 0 : e1000_clock_in_i2c_bit(hw, &bit);
3313 : 0 : *data |= bit << i;
3314 : : }
3315 : 0 : }
3316 : :
3317 : : /**
3318 : : * e1000_clock_out_i2c_byte - Clocks out one byte via I2C
3319 : : * @hw: pointer to hardware structure
3320 : : * @data: data byte clocked out
3321 : : *
3322 : : * Clocks out one byte data via I2C data/clock
3323 : : **/
3324 : 0 : STATIC s32 e1000_clock_out_i2c_byte(struct e1000_hw *hw, u8 data)
3325 : : {
3326 : : s32 status = E1000_SUCCESS;
3327 : : s32 i;
3328 : : u32 i2cctl;
3329 : : bool bit = 0;
3330 : :
3331 : 0 : DEBUGFUNC("e1000_clock_out_i2c_byte");
3332 : :
3333 [ # # ]: 0 : for (i = 7; i >= 0; i--) {
3334 : 0 : bit = (data >> i) & 0x1;
3335 : 0 : status = e1000_clock_out_i2c_bit(hw, bit);
3336 : :
3337 [ # # ]: 0 : if (status != E1000_SUCCESS)
3338 : : break;
3339 : : }
3340 : :
3341 : : /* Release SDA line (set high) */
3342 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3343 : :
3344 : 0 : i2cctl |= E1000_I2C_DATA_OE_N;
3345 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
3346 : 0 : E1000_WRITE_FLUSH(hw);
3347 : :
3348 : 0 : return status;
3349 : : }
3350 : :
3351 : : /**
3352 : : * e1000_get_i2c_ack - Polls for I2C ACK
3353 : : * @hw: pointer to hardware structure
3354 : : *
3355 : : * Clocks in/out one bit via I2C data/clock
3356 : : **/
3357 : 0 : STATIC s32 e1000_get_i2c_ack(struct e1000_hw *hw)
3358 : : {
3359 : : s32 status = E1000_SUCCESS;
3360 : : u32 i = 0;
3361 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3362 : : u32 timeout = 10;
3363 : : bool ack = true;
3364 : :
3365 : 0 : DEBUGFUNC("e1000_get_i2c_ack");
3366 : :
3367 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3368 : :
3369 : : /* Minimum high period of clock is 4us */
3370 : 0 : usec_delay(E1000_I2C_T_HIGH);
3371 : :
3372 : : /* Wait until SCL returns high */
3373 [ # # ]: 0 : for (i = 0; i < timeout; i++) {
3374 : 0 : usec_delay(1);
3375 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3376 [ # # ]: 0 : if (i2cctl & E1000_I2C_CLK_IN)
3377 : : break;
3378 : : }
3379 [ # # ]: 0 : if (!(i2cctl & E1000_I2C_CLK_IN))
3380 : : return E1000_ERR_I2C;
3381 : :
3382 : 0 : ack = e1000_get_i2c_data(&i2cctl);
3383 [ # # ]: 0 : if (ack) {
3384 : 0 : DEBUGOUT("I2C ack was not received.\n");
3385 : : status = E1000_ERR_I2C;
3386 : : }
3387 : :
3388 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3389 : :
3390 : : /* Minimum low period of clock is 4.7 us */
3391 : 0 : usec_delay(E1000_I2C_T_LOW);
3392 : :
3393 : 0 : return status;
3394 : : }
3395 : :
3396 : : /**
3397 : : * e1000_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
3398 : : * @hw: pointer to hardware structure
3399 : : * @data: read data value
3400 : : *
3401 : : * Clocks in one bit via I2C data/clock
3402 : : **/
3403 : 0 : STATIC void e1000_clock_in_i2c_bit(struct e1000_hw *hw, bool *data)
3404 : : {
3405 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3406 : :
3407 : 0 : DEBUGFUNC("e1000_clock_in_i2c_bit");
3408 : :
3409 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3410 : :
3411 : : /* Minimum high period of clock is 4us */
3412 : 0 : usec_delay(E1000_I2C_T_HIGH);
3413 : :
3414 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3415 : 0 : *data = e1000_get_i2c_data(&i2cctl);
3416 : :
3417 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3418 : :
3419 : : /* Minimum low period of clock is 4.7 us */
3420 : 0 : usec_delay(E1000_I2C_T_LOW);
3421 : 0 : }
3422 : :
3423 : : /**
3424 : : * e1000_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
3425 : : * @hw: pointer to hardware structure
3426 : : * @data: data value to write
3427 : : *
3428 : : * Clocks out one bit via I2C data/clock
3429 : : **/
3430 : 0 : STATIC s32 e1000_clock_out_i2c_bit(struct e1000_hw *hw, bool data)
3431 : : {
3432 : : s32 status;
3433 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3434 : :
3435 : 0 : DEBUGFUNC("e1000_clock_out_i2c_bit");
3436 : :
3437 : 0 : status = e1000_set_i2c_data(hw, &i2cctl, data);
3438 [ # # ]: 0 : if (status == E1000_SUCCESS) {
3439 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3440 : :
3441 : : /* Minimum high period of clock is 4us */
3442 : 0 : usec_delay(E1000_I2C_T_HIGH);
3443 : :
3444 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3445 : :
3446 : : /* Minimum low period of clock is 4.7 us.
3447 : : * This also takes care of the data hold time.
3448 : : */
3449 : 0 : usec_delay(E1000_I2C_T_LOW);
3450 : : } else {
3451 : : status = E1000_ERR_I2C;
3452 : 0 : DEBUGOUT1("I2C data was not set to %X\n", data);
3453 : : }
3454 : :
3455 : 0 : return status;
3456 : : }
3457 : : /**
3458 : : * e1000_raise_i2c_clk - Raises the I2C SCL clock
3459 : : * @hw: pointer to hardware structure
3460 : : * @i2cctl: Current value of I2CCTL register
3461 : : *
3462 : : * Raises the I2C clock line '0'->'1'
3463 : : **/
3464 : 0 : STATIC void e1000_raise_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3465 : : {
3466 : 0 : DEBUGFUNC("e1000_raise_i2c_clk");
3467 : :
3468 : 0 : *i2cctl |= E1000_I2C_CLK_OUT;
3469 : 0 : *i2cctl &= ~E1000_I2C_CLK_OE_N;
3470 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3471 : 0 : E1000_WRITE_FLUSH(hw);
3472 : :
3473 : : /* SCL rise time (1000ns) */
3474 : 0 : usec_delay(E1000_I2C_T_RISE);
3475 : 0 : }
3476 : :
3477 : : /**
3478 : : * e1000_lower_i2c_clk - Lowers the I2C SCL clock
3479 : : * @hw: pointer to hardware structure
3480 : : * @i2cctl: Current value of I2CCTL register
3481 : : *
3482 : : * Lowers the I2C clock line '1'->'0'
3483 : : **/
3484 : 0 : STATIC void e1000_lower_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3485 : : {
3486 : :
3487 : 0 : DEBUGFUNC("e1000_lower_i2c_clk");
3488 : :
3489 : 0 : *i2cctl &= ~E1000_I2C_CLK_OUT;
3490 : 0 : *i2cctl &= ~E1000_I2C_CLK_OE_N;
3491 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3492 : 0 : E1000_WRITE_FLUSH(hw);
3493 : :
3494 : : /* SCL fall time (300ns) */
3495 : 0 : usec_delay(E1000_I2C_T_FALL);
3496 : 0 : }
3497 : :
3498 : : /**
3499 : : * e1000_set_i2c_data - Sets the I2C data bit
3500 : : * @hw: pointer to hardware structure
3501 : : * @i2cctl: Current value of I2CCTL register
3502 : : * @data: I2C data value (0 or 1) to set
3503 : : *
3504 : : * Sets the I2C data bit
3505 : : **/
3506 : 0 : STATIC s32 e1000_set_i2c_data(struct e1000_hw *hw, u32 *i2cctl, bool data)
3507 : : {
3508 : : s32 status = E1000_SUCCESS;
3509 : :
3510 : 0 : DEBUGFUNC("e1000_set_i2c_data");
3511 : :
3512 [ # # ]: 0 : if (data)
3513 : 0 : *i2cctl |= E1000_I2C_DATA_OUT;
3514 : : else
3515 : 0 : *i2cctl &= ~E1000_I2C_DATA_OUT;
3516 : :
3517 : 0 : *i2cctl &= ~E1000_I2C_DATA_OE_N;
3518 : 0 : *i2cctl |= E1000_I2C_CLK_OE_N;
3519 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3520 : 0 : E1000_WRITE_FLUSH(hw);
3521 : :
3522 : : /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
3523 : 0 : usec_delay(E1000_I2C_T_RISE + E1000_I2C_T_FALL + E1000_I2C_T_SU_DATA);
3524 : :
3525 : 0 : *i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3526 [ # # ]: 0 : if (data != e1000_get_i2c_data(i2cctl)) {
3527 : : status = E1000_ERR_I2C;
3528 : 0 : DEBUGOUT1("Error - I2C data was not set to %X.\n", data);
3529 : : }
3530 : :
3531 : 0 : return status;
3532 : : }
3533 : :
3534 : : /**
3535 : : * e1000_get_i2c_data - Reads the I2C SDA data bit
3536 : : * @i2cctl: Current value of I2CCTL register
3537 : : *
3538 : : * Returns the I2C data bit value
3539 : : **/
3540 : 0 : STATIC bool e1000_get_i2c_data(u32 *i2cctl)
3541 : : {
3542 : : bool data;
3543 : :
3544 : 0 : DEBUGFUNC("e1000_get_i2c_data");
3545 : :
3546 [ # # ]: 0 : if (*i2cctl & E1000_I2C_DATA_IN)
3547 : : data = 1;
3548 : : else
3549 : : data = 0;
3550 : :
3551 : 0 : return data;
3552 : : }
3553 : :
3554 : : /**
3555 : : * e1000_i2c_bus_clear - Clears the I2C bus
3556 : : * @hw: pointer to hardware structure
3557 : : *
3558 : : * Clears the I2C bus by sending nine clock pulses.
3559 : : * Used when data line is stuck low.
3560 : : **/
3561 : 0 : void e1000_i2c_bus_clear(struct e1000_hw *hw)
3562 : : {
3563 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3564 : : u32 i;
3565 : :
3566 : 0 : DEBUGFUNC("e1000_i2c_bus_clear");
3567 : :
3568 : 0 : e1000_i2c_start(hw);
3569 : :
3570 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3571 : :
3572 [ # # ]: 0 : for (i = 0; i < 9; i++) {
3573 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3574 : :
3575 : : /* Min high period of clock is 4us */
3576 : 0 : usec_delay(E1000_I2C_T_HIGH);
3577 : :
3578 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3579 : :
3580 : : /* Min low period of clock is 4.7us*/
3581 : 0 : usec_delay(E1000_I2C_T_LOW);
3582 : : }
3583 : :
3584 : 0 : e1000_i2c_start(hw);
3585 : :
3586 : : /* Put the i2c bus back to default state */
3587 : 0 : e1000_i2c_stop(hw);
3588 : 0 : }
3589 : :
|