1 /*******************************************************************************
3 Copyright (c) 2001-2012, 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 ***************************************************************************/
34 #include "ixgbe_api.h"
35 #include "ixgbe_common.h"
36 #include "ixgbe_phy.h"
37 #ident "$Id: ixgbe_phy.c,v 1.139 2012/05/24 23:36:12 jtkirshe Exp $"
39 static void ixgbe_i2c_start(struct ixgbe_hw *hw);
40 static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
41 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
42 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
43 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
44 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
45 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
46 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
47 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
48 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
49 static bool ixgbe_get_i2c_data(u32 *i2cctl);
52 * ixgbe_init_phy_ops_generic - Inits PHY function ptrs
53 * @hw: pointer to the hardware structure
55 * Initialize the function pointers.
57 s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
59 struct ixgbe_phy_info *phy = &hw->phy;
61 DEBUGFUNC("ixgbe_init_phy_ops_generic");
64 phy->ops.identify = &ixgbe_identify_phy_generic;
65 phy->ops.reset = &ixgbe_reset_phy_generic;
66 phy->ops.read_reg = &ixgbe_read_phy_reg_generic;
67 phy->ops.write_reg = &ixgbe_write_phy_reg_generic;
68 phy->ops.setup_link = &ixgbe_setup_phy_link_generic;
69 phy->ops.setup_link_speed = &ixgbe_setup_phy_link_speed_generic;
70 phy->ops.check_link = NULL;
71 phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
72 phy->ops.read_i2c_byte = &ixgbe_read_i2c_byte_generic;
73 phy->ops.write_i2c_byte = &ixgbe_write_i2c_byte_generic;
74 phy->ops.read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic;
75 phy->ops.write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic;
76 phy->ops.i2c_bus_clear = &ixgbe_i2c_bus_clear;
77 phy->ops.identify_sfp = &ixgbe_identify_module_generic;
78 phy->sfp_type = ixgbe_sfp_type_unknown;
79 phy->ops.check_overtemp = &ixgbe_tn_check_overtemp;
84 * ixgbe_identify_phy_generic - Get physical layer module
85 * @hw: pointer to hardware structure
87 * Determines the physical layer module found on the current adapter.
89 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
91 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
95 DEBUGFUNC("ixgbe_identify_phy_generic");
97 if (hw->phy.type == ixgbe_phy_unknown) {
98 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
99 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
100 hw->phy.addr = phy_addr;
101 ixgbe_get_phy_id(hw);
103 ixgbe_get_phy_type_from_id(hw->phy.id);
105 if (hw->phy.type == ixgbe_phy_unknown) {
106 hw->phy.ops.read_reg(hw,
107 IXGBE_MDIO_PHY_EXT_ABILITY,
108 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
111 (IXGBE_MDIO_PHY_10GBASET_ABILITY |
112 IXGBE_MDIO_PHY_1000BASET_ABILITY))
114 ixgbe_phy_cu_unknown;
120 status = IXGBE_SUCCESS;
124 /* clear value if nothing found */
125 if (status != IXGBE_SUCCESS)
128 status = IXGBE_SUCCESS;
135 * ixgbe_validate_phy_addr - Determines phy address is valid
136 * @hw: pointer to hardware structure
139 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
144 DEBUGFUNC("ixgbe_validate_phy_addr");
146 hw->phy.addr = phy_addr;
147 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
148 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
150 if (phy_id != 0xFFFF && phy_id != 0x0)
157 * ixgbe_get_phy_id - Get the phy type
158 * @hw: pointer to hardware structure
161 s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
167 DEBUGFUNC("ixgbe_get_phy_id");
169 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
170 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
173 if (status == IXGBE_SUCCESS) {
174 hw->phy.id = (u32)(phy_id_high << 16);
175 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
176 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
178 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
179 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
185 * ixgbe_get_phy_type_from_id - Get the phy type
186 * @hw: pointer to hardware structure
189 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
191 enum ixgbe_phy_type phy_type;
193 DEBUGFUNC("ixgbe_get_phy_type_from_id");
197 phy_type = ixgbe_phy_tn;
200 phy_type = ixgbe_phy_aq;
203 phy_type = ixgbe_phy_qt;
206 phy_type = ixgbe_phy_nl;
209 phy_type = ixgbe_phy_unknown;
213 DEBUGOUT1("phy type found is %d\n", phy_type);
218 * ixgbe_reset_phy_generic - Performs a PHY reset
219 * @hw: pointer to hardware structure
221 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
225 s32 status = IXGBE_SUCCESS;
227 DEBUGFUNC("ixgbe_reset_phy_generic");
229 if (hw->phy.type == ixgbe_phy_unknown)
230 status = ixgbe_identify_phy_generic(hw);
232 if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
235 /* Don't reset PHY if it's shut down due to overtemp. */
236 if (!hw->phy.reset_if_overtemp &&
237 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
241 * Perform soft PHY reset to the PHY_XS.
242 * This will cause a soft reset to the PHY
244 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
245 IXGBE_MDIO_PHY_XS_DEV_TYPE,
246 IXGBE_MDIO_PHY_XS_RESET);
249 * Poll for reset bit to self-clear indicating reset is complete.
250 * Some PHYs could take up to 3 seconds to complete and need about
251 * 1.7 usec delay after the reset is complete.
253 for (i = 0; i < 30; i++) {
255 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
256 IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
257 if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
263 if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
264 status = IXGBE_ERR_RESET_FAILED;
265 DEBUGOUT("PHY reset polling failed to complete.\n");
273 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
274 * @hw: pointer to hardware structure
275 * @reg_addr: 32 bit address of PHY register to read
276 * @phy_data: Pointer to read data from PHY register
278 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
279 u32 device_type, u16 *phy_data)
284 s32 status = IXGBE_SUCCESS;
287 DEBUGFUNC("ixgbe_read_phy_reg_generic");
289 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
290 gssr = IXGBE_GSSR_PHY1_SM;
292 gssr = IXGBE_GSSR_PHY0_SM;
294 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
295 status = IXGBE_ERR_SWFW_SYNC;
297 if (status == IXGBE_SUCCESS) {
298 /* Setup and write the address cycle command */
299 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
300 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
301 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
302 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
304 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
307 * Check every 10 usec to see if the address cycle completed.
308 * The MDI Command bit will clear when the operation is
311 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
314 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
316 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
320 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
321 DEBUGOUT("PHY address command did not complete.\n");
322 status = IXGBE_ERR_PHY;
325 if (status == IXGBE_SUCCESS) {
327 * Address cycle complete, setup and write the read
330 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
331 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
332 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
333 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
335 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
338 * Check every 10 usec to see if the address cycle
339 * completed. The MDI Command bit will clear when the
340 * operation is complete
342 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
345 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
347 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
351 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
352 DEBUGOUT("PHY read command didn't complete\n");
353 status = IXGBE_ERR_PHY;
356 * Read operation is complete. Get the data
359 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
360 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
361 *phy_data = (u16)(data);
365 hw->mac.ops.release_swfw_sync(hw, gssr);
372 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
373 * @hw: pointer to hardware structure
374 * @reg_addr: 32 bit PHY register to write
375 * @device_type: 5 bit device type
376 * @phy_data: Data to write to the PHY register
378 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
379 u32 device_type, u16 phy_data)
383 s32 status = IXGBE_SUCCESS;
386 DEBUGFUNC("ixgbe_write_phy_reg_generic");
388 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
389 gssr = IXGBE_GSSR_PHY1_SM;
391 gssr = IXGBE_GSSR_PHY0_SM;
393 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
394 status = IXGBE_ERR_SWFW_SYNC;
396 if (status == IXGBE_SUCCESS) {
397 /* Put the data in the MDI single read and write data register*/
398 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
400 /* Setup and write the address cycle command */
401 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
402 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
403 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
404 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
406 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
409 * Check every 10 usec to see if the address cycle completed.
410 * The MDI Command bit will clear when the operation is
413 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
416 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
418 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
422 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
423 DEBUGOUT("PHY address cmd didn't complete\n");
424 status = IXGBE_ERR_PHY;
427 if (status == IXGBE_SUCCESS) {
429 * Address cycle complete, setup and write the write
432 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
433 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
434 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
435 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
437 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
440 * Check every 10 usec to see if the address cycle
441 * completed. The MDI Command bit will clear when the
442 * operation is complete
444 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
447 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
449 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
453 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
454 DEBUGOUT("PHY address cmd didn't complete\n");
455 status = IXGBE_ERR_PHY;
459 hw->mac.ops.release_swfw_sync(hw, gssr);
466 * ixgbe_setup_phy_link_generic - Set and restart autoneg
467 * @hw: pointer to hardware structure
469 * Restart autonegotiation and PHY and waits for completion.
471 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
473 s32 status = IXGBE_SUCCESS;
475 u32 max_time_out = 10;
476 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
477 bool autoneg = false;
478 ixgbe_link_speed speed;
480 DEBUGFUNC("ixgbe_setup_phy_link_generic");
482 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
484 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
485 /* Set or unset auto-negotiation 10G advertisement */
486 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
487 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
490 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
491 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
492 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
494 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
495 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
499 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
500 /* Set or unset auto-negotiation 1G advertisement */
501 hw->phy.ops.read_reg(hw,
502 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
503 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
506 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
507 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
508 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
510 hw->phy.ops.write_reg(hw,
511 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
512 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
516 if (speed & IXGBE_LINK_SPEED_100_FULL) {
517 /* Set or unset auto-negotiation 100M advertisement */
518 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
519 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
522 autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
523 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
524 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
525 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
527 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
528 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
532 /* Restart PHY autonegotiation and wait for completion */
533 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
534 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
536 autoneg_reg |= IXGBE_MII_RESTART;
538 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
539 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
541 /* Wait for autonegotiation to finish */
542 for (time_out = 0; time_out < max_time_out; time_out++) {
544 /* Restart PHY autonegotiation and wait for completion */
545 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
546 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
549 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
550 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
554 if (time_out == max_time_out) {
555 status = IXGBE_ERR_LINK_SETUP;
556 DEBUGOUT("ixgbe_setup_phy_link_generic: time out");
563 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
564 * @hw: pointer to hardware structure
565 * @speed: new link speed
566 * @autoneg: true if autonegotiation enabled
568 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
569 ixgbe_link_speed speed,
571 bool autoneg_wait_to_complete)
574 DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
577 * Clear autoneg_advertised and set new values based on input link
580 hw->phy.autoneg_advertised = 0;
582 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
583 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
585 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
586 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
588 if (speed & IXGBE_LINK_SPEED_100_FULL)
589 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
591 /* Setup link based on the new speed settings */
592 hw->phy.ops.setup_link(hw);
594 return IXGBE_SUCCESS;
598 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
599 * @hw: pointer to hardware structure
600 * @speed: pointer to link speed
601 * @autoneg: boolean auto-negotiation value
603 * Determines the link capabilities by reading the AUTOC register.
605 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
606 ixgbe_link_speed *speed,
609 s32 status = IXGBE_ERR_LINK_SETUP;
612 DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
617 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
618 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
621 if (status == IXGBE_SUCCESS) {
622 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
623 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
624 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
625 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
626 if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
627 *speed |= IXGBE_LINK_SPEED_100_FULL;
634 * ixgbe_check_phy_link_tnx - Determine link and speed status
635 * @hw: pointer to hardware structure
637 * Reads the VS1 register to determine if link is up and the current speed for
640 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
643 s32 status = IXGBE_SUCCESS;
645 u32 max_time_out = 10;
650 DEBUGFUNC("ixgbe_check_phy_link_tnx");
652 /* Initialize speed and link to default case */
654 *speed = IXGBE_LINK_SPEED_10GB_FULL;
657 * Check current speed and link status of the PHY register.
658 * This is a vendor specific register and may have to
659 * be changed for other copper PHYs.
661 for (time_out = 0; time_out < max_time_out; time_out++) {
663 status = hw->phy.ops.read_reg(hw,
664 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
665 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
667 phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
668 phy_speed = phy_data &
669 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
670 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
673 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
674 *speed = IXGBE_LINK_SPEED_1GB_FULL;
683 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
684 * @hw: pointer to hardware structure
686 * Restart autonegotiation and PHY and waits for completion.
688 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
690 s32 status = IXGBE_SUCCESS;
692 u32 max_time_out = 10;
693 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
694 bool autoneg = false;
695 ixgbe_link_speed speed;
697 DEBUGFUNC("ixgbe_setup_phy_link_tnx");
699 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
701 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
702 /* Set or unset auto-negotiation 10G advertisement */
703 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
704 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
707 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
708 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
709 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
711 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
712 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
716 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
717 /* Set or unset auto-negotiation 1G advertisement */
718 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
719 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
722 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
723 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
724 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
726 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
727 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
731 if (speed & IXGBE_LINK_SPEED_100_FULL) {
732 /* Set or unset auto-negotiation 100M advertisement */
733 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
734 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
737 autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
738 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
739 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
741 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
742 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
746 /* Restart PHY autonegotiation and wait for completion */
747 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
748 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
750 autoneg_reg |= IXGBE_MII_RESTART;
752 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
753 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
755 /* Wait for autonegotiation to finish */
756 for (time_out = 0; time_out < max_time_out; time_out++) {
758 /* Restart PHY autonegotiation and wait for completion */
759 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
760 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
763 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
764 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
768 if (time_out == max_time_out) {
769 status = IXGBE_ERR_LINK_SETUP;
770 DEBUGOUT("ixgbe_setup_phy_link_tnx: time out");
777 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
778 * @hw: pointer to hardware structure
779 * @firmware_version: pointer to the PHY Firmware Version
781 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
782 u16 *firmware_version)
784 s32 status = IXGBE_SUCCESS;
786 DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
788 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
789 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
796 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
797 * @hw: pointer to hardware structure
798 * @firmware_version: pointer to the PHY Firmware Version
800 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
801 u16 *firmware_version)
803 s32 status = IXGBE_SUCCESS;
805 DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
807 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
808 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
815 * ixgbe_reset_phy_nl - Performs a PHY reset
816 * @hw: pointer to hardware structure
818 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
820 u16 phy_offset, control, eword, edata, block_crc;
821 bool end_data = false;
822 u16 list_offset, data_offset;
824 s32 ret_val = IXGBE_SUCCESS;
827 DEBUGFUNC("ixgbe_reset_phy_nl");
829 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
830 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
832 /* reset the PHY and poll for completion */
833 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
834 IXGBE_MDIO_PHY_XS_DEV_TYPE,
835 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
837 for (i = 0; i < 100; i++) {
838 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
839 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
840 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
845 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
846 DEBUGOUT("PHY reset did not complete.\n");
847 ret_val = IXGBE_ERR_PHY;
851 /* Get init offsets */
852 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
854 if (ret_val != IXGBE_SUCCESS)
857 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
861 * Read control word from PHY init contents offset
863 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
864 control = (eword & IXGBE_CONTROL_MASK_NL) >>
865 IXGBE_CONTROL_SHIFT_NL;
866 edata = eword & IXGBE_DATA_MASK_NL;
870 DEBUGOUT1("DELAY: %d MS\n", edata);
876 hw->eeprom.ops.read(hw, data_offset++,
878 for (i = 0; i < edata; i++) {
879 hw->eeprom.ops.read(hw, data_offset, &eword);
880 hw->phy.ops.write_reg(hw, phy_offset,
881 IXGBE_TWINAX_DEV, eword);
882 DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
888 case IXGBE_CONTROL_NL:
890 DEBUGOUT("CONTROL:\n");
891 if (edata == IXGBE_CONTROL_EOL_NL) {
894 } else if (edata == IXGBE_CONTROL_SOL_NL) {
897 DEBUGOUT("Bad control value\n");
898 ret_val = IXGBE_ERR_PHY;
903 DEBUGOUT("Bad control type\n");
904 ret_val = IXGBE_ERR_PHY;
914 * ixgbe_identify_module_generic - Identifies module type
915 * @hw: pointer to hardware structure
917 * Determines HW type and calls appropriate function.
919 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
921 s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
923 DEBUGFUNC("ixgbe_identify_module_generic");
925 switch (hw->mac.ops.get_media_type(hw)) {
926 case ixgbe_media_type_fiber:
927 status = ixgbe_identify_sfp_module_generic(hw);
932 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
933 status = IXGBE_ERR_SFP_NOT_PRESENT;
941 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
942 * @hw: pointer to hardware structure
944 * Searches for and identifies the SFP module and assigns appropriate PHY type.
946 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
948 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
950 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
952 u8 comp_codes_1g = 0;
953 u8 comp_codes_10g = 0;
954 u8 oui_bytes[3] = {0, 0, 0};
959 DEBUGFUNC("ixgbe_identify_sfp_module_generic");
961 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
962 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
963 status = IXGBE_ERR_SFP_NOT_PRESENT;
967 status = hw->phy.ops.read_i2c_eeprom(hw,
968 IXGBE_SFF_IDENTIFIER,
971 if (status == IXGBE_ERR_SWFW_SYNC ||
972 status == IXGBE_ERR_I2C ||
973 status == IXGBE_ERR_SFP_NOT_PRESENT)
974 goto err_read_i2c_eeprom;
976 /* LAN ID is needed for sfp_type determination */
977 hw->mac.ops.set_lan_id(hw);
979 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
980 hw->phy.type = ixgbe_phy_sfp_unsupported;
981 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
983 status = hw->phy.ops.read_i2c_eeprom(hw,
984 IXGBE_SFF_1GBE_COMP_CODES,
987 if (status == IXGBE_ERR_SWFW_SYNC ||
988 status == IXGBE_ERR_I2C ||
989 status == IXGBE_ERR_SFP_NOT_PRESENT)
990 goto err_read_i2c_eeprom;
992 status = hw->phy.ops.read_i2c_eeprom(hw,
993 IXGBE_SFF_10GBE_COMP_CODES,
996 if (status == IXGBE_ERR_SWFW_SYNC ||
997 status == IXGBE_ERR_I2C ||
998 status == IXGBE_ERR_SFP_NOT_PRESENT)
999 goto err_read_i2c_eeprom;
1000 status = hw->phy.ops.read_i2c_eeprom(hw,
1001 IXGBE_SFF_CABLE_TECHNOLOGY,
1004 if (status == IXGBE_ERR_SWFW_SYNC ||
1005 status == IXGBE_ERR_I2C ||
1006 status == IXGBE_ERR_SFP_NOT_PRESENT)
1007 goto err_read_i2c_eeprom;
1014 * 3 SFP_DA_CORE0 - 82599-specific
1015 * 4 SFP_DA_CORE1 - 82599-specific
1016 * 5 SFP_SR/LR_CORE0 - 82599-specific
1017 * 6 SFP_SR/LR_CORE1 - 82599-specific
1018 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1019 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1020 * 9 SFP_1g_cu_CORE0 - 82599-specific
1021 * 10 SFP_1g_cu_CORE1 - 82599-specific
1022 * 11 SFP_1g_sx_CORE0 - 82599-specific
1023 * 12 SFP_1g_sx_CORE1 - 82599-specific
1025 if (hw->mac.type == ixgbe_mac_82598EB) {
1026 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1027 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1028 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1029 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1030 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1031 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1033 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1034 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1035 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1036 if (hw->bus.lan_id == 0)
1038 ixgbe_sfp_type_da_cu_core0;
1041 ixgbe_sfp_type_da_cu_core1;
1042 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1043 hw->phy.ops.read_i2c_eeprom(
1044 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1047 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1048 if (hw->bus.lan_id == 0)
1050 ixgbe_sfp_type_da_act_lmt_core0;
1053 ixgbe_sfp_type_da_act_lmt_core1;
1056 ixgbe_sfp_type_unknown;
1058 } else if (comp_codes_10g &
1059 (IXGBE_SFF_10GBASESR_CAPABLE |
1060 IXGBE_SFF_10GBASELR_CAPABLE)) {
1061 if (hw->bus.lan_id == 0)
1063 ixgbe_sfp_type_srlr_core0;
1066 ixgbe_sfp_type_srlr_core1;
1067 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1068 if (hw->bus.lan_id == 0)
1070 ixgbe_sfp_type_1g_cu_core0;
1073 ixgbe_sfp_type_1g_cu_core1;
1074 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1075 if (hw->bus.lan_id == 0)
1077 ixgbe_sfp_type_1g_sx_core0;
1080 ixgbe_sfp_type_1g_sx_core1;
1082 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1086 if (hw->phy.sfp_type != stored_sfp_type)
1087 hw->phy.sfp_setup_needed = true;
1089 /* Determine if the SFP+ PHY is dual speed or not. */
1090 hw->phy.multispeed_fiber = false;
1091 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1092 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1093 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1094 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1095 hw->phy.multispeed_fiber = true;
1097 /* Determine PHY vendor */
1098 if (hw->phy.type != ixgbe_phy_nl) {
1099 hw->phy.id = identifier;
1100 status = hw->phy.ops.read_i2c_eeprom(hw,
1101 IXGBE_SFF_VENDOR_OUI_BYTE0,
1104 if (status == IXGBE_ERR_SWFW_SYNC ||
1105 status == IXGBE_ERR_I2C ||
1106 status == IXGBE_ERR_SFP_NOT_PRESENT)
1107 goto err_read_i2c_eeprom;
1109 status = hw->phy.ops.read_i2c_eeprom(hw,
1110 IXGBE_SFF_VENDOR_OUI_BYTE1,
1113 if (status == IXGBE_ERR_SWFW_SYNC ||
1114 status == IXGBE_ERR_I2C ||
1115 status == IXGBE_ERR_SFP_NOT_PRESENT)
1116 goto err_read_i2c_eeprom;
1118 status = hw->phy.ops.read_i2c_eeprom(hw,
1119 IXGBE_SFF_VENDOR_OUI_BYTE2,
1122 if (status == IXGBE_ERR_SWFW_SYNC ||
1123 status == IXGBE_ERR_I2C ||
1124 status == IXGBE_ERR_SFP_NOT_PRESENT)
1125 goto err_read_i2c_eeprom;
1128 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1129 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1130 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1132 switch (vendor_oui) {
1133 case IXGBE_SFF_VENDOR_OUI_TYCO:
1134 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1136 ixgbe_phy_sfp_passive_tyco;
1138 case IXGBE_SFF_VENDOR_OUI_FTL:
1139 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1140 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1142 hw->phy.type = ixgbe_phy_sfp_ftl;
1144 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1145 hw->phy.type = ixgbe_phy_sfp_avago;
1147 case IXGBE_SFF_VENDOR_OUI_INTEL:
1148 hw->phy.type = ixgbe_phy_sfp_intel;
1151 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1153 ixgbe_phy_sfp_passive_unknown;
1154 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1156 ixgbe_phy_sfp_active_unknown;
1158 hw->phy.type = ixgbe_phy_sfp_unknown;
1163 /* Allow any DA cable vendor */
1164 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1165 IXGBE_SFF_DA_ACTIVE_CABLE)) {
1166 status = IXGBE_SUCCESS;
1170 /* Verify supported 1G SFP modules */
1171 if (comp_codes_10g == 0 &&
1172 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1173 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1174 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1175 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1176 hw->phy.type = ixgbe_phy_sfp_unsupported;
1177 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1181 /* Anything else 82598-based is supported */
1182 if (hw->mac.type == ixgbe_mac_82598EB) {
1183 status = IXGBE_SUCCESS;
1187 ixgbe_get_device_caps(hw, &enforce_sfp);
1188 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1189 !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) ||
1190 (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) ||
1191 (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0) ||
1192 (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1))) {
1193 /* Make sure we're a supported PHY type */
1194 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1195 status = IXGBE_SUCCESS;
1197 if (hw->allow_unsupported_sfp == true) {
1198 EWARN(hw, "WARNING: Intel (R) Network "
1199 "Connections are quality tested "
1200 "using Intel (R) Ethernet Optics."
1201 " Using untested modules is not "
1202 "supported and may cause unstable"
1203 " operation or damage to the "
1204 "module or the adapter. Intel "
1205 "Corporation is not responsible "
1206 "for any harm caused by using "
1207 "untested modules.\n", status);
1208 status = IXGBE_SUCCESS;
1210 DEBUGOUT("SFP+ module not supported\n");
1212 ixgbe_phy_sfp_unsupported;
1213 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1217 status = IXGBE_SUCCESS;
1224 err_read_i2c_eeprom:
1225 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1226 if (hw->phy.type != ixgbe_phy_nl) {
1228 hw->phy.type = ixgbe_phy_unknown;
1230 return IXGBE_ERR_SFP_NOT_PRESENT;
1236 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1237 * @hw: pointer to hardware structure
1238 * @list_offset: offset to the SFP ID list
1239 * @data_offset: offset to the SFP data block
1241 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1242 * so it returns the offsets to the phy init sequence block.
1244 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1249 u16 sfp_type = hw->phy.sfp_type;
1251 DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
1253 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1254 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1256 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1257 return IXGBE_ERR_SFP_NOT_PRESENT;
1259 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1260 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1261 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1264 * Limiting active cables and 1G Phys must be initialized as
1267 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1268 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1269 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1270 sfp_type = ixgbe_sfp_type_srlr_core0;
1271 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1272 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1273 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1274 sfp_type = ixgbe_sfp_type_srlr_core1;
1276 /* Read offset to PHY init contents */
1277 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
1279 if ((!*list_offset) || (*list_offset == 0xFFFF))
1280 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1282 /* Shift offset to first ID word */
1286 * Find the matching SFP ID in the EEPROM
1287 * and program the init sequence
1289 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
1291 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1292 if (sfp_id == sfp_type) {
1294 hw->eeprom.ops.read(hw, *list_offset, data_offset);
1295 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1296 DEBUGOUT("SFP+ module not supported\n");
1297 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1302 (*list_offset) += 2;
1303 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1304 return IXGBE_ERR_PHY;
1308 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1309 DEBUGOUT("No matching SFP+ module found\n");
1310 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1313 return IXGBE_SUCCESS;
1317 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1318 * @hw: pointer to hardware structure
1319 * @byte_offset: EEPROM byte offset to read
1320 * @eeprom_data: value read
1322 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1324 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1327 DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
1329 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1330 IXGBE_I2C_EEPROM_DEV_ADDR,
1335 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1336 * @hw: pointer to hardware structure
1337 * @byte_offset: EEPROM byte offset to write
1338 * @eeprom_data: value to write
1340 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1342 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1345 DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
1347 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1348 IXGBE_I2C_EEPROM_DEV_ADDR,
1353 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1354 * @hw: pointer to hardware structure
1355 * @byte_offset: byte offset to read
1358 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1359 * a specified device address.
1361 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1362 u8 dev_addr, u8 *data)
1364 s32 status = IXGBE_SUCCESS;
1371 DEBUGFUNC("ixgbe_read_i2c_byte_generic");
1373 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1374 swfw_mask = IXGBE_GSSR_PHY1_SM;
1376 swfw_mask = IXGBE_GSSR_PHY0_SM;
1379 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
1381 status = IXGBE_ERR_SWFW_SYNC;
1385 ixgbe_i2c_start(hw);
1387 /* Device Address and write indication */
1388 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1389 if (status != IXGBE_SUCCESS)
1392 status = ixgbe_get_i2c_ack(hw);
1393 if (status != IXGBE_SUCCESS)
1396 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1397 if (status != IXGBE_SUCCESS)
1400 status = ixgbe_get_i2c_ack(hw);
1401 if (status != IXGBE_SUCCESS)
1404 ixgbe_i2c_start(hw);
1406 /* Device Address and read indication */
1407 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1408 if (status != IXGBE_SUCCESS)
1411 status = ixgbe_get_i2c_ack(hw);
1412 if (status != IXGBE_SUCCESS)
1415 status = ixgbe_clock_in_i2c_byte(hw, data);
1416 if (status != IXGBE_SUCCESS)
1419 status = ixgbe_clock_out_i2c_bit(hw, nack);
1420 if (status != IXGBE_SUCCESS)
1427 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1429 ixgbe_i2c_bus_clear(hw);
1431 if (retry < max_retry)
1432 DEBUGOUT("I2C byte read error - Retrying.\n");
1434 DEBUGOUT("I2C byte read error.\n");
1436 } while (retry < max_retry);
1438 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1445 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1446 * @hw: pointer to hardware structure
1447 * @byte_offset: byte offset to write
1448 * @data: value to write
1450 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1451 * a specified device address.
1453 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1454 u8 dev_addr, u8 data)
1456 s32 status = IXGBE_SUCCESS;
1461 DEBUGFUNC("ixgbe_write_i2c_byte_generic");
1463 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1464 swfw_mask = IXGBE_GSSR_PHY1_SM;
1466 swfw_mask = IXGBE_GSSR_PHY0_SM;
1468 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != IXGBE_SUCCESS) {
1469 status = IXGBE_ERR_SWFW_SYNC;
1470 goto write_byte_out;
1474 ixgbe_i2c_start(hw);
1476 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1477 if (status != IXGBE_SUCCESS)
1480 status = ixgbe_get_i2c_ack(hw);
1481 if (status != IXGBE_SUCCESS)
1484 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1485 if (status != IXGBE_SUCCESS)
1488 status = ixgbe_get_i2c_ack(hw);
1489 if (status != IXGBE_SUCCESS)
1492 status = ixgbe_clock_out_i2c_byte(hw, data);
1493 if (status != IXGBE_SUCCESS)
1496 status = ixgbe_get_i2c_ack(hw);
1497 if (status != IXGBE_SUCCESS)
1504 ixgbe_i2c_bus_clear(hw);
1506 if (retry < max_retry)
1507 DEBUGOUT("I2C byte write error - Retrying.\n");
1509 DEBUGOUT("I2C byte write error.\n");
1510 } while (retry < max_retry);
1512 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1519 * ixgbe_i2c_start - Sets I2C start condition
1520 * @hw: pointer to hardware structure
1522 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1524 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1526 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1528 DEBUGFUNC("ixgbe_i2c_start");
1530 /* Start condition must begin with data and clock high */
1531 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1532 ixgbe_raise_i2c_clk(hw, &i2cctl);
1534 /* Setup time for start condition (4.7us) */
1535 usec_delay(IXGBE_I2C_T_SU_STA);
1537 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1539 /* Hold time for start condition (4us) */
1540 usec_delay(IXGBE_I2C_T_HD_STA);
1542 ixgbe_lower_i2c_clk(hw, &i2cctl);
1544 /* Minimum low period of clock is 4.7 us */
1545 usec_delay(IXGBE_I2C_T_LOW);
1550 * ixgbe_i2c_stop - Sets I2C stop condition
1551 * @hw: pointer to hardware structure
1553 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1555 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1557 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1559 DEBUGFUNC("ixgbe_i2c_stop");
1561 /* Stop condition must begin with data low and clock high */
1562 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1563 ixgbe_raise_i2c_clk(hw, &i2cctl);
1565 /* Setup time for stop condition (4us) */
1566 usec_delay(IXGBE_I2C_T_SU_STO);
1568 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1570 /* bus free time between stop and start (4.7us)*/
1571 usec_delay(IXGBE_I2C_T_BUF);
1575 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1576 * @hw: pointer to hardware structure
1577 * @data: data byte to clock in
1579 * Clocks in one byte data via I2C data/clock
1581 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1586 DEBUGFUNC("ixgbe_clock_in_i2c_byte");
1588 for (i = 7; i >= 0; i--) {
1589 ixgbe_clock_in_i2c_bit(hw, &bit);
1593 return IXGBE_SUCCESS;
1597 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1598 * @hw: pointer to hardware structure
1599 * @data: data byte clocked out
1601 * Clocks out one byte data via I2C data/clock
1603 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1605 s32 status = IXGBE_SUCCESS;
1610 DEBUGFUNC("ixgbe_clock_out_i2c_byte");
1612 for (i = 7; i >= 0; i--) {
1613 bit = (data >> i) & 0x1;
1614 status = ixgbe_clock_out_i2c_bit(hw, bit);
1616 if (status != IXGBE_SUCCESS)
1620 /* Release SDA line (set high) */
1621 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1622 i2cctl |= IXGBE_I2C_DATA_OUT;
1623 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1624 IXGBE_WRITE_FLUSH(hw);
1630 * ixgbe_get_i2c_ack - Polls for I2C ACK
1631 * @hw: pointer to hardware structure
1633 * Clocks in/out one bit via I2C data/clock
1635 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1637 s32 status = IXGBE_SUCCESS;
1639 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1643 DEBUGFUNC("ixgbe_get_i2c_ack");
1645 ixgbe_raise_i2c_clk(hw, &i2cctl);
1648 /* Minimum high period of clock is 4us */
1649 usec_delay(IXGBE_I2C_T_HIGH);
1651 /* Poll for ACK. Note that ACK in I2C spec is
1652 * transition from 1 to 0 */
1653 for (i = 0; i < timeout; i++) {
1654 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1655 ack = ixgbe_get_i2c_data(&i2cctl);
1663 DEBUGOUT("I2C ack was not received.\n");
1664 status = IXGBE_ERR_I2C;
1667 ixgbe_lower_i2c_clk(hw, &i2cctl);
1669 /* Minimum low period of clock is 4.7 us */
1670 usec_delay(IXGBE_I2C_T_LOW);
1676 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1677 * @hw: pointer to hardware structure
1678 * @data: read data value
1680 * Clocks in one bit via I2C data/clock
1682 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1684 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1686 DEBUGFUNC("ixgbe_clock_in_i2c_bit");
1688 ixgbe_raise_i2c_clk(hw, &i2cctl);
1690 /* Minimum high period of clock is 4us */
1691 usec_delay(IXGBE_I2C_T_HIGH);
1693 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1694 *data = ixgbe_get_i2c_data(&i2cctl);
1696 ixgbe_lower_i2c_clk(hw, &i2cctl);
1698 /* Minimum low period of clock is 4.7 us */
1699 usec_delay(IXGBE_I2C_T_LOW);
1701 return IXGBE_SUCCESS;
1705 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1706 * @hw: pointer to hardware structure
1707 * @data: data value to write
1709 * Clocks out one bit via I2C data/clock
1711 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1714 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1716 DEBUGFUNC("ixgbe_clock_out_i2c_bit");
1718 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1719 if (status == IXGBE_SUCCESS) {
1720 ixgbe_raise_i2c_clk(hw, &i2cctl);
1722 /* Minimum high period of clock is 4us */
1723 usec_delay(IXGBE_I2C_T_HIGH);
1725 ixgbe_lower_i2c_clk(hw, &i2cctl);
1727 /* Minimum low period of clock is 4.7 us.
1728 * This also takes care of the data hold time.
1730 usec_delay(IXGBE_I2C_T_LOW);
1732 status = IXGBE_ERR_I2C;
1733 DEBUGOUT1("I2C data was not set to %X\n", data);
1739 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1740 * @hw: pointer to hardware structure
1741 * @i2cctl: Current value of I2CCTL register
1743 * Raises the I2C clock line '0'->'1'
1745 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1748 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1751 DEBUGFUNC("ixgbe_raise_i2c_clk");
1753 for (i = 0; i < timeout; i++) {
1754 *i2cctl |= IXGBE_I2C_CLK_OUT;
1756 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1757 IXGBE_WRITE_FLUSH(hw);
1758 /* SCL rise time (1000ns) */
1759 usec_delay(IXGBE_I2C_T_RISE);
1761 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1762 if (i2cctl_r & IXGBE_I2C_CLK_IN)
1768 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1769 * @hw: pointer to hardware structure
1770 * @i2cctl: Current value of I2CCTL register
1772 * Lowers the I2C clock line '1'->'0'
1774 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1777 DEBUGFUNC("ixgbe_lower_i2c_clk");
1779 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1781 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1782 IXGBE_WRITE_FLUSH(hw);
1784 /* SCL fall time (300ns) */
1785 usec_delay(IXGBE_I2C_T_FALL);
1789 * ixgbe_set_i2c_data - Sets the I2C data bit
1790 * @hw: pointer to hardware structure
1791 * @i2cctl: Current value of I2CCTL register
1792 * @data: I2C data value (0 or 1) to set
1794 * Sets the I2C data bit
1796 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1798 s32 status = IXGBE_SUCCESS;
1800 DEBUGFUNC("ixgbe_set_i2c_data");
1803 *i2cctl |= IXGBE_I2C_DATA_OUT;
1805 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1807 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1808 IXGBE_WRITE_FLUSH(hw);
1810 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1811 usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1813 /* Verify data was set correctly */
1814 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1815 if (data != ixgbe_get_i2c_data(i2cctl)) {
1816 status = IXGBE_ERR_I2C;
1817 DEBUGOUT1("Error - I2C data was not set to %X.\n", data);
1824 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1825 * @hw: pointer to hardware structure
1826 * @i2cctl: Current value of I2CCTL register
1828 * Returns the I2C data bit value
1830 static bool ixgbe_get_i2c_data(u32 *i2cctl)
1834 DEBUGFUNC("ixgbe_get_i2c_data");
1836 if (*i2cctl & IXGBE_I2C_DATA_IN)
1845 * ixgbe_i2c_bus_clear - Clears the I2C bus
1846 * @hw: pointer to hardware structure
1848 * Clears the I2C bus by sending nine clock pulses.
1849 * Used when data line is stuck low.
1851 void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1853 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1856 DEBUGFUNC("ixgbe_i2c_bus_clear");
1858 ixgbe_i2c_start(hw);
1860 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1862 for (i = 0; i < 9; i++) {
1863 ixgbe_raise_i2c_clk(hw, &i2cctl);
1865 /* Min high period of clock is 4us */
1866 usec_delay(IXGBE_I2C_T_HIGH);
1868 ixgbe_lower_i2c_clk(hw, &i2cctl);
1870 /* Min low period of clock is 4.7us*/
1871 usec_delay(IXGBE_I2C_T_LOW);
1874 ixgbe_i2c_start(hw);
1876 /* Put the i2c bus back to default state */
1881 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
1882 * @hw: pointer to hardware structure
1884 * Checks if the LASI temp alarm status was triggered due to overtemp
1886 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1888 s32 status = IXGBE_SUCCESS;
1891 DEBUGFUNC("ixgbe_tn_check_overtemp");
1893 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
1896 /* Check that the LASI temp alarm status was triggered */
1897 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
1898 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
1900 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
1903 status = IXGBE_ERR_OVERTEMP;