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