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 : : case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
1726 : : /* read media type from SFP EEPROM */
1727 : 0 : ret_val = e1000_set_sfp_media_type_82575(hw);
1728 [ # # ]: 0 : if ((ret_val != E1000_SUCCESS) ||
1729 [ # # ]: 0 : (hw->phy.media_type == e1000_media_type_unknown)) {
1730 : : /*
1731 : : * If media type was not identified then return media
1732 : : * type defined by the CTRL_EXT settings.
1733 : : */
1734 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1735 : :
1736 [ # # ]: 0 : if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
1737 : 0 : hw->phy.media_type = e1000_media_type_copper;
1738 : 0 : dev_spec->sgmii_active = true;
1739 : : }
1740 : :
1741 : : break;
1742 : : }
1743 : :
1744 : : /* do not change link mode for 100BaseFX */
1745 [ # # ]: 0 : if (dev_spec->eth_flags.e100_base_fx)
1746 : : break;
1747 : :
1748 : : /* change current link mode setting */
1749 : 0 : ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
1750 : :
1751 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper)
1752 : 0 : ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
1753 : : else
1754 : 0 : ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1755 : :
1756 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1757 : :
1758 : : break;
1759 : : }
1760 : :
1761 : 0 : return ret_val;
1762 : : }
1763 : :
1764 : : /**
1765 : : * e1000_set_sfp_media_type_82575 - derives SFP module media type.
1766 : : * @hw: pointer to the HW structure
1767 : : *
1768 : : * The media type is chosen based on SFP module.
1769 : : * compatibility flags retrieved from SFP ID EEPROM.
1770 : : **/
1771 : 0 : STATIC s32 e1000_set_sfp_media_type_82575(struct e1000_hw *hw)
1772 : : {
1773 : : s32 ret_val = E1000_ERR_CONFIG;
1774 : : u32 ctrl_ext = 0;
1775 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1776 : 0 : struct sfp_e1000_flags *eth_flags = &dev_spec->eth_flags;
1777 : 0 : u8 tranceiver_type = 0;
1778 : : s32 timeout = 3;
1779 : :
1780 : : /* Turn I2C interface ON and power on sfp cage */
1781 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1782 : 0 : ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1783 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
1784 : :
1785 : 0 : E1000_WRITE_FLUSH(hw);
1786 : :
1787 : : /* Read SFP module data */
1788 [ # # ]: 0 : while (timeout) {
1789 : 0 : ret_val = e1000_read_sfp_data_byte(hw,
1790 : : E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
1791 : : &tranceiver_type);
1792 [ # # ]: 0 : if (ret_val == E1000_SUCCESS)
1793 : : break;
1794 : 0 : msec_delay(100);
1795 : 0 : timeout--;
1796 : : }
1797 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
1798 : 0 : goto out;
1799 : :
1800 : 0 : ret_val = e1000_read_sfp_data_byte(hw,
1801 : : E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
1802 : : (u8 *)eth_flags);
1803 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
1804 : 0 : goto out;
1805 : :
1806 : : /* Check if there is some SFP module plugged and powered */
1807 [ # # ]: 0 : if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
1808 : : (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
1809 : 0 : dev_spec->module_plugged = true;
1810 [ # # ]: 0 : if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
1811 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1812 [ # # ]: 0 : } else if (eth_flags->e100_base_fx) {
1813 : 0 : dev_spec->sgmii_active = true;
1814 : 0 : hw->phy.media_type = e1000_media_type_internal_serdes;
1815 [ # # ]: 0 : } else if (eth_flags->e1000_base_t) {
1816 : 0 : dev_spec->sgmii_active = true;
1817 : 0 : hw->phy.media_type = e1000_media_type_copper;
1818 : : } else {
1819 : 0 : hw->phy.media_type = e1000_media_type_unknown;
1820 : 0 : DEBUGOUT("PHY module has not been recognized\n");
1821 : 0 : goto out;
1822 : : }
1823 : : } else {
1824 : 0 : hw->phy.media_type = e1000_media_type_unknown;
1825 : : }
1826 : : ret_val = E1000_SUCCESS;
1827 : 0 : out:
1828 : : /* Restore I2C interface setting */
1829 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1830 : 0 : return ret_val;
1831 : : }
1832 : :
1833 : : /**
1834 : : * e1000_valid_led_default_82575 - Verify a valid default LED config
1835 : : * @hw: pointer to the HW structure
1836 : : * @data: pointer to the NVM (EEPROM)
1837 : : *
1838 : : * Read the EEPROM for the current default LED configuration. If the
1839 : : * LED configuration is not valid, set to a valid LED configuration.
1840 : : **/
1841 : 0 : STATIC s32 e1000_valid_led_default_82575(struct e1000_hw *hw, u16 *data)
1842 : : {
1843 : : s32 ret_val;
1844 : :
1845 : 0 : DEBUGFUNC("e1000_valid_led_default_82575");
1846 : :
1847 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1848 [ # # ]: 0 : if (ret_val) {
1849 : 0 : DEBUGOUT("NVM Read Error\n");
1850 : 0 : goto out;
1851 : : }
1852 : :
1853 [ # # ]: 0 : if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1854 [ # # ]: 0 : switch (hw->phy.media_type) {
1855 : 0 : case e1000_media_type_internal_serdes:
1856 : 0 : *data = ID_LED_DEFAULT_82575_SERDES;
1857 : 0 : break;
1858 : 0 : case e1000_media_type_copper:
1859 : : default:
1860 : 0 : *data = ID_LED_DEFAULT;
1861 : 0 : break;
1862 : : }
1863 : : }
1864 : 0 : out:
1865 : 0 : return ret_val;
1866 : : }
1867 : :
1868 : : /**
1869 : : * e1000_sgmii_active_82575 - Return sgmii state
1870 : : * @hw: pointer to the HW structure
1871 : : *
1872 : : * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1873 : : * which can be enabled for use in the embedded applications. Simply
1874 : : * return the current state of the sgmii interface.
1875 : : **/
1876 : : STATIC bool e1000_sgmii_active_82575(struct e1000_hw *hw)
1877 : : {
1878 : : struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1879 [ # # # # : 0 : return dev_spec->sgmii_active;
# # # # #
# # # # #
# # ]
1880 : : }
1881 : :
1882 : : /**
1883 : : * e1000_reset_init_script_82575 - Inits HW defaults after reset
1884 : : * @hw: pointer to the HW structure
1885 : : *
1886 : : * Inits recommended HW defaults after a reset when there is no EEPROM
1887 : : * detected. This is only for the 82575.
1888 : : **/
1889 : 0 : s32 e1000_reset_init_script_82575(struct e1000_hw *hw)
1890 : : {
1891 : 0 : DEBUGFUNC("e1000_reset_init_script_82575");
1892 : :
1893 [ # # ]: 0 : if (hw->mac.type == e1000_82575) {
1894 : 0 : DEBUGOUT("Running reset init script for 82575\n");
1895 : : /* SerDes configuration via SERDESCTRL */
1896 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x00, 0x0C);
1897 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x01, 0x78);
1898 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x1B, 0x23);
1899 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x23, 0x15);
1900 : :
1901 : : /* CCM configuration via CCMCTL register */
1902 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x14, 0x00);
1903 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x10, 0x00);
1904 : :
1905 : : /* PCIe lanes configuration */
1906 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x00, 0xEC);
1907 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x61, 0xDF);
1908 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x34, 0x05);
1909 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x2F, 0x81);
1910 : :
1911 : : /* PCIe PLL Configuration */
1912 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x02, 0x47);
1913 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x14, 0x00);
1914 : 0 : e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x10, 0x00);
1915 : : }
1916 : :
1917 : 0 : return E1000_SUCCESS;
1918 : : }
1919 : :
1920 : : /**
1921 : : * e1000_read_mac_addr_82575 - Read device MAC address
1922 : : * @hw: pointer to the HW structure
1923 : : **/
1924 : 0 : STATIC s32 e1000_read_mac_addr_82575(struct e1000_hw *hw)
1925 : : {
1926 : : s32 ret_val;
1927 : :
1928 : 0 : DEBUGFUNC("e1000_read_mac_addr_82575");
1929 : :
1930 : : /*
1931 : : * If there's an alternate MAC address place it in RAR0
1932 : : * so that it will override the Si installed default perm
1933 : : * address.
1934 : : */
1935 : 0 : ret_val = e1000_check_alt_mac_addr_generic(hw);
1936 [ # # ]: 0 : if (ret_val)
1937 : 0 : goto out;
1938 : :
1939 : 0 : ret_val = e1000_read_mac_addr_generic(hw);
1940 : :
1941 : 0 : out:
1942 : 0 : return ret_val;
1943 : : }
1944 : :
1945 : : /**
1946 : : * e1000_config_collision_dist_82575 - Configure collision distance
1947 : : * @hw: pointer to the HW structure
1948 : : *
1949 : : * Configures the collision distance to the default value and is used
1950 : : * during link setup.
1951 : : **/
1952 : 0 : STATIC void e1000_config_collision_dist_82575(struct e1000_hw *hw)
1953 : : {
1954 : : u32 tctl_ext;
1955 : :
1956 : 0 : DEBUGFUNC("e1000_config_collision_dist_82575");
1957 : :
1958 : 0 : tctl_ext = E1000_READ_REG(hw, E1000_TCTL_EXT);
1959 : :
1960 : 0 : tctl_ext &= ~E1000_TCTL_EXT_COLD;
1961 : 0 : tctl_ext |= E1000_COLLISION_DISTANCE << E1000_TCTL_EXT_COLD_SHIFT;
1962 : :
1963 : 0 : E1000_WRITE_REG(hw, E1000_TCTL_EXT, tctl_ext);
1964 : 0 : E1000_WRITE_FLUSH(hw);
1965 : 0 : }
1966 : :
1967 : : /**
1968 : : * e1000_clear_hw_cntrs_82575 - Clear device specific hardware counters
1969 : : * @hw: pointer to the HW structure
1970 : : *
1971 : : * Clears the hardware counters by reading the counter registers.
1972 : : **/
1973 : 0 : STATIC void e1000_clear_hw_cntrs_82575(struct e1000_hw *hw)
1974 : : {
1975 : 0 : DEBUGFUNC("e1000_clear_hw_cntrs_82575");
1976 : :
1977 : 0 : e1000_clear_hw_cntrs_base_generic(hw);
1978 : :
1979 : 0 : E1000_READ_REG(hw, E1000_PRC64);
1980 : 0 : E1000_READ_REG(hw, E1000_PRC127);
1981 : 0 : E1000_READ_REG(hw, E1000_PRC255);
1982 : 0 : E1000_READ_REG(hw, E1000_PRC511);
1983 : 0 : E1000_READ_REG(hw, E1000_PRC1023);
1984 : 0 : E1000_READ_REG(hw, E1000_PRC1522);
1985 : 0 : E1000_READ_REG(hw, E1000_PTC64);
1986 : 0 : E1000_READ_REG(hw, E1000_PTC127);
1987 : 0 : E1000_READ_REG(hw, E1000_PTC255);
1988 : 0 : E1000_READ_REG(hw, E1000_PTC511);
1989 : 0 : E1000_READ_REG(hw, E1000_PTC1023);
1990 : 0 : E1000_READ_REG(hw, E1000_PTC1522);
1991 : :
1992 : 0 : E1000_READ_REG(hw, E1000_ALGNERRC);
1993 : 0 : E1000_READ_REG(hw, E1000_RXERRC);
1994 : 0 : E1000_READ_REG(hw, E1000_TNCRS);
1995 : 0 : E1000_READ_REG(hw, E1000_CEXTERR);
1996 : 0 : E1000_READ_REG(hw, E1000_TSCTC);
1997 : 0 : E1000_READ_REG(hw, E1000_TSCTFC);
1998 : :
1999 : 0 : E1000_READ_REG(hw, E1000_MGTPRC);
2000 : 0 : E1000_READ_REG(hw, E1000_MGTPDC);
2001 : 0 : E1000_READ_REG(hw, E1000_MGTPTC);
2002 : :
2003 : 0 : E1000_READ_REG(hw, E1000_IAC);
2004 : 0 : E1000_READ_REG(hw, E1000_ICRXOC);
2005 : :
2006 : 0 : E1000_READ_REG(hw, E1000_ICRXPTC);
2007 : 0 : E1000_READ_REG(hw, E1000_ICRXATC);
2008 : 0 : E1000_READ_REG(hw, E1000_ICTXPTC);
2009 : 0 : E1000_READ_REG(hw, E1000_ICTXATC);
2010 : 0 : E1000_READ_REG(hw, E1000_ICTXQEC);
2011 : 0 : E1000_READ_REG(hw, E1000_ICTXQMTC);
2012 : 0 : E1000_READ_REG(hw, E1000_ICRXDMTC);
2013 : :
2014 : 0 : E1000_READ_REG(hw, E1000_CBTMPC);
2015 : 0 : E1000_READ_REG(hw, E1000_HTDPMC);
2016 : 0 : E1000_READ_REG(hw, E1000_CBRMPC);
2017 : 0 : E1000_READ_REG(hw, E1000_RPTHC);
2018 : 0 : E1000_READ_REG(hw, E1000_HGPTC);
2019 : 0 : E1000_READ_REG(hw, E1000_HTCBDPC);
2020 : 0 : E1000_READ_REG(hw, E1000_HGORCL);
2021 : 0 : E1000_READ_REG(hw, E1000_HGORCH);
2022 : 0 : E1000_READ_REG(hw, E1000_HGOTCL);
2023 : 0 : E1000_READ_REG(hw, E1000_HGOTCH);
2024 : 0 : E1000_READ_REG(hw, E1000_LENERRS);
2025 : :
2026 : : /* This register should not be read in copper configurations */
2027 [ # # # # ]: 0 : if ((hw->phy.media_type == e1000_media_type_internal_serdes) ||
2028 : : e1000_sgmii_active_82575(hw))
2029 : 0 : E1000_READ_REG(hw, E1000_SCVPC);
2030 : 0 : }
2031 : :
2032 : : /**
2033 : : * e1000_set_pcie_completion_timeout - set pci-e completion timeout
2034 : : * @hw: pointer to the HW structure
2035 : : *
2036 : : * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2037 : : * however the hardware default for these parts is 500us to 1ms which is less
2038 : : * than the 10ms recommended by the pci-e spec. To address this we need to
2039 : : * increase the value to either 10ms to 200ms for capability version 1 config,
2040 : : * or 16ms to 55ms for version 2.
2041 : : **/
2042 : 0 : STATIC s32 e1000_set_pcie_completion_timeout(struct e1000_hw *hw)
2043 : : {
2044 : 0 : u32 gcr = E1000_READ_REG(hw, E1000_GCR);
2045 : : s32 ret_val = E1000_SUCCESS;
2046 : : u16 pcie_devctl2;
2047 : :
2048 : : /* only take action if timeout value is defaulted to 0 */
2049 [ # # ]: 0 : if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2050 : 0 : goto out;
2051 : :
2052 : : /*
2053 : : * if capababilities version is type 1 we can write the
2054 : : * timeout of 10ms to 200ms through the GCR register
2055 : : */
2056 [ # # ]: 0 : if (!(gcr & E1000_GCR_CAP_VER2)) {
2057 : 0 : gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2058 : 0 : goto out;
2059 : : }
2060 : :
2061 : : /*
2062 : : * for version 2 capabilities we need to write the config space
2063 : : * directly in order to set the completion timeout value for
2064 : : * 16ms to 55ms
2065 : : */
2066 : 0 : ret_val = e1000_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2067 : : &pcie_devctl2);
2068 [ # # ]: 0 : if (ret_val)
2069 : 0 : goto out;
2070 : :
2071 : 0 : pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2072 : :
2073 : 0 : ret_val = e1000_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2074 : : &pcie_devctl2);
2075 : 0 : out:
2076 : : /* disable completion timeout resend */
2077 : 0 : gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2078 : :
2079 : 0 : E1000_WRITE_REG(hw, E1000_GCR, gcr);
2080 : 0 : return ret_val;
2081 : : }
2082 : :
2083 : : /**
2084 : : * e1000_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2085 : : * @hw: pointer to the hardware struct
2086 : : * @enable: state to enter, either enabled or disabled
2087 : : * @pf: Physical Function pool - do not set anti-spoofing for the PF
2088 : : *
2089 : : * enables/disables L2 switch anti-spoofing functionality.
2090 : : **/
2091 : 0 : void e1000_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2092 : : {
2093 : : u32 reg_val, reg_offset;
2094 : :
2095 [ # # # ]: 0 : switch (hw->mac.type) {
2096 : : case e1000_82576:
2097 : : reg_offset = E1000_DTXSWC;
2098 : : break;
2099 : 0 : case e1000_i350:
2100 : : case e1000_i354:
2101 : : reg_offset = E1000_TXSWC;
2102 : 0 : break;
2103 : : default:
2104 : : return;
2105 : : }
2106 : :
2107 : 0 : reg_val = E1000_READ_REG(hw, reg_offset);
2108 [ # # ]: 0 : if (enable) {
2109 : 0 : reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2110 : : E1000_DTXSWC_VLAN_SPOOF_MASK);
2111 : : /* The PF can spoof - it has to in order to
2112 : : * support emulation mode NICs
2113 : : */
2114 : 0 : reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2115 : : } else {
2116 : 0 : reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2117 : : E1000_DTXSWC_VLAN_SPOOF_MASK);
2118 : : }
2119 : 0 : E1000_WRITE_REG(hw, reg_offset, reg_val);
2120 : : }
2121 : :
2122 : : /**
2123 : : * e1000_vmdq_set_loopback_pf - enable or disable vmdq loopback
2124 : : * @hw: pointer to the hardware struct
2125 : : * @enable: state to enter, either enabled or disabled
2126 : : *
2127 : : * enables/disables L2 switch loopback functionality.
2128 : : **/
2129 : 0 : void e1000_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2130 : : {
2131 : : u32 dtxswc;
2132 : :
2133 [ # # # ]: 0 : switch (hw->mac.type) {
2134 : 0 : case e1000_82576:
2135 : 0 : dtxswc = E1000_READ_REG(hw, E1000_DTXSWC);
2136 [ # # ]: 0 : if (enable)
2137 : 0 : dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2138 : : else
2139 : 0 : dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2140 : 0 : E1000_WRITE_REG(hw, E1000_DTXSWC, dtxswc);
2141 : : break;
2142 : 0 : case e1000_i350:
2143 : : case e1000_i354:
2144 : 0 : dtxswc = E1000_READ_REG(hw, E1000_TXSWC);
2145 [ # # ]: 0 : if (enable)
2146 : 0 : dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2147 : : else
2148 : 0 : dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2149 : 0 : E1000_WRITE_REG(hw, E1000_TXSWC, dtxswc);
2150 : : break;
2151 : : default:
2152 : : /* Currently no other hardware supports loopback */
2153 : : break;
2154 : : }
2155 : :
2156 : :
2157 : 0 : }
2158 : :
2159 : : /**
2160 : : * e1000_vmdq_set_replication_pf - enable or disable vmdq replication
2161 : : * @hw: pointer to the hardware struct
2162 : : * @enable: state to enter, either enabled or disabled
2163 : : *
2164 : : * enables/disables replication of packets across multiple pools.
2165 : : **/
2166 : 0 : void e1000_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2167 : : {
2168 : 0 : u32 vt_ctl = E1000_READ_REG(hw, E1000_VT_CTL);
2169 : :
2170 [ # # ]: 0 : if (enable)
2171 : 0 : vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2172 : : else
2173 : 0 : vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2174 : :
2175 : 0 : E1000_WRITE_REG(hw, E1000_VT_CTL, vt_ctl);
2176 : 0 : }
2177 : :
2178 : : /**
2179 : : * e1000_read_phy_reg_82580 - Read 82580 MDI control register
2180 : : * @hw: pointer to the HW structure
2181 : : * @offset: register offset to be read
2182 : : * @data: pointer to the read data
2183 : : *
2184 : : * Reads the MDI control register in the PHY at offset and stores the
2185 : : * information read to data.
2186 : : **/
2187 : 0 : STATIC s32 e1000_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2188 : : {
2189 : : s32 ret_val;
2190 : :
2191 : 0 : DEBUGFUNC("e1000_read_phy_reg_82580");
2192 : :
2193 : 0 : ret_val = hw->phy.ops.acquire(hw);
2194 [ # # ]: 0 : if (ret_val)
2195 : 0 : goto out;
2196 : :
2197 : 0 : ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
2198 : :
2199 : 0 : hw->phy.ops.release(hw);
2200 : :
2201 : 0 : out:
2202 : 0 : return ret_val;
2203 : : }
2204 : :
2205 : : /**
2206 : : * e1000_write_phy_reg_82580 - Write 82580 MDI control register
2207 : : * @hw: pointer to the HW structure
2208 : : * @offset: register offset to write to
2209 : : * @data: data to write to register at offset
2210 : : *
2211 : : * Writes data to MDI control register in the PHY at offset.
2212 : : **/
2213 : 0 : STATIC s32 e1000_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2214 : : {
2215 : : s32 ret_val;
2216 : :
2217 : 0 : DEBUGFUNC("e1000_write_phy_reg_82580");
2218 : :
2219 : 0 : ret_val = hw->phy.ops.acquire(hw);
2220 [ # # ]: 0 : if (ret_val)
2221 : 0 : goto out;
2222 : :
2223 : 0 : ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
2224 : :
2225 : 0 : hw->phy.ops.release(hw);
2226 : :
2227 : 0 : out:
2228 : 0 : return ret_val;
2229 : : }
2230 : :
2231 : : /**
2232 : : * e1000_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2233 : : * @hw: pointer to the HW structure
2234 : : *
2235 : : * This resets the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2236 : : * the values found in the EEPROM. This addresses an issue in which these
2237 : : * bits are not restored from EEPROM after reset.
2238 : : **/
2239 : 0 : STATIC s32 e1000_reset_mdicnfg_82580(struct e1000_hw *hw)
2240 : : {
2241 : : s32 ret_val = E1000_SUCCESS;
2242 : : u32 mdicnfg;
2243 : 0 : u16 nvm_data = 0;
2244 : :
2245 : 0 : DEBUGFUNC("e1000_reset_mdicnfg_82580");
2246 : :
2247 [ # # ]: 0 : if (hw->mac.type != e1000_82580)
2248 : 0 : goto out;
2249 [ # # ]: 0 : if (!e1000_sgmii_active_82575(hw))
2250 : 0 : goto out;
2251 : :
2252 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2253 [ # # ]: 0 : NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2254 : : &nvm_data);
2255 [ # # ]: 0 : if (ret_val) {
2256 : 0 : DEBUGOUT("NVM Read Error\n");
2257 : 0 : goto out;
2258 : : }
2259 : :
2260 : 0 : mdicnfg = E1000_READ_REG(hw, E1000_MDICNFG);
2261 [ # # ]: 0 : if (nvm_data & NVM_WORD24_EXT_MDIO)
2262 : 0 : mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2263 [ # # ]: 0 : if (nvm_data & NVM_WORD24_COM_MDIO)
2264 : 0 : mdicnfg |= E1000_MDICNFG_COM_MDIO;
2265 : 0 : E1000_WRITE_REG(hw, E1000_MDICNFG, mdicnfg);
2266 : 0 : out:
2267 : 0 : return ret_val;
2268 : : }
2269 : :
2270 : : /**
2271 : : * e1000_reset_hw_82580 - Reset hardware
2272 : : * @hw: pointer to the HW structure
2273 : : *
2274 : : * This resets function or entire device (all ports, etc.)
2275 : : * to a known state.
2276 : : **/
2277 : 0 : STATIC s32 e1000_reset_hw_82580(struct e1000_hw *hw)
2278 : : {
2279 : : s32 ret_val = E1000_SUCCESS;
2280 : : /* BH SW mailbox bit in SW_FW_SYNC */
2281 : : u16 swmbsw_mask = E1000_SW_SYNCH_MB;
2282 : : u32 ctrl;
2283 : 0 : bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2284 : :
2285 : 0 : DEBUGFUNC("e1000_reset_hw_82580");
2286 : :
2287 : 0 : hw->dev_spec._82575.global_device_reset = false;
2288 : :
2289 : : /* 82580 does not reliably do global_device_reset due to hw errata */
2290 [ # # ]: 0 : if (hw->mac.type == e1000_82580)
2291 : : global_device_reset = false;
2292 : :
2293 : : /* Get current control state. */
2294 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
2295 : :
2296 : : /*
2297 : : * Prevent the PCI-E bus from sticking if there is no TLP connection
2298 : : * on the last TLP read/write transaction when MAC is reset.
2299 : : */
2300 : 0 : ret_val = e1000_disable_pcie_master_generic(hw);
2301 [ # # ]: 0 : if (ret_val)
2302 : 0 : DEBUGOUT("PCI-E Master disable polling has failed.\n");
2303 : :
2304 : 0 : DEBUGOUT("Masking off all interrupts\n");
2305 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2306 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, 0);
2307 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
2308 : 0 : E1000_WRITE_FLUSH(hw);
2309 : :
2310 : 0 : msec_delay(10);
2311 : :
2312 : : /* Determine whether or not a global dev reset is requested */
2313 [ # # # # ]: 0 : if (global_device_reset && hw->mac.ops.acquire_swfw_sync(hw,
2314 : : swmbsw_mask))
2315 : : global_device_reset = false;
2316 : :
2317 [ # # # # ]: 0 : if (global_device_reset && !(E1000_READ_REG(hw, E1000_STATUS) &
2318 : : E1000_STAT_DEV_RST_SET))
2319 : 0 : ctrl |= E1000_CTRL_DEV_RST;
2320 : : else
2321 : 0 : ctrl |= E1000_CTRL_RST;
2322 : :
2323 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2324 : :
2325 [ # # ]: 0 : switch (hw->device_id) {
2326 : : case E1000_DEV_ID_DH89XXCC_SGMII:
2327 : : break;
2328 : 0 : default:
2329 : 0 : E1000_WRITE_FLUSH(hw);
2330 : : break;
2331 : : }
2332 : :
2333 : : /* Add delay to insure DEV_RST or RST has time to complete */
2334 : 0 : msec_delay(5);
2335 : :
2336 : 0 : ret_val = e1000_get_auto_rd_done_generic(hw);
2337 [ # # ]: 0 : if (ret_val) {
2338 : : /*
2339 : : * When auto config read does not complete, do not
2340 : : * return with an error. This can happen in situations
2341 : : * where there is no eeprom and prevents getting link.
2342 : : */
2343 : 0 : DEBUGOUT("Auto Read Done did not complete\n");
2344 : : }
2345 : :
2346 : : /* clear global device reset status bit */
2347 : 0 : E1000_WRITE_REG(hw, E1000_STATUS, E1000_STAT_DEV_RST_SET);
2348 : :
2349 : : /* Clear any pending interrupt events. */
2350 : 0 : E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2351 : 0 : E1000_READ_REG(hw, E1000_ICR);
2352 : :
2353 : 0 : ret_val = e1000_reset_mdicnfg_82580(hw);
2354 [ # # ]: 0 : if (ret_val)
2355 : 0 : DEBUGOUT("Could not reset MDICNFG based on EEPROM\n");
2356 : :
2357 : : /* Install any alternate MAC address into RAR0 */
2358 : 0 : ret_val = e1000_check_alt_mac_addr_generic(hw);
2359 : :
2360 : : /* Release semaphore */
2361 [ # # ]: 0 : if (global_device_reset)
2362 : 0 : hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
2363 : :
2364 : 0 : return ret_val;
2365 : : }
2366 : :
2367 : : /**
2368 : : * e1000_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual Rx PBA size
2369 : : * @data: data received by reading RXPBS register
2370 : : *
2371 : : * The 82580 uses a table based approach for packet buffer allocation sizes.
2372 : : * This function converts the retrieved value into the correct table value
2373 : : * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2374 : : * 0x0 36 72 144 1 2 4 8 16
2375 : : * 0x8 35 70 140 rsv rsv rsv rsv rsv
2376 : : */
2377 : 0 : u16 e1000_rxpbs_adjust_82580(u32 data)
2378 : : {
2379 : : u16 ret_val = 0;
2380 : :
2381 [ # # ]: 0 : if (data < E1000_82580_RXPBS_TABLE_SIZE)
2382 : 0 : ret_val = e1000_82580_rxpbs_table[data];
2383 : :
2384 : 0 : return ret_val;
2385 : : }
2386 : :
2387 : : /**
2388 : : * e1000_validate_nvm_checksum_with_offset - Validate EEPROM
2389 : : * checksum
2390 : : * @hw: pointer to the HW structure
2391 : : * @offset: offset in words of the checksum protected region
2392 : : *
2393 : : * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2394 : : * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2395 : : **/
2396 : 0 : s32 e1000_validate_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2397 : : {
2398 : : s32 ret_val = E1000_SUCCESS;
2399 : : u16 checksum = 0;
2400 : : u16 i, nvm_data;
2401 : :
2402 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_with_offset");
2403 : :
2404 [ # # ]: 0 : for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2405 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2406 [ # # ]: 0 : if (ret_val) {
2407 : 0 : DEBUGOUT("NVM Read Error\n");
2408 : 0 : goto out;
2409 : : }
2410 : 0 : checksum += nvm_data;
2411 : : }
2412 : :
2413 [ # # ]: 0 : if (checksum != (u16) NVM_SUM) {
2414 : 0 : DEBUGOUT("NVM Checksum Invalid\n");
2415 : : ret_val = -E1000_ERR_NVM;
2416 : 0 : goto out;
2417 : : }
2418 : :
2419 : 0 : out:
2420 : 0 : return ret_val;
2421 : : }
2422 : :
2423 : : /**
2424 : : * e1000_update_nvm_checksum_with_offset - Update EEPROM
2425 : : * checksum
2426 : : * @hw: pointer to the HW structure
2427 : : * @offset: offset in words of the checksum protected region
2428 : : *
2429 : : * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2430 : : * up to the checksum. Then calculates the EEPROM checksum and writes the
2431 : : * value to the EEPROM.
2432 : : **/
2433 : 0 : s32 e1000_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2434 : : {
2435 : : s32 ret_val;
2436 : 0 : u16 checksum = 0;
2437 : : u16 i, nvm_data;
2438 : :
2439 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_with_offset");
2440 : :
2441 [ # # ]: 0 : for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2442 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2443 [ # # ]: 0 : if (ret_val) {
2444 : 0 : DEBUGOUT("NVM Read Error while updating checksum.\n");
2445 : 0 : goto out;
2446 : : }
2447 : 0 : checksum += nvm_data;
2448 : : }
2449 : 0 : checksum = (u16) NVM_SUM - checksum;
2450 : 0 : ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2451 : : &checksum);
2452 [ # # ]: 0 : if (ret_val)
2453 : 0 : DEBUGOUT("NVM Write Error while updating checksum.\n");
2454 : :
2455 : 0 : out:
2456 : 0 : return ret_val;
2457 : : }
2458 : :
2459 : : /**
2460 : : * e1000_validate_nvm_checksum_82580 - Validate EEPROM checksum
2461 : : * @hw: pointer to the HW structure
2462 : : *
2463 : : * Calculates the EEPROM section checksum by reading/adding each word of
2464 : : * the EEPROM and then verifies that the sum of the EEPROM is
2465 : : * equal to 0xBABA.
2466 : : **/
2467 : 0 : STATIC s32 e1000_validate_nvm_checksum_82580(struct e1000_hw *hw)
2468 : : {
2469 : : s32 ret_val;
2470 : : u16 eeprom_regions_count = 1;
2471 : : u16 j, nvm_data;
2472 : : u16 nvm_offset;
2473 : :
2474 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_82580");
2475 : :
2476 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2477 [ # # ]: 0 : if (ret_val) {
2478 : 0 : DEBUGOUT("NVM Read Error\n");
2479 : 0 : goto out;
2480 : : }
2481 : :
2482 [ # # ]: 0 : if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
2483 : : /* if chekcsums compatibility bit is set validate checksums
2484 : : * for all 4 ports. */
2485 : : eeprom_regions_count = 4;
2486 : : }
2487 : :
2488 [ # # ]: 0 : for (j = 0; j < eeprom_regions_count; j++) {
2489 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2490 : 0 : ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2491 : : nvm_offset);
2492 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2493 : 0 : goto out;
2494 : : }
2495 : :
2496 : 0 : out:
2497 : 0 : return ret_val;
2498 : : }
2499 : :
2500 : : /**
2501 : : * e1000_update_nvm_checksum_82580 - Update EEPROM checksum
2502 : : * @hw: pointer to the HW structure
2503 : : *
2504 : : * Updates the EEPROM section checksums for all 4 ports by reading/adding
2505 : : * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2506 : : * checksum and writes the value to the EEPROM.
2507 : : **/
2508 : 0 : STATIC s32 e1000_update_nvm_checksum_82580(struct e1000_hw *hw)
2509 : : {
2510 : : s32 ret_val;
2511 : : u16 j, nvm_data;
2512 : : u16 nvm_offset;
2513 : :
2514 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_82580");
2515 : :
2516 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2517 [ # # ]: 0 : if (ret_val) {
2518 : 0 : DEBUGOUT("NVM Read Error while updating checksum compatibility bit.\n");
2519 : 0 : goto out;
2520 : : }
2521 : :
2522 [ # # ]: 0 : if (!(nvm_data & NVM_COMPATIBILITY_BIT_MASK)) {
2523 : : /* set compatibility bit to validate checksums appropriately */
2524 : 0 : nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2525 : 0 : ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2526 : : &nvm_data);
2527 [ # # ]: 0 : if (ret_val) {
2528 : 0 : DEBUGOUT("NVM Write Error while updating checksum compatibility bit.\n");
2529 : 0 : goto out;
2530 : : }
2531 : : }
2532 : :
2533 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2534 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2535 : 0 : ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2536 [ # # ]: 0 : if (ret_val)
2537 : 0 : goto out;
2538 : : }
2539 : :
2540 : 0 : out:
2541 : 0 : return ret_val;
2542 : : }
2543 : :
2544 : : /**
2545 : : * e1000_validate_nvm_checksum_i350 - Validate EEPROM checksum
2546 : : * @hw: pointer to the HW structure
2547 : : *
2548 : : * Calculates the EEPROM section checksum by reading/adding each word of
2549 : : * the EEPROM and then verifies that the sum of the EEPROM is
2550 : : * equal to 0xBABA.
2551 : : **/
2552 : 0 : STATIC s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw)
2553 : : {
2554 : : s32 ret_val = E1000_SUCCESS;
2555 : : u16 j;
2556 : : u16 nvm_offset;
2557 : :
2558 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_i350");
2559 : :
2560 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2561 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2562 : 0 : ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2563 : : nvm_offset);
2564 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2565 : 0 : goto out;
2566 : : }
2567 : :
2568 : 0 : out:
2569 : 0 : return ret_val;
2570 : : }
2571 : :
2572 : : /**
2573 : : * e1000_update_nvm_checksum_i350 - Update EEPROM checksum
2574 : : * @hw: pointer to the HW structure
2575 : : *
2576 : : * Updates the EEPROM section checksums for all 4 ports by reading/adding
2577 : : * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2578 : : * checksum and writes the value to the EEPROM.
2579 : : **/
2580 : 0 : STATIC s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw)
2581 : : {
2582 : : s32 ret_val = E1000_SUCCESS;
2583 : : u16 j;
2584 : : u16 nvm_offset;
2585 : :
2586 : 0 : DEBUGFUNC("e1000_update_nvm_checksum_i350");
2587 : :
2588 [ # # ]: 0 : for (j = 0; j < 4; j++) {
2589 [ # # ]: 0 : nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2590 : 0 : ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2591 [ # # ]: 0 : if (ret_val != E1000_SUCCESS)
2592 : 0 : goto out;
2593 : : }
2594 : :
2595 : 0 : out:
2596 : 0 : return ret_val;
2597 : : }
2598 : :
2599 : : /**
2600 : : * __e1000_access_emi_reg - Read/write EMI register
2601 : : * @hw: pointer to the HW structure
2602 : : * @address: EMI address to program
2603 : : * @data: pointer to value to read/write from/to the EMI address
2604 : : * @read: boolean flag to indicate read or write
2605 : : **/
2606 : 0 : STATIC s32 __e1000_access_emi_reg(struct e1000_hw *hw, u16 address,
2607 : : u16 *data, bool read)
2608 : : {
2609 : : s32 ret_val;
2610 : :
2611 : 0 : DEBUGFUNC("__e1000_access_emi_reg");
2612 : :
2613 : 0 : ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2614 [ # # ]: 0 : if (ret_val)
2615 : : return ret_val;
2616 : :
2617 [ # # ]: 0 : if (read)
2618 : 0 : ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2619 : : else
2620 : 0 : ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2621 : :
2622 : : return ret_val;
2623 : : }
2624 : :
2625 : : /**
2626 : : * e1000_read_emi_reg - Read Extended Management Interface register
2627 : : * @hw: pointer to the HW structure
2628 : : * @addr: EMI address to program
2629 : : * @data: value to be read from the EMI address
2630 : : **/
2631 : 0 : s32 e1000_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2632 : : {
2633 : 0 : DEBUGFUNC("e1000_read_emi_reg");
2634 : :
2635 : 0 : return __e1000_access_emi_reg(hw, addr, data, true);
2636 : : }
2637 : :
2638 : : /**
2639 : : * e1000_initialize_M88E1512_phy - Initialize M88E1512 PHY
2640 : : * @hw: pointer to the HW structure
2641 : : *
2642 : : * Initialize Marvell 1512 to work correctly with Avoton.
2643 : : **/
2644 : 0 : s32 e1000_initialize_M88E1512_phy(struct e1000_hw *hw)
2645 : : {
2646 : : struct e1000_phy_info *phy = &hw->phy;
2647 : : s32 ret_val = E1000_SUCCESS;
2648 : :
2649 : 0 : DEBUGFUNC("e1000_initialize_M88E1512_phy");
2650 : :
2651 : : /* Check if this is correct PHY. */
2652 [ # # ]: 0 : if (phy->id != M88E1512_E_PHY_ID)
2653 : 0 : goto out;
2654 : :
2655 : : /* Switch to PHY page 0xFF. */
2656 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2657 [ # # ]: 0 : if (ret_val)
2658 : 0 : goto out;
2659 : :
2660 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2661 [ # # ]: 0 : if (ret_val)
2662 : 0 : goto out;
2663 : :
2664 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2665 [ # # ]: 0 : if (ret_val)
2666 : 0 : goto out;
2667 : :
2668 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2669 [ # # ]: 0 : if (ret_val)
2670 : 0 : goto out;
2671 : :
2672 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2673 [ # # ]: 0 : if (ret_val)
2674 : 0 : goto out;
2675 : :
2676 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2677 [ # # ]: 0 : if (ret_val)
2678 : 0 : goto out;
2679 : :
2680 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2681 [ # # ]: 0 : if (ret_val)
2682 : 0 : goto out;
2683 : :
2684 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xCC0C);
2685 [ # # ]: 0 : if (ret_val)
2686 : 0 : goto out;
2687 : :
2688 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2689 [ # # ]: 0 : if (ret_val)
2690 : 0 : goto out;
2691 : :
2692 : : /* Switch to PHY page 0xFB. */
2693 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2694 [ # # ]: 0 : if (ret_val)
2695 : 0 : goto out;
2696 : :
2697 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x000D);
2698 [ # # ]: 0 : if (ret_val)
2699 : 0 : goto out;
2700 : :
2701 : : /* Switch to PHY page 0x12. */
2702 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2703 [ # # ]: 0 : if (ret_val)
2704 : 0 : goto out;
2705 : :
2706 : : /* Change mode to SGMII-to-Copper */
2707 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2708 [ # # ]: 0 : if (ret_val)
2709 : 0 : goto out;
2710 : :
2711 : : /* Return the PHY to page 0. */
2712 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2713 [ # # ]: 0 : if (ret_val)
2714 : 0 : goto out;
2715 : :
2716 : 0 : ret_val = phy->ops.commit(hw);
2717 [ # # ]: 0 : if (ret_val) {
2718 : 0 : DEBUGOUT("Error committing the PHY changes\n");
2719 : 0 : return ret_val;
2720 : : }
2721 : :
2722 : 0 : msec_delay(1000);
2723 : : out:
2724 : : return ret_val;
2725 : : }
2726 : :
2727 : : /**
2728 : : * e1000_initialize_M88E1543_phy - Initialize M88E1543 PHY
2729 : : * @hw: pointer to the HW structure
2730 : : *
2731 : : * Initialize Marvell 1543 to work correctly with Avoton.
2732 : : **/
2733 : 0 : s32 e1000_initialize_M88E1543_phy(struct e1000_hw *hw)
2734 : : {
2735 : : struct e1000_phy_info *phy = &hw->phy;
2736 : : s32 ret_val = E1000_SUCCESS;
2737 : :
2738 : 0 : DEBUGFUNC("e1000_initialize_M88E1543_phy");
2739 : :
2740 : : /* Check if this is correct PHY. */
2741 [ # # ]: 0 : if (phy->id != M88E1543_E_PHY_ID)
2742 : 0 : goto out;
2743 : :
2744 : : /* Switch to PHY page 0xFF. */
2745 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2746 [ # # ]: 0 : if (ret_val)
2747 : 0 : goto out;
2748 : :
2749 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2750 [ # # ]: 0 : if (ret_val)
2751 : 0 : goto out;
2752 : :
2753 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2754 [ # # ]: 0 : if (ret_val)
2755 : 0 : goto out;
2756 : :
2757 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2758 [ # # ]: 0 : if (ret_val)
2759 : 0 : goto out;
2760 : :
2761 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2762 [ # # ]: 0 : if (ret_val)
2763 : 0 : goto out;
2764 : :
2765 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2766 [ # # ]: 0 : if (ret_val)
2767 : 0 : goto out;
2768 : :
2769 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2770 [ # # ]: 0 : if (ret_val)
2771 : 0 : goto out;
2772 : :
2773 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xDC0C);
2774 [ # # ]: 0 : if (ret_val)
2775 : 0 : goto out;
2776 : :
2777 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2778 [ # # ]: 0 : if (ret_val)
2779 : 0 : goto out;
2780 : :
2781 : : /* Switch to PHY page 0xFB. */
2782 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2783 [ # # ]: 0 : if (ret_val)
2784 : 0 : goto out;
2785 : :
2786 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0xC00D);
2787 [ # # ]: 0 : if (ret_val)
2788 : 0 : goto out;
2789 : :
2790 : : /* Switch to PHY page 0x12. */
2791 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2792 [ # # ]: 0 : if (ret_val)
2793 : 0 : goto out;
2794 : :
2795 : : /* Change mode to SGMII-to-Copper */
2796 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2797 [ # # ]: 0 : if (ret_val)
2798 : 0 : goto out;
2799 : :
2800 : : /* Switch to PHY page 1. */
2801 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x1);
2802 [ # # ]: 0 : if (ret_val)
2803 : 0 : goto out;
2804 : :
2805 : : /* Change mode to 1000BASE-X/SGMII and autoneg enable; reset */
2806 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_FIBER_CTRL, 0x9140);
2807 [ # # ]: 0 : if (ret_val)
2808 : 0 : goto out;
2809 : :
2810 : : /* Return the PHY to page 0. */
2811 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2812 [ # # ]: 0 : if (ret_val)
2813 : 0 : goto out;
2814 : :
2815 : 0 : ret_val = phy->ops.commit(hw);
2816 [ # # ]: 0 : if (ret_val) {
2817 : 0 : DEBUGOUT("Error committing the PHY changes\n");
2818 : 0 : return ret_val;
2819 : : }
2820 : :
2821 : 0 : msec_delay(1000);
2822 : : out:
2823 : : return ret_val;
2824 : : }
2825 : :
2826 : : /**
2827 : : * e1000_set_eee_i350 - Enable/disable EEE support
2828 : : * @hw: pointer to the HW structure
2829 : : * @adv1G: boolean flag enabling 1G EEE advertisement
2830 : : * @adv100M: boolean flag enabling 100M EEE advertisement
2831 : : *
2832 : : * Enable/disable EEE based on setting in dev_spec structure.
2833 : : *
2834 : : **/
2835 : 0 : s32 e1000_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
2836 : : {
2837 : : u32 ipcnfg, eeer;
2838 : :
2839 : 0 : DEBUGFUNC("e1000_set_eee_i350");
2840 : :
2841 [ # # ]: 0 : if ((hw->mac.type < e1000_i350) ||
2842 [ # # ]: 0 : (hw->phy.media_type != e1000_media_type_copper))
2843 : 0 : goto out;
2844 : 0 : ipcnfg = E1000_READ_REG(hw, E1000_IPCNFG);
2845 : 0 : eeer = E1000_READ_REG(hw, E1000_EEER);
2846 : :
2847 : : /* enable or disable per user setting */
2848 [ # # ]: 0 : if (!(hw->dev_spec._82575.eee_disable)) {
2849 : 0 : u32 eee_su = E1000_READ_REG(hw, E1000_EEE_SU);
2850 : :
2851 [ # # ]: 0 : if (adv100M)
2852 : 0 : ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
2853 : : else
2854 : 0 : ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
2855 : :
2856 [ # # ]: 0 : if (adv1G)
2857 : 0 : ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
2858 : : else
2859 : 0 : ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
2860 : :
2861 : 0 : eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2862 : : E1000_EEER_LPI_FC);
2863 : :
2864 : : /* This bit should not be set in normal operation. */
2865 [ # # ]: 0 : if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2866 : 0 : DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
2867 : : } else {
2868 : 0 : ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2869 : 0 : eeer &= ~(E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2870 : : E1000_EEER_LPI_FC);
2871 : : }
2872 : 0 : E1000_WRITE_REG(hw, E1000_IPCNFG, ipcnfg);
2873 : 0 : E1000_WRITE_REG(hw, E1000_EEER, eeer);
2874 : 0 : E1000_READ_REG(hw, E1000_IPCNFG);
2875 : 0 : E1000_READ_REG(hw, E1000_EEER);
2876 : 0 : out:
2877 : :
2878 : 0 : return E1000_SUCCESS;
2879 : : }
2880 : :
2881 : : /**
2882 : : * e1000_set_eee_i354 - Enable/disable EEE support
2883 : : * @hw: pointer to the HW structure
2884 : : * @adv1G: boolean flag enabling 1G EEE advertisement
2885 : : * @adv100M: boolean flag enabling 100M EEE advertisement
2886 : : *
2887 : : * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2888 : : *
2889 : : **/
2890 : 0 : s32 e1000_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
2891 : : {
2892 : : struct e1000_phy_info *phy = &hw->phy;
2893 : : s32 ret_val = E1000_SUCCESS;
2894 : : u16 phy_data;
2895 : :
2896 : 0 : DEBUGFUNC("e1000_set_eee_i354");
2897 : :
2898 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_copper) ||
2899 [ # # ]: 0 : ((phy->id != M88E1543_E_PHY_ID) &&
2900 : : (phy->id != M88E1512_E_PHY_ID)))
2901 : 0 : goto out;
2902 : :
2903 [ # # ]: 0 : if (!hw->dev_spec._82575.eee_disable) {
2904 : : /* Switch to PHY page 18. */
2905 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
2906 [ # # ]: 0 : if (ret_val)
2907 : 0 : goto out;
2908 : :
2909 : 0 : ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2910 : : &phy_data);
2911 [ # # ]: 0 : if (ret_val)
2912 : 0 : goto out;
2913 : :
2914 : 0 : phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2915 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2916 : : phy_data);
2917 [ # # ]: 0 : if (ret_val)
2918 : 0 : goto out;
2919 : :
2920 : : /* Return the PHY to page 0. */
2921 : 0 : ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2922 [ # # ]: 0 : if (ret_val)
2923 : 0 : goto out;
2924 : :
2925 : : /* Turn on EEE advertisement. */
2926 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2927 : : E1000_EEE_ADV_DEV_I354,
2928 : : &phy_data);
2929 [ # # ]: 0 : if (ret_val)
2930 : 0 : goto out;
2931 : :
2932 [ # # ]: 0 : if (adv100M)
2933 : 0 : phy_data |= E1000_EEE_ADV_100_SUPPORTED;
2934 : : else
2935 : 0 : phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
2936 : :
2937 [ # # ]: 0 : if (adv1G)
2938 : 0 : phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
2939 : : else
2940 : 0 : phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
2941 : :
2942 : 0 : ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2943 : : E1000_EEE_ADV_DEV_I354,
2944 : : phy_data);
2945 : : } else {
2946 : : /* Turn off EEE advertisement. */
2947 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2948 : : E1000_EEE_ADV_DEV_I354,
2949 : : &phy_data);
2950 [ # # ]: 0 : if (ret_val)
2951 : 0 : goto out;
2952 : :
2953 : 0 : phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2954 : : E1000_EEE_ADV_1000_SUPPORTED);
2955 : 0 : ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2956 : : E1000_EEE_ADV_DEV_I354,
2957 : : phy_data);
2958 : : }
2959 : :
2960 : 0 : out:
2961 : 0 : return ret_val;
2962 : : }
2963 : :
2964 : : /**
2965 : : * e1000_get_eee_status_i354 - Get EEE status
2966 : : * @hw: pointer to the HW structure
2967 : : * @status: EEE status
2968 : : *
2969 : : * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2970 : : * been received.
2971 : : **/
2972 : 0 : s32 e1000_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2973 : : {
2974 : : struct e1000_phy_info *phy = &hw->phy;
2975 : : s32 ret_val = E1000_SUCCESS;
2976 : : u16 phy_data;
2977 : :
2978 : 0 : DEBUGFUNC("e1000_get_eee_status_i354");
2979 : :
2980 : : /* Check if EEE is supported on this device. */
2981 [ # # ]: 0 : if ((hw->phy.media_type != e1000_media_type_copper) ||
2982 [ # # ]: 0 : ((phy->id != M88E1543_E_PHY_ID) &&
2983 : : (phy->id != M88E1512_E_PHY_ID)))
2984 : 0 : goto out;
2985 : :
2986 : 0 : ret_val = e1000_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2987 : : E1000_PCS_STATUS_DEV_I354,
2988 : : &phy_data);
2989 [ # # ]: 0 : if (ret_val)
2990 : 0 : goto out;
2991 : :
2992 : 0 : *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2993 : 0 : E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2994 : :
2995 : 0 : out:
2996 : 0 : return ret_val;
2997 : : }
2998 : :
2999 : : /* Due to a hw errata, if the host tries to configure the VFTA register
3000 : : * while performing queries from the BMC or DMA, then the VFTA in some
3001 : : * cases won't be written.
3002 : : */
3003 : :
3004 : : /**
3005 : : * e1000_clear_vfta_i350 - Clear VLAN filter table
3006 : : * @hw: pointer to the HW structure
3007 : : *
3008 : : * Clears the register array which contains the VLAN filter table by
3009 : : * setting all the values to 0.
3010 : : **/
3011 : 0 : void e1000_clear_vfta_i350(struct e1000_hw *hw)
3012 : : {
3013 : : u32 offset;
3014 : : int i;
3015 : :
3016 : 0 : DEBUGFUNC("e1000_clear_vfta_350");
3017 : :
3018 [ # # ]: 0 : for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
3019 [ # # ]: 0 : for (i = 0; i < 10; i++)
3020 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
3021 : :
3022 : 0 : E1000_WRITE_FLUSH(hw);
3023 : : }
3024 : 0 : }
3025 : :
3026 : : /**
3027 : : * e1000_write_vfta_i350 - Write value to VLAN filter table
3028 : : * @hw: pointer to the HW structure
3029 : : * @offset: register offset in VLAN filter table
3030 : : * @value: register value written to VLAN filter table
3031 : : *
3032 : : * Writes value at the given offset in the register array which stores
3033 : : * the VLAN filter table.
3034 : : **/
3035 : 0 : void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
3036 : : {
3037 : : int i;
3038 : :
3039 : 0 : DEBUGFUNC("e1000_write_vfta_350");
3040 : :
3041 [ # # ]: 0 : for (i = 0; i < 10; i++)
3042 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
3043 : :
3044 : 0 : E1000_WRITE_FLUSH(hw);
3045 : 0 : }
3046 : :
3047 : :
3048 : : /**
3049 : : * e1000_set_i2c_bb - Enable I2C bit-bang
3050 : : * @hw: pointer to the HW structure
3051 : : *
3052 : : * Enable I2C bit-bang interface
3053 : : *
3054 : : **/
3055 : 0 : s32 e1000_set_i2c_bb(struct e1000_hw *hw)
3056 : : {
3057 : : s32 ret_val = E1000_SUCCESS;
3058 : : u32 ctrl_ext, i2cparams;
3059 : :
3060 : 0 : DEBUGFUNC("e1000_set_i2c_bb");
3061 : :
3062 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
3063 : 0 : ctrl_ext |= E1000_CTRL_I2C_ENA;
3064 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
3065 : 0 : E1000_WRITE_FLUSH(hw);
3066 : :
3067 : 0 : i2cparams = E1000_READ_REG(hw, E1000_I2CPARAMS);
3068 : : i2cparams |= E1000_I2CBB_EN;
3069 : : i2cparams |= E1000_I2C_DATA_OE_N;
3070 : 0 : i2cparams |= E1000_I2C_CLK_OE_N;
3071 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cparams);
3072 : 0 : E1000_WRITE_FLUSH(hw);
3073 : :
3074 : 0 : return ret_val;
3075 : : }
3076 : :
3077 : : /**
3078 : : * e1000_read_i2c_byte_generic - Reads 8 bit word over I2C
3079 : : * @hw: pointer to hardware structure
3080 : : * @byte_offset: byte offset to read
3081 : : * @dev_addr: device address
3082 : : * @data: value read
3083 : : *
3084 : : * Performs byte read operation over I2C interface at
3085 : : * a specified device address.
3086 : : **/
3087 : 0 : s32 e1000_read_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3088 : : u8 dev_addr, u8 *data)
3089 : : {
3090 : : s32 status = E1000_SUCCESS;
3091 : : u32 max_retry = 10;
3092 : : u32 retry = 1;
3093 : : u16 swfw_mask = 0;
3094 : :
3095 : : bool nack = true;
3096 : :
3097 : 0 : DEBUGFUNC("e1000_read_i2c_byte_generic");
3098 : :
3099 : : swfw_mask = E1000_SWFW_PHY0_SM;
3100 : :
3101 : : do {
3102 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
3103 : : != E1000_SUCCESS) {
3104 : : status = E1000_ERR_SWFW_SYNC;
3105 : 0 : goto read_byte_out;
3106 : : }
3107 : :
3108 : 0 : e1000_i2c_start(hw);
3109 : :
3110 : : /* Device Address and write indication */
3111 : 0 : status = e1000_clock_out_i2c_byte(hw, dev_addr);
3112 [ # # ]: 0 : if (status != E1000_SUCCESS)
3113 : 0 : goto fail;
3114 : :
3115 : 0 : status = e1000_get_i2c_ack(hw);
3116 [ # # ]: 0 : if (status != E1000_SUCCESS)
3117 : 0 : goto fail;
3118 : :
3119 : 0 : status = e1000_clock_out_i2c_byte(hw, byte_offset);
3120 [ # # ]: 0 : if (status != E1000_SUCCESS)
3121 : 0 : goto fail;
3122 : :
3123 : 0 : status = e1000_get_i2c_ack(hw);
3124 [ # # ]: 0 : if (status != E1000_SUCCESS)
3125 : 0 : goto fail;
3126 : :
3127 : 0 : e1000_i2c_start(hw);
3128 : :
3129 : : /* Device Address and read indication */
3130 : 0 : status = e1000_clock_out_i2c_byte(hw, (dev_addr | 0x1));
3131 [ # # ]: 0 : if (status != E1000_SUCCESS)
3132 : 0 : goto fail;
3133 : :
3134 : 0 : status = e1000_get_i2c_ack(hw);
3135 [ # # ]: 0 : if (status != E1000_SUCCESS)
3136 : 0 : goto fail;
3137 : :
3138 : 0 : e1000_clock_in_i2c_byte(hw, data);
3139 : :
3140 : 0 : status = e1000_clock_out_i2c_bit(hw, nack);
3141 [ # # ]: 0 : if (status != E1000_SUCCESS)
3142 : 0 : goto fail;
3143 : :
3144 : 0 : e1000_i2c_stop(hw);
3145 : 0 : break;
3146 : :
3147 : 0 : fail:
3148 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3149 : 0 : msec_delay(100);
3150 : 0 : e1000_i2c_bus_clear(hw);
3151 : 0 : retry++;
3152 [ # # ]: 0 : if (retry < max_retry)
3153 : 0 : DEBUGOUT("I2C byte read error - Retrying.\n");
3154 : : else
3155 : 0 : DEBUGOUT("I2C byte read error.\n");
3156 : :
3157 [ # # ]: 0 : } while (retry < max_retry);
3158 : :
3159 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3160 : :
3161 : 0 : read_byte_out:
3162 : :
3163 : 0 : return status;
3164 : : }
3165 : :
3166 : : /**
3167 : : * e1000_write_i2c_byte_generic - Writes 8 bit word over I2C
3168 : : * @hw: pointer to hardware structure
3169 : : * @byte_offset: byte offset to write
3170 : : * @dev_addr: device address
3171 : : * @data: value to write
3172 : : *
3173 : : * Performs byte write operation over I2C interface at
3174 : : * a specified device address.
3175 : : **/
3176 : 0 : s32 e1000_write_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3177 : : u8 dev_addr, u8 data)
3178 : : {
3179 : : s32 status = E1000_SUCCESS;
3180 : : u32 max_retry = 1;
3181 : : u32 retry = 0;
3182 : : u16 swfw_mask = 0;
3183 : :
3184 : 0 : DEBUGFUNC("e1000_write_i2c_byte_generic");
3185 : :
3186 : : swfw_mask = E1000_SWFW_PHY0_SM;
3187 : :
3188 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != E1000_SUCCESS) {
3189 : : status = E1000_ERR_SWFW_SYNC;
3190 : 0 : goto write_byte_out;
3191 : : }
3192 : :
3193 : : do {
3194 : 0 : e1000_i2c_start(hw);
3195 : :
3196 : 0 : status = e1000_clock_out_i2c_byte(hw, dev_addr);
3197 [ # # ]: 0 : if (status != E1000_SUCCESS)
3198 : 0 : goto fail;
3199 : :
3200 : 0 : status = e1000_get_i2c_ack(hw);
3201 [ # # ]: 0 : if (status != E1000_SUCCESS)
3202 : 0 : goto fail;
3203 : :
3204 : 0 : status = e1000_clock_out_i2c_byte(hw, byte_offset);
3205 [ # # ]: 0 : if (status != E1000_SUCCESS)
3206 : 0 : goto fail;
3207 : :
3208 : 0 : status = e1000_get_i2c_ack(hw);
3209 [ # # ]: 0 : if (status != E1000_SUCCESS)
3210 : 0 : goto fail;
3211 : :
3212 : 0 : status = e1000_clock_out_i2c_byte(hw, data);
3213 [ # # ]: 0 : if (status != E1000_SUCCESS)
3214 : 0 : goto fail;
3215 : :
3216 : 0 : status = e1000_get_i2c_ack(hw);
3217 [ # # ]: 0 : if (status != E1000_SUCCESS)
3218 : 0 : goto fail;
3219 : :
3220 : 0 : e1000_i2c_stop(hw);
3221 : 0 : break;
3222 : :
3223 : 0 : fail:
3224 : 0 : e1000_i2c_bus_clear(hw);
3225 : : retry++;
3226 : : if (retry < max_retry)
3227 : : DEBUGOUT("I2C byte write error - Retrying.\n");
3228 : : else
3229 : 0 : DEBUGOUT("I2C byte write error.\n");
3230 : : } while (retry < max_retry);
3231 : :
3232 : 0 : hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3233 : :
3234 : 0 : write_byte_out:
3235 : :
3236 : 0 : return status;
3237 : : }
3238 : :
3239 : : /**
3240 : : * e1000_i2c_start - Sets I2C start condition
3241 : : * @hw: pointer to hardware structure
3242 : : *
3243 : : * Sets I2C start condition (High -> Low on SDA while SCL is High)
3244 : : **/
3245 : 0 : STATIC void e1000_i2c_start(struct e1000_hw *hw)
3246 : : {
3247 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3248 : :
3249 : 0 : DEBUGFUNC("e1000_i2c_start");
3250 : :
3251 : : /* Start condition must begin with data and clock high */
3252 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3253 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3254 : :
3255 : : /* Setup time for start condition (4.7us) */
3256 : 0 : usec_delay(E1000_I2C_T_SU_STA);
3257 : :
3258 : 0 : e1000_set_i2c_data(hw, &i2cctl, 0);
3259 : :
3260 : : /* Hold time for start condition (4us) */
3261 : 0 : usec_delay(E1000_I2C_T_HD_STA);
3262 : :
3263 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3264 : :
3265 : : /* Minimum low period of clock is 4.7 us */
3266 : 0 : usec_delay(E1000_I2C_T_LOW);
3267 : :
3268 : 0 : }
3269 : :
3270 : : /**
3271 : : * e1000_i2c_stop - Sets I2C stop condition
3272 : : * @hw: pointer to hardware structure
3273 : : *
3274 : : * Sets I2C stop condition (Low -> High on SDA while SCL is High)
3275 : : **/
3276 : 0 : STATIC void e1000_i2c_stop(struct e1000_hw *hw)
3277 : : {
3278 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3279 : :
3280 : 0 : DEBUGFUNC("e1000_i2c_stop");
3281 : :
3282 : : /* Stop condition must begin with data low and clock high */
3283 : 0 : e1000_set_i2c_data(hw, &i2cctl, 0);
3284 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3285 : :
3286 : : /* Setup time for stop condition (4us) */
3287 : 0 : usec_delay(E1000_I2C_T_SU_STO);
3288 : :
3289 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3290 : :
3291 : : /* bus free time between stop and start (4.7us)*/
3292 : 0 : usec_delay(E1000_I2C_T_BUF);
3293 : 0 : }
3294 : :
3295 : : /**
3296 : : * e1000_clock_in_i2c_byte - Clocks in one byte via I2C
3297 : : * @hw: pointer to hardware structure
3298 : : * @data: data byte to clock in
3299 : : *
3300 : : * Clocks in one byte data via I2C data/clock
3301 : : **/
3302 : 0 : STATIC void e1000_clock_in_i2c_byte(struct e1000_hw *hw, u8 *data)
3303 : : {
3304 : : s32 i;
3305 : 0 : bool bit = 0;
3306 : :
3307 : 0 : DEBUGFUNC("e1000_clock_in_i2c_byte");
3308 : :
3309 : 0 : *data = 0;
3310 [ # # ]: 0 : for (i = 7; i >= 0; i--) {
3311 : 0 : e1000_clock_in_i2c_bit(hw, &bit);
3312 : 0 : *data |= bit << i;
3313 : : }
3314 : 0 : }
3315 : :
3316 : : /**
3317 : : * e1000_clock_out_i2c_byte - Clocks out one byte via I2C
3318 : : * @hw: pointer to hardware structure
3319 : : * @data: data byte clocked out
3320 : : *
3321 : : * Clocks out one byte data via I2C data/clock
3322 : : **/
3323 : 0 : STATIC s32 e1000_clock_out_i2c_byte(struct e1000_hw *hw, u8 data)
3324 : : {
3325 : : s32 status = E1000_SUCCESS;
3326 : : s32 i;
3327 : : u32 i2cctl;
3328 : : bool bit = 0;
3329 : :
3330 : 0 : DEBUGFUNC("e1000_clock_out_i2c_byte");
3331 : :
3332 [ # # ]: 0 : for (i = 7; i >= 0; i--) {
3333 : 0 : bit = (data >> i) & 0x1;
3334 : 0 : status = e1000_clock_out_i2c_bit(hw, bit);
3335 : :
3336 [ # # ]: 0 : if (status != E1000_SUCCESS)
3337 : : break;
3338 : : }
3339 : :
3340 : : /* Release SDA line (set high) */
3341 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3342 : :
3343 : 0 : i2cctl |= E1000_I2C_DATA_OE_N;
3344 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
3345 : 0 : E1000_WRITE_FLUSH(hw);
3346 : :
3347 : 0 : return status;
3348 : : }
3349 : :
3350 : : /**
3351 : : * e1000_get_i2c_ack - Polls for I2C ACK
3352 : : * @hw: pointer to hardware structure
3353 : : *
3354 : : * Clocks in/out one bit via I2C data/clock
3355 : : **/
3356 : 0 : STATIC s32 e1000_get_i2c_ack(struct e1000_hw *hw)
3357 : : {
3358 : : s32 status = E1000_SUCCESS;
3359 : : u32 i = 0;
3360 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3361 : : u32 timeout = 10;
3362 : : bool ack = true;
3363 : :
3364 : 0 : DEBUGFUNC("e1000_get_i2c_ack");
3365 : :
3366 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3367 : :
3368 : : /* Minimum high period of clock is 4us */
3369 : 0 : usec_delay(E1000_I2C_T_HIGH);
3370 : :
3371 : : /* Wait until SCL returns high */
3372 [ # # ]: 0 : for (i = 0; i < timeout; i++) {
3373 : 0 : usec_delay(1);
3374 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3375 [ # # ]: 0 : if (i2cctl & E1000_I2C_CLK_IN)
3376 : : break;
3377 : : }
3378 [ # # ]: 0 : if (!(i2cctl & E1000_I2C_CLK_IN))
3379 : : return E1000_ERR_I2C;
3380 : :
3381 : 0 : ack = e1000_get_i2c_data(&i2cctl);
3382 [ # # ]: 0 : if (ack) {
3383 : 0 : DEBUGOUT("I2C ack was not received.\n");
3384 : : status = E1000_ERR_I2C;
3385 : : }
3386 : :
3387 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3388 : :
3389 : : /* Minimum low period of clock is 4.7 us */
3390 : 0 : usec_delay(E1000_I2C_T_LOW);
3391 : :
3392 : 0 : return status;
3393 : : }
3394 : :
3395 : : /**
3396 : : * e1000_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
3397 : : * @hw: pointer to hardware structure
3398 : : * @data: read data value
3399 : : *
3400 : : * Clocks in one bit via I2C data/clock
3401 : : **/
3402 : 0 : STATIC void e1000_clock_in_i2c_bit(struct e1000_hw *hw, bool *data)
3403 : : {
3404 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3405 : :
3406 : 0 : DEBUGFUNC("e1000_clock_in_i2c_bit");
3407 : :
3408 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3409 : :
3410 : : /* Minimum high period of clock is 4us */
3411 : 0 : usec_delay(E1000_I2C_T_HIGH);
3412 : :
3413 : 0 : i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3414 : 0 : *data = e1000_get_i2c_data(&i2cctl);
3415 : :
3416 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3417 : :
3418 : : /* Minimum low period of clock is 4.7 us */
3419 : 0 : usec_delay(E1000_I2C_T_LOW);
3420 : 0 : }
3421 : :
3422 : : /**
3423 : : * e1000_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
3424 : : * @hw: pointer to hardware structure
3425 : : * @data: data value to write
3426 : : *
3427 : : * Clocks out one bit via I2C data/clock
3428 : : **/
3429 : 0 : STATIC s32 e1000_clock_out_i2c_bit(struct e1000_hw *hw, bool data)
3430 : : {
3431 : : s32 status;
3432 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3433 : :
3434 : 0 : DEBUGFUNC("e1000_clock_out_i2c_bit");
3435 : :
3436 : 0 : status = e1000_set_i2c_data(hw, &i2cctl, data);
3437 [ # # ]: 0 : if (status == E1000_SUCCESS) {
3438 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3439 : :
3440 : : /* Minimum high period of clock is 4us */
3441 : 0 : usec_delay(E1000_I2C_T_HIGH);
3442 : :
3443 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3444 : :
3445 : : /* Minimum low period of clock is 4.7 us.
3446 : : * This also takes care of the data hold time.
3447 : : */
3448 : 0 : usec_delay(E1000_I2C_T_LOW);
3449 : : } else {
3450 : : status = E1000_ERR_I2C;
3451 : 0 : DEBUGOUT1("I2C data was not set to %X\n", data);
3452 : : }
3453 : :
3454 : 0 : return status;
3455 : : }
3456 : : /**
3457 : : * e1000_raise_i2c_clk - Raises the I2C SCL clock
3458 : : * @hw: pointer to hardware structure
3459 : : * @i2cctl: Current value of I2CCTL register
3460 : : *
3461 : : * Raises the I2C clock line '0'->'1'
3462 : : **/
3463 : 0 : STATIC void e1000_raise_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3464 : : {
3465 : 0 : DEBUGFUNC("e1000_raise_i2c_clk");
3466 : :
3467 : 0 : *i2cctl |= E1000_I2C_CLK_OUT;
3468 : 0 : *i2cctl &= ~E1000_I2C_CLK_OE_N;
3469 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3470 : 0 : E1000_WRITE_FLUSH(hw);
3471 : :
3472 : : /* SCL rise time (1000ns) */
3473 : 0 : usec_delay(E1000_I2C_T_RISE);
3474 : 0 : }
3475 : :
3476 : : /**
3477 : : * e1000_lower_i2c_clk - Lowers the I2C SCL clock
3478 : : * @hw: pointer to hardware structure
3479 : : * @i2cctl: Current value of I2CCTL register
3480 : : *
3481 : : * Lowers the I2C clock line '1'->'0'
3482 : : **/
3483 : 0 : STATIC void e1000_lower_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3484 : : {
3485 : :
3486 : 0 : DEBUGFUNC("e1000_lower_i2c_clk");
3487 : :
3488 : 0 : *i2cctl &= ~E1000_I2C_CLK_OUT;
3489 : 0 : *i2cctl &= ~E1000_I2C_CLK_OE_N;
3490 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3491 : 0 : E1000_WRITE_FLUSH(hw);
3492 : :
3493 : : /* SCL fall time (300ns) */
3494 : 0 : usec_delay(E1000_I2C_T_FALL);
3495 : 0 : }
3496 : :
3497 : : /**
3498 : : * e1000_set_i2c_data - Sets the I2C data bit
3499 : : * @hw: pointer to hardware structure
3500 : : * @i2cctl: Current value of I2CCTL register
3501 : : * @data: I2C data value (0 or 1) to set
3502 : : *
3503 : : * Sets the I2C data bit
3504 : : **/
3505 : 0 : STATIC s32 e1000_set_i2c_data(struct e1000_hw *hw, u32 *i2cctl, bool data)
3506 : : {
3507 : : s32 status = E1000_SUCCESS;
3508 : :
3509 : 0 : DEBUGFUNC("e1000_set_i2c_data");
3510 : :
3511 [ # # ]: 0 : if (data)
3512 : 0 : *i2cctl |= E1000_I2C_DATA_OUT;
3513 : : else
3514 : 0 : *i2cctl &= ~E1000_I2C_DATA_OUT;
3515 : :
3516 : 0 : *i2cctl &= ~E1000_I2C_DATA_OE_N;
3517 : 0 : *i2cctl |= E1000_I2C_CLK_OE_N;
3518 : 0 : E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3519 : 0 : E1000_WRITE_FLUSH(hw);
3520 : :
3521 : : /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
3522 : 0 : usec_delay(E1000_I2C_T_RISE + E1000_I2C_T_FALL + E1000_I2C_T_SU_DATA);
3523 : :
3524 : 0 : *i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3525 [ # # ]: 0 : if (data != e1000_get_i2c_data(i2cctl)) {
3526 : : status = E1000_ERR_I2C;
3527 : 0 : DEBUGOUT1("Error - I2C data was not set to %X.\n", data);
3528 : : }
3529 : :
3530 : 0 : return status;
3531 : : }
3532 : :
3533 : : /**
3534 : : * e1000_get_i2c_data - Reads the I2C SDA data bit
3535 : : * @i2cctl: Current value of I2CCTL register
3536 : : *
3537 : : * Returns the I2C data bit value
3538 : : **/
3539 : 0 : STATIC bool e1000_get_i2c_data(u32 *i2cctl)
3540 : : {
3541 : : bool data;
3542 : :
3543 : 0 : DEBUGFUNC("e1000_get_i2c_data");
3544 : :
3545 [ # # ]: 0 : if (*i2cctl & E1000_I2C_DATA_IN)
3546 : : data = 1;
3547 : : else
3548 : : data = 0;
3549 : :
3550 : 0 : return data;
3551 : : }
3552 : :
3553 : : /**
3554 : : * e1000_i2c_bus_clear - Clears the I2C bus
3555 : : * @hw: pointer to hardware structure
3556 : : *
3557 : : * Clears the I2C bus by sending nine clock pulses.
3558 : : * Used when data line is stuck low.
3559 : : **/
3560 : 0 : void e1000_i2c_bus_clear(struct e1000_hw *hw)
3561 : : {
3562 : 0 : u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3563 : : u32 i;
3564 : :
3565 : 0 : DEBUGFUNC("e1000_i2c_bus_clear");
3566 : :
3567 : 0 : e1000_i2c_start(hw);
3568 : :
3569 : 0 : e1000_set_i2c_data(hw, &i2cctl, 1);
3570 : :
3571 [ # # ]: 0 : for (i = 0; i < 9; i++) {
3572 : 0 : e1000_raise_i2c_clk(hw, &i2cctl);
3573 : :
3574 : : /* Min high period of clock is 4us */
3575 : 0 : usec_delay(E1000_I2C_T_HIGH);
3576 : :
3577 : 0 : e1000_lower_i2c_clk(hw, &i2cctl);
3578 : :
3579 : : /* Min low period of clock is 4.7us*/
3580 : 0 : usec_delay(E1000_I2C_T_LOW);
3581 : : }
3582 : :
3583 : 0 : e1000_i2c_start(hw);
3584 : :
3585 : : /* Put the i2c bus back to default state */
3586 : 0 : e1000_i2c_stop(hw);
3587 : 0 : }
3588 : :
|