blob: 97275dce2a16dbfaa97353902d5cae36fea904eb [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/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800733 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
734 * @hw: pointer to hardware structure
735 * @speed: pointer to link speed
736 * @autoneg: boolean auto-negotiation value
737 *
738 * Determines the link capabilities by reading the AUTOC register.
739 */
740s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000741 ixgbe_link_speed *speed,
742 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800743{
Mark Rustade90dd262014-07-22 06:51:08 +0000744 s32 status;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800745 u16 speed_ability;
746
747 *speed = 0;
748 *autoneg = true;
749
750 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000751 &speed_ability);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800752
753 if (status == 0) {
754 if (speed_ability & MDIO_SPEED_10G)
755 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
756 if (speed_ability & MDIO_PMA_SPEED_1000)
757 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
758 if (speed_ability & MDIO_PMA_SPEED_100)
759 *speed |= IXGBE_LINK_SPEED_100_FULL;
760 }
761
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000762 /* Internal PHY does not support 100 Mbps */
763 if (hw->mac.type == ixgbe_mac_X550EM_x)
764 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
765
Don Skidmorea391f1d2010-11-16 19:27:15 -0800766 return status;
767}
768
769/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000770 * ixgbe_check_phy_link_tnx - Determine link and speed status
771 * @hw: pointer to hardware structure
772 *
773 * Reads the VS1 register to determine if link is up and the current speed for
774 * the PHY.
775 **/
776s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
777 bool *link_up)
778{
Mark Rustade90dd262014-07-22 06:51:08 +0000779 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000780 u32 time_out;
781 u32 max_time_out = 10;
782 u16 phy_link = 0;
783 u16 phy_speed = 0;
784 u16 phy_data = 0;
785
786 /* Initialize speed and link to default case */
787 *link_up = false;
788 *speed = IXGBE_LINK_SPEED_10GB_FULL;
789
790 /*
791 * Check current speed and link status of the PHY register.
792 * This is a vendor specific register and may have to
793 * be changed for other copper PHYs.
794 */
795 for (time_out = 0; time_out < max_time_out; time_out++) {
796 udelay(10);
797 status = hw->phy.ops.read_reg(hw,
798 MDIO_STAT1,
799 MDIO_MMD_VEND1,
800 &phy_data);
801 phy_link = phy_data &
802 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
803 phy_speed = phy_data &
804 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
805 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
806 *link_up = true;
807 if (phy_speed ==
808 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
809 *speed = IXGBE_LINK_SPEED_1GB_FULL;
810 break;
811 }
812 }
813
814 return status;
815}
816
817/**
818 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
819 * @hw: pointer to hardware structure
820 *
821 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000822 * This function always returns success, this is nessary since
823 * it is called via a function pointer that could call other
824 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000825 **/
826s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
827{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000828 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
829 bool autoneg = false;
830 ixgbe_link_speed speed;
831
832 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
833
834 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
835 /* Set or unset auto-negotiation 10G advertisement */
836 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
837 MDIO_MMD_AN,
838 &autoneg_reg);
839
840 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
841 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
842 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
843
844 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
845 MDIO_MMD_AN,
846 autoneg_reg);
847 }
848
849 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
850 /* Set or unset auto-negotiation 1G advertisement */
851 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
852 MDIO_MMD_AN,
853 &autoneg_reg);
854
855 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
856 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
857 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
858
859 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
860 MDIO_MMD_AN,
861 autoneg_reg);
862 }
863
864 if (speed & IXGBE_LINK_SPEED_100_FULL) {
865 /* Set or unset auto-negotiation 100M advertisement */
866 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
867 MDIO_MMD_AN,
868 &autoneg_reg);
869
Emil Tantilov50c022e2011-03-31 09:36:12 +0000870 autoneg_reg &= ~(ADVERTISE_100FULL |
871 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000872 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
873 autoneg_reg |= ADVERTISE_100FULL;
874
875 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
876 MDIO_MMD_AN,
877 autoneg_reg);
878 }
879
Don Skidmorec97506a2014-02-27 20:32:43 -0800880 /* Blocked by MNG FW so don't reset PHY */
881 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000882 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800883
Emil Tantilov9dda1732011-03-05 01:28:07 +0000884 /* Restart PHY autonegotiation and wait for completion */
885 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
886 MDIO_MMD_AN, &autoneg_reg);
887
888 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
889
890 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
891 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000892 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000893}
894
895/**
896 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
897 * @hw: pointer to hardware structure
898 * @firmware_version: pointer to the PHY Firmware Version
899 **/
900s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
901 u16 *firmware_version)
902{
Mark Rustade90dd262014-07-22 06:51:08 +0000903 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000904
905 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
906 MDIO_MMD_VEND1,
907 firmware_version);
908
909 return status;
910}
911
912/**
913 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
914 * @hw: pointer to hardware structure
915 * @firmware_version: pointer to the PHY Firmware Version
916 **/
917s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
918 u16 *firmware_version)
919{
Mark Rustade90dd262014-07-22 06:51:08 +0000920 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000921
922 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
923 MDIO_MMD_VEND1,
924 firmware_version);
925
926 return status;
927}
928
929/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800930 * ixgbe_reset_phy_nl - Performs a PHY reset
931 * @hw: pointer to hardware structure
932 **/
933s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
934{
935 u16 phy_offset, control, eword, edata, block_crc;
936 bool end_data = false;
937 u16 list_offset, data_offset;
938 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000939 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800940 u32 i;
941
Don Skidmorec97506a2014-02-27 20:32:43 -0800942 /* Blocked by MNG FW so bail */
943 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000944 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800945
Ben Hutchings6b73e102009-04-29 08:08:58 +0000946 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800947
948 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000949 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000950 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800951
952 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000953 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000954 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000955 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800956 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000957 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800958 }
959
Ben Hutchings6b73e102009-04-29 08:08:58 +0000960 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800961 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000962 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800963 }
964
965 /* Get init offsets */
966 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000967 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000968 if (ret_val)
969 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800970
971 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
972 data_offset++;
973 while (!end_data) {
974 /*
975 * Read control word from PHY init contents offset
976 */
977 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000978 if (ret_val)
979 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800980 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +0000981 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800982 edata = eword & IXGBE_DATA_MASK_NL;
983 switch (control) {
984 case IXGBE_DELAY_NL:
985 data_offset++;
986 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000987 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800988 break;
989 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000990 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800991 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000992 ret_val = hw->eeprom.ops.read(hw, data_offset++,
993 &phy_offset);
994 if (ret_val)
995 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800996 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000997 ret_val = hw->eeprom.ops.read(hw, data_offset,
998 &eword);
999 if (ret_val)
1000 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001001 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001002 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001003 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1004 phy_offset);
1005 data_offset++;
1006 phy_offset++;
1007 }
1008 break;
1009 case IXGBE_CONTROL_NL:
1010 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001011 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001012 if (edata == IXGBE_CONTROL_EOL_NL) {
1013 hw_dbg(hw, "EOL\n");
1014 end_data = true;
1015 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1016 hw_dbg(hw, "SOL\n");
1017 } else {
1018 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001019 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001020 }
1021 break;
1022 default:
1023 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001024 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001025 }
1026 }
1027
Donald Skidmorec4900be2008-11-20 21:11:42 -08001028 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001029
1030err_eeprom:
1031 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1032 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001033}
1034
1035/**
Don Skidmore8f583322013-07-27 06:25:38 +00001036 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001037 * @hw: pointer to hardware structure
1038 *
Don Skidmore8f583322013-07-27 06:25:38 +00001039 * Determines HW type and calls appropriate function.
1040 **/
1041s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1042{
Don Skidmore8f583322013-07-27 06:25:38 +00001043 switch (hw->mac.ops.get_media_type(hw)) {
1044 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001045 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001046 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001047 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001048 default:
1049 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001050 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001051 }
1052
Mark Rustade90dd262014-07-22 06:51:08 +00001053 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001054}
1055
1056/**
1057 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1058 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001059 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001060 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001061 **/
1062s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1063{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001064 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001065 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001066 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001067 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001068 u8 identifier = 0;
1069 u8 comp_codes_1g = 0;
1070 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001071 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001072 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001073 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001074 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001075
Don Skidmore8ca783a2009-05-26 20:40:47 -07001076 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1077 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001078 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001079 }
1080
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001081 status = hw->phy.ops.read_i2c_eeprom(hw,
1082 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001083 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001084
Mark Rustade90dd262014-07-22 06:51:08 +00001085 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001086 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001087
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001088 /* LAN ID is needed for sfp_type determination */
1089 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001090
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001091 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1092 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001093 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1094 }
1095 status = hw->phy.ops.read_i2c_eeprom(hw,
1096 IXGBE_SFF_1GBE_COMP_CODES,
1097 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001098
Mark Rustade90dd262014-07-22 06:51:08 +00001099 if (status)
1100 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001101
Mark Rustade90dd262014-07-22 06:51:08 +00001102 status = hw->phy.ops.read_i2c_eeprom(hw,
1103 IXGBE_SFF_10GBE_COMP_CODES,
1104 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001105
Mark Rustade90dd262014-07-22 06:51:08 +00001106 if (status)
1107 goto err_read_i2c_eeprom;
1108 status = hw->phy.ops.read_i2c_eeprom(hw,
1109 IXGBE_SFF_CABLE_TECHNOLOGY,
1110 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001111
Mark Rustade90dd262014-07-22 06:51:08 +00001112 if (status)
1113 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001114
Mark Rustade90dd262014-07-22 06:51:08 +00001115 /* ID Module
1116 * =========
1117 * 0 SFP_DA_CU
1118 * 1 SFP_SR
1119 * 2 SFP_LR
1120 * 3 SFP_DA_CORE0 - 82599-specific
1121 * 4 SFP_DA_CORE1 - 82599-specific
1122 * 5 SFP_SR/LR_CORE0 - 82599-specific
1123 * 6 SFP_SR/LR_CORE1 - 82599-specific
1124 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1125 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1126 * 9 SFP_1g_cu_CORE0 - 82599-specific
1127 * 10 SFP_1g_cu_CORE1 - 82599-specific
1128 * 11 SFP_1g_sx_CORE0 - 82599-specific
1129 * 12 SFP_1g_sx_CORE1 - 82599-specific
1130 */
1131 if (hw->mac.type == ixgbe_mac_82598EB) {
1132 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1133 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1134 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1135 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1136 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1137 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1138 else
1139 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1140 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1141 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1142 if (hw->bus.lan_id == 0)
1143 hw->phy.sfp_type =
1144 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001145 else
Mark Rustade90dd262014-07-22 06:51:08 +00001146 hw->phy.sfp_type =
1147 ixgbe_sfp_type_da_cu_core1;
1148 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1149 hw->phy.ops.read_i2c_eeprom(
1150 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1151 &cable_spec);
1152 if (cable_spec &
1153 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001154 if (hw->bus.lan_id == 0)
1155 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001156 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001157 else
1158 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001159 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001160 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001161 hw->phy.sfp_type =
1162 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001163 }
Mark Rustade90dd262014-07-22 06:51:08 +00001164 } else if (comp_codes_10g &
1165 (IXGBE_SFF_10GBASESR_CAPABLE |
1166 IXGBE_SFF_10GBASELR_CAPABLE)) {
1167 if (hw->bus.lan_id == 0)
1168 hw->phy.sfp_type =
1169 ixgbe_sfp_type_srlr_core0;
1170 else
1171 hw->phy.sfp_type =
1172 ixgbe_sfp_type_srlr_core1;
1173 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1174 if (hw->bus.lan_id == 0)
1175 hw->phy.sfp_type =
1176 ixgbe_sfp_type_1g_cu_core0;
1177 else
1178 hw->phy.sfp_type =
1179 ixgbe_sfp_type_1g_cu_core1;
1180 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1181 if (hw->bus.lan_id == 0)
1182 hw->phy.sfp_type =
1183 ixgbe_sfp_type_1g_sx_core0;
1184 else
1185 hw->phy.sfp_type =
1186 ixgbe_sfp_type_1g_sx_core1;
1187 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1188 if (hw->bus.lan_id == 0)
1189 hw->phy.sfp_type =
1190 ixgbe_sfp_type_1g_lx_core0;
1191 else
1192 hw->phy.sfp_type =
1193 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001194 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001195 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001196 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001197 }
1198
Mark Rustade90dd262014-07-22 06:51:08 +00001199 if (hw->phy.sfp_type != stored_sfp_type)
1200 hw->phy.sfp_setup_needed = true;
1201
1202 /* Determine if the SFP+ PHY is dual speed or not. */
1203 hw->phy.multispeed_fiber = false;
1204 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1205 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1206 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1207 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1208 hw->phy.multispeed_fiber = true;
1209
1210 /* Determine PHY vendor */
1211 if (hw->phy.type != ixgbe_phy_nl) {
1212 hw->phy.id = identifier;
1213 status = hw->phy.ops.read_i2c_eeprom(hw,
1214 IXGBE_SFF_VENDOR_OUI_BYTE0,
1215 &oui_bytes[0]);
1216
1217 if (status != 0)
1218 goto err_read_i2c_eeprom;
1219
1220 status = hw->phy.ops.read_i2c_eeprom(hw,
1221 IXGBE_SFF_VENDOR_OUI_BYTE1,
1222 &oui_bytes[1]);
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_BYTE2,
1229 &oui_bytes[2]);
1230
1231 if (status != 0)
1232 goto err_read_i2c_eeprom;
1233
1234 vendor_oui =
1235 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1236 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1237 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1238
1239 switch (vendor_oui) {
1240 case IXGBE_SFF_VENDOR_OUI_TYCO:
1241 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1242 hw->phy.type =
1243 ixgbe_phy_sfp_passive_tyco;
1244 break;
1245 case IXGBE_SFF_VENDOR_OUI_FTL:
1246 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1247 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1248 else
1249 hw->phy.type = ixgbe_phy_sfp_ftl;
1250 break;
1251 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1252 hw->phy.type = ixgbe_phy_sfp_avago;
1253 break;
1254 case IXGBE_SFF_VENDOR_OUI_INTEL:
1255 hw->phy.type = ixgbe_phy_sfp_intel;
1256 break;
1257 default:
1258 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1259 hw->phy.type =
1260 ixgbe_phy_sfp_passive_unknown;
1261 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1262 hw->phy.type =
1263 ixgbe_phy_sfp_active_unknown;
1264 else
1265 hw->phy.type = ixgbe_phy_sfp_unknown;
1266 break;
1267 }
1268 }
1269
1270 /* Allow any DA cable vendor */
1271 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1272 IXGBE_SFF_DA_ACTIVE_CABLE))
1273 return 0;
1274
1275 /* Verify supported 1G SFP modules */
1276 if (comp_codes_10g == 0 &&
1277 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1278 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1279 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1280 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1281 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1282 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1283 hw->phy.type = ixgbe_phy_sfp_unsupported;
1284 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1285 }
1286
1287 /* Anything else 82598-based is supported */
1288 if (hw->mac.type == ixgbe_mac_82598EB)
1289 return 0;
1290
1291 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1292 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1293 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1294 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1295 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1296 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1297 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1298 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1299 /* Make sure we're a supported PHY type */
1300 if (hw->phy.type == ixgbe_phy_sfp_intel)
1301 return 0;
1302 if (hw->allow_unsupported_sfp) {
1303 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");
1304 return 0;
1305 }
1306 hw_dbg(hw, "SFP+ module not supported\n");
1307 hw->phy.type = ixgbe_phy_sfp_unsupported;
1308 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1309 }
1310 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001311
1312err_read_i2c_eeprom:
1313 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1314 if (hw->phy.type != ixgbe_phy_nl) {
1315 hw->phy.id = 0;
1316 hw->phy.type = ixgbe_phy_unknown;
1317 }
1318 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001319}
1320
1321/**
Don Skidmore8f583322013-07-27 06:25:38 +00001322 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1323 * @hw: pointer to hardware structure
1324 *
1325 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1326 **/
Mark Rustad88217542013-11-23 03:19:19 +00001327static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001328{
1329 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001330 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001331 u32 vendor_oui = 0;
1332 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1333 u8 identifier = 0;
1334 u8 comp_codes_1g = 0;
1335 u8 comp_codes_10g = 0;
1336 u8 oui_bytes[3] = {0, 0, 0};
1337 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001338 u8 connector = 0;
1339 u8 cable_length = 0;
1340 u8 device_tech = 0;
1341 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001342
1343 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1344 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001345 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001346 }
1347
Don Skidmore7e49d612015-06-09 17:48:54 -07001348 /* LAN ID is needed for sfp_type determination */
1349 hw->mac.ops.set_lan_id(hw);
1350
Don Skidmore8f583322013-07-27 06:25:38 +00001351 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1352 &identifier);
1353
1354 if (status != 0)
1355 goto err_read_i2c_eeprom;
1356
1357 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1358 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001359 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001360 }
1361
1362 hw->phy.id = identifier;
1363
Don Skidmore8f583322013-07-27 06:25:38 +00001364 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1365 &comp_codes_10g);
1366
1367 if (status != 0)
1368 goto err_read_i2c_eeprom;
1369
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001370 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1371 &comp_codes_1g);
1372
1373 if (status != 0)
1374 goto err_read_i2c_eeprom;
1375
Don Skidmore8f583322013-07-27 06:25:38 +00001376 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1377 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1378 if (hw->bus.lan_id == 0)
1379 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1380 else
1381 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001382 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1383 IXGBE_SFF_10GBASELR_CAPABLE)) {
1384 if (hw->bus.lan_id == 0)
1385 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1386 else
1387 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1388 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001389 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1390 active_cable = true;
1391
1392 if (!active_cable) {
1393 /* check for active DA cables that pre-date
1394 * SFF-8436 v3.6
1395 */
1396 hw->phy.ops.read_i2c_eeprom(hw,
1397 IXGBE_SFF_QSFP_CONNECTOR,
1398 &connector);
1399
1400 hw->phy.ops.read_i2c_eeprom(hw,
1401 IXGBE_SFF_QSFP_CABLE_LENGTH,
1402 &cable_length);
1403
1404 hw->phy.ops.read_i2c_eeprom(hw,
1405 IXGBE_SFF_QSFP_DEVICE_TECH,
1406 &device_tech);
1407
1408 if ((connector ==
1409 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1410 (cable_length > 0) &&
1411 ((device_tech >> 4) ==
1412 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1413 active_cable = true;
1414 }
1415
1416 if (active_cable) {
1417 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1418 if (hw->bus.lan_id == 0)
1419 hw->phy.sfp_type =
1420 ixgbe_sfp_type_da_act_lmt_core0;
1421 else
1422 hw->phy.sfp_type =
1423 ixgbe_sfp_type_da_act_lmt_core1;
1424 } else {
1425 /* unsupported module type */
1426 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001427 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001428 }
Don Skidmore8f583322013-07-27 06:25:38 +00001429 }
1430
1431 if (hw->phy.sfp_type != stored_sfp_type)
1432 hw->phy.sfp_setup_needed = true;
1433
1434 /* Determine if the QSFP+ PHY is dual speed or not. */
1435 hw->phy.multispeed_fiber = false;
1436 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1437 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1438 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1439 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1440 hw->phy.multispeed_fiber = true;
1441
1442 /* Determine PHY vendor for optical modules */
1443 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1444 IXGBE_SFF_10GBASELR_CAPABLE)) {
1445 status = hw->phy.ops.read_i2c_eeprom(hw,
1446 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1447 &oui_bytes[0]);
1448
1449 if (status != 0)
1450 goto err_read_i2c_eeprom;
1451
1452 status = hw->phy.ops.read_i2c_eeprom(hw,
1453 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1454 &oui_bytes[1]);
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_BYTE2,
1461 &oui_bytes[2]);
1462
1463 if (status != 0)
1464 goto err_read_i2c_eeprom;
1465
1466 vendor_oui =
1467 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1468 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1469 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1470
1471 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1472 hw->phy.type = ixgbe_phy_qsfp_intel;
1473 else
1474 hw->phy.type = ixgbe_phy_qsfp_unknown;
1475
1476 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1477 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1478 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001479 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1480 return 0;
1481 if (hw->allow_unsupported_sfp) {
1482 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");
1483 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001484 }
Mark Rustade90dd262014-07-22 06:51:08 +00001485 hw_dbg(hw, "QSFP module not supported\n");
1486 hw->phy.type = ixgbe_phy_sfp_unsupported;
1487 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001488 }
Mark Rustade90dd262014-07-22 06:51:08 +00001489 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001490 }
Mark Rustade90dd262014-07-22 06:51:08 +00001491 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001492
1493err_read_i2c_eeprom:
1494 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1495 hw->phy.id = 0;
1496 hw->phy.type = ixgbe_phy_unknown;
1497
1498 return IXGBE_ERR_SFP_NOT_PRESENT;
1499}
1500
1501/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001502 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001503 * @hw: pointer to hardware structure
1504 * @list_offset: offset to the SFP ID list
1505 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001506 *
1507 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1508 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001509 **/
1510s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001511 u16 *list_offset,
1512 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001513{
1514 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001515 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001516
1517 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1518 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1519
1520 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1521 return IXGBE_ERR_SFP_NOT_PRESENT;
1522
1523 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1524 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1525 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1526
Don Skidmorecb836a92010-06-29 18:30:59 +00001527 /*
1528 * Limiting active cables and 1G Phys must be initialized as
1529 * SR modules
1530 */
1531 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001532 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001533 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1534 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001535 sfp_type = ixgbe_sfp_type_srlr_core0;
1536 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001537 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001538 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1539 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001540 sfp_type = ixgbe_sfp_type_srlr_core1;
1541
Donald Skidmorec4900be2008-11-20 21:11:42 -08001542 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001543 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1544 hw_err(hw, "eeprom read at %d failed\n",
1545 IXGBE_PHY_INIT_OFFSET_NL);
1546 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1547 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001548
1549 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001550 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001551
1552 /* Shift offset to first ID word */
1553 (*list_offset)++;
1554
1555 /*
1556 * Find the matching SFP ID in the EEPROM
1557 * and program the init sequence
1558 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001559 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1560 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001561
1562 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001563 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001564 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001565 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1566 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001567 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1568 hw_dbg(hw, "SFP+ module not supported\n");
1569 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1570 } else {
1571 break;
1572 }
1573 } else {
1574 (*list_offset) += 2;
1575 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001576 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001577 }
1578 }
1579
1580 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1581 hw_dbg(hw, "No matching SFP+ module found\n");
1582 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1583 }
1584
1585 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001586
1587err_phy:
1588 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1589 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001590}
1591
1592/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001593 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1594 * @hw: pointer to hardware structure
1595 * @byte_offset: EEPROM byte offset to read
1596 * @eeprom_data: value read
1597 *
1598 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1599 **/
1600s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001601 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001602{
1603 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001604 IXGBE_I2C_EEPROM_DEV_ADDR,
1605 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001606}
1607
1608/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001609 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1610 * @hw: pointer to hardware structure
1611 * @byte_offset: byte offset at address 0xA2
1612 * @eeprom_data: value read
1613 *
1614 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1615 **/
1616s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1617 u8 *sff8472_data)
1618{
1619 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1620 IXGBE_I2C_EEPROM_DEV_ADDR2,
1621 sff8472_data);
1622}
1623
1624/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001625 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1626 * @hw: pointer to hardware structure
1627 * @byte_offset: EEPROM byte offset to write
1628 * @eeprom_data: value to write
1629 *
1630 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1631 **/
1632s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001633 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001634{
1635 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001636 IXGBE_I2C_EEPROM_DEV_ADDR,
1637 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001638}
1639
1640/**
1641 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1642 * @hw: pointer to hardware structure
1643 * @byte_offset: byte offset to read
1644 * @data: value read
1645 *
1646 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001647 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001648 **/
1649s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001650 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001651{
Mark Rustade90dd262014-07-22 06:51:08 +00001652 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001653 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001654 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001655 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001656 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001657 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001658
1659 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001660 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1661 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001662
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001663 ixgbe_i2c_start(hw);
1664
1665 /* Device Address and write indication */
1666 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1667 if (status != 0)
1668 goto fail;
1669
1670 status = ixgbe_get_i2c_ack(hw);
1671 if (status != 0)
1672 goto fail;
1673
1674 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1675 if (status != 0)
1676 goto fail;
1677
1678 status = ixgbe_get_i2c_ack(hw);
1679 if (status != 0)
1680 goto fail;
1681
1682 ixgbe_i2c_start(hw);
1683
1684 /* Device Address and read indication */
1685 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1686 if (status != 0)
1687 goto fail;
1688
1689 status = ixgbe_get_i2c_ack(hw);
1690 if (status != 0)
1691 goto fail;
1692
1693 status = ixgbe_clock_in_i2c_byte(hw, data);
1694 if (status != 0)
1695 goto fail;
1696
1697 status = ixgbe_clock_out_i2c_bit(hw, nack);
1698 if (status != 0)
1699 goto fail;
1700
1701 ixgbe_i2c_stop(hw);
1702 break;
1703
1704fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001705 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001706 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001707 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001708 retry++;
1709 if (retry < max_retry)
1710 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1711 else
1712 hw_dbg(hw, "I2C byte read error.\n");
1713
1714 } while (retry < max_retry);
1715
Emil Tantilov6d980c32011-04-13 04:56:15 +00001716 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001717
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001718 return status;
1719}
1720
1721/**
1722 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1723 * @hw: pointer to hardware structure
1724 * @byte_offset: byte offset to write
1725 * @data: value to write
1726 *
1727 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1728 * a specified device address.
1729 **/
1730s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001731 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001732{
Mark Rustade90dd262014-07-22 06:51:08 +00001733 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001734 u32 max_retry = 1;
1735 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001736 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001737
Mark Rustade90dd262014-07-22 06:51:08 +00001738 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1739 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001740
1741 do {
1742 ixgbe_i2c_start(hw);
1743
1744 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1745 if (status != 0)
1746 goto fail;
1747
1748 status = ixgbe_get_i2c_ack(hw);
1749 if (status != 0)
1750 goto fail;
1751
1752 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1753 if (status != 0)
1754 goto fail;
1755
1756 status = ixgbe_get_i2c_ack(hw);
1757 if (status != 0)
1758 goto fail;
1759
1760 status = ixgbe_clock_out_i2c_byte(hw, data);
1761 if (status != 0)
1762 goto fail;
1763
1764 status = ixgbe_get_i2c_ack(hw);
1765 if (status != 0)
1766 goto fail;
1767
1768 ixgbe_i2c_stop(hw);
1769 break;
1770
1771fail:
1772 ixgbe_i2c_bus_clear(hw);
1773 retry++;
1774 if (retry < max_retry)
1775 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1776 else
1777 hw_dbg(hw, "I2C byte write error.\n");
1778 } while (retry < max_retry);
1779
Emil Tantilov6d980c32011-04-13 04:56:15 +00001780 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001781
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001782 return status;
1783}
1784
1785/**
1786 * ixgbe_i2c_start - Sets I2C start condition
1787 * @hw: pointer to hardware structure
1788 *
1789 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1790 **/
1791static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1792{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001793 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001794
1795 /* Start condition must begin with data and clock high */
1796 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1797 ixgbe_raise_i2c_clk(hw, &i2cctl);
1798
1799 /* Setup time for start condition (4.7us) */
1800 udelay(IXGBE_I2C_T_SU_STA);
1801
1802 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1803
1804 /* Hold time for start condition (4us) */
1805 udelay(IXGBE_I2C_T_HD_STA);
1806
1807 ixgbe_lower_i2c_clk(hw, &i2cctl);
1808
1809 /* Minimum low period of clock is 4.7 us */
1810 udelay(IXGBE_I2C_T_LOW);
1811
1812}
1813
1814/**
1815 * ixgbe_i2c_stop - Sets I2C stop condition
1816 * @hw: pointer to hardware structure
1817 *
1818 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1819 **/
1820static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1821{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001822 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001823
1824 /* Stop condition must begin with data low and clock high */
1825 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1826 ixgbe_raise_i2c_clk(hw, &i2cctl);
1827
1828 /* Setup time for stop condition (4us) */
1829 udelay(IXGBE_I2C_T_SU_STO);
1830
1831 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1832
1833 /* bus free time between stop and start (4.7us)*/
1834 udelay(IXGBE_I2C_T_BUF);
1835}
1836
1837/**
1838 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1839 * @hw: pointer to hardware structure
1840 * @data: data byte to clock in
1841 *
1842 * Clocks in one byte data via I2C data/clock
1843 **/
1844static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1845{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001846 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001847 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001848
1849 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001850 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001851 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001852 }
1853
Emil Tantilove1befd72011-08-27 07:18:47 +00001854 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001855}
1856
1857/**
1858 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1859 * @hw: pointer to hardware structure
1860 * @data: data byte clocked out
1861 *
1862 * Clocks out one byte data via I2C data/clock
1863 **/
1864static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1865{
Mark Rustade90dd262014-07-22 06:51:08 +00001866 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001867 s32 i;
1868 u32 i2cctl;
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--) {
1872 bit = (data >> i) & 0x1;
1873 status = ixgbe_clock_out_i2c_bit(hw, bit);
1874
1875 if (status != 0)
1876 break;
1877 }
1878
1879 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07001880 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1881 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1882 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001883 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001884
1885 return status;
1886}
1887
1888/**
1889 * ixgbe_get_i2c_ack - Polls for I2C ACK
1890 * @hw: pointer to hardware structure
1891 *
1892 * Clocks in/out one bit via I2C data/clock
1893 **/
1894static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1895{
Emil Tantilove1befd72011-08-27 07:18:47 +00001896 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001897 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001898 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001899 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001900 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001901
Emil Tantilove1befd72011-08-27 07:18:47 +00001902 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001903
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001904
1905 /* Minimum high period of clock is 4us */
1906 udelay(IXGBE_I2C_T_HIGH);
1907
1908 /* Poll for ACK. Note that ACK in I2C spec is
1909 * transition from 1 to 0 */
1910 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07001911 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001912 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001913
1914 udelay(1);
1915 if (ack == 0)
1916 break;
1917 }
1918
1919 if (ack == 1) {
1920 hw_dbg(hw, "I2C ack was not received.\n");
1921 status = IXGBE_ERR_I2C;
1922 }
1923
1924 ixgbe_lower_i2c_clk(hw, &i2cctl);
1925
1926 /* Minimum low period of clock is 4.7 us */
1927 udelay(IXGBE_I2C_T_LOW);
1928
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001929 return status;
1930}
1931
1932/**
1933 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1934 * @hw: pointer to hardware structure
1935 * @data: read data value
1936 *
1937 * Clocks in one bit via I2C data/clock
1938 **/
1939static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1940{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001941 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001942
Emil Tantilove1befd72011-08-27 07:18:47 +00001943 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001944
1945 /* Minimum high period of clock is 4us */
1946 udelay(IXGBE_I2C_T_HIGH);
1947
Don Skidmore9a900ec2015-06-09 17:15:01 -07001948 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001949 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001950
1951 ixgbe_lower_i2c_clk(hw, &i2cctl);
1952
1953 /* Minimum low period of clock is 4.7 us */
1954 udelay(IXGBE_I2C_T_LOW);
1955
Emil Tantilove1befd72011-08-27 07:18:47 +00001956 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001957}
1958
1959/**
1960 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1961 * @hw: pointer to hardware structure
1962 * @data: data value to write
1963 *
1964 * Clocks out one bit via I2C data/clock
1965 **/
1966static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1967{
1968 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001969 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001970
1971 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1972 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001973 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001974
1975 /* Minimum high period of clock is 4us */
1976 udelay(IXGBE_I2C_T_HIGH);
1977
1978 ixgbe_lower_i2c_clk(hw, &i2cctl);
1979
1980 /* Minimum low period of clock is 4.7 us.
1981 * This also takes care of the data hold time.
1982 */
1983 udelay(IXGBE_I2C_T_LOW);
1984 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001985 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001986 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001987 }
1988
Mark Rustade90dd262014-07-22 06:51:08 +00001989 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001990}
1991/**
1992 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1993 * @hw: pointer to hardware structure
1994 * @i2cctl: Current value of I2CCTL register
1995 *
1996 * Raises the I2C clock line '0'->'1'
1997 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00001998static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001999{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002000 u32 i = 0;
2001 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2002 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002003
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002004 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002005 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2006 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002007 IXGBE_WRITE_FLUSH(hw);
2008 /* SCL rise time (1000ns) */
2009 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002010
Don Skidmore9a900ec2015-06-09 17:15:01 -07002011 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2012 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002013 break;
2014 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002015}
2016
2017/**
2018 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2019 * @hw: pointer to hardware structure
2020 * @i2cctl: Current value of I2CCTL register
2021 *
2022 * Lowers the I2C clock line '1'->'0'
2023 **/
2024static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2025{
2026
Don Skidmore9a900ec2015-06-09 17:15:01 -07002027 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002028
Don Skidmore9a900ec2015-06-09 17:15:01 -07002029 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002030 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002031
2032 /* SCL fall time (300ns) */
2033 udelay(IXGBE_I2C_T_FALL);
2034}
2035
2036/**
2037 * ixgbe_set_i2c_data - Sets the I2C data bit
2038 * @hw: pointer to hardware structure
2039 * @i2cctl: Current value of I2CCTL register
2040 * @data: I2C data value (0 or 1) to set
2041 *
2042 * Sets the I2C data bit
2043 **/
2044static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2045{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002046 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002047 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002048 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002049 *i2cctl &= ~IXGBE_I2C_DATA_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 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2055 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2056
2057 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002058 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002059 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002060 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002061 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002062 }
2063
Mark Rustade90dd262014-07-22 06:51:08 +00002064 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002065}
2066
2067/**
2068 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2069 * @hw: pointer to hardware structure
2070 * @i2cctl: Current value of I2CCTL register
2071 *
2072 * Returns the I2C data bit value
2073 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002074static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002075{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002076 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002077 return true;
2078 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002079}
2080
2081/**
2082 * ixgbe_i2c_bus_clear - Clears the I2C bus
2083 * @hw: pointer to hardware structure
2084 *
2085 * Clears the I2C bus by sending nine clock pulses.
2086 * Used when data line is stuck low.
2087 **/
2088static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2089{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002090 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002091 u32 i;
2092
Emil Tantilov75f19c32011-02-19 08:43:55 +00002093 ixgbe_i2c_start(hw);
2094
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002095 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2096
2097 for (i = 0; i < 9; i++) {
2098 ixgbe_raise_i2c_clk(hw, &i2cctl);
2099
2100 /* Min high period of clock is 4us */
2101 udelay(IXGBE_I2C_T_HIGH);
2102
2103 ixgbe_lower_i2c_clk(hw, &i2cctl);
2104
2105 /* Min low period of clock is 4.7us*/
2106 udelay(IXGBE_I2C_T_LOW);
2107 }
2108
Emil Tantilov75f19c32011-02-19 08:43:55 +00002109 ixgbe_i2c_start(hw);
2110
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002111 /* Put the i2c bus back to default state */
2112 ixgbe_i2c_stop(hw);
2113}
2114
2115/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002116 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002117 * @hw: pointer to hardware structure
2118 *
2119 * Checks if the LASI temp alarm status was triggered due to overtemp
2120 **/
2121s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2122{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002123 u16 phy_data = 0;
2124
2125 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002126 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002127
2128 /* Check that the LASI temp alarm status was triggered */
2129 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002130 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002131
2132 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002133 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002134
Mark Rustade90dd262014-07-22 06:51:08 +00002135 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002136}
Don Skidmore961fac82015-06-09 16:09:47 -07002137
2138/** ixgbe_set_copper_phy_power - Control power for copper phy
2139 * @hw: pointer to hardware structure
2140 * @on: true for on, false for off
2141 **/
2142s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2143{
2144 u32 status;
2145 u16 reg;
2146
2147 /* Bail if we don't have copper phy */
2148 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2149 return 0;
2150
2151 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2152 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2153 &reg);
2154 if (status)
2155 return status;
2156
2157 if (on) {
2158 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2159 } else {
2160 if (ixgbe_check_reset_blocked(hw))
2161 return 0;
2162 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2163 }
2164
2165 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2166 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2167 reg);
2168 return status;
2169}