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;
125 /* Certain media types do not have a phy so an address will not
126 * be found and the code will take this path. Caller has to
127 * decide if it is an error or not.
129 if (status != IXGBE_SUCCESS) {
133 status = IXGBE_SUCCESS;
140 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
141 * @hw: pointer to the hardware structure
143 * This function checks the MMNGC.MNG_VETO bit to see if there are
144 * any constraints on link from manageability. For MAC's that don't
145 * have this bit just return faluse since the link can not be blocked
148 s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
152 DEBUGFUNC("ixgbe_check_reset_blocked");
154 /* If we don't have this bit, it can't be blocking */
155 if (hw->mac.type == ixgbe_mac_82598EB)
158 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
159 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
160 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
161 "MNG_VETO bit detected.\n");
169 * ixgbe_validate_phy_addr - Determines phy address is valid
170 * @hw: pointer to hardware structure
173 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
178 DEBUGFUNC("ixgbe_validate_phy_addr");
180 hw->phy.addr = phy_addr;
181 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
182 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
184 if (phy_id != 0xFFFF && phy_id != 0x0)
191 * ixgbe_get_phy_id - Get the phy type
192 * @hw: pointer to hardware structure
195 s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
201 DEBUGFUNC("ixgbe_get_phy_id");
203 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
204 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
207 if (status == IXGBE_SUCCESS) {
208 hw->phy.id = (u32)(phy_id_high << 16);
209 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
210 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
212 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
213 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
219 * ixgbe_get_phy_type_from_id - Get the phy type
220 * @hw: pointer to hardware structure
223 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
225 enum ixgbe_phy_type phy_type;
227 DEBUGFUNC("ixgbe_get_phy_type_from_id");
231 phy_type = ixgbe_phy_tn;
234 phy_type = ixgbe_phy_aq;
237 phy_type = ixgbe_phy_qt;
240 phy_type = ixgbe_phy_nl;
243 phy_type = ixgbe_phy_unknown;
247 DEBUGOUT1("phy type found is %d\n", phy_type);
252 * ixgbe_reset_phy_generic - Performs a PHY reset
253 * @hw: pointer to hardware structure
255 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
259 s32 status = IXGBE_SUCCESS;
261 DEBUGFUNC("ixgbe_reset_phy_generic");
263 if (hw->phy.type == ixgbe_phy_unknown)
264 status = ixgbe_identify_phy_generic(hw);
266 if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
269 /* Don't reset PHY if it's shut down due to overtemp. */
270 if (!hw->phy.reset_if_overtemp &&
271 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
274 /* Blocked by MNG FW so bail */
275 if (ixgbe_check_reset_blocked(hw))
279 * Perform soft PHY reset to the PHY_XS.
280 * This will cause a soft reset to the PHY
282 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
283 IXGBE_MDIO_PHY_XS_DEV_TYPE,
284 IXGBE_MDIO_PHY_XS_RESET);
287 * Poll for reset bit to self-clear indicating reset is complete.
288 * Some PHYs could take up to 3 seconds to complete and need about
289 * 1.7 usec delay after the reset is complete.
291 for (i = 0; i < 30; i++) {
293 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
294 IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
295 if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
301 if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
302 status = IXGBE_ERR_RESET_FAILED;
303 ERROR_REPORT1(IXGBE_ERROR_POLLING,
304 "PHY reset polling failed to complete.\n");
312 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
313 * @hw: pointer to hardware structure
314 * @reg_addr: 32 bit address of PHY register to read
315 * @phy_data: Pointer to read data from PHY register
317 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
318 u32 device_type, u16 *phy_data)
323 s32 status = IXGBE_SUCCESS;
326 DEBUGFUNC("ixgbe_read_phy_reg_generic");
328 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
329 gssr = IXGBE_GSSR_PHY1_SM;
331 gssr = IXGBE_GSSR_PHY0_SM;
333 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
334 status = IXGBE_ERR_SWFW_SYNC;
336 if (status == IXGBE_SUCCESS) {
337 /* Setup and write the address cycle command */
338 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
339 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
340 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
341 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
343 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
346 * Check every 10 usec to see if the address cycle completed.
347 * The MDI Command bit will clear when the operation is
350 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
353 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
355 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
359 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
360 DEBUGOUT("PHY address command did not complete.\n");
361 status = IXGBE_ERR_PHY;
364 if (status == IXGBE_SUCCESS) {
366 * Address cycle complete, setup and write the read
369 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
370 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
371 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
372 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
374 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
377 * Check every 10 usec to see if the address cycle
378 * completed. The MDI Command bit will clear when the
379 * operation is complete
381 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
384 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
386 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
390 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
391 DEBUGOUT("PHY read command didn't complete\n");
392 status = IXGBE_ERR_PHY;
395 * Read operation is complete. Get the data
398 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
399 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
400 *phy_data = (u16)(data);
404 hw->mac.ops.release_swfw_sync(hw, gssr);
411 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
412 * @hw: pointer to hardware structure
413 * @reg_addr: 32 bit PHY register to write
414 * @device_type: 5 bit device type
415 * @phy_data: Data to write to the PHY register
417 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
418 u32 device_type, u16 phy_data)
422 s32 status = IXGBE_SUCCESS;
425 DEBUGFUNC("ixgbe_write_phy_reg_generic");
427 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
428 gssr = IXGBE_GSSR_PHY1_SM;
430 gssr = IXGBE_GSSR_PHY0_SM;
432 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != IXGBE_SUCCESS)
433 status = IXGBE_ERR_SWFW_SYNC;
435 if (status == IXGBE_SUCCESS) {
436 /* Put the data in the MDI single read and write data register*/
437 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
439 /* Setup and write the address cycle command */
440 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
441 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
442 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
443 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
445 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
448 * Check every 10 usec to see if the address cycle completed.
449 * The MDI Command bit will clear when the operation is
452 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
455 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
457 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
461 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
462 DEBUGOUT("PHY address cmd didn't complete\n");
463 status = IXGBE_ERR_PHY;
466 if (status == IXGBE_SUCCESS) {
468 * Address cycle complete, setup and write the write
471 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
472 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
473 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
474 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
476 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
479 * Check every 10 usec to see if the address cycle
480 * completed. The MDI Command bit will clear when the
481 * operation is complete
483 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
486 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
488 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
492 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
493 DEBUGOUT("PHY address cmd didn't complete\n");
494 status = IXGBE_ERR_PHY;
498 hw->mac.ops.release_swfw_sync(hw, gssr);
505 * ixgbe_setup_phy_link_generic - Set and restart autoneg
506 * @hw: pointer to hardware structure
508 * Restart autonegotiation and PHY and waits for completion.
510 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
512 s32 status = IXGBE_SUCCESS;
514 u32 max_time_out = 10;
515 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
516 bool autoneg = false;
517 ixgbe_link_speed speed;
519 DEBUGFUNC("ixgbe_setup_phy_link_generic");
521 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
523 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
524 /* Set or unset auto-negotiation 10G advertisement */
525 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
526 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
529 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
530 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
531 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
533 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
534 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
538 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
539 /* Set or unset auto-negotiation 1G advertisement */
540 hw->phy.ops.read_reg(hw,
541 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
542 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
545 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
546 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
547 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
549 hw->phy.ops.write_reg(hw,
550 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
551 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
555 if (speed & IXGBE_LINK_SPEED_100_FULL) {
556 /* Set or unset auto-negotiation 100M advertisement */
557 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
558 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
561 autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
562 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
563 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
564 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
566 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
567 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
571 /* Blocked by MNG FW so don't reset PHY */
572 if (ixgbe_check_reset_blocked(hw))
575 /* Restart PHY autonegotiation and wait for completion */
576 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
577 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
579 autoneg_reg |= IXGBE_MII_RESTART;
581 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
582 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
584 /* Wait for autonegotiation to finish */
585 for (time_out = 0; time_out < max_time_out; time_out++) {
587 /* Restart PHY autonegotiation and wait for completion */
588 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
589 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
592 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
593 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
597 if (time_out == max_time_out) {
598 status = IXGBE_ERR_LINK_SETUP;
599 ERROR_REPORT1(IXGBE_ERROR_POLLING,
600 "PHY autonegotiation time out");
607 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
608 * @hw: pointer to hardware structure
609 * @speed: new link speed
611 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
612 ixgbe_link_speed speed,
613 bool autoneg_wait_to_complete)
615 UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
617 DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
620 * Clear autoneg_advertised and set new values based on input link
623 hw->phy.autoneg_advertised = 0;
625 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
626 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
628 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
629 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
631 if (speed & IXGBE_LINK_SPEED_100_FULL)
632 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
634 /* Setup link based on the new speed settings */
635 hw->phy.ops.setup_link(hw);
637 return IXGBE_SUCCESS;
641 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
642 * @hw: pointer to hardware structure
643 * @speed: pointer to link speed
644 * @autoneg: boolean auto-negotiation value
646 * Determines the link capabilities by reading the AUTOC register.
648 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
649 ixgbe_link_speed *speed,
655 DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
660 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
661 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
664 if (status == IXGBE_SUCCESS) {
665 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
666 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
667 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
668 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
669 if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
670 *speed |= IXGBE_LINK_SPEED_100_FULL;
677 * ixgbe_check_phy_link_tnx - Determine link and speed status
678 * @hw: pointer to hardware structure
680 * Reads the VS1 register to determine if link is up and the current speed for
683 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
686 s32 status = IXGBE_SUCCESS;
688 u32 max_time_out = 10;
693 DEBUGFUNC("ixgbe_check_phy_link_tnx");
695 /* Initialize speed and link to default case */
697 *speed = IXGBE_LINK_SPEED_10GB_FULL;
700 * Check current speed and link status of the PHY register.
701 * This is a vendor specific register and may have to
702 * be changed for other copper PHYs.
704 for (time_out = 0; time_out < max_time_out; time_out++) {
706 status = hw->phy.ops.read_reg(hw,
707 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
708 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
710 phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
711 phy_speed = phy_data &
712 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
713 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
716 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
717 *speed = IXGBE_LINK_SPEED_1GB_FULL;
726 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
727 * @hw: pointer to hardware structure
729 * Restart autonegotiation and PHY and waits for completion.
731 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
733 s32 status = IXGBE_SUCCESS;
735 u32 max_time_out = 10;
736 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
737 bool autoneg = false;
738 ixgbe_link_speed speed;
740 DEBUGFUNC("ixgbe_setup_phy_link_tnx");
742 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
744 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
745 /* Set or unset auto-negotiation 10G advertisement */
746 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
747 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
750 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
751 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
752 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
754 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
755 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
759 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
760 /* Set or unset auto-negotiation 1G advertisement */
761 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
762 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
765 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
766 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
767 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
769 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
770 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
774 if (speed & IXGBE_LINK_SPEED_100_FULL) {
775 /* Set or unset auto-negotiation 100M advertisement */
776 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
777 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
780 autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
781 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
782 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
784 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
785 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
789 /* Blocked by MNG FW so don't reset PHY */
790 if (ixgbe_check_reset_blocked(hw))
793 /* Restart PHY autonegotiation and wait for completion */
794 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
795 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
797 autoneg_reg |= IXGBE_MII_RESTART;
799 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
800 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
802 /* Wait for autonegotiation to finish */
803 for (time_out = 0; time_out < max_time_out; time_out++) {
805 /* Restart PHY autonegotiation and wait for completion */
806 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
807 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
810 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
811 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE)
815 if (time_out == max_time_out) {
816 status = IXGBE_ERR_LINK_SETUP;
817 DEBUGOUT("ixgbe_setup_phy_link_tnx: time out");
824 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
825 * @hw: pointer to hardware structure
826 * @firmware_version: pointer to the PHY Firmware Version
828 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
829 u16 *firmware_version)
833 DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
835 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
836 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
843 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
844 * @hw: pointer to hardware structure
845 * @firmware_version: pointer to the PHY Firmware Version
847 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
848 u16 *firmware_version)
852 DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
854 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
855 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
862 * ixgbe_reset_phy_nl - Performs a PHY reset
863 * @hw: pointer to hardware structure
865 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
867 u16 phy_offset, control, eword, edata, block_crc;
868 bool end_data = false;
869 u16 list_offset, data_offset;
871 s32 ret_val = IXGBE_SUCCESS;
874 DEBUGFUNC("ixgbe_reset_phy_nl");
876 /* Blocked by MNG FW so bail */
877 if (ixgbe_check_reset_blocked(hw))
880 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
881 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
883 /* reset the PHY and poll for completion */
884 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
885 IXGBE_MDIO_PHY_XS_DEV_TYPE,
886 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
888 for (i = 0; i < 100; i++) {
889 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
890 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
891 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
896 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
897 DEBUGOUT("PHY reset did not complete.\n");
898 ret_val = IXGBE_ERR_PHY;
902 /* Get init offsets */
903 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
905 if (ret_val != IXGBE_SUCCESS)
908 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
912 * Read control word from PHY init contents offset
914 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
917 control = (eword & IXGBE_CONTROL_MASK_NL) >>
918 IXGBE_CONTROL_SHIFT_NL;
919 edata = eword & IXGBE_DATA_MASK_NL;
923 DEBUGOUT1("DELAY: %d MS\n", edata);
929 ret_val = hw->eeprom.ops.read(hw, data_offset,
934 for (i = 0; i < edata; i++) {
935 ret_val = hw->eeprom.ops.read(hw, data_offset,
939 hw->phy.ops.write_reg(hw, phy_offset,
940 IXGBE_TWINAX_DEV, eword);
941 DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
947 case IXGBE_CONTROL_NL:
949 DEBUGOUT("CONTROL:\n");
950 if (edata == IXGBE_CONTROL_EOL_NL) {
953 } else if (edata == IXGBE_CONTROL_SOL_NL) {
956 DEBUGOUT("Bad control value\n");
957 ret_val = IXGBE_ERR_PHY;
962 DEBUGOUT("Bad control type\n");
963 ret_val = IXGBE_ERR_PHY;
972 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
973 "eeprom read at offset %d failed", data_offset);
974 return IXGBE_ERR_PHY;
978 * ixgbe_identify_module_generic - Identifies module type
979 * @hw: pointer to hardware structure
981 * Determines HW type and calls appropriate function.
983 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
985 s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
987 DEBUGFUNC("ixgbe_identify_module_generic");
989 switch (hw->mac.ops.get_media_type(hw)) {
990 case ixgbe_media_type_fiber:
991 status = ixgbe_identify_sfp_module_generic(hw);
996 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
997 status = IXGBE_ERR_SFP_NOT_PRESENT;
1005 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1006 * @hw: pointer to hardware structure
1008 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1010 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1012 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1014 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1016 u8 comp_codes_1g = 0;
1017 u8 comp_codes_10g = 0;
1018 u8 oui_bytes[3] = {0, 0, 0};
1021 u16 enforce_sfp = 0;
1023 DEBUGFUNC("ixgbe_identify_sfp_module_generic");
1025 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1026 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1027 status = IXGBE_ERR_SFP_NOT_PRESENT;
1031 status = hw->phy.ops.read_i2c_eeprom(hw,
1032 IXGBE_SFF_IDENTIFIER,
1035 if (status != IXGBE_SUCCESS)
1036 goto err_read_i2c_eeprom;
1038 /* LAN ID is needed for sfp_type determination */
1039 hw->mac.ops.set_lan_id(hw);
1041 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1042 hw->phy.type = ixgbe_phy_sfp_unsupported;
1043 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1045 status = hw->phy.ops.read_i2c_eeprom(hw,
1046 IXGBE_SFF_1GBE_COMP_CODES,
1049 if (status != IXGBE_SUCCESS)
1050 goto err_read_i2c_eeprom;
1052 status = hw->phy.ops.read_i2c_eeprom(hw,
1053 IXGBE_SFF_10GBE_COMP_CODES,
1056 if (status != IXGBE_SUCCESS)
1057 goto err_read_i2c_eeprom;
1058 status = hw->phy.ops.read_i2c_eeprom(hw,
1059 IXGBE_SFF_CABLE_TECHNOLOGY,
1062 if (status != IXGBE_SUCCESS)
1063 goto err_read_i2c_eeprom;
1070 * 3 SFP_DA_CORE0 - 82599-specific
1071 * 4 SFP_DA_CORE1 - 82599-specific
1072 * 5 SFP_SR/LR_CORE0 - 82599-specific
1073 * 6 SFP_SR/LR_CORE1 - 82599-specific
1074 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1075 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1076 * 9 SFP_1g_cu_CORE0 - 82599-specific
1077 * 10 SFP_1g_cu_CORE1 - 82599-specific
1078 * 11 SFP_1g_sx_CORE0 - 82599-specific
1079 * 12 SFP_1g_sx_CORE1 - 82599-specific
1081 if (hw->mac.type == ixgbe_mac_82598EB) {
1082 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1083 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1084 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1085 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1086 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1087 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1089 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1090 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1091 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1092 if (hw->bus.lan_id == 0)
1094 ixgbe_sfp_type_da_cu_core0;
1097 ixgbe_sfp_type_da_cu_core1;
1098 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1099 hw->phy.ops.read_i2c_eeprom(
1100 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1103 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1104 if (hw->bus.lan_id == 0)
1106 ixgbe_sfp_type_da_act_lmt_core0;
1109 ixgbe_sfp_type_da_act_lmt_core1;
1112 ixgbe_sfp_type_unknown;
1114 } else if (comp_codes_10g &
1115 (IXGBE_SFF_10GBASESR_CAPABLE |
1116 IXGBE_SFF_10GBASELR_CAPABLE)) {
1117 if (hw->bus.lan_id == 0)
1119 ixgbe_sfp_type_srlr_core0;
1122 ixgbe_sfp_type_srlr_core1;
1123 #ifdef SUPPORT_10GBASE_ER
1124 } else if (comp_codes_10g &
1125 IXGBE_SFF_10GBASEER_CAPABLE) {
1126 if (hw->bus.lan_id == 0)
1128 ixgbe_sfp_type_er_core0;
1131 ixgbe_sfp_type_er_core1;
1132 #endif /* SUPPORT_10GBASE_ER */
1133 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1134 if (hw->bus.lan_id == 0)
1136 ixgbe_sfp_type_1g_cu_core0;
1139 ixgbe_sfp_type_1g_cu_core1;
1140 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1141 if (hw->bus.lan_id == 0)
1143 ixgbe_sfp_type_1g_sx_core0;
1146 ixgbe_sfp_type_1g_sx_core1;
1147 #ifdef SUPPORT_1000BASE_LX
1148 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1149 if (hw->bus.lan_id == 0)
1151 ixgbe_sfp_type_1g_lx_core0;
1154 ixgbe_sfp_type_1g_lx_core1;
1155 #endif /* SUPPORT_1000BASE_LX */
1157 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1161 if (hw->phy.sfp_type != stored_sfp_type)
1162 hw->phy.sfp_setup_needed = true;
1164 /* Determine if the SFP+ PHY is dual speed or not. */
1165 hw->phy.multispeed_fiber = false;
1166 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1167 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1168 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1169 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1170 hw->phy.multispeed_fiber = true;
1172 /* Determine PHY vendor */
1173 if (hw->phy.type != ixgbe_phy_nl) {
1174 hw->phy.id = identifier;
1175 status = hw->phy.ops.read_i2c_eeprom(hw,
1176 IXGBE_SFF_VENDOR_OUI_BYTE0,
1179 if (status != IXGBE_SUCCESS)
1180 goto err_read_i2c_eeprom;
1182 status = hw->phy.ops.read_i2c_eeprom(hw,
1183 IXGBE_SFF_VENDOR_OUI_BYTE1,
1186 if (status != IXGBE_SUCCESS)
1187 goto err_read_i2c_eeprom;
1189 status = hw->phy.ops.read_i2c_eeprom(hw,
1190 IXGBE_SFF_VENDOR_OUI_BYTE2,
1193 if (status != IXGBE_SUCCESS)
1194 goto err_read_i2c_eeprom;
1197 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1198 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1199 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1201 switch (vendor_oui) {
1202 case IXGBE_SFF_VENDOR_OUI_TYCO:
1203 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1205 ixgbe_phy_sfp_passive_tyco;
1207 case IXGBE_SFF_VENDOR_OUI_FTL:
1208 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1209 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1211 hw->phy.type = ixgbe_phy_sfp_ftl;
1213 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1214 hw->phy.type = ixgbe_phy_sfp_avago;
1216 case IXGBE_SFF_VENDOR_OUI_INTEL:
1217 hw->phy.type = ixgbe_phy_sfp_intel;
1220 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1222 ixgbe_phy_sfp_passive_unknown;
1223 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1225 ixgbe_phy_sfp_active_unknown;
1227 hw->phy.type = ixgbe_phy_sfp_unknown;
1232 /* Allow any DA cable vendor */
1233 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1234 IXGBE_SFF_DA_ACTIVE_CABLE)) {
1235 status = IXGBE_SUCCESS;
1239 /* Verify supported 1G SFP modules */
1240 if (comp_codes_10g == 0 &&
1241 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1242 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1243 #ifdef SUPPORT_1000BASE_LX
1244 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1245 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1247 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1248 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1249 hw->phy.type = ixgbe_phy_sfp_unsupported;
1250 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1254 /* Anything else 82598-based is supported */
1255 if (hw->mac.type == ixgbe_mac_82598EB) {
1256 status = IXGBE_SUCCESS;
1260 ixgbe_get_device_caps(hw, &enforce_sfp);
1261 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1262 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1263 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1264 #ifdef SUPPORT_1000BASE_LX
1265 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1266 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1268 #ifdef SUPPORT_10GBASE_ER
1269 hw->phy.sfp_type == ixgbe_sfp_type_er_core0 ||
1270 hw->phy.sfp_type == ixgbe_sfp_type_er_core1 ||
1272 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1273 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1274 /* Make sure we're a supported PHY type */
1275 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1276 status = IXGBE_SUCCESS;
1278 if (hw->allow_unsupported_sfp == true) {
1279 EWARN(hw, "WARNING: Intel (R) Network "
1280 "Connections are quality tested "
1281 "using Intel (R) Ethernet Optics."
1282 " Using untested modules is not "
1283 "supported and may cause unstable"
1284 " operation or damage to the "
1285 "module or the adapter. Intel "
1286 "Corporation is not responsible "
1287 "for any harm caused by using "
1288 "untested modules.\n", status);
1289 status = IXGBE_SUCCESS;
1291 DEBUGOUT("SFP+ module not supported\n");
1293 ixgbe_phy_sfp_unsupported;
1294 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1298 status = IXGBE_SUCCESS;
1305 err_read_i2c_eeprom:
1306 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1307 if (hw->phy.type != ixgbe_phy_nl) {
1309 hw->phy.type = ixgbe_phy_unknown;
1311 return IXGBE_ERR_SFP_NOT_PRESENT;
1317 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1318 * @hw: pointer to hardware structure
1319 * @list_offset: offset to the SFP ID list
1320 * @data_offset: offset to the SFP data block
1322 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1323 * so it returns the offsets to the phy init sequence block.
1325 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1330 u16 sfp_type = hw->phy.sfp_type;
1332 DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
1334 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1335 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1337 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1338 return IXGBE_ERR_SFP_NOT_PRESENT;
1340 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1341 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1342 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1345 * Limiting active cables and 1G Phys must be initialized as
1348 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1349 #ifdef SUPPORT_10GBASE_ER
1350 sfp_type == ixgbe_sfp_type_er_core0 ||
1351 #endif /* SUPPORT_10GBASE_ER */
1352 #ifdef SUPPORT_1000BASE_LX
1353 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1354 #endif /* SUPPORT_1000BASE_LX */
1355 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1356 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1357 sfp_type = ixgbe_sfp_type_srlr_core0;
1358 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1359 #ifdef SUPPORT_10GBASE_ER
1360 sfp_type == ixgbe_sfp_type_er_core1 ||
1361 #endif /* SUPPORT_10GBASE_ER */
1362 #ifdef SUPPORT_1000BASE_LX
1363 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1364 #endif /* SUPPORT_1000BASE_LX */
1365 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1366 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1367 sfp_type = ixgbe_sfp_type_srlr_core1;
1369 /* Read offset to PHY init contents */
1370 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1371 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1372 "eeprom read at offset %d failed",
1373 IXGBE_PHY_INIT_OFFSET_NL);
1374 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1377 if ((!*list_offset) || (*list_offset == 0xFFFF))
1378 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1380 /* Shift offset to first ID word */
1384 * Find the matching SFP ID in the EEPROM
1385 * and program the init sequence
1387 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1390 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1391 if (sfp_id == sfp_type) {
1393 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1395 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1396 DEBUGOUT("SFP+ module not supported\n");
1397 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1402 (*list_offset) += 2;
1403 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1408 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1409 DEBUGOUT("No matching SFP+ module found\n");
1410 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1413 return IXGBE_SUCCESS;
1416 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1417 "eeprom read at offset %d failed", *list_offset);
1418 return IXGBE_ERR_PHY;
1422 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1423 * @hw: pointer to hardware structure
1424 * @byte_offset: EEPROM byte offset to read
1425 * @eeprom_data: value read
1427 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1429 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1432 DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
1434 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1435 IXGBE_I2C_EEPROM_DEV_ADDR,
1440 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1441 * @hw: pointer to hardware structure
1442 * @byte_offset: EEPROM byte offset to write
1443 * @eeprom_data: value to write
1445 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1447 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1450 DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
1452 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1453 IXGBE_I2C_EEPROM_DEV_ADDR,
1458 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1459 * @hw: pointer to hardware structure
1460 * @byte_offset: byte offset to read
1463 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1464 * a specified device address.
1466 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1467 u8 dev_addr, u8 *data)
1469 s32 status = IXGBE_SUCCESS;
1476 DEBUGFUNC("ixgbe_read_i2c_byte_generic");
1478 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1479 swfw_mask = IXGBE_GSSR_PHY1_SM;
1481 swfw_mask = IXGBE_GSSR_PHY0_SM;
1484 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask)
1486 status = IXGBE_ERR_SWFW_SYNC;
1490 ixgbe_i2c_start(hw);
1492 /* Device Address and write indication */
1493 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1494 if (status != IXGBE_SUCCESS)
1497 status = ixgbe_get_i2c_ack(hw);
1498 if (status != IXGBE_SUCCESS)
1501 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1502 if (status != IXGBE_SUCCESS)
1505 status = ixgbe_get_i2c_ack(hw);
1506 if (status != IXGBE_SUCCESS)
1509 ixgbe_i2c_start(hw);
1511 /* Device Address and read indication */
1512 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1513 if (status != IXGBE_SUCCESS)
1516 status = ixgbe_get_i2c_ack(hw);
1517 if (status != IXGBE_SUCCESS)
1520 status = ixgbe_clock_in_i2c_byte(hw, data);
1521 if (status != IXGBE_SUCCESS)
1524 status = ixgbe_clock_out_i2c_bit(hw, nack);
1525 if (status != IXGBE_SUCCESS)
1532 ixgbe_i2c_bus_clear(hw);
1533 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1536 if (retry < max_retry)
1537 DEBUGOUT("I2C byte read error - Retrying.\n");
1539 DEBUGOUT("I2C byte read error.\n");
1541 } while (retry < max_retry);
1543 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1550 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1551 * @hw: pointer to hardware structure
1552 * @byte_offset: byte offset to write
1553 * @data: value to write
1555 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1556 * a specified device address.
1558 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1559 u8 dev_addr, u8 data)
1561 s32 status = IXGBE_SUCCESS;
1566 DEBUGFUNC("ixgbe_write_i2c_byte_generic");
1568 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
1569 swfw_mask = IXGBE_GSSR_PHY1_SM;
1571 swfw_mask = IXGBE_GSSR_PHY0_SM;
1573 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != IXGBE_SUCCESS) {
1574 status = IXGBE_ERR_SWFW_SYNC;
1575 goto write_byte_out;
1579 ixgbe_i2c_start(hw);
1581 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1582 if (status != IXGBE_SUCCESS)
1585 status = ixgbe_get_i2c_ack(hw);
1586 if (status != IXGBE_SUCCESS)
1589 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1590 if (status != IXGBE_SUCCESS)
1593 status = ixgbe_get_i2c_ack(hw);
1594 if (status != IXGBE_SUCCESS)
1597 status = ixgbe_clock_out_i2c_byte(hw, data);
1598 if (status != IXGBE_SUCCESS)
1601 status = ixgbe_get_i2c_ack(hw);
1602 if (status != IXGBE_SUCCESS)
1609 ixgbe_i2c_bus_clear(hw);
1611 if (retry < max_retry)
1612 DEBUGOUT("I2C byte write error - Retrying.\n");
1614 DEBUGOUT("I2C byte write error.\n");
1615 } while (retry < max_retry);
1617 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1624 * ixgbe_i2c_start - Sets I2C start condition
1625 * @hw: pointer to hardware structure
1627 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1629 STATIC void ixgbe_i2c_start(struct ixgbe_hw *hw)
1631 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1633 DEBUGFUNC("ixgbe_i2c_start");
1635 /* Start condition must begin with data and clock high */
1636 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1637 ixgbe_raise_i2c_clk(hw, &i2cctl);
1639 /* Setup time for start condition (4.7us) */
1640 usec_delay(IXGBE_I2C_T_SU_STA);
1642 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1644 /* Hold time for start condition (4us) */
1645 usec_delay(IXGBE_I2C_T_HD_STA);
1647 ixgbe_lower_i2c_clk(hw, &i2cctl);
1649 /* Minimum low period of clock is 4.7 us */
1650 usec_delay(IXGBE_I2C_T_LOW);
1655 * ixgbe_i2c_stop - Sets I2C stop condition
1656 * @hw: pointer to hardware structure
1658 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1660 STATIC void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1662 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1664 DEBUGFUNC("ixgbe_i2c_stop");
1666 /* Stop condition must begin with data low and clock high */
1667 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1668 ixgbe_raise_i2c_clk(hw, &i2cctl);
1670 /* Setup time for stop condition (4us) */
1671 usec_delay(IXGBE_I2C_T_SU_STO);
1673 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1675 /* bus free time between stop and start (4.7us)*/
1676 usec_delay(IXGBE_I2C_T_BUF);
1680 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1681 * @hw: pointer to hardware structure
1682 * @data: data byte to clock in
1684 * Clocks in one byte data via I2C data/clock
1686 STATIC s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1691 DEBUGFUNC("ixgbe_clock_in_i2c_byte");
1693 for (i = 7; i >= 0; i--) {
1694 ixgbe_clock_in_i2c_bit(hw, &bit);
1698 return IXGBE_SUCCESS;
1702 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1703 * @hw: pointer to hardware structure
1704 * @data: data byte clocked out
1706 * Clocks out one byte data via I2C data/clock
1708 STATIC s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1710 s32 status = IXGBE_SUCCESS;
1715 DEBUGFUNC("ixgbe_clock_out_i2c_byte");
1717 for (i = 7; i >= 0; i--) {
1718 bit = (data >> i) & 0x1;
1719 status = ixgbe_clock_out_i2c_bit(hw, bit);
1721 if (status != IXGBE_SUCCESS)
1725 /* Release SDA line (set high) */
1726 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1727 i2cctl |= IXGBE_I2C_DATA_OUT;
1728 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1729 IXGBE_WRITE_FLUSH(hw);
1735 * ixgbe_get_i2c_ack - Polls for I2C ACK
1736 * @hw: pointer to hardware structure
1738 * Clocks in/out one bit via I2C data/clock
1740 STATIC s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1742 s32 status = IXGBE_SUCCESS;
1744 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1748 DEBUGFUNC("ixgbe_get_i2c_ack");
1750 ixgbe_raise_i2c_clk(hw, &i2cctl);
1753 /* Minimum high period of clock is 4us */
1754 usec_delay(IXGBE_I2C_T_HIGH);
1756 /* Poll for ACK. Note that ACK in I2C spec is
1757 * transition from 1 to 0 */
1758 for (i = 0; i < timeout; i++) {
1759 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1760 ack = ixgbe_get_i2c_data(&i2cctl);
1768 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1769 "I2C ack was not received.\n");
1770 status = IXGBE_ERR_I2C;
1773 ixgbe_lower_i2c_clk(hw, &i2cctl);
1775 /* Minimum low period of clock is 4.7 us */
1776 usec_delay(IXGBE_I2C_T_LOW);
1782 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1783 * @hw: pointer to hardware structure
1784 * @data: read data value
1786 * Clocks in one bit via I2C data/clock
1788 STATIC s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1790 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1792 DEBUGFUNC("ixgbe_clock_in_i2c_bit");
1794 ixgbe_raise_i2c_clk(hw, &i2cctl);
1796 /* Minimum high period of clock is 4us */
1797 usec_delay(IXGBE_I2C_T_HIGH);
1799 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1800 *data = ixgbe_get_i2c_data(&i2cctl);
1802 ixgbe_lower_i2c_clk(hw, &i2cctl);
1804 /* Minimum low period of clock is 4.7 us */
1805 usec_delay(IXGBE_I2C_T_LOW);
1807 return IXGBE_SUCCESS;
1811 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1812 * @hw: pointer to hardware structure
1813 * @data: data value to write
1815 * Clocks out one bit via I2C data/clock
1817 STATIC s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1820 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1822 DEBUGFUNC("ixgbe_clock_out_i2c_bit");
1824 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1825 if (status == IXGBE_SUCCESS) {
1826 ixgbe_raise_i2c_clk(hw, &i2cctl);
1828 /* Minimum high period of clock is 4us */
1829 usec_delay(IXGBE_I2C_T_HIGH);
1831 ixgbe_lower_i2c_clk(hw, &i2cctl);
1833 /* Minimum low period of clock is 4.7 us.
1834 * This also takes care of the data hold time.
1836 usec_delay(IXGBE_I2C_T_LOW);
1838 status = IXGBE_ERR_I2C;
1839 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1840 "I2C data was not set to %X\n", data);
1846 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1847 * @hw: pointer to hardware structure
1848 * @i2cctl: Current value of I2CCTL register
1850 * Raises the I2C clock line '0'->'1'
1852 STATIC void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1855 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1858 DEBUGFUNC("ixgbe_raise_i2c_clk");
1860 for (i = 0; i < timeout; i++) {
1861 *i2cctl |= IXGBE_I2C_CLK_OUT;
1863 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1864 IXGBE_WRITE_FLUSH(hw);
1865 /* SCL rise time (1000ns) */
1866 usec_delay(IXGBE_I2C_T_RISE);
1868 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1869 if (i2cctl_r & IXGBE_I2C_CLK_IN)
1875 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1876 * @hw: pointer to hardware structure
1877 * @i2cctl: Current value of I2CCTL register
1879 * Lowers the I2C clock line '1'->'0'
1881 STATIC void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1884 DEBUGFUNC("ixgbe_lower_i2c_clk");
1886 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1888 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1889 IXGBE_WRITE_FLUSH(hw);
1891 /* SCL fall time (300ns) */
1892 usec_delay(IXGBE_I2C_T_FALL);
1896 * ixgbe_set_i2c_data - Sets the I2C data bit
1897 * @hw: pointer to hardware structure
1898 * @i2cctl: Current value of I2CCTL register
1899 * @data: I2C data value (0 or 1) to set
1901 * Sets the I2C data bit
1903 STATIC s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1905 s32 status = IXGBE_SUCCESS;
1907 DEBUGFUNC("ixgbe_set_i2c_data");
1910 *i2cctl |= IXGBE_I2C_DATA_OUT;
1912 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1914 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1915 IXGBE_WRITE_FLUSH(hw);
1917 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1918 usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1920 /* Verify data was set correctly */
1921 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1922 if (data != ixgbe_get_i2c_data(i2cctl)) {
1923 status = IXGBE_ERR_I2C;
1924 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1925 "Error - I2C data was not set to %X.\n",
1933 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1934 * @hw: pointer to hardware structure
1935 * @i2cctl: Current value of I2CCTL register
1937 * Returns the I2C data bit value
1939 STATIC bool ixgbe_get_i2c_data(u32 *i2cctl)
1943 DEBUGFUNC("ixgbe_get_i2c_data");
1945 if (*i2cctl & IXGBE_I2C_DATA_IN)
1954 * ixgbe_i2c_bus_clear - Clears the I2C bus
1955 * @hw: pointer to hardware structure
1957 * Clears the I2C bus by sending nine clock pulses.
1958 * Used when data line is stuck low.
1960 void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1962 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1965 DEBUGFUNC("ixgbe_i2c_bus_clear");
1967 ixgbe_i2c_start(hw);
1969 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1971 for (i = 0; i < 9; i++) {
1972 ixgbe_raise_i2c_clk(hw, &i2cctl);
1974 /* Min high period of clock is 4us */
1975 usec_delay(IXGBE_I2C_T_HIGH);
1977 ixgbe_lower_i2c_clk(hw, &i2cctl);
1979 /* Min low period of clock is 4.7us*/
1980 usec_delay(IXGBE_I2C_T_LOW);
1983 ixgbe_i2c_start(hw);
1985 /* Put the i2c bus back to default state */
1990 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
1991 * @hw: pointer to hardware structure
1993 * Checks if the LASI temp alarm status was triggered due to overtemp
1995 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1997 s32 status = IXGBE_SUCCESS;
2000 DEBUGFUNC("ixgbe_tn_check_overtemp");
2002 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2005 /* Check that the LASI temp alarm status was triggered */
2006 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2007 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
2009 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2012 status = IXGBE_ERR_OVERTEMP;
2013 ERROR_REPORT1(IXGBE_ERROR_CAUTION, "Device over temperature");