1 /******************************************************************************
3 Copyright (c) 2001-2008, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 #include "ixgbe_api.h"
36 #include "ixgbe_common.h"
37 #include "ixgbe_phy.h"
40 * ixgbe_init_phy_ops_generic - Inits PHY function ptrs
41 * @hw: pointer to the hardware structure
43 * Initialize the function pointers.
45 s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
47 struct ixgbe_phy_info *phy = &hw->phy;
50 phy->ops.identify = &ixgbe_identify_phy_generic;
51 phy->ops.reset = &ixgbe_reset_phy_generic;
52 phy->ops.read_reg = &ixgbe_read_phy_reg_generic;
53 phy->ops.write_reg = &ixgbe_write_phy_reg_generic;
54 phy->ops.setup_link = &ixgbe_setup_phy_link_generic;
55 phy->ops.setup_link_speed = &ixgbe_setup_phy_link_speed_generic;
56 phy->ops.check_link = NULL;
57 phy->ops.get_firmware_version = NULL;
63 * ixgbe_identify_phy_generic - Get physical layer module
64 * @hw: pointer to hardware structure
66 * Determines the physical layer module found on the current adapter.
68 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
70 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
73 if (hw->phy.type == ixgbe_phy_unknown) {
74 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
75 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
76 hw->phy.addr = phy_addr;
79 ixgbe_get_phy_type_from_id(hw->phy.id);
80 status = IXGBE_SUCCESS;
85 status = IXGBE_SUCCESS;
92 * ixgbe_validate_phy_addr - Determines phy address is valid
93 * @hw: pointer to hardware structure
96 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
101 hw->phy.addr = phy_addr;
102 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
103 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
105 if (phy_id != 0xFFFF && phy_id != 0x0)
112 * ixgbe_get_phy_id - Get the phy type
113 * @hw: pointer to hardware structure
116 s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
122 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
123 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
126 if (status == IXGBE_SUCCESS) {
127 hw->phy.id = (u32)(phy_id_high << 16);
128 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
129 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
131 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
132 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
139 * ixgbe_get_phy_type_from_id - Get the phy type
140 * @hw: pointer to hardware structure
143 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
145 enum ixgbe_phy_type phy_type;
149 phy_type = ixgbe_phy_tn;
152 phy_type = ixgbe_phy_qt;
155 phy_type = ixgbe_phy_unknown;
159 DEBUGOUT1("phy type found is %d\n", phy_type);
164 * ixgbe_reset_phy_generic - Performs a PHY reset
165 * @hw: pointer to hardware structure
167 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
170 * Perform soft PHY reset to the PHY_XS.
171 * This will cause a soft reset to the PHY
173 return hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
174 IXGBE_MDIO_PHY_XS_DEV_TYPE,
175 IXGBE_MDIO_PHY_XS_RESET);
179 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
180 * @hw: pointer to hardware structure
181 * @reg_addr: 32 bit address of PHY register to read
182 * @phy_data: Pointer to read data from PHY register
184 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
185 u32 device_type, u16 *phy_data)
190 s32 status = IXGBE_SUCCESS;
193 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
194 gssr = IXGBE_GSSR_PHY1_SM;
196 gssr = IXGBE_GSSR_PHY0_SM;
198 if (ixgbe_acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
199 status = IXGBE_ERR_SWFW_SYNC;
201 if (status == IXGBE_SUCCESS) {
202 /* Setup and write the address cycle command */
203 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
204 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
205 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
206 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
208 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
211 * Check every 10 usec to see if the address cycle completed.
212 * The MDI Command bit will clear when the operation is
215 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
218 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
220 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0) {
225 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
226 DEBUGOUT("PHY address command did not complete.\n");
227 status = IXGBE_ERR_PHY;
230 if (status == IXGBE_SUCCESS) {
232 * Address cycle complete, setup and write the read
235 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
236 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
237 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
238 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
240 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
243 * Check every 10 usec to see if the address cycle
244 * completed. The MDI Command bit will clear when the
245 * operation is complete
247 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
250 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
252 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
256 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
257 DEBUGOUT("PHY read command didn't complete\n");
258 status = IXGBE_ERR_PHY;
261 * Read operation is complete. Get the data
264 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
265 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
266 *phy_data = (u16)(data);
270 ixgbe_release_swfw_sync(hw, gssr);
277 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
278 * @hw: pointer to hardware structure
279 * @reg_addr: 32 bit PHY register to write
280 * @device_type: 5 bit device type
281 * @phy_data: Data to write to the PHY register
283 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
284 u32 device_type, u16 phy_data)
288 s32 status = IXGBE_SUCCESS;
291 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
292 gssr = IXGBE_GSSR_PHY1_SM;
294 gssr = IXGBE_GSSR_PHY0_SM;
296 if (ixgbe_acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
297 status = IXGBE_ERR_SWFW_SYNC;
299 if (status == IXGBE_SUCCESS) {
300 /* Put the data in the MDI single read and write data register*/
301 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
303 /* Setup and write the address cycle command */
304 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
305 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
306 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
307 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
309 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
312 * Check every 10 usec to see if the address cycle completed.
313 * The MDI Command bit will clear when the operation is
316 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
319 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
321 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
325 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
326 DEBUGOUT("PHY address cmd didn't complete\n");
327 status = IXGBE_ERR_PHY;
330 if (status == IXGBE_SUCCESS) {
332 * Address cycle complete, setup and write the write
335 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
336 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
337 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
338 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
340 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
343 * Check every 10 usec to see if the address cycle
344 * completed. The MDI Command bit will clear when the
345 * operation is complete
347 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
350 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
352 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
356 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
357 DEBUGOUT("PHY address cmd didn't complete\n");
358 status = IXGBE_ERR_PHY;
362 ixgbe_release_swfw_sync(hw, gssr);
369 * ixgbe_setup_phy_link_generic - Set and restart autoneg
370 * @hw: pointer to hardware structure
372 * Restart autonegotiation and PHY and waits for completion.
374 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
376 s32 status = IXGBE_NOT_IMPLEMENTED;
378 u32 max_time_out = 10;
379 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
382 * Set advertisement settings in PHY based on autoneg_advertised
383 * settings. If autoneg_advertised = 0, then advertise default values
384 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
387 hw->phy.ops.read_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
388 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
390 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
391 autoneg_reg &= 0xEFFF; /* 0 in bit 12 is 1G operation */
393 autoneg_reg |= 0x1000; /* 1 in bit 12 is 10G/1G operation */
395 hw->phy.ops.write_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
396 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
398 /* Restart PHY autonegotiation and wait for completion */
399 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
400 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
402 autoneg_reg |= IXGBE_MII_RESTART;
404 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
405 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
407 /* Wait for autonegotiation to finish */
408 for (time_out = 0; time_out < max_time_out; time_out++) {
410 /* Restart PHY autonegotiation and wait for completion */
411 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
412 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
415 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
416 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE) {
417 status = IXGBE_SUCCESS;
422 if (time_out == max_time_out)
423 status = IXGBE_ERR_LINK_SETUP;
429 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
430 * @hw: pointer to hardware structure
431 * @speed: new link speed
432 * @autoneg: TRUE if autonegotiation enabled
434 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
435 ixgbe_link_speed speed,
437 bool autoneg_wait_to_complete)
439 UNREFERENCED_PARAMETER(autoneg);
440 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
443 * Clear autoneg_advertised and set new values based on input link
446 hw->phy.autoneg_advertised = 0;
448 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
449 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
451 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
452 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
455 /* Setup link based on the new speed settings */
456 hw->phy.ops.setup_link(hw);
458 return IXGBE_SUCCESS;
462 * ixgbe_check_phy_link_tnx - Determine link and speed status
463 * @hw: pointer to hardware structure
465 * Reads the VS1 register to determine if link is up and the current speed for
468 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
471 s32 status = IXGBE_SUCCESS;
473 u32 max_time_out = 10;
478 /* Initialize speed and link to default case */
480 *speed = IXGBE_LINK_SPEED_10GB_FULL;
483 * Check current speed and link status of the PHY register.
484 * This is a vendor specific register and may have to
485 * be changed for other copper PHYs.
487 for (time_out = 0; time_out < max_time_out; time_out++) {
489 status = hw->phy.ops.read_reg(hw,
490 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
491 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
493 phy_link = phy_data &
494 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
495 phy_speed = phy_data &
496 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
497 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
500 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
501 *speed = IXGBE_LINK_SPEED_1GB_FULL;
510 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
511 * @hw: pointer to hardware structure
512 * @firmware_version: pointer to the PHY Firmware Version
514 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
515 u16 *firmware_version)
517 s32 status = IXGBE_SUCCESS;
519 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
520 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,