aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ixgbe/ixgbe_phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ixgbe/ixgbe_phy.c')
-rw-r--r--drivers/net/ixgbe/ixgbe_phy.c590
1 files changed, 576 insertions, 14 deletions
diff --git a/drivers/net/ixgbe/ixgbe_phy.c b/drivers/net/ixgbe/ixgbe_phy.c
index 77ec26f5650a..14e9606aa3b3 100644
--- a/drivers/net/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ixgbe/ixgbe_phy.c
@@ -32,6 +32,18 @@
32#include "ixgbe_common.h" 32#include "ixgbe_common.h"
33#include "ixgbe_phy.h" 33#include "ixgbe_phy.h"
34 34
35static void ixgbe_i2c_start(struct ixgbe_hw *hw);
36static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
37static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
38static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
39static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
40static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
41static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
42static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
43static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
45static bool ixgbe_get_i2c_data(u32 *i2cctl);
46static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
35static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr); 47static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
36static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id); 48static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
37static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw); 49static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
@@ -543,8 +555,9 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
543 u8 identifier = 0; 555 u8 identifier = 0;
544 u8 comp_codes_1g = 0; 556 u8 comp_codes_1g = 0;
545 u8 comp_codes_10g = 0; 557 u8 comp_codes_10g = 0;
546 u8 oui_bytes[4] = {0, 0, 0, 0}; 558 u8 oui_bytes[3] = {0, 0, 0};
547 u8 transmission_media = 0; 559 u8 transmission_media = 0;
560 u16 enforce_sfp = 0;
548 561
549 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER, 562 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
550 &identifier); 563 &identifier);
@@ -564,18 +577,48 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
564 577
565 /* ID Module 578 /* ID Module
566 * ========= 579 * =========
567 * 0 SFP_DA_CU 580 * 0 SFP_DA_CU
568 * 1 SFP_SR 581 * 1 SFP_SR
569 * 2 SFP_LR 582 * 2 SFP_LR
583 * 3 SFP_DA_CORE0 - 82599-specific
584 * 4 SFP_DA_CORE1 - 82599-specific
585 * 5 SFP_SR/LR_CORE0 - 82599-specific
586 * 6 SFP_SR/LR_CORE1 - 82599-specific
570 */ 587 */
571 if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE) 588 if (hw->mac.type == ixgbe_mac_82598EB) {
572 hw->phy.sfp_type = ixgbe_sfp_type_da_cu; 589 if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
573 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) 590 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
574 hw->phy.sfp_type = ixgbe_sfp_type_sr; 591 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
575 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) 592 hw->phy.sfp_type = ixgbe_sfp_type_sr;
576 hw->phy.sfp_type = ixgbe_sfp_type_lr; 593 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
577 else 594 hw->phy.sfp_type = ixgbe_sfp_type_lr;
578 hw->phy.sfp_type = ixgbe_sfp_type_unknown; 595 else
596 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
597 } else if (hw->mac.type == ixgbe_mac_82599EB) {
598 if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
599 if (hw->bus.lan_id == 0)
600 hw->phy.sfp_type =
601 ixgbe_sfp_type_da_cu_core0;
602 else
603 hw->phy.sfp_type =
604 ixgbe_sfp_type_da_cu_core1;
605 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
606 if (hw->bus.lan_id == 0)
607 hw->phy.sfp_type =
608 ixgbe_sfp_type_srlr_core0;
609 else
610 hw->phy.sfp_type =
611 ixgbe_sfp_type_srlr_core1;
612 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
613 if (hw->bus.lan_id == 0)
614 hw->phy.sfp_type =
615 ixgbe_sfp_type_srlr_core0;
616 else
617 hw->phy.sfp_type =
618 ixgbe_sfp_type_srlr_core1;
619 else
620 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
621 }
579 622
580 /* Determine PHY vendor */ 623 /* Determine PHY vendor */
581 if (hw->phy.type == ixgbe_phy_unknown) { 624 if (hw->phy.type == ixgbe_phy_unknown) {
@@ -607,6 +650,9 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
607 case IXGBE_SFF_VENDOR_OUI_AVAGO: 650 case IXGBE_SFF_VENDOR_OUI_AVAGO:
608 hw->phy.type = ixgbe_phy_sfp_avago; 651 hw->phy.type = ixgbe_phy_sfp_avago;
609 break; 652 break;
653 case IXGBE_SFF_VENDOR_OUI_INTEL:
654 hw->phy.type = ixgbe_phy_sfp_intel;
655 break;
610 default: 656 default:
611 if (transmission_media & 657 if (transmission_media &
612 IXGBE_SFF_TWIN_AX_CAPABLE) 658 IXGBE_SFF_TWIN_AX_CAPABLE)
@@ -616,7 +662,28 @@ s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
616 break; 662 break;
617 } 663 }
618 } 664 }
619 status = 0; 665 if (hw->mac.type == ixgbe_mac_82598EB ||
666 (hw->phy.sfp_type != ixgbe_sfp_type_sr &&
667 hw->phy.sfp_type != ixgbe_sfp_type_lr &&
668 hw->phy.sfp_type != ixgbe_sfp_type_srlr_core0 &&
669 hw->phy.sfp_type != ixgbe_sfp_type_srlr_core1)) {
670 status = 0;
671 goto out;
672 }
673
674 hw->eeprom.ops.read(hw, IXGBE_PHY_ENFORCE_INTEL_SFP_OFFSET,
675 &enforce_sfp);
676 if (!(enforce_sfp & IXGBE_PHY_ALLOW_ANY_SFP)) {
677 /* Make sure we're a supported PHY type */
678 if (hw->phy.type == ixgbe_phy_sfp_intel) {
679 status = 0;
680 } else {
681 hw_dbg(hw, "SFP+ module not supported\n");
682 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
683 }
684 } else {
685 status = 0;
686 }
620 } 687 }
621 688
622out: 689out:
@@ -651,7 +718,7 @@ s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
651 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset); 718 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
652 719
653 if ((!*list_offset) || (*list_offset == 0xFFFF)) 720 if ((!*list_offset) || (*list_offset == 0xFFFF))
654 return IXGBE_ERR_PHY; 721 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
655 722
656 /* Shift offset to first ID word */ 723 /* Shift offset to first ID word */
657 (*list_offset)++; 724 (*list_offset)++;
@@ -688,6 +755,501 @@ s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
688} 755}
689 756
690/** 757/**
758 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
759 * @hw: pointer to hardware structure
760 * @byte_offset: EEPROM byte offset to read
761 * @eeprom_data: value read
762 *
763 * Performs byte read operation to SFP module's EEPROM over I2C interface.
764 **/
765s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
766 u8 *eeprom_data)
767{
768 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
769 IXGBE_I2C_EEPROM_DEV_ADDR,
770 eeprom_data);
771}
772
773/**
774 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
775 * @hw: pointer to hardware structure
776 * @byte_offset: EEPROM byte offset to write
777 * @eeprom_data: value to write
778 *
779 * Performs byte write operation to SFP module's EEPROM over I2C interface.
780 **/
781s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
782 u8 eeprom_data)
783{
784 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
785 IXGBE_I2C_EEPROM_DEV_ADDR,
786 eeprom_data);
787}
788
789/**
790 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
791 * @hw: pointer to hardware structure
792 * @byte_offset: byte offset to read
793 * @data: value read
794 *
795 * Performs byte read operation to SFP module's EEPROM over I2C interface at
796 * a specified deivce address.
797 **/
798s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
799 u8 dev_addr, u8 *data)
800{
801 s32 status = 0;
802 u32 max_retry = 1;
803 u32 retry = 0;
804 bool nack = 1;
805
806 do {
807 ixgbe_i2c_start(hw);
808
809 /* Device Address and write indication */
810 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
811 if (status != 0)
812 goto fail;
813
814 status = ixgbe_get_i2c_ack(hw);
815 if (status != 0)
816 goto fail;
817
818 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
819 if (status != 0)
820 goto fail;
821
822 status = ixgbe_get_i2c_ack(hw);
823 if (status != 0)
824 goto fail;
825
826 ixgbe_i2c_start(hw);
827
828 /* Device Address and read indication */
829 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
830 if (status != 0)
831 goto fail;
832
833 status = ixgbe_get_i2c_ack(hw);
834 if (status != 0)
835 goto fail;
836
837 status = ixgbe_clock_in_i2c_byte(hw, data);
838 if (status != 0)
839 goto fail;
840
841 status = ixgbe_clock_out_i2c_bit(hw, nack);
842 if (status != 0)
843 goto fail;
844
845 ixgbe_i2c_stop(hw);
846 break;
847
848fail:
849 ixgbe_i2c_bus_clear(hw);
850 retry++;
851 if (retry < max_retry)
852 hw_dbg(hw, "I2C byte read error - Retrying.\n");
853 else
854 hw_dbg(hw, "I2C byte read error.\n");
855
856 } while (retry < max_retry);
857
858 return status;
859}
860
861/**
862 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
863 * @hw: pointer to hardware structure
864 * @byte_offset: byte offset to write
865 * @data: value to write
866 *
867 * Performs byte write operation to SFP module's EEPROM over I2C interface at
868 * a specified device address.
869 **/
870s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
871 u8 dev_addr, u8 data)
872{
873 s32 status = 0;
874 u32 max_retry = 1;
875 u32 retry = 0;
876
877 do {
878 ixgbe_i2c_start(hw);
879
880 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
881 if (status != 0)
882 goto fail;
883
884 status = ixgbe_get_i2c_ack(hw);
885 if (status != 0)
886 goto fail;
887
888 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
889 if (status != 0)
890 goto fail;
891
892 status = ixgbe_get_i2c_ack(hw);
893 if (status != 0)
894 goto fail;
895
896 status = ixgbe_clock_out_i2c_byte(hw, data);
897 if (status != 0)
898 goto fail;
899
900 status = ixgbe_get_i2c_ack(hw);
901 if (status != 0)
902 goto fail;
903
904 ixgbe_i2c_stop(hw);
905 break;
906
907fail:
908 ixgbe_i2c_bus_clear(hw);
909 retry++;
910 if (retry < max_retry)
911 hw_dbg(hw, "I2C byte write error - Retrying.\n");
912 else
913 hw_dbg(hw, "I2C byte write error.\n");
914 } while (retry < max_retry);
915
916 return status;
917}
918
919/**
920 * ixgbe_i2c_start - Sets I2C start condition
921 * @hw: pointer to hardware structure
922 *
923 * Sets I2C start condition (High -> Low on SDA while SCL is High)
924 **/
925static void ixgbe_i2c_start(struct ixgbe_hw *hw)
926{
927 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
928
929 /* Start condition must begin with data and clock high */
930 ixgbe_set_i2c_data(hw, &i2cctl, 1);
931 ixgbe_raise_i2c_clk(hw, &i2cctl);
932
933 /* Setup time for start condition (4.7us) */
934 udelay(IXGBE_I2C_T_SU_STA);
935
936 ixgbe_set_i2c_data(hw, &i2cctl, 0);
937
938 /* Hold time for start condition (4us) */
939 udelay(IXGBE_I2C_T_HD_STA);
940
941 ixgbe_lower_i2c_clk(hw, &i2cctl);
942
943 /* Minimum low period of clock is 4.7 us */
944 udelay(IXGBE_I2C_T_LOW);
945
946}
947
948/**
949 * ixgbe_i2c_stop - Sets I2C stop condition
950 * @hw: pointer to hardware structure
951 *
952 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
953 **/
954static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
955{
956 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
957
958 /* Stop condition must begin with data low and clock high */
959 ixgbe_set_i2c_data(hw, &i2cctl, 0);
960 ixgbe_raise_i2c_clk(hw, &i2cctl);
961
962 /* Setup time for stop condition (4us) */
963 udelay(IXGBE_I2C_T_SU_STO);
964
965 ixgbe_set_i2c_data(hw, &i2cctl, 1);
966
967 /* bus free time between stop and start (4.7us)*/
968 udelay(IXGBE_I2C_T_BUF);
969}
970
971/**
972 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
973 * @hw: pointer to hardware structure
974 * @data: data byte to clock in
975 *
976 * Clocks in one byte data via I2C data/clock
977 **/
978static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
979{
980 s32 status = 0;
981 s32 i;
982 bool bit = 0;
983
984 for (i = 7; i >= 0; i--) {
985 status = ixgbe_clock_in_i2c_bit(hw, &bit);
986 *data |= bit << i;
987
988 if (status != 0)
989 break;
990 }
991
992 return status;
993}
994
995/**
996 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
997 * @hw: pointer to hardware structure
998 * @data: data byte clocked out
999 *
1000 * Clocks out one byte data via I2C data/clock
1001 **/
1002static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1003{
1004 s32 status = 0;
1005 s32 i;
1006 u32 i2cctl;
1007 bool bit = 0;
1008
1009 for (i = 7; i >= 0; i--) {
1010 bit = (data >> i) & 0x1;
1011 status = ixgbe_clock_out_i2c_bit(hw, bit);
1012
1013 if (status != 0)
1014 break;
1015 }
1016
1017 /* Release SDA line (set high) */
1018 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1019 i2cctl |= IXGBE_I2C_DATA_OUT;
1020 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1021
1022 return status;
1023}
1024
1025/**
1026 * ixgbe_get_i2c_ack - Polls for I2C ACK
1027 * @hw: pointer to hardware structure
1028 *
1029 * Clocks in/out one bit via I2C data/clock
1030 **/
1031static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1032{
1033 s32 status;
1034 u32 i = 0;
1035 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1036 u32 timeout = 10;
1037 bool ack = 1;
1038
1039 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1040
1041 if (status != 0)
1042 goto out;
1043
1044 /* Minimum high period of clock is 4us */
1045 udelay(IXGBE_I2C_T_HIGH);
1046
1047 /* Poll for ACK. Note that ACK in I2C spec is
1048 * transition from 1 to 0 */
1049 for (i = 0; i < timeout; i++) {
1050 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1051 ack = ixgbe_get_i2c_data(&i2cctl);
1052
1053 udelay(1);
1054 if (ack == 0)
1055 break;
1056 }
1057
1058 if (ack == 1) {
1059 hw_dbg(hw, "I2C ack was not received.\n");
1060 status = IXGBE_ERR_I2C;
1061 }
1062
1063 ixgbe_lower_i2c_clk(hw, &i2cctl);
1064
1065 /* Minimum low period of clock is 4.7 us */
1066 udelay(IXGBE_I2C_T_LOW);
1067
1068out:
1069 return status;
1070}
1071
1072/**
1073 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1074 * @hw: pointer to hardware structure
1075 * @data: read data value
1076 *
1077 * Clocks in one bit via I2C data/clock
1078 **/
1079static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1080{
1081 s32 status;
1082 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1083
1084 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1085
1086 /* Minimum high period of clock is 4us */
1087 udelay(IXGBE_I2C_T_HIGH);
1088
1089 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1090 *data = ixgbe_get_i2c_data(&i2cctl);
1091
1092 ixgbe_lower_i2c_clk(hw, &i2cctl);
1093
1094 /* Minimum low period of clock is 4.7 us */
1095 udelay(IXGBE_I2C_T_LOW);
1096
1097 return status;
1098}
1099
1100/**
1101 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1102 * @hw: pointer to hardware structure
1103 * @data: data value to write
1104 *
1105 * Clocks out one bit via I2C data/clock
1106 **/
1107static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1108{
1109 s32 status;
1110 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1111
1112 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1113 if (status == 0) {
1114 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1115
1116 /* Minimum high period of clock is 4us */
1117 udelay(IXGBE_I2C_T_HIGH);
1118
1119 ixgbe_lower_i2c_clk(hw, &i2cctl);
1120
1121 /* Minimum low period of clock is 4.7 us.
1122 * This also takes care of the data hold time.
1123 */
1124 udelay(IXGBE_I2C_T_LOW);
1125 } else {
1126 status = IXGBE_ERR_I2C;
1127 hw_dbg(hw, "I2C data was not set to %X\n", data);
1128 }
1129
1130 return status;
1131}
1132/**
1133 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1134 * @hw: pointer to hardware structure
1135 * @i2cctl: Current value of I2CCTL register
1136 *
1137 * Raises the I2C clock line '0'->'1'
1138 **/
1139static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1140{
1141 s32 status = 0;
1142
1143 *i2cctl |= IXGBE_I2C_CLK_OUT;
1144
1145 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1146
1147 /* SCL rise time (1000ns) */
1148 udelay(IXGBE_I2C_T_RISE);
1149
1150 return status;
1151}
1152
1153/**
1154 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1155 * @hw: pointer to hardware structure
1156 * @i2cctl: Current value of I2CCTL register
1157 *
1158 * Lowers the I2C clock line '1'->'0'
1159 **/
1160static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1161{
1162
1163 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1164
1165 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1166
1167 /* SCL fall time (300ns) */
1168 udelay(IXGBE_I2C_T_FALL);
1169}
1170
1171/**
1172 * ixgbe_set_i2c_data - Sets the I2C data bit
1173 * @hw: pointer to hardware structure
1174 * @i2cctl: Current value of I2CCTL register
1175 * @data: I2C data value (0 or 1) to set
1176 *
1177 * Sets the I2C data bit
1178 **/
1179static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1180{
1181 s32 status = 0;
1182
1183 if (data)
1184 *i2cctl |= IXGBE_I2C_DATA_OUT;
1185 else
1186 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1187
1188 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1189
1190 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1191 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1192
1193 /* Verify data was set correctly */
1194 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1195 if (data != ixgbe_get_i2c_data(i2cctl)) {
1196 status = IXGBE_ERR_I2C;
1197 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1198 }
1199
1200 return status;
1201}
1202
1203/**
1204 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1205 * @hw: pointer to hardware structure
1206 * @i2cctl: Current value of I2CCTL register
1207 *
1208 * Returns the I2C data bit value
1209 **/
1210static bool ixgbe_get_i2c_data(u32 *i2cctl)
1211{
1212 bool data;
1213
1214 if (*i2cctl & IXGBE_I2C_DATA_IN)
1215 data = 1;
1216 else
1217 data = 0;
1218
1219 return data;
1220}
1221
1222/**
1223 * ixgbe_i2c_bus_clear - Clears the I2C bus
1224 * @hw: pointer to hardware structure
1225 *
1226 * Clears the I2C bus by sending nine clock pulses.
1227 * Used when data line is stuck low.
1228 **/
1229static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1230{
1231 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1232 u32 i;
1233
1234 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1235
1236 for (i = 0; i < 9; i++) {
1237 ixgbe_raise_i2c_clk(hw, &i2cctl);
1238
1239 /* Min high period of clock is 4us */
1240 udelay(IXGBE_I2C_T_HIGH);
1241
1242 ixgbe_lower_i2c_clk(hw, &i2cctl);
1243
1244 /* Min low period of clock is 4.7us*/
1245 udelay(IXGBE_I2C_T_LOW);
1246 }
1247
1248 /* Put the i2c bus back to default state */
1249 ixgbe_i2c_stop(hw);
1250}
1251
1252/**
691 * ixgbe_check_phy_link_tnx - Determine link and speed status 1253 * ixgbe_check_phy_link_tnx - Determine link and speed status
692 * @hw: pointer to hardware structure 1254 * @hw: pointer to hardware structure
693 * 1255 *