blob: 0f55d79afe39f394e6ee9b903eca3251fc08fd6b [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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.
9
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
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82571EB Gigabit Ethernet Controller
Bruce Allan16059272008-11-21 16:51:06 -080030 * 82571EB Gigabit Ethernet Controller (Copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -070031 * 82571EB Gigabit Ethernet Controller (Fiber)
Bruce Allanad680762008-03-28 09:15:03 -070032 * 82571EB Dual Port Gigabit Mezzanine Adapter
33 * 82571EB Quad Port Gigabit Mezzanine Adapter
34 * 82571PT Gigabit PT Quad Port Server ExpressModule
Auke Kokbc7f75f2007-09-17 12:30:59 -070035 * 82572EI Gigabit Ethernet Controller (Copper)
36 * 82572EI Gigabit Ethernet Controller (Fiber)
37 * 82572EI Gigabit Ethernet Controller
38 * 82573V Gigabit Ethernet Controller (Copper)
39 * 82573E Gigabit Ethernet Controller (Copper)
40 * 82573L Gigabit Ethernet Controller
Bruce Allan4662e822008-08-26 18:37:06 -070041 * 82574L Gigabit Network Connection
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000042 * 82583V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070043 */
44
Auke Kokbc7f75f2007-09-17 12:30:59 -070045#include "e1000.h"
46
47#define ID_LED_RESERVED_F746 0xF746
48#define ID_LED_DEFAULT_82573 ((ID_LED_DEF1_DEF2 << 12) | \
49 (ID_LED_OFF1_ON2 << 8) | \
50 (ID_LED_DEF1_DEF2 << 4) | \
51 (ID_LED_DEF1_DEF2))
52
53#define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
Bruce Alland9c76f92010-11-24 06:01:35 +000054#define AN_RETRY_COUNT 5 /* Autoneg Retry Count value */
Carolyn Wybornyff10e132010-10-28 00:59:53 +000055#define E1000_BASE1000T_STATUS 10
56#define E1000_IDLE_ERROR_COUNT_MASK 0xFF
57#define E1000_RECEIVE_ERROR_COUNTER 21
58#define E1000_RECEIVE_ERROR_MAX 0xFFFF
Auke Kokbc7f75f2007-09-17 12:30:59 -070059
Bruce Allan4662e822008-08-26 18:37:06 -070060#define E1000_NVM_INIT_CTRL2_MNGM 0x6000 /* Manageability Operation Mode mask */
61
Auke Kokbc7f75f2007-09-17 12:30:59 -070062static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
63static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
64static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
dave grahamc9523372009-02-10 12:52:28 +000065static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -070066static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
67 u16 words, u16 *data);
68static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
69static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -070070static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
Bruce Allan4662e822008-08-26 18:37:06 -070071static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
72static s32 e1000_led_on_82574(struct e1000_hw *hw);
Dave Graham23a2d1b2009-06-08 14:28:17 +000073static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw);
Bruce Allan17f208d2009-12-01 15:47:22 +000074static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw);
Bruce Allan1b98c2b2010-11-16 19:50:14 -080075static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw);
76static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw);
77static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw);
Bruce Allan77996d12011-01-06 14:29:53 +000078static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw, bool active);
79static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw, bool active);
Auke Kokbc7f75f2007-09-17 12:30:59 -070080
81/**
82 * e1000_init_phy_params_82571 - Init PHY func ptrs.
83 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -070084 **/
85static s32 e1000_init_phy_params_82571(struct e1000_hw *hw)
86{
87 struct e1000_phy_info *phy = &hw->phy;
88 s32 ret_val;
89
Jeff Kirsher318a94d2008-03-28 09:15:16 -070090 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -070091 phy->type = e1000_phy_none;
92 return 0;
93 }
94
95 phy->addr = 1;
96 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
97 phy->reset_delay_us = 100;
98
Bruce Allan17f208d2009-12-01 15:47:22 +000099 phy->ops.power_up = e1000_power_up_phy_copper;
100 phy->ops.power_down = e1000_power_down_phy_copper_82571;
101
Auke Kokbc7f75f2007-09-17 12:30:59 -0700102 switch (hw->mac.type) {
103 case e1000_82571:
104 case e1000_82572:
105 phy->type = e1000_phy_igp_2;
106 break;
107 case e1000_82573:
108 phy->type = e1000_phy_m88;
109 break;
Bruce Allan4662e822008-08-26 18:37:06 -0700110 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000111 case e1000_82583:
Bruce Allan4662e822008-08-26 18:37:06 -0700112 phy->type = e1000_phy_bm;
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800113 phy->ops.acquire = e1000_get_hw_semaphore_82574;
114 phy->ops.release = e1000_put_hw_semaphore_82574;
Bruce Allan77996d12011-01-06 14:29:53 +0000115 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82574;
116 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82574;
Bruce Allan4662e822008-08-26 18:37:06 -0700117 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700118 default:
119 return -E1000_ERR_PHY;
120 break;
121 }
122
123 /* This can only be done after all function pointers are setup. */
124 ret_val = e1000_get_phy_id_82571(hw);
Bruce Allandd93f952011-01-06 14:29:48 +0000125 if (ret_val) {
126 e_dbg("Error getting PHY ID\n");
127 return ret_val;
128 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
130 /* Verify phy id */
131 switch (hw->mac.type) {
132 case e1000_82571:
133 case e1000_82572:
134 if (phy->id != IGP01E1000_I_PHY_ID)
Bruce Allandd93f952011-01-06 14:29:48 +0000135 ret_val = -E1000_ERR_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700136 break;
137 case e1000_82573:
138 if (phy->id != M88E1111_I_PHY_ID)
Bruce Allandd93f952011-01-06 14:29:48 +0000139 ret_val = -E1000_ERR_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700140 break;
Bruce Allan4662e822008-08-26 18:37:06 -0700141 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000142 case e1000_82583:
Bruce Allan4662e822008-08-26 18:37:06 -0700143 if (phy->id != BME1000_E_PHY_ID_R2)
Bruce Allandd93f952011-01-06 14:29:48 +0000144 ret_val = -E1000_ERR_PHY;
Bruce Allan4662e822008-08-26 18:37:06 -0700145 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700146 default:
Bruce Allandd93f952011-01-06 14:29:48 +0000147 ret_val = -E1000_ERR_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700148 break;
149 }
150
Bruce Allandd93f952011-01-06 14:29:48 +0000151 if (ret_val)
152 e_dbg("PHY ID unknown: type = 0x%08x\n", phy->id);
153
154 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700155}
156
157/**
158 * e1000_init_nvm_params_82571 - Init NVM func ptrs.
159 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -0700160 **/
161static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
162{
163 struct e1000_nvm_info *nvm = &hw->nvm;
164 u32 eecd = er32(EECD);
165 u16 size;
166
167 nvm->opcode_bits = 8;
168 nvm->delay_usec = 1;
169 switch (nvm->override) {
170 case e1000_nvm_override_spi_large:
171 nvm->page_size = 32;
172 nvm->address_bits = 16;
173 break;
174 case e1000_nvm_override_spi_small:
175 nvm->page_size = 8;
176 nvm->address_bits = 8;
177 break;
178 default:
179 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
180 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
181 break;
182 }
183
184 switch (hw->mac.type) {
185 case e1000_82573:
Bruce Allan4662e822008-08-26 18:37:06 -0700186 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000187 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 if (((eecd >> 15) & 0x3) == 0x3) {
189 nvm->type = e1000_nvm_flash_hw;
190 nvm->word_size = 2048;
Bruce Allane921eb12012-11-28 09:28:37 +0000191 /* Autonomous Flash update bit must be cleared due
Auke Kokbc7f75f2007-09-17 12:30:59 -0700192 * to Flash update issue.
193 */
194 eecd &= ~E1000_EECD_AUPDEN;
195 ew32(EECD, eecd);
196 break;
197 }
198 /* Fall Through */
199 default:
Bruce Allanad680762008-03-28 09:15:03 -0700200 nvm->type = e1000_nvm_eeprom_spi;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700201 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
202 E1000_EECD_SIZE_EX_SHIFT);
Bruce Allane921eb12012-11-28 09:28:37 +0000203 /* Added to a constant, "size" becomes the left-shift value
Auke Kokbc7f75f2007-09-17 12:30:59 -0700204 * for setting word_size.
205 */
206 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher8d7c2942008-04-02 13:48:07 -0700207
208 /* EEPROM access above 16k is unsupported */
209 if (size > 14)
210 size = 14;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700211 nvm->word_size = 1 << size;
212 break;
213 }
214
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800215 /* Function Pointers */
216 switch (hw->mac.type) {
217 case e1000_82574:
218 case e1000_82583:
219 nvm->ops.acquire = e1000_get_hw_semaphore_82574;
220 nvm->ops.release = e1000_put_hw_semaphore_82574;
221 break;
222 default:
223 break;
224 }
225
Auke Kokbc7f75f2007-09-17 12:30:59 -0700226 return 0;
227}
228
229/**
230 * e1000_init_mac_params_82571 - Init MAC func ptrs.
231 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -0700232 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000233static s32 e1000_init_mac_params_82571(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700234{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700235 struct e1000_mac_info *mac = &hw->mac;
Dave Graham23a2d1b2009-06-08 14:28:17 +0000236 u32 swsm = 0;
237 u32 swsm2 = 0;
238 bool force_clear_smbi = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700239
Bruce Allan66092f52012-01-31 06:37:48 +0000240 /* Set media type and media-dependent function pointers */
Bruce Allanec34c172012-02-01 10:53:05 +0000241 switch (hw->adapter->pdev->device) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700242 case E1000_DEV_ID_82571EB_FIBER:
243 case E1000_DEV_ID_82572EI_FIBER:
244 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700245 hw->phy.media_type = e1000_media_type_fiber;
Bruce Allan66092f52012-01-31 06:37:48 +0000246 mac->ops.setup_physical_interface =
247 e1000_setup_fiber_serdes_link_82571;
248 mac->ops.check_for_link = e1000e_check_for_fiber_link;
249 mac->ops.get_link_up_info =
250 e1000e_get_speed_and_duplex_fiber_serdes;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700251 break;
252 case E1000_DEV_ID_82571EB_SERDES:
Auke Kok040babf2007-10-31 15:22:05 -0700253 case E1000_DEV_ID_82571EB_SERDES_DUAL:
254 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Bruce Allan66092f52012-01-31 06:37:48 +0000255 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700256 hw->phy.media_type = e1000_media_type_internal_serdes;
Bruce Allan66092f52012-01-31 06:37:48 +0000257 mac->ops.setup_physical_interface =
258 e1000_setup_fiber_serdes_link_82571;
259 mac->ops.check_for_link = e1000_check_for_serdes_link_82571;
260 mac->ops.get_link_up_info =
261 e1000e_get_speed_and_duplex_fiber_serdes;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700262 break;
263 default:
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700264 hw->phy.media_type = e1000_media_type_copper;
Bruce Allan66092f52012-01-31 06:37:48 +0000265 mac->ops.setup_physical_interface =
266 e1000_setup_copper_link_82571;
267 mac->ops.check_for_link = e1000e_check_for_copper_link;
268 mac->ops.get_link_up_info = e1000e_get_speed_and_duplex_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700269 break;
270 }
271
272 /* Set mta register count */
273 mac->mta_reg_count = 128;
274 /* Set rar entry count */
275 mac->rar_entry_count = E1000_RAR_ENTRIES;
Bruce Allanf464ba82010-01-07 16:31:35 +0000276 /* Adaptive IFS supported */
277 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700278
Bruce Allan66092f52012-01-31 06:37:48 +0000279 /* MAC-specific function pointers */
Bruce Allan4662e822008-08-26 18:37:06 -0700280 switch (hw->mac.type) {
Bruce Allanf4d2dd42010-01-13 02:05:18 +0000281 case e1000_82573:
Bruce Allan66092f52012-01-31 06:37:48 +0000282 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
283 mac->ops.check_mng_mode = e1000e_check_mng_mode_generic;
284 mac->ops.led_on = e1000e_led_on_generic;
285 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana65a4a02010-05-10 15:01:51 +0000286
287 /* FWSM register */
288 mac->has_fwsm = true;
Bruce Allane921eb12012-11-28 09:28:37 +0000289 /* ARC supported; valid only if manageability features are
Bruce Allana65a4a02010-05-10 15:01:51 +0000290 * enabled.
291 */
Bruce Allan04499ec2012-04-13 00:08:31 +0000292 mac->arc_subsystem_valid = !!(er32(FWSM) &
293 E1000_FWSM_MODE_MASK);
Bruce Allanf4d2dd42010-01-13 02:05:18 +0000294 break;
Bruce Allan4662e822008-08-26 18:37:06 -0700295 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000296 case e1000_82583:
Bruce Allan66092f52012-01-31 06:37:48 +0000297 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
298 mac->ops.check_mng_mode = e1000_check_mng_mode_82574;
299 mac->ops.led_on = e1000_led_on_82574;
Bruce Allan4662e822008-08-26 18:37:06 -0700300 break;
301 default:
Bruce Allan66092f52012-01-31 06:37:48 +0000302 mac->ops.check_mng_mode = e1000e_check_mng_mode_generic;
303 mac->ops.led_on = e1000e_led_on_generic;
304 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana65a4a02010-05-10 15:01:51 +0000305
306 /* FWSM register */
307 mac->has_fwsm = true;
Bruce Allan4662e822008-08-26 18:37:06 -0700308 break;
309 }
310
Bruce Allane921eb12012-11-28 09:28:37 +0000311 /* Ensure that the inter-port SWSM.SMBI lock bit is clear before
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400312 * first NVM or PHY access. This should be done for single-port
Dave Graham23a2d1b2009-06-08 14:28:17 +0000313 * devices, and for one port only on dual-port devices so that
314 * for those devices we can still use the SMBI lock to synchronize
315 * inter-port accesses to the PHY & NVM.
316 */
317 switch (hw->mac.type) {
318 case e1000_82571:
319 case e1000_82572:
320 swsm2 = er32(SWSM2);
321
322 if (!(swsm2 & E1000_SWSM2_LOCK)) {
323 /* Only do this for the first interface on this card */
Bruce Allan66092f52012-01-31 06:37:48 +0000324 ew32(SWSM2, swsm2 | E1000_SWSM2_LOCK);
Dave Graham23a2d1b2009-06-08 14:28:17 +0000325 force_clear_smbi = true;
Bruce Allan66092f52012-01-31 06:37:48 +0000326 } else {
Dave Graham23a2d1b2009-06-08 14:28:17 +0000327 force_clear_smbi = false;
Bruce Allan66092f52012-01-31 06:37:48 +0000328 }
Dave Graham23a2d1b2009-06-08 14:28:17 +0000329 break;
330 default:
331 force_clear_smbi = true;
332 break;
333 }
334
335 if (force_clear_smbi) {
336 /* Make sure SWSM.SMBI is clear */
337 swsm = er32(SWSM);
338 if (swsm & E1000_SWSM_SMBI) {
339 /* This bit should not be set on a first interface, and
340 * indicates that the bootagent or EFI code has
341 * improperly left this bit enabled
342 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000343 e_dbg("Please update your 82571 Bootagent\n");
Dave Graham23a2d1b2009-06-08 14:28:17 +0000344 }
345 ew32(SWSM, swsm & ~E1000_SWSM_SMBI);
346 }
347
Bruce Allane921eb12012-11-28 09:28:37 +0000348 /* Initialize device specific counter of SMBI acquisition timeouts. */
349 hw->dev_spec.e82571.smb_counter = 0;
Dave Graham23a2d1b2009-06-08 14:28:17 +0000350
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351 return 0;
352}
353
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700354static s32 e1000_get_variants_82571(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355{
356 struct e1000_hw *hw = &adapter->hw;
357 static int global_quad_port_a; /* global port a indication */
358 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359 int is_port_b = er32(STATUS) & E1000_STATUS_FUNC_1;
360 s32 rc;
361
Bruce Allanec34c172012-02-01 10:53:05 +0000362 rc = e1000_init_mac_params_82571(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363 if (rc)
364 return rc;
365
366 rc = e1000_init_nvm_params_82571(hw);
367 if (rc)
368 return rc;
369
370 rc = e1000_init_phy_params_82571(hw);
371 if (rc)
372 return rc;
373
374 /* tag quad port adapters first, it's used below */
375 switch (pdev->device) {
376 case E1000_DEV_ID_82571EB_QUAD_COPPER:
377 case E1000_DEV_ID_82571EB_QUAD_FIBER:
378 case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
Auke Kok040babf2007-10-31 15:22:05 -0700379 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700380 adapter->flags |= FLAG_IS_QUAD_PORT;
381 /* mark the first port */
382 if (global_quad_port_a == 0)
383 adapter->flags |= FLAG_IS_QUAD_PORT_A;
384 /* Reset for multiple quad port adapters */
385 global_quad_port_a++;
386 if (global_quad_port_a == 4)
387 global_quad_port_a = 0;
388 break;
389 default:
390 break;
391 }
392
393 switch (adapter->hw.mac.type) {
394 case e1000_82571:
395 /* these dual ports don't have WoL on port B at all */
396 if (((pdev->device == E1000_DEV_ID_82571EB_FIBER) ||
397 (pdev->device == E1000_DEV_ID_82571EB_SERDES) ||
398 (pdev->device == E1000_DEV_ID_82571EB_COPPER)) &&
399 (is_port_b))
400 adapter->flags &= ~FLAG_HAS_WOL;
401 /* quad ports only support WoL on port A */
402 if (adapter->flags & FLAG_IS_QUAD_PORT &&
Roel Kluin6e4ca802007-10-29 10:50:05 -0700403 (!(adapter->flags & FLAG_IS_QUAD_PORT_A)))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700404 adapter->flags &= ~FLAG_HAS_WOL;
Auke Kok040babf2007-10-31 15:22:05 -0700405 /* Does not support WoL on any port */
406 if (pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD)
407 adapter->flags &= ~FLAG_HAS_WOL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700408 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700409 case e1000_82573:
410 if (pdev->device == E1000_DEV_ID_82573L) {
Bruce Allan6f461f62010-04-27 03:33:04 +0000411 adapter->flags |= FLAG_HAS_JUMBO_FRAMES;
412 adapter->max_hw_frame_size = DEFAULT_JUMBO;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700413 }
414 break;
415 default:
416 break;
417 }
418
419 return 0;
420}
421
422/**
423 * e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
424 * @hw: pointer to the HW structure
425 *
426 * Reads the PHY registers and stores the PHY ID and possibly the PHY
427 * revision in the hardware structure.
428 **/
429static s32 e1000_get_phy_id_82571(struct e1000_hw *hw)
430{
431 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan4662e822008-08-26 18:37:06 -0700432 s32 ret_val;
433 u16 phy_id = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700434
435 switch (hw->mac.type) {
436 case e1000_82571:
437 case e1000_82572:
Bruce Allane921eb12012-11-28 09:28:37 +0000438 /* The 82571 firmware may still be configuring the PHY.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700439 * In this case, we cannot access the PHY until the
440 * configuration is done. So we explicitly set the
Bruce Allanad680762008-03-28 09:15:03 -0700441 * PHY ID.
442 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700443 phy->id = IGP01E1000_I_PHY_ID;
444 break;
445 case e1000_82573:
446 return e1000e_get_phy_id(hw);
447 break;
Bruce Allan4662e822008-08-26 18:37:06 -0700448 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000449 case e1000_82583:
Bruce Allan4662e822008-08-26 18:37:06 -0700450 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
451 if (ret_val)
452 return ret_val;
453
454 phy->id = (u32)(phy_id << 16);
455 udelay(20);
456 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
457 if (ret_val)
458 return ret_val;
459
460 phy->id |= (u32)(phy_id);
461 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
462 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463 default:
464 return -E1000_ERR_PHY;
465 break;
466 }
467
468 return 0;
469}
470
471/**
472 * e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
473 * @hw: pointer to the HW structure
474 *
475 * Acquire the HW semaphore to access the PHY or NVM
476 **/
477static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
478{
479 u32 swsm;
Dave Graham23a2d1b2009-06-08 14:28:17 +0000480 s32 sw_timeout = hw->nvm.word_size + 1;
481 s32 fw_timeout = hw->nvm.word_size + 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700482 s32 i = 0;
483
Bruce Allane921eb12012-11-28 09:28:37 +0000484 /* If we have timedout 3 times on trying to acquire
Dave Graham23a2d1b2009-06-08 14:28:17 +0000485 * the inter-port SMBI semaphore, there is old code
486 * operating on the other port, and it is not
487 * releasing SMBI. Modify the number of times that
488 * we try for the semaphore to interwork with this
489 * older code.
490 */
491 if (hw->dev_spec.e82571.smb_counter > 2)
492 sw_timeout = 1;
493
494 /* Get the SW semaphore */
495 while (i < sw_timeout) {
496 swsm = er32(SWSM);
497 if (!(swsm & E1000_SWSM_SMBI))
498 break;
499
500 udelay(50);
501 i++;
502 }
503
504 if (i == sw_timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000505 e_dbg("Driver can't access device - SMBI bit is set.\n");
Dave Graham23a2d1b2009-06-08 14:28:17 +0000506 hw->dev_spec.e82571.smb_counter++;
507 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 /* Get the FW semaphore. */
Dave Graham23a2d1b2009-06-08 14:28:17 +0000509 for (i = 0; i < fw_timeout; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700510 swsm = er32(SWSM);
511 ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
512
513 /* Semaphore acquired if bit latched */
514 if (er32(SWSM) & E1000_SWSM_SWESMBI)
515 break;
516
517 udelay(50);
518 }
519
Dave Graham23a2d1b2009-06-08 14:28:17 +0000520 if (i == fw_timeout) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700521 /* Release semaphores */
Dave Graham23a2d1b2009-06-08 14:28:17 +0000522 e1000_put_hw_semaphore_82571(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000523 e_dbg("Driver can't access the NVM\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 return -E1000_ERR_NVM;
525 }
526
527 return 0;
528}
529
530/**
531 * e1000_put_hw_semaphore_82571 - Release hardware semaphore
532 * @hw: pointer to the HW structure
533 *
534 * Release hardware semaphore used to access the PHY or NVM
535 **/
536static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
537{
538 u32 swsm;
539
540 swsm = er32(SWSM);
Dave Graham23a2d1b2009-06-08 14:28:17 +0000541 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700542 ew32(SWSM, swsm);
543}
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800544/**
545 * e1000_get_hw_semaphore_82573 - Acquire hardware semaphore
546 * @hw: pointer to the HW structure
547 *
548 * Acquire the HW semaphore during reset.
549 *
550 **/
551static s32 e1000_get_hw_semaphore_82573(struct e1000_hw *hw)
552{
553 u32 extcnf_ctrl;
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800554 s32 i = 0;
555
556 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800557 do {
Bruce Allan7dbbe5d2013-01-05 05:08:31 +0000558 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800559 ew32(EXTCNF_CTRL, extcnf_ctrl);
560 extcnf_ctrl = er32(EXTCNF_CTRL);
561
562 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
563 break;
564
Bruce Allan1bba4382011-03-19 00:27:20 +0000565 usleep_range(2000, 4000);
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800566 i++;
567 } while (i < MDIO_OWNERSHIP_TIMEOUT);
568
569 if (i == MDIO_OWNERSHIP_TIMEOUT) {
570 /* Release semaphores */
571 e1000_put_hw_semaphore_82573(hw);
572 e_dbg("Driver can't access the PHY\n");
Bruce Allan5015e532012-02-08 02:55:56 +0000573 return -E1000_ERR_PHY;
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800574 }
575
Bruce Allan5015e532012-02-08 02:55:56 +0000576 return 0;
Bruce Allan1b98c2b2010-11-16 19:50:14 -0800577}
578
579/**
580 * e1000_put_hw_semaphore_82573 - Release hardware semaphore
581 * @hw: pointer to the HW structure
582 *
583 * Release hardware semaphore used during reset.
584 *
585 **/
586static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw)
587{
588 u32 extcnf_ctrl;
589
590 extcnf_ctrl = er32(EXTCNF_CTRL);
591 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
592 ew32(EXTCNF_CTRL, extcnf_ctrl);
593}
594
595static DEFINE_MUTEX(swflag_mutex);
596
597/**
598 * e1000_get_hw_semaphore_82574 - Acquire hardware semaphore
599 * @hw: pointer to the HW structure
600 *
601 * Acquire the HW semaphore to access the PHY or NVM.
602 *
603 **/
604static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw)
605{
606 s32 ret_val;
607
608 mutex_lock(&swflag_mutex);
609 ret_val = e1000_get_hw_semaphore_82573(hw);
610 if (ret_val)
611 mutex_unlock(&swflag_mutex);
612 return ret_val;
613}
614
615/**
616 * e1000_put_hw_semaphore_82574 - Release hardware semaphore
617 * @hw: pointer to the HW structure
618 *
619 * Release hardware semaphore used to access the PHY or NVM
620 *
621 **/
622static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw)
623{
624 e1000_put_hw_semaphore_82573(hw);
625 mutex_unlock(&swflag_mutex);
626}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627
628/**
Bruce Allan77996d12011-01-06 14:29:53 +0000629 * e1000_set_d0_lplu_state_82574 - Set Low Power Linkup D0 state
630 * @hw: pointer to the HW structure
631 * @active: true to enable LPLU, false to disable
632 *
633 * Sets the LPLU D0 state according to the active flag.
634 * LPLU will not be activated unless the
635 * device autonegotiation advertisement meets standards of
636 * either 10 or 10/100 or 10/100/1000 at all duplexes.
637 * This is a function pointer entry point only called by
638 * PHY setup routines.
639 **/
640static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw, bool active)
641{
Bruce Allanefc38d22012-08-17 06:17:51 +0000642 u32 data = er32(POEMB);
Bruce Allan77996d12011-01-06 14:29:53 +0000643
644 if (active)
645 data |= E1000_PHY_CTRL_D0A_LPLU;
646 else
647 data &= ~E1000_PHY_CTRL_D0A_LPLU;
648
649 ew32(POEMB, data);
650 return 0;
651}
652
653/**
654 * e1000_set_d3_lplu_state_82574 - Sets low power link up state for D3
655 * @hw: pointer to the HW structure
656 * @active: boolean used to enable/disable lplu
657 *
658 * The low power link up (lplu) state is set to the power management level D3
659 * when active is true, else clear lplu for D3. LPLU
660 * is used during Dx states where the power conservation is most important.
661 * During driver activity, SmartSpeed should be enabled so performance is
662 * maintained.
663 **/
664static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw, bool active)
665{
Bruce Allanefc38d22012-08-17 06:17:51 +0000666 u32 data = er32(POEMB);
Bruce Allan77996d12011-01-06 14:29:53 +0000667
668 if (!active) {
669 data &= ~E1000_PHY_CTRL_NOND0A_LPLU;
670 } else if ((hw->phy.autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
671 (hw->phy.autoneg_advertised == E1000_ALL_NOT_GIG) ||
672 (hw->phy.autoneg_advertised == E1000_ALL_10_SPEED)) {
673 data |= E1000_PHY_CTRL_NOND0A_LPLU;
674 }
675
676 ew32(POEMB, data);
677 return 0;
678}
679
680/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700681 * e1000_acquire_nvm_82571 - Request for access to the EEPROM
682 * @hw: pointer to the HW structure
683 *
684 * To gain access to the EEPROM, first we must obtain a hardware semaphore.
685 * Then for non-82573 hardware, set the EEPROM access request bit and wait
686 * for EEPROM access grant bit. If the access grant bit is not set, release
687 * hardware semaphore.
688 **/
689static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw)
690{
691 s32 ret_val;
692
693 ret_val = e1000_get_hw_semaphore_82571(hw);
694 if (ret_val)
695 return ret_val;
696
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000697 switch (hw->mac.type) {
698 case e1000_82573:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000699 break;
700 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700701 ret_val = e1000e_acquire_nvm(hw);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000702 break;
703 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704
705 if (ret_val)
706 e1000_put_hw_semaphore_82571(hw);
707
708 return ret_val;
709}
710
711/**
712 * e1000_release_nvm_82571 - Release exclusive access to EEPROM
713 * @hw: pointer to the HW structure
714 *
715 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
716 **/
717static void e1000_release_nvm_82571(struct e1000_hw *hw)
718{
719 e1000e_release_nvm(hw);
720 e1000_put_hw_semaphore_82571(hw);
721}
722
723/**
724 * e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
725 * @hw: pointer to the HW structure
726 * @offset: offset within the EEPROM to be written to
727 * @words: number of words to write
728 * @data: 16 bit word(s) to be written to the EEPROM
729 *
730 * For non-82573 silicon, write data to EEPROM at offset using SPI interface.
731 *
732 * If e1000e_update_nvm_checksum is not called after this function, the
Auke Kok489815c2008-02-21 15:11:07 -0800733 * EEPROM will most likely contain an invalid checksum.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700734 **/
735static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
736 u16 *data)
737{
738 s32 ret_val;
739
740 switch (hw->mac.type) {
741 case e1000_82573:
Bruce Allan4662e822008-08-26 18:37:06 -0700742 case e1000_82574:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +0000743 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700744 ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
745 break;
746 case e1000_82571:
747 case e1000_82572:
748 ret_val = e1000e_write_nvm_spi(hw, offset, words, data);
749 break;
750 default:
751 ret_val = -E1000_ERR_NVM;
752 break;
753 }
754
755 return ret_val;
756}
757
758/**
759 * e1000_update_nvm_checksum_82571 - Update EEPROM checksum
760 * @hw: pointer to the HW structure
761 *
762 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
763 * up to the checksum. Then calculates the EEPROM checksum and writes the
764 * value to the EEPROM.
765 **/
766static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
767{
768 u32 eecd;
769 s32 ret_val;
770 u16 i;
771
772 ret_val = e1000e_update_nvm_checksum_generic(hw);
773 if (ret_val)
774 return ret_val;
775
Bruce Allane921eb12012-11-28 09:28:37 +0000776 /* If our nvm is an EEPROM, then we're done
Bruce Allanad680762008-03-28 09:15:03 -0700777 * otherwise, commit the checksum to the flash NVM.
778 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 if (hw->nvm.type != e1000_nvm_flash_hw)
Bruce Allan82607252012-02-08 02:55:09 +0000780 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700781
782 /* Check for pending operations. */
783 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000784 usleep_range(1000, 2000);
Bruce Allan04499ec2012-04-13 00:08:31 +0000785 if (!(er32(EECD) & E1000_EECD_FLUPD))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700786 break;
787 }
788
789 if (i == E1000_FLASH_UPDATES)
790 return -E1000_ERR_NVM;
791
792 /* Reset the firmware if using STM opcode. */
793 if ((er32(FLOP) & 0xFF00) == E1000_STM_OPCODE) {
Bruce Allane921eb12012-11-28 09:28:37 +0000794 /* The enabling of and the actual reset must be done
Auke Kokbc7f75f2007-09-17 12:30:59 -0700795 * in two write cycles.
796 */
797 ew32(HICR, E1000_HICR_FW_RESET_ENABLE);
798 e1e_flush();
799 ew32(HICR, E1000_HICR_FW_RESET);
800 }
801
802 /* Commit the write to flash */
803 eecd = er32(EECD) | E1000_EECD_FLUPD;
804 ew32(EECD, eecd);
805
806 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000807 usleep_range(1000, 2000);
Bruce Allan04499ec2012-04-13 00:08:31 +0000808 if (!(er32(EECD) & E1000_EECD_FLUPD))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 break;
810 }
811
812 if (i == E1000_FLASH_UPDATES)
813 return -E1000_ERR_NVM;
814
815 return 0;
816}
817
818/**
819 * e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
820 * @hw: pointer to the HW structure
821 *
822 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
823 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
824 **/
825static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
826{
827 if (hw->nvm.type == e1000_nvm_flash_hw)
828 e1000_fix_nvm_checksum_82571(hw);
829
830 return e1000e_validate_nvm_checksum_generic(hw);
831}
832
833/**
834 * e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
835 * @hw: pointer to the HW structure
836 * @offset: offset within the EEPROM to be written to
837 * @words: number of words to write
838 * @data: 16 bit word(s) to be written to the EEPROM
839 *
840 * After checking for invalid values, poll the EEPROM to ensure the previous
841 * command has completed before trying to write the next word. After write
842 * poll for completion.
843 *
844 * If e1000e_update_nvm_checksum is not called after this function, the
Auke Kok489815c2008-02-21 15:11:07 -0800845 * EEPROM will most likely contain an invalid checksum.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700846 **/
847static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
848 u16 words, u16 *data)
849{
850 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allana708dd82009-11-20 23:28:37 +0000851 u32 i, eewr = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 s32 ret_val = 0;
853
Bruce Allane921eb12012-11-28 09:28:37 +0000854 /* A check for invalid values: offset too large, too many words,
Bruce Allanad680762008-03-28 09:15:03 -0700855 * and not enough words.
856 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700857 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
858 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000859 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 return -E1000_ERR_NVM;
861 }
862
863 for (i = 0; i < words; i++) {
864 eewr = (data[i] << E1000_NVM_RW_REG_DATA) |
865 ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
866 E1000_NVM_RW_REG_START;
867
868 ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
869 if (ret_val)
870 break;
871
872 ew32(EEWR, eewr);
873
874 ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
875 if (ret_val)
876 break;
877 }
878
879 return ret_val;
880}
881
882/**
883 * e1000_get_cfg_done_82571 - Poll for configuration done
884 * @hw: pointer to the HW structure
885 *
886 * Reads the management control register for the config done bit to be set.
887 **/
888static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw)
889{
890 s32 timeout = PHY_CFG_TIMEOUT;
891
892 while (timeout) {
893 if (er32(EEMNGCTL) &
894 E1000_NVM_CFG_DONE_PORT_0)
895 break;
Bruce Allan1bba4382011-03-19 00:27:20 +0000896 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700897 timeout--;
898 }
899 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000900 e_dbg("MNG configuration cycle has not completed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 return -E1000_ERR_RESET;
902 }
903
904 return 0;
905}
906
907/**
908 * e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
909 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +0000910 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 *
912 * Sets the LPLU D0 state according to the active flag. When activating LPLU
913 * this function also disables smart speed and vice versa. LPLU will not be
914 * activated unless the device autonegotiation advertisement meets standards
915 * of either 10 or 10/100 or 10/100/1000 at all duplexes. This is a function
916 * pointer entry point only called by PHY setup routines.
917 **/
918static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
919{
920 struct e1000_phy_info *phy = &hw->phy;
921 s32 ret_val;
922 u16 data;
923
924 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
925 if (ret_val)
926 return ret_val;
927
928 if (active) {
929 data |= IGP02E1000_PM_D0_LPLU;
930 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
931 if (ret_val)
932 return ret_val;
933
934 /* When LPLU is enabled, we should disable SmartSpeed */
935 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +0000936 if (ret_val)
937 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700938 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
939 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
940 if (ret_val)
941 return ret_val;
942 } else {
943 data &= ~IGP02E1000_PM_D0_LPLU;
944 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Bruce Allane921eb12012-11-28 09:28:37 +0000945 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946 * during Dx states where the power conservation is most
947 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -0700948 * SmartSpeed, so performance is maintained.
949 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 if (phy->smart_speed == e1000_smart_speed_on) {
951 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700952 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700953 if (ret_val)
954 return ret_val;
955
956 data |= IGP01E1000_PSCFR_SMART_SPEED;
957 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700958 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700959 if (ret_val)
960 return ret_val;
961 } else if (phy->smart_speed == e1000_smart_speed_off) {
962 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700963 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700964 if (ret_val)
965 return ret_val;
966
967 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
968 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700969 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970 if (ret_val)
971 return ret_val;
972 }
973 }
974
975 return 0;
976}
977
978/**
979 * e1000_reset_hw_82571 - Reset hardware
980 * @hw: pointer to the HW structure
981 *
Bruce Allanfe401672009-11-20 23:26:05 +0000982 * This resets the hardware into a known state.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983 **/
984static s32 e1000_reset_hw_82571(struct e1000_hw *hw)
985{
Tushar Daveeca90f52012-08-01 02:11:15 +0000986 u32 ctrl, ctrl_ext, eecd, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988
Bruce Allane921eb12012-11-28 09:28:37 +0000989 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 * on the last TLP read/write transaction when MAC is reset.
991 */
992 ret_val = e1000e_disable_pcie_master(hw);
993 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000994 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700995
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000996 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997 ew32(IMC, 0xffffffff);
998
999 ew32(RCTL, 0);
Tushar Daveeca90f52012-08-01 02:11:15 +00001000 tctl = er32(TCTL);
1001 tctl &= ~E1000_TCTL_EN;
1002 ew32(TCTL, tctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 e1e_flush();
1004
Bruce Allan1bba4382011-03-19 00:27:20 +00001005 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006
Bruce Allane921eb12012-11-28 09:28:37 +00001007 /* Must acquire the MDIO ownership before MAC reset.
Bruce Allanad680762008-03-28 09:15:03 -07001008 * Ownership defaults to firmware after a reset.
1009 */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001010 switch (hw->mac.type) {
1011 case e1000_82573:
Bruce Allan1b98c2b2010-11-16 19:50:14 -08001012 ret_val = e1000_get_hw_semaphore_82573(hw);
1013 break;
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001014 case e1000_82574:
1015 case e1000_82583:
Bruce Allan1b98c2b2010-11-16 19:50:14 -08001016 ret_val = e1000_get_hw_semaphore_82574(hw);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001017 break;
1018 default:
1019 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 }
Bruce Allan1b98c2b2010-11-16 19:50:14 -08001021 if (ret_val)
1022 e_dbg("Cannot acquire MDIO ownership\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023
1024 ctrl = er32(CTRL);
1025
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001026 e_dbg("Issuing a global reset to MAC\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 ew32(CTRL, ctrl | E1000_CTRL_RST);
1028
Bruce Allan1b98c2b2010-11-16 19:50:14 -08001029 /* Must release MDIO ownership and mutex after MAC reset. */
1030 switch (hw->mac.type) {
1031 case e1000_82574:
1032 case e1000_82583:
1033 e1000_put_hw_semaphore_82574(hw);
1034 break;
1035 default:
1036 break;
1037 }
1038
Auke Kokbc7f75f2007-09-17 12:30:59 -07001039 if (hw->nvm.type == e1000_nvm_flash_hw) {
1040 udelay(10);
1041 ctrl_ext = er32(CTRL_EXT);
1042 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1043 ew32(CTRL_EXT, ctrl_ext);
1044 e1e_flush();
1045 }
1046
1047 ret_val = e1000e_get_auto_rd_done(hw);
1048 if (ret_val)
1049 /* We don't want to continue accessing MAC registers. */
1050 return ret_val;
1051
Bruce Allane921eb12012-11-28 09:28:37 +00001052 /* Phy configuration from NVM just starts after EECD_AUTO_RD is set.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053 * Need to wait for Phy configuration completion before accessing
1054 * NVM and Phy.
1055 */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001056
1057 switch (hw->mac.type) {
Richard Alpe1f56f452012-04-20 15:24:50 +00001058 case e1000_82571:
1059 case e1000_82572:
Bruce Allane921eb12012-11-28 09:28:37 +00001060 /* REQ and GNT bits need to be cleared when using AUTO_RD
Richard Alpe1f56f452012-04-20 15:24:50 +00001061 * to access the EEPROM.
1062 */
1063 eecd = er32(EECD);
1064 eecd &= ~(E1000_EECD_REQ | E1000_EECD_GNT);
1065 ew32(EECD, eecd);
1066 break;
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001067 case e1000_82573:
1068 case e1000_82574:
1069 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001070 msleep(25);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001071 break;
1072 default:
1073 break;
1074 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075
1076 /* Clear any pending interrupt events. */
1077 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00001078 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079
Bruce Allan1aef70e2010-08-19 15:48:52 -07001080 if (hw->mac.type == e1000_82571) {
1081 /* Install any alternate MAC address into RAR0 */
1082 ret_val = e1000_check_alt_mac_addr_generic(hw);
1083 if (ret_val)
1084 return ret_val;
Bruce Allan608f8a02010-01-13 02:04:58 +00001085
Bruce Allan1aef70e2010-08-19 15:48:52 -07001086 e1000e_set_laa_state_82571(hw, true);
1087 }
Bill Hayes93ca1612007-10-31 15:21:52 -07001088
dave grahamc9523372009-02-10 12:52:28 +00001089 /* Reinitialize the 82571 serdes link state machine */
1090 if (hw->phy.media_type == e1000_media_type_internal_serdes)
1091 hw->mac.serdes_link_state = e1000_serdes_link_down;
1092
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093 return 0;
1094}
1095
1096/**
1097 * e1000_init_hw_82571 - Initialize hardware
1098 * @hw: pointer to the HW structure
1099 *
1100 * This inits the hardware readying it for operation.
1101 **/
1102static s32 e1000_init_hw_82571(struct e1000_hw *hw)
1103{
1104 struct e1000_mac_info *mac = &hw->mac;
1105 u32 reg_data;
1106 s32 ret_val;
Bruce Allana708dd82009-11-20 23:28:37 +00001107 u16 i, rar_count = mac->rar_entry_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108
1109 e1000_initialize_hw_bits_82571(hw);
1110
1111 /* Initialize identification LED */
Bruce Alland1964eb2012-02-22 09:02:21 +00001112 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00001113 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001114 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00001115 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116
1117 /* Disabling VLAN filtering */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001118 e_dbg("Initializing the IEEE VLAN\n");
Bruce Allancaaddaf2009-12-01 15:46:43 +00001119 mac->ops.clear_vfta(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120
Bruce Allane921eb12012-11-28 09:28:37 +00001121 /* Setup the receive address.
Bruce Allanad680762008-03-28 09:15:03 -07001122 * If, however, a locally administered address was assigned to the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 * 82571, we must reserve a RAR for it to work around an issue where
1124 * resetting one port will reload the MAC on the other port.
1125 */
1126 if (e1000e_get_laa_state_82571(hw))
1127 rar_count--;
1128 e1000e_init_rx_addrs(hw, rar_count);
1129
1130 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001131 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 for (i = 0; i < mac->mta_reg_count; i++)
1133 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1134
1135 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00001136 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001137
1138 /* Set the transmit descriptor write-back policy */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001139 reg_data = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
1141 E1000_TXDCTL_FULL_TX_DESC_WB |
1142 E1000_TXDCTL_COUNT_DESC;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001143 ew32(TXDCTL(0), reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144
1145 /* ...for both queues. */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001146 switch (mac->type) {
1147 case e1000_82573:
Bruce Allana65a4a02010-05-10 15:01:51 +00001148 e1000e_enable_tx_pkt_filtering(hw);
1149 /* fall through */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001150 case e1000_82574:
1151 case e1000_82583:
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001152 reg_data = er32(GCR);
1153 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1154 ew32(GCR, reg_data);
1155 break;
1156 default:
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001157 reg_data = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 reg_data = (reg_data & ~E1000_TXDCTL_WTHRESH) |
1159 E1000_TXDCTL_FULL_TX_DESC_WB |
1160 E1000_TXDCTL_COUNT_DESC;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001161 ew32(TXDCTL(1), reg_data);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001162 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 }
1164
Bruce Allane921eb12012-11-28 09:28:37 +00001165 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 * important that we do this after we have tried to establish link
1167 * because the symbol error count will increment wildly if there
1168 * is no link.
1169 */
1170 e1000_clear_hw_cntrs_82571(hw);
1171
1172 return ret_val;
1173}
1174
1175/**
1176 * e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
1177 * @hw: pointer to the HW structure
1178 *
1179 * Initializes required hardware-dependent bits needed for normal operation.
1180 **/
1181static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
1182{
1183 u32 reg;
1184
1185 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001186 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001188 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189
1190 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001191 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001193 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194
1195 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001196 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 reg &= ~(0xF << 27); /* 30:27 */
1198 switch (hw->mac.type) {
1199 case e1000_82571:
1200 case e1000_82572:
1201 reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
1202 break;
Bruce Alland6cb17d2011-12-16 00:46:22 +00001203 case e1000_82574:
1204 case e1000_82583:
1205 reg |= (1 << 26);
1206 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 default:
1208 break;
1209 }
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001210 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211
1212 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001213 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214 switch (hw->mac.type) {
1215 case e1000_82571:
1216 case e1000_82572:
1217 reg &= ~((1 << 29) | (1 << 30));
1218 reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
1219 if (er32(TCTL) & E1000_TCTL_MULR)
1220 reg &= ~(1 << 28);
1221 else
1222 reg |= (1 << 28);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07001223 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 break;
1225 default:
1226 break;
1227 }
1228
1229 /* Device Control */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001230 switch (hw->mac.type) {
1231 case e1000_82573:
1232 case e1000_82574:
1233 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 reg = er32(CTRL);
1235 reg &= ~(1 << 29);
1236 ew32(CTRL, reg);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001237 break;
1238 default:
1239 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001240 }
1241
1242 /* Extended Device Control */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001243 switch (hw->mac.type) {
1244 case e1000_82573:
1245 case e1000_82574:
1246 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 reg = er32(CTRL_EXT);
1248 reg &= ~(1 << 23);
1249 reg |= (1 << 22);
1250 ew32(CTRL_EXT, reg);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001251 break;
1252 default:
1253 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254 }
Bruce Allan4662e822008-08-26 18:37:06 -07001255
Alexander Duyck6ea7ae12008-11-14 06:54:36 +00001256 if (hw->mac.type == e1000_82571) {
1257 reg = er32(PBA_ECC);
1258 reg |= E1000_PBA_ECC_CORR_EN;
1259 ew32(PBA_ECC, reg);
1260 }
Bruce Allan3d3a1672012-02-23 03:13:18 +00001261
Bruce Allane921eb12012-11-28 09:28:37 +00001262 /* Workaround for hardware errata.
dave graham5df3f0e2009-02-10 12:51:41 +00001263 * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
1264 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001265 if ((hw->mac.type == e1000_82571) || (hw->mac.type == e1000_82572)) {
1266 reg = er32(CTRL_EXT);
1267 reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
1268 ew32(CTRL_EXT, reg);
1269 }
Alexander Duyck6ea7ae12008-11-14 06:54:36 +00001270
Bruce Allane921eb12012-11-28 09:28:37 +00001271 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00001272 * IPv6 headers can hang the Rx.
1273 */
1274 if (hw->mac.type <= e1000_82573) {
1275 reg = er32(RFCTL);
1276 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
1277 ew32(RFCTL, reg);
1278 }
1279
Jesse Brandeburg78272bb2009-01-26 12:16:26 -08001280 /* PCI-Ex Control Registers */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001281 switch (hw->mac.type) {
1282 case e1000_82574:
1283 case e1000_82583:
Bruce Allan4662e822008-08-26 18:37:06 -07001284 reg = er32(GCR);
1285 reg |= (1 << 22);
1286 ew32(GCR, reg);
Jesse Brandeburg78272bb2009-01-26 12:16:26 -08001287
Bruce Allane921eb12012-11-28 09:28:37 +00001288 /* Workaround for hardware errata.
Bruce Allan84efb7b2009-11-20 23:26:24 +00001289 * apply workaround for hardware errata documented in errata
1290 * docs Fixes issue where some error prone or unreliable PCIe
1291 * completions are occurring, particularly with ASPM enabled.
Bruce Allanaf667a22010-12-31 06:10:01 +00001292 * Without fix, issue can cause Tx timeouts.
Bruce Allan84efb7b2009-11-20 23:26:24 +00001293 */
Jesse Brandeburg78272bb2009-01-26 12:16:26 -08001294 reg = er32(GCR2);
1295 reg |= 1;
1296 ew32(GCR2, reg);
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001297 break;
1298 default:
1299 break;
Bruce Allan4662e822008-08-26 18:37:06 -07001300 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001301}
1302
1303/**
Bruce Allancaaddaf2009-12-01 15:46:43 +00001304 * e1000_clear_vfta_82571 - Clear VLAN filter table
Auke Kokbc7f75f2007-09-17 12:30:59 -07001305 * @hw: pointer to the HW structure
1306 *
1307 * Clears the register array which contains the VLAN filter table by
1308 * setting all the values to 0.
1309 **/
Bruce Allancaaddaf2009-12-01 15:46:43 +00001310static void e1000_clear_vfta_82571(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311{
1312 u32 offset;
1313 u32 vfta_value = 0;
1314 u32 vfta_offset = 0;
1315 u32 vfta_bit_in_reg = 0;
1316
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001317 switch (hw->mac.type) {
1318 case e1000_82573:
1319 case e1000_82574:
1320 case e1000_82583:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001321 if (hw->mng_cookie.vlan_id != 0) {
Bruce Allane921eb12012-11-28 09:28:37 +00001322 /* The VFTA is a 4096b bit-field, each identifying
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 * a single VLAN ID. The following operations
1324 * determine which 32b entry (i.e. offset) into the
1325 * array we want to set the VLAN ID (i.e. bit) of
1326 * the manageability unit.
1327 */
1328 vfta_offset = (hw->mng_cookie.vlan_id >>
1329 E1000_VFTA_ENTRY_SHIFT) &
1330 E1000_VFTA_ENTRY_MASK;
1331 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
1332 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
1333 }
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001334 break;
1335 default:
1336 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337 }
1338 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
Bruce Allane921eb12012-11-28 09:28:37 +00001339 /* If the offset we want to clear is the same offset of the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001340 * manageability VLAN ID, then clear all bits except that of
1341 * the manageability unit.
1342 */
1343 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
1344 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, vfta_value);
1345 e1e_flush();
1346 }
1347}
1348
1349/**
Bruce Allan4662e822008-08-26 18:37:06 -07001350 * e1000_check_mng_mode_82574 - Check manageability is enabled
1351 * @hw: pointer to the HW structure
1352 *
1353 * Reads the NVM Initialization Control Word 2 and returns true
1354 * (>0) if any manageability is enabled, else false (0).
1355 **/
1356static bool e1000_check_mng_mode_82574(struct e1000_hw *hw)
1357{
1358 u16 data;
1359
1360 e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
1361 return (data & E1000_NVM_INIT_CTRL2_MNGM) != 0;
1362}
1363
1364/**
1365 * e1000_led_on_82574 - Turn LED on
1366 * @hw: pointer to the HW structure
1367 *
1368 * Turn LED on.
1369 **/
1370static s32 e1000_led_on_82574(struct e1000_hw *hw)
1371{
1372 u32 ctrl;
1373 u32 i;
1374
1375 ctrl = hw->mac.ledctl_mode2;
1376 if (!(E1000_STATUS_LU & er32(STATUS))) {
Bruce Allane921eb12012-11-28 09:28:37 +00001377 /* If no link, then turn LED on by setting the invert bit
Bruce Allan4662e822008-08-26 18:37:06 -07001378 * for each LED that's "on" (0x0E) in ledctl_mode2.
1379 */
1380 for (i = 0; i < 4; i++)
1381 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1382 E1000_LEDCTL_MODE_LED_ON)
1383 ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
1384 }
1385 ew32(LEDCTL, ctrl);
1386
1387 return 0;
1388}
1389
1390/**
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001391 * e1000_check_phy_82574 - check 82574 phy hung state
1392 * @hw: pointer to the HW structure
1393 *
1394 * Returns whether phy is hung or not
1395 **/
1396bool e1000_check_phy_82574(struct e1000_hw *hw)
1397{
1398 u16 status_1kbt = 0;
1399 u16 receive_errors = 0;
Bruce Allan70806a72013-01-05 05:08:37 +00001400 s32 ret_val;
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001401
Bruce Allane921eb12012-11-28 09:28:37 +00001402 /* Read PHY Receive Error counter first, if its is max - all F's then
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001403 * read the Base1000T status register If both are max then PHY is hung.
1404 */
1405 ret_val = e1e_rphy(hw, E1000_RECEIVE_ERROR_COUNTER, &receive_errors);
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001406 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001407 return false;
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001408 if (receive_errors == E1000_RECEIVE_ERROR_MAX) {
1409 ret_val = e1e_rphy(hw, E1000_BASE1000T_STATUS, &status_1kbt);
1410 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001411 return false;
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001412 if ((status_1kbt & E1000_IDLE_ERROR_COUNT_MASK) ==
1413 E1000_IDLE_ERROR_COUNT_MASK)
Bruce Allan5015e532012-02-08 02:55:56 +00001414 return true;
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001415 }
Bruce Allan5015e532012-02-08 02:55:56 +00001416
1417 return false;
Carolyn Wybornyff10e132010-10-28 00:59:53 +00001418}
1419
1420/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001421 * e1000_setup_link_82571 - Setup flow control and link settings
1422 * @hw: pointer to the HW structure
1423 *
1424 * Determines which flow control settings to use, then configures flow
1425 * control. Calls the appropriate media-specific link configuration
1426 * function. Assuming the adapter has a valid link partner, a valid link
1427 * should be established. Assumes the hardware has previously been reset
1428 * and the transmitter and receiver are not enabled.
1429 **/
1430static s32 e1000_setup_link_82571(struct e1000_hw *hw)
1431{
Bruce Allane921eb12012-11-28 09:28:37 +00001432 /* 82573 does not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07001433 * the default flow control setting, so we explicitly
1434 * set it to full.
1435 */
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001436 switch (hw->mac.type) {
1437 case e1000_82573:
1438 case e1000_82574:
1439 case e1000_82583:
1440 if (hw->fc.requested_mode == e1000_fc_default)
1441 hw->fc.requested_mode = e1000_fc_full;
1442 break;
1443 default:
1444 break;
1445 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446
Bruce Allan1a46b402012-02-22 09:02:26 +00001447 return e1000e_setup_link_generic(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001448}
1449
1450/**
1451 * e1000_setup_copper_link_82571 - Configure copper link settings
1452 * @hw: pointer to the HW structure
1453 *
1454 * Configures the link for auto-neg or forced speed and duplex. Then we check
1455 * for link, once link is established calls to configure collision distance
1456 * and flow control are called.
1457 **/
1458static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw)
1459{
1460 u32 ctrl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 s32 ret_val;
1462
1463 ctrl = er32(CTRL);
1464 ctrl |= E1000_CTRL_SLU;
1465 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1466 ew32(CTRL, ctrl);
1467
1468 switch (hw->phy.type) {
1469 case e1000_phy_m88:
Bruce Allan4662e822008-08-26 18:37:06 -07001470 case e1000_phy_bm:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001471 ret_val = e1000e_copper_link_setup_m88(hw);
1472 break;
1473 case e1000_phy_igp_2:
1474 ret_val = e1000e_copper_link_setup_igp(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 break;
1476 default:
1477 return -E1000_ERR_PHY;
1478 break;
1479 }
1480
1481 if (ret_val)
1482 return ret_val;
1483
Bruce Allan7eb61d82012-02-08 02:55:03 +00001484 return e1000e_setup_copper_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485}
1486
1487/**
1488 * e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
1489 * @hw: pointer to the HW structure
1490 *
1491 * Configures collision distance and flow control for fiber and serdes links.
1492 * Upon successful setup, poll for link.
1493 **/
1494static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
1495{
1496 switch (hw->mac.type) {
1497 case e1000_82571:
1498 case e1000_82572:
Bruce Allane921eb12012-11-28 09:28:37 +00001499 /* If SerDes loopback mode is entered, there is no form
Auke Kokbc7f75f2007-09-17 12:30:59 -07001500 * of reset to take the adapter out of that mode. So we
1501 * have to explicitly take the adapter out of loopback
Auke Kok489815c2008-02-21 15:11:07 -08001502 * mode. This prevents drivers from twiddling their thumbs
Auke Kokbc7f75f2007-09-17 12:30:59 -07001503 * if another tool failed to take it out of loopback mode.
1504 */
Bruce Allanad680762008-03-28 09:15:03 -07001505 ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001506 break;
1507 default:
1508 break;
1509 }
1510
1511 return e1000e_setup_fiber_serdes_link(hw);
1512}
1513
1514/**
dave grahamc9523372009-02-10 12:52:28 +00001515 * e1000_check_for_serdes_link_82571 - Check for link (Serdes)
1516 * @hw: pointer to the HW structure
1517 *
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001518 * Reports the link state as up or down.
1519 *
1520 * If autonegotiation is supported by the link partner, the link state is
1521 * determined by the result of autonegotiation. This is the most likely case.
1522 * If autonegotiation is not supported by the link partner, and the link
1523 * has a valid signal, force the link up.
1524 *
1525 * The link state is represented internally here by 4 states:
1526 *
1527 * 1) down
1528 * 2) autoneg_progress
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001529 * 3) autoneg_complete (the link successfully autonegotiated)
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001530 * 4) forced_up (the link has been forced up, it did not autonegotiate)
1531 *
dave grahamc9523372009-02-10 12:52:28 +00001532 **/
Hannes Ederf6370112009-02-14 11:32:25 +00001533static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
dave grahamc9523372009-02-10 12:52:28 +00001534{
1535 struct e1000_mac_info *mac = &hw->mac;
1536 u32 rxcw;
1537 u32 ctrl;
1538 u32 status;
Bruce Alland9c76f92010-11-24 06:01:35 +00001539 u32 txcw;
1540 u32 i;
dave grahamc9523372009-02-10 12:52:28 +00001541 s32 ret_val = 0;
1542
1543 ctrl = er32(CTRL);
1544 status = er32(STATUS);
Bruce Allan70806a72013-01-05 05:08:37 +00001545 er32(RXCW);
Tushar Daved0efa8f2012-07-12 08:56:56 +00001546 /* SYNCH bit and IV bit are sticky */
1547 udelay(10);
1548 rxcw = er32(RXCW);
dave grahamc9523372009-02-10 12:52:28 +00001549
1550 if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
1551
1552 /* Receiver is synchronized with no invalid bits. */
1553 switch (mac->serdes_link_state) {
1554 case e1000_serdes_link_autoneg_complete:
1555 if (!(status & E1000_STATUS_LU)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001556 /* We have lost link, retry autoneg before
dave grahamc9523372009-02-10 12:52:28 +00001557 * reporting link failure
1558 */
1559 mac->serdes_link_state =
1560 e1000_serdes_link_autoneg_progress;
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001561 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001562 e_dbg("AN_UP -> AN_PROG\n");
Bruce Allana82a14f2010-11-24 06:01:20 +00001563 } else {
1564 mac->serdes_has_link = true;
dave grahamc9523372009-02-10 12:52:28 +00001565 }
Bruce Allana82a14f2010-11-24 06:01:20 +00001566 break;
dave grahamc9523372009-02-10 12:52:28 +00001567
1568 case e1000_serdes_link_forced_up:
Bruce Allane921eb12012-11-28 09:28:37 +00001569 /* If we are receiving /C/ ordered sets, re-enable
dave grahamc9523372009-02-10 12:52:28 +00001570 * auto-negotiation in the TXCW register and disable
1571 * forced link in the Device Control register in an
1572 * attempt to auto-negotiate with our link partner.
1573 */
Tushar Daveb7ec70b2012-07-31 02:02:43 +00001574 if (rxcw & E1000_RXCW_C) {
dave grahamc9523372009-02-10 12:52:28 +00001575 /* Enable autoneg, and unforce link up */
1576 ew32(TXCW, mac->txcw);
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001577 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
dave grahamc9523372009-02-10 12:52:28 +00001578 mac->serdes_link_state =
1579 e1000_serdes_link_autoneg_progress;
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001580 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001581 e_dbg("FORCED_UP -> AN_PROG\n");
Bruce Allana82a14f2010-11-24 06:01:20 +00001582 } else {
1583 mac->serdes_has_link = true;
dave grahamc9523372009-02-10 12:52:28 +00001584 }
1585 break;
1586
1587 case e1000_serdes_link_autoneg_progress:
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001588 if (rxcw & E1000_RXCW_C) {
Bruce Allane921eb12012-11-28 09:28:37 +00001589 /* We received /C/ ordered sets, meaning the
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001590 * link partner has autonegotiated, and we can
1591 * trust the Link Up (LU) status bit.
1592 */
1593 if (status & E1000_STATUS_LU) {
1594 mac->serdes_link_state =
1595 e1000_serdes_link_autoneg_complete;
1596 e_dbg("AN_PROG -> AN_UP\n");
1597 mac->serdes_has_link = true;
1598 } else {
1599 /* Autoneg completed, but failed. */
1600 mac->serdes_link_state =
1601 e1000_serdes_link_down;
1602 e_dbg("AN_PROG -> DOWN\n");
1603 }
dave grahamc9523372009-02-10 12:52:28 +00001604 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001605 /* The link partner did not autoneg.
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001606 * Force link up and full duplex, and change
1607 * state to forced.
dave grahamc9523372009-02-10 12:52:28 +00001608 */
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001609 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
dave grahamc9523372009-02-10 12:52:28 +00001610 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
1611 ew32(CTRL, ctrl);
1612
1613 /* Configure Flow Control after link up. */
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001614 ret_val = e1000e_config_fc_after_link_up(hw);
dave grahamc9523372009-02-10 12:52:28 +00001615 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001616 e_dbg("Error config flow control\n");
dave grahamc9523372009-02-10 12:52:28 +00001617 break;
1618 }
1619 mac->serdes_link_state =
1620 e1000_serdes_link_forced_up;
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001621 mac->serdes_has_link = true;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001622 e_dbg("AN_PROG -> FORCED_UP\n");
dave grahamc9523372009-02-10 12:52:28 +00001623 }
dave grahamc9523372009-02-10 12:52:28 +00001624 break;
1625
1626 case e1000_serdes_link_down:
1627 default:
Bruce Allane921eb12012-11-28 09:28:37 +00001628 /* The link was down but the receiver has now gained
dave grahamc9523372009-02-10 12:52:28 +00001629 * valid sync, so lets see if we can bring the link
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001630 * up.
1631 */
dave grahamc9523372009-02-10 12:52:28 +00001632 ew32(TXCW, mac->txcw);
Bruce Allan1a40d5c2009-12-01 15:49:51 +00001633 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
dave grahamc9523372009-02-10 12:52:28 +00001634 mac->serdes_link_state =
1635 e1000_serdes_link_autoneg_progress;
Bruce Allana82a14f2010-11-24 06:01:20 +00001636 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001637 e_dbg("DOWN -> AN_PROG\n");
dave grahamc9523372009-02-10 12:52:28 +00001638 break;
1639 }
1640 } else {
1641 if (!(rxcw & E1000_RXCW_SYNCH)) {
1642 mac->serdes_has_link = false;
1643 mac->serdes_link_state = e1000_serdes_link_down;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001644 e_dbg("ANYSTATE -> DOWN\n");
dave grahamc9523372009-02-10 12:52:28 +00001645 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001646 /* Check several times, if SYNCH bit and CONFIG
Tushar Dave18115f82012-07-12 08:00:15 +00001647 * bit both are consistently 1 then simply ignore
1648 * the IV bit and restart Autoneg
dave grahamc9523372009-02-10 12:52:28 +00001649 */
Bruce Alland9c76f92010-11-24 06:01:35 +00001650 for (i = 0; i < AN_RETRY_COUNT; i++) {
1651 udelay(10);
1652 rxcw = er32(RXCW);
Tushar Dave18115f82012-07-12 08:00:15 +00001653 if ((rxcw & E1000_RXCW_SYNCH) &&
1654 (rxcw & E1000_RXCW_C))
1655 continue;
1656
1657 if (rxcw & E1000_RXCW_IV) {
Bruce Alland9c76f92010-11-24 06:01:35 +00001658 mac->serdes_has_link = false;
1659 mac->serdes_link_state =
1660 e1000_serdes_link_down;
1661 e_dbg("ANYSTATE -> DOWN\n");
1662 break;
1663 }
1664 }
1665
1666 if (i == AN_RETRY_COUNT) {
1667 txcw = er32(TXCW);
1668 txcw |= E1000_TXCW_ANE;
1669 ew32(TXCW, txcw);
1670 mac->serdes_link_state =
1671 e1000_serdes_link_autoneg_progress;
dave grahamc9523372009-02-10 12:52:28 +00001672 mac->serdes_has_link = false;
Bruce Alland9c76f92010-11-24 06:01:35 +00001673 e_dbg("ANYSTATE -> AN_PROG\n");
dave grahamc9523372009-02-10 12:52:28 +00001674 }
1675 }
1676 }
1677
1678 return ret_val;
1679}
1680
1681/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 * e1000_valid_led_default_82571 - Verify a valid default LED config
1683 * @hw: pointer to the HW structure
1684 * @data: pointer to the NVM (EEPROM)
1685 *
1686 * Read the EEPROM for the current default LED configuration. If the
1687 * LED configuration is not valid, set to a valid LED configuration.
1688 **/
1689static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
1690{
1691 s32 ret_val;
1692
1693 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1694 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001695 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 return ret_val;
1697 }
1698
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00001699 switch (hw->mac.type) {
1700 case e1000_82573:
1701 case e1000_82574:
1702 case e1000_82583:
1703 if (*data == ID_LED_RESERVED_F746)
1704 *data = ID_LED_DEFAULT_82573;
1705 break;
1706 default:
1707 if (*data == ID_LED_RESERVED_0000 ||
1708 *data == ID_LED_RESERVED_FFFF)
1709 *data = ID_LED_DEFAULT;
1710 break;
1711 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001712
1713 return 0;
1714}
1715
1716/**
1717 * e1000e_get_laa_state_82571 - Get locally administered address state
1718 * @hw: pointer to the HW structure
1719 *
Auke Kok489815c2008-02-21 15:11:07 -08001720 * Retrieve and return the current locally administered address state.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 **/
1722bool e1000e_get_laa_state_82571(struct e1000_hw *hw)
1723{
1724 if (hw->mac.type != e1000_82571)
Bruce Allan564ea9b2009-11-20 23:26:44 +00001725 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726
1727 return hw->dev_spec.e82571.laa_is_present;
1728}
1729
1730/**
1731 * e1000e_set_laa_state_82571 - Set locally administered address state
1732 * @hw: pointer to the HW structure
1733 * @state: enable/disable locally administered address
1734 *
Bruce Allan5ff5b662009-12-01 15:51:11 +00001735 * Enable/Disable the current locally administered address state.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736 **/
1737void e1000e_set_laa_state_82571(struct e1000_hw *hw, bool state)
1738{
1739 if (hw->mac.type != e1000_82571)
1740 return;
1741
1742 hw->dev_spec.e82571.laa_is_present = state;
1743
1744 /* If workaround is activated... */
1745 if (state)
Bruce Allane921eb12012-11-28 09:28:37 +00001746 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07001747 * between the time RAR[0] gets clobbered and the time it
1748 * gets fixed, the actual LAA is in one of the RARs and no
1749 * incoming packets directed to this port are dropped.
1750 * Eventually the LAA will be in RAR[0] and RAR[14].
1751 */
Bruce Allan69e1e012012-04-14 03:28:50 +00001752 hw->mac.ops.rar_set(hw, hw->mac.addr,
1753 hw->mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754}
1755
1756/**
1757 * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
1758 * @hw: pointer to the HW structure
1759 *
1760 * Verifies that the EEPROM has completed the update. After updating the
1761 * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
1762 * the checksum fix is not implemented, we need to set the bit and update
1763 * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
1764 * we need to return bad checksum.
1765 **/
1766static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
1767{
1768 struct e1000_nvm_info *nvm = &hw->nvm;
1769 s32 ret_val;
1770 u16 data;
1771
1772 if (nvm->type != e1000_nvm_flash_hw)
1773 return 0;
1774
Bruce Allane921eb12012-11-28 09:28:37 +00001775 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 * 10h-12h. Checksum may need to be fixed.
1777 */
1778 ret_val = e1000_read_nvm(hw, 0x10, 1, &data);
1779 if (ret_val)
1780 return ret_val;
1781
1782 if (!(data & 0x10)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001783 /* Read 0x23 and check bit 15. This bit is a 1
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 * when the checksum has already been fixed. If
1785 * the checksum is still wrong and this bit is a
1786 * 1, we need to return bad checksum. Otherwise,
1787 * we need to set this bit to a 1 and update the
1788 * checksum.
1789 */
1790 ret_val = e1000_read_nvm(hw, 0x23, 1, &data);
1791 if (ret_val)
1792 return ret_val;
1793
1794 if (!(data & 0x8000)) {
1795 data |= 0x8000;
1796 ret_val = e1000_write_nvm(hw, 0x23, 1, &data);
1797 if (ret_val)
1798 return ret_val;
1799 ret_val = e1000e_update_nvm_checksum(hw);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00001800 if (ret_val)
1801 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802 }
1803 }
1804
1805 return 0;
1806}
1807
1808/**
Bruce Allan608f8a02010-01-13 02:04:58 +00001809 * e1000_read_mac_addr_82571 - Read device MAC address
1810 * @hw: pointer to the HW structure
1811 **/
1812static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw)
1813{
Bruce Allan1aef70e2010-08-19 15:48:52 -07001814 if (hw->mac.type == e1000_82571) {
Bruce Allan70806a72013-01-05 05:08:37 +00001815 s32 ret_val;
Bruce Allan5015e532012-02-08 02:55:56 +00001816
Bruce Allane921eb12012-11-28 09:28:37 +00001817 /* If there's an alternate MAC address place it in RAR0
Bruce Allan1aef70e2010-08-19 15:48:52 -07001818 * so that it will override the Si installed default perm
1819 * address.
1820 */
1821 ret_val = e1000_check_alt_mac_addr_generic(hw);
1822 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001823 return ret_val;
Bruce Allan1aef70e2010-08-19 15:48:52 -07001824 }
Bruce Allan608f8a02010-01-13 02:04:58 +00001825
Bruce Allan5015e532012-02-08 02:55:56 +00001826 return e1000_read_mac_addr_generic(hw);
Bruce Allan608f8a02010-01-13 02:04:58 +00001827}
1828
1829/**
Bruce Allan17f208d2009-12-01 15:47:22 +00001830 * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
1831 * @hw: pointer to the HW structure
1832 *
1833 * In the case of a PHY power down to save power, or to turn off link during a
1834 * driver unload, or wake on lan is not enabled, remove the link.
1835 **/
1836static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
1837{
1838 struct e1000_phy_info *phy = &hw->phy;
1839 struct e1000_mac_info *mac = &hw->mac;
1840
Bruce Allan668018d2012-01-31 07:02:56 +00001841 if (!phy->ops.check_reset_block)
Bruce Allan17f208d2009-12-01 15:47:22 +00001842 return;
1843
1844 /* If the management interface is not enabled, then power down */
1845 if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
1846 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00001847}
1848
1849/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001850 * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
1851 * @hw: pointer to the HW structure
1852 *
1853 * Clears the hardware counters by reading the counter registers.
1854 **/
1855static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
1856{
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857 e1000e_clear_hw_cntrs_base(hw);
1858
Bruce Allan99673d92009-11-20 23:27:21 +00001859 er32(PRC64);
1860 er32(PRC127);
1861 er32(PRC255);
1862 er32(PRC511);
1863 er32(PRC1023);
1864 er32(PRC1522);
1865 er32(PTC64);
1866 er32(PTC127);
1867 er32(PTC255);
1868 er32(PTC511);
1869 er32(PTC1023);
1870 er32(PTC1522);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001871
Bruce Allan99673d92009-11-20 23:27:21 +00001872 er32(ALGNERRC);
1873 er32(RXERRC);
1874 er32(TNCRS);
1875 er32(CEXTERR);
1876 er32(TSCTC);
1877 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878
Bruce Allan99673d92009-11-20 23:27:21 +00001879 er32(MGTPRC);
1880 er32(MGTPDC);
1881 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882
Bruce Allan99673d92009-11-20 23:27:21 +00001883 er32(IAC);
1884 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885
Bruce Allan99673d92009-11-20 23:27:21 +00001886 er32(ICRXPTC);
1887 er32(ICRXATC);
1888 er32(ICTXPTC);
1889 er32(ICTXATC);
1890 er32(ICTXQEC);
1891 er32(ICTXQMTC);
1892 er32(ICRXDMTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893}
1894
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001895static const struct e1000_mac_operations e82571_mac_ops = {
Bruce Allan4662e822008-08-26 18:37:06 -07001896 /* .check_mng_mode: mac type dependent */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001897 /* .check_for_link: media type dependent */
Bruce Alland1964eb2012-02-22 09:02:21 +00001898 .id_led_init = e1000e_id_led_init_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899 .cleanup_led = e1000e_cleanup_led_generic,
1900 .clear_hw_cntrs = e1000_clear_hw_cntrs_82571,
1901 .get_bus_info = e1000e_get_bus_info_pcie,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00001902 .set_lan_id = e1000_set_lan_id_multi_port_pcie,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001903 /* .get_link_up_info: media type dependent */
Bruce Allan4662e822008-08-26 18:37:06 -07001904 /* .led_on: mac type dependent */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 .led_off = e1000e_led_off_generic,
Bruce Allanab8932f2010-01-13 02:05:38 +00001906 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Bruce Allancaaddaf2009-12-01 15:46:43 +00001907 .write_vfta = e1000_write_vfta_generic,
1908 .clear_vfta = e1000_clear_vfta_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001909 .reset_hw = e1000_reset_hw_82571,
1910 .init_hw = e1000_init_hw_82571,
1911 .setup_link = e1000_setup_link_82571,
1912 /* .setup_physical_interface: media type dependent */
Bruce Allana4f58f52009-06-02 11:29:18 +00001913 .setup_led = e1000e_setup_led_generic,
Bruce Allan57cde762012-02-22 09:02:58 +00001914 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan608f8a02010-01-13 02:04:58 +00001915 .read_mac_addr = e1000_read_mac_addr_82571,
Bruce Allan69e1e012012-04-14 03:28:50 +00001916 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001917};
1918
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001919static const struct e1000_phy_operations e82_phy_ops_igp = {
Bruce Allan94d81862009-11-20 23:25:26 +00001920 .acquire = e1000_get_hw_semaphore_82571,
Bruce Allan94e5b652009-12-02 17:02:14 +00001921 .check_polarity = e1000_check_polarity_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001922 .check_reset_block = e1000e_check_reset_block_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00001923 .commit = NULL,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924 .force_speed_duplex = e1000e_phy_force_speed_duplex_igp,
1925 .get_cfg_done = e1000_get_cfg_done_82571,
1926 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00001927 .get_info = e1000e_get_phy_info_igp,
1928 .read_reg = e1000e_read_phy_reg_igp,
1929 .release = e1000_put_hw_semaphore_82571,
1930 .reset = e1000e_phy_hw_reset_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001931 .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
1932 .set_d3_lplu_state = e1000e_set_d3_lplu_state,
Bruce Allan94d81862009-11-20 23:25:26 +00001933 .write_reg = e1000e_write_phy_reg_igp,
Bruce Allan75eb0fa2008-11-21 16:53:51 -08001934 .cfg_on_link_up = NULL,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001935};
1936
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001937static const struct e1000_phy_operations e82_phy_ops_m88 = {
Bruce Allan94d81862009-11-20 23:25:26 +00001938 .acquire = e1000_get_hw_semaphore_82571,
Bruce Allan94e5b652009-12-02 17:02:14 +00001939 .check_polarity = e1000_check_polarity_m88,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001940 .check_reset_block = e1000e_check_reset_block_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00001941 .commit = e1000e_phy_sw_reset,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
1943 .get_cfg_done = e1000e_get_cfg_done,
1944 .get_cable_length = e1000e_get_cable_length_m88,
Bruce Allan94d81862009-11-20 23:25:26 +00001945 .get_info = e1000e_get_phy_info_m88,
1946 .read_reg = e1000e_read_phy_reg_m88,
1947 .release = e1000_put_hw_semaphore_82571,
1948 .reset = e1000e_phy_hw_reset_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001949 .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
1950 .set_d3_lplu_state = e1000e_set_d3_lplu_state,
Bruce Allan94d81862009-11-20 23:25:26 +00001951 .write_reg = e1000e_write_phy_reg_m88,
Bruce Allan75eb0fa2008-11-21 16:53:51 -08001952 .cfg_on_link_up = NULL,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953};
1954
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001955static const struct e1000_phy_operations e82_phy_ops_bm = {
Bruce Allan94d81862009-11-20 23:25:26 +00001956 .acquire = e1000_get_hw_semaphore_82571,
Bruce Allan94e5b652009-12-02 17:02:14 +00001957 .check_polarity = e1000_check_polarity_m88,
Bruce Allan4662e822008-08-26 18:37:06 -07001958 .check_reset_block = e1000e_check_reset_block_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00001959 .commit = e1000e_phy_sw_reset,
Bruce Allan4662e822008-08-26 18:37:06 -07001960 .force_speed_duplex = e1000e_phy_force_speed_duplex_m88,
1961 .get_cfg_done = e1000e_get_cfg_done,
1962 .get_cable_length = e1000e_get_cable_length_m88,
Bruce Allan94d81862009-11-20 23:25:26 +00001963 .get_info = e1000e_get_phy_info_m88,
1964 .read_reg = e1000e_read_phy_reg_bm2,
1965 .release = e1000_put_hw_semaphore_82571,
1966 .reset = e1000e_phy_hw_reset_generic,
Bruce Allan4662e822008-08-26 18:37:06 -07001967 .set_d0_lplu_state = e1000_set_d0_lplu_state_82571,
1968 .set_d3_lplu_state = e1000e_set_d3_lplu_state,
Bruce Allan94d81862009-11-20 23:25:26 +00001969 .write_reg = e1000e_write_phy_reg_bm2,
Bruce Allan75eb0fa2008-11-21 16:53:51 -08001970 .cfg_on_link_up = NULL,
Bruce Allan4662e822008-08-26 18:37:06 -07001971};
1972
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001973static const struct e1000_nvm_operations e82571_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00001974 .acquire = e1000_acquire_nvm_82571,
1975 .read = e1000e_read_nvm_eerd,
1976 .release = e1000_release_nvm_82571,
Bruce Allane85e3632012-02-22 09:03:14 +00001977 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00001978 .update = e1000_update_nvm_checksum_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001979 .valid_led_default = e1000_valid_led_default_82571,
Bruce Allan94d81862009-11-20 23:25:26 +00001980 .validate = e1000_validate_nvm_checksum_82571,
1981 .write = e1000_write_nvm_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982};
1983
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00001984const struct e1000_info e1000_82571_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001985 .mac = e1000_82571,
1986 .flags = FLAG_HAS_HW_VLAN_FILTER
1987 | FLAG_HAS_JUMBO_FRAMES
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988 | FLAG_HAS_WOL
1989 | FLAG_APME_IN_CTRL3
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990 | FLAG_HAS_CTRLEXT_ON_LOAD
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 | FLAG_HAS_SMART_POWER_DOWN
1992 | FLAG_RESET_OVERWRITES_LAA /* errata */
1993 | FLAG_TARC_SPEED_MODE_BIT /* errata */
1994 | FLAG_APME_CHECK_PORT_B,
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00001995 .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
1996 | FLAG2_DMA_BURST,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 .pba = 38,
Bruce Allan2adc55c2009-06-02 11:28:58 +00001998 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001999 .get_variants = e1000_get_variants_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002000 .mac_ops = &e82571_mac_ops,
2001 .phy_ops = &e82_phy_ops_igp,
2002 .nvm_ops = &e82571_nvm_ops,
2003};
2004
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00002005const struct e1000_info e1000_82572_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002006 .mac = e1000_82572,
2007 .flags = FLAG_HAS_HW_VLAN_FILTER
2008 | FLAG_HAS_JUMBO_FRAMES
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009 | FLAG_HAS_WOL
2010 | FLAG_APME_IN_CTRL3
Auke Kokbc7f75f2007-09-17 12:30:59 -07002011 | FLAG_HAS_CTRLEXT_ON_LOAD
Auke Kokbc7f75f2007-09-17 12:30:59 -07002012 | FLAG_TARC_SPEED_MODE_BIT, /* errata */
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002013 .flags2 = FLAG2_DISABLE_ASPM_L1 /* errata 13 */
2014 | FLAG2_DMA_BURST,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002015 .pba = 38,
Bruce Allan2adc55c2009-06-02 11:28:58 +00002016 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07002017 .get_variants = e1000_get_variants_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002018 .mac_ops = &e82571_mac_ops,
2019 .phy_ops = &e82_phy_ops_igp,
2020 .nvm_ops = &e82571_nvm_ops,
2021};
2022
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00002023const struct e1000_info e1000_82573_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002024 .mac = e1000_82573,
2025 .flags = FLAG_HAS_HW_VLAN_FILTER
Auke Kokbc7f75f2007-09-17 12:30:59 -07002026 | FLAG_HAS_WOL
2027 | FLAG_APME_IN_CTRL3
Auke Kokbc7f75f2007-09-17 12:30:59 -07002028 | FLAG_HAS_SMART_POWER_DOWN
2029 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07002030 | FLAG_HAS_SWSM_ON_LOAD,
Bruce Allan78cd29d2011-03-24 03:09:03 +00002031 .flags2 = FLAG2_DISABLE_ASPM_L1
2032 | FLAG2_DISABLE_ASPM_L0S,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002033 .pba = 20,
Bruce Allan2adc55c2009-06-02 11:28:58 +00002034 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07002035 .get_variants = e1000_get_variants_82571,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002036 .mac_ops = &e82571_mac_ops,
2037 .phy_ops = &e82_phy_ops_m88,
Auke Kok31f8c4f2008-02-21 15:10:47 -08002038 .nvm_ops = &e82571_nvm_ops,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002039};
2040
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00002041const struct e1000_info e1000_82574_info = {
Bruce Allan4662e822008-08-26 18:37:06 -07002042 .mac = e1000_82574,
2043 .flags = FLAG_HAS_HW_VLAN_FILTER
2044 | FLAG_HAS_MSIX
2045 | FLAG_HAS_JUMBO_FRAMES
2046 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00002047 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan4662e822008-08-26 18:37:06 -07002048 | FLAG_APME_IN_CTRL3
Bruce Allan4662e822008-08-26 18:37:06 -07002049 | FLAG_HAS_SMART_POWER_DOWN
2050 | FLAG_HAS_AMT
2051 | FLAG_HAS_CTRLEXT_ON_LOAD,
Chris Bootd4a42062012-04-24 07:24:52 +00002052 .flags2 = FLAG2_CHECK_PHY_HANG
Bruce Allan7f99ae62011-07-22 06:21:35 +00002053 | FLAG2_DISABLE_ASPM_L0S
Chris Bootd4a42062012-04-24 07:24:52 +00002054 | FLAG2_DISABLE_ASPM_L1
Matthew Vick2cb7a9c2012-03-16 09:02:59 +00002055 | FLAG2_NO_DISABLE_RX
2056 | FLAG2_DMA_BURST,
Bruce Allaned5c2b02010-11-24 06:01:25 +00002057 .pba = 32,
Alexander Duycka825e002009-10-02 12:30:42 +00002058 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allan4662e822008-08-26 18:37:06 -07002059 .get_variants = e1000_get_variants_82571,
2060 .mac_ops = &e82571_mac_ops,
2061 .phy_ops = &e82_phy_ops_bm,
2062 .nvm_ops = &e82571_nvm_ops,
2063};
2064
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00002065const struct e1000_info e1000_82583_info = {
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00002066 .mac = e1000_82583,
2067 .flags = FLAG_HAS_HW_VLAN_FILTER
2068 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00002069 | FLAG_HAS_HW_TIMESTAMP
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00002070 | FLAG_APME_IN_CTRL3
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00002071 | FLAG_HAS_SMART_POWER_DOWN
2072 | FLAG_HAS_AMT
Carolyn Wybornya3d72d52011-07-12 16:10:11 +00002073 | FLAG_HAS_JUMBO_FRAMES
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00002074 | FLAG_HAS_CTRLEXT_ON_LOAD,
Bruce Allan7f99ae62011-07-22 06:21:35 +00002075 .flags2 = FLAG2_DISABLE_ASPM_L0S
2076 | FLAG2_NO_DISABLE_RX,
Bruce Allaned5c2b02010-11-24 06:01:25 +00002077 .pba = 32,
Carolyn Wybornya3d72d52011-07-12 16:10:11 +00002078 .max_hw_frame_size = DEFAULT_JUMBO,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00002079 .get_variants = e1000_get_variants_82571,
2080 .mac_ops = &e82571_mac_ops,
2081 .phy_ops = &e82_phy_ops_bm,
2082 .nvm_ops = &e82571_nvm_ops,
2083};
2084