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,
79 #define E1000_82580_RXPBS_TABLE_SIZE \
80 (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
83 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
84 * @hw: pointer to the HW structure
86 * Called to determine if the I2C pins are being used for I2C or as an
87 * external MDIO interface since the two options are mutually exclusive.
89 static bool igb_sgmii_uses_mdio_82575(struct e1000_hw
*hw
)
92 bool ext_mdio
= false;
94 switch (hw
->mac
.type
) {
97 reg
= rd32(E1000_MDIC
);
98 ext_mdio
= !!(reg
& E1000_MDIC_DEST
);
105 reg
= rd32(E1000_MDICNFG
);
106 ext_mdio
= !!(reg
& E1000_MDICNFG_EXT_MDIO
);
115 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
116 * @hw: pointer to the HW structure
118 * Poll the M88E1112 interfaces to see which interface achieved link.
120 static s32
igb_check_for_link_media_swap(struct e1000_hw
*hw
)
122 struct e1000_phy_info
*phy
= &hw
->phy
;
127 /* Check the copper medium. */
128 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 0);
132 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1112_STATUS
, &data
);
136 if (data
& E1000_M88E1112_STATUS_LINK
)
137 port
= E1000_MEDIA_PORT_COPPER
;
139 /* Check the other medium. */
140 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 1);
144 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1112_STATUS
, &data
);
148 /* reset page to 0 */
149 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1112_PAGE_ADDR
, 0);
153 if (data
& E1000_M88E1112_STATUS_LINK
)
154 port
= E1000_MEDIA_PORT_OTHER
;
156 /* Determine if a swap needs to happen. */
157 if (port
&& (hw
->dev_spec
._82575
.media_port
!= port
)) {
158 hw
->dev_spec
._82575
.media_port
= port
;
159 hw
->dev_spec
._82575
.media_changed
= true;
161 ret_val
= igb_check_for_link_82575(hw
);
164 return E1000_SUCCESS
;
168 * igb_init_phy_params_82575 - Init PHY func ptrs.
169 * @hw: pointer to the HW structure
171 static s32
igb_init_phy_params_82575(struct e1000_hw
*hw
)
173 struct e1000_phy_info
*phy
= &hw
->phy
;
177 if (hw
->phy
.media_type
!= e1000_media_type_copper
) {
178 phy
->type
= e1000_phy_none
;
182 phy
->autoneg_mask
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
183 phy
->reset_delay_us
= 100;
185 ctrl_ext
= rd32(E1000_CTRL_EXT
);
187 if (igb_sgmii_active_82575(hw
)) {
188 phy
->ops
.reset
= igb_phy_hw_reset_sgmii_82575
;
189 ctrl_ext
|= E1000_CTRL_I2C_ENA
;
191 phy
->ops
.reset
= igb_phy_hw_reset
;
192 ctrl_ext
&= ~E1000_CTRL_I2C_ENA
;
195 wr32(E1000_CTRL_EXT
, ctrl_ext
);
196 igb_reset_mdicnfg_82580(hw
);
198 if (igb_sgmii_active_82575(hw
) && !igb_sgmii_uses_mdio_82575(hw
)) {
199 phy
->ops
.read_reg
= igb_read_phy_reg_sgmii_82575
;
200 phy
->ops
.write_reg
= igb_write_phy_reg_sgmii_82575
;
202 switch (hw
->mac
.type
) {
206 phy
->ops
.read_reg
= igb_read_phy_reg_82580
;
207 phy
->ops
.write_reg
= igb_write_phy_reg_82580
;
211 phy
->ops
.read_reg
= igb_read_phy_reg_gs40g
;
212 phy
->ops
.write_reg
= igb_write_phy_reg_gs40g
;
215 phy
->ops
.read_reg
= igb_read_phy_reg_igp
;
216 phy
->ops
.write_reg
= igb_write_phy_reg_igp
;
221 hw
->bus
.func
= (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_MASK
) >>
222 E1000_STATUS_FUNC_SHIFT
;
224 /* Set phy->phy_addr and phy->id. */
225 ret_val
= igb_get_phy_id_82575(hw
);
229 /* Verify phy id and set remaining function pointers */
231 case M88E1543_E_PHY_ID
:
232 case I347AT4_E_PHY_ID
:
233 case M88E1112_E_PHY_ID
:
234 case M88E1111_I_PHY_ID
:
235 phy
->type
= e1000_phy_m88
;
236 phy
->ops
.check_polarity
= igb_check_polarity_m88
;
237 phy
->ops
.get_phy_info
= igb_get_phy_info_m88
;
238 if (phy
->id
!= M88E1111_I_PHY_ID
)
239 phy
->ops
.get_cable_length
=
240 igb_get_cable_length_m88_gen2
;
242 phy
->ops
.get_cable_length
= igb_get_cable_length_m88
;
243 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_m88
;
244 /* Check if this PHY is confgured for media swap. */
245 if (phy
->id
== M88E1112_E_PHY_ID
) {
248 ret_val
= phy
->ops
.write_reg(hw
,
249 E1000_M88E1112_PAGE_ADDR
,
254 ret_val
= phy
->ops
.read_reg(hw
,
255 E1000_M88E1112_MAC_CTRL_1
,
260 data
= (data
& E1000_M88E1112_MAC_CTRL_1_MODE_MASK
) >>
261 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT
;
262 if (data
== E1000_M88E1112_AUTO_COPPER_SGMII
||
263 data
== E1000_M88E1112_AUTO_COPPER_BASEX
)
264 hw
->mac
.ops
.check_for_link
=
265 igb_check_for_link_media_swap
;
268 case IGP03E1000_E_PHY_ID
:
269 phy
->type
= e1000_phy_igp_3
;
270 phy
->ops
.get_phy_info
= igb_get_phy_info_igp
;
271 phy
->ops
.get_cable_length
= igb_get_cable_length_igp_2
;
272 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_igp
;
273 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82575
;
274 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state
;
276 case I82580_I_PHY_ID
:
278 phy
->type
= e1000_phy_82580
;
279 phy
->ops
.force_speed_duplex
=
280 igb_phy_force_speed_duplex_82580
;
281 phy
->ops
.get_cable_length
= igb_get_cable_length_82580
;
282 phy
->ops
.get_phy_info
= igb_get_phy_info_82580
;
283 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82580
;
284 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state_82580
;
287 phy
->type
= e1000_phy_i210
;
288 phy
->ops
.check_polarity
= igb_check_polarity_m88
;
289 phy
->ops
.get_phy_info
= igb_get_phy_info_m88
;
290 phy
->ops
.get_cable_length
= igb_get_cable_length_m88_gen2
;
291 phy
->ops
.set_d0_lplu_state
= igb_set_d0_lplu_state_82580
;
292 phy
->ops
.set_d3_lplu_state
= igb_set_d3_lplu_state_82580
;
293 phy
->ops
.force_speed_duplex
= igb_phy_force_speed_duplex_m88
;
296 ret_val
= -E1000_ERR_PHY
;
305 * igb_init_nvm_params_82575 - Init NVM func ptrs.
306 * @hw: pointer to the HW structure
308 static s32
igb_init_nvm_params_82575(struct e1000_hw
*hw
)
310 struct e1000_nvm_info
*nvm
= &hw
->nvm
;
311 u32 eecd
= rd32(E1000_EECD
);
314 size
= (u16
)((eecd
& E1000_EECD_SIZE_EX_MASK
) >>
315 E1000_EECD_SIZE_EX_SHIFT
);
317 /* Added to a constant, "size" becomes the left-shift value
318 * for setting word_size.
320 size
+= NVM_WORD_SIZE_BASE_SHIFT
;
322 /* Just in case size is out of range, cap it to the largest
323 * EEPROM size supported
328 nvm
->word_size
= 1 << size
;
329 nvm
->opcode_bits
= 8;
332 switch (nvm
->override
) {
333 case e1000_nvm_override_spi_large
:
335 nvm
->address_bits
= 16;
337 case e1000_nvm_override_spi_small
:
339 nvm
->address_bits
= 8;
342 nvm
->page_size
= eecd
& E1000_EECD_ADDR_BITS
? 32 : 8;
343 nvm
->address_bits
= eecd
& E1000_EECD_ADDR_BITS
?
347 if (nvm
->word_size
== (1 << 15))
348 nvm
->page_size
= 128;
350 nvm
->type
= e1000_nvm_eeprom_spi
;
352 /* NVM Function Pointers */
353 nvm
->ops
.acquire
= igb_acquire_nvm_82575
;
354 nvm
->ops
.release
= igb_release_nvm_82575
;
355 nvm
->ops
.write
= igb_write_nvm_spi
;
356 nvm
->ops
.validate
= igb_validate_nvm_checksum
;
357 nvm
->ops
.update
= igb_update_nvm_checksum
;
358 if (nvm
->word_size
< (1 << 15))
359 nvm
->ops
.read
= igb_read_nvm_eerd
;
361 nvm
->ops
.read
= igb_read_nvm_spi
;
363 /* override generic family function pointers for specific descendants */
364 switch (hw
->mac
.type
) {
366 nvm
->ops
.validate
= igb_validate_nvm_checksum_82580
;
367 nvm
->ops
.update
= igb_update_nvm_checksum_82580
;
371 nvm
->ops
.validate
= igb_validate_nvm_checksum_i350
;
372 nvm
->ops
.update
= igb_update_nvm_checksum_i350
;
382 * igb_init_mac_params_82575 - Init MAC func ptrs.
383 * @hw: pointer to the HW structure
385 static s32
igb_init_mac_params_82575(struct e1000_hw
*hw
)
387 struct e1000_mac_info
*mac
= &hw
->mac
;
388 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
390 /* Set mta register count */
391 mac
->mta_reg_count
= 128;
392 /* Set rar entry count */
395 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82576
;
398 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82580
;
402 mac
->rar_entry_count
= E1000_RAR_ENTRIES_I350
;
405 mac
->rar_entry_count
= E1000_RAR_ENTRIES_82575
;
409 if (mac
->type
>= e1000_82580
)
410 mac
->ops
.reset_hw
= igb_reset_hw_82580
;
412 mac
->ops
.reset_hw
= igb_reset_hw_82575
;
414 if (mac
->type
>= e1000_i210
) {
415 mac
->ops
.acquire_swfw_sync
= igb_acquire_swfw_sync_i210
;
416 mac
->ops
.release_swfw_sync
= igb_release_swfw_sync_i210
;
419 mac
->ops
.acquire_swfw_sync
= igb_acquire_swfw_sync_82575
;
420 mac
->ops
.release_swfw_sync
= igb_release_swfw_sync_82575
;
423 /* Set if part includes ASF firmware */
424 mac
->asf_firmware_present
= true;
425 /* Set if manageability features are enabled. */
426 mac
->arc_subsystem_valid
=
427 (rd32(E1000_FWSM
) & E1000_FWSM_MODE_MASK
)
429 /* enable EEE on i350 parts and later parts */
430 if (mac
->type
>= e1000_i350
)
431 dev_spec
->eee_disable
= false;
433 dev_spec
->eee_disable
= true;
434 /* Allow a single clear of the SW semaphore on I210 and newer */
435 if (mac
->type
>= e1000_i210
)
436 dev_spec
->clear_semaphore_once
= true;
437 /* physical interface link setup */
438 mac
->ops
.setup_physical_interface
=
439 (hw
->phy
.media_type
== e1000_media_type_copper
)
440 ? igb_setup_copper_link_82575
441 : igb_setup_serdes_link_82575
;
443 if (mac
->type
== e1000_82580
) {
444 switch (hw
->device_id
) {
445 /* feature not supported on these id's */
446 case E1000_DEV_ID_DH89XXCC_SGMII
:
447 case E1000_DEV_ID_DH89XXCC_SERDES
:
448 case E1000_DEV_ID_DH89XXCC_BACKPLANE
:
449 case E1000_DEV_ID_DH89XXCC_SFP
:
452 hw
->dev_spec
._82575
.mas_capable
= true;
460 * igb_set_sfp_media_type_82575 - derives SFP module media type.
461 * @hw: pointer to the HW structure
463 * The media type is chosen based on SFP module.
464 * compatibility flags retrieved from SFP ID EEPROM.
466 static s32
igb_set_sfp_media_type_82575(struct e1000_hw
*hw
)
468 s32 ret_val
= E1000_ERR_CONFIG
;
470 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
471 struct e1000_sfp_flags
*eth_flags
= &dev_spec
->eth_flags
;
472 u8 tranceiver_type
= 0;
475 /* Turn I2C interface ON and power on sfp cage */
476 ctrl_ext
= rd32(E1000_CTRL_EXT
);
477 ctrl_ext
&= ~E1000_CTRL_EXT_SDP3_DATA
;
478 wr32(E1000_CTRL_EXT
, ctrl_ext
| E1000_CTRL_I2C_ENA
);
482 /* Read SFP module data */
484 ret_val
= igb_read_sfp_data_byte(hw
,
485 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET
),
495 ret_val
= igb_read_sfp_data_byte(hw
,
496 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET
),
501 /* Check if there is some SFP module plugged and powered */
502 if ((tranceiver_type
== E1000_SFF_IDENTIFIER_SFP
) ||
503 (tranceiver_type
== E1000_SFF_IDENTIFIER_SFF
)) {
504 dev_spec
->module_plugged
= true;
505 if (eth_flags
->e1000_base_lx
|| eth_flags
->e1000_base_sx
) {
506 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
507 } else if (eth_flags
->e100_base_fx
) {
508 dev_spec
->sgmii_active
= true;
509 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
510 } else if (eth_flags
->e1000_base_t
) {
511 dev_spec
->sgmii_active
= true;
512 hw
->phy
.media_type
= e1000_media_type_copper
;
514 hw
->phy
.media_type
= e1000_media_type_unknown
;
515 hw_dbg("PHY module has not been recognized\n");
519 hw
->phy
.media_type
= e1000_media_type_unknown
;
523 /* Restore I2C interface setting */
524 wr32(E1000_CTRL_EXT
, ctrl_ext
);
528 static s32
igb_get_invariants_82575(struct e1000_hw
*hw
)
530 struct e1000_mac_info
*mac
= &hw
->mac
;
531 struct e1000_dev_spec_82575
* dev_spec
= &hw
->dev_spec
._82575
;
536 switch (hw
->device_id
) {
537 case E1000_DEV_ID_82575EB_COPPER
:
538 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
539 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
540 mac
->type
= e1000_82575
;
542 case E1000_DEV_ID_82576
:
543 case E1000_DEV_ID_82576_NS
:
544 case E1000_DEV_ID_82576_NS_SERDES
:
545 case E1000_DEV_ID_82576_FIBER
:
546 case E1000_DEV_ID_82576_SERDES
:
547 case E1000_DEV_ID_82576_QUAD_COPPER
:
548 case E1000_DEV_ID_82576_QUAD_COPPER_ET2
:
549 case E1000_DEV_ID_82576_SERDES_QUAD
:
550 mac
->type
= e1000_82576
;
552 case E1000_DEV_ID_82580_COPPER
:
553 case E1000_DEV_ID_82580_FIBER
:
554 case E1000_DEV_ID_82580_QUAD_FIBER
:
555 case E1000_DEV_ID_82580_SERDES
:
556 case E1000_DEV_ID_82580_SGMII
:
557 case E1000_DEV_ID_82580_COPPER_DUAL
:
558 case E1000_DEV_ID_DH89XXCC_SGMII
:
559 case E1000_DEV_ID_DH89XXCC_SERDES
:
560 case E1000_DEV_ID_DH89XXCC_BACKPLANE
:
561 case E1000_DEV_ID_DH89XXCC_SFP
:
562 mac
->type
= e1000_82580
;
564 case E1000_DEV_ID_I350_COPPER
:
565 case E1000_DEV_ID_I350_FIBER
:
566 case E1000_DEV_ID_I350_SERDES
:
567 case E1000_DEV_ID_I350_SGMII
:
568 mac
->type
= e1000_i350
;
570 case E1000_DEV_ID_I210_COPPER
:
571 case E1000_DEV_ID_I210_FIBER
:
572 case E1000_DEV_ID_I210_SERDES
:
573 case E1000_DEV_ID_I210_SGMII
:
574 case E1000_DEV_ID_I210_COPPER_FLASHLESS
:
575 case E1000_DEV_ID_I210_SERDES_FLASHLESS
:
576 mac
->type
= e1000_i210
;
578 case E1000_DEV_ID_I211_COPPER
:
579 mac
->type
= e1000_i211
;
581 case E1000_DEV_ID_I354_BACKPLANE_1GBPS
:
582 case E1000_DEV_ID_I354_SGMII
:
583 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS
:
584 mac
->type
= e1000_i354
;
587 return -E1000_ERR_MAC_INIT
;
592 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
593 * based on the EEPROM. We cannot rely upon device ID. There
594 * is no distinguishable difference between fiber and internal
595 * SerDes mode on the 82575. There can be an external PHY attached
596 * on the SGMII interface. For this, we'll set sgmii_active to true.
598 hw
->phy
.media_type
= e1000_media_type_copper
;
599 dev_spec
->sgmii_active
= false;
600 dev_spec
->module_plugged
= false;
602 ctrl_ext
= rd32(E1000_CTRL_EXT
);
604 link_mode
= ctrl_ext
& E1000_CTRL_EXT_LINK_MODE_MASK
;
606 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX
:
607 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
609 case E1000_CTRL_EXT_LINK_MODE_SGMII
:
610 /* Get phy control interface type set (MDIO vs. I2C)*/
611 if (igb_sgmii_uses_mdio_82575(hw
)) {
612 hw
->phy
.media_type
= e1000_media_type_copper
;
613 dev_spec
->sgmii_active
= true;
616 /* fall through for I2C based SGMII */
617 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
:
618 /* read media type from SFP EEPROM */
619 ret_val
= igb_set_sfp_media_type_82575(hw
);
620 if ((ret_val
!= 0) ||
621 (hw
->phy
.media_type
== e1000_media_type_unknown
)) {
622 /* If media type was not identified then return media
623 * type defined by the CTRL_EXT settings.
625 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
627 if (link_mode
== E1000_CTRL_EXT_LINK_MODE_SGMII
) {
628 hw
->phy
.media_type
= e1000_media_type_copper
;
629 dev_spec
->sgmii_active
= true;
635 /* do not change link mode for 100BaseFX */
636 if (dev_spec
->eth_flags
.e100_base_fx
)
639 /* change current link mode setting */
640 ctrl_ext
&= ~E1000_CTRL_EXT_LINK_MODE_MASK
;
642 if (hw
->phy
.media_type
== e1000_media_type_copper
)
643 ctrl_ext
|= E1000_CTRL_EXT_LINK_MODE_SGMII
;
645 ctrl_ext
|= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
647 wr32(E1000_CTRL_EXT
, ctrl_ext
);
654 /* mac initialization and operations */
655 ret_val
= igb_init_mac_params_82575(hw
);
659 /* NVM initialization */
660 ret_val
= igb_init_nvm_params_82575(hw
);
661 switch (hw
->mac
.type
) {
664 ret_val
= igb_init_nvm_params_i210(hw
);
673 /* if part supports SR-IOV then initialize mailbox parameters */
677 igb_init_mbx_params_pf(hw
);
683 /* setup PHY parameters */
684 ret_val
= igb_init_phy_params_82575(hw
);
691 * igb_acquire_phy_82575 - Acquire rights to access PHY
692 * @hw: pointer to the HW structure
694 * Acquire access rights to the correct PHY. This is a
695 * function pointer entry point called by the api module.
697 static s32
igb_acquire_phy_82575(struct e1000_hw
*hw
)
699 u16 mask
= E1000_SWFW_PHY0_SM
;
701 if (hw
->bus
.func
== E1000_FUNC_1
)
702 mask
= E1000_SWFW_PHY1_SM
;
703 else if (hw
->bus
.func
== E1000_FUNC_2
)
704 mask
= E1000_SWFW_PHY2_SM
;
705 else if (hw
->bus
.func
== E1000_FUNC_3
)
706 mask
= E1000_SWFW_PHY3_SM
;
708 return hw
->mac
.ops
.acquire_swfw_sync(hw
, mask
);
712 * igb_release_phy_82575 - Release rights to access PHY
713 * @hw: pointer to the HW structure
715 * A wrapper to release access rights to the correct PHY. This is a
716 * function pointer entry point called by the api module.
718 static void igb_release_phy_82575(struct e1000_hw
*hw
)
720 u16 mask
= E1000_SWFW_PHY0_SM
;
722 if (hw
->bus
.func
== E1000_FUNC_1
)
723 mask
= E1000_SWFW_PHY1_SM
;
724 else if (hw
->bus
.func
== E1000_FUNC_2
)
725 mask
= E1000_SWFW_PHY2_SM
;
726 else if (hw
->bus
.func
== E1000_FUNC_3
)
727 mask
= E1000_SWFW_PHY3_SM
;
729 hw
->mac
.ops
.release_swfw_sync(hw
, mask
);
733 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
734 * @hw: pointer to the HW structure
735 * @offset: register offset to be read
736 * @data: pointer to the read data
738 * Reads the PHY register at offset using the serial gigabit media independent
739 * interface and stores the retrieved information in data.
741 static s32
igb_read_phy_reg_sgmii_82575(struct e1000_hw
*hw
, u32 offset
,
744 s32 ret_val
= -E1000_ERR_PARAM
;
746 if (offset
> E1000_MAX_SGMII_PHY_REG_ADDR
) {
747 hw_dbg("PHY Address %u is out of range\n", offset
);
751 ret_val
= hw
->phy
.ops
.acquire(hw
);
755 ret_val
= igb_read_phy_reg_i2c(hw
, offset
, data
);
757 hw
->phy
.ops
.release(hw
);
764 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
765 * @hw: pointer to the HW structure
766 * @offset: register offset to write to
767 * @data: data to write at register offset
769 * Writes the data to PHY register at the offset using the serial gigabit
770 * media independent interface.
772 static s32
igb_write_phy_reg_sgmii_82575(struct e1000_hw
*hw
, u32 offset
,
775 s32 ret_val
= -E1000_ERR_PARAM
;
778 if (offset
> E1000_MAX_SGMII_PHY_REG_ADDR
) {
779 hw_dbg("PHY Address %d is out of range\n", offset
);
783 ret_val
= hw
->phy
.ops
.acquire(hw
);
787 ret_val
= igb_write_phy_reg_i2c(hw
, offset
, data
);
789 hw
->phy
.ops
.release(hw
);
796 * igb_get_phy_id_82575 - Retrieve PHY addr and id
797 * @hw: pointer to the HW structure
799 * Retrieves the PHY address and ID for both PHY's which do and do not use
802 static s32
igb_get_phy_id_82575(struct e1000_hw
*hw
)
804 struct e1000_phy_info
*phy
= &hw
->phy
;
810 /* Extra read required for some PHY's on i354 */
811 if (hw
->mac
.type
== e1000_i354
)
814 /* For SGMII PHYs, we try the list of possible addresses until
815 * we find one that works. For non-SGMII PHYs
816 * (e.g. integrated copper PHYs), an address of 1 should
817 * work. The result of this function should mean phy->phy_addr
818 * and phy->id are set correctly.
820 if (!(igb_sgmii_active_82575(hw
))) {
822 ret_val
= igb_get_phy_id(hw
);
826 if (igb_sgmii_uses_mdio_82575(hw
)) {
827 switch (hw
->mac
.type
) {
830 mdic
= rd32(E1000_MDIC
);
831 mdic
&= E1000_MDIC_PHY_MASK
;
832 phy
->addr
= mdic
>> E1000_MDIC_PHY_SHIFT
;
839 mdic
= rd32(E1000_MDICNFG
);
840 mdic
&= E1000_MDICNFG_PHY_MASK
;
841 phy
->addr
= mdic
>> E1000_MDICNFG_PHY_SHIFT
;
844 ret_val
= -E1000_ERR_PHY
;
848 ret_val
= igb_get_phy_id(hw
);
852 /* Power on sgmii phy if it is disabled */
853 ctrl_ext
= rd32(E1000_CTRL_EXT
);
854 wr32(E1000_CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_SDP3_DATA
);
858 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
859 * Therefore, we need to test 1-7
861 for (phy
->addr
= 1; phy
->addr
< 8; phy
->addr
++) {
862 ret_val
= igb_read_phy_reg_sgmii_82575(hw
, PHY_ID1
, &phy_id
);
864 hw_dbg("Vendor ID 0x%08X read at address %u\n",
866 /* At the time of this writing, The M88 part is
867 * the only supported SGMII PHY product.
869 if (phy_id
== M88_VENDOR
)
872 hw_dbg("PHY address %u was unreadable\n", phy
->addr
);
876 /* A valid PHY type couldn't be found. */
877 if (phy
->addr
== 8) {
879 ret_val
= -E1000_ERR_PHY
;
882 ret_val
= igb_get_phy_id(hw
);
885 /* restore previous sfp cage power state */
886 wr32(E1000_CTRL_EXT
, ctrl_ext
);
893 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
894 * @hw: pointer to the HW structure
896 * Resets the PHY using the serial gigabit media independent interface.
898 static s32
igb_phy_hw_reset_sgmii_82575(struct e1000_hw
*hw
)
902 /* This isn't a true "hard" reset, but is the only reset
903 * available to us at this time.
906 hw_dbg("Soft resetting SGMII attached PHY...\n");
908 /* SFP documentation requires the following to configure the SPF module
909 * to work on SGMII. No further documentation is given.
911 ret_val
= hw
->phy
.ops
.write_reg(hw
, 0x1B, 0x8084);
915 ret_val
= igb_phy_sw_reset(hw
);
922 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
923 * @hw: pointer to the HW structure
924 * @active: true to enable LPLU, false to disable
926 * Sets the LPLU D0 state according to the active flag. When
927 * activating LPLU this function also disables smart speed
928 * and vice versa. LPLU will not be activated unless the
929 * device autonegotiation advertisement meets standards of
930 * either 10 or 10/100 or 10/100/1000 at all duplexes.
931 * This is a function pointer entry point only called by
932 * PHY setup routines.
934 static s32
igb_set_d0_lplu_state_82575(struct e1000_hw
*hw
, bool active
)
936 struct e1000_phy_info
*phy
= &hw
->phy
;
940 ret_val
= phy
->ops
.read_reg(hw
, IGP02E1000_PHY_POWER_MGMT
, &data
);
945 data
|= IGP02E1000_PM_D0_LPLU
;
946 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
951 /* When LPLU is enabled, we should disable SmartSpeed */
952 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
954 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
955 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
960 data
&= ~IGP02E1000_PM_D0_LPLU
;
961 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
963 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
964 * during Dx states where the power conservation is most
965 * important. During driver activity we should enable
966 * SmartSpeed, so performance is maintained.
968 if (phy
->smart_speed
== e1000_smart_speed_on
) {
969 ret_val
= phy
->ops
.read_reg(hw
,
970 IGP01E1000_PHY_PORT_CONFIG
, &data
);
974 data
|= IGP01E1000_PSCFR_SMART_SPEED
;
975 ret_val
= phy
->ops
.write_reg(hw
,
976 IGP01E1000_PHY_PORT_CONFIG
, data
);
979 } else if (phy
->smart_speed
== e1000_smart_speed_off
) {
980 ret_val
= phy
->ops
.read_reg(hw
,
981 IGP01E1000_PHY_PORT_CONFIG
, &data
);
985 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
986 ret_val
= phy
->ops
.write_reg(hw
,
987 IGP01E1000_PHY_PORT_CONFIG
, data
);
998 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
999 * @hw: pointer to the HW structure
1000 * @active: true to enable LPLU, false to disable
1002 * Sets the LPLU D0 state according to the active flag. When
1003 * activating LPLU this function also disables smart speed
1004 * and vice versa. LPLU will not be activated unless the
1005 * device autonegotiation advertisement meets standards of
1006 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1007 * This is a function pointer entry point only called by
1008 * PHY setup routines.
1010 static s32
igb_set_d0_lplu_state_82580(struct e1000_hw
*hw
, bool active
)
1012 struct e1000_phy_info
*phy
= &hw
->phy
;
1016 data
= rd32(E1000_82580_PHY_POWER_MGMT
);
1019 data
|= E1000_82580_PM_D0_LPLU
;
1021 /* When LPLU is enabled, we should disable SmartSpeed */
1022 data
&= ~E1000_82580_PM_SPD
;
1024 data
&= ~E1000_82580_PM_D0_LPLU
;
1026 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1027 * during Dx states where the power conservation is most
1028 * important. During driver activity we should enable
1029 * SmartSpeed, so performance is maintained.
1031 if (phy
->smart_speed
== e1000_smart_speed_on
)
1032 data
|= E1000_82580_PM_SPD
;
1033 else if (phy
->smart_speed
== e1000_smart_speed_off
)
1034 data
&= ~E1000_82580_PM_SPD
; }
1036 wr32(E1000_82580_PHY_POWER_MGMT
, data
);
1041 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1042 * @hw: pointer to the HW structure
1043 * @active: boolean used to enable/disable lplu
1045 * Success returns 0, Failure returns 1
1047 * The low power link up (lplu) state is set to the power management level D3
1048 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1049 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1050 * is used during Dx states where the power conservation is most important.
1051 * During driver activity, SmartSpeed should be enabled so performance is
1054 static s32
igb_set_d3_lplu_state_82580(struct e1000_hw
*hw
, bool active
)
1056 struct e1000_phy_info
*phy
= &hw
->phy
;
1060 data
= rd32(E1000_82580_PHY_POWER_MGMT
);
1063 data
&= ~E1000_82580_PM_D3_LPLU
;
1064 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1065 * during Dx states where the power conservation is most
1066 * important. During driver activity we should enable
1067 * SmartSpeed, so performance is maintained.
1069 if (phy
->smart_speed
== e1000_smart_speed_on
)
1070 data
|= E1000_82580_PM_SPD
;
1071 else if (phy
->smart_speed
== e1000_smart_speed_off
)
1072 data
&= ~E1000_82580_PM_SPD
;
1073 } else if ((phy
->autoneg_advertised
== E1000_ALL_SPEED_DUPLEX
) ||
1074 (phy
->autoneg_advertised
== E1000_ALL_NOT_GIG
) ||
1075 (phy
->autoneg_advertised
== E1000_ALL_10_SPEED
)) {
1076 data
|= E1000_82580_PM_D3_LPLU
;
1077 /* When LPLU is enabled, we should disable SmartSpeed */
1078 data
&= ~E1000_82580_PM_SPD
;
1081 wr32(E1000_82580_PHY_POWER_MGMT
, data
);
1086 * igb_acquire_nvm_82575 - Request for access to EEPROM
1087 * @hw: pointer to the HW structure
1089 * Acquire the necessary semaphores for exclusive access to the EEPROM.
1090 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1091 * Return successful if access grant bit set, else clear the request for
1092 * EEPROM access and return -E1000_ERR_NVM (-1).
1094 static s32
igb_acquire_nvm_82575(struct e1000_hw
*hw
)
1098 ret_val
= hw
->mac
.ops
.acquire_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1102 ret_val
= igb_acquire_nvm(hw
);
1105 hw
->mac
.ops
.release_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1112 * igb_release_nvm_82575 - Release exclusive access to EEPROM
1113 * @hw: pointer to the HW structure
1115 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1116 * then release the semaphores acquired.
1118 static void igb_release_nvm_82575(struct e1000_hw
*hw
)
1120 igb_release_nvm(hw
);
1121 hw
->mac
.ops
.release_swfw_sync(hw
, E1000_SWFW_EEP_SM
);
1125 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
1126 * @hw: pointer to the HW structure
1127 * @mask: specifies which semaphore to acquire
1129 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1130 * will also specify which port we're acquiring the lock for.
1132 static s32
igb_acquire_swfw_sync_82575(struct e1000_hw
*hw
, u16 mask
)
1136 u32 fwmask
= mask
<< 16;
1138 s32 i
= 0, timeout
= 200; /* FIXME: find real value to use here */
1140 while (i
< timeout
) {
1141 if (igb_get_hw_semaphore(hw
)) {
1142 ret_val
= -E1000_ERR_SWFW_SYNC
;
1146 swfw_sync
= rd32(E1000_SW_FW_SYNC
);
1147 if (!(swfw_sync
& (fwmask
| swmask
)))
1150 /* Firmware currently using resource (fwmask)
1151 * or other software thread using resource (swmask)
1153 igb_put_hw_semaphore(hw
);
1159 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
1160 ret_val
= -E1000_ERR_SWFW_SYNC
;
1164 swfw_sync
|= swmask
;
1165 wr32(E1000_SW_FW_SYNC
, swfw_sync
);
1167 igb_put_hw_semaphore(hw
);
1174 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
1175 * @hw: pointer to the HW structure
1176 * @mask: specifies which semaphore to acquire
1178 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1179 * will also specify which port we're releasing the lock for.
1181 static void igb_release_swfw_sync_82575(struct e1000_hw
*hw
, u16 mask
)
1185 while (igb_get_hw_semaphore(hw
) != 0);
1188 swfw_sync
= rd32(E1000_SW_FW_SYNC
);
1190 wr32(E1000_SW_FW_SYNC
, swfw_sync
);
1192 igb_put_hw_semaphore(hw
);
1196 * igb_get_cfg_done_82575 - Read config done bit
1197 * @hw: pointer to the HW structure
1199 * Read the management control register for the config done bit for
1200 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1201 * to read the config done bit, so an error is *ONLY* logged and returns
1202 * 0. If we were to return with error, EEPROM-less silicon
1203 * would not be able to be reset or change link.
1205 static s32
igb_get_cfg_done_82575(struct e1000_hw
*hw
)
1207 s32 timeout
= PHY_CFG_TIMEOUT
;
1209 u32 mask
= E1000_NVM_CFG_DONE_PORT_0
;
1211 if (hw
->bus
.func
== 1)
1212 mask
= E1000_NVM_CFG_DONE_PORT_1
;
1213 else if (hw
->bus
.func
== E1000_FUNC_2
)
1214 mask
= E1000_NVM_CFG_DONE_PORT_2
;
1215 else if (hw
->bus
.func
== E1000_FUNC_3
)
1216 mask
= E1000_NVM_CFG_DONE_PORT_3
;
1219 if (rd32(E1000_EEMNGCTL
) & mask
)
1225 hw_dbg("MNG configuration cycle has not completed.\n");
1227 /* If EEPROM is not marked present, init the PHY manually */
1228 if (((rd32(E1000_EECD
) & E1000_EECD_PRES
) == 0) &&
1229 (hw
->phy
.type
== e1000_phy_igp_3
))
1230 igb_phy_init_script_igp3(hw
);
1236 * igb_get_link_up_info_82575 - Get link speed/duplex info
1237 * @hw: pointer to the HW structure
1238 * @speed: stores the current speed
1239 * @duplex: stores the current duplex
1241 * This is a wrapper function, if using the serial gigabit media independent
1242 * interface, use PCS to retrieve the link speed and duplex information.
1243 * Otherwise, use the generic function to get the link speed and duplex info.
1245 static s32
igb_get_link_up_info_82575(struct e1000_hw
*hw
, u16
*speed
,
1250 if (hw
->phy
.media_type
!= e1000_media_type_copper
)
1251 ret_val
= igb_get_pcs_speed_and_duplex_82575(hw
, speed
,
1254 ret_val
= igb_get_speed_and_duplex_copper(hw
, speed
,
1261 * igb_check_for_link_82575 - Check for link
1262 * @hw: pointer to the HW structure
1264 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1265 * use the generic interface for determining link.
1267 static s32
igb_check_for_link_82575(struct e1000_hw
*hw
)
1272 if (hw
->phy
.media_type
!= e1000_media_type_copper
) {
1273 ret_val
= igb_get_pcs_speed_and_duplex_82575(hw
, &speed
,
1275 /* Use this flag to determine if link needs to be checked or
1276 * not. If we have link clear the flag so that we do not
1277 * continue to check for link.
1279 hw
->mac
.get_link_status
= !hw
->mac
.serdes_has_link
;
1281 /* Configure Flow Control now that Auto-Neg has completed.
1282 * First, we need to restore the desired flow control
1283 * settings because we may have had to re-autoneg with a
1284 * different link partner.
1286 ret_val
= igb_config_fc_after_link_up(hw
);
1288 hw_dbg("Error configuring flow control\n");
1290 ret_val
= igb_check_for_copper_link(hw
);
1297 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1298 * @hw: pointer to the HW structure
1300 void igb_power_up_serdes_link_82575(struct e1000_hw
*hw
)
1305 if ((hw
->phy
.media_type
!= e1000_media_type_internal_serdes
) &&
1306 !igb_sgmii_active_82575(hw
))
1309 /* Enable PCS to turn on link */
1310 reg
= rd32(E1000_PCS_CFG0
);
1311 reg
|= E1000_PCS_CFG_PCS_EN
;
1312 wr32(E1000_PCS_CFG0
, reg
);
1314 /* Power up the laser */
1315 reg
= rd32(E1000_CTRL_EXT
);
1316 reg
&= ~E1000_CTRL_EXT_SDP3_DATA
;
1317 wr32(E1000_CTRL_EXT
, reg
);
1319 /* flush the write to verify completion */
1325 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
1326 * @hw: pointer to the HW structure
1327 * @speed: stores the current speed
1328 * @duplex: stores the current duplex
1330 * Using the physical coding sub-layer (PCS), retrieve the current speed and
1331 * duplex, then store the values in the pointers provided.
1333 static s32
igb_get_pcs_speed_and_duplex_82575(struct e1000_hw
*hw
, u16
*speed
,
1336 struct e1000_mac_info
*mac
= &hw
->mac
;
1339 /* Set up defaults for the return values of this function */
1340 mac
->serdes_has_link
= false;
1344 /* Read the PCS Status register for link state. For non-copper mode,
1345 * the status register is not accurate. The PCS status register is
1348 pcs
= rd32(E1000_PCS_LSTAT
);
1350 /* The link up bit determines when link is up on autoneg. The sync ok
1351 * gets set once both sides sync up and agree upon link. Stable link
1352 * can be determined by checking for both link up and link sync ok
1354 if ((pcs
& E1000_PCS_LSTS_LINK_OK
) && (pcs
& E1000_PCS_LSTS_SYNK_OK
)) {
1355 mac
->serdes_has_link
= true;
1357 /* Detect and store PCS speed */
1358 if (pcs
& E1000_PCS_LSTS_SPEED_1000
)
1359 *speed
= SPEED_1000
;
1360 else if (pcs
& E1000_PCS_LSTS_SPEED_100
)
1365 /* Detect and store PCS duplex */
1366 if (pcs
& E1000_PCS_LSTS_DUPLEX_FULL
)
1367 *duplex
= FULL_DUPLEX
;
1369 *duplex
= HALF_DUPLEX
;
1371 /* Check if it is an I354 2.5Gb backplane connection. */
1372 if (mac
->type
== e1000_i354
) {
1373 status
= rd32(E1000_STATUS
);
1374 if ((status
& E1000_STATUS_2P5_SKU
) &&
1375 !(status
& E1000_STATUS_2P5_SKU_OVER
)) {
1376 *speed
= SPEED_2500
;
1377 *duplex
= FULL_DUPLEX
;
1378 hw_dbg("2500 Mbs, ");
1379 hw_dbg("Full Duplex\n");
1389 * igb_shutdown_serdes_link_82575 - Remove link during power down
1390 * @hw: pointer to the HW structure
1392 * In the case of fiber serdes, shut down optics and PCS on driver unload
1393 * when management pass thru is not enabled.
1395 void igb_shutdown_serdes_link_82575(struct e1000_hw
*hw
)
1399 if (hw
->phy
.media_type
!= e1000_media_type_internal_serdes
&&
1400 igb_sgmii_active_82575(hw
))
1403 if (!igb_enable_mng_pass_thru(hw
)) {
1404 /* Disable PCS to turn off link */
1405 reg
= rd32(E1000_PCS_CFG0
);
1406 reg
&= ~E1000_PCS_CFG_PCS_EN
;
1407 wr32(E1000_PCS_CFG0
, reg
);
1409 /* shutdown the laser */
1410 reg
= rd32(E1000_CTRL_EXT
);
1411 reg
|= E1000_CTRL_EXT_SDP3_DATA
;
1412 wr32(E1000_CTRL_EXT
, reg
);
1414 /* flush the write to verify completion */
1421 * igb_reset_hw_82575 - Reset hardware
1422 * @hw: pointer to the HW structure
1424 * This resets the hardware into a known state. This is a
1425 * function pointer entry point called by the api module.
1427 static s32
igb_reset_hw_82575(struct e1000_hw
*hw
)
1432 /* Prevent the PCI-E bus from sticking if there is no TLP connection
1433 * on the last TLP read/write transaction when MAC is reset.
1435 ret_val
= igb_disable_pcie_master(hw
);
1437 hw_dbg("PCI-E Master disable polling has failed.\n");
1439 /* set the completion timeout for interface */
1440 ret_val
= igb_set_pcie_completion_timeout(hw
);
1442 hw_dbg("PCI-E Set completion timeout has failed.\n");
1445 hw_dbg("Masking off all interrupts\n");
1446 wr32(E1000_IMC
, 0xffffffff);
1448 wr32(E1000_RCTL
, 0);
1449 wr32(E1000_TCTL
, E1000_TCTL_PSP
);
1454 ctrl
= rd32(E1000_CTRL
);
1456 hw_dbg("Issuing a global reset to MAC\n");
1457 wr32(E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
1459 ret_val
= igb_get_auto_rd_done(hw
);
1461 /* When auto config read does not complete, do not
1462 * return with an error. This can happen in situations
1463 * where there is no eeprom and prevents getting link.
1465 hw_dbg("Auto Read Done did not complete\n");
1468 /* If EEPROM is not present, run manual init scripts */
1469 if ((rd32(E1000_EECD
) & E1000_EECD_PRES
) == 0)
1470 igb_reset_init_script_82575(hw
);
1472 /* Clear any pending interrupt events. */
1473 wr32(E1000_IMC
, 0xffffffff);
1476 /* Install any alternate MAC address into RAR0 */
1477 ret_val
= igb_check_alt_mac_addr(hw
);
1483 * igb_init_hw_82575 - Initialize hardware
1484 * @hw: pointer to the HW structure
1486 * This inits the hardware readying it for operation.
1488 static s32
igb_init_hw_82575(struct e1000_hw
*hw
)
1490 struct e1000_mac_info
*mac
= &hw
->mac
;
1492 u16 i
, rar_count
= mac
->rar_entry_count
;
1494 /* Initialize identification LED */
1495 ret_val
= igb_id_led_init(hw
);
1497 hw_dbg("Error initializing identification LED\n");
1498 /* This is not fatal and we should not stop init due to this */
1501 /* Disabling VLAN filtering */
1502 hw_dbg("Initializing the IEEE VLAN\n");
1503 if ((hw
->mac
.type
== e1000_i350
) || (hw
->mac
.type
== e1000_i354
))
1504 igb_clear_vfta_i350(hw
);
1508 /* Setup the receive address */
1509 igb_init_rx_addrs(hw
, rar_count
);
1511 /* Zero out the Multicast HASH table */
1512 hw_dbg("Zeroing the MTA\n");
1513 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
1514 array_wr32(E1000_MTA
, i
, 0);
1516 /* Zero out the Unicast HASH table */
1517 hw_dbg("Zeroing the UTA\n");
1518 for (i
= 0; i
< mac
->uta_reg_count
; i
++)
1519 array_wr32(E1000_UTA
, i
, 0);
1521 /* Setup link and flow control */
1522 ret_val
= igb_setup_link(hw
);
1524 /* Clear all of the statistics registers (clear on read). It is
1525 * important that we do this after we have tried to establish link
1526 * because the symbol error count will increment wildly if there
1529 igb_clear_hw_cntrs_82575(hw
);
1534 * igb_setup_copper_link_82575 - Configure copper link settings
1535 * @hw: pointer to the HW structure
1537 * Configures the link for auto-neg or forced speed and duplex. Then we check
1538 * for link, once link is established calls to configure collision distance
1539 * and flow control are called.
1541 static s32
igb_setup_copper_link_82575(struct e1000_hw
*hw
)
1547 ctrl
= rd32(E1000_CTRL
);
1548 ctrl
|= E1000_CTRL_SLU
;
1549 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1550 wr32(E1000_CTRL
, ctrl
);
1552 /* Clear Go Link Disconnect bit on supported devices */
1553 switch (hw
->mac
.type
) {
1558 phpm_reg
= rd32(E1000_82580_PHY_POWER_MGMT
);
1559 phpm_reg
&= ~E1000_82580_PM_GO_LINKD
;
1560 wr32(E1000_82580_PHY_POWER_MGMT
, phpm_reg
);
1566 ret_val
= igb_setup_serdes_link_82575(hw
);
1570 if (igb_sgmii_active_82575(hw
) && !hw
->phy
.reset_disable
) {
1571 /* allow time for SFP cage time to power up phy */
1574 ret_val
= hw
->phy
.ops
.reset(hw
);
1576 hw_dbg("Error resetting the PHY.\n");
1580 switch (hw
->phy
.type
) {
1581 case e1000_phy_i210
:
1583 switch (hw
->phy
.id
) {
1584 case I347AT4_E_PHY_ID
:
1585 case M88E1112_E_PHY_ID
:
1586 case M88E1543_E_PHY_ID
:
1588 ret_val
= igb_copper_link_setup_m88_gen2(hw
);
1591 ret_val
= igb_copper_link_setup_m88(hw
);
1595 case e1000_phy_igp_3
:
1596 ret_val
= igb_copper_link_setup_igp(hw
);
1598 case e1000_phy_82580
:
1599 ret_val
= igb_copper_link_setup_82580(hw
);
1602 ret_val
= -E1000_ERR_PHY
;
1609 ret_val
= igb_setup_copper_link(hw
);
1615 * igb_setup_serdes_link_82575 - Setup link for serdes
1616 * @hw: pointer to the HW structure
1618 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1619 * used on copper connections where the serialized gigabit media independent
1620 * interface (sgmii), or serdes fiber is being used. Configures the link
1621 * for auto-negotiation or forces speed/duplex.
1623 static s32
igb_setup_serdes_link_82575(struct e1000_hw
*hw
)
1625 u32 ctrl_ext
, ctrl_reg
, reg
, anadv_reg
;
1627 s32 ret_val
= E1000_SUCCESS
;
1630 if ((hw
->phy
.media_type
!= e1000_media_type_internal_serdes
) &&
1631 !igb_sgmii_active_82575(hw
))
1635 /* On the 82575, SerDes loopback mode persists until it is
1636 * explicitly turned off or a power cycle is performed. A read to
1637 * the register does not indicate its status. Therefore, we ensure
1638 * loopback mode is disabled during initialization.
1640 wr32(E1000_SCTL
, E1000_SCTL_DISABLE_SERDES_LOOPBACK
);
1642 /* power on the sfp cage if present and turn on I2C */
1643 ctrl_ext
= rd32(E1000_CTRL_EXT
);
1644 ctrl_ext
&= ~E1000_CTRL_EXT_SDP3_DATA
;
1645 ctrl_ext
|= E1000_CTRL_I2C_ENA
;
1646 wr32(E1000_CTRL_EXT
, ctrl_ext
);
1648 ctrl_reg
= rd32(E1000_CTRL
);
1649 ctrl_reg
|= E1000_CTRL_SLU
;
1651 if (hw
->mac
.type
== e1000_82575
|| hw
->mac
.type
== e1000_82576
) {
1652 /* set both sw defined pins */
1653 ctrl_reg
|= E1000_CTRL_SWDPIN0
| E1000_CTRL_SWDPIN1
;
1655 /* Set switch control to serdes energy detect */
1656 reg
= rd32(E1000_CONNSW
);
1657 reg
|= E1000_CONNSW_ENRGSRC
;
1658 wr32(E1000_CONNSW
, reg
);
1661 reg
= rd32(E1000_PCS_LCTL
);
1663 /* default pcs_autoneg to the same setting as mac autoneg */
1664 pcs_autoneg
= hw
->mac
.autoneg
;
1666 switch (ctrl_ext
& E1000_CTRL_EXT_LINK_MODE_MASK
) {
1667 case E1000_CTRL_EXT_LINK_MODE_SGMII
:
1668 /* sgmii mode lets the phy handle forcing speed/duplex */
1670 /* autoneg time out should be disabled for SGMII mode */
1671 reg
&= ~(E1000_PCS_LCTL_AN_TIMEOUT
);
1673 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX
:
1674 /* disable PCS autoneg and support parallel detect only */
1675 pcs_autoneg
= false;
1677 if (hw
->mac
.type
== e1000_82575
||
1678 hw
->mac
.type
== e1000_82576
) {
1679 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPAT
, 1, &data
);
1681 printk(KERN_DEBUG
"NVM Read Error\n\n");
1685 if (data
& E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT
)
1686 pcs_autoneg
= false;
1689 /* non-SGMII modes only supports a speed of 1000/Full for the
1690 * link so it is best to just force the MAC and let the pcs
1691 * link either autoneg or be forced to 1000/Full
1693 ctrl_reg
|= E1000_CTRL_SPD_1000
| E1000_CTRL_FRCSPD
|
1694 E1000_CTRL_FD
| E1000_CTRL_FRCDPX
;
1696 /* set speed of 1000/Full if speed/duplex is forced */
1697 reg
|= E1000_PCS_LCTL_FSV_1000
| E1000_PCS_LCTL_FDV_FULL
;
1701 wr32(E1000_CTRL
, ctrl_reg
);
1703 /* New SerDes mode allows for forcing speed or autonegotiating speed
1704 * at 1gb. Autoneg should be default set by most drivers. This is the
1705 * mode that will be compatible with older link partners and switches.
1706 * However, both are supported by the hardware and some drivers/tools.
1708 reg
&= ~(E1000_PCS_LCTL_AN_ENABLE
| E1000_PCS_LCTL_FLV_LINK_UP
|
1709 E1000_PCS_LCTL_FSD
| E1000_PCS_LCTL_FORCE_LINK
);
1712 /* Set PCS register for autoneg */
1713 reg
|= E1000_PCS_LCTL_AN_ENABLE
| /* Enable Autoneg */
1714 E1000_PCS_LCTL_AN_RESTART
; /* Restart autoneg */
1716 /* Disable force flow control for autoneg */
1717 reg
&= ~E1000_PCS_LCTL_FORCE_FCTRL
;
1719 /* Configure flow control advertisement for autoneg */
1720 anadv_reg
= rd32(E1000_PCS_ANADV
);
1721 anadv_reg
&= ~(E1000_TXCW_ASM_DIR
| E1000_TXCW_PAUSE
);
1722 switch (hw
->fc
.requested_mode
) {
1724 case e1000_fc_rx_pause
:
1725 anadv_reg
|= E1000_TXCW_ASM_DIR
;
1726 anadv_reg
|= E1000_TXCW_PAUSE
;
1728 case e1000_fc_tx_pause
:
1729 anadv_reg
|= E1000_TXCW_ASM_DIR
;
1734 wr32(E1000_PCS_ANADV
, anadv_reg
);
1736 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg
);
1738 /* Set PCS register for forced link */
1739 reg
|= E1000_PCS_LCTL_FSD
; /* Force Speed */
1741 /* Force flow control for forced link */
1742 reg
|= E1000_PCS_LCTL_FORCE_FCTRL
;
1744 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg
);
1747 wr32(E1000_PCS_LCTL
, reg
);
1749 if (!pcs_autoneg
&& !igb_sgmii_active_82575(hw
))
1750 igb_force_mac_fc(hw
);
1756 * igb_sgmii_active_82575 - Return sgmii state
1757 * @hw: pointer to the HW structure
1759 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1760 * which can be enabled for use in the embedded applications. Simply
1761 * return the current state of the sgmii interface.
1763 static bool igb_sgmii_active_82575(struct e1000_hw
*hw
)
1765 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
1766 return dev_spec
->sgmii_active
;
1770 * igb_reset_init_script_82575 - Inits HW defaults after reset
1771 * @hw: pointer to the HW structure
1773 * Inits recommended HW defaults after a reset when there is no EEPROM
1774 * detected. This is only for the 82575.
1776 static s32
igb_reset_init_script_82575(struct e1000_hw
*hw
)
1778 if (hw
->mac
.type
== e1000_82575
) {
1779 hw_dbg("Running reset init script for 82575\n");
1780 /* SerDes configuration via SERDESCTRL */
1781 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x00, 0x0C);
1782 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x01, 0x78);
1783 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x1B, 0x23);
1784 igb_write_8bit_ctrl_reg(hw
, E1000_SCTL
, 0x23, 0x15);
1786 /* CCM configuration via CCMCTL register */
1787 igb_write_8bit_ctrl_reg(hw
, E1000_CCMCTL
, 0x14, 0x00);
1788 igb_write_8bit_ctrl_reg(hw
, E1000_CCMCTL
, 0x10, 0x00);
1790 /* PCIe lanes configuration */
1791 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x00, 0xEC);
1792 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x61, 0xDF);
1793 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x34, 0x05);
1794 igb_write_8bit_ctrl_reg(hw
, E1000_GIOCTL
, 0x2F, 0x81);
1796 /* PCIe PLL Configuration */
1797 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x02, 0x47);
1798 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x14, 0x00);
1799 igb_write_8bit_ctrl_reg(hw
, E1000_SCCTL
, 0x10, 0x00);
1806 * igb_read_mac_addr_82575 - Read device MAC address
1807 * @hw: pointer to the HW structure
1809 static s32
igb_read_mac_addr_82575(struct e1000_hw
*hw
)
1813 /* If there's an alternate MAC address place it in RAR0
1814 * so that it will override the Si installed default perm
1817 ret_val
= igb_check_alt_mac_addr(hw
);
1821 ret_val
= igb_read_mac_addr(hw
);
1828 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1829 * @hw: pointer to the HW structure
1831 * In the case of a PHY power down to save power, or to turn off link during a
1832 * driver unload, or wake on lan is not enabled, remove the link.
1834 void igb_power_down_phy_copper_82575(struct e1000_hw
*hw
)
1836 /* If the management interface is not enabled, then power down */
1837 if (!(igb_enable_mng_pass_thru(hw
) || igb_check_reset_block(hw
)))
1838 igb_power_down_phy_copper(hw
);
1842 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
1843 * @hw: pointer to the HW structure
1845 * Clears the hardware counters by reading the counter registers.
1847 static void igb_clear_hw_cntrs_82575(struct e1000_hw
*hw
)
1849 igb_clear_hw_cntrs_base(hw
);
1855 rd32(E1000_PRC1023
);
1856 rd32(E1000_PRC1522
);
1861 rd32(E1000_PTC1023
);
1862 rd32(E1000_PTC1522
);
1864 rd32(E1000_ALGNERRC
);
1867 rd32(E1000_CEXTERR
);
1878 rd32(E1000_ICRXPTC
);
1879 rd32(E1000_ICRXATC
);
1880 rd32(E1000_ICTXPTC
);
1881 rd32(E1000_ICTXATC
);
1882 rd32(E1000_ICTXQEC
);
1883 rd32(E1000_ICTXQMTC
);
1884 rd32(E1000_ICRXDMTC
);
1891 rd32(E1000_HTCBDPC
);
1896 rd32(E1000_LENERRS
);
1898 /* This register should not be read in copper configurations */
1899 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
||
1900 igb_sgmii_active_82575(hw
))
1905 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1906 * @hw: pointer to the HW structure
1908 * After rx enable if managability is enabled then there is likely some
1909 * bad data at the start of the fifo and possibly in the DMA fifo. This
1910 * function clears the fifos and flushes any packets that came in as rx was
1913 void igb_rx_fifo_flush_82575(struct e1000_hw
*hw
)
1915 u32 rctl
, rlpml
, rxdctl
[4], rfctl
, temp_rctl
, rx_enabled
;
1918 if (hw
->mac
.type
!= e1000_82575
||
1919 !(rd32(E1000_MANC
) & E1000_MANC_RCV_TCO_EN
))
1922 /* Disable all RX queues */
1923 for (i
= 0; i
< 4; i
++) {
1924 rxdctl
[i
] = rd32(E1000_RXDCTL(i
));
1925 wr32(E1000_RXDCTL(i
),
1926 rxdctl
[i
] & ~E1000_RXDCTL_QUEUE_ENABLE
);
1928 /* Poll all queues to verify they have shut down */
1929 for (ms_wait
= 0; ms_wait
< 10; ms_wait
++) {
1932 for (i
= 0; i
< 4; i
++)
1933 rx_enabled
|= rd32(E1000_RXDCTL(i
));
1934 if (!(rx_enabled
& E1000_RXDCTL_QUEUE_ENABLE
))
1939 hw_dbg("Queue disable timed out after 10ms\n");
1941 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1942 * incoming packets are rejected. Set enable and wait 2ms so that
1943 * any packet that was coming in as RCTL.EN was set is flushed
1945 rfctl
= rd32(E1000_RFCTL
);
1946 wr32(E1000_RFCTL
, rfctl
& ~E1000_RFCTL_LEF
);
1948 rlpml
= rd32(E1000_RLPML
);
1949 wr32(E1000_RLPML
, 0);
1951 rctl
= rd32(E1000_RCTL
);
1952 temp_rctl
= rctl
& ~(E1000_RCTL_EN
| E1000_RCTL_SBP
);
1953 temp_rctl
|= E1000_RCTL_LPE
;
1955 wr32(E1000_RCTL
, temp_rctl
);
1956 wr32(E1000_RCTL
, temp_rctl
| E1000_RCTL_EN
);
1960 /* Enable RX queues that were previously enabled and restore our
1963 for (i
= 0; i
< 4; i
++)
1964 wr32(E1000_RXDCTL(i
), rxdctl
[i
]);
1965 wr32(E1000_RCTL
, rctl
);
1968 wr32(E1000_RLPML
, rlpml
);
1969 wr32(E1000_RFCTL
, rfctl
);
1971 /* Flush receive errors generated by workaround */
1978 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1979 * @hw: pointer to the HW structure
1981 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1982 * however the hardware default for these parts is 500us to 1ms which is less
1983 * than the 10ms recommended by the pci-e spec. To address this we need to
1984 * increase the value to either 10ms to 200ms for capability version 1 config,
1985 * or 16ms to 55ms for version 2.
1987 static s32
igb_set_pcie_completion_timeout(struct e1000_hw
*hw
)
1989 u32 gcr
= rd32(E1000_GCR
);
1993 /* only take action if timeout value is defaulted to 0 */
1994 if (gcr
& E1000_GCR_CMPL_TMOUT_MASK
)
1997 /* if capabilities version is type 1 we can write the
1998 * timeout of 10ms to 200ms through the GCR register
2000 if (!(gcr
& E1000_GCR_CAP_VER2
)) {
2001 gcr
|= E1000_GCR_CMPL_TMOUT_10ms
;
2005 /* for version 2 capabilities we need to write the config space
2006 * directly in order to set the completion timeout value for
2009 ret_val
= igb_read_pcie_cap_reg(hw
, PCIE_DEVICE_CONTROL2
,
2014 pcie_devctl2
|= PCIE_DEVICE_CONTROL2_16ms
;
2016 ret_val
= igb_write_pcie_cap_reg(hw
, PCIE_DEVICE_CONTROL2
,
2019 /* disable completion timeout resend */
2020 gcr
&= ~E1000_GCR_CMPL_TMOUT_RESEND
;
2022 wr32(E1000_GCR
, gcr
);
2027 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2028 * @hw: pointer to the hardware struct
2029 * @enable: state to enter, either enabled or disabled
2030 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2032 * enables/disables L2 switch anti-spoofing functionality.
2034 void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw
*hw
, bool enable
, int pf
)
2036 u32 reg_val
, reg_offset
;
2038 switch (hw
->mac
.type
) {
2040 reg_offset
= E1000_DTXSWC
;
2044 reg_offset
= E1000_TXSWC
;
2050 reg_val
= rd32(reg_offset
);
2052 reg_val
|= (E1000_DTXSWC_MAC_SPOOF_MASK
|
2053 E1000_DTXSWC_VLAN_SPOOF_MASK
);
2054 /* The PF can spoof - it has to in order to
2055 * support emulation mode NICs
2057 reg_val
^= (1 << pf
| 1 << (pf
+ MAX_NUM_VFS
));
2059 reg_val
&= ~(E1000_DTXSWC_MAC_SPOOF_MASK
|
2060 E1000_DTXSWC_VLAN_SPOOF_MASK
);
2062 wr32(reg_offset
, reg_val
);
2066 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2067 * @hw: pointer to the hardware struct
2068 * @enable: state to enter, either enabled or disabled
2070 * enables/disables L2 switch loopback functionality.
2072 void igb_vmdq_set_loopback_pf(struct e1000_hw
*hw
, bool enable
)
2076 switch (hw
->mac
.type
) {
2078 dtxswc
= rd32(E1000_DTXSWC
);
2080 dtxswc
|= E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2082 dtxswc
&= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2083 wr32(E1000_DTXSWC
, dtxswc
);
2087 dtxswc
= rd32(E1000_TXSWC
);
2089 dtxswc
|= E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2091 dtxswc
&= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN
;
2092 wr32(E1000_TXSWC
, dtxswc
);
2095 /* Currently no other hardware supports loopback */
2102 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2103 * @hw: pointer to the hardware struct
2104 * @enable: state to enter, either enabled or disabled
2106 * enables/disables replication of packets across multiple pools.
2108 void igb_vmdq_set_replication_pf(struct e1000_hw
*hw
, bool enable
)
2110 u32 vt_ctl
= rd32(E1000_VT_CTL
);
2113 vt_ctl
|= E1000_VT_CTL_VM_REPL_EN
;
2115 vt_ctl
&= ~E1000_VT_CTL_VM_REPL_EN
;
2117 wr32(E1000_VT_CTL
, vt_ctl
);
2121 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2122 * @hw: pointer to the HW structure
2123 * @offset: register offset to be read
2124 * @data: pointer to the read data
2126 * Reads the MDI control register in the PHY at offset and stores the
2127 * information read to data.
2129 static s32
igb_read_phy_reg_82580(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
2133 ret_val
= hw
->phy
.ops
.acquire(hw
);
2137 ret_val
= igb_read_phy_reg_mdic(hw
, offset
, data
);
2139 hw
->phy
.ops
.release(hw
);
2146 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2147 * @hw: pointer to the HW structure
2148 * @offset: register offset to write to
2149 * @data: data to write to register at offset
2151 * Writes data to MDI control register in the PHY at offset.
2153 static s32
igb_write_phy_reg_82580(struct e1000_hw
*hw
, u32 offset
, u16 data
)
2158 ret_val
= hw
->phy
.ops
.acquire(hw
);
2162 ret_val
= igb_write_phy_reg_mdic(hw
, offset
, data
);
2164 hw
->phy
.ops
.release(hw
);
2171 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2172 * @hw: pointer to the HW structure
2174 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2175 * the values found in the EEPROM. This addresses an issue in which these
2176 * bits are not restored from EEPROM after reset.
2178 static s32
igb_reset_mdicnfg_82580(struct e1000_hw
*hw
)
2184 if (hw
->mac
.type
!= e1000_82580
)
2186 if (!igb_sgmii_active_82575(hw
))
2189 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_A
+
2190 NVM_82580_LAN_FUNC_OFFSET(hw
->bus
.func
), 1,
2193 hw_dbg("NVM Read Error\n");
2197 mdicnfg
= rd32(E1000_MDICNFG
);
2198 if (nvm_data
& NVM_WORD24_EXT_MDIO
)
2199 mdicnfg
|= E1000_MDICNFG_EXT_MDIO
;
2200 if (nvm_data
& NVM_WORD24_COM_MDIO
)
2201 mdicnfg
|= E1000_MDICNFG_COM_MDIO
;
2202 wr32(E1000_MDICNFG
, mdicnfg
);
2208 * igb_reset_hw_82580 - Reset hardware
2209 * @hw: pointer to the HW structure
2211 * This resets function or entire device (all ports, etc.)
2214 static s32
igb_reset_hw_82580(struct e1000_hw
*hw
)
2217 /* BH SW mailbox bit in SW_FW_SYNC */
2218 u16 swmbsw_mask
= E1000_SW_SYNCH_MB
;
2220 bool global_device_reset
= hw
->dev_spec
._82575
.global_device_reset
;
2222 hw
->dev_spec
._82575
.global_device_reset
= false;
2224 /* due to hw errata, global device reset doesn't always
2227 if (hw
->mac
.type
== e1000_82580
)
2228 global_device_reset
= false;
2230 /* Get current control state. */
2231 ctrl
= rd32(E1000_CTRL
);
2233 /* Prevent the PCI-E bus from sticking if there is no TLP connection
2234 * on the last TLP read/write transaction when MAC is reset.
2236 ret_val
= igb_disable_pcie_master(hw
);
2238 hw_dbg("PCI-E Master disable polling has failed.\n");
2240 hw_dbg("Masking off all interrupts\n");
2241 wr32(E1000_IMC
, 0xffffffff);
2242 wr32(E1000_RCTL
, 0);
2243 wr32(E1000_TCTL
, E1000_TCTL_PSP
);
2248 /* Determine whether or not a global dev reset is requested */
2249 if (global_device_reset
&&
2250 hw
->mac
.ops
.acquire_swfw_sync(hw
, swmbsw_mask
))
2251 global_device_reset
= false;
2253 if (global_device_reset
&&
2254 !(rd32(E1000_STATUS
) & E1000_STAT_DEV_RST_SET
))
2255 ctrl
|= E1000_CTRL_DEV_RST
;
2257 ctrl
|= E1000_CTRL_RST
;
2259 wr32(E1000_CTRL
, ctrl
);
2262 /* Add delay to insure DEV_RST has time to complete */
2263 if (global_device_reset
)
2266 ret_val
= igb_get_auto_rd_done(hw
);
2268 /* When auto config read does not complete, do not
2269 * return with an error. This can happen in situations
2270 * where there is no eeprom and prevents getting link.
2272 hw_dbg("Auto Read Done did not complete\n");
2275 /* clear global device reset status bit */
2276 wr32(E1000_STATUS
, E1000_STAT_DEV_RST_SET
);
2278 /* Clear any pending interrupt events. */
2279 wr32(E1000_IMC
, 0xffffffff);
2282 ret_val
= igb_reset_mdicnfg_82580(hw
);
2284 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2286 /* Install any alternate MAC address into RAR0 */
2287 ret_val
= igb_check_alt_mac_addr(hw
);
2289 /* Release semaphore */
2290 if (global_device_reset
)
2291 hw
->mac
.ops
.release_swfw_sync(hw
, swmbsw_mask
);
2297 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2298 * @data: data received by reading RXPBS register
2300 * The 82580 uses a table based approach for packet buffer allocation sizes.
2301 * This function converts the retrieved value into the correct table value
2302 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2303 * 0x0 36 72 144 1 2 4 8 16
2304 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2306 u16
igb_rxpbs_adjust_82580(u32 data
)
2310 if (data
< E1000_82580_RXPBS_TABLE_SIZE
)
2311 ret_val
= e1000_82580_rxpbs_table
[data
];
2317 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2319 * @hw: pointer to the HW structure
2320 * @offset: offset in words of the checksum protected region
2322 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2323 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2325 static s32
igb_validate_nvm_checksum_with_offset(struct e1000_hw
*hw
,
2332 for (i
= offset
; i
< ((NVM_CHECKSUM_REG
+ offset
) + 1); i
++) {
2333 ret_val
= hw
->nvm
.ops
.read(hw
, i
, 1, &nvm_data
);
2335 hw_dbg("NVM Read Error\n");
2338 checksum
+= nvm_data
;
2341 if (checksum
!= (u16
) NVM_SUM
) {
2342 hw_dbg("NVM Checksum Invalid\n");
2343 ret_val
= -E1000_ERR_NVM
;
2352 * igb_update_nvm_checksum_with_offset - Update EEPROM
2354 * @hw: pointer to the HW structure
2355 * @offset: offset in words of the checksum protected region
2357 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2358 * up to the checksum. Then calculates the EEPROM checksum and writes the
2359 * value to the EEPROM.
2361 static s32
igb_update_nvm_checksum_with_offset(struct e1000_hw
*hw
, u16 offset
)
2367 for (i
= offset
; i
< (NVM_CHECKSUM_REG
+ offset
); i
++) {
2368 ret_val
= hw
->nvm
.ops
.read(hw
, i
, 1, &nvm_data
);
2370 hw_dbg("NVM Read Error while updating checksum.\n");
2373 checksum
+= nvm_data
;
2375 checksum
= (u16
) NVM_SUM
- checksum
;
2376 ret_val
= hw
->nvm
.ops
.write(hw
, (NVM_CHECKSUM_REG
+ offset
), 1,
2379 hw_dbg("NVM Write Error while updating checksum.\n");
2386 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2387 * @hw: pointer to the HW structure
2389 * Calculates the EEPROM section checksum by reading/adding each word of
2390 * the EEPROM and then verifies that the sum of the EEPROM is
2393 static s32
igb_validate_nvm_checksum_82580(struct e1000_hw
*hw
)
2396 u16 eeprom_regions_count
= 1;
2400 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPATIBILITY_REG_3
, 1, &nvm_data
);
2402 hw_dbg("NVM Read Error\n");
2406 if (nvm_data
& NVM_COMPATIBILITY_BIT_MASK
) {
2407 /* if checksums compatibility bit is set validate checksums
2410 eeprom_regions_count
= 4;
2413 for (j
= 0; j
< eeprom_regions_count
; j
++) {
2414 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2415 ret_val
= igb_validate_nvm_checksum_with_offset(hw
,
2426 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2427 * @hw: pointer to the HW structure
2429 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2430 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2431 * checksum and writes the value to the EEPROM.
2433 static s32
igb_update_nvm_checksum_82580(struct e1000_hw
*hw
)
2439 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_COMPATIBILITY_REG_3
, 1, &nvm_data
);
2441 hw_dbg("NVM Read Error while updating checksum"
2442 " compatibility bit.\n");
2446 if ((nvm_data
& NVM_COMPATIBILITY_BIT_MASK
) == 0) {
2447 /* set compatibility bit to validate checksums appropriately */
2448 nvm_data
= nvm_data
| NVM_COMPATIBILITY_BIT_MASK
;
2449 ret_val
= hw
->nvm
.ops
.write(hw
, NVM_COMPATIBILITY_REG_3
, 1,
2452 hw_dbg("NVM Write Error while updating checksum"
2453 " compatibility bit.\n");
2458 for (j
= 0; j
< 4; j
++) {
2459 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2460 ret_val
= igb_update_nvm_checksum_with_offset(hw
, nvm_offset
);
2470 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2471 * @hw: pointer to the HW structure
2473 * Calculates the EEPROM section checksum by reading/adding each word of
2474 * the EEPROM and then verifies that the sum of the EEPROM is
2477 static s32
igb_validate_nvm_checksum_i350(struct e1000_hw
*hw
)
2483 for (j
= 0; j
< 4; j
++) {
2484 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2485 ret_val
= igb_validate_nvm_checksum_with_offset(hw
,
2496 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2497 * @hw: pointer to the HW structure
2499 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2500 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2501 * checksum and writes the value to the EEPROM.
2503 static s32
igb_update_nvm_checksum_i350(struct e1000_hw
*hw
)
2509 for (j
= 0; j
< 4; j
++) {
2510 nvm_offset
= NVM_82580_LAN_FUNC_OFFSET(j
);
2511 ret_val
= igb_update_nvm_checksum_with_offset(hw
, nvm_offset
);
2521 * __igb_access_emi_reg - Read/write EMI register
2522 * @hw: pointer to the HW structure
2523 * @addr: EMI address to program
2524 * @data: pointer to value to read/write from/to the EMI address
2525 * @read: boolean flag to indicate read or write
2527 static s32
__igb_access_emi_reg(struct e1000_hw
*hw
, u16 address
,
2528 u16
*data
, bool read
)
2530 s32 ret_val
= E1000_SUCCESS
;
2532 ret_val
= hw
->phy
.ops
.write_reg(hw
, E1000_EMIADD
, address
);
2537 ret_val
= hw
->phy
.ops
.read_reg(hw
, E1000_EMIDATA
, data
);
2539 ret_val
= hw
->phy
.ops
.write_reg(hw
, E1000_EMIDATA
, *data
);
2545 * igb_read_emi_reg - Read Extended Management Interface register
2546 * @hw: pointer to the HW structure
2547 * @addr: EMI address to program
2548 * @data: value to be read from the EMI address
2550 s32
igb_read_emi_reg(struct e1000_hw
*hw
, u16 addr
, u16
*data
)
2552 return __igb_access_emi_reg(hw
, addr
, data
, true);
2556 * igb_set_eee_i350 - Enable/disable EEE support
2557 * @hw: pointer to the HW structure
2559 * Enable/disable EEE based on setting in dev_spec structure.
2562 s32
igb_set_eee_i350(struct e1000_hw
*hw
)
2567 if ((hw
->mac
.type
< e1000_i350
) ||
2568 (hw
->phy
.media_type
!= e1000_media_type_copper
))
2570 ipcnfg
= rd32(E1000_IPCNFG
);
2571 eeer
= rd32(E1000_EEER
);
2573 /* enable or disable per user setting */
2574 if (!(hw
->dev_spec
._82575
.eee_disable
)) {
2575 u32 eee_su
= rd32(E1000_EEE_SU
);
2577 ipcnfg
|= (E1000_IPCNFG_EEE_1G_AN
| E1000_IPCNFG_EEE_100M_AN
);
2578 eeer
|= (E1000_EEER_TX_LPI_EN
| E1000_EEER_RX_LPI_EN
|
2581 /* This bit should not be set in normal operation. */
2582 if (eee_su
& E1000_EEE_SU_LPI_CLK_STP
)
2583 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2586 ipcnfg
&= ~(E1000_IPCNFG_EEE_1G_AN
|
2587 E1000_IPCNFG_EEE_100M_AN
);
2588 eeer
&= ~(E1000_EEER_TX_LPI_EN
|
2589 E1000_EEER_RX_LPI_EN
|
2592 wr32(E1000_IPCNFG
, ipcnfg
);
2593 wr32(E1000_EEER
, eeer
);
2602 * igb_set_eee_i354 - Enable/disable EEE support
2603 * @hw: pointer to the HW structure
2605 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2608 s32
igb_set_eee_i354(struct e1000_hw
*hw
)
2610 struct e1000_phy_info
*phy
= &hw
->phy
;
2614 if ((hw
->phy
.media_type
!= e1000_media_type_copper
) ||
2615 (phy
->id
!= M88E1543_E_PHY_ID
))
2618 if (!hw
->dev_spec
._82575
.eee_disable
) {
2619 /* Switch to PHY page 18. */
2620 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_PAGE_ADDR
, 18);
2624 ret_val
= phy
->ops
.read_reg(hw
, E1000_M88E1543_EEE_CTRL_1
,
2629 phy_data
|= E1000_M88E1543_EEE_CTRL_1_MS
;
2630 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_EEE_CTRL_1
,
2635 /* Return the PHY to page 0. */
2636 ret_val
= phy
->ops
.write_reg(hw
, E1000_M88E1543_PAGE_ADDR
, 0);
2640 /* Turn on EEE advertisement. */
2641 ret_val
= igb_read_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2642 E1000_EEE_ADV_DEV_I354
,
2647 phy_data
|= E1000_EEE_ADV_100_SUPPORTED
|
2648 E1000_EEE_ADV_1000_SUPPORTED
;
2649 ret_val
= igb_write_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2650 E1000_EEE_ADV_DEV_I354
,
2653 /* Turn off EEE advertisement. */
2654 ret_val
= igb_read_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2655 E1000_EEE_ADV_DEV_I354
,
2660 phy_data
&= ~(E1000_EEE_ADV_100_SUPPORTED
|
2661 E1000_EEE_ADV_1000_SUPPORTED
);
2662 ret_val
= igb_write_xmdio_reg(hw
, E1000_EEE_ADV_ADDR_I354
,
2663 E1000_EEE_ADV_DEV_I354
,
2672 * igb_get_eee_status_i354 - Get EEE status
2673 * @hw: pointer to the HW structure
2674 * @status: EEE status
2676 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2679 s32
igb_get_eee_status_i354(struct e1000_hw
*hw
, bool *status
)
2681 struct e1000_phy_info
*phy
= &hw
->phy
;
2685 /* Check if EEE is supported on this device. */
2686 if ((hw
->phy
.media_type
!= e1000_media_type_copper
) ||
2687 (phy
->id
!= M88E1543_E_PHY_ID
))
2690 ret_val
= igb_read_xmdio_reg(hw
, E1000_PCS_STATUS_ADDR_I354
,
2691 E1000_PCS_STATUS_DEV_I354
,
2696 *status
= phy_data
& (E1000_PCS_STATUS_TX_LPI_RCVD
|
2697 E1000_PCS_STATUS_RX_LPI_RCVD
) ? true : false;
2703 static const u8 e1000_emc_temp_data
[4] = {
2704 E1000_EMC_INTERNAL_DATA
,
2705 E1000_EMC_DIODE1_DATA
,
2706 E1000_EMC_DIODE2_DATA
,
2707 E1000_EMC_DIODE3_DATA
2709 static const u8 e1000_emc_therm_limit
[4] = {
2710 E1000_EMC_INTERNAL_THERM_LIMIT
,
2711 E1000_EMC_DIODE1_THERM_LIMIT
,
2712 E1000_EMC_DIODE2_THERM_LIMIT
,
2713 E1000_EMC_DIODE3_THERM_LIMIT
2717 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
2718 * @hw: pointer to hardware structure
2720 * Updates the temperatures in mac.thermal_sensor_data
2722 static s32
igb_get_thermal_sensor_data_generic(struct e1000_hw
*hw
)
2724 s32 status
= E1000_SUCCESS
;
2732 struct e1000_thermal_sensor_data
*data
= &hw
->mac
.thermal_sensor_data
;
2734 if ((hw
->mac
.type
!= e1000_i350
) || (hw
->bus
.func
!= 0))
2735 return E1000_NOT_IMPLEMENTED
;
2737 data
->sensor
[0].temp
= (rd32(E1000_THMJT
) & 0xFF);
2739 /* Return the internal sensor only if ETS is unsupported */
2740 hw
->nvm
.ops
.read(hw
, NVM_ETS_CFG
, 1, &ets_offset
);
2741 if ((ets_offset
== 0x0000) || (ets_offset
== 0xFFFF))
2744 hw
->nvm
.ops
.read(hw
, ets_offset
, 1, &ets_cfg
);
2745 if (((ets_cfg
& NVM_ETS_TYPE_MASK
) >> NVM_ETS_TYPE_SHIFT
)
2746 != NVM_ETS_TYPE_EMC
)
2747 return E1000_NOT_IMPLEMENTED
;
2749 num_sensors
= (ets_cfg
& NVM_ETS_NUM_SENSORS_MASK
);
2750 if (num_sensors
> E1000_MAX_SENSORS
)
2751 num_sensors
= E1000_MAX_SENSORS
;
2753 for (i
= 1; i
< num_sensors
; i
++) {
2754 hw
->nvm
.ops
.read(hw
, (ets_offset
+ i
), 1, &ets_sensor
);
2755 sensor_index
= ((ets_sensor
& NVM_ETS_DATA_INDEX_MASK
) >>
2756 NVM_ETS_DATA_INDEX_SHIFT
);
2757 sensor_location
= ((ets_sensor
& NVM_ETS_DATA_LOC_MASK
) >>
2758 NVM_ETS_DATA_LOC_SHIFT
);
2760 if (sensor_location
!= 0)
2761 hw
->phy
.ops
.read_i2c_byte(hw
,
2762 e1000_emc_temp_data
[sensor_index
],
2763 E1000_I2C_THERMAL_SENSOR_ADDR
,
2764 &data
->sensor
[i
].temp
);
2770 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
2771 * @hw: pointer to hardware structure
2773 * Sets the thermal sensor thresholds according to the NVM map
2774 * and save off the threshold and location values into mac.thermal_sensor_data
2776 static s32
igb_init_thermal_sensor_thresh_generic(struct e1000_hw
*hw
)
2778 s32 status
= E1000_SUCCESS
;
2782 u8 low_thresh_delta
;
2788 struct e1000_thermal_sensor_data
*data
= &hw
->mac
.thermal_sensor_data
;
2790 if ((hw
->mac
.type
!= e1000_i350
) || (hw
->bus
.func
!= 0))
2791 return E1000_NOT_IMPLEMENTED
;
2793 memset(data
, 0, sizeof(struct e1000_thermal_sensor_data
));
2795 data
->sensor
[0].location
= 0x1;
2796 data
->sensor
[0].caution_thresh
=
2797 (rd32(E1000_THHIGHTC
) & 0xFF);
2798 data
->sensor
[0].max_op_thresh
=
2799 (rd32(E1000_THLOWTC
) & 0xFF);
2801 /* Return the internal sensor only if ETS is unsupported */
2802 hw
->nvm
.ops
.read(hw
, NVM_ETS_CFG
, 1, &ets_offset
);
2803 if ((ets_offset
== 0x0000) || (ets_offset
== 0xFFFF))
2806 hw
->nvm
.ops
.read(hw
, ets_offset
, 1, &ets_cfg
);
2807 if (((ets_cfg
& NVM_ETS_TYPE_MASK
) >> NVM_ETS_TYPE_SHIFT
)
2808 != NVM_ETS_TYPE_EMC
)
2809 return E1000_NOT_IMPLEMENTED
;
2811 low_thresh_delta
= ((ets_cfg
& NVM_ETS_LTHRES_DELTA_MASK
) >>
2812 NVM_ETS_LTHRES_DELTA_SHIFT
);
2813 num_sensors
= (ets_cfg
& NVM_ETS_NUM_SENSORS_MASK
);
2815 for (i
= 1; i
<= num_sensors
; i
++) {
2816 hw
->nvm
.ops
.read(hw
, (ets_offset
+ i
), 1, &ets_sensor
);
2817 sensor_index
= ((ets_sensor
& NVM_ETS_DATA_INDEX_MASK
) >>
2818 NVM_ETS_DATA_INDEX_SHIFT
);
2819 sensor_location
= ((ets_sensor
& NVM_ETS_DATA_LOC_MASK
) >>
2820 NVM_ETS_DATA_LOC_SHIFT
);
2821 therm_limit
= ets_sensor
& NVM_ETS_DATA_HTHRESH_MASK
;
2823 hw
->phy
.ops
.write_i2c_byte(hw
,
2824 e1000_emc_therm_limit
[sensor_index
],
2825 E1000_I2C_THERMAL_SENSOR_ADDR
,
2828 if ((i
< E1000_MAX_SENSORS
) && (sensor_location
!= 0)) {
2829 data
->sensor
[i
].location
= sensor_location
;
2830 data
->sensor
[i
].caution_thresh
= therm_limit
;
2831 data
->sensor
[i
].max_op_thresh
= therm_limit
-
2838 static struct e1000_mac_operations e1000_mac_ops_82575
= {
2839 .init_hw
= igb_init_hw_82575
,
2840 .check_for_link
= igb_check_for_link_82575
,
2841 .rar_set
= igb_rar_set
,
2842 .read_mac_addr
= igb_read_mac_addr_82575
,
2843 .get_speed_and_duplex
= igb_get_link_up_info_82575
,
2844 #ifdef CONFIG_IGB_HWMON
2845 .get_thermal_sensor_data
= igb_get_thermal_sensor_data_generic
,
2846 .init_thermal_sensor_thresh
= igb_init_thermal_sensor_thresh_generic
,
2850 static struct e1000_phy_operations e1000_phy_ops_82575
= {
2851 .acquire
= igb_acquire_phy_82575
,
2852 .get_cfg_done
= igb_get_cfg_done_82575
,
2853 .release
= igb_release_phy_82575
,
2854 .write_i2c_byte
= igb_write_i2c_byte
,
2855 .read_i2c_byte
= igb_read_i2c_byte
,
2858 static struct e1000_nvm_operations e1000_nvm_ops_82575
= {
2859 .acquire
= igb_acquire_nvm_82575
,
2860 .read
= igb_read_nvm_eerd
,
2861 .release
= igb_release_nvm_82575
,
2862 .write
= igb_write_nvm_spi
,
2865 const struct e1000_info e1000_82575_info
= {
2866 .get_invariants
= igb_get_invariants_82575
,
2867 .mac_ops
= &e1000_mac_ops_82575
,
2868 .phy_ops
= &e1000_phy_ops_82575
,
2869 .nvm_ops
= &e1000_nvm_ops_82575
,