blob: ac6c0af3badc8ed0dddd56c3175061472ce21995 [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 Skidmorededa5622015-06-09 17:39:46 -0700350 case X550_PHY_ID:
Don Skidmore2b264902010-12-09 06:55:14 +0000351 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800352 phy_type = ixgbe_phy_aq;
353 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700354 case QT2022_PHY_ID:
355 phy_type = ixgbe_phy_qt;
356 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800357 case ATH_PHY_ID:
358 phy_type = ixgbe_phy_nl;
359 break;
Don Skidmorec2c78d52015-06-09 16:04:59 -0700360 case X557_PHY_ID:
361 phy_type = ixgbe_phy_x550em_ext_t;
362 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700363 default:
364 phy_type = ixgbe_phy_unknown;
365 break;
366 }
367
368 return phy_type;
369}
370
371/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700372 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700373 * @hw: pointer to hardware structure
374 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700375s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700376{
Emil Tantilov17835752011-02-16 01:38:13 +0000377 u32 i;
378 u16 ctrl = 0;
379 s32 status = 0;
380
381 if (hw->phy.type == ixgbe_phy_unknown)
382 status = ixgbe_identify_phy_generic(hw);
383
384 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000385 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000386
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700387 /* Don't reset PHY if it's shut down due to overtemp. */
388 if (!hw->phy.reset_if_overtemp &&
389 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000390 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700391
Don Skidmorec97506a2014-02-27 20:32:43 -0800392 /* Blocked by MNG FW so bail */
393 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000394 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800395
Auke Kok9a799d72007-09-15 14:07:45 -0700396 /*
397 * Perform soft PHY reset to the PHY_XS.
398 * This will cause a soft reset to the PHY
399 */
Emil Tantilov17835752011-02-16 01:38:13 +0000400 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
401 MDIO_MMD_PHYXS,
402 MDIO_CTRL1_RESET);
403
404 /*
405 * Poll for reset bit to self-clear indicating reset is complete.
406 * Some PHYs could take up to 3 seconds to complete and need about
407 * 1.7 usec delay after the reset is complete.
408 */
409 for (i = 0; i < 30; i++) {
410 msleep(100);
411 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
412 MDIO_MMD_PHYXS, &ctrl);
413 if (!(ctrl & MDIO_CTRL1_RESET)) {
414 udelay(2);
415 break;
416 }
417 }
418
419 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000420 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000421 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000422 }
423
Mark Rustade90dd262014-07-22 06:51:08 +0000424 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700425}
426
427/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000428 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
429 * the SWFW lock
430 * @hw: pointer to hardware structure
431 * @reg_addr: 32 bit address of PHY register to read
432 * @phy_data: Pointer to read data from PHY register
433 **/
434s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
435 u16 *phy_data)
436{
437 u32 i, data, command;
438
439 /* Setup and write the address cycle command */
440 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
441 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
442 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
443 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
444
445 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
446
447 /* Check every 10 usec to see if the address cycle completed.
448 * The MDI Command bit will clear when the operation is
449 * complete
450 */
451 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
452 udelay(10);
453
454 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
455 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
456 break;
457 }
458
459
460 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
461 hw_dbg(hw, "PHY address command did not complete.\n");
462 return IXGBE_ERR_PHY;
463 }
464
465 /* Address cycle complete, setup and write the read
466 * command
467 */
468 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
469 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
470 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
471 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
472
473 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
474
475 /* Check every 10 usec to see if the address cycle
476 * completed. The MDI Command bit will clear when the
477 * operation is complete
478 */
479 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
480 udelay(10);
481
482 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
483 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
484 break;
485 }
486
487 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
488 hw_dbg(hw, "PHY read command didn't complete\n");
489 return IXGBE_ERR_PHY;
490 }
491
492 /* Read operation is complete. Get the data
493 * from MSRWD
494 */
495 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
496 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
497 *phy_data = (u16)(data);
498
499 return 0;
500}
501
502/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700503 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000504 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700505 * @hw: pointer to hardware structure
506 * @reg_addr: 32 bit address of PHY register to read
507 * @phy_data: Pointer to read data from PHY register
508 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700509s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000510 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700511{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000512 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000513 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700514
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000515 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
516 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
517 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000518 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000519 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000520 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700521 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700522
Auke Kok9a799d72007-09-15 14:07:45 -0700523 return status;
524}
525
526/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000527 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
528 * without SWFW lock
529 * @hw: pointer to hardware structure
530 * @reg_addr: 32 bit PHY register to write
531 * @device_type: 5 bit device type
532 * @phy_data: Data to write to the PHY register
533 **/
534s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
535 u32 device_type, u16 phy_data)
536{
537 u32 i, command;
538
539 /* Put the data in the MDI single read and write data register*/
540 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
541
542 /* Setup and write the address cycle command */
543 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
544 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
545 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
546 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
547
548 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
549
550 /*
551 * Check every 10 usec to see if the address cycle completed.
552 * The MDI Command bit will clear when the operation is
553 * complete
554 */
555 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
556 udelay(10);
557
558 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
559 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
560 break;
561 }
562
563 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
564 hw_dbg(hw, "PHY address cmd didn't complete\n");
565 return IXGBE_ERR_PHY;
566 }
567
568 /*
569 * Address cycle complete, setup and write the write
570 * command
571 */
572 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
573 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
574 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
575 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
576
577 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
578
579 /* Check every 10 usec to see if the address cycle
580 * completed. The MDI Command bit will clear when the
581 * operation is complete
582 */
583 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
584 udelay(10);
585
586 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
587 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
588 break;
589 }
590
591 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
592 hw_dbg(hw, "PHY write cmd didn't complete\n");
593 return IXGBE_ERR_PHY;
594 }
595
596 return 0;
597}
598
599/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700600 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000601 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700602 * @hw: pointer to hardware structure
603 * @reg_addr: 32 bit PHY register to write
604 * @device_type: 5 bit device type
605 * @phy_data: Data to write to the PHY register
606 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700607s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000608 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700609{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000610 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000611 u32 gssr;
Auke Kok9a799d72007-09-15 14:07:45 -0700612
613 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
614 gssr = IXGBE_GSSR_PHY1_SM;
615 else
616 gssr = IXGBE_GSSR_PHY0_SM;
617
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000618 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
619 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
620 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000621 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000622 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000623 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700624 }
625
626 return status;
627}
628
629/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700630 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700631 * @hw: pointer to hardware structure
632 *
633 * Restart autonegotiation and PHY and waits for completion.
634 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700635s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700636{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000637 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000638 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
639 bool autoneg = false;
640 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700641
Emil Tantilov9dda1732011-03-05 01:28:07 +0000642 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700643
Emil Tantilov9dda1732011-03-05 01:28:07 +0000644 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
645 /* Set or unset auto-negotiation 10G advertisement */
646 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
647 MDIO_MMD_AN,
648 &autoneg_reg);
649
Ben Hutchings6b73e102009-04-29 08:08:58 +0000650 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000651 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
652 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700653
Emil Tantilov9dda1732011-03-05 01:28:07 +0000654 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
655 MDIO_MMD_AN,
656 autoneg_reg);
657 }
658
659 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
660 /* Set or unset auto-negotiation 1G advertisement */
661 hw->phy.ops.read_reg(hw,
662 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
663 MDIO_MMD_AN,
664 &autoneg_reg);
665
666 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
667 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
668 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
669
670 hw->phy.ops.write_reg(hw,
671 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
672 MDIO_MMD_AN,
673 autoneg_reg);
674 }
675
676 if (speed & IXGBE_LINK_SPEED_100_FULL) {
677 /* Set or unset auto-negotiation 100M advertisement */
678 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
679 MDIO_MMD_AN,
680 &autoneg_reg);
681
Emil Tantilova59e8a12011-03-31 09:36:12 +0000682 autoneg_reg &= ~(ADVERTISE_100FULL |
683 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000684 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
685 autoneg_reg |= ADVERTISE_100FULL;
686
687 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
688 MDIO_MMD_AN,
689 autoneg_reg);
690 }
Auke Kok9a799d72007-09-15 14:07:45 -0700691
Don Skidmorec97506a2014-02-27 20:32:43 -0800692 /* Blocked by MNG FW so don't reset PHY */
693 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000694 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800695
Auke Kok9a799d72007-09-15 14:07:45 -0700696 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000697 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
698 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700699
Ben Hutchings6b73e102009-04-29 08:08:58 +0000700 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700701
Emil Tantilov9dda1732011-03-05 01:28:07 +0000702 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
703 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700704
Auke Kok9a799d72007-09-15 14:07:45 -0700705 return status;
706}
707
708/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700709 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700710 * @hw: pointer to hardware structure
711 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700712 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700713s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000714 ixgbe_link_speed speed,
715 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700716{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700717
Auke Kok9a799d72007-09-15 14:07:45 -0700718 /*
719 * Clear autoneg_advertised and set new values based on input link
720 * speed.
721 */
722 hw->phy.autoneg_advertised = 0;
723
724 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
725 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700726
Auke Kok9a799d72007-09-15 14:07:45 -0700727 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
728 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
729
Emil Tantilov9dda1732011-03-05 01:28:07 +0000730 if (speed & IXGBE_LINK_SPEED_100_FULL)
731 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
732
Auke Kok9a799d72007-09-15 14:07:45 -0700733 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700734 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700735
736 return 0;
737}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700738
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700739/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800740 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
741 * @hw: pointer to hardware structure
742 * @speed: pointer to link speed
743 * @autoneg: boolean auto-negotiation value
744 *
745 * Determines the link capabilities by reading the AUTOC register.
746 */
747s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000748 ixgbe_link_speed *speed,
749 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800750{
Mark Rustade90dd262014-07-22 06:51:08 +0000751 s32 status;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800752 u16 speed_ability;
753
754 *speed = 0;
755 *autoneg = true;
756
757 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000758 &speed_ability);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800759
760 if (status == 0) {
761 if (speed_ability & MDIO_SPEED_10G)
762 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
763 if (speed_ability & MDIO_PMA_SPEED_1000)
764 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
765 if (speed_ability & MDIO_PMA_SPEED_100)
766 *speed |= IXGBE_LINK_SPEED_100_FULL;
767 }
768
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000769 /* Internal PHY does not support 100 Mbps */
770 if (hw->mac.type == ixgbe_mac_X550EM_x)
771 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
772
Don Skidmorea391f1d2010-11-16 19:27:15 -0800773 return status;
774}
775
776/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000777 * ixgbe_check_phy_link_tnx - Determine link and speed status
778 * @hw: pointer to hardware structure
779 *
780 * Reads the VS1 register to determine if link is up and the current speed for
781 * the PHY.
782 **/
783s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
784 bool *link_up)
785{
Mark Rustade90dd262014-07-22 06:51:08 +0000786 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000787 u32 time_out;
788 u32 max_time_out = 10;
789 u16 phy_link = 0;
790 u16 phy_speed = 0;
791 u16 phy_data = 0;
792
793 /* Initialize speed and link to default case */
794 *link_up = false;
795 *speed = IXGBE_LINK_SPEED_10GB_FULL;
796
797 /*
798 * Check current speed and link status of the PHY register.
799 * This is a vendor specific register and may have to
800 * be changed for other copper PHYs.
801 */
802 for (time_out = 0; time_out < max_time_out; time_out++) {
803 udelay(10);
804 status = hw->phy.ops.read_reg(hw,
805 MDIO_STAT1,
806 MDIO_MMD_VEND1,
807 &phy_data);
808 phy_link = phy_data &
809 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
810 phy_speed = phy_data &
811 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
812 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
813 *link_up = true;
814 if (phy_speed ==
815 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
816 *speed = IXGBE_LINK_SPEED_1GB_FULL;
817 break;
818 }
819 }
820
821 return status;
822}
823
824/**
825 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
826 * @hw: pointer to hardware structure
827 *
828 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000829 * This function always returns success, this is nessary since
830 * it is called via a function pointer that could call other
831 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000832 **/
833s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
834{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000835 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
836 bool autoneg = false;
837 ixgbe_link_speed speed;
838
839 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
840
841 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
842 /* Set or unset auto-negotiation 10G advertisement */
843 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
844 MDIO_MMD_AN,
845 &autoneg_reg);
846
847 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
848 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
849 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
850
851 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
852 MDIO_MMD_AN,
853 autoneg_reg);
854 }
855
856 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
857 /* Set or unset auto-negotiation 1G advertisement */
858 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
859 MDIO_MMD_AN,
860 &autoneg_reg);
861
862 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
863 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
864 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
865
866 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
867 MDIO_MMD_AN,
868 autoneg_reg);
869 }
870
871 if (speed & IXGBE_LINK_SPEED_100_FULL) {
872 /* Set or unset auto-negotiation 100M advertisement */
873 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
874 MDIO_MMD_AN,
875 &autoneg_reg);
876
Emil Tantilov50c022e2011-03-31 09:36:12 +0000877 autoneg_reg &= ~(ADVERTISE_100FULL |
878 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000879 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
880 autoneg_reg |= ADVERTISE_100FULL;
881
882 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
883 MDIO_MMD_AN,
884 autoneg_reg);
885 }
886
Don Skidmorec97506a2014-02-27 20:32:43 -0800887 /* Blocked by MNG FW so don't reset PHY */
888 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000889 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800890
Emil Tantilov9dda1732011-03-05 01:28:07 +0000891 /* Restart PHY autonegotiation and wait for completion */
892 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
893 MDIO_MMD_AN, &autoneg_reg);
894
895 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
896
897 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
898 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000899 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000900}
901
902/**
903 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
904 * @hw: pointer to hardware structure
905 * @firmware_version: pointer to the PHY Firmware Version
906 **/
907s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
908 u16 *firmware_version)
909{
Mark Rustade90dd262014-07-22 06:51:08 +0000910 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000911
912 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
913 MDIO_MMD_VEND1,
914 firmware_version);
915
916 return status;
917}
918
919/**
920 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
921 * @hw: pointer to hardware structure
922 * @firmware_version: pointer to the PHY Firmware Version
923 **/
924s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
925 u16 *firmware_version)
926{
Mark Rustade90dd262014-07-22 06:51:08 +0000927 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000928
929 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
930 MDIO_MMD_VEND1,
931 firmware_version);
932
933 return status;
934}
935
936/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800937 * ixgbe_reset_phy_nl - Performs a PHY reset
938 * @hw: pointer to hardware structure
939 **/
940s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
941{
942 u16 phy_offset, control, eword, edata, block_crc;
943 bool end_data = false;
944 u16 list_offset, data_offset;
945 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000946 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800947 u32 i;
948
Don Skidmorec97506a2014-02-27 20:32:43 -0800949 /* Blocked by MNG FW so bail */
950 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000951 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800952
Ben Hutchings6b73e102009-04-29 08:08:58 +0000953 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800954
955 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000956 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000957 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800958
959 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000960 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000961 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000962 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800963 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000964 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800965 }
966
Ben Hutchings6b73e102009-04-29 08:08:58 +0000967 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800968 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000969 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800970 }
971
972 /* Get init offsets */
973 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000974 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000975 if (ret_val)
976 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800977
978 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
979 data_offset++;
980 while (!end_data) {
981 /*
982 * Read control word from PHY init contents offset
983 */
984 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000985 if (ret_val)
986 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800987 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +0000988 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800989 edata = eword & IXGBE_DATA_MASK_NL;
990 switch (control) {
991 case IXGBE_DELAY_NL:
992 data_offset++;
993 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000994 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800995 break;
996 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000997 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800998 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000999 ret_val = hw->eeprom.ops.read(hw, data_offset++,
1000 &phy_offset);
1001 if (ret_val)
1002 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001003 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001004 ret_val = hw->eeprom.ops.read(hw, data_offset,
1005 &eword);
1006 if (ret_val)
1007 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001008 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001009 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001010 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1011 phy_offset);
1012 data_offset++;
1013 phy_offset++;
1014 }
1015 break;
1016 case IXGBE_CONTROL_NL:
1017 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001018 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001019 if (edata == IXGBE_CONTROL_EOL_NL) {
1020 hw_dbg(hw, "EOL\n");
1021 end_data = true;
1022 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1023 hw_dbg(hw, "SOL\n");
1024 } else {
1025 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001026 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001027 }
1028 break;
1029 default:
1030 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001031 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001032 }
1033 }
1034
Donald Skidmorec4900be2008-11-20 21:11:42 -08001035 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001036
1037err_eeprom:
1038 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1039 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001040}
1041
1042/**
Don Skidmore8f583322013-07-27 06:25:38 +00001043 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001044 * @hw: pointer to hardware structure
1045 *
Don Skidmore8f583322013-07-27 06:25:38 +00001046 * Determines HW type and calls appropriate function.
1047 **/
1048s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1049{
Don Skidmore8f583322013-07-27 06:25:38 +00001050 switch (hw->mac.ops.get_media_type(hw)) {
1051 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001052 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001053 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001054 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001055 default:
1056 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001057 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001058 }
1059
Mark Rustade90dd262014-07-22 06:51:08 +00001060 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001061}
1062
1063/**
1064 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1065 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001066 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001067 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001068 **/
1069s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1070{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001071 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001072 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001073 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001074 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001075 u8 identifier = 0;
1076 u8 comp_codes_1g = 0;
1077 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001078 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001079 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001080 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001081 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001082
Don Skidmore8ca783a2009-05-26 20:40:47 -07001083 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1084 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001085 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001086 }
1087
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001088 status = hw->phy.ops.read_i2c_eeprom(hw,
1089 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001090 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001091
Mark Rustade90dd262014-07-22 06:51:08 +00001092 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001093 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001094
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001095 /* LAN ID is needed for sfp_type determination */
1096 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001097
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001098 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1099 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001100 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1101 }
1102 status = hw->phy.ops.read_i2c_eeprom(hw,
1103 IXGBE_SFF_1GBE_COMP_CODES,
1104 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001105
Mark Rustade90dd262014-07-22 06:51:08 +00001106 if (status)
1107 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001108
Mark Rustade90dd262014-07-22 06:51:08 +00001109 status = hw->phy.ops.read_i2c_eeprom(hw,
1110 IXGBE_SFF_10GBE_COMP_CODES,
1111 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001112
Mark Rustade90dd262014-07-22 06:51:08 +00001113 if (status)
1114 goto err_read_i2c_eeprom;
1115 status = hw->phy.ops.read_i2c_eeprom(hw,
1116 IXGBE_SFF_CABLE_TECHNOLOGY,
1117 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001118
Mark Rustade90dd262014-07-22 06:51:08 +00001119 if (status)
1120 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001121
Mark Rustade90dd262014-07-22 06:51:08 +00001122 /* ID Module
1123 * =========
1124 * 0 SFP_DA_CU
1125 * 1 SFP_SR
1126 * 2 SFP_LR
1127 * 3 SFP_DA_CORE0 - 82599-specific
1128 * 4 SFP_DA_CORE1 - 82599-specific
1129 * 5 SFP_SR/LR_CORE0 - 82599-specific
1130 * 6 SFP_SR/LR_CORE1 - 82599-specific
1131 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1132 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1133 * 9 SFP_1g_cu_CORE0 - 82599-specific
1134 * 10 SFP_1g_cu_CORE1 - 82599-specific
1135 * 11 SFP_1g_sx_CORE0 - 82599-specific
1136 * 12 SFP_1g_sx_CORE1 - 82599-specific
1137 */
1138 if (hw->mac.type == ixgbe_mac_82598EB) {
1139 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1140 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1141 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1142 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1143 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1144 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1145 else
1146 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1147 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1148 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1149 if (hw->bus.lan_id == 0)
1150 hw->phy.sfp_type =
1151 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001152 else
Mark Rustade90dd262014-07-22 06:51:08 +00001153 hw->phy.sfp_type =
1154 ixgbe_sfp_type_da_cu_core1;
1155 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1156 hw->phy.ops.read_i2c_eeprom(
1157 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1158 &cable_spec);
1159 if (cable_spec &
1160 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001161 if (hw->bus.lan_id == 0)
1162 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001163 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001164 else
1165 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001166 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001167 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001168 hw->phy.sfp_type =
1169 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001170 }
Mark Rustade90dd262014-07-22 06:51:08 +00001171 } else if (comp_codes_10g &
1172 (IXGBE_SFF_10GBASESR_CAPABLE |
1173 IXGBE_SFF_10GBASELR_CAPABLE)) {
1174 if (hw->bus.lan_id == 0)
1175 hw->phy.sfp_type =
1176 ixgbe_sfp_type_srlr_core0;
1177 else
1178 hw->phy.sfp_type =
1179 ixgbe_sfp_type_srlr_core1;
1180 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1181 if (hw->bus.lan_id == 0)
1182 hw->phy.sfp_type =
1183 ixgbe_sfp_type_1g_cu_core0;
1184 else
1185 hw->phy.sfp_type =
1186 ixgbe_sfp_type_1g_cu_core1;
1187 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1188 if (hw->bus.lan_id == 0)
1189 hw->phy.sfp_type =
1190 ixgbe_sfp_type_1g_sx_core0;
1191 else
1192 hw->phy.sfp_type =
1193 ixgbe_sfp_type_1g_sx_core1;
1194 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1195 if (hw->bus.lan_id == 0)
1196 hw->phy.sfp_type =
1197 ixgbe_sfp_type_1g_lx_core0;
1198 else
1199 hw->phy.sfp_type =
1200 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001201 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001202 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001203 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001204 }
1205
Mark Rustade90dd262014-07-22 06:51:08 +00001206 if (hw->phy.sfp_type != stored_sfp_type)
1207 hw->phy.sfp_setup_needed = true;
1208
1209 /* Determine if the SFP+ PHY is dual speed or not. */
1210 hw->phy.multispeed_fiber = false;
1211 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1212 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1213 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1214 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1215 hw->phy.multispeed_fiber = true;
1216
1217 /* Determine PHY vendor */
1218 if (hw->phy.type != ixgbe_phy_nl) {
1219 hw->phy.id = identifier;
1220 status = hw->phy.ops.read_i2c_eeprom(hw,
1221 IXGBE_SFF_VENDOR_OUI_BYTE0,
1222 &oui_bytes[0]);
1223
1224 if (status != 0)
1225 goto err_read_i2c_eeprom;
1226
1227 status = hw->phy.ops.read_i2c_eeprom(hw,
1228 IXGBE_SFF_VENDOR_OUI_BYTE1,
1229 &oui_bytes[1]);
1230
1231 if (status != 0)
1232 goto err_read_i2c_eeprom;
1233
1234 status = hw->phy.ops.read_i2c_eeprom(hw,
1235 IXGBE_SFF_VENDOR_OUI_BYTE2,
1236 &oui_bytes[2]);
1237
1238 if (status != 0)
1239 goto err_read_i2c_eeprom;
1240
1241 vendor_oui =
1242 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1243 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1244 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1245
1246 switch (vendor_oui) {
1247 case IXGBE_SFF_VENDOR_OUI_TYCO:
1248 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1249 hw->phy.type =
1250 ixgbe_phy_sfp_passive_tyco;
1251 break;
1252 case IXGBE_SFF_VENDOR_OUI_FTL:
1253 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1254 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1255 else
1256 hw->phy.type = ixgbe_phy_sfp_ftl;
1257 break;
1258 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1259 hw->phy.type = ixgbe_phy_sfp_avago;
1260 break;
1261 case IXGBE_SFF_VENDOR_OUI_INTEL:
1262 hw->phy.type = ixgbe_phy_sfp_intel;
1263 break;
1264 default:
1265 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1266 hw->phy.type =
1267 ixgbe_phy_sfp_passive_unknown;
1268 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1269 hw->phy.type =
1270 ixgbe_phy_sfp_active_unknown;
1271 else
1272 hw->phy.type = ixgbe_phy_sfp_unknown;
1273 break;
1274 }
1275 }
1276
1277 /* Allow any DA cable vendor */
1278 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1279 IXGBE_SFF_DA_ACTIVE_CABLE))
1280 return 0;
1281
1282 /* Verify supported 1G SFP modules */
1283 if (comp_codes_10g == 0 &&
1284 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1285 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1286 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1287 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1288 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1289 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1290 hw->phy.type = ixgbe_phy_sfp_unsupported;
1291 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1292 }
1293
1294 /* Anything else 82598-based is supported */
1295 if (hw->mac.type == ixgbe_mac_82598EB)
1296 return 0;
1297
1298 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1299 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1300 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1301 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1302 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1303 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1304 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1305 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1306 /* Make sure we're a supported PHY type */
1307 if (hw->phy.type == ixgbe_phy_sfp_intel)
1308 return 0;
1309 if (hw->allow_unsupported_sfp) {
1310 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");
1311 return 0;
1312 }
1313 hw_dbg(hw, "SFP+ module not supported\n");
1314 hw->phy.type = ixgbe_phy_sfp_unsupported;
1315 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1316 }
1317 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001318
1319err_read_i2c_eeprom:
1320 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1321 if (hw->phy.type != ixgbe_phy_nl) {
1322 hw->phy.id = 0;
1323 hw->phy.type = ixgbe_phy_unknown;
1324 }
1325 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001326}
1327
1328/**
Don Skidmore8f583322013-07-27 06:25:38 +00001329 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1330 * @hw: pointer to hardware structure
1331 *
1332 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1333 **/
Mark Rustad88217542013-11-23 03:19:19 +00001334static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001335{
1336 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001337 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001338 u32 vendor_oui = 0;
1339 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1340 u8 identifier = 0;
1341 u8 comp_codes_1g = 0;
1342 u8 comp_codes_10g = 0;
1343 u8 oui_bytes[3] = {0, 0, 0};
1344 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001345 u8 connector = 0;
1346 u8 cable_length = 0;
1347 u8 device_tech = 0;
1348 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001349
1350 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1351 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001352 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001353 }
1354
1355 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1356 &identifier);
1357
1358 if (status != 0)
1359 goto err_read_i2c_eeprom;
1360
1361 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1362 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001363 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001364 }
1365
1366 hw->phy.id = identifier;
1367
1368 /* LAN ID is needed for sfp_type determination */
1369 hw->mac.ops.set_lan_id(hw);
1370
1371 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1372 &comp_codes_10g);
1373
1374 if (status != 0)
1375 goto err_read_i2c_eeprom;
1376
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001377 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1378 &comp_codes_1g);
1379
1380 if (status != 0)
1381 goto err_read_i2c_eeprom;
1382
Don Skidmore8f583322013-07-27 06:25:38 +00001383 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1384 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1385 if (hw->bus.lan_id == 0)
1386 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1387 else
1388 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001389 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1390 IXGBE_SFF_10GBASELR_CAPABLE)) {
1391 if (hw->bus.lan_id == 0)
1392 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1393 else
1394 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1395 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001396 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1397 active_cable = true;
1398
1399 if (!active_cable) {
1400 /* check for active DA cables that pre-date
1401 * SFF-8436 v3.6
1402 */
1403 hw->phy.ops.read_i2c_eeprom(hw,
1404 IXGBE_SFF_QSFP_CONNECTOR,
1405 &connector);
1406
1407 hw->phy.ops.read_i2c_eeprom(hw,
1408 IXGBE_SFF_QSFP_CABLE_LENGTH,
1409 &cable_length);
1410
1411 hw->phy.ops.read_i2c_eeprom(hw,
1412 IXGBE_SFF_QSFP_DEVICE_TECH,
1413 &device_tech);
1414
1415 if ((connector ==
1416 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1417 (cable_length > 0) &&
1418 ((device_tech >> 4) ==
1419 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1420 active_cable = true;
1421 }
1422
1423 if (active_cable) {
1424 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1425 if (hw->bus.lan_id == 0)
1426 hw->phy.sfp_type =
1427 ixgbe_sfp_type_da_act_lmt_core0;
1428 else
1429 hw->phy.sfp_type =
1430 ixgbe_sfp_type_da_act_lmt_core1;
1431 } else {
1432 /* unsupported module type */
1433 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001434 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001435 }
Don Skidmore8f583322013-07-27 06:25:38 +00001436 }
1437
1438 if (hw->phy.sfp_type != stored_sfp_type)
1439 hw->phy.sfp_setup_needed = true;
1440
1441 /* Determine if the QSFP+ PHY is dual speed or not. */
1442 hw->phy.multispeed_fiber = false;
1443 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1444 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1445 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1446 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1447 hw->phy.multispeed_fiber = true;
1448
1449 /* Determine PHY vendor for optical modules */
1450 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1451 IXGBE_SFF_10GBASELR_CAPABLE)) {
1452 status = hw->phy.ops.read_i2c_eeprom(hw,
1453 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1454 &oui_bytes[0]);
1455
1456 if (status != 0)
1457 goto err_read_i2c_eeprom;
1458
1459 status = hw->phy.ops.read_i2c_eeprom(hw,
1460 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1461 &oui_bytes[1]);
1462
1463 if (status != 0)
1464 goto err_read_i2c_eeprom;
1465
1466 status = hw->phy.ops.read_i2c_eeprom(hw,
1467 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1468 &oui_bytes[2]);
1469
1470 if (status != 0)
1471 goto err_read_i2c_eeprom;
1472
1473 vendor_oui =
1474 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1475 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1476 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1477
1478 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1479 hw->phy.type = ixgbe_phy_qsfp_intel;
1480 else
1481 hw->phy.type = ixgbe_phy_qsfp_unknown;
1482
1483 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1484 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1485 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001486 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1487 return 0;
1488 if (hw->allow_unsupported_sfp) {
1489 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");
1490 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001491 }
Mark Rustade90dd262014-07-22 06:51:08 +00001492 hw_dbg(hw, "QSFP module not supported\n");
1493 hw->phy.type = ixgbe_phy_sfp_unsupported;
1494 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001495 }
Mark Rustade90dd262014-07-22 06:51:08 +00001496 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001497 }
Mark Rustade90dd262014-07-22 06:51:08 +00001498 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001499
1500err_read_i2c_eeprom:
1501 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1502 hw->phy.id = 0;
1503 hw->phy.type = ixgbe_phy_unknown;
1504
1505 return IXGBE_ERR_SFP_NOT_PRESENT;
1506}
1507
1508/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001509 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001510 * @hw: pointer to hardware structure
1511 * @list_offset: offset to the SFP ID list
1512 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001513 *
1514 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1515 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001516 **/
1517s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001518 u16 *list_offset,
1519 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001520{
1521 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001522 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001523
1524 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1525 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1526
1527 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1528 return IXGBE_ERR_SFP_NOT_PRESENT;
1529
1530 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1531 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1532 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1533
Don Skidmorecb836a92010-06-29 18:30:59 +00001534 /*
1535 * Limiting active cables and 1G Phys must be initialized as
1536 * SR modules
1537 */
1538 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001539 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001540 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1541 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001542 sfp_type = ixgbe_sfp_type_srlr_core0;
1543 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001544 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001545 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1546 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001547 sfp_type = ixgbe_sfp_type_srlr_core1;
1548
Donald Skidmorec4900be2008-11-20 21:11:42 -08001549 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001550 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1551 hw_err(hw, "eeprom read at %d failed\n",
1552 IXGBE_PHY_INIT_OFFSET_NL);
1553 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1554 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001555
1556 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001557 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001558
1559 /* Shift offset to first ID word */
1560 (*list_offset)++;
1561
1562 /*
1563 * Find the matching SFP ID in the EEPROM
1564 * and program the init sequence
1565 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001566 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1567 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001568
1569 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001570 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001571 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001572 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1573 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001574 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1575 hw_dbg(hw, "SFP+ module not supported\n");
1576 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1577 } else {
1578 break;
1579 }
1580 } else {
1581 (*list_offset) += 2;
1582 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001583 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001584 }
1585 }
1586
1587 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1588 hw_dbg(hw, "No matching SFP+ module found\n");
1589 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1590 }
1591
1592 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001593
1594err_phy:
1595 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1596 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001597}
1598
1599/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001600 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1601 * @hw: pointer to hardware structure
1602 * @byte_offset: EEPROM byte offset to read
1603 * @eeprom_data: value read
1604 *
1605 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1606 **/
1607s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001608 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001609{
1610 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001611 IXGBE_I2C_EEPROM_DEV_ADDR,
1612 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001613}
1614
1615/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001616 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1617 * @hw: pointer to hardware structure
1618 * @byte_offset: byte offset at address 0xA2
1619 * @eeprom_data: value read
1620 *
1621 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1622 **/
1623s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1624 u8 *sff8472_data)
1625{
1626 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1627 IXGBE_I2C_EEPROM_DEV_ADDR2,
1628 sff8472_data);
1629}
1630
1631/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001632 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1633 * @hw: pointer to hardware structure
1634 * @byte_offset: EEPROM byte offset to write
1635 * @eeprom_data: value to write
1636 *
1637 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1638 **/
1639s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001640 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001641{
1642 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001643 IXGBE_I2C_EEPROM_DEV_ADDR,
1644 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001645}
1646
1647/**
1648 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1649 * @hw: pointer to hardware structure
1650 * @byte_offset: byte offset to read
1651 * @data: value read
1652 *
1653 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001654 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001655 **/
1656s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001657 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001658{
Mark Rustade90dd262014-07-22 06:51:08 +00001659 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001660 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001661 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001662 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001663 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001664 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001665
1666 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001667 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1668 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001669
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001670 ixgbe_i2c_start(hw);
1671
1672 /* Device Address and write indication */
1673 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1674 if (status != 0)
1675 goto fail;
1676
1677 status = ixgbe_get_i2c_ack(hw);
1678 if (status != 0)
1679 goto fail;
1680
1681 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1682 if (status != 0)
1683 goto fail;
1684
1685 status = ixgbe_get_i2c_ack(hw);
1686 if (status != 0)
1687 goto fail;
1688
1689 ixgbe_i2c_start(hw);
1690
1691 /* Device Address and read indication */
1692 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1693 if (status != 0)
1694 goto fail;
1695
1696 status = ixgbe_get_i2c_ack(hw);
1697 if (status != 0)
1698 goto fail;
1699
1700 status = ixgbe_clock_in_i2c_byte(hw, data);
1701 if (status != 0)
1702 goto fail;
1703
1704 status = ixgbe_clock_out_i2c_bit(hw, nack);
1705 if (status != 0)
1706 goto fail;
1707
1708 ixgbe_i2c_stop(hw);
1709 break;
1710
1711fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001712 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001713 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001714 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001715 retry++;
1716 if (retry < max_retry)
1717 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1718 else
1719 hw_dbg(hw, "I2C byte read error.\n");
1720
1721 } while (retry < max_retry);
1722
Emil Tantilov6d980c32011-04-13 04:56:15 +00001723 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001724
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001725 return status;
1726}
1727
1728/**
1729 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1730 * @hw: pointer to hardware structure
1731 * @byte_offset: byte offset to write
1732 * @data: value to write
1733 *
1734 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1735 * a specified device address.
1736 **/
1737s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001738 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001739{
Mark Rustade90dd262014-07-22 06:51:08 +00001740 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001741 u32 max_retry = 1;
1742 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001743 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001744
Mark Rustade90dd262014-07-22 06:51:08 +00001745 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1746 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001747
1748 do {
1749 ixgbe_i2c_start(hw);
1750
1751 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1752 if (status != 0)
1753 goto fail;
1754
1755 status = ixgbe_get_i2c_ack(hw);
1756 if (status != 0)
1757 goto fail;
1758
1759 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1760 if (status != 0)
1761 goto fail;
1762
1763 status = ixgbe_get_i2c_ack(hw);
1764 if (status != 0)
1765 goto fail;
1766
1767 status = ixgbe_clock_out_i2c_byte(hw, data);
1768 if (status != 0)
1769 goto fail;
1770
1771 status = ixgbe_get_i2c_ack(hw);
1772 if (status != 0)
1773 goto fail;
1774
1775 ixgbe_i2c_stop(hw);
1776 break;
1777
1778fail:
1779 ixgbe_i2c_bus_clear(hw);
1780 retry++;
1781 if (retry < max_retry)
1782 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1783 else
1784 hw_dbg(hw, "I2C byte write error.\n");
1785 } while (retry < max_retry);
1786
Emil Tantilov6d980c32011-04-13 04:56:15 +00001787 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001788
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001789 return status;
1790}
1791
1792/**
1793 * ixgbe_i2c_start - Sets I2C start condition
1794 * @hw: pointer to hardware structure
1795 *
1796 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1797 **/
1798static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1799{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001800 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001801
1802 /* Start condition must begin with data and clock high */
1803 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1804 ixgbe_raise_i2c_clk(hw, &i2cctl);
1805
1806 /* Setup time for start condition (4.7us) */
1807 udelay(IXGBE_I2C_T_SU_STA);
1808
1809 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1810
1811 /* Hold time for start condition (4us) */
1812 udelay(IXGBE_I2C_T_HD_STA);
1813
1814 ixgbe_lower_i2c_clk(hw, &i2cctl);
1815
1816 /* Minimum low period of clock is 4.7 us */
1817 udelay(IXGBE_I2C_T_LOW);
1818
1819}
1820
1821/**
1822 * ixgbe_i2c_stop - Sets I2C stop condition
1823 * @hw: pointer to hardware structure
1824 *
1825 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1826 **/
1827static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1828{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001829 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001830
1831 /* Stop condition must begin with data low and clock high */
1832 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1833 ixgbe_raise_i2c_clk(hw, &i2cctl);
1834
1835 /* Setup time for stop condition (4us) */
1836 udelay(IXGBE_I2C_T_SU_STO);
1837
1838 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1839
1840 /* bus free time between stop and start (4.7us)*/
1841 udelay(IXGBE_I2C_T_BUF);
1842}
1843
1844/**
1845 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1846 * @hw: pointer to hardware structure
1847 * @data: data byte to clock in
1848 *
1849 * Clocks in one byte data via I2C data/clock
1850 **/
1851static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1852{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001853 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001854 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001855
1856 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001857 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001858 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001859 }
1860
Emil Tantilove1befd72011-08-27 07:18:47 +00001861 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001862}
1863
1864/**
1865 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1866 * @hw: pointer to hardware structure
1867 * @data: data byte clocked out
1868 *
1869 * Clocks out one byte data via I2C data/clock
1870 **/
1871static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1872{
Mark Rustade90dd262014-07-22 06:51:08 +00001873 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001874 s32 i;
1875 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001876 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001877
1878 for (i = 7; i >= 0; i--) {
1879 bit = (data >> i) & 0x1;
1880 status = ixgbe_clock_out_i2c_bit(hw, bit);
1881
1882 if (status != 0)
1883 break;
1884 }
1885
1886 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07001887 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1888 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1889 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001890 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001891
1892 return status;
1893}
1894
1895/**
1896 * ixgbe_get_i2c_ack - Polls for I2C ACK
1897 * @hw: pointer to hardware structure
1898 *
1899 * Clocks in/out one bit via I2C data/clock
1900 **/
1901static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1902{
Emil Tantilove1befd72011-08-27 07:18:47 +00001903 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001904 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001905 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001906 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001907 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001908
Emil Tantilove1befd72011-08-27 07:18:47 +00001909 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001910
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001911
1912 /* Minimum high period of clock is 4us */
1913 udelay(IXGBE_I2C_T_HIGH);
1914
1915 /* Poll for ACK. Note that ACK in I2C spec is
1916 * transition from 1 to 0 */
1917 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07001918 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001919 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001920
1921 udelay(1);
1922 if (ack == 0)
1923 break;
1924 }
1925
1926 if (ack == 1) {
1927 hw_dbg(hw, "I2C ack was not received.\n");
1928 status = IXGBE_ERR_I2C;
1929 }
1930
1931 ixgbe_lower_i2c_clk(hw, &i2cctl);
1932
1933 /* Minimum low period of clock is 4.7 us */
1934 udelay(IXGBE_I2C_T_LOW);
1935
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001936 return status;
1937}
1938
1939/**
1940 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1941 * @hw: pointer to hardware structure
1942 * @data: read data value
1943 *
1944 * Clocks in one bit via I2C data/clock
1945 **/
1946static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1947{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001948 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001949
Emil Tantilove1befd72011-08-27 07:18:47 +00001950 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001951
1952 /* Minimum high period of clock is 4us */
1953 udelay(IXGBE_I2C_T_HIGH);
1954
Don Skidmore9a900ec2015-06-09 17:15:01 -07001955 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001956 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001957
1958 ixgbe_lower_i2c_clk(hw, &i2cctl);
1959
1960 /* Minimum low period of clock is 4.7 us */
1961 udelay(IXGBE_I2C_T_LOW);
1962
Emil Tantilove1befd72011-08-27 07:18:47 +00001963 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001964}
1965
1966/**
1967 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1968 * @hw: pointer to hardware structure
1969 * @data: data value to write
1970 *
1971 * Clocks out one bit via I2C data/clock
1972 **/
1973static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1974{
1975 s32 status;
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
1978 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1979 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001980 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001981
1982 /* Minimum high period of clock is 4us */
1983 udelay(IXGBE_I2C_T_HIGH);
1984
1985 ixgbe_lower_i2c_clk(hw, &i2cctl);
1986
1987 /* Minimum low period of clock is 4.7 us.
1988 * This also takes care of the data hold time.
1989 */
1990 udelay(IXGBE_I2C_T_LOW);
1991 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001992 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001993 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001994 }
1995
Mark Rustade90dd262014-07-22 06:51:08 +00001996 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001997}
1998/**
1999 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2000 * @hw: pointer to hardware structure
2001 * @i2cctl: Current value of I2CCTL register
2002 *
2003 * Raises the I2C clock line '0'->'1'
2004 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002005static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002006{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002007 u32 i = 0;
2008 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2009 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002010
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002011 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002012 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2013 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002014 IXGBE_WRITE_FLUSH(hw);
2015 /* SCL rise time (1000ns) */
2016 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002017
Don Skidmore9a900ec2015-06-09 17:15:01 -07002018 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2019 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002020 break;
2021 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002022}
2023
2024/**
2025 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2026 * @hw: pointer to hardware structure
2027 * @i2cctl: Current value of I2CCTL register
2028 *
2029 * Lowers the I2C clock line '1'->'0'
2030 **/
2031static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2032{
2033
Don Skidmore9a900ec2015-06-09 17:15:01 -07002034 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002035
Don Skidmore9a900ec2015-06-09 17:15:01 -07002036 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002037 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002038
2039 /* SCL fall time (300ns) */
2040 udelay(IXGBE_I2C_T_FALL);
2041}
2042
2043/**
2044 * ixgbe_set_i2c_data - Sets the I2C data bit
2045 * @hw: pointer to hardware structure
2046 * @i2cctl: Current value of I2CCTL register
2047 * @data: I2C data value (0 or 1) to set
2048 *
2049 * Sets the I2C data bit
2050 **/
2051static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2052{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002053 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002054 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002055 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002056 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002057
Don Skidmore9a900ec2015-06-09 17:15:01 -07002058 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002059 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002060
2061 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2062 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2063
2064 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002065 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002066 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002067 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002068 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002069 }
2070
Mark Rustade90dd262014-07-22 06:51:08 +00002071 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002072}
2073
2074/**
2075 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2076 * @hw: pointer to hardware structure
2077 * @i2cctl: Current value of I2CCTL register
2078 *
2079 * Returns the I2C data bit value
2080 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002081static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002082{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002083 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002084 return true;
2085 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002086}
2087
2088/**
2089 * ixgbe_i2c_bus_clear - Clears the I2C bus
2090 * @hw: pointer to hardware structure
2091 *
2092 * Clears the I2C bus by sending nine clock pulses.
2093 * Used when data line is stuck low.
2094 **/
2095static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2096{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002097 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002098 u32 i;
2099
Emil Tantilov75f19c32011-02-19 08:43:55 +00002100 ixgbe_i2c_start(hw);
2101
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002102 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2103
2104 for (i = 0; i < 9; i++) {
2105 ixgbe_raise_i2c_clk(hw, &i2cctl);
2106
2107 /* Min high period of clock is 4us */
2108 udelay(IXGBE_I2C_T_HIGH);
2109
2110 ixgbe_lower_i2c_clk(hw, &i2cctl);
2111
2112 /* Min low period of clock is 4.7us*/
2113 udelay(IXGBE_I2C_T_LOW);
2114 }
2115
Emil Tantilov75f19c32011-02-19 08:43:55 +00002116 ixgbe_i2c_start(hw);
2117
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002118 /* Put the i2c bus back to default state */
2119 ixgbe_i2c_stop(hw);
2120}
2121
2122/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002123 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002124 * @hw: pointer to hardware structure
2125 *
2126 * Checks if the LASI temp alarm status was triggered due to overtemp
2127 **/
2128s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2129{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002130 u16 phy_data = 0;
2131
2132 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002133 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002134
2135 /* Check that the LASI temp alarm status was triggered */
2136 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002137 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002138
2139 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002140 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002141
Mark Rustade90dd262014-07-22 06:51:08 +00002142 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002143}
Don Skidmore961fac82015-06-09 16:09:47 -07002144
2145/** ixgbe_set_copper_phy_power - Control power for copper phy
2146 * @hw: pointer to hardware structure
2147 * @on: true for on, false for off
2148 **/
2149s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2150{
2151 u32 status;
2152 u16 reg;
2153
2154 /* Bail if we don't have copper phy */
2155 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2156 return 0;
2157
2158 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2159 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2160 &reg);
2161 if (status)
2162 return status;
2163
2164 if (on) {
2165 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2166 } else {
2167 if (ixgbe_check_reset_blocked(hw))
2168 return 0;
2169 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2170 }
2171
2172 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2173 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2174 reg);
2175 return status;
2176}