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_int - 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
108 * @lock: true if to take and release semaphore
110 * Returns an error code on error.
112 s32
ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw
*hw
, u8 addr
,
113 u16 reg
, u16
*val
, bool lock
)
115 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
124 reg_high
= ((reg
>> 7) & 0xFE) | 1; /* Indicate read combined */
125 csum
= ixgbe_ones_comp_byte_add(reg_high
, reg
& 0xFF);
128 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
129 return IXGBE_ERR_SWFW_SYNC
;
131 /* Device Address and write indication */
132 if (ixgbe_out_i2c_byte_ack(hw
, addr
))
134 /* Write bits 14:8 */
135 if (ixgbe_out_i2c_byte_ack(hw
, reg_high
))
138 if (ixgbe_out_i2c_byte_ack(hw
, reg
& 0xFF))
141 if (ixgbe_out_i2c_byte_ack(hw
, csum
))
143 /* Re-start condition */
145 /* Device Address and read indication */
146 if (ixgbe_out_i2c_byte_ack(hw
, addr
| 1))
149 if (ixgbe_in_i2c_byte_ack(hw
, &high_bits
))
152 if (ixgbe_in_i2c_byte_ack(hw
, &low_bits
))
155 if (ixgbe_clock_in_i2c_byte(hw
, &csum_byte
))
158 if (ixgbe_clock_out_i2c_bit(hw
, false))
162 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
163 *val
= (high_bits
<< 8) | low_bits
;
167 ixgbe_i2c_bus_clear(hw
);
169 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
171 if (retry
< max_retry
)
172 hw_dbg(hw
, "I2C byte read combined error - Retry.\n");
174 hw_dbg(hw
, "I2C byte read combined error.\n");
175 } while (retry
< max_retry
);
177 return IXGBE_ERR_I2C
;
181 * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
182 * @hw: pointer to the hardware structure
183 * @addr: I2C bus address to write to
184 * @reg: I2C device register to write to
185 * @val: value to write
186 * @lock: true if to take and release semaphore
188 * Returns an error code on error.
190 s32
ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw
*hw
, u8 addr
,
191 u16 reg
, u16 val
, bool lock
)
193 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
199 reg_high
= (reg
>> 7) & 0xFE; /* Indicate write combined */
200 csum
= ixgbe_ones_comp_byte_add(reg_high
, reg
& 0xFF);
201 csum
= ixgbe_ones_comp_byte_add(csum
, val
>> 8);
202 csum
= ixgbe_ones_comp_byte_add(csum
, val
& 0xFF);
205 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
206 return IXGBE_ERR_SWFW_SYNC
;
208 /* Device Address and write indication */
209 if (ixgbe_out_i2c_byte_ack(hw
, addr
))
211 /* Write bits 14:8 */
212 if (ixgbe_out_i2c_byte_ack(hw
, reg_high
))
215 if (ixgbe_out_i2c_byte_ack(hw
, reg
& 0xFF))
217 /* Write data 15:8 */
218 if (ixgbe_out_i2c_byte_ack(hw
, val
>> 8))
221 if (ixgbe_out_i2c_byte_ack(hw
, val
& 0xFF))
224 if (ixgbe_out_i2c_byte_ack(hw
, csum
))
228 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
232 ixgbe_i2c_bus_clear(hw
);
234 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
236 if (retry
< max_retry
)
237 hw_dbg(hw
, "I2C byte write combined error - Retry.\n");
239 hw_dbg(hw
, "I2C byte write combined error.\n");
240 } while (retry
< max_retry
);
242 return IXGBE_ERR_I2C
;
246 * ixgbe_probe_phy - Probe a single address for a PHY
247 * @hw: pointer to hardware structure
248 * @phy_addr: PHY address to probe
250 * Returns true if PHY found
252 static bool ixgbe_probe_phy(struct ixgbe_hw
*hw
, u16 phy_addr
)
256 hw
->phy
.mdio
.prtad
= phy_addr
;
257 if (mdio45_probe(&hw
->phy
.mdio
, phy_addr
) != 0)
260 if (ixgbe_get_phy_id(hw
))
263 hw
->phy
.type
= ixgbe_get_phy_type_from_id(hw
->phy
.id
);
265 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
266 hw
->phy
.ops
.read_reg(hw
,
271 (MDIO_PMA_EXTABLE_10GBT
|
272 MDIO_PMA_EXTABLE_1000BT
))
273 hw
->phy
.type
= ixgbe_phy_cu_unknown
;
275 hw
->phy
.type
= ixgbe_phy_generic
;
282 * ixgbe_identify_phy_generic - Get physical layer module
283 * @hw: pointer to hardware structure
285 * Determines the physical layer module found on the current adapter.
287 s32
ixgbe_identify_phy_generic(struct ixgbe_hw
*hw
)
290 u32 status
= IXGBE_ERR_PHY_ADDR_INVALID
;
292 if (!hw
->phy
.phy_semaphore_mask
) {
294 hw
->phy
.phy_semaphore_mask
= IXGBE_GSSR_PHY1_SM
;
296 hw
->phy
.phy_semaphore_mask
= IXGBE_GSSR_PHY0_SM
;
299 if (hw
->phy
.type
!= ixgbe_phy_unknown
)
302 if (hw
->phy
.nw_mng_if_sel
) {
303 phy_addr
= (hw
->phy
.nw_mng_if_sel
&
304 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD
) >>
305 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT
;
306 if (ixgbe_probe_phy(hw
, phy_addr
))
309 return IXGBE_ERR_PHY_ADDR_INVALID
;
312 for (phy_addr
= 0; phy_addr
< IXGBE_MAX_PHY_ADDR
; phy_addr
++) {
313 if (ixgbe_probe_phy(hw
, phy_addr
)) {
319 /* Certain media types do not have a phy so an address will not
320 * be found and the code will take this path. Caller has to
321 * decide if it is an error or not.
324 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
330 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
331 * @hw: pointer to the hardware structure
333 * This function checks the MMNGC.MNG_VETO bit to see if there are
334 * any constraints on link from manageability. For MAC's that don't
335 * have this bit just return false since the link can not be blocked
338 bool ixgbe_check_reset_blocked(struct ixgbe_hw
*hw
)
342 /* If we don't have this bit, it can't be blocking */
343 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
346 mmngc
= IXGBE_READ_REG(hw
, IXGBE_MMNGC
);
347 if (mmngc
& IXGBE_MMNGC_MNG_VETO
) {
348 hw_dbg(hw
, "MNG_VETO bit detected.\n");
356 * ixgbe_get_phy_id - Get the phy type
357 * @hw: pointer to hardware structure
360 static s32
ixgbe_get_phy_id(struct ixgbe_hw
*hw
)
366 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_DEVID1
, MDIO_MMD_PMAPMD
,
370 hw
->phy
.id
= (u32
)(phy_id_high
<< 16);
371 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_DEVID2
, MDIO_MMD_PMAPMD
,
373 hw
->phy
.id
|= (u32
)(phy_id_low
& IXGBE_PHY_REVISION_MASK
);
374 hw
->phy
.revision
= (u32
)(phy_id_low
& ~IXGBE_PHY_REVISION_MASK
);
380 * ixgbe_get_phy_type_from_id - Get the phy type
381 * @hw: pointer to hardware structure
384 static enum ixgbe_phy_type
ixgbe_get_phy_type_from_id(u32 phy_id
)
386 enum ixgbe_phy_type phy_type
;
390 phy_type
= ixgbe_phy_tn
;
395 phy_type
= ixgbe_phy_aq
;
398 phy_type
= ixgbe_phy_qt
;
401 phy_type
= ixgbe_phy_nl
;
405 phy_type
= ixgbe_phy_x550em_ext_t
;
408 phy_type
= ixgbe_phy_unknown
;
416 * ixgbe_reset_phy_generic - Performs a PHY reset
417 * @hw: pointer to hardware structure
419 s32
ixgbe_reset_phy_generic(struct ixgbe_hw
*hw
)
425 if (hw
->phy
.type
== ixgbe_phy_unknown
)
426 status
= ixgbe_identify_phy_generic(hw
);
428 if (status
!= 0 || hw
->phy
.type
== ixgbe_phy_none
)
431 /* Don't reset PHY if it's shut down due to overtemp. */
432 if (!hw
->phy
.reset_if_overtemp
&&
433 (IXGBE_ERR_OVERTEMP
== hw
->phy
.ops
.check_overtemp(hw
)))
436 /* Blocked by MNG FW so bail */
437 if (ixgbe_check_reset_blocked(hw
))
441 * Perform soft PHY reset to the PHY_XS.
442 * This will cause a soft reset to the PHY
444 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
449 * Poll for reset bit to self-clear indicating reset is complete.
450 * Some PHYs could take up to 3 seconds to complete and need about
451 * 1.7 usec delay after the reset is complete.
453 for (i
= 0; i
< 30; i
++) {
455 if (hw
->phy
.type
== ixgbe_phy_x550em_ext_t
) {
456 status
= hw
->phy
.ops
.read_reg(hw
,
457 IXGBE_MDIO_TX_VENDOR_ALARMS_3
,
458 MDIO_MMD_PMAPMD
, &ctrl
);
462 if (ctrl
& IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK
) {
467 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
468 MDIO_MMD_PHYXS
, &ctrl
);
472 if (!(ctrl
& MDIO_CTRL1_RESET
)) {
479 if (ctrl
& MDIO_CTRL1_RESET
) {
480 hw_dbg(hw
, "PHY reset polling failed to complete.\n");
481 return IXGBE_ERR_RESET_FAILED
;
488 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
490 * @hw: pointer to hardware structure
491 * @reg_addr: 32 bit address of PHY register to read
492 * @phy_data: Pointer to read data from PHY register
494 s32
ixgbe_read_phy_reg_mdi(struct ixgbe_hw
*hw
, u32 reg_addr
, u32 device_type
,
497 u32 i
, data
, command
;
499 /* Setup and write the address cycle command */
500 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
501 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
502 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
503 (IXGBE_MSCA_ADDR_CYCLE
| IXGBE_MSCA_MDI_COMMAND
));
505 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
507 /* Check every 10 usec to see if the address cycle completed.
508 * The MDI Command bit will clear when the operation is
511 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
514 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
515 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
520 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
521 hw_dbg(hw
, "PHY address command did not complete.\n");
522 return IXGBE_ERR_PHY
;
525 /* Address cycle complete, setup and write the read
528 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
529 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
530 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
531 (IXGBE_MSCA_READ
| IXGBE_MSCA_MDI_COMMAND
));
533 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
535 /* Check every 10 usec to see if the address cycle
536 * completed. The MDI Command bit will clear when the
537 * operation is complete
539 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
542 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
543 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
547 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
548 hw_dbg(hw
, "PHY read command didn't complete\n");
549 return IXGBE_ERR_PHY
;
552 /* Read operation is complete. Get the data
555 data
= IXGBE_READ_REG(hw
, IXGBE_MSRWD
);
556 data
>>= IXGBE_MSRWD_READ_DATA_SHIFT
;
557 *phy_data
= (u16
)(data
);
563 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
564 * using the SWFW lock - this function is needed in most cases
565 * @hw: pointer to hardware structure
566 * @reg_addr: 32 bit address of PHY register to read
567 * @phy_data: Pointer to read data from PHY register
569 s32
ixgbe_read_phy_reg_generic(struct ixgbe_hw
*hw
, u32 reg_addr
,
570 u32 device_type
, u16
*phy_data
)
573 u32 gssr
= hw
->phy
.phy_semaphore_mask
;
575 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, gssr
) == 0) {
576 status
= ixgbe_read_phy_reg_mdi(hw
, reg_addr
, device_type
,
578 hw
->mac
.ops
.release_swfw_sync(hw
, gssr
);
580 return IXGBE_ERR_SWFW_SYNC
;
587 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
589 * @hw: pointer to hardware structure
590 * @reg_addr: 32 bit PHY register to write
591 * @device_type: 5 bit device type
592 * @phy_data: Data to write to the PHY register
594 s32
ixgbe_write_phy_reg_mdi(struct ixgbe_hw
*hw
, u32 reg_addr
,
595 u32 device_type
, u16 phy_data
)
599 /* Put the data in the MDI single read and write data register*/
600 IXGBE_WRITE_REG(hw
, IXGBE_MSRWD
, (u32
)phy_data
);
602 /* Setup and write the address cycle command */
603 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
604 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
605 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
606 (IXGBE_MSCA_ADDR_CYCLE
| IXGBE_MSCA_MDI_COMMAND
));
608 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
611 * Check every 10 usec to see if the address cycle completed.
612 * The MDI Command bit will clear when the operation is
615 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
618 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
619 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
623 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
624 hw_dbg(hw
, "PHY address cmd didn't complete\n");
625 return IXGBE_ERR_PHY
;
629 * Address cycle complete, setup and write the write
632 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
633 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
634 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
635 (IXGBE_MSCA_WRITE
| IXGBE_MSCA_MDI_COMMAND
));
637 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
639 /* Check every 10 usec to see if the address cycle
640 * completed. The MDI Command bit will clear when the
641 * operation is complete
643 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
646 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
647 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
651 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
652 hw_dbg(hw
, "PHY write cmd didn't complete\n");
653 return IXGBE_ERR_PHY
;
660 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
661 * using SWFW lock- this function is needed in most cases
662 * @hw: pointer to hardware structure
663 * @reg_addr: 32 bit PHY register to write
664 * @device_type: 5 bit device type
665 * @phy_data: Data to write to the PHY register
667 s32
ixgbe_write_phy_reg_generic(struct ixgbe_hw
*hw
, u32 reg_addr
,
668 u32 device_type
, u16 phy_data
)
671 u32 gssr
= hw
->phy
.phy_semaphore_mask
;
673 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, gssr
) == 0) {
674 status
= ixgbe_write_phy_reg_mdi(hw
, reg_addr
, device_type
,
676 hw
->mac
.ops
.release_swfw_sync(hw
, gssr
);
678 return IXGBE_ERR_SWFW_SYNC
;
685 * ixgbe_setup_phy_link_generic - Set and restart autoneg
686 * @hw: pointer to hardware structure
688 * Restart autonegotiation and PHY and waits for completion.
690 s32
ixgbe_setup_phy_link_generic(struct ixgbe_hw
*hw
)
693 u16 autoneg_reg
= IXGBE_MII_AUTONEG_REG
;
694 bool autoneg
= false;
695 ixgbe_link_speed speed
;
697 ixgbe_get_copper_link_capabilities_generic(hw
, &speed
, &autoneg
);
699 /* Set or unset auto-negotiation 10G advertisement */
700 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_10GBT_CTRL
, MDIO_MMD_AN
, &autoneg_reg
);
702 autoneg_reg
&= ~MDIO_AN_10GBT_CTRL_ADV10G
;
703 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_10GB_FULL
) &&
704 (speed
& IXGBE_LINK_SPEED_10GB_FULL
))
705 autoneg_reg
|= MDIO_AN_10GBT_CTRL_ADV10G
;
707 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_10GBT_CTRL
, MDIO_MMD_AN
, autoneg_reg
);
709 hw
->phy
.ops
.read_reg(hw
, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG
,
710 MDIO_MMD_AN
, &autoneg_reg
);
712 if (hw
->mac
.type
== ixgbe_mac_X550
) {
713 /* Set or unset auto-negotiation 5G advertisement */
714 autoneg_reg
&= ~IXGBE_MII_5GBASE_T_ADVERTISE
;
715 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_5GB_FULL
) &&
716 (speed
& IXGBE_LINK_SPEED_5GB_FULL
))
717 autoneg_reg
|= IXGBE_MII_5GBASE_T_ADVERTISE
;
719 /* Set or unset auto-negotiation 2.5G advertisement */
720 autoneg_reg
&= ~IXGBE_MII_2_5GBASE_T_ADVERTISE
;
721 if ((hw
->phy
.autoneg_advertised
&
722 IXGBE_LINK_SPEED_2_5GB_FULL
) &&
723 (speed
& IXGBE_LINK_SPEED_2_5GB_FULL
))
724 autoneg_reg
|= IXGBE_MII_2_5GBASE_T_ADVERTISE
;
727 /* Set or unset auto-negotiation 1G advertisement */
728 autoneg_reg
&= ~IXGBE_MII_1GBASE_T_ADVERTISE
;
729 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_1GB_FULL
) &&
730 (speed
& IXGBE_LINK_SPEED_1GB_FULL
))
731 autoneg_reg
|= IXGBE_MII_1GBASE_T_ADVERTISE
;
733 hw
->phy
.ops
.write_reg(hw
, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG
,
734 MDIO_MMD_AN
, autoneg_reg
);
736 /* Set or unset auto-negotiation 100M advertisement */
737 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_ADVERTISE
, MDIO_MMD_AN
, &autoneg_reg
);
739 autoneg_reg
&= ~(ADVERTISE_100FULL
| ADVERTISE_100HALF
);
740 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_100_FULL
) &&
741 (speed
& IXGBE_LINK_SPEED_100_FULL
))
742 autoneg_reg
|= ADVERTISE_100FULL
;
744 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_ADVERTISE
, MDIO_MMD_AN
, autoneg_reg
);
746 /* Blocked by MNG FW so don't reset PHY */
747 if (ixgbe_check_reset_blocked(hw
))
750 /* Restart PHY autonegotiation and wait for completion */
751 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
752 MDIO_MMD_AN
, &autoneg_reg
);
754 autoneg_reg
|= MDIO_AN_CTRL1_RESTART
;
756 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
757 MDIO_MMD_AN
, autoneg_reg
);
763 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
764 * @hw: pointer to hardware structure
765 * @speed: new link speed
767 s32
ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw
*hw
,
768 ixgbe_link_speed speed
,
769 bool autoneg_wait_to_complete
)
771 /* Clear autoneg_advertised and set new values based on input link
774 hw
->phy
.autoneg_advertised
= 0;
776 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
777 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10GB_FULL
;
779 if (speed
& IXGBE_LINK_SPEED_5GB_FULL
)
780 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_5GB_FULL
;
782 if (speed
& IXGBE_LINK_SPEED_2_5GB_FULL
)
783 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_2_5GB_FULL
;
785 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
)
786 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_1GB_FULL
;
788 if (speed
& IXGBE_LINK_SPEED_100_FULL
)
789 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_100_FULL
;
791 if (speed
& IXGBE_LINK_SPEED_10_FULL
)
792 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10_FULL
;
794 /* Setup link based on the new speed settings */
795 hw
->phy
.ops
.setup_link(hw
);
801 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
802 * @hw: pointer to hardware structure
804 * Determines the supported link capabilities by reading the PHY auto
805 * negotiation register.
807 static s32
ixgbe_get_copper_speeds_supported(struct ixgbe_hw
*hw
)
812 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_SPEED
, MDIO_MMD_PMAPMD
,
817 if (speed_ability
& MDIO_SPEED_10G
)
818 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_10GB_FULL
;
819 if (speed_ability
& MDIO_PMA_SPEED_1000
)
820 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_1GB_FULL
;
821 if (speed_ability
& MDIO_PMA_SPEED_100
)
822 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_100_FULL
;
824 switch (hw
->mac
.type
) {
826 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_2_5GB_FULL
;
827 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_5GB_FULL
;
829 case ixgbe_mac_X550EM_x
:
830 case ixgbe_mac_x550em_a
:
831 hw
->phy
.speeds_supported
&= ~IXGBE_LINK_SPEED_100_FULL
;
841 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
842 * @hw: pointer to hardware structure
843 * @speed: pointer to link speed
844 * @autoneg: boolean auto-negotiation value
846 s32
ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw
*hw
,
847 ixgbe_link_speed
*speed
,
853 if (!hw
->phy
.speeds_supported
)
854 status
= ixgbe_get_copper_speeds_supported(hw
);
856 *speed
= hw
->phy
.speeds_supported
;
861 * ixgbe_check_phy_link_tnx - Determine link and speed status
862 * @hw: pointer to hardware structure
864 * Reads the VS1 register to determine if link is up and the current speed for
867 s32
ixgbe_check_phy_link_tnx(struct ixgbe_hw
*hw
, ixgbe_link_speed
*speed
,
872 u32 max_time_out
= 10;
877 /* Initialize speed and link to default case */
879 *speed
= IXGBE_LINK_SPEED_10GB_FULL
;
882 * Check current speed and link status of the PHY register.
883 * This is a vendor specific register and may have to
884 * be changed for other copper PHYs.
886 for (time_out
= 0; time_out
< max_time_out
; time_out
++) {
888 status
= hw
->phy
.ops
.read_reg(hw
,
892 phy_link
= phy_data
&
893 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS
;
894 phy_speed
= phy_data
&
895 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS
;
896 if (phy_link
== IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS
) {
899 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS
)
900 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
909 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
910 * @hw: pointer to hardware structure
912 * Restart autonegotiation and PHY and waits for completion.
913 * This function always returns success, this is nessary since
914 * it is called via a function pointer that could call other
915 * functions that could return an error.
917 s32
ixgbe_setup_phy_link_tnx(struct ixgbe_hw
*hw
)
919 u16 autoneg_reg
= IXGBE_MII_AUTONEG_REG
;
920 bool autoneg
= false;
921 ixgbe_link_speed speed
;
923 ixgbe_get_copper_link_capabilities_generic(hw
, &speed
, &autoneg
);
925 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
) {
926 /* Set or unset auto-negotiation 10G advertisement */
927 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_10GBT_CTRL
,
931 autoneg_reg
&= ~MDIO_AN_10GBT_CTRL_ADV10G
;
932 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_10GB_FULL
)
933 autoneg_reg
|= MDIO_AN_10GBT_CTRL_ADV10G
;
935 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_10GBT_CTRL
,
940 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
) {
941 /* Set or unset auto-negotiation 1G advertisement */
942 hw
->phy
.ops
.read_reg(hw
, IXGBE_MII_AUTONEG_XNP_TX_REG
,
946 autoneg_reg
&= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX
;
947 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_1GB_FULL
)
948 autoneg_reg
|= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX
;
950 hw
->phy
.ops
.write_reg(hw
, IXGBE_MII_AUTONEG_XNP_TX_REG
,
955 if (speed
& IXGBE_LINK_SPEED_100_FULL
) {
956 /* Set or unset auto-negotiation 100M advertisement */
957 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_ADVERTISE
,
961 autoneg_reg
&= ~(ADVERTISE_100FULL
|
963 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_100_FULL
)
964 autoneg_reg
|= ADVERTISE_100FULL
;
966 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_ADVERTISE
,
971 /* Blocked by MNG FW so don't reset PHY */
972 if (ixgbe_check_reset_blocked(hw
))
975 /* Restart PHY autonegotiation and wait for completion */
976 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
977 MDIO_MMD_AN
, &autoneg_reg
);
979 autoneg_reg
|= MDIO_AN_CTRL1_RESTART
;
981 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
982 MDIO_MMD_AN
, autoneg_reg
);
987 * ixgbe_reset_phy_nl - Performs a PHY reset
988 * @hw: pointer to hardware structure
990 s32
ixgbe_reset_phy_nl(struct ixgbe_hw
*hw
)
992 u16 phy_offset
, control
, eword
, edata
, block_crc
;
993 bool end_data
= false;
994 u16 list_offset
, data_offset
;
999 /* Blocked by MNG FW so bail */
1000 if (ixgbe_check_reset_blocked(hw
))
1003 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
, &phy_data
);
1005 /* reset the PHY and poll for completion */
1006 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
,
1007 (phy_data
| MDIO_CTRL1_RESET
));
1009 for (i
= 0; i
< 100; i
++) {
1010 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
,
1012 if ((phy_data
& MDIO_CTRL1_RESET
) == 0)
1014 usleep_range(10000, 20000);
1017 if ((phy_data
& MDIO_CTRL1_RESET
) != 0) {
1018 hw_dbg(hw
, "PHY reset did not complete.\n");
1019 return IXGBE_ERR_PHY
;
1022 /* Get init offsets */
1023 ret_val
= ixgbe_get_sfp_init_sequence_offsets(hw
, &list_offset
,
1028 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
, &block_crc
);
1032 * Read control word from PHY init contents offset
1034 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
, &eword
);
1037 control
= (eword
& IXGBE_CONTROL_MASK_NL
) >>
1038 IXGBE_CONTROL_SHIFT_NL
;
1039 edata
= eword
& IXGBE_DATA_MASK_NL
;
1041 case IXGBE_DELAY_NL
:
1043 hw_dbg(hw
, "DELAY: %d MS\n", edata
);
1044 usleep_range(edata
* 1000, edata
* 2000);
1047 hw_dbg(hw
, "DATA:\n");
1049 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
++,
1053 for (i
= 0; i
< edata
; i
++) {
1054 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
,
1058 hw
->phy
.ops
.write_reg(hw
, phy_offset
,
1059 MDIO_MMD_PMAPMD
, eword
);
1060 hw_dbg(hw
, "Wrote %4.4x to %4.4x\n", eword
,
1066 case IXGBE_CONTROL_NL
:
1068 hw_dbg(hw
, "CONTROL:\n");
1069 if (edata
== IXGBE_CONTROL_EOL_NL
) {
1070 hw_dbg(hw
, "EOL\n");
1072 } else if (edata
== IXGBE_CONTROL_SOL_NL
) {
1073 hw_dbg(hw
, "SOL\n");
1075 hw_dbg(hw
, "Bad control value\n");
1076 return IXGBE_ERR_PHY
;
1080 hw_dbg(hw
, "Bad control type\n");
1081 return IXGBE_ERR_PHY
;
1088 hw_err(hw
, "eeprom read at offset %d failed\n", data_offset
);
1089 return IXGBE_ERR_PHY
;
1093 * ixgbe_identify_module_generic - Identifies module type
1094 * @hw: pointer to hardware structure
1096 * Determines HW type and calls appropriate function.
1098 s32
ixgbe_identify_module_generic(struct ixgbe_hw
*hw
)
1100 switch (hw
->mac
.ops
.get_media_type(hw
)) {
1101 case ixgbe_media_type_fiber
:
1102 return ixgbe_identify_sfp_module_generic(hw
);
1103 case ixgbe_media_type_fiber_qsfp
:
1104 return ixgbe_identify_qsfp_module_generic(hw
);
1106 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1107 return IXGBE_ERR_SFP_NOT_PRESENT
;
1110 return IXGBE_ERR_SFP_NOT_PRESENT
;
1114 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1115 * @hw: pointer to hardware structure
1117 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1119 s32
ixgbe_identify_sfp_module_generic(struct ixgbe_hw
*hw
)
1121 struct ixgbe_adapter
*adapter
= hw
->back
;
1124 enum ixgbe_sfp_type stored_sfp_type
= hw
->phy
.sfp_type
;
1126 u8 comp_codes_1g
= 0;
1127 u8 comp_codes_10g
= 0;
1128 u8 oui_bytes
[3] = {0, 0, 0};
1131 u16 enforce_sfp
= 0;
1133 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_fiber
) {
1134 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1135 return IXGBE_ERR_SFP_NOT_PRESENT
;
1138 /* LAN ID is needed for sfp_type determination */
1139 hw
->mac
.ops
.set_lan_id(hw
);
1141 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1142 IXGBE_SFF_IDENTIFIER
,
1146 goto err_read_i2c_eeprom
;
1148 if (identifier
!= IXGBE_SFF_IDENTIFIER_SFP
) {
1149 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1150 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1152 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1153 IXGBE_SFF_1GBE_COMP_CODES
,
1157 goto err_read_i2c_eeprom
;
1159 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1160 IXGBE_SFF_10GBE_COMP_CODES
,
1164 goto err_read_i2c_eeprom
;
1165 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1166 IXGBE_SFF_CABLE_TECHNOLOGY
,
1170 goto err_read_i2c_eeprom
;
1177 * 3 SFP_DA_CORE0 - 82599-specific
1178 * 4 SFP_DA_CORE1 - 82599-specific
1179 * 5 SFP_SR/LR_CORE0 - 82599-specific
1180 * 6 SFP_SR/LR_CORE1 - 82599-specific
1181 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1182 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1183 * 9 SFP_1g_cu_CORE0 - 82599-specific
1184 * 10 SFP_1g_cu_CORE1 - 82599-specific
1185 * 11 SFP_1g_sx_CORE0 - 82599-specific
1186 * 12 SFP_1g_sx_CORE1 - 82599-specific
1188 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
1189 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1190 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu
;
1191 else if (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)
1192 hw
->phy
.sfp_type
= ixgbe_sfp_type_sr
;
1193 else if (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)
1194 hw
->phy
.sfp_type
= ixgbe_sfp_type_lr
;
1196 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
1198 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
) {
1199 if (hw
->bus
.lan_id
== 0)
1201 ixgbe_sfp_type_da_cu_core0
;
1204 ixgbe_sfp_type_da_cu_core1
;
1205 } else if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
) {
1206 hw
->phy
.ops
.read_i2c_eeprom(
1207 hw
, IXGBE_SFF_CABLE_SPEC_COMP
,
1210 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING
) {
1211 if (hw
->bus
.lan_id
== 0)
1213 ixgbe_sfp_type_da_act_lmt_core0
;
1216 ixgbe_sfp_type_da_act_lmt_core1
;
1219 ixgbe_sfp_type_unknown
;
1221 } else if (comp_codes_10g
&
1222 (IXGBE_SFF_10GBASESR_CAPABLE
|
1223 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1224 if (hw
->bus
.lan_id
== 0)
1226 ixgbe_sfp_type_srlr_core0
;
1229 ixgbe_sfp_type_srlr_core1
;
1230 } else if (comp_codes_1g
& IXGBE_SFF_1GBASET_CAPABLE
) {
1231 if (hw
->bus
.lan_id
== 0)
1233 ixgbe_sfp_type_1g_cu_core0
;
1236 ixgbe_sfp_type_1g_cu_core1
;
1237 } else if (comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) {
1238 if (hw
->bus
.lan_id
== 0)
1240 ixgbe_sfp_type_1g_sx_core0
;
1243 ixgbe_sfp_type_1g_sx_core1
;
1244 } else if (comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) {
1245 if (hw
->bus
.lan_id
== 0)
1247 ixgbe_sfp_type_1g_lx_core0
;
1250 ixgbe_sfp_type_1g_lx_core1
;
1252 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
1256 if (hw
->phy
.sfp_type
!= stored_sfp_type
)
1257 hw
->phy
.sfp_setup_needed
= true;
1259 /* Determine if the SFP+ PHY is dual speed or not. */
1260 hw
->phy
.multispeed_fiber
= false;
1261 if (((comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) &&
1262 (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)) ||
1263 ((comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) &&
1264 (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)))
1265 hw
->phy
.multispeed_fiber
= true;
1267 /* Determine PHY vendor */
1268 if (hw
->phy
.type
!= ixgbe_phy_nl
) {
1269 hw
->phy
.id
= identifier
;
1270 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1271 IXGBE_SFF_VENDOR_OUI_BYTE0
,
1275 goto err_read_i2c_eeprom
;
1277 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1278 IXGBE_SFF_VENDOR_OUI_BYTE1
,
1282 goto err_read_i2c_eeprom
;
1284 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1285 IXGBE_SFF_VENDOR_OUI_BYTE2
,
1289 goto err_read_i2c_eeprom
;
1292 ((oui_bytes
[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT
) |
1293 (oui_bytes
[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT
) |
1294 (oui_bytes
[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT
));
1296 switch (vendor_oui
) {
1297 case IXGBE_SFF_VENDOR_OUI_TYCO
:
1298 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1300 ixgbe_phy_sfp_passive_tyco
;
1302 case IXGBE_SFF_VENDOR_OUI_FTL
:
1303 if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
)
1304 hw
->phy
.type
= ixgbe_phy_sfp_ftl_active
;
1306 hw
->phy
.type
= ixgbe_phy_sfp_ftl
;
1308 case IXGBE_SFF_VENDOR_OUI_AVAGO
:
1309 hw
->phy
.type
= ixgbe_phy_sfp_avago
;
1311 case IXGBE_SFF_VENDOR_OUI_INTEL
:
1312 hw
->phy
.type
= ixgbe_phy_sfp_intel
;
1315 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1317 ixgbe_phy_sfp_passive_unknown
;
1318 else if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
)
1320 ixgbe_phy_sfp_active_unknown
;
1322 hw
->phy
.type
= ixgbe_phy_sfp_unknown
;
1327 /* Allow any DA cable vendor */
1328 if (cable_tech
& (IXGBE_SFF_DA_PASSIVE_CABLE
|
1329 IXGBE_SFF_DA_ACTIVE_CABLE
))
1332 /* Verify supported 1G SFP modules */
1333 if (comp_codes_10g
== 0 &&
1334 !(hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1335 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1336 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1337 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1338 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core0
||
1339 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core1
)) {
1340 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1341 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1344 /* Anything else 82598-based is supported */
1345 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
1348 hw
->mac
.ops
.get_device_caps(hw
, &enforce_sfp
);
1349 if (!(enforce_sfp
& IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP
) &&
1350 !(hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1351 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1352 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1353 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1354 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core0
||
1355 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core1
)) {
1356 /* Make sure we're a supported PHY type */
1357 if (hw
->phy
.type
== ixgbe_phy_sfp_intel
)
1359 if (hw
->allow_unsupported_sfp
) {
1360 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");
1363 hw_dbg(hw
, "SFP+ module not supported\n");
1364 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1365 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1369 err_read_i2c_eeprom
:
1370 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1371 if (hw
->phy
.type
!= ixgbe_phy_nl
) {
1373 hw
->phy
.type
= ixgbe_phy_unknown
;
1375 return IXGBE_ERR_SFP_NOT_PRESENT
;
1379 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1380 * @hw: pointer to hardware structure
1382 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1384 static s32
ixgbe_identify_qsfp_module_generic(struct ixgbe_hw
*hw
)
1386 struct ixgbe_adapter
*adapter
= hw
->back
;
1389 enum ixgbe_sfp_type stored_sfp_type
= hw
->phy
.sfp_type
;
1391 u8 comp_codes_1g
= 0;
1392 u8 comp_codes_10g
= 0;
1393 u8 oui_bytes
[3] = {0, 0, 0};
1394 u16 enforce_sfp
= 0;
1396 u8 cable_length
= 0;
1398 bool active_cable
= false;
1400 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_fiber_qsfp
) {
1401 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1402 return IXGBE_ERR_SFP_NOT_PRESENT
;
1405 /* LAN ID is needed for sfp_type determination */
1406 hw
->mac
.ops
.set_lan_id(hw
);
1408 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_IDENTIFIER
,
1412 goto err_read_i2c_eeprom
;
1414 if (identifier
!= IXGBE_SFF_IDENTIFIER_QSFP_PLUS
) {
1415 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1416 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1419 hw
->phy
.id
= identifier
;
1421 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_QSFP_10GBE_COMP
,
1425 goto err_read_i2c_eeprom
;
1427 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_QSFP_1GBE_COMP
,
1431 goto err_read_i2c_eeprom
;
1433 if (comp_codes_10g
& IXGBE_SFF_QSFP_DA_PASSIVE_CABLE
) {
1434 hw
->phy
.type
= ixgbe_phy_qsfp_passive_unknown
;
1435 if (hw
->bus
.lan_id
== 0)
1436 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu_core0
;
1438 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu_core1
;
1439 } else if (comp_codes_10g
& (IXGBE_SFF_10GBASESR_CAPABLE
|
1440 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1441 if (hw
->bus
.lan_id
== 0)
1442 hw
->phy
.sfp_type
= ixgbe_sfp_type_srlr_core0
;
1444 hw
->phy
.sfp_type
= ixgbe_sfp_type_srlr_core1
;
1446 if (comp_codes_10g
& IXGBE_SFF_QSFP_DA_ACTIVE_CABLE
)
1447 active_cable
= true;
1449 if (!active_cable
) {
1450 /* check for active DA cables that pre-date
1453 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1454 IXGBE_SFF_QSFP_CONNECTOR
,
1457 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1458 IXGBE_SFF_QSFP_CABLE_LENGTH
,
1461 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1462 IXGBE_SFF_QSFP_DEVICE_TECH
,
1466 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE
) &&
1467 (cable_length
> 0) &&
1468 ((device_tech
>> 4) ==
1469 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL
))
1470 active_cable
= true;
1474 hw
->phy
.type
= ixgbe_phy_qsfp_active_unknown
;
1475 if (hw
->bus
.lan_id
== 0)
1477 ixgbe_sfp_type_da_act_lmt_core0
;
1480 ixgbe_sfp_type_da_act_lmt_core1
;
1482 /* unsupported module type */
1483 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1484 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1488 if (hw
->phy
.sfp_type
!= stored_sfp_type
)
1489 hw
->phy
.sfp_setup_needed
= true;
1491 /* Determine if the QSFP+ PHY is dual speed or not. */
1492 hw
->phy
.multispeed_fiber
= false;
1493 if (((comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) &&
1494 (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)) ||
1495 ((comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) &&
1496 (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)))
1497 hw
->phy
.multispeed_fiber
= true;
1499 /* Determine PHY vendor for optical modules */
1500 if (comp_codes_10g
& (IXGBE_SFF_10GBASESR_CAPABLE
|
1501 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1502 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1503 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0
,
1507 goto err_read_i2c_eeprom
;
1509 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1510 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1
,
1514 goto err_read_i2c_eeprom
;
1516 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1517 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2
,
1521 goto err_read_i2c_eeprom
;
1524 ((oui_bytes
[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT
) |
1525 (oui_bytes
[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT
) |
1526 (oui_bytes
[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT
));
1528 if (vendor_oui
== IXGBE_SFF_VENDOR_OUI_INTEL
)
1529 hw
->phy
.type
= ixgbe_phy_qsfp_intel
;
1531 hw
->phy
.type
= ixgbe_phy_qsfp_unknown
;
1533 hw
->mac
.ops
.get_device_caps(hw
, &enforce_sfp
);
1534 if (!(enforce_sfp
& IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP
)) {
1535 /* Make sure we're a supported PHY type */
1536 if (hw
->phy
.type
== ixgbe_phy_qsfp_intel
)
1538 if (hw
->allow_unsupported_sfp
) {
1539 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");
1542 hw_dbg(hw
, "QSFP module not supported\n");
1543 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1544 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1550 err_read_i2c_eeprom
:
1551 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1553 hw
->phy
.type
= ixgbe_phy_unknown
;
1555 return IXGBE_ERR_SFP_NOT_PRESENT
;
1559 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1560 * @hw: pointer to hardware structure
1561 * @list_offset: offset to the SFP ID list
1562 * @data_offset: offset to the SFP data block
1564 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1565 * so it returns the offsets to the phy init sequence block.
1567 s32
ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw
*hw
,
1572 u16 sfp_type
= hw
->phy
.sfp_type
;
1574 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_unknown
)
1575 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1577 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)
1578 return IXGBE_ERR_SFP_NOT_PRESENT
;
1580 if ((hw
->device_id
== IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
) &&
1581 (hw
->phy
.sfp_type
== ixgbe_sfp_type_da_cu
))
1582 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1585 * Limiting active cables and 1G Phys must be initialized as
1588 if (sfp_type
== ixgbe_sfp_type_da_act_lmt_core0
||
1589 sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1590 sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1591 sfp_type
== ixgbe_sfp_type_1g_sx_core0
)
1592 sfp_type
= ixgbe_sfp_type_srlr_core0
;
1593 else if (sfp_type
== ixgbe_sfp_type_da_act_lmt_core1
||
1594 sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1595 sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1596 sfp_type
== ixgbe_sfp_type_1g_sx_core1
)
1597 sfp_type
= ixgbe_sfp_type_srlr_core1
;
1599 /* Read offset to PHY init contents */
1600 if (hw
->eeprom
.ops
.read(hw
, IXGBE_PHY_INIT_OFFSET_NL
, list_offset
)) {
1601 hw_err(hw
, "eeprom read at %d failed\n",
1602 IXGBE_PHY_INIT_OFFSET_NL
);
1603 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT
;
1606 if ((!*list_offset
) || (*list_offset
== 0xFFFF))
1607 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT
;
1609 /* Shift offset to first ID word */
1613 * Find the matching SFP ID in the EEPROM
1614 * and program the init sequence
1616 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, &sfp_id
))
1619 while (sfp_id
!= IXGBE_PHY_INIT_END_NL
) {
1620 if (sfp_id
== sfp_type
) {
1622 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, data_offset
))
1624 if ((!*data_offset
) || (*data_offset
== 0xFFFF)) {
1625 hw_dbg(hw
, "SFP+ module not supported\n");
1626 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1631 (*list_offset
) += 2;
1632 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, &sfp_id
))
1637 if (sfp_id
== IXGBE_PHY_INIT_END_NL
) {
1638 hw_dbg(hw
, "No matching SFP+ module found\n");
1639 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1645 hw_err(hw
, "eeprom read at offset %d failed\n", *list_offset
);
1646 return IXGBE_ERR_PHY
;
1650 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1651 * @hw: pointer to hardware structure
1652 * @byte_offset: EEPROM byte offset to read
1653 * @eeprom_data: value read
1655 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1657 s32
ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1660 return hw
->phy
.ops
.read_i2c_byte(hw
, byte_offset
,
1661 IXGBE_I2C_EEPROM_DEV_ADDR
,
1666 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1667 * @hw: pointer to hardware structure
1668 * @byte_offset: byte offset at address 0xA2
1669 * @eeprom_data: value read
1671 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1673 s32
ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1676 return hw
->phy
.ops
.read_i2c_byte(hw
, byte_offset
,
1677 IXGBE_I2C_EEPROM_DEV_ADDR2
,
1682 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1683 * @hw: pointer to hardware structure
1684 * @byte_offset: EEPROM byte offset to write
1685 * @eeprom_data: value to write
1687 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1689 s32
ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1692 return hw
->phy
.ops
.write_i2c_byte(hw
, byte_offset
,
1693 IXGBE_I2C_EEPROM_DEV_ADDR
,
1698 * ixgbe_is_sfp_probe - Returns true if SFP is being detected
1699 * @hw: pointer to hardware structure
1700 * @offset: eeprom offset to be read
1701 * @addr: I2C address to be read
1703 static bool ixgbe_is_sfp_probe(struct ixgbe_hw
*hw
, u8 offset
, u8 addr
)
1705 if (addr
== IXGBE_I2C_EEPROM_DEV_ADDR
&&
1706 offset
== IXGBE_SFF_IDENTIFIER
&&
1707 hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)
1713 * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
1714 * @hw: pointer to hardware structure
1715 * @byte_offset: byte offset to read
1717 * @lock: true if to take and release semaphore
1719 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1720 * a specified device address.
1722 static s32
ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw
*hw
, u8 byte_offset
,
1723 u8 dev_addr
, u8
*data
, bool lock
)
1728 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
1731 if (hw
->mac
.type
>= ixgbe_mac_X550
)
1733 if (ixgbe_is_sfp_probe(hw
, byte_offset
, dev_addr
))
1734 max_retry
= IXGBE_SFP_DETECT_RETRIES
;
1739 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
1740 return IXGBE_ERR_SWFW_SYNC
;
1742 ixgbe_i2c_start(hw
);
1744 /* Device Address and write indication */
1745 status
= ixgbe_clock_out_i2c_byte(hw
, dev_addr
);
1749 status
= ixgbe_get_i2c_ack(hw
);
1753 status
= ixgbe_clock_out_i2c_byte(hw
, byte_offset
);
1757 status
= ixgbe_get_i2c_ack(hw
);
1761 ixgbe_i2c_start(hw
);
1763 /* Device Address and read indication */
1764 status
= ixgbe_clock_out_i2c_byte(hw
, (dev_addr
| 0x1));
1768 status
= ixgbe_get_i2c_ack(hw
);
1772 status
= ixgbe_clock_in_i2c_byte(hw
, data
);
1776 status
= ixgbe_clock_out_i2c_bit(hw
, nack
);
1782 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1786 ixgbe_i2c_bus_clear(hw
);
1788 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1792 if (retry
< max_retry
)
1793 hw_dbg(hw
, "I2C byte read error - Retrying.\n");
1795 hw_dbg(hw
, "I2C byte read error.\n");
1797 } while (retry
< max_retry
);
1803 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1804 * @hw: pointer to hardware structure
1805 * @byte_offset: byte offset to read
1808 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1809 * a specified device address.
1811 s32
ixgbe_read_i2c_byte_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1812 u8 dev_addr
, u8
*data
)
1814 return ixgbe_read_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1819 * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
1820 * @hw: pointer to hardware structure
1821 * @byte_offset: byte offset to read
1824 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1825 * a specified device address.
1827 s32
ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw
*hw
, u8 byte_offset
,
1828 u8 dev_addr
, u8
*data
)
1830 return ixgbe_read_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1835 * ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
1836 * @hw: pointer to hardware structure
1837 * @byte_offset: byte offset to write
1838 * @data: value to write
1839 * @lock: true if to take and release semaphore
1841 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1842 * a specified device address.
1844 static s32
ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw
*hw
, u8 byte_offset
,
1845 u8 dev_addr
, u8 data
, bool lock
)
1850 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
1852 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
1853 return IXGBE_ERR_SWFW_SYNC
;
1856 ixgbe_i2c_start(hw
);
1858 status
= ixgbe_clock_out_i2c_byte(hw
, dev_addr
);
1862 status
= ixgbe_get_i2c_ack(hw
);
1866 status
= ixgbe_clock_out_i2c_byte(hw
, byte_offset
);
1870 status
= ixgbe_get_i2c_ack(hw
);
1874 status
= ixgbe_clock_out_i2c_byte(hw
, data
);
1878 status
= ixgbe_get_i2c_ack(hw
);
1884 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1888 ixgbe_i2c_bus_clear(hw
);
1890 if (retry
< max_retry
)
1891 hw_dbg(hw
, "I2C byte write error - Retrying.\n");
1893 hw_dbg(hw
, "I2C byte write error.\n");
1894 } while (retry
< max_retry
);
1897 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1903 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1904 * @hw: pointer to hardware structure
1905 * @byte_offset: byte offset to write
1906 * @data: value to write
1908 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1909 * a specified device address.
1911 s32
ixgbe_write_i2c_byte_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1912 u8 dev_addr
, u8 data
)
1914 return ixgbe_write_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1919 * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
1920 * @hw: pointer to hardware structure
1921 * @byte_offset: byte offset to write
1922 * @data: value to write
1924 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1925 * a specified device address.
1927 s32
ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw
*hw
, u8 byte_offset
,
1928 u8 dev_addr
, u8 data
)
1930 return ixgbe_write_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1935 * ixgbe_i2c_start - Sets I2C start condition
1936 * @hw: pointer to hardware structure
1938 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1939 * Set bit-bang mode on X550 hardware.
1941 static void ixgbe_i2c_start(struct ixgbe_hw
*hw
)
1943 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
1945 i2cctl
|= IXGBE_I2C_BB_EN(hw
);
1947 /* Start condition must begin with data and clock high */
1948 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
1949 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
1951 /* Setup time for start condition (4.7us) */
1952 udelay(IXGBE_I2C_T_SU_STA
);
1954 ixgbe_set_i2c_data(hw
, &i2cctl
, 0);
1956 /* Hold time for start condition (4us) */
1957 udelay(IXGBE_I2C_T_HD_STA
);
1959 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
1961 /* Minimum low period of clock is 4.7 us */
1962 udelay(IXGBE_I2C_T_LOW
);
1967 * ixgbe_i2c_stop - Sets I2C stop condition
1968 * @hw: pointer to hardware structure
1970 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1971 * Disables bit-bang mode and negates data output enable on X550
1974 static void ixgbe_i2c_stop(struct ixgbe_hw
*hw
)
1976 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
1977 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
1978 u32 clk_oe_bit
= IXGBE_I2C_CLK_OE_N_EN(hw
);
1979 u32 bb_en_bit
= IXGBE_I2C_BB_EN(hw
);
1981 /* Stop condition must begin with data low and clock high */
1982 ixgbe_set_i2c_data(hw
, &i2cctl
, 0);
1983 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
1985 /* Setup time for stop condition (4us) */
1986 udelay(IXGBE_I2C_T_SU_STO
);
1988 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
1990 /* bus free time between stop and start (4.7us)*/
1991 udelay(IXGBE_I2C_T_BUF
);
1993 if (bb_en_bit
|| data_oe_bit
|| clk_oe_bit
) {
1994 i2cctl
&= ~bb_en_bit
;
1995 i2cctl
|= data_oe_bit
| clk_oe_bit
;
1996 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
1997 IXGBE_WRITE_FLUSH(hw
);
2002 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
2003 * @hw: pointer to hardware structure
2004 * @data: data byte to clock in
2006 * Clocks in one byte data via I2C data/clock
2008 static s32
ixgbe_clock_in_i2c_byte(struct ixgbe_hw
*hw
, u8
*data
)
2014 for (i
= 7; i
>= 0; i
--) {
2015 ixgbe_clock_in_i2c_bit(hw
, &bit
);
2023 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
2024 * @hw: pointer to hardware structure
2025 * @data: data byte clocked out
2027 * Clocks out one byte data via I2C data/clock
2029 static s32
ixgbe_clock_out_i2c_byte(struct ixgbe_hw
*hw
, u8 data
)
2036 for (i
= 7; i
>= 0; i
--) {
2037 bit
= (data
>> i
) & 0x1;
2038 status
= ixgbe_clock_out_i2c_bit(hw
, bit
);
2044 /* Release SDA line (set high) */
2045 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2046 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2047 i2cctl
|= IXGBE_I2C_DATA_OE_N_EN(hw
);
2048 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2049 IXGBE_WRITE_FLUSH(hw
);
2055 * ixgbe_get_i2c_ack - Polls for I2C ACK
2056 * @hw: pointer to hardware structure
2058 * Clocks in/out one bit via I2C data/clock
2060 static s32
ixgbe_get_i2c_ack(struct ixgbe_hw
*hw
)
2062 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2065 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2070 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2071 i2cctl
|= data_oe_bit
;
2072 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2073 IXGBE_WRITE_FLUSH(hw
);
2075 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2077 /* Minimum high period of clock is 4us */
2078 udelay(IXGBE_I2C_T_HIGH
);
2080 /* Poll for ACK. Note that ACK in I2C spec is
2081 * transition from 1 to 0 */
2082 for (i
= 0; i
< timeout
; i
++) {
2083 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2084 ack
= ixgbe_get_i2c_data(hw
, &i2cctl
);
2092 hw_dbg(hw
, "I2C ack was not received.\n");
2093 status
= IXGBE_ERR_I2C
;
2096 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2098 /* Minimum low period of clock is 4.7 us */
2099 udelay(IXGBE_I2C_T_LOW
);
2105 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
2106 * @hw: pointer to hardware structure
2107 * @data: read data value
2109 * Clocks in one bit via I2C data/clock
2111 static s32
ixgbe_clock_in_i2c_bit(struct ixgbe_hw
*hw
, bool *data
)
2113 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2114 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2117 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2118 i2cctl
|= data_oe_bit
;
2119 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2120 IXGBE_WRITE_FLUSH(hw
);
2122 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2124 /* Minimum high period of clock is 4us */
2125 udelay(IXGBE_I2C_T_HIGH
);
2127 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2128 *data
= ixgbe_get_i2c_data(hw
, &i2cctl
);
2130 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2132 /* Minimum low period of clock is 4.7 us */
2133 udelay(IXGBE_I2C_T_LOW
);
2139 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
2140 * @hw: pointer to hardware structure
2141 * @data: data value to write
2143 * Clocks out one bit via I2C data/clock
2145 static s32
ixgbe_clock_out_i2c_bit(struct ixgbe_hw
*hw
, bool data
)
2148 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2150 status
= ixgbe_set_i2c_data(hw
, &i2cctl
, data
);
2152 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2154 /* Minimum high period of clock is 4us */
2155 udelay(IXGBE_I2C_T_HIGH
);
2157 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2159 /* Minimum low period of clock is 4.7 us.
2160 * This also takes care of the data hold time.
2162 udelay(IXGBE_I2C_T_LOW
);
2164 hw_dbg(hw
, "I2C data was not set to %X\n", data
);
2165 return IXGBE_ERR_I2C
;
2171 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2172 * @hw: pointer to hardware structure
2173 * @i2cctl: Current value of I2CCTL register
2175 * Raises the I2C clock line '0'->'1'
2176 * Negates the I2C clock output enable on X550 hardware.
2178 static void ixgbe_raise_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2180 u32 clk_oe_bit
= IXGBE_I2C_CLK_OE_N_EN(hw
);
2182 u32 timeout
= IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT
;
2186 *i2cctl
|= clk_oe_bit
;
2187 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2190 for (i
= 0; i
< timeout
; i
++) {
2191 *i2cctl
|= IXGBE_I2C_CLK_OUT(hw
);
2192 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2193 IXGBE_WRITE_FLUSH(hw
);
2194 /* SCL rise time (1000ns) */
2195 udelay(IXGBE_I2C_T_RISE
);
2197 i2cctl_r
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2198 if (i2cctl_r
& IXGBE_I2C_CLK_IN(hw
))
2204 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2205 * @hw: pointer to hardware structure
2206 * @i2cctl: Current value of I2CCTL register
2208 * Lowers the I2C clock line '1'->'0'
2209 * Asserts the I2C clock output enable on X550 hardware.
2211 static void ixgbe_lower_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2214 *i2cctl
&= ~IXGBE_I2C_CLK_OUT(hw
);
2215 *i2cctl
&= ~IXGBE_I2C_CLK_OE_N_EN(hw
);
2217 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2218 IXGBE_WRITE_FLUSH(hw
);
2220 /* SCL fall time (300ns) */
2221 udelay(IXGBE_I2C_T_FALL
);
2225 * ixgbe_set_i2c_data - Sets the I2C data bit
2226 * @hw: pointer to hardware structure
2227 * @i2cctl: Current value of I2CCTL register
2228 * @data: I2C data value (0 or 1) to set
2230 * Sets the I2C data bit
2231 * Asserts the I2C data output enable on X550 hardware.
2233 static s32
ixgbe_set_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
, bool data
)
2235 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2238 *i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2240 *i2cctl
&= ~IXGBE_I2C_DATA_OUT(hw
);
2241 *i2cctl
&= ~data_oe_bit
;
2243 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2244 IXGBE_WRITE_FLUSH(hw
);
2246 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2247 udelay(IXGBE_I2C_T_RISE
+ IXGBE_I2C_T_FALL
+ IXGBE_I2C_T_SU_DATA
);
2249 if (!data
) /* Can't verify data in this case */
2252 *i2cctl
|= data_oe_bit
;
2253 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2254 IXGBE_WRITE_FLUSH(hw
);
2257 /* Verify data was set correctly */
2258 *i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2259 if (data
!= ixgbe_get_i2c_data(hw
, i2cctl
)) {
2260 hw_dbg(hw
, "Error - I2C data was not set to %X.\n", data
);
2261 return IXGBE_ERR_I2C
;
2268 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2269 * @hw: pointer to hardware structure
2270 * @i2cctl: Current value of I2CCTL register
2272 * Returns the I2C data bit value
2273 * Negates the I2C data output enable on X550 hardware.
2275 static bool ixgbe_get_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2277 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2280 *i2cctl
|= data_oe_bit
;
2281 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2282 IXGBE_WRITE_FLUSH(hw
);
2283 udelay(IXGBE_I2C_T_FALL
);
2286 if (*i2cctl
& IXGBE_I2C_DATA_IN(hw
))
2292 * ixgbe_i2c_bus_clear - Clears the I2C bus
2293 * @hw: pointer to hardware structure
2295 * Clears the I2C bus by sending nine clock pulses.
2296 * Used when data line is stuck low.
2298 static void ixgbe_i2c_bus_clear(struct ixgbe_hw
*hw
)
2303 ixgbe_i2c_start(hw
);
2304 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2306 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
2308 for (i
= 0; i
< 9; i
++) {
2309 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2311 /* Min high period of clock is 4us */
2312 udelay(IXGBE_I2C_T_HIGH
);
2314 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2316 /* Min low period of clock is 4.7us*/
2317 udelay(IXGBE_I2C_T_LOW
);
2320 ixgbe_i2c_start(hw
);
2322 /* Put the i2c bus back to default state */
2327 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
2328 * @hw: pointer to hardware structure
2330 * Checks if the LASI temp alarm status was triggered due to overtemp
2332 s32
ixgbe_tn_check_overtemp(struct ixgbe_hw
*hw
)
2336 if (hw
->device_id
!= IXGBE_DEV_ID_82599_T3_LOM
)
2339 /* Check that the LASI temp alarm status was triggered */
2340 hw
->phy
.ops
.read_reg(hw
, IXGBE_TN_LASI_STATUS_REG
,
2341 MDIO_MMD_PMAPMD
, &phy_data
);
2343 if (!(phy_data
& IXGBE_TN_LASI_STATUS_TEMP_ALARM
))
2346 return IXGBE_ERR_OVERTEMP
;
2349 /** ixgbe_set_copper_phy_power - Control power for copper phy
2350 * @hw: pointer to hardware structure
2351 * @on: true for on, false for off
2353 s32
ixgbe_set_copper_phy_power(struct ixgbe_hw
*hw
, bool on
)
2358 /* Bail if we don't have copper phy */
2359 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_copper
)
2362 if (!on
&& ixgbe_mng_present(hw
))
2365 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_VEND1
, ®
);
2370 reg
&= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE
;
2372 if (ixgbe_check_reset_blocked(hw
))
2374 reg
|= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE
;
2377 status
= hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
, MDIO_MMD_VEND1
, reg
);