1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 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 bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
48 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
49 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
52 * ixgbe_identify_phy_generic - Get physical layer module
53 * @hw: pointer to hardware structure
55 * Determines the physical layer module found on the current adapter.
57 s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
59 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
62 if (hw->phy.type == ixgbe_phy_unknown) {
63 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
64 if (ixgbe_validate_phy_addr(hw, phy_addr)) {
65 hw->phy.addr = phy_addr;
68 ixgbe_get_phy_type_from_id(hw->phy.id);
81 * ixgbe_validate_phy_addr - Determines phy address is valid
82 * @hw: pointer to hardware structure
85 static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
90 hw->phy.addr = phy_addr;
91 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
92 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
94 if (phy_id != 0xFFFF && phy_id != 0x0)
101 * ixgbe_get_phy_id - Get the phy type
102 * @hw: pointer to hardware structure
105 static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
111 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
112 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
116 hw->phy.id = (u32)(phy_id_high << 16);
117 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
118 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
120 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
121 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
127 * ixgbe_get_phy_type_from_id - Get the phy type
128 * @hw: pointer to hardware structure
131 static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
133 enum ixgbe_phy_type phy_type;
137 phy_type = ixgbe_phy_tn;
140 phy_type = ixgbe_phy_qt;
143 phy_type = ixgbe_phy_nl;
146 phy_type = ixgbe_phy_unknown;
154 * ixgbe_reset_phy_generic - Performs a PHY reset
155 * @hw: pointer to hardware structure
157 s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
160 * Perform soft PHY reset to the PHY_XS.
161 * This will cause a soft reset to the PHY
163 return hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
164 IXGBE_MDIO_PHY_XS_DEV_TYPE,
165 IXGBE_MDIO_PHY_XS_RESET);
169 * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
170 * @hw: pointer to hardware structure
171 * @reg_addr: 32 bit address of PHY register to read
172 * @phy_data: Pointer to read data from PHY register
174 s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
175 u32 device_type, u16 *phy_data)
183 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
184 gssr = IXGBE_GSSR_PHY1_SM;
186 gssr = IXGBE_GSSR_PHY0_SM;
188 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
189 status = IXGBE_ERR_SWFW_SYNC;
192 /* Setup and write the address cycle command */
193 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
194 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
195 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
196 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
198 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
201 * Check every 10 usec to see if the address cycle completed.
202 * The MDI Command bit will clear when the operation is
205 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
208 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
210 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
214 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
215 hw_dbg(hw, "PHY address command did not complete.\n");
216 status = IXGBE_ERR_PHY;
221 * Address cycle complete, setup and write the read
224 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
225 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
226 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
227 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
229 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
232 * Check every 10 usec to see if the address cycle
233 * completed. The MDI Command bit will clear when the
234 * operation is complete
236 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
239 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
241 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
245 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
246 hw_dbg(hw, "PHY read command didn't complete\n");
247 status = IXGBE_ERR_PHY;
250 * Read operation is complete. Get the data
253 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
254 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
255 *phy_data = (u16)(data);
259 ixgbe_release_swfw_sync(hw, gssr);
266 * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
267 * @hw: pointer to hardware structure
268 * @reg_addr: 32 bit PHY register to write
269 * @device_type: 5 bit device type
270 * @phy_data: Data to write to the PHY register
272 s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
273 u32 device_type, u16 phy_data)
280 if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
281 gssr = IXGBE_GSSR_PHY1_SM;
283 gssr = IXGBE_GSSR_PHY0_SM;
285 if (ixgbe_acquire_swfw_sync(hw, gssr) != 0)
286 status = IXGBE_ERR_SWFW_SYNC;
289 /* Put the data in the MDI single read and write data register*/
290 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
292 /* Setup and write the address cycle command */
293 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
294 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
295 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
296 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
298 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
301 * Check every 10 usec to see if the address cycle completed.
302 * The MDI Command bit will clear when the operation is
305 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
308 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
310 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
314 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
315 hw_dbg(hw, "PHY address cmd didn't complete\n");
316 status = IXGBE_ERR_PHY;
321 * Address cycle complete, setup and write the write
324 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
325 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
326 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
327 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
329 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
332 * Check every 10 usec to see if the address cycle
333 * completed. The MDI Command bit will clear when the
334 * operation is complete
336 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
339 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
341 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
345 if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
346 hw_dbg(hw, "PHY address cmd didn't complete\n");
347 status = IXGBE_ERR_PHY;
351 ixgbe_release_swfw_sync(hw, gssr);
358 * ixgbe_setup_phy_link_generic - Set and restart autoneg
359 * @hw: pointer to hardware structure
361 * Restart autonegotiation and PHY and waits for completion.
363 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
365 s32 status = IXGBE_NOT_IMPLEMENTED;
367 u32 max_time_out = 10;
368 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
371 * Set advertisement settings in PHY based on autoneg_advertised
372 * settings. If autoneg_advertised = 0, then advertise default values
373 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
376 hw->phy.ops.read_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
377 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
379 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
380 autoneg_reg &= 0xEFFF; /* 0 in bit 12 is 1G operation */
382 autoneg_reg |= 0x1000; /* 1 in bit 12 is 10G/1G operation */
384 hw->phy.ops.write_reg(hw, IXGBE_MII_SPEED_SELECTION_REG,
385 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
387 /* Restart PHY autonegotiation and wait for completion */
388 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
389 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
391 autoneg_reg |= IXGBE_MII_RESTART;
393 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
394 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
396 /* Wait for autonegotiation to finish */
397 for (time_out = 0; time_out < max_time_out; time_out++) {
399 /* Restart PHY autonegotiation and wait for completion */
400 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
401 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
404 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE;
405 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE) {
411 if (time_out == max_time_out)
412 status = IXGBE_ERR_LINK_SETUP;
418 * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
419 * @hw: pointer to hardware structure
420 * @speed: new link speed
421 * @autoneg: true if autonegotiation enabled
423 s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
424 ixgbe_link_speed speed,
426 bool autoneg_wait_to_complete)
430 * Clear autoneg_advertised and set new values based on input link
433 hw->phy.autoneg_advertised = 0;
435 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
436 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
438 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
439 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
441 /* Setup link based on the new speed settings */
442 hw->phy.ops.setup_link(hw);
448 * ixgbe_reset_phy_nl - Performs a PHY reset
449 * @hw: pointer to hardware structure
451 s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
453 u16 phy_offset, control, eword, edata, block_crc;
454 bool end_data = false;
455 u16 list_offset, data_offset;
460 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
461 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
463 /* reset the PHY and poll for completion */
464 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
465 IXGBE_MDIO_PHY_XS_DEV_TYPE,
466 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
468 for (i = 0; i < 100; i++) {
469 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
470 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
471 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
476 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
477 hw_dbg(hw, "PHY reset did not complete.\n");
478 ret_val = IXGBE_ERR_PHY;
482 /* Get init offsets */
483 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
488 ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
492 * Read control word from PHY init contents offset
494 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
495 control = (eword & IXGBE_CONTROL_MASK_NL) >>
496 IXGBE_CONTROL_SHIFT_NL;
497 edata = eword & IXGBE_DATA_MASK_NL;
501 hw_dbg(hw, "DELAY: %d MS\n", edata);
505 hw_dbg(hw, "DATA: \n");
507 hw->eeprom.ops.read(hw, data_offset++,
509 for (i = 0; i < edata; i++) {
510 hw->eeprom.ops.read(hw, data_offset, &eword);
511 hw->phy.ops.write_reg(hw, phy_offset,
512 IXGBE_TWINAX_DEV, eword);
513 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
519 case IXGBE_CONTROL_NL:
521 hw_dbg(hw, "CONTROL: \n");
522 if (edata == IXGBE_CONTROL_EOL_NL) {
525 } else if (edata == IXGBE_CONTROL_SOL_NL) {
528 hw_dbg(hw, "Bad control value\n");
529 ret_val = IXGBE_ERR_PHY;
534 hw_dbg(hw, "Bad control type\n");
535 ret_val = IXGBE_ERR_PHY;
545 * ixgbe_identify_sfp_module_generic - Identifies SFP module and assigns
547 * @hw: pointer to hardware structure
549 * Searches for and indentifies the SFP module. Assings appropriate PHY type.
551 s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
553 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
555 enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
557 u8 comp_codes_1g = 0;
558 u8 comp_codes_10g = 0;
559 u8 oui_bytes[3] = {0, 0, 0};
560 u8 transmission_media = 0;
563 status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
566 if (status == IXGBE_ERR_SFP_NOT_PRESENT) {
567 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
571 if (identifier == IXGBE_SFF_IDENTIFIER_SFP) {
572 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_1GBE_COMP_CODES,
574 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_10GBE_COMP_CODES,
576 hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_TRANSMISSION_MEDIA,
577 &transmission_media);
584 * 3 SFP_DA_CORE0 - 82599-specific
585 * 4 SFP_DA_CORE1 - 82599-specific
586 * 5 SFP_SR/LR_CORE0 - 82599-specific
587 * 6 SFP_SR/LR_CORE1 - 82599-specific
589 if (hw->mac.type == ixgbe_mac_82598EB) {
590 if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
591 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
592 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
593 hw->phy.sfp_type = ixgbe_sfp_type_sr;
594 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
595 hw->phy.sfp_type = ixgbe_sfp_type_lr;
597 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
598 } else if (hw->mac.type == ixgbe_mac_82599EB) {
599 if (transmission_media & IXGBE_SFF_TWIN_AX_CAPABLE)
600 if (hw->bus.lan_id == 0)
602 ixgbe_sfp_type_da_cu_core0;
605 ixgbe_sfp_type_da_cu_core1;
606 else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
607 if (hw->bus.lan_id == 0)
609 ixgbe_sfp_type_srlr_core0;
612 ixgbe_sfp_type_srlr_core1;
613 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
614 if (hw->bus.lan_id == 0)
616 ixgbe_sfp_type_srlr_core0;
619 ixgbe_sfp_type_srlr_core1;
621 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
624 if (hw->phy.sfp_type != stored_sfp_type)
625 hw->phy.sfp_setup_needed = true;
627 /* Determine if the SFP+ PHY is dual speed or not. */
628 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
629 (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
630 ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
631 (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
632 hw->phy.multispeed_fiber = true;
634 /* Determine PHY vendor */
635 if (hw->phy.type != ixgbe_phy_nl) {
636 hw->phy.id = identifier;
637 hw->phy.ops.read_i2c_eeprom(hw,
638 IXGBE_SFF_VENDOR_OUI_BYTE0,
640 hw->phy.ops.read_i2c_eeprom(hw,
641 IXGBE_SFF_VENDOR_OUI_BYTE1,
643 hw->phy.ops.read_i2c_eeprom(hw,
644 IXGBE_SFF_VENDOR_OUI_BYTE2,
648 ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
649 (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
650 (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
652 switch (vendor_oui) {
653 case IXGBE_SFF_VENDOR_OUI_TYCO:
654 if (transmission_media &
655 IXGBE_SFF_TWIN_AX_CAPABLE)
656 hw->phy.type = ixgbe_phy_tw_tyco;
658 case IXGBE_SFF_VENDOR_OUI_FTL:
659 hw->phy.type = ixgbe_phy_sfp_ftl;
661 case IXGBE_SFF_VENDOR_OUI_AVAGO:
662 hw->phy.type = ixgbe_phy_sfp_avago;
664 case IXGBE_SFF_VENDOR_OUI_INTEL:
665 hw->phy.type = ixgbe_phy_sfp_intel;
668 if (transmission_media &
669 IXGBE_SFF_TWIN_AX_CAPABLE)
670 hw->phy.type = ixgbe_phy_tw_unknown;
672 hw->phy.type = ixgbe_phy_sfp_unknown;
676 if (hw->mac.type == ixgbe_mac_82598EB ||
677 (hw->phy.sfp_type != ixgbe_sfp_type_sr &&
678 hw->phy.sfp_type != ixgbe_sfp_type_lr &&
679 hw->phy.sfp_type != ixgbe_sfp_type_srlr_core0 &&
680 hw->phy.sfp_type != ixgbe_sfp_type_srlr_core1)) {
685 /* This is guaranteed to be 82599, no need to check for NULL */
686 hw->mac.ops.get_device_caps(hw, &enforce_sfp);
687 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
688 /* Make sure we're a supported PHY type */
689 if (hw->phy.type == ixgbe_phy_sfp_intel) {
692 hw_dbg(hw, "SFP+ module not supported\n");
693 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
705 * ixgbe_get_sfp_init_sequence_offsets - Checks the MAC's EEPROM to see
706 * if it supports a given SFP+ module type, if so it returns the offsets to the
707 * phy init sequence block.
708 * @hw: pointer to hardware structure
709 * @list_offset: offset to the SFP ID list
710 * @data_offset: offset to the SFP data block
712 s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
718 if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
719 return IXGBE_ERR_SFP_NOT_SUPPORTED;
721 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
722 return IXGBE_ERR_SFP_NOT_PRESENT;
724 if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
725 (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
726 return IXGBE_ERR_SFP_NOT_SUPPORTED;
728 /* Read offset to PHY init contents */
729 hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset);
731 if ((!*list_offset) || (*list_offset == 0xFFFF))
732 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
734 /* Shift offset to first ID word */
738 * Find the matching SFP ID in the EEPROM
739 * and program the init sequence
741 hw->eeprom.ops.read(hw, *list_offset, &sfp_id);
743 while (sfp_id != IXGBE_PHY_INIT_END_NL) {
744 if (sfp_id == hw->phy.sfp_type) {
746 hw->eeprom.ops.read(hw, *list_offset, data_offset);
747 if ((!*data_offset) || (*data_offset == 0xFFFF)) {
748 hw_dbg(hw, "SFP+ module not supported\n");
749 return IXGBE_ERR_SFP_NOT_SUPPORTED;
755 if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
756 return IXGBE_ERR_PHY;
760 if (sfp_id == IXGBE_PHY_INIT_END_NL) {
761 hw_dbg(hw, "No matching SFP+ module found\n");
762 return IXGBE_ERR_SFP_NOT_SUPPORTED;
769 * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
770 * @hw: pointer to hardware structure
771 * @byte_offset: EEPROM byte offset to read
772 * @eeprom_data: value read
774 * Performs byte read operation to SFP module's EEPROM over I2C interface.
776 s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
779 return hw->phy.ops.read_i2c_byte(hw, byte_offset,
780 IXGBE_I2C_EEPROM_DEV_ADDR,
785 * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
786 * @hw: pointer to hardware structure
787 * @byte_offset: EEPROM byte offset to write
788 * @eeprom_data: value to write
790 * Performs byte write operation to SFP module's EEPROM over I2C interface.
792 s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
795 return hw->phy.ops.write_i2c_byte(hw, byte_offset,
796 IXGBE_I2C_EEPROM_DEV_ADDR,
801 * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
802 * @hw: pointer to hardware structure
803 * @byte_offset: byte offset to read
806 * Performs byte read operation to SFP module's EEPROM over I2C interface at
807 * a specified deivce address.
809 s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
810 u8 dev_addr, u8 *data)
820 /* Device Address and write indication */
821 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
825 status = ixgbe_get_i2c_ack(hw);
829 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
833 status = ixgbe_get_i2c_ack(hw);
839 /* Device Address and read indication */
840 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
844 status = ixgbe_get_i2c_ack(hw);
848 status = ixgbe_clock_in_i2c_byte(hw, data);
852 status = ixgbe_clock_out_i2c_bit(hw, nack);
860 ixgbe_i2c_bus_clear(hw);
862 if (retry < max_retry)
863 hw_dbg(hw, "I2C byte read error - Retrying.\n");
865 hw_dbg(hw, "I2C byte read error.\n");
867 } while (retry < max_retry);
873 * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
874 * @hw: pointer to hardware structure
875 * @byte_offset: byte offset to write
876 * @data: value to write
878 * Performs byte write operation to SFP module's EEPROM over I2C interface at
879 * a specified device address.
881 s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
882 u8 dev_addr, u8 data)
891 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
895 status = ixgbe_get_i2c_ack(hw);
899 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
903 status = ixgbe_get_i2c_ack(hw);
907 status = ixgbe_clock_out_i2c_byte(hw, data);
911 status = ixgbe_get_i2c_ack(hw);
919 ixgbe_i2c_bus_clear(hw);
921 if (retry < max_retry)
922 hw_dbg(hw, "I2C byte write error - Retrying.\n");
924 hw_dbg(hw, "I2C byte write error.\n");
925 } while (retry < max_retry);
931 * ixgbe_i2c_start - Sets I2C start condition
932 * @hw: pointer to hardware structure
934 * Sets I2C start condition (High -> Low on SDA while SCL is High)
936 static void ixgbe_i2c_start(struct ixgbe_hw *hw)
938 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
940 /* Start condition must begin with data and clock high */
941 ixgbe_set_i2c_data(hw, &i2cctl, 1);
942 ixgbe_raise_i2c_clk(hw, &i2cctl);
944 /* Setup time for start condition (4.7us) */
945 udelay(IXGBE_I2C_T_SU_STA);
947 ixgbe_set_i2c_data(hw, &i2cctl, 0);
949 /* Hold time for start condition (4us) */
950 udelay(IXGBE_I2C_T_HD_STA);
952 ixgbe_lower_i2c_clk(hw, &i2cctl);
954 /* Minimum low period of clock is 4.7 us */
955 udelay(IXGBE_I2C_T_LOW);
960 * ixgbe_i2c_stop - Sets I2C stop condition
961 * @hw: pointer to hardware structure
963 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
965 static void ixgbe_i2c_stop(struct ixgbe_hw *hw)
967 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
969 /* Stop condition must begin with data low and clock high */
970 ixgbe_set_i2c_data(hw, &i2cctl, 0);
971 ixgbe_raise_i2c_clk(hw, &i2cctl);
973 /* Setup time for stop condition (4us) */
974 udelay(IXGBE_I2C_T_SU_STO);
976 ixgbe_set_i2c_data(hw, &i2cctl, 1);
978 /* bus free time between stop and start (4.7us)*/
979 udelay(IXGBE_I2C_T_BUF);
983 * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
984 * @hw: pointer to hardware structure
985 * @data: data byte to clock in
987 * Clocks in one byte data via I2C data/clock
989 static s32 ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
995 for (i = 7; i >= 0; i--) {
996 status = ixgbe_clock_in_i2c_bit(hw, &bit);
1007 * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
1008 * @hw: pointer to hardware structure
1009 * @data: data byte clocked out
1011 * Clocks out one byte data via I2C data/clock
1013 static s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
1020 for (i = 7; i >= 0; i--) {
1021 bit = (data >> i) & 0x1;
1022 status = ixgbe_clock_out_i2c_bit(hw, bit);
1028 /* Release SDA line (set high) */
1029 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1030 i2cctl |= IXGBE_I2C_DATA_OUT;
1031 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, i2cctl);
1037 * ixgbe_get_i2c_ack - Polls for I2C ACK
1038 * @hw: pointer to hardware structure
1040 * Clocks in/out one bit via I2C data/clock
1042 static s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
1046 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1050 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1055 /* Minimum high period of clock is 4us */
1056 udelay(IXGBE_I2C_T_HIGH);
1058 /* Poll for ACK. Note that ACK in I2C spec is
1059 * transition from 1 to 0 */
1060 for (i = 0; i < timeout; i++) {
1061 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1062 ack = ixgbe_get_i2c_data(&i2cctl);
1070 hw_dbg(hw, "I2C ack was not received.\n");
1071 status = IXGBE_ERR_I2C;
1074 ixgbe_lower_i2c_clk(hw, &i2cctl);
1076 /* Minimum low period of clock is 4.7 us */
1077 udelay(IXGBE_I2C_T_LOW);
1084 * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
1085 * @hw: pointer to hardware structure
1086 * @data: read data value
1088 * Clocks in one bit via I2C data/clock
1090 static s32 ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
1093 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1095 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1097 /* Minimum high period of clock is 4us */
1098 udelay(IXGBE_I2C_T_HIGH);
1100 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1101 *data = ixgbe_get_i2c_data(&i2cctl);
1103 ixgbe_lower_i2c_clk(hw, &i2cctl);
1105 /* Minimum low period of clock is 4.7 us */
1106 udelay(IXGBE_I2C_T_LOW);
1112 * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
1113 * @hw: pointer to hardware structure
1114 * @data: data value to write
1116 * Clocks out one bit via I2C data/clock
1118 static s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
1121 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1123 status = ixgbe_set_i2c_data(hw, &i2cctl, data);
1125 status = ixgbe_raise_i2c_clk(hw, &i2cctl);
1127 /* Minimum high period of clock is 4us */
1128 udelay(IXGBE_I2C_T_HIGH);
1130 ixgbe_lower_i2c_clk(hw, &i2cctl);
1132 /* Minimum low period of clock is 4.7 us.
1133 * This also takes care of the data hold time.
1135 udelay(IXGBE_I2C_T_LOW);
1137 status = IXGBE_ERR_I2C;
1138 hw_dbg(hw, "I2C data was not set to %X\n", data);
1144 * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
1145 * @hw: pointer to hardware structure
1146 * @i2cctl: Current value of I2CCTL register
1148 * Raises the I2C clock line '0'->'1'
1150 static s32 ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1154 *i2cctl |= IXGBE_I2C_CLK_OUT;
1156 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1158 /* SCL rise time (1000ns) */
1159 udelay(IXGBE_I2C_T_RISE);
1165 * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
1166 * @hw: pointer to hardware structure
1167 * @i2cctl: Current value of I2CCTL register
1169 * Lowers the I2C clock line '1'->'0'
1171 static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
1174 *i2cctl &= ~IXGBE_I2C_CLK_OUT;
1176 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1178 /* SCL fall time (300ns) */
1179 udelay(IXGBE_I2C_T_FALL);
1183 * ixgbe_set_i2c_data - Sets the I2C data bit
1184 * @hw: pointer to hardware structure
1185 * @i2cctl: Current value of I2CCTL register
1186 * @data: I2C data value (0 or 1) to set
1188 * Sets the I2C data bit
1190 static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
1195 *i2cctl |= IXGBE_I2C_DATA_OUT;
1197 *i2cctl &= ~IXGBE_I2C_DATA_OUT;
1199 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL, *i2cctl);
1201 /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
1202 udelay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
1204 /* Verify data was set correctly */
1205 *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1206 if (data != ixgbe_get_i2c_data(i2cctl)) {
1207 status = IXGBE_ERR_I2C;
1208 hw_dbg(hw, "Error - I2C data was not set to %X.\n", data);
1215 * ixgbe_get_i2c_data - Reads the I2C SDA data bit
1216 * @hw: pointer to hardware structure
1217 * @i2cctl: Current value of I2CCTL register
1219 * Returns the I2C data bit value
1221 static bool ixgbe_get_i2c_data(u32 *i2cctl)
1225 if (*i2cctl & IXGBE_I2C_DATA_IN)
1234 * ixgbe_i2c_bus_clear - Clears the I2C bus
1235 * @hw: pointer to hardware structure
1237 * Clears the I2C bus by sending nine clock pulses.
1238 * Used when data line is stuck low.
1240 static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
1242 u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL);
1245 ixgbe_set_i2c_data(hw, &i2cctl, 1);
1247 for (i = 0; i < 9; i++) {
1248 ixgbe_raise_i2c_clk(hw, &i2cctl);
1250 /* Min high period of clock is 4us */
1251 udelay(IXGBE_I2C_T_HIGH);
1253 ixgbe_lower_i2c_clk(hw, &i2cctl);
1255 /* Min low period of clock is 4.7us*/
1256 udelay(IXGBE_I2C_T_LOW);
1259 /* Put the i2c bus back to default state */
1264 * ixgbe_check_phy_link_tnx - Determine link and speed status
1265 * @hw: pointer to hardware structure
1267 * Reads the VS1 register to determine if link is up and the current speed for
1270 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
1275 u32 max_time_out = 10;
1280 /* Initialize speed and link to default case */
1282 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1285 * Check current speed and link status of the PHY register.
1286 * This is a vendor specific register and may have to
1287 * be changed for other copper PHYs.
1289 for (time_out = 0; time_out < max_time_out; time_out++) {
1291 status = hw->phy.ops.read_reg(hw,
1292 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
1293 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1295 phy_link = phy_data &
1296 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
1297 phy_speed = phy_data &
1298 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
1299 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
1302 IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
1303 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1312 * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
1313 * @hw: pointer to hardware structure
1314 * @firmware_version: pointer to the PHY Firmware Version
1316 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1317 u16 *firmware_version)
1321 status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
1322 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,