blob: 47ac0bc6b98a948c1fa6aa3bea52bc2a963db4bf [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/**
103 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
104 * @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
108 *
109 * Returns an error code on error.
110 **/
111s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
112 u16 reg, u16 *val)
113{
114 u32 swfw_mask = hw->phy.phy_semaphore_mask;
115 int max_retry = 10;
116 int retry = 0;
117 u8 csum_byte;
118 u8 high_bits;
119 u8 low_bits;
120 u8 reg_high;
121 u8 csum;
122
123 reg_high = ((reg >> 7) & 0xFE) | 1; /* Indicate read combined */
124 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
125 csum = ~csum;
126 do {
127 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
128 return IXGBE_ERR_SWFW_SYNC;
129 ixgbe_i2c_start(hw);
130 /* Device Address and write indication */
131 if (ixgbe_out_i2c_byte_ack(hw, addr))
132 goto fail;
133 /* Write bits 14:8 */
134 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
135 goto fail;
136 /* Write bits 7:0 */
137 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
138 goto fail;
139 /* Write csum */
140 if (ixgbe_out_i2c_byte_ack(hw, csum))
141 goto fail;
142 /* Re-start condition */
143 ixgbe_i2c_start(hw);
144 /* Device Address and read indication */
145 if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
146 goto fail;
147 /* Get upper bits */
148 if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
149 goto fail;
150 /* Get low bits */
151 if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
152 goto fail;
153 /* Get csum */
154 if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
155 goto fail;
156 /* NACK */
157 if (ixgbe_clock_out_i2c_bit(hw, false))
158 goto fail;
159 ixgbe_i2c_stop(hw);
160 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
161 *val = (high_bits << 8) | low_bits;
162 return 0;
163
164fail:
165 ixgbe_i2c_bus_clear(hw);
166 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
167 retry++;
168 if (retry < max_retry)
169 hw_dbg(hw, "I2C byte read combined error - Retry.\n");
170 else
171 hw_dbg(hw, "I2C byte read combined error.\n");
172 } while (retry < max_retry);
173
174 return IXGBE_ERR_I2C;
175}
176
177/**
178 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
179 * @hw: pointer to the hardware structure
180 * @addr: I2C bus address to write to
181 * @reg: I2C device register to write to
182 * @val: value to write
183 *
184 * Returns an error code on error.
185 **/
186s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
187 u8 addr, u16 reg, u16 val)
188{
189 int max_retry = 1;
190 int retry = 0;
191 u8 reg_high;
192 u8 csum;
193
194 reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
195 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
196 csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
197 csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
198 csum = ~csum;
199 do {
200 ixgbe_i2c_start(hw);
201 /* Device Address and write indication */
202 if (ixgbe_out_i2c_byte_ack(hw, addr))
203 goto fail;
204 /* Write bits 14:8 */
205 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
206 goto fail;
207 /* Write bits 7:0 */
208 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
209 goto fail;
210 /* Write data 15:8 */
211 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
212 goto fail;
213 /* Write data 7:0 */
214 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
215 goto fail;
216 /* Write csum */
217 if (ixgbe_out_i2c_byte_ack(hw, csum))
218 goto fail;
219 ixgbe_i2c_stop(hw);
220 return 0;
221
222fail:
223 ixgbe_i2c_bus_clear(hw);
224 retry++;
225 if (retry < max_retry)
226 hw_dbg(hw, "I2C byte write combined error - Retry.\n");
227 else
228 hw_dbg(hw, "I2C byte write combined error.\n");
229 } while (retry < max_retry);
230
231 return IXGBE_ERR_I2C;
232}
233
234/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700235 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -0700236 * @hw: pointer to hardware structure
237 *
238 * Determines the physical layer module found on the current adapter.
239 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700240s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700241{
Auke Kok9a799d72007-09-15 14:07:45 -0700242 u32 phy_addr;
Emil Tantilov037c6d02011-02-25 07:49:39 +0000243 u16 ext_ability = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700244
Don Skidmore030eaec2014-11-29 05:22:37 +0000245 if (!hw->phy.phy_semaphore_mask) {
246 hw->phy.lan_id = IXGBE_READ_REG(hw, IXGBE_STATUS) &
247 IXGBE_STATUS_LAN_ID_1;
248 if (hw->phy.lan_id)
249 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
250 else
251 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
252 }
253
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700254 if (hw->phy.type == ixgbe_phy_unknown) {
255 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +0000256 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +0000257 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700258 ixgbe_get_phy_id(hw);
259 hw->phy.type =
Jacob Kellere7cf7452014-04-09 06:03:10 +0000260 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +0000261
262 if (hw->phy.type == ixgbe_phy_unknown) {
263 hw->phy.ops.read_reg(hw,
264 MDIO_PMA_EXTABLE,
265 MDIO_MMD_PMAPMD,
266 &ext_ability);
267 if (ext_ability &
268 (MDIO_PMA_EXTABLE_10GBT |
269 MDIO_PMA_EXTABLE_1000BT))
270 hw->phy.type =
271 ixgbe_phy_cu_unknown;
272 else
273 hw->phy.type =
274 ixgbe_phy_generic;
275 }
276
Mark Rustade90dd262014-07-22 06:51:08 +0000277 return 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700278 }
Auke Kok9a799d72007-09-15 14:07:45 -0700279 }
Don Skidmore63d6e1d2009-07-02 12:50:12 +0000280 /* clear value if nothing found */
Mark Rustade90dd262014-07-22 06:51:08 +0000281 hw->phy.mdio.prtad = 0;
282 return IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700283 }
Mark Rustade90dd262014-07-22 06:51:08 +0000284 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700285}
286
287/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800288 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
289 * @hw: pointer to the hardware structure
290 *
291 * This function checks the MMNGC.MNG_VETO bit to see if there are
292 * any constraints on link from manageability. For MAC's that don't
293 * have this bit just return false since the link can not be blocked
294 * via this method.
295 **/
Jean Sacren6425f0f2014-03-11 05:57:56 +0000296bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
Don Skidmorec97506a2014-02-27 20:32:43 -0800297{
298 u32 mmngc;
299
300 /* If we don't have this bit, it can't be blocking */
301 if (hw->mac.type == ixgbe_mac_82598EB)
302 return false;
303
304 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
305 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
306 hw_dbg(hw, "MNG_VETO bit detected.\n");
307 return true;
308 }
309
310 return false;
311}
312
313/**
Auke Kok9a799d72007-09-15 14:07:45 -0700314 * ixgbe_get_phy_id - Get the phy type
315 * @hw: pointer to hardware structure
316 *
317 **/
318static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
319{
Mark Rustada1e869d2015-04-10 10:36:36 -0700320 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700321 u16 phy_id_high = 0;
322 u16 phy_id_low = 0;
323
Ben Hutchings6b73e102009-04-29 08:08:58 +0000324 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000325 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700326
Mark Rustada1e869d2015-04-10 10:36:36 -0700327 if (!status) {
Auke Kok9a799d72007-09-15 14:07:45 -0700328 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000329 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000330 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700331 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
332 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
333 }
Auke Kok9a799d72007-09-15 14:07:45 -0700334 return status;
335}
336
337/**
338 * ixgbe_get_phy_type_from_id - Get the phy type
339 * @hw: pointer to hardware structure
340 *
341 **/
342static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
343{
344 enum ixgbe_phy_type phy_type;
345
346 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700347 case TN1010_PHY_ID:
348 phy_type = ixgbe_phy_tn;
349 break;
Don Skidmore2b264902010-12-09 06:55:14 +0000350 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800351 phy_type = ixgbe_phy_aq;
352 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700353 case QT2022_PHY_ID:
354 phy_type = ixgbe_phy_qt;
355 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800356 case ATH_PHY_ID:
357 phy_type = ixgbe_phy_nl;
358 break;
Don Skidmorec2c78d52015-06-09 16:04:59 -0700359 case X557_PHY_ID:
360 phy_type = ixgbe_phy_x550em_ext_t;
361 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700362 default:
363 phy_type = ixgbe_phy_unknown;
364 break;
365 }
366
367 return phy_type;
368}
369
370/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700371 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700372 * @hw: pointer to hardware structure
373 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700374s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700375{
Emil Tantilov17835752011-02-16 01:38:13 +0000376 u32 i;
377 u16 ctrl = 0;
378 s32 status = 0;
379
380 if (hw->phy.type == ixgbe_phy_unknown)
381 status = ixgbe_identify_phy_generic(hw);
382
383 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000384 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000385
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700386 /* Don't reset PHY if it's shut down due to overtemp. */
387 if (!hw->phy.reset_if_overtemp &&
388 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000389 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700390
Don Skidmorec97506a2014-02-27 20:32:43 -0800391 /* Blocked by MNG FW so bail */
392 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000393 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800394
Auke Kok9a799d72007-09-15 14:07:45 -0700395 /*
396 * Perform soft PHY reset to the PHY_XS.
397 * This will cause a soft reset to the PHY
398 */
Emil Tantilov17835752011-02-16 01:38:13 +0000399 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
400 MDIO_MMD_PHYXS,
401 MDIO_CTRL1_RESET);
402
403 /*
404 * Poll for reset bit to self-clear indicating reset is complete.
405 * Some PHYs could take up to 3 seconds to complete and need about
406 * 1.7 usec delay after the reset is complete.
407 */
408 for (i = 0; i < 30; i++) {
409 msleep(100);
410 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
411 MDIO_MMD_PHYXS, &ctrl);
412 if (!(ctrl & MDIO_CTRL1_RESET)) {
413 udelay(2);
414 break;
415 }
416 }
417
418 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000419 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000420 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000421 }
422
Mark Rustade90dd262014-07-22 06:51:08 +0000423 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700424}
425
426/**
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000427 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
428 * the SWFW lock
429 * @hw: pointer to hardware structure
430 * @reg_addr: 32 bit address of PHY register to read
431 * @phy_data: Pointer to read data from PHY register
432 **/
433s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
434 u16 *phy_data)
435{
436 u32 i, data, command;
437
438 /* Setup and write the address cycle command */
439 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
440 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
441 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
442 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
443
444 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
445
446 /* Check every 10 usec to see if the address cycle completed.
447 * The MDI Command bit will clear when the operation is
448 * complete
449 */
450 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
451 udelay(10);
452
453 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
454 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
455 break;
456 }
457
458
459 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
460 hw_dbg(hw, "PHY address command did not complete.\n");
461 return IXGBE_ERR_PHY;
462 }
463
464 /* Address cycle complete, setup and write the read
465 * command
466 */
467 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
468 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
469 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
470 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
471
472 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
473
474 /* Check every 10 usec to see if the address cycle
475 * completed. The MDI Command bit will clear when the
476 * operation is complete
477 */
478 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
479 udelay(10);
480
481 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
482 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
483 break;
484 }
485
486 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
487 hw_dbg(hw, "PHY read command didn't complete\n");
488 return IXGBE_ERR_PHY;
489 }
490
491 /* Read operation is complete. Get the data
492 * from MSRWD
493 */
494 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
495 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
496 *phy_data = (u16)(data);
497
498 return 0;
499}
500
501/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700502 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000503 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700504 * @hw: pointer to hardware structure
505 * @reg_addr: 32 bit address of PHY register to read
506 * @phy_data: Pointer to read data from PHY register
507 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700508s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000509 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700510{
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000511 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000512 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700513
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000514 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
515 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
516 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000517 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000518 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000519 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700520 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700521
Auke Kok9a799d72007-09-15 14:07:45 -0700522 return status;
523}
524
525/**
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000526 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
527 * without SWFW lock
528 * @hw: pointer to hardware structure
529 * @reg_addr: 32 bit PHY register to write
530 * @device_type: 5 bit device type
531 * @phy_data: Data to write to the PHY register
532 **/
533s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
534 u32 device_type, u16 phy_data)
535{
536 u32 i, command;
537
538 /* Put the data in the MDI single read and write data register*/
539 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
540
541 /* Setup and write the address cycle command */
542 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
543 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
544 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
545 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
546
547 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
548
549 /*
550 * Check every 10 usec to see if the address cycle completed.
551 * The MDI Command bit will clear when the operation is
552 * complete
553 */
554 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
555 udelay(10);
556
557 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
558 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
559 break;
560 }
561
562 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
563 hw_dbg(hw, "PHY address cmd didn't complete\n");
564 return IXGBE_ERR_PHY;
565 }
566
567 /*
568 * Address cycle complete, setup and write the write
569 * command
570 */
571 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
572 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
573 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
574 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
575
576 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
577
578 /* Check every 10 usec to see if the address cycle
579 * completed. The MDI Command bit will clear when the
580 * operation is complete
581 */
582 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
583 udelay(10);
584
585 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
586 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
587 break;
588 }
589
590 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
591 hw_dbg(hw, "PHY write cmd didn't complete\n");
592 return IXGBE_ERR_PHY;
593 }
594
595 return 0;
596}
597
598/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700599 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000600 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700601 * @hw: pointer to hardware structure
602 * @reg_addr: 32 bit PHY register to write
603 * @device_type: 5 bit device type
604 * @phy_data: Data to write to the PHY register
605 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700606s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000607 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700608{
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000609 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000610 u32 gssr;
Auke Kok9a799d72007-09-15 14:07:45 -0700611
612 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
613 gssr = IXGBE_GSSR_PHY1_SM;
614 else
615 gssr = IXGBE_GSSR_PHY0_SM;
616
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000617 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
618 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
619 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000620 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000621 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000622 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700623 }
624
625 return status;
626}
627
628/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700629 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700630 * @hw: pointer to hardware structure
631 *
632 * Restart autonegotiation and PHY and waits for completion.
633 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700634s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700635{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000636 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000637 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
638 bool autoneg = false;
639 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700640
Emil Tantilov9dda1732011-03-05 01:28:07 +0000641 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700642
Emil Tantilov9dda1732011-03-05 01:28:07 +0000643 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
644 /* Set or unset auto-negotiation 10G advertisement */
645 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
646 MDIO_MMD_AN,
647 &autoneg_reg);
648
Ben Hutchings6b73e102009-04-29 08:08:58 +0000649 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000650 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
651 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700652
Emil Tantilov9dda1732011-03-05 01:28:07 +0000653 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
654 MDIO_MMD_AN,
655 autoneg_reg);
656 }
657
658 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
659 /* Set or unset auto-negotiation 1G advertisement */
660 hw->phy.ops.read_reg(hw,
661 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
662 MDIO_MMD_AN,
663 &autoneg_reg);
664
665 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
666 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
667 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
668
669 hw->phy.ops.write_reg(hw,
670 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
671 MDIO_MMD_AN,
672 autoneg_reg);
673 }
674
675 if (speed & IXGBE_LINK_SPEED_100_FULL) {
676 /* Set or unset auto-negotiation 100M advertisement */
677 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
678 MDIO_MMD_AN,
679 &autoneg_reg);
680
Emil Tantilova59e8a12011-03-31 09:36:12 +0000681 autoneg_reg &= ~(ADVERTISE_100FULL |
682 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000683 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
684 autoneg_reg |= ADVERTISE_100FULL;
685
686 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
687 MDIO_MMD_AN,
688 autoneg_reg);
689 }
Auke Kok9a799d72007-09-15 14:07:45 -0700690
Don Skidmorec97506a2014-02-27 20:32:43 -0800691 /* Blocked by MNG FW so don't reset PHY */
692 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000693 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800694
Auke Kok9a799d72007-09-15 14:07:45 -0700695 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000696 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
697 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700698
Ben Hutchings6b73e102009-04-29 08:08:58 +0000699 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700700
Emil Tantilov9dda1732011-03-05 01:28:07 +0000701 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
702 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700703
Auke Kok9a799d72007-09-15 14:07:45 -0700704 return status;
705}
706
707/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700708 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700709 * @hw: pointer to hardware structure
710 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700711 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700712s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000713 ixgbe_link_speed speed,
714 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700715{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700716
Auke Kok9a799d72007-09-15 14:07:45 -0700717 /*
718 * Clear autoneg_advertised and set new values based on input link
719 * speed.
720 */
721 hw->phy.autoneg_advertised = 0;
722
723 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
724 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700725
Auke Kok9a799d72007-09-15 14:07:45 -0700726 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
727 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
728
Emil Tantilov9dda1732011-03-05 01:28:07 +0000729 if (speed & IXGBE_LINK_SPEED_100_FULL)
730 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
731
Auke Kok9a799d72007-09-15 14:07:45 -0700732 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700733 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700734
735 return 0;
736}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700737
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700738/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800739 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
740 * @hw: pointer to hardware structure
741 * @speed: pointer to link speed
742 * @autoneg: boolean auto-negotiation value
743 *
744 * Determines the link capabilities by reading the AUTOC register.
745 */
746s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000747 ixgbe_link_speed *speed,
748 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800749{
Mark Rustade90dd262014-07-22 06:51:08 +0000750 s32 status;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800751 u16 speed_ability;
752
753 *speed = 0;
754 *autoneg = true;
755
756 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000757 &speed_ability);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800758
759 if (status == 0) {
760 if (speed_ability & MDIO_SPEED_10G)
761 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
762 if (speed_ability & MDIO_PMA_SPEED_1000)
763 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
764 if (speed_ability & MDIO_PMA_SPEED_100)
765 *speed |= IXGBE_LINK_SPEED_100_FULL;
766 }
767
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000768 /* Internal PHY does not support 100 Mbps */
769 if (hw->mac.type == ixgbe_mac_X550EM_x)
770 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
771
Don Skidmorea391f1d2010-11-16 19:27:15 -0800772 return status;
773}
774
775/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000776 * ixgbe_check_phy_link_tnx - Determine link and speed status
777 * @hw: pointer to hardware structure
778 *
779 * Reads the VS1 register to determine if link is up and the current speed for
780 * the PHY.
781 **/
782s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
783 bool *link_up)
784{
Mark Rustade90dd262014-07-22 06:51:08 +0000785 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000786 u32 time_out;
787 u32 max_time_out = 10;
788 u16 phy_link = 0;
789 u16 phy_speed = 0;
790 u16 phy_data = 0;
791
792 /* Initialize speed and link to default case */
793 *link_up = false;
794 *speed = IXGBE_LINK_SPEED_10GB_FULL;
795
796 /*
797 * Check current speed and link status of the PHY register.
798 * This is a vendor specific register and may have to
799 * be changed for other copper PHYs.
800 */
801 for (time_out = 0; time_out < max_time_out; time_out++) {
802 udelay(10);
803 status = hw->phy.ops.read_reg(hw,
804 MDIO_STAT1,
805 MDIO_MMD_VEND1,
806 &phy_data);
807 phy_link = phy_data &
808 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
809 phy_speed = phy_data &
810 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
811 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
812 *link_up = true;
813 if (phy_speed ==
814 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
815 *speed = IXGBE_LINK_SPEED_1GB_FULL;
816 break;
817 }
818 }
819
820 return status;
821}
822
823/**
824 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
825 * @hw: pointer to hardware structure
826 *
827 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000828 * This function always returns success, this is nessary since
829 * it is called via a function pointer that could call other
830 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000831 **/
832s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
833{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000834 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
835 bool autoneg = false;
836 ixgbe_link_speed speed;
837
838 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
839
840 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
841 /* Set or unset auto-negotiation 10G advertisement */
842 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
843 MDIO_MMD_AN,
844 &autoneg_reg);
845
846 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
847 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
848 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
849
850 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
851 MDIO_MMD_AN,
852 autoneg_reg);
853 }
854
855 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
856 /* Set or unset auto-negotiation 1G advertisement */
857 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
858 MDIO_MMD_AN,
859 &autoneg_reg);
860
861 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
862 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
863 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
864
865 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
866 MDIO_MMD_AN,
867 autoneg_reg);
868 }
869
870 if (speed & IXGBE_LINK_SPEED_100_FULL) {
871 /* Set or unset auto-negotiation 100M advertisement */
872 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
873 MDIO_MMD_AN,
874 &autoneg_reg);
875
Emil Tantilov50c022e2011-03-31 09:36:12 +0000876 autoneg_reg &= ~(ADVERTISE_100FULL |
877 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000878 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
879 autoneg_reg |= ADVERTISE_100FULL;
880
881 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
882 MDIO_MMD_AN,
883 autoneg_reg);
884 }
885
Don Skidmorec97506a2014-02-27 20:32:43 -0800886 /* Blocked by MNG FW so don't reset PHY */
887 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000888 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800889
Emil Tantilov9dda1732011-03-05 01:28:07 +0000890 /* Restart PHY autonegotiation and wait for completion */
891 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
892 MDIO_MMD_AN, &autoneg_reg);
893
894 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
895
896 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
897 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000898 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000899}
900
901/**
902 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
903 * @hw: pointer to hardware structure
904 * @firmware_version: pointer to the PHY Firmware Version
905 **/
906s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
907 u16 *firmware_version)
908{
Mark Rustade90dd262014-07-22 06:51:08 +0000909 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000910
911 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
912 MDIO_MMD_VEND1,
913 firmware_version);
914
915 return status;
916}
917
918/**
919 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
920 * @hw: pointer to hardware structure
921 * @firmware_version: pointer to the PHY Firmware Version
922 **/
923s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
924 u16 *firmware_version)
925{
Mark Rustade90dd262014-07-22 06:51:08 +0000926 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000927
928 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
929 MDIO_MMD_VEND1,
930 firmware_version);
931
932 return status;
933}
934
935/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800936 * ixgbe_reset_phy_nl - Performs a PHY reset
937 * @hw: pointer to hardware structure
938 **/
939s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
940{
941 u16 phy_offset, control, eword, edata, block_crc;
942 bool end_data = false;
943 u16 list_offset, data_offset;
944 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000945 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800946 u32 i;
947
Don Skidmorec97506a2014-02-27 20:32:43 -0800948 /* Blocked by MNG FW so bail */
949 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000950 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800951
Ben Hutchings6b73e102009-04-29 08:08:58 +0000952 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800953
954 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000955 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000956 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800957
958 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000959 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000960 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000961 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800962 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000963 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800964 }
965
Ben Hutchings6b73e102009-04-29 08:08:58 +0000966 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800967 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000968 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800969 }
970
971 /* Get init offsets */
972 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000973 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000974 if (ret_val)
975 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800976
977 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
978 data_offset++;
979 while (!end_data) {
980 /*
981 * Read control word from PHY init contents offset
982 */
983 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000984 if (ret_val)
985 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800986 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +0000987 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800988 edata = eword & IXGBE_DATA_MASK_NL;
989 switch (control) {
990 case IXGBE_DELAY_NL:
991 data_offset++;
992 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000993 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800994 break;
995 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000996 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800997 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000998 ret_val = hw->eeprom.ops.read(hw, data_offset++,
999 &phy_offset);
1000 if (ret_val)
1001 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001002 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001003 ret_val = hw->eeprom.ops.read(hw, data_offset,
1004 &eword);
1005 if (ret_val)
1006 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001007 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001008 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001009 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1010 phy_offset);
1011 data_offset++;
1012 phy_offset++;
1013 }
1014 break;
1015 case IXGBE_CONTROL_NL:
1016 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001017 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001018 if (edata == IXGBE_CONTROL_EOL_NL) {
1019 hw_dbg(hw, "EOL\n");
1020 end_data = true;
1021 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1022 hw_dbg(hw, "SOL\n");
1023 } else {
1024 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001025 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001026 }
1027 break;
1028 default:
1029 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001030 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001031 }
1032 }
1033
Donald Skidmorec4900be2008-11-20 21:11:42 -08001034 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001035
1036err_eeprom:
1037 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1038 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001039}
1040
1041/**
Don Skidmore8f583322013-07-27 06:25:38 +00001042 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001043 * @hw: pointer to hardware structure
1044 *
Don Skidmore8f583322013-07-27 06:25:38 +00001045 * Determines HW type and calls appropriate function.
1046 **/
1047s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1048{
Don Skidmore8f583322013-07-27 06:25:38 +00001049 switch (hw->mac.ops.get_media_type(hw)) {
1050 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001051 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001052 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001053 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001054 default:
1055 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001056 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001057 }
1058
Mark Rustade90dd262014-07-22 06:51:08 +00001059 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001060}
1061
1062/**
1063 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1064 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001065 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001066 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001067 **/
1068s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1069{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001070 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001071 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001072 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001073 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001074 u8 identifier = 0;
1075 u8 comp_codes_1g = 0;
1076 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001077 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001078 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001079 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001080 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001081
Don Skidmore8ca783a2009-05-26 20:40:47 -07001082 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1083 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001084 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001085 }
1086
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001087 status = hw->phy.ops.read_i2c_eeprom(hw,
1088 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001089 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001090
Mark Rustade90dd262014-07-22 06:51:08 +00001091 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001092 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001093
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001094 /* LAN ID is needed for sfp_type determination */
1095 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001096
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001097 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1098 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001099 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1100 }
1101 status = hw->phy.ops.read_i2c_eeprom(hw,
1102 IXGBE_SFF_1GBE_COMP_CODES,
1103 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001104
Mark Rustade90dd262014-07-22 06:51:08 +00001105 if (status)
1106 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001107
Mark Rustade90dd262014-07-22 06:51:08 +00001108 status = hw->phy.ops.read_i2c_eeprom(hw,
1109 IXGBE_SFF_10GBE_COMP_CODES,
1110 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001111
Mark Rustade90dd262014-07-22 06:51:08 +00001112 if (status)
1113 goto err_read_i2c_eeprom;
1114 status = hw->phy.ops.read_i2c_eeprom(hw,
1115 IXGBE_SFF_CABLE_TECHNOLOGY,
1116 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001117
Mark Rustade90dd262014-07-22 06:51:08 +00001118 if (status)
1119 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001120
Mark Rustade90dd262014-07-22 06:51:08 +00001121 /* ID Module
1122 * =========
1123 * 0 SFP_DA_CU
1124 * 1 SFP_SR
1125 * 2 SFP_LR
1126 * 3 SFP_DA_CORE0 - 82599-specific
1127 * 4 SFP_DA_CORE1 - 82599-specific
1128 * 5 SFP_SR/LR_CORE0 - 82599-specific
1129 * 6 SFP_SR/LR_CORE1 - 82599-specific
1130 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1131 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1132 * 9 SFP_1g_cu_CORE0 - 82599-specific
1133 * 10 SFP_1g_cu_CORE1 - 82599-specific
1134 * 11 SFP_1g_sx_CORE0 - 82599-specific
1135 * 12 SFP_1g_sx_CORE1 - 82599-specific
1136 */
1137 if (hw->mac.type == ixgbe_mac_82598EB) {
1138 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1139 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1140 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1141 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1142 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1143 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1144 else
1145 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1146 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1147 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1148 if (hw->bus.lan_id == 0)
1149 hw->phy.sfp_type =
1150 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001151 else
Mark Rustade90dd262014-07-22 06:51:08 +00001152 hw->phy.sfp_type =
1153 ixgbe_sfp_type_da_cu_core1;
1154 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1155 hw->phy.ops.read_i2c_eeprom(
1156 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1157 &cable_spec);
1158 if (cable_spec &
1159 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001160 if (hw->bus.lan_id == 0)
1161 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001162 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001163 else
1164 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001165 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001166 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001167 hw->phy.sfp_type =
1168 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001169 }
Mark Rustade90dd262014-07-22 06:51:08 +00001170 } else if (comp_codes_10g &
1171 (IXGBE_SFF_10GBASESR_CAPABLE |
1172 IXGBE_SFF_10GBASELR_CAPABLE)) {
1173 if (hw->bus.lan_id == 0)
1174 hw->phy.sfp_type =
1175 ixgbe_sfp_type_srlr_core0;
1176 else
1177 hw->phy.sfp_type =
1178 ixgbe_sfp_type_srlr_core1;
1179 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1180 if (hw->bus.lan_id == 0)
1181 hw->phy.sfp_type =
1182 ixgbe_sfp_type_1g_cu_core0;
1183 else
1184 hw->phy.sfp_type =
1185 ixgbe_sfp_type_1g_cu_core1;
1186 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1187 if (hw->bus.lan_id == 0)
1188 hw->phy.sfp_type =
1189 ixgbe_sfp_type_1g_sx_core0;
1190 else
1191 hw->phy.sfp_type =
1192 ixgbe_sfp_type_1g_sx_core1;
1193 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1194 if (hw->bus.lan_id == 0)
1195 hw->phy.sfp_type =
1196 ixgbe_sfp_type_1g_lx_core0;
1197 else
1198 hw->phy.sfp_type =
1199 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001200 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001201 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001202 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001203 }
1204
Mark Rustade90dd262014-07-22 06:51:08 +00001205 if (hw->phy.sfp_type != stored_sfp_type)
1206 hw->phy.sfp_setup_needed = true;
1207
1208 /* Determine if the SFP+ PHY is dual speed or not. */
1209 hw->phy.multispeed_fiber = false;
1210 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1211 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1212 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1213 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1214 hw->phy.multispeed_fiber = true;
1215
1216 /* Determine PHY vendor */
1217 if (hw->phy.type != ixgbe_phy_nl) {
1218 hw->phy.id = identifier;
1219 status = hw->phy.ops.read_i2c_eeprom(hw,
1220 IXGBE_SFF_VENDOR_OUI_BYTE0,
1221 &oui_bytes[0]);
1222
1223 if (status != 0)
1224 goto err_read_i2c_eeprom;
1225
1226 status = hw->phy.ops.read_i2c_eeprom(hw,
1227 IXGBE_SFF_VENDOR_OUI_BYTE1,
1228 &oui_bytes[1]);
1229
1230 if (status != 0)
1231 goto err_read_i2c_eeprom;
1232
1233 status = hw->phy.ops.read_i2c_eeprom(hw,
1234 IXGBE_SFF_VENDOR_OUI_BYTE2,
1235 &oui_bytes[2]);
1236
1237 if (status != 0)
1238 goto err_read_i2c_eeprom;
1239
1240 vendor_oui =
1241 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1242 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1243 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1244
1245 switch (vendor_oui) {
1246 case IXGBE_SFF_VENDOR_OUI_TYCO:
1247 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1248 hw->phy.type =
1249 ixgbe_phy_sfp_passive_tyco;
1250 break;
1251 case IXGBE_SFF_VENDOR_OUI_FTL:
1252 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1253 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1254 else
1255 hw->phy.type = ixgbe_phy_sfp_ftl;
1256 break;
1257 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1258 hw->phy.type = ixgbe_phy_sfp_avago;
1259 break;
1260 case IXGBE_SFF_VENDOR_OUI_INTEL:
1261 hw->phy.type = ixgbe_phy_sfp_intel;
1262 break;
1263 default:
1264 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1265 hw->phy.type =
1266 ixgbe_phy_sfp_passive_unknown;
1267 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1268 hw->phy.type =
1269 ixgbe_phy_sfp_active_unknown;
1270 else
1271 hw->phy.type = ixgbe_phy_sfp_unknown;
1272 break;
1273 }
1274 }
1275
1276 /* Allow any DA cable vendor */
1277 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1278 IXGBE_SFF_DA_ACTIVE_CABLE))
1279 return 0;
1280
1281 /* Verify supported 1G SFP modules */
1282 if (comp_codes_10g == 0 &&
1283 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1284 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1285 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1286 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1287 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1288 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1289 hw->phy.type = ixgbe_phy_sfp_unsupported;
1290 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1291 }
1292
1293 /* Anything else 82598-based is supported */
1294 if (hw->mac.type == ixgbe_mac_82598EB)
1295 return 0;
1296
1297 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1298 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1299 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1300 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1301 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1302 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1303 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1304 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1305 /* Make sure we're a supported PHY type */
1306 if (hw->phy.type == ixgbe_phy_sfp_intel)
1307 return 0;
1308 if (hw->allow_unsupported_sfp) {
1309 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");
1310 return 0;
1311 }
1312 hw_dbg(hw, "SFP+ module not supported\n");
1313 hw->phy.type = ixgbe_phy_sfp_unsupported;
1314 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1315 }
1316 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001317
1318err_read_i2c_eeprom:
1319 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1320 if (hw->phy.type != ixgbe_phy_nl) {
1321 hw->phy.id = 0;
1322 hw->phy.type = ixgbe_phy_unknown;
1323 }
1324 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001325}
1326
1327/**
Don Skidmore8f583322013-07-27 06:25:38 +00001328 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1329 * @hw: pointer to hardware structure
1330 *
1331 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1332 **/
Mark Rustad88217542013-11-23 03:19:19 +00001333static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001334{
1335 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001336 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001337 u32 vendor_oui = 0;
1338 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1339 u8 identifier = 0;
1340 u8 comp_codes_1g = 0;
1341 u8 comp_codes_10g = 0;
1342 u8 oui_bytes[3] = {0, 0, 0};
1343 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001344 u8 connector = 0;
1345 u8 cable_length = 0;
1346 u8 device_tech = 0;
1347 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001348
1349 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1350 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001351 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001352 }
1353
1354 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1355 &identifier);
1356
1357 if (status != 0)
1358 goto err_read_i2c_eeprom;
1359
1360 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1361 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001362 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001363 }
1364
1365 hw->phy.id = identifier;
1366
1367 /* LAN ID is needed for sfp_type determination */
1368 hw->mac.ops.set_lan_id(hw);
1369
1370 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1371 &comp_codes_10g);
1372
1373 if (status != 0)
1374 goto err_read_i2c_eeprom;
1375
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001376 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1377 &comp_codes_1g);
1378
1379 if (status != 0)
1380 goto err_read_i2c_eeprom;
1381
Don Skidmore8f583322013-07-27 06:25:38 +00001382 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1383 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1384 if (hw->bus.lan_id == 0)
1385 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1386 else
1387 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001388 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1389 IXGBE_SFF_10GBASELR_CAPABLE)) {
1390 if (hw->bus.lan_id == 0)
1391 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1392 else
1393 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1394 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001395 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1396 active_cable = true;
1397
1398 if (!active_cable) {
1399 /* check for active DA cables that pre-date
1400 * SFF-8436 v3.6
1401 */
1402 hw->phy.ops.read_i2c_eeprom(hw,
1403 IXGBE_SFF_QSFP_CONNECTOR,
1404 &connector);
1405
1406 hw->phy.ops.read_i2c_eeprom(hw,
1407 IXGBE_SFF_QSFP_CABLE_LENGTH,
1408 &cable_length);
1409
1410 hw->phy.ops.read_i2c_eeprom(hw,
1411 IXGBE_SFF_QSFP_DEVICE_TECH,
1412 &device_tech);
1413
1414 if ((connector ==
1415 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1416 (cable_length > 0) &&
1417 ((device_tech >> 4) ==
1418 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1419 active_cable = true;
1420 }
1421
1422 if (active_cable) {
1423 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1424 if (hw->bus.lan_id == 0)
1425 hw->phy.sfp_type =
1426 ixgbe_sfp_type_da_act_lmt_core0;
1427 else
1428 hw->phy.sfp_type =
1429 ixgbe_sfp_type_da_act_lmt_core1;
1430 } else {
1431 /* unsupported module type */
1432 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001433 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001434 }
Don Skidmore8f583322013-07-27 06:25:38 +00001435 }
1436
1437 if (hw->phy.sfp_type != stored_sfp_type)
1438 hw->phy.sfp_setup_needed = true;
1439
1440 /* Determine if the QSFP+ PHY is dual speed or not. */
1441 hw->phy.multispeed_fiber = false;
1442 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1443 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1444 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1445 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1446 hw->phy.multispeed_fiber = true;
1447
1448 /* Determine PHY vendor for optical modules */
1449 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1450 IXGBE_SFF_10GBASELR_CAPABLE)) {
1451 status = hw->phy.ops.read_i2c_eeprom(hw,
1452 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1453 &oui_bytes[0]);
1454
1455 if (status != 0)
1456 goto err_read_i2c_eeprom;
1457
1458 status = hw->phy.ops.read_i2c_eeprom(hw,
1459 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1460 &oui_bytes[1]);
1461
1462 if (status != 0)
1463 goto err_read_i2c_eeprom;
1464
1465 status = hw->phy.ops.read_i2c_eeprom(hw,
1466 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1467 &oui_bytes[2]);
1468
1469 if (status != 0)
1470 goto err_read_i2c_eeprom;
1471
1472 vendor_oui =
1473 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1474 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1475 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1476
1477 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1478 hw->phy.type = ixgbe_phy_qsfp_intel;
1479 else
1480 hw->phy.type = ixgbe_phy_qsfp_unknown;
1481
1482 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1483 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1484 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001485 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1486 return 0;
1487 if (hw->allow_unsupported_sfp) {
1488 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");
1489 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001490 }
Mark Rustade90dd262014-07-22 06:51:08 +00001491 hw_dbg(hw, "QSFP module not supported\n");
1492 hw->phy.type = ixgbe_phy_sfp_unsupported;
1493 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001494 }
Mark Rustade90dd262014-07-22 06:51:08 +00001495 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001496 }
Mark Rustade90dd262014-07-22 06:51:08 +00001497 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001498
1499err_read_i2c_eeprom:
1500 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1501 hw->phy.id = 0;
1502 hw->phy.type = ixgbe_phy_unknown;
1503
1504 return IXGBE_ERR_SFP_NOT_PRESENT;
1505}
1506
1507/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001508 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001509 * @hw: pointer to hardware structure
1510 * @list_offset: offset to the SFP ID list
1511 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001512 *
1513 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1514 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001515 **/
1516s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001517 u16 *list_offset,
1518 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001519{
1520 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001521 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001522
1523 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1524 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1525
1526 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1527 return IXGBE_ERR_SFP_NOT_PRESENT;
1528
1529 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1530 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1531 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1532
Don Skidmorecb836a92010-06-29 18:30:59 +00001533 /*
1534 * Limiting active cables and 1G Phys must be initialized as
1535 * SR modules
1536 */
1537 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001538 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001539 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1540 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001541 sfp_type = ixgbe_sfp_type_srlr_core0;
1542 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001543 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001544 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1545 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001546 sfp_type = ixgbe_sfp_type_srlr_core1;
1547
Donald Skidmorec4900be2008-11-20 21:11:42 -08001548 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001549 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1550 hw_err(hw, "eeprom read at %d failed\n",
1551 IXGBE_PHY_INIT_OFFSET_NL);
1552 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1553 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001554
1555 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001556 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001557
1558 /* Shift offset to first ID word */
1559 (*list_offset)++;
1560
1561 /*
1562 * Find the matching SFP ID in the EEPROM
1563 * and program the init sequence
1564 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001565 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1566 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001567
1568 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001569 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001570 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001571 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1572 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001573 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1574 hw_dbg(hw, "SFP+ module not supported\n");
1575 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1576 } else {
1577 break;
1578 }
1579 } else {
1580 (*list_offset) += 2;
1581 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001582 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001583 }
1584 }
1585
1586 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1587 hw_dbg(hw, "No matching SFP+ module found\n");
1588 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1589 }
1590
1591 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001592
1593err_phy:
1594 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1595 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001596}
1597
1598/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001599 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1600 * @hw: pointer to hardware structure
1601 * @byte_offset: EEPROM byte offset to read
1602 * @eeprom_data: value read
1603 *
1604 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1605 **/
1606s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001607 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001608{
1609 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001610 IXGBE_I2C_EEPROM_DEV_ADDR,
1611 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001612}
1613
1614/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001615 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1616 * @hw: pointer to hardware structure
1617 * @byte_offset: byte offset at address 0xA2
1618 * @eeprom_data: value read
1619 *
1620 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1621 **/
1622s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1623 u8 *sff8472_data)
1624{
1625 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1626 IXGBE_I2C_EEPROM_DEV_ADDR2,
1627 sff8472_data);
1628}
1629
1630/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001631 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1632 * @hw: pointer to hardware structure
1633 * @byte_offset: EEPROM byte offset to write
1634 * @eeprom_data: value to write
1635 *
1636 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1637 **/
1638s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001639 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001640{
1641 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001642 IXGBE_I2C_EEPROM_DEV_ADDR,
1643 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001644}
1645
1646/**
1647 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1648 * @hw: pointer to hardware structure
1649 * @byte_offset: byte offset to read
1650 * @data: value read
1651 *
1652 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001653 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001654 **/
1655s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001656 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001657{
Mark Rustade90dd262014-07-22 06:51:08 +00001658 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001659 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001660 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001661 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001662 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001663 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001664
1665 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001666 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1667 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001668
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001669 ixgbe_i2c_start(hw);
1670
1671 /* Device Address and write indication */
1672 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1673 if (status != 0)
1674 goto fail;
1675
1676 status = ixgbe_get_i2c_ack(hw);
1677 if (status != 0)
1678 goto fail;
1679
1680 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1681 if (status != 0)
1682 goto fail;
1683
1684 status = ixgbe_get_i2c_ack(hw);
1685 if (status != 0)
1686 goto fail;
1687
1688 ixgbe_i2c_start(hw);
1689
1690 /* Device Address and read indication */
1691 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1692 if (status != 0)
1693 goto fail;
1694
1695 status = ixgbe_get_i2c_ack(hw);
1696 if (status != 0)
1697 goto fail;
1698
1699 status = ixgbe_clock_in_i2c_byte(hw, data);
1700 if (status != 0)
1701 goto fail;
1702
1703 status = ixgbe_clock_out_i2c_bit(hw, nack);
1704 if (status != 0)
1705 goto fail;
1706
1707 ixgbe_i2c_stop(hw);
1708 break;
1709
1710fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001711 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001712 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001713 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001714 retry++;
1715 if (retry < max_retry)
1716 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1717 else
1718 hw_dbg(hw, "I2C byte read error.\n");
1719
1720 } while (retry < max_retry);
1721
Emil Tantilov6d980c32011-04-13 04:56:15 +00001722 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001723
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001724 return status;
1725}
1726
1727/**
1728 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1729 * @hw: pointer to hardware structure
1730 * @byte_offset: byte offset to write
1731 * @data: value to write
1732 *
1733 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1734 * a specified device address.
1735 **/
1736s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001737 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001738{
Mark Rustade90dd262014-07-22 06:51:08 +00001739 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001740 u32 max_retry = 1;
1741 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001742 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001743
Mark Rustade90dd262014-07-22 06:51:08 +00001744 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1745 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001746
1747 do {
1748 ixgbe_i2c_start(hw);
1749
1750 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1751 if (status != 0)
1752 goto fail;
1753
1754 status = ixgbe_get_i2c_ack(hw);
1755 if (status != 0)
1756 goto fail;
1757
1758 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1759 if (status != 0)
1760 goto fail;
1761
1762 status = ixgbe_get_i2c_ack(hw);
1763 if (status != 0)
1764 goto fail;
1765
1766 status = ixgbe_clock_out_i2c_byte(hw, data);
1767 if (status != 0)
1768 goto fail;
1769
1770 status = ixgbe_get_i2c_ack(hw);
1771 if (status != 0)
1772 goto fail;
1773
1774 ixgbe_i2c_stop(hw);
1775 break;
1776
1777fail:
1778 ixgbe_i2c_bus_clear(hw);
1779 retry++;
1780 if (retry < max_retry)
1781 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1782 else
1783 hw_dbg(hw, "I2C byte write error.\n");
1784 } while (retry < max_retry);
1785
Emil Tantilov6d980c32011-04-13 04:56:15 +00001786 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001787
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001788 return status;
1789}
1790
1791/**
1792 * ixgbe_i2c_start - Sets I2C start condition
1793 * @hw: pointer to hardware structure
1794 *
1795 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1796 **/
1797static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1798{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001799 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001800
1801 /* Start condition must begin with data and clock high */
1802 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1803 ixgbe_raise_i2c_clk(hw, &i2cctl);
1804
1805 /* Setup time for start condition (4.7us) */
1806 udelay(IXGBE_I2C_T_SU_STA);
1807
1808 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1809
1810 /* Hold time for start condition (4us) */
1811 udelay(IXGBE_I2C_T_HD_STA);
1812
1813 ixgbe_lower_i2c_clk(hw, &i2cctl);
1814
1815 /* Minimum low period of clock is 4.7 us */
1816 udelay(IXGBE_I2C_T_LOW);
1817
1818}
1819
1820/**
1821 * ixgbe_i2c_stop - Sets I2C stop condition
1822 * @hw: pointer to hardware structure
1823 *
1824 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1825 **/
1826static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1827{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001828 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001829
1830 /* Stop condition must begin with data low and clock high */
1831 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1832 ixgbe_raise_i2c_clk(hw, &i2cctl);
1833
1834 /* Setup time for stop condition (4us) */
1835 udelay(IXGBE_I2C_T_SU_STO);
1836
1837 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1838
1839 /* bus free time between stop and start (4.7us)*/
1840 udelay(IXGBE_I2C_T_BUF);
1841}
1842
1843/**
1844 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1845 * @hw: pointer to hardware structure
1846 * @data: data byte to clock in
1847 *
1848 * Clocks in one byte data via I2C data/clock
1849 **/
1850static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1851{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001852 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001853 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001854
1855 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001856 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001857 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001858 }
1859
Emil Tantilove1befd72011-08-27 07:18:47 +00001860 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001861}
1862
1863/**
1864 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1865 * @hw: pointer to hardware structure
1866 * @data: data byte clocked out
1867 *
1868 * Clocks out one byte data via I2C data/clock
1869 **/
1870static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1871{
Mark Rustade90dd262014-07-22 06:51:08 +00001872 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001873 s32 i;
1874 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001875 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001876
1877 for (i = 7; i >= 0; i--) {
1878 bit = (data >> i) & 0x1;
1879 status = ixgbe_clock_out_i2c_bit(hw, bit);
1880
1881 if (status != 0)
1882 break;
1883 }
1884
1885 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07001886 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1887 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1888 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001889 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001890
1891 return status;
1892}
1893
1894/**
1895 * ixgbe_get_i2c_ack - Polls for I2C ACK
1896 * @hw: pointer to hardware structure
1897 *
1898 * Clocks in/out one bit via I2C data/clock
1899 **/
1900static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1901{
Emil Tantilove1befd72011-08-27 07:18:47 +00001902 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001903 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001904 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001905 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001906 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001907
Emil Tantilove1befd72011-08-27 07:18:47 +00001908 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001909
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001910
1911 /* Minimum high period of clock is 4us */
1912 udelay(IXGBE_I2C_T_HIGH);
1913
1914 /* Poll for ACK. Note that ACK in I2C spec is
1915 * transition from 1 to 0 */
1916 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07001917 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001918 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001919
1920 udelay(1);
1921 if (ack == 0)
1922 break;
1923 }
1924
1925 if (ack == 1) {
1926 hw_dbg(hw, "I2C ack was not received.\n");
1927 status = IXGBE_ERR_I2C;
1928 }
1929
1930 ixgbe_lower_i2c_clk(hw, &i2cctl);
1931
1932 /* Minimum low period of clock is 4.7 us */
1933 udelay(IXGBE_I2C_T_LOW);
1934
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001935 return status;
1936}
1937
1938/**
1939 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1940 * @hw: pointer to hardware structure
1941 * @data: read data value
1942 *
1943 * Clocks in one bit via I2C data/clock
1944 **/
1945static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1946{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001947 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001948
Emil Tantilove1befd72011-08-27 07:18:47 +00001949 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001950
1951 /* Minimum high period of clock is 4us */
1952 udelay(IXGBE_I2C_T_HIGH);
1953
Don Skidmore9a900ec2015-06-09 17:15:01 -07001954 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001955 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001956
1957 ixgbe_lower_i2c_clk(hw, &i2cctl);
1958
1959 /* Minimum low period of clock is 4.7 us */
1960 udelay(IXGBE_I2C_T_LOW);
1961
Emil Tantilove1befd72011-08-27 07:18:47 +00001962 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001963}
1964
1965/**
1966 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1967 * @hw: pointer to hardware structure
1968 * @data: data value to write
1969 *
1970 * Clocks out one bit via I2C data/clock
1971 **/
1972static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1973{
1974 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001975 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001976
1977 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1978 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001979 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001980
1981 /* Minimum high period of clock is 4us */
1982 udelay(IXGBE_I2C_T_HIGH);
1983
1984 ixgbe_lower_i2c_clk(hw, &i2cctl);
1985
1986 /* Minimum low period of clock is 4.7 us.
1987 * This also takes care of the data hold time.
1988 */
1989 udelay(IXGBE_I2C_T_LOW);
1990 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001991 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001992 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001993 }
1994
Mark Rustade90dd262014-07-22 06:51:08 +00001995 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001996}
1997/**
1998 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1999 * @hw: pointer to hardware structure
2000 * @i2cctl: Current value of I2CCTL register
2001 *
2002 * Raises the I2C clock line '0'->'1'
2003 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002004static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002005{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002006 u32 i = 0;
2007 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2008 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002009
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002010 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002011 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2012 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002013 IXGBE_WRITE_FLUSH(hw);
2014 /* SCL rise time (1000ns) */
2015 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002016
Don Skidmore9a900ec2015-06-09 17:15:01 -07002017 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2018 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002019 break;
2020 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002021}
2022
2023/**
2024 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2025 * @hw: pointer to hardware structure
2026 * @i2cctl: Current value of I2CCTL register
2027 *
2028 * Lowers the I2C clock line '1'->'0'
2029 **/
2030static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2031{
2032
Don Skidmore9a900ec2015-06-09 17:15:01 -07002033 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002034
Don Skidmore9a900ec2015-06-09 17:15:01 -07002035 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002036 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002037
2038 /* SCL fall time (300ns) */
2039 udelay(IXGBE_I2C_T_FALL);
2040}
2041
2042/**
2043 * ixgbe_set_i2c_data - Sets the I2C data bit
2044 * @hw: pointer to hardware structure
2045 * @i2cctl: Current value of I2CCTL register
2046 * @data: I2C data value (0 or 1) to set
2047 *
2048 * Sets the I2C data bit
2049 **/
2050static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2051{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002052 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002053 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002054 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002055 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002056
Don Skidmore9a900ec2015-06-09 17:15:01 -07002057 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002058 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002059
2060 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2061 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2062
2063 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002064 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002065 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002066 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002067 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002068 }
2069
Mark Rustade90dd262014-07-22 06:51:08 +00002070 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002071}
2072
2073/**
2074 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2075 * @hw: pointer to hardware structure
2076 * @i2cctl: Current value of I2CCTL register
2077 *
2078 * Returns the I2C data bit value
2079 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002080static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002081{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002082 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002083 return true;
2084 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002085}
2086
2087/**
2088 * ixgbe_i2c_bus_clear - Clears the I2C bus
2089 * @hw: pointer to hardware structure
2090 *
2091 * Clears the I2C bus by sending nine clock pulses.
2092 * Used when data line is stuck low.
2093 **/
2094static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2095{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002096 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002097 u32 i;
2098
Emil Tantilov75f19c32011-02-19 08:43:55 +00002099 ixgbe_i2c_start(hw);
2100
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002101 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2102
2103 for (i = 0; i < 9; i++) {
2104 ixgbe_raise_i2c_clk(hw, &i2cctl);
2105
2106 /* Min high period of clock is 4us */
2107 udelay(IXGBE_I2C_T_HIGH);
2108
2109 ixgbe_lower_i2c_clk(hw, &i2cctl);
2110
2111 /* Min low period of clock is 4.7us*/
2112 udelay(IXGBE_I2C_T_LOW);
2113 }
2114
Emil Tantilov75f19c32011-02-19 08:43:55 +00002115 ixgbe_i2c_start(hw);
2116
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002117 /* Put the i2c bus back to default state */
2118 ixgbe_i2c_stop(hw);
2119}
2120
2121/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002122 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002123 * @hw: pointer to hardware structure
2124 *
2125 * Checks if the LASI temp alarm status was triggered due to overtemp
2126 **/
2127s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2128{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002129 u16 phy_data = 0;
2130
2131 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002132 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002133
2134 /* Check that the LASI temp alarm status was triggered */
2135 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002136 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002137
2138 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002139 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002140
Mark Rustade90dd262014-07-22 06:51:08 +00002141 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002142}