1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2010 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/pci.h>
29 #include <linux/delay.h>
30 #include <linux/sched.h>
32 #include "ixgbe_common.h"
33 #include "ixgbe_phy.h"
35 static void ixgbe_i2c_start(struct ixgbe_hw *hw);
36 static void ixgbe_i2c_stop(struct ixgbe_hw *hw);
37 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
38 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
39 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
40 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
41 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
42 static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
43 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
45 static bool ixgbe_get_i2c_data(u32 *i2cctl);
46 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
47 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
48 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
51 * ixgbe_identify_phy_generic - Get physical layer module
52 * @hw: pointer to hardware structure
54 * Determines the physical layer module found on the current adapter.
56 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
58 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
61 if (hw->phy.type == ixgbe_phy_unknown) {
62 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
63 hw->phy.mdio.prtad = phy_addr;
64 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
67 ixgbe_get_phy_type_from_id(hw->phy.id);
72 /* clear value if nothing found */
73 hw->phy.mdio.prtad = 0;
82 * ixgbe_get_phy_id - Get the phy type
83 * @hw: pointer to hardware structure
86 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
92 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
96 hw->phy.id = (u32)(phy_id_high << 16);
97 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
99 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
100 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
106 * ixgbe_get_phy_type_from_id - Get the phy type
107 * @hw: pointer to hardware structure
110 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
112 enum ixgbe_phy_type phy_type;
116 phy_type = ixgbe_phy_tn;
119 phy_type = ixgbe_phy_aq;
122 phy_type = ixgbe_phy_qt;
125 phy_type = ixgbe_phy_nl;
128 phy_type = ixgbe_phy_unknown;
136 * ixgbe_reset_phy_generic - Performs a PHY reset
137 * @hw: pointer to hardware structure
139 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
141 /* Don't reset PHY if it's shut down due to overtemp. */
142 if (!hw->phy.reset_if_overtemp &&
143 (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
147 * Perform soft PHY reset to the PHY_XS.
148 * This will cause a soft reset to the PHY
150 return hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
155 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
156 * @hw: pointer to hardware structure
157 * @reg_addr: 32 bit address of PHY register to read
158 * @phy_data: Pointer to read data from PHY register
160 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
161 u32 device_type, u16 *phy_data)
169 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
170 gssr = IXGBE_GSSR_PHY1_SM;
172 gssr = IXGBE_GSSR_PHY0_SM;
174 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
175 status = IXGBE_ERR_SWFW_SYNC;
178 /* Setup and write the address cycle command */
179 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
180 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
181 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
182 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
184 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
187 * Check every 10 usec to see if the address cycle completed.
188 * The MDI Command bit will clear when the operation is
191 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
194 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
196 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
200 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
201 hw_dbg(hw, "PHY address command did not complete.\n");
202 status = IXGBE_ERR_PHY;
207 * Address cycle complete, setup and write the read
210 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
211 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
212 (hw->phy.mdio.prtad <<
213 IXGBE_MSCA_PHY_ADDR_SHIFT) |
214 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
216 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
219 * Check every 10 usec to see if the address cycle
220 * completed. The MDI Command bit will clear when the
221 * operation is complete
223 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
226 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
228 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
232 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
233 hw_dbg(hw, "PHY read command didn't complete\n");
234 status = IXGBE_ERR_PHY;
237 * Read operation is complete. Get the data
240 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
241 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
242 *phy_data = (u16)(data);
246 ixgbe_release_swfw_sync(hw, gssr);
253 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
254 * @hw: pointer to hardware structure
255 * @reg_addr: 32 bit PHY register to write
256 * @device_type: 5 bit device type
257 * @phy_data: Data to write to the PHY register
259 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
260 u32 device_type, u16 phy_data)
267 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
268 gssr = IXGBE_GSSR_PHY1_SM;
270 gssr = IXGBE_GSSR_PHY0_SM;
272 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
273 status = IXGBE_ERR_SWFW_SYNC;
276 /* Put the data in the MDI single read and write data register*/
277 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
279 /* Setup and write the address cycle command */
280 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
281 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
282 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
283 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
285 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
288 * Check every 10 usec to see if the address cycle completed.
289 * The MDI Command bit will clear when the operation is
292 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
295 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
297 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
301 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
302 hw_dbg(hw, "PHY address cmd didn't complete\n");
303 status = IXGBE_ERR_PHY;
308 * Address cycle complete, setup and write the write
311 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
312 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
313 (hw->phy.mdio.prtad <<
314 IXGBE_MSCA_PHY_ADDR_SHIFT) |
315 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
317 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
320 * Check every 10 usec to see if the address cycle
321 * completed. The MDI Command bit will clear when the
322 * operation is complete
324 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
327 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
329 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
333 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
334 hw_dbg(hw, "PHY address cmd didn't complete\n");
335 status = IXGBE_ERR_PHY;
339 ixgbe_release_swfw_sync(hw, gssr);
346 * ixgbe_setup_phy_link_generic - Set and restart autoneg
347 * @hw: pointer to hardware structure
349 * Restart autonegotiation and PHY and waits for completion.
351 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
353 s32 status = IXGBE_NOT_IMPLEMENTED;
355 u32 max_time_out = 10;
359 * Set advertisement settings in PHY based on autoneg_advertised
360 * settings. If autoneg_advertised = 0, then advertise default values
361 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
364 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
366 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
367 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
369 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
371 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
373 /* Restart PHY autonegotiation and wait for completion */
374 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg);
376 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
378 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
380 /* Wait for autonegotiation to finish */
381 for (time_out = 0; time_out < max_time_out; time_out++) {
383 /* Restart PHY autonegotiation and wait for completion */
384 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
387 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
388 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
394 if (time_out == max_time_out)
395 status = IXGBE_ERR_LINK_SETUP;
401 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
402 * @hw: pointer to hardware structure
403 * @speed: new link speed
404 * @autoneg: true if autonegotiation enabled
406 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
407 ixgbe_link_speed speed,
409 bool autoneg_wait_to_complete)
413 * Clear autoneg_advertised and set new values based on input link
416 hw->phy.autoneg_advertised = 0;
418 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
419 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
421 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
422 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
424 /* Setup link based on the new speed settings */
425 hw->phy.ops.setup_link(hw);
431 * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
432 * @hw: pointer to hardware structure
433 * @speed: pointer to link speed
434 * @autoneg: boolean auto-negotiation value
436 * Determines the link capabilities by reading the AUTOC register.
438 s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
439 ixgbe_link_speed *speed,
442 s32 status = IXGBE_ERR_LINK_SETUP;
448 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
452 if (speed_ability & MDIO_SPEED_10G)
453 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
454 if (speed_ability & MDIO_PMA_SPEED_1000)
455 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
456 if (speed_ability & MDIO_PMA_SPEED_100)
457 *speed |= IXGBE_LINK_SPEED_100_FULL;
464 * ixgbe_reset_phy_nl - Performs a PHY reset
465 * @hw: pointer to hardware structure
467 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
469 u16 phy_offset, control, eword, edata, block_crc;
470 bool end_data = false;
471 u16 list_offset, data_offset;
476 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
478 /* reset the PHY and poll for completion */
479 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
480 (phy_data | MDIO_CTRL1_RESET));
482 for (i = 0; i < 100; i++) {
483 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
485 if ((phy_data & MDIO_CTRL1_RESET) == 0)
490 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
491 hw_dbg(hw, "PHY reset did not complete.\n");
492 ret_val = IXGBE_ERR_PHY;
496 /* Get init offsets */
497 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
502 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
506 * Read control word from PHY init contents offset
508 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
509 control = (eword & IXGBE_CONTROL_MASK_NL) >>
510 IXGBE_CONTROL_SHIFT_NL;
511 edata = eword & IXGBE_DATA_MASK_NL;
515 hw_dbg(hw, "DELAY: %d MS\n", edata);
519 hw_dbg(hw, "DATA:\n");
521 hw->eeprom.ops.read(hw, data_offset++,
523 for (i = 0; i < edata; i++) {
524 hw->eeprom.ops.read(hw, data_offset, &eword);
525 hw->phy.ops.write_reg(hw, phy_offset,
526 MDIO_MMD_PMAPMD, eword);
527 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
533 case IXGBE_CONTROL_NL:
535 hw_dbg(hw, "CONTROL:\n");
536 if (edata == IXGBE_CONTROL_EOL_NL) {
539 } else if (edata == IXGBE_CONTROL_SOL_NL) {
542 hw_dbg(hw, "Bad control value\n");
543 ret_val = IXGBE_ERR_PHY;
548 hw_dbg(hw, "Bad control type\n");
549 ret_val = IXGBE_ERR_PHY;
559 * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns
561 * @hw: pointer to hardware structure
563 * Searches for and indentifies the SFP module. Assings appropriate PHY type.
565 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
567 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
569 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
571 u8 comp_codes_1g = 0;
572 u8 comp_codes_10g = 0;
573 u8 oui_bytes[3] = {0, 0, 0};
578 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
579 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
580 status = IXGBE_ERR_SFP_NOT_PRESENT;
584 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
587 if (status == IXGBE_ERR_SFP_NOT_PRESENT || status == IXGBE_ERR_I2C) {
588 status = IXGBE_ERR_SFP_NOT_PRESENT;
589 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
590 if (hw->phy.type != ixgbe_phy_nl) {
592 hw->phy.type = ixgbe_phy_unknown;
597 if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
598 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
600 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
602 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_CABLE_TECHNOLOGY,
610 * 3 SFP_DA_CORE0 - 82599-specific
611 * 4 SFP_DA_CORE1 - 82599-specific
612 * 5 SFP_SR/LR_CORE0 - 82599-specific
613 * 6 SFP_SR/LR_CORE1 - 82599-specific
614 * 7 SFP_act_lmt_DA_CORE0 - 82599-specific
615 * 8 SFP_act_lmt_DA_CORE1 - 82599-specific
616 * 9 SFP_1g_cu_CORE0 - 82599-specific
617 * 10 SFP_1g_cu_CORE1 - 82599-specific
619 if (hw->mac.type == ixgbe_mac_82598EB) {
620 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
621 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
622 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
623 hw->phy.sfp_type = ixgbe_sfp_type_sr;
624 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
625 hw->phy.sfp_type = ixgbe_sfp_type_lr;
627 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
628 } else if (hw->mac.type == ixgbe_mac_82599EB) {
629 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
630 if (hw->bus.lan_id == 0)
632 ixgbe_sfp_type_da_cu_core0;
635 ixgbe_sfp_type_da_cu_core1;
636 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
637 hw->phy.ops.read_i2c_eeprom(
638 hw, IXGBE_SFF_CABLE_SPEC_COMP,
641 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
642 if (hw->bus.lan_id == 0)
644 ixgbe_sfp_type_da_act_lmt_core0;
647 ixgbe_sfp_type_da_act_lmt_core1;
650 ixgbe_sfp_type_unknown;
652 } else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
653 if (hw->bus.lan_id == 0)
655 ixgbe_sfp_type_srlr_core0;
658 ixgbe_sfp_type_srlr_core1;
659 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
660 if (hw->bus.lan_id == 0)
662 ixgbe_sfp_type_srlr_core0;
665 ixgbe_sfp_type_srlr_core1;
666 else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
667 if (hw->bus.lan_id == 0)
669 ixgbe_sfp_type_1g_cu_core0;
672 ixgbe_sfp_type_1g_cu_core1;
674 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
677 if (hw->phy.sfp_type != stored_sfp_type)
678 hw->phy.sfp_setup_needed = true;
680 /* Determine if the SFP+ PHY is dual speed or not. */
681 hw->phy.multispeed_fiber = false;
682 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
683 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
684 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
685 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
686 hw->phy.multispeed_fiber = true;
688 /* Determine PHY vendor */
689 if (hw->phy.type != ixgbe_phy_nl) {
690 hw->phy.id = identifier;
691 hw->phy.ops.read_i2c_eeprom(hw,
692 IXGBE_SFF_VENDOR_OUI_BYTE0,
694 hw->phy.ops.read_i2c_eeprom(hw,
695 IXGBE_SFF_VENDOR_OUI_BYTE1,
697 hw->phy.ops.read_i2c_eeprom(hw,
698 IXGBE_SFF_VENDOR_OUI_BYTE2,
702 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
703 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
704 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
706 switch (vendor_oui) {
707 case IXGBE_SFF_VENDOR_OUI_TYCO:
708 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
710 ixgbe_phy_sfp_passive_tyco;
712 case IXGBE_SFF_VENDOR_OUI_FTL:
713 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
714 hw->phy.type = ixgbe_phy_sfp_ftl_active;
716 hw->phy.type = ixgbe_phy_sfp_ftl;
718 case IXGBE_SFF_VENDOR_OUI_AVAGO:
719 hw->phy.type = ixgbe_phy_sfp_avago;
721 case IXGBE_SFF_VENDOR_OUI_INTEL:
722 hw->phy.type = ixgbe_phy_sfp_intel;
725 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
727 ixgbe_phy_sfp_passive_unknown;
728 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
730 ixgbe_phy_sfp_active_unknown;
732 hw->phy.type = ixgbe_phy_sfp_unknown;
737 /* All passive DA cables are supported */
738 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
739 IXGBE_SFF_DA_ACTIVE_CABLE)) {
744 /* Verify supported 1G SFP modules */
745 if (comp_codes_10g == 0 &&
746 !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
747 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0)) {
748 hw->phy.type = ixgbe_phy_sfp_unsupported;
749 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
753 /* Anything else 82598-based is supported */
754 if (hw->mac.type == ixgbe_mac_82598EB) {
759 /* This is guaranteed to be 82599, no need to check for NULL */
760 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
761 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
762 !((hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0) ||
763 (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1))) {
764 /* Make sure we're a supported PHY type */
765 if (hw->phy.type == ixgbe_phy_sfp_intel) {
768 hw_dbg(hw, "SFP+ module not supported\n");
769 hw->phy.type = ixgbe_phy_sfp_unsupported;
770 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
782 * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
783 * if it supports a given SFP+ module type, if so it returns the offsets to the
784 * phy init sequence block.
785 * @hw: pointer to hardware structure
786 * @list_offset: offset to the SFP ID list
787 * @data_offset: offset to the SFP data block
789 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
794 u16 sfp_type = hw->phy.sfp_type;
796 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
797 return IXGBE_ERR_SFP_NOT_SUPPORTED;
799 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
800 return IXGBE_ERR_SFP_NOT_PRESENT;
802 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
803 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
804 return IXGBE_ERR_SFP_NOT_SUPPORTED;
807 * Limiting active cables and 1G Phys must be initialized as
810 if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
811 sfp_type == ixgbe_sfp_type_1g_cu_core0)
812 sfp_type = ixgbe_sfp_type_srlr_core0;
813 else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
814 sfp_type == ixgbe_sfp_type_1g_cu_core1)
815 sfp_type = ixgbe_sfp_type_srlr_core1;
817 /* Read offset to PHY init contents */
818 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
820 if ((!*list_offset) || (*list_offset == 0xFFFF))
821 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
823 /* Shift offset to first ID word */
827 * Find the matching SFP ID in the EEPROM
828 * and program the init sequence
830 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
832 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
833 if (sfp_id == sfp_type) {
835 hw->eeprom.ops.read(hw, *list_offset, data_offset);
836 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
837 hw_dbg(hw, "SFP+ module not supported\n");
838 return IXGBE_ERR_SFP_NOT_SUPPORTED;
844 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
845 return IXGBE_ERR_PHY;
849 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
850 hw_dbg(hw, "No matching SFP+ module found\n");
851 return IXGBE_ERR_SFP_NOT_SUPPORTED;
858 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
859 * @hw: pointer to hardware structure
860 * @byte_offset: EEPROM byte offset to read
861 * @eeprom_data: value read
863 * Performs byte read operation to SFP module's EEPROM over I2C interface.
865 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
868 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
869 IXGBE_I2C_EEPROM_DEV_ADDR,
874 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
875 * @hw: pointer to hardware structure
876 * @byte_offset: EEPROM byte offset to write
877 * @eeprom_data: value to write
879 * Performs byte write operation to SFP module's EEPROM over I2C interface.
881 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
884 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
885 IXGBE_I2C_EEPROM_DEV_ADDR,
890 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
891 * @hw: pointer to hardware structure
892 * @byte_offset: byte offset to read
895 * Performs byte read operation to SFP module's EEPROM over I2C interface at
896 * a specified deivce address.
898 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
899 u8 dev_addr, u8 *data)
909 /* Device Address and write indication */
910 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
914 status = ixgbe_get_i2c_ack(hw);
918 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
922 status = ixgbe_get_i2c_ack(hw);
928 /* Device Address and read indication */
929 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
933 status = ixgbe_get_i2c_ack(hw);
937 status = ixgbe_clock_in_i2c_byte(hw, data);
941 status = ixgbe_clock_out_i2c_bit(hw, nack);
949 ixgbe_i2c_bus_clear(hw);
951 if (retry < max_retry)
952 hw_dbg(hw, "I2C byte read error - Retrying.\n");
954 hw_dbg(hw, "I2C byte read error.\n");
956 } while (retry < max_retry);
962 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
963 * @hw: pointer to hardware structure
964 * @byte_offset: byte offset to write
965 * @data: value to write
967 * Performs byte write operation to SFP module's EEPROM over I2C interface at
968 * a specified device address.
970 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
971 u8 dev_addr, u8 data)
980 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
984 status = ixgbe_get_i2c_ack(hw);
988 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
992 status = ixgbe_get_i2c_ack(hw);
996 status = ixgbe_clock_out_i2c_byte(hw, data);
1000 status = ixgbe_get_i2c_ack(hw);
1008 ixgbe_i2c_bus_clear(hw);
1010 if (retry < max_retry)
1011 hw_dbg(hw, "I2C byte write error - Retrying.\n");
1013 hw_dbg(hw, "I2C byte write error.\n");
1014 } while (retry < max_retry);
1020 * ixgbe_i2c_start - Sets I2C start condition
1021 * @hw: pointer to hardware structure
1023 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1025 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
1027 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1029 /* Start condition must begin with data and clock high */
1030 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1031 ixgbe_raise_i2c_clk(hw, &i2cctl);
1033 /* Setup time for start condition (4.7us) */
1034 udelay(IXGBE_I2C_T_SU_STA);
1036 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1038 /* Hold time for start condition (4us) */
1039 udelay(IXGBE_I2C_T_HD_STA);
1041 ixgbe_lower_i2c_clk(hw, &i2cctl);
1043 /* Minimum low period of clock is 4.7 us */
1044 udelay(IXGBE_I2C_T_LOW);
1049 * ixgbe_i2c_stop - Sets I2C stop condition
1050 * @hw: pointer to hardware structure
1052 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1054 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
1056 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1058 /* Stop condition must begin with data low and clock high */
1059 ixgbe_set_i2c_data(hw, &i2cctl, 0);
1060 ixgbe_raise_i2c_clk(hw, &i2cctl);
1062 /* Setup time for stop condition (4us) */
1063 udelay(IXGBE_I2C_T_SU_STO);
1065 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1067 /* bus free time between stop and start (4.7us)*/
1068 udelay(IXGBE_I2C_T_BUF);
1072 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1073 * @hw: pointer to hardware structure
1074 * @data: data byte to clock in
1076 * Clocks in one byte data via I2C data/clock
1078 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1084 for (i = 7; i >= 0; i--) {
1085 status = ixgbe_clock_in_i2c_bit(hw, &bit);
1096 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1097 * @hw: pointer to hardware structure
1098 * @data: data byte clocked out
1100 * Clocks out one byte data via I2C data/clock
1102 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1109 for (i = 7; i >= 0; i--) {
1110 bit = (data >> i) & 0x1;
1111 status = ixgbe_clock_out_i2c_bit(hw, bit);
1117 /* Release SDA line (set high) */
1118 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1119 i2cctl |= IXGBE_I2C_DATA_OUT;
1120 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1126 * ixgbe_get_i2c_ack - Polls for I2C ACK
1127 * @hw: pointer to hardware structure
1129 * Clocks in/out one bit via I2C data/clock
1131 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1135 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1139 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1144 /* Minimum high period of clock is 4us */
1145 udelay(IXGBE_I2C_T_HIGH);
1147 /* Poll for ACK. Note that ACK in I2C spec is
1148 * transition from 1 to 0 */
1149 for (i = 0; i < timeout; i++) {
1150 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1151 ack = ixgbe_get_i2c_data(&i2cctl);
1159 hw_dbg(hw, "I2C ack was not received.\n");
1160 status = IXGBE_ERR_I2C;
1163 ixgbe_lower_i2c_clk(hw, &i2cctl);
1165 /* Minimum low period of clock is 4.7 us */
1166 udelay(IXGBE_I2C_T_LOW);
1173 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1174 * @hw: pointer to hardware structure
1175 * @data: read data value
1177 * Clocks in one bit via I2C data/clock
1179 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1182 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1184 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1186 /* Minimum high period of clock is 4us */
1187 udelay(IXGBE_I2C_T_HIGH);
1189 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1190 *data = ixgbe_get_i2c_data(&i2cctl);
1192 ixgbe_lower_i2c_clk(hw, &i2cctl);
1194 /* Minimum low period of clock is 4.7 us */
1195 udelay(IXGBE_I2C_T_LOW);
1201 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1202 * @hw: pointer to hardware structure
1203 * @data: data value to write
1205 * Clocks out one bit via I2C data/clock
1207 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1210 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1212 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1214 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1216 /* Minimum high period of clock is 4us */
1217 udelay(IXGBE_I2C_T_HIGH);
1219 ixgbe_lower_i2c_clk(hw, &i2cctl);
1221 /* Minimum low period of clock is 4.7 us.
1222 * This also takes care of the data hold time.
1224 udelay(IXGBE_I2C_T_LOW);
1226 status = IXGBE_ERR_I2C;
1227 hw_dbg(hw, "I2C data was not set to %X\n", data);
1233 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1234 * @hw: pointer to hardware structure
1235 * @i2cctl: Current value of I2CCTL register
1237 * Raises the I2C clock line '0'->'1'
1239 static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1243 *i2cctl |= IXGBE_I2C_CLK_OUT;
1245 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1247 /* SCL rise time (1000ns) */
1248 udelay(IXGBE_I2C_T_RISE);
1254 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1255 * @hw: pointer to hardware structure
1256 * @i2cctl: Current value of I2CCTL register
1258 * Lowers the I2C clock line '1'->'0'
1260 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1263 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1265 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1267 /* SCL fall time (300ns) */
1268 udelay(IXGBE_I2C_T_FALL);
1272 * ixgbe_set_i2c_data - Sets the I2C data bit
1273 * @hw: pointer to hardware structure
1274 * @i2cctl: Current value of I2CCTL register
1275 * @data: I2C data value (0 or 1) to set
1277 * Sets the I2C data bit
1279 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1284 *i2cctl |= IXGBE_I2C_DATA_OUT;
1286 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1288 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1290 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1291 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1293 /* Verify data was set correctly */
1294 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1295 if (data != ixgbe_get_i2c_data(i2cctl)) {
1296 status = IXGBE_ERR_I2C;
1297 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1304 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1305 * @hw: pointer to hardware structure
1306 * @i2cctl: Current value of I2CCTL register
1308 * Returns the I2C data bit value
1310 static bool ixgbe_get_i2c_data(u32 *i2cctl)
1314 if (*i2cctl & IXGBE_I2C_DATA_IN)
1323 * ixgbe_i2c_bus_clear - Clears the I2C bus
1324 * @hw: pointer to hardware structure
1326 * Clears the I2C bus by sending nine clock pulses.
1327 * Used when data line is stuck low.
1329 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1331 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1334 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1336 for (i = 0; i < 9; i++) {
1337 ixgbe_raise_i2c_clk(hw, &i2cctl);
1339 /* Min high period of clock is 4us */
1340 udelay(IXGBE_I2C_T_HIGH);
1342 ixgbe_lower_i2c_clk(hw, &i2cctl);
1344 /* Min low period of clock is 4.7us*/
1345 udelay(IXGBE_I2C_T_LOW);
1348 /* Put the i2c bus back to default state */
1353 * ixgbe_check_phy_link_tnx - Determine link and speed status
1354 * @hw: pointer to hardware structure
1356 * Reads the VS1 register to determine if link is up and the current speed for
1359 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
1364 u32 max_time_out = 10;
1369 /* Initialize speed and link to default case */
1371 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1374 * Check current speed and link status of the PHY register.
1375 * This is a vendor specific register and may have to
1376 * be changed for other copper PHYs.
1378 for (time_out = 0; time_out < max_time_out; time_out++) {
1380 status = hw->phy.ops.read_reg(hw,
1381 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
1384 phy_link = phy_data &
1385 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
1386 phy_speed = phy_data &
1387 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
1388 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
1391 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
1392 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1401 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
1402 * @hw: pointer to hardware structure
1403 * @firmware_version: pointer to the PHY Firmware Version
1405 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1406 u16 *firmware_version)
1410 status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,
1417 * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
1418 * @hw: pointer to hardware structure
1419 * @firmware_version: pointer to the PHY Firmware Version
1421 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
1422 u16 *firmware_version)
1426 status = hw->phy.ops.read_reg(hw, AQ_FW_REV, MDIO_MMD_VEND1,
1433 * ixgbe_tn_check_overtemp - Checks if an overtemp occured.
1434 * @hw: pointer to hardware structure
1436 * Checks if the LASI temp alarm status was triggered due to overtemp
1438 s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
1443 if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
1446 /* Check that the LASI temp alarm status was triggered */
1447 hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
1448 MDIO_MMD_PMAPMD, &phy_data);
1450 if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
1453 status = IXGBE_ERR_OVERTEMP;