blob: 740e566cca077bc20f3f722aca03fdab8417ff4b [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 Skidmore030eaec2014-11-29 05:22:37 +0000609 u32 gssr;
Auke Kok9a799d72007-09-15 14:07:45 -0700610
611 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
612 gssr = IXGBE_GSSR_PHY1_SM;
613 else
614 gssr = IXGBE_GSSR_PHY0_SM;
615
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000616 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
617 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
618 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000619 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000620 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000621 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700622 }
623
624 return status;
625}
626
627/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700628 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700629 * @hw: pointer to hardware structure
630 *
631 * Restart autonegotiation and PHY and waits for completion.
632 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700633s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700634{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000635 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000636 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
637 bool autoneg = false;
638 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700639
Emil Tantilov9dda1732011-03-05 01:28:07 +0000640 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700641
Emil Tantilov9dda1732011-03-05 01:28:07 +0000642 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
643 /* Set or unset auto-negotiation 10G advertisement */
644 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
645 MDIO_MMD_AN,
646 &autoneg_reg);
647
Ben Hutchings6b73e102009-04-29 08:08:58 +0000648 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000649 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
650 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700651
Emil Tantilov9dda1732011-03-05 01:28:07 +0000652 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
653 MDIO_MMD_AN,
654 autoneg_reg);
655 }
656
657 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
658 /* Set or unset auto-negotiation 1G advertisement */
659 hw->phy.ops.read_reg(hw,
660 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
661 MDIO_MMD_AN,
662 &autoneg_reg);
663
664 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
665 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
666 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
667
668 hw->phy.ops.write_reg(hw,
669 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
670 MDIO_MMD_AN,
671 autoneg_reg);
672 }
673
674 if (speed & IXGBE_LINK_SPEED_100_FULL) {
675 /* Set or unset auto-negotiation 100M advertisement */
676 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
677 MDIO_MMD_AN,
678 &autoneg_reg);
679
Emil Tantilova59e8a12011-03-31 09:36:12 +0000680 autoneg_reg &= ~(ADVERTISE_100FULL |
681 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000682 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
683 autoneg_reg |= ADVERTISE_100FULL;
684
685 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
686 MDIO_MMD_AN,
687 autoneg_reg);
688 }
Auke Kok9a799d72007-09-15 14:07:45 -0700689
Don Skidmorec97506a2014-02-27 20:32:43 -0800690 /* Blocked by MNG FW so don't reset PHY */
691 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000692 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800693
Auke Kok9a799d72007-09-15 14:07:45 -0700694 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000695 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
696 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700697
Ben Hutchings6b73e102009-04-29 08:08:58 +0000698 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700699
Emil Tantilov9dda1732011-03-05 01:28:07 +0000700 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
701 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700702
Auke Kok9a799d72007-09-15 14:07:45 -0700703 return status;
704}
705
706/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700707 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700708 * @hw: pointer to hardware structure
709 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700710 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700711s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000712 ixgbe_link_speed speed,
713 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700714{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700715
Auke Kok9a799d72007-09-15 14:07:45 -0700716 /*
717 * Clear autoneg_advertised and set new values based on input link
718 * speed.
719 */
720 hw->phy.autoneg_advertised = 0;
721
722 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
723 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700724
Auke Kok9a799d72007-09-15 14:07:45 -0700725 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
726 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
727
Emil Tantilov9dda1732011-03-05 01:28:07 +0000728 if (speed & IXGBE_LINK_SPEED_100_FULL)
729 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
730
Auke Kok9a799d72007-09-15 14:07:45 -0700731 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700732 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700733
734 return 0;
735}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700736
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700737/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800738 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
739 * @hw: pointer to hardware structure
740 * @speed: pointer to link speed
741 * @autoneg: boolean auto-negotiation value
742 *
743 * Determines the link capabilities by reading the AUTOC register.
744 */
745s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000746 ixgbe_link_speed *speed,
747 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800748{
Mark Rustade90dd262014-07-22 06:51:08 +0000749 s32 status;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800750 u16 speed_ability;
751
752 *speed = 0;
753 *autoneg = true;
754
755 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000756 &speed_ability);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800757
758 if (status == 0) {
759 if (speed_ability & MDIO_SPEED_10G)
760 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
761 if (speed_ability & MDIO_PMA_SPEED_1000)
762 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
763 if (speed_ability & MDIO_PMA_SPEED_100)
764 *speed |= IXGBE_LINK_SPEED_100_FULL;
765 }
766
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000767 /* Internal PHY does not support 100 Mbps */
768 if (hw->mac.type == ixgbe_mac_X550EM_x)
769 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
770
Don Skidmorea391f1d2010-11-16 19:27:15 -0800771 return status;
772}
773
774/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000775 * ixgbe_check_phy_link_tnx - Determine link and speed status
776 * @hw: pointer to hardware structure
777 *
778 * Reads the VS1 register to determine if link is up and the current speed for
779 * the PHY.
780 **/
781s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
782 bool *link_up)
783{
Mark Rustade90dd262014-07-22 06:51:08 +0000784 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000785 u32 time_out;
786 u32 max_time_out = 10;
787 u16 phy_link = 0;
788 u16 phy_speed = 0;
789 u16 phy_data = 0;
790
791 /* Initialize speed and link to default case */
792 *link_up = false;
793 *speed = IXGBE_LINK_SPEED_10GB_FULL;
794
795 /*
796 * Check current speed and link status of the PHY register.
797 * This is a vendor specific register and may have to
798 * be changed for other copper PHYs.
799 */
800 for (time_out = 0; time_out < max_time_out; time_out++) {
801 udelay(10);
802 status = hw->phy.ops.read_reg(hw,
803 MDIO_STAT1,
804 MDIO_MMD_VEND1,
805 &phy_data);
806 phy_link = phy_data &
807 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
808 phy_speed = phy_data &
809 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
810 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
811 *link_up = true;
812 if (phy_speed ==
813 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
814 *speed = IXGBE_LINK_SPEED_1GB_FULL;
815 break;
816 }
817 }
818
819 return status;
820}
821
822/**
823 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
824 * @hw: pointer to hardware structure
825 *
826 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000827 * This function always returns success, this is nessary since
828 * it is called via a function pointer that could call other
829 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000830 **/
831s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
832{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000833 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
834 bool autoneg = false;
835 ixgbe_link_speed speed;
836
837 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
838
839 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
840 /* Set or unset auto-negotiation 10G advertisement */
841 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
842 MDIO_MMD_AN,
843 &autoneg_reg);
844
845 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
846 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
847 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
848
849 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
850 MDIO_MMD_AN,
851 autoneg_reg);
852 }
853
854 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
855 /* Set or unset auto-negotiation 1G advertisement */
856 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
857 MDIO_MMD_AN,
858 &autoneg_reg);
859
860 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
861 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
862 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
863
864 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
865 MDIO_MMD_AN,
866 autoneg_reg);
867 }
868
869 if (speed & IXGBE_LINK_SPEED_100_FULL) {
870 /* Set or unset auto-negotiation 100M advertisement */
871 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
872 MDIO_MMD_AN,
873 &autoneg_reg);
874
Emil Tantilov50c022e2011-03-31 09:36:12 +0000875 autoneg_reg &= ~(ADVERTISE_100FULL |
876 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000877 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
878 autoneg_reg |= ADVERTISE_100FULL;
879
880 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
881 MDIO_MMD_AN,
882 autoneg_reg);
883 }
884
Don Skidmorec97506a2014-02-27 20:32:43 -0800885 /* Blocked by MNG FW so don't reset PHY */
886 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000887 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800888
Emil Tantilov9dda1732011-03-05 01:28:07 +0000889 /* Restart PHY autonegotiation and wait for completion */
890 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
891 MDIO_MMD_AN, &autoneg_reg);
892
893 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
894
895 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
896 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000897 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000898}
899
900/**
901 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
902 * @hw: pointer to hardware structure
903 * @firmware_version: pointer to the PHY Firmware Version
904 **/
905s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
906 u16 *firmware_version)
907{
Mark Rustade90dd262014-07-22 06:51:08 +0000908 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000909
910 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
911 MDIO_MMD_VEND1,
912 firmware_version);
913
914 return status;
915}
916
917/**
918 * ixgbe_get_phy_firmware_version_generic - 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_generic(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, AQ_FW_REV,
928 MDIO_MMD_VEND1,
929 firmware_version);
930
931 return status;
932}
933
934/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800935 * ixgbe_reset_phy_nl - Performs a PHY reset
936 * @hw: pointer to hardware structure
937 **/
938s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
939{
940 u16 phy_offset, control, eword, edata, block_crc;
941 bool end_data = false;
942 u16 list_offset, data_offset;
943 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000944 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800945 u32 i;
946
Don Skidmorec97506a2014-02-27 20:32:43 -0800947 /* Blocked by MNG FW so bail */
948 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000949 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800950
Ben Hutchings6b73e102009-04-29 08:08:58 +0000951 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800952
953 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000954 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000955 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800956
957 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000958 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000959 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000960 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800961 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000962 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800963 }
964
Ben Hutchings6b73e102009-04-29 08:08:58 +0000965 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800966 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000967 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800968 }
969
970 /* Get init offsets */
971 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000972 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000973 if (ret_val)
974 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800975
976 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
977 data_offset++;
978 while (!end_data) {
979 /*
980 * Read control word from PHY init contents offset
981 */
982 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000983 if (ret_val)
984 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800985 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +0000986 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800987 edata = eword & IXGBE_DATA_MASK_NL;
988 switch (control) {
989 case IXGBE_DELAY_NL:
990 data_offset++;
991 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000992 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800993 break;
994 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000995 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800996 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000997 ret_val = hw->eeprom.ops.read(hw, data_offset++,
998 &phy_offset);
999 if (ret_val)
1000 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001001 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001002 ret_val = hw->eeprom.ops.read(hw, data_offset,
1003 &eword);
1004 if (ret_val)
1005 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001006 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001007 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001008 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1009 phy_offset);
1010 data_offset++;
1011 phy_offset++;
1012 }
1013 break;
1014 case IXGBE_CONTROL_NL:
1015 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001016 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001017 if (edata == IXGBE_CONTROL_EOL_NL) {
1018 hw_dbg(hw, "EOL\n");
1019 end_data = true;
1020 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1021 hw_dbg(hw, "SOL\n");
1022 } else {
1023 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001024 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001025 }
1026 break;
1027 default:
1028 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001029 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001030 }
1031 }
1032
Donald Skidmorec4900be2008-11-20 21:11:42 -08001033 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001034
1035err_eeprom:
1036 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1037 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001038}
1039
1040/**
Don Skidmore8f583322013-07-27 06:25:38 +00001041 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001042 * @hw: pointer to hardware structure
1043 *
Don Skidmore8f583322013-07-27 06:25:38 +00001044 * Determines HW type and calls appropriate function.
1045 **/
1046s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1047{
Don Skidmore8f583322013-07-27 06:25:38 +00001048 switch (hw->mac.ops.get_media_type(hw)) {
1049 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001050 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001051 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001052 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001053 default:
1054 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001055 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001056 }
1057
Mark Rustade90dd262014-07-22 06:51:08 +00001058 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001059}
1060
1061/**
1062 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1063 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001064 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001065 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001066 **/
1067s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1068{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001069 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001070 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001071 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001072 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001073 u8 identifier = 0;
1074 u8 comp_codes_1g = 0;
1075 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001076 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001077 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001078 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001079 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001080
Don Skidmore8ca783a2009-05-26 20:40:47 -07001081 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1082 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001083 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001084 }
1085
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001086 status = hw->phy.ops.read_i2c_eeprom(hw,
1087 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001088 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001089
Mark Rustade90dd262014-07-22 06:51:08 +00001090 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001091 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001092
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001093 /* LAN ID is needed for sfp_type determination */
1094 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001095
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001096 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1097 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001098 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1099 }
1100 status = hw->phy.ops.read_i2c_eeprom(hw,
1101 IXGBE_SFF_1GBE_COMP_CODES,
1102 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001103
Mark Rustade90dd262014-07-22 06:51:08 +00001104 if (status)
1105 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001106
Mark Rustade90dd262014-07-22 06:51:08 +00001107 status = hw->phy.ops.read_i2c_eeprom(hw,
1108 IXGBE_SFF_10GBE_COMP_CODES,
1109 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001110
Mark Rustade90dd262014-07-22 06:51:08 +00001111 if (status)
1112 goto err_read_i2c_eeprom;
1113 status = hw->phy.ops.read_i2c_eeprom(hw,
1114 IXGBE_SFF_CABLE_TECHNOLOGY,
1115 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001116
Mark Rustade90dd262014-07-22 06:51:08 +00001117 if (status)
1118 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001119
Mark Rustade90dd262014-07-22 06:51:08 +00001120 /* ID Module
1121 * =========
1122 * 0 SFP_DA_CU
1123 * 1 SFP_SR
1124 * 2 SFP_LR
1125 * 3 SFP_DA_CORE0 - 82599-specific
1126 * 4 SFP_DA_CORE1 - 82599-specific
1127 * 5 SFP_SR/LR_CORE0 - 82599-specific
1128 * 6 SFP_SR/LR_CORE1 - 82599-specific
1129 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1130 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1131 * 9 SFP_1g_cu_CORE0 - 82599-specific
1132 * 10 SFP_1g_cu_CORE1 - 82599-specific
1133 * 11 SFP_1g_sx_CORE0 - 82599-specific
1134 * 12 SFP_1g_sx_CORE1 - 82599-specific
1135 */
1136 if (hw->mac.type == ixgbe_mac_82598EB) {
1137 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1138 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1139 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1140 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1141 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1142 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1143 else
1144 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1145 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1146 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1147 if (hw->bus.lan_id == 0)
1148 hw->phy.sfp_type =
1149 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001150 else
Mark Rustade90dd262014-07-22 06:51:08 +00001151 hw->phy.sfp_type =
1152 ixgbe_sfp_type_da_cu_core1;
1153 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1154 hw->phy.ops.read_i2c_eeprom(
1155 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1156 &cable_spec);
1157 if (cable_spec &
1158 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001159 if (hw->bus.lan_id == 0)
1160 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001161 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001162 else
1163 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001164 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001165 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001166 hw->phy.sfp_type =
1167 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001168 }
Mark Rustade90dd262014-07-22 06:51:08 +00001169 } else if (comp_codes_10g &
1170 (IXGBE_SFF_10GBASESR_CAPABLE |
1171 IXGBE_SFF_10GBASELR_CAPABLE)) {
1172 if (hw->bus.lan_id == 0)
1173 hw->phy.sfp_type =
1174 ixgbe_sfp_type_srlr_core0;
1175 else
1176 hw->phy.sfp_type =
1177 ixgbe_sfp_type_srlr_core1;
1178 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1179 if (hw->bus.lan_id == 0)
1180 hw->phy.sfp_type =
1181 ixgbe_sfp_type_1g_cu_core0;
1182 else
1183 hw->phy.sfp_type =
1184 ixgbe_sfp_type_1g_cu_core1;
1185 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1186 if (hw->bus.lan_id == 0)
1187 hw->phy.sfp_type =
1188 ixgbe_sfp_type_1g_sx_core0;
1189 else
1190 hw->phy.sfp_type =
1191 ixgbe_sfp_type_1g_sx_core1;
1192 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1193 if (hw->bus.lan_id == 0)
1194 hw->phy.sfp_type =
1195 ixgbe_sfp_type_1g_lx_core0;
1196 else
1197 hw->phy.sfp_type =
1198 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001199 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001200 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001201 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001202 }
1203
Mark Rustade90dd262014-07-22 06:51:08 +00001204 if (hw->phy.sfp_type != stored_sfp_type)
1205 hw->phy.sfp_setup_needed = true;
1206
1207 /* Determine if the SFP+ PHY is dual speed or not. */
1208 hw->phy.multispeed_fiber = false;
1209 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1210 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1211 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1212 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1213 hw->phy.multispeed_fiber = true;
1214
1215 /* Determine PHY vendor */
1216 if (hw->phy.type != ixgbe_phy_nl) {
1217 hw->phy.id = identifier;
1218 status = hw->phy.ops.read_i2c_eeprom(hw,
1219 IXGBE_SFF_VENDOR_OUI_BYTE0,
1220 &oui_bytes[0]);
1221
1222 if (status != 0)
1223 goto err_read_i2c_eeprom;
1224
1225 status = hw->phy.ops.read_i2c_eeprom(hw,
1226 IXGBE_SFF_VENDOR_OUI_BYTE1,
1227 &oui_bytes[1]);
1228
1229 if (status != 0)
1230 goto err_read_i2c_eeprom;
1231
1232 status = hw->phy.ops.read_i2c_eeprom(hw,
1233 IXGBE_SFF_VENDOR_OUI_BYTE2,
1234 &oui_bytes[2]);
1235
1236 if (status != 0)
1237 goto err_read_i2c_eeprom;
1238
1239 vendor_oui =
1240 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1241 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1242 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1243
1244 switch (vendor_oui) {
1245 case IXGBE_SFF_VENDOR_OUI_TYCO:
1246 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1247 hw->phy.type =
1248 ixgbe_phy_sfp_passive_tyco;
1249 break;
1250 case IXGBE_SFF_VENDOR_OUI_FTL:
1251 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1252 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1253 else
1254 hw->phy.type = ixgbe_phy_sfp_ftl;
1255 break;
1256 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1257 hw->phy.type = ixgbe_phy_sfp_avago;
1258 break;
1259 case IXGBE_SFF_VENDOR_OUI_INTEL:
1260 hw->phy.type = ixgbe_phy_sfp_intel;
1261 break;
1262 default:
1263 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1264 hw->phy.type =
1265 ixgbe_phy_sfp_passive_unknown;
1266 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1267 hw->phy.type =
1268 ixgbe_phy_sfp_active_unknown;
1269 else
1270 hw->phy.type = ixgbe_phy_sfp_unknown;
1271 break;
1272 }
1273 }
1274
1275 /* Allow any DA cable vendor */
1276 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1277 IXGBE_SFF_DA_ACTIVE_CABLE))
1278 return 0;
1279
1280 /* Verify supported 1G SFP modules */
1281 if (comp_codes_10g == 0 &&
1282 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1283 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1284 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1285 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1286 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1287 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1288 hw->phy.type = ixgbe_phy_sfp_unsupported;
1289 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1290 }
1291
1292 /* Anything else 82598-based is supported */
1293 if (hw->mac.type == ixgbe_mac_82598EB)
1294 return 0;
1295
1296 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1297 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1298 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1299 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1300 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1301 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1302 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1303 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1304 /* Make sure we're a supported PHY type */
1305 if (hw->phy.type == ixgbe_phy_sfp_intel)
1306 return 0;
1307 if (hw->allow_unsupported_sfp) {
1308 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");
1309 return 0;
1310 }
1311 hw_dbg(hw, "SFP+ module not supported\n");
1312 hw->phy.type = ixgbe_phy_sfp_unsupported;
1313 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1314 }
1315 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001316
1317err_read_i2c_eeprom:
1318 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1319 if (hw->phy.type != ixgbe_phy_nl) {
1320 hw->phy.id = 0;
1321 hw->phy.type = ixgbe_phy_unknown;
1322 }
1323 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001324}
1325
1326/**
Don Skidmore8f583322013-07-27 06:25:38 +00001327 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1328 * @hw: pointer to hardware structure
1329 *
1330 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1331 **/
Mark Rustad88217542013-11-23 03:19:19 +00001332static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001333{
1334 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001335 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001336 u32 vendor_oui = 0;
1337 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1338 u8 identifier = 0;
1339 u8 comp_codes_1g = 0;
1340 u8 comp_codes_10g = 0;
1341 u8 oui_bytes[3] = {0, 0, 0};
1342 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001343 u8 connector = 0;
1344 u8 cable_length = 0;
1345 u8 device_tech = 0;
1346 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001347
1348 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1349 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001350 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001351 }
1352
Don Skidmore7e49d612015-06-09 17:48:54 -07001353 /* LAN ID is needed for sfp_type determination */
1354 hw->mac.ops.set_lan_id(hw);
1355
Don Skidmore8f583322013-07-27 06:25:38 +00001356 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1357 &identifier);
1358
1359 if (status != 0)
1360 goto err_read_i2c_eeprom;
1361
1362 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1363 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001364 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001365 }
1366
1367 hw->phy.id = identifier;
1368
Don Skidmore8f583322013-07-27 06:25:38 +00001369 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1370 &comp_codes_10g);
1371
1372 if (status != 0)
1373 goto err_read_i2c_eeprom;
1374
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001375 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1376 &comp_codes_1g);
1377
1378 if (status != 0)
1379 goto err_read_i2c_eeprom;
1380
Don Skidmore8f583322013-07-27 06:25:38 +00001381 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1382 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1383 if (hw->bus.lan_id == 0)
1384 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1385 else
1386 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001387 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1388 IXGBE_SFF_10GBASELR_CAPABLE)) {
1389 if (hw->bus.lan_id == 0)
1390 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1391 else
1392 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1393 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001394 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1395 active_cable = true;
1396
1397 if (!active_cable) {
1398 /* check for active DA cables that pre-date
1399 * SFF-8436 v3.6
1400 */
1401 hw->phy.ops.read_i2c_eeprom(hw,
1402 IXGBE_SFF_QSFP_CONNECTOR,
1403 &connector);
1404
1405 hw->phy.ops.read_i2c_eeprom(hw,
1406 IXGBE_SFF_QSFP_CABLE_LENGTH,
1407 &cable_length);
1408
1409 hw->phy.ops.read_i2c_eeprom(hw,
1410 IXGBE_SFF_QSFP_DEVICE_TECH,
1411 &device_tech);
1412
1413 if ((connector ==
1414 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1415 (cable_length > 0) &&
1416 ((device_tech >> 4) ==
1417 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1418 active_cable = true;
1419 }
1420
1421 if (active_cable) {
1422 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1423 if (hw->bus.lan_id == 0)
1424 hw->phy.sfp_type =
1425 ixgbe_sfp_type_da_act_lmt_core0;
1426 else
1427 hw->phy.sfp_type =
1428 ixgbe_sfp_type_da_act_lmt_core1;
1429 } else {
1430 /* unsupported module type */
1431 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001432 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001433 }
Don Skidmore8f583322013-07-27 06:25:38 +00001434 }
1435
1436 if (hw->phy.sfp_type != stored_sfp_type)
1437 hw->phy.sfp_setup_needed = true;
1438
1439 /* Determine if the QSFP+ PHY is dual speed or not. */
1440 hw->phy.multispeed_fiber = false;
1441 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1442 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1443 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1444 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1445 hw->phy.multispeed_fiber = true;
1446
1447 /* Determine PHY vendor for optical modules */
1448 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1449 IXGBE_SFF_10GBASELR_CAPABLE)) {
1450 status = hw->phy.ops.read_i2c_eeprom(hw,
1451 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1452 &oui_bytes[0]);
1453
1454 if (status != 0)
1455 goto err_read_i2c_eeprom;
1456
1457 status = hw->phy.ops.read_i2c_eeprom(hw,
1458 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1459 &oui_bytes[1]);
1460
1461 if (status != 0)
1462 goto err_read_i2c_eeprom;
1463
1464 status = hw->phy.ops.read_i2c_eeprom(hw,
1465 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1466 &oui_bytes[2]);
1467
1468 if (status != 0)
1469 goto err_read_i2c_eeprom;
1470
1471 vendor_oui =
1472 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1473 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1474 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1475
1476 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1477 hw->phy.type = ixgbe_phy_qsfp_intel;
1478 else
1479 hw->phy.type = ixgbe_phy_qsfp_unknown;
1480
1481 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1482 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1483 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001484 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1485 return 0;
1486 if (hw->allow_unsupported_sfp) {
1487 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");
1488 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001489 }
Mark Rustade90dd262014-07-22 06:51:08 +00001490 hw_dbg(hw, "QSFP module not supported\n");
1491 hw->phy.type = ixgbe_phy_sfp_unsupported;
1492 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001493 }
Mark Rustade90dd262014-07-22 06:51:08 +00001494 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001495 }
Mark Rustade90dd262014-07-22 06:51:08 +00001496 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001497
1498err_read_i2c_eeprom:
1499 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1500 hw->phy.id = 0;
1501 hw->phy.type = ixgbe_phy_unknown;
1502
1503 return IXGBE_ERR_SFP_NOT_PRESENT;
1504}
1505
1506/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001507 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001508 * @hw: pointer to hardware structure
1509 * @list_offset: offset to the SFP ID list
1510 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001511 *
1512 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1513 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001514 **/
1515s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001516 u16 *list_offset,
1517 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001518{
1519 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001520 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001521
1522 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1523 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1524
1525 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1526 return IXGBE_ERR_SFP_NOT_PRESENT;
1527
1528 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1529 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1530 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1531
Don Skidmorecb836a92010-06-29 18:30:59 +00001532 /*
1533 * Limiting active cables and 1G Phys must be initialized as
1534 * SR modules
1535 */
1536 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001537 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001538 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1539 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001540 sfp_type = ixgbe_sfp_type_srlr_core0;
1541 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001542 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001543 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1544 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001545 sfp_type = ixgbe_sfp_type_srlr_core1;
1546
Donald Skidmorec4900be2008-11-20 21:11:42 -08001547 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001548 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1549 hw_err(hw, "eeprom read at %d failed\n",
1550 IXGBE_PHY_INIT_OFFSET_NL);
1551 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1552 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001553
1554 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001555 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001556
1557 /* Shift offset to first ID word */
1558 (*list_offset)++;
1559
1560 /*
1561 * Find the matching SFP ID in the EEPROM
1562 * and program the init sequence
1563 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001564 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1565 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001566
1567 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001568 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001569 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001570 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1571 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001572 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1573 hw_dbg(hw, "SFP+ module not supported\n");
1574 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1575 } else {
1576 break;
1577 }
1578 } else {
1579 (*list_offset) += 2;
1580 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001581 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001582 }
1583 }
1584
1585 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1586 hw_dbg(hw, "No matching SFP+ module found\n");
1587 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1588 }
1589
1590 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001591
1592err_phy:
1593 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1594 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001595}
1596
1597/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001598 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1599 * @hw: pointer to hardware structure
1600 * @byte_offset: EEPROM byte offset to read
1601 * @eeprom_data: value read
1602 *
1603 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1604 **/
1605s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001606 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001607{
1608 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001609 IXGBE_I2C_EEPROM_DEV_ADDR,
1610 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001611}
1612
1613/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001614 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1615 * @hw: pointer to hardware structure
1616 * @byte_offset: byte offset at address 0xA2
1617 * @eeprom_data: value read
1618 *
1619 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1620 **/
1621s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1622 u8 *sff8472_data)
1623{
1624 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1625 IXGBE_I2C_EEPROM_DEV_ADDR2,
1626 sff8472_data);
1627}
1628
1629/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001630 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1631 * @hw: pointer to hardware structure
1632 * @byte_offset: EEPROM byte offset to write
1633 * @eeprom_data: value to write
1634 *
1635 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1636 **/
1637s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001638 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001639{
1640 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001641 IXGBE_I2C_EEPROM_DEV_ADDR,
1642 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001643}
1644
1645/**
1646 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1647 * @hw: pointer to hardware structure
1648 * @byte_offset: byte offset to read
1649 * @data: value read
1650 *
1651 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001652 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001653 **/
1654s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001655 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001656{
Mark Rustade90dd262014-07-22 06:51:08 +00001657 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001658 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001659 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001660 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001661 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001662 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001663
1664 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001665 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1666 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001667
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001668 ixgbe_i2c_start(hw);
1669
1670 /* Device Address and write indication */
1671 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1672 if (status != 0)
1673 goto fail;
1674
1675 status = ixgbe_get_i2c_ack(hw);
1676 if (status != 0)
1677 goto fail;
1678
1679 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1680 if (status != 0)
1681 goto fail;
1682
1683 status = ixgbe_get_i2c_ack(hw);
1684 if (status != 0)
1685 goto fail;
1686
1687 ixgbe_i2c_start(hw);
1688
1689 /* Device Address and read indication */
1690 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1691 if (status != 0)
1692 goto fail;
1693
1694 status = ixgbe_get_i2c_ack(hw);
1695 if (status != 0)
1696 goto fail;
1697
1698 status = ixgbe_clock_in_i2c_byte(hw, data);
1699 if (status != 0)
1700 goto fail;
1701
1702 status = ixgbe_clock_out_i2c_bit(hw, nack);
1703 if (status != 0)
1704 goto fail;
1705
1706 ixgbe_i2c_stop(hw);
1707 break;
1708
1709fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001710 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001711 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001712 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001713 retry++;
1714 if (retry < max_retry)
1715 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1716 else
1717 hw_dbg(hw, "I2C byte read error.\n");
1718
1719 } while (retry < max_retry);
1720
Emil Tantilov6d980c32011-04-13 04:56:15 +00001721 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001722
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001723 return status;
1724}
1725
1726/**
1727 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1728 * @hw: pointer to hardware structure
1729 * @byte_offset: byte offset to write
1730 * @data: value to write
1731 *
1732 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1733 * a specified device address.
1734 **/
1735s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001736 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001737{
Mark Rustade90dd262014-07-22 06:51:08 +00001738 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001739 u32 max_retry = 1;
1740 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001741 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001742
Mark Rustade90dd262014-07-22 06:51:08 +00001743 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1744 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001745
1746 do {
1747 ixgbe_i2c_start(hw);
1748
1749 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1750 if (status != 0)
1751 goto fail;
1752
1753 status = ixgbe_get_i2c_ack(hw);
1754 if (status != 0)
1755 goto fail;
1756
1757 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1758 if (status != 0)
1759 goto fail;
1760
1761 status = ixgbe_get_i2c_ack(hw);
1762 if (status != 0)
1763 goto fail;
1764
1765 status = ixgbe_clock_out_i2c_byte(hw, data);
1766 if (status != 0)
1767 goto fail;
1768
1769 status = ixgbe_get_i2c_ack(hw);
1770 if (status != 0)
1771 goto fail;
1772
1773 ixgbe_i2c_stop(hw);
1774 break;
1775
1776fail:
1777 ixgbe_i2c_bus_clear(hw);
1778 retry++;
1779 if (retry < max_retry)
1780 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1781 else
1782 hw_dbg(hw, "I2C byte write error.\n");
1783 } while (retry < max_retry);
1784
Emil Tantilov6d980c32011-04-13 04:56:15 +00001785 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001786
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001787 return status;
1788}
1789
1790/**
1791 * ixgbe_i2c_start - Sets I2C start condition
1792 * @hw: pointer to hardware structure
1793 *
1794 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1795 **/
1796static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1797{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001798 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001799
1800 /* Start condition must begin with data and clock high */
1801 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1802 ixgbe_raise_i2c_clk(hw, &i2cctl);
1803
1804 /* Setup time for start condition (4.7us) */
1805 udelay(IXGBE_I2C_T_SU_STA);
1806
1807 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1808
1809 /* Hold time for start condition (4us) */
1810 udelay(IXGBE_I2C_T_HD_STA);
1811
1812 ixgbe_lower_i2c_clk(hw, &i2cctl);
1813
1814 /* Minimum low period of clock is 4.7 us */
1815 udelay(IXGBE_I2C_T_LOW);
1816
1817}
1818
1819/**
1820 * ixgbe_i2c_stop - Sets I2C stop condition
1821 * @hw: pointer to hardware structure
1822 *
1823 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1824 **/
1825static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1826{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001827 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001828
1829 /* Stop condition must begin with data low and clock high */
1830 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1831 ixgbe_raise_i2c_clk(hw, &i2cctl);
1832
1833 /* Setup time for stop condition (4us) */
1834 udelay(IXGBE_I2C_T_SU_STO);
1835
1836 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1837
1838 /* bus free time between stop and start (4.7us)*/
1839 udelay(IXGBE_I2C_T_BUF);
1840}
1841
1842/**
1843 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1844 * @hw: pointer to hardware structure
1845 * @data: data byte to clock in
1846 *
1847 * Clocks in one byte data via I2C data/clock
1848 **/
1849static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1850{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001851 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001852 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001853
1854 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001855 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001856 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001857 }
1858
Emil Tantilove1befd72011-08-27 07:18:47 +00001859 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001860}
1861
1862/**
1863 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1864 * @hw: pointer to hardware structure
1865 * @data: data byte clocked out
1866 *
1867 * Clocks out one byte data via I2C data/clock
1868 **/
1869static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1870{
Mark Rustade90dd262014-07-22 06:51:08 +00001871 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001872 s32 i;
1873 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001874 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001875
1876 for (i = 7; i >= 0; i--) {
1877 bit = (data >> i) & 0x1;
1878 status = ixgbe_clock_out_i2c_bit(hw, bit);
1879
1880 if (status != 0)
1881 break;
1882 }
1883
1884 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07001885 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1886 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1887 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001888 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001889
1890 return status;
1891}
1892
1893/**
1894 * ixgbe_get_i2c_ack - Polls for I2C ACK
1895 * @hw: pointer to hardware structure
1896 *
1897 * Clocks in/out one bit via I2C data/clock
1898 **/
1899static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1900{
Emil Tantilove1befd72011-08-27 07:18:47 +00001901 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001902 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001903 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001904 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001905 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001906
Emil Tantilove1befd72011-08-27 07:18:47 +00001907 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001908
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001909
1910 /* Minimum high period of clock is 4us */
1911 udelay(IXGBE_I2C_T_HIGH);
1912
1913 /* Poll for ACK. Note that ACK in I2C spec is
1914 * transition from 1 to 0 */
1915 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07001916 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001917 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001918
1919 udelay(1);
1920 if (ack == 0)
1921 break;
1922 }
1923
1924 if (ack == 1) {
1925 hw_dbg(hw, "I2C ack was not received.\n");
1926 status = IXGBE_ERR_I2C;
1927 }
1928
1929 ixgbe_lower_i2c_clk(hw, &i2cctl);
1930
1931 /* Minimum low period of clock is 4.7 us */
1932 udelay(IXGBE_I2C_T_LOW);
1933
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001934 return status;
1935}
1936
1937/**
1938 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1939 * @hw: pointer to hardware structure
1940 * @data: read data value
1941 *
1942 * Clocks in one bit via I2C data/clock
1943 **/
1944static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1945{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001946 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001947
Emil Tantilove1befd72011-08-27 07:18:47 +00001948 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001949
1950 /* Minimum high period of clock is 4us */
1951 udelay(IXGBE_I2C_T_HIGH);
1952
Don Skidmore9a900ec2015-06-09 17:15:01 -07001953 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001954 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001955
1956 ixgbe_lower_i2c_clk(hw, &i2cctl);
1957
1958 /* Minimum low period of clock is 4.7 us */
1959 udelay(IXGBE_I2C_T_LOW);
1960
Emil Tantilove1befd72011-08-27 07:18:47 +00001961 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001962}
1963
1964/**
1965 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1966 * @hw: pointer to hardware structure
1967 * @data: data value to write
1968 *
1969 * Clocks out one bit via I2C data/clock
1970 **/
1971static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1972{
1973 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07001974 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001975
1976 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1977 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001978 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001979
1980 /* Minimum high period of clock is 4us */
1981 udelay(IXGBE_I2C_T_HIGH);
1982
1983 ixgbe_lower_i2c_clk(hw, &i2cctl);
1984
1985 /* Minimum low period of clock is 4.7 us.
1986 * This also takes care of the data hold time.
1987 */
1988 udelay(IXGBE_I2C_T_LOW);
1989 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001990 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001991 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001992 }
1993
Mark Rustade90dd262014-07-22 06:51:08 +00001994 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001995}
1996/**
1997 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1998 * @hw: pointer to hardware structure
1999 * @i2cctl: Current value of I2CCTL register
2000 *
2001 * Raises the I2C clock line '0'->'1'
2002 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002003static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002004{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002005 u32 i = 0;
2006 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2007 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002008
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002009 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002010 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2011 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002012 IXGBE_WRITE_FLUSH(hw);
2013 /* SCL rise time (1000ns) */
2014 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002015
Don Skidmore9a900ec2015-06-09 17:15:01 -07002016 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2017 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002018 break;
2019 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002020}
2021
2022/**
2023 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2024 * @hw: pointer to hardware structure
2025 * @i2cctl: Current value of I2CCTL register
2026 *
2027 * Lowers the I2C clock line '1'->'0'
2028 **/
2029static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2030{
2031
Don Skidmore9a900ec2015-06-09 17:15:01 -07002032 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002033
Don Skidmore9a900ec2015-06-09 17:15:01 -07002034 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002035 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002036
2037 /* SCL fall time (300ns) */
2038 udelay(IXGBE_I2C_T_FALL);
2039}
2040
2041/**
2042 * ixgbe_set_i2c_data - Sets the I2C data bit
2043 * @hw: pointer to hardware structure
2044 * @i2cctl: Current value of I2CCTL register
2045 * @data: I2C data value (0 or 1) to set
2046 *
2047 * Sets the I2C data bit
2048 **/
2049static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2050{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002051 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002052 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002053 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002054 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002055
Don Skidmore9a900ec2015-06-09 17:15:01 -07002056 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002057 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002058
2059 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2060 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2061
2062 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002063 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002064 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002065 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002066 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002067 }
2068
Mark Rustade90dd262014-07-22 06:51:08 +00002069 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002070}
2071
2072/**
2073 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2074 * @hw: pointer to hardware structure
2075 * @i2cctl: Current value of I2CCTL register
2076 *
2077 * Returns the I2C data bit value
2078 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002079static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002080{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002081 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002082 return true;
2083 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002084}
2085
2086/**
2087 * ixgbe_i2c_bus_clear - Clears the I2C bus
2088 * @hw: pointer to hardware structure
2089 *
2090 * Clears the I2C bus by sending nine clock pulses.
2091 * Used when data line is stuck low.
2092 **/
2093static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2094{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002095 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002096 u32 i;
2097
Emil Tantilov75f19c32011-02-19 08:43:55 +00002098 ixgbe_i2c_start(hw);
2099
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002100 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2101
2102 for (i = 0; i < 9; i++) {
2103 ixgbe_raise_i2c_clk(hw, &i2cctl);
2104
2105 /* Min high period of clock is 4us */
2106 udelay(IXGBE_I2C_T_HIGH);
2107
2108 ixgbe_lower_i2c_clk(hw, &i2cctl);
2109
2110 /* Min low period of clock is 4.7us*/
2111 udelay(IXGBE_I2C_T_LOW);
2112 }
2113
Emil Tantilov75f19c32011-02-19 08:43:55 +00002114 ixgbe_i2c_start(hw);
2115
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002116 /* Put the i2c bus back to default state */
2117 ixgbe_i2c_stop(hw);
2118}
2119
2120/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002121 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002122 * @hw: pointer to hardware structure
2123 *
2124 * Checks if the LASI temp alarm status was triggered due to overtemp
2125 **/
2126s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2127{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002128 u16 phy_data = 0;
2129
2130 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002131 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002132
2133 /* Check that the LASI temp alarm status was triggered */
2134 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002135 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002136
2137 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002138 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002139
Mark Rustade90dd262014-07-22 06:51:08 +00002140 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002141}
Don Skidmore961fac82015-06-09 16:09:47 -07002142
2143/** ixgbe_set_copper_phy_power - Control power for copper phy
2144 * @hw: pointer to hardware structure
2145 * @on: true for on, false for off
2146 **/
2147s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2148{
2149 u32 status;
2150 u16 reg;
2151
2152 /* Bail if we don't have copper phy */
2153 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2154 return 0;
2155
2156 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2157 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2158 &reg);
2159 if (status)
2160 return status;
2161
2162 if (on) {
2163 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2164 } else {
2165 if (ixgbe_check_reset_blocked(hw))
2166 return 0;
2167 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2168 }
2169
2170 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2171 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2172 reg);
2173 return status;
2174}