1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2014 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, see <http://www.gnu.org/licenses/>.
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *******************************************************************************/
31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/types.h>
34 #include <linux/if_ether.h>
35 #include <linux/i2c.h>
37 #include "e1000_mac.h"
38 #include "e1000_82575.h"
39 #include "e1000_i210.h"
41 static s32
igb_get_invariants_82575(struct e1000_hw
*);
42 static s32
igb_acquire_phy_82575(struct e1000_hw
*);
43 static void igb_release_phy_82575(struct e1000_hw
*);
44 static s32
igb_acquire_nvm_82575(struct e1000_hw
*);
45 static void igb_release_nvm_82575(struct e1000_hw
*);
46 static s32
igb_check_for_link_82575(struct e1000_hw
*);
47 static s32
igb_get_cfg_done_82575(struct e1000_hw
*);
48 static s32
igb_init_hw_82575(struct e1000_hw
*);
49 static s32
igb_phy_hw_reset_sgmii_82575(struct e1000_hw
*);
50 static s32
igb_read_phy_reg_sgmii_82575(struct e1000_hw
*, u32
, u16
*);
51 static s32
igb_read_phy_reg_82580(struct e1000_hw
*, u32
, u16
*);
52 static s32
igb_write_phy_reg_82580(struct e1000_hw
*, u32
, u16
);
53 static s32
igb_reset_hw_82575(struct e1000_hw
*);
54 static s32
igb_reset_hw_82580(struct e1000_hw
*);
55 static s32
igb_set_d0_lplu_state_82575(struct e1000_hw
*, bool);
56 static s32
igb_set_d0_lplu_state_82580(struct e1000_hw
*, bool);
57 static s32
igb_set_d3_lplu_state_82580(struct e1000_hw
*, bool);
58 static s32
igb_setup_copper_link_82575(struct e1000_hw
*);
59 static s32
igb_setup_serdes_link_82575(struct e1000_hw
*);
60 static s32
igb_write_phy_reg_sgmii_82575(struct e1000_hw
*, u32
, u16
);
61 static void igb_clear_hw_cntrs_82575(struct e1000_hw
*);
62 static s32
igb_acquire_swfw_sync_82575(struct e1000_hw
*, u16
);
63 static s32
igb_get_pcs_speed_and_duplex_82575(struct e1000_hw
*, u16
*,
65 static s32
igb_get_phy_id_82575(struct e1000_hw
*);
66 static void igb_release_swfw_sync_82575(struct e1000_hw
*, u16
);
67 static bool igb_sgmii_active_82575(struct e1000_hw
*);
68 static s32
igb_reset_init_script_82575(struct e1000_hw
*);
69 static s32
igb_read_mac_addr_82575(struct e1000_hw
*);
70 static s32
igb_set_pcie_completion_timeout(struct e1000_hw
*hw
);
71 static s32
igb_reset_mdicnfg_82580(struct e1000_hw
*hw
);
72 static s32
igb_validate_nvm_checksum_82580(struct e1000_hw
*hw
);
73 static s32
igb_update_nvm_checksum_82580(struct e1000_hw
*hw
);
74 static s32
igb_validate_nvm_checksum_i350(struct e1000_hw
*hw
);
75 static s32
igb_update_nvm_checksum_i350(struct e1000_hw
*hw
);
76 static const u16 e1000_82580_rxpbs_table
[] = {
77 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
80 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
81 * @hw: pointer to the HW structure
83 * Called to determine if the I2C pins are being used for I2C or as an
84 * external MDIO interface since the two options are mutually exclusive.
86 static bool igb_sgmii_uses_mdio_82575(struct e1000_hw
*hw
)
89 bool ext_mdio
= false;
91 switch (hw
->mac
.type
) {
94 reg
= rd32(E1000_MDIC
);
95 ext_mdio
= !!(reg
& E1000_MDIC_DEST
);
102 reg
= rd32(E1000_MDICNFG
);
103 ext_mdio
= !!(reg
& E1000_MDICNFG_EXT_MDIO
);
112 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
113 * @hw: pointer to the HW structure
115 * Poll the M88E1112 interfaces to see which interface achieved link.
117 static s32
igb_check_for_link_media_swap(struct e1000_hw
*hw
)
119 struct e1000_phy_info
*phy
= &hw
->phy
;
124 /* Check the copper medium. */
125 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 0);
129 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1112_STATUS
, &data
);
133 if (data
& E1000_M88E1112_STATUS_LINK
)
134 port
= E1000_MEDIA_PORT_COPPER
;
136 /* Check the other medium. */
137 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 1);
141 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1112_STATUS
, &data
);
145 /* reset page to 0 */
146 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 0);
150 if (data
& E1000_M88E1112_STATUS_LINK
)
151 port
= E1000_MEDIA_PORT_OTHER
;
153 /* Determine if a swap needs to happen. */
154 if (port
&& (hw
->dev_spec
._82575
.media_port
!= port
)) {
155 hw
->dev_spec
._82575
.media_port
= port
;
156 hw
->dev_spec
._82575
.media_changed
= true;
158 ret_val
= igb_check_for_link_82575(hw
);
161 return E1000_SUCCESS
;
165 * igb_init_phy_params_82575 - Init PHY func ptrs.
166 * @hw: pointer to the HW structure
168 static s32
igb_init_phy_params_82575(struct e1000_hw
*hw
)
170 struct e1000_phy_info
*phy
= &hw
->phy
;
174 if (hw
->phy
.media_type
!= e1000_media_type_copper
) {
175 phy
->type
= e1000_phy_none
;
179 phy
->autoneg_mask
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
180 phy
->reset_delay_us
= 100;
182 ctrl_ext
= rd32(E1000_CTRL_EXT
);
184 if (igb_sgmii_active_82575(hw
)) {
185 phy
->ops
.reset
= igb_phy_hw_reset_sgmii_82575
;
186 ctrl_ext
|= E1000_CTRL_I2C_ENA
;
188 phy
->ops
.reset
= igb_phy_hw_reset
;
189 ctrl_ext
&= ~E1000_CTRL_I2C_ENA
;
192 wr32(E1000_CTRL_EXT
, ctrl_ext
);
193 igb_reset_mdicnfg_82580(hw
);
195 if (igb_sgmii_active_82575(hw
) && !igb_sgmii_uses_mdio_82575(hw
)) {
196 phy
->ops
.read_reg
= igb_read_phy_reg_sgmii_82575
;
197 phy
->ops
.write_reg
= igb_write_phy_reg_sgmii_82575
;
199 switch (hw
->mac
.type
) {
203 phy
->ops
.read_reg
= igb_read_phy_reg_82580
;
204 phy
->ops
.write_reg
= igb_write_phy_reg_82580
;
208 phy
->ops
.read_reg
= igb_read_phy_reg_gs40g
;
209 phy
->ops
.write_reg
= igb_write_phy_reg_gs40g
;
212 phy
->ops
.read_reg
= igb_read_phy_reg_igp
;
213 phy
->ops
.write_reg
= igb_write_phy_reg_igp
;
218 hw
->bus
.func
= (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_MASK
) >>
219 E1000_STATUS_FUNC_SHIFT
;
221 /* Set phy->phy_addr and phy->id. */
222 ret_val
= igb_get_phy_id_82575(hw
);
226 /* Verify phy id and set remaining function pointers */
228 case M88E1543_E_PHY_ID
:
229 case I347AT4_E_PHY_ID
:
230 case M88E1112_E_PHY_ID
:
231 case M88E1111_I_PHY_ID
:
232 phy
->type
= e1000_phy_m88
;
233 phy
->ops
.check_polarity
= igb_check_polarity_m88
;
234 phy
->ops
.get_phy_info
= igb_get_phy_info_m88
;
235 if (phy
->id
!= M88E1111_I_PHY_ID
)
236 phy
->ops
.get_cable_length
=
237 igb_get_cable_length_m88_gen2
;
239 phy
->ops
.get_cable_length
= igb_get_cable_length_m88
;
240 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_m88
;
241 /* Check if this PHY is confgured for media swap. */
242 if (phy
->id
== M88E1112_E_PHY_ID
) {
245 ret_val
= phy
->ops
.write_reg(hw
,
246 E1000_M88E1112_PAGE_ADDR
,
251 ret_val
= phy
->ops
.read_reg(hw
,
252 E1000_M88E1112_MAC_CTRL_1
,
257 data
= (data
& E1000_M88E1112_MAC_CTRL_1_MODE_MASK
) >>
258 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT
;
259 if (data
== E1000_M88E1112_AUTO_COPPER_SGMII
||
260 data
== E1000_M88E1112_AUTO_COPPER_BASEX
)
261 hw
->mac
.ops
.check_for_link
=
262 igb_check_for_link_media_swap
;
265 case IGP03E1000_E_PHY_ID
:
266 phy
->type
= e1000_phy_igp_3
;
267 phy
->ops
.get_phy_info
= igb_get_phy_info_igp
;
268 phy
->ops
.get_cable_length
= igb_get_cable_length_igp_2
;
269 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_igp
;
270 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82575
;
271 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state
;
273 case I82580_I_PHY_ID
:
275 phy
->type
= e1000_phy_82580
;
276 phy
->ops
.force_speed_duplex
=
277 igb_phy_force_speed_duplex_82580
;
278 phy
->ops
.get_cable_length
= igb_get_cable_length_82580
;
279 phy
->ops
.get_phy_info
= igb_get_phy_info_82580
;
280 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82580
;
281 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state_82580
;
284 phy
->type
= e1000_phy_i210
;
285 phy
->ops
.check_polarity
= igb_check_polarity_m88
;
286 phy
->ops
.get_phy_info
= igb_get_phy_info_m88
;
287 phy
->ops
.get_cable_length
= igb_get_cable_length_m88_gen2
;
288 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82580
;
289 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state_82580
;
290 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_m88
;
293 ret_val
= -E1000_ERR_PHY
;
302 * igb_init_nvm_params_82575 - Init NVM func ptrs.
303 * @hw: pointer to the HW structure
305 static s32
igb_init_nvm_params_82575(struct e1000_hw
*hw
)
307 struct e1000_nvm_info
*nvm
= &hw
->nvm
;
308 u32 eecd
= rd32(E1000_EECD
);
311 size
= (u16
)((eecd
& E1000_EECD_SIZE_EX_MASK
) >>
312 E1000_EECD_SIZE_EX_SHIFT
);
314 /* Added to a constant, "size" becomes the left-shift value
315 * for setting word_size.
317 size
+= NVM_WORD_SIZE_BASE_SHIFT
;
319 /* Just in case size is out of range, cap it to the largest
320 * EEPROM size supported
325 nvm
->word_size
= 1 << size
;
326 nvm
->opcode_bits
= 8;
329 switch (nvm
->override
) {
330 case e1000_nvm_override_spi_large
:
332 nvm
->address_bits
= 16;
334 case e1000_nvm_override_spi_small
:
336 nvm
->address_bits
= 8;
339 nvm
->page_size
= eecd
& E1000_EECD_ADDR_BITS
? 32 : 8;
340 nvm
->address_bits
= eecd
& E1000_EECD_ADDR_BITS
?
344 if (nvm
->word_size
== (1 << 15))
345 nvm
->page_size
= 128;
347 nvm
->type
= e1000_nvm_eeprom_spi
;
349 /* NVM Function Pointers */
350 nvm
->ops
.acquire
= igb_acquire_nvm_82575
;
351 nvm
->ops
.release
= igb_release_nvm_82575
;
352 nvm
->ops
.write
= igb_write_nvm_spi
;
353 nvm
->ops
.validate
= igb_validate_nvm_checksum
;
354 nvm
->ops
.update
= igb_update_nvm_checksum
;
355 if (nvm
->word_size
< (1 << 15))
356 nvm
->ops
.read
= igb_read_nvm_eerd
;
358 nvm
->ops
.read
= igb_read_nvm_spi
;
360 /* override generic family function pointers for specific descendants */
361 switch (hw
->mac
.type
) {
363 nvm
->ops
.validate
= igb_validate_nvm_checksum_82580
;
364 nvm
->ops
.update
= igb_update_nvm_checksum_82580
;
368 nvm
->ops
.validate
= igb_validate_nvm_checksum_i350
;
369 nvm
->ops
.update
= igb_update_nvm_checksum_i350
;
379 * igb_init_mac_params_82575 - Init MAC func ptrs.
380 * @hw: pointer to the HW structure
382 static s32
igb_init_mac_params_82575(struct e1000_hw
*hw
)
384 struct e1000_mac_info
*mac
= &hw
->mac
;
385 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
387 /* Set mta register count */
388 mac
->mta_reg_count
= 128;
389 /* Set rar entry count */
392 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82576
;
395 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82580
;
399 mac
->rar_entry_count
= E1000_RAR_ENTRIES_I350
;
402 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82575
;
406 if (mac
->type
>= e1000_82580
)
407 mac
->ops
.reset_hw
= igb_reset_hw_82580
;
409 mac
->ops
.reset_hw
= igb_reset_hw_82575
;
411 if (mac
->type
>= e1000_i210
) {
412 mac
->ops
.acquire_swfw_sync
= igb_acquire_swfw_sync_i210
;
413 mac
->ops
.release_swfw_sync
= igb_release_swfw_sync_i210
;
416 mac
->ops
.acquire_swfw_sync
= igb_acquire_swfw_sync_82575
;
417 mac
->ops
.release_swfw_sync
= igb_release_swfw_sync_82575
;
420 /* Set if part includes ASF firmware */
421 mac
->asf_firmware_present
= true;
422 /* Set if manageability features are enabled. */
423 mac
->arc_subsystem_valid
=
424 (rd32(E1000_FWSM
) & E1000_FWSM_MODE_MASK
)
426 /* enable EEE on i350 parts and later parts */
427 if (mac
->type
>= e1000_i350
)
428 dev_spec
->eee_disable
= false;
430 dev_spec
->eee_disable
= true;
431 /* Allow a single clear of the SW semaphore on I210 and newer */
432 if (mac
->type
>= e1000_i210
)
433 dev_spec
->clear_semaphore_once
= true;
434 /* physical interface link setup */
435 mac
->ops
.setup_physical_interface
=
436 (hw
->phy
.media_type
== e1000_media_type_copper
)
437 ? igb_setup_copper_link_82575
438 : igb_setup_serdes_link_82575
;
440 if (mac
->type
== e1000_82580
) {
441 switch (hw
->device_id
) {
442 /* feature not supported on these id's */
443 case E1000_DEV_ID_DH89XXCC_SGMII
:
444 case E1000_DEV_ID_DH89XXCC_SERDES
:
445 case E1000_DEV_ID_DH89XXCC_BACKPLANE
:
446 case E1000_DEV_ID_DH89XXCC_SFP
:
449 hw
->dev_spec
._82575
.mas_capable
= true;
457 * igb_set_sfp_media_type_82575 - derives SFP module media type.
458 * @hw: pointer to the HW structure
460 * The media type is chosen based on SFP module.
461 * compatibility flags retrieved from SFP ID EEPROM.
463 static s32
igb_set_sfp_media_type_82575(struct e1000_hw
*hw
)
465 s32 ret_val
= E1000_ERR_CONFIG
;
467 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
468 struct e1000_sfp_flags
*eth_flags
= &dev_spec
->eth_flags
;
469 u8 tranceiver_type
= 0;
472 /* Turn I2C interface ON and power on sfp cage */
473 ctrl_ext
= rd32(E1000_CTRL_EXT
);
474 ctrl_ext
&= ~E1000_CTRL_EXT_SDP3_DATA
;
475 wr32(E1000_CTRL_EXT
, ctrl_ext
| E1000_CTRL_I2C_ENA
);
479 /* Read SFP module data */
481 ret_val
= igb_read_sfp_data_byte(hw
,
482 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET
),
492 ret_val
= igb_read_sfp_data_byte(hw
,
493 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET
),
498 /* Check if there is some SFP module plugged and powered */
499 if ((tranceiver_type
== E1000_SFF_IDENTIFIER_SFP
) ||
500 (tranceiver_type
== E1000_SFF_IDENTIFIER_SFF
)) {
501 dev_spec
->module_plugged
= true;
502 if (eth_flags
->e1000_base_lx
|| eth_flags
->e1000_base_sx
) {
503 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
504 } else if (eth_flags
->e100_base_fx
) {
505 dev_spec
->sgmii_active
= true;
506 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
507 } else if (eth_flags
->e1000_base_t
) {
508 dev_spec
->sgmii_active
= true;
509 hw
->phy
.media_type
= e1000_media_type_copper
;
511 hw
->phy
.media_type
= e1000_media_type_unknown
;
512 hw_dbg("PHY module has not been recognized\n");
516 hw
->phy
.media_type
= e1000_media_type_unknown
;
520 /* Restore I2C interface setting */
521 wr32(E1000_CTRL_EXT
, ctrl_ext
);
525 static s32
igb_get_invariants_82575(struct e1000_hw
*hw
)
527 struct e1000_mac_info
*mac
= &hw
->mac
;
528 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
533 switch (hw
->device_id
) {
534 case E1000_DEV_ID_82575EB_COPPER
:
535 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
536 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
537 mac
->type
= e1000_82575
;
539 case E1000_DEV_ID_82576
:
540 case E1000_DEV_ID_82576_NS
:
541 case E1000_DEV_ID_82576_NS_SERDES
:
542 case E1000_DEV_ID_82576_FIBER
:
543 case E1000_DEV_ID_82576_SERDES
:
544 case E1000_DEV_ID_82576_QUAD_COPPER
:
545 case E1000_DEV_ID_82576_QUAD_COPPER_ET2
:
546 case E1000_DEV_ID_82576_SERDES_QUAD
:
547 mac
->type
= e1000_82576
;
549 case E1000_DEV_ID_82580_COPPER
:
550 case E1000_DEV_ID_82580_FIBER
:
551 case E1000_DEV_ID_82580_QUAD_FIBER
:
552 case E1000_DEV_ID_82580_SERDES
:
553 case E1000_DEV_ID_82580_SGMII
:
554 case E1000_DEV_ID_82580_COPPER_DUAL
:
555 case E1000_DEV_ID_DH89XXCC_SGMII
:
556 case E1000_DEV_ID_DH89XXCC_SERDES
:
557 case E1000_DEV_ID_DH89XXCC_BACKPLANE
:
558 case E1000_DEV_ID_DH89XXCC_SFP
:
559 mac
->type
= e1000_82580
;
561 case E1000_DEV_ID_I350_COPPER
:
562 case E1000_DEV_ID_I350_FIBER
:
563 case E1000_DEV_ID_I350_SERDES
:
564 case E1000_DEV_ID_I350_SGMII
:
565 mac
->type
= e1000_i350
;
567 case E1000_DEV_ID_I210_COPPER
:
568 case E1000_DEV_ID_I210_FIBER
:
569 case E1000_DEV_ID_I210_SERDES
:
570 case E1000_DEV_ID_I210_SGMII
:
571 case E1000_DEV_ID_I210_COPPER_FLASHLESS
:
572 case E1000_DEV_ID_I210_SERDES_FLASHLESS
:
573 mac
->type
= e1000_i210
;
575 case E1000_DEV_ID_I211_COPPER
:
576 mac
->type
= e1000_i211
;
578 case E1000_DEV_ID_I354_BACKPLANE_1GBPS
:
579 case E1000_DEV_ID_I354_SGMII
:
580 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS
:
581 mac
->type
= e1000_i354
;
584 return -E1000_ERR_MAC_INIT
;
589 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
590 * based on the EEPROM. We cannot rely upon device ID. There
591 * is no distinguishable difference between fiber and internal
592 * SerDes mode on the 82575. There can be an external PHY attached
593 * on the SGMII interface. For this, we'll set sgmii_active to true.
595 hw
->phy
.media_type
= e1000_media_type_copper
;
596 dev_spec
->sgmii_active
= false;
597 dev_spec
->module_plugged
= false;
599 ctrl_ext
= rd32(E1000_CTRL_EXT
);
601 link_mode
= ctrl_ext
& E1000_CTRL_EXT_LINK_MODE_MASK
;
603 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX
:
604 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
606 case E1000_CTRL_EXT_LINK_MODE_SGMII
:
607 /* Get phy control interface type set (MDIO vs. I2C)*/
608 if (igb_sgmii_uses_mdio_82575(hw
)) {
609 hw
->phy
.media_type
= e1000_media_type_copper
;
610 dev_spec
->sgmii_active
= true;
613 /* fall through for I2C based SGMII */
614 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
:
615 /* read media type from SFP EEPROM */
616 ret_val
= igb_set_sfp_media_type_82575(hw
);
617 if ((ret_val
!= 0) ||
618 (hw
->phy
.media_type
== e1000_media_type_unknown
)) {
619 /* If media type was not identified then return media
620 * type defined by the CTRL_EXT settings.
622 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
624 if (link_mode
== E1000_CTRL_EXT_LINK_MODE_SGMII
) {
625 hw
->phy
.media_type
= e1000_media_type_copper
;
626 dev_spec
->sgmii_active
= true;
632 /* do not change link mode for 100BaseFX */
633 if (dev_spec
->eth_flags
.e100_base_fx
)
636 /* change current link mode setting */
637 ctrl_ext
&= ~E1000_CTRL_EXT_LINK_MODE_MASK
;
639 if (hw
->phy
.media_type
== e1000_media_type_copper
)
640 ctrl_ext
|= E1000_CTRL_EXT_LINK_MODE_SGMII
;
642 ctrl_ext
|= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
644 wr32(E1000_CTRL_EXT
, ctrl_ext
);
651 /* mac initialization and operations */
652 ret_val
= igb_init_mac_params_82575(hw
);
656 /* NVM initialization */
657 ret_val
= igb_init_nvm_params_82575(hw
);
658 switch (hw
->mac
.type
) {
661 ret_val
= igb_init_nvm_params_i210(hw
);
670 /* if part supports SR-IOV then initialize mailbox parameters */
674 igb_init_mbx_params_pf(hw
);
680 /* setup PHY parameters */
681 ret_val
= igb_init_phy_params_82575(hw
);
688 * igb_acquire_phy_82575 - Acquire rights to access PHY
689 * @hw: pointer to the HW structure
691 * Acquire access rights to the correct PHY. This is a
692 * function pointer entry point called by the api module.
694 static s32
igb_acquire_phy_82575(struct e1000_hw
*hw
)
696 u16 mask
= E1000_SWFW_PHY0_SM
;
698 if (hw
->bus
.func
== E1000_FUNC_1
)
699 mask
= E1000_SWFW_PHY1_SM
;
700 else if (hw
->bus
.func
== E1000_FUNC_2
)
701 mask
= E1000_SWFW_PHY2_SM
;
702 else if (hw
->bus
.func
== E1000_FUNC_3
)
703 mask
= E1000_SWFW_PHY3_SM
;
705 return hw
->mac
.ops
.acquire_swfw_sync(hw
, mask
);
709 * igb_release_phy_82575 - Release rights to access PHY
710 * @hw: pointer to the HW structure
712 * A wrapper to release access rights to the correct PHY. This is a
713 * function pointer entry point called by the api module.
715 static void igb_release_phy_82575(struct e1000_hw
*hw
)
717 u16 mask
= E1000_SWFW_PHY0_SM
;
719 if (hw
->bus
.func
== E1000_FUNC_1
)
720 mask
= E1000_SWFW_PHY1_SM
;
721 else if (hw
->bus
.func
== E1000_FUNC_2
)
722 mask
= E1000_SWFW_PHY2_SM
;
723 else if (hw
->bus
.func
== E1000_FUNC_3
)
724 mask
= E1000_SWFW_PHY3_SM
;
726 hw
->mac
.ops
.release_swfw_sync(hw
, mask
);
730 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
731 * @hw: pointer to the HW structure
732 * @offset: register offset to be read
733 * @data: pointer to the read data
735 * Reads the PHY register at offset using the serial gigabit media independent
736 * interface and stores the retrieved information in data.
738 static s32
igb_read_phy_reg_sgmii_82575(struct e1000_hw
*hw
, u32 offset
,
741 s32 ret_val
= -E1000_ERR_PARAM
;
743 if (offset
> E1000_MAX_SGMII_PHY_REG_ADDR
) {
744 hw_dbg("PHY Address %u is out of range\n", offset
);
748 ret_val
= hw
->phy
.ops
.acquire(hw
);
752 ret_val
= igb_read_phy_reg_i2c(hw
, offset
, data
);
754 hw
->phy
.ops
.release(hw
);
761 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
762 * @hw: pointer to the HW structure
763 * @offset: register offset to write to
764 * @data: data to write at register offset
766 * Writes the data to PHY register at the offset using the serial gigabit
767 * media independent interface.
769 static s32
igb_write_phy_reg_sgmii_82575(struct e1000_hw
*hw
, u32 offset
,
772 s32 ret_val
= -E1000_ERR_PARAM
;
775 if (offset
> E1000_MAX_SGMII_PHY_REG_ADDR
) {
776 hw_dbg("PHY Address %d is out of range\n", offset
);
780 ret_val
= hw
->phy
.ops
.acquire(hw
);
784 ret_val
= igb_write_phy_reg_i2c(hw
, offset
, data
);
786 hw
->phy
.ops
.release(hw
);
793 * igb_get_phy_id_82575 - Retrieve PHY addr and id
794 * @hw: pointer to the HW structure
796 * Retrieves the PHY address and ID for both PHY's which do and do not use
799 static s32
igb_get_phy_id_82575(struct e1000_hw
*hw
)
801 struct e1000_phy_info
*phy
= &hw
->phy
;
807 /* Extra read required for some PHY's on i354 */
808 if (hw
->mac
.type
== e1000_i354
)
811 /* For SGMII PHYs, we try the list of possible addresses until
812 * we find one that works. For non-SGMII PHYs
813 * (e.g. integrated copper PHYs), an address of 1 should
814 * work. The result of this function should mean phy->phy_addr
815 * and phy->id are set correctly.
817 if (!(igb_sgmii_active_82575(hw
))) {
819 ret_val
= igb_get_phy_id(hw
);
823 if (igb_sgmii_uses_mdio_82575(hw
)) {
824 switch (hw
->mac
.type
) {
827 mdic
= rd32(E1000_MDIC
);
828 mdic
&= E1000_MDIC_PHY_MASK
;
829 phy
->addr
= mdic
>> E1000_MDIC_PHY_SHIFT
;
836 mdic
= rd32(E1000_MDICNFG
);
837 mdic
&= E1000_MDICNFG_PHY_MASK
;
838 phy
->addr
= mdic
>> E1000_MDICNFG_PHY_SHIFT
;
841 ret_val
= -E1000_ERR_PHY
;
845 ret_val
= igb_get_phy_id(hw
);
849 /* Power on sgmii phy if it is disabled */
850 ctrl_ext
= rd32(E1000_CTRL_EXT
);
851 wr32(E1000_CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_SDP3_DATA
);
855 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
856 * Therefore, we need to test 1-7
858 for (phy
->addr
= 1; phy
->addr
< 8; phy
->addr
++) {
859 ret_val
= igb_read_phy_reg_sgmii_82575(hw
, PHY_ID1
, &phy_id
);
861 hw_dbg("Vendor ID 0x%08X read at address %u\n",
863 /* At the time of this writing, The M88 part is
864 * the only supported SGMII PHY product.
866 if (phy_id
== M88_VENDOR
)
869 hw_dbg("PHY address %u was unreadable\n", phy
->addr
);
873 /* A valid PHY type couldn't be found. */
874 if (phy
->addr
== 8) {
876 ret_val
= -E1000_ERR_PHY
;
879 ret_val
= igb_get_phy_id(hw
);
882 /* restore previous sfp cage power state */
883 wr32(E1000_CTRL_EXT
, ctrl_ext
);
890 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
891 * @hw: pointer to the HW structure
893 * Resets the PHY using the serial gigabit media independent interface.
895 static s32
igb_phy_hw_reset_sgmii_82575(struct e1000_hw
*hw
)
899 /* This isn't a true "hard" reset, but is the only reset
900 * available to us at this time.
903 hw_dbg("Soft resetting SGMII attached PHY...\n");
905 /* SFP documentation requires the following to configure the SPF module
906 * to work on SGMII. No further documentation is given.
908 ret_val
= hw
->phy
.ops
.write_reg(hw
, 0x1B, 0x8084);
912 ret_val
= igb_phy_sw_reset(hw
);
919 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
920 * @hw: pointer to the HW structure
921 * @active: true to enable LPLU, false to disable
923 * Sets the LPLU D0 state according to the active flag. When
924 * activating LPLU this function also disables smart speed
925 * and vice versa. LPLU will not be activated unless the
926 * device autonegotiation advertisement meets standards of
927 * either 10 or 10/100 or 10/100/1000 at all duplexes.
928 * This is a function pointer entry point only called by
929 * PHY setup routines.
931 static s32
igb_set_d0_lplu_state_82575(struct e1000_hw
*hw
, bool active
)
933 struct e1000_phy_info
*phy
= &hw
->phy
;
937 ret_val
= phy
->ops
.read_reg(hw
, IGP02E1000_PHY_POWER_MGMT
, &data
);
942 data
|= IGP02E1000_PM_D0_LPLU
;
943 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
948 /* When LPLU is enabled, we should disable SmartSpeed */
949 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
951 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
952 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
957 data
&= ~IGP02E1000_PM_D0_LPLU
;
958 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
960 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
961 * during Dx states where the power conservation is most
962 * important. During driver activity we should enable
963 * SmartSpeed, so performance is maintained.
965 if (phy
->smart_speed
== e1000_smart_speed_on
) {
966 ret_val
= phy
->ops
.read_reg(hw
,
967 IGP01E1000_PHY_PORT_CONFIG
, &data
);
971 data
|= IGP01E1000_PSCFR_SMART_SPEED
;
972 ret_val
= phy
->ops
.write_reg(hw
,
973 IGP01E1000_PHY_PORT_CONFIG
, data
);
976 } else if (phy
->smart_speed
== e1000_smart_speed_off
) {
977 ret_val
= phy
->ops
.read_reg(hw
,
978 IGP01E1000_PHY_PORT_CONFIG
, &data
);
982 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
983 ret_val
= phy
->ops
.write_reg(hw
,
984 IGP01E1000_PHY_PORT_CONFIG
, data
);
995 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
996 * @hw: pointer to the HW structure
997 * @active: true to enable LPLU, false to disable
999 * Sets the LPLU D0 state according to the active flag. When
1000 * activating LPLU this function also disables smart speed
1001 * and vice versa. LPLU will not be activated unless the
1002 * device autonegotiation advertisement meets standards of
1003 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1004 * This is a function pointer entry point only called by
1005 * PHY setup routines.
1007 static s32
igb_set_d0_lplu_state_82580(struct e1000_hw
*hw
, bool active
)
1009 struct e1000_phy_info
*phy
= &hw
->phy
;
1013 data
= rd32(E1000_82580_PHY_POWER_MGMT
);
1016 data
|= E1000_82580_PM_D0_LPLU
;
1018 /* When LPLU is enabled, we should disable SmartSpeed */
1019 data
&= ~E1000_82580_PM_SPD
;
1021 data
&= ~E1000_82580_PM_D0_LPLU
;
1023 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1024 * during Dx states where the power conservation is most
1025 * important. During driver activity we should enable
1026 * SmartSpeed, so performance is maintained.
1028 if (phy
->smart_speed
== e1000_smart_speed_on
)
1029 data
|= E1000_82580_PM_SPD
;
1030 else if (phy
->smart_speed
== e1000_smart_speed_off
)
1031 data
&= ~E1000_82580_PM_SPD
; }
1033 wr32(E1000_82580_PHY_POWER_MGMT
, data
);
1038 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1039 * @hw: pointer to the HW structure
1040 * @active: boolean used to enable/disable lplu
1042 * Success returns 0, Failure returns 1
1044 * The low power link up (lplu) state is set to the power management level D3
1045 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1046 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1047 * is used during Dx states where the power conservation is most important.
1048 * During driver activity, SmartSpeed should be enabled so performance is
1051 static s32
igb_set_d3_lplu_state_82580(struct e1000_hw
*hw
, bool active
)
1053 struct e1000_phy_info
*phy
= &hw
->phy
;
1057 data
= rd32(E1000_82580_PHY_POWER_MGMT
);
1060 data
&= ~E1000_82580_PM_D3_LPLU
;
1061 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1062 * during Dx states where the power conservation is most
1063 * important. During driver activity we should enable
1064 * SmartSpeed, so performance is maintained.
1066 if (phy
->smart_speed
== e1000_smart_speed_on
)
1067 data
|= E1000_82580_PM_SPD
;
1068 else if (phy
->smart_speed
== e1000_smart_speed_off
)
1069 data
&= ~E1000_82580_PM_SPD
;
1070 } else if ((phy
->autoneg_advertised
== E1000_ALL_SPEED_DUPLEX
) ||
1071 (phy
->autoneg_advertised
== E1000_ALL_NOT_GIG
) ||
1072 (phy
->autoneg_advertised
== E1000_ALL_10_SPEED
)) {
1073 data
|= E1000_82580_PM_D3_LPLU
;
1074 /* When LPLU is enabled, we should disable SmartSpeed */
1075 data
&= ~E1000_82580_PM_SPD
;
1078 wr32(E1000_82580_PHY_POWER_MGMT
, data
);
1083 * igb_acquire_nvm_82575 - Request for access to EEPROM
1084 * @hw: pointer to the HW structure
1086 * Acquire the necessary semaphores for exclusive access to the EEPROM.
1087 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1088 * Return successful if access grant bit set, else clear the request for
1089 * EEPROM access and return -E1000_ERR_NVM (-1).
1091 static s32
igb_acquire_nvm_82575(struct e1000_hw
*hw
)
1095 ret_val
= hw
->mac
.ops
.acquire_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1099 ret_val
= igb_acquire_nvm(hw
);
1102 hw
->mac
.ops
.release_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1109 * igb_release_nvm_82575 - Release exclusive access to EEPROM
1110 * @hw: pointer to the HW structure
1112 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1113 * then release the semaphores acquired.
1115 static void igb_release_nvm_82575(struct e1000_hw
*hw
)
1117 igb_release_nvm(hw
);
1118 hw
->mac
.ops
.release_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1122 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
1123 * @hw: pointer to the HW structure
1124 * @mask: specifies which semaphore to acquire
1126 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1127 * will also specify which port we're acquiring the lock for.
1129 static s32
igb_acquire_swfw_sync_82575(struct e1000_hw
*hw
, u16 mask
)
1133 u32 fwmask
= mask
<< 16;
1135 s32 i
= 0, timeout
= 200; /* FIXME: find real value to use here */
1137 while (i
< timeout
) {
1138 if (igb_get_hw_semaphore(hw
)) {
1139 ret_val
= -E1000_ERR_SWFW_SYNC
;
1143 swfw_sync
= rd32(E1000_SW_FW_SYNC
);
1144 if (!(swfw_sync
& (fwmask
| swmask
)))
1147 /* Firmware currently using resource (fwmask)
1148 * or other software thread using resource (swmask)
1150 igb_put_hw_semaphore(hw
);
1156 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
1157 ret_val
= -E1000_ERR_SWFW_SYNC
;
1161 swfw_sync
|= swmask
;
1162 wr32(E1000_SW_FW_SYNC
, swfw_sync
);
1164 igb_put_hw_semaphore(hw
);
1171 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
1172 * @hw: pointer to the HW structure
1173 * @mask: specifies which semaphore to acquire
1175 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1176 * will also specify which port we're releasing the lock for.
1178 static void igb_release_swfw_sync_82575(struct e1000_hw
*hw
, u16 mask
)
1182 while (igb_get_hw_semaphore(hw
) != 0)
1185 swfw_sync
= rd32(E1000_SW_FW_SYNC
);
1187 wr32(E1000_SW_FW_SYNC
, swfw_sync
);
1189 igb_put_hw_semaphore(hw
);
1193 * igb_get_cfg_done_82575 - Read config done bit
1194 * @hw: pointer to the HW structure
1196 * Read the management control register for the config done bit for
1197 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1198 * to read the config done bit, so an error is *ONLY* logged and returns
1199 * 0. If we were to return with error, EEPROM-less silicon
1200 * would not be able to be reset or change link.
1202 static s32
igb_get_cfg_done_82575(struct e1000_hw
*hw
)
1204 s32 timeout
= PHY_CFG_TIMEOUT
;
1206 u32 mask
= E1000_NVM_CFG_DONE_PORT_0
;
1208 if (hw
->bus
.func
== 1)
1209 mask
= E1000_NVM_CFG_DONE_PORT_1
;
1210 else if (hw
->bus
.func
== E1000_FUNC_2
)
1211 mask
= E1000_NVM_CFG_DONE_PORT_2
;
1212 else if (hw
->bus
.func
== E1000_FUNC_3
)
1213 mask
= E1000_NVM_CFG_DONE_PORT_3
;
1216 if (rd32(E1000_EEMNGCTL
) & mask
)
1222 hw_dbg("MNG configuration cycle has not completed.\n");
1224 /* If EEPROM is not marked present, init the PHY manually */
1225 if (((rd32(E1000_EECD
) & E1000_EECD_PRES
) == 0) &&
1226 (hw
->phy
.type
== e1000_phy_igp_3
))
1227 igb_phy_init_script_igp3(hw
);
1233 * igb_get_link_up_info_82575 - Get link speed/duplex info
1234 * @hw: pointer to the HW structure
1235 * @speed: stores the current speed
1236 * @duplex: stores the current duplex
1238 * This is a wrapper function, if using the serial gigabit media independent
1239 * interface, use PCS to retrieve the link speed and duplex information.
1240 * Otherwise, use the generic function to get the link speed and duplex info.
1242 static s32
igb_get_link_up_info_82575(struct e1000_hw
*hw
, u16
*speed
,
1247 if (hw
->phy
.media_type
!= e1000_media_type_copper
)
1248 ret_val
= igb_get_pcs_speed_and_duplex_82575(hw
, speed
,
1251 ret_val
= igb_get_speed_and_duplex_copper(hw
, speed
,
1258 * igb_check_for_link_82575 - Check for link
1259 * @hw: pointer to the HW structure
1261 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1262 * use the generic interface for determining link.
1264 static s32
igb_check_for_link_82575(struct e1000_hw
*hw
)
1269 if (hw
->phy
.media_type
!= e1000_media_type_copper
) {
1270 ret_val
= igb_get_pcs_speed_and_duplex_82575(hw
, &speed
,
1272 /* Use this flag to determine if link needs to be checked or
1273 * not. If we have link clear the flag so that we do not
1274 * continue to check for link.
1276 hw
->mac
.get_link_status
= !hw
->mac
.serdes_has_link
;
1278 /* Configure Flow Control now that Auto-Neg has completed.
1279 * First, we need to restore the desired flow control
1280 * settings because we may have had to re-autoneg with a
1281 * different link partner.
1283 ret_val
= igb_config_fc_after_link_up(hw
);
1285 hw_dbg("Error configuring flow control\n");
1287 ret_val
= igb_check_for_copper_link(hw
);
1294 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1295 * @hw: pointer to the HW structure
1297 void igb_power_up_serdes_link_82575(struct e1000_hw
*hw
)
1302 if ((hw
->phy
.media_type
!= e1000_media_type_internal_serdes
) &&
1303 !igb_sgmii_active_82575(hw
))
1306 /* Enable PCS to turn on link */
1307 reg
= rd32(E1000_PCS_CFG0
);
1308 reg
|= E1000_PCS_CFG_PCS_EN
;
1309 wr32(E1000_PCS_CFG0
, reg
);
1311 /* Power up the laser */
1312 reg
= rd32(E1000_CTRL_EXT
);
1313 reg
&= ~E1000_CTRL_EXT_SDP3_DATA
;
1314 wr32(E1000_CTRL_EXT
, reg
);
1316 /* flush the write to verify completion */
1322 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
1323 * @hw: pointer to the HW structure
1324 * @speed: stores the current speed
1325 * @duplex: stores the current duplex
1327 * Using the physical coding sub-layer (PCS), retrieve the current speed and
1328 * duplex, then store the values in the pointers provided.
1330 static s32
igb_get_pcs_speed_and_duplex_82575(struct e1000_hw
*hw
, u16
*speed
,
1333 struct e1000_mac_info
*mac
= &hw
->mac
;
1336 /* Set up defaults for the return values of this function */
1337 mac
->serdes_has_link
= false;
1341 /* Read the PCS Status register for link state. For non-copper mode,
1342 * the status register is not accurate. The PCS status register is
1345 pcs
= rd32(E1000_PCS_LSTAT
);
1347 /* The link up bit determines when link is up on autoneg. The sync ok
1348 * gets set once both sides sync up and agree upon link. Stable link
1349 * can be determined by checking for both link up and link sync ok
1351 if ((pcs
& E1000_PCS_LSTS_LINK_OK
) && (pcs
& E1000_PCS_LSTS_SYNK_OK
)) {
1352 mac
->serdes_has_link
= true;
1354 /* Detect and store PCS speed */
1355 if (pcs
& E1000_PCS_LSTS_SPEED_1000
)
1356 *speed
= SPEED_1000
;
1357 else if (pcs
& E1000_PCS_LSTS_SPEED_100
)
1362 /* Detect and store PCS duplex */
1363 if (pcs
& E1000_PCS_LSTS_DUPLEX_FULL
)
1364 *duplex
= FULL_DUPLEX
;
1366 *duplex
= HALF_DUPLEX
;
1368 /* Check if it is an I354 2.5Gb backplane connection. */
1369 if (mac
->type
== e1000_i354
) {
1370 status
= rd32(E1000_STATUS
);
1371 if ((status
& E1000_STATUS_2P5_SKU
) &&
1372 !(status
& E1000_STATUS_2P5_SKU_OVER
)) {
1373 *speed
= SPEED_2500
;
1374 *duplex
= FULL_DUPLEX
;
1375 hw_dbg("2500 Mbs, ");
1376 hw_dbg("Full Duplex\n");
1386 * igb_shutdown_serdes_link_82575 - Remove link during power down
1387 * @hw: pointer to the HW structure
1389 * In the case of fiber serdes, shut down optics and PCS on driver unload
1390 * when management pass thru is not enabled.
1392 void igb_shutdown_serdes_link_82575(struct e1000_hw
*hw
)
1396 if (hw
->phy
.media_type
!= e1000_media_type_internal_serdes
&&
1397 igb_sgmii_active_82575(hw
))
1400 if (!igb_enable_mng_pass_thru(hw
)) {
1401 /* Disable PCS to turn off link */
1402 reg
= rd32(E1000_PCS_CFG0
);
1403 reg
&= ~E1000_PCS_CFG_PCS_EN
;
1404 wr32(E1000_PCS_CFG0
, reg
);
1406 /* shutdown the laser */
1407 reg
= rd32(E1000_CTRL_EXT
);
1408 reg
|= E1000_CTRL_EXT_SDP3_DATA
;
1409 wr32(E1000_CTRL_EXT
, reg
);
1411 /* flush the write to verify completion */
1418 * igb_reset_hw_82575 - Reset hardware
1419 * @hw: pointer to the HW structure
1421 * This resets the hardware into a known state. This is a
1422 * function pointer entry point called by the api module.
1424 static s32
igb_reset_hw_82575(struct e1000_hw
*hw
)
1429 /* Prevent the PCI-E bus from sticking if there is no TLP connection
1430 * on the last TLP read/write transaction when MAC is reset.
1432 ret_val
= igb_disable_pcie_master(hw
);
1434 hw_dbg("PCI-E Master disable polling has failed.\n");
1436 /* set the completion timeout for interface */
1437 ret_val
= igb_set_pcie_completion_timeout(hw
);
1439 hw_dbg("PCI-E Set completion timeout has failed.\n");
1441 hw_dbg("Masking off all interrupts\n");
1442 wr32(E1000_IMC
, 0xffffffff);
1444 wr32(E1000_RCTL
, 0);
1445 wr32(E1000_TCTL
, E1000_TCTL_PSP
);
1450 ctrl
= rd32(E1000_CTRL
);
1452 hw_dbg("Issuing a global reset to MAC\n");
1453 wr32(E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
1455 ret_val
= igb_get_auto_rd_done(hw
);
1457 /* When auto config read does not complete, do not
1458 * return with an error. This can happen in situations
1459 * where there is no eeprom and prevents getting link.
1461 hw_dbg("Auto Read Done did not complete\n");
1464 /* If EEPROM is not present, run manual init scripts */
1465 if ((rd32(E1000_EECD
) & E1000_EECD_PRES
) == 0)
1466 igb_reset_init_script_82575(hw
);
1468 /* Clear any pending interrupt events. */
1469 wr32(E1000_IMC
, 0xffffffff);
1472 /* Install any alternate MAC address into RAR0 */
1473 ret_val
= igb_check_alt_mac_addr(hw
);
1479 * igb_init_hw_82575 - Initialize hardware
1480 * @hw: pointer to the HW structure
1482 * This inits the hardware readying it for operation.
1484 static s32
igb_init_hw_82575(struct e1000_hw
*hw
)
1486 struct e1000_mac_info
*mac
= &hw
->mac
;
1488 u16 i
, rar_count
= mac
->rar_entry_count
;
1490 /* Initialize identification LED */
1491 ret_val
= igb_id_led_init(hw
);
1493 hw_dbg("Error initializing identification LED\n");
1494 /* This is not fatal and we should not stop init due to this */
1497 /* Disabling VLAN filtering */
1498 hw_dbg("Initializing the IEEE VLAN\n");
1499 if ((hw
->mac
.type
== e1000_i350
) || (hw
->mac
.type
== e1000_i354
))
1500 igb_clear_vfta_i350(hw
);
1504 /* Setup the receive address */
1505 igb_init_rx_addrs(hw
, rar_count
);
1507 /* Zero out the Multicast HASH table */
1508 hw_dbg("Zeroing the MTA\n");
1509 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
1510 array_wr32(E1000_MTA
, i
, 0);
1512 /* Zero out the Unicast HASH table */
1513 hw_dbg("Zeroing the UTA\n");
1514 for (i
= 0; i
< mac
->uta_reg_count
; i
++)
1515 array_wr32(E1000_UTA
, i
, 0);
1517 /* Setup link and flow control */
1518 ret_val
= igb_setup_link(hw
);
1520 /* Clear all of the statistics registers (clear on read). It is
1521 * important that we do this after we have tried to establish link
1522 * because the symbol error count will increment wildly if there
1525 igb_clear_hw_cntrs_82575(hw
);
1530 * igb_setup_copper_link_82575 - Configure copper link settings
1531 * @hw: pointer to the HW structure
1533 * Configures the link for auto-neg or forced speed and duplex. Then we check
1534 * for link, once link is established calls to configure collision distance
1535 * and flow control are called.
1537 static s32
igb_setup_copper_link_82575(struct e1000_hw
*hw
)
1543 ctrl
= rd32(E1000_CTRL
);
1544 ctrl
|= E1000_CTRL_SLU
;
1545 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1546 wr32(E1000_CTRL
, ctrl
);
1548 /* Clear Go Link Disconnect bit on supported devices */
1549 switch (hw
->mac
.type
) {
1554 phpm_reg
= rd32(E1000_82580_PHY_POWER_MGMT
);
1555 phpm_reg
&= ~E1000_82580_PM_GO_LINKD
;
1556 wr32(E1000_82580_PHY_POWER_MGMT
, phpm_reg
);
1562 ret_val
= igb_setup_serdes_link_82575(hw
);
1566 if (igb_sgmii_active_82575(hw
) && !hw
->phy
.reset_disable
) {
1567 /* allow time for SFP cage time to power up phy */
1570 ret_val
= hw
->phy
.ops
.reset(hw
);
1572 hw_dbg("Error resetting the PHY.\n");
1576 switch (hw
->phy
.type
) {
1577 case e1000_phy_i210
:
1579 switch (hw
->phy
.id
) {
1580 case I347AT4_E_PHY_ID
:
1581 case M88E1112_E_PHY_ID
:
1582 case M88E1543_E_PHY_ID
:
1584 ret_val
= igb_copper_link_setup_m88_gen2(hw
);
1587 ret_val
= igb_copper_link_setup_m88(hw
);
1591 case e1000_phy_igp_3
:
1592 ret_val
= igb_copper_link_setup_igp(hw
);
1594 case e1000_phy_82580
:
1595 ret_val
= igb_copper_link_setup_82580(hw
);
1598 ret_val
= -E1000_ERR_PHY
;
1605 ret_val
= igb_setup_copper_link(hw
);
1611 * igb_setup_serdes_link_82575 - Setup link for serdes
1612 * @hw: pointer to the HW structure
1614 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1615 * used on copper connections where the serialized gigabit media independent
1616 * interface (sgmii), or serdes fiber is being used. Configures the link
1617 * for auto-negotiation or forces speed/duplex.
1619 static s32
igb_setup_serdes_link_82575(struct e1000_hw
*hw
)
1621 u32 ctrl_ext
, ctrl_reg
, reg
, anadv_reg
;
1623 s32 ret_val
= E1000_SUCCESS
;
1626 if ((hw
->phy
.media_type
!= e1000_media_type_internal_serdes
) &&
1627 !igb_sgmii_active_82575(hw
))
1631 /* On the 82575, SerDes loopback mode persists until it is
1632 * explicitly turned off or a power cycle is performed. A read to
1633 * the register does not indicate its status. Therefore, we ensure
1634 * loopback mode is disabled during initialization.
1636 wr32(E1000_SCTL
, E1000_SCTL_DISABLE_SERDES_LOOPBACK
);
1638 /* power on the sfp cage if present and turn on I2C */
1639 ctrl_ext
= rd32(E1000_CTRL_EXT
);
1640 ctrl_ext
&= ~E1000_CTRL_EXT_SDP3_DATA
;
1641 ctrl_ext
|= E1000_CTRL_I2C_ENA
;
1642 wr32(E1000_CTRL_EXT
, ctrl_ext
);
1644 ctrl_reg
= rd32(E1000_CTRL
);
1645 ctrl_reg
|= E1000_CTRL_SLU
;
1647 if (hw
->mac
.type
== e1000_82575
|| hw
->mac
.type
== e1000_82576
) {
1648 /* set both sw defined pins */
1649 ctrl_reg
|= E1000_CTRL_SWDPIN0
| E1000_CTRL_SWDPIN1
;
1651 /* Set switch control to serdes energy detect */
1652 reg
= rd32(E1000_CONNSW
);
1653 reg
|= E1000_CONNSW_ENRGSRC
;
1654 wr32(E1000_CONNSW
, reg
);
1657 reg
= rd32(E1000_PCS_LCTL
);
1659 /* default pcs_autoneg to the same setting as mac autoneg */
1660 pcs_autoneg
= hw
->mac
.autoneg
;
1662 switch (ctrl_ext
& E1000_CTRL_EXT_LINK_MODE_MASK
) {
1663 case E1000_CTRL_EXT_LINK_MODE_SGMII
:
1664 /* sgmii mode lets the phy handle forcing speed/duplex */
1666 /* autoneg time out should be disabled for SGMII mode */
1667 reg
&= ~(E1000_PCS_LCTL_AN_TIMEOUT
);
1669 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX
:
1670 /* disable PCS autoneg and support parallel detect only */
1671 pcs_autoneg
= false;
1673 if (hw
->mac
.type
== e1000_82575
||
1674 hw
->mac
.type
== e1000_82576
) {
1675 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPAT
, 1, &data
);
1677 hw_dbg(KERN_DEBUG
"NVM Read Error\n\n");
1681 if (data
& E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT
)
1682 pcs_autoneg
= false;
1685 /* non-SGMII modes only supports a speed of 1000/Full for the
1686 * link so it is best to just force the MAC and let the pcs
1687 * link either autoneg or be forced to 1000/Full
1689 ctrl_reg
|= E1000_CTRL_SPD_1000
| E1000_CTRL_FRCSPD
|
1690 E1000_CTRL_FD
| E1000_CTRL_FRCDPX
;
1692 /* set speed of 1000/Full if speed/duplex is forced */
1693 reg
|= E1000_PCS_LCTL_FSV_1000
| E1000_PCS_LCTL_FDV_FULL
;
1697 wr32(E1000_CTRL
, ctrl_reg
);
1699 /* New SerDes mode allows for forcing speed or autonegotiating speed
1700 * at 1gb. Autoneg should be default set by most drivers. This is the
1701 * mode that will be compatible with older link partners and switches.
1702 * However, both are supported by the hardware and some drivers/tools.
1704 reg
&= ~(E1000_PCS_LCTL_AN_ENABLE
| E1000_PCS_LCTL_FLV_LINK_UP
|
1705 E1000_PCS_LCTL_FSD
| E1000_PCS_LCTL_FORCE_LINK
);
1708 /* Set PCS register for autoneg */
1709 reg
|= E1000_PCS_LCTL_AN_ENABLE
| /* Enable Autoneg */
1710 E1000_PCS_LCTL_AN_RESTART
; /* Restart autoneg */
1712 /* Disable force flow control for autoneg */
1713 reg
&= ~E1000_PCS_LCTL_FORCE_FCTRL
;
1715 /* Configure flow control advertisement for autoneg */
1716 anadv_reg
= rd32(E1000_PCS_ANADV
);
1717 anadv_reg
&= ~(E1000_TXCW_ASM_DIR
| E1000_TXCW_PAUSE
);
1718 switch (hw
->fc
.requested_mode
) {
1720 case e1000_fc_rx_pause
:
1721 anadv_reg
|= E1000_TXCW_ASM_DIR
;
1722 anadv_reg
|= E1000_TXCW_PAUSE
;
1724 case e1000_fc_tx_pause
:
1725 anadv_reg
|= E1000_TXCW_ASM_DIR
;
1730 wr32(E1000_PCS_ANADV
, anadv_reg
);
1732 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg
);
1734 /* Set PCS register for forced link */
1735 reg
|= E1000_PCS_LCTL_FSD
; /* Force Speed */
1737 /* Force flow control for forced link */
1738 reg
|= E1000_PCS_LCTL_FORCE_FCTRL
;
1740 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg
);
1743 wr32(E1000_PCS_LCTL
, reg
);
1745 if (!pcs_autoneg
&& !igb_sgmii_active_82575(hw
))
1746 igb_force_mac_fc(hw
);
1752 * igb_sgmii_active_82575 - Return sgmii state
1753 * @hw: pointer to the HW structure
1755 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1756 * which can be enabled for use in the embedded applications. Simply
1757 * return the current state of the sgmii interface.
1759 static bool igb_sgmii_active_82575(struct e1000_hw
*hw
)
1761 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
1762 return dev_spec
->sgmii_active
;
1766 * igb_reset_init_script_82575 - Inits HW defaults after reset
1767 * @hw: pointer to the HW structure
1769 * Inits recommended HW defaults after a reset when there is no EEPROM
1770 * detected. This is only for the 82575.
1772 static s32
igb_reset_init_script_82575(struct e1000_hw
*hw
)
1774 if (hw
->mac
.type
== e1000_82575
) {
1775 hw_dbg("Running reset init script for 82575\n");
1776 /* SerDes configuration via SERDESCTRL */
1777 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x00, 0x0C);
1778 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x01, 0x78);
1779 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x1B, 0x23);
1780 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x23, 0x15);
1782 /* CCM configuration via CCMCTL register */
1783 igb_write_8bit_ctrl_reg(hw
, E1000_CCMCTL
, 0x14, 0x00);
1784 igb_write_8bit_ctrl_reg(hw
, E1000_CCMCTL
, 0x10, 0x00);
1786 /* PCIe lanes configuration */
1787 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x00, 0xEC);
1788 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x61, 0xDF);
1789 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x34, 0x05);
1790 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x2F, 0x81);
1792 /* PCIe PLL Configuration */
1793 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x02, 0x47);
1794 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x14, 0x00);
1795 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x10, 0x00);
1802 * igb_read_mac_addr_82575 - Read device MAC address
1803 * @hw: pointer to the HW structure
1805 static s32
igb_read_mac_addr_82575(struct e1000_hw
*hw
)
1809 /* If there's an alternate MAC address place it in RAR0
1810 * so that it will override the Si installed default perm
1813 ret_val
= igb_check_alt_mac_addr(hw
);
1817 ret_val
= igb_read_mac_addr(hw
);
1824 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1825 * @hw: pointer to the HW structure
1827 * In the case of a PHY power down to save power, or to turn off link during a
1828 * driver unload, or wake on lan is not enabled, remove the link.
1830 void igb_power_down_phy_copper_82575(struct e1000_hw
*hw
)
1832 /* If the management interface is not enabled, then power down */
1833 if (!(igb_enable_mng_pass_thru(hw
) || igb_check_reset_block(hw
)))
1834 igb_power_down_phy_copper(hw
);
1838 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
1839 * @hw: pointer to the HW structure
1841 * Clears the hardware counters by reading the counter registers.
1843 static void igb_clear_hw_cntrs_82575(struct e1000_hw
*hw
)
1845 igb_clear_hw_cntrs_base(hw
);
1851 rd32(E1000_PRC1023
);
1852 rd32(E1000_PRC1522
);
1857 rd32(E1000_PTC1023
);
1858 rd32(E1000_PTC1522
);
1860 rd32(E1000_ALGNERRC
);
1863 rd32(E1000_CEXTERR
);
1874 rd32(E1000_ICRXPTC
);
1875 rd32(E1000_ICRXATC
);
1876 rd32(E1000_ICTXPTC
);
1877 rd32(E1000_ICTXATC
);
1878 rd32(E1000_ICTXQEC
);
1879 rd32(E1000_ICTXQMTC
);
1880 rd32(E1000_ICRXDMTC
);
1887 rd32(E1000_HTCBDPC
);
1892 rd32(E1000_LENERRS
);
1894 /* This register should not be read in copper configurations */
1895 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
||
1896 igb_sgmii_active_82575(hw
))
1901 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1902 * @hw: pointer to the HW structure
1904 * After rx enable if managability is enabled then there is likely some
1905 * bad data at the start of the fifo and possibly in the DMA fifo. This
1906 * function clears the fifos and flushes any packets that came in as rx was
1909 void igb_rx_fifo_flush_82575(struct e1000_hw
*hw
)
1911 u32 rctl
, rlpml
, rxdctl
[4], rfctl
, temp_rctl
, rx_enabled
;
1914 if (hw
->mac
.type
!= e1000_82575
||
1915 !(rd32(E1000_MANC
) & E1000_MANC_RCV_TCO_EN
))
1918 /* Disable all RX queues */
1919 for (i
= 0; i
< 4; i
++) {
1920 rxdctl
[i
] = rd32(E1000_RXDCTL(i
));
1921 wr32(E1000_RXDCTL(i
),
1922 rxdctl
[i
] & ~E1000_RXDCTL_QUEUE_ENABLE
);
1924 /* Poll all queues to verify they have shut down */
1925 for (ms_wait
= 0; ms_wait
< 10; ms_wait
++) {
1928 for (i
= 0; i
< 4; i
++)
1929 rx_enabled
|= rd32(E1000_RXDCTL(i
));
1930 if (!(rx_enabled
& E1000_RXDCTL_QUEUE_ENABLE
))
1935 hw_dbg("Queue disable timed out after 10ms\n");
1937 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1938 * incoming packets are rejected. Set enable and wait 2ms so that
1939 * any packet that was coming in as RCTL.EN was set is flushed
1941 rfctl
= rd32(E1000_RFCTL
);
1942 wr32(E1000_RFCTL
, rfctl
& ~E1000_RFCTL_LEF
);
1944 rlpml
= rd32(E1000_RLPML
);
1945 wr32(E1000_RLPML
, 0);
1947 rctl
= rd32(E1000_RCTL
);
1948 temp_rctl
= rctl
& ~(E1000_RCTL_EN
| E1000_RCTL_SBP
);
1949 temp_rctl
|= E1000_RCTL_LPE
;
1951 wr32(E1000_RCTL
, temp_rctl
);
1952 wr32(E1000_RCTL
, temp_rctl
| E1000_RCTL_EN
);
1956 /* Enable RX queues that were previously enabled and restore our
1959 for (i
= 0; i
< 4; i
++)
1960 wr32(E1000_RXDCTL(i
), rxdctl
[i
]);
1961 wr32(E1000_RCTL
, rctl
);
1964 wr32(E1000_RLPML
, rlpml
);
1965 wr32(E1000_RFCTL
, rfctl
);
1967 /* Flush receive errors generated by workaround */
1974 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1975 * @hw: pointer to the HW structure
1977 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1978 * however the hardware default for these parts is 500us to 1ms which is less
1979 * than the 10ms recommended by the pci-e spec. To address this we need to
1980 * increase the value to either 10ms to 200ms for capability version 1 config,
1981 * or 16ms to 55ms for version 2.
1983 static s32
igb_set_pcie_completion_timeout(struct e1000_hw
*hw
)
1985 u32 gcr
= rd32(E1000_GCR
);
1989 /* only take action if timeout value is defaulted to 0 */
1990 if (gcr
& E1000_GCR_CMPL_TMOUT_MASK
)
1993 /* if capabilities version is type 1 we can write the
1994 * timeout of 10ms to 200ms through the GCR register
1996 if (!(gcr
& E1000_GCR_CAP_VER2
)) {
1997 gcr
|= E1000_GCR_CMPL_TMOUT_10ms
;
2001 /* for version 2 capabilities we need to write the config space
2002 * directly in order to set the completion timeout value for
2005 ret_val
= igb_read_pcie_cap_reg(hw
, PCIE_DEVICE_CONTROL2
,
2010 pcie_devctl2
|= PCIE_DEVICE_CONTROL2_16ms
;
2012 ret_val
= igb_write_pcie_cap_reg(hw
, PCIE_DEVICE_CONTROL2
,
2015 /* disable completion timeout resend */
2016 gcr
&= ~E1000_GCR_CMPL_TMOUT_RESEND
;
2018 wr32(E1000_GCR
, gcr
);
2023 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2024 * @hw: pointer to the hardware struct
2025 * @enable: state to enter, either enabled or disabled
2026 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2028 * enables/disables L2 switch anti-spoofing functionality.
2030 void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw
*hw
, bool enable
, int pf
)
2032 u32 reg_val
, reg_offset
;
2034 switch (hw
->mac
.type
) {
2036 reg_offset
= E1000_DTXSWC
;
2040 reg_offset
= E1000_TXSWC
;
2046 reg_val
= rd32(reg_offset
);
2048 reg_val
|= (E1000_DTXSWC_MAC_SPOOF_MASK
|
2049 E1000_DTXSWC_VLAN_SPOOF_MASK
);
2050 /* The PF can spoof - it has to in order to
2051 * support emulation mode NICs
2053 reg_val
^= (1 << pf
| 1 << (pf
+ MAX_NUM_VFS
));
2055 reg_val
&= ~(E1000_DTXSWC_MAC_SPOOF_MASK
|
2056 E1000_DTXSWC_VLAN_SPOOF_MASK
);
2058 wr32(reg_offset
, reg_val
);
2062 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2063 * @hw: pointer to the hardware struct
2064 * @enable: state to enter, either enabled or disabled
2066 * enables/disables L2 switch loopback functionality.
2068 void igb_vmdq_set_loopback_pf(struct e1000_hw
*hw
, bool enable
)
2072 switch (hw
->mac
.type
) {
2074 dtxswc
= rd32(E1000_DTXSWC
);
2076 dtxswc
|= E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2078 dtxswc
&= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2079 wr32(E1000_DTXSWC
, dtxswc
);
2083 dtxswc
= rd32(E1000_TXSWC
);
2085 dtxswc
|= E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2087 dtxswc
&= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2088 wr32(E1000_TXSWC
, dtxswc
);
2091 /* Currently no other hardware supports loopback */
2098 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2099 * @hw: pointer to the hardware struct
2100 * @enable: state to enter, either enabled or disabled
2102 * enables/disables replication of packets across multiple pools.
2104 void igb_vmdq_set_replication_pf(struct e1000_hw
*hw
, bool enable
)
2106 u32 vt_ctl
= rd32(E1000_VT_CTL
);
2109 vt_ctl
|= E1000_VT_CTL_VM_REPL_EN
;
2111 vt_ctl
&= ~E1000_VT_CTL_VM_REPL_EN
;
2113 wr32(E1000_VT_CTL
, vt_ctl
);
2117 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2118 * @hw: pointer to the HW structure
2119 * @offset: register offset to be read
2120 * @data: pointer to the read data
2122 * Reads the MDI control register in the PHY at offset and stores the
2123 * information read to data.
2125 static s32
igb_read_phy_reg_82580(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
2129 ret_val
= hw
->phy
.ops
.acquire(hw
);
2133 ret_val
= igb_read_phy_reg_mdic(hw
, offset
, data
);
2135 hw
->phy
.ops
.release(hw
);
2142 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2143 * @hw: pointer to the HW structure
2144 * @offset: register offset to write to
2145 * @data: data to write to register at offset
2147 * Writes data to MDI control register in the PHY at offset.
2149 static s32
igb_write_phy_reg_82580(struct e1000_hw
*hw
, u32 offset
, u16 data
)
2154 ret_val
= hw
->phy
.ops
.acquire(hw
);
2158 ret_val
= igb_write_phy_reg_mdic(hw
, offset
, data
);
2160 hw
->phy
.ops
.release(hw
);
2167 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2168 * @hw: pointer to the HW structure
2170 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2171 * the values found in the EEPROM. This addresses an issue in which these
2172 * bits are not restored from EEPROM after reset.
2174 static s32
igb_reset_mdicnfg_82580(struct e1000_hw
*hw
)
2180 if (hw
->mac
.type
!= e1000_82580
)
2182 if (!igb_sgmii_active_82575(hw
))
2185 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_A
+
2186 NVM_82580_LAN_FUNC_OFFSET(hw
->bus
.func
), 1,
2189 hw_dbg("NVM Read Error\n");
2193 mdicnfg
= rd32(E1000_MDICNFG
);
2194 if (nvm_data
& NVM_WORD24_EXT_MDIO
)
2195 mdicnfg
|= E1000_MDICNFG_EXT_MDIO
;
2196 if (nvm_data
& NVM_WORD24_COM_MDIO
)
2197 mdicnfg
|= E1000_MDICNFG_COM_MDIO
;
2198 wr32(E1000_MDICNFG
, mdicnfg
);
2204 * igb_reset_hw_82580 - Reset hardware
2205 * @hw: pointer to the HW structure
2207 * This resets function or entire device (all ports, etc.)
2210 static s32
igb_reset_hw_82580(struct e1000_hw
*hw
)
2213 /* BH SW mailbox bit in SW_FW_SYNC */
2214 u16 swmbsw_mask
= E1000_SW_SYNCH_MB
;
2216 bool global_device_reset
= hw
->dev_spec
._82575
.global_device_reset
;
2218 hw
->dev_spec
._82575
.global_device_reset
= false;
2220 /* due to hw errata, global device reset doesn't always
2223 if (hw
->mac
.type
== e1000_82580
)
2224 global_device_reset
= false;
2226 /* Get current control state. */
2227 ctrl
= rd32(E1000_CTRL
);
2229 /* Prevent the PCI-E bus from sticking if there is no TLP connection
2230 * on the last TLP read/write transaction when MAC is reset.
2232 ret_val
= igb_disable_pcie_master(hw
);
2234 hw_dbg("PCI-E Master disable polling has failed.\n");
2236 hw_dbg("Masking off all interrupts\n");
2237 wr32(E1000_IMC
, 0xffffffff);
2238 wr32(E1000_RCTL
, 0);
2239 wr32(E1000_TCTL
, E1000_TCTL_PSP
);
2244 /* Determine whether or not a global dev reset is requested */
2245 if (global_device_reset
&&
2246 hw
->mac
.ops
.acquire_swfw_sync(hw
, swmbsw_mask
))
2247 global_device_reset
= false;
2249 if (global_device_reset
&&
2250 !(rd32(E1000_STATUS
) & E1000_STAT_DEV_RST_SET
))
2251 ctrl
|= E1000_CTRL_DEV_RST
;
2253 ctrl
|= E1000_CTRL_RST
;
2255 wr32(E1000_CTRL
, ctrl
);
2258 /* Add delay to insure DEV_RST has time to complete */
2259 if (global_device_reset
)
2262 ret_val
= igb_get_auto_rd_done(hw
);
2264 /* When auto config read does not complete, do not
2265 * return with an error. This can happen in situations
2266 * where there is no eeprom and prevents getting link.
2268 hw_dbg("Auto Read Done did not complete\n");
2271 /* clear global device reset status bit */
2272 wr32(E1000_STATUS
, E1000_STAT_DEV_RST_SET
);
2274 /* Clear any pending interrupt events. */
2275 wr32(E1000_IMC
, 0xffffffff);
2278 ret_val
= igb_reset_mdicnfg_82580(hw
);
2280 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2282 /* Install any alternate MAC address into RAR0 */
2283 ret_val
= igb_check_alt_mac_addr(hw
);
2285 /* Release semaphore */
2286 if (global_device_reset
)
2287 hw
->mac
.ops
.release_swfw_sync(hw
, swmbsw_mask
);
2293 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2294 * @data: data received by reading RXPBS register
2296 * The 82580 uses a table based approach for packet buffer allocation sizes.
2297 * This function converts the retrieved value into the correct table value
2298 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2299 * 0x0 36 72 144 1 2 4 8 16
2300 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2302 u16
igb_rxpbs_adjust_82580(u32 data
)
2306 if (data
< ARRAY_SIZE(e1000_82580_rxpbs_table
))
2307 ret_val
= e1000_82580_rxpbs_table
[data
];
2313 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2315 * @hw: pointer to the HW structure
2316 * @offset: offset in words of the checksum protected region
2318 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2319 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2321 static s32
igb_validate_nvm_checksum_with_offset(struct e1000_hw
*hw
,
2328 for (i
= offset
; i
< ((NVM_CHECKSUM_REG
+ offset
) + 1); i
++) {
2329 ret_val
= hw
->nvm
.ops
.read(hw
, i
, 1, &nvm_data
);
2331 hw_dbg("NVM Read Error\n");
2334 checksum
+= nvm_data
;
2337 if (checksum
!= (u16
) NVM_SUM
) {
2338 hw_dbg("NVM Checksum Invalid\n");
2339 ret_val
= -E1000_ERR_NVM
;
2348 * igb_update_nvm_checksum_with_offset - Update EEPROM
2350 * @hw: pointer to the HW structure
2351 * @offset: offset in words of the checksum protected region
2353 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2354 * up to the checksum. Then calculates the EEPROM checksum and writes the
2355 * value to the EEPROM.
2357 static s32
igb_update_nvm_checksum_with_offset(struct e1000_hw
*hw
, u16 offset
)
2363 for (i
= offset
; i
< (NVM_CHECKSUM_REG
+ offset
); i
++) {
2364 ret_val
= hw
->nvm
.ops
.read(hw
, i
, 1, &nvm_data
);
2366 hw_dbg("NVM Read Error while updating checksum.\n");
2369 checksum
+= nvm_data
;
2371 checksum
= (u16
) NVM_SUM
- checksum
;
2372 ret_val
= hw
->nvm
.ops
.write(hw
, (NVM_CHECKSUM_REG
+ offset
), 1,
2375 hw_dbg("NVM Write Error while updating checksum.\n");
2382 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2383 * @hw: pointer to the HW structure
2385 * Calculates the EEPROM section checksum by reading/adding each word of
2386 * the EEPROM and then verifies that the sum of the EEPROM is
2389 static s32
igb_validate_nvm_checksum_82580(struct e1000_hw
*hw
)
2392 u16 eeprom_regions_count
= 1;
2396 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPATIBILITY_REG_3
, 1, &nvm_data
);
2398 hw_dbg("NVM Read Error\n");
2402 if (nvm_data
& NVM_COMPATIBILITY_BIT_MASK
) {
2403 /* if checksums compatibility bit is set validate checksums
2406 eeprom_regions_count
= 4;
2409 for (j
= 0; j
< eeprom_regions_count
; j
++) {
2410 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2411 ret_val
= igb_validate_nvm_checksum_with_offset(hw
,
2422 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2423 * @hw: pointer to the HW structure
2425 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2426 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2427 * checksum and writes the value to the EEPROM.
2429 static s32
igb_update_nvm_checksum_82580(struct e1000_hw
*hw
)
2435 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPATIBILITY_REG_3
, 1, &nvm_data
);
2437 hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
2441 if ((nvm_data
& NVM_COMPATIBILITY_BIT_MASK
) == 0) {
2442 /* set compatibility bit to validate checksums appropriately */
2443 nvm_data
= nvm_data
| NVM_COMPATIBILITY_BIT_MASK
;
2444 ret_val
= hw
->nvm
.ops
.write(hw
, NVM_COMPATIBILITY_REG_3
, 1,
2447 hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
2452 for (j
= 0; j
< 4; j
++) {
2453 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2454 ret_val
= igb_update_nvm_checksum_with_offset(hw
, nvm_offset
);
2464 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2465 * @hw: pointer to the HW structure
2467 * Calculates the EEPROM section checksum by reading/adding each word of
2468 * the EEPROM and then verifies that the sum of the EEPROM is
2471 static s32
igb_validate_nvm_checksum_i350(struct e1000_hw
*hw
)
2477 for (j
= 0; j
< 4; j
++) {
2478 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2479 ret_val
= igb_validate_nvm_checksum_with_offset(hw
,
2490 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2491 * @hw: pointer to the HW structure
2493 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2494 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2495 * checksum and writes the value to the EEPROM.
2497 static s32
igb_update_nvm_checksum_i350(struct e1000_hw
*hw
)
2503 for (j
= 0; j
< 4; j
++) {
2504 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2505 ret_val
= igb_update_nvm_checksum_with_offset(hw
, nvm_offset
);
2515 * __igb_access_emi_reg - Read/write EMI register
2516 * @hw: pointer to the HW structure
2517 * @addr: EMI address to program
2518 * @data: pointer to value to read/write from/to the EMI address
2519 * @read: boolean flag to indicate read or write
2521 static s32
__igb_access_emi_reg(struct e1000_hw
*hw
, u16 address
,
2522 u16
*data
, bool read
)
2524 s32 ret_val
= E1000_SUCCESS
;
2526 ret_val
= hw
->phy
.ops
.write_reg(hw
, E1000_EMIADD
, address
);
2531 ret_val
= hw
->phy
.ops
.read_reg(hw
, E1000_EMIDATA
, data
);
2533 ret_val
= hw
->phy
.ops
.write_reg(hw
, E1000_EMIDATA
, *data
);
2539 * igb_read_emi_reg - Read Extended Management Interface register
2540 * @hw: pointer to the HW structure
2541 * @addr: EMI address to program
2542 * @data: value to be read from the EMI address
2544 s32
igb_read_emi_reg(struct e1000_hw
*hw
, u16 addr
, u16
*data
)
2546 return __igb_access_emi_reg(hw
, addr
, data
, true);
2550 * igb_set_eee_i350 - Enable/disable EEE support
2551 * @hw: pointer to the HW structure
2553 * Enable/disable EEE based on setting in dev_spec structure.
2556 s32
igb_set_eee_i350(struct e1000_hw
*hw
)
2561 if ((hw
->mac
.type
< e1000_i350
) ||
2562 (hw
->phy
.media_type
!= e1000_media_type_copper
))
2564 ipcnfg
= rd32(E1000_IPCNFG
);
2565 eeer
= rd32(E1000_EEER
);
2567 /* enable or disable per user setting */
2568 if (!(hw
->dev_spec
._82575
.eee_disable
)) {
2569 u32 eee_su
= rd32(E1000_EEE_SU
);
2571 ipcnfg
|= (E1000_IPCNFG_EEE_1G_AN
| E1000_IPCNFG_EEE_100M_AN
);
2572 eeer
|= (E1000_EEER_TX_LPI_EN
| E1000_EEER_RX_LPI_EN
|
2575 /* This bit should not be set in normal operation. */
2576 if (eee_su
& E1000_EEE_SU_LPI_CLK_STP
)
2577 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2580 ipcnfg
&= ~(E1000_IPCNFG_EEE_1G_AN
|
2581 E1000_IPCNFG_EEE_100M_AN
);
2582 eeer
&= ~(E1000_EEER_TX_LPI_EN
|
2583 E1000_EEER_RX_LPI_EN
|
2586 wr32(E1000_IPCNFG
, ipcnfg
);
2587 wr32(E1000_EEER
, eeer
);
2596 * igb_set_eee_i354 - Enable/disable EEE support
2597 * @hw: pointer to the HW structure
2599 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2602 s32
igb_set_eee_i354(struct e1000_hw
*hw
)
2604 struct e1000_phy_info
*phy
= &hw
->phy
;
2608 if ((hw
->phy
.media_type
!= e1000_media_type_copper
) ||
2609 (phy
->id
!= M88E1543_E_PHY_ID
))
2612 if (!hw
->dev_spec
._82575
.eee_disable
) {
2613 /* Switch to PHY page 18. */
2614 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_PAGE_ADDR
, 18);
2618 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1543_EEE_CTRL_1
,
2623 phy_data
|= E1000_M88E1543_EEE_CTRL_1_MS
;
2624 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_EEE_CTRL_1
,
2629 /* Return the PHY to page 0. */
2630 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_PAGE_ADDR
, 0);
2634 /* Turn on EEE advertisement. */
2635 ret_val
= igb_read_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2636 E1000_EEE_ADV_DEV_I354
,
2641 phy_data
|= E1000_EEE_ADV_100_SUPPORTED
|
2642 E1000_EEE_ADV_1000_SUPPORTED
;
2643 ret_val
= igb_write_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2644 E1000_EEE_ADV_DEV_I354
,
2647 /* Turn off EEE advertisement. */
2648 ret_val
= igb_read_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2649 E1000_EEE_ADV_DEV_I354
,
2654 phy_data
&= ~(E1000_EEE_ADV_100_SUPPORTED
|
2655 E1000_EEE_ADV_1000_SUPPORTED
);
2656 ret_val
= igb_write_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2657 E1000_EEE_ADV_DEV_I354
,
2666 * igb_get_eee_status_i354 - Get EEE status
2667 * @hw: pointer to the HW structure
2668 * @status: EEE status
2670 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2673 s32
igb_get_eee_status_i354(struct e1000_hw
*hw
, bool *status
)
2675 struct e1000_phy_info
*phy
= &hw
->phy
;
2679 /* Check if EEE is supported on this device. */
2680 if ((hw
->phy
.media_type
!= e1000_media_type_copper
) ||
2681 (phy
->id
!= M88E1543_E_PHY_ID
))
2684 ret_val
= igb_read_xmdio_reg(hw
, E1000_PCS_STATUS_ADDR_I354
,
2685 E1000_PCS_STATUS_DEV_I354
,
2690 *status
= phy_data
& (E1000_PCS_STATUS_TX_LPI_RCVD
|
2691 E1000_PCS_STATUS_RX_LPI_RCVD
) ? true : false;
2697 static const u8 e1000_emc_temp_data
[4] = {
2698 E1000_EMC_INTERNAL_DATA
,
2699 E1000_EMC_DIODE1_DATA
,
2700 E1000_EMC_DIODE2_DATA
,
2701 E1000_EMC_DIODE3_DATA
2703 static const u8 e1000_emc_therm_limit
[4] = {
2704 E1000_EMC_INTERNAL_THERM_LIMIT
,
2705 E1000_EMC_DIODE1_THERM_LIMIT
,
2706 E1000_EMC_DIODE2_THERM_LIMIT
,
2707 E1000_EMC_DIODE3_THERM_LIMIT
2710 #ifdef CONFIG_IGB_HWMON
2712 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
2713 * @hw: pointer to hardware structure
2715 * Updates the temperatures in mac.thermal_sensor_data
2717 static s32
igb_get_thermal_sensor_data_generic(struct e1000_hw
*hw
)
2719 s32 status
= E1000_SUCCESS
;
2727 struct e1000_thermal_sensor_data
*data
= &hw
->mac
.thermal_sensor_data
;
2729 if ((hw
->mac
.type
!= e1000_i350
) || (hw
->bus
.func
!= 0))
2730 return E1000_NOT_IMPLEMENTED
;
2732 data
->sensor
[0].temp
= (rd32(E1000_THMJT
) & 0xFF);
2734 /* Return the internal sensor only if ETS is unsupported */
2735 hw
->nvm
.ops
.read(hw
, NVM_ETS_CFG
, 1, &ets_offset
);
2736 if ((ets_offset
== 0x0000) || (ets_offset
== 0xFFFF))
2739 hw
->nvm
.ops
.read(hw
, ets_offset
, 1, &ets_cfg
);
2740 if (((ets_cfg
& NVM_ETS_TYPE_MASK
) >> NVM_ETS_TYPE_SHIFT
)
2741 != NVM_ETS_TYPE_EMC
)
2742 return E1000_NOT_IMPLEMENTED
;
2744 num_sensors
= (ets_cfg
& NVM_ETS_NUM_SENSORS_MASK
);
2745 if (num_sensors
> E1000_MAX_SENSORS
)
2746 num_sensors
= E1000_MAX_SENSORS
;
2748 for (i
= 1; i
< num_sensors
; i
++) {
2749 hw
->nvm
.ops
.read(hw
, (ets_offset
+ i
), 1, &ets_sensor
);
2750 sensor_index
= ((ets_sensor
& NVM_ETS_DATA_INDEX_MASK
) >>
2751 NVM_ETS_DATA_INDEX_SHIFT
);
2752 sensor_location
= ((ets_sensor
& NVM_ETS_DATA_LOC_MASK
) >>
2753 NVM_ETS_DATA_LOC_SHIFT
);
2755 if (sensor_location
!= 0)
2756 hw
->phy
.ops
.read_i2c_byte(hw
,
2757 e1000_emc_temp_data
[sensor_index
],
2758 E1000_I2C_THERMAL_SENSOR_ADDR
,
2759 &data
->sensor
[i
].temp
);
2765 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
2766 * @hw: pointer to hardware structure
2768 * Sets the thermal sensor thresholds according to the NVM map
2769 * and save off the threshold and location values into mac.thermal_sensor_data
2771 static s32
igb_init_thermal_sensor_thresh_generic(struct e1000_hw
*hw
)
2773 s32 status
= E1000_SUCCESS
;
2777 u8 low_thresh_delta
;
2783 struct e1000_thermal_sensor_data
*data
= &hw
->mac
.thermal_sensor_data
;
2785 if ((hw
->mac
.type
!= e1000_i350
) || (hw
->bus
.func
!= 0))
2786 return E1000_NOT_IMPLEMENTED
;
2788 memset(data
, 0, sizeof(struct e1000_thermal_sensor_data
));
2790 data
->sensor
[0].location
= 0x1;
2791 data
->sensor
[0].caution_thresh
=
2792 (rd32(E1000_THHIGHTC
) & 0xFF);
2793 data
->sensor
[0].max_op_thresh
=
2794 (rd32(E1000_THLOWTC
) & 0xFF);
2796 /* Return the internal sensor only if ETS is unsupported */
2797 hw
->nvm
.ops
.read(hw
, NVM_ETS_CFG
, 1, &ets_offset
);
2798 if ((ets_offset
== 0x0000) || (ets_offset
== 0xFFFF))
2801 hw
->nvm
.ops
.read(hw
, ets_offset
, 1, &ets_cfg
);
2802 if (((ets_cfg
& NVM_ETS_TYPE_MASK
) >> NVM_ETS_TYPE_SHIFT
)
2803 != NVM_ETS_TYPE_EMC
)
2804 return E1000_NOT_IMPLEMENTED
;
2806 low_thresh_delta
= ((ets_cfg
& NVM_ETS_LTHRES_DELTA_MASK
) >>
2807 NVM_ETS_LTHRES_DELTA_SHIFT
);
2808 num_sensors
= (ets_cfg
& NVM_ETS_NUM_SENSORS_MASK
);
2810 for (i
= 1; i
<= num_sensors
; i
++) {
2811 hw
->nvm
.ops
.read(hw
, (ets_offset
+ i
), 1, &ets_sensor
);
2812 sensor_index
= ((ets_sensor
& NVM_ETS_DATA_INDEX_MASK
) >>
2813 NVM_ETS_DATA_INDEX_SHIFT
);
2814 sensor_location
= ((ets_sensor
& NVM_ETS_DATA_LOC_MASK
) >>
2815 NVM_ETS_DATA_LOC_SHIFT
);
2816 therm_limit
= ets_sensor
& NVM_ETS_DATA_HTHRESH_MASK
;
2818 hw
->phy
.ops
.write_i2c_byte(hw
,
2819 e1000_emc_therm_limit
[sensor_index
],
2820 E1000_I2C_THERMAL_SENSOR_ADDR
,
2823 if ((i
< E1000_MAX_SENSORS
) && (sensor_location
!= 0)) {
2824 data
->sensor
[i
].location
= sensor_location
;
2825 data
->sensor
[i
].caution_thresh
= therm_limit
;
2826 data
->sensor
[i
].max_op_thresh
= therm_limit
-
2834 static struct e1000_mac_operations e1000_mac_ops_82575
= {
2835 .init_hw
= igb_init_hw_82575
,
2836 .check_for_link
= igb_check_for_link_82575
,
2837 .rar_set
= igb_rar_set
,
2838 .read_mac_addr
= igb_read_mac_addr_82575
,
2839 .get_speed_and_duplex
= igb_get_link_up_info_82575
,
2840 #ifdef CONFIG_IGB_HWMON
2841 .get_thermal_sensor_data
= igb_get_thermal_sensor_data_generic
,
2842 .init_thermal_sensor_thresh
= igb_init_thermal_sensor_thresh_generic
,
2846 static struct e1000_phy_operations e1000_phy_ops_82575
= {
2847 .acquire
= igb_acquire_phy_82575
,
2848 .get_cfg_done
= igb_get_cfg_done_82575
,
2849 .release
= igb_release_phy_82575
,
2850 .write_i2c_byte
= igb_write_i2c_byte
,
2851 .read_i2c_byte
= igb_read_i2c_byte
,
2854 static struct e1000_nvm_operations e1000_nvm_ops_82575
= {
2855 .acquire
= igb_acquire_nvm_82575
,
2856 .read
= igb_read_nvm_eerd
,
2857 .release
= igb_release_nvm_82575
,
2858 .write
= igb_write_nvm_spi
,
2861 const struct e1000_info e1000_82575_info
= {
2862 .get_invariants
= igb_get_invariants_82575
,
2863 .mac_ops
= &e1000_mac_ops_82575
,
2864 .phy_ops
= &e1000_phy_ops_82575
,
2865 .nvm_ops
= &e1000_nvm_ops_82575
,