1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
5 #include <linux/delay.h>
6 #include <linux/sched.h>
11 static void ixgbe_i2c_start(struct ixgbe_hw
*hw
);
12 static void ixgbe_i2c_stop(struct ixgbe_hw
*hw
);
13 static s32
ixgbe_clock_in_i2c_byte(struct ixgbe_hw
*hw
, u8
*data
);
14 static s32
ixgbe_clock_out_i2c_byte(struct ixgbe_hw
*hw
, u8 data
);
15 static s32
ixgbe_get_i2c_ack(struct ixgbe_hw
*hw
);
16 static s32
ixgbe_clock_in_i2c_bit(struct ixgbe_hw
*hw
, bool *data
);
17 static s32
ixgbe_clock_out_i2c_bit(struct ixgbe_hw
*hw
, bool data
);
18 static void ixgbe_raise_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
);
19 static void ixgbe_lower_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
);
20 static s32
ixgbe_set_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
, bool data
);
21 static bool ixgbe_get_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
);
22 static void ixgbe_i2c_bus_clear(struct ixgbe_hw
*hw
);
23 static enum ixgbe_phy_type
ixgbe_get_phy_type_from_id(u32 phy_id
);
24 static s32
ixgbe_get_phy_id(struct ixgbe_hw
*hw
);
25 static s32
ixgbe_identify_qsfp_module_generic(struct ixgbe_hw
*hw
);
28 * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
29 * @hw: pointer to the hardware structure
32 * Returns an error code on error.
34 static s32
ixgbe_out_i2c_byte_ack(struct ixgbe_hw
*hw
, u8 byte
)
38 status
= ixgbe_clock_out_i2c_byte(hw
, byte
);
41 return ixgbe_get_i2c_ack(hw
);
45 * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
46 * @hw: pointer to the hardware structure
47 * @byte: pointer to a u8 to receive the byte
49 * Returns an error code on error.
51 static s32
ixgbe_in_i2c_byte_ack(struct ixgbe_hw
*hw
, u8
*byte
)
55 status
= ixgbe_clock_in_i2c_byte(hw
, byte
);
59 return ixgbe_clock_out_i2c_bit(hw
, false);
63 * ixgbe_ones_comp_byte_add - Perform one's complement addition
67 * Returns one's complement 8-bit sum.
69 static u8
ixgbe_ones_comp_byte_add(u8 add1
, u8 add2
)
71 u16 sum
= add1
+ add2
;
73 sum
= (sum
& 0xFF) + (sum
>> 8);
78 * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
79 * @hw: pointer to the hardware structure
80 * @addr: I2C bus address to read from
81 * @reg: I2C device register to read from
82 * @val: pointer to location to receive read value
83 * @lock: true if to take and release semaphore
85 * Returns an error code on error.
87 s32
ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw
*hw
, u8 addr
,
88 u16 reg
, u16
*val
, bool lock
)
90 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
99 reg_high
= ((reg
>> 7) & 0xFE) | 1; /* Indicate read combined */
100 csum
= ixgbe_ones_comp_byte_add(reg_high
, reg
& 0xFF);
103 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
104 return IXGBE_ERR_SWFW_SYNC
;
106 /* Device Address and write indication */
107 if (ixgbe_out_i2c_byte_ack(hw
, addr
))
109 /* Write bits 14:8 */
110 if (ixgbe_out_i2c_byte_ack(hw
, reg_high
))
113 if (ixgbe_out_i2c_byte_ack(hw
, reg
& 0xFF))
116 if (ixgbe_out_i2c_byte_ack(hw
, csum
))
118 /* Re-start condition */
120 /* Device Address and read indication */
121 if (ixgbe_out_i2c_byte_ack(hw
, addr
| 1))
124 if (ixgbe_in_i2c_byte_ack(hw
, &high_bits
))
127 if (ixgbe_in_i2c_byte_ack(hw
, &low_bits
))
130 if (ixgbe_clock_in_i2c_byte(hw
, &csum_byte
))
133 if (ixgbe_clock_out_i2c_bit(hw
, false))
137 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
138 *val
= (high_bits
<< 8) | low_bits
;
142 ixgbe_i2c_bus_clear(hw
);
144 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
146 if (retry
< max_retry
)
147 hw_dbg(hw
, "I2C byte read combined error - Retry.\n");
149 hw_dbg(hw
, "I2C byte read combined error.\n");
150 } while (retry
< max_retry
);
152 return IXGBE_ERR_I2C
;
156 * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
157 * @hw: pointer to the hardware structure
158 * @addr: I2C bus address to write to
159 * @reg: I2C device register to write to
160 * @val: value to write
161 * @lock: true if to take and release semaphore
163 * Returns an error code on error.
165 s32
ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw
*hw
, u8 addr
,
166 u16 reg
, u16 val
, bool lock
)
168 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
174 reg_high
= (reg
>> 7) & 0xFE; /* Indicate write combined */
175 csum
= ixgbe_ones_comp_byte_add(reg_high
, reg
& 0xFF);
176 csum
= ixgbe_ones_comp_byte_add(csum
, val
>> 8);
177 csum
= ixgbe_ones_comp_byte_add(csum
, val
& 0xFF);
180 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
181 return IXGBE_ERR_SWFW_SYNC
;
183 /* Device Address and write indication */
184 if (ixgbe_out_i2c_byte_ack(hw
, addr
))
186 /* Write bits 14:8 */
187 if (ixgbe_out_i2c_byte_ack(hw
, reg_high
))
190 if (ixgbe_out_i2c_byte_ack(hw
, reg
& 0xFF))
192 /* Write data 15:8 */
193 if (ixgbe_out_i2c_byte_ack(hw
, val
>> 8))
196 if (ixgbe_out_i2c_byte_ack(hw
, val
& 0xFF))
199 if (ixgbe_out_i2c_byte_ack(hw
, csum
))
203 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
207 ixgbe_i2c_bus_clear(hw
);
209 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
211 if (retry
< max_retry
)
212 hw_dbg(hw
, "I2C byte write combined error - Retry.\n");
214 hw_dbg(hw
, "I2C byte write combined error.\n");
215 } while (retry
< max_retry
);
217 return IXGBE_ERR_I2C
;
221 * ixgbe_probe_phy - Probe a single address for a PHY
222 * @hw: pointer to hardware structure
223 * @phy_addr: PHY address to probe
225 * Returns true if PHY found
227 static bool ixgbe_probe_phy(struct ixgbe_hw
*hw
, u16 phy_addr
)
231 hw
->phy
.mdio
.prtad
= phy_addr
;
232 if (mdio45_probe(&hw
->phy
.mdio
, phy_addr
) != 0)
235 if (ixgbe_get_phy_id(hw
))
238 hw
->phy
.type
= ixgbe_get_phy_type_from_id(hw
->phy
.id
);
240 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
241 hw
->phy
.ops
.read_reg(hw
,
246 (MDIO_PMA_EXTABLE_10GBT
|
247 MDIO_PMA_EXTABLE_1000BT
))
248 hw
->phy
.type
= ixgbe_phy_cu_unknown
;
250 hw
->phy
.type
= ixgbe_phy_generic
;
257 * ixgbe_identify_phy_generic - Get physical layer module
258 * @hw: pointer to hardware structure
260 * Determines the physical layer module found on the current adapter.
262 s32
ixgbe_identify_phy_generic(struct ixgbe_hw
*hw
)
265 u32 status
= IXGBE_ERR_PHY_ADDR_INVALID
;
267 if (!hw
->phy
.phy_semaphore_mask
) {
269 hw
->phy
.phy_semaphore_mask
= IXGBE_GSSR_PHY1_SM
;
271 hw
->phy
.phy_semaphore_mask
= IXGBE_GSSR_PHY0_SM
;
274 if (hw
->phy
.type
!= ixgbe_phy_unknown
)
277 if (hw
->phy
.nw_mng_if_sel
) {
278 phy_addr
= (hw
->phy
.nw_mng_if_sel
&
279 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD
) >>
280 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT
;
281 if (ixgbe_probe_phy(hw
, phy_addr
))
284 return IXGBE_ERR_PHY_ADDR_INVALID
;
287 for (phy_addr
= 0; phy_addr
< IXGBE_MAX_PHY_ADDR
; phy_addr
++) {
288 if (ixgbe_probe_phy(hw
, phy_addr
)) {
294 /* Certain media types do not have a phy so an address will not
295 * be found and the code will take this path. Caller has to
296 * decide if it is an error or not.
299 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
305 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
306 * @hw: pointer to the hardware structure
308 * This function checks the MMNGC.MNG_VETO bit to see if there are
309 * any constraints on link from manageability. For MAC's that don't
310 * have this bit just return false since the link can not be blocked
313 bool ixgbe_check_reset_blocked(struct ixgbe_hw
*hw
)
317 /* If we don't have this bit, it can't be blocking */
318 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
321 mmngc
= IXGBE_READ_REG(hw
, IXGBE_MMNGC
);
322 if (mmngc
& IXGBE_MMNGC_MNG_VETO
) {
323 hw_dbg(hw
, "MNG_VETO bit detected.\n");
331 * ixgbe_get_phy_id - Get the phy type
332 * @hw: pointer to hardware structure
335 static s32
ixgbe_get_phy_id(struct ixgbe_hw
*hw
)
341 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_DEVID1
, MDIO_MMD_PMAPMD
,
345 hw
->phy
.id
= (u32
)(phy_id_high
<< 16);
346 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_DEVID2
, MDIO_MMD_PMAPMD
,
348 hw
->phy
.id
|= (u32
)(phy_id_low
& IXGBE_PHY_REVISION_MASK
);
349 hw
->phy
.revision
= (u32
)(phy_id_low
& ~IXGBE_PHY_REVISION_MASK
);
355 * ixgbe_get_phy_type_from_id - Get the phy type
356 * @phy_id: hardware phy id
359 static enum ixgbe_phy_type
ixgbe_get_phy_type_from_id(u32 phy_id
)
361 enum ixgbe_phy_type phy_type
;
365 phy_type
= ixgbe_phy_tn
;
370 phy_type
= ixgbe_phy_aq
;
373 phy_type
= ixgbe_phy_qt
;
376 phy_type
= ixgbe_phy_nl
;
380 phy_type
= ixgbe_phy_x550em_ext_t
;
383 phy_type
= ixgbe_phy_unknown
;
391 * ixgbe_reset_phy_generic - Performs a PHY reset
392 * @hw: pointer to hardware structure
394 s32
ixgbe_reset_phy_generic(struct ixgbe_hw
*hw
)
400 if (hw
->phy
.type
== ixgbe_phy_unknown
)
401 status
= ixgbe_identify_phy_generic(hw
);
403 if (status
!= 0 || hw
->phy
.type
== ixgbe_phy_none
)
406 /* Don't reset PHY if it's shut down due to overtemp. */
407 if (!hw
->phy
.reset_if_overtemp
&&
408 (IXGBE_ERR_OVERTEMP
== hw
->phy
.ops
.check_overtemp(hw
)))
411 /* Blocked by MNG FW so bail */
412 if (ixgbe_check_reset_blocked(hw
))
416 * Perform soft PHY reset to the PHY_XS.
417 * This will cause a soft reset to the PHY
419 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
424 * Poll for reset bit to self-clear indicating reset is complete.
425 * Some PHYs could take up to 3 seconds to complete and need about
426 * 1.7 usec delay after the reset is complete.
428 for (i
= 0; i
< 30; i
++) {
430 if (hw
->phy
.type
== ixgbe_phy_x550em_ext_t
) {
431 status
= hw
->phy
.ops
.read_reg(hw
,
432 IXGBE_MDIO_TX_VENDOR_ALARMS_3
,
433 MDIO_MMD_PMAPMD
, &ctrl
);
437 if (ctrl
& IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK
) {
442 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
443 MDIO_MMD_PHYXS
, &ctrl
);
447 if (!(ctrl
& MDIO_CTRL1_RESET
)) {
454 if (ctrl
& MDIO_CTRL1_RESET
) {
455 hw_dbg(hw
, "PHY reset polling failed to complete.\n");
456 return IXGBE_ERR_RESET_FAILED
;
463 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
465 * @hw: pointer to hardware structure
466 * @reg_addr: 32 bit address of PHY register to read
467 * @device_type: 5 bit device type
468 * @phy_data: Pointer to read data from PHY register
470 s32
ixgbe_read_phy_reg_mdi(struct ixgbe_hw
*hw
, u32 reg_addr
, u32 device_type
,
473 u32 i
, data
, command
;
475 /* Setup and write the address cycle command */
476 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
477 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
478 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
479 (IXGBE_MSCA_ADDR_CYCLE
| IXGBE_MSCA_MDI_COMMAND
));
481 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
483 /* Check every 10 usec to see if the address cycle completed.
484 * The MDI Command bit will clear when the operation is
487 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
490 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
491 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
496 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
497 hw_dbg(hw
, "PHY address command did not complete.\n");
498 return IXGBE_ERR_PHY
;
501 /* Address cycle complete, setup and write the read
504 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
505 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
506 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
507 (IXGBE_MSCA_READ
| IXGBE_MSCA_MDI_COMMAND
));
509 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
511 /* Check every 10 usec to see if the address cycle
512 * completed. The MDI Command bit will clear when the
513 * operation is complete
515 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
518 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
519 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
523 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
524 hw_dbg(hw
, "PHY read command didn't complete\n");
525 return IXGBE_ERR_PHY
;
528 /* Read operation is complete. Get the data
531 data
= IXGBE_READ_REG(hw
, IXGBE_MSRWD
);
532 data
>>= IXGBE_MSRWD_READ_DATA_SHIFT
;
533 *phy_data
= (u16
)(data
);
539 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
540 * using the SWFW lock - this function is needed in most cases
541 * @hw: pointer to hardware structure
542 * @reg_addr: 32 bit address of PHY register to read
543 * @device_type: 5 bit device type
544 * @phy_data: Pointer to read data from PHY register
546 s32
ixgbe_read_phy_reg_generic(struct ixgbe_hw
*hw
, u32 reg_addr
,
547 u32 device_type
, u16
*phy_data
)
550 u32 gssr
= hw
->phy
.phy_semaphore_mask
;
552 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, gssr
) == 0) {
553 status
= ixgbe_read_phy_reg_mdi(hw
, reg_addr
, device_type
,
555 hw
->mac
.ops
.release_swfw_sync(hw
, gssr
);
557 return IXGBE_ERR_SWFW_SYNC
;
564 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
566 * @hw: pointer to hardware structure
567 * @reg_addr: 32 bit PHY register to write
568 * @device_type: 5 bit device type
569 * @phy_data: Data to write to the PHY register
571 s32
ixgbe_write_phy_reg_mdi(struct ixgbe_hw
*hw
, u32 reg_addr
,
572 u32 device_type
, u16 phy_data
)
576 /* Put the data in the MDI single read and write data register*/
577 IXGBE_WRITE_REG(hw
, IXGBE_MSRWD
, (u32
)phy_data
);
579 /* Setup and write the address cycle command */
580 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
581 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
582 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
583 (IXGBE_MSCA_ADDR_CYCLE
| IXGBE_MSCA_MDI_COMMAND
));
585 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
588 * Check every 10 usec to see if the address cycle completed.
589 * The MDI Command bit will clear when the operation is
592 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
595 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
596 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
600 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
601 hw_dbg(hw
, "PHY address cmd didn't complete\n");
602 return IXGBE_ERR_PHY
;
606 * Address cycle complete, setup and write the write
609 command
= ((reg_addr
<< IXGBE_MSCA_NP_ADDR_SHIFT
) |
610 (device_type
<< IXGBE_MSCA_DEV_TYPE_SHIFT
) |
611 (hw
->phy
.mdio
.prtad
<< IXGBE_MSCA_PHY_ADDR_SHIFT
) |
612 (IXGBE_MSCA_WRITE
| IXGBE_MSCA_MDI_COMMAND
));
614 IXGBE_WRITE_REG(hw
, IXGBE_MSCA
, command
);
616 /* Check every 10 usec to see if the address cycle
617 * completed. The MDI Command bit will clear when the
618 * operation is complete
620 for (i
= 0; i
< IXGBE_MDIO_COMMAND_TIMEOUT
; i
++) {
623 command
= IXGBE_READ_REG(hw
, IXGBE_MSCA
);
624 if ((command
& IXGBE_MSCA_MDI_COMMAND
) == 0)
628 if ((command
& IXGBE_MSCA_MDI_COMMAND
) != 0) {
629 hw_dbg(hw
, "PHY write cmd didn't complete\n");
630 return IXGBE_ERR_PHY
;
637 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
638 * using SWFW lock- this function is needed in most cases
639 * @hw: pointer to hardware structure
640 * @reg_addr: 32 bit PHY register to write
641 * @device_type: 5 bit device type
642 * @phy_data: Data to write to the PHY register
644 s32
ixgbe_write_phy_reg_generic(struct ixgbe_hw
*hw
, u32 reg_addr
,
645 u32 device_type
, u16 phy_data
)
648 u32 gssr
= hw
->phy
.phy_semaphore_mask
;
650 if (hw
->mac
.ops
.acquire_swfw_sync(hw
, gssr
) == 0) {
651 status
= ixgbe_write_phy_reg_mdi(hw
, reg_addr
, device_type
,
653 hw
->mac
.ops
.release_swfw_sync(hw
, gssr
);
655 return IXGBE_ERR_SWFW_SYNC
;
662 * ixgbe_setup_phy_link_generic - Set and restart autoneg
663 * @hw: pointer to hardware structure
665 * Restart autonegotiation and PHY and waits for completion.
667 s32
ixgbe_setup_phy_link_generic(struct ixgbe_hw
*hw
)
670 u16 autoneg_reg
= IXGBE_MII_AUTONEG_REG
;
671 bool autoneg
= false;
672 ixgbe_link_speed speed
;
674 ixgbe_get_copper_link_capabilities_generic(hw
, &speed
, &autoneg
);
676 /* Set or unset auto-negotiation 10G advertisement */
677 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_10GBT_CTRL
, MDIO_MMD_AN
, &autoneg_reg
);
679 autoneg_reg
&= ~MDIO_AN_10GBT_CTRL_ADV10G
;
680 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_10GB_FULL
) &&
681 (speed
& IXGBE_LINK_SPEED_10GB_FULL
))
682 autoneg_reg
|= MDIO_AN_10GBT_CTRL_ADV10G
;
684 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_10GBT_CTRL
, MDIO_MMD_AN
, autoneg_reg
);
686 hw
->phy
.ops
.read_reg(hw
, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG
,
687 MDIO_MMD_AN
, &autoneg_reg
);
689 if (hw
->mac
.type
== ixgbe_mac_X550
) {
690 /* Set or unset auto-negotiation 5G advertisement */
691 autoneg_reg
&= ~IXGBE_MII_5GBASE_T_ADVERTISE
;
692 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_5GB_FULL
) &&
693 (speed
& IXGBE_LINK_SPEED_5GB_FULL
))
694 autoneg_reg
|= IXGBE_MII_5GBASE_T_ADVERTISE
;
696 /* Set or unset auto-negotiation 2.5G advertisement */
697 autoneg_reg
&= ~IXGBE_MII_2_5GBASE_T_ADVERTISE
;
698 if ((hw
->phy
.autoneg_advertised
&
699 IXGBE_LINK_SPEED_2_5GB_FULL
) &&
700 (speed
& IXGBE_LINK_SPEED_2_5GB_FULL
))
701 autoneg_reg
|= IXGBE_MII_2_5GBASE_T_ADVERTISE
;
704 /* Set or unset auto-negotiation 1G advertisement */
705 autoneg_reg
&= ~IXGBE_MII_1GBASE_T_ADVERTISE
;
706 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_1GB_FULL
) &&
707 (speed
& IXGBE_LINK_SPEED_1GB_FULL
))
708 autoneg_reg
|= IXGBE_MII_1GBASE_T_ADVERTISE
;
710 hw
->phy
.ops
.write_reg(hw
, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG
,
711 MDIO_MMD_AN
, autoneg_reg
);
713 /* Set or unset auto-negotiation 100M advertisement */
714 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_ADVERTISE
, MDIO_MMD_AN
, &autoneg_reg
);
716 autoneg_reg
&= ~(ADVERTISE_100FULL
| ADVERTISE_100HALF
);
717 if ((hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_100_FULL
) &&
718 (speed
& IXGBE_LINK_SPEED_100_FULL
))
719 autoneg_reg
|= ADVERTISE_100FULL
;
721 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_ADVERTISE
, MDIO_MMD_AN
, autoneg_reg
);
723 /* Blocked by MNG FW so don't reset PHY */
724 if (ixgbe_check_reset_blocked(hw
))
727 /* Restart PHY autonegotiation and wait for completion */
728 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
729 MDIO_MMD_AN
, &autoneg_reg
);
731 autoneg_reg
|= MDIO_AN_CTRL1_RESTART
;
733 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
734 MDIO_MMD_AN
, autoneg_reg
);
740 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
741 * @hw: pointer to hardware structure
742 * @speed: new link speed
743 * @autoneg_wait_to_complete: unused
745 s32
ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw
*hw
,
746 ixgbe_link_speed speed
,
747 bool autoneg_wait_to_complete
)
749 /* Clear autoneg_advertised and set new values based on input link
752 hw
->phy
.autoneg_advertised
= 0;
754 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
755 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10GB_FULL
;
757 if (speed
& IXGBE_LINK_SPEED_5GB_FULL
)
758 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_5GB_FULL
;
760 if (speed
& IXGBE_LINK_SPEED_2_5GB_FULL
)
761 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_2_5GB_FULL
;
763 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
)
764 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_1GB_FULL
;
766 if (speed
& IXGBE_LINK_SPEED_100_FULL
)
767 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_100_FULL
;
769 if (speed
& IXGBE_LINK_SPEED_10_FULL
)
770 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10_FULL
;
772 /* Setup link based on the new speed settings */
773 if (hw
->phy
.ops
.setup_link
)
774 hw
->phy
.ops
.setup_link(hw
);
780 * ixgbe_get_copper_speeds_supported - Get copper link speed from phy
781 * @hw: pointer to hardware structure
783 * Determines the supported link capabilities by reading the PHY auto
784 * negotiation register.
786 static s32
ixgbe_get_copper_speeds_supported(struct ixgbe_hw
*hw
)
791 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_SPEED
, MDIO_MMD_PMAPMD
,
796 if (speed_ability
& MDIO_SPEED_10G
)
797 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_10GB_FULL
;
798 if (speed_ability
& MDIO_PMA_SPEED_1000
)
799 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_1GB_FULL
;
800 if (speed_ability
& MDIO_PMA_SPEED_100
)
801 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_100_FULL
;
803 switch (hw
->mac
.type
) {
805 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_2_5GB_FULL
;
806 hw
->phy
.speeds_supported
|= IXGBE_LINK_SPEED_5GB_FULL
;
808 case ixgbe_mac_X550EM_x
:
809 case ixgbe_mac_x550em_a
:
810 hw
->phy
.speeds_supported
&= ~IXGBE_LINK_SPEED_100_FULL
;
820 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
821 * @hw: pointer to hardware structure
822 * @speed: pointer to link speed
823 * @autoneg: boolean auto-negotiation value
825 s32
ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw
*hw
,
826 ixgbe_link_speed
*speed
,
832 if (!hw
->phy
.speeds_supported
)
833 status
= ixgbe_get_copper_speeds_supported(hw
);
835 *speed
= hw
->phy
.speeds_supported
;
840 * ixgbe_check_phy_link_tnx - Determine link and speed status
841 * @hw: pointer to hardware structure
843 * @link_up: status of link
845 * Reads the VS1 register to determine if link is up and the current speed for
848 s32
ixgbe_check_phy_link_tnx(struct ixgbe_hw
*hw
, ixgbe_link_speed
*speed
,
853 u32 max_time_out
= 10;
858 /* Initialize speed and link to default case */
860 *speed
= IXGBE_LINK_SPEED_10GB_FULL
;
863 * Check current speed and link status of the PHY register.
864 * This is a vendor specific register and may have to
865 * be changed for other copper PHYs.
867 for (time_out
= 0; time_out
< max_time_out
; time_out
++) {
869 status
= hw
->phy
.ops
.read_reg(hw
,
873 phy_link
= phy_data
&
874 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS
;
875 phy_speed
= phy_data
&
876 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS
;
877 if (phy_link
== IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS
) {
880 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS
)
881 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
890 * ixgbe_setup_phy_link_tnx - Set and restart autoneg
891 * @hw: pointer to hardware structure
893 * Restart autonegotiation and PHY and waits for completion.
894 * This function always returns success, this is nessary since
895 * it is called via a function pointer that could call other
896 * functions that could return an error.
898 s32
ixgbe_setup_phy_link_tnx(struct ixgbe_hw
*hw
)
900 u16 autoneg_reg
= IXGBE_MII_AUTONEG_REG
;
901 bool autoneg
= false;
902 ixgbe_link_speed speed
;
904 ixgbe_get_copper_link_capabilities_generic(hw
, &speed
, &autoneg
);
906 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
) {
907 /* Set or unset auto-negotiation 10G advertisement */
908 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_10GBT_CTRL
,
912 autoneg_reg
&= ~MDIO_AN_10GBT_CTRL_ADV10G
;
913 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_10GB_FULL
)
914 autoneg_reg
|= MDIO_AN_10GBT_CTRL_ADV10G
;
916 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_10GBT_CTRL
,
921 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
) {
922 /* Set or unset auto-negotiation 1G advertisement */
923 hw
->phy
.ops
.read_reg(hw
, IXGBE_MII_AUTONEG_XNP_TX_REG
,
927 autoneg_reg
&= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX
;
928 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_1GB_FULL
)
929 autoneg_reg
|= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX
;
931 hw
->phy
.ops
.write_reg(hw
, IXGBE_MII_AUTONEG_XNP_TX_REG
,
936 if (speed
& IXGBE_LINK_SPEED_100_FULL
) {
937 /* Set or unset auto-negotiation 100M advertisement */
938 hw
->phy
.ops
.read_reg(hw
, MDIO_AN_ADVERTISE
,
942 autoneg_reg
&= ~(ADVERTISE_100FULL
|
944 if (hw
->phy
.autoneg_advertised
& IXGBE_LINK_SPEED_100_FULL
)
945 autoneg_reg
|= ADVERTISE_100FULL
;
947 hw
->phy
.ops
.write_reg(hw
, MDIO_AN_ADVERTISE
,
952 /* Blocked by MNG FW so don't reset PHY */
953 if (ixgbe_check_reset_blocked(hw
))
956 /* Restart PHY autonegotiation and wait for completion */
957 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
,
958 MDIO_MMD_AN
, &autoneg_reg
);
960 autoneg_reg
|= MDIO_AN_CTRL1_RESTART
;
962 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
,
963 MDIO_MMD_AN
, autoneg_reg
);
968 * ixgbe_reset_phy_nl - Performs a PHY reset
969 * @hw: pointer to hardware structure
971 s32
ixgbe_reset_phy_nl(struct ixgbe_hw
*hw
)
973 u16 phy_offset
, control
, eword
, edata
, block_crc
;
974 bool end_data
= false;
975 u16 list_offset
, data_offset
;
980 /* Blocked by MNG FW so bail */
981 if (ixgbe_check_reset_blocked(hw
))
984 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
, &phy_data
);
986 /* reset the PHY and poll for completion */
987 hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
,
988 (phy_data
| MDIO_CTRL1_RESET
));
990 for (i
= 0; i
< 100; i
++) {
991 hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_PHYXS
,
993 if ((phy_data
& MDIO_CTRL1_RESET
) == 0)
995 usleep_range(10000, 20000);
998 if ((phy_data
& MDIO_CTRL1_RESET
) != 0) {
999 hw_dbg(hw
, "PHY reset did not complete.\n");
1000 return IXGBE_ERR_PHY
;
1003 /* Get init offsets */
1004 ret_val
= ixgbe_get_sfp_init_sequence_offsets(hw
, &list_offset
,
1009 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
, &block_crc
);
1013 * Read control word from PHY init contents offset
1015 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
, &eword
);
1018 control
= (eword
& IXGBE_CONTROL_MASK_NL
) >>
1019 IXGBE_CONTROL_SHIFT_NL
;
1020 edata
= eword
& IXGBE_DATA_MASK_NL
;
1022 case IXGBE_DELAY_NL
:
1024 hw_dbg(hw
, "DELAY: %d MS\n", edata
);
1025 usleep_range(edata
* 1000, edata
* 2000);
1028 hw_dbg(hw
, "DATA:\n");
1030 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
++,
1034 for (i
= 0; i
< edata
; i
++) {
1035 ret_val
= hw
->eeprom
.ops
.read(hw
, data_offset
,
1039 hw
->phy
.ops
.write_reg(hw
, phy_offset
,
1040 MDIO_MMD_PMAPMD
, eword
);
1041 hw_dbg(hw
, "Wrote %4.4x to %4.4x\n", eword
,
1047 case IXGBE_CONTROL_NL
:
1049 hw_dbg(hw
, "CONTROL:\n");
1050 if (edata
== IXGBE_CONTROL_EOL_NL
) {
1051 hw_dbg(hw
, "EOL\n");
1053 } else if (edata
== IXGBE_CONTROL_SOL_NL
) {
1054 hw_dbg(hw
, "SOL\n");
1056 hw_dbg(hw
, "Bad control value\n");
1057 return IXGBE_ERR_PHY
;
1061 hw_dbg(hw
, "Bad control type\n");
1062 return IXGBE_ERR_PHY
;
1069 hw_err(hw
, "eeprom read at offset %d failed\n", data_offset
);
1070 return IXGBE_ERR_PHY
;
1074 * ixgbe_identify_module_generic - Identifies module type
1075 * @hw: pointer to hardware structure
1077 * Determines HW type and calls appropriate function.
1079 s32
ixgbe_identify_module_generic(struct ixgbe_hw
*hw
)
1081 switch (hw
->mac
.ops
.get_media_type(hw
)) {
1082 case ixgbe_media_type_fiber
:
1083 return ixgbe_identify_sfp_module_generic(hw
);
1084 case ixgbe_media_type_fiber_qsfp
:
1085 return ixgbe_identify_qsfp_module_generic(hw
);
1087 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1088 return IXGBE_ERR_SFP_NOT_PRESENT
;
1091 return IXGBE_ERR_SFP_NOT_PRESENT
;
1095 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1096 * @hw: pointer to hardware structure
1098 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1100 s32
ixgbe_identify_sfp_module_generic(struct ixgbe_hw
*hw
)
1102 struct ixgbe_adapter
*adapter
= hw
->back
;
1105 enum ixgbe_sfp_type stored_sfp_type
= hw
->phy
.sfp_type
;
1107 u8 comp_codes_1g
= 0;
1108 u8 comp_codes_10g
= 0;
1109 u8 oui_bytes
[3] = {0, 0, 0};
1112 u16 enforce_sfp
= 0;
1114 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_fiber
) {
1115 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1116 return IXGBE_ERR_SFP_NOT_PRESENT
;
1119 /* LAN ID is needed for sfp_type determination */
1120 hw
->mac
.ops
.set_lan_id(hw
);
1122 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1123 IXGBE_SFF_IDENTIFIER
,
1127 goto err_read_i2c_eeprom
;
1129 if (identifier
!= IXGBE_SFF_IDENTIFIER_SFP
) {
1130 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1131 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1133 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1134 IXGBE_SFF_1GBE_COMP_CODES
,
1138 goto err_read_i2c_eeprom
;
1140 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1141 IXGBE_SFF_10GBE_COMP_CODES
,
1145 goto err_read_i2c_eeprom
;
1146 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1147 IXGBE_SFF_CABLE_TECHNOLOGY
,
1151 goto err_read_i2c_eeprom
;
1158 * 3 SFP_DA_CORE0 - 82599-specific
1159 * 4 SFP_DA_CORE1 - 82599-specific
1160 * 5 SFP_SR/LR_CORE0 - 82599-specific
1161 * 6 SFP_SR/LR_CORE1 - 82599-specific
1162 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1163 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1164 * 9 SFP_1g_cu_CORE0 - 82599-specific
1165 * 10 SFP_1g_cu_CORE1 - 82599-specific
1166 * 11 SFP_1g_sx_CORE0 - 82599-specific
1167 * 12 SFP_1g_sx_CORE1 - 82599-specific
1169 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
1170 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1171 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu
;
1172 else if (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)
1173 hw
->phy
.sfp_type
= ixgbe_sfp_type_sr
;
1174 else if (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)
1175 hw
->phy
.sfp_type
= ixgbe_sfp_type_lr
;
1177 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
1179 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
) {
1180 if (hw
->bus
.lan_id
== 0)
1182 ixgbe_sfp_type_da_cu_core0
;
1185 ixgbe_sfp_type_da_cu_core1
;
1186 } else if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
) {
1187 hw
->phy
.ops
.read_i2c_eeprom(
1188 hw
, IXGBE_SFF_CABLE_SPEC_COMP
,
1191 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING
) {
1192 if (hw
->bus
.lan_id
== 0)
1194 ixgbe_sfp_type_da_act_lmt_core0
;
1197 ixgbe_sfp_type_da_act_lmt_core1
;
1200 ixgbe_sfp_type_unknown
;
1202 } else if (comp_codes_10g
&
1203 (IXGBE_SFF_10GBASESR_CAPABLE
|
1204 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1205 if (hw
->bus
.lan_id
== 0)
1207 ixgbe_sfp_type_srlr_core0
;
1210 ixgbe_sfp_type_srlr_core1
;
1211 } else if (comp_codes_1g
& IXGBE_SFF_1GBASET_CAPABLE
) {
1212 if (hw
->bus
.lan_id
== 0)
1214 ixgbe_sfp_type_1g_cu_core0
;
1217 ixgbe_sfp_type_1g_cu_core1
;
1218 } else if (comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) {
1219 if (hw
->bus
.lan_id
== 0)
1221 ixgbe_sfp_type_1g_sx_core0
;
1224 ixgbe_sfp_type_1g_sx_core1
;
1225 } else if (comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) {
1226 if (hw
->bus
.lan_id
== 0)
1228 ixgbe_sfp_type_1g_lx_core0
;
1231 ixgbe_sfp_type_1g_lx_core1
;
1233 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
1237 if (hw
->phy
.sfp_type
!= stored_sfp_type
)
1238 hw
->phy
.sfp_setup_needed
= true;
1240 /* Determine if the SFP+ PHY is dual speed or not. */
1241 hw
->phy
.multispeed_fiber
= false;
1242 if (((comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) &&
1243 (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)) ||
1244 ((comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) &&
1245 (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)))
1246 hw
->phy
.multispeed_fiber
= true;
1248 /* Determine PHY vendor */
1249 if (hw
->phy
.type
!= ixgbe_phy_nl
) {
1250 hw
->phy
.id
= identifier
;
1251 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1252 IXGBE_SFF_VENDOR_OUI_BYTE0
,
1256 goto err_read_i2c_eeprom
;
1258 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1259 IXGBE_SFF_VENDOR_OUI_BYTE1
,
1263 goto err_read_i2c_eeprom
;
1265 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1266 IXGBE_SFF_VENDOR_OUI_BYTE2
,
1270 goto err_read_i2c_eeprom
;
1273 ((oui_bytes
[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT
) |
1274 (oui_bytes
[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT
) |
1275 (oui_bytes
[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT
));
1277 switch (vendor_oui
) {
1278 case IXGBE_SFF_VENDOR_OUI_TYCO
:
1279 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1281 ixgbe_phy_sfp_passive_tyco
;
1283 case IXGBE_SFF_VENDOR_OUI_FTL
:
1284 if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
)
1285 hw
->phy
.type
= ixgbe_phy_sfp_ftl_active
;
1287 hw
->phy
.type
= ixgbe_phy_sfp_ftl
;
1289 case IXGBE_SFF_VENDOR_OUI_AVAGO
:
1290 hw
->phy
.type
= ixgbe_phy_sfp_avago
;
1292 case IXGBE_SFF_VENDOR_OUI_INTEL
:
1293 hw
->phy
.type
= ixgbe_phy_sfp_intel
;
1296 if (cable_tech
& IXGBE_SFF_DA_PASSIVE_CABLE
)
1298 ixgbe_phy_sfp_passive_unknown
;
1299 else if (cable_tech
& IXGBE_SFF_DA_ACTIVE_CABLE
)
1301 ixgbe_phy_sfp_active_unknown
;
1303 hw
->phy
.type
= ixgbe_phy_sfp_unknown
;
1308 /* Allow any DA cable vendor */
1309 if (cable_tech
& (IXGBE_SFF_DA_PASSIVE_CABLE
|
1310 IXGBE_SFF_DA_ACTIVE_CABLE
))
1313 /* Verify supported 1G SFP modules */
1314 if (comp_codes_10g
== 0 &&
1315 !(hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1316 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1317 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1318 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1319 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core0
||
1320 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core1
)) {
1321 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1322 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1325 /* Anything else 82598-based is supported */
1326 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
1329 hw
->mac
.ops
.get_device_caps(hw
, &enforce_sfp
);
1330 if (!(enforce_sfp
& IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP
) &&
1331 !(hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1332 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1333 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1334 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1335 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core0
||
1336 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core1
)) {
1337 /* Make sure we're a supported PHY type */
1338 if (hw
->phy
.type
== ixgbe_phy_sfp_intel
)
1340 if (hw
->allow_unsupported_sfp
) {
1341 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");
1344 hw_dbg(hw
, "SFP+ module not supported\n");
1345 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1346 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1350 err_read_i2c_eeprom
:
1351 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1352 if (hw
->phy
.type
!= ixgbe_phy_nl
) {
1354 hw
->phy
.type
= ixgbe_phy_unknown
;
1356 return IXGBE_ERR_SFP_NOT_PRESENT
;
1360 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1361 * @hw: pointer to hardware structure
1363 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1365 static s32
ixgbe_identify_qsfp_module_generic(struct ixgbe_hw
*hw
)
1367 struct ixgbe_adapter
*adapter
= hw
->back
;
1370 enum ixgbe_sfp_type stored_sfp_type
= hw
->phy
.sfp_type
;
1372 u8 comp_codes_1g
= 0;
1373 u8 comp_codes_10g
= 0;
1374 u8 oui_bytes
[3] = {0, 0, 0};
1375 u16 enforce_sfp
= 0;
1377 u8 cable_length
= 0;
1379 bool active_cable
= false;
1381 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_fiber_qsfp
) {
1382 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1383 return IXGBE_ERR_SFP_NOT_PRESENT
;
1386 /* LAN ID is needed for sfp_type determination */
1387 hw
->mac
.ops
.set_lan_id(hw
);
1389 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_IDENTIFIER
,
1393 goto err_read_i2c_eeprom
;
1395 if (identifier
!= IXGBE_SFF_IDENTIFIER_QSFP_PLUS
) {
1396 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1397 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1400 hw
->phy
.id
= identifier
;
1402 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_QSFP_10GBE_COMP
,
1406 goto err_read_i2c_eeprom
;
1408 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
, IXGBE_SFF_QSFP_1GBE_COMP
,
1412 goto err_read_i2c_eeprom
;
1414 if (comp_codes_10g
& IXGBE_SFF_QSFP_DA_PASSIVE_CABLE
) {
1415 hw
->phy
.type
= ixgbe_phy_qsfp_passive_unknown
;
1416 if (hw
->bus
.lan_id
== 0)
1417 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu_core0
;
1419 hw
->phy
.sfp_type
= ixgbe_sfp_type_da_cu_core1
;
1420 } else if (comp_codes_10g
& (IXGBE_SFF_10GBASESR_CAPABLE
|
1421 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1422 if (hw
->bus
.lan_id
== 0)
1423 hw
->phy
.sfp_type
= ixgbe_sfp_type_srlr_core0
;
1425 hw
->phy
.sfp_type
= ixgbe_sfp_type_srlr_core1
;
1427 if (comp_codes_10g
& IXGBE_SFF_QSFP_DA_ACTIVE_CABLE
)
1428 active_cable
= true;
1430 if (!active_cable
) {
1431 /* check for active DA cables that pre-date
1434 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1435 IXGBE_SFF_QSFP_CONNECTOR
,
1438 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1439 IXGBE_SFF_QSFP_CABLE_LENGTH
,
1442 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1443 IXGBE_SFF_QSFP_DEVICE_TECH
,
1447 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE
) &&
1448 (cable_length
> 0) &&
1449 ((device_tech
>> 4) ==
1450 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL
))
1451 active_cable
= true;
1455 hw
->phy
.type
= ixgbe_phy_qsfp_active_unknown
;
1456 if (hw
->bus
.lan_id
== 0)
1458 ixgbe_sfp_type_da_act_lmt_core0
;
1461 ixgbe_sfp_type_da_act_lmt_core1
;
1463 /* unsupported module type */
1464 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1465 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1469 if (hw
->phy
.sfp_type
!= stored_sfp_type
)
1470 hw
->phy
.sfp_setup_needed
= true;
1472 /* Determine if the QSFP+ PHY is dual speed or not. */
1473 hw
->phy
.multispeed_fiber
= false;
1474 if (((comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
) &&
1475 (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)) ||
1476 ((comp_codes_1g
& IXGBE_SFF_1GBASELX_CAPABLE
) &&
1477 (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)))
1478 hw
->phy
.multispeed_fiber
= true;
1480 /* Determine PHY vendor for optical modules */
1481 if (comp_codes_10g
& (IXGBE_SFF_10GBASESR_CAPABLE
|
1482 IXGBE_SFF_10GBASELR_CAPABLE
)) {
1483 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1484 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0
,
1488 goto err_read_i2c_eeprom
;
1490 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1491 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1
,
1495 goto err_read_i2c_eeprom
;
1497 status
= hw
->phy
.ops
.read_i2c_eeprom(hw
,
1498 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2
,
1502 goto err_read_i2c_eeprom
;
1505 ((oui_bytes
[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT
) |
1506 (oui_bytes
[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT
) |
1507 (oui_bytes
[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT
));
1509 if (vendor_oui
== IXGBE_SFF_VENDOR_OUI_INTEL
)
1510 hw
->phy
.type
= ixgbe_phy_qsfp_intel
;
1512 hw
->phy
.type
= ixgbe_phy_qsfp_unknown
;
1514 hw
->mac
.ops
.get_device_caps(hw
, &enforce_sfp
);
1515 if (!(enforce_sfp
& IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP
)) {
1516 /* Make sure we're a supported PHY type */
1517 if (hw
->phy
.type
== ixgbe_phy_qsfp_intel
)
1519 if (hw
->allow_unsupported_sfp
) {
1520 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");
1523 hw_dbg(hw
, "QSFP module not supported\n");
1524 hw
->phy
.type
= ixgbe_phy_sfp_unsupported
;
1525 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1531 err_read_i2c_eeprom
:
1532 hw
->phy
.sfp_type
= ixgbe_sfp_type_not_present
;
1534 hw
->phy
.type
= ixgbe_phy_unknown
;
1536 return IXGBE_ERR_SFP_NOT_PRESENT
;
1540 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1541 * @hw: pointer to hardware structure
1542 * @list_offset: offset to the SFP ID list
1543 * @data_offset: offset to the SFP data block
1545 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1546 * so it returns the offsets to the phy init sequence block.
1548 s32
ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw
*hw
,
1553 u16 sfp_type
= hw
->phy
.sfp_type
;
1555 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_unknown
)
1556 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1558 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)
1559 return IXGBE_ERR_SFP_NOT_PRESENT
;
1561 if ((hw
->device_id
== IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
) &&
1562 (hw
->phy
.sfp_type
== ixgbe_sfp_type_da_cu
))
1563 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1566 * Limiting active cables and 1G Phys must be initialized as
1569 if (sfp_type
== ixgbe_sfp_type_da_act_lmt_core0
||
1570 sfp_type
== ixgbe_sfp_type_1g_lx_core0
||
1571 sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
1572 sfp_type
== ixgbe_sfp_type_1g_sx_core0
)
1573 sfp_type
= ixgbe_sfp_type_srlr_core0
;
1574 else if (sfp_type
== ixgbe_sfp_type_da_act_lmt_core1
||
1575 sfp_type
== ixgbe_sfp_type_1g_lx_core1
||
1576 sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
1577 sfp_type
== ixgbe_sfp_type_1g_sx_core1
)
1578 sfp_type
= ixgbe_sfp_type_srlr_core1
;
1580 /* Read offset to PHY init contents */
1581 if (hw
->eeprom
.ops
.read(hw
, IXGBE_PHY_INIT_OFFSET_NL
, list_offset
)) {
1582 hw_err(hw
, "eeprom read at %d failed\n",
1583 IXGBE_PHY_INIT_OFFSET_NL
);
1584 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT
;
1587 if ((!*list_offset
) || (*list_offset
== 0xFFFF))
1588 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT
;
1590 /* Shift offset to first ID word */
1594 * Find the matching SFP ID in the EEPROM
1595 * and program the init sequence
1597 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, &sfp_id
))
1600 while (sfp_id
!= IXGBE_PHY_INIT_END_NL
) {
1601 if (sfp_id
== sfp_type
) {
1603 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, data_offset
))
1605 if ((!*data_offset
) || (*data_offset
== 0xFFFF)) {
1606 hw_dbg(hw
, "SFP+ module not supported\n");
1607 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1612 (*list_offset
) += 2;
1613 if (hw
->eeprom
.ops
.read(hw
, *list_offset
, &sfp_id
))
1618 if (sfp_id
== IXGBE_PHY_INIT_END_NL
) {
1619 hw_dbg(hw
, "No matching SFP+ module found\n");
1620 return IXGBE_ERR_SFP_NOT_SUPPORTED
;
1626 hw_err(hw
, "eeprom read at offset %d failed\n", *list_offset
);
1627 return IXGBE_ERR_PHY
;
1631 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1632 * @hw: pointer to hardware structure
1633 * @byte_offset: EEPROM byte offset to read
1634 * @eeprom_data: value read
1636 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1638 s32
ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1641 return hw
->phy
.ops
.read_i2c_byte(hw
, byte_offset
,
1642 IXGBE_I2C_EEPROM_DEV_ADDR
,
1647 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1648 * @hw: pointer to hardware structure
1649 * @byte_offset: byte offset at address 0xA2
1650 * @sff8472_data: value read
1652 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1654 s32
ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1657 return hw
->phy
.ops
.read_i2c_byte(hw
, byte_offset
,
1658 IXGBE_I2C_EEPROM_DEV_ADDR2
,
1663 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1664 * @hw: pointer to hardware structure
1665 * @byte_offset: EEPROM byte offset to write
1666 * @eeprom_data: value to write
1668 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1670 s32
ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1673 return hw
->phy
.ops
.write_i2c_byte(hw
, byte_offset
,
1674 IXGBE_I2C_EEPROM_DEV_ADDR
,
1679 * ixgbe_is_sfp_probe - Returns true if SFP is being detected
1680 * @hw: pointer to hardware structure
1681 * @offset: eeprom offset to be read
1682 * @addr: I2C address to be read
1684 static bool ixgbe_is_sfp_probe(struct ixgbe_hw
*hw
, u8 offset
, u8 addr
)
1686 if (addr
== IXGBE_I2C_EEPROM_DEV_ADDR
&&
1687 offset
== IXGBE_SFF_IDENTIFIER
&&
1688 hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)
1694 * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
1695 * @hw: pointer to hardware structure
1696 * @byte_offset: byte offset to read
1697 * @dev_addr: device address
1699 * @lock: true if to take and release semaphore
1701 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1702 * a specified device address.
1704 static s32
ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw
*hw
, u8 byte_offset
,
1705 u8 dev_addr
, u8
*data
, bool lock
)
1710 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
1713 if (hw
->mac
.type
>= ixgbe_mac_X550
)
1715 if (ixgbe_is_sfp_probe(hw
, byte_offset
, dev_addr
))
1716 max_retry
= IXGBE_SFP_DETECT_RETRIES
;
1721 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
1722 return IXGBE_ERR_SWFW_SYNC
;
1724 ixgbe_i2c_start(hw
);
1726 /* Device Address and write indication */
1727 status
= ixgbe_clock_out_i2c_byte(hw
, dev_addr
);
1731 status
= ixgbe_get_i2c_ack(hw
);
1735 status
= ixgbe_clock_out_i2c_byte(hw
, byte_offset
);
1739 status
= ixgbe_get_i2c_ack(hw
);
1743 ixgbe_i2c_start(hw
);
1745 /* Device Address and read indication */
1746 status
= ixgbe_clock_out_i2c_byte(hw
, (dev_addr
| 0x1));
1750 status
= ixgbe_get_i2c_ack(hw
);
1754 status
= ixgbe_clock_in_i2c_byte(hw
, data
);
1758 status
= ixgbe_clock_out_i2c_bit(hw
, nack
);
1764 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1768 ixgbe_i2c_bus_clear(hw
);
1770 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1774 if (retry
< max_retry
)
1775 hw_dbg(hw
, "I2C byte read error - Retrying.\n");
1777 hw_dbg(hw
, "I2C byte read error.\n");
1779 } while (retry
< max_retry
);
1785 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1786 * @hw: pointer to hardware structure
1787 * @byte_offset: byte offset to read
1788 * @dev_addr: device address
1791 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1792 * a specified device address.
1794 s32
ixgbe_read_i2c_byte_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1795 u8 dev_addr
, u8
*data
)
1797 return ixgbe_read_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1802 * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
1803 * @hw: pointer to hardware structure
1804 * @byte_offset: byte offset to read
1805 * @dev_addr: device address
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_unlocked(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_write_i2c_byte_generic_int - Writes 8 bit word over I2C
1820 * @hw: pointer to hardware structure
1821 * @byte_offset: byte offset to write
1822 * @dev_addr: device address
1823 * @data: value to write
1824 * @lock: true if to take and release semaphore
1826 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1827 * a specified device address.
1829 static s32
ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw
*hw
, u8 byte_offset
,
1830 u8 dev_addr
, u8 data
, bool lock
)
1835 u32 swfw_mask
= hw
->phy
.phy_semaphore_mask
;
1837 if (lock
&& hw
->mac
.ops
.acquire_swfw_sync(hw
, swfw_mask
))
1838 return IXGBE_ERR_SWFW_SYNC
;
1841 ixgbe_i2c_start(hw
);
1843 status
= ixgbe_clock_out_i2c_byte(hw
, dev_addr
);
1847 status
= ixgbe_get_i2c_ack(hw
);
1851 status
= ixgbe_clock_out_i2c_byte(hw
, byte_offset
);
1855 status
= ixgbe_get_i2c_ack(hw
);
1859 status
= ixgbe_clock_out_i2c_byte(hw
, data
);
1863 status
= ixgbe_get_i2c_ack(hw
);
1869 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1873 ixgbe_i2c_bus_clear(hw
);
1875 if (retry
< max_retry
)
1876 hw_dbg(hw
, "I2C byte write error - Retrying.\n");
1878 hw_dbg(hw
, "I2C byte write error.\n");
1879 } while (retry
< max_retry
);
1882 hw
->mac
.ops
.release_swfw_sync(hw
, swfw_mask
);
1888 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
1889 * @hw: pointer to hardware structure
1890 * @byte_offset: byte offset to write
1891 * @dev_addr: device address
1892 * @data: value to write
1894 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1895 * a specified device address.
1897 s32
ixgbe_write_i2c_byte_generic(struct ixgbe_hw
*hw
, u8 byte_offset
,
1898 u8 dev_addr
, u8 data
)
1900 return ixgbe_write_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1905 * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
1906 * @hw: pointer to hardware structure
1907 * @byte_offset: byte offset to write
1908 * @dev_addr: device address
1909 * @data: value to write
1911 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1912 * a specified device address.
1914 s32
ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw
*hw
, u8 byte_offset
,
1915 u8 dev_addr
, u8 data
)
1917 return ixgbe_write_i2c_byte_generic_int(hw
, byte_offset
, dev_addr
,
1922 * ixgbe_i2c_start - Sets I2C start condition
1923 * @hw: pointer to hardware structure
1925 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1926 * Set bit-bang mode on X550 hardware.
1928 static void ixgbe_i2c_start(struct ixgbe_hw
*hw
)
1930 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
1932 i2cctl
|= IXGBE_I2C_BB_EN(hw
);
1934 /* Start condition must begin with data and clock high */
1935 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
1936 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
1938 /* Setup time for start condition (4.7us) */
1939 udelay(IXGBE_I2C_T_SU_STA
);
1941 ixgbe_set_i2c_data(hw
, &i2cctl
, 0);
1943 /* Hold time for start condition (4us) */
1944 udelay(IXGBE_I2C_T_HD_STA
);
1946 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
1948 /* Minimum low period of clock is 4.7 us */
1949 udelay(IXGBE_I2C_T_LOW
);
1954 * ixgbe_i2c_stop - Sets I2C stop condition
1955 * @hw: pointer to hardware structure
1957 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1958 * Disables bit-bang mode and negates data output enable on X550
1961 static void ixgbe_i2c_stop(struct ixgbe_hw
*hw
)
1963 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
1964 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
1965 u32 clk_oe_bit
= IXGBE_I2C_CLK_OE_N_EN(hw
);
1966 u32 bb_en_bit
= IXGBE_I2C_BB_EN(hw
);
1968 /* Stop condition must begin with data low and clock high */
1969 ixgbe_set_i2c_data(hw
, &i2cctl
, 0);
1970 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
1972 /* Setup time for stop condition (4us) */
1973 udelay(IXGBE_I2C_T_SU_STO
);
1975 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
1977 /* bus free time between stop and start (4.7us)*/
1978 udelay(IXGBE_I2C_T_BUF
);
1980 if (bb_en_bit
|| data_oe_bit
|| clk_oe_bit
) {
1981 i2cctl
&= ~bb_en_bit
;
1982 i2cctl
|= data_oe_bit
| clk_oe_bit
;
1983 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
1984 IXGBE_WRITE_FLUSH(hw
);
1989 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1990 * @hw: pointer to hardware structure
1991 * @data: data byte to clock in
1993 * Clocks in one byte data via I2C data/clock
1995 static s32
ixgbe_clock_in_i2c_byte(struct ixgbe_hw
*hw
, u8
*data
)
2001 for (i
= 7; i
>= 0; i
--) {
2002 ixgbe_clock_in_i2c_bit(hw
, &bit
);
2010 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
2011 * @hw: pointer to hardware structure
2012 * @data: data byte clocked out
2014 * Clocks out one byte data via I2C data/clock
2016 static s32
ixgbe_clock_out_i2c_byte(struct ixgbe_hw
*hw
, u8 data
)
2023 for (i
= 7; i
>= 0; i
--) {
2024 bit
= (data
>> i
) & 0x1;
2025 status
= ixgbe_clock_out_i2c_bit(hw
, bit
);
2031 /* Release SDA line (set high) */
2032 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2033 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2034 i2cctl
|= IXGBE_I2C_DATA_OE_N_EN(hw
);
2035 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2036 IXGBE_WRITE_FLUSH(hw
);
2042 * ixgbe_get_i2c_ack - Polls for I2C ACK
2043 * @hw: pointer to hardware structure
2045 * Clocks in/out one bit via I2C data/clock
2047 static s32
ixgbe_get_i2c_ack(struct ixgbe_hw
*hw
)
2049 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2052 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2057 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2058 i2cctl
|= data_oe_bit
;
2059 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2060 IXGBE_WRITE_FLUSH(hw
);
2062 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2064 /* Minimum high period of clock is 4us */
2065 udelay(IXGBE_I2C_T_HIGH
);
2067 /* Poll for ACK. Note that ACK in I2C spec is
2068 * transition from 1 to 0 */
2069 for (i
= 0; i
< timeout
; i
++) {
2070 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2071 ack
= ixgbe_get_i2c_data(hw
, &i2cctl
);
2079 hw_dbg(hw
, "I2C ack was not received.\n");
2080 status
= IXGBE_ERR_I2C
;
2083 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2085 /* Minimum low period of clock is 4.7 us */
2086 udelay(IXGBE_I2C_T_LOW
);
2092 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
2093 * @hw: pointer to hardware structure
2094 * @data: read data value
2096 * Clocks in one bit via I2C data/clock
2098 static s32
ixgbe_clock_in_i2c_bit(struct ixgbe_hw
*hw
, bool *data
)
2100 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2101 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2104 i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2105 i2cctl
|= data_oe_bit
;
2106 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), i2cctl
);
2107 IXGBE_WRITE_FLUSH(hw
);
2109 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2111 /* Minimum high period of clock is 4us */
2112 udelay(IXGBE_I2C_T_HIGH
);
2114 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2115 *data
= ixgbe_get_i2c_data(hw
, &i2cctl
);
2117 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2119 /* Minimum low period of clock is 4.7 us */
2120 udelay(IXGBE_I2C_T_LOW
);
2126 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
2127 * @hw: pointer to hardware structure
2128 * @data: data value to write
2130 * Clocks out one bit via I2C data/clock
2132 static s32
ixgbe_clock_out_i2c_bit(struct ixgbe_hw
*hw
, bool data
)
2135 u32 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2137 status
= ixgbe_set_i2c_data(hw
, &i2cctl
, data
);
2139 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2141 /* Minimum high period of clock is 4us */
2142 udelay(IXGBE_I2C_T_HIGH
);
2144 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2146 /* Minimum low period of clock is 4.7 us.
2147 * This also takes care of the data hold time.
2149 udelay(IXGBE_I2C_T_LOW
);
2151 hw_dbg(hw
, "I2C data was not set to %X\n", data
);
2152 return IXGBE_ERR_I2C
;
2158 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2159 * @hw: pointer to hardware structure
2160 * @i2cctl: Current value of I2CCTL register
2162 * Raises the I2C clock line '0'->'1'
2163 * Negates the I2C clock output enable on X550 hardware.
2165 static void ixgbe_raise_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2167 u32 clk_oe_bit
= IXGBE_I2C_CLK_OE_N_EN(hw
);
2169 u32 timeout
= IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT
;
2173 *i2cctl
|= clk_oe_bit
;
2174 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2177 for (i
= 0; i
< timeout
; i
++) {
2178 *i2cctl
|= IXGBE_I2C_CLK_OUT(hw
);
2179 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2180 IXGBE_WRITE_FLUSH(hw
);
2181 /* SCL rise time (1000ns) */
2182 udelay(IXGBE_I2C_T_RISE
);
2184 i2cctl_r
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2185 if (i2cctl_r
& IXGBE_I2C_CLK_IN(hw
))
2191 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2192 * @hw: pointer to hardware structure
2193 * @i2cctl: Current value of I2CCTL register
2195 * Lowers the I2C clock line '1'->'0'
2196 * Asserts the I2C clock output enable on X550 hardware.
2198 static void ixgbe_lower_i2c_clk(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2201 *i2cctl
&= ~IXGBE_I2C_CLK_OUT(hw
);
2202 *i2cctl
&= ~IXGBE_I2C_CLK_OE_N_EN(hw
);
2204 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2205 IXGBE_WRITE_FLUSH(hw
);
2207 /* SCL fall time (300ns) */
2208 udelay(IXGBE_I2C_T_FALL
);
2212 * ixgbe_set_i2c_data - Sets the I2C data bit
2213 * @hw: pointer to hardware structure
2214 * @i2cctl: Current value of I2CCTL register
2215 * @data: I2C data value (0 or 1) to set
2217 * Sets the I2C data bit
2218 * Asserts the I2C data output enable on X550 hardware.
2220 static s32
ixgbe_set_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
, bool data
)
2222 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2225 *i2cctl
|= IXGBE_I2C_DATA_OUT(hw
);
2227 *i2cctl
&= ~IXGBE_I2C_DATA_OUT(hw
);
2228 *i2cctl
&= ~data_oe_bit
;
2230 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2231 IXGBE_WRITE_FLUSH(hw
);
2233 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2234 udelay(IXGBE_I2C_T_RISE
+ IXGBE_I2C_T_FALL
+ IXGBE_I2C_T_SU_DATA
);
2236 if (!data
) /* Can't verify data in this case */
2239 *i2cctl
|= data_oe_bit
;
2240 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2241 IXGBE_WRITE_FLUSH(hw
);
2244 /* Verify data was set correctly */
2245 *i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2246 if (data
!= ixgbe_get_i2c_data(hw
, i2cctl
)) {
2247 hw_dbg(hw
, "Error - I2C data was not set to %X.\n", data
);
2248 return IXGBE_ERR_I2C
;
2255 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2256 * @hw: pointer to hardware structure
2257 * @i2cctl: Current value of I2CCTL register
2259 * Returns the I2C data bit value
2260 * Negates the I2C data output enable on X550 hardware.
2262 static bool ixgbe_get_i2c_data(struct ixgbe_hw
*hw
, u32
*i2cctl
)
2264 u32 data_oe_bit
= IXGBE_I2C_DATA_OE_N_EN(hw
);
2267 *i2cctl
|= data_oe_bit
;
2268 IXGBE_WRITE_REG(hw
, IXGBE_I2CCTL(hw
), *i2cctl
);
2269 IXGBE_WRITE_FLUSH(hw
);
2270 udelay(IXGBE_I2C_T_FALL
);
2273 if (*i2cctl
& IXGBE_I2C_DATA_IN(hw
))
2279 * ixgbe_i2c_bus_clear - Clears the I2C bus
2280 * @hw: pointer to hardware structure
2282 * Clears the I2C bus by sending nine clock pulses.
2283 * Used when data line is stuck low.
2285 static void ixgbe_i2c_bus_clear(struct ixgbe_hw
*hw
)
2290 ixgbe_i2c_start(hw
);
2291 i2cctl
= IXGBE_READ_REG(hw
, IXGBE_I2CCTL(hw
));
2293 ixgbe_set_i2c_data(hw
, &i2cctl
, 1);
2295 for (i
= 0; i
< 9; i
++) {
2296 ixgbe_raise_i2c_clk(hw
, &i2cctl
);
2298 /* Min high period of clock is 4us */
2299 udelay(IXGBE_I2C_T_HIGH
);
2301 ixgbe_lower_i2c_clk(hw
, &i2cctl
);
2303 /* Min low period of clock is 4.7us*/
2304 udelay(IXGBE_I2C_T_LOW
);
2307 ixgbe_i2c_start(hw
);
2309 /* Put the i2c bus back to default state */
2314 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
2315 * @hw: pointer to hardware structure
2317 * Checks if the LASI temp alarm status was triggered due to overtemp
2319 s32
ixgbe_tn_check_overtemp(struct ixgbe_hw
*hw
)
2323 if (hw
->device_id
!= IXGBE_DEV_ID_82599_T3_LOM
)
2326 /* Check that the LASI temp alarm status was triggered */
2327 hw
->phy
.ops
.read_reg(hw
, IXGBE_TN_LASI_STATUS_REG
,
2328 MDIO_MMD_PMAPMD
, &phy_data
);
2330 if (!(phy_data
& IXGBE_TN_LASI_STATUS_TEMP_ALARM
))
2333 return IXGBE_ERR_OVERTEMP
;
2336 /** ixgbe_set_copper_phy_power - Control power for copper phy
2337 * @hw: pointer to hardware structure
2338 * @on: true for on, false for off
2340 s32
ixgbe_set_copper_phy_power(struct ixgbe_hw
*hw
, bool on
)
2345 /* Bail if we don't have copper phy */
2346 if (hw
->mac
.ops
.get_media_type(hw
) != ixgbe_media_type_copper
)
2349 if (!on
&& ixgbe_mng_present(hw
))
2352 status
= hw
->phy
.ops
.read_reg(hw
, MDIO_CTRL1
, MDIO_MMD_VEND1
, ®
);
2357 reg
&= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE
;
2359 if (ixgbe_check_reset_blocked(hw
))
2361 reg
|= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE
;
2364 status
= hw
->phy
.ops
.write_reg(hw
, MDIO_CTRL1
, MDIO_MMD_VEND1
, reg
);