1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-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 *******************************************************************************/
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/if_ether.h>
36 #include "e1000_mac.h"
37 #include "e1000_82575.h"
39 static s32 igb_get_invariants_82575(struct e1000_hw *);
40 static s32 igb_acquire_phy_82575(struct e1000_hw *);
41 static void igb_release_phy_82575(struct e1000_hw *);
42 static s32 igb_acquire_nvm_82575(struct e1000_hw *);
43 static void igb_release_nvm_82575(struct e1000_hw *);
44 static s32 igb_check_for_link_82575(struct e1000_hw *);
45 static s32 igb_get_cfg_done_82575(struct e1000_hw *);
46 static s32 igb_init_hw_82575(struct e1000_hw *);
47 static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
48 static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
49 static s32 igb_reset_hw_82575(struct e1000_hw *);
50 static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
51 static s32 igb_setup_copper_link_82575(struct e1000_hw *);
52 static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
53 static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
54 static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
55 static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
56 static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
58 static s32 igb_get_phy_id_82575(struct e1000_hw *);
59 static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
60 static bool igb_sgmii_active_82575(struct e1000_hw *);
61 static s32 igb_reset_init_script_82575(struct e1000_hw *);
62 static s32 igb_read_mac_addr_82575(struct e1000_hw *);
63 static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
65 static s32 igb_get_invariants_82575(struct e1000_hw *hw)
67 struct e1000_phy_info *phy = &hw->phy;
68 struct e1000_nvm_info *nvm = &hw->nvm;
69 struct e1000_mac_info *mac = &hw->mac;
70 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
76 switch (hw->device_id) {
77 case E1000_DEV_ID_82575EB_COPPER:
78 case E1000_DEV_ID_82575EB_FIBER_SERDES:
79 case E1000_DEV_ID_82575GB_QUAD_COPPER:
80 mac->type = e1000_82575;
82 case E1000_DEV_ID_82576:
83 case E1000_DEV_ID_82576_NS:
84 case E1000_DEV_ID_82576_NS_SERDES:
85 case E1000_DEV_ID_82576_FIBER:
86 case E1000_DEV_ID_82576_SERDES:
87 case E1000_DEV_ID_82576_QUAD_COPPER:
88 case E1000_DEV_ID_82576_SERDES_QUAD:
89 mac->type = e1000_82576;
92 return -E1000_ERR_MAC_INIT;
98 * The 82575 uses bits 22:23 for link mode. The mode can be changed
99 * based on the EEPROM. We cannot rely upon device ID. There
100 * is no distinguishable difference between fiber and internal
101 * SerDes mode on the 82575. There can be an external PHY attached
102 * on the SGMII interface. For this, we'll set sgmii_active to true.
104 phy->media_type = e1000_media_type_copper;
105 dev_spec->sgmii_active = false;
107 ctrl_ext = rd32(E1000_CTRL_EXT);
108 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
109 case E1000_CTRL_EXT_LINK_MODE_SGMII:
110 dev_spec->sgmii_active = true;
111 ctrl_ext |= E1000_CTRL_I2C_ENA;
113 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
114 hw->phy.media_type = e1000_media_type_internal_serdes;
115 ctrl_ext |= E1000_CTRL_I2C_ENA;
118 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
122 wr32(E1000_CTRL_EXT, ctrl_ext);
124 /* Set mta register count */
125 mac->mta_reg_count = 128;
126 /* Set rar entry count */
127 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
128 if (mac->type == e1000_82576)
129 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
130 /* Set if part includes ASF firmware */
131 mac->asf_firmware_present = true;
132 /* Set if manageability features are enabled. */
133 mac->arc_subsystem_valid =
134 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
137 /* physical interface link setup */
138 mac->ops.setup_physical_interface =
139 (hw->phy.media_type == e1000_media_type_copper)
140 ? igb_setup_copper_link_82575
141 : igb_setup_serdes_link_82575;
143 /* NVM initialization */
144 eecd = rd32(E1000_EECD);
146 nvm->opcode_bits = 8;
148 switch (nvm->override) {
149 case e1000_nvm_override_spi_large:
151 nvm->address_bits = 16;
153 case e1000_nvm_override_spi_small:
155 nvm->address_bits = 8;
158 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
159 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
163 nvm->type = e1000_nvm_eeprom_spi;
165 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
166 E1000_EECD_SIZE_EX_SHIFT);
169 * Added to a constant, "size" becomes the left-shift value
170 * for setting word_size.
172 size += NVM_WORD_SIZE_BASE_SHIFT;
174 /* EEPROM access above 16k is unsupported */
177 nvm->word_size = 1 << size;
179 /* if 82576 then initialize mailbox parameters */
180 if (mac->type == e1000_82576)
181 igb_init_mbx_params_pf(hw);
183 /* setup PHY parameters */
184 if (phy->media_type != e1000_media_type_copper) {
185 phy->type = e1000_phy_none;
189 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
190 phy->reset_delay_us = 100;
192 /* PHY function pointers */
193 if (igb_sgmii_active_82575(hw)) {
194 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
195 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
196 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
198 phy->ops.reset = igb_phy_hw_reset;
199 phy->ops.read_reg = igb_read_phy_reg_igp;
200 phy->ops.write_reg = igb_write_phy_reg_igp;
204 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
205 E1000_STATUS_FUNC_SHIFT;
207 /* Set phy->phy_addr and phy->id. */
208 ret_val = igb_get_phy_id_82575(hw);
212 /* Verify phy id and set remaining function pointers */
214 case M88E1111_I_PHY_ID:
215 phy->type = e1000_phy_m88;
216 phy->ops.get_phy_info = igb_get_phy_info_m88;
217 phy->ops.get_cable_length = igb_get_cable_length_m88;
218 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
220 case IGP03E1000_E_PHY_ID:
221 phy->type = e1000_phy_igp_3;
222 phy->ops.get_phy_info = igb_get_phy_info_igp;
223 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
224 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
225 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
226 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
229 return -E1000_ERR_PHY;
236 * igb_acquire_phy_82575 - Acquire rights to access PHY
237 * @hw: pointer to the HW structure
239 * Acquire access rights to the correct PHY. This is a
240 * function pointer entry point called by the api module.
242 static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
244 u16 mask = E1000_SWFW_PHY0_SM;
246 if (hw->bus.func == E1000_FUNC_1)
247 mask = E1000_SWFW_PHY1_SM;
249 return igb_acquire_swfw_sync_82575(hw, mask);
253 * igb_release_phy_82575 - Release rights to access PHY
254 * @hw: pointer to the HW structure
256 * A wrapper to release access rights to the correct PHY. This is a
257 * function pointer entry point called by the api module.
259 static void igb_release_phy_82575(struct e1000_hw *hw)
261 u16 mask = E1000_SWFW_PHY0_SM;
263 if (hw->bus.func == E1000_FUNC_1)
264 mask = E1000_SWFW_PHY1_SM;
266 igb_release_swfw_sync_82575(hw, mask);
270 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
271 * @hw: pointer to the HW structure
272 * @offset: register offset to be read
273 * @data: pointer to the read data
275 * Reads the PHY register at offset using the serial gigabit media independent
276 * interface and stores the retrieved information in data.
278 static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
281 s32 ret_val = -E1000_ERR_PARAM;
283 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
284 hw_dbg("PHY Address %u is out of range\n", offset);
288 ret_val = hw->phy.ops.acquire(hw);
292 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
294 hw->phy.ops.release(hw);
301 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
302 * @hw: pointer to the HW structure
303 * @offset: register offset to write to
304 * @data: data to write at register offset
306 * Writes the data to PHY register at the offset using the serial gigabit
307 * media independent interface.
309 static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
312 s32 ret_val = -E1000_ERR_PARAM;
315 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
316 hw_dbg("PHY Address %d is out of range\n", offset);
320 ret_val = hw->phy.ops.acquire(hw);
324 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
326 hw->phy.ops.release(hw);
333 * igb_get_phy_id_82575 - Retrieve PHY addr and id
334 * @hw: pointer to the HW structure
336 * Retrieves the PHY address and ID for both PHY's which do and do not use
339 static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
341 struct e1000_phy_info *phy = &hw->phy;
347 * For SGMII PHYs, we try the list of possible addresses until
348 * we find one that works. For non-SGMII PHYs
349 * (e.g. integrated copper PHYs), an address of 1 should
350 * work. The result of this function should mean phy->phy_addr
351 * and phy->id are set correctly.
353 if (!(igb_sgmii_active_82575(hw))) {
355 ret_val = igb_get_phy_id(hw);
359 /* Power on sgmii phy if it is disabled */
360 ctrl_ext = rd32(E1000_CTRL_EXT);
361 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
366 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
367 * Therefore, we need to test 1-7
369 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
370 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
372 hw_dbg("Vendor ID 0x%08X read at address %u\n",
375 * At the time of this writing, The M88 part is
376 * the only supported SGMII PHY product.
378 if (phy_id == M88_VENDOR)
381 hw_dbg("PHY address %u was unreadable\n", phy->addr);
385 /* A valid PHY type couldn't be found. */
386 if (phy->addr == 8) {
388 ret_val = -E1000_ERR_PHY;
391 ret_val = igb_get_phy_id(hw);
394 /* restore previous sfp cage power state */
395 wr32(E1000_CTRL_EXT, ctrl_ext);
402 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
403 * @hw: pointer to the HW structure
405 * Resets the PHY using the serial gigabit media independent interface.
407 static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
412 * This isn't a true "hard" reset, but is the only reset
413 * available to us at this time.
416 hw_dbg("Soft resetting SGMII attached PHY...\n");
419 * SFP documentation requires the following to configure the SPF module
420 * to work on SGMII. No further documentation is given.
422 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
426 ret_val = igb_phy_sw_reset(hw);
433 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
434 * @hw: pointer to the HW structure
435 * @active: true to enable LPLU, false to disable
437 * Sets the LPLU D0 state according to the active flag. When
438 * activating LPLU this function also disables smart speed
439 * and vice versa. LPLU will not be activated unless the
440 * device autonegotiation advertisement meets standards of
441 * either 10 or 10/100 or 10/100/1000 at all duplexes.
442 * This is a function pointer entry point only called by
443 * PHY setup routines.
445 static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
447 struct e1000_phy_info *phy = &hw->phy;
451 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
456 data |= IGP02E1000_PM_D0_LPLU;
457 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
462 /* When LPLU is enabled, we should disable SmartSpeed */
463 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
465 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
466 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
471 data &= ~IGP02E1000_PM_D0_LPLU;
472 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
475 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
476 * during Dx states where the power conservation is most
477 * important. During driver activity we should enable
478 * SmartSpeed, so performance is maintained.
480 if (phy->smart_speed == e1000_smart_speed_on) {
481 ret_val = phy->ops.read_reg(hw,
482 IGP01E1000_PHY_PORT_CONFIG, &data);
486 data |= IGP01E1000_PSCFR_SMART_SPEED;
487 ret_val = phy->ops.write_reg(hw,
488 IGP01E1000_PHY_PORT_CONFIG, data);
491 } else if (phy->smart_speed == e1000_smart_speed_off) {
492 ret_val = phy->ops.read_reg(hw,
493 IGP01E1000_PHY_PORT_CONFIG, &data);
497 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
498 ret_val = phy->ops.write_reg(hw,
499 IGP01E1000_PHY_PORT_CONFIG, data);
510 * igb_acquire_nvm_82575 - Request for access to EEPROM
511 * @hw: pointer to the HW structure
513 * Acquire the necessary semaphores for exclusive access to the EEPROM.
514 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
515 * Return successful if access grant bit set, else clear the request for
516 * EEPROM access and return -E1000_ERR_NVM (-1).
518 static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
522 ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
526 ret_val = igb_acquire_nvm(hw);
529 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
536 * igb_release_nvm_82575 - Release exclusive access to EEPROM
537 * @hw: pointer to the HW structure
539 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
540 * then release the semaphores acquired.
542 static void igb_release_nvm_82575(struct e1000_hw *hw)
545 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
549 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
550 * @hw: pointer to the HW structure
551 * @mask: specifies which semaphore to acquire
553 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
554 * will also specify which port we're acquiring the lock for.
556 static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
560 u32 fwmask = mask << 16;
562 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
564 while (i < timeout) {
565 if (igb_get_hw_semaphore(hw)) {
566 ret_val = -E1000_ERR_SWFW_SYNC;
570 swfw_sync = rd32(E1000_SW_FW_SYNC);
571 if (!(swfw_sync & (fwmask | swmask)))
575 * Firmware currently using resource (fwmask)
576 * or other software thread using resource (swmask)
578 igb_put_hw_semaphore(hw);
584 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
585 ret_val = -E1000_ERR_SWFW_SYNC;
590 wr32(E1000_SW_FW_SYNC, swfw_sync);
592 igb_put_hw_semaphore(hw);
599 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
600 * @hw: pointer to the HW structure
601 * @mask: specifies which semaphore to acquire
603 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
604 * will also specify which port we're releasing the lock for.
606 static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
610 while (igb_get_hw_semaphore(hw) != 0);
613 swfw_sync = rd32(E1000_SW_FW_SYNC);
615 wr32(E1000_SW_FW_SYNC, swfw_sync);
617 igb_put_hw_semaphore(hw);
621 * igb_get_cfg_done_82575 - Read config done bit
622 * @hw: pointer to the HW structure
624 * Read the management control register for the config done bit for
625 * completion status. NOTE: silicon which is EEPROM-less will fail trying
626 * to read the config done bit, so an error is *ONLY* logged and returns
627 * 0. If we were to return with error, EEPROM-less silicon
628 * would not be able to be reset or change link.
630 static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
632 s32 timeout = PHY_CFG_TIMEOUT;
634 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
636 if (hw->bus.func == 1)
637 mask = E1000_NVM_CFG_DONE_PORT_1;
640 if (rd32(E1000_EEMNGCTL) & mask)
646 hw_dbg("MNG configuration cycle has not completed.\n");
648 /* If EEPROM is not marked present, init the PHY manually */
649 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
650 (hw->phy.type == e1000_phy_igp_3))
651 igb_phy_init_script_igp3(hw);
657 * igb_check_for_link_82575 - Check for link
658 * @hw: pointer to the HW structure
660 * If sgmii is enabled, then use the pcs register to determine link, otherwise
661 * use the generic interface for determining link.
663 static s32 igb_check_for_link_82575(struct e1000_hw *hw)
668 if (hw->phy.media_type != e1000_media_type_copper) {
669 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
672 * Use this flag to determine if link needs to be checked or
673 * not. If we have link clear the flag so that we do not
674 * continue to check for link.
676 hw->mac.get_link_status = !hw->mac.serdes_has_link;
678 ret_val = igb_check_for_copper_link(hw);
685 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
686 * @hw: pointer to the HW structure
687 * @speed: stores the current speed
688 * @duplex: stores the current duplex
690 * Using the physical coding sub-layer (PCS), retrieve the current speed and
691 * duplex, then store the values in the pointers provided.
693 static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
696 struct e1000_mac_info *mac = &hw->mac;
699 /* Set up defaults for the return values of this function */
700 mac->serdes_has_link = false;
705 * Read the PCS Status register for link state. For non-copper mode,
706 * the status register is not accurate. The PCS status register is
709 pcs = rd32(E1000_PCS_LSTAT);
712 * The link up bit determines when link is up on autoneg. The sync ok
713 * gets set once both sides sync up and agree upon link. Stable link
714 * can be determined by checking for both link up and link sync ok
716 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
717 mac->serdes_has_link = true;
719 /* Detect and store PCS speed */
720 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
722 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
728 /* Detect and store PCS duplex */
729 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
730 *duplex = FULL_DUPLEX;
732 *duplex = HALF_DUPLEX;
740 * igb_shutdown_serdes_link_82575 - Remove link during power down
741 * @hw: pointer to the HW structure
743 * In the case of fiber serdes, shut down optics and PCS on driver unload
744 * when management pass thru is not enabled.
746 void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
751 if (hw->phy.media_type != e1000_media_type_internal_serdes ||
752 igb_sgmii_active_82575(hw))
755 if (hw->bus.func == E1000_FUNC_0)
756 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
757 else if (hw->bus.func == E1000_FUNC_1)
758 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
761 * If APM is not enabled in the EEPROM and management interface is
762 * not enabled, then power down.
764 if (!(eeprom_data & E1000_NVM_APME_82575) &&
765 !igb_enable_mng_pass_thru(hw)) {
766 /* Disable PCS to turn off link */
767 reg = rd32(E1000_PCS_CFG0);
768 reg &= ~E1000_PCS_CFG_PCS_EN;
769 wr32(E1000_PCS_CFG0, reg);
771 /* shutdown the laser */
772 reg = rd32(E1000_CTRL_EXT);
773 reg |= E1000_CTRL_EXT_SDP3_DATA;
774 wr32(E1000_CTRL_EXT, reg);
776 /* flush the write to verify completion */
785 * igb_reset_hw_82575 - Reset hardware
786 * @hw: pointer to the HW structure
788 * This resets the hardware into a known state. This is a
789 * function pointer entry point called by the api module.
791 static s32 igb_reset_hw_82575(struct e1000_hw *hw)
797 * Prevent the PCI-E bus from sticking if there is no TLP connection
798 * on the last TLP read/write transaction when MAC is reset.
800 ret_val = igb_disable_pcie_master(hw);
802 hw_dbg("PCI-E Master disable polling has failed.\n");
804 /* set the completion timeout for interface */
805 ret_val = igb_set_pcie_completion_timeout(hw);
807 hw_dbg("PCI-E Set completion timeout has failed.\n");
810 hw_dbg("Masking off all interrupts\n");
811 wr32(E1000_IMC, 0xffffffff);
814 wr32(E1000_TCTL, E1000_TCTL_PSP);
819 ctrl = rd32(E1000_CTRL);
821 hw_dbg("Issuing a global reset to MAC\n");
822 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
824 ret_val = igb_get_auto_rd_done(hw);
827 * When auto config read does not complete, do not
828 * return with an error. This can happen in situations
829 * where there is no eeprom and prevents getting link.
831 hw_dbg("Auto Read Done did not complete\n");
834 /* If EEPROM is not present, run manual init scripts */
835 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
836 igb_reset_init_script_82575(hw);
838 /* Clear any pending interrupt events. */
839 wr32(E1000_IMC, 0xffffffff);
840 icr = rd32(E1000_ICR);
842 /* Install any alternate MAC address into RAR0 */
843 ret_val = igb_check_alt_mac_addr(hw);
849 * igb_init_hw_82575 - Initialize hardware
850 * @hw: pointer to the HW structure
852 * This inits the hardware readying it for operation.
854 static s32 igb_init_hw_82575(struct e1000_hw *hw)
856 struct e1000_mac_info *mac = &hw->mac;
858 u16 i, rar_count = mac->rar_entry_count;
860 /* Initialize identification LED */
861 ret_val = igb_id_led_init(hw);
863 hw_dbg("Error initializing identification LED\n");
864 /* This is not fatal and we should not stop init due to this */
867 /* Disabling VLAN filtering */
868 hw_dbg("Initializing the IEEE VLAN\n");
871 /* Setup the receive address */
872 igb_init_rx_addrs(hw, rar_count);
874 /* Zero out the Multicast HASH table */
875 hw_dbg("Zeroing the MTA\n");
876 for (i = 0; i < mac->mta_reg_count; i++)
877 array_wr32(E1000_MTA, i, 0);
879 /* Zero out the Unicast HASH table */
880 hw_dbg("Zeroing the UTA\n");
881 for (i = 0; i < mac->uta_reg_count; i++)
882 array_wr32(E1000_UTA, i, 0);
884 /* Setup link and flow control */
885 ret_val = igb_setup_link(hw);
888 * Clear all of the statistics registers (clear on read). It is
889 * important that we do this after we have tried to establish link
890 * because the symbol error count will increment wildly if there
893 igb_clear_hw_cntrs_82575(hw);
899 * igb_setup_copper_link_82575 - Configure copper link settings
900 * @hw: pointer to the HW structure
902 * Configures the link for auto-neg or forced speed and duplex. Then we check
903 * for link, once link is established calls to configure collision distance
904 * and flow control are called.
906 static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
911 ctrl = rd32(E1000_CTRL);
912 ctrl |= E1000_CTRL_SLU;
913 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
914 wr32(E1000_CTRL, ctrl);
916 ret_val = igb_setup_serdes_link_82575(hw);
920 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
921 ret_val = hw->phy.ops.reset(hw);
923 hw_dbg("Error resetting the PHY.\n");
927 switch (hw->phy.type) {
929 ret_val = igb_copper_link_setup_m88(hw);
931 case e1000_phy_igp_3:
932 ret_val = igb_copper_link_setup_igp(hw);
935 ret_val = -E1000_ERR_PHY;
942 ret_val = igb_setup_copper_link(hw);
948 * igb_setup_serdes_link_82575 - Setup link for serdes
949 * @hw: pointer to the HW structure
951 * Configure the physical coding sub-layer (PCS) link. The PCS link is
952 * used on copper connections where the serialized gigabit media independent
953 * interface (sgmii), or serdes fiber is being used. Configures the link
954 * for auto-negotiation or forces speed/duplex.
956 static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
960 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
961 !igb_sgmii_active_82575(hw))
965 * On the 82575, SerDes loopback mode persists until it is
966 * explicitly turned off or a power cycle is performed. A read to
967 * the register does not indicate its status. Therefore, we ensure
968 * loopback mode is disabled during initialization.
970 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
972 /* power on the sfp cage if present */
973 reg = rd32(E1000_CTRL_EXT);
974 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
975 wr32(E1000_CTRL_EXT, reg);
977 ctrl_reg = rd32(E1000_CTRL);
978 ctrl_reg |= E1000_CTRL_SLU;
980 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
981 /* set both sw defined pins */
982 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
984 /* Set switch control to serdes energy detect */
985 reg = rd32(E1000_CONNSW);
986 reg |= E1000_CONNSW_ENRGSRC;
987 wr32(E1000_CONNSW, reg);
990 reg = rd32(E1000_PCS_LCTL);
992 if (igb_sgmii_active_82575(hw)) {
993 /* allow time for SFP cage to power up phy */
996 /* AN time out should be disabled for SGMII mode */
997 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
999 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1000 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
1003 wr32(E1000_CTRL, ctrl_reg);
1006 * New SerDes mode allows for forcing speed or autonegotiating speed
1007 * at 1gb. Autoneg should be default set by most drivers. This is the
1008 * mode that will be compatible with older link partners and switches.
1009 * However, both are supported by the hardware and some drivers/tools.
1012 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1013 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1016 * We force flow control to prevent the CTRL register values from being
1017 * overwritten by the autonegotiated flow control values
1019 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1022 * we always set sgmii to autoneg since it is the phy that will be
1023 * forcing the link and the serdes is just a go-between
1025 if (hw->mac.autoneg || igb_sgmii_active_82575(hw)) {
1026 /* Set PCS register for autoneg */
1027 reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1028 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full dplx */
1029 E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1030 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
1031 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
1033 /* Check for duplex first */
1034 if (hw->mac.forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1035 reg |= E1000_PCS_LCTL_FDV_FULL;
1037 /* No need to check for 1000/full since the spec states that
1038 * it requires autoneg to be enabled */
1040 if (hw->mac.forced_speed_duplex & E1000_ALL_100_SPEED)
1041 reg |= E1000_PCS_LCTL_FSV_100;
1043 /* Force speed and force link */
1044 reg |= E1000_PCS_LCTL_FSD |
1045 E1000_PCS_LCTL_FORCE_LINK |
1046 E1000_PCS_LCTL_FLV_LINK_UP;
1048 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
1051 wr32(E1000_PCS_LCTL, reg);
1053 if (!igb_sgmii_active_82575(hw))
1054 igb_force_mac_fc(hw);
1060 * igb_sgmii_active_82575 - Return sgmii state
1061 * @hw: pointer to the HW structure
1063 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1064 * which can be enabled for use in the embedded applications. Simply
1065 * return the current state of the sgmii interface.
1067 static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1069 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1070 return dev_spec->sgmii_active;
1074 * igb_reset_init_script_82575 - Inits HW defaults after reset
1075 * @hw: pointer to the HW structure
1077 * Inits recommended HW defaults after a reset when there is no EEPROM
1078 * detected. This is only for the 82575.
1080 static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1082 if (hw->mac.type == e1000_82575) {
1083 hw_dbg("Running reset init script for 82575\n");
1084 /* SerDes configuration via SERDESCTRL */
1085 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1086 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1087 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1088 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1090 /* CCM configuration via CCMCTL register */
1091 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1092 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1094 /* PCIe lanes configuration */
1095 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1096 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1097 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1098 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1100 /* PCIe PLL Configuration */
1101 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1102 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1103 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1110 * igb_read_mac_addr_82575 - Read device MAC address
1111 * @hw: pointer to the HW structure
1113 static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1118 * If there's an alternate MAC address place it in RAR0
1119 * so that it will override the Si installed default perm
1122 ret_val = igb_check_alt_mac_addr(hw);
1126 ret_val = igb_read_mac_addr(hw);
1133 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
1134 * @hw: pointer to the HW structure
1136 * Clears the hardware counters by reading the counter registers.
1138 static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1140 igb_clear_hw_cntrs_base(hw);
1146 rd32(E1000_PRC1023);
1147 rd32(E1000_PRC1522);
1152 rd32(E1000_PTC1023);
1153 rd32(E1000_PTC1522);
1155 rd32(E1000_ALGNERRC);
1158 rd32(E1000_CEXTERR);
1169 rd32(E1000_ICRXPTC);
1170 rd32(E1000_ICRXATC);
1171 rd32(E1000_ICTXPTC);
1172 rd32(E1000_ICTXATC);
1173 rd32(E1000_ICTXQEC);
1174 rd32(E1000_ICTXQMTC);
1175 rd32(E1000_ICRXDMTC);
1182 rd32(E1000_HTCBDPC);
1187 rd32(E1000_LENERRS);
1189 /* This register should not be read in copper configurations */
1190 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1191 igb_sgmii_active_82575(hw))
1196 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1197 * @hw: pointer to the HW structure
1199 * After rx enable if managability is enabled then there is likely some
1200 * bad data at the start of the fifo and possibly in the DMA fifo. This
1201 * function clears the fifos and flushes any packets that came in as rx was
1204 void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1206 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1209 if (hw->mac.type != e1000_82575 ||
1210 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1213 /* Disable all RX queues */
1214 for (i = 0; i < 4; i++) {
1215 rxdctl[i] = rd32(E1000_RXDCTL(i));
1216 wr32(E1000_RXDCTL(i),
1217 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1219 /* Poll all queues to verify they have shut down */
1220 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1223 for (i = 0; i < 4; i++)
1224 rx_enabled |= rd32(E1000_RXDCTL(i));
1225 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1230 hw_dbg("Queue disable timed out after 10ms\n");
1232 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1233 * incoming packets are rejected. Set enable and wait 2ms so that
1234 * any packet that was coming in as RCTL.EN was set is flushed
1236 rfctl = rd32(E1000_RFCTL);
1237 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1239 rlpml = rd32(E1000_RLPML);
1240 wr32(E1000_RLPML, 0);
1242 rctl = rd32(E1000_RCTL);
1243 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1244 temp_rctl |= E1000_RCTL_LPE;
1246 wr32(E1000_RCTL, temp_rctl);
1247 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1251 /* Enable RX queues that were previously enabled and restore our
1254 for (i = 0; i < 4; i++)
1255 wr32(E1000_RXDCTL(i), rxdctl[i]);
1256 wr32(E1000_RCTL, rctl);
1259 wr32(E1000_RLPML, rlpml);
1260 wr32(E1000_RFCTL, rfctl);
1262 /* Flush receive errors generated by workaround */
1269 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1270 * @hw: pointer to the HW structure
1272 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1273 * however the hardware default for these parts is 500us to 1ms which is less
1274 * than the 10ms recommended by the pci-e spec. To address this we need to
1275 * increase the value to either 10ms to 200ms for capability version 1 config,
1276 * or 16ms to 55ms for version 2.
1278 static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1280 u32 gcr = rd32(E1000_GCR);
1284 /* only take action if timeout value is defaulted to 0 */
1285 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1289 * if capababilities version is type 1 we can write the
1290 * timeout of 10ms to 200ms through the GCR register
1292 if (!(gcr & E1000_GCR_CAP_VER2)) {
1293 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1298 * for version 2 capabilities we need to write the config space
1299 * directly in order to set the completion timeout value for
1302 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1307 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1309 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1312 /* disable completion timeout resend */
1313 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1315 wr32(E1000_GCR, gcr);
1320 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1321 * @hw: pointer to the hardware struct
1322 * @enable: state to enter, either enabled or disabled
1324 * enables/disables L2 switch loopback functionality.
1326 void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1328 u32 dtxswc = rd32(E1000_DTXSWC);
1331 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1333 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1335 wr32(E1000_DTXSWC, dtxswc);
1339 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1340 * @hw: pointer to the hardware struct
1341 * @enable: state to enter, either enabled or disabled
1343 * enables/disables replication of packets across multiple pools.
1345 void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1347 u32 vt_ctl = rd32(E1000_VT_CTL);
1350 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1352 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1354 wr32(E1000_VT_CTL, vt_ctl);
1357 static struct e1000_mac_operations e1000_mac_ops_82575 = {
1358 .reset_hw = igb_reset_hw_82575,
1359 .init_hw = igb_init_hw_82575,
1360 .check_for_link = igb_check_for_link_82575,
1361 .rar_set = igb_rar_set,
1362 .read_mac_addr = igb_read_mac_addr_82575,
1363 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1366 static struct e1000_phy_operations e1000_phy_ops_82575 = {
1367 .acquire = igb_acquire_phy_82575,
1368 .get_cfg_done = igb_get_cfg_done_82575,
1369 .release = igb_release_phy_82575,
1372 static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
1373 .acquire = igb_acquire_nvm_82575,
1374 .read = igb_read_nvm_eerd,
1375 .release = igb_release_nvm_82575,
1376 .write = igb_write_nvm_spi,
1379 const struct e1000_info e1000_82575_info = {
1380 .get_invariants = igb_get_invariants_82575,
1381 .mac_ops = &e1000_mac_ops_82575,
1382 .phy_ops = &e1000_phy_ops_82575,
1383 .nvm_ops = &e1000_nvm_ops_82575,