1 /******************************************************************************
3 Copyright (c) 2001-2014, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 #include "ixgbe_api.h"
36 #include "ixgbe_common.h"
37 #include "ixgbe_phy.h"
39 static void ixgbe_i2c_start(struct ixgbe_hw *hw);
40 static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
41 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
42 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
43 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
44 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
45 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
46 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
47 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
48 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
49 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
50 static s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
54 * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
55 * @hw: pointer to the hardware structure
58 * Returns an error code on error.
60 static s32 ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
64 status = ixgbe_clock_out_i2c_byte(hw, byte);
67 return ixgbe_get_i2c_ack(hw);
71 * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
72 * @hw: pointer to the hardware structure
73 * @byte: pointer to a u8 to receive the byte
75 * Returns an error code on error.
77 static s32 ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
81 status = ixgbe_clock_in_i2c_byte(hw, byte);
85 return ixgbe_clock_out_i2c_bit(hw, FALSE);
89 * ixgbe_ones_comp_byte_add - Perform one's complement addition
93 * Returns one's complement 8-bit sum.
95 static u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
97 u16 sum = add1 + add2;
99 sum = (sum & 0xFF) + (sum >> 8);
104 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
105 * @hw: pointer to the hardware structure
106 * @addr: I2C bus address to read from
107 * @reg: I2C device register to read from
108 * @val: pointer to location to receive read value
110 * Returns an error code on error.
112 static s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
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 (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))
161 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
162 *val = (high_bits << 8) | low_bits;
166 ixgbe_i2c_bus_clear(hw);
167 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
169 if (retry < max_retry)
170 DEBUGOUT("I2C byte read combined error - Retrying.\n");
172 DEBUGOUT("I2C byte read combined error.\n");
173 } while (retry < max_retry);
175 return IXGBE_ERR_I2C;
179 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
180 * @hw: pointer to the hardware structure
181 * @addr: I2C bus address to write to
182 * @reg: I2C device register to write to
183 * @val: value to write
185 * Returns an error code on error.
187 static s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
188 u8 addr, u16 reg, u16 val)
195 reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
196 csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
197 csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
198 csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
202 /* Device Address and write indication */
203 if (ixgbe_out_i2c_byte_ack(hw, addr))
205 /* Write bits 14:8 */
206 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
209 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
211 /* Write data 15:8 */
212 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
215 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
218 if (ixgbe_out_i2c_byte_ack(hw, csum))
224 ixgbe_i2c_bus_clear(hw);
226 if (retry < max_retry)
227 DEBUGOUT("I2C byte write combined error - Retrying.\n");
229 DEBUGOUT("I2C byte write combined error.\n");
230 } while (retry < max_retry);
232 return IXGBE_ERR_I2C;
236 * ixgbe_init_phy_ops_generic - Inits PHY function ptrs
237 * @hw: pointer to the hardware structure
239 * Initialize the function pointers.
241 s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
243 struct ixgbe_phy_info *phy = &hw->phy;
245 DEBUGFUNC("ixgbe_init_phy_ops_generic");
248 phy->ops.identify = ixgbe_identify_phy_generic;
249 phy->ops.reset = ixgbe_reset_phy_generic;
250 phy->ops.read_reg = ixgbe_read_phy_reg_generic;
251 phy->ops.write_reg = ixgbe_write_phy_reg_generic;
252 phy->ops.read_reg_mdi = ixgbe_read_phy_reg_mdi;
253 phy->ops.write_reg_mdi = ixgbe_write_phy_reg_mdi;
254 phy->ops.setup_link = ixgbe_setup_phy_link_generic;
255 phy->ops.setup_link_speed = ixgbe_setup_phy_link_speed_generic;
256 phy->ops.check_link = NULL;
257 phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
258 phy->ops.read_i2c_byte = ixgbe_read_i2c_byte_generic;
259 phy->ops.write_i2c_byte = ixgbe_write_i2c_byte_generic;
260 phy->ops.read_i2c_sff8472 = ixgbe_read_i2c_sff8472_generic;
261 phy->ops.read_i2c_eeprom = ixgbe_read_i2c_eeprom_generic;
262 phy->ops.write_i2c_eeprom = ixgbe_write_i2c_eeprom_generic;
263 phy->ops.i2c_bus_clear = ixgbe_i2c_bus_clear;
264 phy->ops.identify_sfp = ixgbe_identify_module_generic;
265 phy->sfp_type = ixgbe_sfp_type_unknown;
266 phy->ops.read_i2c_combined = ixgbe_read_i2c_combined_generic;
267 phy->ops.write_i2c_combined = ixgbe_write_i2c_combined_generic;
268 phy->ops.check_overtemp = ixgbe_tn_check_overtemp;
269 return IXGBE_SUCCESS;
273 * ixgbe_identify_phy_generic - Get physical layer module
274 * @hw: pointer to hardware structure
276 * Determines the physical layer module found on the current adapter.
278 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
280 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
284 DEBUGFUNC("ixgbe_identify_phy_generic");
286 if (!hw->phy.phy_semaphore_mask) {
288 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
290 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
293 if (hw->phy.type == ixgbe_phy_unknown) {
294 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
295 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
296 hw->phy.addr = phy_addr;
297 ixgbe_get_phy_id(hw);
299 ixgbe_get_phy_type_from_id(hw->phy.id);
301 if (hw->phy.type == ixgbe_phy_unknown) {
302 hw->phy.ops.read_reg(hw,
303 IXGBE_MDIO_PHY_EXT_ABILITY,
304 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
307 (IXGBE_MDIO_PHY_10GBASET_ABILITY |
308 IXGBE_MDIO_PHY_1000BASET_ABILITY))
310 ixgbe_phy_cu_unknown;
316 status = IXGBE_SUCCESS;
321 /* Certain media types do not have a phy so an address will not
322 * be found and the code will take this path. Caller has to
323 * decide if it is an error or not.
325 if (status != IXGBE_SUCCESS) {
329 status = IXGBE_SUCCESS;
336 * ixgbe_check_reset_blocked - check status of MNG FW veto bit
337 * @hw: pointer to the hardware structure
339 * This function checks the MMNGC.MNG_VETO bit to see if there are
340 * any constraints on link from manageability. For MAC's that don't
341 * have this bit just return faluse since the link can not be blocked
344 s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
348 DEBUGFUNC("ixgbe_check_reset_blocked");
350 /* If we don't have this bit, it can't be blocking */
351 if (hw->mac.type == ixgbe_mac_82598EB)
354 mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
355 if (mmngc & IXGBE_MMNGC_MNG_VETO) {
356 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
357 "MNG_VETO bit detected.\n");
365 * ixgbe_validate_phy_addr - Determines phy address is valid
366 * @hw: pointer to hardware structure
369 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
374 DEBUGFUNC("ixgbe_validate_phy_addr");
376 hw->phy.addr = phy_addr;
377 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
378 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
380 if (phy_id != 0xFFFF && phy_id != 0x0)
387 * ixgbe_get_phy_id - Get the phy type
388 * @hw: pointer to hardware structure
391 s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
397 DEBUGFUNC("ixgbe_get_phy_id");
399 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
400 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
403 if (status == IXGBE_SUCCESS) {
404 hw->phy.id = (u32)(phy_id_high << 16);
405 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
406 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
408 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
409 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
415 * ixgbe_get_phy_type_from_id - Get the phy type
416 * @hw: pointer to hardware structure
419 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
421 enum ixgbe_phy_type phy_type;
423 DEBUGFUNC("ixgbe_get_phy_type_from_id");
427 phy_type = ixgbe_phy_tn;
431 phy_type = ixgbe_phy_aq;
434 phy_type = ixgbe_phy_qt;
437 phy_type = ixgbe_phy_nl;
440 phy_type = ixgbe_phy_x550em_ext_t;
443 phy_type = ixgbe_phy_unknown;
447 DEBUGOUT1("phy type found is %d\n", phy_type);
452 * ixgbe_reset_phy_generic - Performs a PHY reset
453 * @hw: pointer to hardware structure
455 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
459 s32 status = IXGBE_SUCCESS;
461 DEBUGFUNC("ixgbe_reset_phy_generic");
463 if (hw->phy.type == ixgbe_phy_unknown)
464 status = ixgbe_identify_phy_generic(hw);
466 if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
469 /* Don't reset PHY if it's shut down due to overtemp. */
470 if (!hw->phy.reset_if_overtemp &&
471 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
474 /* Blocked by MNG FW so bail */
475 if (ixgbe_check_reset_blocked(hw))
479 * Perform soft PHY reset to the PHY_XS.
480 * This will cause a soft reset to the PHY
482 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
483 IXGBE_MDIO_PHY_XS_DEV_TYPE,
484 IXGBE_MDIO_PHY_XS_RESET);
487 * Poll for reset bit to self-clear indicating reset is complete.
488 * Some PHYs could take up to 3 seconds to complete and need about
489 * 1.7 usec delay after the reset is complete.
491 for (i = 0; i < 30; i++) {
493 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
494 IXGBE_MDIO_PHY_XS_DEV_TYPE, &ctrl);
495 if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
501 if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
502 status = IXGBE_ERR_RESET_FAILED;
503 ERROR_REPORT1(IXGBE_ERROR_POLLING,
504 "PHY reset polling failed to complete.\n");
512 * ixgbe_read_phy_mdi - Reads a value from a specified PHY register without
514 * @hw: pointer to hardware structure
515 * @reg_addr: 32 bit address of PHY register to read
516 * @phy_data: Pointer to read data from PHY register
518 s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
521 u32 i, data, command;
523 /* Setup and write the address cycle command */
524 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
525 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
526 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
527 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
529 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
532 * Check every 10 usec to see if the address cycle completed.
533 * The MDI Command bit will clear when the operation is
536 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
539 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
540 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
545 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
546 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address command did not complete.\n");
547 return IXGBE_ERR_PHY;
551 * Address cycle complete, setup and write the read
554 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
555 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
556 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
557 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
559 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
562 * Check every 10 usec to see if the address cycle
563 * completed. The MDI Command bit will clear when the
564 * operation is complete
566 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
569 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
570 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
574 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
575 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY read command didn't complete\n");
576 return IXGBE_ERR_PHY;
580 * Read operation is complete. Get the data
583 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
584 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
585 *phy_data = (u16)(data);
587 return IXGBE_SUCCESS;
591 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
592 * using the SWFW lock - this function is needed in most cases
593 * @hw: pointer to hardware structure
594 * @reg_addr: 32 bit address of PHY register to read
595 * @phy_data: Pointer to read data from PHY register
597 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
598 u32 device_type, u16 *phy_data)
601 u32 gssr = hw->phy.phy_semaphore_mask;
603 DEBUGFUNC("ixgbe_read_phy_reg_generic");
605 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
606 status = ixgbe_read_phy_reg_mdi(hw, reg_addr, device_type,
608 hw->mac.ops.release_swfw_sync(hw, gssr);
610 status = IXGBE_ERR_SWFW_SYNC;
617 * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
619 * @hw: pointer to hardware structure
620 * @reg_addr: 32 bit PHY register to write
621 * @device_type: 5 bit device type
622 * @phy_data: Data to write to the PHY register
624 s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
625 u32 device_type, u16 phy_data)
629 /* Put the data in the MDI single read and write data register*/
630 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
632 /* Setup and write the address cycle command */
633 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
634 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
635 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
636 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
638 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
641 * Check every 10 usec to see if the address cycle completed.
642 * The MDI Command bit will clear when the operation is
645 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
648 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
649 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
653 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
654 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address cmd didn't complete\n");
655 return IXGBE_ERR_PHY;
659 * Address cycle complete, setup and write the write
662 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
663 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
664 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
665 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
667 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
670 * Check every 10 usec to see if the address cycle
671 * completed. The MDI Command bit will clear when the
672 * operation is complete
674 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
677 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
678 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
682 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
683 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY write cmd didn't complete\n");
684 return IXGBE_ERR_PHY;
687 return IXGBE_SUCCESS;
691 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
692 * using SWFW lock- this function is needed in most cases
693 * @hw: pointer to hardware structure
694 * @reg_addr: 32 bit PHY register to write
695 * @device_type: 5 bit device type
696 * @phy_data: Data to write to the PHY register
698 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
699 u32 device_type, u16 phy_data)
702 u32 gssr = hw->phy.phy_semaphore_mask;
704 DEBUGFUNC("ixgbe_write_phy_reg_generic");
706 if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
707 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type,
709 hw->mac.ops.release_swfw_sync(hw, gssr);
711 status = IXGBE_ERR_SWFW_SYNC;
718 * ixgbe_setup_phy_link_generic - Set and restart auto-neg
719 * @hw: pointer to hardware structure
721 * Restart auto-negotiation and PHY and waits for completion.
723 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
725 s32 status = IXGBE_SUCCESS;
726 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
727 bool autoneg = FALSE;
728 ixgbe_link_speed speed;
730 DEBUGFUNC("ixgbe_setup_phy_link_generic");
732 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
734 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
735 /* Set or unset auto-negotiation 10G advertisement */
736 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
737 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
740 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
741 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
742 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
744 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
745 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
749 if (hw->mac.type == ixgbe_mac_X550) {
750 if (speed & IXGBE_LINK_SPEED_5GB_FULL) {
751 /* Set or unset auto-negotiation 1G advertisement */
752 hw->phy.ops.read_reg(hw,
753 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
754 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
757 autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
758 if (hw->phy.autoneg_advertised &
759 IXGBE_LINK_SPEED_5GB_FULL)
760 autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
762 hw->phy.ops.write_reg(hw,
763 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
764 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
768 if (speed & IXGBE_LINK_SPEED_2_5GB_FULL) {
769 /* Set or unset auto-negotiation 1G advertisement */
770 hw->phy.ops.read_reg(hw,
771 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
772 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
775 autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
776 if (hw->phy.autoneg_advertised &
777 IXGBE_LINK_SPEED_2_5GB_FULL)
778 autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
780 hw->phy.ops.write_reg(hw,
781 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
782 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
787 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
788 /* Set or unset auto-negotiation 1G advertisement */
789 hw->phy.ops.read_reg(hw,
790 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
791 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
794 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
795 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
796 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
798 hw->phy.ops.write_reg(hw,
799 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
800 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
804 if (speed & IXGBE_LINK_SPEED_100_FULL) {
805 /* Set or unset auto-negotiation 100M advertisement */
806 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
807 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
810 autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
811 IXGBE_MII_100BASE_T_ADVERTISE_HALF);
812 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
813 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
815 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
816 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
820 /* Blocked by MNG FW so don't reset PHY */
821 if (ixgbe_check_reset_blocked(hw))
824 /* Restart PHY auto-negotiation. */
825 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
826 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
828 autoneg_reg |= IXGBE_MII_RESTART;
830 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
831 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
837 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
838 * @hw: pointer to hardware structure
839 * @speed: new link speed
841 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
842 ixgbe_link_speed speed,
843 bool autoneg_wait_to_complete)
845 UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
847 DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
850 * Clear autoneg_advertised and set new values based on input link
853 hw->phy.autoneg_advertised = 0;
855 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
856 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
858 if (speed & IXGBE_LINK_SPEED_5GB_FULL)
859 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_5GB_FULL;
861 if (speed & IXGBE_LINK_SPEED_2_5GB_FULL)
862 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_2_5GB_FULL;
864 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
865 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
867 if (speed & IXGBE_LINK_SPEED_100_FULL)
868 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
870 /* Setup link based on the new speed settings */
871 hw->phy.ops.setup_link(hw);
873 return IXGBE_SUCCESS;
877 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
878 * @hw: pointer to hardware structure
879 * @speed: pointer to link speed
880 * @autoneg: boolean auto-negotiation value
882 * Determines the supported link capabilities by reading the PHY auto
883 * negotiation register.
885 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
886 ixgbe_link_speed *speed,
892 DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
897 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
898 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
901 if (status == IXGBE_SUCCESS) {
902 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
903 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
904 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
905 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
906 if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
907 *speed |= IXGBE_LINK_SPEED_100_FULL;
910 /* Internal PHY does not support 100 Mbps */
911 if (hw->mac.type == ixgbe_mac_X550EM_x)
912 *speed &= ~IXGBE_LINK_SPEED_100_FULL;
914 if (hw->mac.type == ixgbe_mac_X550) {
915 *speed |= IXGBE_LINK_SPEED_2_5GB_FULL;
916 *speed |= IXGBE_LINK_SPEED_5GB_FULL;
923 * ixgbe_check_phy_link_tnx - Determine link and speed status
924 * @hw: pointer to hardware structure
926 * Reads the VS1 register to determine if link is up and the current speed for
929 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
932 s32 status = IXGBE_SUCCESS;
934 u32 max_time_out = 10;
939 DEBUGFUNC("ixgbe_check_phy_link_tnx");
941 /* Initialize speed and link to default case */
943 *speed = IXGBE_LINK_SPEED_10GB_FULL;
946 * Check current speed and link status of the PHY register.
947 * This is a vendor specific register and may have to
948 * be changed for other copper PHYs.
950 for (time_out = 0; time_out < max_time_out; time_out++) {
952 status = hw->phy.ops.read_reg(hw,
953 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
954 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
956 phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
957 phy_speed = phy_data &
958 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
959 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
962 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
963 *speed = IXGBE_LINK_SPEED_1GB_FULL;
972 * ixgbe_setup_phy_link_tnx - Set and restart auto-neg
973 * @hw: pointer to hardware structure
975 * Restart auto-negotiation and PHY and waits for completion.
977 s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
979 s32 status = IXGBE_SUCCESS;
980 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
981 bool autoneg = FALSE;
982 ixgbe_link_speed speed;
984 DEBUGFUNC("ixgbe_setup_phy_link_tnx");
986 ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
988 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
989 /* Set or unset auto-negotiation 10G advertisement */
990 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
991 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
994 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
995 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
996 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
998 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
999 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1003 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
1004 /* Set or unset auto-negotiation 1G advertisement */
1005 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
1006 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1009 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
1010 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
1011 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
1013 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
1014 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1018 if (speed & IXGBE_LINK_SPEED_100_FULL) {
1019 /* Set or unset auto-negotiation 100M advertisement */
1020 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
1021 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1024 autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
1025 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
1026 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
1028 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
1029 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1033 /* Blocked by MNG FW so don't reset PHY */
1034 if (ixgbe_check_reset_blocked(hw))
1037 /* Restart PHY auto-negotiation. */
1038 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
1039 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
1041 autoneg_reg |= IXGBE_MII_RESTART;
1043 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
1044 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
1050 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
1051 * @hw: pointer to hardware structure
1052 * @firmware_version: pointer to the PHY Firmware Version
1054 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1055 u16 *firmware_version)
1059 DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
1061 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
1062 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1069 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
1070 * @hw: pointer to hardware structure
1071 * @firmware_version: pointer to the PHY Firmware Version
1073 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
1074 u16 *firmware_version)
1078 DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
1080 status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
1081 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1088 * ixgbe_reset_phy_nl - Performs a PHY reset
1089 * @hw: pointer to hardware structure
1091 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
1093 u16 phy_offset, control, eword, edata, block_crc;
1094 bool end_data = FALSE;
1095 u16 list_offset, data_offset;
1097 s32 ret_val = IXGBE_SUCCESS;
1100 DEBUGFUNC("ixgbe_reset_phy_nl");
1102 /* Blocked by MNG FW so bail */
1103 if (ixgbe_check_reset_blocked(hw))
1106 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
1107 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
1109 /* reset the PHY and poll for completion */
1110 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
1111 IXGBE_MDIO_PHY_XS_DEV_TYPE,
1112 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
1114 for (i = 0; i < 100; i++) {
1115 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
1116 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
1117 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
1122 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
1123 DEBUGOUT("PHY reset did not complete.\n");
1124 ret_val = IXGBE_ERR_PHY;
1128 /* Get init offsets */
1129 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
1131 if (ret_val != IXGBE_SUCCESS)
1134 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
1138 * Read control word from PHY init contents offset
1140 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
1143 control = (eword & IXGBE_CONTROL_MASK_NL) >>
1144 IXGBE_CONTROL_SHIFT_NL;
1145 edata = eword & IXGBE_DATA_MASK_NL;
1147 case IXGBE_DELAY_NL:
1149 DEBUGOUT1("DELAY: %d MS\n", edata);
1153 DEBUGOUT("DATA:\n");
1155 ret_val = hw->eeprom.ops.read(hw, data_offset,
1160 for (i = 0; i < edata; i++) {
1161 ret_val = hw->eeprom.ops.read(hw, data_offset,
1165 hw->phy.ops.write_reg(hw, phy_offset,
1166 IXGBE_TWINAX_DEV, eword);
1167 DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
1173 case IXGBE_CONTROL_NL:
1175 DEBUGOUT("CONTROL:\n");
1176 if (edata == IXGBE_CONTROL_EOL_NL) {
1179 } else if (edata == IXGBE_CONTROL_SOL_NL) {
1182 DEBUGOUT("Bad control value\n");
1183 ret_val = IXGBE_ERR_PHY;
1188 DEBUGOUT("Bad control type\n");
1189 ret_val = IXGBE_ERR_PHY;
1198 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1199 "eeprom read at offset %d failed", data_offset);
1200 return IXGBE_ERR_PHY;
1204 * ixgbe_identify_module_generic - Identifies module type
1205 * @hw: pointer to hardware structure
1207 * Determines HW type and calls appropriate function.
1209 s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
1211 s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
1213 DEBUGFUNC("ixgbe_identify_module_generic");
1215 switch (hw->mac.ops.get_media_type(hw)) {
1216 case ixgbe_media_type_fiber:
1217 status = ixgbe_identify_sfp_module_generic(hw);
1220 case ixgbe_media_type_fiber_qsfp:
1221 status = ixgbe_identify_qsfp_module_generic(hw);
1225 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1226 status = IXGBE_ERR_SFP_NOT_PRESENT;
1234 * ixgbe_identify_sfp_module_generic - Identifies SFP modules
1235 * @hw: pointer to hardware structure
1237 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1239 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
1241 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1243 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1245 u8 comp_codes_1g = 0;
1246 u8 comp_codes_10g = 0;
1247 u8 oui_bytes[3] = {0, 0, 0};
1250 u16 enforce_sfp = 0;
1252 DEBUGFUNC("ixgbe_identify_sfp_module_generic");
1254 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
1255 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1256 status = IXGBE_ERR_SFP_NOT_PRESENT;
1260 /* LAN ID is needed for I2C access */
1261 hw->mac.ops.set_lan_id(hw);
1263 status = hw->phy.ops.read_i2c_eeprom(hw,
1264 IXGBE_SFF_IDENTIFIER,
1267 if (status != IXGBE_SUCCESS)
1268 goto err_read_i2c_eeprom;
1270 if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
1271 hw->phy.type = ixgbe_phy_sfp_unsupported;
1272 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1274 status = hw->phy.ops.read_i2c_eeprom(hw,
1275 IXGBE_SFF_1GBE_COMP_CODES,
1278 if (status != IXGBE_SUCCESS)
1279 goto err_read_i2c_eeprom;
1281 status = hw->phy.ops.read_i2c_eeprom(hw,
1282 IXGBE_SFF_10GBE_COMP_CODES,
1285 if (status != IXGBE_SUCCESS)
1286 goto err_read_i2c_eeprom;
1287 status = hw->phy.ops.read_i2c_eeprom(hw,
1288 IXGBE_SFF_CABLE_TECHNOLOGY,
1291 if (status != IXGBE_SUCCESS)
1292 goto err_read_i2c_eeprom;
1299 * 3 SFP_DA_CORE0 - 82599-specific
1300 * 4 SFP_DA_CORE1 - 82599-specific
1301 * 5 SFP_SR/LR_CORE0 - 82599-specific
1302 * 6 SFP_SR/LR_CORE1 - 82599-specific
1303 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
1304 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
1305 * 9 SFP_1g_cu_CORE0 - 82599-specific
1306 * 10 SFP_1g_cu_CORE1 - 82599-specific
1307 * 11 SFP_1g_sx_CORE0 - 82599-specific
1308 * 12 SFP_1g_sx_CORE1 - 82599-specific
1310 if (hw->mac.type == ixgbe_mac_82598EB) {
1311 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1312 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
1313 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1314 hw->phy.sfp_type = ixgbe_sfp_type_sr;
1315 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1316 hw->phy.sfp_type = ixgbe_sfp_type_lr;
1318 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1320 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
1321 if (hw->bus.lan_id == 0)
1323 ixgbe_sfp_type_da_cu_core0;
1326 ixgbe_sfp_type_da_cu_core1;
1327 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
1328 hw->phy.ops.read_i2c_eeprom(
1329 hw, IXGBE_SFF_CABLE_SPEC_COMP,
1332 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
1333 if (hw->bus.lan_id == 0)
1335 ixgbe_sfp_type_da_act_lmt_core0;
1338 ixgbe_sfp_type_da_act_lmt_core1;
1341 ixgbe_sfp_type_unknown;
1343 } else if (comp_codes_10g &
1344 (IXGBE_SFF_10GBASESR_CAPABLE |
1345 IXGBE_SFF_10GBASELR_CAPABLE)) {
1346 if (hw->bus.lan_id == 0)
1348 ixgbe_sfp_type_srlr_core0;
1351 ixgbe_sfp_type_srlr_core1;
1352 } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
1353 if (hw->bus.lan_id == 0)
1355 ixgbe_sfp_type_1g_cu_core0;
1358 ixgbe_sfp_type_1g_cu_core1;
1359 } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
1360 if (hw->bus.lan_id == 0)
1362 ixgbe_sfp_type_1g_sx_core0;
1365 ixgbe_sfp_type_1g_sx_core1;
1367 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
1371 if (hw->phy.sfp_type != stored_sfp_type)
1372 hw->phy.sfp_setup_needed = TRUE;
1374 /* Determine if the SFP+ PHY is dual speed or not. */
1375 hw->phy.multispeed_fiber = FALSE;
1376 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1377 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1378 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1379 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1380 hw->phy.multispeed_fiber = TRUE;
1382 /* Determine PHY vendor */
1383 if (hw->phy.type != ixgbe_phy_nl) {
1384 hw->phy.id = identifier;
1385 status = hw->phy.ops.read_i2c_eeprom(hw,
1386 IXGBE_SFF_VENDOR_OUI_BYTE0,
1389 if (status != IXGBE_SUCCESS)
1390 goto err_read_i2c_eeprom;
1392 status = hw->phy.ops.read_i2c_eeprom(hw,
1393 IXGBE_SFF_VENDOR_OUI_BYTE1,
1396 if (status != IXGBE_SUCCESS)
1397 goto err_read_i2c_eeprom;
1399 status = hw->phy.ops.read_i2c_eeprom(hw,
1400 IXGBE_SFF_VENDOR_OUI_BYTE2,
1403 if (status != IXGBE_SUCCESS)
1404 goto err_read_i2c_eeprom;
1407 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1408 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1409 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1411 switch (vendor_oui) {
1412 case IXGBE_SFF_VENDOR_OUI_TYCO:
1413 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1415 ixgbe_phy_sfp_passive_tyco;
1417 case IXGBE_SFF_VENDOR_OUI_FTL:
1418 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1419 hw->phy.type = ixgbe_phy_sfp_ftl_active;
1421 hw->phy.type = ixgbe_phy_sfp_ftl;
1423 case IXGBE_SFF_VENDOR_OUI_AVAGO:
1424 hw->phy.type = ixgbe_phy_sfp_avago;
1426 case IXGBE_SFF_VENDOR_OUI_INTEL:
1427 hw->phy.type = ixgbe_phy_sfp_intel;
1430 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
1432 ixgbe_phy_sfp_passive_unknown;
1433 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
1435 ixgbe_phy_sfp_active_unknown;
1437 hw->phy.type = ixgbe_phy_sfp_unknown;
1442 /* Allow any DA cable vendor */
1443 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
1444 IXGBE_SFF_DA_ACTIVE_CABLE)) {
1445 status = IXGBE_SUCCESS;
1449 /* Verify supported 1G SFP modules */
1450 if (comp_codes_10g == 0 &&
1451 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1452 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1453 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1454 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1455 hw->phy.type = ixgbe_phy_sfp_unsupported;
1456 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1460 /* Anything else 82598-based is supported */
1461 if (hw->mac.type == ixgbe_mac_82598EB) {
1462 status = IXGBE_SUCCESS;
1466 ixgbe_get_device_caps(hw, &enforce_sfp);
1467 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
1468 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1469 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1470 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1471 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
1472 /* Make sure we're a supported PHY type */
1473 if (hw->phy.type == ixgbe_phy_sfp_intel) {
1474 status = IXGBE_SUCCESS;
1476 if (hw->allow_unsupported_sfp == TRUE) {
1477 EWARN(hw, "WARNING: Intel (R) Network "
1478 "Connections are quality tested "
1479 "using Intel (R) Ethernet Optics."
1480 " Using untested modules is not "
1481 "supported and may cause unstable"
1482 " operation or damage to the "
1483 "module or the adapter. Intel "
1484 "Corporation is not responsible "
1485 "for any harm caused by using "
1486 "untested modules.\n", status);
1487 status = IXGBE_SUCCESS;
1489 DEBUGOUT("SFP+ module not supported\n");
1491 ixgbe_phy_sfp_unsupported;
1492 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1496 status = IXGBE_SUCCESS;
1503 err_read_i2c_eeprom:
1504 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1505 if (hw->phy.type != ixgbe_phy_nl) {
1507 hw->phy.type = ixgbe_phy_unknown;
1509 return IXGBE_ERR_SFP_NOT_PRESENT;
1513 * ixgbe_get_supported_phy_sfp_layer_generic - Returns physical layer type
1514 * @hw: pointer to hardware structure
1516 * Determines physical layer capabilities of the current SFP.
1518 s32 ixgbe_get_supported_phy_sfp_layer_generic(struct ixgbe_hw *hw)
1520 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1521 u8 comp_codes_10g = 0;
1522 u8 comp_codes_1g = 0;
1524 DEBUGFUNC("ixgbe_get_supported_phy_sfp_layer_generic");
1526 hw->phy.ops.identify_sfp(hw);
1527 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1528 return physical_layer;
1530 switch (hw->phy.type) {
1531 case ixgbe_phy_sfp_passive_tyco:
1532 case ixgbe_phy_sfp_passive_unknown:
1533 case ixgbe_phy_qsfp_passive_unknown:
1534 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1536 case ixgbe_phy_sfp_ftl_active:
1537 case ixgbe_phy_sfp_active_unknown:
1538 case ixgbe_phy_qsfp_active_unknown:
1539 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
1541 case ixgbe_phy_sfp_avago:
1542 case ixgbe_phy_sfp_ftl:
1543 case ixgbe_phy_sfp_intel:
1544 case ixgbe_phy_sfp_unknown:
1545 hw->phy.ops.read_i2c_eeprom(hw,
1546 IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
1547 hw->phy.ops.read_i2c_eeprom(hw,
1548 IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
1549 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1550 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1551 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1552 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1553 else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
1554 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
1555 else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE)
1556 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_SX;
1558 case ixgbe_phy_qsfp_intel:
1559 case ixgbe_phy_qsfp_unknown:
1560 hw->phy.ops.read_i2c_eeprom(hw,
1561 IXGBE_SFF_QSFP_10GBE_COMP, &comp_codes_10g);
1562 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1563 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1564 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1565 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1571 return physical_layer;
1575 * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
1576 * @hw: pointer to hardware structure
1578 * Searches for and identifies the QSFP module and assigns appropriate PHY type
1580 s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
1582 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1584 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1586 u8 comp_codes_1g = 0;
1587 u8 comp_codes_10g = 0;
1588 u8 oui_bytes[3] = {0, 0, 0};
1589 u16 enforce_sfp = 0;
1591 u8 cable_length = 0;
1593 bool active_cable = FALSE;
1595 DEBUGFUNC("ixgbe_identify_qsfp_module_generic");
1597 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
1598 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1599 status = IXGBE_ERR_SFP_NOT_PRESENT;
1603 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
1606 if (status != IXGBE_SUCCESS)
1607 goto err_read_i2c_eeprom;
1609 if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1610 hw->phy.type = ixgbe_phy_sfp_unsupported;
1611 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1615 hw->phy.id = identifier;
1617 /* LAN ID is needed for sfp_type determination */
1618 hw->mac.ops.set_lan_id(hw);
1620 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
1623 if (status != IXGBE_SUCCESS)
1624 goto err_read_i2c_eeprom;
1626 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
1629 if (status != IXGBE_SUCCESS)
1630 goto err_read_i2c_eeprom;
1632 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1633 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
1634 if (hw->bus.lan_id == 0)
1635 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
1637 hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
1638 } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1639 IXGBE_SFF_10GBASELR_CAPABLE)) {
1640 if (hw->bus.lan_id == 0)
1641 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
1643 hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
1645 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1646 active_cable = TRUE;
1648 if (!active_cable) {
1649 /* check for active DA cables that pre-date
1651 hw->phy.ops.read_i2c_eeprom(hw,
1652 IXGBE_SFF_QSFP_CONNECTOR,
1655 hw->phy.ops.read_i2c_eeprom(hw,
1656 IXGBE_SFF_QSFP_CABLE_LENGTH,
1659 hw->phy.ops.read_i2c_eeprom(hw,
1660 IXGBE_SFF_QSFP_DEVICE_TECH,
1664 IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
1665 (cable_length > 0) &&
1666 ((device_tech >> 4) ==
1667 IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
1668 active_cable = TRUE;
1672 hw->phy.type = ixgbe_phy_qsfp_active_unknown;
1673 if (hw->bus.lan_id == 0)
1675 ixgbe_sfp_type_da_act_lmt_core0;
1678 ixgbe_sfp_type_da_act_lmt_core1;
1680 /* unsupported module type */
1681 hw->phy.type = ixgbe_phy_sfp_unsupported;
1682 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1687 if (hw->phy.sfp_type != stored_sfp_type)
1688 hw->phy.sfp_setup_needed = TRUE;
1690 /* Determine if the QSFP+ PHY is dual speed or not. */
1691 hw->phy.multispeed_fiber = FALSE;
1692 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
1693 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
1694 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
1695 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
1696 hw->phy.multispeed_fiber = TRUE;
1698 /* Determine PHY vendor for optical modules */
1699 if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
1700 IXGBE_SFF_10GBASELR_CAPABLE)) {
1701 status = hw->phy.ops.read_i2c_eeprom(hw,
1702 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1705 if (status != IXGBE_SUCCESS)
1706 goto err_read_i2c_eeprom;
1708 status = hw->phy.ops.read_i2c_eeprom(hw,
1709 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1712 if (status != IXGBE_SUCCESS)
1713 goto err_read_i2c_eeprom;
1715 status = hw->phy.ops.read_i2c_eeprom(hw,
1716 IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1719 if (status != IXGBE_SUCCESS)
1720 goto err_read_i2c_eeprom;
1723 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
1724 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
1725 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
1727 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
1728 hw->phy.type = ixgbe_phy_qsfp_intel;
1730 hw->phy.type = ixgbe_phy_qsfp_unknown;
1732 ixgbe_get_device_caps(hw, &enforce_sfp);
1733 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1734 /* Make sure we're a supported PHY type */
1735 if (hw->phy.type == ixgbe_phy_qsfp_intel) {
1736 status = IXGBE_SUCCESS;
1738 if (hw->allow_unsupported_sfp == TRUE) {
1739 EWARN(hw, "WARNING: Intel (R) Network "
1740 "Connections are quality tested "
1741 "using Intel (R) Ethernet Optics."
1742 " Using untested modules is not "
1743 "supported and may cause unstable"
1744 " operation or damage to the "
1745 "module or the adapter. Intel "
1746 "Corporation is not responsible "
1747 "for any harm caused by using "
1748 "untested modules.\n", status);
1749 status = IXGBE_SUCCESS;
1751 DEBUGOUT("QSFP module not supported\n");
1753 ixgbe_phy_sfp_unsupported;
1754 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
1758 status = IXGBE_SUCCESS;
1765 err_read_i2c_eeprom:
1766 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
1768 hw->phy.type = ixgbe_phy_unknown;
1770 return IXGBE_ERR_SFP_NOT_PRESENT;
1775 * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
1776 * @hw: pointer to hardware structure
1777 * @list_offset: offset to the SFP ID list
1778 * @data_offset: offset to the SFP data block
1780 * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
1781 * so it returns the offsets to the phy init sequence block.
1783 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
1788 u16 sfp_type = hw->phy.sfp_type;
1790 DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
1792 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
1793 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1795 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1796 return IXGBE_ERR_SFP_NOT_PRESENT;
1798 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
1799 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
1800 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1803 * Limiting active cables and 1G Phys must be initialized as
1806 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
1807 sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
1808 sfp_type == ixgbe_sfp_type_1g_sx_core0)
1809 sfp_type = ixgbe_sfp_type_srlr_core0;
1810 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
1811 sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
1812 sfp_type == ixgbe_sfp_type_1g_sx_core1)
1813 sfp_type = ixgbe_sfp_type_srlr_core1;
1815 /* Read offset to PHY init contents */
1816 if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
1817 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1818 "eeprom read at offset %d failed",
1819 IXGBE_PHY_INIT_OFFSET_NL);
1820 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1823 if ((!*list_offset) || (*list_offset == 0xFFFF))
1824 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
1826 /* Shift offset to first ID word */
1830 * Find the matching SFP ID in the EEPROM
1831 * and program the init sequence
1833 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1836 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
1837 if (sfp_id == sfp_type) {
1839 if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
1841 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
1842 DEBUGOUT("SFP+ module not supported\n");
1843 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1848 (*list_offset) += 2;
1849 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
1854 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
1855 DEBUGOUT("No matching SFP+ module found\n");
1856 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1859 return IXGBE_SUCCESS;
1862 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
1863 "eeprom read at offset %d failed", *list_offset);
1864 return IXGBE_ERR_PHY;
1868 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
1869 * @hw: pointer to hardware structure
1870 * @byte_offset: EEPROM byte offset to read
1871 * @eeprom_data: value read
1873 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1875 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1878 DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
1880 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1881 IXGBE_I2C_EEPROM_DEV_ADDR,
1886 * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
1887 * @hw: pointer to hardware structure
1888 * @byte_offset: byte offset at address 0xA2
1889 * @eeprom_data: value read
1891 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1893 static s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
1896 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
1897 IXGBE_I2C_EEPROM_DEV_ADDR2,
1902 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
1903 * @hw: pointer to hardware structure
1904 * @byte_offset: EEPROM byte offset to write
1905 * @eeprom_data: value to write
1907 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1909 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
1912 DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
1914 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
1915 IXGBE_I2C_EEPROM_DEV_ADDR,
1920 * ixgbe_is_sfp_probe - Returns TRUE if SFP is being detected
1921 * @hw: pointer to hardware structure
1922 * @offset: eeprom offset to be read
1923 * @addr: I2C address to be read
1925 static bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
1927 if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
1928 offset == IXGBE_SFF_IDENTIFIER &&
1929 hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1935 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
1936 * @hw: pointer to hardware structure
1937 * @byte_offset: byte offset to read
1940 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1941 * a specified device address.
1943 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
1944 u8 dev_addr, u8 *data)
1949 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1953 DEBUGFUNC("ixgbe_read_i2c_byte_generic");
1955 if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
1956 max_retry = IXGBE_SFP_DETECT_RETRIES;
1959 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
1960 return IXGBE_ERR_SWFW_SYNC;
1962 ixgbe_i2c_start(hw);
1964 /* Device Address and write indication */
1965 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
1966 if (status != IXGBE_SUCCESS)
1969 status = ixgbe_get_i2c_ack(hw);
1970 if (status != IXGBE_SUCCESS)
1973 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
1974 if (status != IXGBE_SUCCESS)
1977 status = ixgbe_get_i2c_ack(hw);
1978 if (status != IXGBE_SUCCESS)
1981 ixgbe_i2c_start(hw);
1983 /* Device Address and read indication */
1984 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
1985 if (status != IXGBE_SUCCESS)
1988 status = ixgbe_get_i2c_ack(hw);
1989 if (status != IXGBE_SUCCESS)
1992 status = ixgbe_clock_in_i2c_byte(hw, data);
1993 if (status != IXGBE_SUCCESS)
1996 status = ixgbe_clock_out_i2c_bit(hw, nack);
1997 if (status != IXGBE_SUCCESS)
2001 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
2002 return IXGBE_SUCCESS;
2005 ixgbe_i2c_bus_clear(hw);
2006 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
2009 if (retry < max_retry)
2010 DEBUGOUT("I2C byte read error - Retrying.\n");
2012 DEBUGOUT("I2C byte read error.\n");
2014 } while (retry < max_retry);
2020 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
2021 * @hw: pointer to hardware structure
2022 * @byte_offset: byte offset to write
2023 * @data: value to write
2025 * Performs byte write operation to SFP module's EEPROM over I2C interface at
2026 * a specified device address.
2028 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
2029 u8 dev_addr, u8 data)
2031 s32 status = IXGBE_SUCCESS;
2034 u32 swfw_mask = hw->phy.phy_semaphore_mask;
2036 DEBUGFUNC("ixgbe_write_i2c_byte_generic");
2038 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) != IXGBE_SUCCESS) {
2039 status = IXGBE_ERR_SWFW_SYNC;
2040 goto write_byte_out;
2044 ixgbe_i2c_start(hw);
2046 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
2047 if (status != IXGBE_SUCCESS)
2050 status = ixgbe_get_i2c_ack(hw);
2051 if (status != IXGBE_SUCCESS)
2054 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
2055 if (status != IXGBE_SUCCESS)
2058 status = ixgbe_get_i2c_ack(hw);
2059 if (status != IXGBE_SUCCESS)
2062 status = ixgbe_clock_out_i2c_byte(hw, data);
2063 if (status != IXGBE_SUCCESS)
2066 status = ixgbe_get_i2c_ack(hw);
2067 if (status != IXGBE_SUCCESS)
2071 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
2072 return IXGBE_SUCCESS;
2075 ixgbe_i2c_bus_clear(hw);
2077 if (retry < max_retry)
2078 DEBUGOUT("I2C byte write error - Retrying.\n");
2080 DEBUGOUT("I2C byte write error.\n");
2081 } while (retry < max_retry);
2083 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
2090 * ixgbe_i2c_start - Sets I2C start condition
2091 * @hw: pointer to hardware structure
2093 * Sets I2C start condition (High -> Low on SDA while SCL is High)
2094 * Set bit-bang mode on X550 hardware.
2096 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
2098 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2100 DEBUGFUNC("ixgbe_i2c_start");
2102 i2cctl |= IXGBE_I2C_BB_EN_BY_MAC(hw);
2104 /* Start condition must begin with data and clock high */
2105 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2106 ixgbe_raise_i2c_clk(hw, &i2cctl);
2108 /* Setup time for start condition (4.7us) */
2109 usec_delay(IXGBE_I2C_T_SU_STA);
2111 ixgbe_set_i2c_data(hw, &i2cctl, 0);
2113 /* Hold time for start condition (4us) */
2114 usec_delay(IXGBE_I2C_T_HD_STA);
2116 ixgbe_lower_i2c_clk(hw, &i2cctl);
2118 /* Minimum low period of clock is 4.7 us */
2119 usec_delay(IXGBE_I2C_T_LOW);
2124 * ixgbe_i2c_stop - Sets I2C stop condition
2125 * @hw: pointer to hardware structure
2127 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
2128 * Disables bit-bang mode and negates data output enable on X550
2131 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
2133 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2134 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2135 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
2136 u32 bb_en_bit = IXGBE_I2C_BB_EN_BY_MAC(hw);
2138 DEBUGFUNC("ixgbe_i2c_stop");
2140 /* Stop condition must begin with data low and clock high */
2141 ixgbe_set_i2c_data(hw, &i2cctl, 0);
2142 ixgbe_raise_i2c_clk(hw, &i2cctl);
2144 /* Setup time for stop condition (4us) */
2145 usec_delay(IXGBE_I2C_T_SU_STO);
2147 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2149 /* bus free time between stop and start (4.7us)*/
2150 usec_delay(IXGBE_I2C_T_BUF);
2152 if (bb_en_bit || data_oe_bit || clk_oe_bit) {
2153 i2cctl &= ~bb_en_bit;
2154 i2cctl |= data_oe_bit | clk_oe_bit;
2155 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
2156 IXGBE_WRITE_FLUSH(hw);
2161 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
2162 * @hw: pointer to hardware structure
2163 * @data: data byte to clock in
2165 * Clocks in one byte data via I2C data/clock
2167 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
2172 DEBUGFUNC("ixgbe_clock_in_i2c_byte");
2175 for (i = 7; i >= 0; i--) {
2176 ixgbe_clock_in_i2c_bit(hw, &bit);
2180 return IXGBE_SUCCESS;
2184 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
2185 * @hw: pointer to hardware structure
2186 * @data: data byte clocked out
2188 * Clocks out one byte data via I2C data/clock
2190 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
2192 s32 status = IXGBE_SUCCESS;
2197 DEBUGFUNC("ixgbe_clock_out_i2c_byte");
2199 for (i = 7; i >= 0; i--) {
2200 bit = (data >> i) & 0x1;
2201 status = ixgbe_clock_out_i2c_bit(hw, bit);
2203 if (status != IXGBE_SUCCESS)
2207 /* Release SDA line (set high) */
2208 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2209 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2210 i2cctl |= IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2211 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
2212 IXGBE_WRITE_FLUSH(hw);
2218 * ixgbe_get_i2c_ack - Polls for I2C ACK
2219 * @hw: pointer to hardware structure
2221 * Clocks in/out one bit via I2C data/clock
2223 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
2225 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2226 s32 status = IXGBE_SUCCESS;
2228 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2232 DEBUGFUNC("ixgbe_get_i2c_ack");
2235 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2236 i2cctl |= data_oe_bit;
2237 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
2238 IXGBE_WRITE_FLUSH(hw);
2240 ixgbe_raise_i2c_clk(hw, &i2cctl);
2242 /* Minimum high period of clock is 4us */
2243 usec_delay(IXGBE_I2C_T_HIGH);
2245 /* Poll for ACK. Note that ACK in I2C spec is
2246 * transition from 1 to 0 */
2247 for (i = 0; i < timeout; i++) {
2248 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2249 ack = ixgbe_get_i2c_data(hw, &i2cctl);
2257 DEBUGOUT("I2C ack was not received.\n");
2258 status = IXGBE_ERR_I2C;
2261 ixgbe_lower_i2c_clk(hw, &i2cctl);
2263 /* Minimum low period of clock is 4.7 us */
2264 usec_delay(IXGBE_I2C_T_LOW);
2270 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
2271 * @hw: pointer to hardware structure
2272 * @data: read data value
2274 * Clocks in one bit via I2C data/clock
2276 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
2278 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2279 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2281 DEBUGFUNC("ixgbe_clock_in_i2c_bit");
2284 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2285 i2cctl |= data_oe_bit;
2286 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
2287 IXGBE_WRITE_FLUSH(hw);
2289 ixgbe_raise_i2c_clk(hw, &i2cctl);
2291 /* Minimum high period of clock is 4us */
2292 usec_delay(IXGBE_I2C_T_HIGH);
2294 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2295 *data = ixgbe_get_i2c_data(hw, &i2cctl);
2297 ixgbe_lower_i2c_clk(hw, &i2cctl);
2299 /* Minimum low period of clock is 4.7 us */
2300 usec_delay(IXGBE_I2C_T_LOW);
2302 return IXGBE_SUCCESS;
2306 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
2307 * @hw: pointer to hardware structure
2308 * @data: data value to write
2310 * Clocks out one bit via I2C data/clock
2312 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
2315 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2317 DEBUGFUNC("ixgbe_clock_out_i2c_bit");
2319 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
2320 if (status == IXGBE_SUCCESS) {
2321 ixgbe_raise_i2c_clk(hw, &i2cctl);
2323 /* Minimum high period of clock is 4us */
2324 usec_delay(IXGBE_I2C_T_HIGH);
2326 ixgbe_lower_i2c_clk(hw, &i2cctl);
2328 /* Minimum low period of clock is 4.7 us.
2329 * This also takes care of the data hold time.
2331 usec_delay(IXGBE_I2C_T_LOW);
2333 status = IXGBE_ERR_I2C;
2334 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
2335 "I2C data was not set to %X\n", data);
2342 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
2343 * @hw: pointer to hardware structure
2344 * @i2cctl: Current value of I2CCTL register
2346 * Raises the I2C clock line '0'->'1'
2347 * Negates the I2C clock output enable on X550 hardware.
2349 static void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2351 u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
2353 u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
2356 DEBUGFUNC("ixgbe_raise_i2c_clk");
2359 *i2cctl |= clk_oe_bit;
2360 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2363 for (i = 0; i < timeout; i++) {
2364 *i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
2366 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2367 IXGBE_WRITE_FLUSH(hw);
2368 /* SCL rise time (1000ns) */
2369 usec_delay(IXGBE_I2C_T_RISE);
2371 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2372 if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
2378 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
2379 * @hw: pointer to hardware structure
2380 * @i2cctl: Current value of I2CCTL register
2382 * Lowers the I2C clock line '1'->'0'
2383 * Asserts the I2C clock output enable on X550 hardware.
2385 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
2387 DEBUGFUNC("ixgbe_lower_i2c_clk");
2389 *i2cctl &= ~(IXGBE_I2C_CLK_OUT_BY_MAC(hw));
2390 *i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
2392 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2393 IXGBE_WRITE_FLUSH(hw);
2395 /* SCL fall time (300ns) */
2396 usec_delay(IXGBE_I2C_T_FALL);
2400 * ixgbe_set_i2c_data - Sets the I2C data bit
2401 * @hw: pointer to hardware structure
2402 * @i2cctl: Current value of I2CCTL register
2403 * @data: I2C data value (0 or 1) to set
2405 * Sets the I2C data bit
2406 * Asserts the I2C data output enable on X550 hardware.
2408 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
2410 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2411 s32 status = IXGBE_SUCCESS;
2413 DEBUGFUNC("ixgbe_set_i2c_data");
2416 *i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
2418 *i2cctl &= ~(IXGBE_I2C_DATA_OUT_BY_MAC(hw));
2419 *i2cctl &= ~data_oe_bit;
2421 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2422 IXGBE_WRITE_FLUSH(hw);
2424 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
2425 usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
2427 if (!data) /* Can't verify data in this case */
2428 return IXGBE_SUCCESS;
2430 *i2cctl |= data_oe_bit;
2431 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2432 IXGBE_WRITE_FLUSH(hw);
2435 /* Verify data was set correctly */
2436 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2437 if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
2438 status = IXGBE_ERR_I2C;
2439 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
2440 "Error - I2C data was not set to %X.\n",
2448 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
2449 * @hw: pointer to hardware structure
2450 * @i2cctl: Current value of I2CCTL register
2452 * Returns the I2C data bit value
2453 * Negates the I2C data output enable on X550 hardware.
2455 static bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
2457 u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
2460 DEBUGFUNC("ixgbe_get_i2c_data");
2463 *i2cctl |= data_oe_bit;
2464 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
2465 IXGBE_WRITE_FLUSH(hw);
2466 usec_delay(IXGBE_I2C_T_FALL);
2469 if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
2478 * ixgbe_i2c_bus_clear - Clears the I2C bus
2479 * @hw: pointer to hardware structure
2481 * Clears the I2C bus by sending nine clock pulses.
2482 * Used when data line is stuck low.
2484 void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
2489 DEBUGFUNC("ixgbe_i2c_bus_clear");
2491 ixgbe_i2c_start(hw);
2492 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
2494 ixgbe_set_i2c_data(hw, &i2cctl, 1);
2496 for (i = 0; i < 9; i++) {
2497 ixgbe_raise_i2c_clk(hw, &i2cctl);
2499 /* Min high period of clock is 4us */
2500 usec_delay(IXGBE_I2C_T_HIGH);
2502 ixgbe_lower_i2c_clk(hw, &i2cctl);
2504 /* Min low period of clock is 4.7us*/
2505 usec_delay(IXGBE_I2C_T_LOW);
2508 ixgbe_i2c_start(hw);
2510 /* Put the i2c bus back to default state */
2515 * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
2516 * @hw: pointer to hardware structure
2518 * Checks if the LASI temp alarm status was triggered due to overtemp
2520 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
2522 s32 status = IXGBE_SUCCESS;
2525 DEBUGFUNC("ixgbe_tn_check_overtemp");
2527 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
2530 /* Check that the LASI temp alarm status was triggered */
2531 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
2532 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
2534 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
2537 status = IXGBE_ERR_OVERTEMP;
2538 ERROR_REPORT1(IXGBE_ERROR_CAUTION, "Device over temperature");
2544 * ixgbe_set_copper_phy_power - Control power for copper phy
2545 * @hw: pointer to hardware structure
2546 * @on: TRUE for on, FALSE for off
2548 s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
2553 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2554 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2560 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2562 if (ixgbe_check_reset_blocked(hw))
2564 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
2567 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
2568 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,