blob: 71f554a3bcc2f9f11dcb04462b41f588819308c8 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 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
32#include "ixgbe_common.h"
33#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);
Auke Kok9a799d72007-09-15 14:07:45 -070049
50/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070051 * ixgbe_identify_phy_generic - Get physical layer module
Auke Kok9a799d72007-09-15 14:07:45 -070052 * @hw: pointer to hardware structure
53 *
54 * Determines the physical layer module found on the current adapter.
55 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070056s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070057{
58 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
59 u32 phy_addr;
Emil Tantilov037c6d02011-02-25 07:49:39 +000060 u16 ext_ability = 0;
Auke Kok9a799d72007-09-15 14:07:45 -070061
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070062 if (hw->phy.type == ixgbe_phy_unknown) {
63 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
Don Skidmore63d6e1d2009-07-02 12:50:12 +000064 hw->phy.mdio.prtad = phy_addr;
Ben Hutchings6b73e102009-04-29 08:08:58 +000065 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070066 ixgbe_get_phy_id(hw);
67 hw->phy.type =
68 ixgbe_get_phy_type_from_id(hw->phy.id);
Emil Tantilov037c6d02011-02-25 07:49:39 +000069
70 if (hw->phy.type == ixgbe_phy_unknown) {
71 hw->phy.ops.read_reg(hw,
72 MDIO_PMA_EXTABLE,
73 MDIO_MMD_PMAPMD,
74 &ext_ability);
75 if (ext_ability &
76 (MDIO_PMA_EXTABLE_10GBT |
77 MDIO_PMA_EXTABLE_1000BT))
78 hw->phy.type =
79 ixgbe_phy_cu_unknown;
80 else
81 hw->phy.type =
82 ixgbe_phy_generic;
83 }
84
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070085 status = 0;
86 break;
87 }
Auke Kok9a799d72007-09-15 14:07:45 -070088 }
Don Skidmore63d6e1d2009-07-02 12:50:12 +000089 /* clear value if nothing found */
Emil Tantilov037c6d02011-02-25 07:49:39 +000090 if (status != 0)
91 hw->phy.mdio.prtad = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070092 } else {
93 status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -070094 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070095
Auke Kok9a799d72007-09-15 14:07:45 -070096 return status;
97}
98
99/**
Auke Kok9a799d72007-09-15 14:07:45 -0700100 * ixgbe_get_phy_id - Get the phy type
101 * @hw: pointer to hardware structure
102 *
103 **/
104static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
105{
106 u32 status;
107 u16 phy_id_high = 0;
108 u16 phy_id_low = 0;
109
Ben Hutchings6b73e102009-04-29 08:08:58 +0000110 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700111 &phy_id_high);
Auke Kok9a799d72007-09-15 14:07:45 -0700112
113 if (status == 0) {
114 hw->phy.id = (u32)(phy_id_high << 16);
Ben Hutchings6b73e102009-04-29 08:08:58 +0000115 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700116 &phy_id_low);
Auke Kok9a799d72007-09-15 14:07:45 -0700117 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
118 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
119 }
Auke Kok9a799d72007-09-15 14:07:45 -0700120 return status;
121}
122
123/**
124 * ixgbe_get_phy_type_from_id - Get the phy type
125 * @hw: pointer to hardware structure
126 *
127 **/
128static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
129{
130 enum ixgbe_phy_type phy_type;
131
132 switch (phy_id) {
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700133 case TN1010_PHY_ID:
134 phy_type = ixgbe_phy_tn;
135 break;
Don Skidmore2b264902010-12-09 06:55:14 +0000136 case X540_PHY_ID:
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800137 phy_type = ixgbe_phy_aq;
138 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700139 case QT2022_PHY_ID:
140 phy_type = ixgbe_phy_qt;
141 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800142 case ATH_PHY_ID:
143 phy_type = ixgbe_phy_nl;
144 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700145 default:
146 phy_type = ixgbe_phy_unknown;
147 break;
148 }
149
150 return phy_type;
151}
152
153/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700154 * ixgbe_reset_phy_generic - Performs a PHY reset
Auke Kok9a799d72007-09-15 14:07:45 -0700155 * @hw: pointer to hardware structure
156 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700157s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700158{
Emil Tantilov17835752011-02-16 01:38:13 +0000159 u32 i;
160 u16 ctrl = 0;
161 s32 status = 0;
162
163 if (hw->phy.type == ixgbe_phy_unknown)
164 status = ixgbe_identify_phy_generic(hw);
165
166 if (status != 0 || hw->phy.type == ixgbe_phy_none)
167 goto out;
168
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700169 /* Don't reset PHY if it's shut down due to overtemp. */
170 if (!hw->phy.reset_if_overtemp &&
171 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
Emil Tantilov17835752011-02-16 01:38:13 +0000172 goto out;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700173
Auke Kok9a799d72007-09-15 14:07:45 -0700174 /*
175 * Perform soft PHY reset to the PHY_XS.
176 * This will cause a soft reset to the PHY
177 */
Emil Tantilov17835752011-02-16 01:38:13 +0000178 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
179 MDIO_MMD_PHYXS,
180 MDIO_CTRL1_RESET);
181
182 /*
183 * Poll for reset bit to self-clear indicating reset is complete.
184 * Some PHYs could take up to 3 seconds to complete and need about
185 * 1.7 usec delay after the reset is complete.
186 */
187 for (i = 0; i < 30; i++) {
188 msleep(100);
189 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
190 MDIO_MMD_PHYXS, &ctrl);
191 if (!(ctrl & MDIO_CTRL1_RESET)) {
192 udelay(2);
193 break;
194 }
195 }
196
197 if (ctrl & MDIO_CTRL1_RESET) {
198 status = IXGBE_ERR_RESET_FAILED;
199 hw_dbg(hw, "PHY reset polling failed to complete.\n");
200 }
201
202out:
203 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700204}
205
206/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000207 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
208 * the SWFW lock
209 * @hw: pointer to hardware structure
210 * @reg_addr: 32 bit address of PHY register to read
211 * @phy_data: Pointer to read data from PHY register
212 **/
213s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
214 u16 *phy_data)
215{
216 u32 i, data, command;
217
218 /* Setup and write the address cycle command */
219 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
220 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
221 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
222 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
223
224 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
225
226 /* Check every 10 usec to see if the address cycle completed.
227 * The MDI Command bit will clear when the operation is
228 * complete
229 */
230 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
231 udelay(10);
232
233 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
234 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
235 break;
236 }
237
238
239 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
240 hw_dbg(hw, "PHY address command did not complete.\n");
241 return IXGBE_ERR_PHY;
242 }
243
244 /* Address cycle complete, setup and write the read
245 * command
246 */
247 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
248 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
249 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
250 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
251
252 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
253
254 /* Check every 10 usec to see if the address cycle
255 * completed. The MDI Command bit will clear when the
256 * operation is complete
257 */
258 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
259 udelay(10);
260
261 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
262 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
263 break;
264 }
265
266 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
267 hw_dbg(hw, "PHY read command didn't complete\n");
268 return IXGBE_ERR_PHY;
269 }
270
271 /* Read operation is complete. Get the data
272 * from MSRWD
273 */
274 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
275 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
276 *phy_data = (u16)(data);
277
278 return 0;
279}
280
281/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700282 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000283 * using the SWFW lock - this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700284 * @hw: pointer to hardware structure
285 * @reg_addr: 32 bit address of PHY register to read
286 * @phy_data: Pointer to read data from PHY register
287 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700288s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
289 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700290{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000291 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700292 u16 gssr;
293
294 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
295 gssr = IXGBE_GSSR_PHY1_SM;
296 else
297 gssr = IXGBE_GSSR_PHY0_SM;
298
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000299 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
300 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
301 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000302 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000303 } else {
304 status = IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700305 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700306
Auke Kok9a799d72007-09-15 14:07:45 -0700307 return status;
308}
309
310/**
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000311 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
312 * without SWFW lock
313 * @hw: pointer to hardware structure
314 * @reg_addr: 32 bit PHY register to write
315 * @device_type: 5 bit device type
316 * @phy_data: Data to write to the PHY register
317 **/
318s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
319 u32 device_type, u16 phy_data)
320{
321 u32 i, command;
322
323 /* Put the data in the MDI single read and write data register*/
324 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
325
326 /* Setup and write the address cycle command */
327 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
328 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
329 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
330 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
331
332 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
333
334 /*
335 * Check every 10 usec to see if the address cycle completed.
336 * The MDI Command bit will clear when the operation is
337 * complete
338 */
339 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
340 udelay(10);
341
342 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
343 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
344 break;
345 }
346
347 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
348 hw_dbg(hw, "PHY address cmd didn't complete\n");
349 return IXGBE_ERR_PHY;
350 }
351
352 /*
353 * Address cycle complete, setup and write the write
354 * command
355 */
356 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
357 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
358 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
359 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
360
361 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
362
363 /* Check every 10 usec to see if the address cycle
364 * completed. The MDI Command bit will clear when the
365 * operation is complete
366 */
367 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
368 udelay(10);
369
370 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
371 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
372 break;
373 }
374
375 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
376 hw_dbg(hw, "PHY write cmd didn't complete\n");
377 return IXGBE_ERR_PHY;
378 }
379
380 return 0;
381}
382
383/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700384 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000385 * using SWFW lock- this function is needed in most cases
Auke Kok9a799d72007-09-15 14:07:45 -0700386 * @hw: pointer to hardware structure
387 * @reg_addr: 32 bit PHY register to write
388 * @device_type: 5 bit device type
389 * @phy_data: Data to write to the PHY register
390 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700391s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
392 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700393{
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000394 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700395 u16 gssr;
396
397 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
398 gssr = IXGBE_GSSR_PHY1_SM;
399 else
400 gssr = IXGBE_GSSR_PHY0_SM;
401
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000402 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
403 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
404 phy_data);
Don Skidmore5e655102011-02-25 01:58:04 +0000405 hw->mac.ops.release_swfw_sync(hw, gssr);
Emil Tantilov3dcc2f412013-05-29 06:23:05 +0000406 } else {
407 status = IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -0700408 }
409
410 return status;
411}
412
413/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700414 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700415 * @hw: pointer to hardware structure
416 *
417 * Restart autonegotiation and PHY and waits for completion.
418 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700419s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700420{
Emil Tantilov9dda1732011-03-05 01:28:07 +0000421 s32 status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700422 u32 time_out;
423 u32 max_time_out = 10;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000424 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
425 bool autoneg = false;
426 ixgbe_link_speed speed;
Auke Kok9a799d72007-09-15 14:07:45 -0700427
Emil Tantilov9dda1732011-03-05 01:28:07 +0000428 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700429
Emil Tantilov9dda1732011-03-05 01:28:07 +0000430 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
431 /* Set or unset auto-negotiation 10G advertisement */
432 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
433 MDIO_MMD_AN,
434 &autoneg_reg);
435
Ben Hutchings6b73e102009-04-29 08:08:58 +0000436 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000437 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
438 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700439
Emil Tantilov9dda1732011-03-05 01:28:07 +0000440 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
441 MDIO_MMD_AN,
442 autoneg_reg);
443 }
444
445 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
446 /* Set or unset auto-negotiation 1G advertisement */
447 hw->phy.ops.read_reg(hw,
448 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
449 MDIO_MMD_AN,
450 &autoneg_reg);
451
452 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
453 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
454 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
455
456 hw->phy.ops.write_reg(hw,
457 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
458 MDIO_MMD_AN,
459 autoneg_reg);
460 }
461
462 if (speed & IXGBE_LINK_SPEED_100_FULL) {
463 /* Set or unset auto-negotiation 100M advertisement */
464 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
465 MDIO_MMD_AN,
466 &autoneg_reg);
467
Emil Tantilova59e8a12011-03-31 09:36:12 +0000468 autoneg_reg &= ~(ADVERTISE_100FULL |
469 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000470 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
471 autoneg_reg |= ADVERTISE_100FULL;
472
473 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
474 MDIO_MMD_AN,
475 autoneg_reg);
476 }
Auke Kok9a799d72007-09-15 14:07:45 -0700477
478 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000479 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
480 MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700481
Ben Hutchings6b73e102009-04-29 08:08:58 +0000482 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700483
Emil Tantilov9dda1732011-03-05 01:28:07 +0000484 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
485 MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700486
487 /* Wait for autonegotiation to finish */
488 for (time_out = 0; time_out < max_time_out; time_out++) {
489 udelay(10);
490 /* Restart PHY autonegotiation and wait for completion */
Emil Tantilov9dda1732011-03-05 01:28:07 +0000491 status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
492 MDIO_MMD_AN,
493 &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700494
Ben Hutchings6b73e102009-04-29 08:08:58 +0000495 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
496 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700497 break;
498 }
499 }
500
Emil Tantilov9dda1732011-03-05 01:28:07 +0000501 if (time_out == max_time_out) {
Auke Kok9a799d72007-09-15 14:07:45 -0700502 status = IXGBE_ERR_LINK_SETUP;
Emil Tantilov9dda1732011-03-05 01:28:07 +0000503 hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out");
504 }
Auke Kok9a799d72007-09-15 14:07:45 -0700505
506 return status;
507}
508
509/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700510 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700511 * @hw: pointer to hardware structure
512 * @speed: new link speed
Auke Kok9a799d72007-09-15 14:07:45 -0700513 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700514s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
515 ixgbe_link_speed speed,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700516 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700517{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700518
Auke Kok9a799d72007-09-15 14:07:45 -0700519 /*
520 * Clear autoneg_advertised and set new values based on input link
521 * speed.
522 */
523 hw->phy.autoneg_advertised = 0;
524
525 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
526 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700527
Auke Kok9a799d72007-09-15 14:07:45 -0700528 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
529 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
530
Emil Tantilov9dda1732011-03-05 01:28:07 +0000531 if (speed & IXGBE_LINK_SPEED_100_FULL)
532 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
533
Auke Kok9a799d72007-09-15 14:07:45 -0700534 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700535 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700536
537 return 0;
538}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700539
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700540/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800541 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
542 * @hw: pointer to hardware structure
543 * @speed: pointer to link speed
544 * @autoneg: boolean auto-negotiation value
545 *
546 * Determines the link capabilities by reading the AUTOC register.
547 */
548s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800549 ixgbe_link_speed *speed,
550 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800551{
552 s32 status = IXGBE_ERR_LINK_SETUP;
553 u16 speed_ability;
554
555 *speed = 0;
556 *autoneg = true;
557
558 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
559 &speed_ability);
560
561 if (status == 0) {
562 if (speed_ability & MDIO_SPEED_10G)
563 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
564 if (speed_ability & MDIO_PMA_SPEED_1000)
565 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
566 if (speed_ability & MDIO_PMA_SPEED_100)
567 *speed |= IXGBE_LINK_SPEED_100_FULL;
568 }
569
570 return status;
571}
572
573/**
Emil Tantilov9dda1732011-03-05 01:28:07 +0000574 * ixgbe_check_phy_link_tnx - Determine link and speed status
575 * @hw: pointer to hardware structure
576 *
577 * Reads the VS1 register to determine if link is up and the current speed for
578 * the PHY.
579 **/
580s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
581 bool *link_up)
582{
583 s32 status = 0;
584 u32 time_out;
585 u32 max_time_out = 10;
586 u16 phy_link = 0;
587 u16 phy_speed = 0;
588 u16 phy_data = 0;
589
590 /* Initialize speed and link to default case */
591 *link_up = false;
592 *speed = IXGBE_LINK_SPEED_10GB_FULL;
593
594 /*
595 * Check current speed and link status of the PHY register.
596 * This is a vendor specific register and may have to
597 * be changed for other copper PHYs.
598 */
599 for (time_out = 0; time_out < max_time_out; time_out++) {
600 udelay(10);
601 status = hw->phy.ops.read_reg(hw,
602 MDIO_STAT1,
603 MDIO_MMD_VEND1,
604 &phy_data);
605 phy_link = phy_data &
606 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
607 phy_speed = phy_data &
608 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
609 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
610 *link_up = true;
611 if (phy_speed ==
612 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
613 *speed = IXGBE_LINK_SPEED_1GB_FULL;
614 break;
615 }
616 }
617
618 return status;
619}
620
621/**
622 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
623 * @hw: pointer to hardware structure
624 *
625 * Restart autonegotiation and PHY and waits for completion.
626 **/
627s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
628{
629 s32 status = 0;
630 u32 time_out;
631 u32 max_time_out = 10;
632 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
633 bool autoneg = false;
634 ixgbe_link_speed speed;
635
636 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
637
638 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
639 /* Set or unset auto-negotiation 10G advertisement */
640 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
641 MDIO_MMD_AN,
642 &autoneg_reg);
643
644 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
645 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
646 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
647
648 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
649 MDIO_MMD_AN,
650 autoneg_reg);
651 }
652
653 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
654 /* Set or unset auto-negotiation 1G advertisement */
655 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
656 MDIO_MMD_AN,
657 &autoneg_reg);
658
659 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
660 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
661 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
662
663 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
664 MDIO_MMD_AN,
665 autoneg_reg);
666 }
667
668 if (speed & IXGBE_LINK_SPEED_100_FULL) {
669 /* Set or unset auto-negotiation 100M advertisement */
670 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
671 MDIO_MMD_AN,
672 &autoneg_reg);
673
Emil Tantilov50c022e2011-03-31 09:36:12 +0000674 autoneg_reg &= ~(ADVERTISE_100FULL |
675 ADVERTISE_100HALF);
Emil Tantilov9dda1732011-03-05 01:28:07 +0000676 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
677 autoneg_reg |= ADVERTISE_100FULL;
678
679 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
680 MDIO_MMD_AN,
681 autoneg_reg);
682 }
683
684 /* Restart PHY autonegotiation and wait for completion */
685 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
686 MDIO_MMD_AN, &autoneg_reg);
687
688 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
689
690 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
691 MDIO_MMD_AN, autoneg_reg);
692
693 /* Wait for autonegotiation to finish */
694 for (time_out = 0; time_out < max_time_out; time_out++) {
695 udelay(10);
696 /* Restart PHY autonegotiation and wait for completion */
697 status = hw->phy.ops.read_reg(hw, MDIO_STAT1,
698 MDIO_MMD_AN,
699 &autoneg_reg);
700
701 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
702 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE)
703 break;
704 }
705
706 if (time_out == max_time_out) {
707 status = IXGBE_ERR_LINK_SETUP;
708 hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out");
709 }
710
711 return status;
712}
713
714/**
715 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
716 * @hw: pointer to hardware structure
717 * @firmware_version: pointer to the PHY Firmware Version
718 **/
719s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
720 u16 *firmware_version)
721{
722 s32 status = 0;
723
724 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
725 MDIO_MMD_VEND1,
726 firmware_version);
727
728 return status;
729}
730
731/**
732 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
733 * @hw: pointer to hardware structure
734 * @firmware_version: pointer to the PHY Firmware Version
735 **/
736s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
737 u16 *firmware_version)
738{
739 s32 status = 0;
740
741 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
742 MDIO_MMD_VEND1,
743 firmware_version);
744
745 return status;
746}
747
748/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800749 * ixgbe_reset_phy_nl - Performs a PHY reset
750 * @hw: pointer to hardware structure
751 **/
752s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
753{
754 u16 phy_offset, control, eword, edata, block_crc;
755 bool end_data = false;
756 u16 list_offset, data_offset;
757 u16 phy_data = 0;
758 s32 ret_val = 0;
759 u32 i;
760
Ben Hutchings6b73e102009-04-29 08:08:58 +0000761 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800762
763 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000764 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
765 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800766
767 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000768 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
769 &phy_data);
770 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800771 break;
Don Skidmore032b4322011-03-18 09:32:53 +0000772 usleep_range(10000, 20000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800773 }
774
Ben Hutchings6b73e102009-04-29 08:08:58 +0000775 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800776 hw_dbg(hw, "PHY reset did not complete.\n");
777 ret_val = IXGBE_ERR_PHY;
778 goto out;
779 }
780
781 /* Get init offsets */
782 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
783 &data_offset);
784 if (ret_val != 0)
785 goto out;
786
787 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
788 data_offset++;
789 while (!end_data) {
790 /*
791 * Read control word from PHY init contents offset
792 */
793 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
794 control = (eword & IXGBE_CONTROL_MASK_NL) >>
795 IXGBE_CONTROL_SHIFT_NL;
796 edata = eword & IXGBE_DATA_MASK_NL;
797 switch (control) {
798 case IXGBE_DELAY_NL:
799 data_offset++;
800 hw_dbg(hw, "DELAY: %d MS\n", edata);
Don Skidmore032b4322011-03-18 09:32:53 +0000801 usleep_range(edata * 1000, edata * 2000);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800802 break;
803 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000804 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800805 data_offset++;
806 hw->eeprom.ops.read(hw, data_offset++,
807 &phy_offset);
808 for (i = 0; i < edata; i++) {
809 hw->eeprom.ops.read(hw, data_offset, &eword);
810 hw->phy.ops.write_reg(hw, phy_offset,
Ben Hutchings6b73e102009-04-29 08:08:58 +0000811 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800812 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
813 phy_offset);
814 data_offset++;
815 phy_offset++;
816 }
817 break;
818 case IXGBE_CONTROL_NL:
819 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +0000820 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800821 if (edata == IXGBE_CONTROL_EOL_NL) {
822 hw_dbg(hw, "EOL\n");
823 end_data = true;
824 } else if (edata == IXGBE_CONTROL_SOL_NL) {
825 hw_dbg(hw, "SOL\n");
826 } else {
827 hw_dbg(hw, "Bad control value\n");
828 ret_val = IXGBE_ERR_PHY;
829 goto out;
830 }
831 break;
832 default:
833 hw_dbg(hw, "Bad control type\n");
834 ret_val = IXGBE_ERR_PHY;
835 goto out;
836 }
837 }
838
839out:
840 return ret_val;
841}
842
843/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000844 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
Donald Skidmorec4900be2008-11-20 21:11:42 -0800845 * @hw: pointer to hardware structure
846 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000847 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -0800848 **/
849s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
850{
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000851 struct ixgbe_adapter *adapter = hw->back;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800852 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
853 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000854 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800855 u8 identifier = 0;
856 u8 comp_codes_1g = 0;
857 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000858 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000859 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000860 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000861 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800862
Don Skidmore8ca783a2009-05-26 20:40:47 -0700863 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
864 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
865 status = IXGBE_ERR_SFP_NOT_PRESENT;
866 goto out;
867 }
868
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000869 status = hw->phy.ops.read_i2c_eeprom(hw,
870 IXGBE_SFF_IDENTIFIER,
Emil Tantilov51d04202013-01-18 02:17:11 +0000871 &identifier);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800872
Emil Tantilov51d04202013-01-18 02:17:11 +0000873 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000874 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800875
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000876 /* LAN ID is needed for sfp_type determination */
877 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800878
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000879 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
880 hw->phy.type = ixgbe_phy_sfp_unsupported;
881 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
882 } else {
883 status = hw->phy.ops.read_i2c_eeprom(hw,
884 IXGBE_SFF_1GBE_COMP_CODES,
885 &comp_codes_1g);
886
Emil Tantilov51d04202013-01-18 02:17:11 +0000887 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000888 goto err_read_i2c_eeprom;
889
890 status = hw->phy.ops.read_i2c_eeprom(hw,
891 IXGBE_SFF_10GBE_COMP_CODES,
892 &comp_codes_10g);
893
Emil Tantilov51d04202013-01-18 02:17:11 +0000894 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000895 goto err_read_i2c_eeprom;
896 status = hw->phy.ops.read_i2c_eeprom(hw,
897 IXGBE_SFF_CABLE_TECHNOLOGY,
898 &cable_tech);
899
Emil Tantilov51d04202013-01-18 02:17:11 +0000900 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000901 goto err_read_i2c_eeprom;
902
903 /* ID Module
904 * =========
905 * 0 SFP_DA_CU
906 * 1 SFP_SR
907 * 2 SFP_LR
908 * 3 SFP_DA_CORE0 - 82599-specific
909 * 4 SFP_DA_CORE1 - 82599-specific
910 * 5 SFP_SR/LR_CORE0 - 82599-specific
911 * 6 SFP_SR/LR_CORE1 - 82599-specific
912 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
913 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
914 * 9 SFP_1g_cu_CORE0 - 82599-specific
915 * 10 SFP_1g_cu_CORE1 - 82599-specific
Jacob Kellera49fda32012-06-08 06:59:09 +0000916 * 11 SFP_1g_sx_CORE0 - 82599-specific
917 * 12 SFP_1g_sx_CORE1 - 82599-specific
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000918 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000919 if (hw->mac.type == ixgbe_mac_82598EB) {
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000920 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000921 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
922 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
923 hw->phy.sfp_type = ixgbe_sfp_type_sr;
924 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
925 hw->phy.sfp_type = ixgbe_sfp_type_lr;
926 else
927 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
928 } else if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000929 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000930 if (hw->bus.lan_id == 0)
931 hw->phy.sfp_type =
932 ixgbe_sfp_type_da_cu_core0;
933 else
934 hw->phy.sfp_type =
935 ixgbe_sfp_type_da_cu_core1;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000936 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
937 hw->phy.ops.read_i2c_eeprom(
938 hw, IXGBE_SFF_CABLE_SPEC_COMP,
939 &cable_spec);
940 if (cable_spec &
941 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
942 if (hw->bus.lan_id == 0)
943 hw->phy.sfp_type =
944 ixgbe_sfp_type_da_act_lmt_core0;
945 else
946 hw->phy.sfp_type =
947 ixgbe_sfp_type_da_act_lmt_core1;
948 } else {
949 hw->phy.sfp_type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000950 ixgbe_sfp_type_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000951 }
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000952 } else if (comp_codes_10g &
953 (IXGBE_SFF_10GBASESR_CAPABLE |
954 IXGBE_SFF_10GBASELR_CAPABLE)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000955 if (hw->bus.lan_id == 0)
956 hw->phy.sfp_type =
957 ixgbe_sfp_type_srlr_core0;
958 else
959 hw->phy.sfp_type =
960 ixgbe_sfp_type_srlr_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000961 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
Don Skidmorecb836a92010-06-29 18:30:59 +0000962 if (hw->bus.lan_id == 0)
963 hw->phy.sfp_type =
964 ixgbe_sfp_type_1g_cu_core0;
965 else
966 hw->phy.sfp_type =
967 ixgbe_sfp_type_1g_cu_core1;
Jacob Kellera49fda32012-06-08 06:59:09 +0000968 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
969 if (hw->bus.lan_id == 0)
970 hw->phy.sfp_type =
971 ixgbe_sfp_type_1g_sx_core0;
972 else
973 hw->phy.sfp_type =
974 ixgbe_sfp_type_1g_sx_core1;
Don Skidmore345be202013-04-11 06:23:34 +0000975 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
976 if (hw->bus.lan_id == 0)
977 hw->phy.sfp_type =
978 ixgbe_sfp_type_1g_lx_core0;
979 else
980 hw->phy.sfp_type =
981 ixgbe_sfp_type_1g_lx_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000982 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000983 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000984 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000985 }
Donald Skidmorec4900be2008-11-20 21:11:42 -0800986
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000987 if (hw->phy.sfp_type != stored_sfp_type)
988 hw->phy.sfp_setup_needed = true;
989
990 /* Determine if the SFP+ PHY is dual speed or not. */
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +0000991 hw->phy.multispeed_fiber = false;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000992 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
993 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
994 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
995 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
996 hw->phy.multispeed_fiber = true;
997
Donald Skidmorec4900be2008-11-20 21:11:42 -0800998 /* Determine PHY vendor */
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +0000999 if (hw->phy.type != ixgbe_phy_nl) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001000 hw->phy.id = identifier;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001001 status = hw->phy.ops.read_i2c_eeprom(hw,
Emil Tantilov51d04202013-01-18 02:17:11 +00001002 IXGBE_SFF_VENDOR_OUI_BYTE0,
1003 &oui_bytes[0]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001004
Emil Tantilov51d04202013-01-18 02:17:11 +00001005 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001006 goto err_read_i2c_eeprom;
1007
1008 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -08001009 IXGBE_SFF_VENDOR_OUI_BYTE1,
1010 &oui_bytes[1]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001011
Emil Tantilov51d04202013-01-18 02:17:11 +00001012 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001013 goto err_read_i2c_eeprom;
1014
1015 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -08001016 IXGBE_SFF_VENDOR_OUI_BYTE2,
1017 &oui_bytes[2]);
1018
Emil Tantilov51d04202013-01-18 02:17:11 +00001019 if (status != 0)
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001020 goto err_read_i2c_eeprom;
1021
Donald Skidmorec4900be2008-11-20 21:11:42 -08001022 vendor_oui =
1023 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1024 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1025 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1026
1027 switch (vendor_oui) {
1028 case IXGBE_SFF_VENDOR_OUI_TYCO:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001029 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001030 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001031 ixgbe_phy_sfp_passive_tyco;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001032 break;
1033 case IXGBE_SFF_VENDOR_OUI_FTL:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001034 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1035 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1036 else
1037 hw->phy.type = ixgbe_phy_sfp_ftl;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001038 break;
1039 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1040 hw->phy.type = ixgbe_phy_sfp_avago;
1041 break;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001042 case IXGBE_SFF_VENDOR_OUI_INTEL:
1043 hw->phy.type = ixgbe_phy_sfp_intel;
1044 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001045 default:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +00001046 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001047 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001048 ixgbe_phy_sfp_passive_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001049 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1050 hw->phy.type =
1051 ixgbe_phy_sfp_active_unknown;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001052 else
1053 hw->phy.type = ixgbe_phy_sfp_unknown;
1054 break;
1055 }
1056 }
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001057
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001058 /* Allow any DA cable vendor */
Don Skidmoreea0a04d2010-05-18 16:00:13 +00001059 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1060 IXGBE_SFF_DA_ACTIVE_CABLE)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001061 status = 0;
1062 goto out;
1063 }
1064
Don Skidmorecb836a92010-06-29 18:30:59 +00001065 /* Verify supported 1G SFP modules */
1066 if (comp_codes_10g == 0 &&
1067 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001068 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001069 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1070 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001071 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1072 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +00001073 hw->phy.type = ixgbe_phy_sfp_unsupported;
1074 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1075 goto out;
1076 }
1077
1078 /* Anything else 82598-based is supported */
1079 if (hw->mac.type == ixgbe_mac_82598EB) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001080 status = 0;
1081 goto out;
1082 }
1083
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +00001084 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
Don Skidmorecb836a92010-06-29 18:30:59 +00001085 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
Don Skidmore345be202013-04-11 06:23:34 +00001086 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1087 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1088 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1089 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1090 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1091 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001092 /* Make sure we're a supported PHY type */
1093 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1094 status = 0;
1095 } else {
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00001096 if (hw->allow_unsupported_sfp) {
1097 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.");
1098 status = 0;
1099 } else {
1100 hw_dbg(hw,
1101 "SFP+ module not supported\n");
1102 hw->phy.type =
1103 ixgbe_phy_sfp_unsupported;
1104 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1105 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001106 }
1107 } else {
1108 status = 0;
1109 }
Donald Skidmorec4900be2008-11-20 21:11:42 -08001110 }
1111
1112out:
1113 return status;
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001114
1115err_read_i2c_eeprom:
1116 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1117 if (hw->phy.type != ixgbe_phy_nl) {
1118 hw->phy.id = 0;
1119 hw->phy.type = ixgbe_phy_unknown;
1120 }
1121 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001122}
1123
1124/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +00001125 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -08001126 * @hw: pointer to hardware structure
1127 * @list_offset: offset to the SFP ID list
1128 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +00001129 *
1130 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1131 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -08001132 **/
1133s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1134 u16 *list_offset,
1135 u16 *data_offset)
1136{
1137 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +00001138 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001139
1140 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1141 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1142
1143 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1144 return IXGBE_ERR_SFP_NOT_PRESENT;
1145
1146 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1147 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1148 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1149
Don Skidmorecb836a92010-06-29 18:30:59 +00001150 /*
1151 * Limiting active cables and 1G Phys must be initialized as
1152 * SR modules
1153 */
1154 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
Don Skidmore345be202013-04-11 06:23:34 +00001155 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001156 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1157 sfp_type == ixgbe_sfp_type_1g_sx_core0)
Don Skidmorecb836a92010-06-29 18:30:59 +00001158 sfp_type = ixgbe_sfp_type_srlr_core0;
1159 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +00001160 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +00001161 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1162 sfp_type == ixgbe_sfp_type_1g_sx_core1)
Don Skidmorecb836a92010-06-29 18:30:59 +00001163 sfp_type = ixgbe_sfp_type_srlr_core1;
1164
Donald Skidmorec4900be2008-11-20 21:11:42 -08001165 /* Read offset to PHY init contents */
1166 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
1167
1168 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001169 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -08001170
1171 /* Shift offset to first ID word */
1172 (*list_offset)++;
1173
1174 /*
1175 * Find the matching SFP ID in the EEPROM
1176 * and program the init sequence
1177 */
1178 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
1179
1180 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +00001181 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -08001182 (*list_offset)++;
1183 hw->eeprom.ops.read(hw, *list_offset, data_offset);
1184 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1185 hw_dbg(hw, "SFP+ module not supported\n");
1186 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1187 } else {
1188 break;
1189 }
1190 } else {
1191 (*list_offset) += 2;
1192 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1193 return IXGBE_ERR_PHY;
1194 }
1195 }
1196
1197 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1198 hw_dbg(hw, "No matching SFP+ module found\n");
1199 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1200 }
1201
1202 return 0;
1203}
1204
1205/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001206 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1207 * @hw: pointer to hardware structure
1208 * @byte_offset: EEPROM byte offset to read
1209 * @eeprom_data: value read
1210 *
1211 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1212 **/
1213s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1214 u8 *eeprom_data)
1215{
1216 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1217 IXGBE_I2C_EEPROM_DEV_ADDR,
1218 eeprom_data);
1219}
1220
1221/**
Emil Tantilov07ce8702012-12-19 07:14:17 +00001222 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1223 * @hw: pointer to hardware structure
1224 * @byte_offset: byte offset at address 0xA2
1225 * @eeprom_data: value read
1226 *
1227 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1228 **/
1229s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1230 u8 *sff8472_data)
1231{
1232 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1233 IXGBE_I2C_EEPROM_DEV_ADDR2,
1234 sff8472_data);
1235}
1236
1237/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001238 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1239 * @hw: pointer to hardware structure
1240 * @byte_offset: EEPROM byte offset to write
1241 * @eeprom_data: value to write
1242 *
1243 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1244 **/
1245s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1246 u8 eeprom_data)
1247{
1248 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1249 IXGBE_I2C_EEPROM_DEV_ADDR,
1250 eeprom_data);
1251}
1252
1253/**
1254 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1255 * @hw: pointer to hardware structure
1256 * @byte_offset: byte offset to read
1257 * @data: value read
1258 *
1259 * Performs byte read operation to SFP module's EEPROM over I2C interface at
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001260 * a specified device address.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001261 **/
1262s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1263 u8 dev_addr, u8 *data)
1264{
1265 s32 status = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001266 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001267 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001268 u16 swfw_mask = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001269 bool nack = true;
Emil Tantilov3fbaa3a2011-08-30 13:33:51 +00001270 *data = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001271
Emil Tantilov75f19c32011-02-19 08:43:55 +00001272 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1273 swfw_mask = IXGBE_GSSR_PHY1_SM;
1274 else
1275 swfw_mask = IXGBE_GSSR_PHY0_SM;
1276
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001277 do {
Emil Tantilov6d980c32011-04-13 04:56:15 +00001278 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
Emil Tantilov75f19c32011-02-19 08:43:55 +00001279 status = IXGBE_ERR_SWFW_SYNC;
1280 goto read_byte_out;
1281 }
1282
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001283 ixgbe_i2c_start(hw);
1284
1285 /* Device Address and write indication */
1286 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1287 if (status != 0)
1288 goto fail;
1289
1290 status = ixgbe_get_i2c_ack(hw);
1291 if (status != 0)
1292 goto fail;
1293
1294 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1295 if (status != 0)
1296 goto fail;
1297
1298 status = ixgbe_get_i2c_ack(hw);
1299 if (status != 0)
1300 goto fail;
1301
1302 ixgbe_i2c_start(hw);
1303
1304 /* Device Address and read indication */
1305 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1306 if (status != 0)
1307 goto fail;
1308
1309 status = ixgbe_get_i2c_ack(hw);
1310 if (status != 0)
1311 goto fail;
1312
1313 status = ixgbe_clock_in_i2c_byte(hw, data);
1314 if (status != 0)
1315 goto fail;
1316
1317 status = ixgbe_clock_out_i2c_bit(hw, nack);
1318 if (status != 0)
1319 goto fail;
1320
1321 ixgbe_i2c_stop(hw);
1322 break;
1323
1324fail:
Emil Tantilovd0310dc2013-01-18 02:16:41 +00001325 ixgbe_i2c_bus_clear(hw);
Emil Tantilov6d980c32011-04-13 04:56:15 +00001326 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001327 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001328 retry++;
1329 if (retry < max_retry)
1330 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1331 else
1332 hw_dbg(hw, "I2C byte read error.\n");
1333
1334 } while (retry < max_retry);
1335
Emil Tantilov6d980c32011-04-13 04:56:15 +00001336 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001337
1338read_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001339 return status;
1340}
1341
1342/**
1343 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1344 * @hw: pointer to hardware structure
1345 * @byte_offset: byte offset to write
1346 * @data: value to write
1347 *
1348 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1349 * a specified device address.
1350 **/
1351s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1352 u8 dev_addr, u8 data)
1353{
1354 s32 status = 0;
1355 u32 max_retry = 1;
1356 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001357 u16 swfw_mask = 0;
1358
1359 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1360 swfw_mask = IXGBE_GSSR_PHY1_SM;
1361 else
1362 swfw_mask = IXGBE_GSSR_PHY0_SM;
1363
Emil Tantilov6d980c32011-04-13 04:56:15 +00001364 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != 0) {
Emil Tantilov75f19c32011-02-19 08:43:55 +00001365 status = IXGBE_ERR_SWFW_SYNC;
1366 goto write_byte_out;
1367 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001368
1369 do {
1370 ixgbe_i2c_start(hw);
1371
1372 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1373 if (status != 0)
1374 goto fail;
1375
1376 status = ixgbe_get_i2c_ack(hw);
1377 if (status != 0)
1378 goto fail;
1379
1380 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1381 if (status != 0)
1382 goto fail;
1383
1384 status = ixgbe_get_i2c_ack(hw);
1385 if (status != 0)
1386 goto fail;
1387
1388 status = ixgbe_clock_out_i2c_byte(hw, data);
1389 if (status != 0)
1390 goto fail;
1391
1392 status = ixgbe_get_i2c_ack(hw);
1393 if (status != 0)
1394 goto fail;
1395
1396 ixgbe_i2c_stop(hw);
1397 break;
1398
1399fail:
1400 ixgbe_i2c_bus_clear(hw);
1401 retry++;
1402 if (retry < max_retry)
1403 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1404 else
1405 hw_dbg(hw, "I2C byte write error.\n");
1406 } while (retry < max_retry);
1407
Emil Tantilov6d980c32011-04-13 04:56:15 +00001408 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Emil Tantilov75f19c32011-02-19 08:43:55 +00001409
1410write_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001411 return status;
1412}
1413
1414/**
1415 * ixgbe_i2c_start - Sets I2C start condition
1416 * @hw: pointer to hardware structure
1417 *
1418 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1419 **/
1420static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1421{
1422 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1423
1424 /* Start condition must begin with data and clock high */
1425 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1426 ixgbe_raise_i2c_clk(hw, &i2cctl);
1427
1428 /* Setup time for start condition (4.7us) */
1429 udelay(IXGBE_I2C_T_SU_STA);
1430
1431 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1432
1433 /* Hold time for start condition (4us) */
1434 udelay(IXGBE_I2C_T_HD_STA);
1435
1436 ixgbe_lower_i2c_clk(hw, &i2cctl);
1437
1438 /* Minimum low period of clock is 4.7 us */
1439 udelay(IXGBE_I2C_T_LOW);
1440
1441}
1442
1443/**
1444 * ixgbe_i2c_stop - Sets I2C stop condition
1445 * @hw: pointer to hardware structure
1446 *
1447 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1448 **/
1449static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1450{
1451 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1452
1453 /* Stop condition must begin with data low and clock high */
1454 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1455 ixgbe_raise_i2c_clk(hw, &i2cctl);
1456
1457 /* Setup time for stop condition (4us) */
1458 udelay(IXGBE_I2C_T_SU_STO);
1459
1460 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1461
1462 /* bus free time between stop and start (4.7us)*/
1463 udelay(IXGBE_I2C_T_BUF);
1464}
1465
1466/**
1467 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1468 * @hw: pointer to hardware structure
1469 * @data: data byte to clock in
1470 *
1471 * Clocks in one byte data via I2C data/clock
1472 **/
1473static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1474{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001475 s32 i;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001476 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001477
1478 for (i = 7; i >= 0; i--) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001479 ixgbe_clock_in_i2c_bit(hw, &bit);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001480 *data |= bit << i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001481 }
1482
Emil Tantilove1befd72011-08-27 07:18:47 +00001483 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001484}
1485
1486/**
1487 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1488 * @hw: pointer to hardware structure
1489 * @data: data byte clocked out
1490 *
1491 * Clocks out one byte data via I2C data/clock
1492 **/
1493static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1494{
1495 s32 status = 0;
1496 s32 i;
1497 u32 i2cctl;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001498 bool bit = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001499
1500 for (i = 7; i >= 0; i--) {
1501 bit = (data >> i) & 0x1;
1502 status = ixgbe_clock_out_i2c_bit(hw, bit);
1503
1504 if (status != 0)
1505 break;
1506 }
1507
1508 /* Release SDA line (set high) */
1509 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1510 i2cctl |= IXGBE_I2C_DATA_OUT;
1511 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
Emil Tantilov176f9502011-11-04 06:43:23 +00001512 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001513
1514 return status;
1515}
1516
1517/**
1518 * ixgbe_get_i2c_ack - Polls for I2C ACK
1519 * @hw: pointer to hardware structure
1520 *
1521 * Clocks in/out one bit via I2C data/clock
1522 **/
1523static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1524{
Emil Tantilove1befd72011-08-27 07:18:47 +00001525 s32 status = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001526 u32 i = 0;
1527 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1528 u32 timeout = 10;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001529 bool ack = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001530
Emil Tantilove1befd72011-08-27 07:18:47 +00001531 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001532
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001533
1534 /* Minimum high period of clock is 4us */
1535 udelay(IXGBE_I2C_T_HIGH);
1536
1537 /* Poll for ACK. Note that ACK in I2C spec is
1538 * transition from 1 to 0 */
1539 for (i = 0; i < timeout; i++) {
1540 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1541 ack = ixgbe_get_i2c_data(&i2cctl);
1542
1543 udelay(1);
1544 if (ack == 0)
1545 break;
1546 }
1547
1548 if (ack == 1) {
1549 hw_dbg(hw, "I2C ack was not received.\n");
1550 status = IXGBE_ERR_I2C;
1551 }
1552
1553 ixgbe_lower_i2c_clk(hw, &i2cctl);
1554
1555 /* Minimum low period of clock is 4.7 us */
1556 udelay(IXGBE_I2C_T_LOW);
1557
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001558 return status;
1559}
1560
1561/**
1562 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1563 * @hw: pointer to hardware structure
1564 * @data: read data value
1565 *
1566 * Clocks in one bit via I2C data/clock
1567 **/
1568static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1569{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001570 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1571
Emil Tantilove1befd72011-08-27 07:18:47 +00001572 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001573
1574 /* Minimum high period of clock is 4us */
1575 udelay(IXGBE_I2C_T_HIGH);
1576
1577 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1578 *data = ixgbe_get_i2c_data(&i2cctl);
1579
1580 ixgbe_lower_i2c_clk(hw, &i2cctl);
1581
1582 /* Minimum low period of clock is 4.7 us */
1583 udelay(IXGBE_I2C_T_LOW);
1584
Emil Tantilove1befd72011-08-27 07:18:47 +00001585 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001586}
1587
1588/**
1589 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1590 * @hw: pointer to hardware structure
1591 * @data: data value to write
1592 *
1593 * Clocks out one bit via I2C data/clock
1594 **/
1595static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1596{
1597 s32 status;
1598 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1599
1600 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1601 if (status == 0) {
Emil Tantilove1befd72011-08-27 07:18:47 +00001602 ixgbe_raise_i2c_clk(hw, &i2cctl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001603
1604 /* Minimum high period of clock is 4us */
1605 udelay(IXGBE_I2C_T_HIGH);
1606
1607 ixgbe_lower_i2c_clk(hw, &i2cctl);
1608
1609 /* Minimum low period of clock is 4.7 us.
1610 * This also takes care of the data hold time.
1611 */
1612 udelay(IXGBE_I2C_T_LOW);
1613 } else {
1614 status = IXGBE_ERR_I2C;
1615 hw_dbg(hw, "I2C data was not set to %X\n", data);
1616 }
1617
1618 return status;
1619}
1620/**
1621 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1622 * @hw: pointer to hardware structure
1623 * @i2cctl: Current value of I2CCTL register
1624 *
1625 * Raises the I2C clock line '0'->'1'
1626 **/
Emil Tantilove1befd72011-08-27 07:18:47 +00001627static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001628{
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001629 u32 i = 0;
1630 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1631 u32 i2cctl_r = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001632
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001633 for (i = 0; i < timeout; i++) {
1634 *i2cctl |= IXGBE_I2C_CLK_OUT;
1635 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1636 IXGBE_WRITE_FLUSH(hw);
1637 /* SCL rise time (1000ns) */
1638 udelay(IXGBE_I2C_T_RISE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001639
Don Skidmore8f56e4b2012-03-15 07:36:37 +00001640 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1641 if (i2cctl_r & IXGBE_I2C_CLK_IN)
1642 break;
1643 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001644}
1645
1646/**
1647 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1648 * @hw: pointer to hardware structure
1649 * @i2cctl: Current value of I2CCTL register
1650 *
1651 * Lowers the I2C clock line '1'->'0'
1652 **/
1653static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1654{
1655
1656 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1657
1658 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001659 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001660
1661 /* SCL fall time (300ns) */
1662 udelay(IXGBE_I2C_T_FALL);
1663}
1664
1665/**
1666 * ixgbe_set_i2c_data - Sets the I2C data bit
1667 * @hw: pointer to hardware structure
1668 * @i2cctl: Current value of I2CCTL register
1669 * @data: I2C data value (0 or 1) to set
1670 *
1671 * Sets the I2C data bit
1672 **/
1673static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1674{
1675 s32 status = 0;
1676
1677 if (data)
1678 *i2cctl |= IXGBE_I2C_DATA_OUT;
1679 else
1680 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1681
1682 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001683 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001684
1685 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1686 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1687
1688 /* Verify data was set correctly */
1689 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1690 if (data != ixgbe_get_i2c_data(i2cctl)) {
1691 status = IXGBE_ERR_I2C;
1692 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1693 }
1694
1695 return status;
1696}
1697
1698/**
1699 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1700 * @hw: pointer to hardware structure
1701 * @i2cctl: Current value of I2CCTL register
1702 *
1703 * Returns the I2C data bit value
1704 **/
1705static bool ixgbe_get_i2c_data(u32 *i2cctl)
1706{
1707 bool data;
1708
1709 if (*i2cctl & IXGBE_I2C_DATA_IN)
Rusty Russell3db1cd52011-12-19 13:56:45 +00001710 data = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001711 else
Rusty Russell3db1cd52011-12-19 13:56:45 +00001712 data = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001713
1714 return data;
1715}
1716
1717/**
1718 * ixgbe_i2c_bus_clear - Clears the I2C bus
1719 * @hw: pointer to hardware structure
1720 *
1721 * Clears the I2C bus by sending nine clock pulses.
1722 * Used when data line is stuck low.
1723 **/
1724static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1725{
1726 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1727 u32 i;
1728
Emil Tantilov75f19c32011-02-19 08:43:55 +00001729 ixgbe_i2c_start(hw);
1730
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001731 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1732
1733 for (i = 0; i < 9; i++) {
1734 ixgbe_raise_i2c_clk(hw, &i2cctl);
1735
1736 /* Min high period of clock is 4us */
1737 udelay(IXGBE_I2C_T_HIGH);
1738
1739 ixgbe_lower_i2c_clk(hw, &i2cctl);
1740
1741 /* Min low period of clock is 4.7us*/
1742 udelay(IXGBE_I2C_T_LOW);
1743 }
1744
Emil Tantilov75f19c32011-02-19 08:43:55 +00001745 ixgbe_i2c_start(hw);
1746
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001747 /* Put the i2c bus back to default state */
1748 ixgbe_i2c_stop(hw);
1749}
1750
1751/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001752 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001753 * @hw: pointer to hardware structure
1754 *
1755 * Checks if the LASI temp alarm status was triggered due to overtemp
1756 **/
1757s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1758{
1759 s32 status = 0;
1760 u16 phy_data = 0;
1761
1762 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
1763 goto out;
1764
1765 /* Check that the LASI temp alarm status was triggered */
1766 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
1767 MDIO_MMD_PMAPMD, &phy_data);
1768
1769 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
1770 goto out;
1771
1772 status = IXGBE_ERR_OVERTEMP;
1773out:
1774 return status;
1775}