Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Shannon Nelson | 8c47eaa | 2010-01-13 01:49:34 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2010 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/sched.h> |
| 31 | |
| 32 | #include "ixgbe_common.h" |
| 33 | #include "ixgbe_phy.h" |
| 34 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 35 | static void ixgbe_i2c_start(struct ixgbe_hw *hw); |
| 36 | static void ixgbe_i2c_stop(struct ixgbe_hw *hw); |
| 37 | static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data); |
| 38 | static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data); |
| 39 | static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw); |
| 40 | static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data); |
| 41 | static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data); |
| 42 | static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl); |
| 43 | static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl); |
| 44 | static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data); |
| 45 | static bool ixgbe_get_i2c_data(u32 *i2cctl); |
| 46 | static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 47 | static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id); |
| 48 | static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 51 | * ixgbe_identify_phy_generic - Get physical layer module |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 52 | * @hw: pointer to hardware structure |
| 53 | * |
| 54 | * Determines the physical layer module found on the current adapter. |
| 55 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 56 | s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 57 | { |
| 58 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; |
| 59 | u32 phy_addr; |
| 60 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 61 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 62 | for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) { |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 63 | hw->phy.mdio.prtad = phy_addr; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 64 | if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 65 | ixgbe_get_phy_id(hw); |
| 66 | hw->phy.type = |
| 67 | ixgbe_get_phy_type_from_id(hw->phy.id); |
| 68 | status = 0; |
| 69 | break; |
| 70 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | } |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 72 | /* clear value if nothing found */ |
| 73 | hw->phy.mdio.prtad = 0; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 74 | } else { |
| 75 | status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 76 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 77 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 78 | return status; |
| 79 | } |
| 80 | |
| 81 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | * ixgbe_get_phy_id - Get the phy type |
| 83 | * @hw: pointer to hardware structure |
| 84 | * |
| 85 | **/ |
| 86 | static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw) |
| 87 | { |
| 88 | u32 status; |
| 89 | u16 phy_id_high = 0; |
| 90 | u16 phy_id_low = 0; |
| 91 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 92 | status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD, |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 93 | &phy_id_high); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 94 | |
| 95 | if (status == 0) { |
| 96 | hw->phy.id = (u32)(phy_id_high << 16); |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 97 | status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD, |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 98 | &phy_id_low); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 99 | hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK); |
| 100 | hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK); |
| 101 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 102 | return status; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * ixgbe_get_phy_type_from_id - Get the phy type |
| 107 | * @hw: pointer to hardware structure |
| 108 | * |
| 109 | **/ |
| 110 | static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id) |
| 111 | { |
| 112 | enum ixgbe_phy_type phy_type; |
| 113 | |
| 114 | switch (phy_id) { |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 115 | case TN1010_PHY_ID: |
| 116 | phy_type = ixgbe_phy_tn; |
| 117 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 118 | case QT2022_PHY_ID: |
| 119 | phy_type = ixgbe_phy_qt; |
| 120 | break; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 121 | case ATH_PHY_ID: |
| 122 | phy_type = ixgbe_phy_nl; |
| 123 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 124 | default: |
| 125 | phy_type = ixgbe_phy_unknown; |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | return phy_type; |
| 130 | } |
| 131 | |
| 132 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 133 | * ixgbe_reset_phy_generic - Performs a PHY reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 134 | * @hw: pointer to hardware structure |
| 135 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 136 | s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 137 | { |
| 138 | /* |
| 139 | * Perform soft PHY reset to the PHY_XS. |
| 140 | * This will cause a soft reset to the PHY |
| 141 | */ |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 142 | return hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, |
| 143 | MDIO_CTRL1_RESET); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 147 | * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 148 | * @hw: pointer to hardware structure |
| 149 | * @reg_addr: 32 bit address of PHY register to read |
| 150 | * @phy_data: Pointer to read data from PHY register |
| 151 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 152 | s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, |
| 153 | u32 device_type, u16 *phy_data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 154 | { |
| 155 | u32 command; |
| 156 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 157 | u32 data; |
| 158 | s32 status = 0; |
| 159 | u16 gssr; |
| 160 | |
| 161 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) |
| 162 | gssr = IXGBE_GSSR_PHY1_SM; |
| 163 | else |
| 164 | gssr = IXGBE_GSSR_PHY0_SM; |
| 165 | |
| 166 | if (ixgbe_acquire_swfw_sync(hw, gssr) != 0) |
| 167 | status = IXGBE_ERR_SWFW_SYNC; |
| 168 | |
| 169 | if (status == 0) { |
| 170 | /* Setup and write the address cycle command */ |
| 171 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 172 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 173 | (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 174 | (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 175 | |
| 176 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); |
| 177 | |
| 178 | /* |
| 179 | * Check every 10 usec to see if the address cycle completed. |
| 180 | * The MDI Command bit will clear when the operation is |
| 181 | * complete |
| 182 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 183 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 184 | udelay(10); |
| 185 | |
| 186 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); |
| 187 | |
| 188 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { |
| 193 | hw_dbg(hw, "PHY address command did not complete.\n"); |
| 194 | status = IXGBE_ERR_PHY; |
| 195 | } |
| 196 | |
| 197 | if (status == 0) { |
| 198 | /* |
| 199 | * Address cycle complete, setup and write the read |
| 200 | * command |
| 201 | */ |
| 202 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 203 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 204 | (hw->phy.mdio.prtad << |
| 205 | IXGBE_MSCA_PHY_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 206 | (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 207 | |
| 208 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); |
| 209 | |
| 210 | /* |
| 211 | * Check every 10 usec to see if the address cycle |
| 212 | * completed. The MDI Command bit will clear when the |
| 213 | * operation is complete |
| 214 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 215 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 216 | udelay(10); |
| 217 | |
| 218 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); |
| 219 | |
| 220 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 225 | hw_dbg(hw, "PHY read command didn't complete\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 226 | status = IXGBE_ERR_PHY; |
| 227 | } else { |
| 228 | /* |
| 229 | * Read operation is complete. Get the data |
| 230 | * from MSRWD |
| 231 | */ |
| 232 | data = IXGBE_READ_REG(hw, IXGBE_MSRWD); |
| 233 | data >>= IXGBE_MSRWD_READ_DATA_SHIFT; |
| 234 | *phy_data = (u16)(data); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | ixgbe_release_swfw_sync(hw, gssr); |
| 239 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 240 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 241 | return status; |
| 242 | } |
| 243 | |
| 244 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 245 | * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 246 | * @hw: pointer to hardware structure |
| 247 | * @reg_addr: 32 bit PHY register to write |
| 248 | * @device_type: 5 bit device type |
| 249 | * @phy_data: Data to write to the PHY register |
| 250 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 251 | s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr, |
| 252 | u32 device_type, u16 phy_data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 253 | { |
| 254 | u32 command; |
| 255 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 256 | s32 status = 0; |
| 257 | u16 gssr; |
| 258 | |
| 259 | if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1) |
| 260 | gssr = IXGBE_GSSR_PHY1_SM; |
| 261 | else |
| 262 | gssr = IXGBE_GSSR_PHY0_SM; |
| 263 | |
| 264 | if (ixgbe_acquire_swfw_sync(hw, gssr) != 0) |
| 265 | status = IXGBE_ERR_SWFW_SYNC; |
| 266 | |
| 267 | if (status == 0) { |
| 268 | /* Put the data in the MDI single read and write data register*/ |
| 269 | IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data); |
| 270 | |
| 271 | /* Setup and write the address cycle command */ |
| 272 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 273 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 274 | (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 275 | (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 276 | |
| 277 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); |
| 278 | |
| 279 | /* |
| 280 | * Check every 10 usec to see if the address cycle completed. |
| 281 | * The MDI Command bit will clear when the operation is |
| 282 | * complete |
| 283 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 284 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 285 | udelay(10); |
| 286 | |
| 287 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); |
| 288 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 289 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 290 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 293 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { |
| 294 | hw_dbg(hw, "PHY address cmd didn't complete\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 295 | status = IXGBE_ERR_PHY; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 296 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 297 | |
| 298 | if (status == 0) { |
| 299 | /* |
| 300 | * Address cycle complete, setup and write the write |
| 301 | * command |
| 302 | */ |
| 303 | command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 304 | (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 305 | (hw->phy.mdio.prtad << |
| 306 | IXGBE_MSCA_PHY_ADDR_SHIFT) | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 307 | (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 308 | |
| 309 | IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); |
| 310 | |
| 311 | /* |
| 312 | * Check every 10 usec to see if the address cycle |
| 313 | * completed. The MDI Command bit will clear when the |
| 314 | * operation is complete |
| 315 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 316 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 317 | udelay(10); |
| 318 | |
| 319 | command = IXGBE_READ_REG(hw, IXGBE_MSCA); |
| 320 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 321 | if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 322 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 325 | if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) { |
| 326 | hw_dbg(hw, "PHY address cmd didn't complete\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 327 | status = IXGBE_ERR_PHY; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 328 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | ixgbe_release_swfw_sync(hw, gssr); |
| 332 | } |
| 333 | |
| 334 | return status; |
| 335 | } |
| 336 | |
| 337 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 338 | * ixgbe_setup_phy_link_generic - Set and restart autoneg |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 339 | * @hw: pointer to hardware structure |
| 340 | * |
| 341 | * Restart autonegotiation and PHY and waits for completion. |
| 342 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 343 | s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 344 | { |
| 345 | s32 status = IXGBE_NOT_IMPLEMENTED; |
| 346 | u32 time_out; |
| 347 | u32 max_time_out = 10; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 348 | u16 autoneg_reg; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * Set advertisement settings in PHY based on autoneg_advertised |
| 352 | * settings. If autoneg_advertised = 0, then advertise default values |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 353 | * tnx devices cannot be "forced" to a autoneg 10G and fail. But can |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 354 | * for a 1G. |
| 355 | */ |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 356 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 357 | |
| 358 | if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL) |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 359 | autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 360 | else |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 361 | autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 362 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 363 | hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 364 | |
| 365 | /* Restart PHY autonegotiation and wait for completion */ |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 366 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 367 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 368 | autoneg_reg |= MDIO_AN_CTRL1_RESTART; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 369 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 370 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 371 | |
| 372 | /* Wait for autonegotiation to finish */ |
| 373 | for (time_out = 0; time_out < max_time_out; time_out++) { |
| 374 | udelay(10); |
| 375 | /* Restart PHY autonegotiation and wait for completion */ |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 376 | status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN, |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 377 | &autoneg_reg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 378 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 379 | autoneg_reg &= MDIO_AN_STAT1_COMPLETE; |
| 380 | if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 381 | status = 0; |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | if (time_out == max_time_out) |
| 387 | status = IXGBE_ERR_LINK_SETUP; |
| 388 | |
| 389 | return status; |
| 390 | } |
| 391 | |
| 392 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 393 | * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 394 | * @hw: pointer to hardware structure |
| 395 | * @speed: new link speed |
| 396 | * @autoneg: true if autonegotiation enabled |
| 397 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 398 | s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw, |
| 399 | ixgbe_link_speed speed, |
| 400 | bool autoneg, |
| 401 | bool autoneg_wait_to_complete) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 402 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 403 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 404 | /* |
| 405 | * Clear autoneg_advertised and set new values based on input link |
| 406 | * speed. |
| 407 | */ |
| 408 | hw->phy.autoneg_advertised = 0; |
| 409 | |
| 410 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 411 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 412 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 413 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) |
| 414 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; |
| 415 | |
| 416 | /* Setup link based on the new speed settings */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 417 | hw->phy.ops.setup_link(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 418 | |
| 419 | return 0; |
| 420 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 421 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 422 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 423 | * ixgbe_reset_phy_nl - Performs a PHY reset |
| 424 | * @hw: pointer to hardware structure |
| 425 | **/ |
| 426 | s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw) |
| 427 | { |
| 428 | u16 phy_offset, control, eword, edata, block_crc; |
| 429 | bool end_data = false; |
| 430 | u16 list_offset, data_offset; |
| 431 | u16 phy_data = 0; |
| 432 | s32 ret_val = 0; |
| 433 | u32 i; |
| 434 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 435 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 436 | |
| 437 | /* reset the PHY and poll for completion */ |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 438 | hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, |
| 439 | (phy_data | MDIO_CTRL1_RESET)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 440 | |
| 441 | for (i = 0; i < 100; i++) { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 442 | hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, |
| 443 | &phy_data); |
| 444 | if ((phy_data & MDIO_CTRL1_RESET) == 0) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 445 | break; |
| 446 | msleep(10); |
| 447 | } |
| 448 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 449 | if ((phy_data & MDIO_CTRL1_RESET) != 0) { |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 450 | hw_dbg(hw, "PHY reset did not complete.\n"); |
| 451 | ret_val = IXGBE_ERR_PHY; |
| 452 | goto out; |
| 453 | } |
| 454 | |
| 455 | /* Get init offsets */ |
| 456 | ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset, |
| 457 | &data_offset); |
| 458 | if (ret_val != 0) |
| 459 | goto out; |
| 460 | |
| 461 | ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc); |
| 462 | data_offset++; |
| 463 | while (!end_data) { |
| 464 | /* |
| 465 | * Read control word from PHY init contents offset |
| 466 | */ |
| 467 | ret_val = hw->eeprom.ops.read(hw, data_offset, &eword); |
| 468 | control = (eword & IXGBE_CONTROL_MASK_NL) >> |
| 469 | IXGBE_CONTROL_SHIFT_NL; |
| 470 | edata = eword & IXGBE_DATA_MASK_NL; |
| 471 | switch (control) { |
| 472 | case IXGBE_DELAY_NL: |
| 473 | data_offset++; |
| 474 | hw_dbg(hw, "DELAY: %d MS\n", edata); |
| 475 | msleep(edata); |
| 476 | break; |
| 477 | case IXGBE_DATA_NL: |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 478 | hw_dbg(hw, "DATA:\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 479 | data_offset++; |
| 480 | hw->eeprom.ops.read(hw, data_offset++, |
| 481 | &phy_offset); |
| 482 | for (i = 0; i < edata; i++) { |
| 483 | hw->eeprom.ops.read(hw, data_offset, &eword); |
| 484 | hw->phy.ops.write_reg(hw, phy_offset, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 485 | MDIO_MMD_PMAPMD, eword); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 486 | hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword, |
| 487 | phy_offset); |
| 488 | data_offset++; |
| 489 | phy_offset++; |
| 490 | } |
| 491 | break; |
| 492 | case IXGBE_CONTROL_NL: |
| 493 | data_offset++; |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 494 | hw_dbg(hw, "CONTROL:\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 495 | if (edata == IXGBE_CONTROL_EOL_NL) { |
| 496 | hw_dbg(hw, "EOL\n"); |
| 497 | end_data = true; |
| 498 | } else if (edata == IXGBE_CONTROL_SOL_NL) { |
| 499 | hw_dbg(hw, "SOL\n"); |
| 500 | } else { |
| 501 | hw_dbg(hw, "Bad control value\n"); |
| 502 | ret_val = IXGBE_ERR_PHY; |
| 503 | goto out; |
| 504 | } |
| 505 | break; |
| 506 | default: |
| 507 | hw_dbg(hw, "Bad control type\n"); |
| 508 | ret_val = IXGBE_ERR_PHY; |
| 509 | goto out; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | out: |
| 514 | return ret_val; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns |
| 519 | * the PHY type. |
| 520 | * @hw: pointer to hardware structure |
| 521 | * |
| 522 | * Searches for and indentifies the SFP module. Assings appropriate PHY type. |
| 523 | **/ |
| 524 | s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw) |
| 525 | { |
| 526 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; |
| 527 | u32 vendor_oui = 0; |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 528 | enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 529 | u8 identifier = 0; |
| 530 | u8 comp_codes_1g = 0; |
| 531 | u8 comp_codes_10g = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 532 | u8 oui_bytes[3] = {0, 0, 0}; |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 533 | u8 cable_tech = 0; |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 534 | u8 cable_spec = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 535 | u16 enforce_sfp = 0; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 536 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 537 | if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) { |
| 538 | hw->phy.sfp_type = ixgbe_sfp_type_not_present; |
| 539 | status = IXGBE_ERR_SFP_NOT_PRESENT; |
| 540 | goto out; |
| 541 | } |
| 542 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 543 | status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER, |
| 544 | &identifier); |
| 545 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 546 | if (status == IXGBE_ERR_SFP_NOT_PRESENT || status == IXGBE_ERR_I2C) { |
| 547 | status = IXGBE_ERR_SFP_NOT_PRESENT; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 548 | hw->phy.sfp_type = ixgbe_sfp_type_not_present; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 549 | if (hw->phy.type != ixgbe_phy_nl) { |
| 550 | hw->phy.id = 0; |
| 551 | hw->phy.type = ixgbe_phy_unknown; |
| 552 | } |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 553 | goto out; |
| 554 | } |
| 555 | |
| 556 | if (identifier == IXGBE_SFF_IDENTIFIER_SFP) { |
| 557 | hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES, |
| 558 | &comp_codes_1g); |
| 559 | hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES, |
| 560 | &comp_codes_10g); |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 561 | hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_CABLE_TECHNOLOGY, |
| 562 | &cable_tech); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 563 | |
| 564 | /* ID Module |
| 565 | * ========= |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 566 | * 0 SFP_DA_CU |
| 567 | * 1 SFP_SR |
| 568 | * 2 SFP_LR |
| 569 | * 3 SFP_DA_CORE0 - 82599-specific |
| 570 | * 4 SFP_DA_CORE1 - 82599-specific |
| 571 | * 5 SFP_SR/LR_CORE0 - 82599-specific |
| 572 | * 6 SFP_SR/LR_CORE1 - 82599-specific |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 573 | */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 574 | if (hw->mac.type == ixgbe_mac_82598EB) { |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 575 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 576 | hw->phy.sfp_type = ixgbe_sfp_type_da_cu; |
| 577 | else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) |
| 578 | hw->phy.sfp_type = ixgbe_sfp_type_sr; |
| 579 | else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) |
| 580 | hw->phy.sfp_type = ixgbe_sfp_type_lr; |
| 581 | else |
| 582 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
| 583 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 584 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 585 | if (hw->bus.lan_id == 0) |
| 586 | hw->phy.sfp_type = |
| 587 | ixgbe_sfp_type_da_cu_core0; |
| 588 | else |
| 589 | hw->phy.sfp_type = |
| 590 | ixgbe_sfp_type_da_cu_core1; |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 591 | } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) { |
| 592 | hw->phy.ops.read_i2c_eeprom( |
| 593 | hw, IXGBE_SFF_CABLE_SPEC_COMP, |
| 594 | &cable_spec); |
| 595 | if (cable_spec & |
| 596 | IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) { |
| 597 | if (hw->bus.lan_id == 0) |
| 598 | hw->phy.sfp_type = |
| 599 | ixgbe_sfp_type_da_act_lmt_core0; |
| 600 | else |
| 601 | hw->phy.sfp_type = |
| 602 | ixgbe_sfp_type_da_act_lmt_core1; |
| 603 | } else { |
| 604 | hw->phy.sfp_type = |
| 605 | ixgbe_sfp_type_unknown; |
| 606 | } |
| 607 | } else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 608 | if (hw->bus.lan_id == 0) |
| 609 | hw->phy.sfp_type = |
| 610 | ixgbe_sfp_type_srlr_core0; |
| 611 | else |
| 612 | hw->phy.sfp_type = |
| 613 | ixgbe_sfp_type_srlr_core1; |
| 614 | else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) |
| 615 | if (hw->bus.lan_id == 0) |
| 616 | hw->phy.sfp_type = |
| 617 | ixgbe_sfp_type_srlr_core0; |
| 618 | else |
| 619 | hw->phy.sfp_type = |
| 620 | ixgbe_sfp_type_srlr_core1; |
| 621 | else |
| 622 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
| 623 | } |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 624 | |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 625 | if (hw->phy.sfp_type != stored_sfp_type) |
| 626 | hw->phy.sfp_setup_needed = true; |
| 627 | |
| 628 | /* Determine if the SFP+ PHY is dual speed or not. */ |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 629 | hw->phy.multispeed_fiber = false; |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 630 | if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) && |
| 631 | (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) || |
| 632 | ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) && |
| 633 | (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE))) |
| 634 | hw->phy.multispeed_fiber = true; |
| 635 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 636 | /* Determine PHY vendor */ |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 637 | if (hw->phy.type != ixgbe_phy_nl) { |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 638 | hw->phy.id = identifier; |
| 639 | hw->phy.ops.read_i2c_eeprom(hw, |
| 640 | IXGBE_SFF_VENDOR_OUI_BYTE0, |
| 641 | &oui_bytes[0]); |
| 642 | hw->phy.ops.read_i2c_eeprom(hw, |
| 643 | IXGBE_SFF_VENDOR_OUI_BYTE1, |
| 644 | &oui_bytes[1]); |
| 645 | hw->phy.ops.read_i2c_eeprom(hw, |
| 646 | IXGBE_SFF_VENDOR_OUI_BYTE2, |
| 647 | &oui_bytes[2]); |
| 648 | |
| 649 | vendor_oui = |
| 650 | ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) | |
| 651 | (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) | |
| 652 | (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT)); |
| 653 | |
| 654 | switch (vendor_oui) { |
| 655 | case IXGBE_SFF_VENDOR_OUI_TYCO: |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 656 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 657 | hw->phy.type = |
| 658 | ixgbe_phy_sfp_passive_tyco; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 659 | break; |
| 660 | case IXGBE_SFF_VENDOR_OUI_FTL: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 661 | if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) |
| 662 | hw->phy.type = ixgbe_phy_sfp_ftl_active; |
| 663 | else |
| 664 | hw->phy.type = ixgbe_phy_sfp_ftl; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 665 | break; |
| 666 | case IXGBE_SFF_VENDOR_OUI_AVAGO: |
| 667 | hw->phy.type = ixgbe_phy_sfp_avago; |
| 668 | break; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 669 | case IXGBE_SFF_VENDOR_OUI_INTEL: |
| 670 | hw->phy.type = ixgbe_phy_sfp_intel; |
| 671 | break; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 672 | default: |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 673 | if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 674 | hw->phy.type = |
| 675 | ixgbe_phy_sfp_passive_unknown; |
| 676 | else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) |
| 677 | hw->phy.type = |
| 678 | ixgbe_phy_sfp_active_unknown; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 679 | else |
| 680 | hw->phy.type = ixgbe_phy_sfp_unknown; |
| 681 | break; |
| 682 | } |
| 683 | } |
Waskiewicz Jr, Peter P | fa466e9 | 2009-04-23 11:31:37 +0000 | [diff] [blame] | 684 | |
Peter P Waskiewicz Jr | 537d58a | 2009-05-19 09:18:51 +0000 | [diff] [blame] | 685 | /* All passive DA cables are supported */ |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame^] | 686 | if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE | |
| 687 | IXGBE_SFF_DA_ACTIVE_CABLE)) { |
Waskiewicz Jr, Peter P | fa466e9 | 2009-04-23 11:31:37 +0000 | [diff] [blame] | 688 | status = 0; |
| 689 | goto out; |
| 690 | } |
| 691 | |
| 692 | /* 1G SFP modules are not supported */ |
| 693 | if (comp_codes_10g == 0) { |
| 694 | hw->phy.type = ixgbe_phy_sfp_unsupported; |
| 695 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 696 | goto out; |
| 697 | } |
| 698 | |
| 699 | /* Anything else 82598-based is supported */ |
| 700 | if (hw->mac.type == ixgbe_mac_82598EB) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 701 | status = 0; |
| 702 | goto out; |
| 703 | } |
| 704 | |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 705 | /* This is guaranteed to be 82599, no need to check for NULL */ |
| 706 | hw->mac.ops.get_device_caps(hw, &enforce_sfp); |
| 707 | if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 708 | /* Make sure we're a supported PHY type */ |
| 709 | if (hw->phy.type == ixgbe_phy_sfp_intel) { |
| 710 | status = 0; |
| 711 | } else { |
| 712 | hw_dbg(hw, "SFP+ module not supported\n"); |
Waskiewicz Jr, Peter P | fa466e9 | 2009-04-23 11:31:37 +0000 | [diff] [blame] | 713 | hw->phy.type = ixgbe_phy_sfp_unsupported; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 714 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 715 | } |
| 716 | } else { |
| 717 | status = 0; |
| 718 | } |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | out: |
| 722 | return status; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see |
| 727 | * if it supports a given SFP+ module type, if so it returns the offsets to the |
| 728 | * phy init sequence block. |
| 729 | * @hw: pointer to hardware structure |
| 730 | * @list_offset: offset to the SFP ID list |
| 731 | * @data_offset: offset to the SFP data block |
| 732 | **/ |
| 733 | s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw, |
| 734 | u16 *list_offset, |
| 735 | u16 *data_offset) |
| 736 | { |
| 737 | u16 sfp_id; |
| 738 | |
| 739 | if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) |
| 740 | return IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 741 | |
| 742 | if (hw->phy.sfp_type == ixgbe_sfp_type_not_present) |
| 743 | return IXGBE_ERR_SFP_NOT_PRESENT; |
| 744 | |
| 745 | if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) && |
| 746 | (hw->phy.sfp_type == ixgbe_sfp_type_da_cu)) |
| 747 | return IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 748 | |
| 749 | /* Read offset to PHY init contents */ |
| 750 | hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset); |
| 751 | |
| 752 | if ((!*list_offset) || (*list_offset == 0xFFFF)) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 753 | return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 754 | |
| 755 | /* Shift offset to first ID word */ |
| 756 | (*list_offset)++; |
| 757 | |
| 758 | /* |
| 759 | * Find the matching SFP ID in the EEPROM |
| 760 | * and program the init sequence |
| 761 | */ |
| 762 | hw->eeprom.ops.read(hw, *list_offset, &sfp_id); |
| 763 | |
| 764 | while (sfp_id != IXGBE_PHY_INIT_END_NL) { |
| 765 | if (sfp_id == hw->phy.sfp_type) { |
| 766 | (*list_offset)++; |
| 767 | hw->eeprom.ops.read(hw, *list_offset, data_offset); |
| 768 | if ((!*data_offset) || (*data_offset == 0xFFFF)) { |
| 769 | hw_dbg(hw, "SFP+ module not supported\n"); |
| 770 | return IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 771 | } else { |
| 772 | break; |
| 773 | } |
| 774 | } else { |
| 775 | (*list_offset) += 2; |
| 776 | if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id)) |
| 777 | return IXGBE_ERR_PHY; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | if (sfp_id == IXGBE_PHY_INIT_END_NL) { |
| 782 | hw_dbg(hw, "No matching SFP+ module found\n"); |
| 783 | return IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 784 | } |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 790 | * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface |
| 791 | * @hw: pointer to hardware structure |
| 792 | * @byte_offset: EEPROM byte offset to read |
| 793 | * @eeprom_data: value read |
| 794 | * |
| 795 | * Performs byte read operation to SFP module's EEPROM over I2C interface. |
| 796 | **/ |
| 797 | s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, |
| 798 | u8 *eeprom_data) |
| 799 | { |
| 800 | return hw->phy.ops.read_i2c_byte(hw, byte_offset, |
| 801 | IXGBE_I2C_EEPROM_DEV_ADDR, |
| 802 | eeprom_data); |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface |
| 807 | * @hw: pointer to hardware structure |
| 808 | * @byte_offset: EEPROM byte offset to write |
| 809 | * @eeprom_data: value to write |
| 810 | * |
| 811 | * Performs byte write operation to SFP module's EEPROM over I2C interface. |
| 812 | **/ |
| 813 | s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset, |
| 814 | u8 eeprom_data) |
| 815 | { |
| 816 | return hw->phy.ops.write_i2c_byte(hw, byte_offset, |
| 817 | IXGBE_I2C_EEPROM_DEV_ADDR, |
| 818 | eeprom_data); |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C |
| 823 | * @hw: pointer to hardware structure |
| 824 | * @byte_offset: byte offset to read |
| 825 | * @data: value read |
| 826 | * |
| 827 | * Performs byte read operation to SFP module's EEPROM over I2C interface at |
| 828 | * a specified deivce address. |
| 829 | **/ |
| 830 | s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, |
| 831 | u8 dev_addr, u8 *data) |
| 832 | { |
| 833 | s32 status = 0; |
| 834 | u32 max_retry = 1; |
| 835 | u32 retry = 0; |
| 836 | bool nack = 1; |
| 837 | |
| 838 | do { |
| 839 | ixgbe_i2c_start(hw); |
| 840 | |
| 841 | /* Device Address and write indication */ |
| 842 | status = ixgbe_clock_out_i2c_byte(hw, dev_addr); |
| 843 | if (status != 0) |
| 844 | goto fail; |
| 845 | |
| 846 | status = ixgbe_get_i2c_ack(hw); |
| 847 | if (status != 0) |
| 848 | goto fail; |
| 849 | |
| 850 | status = ixgbe_clock_out_i2c_byte(hw, byte_offset); |
| 851 | if (status != 0) |
| 852 | goto fail; |
| 853 | |
| 854 | status = ixgbe_get_i2c_ack(hw); |
| 855 | if (status != 0) |
| 856 | goto fail; |
| 857 | |
| 858 | ixgbe_i2c_start(hw); |
| 859 | |
| 860 | /* Device Address and read indication */ |
| 861 | status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1)); |
| 862 | if (status != 0) |
| 863 | goto fail; |
| 864 | |
| 865 | status = ixgbe_get_i2c_ack(hw); |
| 866 | if (status != 0) |
| 867 | goto fail; |
| 868 | |
| 869 | status = ixgbe_clock_in_i2c_byte(hw, data); |
| 870 | if (status != 0) |
| 871 | goto fail; |
| 872 | |
| 873 | status = ixgbe_clock_out_i2c_bit(hw, nack); |
| 874 | if (status != 0) |
| 875 | goto fail; |
| 876 | |
| 877 | ixgbe_i2c_stop(hw); |
| 878 | break; |
| 879 | |
| 880 | fail: |
| 881 | ixgbe_i2c_bus_clear(hw); |
| 882 | retry++; |
| 883 | if (retry < max_retry) |
| 884 | hw_dbg(hw, "I2C byte read error - Retrying.\n"); |
| 885 | else |
| 886 | hw_dbg(hw, "I2C byte read error.\n"); |
| 887 | |
| 888 | } while (retry < max_retry); |
| 889 | |
| 890 | return status; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C |
| 895 | * @hw: pointer to hardware structure |
| 896 | * @byte_offset: byte offset to write |
| 897 | * @data: value to write |
| 898 | * |
| 899 | * Performs byte write operation to SFP module's EEPROM over I2C interface at |
| 900 | * a specified device address. |
| 901 | **/ |
| 902 | s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset, |
| 903 | u8 dev_addr, u8 data) |
| 904 | { |
| 905 | s32 status = 0; |
| 906 | u32 max_retry = 1; |
| 907 | u32 retry = 0; |
| 908 | |
| 909 | do { |
| 910 | ixgbe_i2c_start(hw); |
| 911 | |
| 912 | status = ixgbe_clock_out_i2c_byte(hw, dev_addr); |
| 913 | if (status != 0) |
| 914 | goto fail; |
| 915 | |
| 916 | status = ixgbe_get_i2c_ack(hw); |
| 917 | if (status != 0) |
| 918 | goto fail; |
| 919 | |
| 920 | status = ixgbe_clock_out_i2c_byte(hw, byte_offset); |
| 921 | if (status != 0) |
| 922 | goto fail; |
| 923 | |
| 924 | status = ixgbe_get_i2c_ack(hw); |
| 925 | if (status != 0) |
| 926 | goto fail; |
| 927 | |
| 928 | status = ixgbe_clock_out_i2c_byte(hw, data); |
| 929 | if (status != 0) |
| 930 | goto fail; |
| 931 | |
| 932 | status = ixgbe_get_i2c_ack(hw); |
| 933 | if (status != 0) |
| 934 | goto fail; |
| 935 | |
| 936 | ixgbe_i2c_stop(hw); |
| 937 | break; |
| 938 | |
| 939 | fail: |
| 940 | ixgbe_i2c_bus_clear(hw); |
| 941 | retry++; |
| 942 | if (retry < max_retry) |
| 943 | hw_dbg(hw, "I2C byte write error - Retrying.\n"); |
| 944 | else |
| 945 | hw_dbg(hw, "I2C byte write error.\n"); |
| 946 | } while (retry < max_retry); |
| 947 | |
| 948 | return status; |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * ixgbe_i2c_start - Sets I2C start condition |
| 953 | * @hw: pointer to hardware structure |
| 954 | * |
| 955 | * Sets I2C start condition (High -> Low on SDA while SCL is High) |
| 956 | **/ |
| 957 | static void ixgbe_i2c_start(struct ixgbe_hw *hw) |
| 958 | { |
| 959 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 960 | |
| 961 | /* Start condition must begin with data and clock high */ |
| 962 | ixgbe_set_i2c_data(hw, &i2cctl, 1); |
| 963 | ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 964 | |
| 965 | /* Setup time for start condition (4.7us) */ |
| 966 | udelay(IXGBE_I2C_T_SU_STA); |
| 967 | |
| 968 | ixgbe_set_i2c_data(hw, &i2cctl, 0); |
| 969 | |
| 970 | /* Hold time for start condition (4us) */ |
| 971 | udelay(IXGBE_I2C_T_HD_STA); |
| 972 | |
| 973 | ixgbe_lower_i2c_clk(hw, &i2cctl); |
| 974 | |
| 975 | /* Minimum low period of clock is 4.7 us */ |
| 976 | udelay(IXGBE_I2C_T_LOW); |
| 977 | |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * ixgbe_i2c_stop - Sets I2C stop condition |
| 982 | * @hw: pointer to hardware structure |
| 983 | * |
| 984 | * Sets I2C stop condition (Low -> High on SDA while SCL is High) |
| 985 | **/ |
| 986 | static void ixgbe_i2c_stop(struct ixgbe_hw *hw) |
| 987 | { |
| 988 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 989 | |
| 990 | /* Stop condition must begin with data low and clock high */ |
| 991 | ixgbe_set_i2c_data(hw, &i2cctl, 0); |
| 992 | ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 993 | |
| 994 | /* Setup time for stop condition (4us) */ |
| 995 | udelay(IXGBE_I2C_T_SU_STO); |
| 996 | |
| 997 | ixgbe_set_i2c_data(hw, &i2cctl, 1); |
| 998 | |
| 999 | /* bus free time between stop and start (4.7us)*/ |
| 1000 | udelay(IXGBE_I2C_T_BUF); |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C |
| 1005 | * @hw: pointer to hardware structure |
| 1006 | * @data: data byte to clock in |
| 1007 | * |
| 1008 | * Clocks in one byte data via I2C data/clock |
| 1009 | **/ |
| 1010 | static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data) |
| 1011 | { |
| 1012 | s32 status = 0; |
| 1013 | s32 i; |
| 1014 | bool bit = 0; |
| 1015 | |
| 1016 | for (i = 7; i >= 0; i--) { |
| 1017 | status = ixgbe_clock_in_i2c_bit(hw, &bit); |
| 1018 | *data |= bit << i; |
| 1019 | |
| 1020 | if (status != 0) |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | return status; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C |
| 1029 | * @hw: pointer to hardware structure |
| 1030 | * @data: data byte clocked out |
| 1031 | * |
| 1032 | * Clocks out one byte data via I2C data/clock |
| 1033 | **/ |
| 1034 | static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data) |
| 1035 | { |
| 1036 | s32 status = 0; |
| 1037 | s32 i; |
| 1038 | u32 i2cctl; |
| 1039 | bool bit = 0; |
| 1040 | |
| 1041 | for (i = 7; i >= 0; i--) { |
| 1042 | bit = (data >> i) & 0x1; |
| 1043 | status = ixgbe_clock_out_i2c_bit(hw, bit); |
| 1044 | |
| 1045 | if (status != 0) |
| 1046 | break; |
| 1047 | } |
| 1048 | |
| 1049 | /* Release SDA line (set high) */ |
| 1050 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1051 | i2cctl |= IXGBE_I2C_DATA_OUT; |
| 1052 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl); |
| 1053 | |
| 1054 | return status; |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * ixgbe_get_i2c_ack - Polls for I2C ACK |
| 1059 | * @hw: pointer to hardware structure |
| 1060 | * |
| 1061 | * Clocks in/out one bit via I2C data/clock |
| 1062 | **/ |
| 1063 | static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw) |
| 1064 | { |
| 1065 | s32 status; |
| 1066 | u32 i = 0; |
| 1067 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1068 | u32 timeout = 10; |
| 1069 | bool ack = 1; |
| 1070 | |
| 1071 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 1072 | |
| 1073 | if (status != 0) |
| 1074 | goto out; |
| 1075 | |
| 1076 | /* Minimum high period of clock is 4us */ |
| 1077 | udelay(IXGBE_I2C_T_HIGH); |
| 1078 | |
| 1079 | /* Poll for ACK. Note that ACK in I2C spec is |
| 1080 | * transition from 1 to 0 */ |
| 1081 | for (i = 0; i < timeout; i++) { |
| 1082 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1083 | ack = ixgbe_get_i2c_data(&i2cctl); |
| 1084 | |
| 1085 | udelay(1); |
| 1086 | if (ack == 0) |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | if (ack == 1) { |
| 1091 | hw_dbg(hw, "I2C ack was not received.\n"); |
| 1092 | status = IXGBE_ERR_I2C; |
| 1093 | } |
| 1094 | |
| 1095 | ixgbe_lower_i2c_clk(hw, &i2cctl); |
| 1096 | |
| 1097 | /* Minimum low period of clock is 4.7 us */ |
| 1098 | udelay(IXGBE_I2C_T_LOW); |
| 1099 | |
| 1100 | out: |
| 1101 | return status; |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock |
| 1106 | * @hw: pointer to hardware structure |
| 1107 | * @data: read data value |
| 1108 | * |
| 1109 | * Clocks in one bit via I2C data/clock |
| 1110 | **/ |
| 1111 | static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data) |
| 1112 | { |
| 1113 | s32 status; |
| 1114 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1115 | |
| 1116 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 1117 | |
| 1118 | /* Minimum high period of clock is 4us */ |
| 1119 | udelay(IXGBE_I2C_T_HIGH); |
| 1120 | |
| 1121 | i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1122 | *data = ixgbe_get_i2c_data(&i2cctl); |
| 1123 | |
| 1124 | ixgbe_lower_i2c_clk(hw, &i2cctl); |
| 1125 | |
| 1126 | /* Minimum low period of clock is 4.7 us */ |
| 1127 | udelay(IXGBE_I2C_T_LOW); |
| 1128 | |
| 1129 | return status; |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock |
| 1134 | * @hw: pointer to hardware structure |
| 1135 | * @data: data value to write |
| 1136 | * |
| 1137 | * Clocks out one bit via I2C data/clock |
| 1138 | **/ |
| 1139 | static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data) |
| 1140 | { |
| 1141 | s32 status; |
| 1142 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1143 | |
| 1144 | status = ixgbe_set_i2c_data(hw, &i2cctl, data); |
| 1145 | if (status == 0) { |
| 1146 | status = ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 1147 | |
| 1148 | /* Minimum high period of clock is 4us */ |
| 1149 | udelay(IXGBE_I2C_T_HIGH); |
| 1150 | |
| 1151 | ixgbe_lower_i2c_clk(hw, &i2cctl); |
| 1152 | |
| 1153 | /* Minimum low period of clock is 4.7 us. |
| 1154 | * This also takes care of the data hold time. |
| 1155 | */ |
| 1156 | udelay(IXGBE_I2C_T_LOW); |
| 1157 | } else { |
| 1158 | status = IXGBE_ERR_I2C; |
| 1159 | hw_dbg(hw, "I2C data was not set to %X\n", data); |
| 1160 | } |
| 1161 | |
| 1162 | return status; |
| 1163 | } |
| 1164 | /** |
| 1165 | * ixgbe_raise_i2c_clk - Raises the I2C SCL clock |
| 1166 | * @hw: pointer to hardware structure |
| 1167 | * @i2cctl: Current value of I2CCTL register |
| 1168 | * |
| 1169 | * Raises the I2C clock line '0'->'1' |
| 1170 | **/ |
| 1171 | static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl) |
| 1172 | { |
| 1173 | s32 status = 0; |
| 1174 | |
| 1175 | *i2cctl |= IXGBE_I2C_CLK_OUT; |
| 1176 | |
| 1177 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); |
| 1178 | |
| 1179 | /* SCL rise time (1000ns) */ |
| 1180 | udelay(IXGBE_I2C_T_RISE); |
| 1181 | |
| 1182 | return status; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock |
| 1187 | * @hw: pointer to hardware structure |
| 1188 | * @i2cctl: Current value of I2CCTL register |
| 1189 | * |
| 1190 | * Lowers the I2C clock line '1'->'0' |
| 1191 | **/ |
| 1192 | static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl) |
| 1193 | { |
| 1194 | |
| 1195 | *i2cctl &= ~IXGBE_I2C_CLK_OUT; |
| 1196 | |
| 1197 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); |
| 1198 | |
| 1199 | /* SCL fall time (300ns) */ |
| 1200 | udelay(IXGBE_I2C_T_FALL); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * ixgbe_set_i2c_data - Sets the I2C data bit |
| 1205 | * @hw: pointer to hardware structure |
| 1206 | * @i2cctl: Current value of I2CCTL register |
| 1207 | * @data: I2C data value (0 or 1) to set |
| 1208 | * |
| 1209 | * Sets the I2C data bit |
| 1210 | **/ |
| 1211 | static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data) |
| 1212 | { |
| 1213 | s32 status = 0; |
| 1214 | |
| 1215 | if (data) |
| 1216 | *i2cctl |= IXGBE_I2C_DATA_OUT; |
| 1217 | else |
| 1218 | *i2cctl &= ~IXGBE_I2C_DATA_OUT; |
| 1219 | |
| 1220 | IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl); |
| 1221 | |
| 1222 | /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */ |
| 1223 | udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA); |
| 1224 | |
| 1225 | /* Verify data was set correctly */ |
| 1226 | *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1227 | if (data != ixgbe_get_i2c_data(i2cctl)) { |
| 1228 | status = IXGBE_ERR_I2C; |
| 1229 | hw_dbg(hw, "Error - I2C data was not set to %X.\n", data); |
| 1230 | } |
| 1231 | |
| 1232 | return status; |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * ixgbe_get_i2c_data - Reads the I2C SDA data bit |
| 1237 | * @hw: pointer to hardware structure |
| 1238 | * @i2cctl: Current value of I2CCTL register |
| 1239 | * |
| 1240 | * Returns the I2C data bit value |
| 1241 | **/ |
| 1242 | static bool ixgbe_get_i2c_data(u32 *i2cctl) |
| 1243 | { |
| 1244 | bool data; |
| 1245 | |
| 1246 | if (*i2cctl & IXGBE_I2C_DATA_IN) |
| 1247 | data = 1; |
| 1248 | else |
| 1249 | data = 0; |
| 1250 | |
| 1251 | return data; |
| 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * ixgbe_i2c_bus_clear - Clears the I2C bus |
| 1256 | * @hw: pointer to hardware structure |
| 1257 | * |
| 1258 | * Clears the I2C bus by sending nine clock pulses. |
| 1259 | * Used when data line is stuck low. |
| 1260 | **/ |
| 1261 | static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw) |
| 1262 | { |
| 1263 | u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL); |
| 1264 | u32 i; |
| 1265 | |
| 1266 | ixgbe_set_i2c_data(hw, &i2cctl, 1); |
| 1267 | |
| 1268 | for (i = 0; i < 9; i++) { |
| 1269 | ixgbe_raise_i2c_clk(hw, &i2cctl); |
| 1270 | |
| 1271 | /* Min high period of clock is 4us */ |
| 1272 | udelay(IXGBE_I2C_T_HIGH); |
| 1273 | |
| 1274 | ixgbe_lower_i2c_clk(hw, &i2cctl); |
| 1275 | |
| 1276 | /* Min low period of clock is 4.7us*/ |
| 1277 | udelay(IXGBE_I2C_T_LOW); |
| 1278 | } |
| 1279 | |
| 1280 | /* Put the i2c bus back to default state */ |
| 1281 | ixgbe_i2c_stop(hw); |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1285 | * ixgbe_check_phy_link_tnx - Determine link and speed status |
| 1286 | * @hw: pointer to hardware structure |
| 1287 | * |
| 1288 | * Reads the VS1 register to determine if link is up and the current speed for |
| 1289 | * the PHY. |
| 1290 | **/ |
| 1291 | s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed, |
| 1292 | bool *link_up) |
| 1293 | { |
| 1294 | s32 status = 0; |
| 1295 | u32 time_out; |
| 1296 | u32 max_time_out = 10; |
| 1297 | u16 phy_link = 0; |
| 1298 | u16 phy_speed = 0; |
| 1299 | u16 phy_data = 0; |
| 1300 | |
| 1301 | /* Initialize speed and link to default case */ |
| 1302 | *link_up = false; |
| 1303 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 1304 | |
| 1305 | /* |
| 1306 | * Check current speed and link status of the PHY register. |
| 1307 | * This is a vendor specific register and may have to |
| 1308 | * be changed for other copper PHYs. |
| 1309 | */ |
| 1310 | for (time_out = 0; time_out < max_time_out; time_out++) { |
| 1311 | udelay(10); |
| 1312 | status = hw->phy.ops.read_reg(hw, |
| 1313 | IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1314 | MDIO_MMD_VEND1, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1315 | &phy_data); |
| 1316 | phy_link = phy_data & |
| 1317 | IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS; |
| 1318 | phy_speed = phy_data & |
| 1319 | IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS; |
| 1320 | if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) { |
| 1321 | *link_up = true; |
| 1322 | if (phy_speed == |
| 1323 | IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS) |
| 1324 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 1325 | break; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | return status; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version |
| 1334 | * @hw: pointer to hardware structure |
| 1335 | * @firmware_version: pointer to the PHY Firmware Version |
| 1336 | **/ |
| 1337 | s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, |
| 1338 | u16 *firmware_version) |
| 1339 | { |
| 1340 | s32 status = 0; |
| 1341 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1342 | status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1343 | firmware_version); |
| 1344 | |
| 1345 | return status; |
| 1346 | } |
| 1347 | |