blob: 597d0b1c23701eadad2c3d9a68448acc7d4c941c [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) {
Don Skidmored5702de2015-06-19 12:23:36 -0400246 if (hw->bus.lan_id)
Don Skidmore030eaec2014-11-29 05:22:37 +0000247 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
248 else
249 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
250 }
251
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700252 if (hw->phy.type == ixgbe_phy_unknown) {
253 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +0000254 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +0000255 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700256 ixgbe_get_phy_id(hw);
257 hw->phy.type =
Jacob Kellere7cf7452014-04-09 06:03:10 +0000258 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +0000259
260 if (hw->phy.type == ixgbe_phy_unknown) {
261 hw->phy.ops.read_reg(hw,
262 MDIO_PMA_EXTABLE,
263 MDIO_MMD_PMAPMD,
264 &ext_ability);
265 if (ext_ability &
266 (MDIO_PMA_EXTABLE_10GBT |
267 MDIO_PMA_EXTABLE_1000BT))
268 hw->phy.type =
269 ixgbe_phy_cu_unknown;
270 else
271 hw->phy.type =
272 ixgbe_phy_generic;
273 }
274
Mark Rustade90dd262014-07-22 06:51:08 +0000275 return 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700276 }
Auke Kok9a799d72007-09-15 14:07:45 -0700277 }
Don Skidmore63d6e1d2009-07-02 12:50:12 +0000278 /* clear value if nothing found */
Mark Rustade90dd262014-07-22 06:51:08 +0000279 hw->phy.mdio.prtad = 0;
280 return IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700281 }
Mark Rustade90dd262014-07-22 06:51:08 +0000282 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700283}
284
285/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800286 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
287 * @hw: pointer to the hardware structure
288 *
289 * This function checks the MMNGC.MNG_VETO bit to see if there are
290 * any constraints on link from manageability. For MAC's that don't
291 * have this bit just return false since the link can not be blocked
292 * via this method.
293 **/
Jean Sacren6425f0f2014-03-11 05:57:56 +0000294bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
Don Skidmorec97506a2014-02-27 20:32:43 -0800295{
296 u32 mmngc;
297
298 /* If we don't have this bit, it can't be blocking */
299 if (hw->mac.type == ixgbe_mac_82598EB)
300 return false;
301
302 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
303 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
304 hw_dbg(hw, "MNG_VETO bit detected.\n");
305 return true;
306 }
307
308 return false;
309}
310
311/**
Auke Kok9a799d72007-09-15 14:07:45 -0700312 * ixgbe_get_phy_id - Get the phy type
313 * @hw: pointer to hardware structure
314 *
315 **/
316static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
317{
Mark Rustada1e869d2015-04-10 10:36:36 -0700318 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700319 u16 phy_id_high = 0;
320 u16 phy_id_low = 0;
321
Ben Hutchings6b73e102009-04-29 08:08:58 +0000322 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000323 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700324
Mark Rustada1e869d2015-04-10 10:36:36 -0700325 if (!status) {
Auke Kok9a799d72007-09-15 14:07:45 -0700326 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000327 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000328 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700329 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
330 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
331 }
Auke Kok9a799d72007-09-15 14:07:45 -0700332 return status;
333}
334
335/**
336 * ixgbe_get_phy_type_from_id - Get the phy type
337 * @hw: pointer to hardware structure
338 *
339 **/
340static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
341{
342 enum ixgbe_phy_type phy_type;
343
344 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700345 case TN1010_PHY_ID:
346 phy_type = ixgbe_phy_tn;
347 break;
Don Skidmorededa5622015-06-09 17:39:46 -0700348 case X550_PHY_ID:
Don Skidmore2b264902010-12-09 06:55:14 +0000349 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800350 phy_type = ixgbe_phy_aq;
351 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700352 case QT2022_PHY_ID:
353 phy_type = ixgbe_phy_qt;
354 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800355 case ATH_PHY_ID:
356 phy_type = ixgbe_phy_nl;
357 break;
Don Skidmorec2c78d52015-06-09 16:04:59 -0700358 case X557_PHY_ID:
359 phy_type = ixgbe_phy_x550em_ext_t;
360 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700361 default:
362 phy_type = ixgbe_phy_unknown;
363 break;
364 }
365
366 return phy_type;
367}
368
369/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700370 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700371 * @hw: pointer to hardware structure
372 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700373s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700374{
Emil Tantilov17835752011-02-16 01:38:13 +0000375 u32 i;
376 u16 ctrl = 0;
377 s32 status = 0;
378
379 if (hw->phy.type == ixgbe_phy_unknown)
380 status = ixgbe_identify_phy_generic(hw);
381
382 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000383 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000384
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700385 /* Don't reset PHY if it's shut down due to overtemp. */
386 if (!hw->phy.reset_if_overtemp &&
387 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000388 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700389
Don Skidmorec97506a2014-02-27 20:32:43 -0800390 /* Blocked by MNG FW so bail */
391 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000392 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800393
Auke Kok9a799d72007-09-15 14:07:45 -0700394 /*
395 * Perform soft PHY reset to the PHY_XS.
396 * This will cause a soft reset to the PHY
397 */
Emil Tantilov17835752011-02-16 01:38:13 +0000398 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
399 MDIO_MMD_PHYXS,
400 MDIO_CTRL1_RESET);
401
402 /*
403 * Poll for reset bit to self-clear indicating reset is complete.
404 * Some PHYs could take up to 3 seconds to complete and need about
405 * 1.7 usec delay after the reset is complete.
406 */
407 for (i = 0; i < 30; i++) {
408 msleep(100);
409 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
410 MDIO_MMD_PHYXS, &ctrl);
411 if (!(ctrl & MDIO_CTRL1_RESET)) {
412 udelay(2);
413 break;
414 }
415 }
416
417 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000418 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000419 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000420 }
421
Mark Rustade90dd262014-07-22 06:51:08 +0000422 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700423}
424
425/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000426 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
427 * the SWFW lock
428 * @hw: pointer to hardware structure
429 * @reg_addr: 32 bit address of PHY register to read
430 * @phy_data: Pointer to read data from PHY register
431 **/
432s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
433 u16 *phy_data)
434{
435 u32 i, data, command;
436
437 /* Setup and write the address cycle command */
438 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
439 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
440 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
441 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
442
443 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
444
445 /* Check every 10 usec to see if the address cycle completed.
446 * The MDI Command bit will clear when the operation is
447 * complete
448 */
449 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
450 udelay(10);
451
452 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
453 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
454 break;
455 }
456
457
458 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
459 hw_dbg(hw, "PHY address command did not complete.\n");
460 return IXGBE_ERR_PHY;
461 }
462
463 /* Address cycle complete, setup and write the read
464 * command
465 */
466 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
467 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
468 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
469 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
470
471 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
472
473 /* Check every 10 usec to see if the address cycle
474 * completed. The MDI Command bit will clear when the
475 * operation is complete
476 */
477 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
478 udelay(10);
479
480 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
481 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
482 break;
483 }
484
485 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
486 hw_dbg(hw, "PHY read command didn't complete\n");
487 return IXGBE_ERR_PHY;
488 }
489
490 /* Read operation is complete. Get the data
491 * from MSRWD
492 */
493 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
494 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
495 *phy_data = (u16)(data);
496
497 return 0;
498}
499
500/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700501 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000502 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700503 * @hw: pointer to hardware structure
504 * @reg_addr: 32 bit address of PHY register to read
505 * @phy_data: Pointer to read data from PHY register
506 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700507s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000508 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700509{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000510 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000511 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700512
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000513 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
514 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
515 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000516 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000517 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000518 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700519 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700520
Auke Kok9a799d72007-09-15 14:07:45 -0700521 return status;
522}
523
524/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000525 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
526 * without SWFW lock
527 * @hw: pointer to hardware structure
528 * @reg_addr: 32 bit PHY register to write
529 * @device_type: 5 bit device type
530 * @phy_data: Data to write to the PHY register
531 **/
532s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
533 u32 device_type, u16 phy_data)
534{
535 u32 i, command;
536
537 /* Put the data in the MDI single read and write data register*/
538 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
539
540 /* Setup and write the address cycle command */
541 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
542 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
543 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
544 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
545
546 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
547
548 /*
549 * Check every 10 usec to see if the address cycle completed.
550 * The MDI Command bit will clear when the operation is
551 * complete
552 */
553 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
554 udelay(10);
555
556 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
557 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
558 break;
559 }
560
561 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
562 hw_dbg(hw, "PHY address cmd didn't complete\n");
563 return IXGBE_ERR_PHY;
564 }
565
566 /*
567 * Address cycle complete, setup and write the write
568 * command
569 */
570 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
571 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
572 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
573 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
574
575 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
576
577 /* Check every 10 usec to see if the address cycle
578 * completed. The MDI Command bit will clear when the
579 * operation is complete
580 */
581 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
582 udelay(10);
583
584 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
585 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
586 break;
587 }
588
589 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
590 hw_dbg(hw, "PHY write cmd didn't complete\n");
591 return IXGBE_ERR_PHY;
592 }
593
594 return 0;
595}
596
597/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700598 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000599 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700600 * @hw: pointer to hardware structure
601 * @reg_addr: 32 bit PHY register to write
602 * @device_type: 5 bit device type
603 * @phy_data: Data to write to the PHY register
604 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700605s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000606 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700607{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000608 s32 status;
Don Skidmore897b9342015-06-19 19:14:57 -0400609 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700610
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000611 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
612 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
613 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000614 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000615 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000616 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700617 }
618
619 return status;
620}
621
622/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700623 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700624 * @hw: pointer to hardware structure
625 *
626 * Restart autonegotiation and PHY and waits for completion.
627 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700628s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700629{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000630 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000631 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
632 bool autoneg = false;
633 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700634
Emil Tantilov9dda1732011-03-05 01:28:07 +0000635 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700636
Emil Tantilov9dda1732011-03-05 01:28:07 +0000637 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
638 /* Set or unset auto-negotiation 10G advertisement */
639 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
640 MDIO_MMD_AN,
641 &autoneg_reg);
642
Ben Hutchings6b73e102009-04-29 08:08:58 +0000643 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000644 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
645 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700646
Emil Tantilov9dda1732011-03-05 01:28:07 +0000647 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
648 MDIO_MMD_AN,
649 autoneg_reg);
650 }
651
652 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
653 /* Set or unset auto-negotiation 1G advertisement */
654 hw->phy.ops.read_reg(hw,
655 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
656 MDIO_MMD_AN,
657 &autoneg_reg);
658
659 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
660 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
661 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
662
663 hw->phy.ops.write_reg(hw,
664 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
665 MDIO_MMD_AN,
666 autoneg_reg);
667 }
668
669 if (speed & IXGBE_LINK_SPEED_100_FULL) {
670 /* Set or unset auto-negotiation 100M advertisement */
671 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
672 MDIO_MMD_AN,
673 &autoneg_reg);
674
Emil Tantilova59e8a12011-03-31 09:36:12 +0000675 autoneg_reg &= ~(ADVERTISE_100FULL |
676 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000677 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
678 autoneg_reg |= ADVERTISE_100FULL;
679
680 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
681 MDIO_MMD_AN,
682 autoneg_reg);
683 }
Auke Kok9a799d72007-09-15 14:07:45 -0700684
Don Skidmorec97506a2014-02-27 20:32:43 -0800685 /* Blocked by MNG FW so don't reset PHY */
686 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000687 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800688
Auke Kok9a799d72007-09-15 14:07:45 -0700689 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000690 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
691 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700692
Ben Hutchings6b73e102009-04-29 08:08:58 +0000693 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700694
Emil Tantilov9dda1732011-03-05 01:28:07 +0000695 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
696 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700697
Auke Kok9a799d72007-09-15 14:07:45 -0700698 return status;
699}
700
701/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700702 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700703 * @hw: pointer to hardware structure
704 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700705 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700706s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000707 ixgbe_link_speed speed,
708 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700709{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700710
Auke Kok9a799d72007-09-15 14:07:45 -0700711 /*
712 * Clear autoneg_advertised and set new values based on input link
713 * speed.
714 */
715 hw->phy.autoneg_advertised = 0;
716
717 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
718 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700719
Auke Kok9a799d72007-09-15 14:07:45 -0700720 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
721 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
722
Emil Tantilov9dda1732011-03-05 01:28:07 +0000723 if (speed & IXGBE_LINK_SPEED_100_FULL)
724 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
725
Auke Kok9a799d72007-09-15 14:07:45 -0700726 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700727 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700728
729 return 0;
730}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700731
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700732/**
Mark Rustadae8140a2015-06-25 17:49:57 -0700733 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
734 * @hw: pointer to hardware structure
735 *
736 * Determines the supported link capabilities by reading the PHY auto
737 * negotiation register.
738 */
739static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
740{
741 u16 speed_ability;
742 s32 status;
743
744 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
745 &speed_ability);
746 if (status)
747 return status;
748
749 if (speed_ability & MDIO_SPEED_10G)
750 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
751 if (speed_ability & MDIO_PMA_SPEED_1000)
752 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
753 if (speed_ability & MDIO_PMA_SPEED_100)
754 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
755
756 switch (hw->mac.type) {
757 case ixgbe_mac_X550:
758 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
759 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
760 break;
761 case ixgbe_mac_X550EM_x:
762 hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
763 break;
764 default:
765 break;
766 }
767
768 return 0;
769}
770
771/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800772 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
773 * @hw: pointer to hardware structure
774 * @speed: pointer to link speed
775 * @autoneg: boolean auto-negotiation value
Don Skidmorea391f1d2010-11-16 19:27:15 -0800776 */
777s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000778 ixgbe_link_speed *speed,
779 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800780{
Mark Rustadae8140a2015-06-25 17:49:57 -0700781 s32 status = 0;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800782
Don Skidmorea391f1d2010-11-16 19:27:15 -0800783 *autoneg = true;
Mark Rustadae8140a2015-06-25 17:49:57 -0700784 if (!hw->phy.speeds_supported)
785 status = ixgbe_get_copper_speeds_supported(hw);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800786
Mark Rustadae8140a2015-06-25 17:49:57 -0700787 *speed = hw->phy.speeds_supported;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800788 return status;
789}
790
791/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000792 * ixgbe_check_phy_link_tnx - Determine link and speed status
793 * @hw: pointer to hardware structure
794 *
795 * Reads the VS1 register to determine if link is up and the current speed for
796 * the PHY.
797 **/
798s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
799 bool *link_up)
800{
Mark Rustade90dd262014-07-22 06:51:08 +0000801 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000802 u32 time_out;
803 u32 max_time_out = 10;
804 u16 phy_link = 0;
805 u16 phy_speed = 0;
806 u16 phy_data = 0;
807
808 /* Initialize speed and link to default case */
809 *link_up = false;
810 *speed = IXGBE_LINK_SPEED_10GB_FULL;
811
812 /*
813 * Check current speed and link status of the PHY register.
814 * This is a vendor specific register and may have to
815 * be changed for other copper PHYs.
816 */
817 for (time_out = 0; time_out < max_time_out; time_out++) {
818 udelay(10);
819 status = hw->phy.ops.read_reg(hw,
820 MDIO_STAT1,
821 MDIO_MMD_VEND1,
822 &phy_data);
823 phy_link = phy_data &
824 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
825 phy_speed = phy_data &
826 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
827 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
828 *link_up = true;
829 if (phy_speed ==
830 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
831 *speed = IXGBE_LINK_SPEED_1GB_FULL;
832 break;
833 }
834 }
835
836 return status;
837}
838
839/**
840 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
841 * @hw: pointer to hardware structure
842 *
843 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000844 * This function always returns success, this is nessary since
845 * it is called via a function pointer that could call other
846 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000847 **/
848s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
849{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000850 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
851 bool autoneg = false;
852 ixgbe_link_speed speed;
853
854 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
855
856 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
857 /* Set or unset auto-negotiation 10G advertisement */
858 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
859 MDIO_MMD_AN,
860 &autoneg_reg);
861
862 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
863 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
864 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
865
866 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
867 MDIO_MMD_AN,
868 autoneg_reg);
869 }
870
871 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
872 /* Set or unset auto-negotiation 1G advertisement */
873 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
874 MDIO_MMD_AN,
875 &autoneg_reg);
876
877 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
878 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
879 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
880
881 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
882 MDIO_MMD_AN,
883 autoneg_reg);
884 }
885
886 if (speed & IXGBE_LINK_SPEED_100_FULL) {
887 /* Set or unset auto-negotiation 100M advertisement */
888 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
889 MDIO_MMD_AN,
890 &autoneg_reg);
891
Emil Tantilov50c022e2011-03-31 09:36:12 +0000892 autoneg_reg &= ~(ADVERTISE_100FULL |
893 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000894 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
895 autoneg_reg |= ADVERTISE_100FULL;
896
897 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
898 MDIO_MMD_AN,
899 autoneg_reg);
900 }
901
Don Skidmorec97506a2014-02-27 20:32:43 -0800902 /* Blocked by MNG FW so don't reset PHY */
903 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000904 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800905
Emil Tantilov9dda1732011-03-05 01:28:07 +0000906 /* Restart PHY autonegotiation and wait for completion */
907 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
908 MDIO_MMD_AN, &autoneg_reg);
909
910 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
911
912 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
913 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000914 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000915}
916
917/**
918 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
919 * @hw: pointer to hardware structure
920 * @firmware_version: pointer to the PHY Firmware Version
921 **/
922s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
923 u16 *firmware_version)
924{
Mark Rustade90dd262014-07-22 06:51:08 +0000925 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000926
927 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
928 MDIO_MMD_VEND1,
929 firmware_version);
930
931 return status;
932}
933
934/**
935 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
936 * @hw: pointer to hardware structure
937 * @firmware_version: pointer to the PHY Firmware Version
938 **/
939s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
940 u16 *firmware_version)
941{
Mark Rustade90dd262014-07-22 06:51:08 +0000942 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000943
944 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
945 MDIO_MMD_VEND1,
946 firmware_version);
947
948 return status;
949}
950
951/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800952 * ixgbe_reset_phy_nl - Performs a PHY reset
953 * @hw: pointer to hardware structure
954 **/
955s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
956{
957 u16 phy_offset, control, eword, edata, block_crc;
958 bool end_data = false;
959 u16 list_offset, data_offset;
960 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000961 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800962 u32 i;
963
Don Skidmorec97506a2014-02-27 20:32:43 -0800964 /* Blocked by MNG FW so bail */
965 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000966 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800967
Ben Hutchings6b73e102009-04-29 08:08:58 +0000968 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800969
970 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000971 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000972 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800973
974 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000975 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000976 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000977 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800978 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000979 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800980 }
981
Ben Hutchings6b73e102009-04-29 08:08:58 +0000982 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800983 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000984 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800985 }
986
987 /* Get init offsets */
988 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000989 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000990 if (ret_val)
991 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800992
993 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
994 data_offset++;
995 while (!end_data) {
996 /*
997 * Read control word from PHY init contents offset
998 */
999 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001000 if (ret_val)
1001 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001002 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +00001003 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001004 edata = eword & IXGBE_DATA_MASK_NL;
1005 switch (control) {
1006 case IXGBE_DELAY_NL:
1007 data_offset++;
1008 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +00001009 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001010 break;
1011 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +00001012 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001013 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001014 ret_val = hw->eeprom.ops.read(hw, data_offset++,
1015 &phy_offset);
1016 if (ret_val)
1017 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001018 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001019 ret_val = hw->eeprom.ops.read(hw, data_offset,
1020 &eword);
1021 if (ret_val)
1022 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001023 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001024 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001025 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1026 phy_offset);
1027 data_offset++;
1028 phy_offset++;
1029 }
1030 break;
1031 case IXGBE_CONTROL_NL:
1032 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001033 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001034 if (edata == IXGBE_CONTROL_EOL_NL) {
1035 hw_dbg(hw, "EOL\n");
1036 end_data = true;
1037 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1038 hw_dbg(hw, "SOL\n");
1039 } else {
1040 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001041 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001042 }
1043 break;
1044 default:
1045 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001046 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001047 }
1048 }
1049
Donald Skidmorec4900be2008-11-20 21:11:42 -08001050 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001051
1052err_eeprom:
1053 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1054 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001055}
1056
1057/**
Don Skidmore8f583322013-07-27 06:25:38 +00001058 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001059 * @hw: pointer to hardware structure
1060 *
Don Skidmore8f583322013-07-27 06:25:38 +00001061 * Determines HW type and calls appropriate function.
1062 **/
1063s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1064{
Don Skidmore8f583322013-07-27 06:25:38 +00001065 switch (hw->mac.ops.get_media_type(hw)) {
1066 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001067 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001068 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001069 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001070 default:
1071 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001072 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001073 }
1074
Mark Rustade90dd262014-07-22 06:51:08 +00001075 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001076}
1077
1078/**
1079 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1080 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001081 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001082 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001083 **/
1084s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1085{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001086 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001087 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001088 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001089 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001090 u8 identifier = 0;
1091 u8 comp_codes_1g = 0;
1092 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001093 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001094 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001095 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001096 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001097
Don Skidmore8ca783a2009-05-26 20:40:47 -07001098 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1099 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001100 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001101 }
1102
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001103 status = hw->phy.ops.read_i2c_eeprom(hw,
1104 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001105 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001106
Mark Rustade90dd262014-07-22 06:51:08 +00001107 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001108 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001109
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001110 /* LAN ID is needed for sfp_type determination */
1111 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001112
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001113 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1114 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001115 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1116 }
1117 status = hw->phy.ops.read_i2c_eeprom(hw,
1118 IXGBE_SFF_1GBE_COMP_CODES,
1119 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001120
Mark Rustade90dd262014-07-22 06:51:08 +00001121 if (status)
1122 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001123
Mark Rustade90dd262014-07-22 06:51:08 +00001124 status = hw->phy.ops.read_i2c_eeprom(hw,
1125 IXGBE_SFF_10GBE_COMP_CODES,
1126 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001127
Mark Rustade90dd262014-07-22 06:51:08 +00001128 if (status)
1129 goto err_read_i2c_eeprom;
1130 status = hw->phy.ops.read_i2c_eeprom(hw,
1131 IXGBE_SFF_CABLE_TECHNOLOGY,
1132 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001133
Mark Rustade90dd262014-07-22 06:51:08 +00001134 if (status)
1135 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001136
Mark Rustade90dd262014-07-22 06:51:08 +00001137 /* ID Module
1138 * =========
1139 * 0 SFP_DA_CU
1140 * 1 SFP_SR
1141 * 2 SFP_LR
1142 * 3 SFP_DA_CORE0 - 82599-specific
1143 * 4 SFP_DA_CORE1 - 82599-specific
1144 * 5 SFP_SR/LR_CORE0 - 82599-specific
1145 * 6 SFP_SR/LR_CORE1 - 82599-specific
1146 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1147 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1148 * 9 SFP_1g_cu_CORE0 - 82599-specific
1149 * 10 SFP_1g_cu_CORE1 - 82599-specific
1150 * 11 SFP_1g_sx_CORE0 - 82599-specific
1151 * 12 SFP_1g_sx_CORE1 - 82599-specific
1152 */
1153 if (hw->mac.type == ixgbe_mac_82598EB) {
1154 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1155 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1156 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1157 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1158 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1159 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1160 else
1161 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1162 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1163 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1164 if (hw->bus.lan_id == 0)
1165 hw->phy.sfp_type =
1166 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001167 else
Mark Rustade90dd262014-07-22 06:51:08 +00001168 hw->phy.sfp_type =
1169 ixgbe_sfp_type_da_cu_core1;
1170 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1171 hw->phy.ops.read_i2c_eeprom(
1172 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1173 &cable_spec);
1174 if (cable_spec &
1175 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001176 if (hw->bus.lan_id == 0)
1177 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001178 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001179 else
1180 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001181 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001182 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001183 hw->phy.sfp_type =
1184 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001185 }
Mark Rustade90dd262014-07-22 06:51:08 +00001186 } else if (comp_codes_10g &
1187 (IXGBE_SFF_10GBASESR_CAPABLE |
1188 IXGBE_SFF_10GBASELR_CAPABLE)) {
1189 if (hw->bus.lan_id == 0)
1190 hw->phy.sfp_type =
1191 ixgbe_sfp_type_srlr_core0;
1192 else
1193 hw->phy.sfp_type =
1194 ixgbe_sfp_type_srlr_core1;
1195 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1196 if (hw->bus.lan_id == 0)
1197 hw->phy.sfp_type =
1198 ixgbe_sfp_type_1g_cu_core0;
1199 else
1200 hw->phy.sfp_type =
1201 ixgbe_sfp_type_1g_cu_core1;
1202 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1203 if (hw->bus.lan_id == 0)
1204 hw->phy.sfp_type =
1205 ixgbe_sfp_type_1g_sx_core0;
1206 else
1207 hw->phy.sfp_type =
1208 ixgbe_sfp_type_1g_sx_core1;
1209 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1210 if (hw->bus.lan_id == 0)
1211 hw->phy.sfp_type =
1212 ixgbe_sfp_type_1g_lx_core0;
1213 else
1214 hw->phy.sfp_type =
1215 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001216 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001217 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001218 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001219 }
1220
Mark Rustade90dd262014-07-22 06:51:08 +00001221 if (hw->phy.sfp_type != stored_sfp_type)
1222 hw->phy.sfp_setup_needed = true;
1223
1224 /* Determine if the SFP+ PHY is dual speed or not. */
1225 hw->phy.multispeed_fiber = false;
1226 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1227 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1228 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1229 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1230 hw->phy.multispeed_fiber = true;
1231
1232 /* Determine PHY vendor */
1233 if (hw->phy.type != ixgbe_phy_nl) {
1234 hw->phy.id = identifier;
1235 status = hw->phy.ops.read_i2c_eeprom(hw,
1236 IXGBE_SFF_VENDOR_OUI_BYTE0,
1237 &oui_bytes[0]);
1238
1239 if (status != 0)
1240 goto err_read_i2c_eeprom;
1241
1242 status = hw->phy.ops.read_i2c_eeprom(hw,
1243 IXGBE_SFF_VENDOR_OUI_BYTE1,
1244 &oui_bytes[1]);
1245
1246 if (status != 0)
1247 goto err_read_i2c_eeprom;
1248
1249 status = hw->phy.ops.read_i2c_eeprom(hw,
1250 IXGBE_SFF_VENDOR_OUI_BYTE2,
1251 &oui_bytes[2]);
1252
1253 if (status != 0)
1254 goto err_read_i2c_eeprom;
1255
1256 vendor_oui =
1257 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1258 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1259 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1260
1261 switch (vendor_oui) {
1262 case IXGBE_SFF_VENDOR_OUI_TYCO:
1263 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1264 hw->phy.type =
1265 ixgbe_phy_sfp_passive_tyco;
1266 break;
1267 case IXGBE_SFF_VENDOR_OUI_FTL:
1268 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1269 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1270 else
1271 hw->phy.type = ixgbe_phy_sfp_ftl;
1272 break;
1273 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1274 hw->phy.type = ixgbe_phy_sfp_avago;
1275 break;
1276 case IXGBE_SFF_VENDOR_OUI_INTEL:
1277 hw->phy.type = ixgbe_phy_sfp_intel;
1278 break;
1279 default:
1280 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1281 hw->phy.type =
1282 ixgbe_phy_sfp_passive_unknown;
1283 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1284 hw->phy.type =
1285 ixgbe_phy_sfp_active_unknown;
1286 else
1287 hw->phy.type = ixgbe_phy_sfp_unknown;
1288 break;
1289 }
1290 }
1291
1292 /* Allow any DA cable vendor */
1293 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1294 IXGBE_SFF_DA_ACTIVE_CABLE))
1295 return 0;
1296
1297 /* Verify supported 1G SFP modules */
1298 if (comp_codes_10g == 0 &&
1299 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1300 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
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 hw->phy.type = ixgbe_phy_sfp_unsupported;
1306 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1307 }
1308
1309 /* Anything else 82598-based is supported */
1310 if (hw->mac.type == ixgbe_mac_82598EB)
1311 return 0;
1312
1313 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1314 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1315 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1316 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1317 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1318 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1319 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1320 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1321 /* Make sure we're a supported PHY type */
1322 if (hw->phy.type == ixgbe_phy_sfp_intel)
1323 return 0;
1324 if (hw->allow_unsupported_sfp) {
1325 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");
1326 return 0;
1327 }
1328 hw_dbg(hw, "SFP+ module not supported\n");
1329 hw->phy.type = ixgbe_phy_sfp_unsupported;
1330 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1331 }
1332 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001333
1334err_read_i2c_eeprom:
1335 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1336 if (hw->phy.type != ixgbe_phy_nl) {
1337 hw->phy.id = 0;
1338 hw->phy.type = ixgbe_phy_unknown;
1339 }
1340 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001341}
1342
1343/**
Don Skidmore8f583322013-07-27 06:25:38 +00001344 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1345 * @hw: pointer to hardware structure
1346 *
1347 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1348 **/
Mark Rustad88217542013-11-23 03:19:19 +00001349static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001350{
1351 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001352 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001353 u32 vendor_oui = 0;
1354 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1355 u8 identifier = 0;
1356 u8 comp_codes_1g = 0;
1357 u8 comp_codes_10g = 0;
1358 u8 oui_bytes[3] = {0, 0, 0};
1359 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001360 u8 connector = 0;
1361 u8 cable_length = 0;
1362 u8 device_tech = 0;
1363 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001364
1365 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1366 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001367 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001368 }
1369
Don Skidmore7e49d612015-06-09 17:48:54 -07001370 /* LAN ID is needed for sfp_type determination */
1371 hw->mac.ops.set_lan_id(hw);
1372
Don Skidmore8f583322013-07-27 06:25:38 +00001373 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1374 &identifier);
1375
1376 if (status != 0)
1377 goto err_read_i2c_eeprom;
1378
1379 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1380 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001381 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001382 }
1383
1384 hw->phy.id = identifier;
1385
Don Skidmore8f583322013-07-27 06:25:38 +00001386 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1387 &comp_codes_10g);
1388
1389 if (status != 0)
1390 goto err_read_i2c_eeprom;
1391
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001392 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1393 &comp_codes_1g);
1394
1395 if (status != 0)
1396 goto err_read_i2c_eeprom;
1397
Don Skidmore8f583322013-07-27 06:25:38 +00001398 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1399 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1400 if (hw->bus.lan_id == 0)
1401 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1402 else
1403 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001404 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1405 IXGBE_SFF_10GBASELR_CAPABLE)) {
1406 if (hw->bus.lan_id == 0)
1407 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1408 else
1409 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1410 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001411 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1412 active_cable = true;
1413
1414 if (!active_cable) {
1415 /* check for active DA cables that pre-date
1416 * SFF-8436 v3.6
1417 */
1418 hw->phy.ops.read_i2c_eeprom(hw,
1419 IXGBE_SFF_QSFP_CONNECTOR,
1420 &connector);
1421
1422 hw->phy.ops.read_i2c_eeprom(hw,
1423 IXGBE_SFF_QSFP_CABLE_LENGTH,
1424 &cable_length);
1425
1426 hw->phy.ops.read_i2c_eeprom(hw,
1427 IXGBE_SFF_QSFP_DEVICE_TECH,
1428 &device_tech);
1429
1430 if ((connector ==
1431 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1432 (cable_length > 0) &&
1433 ((device_tech >> 4) ==
1434 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1435 active_cable = true;
1436 }
1437
1438 if (active_cable) {
1439 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1440 if (hw->bus.lan_id == 0)
1441 hw->phy.sfp_type =
1442 ixgbe_sfp_type_da_act_lmt_core0;
1443 else
1444 hw->phy.sfp_type =
1445 ixgbe_sfp_type_da_act_lmt_core1;
1446 } else {
1447 /* unsupported module type */
1448 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001449 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001450 }
Don Skidmore8f583322013-07-27 06:25:38 +00001451 }
1452
1453 if (hw->phy.sfp_type != stored_sfp_type)
1454 hw->phy.sfp_setup_needed = true;
1455
1456 /* Determine if the QSFP+ PHY is dual speed or not. */
1457 hw->phy.multispeed_fiber = false;
1458 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1459 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1460 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1461 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1462 hw->phy.multispeed_fiber = true;
1463
1464 /* Determine PHY vendor for optical modules */
1465 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1466 IXGBE_SFF_10GBASELR_CAPABLE)) {
1467 status = hw->phy.ops.read_i2c_eeprom(hw,
1468 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1469 &oui_bytes[0]);
1470
1471 if (status != 0)
1472 goto err_read_i2c_eeprom;
1473
1474 status = hw->phy.ops.read_i2c_eeprom(hw,
1475 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1476 &oui_bytes[1]);
1477
1478 if (status != 0)
1479 goto err_read_i2c_eeprom;
1480
1481 status = hw->phy.ops.read_i2c_eeprom(hw,
1482 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1483 &oui_bytes[2]);
1484
1485 if (status != 0)
1486 goto err_read_i2c_eeprom;
1487
1488 vendor_oui =
1489 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1490 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1491 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1492
1493 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1494 hw->phy.type = ixgbe_phy_qsfp_intel;
1495 else
1496 hw->phy.type = ixgbe_phy_qsfp_unknown;
1497
1498 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1499 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1500 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001501 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1502 return 0;
1503 if (hw->allow_unsupported_sfp) {
1504 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");
1505 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001506 }
Mark Rustade90dd262014-07-22 06:51:08 +00001507 hw_dbg(hw, "QSFP module not supported\n");
1508 hw->phy.type = ixgbe_phy_sfp_unsupported;
1509 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001510 }
Mark Rustade90dd262014-07-22 06:51:08 +00001511 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001512 }
Mark Rustade90dd262014-07-22 06:51:08 +00001513 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001514
1515err_read_i2c_eeprom:
1516 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1517 hw->phy.id = 0;
1518 hw->phy.type = ixgbe_phy_unknown;
1519
1520 return IXGBE_ERR_SFP_NOT_PRESENT;
1521}
1522
1523/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001524 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001525 * @hw: pointer to hardware structure
1526 * @list_offset: offset to the SFP ID list
1527 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001528 *
1529 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1530 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001531 **/
1532s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001533 u16 *list_offset,
1534 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001535{
1536 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001537 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001538
1539 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1540 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1541
1542 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1543 return IXGBE_ERR_SFP_NOT_PRESENT;
1544
1545 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1546 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1547 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1548
Don Skidmorecb836a92010-06-29 18:30:59 +00001549 /*
1550 * Limiting active cables and 1G Phys must be initialized as
1551 * SR modules
1552 */
1553 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001554 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001555 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1556 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001557 sfp_type = ixgbe_sfp_type_srlr_core0;
1558 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001559 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001560 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1561 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001562 sfp_type = ixgbe_sfp_type_srlr_core1;
1563
Donald Skidmorec4900be2008-11-20 21:11:42 -08001564 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001565 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1566 hw_err(hw, "eeprom read at %d failed\n",
1567 IXGBE_PHY_INIT_OFFSET_NL);
1568 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1569 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001570
1571 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001572 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001573
1574 /* Shift offset to first ID word */
1575 (*list_offset)++;
1576
1577 /*
1578 * Find the matching SFP ID in the EEPROM
1579 * and program the init sequence
1580 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001581 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1582 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001583
1584 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001585 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001586 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001587 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1588 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001589 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1590 hw_dbg(hw, "SFP+ module not supported\n");
1591 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1592 } else {
1593 break;
1594 }
1595 } else {
1596 (*list_offset) += 2;
1597 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001598 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001599 }
1600 }
1601
1602 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1603 hw_dbg(hw, "No matching SFP+ module found\n");
1604 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1605 }
1606
1607 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001608
1609err_phy:
1610 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1611 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001612}
1613
1614/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001615 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1616 * @hw: pointer to hardware structure
1617 * @byte_offset: EEPROM byte offset to read
1618 * @eeprom_data: value read
1619 *
1620 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1621 **/
1622s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001623 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001624{
1625 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001626 IXGBE_I2C_EEPROM_DEV_ADDR,
1627 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001628}
1629
1630/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001631 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1632 * @hw: pointer to hardware structure
1633 * @byte_offset: byte offset at address 0xA2
1634 * @eeprom_data: value read
1635 *
1636 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1637 **/
1638s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1639 u8 *sff8472_data)
1640{
1641 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1642 IXGBE_I2C_EEPROM_DEV_ADDR2,
1643 sff8472_data);
1644}
1645
1646/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001647 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1648 * @hw: pointer to hardware structure
1649 * @byte_offset: EEPROM byte offset to write
1650 * @eeprom_data: value to write
1651 *
1652 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1653 **/
1654s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001655 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001656{
1657 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001658 IXGBE_I2C_EEPROM_DEV_ADDR,
1659 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001660}
1661
1662/**
1663 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1664 * @hw: pointer to hardware structure
1665 * @byte_offset: byte offset to read
1666 * @data: value read
1667 *
1668 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001669 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001670 **/
1671s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001672 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001673{
Mark Rustade90dd262014-07-22 06:51:08 +00001674 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001675 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001676 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001677 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001678 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001679 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001680
1681 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001682 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1683 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001684
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001685 ixgbe_i2c_start(hw);
1686
1687 /* Device Address and write indication */
1688 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1689 if (status != 0)
1690 goto fail;
1691
1692 status = ixgbe_get_i2c_ack(hw);
1693 if (status != 0)
1694 goto fail;
1695
1696 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1697 if (status != 0)
1698 goto fail;
1699
1700 status = ixgbe_get_i2c_ack(hw);
1701 if (status != 0)
1702 goto fail;
1703
1704 ixgbe_i2c_start(hw);
1705
1706 /* Device Address and read indication */
1707 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1708 if (status != 0)
1709 goto fail;
1710
1711 status = ixgbe_get_i2c_ack(hw);
1712 if (status != 0)
1713 goto fail;
1714
1715 status = ixgbe_clock_in_i2c_byte(hw, data);
1716 if (status != 0)
1717 goto fail;
1718
1719 status = ixgbe_clock_out_i2c_bit(hw, nack);
1720 if (status != 0)
1721 goto fail;
1722
1723 ixgbe_i2c_stop(hw);
1724 break;
1725
1726fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001727 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001728 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001729 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001730 retry++;
1731 if (retry < max_retry)
1732 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1733 else
1734 hw_dbg(hw, "I2C byte read error.\n");
1735
1736 } while (retry < max_retry);
1737
Emil Tantilov6d980c32011-04-13 04:56:15 +00001738 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001739
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001740 return status;
1741}
1742
1743/**
1744 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1745 * @hw: pointer to hardware structure
1746 * @byte_offset: byte offset to write
1747 * @data: value to write
1748 *
1749 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1750 * a specified device address.
1751 **/
1752s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001753 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001754{
Mark Rustade90dd262014-07-22 06:51:08 +00001755 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001756 u32 max_retry = 1;
1757 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001758 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001759
Mark Rustade90dd262014-07-22 06:51:08 +00001760 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1761 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001762
1763 do {
1764 ixgbe_i2c_start(hw);
1765
1766 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1767 if (status != 0)
1768 goto fail;
1769
1770 status = ixgbe_get_i2c_ack(hw);
1771 if (status != 0)
1772 goto fail;
1773
1774 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1775 if (status != 0)
1776 goto fail;
1777
1778 status = ixgbe_get_i2c_ack(hw);
1779 if (status != 0)
1780 goto fail;
1781
1782 status = ixgbe_clock_out_i2c_byte(hw, data);
1783 if (status != 0)
1784 goto fail;
1785
1786 status = ixgbe_get_i2c_ack(hw);
1787 if (status != 0)
1788 goto fail;
1789
1790 ixgbe_i2c_stop(hw);
1791 break;
1792
1793fail:
1794 ixgbe_i2c_bus_clear(hw);
1795 retry++;
1796 if (retry < max_retry)
1797 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1798 else
1799 hw_dbg(hw, "I2C byte write error.\n");
1800 } while (retry < max_retry);
1801
Emil Tantilov6d980c32011-04-13 04:56:15 +00001802 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001803
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001804 return status;
1805}
1806
1807/**
1808 * ixgbe_i2c_start - Sets I2C start condition
1809 * @hw: pointer to hardware structure
1810 *
1811 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1812 **/
1813static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1814{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001815 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001816
1817 /* Start condition must begin with data and clock high */
1818 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1819 ixgbe_raise_i2c_clk(hw, &i2cctl);
1820
1821 /* Setup time for start condition (4.7us) */
1822 udelay(IXGBE_I2C_T_SU_STA);
1823
1824 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1825
1826 /* Hold time for start condition (4us) */
1827 udelay(IXGBE_I2C_T_HD_STA);
1828
1829 ixgbe_lower_i2c_clk(hw, &i2cctl);
1830
1831 /* Minimum low period of clock is 4.7 us */
1832 udelay(IXGBE_I2C_T_LOW);
1833
1834}
1835
1836/**
1837 * ixgbe_i2c_stop - Sets I2C stop condition
1838 * @hw: pointer to hardware structure
1839 *
1840 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1841 **/
1842static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1843{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001844 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001845
1846 /* Stop condition must begin with data low and clock high */
1847 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1848 ixgbe_raise_i2c_clk(hw, &i2cctl);
1849
1850 /* Setup time for stop condition (4us) */
1851 udelay(IXGBE_I2C_T_SU_STO);
1852
1853 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1854
1855 /* bus free time between stop and start (4.7us)*/
1856 udelay(IXGBE_I2C_T_BUF);
1857}
1858
1859/**
1860 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1861 * @hw: pointer to hardware structure
1862 * @data: data byte to clock in
1863 *
1864 * Clocks in one byte data via I2C data/clock
1865 **/
1866static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1867{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001868 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001869 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001870
1871 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001872 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001873 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001874 }
1875
Emil Tantilove1befd72011-08-27 07:18:47 +00001876 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001877}
1878
1879/**
1880 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1881 * @hw: pointer to hardware structure
1882 * @data: data byte clocked out
1883 *
1884 * Clocks out one byte data via I2C data/clock
1885 **/
1886static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1887{
Mark Rustade90dd262014-07-22 06:51:08 +00001888 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001889 s32 i;
1890 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001891 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001892
1893 for (i = 7; i >= 0; i--) {
1894 bit = (data >> i) & 0x1;
1895 status = ixgbe_clock_out_i2c_bit(hw, bit);
1896
1897 if (status != 0)
1898 break;
1899 }
1900
1901 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07001902 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1903 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1904 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001905 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001906
1907 return status;
1908}
1909
1910/**
1911 * ixgbe_get_i2c_ack - Polls for I2C ACK
1912 * @hw: pointer to hardware structure
1913 *
1914 * Clocks in/out one bit via I2C data/clock
1915 **/
1916static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1917{
Emil Tantilove1befd72011-08-27 07:18:47 +00001918 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001919 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001920 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001921 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001922 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001923
Emil Tantilove1befd72011-08-27 07:18:47 +00001924 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001925
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001926
1927 /* Minimum high period of clock is 4us */
1928 udelay(IXGBE_I2C_T_HIGH);
1929
1930 /* Poll for ACK. Note that ACK in I2C spec is
1931 * transition from 1 to 0 */
1932 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07001933 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001934 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001935
1936 udelay(1);
1937 if (ack == 0)
1938 break;
1939 }
1940
1941 if (ack == 1) {
1942 hw_dbg(hw, "I2C ack was not received.\n");
1943 status = IXGBE_ERR_I2C;
1944 }
1945
1946 ixgbe_lower_i2c_clk(hw, &i2cctl);
1947
1948 /* Minimum low period of clock is 4.7 us */
1949 udelay(IXGBE_I2C_T_LOW);
1950
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001951 return status;
1952}
1953
1954/**
1955 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1956 * @hw: pointer to hardware structure
1957 * @data: read data value
1958 *
1959 * Clocks in one bit via I2C data/clock
1960 **/
1961static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1962{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001963 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001964
Emil Tantilove1befd72011-08-27 07:18:47 +00001965 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001966
1967 /* Minimum high period of clock is 4us */
1968 udelay(IXGBE_I2C_T_HIGH);
1969
Don Skidmore9a900ec2015-06-09 17:15:01 -07001970 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001971 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001972
1973 ixgbe_lower_i2c_clk(hw, &i2cctl);
1974
1975 /* Minimum low period of clock is 4.7 us */
1976 udelay(IXGBE_I2C_T_LOW);
1977
Emil Tantilove1befd72011-08-27 07:18:47 +00001978 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001979}
1980
1981/**
1982 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1983 * @hw: pointer to hardware structure
1984 * @data: data value to write
1985 *
1986 * Clocks out one bit via I2C data/clock
1987 **/
1988static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1989{
1990 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001991 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001992
1993 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1994 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001995 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001996
1997 /* Minimum high period of clock is 4us */
1998 udelay(IXGBE_I2C_T_HIGH);
1999
2000 ixgbe_lower_i2c_clk(hw, &i2cctl);
2001
2002 /* Minimum low period of clock is 4.7 us.
2003 * This also takes care of the data hold time.
2004 */
2005 udelay(IXGBE_I2C_T_LOW);
2006 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002007 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002008 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002009 }
2010
Mark Rustade90dd262014-07-22 06:51:08 +00002011 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002012}
2013/**
2014 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2015 * @hw: pointer to hardware structure
2016 * @i2cctl: Current value of I2CCTL register
2017 *
2018 * Raises the I2C clock line '0'->'1'
2019 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002020static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002021{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002022 u32 i = 0;
2023 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2024 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002025
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002026 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002027 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2028 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002029 IXGBE_WRITE_FLUSH(hw);
2030 /* SCL rise time (1000ns) */
2031 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002032
Don Skidmore9a900ec2015-06-09 17:15:01 -07002033 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2034 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002035 break;
2036 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002037}
2038
2039/**
2040 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2041 * @hw: pointer to hardware structure
2042 * @i2cctl: Current value of I2CCTL register
2043 *
2044 * Lowers the I2C clock line '1'->'0'
2045 **/
2046static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2047{
2048
Don Skidmore9a900ec2015-06-09 17:15:01 -07002049 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002050
Don Skidmore9a900ec2015-06-09 17:15:01 -07002051 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002052 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002053
2054 /* SCL fall time (300ns) */
2055 udelay(IXGBE_I2C_T_FALL);
2056}
2057
2058/**
2059 * ixgbe_set_i2c_data - Sets the I2C data bit
2060 * @hw: pointer to hardware structure
2061 * @i2cctl: Current value of I2CCTL register
2062 * @data: I2C data value (0 or 1) to set
2063 *
2064 * Sets the I2C data bit
2065 **/
2066static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2067{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002068 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002069 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002070 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002071 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002072
Don Skidmore9a900ec2015-06-09 17:15:01 -07002073 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002074 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002075
2076 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2077 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2078
2079 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002080 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002081 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002082 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002083 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002084 }
2085
Mark Rustade90dd262014-07-22 06:51:08 +00002086 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002087}
2088
2089/**
2090 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2091 * @hw: pointer to hardware structure
2092 * @i2cctl: Current value of I2CCTL register
2093 *
2094 * Returns the I2C data bit value
2095 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002096static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002097{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002098 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002099 return true;
2100 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002101}
2102
2103/**
2104 * ixgbe_i2c_bus_clear - Clears the I2C bus
2105 * @hw: pointer to hardware structure
2106 *
2107 * Clears the I2C bus by sending nine clock pulses.
2108 * Used when data line is stuck low.
2109 **/
2110static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2111{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002112 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002113 u32 i;
2114
Emil Tantilov75f19c32011-02-19 08:43:55 +00002115 ixgbe_i2c_start(hw);
2116
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002117 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2118
2119 for (i = 0; i < 9; i++) {
2120 ixgbe_raise_i2c_clk(hw, &i2cctl);
2121
2122 /* Min high period of clock is 4us */
2123 udelay(IXGBE_I2C_T_HIGH);
2124
2125 ixgbe_lower_i2c_clk(hw, &i2cctl);
2126
2127 /* Min low period of clock is 4.7us*/
2128 udelay(IXGBE_I2C_T_LOW);
2129 }
2130
Emil Tantilov75f19c32011-02-19 08:43:55 +00002131 ixgbe_i2c_start(hw);
2132
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002133 /* Put the i2c bus back to default state */
2134 ixgbe_i2c_stop(hw);
2135}
2136
2137/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002138 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002139 * @hw: pointer to hardware structure
2140 *
2141 * Checks if the LASI temp alarm status was triggered due to overtemp
2142 **/
2143s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2144{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002145 u16 phy_data = 0;
2146
2147 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002148 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002149
2150 /* Check that the LASI temp alarm status was triggered */
2151 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002152 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002153
2154 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002155 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002156
Mark Rustade90dd262014-07-22 06:51:08 +00002157 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002158}
Don Skidmore961fac82015-06-09 16:09:47 -07002159
2160/** ixgbe_set_copper_phy_power - Control power for copper phy
2161 * @hw: pointer to hardware structure
2162 * @on: true for on, false for off
2163 **/
2164s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2165{
2166 u32 status;
2167 u16 reg;
2168
2169 /* Bail if we don't have copper phy */
2170 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2171 return 0;
2172
2173 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2174 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2175 &reg);
2176 if (status)
2177 return status;
2178
2179 if (on) {
2180 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2181 } else {
2182 if (ixgbe_check_reset_blocked(hw))
2183 return 0;
2184 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2185 }
2186
2187 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2188 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2189 reg);
2190 return status;
2191}