1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2014 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
34 #include "ixgbe_phy.h"
36 static void ixgbe_i2c_start(struct ixgbe_hw *hw);
37 static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
38 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
39 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
40 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
41 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
42 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
43 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
45 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
46 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
47 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
48 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
49 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
50 static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw);
53 * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
54 * @hw: pointer to the hardware structure
57 * Returns an error code on error.
59 static s32 ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
63 status = ixgbe_clock_out_i2c_byte(hw, byte);
66 return ixgbe_get_i2c_ack(hw);
70 * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
71 * @hw: pointer to the hardware structure
72 * @byte: pointer to a u8 to receive the byte
74 * Returns an error code on error.
76 static s32 ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
80 status = ixgbe_clock_in_i2c_byte(hw, byte);
84 return ixgbe_clock_out_i2c_bit(hw, false);
88 * ixgbe_ones_comp_byte_add - Perform one's complement addition
92 * Returns one's complement 8-bit sum.
94 static u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
96 u16 sum = add1 + add2;
98 sum = (sum & 0xFF) + (sum >> 8);
103 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
104 * @hw: pointer to the hardware structure
105 * @addr: I2C bus address to read from
106 * @reg: I2C device register to read from
107 * @val: pointer to location to receive read value
109 * Returns an error code on error.
111 s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
114 u32 swfw_mask = hw->phy.phy_semaphore_mask;
123 reg_high = ((reg >> 7) & 0xFE) | 1; /* Indicate read combined */
124 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
127 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
128 return IXGBE_ERR_SWFW_SYNC;
130 /* Device Address and write indication */
131 if (ixgbe_out_i2c_byte_ack(hw, addr))
133 /* Write bits 14:8 */
134 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
137 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
140 if (ixgbe_out_i2c_byte_ack(hw, csum))
142 /* Re-start condition */
144 /* Device Address and read indication */
145 if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
148 if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
151 if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
154 if (ixgbe_clock_in_i2c_byte(hw, &csum_byte))
157 if (ixgbe_clock_out_i2c_bit(hw, false))
160 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
161 *val = (high_bits << 8) | low_bits;
165 ixgbe_i2c_bus_clear(hw);
166 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
168 if (retry < max_retry)
169 hw_dbg(hw, "I2C byte read combined error - Retry.\n");
171 hw_dbg(hw, "I2C byte read combined error.\n");
172 } while (retry < max_retry);
174 return IXGBE_ERR_I2C;
178 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
179 * @hw: pointer to the hardware structure
180 * @addr: I2C bus address to write to
181 * @reg: I2C device register to write to
182 * @val: value to write
184 * Returns an error code on error.
186 s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
187 u8 addr, u16 reg, u16 val)
194 reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
195 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
196 csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
197 csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
201 /* Device Address and write indication */
202 if (ixgbe_out_i2c_byte_ack(hw, addr))
204 /* Write bits 14:8 */
205 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
208 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
210 /* Write data 15:8 */
211 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
214 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
217 if (ixgbe_out_i2c_byte_ack(hw, csum))
223 ixgbe_i2c_bus_clear(hw);
225 if (retry < max_retry)
226 hw_dbg(hw, "I2C byte write combined error - Retry.\n");
228 hw_dbg(hw, "I2C byte write combined error.\n");
229 } while (retry < max_retry);
231 return IXGBE_ERR_I2C;
235 * ixgbe_identify_phy_generic - Get physical layer module
236 * @hw: pointer to hardware structure
238 * Determines the physical layer module found on the current adapter.
240 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
245 if (!hw->phy.phy_semaphore_mask) {
247 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
249 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
252 if (hw->phy.type == ixgbe_phy_unknown) {
253 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
254 hw->phy.mdio.prtad = phy_addr;
255 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
256 ixgbe_get_phy_id(hw);
258 ixgbe_get_phy_type_from_id(hw->phy.id);
260 if (hw->phy.type == ixgbe_phy_unknown) {
261 hw->phy.ops.read_reg(hw,
266 (MDIO_PMA_EXTABLE_10GBT |
267 MDIO_PMA_EXTABLE_1000BT))
269 ixgbe_phy_cu_unknown;
278 /* clear value if nothing found */
279 hw->phy.mdio.prtad = 0;
280 return IXGBE_ERR_PHY_ADDR_INVALID;
286 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
287 * @hw: pointer to the hardware structure
289 * This function checks the MMNGC.MNG_VETO bit to see if there are
290 * any constraints on link from manageability. For MAC's that don't
291 * have this bit just return false since the link can not be blocked
294 bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
298 /* If we don't have this bit, it can't be blocking */
299 if (hw->mac.type == ixgbe_mac_82598EB)
302 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
303 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
304 hw_dbg(hw, "MNG_VETO bit detected.\n");
312 * ixgbe_get_phy_id - Get the phy type
313 * @hw: pointer to hardware structure
316 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
322 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
326 hw->phy.id = (u32)(phy_id_high << 16);
327 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
329 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
330 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
336 * ixgbe_get_phy_type_from_id - Get the phy type
337 * @hw: pointer to hardware structure
340 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
342 enum ixgbe_phy_type phy_type;
346 phy_type = ixgbe_phy_tn;
350 phy_type = ixgbe_phy_aq;
353 phy_type = ixgbe_phy_qt;
356 phy_type = ixgbe_phy_nl;
359 phy_type = ixgbe_phy_x550em_ext_t;
362 phy_type = ixgbe_phy_unknown;
370 * ixgbe_reset_phy_generic - Performs a PHY reset
371 * @hw: pointer to hardware structure
373 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
379 if (hw->phy.type == ixgbe_phy_unknown)
380 status = ixgbe_identify_phy_generic(hw);
382 if (status != 0 || hw->phy.type == ixgbe_phy_none)
385 /* Don't reset PHY if it's shut down due to overtemp. */
386 if (!hw->phy.reset_if_overtemp &&
387 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
390 /* Blocked by MNG FW so bail */
391 if (ixgbe_check_reset_blocked(hw))
395 * Perform soft PHY reset to the PHY_XS.
396 * This will cause a soft reset to the PHY
398 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
403 * Poll for reset bit to self-clear indicating reset is complete.
404 * Some PHYs could take up to 3 seconds to complete and need about
405 * 1.7 usec delay after the reset is complete.
407 for (i = 0; i < 30; i++) {
409 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
410 MDIO_MMD_PHYXS, &ctrl);
411 if (!(ctrl & MDIO_CTRL1_RESET)) {
417 if (ctrl & MDIO_CTRL1_RESET) {
418 hw_dbg(hw, "PHY reset polling failed to complete.\n");
419 return IXGBE_ERR_RESET_FAILED;
426 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
428 * @hw: pointer to hardware structure
429 * @reg_addr: 32 bit address of PHY register to read
430 * @phy_data: Pointer to read data from PHY register
432 s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
435 u32 i, data, command;
437 /* Setup and write the address cycle command */
438 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
439 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
440 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
441 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
443 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
445 /* Check every 10 usec to see if the address cycle completed.
446 * The MDI Command bit will clear when the operation is
449 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
452 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
453 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
458 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
459 hw_dbg(hw, "PHY address command did not complete.\n");
460 return IXGBE_ERR_PHY;
463 /* Address cycle complete, setup and write the read
466 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
467 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
468 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
469 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
471 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
473 /* Check every 10 usec to see if the address cycle
474 * completed. The MDI Command bit will clear when the
475 * operation is complete
477 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
480 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
481 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
485 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
486 hw_dbg(hw, "PHY read command didn't complete\n");
487 return IXGBE_ERR_PHY;
490 /* Read operation is complete. Get the data
493 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
494 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
495 *phy_data = (u16)(data);
501 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
502 * using the SWFW lock - this function is needed in most cases
503 * @hw: pointer to hardware structure
504 * @reg_addr: 32 bit address of PHY register to read
505 * @phy_data: Pointer to read data from PHY register
507 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
508 u32 device_type, u16 *phy_data)
511 u32 gssr = hw->phy.phy_semaphore_mask;
513 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
514 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
516 hw->mac.ops.release_swfw_sync(hw, gssr);
518 return IXGBE_ERR_SWFW_SYNC;
525 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
527 * @hw: pointer to hardware structure
528 * @reg_addr: 32 bit PHY register to write
529 * @device_type: 5 bit device type
530 * @phy_data: Data to write to the PHY register
532 s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
533 u32 device_type, u16 phy_data)
537 /* Put the data in the MDI single read and write data register*/
538 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
540 /* Setup and write the address cycle command */
541 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
542 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
543 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
544 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
546 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
549 * Check every 10 usec to see if the address cycle completed.
550 * The MDI Command bit will clear when the operation is
553 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
556 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
557 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
561 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
562 hw_dbg(hw, "PHY address cmd didn't complete\n");
563 return IXGBE_ERR_PHY;
567 * Address cycle complete, setup and write the write
570 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
571 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
572 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
573 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
575 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
577 /* Check every 10 usec to see if the address cycle
578 * completed. The MDI Command bit will clear when the
579 * operation is complete
581 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
584 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
585 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
589 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
590 hw_dbg(hw, "PHY write cmd didn't complete\n");
591 return IXGBE_ERR_PHY;
598 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
599 * using SWFW lock- this function is needed in most cases
600 * @hw: pointer to hardware structure
601 * @reg_addr: 32 bit PHY register to write
602 * @device_type: 5 bit device type
603 * @phy_data: Data to write to the PHY register
605 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
606 u32 device_type, u16 phy_data)
609 u32 gssr = hw->phy.phy_semaphore_mask;
611 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
612 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
614 hw->mac.ops.release_swfw_sync(hw, gssr);
616 return IXGBE_ERR_SWFW_SYNC;
623 * ixgbe_setup_phy_link_generic - Set and restart autoneg
624 * @hw: pointer to hardware structure
626 * Restart autonegotiation and PHY and waits for completion.
628 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
631 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
632 bool autoneg = false;
633 ixgbe_link_speed speed;
635 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
637 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
638 /* Set or unset auto-negotiation 10G advertisement */
639 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
643 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
644 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
645 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
647 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
652 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
653 /* Set or unset auto-negotiation 1G advertisement */
654 hw->phy.ops.read_reg(hw,
655 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
659 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
660 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
661 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
663 hw->phy.ops.write_reg(hw,
664 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
669 if (speed & IXGBE_LINK_SPEED_100_FULL) {
670 /* Set or unset auto-negotiation 100M advertisement */
671 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
675 autoneg_reg &= ~(ADVERTISE_100FULL |
677 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
678 autoneg_reg |= ADVERTISE_100FULL;
680 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
685 /* Blocked by MNG FW so don't reset PHY */
686 if (ixgbe_check_reset_blocked(hw))
689 /* Restart PHY autonegotiation and wait for completion */
690 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
691 MDIO_MMD_AN, &autoneg_reg);
693 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
695 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
696 MDIO_MMD_AN, autoneg_reg);
702 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
703 * @hw: pointer to hardware structure
704 * @speed: new link speed
706 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
707 ixgbe_link_speed speed,
708 bool autoneg_wait_to_complete)
712 * Clear autoneg_advertised and set new values based on input link
715 hw->phy.autoneg_advertised = 0;
717 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
718 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
720 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
721 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
723 if (speed & IXGBE_LINK_SPEED_100_FULL)
724 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
726 /* Setup link based on the new speed settings */
727 hw->phy.ops.setup_link(hw);
733 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
734 * @hw: pointer to hardware structure
736 * Determines the supported link capabilities by reading the PHY auto
737 * negotiation register.
739 static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
744 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
749 if (speed_ability & MDIO_SPEED_10G)
750 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
751 if (speed_ability & MDIO_PMA_SPEED_1000)
752 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
753 if (speed_ability & MDIO_PMA_SPEED_100)
754 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
756 switch (hw->mac.type) {
758 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
759 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
761 case ixgbe_mac_X550EM_x:
762 hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
772 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
773 * @hw: pointer to hardware structure
774 * @speed: pointer to link speed
775 * @autoneg: boolean auto-negotiation value
777 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
778 ixgbe_link_speed *speed,
784 if (!hw->phy.speeds_supported)
785 status = ixgbe_get_copper_speeds_supported(hw);
787 *speed = hw->phy.speeds_supported;
792 * ixgbe_check_phy_link_tnx - Determine link and speed status
793 * @hw: pointer to hardware structure
795 * Reads the VS1 register to determine if link is up and the current speed for
798 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
803 u32 max_time_out = 10;
808 /* Initialize speed and link to default case */
810 *speed = IXGBE_LINK_SPEED_10GB_FULL;
813 * Check current speed and link status of the PHY register.
814 * This is a vendor specific register and may have to
815 * be changed for other copper PHYs.
817 for (time_out = 0; time_out < max_time_out; time_out++) {
819 status = hw->phy.ops.read_reg(hw,
823 phy_link = phy_data &
824 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
825 phy_speed = phy_data &
826 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
827 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
830 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
831 *speed = IXGBE_LINK_SPEED_1GB_FULL;
840 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
841 * @hw: pointer to hardware structure
843 * Restart autonegotiation and PHY and waits for completion.
844 * This function always returns success, this is nessary since
845 * it is called via a function pointer that could call other
846 * functions that could return an error.
848 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
850 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
851 bool autoneg = false;
852 ixgbe_link_speed speed;
854 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
856 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
857 /* Set or unset auto-negotiation 10G advertisement */
858 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
862 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
863 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
864 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
866 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
871 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
872 /* Set or unset auto-negotiation 1G advertisement */
873 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
877 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
878 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
879 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
881 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
886 if (speed & IXGBE_LINK_SPEED_100_FULL) {
887 /* Set or unset auto-negotiation 100M advertisement */
888 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
892 autoneg_reg &= ~(ADVERTISE_100FULL |
894 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
895 autoneg_reg |= ADVERTISE_100FULL;
897 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
902 /* Blocked by MNG FW so don't reset PHY */
903 if (ixgbe_check_reset_blocked(hw))
906 /* Restart PHY autonegotiation and wait for completion */
907 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
908 MDIO_MMD_AN, &autoneg_reg);
910 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
912 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
913 MDIO_MMD_AN, autoneg_reg);
918 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
919 * @hw: pointer to hardware structure
920 * @firmware_version: pointer to the PHY Firmware Version
922 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
923 u16 *firmware_version)
927 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
935 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
936 * @hw: pointer to hardware structure
937 * @firmware_version: pointer to the PHY Firmware Version
939 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
940 u16 *firmware_version)
944 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
952 * ixgbe_reset_phy_nl - Performs a PHY reset
953 * @hw: pointer to hardware structure
955 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
957 u16 phy_offset, control, eword, edata, block_crc;
958 bool end_data = false;
959 u16 list_offset, data_offset;
964 /* Blocked by MNG FW so bail */
965 if (ixgbe_check_reset_blocked(hw))
968 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
970 /* reset the PHY and poll for completion */
971 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
972 (phy_data | MDIO_CTRL1_RESET));
974 for (i = 0; i < 100; i++) {
975 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
977 if ((phy_data & MDIO_CTRL1_RESET) == 0)
979 usleep_range(10000, 20000);
982 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
983 hw_dbg(hw, "PHY reset did not complete.\n");
984 return IXGBE_ERR_PHY;
987 /* Get init offsets */
988 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
993 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
997 * Read control word from PHY init contents offset
999 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
1002 control = (eword & IXGBE_CONTROL_MASK_NL) >>
1003 IXGBE_CONTROL_SHIFT_NL;
1004 edata = eword & IXGBE_DATA_MASK_NL;
1006 case IXGBE_DELAY_NL:
1008 hw_dbg(hw, "DELAY: %d MS\n", edata);
1009 usleep_range(edata * 1000, edata * 2000);
1012 hw_dbg(hw, "DATA:\n");
1014 ret_val = hw->eeprom.ops.read(hw, data_offset++,
1018 for (i = 0; i < edata; i++) {
1019 ret_val = hw->eeprom.ops.read(hw, data_offset,
1023 hw->phy.ops.write_reg(hw, phy_offset,
1024 MDIO_MMD_PMAPMD, eword);
1025 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1031 case IXGBE_CONTROL_NL:
1033 hw_dbg(hw, "CONTROL:\n");
1034 if (edata == IXGBE_CONTROL_EOL_NL) {
1035 hw_dbg(hw, "EOL\n");
1037 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1038 hw_dbg(hw, "SOL\n");
1040 hw_dbg(hw, "Bad control value\n");
1041 return IXGBE_ERR_PHY;
1045 hw_dbg(hw, "Bad control type\n");
1046 return IXGBE_ERR_PHY;
1053 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1054 return IXGBE_ERR_PHY;
1058 * ixgbe_identify_module_generic - Identifies module type
1059 * @hw: pointer to hardware structure
1061 * Determines HW type and calls appropriate function.
1063 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1065 switch (hw->mac.ops.get_media_type(hw)) {
1066 case ixgbe_media_type_fiber:
1067 return ixgbe_identify_sfp_module_generic(hw);
1068 case ixgbe_media_type_fiber_qsfp:
1069 return ixgbe_identify_qsfp_module_generic(hw);
1071 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1072 return IXGBE_ERR_SFP_NOT_PRESENT;
1075 return IXGBE_ERR_SFP_NOT_PRESENT;
1079 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1080 * @hw: pointer to hardware structure
1082 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1084 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1086 struct ixgbe_adapter *adapter = hw->back;
1089 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1091 u8 comp_codes_1g = 0;
1092 u8 comp_codes_10g = 0;
1093 u8 oui_bytes[3] = {0, 0, 0};
1096 u16 enforce_sfp = 0;
1098 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1099 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1100 return IXGBE_ERR_SFP_NOT_PRESENT;
1103 status = hw->phy.ops.read_i2c_eeprom(hw,
1104 IXGBE_SFF_IDENTIFIER,
1108 goto err_read_i2c_eeprom;
1110 /* LAN ID is needed for sfp_type determination */
1111 hw->mac.ops.set_lan_id(hw);
1113 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1114 hw->phy.type = ixgbe_phy_sfp_unsupported;
1115 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1117 status = hw->phy.ops.read_i2c_eeprom(hw,
1118 IXGBE_SFF_1GBE_COMP_CODES,
1122 goto err_read_i2c_eeprom;
1124 status = hw->phy.ops.read_i2c_eeprom(hw,
1125 IXGBE_SFF_10GBE_COMP_CODES,
1129 goto err_read_i2c_eeprom;
1130 status = hw->phy.ops.read_i2c_eeprom(hw,
1131 IXGBE_SFF_CABLE_TECHNOLOGY,
1135 goto err_read_i2c_eeprom;
1142 * 3 SFP_DA_CORE0 - 82599-specific
1143 * 4 SFP_DA_CORE1 - 82599-specific
1144 * 5 SFP_SR/LR_CORE0 - 82599-specific
1145 * 6 SFP_SR/LR_CORE1 - 82599-specific
1146 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1147 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1148 * 9 SFP_1g_cu_CORE0 - 82599-specific
1149 * 10 SFP_1g_cu_CORE1 - 82599-specific
1150 * 11 SFP_1g_sx_CORE0 - 82599-specific
1151 * 12 SFP_1g_sx_CORE1 - 82599-specific
1153 if (hw->mac.type == ixgbe_mac_82598EB) {
1154 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1155 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1156 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1157 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1158 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1159 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1161 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1162 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1163 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1164 if (hw->bus.lan_id == 0)
1166 ixgbe_sfp_type_da_cu_core0;
1169 ixgbe_sfp_type_da_cu_core1;
1170 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1171 hw->phy.ops.read_i2c_eeprom(
1172 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1175 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1176 if (hw->bus.lan_id == 0)
1178 ixgbe_sfp_type_da_act_lmt_core0;
1181 ixgbe_sfp_type_da_act_lmt_core1;
1184 ixgbe_sfp_type_unknown;
1186 } else if (comp_codes_10g &
1187 (IXGBE_SFF_10GBASESR_CAPABLE |
1188 IXGBE_SFF_10GBASELR_CAPABLE)) {
1189 if (hw->bus.lan_id == 0)
1191 ixgbe_sfp_type_srlr_core0;
1194 ixgbe_sfp_type_srlr_core1;
1195 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1196 if (hw->bus.lan_id == 0)
1198 ixgbe_sfp_type_1g_cu_core0;
1201 ixgbe_sfp_type_1g_cu_core1;
1202 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1203 if (hw->bus.lan_id == 0)
1205 ixgbe_sfp_type_1g_sx_core0;
1208 ixgbe_sfp_type_1g_sx_core1;
1209 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1210 if (hw->bus.lan_id == 0)
1212 ixgbe_sfp_type_1g_lx_core0;
1215 ixgbe_sfp_type_1g_lx_core1;
1217 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1221 if (hw->phy.sfp_type != stored_sfp_type)
1222 hw->phy.sfp_setup_needed = true;
1224 /* Determine if the SFP+ PHY is dual speed or not. */
1225 hw->phy.multispeed_fiber = false;
1226 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1227 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1228 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1229 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1230 hw->phy.multispeed_fiber = true;
1232 /* Determine PHY vendor */
1233 if (hw->phy.type != ixgbe_phy_nl) {
1234 hw->phy.id = identifier;
1235 status = hw->phy.ops.read_i2c_eeprom(hw,
1236 IXGBE_SFF_VENDOR_OUI_BYTE0,
1240 goto err_read_i2c_eeprom;
1242 status = hw->phy.ops.read_i2c_eeprom(hw,
1243 IXGBE_SFF_VENDOR_OUI_BYTE1,
1247 goto err_read_i2c_eeprom;
1249 status = hw->phy.ops.read_i2c_eeprom(hw,
1250 IXGBE_SFF_VENDOR_OUI_BYTE2,
1254 goto err_read_i2c_eeprom;
1257 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1258 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1259 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1261 switch (vendor_oui) {
1262 case IXGBE_SFF_VENDOR_OUI_TYCO:
1263 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1265 ixgbe_phy_sfp_passive_tyco;
1267 case IXGBE_SFF_VENDOR_OUI_FTL:
1268 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1269 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1271 hw->phy.type = ixgbe_phy_sfp_ftl;
1273 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1274 hw->phy.type = ixgbe_phy_sfp_avago;
1276 case IXGBE_SFF_VENDOR_OUI_INTEL:
1277 hw->phy.type = ixgbe_phy_sfp_intel;
1280 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1282 ixgbe_phy_sfp_passive_unknown;
1283 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1285 ixgbe_phy_sfp_active_unknown;
1287 hw->phy.type = ixgbe_phy_sfp_unknown;
1292 /* Allow any DA cable vendor */
1293 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1294 IXGBE_SFF_DA_ACTIVE_CABLE))
1297 /* Verify supported 1G SFP modules */
1298 if (comp_codes_10g == 0 &&
1299 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1300 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1301 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1302 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1303 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1304 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1305 hw->phy.type = ixgbe_phy_sfp_unsupported;
1306 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1309 /* Anything else 82598-based is supported */
1310 if (hw->mac.type == ixgbe_mac_82598EB)
1313 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1314 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1315 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1316 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1317 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1318 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1319 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1320 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1321 /* Make sure we're a supported PHY type */
1322 if (hw->phy.type == ixgbe_phy_sfp_intel)
1324 if (hw->allow_unsupported_sfp) {
1325 e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
1328 hw_dbg(hw, "SFP+ module not supported\n");
1329 hw->phy.type = ixgbe_phy_sfp_unsupported;
1330 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1334 err_read_i2c_eeprom:
1335 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1336 if (hw->phy.type != ixgbe_phy_nl) {
1338 hw->phy.type = ixgbe_phy_unknown;
1340 return IXGBE_ERR_SFP_NOT_PRESENT;
1344 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1345 * @hw: pointer to hardware structure
1347 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1349 static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
1351 struct ixgbe_adapter *adapter = hw->back;
1354 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1356 u8 comp_codes_1g = 0;
1357 u8 comp_codes_10g = 0;
1358 u8 oui_bytes[3] = {0, 0, 0};
1359 u16 enforce_sfp = 0;
1361 u8 cable_length = 0;
1363 bool active_cable = false;
1365 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1366 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1367 return IXGBE_ERR_SFP_NOT_PRESENT;
1370 /* LAN ID is needed for sfp_type determination */
1371 hw->mac.ops.set_lan_id(hw);
1373 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1377 goto err_read_i2c_eeprom;
1379 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1380 hw->phy.type = ixgbe_phy_sfp_unsupported;
1381 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1384 hw->phy.id = identifier;
1386 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1390 goto err_read_i2c_eeprom;
1392 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1396 goto err_read_i2c_eeprom;
1398 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1399 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1400 if (hw->bus.lan_id == 0)
1401 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1403 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
1404 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1405 IXGBE_SFF_10GBASELR_CAPABLE)) {
1406 if (hw->bus.lan_id == 0)
1407 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1409 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1411 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1412 active_cable = true;
1414 if (!active_cable) {
1415 /* check for active DA cables that pre-date
1418 hw->phy.ops.read_i2c_eeprom(hw,
1419 IXGBE_SFF_QSFP_CONNECTOR,
1422 hw->phy.ops.read_i2c_eeprom(hw,
1423 IXGBE_SFF_QSFP_CABLE_LENGTH,
1426 hw->phy.ops.read_i2c_eeprom(hw,
1427 IXGBE_SFF_QSFP_DEVICE_TECH,
1431 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1432 (cable_length > 0) &&
1433 ((device_tech >> 4) ==
1434 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1435 active_cable = true;
1439 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1440 if (hw->bus.lan_id == 0)
1442 ixgbe_sfp_type_da_act_lmt_core0;
1445 ixgbe_sfp_type_da_act_lmt_core1;
1447 /* unsupported module type */
1448 hw->phy.type = ixgbe_phy_sfp_unsupported;
1449 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1453 if (hw->phy.sfp_type != stored_sfp_type)
1454 hw->phy.sfp_setup_needed = true;
1456 /* Determine if the QSFP+ PHY is dual speed or not. */
1457 hw->phy.multispeed_fiber = false;
1458 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1459 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1460 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1461 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1462 hw->phy.multispeed_fiber = true;
1464 /* Determine PHY vendor for optical modules */
1465 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1466 IXGBE_SFF_10GBASELR_CAPABLE)) {
1467 status = hw->phy.ops.read_i2c_eeprom(hw,
1468 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1472 goto err_read_i2c_eeprom;
1474 status = hw->phy.ops.read_i2c_eeprom(hw,
1475 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1479 goto err_read_i2c_eeprom;
1481 status = hw->phy.ops.read_i2c_eeprom(hw,
1482 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1486 goto err_read_i2c_eeprom;
1489 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1490 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1491 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1493 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1494 hw->phy.type = ixgbe_phy_qsfp_intel;
1496 hw->phy.type = ixgbe_phy_qsfp_unknown;
1498 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1499 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1500 /* Make sure we're a supported PHY type */
1501 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1503 if (hw->allow_unsupported_sfp) {
1504 e_warn(drv, "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. Intel Corporation is not responsible for any harm caused by using untested modules.\n");
1507 hw_dbg(hw, "QSFP module not supported\n");
1508 hw->phy.type = ixgbe_phy_sfp_unsupported;
1509 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1515 err_read_i2c_eeprom:
1516 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1518 hw->phy.type = ixgbe_phy_unknown;
1520 return IXGBE_ERR_SFP_NOT_PRESENT;
1524 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1525 * @hw: pointer to hardware structure
1526 * @list_offset: offset to the SFP ID list
1527 * @data_offset: offset to the SFP data block
1529 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1530 * so it returns the offsets to the phy init sequence block.
1532 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1537 u16 sfp_type = hw->phy.sfp_type;
1539 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1540 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1542 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1543 return IXGBE_ERR_SFP_NOT_PRESENT;
1545 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1546 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1547 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1550 * Limiting active cables and 1G Phys must be initialized as
1553 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1554 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1555 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1556 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1557 sfp_type = ixgbe_sfp_type_srlr_core0;
1558 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1559 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1560 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1561 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1562 sfp_type = ixgbe_sfp_type_srlr_core1;
1564 /* Read offset to PHY init contents */
1565 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1566 hw_err(hw, "eeprom read at %d failed\n",
1567 IXGBE_PHY_INIT_OFFSET_NL);
1568 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1571 if ((!*list_offset) || (*list_offset == 0xFFFF))
1572 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1574 /* Shift offset to first ID word */
1578 * Find the matching SFP ID in the EEPROM
1579 * and program the init sequence
1581 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1584 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1585 if (sfp_id == sfp_type) {
1587 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1589 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1590 hw_dbg(hw, "SFP+ module not supported\n");
1591 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1596 (*list_offset) += 2;
1597 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1602 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1603 hw_dbg(hw, "No matching SFP+ module found\n");
1604 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1610 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1611 return IXGBE_ERR_PHY;
1615 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1616 * @hw: pointer to hardware structure
1617 * @byte_offset: EEPROM byte offset to read
1618 * @eeprom_data: value read
1620 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1622 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1625 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1626 IXGBE_I2C_EEPROM_DEV_ADDR,
1631 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1632 * @hw: pointer to hardware structure
1633 * @byte_offset: byte offset at address 0xA2
1634 * @eeprom_data: value read
1636 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1638 s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1641 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1642 IXGBE_I2C_EEPROM_DEV_ADDR2,
1647 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1648 * @hw: pointer to hardware structure
1649 * @byte_offset: EEPROM byte offset to write
1650 * @eeprom_data: value to write
1652 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1654 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1657 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1658 IXGBE_I2C_EEPROM_DEV_ADDR,
1663 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1664 * @hw: pointer to hardware structure
1665 * @byte_offset: byte offset to read
1668 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1669 * a specified device address.
1671 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1672 u8 dev_addr, u8 *data)
1677 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1682 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1683 return IXGBE_ERR_SWFW_SYNC;
1685 ixgbe_i2c_start(hw);
1687 /* Device Address and write indication */
1688 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1692 status = ixgbe_get_i2c_ack(hw);
1696 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1700 status = ixgbe_get_i2c_ack(hw);
1704 ixgbe_i2c_start(hw);
1706 /* Device Address and read indication */
1707 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1711 status = ixgbe_get_i2c_ack(hw);
1715 status = ixgbe_clock_in_i2c_byte(hw, data);
1719 status = ixgbe_clock_out_i2c_bit(hw, nack);
1727 ixgbe_i2c_bus_clear(hw);
1728 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1731 if (retry < max_retry)
1732 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1734 hw_dbg(hw, "I2C byte read error.\n");
1736 } while (retry < max_retry);
1738 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1744 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1745 * @hw: pointer to hardware structure
1746 * @byte_offset: byte offset to write
1747 * @data: value to write
1749 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1750 * a specified device address.
1752 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1753 u8 dev_addr, u8 data)
1758 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1760 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1761 return IXGBE_ERR_SWFW_SYNC;
1764 ixgbe_i2c_start(hw);
1766 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1770 status = ixgbe_get_i2c_ack(hw);
1774 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1778 status = ixgbe_get_i2c_ack(hw);
1782 status = ixgbe_clock_out_i2c_byte(hw, data);
1786 status = ixgbe_get_i2c_ack(hw);
1794 ixgbe_i2c_bus_clear(hw);
1796 if (retry < max_retry)
1797 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1799 hw_dbg(hw, "I2C byte write error.\n");
1800 } while (retry < max_retry);
1802 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1808 * ixgbe_i2c_start - Sets I2C start condition
1809 * @hw: pointer to hardware structure
1811 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1813 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1815 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1817 /* Start condition must begin with data and clock high */
1818 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1819 ixgbe_raise_i2c_clk(hw, &i2cctl);
1821 /* Setup time for start condition (4.7us) */
1822 udelay(IXGBE_I2C_T_SU_STA);
1824 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1826 /* Hold time for start condition (4us) */
1827 udelay(IXGBE_I2C_T_HD_STA);
1829 ixgbe_lower_i2c_clk(hw, &i2cctl);
1831 /* Minimum low period of clock is 4.7 us */
1832 udelay(IXGBE_I2C_T_LOW);
1837 * ixgbe_i2c_stop - Sets I2C stop condition
1838 * @hw: pointer to hardware structure
1840 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1842 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1844 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1846 /* Stop condition must begin with data low and clock high */
1847 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1848 ixgbe_raise_i2c_clk(hw, &i2cctl);
1850 /* Setup time for stop condition (4us) */
1851 udelay(IXGBE_I2C_T_SU_STO);
1853 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1855 /* bus free time between stop and start (4.7us)*/
1856 udelay(IXGBE_I2C_T_BUF);
1860 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1861 * @hw: pointer to hardware structure
1862 * @data: data byte to clock in
1864 * Clocks in one byte data via I2C data/clock
1866 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1871 for (i = 7; i >= 0; i--) {
1872 ixgbe_clock_in_i2c_bit(hw, &bit);
1880 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1881 * @hw: pointer to hardware structure
1882 * @data: data byte clocked out
1884 * Clocks out one byte data via I2C data/clock
1886 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1893 for (i = 7; i >= 0; i--) {
1894 bit = (data >> i) & 0x1;
1895 status = ixgbe_clock_out_i2c_bit(hw, bit);
1901 /* Release SDA line (set high) */
1902 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1903 i2cctl |= IXGBE_I2C_DATA_OUT(hw);
1904 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), i2cctl);
1905 IXGBE_WRITE_FLUSH(hw);
1911 * ixgbe_get_i2c_ack - Polls for I2C ACK
1912 * @hw: pointer to hardware structure
1914 * Clocks in/out one bit via I2C data/clock
1916 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1920 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1924 ixgbe_raise_i2c_clk(hw, &i2cctl);
1927 /* Minimum high period of clock is 4us */
1928 udelay(IXGBE_I2C_T_HIGH);
1930 /* Poll for ACK. Note that ACK in I2C spec is
1931 * transition from 1 to 0 */
1932 for (i = 0; i < timeout; i++) {
1933 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1934 ack = ixgbe_get_i2c_data(hw, &i2cctl);
1942 hw_dbg(hw, "I2C ack was not received.\n");
1943 status = IXGBE_ERR_I2C;
1946 ixgbe_lower_i2c_clk(hw, &i2cctl);
1948 /* Minimum low period of clock is 4.7 us */
1949 udelay(IXGBE_I2C_T_LOW);
1955 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1956 * @hw: pointer to hardware structure
1957 * @data: read data value
1959 * Clocks in one bit via I2C data/clock
1961 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1963 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1965 ixgbe_raise_i2c_clk(hw, &i2cctl);
1967 /* Minimum high period of clock is 4us */
1968 udelay(IXGBE_I2C_T_HIGH);
1970 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1971 *data = ixgbe_get_i2c_data(hw, &i2cctl);
1973 ixgbe_lower_i2c_clk(hw, &i2cctl);
1975 /* Minimum low period of clock is 4.7 us */
1976 udelay(IXGBE_I2C_T_LOW);
1982 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1983 * @hw: pointer to hardware structure
1984 * @data: data value to write
1986 * Clocks out one bit via I2C data/clock
1988 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1991 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
1993 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1995 ixgbe_raise_i2c_clk(hw, &i2cctl);
1997 /* Minimum high period of clock is 4us */
1998 udelay(IXGBE_I2C_T_HIGH);
2000 ixgbe_lower_i2c_clk(hw, &i2cctl);
2002 /* Minimum low period of clock is 4.7 us.
2003 * This also takes care of the data hold time.
2005 udelay(IXGBE_I2C_T_LOW);
2007 hw_dbg(hw, "I2C data was not set to %X\n", data);
2008 return IXGBE_ERR_I2C;
2014 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2015 * @hw: pointer to hardware structure
2016 * @i2cctl: Current value of I2CCTL register
2018 * Raises the I2C clock line '0'->'1'
2020 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2023 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2026 for (i = 0; i < timeout; i++) {
2027 *i2cctl |= IXGBE_I2C_CLK_OUT(hw);
2028 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2029 IXGBE_WRITE_FLUSH(hw);
2030 /* SCL rise time (1000ns) */
2031 udelay(IXGBE_I2C_T_RISE);
2033 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2034 if (i2cctl_r & IXGBE_I2C_CLK_IN(hw))
2040 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2041 * @hw: pointer to hardware structure
2042 * @i2cctl: Current value of I2CCTL register
2044 * Lowers the I2C clock line '1'->'0'
2046 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2049 *i2cctl &= ~IXGBE_I2C_CLK_OUT(hw);
2051 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2052 IXGBE_WRITE_FLUSH(hw);
2054 /* SCL fall time (300ns) */
2055 udelay(IXGBE_I2C_T_FALL);
2059 * ixgbe_set_i2c_data - Sets the I2C data bit
2060 * @hw: pointer to hardware structure
2061 * @i2cctl: Current value of I2CCTL register
2062 * @data: I2C data value (0 or 1) to set
2064 * Sets the I2C data bit
2066 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2069 *i2cctl |= IXGBE_I2C_DATA_OUT(hw);
2071 *i2cctl &= ~IXGBE_I2C_DATA_OUT(hw);
2073 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL(hw), *i2cctl);
2074 IXGBE_WRITE_FLUSH(hw);
2076 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2077 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2079 /* Verify data was set correctly */
2080 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2081 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
2082 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
2083 return IXGBE_ERR_I2C;
2090 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2091 * @hw: pointer to hardware structure
2092 * @i2cctl: Current value of I2CCTL register
2094 * Returns the I2C data bit value
2096 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
2098 if (*i2cctl & IXGBE_I2C_DATA_IN(hw))
2104 * ixgbe_i2c_bus_clear - Clears the I2C bus
2105 * @hw: pointer to hardware structure
2107 * Clears the I2C bus by sending nine clock pulses.
2108 * Used when data line is stuck low.
2110 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2112 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL(hw));
2115 ixgbe_i2c_start(hw);
2117 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2119 for (i = 0; i < 9; i++) {
2120 ixgbe_raise_i2c_clk(hw, &i2cctl);
2122 /* Min high period of clock is 4us */
2123 udelay(IXGBE_I2C_T_HIGH);
2125 ixgbe_lower_i2c_clk(hw, &i2cctl);
2127 /* Min low period of clock is 4.7us*/
2128 udelay(IXGBE_I2C_T_LOW);
2131 ixgbe_i2c_start(hw);
2133 /* Put the i2c bus back to default state */
2138 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
2139 * @hw: pointer to hardware structure
2141 * Checks if the LASI temp alarm status was triggered due to overtemp
2143 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2147 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2150 /* Check that the LASI temp alarm status was triggered */
2151 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2152 MDIO_MMD_PMAPMD, &phy_data);
2154 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2157 return IXGBE_ERR_OVERTEMP;
2160 /** ixgbe_set_copper_phy_power - Control power for copper phy
2161 * @hw: pointer to hardware structure
2162 * @on: true for on, false for off
2164 s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2169 /* Bail if we don't have copper phy */
2170 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2173 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2174 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2180 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2182 if (ixgbe_check_reset_blocked(hw))
2184 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2187 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2188 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,