blob: ebf46afd08b003e705f07522fe6b2c0a6142661f [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorec97506a2014-02-27 20:32:43 -08004 Copyright(c) 1999 - 2014 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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:
Jacob Kellerb89aae72014-02-22 01:23:50 +000023 Linux NICS <linux.nics@intel.com>
Auke Kok9a799d72007-09-15 14:07:45 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include <linux/pci.h>
30#include <linux/delay.h>
31#include <linux/sched.h>
32
Mark Rustadb12babd2014-01-14 18:53:16 -080033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_phy.h"
35
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000036static void ixgbe_i2c_start(struct ixgbe_hw *hw);
37static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
38static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
39static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
40static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
41static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
42static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
Emil Tantilove1befd72011-08-27 07:18:47 +000043static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000044static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
45static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
Don Skidmore9a75a1a2014-11-07 03:53:35 +000046static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000047static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
49static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
Mark Rustad88217542013-11-23 03:19:19 +000050static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070051
52/**
Don Skidmore28abba02014-11-29 05:22:43 +000053 * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
54 * @hw: pointer to the hardware structure
55 * @byte: byte to send
56 *
57 * Returns an error code on error.
58 **/
59static s32 ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
60{
61 s32 status;
62
63 status = ixgbe_clock_out_i2c_byte(hw, byte);
64 if (status)
65 return status;
66 return ixgbe_get_i2c_ack(hw);
67}
68
69/**
70 * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
71 * @hw: pointer to the hardware structure
72 * @byte: pointer to a u8 to receive the byte
73 *
74 * Returns an error code on error.
75 **/
76static s32 ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
77{
78 s32 status;
79
80 status = ixgbe_clock_in_i2c_byte(hw, byte);
81 if (status)
82 return status;
83 /* ACK */
84 return ixgbe_clock_out_i2c_bit(hw, false);
85}
86
87/**
88 * ixgbe_ones_comp_byte_add - Perform one's complement addition
89 * @add1: addend 1
90 * @add2: addend 2
91 *
92 * Returns one's complement 8-bit sum.
93 **/
94static u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
95{
96 u16 sum = add1 + add2;
97
98 sum = (sum & 0xFF) + (sum >> 8);
99 return sum & 0xFF;
100}
101
102/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700103 * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
Don Skidmore28abba02014-11-29 05:22:43 +0000104 * @hw: pointer to the hardware structure
105 * @addr: I2C bus address to read from
106 * @reg: I2C device register to read from
107 * @val: pointer to location to receive read value
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700108 * @lock: true if to take and release semaphore
Don Skidmore28abba02014-11-29 05:22:43 +0000109 *
110 * Returns an error code on error.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700111 */
112static s32 ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
113 u16 reg, u16 *val, bool lock)
Don Skidmore28abba02014-11-29 05:22:43 +0000114{
115 u32 swfw_mask = hw->phy.phy_semaphore_mask;
116 int max_retry = 10;
117 int retry = 0;
118 u8 csum_byte;
119 u8 high_bits;
120 u8 low_bits;
121 u8 reg_high;
122 u8 csum;
123
124 reg_high = ((reg >> 7) & 0xFE) | 1; /* Indicate read combined */
125 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
126 csum = ~csum;
127 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700128 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Don Skidmore28abba02014-11-29 05:22:43 +0000129 return IXGBE_ERR_SWFW_SYNC;
130 ixgbe_i2c_start(hw);
131 /* Device Address and write indication */
132 if (ixgbe_out_i2c_byte_ack(hw, addr))
133 goto fail;
134 /* Write bits 14:8 */
135 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
136 goto fail;
137 /* Write bits 7:0 */
138 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
139 goto fail;
140 /* Write csum */
141 if (ixgbe_out_i2c_byte_ack(hw, csum))
142 goto fail;
143 /* Re-start condition */
144 ixgbe_i2c_start(hw);
145 /* Device Address and read indication */
146 if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
147 goto fail;
148 /* Get upper bits */
149 if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
150 goto fail;
151 /* Get low bits */
152 if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
153 goto fail;
154 /* Get csum */
155 if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
156 goto fail;
157 /* NACK */
158 if (ixgbe_clock_out_i2c_bit(hw, false))
159 goto fail;
160 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700161 if (lock)
162 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000163 *val = (high_bits << 8) | low_bits;
164 return 0;
165
166fail:
167 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700168 if (lock)
169 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000170 retry++;
171 if (retry < max_retry)
172 hw_dbg(hw, "I2C byte read combined error - Retry.\n");
173 else
174 hw_dbg(hw, "I2C byte read combined error.\n");
175 } while (retry < max_retry);
176
177 return IXGBE_ERR_I2C;
178}
179
180/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700181 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
182 * @hw: pointer to the hardware structure
183 * @addr: I2C bus address to read from
184 * @reg: I2C device register to read from
185 * @val: pointer to location to receive read value
186 *
187 * Returns an error code on error.
188 */
189s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
190 u16 reg, u16 *val)
191{
192 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, true);
193}
194
195/**
196 * ixgbe_read_i2c_combined_generic_unlocked - Unlocked I2C read combined
197 * @hw: pointer to the hardware structure
198 * @addr: I2C bus address to read from
199 * @reg: I2C device register to read from
200 * @val: pointer to location to receive read value
201 *
202 * Returns an error code on error.
203 */
204s32 ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *hw, u8 addr,
205 u16 reg, u16 *val)
206{
207 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, false);
208}
209
210/**
211 * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
Don Skidmore28abba02014-11-29 05:22:43 +0000212 * @hw: pointer to the hardware structure
213 * @addr: I2C bus address to write to
214 * @reg: I2C device register to write to
215 * @val: value to write
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700216 * @lock: true if to take and release semaphore
Don Skidmore28abba02014-11-29 05:22:43 +0000217 *
218 * Returns an error code on error.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700219 */
220static s32 ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
221 u16 reg, u16 val, bool lock)
Don Skidmore28abba02014-11-29 05:22:43 +0000222{
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700223 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Don Skidmore28abba02014-11-29 05:22:43 +0000224 int max_retry = 1;
225 int retry = 0;
226 u8 reg_high;
227 u8 csum;
228
229 reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
230 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
231 csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
232 csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
233 csum = ~csum;
234 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700235 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
236 return IXGBE_ERR_SWFW_SYNC;
Don Skidmore28abba02014-11-29 05:22:43 +0000237 ixgbe_i2c_start(hw);
238 /* Device Address and write indication */
239 if (ixgbe_out_i2c_byte_ack(hw, addr))
240 goto fail;
241 /* Write bits 14:8 */
242 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
243 goto fail;
244 /* Write bits 7:0 */
245 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
246 goto fail;
247 /* Write data 15:8 */
248 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
249 goto fail;
250 /* Write data 7:0 */
251 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
252 goto fail;
253 /* Write csum */
254 if (ixgbe_out_i2c_byte_ack(hw, csum))
255 goto fail;
256 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700257 if (lock)
258 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000259 return 0;
260
261fail:
262 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700263 if (lock)
264 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000265 retry++;
266 if (retry < max_retry)
267 hw_dbg(hw, "I2C byte write combined error - Retry.\n");
268 else
269 hw_dbg(hw, "I2C byte write combined error.\n");
270 } while (retry < max_retry);
271
272 return IXGBE_ERR_I2C;
273}
274
275/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700276 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
277 * @hw: pointer to the hardware structure
278 * @addr: I2C bus address to write to
279 * @reg: I2C device register to write to
280 * @val: value to write
281 *
282 * Returns an error code on error.
283 */
284s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
285 u8 addr, u16 reg, u16 val)
286{
287 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, true);
288}
289
290/**
291 * ixgbe_write_i2c_combined_generic_unlocked - Unlocked I2C write combined
292 * @hw: pointer to the hardware structure
293 * @addr: I2C bus address to write to
294 * @reg: I2C device register to write to
295 * @val: value to write
296 *
297 * Returns an error code on error.
298 */
299s32 ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *hw,
300 u8 addr, u16 reg, u16 val)
301{
302 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, false);
303}
304
305/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700306 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -0700307 * @hw: pointer to hardware structure
308 *
309 * Determines the physical layer module found on the current adapter.
310 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700311s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700312{
Auke Kok9a799d72007-09-15 14:07:45 -0700313 u32 phy_addr;
Emil Tantilov037c6d02011-02-25 07:49:39 +0000314 u16 ext_ability = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700315
Don Skidmore030eaec2014-11-29 05:22:37 +0000316 if (!hw->phy.phy_semaphore_mask) {
Don Skidmored5702de2015-06-19 12:23:36 -0400317 if (hw->bus.lan_id)
Don Skidmore030eaec2014-11-29 05:22:37 +0000318 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
319 else
320 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
321 }
322
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700323 if (hw->phy.type == ixgbe_phy_unknown) {
324 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +0000325 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +0000326 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700327 ixgbe_get_phy_id(hw);
328 hw->phy.type =
Jacob Kellere7cf7452014-04-09 06:03:10 +0000329 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +0000330
331 if (hw->phy.type == ixgbe_phy_unknown) {
332 hw->phy.ops.read_reg(hw,
333 MDIO_PMA_EXTABLE,
334 MDIO_MMD_PMAPMD,
335 &ext_ability);
336 if (ext_ability &
337 (MDIO_PMA_EXTABLE_10GBT |
338 MDIO_PMA_EXTABLE_1000BT))
339 hw->phy.type =
340 ixgbe_phy_cu_unknown;
341 else
342 hw->phy.type =
343 ixgbe_phy_generic;
344 }
345
Mark Rustade90dd262014-07-22 06:51:08 +0000346 return 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700347 }
Auke Kok9a799d72007-09-15 14:07:45 -0700348 }
Mark Rustad7564a882016-09-01 13:58:51 -0700349 /* indicate no PHY found */
350 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
Mark Rustade90dd262014-07-22 06:51:08 +0000351 return IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700352 }
Mark Rustade90dd262014-07-22 06:51:08 +0000353 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700354}
355
356/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800357 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
358 * @hw: pointer to the hardware structure
359 *
360 * This function checks the MMNGC.MNG_VETO bit to see if there are
361 * any constraints on link from manageability. For MAC's that don't
362 * have this bit just return false since the link can not be blocked
363 * via this method.
364 **/
Jean Sacren6425f0f2014-03-11 05:57:56 +0000365bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
Don Skidmorec97506a2014-02-27 20:32:43 -0800366{
367 u32 mmngc;
368
369 /* If we don't have this bit, it can't be blocking */
370 if (hw->mac.type == ixgbe_mac_82598EB)
371 return false;
372
373 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
374 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
375 hw_dbg(hw, "MNG_VETO bit detected.\n");
376 return true;
377 }
378
379 return false;
380}
381
382/**
Auke Kok9a799d72007-09-15 14:07:45 -0700383 * ixgbe_get_phy_id - Get the phy type
384 * @hw: pointer to hardware structure
385 *
386 **/
387static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
388{
Mark Rustada1e869d2015-04-10 10:36:36 -0700389 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700390 u16 phy_id_high = 0;
391 u16 phy_id_low = 0;
392
Ben Hutchings6b73e102009-04-29 08:08:58 +0000393 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000394 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700395
Mark Rustada1e869d2015-04-10 10:36:36 -0700396 if (!status) {
Auke Kok9a799d72007-09-15 14:07:45 -0700397 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000398 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000399 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700400 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
401 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
402 }
Auke Kok9a799d72007-09-15 14:07:45 -0700403 return status;
404}
405
406/**
407 * ixgbe_get_phy_type_from_id - Get the phy type
408 * @hw: pointer to hardware structure
409 *
410 **/
411static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
412{
413 enum ixgbe_phy_type phy_type;
414
415 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700416 case TN1010_PHY_ID:
417 phy_type = ixgbe_phy_tn;
418 break;
Don Skidmorededa5622015-06-09 17:39:46 -0700419 case X550_PHY_ID:
Don Skidmore2b264902010-12-09 06:55:14 +0000420 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800421 phy_type = ixgbe_phy_aq;
422 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700423 case QT2022_PHY_ID:
424 phy_type = ixgbe_phy_qt;
425 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800426 case ATH_PHY_ID:
427 phy_type = ixgbe_phy_nl;
428 break;
Don Skidmorec2c78d52015-06-09 16:04:59 -0700429 case X557_PHY_ID:
430 phy_type = ixgbe_phy_x550em_ext_t;
431 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700432 default:
433 phy_type = ixgbe_phy_unknown;
434 break;
435 }
436
437 return phy_type;
438}
439
440/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700441 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700442 * @hw: pointer to hardware structure
443 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700444s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700445{
Emil Tantilov17835752011-02-16 01:38:13 +0000446 u32 i;
447 u16 ctrl = 0;
448 s32 status = 0;
449
450 if (hw->phy.type == ixgbe_phy_unknown)
451 status = ixgbe_identify_phy_generic(hw);
452
453 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000454 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000455
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700456 /* Don't reset PHY if it's shut down due to overtemp. */
457 if (!hw->phy.reset_if_overtemp &&
458 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000459 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700460
Don Skidmorec97506a2014-02-27 20:32:43 -0800461 /* Blocked by MNG FW so bail */
462 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000463 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800464
Auke Kok9a799d72007-09-15 14:07:45 -0700465 /*
466 * Perform soft PHY reset to the PHY_XS.
467 * This will cause a soft reset to the PHY
468 */
Emil Tantilov17835752011-02-16 01:38:13 +0000469 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
470 MDIO_MMD_PHYXS,
471 MDIO_CTRL1_RESET);
472
473 /*
474 * Poll for reset bit to self-clear indicating reset is complete.
475 * Some PHYs could take up to 3 seconds to complete and need about
476 * 1.7 usec delay after the reset is complete.
477 */
478 for (i = 0; i < 30; i++) {
479 msleep(100);
480 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
481 MDIO_MMD_PHYXS, &ctrl);
482 if (!(ctrl & MDIO_CTRL1_RESET)) {
483 udelay(2);
484 break;
485 }
486 }
487
488 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000489 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000490 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000491 }
492
Mark Rustade90dd262014-07-22 06:51:08 +0000493 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700494}
495
496/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000497 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
498 * the SWFW lock
499 * @hw: pointer to hardware structure
500 * @reg_addr: 32 bit address of PHY register to read
501 * @phy_data: Pointer to read data from PHY register
502 **/
503s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
504 u16 *phy_data)
505{
506 u32 i, data, command;
507
508 /* Setup and write the address cycle command */
509 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
510 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
511 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
512 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
513
514 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
515
516 /* Check every 10 usec to see if the address cycle completed.
517 * The MDI Command bit will clear when the operation is
518 * complete
519 */
520 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
521 udelay(10);
522
523 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
524 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
525 break;
526 }
527
528
529 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
530 hw_dbg(hw, "PHY address command did not complete.\n");
531 return IXGBE_ERR_PHY;
532 }
533
534 /* Address cycle complete, setup and write the read
535 * command
536 */
537 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
538 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
539 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
540 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
541
542 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
543
544 /* Check every 10 usec to see if the address cycle
545 * completed. The MDI Command bit will clear when the
546 * operation is complete
547 */
548 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
549 udelay(10);
550
551 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
552 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
553 break;
554 }
555
556 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
557 hw_dbg(hw, "PHY read command didn't complete\n");
558 return IXGBE_ERR_PHY;
559 }
560
561 /* Read operation is complete. Get the data
562 * from MSRWD
563 */
564 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
565 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
566 *phy_data = (u16)(data);
567
568 return 0;
569}
570
571/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700572 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000573 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700574 * @hw: pointer to hardware structure
575 * @reg_addr: 32 bit address of PHY register to read
576 * @phy_data: Pointer to read data from PHY register
577 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700578s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000579 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700580{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000581 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000582 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700583
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000584 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
585 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
586 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000587 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000588 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000589 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700590 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700591
Auke Kok9a799d72007-09-15 14:07:45 -0700592 return status;
593}
594
595/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000596 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
597 * without SWFW lock
598 * @hw: pointer to hardware structure
599 * @reg_addr: 32 bit PHY register to write
600 * @device_type: 5 bit device type
601 * @phy_data: Data to write to the PHY register
602 **/
603s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
604 u32 device_type, u16 phy_data)
605{
606 u32 i, command;
607
608 /* Put the data in the MDI single read and write data register*/
609 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
610
611 /* Setup and write the address cycle command */
612 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
613 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
614 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
615 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
616
617 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
618
619 /*
620 * Check every 10 usec to see if the address cycle completed.
621 * The MDI Command bit will clear when the operation is
622 * complete
623 */
624 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
625 udelay(10);
626
627 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
628 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
629 break;
630 }
631
632 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
633 hw_dbg(hw, "PHY address cmd didn't complete\n");
634 return IXGBE_ERR_PHY;
635 }
636
637 /*
638 * Address cycle complete, setup and write the write
639 * command
640 */
641 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
642 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
643 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
644 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
645
646 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
647
648 /* Check every 10 usec to see if the address cycle
649 * completed. The MDI Command bit will clear when the
650 * operation is complete
651 */
652 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
653 udelay(10);
654
655 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
656 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
657 break;
658 }
659
660 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
661 hw_dbg(hw, "PHY write cmd didn't complete\n");
662 return IXGBE_ERR_PHY;
663 }
664
665 return 0;
666}
667
668/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700669 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000670 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700671 * @hw: pointer to hardware structure
672 * @reg_addr: 32 bit PHY register to write
673 * @device_type: 5 bit device type
674 * @phy_data: Data to write to the PHY register
675 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700676s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000677 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700678{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000679 s32 status;
Don Skidmore897b9342015-06-19 19:14:57 -0400680 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700681
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000682 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
683 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
684 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000685 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000686 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000687 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700688 }
689
690 return status;
691}
692
693/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700694 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700695 * @hw: pointer to hardware structure
696 *
697 * Restart autonegotiation and PHY and waits for completion.
698 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700699s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700700{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000701 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000702 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
703 bool autoneg = false;
704 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700705
Emil Tantilov9dda1732011-03-05 01:28:07 +0000706 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700707
Don Skidmored2e455a2016-10-21 21:10:54 -0400708 /* Set or unset auto-negotiation 10G advertisement */
709 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, &autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000710
Don Skidmored2e455a2016-10-21 21:10:54 -0400711 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
712 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) &&
713 (speed & IXGBE_LINK_SPEED_10GB_FULL))
714 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700715
Don Skidmored2e455a2016-10-21 21:10:54 -0400716 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, autoneg_reg);
717
718 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
719 MDIO_MMD_AN, &autoneg_reg);
720
721 if (hw->mac.type == ixgbe_mac_X550) {
722 /* Set or unset auto-negotiation 5G advertisement */
723 autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
724 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) &&
725 (speed & IXGBE_LINK_SPEED_5GB_FULL))
726 autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
727
728 /* Set or unset auto-negotiation 2.5G advertisement */
729 autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
730 if ((hw->phy.autoneg_advertised &
731 IXGBE_LINK_SPEED_2_5GB_FULL) &&
732 (speed & IXGBE_LINK_SPEED_2_5GB_FULL))
733 autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000734 }
735
Don Skidmored2e455a2016-10-21 21:10:54 -0400736 /* Set or unset auto-negotiation 1G advertisement */
737 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
738 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) &&
739 (speed & IXGBE_LINK_SPEED_1GB_FULL))
740 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000741
Don Skidmored2e455a2016-10-21 21:10:54 -0400742 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
743 MDIO_MMD_AN, autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000744
Don Skidmored2e455a2016-10-21 21:10:54 -0400745 /* Set or unset auto-negotiation 100M advertisement */
746 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000747
Don Skidmored2e455a2016-10-21 21:10:54 -0400748 autoneg_reg &= ~(ADVERTISE_100FULL | ADVERTISE_100HALF);
749 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) &&
750 (speed & IXGBE_LINK_SPEED_100_FULL))
751 autoneg_reg |= ADVERTISE_100FULL;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000752
Don Skidmored2e455a2016-10-21 21:10:54 -0400753 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700754
Don Skidmorec97506a2014-02-27 20:32:43 -0800755 /* Blocked by MNG FW so don't reset PHY */
756 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000757 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800758
Auke Kok9a799d72007-09-15 14:07:45 -0700759 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000760 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
761 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700762
Ben Hutchings6b73e102009-04-29 08:08:58 +0000763 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700764
Emil Tantilov9dda1732011-03-05 01:28:07 +0000765 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
766 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700767
Auke Kok9a799d72007-09-15 14:07:45 -0700768 return status;
769}
770
771/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700772 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700773 * @hw: pointer to hardware structure
774 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700775 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700776s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000777 ixgbe_link_speed speed,
778 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700779{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700780
Auke Kok9a799d72007-09-15 14:07:45 -0700781 /*
782 * Clear autoneg_advertised and set new values based on input link
783 * speed.
784 */
785 hw->phy.autoneg_advertised = 0;
786
787 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
788 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700789
Auke Kok9a799d72007-09-15 14:07:45 -0700790 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
791 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
792
Emil Tantilov9dda1732011-03-05 01:28:07 +0000793 if (speed & IXGBE_LINK_SPEED_100_FULL)
794 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
795
Auke Kok9a799d72007-09-15 14:07:45 -0700796 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700797 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700798
799 return 0;
800}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700801
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700802/**
Mark Rustadae8140a2015-06-25 17:49:57 -0700803 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
804 * @hw: pointer to hardware structure
805 *
806 * Determines the supported link capabilities by reading the PHY auto
807 * negotiation register.
808 */
809static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
810{
811 u16 speed_ability;
812 s32 status;
813
814 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
815 &speed_ability);
816 if (status)
817 return status;
818
819 if (speed_ability & MDIO_SPEED_10G)
820 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
821 if (speed_ability & MDIO_PMA_SPEED_1000)
822 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
823 if (speed_ability & MDIO_PMA_SPEED_100)
824 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
825
826 switch (hw->mac.type) {
827 case ixgbe_mac_X550:
828 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
829 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
830 break;
831 case ixgbe_mac_X550EM_x:
832 hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
833 break;
834 default:
835 break;
836 }
837
838 return 0;
839}
840
841/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800842 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
843 * @hw: pointer to hardware structure
844 * @speed: pointer to link speed
845 * @autoneg: boolean auto-negotiation value
Don Skidmorea391f1d2010-11-16 19:27:15 -0800846 */
847s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000848 ixgbe_link_speed *speed,
849 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800850{
Mark Rustadae8140a2015-06-25 17:49:57 -0700851 s32 status = 0;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800852
Don Skidmorea391f1d2010-11-16 19:27:15 -0800853 *autoneg = true;
Mark Rustadae8140a2015-06-25 17:49:57 -0700854 if (!hw->phy.speeds_supported)
855 status = ixgbe_get_copper_speeds_supported(hw);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800856
Mark Rustadae8140a2015-06-25 17:49:57 -0700857 *speed = hw->phy.speeds_supported;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800858 return status;
859}
860
861/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000862 * ixgbe_check_phy_link_tnx - Determine link and speed status
863 * @hw: pointer to hardware structure
864 *
865 * Reads the VS1 register to determine if link is up and the current speed for
866 * the PHY.
867 **/
868s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
869 bool *link_up)
870{
Mark Rustade90dd262014-07-22 06:51:08 +0000871 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000872 u32 time_out;
873 u32 max_time_out = 10;
874 u16 phy_link = 0;
875 u16 phy_speed = 0;
876 u16 phy_data = 0;
877
878 /* Initialize speed and link to default case */
879 *link_up = false;
880 *speed = IXGBE_LINK_SPEED_10GB_FULL;
881
882 /*
883 * Check current speed and link status of the PHY register.
884 * This is a vendor specific register and may have to
885 * be changed for other copper PHYs.
886 */
887 for (time_out = 0; time_out < max_time_out; time_out++) {
888 udelay(10);
889 status = hw->phy.ops.read_reg(hw,
890 MDIO_STAT1,
891 MDIO_MMD_VEND1,
892 &phy_data);
893 phy_link = phy_data &
894 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
895 phy_speed = phy_data &
896 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
897 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
898 *link_up = true;
899 if (phy_speed ==
900 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
901 *speed = IXGBE_LINK_SPEED_1GB_FULL;
902 break;
903 }
904 }
905
906 return status;
907}
908
909/**
910 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
911 * @hw: pointer to hardware structure
912 *
913 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000914 * This function always returns success, this is nessary since
915 * it is called via a function pointer that could call other
916 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000917 **/
918s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
919{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000920 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
921 bool autoneg = false;
922 ixgbe_link_speed speed;
923
924 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
925
926 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
927 /* Set or unset auto-negotiation 10G advertisement */
928 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
929 MDIO_MMD_AN,
930 &autoneg_reg);
931
932 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
933 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
934 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
935
936 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
937 MDIO_MMD_AN,
938 autoneg_reg);
939 }
940
941 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
942 /* Set or unset auto-negotiation 1G advertisement */
943 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
944 MDIO_MMD_AN,
945 &autoneg_reg);
946
947 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
948 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
949 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
950
951 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
952 MDIO_MMD_AN,
953 autoneg_reg);
954 }
955
956 if (speed & IXGBE_LINK_SPEED_100_FULL) {
957 /* Set or unset auto-negotiation 100M advertisement */
958 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
959 MDIO_MMD_AN,
960 &autoneg_reg);
961
Emil Tantilov50c022e2011-03-31 09:36:12 +0000962 autoneg_reg &= ~(ADVERTISE_100FULL |
963 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000964 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
965 autoneg_reg |= ADVERTISE_100FULL;
966
967 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
968 MDIO_MMD_AN,
969 autoneg_reg);
970 }
971
Don Skidmorec97506a2014-02-27 20:32:43 -0800972 /* Blocked by MNG FW so don't reset PHY */
973 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000974 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800975
Emil Tantilov9dda1732011-03-05 01:28:07 +0000976 /* Restart PHY autonegotiation and wait for completion */
977 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
978 MDIO_MMD_AN, &autoneg_reg);
979
980 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
981
982 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
983 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000984 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000985}
986
987/**
988 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
989 * @hw: pointer to hardware structure
990 * @firmware_version: pointer to the PHY Firmware Version
991 **/
992s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
993 u16 *firmware_version)
994{
Mark Rustade90dd262014-07-22 06:51:08 +0000995 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000996
997 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
998 MDIO_MMD_VEND1,
999 firmware_version);
1000
1001 return status;
1002}
1003
1004/**
1005 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
1006 * @hw: pointer to hardware structure
1007 * @firmware_version: pointer to the PHY Firmware Version
1008 **/
1009s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
1010 u16 *firmware_version)
1011{
Mark Rustade90dd262014-07-22 06:51:08 +00001012 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +00001013
1014 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
1015 MDIO_MMD_VEND1,
1016 firmware_version);
1017
1018 return status;
1019}
1020
1021/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08001022 * ixgbe_reset_phy_nl - Performs a PHY reset
1023 * @hw: pointer to hardware structure
1024 **/
1025s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
1026{
1027 u16 phy_offset, control, eword, edata, block_crc;
1028 bool end_data = false;
1029 u16 list_offset, data_offset;
1030 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +00001031 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001032 u32 i;
1033
Don Skidmorec97506a2014-02-27 20:32:43 -08001034 /* Blocked by MNG FW so bail */
1035 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00001036 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -08001037
Ben Hutchings6b73e102009-04-29 08:08:58 +00001038 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001039
1040 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +00001041 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001042 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -08001043
1044 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +00001045 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001046 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +00001047 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001048 break;
Don Skidmore032b4322011-03-18 09:32:53 +00001049 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001050 }
1051
Ben Hutchings6b73e102009-04-29 08:08:58 +00001052 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001053 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001054 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001055 }
1056
1057 /* Get init offsets */
1058 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001059 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +00001060 if (ret_val)
1061 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001062
1063 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
1064 data_offset++;
1065 while (!end_data) {
1066 /*
1067 * Read control word from PHY init contents offset
1068 */
1069 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001070 if (ret_val)
1071 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001072 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +00001073 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001074 edata = eword & IXGBE_DATA_MASK_NL;
1075 switch (control) {
1076 case IXGBE_DELAY_NL:
1077 data_offset++;
1078 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +00001079 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001080 break;
1081 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +00001082 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001083 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001084 ret_val = hw->eeprom.ops.read(hw, data_offset++,
1085 &phy_offset);
1086 if (ret_val)
1087 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001088 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001089 ret_val = hw->eeprom.ops.read(hw, data_offset,
1090 &eword);
1091 if (ret_val)
1092 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001093 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001094 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001095 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1096 phy_offset);
1097 data_offset++;
1098 phy_offset++;
1099 }
1100 break;
1101 case IXGBE_CONTROL_NL:
1102 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001103 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001104 if (edata == IXGBE_CONTROL_EOL_NL) {
1105 hw_dbg(hw, "EOL\n");
1106 end_data = true;
1107 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1108 hw_dbg(hw, "SOL\n");
1109 } else {
1110 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001111 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001112 }
1113 break;
1114 default:
1115 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001116 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001117 }
1118 }
1119
Donald Skidmorec4900be2008-11-20 21:11:42 -08001120 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001121
1122err_eeprom:
1123 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1124 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001125}
1126
1127/**
Don Skidmore8f583322013-07-27 06:25:38 +00001128 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001129 * @hw: pointer to hardware structure
1130 *
Don Skidmore8f583322013-07-27 06:25:38 +00001131 * Determines HW type and calls appropriate function.
1132 **/
1133s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1134{
Don Skidmore8f583322013-07-27 06:25:38 +00001135 switch (hw->mac.ops.get_media_type(hw)) {
1136 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001137 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001138 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001139 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001140 default:
1141 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001142 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001143 }
1144
Mark Rustade90dd262014-07-22 06:51:08 +00001145 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001146}
1147
1148/**
1149 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1150 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001151 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001152 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001153 **/
1154s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1155{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001156 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001157 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001158 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001159 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001160 u8 identifier = 0;
1161 u8 comp_codes_1g = 0;
1162 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001163 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001164 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001165 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001166 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001167
Don Skidmore8ca783a2009-05-26 20:40:47 -07001168 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1169 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001170 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001171 }
1172
Mark Rustadda4ea4b2015-08-08 16:18:07 -07001173 /* LAN ID is needed for sfp_type determination */
1174 hw->mac.ops.set_lan_id(hw);
1175
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001176 status = hw->phy.ops.read_i2c_eeprom(hw,
1177 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001178 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001179
Mark Rustade90dd262014-07-22 06:51:08 +00001180 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001181 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001182
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001183 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1184 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001185 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1186 }
1187 status = hw->phy.ops.read_i2c_eeprom(hw,
1188 IXGBE_SFF_1GBE_COMP_CODES,
1189 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001190
Mark Rustade90dd262014-07-22 06:51:08 +00001191 if (status)
1192 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001193
Mark Rustade90dd262014-07-22 06:51:08 +00001194 status = hw->phy.ops.read_i2c_eeprom(hw,
1195 IXGBE_SFF_10GBE_COMP_CODES,
1196 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001197
Mark Rustade90dd262014-07-22 06:51:08 +00001198 if (status)
1199 goto err_read_i2c_eeprom;
1200 status = hw->phy.ops.read_i2c_eeprom(hw,
1201 IXGBE_SFF_CABLE_TECHNOLOGY,
1202 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001203
Mark Rustade90dd262014-07-22 06:51:08 +00001204 if (status)
1205 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001206
Mark Rustade90dd262014-07-22 06:51:08 +00001207 /* ID Module
1208 * =========
1209 * 0 SFP_DA_CU
1210 * 1 SFP_SR
1211 * 2 SFP_LR
1212 * 3 SFP_DA_CORE0 - 82599-specific
1213 * 4 SFP_DA_CORE1 - 82599-specific
1214 * 5 SFP_SR/LR_CORE0 - 82599-specific
1215 * 6 SFP_SR/LR_CORE1 - 82599-specific
1216 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1217 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1218 * 9 SFP_1g_cu_CORE0 - 82599-specific
1219 * 10 SFP_1g_cu_CORE1 - 82599-specific
1220 * 11 SFP_1g_sx_CORE0 - 82599-specific
1221 * 12 SFP_1g_sx_CORE1 - 82599-specific
1222 */
1223 if (hw->mac.type == ixgbe_mac_82598EB) {
1224 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1225 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1226 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1227 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1228 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1229 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1230 else
1231 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Mark Rustad69eec0c2015-08-08 16:18:43 -07001232 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001233 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1234 if (hw->bus.lan_id == 0)
1235 hw->phy.sfp_type =
1236 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001237 else
Mark Rustade90dd262014-07-22 06:51:08 +00001238 hw->phy.sfp_type =
1239 ixgbe_sfp_type_da_cu_core1;
1240 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1241 hw->phy.ops.read_i2c_eeprom(
1242 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1243 &cable_spec);
1244 if (cable_spec &
1245 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001246 if (hw->bus.lan_id == 0)
1247 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001248 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001249 else
1250 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001251 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001252 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001253 hw->phy.sfp_type =
1254 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001255 }
Mark Rustade90dd262014-07-22 06:51:08 +00001256 } else if (comp_codes_10g &
1257 (IXGBE_SFF_10GBASESR_CAPABLE |
1258 IXGBE_SFF_10GBASELR_CAPABLE)) {
1259 if (hw->bus.lan_id == 0)
1260 hw->phy.sfp_type =
1261 ixgbe_sfp_type_srlr_core0;
1262 else
1263 hw->phy.sfp_type =
1264 ixgbe_sfp_type_srlr_core1;
1265 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1266 if (hw->bus.lan_id == 0)
1267 hw->phy.sfp_type =
1268 ixgbe_sfp_type_1g_cu_core0;
1269 else
1270 hw->phy.sfp_type =
1271 ixgbe_sfp_type_1g_cu_core1;
1272 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1273 if (hw->bus.lan_id == 0)
1274 hw->phy.sfp_type =
1275 ixgbe_sfp_type_1g_sx_core0;
1276 else
1277 hw->phy.sfp_type =
1278 ixgbe_sfp_type_1g_sx_core1;
1279 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1280 if (hw->bus.lan_id == 0)
1281 hw->phy.sfp_type =
1282 ixgbe_sfp_type_1g_lx_core0;
1283 else
1284 hw->phy.sfp_type =
1285 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001286 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001287 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001288 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001289 }
1290
Mark Rustade90dd262014-07-22 06:51:08 +00001291 if (hw->phy.sfp_type != stored_sfp_type)
1292 hw->phy.sfp_setup_needed = true;
1293
1294 /* Determine if the SFP+ PHY is dual speed or not. */
1295 hw->phy.multispeed_fiber = false;
1296 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1297 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1298 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1299 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1300 hw->phy.multispeed_fiber = true;
1301
1302 /* Determine PHY vendor */
1303 if (hw->phy.type != ixgbe_phy_nl) {
1304 hw->phy.id = identifier;
1305 status = hw->phy.ops.read_i2c_eeprom(hw,
1306 IXGBE_SFF_VENDOR_OUI_BYTE0,
1307 &oui_bytes[0]);
1308
1309 if (status != 0)
1310 goto err_read_i2c_eeprom;
1311
1312 status = hw->phy.ops.read_i2c_eeprom(hw,
1313 IXGBE_SFF_VENDOR_OUI_BYTE1,
1314 &oui_bytes[1]);
1315
1316 if (status != 0)
1317 goto err_read_i2c_eeprom;
1318
1319 status = hw->phy.ops.read_i2c_eeprom(hw,
1320 IXGBE_SFF_VENDOR_OUI_BYTE2,
1321 &oui_bytes[2]);
1322
1323 if (status != 0)
1324 goto err_read_i2c_eeprom;
1325
1326 vendor_oui =
1327 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1328 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1329 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1330
1331 switch (vendor_oui) {
1332 case IXGBE_SFF_VENDOR_OUI_TYCO:
1333 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1334 hw->phy.type =
1335 ixgbe_phy_sfp_passive_tyco;
1336 break;
1337 case IXGBE_SFF_VENDOR_OUI_FTL:
1338 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1339 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1340 else
1341 hw->phy.type = ixgbe_phy_sfp_ftl;
1342 break;
1343 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1344 hw->phy.type = ixgbe_phy_sfp_avago;
1345 break;
1346 case IXGBE_SFF_VENDOR_OUI_INTEL:
1347 hw->phy.type = ixgbe_phy_sfp_intel;
1348 break;
1349 default:
1350 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1351 hw->phy.type =
1352 ixgbe_phy_sfp_passive_unknown;
1353 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1354 hw->phy.type =
1355 ixgbe_phy_sfp_active_unknown;
1356 else
1357 hw->phy.type = ixgbe_phy_sfp_unknown;
1358 break;
1359 }
1360 }
1361
1362 /* Allow any DA cable vendor */
1363 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1364 IXGBE_SFF_DA_ACTIVE_CABLE))
1365 return 0;
1366
1367 /* Verify supported 1G SFP modules */
1368 if (comp_codes_10g == 0 &&
1369 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1370 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1371 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1372 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1373 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1374 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1375 hw->phy.type = ixgbe_phy_sfp_unsupported;
1376 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1377 }
1378
1379 /* Anything else 82598-based is supported */
1380 if (hw->mac.type == ixgbe_mac_82598EB)
1381 return 0;
1382
1383 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1384 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1385 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1386 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1387 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1388 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1389 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1390 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1391 /* Make sure we're a supported PHY type */
1392 if (hw->phy.type == ixgbe_phy_sfp_intel)
1393 return 0;
1394 if (hw->allow_unsupported_sfp) {
1395 e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
1396 return 0;
1397 }
1398 hw_dbg(hw, "SFP+ module not supported\n");
1399 hw->phy.type = ixgbe_phy_sfp_unsupported;
1400 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1401 }
1402 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001403
1404err_read_i2c_eeprom:
1405 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1406 if (hw->phy.type != ixgbe_phy_nl) {
1407 hw->phy.id = 0;
1408 hw->phy.type = ixgbe_phy_unknown;
1409 }
1410 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001411}
1412
1413/**
Don Skidmore8f583322013-07-27 06:25:38 +00001414 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1415 * @hw: pointer to hardware structure
1416 *
1417 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1418 **/
Mark Rustad88217542013-11-23 03:19:19 +00001419static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001420{
1421 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001422 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001423 u32 vendor_oui = 0;
1424 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1425 u8 identifier = 0;
1426 u8 comp_codes_1g = 0;
1427 u8 comp_codes_10g = 0;
1428 u8 oui_bytes[3] = {0, 0, 0};
1429 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001430 u8 connector = 0;
1431 u8 cable_length = 0;
1432 u8 device_tech = 0;
1433 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001434
1435 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1436 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001437 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001438 }
1439
Don Skidmore7e49d612015-06-09 17:48:54 -07001440 /* LAN ID is needed for sfp_type determination */
1441 hw->mac.ops.set_lan_id(hw);
1442
Don Skidmore8f583322013-07-27 06:25:38 +00001443 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1444 &identifier);
1445
1446 if (status != 0)
1447 goto err_read_i2c_eeprom;
1448
1449 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1450 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001451 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001452 }
1453
1454 hw->phy.id = identifier;
1455
Don Skidmore8f583322013-07-27 06:25:38 +00001456 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1457 &comp_codes_10g);
1458
1459 if (status != 0)
1460 goto err_read_i2c_eeprom;
1461
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001462 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1463 &comp_codes_1g);
1464
1465 if (status != 0)
1466 goto err_read_i2c_eeprom;
1467
Don Skidmore8f583322013-07-27 06:25:38 +00001468 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1469 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1470 if (hw->bus.lan_id == 0)
1471 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1472 else
1473 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001474 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1475 IXGBE_SFF_10GBASELR_CAPABLE)) {
1476 if (hw->bus.lan_id == 0)
1477 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1478 else
1479 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1480 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001481 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1482 active_cable = true;
1483
1484 if (!active_cable) {
1485 /* check for active DA cables that pre-date
1486 * SFF-8436 v3.6
1487 */
1488 hw->phy.ops.read_i2c_eeprom(hw,
1489 IXGBE_SFF_QSFP_CONNECTOR,
1490 &connector);
1491
1492 hw->phy.ops.read_i2c_eeprom(hw,
1493 IXGBE_SFF_QSFP_CABLE_LENGTH,
1494 &cable_length);
1495
1496 hw->phy.ops.read_i2c_eeprom(hw,
1497 IXGBE_SFF_QSFP_DEVICE_TECH,
1498 &device_tech);
1499
1500 if ((connector ==
1501 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1502 (cable_length > 0) &&
1503 ((device_tech >> 4) ==
1504 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1505 active_cable = true;
1506 }
1507
1508 if (active_cable) {
1509 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1510 if (hw->bus.lan_id == 0)
1511 hw->phy.sfp_type =
1512 ixgbe_sfp_type_da_act_lmt_core0;
1513 else
1514 hw->phy.sfp_type =
1515 ixgbe_sfp_type_da_act_lmt_core1;
1516 } else {
1517 /* unsupported module type */
1518 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001519 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001520 }
Don Skidmore8f583322013-07-27 06:25:38 +00001521 }
1522
1523 if (hw->phy.sfp_type != stored_sfp_type)
1524 hw->phy.sfp_setup_needed = true;
1525
1526 /* Determine if the QSFP+ PHY is dual speed or not. */
1527 hw->phy.multispeed_fiber = false;
1528 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1529 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1530 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1531 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1532 hw->phy.multispeed_fiber = true;
1533
1534 /* Determine PHY vendor for optical modules */
1535 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1536 IXGBE_SFF_10GBASELR_CAPABLE)) {
1537 status = hw->phy.ops.read_i2c_eeprom(hw,
1538 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1539 &oui_bytes[0]);
1540
1541 if (status != 0)
1542 goto err_read_i2c_eeprom;
1543
1544 status = hw->phy.ops.read_i2c_eeprom(hw,
1545 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1546 &oui_bytes[1]);
1547
1548 if (status != 0)
1549 goto err_read_i2c_eeprom;
1550
1551 status = hw->phy.ops.read_i2c_eeprom(hw,
1552 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1553 &oui_bytes[2]);
1554
1555 if (status != 0)
1556 goto err_read_i2c_eeprom;
1557
1558 vendor_oui =
1559 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1560 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1561 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1562
1563 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1564 hw->phy.type = ixgbe_phy_qsfp_intel;
1565 else
1566 hw->phy.type = ixgbe_phy_qsfp_unknown;
1567
1568 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1569 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1570 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001571 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1572 return 0;
1573 if (hw->allow_unsupported_sfp) {
1574 e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
1575 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001576 }
Mark Rustade90dd262014-07-22 06:51:08 +00001577 hw_dbg(hw, "QSFP module not supported\n");
1578 hw->phy.type = ixgbe_phy_sfp_unsupported;
1579 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001580 }
Mark Rustade90dd262014-07-22 06:51:08 +00001581 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001582 }
Mark Rustade90dd262014-07-22 06:51:08 +00001583 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001584
1585err_read_i2c_eeprom:
1586 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1587 hw->phy.id = 0;
1588 hw->phy.type = ixgbe_phy_unknown;
1589
1590 return IXGBE_ERR_SFP_NOT_PRESENT;
1591}
1592
1593/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001594 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001595 * @hw: pointer to hardware structure
1596 * @list_offset: offset to the SFP ID list
1597 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001598 *
1599 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1600 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001601 **/
1602s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001603 u16 *list_offset,
1604 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001605{
1606 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001607 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001608
1609 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1610 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1611
1612 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1613 return IXGBE_ERR_SFP_NOT_PRESENT;
1614
1615 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1616 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1617 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1618
Don Skidmorecb836a92010-06-29 18:30:59 +00001619 /*
1620 * Limiting active cables and 1G Phys must be initialized as
1621 * SR modules
1622 */
1623 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001624 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001625 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1626 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001627 sfp_type = ixgbe_sfp_type_srlr_core0;
1628 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001629 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001630 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1631 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001632 sfp_type = ixgbe_sfp_type_srlr_core1;
1633
Donald Skidmorec4900be2008-11-20 21:11:42 -08001634 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001635 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1636 hw_err(hw, "eeprom read at %d failed\n",
1637 IXGBE_PHY_INIT_OFFSET_NL);
1638 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1639 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001640
1641 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001642 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001643
1644 /* Shift offset to first ID word */
1645 (*list_offset)++;
1646
1647 /*
1648 * Find the matching SFP ID in the EEPROM
1649 * and program the init sequence
1650 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001651 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1652 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001653
1654 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001655 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001656 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001657 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1658 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001659 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1660 hw_dbg(hw, "SFP+ module not supported\n");
1661 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1662 } else {
1663 break;
1664 }
1665 } else {
1666 (*list_offset) += 2;
1667 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001668 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001669 }
1670 }
1671
1672 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1673 hw_dbg(hw, "No matching SFP+ module found\n");
1674 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1675 }
1676
1677 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001678
1679err_phy:
1680 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1681 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001682}
1683
1684/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001685 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1686 * @hw: pointer to hardware structure
1687 * @byte_offset: EEPROM byte offset to read
1688 * @eeprom_data: value read
1689 *
1690 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1691 **/
1692s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001693 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001694{
1695 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001696 IXGBE_I2C_EEPROM_DEV_ADDR,
1697 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001698}
1699
1700/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001701 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1702 * @hw: pointer to hardware structure
1703 * @byte_offset: byte offset at address 0xA2
1704 * @eeprom_data: value read
1705 *
1706 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1707 **/
1708s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1709 u8 *sff8472_data)
1710{
1711 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1712 IXGBE_I2C_EEPROM_DEV_ADDR2,
1713 sff8472_data);
1714}
1715
1716/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001717 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1718 * @hw: pointer to hardware structure
1719 * @byte_offset: EEPROM byte offset to write
1720 * @eeprom_data: value to write
1721 *
1722 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1723 **/
1724s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001725 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001726{
1727 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001728 IXGBE_I2C_EEPROM_DEV_ADDR,
1729 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001730}
1731
1732/**
Mark Rustad56f6ed12015-08-08 16:18:22 -07001733 * ixgbe_is_sfp_probe - Returns true if SFP is being detected
1734 * @hw: pointer to hardware structure
1735 * @offset: eeprom offset to be read
1736 * @addr: I2C address to be read
1737 */
1738static bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
1739{
1740 if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
1741 offset == IXGBE_SFF_IDENTIFIER &&
1742 hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1743 return true;
1744 return false;
1745}
1746
1747/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001748 * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001749 * @hw: pointer to hardware structure
1750 * @byte_offset: byte offset to read
1751 * @data: value read
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001752 * @lock: true if to take and release semaphore
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001753 *
1754 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001755 * a specified device address.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001756 */
1757static s32 ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
1758 u8 dev_addr, u8 *data, bool lock)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001759{
Mark Rustade90dd262014-07-22 06:51:08 +00001760 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001761 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001762 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001763 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001764 bool nack = true;
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001765
Mark Rustad56f6ed12015-08-08 16:18:22 -07001766 if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
1767 max_retry = IXGBE_SFP_DETECT_RETRIES;
1768
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001769 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001770
1771 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001772 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Mark Rustade90dd262014-07-22 06:51:08 +00001773 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001774
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001775 ixgbe_i2c_start(hw);
1776
1777 /* Device Address and write indication */
1778 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1779 if (status != 0)
1780 goto fail;
1781
1782 status = ixgbe_get_i2c_ack(hw);
1783 if (status != 0)
1784 goto fail;
1785
1786 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1787 if (status != 0)
1788 goto fail;
1789
1790 status = ixgbe_get_i2c_ack(hw);
1791 if (status != 0)
1792 goto fail;
1793
1794 ixgbe_i2c_start(hw);
1795
1796 /* Device Address and read indication */
1797 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1798 if (status != 0)
1799 goto fail;
1800
1801 status = ixgbe_get_i2c_ack(hw);
1802 if (status != 0)
1803 goto fail;
1804
1805 status = ixgbe_clock_in_i2c_byte(hw, data);
1806 if (status != 0)
1807 goto fail;
1808
1809 status = ixgbe_clock_out_i2c_bit(hw, nack);
1810 if (status != 0)
1811 goto fail;
1812
1813 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001814 if (lock)
1815 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1816 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001817
1818fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001819 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001820 if (lock) {
1821 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1822 msleep(100);
1823 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001824 retry++;
1825 if (retry < max_retry)
1826 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1827 else
1828 hw_dbg(hw, "I2C byte read error.\n");
1829
1830 } while (retry < max_retry);
1831
1832 return status;
1833}
1834
1835/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001836 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1837 * @hw: pointer to hardware structure
1838 * @byte_offset: byte offset to read
1839 * @data: value read
1840 *
1841 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1842 * a specified device address.
1843 */
1844s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1845 u8 dev_addr, u8 *data)
1846{
1847 return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1848 data, true);
1849}
1850
1851/**
1852 * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
1853 * @hw: pointer to hardware structure
1854 * @byte_offset: byte offset to read
1855 * @data: value read
1856 *
1857 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1858 * a specified device address.
1859 */
1860s32 ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
1861 u8 dev_addr, u8 *data)
1862{
1863 return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1864 data, false);
1865}
1866
1867/**
1868 * ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001869 * @hw: pointer to hardware structure
1870 * @byte_offset: byte offset to write
1871 * @data: value to write
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001872 * @lock: true if to take and release semaphore
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001873 *
1874 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1875 * a specified device address.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001876 */
1877static s32 ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
1878 u8 dev_addr, u8 data, bool lock)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001879{
Mark Rustade90dd262014-07-22 06:51:08 +00001880 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001881 u32 max_retry = 1;
1882 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001883 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001884
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001885 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Mark Rustade90dd262014-07-22 06:51:08 +00001886 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001887
1888 do {
1889 ixgbe_i2c_start(hw);
1890
1891 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1892 if (status != 0)
1893 goto fail;
1894
1895 status = ixgbe_get_i2c_ack(hw);
1896 if (status != 0)
1897 goto fail;
1898
1899 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1900 if (status != 0)
1901 goto fail;
1902
1903 status = ixgbe_get_i2c_ack(hw);
1904 if (status != 0)
1905 goto fail;
1906
1907 status = ixgbe_clock_out_i2c_byte(hw, data);
1908 if (status != 0)
1909 goto fail;
1910
1911 status = ixgbe_get_i2c_ack(hw);
1912 if (status != 0)
1913 goto fail;
1914
1915 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001916 if (lock)
1917 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1918 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001919
1920fail:
1921 ixgbe_i2c_bus_clear(hw);
1922 retry++;
1923 if (retry < max_retry)
1924 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1925 else
1926 hw_dbg(hw, "I2C byte write error.\n");
1927 } while (retry < max_retry);
1928
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001929 if (lock)
1930 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001931
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001932 return status;
1933}
1934
1935/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001936 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1937 * @hw: pointer to hardware structure
1938 * @byte_offset: byte offset to write
1939 * @data: value to write
1940 *
1941 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1942 * a specified device address.
1943 */
1944s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1945 u8 dev_addr, u8 data)
1946{
1947 return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1948 data, true);
1949}
1950
1951/**
1952 * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
1953 * @hw: pointer to hardware structure
1954 * @byte_offset: byte offset to write
1955 * @data: value to write
1956 *
1957 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1958 * a specified device address.
1959 */
1960s32 ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
1961 u8 dev_addr, u8 data)
1962{
1963 return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1964 data, false);
1965}
1966
1967/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001968 * ixgbe_i2c_start - Sets I2C start condition
1969 * @hw: pointer to hardware structure
1970 *
1971 * Sets I2C start condition (High -> Low on SDA while SCL is High)
Mark Rustad25b10292015-08-08 16:18:12 -07001972 * Set bit-bang mode on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001973 **/
1974static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1975{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001976 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001977
Mark Rustad25b10292015-08-08 16:18:12 -07001978 i2cctl |= IXGBE_I2C_BB_EN(hw);
1979
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001980 /* Start condition must begin with data and clock high */
1981 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1982 ixgbe_raise_i2c_clk(hw, &i2cctl);
1983
1984 /* Setup time for start condition (4.7us) */
1985 udelay(IXGBE_I2C_T_SU_STA);
1986
1987 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1988
1989 /* Hold time for start condition (4us) */
1990 udelay(IXGBE_I2C_T_HD_STA);
1991
1992 ixgbe_lower_i2c_clk(hw, &i2cctl);
1993
1994 /* Minimum low period of clock is 4.7 us */
1995 udelay(IXGBE_I2C_T_LOW);
1996
1997}
1998
1999/**
2000 * ixgbe_i2c_stop - Sets I2C stop condition
2001 * @hw: pointer to hardware structure
2002 *
2003 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
Mark Rustad25b10292015-08-08 16:18:12 -07002004 * Disables bit-bang mode and negates data output enable on X550
2005 * hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002006 **/
2007static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
2008{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002009 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Mark Rustad25b10292015-08-08 16:18:12 -07002010 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
2011 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
2012 u32 bb_en_bit = IXGBE_I2C_BB_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002013
2014 /* Stop condition must begin with data low and clock high */
2015 ixgbe_set_i2c_data(hw, &i2cctl, 0);
2016 ixgbe_raise_i2c_clk(hw, &i2cctl);
2017
2018 /* Setup time for stop condition (4us) */
2019 udelay(IXGBE_I2C_T_SU_STO);
2020
2021 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2022
2023 /* bus free time between stop and start (4.7us)*/
2024 udelay(IXGBE_I2C_T_BUF);
Mark Rustad25b10292015-08-08 16:18:12 -07002025
2026 if (bb_en_bit || data_oe_bit || clk_oe_bit) {
2027 i2cctl &= ~bb_en_bit;
2028 i2cctl |= data_oe_bit | clk_oe_bit;
2029 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2030 IXGBE_WRITE_FLUSH(hw);
2031 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002032}
2033
2034/**
2035 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
2036 * @hw: pointer to hardware structure
2037 * @data: data byte to clock in
2038 *
2039 * Clocks in one byte data via I2C data/clock
2040 **/
2041static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
2042{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002043 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002044 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002045
Mark Rustad6ee8c9a2015-08-08 16:18:17 -07002046 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002047 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00002048 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002049 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002050 }
2051
Emil Tantilove1befd72011-08-27 07:18:47 +00002052 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002053}
2054
2055/**
2056 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
2057 * @hw: pointer to hardware structure
2058 * @data: data byte clocked out
2059 *
2060 * Clocks out one byte data via I2C data/clock
2061 **/
2062static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
2063{
Mark Rustade90dd262014-07-22 06:51:08 +00002064 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002065 s32 i;
2066 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002067 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002068
2069 for (i = 7; i >= 0; i--) {
2070 bit = (data >> i) & 0x1;
2071 status = ixgbe_clock_out_i2c_bit(hw, bit);
2072
2073 if (status != 0)
2074 break;
2075 }
2076
2077 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002078 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2079 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002080 i2cctl |= IXGBE_I2C_DATA_OE_N_EN(hw);
Don Skidmore9a900ec2015-06-09 17:15:01 -07002081 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00002082 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002083
2084 return status;
2085}
2086
2087/**
2088 * ixgbe_get_i2c_ack - Polls for I2C ACK
2089 * @hw: pointer to hardware structure
2090 *
2091 * Clocks in/out one bit via I2C data/clock
2092 **/
2093static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
2094{
Mark Rustad25b10292015-08-08 16:18:12 -07002095 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
Emil Tantilove1befd72011-08-27 07:18:47 +00002096 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002097 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002098 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002099 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002100 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002101
Mark Rustad25b10292015-08-08 16:18:12 -07002102 if (data_oe_bit) {
2103 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
2104 i2cctl |= data_oe_bit;
2105 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2106 IXGBE_WRITE_FLUSH(hw);
2107 }
Emil Tantilove1befd72011-08-27 07:18:47 +00002108 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002109
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002110 /* Minimum high period of clock is 4us */
2111 udelay(IXGBE_I2C_T_HIGH);
2112
2113 /* Poll for ACK. Note that ACK in I2C spec is
2114 * transition from 1 to 0 */
2115 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002116 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002117 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002118
2119 udelay(1);
2120 if (ack == 0)
2121 break;
2122 }
2123
2124 if (ack == 1) {
2125 hw_dbg(hw, "I2C ack was not received.\n");
2126 status = IXGBE_ERR_I2C;
2127 }
2128
2129 ixgbe_lower_i2c_clk(hw, &i2cctl);
2130
2131 /* Minimum low period of clock is 4.7 us */
2132 udelay(IXGBE_I2C_T_LOW);
2133
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002134 return status;
2135}
2136
2137/**
2138 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
2139 * @hw: pointer to hardware structure
2140 * @data: read data value
2141 *
2142 * Clocks in one bit via I2C data/clock
2143 **/
2144static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
2145{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002146 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Mark Rustad25b10292015-08-08 16:18:12 -07002147 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002148
Mark Rustad25b10292015-08-08 16:18:12 -07002149 if (data_oe_bit) {
2150 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
2151 i2cctl |= data_oe_bit;
2152 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2153 IXGBE_WRITE_FLUSH(hw);
2154 }
Emil Tantilove1befd72011-08-27 07:18:47 +00002155 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002156
2157 /* Minimum high period of clock is 4us */
2158 udelay(IXGBE_I2C_T_HIGH);
2159
Don Skidmore9a900ec2015-06-09 17:15:01 -07002160 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002161 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002162
2163 ixgbe_lower_i2c_clk(hw, &i2cctl);
2164
2165 /* Minimum low period of clock is 4.7 us */
2166 udelay(IXGBE_I2C_T_LOW);
2167
Emil Tantilove1befd72011-08-27 07:18:47 +00002168 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002169}
2170
2171/**
2172 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
2173 * @hw: pointer to hardware structure
2174 * @data: data value to write
2175 *
2176 * Clocks out one bit via I2C data/clock
2177 **/
2178static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
2179{
2180 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002181 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002182
2183 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
2184 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00002185 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002186
2187 /* Minimum high period of clock is 4us */
2188 udelay(IXGBE_I2C_T_HIGH);
2189
2190 ixgbe_lower_i2c_clk(hw, &i2cctl);
2191
2192 /* Minimum low period of clock is 4.7 us.
2193 * This also takes care of the data hold time.
2194 */
2195 udelay(IXGBE_I2C_T_LOW);
2196 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002197 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002198 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002199 }
2200
Mark Rustade90dd262014-07-22 06:51:08 +00002201 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002202}
2203/**
2204 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2205 * @hw: pointer to hardware structure
2206 * @i2cctl: Current value of I2CCTL register
2207 *
2208 * Raises the I2C clock line '0'->'1'
Mark Rustad25b10292015-08-08 16:18:12 -07002209 * Negates the I2C clock output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002210 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002211static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002212{
Mark Rustad25b10292015-08-08 16:18:12 -07002213 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002214 u32 i = 0;
2215 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2216 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002217
Mark Rustad25b10292015-08-08 16:18:12 -07002218 if (clk_oe_bit) {
2219 *i2cctl |= clk_oe_bit;
2220 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2221 }
2222
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002223 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002224 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2225 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002226 IXGBE_WRITE_FLUSH(hw);
2227 /* SCL rise time (1000ns) */
2228 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002229
Don Skidmore9a900ec2015-06-09 17:15:01 -07002230 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2231 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002232 break;
2233 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002234}
2235
2236/**
2237 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2238 * @hw: pointer to hardware structure
2239 * @i2cctl: Current value of I2CCTL register
2240 *
2241 * Lowers the I2C clock line '1'->'0'
Mark Rustad25b10292015-08-08 16:18:12 -07002242 * Asserts the I2C clock output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002243 **/
2244static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2245{
2246
Don Skidmore9a900ec2015-06-09 17:15:01 -07002247 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002248 *i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002249
Don Skidmore9a900ec2015-06-09 17:15:01 -07002250 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002251 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002252
2253 /* SCL fall time (300ns) */
2254 udelay(IXGBE_I2C_T_FALL);
2255}
2256
2257/**
2258 * ixgbe_set_i2c_data - Sets the I2C data bit
2259 * @hw: pointer to hardware structure
2260 * @i2cctl: Current value of I2CCTL register
2261 * @data: I2C data value (0 or 1) to set
2262 *
2263 * Sets the I2C data bit
Mark Rustad25b10292015-08-08 16:18:12 -07002264 * Asserts the I2C data output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002265 **/
2266static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2267{
Mark Rustad25b10292015-08-08 16:18:12 -07002268 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
2269
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002270 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002271 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002272 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002273 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002274 *i2cctl &= ~data_oe_bit;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002275
Don Skidmore9a900ec2015-06-09 17:15:01 -07002276 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002277 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002278
2279 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2280 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2281
Mark Rustad25b10292015-08-08 16:18:12 -07002282 if (!data) /* Can't verify data in this case */
2283 return 0;
2284 if (data_oe_bit) {
2285 *i2cctl |= data_oe_bit;
2286 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2287 IXGBE_WRITE_FLUSH(hw);
2288 }
2289
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002290 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002291 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002292 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002293 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002294 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002295 }
2296
Mark Rustade90dd262014-07-22 06:51:08 +00002297 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002298}
2299
2300/**
2301 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2302 * @hw: pointer to hardware structure
2303 * @i2cctl: Current value of I2CCTL register
2304 *
2305 * Returns the I2C data bit value
Mark Rustad25b10292015-08-08 16:18:12 -07002306 * Negates the I2C data output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002307 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002308static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002309{
Mark Rustad25b10292015-08-08 16:18:12 -07002310 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
2311
2312 if (data_oe_bit) {
2313 *i2cctl |= data_oe_bit;
2314 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2315 IXGBE_WRITE_FLUSH(hw);
2316 udelay(IXGBE_I2C_T_FALL);
2317 }
2318
Don Skidmore9a900ec2015-06-09 17:15:01 -07002319 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002320 return true;
2321 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002322}
2323
2324/**
2325 * ixgbe_i2c_bus_clear - Clears the I2C bus
2326 * @hw: pointer to hardware structure
2327 *
2328 * Clears the I2C bus by sending nine clock pulses.
2329 * Used when data line is stuck low.
2330 **/
2331static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2332{
Mark Rustad25b10292015-08-08 16:18:12 -07002333 u32 i2cctl;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002334 u32 i;
2335
Emil Tantilov75f19c32011-02-19 08:43:55 +00002336 ixgbe_i2c_start(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002337 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Emil Tantilov75f19c32011-02-19 08:43:55 +00002338
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002339 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2340
2341 for (i = 0; i < 9; i++) {
2342 ixgbe_raise_i2c_clk(hw, &i2cctl);
2343
2344 /* Min high period of clock is 4us */
2345 udelay(IXGBE_I2C_T_HIGH);
2346
2347 ixgbe_lower_i2c_clk(hw, &i2cctl);
2348
2349 /* Min low period of clock is 4.7us*/
2350 udelay(IXGBE_I2C_T_LOW);
2351 }
2352
Emil Tantilov75f19c32011-02-19 08:43:55 +00002353 ixgbe_i2c_start(hw);
2354
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002355 /* Put the i2c bus back to default state */
2356 ixgbe_i2c_stop(hw);
2357}
2358
2359/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002360 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002361 * @hw: pointer to hardware structure
2362 *
2363 * Checks if the LASI temp alarm status was triggered due to overtemp
2364 **/
2365s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2366{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002367 u16 phy_data = 0;
2368
2369 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002370 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002371
2372 /* Check that the LASI temp alarm status was triggered */
2373 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002374 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002375
2376 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002377 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002378
Mark Rustade90dd262014-07-22 06:51:08 +00002379 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002380}
Don Skidmore961fac82015-06-09 16:09:47 -07002381
2382/** ixgbe_set_copper_phy_power - Control power for copper phy
2383 * @hw: pointer to hardware structure
2384 * @on: true for on, false for off
2385 **/
2386s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2387{
2388 u32 status;
2389 u16 reg;
2390
2391 /* Bail if we don't have copper phy */
2392 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2393 return 0;
2394
Mark Rustad3c2f2b72015-11-05 11:02:14 -08002395 if (!on && ixgbe_mng_present(hw))
2396 return 0;
2397
Emil Tantilov4dc40002016-09-26 14:08:13 -07002398 status = hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, &reg);
Don Skidmore961fac82015-06-09 16:09:47 -07002399 if (status)
2400 return status;
2401
2402 if (on) {
2403 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2404 } else {
2405 if (ixgbe_check_reset_blocked(hw))
2406 return 0;
2407 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2408 }
2409
Emil Tantilov4dc40002016-09-26 14:08:13 -07002410 status = hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, reg);
Don Skidmore961fac82015-06-09 16:09:47 -07002411 return status;
2412}