blob: a17495831d84c1e86f35f427b9b3976cbc56b205 [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/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070053 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -070054 * @hw: pointer to hardware structure
55 *
56 * Determines the physical layer module found on the current adapter.
57 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070058s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070059{
Auke Kok9a799d72007-09-15 14:07:45 -070060 u32 phy_addr;
Emil Tantilov037c6d02011-02-25 07:49:39 +000061 u16 ext_ability = 0;
Auke Kok9a799d72007-09-15 14:07:45 -070062
Don Skidmore030eaec2014-11-29 05:22:37 +000063 if (!hw->phy.phy_semaphore_mask) {
64 hw->phy.lan_id = IXGBE_READ_REG(hw, IXGBE_STATUS) &
65 IXGBE_STATUS_LAN_ID_1;
66 if (hw->phy.lan_id)
67 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
68 else
69 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
70 }
71
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070072 if (hw->phy.type == ixgbe_phy_unknown) {
73 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +000074 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +000075 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070076 ixgbe_get_phy_id(hw);
77 hw->phy.type =
Jacob Kellere7cf7452014-04-09 06:03:10 +000078 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +000079
80 if (hw->phy.type == ixgbe_phy_unknown) {
81 hw->phy.ops.read_reg(hw,
82 MDIO_PMA_EXTABLE,
83 MDIO_MMD_PMAPMD,
84 &ext_ability);
85 if (ext_ability &
86 (MDIO_PMA_EXTABLE_10GBT |
87 MDIO_PMA_EXTABLE_1000BT))
88 hw->phy.type =
89 ixgbe_phy_cu_unknown;
90 else
91 hw->phy.type =
92 ixgbe_phy_generic;
93 }
94
Mark Rustade90dd262014-07-22 06:51:08 +000095 return 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070096 }
Auke Kok9a799d72007-09-15 14:07:45 -070097 }
Don Skidmore63d6e1d2009-07-02 12:50:12 +000098 /* clear value if nothing found */
Mark Rustade90dd262014-07-22 06:51:08 +000099 hw->phy.mdio.prtad = 0;
100 return IXGBE_ERR_PHY_ADDR_INVALID;
Auke Kok9a799d72007-09-15 14:07:45 -0700101 }
Mark Rustade90dd262014-07-22 06:51:08 +0000102 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700103}
104
105/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800106 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
107 * @hw: pointer to the hardware structure
108 *
109 * This function checks the MMNGC.MNG_VETO bit to see if there are
110 * any constraints on link from manageability. For MAC's that don't
111 * have this bit just return false since the link can not be blocked
112 * via this method.
113 **/
Jean Sacren6425f0f2014-03-11 05:57:56 +0000114bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
Don Skidmorec97506a2014-02-27 20:32:43 -0800115{
116 u32 mmngc;
117
118 /* If we don't have this bit, it can't be blocking */
119 if (hw->mac.type == ixgbe_mac_82598EB)
120 return false;
121
122 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
123 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
124 hw_dbg(hw, "MNG_VETO bit detected.\n");
125 return true;
126 }
127
128 return false;
129}
130
131/**
Auke Kok9a799d72007-09-15 14:07:45 -0700132 * ixgbe_get_phy_id - Get the phy type
133 * @hw: pointer to hardware structure
134 *
135 **/
136static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
137{
138 u32 status;
139 u16 phy_id_high = 0;
140 u16 phy_id_low = 0;
141
Ben Hutchings6b73e102009-04-29 08:08:58 +0000142 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000143 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700144
145 if (status == 0) {
146 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000147 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000148 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700149 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
150 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
151 }
Auke Kok9a799d72007-09-15 14:07:45 -0700152 return status;
153}
154
155/**
156 * ixgbe_get_phy_type_from_id - Get the phy type
157 * @hw: pointer to hardware structure
158 *
159 **/
160static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
161{
162 enum ixgbe_phy_type phy_type;
163
164 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700165 case TN1010_PHY_ID:
166 phy_type = ixgbe_phy_tn;
167 break;
Don Skidmore2b264902010-12-09 06:55:14 +0000168 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800169 phy_type = ixgbe_phy_aq;
170 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700171 case QT2022_PHY_ID:
172 phy_type = ixgbe_phy_qt;
173 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800174 case ATH_PHY_ID:
175 phy_type = ixgbe_phy_nl;
176 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700177 default:
178 phy_type = ixgbe_phy_unknown;
179 break;
180 }
181
182 return phy_type;
183}
184
185/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700186 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700187 * @hw: pointer to hardware structure
188 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700189s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700190{
Emil Tantilov17835752011-02-16 01:38:13 +0000191 u32 i;
192 u16 ctrl = 0;
193 s32 status = 0;
194
195 if (hw->phy.type == ixgbe_phy_unknown)
196 status = ixgbe_identify_phy_generic(hw);
197
198 if (status != 0 || hw->phy.type == ixgbe_phy_none)
Mark Rustade90dd262014-07-22 06:51:08 +0000199 return status;
Emil Tantilov17835752011-02-16 01:38:13 +0000200
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700201 /* Don't reset PHY if it's shut down due to overtemp. */
202 if (!hw->phy.reset_if_overtemp &&
203 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Mark Rustade90dd262014-07-22 06:51:08 +0000204 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700205
Don Skidmorec97506a2014-02-27 20:32:43 -0800206 /* Blocked by MNG FW so bail */
207 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000208 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800209
Auke Kok9a799d72007-09-15 14:07:45 -0700210 /*
211 * Perform soft PHY reset to the PHY_XS.
212 * This will cause a soft reset to the PHY
213 */
Emil Tantilov17835752011-02-16 01:38:13 +0000214 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
215 MDIO_MMD_PHYXS,
216 MDIO_CTRL1_RESET);
217
218 /*
219 * Poll for reset bit to self-clear indicating reset is complete.
220 * Some PHYs could take up to 3 seconds to complete and need about
221 * 1.7 usec delay after the reset is complete.
222 */
223 for (i = 0; i < 30; i++) {
224 msleep(100);
225 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
226 MDIO_MMD_PHYXS, &ctrl);
227 if (!(ctrl & MDIO_CTRL1_RESET)) {
228 udelay(2);
229 break;
230 }
231 }
232
233 if (ctrl & MDIO_CTRL1_RESET) {
Emil Tantilov17835752011-02-16 01:38:13 +0000234 hw_dbg(hw, "PHY reset polling failed to complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000235 return IXGBE_ERR_RESET_FAILED;
Emil Tantilov17835752011-02-16 01:38:13 +0000236 }
237
Mark Rustade90dd262014-07-22 06:51:08 +0000238 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700239}
240
241/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000242 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
243 * the SWFW lock
244 * @hw: pointer to hardware structure
245 * @reg_addr: 32 bit address of PHY register to read
246 * @phy_data: Pointer to read data from PHY register
247 **/
248s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
249 u16 *phy_data)
250{
251 u32 i, data, command;
252
253 /* Setup and write the address cycle command */
254 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
255 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
256 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
257 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
258
259 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
260
261 /* Check every 10 usec to see if the address cycle completed.
262 * The MDI Command bit will clear when the operation is
263 * complete
264 */
265 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
266 udelay(10);
267
268 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
269 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
270 break;
271 }
272
273
274 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
275 hw_dbg(hw, "PHY address command did not complete.\n");
276 return IXGBE_ERR_PHY;
277 }
278
279 /* Address cycle complete, setup and write the read
280 * command
281 */
282 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
283 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
284 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
285 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
286
287 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
288
289 /* Check every 10 usec to see if the address cycle
290 * completed. The MDI Command bit will clear when the
291 * operation is complete
292 */
293 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
294 udelay(10);
295
296 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
297 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
298 break;
299 }
300
301 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
302 hw_dbg(hw, "PHY read command didn't complete\n");
303 return IXGBE_ERR_PHY;
304 }
305
306 /* Read operation is complete. Get the data
307 * from MSRWD
308 */
309 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
310 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
311 *phy_data = (u16)(data);
312
313 return 0;
314}
315
316/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700317 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000318 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700319 * @hw: pointer to hardware structure
320 * @reg_addr: 32 bit address of PHY register to read
321 * @phy_data: Pointer to read data from PHY register
322 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700323s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000324 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700325{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000326 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000327 u32 gssr = hw->phy.phy_semaphore_mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700328
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000329 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
330 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
331 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000332 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000333 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000334 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700335 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700336
Auke Kok9a799d72007-09-15 14:07:45 -0700337 return status;
338}
339
340/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000341 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
342 * without SWFW lock
343 * @hw: pointer to hardware structure
344 * @reg_addr: 32 bit PHY register to write
345 * @device_type: 5 bit device type
346 * @phy_data: Data to write to the PHY register
347 **/
348s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
349 u32 device_type, u16 phy_data)
350{
351 u32 i, command;
352
353 /* Put the data in the MDI single read and write data register*/
354 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
355
356 /* Setup and write the address cycle command */
357 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
358 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
359 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
360 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
361
362 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
363
364 /*
365 * Check every 10 usec to see if the address cycle completed.
366 * The MDI Command bit will clear when the operation is
367 * complete
368 */
369 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
370 udelay(10);
371
372 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
373 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
374 break;
375 }
376
377 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
378 hw_dbg(hw, "PHY address cmd didn't complete\n");
379 return IXGBE_ERR_PHY;
380 }
381
382 /*
383 * Address cycle complete, setup and write the write
384 * command
385 */
386 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
387 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
388 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
389 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
390
391 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
392
393 /* Check every 10 usec to see if the address cycle
394 * completed. The MDI Command bit will clear when the
395 * operation is complete
396 */
397 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
398 udelay(10);
399
400 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
401 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
402 break;
403 }
404
405 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
406 hw_dbg(hw, "PHY write cmd didn't complete\n");
407 return IXGBE_ERR_PHY;
408 }
409
410 return 0;
411}
412
413/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700414 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000415 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700416 * @hw: pointer to hardware structure
417 * @reg_addr: 32 bit PHY register to write
418 * @device_type: 5 bit device type
419 * @phy_data: Data to write to the PHY register
420 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700421s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000422 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700423{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000424 s32 status;
Don Skidmore030eaec2014-11-29 05:22:37 +0000425 u32 gssr;
Auke Kok9a799d72007-09-15 14:07:45 -0700426
427 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
428 gssr = IXGBE_GSSR_PHY1_SM;
429 else
430 gssr = IXGBE_GSSR_PHY0_SM;
431
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000432 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
433 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
434 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000435 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000436 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000437 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700438 }
439
440 return status;
441}
442
443/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700444 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700445 * @hw: pointer to hardware structure
446 *
447 * Restart autonegotiation and PHY and waits for completion.
448 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700449s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700450{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000451 s32 status = 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000452 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
453 bool autoneg = false;
454 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700455
Emil Tantilov9dda1732011-03-05 01:28:07 +0000456 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700457
Emil Tantilov9dda1732011-03-05 01:28:07 +0000458 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
459 /* Set or unset auto-negotiation 10G advertisement */
460 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
461 MDIO_MMD_AN,
462 &autoneg_reg);
463
Ben Hutchings6b73e102009-04-29 08:08:58 +0000464 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000465 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
466 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700467
Emil Tantilov9dda1732011-03-05 01:28:07 +0000468 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
469 MDIO_MMD_AN,
470 autoneg_reg);
471 }
472
473 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
474 /* Set or unset auto-negotiation 1G advertisement */
475 hw->phy.ops.read_reg(hw,
476 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
477 MDIO_MMD_AN,
478 &autoneg_reg);
479
480 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
481 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
482 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
483
484 hw->phy.ops.write_reg(hw,
485 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
486 MDIO_MMD_AN,
487 autoneg_reg);
488 }
489
490 if (speed & IXGBE_LINK_SPEED_100_FULL) {
491 /* Set or unset auto-negotiation 100M advertisement */
492 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
493 MDIO_MMD_AN,
494 &autoneg_reg);
495
Emil Tantilova59e8a12011-03-31 09:36:12 +0000496 autoneg_reg &= ~(ADVERTISE_100FULL |
497 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000498 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
499 autoneg_reg |= ADVERTISE_100FULL;
500
501 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
502 MDIO_MMD_AN,
503 autoneg_reg);
504 }
Auke Kok9a799d72007-09-15 14:07:45 -0700505
Don Skidmorec97506a2014-02-27 20:32:43 -0800506 /* Blocked by MNG FW so don't reset PHY */
507 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000508 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800509
Auke Kok9a799d72007-09-15 14:07:45 -0700510 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000511 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
512 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700513
Ben Hutchings6b73e102009-04-29 08:08:58 +0000514 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700515
Emil Tantilov9dda1732011-03-05 01:28:07 +0000516 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
517 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700518
Auke Kok9a799d72007-09-15 14:07:45 -0700519 return status;
520}
521
522/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700523 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700524 * @hw: pointer to hardware structure
525 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700526 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700527s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000528 ixgbe_link_speed speed,
529 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700531
Auke Kok9a799d72007-09-15 14:07:45 -0700532 /*
533 * Clear autoneg_advertised and set new values based on input link
534 * speed.
535 */
536 hw->phy.autoneg_advertised = 0;
537
538 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
539 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700540
Auke Kok9a799d72007-09-15 14:07:45 -0700541 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
542 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
543
Emil Tantilov9dda1732011-03-05 01:28:07 +0000544 if (speed & IXGBE_LINK_SPEED_100_FULL)
545 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
546
Auke Kok9a799d72007-09-15 14:07:45 -0700547 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700548 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700549
550 return 0;
551}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700552
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700553/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800554 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
555 * @hw: pointer to hardware structure
556 * @speed: pointer to link speed
557 * @autoneg: boolean auto-negotiation value
558 *
559 * Determines the link capabilities by reading the AUTOC register.
560 */
561s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000562 ixgbe_link_speed *speed,
563 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800564{
Mark Rustade90dd262014-07-22 06:51:08 +0000565 s32 status;
Don Skidmorea391f1d2010-11-16 19:27:15 -0800566 u16 speed_ability;
567
568 *speed = 0;
569 *autoneg = true;
570
571 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000572 &speed_ability);
Don Skidmorea391f1d2010-11-16 19:27:15 -0800573
574 if (status == 0) {
575 if (speed_ability & MDIO_SPEED_10G)
576 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
577 if (speed_ability & MDIO_PMA_SPEED_1000)
578 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
579 if (speed_ability & MDIO_PMA_SPEED_100)
580 *speed |= IXGBE_LINK_SPEED_100_FULL;
581 }
582
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000583 /* Internal PHY does not support 100 Mbps */
584 if (hw->mac.type == ixgbe_mac_X550EM_x)
585 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
586
Don Skidmorea391f1d2010-11-16 19:27:15 -0800587 return status;
588}
589
590/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000591 * ixgbe_check_phy_link_tnx - Determine link and speed status
592 * @hw: pointer to hardware structure
593 *
594 * Reads the VS1 register to determine if link is up and the current speed for
595 * the PHY.
596 **/
597s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
598 bool *link_up)
599{
Mark Rustade90dd262014-07-22 06:51:08 +0000600 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000601 u32 time_out;
602 u32 max_time_out = 10;
603 u16 phy_link = 0;
604 u16 phy_speed = 0;
605 u16 phy_data = 0;
606
607 /* Initialize speed and link to default case */
608 *link_up = false;
609 *speed = IXGBE_LINK_SPEED_10GB_FULL;
610
611 /*
612 * Check current speed and link status of the PHY register.
613 * This is a vendor specific register and may have to
614 * be changed for other copper PHYs.
615 */
616 for (time_out = 0; time_out < max_time_out; time_out++) {
617 udelay(10);
618 status = hw->phy.ops.read_reg(hw,
619 MDIO_STAT1,
620 MDIO_MMD_VEND1,
621 &phy_data);
622 phy_link = phy_data &
623 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
624 phy_speed = phy_data &
625 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
626 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
627 *link_up = true;
628 if (phy_speed ==
629 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
630 *speed = IXGBE_LINK_SPEED_1GB_FULL;
631 break;
632 }
633 }
634
635 return status;
636}
637
638/**
639 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
640 * @hw: pointer to hardware structure
641 *
642 * Restart autonegotiation and PHY and waits for completion.
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000643 * This function always returns success, this is nessary since
644 * it is called via a function pointer that could call other
645 * functions that could return an error.
Emil Tantilov9dda1732011-03-05 01:28:07 +0000646 **/
647s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
648{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000649 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
650 bool autoneg = false;
651 ixgbe_link_speed speed;
652
653 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
654
655 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
656 /* Set or unset auto-negotiation 10G advertisement */
657 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
658 MDIO_MMD_AN,
659 &autoneg_reg);
660
661 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
662 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
663 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
664
665 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
666 MDIO_MMD_AN,
667 autoneg_reg);
668 }
669
670 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
671 /* Set or unset auto-negotiation 1G advertisement */
672 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
673 MDIO_MMD_AN,
674 &autoneg_reg);
675
676 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
677 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
678 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
679
680 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
681 MDIO_MMD_AN,
682 autoneg_reg);
683 }
684
685 if (speed & IXGBE_LINK_SPEED_100_FULL) {
686 /* Set or unset auto-negotiation 100M advertisement */
687 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
688 MDIO_MMD_AN,
689 &autoneg_reg);
690
Emil Tantilov50c022e2011-03-31 09:36:12 +0000691 autoneg_reg &= ~(ADVERTISE_100FULL |
692 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000693 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
694 autoneg_reg |= ADVERTISE_100FULL;
695
696 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
697 MDIO_MMD_AN,
698 autoneg_reg);
699 }
700
Don Skidmorec97506a2014-02-27 20:32:43 -0800701 /* Blocked by MNG FW so don't reset PHY */
702 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000703 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800704
Emil Tantilov9dda1732011-03-05 01:28:07 +0000705 /* Restart PHY autonegotiation and wait for completion */
706 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
707 MDIO_MMD_AN, &autoneg_reg);
708
709 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
710
711 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
712 MDIO_MMD_AN, autoneg_reg);
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000713 return 0;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000714}
715
716/**
717 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
718 * @hw: pointer to hardware structure
719 * @firmware_version: pointer to the PHY Firmware Version
720 **/
721s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
722 u16 *firmware_version)
723{
Mark Rustade90dd262014-07-22 06:51:08 +0000724 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000725
726 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
727 MDIO_MMD_VEND1,
728 firmware_version);
729
730 return status;
731}
732
733/**
734 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
735 * @hw: pointer to hardware structure
736 * @firmware_version: pointer to the PHY Firmware Version
737 **/
738s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
739 u16 *firmware_version)
740{
Mark Rustade90dd262014-07-22 06:51:08 +0000741 s32 status;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000742
743 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
744 MDIO_MMD_VEND1,
745 firmware_version);
746
747 return status;
748}
749
750/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800751 * ixgbe_reset_phy_nl - Performs a PHY reset
752 * @hw: pointer to hardware structure
753 **/
754s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
755{
756 u16 phy_offset, control, eword, edata, block_crc;
757 bool end_data = false;
758 u16 list_offset, data_offset;
759 u16 phy_data = 0;
Mark Rustade90dd262014-07-22 06:51:08 +0000760 s32 ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800761 u32 i;
762
Don Skidmorec97506a2014-02-27 20:32:43 -0800763 /* Blocked by MNG FW so bail */
764 if (ixgbe_check_reset_blocked(hw))
Mark Rustade90dd262014-07-22 06:51:08 +0000765 return 0;
Don Skidmorec97506a2014-02-27 20:32:43 -0800766
Ben Hutchings6b73e102009-04-29 08:08:58 +0000767 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800768
769 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000770 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000771 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800772
773 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000774 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000775 &phy_data);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000776 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800777 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000778 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800779 }
780
Ben Hutchings6b73e102009-04-29 08:08:58 +0000781 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800782 hw_dbg(hw, "PHY reset did not complete.\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000783 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800784 }
785
786 /* Get init offsets */
787 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000788 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000789 if (ret_val)
790 return ret_val;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800791
792 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
793 data_offset++;
794 while (!end_data) {
795 /*
796 * Read control word from PHY init contents offset
797 */
798 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000799 if (ret_val)
800 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800801 control = (eword & IXGBE_CONTROL_MASK_NL) >>
Jacob Kellere7cf7452014-04-09 06:03:10 +0000802 IXGBE_CONTROL_SHIFT_NL;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800803 edata = eword & IXGBE_DATA_MASK_NL;
804 switch (control) {
805 case IXGBE_DELAY_NL:
806 data_offset++;
807 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000808 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800809 break;
810 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000811 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800812 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000813 ret_val = hw->eeprom.ops.read(hw, data_offset++,
814 &phy_offset);
815 if (ret_val)
816 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800817 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000818 ret_val = hw->eeprom.ops.read(hw, data_offset,
819 &eword);
820 if (ret_val)
821 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800822 hw->phy.ops.write_reg(hw, phy_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000823 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800824 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
825 phy_offset);
826 data_offset++;
827 phy_offset++;
828 }
829 break;
830 case IXGBE_CONTROL_NL:
831 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +0000832 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800833 if (edata == IXGBE_CONTROL_EOL_NL) {
834 hw_dbg(hw, "EOL\n");
835 end_data = true;
836 } else if (edata == IXGBE_CONTROL_SOL_NL) {
837 hw_dbg(hw, "SOL\n");
838 } else {
839 hw_dbg(hw, "Bad control value\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000840 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800841 }
842 break;
843 default:
844 hw_dbg(hw, "Bad control type\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000845 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800846 }
847 }
848
Donald Skidmorec4900be2008-11-20 21:11:42 -0800849 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000850
851err_eeprom:
852 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
853 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800854}
855
856/**
Don Skidmore8f583322013-07-27 06:25:38 +0000857 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -0800858 * @hw: pointer to hardware structure
859 *
Don Skidmore8f583322013-07-27 06:25:38 +0000860 * Determines HW type and calls appropriate function.
861 **/
862s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
863{
Don Skidmore8f583322013-07-27 06:25:38 +0000864 switch (hw->mac.ops.get_media_type(hw)) {
865 case ixgbe_media_type_fiber:
Mark Rustade90dd262014-07-22 06:51:08 +0000866 return ixgbe_identify_sfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +0000867 case ixgbe_media_type_fiber_qsfp:
Mark Rustade90dd262014-07-22 06:51:08 +0000868 return ixgbe_identify_qsfp_module_generic(hw);
Don Skidmore8f583322013-07-27 06:25:38 +0000869 default:
870 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +0000871 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +0000872 }
873
Mark Rustade90dd262014-07-22 06:51:08 +0000874 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +0000875}
876
877/**
878 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
879 * @hw: pointer to hardware structure
Mark Rustade90dd262014-07-22 06:51:08 +0000880 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000881 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -0800882 **/
883s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
884{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000885 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +0000886 s32 status;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800887 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000888 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800889 u8 identifier = 0;
890 u8 comp_codes_1g = 0;
891 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000892 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000893 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000894 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000895 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800896
Don Skidmore8ca783a2009-05-26 20:40:47 -0700897 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
898 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +0000899 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8ca783a2009-05-26 20:40:47 -0700900 }
901
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000902 status = hw->phy.ops.read_i2c_eeprom(hw,
903 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +0000904 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800905
Mark Rustade90dd262014-07-22 06:51:08 +0000906 if (status)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000907 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800908
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000909 /* LAN ID is needed for sfp_type determination */
910 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800911
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000912 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
913 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +0000914 return IXGBE_ERR_SFP_NOT_SUPPORTED;
915 }
916 status = hw->phy.ops.read_i2c_eeprom(hw,
917 IXGBE_SFF_1GBE_COMP_CODES,
918 &comp_codes_1g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000919
Mark Rustade90dd262014-07-22 06:51:08 +0000920 if (status)
921 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000922
Mark Rustade90dd262014-07-22 06:51:08 +0000923 status = hw->phy.ops.read_i2c_eeprom(hw,
924 IXGBE_SFF_10GBE_COMP_CODES,
925 &comp_codes_10g);
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000926
Mark Rustade90dd262014-07-22 06:51:08 +0000927 if (status)
928 goto err_read_i2c_eeprom;
929 status = hw->phy.ops.read_i2c_eeprom(hw,
930 IXGBE_SFF_CABLE_TECHNOLOGY,
931 &cable_tech);
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000932
Mark Rustade90dd262014-07-22 06:51:08 +0000933 if (status)
934 goto err_read_i2c_eeprom;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000935
Mark Rustade90dd262014-07-22 06:51:08 +0000936 /* ID Module
937 * =========
938 * 0 SFP_DA_CU
939 * 1 SFP_SR
940 * 2 SFP_LR
941 * 3 SFP_DA_CORE0 - 82599-specific
942 * 4 SFP_DA_CORE1 - 82599-specific
943 * 5 SFP_SR/LR_CORE0 - 82599-specific
944 * 6 SFP_SR/LR_CORE1 - 82599-specific
945 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
946 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
947 * 9 SFP_1g_cu_CORE0 - 82599-specific
948 * 10 SFP_1g_cu_CORE1 - 82599-specific
949 * 11 SFP_1g_sx_CORE0 - 82599-specific
950 * 12 SFP_1g_sx_CORE1 - 82599-specific
951 */
952 if (hw->mac.type == ixgbe_mac_82598EB) {
953 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
954 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
955 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
956 hw->phy.sfp_type = ixgbe_sfp_type_sr;
957 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
958 hw->phy.sfp_type = ixgbe_sfp_type_lr;
959 else
960 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
961 } else if (hw->mac.type == ixgbe_mac_82599EB) {
962 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
963 if (hw->bus.lan_id == 0)
964 hw->phy.sfp_type =
965 ixgbe_sfp_type_da_cu_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000966 else
Mark Rustade90dd262014-07-22 06:51:08 +0000967 hw->phy.sfp_type =
968 ixgbe_sfp_type_da_cu_core1;
969 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
970 hw->phy.ops.read_i2c_eeprom(
971 hw, IXGBE_SFF_CABLE_SPEC_COMP,
972 &cable_spec);
973 if (cable_spec &
974 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000975 if (hw->bus.lan_id == 0)
976 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +0000977 ixgbe_sfp_type_da_act_lmt_core0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000978 else
979 hw->phy.sfp_type =
Mark Rustade90dd262014-07-22 06:51:08 +0000980 ixgbe_sfp_type_da_act_lmt_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000981 } else {
Mark Rustade90dd262014-07-22 06:51:08 +0000982 hw->phy.sfp_type =
983 ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000984 }
Mark Rustade90dd262014-07-22 06:51:08 +0000985 } else if (comp_codes_10g &
986 (IXGBE_SFF_10GBASESR_CAPABLE |
987 IXGBE_SFF_10GBASELR_CAPABLE)) {
988 if (hw->bus.lan_id == 0)
989 hw->phy.sfp_type =
990 ixgbe_sfp_type_srlr_core0;
991 else
992 hw->phy.sfp_type =
993 ixgbe_sfp_type_srlr_core1;
994 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
995 if (hw->bus.lan_id == 0)
996 hw->phy.sfp_type =
997 ixgbe_sfp_type_1g_cu_core0;
998 else
999 hw->phy.sfp_type =
1000 ixgbe_sfp_type_1g_cu_core1;
1001 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1002 if (hw->bus.lan_id == 0)
1003 hw->phy.sfp_type =
1004 ixgbe_sfp_type_1g_sx_core0;
1005 else
1006 hw->phy.sfp_type =
1007 ixgbe_sfp_type_1g_sx_core1;
1008 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1009 if (hw->bus.lan_id == 0)
1010 hw->phy.sfp_type =
1011 ixgbe_sfp_type_1g_lx_core0;
1012 else
1013 hw->phy.sfp_type =
1014 ixgbe_sfp_type_1g_lx_core1;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001015 } else {
Mark Rustade90dd262014-07-22 06:51:08 +00001016 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001017 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001018 }
1019
Mark Rustade90dd262014-07-22 06:51:08 +00001020 if (hw->phy.sfp_type != stored_sfp_type)
1021 hw->phy.sfp_setup_needed = true;
1022
1023 /* Determine if the SFP+ PHY is dual speed or not. */
1024 hw->phy.multispeed_fiber = false;
1025 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1026 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1027 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1028 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1029 hw->phy.multispeed_fiber = true;
1030
1031 /* Determine PHY vendor */
1032 if (hw->phy.type != ixgbe_phy_nl) {
1033 hw->phy.id = identifier;
1034 status = hw->phy.ops.read_i2c_eeprom(hw,
1035 IXGBE_SFF_VENDOR_OUI_BYTE0,
1036 &oui_bytes[0]);
1037
1038 if (status != 0)
1039 goto err_read_i2c_eeprom;
1040
1041 status = hw->phy.ops.read_i2c_eeprom(hw,
1042 IXGBE_SFF_VENDOR_OUI_BYTE1,
1043 &oui_bytes[1]);
1044
1045 if (status != 0)
1046 goto err_read_i2c_eeprom;
1047
1048 status = hw->phy.ops.read_i2c_eeprom(hw,
1049 IXGBE_SFF_VENDOR_OUI_BYTE2,
1050 &oui_bytes[2]);
1051
1052 if (status != 0)
1053 goto err_read_i2c_eeprom;
1054
1055 vendor_oui =
1056 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1057 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1058 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1059
1060 switch (vendor_oui) {
1061 case IXGBE_SFF_VENDOR_OUI_TYCO:
1062 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1063 hw->phy.type =
1064 ixgbe_phy_sfp_passive_tyco;
1065 break;
1066 case IXGBE_SFF_VENDOR_OUI_FTL:
1067 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1068 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1069 else
1070 hw->phy.type = ixgbe_phy_sfp_ftl;
1071 break;
1072 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1073 hw->phy.type = ixgbe_phy_sfp_avago;
1074 break;
1075 case IXGBE_SFF_VENDOR_OUI_INTEL:
1076 hw->phy.type = ixgbe_phy_sfp_intel;
1077 break;
1078 default:
1079 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1080 hw->phy.type =
1081 ixgbe_phy_sfp_passive_unknown;
1082 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1083 hw->phy.type =
1084 ixgbe_phy_sfp_active_unknown;
1085 else
1086 hw->phy.type = ixgbe_phy_sfp_unknown;
1087 break;
1088 }
1089 }
1090
1091 /* Allow any DA cable vendor */
1092 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1093 IXGBE_SFF_DA_ACTIVE_CABLE))
1094 return 0;
1095
1096 /* Verify supported 1G SFP modules */
1097 if (comp_codes_10g == 0 &&
1098 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1099 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1100 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1101 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1102 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1103 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1104 hw->phy.type = ixgbe_phy_sfp_unsupported;
1105 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1106 }
1107
1108 /* Anything else 82598-based is supported */
1109 if (hw->mac.type == ixgbe_mac_82598EB)
1110 return 0;
1111
1112 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1113 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1114 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1115 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1116 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1117 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1118 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1119 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1120 /* Make sure we're a supported PHY type */
1121 if (hw->phy.type == ixgbe_phy_sfp_intel)
1122 return 0;
1123 if (hw->allow_unsupported_sfp) {
1124 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");
1125 return 0;
1126 }
1127 hw_dbg(hw, "SFP+ module not supported\n");
1128 hw->phy.type = ixgbe_phy_sfp_unsupported;
1129 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1130 }
1131 return 0;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001132
1133err_read_i2c_eeprom:
1134 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1135 if (hw->phy.type != ixgbe_phy_nl) {
1136 hw->phy.id = 0;
1137 hw->phy.type = ixgbe_phy_unknown;
1138 }
1139 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001140}
1141
1142/**
Don Skidmore8f583322013-07-27 06:25:38 +00001143 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1144 * @hw: pointer to hardware structure
1145 *
1146 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1147 **/
Mark Rustad88217542013-11-23 03:19:19 +00001148static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001149{
1150 struct ixgbe_adapter *adapter = hw->back;
Mark Rustade90dd262014-07-22 06:51:08 +00001151 s32 status;
Don Skidmore8f583322013-07-27 06:25:38 +00001152 u32 vendor_oui = 0;
1153 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1154 u8 identifier = 0;
1155 u8 comp_codes_1g = 0;
1156 u8 comp_codes_10g = 0;
1157 u8 oui_bytes[3] = {0, 0, 0};
1158 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001159 u8 connector = 0;
1160 u8 cable_length = 0;
1161 u8 device_tech = 0;
1162 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001163
1164 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1165 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
Mark Rustade90dd262014-07-22 06:51:08 +00001166 return IXGBE_ERR_SFP_NOT_PRESENT;
Don Skidmore8f583322013-07-27 06:25:38 +00001167 }
1168
1169 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1170 &identifier);
1171
1172 if (status != 0)
1173 goto err_read_i2c_eeprom;
1174
1175 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1176 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001177 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001178 }
1179
1180 hw->phy.id = identifier;
1181
1182 /* LAN ID is needed for sfp_type determination */
1183 hw->mac.ops.set_lan_id(hw);
1184
1185 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1186 &comp_codes_10g);
1187
1188 if (status != 0)
1189 goto err_read_i2c_eeprom;
1190
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001191 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1192 &comp_codes_1g);
1193
1194 if (status != 0)
1195 goto err_read_i2c_eeprom;
1196
Don Skidmore8f583322013-07-27 06:25:38 +00001197 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1198 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1199 if (hw->bus.lan_id == 0)
1200 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1201 else
1202 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001203 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1204 IXGBE_SFF_10GBASELR_CAPABLE)) {
1205 if (hw->bus.lan_id == 0)
1206 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1207 else
1208 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1209 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001210 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1211 active_cable = true;
1212
1213 if (!active_cable) {
1214 /* check for active DA cables that pre-date
1215 * SFF-8436 v3.6
1216 */
1217 hw->phy.ops.read_i2c_eeprom(hw,
1218 IXGBE_SFF_QSFP_CONNECTOR,
1219 &connector);
1220
1221 hw->phy.ops.read_i2c_eeprom(hw,
1222 IXGBE_SFF_QSFP_CABLE_LENGTH,
1223 &cable_length);
1224
1225 hw->phy.ops.read_i2c_eeprom(hw,
1226 IXGBE_SFF_QSFP_DEVICE_TECH,
1227 &device_tech);
1228
1229 if ((connector ==
1230 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1231 (cable_length > 0) &&
1232 ((device_tech >> 4) ==
1233 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1234 active_cable = true;
1235 }
1236
1237 if (active_cable) {
1238 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1239 if (hw->bus.lan_id == 0)
1240 hw->phy.sfp_type =
1241 ixgbe_sfp_type_da_act_lmt_core0;
1242 else
1243 hw->phy.sfp_type =
1244 ixgbe_sfp_type_da_act_lmt_core1;
1245 } else {
1246 /* unsupported module type */
1247 hw->phy.type = ixgbe_phy_sfp_unsupported;
Mark Rustade90dd262014-07-22 06:51:08 +00001248 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001249 }
Don Skidmore8f583322013-07-27 06:25:38 +00001250 }
1251
1252 if (hw->phy.sfp_type != stored_sfp_type)
1253 hw->phy.sfp_setup_needed = true;
1254
1255 /* Determine if the QSFP+ PHY is dual speed or not. */
1256 hw->phy.multispeed_fiber = false;
1257 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1258 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1259 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1260 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1261 hw->phy.multispeed_fiber = true;
1262
1263 /* Determine PHY vendor for optical modules */
1264 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1265 IXGBE_SFF_10GBASELR_CAPABLE)) {
1266 status = hw->phy.ops.read_i2c_eeprom(hw,
1267 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1268 &oui_bytes[0]);
1269
1270 if (status != 0)
1271 goto err_read_i2c_eeprom;
1272
1273 status = hw->phy.ops.read_i2c_eeprom(hw,
1274 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1275 &oui_bytes[1]);
1276
1277 if (status != 0)
1278 goto err_read_i2c_eeprom;
1279
1280 status = hw->phy.ops.read_i2c_eeprom(hw,
1281 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1282 &oui_bytes[2]);
1283
1284 if (status != 0)
1285 goto err_read_i2c_eeprom;
1286
1287 vendor_oui =
1288 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1289 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1290 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1291
1292 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1293 hw->phy.type = ixgbe_phy_qsfp_intel;
1294 else
1295 hw->phy.type = ixgbe_phy_qsfp_unknown;
1296
1297 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1298 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1299 /* Make sure we're a supported PHY type */
Mark Rustade90dd262014-07-22 06:51:08 +00001300 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1301 return 0;
1302 if (hw->allow_unsupported_sfp) {
1303 e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
1304 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001305 }
Mark Rustade90dd262014-07-22 06:51:08 +00001306 hw_dbg(hw, "QSFP module not supported\n");
1307 hw->phy.type = ixgbe_phy_sfp_unsupported;
1308 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Don Skidmore8f583322013-07-27 06:25:38 +00001309 }
Mark Rustade90dd262014-07-22 06:51:08 +00001310 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001311 }
Mark Rustade90dd262014-07-22 06:51:08 +00001312 return 0;
Don Skidmore8f583322013-07-27 06:25:38 +00001313
1314err_read_i2c_eeprom:
1315 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1316 hw->phy.id = 0;
1317 hw->phy.type = ixgbe_phy_unknown;
1318
1319 return IXGBE_ERR_SFP_NOT_PRESENT;
1320}
1321
1322/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001323 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001324 * @hw: pointer to hardware structure
1325 * @list_offset: offset to the SFP ID list
1326 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001327 *
1328 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1329 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001330 **/
1331s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001332 u16 *list_offset,
1333 u16 *data_offset)
Donald Skidmorec4900be2008-11-20 21:11:42 -08001334{
1335 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001336 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001337
1338 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1339 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1340
1341 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1342 return IXGBE_ERR_SFP_NOT_PRESENT;
1343
1344 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1345 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1346 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1347
Don Skidmorecb836a92010-06-29 18:30:59 +00001348 /*
1349 * Limiting active cables and 1G Phys must be initialized as
1350 * SR modules
1351 */
1352 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001353 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001354 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1355 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001356 sfp_type = ixgbe_sfp_type_srlr_core0;
1357 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001358 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001359 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1360 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001361 sfp_type = ixgbe_sfp_type_srlr_core1;
1362
Donald Skidmorec4900be2008-11-20 21:11:42 -08001363 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001364 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1365 hw_err(hw, "eeprom read at %d failed\n",
1366 IXGBE_PHY_INIT_OFFSET_NL);
1367 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1368 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001369
1370 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001371 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001372
1373 /* Shift offset to first ID word */
1374 (*list_offset)++;
1375
1376 /*
1377 * Find the matching SFP ID in the EEPROM
1378 * and program the init sequence
1379 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001380 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1381 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001382
1383 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001384 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001385 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001386 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1387 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001388 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1389 hw_dbg(hw, "SFP+ module not supported\n");
1390 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1391 } else {
1392 break;
1393 }
1394 } else {
1395 (*list_offset) += 2;
1396 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001397 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001398 }
1399 }
1400
1401 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1402 hw_dbg(hw, "No matching SFP+ module found\n");
1403 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1404 }
1405
1406 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001407
1408err_phy:
1409 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1410 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001411}
1412
1413/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001414 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1415 * @hw: pointer to hardware structure
1416 * @byte_offset: EEPROM byte offset to read
1417 * @eeprom_data: value read
1418 *
1419 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1420 **/
1421s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001422 u8 *eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001423{
1424 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001425 IXGBE_I2C_EEPROM_DEV_ADDR,
1426 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001427}
1428
1429/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001430 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1431 * @hw: pointer to hardware structure
1432 * @byte_offset: byte offset at address 0xA2
1433 * @eeprom_data: value read
1434 *
1435 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1436 **/
1437s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1438 u8 *sff8472_data)
1439{
1440 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1441 IXGBE_I2C_EEPROM_DEV_ADDR2,
1442 sff8472_data);
1443}
1444
1445/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001446 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1447 * @hw: pointer to hardware structure
1448 * @byte_offset: EEPROM byte offset to write
1449 * @eeprom_data: value to write
1450 *
1451 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1452 **/
1453s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001454 u8 eeprom_data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001455{
1456 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001457 IXGBE_I2C_EEPROM_DEV_ADDR,
1458 eeprom_data);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001459}
1460
1461/**
1462 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1463 * @hw: pointer to hardware structure
1464 * @byte_offset: byte offset to read
1465 * @data: value read
1466 *
1467 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001468 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001469 **/
1470s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001471 u8 dev_addr, u8 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001472{
Mark Rustade90dd262014-07-22 06:51:08 +00001473 s32 status;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001474 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001475 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001476 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001477 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001478 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001479
1480 do {
Mark Rustade90dd262014-07-22 06:51:08 +00001481 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1482 return IXGBE_ERR_SWFW_SYNC;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001483
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001484 ixgbe_i2c_start(hw);
1485
1486 /* Device Address and write indication */
1487 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1488 if (status != 0)
1489 goto fail;
1490
1491 status = ixgbe_get_i2c_ack(hw);
1492 if (status != 0)
1493 goto fail;
1494
1495 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1496 if (status != 0)
1497 goto fail;
1498
1499 status = ixgbe_get_i2c_ack(hw);
1500 if (status != 0)
1501 goto fail;
1502
1503 ixgbe_i2c_start(hw);
1504
1505 /* Device Address and read indication */
1506 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1507 if (status != 0)
1508 goto fail;
1509
1510 status = ixgbe_get_i2c_ack(hw);
1511 if (status != 0)
1512 goto fail;
1513
1514 status = ixgbe_clock_in_i2c_byte(hw, data);
1515 if (status != 0)
1516 goto fail;
1517
1518 status = ixgbe_clock_out_i2c_bit(hw, nack);
1519 if (status != 0)
1520 goto fail;
1521
1522 ixgbe_i2c_stop(hw);
1523 break;
1524
1525fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001526 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001527 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001528 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001529 retry++;
1530 if (retry < max_retry)
1531 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1532 else
1533 hw_dbg(hw, "I2C byte read error.\n");
1534
1535 } while (retry < max_retry);
1536
Emil Tantilov6d980c32011-04-13 04:56:15 +00001537 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001538
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001539 return status;
1540}
1541
1542/**
1543 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1544 * @hw: pointer to hardware structure
1545 * @byte_offset: byte offset to write
1546 * @data: value to write
1547 *
1548 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1549 * a specified device address.
1550 **/
1551s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001552 u8 dev_addr, u8 data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001553{
Mark Rustade90dd262014-07-22 06:51:08 +00001554 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001555 u32 max_retry = 1;
1556 u32 retry = 0;
Don Skidmore030eaec2014-11-29 05:22:37 +00001557 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001558
Mark Rustade90dd262014-07-22 06:51:08 +00001559 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1560 return IXGBE_ERR_SWFW_SYNC;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001561
1562 do {
1563 ixgbe_i2c_start(hw);
1564
1565 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1566 if (status != 0)
1567 goto fail;
1568
1569 status = ixgbe_get_i2c_ack(hw);
1570 if (status != 0)
1571 goto fail;
1572
1573 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1574 if (status != 0)
1575 goto fail;
1576
1577 status = ixgbe_get_i2c_ack(hw);
1578 if (status != 0)
1579 goto fail;
1580
1581 status = ixgbe_clock_out_i2c_byte(hw, data);
1582 if (status != 0)
1583 goto fail;
1584
1585 status = ixgbe_get_i2c_ack(hw);
1586 if (status != 0)
1587 goto fail;
1588
1589 ixgbe_i2c_stop(hw);
1590 break;
1591
1592fail:
1593 ixgbe_i2c_bus_clear(hw);
1594 retry++;
1595 if (retry < max_retry)
1596 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1597 else
1598 hw_dbg(hw, "I2C byte write error.\n");
1599 } while (retry < max_retry);
1600
Emil Tantilov6d980c32011-04-13 04:56:15 +00001601 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001602
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001603 return status;
1604}
1605
1606/**
1607 * ixgbe_i2c_start - Sets I2C start condition
1608 * @hw: pointer to hardware structure
1609 *
1610 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1611 **/
1612static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1613{
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001614 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001615
1616 /* Start condition must begin with data and clock high */
1617 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1618 ixgbe_raise_i2c_clk(hw, &i2cctl);
1619
1620 /* Setup time for start condition (4.7us) */
1621 udelay(IXGBE_I2C_T_SU_STA);
1622
1623 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1624
1625 /* Hold time for start condition (4us) */
1626 udelay(IXGBE_I2C_T_HD_STA);
1627
1628 ixgbe_lower_i2c_clk(hw, &i2cctl);
1629
1630 /* Minimum low period of clock is 4.7 us */
1631 udelay(IXGBE_I2C_T_LOW);
1632
1633}
1634
1635/**
1636 * ixgbe_i2c_stop - Sets I2C stop condition
1637 * @hw: pointer to hardware structure
1638 *
1639 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1640 **/
1641static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1642{
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001643 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001644
1645 /* Stop condition must begin with data low and clock high */
1646 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1647 ixgbe_raise_i2c_clk(hw, &i2cctl);
1648
1649 /* Setup time for stop condition (4us) */
1650 udelay(IXGBE_I2C_T_SU_STO);
1651
1652 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1653
1654 /* bus free time between stop and start (4.7us)*/
1655 udelay(IXGBE_I2C_T_BUF);
1656}
1657
1658/**
1659 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1660 * @hw: pointer to hardware structure
1661 * @data: data byte to clock in
1662 *
1663 * Clocks in one byte data via I2C data/clock
1664 **/
1665static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1666{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001667 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001668 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001669
1670 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001671 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001672 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001673 }
1674
Emil Tantilove1befd72011-08-27 07:18:47 +00001675 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001676}
1677
1678/**
1679 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1680 * @hw: pointer to hardware structure
1681 * @data: data byte clocked out
1682 *
1683 * Clocks out one byte data via I2C data/clock
1684 **/
1685static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1686{
Mark Rustade90dd262014-07-22 06:51:08 +00001687 s32 status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001688 s32 i;
1689 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001690 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001691
1692 for (i = 7; i >= 0; i--) {
1693 bit = (data >> i) & 0x1;
1694 status = ixgbe_clock_out_i2c_bit(hw, bit);
1695
1696 if (status != 0)
1697 break;
1698 }
1699
1700 /* Release SDA line (set high) */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001701 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1702 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
1703 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001704 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001705
1706 return status;
1707}
1708
1709/**
1710 * ixgbe_get_i2c_ack - Polls for I2C ACK
1711 * @hw: pointer to hardware structure
1712 *
1713 * Clocks in/out one bit via I2C data/clock
1714 **/
1715static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1716{
Emil Tantilove1befd72011-08-27 07:18:47 +00001717 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001718 u32 i = 0;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001719 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001720 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001721 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001722
Emil Tantilove1befd72011-08-27 07:18:47 +00001723 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001724
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001725
1726 /* Minimum high period of clock is 4us */
1727 udelay(IXGBE_I2C_T_HIGH);
1728
1729 /* Poll for ACK. Note that ACK in I2C spec is
1730 * transition from 1 to 0 */
1731 for (i = 0; i < timeout; i++) {
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001732 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1733 ack = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001734
1735 udelay(1);
1736 if (ack == 0)
1737 break;
1738 }
1739
1740 if (ack == 1) {
1741 hw_dbg(hw, "I2C ack was not received.\n");
1742 status = IXGBE_ERR_I2C;
1743 }
1744
1745 ixgbe_lower_i2c_clk(hw, &i2cctl);
1746
1747 /* Minimum low period of clock is 4.7 us */
1748 udelay(IXGBE_I2C_T_LOW);
1749
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001750 return status;
1751}
1752
1753/**
1754 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1755 * @hw: pointer to hardware structure
1756 * @data: read data value
1757 *
1758 * Clocks in one bit via I2C data/clock
1759 **/
1760static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1761{
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001762 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001763
Emil Tantilove1befd72011-08-27 07:18:47 +00001764 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001765
1766 /* Minimum high period of clock is 4us */
1767 udelay(IXGBE_I2C_T_HIGH);
1768
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001769 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1770 *data = ixgbe_get_i2c_data(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001771
1772 ixgbe_lower_i2c_clk(hw, &i2cctl);
1773
1774 /* Minimum low period of clock is 4.7 us */
1775 udelay(IXGBE_I2C_T_LOW);
1776
Emil Tantilove1befd72011-08-27 07:18:47 +00001777 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001778}
1779
1780/**
1781 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1782 * @hw: pointer to hardware structure
1783 * @data: data value to write
1784 *
1785 * Clocks out one bit via I2C data/clock
1786 **/
1787static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1788{
1789 s32 status;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001790 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001791
1792 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1793 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001794 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001795
1796 /* Minimum high period of clock is 4us */
1797 udelay(IXGBE_I2C_T_HIGH);
1798
1799 ixgbe_lower_i2c_clk(hw, &i2cctl);
1800
1801 /* Minimum low period of clock is 4.7 us.
1802 * This also takes care of the data hold time.
1803 */
1804 udelay(IXGBE_I2C_T_LOW);
1805 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001806 hw_dbg(hw, "I2C data was not set to %X\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001807 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001808 }
1809
Mark Rustade90dd262014-07-22 06:51:08 +00001810 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001811}
1812/**
1813 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1814 * @hw: pointer to hardware structure
1815 * @i2cctl: Current value of I2CCTL register
1816 *
1817 * Raises the I2C clock line '0'->'1'
1818 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00001819static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001820{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001821 u32 i = 0;
1822 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1823 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001824
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001825 for (i = 0; i < timeout; i++) {
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001826 *i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
1827 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001828 IXGBE_WRITE_FLUSH(hw);
1829 /* SCL rise time (1000ns) */
1830 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001831
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001832 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1833 if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001834 break;
1835 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001836}
1837
1838/**
1839 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1840 * @hw: pointer to hardware structure
1841 * @i2cctl: Current value of I2CCTL register
1842 *
1843 * Lowers the I2C clock line '1'->'0'
1844 **/
1845static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1846{
1847
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001848 *i2cctl &= ~IXGBE_I2C_CLK_OUT_BY_MAC(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001849
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001850 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001851 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001852
1853 /* SCL fall time (300ns) */
1854 udelay(IXGBE_I2C_T_FALL);
1855}
1856
1857/**
1858 * ixgbe_set_i2c_data - Sets the I2C data bit
1859 * @hw: pointer to hardware structure
1860 * @i2cctl: Current value of I2CCTL register
1861 * @data: I2C data value (0 or 1) to set
1862 *
1863 * Sets the I2C data bit
1864 **/
1865static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1866{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001867 if (data)
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001868 *i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001869 else
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001870 *i2cctl &= ~IXGBE_I2C_DATA_OUT_BY_MAC(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001871
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001872 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001873 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001874
1875 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1876 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1877
1878 /* Verify data was set correctly */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001879 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1880 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001881 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
Mark Rustade90dd262014-07-22 06:51:08 +00001882 return IXGBE_ERR_I2C;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001883 }
1884
Mark Rustade90dd262014-07-22 06:51:08 +00001885 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001886}
1887
1888/**
1889 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1890 * @hw: pointer to hardware structure
1891 * @i2cctl: Current value of I2CCTL register
1892 *
1893 * Returns the I2C data bit value
1894 **/
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001895static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001896{
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001897 if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
Mark Rustade90dd262014-07-22 06:51:08 +00001898 return true;
1899 return false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001900}
1901
1902/**
1903 * ixgbe_i2c_bus_clear - Clears the I2C bus
1904 * @hw: pointer to hardware structure
1905 *
1906 * Clears the I2C bus by sending nine clock pulses.
1907 * Used when data line is stuck low.
1908 **/
1909static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1910{
Don Skidmore9a75a1a2014-11-07 03:53:35 +00001911 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001912 u32 i;
1913
Emil Tantilov75f19c32011-02-19 08:43:55 +00001914 ixgbe_i2c_start(hw);
1915
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001916 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1917
1918 for (i = 0; i < 9; i++) {
1919 ixgbe_raise_i2c_clk(hw, &i2cctl);
1920
1921 /* Min high period of clock is 4us */
1922 udelay(IXGBE_I2C_T_HIGH);
1923
1924 ixgbe_lower_i2c_clk(hw, &i2cctl);
1925
1926 /* Min low period of clock is 4.7us*/
1927 udelay(IXGBE_I2C_T_LOW);
1928 }
1929
Emil Tantilov75f19c32011-02-19 08:43:55 +00001930 ixgbe_i2c_start(hw);
1931
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001932 /* Put the i2c bus back to default state */
1933 ixgbe_i2c_stop(hw);
1934}
1935
1936/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001937 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001938 * @hw: pointer to hardware structure
1939 *
1940 * Checks if the LASI temp alarm status was triggered due to overtemp
1941 **/
1942s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1943{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001944 u16 phy_data = 0;
1945
1946 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
Mark Rustade90dd262014-07-22 06:51:08 +00001947 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001948
1949 /* Check that the LASI temp alarm status was triggered */
1950 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001951 MDIO_MMD_PMAPMD, &phy_data);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001952
1953 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
Mark Rustade90dd262014-07-22 06:51:08 +00001954 return 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001955
Mark Rustade90dd262014-07-22 06:51:08 +00001956 return IXGBE_ERR_OVERTEMP;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001957}