1 /*******************************************************************************
3 Copyright (c) 2001-2014, 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.155 2013/08/14 22:34:03 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);
50 STATIC s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
54 * ixgbe_init_phy_ops_generic - Inits PHY function ptrs
55 * @hw: pointer to the hardware structure
57 * Initialize the function pointers.
59 s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
61 struct ixgbe_phy_info *phy = &hw->phy;
63 DEBUGFUNC("ixgbe_init_phy_ops_generic");
66 phy->ops.identify = &ixgbe_identify_phy_generic;
67 phy->ops.reset = &ixgbe_reset_phy_generic;
68 phy->ops.read_reg = &ixgbe_read_phy_reg_generic;
69 phy->ops.write_reg = &ixgbe_write_phy_reg_generic;
70 phy->ops.read_reg_mdi = &ixgbe_read_phy_reg_mdi;
71 phy->ops.write_reg_mdi = &ixgbe_write_phy_reg_mdi;
72 phy->ops.setup_link = &ixgbe_setup_phy_link_generic;
73 phy->ops.setup_link_speed = &ixgbe_setup_phy_link_speed_generic;
74 phy->ops.check_link = NULL;
75 phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
76 phy->ops.read_i2c_byte = &ixgbe_read_i2c_byte_generic;
77 phy->ops.write_i2c_byte = &ixgbe_write_i2c_byte_generic;
78 phy->ops.read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic;
79 phy->ops.read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic;
80 phy->ops.write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic;
81 phy->ops.i2c_bus_clear = &ixgbe_i2c_bus_clear;
82 phy->ops.identify_sfp = &ixgbe_identify_module_generic;
83 phy->sfp_type = ixgbe_sfp_type_unknown;
84 phy->ops.check_overtemp = &ixgbe_tn_check_overtemp;
89 * ixgbe_identify_phy_generic - Get physical layer module
90 * @hw: pointer to hardware structure
92 * Determines the physical layer module found on the current adapter.
94 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
96 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
100 DEBUGFUNC("ixgbe_identify_phy_generic");
102 if (hw->phy.type == ixgbe_phy_unknown) {
103 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
104 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
105 hw->phy.addr = phy_addr;
106 ixgbe_get_phy_id(hw);
108 ixgbe_get_phy_type_from_id(hw->phy.id);
110 if (hw->phy.type == ixgbe_phy_unknown) {
111 hw->phy.ops.read_reg(hw,
112 IXGBE_MDIO_PHY_EXT_ABILITY,
113 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
116 (IXGBE_MDIO_PHY_10GBASET_ABILITY |
117 IXGBE_MDIO_PHY_1000BASET_ABILITY))
119 ixgbe_phy_cu_unknown;
125 status = IXGBE_SUCCESS;
130 /* Certain media types do not have a phy so an address will not
131 * be found and the code will take this path. Caller has to
132 * decide if it is an error or not.
134 if (status != IXGBE_SUCCESS) {
138 status = IXGBE_SUCCESS;
145 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
146 * @hw: pointer to the hardware structure
148 * This function checks the MMNGC.MNG_VETO bit to see if there are
149 * any constraints on link from manageability. For MAC's that don't
150 * have this bit just return faluse since the link can not be blocked
153 s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
157 DEBUGFUNC("ixgbe_check_reset_blocked");
159 /* If we don't have this bit, it can't be blocking */
160 if (hw->mac.type == ixgbe_mac_82598EB)
163 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
164 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
165 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
166 "MNG_VETO bit detected.\n");
174 * ixgbe_validate_phy_addr - Determines phy address is valid
175 * @hw: pointer to hardware structure
178 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
183 DEBUGFUNC("ixgbe_validate_phy_addr");
185 hw->phy.addr = phy_addr;
186 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
187 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
189 if (phy_id != 0xFFFF && phy_id != 0x0)
196 * ixgbe_get_phy_id - Get the phy type
197 * @hw: pointer to hardware structure
200 s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
206 DEBUGFUNC("ixgbe_get_phy_id");
208 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
209 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
212 if (status == IXGBE_SUCCESS) {
213 hw->phy.id = (u32)(phy_id_high << 16);
214 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
215 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
217 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
218 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
224 * ixgbe_get_phy_type_from_id - Get the phy type
225 * @hw: pointer to hardware structure
228 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
230 enum ixgbe_phy_type phy_type;
232 DEBUGFUNC("ixgbe_get_phy_type_from_id");
236 phy_type = ixgbe_phy_tn;
239 phy_type = ixgbe_phy_aq;
242 phy_type = ixgbe_phy_qt;
245 phy_type = ixgbe_phy_nl;
248 phy_type = ixgbe_phy_unknown;
252 DEBUGOUT1("phy type found is %d\n", phy_type);
257 * ixgbe_reset_phy_generic - Performs a PHY reset
258 * @hw: pointer to hardware structure
260 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
264 s32 status = IXGBE_SUCCESS;
266 DEBUGFUNC("ixgbe_reset_phy_generic");
268 if (hw->phy.type == ixgbe_phy_unknown)
269 status = ixgbe_identify_phy_generic(hw);
271 if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
274 /* Don't reset PHY if it's shut down due to overtemp. */
275 if (!hw->phy.reset_if_overtemp &&
276 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
279 /* Blocked by MNG FW so bail */
280 if (ixgbe_check_reset_blocked(hw))
284 * Perform soft PHY reset to the PHY_XS.
285 * This will cause a soft reset to the PHY
287 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
288 IXGBE_MDIO_PHY_XS_DEV_TYPE,
289 IXGBE_MDIO_PHY_XS_RESET);
292 * Poll for reset bit to self-clear indicating reset is complete.
293 * Some PHYs could take up to 3 seconds to complete and need about
294 * 1.7 usec delay after the reset is complete.
296 for (i = 0; i < 30; i++) {
298 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
299 IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
300 if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
306 if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
307 status = IXGBE_ERR_RESET_FAILED;
308 ERROR_REPORT1(IXGBE_ERROR_POLLING,
309 "PHY reset polling failed to complete.\n");
317 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
319 * @hw: pointer to hardware structure
320 * @reg_addr: 32 bit address of PHY register to read
321 * @phy_data: Pointer to read data from PHY register
323 s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
326 u32 i, data, command;
328 /* Setup and write the address cycle command */
329 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
330 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
331 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
332 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
334 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
337 * Check every 10 usec to see if the address cycle completed.
338 * The MDI Command bit will clear when the operation is
341 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
344 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
345 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
350 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
351 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address command did not complete.\n");
352 return IXGBE_ERR_PHY;
356 * Address cycle complete, setup and write the read
359 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
360 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
361 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
362 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
364 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
367 * Check every 10 usec to see if the address cycle
368 * completed. The MDI Command bit will clear when the
369 * operation is complete
371 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
374 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
375 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
379 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
380 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY read command didn't complete\n");
381 return IXGBE_ERR_PHY;
385 * Read operation is complete. Get the data
388 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
389 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
390 *phy_data = (u16)(data);
392 return IXGBE_SUCCESS;
396 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
397 * using the SWFW lock - this function is needed in most cases
398 * @hw: pointer to hardware structure
399 * @reg_addr: 32 bit address of PHY register to read
400 * @phy_data: Pointer to read data from PHY register
402 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
403 u32 device_type, u16 *phy_data)
408 DEBUGFUNC("ixgbe_read_phy_reg_generic");
410 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
411 gssr = IXGBE_GSSR_PHY1_SM;
413 gssr = IXGBE_GSSR_PHY0_SM;
415 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
416 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
418 hw->mac.ops.release_swfw_sync(hw, gssr);
420 status = IXGBE_ERR_SWFW_SYNC;
427 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
429 * @hw: pointer to hardware structure
430 * @reg_addr: 32 bit PHY register to write
431 * @device_type: 5 bit device type
432 * @phy_data: Data to write to the PHY register
434 s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
435 u32 device_type, u16 phy_data)
439 /* Put the data in the MDI single read and write data register*/
440 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
442 /* Setup and write the address cycle command */
443 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
444 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
445 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
446 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
448 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
451 * Check every 10 usec to see if the address cycle completed.
452 * The MDI Command bit will clear when the operation is
455 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
458 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
459 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
463 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
464 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address cmd didn't complete\n");
465 return IXGBE_ERR_PHY;
469 * Address cycle complete, setup and write the write
472 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
473 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
474 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
475 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
477 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
480 * Check every 10 usec to see if the address cycle
481 * completed. The MDI Command bit will clear when the
482 * operation is complete
484 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
487 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
488 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
492 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
493 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY write cmd didn't complete\n");
494 return IXGBE_ERR_PHY;
497 return IXGBE_SUCCESS;
501 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
502 * using SWFW lock- this function is needed in most cases
503 * @hw: pointer to hardware structure
504 * @reg_addr: 32 bit PHY register to write
505 * @device_type: 5 bit device type
506 * @phy_data: Data to write to the PHY register
508 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
509 u32 device_type, u16 phy_data)
514 DEBUGFUNC("ixgbe_write_phy_reg_generic");
516 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
517 gssr = IXGBE_GSSR_PHY1_SM;
519 gssr = IXGBE_GSSR_PHY0_SM;
521 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
522 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
524 hw->mac.ops.release_swfw_sync(hw, gssr);
526 status = IXGBE_ERR_SWFW_SYNC;
533 * ixgbe_setup_phy_link_generic - Set and restart auto-neg
534 * @hw: pointer to hardware structure
536 * Restart auto-negotiation and PHY and waits for completion.
538 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
540 s32 status = IXGBE_SUCCESS;
541 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
542 bool autoneg = false;
543 ixgbe_link_speed speed;
545 DEBUGFUNC("ixgbe_setup_phy_link_generic");
547 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
549 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
550 /* Set or unset auto-negotiation 10G advertisement */
551 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
552 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
555 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
556 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
557 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
559 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
560 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
564 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
565 /* Set or unset auto-negotiation 1G advertisement */
566 hw->phy.ops.read_reg(hw,
567 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
568 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
571 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
572 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
573 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
575 hw->phy.ops.write_reg(hw,
576 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
577 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
581 if (speed & IXGBE_LINK_SPEED_100_FULL) {
582 /* Set or unset auto-negotiation 100M advertisement */
583 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
584 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
587 autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
588 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
589 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
590 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
592 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
593 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
597 /* Blocked by MNG FW so don't reset PHY */
598 if (ixgbe_check_reset_blocked(hw))
601 /* Restart PHY auto-negotiation. */
602 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
603 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
605 autoneg_reg |= IXGBE_MII_RESTART;
607 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
608 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
614 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
615 * @hw: pointer to hardware structure
616 * @speed: new link speed
618 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
619 ixgbe_link_speed speed,
620 bool autoneg_wait_to_complete)
622 UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
624 DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
627 * Clear autoneg_advertised and set new values based on input link
630 hw->phy.autoneg_advertised = 0;
632 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
633 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
635 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
636 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
638 if (speed & IXGBE_LINK_SPEED_100_FULL)
639 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
641 /* Setup link based on the new speed settings */
642 hw->phy.ops.setup_link(hw);
644 return IXGBE_SUCCESS;
648 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
649 * @hw: pointer to hardware structure
650 * @speed: pointer to link speed
651 * @autoneg: boolean auto-negotiation value
653 * Determines the link capabilities by reading the AUTOC register.
655 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
656 ixgbe_link_speed *speed,
662 DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
667 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
668 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
671 if (status == IXGBE_SUCCESS) {
672 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
673 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
674 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
675 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
676 if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
677 *speed |= IXGBE_LINK_SPEED_100_FULL;
684 * ixgbe_check_phy_link_tnx - Determine link and speed status
685 * @hw: pointer to hardware structure
687 * Reads the VS1 register to determine if link is up and the current speed for
690 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
693 s32 status = IXGBE_SUCCESS;
695 u32 max_time_out = 10;
700 DEBUGFUNC("ixgbe_check_phy_link_tnx");
702 /* Initialize speed and link to default case */
704 *speed = IXGBE_LINK_SPEED_10GB_FULL;
707 * Check current speed and link status of the PHY register.
708 * This is a vendor specific register and may have to
709 * be changed for other copper PHYs.
711 for (time_out = 0; time_out < max_time_out; time_out++) {
713 status = hw->phy.ops.read_reg(hw,
714 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
715 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
717 phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
718 phy_speed = phy_data &
719 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
720 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
723 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
724 *speed = IXGBE_LINK_SPEED_1GB_FULL;
733 * ixgbe_setup_phy_link_tnx - Set and restart auto-neg
734 * @hw: pointer to hardware structure
736 * Restart auto-negotiation and PHY and waits for completion.
738 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
740 s32 status = IXGBE_SUCCESS;
741 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
742 bool autoneg = false;
743 ixgbe_link_speed speed;
745 DEBUGFUNC("ixgbe_setup_phy_link_tnx");
747 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
749 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
750 /* Set or unset auto-negotiation 10G advertisement */
751 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
752 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
755 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
756 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
757 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
759 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
760 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
764 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
765 /* Set or unset auto-negotiation 1G advertisement */
766 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
767 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
770 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
771 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
772 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
774 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
775 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
779 if (speed & IXGBE_LINK_SPEED_100_FULL) {
780 /* Set or unset auto-negotiation 100M advertisement */
781 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
782 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
785 autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
786 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
787 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
789 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
790 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
794 /* Blocked by MNG FW so don't reset PHY */
795 if (ixgbe_check_reset_blocked(hw))
798 /* Restart PHY auto-negotiation. */
799 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
800 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
802 autoneg_reg |= IXGBE_MII_RESTART;
804 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
805 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
811 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
812 * @hw: pointer to hardware structure
813 * @firmware_version: pointer to the PHY Firmware Version
815 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
816 u16 *firmware_version)
820 DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
822 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
823 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
830 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
831 * @hw: pointer to hardware structure
832 * @firmware_version: pointer to the PHY Firmware Version
834 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
835 u16 *firmware_version)
839 DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
841 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
842 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
849 * ixgbe_reset_phy_nl - Performs a PHY reset
850 * @hw: pointer to hardware structure
852 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
854 u16 phy_offset, control, eword, edata, block_crc;
855 bool end_data = false;
856 u16 list_offset, data_offset;
858 s32 ret_val = IXGBE_SUCCESS;
861 DEBUGFUNC("ixgbe_reset_phy_nl");
863 /* Blocked by MNG FW so bail */
864 if (ixgbe_check_reset_blocked(hw))
867 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
868 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
870 /* reset the PHY and poll for completion */
871 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
872 IXGBE_MDIO_PHY_XS_DEV_TYPE,
873 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
875 for (i = 0; i < 100; i++) {
876 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
877 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
878 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
883 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
884 DEBUGOUT("PHY reset did not complete.\n");
885 ret_val = IXGBE_ERR_PHY;
889 /* Get init offsets */
890 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
892 if (ret_val != IXGBE_SUCCESS)
895 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
899 * Read control word from PHY init contents offset
901 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
904 control = (eword & IXGBE_CONTROL_MASK_NL) >>
905 IXGBE_CONTROL_SHIFT_NL;
906 edata = eword & IXGBE_DATA_MASK_NL;
910 DEBUGOUT1("DELAY: %d MS\n", edata);
916 ret_val = hw->eeprom.ops.read(hw, data_offset,
921 for (i = 0; i < edata; i++) {
922 ret_val = hw->eeprom.ops.read(hw, data_offset,
926 hw->phy.ops.write_reg(hw, phy_offset,
927 IXGBE_TWINAX_DEV, eword);
928 DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
934 case IXGBE_CONTROL_NL:
936 DEBUGOUT("CONTROL:\n");
937 if (edata == IXGBE_CONTROL_EOL_NL) {
940 } else if (edata == IXGBE_CONTROL_SOL_NL) {
943 DEBUGOUT("Bad control value\n");
944 ret_val = IXGBE_ERR_PHY;
949 DEBUGOUT("Bad control type\n");
950 ret_val = IXGBE_ERR_PHY;
959 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
960 "eeprom read at offset %d failed", data_offset);
961 return IXGBE_ERR_PHY;
965 * ixgbe_identify_module_generic - Identifies module type
966 * @hw: pointer to hardware structure
968 * Determines HW type and calls appropriate function.
970 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
972 s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
974 DEBUGFUNC("ixgbe_identify_module_generic");
976 switch (hw->mac.ops.get_media_type(hw)) {
977 case ixgbe_media_type_fiber:
978 status = ixgbe_identify_sfp_module_generic(hw);
983 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
984 status = IXGBE_ERR_SFP_NOT_PRESENT;
992 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
993 * @hw: pointer to hardware structure
995 * Searches for and identifies the SFP module and assigns appropriate PHY type.
997 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
999 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1001 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1003 u8 comp_codes_1g = 0;
1004 u8 comp_codes_10g = 0;
1005 u8 oui_bytes[3] = {0, 0, 0};
1008 u16 enforce_sfp = 0;
1010 DEBUGFUNC("ixgbe_identify_sfp_module_generic");
1012 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1013 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1014 status = IXGBE_ERR_SFP_NOT_PRESENT;
1018 status = hw->phy.ops.read_i2c_eeprom(hw,
1019 IXGBE_SFF_IDENTIFIER,
1022 if (status != IXGBE_SUCCESS)
1023 goto err_read_i2c_eeprom;
1025 /* LAN ID is needed for sfp_type determination */
1026 hw->mac.ops.set_lan_id(hw);
1028 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1029 hw->phy.type = ixgbe_phy_sfp_unsupported;
1030 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1032 status = hw->phy.ops.read_i2c_eeprom(hw,
1033 IXGBE_SFF_1GBE_COMP_CODES,
1036 if (status != IXGBE_SUCCESS)
1037 goto err_read_i2c_eeprom;
1039 status = hw->phy.ops.read_i2c_eeprom(hw,
1040 IXGBE_SFF_10GBE_COMP_CODES,
1043 if (status != IXGBE_SUCCESS)
1044 goto err_read_i2c_eeprom;
1045 status = hw->phy.ops.read_i2c_eeprom(hw,
1046 IXGBE_SFF_CABLE_TECHNOLOGY,
1049 if (status != IXGBE_SUCCESS)
1050 goto err_read_i2c_eeprom;
1057 * 3 SFP_DA_CORE0 - 82599-specific
1058 * 4 SFP_DA_CORE1 - 82599-specific
1059 * 5 SFP_SR/LR_CORE0 - 82599-specific
1060 * 6 SFP_SR/LR_CORE1 - 82599-specific
1061 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1062 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1063 * 9 SFP_1g_cu_CORE0 - 82599-specific
1064 * 10 SFP_1g_cu_CORE1 - 82599-specific
1065 * 11 SFP_1g_sx_CORE0 - 82599-specific
1066 * 12 SFP_1g_sx_CORE1 - 82599-specific
1068 if (hw->mac.type == ixgbe_mac_82598EB) {
1069 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1070 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1071 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1072 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1073 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1074 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1076 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1077 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1078 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1079 if (hw->bus.lan_id == 0)
1081 ixgbe_sfp_type_da_cu_core0;
1084 ixgbe_sfp_type_da_cu_core1;
1085 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1086 hw->phy.ops.read_i2c_eeprom(
1087 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1090 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1091 if (hw->bus.lan_id == 0)
1093 ixgbe_sfp_type_da_act_lmt_core0;
1096 ixgbe_sfp_type_da_act_lmt_core1;
1099 ixgbe_sfp_type_unknown;
1101 } else if (comp_codes_10g &
1102 (IXGBE_SFF_10GBASESR_CAPABLE |
1103 IXGBE_SFF_10GBASELR_CAPABLE)) {
1104 if (hw->bus.lan_id == 0)
1106 ixgbe_sfp_type_srlr_core0;
1109 ixgbe_sfp_type_srlr_core1;
1110 #ifdef SUPPORT_10GBASE_ER
1111 } else if (comp_codes_10g &
1112 IXGBE_SFF_10GBASEER_CAPABLE) {
1113 if (hw->bus.lan_id == 0)
1115 ixgbe_sfp_type_er_core0;
1118 ixgbe_sfp_type_er_core1;
1119 #endif /* SUPPORT_10GBASE_ER */
1120 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1121 if (hw->bus.lan_id == 0)
1123 ixgbe_sfp_type_1g_cu_core0;
1126 ixgbe_sfp_type_1g_cu_core1;
1127 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1128 if (hw->bus.lan_id == 0)
1130 ixgbe_sfp_type_1g_sx_core0;
1133 ixgbe_sfp_type_1g_sx_core1;
1134 #ifdef SUPPORT_1000BASE_LX
1135 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1136 if (hw->bus.lan_id == 0)
1138 ixgbe_sfp_type_1g_lx_core0;
1141 ixgbe_sfp_type_1g_lx_core1;
1142 #endif /* SUPPORT_1000BASE_LX */
1144 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1148 if (hw->phy.sfp_type != stored_sfp_type)
1149 hw->phy.sfp_setup_needed = true;
1151 /* Determine if the SFP+ PHY is dual speed or not. */
1152 hw->phy.multispeed_fiber = false;
1153 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1154 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1155 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1156 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1157 hw->phy.multispeed_fiber = true;
1159 /* Determine PHY vendor */
1160 if (hw->phy.type != ixgbe_phy_nl) {
1161 hw->phy.id = identifier;
1162 status = hw->phy.ops.read_i2c_eeprom(hw,
1163 IXGBE_SFF_VENDOR_OUI_BYTE0,
1166 if (status != IXGBE_SUCCESS)
1167 goto err_read_i2c_eeprom;
1169 status = hw->phy.ops.read_i2c_eeprom(hw,
1170 IXGBE_SFF_VENDOR_OUI_BYTE1,
1173 if (status != IXGBE_SUCCESS)
1174 goto err_read_i2c_eeprom;
1176 status = hw->phy.ops.read_i2c_eeprom(hw,
1177 IXGBE_SFF_VENDOR_OUI_BYTE2,
1180 if (status != IXGBE_SUCCESS)
1181 goto err_read_i2c_eeprom;
1184 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1185 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1186 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1188 switch (vendor_oui) {
1189 case IXGBE_SFF_VENDOR_OUI_TYCO:
1190 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1192 ixgbe_phy_sfp_passive_tyco;
1194 case IXGBE_SFF_VENDOR_OUI_FTL:
1195 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1196 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1198 hw->phy.type = ixgbe_phy_sfp_ftl;
1200 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1201 hw->phy.type = ixgbe_phy_sfp_avago;
1203 case IXGBE_SFF_VENDOR_OUI_INTEL:
1204 hw->phy.type = ixgbe_phy_sfp_intel;
1207 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1209 ixgbe_phy_sfp_passive_unknown;
1210 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1212 ixgbe_phy_sfp_active_unknown;
1214 hw->phy.type = ixgbe_phy_sfp_unknown;
1219 /* Allow any DA cable vendor */
1220 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1221 IXGBE_SFF_DA_ACTIVE_CABLE)) {
1222 status = IXGBE_SUCCESS;
1226 /* Verify supported 1G SFP modules */
1227 if (comp_codes_10g == 0 &&
1228 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1229 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1230 #ifdef SUPPORT_1000BASE_LX
1231 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1232 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1234 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1235 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1236 hw->phy.type = ixgbe_phy_sfp_unsupported;
1237 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1241 /* Anything else 82598-based is supported */
1242 if (hw->mac.type == ixgbe_mac_82598EB) {
1243 status = IXGBE_SUCCESS;
1247 ixgbe_get_device_caps(hw, &enforce_sfp);
1248 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1249 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1250 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1251 #ifdef SUPPORT_1000BASE_LX
1252 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1253 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1255 #ifdef SUPPORT_10GBASE_ER
1256 hw->phy.sfp_type == ixgbe_sfp_type_er_core0 ||
1257 hw->phy.sfp_type == ixgbe_sfp_type_er_core1 ||
1259 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1260 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1261 /* Make sure we're a supported PHY type */
1262 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1263 status = IXGBE_SUCCESS;
1265 if (hw->allow_unsupported_sfp == true) {
1266 EWARN(hw, "WARNING: Intel (R) Network "
1267 "Connections are quality tested "
1268 "using Intel (R) Ethernet Optics."
1269 " Using untested modules is not "
1270 "supported and may cause unstable"
1271 " operation or damage to the "
1272 "module or the adapter. Intel "
1273 "Corporation is not responsible "
1274 "for any harm caused by using "
1275 "untested modules.\n", status);
1276 status = IXGBE_SUCCESS;
1278 DEBUGOUT("SFP+ module not supported\n");
1280 ixgbe_phy_sfp_unsupported;
1281 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1285 status = IXGBE_SUCCESS;
1292 err_read_i2c_eeprom:
1293 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1294 if (hw->phy.type != ixgbe_phy_nl) {
1296 hw->phy.type = ixgbe_phy_unknown;
1298 return IXGBE_ERR_SFP_NOT_PRESENT;
1304 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1305 * @hw: pointer to hardware structure
1306 * @list_offset: offset to the SFP ID list
1307 * @data_offset: offset to the SFP data block
1309 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1310 * so it returns the offsets to the phy init sequence block.
1312 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1317 u16 sfp_type = hw->phy.sfp_type;
1319 DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
1321 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1322 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1324 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1325 return IXGBE_ERR_SFP_NOT_PRESENT;
1327 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1328 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1329 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1332 * Limiting active cables and 1G Phys must be initialized as
1335 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1336 #ifdef SUPPORT_10GBASE_ER
1337 sfp_type == ixgbe_sfp_type_er_core0 ||
1338 #endif /* SUPPORT_10GBASE_ER */
1339 #ifdef SUPPORT_1000BASE_LX
1340 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1341 #endif /* SUPPORT_1000BASE_LX */
1342 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1343 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1344 sfp_type = ixgbe_sfp_type_srlr_core0;
1345 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1346 #ifdef SUPPORT_10GBASE_ER
1347 sfp_type == ixgbe_sfp_type_er_core1 ||
1348 #endif /* SUPPORT_10GBASE_ER */
1349 #ifdef SUPPORT_1000BASE_LX
1350 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1351 #endif /* SUPPORT_1000BASE_LX */
1352 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1353 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1354 sfp_type = ixgbe_sfp_type_srlr_core1;
1356 /* Read offset to PHY init contents */
1357 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1358 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1359 "eeprom read at offset %d failed",
1360 IXGBE_PHY_INIT_OFFSET_NL);
1361 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1364 if ((!*list_offset) || (*list_offset == 0xFFFF))
1365 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1367 /* Shift offset to first ID word */
1371 * Find the matching SFP ID in the EEPROM
1372 * and program the init sequence
1374 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1377 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1378 if (sfp_id == sfp_type) {
1380 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1382 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1383 DEBUGOUT("SFP+ module not supported\n");
1384 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1389 (*list_offset) += 2;
1390 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1395 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1396 DEBUGOUT("No matching SFP+ module found\n");
1397 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1400 return IXGBE_SUCCESS;
1403 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1404 "eeprom read at offset %d failed", *list_offset);
1405 return IXGBE_ERR_PHY;
1409 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1410 * @hw: pointer to hardware structure
1411 * @byte_offset: EEPROM byte offset to read
1412 * @eeprom_data: value read
1414 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1416 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1419 DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
1421 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1422 IXGBE_I2C_EEPROM_DEV_ADDR,
1427 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1428 * @hw: pointer to hardware structure
1429 * @byte_offset: byte offset at address 0xA2
1430 * @eeprom_data: value read
1432 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1434 STATIC s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1437 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1438 IXGBE_I2C_EEPROM_DEV_ADDR2,
1443 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1444 * @hw: pointer to hardware structure
1445 * @byte_offset: EEPROM byte offset to write
1446 * @eeprom_data: value to write
1448 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1450 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1453 DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
1455 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1456 IXGBE_I2C_EEPROM_DEV_ADDR,
1461 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1462 * @hw: pointer to hardware structure
1463 * @byte_offset: byte offset to read
1466 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1467 * a specified device address.
1469 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1470 u8 dev_addr, u8 *data)
1472 s32 status = IXGBE_SUCCESS;
1479 DEBUGFUNC("ixgbe_read_i2c_byte_generic");
1481 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1482 swfw_mask = IXGBE_GSSR_PHY1_SM;
1484 swfw_mask = IXGBE_GSSR_PHY0_SM;
1487 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
1489 status = IXGBE_ERR_SWFW_SYNC;
1493 ixgbe_i2c_start(hw);
1495 /* Device Address and write indication */
1496 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1497 if (status != IXGBE_SUCCESS)
1500 status = ixgbe_get_i2c_ack(hw);
1501 if (status != IXGBE_SUCCESS)
1504 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1505 if (status != IXGBE_SUCCESS)
1508 status = ixgbe_get_i2c_ack(hw);
1509 if (status != IXGBE_SUCCESS)
1512 ixgbe_i2c_start(hw);
1514 /* Device Address and read indication */
1515 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1516 if (status != IXGBE_SUCCESS)
1519 status = ixgbe_get_i2c_ack(hw);
1520 if (status != IXGBE_SUCCESS)
1523 status = ixgbe_clock_in_i2c_byte(hw, data);
1524 if (status != IXGBE_SUCCESS)
1527 status = ixgbe_clock_out_i2c_bit(hw, nack);
1528 if (status != IXGBE_SUCCESS)
1535 ixgbe_i2c_bus_clear(hw);
1536 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1539 if (retry < max_retry)
1540 DEBUGOUT("I2C byte read error - Retrying.\n");
1542 DEBUGOUT("I2C byte read error.\n");
1544 } while (retry < max_retry);
1546 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1553 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1554 * @hw: pointer to hardware structure
1555 * @byte_offset: byte offset to write
1556 * @data: value to write
1558 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1559 * a specified device address.
1561 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1562 u8 dev_addr, u8 data)
1564 s32 status = IXGBE_SUCCESS;
1569 DEBUGFUNC("ixgbe_write_i2c_byte_generic");
1571 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1572 swfw_mask = IXGBE_GSSR_PHY1_SM;
1574 swfw_mask = IXGBE_GSSR_PHY0_SM;
1576 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != IXGBE_SUCCESS) {
1577 status = IXGBE_ERR_SWFW_SYNC;
1578 goto write_byte_out;
1582 ixgbe_i2c_start(hw);
1584 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1585 if (status != IXGBE_SUCCESS)
1588 status = ixgbe_get_i2c_ack(hw);
1589 if (status != IXGBE_SUCCESS)
1592 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1593 if (status != IXGBE_SUCCESS)
1596 status = ixgbe_get_i2c_ack(hw);
1597 if (status != IXGBE_SUCCESS)
1600 status = ixgbe_clock_out_i2c_byte(hw, data);
1601 if (status != IXGBE_SUCCESS)
1604 status = ixgbe_get_i2c_ack(hw);
1605 if (status != IXGBE_SUCCESS)
1612 ixgbe_i2c_bus_clear(hw);
1614 if (retry < max_retry)
1615 DEBUGOUT("I2C byte write error - Retrying.\n");
1617 DEBUGOUT("I2C byte write error.\n");
1618 } while (retry < max_retry);
1620 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1627 * ixgbe_i2c_start - Sets I2C start condition
1628 * @hw: pointer to hardware structure
1630 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1632 STATIC void ixgbe_i2c_start(struct ixgbe_hw *hw)
1634 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1636 DEBUGFUNC("ixgbe_i2c_start");
1638 /* Start condition must begin with data and clock high */
1639 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1640 ixgbe_raise_i2c_clk(hw, &i2cctl);
1642 /* Setup time for start condition (4.7us) */
1643 usec_delay(IXGBE_I2C_T_SU_STA);
1645 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1647 /* Hold time for start condition (4us) */
1648 usec_delay(IXGBE_I2C_T_HD_STA);
1650 ixgbe_lower_i2c_clk(hw, &i2cctl);
1652 /* Minimum low period of clock is 4.7 us */
1653 usec_delay(IXGBE_I2C_T_LOW);
1658 * ixgbe_i2c_stop - Sets I2C stop condition
1659 * @hw: pointer to hardware structure
1661 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1663 STATIC void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1665 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1667 DEBUGFUNC("ixgbe_i2c_stop");
1669 /* Stop condition must begin with data low and clock high */
1670 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1671 ixgbe_raise_i2c_clk(hw, &i2cctl);
1673 /* Setup time for stop condition (4us) */
1674 usec_delay(IXGBE_I2C_T_SU_STO);
1676 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1678 /* bus free time between stop and start (4.7us)*/
1679 usec_delay(IXGBE_I2C_T_BUF);
1683 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1684 * @hw: pointer to hardware structure
1685 * @data: data byte to clock in
1687 * Clocks in one byte data via I2C data/clock
1689 STATIC s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1694 DEBUGFUNC("ixgbe_clock_in_i2c_byte");
1696 for (i = 7; i >= 0; i--) {
1697 ixgbe_clock_in_i2c_bit(hw, &bit);
1701 return IXGBE_SUCCESS;
1705 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1706 * @hw: pointer to hardware structure
1707 * @data: data byte clocked out
1709 * Clocks out one byte data via I2C data/clock
1711 STATIC s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1713 s32 status = IXGBE_SUCCESS;
1718 DEBUGFUNC("ixgbe_clock_out_i2c_byte");
1720 for (i = 7; i >= 0; i--) {
1721 bit = (data >> i) & 0x1;
1722 status = ixgbe_clock_out_i2c_bit(hw, bit);
1724 if (status != IXGBE_SUCCESS)
1728 /* Release SDA line (set high) */
1729 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1730 i2cctl |= IXGBE_I2C_DATA_OUT;
1731 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1732 IXGBE_WRITE_FLUSH(hw);
1738 * ixgbe_get_i2c_ack - Polls for I2C ACK
1739 * @hw: pointer to hardware structure
1741 * Clocks in/out one bit via I2C data/clock
1743 STATIC s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1745 s32 status = IXGBE_SUCCESS;
1747 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1751 DEBUGFUNC("ixgbe_get_i2c_ack");
1753 ixgbe_raise_i2c_clk(hw, &i2cctl);
1756 /* Minimum high period of clock is 4us */
1757 usec_delay(IXGBE_I2C_T_HIGH);
1759 /* Poll for ACK. Note that ACK in I2C spec is
1760 * transition from 1 to 0 */
1761 for (i = 0; i < timeout; i++) {
1762 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1763 ack = ixgbe_get_i2c_data(&i2cctl);
1771 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1772 "I2C ack was not received.\n");
1773 status = IXGBE_ERR_I2C;
1776 ixgbe_lower_i2c_clk(hw, &i2cctl);
1778 /* Minimum low period of clock is 4.7 us */
1779 usec_delay(IXGBE_I2C_T_LOW);
1785 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1786 * @hw: pointer to hardware structure
1787 * @data: read data value
1789 * Clocks in one bit via I2C data/clock
1791 STATIC s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1793 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1795 DEBUGFUNC("ixgbe_clock_in_i2c_bit");
1797 ixgbe_raise_i2c_clk(hw, &i2cctl);
1799 /* Minimum high period of clock is 4us */
1800 usec_delay(IXGBE_I2C_T_HIGH);
1802 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1803 *data = ixgbe_get_i2c_data(&i2cctl);
1805 ixgbe_lower_i2c_clk(hw, &i2cctl);
1807 /* Minimum low period of clock is 4.7 us */
1808 usec_delay(IXGBE_I2C_T_LOW);
1810 return IXGBE_SUCCESS;
1814 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1815 * @hw: pointer to hardware structure
1816 * @data: data value to write
1818 * Clocks out one bit via I2C data/clock
1820 STATIC s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1823 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1825 DEBUGFUNC("ixgbe_clock_out_i2c_bit");
1827 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1828 if (status == IXGBE_SUCCESS) {
1829 ixgbe_raise_i2c_clk(hw, &i2cctl);
1831 /* Minimum high period of clock is 4us */
1832 usec_delay(IXGBE_I2C_T_HIGH);
1834 ixgbe_lower_i2c_clk(hw, &i2cctl);
1836 /* Minimum low period of clock is 4.7 us.
1837 * This also takes care of the data hold time.
1839 usec_delay(IXGBE_I2C_T_LOW);
1841 status = IXGBE_ERR_I2C;
1842 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1843 "I2C data was not set to %X\n", data);
1850 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1851 * @hw: pointer to hardware structure
1852 * @i2cctl: Current value of I2CCTL register
1854 * Raises the I2C clock line '0'->'1'
1856 STATIC void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1859 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1862 DEBUGFUNC("ixgbe_raise_i2c_clk");
1864 for (i = 0; i < timeout; i++) {
1865 *i2cctl |= IXGBE_I2C_CLK_OUT;
1867 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1868 IXGBE_WRITE_FLUSH(hw);
1869 /* SCL rise time (1000ns) */
1870 usec_delay(IXGBE_I2C_T_RISE);
1872 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1873 if (i2cctl_r & IXGBE_I2C_CLK_IN)
1879 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1880 * @hw: pointer to hardware structure
1881 * @i2cctl: Current value of I2CCTL register
1883 * Lowers the I2C clock line '1'->'0'
1885 STATIC void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1888 DEBUGFUNC("ixgbe_lower_i2c_clk");
1890 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1892 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1893 IXGBE_WRITE_FLUSH(hw);
1895 /* SCL fall time (300ns) */
1896 usec_delay(IXGBE_I2C_T_FALL);
1900 * ixgbe_set_i2c_data - Sets the I2C data bit
1901 * @hw: pointer to hardware structure
1902 * @i2cctl: Current value of I2CCTL register
1903 * @data: I2C data value (0 or 1) to set
1905 * Sets the I2C data bit
1907 STATIC s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1909 s32 status = IXGBE_SUCCESS;
1911 DEBUGFUNC("ixgbe_set_i2c_data");
1914 *i2cctl |= IXGBE_I2C_DATA_OUT;
1916 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1918 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1919 IXGBE_WRITE_FLUSH(hw);
1921 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1922 usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1924 /* Verify data was set correctly */
1925 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1926 if (data != ixgbe_get_i2c_data(i2cctl)) {
1927 status = IXGBE_ERR_I2C;
1928 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1929 "Error - I2C data was not set to %X.\n",
1937 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1938 * @hw: pointer to hardware structure
1939 * @i2cctl: Current value of I2CCTL register
1941 * Returns the I2C data bit value
1943 STATIC bool ixgbe_get_i2c_data(u32 *i2cctl)
1947 DEBUGFUNC("ixgbe_get_i2c_data");
1949 if (*i2cctl & IXGBE_I2C_DATA_IN)
1958 * ixgbe_i2c_bus_clear - Clears the I2C bus
1959 * @hw: pointer to hardware structure
1961 * Clears the I2C bus by sending nine clock pulses.
1962 * Used when data line is stuck low.
1964 void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1966 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1969 DEBUGFUNC("ixgbe_i2c_bus_clear");
1971 ixgbe_i2c_start(hw);
1973 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1975 for (i = 0; i < 9; i++) {
1976 ixgbe_raise_i2c_clk(hw, &i2cctl);
1978 /* Min high period of clock is 4us */
1979 usec_delay(IXGBE_I2C_T_HIGH);
1981 ixgbe_lower_i2c_clk(hw, &i2cctl);
1983 /* Min low period of clock is 4.7us*/
1984 usec_delay(IXGBE_I2C_T_LOW);
1987 ixgbe_i2c_start(hw);
1989 /* Put the i2c bus back to default state */
1994 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
1995 * @hw: pointer to hardware structure
1997 * Checks if the LASI temp alarm status was triggered due to overtemp
1999 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2001 s32 status = IXGBE_SUCCESS;
2004 DEBUGFUNC("ixgbe_tn_check_overtemp");
2006 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2009 /* Check that the LASI temp alarm status was triggered */
2010 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2011 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
2013 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2016 status = IXGBE_ERR_OVERTEMP;
2017 ERROR_REPORT1(IXGBE_ERROR_CAUTION, "Device over temperature");