28 #include <linux/pci.h>
30 #include <linux/sched.h>
35 static void ixgbe_i2c_start(
struct ixgbe_hw *
hw);
36 static void ixgbe_i2c_stop(
struct ixgbe_hw *
hw);
42 static void ixgbe_raise_i2c_clk(
struct ixgbe_hw *
hw,
u32 *i2cctl);
43 static void ixgbe_lower_i2c_clk(
struct ixgbe_hw *
hw,
u32 *i2cctl);
45 static bool ixgbe_get_i2c_data(
u32 *i2cctl);
46 static void ixgbe_i2c_bus_clear(
struct ixgbe_hw *
hw);
64 hw->
phy.mdio.prtad = phy_addr;
68 ixgbe_get_phy_type_from_id(hw->
phy.id);
71 hw->
phy.ops.read_reg(hw,
91 hw->
phy.mdio.prtad = 0;
114 hw->
phy.id = (
u32)(phy_id_high << 16);
118 hw->
phy.revision = (
u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
170 if (!hw->
phy.reset_if_overtemp &&
187 for (i = 0; i < 30; i++) {
199 hw_dbg(hw,
"PHY reset polling failed to complete.\n");
226 if (hw->
mac.ops.acquire_swfw_sync(hw, gssr) != 0)
253 hw_dbg(hw,
"PHY address command did not complete.\n");
264 (hw->
phy.mdio.prtad <<
280 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
284 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
285 hw_dbg(hw,
"PHY read command didn't complete\n");
294 *phy_data = (
u16)(data);
298 hw->
mac.ops.release_swfw_sync(hw, gssr);
324 if (hw->
mac.ops.acquire_swfw_sync(hw, gssr) != 0)
354 hw_dbg(hw,
"PHY address cmd didn't complete\n");
365 (hw->
phy.mdio.prtad <<
381 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
385 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
386 hw_dbg(hw,
"PHY address cmd didn't complete\n");
391 hw->
mac.ops.release_swfw_sync(hw, gssr);
407 u32 max_time_out = 10;
421 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
431 hw->
phy.ops.read_reg(hw,
437 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
440 hw->
phy.ops.write_reg(hw,
454 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
472 for (time_out = 0; time_out < max_time_out; time_out++) {
485 if (time_out == max_time_out) {
487 hw_dbg(hw,
"ixgbe_setup_phy_link_generic: time out");
502 bool autoneg_wait_to_complete)
509 hw->
phy.autoneg_advertised = 0;
521 hw->
phy.ops.setup_link(hw);
571 u32 max_time_out = 10;
585 for (time_out = 0; time_out < max_time_out; time_out++) {
587 status = hw->
phy.ops.read_reg(hw,
591 phy_link = phy_data &
593 phy_speed = phy_data &
595 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
598 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
617 u32 max_time_out = 10;
631 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
646 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
662 if (hw->
phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
680 for (time_out = 0; time_out < max_time_out; time_out++) {
692 if (time_out == max_time_out) {
694 hw_dbg(hw,
"ixgbe_setup_phy_link_tnx: time out");
741 bool end_data =
false;
753 for (i = 0; i < 100; i++) {
762 hw_dbg(hw,
"PHY reset did not complete.\n");
773 ret_val = hw->
eeprom.ops.read(hw, data_offset, &block_crc);
779 ret_val = hw->
eeprom.ops.read(hw, data_offset, &eword);
786 hw_dbg(hw,
"DELAY: %d MS\n", edata);
792 hw->
eeprom.ops.read(hw, data_offset++,
794 for (i = 0; i < edata; i++) {
795 hw->
eeprom.ops.read(hw, data_offset, &eword);
796 hw->
phy.ops.write_reg(hw, phy_offset,
798 hw_dbg(hw,
"Wrote %4.4x to %4.4x\n", eword,
813 hw_dbg(hw,
"Bad control value\n");
819 hw_dbg(hw,
"Bad control type\n");
842 u8 comp_codes_1g = 0;
843 u8 comp_codes_10g = 0;
844 u8 oui_bytes[3] = {0, 0, 0};
855 status = hw->
phy.ops.read_i2c_eeprom(hw,
862 goto err_read_i2c_eeprom;
865 hw->
mac.ops.set_lan_id(hw);
871 status = hw->
phy.ops.read_i2c_eeprom(hw,
878 goto err_read_i2c_eeprom;
880 status = hw->
phy.ops.read_i2c_eeprom(hw,
887 goto err_read_i2c_eeprom;
888 status = hw->
phy.ops.read_i2c_eeprom(hw,
895 goto err_read_i2c_eeprom;
924 if (hw->
bus.lan_id == 0)
931 hw->
phy.ops.read_i2c_eeprom(
936 if (hw->
bus.lan_id == 0)
946 }
else if (comp_codes_10g &
949 if (hw->
bus.lan_id == 0)
956 if (hw->
bus.lan_id == 0)
963 if (hw->
bus.lan_id == 0)
974 if (hw->
phy.sfp_type != stored_sfp_type)
975 hw->
phy.sfp_setup_needed =
true;
978 hw->
phy.multispeed_fiber =
false;
983 hw->
phy.multispeed_fiber =
true;
988 status = hw->
phy.ops.read_i2c_eeprom(hw,
995 goto err_read_i2c_eeprom;
997 status = hw->
phy.ops.read_i2c_eeprom(hw,
1004 goto err_read_i2c_eeprom;
1006 status = hw->
phy.ops.read_i2c_eeprom(hw,
1013 goto err_read_i2c_eeprom;
1020 switch (vendor_oui) {
1039 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1042 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1059 if (comp_codes_10g == 0 &&
1075 hw->
mac.ops.get_device_caps(hw, &enforce_sfp);
1086 e_warn(drv,
"WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.");
1090 "SFP+ module not supported\n");
1104 err_read_i2c_eeprom:
1127 u16 sfp_type = hw->
phy.sfp_type;
1155 if ((!*list_offset) || (*list_offset == 0xFFFF))
1165 hw->
eeprom.ops.read(hw, *list_offset, &sfp_id);
1168 if (sfp_id == sfp_type) {
1170 hw->
eeprom.ops.read(hw, *list_offset, data_offset);
1171 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1172 hw_dbg(hw,
"SFP+ module not supported\n");
1178 (*list_offset) += 2;
1179 if (hw->
eeprom.ops.read(hw, *list_offset, &sfp_id))
1185 hw_dbg(hw,
"No matching SFP+ module found\n");
1203 return hw->
phy.ops.read_i2c_byte(hw, byte_offset,
1219 return hw->
phy.ops.write_i2c_byte(hw, byte_offset,
1249 if (hw->
mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
1254 ixgbe_i2c_start(hw);
1257 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1261 status = ixgbe_get_i2c_ack(hw);
1265 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1269 status = ixgbe_get_i2c_ack(hw);
1273 ixgbe_i2c_start(hw);
1276 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1280 status = ixgbe_get_i2c_ack(hw);
1284 status = ixgbe_clock_in_i2c_byte(hw, data);
1288 status = ixgbe_clock_out_i2c_bit(hw, nack);
1296 hw->
mac.ops.release_swfw_sync(hw, swfw_mask);
1298 ixgbe_i2c_bus_clear(hw);
1300 if (retry < max_retry)
1301 hw_dbg(hw,
"I2C byte read error - Retrying.\n");
1303 hw_dbg(hw,
"I2C byte read error.\n");
1305 }
while (retry < max_retry);
1307 hw->
mac.ops.release_swfw_sync(hw, swfw_mask);
1335 if (hw->
mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
1337 goto write_byte_out;
1341 ixgbe_i2c_start(hw);
1343 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1347 status = ixgbe_get_i2c_ack(hw);
1351 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1355 status = ixgbe_get_i2c_ack(hw);
1359 status = ixgbe_clock_out_i2c_byte(hw, data);
1363 status = ixgbe_get_i2c_ack(hw);
1371 ixgbe_i2c_bus_clear(hw);
1373 if (retry < max_retry)
1374 hw_dbg(hw,
"I2C byte write error - Retrying.\n");
1376 hw_dbg(hw,
"I2C byte write error.\n");
1377 }
while (retry < max_retry);
1379 hw->
mac.ops.release_swfw_sync(hw, swfw_mask);
1391 static void ixgbe_i2c_start(
struct ixgbe_hw *hw)
1396 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1397 ixgbe_raise_i2c_clk(hw, &i2cctl);
1402 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1407 ixgbe_lower_i2c_clk(hw, &i2cctl);
1420 static void ixgbe_i2c_stop(
struct ixgbe_hw *hw)
1425 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1426 ixgbe_raise_i2c_clk(hw, &i2cctl);
1431 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1449 for (i = 7; i >= 0; i--) {
1450 ixgbe_clock_in_i2c_bit(hw, &bit);
1464 static s32 ixgbe_clock_out_i2c_byte(
struct ixgbe_hw *hw,
u8 data)
1471 for (i = 7; i >= 0; i--) {
1472 bit = (data >>
i) & 0x1;
1473 status = ixgbe_clock_out_i2c_bit(hw, bit);
1502 ixgbe_raise_i2c_clk(hw, &i2cctl);
1510 for (i = 0; i < timeout; i++) {
1512 ack = ixgbe_get_i2c_data(&i2cctl);
1520 hw_dbg(hw,
"I2C ack was not received.\n");
1524 ixgbe_lower_i2c_clk(hw, &i2cctl);
1539 static s32 ixgbe_clock_in_i2c_bit(
struct ixgbe_hw *hw,
bool *data)
1543 ixgbe_raise_i2c_clk(hw, &i2cctl);
1549 *data = ixgbe_get_i2c_data(&i2cctl);
1551 ixgbe_lower_i2c_clk(hw, &i2cctl);
1566 static s32 ixgbe_clock_out_i2c_bit(
struct ixgbe_hw *hw,
bool data)
1571 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1573 ixgbe_raise_i2c_clk(hw, &i2cctl);
1578 ixgbe_lower_i2c_clk(hw, &i2cctl);
1586 hw_dbg(hw,
"I2C data was not set to %X\n", data);
1598 static void ixgbe_raise_i2c_clk(
struct ixgbe_hw *hw,
u32 *i2cctl)
1604 for (i = 0; i < timeout; i++) {
1624 static void ixgbe_lower_i2c_clk(
struct ixgbe_hw *hw,
u32 *i2cctl)
1644 static s32 ixgbe_set_i2c_data(
struct ixgbe_hw *hw,
u32 *i2cctl,
bool data)
1661 if (data != ixgbe_get_i2c_data(i2cctl)) {
1663 hw_dbg(hw,
"Error - I2C data was not set to %X.\n", data);
1676 static bool ixgbe_get_i2c_data(
u32 *i2cctl)
1695 static void ixgbe_i2c_bus_clear(
struct ixgbe_hw *hw)
1700 ixgbe_i2c_start(hw);
1702 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1704 for (i = 0; i < 9; i++) {
1705 ixgbe_raise_i2c_clk(hw, &i2cctl);
1710 ixgbe_lower_i2c_clk(hw, &i2cctl);
1716 ixgbe_i2c_start(hw);