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_qt;
122 phy_type = ixgbe_phy_nl;
125 phy_type = ixgbe_phy_unknown;
133 * ixgbe_reset_phy_generic - Performs a PHY reset
134 * @hw: pointer to hardware structure
136 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
139 * Perform soft PHY reset to the PHY_XS.
140 * This will cause a soft reset to the PHY
142 return hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
147 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
148 * @hw: pointer to hardware structure
149 * @reg_addr: 32 bit address of PHY register to read
150 * @phy_data: Pointer to read data from PHY register
152 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
153 u32 device_type, u16 *phy_data)
161 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
162 gssr = IXGBE_GSSR_PHY1_SM;
164 gssr = IXGBE_GSSR_PHY0_SM;
166 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
167 status = IXGBE_ERR_SWFW_SYNC;
170 /* Setup and write the address cycle command */
171 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
172 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
173 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
174 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
176 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
179 * Check every 10 usec to see if the address cycle completed.
180 * The MDI Command bit will clear when the operation is
183 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
186 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
188 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
192 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
193 hw_dbg(hw, "PHY address command did not complete.\n");
194 status = IXGBE_ERR_PHY;
199 * Address cycle complete, setup and write the read
202 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
203 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
204 (hw->phy.mdio.prtad <<
205 IXGBE_MSCA_PHY_ADDR_SHIFT) |
206 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
208 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
211 * Check every 10 usec to see if the address cycle
212 * completed. The MDI Command bit will clear when the
213 * operation is complete
215 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
218 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
220 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
224 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
225 hw_dbg(hw, "PHY read command didn't complete\n");
226 status = IXGBE_ERR_PHY;
229 * Read operation is complete. Get the data
232 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
233 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
234 *phy_data = (u16)(data);
238 ixgbe_release_swfw_sync(hw, gssr);
245 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
246 * @hw: pointer to hardware structure
247 * @reg_addr: 32 bit PHY register to write
248 * @device_type: 5 bit device type
249 * @phy_data: Data to write to the PHY register
251 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
252 u32 device_type, u16 phy_data)
259 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
260 gssr = IXGBE_GSSR_PHY1_SM;
262 gssr = IXGBE_GSSR_PHY0_SM;
264 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
265 status = IXGBE_ERR_SWFW_SYNC;
268 /* Put the data in the MDI single read and write data register*/
269 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
271 /* Setup and write the address cycle command */
272 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
273 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
274 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
275 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
277 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
280 * Check every 10 usec to see if the address cycle completed.
281 * The MDI Command bit will clear when the operation is
284 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
287 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
289 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
293 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
294 hw_dbg(hw, "PHY address cmd didn't complete\n");
295 status = IXGBE_ERR_PHY;
300 * Address cycle complete, setup and write the write
303 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
304 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
305 (hw->phy.mdio.prtad <<
306 IXGBE_MSCA_PHY_ADDR_SHIFT) |
307 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
309 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
312 * Check every 10 usec to see if the address cycle
313 * completed. The MDI Command bit will clear when the
314 * operation is complete
316 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
319 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
321 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
325 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
326 hw_dbg(hw, "PHY address cmd didn't complete\n");
327 status = IXGBE_ERR_PHY;
331 ixgbe_release_swfw_sync(hw, gssr);
338 * ixgbe_setup_phy_link_generic - Set and restart autoneg
339 * @hw: pointer to hardware structure
341 * Restart autonegotiation and PHY and waits for completion.
343 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
345 s32 status = IXGBE_NOT_IMPLEMENTED;
347 u32 max_time_out = 10;
351 * Set advertisement settings in PHY based on autoneg_advertised
352 * settings. If autoneg_advertised = 0, then advertise default values
353 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
356 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
358 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
359 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
361 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
363 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
365 /* Restart PHY autonegotiation and wait for completion */
366 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg);
368 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
370 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
372 /* Wait for autonegotiation to finish */
373 for (time_out = 0; time_out < max_time_out; time_out++) {
375 /* Restart PHY autonegotiation and wait for completion */
376 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
379 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
380 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
386 if (time_out == max_time_out)
387 status = IXGBE_ERR_LINK_SETUP;
393 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
394 * @hw: pointer to hardware structure
395 * @speed: new link speed
396 * @autoneg: true if autonegotiation enabled
398 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
399 ixgbe_link_speed speed,
401 bool autoneg_wait_to_complete)
405 * Clear autoneg_advertised and set new values based on input link
408 hw->phy.autoneg_advertised = 0;
410 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
411 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
413 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
414 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
416 /* Setup link based on the new speed settings */
417 hw->phy.ops.setup_link(hw);
423 * ixgbe_reset_phy_nl - Performs a PHY reset
424 * @hw: pointer to hardware structure
426 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
428 u16 phy_offset, control, eword, edata, block_crc;
429 bool end_data = false;
430 u16 list_offset, data_offset;
435 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
437 /* reset the PHY and poll for completion */
438 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
439 (phy_data | MDIO_CTRL1_RESET));
441 for (i = 0; i < 100; i++) {
442 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
444 if ((phy_data & MDIO_CTRL1_RESET) == 0)
449 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
450 hw_dbg(hw, "PHY reset did not complete.\n");
451 ret_val = IXGBE_ERR_PHY;
455 /* Get init offsets */
456 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
461 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
465 * Read control word from PHY init contents offset
467 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
468 control = (eword & IXGBE_CONTROL_MASK_NL) >>
469 IXGBE_CONTROL_SHIFT_NL;
470 edata = eword & IXGBE_DATA_MASK_NL;
474 hw_dbg(hw, "DELAY: %d MS\n", edata);
478 hw_dbg(hw, "DATA:\n");
480 hw->eeprom.ops.read(hw, data_offset++,
482 for (i = 0; i < edata; i++) {
483 hw->eeprom.ops.read(hw, data_offset, &eword);
484 hw->phy.ops.write_reg(hw, phy_offset,
485 MDIO_MMD_PMAPMD, eword);
486 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
492 case IXGBE_CONTROL_NL:
494 hw_dbg(hw, "CONTROL:\n");
495 if (edata == IXGBE_CONTROL_EOL_NL) {
498 } else if (edata == IXGBE_CONTROL_SOL_NL) {
501 hw_dbg(hw, "Bad control value\n");
502 ret_val = IXGBE_ERR_PHY;
507 hw_dbg(hw, "Bad control type\n");
508 ret_val = IXGBE_ERR_PHY;
518 * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns
520 * @hw: pointer to hardware structure
522 * Searches for and indentifies the SFP module. Assings appropriate PHY type.
524 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
526 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
528 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
530 u8 comp_codes_1g = 0;
531 u8 comp_codes_10g = 0;
532 u8 oui_bytes[3] = {0, 0, 0};
537 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
538 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
539 status = IXGBE_ERR_SFP_NOT_PRESENT;
543 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
546 if (status == IXGBE_ERR_SFP_NOT_PRESENT || status == IXGBE_ERR_I2C) {
547 status = IXGBE_ERR_SFP_NOT_PRESENT;
548 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
549 if (hw->phy.type != ixgbe_phy_nl) {
551 hw->phy.type = ixgbe_phy_unknown;
556 if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
557 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
559 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
561 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_CABLE_TECHNOLOGY,
569 * 3 SFP_DA_CORE0 - 82599-specific
570 * 4 SFP_DA_CORE1 - 82599-specific
571 * 5 SFP_SR/LR_CORE0 - 82599-specific
572 * 6 SFP_SR/LR_CORE1 - 82599-specific
574 if (hw->mac.type == ixgbe_mac_82598EB) {
575 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
576 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
577 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
578 hw->phy.sfp_type = ixgbe_sfp_type_sr;
579 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
580 hw->phy.sfp_type = ixgbe_sfp_type_lr;
582 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
583 } else if (hw->mac.type == ixgbe_mac_82599EB) {
584 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
585 if (hw->bus.lan_id == 0)
587 ixgbe_sfp_type_da_cu_core0;
590 ixgbe_sfp_type_da_cu_core1;
591 } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
592 hw->phy.ops.read_i2c_eeprom(
593 hw, IXGBE_SFF_CABLE_SPEC_COMP,
596 IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
597 if (hw->bus.lan_id == 0)
599 ixgbe_sfp_type_da_act_lmt_core0;
602 ixgbe_sfp_type_da_act_lmt_core1;
605 ixgbe_sfp_type_unknown;
607 } else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
608 if (hw->bus.lan_id == 0)
610 ixgbe_sfp_type_srlr_core0;
613 ixgbe_sfp_type_srlr_core1;
614 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
615 if (hw->bus.lan_id == 0)
617 ixgbe_sfp_type_srlr_core0;
620 ixgbe_sfp_type_srlr_core1;
622 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
625 if (hw->phy.sfp_type != stored_sfp_type)
626 hw->phy.sfp_setup_needed = true;
628 /* Determine if the SFP+ PHY is dual speed or not. */
629 hw->phy.multispeed_fiber = false;
630 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
631 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
632 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
633 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
634 hw->phy.multispeed_fiber = true;
636 /* Determine PHY vendor */
637 if (hw->phy.type != ixgbe_phy_nl) {
638 hw->phy.id = identifier;
639 hw->phy.ops.read_i2c_eeprom(hw,
640 IXGBE_SFF_VENDOR_OUI_BYTE0,
642 hw->phy.ops.read_i2c_eeprom(hw,
643 IXGBE_SFF_VENDOR_OUI_BYTE1,
645 hw->phy.ops.read_i2c_eeprom(hw,
646 IXGBE_SFF_VENDOR_OUI_BYTE2,
650 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
651 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
652 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
654 switch (vendor_oui) {
655 case IXGBE_SFF_VENDOR_OUI_TYCO:
656 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
658 ixgbe_phy_sfp_passive_tyco;
660 case IXGBE_SFF_VENDOR_OUI_FTL:
661 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
662 hw->phy.type = ixgbe_phy_sfp_ftl_active;
664 hw->phy.type = ixgbe_phy_sfp_ftl;
666 case IXGBE_SFF_VENDOR_OUI_AVAGO:
667 hw->phy.type = ixgbe_phy_sfp_avago;
669 case IXGBE_SFF_VENDOR_OUI_INTEL:
670 hw->phy.type = ixgbe_phy_sfp_intel;
673 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
675 ixgbe_phy_sfp_passive_unknown;
676 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
678 ixgbe_phy_sfp_active_unknown;
680 hw->phy.type = ixgbe_phy_sfp_unknown;
685 /* All passive DA cables are supported */
686 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
687 IXGBE_SFF_DA_ACTIVE_CABLE)) {
692 /* 1G SFP modules are not supported */
693 if (comp_codes_10g == 0) {
694 hw->phy.type = ixgbe_phy_sfp_unsupported;
695 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
699 /* Anything else 82598-based is supported */
700 if (hw->mac.type == ixgbe_mac_82598EB) {
705 /* This is guaranteed to be 82599, no need to check for NULL */
706 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
707 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
708 /* Make sure we're a supported PHY type */
709 if (hw->phy.type == ixgbe_phy_sfp_intel) {
712 hw_dbg(hw, "SFP+ module not supported\n");
713 hw->phy.type = ixgbe_phy_sfp_unsupported;
714 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
726 * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
727 * if it supports a given SFP+ module type, if so it returns the offsets to the
728 * phy init sequence block.
729 * @hw: pointer to hardware structure
730 * @list_offset: offset to the SFP ID list
731 * @data_offset: offset to the SFP data block
733 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
739 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
740 return IXGBE_ERR_SFP_NOT_SUPPORTED;
742 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
743 return IXGBE_ERR_SFP_NOT_PRESENT;
745 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
746 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
747 return IXGBE_ERR_SFP_NOT_SUPPORTED;
749 /* Read offset to PHY init contents */
750 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
752 if ((!*list_offset) || (*list_offset == 0xFFFF))
753 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
755 /* Shift offset to first ID word */
759 * Find the matching SFP ID in the EEPROM
760 * and program the init sequence
762 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
764 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
765 if (sfp_id == hw->phy.sfp_type) {
767 hw->eeprom.ops.read(hw, *list_offset, data_offset);
768 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
769 hw_dbg(hw, "SFP+ module not supported\n");
770 return IXGBE_ERR_SFP_NOT_SUPPORTED;
776 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
777 return IXGBE_ERR_PHY;
781 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
782 hw_dbg(hw, "No matching SFP+ module found\n");
783 return IXGBE_ERR_SFP_NOT_SUPPORTED;
790 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
791 * @hw: pointer to hardware structure
792 * @byte_offset: EEPROM byte offset to read
793 * @eeprom_data: value read
795 * Performs byte read operation to SFP module's EEPROM over I2C interface.
797 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
800 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
801 IXGBE_I2C_EEPROM_DEV_ADDR,
806 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
807 * @hw: pointer to hardware structure
808 * @byte_offset: EEPROM byte offset to write
809 * @eeprom_data: value to write
811 * Performs byte write operation to SFP module's EEPROM over I2C interface.
813 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
816 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
817 IXGBE_I2C_EEPROM_DEV_ADDR,
822 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
823 * @hw: pointer to hardware structure
824 * @byte_offset: byte offset to read
827 * Performs byte read operation to SFP module's EEPROM over I2C interface at
828 * a specified deivce address.
830 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
831 u8 dev_addr, u8 *data)
841 /* Device Address and write indication */
842 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
846 status = ixgbe_get_i2c_ack(hw);
850 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
854 status = ixgbe_get_i2c_ack(hw);
860 /* Device Address and read indication */
861 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
865 status = ixgbe_get_i2c_ack(hw);
869 status = ixgbe_clock_in_i2c_byte(hw, data);
873 status = ixgbe_clock_out_i2c_bit(hw, nack);
881 ixgbe_i2c_bus_clear(hw);
883 if (retry < max_retry)
884 hw_dbg(hw, "I2C byte read error - Retrying.\n");
886 hw_dbg(hw, "I2C byte read error.\n");
888 } while (retry < max_retry);
894 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
895 * @hw: pointer to hardware structure
896 * @byte_offset: byte offset to write
897 * @data: value to write
899 * Performs byte write operation to SFP module's EEPROM over I2C interface at
900 * a specified device address.
902 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
903 u8 dev_addr, u8 data)
912 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
916 status = ixgbe_get_i2c_ack(hw);
920 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
924 status = ixgbe_get_i2c_ack(hw);
928 status = ixgbe_clock_out_i2c_byte(hw, data);
932 status = ixgbe_get_i2c_ack(hw);
940 ixgbe_i2c_bus_clear(hw);
942 if (retry < max_retry)
943 hw_dbg(hw, "I2C byte write error - Retrying.\n");
945 hw_dbg(hw, "I2C byte write error.\n");
946 } while (retry < max_retry);
952 * ixgbe_i2c_start - Sets I2C start condition
953 * @hw: pointer to hardware structure
955 * Sets I2C start condition (High -> Low on SDA while SCL is High)
957 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
959 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
961 /* Start condition must begin with data and clock high */
962 ixgbe_set_i2c_data(hw, &i2cctl, 1);
963 ixgbe_raise_i2c_clk(hw, &i2cctl);
965 /* Setup time for start condition (4.7us) */
966 udelay(IXGBE_I2C_T_SU_STA);
968 ixgbe_set_i2c_data(hw, &i2cctl, 0);
970 /* Hold time for start condition (4us) */
971 udelay(IXGBE_I2C_T_HD_STA);
973 ixgbe_lower_i2c_clk(hw, &i2cctl);
975 /* Minimum low period of clock is 4.7 us */
976 udelay(IXGBE_I2C_T_LOW);
981 * ixgbe_i2c_stop - Sets I2C stop condition
982 * @hw: pointer to hardware structure
984 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
986 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
988 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
990 /* Stop condition must begin with data low and clock high */
991 ixgbe_set_i2c_data(hw, &i2cctl, 0);
992 ixgbe_raise_i2c_clk(hw, &i2cctl);
994 /* Setup time for stop condition (4us) */
995 udelay(IXGBE_I2C_T_SU_STO);
997 ixgbe_set_i2c_data(hw, &i2cctl, 1);
999 /* bus free time between stop and start (4.7us)*/
1000 udelay(IXGBE_I2C_T_BUF);
1004 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
1005 * @hw: pointer to hardware structure
1006 * @data: data byte to clock in
1008 * Clocks in one byte data via I2C data/clock
1010 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
1016 for (i = 7; i >= 0; i--) {
1017 status = ixgbe_clock_in_i2c_bit(hw, &bit);
1028 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1029 * @hw: pointer to hardware structure
1030 * @data: data byte clocked out
1032 * Clocks out one byte data via I2C data/clock
1034 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1041 for (i = 7; i >= 0; i--) {
1042 bit = (data >> i) & 0x1;
1043 status = ixgbe_clock_out_i2c_bit(hw, bit);
1049 /* Release SDA line (set high) */
1050 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1051 i2cctl |= IXGBE_I2C_DATA_OUT;
1052 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1058 * ixgbe_get_i2c_ack - Polls for I2C ACK
1059 * @hw: pointer to hardware structure
1061 * Clocks in/out one bit via I2C data/clock
1063 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1067 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1071 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1076 /* Minimum high period of clock is 4us */
1077 udelay(IXGBE_I2C_T_HIGH);
1079 /* Poll for ACK. Note that ACK in I2C spec is
1080 * transition from 1 to 0 */
1081 for (i = 0; i < timeout; i++) {
1082 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1083 ack = ixgbe_get_i2c_data(&i2cctl);
1091 hw_dbg(hw, "I2C ack was not received.\n");
1092 status = IXGBE_ERR_I2C;
1095 ixgbe_lower_i2c_clk(hw, &i2cctl);
1097 /* Minimum low period of clock is 4.7 us */
1098 udelay(IXGBE_I2C_T_LOW);
1105 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1106 * @hw: pointer to hardware structure
1107 * @data: read data value
1109 * Clocks in one bit via I2C data/clock
1111 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1114 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1116 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1118 /* Minimum high period of clock is 4us */
1119 udelay(IXGBE_I2C_T_HIGH);
1121 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1122 *data = ixgbe_get_i2c_data(&i2cctl);
1124 ixgbe_lower_i2c_clk(hw, &i2cctl);
1126 /* Minimum low period of clock is 4.7 us */
1127 udelay(IXGBE_I2C_T_LOW);
1133 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1134 * @hw: pointer to hardware structure
1135 * @data: data value to write
1137 * Clocks out one bit via I2C data/clock
1139 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1142 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1144 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1146 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1148 /* Minimum high period of clock is 4us */
1149 udelay(IXGBE_I2C_T_HIGH);
1151 ixgbe_lower_i2c_clk(hw, &i2cctl);
1153 /* Minimum low period of clock is 4.7 us.
1154 * This also takes care of the data hold time.
1156 udelay(IXGBE_I2C_T_LOW);
1158 status = IXGBE_ERR_I2C;
1159 hw_dbg(hw, "I2C data was not set to %X\n", data);
1165 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1166 * @hw: pointer to hardware structure
1167 * @i2cctl: Current value of I2CCTL register
1169 * Raises the I2C clock line '0'->'1'
1171 static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1175 *i2cctl |= IXGBE_I2C_CLK_OUT;
1177 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1179 /* SCL rise time (1000ns) */
1180 udelay(IXGBE_I2C_T_RISE);
1186 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1187 * @hw: pointer to hardware structure
1188 * @i2cctl: Current value of I2CCTL register
1190 * Lowers the I2C clock line '1'->'0'
1192 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1195 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1197 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1199 /* SCL fall time (300ns) */
1200 udelay(IXGBE_I2C_T_FALL);
1204 * ixgbe_set_i2c_data - Sets the I2C data bit
1205 * @hw: pointer to hardware structure
1206 * @i2cctl: Current value of I2CCTL register
1207 * @data: I2C data value (0 or 1) to set
1209 * Sets the I2C data bit
1211 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1216 *i2cctl |= IXGBE_I2C_DATA_OUT;
1218 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1220 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1222 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1223 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1225 /* Verify data was set correctly */
1226 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1227 if (data != ixgbe_get_i2c_data(i2cctl)) {
1228 status = IXGBE_ERR_I2C;
1229 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1236 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1237 * @hw: pointer to hardware structure
1238 * @i2cctl: Current value of I2CCTL register
1240 * Returns the I2C data bit value
1242 static bool ixgbe_get_i2c_data(u32 *i2cctl)
1246 if (*i2cctl & IXGBE_I2C_DATA_IN)
1255 * ixgbe_i2c_bus_clear - Clears the I2C bus
1256 * @hw: pointer to hardware structure
1258 * Clears the I2C bus by sending nine clock pulses.
1259 * Used when data line is stuck low.
1261 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1263 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1266 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1268 for (i = 0; i < 9; i++) {
1269 ixgbe_raise_i2c_clk(hw, &i2cctl);
1271 /* Min high period of clock is 4us */
1272 udelay(IXGBE_I2C_T_HIGH);
1274 ixgbe_lower_i2c_clk(hw, &i2cctl);
1276 /* Min low period of clock is 4.7us*/
1277 udelay(IXGBE_I2C_T_LOW);
1280 /* Put the i2c bus back to default state */
1285 * ixgbe_check_phy_link_tnx - Determine link and speed status
1286 * @hw: pointer to hardware structure
1288 * Reads the VS1 register to determine if link is up and the current speed for
1291 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
1296 u32 max_time_out = 10;
1301 /* Initialize speed and link to default case */
1303 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1306 * Check current speed and link status of the PHY register.
1307 * This is a vendor specific register and may have to
1308 * be changed for other copper PHYs.
1310 for (time_out = 0; time_out < max_time_out; time_out++) {
1312 status = hw->phy.ops.read_reg(hw,
1313 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
1316 phy_link = phy_data &
1317 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
1318 phy_speed = phy_data &
1319 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
1320 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
1323 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
1324 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1333 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
1334 * @hw: pointer to hardware structure
1335 * @firmware_version: pointer to the PHY Firmware Version
1337 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1338 u16 *firmware_version)
1342 status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,