14919Sxy150489 /*
24919Sxy150489 * This file is provided under a CDDLv1 license. When using or
34919Sxy150489 * redistributing this file, you may do so under this license.
44919Sxy150489 * In redistributing this file this license must be included
54919Sxy150489 * and no other modification of this header file is permitted.
64919Sxy150489 *
74919Sxy150489 * CDDL LICENSE SUMMARY
84919Sxy150489 *
98479SChenlu.Chen@Sun.COM * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
104919Sxy150489 *
114919Sxy150489 * The contents of this file are subject to the terms of Version
124919Sxy150489 * 1.0 of the Common Development and Distribution License (the "License").
134919Sxy150489 *
144919Sxy150489 * You should have received a copy of the License with this software.
154919Sxy150489 * You can obtain a copy of the License at
164919Sxy150489 * http://www.opensolaris.org/os/licensing.
174919Sxy150489 * See the License for the specific language governing permissions
184919Sxy150489 * and limitations under the License.
194919Sxy150489 */
204919Sxy150489
214919Sxy150489 /*
228479SChenlu.Chen@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
234919Sxy150489 * Use is subject to license terms of the CDDLv1.
244919Sxy150489 */
254919Sxy150489
264919Sxy150489 /*
2711020SMin.Xu@Sun.COM * IntelVersion: 1.113 v3-1-10-1_2009-9-18_Release14-6
284919Sxy150489 */
296735Scc210113
304919Sxy150489 /*
318479SChenlu.Chen@Sun.COM * 82571EB Gigabit Ethernet Controller
328479SChenlu.Chen@Sun.COM * 82571EB Gigabit Ethernet Controller (Copper)
338479SChenlu.Chen@Sun.COM * 82571EB Gigabit Ethernet Controller (Fiber)
348479SChenlu.Chen@Sun.COM * 82571EB Dual Port Gigabit Mezzanine Adapter
358479SChenlu.Chen@Sun.COM * 82571EB Quad Port Gigabit Mezzanine Adapter
368479SChenlu.Chen@Sun.COM * 82571PT Gigabit PT Quad Port Server ExpressModule
378479SChenlu.Chen@Sun.COM * 82572EI Gigabit Ethernet Controller (Copper)
388479SChenlu.Chen@Sun.COM * 82572EI Gigabit Ethernet Controller (Fiber)
398479SChenlu.Chen@Sun.COM * 82572EI Gigabit Ethernet Controller
408479SChenlu.Chen@Sun.COM * 82573V Gigabit Ethernet Controller (Copper)
418479SChenlu.Chen@Sun.COM * 82573E Gigabit Ethernet Controller (Copper)
428479SChenlu.Chen@Sun.COM * 82573L Gigabit Ethernet Controller
438479SChenlu.Chen@Sun.COM * 82574L Gigabit Network Connection
4410680SMin.Xu@Sun.COM * 82583V Gigabit Network Connection
454919Sxy150489 */
464919Sxy150489
474919Sxy150489 #include "e1000_api.h"
484919Sxy150489
494919Sxy150489 static s32 e1000_init_phy_params_82571(struct e1000_hw *hw);
504919Sxy150489 static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw);
514919Sxy150489 static s32 e1000_init_mac_params_82571(struct e1000_hw *hw);
524919Sxy150489 static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw);
534919Sxy150489 static void e1000_release_nvm_82571(struct e1000_hw *hw);
544919Sxy150489 static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset,
554919Sxy150489 u16 words, u16 *data);
564919Sxy150489 static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw);
574919Sxy150489 static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw);
584919Sxy150489 static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw);
594919Sxy150489 static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw,
606735Scc210113 bool active);
614919Sxy150489 static s32 e1000_reset_hw_82571(struct e1000_hw *hw);
624919Sxy150489 static s32 e1000_init_hw_82571(struct e1000_hw *hw);
634919Sxy150489 static void e1000_clear_vfta_82571(struct e1000_hw *hw);
647607STed.You@Sun.COM static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
657607STed.You@Sun.COM static s32 e1000_led_on_82574(struct e1000_hw *hw);
664919Sxy150489 static s32 e1000_setup_link_82571(struct e1000_hw *hw);
674919Sxy150489 static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
6810680SMin.Xu@Sun.COM static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
694919Sxy150489 static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
704919Sxy150489 static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data);
714919Sxy150489 static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
7210680SMin.Xu@Sun.COM static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw);
734919Sxy150489 static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
744919Sxy150489 static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
754919Sxy150489 static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw);
764919Sxy150489 static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
774919Sxy150489 static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
784919Sxy150489 u16 words, u16 *data);
796735Scc210113 static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw);
806735Scc210113 static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw);
814919Sxy150489
824919Sxy150489 /*
834919Sxy150489 * e1000_init_phy_params_82571 - Init PHY func ptrs.
844919Sxy150489 * @hw: pointer to the HW structure
854919Sxy150489 */
864919Sxy150489 static s32
e1000_init_phy_params_82571(struct e1000_hw * hw)874919Sxy150489 e1000_init_phy_params_82571(struct e1000_hw *hw)
884919Sxy150489 {
894919Sxy150489 struct e1000_phy_info *phy = &hw->phy;
904919Sxy150489 s32 ret_val = E1000_SUCCESS;
914919Sxy150489
924919Sxy150489 DEBUGFUNC("e1000_init_phy_params_82571");
934919Sxy150489
946735Scc210113 if (hw->phy.media_type != e1000_media_type_copper) {
954919Sxy150489 phy->type = e1000_phy_none;
964919Sxy150489 goto out;
974919Sxy150489 }
984919Sxy150489
994919Sxy150489 phy->addr = 1;
1004919Sxy150489 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1014919Sxy150489 phy->reset_delay_us = 100;
1024919Sxy150489
1036735Scc210113 phy->ops.acquire = e1000_get_hw_semaphore_82571;
1046735Scc210113 phy->ops.check_polarity = e1000_check_polarity_igp;
1056735Scc210113 phy->ops.check_reset_block = e1000_check_reset_block_generic;
1066735Scc210113 phy->ops.release = e1000_put_hw_semaphore_82571;
1076735Scc210113 phy->ops.reset = e1000_phy_hw_reset_generic;
1086735Scc210113 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82571;
1096735Scc210113 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_generic;
1106735Scc210113 phy->ops.power_up = e1000_power_up_phy_copper;
1116735Scc210113 phy->ops.power_down = e1000_power_down_phy_copper_82571;
1124919Sxy150489
1134919Sxy150489 switch (hw->mac.type) {
1144919Sxy150489 case e1000_82571:
1154919Sxy150489 case e1000_82572:
1164919Sxy150489 phy->type = e1000_phy_igp_2;
1176735Scc210113 phy->ops.get_cfg_done = e1000_get_cfg_done_82571;
1186735Scc210113 phy->ops.get_info = e1000_get_phy_info_igp;
1196735Scc210113 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
1206735Scc210113 phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
1216735Scc210113 phy->ops.read_reg = e1000_read_phy_reg_igp;
1226735Scc210113 phy->ops.write_reg = e1000_write_phy_reg_igp;
1234919Sxy150489
1246735Scc210113 /* This uses above function pointers */
1256735Scc210113 ret_val = e1000_get_phy_id_82571(hw);
1264919Sxy150489
1276735Scc210113 /* Verify PHY ID */
1284919Sxy150489 if (phy->id != IGP01E1000_I_PHY_ID) {
1294919Sxy150489 ret_val = -E1000_ERR_PHY;
1304919Sxy150489 goto out;
1314919Sxy150489 }
1324919Sxy150489 break;
1334919Sxy150489 case e1000_82573:
1346735Scc210113 phy->type = e1000_phy_m88;
1356735Scc210113 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
1366735Scc210113 phy->ops.get_info = e1000_get_phy_info_m88;
1376735Scc210113 phy->ops.commit = e1000_phy_sw_reset_generic;
1386735Scc210113 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
1396735Scc210113 phy->ops.get_cable_length = e1000_get_cable_length_m88;
1406735Scc210113 phy->ops.read_reg = e1000_read_phy_reg_m88;
1416735Scc210113 phy->ops.write_reg = e1000_write_phy_reg_m88;
1426735Scc210113
1436735Scc210113 /* This uses above function pointers */
1446735Scc210113 ret_val = e1000_get_phy_id_82571(hw);
1456735Scc210113
1466735Scc210113 /* Verify PHY ID */
1474919Sxy150489 if (phy->id != M88E1111_I_PHY_ID) {
1484919Sxy150489 ret_val = -E1000_ERR_PHY;
1496735Scc210113 DEBUGOUT1("PHY ID unknown: type = 0x%08x\n", phy->id);
1504919Sxy150489 goto out;
1514919Sxy150489 }
1524919Sxy150489 break;
1537607STed.You@Sun.COM case e1000_82574:
15410680SMin.Xu@Sun.COM case e1000_82583:
1557607STed.You@Sun.COM phy->type = e1000_phy_bm;
1567607STed.You@Sun.COM phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
1577607STed.You@Sun.COM phy->ops.get_info = e1000_get_phy_info_m88;
1587607STed.You@Sun.COM phy->ops.commit = e1000_phy_sw_reset_generic;
1597607STed.You@Sun.COM phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
1607607STed.You@Sun.COM phy->ops.get_cable_length = e1000_get_cable_length_m88;
1617607STed.You@Sun.COM phy->ops.read_reg = e1000_read_phy_reg_bm2;
1627607STed.You@Sun.COM phy->ops.write_reg = e1000_write_phy_reg_bm2;
1637607STed.You@Sun.COM
1647607STed.You@Sun.COM /* This uses above function pointers */
1657607STed.You@Sun.COM ret_val = e1000_get_phy_id_82571(hw);
1667607STed.You@Sun.COM /* Verify PHY ID */
1677607STed.You@Sun.COM if (phy->id != BME1000_E_PHY_ID_R2) {
1687607STed.You@Sun.COM ret_val = -E1000_ERR_PHY;
1697607STed.You@Sun.COM DEBUGOUT1("PHY ID unknown: type = 0x%08x\n", phy->id);
1707607STed.You@Sun.COM goto out;
1717607STed.You@Sun.COM }
1727607STed.You@Sun.COM break;
1734919Sxy150489 default:
1744919Sxy150489 ret_val = -E1000_ERR_PHY;
1754919Sxy150489 goto out;
1764919Sxy150489 }
1774919Sxy150489
1784919Sxy150489 out:
1794919Sxy150489 return (ret_val);
1804919Sxy150489 }
1814919Sxy150489
1824919Sxy150489 /*
1834919Sxy150489 * e1000_init_nvm_params_82571 - Init NVM func ptrs.
1844919Sxy150489 * @hw: pointer to the HW structure
1854919Sxy150489 */
1864919Sxy150489 static s32
e1000_init_nvm_params_82571(struct e1000_hw * hw)1874919Sxy150489 e1000_init_nvm_params_82571(struct e1000_hw *hw)
1884919Sxy150489 {
1894919Sxy150489 struct e1000_nvm_info *nvm = &hw->nvm;
1904919Sxy150489 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
1914919Sxy150489 u16 size;
1924919Sxy150489
1934919Sxy150489 DEBUGFUNC("e1000_init_nvm_params_82571");
1944919Sxy150489
1954919Sxy150489 nvm->opcode_bits = 8;
1964919Sxy150489 nvm->delay_usec = 1;
1974919Sxy150489 switch (nvm->override) {
1984919Sxy150489 case e1000_nvm_override_spi_large:
1994919Sxy150489 nvm->page_size = 32;
2004919Sxy150489 nvm->address_bits = 16;
2014919Sxy150489 break;
2024919Sxy150489 case e1000_nvm_override_spi_small:
2034919Sxy150489 nvm->page_size = 8;
2044919Sxy150489 nvm->address_bits = 8;
2054919Sxy150489 break;
2064919Sxy150489 default:
2074919Sxy150489 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
2084919Sxy150489 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
2094919Sxy150489 break;
2104919Sxy150489 }
2114919Sxy150489
2124919Sxy150489 switch (hw->mac.type) {
2134919Sxy150489 case e1000_82573:
2147607STed.You@Sun.COM case e1000_82574:
21510680SMin.Xu@Sun.COM case e1000_82583:
2164919Sxy150489 if (((eecd >> 15) & 0x3) == 0x3) {
2174919Sxy150489 nvm->type = e1000_nvm_flash_hw;
2184919Sxy150489 nvm->word_size = 2048;
2194919Sxy150489 /*
2204919Sxy150489 * Autonomous Flash update bit must be cleared due
2214919Sxy150489 * to Flash update issue.
2224919Sxy150489 */
2234919Sxy150489 eecd &= ~E1000_EECD_AUPDEN;
2244919Sxy150489 E1000_WRITE_REG(hw, E1000_EECD, eecd);
2254919Sxy150489 break;
2264919Sxy150489 }
2274919Sxy150489 /* Fall Through */
2284919Sxy150489 default:
2294919Sxy150489 nvm->type = e1000_nvm_eeprom_spi;
2304919Sxy150489 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
2314919Sxy150489 E1000_EECD_SIZE_EX_SHIFT);
2324919Sxy150489 /*
2334919Sxy150489 * Added to a constant, "size" becomes the left-shift value
2344919Sxy150489 * for setting word_size.
2354919Sxy150489 */
2364919Sxy150489 size += NVM_WORD_SIZE_BASE_SHIFT;
2376735Scc210113
2386735Scc210113 /* EEPROM access above 16k is unsupported */
2396735Scc210113 if (size > 14)
2406735Scc210113 size = 14;
2414919Sxy150489 nvm->word_size = 1 << size;
2424919Sxy150489 break;
2434919Sxy150489 }
2444919Sxy150489
2454919Sxy150489 /* Function Pointers */
2466735Scc210113 nvm->ops.acquire = e1000_acquire_nvm_82571;
2476735Scc210113 nvm->ops.read = e1000_read_nvm_eerd;
2486735Scc210113 nvm->ops.release = e1000_release_nvm_82571;
2496735Scc210113 nvm->ops.update = e1000_update_nvm_checksum_82571;
2506735Scc210113 nvm->ops.validate = e1000_validate_nvm_checksum_82571;
2516735Scc210113 nvm->ops.valid_led_default = e1000_valid_led_default_82571;
2526735Scc210113 nvm->ops.write = e1000_write_nvm_82571;
2534919Sxy150489
2544919Sxy150489 return (E1000_SUCCESS);
2554919Sxy150489 }
2564919Sxy150489
2574919Sxy150489 /*
2584919Sxy150489 * e1000_init_mac_params_82571 - Init MAC func ptrs.
2594919Sxy150489 * @hw: pointer to the HW structure
2604919Sxy150489 */
2614919Sxy150489 static s32
e1000_init_mac_params_82571(struct e1000_hw * hw)2624919Sxy150489 e1000_init_mac_params_82571(struct e1000_hw *hw)
2634919Sxy150489 {
2644919Sxy150489 struct e1000_mac_info *mac = &hw->mac;
2654919Sxy150489 s32 ret_val = E1000_SUCCESS;
26610680SMin.Xu@Sun.COM u32 swsm = 0;
26710680SMin.Xu@Sun.COM u32 swsm2 = 0;
26810680SMin.Xu@Sun.COM bool force_clear_smbi = false;
2694919Sxy150489
2704919Sxy150489 DEBUGFUNC("e1000_init_mac_params_82571");
2714919Sxy150489
2724919Sxy150489 /* Set media type */
2734919Sxy150489 switch (hw->device_id) {
2744919Sxy150489 case E1000_DEV_ID_82571EB_FIBER:
2754919Sxy150489 case E1000_DEV_ID_82572EI_FIBER:
2764919Sxy150489 case E1000_DEV_ID_82571EB_QUAD_FIBER:
2776735Scc210113 hw->phy.media_type = e1000_media_type_fiber;
2784919Sxy150489 break;
2794919Sxy150489 case E1000_DEV_ID_82571EB_SERDES:
2804919Sxy150489 case E1000_DEV_ID_82571EB_SERDES_DUAL:
2814919Sxy150489 case E1000_DEV_ID_82571EB_SERDES_QUAD:
2824919Sxy150489 case E1000_DEV_ID_82572EI_SERDES:
2836735Scc210113 hw->phy.media_type = e1000_media_type_internal_serdes;
2844919Sxy150489 break;
2854919Sxy150489 default:
2866735Scc210113 hw->phy.media_type = e1000_media_type_copper;
2874919Sxy150489 break;
2884919Sxy150489 }
2894919Sxy150489
2904919Sxy150489 /* Set mta register count */
2914919Sxy150489 mac->mta_reg_count = 128;
2924919Sxy150489 /* Set rar entry count */
2934919Sxy150489 mac->rar_entry_count = E1000_RAR_ENTRIES;
2944919Sxy150489 /* Set if part includes ASF firmware */
2957607STed.You@Sun.COM mac->asf_firmware_present = true;
2964919Sxy150489 /* Set if manageability features are enabled. */
2974919Sxy150489 mac->arc_subsystem_valid =
2984919Sxy150489 (E1000_READ_REG(hw, E1000_FWSM) & E1000_FWSM_MODE_MASK)
2997607STed.You@Sun.COM ? true : false;
3004919Sxy150489
3014919Sxy150489 /* Function pointers */
3024919Sxy150489
3034919Sxy150489 /* bus type/speed/width */
3046735Scc210113 mac->ops.get_bus_info = e1000_get_bus_info_pcie_generic;
30510680SMin.Xu@Sun.COM /* function id */
30610680SMin.Xu@Sun.COM switch (hw->mac.type) {
30710680SMin.Xu@Sun.COM case e1000_82573:
30810680SMin.Xu@Sun.COM case e1000_82574:
30910680SMin.Xu@Sun.COM case e1000_82583:
31010680SMin.Xu@Sun.COM mac->ops.set_lan_id = e1000_set_lan_id_single_port;
31110680SMin.Xu@Sun.COM break;
31210680SMin.Xu@Sun.COM default:
31310680SMin.Xu@Sun.COM break;
31410680SMin.Xu@Sun.COM }
3154919Sxy150489 /* reset */
3166735Scc210113 mac->ops.reset_hw = e1000_reset_hw_82571;
3174919Sxy150489 /* hw initialization */
3186735Scc210113 mac->ops.init_hw = e1000_init_hw_82571;
3194919Sxy150489 /* link setup */
3206735Scc210113 mac->ops.setup_link = e1000_setup_link_82571;
3214919Sxy150489 /* physical interface link setup */
3226735Scc210113 mac->ops.setup_physical_interface =
3236735Scc210113 (hw->phy.media_type == e1000_media_type_copper)
3244919Sxy150489 ? e1000_setup_copper_link_82571
3254919Sxy150489 : e1000_setup_fiber_serdes_link_82571;
3264919Sxy150489 /* check for link */
3276735Scc210113 switch (hw->phy.media_type) {
3284919Sxy150489 case e1000_media_type_copper:
3296735Scc210113 mac->ops.check_for_link = e1000_check_for_copper_link_generic;
3304919Sxy150489 break;
3314919Sxy150489 case e1000_media_type_fiber:
3326735Scc210113 mac->ops.check_for_link = e1000_check_for_fiber_link_generic;
3334919Sxy150489 break;
3344919Sxy150489 case e1000_media_type_internal_serdes:
33510680SMin.Xu@Sun.COM mac->ops.check_for_link = e1000_check_for_serdes_link_82571;
3364919Sxy150489 break;
3374919Sxy150489 default:
3384919Sxy150489 ret_val = -E1000_ERR_CONFIG;
3394919Sxy150489 goto out;
3404919Sxy150489 }
3414919Sxy150489 /* check management mode */
3427607STed.You@Sun.COM switch (hw->mac.type) {
3437607STed.You@Sun.COM case e1000_82574:
34410680SMin.Xu@Sun.COM case e1000_82583:
3457607STed.You@Sun.COM mac->ops.check_mng_mode = e1000_check_mng_mode_82574;
3467607STed.You@Sun.COM break;
3477607STed.You@Sun.COM default:
3487607STed.You@Sun.COM mac->ops.check_mng_mode = e1000_check_mng_mode_generic;
3497607STed.You@Sun.COM break;
3507607STed.You@Sun.COM }
3514919Sxy150489 /* multicast address update */
35210680SMin.Xu@Sun.COM mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
3534919Sxy150489 /* writing VFTA */
3546735Scc210113 mac->ops.write_vfta = e1000_write_vfta_generic;
3554919Sxy150489 /* clearing VFTA */
3566735Scc210113 mac->ops.clear_vfta = e1000_clear_vfta_82571;
3574919Sxy150489 /* setting MTA */
3586735Scc210113 mac->ops.mta_set = e1000_mta_set_generic;
3596735Scc210113 /* read mac address */
3606735Scc210113 mac->ops.read_mac_addr = e1000_read_mac_addr_82571;
36110680SMin.Xu@Sun.COM /* ID LED init */
36210680SMin.Xu@Sun.COM mac->ops.id_led_init = e1000_id_led_init_generic;
3634919Sxy150489 /* blink LED */
3646735Scc210113 mac->ops.blink_led = e1000_blink_led_generic;
3654919Sxy150489 /* setup LED */
3666735Scc210113 mac->ops.setup_led = e1000_setup_led_generic;
3674919Sxy150489 /* cleanup LED */
3686735Scc210113 mac->ops.cleanup_led = e1000_cleanup_led_generic;
3694919Sxy150489 /* turn on/off LED */
3707607STed.You@Sun.COM switch (hw->mac.type) {
3717607STed.You@Sun.COM case e1000_82574:
37210680SMin.Xu@Sun.COM case e1000_82583:
3737607STed.You@Sun.COM mac->ops.led_on = e1000_led_on_82574;
3747607STed.You@Sun.COM break;
3757607STed.You@Sun.COM default:
3767607STed.You@Sun.COM mac->ops.led_on = e1000_led_on_generic;
3777607STed.You@Sun.COM break;
3787607STed.You@Sun.COM }
3796735Scc210113 mac->ops.led_off = e1000_led_off_generic;
3804919Sxy150489 /* clear hardware counters */
3816735Scc210113 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82571;
3824919Sxy150489 /* link info */
3836735Scc210113 mac->ops.get_link_up_info =
3846735Scc210113 (hw->phy.media_type == e1000_media_type_copper)
3854919Sxy150489 ? e1000_get_speed_and_duplex_copper_generic
3864919Sxy150489 : e1000_get_speed_and_duplex_fiber_serdes_generic;
3874919Sxy150489
38810680SMin.Xu@Sun.COM /*
38910680SMin.Xu@Sun.COM * Ensure that the inter-port SWSM.SMBI lock bit is clear before
39010680SMin.Xu@Sun.COM * first NVM or PHY acess. This should be done for single-port
39110680SMin.Xu@Sun.COM * devices, and for one port only on dual-port devices so that
39210680SMin.Xu@Sun.COM * for those devices we can still use the SMBI lock to synchronize
39310680SMin.Xu@Sun.COM * inter-port accesses to the PHY & NVM.
39410680SMin.Xu@Sun.COM */
39510680SMin.Xu@Sun.COM switch (hw->mac.type) {
39610680SMin.Xu@Sun.COM case e1000_82571:
39710680SMin.Xu@Sun.COM case e1000_82572:
39810680SMin.Xu@Sun.COM swsm2 = E1000_READ_REG(hw, E1000_SWSM2);
39910680SMin.Xu@Sun.COM
40010680SMin.Xu@Sun.COM if (!(swsm2 & E1000_SWSM2_LOCK)) {
40110680SMin.Xu@Sun.COM /* Only do this for the first interface on this card */
40210680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM2,
40310680SMin.Xu@Sun.COM swsm2 | E1000_SWSM2_LOCK);
40410680SMin.Xu@Sun.COM force_clear_smbi = true;
40510680SMin.Xu@Sun.COM } else
40610680SMin.Xu@Sun.COM force_clear_smbi = false;
40710680SMin.Xu@Sun.COM break;
40810680SMin.Xu@Sun.COM default:
40910680SMin.Xu@Sun.COM force_clear_smbi = true;
41010680SMin.Xu@Sun.COM break;
41110680SMin.Xu@Sun.COM }
41210680SMin.Xu@Sun.COM
41310680SMin.Xu@Sun.COM if (force_clear_smbi) {
41410680SMin.Xu@Sun.COM /* Make sure SWSM.SMBI is clear */
41510680SMin.Xu@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM);
41610680SMin.Xu@Sun.COM if (swsm & E1000_SWSM_SMBI) {
417*11143SGuoqing.Zhu@Sun.COM /* EMPTY */
41810680SMin.Xu@Sun.COM /*
41910680SMin.Xu@Sun.COM * This bit should not be set on a first interface, and
42010680SMin.Xu@Sun.COM * indicates that the bootagent or EFI code has
42110680SMin.Xu@Sun.COM * improperly left this bit enabled
42210680SMin.Xu@Sun.COM */
42310680SMin.Xu@Sun.COM DEBUGOUT("Please update your 82571 Bootagent\n");
42410680SMin.Xu@Sun.COM }
42510680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_SMBI);
42610680SMin.Xu@Sun.COM }
42710680SMin.Xu@Sun.COM
42810680SMin.Xu@Sun.COM /*
42910680SMin.Xu@Sun.COM * Initialze device specific counter of SMBI acquisition
43010680SMin.Xu@Sun.COM * timeouts.
43110680SMin.Xu@Sun.COM */
43210680SMin.Xu@Sun.COM hw->dev_spec._82571.smb_counter = 0;
43310680SMin.Xu@Sun.COM
4344919Sxy150489 out:
4354919Sxy150489 return (ret_val);
4364919Sxy150489 }
4374919Sxy150489
4384919Sxy150489 /*
4394919Sxy150489 * e1000_init_function_pointers_82571 - Init func ptrs.
4404919Sxy150489 * @hw: pointer to the HW structure
4414919Sxy150489 *
4428479SChenlu.Chen@Sun.COM * Called to initialize all function pointers and parameters.
4434919Sxy150489 */
4444919Sxy150489 void
e1000_init_function_pointers_82571(struct e1000_hw * hw)4454919Sxy150489 e1000_init_function_pointers_82571(struct e1000_hw *hw)
4464919Sxy150489 {
4474919Sxy150489 DEBUGFUNC("e1000_init_function_pointers_82571");
4484919Sxy150489
4496735Scc210113 hw->mac.ops.init_params = e1000_init_mac_params_82571;
4506735Scc210113 hw->nvm.ops.init_params = e1000_init_nvm_params_82571;
4516735Scc210113 hw->phy.ops.init_params = e1000_init_phy_params_82571;
4524919Sxy150489 }
4534919Sxy150489
4544919Sxy150489 /*
4554919Sxy150489 * e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
4564919Sxy150489 * @hw: pointer to the HW structure
4574919Sxy150489 *
4584919Sxy150489 * Reads the PHY registers and stores the PHY ID and possibly the PHY
4594919Sxy150489 * revision in the hardware structure.
4604919Sxy150489 */
4614919Sxy150489 static s32
e1000_get_phy_id_82571(struct e1000_hw * hw)4624919Sxy150489 e1000_get_phy_id_82571(struct e1000_hw *hw)
4634919Sxy150489 {
4644919Sxy150489 struct e1000_phy_info *phy = &hw->phy;
4654919Sxy150489 s32 ret_val = E1000_SUCCESS;
4667607STed.You@Sun.COM u16 phy_id = 0;
4674919Sxy150489
4684919Sxy150489 DEBUGFUNC("e1000_get_phy_id_82571");
4694919Sxy150489
4704919Sxy150489 switch (hw->mac.type) {
4714919Sxy150489 case e1000_82571:
4724919Sxy150489 case e1000_82572:
4734919Sxy150489 /*
4746735Scc210113 * The 82571 firmware may still be configuring the PHY. In
4756735Scc210113 * this case, we cannot access the PHY until the configuration
4766735Scc210113 * is done. So we explicitly set the PHY ID.
4774919Sxy150489 */
4784919Sxy150489 phy->id = IGP01E1000_I_PHY_ID;
4794919Sxy150489 break;
4804919Sxy150489 case e1000_82573:
4814919Sxy150489 ret_val = e1000_get_phy_id(hw);
4824919Sxy150489 break;
4837607STed.You@Sun.COM case e1000_82574:
48410680SMin.Xu@Sun.COM case e1000_82583:
4857607STed.You@Sun.COM ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
4867607STed.You@Sun.COM if (ret_val)
4877607STed.You@Sun.COM goto out;
4887607STed.You@Sun.COM
4897607STed.You@Sun.COM phy->id = (u32)(phy_id << 16);
4907607STed.You@Sun.COM usec_delay(20);
4917607STed.You@Sun.COM ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
4927607STed.You@Sun.COM if (ret_val)
4937607STed.You@Sun.COM goto out;
4947607STed.You@Sun.COM
4957607STed.You@Sun.COM phy->id |= (u32)(phy_id);
4967607STed.You@Sun.COM phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
4977607STed.You@Sun.COM break;
4984919Sxy150489 default:
4994919Sxy150489 ret_val = -E1000_ERR_PHY;
5004919Sxy150489 break;
5014919Sxy150489 }
5024919Sxy150489
5037607STed.You@Sun.COM out:
5044919Sxy150489 return (ret_val);
5054919Sxy150489 }
5064919Sxy150489
5074919Sxy150489 /*
5084919Sxy150489 * e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
5094919Sxy150489 * @hw: pointer to the HW structure
5104919Sxy150489 *
5114919Sxy150489 * Acquire the HW semaphore to access the PHY or NVM
5124919Sxy150489 */
51310680SMin.Xu@Sun.COM s32
e1000_get_hw_semaphore_82571(struct e1000_hw * hw)5144919Sxy150489 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
5154919Sxy150489 {
5164919Sxy150489 u32 swsm;
5174919Sxy150489 s32 ret_val = E1000_SUCCESS;
51810680SMin.Xu@Sun.COM s32 sw_timeout = hw->nvm.word_size + 1;
51910680SMin.Xu@Sun.COM s32 fw_timeout = hw->nvm.word_size + 1;
5204919Sxy150489 s32 i = 0;
5214919Sxy150489
5224919Sxy150489 DEBUGFUNC("e1000_get_hw_semaphore_82571");
5234919Sxy150489
52410680SMin.Xu@Sun.COM /*
52510680SMin.Xu@Sun.COM * If we have timedout 3 times on trying to acquire
52610680SMin.Xu@Sun.COM * the inter-port SMBI semaphore, there is old code
52710680SMin.Xu@Sun.COM * operating on the other port, and it is not
52810680SMin.Xu@Sun.COM * releasing SMBI. Modify the number of times that
52910680SMin.Xu@Sun.COM * we try for the semaphore to interwork with this
53010680SMin.Xu@Sun.COM * older code.
53110680SMin.Xu@Sun.COM */
53210680SMin.Xu@Sun.COM if (hw->dev_spec._82571.smb_counter > 2)
53310680SMin.Xu@Sun.COM sw_timeout = 1;
53410680SMin.Xu@Sun.COM
53510680SMin.Xu@Sun.COM /* Get the SW semaphore */
53610680SMin.Xu@Sun.COM while (i < sw_timeout) {
53710680SMin.Xu@Sun.COM swsm = E1000_READ_REG(hw, E1000_SWSM);
53810680SMin.Xu@Sun.COM if (!(swsm & E1000_SWSM_SMBI))
53910680SMin.Xu@Sun.COM break;
54010680SMin.Xu@Sun.COM
54110680SMin.Xu@Sun.COM usec_delay(50);
54210680SMin.Xu@Sun.COM i++;
54310680SMin.Xu@Sun.COM }
54410680SMin.Xu@Sun.COM
54510680SMin.Xu@Sun.COM if (i == sw_timeout) {
54610680SMin.Xu@Sun.COM DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
54710680SMin.Xu@Sun.COM hw->dev_spec._82571.smb_counter++;
54810680SMin.Xu@Sun.COM }
5494919Sxy150489 /* Get the FW semaphore. */
55010680SMin.Xu@Sun.COM for (i = 0; i < fw_timeout; i++) {
5514919Sxy150489 swsm = E1000_READ_REG(hw, E1000_SWSM);
5524919Sxy150489 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
5534919Sxy150489
5544919Sxy150489 /* Semaphore acquired if bit latched */
5554919Sxy150489 if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
5564919Sxy150489 break;
5574919Sxy150489
5584919Sxy150489 usec_delay(50);
5594919Sxy150489 }
5604919Sxy150489
56110680SMin.Xu@Sun.COM if (i == fw_timeout) {
5624919Sxy150489 /* Release semaphores */
56310680SMin.Xu@Sun.COM e1000_put_hw_semaphore_82571(hw);
5644919Sxy150489 DEBUGOUT("Driver can't access the NVM\n");
5654919Sxy150489 ret_val = -E1000_ERR_NVM;
5664919Sxy150489 goto out;
5674919Sxy150489 }
5684919Sxy150489
5694919Sxy150489 out:
5704919Sxy150489 return (ret_val);
5714919Sxy150489 }
5724919Sxy150489
5734919Sxy150489 /*
5744919Sxy150489 * e1000_put_hw_semaphore_82571 - Release hardware semaphore
5754919Sxy150489 * @hw: pointer to the HW structure
5764919Sxy150489 *
5774919Sxy150489 * Release hardware semaphore used to access the PHY or NVM
5784919Sxy150489 */
57910680SMin.Xu@Sun.COM void
e1000_put_hw_semaphore_82571(struct e1000_hw * hw)5804919Sxy150489 e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
5814919Sxy150489 {
5824919Sxy150489 u32 swsm;
5834919Sxy150489
58410680SMin.Xu@Sun.COM DEBUGFUNC("e1000_put_hw_semaphore_generic");
5854919Sxy150489
5864919Sxy150489 swsm = E1000_READ_REG(hw, E1000_SWSM);
5874919Sxy150489
58810680SMin.Xu@Sun.COM swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
5894919Sxy150489
5904919Sxy150489 E1000_WRITE_REG(hw, E1000_SWSM, swsm);
5914919Sxy150489 }
5924919Sxy150489
5934919Sxy150489 /*
5944919Sxy150489 * e1000_acquire_nvm_82571 - Request for access to the EEPROM
5954919Sxy150489 * @hw: pointer to the HW structure
5964919Sxy150489 *
5974919Sxy150489 * To gain access to the EEPROM, first we must obtain a hardware semaphore.
5984919Sxy150489 * Then for non-82573 hardware, set the EEPROM access request bit and wait
5994919Sxy150489 * for EEPROM access grant bit. If the access grant bit is not set, release
6004919Sxy150489 * hardware semaphore.
6014919Sxy150489 */
6024919Sxy150489 static s32
e1000_acquire_nvm_82571(struct e1000_hw * hw)6034919Sxy150489 e1000_acquire_nvm_82571(struct e1000_hw *hw)
6044919Sxy150489 {
6054919Sxy150489 s32 ret_val;
6064919Sxy150489
6074919Sxy150489 DEBUGFUNC("e1000_acquire_nvm_82571");
6084919Sxy150489
6094919Sxy150489 ret_val = e1000_get_hw_semaphore_82571(hw);
6104919Sxy150489 if (ret_val)
6114919Sxy150489 goto out;
6124919Sxy150489
61310680SMin.Xu@Sun.COM switch (hw->mac.type) {
61410680SMin.Xu@Sun.COM case e1000_82573:
61510680SMin.Xu@Sun.COM case e1000_82574:
61610680SMin.Xu@Sun.COM case e1000_82583:
61710680SMin.Xu@Sun.COM break;
61810680SMin.Xu@Sun.COM default:
6194919Sxy150489 ret_val = e1000_acquire_nvm_generic(hw);
62010680SMin.Xu@Sun.COM break;
62110680SMin.Xu@Sun.COM }
6224919Sxy150489
6234919Sxy150489 if (ret_val)
6244919Sxy150489 e1000_put_hw_semaphore_82571(hw);
6254919Sxy150489
6264919Sxy150489 out:
6274919Sxy150489 return (ret_val);
6284919Sxy150489 }
6294919Sxy150489
6304919Sxy150489 /*
6314919Sxy150489 * e1000_release_nvm_82571 - Release exclusive access to EEPROM
6324919Sxy150489 * @hw: pointer to the HW structure
6334919Sxy150489 *
6344919Sxy150489 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
6354919Sxy150489 */
6364919Sxy150489 static void
e1000_release_nvm_82571(struct e1000_hw * hw)6374919Sxy150489 e1000_release_nvm_82571(struct e1000_hw *hw)
6384919Sxy150489 {
6394919Sxy150489 DEBUGFUNC("e1000_release_nvm_82571");
6404919Sxy150489
6414919Sxy150489 e1000_release_nvm_generic(hw);
6424919Sxy150489 e1000_put_hw_semaphore_82571(hw);
6434919Sxy150489 }
6444919Sxy150489
6454919Sxy150489 /*
6464919Sxy150489 * e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
6474919Sxy150489 * @hw: pointer to the HW structure
6484919Sxy150489 * @offset: offset within the EEPROM to be written to
6494919Sxy150489 * @words: number of words to write
6504919Sxy150489 * @data: 16 bit word(s) to be written to the EEPROM
6514919Sxy150489 *
6524919Sxy150489 * For non-82573 silicon, write data to EEPROM at offset using SPI interface.
6534919Sxy150489 *
6544919Sxy150489 * If e1000_update_nvm_checksum is not called after this function, the
6556735Scc210113 * EEPROM will most likely contain an invalid checksum.
6564919Sxy150489 */
6574919Sxy150489 static s32
e1000_write_nvm_82571(struct e1000_hw * hw,u16 offset,u16 words,u16 * data)6586735Scc210113 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
6596735Scc210113 u16 *data)
6604919Sxy150489 {
6614919Sxy150489 s32 ret_val = E1000_SUCCESS;
6624919Sxy150489
6634919Sxy150489 DEBUGFUNC("e1000_write_nvm_82571");
6644919Sxy150489
6654919Sxy150489 switch (hw->mac.type) {
6664919Sxy150489 case e1000_82573:
6677607STed.You@Sun.COM case e1000_82574:
66810680SMin.Xu@Sun.COM case e1000_82583:
6694919Sxy150489 ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
6704919Sxy150489 break;
6714919Sxy150489 case e1000_82571:
6724919Sxy150489 case e1000_82572:
6734919Sxy150489 ret_val = e1000_write_nvm_spi(hw, offset, words, data);
6744919Sxy150489 break;
6754919Sxy150489 default:
6764919Sxy150489 ret_val = -E1000_ERR_NVM;
6774919Sxy150489 break;
6784919Sxy150489 }
6794919Sxy150489
6804919Sxy150489 return (ret_val);
6814919Sxy150489 }
6824919Sxy150489
6834919Sxy150489 /*
6844919Sxy150489 * e1000_update_nvm_checksum_82571 - Update EEPROM checksum
6854919Sxy150489 * @hw: pointer to the HW structure
6864919Sxy150489 *
6874919Sxy150489 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
6884919Sxy150489 * up to the checksum. Then calculates the EEPROM checksum and writes the
6894919Sxy150489 * value to the EEPROM.
6904919Sxy150489 */
6914919Sxy150489 static s32
e1000_update_nvm_checksum_82571(struct e1000_hw * hw)6924919Sxy150489 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
6934919Sxy150489 {
6944919Sxy150489 u32 eecd;
6954919Sxy150489 s32 ret_val;
6964919Sxy150489 u16 i;
6974919Sxy150489
6984919Sxy150489 DEBUGFUNC("e1000_update_nvm_checksum_82571");
6994919Sxy150489
7004919Sxy150489 ret_val = e1000_update_nvm_checksum_generic(hw);
7014919Sxy150489 if (ret_val)
7024919Sxy150489 goto out;
7034919Sxy150489
7044919Sxy150489 /*
7056735Scc210113 * If our nvm is an EEPROM, then we're done otherwise, commit the
7066735Scc210113 * checksum to the flash NVM.
7074919Sxy150489 */
7084919Sxy150489 if (hw->nvm.type != e1000_nvm_flash_hw)
7094919Sxy150489 goto out;
7104919Sxy150489
7114919Sxy150489 /* Check for pending operations. */
7124919Sxy150489 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
7134919Sxy150489 msec_delay(1);
7144919Sxy150489 if ((E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_FLUPD) == 0)
7154919Sxy150489 break;
7164919Sxy150489 }
7174919Sxy150489
7184919Sxy150489 if (i == E1000_FLASH_UPDATES) {
7194919Sxy150489 ret_val = -E1000_ERR_NVM;
7204919Sxy150489 goto out;
7214919Sxy150489 }
7224919Sxy150489
7234919Sxy150489 /* Reset the firmware if using STM opcode. */
7244919Sxy150489 if ((E1000_READ_REG(hw, E1000_FLOP) & 0xFF00) == E1000_STM_OPCODE) {
7254919Sxy150489 /*
7266735Scc210113 * The enabling of and the actual reset must be done in two
7276735Scc210113 * write cycles.
7284919Sxy150489 */
7294919Sxy150489 E1000_WRITE_REG(hw, E1000_HICR, E1000_HICR_FW_RESET_ENABLE);
7304919Sxy150489 E1000_WRITE_FLUSH(hw);
7314919Sxy150489 E1000_WRITE_REG(hw, E1000_HICR, E1000_HICR_FW_RESET);
7324919Sxy150489 }
7334919Sxy150489
7344919Sxy150489 /* Commit the write to flash */
7354919Sxy150489 eecd = E1000_READ_REG(hw, E1000_EECD) | E1000_EECD_FLUPD;
7364919Sxy150489 E1000_WRITE_REG(hw, E1000_EECD, eecd);
7374919Sxy150489
7384919Sxy150489 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
7394919Sxy150489 msec_delay(1);
7404919Sxy150489 if ((E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_FLUPD) == 0)
7414919Sxy150489 break;
7424919Sxy150489 }
7434919Sxy150489
7444919Sxy150489 if (i == E1000_FLASH_UPDATES) {
7454919Sxy150489 ret_val = -E1000_ERR_NVM;
7464919Sxy150489 goto out;
7474919Sxy150489 }
7484919Sxy150489
7494919Sxy150489 out:
7504919Sxy150489 return (ret_val);
7514919Sxy150489 }
7524919Sxy150489
7534919Sxy150489 /*
7544919Sxy150489 * e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
7554919Sxy150489 * @hw: pointer to the HW structure
7564919Sxy150489 *
7574919Sxy150489 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
7584919Sxy150489 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
7594919Sxy150489 */
7604919Sxy150489 static s32
e1000_validate_nvm_checksum_82571(struct e1000_hw * hw)7614919Sxy150489 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
7624919Sxy150489 {
7634919Sxy150489 DEBUGFUNC("e1000_validate_nvm_checksum_82571");
7644919Sxy150489
7654919Sxy150489 if (hw->nvm.type == e1000_nvm_flash_hw)
7667426SChenliang.Xu@Sun.COM (void) e1000_fix_nvm_checksum_82571(hw);
7674919Sxy150489
7684919Sxy150489 return (e1000_validate_nvm_checksum_generic(hw));
7694919Sxy150489 }
7704919Sxy150489
7714919Sxy150489 /*
7724919Sxy150489 * e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
7734919Sxy150489 * @hw: pointer to the HW structure
7744919Sxy150489 * @offset: offset within the EEPROM to be written to
7754919Sxy150489 * @words: number of words to write
7764919Sxy150489 * @data: 16 bit word(s) to be written to the EEPROM
7774919Sxy150489 *
7784919Sxy150489 * After checking for invalid values, poll the EEPROM to ensure the previous
7794919Sxy150489 * command has completed before trying to write the next word. After write
7804919Sxy150489 * poll for completion.
7814919Sxy150489 *
7824919Sxy150489 * If e1000_update_nvm_checksum is not called after this function, the
7836735Scc210113 * EEPROM will most likely contain an invalid checksum.
7844919Sxy150489 */
7854919Sxy150489 static s32
e1000_write_nvm_eewr_82571(struct e1000_hw * hw,u16 offset,u16 words,u16 * data)7864919Sxy150489 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
7874919Sxy150489 u16 words, u16 *data)
7884919Sxy150489 {
7894919Sxy150489 struct e1000_nvm_info *nvm = &hw->nvm;
7904919Sxy150489 u32 i, eewr = 0;
7914919Sxy150489 s32 ret_val = 0;
7924919Sxy150489
7934919Sxy150489 DEBUGFUNC("e1000_write_nvm_eewr_82571");
7944919Sxy150489
7954919Sxy150489 /*
7966735Scc210113 * A check for invalid values: offset too large, too many words, and
7976735Scc210113 * not enough words.
7984919Sxy150489 */
7994919Sxy150489 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
8004919Sxy150489 (words == 0)) {
8014919Sxy150489 DEBUGOUT("nvm parameter(s) out of bounds\n");
8024919Sxy150489 ret_val = -E1000_ERR_NVM;
8034919Sxy150489 goto out;
8044919Sxy150489 }
8054919Sxy150489
8064919Sxy150489 for (i = 0; i < words; i++) {
8074919Sxy150489 eewr = (data[i] << E1000_NVM_RW_REG_DATA) |
8084919Sxy150489 ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) |
8094919Sxy150489 E1000_NVM_RW_REG_START;
8104919Sxy150489
8114919Sxy150489 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
8124919Sxy150489 if (ret_val)
8134919Sxy150489 break;
8144919Sxy150489
8154919Sxy150489 E1000_WRITE_REG(hw, E1000_EEWR, eewr);
8164919Sxy150489
8174919Sxy150489 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
8184919Sxy150489 if (ret_val)
8194919Sxy150489 break;
8204919Sxy150489 }
8214919Sxy150489
8224919Sxy150489 out:
8234919Sxy150489 return (ret_val);
8244919Sxy150489 }
8254919Sxy150489
8264919Sxy150489 /*
8274919Sxy150489 * e1000_get_cfg_done_82571 - Poll for configuration done
8284919Sxy150489 * @hw: pointer to the HW structure
8294919Sxy150489 *
8304919Sxy150489 * Reads the management control register for the config done bit to be set.
8314919Sxy150489 */
8324919Sxy150489 static s32
e1000_get_cfg_done_82571(struct e1000_hw * hw)8334919Sxy150489 e1000_get_cfg_done_82571(struct e1000_hw *hw)
8344919Sxy150489 {
8354919Sxy150489 s32 timeout = PHY_CFG_TIMEOUT;
8364919Sxy150489 s32 ret_val = E1000_SUCCESS;
8374919Sxy150489
8384919Sxy150489 DEBUGFUNC("e1000_get_cfg_done_82571");
8394919Sxy150489
8404919Sxy150489 while (timeout) {
8414919Sxy150489 if (E1000_READ_REG(hw, E1000_EEMNGCTL) &
8424919Sxy150489 E1000_NVM_CFG_DONE_PORT_0)
8434919Sxy150489 break;
8444919Sxy150489 msec_delay(1);
8454919Sxy150489 timeout--;
8464919Sxy150489 }
8474919Sxy150489 if (!timeout) {
8484919Sxy150489 DEBUGOUT("MNG configuration cycle has not completed.\n");
8494919Sxy150489 goto out;
8504919Sxy150489 }
8514919Sxy150489
8524919Sxy150489 out:
8534919Sxy150489 return (ret_val);
8544919Sxy150489 }
8554919Sxy150489
8564919Sxy150489 /*
8574919Sxy150489 * e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
8584919Sxy150489 * @hw: pointer to the HW structure
8597607STed.You@Sun.COM * @active: true to enable LPLU, false to disable
8604919Sxy150489 *
8614919Sxy150489 * Sets the LPLU D0 state according to the active flag. When activating LPLU
8624919Sxy150489 * this function also disables smart speed and vice versa. LPLU will not be
8634919Sxy150489 * activated unless the device autonegotiation advertisement meets standards
8644919Sxy150489 * of either 10 or 10/100 or 10/100/1000 at all duplexes. This is a function
8654919Sxy150489 * pointer entry point only called by PHY setup routines.
8664919Sxy150489 */
8674919Sxy150489 static s32
e1000_set_d0_lplu_state_82571(struct e1000_hw * hw,bool active)8686735Scc210113 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
8694919Sxy150489 {
8704919Sxy150489 struct e1000_phy_info *phy = &hw->phy;
8716735Scc210113 s32 ret_val = E1000_SUCCESS;
8724919Sxy150489 u16 data;
8734919Sxy150489
8744919Sxy150489 DEBUGFUNC("e1000_set_d0_lplu_state_82571");
8754919Sxy150489
8766735Scc210113 if (!(phy->ops.read_reg))
8776735Scc210113 goto out;
8786735Scc210113
8796735Scc210113 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
8804919Sxy150489 if (ret_val)
8814919Sxy150489 goto out;
8824919Sxy150489
8834919Sxy150489 if (active) {
8844919Sxy150489 data |= IGP02E1000_PM_D0_LPLU;
8856735Scc210113 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
8864919Sxy150489 data);
8874919Sxy150489 if (ret_val)
8884919Sxy150489 goto out;
8894919Sxy150489
8904919Sxy150489 /* When LPLU is enabled, we should disable SmartSpeed */
8916735Scc210113 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
8924919Sxy150489 &data);
8934919Sxy150489 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
8946735Scc210113 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
8954919Sxy150489 data);
8964919Sxy150489 if (ret_val)
8974919Sxy150489 goto out;
8984919Sxy150489 } else {
8994919Sxy150489 data &= ~IGP02E1000_PM_D0_LPLU;
9006735Scc210113 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
9014919Sxy150489 data);
9024919Sxy150489 /*
9034919Sxy150489 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
9044919Sxy150489 * during Dx states where the power conservation is most
9054919Sxy150489 * important. During driver activity we should enable
9064919Sxy150489 * SmartSpeed, so performance is maintained.
9074919Sxy150489 */
9084919Sxy150489 if (phy->smart_speed == e1000_smart_speed_on) {
9096735Scc210113 ret_val = phy->ops.read_reg(hw,
9104919Sxy150489 IGP01E1000_PHY_PORT_CONFIG,
9114919Sxy150489 &data);
9124919Sxy150489 if (ret_val)
9134919Sxy150489 goto out;
9144919Sxy150489
9154919Sxy150489 data |= IGP01E1000_PSCFR_SMART_SPEED;
9166735Scc210113 ret_val = phy->ops.write_reg(hw,
9174919Sxy150489 IGP01E1000_PHY_PORT_CONFIG,
9184919Sxy150489 data);
9194919Sxy150489 if (ret_val)
9204919Sxy150489 goto out;
9214919Sxy150489 } else if (phy->smart_speed == e1000_smart_speed_off) {
9226735Scc210113 ret_val = phy->ops.read_reg(hw,
9234919Sxy150489 IGP01E1000_PHY_PORT_CONFIG,
9244919Sxy150489 &data);
9254919Sxy150489 if (ret_val)
9264919Sxy150489 goto out;
9274919Sxy150489
9284919Sxy150489 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
9296735Scc210113 ret_val = phy->ops.write_reg(hw,
9304919Sxy150489 IGP01E1000_PHY_PORT_CONFIG,
9314919Sxy150489 data);
9324919Sxy150489 if (ret_val)
9334919Sxy150489 goto out;
9344919Sxy150489 }
9354919Sxy150489 }
9364919Sxy150489
9374919Sxy150489 out:
9384919Sxy150489 return (ret_val);
9394919Sxy150489 }
9404919Sxy150489
9414919Sxy150489 /*
9424919Sxy150489 * e1000_reset_hw_82571 - Reset hardware
9434919Sxy150489 * @hw: pointer to the HW structure
9444919Sxy150489 *
9458479SChenlu.Chen@Sun.COM * This resets the hardware into a known state.
9464919Sxy150489 */
9474919Sxy150489 static s32
e1000_reset_hw_82571(struct e1000_hw * hw)9484919Sxy150489 e1000_reset_hw_82571(struct e1000_hw *hw)
9494919Sxy150489 {
9507426SChenliang.Xu@Sun.COM u32 ctrl, extcnf_ctrl, ctrl_ext;
9514919Sxy150489 s32 ret_val;
9524919Sxy150489 u16 i = 0;
9534919Sxy150489
9544919Sxy150489 DEBUGFUNC("e1000_reset_hw_82571");
9554919Sxy150489
9564919Sxy150489 /*
9574919Sxy150489 * Prevent the PCI-E bus from sticking if there is no TLP connection
9584919Sxy150489 * on the last TLP read/write transaction when MAC is reset.
9594919Sxy150489 */
9604919Sxy150489 ret_val = e1000_disable_pcie_master_generic(hw);
961*11143SGuoqing.Zhu@Sun.COM if (ret_val) {
962*11143SGuoqing.Zhu@Sun.COM /* EMPTY */
9634919Sxy150489 DEBUGOUT("PCI-E Master disable polling has failed.\n");
964*11143SGuoqing.Zhu@Sun.COM }
9654919Sxy150489
9664919Sxy150489 DEBUGOUT("Masking off all interrupts\n");
9674919Sxy150489 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
9684919Sxy150489
9694919Sxy150489 E1000_WRITE_REG(hw, E1000_RCTL, 0);
9704919Sxy150489 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
9714919Sxy150489 E1000_WRITE_FLUSH(hw);
9724919Sxy150489
9734919Sxy150489 msec_delay(10);
9744919Sxy150489
9754919Sxy150489 /*
9766735Scc210113 * Must acquire the MDIO ownership before MAC reset. Ownership
9776735Scc210113 * defaults to firmware after a reset.
9784919Sxy150489 */
97910680SMin.Xu@Sun.COM switch (hw->mac.type) {
98010680SMin.Xu@Sun.COM case e1000_82573:
98110680SMin.Xu@Sun.COM case e1000_82574:
98210680SMin.Xu@Sun.COM case e1000_82583:
9834919Sxy150489 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
9844919Sxy150489 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
9854919Sxy150489
9864919Sxy150489 do {
9874919Sxy150489 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
9884919Sxy150489 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
9894919Sxy150489
9904919Sxy150489 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
9914919Sxy150489 break;
9924919Sxy150489
9934919Sxy150489 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
9944919Sxy150489
9954919Sxy150489 msec_delay(2);
9964919Sxy150489 i++;
9974919Sxy150489 } while (i < MDIO_OWNERSHIP_TIMEOUT);
99810680SMin.Xu@Sun.COM break;
99910680SMin.Xu@Sun.COM default:
100010680SMin.Xu@Sun.COM break;
10014919Sxy150489 }
10024919Sxy150489
10034919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
10044919Sxy150489
10054919Sxy150489 DEBUGOUT("Issuing a global reset to MAC\n");
10064919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
10074919Sxy150489
10084919Sxy150489 if (hw->nvm.type == e1000_nvm_flash_hw) {
10094919Sxy150489 usec_delay(10);
10104919Sxy150489 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
10114919Sxy150489 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
10124919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
10134919Sxy150489 E1000_WRITE_FLUSH(hw);
10144919Sxy150489 }
10154919Sxy150489
10164919Sxy150489 ret_val = e1000_get_auto_rd_done_generic(hw);
10174919Sxy150489 if (ret_val)
10184919Sxy150489 /* We don't want to continue accessing MAC registers. */
10194919Sxy150489 goto out;
10204919Sxy150489
10214919Sxy150489 /*
10224919Sxy150489 * Phy configuration from NVM just starts after EECD_AUTO_RD is set.
10234919Sxy150489 * Need to wait for Phy configuration completion before accessing
10244919Sxy150489 * NVM and Phy.
10254919Sxy150489 */
102610680SMin.Xu@Sun.COM switch (hw->mac.type) {
102710680SMin.Xu@Sun.COM case e1000_82573:
102810680SMin.Xu@Sun.COM case e1000_82574:
102910680SMin.Xu@Sun.COM case e1000_82583:
10304919Sxy150489 msec_delay(25);
103110680SMin.Xu@Sun.COM break;
103210680SMin.Xu@Sun.COM default:
103310680SMin.Xu@Sun.COM break;
103410680SMin.Xu@Sun.COM }
10354919Sxy150489
10364919Sxy150489 /* Clear any pending interrupt events. */
10374919Sxy150489 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
10387426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICR);
10394919Sxy150489
104010680SMin.Xu@Sun.COM /* Install any alternate MAC address into RAR0 */
104110680SMin.Xu@Sun.COM ret_val = e1000_check_alt_mac_addr_generic(hw);
104210680SMin.Xu@Sun.COM if (ret_val)
104310680SMin.Xu@Sun.COM goto out;
104410680SMin.Xu@Sun.COM
104510680SMin.Xu@Sun.COM e1000_set_laa_state_82571(hw, true);
104610680SMin.Xu@Sun.COM
104710680SMin.Xu@Sun.COM /* Reinitialize the 82571 serdes link state machine */
104810680SMin.Xu@Sun.COM if (hw->phy.media_type == e1000_media_type_internal_serdes)
104910680SMin.Xu@Sun.COM hw->mac.serdes_link_state = e1000_serdes_link_down;
10506735Scc210113
10514919Sxy150489 out:
10524919Sxy150489 return (ret_val);
10534919Sxy150489 }
10544919Sxy150489
10554919Sxy150489 /*
10564919Sxy150489 * e1000_init_hw_82571 - Initialize hardware
10574919Sxy150489 * @hw: pointer to the HW structure
10584919Sxy150489 *
10594919Sxy150489 * This inits the hardware readying it for operation.
10604919Sxy150489 */
10614919Sxy150489 static s32
e1000_init_hw_82571(struct e1000_hw * hw)10624919Sxy150489 e1000_init_hw_82571(struct e1000_hw *hw)
10634919Sxy150489 {
10644919Sxy150489 struct e1000_mac_info *mac = &hw->mac;
10654919Sxy150489 u32 reg_data;
10664919Sxy150489 s32 ret_val;
10674919Sxy150489 u16 i, rar_count = mac->rar_entry_count;
10684919Sxy150489
10694919Sxy150489 DEBUGFUNC("e1000_init_hw_82571");
10704919Sxy150489
10714919Sxy150489 e1000_initialize_hw_bits_82571(hw);
10724919Sxy150489
10734919Sxy150489 /* Initialize identification LED */
107410680SMin.Xu@Sun.COM ret_val = mac->ops.id_led_init(hw);
10754919Sxy150489 if (ret_val) {
1076*11143SGuoqing.Zhu@Sun.COM /* EMPTY */
10774919Sxy150489 DEBUGOUT("Error initializing identification LED\n");
10786735Scc210113 /* This is not fatal and we should not stop init due to this */
10794919Sxy150489 }
10804919Sxy150489
10814919Sxy150489 /* Disabling VLAN filtering */
10824919Sxy150489 DEBUGOUT("Initializing the IEEE VLAN\n");
10836735Scc210113 mac->ops.clear_vfta(hw);
10844919Sxy150489
10854919Sxy150489 /* Setup the receive address. */
10864919Sxy150489 /*
10874919Sxy150489 * If, however, a locally administered address was assigned to the
10884919Sxy150489 * 82571, we must reserve a RAR for it to work around an issue where
10894919Sxy150489 * resetting one port will reload the MAC on the other port.
10904919Sxy150489 */
10914919Sxy150489 if (e1000_get_laa_state_82571(hw))
10924919Sxy150489 rar_count--;
10934919Sxy150489 e1000_init_rx_addrs_generic(hw, rar_count);
10944919Sxy150489
10954919Sxy150489 /* Zero out the Multicast HASH table */
10964919Sxy150489 DEBUGOUT("Zeroing the MTA\n");
10974919Sxy150489 for (i = 0; i < mac->mta_reg_count; i++)
10984919Sxy150489 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
10994919Sxy150489
11004919Sxy150489 /* Setup link and flow control */
11016735Scc210113 ret_val = mac->ops.setup_link(hw);
11024919Sxy150489
11034919Sxy150489 /* Set the transmit descriptor write-back policy */
11046735Scc210113 reg_data = E1000_READ_REG(hw, E1000_TXDCTL(0));
11054919Sxy150489 reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
11064919Sxy150489 E1000_TXDCTL_FULL_TX_DESC_WB |
11074919Sxy150489 E1000_TXDCTL_COUNT_DESC;
11086735Scc210113 E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg_data);
11094919Sxy150489
11104919Sxy150489 /* ...for both queues. */
111110680SMin.Xu@Sun.COM switch (mac->type) {
111210680SMin.Xu@Sun.COM case e1000_82573:
111310680SMin.Xu@Sun.COM case e1000_82574:
111410680SMin.Xu@Sun.COM case e1000_82583:
1115*11143SGuoqing.Zhu@Sun.COM (void) e1000_enable_tx_pkt_filtering_generic(hw);
111610680SMin.Xu@Sun.COM reg_data = E1000_READ_REG(hw, E1000_GCR);
111710680SMin.Xu@Sun.COM reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
111810680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_GCR, reg_data);
111910680SMin.Xu@Sun.COM break;
112010680SMin.Xu@Sun.COM default:
11216735Scc210113 reg_data = E1000_READ_REG(hw, E1000_TXDCTL(1));
11224919Sxy150489 reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
11234919Sxy150489 E1000_TXDCTL_FULL_TX_DESC_WB |
11244919Sxy150489 E1000_TXDCTL_COUNT_DESC;
11256735Scc210113 E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg_data);
112610680SMin.Xu@Sun.COM break;
11274919Sxy150489 }
11284919Sxy150489
11294919Sxy150489 /*
11304919Sxy150489 * Clear all of the statistics registers (clear on read). It is
11314919Sxy150489 * important that we do this after we have tried to establish link
11324919Sxy150489 * because the symbol error count will increment wildly if there
11334919Sxy150489 * is no link.
11344919Sxy150489 */
11354919Sxy150489 e1000_clear_hw_cntrs_82571(hw);
11364919Sxy150489
11374919Sxy150489 return (ret_val);
11384919Sxy150489 }
11394919Sxy150489
11404919Sxy150489 /*
11414919Sxy150489 * e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
11424919Sxy150489 * @hw: pointer to the HW structure
11434919Sxy150489 *
11444919Sxy150489 * Initializes required hardware-dependent bits needed for normal operation.
11454919Sxy150489 */
11464919Sxy150489 static void
e1000_initialize_hw_bits_82571(struct e1000_hw * hw)11474919Sxy150489 e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
11484919Sxy150489 {
11494919Sxy150489 u32 reg;
11504919Sxy150489
11514919Sxy150489 DEBUGFUNC("e1000_initialize_hw_bits_82571");
11524919Sxy150489
11534919Sxy150489 /* Transmit Descriptor Control 0 */
11546735Scc210113 reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
11554919Sxy150489 reg |= (1 << 22);
11566735Scc210113 E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
11574919Sxy150489
11584919Sxy150489 /* Transmit Descriptor Control 1 */
11596735Scc210113 reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
11604919Sxy150489 reg |= (1 << 22);
11616735Scc210113 E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
11624919Sxy150489
11634919Sxy150489 /* Transmit Arbitration Control 0 */
11646735Scc210113 reg = E1000_READ_REG(hw, E1000_TARC(0));
11654919Sxy150489 reg &= ~(0xF << 27); /* 30:27 */
11664919Sxy150489 switch (hw->mac.type) {
11674919Sxy150489 case e1000_82571:
11684919Sxy150489 case e1000_82572:
11694919Sxy150489 reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
11704919Sxy150489 break;
11714919Sxy150489 default:
11724919Sxy150489 break;
11734919Sxy150489 }
11746735Scc210113 E1000_WRITE_REG(hw, E1000_TARC(0), reg);
11754919Sxy150489
11764919Sxy150489 /* Transmit Arbitration Control 1 */
11776735Scc210113 reg = E1000_READ_REG(hw, E1000_TARC(1));
11784919Sxy150489 switch (hw->mac.type) {
11794919Sxy150489 case e1000_82571:
11804919Sxy150489 case e1000_82572:
11814919Sxy150489 reg &= ~((1 << 29) | (1 << 30));
11824919Sxy150489 reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
11834919Sxy150489 if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
11844919Sxy150489 reg &= ~(1 << 28);
11854919Sxy150489 else
11864919Sxy150489 reg |= (1 << 28);
11876735Scc210113 E1000_WRITE_REG(hw, E1000_TARC(1), reg);
11884919Sxy150489 break;
11894919Sxy150489 default:
11904919Sxy150489 break;
11914919Sxy150489 }
11924919Sxy150489
11934919Sxy150489 /* Device Control */
119410680SMin.Xu@Sun.COM switch (hw->mac.type) {
119510680SMin.Xu@Sun.COM case e1000_82573:
119610680SMin.Xu@Sun.COM case e1000_82574:
119710680SMin.Xu@Sun.COM case e1000_82583:
11984919Sxy150489 reg = E1000_READ_REG(hw, E1000_CTRL);
11994919Sxy150489 reg &= ~(1 << 29);
12004919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, reg);
120110680SMin.Xu@Sun.COM break;
120210680SMin.Xu@Sun.COM default:
120310680SMin.Xu@Sun.COM break;
12044919Sxy150489 }
12054919Sxy150489
12064919Sxy150489 /* Extended Device Control */
120710680SMin.Xu@Sun.COM switch (hw->mac.type) {
120810680SMin.Xu@Sun.COM case e1000_82573:
120910680SMin.Xu@Sun.COM case e1000_82574:
121010680SMin.Xu@Sun.COM case e1000_82583:
12114919Sxy150489 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
12124919Sxy150489 reg &= ~(1 << 23);
12134919Sxy150489 reg |= (1 << 22);
12144919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
121510680SMin.Xu@Sun.COM break;
121610680SMin.Xu@Sun.COM default:
121710680SMin.Xu@Sun.COM break;
121810680SMin.Xu@Sun.COM }
121910680SMin.Xu@Sun.COM
122010680SMin.Xu@Sun.COM if (hw->mac.type == e1000_82571) {
122110680SMin.Xu@Sun.COM reg = E1000_READ_REG(hw, E1000_PBA_ECC);
122210680SMin.Xu@Sun.COM reg |= E1000_PBA_ECC_CORR_EN;
122310680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_PBA_ECC, reg);
12244919Sxy150489 }
12257607STed.You@Sun.COM
122610680SMin.Xu@Sun.COM /*
122710680SMin.Xu@Sun.COM * Workaround for hardware errata.
122810680SMin.Xu@Sun.COM * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
122910680SMin.Xu@Sun.COM */
123010680SMin.Xu@Sun.COM if ((hw->mac.type == e1000_82571) ||
123110680SMin.Xu@Sun.COM (hw->mac.type == e1000_82572)) {
123210680SMin.Xu@Sun.COM reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
123310680SMin.Xu@Sun.COM reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
123410680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
123510680SMin.Xu@Sun.COM }
123610680SMin.Xu@Sun.COM
123710680SMin.Xu@Sun.COM /* PCI-Ex Control Registers */
123810680SMin.Xu@Sun.COM switch (hw->mac.type) {
123910680SMin.Xu@Sun.COM case e1000_82574:
124010680SMin.Xu@Sun.COM case e1000_82583:
12417607STed.You@Sun.COM reg = E1000_READ_REG(hw, E1000_GCR);
12427607STed.You@Sun.COM reg |= (1 << 22);
12437607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_GCR, reg);
124410680SMin.Xu@Sun.COM /*
124510680SMin.Xu@Sun.COM * Workaround for hardware errata.
124610680SMin.Xu@Sun.COM * apply workaround for hardware errata documented in errata
124710680SMin.Xu@Sun.COM * docs Fixes issue where some error prone or unreliable PCIe
124810680SMin.Xu@Sun.COM * completions are occurring, particularly with ASPM enabled.
124910680SMin.Xu@Sun.COM * Without fix, issue can cause tx timeouts.
125010680SMin.Xu@Sun.COM */
125110680SMin.Xu@Sun.COM reg = E1000_READ_REG(hw, E1000_GCR2);
125210680SMin.Xu@Sun.COM reg |= 1;
125310680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_GCR2, reg);
125410680SMin.Xu@Sun.COM break;
125510680SMin.Xu@Sun.COM default:
125610680SMin.Xu@Sun.COM break;
12577607STed.You@Sun.COM }
12584919Sxy150489 }
12594919Sxy150489
12604919Sxy150489 /*
12614919Sxy150489 * e1000_clear_vfta_82571 - Clear VLAN filter table
12624919Sxy150489 * @hw: pointer to the HW structure
12634919Sxy150489 *
12644919Sxy150489 * Clears the register array which contains the VLAN filter table by
12654919Sxy150489 * setting all the values to 0.
12664919Sxy150489 */
12674919Sxy150489 static void
e1000_clear_vfta_82571(struct e1000_hw * hw)12684919Sxy150489 e1000_clear_vfta_82571(struct e1000_hw *hw)
12694919Sxy150489 {
12704919Sxy150489 u32 offset;
12714919Sxy150489 u32 vfta_value = 0;
12724919Sxy150489 u32 vfta_offset = 0;
12734919Sxy150489 u32 vfta_bit_in_reg = 0;
12744919Sxy150489
12754919Sxy150489 DEBUGFUNC("e1000_clear_vfta_82571");
12764919Sxy150489
127710680SMin.Xu@Sun.COM switch (hw->mac.type) {
127810680SMin.Xu@Sun.COM case e1000_82573:
127910680SMin.Xu@Sun.COM case e1000_82574:
128010680SMin.Xu@Sun.COM case e1000_82583:
12814919Sxy150489 if (hw->mng_cookie.vlan_id != 0) {
12824919Sxy150489 /*
128310680SMin.Xu@Sun.COM * The VFTA is a 4096b bit-field, each identifying
128410680SMin.Xu@Sun.COM * a single VLAN ID. The following operations
128510680SMin.Xu@Sun.COM * determine which 32b entry (i.e. offset) into the
128610680SMin.Xu@Sun.COM * array we want to set the VLAN ID (i.e. bit) of
128710680SMin.Xu@Sun.COM * the manageability unit.
12884919Sxy150489 */
12894919Sxy150489 vfta_offset = (hw->mng_cookie.vlan_id >>
129010680SMin.Xu@Sun.COM E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
129110680SMin.Xu@Sun.COM
12924919Sxy150489 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
12934919Sxy150489 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
12944919Sxy150489 }
129510680SMin.Xu@Sun.COM
129610680SMin.Xu@Sun.COM for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE;
129710680SMin.Xu@Sun.COM offset ++) {
129810680SMin.Xu@Sun.COM /*
129910680SMin.Xu@Sun.COM * If the offset we want to clear is the same offset of
130010680SMin.Xu@Sun.COM * the manageability VLAN ID, then clear all bits except
130110680SMin.Xu@Sun.COM * that of the manageability unit
130210680SMin.Xu@Sun.COM */
130310680SMin.Xu@Sun.COM vfta_value = (offset == vfta_offset) ?
130410680SMin.Xu@Sun.COM vfta_bit_in_reg : 0;
130510680SMin.Xu@Sun.COM E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset,
130610680SMin.Xu@Sun.COM vfta_value);
130710680SMin.Xu@Sun.COM E1000_WRITE_FLUSH(hw);
130810680SMin.Xu@Sun.COM }
130910680SMin.Xu@Sun.COM break;
131010680SMin.Xu@Sun.COM default:
131110680SMin.Xu@Sun.COM break;
13124919Sxy150489 }
13134919Sxy150489 }
13144919Sxy150489
13154919Sxy150489 /*
13167607STed.You@Sun.COM * e1000_check_mng_mode_82574 - Check manageability is enabled
13177607STed.You@Sun.COM * @hw: pointer to the HW structure
13187607STed.You@Sun.COM *
13197607STed.You@Sun.COM * Reads the NVM Initialization Control Word 2 and returns true
13207607STed.You@Sun.COM * (>0) if any manageability is enabled, else false (0).
13217607STed.You@Sun.COM */
13227607STed.You@Sun.COM static bool
e1000_check_mng_mode_82574(struct e1000_hw * hw)13237607STed.You@Sun.COM e1000_check_mng_mode_82574(struct e1000_hw *hw)
13247607STed.You@Sun.COM {
13257607STed.You@Sun.COM u16 data;
13267607STed.You@Sun.COM
13277607STed.You@Sun.COM DEBUGFUNC("e1000_check_mng_mode_82574");
13287607STed.You@Sun.COM
13297607STed.You@Sun.COM hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data);
13307607STed.You@Sun.COM return ((data & E1000_NVM_INIT_CTRL2_MNGM) != 0);
13317607STed.You@Sun.COM }
13327607STed.You@Sun.COM
13337607STed.You@Sun.COM /*
13347607STed.You@Sun.COM * e1000_led_on_82574 - Turn LED on
13357607STed.You@Sun.COM * @hw: pointer to the HW structure
13367607STed.You@Sun.COM *
13377607STed.You@Sun.COM * Turn LED on.
13387607STed.You@Sun.COM */
13397607STed.You@Sun.COM static s32
e1000_led_on_82574(struct e1000_hw * hw)13407607STed.You@Sun.COM e1000_led_on_82574(struct e1000_hw *hw)
13417607STed.You@Sun.COM {
13427607STed.You@Sun.COM u32 ctrl;
13437607STed.You@Sun.COM u32 i;
13447607STed.You@Sun.COM
13457607STed.You@Sun.COM DEBUGFUNC("e1000_led_on_82574");
13467607STed.You@Sun.COM
13477607STed.You@Sun.COM ctrl = hw->mac.ledctl_mode2;
13487607STed.You@Sun.COM if (!(E1000_STATUS_LU & E1000_READ_REG(hw, E1000_STATUS))) {
13497607STed.You@Sun.COM /*
13507607STed.You@Sun.COM * If no link, then turn LED on by setting the invert bit
13517607STed.You@Sun.COM * for each LED that's "on" (0x0E) in ledctl_mode2.
13527607STed.You@Sun.COM */
13537607STed.You@Sun.COM for (i = 0; i < 4; i++)
13547607STed.You@Sun.COM if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
13557607STed.You@Sun.COM E1000_LEDCTL_MODE_LED_ON)
13567607STed.You@Sun.COM ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
13577607STed.You@Sun.COM }
13587607STed.You@Sun.COM E1000_WRITE_REG(hw, E1000_LEDCTL, ctrl);
13597607STed.You@Sun.COM
13607607STed.You@Sun.COM return (E1000_SUCCESS);
13617607STed.You@Sun.COM }
13627607STed.You@Sun.COM
13637607STed.You@Sun.COM /*
13644919Sxy150489 * e1000_setup_link_82571 - Setup flow control and link settings
13654919Sxy150489 * @hw: pointer to the HW structure
13664919Sxy150489 *
13674919Sxy150489 * Determines which flow control settings to use, then configures flow
13684919Sxy150489 * control. Calls the appropriate media-specific link configuration
13694919Sxy150489 * function. Assuming the adapter has a valid link partner, a valid link
13704919Sxy150489 * should be established. Assumes the hardware has previously been reset
13714919Sxy150489 * and the transmitter and receiver are not enabled.
13724919Sxy150489 */
13734919Sxy150489 static s32
e1000_setup_link_82571(struct e1000_hw * hw)13744919Sxy150489 e1000_setup_link_82571(struct e1000_hw *hw)
13754919Sxy150489 {
13764919Sxy150489 DEBUGFUNC("e1000_setup_link_82571");
13774919Sxy150489
13784919Sxy150489 /*
13796735Scc210113 * 82573 does not have a word in the NVM to determine the default flow
13806735Scc210113 * control setting, so we explicitly set it to full.
13814919Sxy150489 */
138210680SMin.Xu@Sun.COM switch (hw->mac.type) {
138310680SMin.Xu@Sun.COM case e1000_82573:
138410680SMin.Xu@Sun.COM case e1000_82574:
138510680SMin.Xu@Sun.COM case e1000_82583:
138610680SMin.Xu@Sun.COM if (hw->fc.requested_mode == e1000_fc_default)
138710680SMin.Xu@Sun.COM hw->fc.requested_mode = e1000_fc_full;
138810680SMin.Xu@Sun.COM break;
138910680SMin.Xu@Sun.COM default:
139010680SMin.Xu@Sun.COM break;
139110680SMin.Xu@Sun.COM }
13924919Sxy150489 return (e1000_setup_link_generic(hw));
13934919Sxy150489 }
13944919Sxy150489
13954919Sxy150489 /*
13964919Sxy150489 * e1000_setup_copper_link_82571 - Configure copper link settings
13974919Sxy150489 * @hw: pointer to the HW structure
13984919Sxy150489 *
13994919Sxy150489 * Configures the link for auto-neg or forced speed and duplex. Then we check
14004919Sxy150489 * for link, once link is established calls to configure collision distance
14014919Sxy150489 * and flow control are called.
14024919Sxy150489 */
14034919Sxy150489 static s32
e1000_setup_copper_link_82571(struct e1000_hw * hw)14044919Sxy150489 e1000_setup_copper_link_82571(struct e1000_hw *hw)
14054919Sxy150489 {
140610680SMin.Xu@Sun.COM u32 ctrl;
14074919Sxy150489 s32 ret_val;
14084919Sxy150489
14094919Sxy150489 DEBUGFUNC("e1000_setup_copper_link_82571");
14104919Sxy150489
14114919Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL);
14124919Sxy150489 ctrl |= E1000_CTRL_SLU;
14134919Sxy150489 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
14144919Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
14154919Sxy150489
14164919Sxy150489 switch (hw->phy.type) {
14174919Sxy150489 case e1000_phy_m88:
14186735Scc210113 case e1000_phy_bm:
14194919Sxy150489 ret_val = e1000_copper_link_setup_m88(hw);
14204919Sxy150489 break;
14214919Sxy150489 case e1000_phy_igp_2:
14224919Sxy150489 ret_val = e1000_copper_link_setup_igp(hw);
14234919Sxy150489 break;
14244919Sxy150489 default:
14254919Sxy150489 ret_val = -E1000_ERR_PHY;
14264919Sxy150489 break;
14274919Sxy150489 }
14284919Sxy150489
14294919Sxy150489 if (ret_val)
14304919Sxy150489 goto out;
14314919Sxy150489
14324919Sxy150489 ret_val = e1000_setup_copper_link_generic(hw);
14334919Sxy150489
14344919Sxy150489 out:
14354919Sxy150489 return (ret_val);
14364919Sxy150489 }
14374919Sxy150489
14384919Sxy150489 /*
14394919Sxy150489 * e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
14404919Sxy150489 * @hw: pointer to the HW structure
14414919Sxy150489 *
14424919Sxy150489 * Configures collision distance and flow control for fiber and serdes links.
14434919Sxy150489 * Upon successful setup, poll for link.
14444919Sxy150489 */
14454919Sxy150489 static s32
e1000_setup_fiber_serdes_link_82571(struct e1000_hw * hw)14464919Sxy150489 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
14474919Sxy150489 {
14484919Sxy150489 DEBUGFUNC("e1000_setup_fiber_serdes_link_82571");
14494919Sxy150489
14504919Sxy150489 switch (hw->mac.type) {
14514919Sxy150489 case e1000_82571:
14524919Sxy150489 case e1000_82572:
14534919Sxy150489 /*
14546735Scc210113 * If SerDes loopback mode is entered, there is no form of
14556735Scc210113 * reset to take the adapter out of that mode. So we have to
14566735Scc210113 * explicitly take the adapter out of loopback mode. This
14576735Scc210113 * prevents drivers from twiddling their thumbs if another
14586735Scc210113 * tool failed to take it out of loopback mode.
14594919Sxy150489 */
14604919Sxy150489 E1000_WRITE_REG(hw, E1000_SCTL,
14614919Sxy150489 E1000_SCTL_DISABLE_SERDES_LOOPBACK);
14624919Sxy150489 break;
14634919Sxy150489 default:
14644919Sxy150489 break;
14654919Sxy150489 }
14664919Sxy150489
14674919Sxy150489 return (e1000_setup_fiber_serdes_link_generic(hw));
14684919Sxy150489 }
14694919Sxy150489
14704919Sxy150489 /*
147110680SMin.Xu@Sun.COM * e1000_check_for_serdes_link_82571 - Check for link (Serdes)
147210680SMin.Xu@Sun.COM * @hw: pointer to the HW structure
147310680SMin.Xu@Sun.COM *
147410680SMin.Xu@Sun.COM * Reports the link state as up or down.
147510680SMin.Xu@Sun.COM *
147610680SMin.Xu@Sun.COM * If autonegotiation is supported by the link partner, the link state is
147710680SMin.Xu@Sun.COM * determined by the result of autongotiation. This is the most likely case.
147810680SMin.Xu@Sun.COM * If autonegotiation is not supported by the link partner, and the link
147910680SMin.Xu@Sun.COM * has a valid signal, force the link up.
148010680SMin.Xu@Sun.COM *
148110680SMin.Xu@Sun.COM * The link state is represented internally here by 4 states:
148210680SMin.Xu@Sun.COM *
148310680SMin.Xu@Sun.COM * 1) down
148410680SMin.Xu@Sun.COM * 2) autoneg_progress
148510680SMin.Xu@Sun.COM * 3) autoneg_complete (the link sucessfully autonegotiated)
148610680SMin.Xu@Sun.COM * 4) forced_up (the link has been forced up, it did not autonegotiate)
148710680SMin.Xu@Sun.COM */
148810680SMin.Xu@Sun.COM s32
e1000_check_for_serdes_link_82571(struct e1000_hw * hw)148910680SMin.Xu@Sun.COM e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
149010680SMin.Xu@Sun.COM {
149110680SMin.Xu@Sun.COM struct e1000_mac_info *mac = &hw->mac;
149210680SMin.Xu@Sun.COM u32 rxcw;
149310680SMin.Xu@Sun.COM u32 ctrl;
149410680SMin.Xu@Sun.COM u32 status;
149510680SMin.Xu@Sun.COM s32 ret_val = E1000_SUCCESS;
149610680SMin.Xu@Sun.COM
149710680SMin.Xu@Sun.COM DEBUGFUNC("e1000_check_for_serdes_link_82571");
149810680SMin.Xu@Sun.COM
149910680SMin.Xu@Sun.COM ctrl = E1000_READ_REG(hw, E1000_CTRL);
150010680SMin.Xu@Sun.COM status = E1000_READ_REG(hw, E1000_STATUS);
150110680SMin.Xu@Sun.COM rxcw = E1000_READ_REG(hw, E1000_RXCW);
150210680SMin.Xu@Sun.COM
150310680SMin.Xu@Sun.COM if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
150410680SMin.Xu@Sun.COM
150510680SMin.Xu@Sun.COM /* Receiver is synchronized with no invalid bits. */
150610680SMin.Xu@Sun.COM switch (mac->serdes_link_state) {
150710680SMin.Xu@Sun.COM case e1000_serdes_link_autoneg_complete:
150810680SMin.Xu@Sun.COM if (!(status & E1000_STATUS_LU)) {
150910680SMin.Xu@Sun.COM /*
151010680SMin.Xu@Sun.COM * We have lost link, retry autoneg before
151110680SMin.Xu@Sun.COM * reporting link failure
151210680SMin.Xu@Sun.COM */
151310680SMin.Xu@Sun.COM mac->serdes_link_state =
151410680SMin.Xu@Sun.COM e1000_serdes_link_autoneg_progress;
151510680SMin.Xu@Sun.COM mac->serdes_has_link = false;
151610680SMin.Xu@Sun.COM DEBUGOUT("AN_UP -> AN_PROG\n");
151710680SMin.Xu@Sun.COM }
151810680SMin.Xu@Sun.COM break;
151910680SMin.Xu@Sun.COM
152010680SMin.Xu@Sun.COM case e1000_serdes_link_forced_up:
152110680SMin.Xu@Sun.COM /*
152210680SMin.Xu@Sun.COM * If we are receiving /C/ ordered sets, re-enable
152310680SMin.Xu@Sun.COM * auto-negotiation in the TXCW register and disable
152410680SMin.Xu@Sun.COM * forced link in the Device Control register in an
152510680SMin.Xu@Sun.COM * attempt to auto-negotiate with our link partner.
152610680SMin.Xu@Sun.COM */
152710680SMin.Xu@Sun.COM if (rxcw & E1000_RXCW_C) {
152810680SMin.Xu@Sun.COM /* Enable autoneg, and unforce link up */
152910680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
153010680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL,
153110680SMin.Xu@Sun.COM (ctrl & ~E1000_CTRL_SLU));
153210680SMin.Xu@Sun.COM mac->serdes_link_state =
153310680SMin.Xu@Sun.COM e1000_serdes_link_autoneg_progress;
153410680SMin.Xu@Sun.COM mac->serdes_has_link = false;
153510680SMin.Xu@Sun.COM DEBUGOUT("FORCED_UP -> AN_PROG\n");
153610680SMin.Xu@Sun.COM }
153710680SMin.Xu@Sun.COM break;
153810680SMin.Xu@Sun.COM
153910680SMin.Xu@Sun.COM case e1000_serdes_link_autoneg_progress:
154010680SMin.Xu@Sun.COM if (rxcw & E1000_RXCW_C) {
154110680SMin.Xu@Sun.COM /*
154210680SMin.Xu@Sun.COM * We received /C/ ordered sets, meaning the
154310680SMin.Xu@Sun.COM * link partner has autonegotiated, and we can
154410680SMin.Xu@Sun.COM * trust the Link Up (LU) status bit
154510680SMin.Xu@Sun.COM */
154610680SMin.Xu@Sun.COM if (status & E1000_STATUS_LU) {
154710680SMin.Xu@Sun.COM mac->serdes_link_state =
154810680SMin.Xu@Sun.COM e1000_serdes_link_autoneg_complete;
154910680SMin.Xu@Sun.COM DEBUGOUT("AN_PROG -> AN_UP\n");
155010680SMin.Xu@Sun.COM mac->serdes_has_link = true;
155110680SMin.Xu@Sun.COM } else {
155210680SMin.Xu@Sun.COM /* Autoneg completed, but failed */
155310680SMin.Xu@Sun.COM mac->serdes_link_state =
155410680SMin.Xu@Sun.COM e1000_serdes_link_down;
155510680SMin.Xu@Sun.COM DEBUGOUT("AN_PROG -> DOWN\n");
155610680SMin.Xu@Sun.COM }
155710680SMin.Xu@Sun.COM } else {
155810680SMin.Xu@Sun.COM /*
155910680SMin.Xu@Sun.COM * The link partner did not autoneg.
156010680SMin.Xu@Sun.COM * Force link up and full duplex, and change
156110680SMin.Xu@Sun.COM * state to forced.
156210680SMin.Xu@Sun.COM */
156310680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_TXCW,
156410680SMin.Xu@Sun.COM (mac->txcw & ~E1000_TXCW_ANE));
156510680SMin.Xu@Sun.COM ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
156610680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
156710680SMin.Xu@Sun.COM
156810680SMin.Xu@Sun.COM /* Configure Flow Control after link up. */
156910680SMin.Xu@Sun.COM ret_val =
157010680SMin.Xu@Sun.COM e1000_config_fc_after_link_up_generic(hw);
157110680SMin.Xu@Sun.COM if (ret_val) {
157210680SMin.Xu@Sun.COM DEBUGOUT("Error config flow control\n");
157310680SMin.Xu@Sun.COM break;
157410680SMin.Xu@Sun.COM }
157510680SMin.Xu@Sun.COM mac->serdes_link_state =
157610680SMin.Xu@Sun.COM e1000_serdes_link_forced_up;
157710680SMin.Xu@Sun.COM mac->serdes_has_link = true;
157810680SMin.Xu@Sun.COM DEBUGOUT("AN_PROG -> FORCED_UP\n");
157910680SMin.Xu@Sun.COM }
158010680SMin.Xu@Sun.COM break;
158110680SMin.Xu@Sun.COM
158210680SMin.Xu@Sun.COM case e1000_serdes_link_down:
158310680SMin.Xu@Sun.COM default:
158410680SMin.Xu@Sun.COM /*
158510680SMin.Xu@Sun.COM * The link was down but the receiver has now gained
158610680SMin.Xu@Sun.COM * valid sync, so lets see if we can bring the link
158710680SMin.Xu@Sun.COM * up.
158810680SMin.Xu@Sun.COM */
158910680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
159010680SMin.Xu@Sun.COM E1000_WRITE_REG(hw, E1000_CTRL,
159110680SMin.Xu@Sun.COM (ctrl & ~E1000_CTRL_SLU));
159210680SMin.Xu@Sun.COM mac->serdes_link_state =
159310680SMin.Xu@Sun.COM e1000_serdes_link_autoneg_progress;
159410680SMin.Xu@Sun.COM DEBUGOUT("DOWN -> AN_PROG\n");
159510680SMin.Xu@Sun.COM break;
159610680SMin.Xu@Sun.COM }
159710680SMin.Xu@Sun.COM } else {
159810680SMin.Xu@Sun.COM if (!(rxcw & E1000_RXCW_SYNCH)) {
159910680SMin.Xu@Sun.COM mac->serdes_has_link = false;
160010680SMin.Xu@Sun.COM mac->serdes_link_state = e1000_serdes_link_down;
160110680SMin.Xu@Sun.COM DEBUGOUT("ANYSTATE -> DOWN\n");
160210680SMin.Xu@Sun.COM } else {
160310680SMin.Xu@Sun.COM /*
160410680SMin.Xu@Sun.COM * We have sync, and can tolerate one
160510680SMin.Xu@Sun.COM * invalid (IV) codeword before declaring
160610680SMin.Xu@Sun.COM * link down, so reread to look again
160710680SMin.Xu@Sun.COM */
160810680SMin.Xu@Sun.COM usec_delay(10);
160910680SMin.Xu@Sun.COM rxcw = E1000_READ_REG(hw, E1000_RXCW);
161010680SMin.Xu@Sun.COM if (rxcw & E1000_RXCW_IV) {
161110680SMin.Xu@Sun.COM mac->serdes_link_state = e1000_serdes_link_down;
161210680SMin.Xu@Sun.COM mac->serdes_has_link = false;
161310680SMin.Xu@Sun.COM DEBUGOUT("ANYSTATE -> DOWN\n");
161410680SMin.Xu@Sun.COM }
161510680SMin.Xu@Sun.COM }
161610680SMin.Xu@Sun.COM }
161710680SMin.Xu@Sun.COM
161810680SMin.Xu@Sun.COM return (ret_val);
161910680SMin.Xu@Sun.COM }
162010680SMin.Xu@Sun.COM
162110680SMin.Xu@Sun.COM /*
16224919Sxy150489 * e1000_valid_led_default_82571 - Verify a valid default LED config
16234919Sxy150489 * @hw: pointer to the HW structure
16244919Sxy150489 * @data: pointer to the NVM (EEPROM)
16254919Sxy150489 *
16264919Sxy150489 * Read the EEPROM for the current default LED configuration. If the
16274919Sxy150489 * LED configuration is not valid, set to a valid LED configuration.
16284919Sxy150489 */
16294919Sxy150489 static s32
e1000_valid_led_default_82571(struct e1000_hw * hw,u16 * data)16304919Sxy150489 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 * data)
16314919Sxy150489 {
16324919Sxy150489 s32 ret_val;
16334919Sxy150489
16344919Sxy150489 DEBUGFUNC("e1000_valid_led_default_82571");
16354919Sxy150489
16366735Scc210113 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
16374919Sxy150489 if (ret_val) {
16384919Sxy150489 DEBUGOUT("NVM Read Error\n");
16394919Sxy150489 goto out;
16404919Sxy150489 }
16414919Sxy150489
164210680SMin.Xu@Sun.COM switch (hw->mac.type) {
164310680SMin.Xu@Sun.COM case e1000_82573:
164410680SMin.Xu@Sun.COM case e1000_82574:
164510680SMin.Xu@Sun.COM case e1000_82583:
164610680SMin.Xu@Sun.COM if (*data == ID_LED_RESERVED_F746)
164710680SMin.Xu@Sun.COM *data = ID_LED_DEFAULT_82573;
164810680SMin.Xu@Sun.COM break;
164910680SMin.Xu@Sun.COM default:
165010680SMin.Xu@Sun.COM if (*data == ID_LED_RESERVED_0000 ||
165110680SMin.Xu@Sun.COM *data == ID_LED_RESERVED_FFFF)
165210680SMin.Xu@Sun.COM *data = ID_LED_DEFAULT;
165310680SMin.Xu@Sun.COM break;
165410680SMin.Xu@Sun.COM }
16554919Sxy150489
16564919Sxy150489 out:
16574919Sxy150489 return (ret_val);
16584919Sxy150489 }
16594919Sxy150489
16604919Sxy150489 /*
16614919Sxy150489 * e1000_get_laa_state_82571 - Get locally administered address state
16624919Sxy150489 * @hw: pointer to the HW structure
16634919Sxy150489 *
16646735Scc210113 * Retrieve and return the current locally administered address state.
16654919Sxy150489 */
16666735Scc210113 bool
e1000_get_laa_state_82571(struct e1000_hw * hw)16674919Sxy150489 e1000_get_laa_state_82571(struct e1000_hw *hw)
16684919Sxy150489 {
16694919Sxy150489 DEBUGFUNC("e1000_get_laa_state_82571");
16704919Sxy150489
16714919Sxy150489 if (hw->mac.type != e1000_82571)
16728479SChenlu.Chen@Sun.COM return (false);
16734919Sxy150489
16748479SChenlu.Chen@Sun.COM return (hw->dev_spec._82571.laa_is_present);
16754919Sxy150489 }
16764919Sxy150489
16774919Sxy150489 /*
16784919Sxy150489 * e1000_set_laa_state_82571 - Set locally administered address state
16794919Sxy150489 * @hw: pointer to the HW structure
16804919Sxy150489 * @state: enable/disable locally administered address
16814919Sxy150489 *
16826735Scc210113 * Enable/Disable the current locally administered address state.
16834919Sxy150489 */
16844919Sxy150489 void
e1000_set_laa_state_82571(struct e1000_hw * hw,bool state)16856735Scc210113 e1000_set_laa_state_82571(struct e1000_hw *hw, bool state)
16864919Sxy150489 {
16874919Sxy150489 DEBUGFUNC("e1000_set_laa_state_82571");
16884919Sxy150489
16894919Sxy150489 if (hw->mac.type != e1000_82571)
16904919Sxy150489 return;
16914919Sxy150489
16928479SChenlu.Chen@Sun.COM hw->dev_spec._82571.laa_is_present = state;
16934919Sxy150489
16944919Sxy150489 /* If workaround is activated... */
16954919Sxy150489 if (state) {
16964919Sxy150489 /*
16974919Sxy150489 * Hold a copy of the LAA in RAR[14] This is done so that
16986735Scc210113 * between the time RAR[0] gets clobbered and the time it gets
16996735Scc210113 * fixed, the actual LAA is in one of the RARs and no incoming
17006735Scc210113 * packets directed to this port are dropped. Eventually the
17016735Scc210113 * LAA will be in RAR[0] and RAR[14].
17024919Sxy150489 */
17034919Sxy150489 e1000_rar_set_generic(hw, hw->mac.addr,
17044919Sxy150489 hw->mac.rar_entry_count - 1);
17054919Sxy150489 }
17064919Sxy150489 }
17074919Sxy150489
17084919Sxy150489 /*
17094919Sxy150489 * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
17104919Sxy150489 * @hw: pointer to the HW structure
17114919Sxy150489 *
17124919Sxy150489 * Verifies that the EEPROM has completed the update. After updating the
17134919Sxy150489 * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
17144919Sxy150489 * the checksum fix is not implemented, we need to set the bit and update
17154919Sxy150489 * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
17164919Sxy150489 * we need to return bad checksum.
17174919Sxy150489 */
17184919Sxy150489 static s32
e1000_fix_nvm_checksum_82571(struct e1000_hw * hw)17194919Sxy150489 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
17204919Sxy150489 {
17214919Sxy150489 struct e1000_nvm_info *nvm = &hw->nvm;
17224919Sxy150489 s32 ret_val = E1000_SUCCESS;
17234919Sxy150489 u16 data;
17244919Sxy150489
17254919Sxy150489 DEBUGFUNC("e1000_fix_nvm_checksum_82571");
17264919Sxy150489
17274919Sxy150489 if (nvm->type != e1000_nvm_flash_hw)
17284919Sxy150489 goto out;
17294919Sxy150489
17304919Sxy150489 /*
17314919Sxy150489 * Check bit 4 of word 10h. If it is 0, firmware is done updating
17324919Sxy150489 * 10h-12h. Checksum may need to be fixed.
17334919Sxy150489 */
17346735Scc210113 ret_val = nvm->ops.read(hw, 0x10, 1, &data);
17354919Sxy150489 if (ret_val)
17364919Sxy150489 goto out;
17374919Sxy150489
17384919Sxy150489 if (!(data & 0x10)) {
17394919Sxy150489 /*
17406735Scc210113 * Read 0x23 and check bit 15. This bit is a 1 when the
17416735Scc210113 * checksum has already been fixed. If the checksum is still
17426735Scc210113 * wrong and this bit is a 1, we need to return bad checksum.
17436735Scc210113 * Otherwise, we need to set this bit to a 1 and update the
17444919Sxy150489 * checksum.
17454919Sxy150489 */
17466735Scc210113 ret_val = nvm->ops.read(hw, 0x23, 1, &data);
17474919Sxy150489 if (ret_val)
17484919Sxy150489 goto out;
17494919Sxy150489
17504919Sxy150489 if (!(data & 0x8000)) {
17514919Sxy150489 data |= 0x8000;
17526735Scc210113 ret_val = nvm->ops.write(hw, 0x23, 1, &data);
17534919Sxy150489 if (ret_val)
17544919Sxy150489 goto out;
17556735Scc210113 ret_val = nvm->ops.update(hw);
17564919Sxy150489 }
17574919Sxy150489 }
17584919Sxy150489
17594919Sxy150489 out:
17604919Sxy150489 return (ret_val);
17614919Sxy150489 }
17624919Sxy150489
17634919Sxy150489 /*
17646735Scc210113 * e1000_read_mac_addr_82571 - Read device MAC address
17656735Scc210113 * @hw: pointer to the HW structure
17666735Scc210113 */
17676735Scc210113 static s32
e1000_read_mac_addr_82571(struct e1000_hw * hw)17686735Scc210113 e1000_read_mac_addr_82571(struct e1000_hw *hw)
17696735Scc210113 {
17706735Scc210113 s32 ret_val = E1000_SUCCESS;
17716735Scc210113
17726735Scc210113 DEBUGFUNC("e1000_read_mac_addr_82571");
17736735Scc210113
177410680SMin.Xu@Sun.COM /*
177510680SMin.Xu@Sun.COM * If there's an alternate MAC address place it in RAR0
177610680SMin.Xu@Sun.COM * so that it will override the Si installed default perm
177710680SMin.Xu@Sun.COM * address.
177810680SMin.Xu@Sun.COM */
177910680SMin.Xu@Sun.COM ret_val = e1000_check_alt_mac_addr_generic(hw);
178010680SMin.Xu@Sun.COM if (ret_val)
178110680SMin.Xu@Sun.COM goto out;
178210680SMin.Xu@Sun.COM
178310680SMin.Xu@Sun.COM ret_val = e1000_read_mac_addr_generic(hw);
178410680SMin.Xu@Sun.COM
178510680SMin.Xu@Sun.COM out:
17866735Scc210113 return (ret_val);
17876735Scc210113 }
17886735Scc210113
17896735Scc210113 /*
17906735Scc210113 * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
17916735Scc210113 * @hw: pointer to the HW structure
17926735Scc210113 *
17936735Scc210113 * In the case of a PHY power down to save power, or to turn off link during a
17946735Scc210113 * driver unload, or wake on lan is not enabled, remove the link.
17956735Scc210113 */
17966735Scc210113 static void
e1000_power_down_phy_copper_82571(struct e1000_hw * hw)17976735Scc210113 e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
17986735Scc210113 {
17996735Scc210113 struct e1000_phy_info *phy = &hw->phy;
18006735Scc210113 struct e1000_mac_info *mac = &hw->mac;
18016735Scc210113
18026735Scc210113 if (!(phy->ops.check_reset_block))
18036735Scc210113 return;
18046735Scc210113
18056735Scc210113 /* If the management interface is not enabled, then power down */
18066735Scc210113 if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
18076735Scc210113 e1000_power_down_phy_copper(hw);
18086735Scc210113 }
18096735Scc210113
18106735Scc210113 /*
18114919Sxy150489 * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
18124919Sxy150489 * @hw: pointer to the HW structure
18134919Sxy150489 *
18144919Sxy150489 * Clears the hardware counters by reading the counter registers.
18154919Sxy150489 */
18164919Sxy150489 static void
e1000_clear_hw_cntrs_82571(struct e1000_hw * hw)18174919Sxy150489 e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
18184919Sxy150489 {
18194919Sxy150489 DEBUGFUNC("e1000_clear_hw_cntrs_82571");
18204919Sxy150489
18214919Sxy150489 e1000_clear_hw_cntrs_base_generic(hw);
182210680SMin.Xu@Sun.COM
18237426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC64);
18247426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC127);
18257426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC255);
18267426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC511);
18277426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC1023);
18287426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PRC1522);
18297426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC64);
18307426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC127);
18317426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC255);
18327426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC511);
18337426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC1023);
18347426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_PTC1522);
18354919Sxy150489
18367426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ALGNERRC);
18377426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_RXERRC);
18387426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_TNCRS);
18397426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_CEXTERR);
18407426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_TSCTC);
18417426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_TSCTFC);
18424919Sxy150489
18437426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_MGTPRC);
18447426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_MGTPDC);
18457426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_MGTPTC);
18464919Sxy150489
18477426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_IAC);
18487426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICRXOC);
18494919Sxy150489
18507426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICRXPTC);
18517426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICRXATC);
18527426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICTXPTC);
18537426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICTXATC);
18547426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICTXQEC);
18557426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICTXQMTC);
18567426SChenliang.Xu@Sun.COM (void) E1000_READ_REG(hw, E1000_ICRXDMTC);
18574919Sxy150489 }
1858