1 /*******************************************************************************
3 Copyright (c) 2001-2012, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
35 * 82575EB Gigabit Network Connection
36 * 82575EB Gigabit Backplane Connection
37 * 82575GB Gigabit Network Connection
38 * 82576 Gigabit Network Connection
39 * 82576 Quad Port Gigabit Mezzanine Adapter
40 * 82580 Gigabit Network Connection
41 * I350 Gigabit Network Connection
44 #include "e1000_api.h"
45 #include "e1000_i210.h"
47 STATIC s32 e1000_init_phy_params_82575(struct e1000_hw *hw);
48 STATIC s32 e1000_init_mac_params_82575(struct e1000_hw *hw);
49 STATIC s32 e1000_acquire_phy_82575(struct e1000_hw *hw);
50 STATIC void e1000_release_phy_82575(struct e1000_hw *hw);
51 STATIC s32 e1000_acquire_nvm_82575(struct e1000_hw *hw);
52 STATIC void e1000_release_nvm_82575(struct e1000_hw *hw);
53 STATIC s32 e1000_check_for_link_82575(struct e1000_hw *hw);
54 STATIC s32 e1000_check_for_link_media_swap(struct e1000_hw *hw);
55 STATIC s32 e1000_get_cfg_done_82575(struct e1000_hw *hw);
56 STATIC s32 e1000_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
58 STATIC s32 e1000_phy_hw_reset_sgmii_82575(struct e1000_hw *hw);
59 STATIC s32 e1000_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
61 STATIC s32 e1000_reset_hw_82575(struct e1000_hw *hw);
62 STATIC s32 e1000_reset_hw_82580(struct e1000_hw *hw);
63 STATIC s32 e1000_read_phy_reg_82580(struct e1000_hw *hw,
64 u32 offset, u16 *data);
65 STATIC s32 e1000_write_phy_reg_82580(struct e1000_hw *hw,
66 u32 offset, u16 data);
67 STATIC s32 e1000_set_d0_lplu_state_82580(struct e1000_hw *hw,
69 STATIC s32 e1000_set_d3_lplu_state_82580(struct e1000_hw *hw,
71 STATIC s32 e1000_set_d0_lplu_state_82575(struct e1000_hw *hw,
73 STATIC s32 e1000_setup_copper_link_82575(struct e1000_hw *hw);
74 STATIC s32 e1000_setup_serdes_link_82575(struct e1000_hw *hw);
75 STATIC s32 e1000_get_media_type_82575(struct e1000_hw *hw);
76 STATIC s32 e1000_set_sfp_media_type_82575(struct e1000_hw *hw);
77 STATIC s32 e1000_valid_led_default_82575(struct e1000_hw *hw, u16 *data);
78 STATIC s32 e1000_write_phy_reg_sgmii_82575(struct e1000_hw *hw,
79 u32 offset, u16 data);
80 STATIC void e1000_clear_hw_cntrs_82575(struct e1000_hw *hw);
81 STATIC s32 e1000_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask);
82 STATIC s32 e1000_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw,
83 u16 *speed, u16 *duplex);
84 STATIC s32 e1000_get_phy_id_82575(struct e1000_hw *hw);
85 STATIC void e1000_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask);
86 STATIC bool e1000_sgmii_active_82575(struct e1000_hw *hw);
87 STATIC s32 e1000_reset_init_script_82575(struct e1000_hw *hw);
88 STATIC s32 e1000_read_mac_addr_82575(struct e1000_hw *hw);
89 STATIC void e1000_config_collision_dist_82575(struct e1000_hw *hw);
90 STATIC void e1000_power_down_phy_copper_82575(struct e1000_hw *hw);
91 STATIC void e1000_shutdown_serdes_link_82575(struct e1000_hw *hw);
92 STATIC void e1000_power_up_serdes_link_82575(struct e1000_hw *hw);
93 STATIC s32 e1000_set_pcie_completion_timeout(struct e1000_hw *hw);
94 STATIC s32 e1000_reset_mdicnfg_82580(struct e1000_hw *hw);
95 STATIC s32 e1000_validate_nvm_checksum_82580(struct e1000_hw *hw);
96 STATIC s32 e1000_update_nvm_checksum_82580(struct e1000_hw *hw);
97 STATIC s32 e1000_update_nvm_checksum_with_offset(struct e1000_hw *hw,
99 STATIC s32 e1000_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
101 STATIC s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw);
102 STATIC s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw);
103 STATIC void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value);
104 STATIC void e1000_clear_vfta_i350(struct e1000_hw *hw);
106 STATIC void e1000_i2c_start(struct e1000_hw *hw);
107 STATIC void e1000_i2c_stop(struct e1000_hw *hw);
108 STATIC s32 e1000_clock_in_i2c_byte(struct e1000_hw *hw, u8 *data);
109 STATIC s32 e1000_clock_out_i2c_byte(struct e1000_hw *hw, u8 data);
110 STATIC s32 e1000_get_i2c_ack(struct e1000_hw *hw);
111 STATIC s32 e1000_clock_in_i2c_bit(struct e1000_hw *hw, bool *data);
112 STATIC s32 e1000_clock_out_i2c_bit(struct e1000_hw *hw, bool data);
113 STATIC void e1000_raise_i2c_clk(struct e1000_hw *hw, u32 *i2cctl);
114 STATIC void e1000_lower_i2c_clk(struct e1000_hw *hw, u32 *i2cctl);
115 STATIC s32 e1000_set_i2c_data(struct e1000_hw *hw, u32 *i2cctl, bool data);
116 STATIC bool e1000_get_i2c_data(u32 *i2cctl);
118 STATIC const u16 e1000_82580_rxpbs_table[] = {
119 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
120 #define E1000_82580_RXPBS_TABLE_SIZE \
121 (sizeof(e1000_82580_rxpbs_table) / \
122 sizeof(e1000_82580_rxpbs_table[0]))
126 * e1000_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
127 * @hw: pointer to the HW structure
129 * Called to determine if the I2C pins are being used for I2C or as an
130 * external MDIO interface since the two options are mutually exclusive.
132 STATIC bool e1000_sgmii_uses_mdio_82575(struct e1000_hw *hw)
135 bool ext_mdio = false;
137 DEBUGFUNC("e1000_sgmii_uses_mdio_82575");
139 switch (hw->mac.type) {
142 reg = E1000_READ_REG(hw, E1000_MDIC);
143 ext_mdio = !!(reg & E1000_MDIC_DEST);
150 reg = E1000_READ_REG(hw, E1000_MDICNFG);
151 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
160 * e1000_init_phy_params_82575 - Init PHY func ptrs.
161 * @hw: pointer to the HW structure
163 STATIC s32 e1000_init_phy_params_82575(struct e1000_hw *hw)
165 struct e1000_phy_info *phy = &hw->phy;
166 s32 ret_val = E1000_SUCCESS;
169 DEBUGFUNC("e1000_init_phy_params_82575");
171 phy->ops.read_i2c_byte = e1000_read_i2c_byte_generic;
172 phy->ops.write_i2c_byte = e1000_write_i2c_byte_generic;
174 if (hw->phy.media_type != e1000_media_type_copper) {
175 phy->type = e1000_phy_none;
179 phy->ops.power_up = e1000_power_up_phy_copper;
180 phy->ops.power_down = e1000_power_down_phy_copper_82575;
182 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
183 phy->reset_delay_us = 100;
185 phy->ops.acquire = e1000_acquire_phy_82575;
186 phy->ops.check_reset_block = e1000_check_reset_block_generic;
187 phy->ops.commit = e1000_phy_sw_reset_generic;
188 phy->ops.get_cfg_done = e1000_get_cfg_done_82575;
189 phy->ops.release = e1000_release_phy_82575;
191 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
193 if (e1000_sgmii_active_82575(hw)) {
194 phy->ops.reset = e1000_phy_hw_reset_sgmii_82575;
195 ctrl_ext |= E1000_CTRL_I2C_ENA;
197 phy->ops.reset = e1000_phy_hw_reset_generic;
198 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
201 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
202 e1000_reset_mdicnfg_82580(hw);
204 if (e1000_sgmii_active_82575(hw) && !e1000_sgmii_uses_mdio_82575(hw)) {
205 phy->ops.read_reg = e1000_read_phy_reg_sgmii_82575;
206 phy->ops.write_reg = e1000_write_phy_reg_sgmii_82575;
208 switch (hw->mac.type) {
212 phy->ops.read_reg = e1000_read_phy_reg_82580;
213 phy->ops.write_reg = e1000_write_phy_reg_82580;
217 phy->ops.read_reg = e1000_read_phy_reg_gs40g;
218 phy->ops.write_reg = e1000_write_phy_reg_gs40g;
221 phy->ops.read_reg = e1000_read_phy_reg_igp;
222 phy->ops.write_reg = e1000_write_phy_reg_igp;
226 /* Set phy->phy_addr and phy->id. */
227 ret_val = e1000_get_phy_id_82575(hw);
229 /* Verify phy id and set remaining function pointers */
231 case M88E1543_E_PHY_ID:
232 case M88E1512_E_PHY_ID:
233 case I347AT4_E_PHY_ID:
234 case M88E1112_E_PHY_ID:
235 case M88E1340M_E_PHY_ID:
236 case M88E1111_I_PHY_ID:
237 phy->type = e1000_phy_m88;
238 phy->ops.check_polarity = e1000_check_polarity_m88;
239 phy->ops.get_info = e1000_get_phy_info_m88;
240 if (phy->id == I347AT4_E_PHY_ID ||
241 phy->id == M88E1112_E_PHY_ID ||
242 phy->id == M88E1340M_E_PHY_ID)
243 phy->ops.get_cable_length =
244 e1000_get_cable_length_m88_gen2;
245 else if (phy->id == M88E1543_E_PHY_ID ||
246 phy->id == M88E1512_E_PHY_ID)
247 phy->ops.get_cable_length =
248 e1000_get_cable_length_m88_gen2;
250 phy->ops.get_cable_length = e1000_get_cable_length_m88;
251 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
252 /* Check if this PHY is confgured for media swap. */
253 if (phy->id == M88E1112_E_PHY_ID) {
256 ret_val = phy->ops.write_reg(hw,
257 E1000_M88E1112_PAGE_ADDR,
262 ret_val = phy->ops.read_reg(hw,
263 E1000_M88E1112_MAC_CTRL_1,
268 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
269 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
270 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
271 data == E1000_M88E1112_AUTO_COPPER_BASEX)
272 hw->mac.ops.check_for_link =
273 e1000_check_for_link_media_swap;
276 case IGP03E1000_E_PHY_ID:
277 case IGP04E1000_E_PHY_ID:
278 phy->type = e1000_phy_igp_3;
279 phy->ops.check_polarity = e1000_check_polarity_igp;
280 phy->ops.get_info = e1000_get_phy_info_igp;
281 phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
282 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
283 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82575;
284 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_generic;
286 case I82580_I_PHY_ID:
288 phy->type = e1000_phy_82580;
289 phy->ops.check_polarity = e1000_check_polarity_82577;
290 phy->ops.force_speed_duplex =
291 e1000_phy_force_speed_duplex_82577;
292 phy->ops.get_cable_length = e1000_get_cable_length_82577;
293 phy->ops.get_info = e1000_get_phy_info_82577;
294 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82580;
295 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82580;
298 phy->type = e1000_phy_i210;
299 phy->ops.check_polarity = e1000_check_polarity_m88;
300 phy->ops.get_info = e1000_get_phy_info_m88;
301 phy->ops.get_cable_length = e1000_get_cable_length_m88_gen2;
302 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82580;
303 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82580;
304 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
307 ret_val = -E1000_ERR_PHY;
316 * e1000_init_nvm_params_82575 - Init NVM func ptrs.
317 * @hw: pointer to the HW structure
319 s32 e1000_init_nvm_params_82575(struct e1000_hw *hw)
321 struct e1000_nvm_info *nvm = &hw->nvm;
322 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
325 DEBUGFUNC("e1000_init_nvm_params_82575");
327 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
328 E1000_EECD_SIZE_EX_SHIFT);
330 * Added to a constant, "size" becomes the left-shift value
331 * for setting word_size.
333 size += NVM_WORD_SIZE_BASE_SHIFT;
335 /* Just in case size is out of range, cap it to the largest
336 * EEPROM size supported
341 nvm->word_size = 1 << size;
342 if (hw->mac.type < e1000_i210) {
343 nvm->opcode_bits = 8;
346 switch (nvm->override) {
347 case e1000_nvm_override_spi_large:
349 nvm->address_bits = 16;
351 case e1000_nvm_override_spi_small:
353 nvm->address_bits = 8;
356 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
357 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
361 if (nvm->word_size == (1 << 15))
362 nvm->page_size = 128;
364 nvm->type = e1000_nvm_eeprom_spi;
366 nvm->type = e1000_nvm_flash_hw;
369 /* Function Pointers */
370 nvm->ops.acquire = e1000_acquire_nvm_82575;
371 nvm->ops.release = e1000_release_nvm_82575;
372 if (nvm->word_size < (1 << 15))
373 nvm->ops.read = e1000_read_nvm_eerd;
375 nvm->ops.read = e1000_read_nvm_spi;
377 nvm->ops.write = e1000_write_nvm_spi;
378 nvm->ops.validate = e1000_validate_nvm_checksum_generic;
379 nvm->ops.update = e1000_update_nvm_checksum_generic;
380 nvm->ops.valid_led_default = e1000_valid_led_default_82575;
382 /* override generic family function pointers for specific descendants */
383 switch (hw->mac.type) {
385 nvm->ops.validate = e1000_validate_nvm_checksum_82580;
386 nvm->ops.update = e1000_update_nvm_checksum_82580;
390 nvm->ops.validate = e1000_validate_nvm_checksum_i350;
391 nvm->ops.update = e1000_update_nvm_checksum_i350;
397 return E1000_SUCCESS;
401 * e1000_init_mac_params_82575 - Init MAC func ptrs.
402 * @hw: pointer to the HW structure
404 STATIC s32 e1000_init_mac_params_82575(struct e1000_hw *hw)
406 struct e1000_mac_info *mac = &hw->mac;
407 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
409 DEBUGFUNC("e1000_init_mac_params_82575");
411 /* Derives media type */
412 e1000_get_media_type_82575(hw);
413 /* Set mta register count */
414 mac->mta_reg_count = 128;
415 /* Set uta register count */
416 mac->uta_reg_count = (hw->mac.type == e1000_82575) ? 0 : 128;
417 /* Set rar entry count */
418 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
419 if (mac->type == e1000_82576)
420 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
421 if (mac->type == e1000_82580)
422 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
423 if (mac->type == e1000_i350 || mac->type == e1000_i354)
424 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
426 /* Enable EEE default settings for EEE supported devices */
427 if (mac->type >= e1000_i350)
428 dev_spec->eee_disable = false;
430 /* Allow a single clear of the SW semaphore on I210 and newer */
431 if (mac->type >= e1000_i210)
432 dev_spec->clear_semaphore_once = true;
434 /* Set if part includes ASF firmware */
435 mac->asf_firmware_present = true;
437 mac->has_fwsm = true;
438 /* ARC supported; valid only if manageability features are enabled. */
439 mac->arc_subsystem_valid =
440 !!(E1000_READ_REG(hw, E1000_FWSM) & E1000_FWSM_MODE_MASK);
442 /* Function pointers */
444 /* bus type/speed/width */
445 mac->ops.get_bus_info = e1000_get_bus_info_pcie_generic;
447 if (mac->type >= e1000_82580)
448 mac->ops.reset_hw = e1000_reset_hw_82580;
450 mac->ops.reset_hw = e1000_reset_hw_82575;
451 /* hw initialization */
452 if ((mac->type == e1000_i210) || (mac->type == e1000_i211))
453 mac->ops.init_hw = e1000_init_hw_i210;
455 mac->ops.init_hw = e1000_init_hw_82575;
457 mac->ops.setup_link = e1000_setup_link_generic;
458 /* physical interface link setup */
459 mac->ops.setup_physical_interface =
460 (hw->phy.media_type == e1000_media_type_copper)
461 ? e1000_setup_copper_link_82575 : e1000_setup_serdes_link_82575;
462 /* physical interface shutdown */
463 mac->ops.shutdown_serdes = e1000_shutdown_serdes_link_82575;
464 /* physical interface power up */
465 mac->ops.power_up_serdes = e1000_power_up_serdes_link_82575;
467 mac->ops.check_for_link = e1000_check_for_link_82575;
468 /* read mac address */
469 mac->ops.read_mac_addr = e1000_read_mac_addr_82575;
470 /* configure collision distance */
471 mac->ops.config_collision_dist = e1000_config_collision_dist_82575;
472 /* multicast address update */
473 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
474 if (hw->mac.type == e1000_i350 || mac->type == e1000_i354) {
476 mac->ops.write_vfta = e1000_write_vfta_i350;
478 mac->ops.clear_vfta = e1000_clear_vfta_i350;
481 mac->ops.write_vfta = e1000_write_vfta_generic;
483 mac->ops.clear_vfta = e1000_clear_vfta_generic;
485 if (hw->mac.type >= e1000_82580)
486 mac->ops.validate_mdi_setting =
487 e1000_validate_mdi_setting_crossover_generic;
489 mac->ops.id_led_init = e1000_id_led_init_generic;
491 mac->ops.blink_led = e1000_blink_led_generic;
493 mac->ops.setup_led = e1000_setup_led_generic;
495 mac->ops.cleanup_led = e1000_cleanup_led_generic;
496 /* turn on/off LED */
497 mac->ops.led_on = e1000_led_on_generic;
498 mac->ops.led_off = e1000_led_off_generic;
499 /* clear hardware counters */
500 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82575;
502 mac->ops.get_link_up_info = e1000_get_link_up_info_82575;
503 /* acquire SW_FW sync */
504 mac->ops.acquire_swfw_sync = e1000_acquire_swfw_sync_82575;
505 mac->ops.release_swfw_sync = e1000_release_swfw_sync_82575;
506 if (mac->type >= e1000_i210) {
507 mac->ops.acquire_swfw_sync = e1000_acquire_swfw_sync_i210;
508 mac->ops.release_swfw_sync = e1000_release_swfw_sync_i210;
511 /* set lan id for port to determine which phy lock to use */
512 hw->mac.ops.set_lan_id(hw);
514 return E1000_SUCCESS;
518 * e1000_init_function_pointers_82575 - Init func ptrs.
519 * @hw: pointer to the HW structure
521 * Called to initialize all function pointers and parameters.
523 void e1000_init_function_pointers_82575(struct e1000_hw *hw)
525 DEBUGFUNC("e1000_init_function_pointers_82575");
527 hw->mac.ops.init_params = e1000_init_mac_params_82575;
528 hw->nvm.ops.init_params = e1000_init_nvm_params_82575;
529 hw->phy.ops.init_params = e1000_init_phy_params_82575;
530 hw->mbx.ops.init_params = e1000_init_mbx_params_pf;
534 * e1000_acquire_phy_82575 - Acquire rights to access PHY
535 * @hw: pointer to the HW structure
537 * Acquire access rights to the correct PHY.
539 STATIC s32 e1000_acquire_phy_82575(struct e1000_hw *hw)
541 u16 mask = E1000_SWFW_PHY0_SM;
543 DEBUGFUNC("e1000_acquire_phy_82575");
545 if (hw->bus.func == E1000_FUNC_1)
546 mask = E1000_SWFW_PHY1_SM;
547 else if (hw->bus.func == E1000_FUNC_2)
548 mask = E1000_SWFW_PHY2_SM;
549 else if (hw->bus.func == E1000_FUNC_3)
550 mask = E1000_SWFW_PHY3_SM;
552 return hw->mac.ops.acquire_swfw_sync(hw, mask);
556 * e1000_release_phy_82575 - Release rights to access PHY
557 * @hw: pointer to the HW structure
559 * A wrapper to release access rights to the correct PHY.
561 STATIC void e1000_release_phy_82575(struct e1000_hw *hw)
563 u16 mask = E1000_SWFW_PHY0_SM;
565 DEBUGFUNC("e1000_release_phy_82575");
567 if (hw->bus.func == E1000_FUNC_1)
568 mask = E1000_SWFW_PHY1_SM;
569 else if (hw->bus.func == E1000_FUNC_2)
570 mask = E1000_SWFW_PHY2_SM;
571 else if (hw->bus.func == E1000_FUNC_3)
572 mask = E1000_SWFW_PHY3_SM;
574 hw->mac.ops.release_swfw_sync(hw, mask);
578 * e1000_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
579 * @hw: pointer to the HW structure
580 * @offset: register offset to be read
581 * @data: pointer to the read data
583 * Reads the PHY register at offset using the serial gigabit media independent
584 * interface and stores the retrieved information in data.
586 STATIC s32 e1000_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
589 s32 ret_val = -E1000_ERR_PARAM;
591 DEBUGFUNC("e1000_read_phy_reg_sgmii_82575");
593 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
594 DEBUGOUT1("PHY Address %u is out of range\n", offset);
598 ret_val = hw->phy.ops.acquire(hw);
602 ret_val = e1000_read_phy_reg_i2c(hw, offset, data);
604 hw->phy.ops.release(hw);
611 * e1000_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
612 * @hw: pointer to the HW structure
613 * @offset: register offset to write to
614 * @data: data to write at register offset
616 * Writes the data to PHY register at the offset using the serial gigabit
617 * media independent interface.
619 STATIC s32 e1000_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
622 s32 ret_val = -E1000_ERR_PARAM;
624 DEBUGFUNC("e1000_write_phy_reg_sgmii_82575");
626 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
627 DEBUGOUT1("PHY Address %d is out of range\n", offset);
631 ret_val = hw->phy.ops.acquire(hw);
635 ret_val = e1000_write_phy_reg_i2c(hw, offset, data);
637 hw->phy.ops.release(hw);
644 * e1000_get_phy_id_82575 - Retrieve PHY addr and id
645 * @hw: pointer to the HW structure
647 * Retrieves the PHY address and ID for both PHY's which do and do not use
650 STATIC s32 e1000_get_phy_id_82575(struct e1000_hw *hw)
652 struct e1000_phy_info *phy = &hw->phy;
653 s32 ret_val = E1000_SUCCESS;
658 DEBUGFUNC("e1000_get_phy_id_82575");
660 /* some i354 devices need an extra read for phy id */
661 if (hw->mac.type == e1000_i354)
662 e1000_get_phy_id(hw);
665 * For SGMII PHYs, we try the list of possible addresses until
666 * we find one that works. For non-SGMII PHYs
667 * (e.g. integrated copper PHYs), an address of 1 should
668 * work. The result of this function should mean phy->phy_addr
669 * and phy->id are set correctly.
671 if (!e1000_sgmii_active_82575(hw)) {
673 ret_val = e1000_get_phy_id(hw);
677 if (e1000_sgmii_uses_mdio_82575(hw)) {
678 switch (hw->mac.type) {
681 mdic = E1000_READ_REG(hw, E1000_MDIC);
682 mdic &= E1000_MDIC_PHY_MASK;
683 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
690 mdic = E1000_READ_REG(hw, E1000_MDICNFG);
691 mdic &= E1000_MDICNFG_PHY_MASK;
692 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
695 ret_val = -E1000_ERR_PHY;
699 ret_val = e1000_get_phy_id(hw);
703 /* Power on sgmii phy if it is disabled */
704 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
705 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
706 ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
707 E1000_WRITE_FLUSH(hw);
711 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
712 * Therefore, we need to test 1-7
714 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
715 ret_val = e1000_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
716 if (ret_val == E1000_SUCCESS) {
717 DEBUGOUT2("Vendor ID 0x%08X read at address %u\n",
720 * At the time of this writing, The M88 part is
721 * the only supported SGMII PHY product.
723 if (phy_id == M88_VENDOR)
726 DEBUGOUT1("PHY address %u was unreadable\n",
731 /* A valid PHY type couldn't be found. */
732 if (phy->addr == 8) {
734 ret_val = -E1000_ERR_PHY;
736 ret_val = e1000_get_phy_id(hw);
739 /* restore previous sfp cage power state */
740 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
747 * e1000_phy_hw_reset_sgmii_82575 - Performs a PHY reset
748 * @hw: pointer to the HW structure
750 * Resets the PHY using the serial gigabit media independent interface.
752 STATIC s32 e1000_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
754 s32 ret_val = E1000_SUCCESS;
756 DEBUGFUNC("e1000_phy_hw_reset_sgmii_82575");
759 * This isn't a true "hard" reset, but is the only reset
760 * available to us at this time.
763 DEBUGOUT("Soft resetting SGMII attached PHY...\n");
765 if (!(hw->phy.ops.write_reg))
769 * SFP documentation requires the following to configure the SPF module
770 * to work on SGMII. No further documentation is given.
772 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
776 ret_val = hw->phy.ops.commit(hw);
783 * e1000_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
784 * @hw: pointer to the HW structure
785 * @active: true to enable LPLU, false to disable
787 * Sets the LPLU D0 state according to the active flag. When
788 * activating LPLU this function also disables smart speed
789 * and vice versa. LPLU will not be activated unless the
790 * device autonegotiation advertisement meets standards of
791 * either 10 or 10/100 or 10/100/1000 at all duplexes.
792 * This is a function pointer entry point only called by
793 * PHY setup routines.
795 STATIC s32 e1000_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
797 struct e1000_phy_info *phy = &hw->phy;
798 s32 ret_val = E1000_SUCCESS;
801 DEBUGFUNC("e1000_set_d0_lplu_state_82575");
803 if (!(hw->phy.ops.read_reg))
806 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
811 data |= IGP02E1000_PM_D0_LPLU;
812 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
817 /* When LPLU is enabled, we should disable SmartSpeed */
818 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
820 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
821 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
826 data &= ~IGP02E1000_PM_D0_LPLU;
827 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
830 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
831 * during Dx states where the power conservation is most
832 * important. During driver activity we should enable
833 * SmartSpeed, so performance is maintained.
835 if (phy->smart_speed == e1000_smart_speed_on) {
836 ret_val = phy->ops.read_reg(hw,
837 IGP01E1000_PHY_PORT_CONFIG,
842 data |= IGP01E1000_PSCFR_SMART_SPEED;
843 ret_val = phy->ops.write_reg(hw,
844 IGP01E1000_PHY_PORT_CONFIG,
848 } else if (phy->smart_speed == e1000_smart_speed_off) {
849 ret_val = phy->ops.read_reg(hw,
850 IGP01E1000_PHY_PORT_CONFIG,
855 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
856 ret_val = phy->ops.write_reg(hw,
857 IGP01E1000_PHY_PORT_CONFIG,
869 * e1000_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
870 * @hw: pointer to the HW structure
871 * @active: true to enable LPLU, false to disable
873 * Sets the LPLU D0 state according to the active flag. When
874 * activating LPLU this function also disables smart speed
875 * and vice versa. LPLU will not be activated unless the
876 * device autonegotiation advertisement meets standards of
877 * either 10 or 10/100 or 10/100/1000 at all duplexes.
878 * This is a function pointer entry point only called by
879 * PHY setup routines.
881 STATIC s32 e1000_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
883 struct e1000_phy_info *phy = &hw->phy;
884 s32 ret_val = E1000_SUCCESS;
887 DEBUGFUNC("e1000_set_d0_lplu_state_82580");
889 data = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
892 data |= E1000_82580_PM_D0_LPLU;
894 /* When LPLU is enabled, we should disable SmartSpeed */
895 data &= ~E1000_82580_PM_SPD;
897 data &= ~E1000_82580_PM_D0_LPLU;
900 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
901 * during Dx states where the power conservation is most
902 * important. During driver activity we should enable
903 * SmartSpeed, so performance is maintained.
905 if (phy->smart_speed == e1000_smart_speed_on)
906 data |= E1000_82580_PM_SPD;
907 else if (phy->smart_speed == e1000_smart_speed_off)
908 data &= ~E1000_82580_PM_SPD;
911 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, data);
916 * e1000_set_d3_lplu_state_82580 - Sets low power link up state for D3
917 * @hw: pointer to the HW structure
918 * @active: boolean used to enable/disable lplu
920 * Success returns 0, Failure returns 1
922 * The low power link up (lplu) state is set to the power management level D3
923 * and SmartSpeed is disabled when active is true, else clear lplu for D3
924 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
925 * is used during Dx states where the power conservation is most important.
926 * During driver activity, SmartSpeed should be enabled so performance is
929 s32 e1000_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
931 struct e1000_phy_info *phy = &hw->phy;
932 s32 ret_val = E1000_SUCCESS;
935 DEBUGFUNC("e1000_set_d3_lplu_state_82580");
937 data = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
940 data &= ~E1000_82580_PM_D3_LPLU;
942 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
943 * during Dx states where the power conservation is most
944 * important. During driver activity we should enable
945 * SmartSpeed, so performance is maintained.
947 if (phy->smart_speed == e1000_smart_speed_on)
948 data |= E1000_82580_PM_SPD;
949 else if (phy->smart_speed == e1000_smart_speed_off)
950 data &= ~E1000_82580_PM_SPD;
951 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
952 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
953 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
954 data |= E1000_82580_PM_D3_LPLU;
955 /* When LPLU is enabled, we should disable SmartSpeed */
956 data &= ~E1000_82580_PM_SPD;
959 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, data);
964 * e1000_acquire_nvm_82575 - Request for access to EEPROM
965 * @hw: pointer to the HW structure
967 * Acquire the necessary semaphores for exclusive access to the EEPROM.
968 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
969 * Return successful if access grant bit set, else clear the request for
970 * EEPROM access and return -E1000_ERR_NVM (-1).
972 STATIC s32 e1000_acquire_nvm_82575(struct e1000_hw *hw)
976 DEBUGFUNC("e1000_acquire_nvm_82575");
978 ret_val = e1000_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
983 * Check if there is some access
984 * error this access may hook on
986 if (hw->mac.type == e1000_i350) {
987 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
988 if (eecd & (E1000_EECD_BLOCKED | E1000_EECD_ABORT |
989 E1000_EECD_TIMEOUT)) {
990 /* Clear all access error flags */
991 E1000_WRITE_REG(hw, E1000_EECD, eecd |
992 E1000_EECD_ERROR_CLR);
993 DEBUGOUT("Nvm bit banging access error detected and cleared.\n");
996 if (hw->mac.type == e1000_82580) {
997 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
998 if (eecd & E1000_EECD_BLOCKED) {
999 /* Clear access error flag */
1000 E1000_WRITE_REG(hw, E1000_EECD, eecd |
1001 E1000_EECD_BLOCKED);
1002 DEBUGOUT("Nvm bit banging access error detected and cleared.\n");
1007 ret_val = e1000_acquire_nvm_generic(hw);
1009 e1000_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
1016 * e1000_release_nvm_82575 - Release exclusive access to EEPROM
1017 * @hw: pointer to the HW structure
1019 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1020 * then release the semaphores acquired.
1022 STATIC void e1000_release_nvm_82575(struct e1000_hw *hw)
1024 DEBUGFUNC("e1000_release_nvm_82575");
1026 e1000_release_nvm_generic(hw);
1028 e1000_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
1032 * e1000_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
1033 * @hw: pointer to the HW structure
1034 * @mask: specifies which semaphore to acquire
1036 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1037 * will also specify which port we're acquiring the lock for.
1039 STATIC s32 e1000_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1043 u32 fwmask = mask << 16;
1044 s32 ret_val = E1000_SUCCESS;
1045 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
1047 DEBUGFUNC("e1000_acquire_swfw_sync_82575");
1049 while (i < timeout) {
1050 if (e1000_get_hw_semaphore_generic(hw)) {
1051 ret_val = -E1000_ERR_SWFW_SYNC;
1055 swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
1056 if (!(swfw_sync & (fwmask | swmask)))
1060 * Firmware currently using resource (fwmask)
1061 * or other software thread using resource (swmask)
1063 e1000_put_hw_semaphore_generic(hw);
1069 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1070 ret_val = -E1000_ERR_SWFW_SYNC;
1074 swfw_sync |= swmask;
1075 E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
1077 e1000_put_hw_semaphore_generic(hw);
1084 * e1000_release_swfw_sync_82575 - Release SW/FW semaphore
1085 * @hw: pointer to the HW structure
1086 * @mask: specifies which semaphore to acquire
1088 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1089 * will also specify which port we're releasing the lock for.
1091 STATIC void e1000_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1095 DEBUGFUNC("e1000_release_swfw_sync_82575");
1097 while (e1000_get_hw_semaphore_generic(hw) != E1000_SUCCESS)
1100 swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
1102 E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
1104 e1000_put_hw_semaphore_generic(hw);
1108 * e1000_get_cfg_done_82575 - Read config done bit
1109 * @hw: pointer to the HW structure
1111 * Read the management control register for the config done bit for
1112 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1113 * to read the config done bit, so an error is *ONLY* logged and returns
1114 * E1000_SUCCESS. If we were to return with error, EEPROM-less silicon
1115 * would not be able to be reset or change link.
1117 STATIC s32 e1000_get_cfg_done_82575(struct e1000_hw *hw)
1119 s32 timeout = PHY_CFG_TIMEOUT;
1120 s32 ret_val = E1000_SUCCESS;
1121 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1123 DEBUGFUNC("e1000_get_cfg_done_82575");
1125 if (hw->bus.func == E1000_FUNC_1)
1126 mask = E1000_NVM_CFG_DONE_PORT_1;
1127 else if (hw->bus.func == E1000_FUNC_2)
1128 mask = E1000_NVM_CFG_DONE_PORT_2;
1129 else if (hw->bus.func == E1000_FUNC_3)
1130 mask = E1000_NVM_CFG_DONE_PORT_3;
1132 if (E1000_READ_REG(hw, E1000_EEMNGCTL) & mask)
1138 DEBUGOUT("MNG configuration cycle has not completed.\n");
1140 /* If EEPROM is not marked present, init the PHY manually */
1141 if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) &&
1142 (hw->phy.type == e1000_phy_igp_3))
1143 e1000_phy_init_script_igp3(hw);
1149 * e1000_get_link_up_info_82575 - Get link speed/duplex info
1150 * @hw: pointer to the HW structure
1151 * @speed: stores the current speed
1152 * @duplex: stores the current duplex
1154 * This is a wrapper function, if using the serial gigabit media independent
1155 * interface, use PCS to retrieve the link speed and duplex information.
1156 * Otherwise, use the generic function to get the link speed and duplex info.
1158 STATIC s32 e1000_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1163 DEBUGFUNC("e1000_get_link_up_info_82575");
1165 if (hw->phy.media_type != e1000_media_type_copper)
1166 ret_val = e1000_get_pcs_speed_and_duplex_82575(hw, speed,
1169 ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed,
1176 * e1000_check_for_link_82575 - Check for link
1177 * @hw: pointer to the HW structure
1179 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1180 * use the generic interface for determining link.
1182 STATIC s32 e1000_check_for_link_82575(struct e1000_hw *hw)
1187 DEBUGFUNC("e1000_check_for_link_82575");
1189 if (hw->phy.media_type != e1000_media_type_copper) {
1190 ret_val = e1000_get_pcs_speed_and_duplex_82575(hw, &speed,
1193 * Use this flag to determine if link needs to be checked or
1194 * not. If we have link clear the flag so that we do not
1195 * continue to check for link.
1197 hw->mac.get_link_status = !hw->mac.serdes_has_link;
1200 * Configure Flow Control now that Auto-Neg has completed.
1201 * First, we need to restore the desired flow control
1202 * settings because we may have had to re-autoneg with a
1203 * different link partner.
1205 ret_val = e1000_config_fc_after_link_up_generic(hw);
1207 DEBUGOUT("Error configuring flow control\n");
1209 ret_val = e1000_check_for_copper_link_generic(hw);
1216 * e1000_check_for_link_media_swap - Check which M88E1112 interface linked
1217 * @hw: pointer to the HW structure
1219 * Poll the M88E1112 interfaces to see which interface achieved link.
1221 STATIC s32 e1000_check_for_link_media_swap(struct e1000_hw *hw)
1223 struct e1000_phy_info *phy = &hw->phy;
1228 DEBUGFUNC("e1000_check_for_link_media_swap");
1230 /* Check the copper medium. */
1231 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1235 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1239 if (data & E1000_M88E1112_STATUS_LINK)
1240 port = E1000_MEDIA_PORT_COPPER;
1242 /* Check the other medium. */
1243 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
1247 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
1251 /* reset page to 0 */
1252 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
1256 if (data & E1000_M88E1112_STATUS_LINK)
1257 port = E1000_MEDIA_PORT_OTHER;
1259 /* Determine if a swap needs to happen. */
1260 if (port && (hw->dev_spec._82575.media_port != port)) {
1261 hw->dev_spec._82575.media_port = port;
1262 hw->dev_spec._82575.media_changed = true;
1264 ret_val = e1000_check_for_link_82575(hw);
1267 return E1000_SUCCESS;
1271 * e1000_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1272 * @hw: pointer to the HW structure
1274 STATIC void e1000_power_up_serdes_link_82575(struct e1000_hw *hw)
1278 DEBUGFUNC("e1000_power_up_serdes_link_82575");
1280 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1281 !e1000_sgmii_active_82575(hw))
1284 /* Enable PCS to turn on link */
1285 reg = E1000_READ_REG(hw, E1000_PCS_CFG0);
1286 reg |= E1000_PCS_CFG_PCS_EN;
1287 E1000_WRITE_REG(hw, E1000_PCS_CFG0, reg);
1289 /* Power up the laser */
1290 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1291 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1292 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1294 /* flush the write to verify completion */
1295 E1000_WRITE_FLUSH(hw);
1300 * e1000_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
1301 * @hw: pointer to the HW structure
1302 * @speed: stores the current speed
1303 * @duplex: stores the current duplex
1305 * Using the physical coding sub-layer (PCS), retrieve the current speed and
1306 * duplex, then store the values in the pointers provided.
1308 STATIC s32 e1000_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw,
1309 u16 *speed, u16 *duplex)
1311 struct e1000_mac_info *mac = &hw->mac;
1315 DEBUGFUNC("e1000_get_pcs_speed_and_duplex_82575");
1318 * Read the PCS Status register for link state. For non-copper mode,
1319 * the status register is not accurate. The PCS status register is
1322 pcs = E1000_READ_REG(hw, E1000_PCS_LSTAT);
1325 * The link up bit determines when link is up on autoneg.
1327 if (pcs & E1000_PCS_LSTS_LINK_OK) {
1328 mac->serdes_has_link = true;
1330 /* Detect and store PCS speed */
1331 if (pcs & E1000_PCS_LSTS_SPEED_1000)
1332 *speed = SPEED_1000;
1333 else if (pcs & E1000_PCS_LSTS_SPEED_100)
1338 /* Detect and store PCS duplex */
1339 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
1340 *duplex = FULL_DUPLEX;
1342 *duplex = HALF_DUPLEX;
1344 /* Check if it is an I354 2.5Gb backplane connection. */
1345 if (mac->type == e1000_i354) {
1346 status = E1000_READ_REG(hw, E1000_STATUS);
1347 if ((status & E1000_STATUS_2P5_SKU) &&
1348 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1349 *speed = SPEED_2500;
1350 *duplex = FULL_DUPLEX;
1351 DEBUGOUT("2500 Mbs, ");
1352 DEBUGOUT("Full Duplex\n");
1357 mac->serdes_has_link = false;
1362 return E1000_SUCCESS;
1366 * e1000_shutdown_serdes_link_82575 - Remove link during power down
1367 * @hw: pointer to the HW structure
1369 * In the case of serdes shut down sfp and PCS on driver unload
1370 * when management pass thru is not enabled.
1372 void e1000_shutdown_serdes_link_82575(struct e1000_hw *hw)
1376 DEBUGFUNC("e1000_shutdown_serdes_link_82575");
1378 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1379 !e1000_sgmii_active_82575(hw))
1382 if (!e1000_enable_mng_pass_thru(hw)) {
1383 /* Disable PCS to turn off link */
1384 reg = E1000_READ_REG(hw, E1000_PCS_CFG0);
1385 reg &= ~E1000_PCS_CFG_PCS_EN;
1386 E1000_WRITE_REG(hw, E1000_PCS_CFG0, reg);
1388 /* shutdown the laser */
1389 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1390 reg |= E1000_CTRL_EXT_SDP3_DATA;
1391 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1393 /* flush the write to verify completion */
1394 E1000_WRITE_FLUSH(hw);
1402 * e1000_reset_hw_82575 - Reset hardware
1403 * @hw: pointer to the HW structure
1405 * This resets the hardware into a known state.
1407 STATIC s32 e1000_reset_hw_82575(struct e1000_hw *hw)
1412 DEBUGFUNC("e1000_reset_hw_82575");
1415 * Prevent the PCI-E bus from sticking if there is no TLP connection
1416 * on the last TLP read/write transaction when MAC is reset.
1418 ret_val = e1000_disable_pcie_master_generic(hw);
1420 DEBUGOUT("PCI-E Master disable polling has failed.\n");
1422 /* set the completion timeout for interface */
1423 ret_val = e1000_set_pcie_completion_timeout(hw);
1425 DEBUGOUT("PCI-E Set completion timeout has failed.\n");
1427 DEBUGOUT("Masking off all interrupts\n");
1428 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1430 E1000_WRITE_REG(hw, E1000_RCTL, 0);
1431 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
1432 E1000_WRITE_FLUSH(hw);
1436 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1438 DEBUGOUT("Issuing a global reset to MAC\n");
1439 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
1441 ret_val = e1000_get_auto_rd_done_generic(hw);
1444 * When auto config read does not complete, do not
1445 * return with an error. This can happen in situations
1446 * where there is no eeprom and prevents getting link.
1448 DEBUGOUT("Auto Read Done did not complete\n");
1451 /* If EEPROM is not present, run manual init scripts */
1452 if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES))
1453 e1000_reset_init_script_82575(hw);
1455 /* Clear any pending interrupt events. */
1456 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1457 E1000_READ_REG(hw, E1000_ICR);
1459 /* Install any alternate MAC address into RAR0 */
1460 ret_val = e1000_check_alt_mac_addr_generic(hw);
1466 * e1000_init_hw_82575 - Initialize hardware
1467 * @hw: pointer to the HW structure
1469 * This inits the hardware readying it for operation.
1471 s32 e1000_init_hw_82575(struct e1000_hw *hw)
1473 struct e1000_mac_info *mac = &hw->mac;
1475 u16 i, rar_count = mac->rar_entry_count;
1477 DEBUGFUNC("e1000_init_hw_82575");
1479 /* Initialize identification LED */
1480 ret_val = mac->ops.id_led_init(hw);
1482 DEBUGOUT("Error initializing identification LED\n");
1483 /* This is not fatal and we should not stop init due to this */
1486 /* Disabling VLAN filtering */
1487 DEBUGOUT("Initializing the IEEE VLAN\n");
1488 mac->ops.clear_vfta(hw);
1490 /* Setup the receive address */
1491 e1000_init_rx_addrs_generic(hw, rar_count);
1493 /* Zero out the Multicast HASH table */
1494 DEBUGOUT("Zeroing the MTA\n");
1495 for (i = 0; i < mac->mta_reg_count; i++)
1496 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1498 /* Zero out the Unicast HASH table */
1499 DEBUGOUT("Zeroing the UTA\n");
1500 for (i = 0; i < mac->uta_reg_count; i++)
1501 E1000_WRITE_REG_ARRAY(hw, E1000_UTA, i, 0);
1503 /* Setup link and flow control */
1504 ret_val = mac->ops.setup_link(hw);
1506 /* Set the default MTU size */
1507 hw->dev_spec._82575.mtu = 1500;
1510 * Clear all of the statistics registers (clear on read). It is
1511 * important that we do this after we have tried to establish link
1512 * because the symbol error count will increment wildly if there
1515 e1000_clear_hw_cntrs_82575(hw);
1521 * e1000_setup_copper_link_82575 - Configure copper link settings
1522 * @hw: pointer to the HW structure
1524 * Configures the link for auto-neg or forced speed and duplex. Then we check
1525 * for link, once link is established calls to configure collision distance
1526 * and flow control are called.
1528 STATIC s32 e1000_setup_copper_link_82575(struct e1000_hw *hw)
1534 DEBUGFUNC("e1000_setup_copper_link_82575");
1536 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1537 ctrl |= E1000_CTRL_SLU;
1538 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1539 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1541 /* Clear Go Link Disconnect bit on supported devices */
1542 switch (hw->mac.type) {
1547 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1548 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1549 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1555 ret_val = e1000_setup_serdes_link_82575(hw);
1559 if (e1000_sgmii_active_82575(hw)) {
1560 /* allow time for SFP cage time to power up phy */
1563 ret_val = hw->phy.ops.reset(hw);
1565 DEBUGOUT("Error resetting the PHY.\n");
1569 switch (hw->phy.type) {
1570 case e1000_phy_i210:
1572 switch (hw->phy.id) {
1573 case I347AT4_E_PHY_ID:
1574 case M88E1112_E_PHY_ID:
1575 case M88E1340M_E_PHY_ID:
1576 case M88E1543_E_PHY_ID:
1577 case M88E1512_E_PHY_ID:
1579 ret_val = e1000_copper_link_setup_m88_gen2(hw);
1582 ret_val = e1000_copper_link_setup_m88(hw);
1586 case e1000_phy_igp_3:
1587 ret_val = e1000_copper_link_setup_igp(hw);
1589 case e1000_phy_82580:
1590 ret_val = e1000_copper_link_setup_82577(hw);
1593 ret_val = -E1000_ERR_PHY;
1600 ret_val = e1000_setup_copper_link_generic(hw);
1606 * e1000_setup_serdes_link_82575 - Setup link for serdes
1607 * @hw: pointer to the HW structure
1609 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1610 * used on copper connections where the serialized gigabit media independent
1611 * interface (sgmii), or serdes fiber is being used. Configures the link
1612 * for auto-negotiation or forces speed/duplex.
1614 STATIC s32 e1000_setup_serdes_link_82575(struct e1000_hw *hw)
1616 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
1618 s32 ret_val = E1000_SUCCESS;
1621 DEBUGFUNC("e1000_setup_serdes_link_82575");
1623 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1624 !e1000_sgmii_active_82575(hw))
1628 * On the 82575, SerDes loopback mode persists until it is
1629 * explicitly turned off or a power cycle is performed. A read to
1630 * the register does not indicate its status. Therefore, we ensure
1631 * loopback mode is disabled during initialization.
1633 E1000_WRITE_REG(hw, E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1635 /* power on the sfp cage if present */
1636 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1637 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1638 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1640 ctrl_reg = E1000_READ_REG(hw, E1000_CTRL);
1641 ctrl_reg |= E1000_CTRL_SLU;
1643 /* set both sw defined pins on 82575/82576*/
1644 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576)
1645 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1647 reg = E1000_READ_REG(hw, E1000_PCS_LCTL);
1649 /* default pcs_autoneg to the same setting as mac autoneg */
1650 pcs_autoneg = hw->mac.autoneg;
1652 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1653 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1654 /* sgmii mode lets the phy handle forcing speed/duplex */
1656 /* autoneg time out should be disabled for SGMII mode */
1657 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1659 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1660 /* disable PCS autoneg and support parallel detect only */
1661 pcs_autoneg = false;
1662 /* fall through to default case */
1664 if (hw->mac.type == e1000_82575 ||
1665 hw->mac.type == e1000_82576) {
1666 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1668 DEBUGOUT("NVM Read Error\n");
1672 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1673 pcs_autoneg = false;
1677 * non-SGMII modes only supports a speed of 1000/Full for the
1678 * link so it is best to just force the MAC and let the pcs
1679 * link either autoneg or be forced to 1000/Full
1681 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1682 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
1684 /* set speed of 1000/Full if speed/duplex is forced */
1685 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1689 E1000_WRITE_REG(hw, E1000_CTRL, ctrl_reg);
1692 * New SerDes mode allows for forcing speed or autonegotiating speed
1693 * at 1gb. Autoneg should be default set by most drivers. This is the
1694 * mode that will be compatible with older link partners and switches.
1695 * However, both are supported by the hardware and some drivers/tools.
1697 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1698 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1701 /* Set PCS register for autoneg */
1702 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1703 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
1705 /* Disable force flow control for autoneg */
1706 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1708 /* Configure flow control advertisement for autoneg */
1709 anadv_reg = E1000_READ_REG(hw, E1000_PCS_ANADV);
1710 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1712 switch (hw->fc.requested_mode) {
1714 case e1000_fc_rx_pause:
1715 anadv_reg |= E1000_TXCW_ASM_DIR;
1716 anadv_reg |= E1000_TXCW_PAUSE;
1718 case e1000_fc_tx_pause:
1719 anadv_reg |= E1000_TXCW_ASM_DIR;
1725 E1000_WRITE_REG(hw, E1000_PCS_ANADV, anadv_reg);
1727 DEBUGOUT1("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
1729 /* Set PCS register for forced link */
1730 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
1732 /* Force flow control for forced link */
1733 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1735 DEBUGOUT1("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
1738 E1000_WRITE_REG(hw, E1000_PCS_LCTL, reg);
1740 if (!pcs_autoneg && !e1000_sgmii_active_82575(hw))
1741 e1000_force_mac_fc_generic(hw);
1747 * e1000_get_media_type_82575 - derives current media type.
1748 * @hw: pointer to the HW structure
1750 * The media type is chosen reflecting few settings.
1751 * The following are taken into account:
1752 * - link mode set in the current port Init Control Word #3
1753 * - current link mode settings in CSR register
1754 * - MDIO vs. I2C PHY control interface chosen
1755 * - SFP module media type
1757 STATIC s32 e1000_get_media_type_82575(struct e1000_hw *hw)
1759 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1760 s32 ret_val = E1000_SUCCESS;
1764 /* Set internal phy as default */
1765 dev_spec->sgmii_active = false;
1766 dev_spec->module_plugged = false;
1768 /* Get CSR setting */
1769 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1771 /* extract link mode setting */
1772 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
1774 switch (link_mode) {
1775 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1776 hw->phy.media_type = e1000_media_type_internal_serdes;
1778 case E1000_CTRL_EXT_LINK_MODE_GMII:
1779 hw->phy.media_type = e1000_media_type_copper;
1781 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1782 /* Get phy control interface type set (MDIO vs. I2C)*/
1783 if (e1000_sgmii_uses_mdio_82575(hw)) {
1784 hw->phy.media_type = e1000_media_type_copper;
1785 dev_spec->sgmii_active = true;
1788 /* fall through for I2C based SGMII */
1789 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
1790 /* read media type from SFP EEPROM */
1791 ret_val = e1000_set_sfp_media_type_82575(hw);
1792 if ((ret_val != E1000_SUCCESS) ||
1793 (hw->phy.media_type == e1000_media_type_unknown)) {
1795 * If media type was not identified then return media
1796 * type defined by the CTRL_EXT settings.
1798 hw->phy.media_type = e1000_media_type_internal_serdes;
1800 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
1801 hw->phy.media_type = e1000_media_type_copper;
1802 dev_spec->sgmii_active = true;
1808 /* do not change link mode for 100BaseFX */
1809 if (dev_spec->eth_flags.e100_base_fx)
1812 /* change current link mode setting */
1813 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
1815 if (hw->phy.media_type == e1000_media_type_copper)
1816 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
1818 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1820 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1829 * e1000_set_sfp_media_type_82575 - derives SFP module media type.
1830 * @hw: pointer to the HW structure
1832 * The media type is chosen based on SFP module.
1833 * compatibility flags retrieved from SFP ID EEPROM.
1835 STATIC s32 e1000_set_sfp_media_type_82575(struct e1000_hw *hw)
1837 s32 ret_val = E1000_ERR_CONFIG;
1839 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1840 struct sfp_e1000_flags *eth_flags = &dev_spec->eth_flags;
1841 u8 tranceiver_type = 0;
1844 /* Turn I2C interface ON and power on sfp cage */
1845 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1846 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1847 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
1849 E1000_WRITE_FLUSH(hw);
1851 /* Read SFP module data */
1853 ret_val = e1000_read_sfp_data_byte(hw,
1854 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
1856 if (ret_val == E1000_SUCCESS)
1861 if (ret_val != E1000_SUCCESS)
1864 ret_val = e1000_read_sfp_data_byte(hw,
1865 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
1867 if (ret_val != E1000_SUCCESS)
1870 /* Check if there is some SFP module plugged and powered */
1871 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
1872 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
1873 dev_spec->module_plugged = true;
1874 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
1875 hw->phy.media_type = e1000_media_type_internal_serdes;
1876 } else if (eth_flags->e100_base_fx) {
1877 dev_spec->sgmii_active = true;
1878 hw->phy.media_type = e1000_media_type_internal_serdes;
1879 } else if (eth_flags->e1000_base_t) {
1880 dev_spec->sgmii_active = true;
1881 hw->phy.media_type = e1000_media_type_copper;
1883 hw->phy.media_type = e1000_media_type_unknown;
1884 DEBUGOUT("PHY module has not been recognized\n");
1888 hw->phy.media_type = e1000_media_type_unknown;
1890 ret_val = E1000_SUCCESS;
1892 /* Restore I2C interface setting */
1893 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1898 * e1000_valid_led_default_82575 - Verify a valid default LED config
1899 * @hw: pointer to the HW structure
1900 * @data: pointer to the NVM (EEPROM)
1902 * Read the EEPROM for the current default LED configuration. If the
1903 * LED configuration is not valid, set to a valid LED configuration.
1905 STATIC s32 e1000_valid_led_default_82575(struct e1000_hw *hw, u16 *data)
1909 DEBUGFUNC("e1000_valid_led_default_82575");
1911 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1913 DEBUGOUT("NVM Read Error\n");
1917 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1918 switch (hw->phy.media_type) {
1919 case e1000_media_type_internal_serdes:
1920 *data = ID_LED_DEFAULT_82575_SERDES;
1922 case e1000_media_type_copper:
1924 *data = ID_LED_DEFAULT;
1933 * e1000_sgmii_active_82575 - Return sgmii state
1934 * @hw: pointer to the HW structure
1936 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1937 * which can be enabled for use in the embedded applications. Simply
1938 * return the current state of the sgmii interface.
1940 STATIC bool e1000_sgmii_active_82575(struct e1000_hw *hw)
1942 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1943 return dev_spec->sgmii_active;
1947 * e1000_reset_init_script_82575 - Inits HW defaults after reset
1948 * @hw: pointer to the HW structure
1950 * Inits recommended HW defaults after a reset when there is no EEPROM
1951 * detected. This is only for the 82575.
1953 STATIC s32 e1000_reset_init_script_82575(struct e1000_hw *hw)
1955 DEBUGFUNC("e1000_reset_init_script_82575");
1957 if (hw->mac.type == e1000_82575) {
1958 DEBUGOUT("Running reset init script for 82575\n");
1959 /* SerDes configuration via SERDESCTRL */
1960 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x00, 0x0C);
1961 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x01, 0x78);
1962 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x1B, 0x23);
1963 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCTL, 0x23, 0x15);
1965 /* CCM configuration via CCMCTL register */
1966 e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x14, 0x00);
1967 e1000_write_8bit_ctrl_reg_generic(hw, E1000_CCMCTL, 0x10, 0x00);
1969 /* PCIe lanes configuration */
1970 e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x00, 0xEC);
1971 e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x61, 0xDF);
1972 e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x34, 0x05);
1973 e1000_write_8bit_ctrl_reg_generic(hw, E1000_GIOCTL, 0x2F, 0x81);
1975 /* PCIe PLL Configuration */
1976 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x02, 0x47);
1977 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x14, 0x00);
1978 e1000_write_8bit_ctrl_reg_generic(hw, E1000_SCCTL, 0x10, 0x00);
1981 return E1000_SUCCESS;
1985 * e1000_read_mac_addr_82575 - Read device MAC address
1986 * @hw: pointer to the HW structure
1988 STATIC s32 e1000_read_mac_addr_82575(struct e1000_hw *hw)
1992 DEBUGFUNC("e1000_read_mac_addr_82575");
1995 * If there's an alternate MAC address place it in RAR0
1996 * so that it will override the Si installed default perm
1999 ret_val = e1000_check_alt_mac_addr_generic(hw);
2003 ret_val = e1000_read_mac_addr_generic(hw);
2010 * e1000_config_collision_dist_82575 - Configure collision distance
2011 * @hw: pointer to the HW structure
2013 * Configures the collision distance to the default value and is used
2014 * during link setup.
2016 STATIC void e1000_config_collision_dist_82575(struct e1000_hw *hw)
2020 DEBUGFUNC("e1000_config_collision_dist_82575");
2022 tctl_ext = E1000_READ_REG(hw, E1000_TCTL_EXT);
2024 tctl_ext &= ~E1000_TCTL_EXT_COLD;
2025 tctl_ext |= E1000_COLLISION_DISTANCE << E1000_TCTL_EXT_COLD_SHIFT;
2027 E1000_WRITE_REG(hw, E1000_TCTL_EXT, tctl_ext);
2028 E1000_WRITE_FLUSH(hw);
2032 * e1000_power_down_phy_copper_82575 - Remove link during PHY power down
2033 * @hw: pointer to the HW structure
2035 * In the case of a PHY power down to save power, or to turn off link during a
2036 * driver unload, or wake on lan is not enabled, remove the link.
2038 STATIC void e1000_power_down_phy_copper_82575(struct e1000_hw *hw)
2040 struct e1000_phy_info *phy = &hw->phy;
2042 if (!(phy->ops.check_reset_block))
2045 /* If the management interface is not enabled, then power down */
2046 if (!(e1000_enable_mng_pass_thru(hw) || phy->ops.check_reset_block(hw)))
2047 e1000_power_down_phy_copper(hw);
2053 * e1000_clear_hw_cntrs_82575 - Clear device specific hardware counters
2054 * @hw: pointer to the HW structure
2056 * Clears the hardware counters by reading the counter registers.
2058 STATIC void e1000_clear_hw_cntrs_82575(struct e1000_hw *hw)
2060 DEBUGFUNC("e1000_clear_hw_cntrs_82575");
2062 e1000_clear_hw_cntrs_base_generic(hw);
2064 E1000_READ_REG(hw, E1000_PRC64);
2065 E1000_READ_REG(hw, E1000_PRC127);
2066 E1000_READ_REG(hw, E1000_PRC255);
2067 E1000_READ_REG(hw, E1000_PRC511);
2068 E1000_READ_REG(hw, E1000_PRC1023);
2069 E1000_READ_REG(hw, E1000_PRC1522);
2070 E1000_READ_REG(hw, E1000_PTC64);
2071 E1000_READ_REG(hw, E1000_PTC127);
2072 E1000_READ_REG(hw, E1000_PTC255);
2073 E1000_READ_REG(hw, E1000_PTC511);
2074 E1000_READ_REG(hw, E1000_PTC1023);
2075 E1000_READ_REG(hw, E1000_PTC1522);
2077 E1000_READ_REG(hw, E1000_ALGNERRC);
2078 E1000_READ_REG(hw, E1000_RXERRC);
2079 E1000_READ_REG(hw, E1000_TNCRS);
2080 E1000_READ_REG(hw, E1000_CEXTERR);
2081 E1000_READ_REG(hw, E1000_TSCTC);
2082 E1000_READ_REG(hw, E1000_TSCTFC);
2084 E1000_READ_REG(hw, E1000_MGTPRC);
2085 E1000_READ_REG(hw, E1000_MGTPDC);
2086 E1000_READ_REG(hw, E1000_MGTPTC);
2088 E1000_READ_REG(hw, E1000_IAC);
2089 E1000_READ_REG(hw, E1000_ICRXOC);
2091 E1000_READ_REG(hw, E1000_ICRXPTC);
2092 E1000_READ_REG(hw, E1000_ICRXATC);
2093 E1000_READ_REG(hw, E1000_ICTXPTC);
2094 E1000_READ_REG(hw, E1000_ICTXATC);
2095 E1000_READ_REG(hw, E1000_ICTXQEC);
2096 E1000_READ_REG(hw, E1000_ICTXQMTC);
2097 E1000_READ_REG(hw, E1000_ICRXDMTC);
2099 E1000_READ_REG(hw, E1000_CBTMPC);
2100 E1000_READ_REG(hw, E1000_HTDPMC);
2101 E1000_READ_REG(hw, E1000_CBRMPC);
2102 E1000_READ_REG(hw, E1000_RPTHC);
2103 E1000_READ_REG(hw, E1000_HGPTC);
2104 E1000_READ_REG(hw, E1000_HTCBDPC);
2105 E1000_READ_REG(hw, E1000_HGORCL);
2106 E1000_READ_REG(hw, E1000_HGORCH);
2107 E1000_READ_REG(hw, E1000_HGOTCL);
2108 E1000_READ_REG(hw, E1000_HGOTCH);
2109 E1000_READ_REG(hw, E1000_LENERRS);
2111 /* This register should not be read in copper configurations */
2112 if ((hw->phy.media_type == e1000_media_type_internal_serdes) ||
2113 e1000_sgmii_active_82575(hw))
2114 E1000_READ_REG(hw, E1000_SCVPC);
2118 * e1000_rx_fifo_flush_82575 - Clean rx fifo after Rx enable
2119 * @hw: pointer to the HW structure
2121 * After rx enable if managability is enabled then there is likely some
2122 * bad data at the start of the fifo and possibly in the DMA fifo. This
2123 * function clears the fifos and flushes any packets that came in as rx was
2126 void e1000_rx_fifo_flush_82575(struct e1000_hw *hw)
2128 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
2131 DEBUGFUNC("e1000_rx_fifo_workaround_82575");
2132 if (hw->mac.type != e1000_82575 ||
2133 !(E1000_READ_REG(hw, E1000_MANC) & E1000_MANC_RCV_TCO_EN))
2136 /* Disable all Rx queues */
2137 for (i = 0; i < 4; i++) {
2138 rxdctl[i] = E1000_READ_REG(hw, E1000_RXDCTL(i));
2139 E1000_WRITE_REG(hw, E1000_RXDCTL(i),
2140 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
2142 /* Poll all queues to verify they have shut down */
2143 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
2146 for (i = 0; i < 4; i++)
2147 rx_enabled |= E1000_READ_REG(hw, E1000_RXDCTL(i));
2148 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
2153 DEBUGOUT("Queue disable timed out after 10ms\n");
2155 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
2156 * incoming packets are rejected. Set enable and wait 2ms so that
2157 * any packet that was coming in as RCTL.EN was set is flushed
2159 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2160 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
2162 rlpml = E1000_READ_REG(hw, E1000_RLPML);
2163 E1000_WRITE_REG(hw, E1000_RLPML, 0);
2165 rctl = E1000_READ_REG(hw, E1000_RCTL);
2166 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
2167 temp_rctl |= E1000_RCTL_LPE;
2169 E1000_WRITE_REG(hw, E1000_RCTL, temp_rctl);
2170 E1000_WRITE_REG(hw, E1000_RCTL, temp_rctl | E1000_RCTL_EN);
2171 E1000_WRITE_FLUSH(hw);
2174 /* Enable Rx queues that were previously enabled and restore our
2177 for (i = 0; i < 4; i++)
2178 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl[i]);
2179 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2180 E1000_WRITE_FLUSH(hw);
2182 E1000_WRITE_REG(hw, E1000_RLPML, rlpml);
2183 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
2185 /* Flush receive errors generated by workaround */
2186 E1000_READ_REG(hw, E1000_ROC);
2187 E1000_READ_REG(hw, E1000_RNBC);
2188 E1000_READ_REG(hw, E1000_MPC);
2192 * e1000_set_pcie_completion_timeout - set pci-e completion timeout
2193 * @hw: pointer to the HW structure
2195 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2196 * however the hardware default for these parts is 500us to 1ms which is less
2197 * than the 10ms recommended by the pci-e spec. To address this we need to
2198 * increase the value to either 10ms to 200ms for capability version 1 config,
2199 * or 16ms to 55ms for version 2.
2201 STATIC s32 e1000_set_pcie_completion_timeout(struct e1000_hw *hw)
2203 u32 gcr = E1000_READ_REG(hw, E1000_GCR);
2204 s32 ret_val = E1000_SUCCESS;
2207 /* only take action if timeout value is defaulted to 0 */
2208 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2212 * if capababilities version is type 1 we can write the
2213 * timeout of 10ms to 200ms through the GCR register
2215 if (!(gcr & E1000_GCR_CAP_VER2)) {
2216 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2221 * for version 2 capabilities we need to write the config space
2222 * directly in order to set the completion timeout value for
2225 ret_val = e1000_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2230 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2232 ret_val = e1000_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2235 /* disable completion timeout resend */
2236 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2238 E1000_WRITE_REG(hw, E1000_GCR, gcr);
2243 * e1000_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2244 * @hw: pointer to the hardware struct
2245 * @enable: state to enter, either enabled or disabled
2246 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2248 * enables/disables L2 switch anti-spoofing functionality.
2250 void e1000_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2252 u32 reg_val, reg_offset;
2254 switch (hw->mac.type) {
2256 reg_offset = E1000_DTXSWC;
2260 reg_offset = E1000_TXSWC;
2266 reg_val = E1000_READ_REG(hw, reg_offset);
2268 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2269 E1000_DTXSWC_VLAN_SPOOF_MASK);
2270 /* The PF can spoof - it has to in order to
2271 * support emulation mode NICs
2273 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2275 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2276 E1000_DTXSWC_VLAN_SPOOF_MASK);
2278 E1000_WRITE_REG(hw, reg_offset, reg_val);
2282 * e1000_vmdq_set_loopback_pf - enable or disable vmdq loopback
2283 * @hw: pointer to the hardware struct
2284 * @enable: state to enter, either enabled or disabled
2286 * enables/disables L2 switch loopback functionality.
2288 void e1000_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2292 switch (hw->mac.type) {
2294 dtxswc = E1000_READ_REG(hw, E1000_DTXSWC);
2296 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2298 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2299 E1000_WRITE_REG(hw, E1000_DTXSWC, dtxswc);
2303 dtxswc = E1000_READ_REG(hw, E1000_TXSWC);
2305 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2307 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2308 E1000_WRITE_REG(hw, E1000_TXSWC, dtxswc);
2311 /* Currently no other hardware supports loopback */
2319 * e1000_vmdq_set_replication_pf - enable or disable vmdq replication
2320 * @hw: pointer to the hardware struct
2321 * @enable: state to enter, either enabled or disabled
2323 * enables/disables replication of packets across multiple pools.
2325 void e1000_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2327 u32 vt_ctl = E1000_READ_REG(hw, E1000_VT_CTL);
2330 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2332 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2334 E1000_WRITE_REG(hw, E1000_VT_CTL, vt_ctl);
2338 * e1000_read_phy_reg_82580 - Read 82580 MDI control register
2339 * @hw: pointer to the HW structure
2340 * @offset: register offset to be read
2341 * @data: pointer to the read data
2343 * Reads the MDI control register in the PHY at offset and stores the
2344 * information read to data.
2346 STATIC s32 e1000_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2350 DEBUGFUNC("e1000_read_phy_reg_82580");
2352 ret_val = hw->phy.ops.acquire(hw);
2356 ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
2358 hw->phy.ops.release(hw);
2365 * e1000_write_phy_reg_82580 - Write 82580 MDI control register
2366 * @hw: pointer to the HW structure
2367 * @offset: register offset to write to
2368 * @data: data to write to register at offset
2370 * Writes data to MDI control register in the PHY at offset.
2372 STATIC s32 e1000_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2376 DEBUGFUNC("e1000_write_phy_reg_82580");
2378 ret_val = hw->phy.ops.acquire(hw);
2382 ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
2384 hw->phy.ops.release(hw);
2391 * e1000_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2392 * @hw: pointer to the HW structure
2394 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2395 * the values found in the EEPROM. This addresses an issue in which these
2396 * bits are not restored from EEPROM after reset.
2398 STATIC s32 e1000_reset_mdicnfg_82580(struct e1000_hw *hw)
2400 s32 ret_val = E1000_SUCCESS;
2404 DEBUGFUNC("e1000_reset_mdicnfg_82580");
2406 if (hw->mac.type != e1000_82580)
2408 if (!e1000_sgmii_active_82575(hw))
2411 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2412 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2415 DEBUGOUT("NVM Read Error\n");
2419 mdicnfg = E1000_READ_REG(hw, E1000_MDICNFG);
2420 if (nvm_data & NVM_WORD24_EXT_MDIO)
2421 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2422 if (nvm_data & NVM_WORD24_COM_MDIO)
2423 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2424 E1000_WRITE_REG(hw, E1000_MDICNFG, mdicnfg);
2430 * e1000_reset_hw_82580 - Reset hardware
2431 * @hw: pointer to the HW structure
2433 * This resets function or entire device (all ports, etc.)
2436 STATIC s32 e1000_reset_hw_82580(struct e1000_hw *hw)
2438 s32 ret_val = E1000_SUCCESS;
2439 /* BH SW mailbox bit in SW_FW_SYNC */
2440 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
2442 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2444 DEBUGFUNC("e1000_reset_hw_82580");
2446 hw->dev_spec._82575.global_device_reset = false;
2448 /* 82580 does not reliably do global_device_reset due to hw errata */
2449 if (hw->mac.type == e1000_82580)
2450 global_device_reset = false;
2452 /* Get current control state. */
2453 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2456 * Prevent the PCI-E bus from sticking if there is no TLP connection
2457 * on the last TLP read/write transaction when MAC is reset.
2459 ret_val = e1000_disable_pcie_master_generic(hw);
2461 DEBUGOUT("PCI-E Master disable polling has failed.\n");
2463 DEBUGOUT("Masking off all interrupts\n");
2464 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2465 E1000_WRITE_REG(hw, E1000_RCTL, 0);
2466 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
2467 E1000_WRITE_FLUSH(hw);
2471 /* Determine whether or not a global dev reset is requested */
2472 if (global_device_reset && hw->mac.ops.acquire_swfw_sync(hw,
2474 global_device_reset = false;
2476 if (global_device_reset && !(E1000_READ_REG(hw, E1000_STATUS) &
2477 E1000_STAT_DEV_RST_SET))
2478 ctrl |= E1000_CTRL_DEV_RST;
2480 ctrl |= E1000_CTRL_RST;
2482 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2483 E1000_WRITE_FLUSH(hw);
2485 /* Add delay to insure DEV_RST has time to complete */
2486 if (global_device_reset)
2489 ret_val = e1000_get_auto_rd_done_generic(hw);
2492 * When auto config read does not complete, do not
2493 * return with an error. This can happen in situations
2494 * where there is no eeprom and prevents getting link.
2496 DEBUGOUT("Auto Read Done did not complete\n");
2499 /* clear global device reset status bit */
2500 E1000_WRITE_REG(hw, E1000_STATUS, E1000_STAT_DEV_RST_SET);
2502 /* Clear any pending interrupt events. */
2503 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2504 E1000_READ_REG(hw, E1000_ICR);
2506 ret_val = e1000_reset_mdicnfg_82580(hw);
2508 DEBUGOUT("Could not reset MDICNFG based on EEPROM\n");
2510 /* Install any alternate MAC address into RAR0 */
2511 ret_val = e1000_check_alt_mac_addr_generic(hw);
2513 /* Release semaphore */
2514 if (global_device_reset)
2515 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
2521 * e1000_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual Rx PBA size
2522 * @data: data received by reading RXPBS register
2524 * The 82580 uses a table based approach for packet buffer allocation sizes.
2525 * This function converts the retrieved value into the correct table value
2526 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2527 * 0x0 36 72 144 1 2 4 8 16
2528 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2530 u16 e1000_rxpbs_adjust_82580(u32 data)
2534 if (data < E1000_82580_RXPBS_TABLE_SIZE)
2535 ret_val = e1000_82580_rxpbs_table[data];
2541 * e1000_validate_nvm_checksum_with_offset - Validate EEPROM
2543 * @hw: pointer to the HW structure
2544 * @offset: offset in words of the checksum protected region
2546 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2547 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2549 s32 e1000_validate_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2551 s32 ret_val = E1000_SUCCESS;
2555 DEBUGFUNC("e1000_validate_nvm_checksum_with_offset");
2557 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2558 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2560 DEBUGOUT("NVM Read Error\n");
2563 checksum += nvm_data;
2566 if (checksum != (u16) NVM_SUM) {
2567 DEBUGOUT("NVM Checksum Invalid\n");
2568 ret_val = -E1000_ERR_NVM;
2577 * e1000_update_nvm_checksum_with_offset - Update EEPROM
2579 * @hw: pointer to the HW structure
2580 * @offset: offset in words of the checksum protected region
2582 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2583 * up to the checksum. Then calculates the EEPROM checksum and writes the
2584 * value to the EEPROM.
2586 s32 e1000_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
2592 DEBUGFUNC("e1000_update_nvm_checksum_with_offset");
2594 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2595 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2597 DEBUGOUT("NVM Read Error while updating checksum.\n");
2600 checksum += nvm_data;
2602 checksum = (u16) NVM_SUM - checksum;
2603 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2606 DEBUGOUT("NVM Write Error while updating checksum.\n");
2613 * e1000_validate_nvm_checksum_82580 - Validate EEPROM checksum
2614 * @hw: pointer to the HW structure
2616 * Calculates the EEPROM section checksum by reading/adding each word of
2617 * the EEPROM and then verifies that the sum of the EEPROM is
2620 STATIC s32 e1000_validate_nvm_checksum_82580(struct e1000_hw *hw)
2623 u16 eeprom_regions_count = 1;
2627 DEBUGFUNC("e1000_validate_nvm_checksum_82580");
2629 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2631 DEBUGOUT("NVM Read Error\n");
2635 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
2636 /* if chekcsums compatibility bit is set validate checksums
2637 * for all 4 ports. */
2638 eeprom_regions_count = 4;
2641 for (j = 0; j < eeprom_regions_count; j++) {
2642 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2643 ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2645 if (ret_val != E1000_SUCCESS)
2654 * e1000_update_nvm_checksum_82580 - Update EEPROM checksum
2655 * @hw: pointer to the HW structure
2657 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2658 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2659 * checksum and writes the value to the EEPROM.
2661 STATIC s32 e1000_update_nvm_checksum_82580(struct e1000_hw *hw)
2667 DEBUGFUNC("e1000_update_nvm_checksum_82580");
2669 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2671 DEBUGOUT("NVM Read Error while updating checksum compatibility bit.\n");
2675 if (!(nvm_data & NVM_COMPATIBILITY_BIT_MASK)) {
2676 /* set compatibility bit to validate checksums appropriately */
2677 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2678 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2681 DEBUGOUT("NVM Write Error while updating checksum compatibility bit.\n");
2686 for (j = 0; j < 4; j++) {
2687 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2688 ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2698 * e1000_validate_nvm_checksum_i350 - Validate EEPROM checksum
2699 * @hw: pointer to the HW structure
2701 * Calculates the EEPROM section checksum by reading/adding each word of
2702 * the EEPROM and then verifies that the sum of the EEPROM is
2705 STATIC s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw)
2707 s32 ret_val = E1000_SUCCESS;
2711 DEBUGFUNC("e1000_validate_nvm_checksum_i350");
2713 for (j = 0; j < 4; j++) {
2714 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2715 ret_val = e1000_validate_nvm_checksum_with_offset(hw,
2717 if (ret_val != E1000_SUCCESS)
2726 * e1000_update_nvm_checksum_i350 - Update EEPROM checksum
2727 * @hw: pointer to the HW structure
2729 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2730 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2731 * checksum and writes the value to the EEPROM.
2733 STATIC s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw)
2735 s32 ret_val = E1000_SUCCESS;
2739 DEBUGFUNC("e1000_update_nvm_checksum_i350");
2741 for (j = 0; j < 4; j++) {
2742 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2743 ret_val = e1000_update_nvm_checksum_with_offset(hw, nvm_offset);
2744 if (ret_val != E1000_SUCCESS)
2753 * __e1000_access_emi_reg - Read/write EMI register
2754 * @hw: pointer to the HW structure
2755 * @addr: EMI address to program
2756 * @data: pointer to value to read/write from/to the EMI address
2757 * @read: boolean flag to indicate read or write
2759 STATIC s32 __e1000_access_emi_reg(struct e1000_hw *hw, u16 address,
2760 u16 *data, bool read)
2764 DEBUGFUNC("__e1000_access_emi_reg");
2766 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2771 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2773 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2779 * e1000_read_emi_reg - Read Extended Management Interface register
2780 * @hw: pointer to the HW structure
2781 * @addr: EMI address to program
2782 * @data: value to be read from the EMI address
2784 s32 e1000_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2786 DEBUGFUNC("e1000_read_emi_reg");
2788 return __e1000_access_emi_reg(hw, addr, data, true);
2792 * e1000_set_eee_i350 - Enable/disable EEE support
2793 * @hw: pointer to the HW structure
2795 * Enable/disable EEE based on setting in dev_spec structure.
2798 s32 e1000_set_eee_i350(struct e1000_hw *hw)
2800 s32 ret_val = E1000_SUCCESS;
2803 DEBUGFUNC("e1000_set_eee_i350");
2805 if ((hw->mac.type < e1000_i350) ||
2806 (hw->phy.media_type != e1000_media_type_copper))
2808 ipcnfg = E1000_READ_REG(hw, E1000_IPCNFG);
2809 eeer = E1000_READ_REG(hw, E1000_EEER);
2811 /* enable or disable per user setting */
2812 if (!(hw->dev_spec._82575.eee_disable)) {
2813 u32 eee_su = E1000_READ_REG(hw, E1000_EEE_SU);
2815 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2816 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2819 /* This bit should not be set in normal operation. */
2820 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2821 DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
2823 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2824 eeer &= ~(E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
2827 E1000_WRITE_REG(hw, E1000_IPCNFG, ipcnfg);
2828 E1000_WRITE_REG(hw, E1000_EEER, eeer);
2829 E1000_READ_REG(hw, E1000_IPCNFG);
2830 E1000_READ_REG(hw, E1000_EEER);
2837 * e1000_set_eee_i354 - Enable/disable EEE support
2838 * @hw: pointer to the HW structure
2840 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2843 s32 e1000_set_eee_i354(struct e1000_hw *hw)
2845 struct e1000_phy_info *phy = &hw->phy;
2846 s32 ret_val = E1000_SUCCESS;
2849 DEBUGFUNC("e1000_set_eee_i354");
2851 if ((hw->phy.media_type != e1000_media_type_copper) ||
2852 ((phy->id != M88E1543_E_PHY_ID) &&
2853 (phy->id != M88E1512_E_PHY_ID)))
2856 if (!hw->dev_spec._82575.eee_disable) {
2857 /* Switch to PHY page 18. */
2858 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
2862 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2867 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2868 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
2873 /* Return the PHY to page 0. */
2874 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2878 /* Turn on EEE advertisement. */
2879 ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2880 E1000_EEE_ADV_DEV_I354,
2885 phy_data |= E1000_EEE_ADV_100_SUPPORTED |
2886 E1000_EEE_ADV_1000_SUPPORTED;
2887 ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2888 E1000_EEE_ADV_DEV_I354,
2891 /* Turn off EEE advertisement. */
2892 ret_val = e1000_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2893 E1000_EEE_ADV_DEV_I354,
2898 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2899 E1000_EEE_ADV_1000_SUPPORTED);
2900 ret_val = e1000_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2901 E1000_EEE_ADV_DEV_I354,
2910 * e1000_get_eee_status_i354 - Get EEE status
2911 * @hw: pointer to the HW structure
2912 * @status: EEE status
2914 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2917 s32 e1000_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2919 struct e1000_phy_info *phy = &hw->phy;
2920 s32 ret_val = E1000_SUCCESS;
2923 DEBUGFUNC("e1000_get_eee_status_i354");
2925 /* Check if EEE is supported on this device. */
2926 if ((hw->phy.media_type != e1000_media_type_copper) ||
2927 ((phy->id != M88E1543_E_PHY_ID) &&
2928 (phy->id != M88E1512_E_PHY_ID)))
2931 ret_val = e1000_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2932 E1000_PCS_STATUS_DEV_I354,
2937 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2938 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2944 /* Due to a hw errata, if the host tries to configure the VFTA register
2945 * while performing queries from the BMC or DMA, then the VFTA in some
2946 * cases won't be written.
2950 * e1000_clear_vfta_i350 - Clear VLAN filter table
2951 * @hw: pointer to the HW structure
2953 * Clears the register array which contains the VLAN filter table by
2954 * setting all the values to 0.
2956 void e1000_clear_vfta_i350(struct e1000_hw *hw)
2961 DEBUGFUNC("e1000_clear_vfta_350");
2963 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
2964 for (i = 0; i < 10; i++)
2965 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
2967 E1000_WRITE_FLUSH(hw);
2972 * e1000_write_vfta_i350 - Write value to VLAN filter table
2973 * @hw: pointer to the HW structure
2974 * @offset: register offset in VLAN filter table
2975 * @value: register value written to VLAN filter table
2977 * Writes value at the given offset in the register array which stores
2978 * the VLAN filter table.
2980 void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
2984 DEBUGFUNC("e1000_write_vfta_350");
2986 for (i = 0; i < 10; i++)
2987 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
2989 E1000_WRITE_FLUSH(hw);
2994 * e1000_set_i2c_bb - Enable I2C bit-bang
2995 * @hw: pointer to the HW structure
2997 * Enable I2C bit-bang interface
3000 s32 e1000_set_i2c_bb(struct e1000_hw *hw)
3002 s32 ret_val = E1000_SUCCESS;
3003 u32 ctrl_ext, i2cparams;
3005 DEBUGFUNC("e1000_set_i2c_bb");
3007 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
3008 ctrl_ext |= E1000_CTRL_I2C_ENA;
3009 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
3010 E1000_WRITE_FLUSH(hw);
3012 i2cparams = E1000_READ_REG(hw, E1000_I2CPARAMS);
3013 i2cparams |= E1000_I2CBB_EN;
3014 i2cparams |= E1000_I2C_DATA_OE_N;
3015 i2cparams |= E1000_I2C_CLK_OE_N;
3016 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cparams);
3017 E1000_WRITE_FLUSH(hw);
3023 * e1000_read_i2c_byte_generic - Reads 8 bit word over I2C
3024 * @hw: pointer to hardware structure
3025 * @byte_offset: byte offset to read
3026 * @dev_addr: device address
3029 * Performs byte read operation over I2C interface at
3030 * a specified device address.
3032 s32 e1000_read_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3033 u8 dev_addr, u8 *data)
3035 s32 status = E1000_SUCCESS;
3042 DEBUGFUNC("e1000_read_i2c_byte_generic");
3044 swfw_mask = E1000_SWFW_PHY0_SM;
3047 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
3049 status = E1000_ERR_SWFW_SYNC;
3053 e1000_i2c_start(hw);
3055 /* Device Address and write indication */
3056 status = e1000_clock_out_i2c_byte(hw, dev_addr);
3057 if (status != E1000_SUCCESS)
3060 status = e1000_get_i2c_ack(hw);
3061 if (status != E1000_SUCCESS)
3064 status = e1000_clock_out_i2c_byte(hw, byte_offset);
3065 if (status != E1000_SUCCESS)
3068 status = e1000_get_i2c_ack(hw);
3069 if (status != E1000_SUCCESS)
3072 e1000_i2c_start(hw);
3074 /* Device Address and read indication */
3075 status = e1000_clock_out_i2c_byte(hw, (dev_addr | 0x1));
3076 if (status != E1000_SUCCESS)
3079 status = e1000_get_i2c_ack(hw);
3080 if (status != E1000_SUCCESS)
3083 status = e1000_clock_in_i2c_byte(hw, data);
3084 if (status != E1000_SUCCESS)
3087 status = e1000_clock_out_i2c_bit(hw, nack);
3088 if (status != E1000_SUCCESS)
3095 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3097 e1000_i2c_bus_clear(hw);
3099 if (retry < max_retry)
3100 DEBUGOUT("I2C byte read error - Retrying.\n");
3102 DEBUGOUT("I2C byte read error.\n");
3104 } while (retry < max_retry);
3106 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3114 * e1000_write_i2c_byte_generic - Writes 8 bit word over I2C
3115 * @hw: pointer to hardware structure
3116 * @byte_offset: byte offset to write
3117 * @dev_addr: device address
3118 * @data: value to write
3120 * Performs byte write operation over I2C interface at
3121 * a specified device address.
3123 s32 e1000_write_i2c_byte_generic(struct e1000_hw *hw, u8 byte_offset,
3124 u8 dev_addr, u8 data)
3126 s32 status = E1000_SUCCESS;
3131 DEBUGFUNC("e1000_write_i2c_byte_generic");
3133 swfw_mask = E1000_SWFW_PHY0_SM;
3135 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != E1000_SUCCESS) {
3136 status = E1000_ERR_SWFW_SYNC;
3137 goto write_byte_out;
3141 e1000_i2c_start(hw);
3143 status = e1000_clock_out_i2c_byte(hw, dev_addr);
3144 if (status != E1000_SUCCESS)
3147 status = e1000_get_i2c_ack(hw);
3148 if (status != E1000_SUCCESS)
3151 status = e1000_clock_out_i2c_byte(hw, byte_offset);
3152 if (status != E1000_SUCCESS)
3155 status = e1000_get_i2c_ack(hw);
3156 if (status != E1000_SUCCESS)
3159 status = e1000_clock_out_i2c_byte(hw, data);
3160 if (status != E1000_SUCCESS)
3163 status = e1000_get_i2c_ack(hw);
3164 if (status != E1000_SUCCESS)
3171 e1000_i2c_bus_clear(hw);
3173 if (retry < max_retry)
3174 DEBUGOUT("I2C byte write error - Retrying.\n");
3176 DEBUGOUT("I2C byte write error.\n");
3177 } while (retry < max_retry);
3179 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
3187 * e1000_i2c_start - Sets I2C start condition
3188 * @hw: pointer to hardware structure
3190 * Sets I2C start condition (High -> Low on SDA while SCL is High)
3192 STATIC void e1000_i2c_start(struct e1000_hw *hw)
3194 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3196 DEBUGFUNC("e1000_i2c_start");
3198 /* Start condition must begin with data and clock high */
3199 e1000_set_i2c_data(hw, &i2cctl, 1);
3200 e1000_raise_i2c_clk(hw, &i2cctl);
3202 /* Setup time for start condition (4.7us) */
3203 usec_delay(E1000_I2C_T_SU_STA);
3205 e1000_set_i2c_data(hw, &i2cctl, 0);
3207 /* Hold time for start condition (4us) */
3208 usec_delay(E1000_I2C_T_HD_STA);
3210 e1000_lower_i2c_clk(hw, &i2cctl);
3212 /* Minimum low period of clock is 4.7 us */
3213 usec_delay(E1000_I2C_T_LOW);
3218 * e1000_i2c_stop - Sets I2C stop condition
3219 * @hw: pointer to hardware structure
3221 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
3223 STATIC void e1000_i2c_stop(struct e1000_hw *hw)
3225 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3227 DEBUGFUNC("e1000_i2c_stop");
3229 /* Stop condition must begin with data low and clock high */
3230 e1000_set_i2c_data(hw, &i2cctl, 0);
3231 e1000_raise_i2c_clk(hw, &i2cctl);
3233 /* Setup time for stop condition (4us) */
3234 usec_delay(E1000_I2C_T_SU_STO);
3236 e1000_set_i2c_data(hw, &i2cctl, 1);
3238 /* bus free time between stop and start (4.7us)*/
3239 usec_delay(E1000_I2C_T_BUF);
3243 * e1000_clock_in_i2c_byte - Clocks in one byte via I2C
3244 * @hw: pointer to hardware structure
3245 * @data: data byte to clock in
3247 * Clocks in one byte data via I2C data/clock
3249 STATIC s32 e1000_clock_in_i2c_byte(struct e1000_hw *hw, u8 *data)
3254 DEBUGFUNC("e1000_clock_in_i2c_byte");
3257 for (i = 7; i >= 0; i--) {
3258 e1000_clock_in_i2c_bit(hw, &bit);
3262 return E1000_SUCCESS;
3266 * e1000_clock_out_i2c_byte - Clocks out one byte via I2C
3267 * @hw: pointer to hardware structure
3268 * @data: data byte clocked out
3270 * Clocks out one byte data via I2C data/clock
3272 STATIC s32 e1000_clock_out_i2c_byte(struct e1000_hw *hw, u8 data)
3274 s32 status = E1000_SUCCESS;
3279 DEBUGFUNC("e1000_clock_out_i2c_byte");
3281 for (i = 7; i >= 0; i--) {
3282 bit = (data >> i) & 0x1;
3283 status = e1000_clock_out_i2c_bit(hw, bit);
3285 if (status != E1000_SUCCESS)
3289 /* Release SDA line (set high) */
3290 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3292 i2cctl |= E1000_I2C_DATA_OE_N;
3293 E1000_WRITE_REG(hw, E1000_I2CPARAMS, i2cctl);
3294 E1000_WRITE_FLUSH(hw);
3300 * e1000_get_i2c_ack - Polls for I2C ACK
3301 * @hw: pointer to hardware structure
3303 * Clocks in/out one bit via I2C data/clock
3305 STATIC s32 e1000_get_i2c_ack(struct e1000_hw *hw)
3307 s32 status = E1000_SUCCESS;
3309 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3313 DEBUGFUNC("e1000_get_i2c_ack");
3315 e1000_raise_i2c_clk(hw, &i2cctl);
3317 /* Minimum high period of clock is 4us */
3318 usec_delay(E1000_I2C_T_HIGH);
3320 /* Wait until SCL returns high */
3321 for (i = 0; i < timeout; i++) {
3323 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3324 if (i2cctl & E1000_I2C_CLK_IN)
3327 if (!(i2cctl & E1000_I2C_CLK_IN))
3328 return E1000_ERR_I2C;
3330 ack = e1000_get_i2c_data(&i2cctl);
3332 DEBUGOUT("I2C ack was not received.\n");
3333 status = E1000_ERR_I2C;
3336 e1000_lower_i2c_clk(hw, &i2cctl);
3338 /* Minimum low period of clock is 4.7 us */
3339 usec_delay(E1000_I2C_T_LOW);
3345 * e1000_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
3346 * @hw: pointer to hardware structure
3347 * @data: read data value
3349 * Clocks in one bit via I2C data/clock
3351 STATIC s32 e1000_clock_in_i2c_bit(struct e1000_hw *hw, bool *data)
3353 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3355 DEBUGFUNC("e1000_clock_in_i2c_bit");
3357 e1000_raise_i2c_clk(hw, &i2cctl);
3359 /* Minimum high period of clock is 4us */
3360 usec_delay(E1000_I2C_T_HIGH);
3362 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3363 *data = e1000_get_i2c_data(&i2cctl);
3365 e1000_lower_i2c_clk(hw, &i2cctl);
3367 /* Minimum low period of clock is 4.7 us */
3368 usec_delay(E1000_I2C_T_LOW);
3370 return E1000_SUCCESS;
3374 * e1000_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
3375 * @hw: pointer to hardware structure
3376 * @data: data value to write
3378 * Clocks out one bit via I2C data/clock
3380 STATIC s32 e1000_clock_out_i2c_bit(struct e1000_hw *hw, bool data)
3383 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3385 DEBUGFUNC("e1000_clock_out_i2c_bit");
3387 status = e1000_set_i2c_data(hw, &i2cctl, data);
3388 if (status == E1000_SUCCESS) {
3389 e1000_raise_i2c_clk(hw, &i2cctl);
3391 /* Minimum high period of clock is 4us */
3392 usec_delay(E1000_I2C_T_HIGH);
3394 e1000_lower_i2c_clk(hw, &i2cctl);
3396 /* Minimum low period of clock is 4.7 us.
3397 * This also takes care of the data hold time.
3399 usec_delay(E1000_I2C_T_LOW);
3401 status = E1000_ERR_I2C;
3402 DEBUGOUT1("I2C data was not set to %X\n", data);
3408 * e1000_raise_i2c_clk - Raises the I2C SCL clock
3409 * @hw: pointer to hardware structure
3410 * @i2cctl: Current value of I2CCTL register
3412 * Raises the I2C clock line '0'->'1'
3414 STATIC void e1000_raise_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3416 DEBUGFUNC("e1000_raise_i2c_clk");
3418 *i2cctl |= E1000_I2C_CLK_OUT;
3419 *i2cctl &= ~E1000_I2C_CLK_OE_N;
3420 E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3421 E1000_WRITE_FLUSH(hw);
3423 /* SCL rise time (1000ns) */
3424 usec_delay(E1000_I2C_T_RISE);
3428 * e1000_lower_i2c_clk - Lowers the I2C SCL clock
3429 * @hw: pointer to hardware structure
3430 * @i2cctl: Current value of I2CCTL register
3432 * Lowers the I2C clock line '1'->'0'
3434 STATIC void e1000_lower_i2c_clk(struct e1000_hw *hw, u32 *i2cctl)
3437 DEBUGFUNC("e1000_lower_i2c_clk");
3439 *i2cctl &= ~E1000_I2C_CLK_OUT;
3440 *i2cctl &= ~E1000_I2C_CLK_OE_N;
3441 E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3442 E1000_WRITE_FLUSH(hw);
3444 /* SCL fall time (300ns) */
3445 usec_delay(E1000_I2C_T_FALL);
3449 * e1000_set_i2c_data - Sets the I2C data bit
3450 * @hw: pointer to hardware structure
3451 * @i2cctl: Current value of I2CCTL register
3452 * @data: I2C data value (0 or 1) to set
3454 * Sets the I2C data bit
3456 STATIC s32 e1000_set_i2c_data(struct e1000_hw *hw, u32 *i2cctl, bool data)
3458 s32 status = E1000_SUCCESS;
3460 DEBUGFUNC("e1000_set_i2c_data");
3463 *i2cctl |= E1000_I2C_DATA_OUT;
3465 *i2cctl &= ~E1000_I2C_DATA_OUT;
3467 *i2cctl &= ~E1000_I2C_DATA_OE_N;
3468 *i2cctl |= E1000_I2C_CLK_OE_N;
3469 E1000_WRITE_REG(hw, E1000_I2CPARAMS, *i2cctl);
3470 E1000_WRITE_FLUSH(hw);
3472 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
3473 usec_delay(E1000_I2C_T_RISE + E1000_I2C_T_FALL + E1000_I2C_T_SU_DATA);
3475 *i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3476 if (data != e1000_get_i2c_data(i2cctl)) {
3477 status = E1000_ERR_I2C;
3478 DEBUGOUT1("Error - I2C data was not set to %X.\n", data);
3485 * e1000_get_i2c_data - Reads the I2C SDA data bit
3486 * @hw: pointer to hardware structure
3487 * @i2cctl: Current value of I2CCTL register
3489 * Returns the I2C data bit value
3491 STATIC bool e1000_get_i2c_data(u32 *i2cctl)
3495 DEBUGFUNC("e1000_get_i2c_data");
3497 if (*i2cctl & E1000_I2C_DATA_IN)
3506 * e1000_i2c_bus_clear - Clears the I2C bus
3507 * @hw: pointer to hardware structure
3509 * Clears the I2C bus by sending nine clock pulses.
3510 * Used when data line is stuck low.
3512 void e1000_i2c_bus_clear(struct e1000_hw *hw)
3514 u32 i2cctl = E1000_READ_REG(hw, E1000_I2CPARAMS);
3517 DEBUGFUNC("e1000_i2c_bus_clear");
3519 e1000_i2c_start(hw);
3521 e1000_set_i2c_data(hw, &i2cctl, 1);
3523 for (i = 0; i < 9; i++) {
3524 e1000_raise_i2c_clk(hw, &i2cctl);
3526 /* Min high period of clock is 4us */
3527 usec_delay(E1000_I2C_T_HIGH);
3529 e1000_lower_i2c_clk(hw, &i2cctl);
3531 /* Min low period of clock is 4.7us*/
3532 usec_delay(E1000_I2C_T_LOW);
3535 e1000_i2c_start(hw);
3537 /* Put the i2c bus back to default state */