blob: 5dadae60fe23ecf71a4b320cfe5ce25f89d772cc [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/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700103 * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
Don Skidmore28abba02014-11-29 05:22:43 +0000104 * @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
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700108 * @lock: true if to take and release semaphore
Don Skidmore28abba02014-11-29 05:22:43 +0000109 *
110 * Returns an error code on error.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700111 */
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700112s32 ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
113 u16 reg, u16 *val, bool lock)
Don Skidmore28abba02014-11-29 05:22:43 +0000114{
115 u32 swfw_mask = hw->phy.phy_semaphore_mask;
116 int max_retry = 10;
117 int retry = 0;
118 u8 csum_byte;
119 u8 high_bits;
120 u8 low_bits;
121 u8 reg_high;
122 u8 csum;
123
124 reg_high = ((reg >> 7) & 0xFE) | 1; /* Indicate read combined */
125 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
126 csum = ~csum;
127 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700128 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Don Skidmore28abba02014-11-29 05:22:43 +0000129 return IXGBE_ERR_SWFW_SYNC;
130 ixgbe_i2c_start(hw);
131 /* Device Address and write indication */
132 if (ixgbe_out_i2c_byte_ack(hw, addr))
133 goto fail;
134 /* Write bits 14:8 */
135 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
136 goto fail;
137 /* Write bits 7:0 */
138 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
139 goto fail;
140 /* Write csum */
141 if (ixgbe_out_i2c_byte_ack(hw, csum))
142 goto fail;
143 /* Re-start condition */
144 ixgbe_i2c_start(hw);
145 /* Device Address and read indication */
146 if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
147 goto fail;
148 /* Get upper bits */
149 if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
150 goto fail;
151 /* Get low bits */
152 if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
153 goto fail;
154 /* Get csum */
155 if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
156 goto fail;
157 /* NACK */
158 if (ixgbe_clock_out_i2c_bit(hw, false))
159 goto fail;
160 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700161 if (lock)
162 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000163 *val = (high_bits << 8) | low_bits;
164 return 0;
165
166fail:
167 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700168 if (lock)
169 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000170 retry++;
171 if (retry < max_retry)
172 hw_dbg(hw, "I2C byte read combined error - Retry.\n");
173 else
174 hw_dbg(hw, "I2C byte read combined error.\n");
175 } while (retry < max_retry);
176
177 return IXGBE_ERR_I2C;
178}
179
180/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700181 * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
Don Skidmore28abba02014-11-29 05:22:43 +0000182 * @hw: pointer to the hardware structure
183 * @addr: I2C bus address to write to
184 * @reg: I2C device register to write to
185 * @val: value to write
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700186 * @lock: true if to take and release semaphore
Don Skidmore28abba02014-11-29 05:22:43 +0000187 *
188 * Returns an error code on error.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700189 */
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700190s32 ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr,
191 u16 reg, u16 val, bool lock)
Don Skidmore28abba02014-11-29 05:22:43 +0000192{
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700193 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Don Skidmore28abba02014-11-29 05:22:43 +0000194 int max_retry = 1;
195 int retry = 0;
196 u8 reg_high;
197 u8 csum;
198
199 reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
200 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
201 csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
202 csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
203 csum = ~csum;
204 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700205 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
206 return IXGBE_ERR_SWFW_SYNC;
Don Skidmore28abba02014-11-29 05:22:43 +0000207 ixgbe_i2c_start(hw);
208 /* Device Address and write indication */
209 if (ixgbe_out_i2c_byte_ack(hw, addr))
210 goto fail;
211 /* Write bits 14:8 */
212 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
213 goto fail;
214 /* Write bits 7:0 */
215 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
216 goto fail;
217 /* Write data 15:8 */
218 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
219 goto fail;
220 /* Write data 7:0 */
221 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
222 goto fail;
223 /* Write csum */
224 if (ixgbe_out_i2c_byte_ack(hw, csum))
225 goto fail;
226 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700227 if (lock)
228 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000229 return 0;
230
231fail:
232 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -0700233 if (lock)
234 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Don Skidmore28abba02014-11-29 05:22:43 +0000235 retry++;
236 if (retry < max_retry)
237 hw_dbg(hw, "I2C byte write combined error - Retry.\n");
238 else
239 hw_dbg(hw, "I2C byte write combined error.\n");
240 } while (retry < max_retry);
241
242 return IXGBE_ERR_I2C;
243}
244
245/**
Don Skidmore470739b2016-11-03 21:01:37 -0400246 * ixgbe_probe_phy - Probe a single address for a PHY
247 * @hw: pointer to hardware structure
248 * @phy_addr: PHY address to probe
249 *
250 * Returns true if PHY found
251 **/
252static bool ixgbe_probe_phy(struct ixgbe_hw *hw, u16 phy_addr)
253{
254 u16 ext_ability = 0;
255
256 hw->phy.mdio.prtad = phy_addr;
257 if (mdio45_probe(&hw->phy.mdio, phy_addr) != 0)
258 return false;
259
260 if (ixgbe_get_phy_id(hw))
261 return false;
262
263 hw->phy.type = ixgbe_get_phy_type_from_id(hw->phy.id);
264
265 if (hw->phy.type == ixgbe_phy_unknown) {
266 hw->phy.ops.read_reg(hw,
267 MDIO_PMA_EXTABLE,
268 MDIO_MMD_PMAPMD,
269 &ext_ability);
270 if (ext_ability &
271 (MDIO_PMA_EXTABLE_10GBT |
272 MDIO_PMA_EXTABLE_1000BT))
273 hw->phy.type = ixgbe_phy_cu_unknown;
274 else
275 hw->phy.type = ixgbe_phy_generic;
276 }
277
278 return true;
279}
280
281/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700282 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -0700283 * @hw: pointer to hardware structure
284 *
285 * Determines the physical layer module found on the current adapter.
286 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700287s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700288{
Auke Kok9a799d72007-09-15 14:07:45 -0700289 u32 phy_addr;
Don Skidmore470739b2016-11-03 21:01:37 -0400290 u32 status = IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700291
Don Skidmore030eaec2014-11-29 05:22:37 +0000292 if (!hw->phy.phy_semaphore_mask) {
Don Skidmored5702de2015-06-19 12:23:36 -0400293 if (hw->bus.lan_id)
Don Skidmore030eaec2014-11-29 05:22:37 +0000294 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
295 else
296 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
297 }
298
Don Skidmore470739b2016-11-03 21:01:37 -0400299 if (hw->phy.type != ixgbe_phy_unknown)
300 return 0;
Emil Tantilov037c6d02011-02-25 07:49:39 +0000301
Don Skidmore470739b2016-11-03 21:01:37 -0400302 if (hw->phy.nw_mng_if_sel) {
303 phy_addr = (hw->phy.nw_mng_if_sel &
304 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
305 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
306 if (ixgbe_probe_phy(hw, phy_addr))
307 return 0;
308 else
309 return IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700310 }
Don Skidmore470739b2016-11-03 21:01:37 -0400311
312 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
313 if (ixgbe_probe_phy(hw, phy_addr)) {
314 status = 0;
315 break;
316 }
317 }
318
319 /* Certain media types do not have a phy so an address will not
320 * be found and the code will take this path. Caller has to
321 * decide if it is an error or not.
322 */
323 if (status)
324 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
325
326 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700327}
328
329/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800330 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
331 * @hw: pointer to the hardware structure
332 *
333 * This function checks the MMNGC.MNG_VETO bit to see if there are
334 * any constraints on link from manageability. For MAC's that don't
335 * have this bit just return false since the link can not be blocked
336 * via this method.
337 **/
Jean Sacren6425f0f2014-03-11 05:57:56 +0000338bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
Don Skidmorec97506a2014-02-27 20:32:43 -0800339{
340 u32 mmngc;
341
342 /* If we don't have this bit, it can't be blocking */
343 if (hw->mac.type == ixgbe_mac_82598EB)
344 return false;
345
346 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
347 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
348 hw_dbg(hw, "MNG_VETO bit detected.\n");
349 return true;
350 }
351
352 return false;
353}
354
355/**
Auke Kok9a799d72007-09-15 14:07:45 -0700356 * ixgbe_get_phy_id - Get the phy type
357 * @hw: pointer to hardware structure
358 *
359 **/
360static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
361{
Mark Rustada1e869d2015-04-10 10:36:36 -0700362 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700363 u16 phy_id_high = 0;
364 u16 phy_id_low = 0;
365
Ben Hutchings6b73e102009-04-29 08:08:58 +0000366 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000367 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700368
Mark Rustada1e869d2015-04-10 10:36:36 -0700369 if (!status) {
Auke Kok9a799d72007-09-15 14:07:45 -0700370 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000371 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000372 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700373 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
374 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
375 }
Auke Kok9a799d72007-09-15 14:07:45 -0700376 return status;
377}
378
379/**
380 * ixgbe_get_phy_type_from_id - Get the phy type
381 * @hw: pointer to hardware structure
382 *
383 **/
384static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
385{
386 enum ixgbe_phy_type phy_type;
387
388 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700389 case TN1010_PHY_ID:
390 phy_type = ixgbe_phy_tn;
391 break;
Don Skidmorededa5622015-06-09 17:39:46 -0700392 case X550_PHY_ID:
Don Skidmore2b264902010-12-09 06:55:14 +0000393 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800394 phy_type = ixgbe_phy_aq;
395 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700396 case QT2022_PHY_ID:
397 phy_type = ixgbe_phy_qt;
398 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800399 case ATH_PHY_ID:
400 phy_type = ixgbe_phy_nl;
401 break;
Don Skidmorec2c78d52015-06-09 16:04:59 -0700402 case X557_PHY_ID:
Don Skidmore470739b2016-11-03 21:01:37 -0400403 case X557_PHY_ID2:
Don Skidmorec2c78d52015-06-09 16:04:59 -0700404 phy_type = ixgbe_phy_x550em_ext_t;
405 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700406 default:
407 phy_type = ixgbe_phy_unknown;
408 break;
409 }
410
411 return phy_type;
412}
413
414/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700415 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700416 * @hw: pointer to hardware structure
417 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700418s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700419{
Emil Tantilov17835752011-02-16 01:38:13 +0000420 u32 i;
421 u16 ctrl = 0;
422 s32 status = 0;
423
424 if (hw->phy.type == ixgbe_phy_unknown)
425 status = ixgbe_identify_phy_generic(hw);
426
427 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000428 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000429
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700430 /* Don't reset PHY if it's shut down due to overtemp. */
431 if (!hw->phy.reset_if_overtemp &&
432 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000433 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700434
Don Skidmorec97506a2014-02-27 20:32:43 -0800435 /* Blocked by MNG FW so bail */
436 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000437 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800438
Auke Kok9a799d72007-09-15 14:07:45 -0700439 /*
440 * Perform soft PHY reset to the PHY_XS.
441 * This will cause a soft reset to the PHY
442 */
Emil Tantilov17835752011-02-16 01:38:13 +0000443 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
444 MDIO_MMD_PHYXS,
445 MDIO_CTRL1_RESET);
446
447 /*
448 * Poll for reset bit to self-clear indicating reset is complete.
449 * Some PHYs could take up to 3 seconds to complete and need about
450 * 1.7 usec delay after the reset is complete.
451 */
452 for (i = 0; i < 30; i++) {
453 msleep(100);
Don Skidmore470739b2016-11-03 21:01:37 -0400454 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &ctrl);
Emil Tantilov17835752011-02-16 01:38:13 +0000455 if (!(ctrl & MDIO_CTRL1_RESET)) {
456 udelay(2);
457 break;
458 }
459 }
460
461 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000462 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000463 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000464 }
465
Mark Rustade90dd262014-07-22 06:51:08 +0000466 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700467}
468
469/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000470 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
471 * the SWFW lock
472 * @hw: pointer to hardware structure
473 * @reg_addr: 32 bit address of PHY register to read
474 * @phy_data: Pointer to read data from PHY register
475 **/
476s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
477 u16 *phy_data)
478{
479 u32 i, data, command;
480
481 /* Setup and write the address cycle command */
482 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
483 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
484 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
485 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
486
487 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
488
489 /* Check every 10 usec to see if the address cycle completed.
490 * The MDI Command bit will clear when the operation is
491 * complete
492 */
493 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
494 udelay(10);
495
496 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
497 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
498 break;
499 }
500
501
502 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
503 hw_dbg(hw, "PHY address command did not complete.\n");
504 return IXGBE_ERR_PHY;
505 }
506
507 /* Address cycle complete, setup and write the read
508 * command
509 */
510 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
511 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
512 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
513 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
514
515 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
516
517 /* Check every 10 usec to see if the address cycle
518 * completed. The MDI Command bit will clear when the
519 * operation is complete
520 */
521 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
522 udelay(10);
523
524 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
525 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
526 break;
527 }
528
529 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
530 hw_dbg(hw, "PHY read command didn't complete\n");
531 return IXGBE_ERR_PHY;
532 }
533
534 /* Read operation is complete. Get the data
535 * from MSRWD
536 */
537 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
538 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
539 *phy_data = (u16)(data);
540
541 return 0;
542}
543
544/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700545 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000546 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700547 * @hw: pointer to hardware structure
548 * @reg_addr: 32 bit address of PHY register to read
549 * @phy_data: Pointer to read data from PHY register
550 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700551s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000552 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700553{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000554 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000555 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700556
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000557 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
558 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
559 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000560 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000561 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000562 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700563 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700564
Auke Kok9a799d72007-09-15 14:07:45 -0700565 return status;
566}
567
568/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000569 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
570 * without SWFW lock
571 * @hw: pointer to hardware structure
572 * @reg_addr: 32 bit PHY register to write
573 * @device_type: 5 bit device type
574 * @phy_data: Data to write to the PHY register
575 **/
576s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
577 u32 device_type, u16 phy_data)
578{
579 u32 i, command;
580
581 /* Put the data in the MDI single read and write data register*/
582 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
583
584 /* Setup and write the address cycle command */
585 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
586 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
587 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
588 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
589
590 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
591
592 /*
593 * Check every 10 usec to see if the address cycle completed.
594 * The MDI Command bit will clear when the operation is
595 * complete
596 */
597 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
598 udelay(10);
599
600 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
601 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
602 break;
603 }
604
605 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
606 hw_dbg(hw, "PHY address cmd didn't complete\n");
607 return IXGBE_ERR_PHY;
608 }
609
610 /*
611 * Address cycle complete, setup and write the write
612 * command
613 */
614 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
615 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
616 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
617 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
618
619 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
620
621 /* Check every 10 usec to see if the address cycle
622 * completed. The MDI Command bit will clear when the
623 * operation is complete
624 */
625 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
626 udelay(10);
627
628 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
629 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
630 break;
631 }
632
633 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
634 hw_dbg(hw, "PHY write cmd didn't complete\n");
635 return IXGBE_ERR_PHY;
636 }
637
638 return 0;
639}
640
641/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700642 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000643 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700644 * @hw: pointer to hardware structure
645 * @reg_addr: 32 bit PHY register to write
646 * @device_type: 5 bit device type
647 * @phy_data: Data to write to the PHY register
648 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700649s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000650 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700651{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000652 s32 status;
Don Skidmore897b9342015-06-19 19:14:57 -0400653 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700654
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000655 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
656 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
657 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000658 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000659 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000660 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700661 }
662
663 return status;
664}
665
666/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700667 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700668 * @hw: pointer to hardware structure
669 *
670 * Restart autonegotiation and PHY and waits for completion.
671 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700672s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700673{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000674 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000675 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
676 bool autoneg = false;
677 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700678
Emil Tantilov9dda1732011-03-05 01:28:07 +0000679 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700680
Don Skidmored2e455a2016-10-21 21:10:54 -0400681 /* Set or unset auto-negotiation 10G advertisement */
682 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, &autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000683
Don Skidmored2e455a2016-10-21 21:10:54 -0400684 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
685 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) &&
686 (speed & IXGBE_LINK_SPEED_10GB_FULL))
687 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700688
Don Skidmored2e455a2016-10-21 21:10:54 -0400689 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, MDIO_MMD_AN, autoneg_reg);
690
691 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
692 MDIO_MMD_AN, &autoneg_reg);
693
694 if (hw->mac.type == ixgbe_mac_X550) {
695 /* Set or unset auto-negotiation 5G advertisement */
696 autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
697 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) &&
698 (speed & IXGBE_LINK_SPEED_5GB_FULL))
699 autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
700
701 /* Set or unset auto-negotiation 2.5G advertisement */
702 autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
703 if ((hw->phy.autoneg_advertised &
704 IXGBE_LINK_SPEED_2_5GB_FULL) &&
705 (speed & IXGBE_LINK_SPEED_2_5GB_FULL))
706 autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000707 }
708
Don Skidmored2e455a2016-10-21 21:10:54 -0400709 /* Set or unset auto-negotiation 1G advertisement */
710 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
711 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) &&
712 (speed & IXGBE_LINK_SPEED_1GB_FULL))
713 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000714
Don Skidmored2e455a2016-10-21 21:10:54 -0400715 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
716 MDIO_MMD_AN, autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000717
Don Skidmored2e455a2016-10-21 21:10:54 -0400718 /* Set or unset auto-negotiation 100M advertisement */
719 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000720
Don Skidmored2e455a2016-10-21 21:10:54 -0400721 autoneg_reg &= ~(ADVERTISE_100FULL | ADVERTISE_100HALF);
722 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) &&
723 (speed & IXGBE_LINK_SPEED_100_FULL))
724 autoneg_reg |= ADVERTISE_100FULL;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000725
Don Skidmored2e455a2016-10-21 21:10:54 -0400726 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700727
Don Skidmorec97506a2014-02-27 20:32:43 -0800728 /* Blocked by MNG FW so don't reset PHY */
729 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000730 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800731
Auke Kok9a799d72007-09-15 14:07:45 -0700732 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000733 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
734 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700735
Ben Hutchings6b73e102009-04-29 08:08:58 +0000736 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700737
Emil Tantilov9dda1732011-03-05 01:28:07 +0000738 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
739 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700740
Auke Kok9a799d72007-09-15 14:07:45 -0700741 return status;
742}
743
744/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700745 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700746 * @hw: pointer to hardware structure
747 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700748 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700749s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000750 ixgbe_link_speed speed,
751 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700752{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700753
Auke Kok9a799d72007-09-15 14:07:45 -0700754 /*
755 * Clear autoneg_advertised and set new values based on input link
756 * speed.
757 */
758 hw->phy.autoneg_advertised = 0;
759
760 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
761 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700762
Auke Kok9a799d72007-09-15 14:07:45 -0700763 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
764 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
765
Emil Tantilov9dda1732011-03-05 01:28:07 +0000766 if (speed & IXGBE_LINK_SPEED_100_FULL)
767 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
768
Auke Kok9a799d72007-09-15 14:07:45 -0700769 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700770 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700771
772 return 0;
773}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700774
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700775/**
Mark Rustadae8140a2015-06-25 17:49:57 -0700776 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
777 * @hw: pointer to hardware structure
778 *
779 * Determines the supported link capabilities by reading the PHY auto
780 * negotiation register.
781 */
782static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
783{
784 u16 speed_ability;
785 s32 status;
786
787 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
788 &speed_ability);
789 if (status)
790 return status;
791
792 if (speed_ability & MDIO_SPEED_10G)
793 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
794 if (speed_ability & MDIO_PMA_SPEED_1000)
795 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
796 if (speed_ability & MDIO_PMA_SPEED_100)
797 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
798
799 switch (hw->mac.type) {
800 case ixgbe_mac_X550:
801 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
802 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
803 break;
804 case ixgbe_mac_X550EM_x:
Don Skidmore470739b2016-11-03 21:01:37 -0400805 case ixgbe_mac_x550em_a:
Mark Rustadae8140a2015-06-25 17:49:57 -0700806 hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
807 break;
808 default:
809 break;
810 }
811
812 return 0;
813}
814
815/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800816 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
817 * @hw: pointer to hardware structure
818 * @speed: pointer to link speed
819 * @autoneg: boolean auto-negotiation value
Don Skidmorea391f1d2010-11-16 19:27:15 -0800820 */
821s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000822 ixgbe_link_speed *speed,
823 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800824{
Mark Rustadae8140a2015-06-25 17:49:57 -0700825 s32 status = 0;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800826
Don Skidmorea391f1d2010-11-16 19:27:15 -0800827 *autoneg = true;
Mark Rustadae8140a2015-06-25 17:49:57 -0700828 if (!hw->phy.speeds_supported)
829 status = ixgbe_get_copper_speeds_supported(hw);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800830
Mark Rustadae8140a2015-06-25 17:49:57 -0700831 *speed = hw->phy.speeds_supported;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800832 return status;
833}
834
835/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000836 * ixgbe_check_phy_link_tnx - Determine link and speed status
837 * @hw: pointer to hardware structure
838 *
839 * Reads the VS1 register to determine if link is up and the current speed for
840 * the PHY.
841 **/
842s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
843 bool *link_up)
844{
Mark Rustade90dd262014-07-22 06:51:08 +0000845 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000846 u32 time_out;
847 u32 max_time_out = 10;
848 u16 phy_link = 0;
849 u16 phy_speed = 0;
850 u16 phy_data = 0;
851
852 /* Initialize speed and link to default case */
853 *link_up = false;
854 *speed = IXGBE_LINK_SPEED_10GB_FULL;
855
856 /*
857 * Check current speed and link status of the PHY register.
858 * This is a vendor specific register and may have to
859 * be changed for other copper PHYs.
860 */
861 for (time_out = 0; time_out < max_time_out; time_out++) {
862 udelay(10);
863 status = hw->phy.ops.read_reg(hw,
864 MDIO_STAT1,
865 MDIO_MMD_VEND1,
866 &phy_data);
867 phy_link = phy_data &
868 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
869 phy_speed = phy_data &
870 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
871 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
872 *link_up = true;
873 if (phy_speed ==
874 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
875 *speed = IXGBE_LINK_SPEED_1GB_FULL;
876 break;
877 }
878 }
879
880 return status;
881}
882
883/**
884 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
885 * @hw: pointer to hardware structure
886 *
887 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000888 * This function always returns success, this is nessary since
889 * it is called via a function pointer that could call other
890 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000891 **/
892s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
893{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000894 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
895 bool autoneg = false;
896 ixgbe_link_speed speed;
897
898 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
899
900 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
901 /* Set or unset auto-negotiation 10G advertisement */
902 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
903 MDIO_MMD_AN,
904 &autoneg_reg);
905
906 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
907 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
908 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
909
910 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
911 MDIO_MMD_AN,
912 autoneg_reg);
913 }
914
915 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
916 /* Set or unset auto-negotiation 1G advertisement */
917 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
918 MDIO_MMD_AN,
919 &autoneg_reg);
920
921 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
922 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
923 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
924
925 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
926 MDIO_MMD_AN,
927 autoneg_reg);
928 }
929
930 if (speed & IXGBE_LINK_SPEED_100_FULL) {
931 /* Set or unset auto-negotiation 100M advertisement */
932 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
933 MDIO_MMD_AN,
934 &autoneg_reg);
935
Emil Tantilov50c022e2011-03-31 09:36:12 +0000936 autoneg_reg &= ~(ADVERTISE_100FULL |
937 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000938 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
939 autoneg_reg |= ADVERTISE_100FULL;
940
941 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
942 MDIO_MMD_AN,
943 autoneg_reg);
944 }
945
Don Skidmorec97506a2014-02-27 20:32:43 -0800946 /* Blocked by MNG FW so don't reset PHY */
947 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000948 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800949
Emil Tantilov9dda1732011-03-05 01:28:07 +0000950 /* Restart PHY autonegotiation and wait for completion */
951 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
952 MDIO_MMD_AN, &autoneg_reg);
953
954 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
955
956 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
957 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000958 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000959}
960
961/**
962 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
963 * @hw: pointer to hardware structure
964 * @firmware_version: pointer to the PHY Firmware Version
965 **/
966s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
967 u16 *firmware_version)
968{
Mark Rustade90dd262014-07-22 06:51:08 +0000969 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000970
971 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
972 MDIO_MMD_VEND1,
973 firmware_version);
974
975 return status;
976}
977
978/**
979 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
980 * @hw: pointer to hardware structure
981 * @firmware_version: pointer to the PHY Firmware Version
982 **/
983s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
984 u16 *firmware_version)
985{
Mark Rustade90dd262014-07-22 06:51:08 +0000986 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000987
988 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
989 MDIO_MMD_VEND1,
990 firmware_version);
991
992 return status;
993}
994
995/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800996 * ixgbe_reset_phy_nl - Performs a PHY reset
997 * @hw: pointer to hardware structure
998 **/
999s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
1000{
1001 u16 phy_offset, control, eword, edata, block_crc;
1002 bool end_data = false;
1003 u16 list_offset, data_offset;
1004 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +00001005 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001006 u32 i;
1007
Don Skidmorec97506a2014-02-27 20:32:43 -08001008 /* Blocked by MNG FW so bail */
1009 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00001010 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -08001011
Ben Hutchings6b73e102009-04-29 08:08:58 +00001012 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001013
1014 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +00001015 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001016 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -08001017
1018 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +00001019 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001020 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +00001021 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001022 break;
Don Skidmore032b4322011-03-18 09:32:53 +00001023 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001024 }
1025
Ben Hutchings6b73e102009-04-29 08:08:58 +00001026 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001027 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001028 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001029 }
1030
1031 /* Get init offsets */
1032 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001033 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +00001034 if (ret_val)
1035 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001036
1037 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
1038 data_offset++;
1039 while (!end_data) {
1040 /*
1041 * Read control word from PHY init contents offset
1042 */
1043 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001044 if (ret_val)
1045 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001046 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +00001047 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001048 edata = eword & IXGBE_DATA_MASK_NL;
1049 switch (control) {
1050 case IXGBE_DELAY_NL:
1051 data_offset++;
1052 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +00001053 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001054 break;
1055 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +00001056 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001057 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001058 ret_val = hw->eeprom.ops.read(hw, data_offset++,
1059 &phy_offset);
1060 if (ret_val)
1061 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001062 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001063 ret_val = hw->eeprom.ops.read(hw, data_offset,
1064 &eword);
1065 if (ret_val)
1066 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001067 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001068 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001069 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1070 phy_offset);
1071 data_offset++;
1072 phy_offset++;
1073 }
1074 break;
1075 case IXGBE_CONTROL_NL:
1076 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +00001077 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08001078 if (edata == IXGBE_CONTROL_EOL_NL) {
1079 hw_dbg(hw, "EOL\n");
1080 end_data = true;
1081 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1082 hw_dbg(hw, "SOL\n");
1083 } else {
1084 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001085 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001086 }
1087 break;
1088 default:
1089 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +00001090 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001091 }
1092 }
1093
Donald Skidmorec4900be2008-11-20 21:11:42 -08001094 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001095
1096err_eeprom:
1097 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1098 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001099}
1100
1101/**
Don Skidmore8f583322013-07-27 06:25:38 +00001102 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -08001103 * @hw: pointer to hardware structure
1104 *
Don Skidmore8f583322013-07-27 06:25:38 +00001105 * Determines HW type and calls appropriate function.
1106 **/
1107s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1108{
Don Skidmore8f583322013-07-27 06:25:38 +00001109 switch (hw->mac.ops.get_media_type(hw)) {
1110 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +00001111 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001112 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +00001113 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +00001114 default:
1115 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001116 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001117 }
1118
Mark Rustade90dd262014-07-22 06:51:08 +00001119 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001120}
1121
1122/**
1123 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1124 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +00001125 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001126 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001127 **/
1128s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1129{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001130 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001131 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001132 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001133 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001134 u8 identifier = 0;
1135 u8 comp_codes_1g = 0;
1136 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001137 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001138 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001139 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001140 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001141
Don Skidmore8ca783a2009-05-26 20:40:47 -07001142 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1143 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001144 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -07001145 }
1146
Mark Rustadda4ea4b2015-08-08 16:18:07 -07001147 /* LAN ID is needed for sfp_type determination */
1148 hw->mac.ops.set_lan_id(hw);
1149
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001150 status = hw->phy.ops.read_i2c_eeprom(hw,
1151 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +00001152 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -08001153
Mark Rustade90dd262014-07-22 06:51:08 +00001154 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001155 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001156
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001157 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1158 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001159 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1160 }
1161 status = hw->phy.ops.read_i2c_eeprom(hw,
1162 IXGBE_SFF_1GBE_COMP_CODES,
1163 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001164
Mark Rustade90dd262014-07-22 06:51:08 +00001165 if (status)
1166 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001167
Mark Rustade90dd262014-07-22 06:51:08 +00001168 status = hw->phy.ops.read_i2c_eeprom(hw,
1169 IXGBE_SFF_10GBE_COMP_CODES,
1170 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001171
Mark Rustade90dd262014-07-22 06:51:08 +00001172 if (status)
1173 goto err_read_i2c_eeprom;
1174 status = hw->phy.ops.read_i2c_eeprom(hw,
1175 IXGBE_SFF_CABLE_TECHNOLOGY,
1176 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001177
Mark Rustade90dd262014-07-22 06:51:08 +00001178 if (status)
1179 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001180
Mark Rustade90dd262014-07-22 06:51:08 +00001181 /* ID Module
1182 * =========
1183 * 0 SFP_DA_CU
1184 * 1 SFP_SR
1185 * 2 SFP_LR
1186 * 3 SFP_DA_CORE0 - 82599-specific
1187 * 4 SFP_DA_CORE1 - 82599-specific
1188 * 5 SFP_SR/LR_CORE0 - 82599-specific
1189 * 6 SFP_SR/LR_CORE1 - 82599-specific
1190 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1191 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1192 * 9 SFP_1g_cu_CORE0 - 82599-specific
1193 * 10 SFP_1g_cu_CORE1 - 82599-specific
1194 * 11 SFP_1g_sx_CORE0 - 82599-specific
1195 * 12 SFP_1g_sx_CORE1 - 82599-specific
1196 */
1197 if (hw->mac.type == ixgbe_mac_82598EB) {
1198 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1199 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1200 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1201 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1202 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1203 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1204 else
1205 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Mark Rustad69eec0c2015-08-08 16:18:43 -07001206 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001207 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1208 if (hw->bus.lan_id == 0)
1209 hw->phy.sfp_type =
1210 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001211 else
Mark Rustade90dd262014-07-22 06:51:08 +00001212 hw->phy.sfp_type =
1213 ixgbe_sfp_type_da_cu_core1;
1214 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1215 hw->phy.ops.read_i2c_eeprom(
1216 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1217 &cable_spec);
1218 if (cable_spec &
1219 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001220 if (hw->bus.lan_id == 0)
1221 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001222 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001223 else
1224 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +00001225 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001226 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001227 hw->phy.sfp_type =
1228 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001229 }
Mark Rustade90dd262014-07-22 06:51:08 +00001230 } else if (comp_codes_10g &
1231 (IXGBE_SFF_10GBASESR_CAPABLE |
1232 IXGBE_SFF_10GBASELR_CAPABLE)) {
1233 if (hw->bus.lan_id == 0)
1234 hw->phy.sfp_type =
1235 ixgbe_sfp_type_srlr_core0;
1236 else
1237 hw->phy.sfp_type =
1238 ixgbe_sfp_type_srlr_core1;
1239 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1240 if (hw->bus.lan_id == 0)
1241 hw->phy.sfp_type =
1242 ixgbe_sfp_type_1g_cu_core0;
1243 else
1244 hw->phy.sfp_type =
1245 ixgbe_sfp_type_1g_cu_core1;
1246 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1247 if (hw->bus.lan_id == 0)
1248 hw->phy.sfp_type =
1249 ixgbe_sfp_type_1g_sx_core0;
1250 else
1251 hw->phy.sfp_type =
1252 ixgbe_sfp_type_1g_sx_core1;
1253 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1254 if (hw->bus.lan_id == 0)
1255 hw->phy.sfp_type =
1256 ixgbe_sfp_type_1g_lx_core0;
1257 else
1258 hw->phy.sfp_type =
1259 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001260 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001261 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001262 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001263 }
1264
Mark Rustade90dd262014-07-22 06:51:08 +00001265 if (hw->phy.sfp_type != stored_sfp_type)
1266 hw->phy.sfp_setup_needed = true;
1267
1268 /* Determine if the SFP+ PHY is dual speed or not. */
1269 hw->phy.multispeed_fiber = false;
1270 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1271 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1272 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1273 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1274 hw->phy.multispeed_fiber = true;
1275
1276 /* Determine PHY vendor */
1277 if (hw->phy.type != ixgbe_phy_nl) {
1278 hw->phy.id = identifier;
1279 status = hw->phy.ops.read_i2c_eeprom(hw,
1280 IXGBE_SFF_VENDOR_OUI_BYTE0,
1281 &oui_bytes[0]);
1282
1283 if (status != 0)
1284 goto err_read_i2c_eeprom;
1285
1286 status = hw->phy.ops.read_i2c_eeprom(hw,
1287 IXGBE_SFF_VENDOR_OUI_BYTE1,
1288 &oui_bytes[1]);
1289
1290 if (status != 0)
1291 goto err_read_i2c_eeprom;
1292
1293 status = hw->phy.ops.read_i2c_eeprom(hw,
1294 IXGBE_SFF_VENDOR_OUI_BYTE2,
1295 &oui_bytes[2]);
1296
1297 if (status != 0)
1298 goto err_read_i2c_eeprom;
1299
1300 vendor_oui =
1301 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1302 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1303 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1304
1305 switch (vendor_oui) {
1306 case IXGBE_SFF_VENDOR_OUI_TYCO:
1307 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1308 hw->phy.type =
1309 ixgbe_phy_sfp_passive_tyco;
1310 break;
1311 case IXGBE_SFF_VENDOR_OUI_FTL:
1312 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1313 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1314 else
1315 hw->phy.type = ixgbe_phy_sfp_ftl;
1316 break;
1317 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1318 hw->phy.type = ixgbe_phy_sfp_avago;
1319 break;
1320 case IXGBE_SFF_VENDOR_OUI_INTEL:
1321 hw->phy.type = ixgbe_phy_sfp_intel;
1322 break;
1323 default:
1324 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1325 hw->phy.type =
1326 ixgbe_phy_sfp_passive_unknown;
1327 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1328 hw->phy.type =
1329 ixgbe_phy_sfp_active_unknown;
1330 else
1331 hw->phy.type = ixgbe_phy_sfp_unknown;
1332 break;
1333 }
1334 }
1335
1336 /* Allow any DA cable vendor */
1337 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1338 IXGBE_SFF_DA_ACTIVE_CABLE))
1339 return 0;
1340
1341 /* Verify supported 1G SFP modules */
1342 if (comp_codes_10g == 0 &&
1343 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1344 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1345 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1346 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1347 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1348 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1349 hw->phy.type = ixgbe_phy_sfp_unsupported;
1350 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1351 }
1352
1353 /* Anything else 82598-based is supported */
1354 if (hw->mac.type == ixgbe_mac_82598EB)
1355 return 0;
1356
1357 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1358 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1359 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1360 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1361 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1362 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1363 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1364 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1365 /* Make sure we're a supported PHY type */
1366 if (hw->phy.type == ixgbe_phy_sfp_intel)
1367 return 0;
1368 if (hw->allow_unsupported_sfp) {
1369 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");
1370 return 0;
1371 }
1372 hw_dbg(hw, "SFP+ module not supported\n");
1373 hw->phy.type = ixgbe_phy_sfp_unsupported;
1374 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1375 }
1376 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001377
1378err_read_i2c_eeprom:
1379 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1380 if (hw->phy.type != ixgbe_phy_nl) {
1381 hw->phy.id = 0;
1382 hw->phy.type = ixgbe_phy_unknown;
1383 }
1384 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001385}
1386
1387/**
Don Skidmore8f583322013-07-27 06:25:38 +00001388 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1389 * @hw: pointer to hardware structure
1390 *
1391 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1392 **/
Mark Rustad88217542013-11-23 03:19:19 +00001393static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001394{
1395 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001396 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001397 u32 vendor_oui = 0;
1398 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1399 u8 identifier = 0;
1400 u8 comp_codes_1g = 0;
1401 u8 comp_codes_10g = 0;
1402 u8 oui_bytes[3] = {0, 0, 0};
1403 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001404 u8 connector = 0;
1405 u8 cable_length = 0;
1406 u8 device_tech = 0;
1407 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001408
1409 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1410 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001411 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001412 }
1413
Don Skidmore7e49d612015-06-09 17:48:54 -07001414 /* LAN ID is needed for sfp_type determination */
1415 hw->mac.ops.set_lan_id(hw);
1416
Don Skidmore8f583322013-07-27 06:25:38 +00001417 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1418 &identifier);
1419
1420 if (status != 0)
1421 goto err_read_i2c_eeprom;
1422
1423 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1424 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001425 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001426 }
1427
1428 hw->phy.id = identifier;
1429
Don Skidmore8f583322013-07-27 06:25:38 +00001430 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1431 &comp_codes_10g);
1432
1433 if (status != 0)
1434 goto err_read_i2c_eeprom;
1435
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001436 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1437 &comp_codes_1g);
1438
1439 if (status != 0)
1440 goto err_read_i2c_eeprom;
1441
Don Skidmore8f583322013-07-27 06:25:38 +00001442 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1443 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1444 if (hw->bus.lan_id == 0)
1445 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1446 else
1447 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001448 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1449 IXGBE_SFF_10GBASELR_CAPABLE)) {
1450 if (hw->bus.lan_id == 0)
1451 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1452 else
1453 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1454 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001455 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1456 active_cable = true;
1457
1458 if (!active_cable) {
1459 /* check for active DA cables that pre-date
1460 * SFF-8436 v3.6
1461 */
1462 hw->phy.ops.read_i2c_eeprom(hw,
1463 IXGBE_SFF_QSFP_CONNECTOR,
1464 &connector);
1465
1466 hw->phy.ops.read_i2c_eeprom(hw,
1467 IXGBE_SFF_QSFP_CABLE_LENGTH,
1468 &cable_length);
1469
1470 hw->phy.ops.read_i2c_eeprom(hw,
1471 IXGBE_SFF_QSFP_DEVICE_TECH,
1472 &device_tech);
1473
1474 if ((connector ==
1475 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1476 (cable_length > 0) &&
1477 ((device_tech >> 4) ==
1478 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1479 active_cable = true;
1480 }
1481
1482 if (active_cable) {
1483 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1484 if (hw->bus.lan_id == 0)
1485 hw->phy.sfp_type =
1486 ixgbe_sfp_type_da_act_lmt_core0;
1487 else
1488 hw->phy.sfp_type =
1489 ixgbe_sfp_type_da_act_lmt_core1;
1490 } else {
1491 /* unsupported module type */
1492 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001493 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001494 }
Don Skidmore8f583322013-07-27 06:25:38 +00001495 }
1496
1497 if (hw->phy.sfp_type != stored_sfp_type)
1498 hw->phy.sfp_setup_needed = true;
1499
1500 /* Determine if the QSFP+ PHY is dual speed or not. */
1501 hw->phy.multispeed_fiber = false;
1502 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1503 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1504 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1505 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1506 hw->phy.multispeed_fiber = true;
1507
1508 /* Determine PHY vendor for optical modules */
1509 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1510 IXGBE_SFF_10GBASELR_CAPABLE)) {
1511 status = hw->phy.ops.read_i2c_eeprom(hw,
1512 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1513 &oui_bytes[0]);
1514
1515 if (status != 0)
1516 goto err_read_i2c_eeprom;
1517
1518 status = hw->phy.ops.read_i2c_eeprom(hw,
1519 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1520 &oui_bytes[1]);
1521
1522 if (status != 0)
1523 goto err_read_i2c_eeprom;
1524
1525 status = hw->phy.ops.read_i2c_eeprom(hw,
1526 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1527 &oui_bytes[2]);
1528
1529 if (status != 0)
1530 goto err_read_i2c_eeprom;
1531
1532 vendor_oui =
1533 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1534 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1535 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1536
1537 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1538 hw->phy.type = ixgbe_phy_qsfp_intel;
1539 else
1540 hw->phy.type = ixgbe_phy_qsfp_unknown;
1541
1542 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1543 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1544 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001545 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1546 return 0;
1547 if (hw->allow_unsupported_sfp) {
1548 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");
1549 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001550 }
Mark Rustade90dd262014-07-22 06:51:08 +00001551 hw_dbg(hw, "QSFP module not supported\n");
1552 hw->phy.type = ixgbe_phy_sfp_unsupported;
1553 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001554 }
Mark Rustade90dd262014-07-22 06:51:08 +00001555 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001556 }
Mark Rustade90dd262014-07-22 06:51:08 +00001557 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001558
1559err_read_i2c_eeprom:
1560 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1561 hw->phy.id = 0;
1562 hw->phy.type = ixgbe_phy_unknown;
1563
1564 return IXGBE_ERR_SFP_NOT_PRESENT;
1565}
1566
1567/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001568 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001569 * @hw: pointer to hardware structure
1570 * @list_offset: offset to the SFP ID list
1571 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001572 *
1573 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1574 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001575 **/
1576s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001577 u16 *list_offset,
1578 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001579{
1580 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001581 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001582
1583 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1584 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1585
1586 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1587 return IXGBE_ERR_SFP_NOT_PRESENT;
1588
1589 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1590 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1591 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1592
Don Skidmorecb836a92010-06-29 18:30:59 +00001593 /*
1594 * Limiting active cables and 1G Phys must be initialized as
1595 * SR modules
1596 */
1597 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001598 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001599 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1600 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001601 sfp_type = ixgbe_sfp_type_srlr_core0;
1602 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001603 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001604 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1605 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001606 sfp_type = ixgbe_sfp_type_srlr_core1;
1607
Donald Skidmorec4900be2008-11-20 21:11:42 -08001608 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001609 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1610 hw_err(hw, "eeprom read at %d failed\n",
1611 IXGBE_PHY_INIT_OFFSET_NL);
1612 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1613 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001614
1615 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001616 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001617
1618 /* Shift offset to first ID word */
1619 (*list_offset)++;
1620
1621 /*
1622 * Find the matching SFP ID in the EEPROM
1623 * and program the init sequence
1624 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001625 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1626 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001627
1628 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001629 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001630 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001631 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1632 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001633 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1634 hw_dbg(hw, "SFP+ module not supported\n");
1635 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1636 } else {
1637 break;
1638 }
1639 } else {
1640 (*list_offset) += 2;
1641 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001642 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001643 }
1644 }
1645
1646 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1647 hw_dbg(hw, "No matching SFP+ module found\n");
1648 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1649 }
1650
1651 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001652
1653err_phy:
1654 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1655 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001656}
1657
1658/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001659 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1660 * @hw: pointer to hardware structure
1661 * @byte_offset: EEPROM byte offset to read
1662 * @eeprom_data: value read
1663 *
1664 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1665 **/
1666s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001667 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001668{
1669 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001670 IXGBE_I2C_EEPROM_DEV_ADDR,
1671 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001672}
1673
1674/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001675 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1676 * @hw: pointer to hardware structure
1677 * @byte_offset: byte offset at address 0xA2
1678 * @eeprom_data: value read
1679 *
1680 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1681 **/
1682s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1683 u8 *sff8472_data)
1684{
1685 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1686 IXGBE_I2C_EEPROM_DEV_ADDR2,
1687 sff8472_data);
1688}
1689
1690/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001691 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1692 * @hw: pointer to hardware structure
1693 * @byte_offset: EEPROM byte offset to write
1694 * @eeprom_data: value to write
1695 *
1696 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1697 **/
1698s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001699 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001700{
1701 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001702 IXGBE_I2C_EEPROM_DEV_ADDR,
1703 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001704}
1705
1706/**
Mark Rustad56f6ed12015-08-08 16:18:22 -07001707 * ixgbe_is_sfp_probe - Returns true if SFP is being detected
1708 * @hw: pointer to hardware structure
1709 * @offset: eeprom offset to be read
1710 * @addr: I2C address to be read
1711 */
1712static bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
1713{
1714 if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
1715 offset == IXGBE_SFF_IDENTIFIER &&
1716 hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1717 return true;
1718 return false;
1719}
1720
1721/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001722 * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001723 * @hw: pointer to hardware structure
1724 * @byte_offset: byte offset to read
1725 * @data: value read
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001726 * @lock: true if to take and release semaphore
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001727 *
1728 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001729 * a specified device address.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001730 */
1731static s32 ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
1732 u8 dev_addr, u8 *data, bool lock)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001733{
Mark Rustade90dd262014-07-22 06:51:08 +00001734 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001735 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001736 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001737 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001738 bool nack = true;
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001739
Mark Rustad56f6ed12015-08-08 16:18:22 -07001740 if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
1741 max_retry = IXGBE_SFP_DETECT_RETRIES;
1742
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001743 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001744
1745 do {
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001746 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Mark Rustade90dd262014-07-22 06:51:08 +00001747 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001748
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001749 ixgbe_i2c_start(hw);
1750
1751 /* Device Address and write indication */
1752 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
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, byte_offset);
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_start(hw);
1769
1770 /* Device Address and read indication */
1771 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1772 if (status != 0)
1773 goto fail;
1774
1775 status = ixgbe_get_i2c_ack(hw);
1776 if (status != 0)
1777 goto fail;
1778
1779 status = ixgbe_clock_in_i2c_byte(hw, data);
1780 if (status != 0)
1781 goto fail;
1782
1783 status = ixgbe_clock_out_i2c_bit(hw, nack);
1784 if (status != 0)
1785 goto fail;
1786
1787 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001788 if (lock)
1789 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1790 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001791
1792fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001793 ixgbe_i2c_bus_clear(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001794 if (lock) {
1795 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1796 msleep(100);
1797 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001798 retry++;
1799 if (retry < max_retry)
1800 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1801 else
1802 hw_dbg(hw, "I2C byte read error.\n");
1803
1804 } while (retry < max_retry);
1805
1806 return status;
1807}
1808
1809/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001810 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1811 * @hw: pointer to hardware structure
1812 * @byte_offset: byte offset to read
1813 * @data: value read
1814 *
1815 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1816 * a specified device address.
1817 */
1818s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1819 u8 dev_addr, u8 *data)
1820{
1821 return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1822 data, true);
1823}
1824
1825/**
1826 * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
1827 * @hw: pointer to hardware structure
1828 * @byte_offset: byte offset to read
1829 * @data: value read
1830 *
1831 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1832 * a specified device address.
1833 */
1834s32 ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
1835 u8 dev_addr, u8 *data)
1836{
1837 return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1838 data, false);
1839}
1840
1841/**
1842 * ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001843 * @hw: pointer to hardware structure
1844 * @byte_offset: byte offset to write
1845 * @data: value to write
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001846 * @lock: true if to take and release semaphore
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001847 *
1848 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1849 * a specified device address.
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001850 */
1851static s32 ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
1852 u8 dev_addr, u8 data, bool lock)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001853{
Mark Rustade90dd262014-07-22 06:51:08 +00001854 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001855 u32 max_retry = 1;
1856 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001857 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001858
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001859 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
Mark Rustade90dd262014-07-22 06:51:08 +00001860 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001861
1862 do {
1863 ixgbe_i2c_start(hw);
1864
1865 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1866 if (status != 0)
1867 goto fail;
1868
1869 status = ixgbe_get_i2c_ack(hw);
1870 if (status != 0)
1871 goto fail;
1872
1873 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1874 if (status != 0)
1875 goto fail;
1876
1877 status = ixgbe_get_i2c_ack(hw);
1878 if (status != 0)
1879 goto fail;
1880
1881 status = ixgbe_clock_out_i2c_byte(hw, data);
1882 if (status != 0)
1883 goto fail;
1884
1885 status = ixgbe_get_i2c_ack(hw);
1886 if (status != 0)
1887 goto fail;
1888
1889 ixgbe_i2c_stop(hw);
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001890 if (lock)
1891 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1892 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001893
1894fail:
1895 ixgbe_i2c_bus_clear(hw);
1896 retry++;
1897 if (retry < max_retry)
1898 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1899 else
1900 hw_dbg(hw, "I2C byte write error.\n");
1901 } while (retry < max_retry);
1902
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001903 if (lock)
1904 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001905
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001906 return status;
1907}
1908
1909/**
Mark Rustadbb5ce9a52015-08-08 16:18:02 -07001910 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1911 * @hw: pointer to hardware structure
1912 * @byte_offset: byte offset to write
1913 * @data: value to write
1914 *
1915 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1916 * a specified device address.
1917 */
1918s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1919 u8 dev_addr, u8 data)
1920{
1921 return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1922 data, true);
1923}
1924
1925/**
1926 * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
1927 * @hw: pointer to hardware structure
1928 * @byte_offset: byte offset to write
1929 * @data: value to write
1930 *
1931 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1932 * a specified device address.
1933 */
1934s32 ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
1935 u8 dev_addr, u8 data)
1936{
1937 return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
1938 data, false);
1939}
1940
1941/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001942 * ixgbe_i2c_start - Sets I2C start condition
1943 * @hw: pointer to hardware structure
1944 *
1945 * Sets I2C start condition (High -> Low on SDA while SCL is High)
Mark Rustad25b10292015-08-08 16:18:12 -07001946 * Set bit-bang mode on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001947 **/
1948static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1949{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001950 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001951
Mark Rustad25b10292015-08-08 16:18:12 -07001952 i2cctl |= IXGBE_I2C_BB_EN(hw);
1953
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001954 /* Start condition must begin with data and clock high */
1955 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1956 ixgbe_raise_i2c_clk(hw, &i2cctl);
1957
1958 /* Setup time for start condition (4.7us) */
1959 udelay(IXGBE_I2C_T_SU_STA);
1960
1961 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1962
1963 /* Hold time for start condition (4us) */
1964 udelay(IXGBE_I2C_T_HD_STA);
1965
1966 ixgbe_lower_i2c_clk(hw, &i2cctl);
1967
1968 /* Minimum low period of clock is 4.7 us */
1969 udelay(IXGBE_I2C_T_LOW);
1970
1971}
1972
1973/**
1974 * ixgbe_i2c_stop - Sets I2C stop condition
1975 * @hw: pointer to hardware structure
1976 *
1977 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
Mark Rustad25b10292015-08-08 16:18:12 -07001978 * Disables bit-bang mode and negates data output enable on X550
1979 * hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001980 **/
1981static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1982{
Don Skidmore9a900ec2015-06-09 17:15:01 -07001983 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Mark Rustad25b10292015-08-08 16:18:12 -07001984 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
1985 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
1986 u32 bb_en_bit = IXGBE_I2C_BB_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001987
1988 /* Stop condition must begin with data low and clock high */
1989 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1990 ixgbe_raise_i2c_clk(hw, &i2cctl);
1991
1992 /* Setup time for stop condition (4us) */
1993 udelay(IXGBE_I2C_T_SU_STO);
1994
1995 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1996
1997 /* bus free time between stop and start (4.7us)*/
1998 udelay(IXGBE_I2C_T_BUF);
Mark Rustad25b10292015-08-08 16:18:12 -07001999
2000 if (bb_en_bit || data_oe_bit || clk_oe_bit) {
2001 i2cctl &= ~bb_en_bit;
2002 i2cctl |= data_oe_bit | clk_oe_bit;
2003 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2004 IXGBE_WRITE_FLUSH(hw);
2005 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002006}
2007
2008/**
2009 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
2010 * @hw: pointer to hardware structure
2011 * @data: data byte to clock in
2012 *
2013 * Clocks in one byte data via I2C data/clock
2014 **/
2015static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
2016{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002017 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002018 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002019
Mark Rustad6ee8c9a2015-08-08 16:18:17 -07002020 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002021 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00002022 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002023 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002024 }
2025
Emil Tantilove1befd72011-08-27 07:18:47 +00002026 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002027}
2028
2029/**
2030 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
2031 * @hw: pointer to hardware structure
2032 * @data: data byte clocked out
2033 *
2034 * Clocks out one byte data via I2C data/clock
2035 **/
2036static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
2037{
Mark Rustade90dd262014-07-22 06:51:08 +00002038 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002039 s32 i;
2040 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002041 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002042
2043 for (i = 7; i >= 0; i--) {
2044 bit = (data >> i) & 0x1;
2045 status = ixgbe_clock_out_i2c_bit(hw, bit);
2046
2047 if (status != 0)
2048 break;
2049 }
2050
2051 /* Release SDA line (set high) */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002052 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2053 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002054 i2cctl |= IXGBE_I2C_DATA_OE_N_EN(hw);
Don Skidmore9a900ec2015-06-09 17:15:01 -07002055 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00002056 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002057
2058 return status;
2059}
2060
2061/**
2062 * ixgbe_get_i2c_ack - Polls for I2C ACK
2063 * @hw: pointer to hardware structure
2064 *
2065 * Clocks in/out one bit via I2C data/clock
2066 **/
2067static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
2068{
Mark Rustad25b10292015-08-08 16:18:12 -07002069 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
Emil Tantilove1befd72011-08-27 07:18:47 +00002070 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002071 u32 i = 0;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002072 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002073 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002074 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002075
Mark Rustad25b10292015-08-08 16:18:12 -07002076 if (data_oe_bit) {
2077 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
2078 i2cctl |= data_oe_bit;
2079 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2080 IXGBE_WRITE_FLUSH(hw);
2081 }
Emil Tantilove1befd72011-08-27 07:18:47 +00002082 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002083
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002084 /* Minimum high period of clock is 4us */
2085 udelay(IXGBE_I2C_T_HIGH);
2086
2087 /* Poll for ACK. Note that ACK in I2C spec is
2088 * transition from 1 to 0 */
2089 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002090 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002091 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002092
2093 udelay(1);
2094 if (ack == 0)
2095 break;
2096 }
2097
2098 if (ack == 1) {
2099 hw_dbg(hw, "I2C ack was not received.\n");
2100 status = IXGBE_ERR_I2C;
2101 }
2102
2103 ixgbe_lower_i2c_clk(hw, &i2cctl);
2104
2105 /* Minimum low period of clock is 4.7 us */
2106 udelay(IXGBE_I2C_T_LOW);
2107
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002108 return status;
2109}
2110
2111/**
2112 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
2113 * @hw: pointer to hardware structure
2114 * @data: read data value
2115 *
2116 * Clocks in one bit via I2C data/clock
2117 **/
2118static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
2119{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002120 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Mark Rustad25b10292015-08-08 16:18:12 -07002121 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002122
Mark Rustad25b10292015-08-08 16:18:12 -07002123 if (data_oe_bit) {
2124 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
2125 i2cctl |= data_oe_bit;
2126 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
2127 IXGBE_WRITE_FLUSH(hw);
2128 }
Emil Tantilove1befd72011-08-27 07:18:47 +00002129 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002130
2131 /* Minimum high period of clock is 4us */
2132 udelay(IXGBE_I2C_T_HIGH);
2133
Don Skidmore9a900ec2015-06-09 17:15:01 -07002134 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002135 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002136
2137 ixgbe_lower_i2c_clk(hw, &i2cctl);
2138
2139 /* Minimum low period of clock is 4.7 us */
2140 udelay(IXGBE_I2C_T_LOW);
2141
Emil Tantilove1befd72011-08-27 07:18:47 +00002142 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002143}
2144
2145/**
2146 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
2147 * @hw: pointer to hardware structure
2148 * @data: data value to write
2149 *
2150 * Clocks out one bit via I2C data/clock
2151 **/
2152static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
2153{
2154 s32 status;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002155 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002156
2157 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
2158 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00002159 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002160
2161 /* Minimum high period of clock is 4us */
2162 udelay(IXGBE_I2C_T_HIGH);
2163
2164 ixgbe_lower_i2c_clk(hw, &i2cctl);
2165
2166 /* Minimum low period of clock is 4.7 us.
2167 * This also takes care of the data hold time.
2168 */
2169 udelay(IXGBE_I2C_T_LOW);
2170 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002171 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002172 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002173 }
2174
Mark Rustade90dd262014-07-22 06:51:08 +00002175 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002176}
2177/**
2178 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2179 * @hw: pointer to hardware structure
2180 * @i2cctl: Current value of I2CCTL register
2181 *
2182 * Raises the I2C clock line '0'->'1'
Mark Rustad25b10292015-08-08 16:18:12 -07002183 * Negates the I2C clock output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002184 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00002185static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002186{
Mark Rustad25b10292015-08-08 16:18:12 -07002187 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN(hw);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002188 u32 i = 0;
2189 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2190 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002191
Mark Rustad25b10292015-08-08 16:18:12 -07002192 if (clk_oe_bit) {
2193 *i2cctl |= clk_oe_bit;
2194 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2195 }
2196
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002197 for (i = 0; i < timeout; i++) {
Don Skidmore9a900ec2015-06-09 17:15:01 -07002198 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2199 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002200 IXGBE_WRITE_FLUSH(hw);
2201 /* SCL rise time (1000ns) */
2202 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002203
Don Skidmore9a900ec2015-06-09 17:15:01 -07002204 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2205 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00002206 break;
2207 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002208}
2209
2210/**
2211 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2212 * @hw: pointer to hardware structure
2213 * @i2cctl: Current value of I2CCTL register
2214 *
2215 * Lowers the I2C clock line '1'->'0'
Mark Rustad25b10292015-08-08 16:18:12 -07002216 * Asserts the I2C clock output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002217 **/
2218static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2219{
2220
Don Skidmore9a900ec2015-06-09 17:15:01 -07002221 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002222 *i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002223
Don Skidmore9a900ec2015-06-09 17:15:01 -07002224 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002225 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002226
2227 /* SCL fall time (300ns) */
2228 udelay(IXGBE_I2C_T_FALL);
2229}
2230
2231/**
2232 * ixgbe_set_i2c_data - Sets the I2C data bit
2233 * @hw: pointer to hardware structure
2234 * @i2cctl: Current value of I2CCTL register
2235 * @data: I2C data value (0 or 1) to set
2236 *
2237 * Sets the I2C data bit
Mark Rustad25b10292015-08-08 16:18:12 -07002238 * Asserts the I2C data output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002239 **/
2240static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2241{
Mark Rustad25b10292015-08-08 16:18:12 -07002242 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
2243
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002244 if (data)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002245 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002246 else
Don Skidmore9a900ec2015-06-09 17:15:01 -07002247 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002248 *i2cctl &= ~data_oe_bit;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002249
Don Skidmore9a900ec2015-06-09 17:15:01 -07002250 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002251 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002252
2253 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2254 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2255
Mark Rustad25b10292015-08-08 16:18:12 -07002256 if (!data) /* Can't verify data in this case */
2257 return 0;
2258 if (data_oe_bit) {
2259 *i2cctl |= data_oe_bit;
2260 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2261 IXGBE_WRITE_FLUSH(hw);
2262 }
2263
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002264 /* Verify data was set correctly */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002265 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002266 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002267 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00002268 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002269 }
2270
Mark Rustade90dd262014-07-22 06:51:08 +00002271 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002272}
2273
2274/**
2275 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2276 * @hw: pointer to hardware structure
2277 * @i2cctl: Current value of I2CCTL register
2278 *
2279 * Returns the I2C data bit value
Mark Rustad25b10292015-08-08 16:18:12 -07002280 * Negates the I2C data output enable on X550 hardware.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002281 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002282static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002283{
Mark Rustad25b10292015-08-08 16:18:12 -07002284 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN(hw);
2285
2286 if (data_oe_bit) {
2287 *i2cctl |= data_oe_bit;
2288 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2289 IXGBE_WRITE_FLUSH(hw);
2290 udelay(IXGBE_I2C_T_FALL);
2291 }
2292
Don Skidmore9a900ec2015-06-09 17:15:01 -07002293 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00002294 return true;
2295 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002296}
2297
2298/**
2299 * ixgbe_i2c_bus_clear - Clears the I2C bus
2300 * @hw: pointer to hardware structure
2301 *
2302 * Clears the I2C bus by sending nine clock pulses.
2303 * Used when data line is stuck low.
2304 **/
2305static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2306{
Mark Rustad25b10292015-08-08 16:18:12 -07002307 u32 i2cctl;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002308 u32 i;
2309
Emil Tantilov75f19c32011-02-19 08:43:55 +00002310 ixgbe_i2c_start(hw);
Mark Rustad25b10292015-08-08 16:18:12 -07002311 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
Emil Tantilov75f19c32011-02-19 08:43:55 +00002312
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002313 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2314
2315 for (i = 0; i < 9; i++) {
2316 ixgbe_raise_i2c_clk(hw, &i2cctl);
2317
2318 /* Min high period of clock is 4us */
2319 udelay(IXGBE_I2C_T_HIGH);
2320
2321 ixgbe_lower_i2c_clk(hw, &i2cctl);
2322
2323 /* Min low period of clock is 4.7us*/
2324 udelay(IXGBE_I2C_T_LOW);
2325 }
2326
Emil Tantilov75f19c32011-02-19 08:43:55 +00002327 ixgbe_i2c_start(hw);
2328
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002329 /* Put the i2c bus back to default state */
2330 ixgbe_i2c_stop(hw);
2331}
2332
2333/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002334 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002335 * @hw: pointer to hardware structure
2336 *
2337 * Checks if the LASI temp alarm status was triggered due to overtemp
2338 **/
2339s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2340{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002341 u16 phy_data = 0;
2342
2343 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00002344 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002345
2346 /* Check that the LASI temp alarm status was triggered */
2347 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00002348 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002349
2350 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00002351 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002352
Mark Rustade90dd262014-07-22 06:51:08 +00002353 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002354}
Don Skidmore961fac82015-06-09 16:09:47 -07002355
2356/** ixgbe_set_copper_phy_power - Control power for copper phy
2357 * @hw: pointer to hardware structure
2358 * @on: true for on, false for off
2359 **/
2360s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2361{
2362 u32 status;
2363 u16 reg;
2364
2365 /* Bail if we don't have copper phy */
2366 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2367 return 0;
2368
Mark Rustad3c2f2b72015-11-05 11:02:14 -08002369 if (!on && ixgbe_mng_present(hw))
2370 return 0;
2371
Emil Tantilov4dc40002016-09-26 14:08:13 -07002372 status = hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, &reg);
Don Skidmore961fac82015-06-09 16:09:47 -07002373 if (status)
2374 return status;
2375
2376 if (on) {
2377 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2378 } else {
2379 if (ixgbe_check_reset_blocked(hw))
2380 return 0;
2381 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2382 }
2383
Emil Tantilov4dc40002016-09-26 14:08:13 -07002384 status = hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_VEND1, reg);
Don Skidmore961fac82015-06-09 16:09:47 -07002385 return status;
2386}