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_identify_phy_generic - Get physical layer module
54 * @hw: pointer to hardware structure
56 * Determines the physical layer module found on the current adapter.
58 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
63 if (!hw->phy.phy_semaphore_mask) {
64 hw->phy.lan_id = IXGBE_READ_REG(hw, IXGBE_STATUS) &
65 IXGBE_STATUS_LAN_ID_1;
67 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
69 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
72 if (hw->phy.type == ixgbe_phy_unknown) {
73 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
74 hw->phy.mdio.prtad = phy_addr;
75 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
78 ixgbe_get_phy_type_from_id(hw->phy.id);
80 if (hw->phy.type == ixgbe_phy_unknown) {
81 hw->phy.ops.read_reg(hw,
86 (MDIO_PMA_EXTABLE_10GBT |
87 MDIO_PMA_EXTABLE_1000BT))
98 /* clear value if nothing found */
99 hw->phy.mdio.prtad = 0;
100 return IXGBE_ERR_PHY_ADDR_INVALID;
106 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
107 * @hw: pointer to the hardware structure
109 * This function checks the MMNGC.MNG_VETO bit to see if there are
110 * any constraints on link from manageability. For MAC's that don't
111 * have this bit just return false since the link can not be blocked
114 bool ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
118 /* If we don't have this bit, it can't be blocking */
119 if (hw->mac.type == ixgbe_mac_82598EB)
122 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
123 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
124 hw_dbg(hw, "MNG_VETO bit detected.\n");
132 * ixgbe_get_phy_id - Get the phy type
133 * @hw: pointer to hardware structure
136 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
142 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
146 hw->phy.id = (u32)(phy_id_high << 16);
147 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
149 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
150 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
156 * ixgbe_get_phy_type_from_id - Get the phy type
157 * @hw: pointer to hardware structure
160 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
162 enum ixgbe_phy_type phy_type;
166 phy_type = ixgbe_phy_tn;
169 phy_type = ixgbe_phy_aq;
172 phy_type = ixgbe_phy_qt;
175 phy_type = ixgbe_phy_nl;
178 phy_type = ixgbe_phy_unknown;
186 * ixgbe_reset_phy_generic - Performs a PHY reset
187 * @hw: pointer to hardware structure
189 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
195 if (hw->phy.type == ixgbe_phy_unknown)
196 status = ixgbe_identify_phy_generic(hw);
198 if (status != 0 || hw->phy.type == ixgbe_phy_none)
201 /* Don't reset PHY if it's shut down due to overtemp. */
202 if (!hw->phy.reset_if_overtemp &&
203 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
206 /* Blocked by MNG FW so bail */
207 if (ixgbe_check_reset_blocked(hw))
211 * Perform soft PHY reset to the PHY_XS.
212 * This will cause a soft reset to the PHY
214 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
219 * Poll for reset bit to self-clear indicating reset is complete.
220 * Some PHYs could take up to 3 seconds to complete and need about
221 * 1.7 usec delay after the reset is complete.
223 for (i = 0; i < 30; i++) {
225 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
226 MDIO_MMD_PHYXS, &ctrl);
227 if (!(ctrl & MDIO_CTRL1_RESET)) {
233 if (ctrl & MDIO_CTRL1_RESET) {
234 hw_dbg(hw, "PHY reset polling failed to complete.\n");
235 return IXGBE_ERR_RESET_FAILED;
242 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
244 * @hw: pointer to hardware structure
245 * @reg_addr: 32 bit address of PHY register to read
246 * @phy_data: Pointer to read data from PHY register
248 s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
251 u32 i, data, command;
253 /* Setup and write the address cycle command */
254 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
255 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
256 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
257 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
259 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
261 /* Check every 10 usec to see if the address cycle completed.
262 * The MDI Command bit will clear when the operation is
265 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
268 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
269 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
274 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
275 hw_dbg(hw, "PHY address command did not complete.\n");
276 return IXGBE_ERR_PHY;
279 /* Address cycle complete, setup and write the read
282 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
283 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
284 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
285 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
287 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
289 /* Check every 10 usec to see if the address cycle
290 * completed. The MDI Command bit will clear when the
291 * operation is complete
293 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
296 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
297 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
301 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
302 hw_dbg(hw, "PHY read command didn't complete\n");
303 return IXGBE_ERR_PHY;
306 /* Read operation is complete. Get the data
309 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
310 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
311 *phy_data = (u16)(data);
317 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
318 * using the SWFW lock - this function is needed in most cases
319 * @hw: pointer to hardware structure
320 * @reg_addr: 32 bit address of PHY register to read
321 * @phy_data: Pointer to read data from PHY register
323 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
324 u32 device_type, u16 *phy_data)
327 u32 gssr = hw->phy.phy_semaphore_mask;
329 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
330 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
332 hw->mac.ops.release_swfw_sync(hw, gssr);
334 return IXGBE_ERR_SWFW_SYNC;
341 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
343 * @hw: pointer to hardware structure
344 * @reg_addr: 32 bit PHY register to write
345 * @device_type: 5 bit device type
346 * @phy_data: Data to write to the PHY register
348 s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
349 u32 device_type, u16 phy_data)
353 /* Put the data in the MDI single read and write data register*/
354 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
356 /* Setup and write the address cycle command */
357 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
358 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
359 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
360 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
362 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
365 * Check every 10 usec to see if the address cycle completed.
366 * The MDI Command bit will clear when the operation is
369 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
372 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
373 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
377 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
378 hw_dbg(hw, "PHY address cmd didn't complete\n");
379 return IXGBE_ERR_PHY;
383 * Address cycle complete, setup and write the write
386 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
387 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
388 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
389 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
391 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
393 /* Check every 10 usec to see if the address cycle
394 * completed. The MDI Command bit will clear when the
395 * operation is complete
397 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
400 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
401 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
405 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
406 hw_dbg(hw, "PHY write cmd didn't complete\n");
407 return IXGBE_ERR_PHY;
414 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
415 * using SWFW lock- this function is needed in most cases
416 * @hw: pointer to hardware structure
417 * @reg_addr: 32 bit PHY register to write
418 * @device_type: 5 bit device type
419 * @phy_data: Data to write to the PHY register
421 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
422 u32 device_type, u16 phy_data)
427 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
428 gssr = IXGBE_GSSR_PHY1_SM;
430 gssr = IXGBE_GSSR_PHY0_SM;
432 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == 0) {
433 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
435 hw->mac.ops.release_swfw_sync(hw, gssr);
437 return IXGBE_ERR_SWFW_SYNC;
444 * ixgbe_setup_phy_link_generic - Set and restart autoneg
445 * @hw: pointer to hardware structure
447 * Restart autonegotiation and PHY and waits for completion.
449 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
452 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
453 bool autoneg = false;
454 ixgbe_link_speed speed;
456 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
458 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
459 /* Set or unset auto-negotiation 10G advertisement */
460 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
464 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
465 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
466 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
468 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
473 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
474 /* Set or unset auto-negotiation 1G advertisement */
475 hw->phy.ops.read_reg(hw,
476 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
480 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
481 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
482 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
484 hw->phy.ops.write_reg(hw,
485 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
490 if (speed & IXGBE_LINK_SPEED_100_FULL) {
491 /* Set or unset auto-negotiation 100M advertisement */
492 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
496 autoneg_reg &= ~(ADVERTISE_100FULL |
498 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
499 autoneg_reg |= ADVERTISE_100FULL;
501 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
506 /* Blocked by MNG FW so don't reset PHY */
507 if (ixgbe_check_reset_blocked(hw))
510 /* Restart PHY autonegotiation and wait for completion */
511 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
512 MDIO_MMD_AN, &autoneg_reg);
514 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
516 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
517 MDIO_MMD_AN, autoneg_reg);
523 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
524 * @hw: pointer to hardware structure
525 * @speed: new link speed
527 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
528 ixgbe_link_speed speed,
529 bool autoneg_wait_to_complete)
533 * Clear autoneg_advertised and set new values based on input link
536 hw->phy.autoneg_advertised = 0;
538 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
539 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
541 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
542 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
544 if (speed & IXGBE_LINK_SPEED_100_FULL)
545 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
547 /* Setup link based on the new speed settings */
548 hw->phy.ops.setup_link(hw);
554 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
555 * @hw: pointer to hardware structure
556 * @speed: pointer to link speed
557 * @autoneg: boolean auto-negotiation value
559 * Determines the link capabilities by reading the AUTOC register.
561 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
562 ixgbe_link_speed *speed,
571 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
575 if (speed_ability & MDIO_SPEED_10G)
576 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
577 if (speed_ability & MDIO_PMA_SPEED_1000)
578 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
579 if (speed_ability & MDIO_PMA_SPEED_100)
580 *speed |= IXGBE_LINK_SPEED_100_FULL;
583 /* Internal PHY does not support 100 Mbps */
584 if (hw->mac.type == ixgbe_mac_X550EM_x)
585 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
591 * ixgbe_check_phy_link_tnx - Determine link and speed status
592 * @hw: pointer to hardware structure
594 * Reads the VS1 register to determine if link is up and the current speed for
597 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
602 u32 max_time_out = 10;
607 /* Initialize speed and link to default case */
609 *speed = IXGBE_LINK_SPEED_10GB_FULL;
612 * Check current speed and link status of the PHY register.
613 * This is a vendor specific register and may have to
614 * be changed for other copper PHYs.
616 for (time_out = 0; time_out < max_time_out; time_out++) {
618 status = hw->phy.ops.read_reg(hw,
622 phy_link = phy_data &
623 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
624 phy_speed = phy_data &
625 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
626 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
629 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
630 *speed = IXGBE_LINK_SPEED_1GB_FULL;
639 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
640 * @hw: pointer to hardware structure
642 * Restart autonegotiation and PHY and waits for completion.
643 * This function always returns success, this is nessary since
644 * it is called via a function pointer that could call other
645 * functions that could return an error.
647 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
649 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
650 bool autoneg = false;
651 ixgbe_link_speed speed;
653 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
655 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
656 /* Set or unset auto-negotiation 10G advertisement */
657 hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
661 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
662 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
663 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
665 hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL,
670 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
671 /* Set or unset auto-negotiation 1G advertisement */
672 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
676 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
677 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
678 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
680 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
685 if (speed & IXGBE_LINK_SPEED_100_FULL) {
686 /* Set or unset auto-negotiation 100M advertisement */
687 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
691 autoneg_reg &= ~(ADVERTISE_100FULL |
693 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
694 autoneg_reg |= ADVERTISE_100FULL;
696 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
701 /* Blocked by MNG FW so don't reset PHY */
702 if (ixgbe_check_reset_blocked(hw))
705 /* Restart PHY autonegotiation and wait for completion */
706 hw->phy.ops.read_reg(hw, MDIO_CTRL1,
707 MDIO_MMD_AN, &autoneg_reg);
709 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
711 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
712 MDIO_MMD_AN, autoneg_reg);
717 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
718 * @hw: pointer to hardware structure
719 * @firmware_version: pointer to the PHY Firmware Version
721 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
722 u16 *firmware_version)
726 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
734 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
735 * @hw: pointer to hardware structure
736 * @firmware_version: pointer to the PHY Firmware Version
738 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
739 u16 *firmware_version)
743 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
751 * ixgbe_reset_phy_nl - Performs a PHY reset
752 * @hw: pointer to hardware structure
754 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
756 u16 phy_offset, control, eword, edata, block_crc;
757 bool end_data = false;
758 u16 list_offset, data_offset;
763 /* Blocked by MNG FW so bail */
764 if (ixgbe_check_reset_blocked(hw))
767 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
769 /* reset the PHY and poll for completion */
770 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
771 (phy_data | MDIO_CTRL1_RESET));
773 for (i = 0; i < 100; i++) {
774 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
776 if ((phy_data & MDIO_CTRL1_RESET) == 0)
778 usleep_range(10000, 20000);
781 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
782 hw_dbg(hw, "PHY reset did not complete.\n");
783 return IXGBE_ERR_PHY;
786 /* Get init offsets */
787 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
792 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
796 * Read control word from PHY init contents offset
798 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
801 control = (eword & IXGBE_CONTROL_MASK_NL) >>
802 IXGBE_CONTROL_SHIFT_NL;
803 edata = eword & IXGBE_DATA_MASK_NL;
807 hw_dbg(hw, "DELAY: %d MS\n", edata);
808 usleep_range(edata * 1000, edata * 2000);
811 hw_dbg(hw, "DATA:\n");
813 ret_val = hw->eeprom.ops.read(hw, data_offset++,
817 for (i = 0; i < edata; i++) {
818 ret_val = hw->eeprom.ops.read(hw, data_offset,
822 hw->phy.ops.write_reg(hw, phy_offset,
823 MDIO_MMD_PMAPMD, eword);
824 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
830 case IXGBE_CONTROL_NL:
832 hw_dbg(hw, "CONTROL:\n");
833 if (edata == IXGBE_CONTROL_EOL_NL) {
836 } else if (edata == IXGBE_CONTROL_SOL_NL) {
839 hw_dbg(hw, "Bad control value\n");
840 return IXGBE_ERR_PHY;
844 hw_dbg(hw, "Bad control type\n");
845 return IXGBE_ERR_PHY;
852 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
853 return IXGBE_ERR_PHY;
857 * ixgbe_identify_module_generic - Identifies module type
858 * @hw: pointer to hardware structure
860 * Determines HW type and calls appropriate function.
862 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
864 switch (hw->mac.ops.get_media_type(hw)) {
865 case ixgbe_media_type_fiber:
866 return ixgbe_identify_sfp_module_generic(hw);
867 case ixgbe_media_type_fiber_qsfp:
868 return ixgbe_identify_qsfp_module_generic(hw);
870 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
871 return IXGBE_ERR_SFP_NOT_PRESENT;
874 return IXGBE_ERR_SFP_NOT_PRESENT;
878 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
879 * @hw: pointer to hardware structure
881 * Searches for and identifies the SFP module and assigns appropriate PHY type.
883 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
885 struct ixgbe_adapter *adapter = hw->back;
888 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
890 u8 comp_codes_1g = 0;
891 u8 comp_codes_10g = 0;
892 u8 oui_bytes[3] = {0, 0, 0};
897 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
898 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
899 return IXGBE_ERR_SFP_NOT_PRESENT;
902 status = hw->phy.ops.read_i2c_eeprom(hw,
903 IXGBE_SFF_IDENTIFIER,
907 goto err_read_i2c_eeprom;
909 /* LAN ID is needed for sfp_type determination */
910 hw->mac.ops.set_lan_id(hw);
912 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
913 hw->phy.type = ixgbe_phy_sfp_unsupported;
914 return IXGBE_ERR_SFP_NOT_SUPPORTED;
916 status = hw->phy.ops.read_i2c_eeprom(hw,
917 IXGBE_SFF_1GBE_COMP_CODES,
921 goto err_read_i2c_eeprom;
923 status = hw->phy.ops.read_i2c_eeprom(hw,
924 IXGBE_SFF_10GBE_COMP_CODES,
928 goto err_read_i2c_eeprom;
929 status = hw->phy.ops.read_i2c_eeprom(hw,
930 IXGBE_SFF_CABLE_TECHNOLOGY,
934 goto err_read_i2c_eeprom;
941 * 3 SFP_DA_CORE0 - 82599-specific
942 * 4 SFP_DA_CORE1 - 82599-specific
943 * 5 SFP_SR/LR_CORE0 - 82599-specific
944 * 6 SFP_SR/LR_CORE1 - 82599-specific
945 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
946 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
947 * 9 SFP_1g_cu_CORE0 - 82599-specific
948 * 10 SFP_1g_cu_CORE1 - 82599-specific
949 * 11 SFP_1g_sx_CORE0 - 82599-specific
950 * 12 SFP_1g_sx_CORE1 - 82599-specific
952 if (hw->mac.type == ixgbe_mac_82598EB) {
953 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
954 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
955 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
956 hw->phy.sfp_type = ixgbe_sfp_type_sr;
957 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
958 hw->phy.sfp_type = ixgbe_sfp_type_lr;
960 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
961 } else if (hw->mac.type == ixgbe_mac_82599EB) {
962 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
963 if (hw->bus.lan_id == 0)
965 ixgbe_sfp_type_da_cu_core0;
968 ixgbe_sfp_type_da_cu_core1;
969 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
970 hw->phy.ops.read_i2c_eeprom(
971 hw, IXGBE_SFF_CABLE_SPEC_COMP,
974 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
975 if (hw->bus.lan_id == 0)
977 ixgbe_sfp_type_da_act_lmt_core0;
980 ixgbe_sfp_type_da_act_lmt_core1;
983 ixgbe_sfp_type_unknown;
985 } else if (comp_codes_10g &
986 (IXGBE_SFF_10GBASESR_CAPABLE |
987 IXGBE_SFF_10GBASELR_CAPABLE)) {
988 if (hw->bus.lan_id == 0)
990 ixgbe_sfp_type_srlr_core0;
993 ixgbe_sfp_type_srlr_core1;
994 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
995 if (hw->bus.lan_id == 0)
997 ixgbe_sfp_type_1g_cu_core0;
1000 ixgbe_sfp_type_1g_cu_core1;
1001 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1002 if (hw->bus.lan_id == 0)
1004 ixgbe_sfp_type_1g_sx_core0;
1007 ixgbe_sfp_type_1g_sx_core1;
1008 } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
1009 if (hw->bus.lan_id == 0)
1011 ixgbe_sfp_type_1g_lx_core0;
1014 ixgbe_sfp_type_1g_lx_core1;
1016 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1020 if (hw->phy.sfp_type != stored_sfp_type)
1021 hw->phy.sfp_setup_needed = true;
1023 /* Determine if the SFP+ PHY is dual speed or not. */
1024 hw->phy.multispeed_fiber = false;
1025 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1026 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1027 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1028 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1029 hw->phy.multispeed_fiber = true;
1031 /* Determine PHY vendor */
1032 if (hw->phy.type != ixgbe_phy_nl) {
1033 hw->phy.id = identifier;
1034 status = hw->phy.ops.read_i2c_eeprom(hw,
1035 IXGBE_SFF_VENDOR_OUI_BYTE0,
1039 goto err_read_i2c_eeprom;
1041 status = hw->phy.ops.read_i2c_eeprom(hw,
1042 IXGBE_SFF_VENDOR_OUI_BYTE1,
1046 goto err_read_i2c_eeprom;
1048 status = hw->phy.ops.read_i2c_eeprom(hw,
1049 IXGBE_SFF_VENDOR_OUI_BYTE2,
1053 goto err_read_i2c_eeprom;
1056 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1057 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1058 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1060 switch (vendor_oui) {
1061 case IXGBE_SFF_VENDOR_OUI_TYCO:
1062 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1064 ixgbe_phy_sfp_passive_tyco;
1066 case IXGBE_SFF_VENDOR_OUI_FTL:
1067 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1068 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1070 hw->phy.type = ixgbe_phy_sfp_ftl;
1072 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1073 hw->phy.type = ixgbe_phy_sfp_avago;
1075 case IXGBE_SFF_VENDOR_OUI_INTEL:
1076 hw->phy.type = ixgbe_phy_sfp_intel;
1079 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1081 ixgbe_phy_sfp_passive_unknown;
1082 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1084 ixgbe_phy_sfp_active_unknown;
1086 hw->phy.type = ixgbe_phy_sfp_unknown;
1091 /* Allow any DA cable vendor */
1092 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1093 IXGBE_SFF_DA_ACTIVE_CABLE))
1096 /* Verify supported 1G SFP modules */
1097 if (comp_codes_10g == 0 &&
1098 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1099 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1100 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1101 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1102 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1103 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1104 hw->phy.type = ixgbe_phy_sfp_unsupported;
1105 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1108 /* Anything else 82598-based is supported */
1109 if (hw->mac.type == ixgbe_mac_82598EB)
1112 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1113 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1114 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1115 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1116 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1117 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1118 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1119 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1120 /* Make sure we're a supported PHY type */
1121 if (hw->phy.type == ixgbe_phy_sfp_intel)
1123 if (hw->allow_unsupported_sfp) {
1124 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");
1127 hw_dbg(hw, "SFP+ module not supported\n");
1128 hw->phy.type = ixgbe_phy_sfp_unsupported;
1129 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1133 err_read_i2c_eeprom:
1134 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1135 if (hw->phy.type != ixgbe_phy_nl) {
1137 hw->phy.type = ixgbe_phy_unknown;
1139 return IXGBE_ERR_SFP_NOT_PRESENT;
1143 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1144 * @hw: pointer to hardware structure
1146 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1148 static s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
1150 struct ixgbe_adapter *adapter = hw->back;
1153 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1155 u8 comp_codes_1g = 0;
1156 u8 comp_codes_10g = 0;
1157 u8 oui_bytes[3] = {0, 0, 0};
1158 u16 enforce_sfp = 0;
1160 u8 cable_length = 0;
1162 bool active_cable = false;
1164 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1165 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1166 return IXGBE_ERR_SFP_NOT_PRESENT;
1169 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1173 goto err_read_i2c_eeprom;
1175 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1176 hw->phy.type = ixgbe_phy_sfp_unsupported;
1177 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1180 hw->phy.id = identifier;
1182 /* LAN ID is needed for sfp_type determination */
1183 hw->mac.ops.set_lan_id(hw);
1185 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1189 goto err_read_i2c_eeprom;
1191 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1195 goto err_read_i2c_eeprom;
1197 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1198 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1199 if (hw->bus.lan_id == 0)
1200 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1202 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
1203 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1204 IXGBE_SFF_10GBASELR_CAPABLE)) {
1205 if (hw->bus.lan_id == 0)
1206 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1208 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1210 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1211 active_cable = true;
1213 if (!active_cable) {
1214 /* check for active DA cables that pre-date
1217 hw->phy.ops.read_i2c_eeprom(hw,
1218 IXGBE_SFF_QSFP_CONNECTOR,
1221 hw->phy.ops.read_i2c_eeprom(hw,
1222 IXGBE_SFF_QSFP_CABLE_LENGTH,
1225 hw->phy.ops.read_i2c_eeprom(hw,
1226 IXGBE_SFF_QSFP_DEVICE_TECH,
1230 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1231 (cable_length > 0) &&
1232 ((device_tech >> 4) ==
1233 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1234 active_cable = true;
1238 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1239 if (hw->bus.lan_id == 0)
1241 ixgbe_sfp_type_da_act_lmt_core0;
1244 ixgbe_sfp_type_da_act_lmt_core1;
1246 /* unsupported module type */
1247 hw->phy.type = ixgbe_phy_sfp_unsupported;
1248 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1252 if (hw->phy.sfp_type != stored_sfp_type)
1253 hw->phy.sfp_setup_needed = true;
1255 /* Determine if the QSFP+ PHY is dual speed or not. */
1256 hw->phy.multispeed_fiber = false;
1257 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1258 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1259 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1260 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1261 hw->phy.multispeed_fiber = true;
1263 /* Determine PHY vendor for optical modules */
1264 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1265 IXGBE_SFF_10GBASELR_CAPABLE)) {
1266 status = hw->phy.ops.read_i2c_eeprom(hw,
1267 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1271 goto err_read_i2c_eeprom;
1273 status = hw->phy.ops.read_i2c_eeprom(hw,
1274 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1278 goto err_read_i2c_eeprom;
1280 status = hw->phy.ops.read_i2c_eeprom(hw,
1281 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1285 goto err_read_i2c_eeprom;
1288 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1289 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1290 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1292 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1293 hw->phy.type = ixgbe_phy_qsfp_intel;
1295 hw->phy.type = ixgbe_phy_qsfp_unknown;
1297 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
1298 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1299 /* Make sure we're a supported PHY type */
1300 if (hw->phy.type == ixgbe_phy_qsfp_intel)
1302 if (hw->allow_unsupported_sfp) {
1303 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");
1306 hw_dbg(hw, "QSFP module not supported\n");
1307 hw->phy.type = ixgbe_phy_sfp_unsupported;
1308 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1314 err_read_i2c_eeprom:
1315 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1317 hw->phy.type = ixgbe_phy_unknown;
1319 return IXGBE_ERR_SFP_NOT_PRESENT;
1323 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1324 * @hw: pointer to hardware structure
1325 * @list_offset: offset to the SFP ID list
1326 * @data_offset: offset to the SFP data block
1328 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1329 * so it returns the offsets to the phy init sequence block.
1331 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1336 u16 sfp_type = hw->phy.sfp_type;
1338 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1339 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1341 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1342 return IXGBE_ERR_SFP_NOT_PRESENT;
1344 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1345 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1346 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1349 * Limiting active cables and 1G Phys must be initialized as
1352 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1353 sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1354 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1355 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1356 sfp_type = ixgbe_sfp_type_srlr_core0;
1357 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1358 sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
1359 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1360 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1361 sfp_type = ixgbe_sfp_type_srlr_core1;
1363 /* Read offset to PHY init contents */
1364 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1365 hw_err(hw, "eeprom read at %d failed\n",
1366 IXGBE_PHY_INIT_OFFSET_NL);
1367 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1370 if ((!*list_offset) || (*list_offset == 0xFFFF))
1371 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1373 /* Shift offset to first ID word */
1377 * Find the matching SFP ID in the EEPROM
1378 * and program the init sequence
1380 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1383 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1384 if (sfp_id == sfp_type) {
1386 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1388 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1389 hw_dbg(hw, "SFP+ module not supported\n");
1390 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1395 (*list_offset) += 2;
1396 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1401 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1402 hw_dbg(hw, "No matching SFP+ module found\n");
1403 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1409 hw_err(hw, "eeprom read at offset %d failed\n", *list_offset);
1410 return IXGBE_ERR_PHY;
1414 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1415 * @hw: pointer to hardware structure
1416 * @byte_offset: EEPROM byte offset to read
1417 * @eeprom_data: value read
1419 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1421 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1424 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1425 IXGBE_I2C_EEPROM_DEV_ADDR,
1430 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1431 * @hw: pointer to hardware structure
1432 * @byte_offset: byte offset at address 0xA2
1433 * @eeprom_data: value read
1435 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1437 s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1440 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1441 IXGBE_I2C_EEPROM_DEV_ADDR2,
1446 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1447 * @hw: pointer to hardware structure
1448 * @byte_offset: EEPROM byte offset to write
1449 * @eeprom_data: value to write
1451 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1453 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1456 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1457 IXGBE_I2C_EEPROM_DEV_ADDR,
1462 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1463 * @hw: pointer to hardware structure
1464 * @byte_offset: byte offset to read
1467 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1468 * a specified device address.
1470 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1471 u8 dev_addr, u8 *data)
1476 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1481 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1482 return IXGBE_ERR_SWFW_SYNC;
1484 ixgbe_i2c_start(hw);
1486 /* Device Address and write indication */
1487 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1491 status = ixgbe_get_i2c_ack(hw);
1495 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1499 status = ixgbe_get_i2c_ack(hw);
1503 ixgbe_i2c_start(hw);
1505 /* Device Address and read indication */
1506 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1510 status = ixgbe_get_i2c_ack(hw);
1514 status = ixgbe_clock_in_i2c_byte(hw, data);
1518 status = ixgbe_clock_out_i2c_bit(hw, nack);
1526 ixgbe_i2c_bus_clear(hw);
1527 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1530 if (retry < max_retry)
1531 hw_dbg(hw, "I2C byte read error - Retrying.\n");
1533 hw_dbg(hw, "I2C byte read error.\n");
1535 } while (retry < max_retry);
1537 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1543 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1544 * @hw: pointer to hardware structure
1545 * @byte_offset: byte offset to write
1546 * @data: value to write
1548 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1549 * a specified device address.
1551 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1552 u8 dev_addr, u8 data)
1557 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1559 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1560 return IXGBE_ERR_SWFW_SYNC;
1563 ixgbe_i2c_start(hw);
1565 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1569 status = ixgbe_get_i2c_ack(hw);
1573 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1577 status = ixgbe_get_i2c_ack(hw);
1581 status = ixgbe_clock_out_i2c_byte(hw, data);
1585 status = ixgbe_get_i2c_ack(hw);
1593 ixgbe_i2c_bus_clear(hw);
1595 if (retry < max_retry)
1596 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1598 hw_dbg(hw, "I2C byte write error.\n");
1599 } while (retry < max_retry);
1601 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
1607 * ixgbe_i2c_start - Sets I2C start condition
1608 * @hw: pointer to hardware structure
1610 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1612 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1614 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1616 /* Start condition must begin with data and clock high */
1617 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1618 ixgbe_raise_i2c_clk(hw, &i2cctl);
1620 /* Setup time for start condition (4.7us) */
1621 udelay(IXGBE_I2C_T_SU_STA);
1623 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1625 /* Hold time for start condition (4us) */
1626 udelay(IXGBE_I2C_T_HD_STA);
1628 ixgbe_lower_i2c_clk(hw, &i2cctl);
1630 /* Minimum low period of clock is 4.7 us */
1631 udelay(IXGBE_I2C_T_LOW);
1636 * ixgbe_i2c_stop - Sets I2C stop condition
1637 * @hw: pointer to hardware structure
1639 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1641 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1643 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1645 /* Stop condition must begin with data low and clock high */
1646 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1647 ixgbe_raise_i2c_clk(hw, &i2cctl);
1649 /* Setup time for stop condition (4us) */
1650 udelay(IXGBE_I2C_T_SU_STO);
1652 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1654 /* bus free time between stop and start (4.7us)*/
1655 udelay(IXGBE_I2C_T_BUF);
1659 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1660 * @hw: pointer to hardware structure
1661 * @data: data byte to clock in
1663 * Clocks in one byte data via I2C data/clock
1665 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1670 for (i = 7; i >= 0; i--) {
1671 ixgbe_clock_in_i2c_bit(hw, &bit);
1679 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1680 * @hw: pointer to hardware structure
1681 * @data: data byte clocked out
1683 * Clocks out one byte data via I2C data/clock
1685 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1692 for (i = 7; i >= 0; i--) {
1693 bit = (data >> i) & 0x1;
1694 status = ixgbe_clock_out_i2c_bit(hw, bit);
1700 /* Release SDA line (set high) */
1701 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1702 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
1703 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
1704 IXGBE_WRITE_FLUSH(hw);
1710 * ixgbe_get_i2c_ack - Polls for I2C ACK
1711 * @hw: pointer to hardware structure
1713 * Clocks in/out one bit via I2C data/clock
1715 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1719 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1723 ixgbe_raise_i2c_clk(hw, &i2cctl);
1726 /* Minimum high period of clock is 4us */
1727 udelay(IXGBE_I2C_T_HIGH);
1729 /* Poll for ACK. Note that ACK in I2C spec is
1730 * transition from 1 to 0 */
1731 for (i = 0; i < timeout; i++) {
1732 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1733 ack = ixgbe_get_i2c_data(hw, &i2cctl);
1741 hw_dbg(hw, "I2C ack was not received.\n");
1742 status = IXGBE_ERR_I2C;
1745 ixgbe_lower_i2c_clk(hw, &i2cctl);
1747 /* Minimum low period of clock is 4.7 us */
1748 udelay(IXGBE_I2C_T_LOW);
1754 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1755 * @hw: pointer to hardware structure
1756 * @data: read data value
1758 * Clocks in one bit via I2C data/clock
1760 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1762 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1764 ixgbe_raise_i2c_clk(hw, &i2cctl);
1766 /* Minimum high period of clock is 4us */
1767 udelay(IXGBE_I2C_T_HIGH);
1769 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1770 *data = ixgbe_get_i2c_data(hw, &i2cctl);
1772 ixgbe_lower_i2c_clk(hw, &i2cctl);
1774 /* Minimum low period of clock is 4.7 us */
1775 udelay(IXGBE_I2C_T_LOW);
1781 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1782 * @hw: pointer to hardware structure
1783 * @data: data value to write
1785 * Clocks out one bit via I2C data/clock
1787 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1790 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1792 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1794 ixgbe_raise_i2c_clk(hw, &i2cctl);
1796 /* Minimum high period of clock is 4us */
1797 udelay(IXGBE_I2C_T_HIGH);
1799 ixgbe_lower_i2c_clk(hw, &i2cctl);
1801 /* Minimum low period of clock is 4.7 us.
1802 * This also takes care of the data hold time.
1804 udelay(IXGBE_I2C_T_LOW);
1806 hw_dbg(hw, "I2C data was not set to %X\n", data);
1807 return IXGBE_ERR_I2C;
1813 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1814 * @hw: pointer to hardware structure
1815 * @i2cctl: Current value of I2CCTL register
1817 * Raises the I2C clock line '0'->'1'
1819 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1822 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
1825 for (i = 0; i < timeout; i++) {
1826 *i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
1827 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
1828 IXGBE_WRITE_FLUSH(hw);
1829 /* SCL rise time (1000ns) */
1830 udelay(IXGBE_I2C_T_RISE);
1832 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1833 if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
1839 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1840 * @hw: pointer to hardware structure
1841 * @i2cctl: Current value of I2CCTL register
1843 * Lowers the I2C clock line '1'->'0'
1845 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1848 *i2cctl &= ~IXGBE_I2C_CLK_OUT_BY_MAC(hw);
1850 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
1851 IXGBE_WRITE_FLUSH(hw);
1853 /* SCL fall time (300ns) */
1854 udelay(IXGBE_I2C_T_FALL);
1858 * ixgbe_set_i2c_data - Sets the I2C data bit
1859 * @hw: pointer to hardware structure
1860 * @i2cctl: Current value of I2CCTL register
1861 * @data: I2C data value (0 or 1) to set
1863 * Sets the I2C data bit
1865 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1868 *i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
1870 *i2cctl &= ~IXGBE_I2C_DATA_OUT_BY_MAC(hw);
1872 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
1873 IXGBE_WRITE_FLUSH(hw);
1875 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1876 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1878 /* Verify data was set correctly */
1879 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1880 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
1881 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1882 return IXGBE_ERR_I2C;
1889 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1890 * @hw: pointer to hardware structure
1891 * @i2cctl: Current value of I2CCTL register
1893 * Returns the I2C data bit value
1895 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
1897 if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
1903 * ixgbe_i2c_bus_clear - Clears the I2C bus
1904 * @hw: pointer to hardware structure
1906 * Clears the I2C bus by sending nine clock pulses.
1907 * Used when data line is stuck low.
1909 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1911 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
1914 ixgbe_i2c_start(hw);
1916 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1918 for (i = 0; i < 9; i++) {
1919 ixgbe_raise_i2c_clk(hw, &i2cctl);
1921 /* Min high period of clock is 4us */
1922 udelay(IXGBE_I2C_T_HIGH);
1924 ixgbe_lower_i2c_clk(hw, &i2cctl);
1926 /* Min low period of clock is 4.7us*/
1927 udelay(IXGBE_I2C_T_LOW);
1930 ixgbe_i2c_start(hw);
1932 /* Put the i2c bus back to default state */
1937 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
1938 * @hw: pointer to hardware structure
1940 * Checks if the LASI temp alarm status was triggered due to overtemp
1942 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1946 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
1949 /* Check that the LASI temp alarm status was triggered */
1950 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
1951 MDIO_MMD_PMAPMD, &phy_data);
1953 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
1956 return IXGBE_ERR_OVERTEMP;