blob: 9190a8fca4273cd533560f2d6f294f088b423c69 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 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);
42static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
43static 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/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700207 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
Auke Kok9a799d72007-09-15 14:07:45 -0700208 * @hw: pointer to hardware structure
209 * @reg_addr: 32 bit address of PHY register to read
210 * @phy_data: Pointer to read data from PHY register
211 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700212s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
213 u32 device_type, u16 *phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700214{
215 u32 command;
216 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -0700217 u32 data;
218 s32 status = 0;
219 u16 gssr;
220
221 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
222 gssr = IXGBE_GSSR_PHY1_SM;
223 else
224 gssr = IXGBE_GSSR_PHY0_SM;
225
Don Skidmore5e655102011-02-25 01:58:04 +0000226 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0)
Auke Kok9a799d72007-09-15 14:07:45 -0700227 status = IXGBE_ERR_SWFW_SYNC;
228
229 if (status == 0) {
230 /* Setup and write the address cycle command */
231 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700232 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
Ben Hutchings6b73e102009-04-29 08:08:58 +0000233 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700234 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
Auke Kok9a799d72007-09-15 14:07:45 -0700235
236 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
237
238 /*
239 * Check every 10 usec to see if the address cycle completed.
240 * The MDI Command bit will clear when the operation is
241 * complete
242 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700243 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -0700244 udelay(10);
245
246 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
247
248 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
249 break;
250 }
251
252 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
253 hw_dbg(hw, "PHY address command did not complete.\n");
254 status = IXGBE_ERR_PHY;
255 }
256
257 if (status == 0) {
258 /*
259 * Address cycle complete, setup and write the read
260 * command
261 */
262 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700263 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
Ben Hutchings6b73e102009-04-29 08:08:58 +0000264 (hw->phy.mdio.prtad <<
265 IXGBE_MSCA_PHY_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700266 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
Auke Kok9a799d72007-09-15 14:07:45 -0700267
268 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
269
270 /*
271 * Check every 10 usec to see if the address cycle
272 * completed. The MDI Command bit will clear when the
273 * operation is complete
274 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700275 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -0700276 udelay(10);
277
278 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
279
280 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
281 break;
282 }
283
284 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700285 hw_dbg(hw, "PHY read command didn't complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700286 status = IXGBE_ERR_PHY;
287 } else {
288 /*
289 * Read operation is complete. Get the data
290 * from MSRWD
291 */
292 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
293 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
294 *phy_data = (u16)(data);
295 }
296 }
297
Don Skidmore5e655102011-02-25 01:58:04 +0000298 hw->mac.ops.release_swfw_sync(hw, gssr);
Auke Kok9a799d72007-09-15 14:07:45 -0700299 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700300
Auke Kok9a799d72007-09-15 14:07:45 -0700301 return status;
302}
303
304/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700305 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
Auke Kok9a799d72007-09-15 14:07:45 -0700306 * @hw: pointer to hardware structure
307 * @reg_addr: 32 bit PHY register to write
308 * @device_type: 5 bit device type
309 * @phy_data: Data to write to the PHY register
310 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700311s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
312 u32 device_type, u16 phy_data)
Auke Kok9a799d72007-09-15 14:07:45 -0700313{
314 u32 command;
315 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -0700316 s32 status = 0;
317 u16 gssr;
318
319 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
320 gssr = IXGBE_GSSR_PHY1_SM;
321 else
322 gssr = IXGBE_GSSR_PHY0_SM;
323
Don Skidmore5e655102011-02-25 01:58:04 +0000324 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0)
Auke Kok9a799d72007-09-15 14:07:45 -0700325 status = IXGBE_ERR_SWFW_SYNC;
326
327 if (status == 0) {
328 /* Put the data in the MDI single read and write data register*/
329 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
330
331 /* Setup and write the address cycle command */
332 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700333 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
Ben Hutchings6b73e102009-04-29 08:08:58 +0000334 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700335 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
Auke Kok9a799d72007-09-15 14:07:45 -0700336
337 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
338
339 /*
340 * Check every 10 usec to see if the address cycle completed.
341 * The MDI Command bit will clear when the operation is
342 * complete
343 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700344 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -0700345 udelay(10);
346
347 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
348
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700349 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
Auke Kok9a799d72007-09-15 14:07:45 -0700350 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700351 }
352
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700353 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
354 hw_dbg(hw, "PHY address cmd didn't complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700355 status = IXGBE_ERR_PHY;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700356 }
Auke Kok9a799d72007-09-15 14:07:45 -0700357
358 if (status == 0) {
359 /*
360 * Address cycle complete, setup and write the write
361 * command
362 */
363 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700364 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
Ben Hutchings6b73e102009-04-29 08:08:58 +0000365 (hw->phy.mdio.prtad <<
366 IXGBE_MSCA_PHY_ADDR_SHIFT) |
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700367 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
Auke Kok9a799d72007-09-15 14:07:45 -0700368
369 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
370
371 /*
372 * Check every 10 usec to see if the address cycle
373 * completed. The MDI Command bit will clear when the
374 * operation is complete
375 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700376 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -0700377 udelay(10);
378
379 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
380
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700381 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
Auke Kok9a799d72007-09-15 14:07:45 -0700382 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700383 }
384
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700385 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
386 hw_dbg(hw, "PHY address cmd didn't complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700387 status = IXGBE_ERR_PHY;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700388 }
Auke Kok9a799d72007-09-15 14:07:45 -0700389 }
390
Don Skidmore5e655102011-02-25 01:58:04 +0000391 hw->mac.ops.release_swfw_sync(hw, gssr);
Auke Kok9a799d72007-09-15 14:07:45 -0700392 }
393
394 return status;
395}
396
397/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700398 * ixgbe_setup_phy_link_generic - Set and restart autoneg
Auke Kok9a799d72007-09-15 14:07:45 -0700399 * @hw: pointer to hardware structure
400 *
401 * Restart autonegotiation and PHY and waits for completion.
402 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700403s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700404{
405 s32 status = IXGBE_NOT_IMPLEMENTED;
406 u32 time_out;
407 u32 max_time_out = 10;
Ben Hutchings6b73e102009-04-29 08:08:58 +0000408 u16 autoneg_reg;
Auke Kok9a799d72007-09-15 14:07:45 -0700409
410 /*
411 * Set advertisement settings in PHY based on autoneg_advertised
412 * settings. If autoneg_advertised = 0, then advertise default values
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700413 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
Auke Kok9a799d72007-09-15 14:07:45 -0700414 * for a 1G.
415 */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000416 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700417
418 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
Ben Hutchings6b73e102009-04-29 08:08:58 +0000419 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700420 else
Ben Hutchings6b73e102009-04-29 08:08:58 +0000421 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
Auke Kok9a799d72007-09-15 14:07:45 -0700422
Ben Hutchings6b73e102009-04-29 08:08:58 +0000423 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700424
425 /* Restart PHY autonegotiation and wait for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000426 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700427
Ben Hutchings6b73e102009-04-29 08:08:58 +0000428 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
Auke Kok9a799d72007-09-15 14:07:45 -0700429
Ben Hutchings6b73e102009-04-29 08:08:58 +0000430 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700431
432 /* Wait for autonegotiation to finish */
433 for (time_out = 0; time_out < max_time_out; time_out++) {
434 udelay(10);
435 /* Restart PHY autonegotiation and wait for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000436 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700437 &autoneg_reg);
Auke Kok9a799d72007-09-15 14:07:45 -0700438
Ben Hutchings6b73e102009-04-29 08:08:58 +0000439 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
440 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700441 status = 0;
442 break;
443 }
444 }
445
446 if (time_out == max_time_out)
447 status = IXGBE_ERR_LINK_SETUP;
448
449 return status;
450}
451
452/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700453 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700454 * @hw: pointer to hardware structure
455 * @speed: new link speed
456 * @autoneg: true if autonegotiation enabled
457 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700458s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
459 ixgbe_link_speed speed,
460 bool autoneg,
461 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700462{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700463
Auke Kok9a799d72007-09-15 14:07:45 -0700464 /*
465 * Clear autoneg_advertised and set new values based on input link
466 * speed.
467 */
468 hw->phy.autoneg_advertised = 0;
469
470 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
471 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700472
Auke Kok9a799d72007-09-15 14:07:45 -0700473 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
474 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
475
476 /* Setup link based on the new speed settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700477 hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700478
479 return 0;
480}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700481
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700482/**
Don Skidmorea391f1d2010-11-16 19:27:15 -0800483 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
484 * @hw: pointer to hardware structure
485 * @speed: pointer to link speed
486 * @autoneg: boolean auto-negotiation value
487 *
488 * Determines the link capabilities by reading the AUTOC register.
489 */
490s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
Don Skidmorefe15e8e12010-11-16 19:27:16 -0800491 ixgbe_link_speed *speed,
492 bool *autoneg)
Don Skidmorea391f1d2010-11-16 19:27:15 -0800493{
494 s32 status = IXGBE_ERR_LINK_SETUP;
495 u16 speed_ability;
496
497 *speed = 0;
498 *autoneg = true;
499
500 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
501 &speed_ability);
502
503 if (status == 0) {
504 if (speed_ability & MDIO_SPEED_10G)
505 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
506 if (speed_ability & MDIO_PMA_SPEED_1000)
507 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
508 if (speed_ability & MDIO_PMA_SPEED_100)
509 *speed |= IXGBE_LINK_SPEED_100_FULL;
510 }
511
512 return status;
513}
514
515/**
Donald Skidmorec4900be2008-11-20 21:11:42 -0800516 * ixgbe_reset_phy_nl - Performs a PHY reset
517 * @hw: pointer to hardware structure
518 **/
519s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
520{
521 u16 phy_offset, control, eword, edata, block_crc;
522 bool end_data = false;
523 u16 list_offset, data_offset;
524 u16 phy_data = 0;
525 s32 ret_val = 0;
526 u32 i;
527
Ben Hutchings6b73e102009-04-29 08:08:58 +0000528 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800529
530 /* reset the PHY and poll for completion */
Ben Hutchings6b73e102009-04-29 08:08:58 +0000531 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
532 (phy_data | MDIO_CTRL1_RESET));
Donald Skidmorec4900be2008-11-20 21:11:42 -0800533
534 for (i = 0; i < 100; i++) {
Ben Hutchings6b73e102009-04-29 08:08:58 +0000535 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
536 &phy_data);
537 if ((phy_data & MDIO_CTRL1_RESET) == 0)
Donald Skidmorec4900be2008-11-20 21:11:42 -0800538 break;
539 msleep(10);
540 }
541
Ben Hutchings6b73e102009-04-29 08:08:58 +0000542 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800543 hw_dbg(hw, "PHY reset did not complete.\n");
544 ret_val = IXGBE_ERR_PHY;
545 goto out;
546 }
547
548 /* Get init offsets */
549 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
550 &data_offset);
551 if (ret_val != 0)
552 goto out;
553
554 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
555 data_offset++;
556 while (!end_data) {
557 /*
558 * Read control word from PHY init contents offset
559 */
560 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
561 control = (eword & IXGBE_CONTROL_MASK_NL) >>
562 IXGBE_CONTROL_SHIFT_NL;
563 edata = eword & IXGBE_DATA_MASK_NL;
564 switch (control) {
565 case IXGBE_DELAY_NL:
566 data_offset++;
567 hw_dbg(hw, "DELAY: %d MS\n", edata);
568 msleep(edata);
569 break;
570 case IXGBE_DATA_NL:
Frans Popd6dbee82010-03-24 07:57:35 +0000571 hw_dbg(hw, "DATA:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800572 data_offset++;
573 hw->eeprom.ops.read(hw, data_offset++,
574 &phy_offset);
575 for (i = 0; i < edata; i++) {
576 hw->eeprom.ops.read(hw, data_offset, &eword);
577 hw->phy.ops.write_reg(hw, phy_offset,
Ben Hutchings6b73e102009-04-29 08:08:58 +0000578 MDIO_MMD_PMAPMD, eword);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800579 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
580 phy_offset);
581 data_offset++;
582 phy_offset++;
583 }
584 break;
585 case IXGBE_CONTROL_NL:
586 data_offset++;
Frans Popd6dbee82010-03-24 07:57:35 +0000587 hw_dbg(hw, "CONTROL:\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -0800588 if (edata == IXGBE_CONTROL_EOL_NL) {
589 hw_dbg(hw, "EOL\n");
590 end_data = true;
591 } else if (edata == IXGBE_CONTROL_SOL_NL) {
592 hw_dbg(hw, "SOL\n");
593 } else {
594 hw_dbg(hw, "Bad control value\n");
595 ret_val = IXGBE_ERR_PHY;
596 goto out;
597 }
598 break;
599 default:
600 hw_dbg(hw, "Bad control type\n");
601 ret_val = IXGBE_ERR_PHY;
602 goto out;
603 }
604 }
605
606out:
607 return ret_val;
608}
609
610/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000611 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
Donald Skidmorec4900be2008-11-20 21:11:42 -0800612 * @hw: pointer to hardware structure
613 *
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000614 * Searches for and identifies the SFP module and assigns appropriate PHY type.
Donald Skidmorec4900be2008-11-20 21:11:42 -0800615 **/
616s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
617{
618 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
619 u32 vendor_oui = 0;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000620 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800621 u8 identifier = 0;
622 u8 comp_codes_1g = 0;
623 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000624 u8 oui_bytes[3] = {0, 0, 0};
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000625 u8 cable_tech = 0;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000626 u8 cable_spec = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000627 u16 enforce_sfp = 0;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800628
Don Skidmore8ca783a2009-05-26 20:40:47 -0700629 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
630 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
631 status = IXGBE_ERR_SFP_NOT_PRESENT;
632 goto out;
633 }
634
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000635 status = hw->phy.ops.read_i2c_eeprom(hw,
636 IXGBE_SFF_IDENTIFIER,
Donald Skidmorec4900be2008-11-20 21:11:42 -0800637 &identifier);
638
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000639 if (status == IXGBE_ERR_SWFW_SYNC ||
640 status == IXGBE_ERR_I2C ||
641 status == IXGBE_ERR_SFP_NOT_PRESENT)
642 goto err_read_i2c_eeprom;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800643
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000644 /* LAN ID is needed for sfp_type determination */
645 hw->mac.ops.set_lan_id(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -0800646
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000647 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
648 hw->phy.type = ixgbe_phy_sfp_unsupported;
649 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
650 } else {
651 status = hw->phy.ops.read_i2c_eeprom(hw,
652 IXGBE_SFF_1GBE_COMP_CODES,
653 &comp_codes_1g);
654
655 if (status == IXGBE_ERR_SWFW_SYNC ||
656 status == IXGBE_ERR_I2C ||
657 status == IXGBE_ERR_SFP_NOT_PRESENT)
658 goto err_read_i2c_eeprom;
659
660 status = hw->phy.ops.read_i2c_eeprom(hw,
661 IXGBE_SFF_10GBE_COMP_CODES,
662 &comp_codes_10g);
663
664 if (status == IXGBE_ERR_SWFW_SYNC ||
665 status == IXGBE_ERR_I2C ||
666 status == IXGBE_ERR_SFP_NOT_PRESENT)
667 goto err_read_i2c_eeprom;
668 status = hw->phy.ops.read_i2c_eeprom(hw,
669 IXGBE_SFF_CABLE_TECHNOLOGY,
670 &cable_tech);
671
672 if (status == IXGBE_ERR_SWFW_SYNC ||
673 status == IXGBE_ERR_I2C ||
674 status == IXGBE_ERR_SFP_NOT_PRESENT)
675 goto err_read_i2c_eeprom;
676
677 /* ID Module
678 * =========
679 * 0 SFP_DA_CU
680 * 1 SFP_SR
681 * 2 SFP_LR
682 * 3 SFP_DA_CORE0 - 82599-specific
683 * 4 SFP_DA_CORE1 - 82599-specific
684 * 5 SFP_SR/LR_CORE0 - 82599-specific
685 * 6 SFP_SR/LR_CORE1 - 82599-specific
686 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
687 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
688 * 9 SFP_1g_cu_CORE0 - 82599-specific
689 * 10 SFP_1g_cu_CORE1 - 82599-specific
690 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000691 if (hw->mac.type == ixgbe_mac_82598EB) {
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000692 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000693 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
694 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
695 hw->phy.sfp_type = ixgbe_sfp_type_sr;
696 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
697 hw->phy.sfp_type = ixgbe_sfp_type_lr;
698 else
699 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
700 } else if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000701 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000702 if (hw->bus.lan_id == 0)
703 hw->phy.sfp_type =
704 ixgbe_sfp_type_da_cu_core0;
705 else
706 hw->phy.sfp_type =
707 ixgbe_sfp_type_da_cu_core1;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000708 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
709 hw->phy.ops.read_i2c_eeprom(
710 hw, IXGBE_SFF_CABLE_SPEC_COMP,
711 &cable_spec);
712 if (cable_spec &
713 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
714 if (hw->bus.lan_id == 0)
715 hw->phy.sfp_type =
716 ixgbe_sfp_type_da_act_lmt_core0;
717 else
718 hw->phy.sfp_type =
719 ixgbe_sfp_type_da_act_lmt_core1;
720 } else {
721 hw->phy.sfp_type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000722 ixgbe_sfp_type_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000723 }
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000724 } else if (comp_codes_10g &
725 (IXGBE_SFF_10GBASESR_CAPABLE |
726 IXGBE_SFF_10GBASELR_CAPABLE)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000727 if (hw->bus.lan_id == 0)
728 hw->phy.sfp_type =
729 ixgbe_sfp_type_srlr_core0;
730 else
731 hw->phy.sfp_type =
732 ixgbe_sfp_type_srlr_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000733 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
Don Skidmorecb836a92010-06-29 18:30:59 +0000734 if (hw->bus.lan_id == 0)
735 hw->phy.sfp_type =
736 ixgbe_sfp_type_1g_cu_core0;
737 else
738 hw->phy.sfp_type =
739 ixgbe_sfp_type_1g_cu_core1;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000740 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000741 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000742 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000743 }
Donald Skidmorec4900be2008-11-20 21:11:42 -0800744
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000745 if (hw->phy.sfp_type != stored_sfp_type)
746 hw->phy.sfp_setup_needed = true;
747
748 /* Determine if the SFP+ PHY is dual speed or not. */
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +0000749 hw->phy.multispeed_fiber = false;
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000750 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
751 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
752 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
753 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
754 hw->phy.multispeed_fiber = true;
755
Donald Skidmorec4900be2008-11-20 21:11:42 -0800756 /* Determine PHY vendor */
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +0000757 if (hw->phy.type != ixgbe_phy_nl) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800758 hw->phy.id = identifier;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000759 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -0800760 IXGBE_SFF_VENDOR_OUI_BYTE0,
761 &oui_bytes[0]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000762
763 if (status == IXGBE_ERR_SWFW_SYNC ||
764 status == IXGBE_ERR_I2C ||
765 status == IXGBE_ERR_SFP_NOT_PRESENT)
766 goto err_read_i2c_eeprom;
767
768 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -0800769 IXGBE_SFF_VENDOR_OUI_BYTE1,
770 &oui_bytes[1]);
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000771
772 if (status == IXGBE_ERR_SWFW_SYNC ||
773 status == IXGBE_ERR_I2C ||
774 status == IXGBE_ERR_SFP_NOT_PRESENT)
775 goto err_read_i2c_eeprom;
776
777 status = hw->phy.ops.read_i2c_eeprom(hw,
Donald Skidmorec4900be2008-11-20 21:11:42 -0800778 IXGBE_SFF_VENDOR_OUI_BYTE2,
779 &oui_bytes[2]);
780
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000781 if (status == IXGBE_ERR_SWFW_SYNC ||
782 status == IXGBE_ERR_I2C ||
783 status == IXGBE_ERR_SFP_NOT_PRESENT)
784 goto err_read_i2c_eeprom;
785
Donald Skidmorec4900be2008-11-20 21:11:42 -0800786 vendor_oui =
787 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
788 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
789 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
790
791 switch (vendor_oui) {
792 case IXGBE_SFF_VENDOR_OUI_TYCO:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000793 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000794 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000795 ixgbe_phy_sfp_passive_tyco;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800796 break;
797 case IXGBE_SFF_VENDOR_OUI_FTL:
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000798 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
799 hw->phy.type = ixgbe_phy_sfp_ftl_active;
800 else
801 hw->phy.type = ixgbe_phy_sfp_ftl;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800802 break;
803 case IXGBE_SFF_VENDOR_OUI_AVAGO:
804 hw->phy.type = ixgbe_phy_sfp_avago;
805 break;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000806 case IXGBE_SFF_VENDOR_OUI_INTEL:
807 hw->phy.type = ixgbe_phy_sfp_intel;
808 break;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800809 default:
Peter P Waskiewicz Jr537d58a2009-05-19 09:18:51 +0000810 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000811 hw->phy.type =
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000812 ixgbe_phy_sfp_passive_unknown;
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000813 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
814 hw->phy.type =
815 ixgbe_phy_sfp_active_unknown;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800816 else
817 hw->phy.type = ixgbe_phy_sfp_unknown;
818 break;
819 }
820 }
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +0000821
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000822 /* Allow any DA cable vendor */
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000823 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
824 IXGBE_SFF_DA_ACTIVE_CABLE)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +0000825 status = 0;
826 goto out;
827 }
828
Don Skidmorecb836a92010-06-29 18:30:59 +0000829 /* Verify supported 1G SFP modules */
830 if (comp_codes_10g == 0 &&
831 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
832 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0)) {
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +0000833 hw->phy.type = ixgbe_phy_sfp_unsupported;
834 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
835 goto out;
836 }
837
838 /* Anything else 82598-based is supported */
839 if (hw->mac.type == ixgbe_mac_82598EB) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000840 status = 0;
841 goto out;
842 }
843
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +0000844 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
Don Skidmorecb836a92010-06-29 18:30:59 +0000845 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
846 !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) ||
847 (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1))) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000848 /* Make sure we're a supported PHY type */
849 if (hw->phy.type == ixgbe_phy_sfp_intel) {
850 status = 0;
851 } else {
852 hw_dbg(hw, "SFP+ module not supported\n");
Waskiewicz Jr, Peter Pfa466e92009-04-23 11:31:37 +0000853 hw->phy.type = ixgbe_phy_sfp_unsupported;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000854 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
855 }
856 } else {
857 status = 0;
858 }
Donald Skidmorec4900be2008-11-20 21:11:42 -0800859 }
860
861out:
862 return status;
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000863
864err_read_i2c_eeprom:
865 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
866 if (hw->phy.type != ixgbe_phy_nl) {
867 hw->phy.id = 0;
868 hw->phy.type = ixgbe_phy_unknown;
869 }
870 return IXGBE_ERR_SFP_NOT_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800871}
872
873/**
Emil Tantilov76d97dd2011-02-16 10:14:00 +0000874 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
Donald Skidmorec4900be2008-11-20 21:11:42 -0800875 * @hw: pointer to hardware structure
876 * @list_offset: offset to the SFP ID list
877 * @data_offset: offset to the SFP data block
Emil Tantilov75f19c32011-02-19 08:43:55 +0000878 *
879 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
880 * so it returns the offsets to the phy init sequence block.
Donald Skidmorec4900be2008-11-20 21:11:42 -0800881 **/
882s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
883 u16 *list_offset,
884 u16 *data_offset)
885{
886 u16 sfp_id;
Don Skidmorecb836a92010-06-29 18:30:59 +0000887 u16 sfp_type = hw->phy.sfp_type;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800888
889 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
890 return IXGBE_ERR_SFP_NOT_SUPPORTED;
891
892 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
893 return IXGBE_ERR_SFP_NOT_PRESENT;
894
895 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
896 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
897 return IXGBE_ERR_SFP_NOT_SUPPORTED;
898
Don Skidmorecb836a92010-06-29 18:30:59 +0000899 /*
900 * Limiting active cables and 1G Phys must be initialized as
901 * SR modules
902 */
903 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
904 sfp_type == ixgbe_sfp_type_1g_cu_core0)
905 sfp_type = ixgbe_sfp_type_srlr_core0;
906 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
907 sfp_type == ixgbe_sfp_type_1g_cu_core1)
908 sfp_type = ixgbe_sfp_type_srlr_core1;
909
Donald Skidmorec4900be2008-11-20 21:11:42 -0800910 /* Read offset to PHY init contents */
911 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
912
913 if ((!*list_offset) || (*list_offset == 0xFFFF))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000914 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
Donald Skidmorec4900be2008-11-20 21:11:42 -0800915
916 /* Shift offset to first ID word */
917 (*list_offset)++;
918
919 /*
920 * Find the matching SFP ID in the EEPROM
921 * and program the init sequence
922 */
923 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
924
925 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
Don Skidmorecb836a92010-06-29 18:30:59 +0000926 if (sfp_id == sfp_type) {
Donald Skidmorec4900be2008-11-20 21:11:42 -0800927 (*list_offset)++;
928 hw->eeprom.ops.read(hw, *list_offset, data_offset);
929 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
930 hw_dbg(hw, "SFP+ module not supported\n");
931 return IXGBE_ERR_SFP_NOT_SUPPORTED;
932 } else {
933 break;
934 }
935 } else {
936 (*list_offset) += 2;
937 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
938 return IXGBE_ERR_PHY;
939 }
940 }
941
942 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
943 hw_dbg(hw, "No matching SFP+ module found\n");
944 return IXGBE_ERR_SFP_NOT_SUPPORTED;
945 }
946
947 return 0;
948}
949
950/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000951 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
952 * @hw: pointer to hardware structure
953 * @byte_offset: EEPROM byte offset to read
954 * @eeprom_data: value read
955 *
956 * Performs byte read operation to SFP module's EEPROM over I2C interface.
957 **/
958s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
959 u8 *eeprom_data)
960{
961 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
962 IXGBE_I2C_EEPROM_DEV_ADDR,
963 eeprom_data);
964}
965
966/**
967 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
968 * @hw: pointer to hardware structure
969 * @byte_offset: EEPROM byte offset to write
970 * @eeprom_data: value to write
971 *
972 * Performs byte write operation to SFP module's EEPROM over I2C interface.
973 **/
974s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
975 u8 eeprom_data)
976{
977 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
978 IXGBE_I2C_EEPROM_DEV_ADDR,
979 eeprom_data);
980}
981
982/**
983 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
984 * @hw: pointer to hardware structure
985 * @byte_offset: byte offset to read
986 * @data: value read
987 *
988 * Performs byte read operation to SFP module's EEPROM over I2C interface at
989 * a specified deivce address.
990 **/
991s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
992 u8 dev_addr, u8 *data)
993{
994 s32 status = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +0000995 u32 max_retry = 10;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000996 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +0000997 u16 swfw_mask = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000998 bool nack = 1;
999
Emil Tantilov75f19c32011-02-19 08:43:55 +00001000 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1001 swfw_mask = IXGBE_GSSR_PHY1_SM;
1002 else
1003 swfw_mask = IXGBE_GSSR_PHY0_SM;
1004
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001005 do {
Emil Tantilov75f19c32011-02-19 08:43:55 +00001006 if (ixgbe_acquire_swfw_sync(hw, swfw_mask) != 0) {
1007 status = IXGBE_ERR_SWFW_SYNC;
1008 goto read_byte_out;
1009 }
1010
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001011 ixgbe_i2c_start(hw);
1012
1013 /* Device Address and write indication */
1014 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1015 if (status != 0)
1016 goto fail;
1017
1018 status = ixgbe_get_i2c_ack(hw);
1019 if (status != 0)
1020 goto fail;
1021
1022 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1023 if (status != 0)
1024 goto fail;
1025
1026 status = ixgbe_get_i2c_ack(hw);
1027 if (status != 0)
1028 goto fail;
1029
1030 ixgbe_i2c_start(hw);
1031
1032 /* Device Address and read indication */
1033 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1034 if (status != 0)
1035 goto fail;
1036
1037 status = ixgbe_get_i2c_ack(hw);
1038 if (status != 0)
1039 goto fail;
1040
1041 status = ixgbe_clock_in_i2c_byte(hw, data);
1042 if (status != 0)
1043 goto fail;
1044
1045 status = ixgbe_clock_out_i2c_bit(hw, nack);
1046 if (status != 0)
1047 goto fail;
1048
1049 ixgbe_i2c_stop(hw);
1050 break;
1051
1052fail:
Emil Tantilov75f19c32011-02-19 08:43:55 +00001053 ixgbe_release_swfw_sync(hw, swfw_mask);
1054 msleep(100);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001055 ixgbe_i2c_bus_clear(hw);
1056 retry++;
1057 if (retry < max_retry)
1058 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1059 else
1060 hw_dbg(hw, "I2C byte read error.\n");
1061
1062 } while (retry < max_retry);
1063
Emil Tantilov75f19c32011-02-19 08:43:55 +00001064 ixgbe_release_swfw_sync(hw, swfw_mask);
1065
1066read_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001067 return status;
1068}
1069
1070/**
1071 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1072 * @hw: pointer to hardware structure
1073 * @byte_offset: byte offset to write
1074 * @data: value to write
1075 *
1076 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1077 * a specified device address.
1078 **/
1079s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1080 u8 dev_addr, u8 data)
1081{
1082 s32 status = 0;
1083 u32 max_retry = 1;
1084 u32 retry = 0;
Emil Tantilov75f19c32011-02-19 08:43:55 +00001085 u16 swfw_mask = 0;
1086
1087 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1088 swfw_mask = IXGBE_GSSR_PHY1_SM;
1089 else
1090 swfw_mask = IXGBE_GSSR_PHY0_SM;
1091
1092 if (ixgbe_acquire_swfw_sync(hw, swfw_mask) != 0) {
1093 status = IXGBE_ERR_SWFW_SYNC;
1094 goto write_byte_out;
1095 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001096
1097 do {
1098 ixgbe_i2c_start(hw);
1099
1100 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1101 if (status != 0)
1102 goto fail;
1103
1104 status = ixgbe_get_i2c_ack(hw);
1105 if (status != 0)
1106 goto fail;
1107
1108 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1109 if (status != 0)
1110 goto fail;
1111
1112 status = ixgbe_get_i2c_ack(hw);
1113 if (status != 0)
1114 goto fail;
1115
1116 status = ixgbe_clock_out_i2c_byte(hw, data);
1117 if (status != 0)
1118 goto fail;
1119
1120 status = ixgbe_get_i2c_ack(hw);
1121 if (status != 0)
1122 goto fail;
1123
1124 ixgbe_i2c_stop(hw);
1125 break;
1126
1127fail:
1128 ixgbe_i2c_bus_clear(hw);
1129 retry++;
1130 if (retry < max_retry)
1131 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1132 else
1133 hw_dbg(hw, "I2C byte write error.\n");
1134 } while (retry < max_retry);
1135
Emil Tantilov75f19c32011-02-19 08:43:55 +00001136 ixgbe_release_swfw_sync(hw, swfw_mask);
1137
1138write_byte_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001139 return status;
1140}
1141
1142/**
1143 * ixgbe_i2c_start - Sets I2C start condition
1144 * @hw: pointer to hardware structure
1145 *
1146 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1147 **/
1148static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1149{
1150 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1151
1152 /* Start condition must begin with data and clock high */
1153 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1154 ixgbe_raise_i2c_clk(hw, &i2cctl);
1155
1156 /* Setup time for start condition (4.7us) */
1157 udelay(IXGBE_I2C_T_SU_STA);
1158
1159 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1160
1161 /* Hold time for start condition (4us) */
1162 udelay(IXGBE_I2C_T_HD_STA);
1163
1164 ixgbe_lower_i2c_clk(hw, &i2cctl);
1165
1166 /* Minimum low period of clock is 4.7 us */
1167 udelay(IXGBE_I2C_T_LOW);
1168
1169}
1170
1171/**
1172 * ixgbe_i2c_stop - Sets I2C stop condition
1173 * @hw: pointer to hardware structure
1174 *
1175 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1176 **/
1177static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1178{
1179 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1180
1181 /* Stop condition must begin with data low and clock high */
1182 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1183 ixgbe_raise_i2c_clk(hw, &i2cctl);
1184
1185 /* Setup time for stop condition (4us) */
1186 udelay(IXGBE_I2C_T_SU_STO);
1187
1188 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1189
1190 /* bus free time between stop and start (4.7us)*/
1191 udelay(IXGBE_I2C_T_BUF);
1192}
1193
1194/**
1195 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1196 * @hw: pointer to hardware structure
1197 * @data: data byte to clock in
1198 *
1199 * Clocks in one byte data via I2C data/clock
1200 **/
1201static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1202{
1203 s32 status = 0;
1204 s32 i;
1205 bool bit = 0;
1206
1207 for (i = 7; i >= 0; i--) {
1208 status = ixgbe_clock_in_i2c_bit(hw, &bit);
1209 *data |= bit << i;
1210
1211 if (status != 0)
1212 break;
1213 }
1214
1215 return status;
1216}
1217
1218/**
1219 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1220 * @hw: pointer to hardware structure
1221 * @data: data byte clocked out
1222 *
1223 * Clocks out one byte data via I2C data/clock
1224 **/
1225static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1226{
1227 s32 status = 0;
1228 s32 i;
1229 u32 i2cctl;
1230 bool bit = 0;
1231
1232 for (i = 7; i >= 0; i--) {
1233 bit = (data >> i) & 0x1;
1234 status = ixgbe_clock_out_i2c_bit(hw, bit);
1235
1236 if (status != 0)
1237 break;
1238 }
1239
1240 /* Release SDA line (set high) */
1241 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1242 i2cctl |= IXGBE_I2C_DATA_OUT;
1243 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1244
1245 return status;
1246}
1247
1248/**
1249 * ixgbe_get_i2c_ack - Polls for I2C ACK
1250 * @hw: pointer to hardware structure
1251 *
1252 * Clocks in/out one bit via I2C data/clock
1253 **/
1254static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1255{
1256 s32 status;
1257 u32 i = 0;
1258 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1259 u32 timeout = 10;
1260 bool ack = 1;
1261
1262 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1263
1264 if (status != 0)
1265 goto out;
1266
1267 /* Minimum high period of clock is 4us */
1268 udelay(IXGBE_I2C_T_HIGH);
1269
1270 /* Poll for ACK. Note that ACK in I2C spec is
1271 * transition from 1 to 0 */
1272 for (i = 0; i < timeout; i++) {
1273 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1274 ack = ixgbe_get_i2c_data(&i2cctl);
1275
1276 udelay(1);
1277 if (ack == 0)
1278 break;
1279 }
1280
1281 if (ack == 1) {
1282 hw_dbg(hw, "I2C ack was not received.\n");
1283 status = IXGBE_ERR_I2C;
1284 }
1285
1286 ixgbe_lower_i2c_clk(hw, &i2cctl);
1287
1288 /* Minimum low period of clock is 4.7 us */
1289 udelay(IXGBE_I2C_T_LOW);
1290
1291out:
1292 return status;
1293}
1294
1295/**
1296 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1297 * @hw: pointer to hardware structure
1298 * @data: read data value
1299 *
1300 * Clocks in one bit via I2C data/clock
1301 **/
1302static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1303{
1304 s32 status;
1305 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1306
1307 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1308
1309 /* Minimum high period of clock is 4us */
1310 udelay(IXGBE_I2C_T_HIGH);
1311
1312 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1313 *data = ixgbe_get_i2c_data(&i2cctl);
1314
1315 ixgbe_lower_i2c_clk(hw, &i2cctl);
1316
1317 /* Minimum low period of clock is 4.7 us */
1318 udelay(IXGBE_I2C_T_LOW);
1319
1320 return status;
1321}
1322
1323/**
1324 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1325 * @hw: pointer to hardware structure
1326 * @data: data value to write
1327 *
1328 * Clocks out one bit via I2C data/clock
1329 **/
1330static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1331{
1332 s32 status;
1333 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1334
1335 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1336 if (status == 0) {
1337 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1338
1339 /* Minimum high period of clock is 4us */
1340 udelay(IXGBE_I2C_T_HIGH);
1341
1342 ixgbe_lower_i2c_clk(hw, &i2cctl);
1343
1344 /* Minimum low period of clock is 4.7 us.
1345 * This also takes care of the data hold time.
1346 */
1347 udelay(IXGBE_I2C_T_LOW);
1348 } else {
1349 status = IXGBE_ERR_I2C;
1350 hw_dbg(hw, "I2C data was not set to %X\n", data);
1351 }
1352
1353 return status;
1354}
1355/**
1356 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1357 * @hw: pointer to hardware structure
1358 * @i2cctl: Current value of I2CCTL register
1359 *
1360 * Raises the I2C clock line '0'->'1'
1361 **/
1362static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1363{
1364 s32 status = 0;
1365
1366 *i2cctl |= IXGBE_I2C_CLK_OUT;
1367
1368 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1369
1370 /* SCL rise time (1000ns) */
1371 udelay(IXGBE_I2C_T_RISE);
1372
1373 return status;
1374}
1375
1376/**
1377 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1378 * @hw: pointer to hardware structure
1379 * @i2cctl: Current value of I2CCTL register
1380 *
1381 * Lowers the I2C clock line '1'->'0'
1382 **/
1383static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1384{
1385
1386 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1387
1388 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1389
1390 /* SCL fall time (300ns) */
1391 udelay(IXGBE_I2C_T_FALL);
1392}
1393
1394/**
1395 * ixgbe_set_i2c_data - Sets the I2C data bit
1396 * @hw: pointer to hardware structure
1397 * @i2cctl: Current value of I2CCTL register
1398 * @data: I2C data value (0 or 1) to set
1399 *
1400 * Sets the I2C data bit
1401 **/
1402static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1403{
1404 s32 status = 0;
1405
1406 if (data)
1407 *i2cctl |= IXGBE_I2C_DATA_OUT;
1408 else
1409 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1410
1411 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1412
1413 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1414 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1415
1416 /* Verify data was set correctly */
1417 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1418 if (data != ixgbe_get_i2c_data(i2cctl)) {
1419 status = IXGBE_ERR_I2C;
1420 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1421 }
1422
1423 return status;
1424}
1425
1426/**
1427 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1428 * @hw: pointer to hardware structure
1429 * @i2cctl: Current value of I2CCTL register
1430 *
1431 * Returns the I2C data bit value
1432 **/
1433static bool ixgbe_get_i2c_data(u32 *i2cctl)
1434{
1435 bool data;
1436
1437 if (*i2cctl & IXGBE_I2C_DATA_IN)
1438 data = 1;
1439 else
1440 data = 0;
1441
1442 return data;
1443}
1444
1445/**
1446 * ixgbe_i2c_bus_clear - Clears the I2C bus
1447 * @hw: pointer to hardware structure
1448 *
1449 * Clears the I2C bus by sending nine clock pulses.
1450 * Used when data line is stuck low.
1451 **/
1452static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1453{
1454 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1455 u32 i;
1456
Emil Tantilov75f19c32011-02-19 08:43:55 +00001457 ixgbe_i2c_start(hw);
1458
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001459 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1460
1461 for (i = 0; i < 9; i++) {
1462 ixgbe_raise_i2c_clk(hw, &i2cctl);
1463
1464 /* Min high period of clock is 4us */
1465 udelay(IXGBE_I2C_T_HIGH);
1466
1467 ixgbe_lower_i2c_clk(hw, &i2cctl);
1468
1469 /* Min low period of clock is 4.7us*/
1470 udelay(IXGBE_I2C_T_LOW);
1471 }
1472
Emil Tantilov75f19c32011-02-19 08:43:55 +00001473 ixgbe_i2c_start(hw);
1474
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001475 /* Put the i2c bus back to default state */
1476 ixgbe_i2c_stop(hw);
1477}
1478
1479/**
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001480 * ixgbe_check_phy_link_tnx - Determine link and speed status
1481 * @hw: pointer to hardware structure
1482 *
1483 * Reads the VS1 register to determine if link is up and the current speed for
1484 * the PHY.
1485 **/
1486s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
1487 bool *link_up)
1488{
1489 s32 status = 0;
1490 u32 time_out;
1491 u32 max_time_out = 10;
1492 u16 phy_link = 0;
1493 u16 phy_speed = 0;
1494 u16 phy_data = 0;
1495
1496 /* Initialize speed and link to default case */
1497 *link_up = false;
1498 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1499
1500 /*
1501 * Check current speed and link status of the PHY register.
1502 * This is a vendor specific register and may have to
1503 * be changed for other copper PHYs.
1504 */
1505 for (time_out = 0; time_out < max_time_out; time_out++) {
1506 udelay(10);
1507 status = hw->phy.ops.read_reg(hw,
1508 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
Ben Hutchings6b73e102009-04-29 08:08:58 +00001509 MDIO_MMD_VEND1,
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001510 &phy_data);
1511 phy_link = phy_data &
1512 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
1513 phy_speed = phy_data &
1514 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
1515 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
1516 *link_up = true;
1517 if (phy_speed ==
1518 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
1519 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1520 break;
1521 }
1522 }
1523
1524 return status;
1525}
1526
1527/**
1528 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
1529 * @hw: pointer to hardware structure
1530 * @firmware_version: pointer to the PHY Firmware Version
1531 **/
1532s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1533 u16 *firmware_version)
1534{
1535 s32 status = 0;
1536
Ben Hutchings6b73e102009-04-29 08:08:58 +00001537 status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001538 firmware_version);
1539
1540 return status;
1541}
1542
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001543/**
Don Skidmorefe15e8e12010-11-16 19:27:16 -08001544 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
1545 * @hw: pointer to hardware structure
1546 * @firmware_version: pointer to the PHY Firmware Version
1547**/
1548s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
1549 u16 *firmware_version)
1550{
1551 s32 status = 0;
1552
1553 status = hw->phy.ops.read_reg(hw, AQ_FW_REV, MDIO_MMD_VEND1,
1554 firmware_version);
1555
1556 return status;
1557}
1558
1559/**
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001560 * ixgbe_tn_check_overtemp - Checks if an overtemp occured.
1561 * @hw: pointer to hardware structure
1562 *
1563 * Checks if the LASI temp alarm status was triggered due to overtemp
1564 **/
1565s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1566{
1567 s32 status = 0;
1568 u16 phy_data = 0;
1569
1570 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
1571 goto out;
1572
1573 /* Check that the LASI temp alarm status was triggered */
1574 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
1575 MDIO_MMD_PMAPMD, &phy_data);
1576
1577 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
1578 goto out;
1579
1580 status = IXGBE_ERR_OVERTEMP;
1581out:
1582 return status;
1583}