28 #include <linux/if_ether.h>
35 static void igb_phy_force_speed_duplex_setup(
struct e1000_hw *
hw,
41 static const u16 e1000_m88_cable_length_table[] =
43 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
44 (sizeof(e1000_m88_cable_length_table) / \
45 sizeof(e1000_m88_cable_length_table[0]))
47 static const u16 e1000_igp_2_cable_length_table[] =
48 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
49 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
50 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
51 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
52 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
53 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
54 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
55 104, 109, 114, 118, 121, 124};
56 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
57 (sizeof(e1000_igp_2_cable_length_table) / \
58 sizeof(e1000_igp_2_cable_length_table[0]))
91 ret_val = phy->
ops.read_reg(hw,
PHY_ID1, &phy_id);
95 phy->
id = (
u32)(phy_id << 16);
97 ret_val = phy->
ops.read_reg(hw,
PHY_ID2, &phy_id);
102 phy->
revision = (
u32)(phy_id & ~PHY_REVISION_MASK);
118 if (!(hw->
phy.ops.write_reg))
147 hw_dbg(
"PHY Address %d is out of range\n", offset);
175 hw_dbg(
"MDI Read did not complete\n");
205 hw_dbg(
"PHY Address %d is out of range\n", offset);
215 mdic = (((
u32)data) |
234 hw_dbg(
"MDI Write did not complete\n");
282 hw_dbg(
"I2CCMD Read did not complete\n");
286 hw_dbg(
"I2CCMD Error bit set\n");
291 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
308 u16 phy_data_swapped;
311 if ((hw->
phy.addr == 0) || (hw->
phy.addr > 7)) {
312 hw_dbg(
"PHY I2C Address %d is out of range.\n",
318 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
340 hw_dbg(
"I2CCMD Write did not complete\n");
344 hw_dbg(
"I2CCMD Error bit set\n");
365 if (!(hw->
phy.ops.acquire))
368 ret_val = hw->
phy.ops.acquire(hw);
377 hw->
phy.ops.release(hw);
385 hw->
phy.ops.release(hw);
404 if (!(hw->
phy.ops.acquire))
407 ret_val = hw->
phy.ops.acquire(hw);
416 hw->
phy.ops.release(hw);
424 hw->
phy.ops.release(hw);
449 ret_val = hw->
phy.ops.reset(hw);
451 hw_dbg(
"Error resetting the PHY.\n");
481 switch (hw->
phy.mdix) {
597 hw_dbg(
"Error committing the PHY changes\n");
601 ret_val = igb_set_master_slave_mode(hw);
685 hw_dbg(
"Error committing the PHY changes\n");
711 ret_val = phy->
ops.reset(hw);
713 hw_dbg(
"Error resetting the PHY.\n");
729 if (phy->
ops.set_d3_lplu_state)
730 ret_val = phy->
ops.set_d3_lplu_state(hw,
false);
732 hw_dbg(
"Error Disabling LPLU D3\n");
738 ret_val = phy->
ops.set_d0_lplu_state(hw,
false);
740 hw_dbg(
"Error Disabling LPLU D0\n");
767 if (hw->
mac.autoneg) {
775 ret_val = phy->
ops.read_reg(hw,
782 ret_val = phy->
ops.write_reg(hw,
841 static s32 igb_copper_link_autoneg(
struct e1000_hw *hw)
860 hw_dbg(
"Reconfiguring auto-neg advertisement params\n");
861 ret_val = igb_phy_setup_autoneg(hw);
863 hw_dbg(
"Error Setting up Auto-Negotiation\n");
866 hw_dbg(
"Restarting Auto-Neg\n");
886 ret_val = igb_wait_autoneg(hw);
888 hw_dbg(
"Error while waiting for "
889 "autoneg to complete\n");
894 hw->
mac.get_link_status =
true;
909 static s32 igb_phy_setup_autoneg(
struct e1000_hw *hw)
913 u16 mii_autoneg_adv_reg;
914 u16 mii_1000t_ctrl_reg = 0;
926 &mii_1000t_ctrl_reg);
954 hw_dbg(
"Advertise 10mb Half duplex\n");
960 hw_dbg(
"Advertise 10mb Full duplex\n");
966 hw_dbg(
"Advertise 100mb Half duplex\n");
972 hw_dbg(
"Advertise 100mb Full duplex\n");
978 hw_dbg(
"Advertise 1000mb Half duplex request denied!\n");
982 hw_dbg(
"Advertise 1000mb Full duplex\n");
1004 switch (hw->
fc.current_mode) {
1041 hw_dbg(
"Flow control param set incorrectly\n");
1050 hw_dbg(
"Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1053 ret_val = phy->
ops.write_reg(hw,
1055 mii_1000t_ctrl_reg);
1079 if (hw->
mac.autoneg) {
1084 ret_val = igb_copper_link_autoneg(hw);
1092 hw_dbg(
"Forcing Speed and Duplex\n");
1093 ret_val = hw->
phy.ops.force_speed_duplex(hw);
1095 hw_dbg(
"Error Forcing Speed and Duplex\n");
1112 hw_dbg(
"Valid link established!!!\n");
1116 hw_dbg(
"Unable to establish link!!!\n");
1142 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1163 hw_dbg(
"IGP PSCR: %X\n", phy_data);
1168 hw_dbg(
"Waiting for forced speed/duplex link on IGP phy.\n");
1178 hw_dbg(
"Link taking longer than expected.\n");
1223 hw_dbg(
"M88E1000 PSCR: %X\n", phy_data);
1229 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1241 hw_dbg(
"Waiting for forced speed/duplex link on M88 phy.\n");
1248 bool reset_dsp =
true;
1250 switch (hw->
phy.id) {
1262 hw_dbg(
"Link taking longer than expected.\n");
1268 ret_val = phy->
ops.write_reg(hw,
1273 ret_val = igb_phy_reset_dsp(hw);
1333 static void igb_phy_force_speed_duplex_setup(
struct e1000_hw *hw,
1369 hw_dbg(
"Forcing 100mb\n");
1374 hw_dbg(
"Forcing 10mb\n");
1402 if (!(hw->
phy.ops.read_reg))
1422 ret_val = phy->
ops.read_reg(hw,
1429 ret_val = phy->
ops.write_reg(hw,
1435 ret_val = phy->
ops.read_reg(hw,
1442 ret_val = phy->
ops.write_reg(hw,
1486 switch (phy->
type) {
1506 ret_val = phy->
ops.read_reg(hw, offset, &phy_data);
1548 static s32 igb_check_polarity_igp(
struct e1000_hw *hw)
1575 ret_val = phy->
ops.read_reg(hw, offset, &data);
1600 ret_val = hw->
phy.ops.read_reg(hw,
PHY_STATUS, &phy_status);
1603 ret_val = hw->
phy.ops.read_reg(hw,
PHY_STATUS, &phy_status);
1628 u32 usec_interval,
bool *success)
1633 for (i = 0; i < iterations; i++) {
1639 ret_val = hw->
phy.ops.read_reg(hw,
PHY_STATUS, &phy_status);
1648 ret_val = hw->
phy.ops.read_reg(hw,
PHY_STATUS, &phy_status);
1653 if (usec_interval >= 1000)
1654 mdelay(usec_interval/1000);
1659 *success = (i < iterations) ?
true :
false;
1709 u16 phy_data, phy_data2,
index, default_page, is_cm;
1711 switch (hw->
phy.id) {
1808 u16 phy_data,
i, agc_value = 0;
1809 u16 cur_agc_index, max_agc_index = 0;
1820 ret_val = phy->
ops.read_reg(hw, agc_reg_array[i], &phy_data);
1835 (cur_agc_index == 0)) {
1841 if (e1000_igp_2_cable_length_table[min_agc_index] >
1842 e1000_igp_2_cable_length_table[cur_agc_index])
1843 min_agc_index = cur_agc_index;
1844 if (e1000_igp_2_cable_length_table[max_agc_index] <
1845 e1000_igp_2_cable_length_table[cur_agc_index])
1846 max_agc_index = cur_agc_index;
1848 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1851 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1852 e1000_igp_2_cable_length_table[max_agc_index]);
1853 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1884 hw_dbg(
"Phy info is only valid for copper media\n");
1894 hw_dbg(
"Phy info is only valid if link is up\n");
1917 ret_val = phy->
ops.get_cable_length(hw);
1964 hw_dbg(
"Phy info is only valid if link is up\n");
1971 ret_val = igb_check_polarity_igp(hw);
1981 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1983 ret_val = phy->
ops.get_cable_length(hw);
2020 if (!(hw->
phy.ops.read_reg))
2059 ret_val = phy->
ops.acquire(hw);
2074 phy->
ops.release(hw);
2076 ret_val = phy->
ops.get_cfg_done(hw);
2090 hw_dbg(
"Running IGP 3 PHY init script\n");
2094 hw->
phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2096 hw->
phy.ops.write_reg(hw, 0x2F52, 0x0000);
2098 hw->
phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2100 hw->
phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2102 hw->
phy.ops.write_reg(hw, 0x2010, 0x10B0);
2104 hw->
phy.ops.write_reg(hw, 0x2011, 0x0000);
2106 hw->
phy.ops.write_reg(hw, 0x20DD, 0x249A);
2108 hw->
phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2110 hw->
phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2112 hw->
phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2114 hw->
phy.ops.write_reg(hw, 0x0000, 0x0140);
2116 hw->
phy.ops.write_reg(hw, 0x1F30, 0x1606);
2118 hw->
phy.ops.write_reg(hw, 0x1F31, 0xB814);
2120 hw->
phy.ops.write_reg(hw, 0x1F35, 0x002A);
2122 hw->
phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2124 hw->
phy.ops.write_reg(hw, 0x1F54, 0x0065);
2126 hw->
phy.ops.write_reg(hw, 0x1F55, 0x002A);
2128 hw->
phy.ops.write_reg(hw, 0x1F56, 0x002A);
2130 hw->
phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2132 hw->
phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2134 hw->
phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2136 hw->
phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2138 hw->
phy.ops.write_reg(hw, 0x1F79, 0x0210);
2140 hw->
phy.ops.write_reg(hw, 0x1895, 0x0003);
2142 hw->
phy.ops.write_reg(hw, 0x1796, 0x0008);
2144 hw->
phy.ops.write_reg(hw, 0x1798, 0xD008);
2149 hw->
phy.ops.write_reg(hw, 0x1898, 0xD918);
2151 hw->
phy.ops.write_reg(hw, 0x187A, 0x0800);
2156 hw->
phy.ops.write_reg(hw, 0x0019, 0x008D);
2158 hw->
phy.ops.write_reg(hw, 0x001B, 0x2080);
2160 hw->
phy.ops.write_reg(hw, 0x0014, 0x0045);
2162 hw->
phy.ops.write_reg(hw, 0x0000, 0x1340);
2224 static s32 igb_check_polarity_82580(
struct e1000_hw *hw)
2261 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2281 hw_dbg(
"I82580_PHY_CTRL_2: %X\n", phy_data);
2286 hw_dbg(
"Waiting for forced speed/duplex link on 82580 phy\n");
2296 hw_dbg(
"Link taking longer than expected.\n");
2333 hw_dbg(
"Phy info is only valid if link is up\n");
2340 ret_val = igb_check_polarity_82580(hw);
2352 ret_val = hw->
phy.ops.get_cable_length(hw);
2423 ret_val = hw->
phy.ops.acquire(hw);
2433 hw->
phy.ops.release(hw);
2453 ret_val = hw->
phy.ops.acquire(hw);
2463 hw->
phy.ops.release(hw);
2473 static s32 igb_set_master_slave_mode(
struct e1000_hw *hw)
2489 switch (hw->
phy.ms_type) {