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) {
246 hw->phy.lan_id = IXGBE_READ_REG(hw, IXGBE_STATUS) &
247 IXGBE_STATUS_LAN_ID_1;
249 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
251 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
254 if (hw->phy.type == ixgbe_phy_unknown) {
255 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
256 hw->phy.mdio.prtad = phy_addr;
257 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
258 ixgbe_get_phy_id(hw);
260 ixgbe_get_phy_type_from_id(hw->phy.id);
262 if (hw->phy.type == ixgbe_phy_unknown) {
263 hw->phy.ops.read_reg(hw,
268 (MDIO_PMA_EXTABLE_10GBT |
269 MDIO_PMA_EXTABLE_1000BT))
271 ixgbe_phy_cu_unknown;
280 /* clear value if nothing found */
281 hw->phy.mdio.prtad = 0;
282 return IXGBE_ERR_PHY_ADDR_INVALID;
288 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
289 * @hw: pointer to the hardware structure
291 * This function checks the MMNGC.MNG_VETO bit to see if there are
292 * any constraints on link from manageability. For MAC's that don't
293 * have this bit just return false since the link can not be blocked
296 bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
300 /* If we don't have this bit, it can't be blocking */
301 if (hw->mac.type == ixgbe_mac_82598EB)
304 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
305 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
306 hw_dbg(hw, "MNG_VETO bit detected.\n");
314 * ixgbe_get_phy_id - Get the phy type
315 * @hw: pointer to hardware structure
318 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
324 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
328 hw->phy.id = (u32)(phy_id_high << 16);
329 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
331 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
332 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
338 * ixgbe_get_phy_type_from_id - Get the phy type
339 * @hw: pointer to hardware structure
342 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
344 enum ixgbe_phy_type phy_type;
348 phy_type = ixgbe_phy_tn;
351 phy_type = ixgbe_phy_aq;
354 phy_type = ixgbe_phy_qt;
357 phy_type = ixgbe_phy_nl;
360 phy_type = ixgbe_phy_unknown;
368 * ixgbe_reset_phy_generic - Performs a PHY reset
369 * @hw: pointer to hardware structure
371 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
377 if (hw->phy.type == ixgbe_phy_unknown)
378 status = ixgbe_identify_phy_generic(hw);
380 if (status != 0 || hw->phy.type == ixgbe_phy_none)
383 /* Don't reset PHY if it's shut down due to overtemp. */
384 if (!hw->phy.reset_if_overtemp &&
385 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
388 /* Blocked by MNG FW so bail */
389 if (ixgbe_check_reset_blocked(hw))
393 * Perform soft PHY reset to the PHY_XS.
394 * This will cause a soft reset to the PHY
396 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
401 * Poll for reset bit to self-clear indicating reset is complete.
402 * Some PHYs could take up to 3 seconds to complete and need about
403 * 1.7 usec delay after the reset is complete.
405 for (i = 0; i < 30; i++) {
407 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
408 MDIO_MMD_PHYXS, &ctrl);
409 if (!(ctrl & MDIO_CTRL1_RESET)) {
415 if (ctrl & MDIO_CTRL1_RESET) {
416 hw_dbg(hw, "PHY reset polling failed to complete.\n");
417 return IXGBE_ERR_RESET_FAILED;
424 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
426 * @hw: pointer to hardware structure
427 * @reg_addr: 32 bit address of PHY register to read
428 * @phy_data: Pointer to read data from PHY register
430 s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
433 u32 i, data, command;
435 /* Setup and write the address cycle command */
436 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
437 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
438 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
439 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
441 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
443 /* Check every 10 usec to see if the address cycle completed.
444 * The MDI Command bit will clear when the operation is
447 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
450 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
451 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
456 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
457 hw_dbg(hw, "PHY address command did not complete.\n");
458 return IXGBE_ERR_PHY;
461 /* Address cycle complete, setup and write the read
464 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
465 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
466 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
467 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
469 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
471 /* Check every 10 usec to see if the address cycle
472 * completed. The MDI Command bit will clear when the
473 * operation is complete
475 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
478 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
479 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
483 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
484 hw_dbg(hw, "PHY read command didn't complete\n");
485 return IXGBE_ERR_PHY;
488 /* Read operation is complete. Get the data
491 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
492 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
493 *phy_data = (u16)(data);
499 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
500 * using the SWFW lock - this function is needed in most cases
501 * @hw: pointer to hardware structure
502 * @reg_addr: 32 bit address of PHY register to read
503 * @phy_data: Pointer to read data from PHY register
505 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
506 u32 device_type, u16 *phy_data)
509 u32 gssr = hw->phy.phy_semaphore_mask;
511 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
512 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
514 hw->mac.ops.release_swfw_sync(hw, gssr);
516 return IXGBE_ERR_SWFW_SYNC;
523 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
525 * @hw: pointer to hardware structure
526 * @reg_addr: 32 bit PHY register to write
527 * @device_type: 5 bit device type
528 * @phy_data: Data to write to the PHY register
530 s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
531 u32 device_type, u16 phy_data)
535 /* Put the data in the MDI single read and write data register*/
536 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
538 /* Setup and write the address cycle command */
539 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
540 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
541 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
542 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
544 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
547 * Check every 10 usec to see if the address cycle completed.
548 * The MDI Command bit will clear when the operation is
551 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
554 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
555 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
559 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
560 hw_dbg(hw, "PHY address cmd didn't complete\n");
561 return IXGBE_ERR_PHY;
565 * Address cycle complete, setup and write the write
568 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
569 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
570 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
571 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
573 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
575 /* Check every 10 usec to see if the address cycle
576 * completed. The MDI Command bit will clear when the
577 * operation is complete
579 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
582 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
583 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
587 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
588 hw_dbg(hw, "PHY write cmd didn't complete\n");
589 return IXGBE_ERR_PHY;
596 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
597 * using SWFW lock- this function is needed in most cases
598 * @hw: pointer to hardware structure
599 * @reg_addr: 32 bit PHY register to write
600 * @device_type: 5 bit device type
601 * @phy_data: Data to write to the PHY register
603 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
604 u32 device_type, u16 phy_data)
609 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
610 gssr = IXGBE_GSSR_PHY1_SM;
612 gssr = IXGBE_GSSR_PHY0_SM;
614 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
615 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
617 hw->mac.ops.release_swfw_sync(hw, gssr);
619 return IXGBE_ERR_SWFW_SYNC;
626 * ixgbe_setup_phy_link_generic - Set and restart autoneg
627 * @hw: pointer to hardware structure
629 * Restart autonegotiation and PHY and waits for completion.
631 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
634 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
635 bool autoneg = false;
636 ixgbe_link_speed speed;
638 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
640 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
641 /* Set or unset auto-negotiation 10G advertisement */
642 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
646 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
647 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
648 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
650 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
655 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
656 /* Set or unset auto-negotiation 1G advertisement */
657 hw->phy.ops.read_reg(hw,
658 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
662 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
663 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
664 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
666 hw->phy.ops.write_reg(hw,
667 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
672 if (speed & IXGBE_LINK_SPEED_100_FULL) {
673 /* Set or unset auto-negotiation 100M advertisement */
674 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
678 autoneg_reg &= ~(ADVERTISE_100FULL |
680 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
681 autoneg_reg |= ADVERTISE_100FULL;
683 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
688 /* Blocked by MNG FW so don't reset PHY */
689 if (ixgbe_check_reset_blocked(hw))
692 /* Restart PHY autonegotiation and wait for completion */
693 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
694 MDIO_MMD_AN, &autoneg_reg);
696 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
698 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
699 MDIO_MMD_AN, autoneg_reg);
705 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
706 * @hw: pointer to hardware structure
707 * @speed: new link speed
709 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
710 ixgbe_link_speed speed,
711 bool autoneg_wait_to_complete)
715 * Clear autoneg_advertised and set new values based on input link
718 hw->phy.autoneg_advertised = 0;
720 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
721 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
723 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
724 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
726 if (speed & IXGBE_LINK_SPEED_100_FULL)
727 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
729 /* Setup link based on the new speed settings */
730 hw->phy.ops.setup_link(hw);
736 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
737 * @hw: pointer to hardware structure
738 * @speed: pointer to link speed
739 * @autoneg: boolean auto-negotiation value
741 * Determines the link capabilities by reading the AUTOC register.
743 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
744 ixgbe_link_speed *speed,
753 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
757 if (speed_ability & MDIO_SPEED_10G)
758 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
759 if (speed_ability & MDIO_PMA_SPEED_1000)
760 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
761 if (speed_ability & MDIO_PMA_SPEED_100)
762 *speed |= IXGBE_LINK_SPEED_100_FULL;
765 /* Internal PHY does not support 100 Mbps */
766 if (hw->mac.type == ixgbe_mac_X550EM_x)
767 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
773 * ixgbe_check_phy_link_tnx - Determine link and speed status
774 * @hw: pointer to hardware structure
776 * Reads the VS1 register to determine if link is up and the current speed for
779 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
784 u32 max_time_out = 10;
789 /* Initialize speed and link to default case */
791 *speed = IXGBE_LINK_SPEED_10GB_FULL;
794 * Check current speed and link status of the PHY register.
795 * This is a vendor specific register and may have to
796 * be changed for other copper PHYs.
798 for (time_out = 0; time_out < max_time_out; time_out++) {
800 status = hw->phy.ops.read_reg(hw,
804 phy_link = phy_data &
805 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
806 phy_speed = phy_data &
807 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
808 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
811 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
812 *speed = IXGBE_LINK_SPEED_1GB_FULL;
821 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
822 * @hw: pointer to hardware structure
824 * Restart autonegotiation and PHY and waits for completion.
825 * This function always returns success, this is nessary since
826 * it is called via a function pointer that could call other
827 * functions that could return an error.
829 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
831 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
832 bool autoneg = false;
833 ixgbe_link_speed speed;
835 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
837 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
838 /* Set or unset auto-negotiation 10G advertisement */
839 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
843 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
844 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
845 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
847 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
852 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
853 /* Set or unset auto-negotiation 1G advertisement */
854 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
858 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
859 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
860 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
862 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
867 if (speed & IXGBE_LINK_SPEED_100_FULL) {
868 /* Set or unset auto-negotiation 100M advertisement */
869 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
873 autoneg_reg &= ~(ADVERTISE_100FULL |
875 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
876 autoneg_reg |= ADVERTISE_100FULL;
878 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
883 /* Blocked by MNG FW so don't reset PHY */
884 if (ixgbe_check_reset_blocked(hw))
887 /* Restart PHY autonegotiation and wait for completion */
888 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
889 MDIO_MMD_AN, &autoneg_reg);
891 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
893 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
894 MDIO_MMD_AN, autoneg_reg);
899 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
900 * @hw: pointer to hardware structure
901 * @firmware_version: pointer to the PHY Firmware Version
903 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
904 u16 *firmware_version)
908 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
916 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
917 * @hw: pointer to hardware structure
918 * @firmware_version: pointer to the PHY Firmware Version
920 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
921 u16 *firmware_version)
925 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
933 * ixgbe_reset_phy_nl - Performs a PHY reset
934 * @hw: pointer to hardware structure
936 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
938 u16 phy_offset, control, eword, edata, block_crc;
939 bool end_data = false;
940 u16 list_offset, data_offset;
945 /* Blocked by MNG FW so bail */
946 if (ixgbe_check_reset_blocked(hw))
949 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
951 /* reset the PHY and poll for completion */
952 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
953 (phy_data | MDIO_CTRL1_RESET));
955 for (i = 0; i < 100; i++) {
956 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
958 if ((phy_data & MDIO_CTRL1_RESET) == 0)
960 usleep_range(10000, 20000);
963 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
964 hw_dbg(hw, "PHY reset did not complete.\n");
965 return IXGBE_ERR_PHY;
968 /* Get init offsets */
969 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
974 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
978 * Read control word from PHY init contents offset
980 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
983 control = (eword & IXGBE_CONTROL_MASK_NL) >>
984 IXGBE_CONTROL_SHIFT_NL;
985 edata = eword & IXGBE_DATA_MASK_NL;
989 hw_dbg(hw, "DELAY: %d MS\n", edata);
990 usleep_range(edata * 1000, edata * 2000);
993 hw_dbg(hw, "DATA:\n");
995 ret_val = hw->eeprom.ops.read(hw, data_offset++,
999 for (i = 0; i < edata; i++) {
1000 ret_val = hw->eeprom.ops.read(hw, data_offset,
1004 hw->phy.ops.write_reg(hw, phy_offset,
1005 MDIO_MMD_PMAPMD, eword);
1006 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
1012 case IXGBE_CONTROL_NL:
1014 hw_dbg(hw, "CONTROL:\n");
1015 if (edata == IXGBE_CONTROL_EOL_NL) {
1016 hw_dbg(hw, "EOL\n");
1018 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1019 hw_dbg(hw, "SOL\n");
1021 hw_dbg(hw, "Bad control value\n");
1022 return IXGBE_ERR_PHY;
1026 hw_dbg(hw, "Bad control type\n");
1027 return IXGBE_ERR_PHY;
1034 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
1035 return IXGBE_ERR_PHY;
1039 * ixgbe_identify_module_generic - Identifies module type
1040 * @hw: pointer to hardware structure
1042 * Determines HW type and calls appropriate function.
1044 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1046 switch (hw->mac.ops.get_media_type(hw)) {
1047 case ixgbe_media_type_fiber:
1048 return ixgbe_identify_sfp_module_generic(hw);
1049 case ixgbe_media_type_fiber_qsfp:
1050 return ixgbe_identify_qsfp_module_generic(hw);
1052 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1053 return IXGBE_ERR_SFP_NOT_PRESENT;
1056 return IXGBE_ERR_SFP_NOT_PRESENT;
1060 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1061 * @hw: pointer to hardware structure
1063 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1065 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1067 struct ixgbe_adapter *adapter = hw->back;
1070 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1072 u8 comp_codes_1g = 0;
1073 u8 comp_codes_10g = 0;
1074 u8 oui_bytes[3] = {0, 0, 0};
1077 u16 enforce_sfp = 0;
1079 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1080 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1081 return IXGBE_ERR_SFP_NOT_PRESENT;
1084 status = hw->phy.ops.read_i2c_eeprom(hw,
1085 IXGBE_SFF_IDENTIFIER,
1089 goto err_read_i2c_eeprom;
1091 /* LAN ID is needed for sfp_type determination */
1092 hw->mac.ops.set_lan_id(hw);
1094 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1095 hw->phy.type = ixgbe_phy_sfp_unsupported;
1096 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1098 status = hw->phy.ops.read_i2c_eeprom(hw,
1099 IXGBE_SFF_1GBE_COMP_CODES,
1103 goto err_read_i2c_eeprom;
1105 status = hw->phy.ops.read_i2c_eeprom(hw,
1106 IXGBE_SFF_10GBE_COMP_CODES,
1110 goto err_read_i2c_eeprom;
1111 status = hw->phy.ops.read_i2c_eeprom(hw,
1112 IXGBE_SFF_CABLE_TECHNOLOGY,
1116 goto err_read_i2c_eeprom;
1123 * 3 SFP_DA_CORE0 - 82599-specific
1124 * 4 SFP_DA_CORE1 - 82599-specific
1125 * 5 SFP_SR/LR_CORE0 - 82599-specific
1126 * 6 SFP_SR/LR_CORE1 - 82599-specific
1127 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1128 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1129 * 9 SFP_1g_cu_CORE0 - 82599-specific
1130 * 10 SFP_1g_cu_CORE1 - 82599-specific
1131 * 11 SFP_1g_sx_CORE0 - 82599-specific
1132 * 12 SFP_1g_sx_CORE1 - 82599-specific
1134 if (hw->mac.type == ixgbe_mac_82598EB) {
1135 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1136 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1137 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1138 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1139 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1140 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1142 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1143 } else if (hw->mac.type == ixgbe_mac_82599EB) {
1144 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1145 if (hw->bus.lan_id == 0)
1147 ixgbe_sfp_type_da_cu_core0;
1150 ixgbe_sfp_type_da_cu_core1;
1151 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1152 hw->phy.ops.read_i2c_eeprom(
1153 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1156 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1157 if (hw->bus.lan_id == 0)
1159 ixgbe_sfp_type_da_act_lmt_core0;
1162 ixgbe_sfp_type_da_act_lmt_core1;
1165 ixgbe_sfp_type_unknown;
1167 } else if (comp_codes_10g &
1168 (IXGBE_SFF_10GBASESR_CAPABLE |
1169 IXGBE_SFF_10GBASELR_CAPABLE)) {
1170 if (hw->bus.lan_id == 0)
1172 ixgbe_sfp_type_srlr_core0;
1175 ixgbe_sfp_type_srlr_core1;
1176 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1177 if (hw->bus.lan_id == 0)
1179 ixgbe_sfp_type_1g_cu_core0;
1182 ixgbe_sfp_type_1g_cu_core1;
1183 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1184 if (hw->bus.lan_id == 0)
1186 ixgbe_sfp_type_1g_sx_core0;
1189 ixgbe_sfp_type_1g_sx_core1;
1190 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1191 if (hw->bus.lan_id == 0)
1193 ixgbe_sfp_type_1g_lx_core0;
1196 ixgbe_sfp_type_1g_lx_core1;
1198 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1202 if (hw->phy.sfp_type != stored_sfp_type)
1203 hw->phy.sfp_setup_needed = true;
1205 /* Determine if the SFP+ PHY is dual speed or not. */
1206 hw->phy.multispeed_fiber = false;
1207 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1208 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1209 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1210 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1211 hw->phy.multispeed_fiber = true;
1213 /* Determine PHY vendor */
1214 if (hw->phy.type != ixgbe_phy_nl) {
1215 hw->phy.id = identifier;
1216 status = hw->phy.ops.read_i2c_eeprom(hw,
1217 IXGBE_SFF_VENDOR_OUI_BYTE0,
1221 goto err_read_i2c_eeprom;
1223 status = hw->phy.ops.read_i2c_eeprom(hw,
1224 IXGBE_SFF_VENDOR_OUI_BYTE1,
1228 goto err_read_i2c_eeprom;
1230 status = hw->phy.ops.read_i2c_eeprom(hw,
1231 IXGBE_SFF_VENDOR_OUI_BYTE2,
1235 goto err_read_i2c_eeprom;
1238 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1239 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1240 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1242 switch (vendor_oui) {
1243 case IXGBE_SFF_VENDOR_OUI_TYCO:
1244 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1246 ixgbe_phy_sfp_passive_tyco;
1248 case IXGBE_SFF_VENDOR_OUI_FTL:
1249 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1250 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1252 hw->phy.type = ixgbe_phy_sfp_ftl;
1254 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1255 hw->phy.type = ixgbe_phy_sfp_avago;
1257 case IXGBE_SFF_VENDOR_OUI_INTEL:
1258 hw->phy.type = ixgbe_phy_sfp_intel;
1261 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1263 ixgbe_phy_sfp_passive_unknown;
1264 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1266 ixgbe_phy_sfp_active_unknown;
1268 hw->phy.type = ixgbe_phy_sfp_unknown;
1273 /* Allow any DA cable vendor */
1274 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1275 IXGBE_SFF_DA_ACTIVE_CABLE))
1278 /* Verify supported 1G SFP modules */
1279 if (comp_codes_10g == 0 &&
1280 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1281 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1282 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1283 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1284 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1285 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1286 hw->phy.type = ixgbe_phy_sfp_unsupported;
1287 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1290 /* Anything else 82598-based is supported */
1291 if (hw->mac.type == ixgbe_mac_82598EB)
1294 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1295 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1296 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1297 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1298 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1299 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1300 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1301 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1302 /* Make sure we're a supported PHY type */
1303 if (hw->phy.type == ixgbe_phy_sfp_intel)
1305 if (hw->allow_unsupported_sfp) {
1306 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");
1309 hw_dbg(hw, "SFP+ module not supported\n");
1310 hw->phy.type = ixgbe_phy_sfp_unsupported;
1311 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1315 err_read_i2c_eeprom:
1316 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1317 if (hw->phy.type != ixgbe_phy_nl) {
1319 hw->phy.type = ixgbe_phy_unknown;
1321 return IXGBE_ERR_SFP_NOT_PRESENT;
1325 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1326 * @hw: pointer to hardware structure
1328 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1330 static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
1332 struct ixgbe_adapter *adapter = hw->back;
1335 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1337 u8 comp_codes_1g = 0;
1338 u8 comp_codes_10g = 0;
1339 u8 oui_bytes[3] = {0, 0, 0};
1340 u16 enforce_sfp = 0;
1342 u8 cable_length = 0;
1344 bool active_cable = false;
1346 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1347 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1348 return IXGBE_ERR_SFP_NOT_PRESENT;
1351 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1355 goto err_read_i2c_eeprom;
1357 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1358 hw->phy.type = ixgbe_phy_sfp_unsupported;
1359 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1362 hw->phy.id = identifier;
1364 /* LAN ID is needed for sfp_type determination */
1365 hw->mac.ops.set_lan_id(hw);
1367 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1371 goto err_read_i2c_eeprom;
1373 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1377 goto err_read_i2c_eeprom;
1379 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1380 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1381 if (hw->bus.lan_id == 0)
1382 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1384 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
1385 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1386 IXGBE_SFF_10GBASELR_CAPABLE)) {
1387 if (hw->bus.lan_id == 0)
1388 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1390 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1392 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1393 active_cable = true;
1395 if (!active_cable) {
1396 /* check for active DA cables that pre-date
1399 hw->phy.ops.read_i2c_eeprom(hw,
1400 IXGBE_SFF_QSFP_CONNECTOR,
1403 hw->phy.ops.read_i2c_eeprom(hw,
1404 IXGBE_SFF_QSFP_CABLE_LENGTH,
1407 hw->phy.ops.read_i2c_eeprom(hw,
1408 IXGBE_SFF_QSFP_DEVICE_TECH,
1412 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1413 (cable_length > 0) &&
1414 ((device_tech >> 4) ==
1415 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1416 active_cable = true;
1420 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1421 if (hw->bus.lan_id == 0)
1423 ixgbe_sfp_type_da_act_lmt_core0;
1426 ixgbe_sfp_type_da_act_lmt_core1;
1428 /* unsupported module type */
1429 hw->phy.type = ixgbe_phy_sfp_unsupported;
1430 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1434 if (hw->phy.sfp_type != stored_sfp_type)
1435 hw->phy.sfp_setup_needed = true;
1437 /* Determine if the QSFP+ PHY is dual speed or not. */
1438 hw->phy.multispeed_fiber = false;
1439 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1440 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1441 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1442 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1443 hw->phy.multispeed_fiber = true;
1445 /* Determine PHY vendor for optical modules */
1446 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1447 IXGBE_SFF_10GBASELR_CAPABLE)) {
1448 status = hw->phy.ops.read_i2c_eeprom(hw,
1449 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1453 goto err_read_i2c_eeprom;
1455 status = hw->phy.ops.read_i2c_eeprom(hw,
1456 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1460 goto err_read_i2c_eeprom;
1462 status = hw->phy.ops.read_i2c_eeprom(hw,
1463 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1467 goto err_read_i2c_eeprom;
1470 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1471 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1472 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1474 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1475 hw->phy.type = ixgbe_phy_qsfp_intel;
1477 hw->phy.type = ixgbe_phy_qsfp_unknown;
1479 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1480 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1481 /* Make sure we're a supported PHY type */
1482 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1484 if (hw->allow_unsupported_sfp) {
1485 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");
1488 hw_dbg(hw, "QSFP module not supported\n");
1489 hw->phy.type = ixgbe_phy_sfp_unsupported;
1490 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1496 err_read_i2c_eeprom:
1497 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1499 hw->phy.type = ixgbe_phy_unknown;
1501 return IXGBE_ERR_SFP_NOT_PRESENT;
1505 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1506 * @hw: pointer to hardware structure
1507 * @list_offset: offset to the SFP ID list
1508 * @data_offset: offset to the SFP data block
1510 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1511 * so it returns the offsets to the phy init sequence block.
1513 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1518 u16 sfp_type = hw->phy.sfp_type;
1520 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1521 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1523 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1524 return IXGBE_ERR_SFP_NOT_PRESENT;
1526 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1527 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1528 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1531 * Limiting active cables and 1G Phys must be initialized as
1534 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1535 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1536 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1537 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1538 sfp_type = ixgbe_sfp_type_srlr_core0;
1539 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1540 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1541 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1542 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1543 sfp_type = ixgbe_sfp_type_srlr_core1;
1545 /* Read offset to PHY init contents */
1546 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1547 hw_err(hw, "eeprom read at %d failed\n",
1548 IXGBE_PHY_INIT_OFFSET_NL);
1549 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1552 if ((!*list_offset) || (*list_offset == 0xFFFF))
1553 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1555 /* Shift offset to first ID word */
1559 * Find the matching SFP ID in the EEPROM
1560 * and program the init sequence
1562 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1565 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1566 if (sfp_id == sfp_type) {
1568 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1570 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1571 hw_dbg(hw, "SFP+ module not supported\n");
1572 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1577 (*list_offset) += 2;
1578 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1583 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1584 hw_dbg(hw, "No matching SFP+ module found\n");
1585 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1591 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1592 return IXGBE_ERR_PHY;
1596 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1597 * @hw: pointer to hardware structure
1598 * @byte_offset: EEPROM byte offset to read
1599 * @eeprom_data: value read
1601 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1603 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1606 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1607 IXGBE_I2C_EEPROM_DEV_ADDR,
1612 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1613 * @hw: pointer to hardware structure
1614 * @byte_offset: byte offset at address 0xA2
1615 * @eeprom_data: value read
1617 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1619 s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1622 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1623 IXGBE_I2C_EEPROM_DEV_ADDR2,
1628 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1629 * @hw: pointer to hardware structure
1630 * @byte_offset: EEPROM byte offset to write
1631 * @eeprom_data: value to write
1633 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1635 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1638 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1639 IXGBE_I2C_EEPROM_DEV_ADDR,
1644 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1645 * @hw: pointer to hardware structure
1646 * @byte_offset: byte offset to read
1649 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1650 * a specified device address.
1652 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1653 u8 dev_addr, u8 *data)
1658 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1663 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1664 return IXGBE_ERR_SWFW_SYNC;
1666 ixgbe_i2c_start(hw);
1668 /* Device Address and write indication */
1669 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1673 status = ixgbe_get_i2c_ack(hw);
1677 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1681 status = ixgbe_get_i2c_ack(hw);
1685 ixgbe_i2c_start(hw);
1687 /* Device Address and read indication */
1688 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1692 status = ixgbe_get_i2c_ack(hw);
1696 status = ixgbe_clock_in_i2c_byte(hw, data);
1700 status = ixgbe_clock_out_i2c_bit(hw, nack);
1708 ixgbe_i2c_bus_clear(hw);
1709 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1712 if (retry < max_retry)
1713 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1715 hw_dbg(hw, "I2C byte read error.\n");
1717 } while (retry < max_retry);
1719 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1725 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1726 * @hw: pointer to hardware structure
1727 * @byte_offset: byte offset to write
1728 * @data: value to write
1730 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1731 * a specified device address.
1733 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1734 u8 dev_addr, u8 data)
1739 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1741 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1742 return IXGBE_ERR_SWFW_SYNC;
1745 ixgbe_i2c_start(hw);
1747 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1751 status = ixgbe_get_i2c_ack(hw);
1755 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1759 status = ixgbe_get_i2c_ack(hw);
1763 status = ixgbe_clock_out_i2c_byte(hw, data);
1767 status = ixgbe_get_i2c_ack(hw);
1775 ixgbe_i2c_bus_clear(hw);
1777 if (retry < max_retry)
1778 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1780 hw_dbg(hw, "I2C byte write error.\n");
1781 } while (retry < max_retry);
1783 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1789 * ixgbe_i2c_start - Sets I2C start condition
1790 * @hw: pointer to hardware structure
1792 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1794 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1796 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1798 /* Start condition must begin with data and clock high */
1799 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1800 ixgbe_raise_i2c_clk(hw, &i2cctl);
1802 /* Setup time for start condition (4.7us) */
1803 udelay(IXGBE_I2C_T_SU_STA);
1805 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1807 /* Hold time for start condition (4us) */
1808 udelay(IXGBE_I2C_T_HD_STA);
1810 ixgbe_lower_i2c_clk(hw, &i2cctl);
1812 /* Minimum low period of clock is 4.7 us */
1813 udelay(IXGBE_I2C_T_LOW);
1818 * ixgbe_i2c_stop - Sets I2C stop condition
1819 * @hw: pointer to hardware structure
1821 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1823 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1825 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1827 /* Stop condition must begin with data low and clock high */
1828 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1829 ixgbe_raise_i2c_clk(hw, &i2cctl);
1831 /* Setup time for stop condition (4us) */
1832 udelay(IXGBE_I2C_T_SU_STO);
1834 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1836 /* bus free time between stop and start (4.7us)*/
1837 udelay(IXGBE_I2C_T_BUF);
1841 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1842 * @hw: pointer to hardware structure
1843 * @data: data byte to clock in
1845 * Clocks in one byte data via I2C data/clock
1847 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1852 for (i = 7; i >= 0; i--) {
1853 ixgbe_clock_in_i2c_bit(hw, &bit);
1861 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1862 * @hw: pointer to hardware structure
1863 * @data: data byte clocked out
1865 * Clocks out one byte data via I2C data/clock
1867 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1874 for (i = 7; i >= 0; i--) {
1875 bit = (data >> i) & 0x1;
1876 status = ixgbe_clock_out_i2c_bit(hw, bit);
1882 /* Release SDA line (set high) */
1883 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1884 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
1885 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
1886 IXGBE_WRITE_FLUSH(hw);
1892 * ixgbe_get_i2c_ack - Polls for I2C ACK
1893 * @hw: pointer to hardware structure
1895 * Clocks in/out one bit via I2C data/clock
1897 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1901 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1905 ixgbe_raise_i2c_clk(hw, &i2cctl);
1908 /* Minimum high period of clock is 4us */
1909 udelay(IXGBE_I2C_T_HIGH);
1911 /* Poll for ACK. Note that ACK in I2C spec is
1912 * transition from 1 to 0 */
1913 for (i = 0; i < timeout; i++) {
1914 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1915 ack = ixgbe_get_i2c_data(hw, &i2cctl);
1923 hw_dbg(hw, "I2C ack was not received.\n");
1924 status = IXGBE_ERR_I2C;
1927 ixgbe_lower_i2c_clk(hw, &i2cctl);
1929 /* Minimum low period of clock is 4.7 us */
1930 udelay(IXGBE_I2C_T_LOW);
1936 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1937 * @hw: pointer to hardware structure
1938 * @data: read data value
1940 * Clocks in one bit via I2C data/clock
1942 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1944 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1946 ixgbe_raise_i2c_clk(hw, &i2cctl);
1948 /* Minimum high period of clock is 4us */
1949 udelay(IXGBE_I2C_T_HIGH);
1951 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1952 *data = ixgbe_get_i2c_data(hw, &i2cctl);
1954 ixgbe_lower_i2c_clk(hw, &i2cctl);
1956 /* Minimum low period of clock is 4.7 us */
1957 udelay(IXGBE_I2C_T_LOW);
1963 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1964 * @hw: pointer to hardware structure
1965 * @data: data value to write
1967 * Clocks out one bit via I2C data/clock
1969 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1972 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1974 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1976 ixgbe_raise_i2c_clk(hw, &i2cctl);
1978 /* Minimum high period of clock is 4us */
1979 udelay(IXGBE_I2C_T_HIGH);
1981 ixgbe_lower_i2c_clk(hw, &i2cctl);
1983 /* Minimum low period of clock is 4.7 us.
1984 * This also takes care of the data hold time.
1986 udelay(IXGBE_I2C_T_LOW);
1988 hw_dbg(hw, "I2C data was not set to %X\n", data);
1989 return IXGBE_ERR_I2C;
1995 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1996 * @hw: pointer to hardware structure
1997 * @i2cctl: Current value of I2CCTL register
1999 * Raises the I2C clock line '0'->'1'
2001 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2004 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2007 for (i = 0; i < timeout; i++) {
2008 *i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
2009 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2010 IXGBE_WRITE_FLUSH(hw);
2011 /* SCL rise time (1000ns) */
2012 udelay(IXGBE_I2C_T_RISE);
2014 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2015 if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
2021 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2022 * @hw: pointer to hardware structure
2023 * @i2cctl: Current value of I2CCTL register
2025 * Lowers the I2C clock line '1'->'0'
2027 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2030 *i2cctl &= ~IXGBE_I2C_CLK_OUT_BY_MAC(hw);
2032 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2033 IXGBE_WRITE_FLUSH(hw);
2035 /* SCL fall time (300ns) */
2036 udelay(IXGBE_I2C_T_FALL);
2040 * ixgbe_set_i2c_data - Sets the I2C data bit
2041 * @hw: pointer to hardware structure
2042 * @i2cctl: Current value of I2CCTL register
2043 * @data: I2C data value (0 or 1) to set
2045 * Sets the I2C data bit
2047 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2050 *i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2052 *i2cctl &= ~IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2054 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2055 IXGBE_WRITE_FLUSH(hw);
2057 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2058 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2060 /* Verify data was set correctly */
2061 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2062 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
2063 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
2064 return IXGBE_ERR_I2C;
2071 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2072 * @hw: pointer to hardware structure
2073 * @i2cctl: Current value of I2CCTL register
2075 * Returns the I2C data bit value
2077 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
2079 if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
2085 * ixgbe_i2c_bus_clear - Clears the I2C bus
2086 * @hw: pointer to hardware structure
2088 * Clears the I2C bus by sending nine clock pulses.
2089 * Used when data line is stuck low.
2091 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2093 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2096 ixgbe_i2c_start(hw);
2098 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2100 for (i = 0; i < 9; i++) {
2101 ixgbe_raise_i2c_clk(hw, &i2cctl);
2103 /* Min high period of clock is 4us */
2104 udelay(IXGBE_I2C_T_HIGH);
2106 ixgbe_lower_i2c_clk(hw, &i2cctl);
2108 /* Min low period of clock is 4.7us*/
2109 udelay(IXGBE_I2C_T_LOW);
2112 ixgbe_i2c_start(hw);
2114 /* Put the i2c bus back to default state */
2119 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
2120 * @hw: pointer to hardware structure
2122 * Checks if the LASI temp alarm status was triggered due to overtemp
2124 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2128 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2131 /* Check that the LASI temp alarm status was triggered */
2132 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2133 MDIO_MMD_PMAPMD, &phy_data);
2135 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2138 return IXGBE_ERR_OVERTEMP;