USB: unusual devs patch for Nokia 7610 Supernova
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / ixgbe / ixgbe_phy.c
blob8002931ae82371d62f1f410a28ca0df5ba4746c6
1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
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.
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.
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
33 #include "ixgbe_common.h"
34 #include "ixgbe_phy.h"
36 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
37 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
38 static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
39 static s32 ixgbe_write_phy_reg(struct ixgbe_hw *hw, u32 reg_addr,
40 u32 device_type, u16 phy_data);
42 /**
43 * ixgbe_identify_phy - Get physical layer module
44 * @hw: pointer to hardware structure
46 * Determines the physical layer module found on the current adapter.
47 **/
48 s32 ixgbe_identify_phy(struct ixgbe_hw *hw)
50 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
51 u32 phy_addr;
53 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
54 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
55 hw->phy.addr = phy_addr;
56 ixgbe_get_phy_id(hw);
57 hw->phy.type = ixgbe_get_phy_type_from_id(hw->phy.id);
58 status = 0;
59 break;
62 return status;
65 /**
66 * ixgbe_validate_phy_addr - Determines phy address is valid
67 * @hw: pointer to hardware structure
69 **/
70 static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
72 u16 phy_id = 0;
73 bool valid = false;
75 hw->phy.addr = phy_addr;
76 ixgbe_read_phy_reg(hw,
77 IXGBE_MDIO_PHY_ID_HIGH,
78 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
79 &phy_id);
81 if (phy_id != 0xFFFF && phy_id != 0x0)
82 valid = true;
84 return valid;
87 /**
88 * ixgbe_get_phy_id - Get the phy type
89 * @hw: pointer to hardware structure
91 **/
92 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
94 u32 status;
95 u16 phy_id_high = 0;
96 u16 phy_id_low = 0;
98 status = ixgbe_read_phy_reg(hw,
99 IXGBE_MDIO_PHY_ID_HIGH,
100 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
101 &phy_id_high);
103 if (status == 0) {
104 hw->phy.id = (u32)(phy_id_high << 16);
105 status = ixgbe_read_phy_reg(hw,
106 IXGBE_MDIO_PHY_ID_LOW,
107 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
108 &phy_id_low);
109 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
110 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
113 return status;
117 * ixgbe_get_phy_type_from_id - Get the phy type
118 * @hw: pointer to hardware structure
121 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
123 enum ixgbe_phy_type phy_type;
125 switch (phy_id) {
126 case TN1010_PHY_ID:
127 phy_type = ixgbe_phy_tn;
128 break;
129 case QT2022_PHY_ID:
130 phy_type = ixgbe_phy_qt;
131 break;
132 default:
133 phy_type = ixgbe_phy_unknown;
134 break;
137 return phy_type;
141 * ixgbe_reset_phy - Performs a PHY reset
142 * @hw: pointer to hardware structure
144 s32 ixgbe_reset_phy(struct ixgbe_hw *hw)
147 * Perform soft PHY reset to the PHY_XS.
148 * This will cause a soft reset to the PHY
150 return ixgbe_write_phy_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
151 IXGBE_MDIO_PHY_XS_DEV_TYPE,
152 IXGBE_MDIO_PHY_XS_RESET);
156 * ixgbe_read_phy_reg - Reads a value from a specified PHY register
157 * @hw: pointer to hardware structure
158 * @reg_addr: 32 bit address of PHY register to read
159 * @phy_data: Pointer to read data from PHY register
161 s32 ixgbe_read_phy_reg(struct ixgbe_hw *hw, u32 reg_addr,
162 u32 device_type, u16 *phy_data)
164 u32 command;
165 u32 i;
166 u32 timeout = 10;
167 u32 data;
168 s32 status = 0;
169 u16 gssr;
171 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
172 gssr = IXGBE_GSSR_PHY1_SM;
173 else
174 gssr = IXGBE_GSSR_PHY0_SM;
176 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
177 status = IXGBE_ERR_SWFW_SYNC;
179 if (status == 0) {
180 /* Setup and write the address cycle command */
181 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
182 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
183 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
184 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
186 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
189 * Check every 10 usec to see if the address cycle completed.
190 * The MDI Command bit will clear when the operation is
191 * complete
193 for (i = 0; i < timeout; i++) {
194 udelay(10);
196 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
198 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
199 break;
202 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
203 hw_dbg(hw, "PHY address command did not complete.\n");
204 status = IXGBE_ERR_PHY;
207 if (status == 0) {
209 * Address cycle complete, setup and write the read
210 * command
212 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
213 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
214 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
215 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
217 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
220 * Check every 10 usec to see if the address cycle
221 * completed. The MDI Command bit will clear when the
222 * operation is complete
224 for (i = 0; i < timeout; i++) {
225 udelay(10);
227 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
229 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
230 break;
233 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
234 hw_dbg(hw,
235 "PHY read command didn't complete\n");
236 status = IXGBE_ERR_PHY;
237 } else {
239 * Read operation is complete. Get the data
240 * from MSRWD
242 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
243 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
244 *phy_data = (u16)(data);
248 ixgbe_release_swfw_sync(hw, gssr);
250 return status;
254 * ixgbe_write_phy_reg - Writes a value to specified PHY register
255 * @hw: pointer to hardware structure
256 * @reg_addr: 32 bit PHY register to write
257 * @device_type: 5 bit device type
258 * @phy_data: Data to write to the PHY register
260 static s32 ixgbe_write_phy_reg(struct ixgbe_hw *hw, u32 reg_addr,
261 u32 device_type, u16 phy_data)
263 u32 command;
264 u32 i;
265 u32 timeout = 10;
266 s32 status = 0;
267 u16 gssr;
269 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
270 gssr = IXGBE_GSSR_PHY1_SM;
271 else
272 gssr = IXGBE_GSSR_PHY0_SM;
274 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
275 status = IXGBE_ERR_SWFW_SYNC;
277 if (status == 0) {
278 /* Put the data in the MDI single read and write data register*/
279 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
281 /* Setup and write the address cycle command */
282 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
283 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
284 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
285 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
287 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
290 * Check every 10 usec to see if the address cycle completed.
291 * The MDI Command bit will clear when the operation is
292 * complete
294 for (i = 0; i < timeout; i++) {
295 udelay(10);
297 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
299 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) {
300 hw_dbg(hw, "PHY address cmd didn't complete\n");
301 break;
305 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0)
306 status = IXGBE_ERR_PHY;
308 if (status == 0) {
310 * Address cycle complete, setup and write the write
311 * command
313 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
314 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
315 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
316 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
318 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
321 * Check every 10 usec to see if the address cycle
322 * completed. The MDI Command bit will clear when the
323 * operation is complete
325 for (i = 0; i < timeout; i++) {
326 udelay(10);
328 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
330 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) {
331 hw_dbg(hw, "PHY write command did not "
332 "complete.\n");
333 break;
337 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0)
338 status = IXGBE_ERR_PHY;
341 ixgbe_release_swfw_sync(hw, gssr);
344 return status;
348 * ixgbe_setup_tnx_phy_link - Set and restart autoneg
349 * @hw: pointer to hardware structure
351 * Restart autonegotiation and PHY and waits for completion.
353 s32 ixgbe_setup_tnx_phy_link(struct ixgbe_hw *hw)
355 s32 status = IXGBE_NOT_IMPLEMENTED;
356 u32 time_out;
357 u32 max_time_out = 10;
358 u16 autoneg_speed_selection_register = 0x10;
359 u16 autoneg_restart_mask = 0x0200;
360 u16 autoneg_complete_mask = 0x0020;
361 u16 autoneg_reg = 0;
364 * Set advertisement settings in PHY based on autoneg_advertised
365 * settings. If autoneg_advertised = 0, then advertise default values
366 * txn devices cannot be "forced" to a autoneg 10G and fail. But can
367 * for a 1G.
369 ixgbe_read_phy_reg(hw,
370 autoneg_speed_selection_register,
371 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
372 &autoneg_reg);
374 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
375 autoneg_reg &= 0xEFFF; /* 0 in bit 12 is 1G operation */
376 else
377 autoneg_reg |= 0x1000; /* 1 in bit 12 is 10G/1G operation */
379 ixgbe_write_phy_reg(hw,
380 autoneg_speed_selection_register,
381 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
382 autoneg_reg);
385 /* Restart PHY autonegotiation and wait for completion */
386 ixgbe_read_phy_reg(hw,
387 IXGBE_MDIO_AUTO_NEG_CONTROL,
388 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
389 &autoneg_reg);
391 autoneg_reg |= autoneg_restart_mask;
393 ixgbe_write_phy_reg(hw,
394 IXGBE_MDIO_AUTO_NEG_CONTROL,
395 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
396 autoneg_reg);
398 /* Wait for autonegotiation to finish */
399 for (time_out = 0; time_out < max_time_out; time_out++) {
400 udelay(10);
401 /* Restart PHY autonegotiation and wait for completion */
402 status = ixgbe_read_phy_reg(hw,
403 IXGBE_MDIO_AUTO_NEG_STATUS,
404 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
405 &autoneg_reg);
407 autoneg_reg &= autoneg_complete_mask;
408 if (autoneg_reg == autoneg_complete_mask) {
409 status = 0;
410 break;
414 if (time_out == max_time_out)
415 status = IXGBE_ERR_LINK_SETUP;
417 return status;
421 * ixgbe_check_tnx_phy_link - Determine link and speed status
422 * @hw: pointer to hardware structure
424 * Reads the VS1 register to determine if link is up and the current speed for
425 * the PHY.
427 s32 ixgbe_check_tnx_phy_link(struct ixgbe_hw *hw, u32 *speed,
428 bool *link_up)
430 s32 status = 0;
431 u32 time_out;
432 u32 max_time_out = 10;
433 u16 phy_link = 0;
434 u16 phy_speed = 0;
435 u16 phy_data = 0;
437 /* Initialize speed and link to default case */
438 *link_up = false;
439 *speed = IXGBE_LINK_SPEED_10GB_FULL;
442 * Check current speed and link status of the PHY register.
443 * This is a vendor specific register and may have to
444 * be changed for other copper PHYs.
446 for (time_out = 0; time_out < max_time_out; time_out++) {
447 udelay(10);
448 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
449 *link_up = true;
450 if (phy_speed ==
451 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
452 *speed = IXGBE_LINK_SPEED_1GB_FULL;
453 break;
454 } else {
455 status = ixgbe_read_phy_reg(hw,
456 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
457 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
458 &phy_data);
459 phy_link = phy_data &
460 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
461 phy_speed = phy_data &
462 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
466 return status;
470 * ixgbe_setup_tnx_phy_link_speed - Sets the auto advertised capabilities
471 * @hw: pointer to hardware structure
472 * @speed: new link speed
473 * @autoneg: true if autonegotiation enabled
475 s32 ixgbe_setup_tnx_phy_link_speed(struct ixgbe_hw *hw, u32 speed,
476 bool autoneg,
477 bool autoneg_wait_to_complete)
480 * Clear autoneg_advertised and set new values based on input link
481 * speed.
483 hw->phy.autoneg_advertised = 0;
485 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
486 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
487 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
488 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
490 /* Setup link based on the new speed settings */
491 ixgbe_setup_tnx_phy_link(hw);
493 return 0;