blob: d2caae4750e0cfcf9c783a5692d16c767c1261d7 [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:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
31
Mark Rustadb12babd2014-01-14 18:53:16 -080032#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070033#include "ixgbe_phy.h"
34
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000035static void ixgbe_i2c_start(struct ixgbe_hw *hw);
36static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
37static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
38static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
39static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
40static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
41static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
Emil Tantilove1befd72011-08-27 07:18:47 +000042static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000043static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
45static bool ixgbe_get_i2c_data(u32 *i2cctl);
46static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070047static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
48static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
Mark Rustad88217542013-11-23 03:19:19 +000049static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070050
51/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070052 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -070053 * @hw: pointer to hardware structure
54 *
55 * Determines the physical layer module found on the current adapter.
56 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070057s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070058{
59 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
60 u32 phy_addr;
Emil Tantilov037c6d02011-02-25 07:49:39 +000061 u16 ext_ability = 0;
Auke Kok9a799d72007-09-15 14:07:45 -070062
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070063 if (hw->phy.type == ixgbe_phy_unknown) {
64 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +000065 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +000066 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070067 ixgbe_get_phy_id(hw);
68 hw->phy.type =
69 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +000070
71 if (hw->phy.type == ixgbe_phy_unknown) {
72 hw->phy.ops.read_reg(hw,
73 MDIO_PMA_EXTABLE,
74 MDIO_MMD_PMAPMD,
75 &ext_ability);
76 if (ext_ability &
77 (MDIO_PMA_EXTABLE_10GBT |
78 MDIO_PMA_EXTABLE_1000BT))
79 hw->phy.type =
80 ixgbe_phy_cu_unknown;
81 else
82 hw->phy.type =
83 ixgbe_phy_generic;
84 }
85
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070086 status = 0;
87 break;
88 }
Auke Kok9a799d72007-09-15 14:07:45 -070089 }
Don Skidmore63d6e1d2009-07-02 12:50:12 +000090 /* clear value if nothing found */
Emil Tantilov037c6d02011-02-25 07:49:39 +000091 if (status != 0)
92 hw->phy.mdio.prtad = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070093 } else {
94 status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -070095 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070096
Auke Kok9a799d72007-09-15 14:07:45 -070097 return status;
98}
99
100/**
Don Skidmorec97506a2014-02-27 20:32:43 -0800101 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
102 * @hw: pointer to the hardware structure
103 *
104 * This function checks the MMNGC.MNG_VETO bit to see if there are
105 * any constraints on link from manageability. For MAC's that don't
106 * have this bit just return false since the link can not be blocked
107 * via this method.
108 **/
109s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
110{
111 u32 mmngc;
112
113 /* If we don't have this bit, it can't be blocking */
114 if (hw->mac.type == ixgbe_mac_82598EB)
115 return false;
116
117 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
118 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
119 hw_dbg(hw, "MNG_VETO bit detected.\n");
120 return true;
121 }
122
123 return false;
124}
125
126/**
Auke Kok9a799d72007-09-15 14:07:45 -0700127 * ixgbe_get_phy_id - Get the phy type
128 * @hw: pointer to hardware structure
129 *
130 **/
131static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
132{
133 u32 status;
134 u16 phy_id_high = 0;
135 u16 phy_id_low = 0;
136
Ben Hutchings6b73e102009-04-29 08:08:58 +0000137 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700138 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700139
140 if (status == 0) {
141 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000142 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700143 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700144 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
145 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
146 }
Auke Kok9a799d72007-09-15 14:07:45 -0700147 return status;
148}
149
150/**
151 * ixgbe_get_phy_type_from_id - Get the phy type
152 * @hw: pointer to hardware structure
153 *
154 **/
155static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
156{
157 enum ixgbe_phy_type phy_type;
158
159 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700160 case TN1010_PHY_ID:
161 phy_type = ixgbe_phy_tn;
162 break;
Don Skidmore2b264902010-12-09 06:55:14 +0000163 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800164 phy_type = ixgbe_phy_aq;
165 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700166 case QT2022_PHY_ID:
167 phy_type = ixgbe_phy_qt;
168 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800169 case ATH_PHY_ID:
170 phy_type = ixgbe_phy_nl;
171 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700172 default:
173 phy_type = ixgbe_phy_unknown;
174 break;
175 }
176
177 return phy_type;
178}
179
180/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700181 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700182 * @hw: pointer to hardware structure
183 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700184s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700185{
Emil Tantilov17835752011-02-16 01:38:13 +0000186 u32 i;
187 u16 ctrl = 0;
188 s32 status = 0;
189
190 if (hw->phy.type == ixgbe_phy_unknown)
191 status = ixgbe_identify_phy_generic(hw);
192
193 if (status != 0 || hw->phy.type == ixgbe_phy_none)
194 goto out;
195
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700196 /* Don't reset PHY if it's shut down due to overtemp. */
197 if (!hw->phy.reset_if_overtemp &&
198 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Emil Tantilov17835752011-02-16 01:38:13 +0000199 goto out;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700200
Don Skidmorec97506a2014-02-27 20:32:43 -0800201 /* Blocked by MNG FW so bail */
202 if (ixgbe_check_reset_blocked(hw))
203 goto out;
204
Auke Kok9a799d72007-09-15 14:07:45 -0700205 /*
206 * Perform soft PHY reset to the PHY_XS.
207 * This will cause a soft reset to the PHY
208 */
Emil Tantilov17835752011-02-16 01:38:13 +0000209 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
210 MDIO_MMD_PHYXS,
211 MDIO_CTRL1_RESET);
212
213 /*
214 * Poll for reset bit to self-clear indicating reset is complete.
215 * Some PHYs could take up to 3 seconds to complete and need about
216 * 1.7 usec delay after the reset is complete.
217 */
218 for (i = 0; i < 30; i++) {
219 msleep(100);
220 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
221 MDIO_MMD_PHYXS, &ctrl);
222 if (!(ctrl & MDIO_CTRL1_RESET)) {
223 udelay(2);
224 break;
225 }
226 }
227
228 if (ctrl & MDIO_CTRL1_RESET) {
229 status = IXGBE_ERR_RESET_FAILED;
230 hw_dbg(hw, "PHY reset polling failed to complete.\n");
231 }
232
233out:
234 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700235}
236
237/**
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000238 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
239 * the SWFW lock
240 * @hw: pointer to hardware structure
241 * @reg_addr: 32 bit address of PHY register to read
242 * @phy_data: Pointer to read data from PHY register
243 **/
244s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
245 u16 *phy_data)
246{
247 u32 i, data, command;
248
249 /* Setup and write the address cycle command */
250 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
251 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
252 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
253 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
254
255 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
256
257 /* Check every 10 usec to see if the address cycle completed.
258 * The MDI Command bit will clear when the operation is
259 * complete
260 */
261 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
262 udelay(10);
263
264 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
265 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
266 break;
267 }
268
269
270 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
271 hw_dbg(hw, "PHY address command did not complete.\n");
272 return IXGBE_ERR_PHY;
273 }
274
275 /* Address cycle complete, setup and write the read
276 * command
277 */
278 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
279 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
280 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
281 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
282
283 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
284
285 /* Check every 10 usec to see if the address cycle
286 * completed. The MDI Command bit will clear when the
287 * operation is complete
288 */
289 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
290 udelay(10);
291
292 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
293 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
294 break;
295 }
296
297 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
298 hw_dbg(hw, "PHY read command didn't complete\n");
299 return IXGBE_ERR_PHY;
300 }
301
302 /* Read operation is complete. Get the data
303 * from MSRWD
304 */
305 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
306 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
307 *phy_data = (u16)(data);
308
309 return 0;
310}
311
312/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700313 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000314 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700315 * @hw: pointer to hardware structure
316 * @reg_addr: 32 bit address of PHY register to read
317 * @phy_data: Pointer to read data from PHY register
318 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700319s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
320 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700321{
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000322 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700323 u16 gssr;
324
325 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
326 gssr = IXGBE_GSSR_PHY1_SM;
327 else
328 gssr = IXGBE_GSSR_PHY0_SM;
329
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000330 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
331 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
332 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000333 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000334 } else {
335 status = IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700336 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700337
Auke Kok9a799d72007-09-15 14:07:45 -0700338 return status;
339}
340
341/**
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000342 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
343 * without SWFW lock
344 * @hw: pointer to hardware structure
345 * @reg_addr: 32 bit PHY register to write
346 * @device_type: 5 bit device type
347 * @phy_data: Data to write to the PHY register
348 **/
349s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
350 u32 device_type, u16 phy_data)
351{
352 u32 i, command;
353
354 /* Put the data in the MDI single read and write data register*/
355 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
356
357 /* Setup and write the address cycle command */
358 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
359 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
360 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
361 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
362
363 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
364
365 /*
366 * Check every 10 usec to see if the address cycle completed.
367 * The MDI Command bit will clear when the operation is
368 * complete
369 */
370 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
371 udelay(10);
372
373 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
374 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
375 break;
376 }
377
378 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
379 hw_dbg(hw, "PHY address cmd didn't complete\n");
380 return IXGBE_ERR_PHY;
381 }
382
383 /*
384 * Address cycle complete, setup and write the write
385 * command
386 */
387 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
388 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
389 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
390 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
391
392 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
393
394 /* Check every 10 usec to see if the address cycle
395 * completed. The MDI Command bit will clear when the
396 * operation is complete
397 */
398 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
399 udelay(10);
400
401 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
402 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
403 break;
404 }
405
406 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
407 hw_dbg(hw, "PHY write cmd didn't complete\n");
408 return IXGBE_ERR_PHY;
409 }
410
411 return 0;
412}
413
414/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700415 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000416 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700417 * @hw: pointer to hardware structure
418 * @reg_addr: 32 bit PHY register to write
419 * @device_type: 5 bit device type
420 * @phy_data: Data to write to the PHY register
421 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700422s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
423 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700424{
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000425 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700426 u16 gssr;
427
428 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
429 gssr = IXGBE_GSSR_PHY1_SM;
430 else
431 gssr = IXGBE_GSSR_PHY0_SM;
432
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000433 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
434 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
435 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000436 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f42013-05-29 06:23:05 +0000437 } else {
438 status = IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700439 }
440
441 return status;
442}
443
444/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700445 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700446 * @hw: pointer to hardware structure
447 *
448 * Restart autonegotiation and PHY and waits for completion.
449 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700450s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700451{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000452 s32 status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700453 u32 time_out;
454 u32 max_time_out = 10;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000455 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
456 bool autoneg = false;
457 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700458
Emil Tantilov9dda1732011-03-05 01:28:07 +0000459 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700460
Emil Tantilov9dda1732011-03-05 01:28:07 +0000461 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
462 /* Set or unset auto-negotiation 10G advertisement */
463 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
464 MDIO_MMD_AN,
465 &autoneg_reg);
466
Ben Hutchings6b73e102009-04-29 08:08:58 +0000467 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000468 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
469 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700470
Emil Tantilov9dda1732011-03-05 01:28:07 +0000471 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
472 MDIO_MMD_AN,
473 autoneg_reg);
474 }
475
476 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
477 /* Set or unset auto-negotiation 1G advertisement */
478 hw->phy.ops.read_reg(hw,
479 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
480 MDIO_MMD_AN,
481 &autoneg_reg);
482
483 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
484 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
485 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
486
487 hw->phy.ops.write_reg(hw,
488 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
489 MDIO_MMD_AN,
490 autoneg_reg);
491 }
492
493 if (speed & IXGBE_LINK_SPEED_100_FULL) {
494 /* Set or unset auto-negotiation 100M advertisement */
495 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
496 MDIO_MMD_AN,
497 &autoneg_reg);
498
Emil Tantilova59e8a12011-03-31 09:36:12 +0000499 autoneg_reg &= ~(ADVERTISE_100FULL |
500 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000501 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
502 autoneg_reg |= ADVERTISE_100FULL;
503
504 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
505 MDIO_MMD_AN,
506 autoneg_reg);
507 }
Auke Kok9a799d72007-09-15 14:07:45 -0700508
Don Skidmorec97506a2014-02-27 20:32:43 -0800509 /* Blocked by MNG FW so don't reset PHY */
510 if (ixgbe_check_reset_blocked(hw))
511 return status;
512
Auke Kok9a799d72007-09-15 14:07:45 -0700513 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000514 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
515 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700516
Ben Hutchings6b73e102009-04-29 08:08:58 +0000517 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700518
Emil Tantilov9dda1732011-03-05 01:28:07 +0000519 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
520 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700521
522 /* Wait for autonegotiation to finish */
523 for (time_out = 0; time_out < max_time_out; time_out++) {
524 udelay(10);
525 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000526 status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
527 MDIO_MMD_AN,
528 &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700529
Ben Hutchings6b73e102009-04-29 08:08:58 +0000530 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
531 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700532 break;
533 }
534 }
535
Emil Tantilov9dda1732011-03-05 01:28:07 +0000536 if (time_out == max_time_out) {
Auke Kok9a799d72007-09-15 14:07:45 -0700537 status = IXGBE_ERR_LINK_SETUP;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000538 hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out");
539 }
Auke Kok9a799d72007-09-15 14:07:45 -0700540
541 return status;
542}
543
544/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700545 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700546 * @hw: pointer to hardware structure
547 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700548 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700549s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
550 ixgbe_link_speed speed,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700551 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700552{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700553
Auke Kok9a799d72007-09-15 14:07:45 -0700554 /*
555 * Clear autoneg_advertised and set new values based on input link
556 * speed.
557 */
558 hw->phy.autoneg_advertised = 0;
559
560 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
561 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700562
Auke Kok9a799d72007-09-15 14:07:45 -0700563 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
564 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
565
Emil Tantilov9dda1732011-03-05 01:28:07 +0000566 if (speed & IXGBE_LINK_SPEED_100_FULL)
567 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
568
Auke Kok9a799d72007-09-15 14:07:45 -0700569 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700570 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700571
572 return 0;
573}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700574
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700575/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800576 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
577 * @hw: pointer to hardware structure
578 * @speed: pointer to link speed
579 * @autoneg: boolean auto-negotiation value
580 *
581 * Determines the link capabilities by reading the AUTOC register.
582 */
583s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800584 ixgbe_link_speed *speed,
585 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800586{
587 s32 status = IXGBE_ERR_LINK_SETUP;
588 u16 speed_ability;
589
590 *speed = 0;
591 *autoneg = true;
592
593 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
594 &speed_ability);
595
596 if (status == 0) {
597 if (speed_ability & MDIO_SPEED_10G)
598 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
599 if (speed_ability & MDIO_PMA_SPEED_1000)
600 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
601 if (speed_ability & MDIO_PMA_SPEED_100)
602 *speed |= IXGBE_LINK_SPEED_100_FULL;
603 }
604
605 return status;
606}
607
608/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000609 * ixgbe_check_phy_link_tnx - Determine link and speed status
610 * @hw: pointer to hardware structure
611 *
612 * Reads the VS1 register to determine if link is up and the current speed for
613 * the PHY.
614 **/
615s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
616 bool *link_up)
617{
618 s32 status = 0;
619 u32 time_out;
620 u32 max_time_out = 10;
621 u16 phy_link = 0;
622 u16 phy_speed = 0;
623 u16 phy_data = 0;
624
625 /* Initialize speed and link to default case */
626 *link_up = false;
627 *speed = IXGBE_LINK_SPEED_10GB_FULL;
628
629 /*
630 * Check current speed and link status of the PHY register.
631 * This is a vendor specific register and may have to
632 * be changed for other copper PHYs.
633 */
634 for (time_out = 0; time_out < max_time_out; time_out++) {
635 udelay(10);
636 status = hw->phy.ops.read_reg(hw,
637 MDIO_STAT1,
638 MDIO_MMD_VEND1,
639 &phy_data);
640 phy_link = phy_data &
641 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
642 phy_speed = phy_data &
643 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
644 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
645 *link_up = true;
646 if (phy_speed ==
647 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
648 *speed = IXGBE_LINK_SPEED_1GB_FULL;
649 break;
650 }
651 }
652
653 return status;
654}
655
656/**
657 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
658 * @hw: pointer to hardware structure
659 *
660 * Restart autonegotiation and PHY and waits for completion.
661 **/
662s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
663{
664 s32 status = 0;
665 u32 time_out;
666 u32 max_time_out = 10;
667 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
668 bool autoneg = false;
669 ixgbe_link_speed speed;
670
671 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
672
673 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
674 /* Set or unset auto-negotiation 10G advertisement */
675 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
676 MDIO_MMD_AN,
677 &autoneg_reg);
678
679 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
680 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
681 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
682
683 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
684 MDIO_MMD_AN,
685 autoneg_reg);
686 }
687
688 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
689 /* Set or unset auto-negotiation 1G advertisement */
690 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
691 MDIO_MMD_AN,
692 &autoneg_reg);
693
694 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
695 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
696 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
697
698 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
699 MDIO_MMD_AN,
700 autoneg_reg);
701 }
702
703 if (speed & IXGBE_LINK_SPEED_100_FULL) {
704 /* Set or unset auto-negotiation 100M advertisement */
705 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
706 MDIO_MMD_AN,
707 &autoneg_reg);
708
Emil Tantilov50c022e2011-03-31 09:36:12 +0000709 autoneg_reg &= ~(ADVERTISE_100FULL |
710 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000711 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
712 autoneg_reg |= ADVERTISE_100FULL;
713
714 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
715 MDIO_MMD_AN,
716 autoneg_reg);
717 }
718
Don Skidmorec97506a2014-02-27 20:32:43 -0800719 /* Blocked by MNG FW so don't reset PHY */
720 if (ixgbe_check_reset_blocked(hw))
721 return status;
722
Emil Tantilov9dda1732011-03-05 01:28:07 +0000723 /* Restart PHY autonegotiation and wait for completion */
724 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
725 MDIO_MMD_AN, &autoneg_reg);
726
727 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
728
729 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
730 MDIO_MMD_AN, autoneg_reg);
731
732 /* Wait for autonegotiation to finish */
733 for (time_out = 0; time_out < max_time_out; time_out++) {
734 udelay(10);
735 /* Restart PHY autonegotiation and wait for completion */
736 status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
737 MDIO_MMD_AN,
738 &autoneg_reg);
739
740 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
741 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE)
742 break;
743 }
744
745 if (time_out == max_time_out) {
746 status = IXGBE_ERR_LINK_SETUP;
747 hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out");
748 }
749
750 return status;
751}
752
753/**
754 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
755 * @hw: pointer to hardware structure
756 * @firmware_version: pointer to the PHY Firmware Version
757 **/
758s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
759 u16 *firmware_version)
760{
761 s32 status = 0;
762
763 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
764 MDIO_MMD_VEND1,
765 firmware_version);
766
767 return status;
768}
769
770/**
771 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
772 * @hw: pointer to hardware structure
773 * @firmware_version: pointer to the PHY Firmware Version
774 **/
775s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
776 u16 *firmware_version)
777{
778 s32 status = 0;
779
780 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
781 MDIO_MMD_VEND1,
782 firmware_version);
783
784 return status;
785}
786
787/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800788 * ixgbe_reset_phy_nl - Performs a PHY reset
789 * @hw: pointer to hardware structure
790 **/
791s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
792{
793 u16 phy_offset, control, eword, edata, block_crc;
794 bool end_data = false;
795 u16 list_offset, data_offset;
796 u16 phy_data = 0;
797 s32 ret_val = 0;
798 u32 i;
799
Don Skidmorec97506a2014-02-27 20:32:43 -0800800 /* Blocked by MNG FW so bail */
801 if (ixgbe_check_reset_blocked(hw))
802 goto out;
803
Ben Hutchings6b73e102009-04-29 08:08:58 +0000804 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800805
806 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000807 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
808 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800809
810 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000811 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
812 &phy_data);
813 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800814 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000815 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800816 }
817
Ben Hutchings6b73e102009-04-29 08:08:58 +0000818 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800819 hw_dbg(hw, "PHY reset did not complete.\n");
820 ret_val = IXGBE_ERR_PHY;
821 goto out;
822 }
823
824 /* Get init offsets */
825 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
826 &data_offset);
827 if (ret_val != 0)
828 goto out;
829
830 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
831 data_offset++;
832 while (!end_data) {
833 /*
834 * Read control word from PHY init contents offset
835 */
836 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000837 if (ret_val)
838 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800839 control = (eword & IXGBE_CONTROL_MASK_NL) >>
840 IXGBE_CONTROL_SHIFT_NL;
841 edata = eword & IXGBE_DATA_MASK_NL;
842 switch (control) {
843 case IXGBE_DELAY_NL:
844 data_offset++;
845 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000846 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800847 break;
848 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000849 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800850 data_offset++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000851 ret_val = hw->eeprom.ops.read(hw, data_offset++,
852 &phy_offset);
853 if (ret_val)
854 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800855 for (i = 0; i < edata; i++) {
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000856 ret_val = hw->eeprom.ops.read(hw, data_offset,
857 &eword);
858 if (ret_val)
859 goto err_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800860 hw->phy.ops.write_reg(hw, phy_offset,
Ben Hutchings6b73e102009-04-29 08:08:58 +0000861 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800862 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
863 phy_offset);
864 data_offset++;
865 phy_offset++;
866 }
867 break;
868 case IXGBE_CONTROL_NL:
869 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +0000870 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800871 if (edata == IXGBE_CONTROL_EOL_NL) {
872 hw_dbg(hw, "EOL\n");
873 end_data = true;
874 } else if (edata == IXGBE_CONTROL_SOL_NL) {
875 hw_dbg(hw, "SOL\n");
876 } else {
877 hw_dbg(hw, "Bad control value\n");
878 ret_val = IXGBE_ERR_PHY;
879 goto out;
880 }
881 break;
882 default:
883 hw_dbg(hw, "Bad control type\n");
884 ret_val = IXGBE_ERR_PHY;
885 goto out;
886 }
887 }
888
889out:
890 return ret_val;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000891
892err_eeprom:
893 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
894 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800895}
896
897/**
Don Skidmore8f583322013-07-27 06:25:38 +0000898 * ixgbe_identify_module_generic - Identifies module type
Donald Skidmorec4900be2008-11-20 21:11:42 -0800899 * @hw: pointer to hardware structure
900 *
Don Skidmore8f583322013-07-27 06:25:38 +0000901 * Determines HW type and calls appropriate function.
902 **/
903s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
904{
905 s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
906
907 switch (hw->mac.ops.get_media_type(hw)) {
908 case ixgbe_media_type_fiber:
909 status = ixgbe_identify_sfp_module_generic(hw);
910 break;
911 case ixgbe_media_type_fiber_qsfp:
912 status = ixgbe_identify_qsfp_module_generic(hw);
913 break;
914 default:
915 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
916 status = IXGBE_ERR_SFP_NOT_PRESENT;
917 break;
918 }
919
920 return status;
921}
922
923/**
924 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
925 * @hw: pointer to hardware structure
926*
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000927 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -0800928 **/
929s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
930{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000931 struct ixgbe_adapter *adapter = hw->back;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800932 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
933 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000934 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800935 u8 identifier = 0;
936 u8 comp_codes_1g = 0;
937 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000938 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000939 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000940 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000941 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800942
Don Skidmore8ca783a2009-05-26 20:40:47 -0700943 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
944 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
945 status = IXGBE_ERR_SFP_NOT_PRESENT;
946 goto out;
947 }
948
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000949 status = hw->phy.ops.read_i2c_eeprom(hw,
950 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +0000951 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800952
Emil Tantilov51d04202013-01-18 02:17:11 +0000953 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000954 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800955
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000956 /* LAN ID is needed for sfp_type determination */
957 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800958
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000959 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
960 hw->phy.type = ixgbe_phy_sfp_unsupported;
961 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
962 } else {
963 status = hw->phy.ops.read_i2c_eeprom(hw,
964 IXGBE_SFF_1GBE_COMP_CODES,
965 &comp_codes_1g);
966
Emil Tantilov51d04202013-01-18 02:17:11 +0000967 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000968 goto err_read_i2c_eeprom;
969
970 status = hw->phy.ops.read_i2c_eeprom(hw,
971 IXGBE_SFF_10GBE_COMP_CODES,
972 &comp_codes_10g);
973
Emil Tantilov51d04202013-01-18 02:17:11 +0000974 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000975 goto err_read_i2c_eeprom;
976 status = hw->phy.ops.read_i2c_eeprom(hw,
977 IXGBE_SFF_CABLE_TECHNOLOGY,
978 &cable_tech);
979
Emil Tantilov51d04202013-01-18 02:17:11 +0000980 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000981 goto err_read_i2c_eeprom;
982
983 /* ID Module
984 * =========
985 * 0 SFP_DA_CU
986 * 1 SFP_SR
987 * 2 SFP_LR
988 * 3 SFP_DA_CORE0 - 82599-specific
989 * 4 SFP_DA_CORE1 - 82599-specific
990 * 5 SFP_SR/LR_CORE0 - 82599-specific
991 * 6 SFP_SR/LR_CORE1 - 82599-specific
992 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
993 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
994 * 9 SFP_1g_cu_CORE0 - 82599-specific
995 * 10 SFP_1g_cu_CORE1 - 82599-specific
Jacob Kellera49fda32012-06-08 06:59:09 +0000996 * 11 SFP_1g_sx_CORE0 - 82599-specific
997 * 12 SFP_1g_sx_CORE1 - 82599-specific
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000998 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000999 if (hw->mac.type == ixgbe_mac_82598EB) {
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001000 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001001 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1002 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1003 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1004 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1005 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1006 else
1007 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1008 } else if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001009 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001010 if (hw->bus.lan_id == 0)
1011 hw->phy.sfp_type =
1012 ixgbe_sfp_type_da_cu_core0;
1013 else
1014 hw->phy.sfp_type =
1015 ixgbe_sfp_type_da_cu_core1;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001016 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1017 hw->phy.ops.read_i2c_eeprom(
1018 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1019 &cable_spec);
1020 if (cable_spec &
1021 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1022 if (hw->bus.lan_id == 0)
1023 hw->phy.sfp_type =
1024 ixgbe_sfp_type_da_act_lmt_core0;
1025 else
1026 hw->phy.sfp_type =
1027 ixgbe_sfp_type_da_act_lmt_core1;
1028 } else {
1029 hw->phy.sfp_type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001030 ixgbe_sfp_type_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001031 }
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001032 } else if (comp_codes_10g &
1033 (IXGBE_SFF_10GBASESR_CAPABLE |
1034 IXGBE_SFF_10GBASELR_CAPABLE)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001035 if (hw->bus.lan_id == 0)
1036 hw->phy.sfp_type =
1037 ixgbe_sfp_type_srlr_core0;
1038 else
1039 hw->phy.sfp_type =
1040 ixgbe_sfp_type_srlr_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001041 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001042 if (hw->bus.lan_id == 0)
1043 hw->phy.sfp_type =
1044 ixgbe_sfp_type_1g_cu_core0;
1045 else
1046 hw->phy.sfp_type =
1047 ixgbe_sfp_type_1g_cu_core1;
Jacob Kellera49fda32012-06-08 06:59:09 +00001048 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1049 if (hw->bus.lan_id == 0)
1050 hw->phy.sfp_type =
1051 ixgbe_sfp_type_1g_sx_core0;
1052 else
1053 hw->phy.sfp_type =
1054 ixgbe_sfp_type_1g_sx_core1;
Don Skidmore345be202013-04-11 06:23:34 +00001055 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1056 if (hw->bus.lan_id == 0)
1057 hw->phy.sfp_type =
1058 ixgbe_sfp_type_1g_lx_core0;
1059 else
1060 hw->phy.sfp_type =
1061 ixgbe_sfp_type_1g_lx_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001062 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001063 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001064 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001065 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001066
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001067 if (hw->phy.sfp_type != stored_sfp_type)
1068 hw->phy.sfp_setup_needed = true;
1069
1070 /* Determine if the SFP+ PHY is dual speed or not. */
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00001071 hw->phy.multispeed_fiber = false;
PJ Waskiewicz553b4492009-04-09 22:28:15 +00001072 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1073 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1074 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1075 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1076 hw->phy.multispeed_fiber = true;
1077
Donald Skidmorec4900be2008-11-20 21:11:42 -08001078 /* Determine PHY vendor */
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +00001079 if (hw->phy.type != ixgbe_phy_nl) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001080 hw->phy.id = identifier;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001081 status = hw->phy.ops.read_i2c_eeprom(hw,
Emil Tantilov51d04202013-01-18 02:17:11 +00001082 IXGBE_SFF_VENDOR_OUI_BYTE0,
1083 &oui_bytes[0]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001084
Emil Tantilov51d04202013-01-18 02:17:11 +00001085 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001086 goto err_read_i2c_eeprom;
1087
1088 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -08001089 IXGBE_SFF_VENDOR_OUI_BYTE1,
1090 &oui_bytes[1]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001091
Emil Tantilov51d04202013-01-18 02:17:11 +00001092 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001093 goto err_read_i2c_eeprom;
1094
1095 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -08001096 IXGBE_SFF_VENDOR_OUI_BYTE2,
1097 &oui_bytes[2]);
1098
Emil Tantilov51d04202013-01-18 02:17:11 +00001099 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001100 goto err_read_i2c_eeprom;
1101
Donald Skidmorec4900be2008-11-20 21:11:42 -08001102 vendor_oui =
1103 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1104 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1105 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1106
1107 switch (vendor_oui) {
1108 case IXGBE_SFF_VENDOR_OUI_TYCO:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001109 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001110 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001111 ixgbe_phy_sfp_passive_tyco;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001112 break;
1113 case IXGBE_SFF_VENDOR_OUI_FTL:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001114 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1115 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1116 else
1117 hw->phy.type = ixgbe_phy_sfp_ftl;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001118 break;
1119 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1120 hw->phy.type = ixgbe_phy_sfp_avago;
1121 break;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001122 case IXGBE_SFF_VENDOR_OUI_INTEL:
1123 hw->phy.type = ixgbe_phy_sfp_intel;
1124 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001125 default:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001126 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001127 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001128 ixgbe_phy_sfp_passive_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001129 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1130 hw->phy.type =
1131 ixgbe_phy_sfp_active_unknown;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001132 else
1133 hw->phy.type = ixgbe_phy_sfp_unknown;
1134 break;
1135 }
1136 }
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001137
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001138 /* Allow any DA cable vendor */
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001139 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1140 IXGBE_SFF_DA_ACTIVE_CABLE)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001141 status = 0;
1142 goto out;
1143 }
1144
Don Skidmorecb836a92010-06-29 18:30:59 +00001145 /* Verify supported 1G SFP modules */
1146 if (comp_codes_10g == 0 &&
1147 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001148 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001149 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1150 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001151 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1152 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001153 hw->phy.type = ixgbe_phy_sfp_unsupported;
1154 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1155 goto out;
1156 }
1157
1158 /* Anything else 82598-based is supported */
1159 if (hw->mac.type == ixgbe_mac_82598EB) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001160 status = 0;
1161 goto out;
1162 }
1163
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +00001164 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
Don Skidmorecb836a92010-06-29 18:30:59 +00001165 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
Don Skidmore345be202013-04-11 06:23:34 +00001166 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1167 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1168 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1169 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1170 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1171 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001172 /* Make sure we're a supported PHY type */
1173 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1174 status = 0;
1175 } else {
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001176 if (hw->allow_unsupported_sfp) {
1177 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.");
1178 status = 0;
1179 } else {
1180 hw_dbg(hw,
1181 "SFP+ module not supported\n");
1182 hw->phy.type =
1183 ixgbe_phy_sfp_unsupported;
1184 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1185 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001186 }
1187 } else {
1188 status = 0;
1189 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001190 }
1191
1192out:
1193 return status;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001194
1195err_read_i2c_eeprom:
1196 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1197 if (hw->phy.type != ixgbe_phy_nl) {
1198 hw->phy.id = 0;
1199 hw->phy.type = ixgbe_phy_unknown;
1200 }
1201 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001202}
1203
1204/**
Don Skidmore8f583322013-07-27 06:25:38 +00001205 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1206 * @hw: pointer to hardware structure
1207 *
1208 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1209 **/
Mark Rustad88217542013-11-23 03:19:19 +00001210static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
Don Skidmore8f583322013-07-27 06:25:38 +00001211{
1212 struct ixgbe_adapter *adapter = hw->back;
1213 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1214 u32 vendor_oui = 0;
1215 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1216 u8 identifier = 0;
1217 u8 comp_codes_1g = 0;
1218 u8 comp_codes_10g = 0;
1219 u8 oui_bytes[3] = {0, 0, 0};
1220 u16 enforce_sfp = 0;
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001221 u8 connector = 0;
1222 u8 cable_length = 0;
1223 u8 device_tech = 0;
1224 bool active_cable = false;
Don Skidmore8f583322013-07-27 06:25:38 +00001225
1226 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1227 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1228 status = IXGBE_ERR_SFP_NOT_PRESENT;
1229 goto out;
1230 }
1231
1232 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1233 &identifier);
1234
1235 if (status != 0)
1236 goto err_read_i2c_eeprom;
1237
1238 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1239 hw->phy.type = ixgbe_phy_sfp_unsupported;
1240 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1241 goto out;
1242 }
1243
1244 hw->phy.id = identifier;
1245
1246 /* LAN ID is needed for sfp_type determination */
1247 hw->mac.ops.set_lan_id(hw);
1248
1249 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1250 &comp_codes_10g);
1251
1252 if (status != 0)
1253 goto err_read_i2c_eeprom;
1254
Emil Tantilov61aaf9e2013-08-13 07:22:16 +00001255 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1256 &comp_codes_1g);
1257
1258 if (status != 0)
1259 goto err_read_i2c_eeprom;
1260
Don Skidmore8f583322013-07-27 06:25:38 +00001261 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1262 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1263 if (hw->bus.lan_id == 0)
1264 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1265 else
1266 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
Don Skidmore8f583322013-07-27 06:25:38 +00001267 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1268 IXGBE_SFF_10GBASELR_CAPABLE)) {
1269 if (hw->bus.lan_id == 0)
1270 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1271 else
1272 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1273 } else {
Emil Tantilov9a84fea2013-08-16 23:11:14 +00001274 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1275 active_cable = true;
1276
1277 if (!active_cable) {
1278 /* check for active DA cables that pre-date
1279 * SFF-8436 v3.6
1280 */
1281 hw->phy.ops.read_i2c_eeprom(hw,
1282 IXGBE_SFF_QSFP_CONNECTOR,
1283 &connector);
1284
1285 hw->phy.ops.read_i2c_eeprom(hw,
1286 IXGBE_SFF_QSFP_CABLE_LENGTH,
1287 &cable_length);
1288
1289 hw->phy.ops.read_i2c_eeprom(hw,
1290 IXGBE_SFF_QSFP_DEVICE_TECH,
1291 &device_tech);
1292
1293 if ((connector ==
1294 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1295 (cable_length > 0) &&
1296 ((device_tech >> 4) ==
1297 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1298 active_cable = true;
1299 }
1300
1301 if (active_cable) {
1302 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1303 if (hw->bus.lan_id == 0)
1304 hw->phy.sfp_type =
1305 ixgbe_sfp_type_da_act_lmt_core0;
1306 else
1307 hw->phy.sfp_type =
1308 ixgbe_sfp_type_da_act_lmt_core1;
1309 } else {
1310 /* unsupported module type */
1311 hw->phy.type = ixgbe_phy_sfp_unsupported;
1312 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1313 goto out;
1314 }
Don Skidmore8f583322013-07-27 06:25:38 +00001315 }
1316
1317 if (hw->phy.sfp_type != stored_sfp_type)
1318 hw->phy.sfp_setup_needed = true;
1319
1320 /* Determine if the QSFP+ PHY is dual speed or not. */
1321 hw->phy.multispeed_fiber = false;
1322 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1323 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1324 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1325 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1326 hw->phy.multispeed_fiber = true;
1327
1328 /* Determine PHY vendor for optical modules */
1329 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1330 IXGBE_SFF_10GBASELR_CAPABLE)) {
1331 status = hw->phy.ops.read_i2c_eeprom(hw,
1332 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1333 &oui_bytes[0]);
1334
1335 if (status != 0)
1336 goto err_read_i2c_eeprom;
1337
1338 status = hw->phy.ops.read_i2c_eeprom(hw,
1339 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1340 &oui_bytes[1]);
1341
1342 if (status != 0)
1343 goto err_read_i2c_eeprom;
1344
1345 status = hw->phy.ops.read_i2c_eeprom(hw,
1346 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1347 &oui_bytes[2]);
1348
1349 if (status != 0)
1350 goto err_read_i2c_eeprom;
1351
1352 vendor_oui =
1353 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1354 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1355 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1356
1357 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1358 hw->phy.type = ixgbe_phy_qsfp_intel;
1359 else
1360 hw->phy.type = ixgbe_phy_qsfp_unknown;
1361
1362 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1363 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1364 /* Make sure we're a supported PHY type */
1365 if (hw->phy.type == ixgbe_phy_qsfp_intel) {
1366 status = 0;
1367 } else {
1368 if (hw->allow_unsupported_sfp == true) {
Don Skidmore1b1bf312013-07-31 05:27:04 +00001369 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");
Don Skidmore8f583322013-07-27 06:25:38 +00001370 status = 0;
1371 } else {
1372 hw_dbg(hw,
1373 "QSFP module not supported\n");
1374 hw->phy.type =
1375 ixgbe_phy_sfp_unsupported;
1376 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1377 }
1378 }
1379 } else {
1380 status = 0;
1381 }
1382 }
1383
1384out:
1385 return status;
1386
1387err_read_i2c_eeprom:
1388 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1389 hw->phy.id = 0;
1390 hw->phy.type = ixgbe_phy_unknown;
1391
1392 return IXGBE_ERR_SFP_NOT_PRESENT;
1393}
1394
1395/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001396 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001397 * @hw: pointer to hardware structure
1398 * @list_offset: offset to the SFP ID list
1399 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001400 *
1401 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1402 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001403 **/
1404s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1405 u16 *list_offset,
1406 u16 *data_offset)
1407{
1408 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001409 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001410
1411 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1412 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1413
1414 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1415 return IXGBE_ERR_SFP_NOT_PRESENT;
1416
1417 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1418 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1419 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1420
Don Skidmorecb836a92010-06-29 18:30:59 +00001421 /*
1422 * Limiting active cables and 1G Phys must be initialized as
1423 * SR modules
1424 */
1425 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001426 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001427 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1428 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001429 sfp_type = ixgbe_sfp_type_srlr_core0;
1430 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001431 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001432 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1433 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001434 sfp_type = ixgbe_sfp_type_srlr_core1;
1435
Donald Skidmorec4900be2008-11-20 21:11:42 -08001436 /* Read offset to PHY init contents */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001437 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1438 hw_err(hw, "eeprom read at %d failed\n",
1439 IXGBE_PHY_INIT_OFFSET_NL);
1440 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1441 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001442
1443 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001444 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001445
1446 /* Shift offset to first ID word */
1447 (*list_offset)++;
1448
1449 /*
1450 * Find the matching SFP ID in the EEPROM
1451 * and program the init sequence
1452 */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001453 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1454 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001455
1456 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001457 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001458 (*list_offset)++;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001459 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1460 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001461 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1462 hw_dbg(hw, "SFP+ module not supported\n");
1463 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1464 } else {
1465 break;
1466 }
1467 } else {
1468 (*list_offset) += 2;
1469 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001470 goto err_phy;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001471 }
1472 }
1473
1474 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1475 hw_dbg(hw, "No matching SFP+ module found\n");
1476 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1477 }
1478
1479 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001480
1481err_phy:
1482 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1483 return IXGBE_ERR_PHY;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001484}
1485
1486/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001487 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1488 * @hw: pointer to hardware structure
1489 * @byte_offset: EEPROM byte offset to read
1490 * @eeprom_data: value read
1491 *
1492 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1493 **/
1494s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1495 u8 *eeprom_data)
1496{
1497 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1498 IXGBE_I2C_EEPROM_DEV_ADDR,
1499 eeprom_data);
1500}
1501
1502/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001503 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1504 * @hw: pointer to hardware structure
1505 * @byte_offset: byte offset at address 0xA2
1506 * @eeprom_data: value read
1507 *
1508 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1509 **/
1510s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1511 u8 *sff8472_data)
1512{
1513 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1514 IXGBE_I2C_EEPROM_DEV_ADDR2,
1515 sff8472_data);
1516}
1517
1518/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001519 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1520 * @hw: pointer to hardware structure
1521 * @byte_offset: EEPROM byte offset to write
1522 * @eeprom_data: value to write
1523 *
1524 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1525 **/
1526s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1527 u8 eeprom_data)
1528{
1529 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1530 IXGBE_I2C_EEPROM_DEV_ADDR,
1531 eeprom_data);
1532}
1533
1534/**
1535 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1536 * @hw: pointer to hardware structure
1537 * @byte_offset: byte offset to read
1538 * @data: value read
1539 *
1540 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001541 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001542 **/
1543s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1544 u8 dev_addr, u8 *data)
1545{
1546 s32 status = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001547 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001548 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001549 u16 swfw_mask = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001550 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001551 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001552
Emil Tantilov75f19c32011-02-19 08:43:55 +00001553 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1554 swfw_mask = IXGBE_GSSR_PHY1_SM;
1555 else
1556 swfw_mask = IXGBE_GSSR_PHY0_SM;
1557
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001558 do {
Emil Tantilov6d980c32011-04-13 04:56:15 +00001559 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
Emil Tantilov75f19c32011-02-19 08:43:55 +00001560 status = IXGBE_ERR_SWFW_SYNC;
1561 goto read_byte_out;
1562 }
1563
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001564 ixgbe_i2c_start(hw);
1565
1566 /* Device Address and write indication */
1567 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1568 if (status != 0)
1569 goto fail;
1570
1571 status = ixgbe_get_i2c_ack(hw);
1572 if (status != 0)
1573 goto fail;
1574
1575 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1576 if (status != 0)
1577 goto fail;
1578
1579 status = ixgbe_get_i2c_ack(hw);
1580 if (status != 0)
1581 goto fail;
1582
1583 ixgbe_i2c_start(hw);
1584
1585 /* Device Address and read indication */
1586 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1587 if (status != 0)
1588 goto fail;
1589
1590 status = ixgbe_get_i2c_ack(hw);
1591 if (status != 0)
1592 goto fail;
1593
1594 status = ixgbe_clock_in_i2c_byte(hw, data);
1595 if (status != 0)
1596 goto fail;
1597
1598 status = ixgbe_clock_out_i2c_bit(hw, nack);
1599 if (status != 0)
1600 goto fail;
1601
1602 ixgbe_i2c_stop(hw);
1603 break;
1604
1605fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001606 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001607 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001608 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001609 retry++;
1610 if (retry < max_retry)
1611 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1612 else
1613 hw_dbg(hw, "I2C byte read error.\n");
1614
1615 } while (retry < max_retry);
1616
Emil Tantilov6d980c32011-04-13 04:56:15 +00001617 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001618
1619read_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001620 return status;
1621}
1622
1623/**
1624 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1625 * @hw: pointer to hardware structure
1626 * @byte_offset: byte offset to write
1627 * @data: value to write
1628 *
1629 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1630 * a specified device address.
1631 **/
1632s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1633 u8 dev_addr, u8 data)
1634{
1635 s32 status = 0;
1636 u32 max_retry = 1;
1637 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001638 u16 swfw_mask = 0;
1639
1640 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1641 swfw_mask = IXGBE_GSSR_PHY1_SM;
1642 else
1643 swfw_mask = IXGBE_GSSR_PHY0_SM;
1644
Emil Tantilov6d980c32011-04-13 04:56:15 +00001645 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
Emil Tantilov75f19c32011-02-19 08:43:55 +00001646 status = IXGBE_ERR_SWFW_SYNC;
1647 goto write_byte_out;
1648 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001649
1650 do {
1651 ixgbe_i2c_start(hw);
1652
1653 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1654 if (status != 0)
1655 goto fail;
1656
1657 status = ixgbe_get_i2c_ack(hw);
1658 if (status != 0)
1659 goto fail;
1660
1661 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1662 if (status != 0)
1663 goto fail;
1664
1665 status = ixgbe_get_i2c_ack(hw);
1666 if (status != 0)
1667 goto fail;
1668
1669 status = ixgbe_clock_out_i2c_byte(hw, data);
1670 if (status != 0)
1671 goto fail;
1672
1673 status = ixgbe_get_i2c_ack(hw);
1674 if (status != 0)
1675 goto fail;
1676
1677 ixgbe_i2c_stop(hw);
1678 break;
1679
1680fail:
1681 ixgbe_i2c_bus_clear(hw);
1682 retry++;
1683 if (retry < max_retry)
1684 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1685 else
1686 hw_dbg(hw, "I2C byte write error.\n");
1687 } while (retry < max_retry);
1688
Emil Tantilov6d980c32011-04-13 04:56:15 +00001689 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001690
1691write_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001692 return status;
1693}
1694
1695/**
1696 * ixgbe_i2c_start - Sets I2C start condition
1697 * @hw: pointer to hardware structure
1698 *
1699 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1700 **/
1701static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1702{
1703 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1704
1705 /* Start condition must begin with data and clock high */
1706 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1707 ixgbe_raise_i2c_clk(hw, &i2cctl);
1708
1709 /* Setup time for start condition (4.7us) */
1710 udelay(IXGBE_I2C_T_SU_STA);
1711
1712 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1713
1714 /* Hold time for start condition (4us) */
1715 udelay(IXGBE_I2C_T_HD_STA);
1716
1717 ixgbe_lower_i2c_clk(hw, &i2cctl);
1718
1719 /* Minimum low period of clock is 4.7 us */
1720 udelay(IXGBE_I2C_T_LOW);
1721
1722}
1723
1724/**
1725 * ixgbe_i2c_stop - Sets I2C stop condition
1726 * @hw: pointer to hardware structure
1727 *
1728 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1729 **/
1730static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1731{
1732 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1733
1734 /* Stop condition must begin with data low and clock high */
1735 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1736 ixgbe_raise_i2c_clk(hw, &i2cctl);
1737
1738 /* Setup time for stop condition (4us) */
1739 udelay(IXGBE_I2C_T_SU_STO);
1740
1741 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1742
1743 /* bus free time between stop and start (4.7us)*/
1744 udelay(IXGBE_I2C_T_BUF);
1745}
1746
1747/**
1748 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1749 * @hw: pointer to hardware structure
1750 * @data: data byte to clock in
1751 *
1752 * Clocks in one byte data via I2C data/clock
1753 **/
1754static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1755{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001756 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001757 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001758
1759 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001760 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001761 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001762 }
1763
Emil Tantilove1befd72011-08-27 07:18:47 +00001764 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001765}
1766
1767/**
1768 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1769 * @hw: pointer to hardware structure
1770 * @data: data byte clocked out
1771 *
1772 * Clocks out one byte data via I2C data/clock
1773 **/
1774static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1775{
1776 s32 status = 0;
1777 s32 i;
1778 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001779 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001780
1781 for (i = 7; i >= 0; i--) {
1782 bit = (data >> i) & 0x1;
1783 status = ixgbe_clock_out_i2c_bit(hw, bit);
1784
1785 if (status != 0)
1786 break;
1787 }
1788
1789 /* Release SDA line (set high) */
1790 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1791 i2cctl |= IXGBE_I2C_DATA_OUT;
1792 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001793 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001794
1795 return status;
1796}
1797
1798/**
1799 * ixgbe_get_i2c_ack - Polls for I2C ACK
1800 * @hw: pointer to hardware structure
1801 *
1802 * Clocks in/out one bit via I2C data/clock
1803 **/
1804static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1805{
Emil Tantilove1befd72011-08-27 07:18:47 +00001806 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001807 u32 i = 0;
1808 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1809 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001810 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001811
Emil Tantilove1befd72011-08-27 07:18:47 +00001812 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001813
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001814
1815 /* Minimum high period of clock is 4us */
1816 udelay(IXGBE_I2C_T_HIGH);
1817
1818 /* Poll for ACK. Note that ACK in I2C spec is
1819 * transition from 1 to 0 */
1820 for (i = 0; i < timeout; i++) {
1821 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1822 ack = ixgbe_get_i2c_data(&i2cctl);
1823
1824 udelay(1);
1825 if (ack == 0)
1826 break;
1827 }
1828
1829 if (ack == 1) {
1830 hw_dbg(hw, "I2C ack was not received.\n");
1831 status = IXGBE_ERR_I2C;
1832 }
1833
1834 ixgbe_lower_i2c_clk(hw, &i2cctl);
1835
1836 /* Minimum low period of clock is 4.7 us */
1837 udelay(IXGBE_I2C_T_LOW);
1838
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001839 return status;
1840}
1841
1842/**
1843 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1844 * @hw: pointer to hardware structure
1845 * @data: read data value
1846 *
1847 * Clocks in one bit via I2C data/clock
1848 **/
1849static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1850{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001851 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1852
Emil Tantilove1befd72011-08-27 07:18:47 +00001853 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001854
1855 /* Minimum high period of clock is 4us */
1856 udelay(IXGBE_I2C_T_HIGH);
1857
1858 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1859 *data = ixgbe_get_i2c_data(&i2cctl);
1860
1861 ixgbe_lower_i2c_clk(hw, &i2cctl);
1862
1863 /* Minimum low period of clock is 4.7 us */
1864 udelay(IXGBE_I2C_T_LOW);
1865
Emil Tantilove1befd72011-08-27 07:18:47 +00001866 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001867}
1868
1869/**
1870 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1871 * @hw: pointer to hardware structure
1872 * @data: data value to write
1873 *
1874 * Clocks out one bit via I2C data/clock
1875 **/
1876static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1877{
1878 s32 status;
1879 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1880
1881 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1882 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001883 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001884
1885 /* Minimum high period of clock is 4us */
1886 udelay(IXGBE_I2C_T_HIGH);
1887
1888 ixgbe_lower_i2c_clk(hw, &i2cctl);
1889
1890 /* Minimum low period of clock is 4.7 us.
1891 * This also takes care of the data hold time.
1892 */
1893 udelay(IXGBE_I2C_T_LOW);
1894 } else {
1895 status = IXGBE_ERR_I2C;
1896 hw_dbg(hw, "I2C data was not set to %X\n", data);
1897 }
1898
1899 return status;
1900}
1901/**
1902 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1903 * @hw: pointer to hardware structure
1904 * @i2cctl: Current value of I2CCTL register
1905 *
1906 * Raises the I2C clock line '0'->'1'
1907 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00001908static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001909{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001910 u32 i = 0;
1911 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1912 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001913
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001914 for (i = 0; i < timeout; i++) {
1915 *i2cctl |= IXGBE_I2C_CLK_OUT;
1916 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1917 IXGBE_WRITE_FLUSH(hw);
1918 /* SCL rise time (1000ns) */
1919 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001920
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001921 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1922 if (i2cctl_r & IXGBE_I2C_CLK_IN)
1923 break;
1924 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001925}
1926
1927/**
1928 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1929 * @hw: pointer to hardware structure
1930 * @i2cctl: Current value of I2CCTL register
1931 *
1932 * Lowers the I2C clock line '1'->'0'
1933 **/
1934static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1935{
1936
1937 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1938
1939 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001940 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001941
1942 /* SCL fall time (300ns) */
1943 udelay(IXGBE_I2C_T_FALL);
1944}
1945
1946/**
1947 * ixgbe_set_i2c_data - Sets the I2C data bit
1948 * @hw: pointer to hardware structure
1949 * @i2cctl: Current value of I2CCTL register
1950 * @data: I2C data value (0 or 1) to set
1951 *
1952 * Sets the I2C data bit
1953 **/
1954static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1955{
1956 s32 status = 0;
1957
1958 if (data)
1959 *i2cctl |= IXGBE_I2C_DATA_OUT;
1960 else
1961 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1962
1963 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001964 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001965
1966 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1967 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1968
1969 /* Verify data was set correctly */
1970 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1971 if (data != ixgbe_get_i2c_data(i2cctl)) {
1972 status = IXGBE_ERR_I2C;
1973 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1974 }
1975
1976 return status;
1977}
1978
1979/**
1980 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1981 * @hw: pointer to hardware structure
1982 * @i2cctl: Current value of I2CCTL register
1983 *
1984 * Returns the I2C data bit value
1985 **/
1986static bool ixgbe_get_i2c_data(u32 *i2cctl)
1987{
1988 bool data;
1989
1990 if (*i2cctl & IXGBE_I2C_DATA_IN)
Rusty Russell3db1cd52011-12-19 13:56:45 +00001991 data = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001992 else
Rusty Russell3db1cd52011-12-19 13:56:45 +00001993 data = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001994
1995 return data;
1996}
1997
1998/**
1999 * ixgbe_i2c_bus_clear - Clears the I2C bus
2000 * @hw: pointer to hardware structure
2001 *
2002 * Clears the I2C bus by sending nine clock pulses.
2003 * Used when data line is stuck low.
2004 **/
2005static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2006{
2007 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
2008 u32 i;
2009
Emil Tantilov75f19c32011-02-19 08:43:55 +00002010 ixgbe_i2c_start(hw);
2011
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002012 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2013
2014 for (i = 0; i < 9; i++) {
2015 ixgbe_raise_i2c_clk(hw, &i2cctl);
2016
2017 /* Min high period of clock is 4us */
2018 udelay(IXGBE_I2C_T_HIGH);
2019
2020 ixgbe_lower_i2c_clk(hw, &i2cctl);
2021
2022 /* Min low period of clock is 4.7us*/
2023 udelay(IXGBE_I2C_T_LOW);
2024 }
2025
Emil Tantilov75f19c32011-02-19 08:43:55 +00002026 ixgbe_i2c_start(hw);
2027
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002028 /* Put the i2c bus back to default state */
2029 ixgbe_i2c_stop(hw);
2030}
2031
2032/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002033 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002034 * @hw: pointer to hardware structure
2035 *
2036 * Checks if the LASI temp alarm status was triggered due to overtemp
2037 **/
2038s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2039{
2040 s32 status = 0;
2041 u16 phy_data = 0;
2042
2043 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2044 goto out;
2045
2046 /* Check that the LASI temp alarm status was triggered */
2047 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2048 MDIO_MMD_PMAPMD, &phy_data);
2049
2050 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2051 goto out;
2052
2053 status = IXGBE_ERR_OVERTEMP;
2054out:
2055 return status;
2056}