blob: 9057d10a698a60fed35d87e0b0f5b2e67a92462b [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Akeem G. Abodunrin4b9ea462013-01-08 18:31:12 +00004 Copyright(c) 2007-2013 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28/* e1000_82575
29 * e1000_82576
30 */
31
Joe Perches82bbcde2011-10-21 20:04:09 +000032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Auke Kok9d5c8242008-01-24 02:22:38 -080034#include <linux/types.h>
Alexander Duyck2d064c02008-07-08 15:10:12 -070035#include <linux/if_ether.h>
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +000036#include <linux/i2c.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080037
38#include "e1000_mac.h"
39#include "e1000_82575.h"
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000040#include "e1000_i210.h"
Auke Kok9d5c8242008-01-24 02:22:38 -080041
42static s32 igb_get_invariants_82575(struct e1000_hw *);
43static s32 igb_acquire_phy_82575(struct e1000_hw *);
44static void igb_release_phy_82575(struct e1000_hw *);
45static s32 igb_acquire_nvm_82575(struct e1000_hw *);
46static void igb_release_nvm_82575(struct e1000_hw *);
47static s32 igb_check_for_link_82575(struct e1000_hw *);
48static s32 igb_get_cfg_done_82575(struct e1000_hw *);
49static s32 igb_init_hw_82575(struct e1000_hw *);
50static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
51static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000052static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
53static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080054static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000055static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080056static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
Carolyn Wybornyda02cde2012-03-04 03:26:26 +000057static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
58static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
Auke Kok9d5c8242008-01-24 02:22:38 -080059static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000060static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080061static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
62static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
63static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080064static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
65 u16 *);
66static s32 igb_get_phy_id_82575(struct e1000_hw *);
67static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
68static bool igb_sgmii_active_82575(struct e1000_hw *);
69static s32 igb_reset_init_script_82575(struct e1000_hw *);
70static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000071static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Alexander Duyck99870a72010-08-03 11:50:08 +000072static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080073static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
74static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080075static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
76static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000077static const u16 e1000_82580_rxpbs_table[] =
78 { 36, 72, 144, 1, 2, 4, 8, 16,
79 35, 70, 140 };
80#define E1000_82580_RXPBS_TABLE_SIZE \
81 (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
82
Nick Nunley4085f742010-07-26 13:15:06 +000083/**
84 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
85 * @hw: pointer to the HW structure
86 *
87 * Called to determine if the I2C pins are being used for I2C or as an
88 * external MDIO interface since the two options are mutually exclusive.
89 **/
90static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
91{
92 u32 reg = 0;
93 bool ext_mdio = false;
94
95 switch (hw->mac.type) {
96 case e1000_82575:
97 case e1000_82576:
98 reg = rd32(E1000_MDIC);
99 ext_mdio = !!(reg & E1000_MDIC_DEST);
100 break;
101 case e1000_82580:
102 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000103 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000104 case e1000_i210:
105 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000106 reg = rd32(E1000_MDICNFG);
107 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
108 break;
109 default:
110 break;
111 }
112 return ext_mdio;
113}
114
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000115/**
116 * igb_init_phy_params_82575 - Init PHY func ptrs.
117 * @hw: pointer to the HW structure
118 **/
119static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
120{
121 struct e1000_phy_info *phy = &hw->phy;
122 s32 ret_val = 0;
123 u32 ctrl_ext;
124
125 if (hw->phy.media_type != e1000_media_type_copper) {
126 phy->type = e1000_phy_none;
127 goto out;
128 }
129
130 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
131 phy->reset_delay_us = 100;
132
133 ctrl_ext = rd32(E1000_CTRL_EXT);
134
135 if (igb_sgmii_active_82575(hw)) {
136 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
137 ctrl_ext |= E1000_CTRL_I2C_ENA;
138 } else {
139 phy->ops.reset = igb_phy_hw_reset;
140 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
141 }
142
143 wr32(E1000_CTRL_EXT, ctrl_ext);
144 igb_reset_mdicnfg_82580(hw);
145
146 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
147 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
148 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
149 } else {
150 switch (hw->mac.type) {
151 case e1000_82580:
152 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000153 case e1000_i354:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000154 phy->ops.read_reg = igb_read_phy_reg_82580;
155 phy->ops.write_reg = igb_write_phy_reg_82580;
156 break;
157 case e1000_i210:
158 case e1000_i211:
159 phy->ops.read_reg = igb_read_phy_reg_gs40g;
160 phy->ops.write_reg = igb_write_phy_reg_gs40g;
161 break;
162 default:
163 phy->ops.read_reg = igb_read_phy_reg_igp;
164 phy->ops.write_reg = igb_write_phy_reg_igp;
165 }
166 }
167
168 /* set lan id */
169 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
170 E1000_STATUS_FUNC_SHIFT;
171
172 /* Set phy->phy_addr and phy->id. */
173 ret_val = igb_get_phy_id_82575(hw);
174 if (ret_val)
175 return ret_val;
176
177 /* Verify phy id and set remaining function pointers */
178 switch (phy->id) {
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000179 case M88E1545_E_PHY_ID:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000180 case I347AT4_E_PHY_ID:
181 case M88E1112_E_PHY_ID:
182 case M88E1111_I_PHY_ID:
183 phy->type = e1000_phy_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000184 phy->ops.check_polarity = igb_check_polarity_m88;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000185 phy->ops.get_phy_info = igb_get_phy_info_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000186 if (phy->id != M88E1111_I_PHY_ID)
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000187 phy->ops.get_cable_length =
188 igb_get_cable_length_m88_gen2;
189 else
190 phy->ops.get_cable_length = igb_get_cable_length_m88;
191 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
192 break;
193 case IGP03E1000_E_PHY_ID:
194 phy->type = e1000_phy_igp_3;
195 phy->ops.get_phy_info = igb_get_phy_info_igp;
196 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
197 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
198 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
199 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
200 break;
201 case I82580_I_PHY_ID:
202 case I350_I_PHY_ID:
203 phy->type = e1000_phy_82580;
204 phy->ops.force_speed_duplex =
205 igb_phy_force_speed_duplex_82580;
206 phy->ops.get_cable_length = igb_get_cable_length_82580;
207 phy->ops.get_phy_info = igb_get_phy_info_82580;
208 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
209 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
210 break;
211 case I210_I_PHY_ID:
212 phy->type = e1000_phy_i210;
213 phy->ops.check_polarity = igb_check_polarity_m88;
214 phy->ops.get_phy_info = igb_get_phy_info_m88;
215 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
216 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
217 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
218 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
219 break;
220 default:
221 ret_val = -E1000_ERR_PHY;
222 goto out;
223 }
224
225out:
226 return ret_val;
227}
228
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000229/**
230 * igb_init_nvm_params_82575 - Init NVM func ptrs.
231 * @hw: pointer to the HW structure
232 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000233static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000234{
235 struct e1000_nvm_info *nvm = &hw->nvm;
236 u32 eecd = rd32(E1000_EECD);
237 u16 size;
238
239 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
240 E1000_EECD_SIZE_EX_SHIFT);
241 /* Added to a constant, "size" becomes the left-shift value
242 * for setting word_size.
243 */
244 size += NVM_WORD_SIZE_BASE_SHIFT;
245
246 /* Just in case size is out of range, cap it to the largest
247 * EEPROM size supported
248 */
249 if (size > 15)
250 size = 15;
251
252 nvm->word_size = 1 << size;
253 if (hw->mac.type < e1000_i210) {
254 nvm->opcode_bits = 8;
255 nvm->delay_usec = 1;
256
257 switch (nvm->override) {
258 case e1000_nvm_override_spi_large:
259 nvm->page_size = 32;
260 nvm->address_bits = 16;
261 break;
262 case e1000_nvm_override_spi_small:
263 nvm->page_size = 8;
264 nvm->address_bits = 8;
265 break;
266 default:
267 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
268 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
269 16 : 8;
270 break;
271 }
272 if (nvm->word_size == (1 << 15))
273 nvm->page_size = 128;
274
275 nvm->type = e1000_nvm_eeprom_spi;
276 } else {
277 nvm->type = e1000_nvm_flash_hw;
278 }
279
280 /* NVM Function Pointers */
281 switch (hw->mac.type) {
282 case e1000_82580:
283 nvm->ops.validate = igb_validate_nvm_checksum_82580;
284 nvm->ops.update = igb_update_nvm_checksum_82580;
285 nvm->ops.acquire = igb_acquire_nvm_82575;
286 nvm->ops.release = igb_release_nvm_82575;
287 if (nvm->word_size < (1 << 15))
288 nvm->ops.read = igb_read_nvm_eerd;
289 else
290 nvm->ops.read = igb_read_nvm_spi;
291 nvm->ops.write = igb_write_nvm_spi;
292 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000293 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000294 case e1000_i350:
295 nvm->ops.validate = igb_validate_nvm_checksum_i350;
296 nvm->ops.update = igb_update_nvm_checksum_i350;
297 nvm->ops.acquire = igb_acquire_nvm_82575;
298 nvm->ops.release = igb_release_nvm_82575;
299 if (nvm->word_size < (1 << 15))
300 nvm->ops.read = igb_read_nvm_eerd;
301 else
302 nvm->ops.read = igb_read_nvm_spi;
303 nvm->ops.write = igb_write_nvm_spi;
304 break;
305 case e1000_i210:
306 nvm->ops.validate = igb_validate_nvm_checksum_i210;
307 nvm->ops.update = igb_update_nvm_checksum_i210;
308 nvm->ops.acquire = igb_acquire_nvm_i210;
309 nvm->ops.release = igb_release_nvm_i210;
310 nvm->ops.read = igb_read_nvm_srrd_i210;
311 nvm->ops.write = igb_write_nvm_srwr_i210;
312 nvm->ops.valid_led_default = igb_valid_led_default_i210;
313 break;
314 case e1000_i211:
315 nvm->ops.acquire = igb_acquire_nvm_i210;
316 nvm->ops.release = igb_release_nvm_i210;
317 nvm->ops.read = igb_read_nvm_i211;
318 nvm->ops.valid_led_default = igb_valid_led_default_i210;
319 nvm->ops.validate = NULL;
320 nvm->ops.update = NULL;
321 nvm->ops.write = NULL;
322 break;
323 default:
324 nvm->ops.validate = igb_validate_nvm_checksum;
325 nvm->ops.update = igb_update_nvm_checksum;
326 nvm->ops.acquire = igb_acquire_nvm_82575;
327 nvm->ops.release = igb_release_nvm_82575;
328 if (nvm->word_size < (1 << 15))
329 nvm->ops.read = igb_read_nvm_eerd;
330 else
331 nvm->ops.read = igb_read_nvm_spi;
332 nvm->ops.write = igb_write_nvm_spi;
333 break;
334 }
335
336 return 0;
337}
338
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000339/**
340 * igb_init_mac_params_82575 - Init MAC func ptrs.
341 * @hw: pointer to the HW structure
342 **/
343static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
344{
345 struct e1000_mac_info *mac = &hw->mac;
346 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
347
348 /* Set mta register count */
349 mac->mta_reg_count = 128;
350 /* Set rar entry count */
351 switch (mac->type) {
352 case e1000_82576:
353 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
354 break;
355 case e1000_82580:
356 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
357 break;
358 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000359 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000360 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
361 break;
362 default:
363 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
364 break;
365 }
366 /* reset */
367 if (mac->type >= e1000_82580)
368 mac->ops.reset_hw = igb_reset_hw_82580;
369 else
370 mac->ops.reset_hw = igb_reset_hw_82575;
371
372 if (mac->type >= e1000_i210) {
373 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
374 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
375
376 } else {
377 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
378 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
379 }
380
381 /* Set if part includes ASF firmware */
382 mac->asf_firmware_present = true;
383 /* Set if manageability features are enabled. */
384 mac->arc_subsystem_valid =
385 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
386 ? true : false;
387 /* enable EEE on i350 parts and later parts */
388 if (mac->type >= e1000_i350)
389 dev_spec->eee_disable = false;
390 else
391 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000392 /* Allow a single clear of the SW semaphore on I210 and newer */
393 if (mac->type >= e1000_i210)
394 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000395 /* physical interface link setup */
396 mac->ops.setup_physical_interface =
397 (hw->phy.media_type == e1000_media_type_copper)
398 ? igb_setup_copper_link_82575
399 : igb_setup_serdes_link_82575;
400
401 return 0;
402}
403
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000404/**
405 * igb_set_sfp_media_type_82575 - derives SFP module media type.
406 * @hw: pointer to the HW structure
407 *
408 * The media type is chosen based on SFP module.
409 * compatibility flags retrieved from SFP ID EEPROM.
410 **/
411static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
412{
413 s32 ret_val = E1000_ERR_CONFIG;
414 u32 ctrl_ext = 0;
415 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
416 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
417 u8 tranceiver_type = 0;
418 s32 timeout = 3;
419
420 /* Turn I2C interface ON and power on sfp cage */
421 ctrl_ext = rd32(E1000_CTRL_EXT);
422 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
423 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
424
425 wrfl();
426
427 /* Read SFP module data */
428 while (timeout) {
429 ret_val = igb_read_sfp_data_byte(hw,
430 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
431 &tranceiver_type);
432 if (ret_val == 0)
433 break;
434 msleep(100);
435 timeout--;
436 }
437 if (ret_val != 0)
438 goto out;
439
440 ret_val = igb_read_sfp_data_byte(hw,
441 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
442 (u8 *)eth_flags);
443 if (ret_val != 0)
444 goto out;
445
446 /* Check if there is some SFP module plugged and powered */
447 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
448 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
449 dev_spec->module_plugged = true;
450 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
451 hw->phy.media_type = e1000_media_type_internal_serdes;
452 } else if (eth_flags->e100_base_fx) {
453 dev_spec->sgmii_active = true;
454 hw->phy.media_type = e1000_media_type_internal_serdes;
455 } else if (eth_flags->e1000_base_t) {
456 dev_spec->sgmii_active = true;
457 hw->phy.media_type = e1000_media_type_copper;
458 } else {
459 hw->phy.media_type = e1000_media_type_unknown;
460 hw_dbg("PHY module has not been recognized\n");
461 goto out;
462 }
463 } else {
464 hw->phy.media_type = e1000_media_type_unknown;
465 }
466 ret_val = 0;
467out:
468 /* Restore I2C interface setting */
469 wr32(E1000_CTRL_EXT, ctrl_ext);
470 return ret_val;
471}
472
Auke Kok9d5c8242008-01-24 02:22:38 -0800473static s32 igb_get_invariants_82575(struct e1000_hw *hw)
474{
Auke Kok9d5c8242008-01-24 02:22:38 -0800475 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +0000476 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800477 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800478 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000479 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800480
481 switch (hw->device_id) {
482 case E1000_DEV_ID_82575EB_COPPER:
483 case E1000_DEV_ID_82575EB_FIBER_SERDES:
484 case E1000_DEV_ID_82575GB_QUAD_COPPER:
485 mac->type = e1000_82575;
486 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700487 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000488 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000489 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700490 case E1000_DEV_ID_82576_FIBER:
491 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000492 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000493 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000494 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700495 mac->type = e1000_82576;
496 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000497 case E1000_DEV_ID_82580_COPPER:
498 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000499 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000500 case E1000_DEV_ID_82580_SERDES:
501 case E1000_DEV_ID_82580_SGMII:
502 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000503 case E1000_DEV_ID_DH89XXCC_SGMII:
504 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000505 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
506 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000507 mac->type = e1000_82580;
508 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000509 case E1000_DEV_ID_I350_COPPER:
510 case E1000_DEV_ID_I350_FIBER:
511 case E1000_DEV_ID_I350_SERDES:
512 case E1000_DEV_ID_I350_SGMII:
513 mac->type = e1000_i350;
514 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000515 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000516 case E1000_DEV_ID_I210_FIBER:
517 case E1000_DEV_ID_I210_SERDES:
518 case E1000_DEV_ID_I210_SGMII:
519 mac->type = e1000_i210;
520 break;
521 case E1000_DEV_ID_I211_COPPER:
522 mac->type = e1000_i211;
523 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000524 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
525 case E1000_DEV_ID_I354_SGMII:
526 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
527 mac->type = e1000_i354;
528 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800529 default:
530 return -E1000_ERR_MAC_INIT;
531 break;
532 }
533
Auke Kok9d5c8242008-01-24 02:22:38 -0800534 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000535 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800536 * based on the EEPROM. We cannot rely upon device ID. There
537 * is no distinguishable difference between fiber and internal
538 * SerDes mode on the 82575. There can be an external PHY attached
539 * on the SGMII interface. For this, we'll set sgmii_active to true.
540 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000541 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800542 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000543 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800544
545 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000546
547 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
548 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000549 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000550 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000551 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000552 case E1000_CTRL_EXT_LINK_MODE_SGMII:
553 /* Get phy control interface type set (MDIO vs. I2C)*/
554 if (igb_sgmii_uses_mdio_82575(hw)) {
555 hw->phy.media_type = e1000_media_type_copper;
556 dev_spec->sgmii_active = true;
557 break;
558 }
559 /* fall through for I2C based SGMII */
560 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
561 /* read media type from SFP EEPROM */
562 ret_val = igb_set_sfp_media_type_82575(hw);
563 if ((ret_val != 0) ||
564 (hw->phy.media_type == e1000_media_type_unknown)) {
565 /* If media type was not identified then return media
566 * type defined by the CTRL_EXT settings.
567 */
568 hw->phy.media_type = e1000_media_type_internal_serdes;
569
570 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
571 hw->phy.media_type = e1000_media_type_copper;
572 dev_spec->sgmii_active = true;
573 }
574
575 break;
576 }
577
578 /* do not change link mode for 100BaseFX */
579 if (dev_spec->eth_flags.e100_base_fx)
580 break;
581
582 /* change current link mode setting */
583 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
584
585 if (hw->phy.media_type == e1000_media_type_copper)
586 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
587 else
588 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
589
590 wr32(E1000_CTRL_EXT, ctrl_ext);
591
592 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000593 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000594 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800595 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000596
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000597 /* mac initialization and operations */
598 ret_val = igb_init_mac_params_82575(hw);
599 if (ret_val)
600 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800601
602 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000603 ret_val = igb_init_nvm_params_82575(hw);
604 if (ret_val)
605 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800606
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000607 /* if part supports SR-IOV then initialize mailbox parameters */
608 switch (mac->type) {
609 case e1000_82576:
610 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000611 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000612 break;
613 default:
614 break;
615 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000616
Auke Kok9d5c8242008-01-24 02:22:38 -0800617 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000618 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800619
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000620out:
621 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800622}
623
624/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700625 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800626 * @hw: pointer to the HW structure
627 *
628 * Acquire access rights to the correct PHY. This is a
629 * function pointer entry point called by the api module.
630 **/
631static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
632{
Alexander Duyck008c3422009-10-05 06:32:07 +0000633 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800634
Alexander Duyck008c3422009-10-05 06:32:07 +0000635 if (hw->bus.func == E1000_FUNC_1)
636 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000637 else if (hw->bus.func == E1000_FUNC_2)
638 mask = E1000_SWFW_PHY2_SM;
639 else if (hw->bus.func == E1000_FUNC_3)
640 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800641
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000642 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800643}
644
645/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700646 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800647 * @hw: pointer to the HW structure
648 *
649 * A wrapper to release access rights to the correct PHY. This is a
650 * function pointer entry point called by the api module.
651 **/
652static void igb_release_phy_82575(struct e1000_hw *hw)
653{
Alexander Duyck008c3422009-10-05 06:32:07 +0000654 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800655
Alexander Duyck008c3422009-10-05 06:32:07 +0000656 if (hw->bus.func == E1000_FUNC_1)
657 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000658 else if (hw->bus.func == E1000_FUNC_2)
659 mask = E1000_SWFW_PHY2_SM;
660 else if (hw->bus.func == E1000_FUNC_3)
661 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000662
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000663 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800664}
665
666/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700667 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800668 * @hw: pointer to the HW structure
669 * @offset: register offset to be read
670 * @data: pointer to the read data
671 *
672 * Reads the PHY register at offset using the serial gigabit media independent
673 * interface and stores the retrieved information in data.
674 **/
675static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
676 u16 *data)
677{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000678 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800679
680 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700681 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000682 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800683 }
684
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000685 ret_val = hw->phy.ops.acquire(hw);
686 if (ret_val)
687 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800688
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000689 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800690
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000691 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800692
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000693out:
694 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800695}
696
697/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700698 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800699 * @hw: pointer to the HW structure
700 * @offset: register offset to write to
701 * @data: data to write at register offset
702 *
703 * Writes the data to PHY register at the offset using the serial gigabit
704 * media independent interface.
705 **/
706static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
707 u16 data)
708{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000709 s32 ret_val = -E1000_ERR_PARAM;
710
Auke Kok9d5c8242008-01-24 02:22:38 -0800711
712 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700713 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000714 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800715 }
716
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000717 ret_val = hw->phy.ops.acquire(hw);
718 if (ret_val)
719 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800720
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000721 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800722
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000723 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800724
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000725out:
726 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800727}
728
729/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700730 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800731 * @hw: pointer to the HW structure
732 *
Auke Kok652fff32008-06-27 11:00:18 -0700733 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800734 * sgmi interface.
735 **/
736static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
737{
738 struct e1000_phy_info *phy = &hw->phy;
739 s32 ret_val = 0;
740 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000741 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000742 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800743
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000744 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800745 * we find one that works. For non-SGMII PHYs
746 * (e.g. integrated copper PHYs), an address of 1 should
747 * work. The result of this function should mean phy->phy_addr
748 * and phy->id are set correctly.
749 */
750 if (!(igb_sgmii_active_82575(hw))) {
751 phy->addr = 1;
752 ret_val = igb_get_phy_id(hw);
753 goto out;
754 }
755
Nick Nunley4085f742010-07-26 13:15:06 +0000756 if (igb_sgmii_uses_mdio_82575(hw)) {
757 switch (hw->mac.type) {
758 case e1000_82575:
759 case e1000_82576:
760 mdic = rd32(E1000_MDIC);
761 mdic &= E1000_MDIC_PHY_MASK;
762 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
763 break;
764 case e1000_82580:
765 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000766 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000767 case e1000_i210:
768 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000769 mdic = rd32(E1000_MDICNFG);
770 mdic &= E1000_MDICNFG_PHY_MASK;
771 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
772 break;
773 default:
774 ret_val = -E1000_ERR_PHY;
775 goto out;
776 break;
777 }
778 ret_val = igb_get_phy_id(hw);
779 goto out;
780 }
781
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000782 /* Power on sgmii phy if it is disabled */
783 ctrl_ext = rd32(E1000_CTRL_EXT);
784 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
785 wrfl();
786 msleep(300);
787
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000788 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800789 * Therefore, we need to test 1-7
790 */
791 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
792 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
793 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700794 hw_dbg("Vendor ID 0x%08X read at address %u\n",
795 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000796 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800797 * the only supported SGMII PHY product.
798 */
799 if (phy_id == M88_VENDOR)
800 break;
801 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700802 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800803 }
804 }
805
806 /* A valid PHY type couldn't be found. */
807 if (phy->addr == 8) {
808 phy->addr = 0;
809 ret_val = -E1000_ERR_PHY;
810 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000811 } else {
812 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800813 }
814
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000815 /* restore previous sfp cage power state */
816 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800817
818out:
819 return ret_val;
820}
821
822/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700823 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800824 * @hw: pointer to the HW structure
825 *
826 * Resets the PHY using the serial gigabit media independent interface.
827 **/
828static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
829{
830 s32 ret_val;
831
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000832 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800833 * available to us at this time.
834 */
835
Auke Kok652fff32008-06-27 11:00:18 -0700836 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800837
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000838 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800839 * to work on SGMII. No further documentation is given.
840 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000841 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800842 if (ret_val)
843 goto out;
844
845 ret_val = igb_phy_sw_reset(hw);
846
847out:
848 return ret_val;
849}
850
851/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700852 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800853 * @hw: pointer to the HW structure
854 * @active: true to enable LPLU, false to disable
855 *
856 * Sets the LPLU D0 state according to the active flag. When
857 * activating LPLU this function also disables smart speed
858 * and vice versa. LPLU will not be activated unless the
859 * device autonegotiation advertisement meets standards of
860 * either 10 or 10/100 or 10/100/1000 at all duplexes.
861 * This is a function pointer entry point only called by
862 * PHY setup routines.
863 **/
864static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
865{
866 struct e1000_phy_info *phy = &hw->phy;
867 s32 ret_val;
868 u16 data;
869
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000870 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800871 if (ret_val)
872 goto out;
873
874 if (active) {
875 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000876 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700877 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800878 if (ret_val)
879 goto out;
880
881 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000882 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700883 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800884 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000885 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700886 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 if (ret_val)
888 goto out;
889 } else {
890 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000891 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700892 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000893 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -0800894 * during Dx states where the power conservation is most
895 * important. During driver activity we should enable
896 * SmartSpeed, so performance is maintained.
897 */
898 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000899 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700900 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800901 if (ret_val)
902 goto out;
903
904 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000905 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700906 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800907 if (ret_val)
908 goto out;
909 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000910 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700911 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800912 if (ret_val)
913 goto out;
914
915 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000916 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700917 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800918 if (ret_val)
919 goto out;
920 }
921 }
922
923out:
924 return ret_val;
925}
926
927/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000928 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
929 * @hw: pointer to the HW structure
930 * @active: true to enable LPLU, false to disable
931 *
932 * Sets the LPLU D0 state according to the active flag. When
933 * activating LPLU this function also disables smart speed
934 * and vice versa. LPLU will not be activated unless the
935 * device autonegotiation advertisement meets standards of
936 * either 10 or 10/100 or 10/100/1000 at all duplexes.
937 * This is a function pointer entry point only called by
938 * PHY setup routines.
939 **/
940static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
941{
942 struct e1000_phy_info *phy = &hw->phy;
943 s32 ret_val = 0;
944 u16 data;
945
946 data = rd32(E1000_82580_PHY_POWER_MGMT);
947
948 if (active) {
949 data |= E1000_82580_PM_D0_LPLU;
950
951 /* When LPLU is enabled, we should disable SmartSpeed */
952 data &= ~E1000_82580_PM_SPD;
953 } else {
954 data &= ~E1000_82580_PM_D0_LPLU;
955
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000956 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000957 * during Dx states where the power conservation is most
958 * important. During driver activity we should enable
959 * SmartSpeed, so performance is maintained.
960 */
961 if (phy->smart_speed == e1000_smart_speed_on)
962 data |= E1000_82580_PM_SPD;
963 else if (phy->smart_speed == e1000_smart_speed_off)
964 data &= ~E1000_82580_PM_SPD; }
965
966 wr32(E1000_82580_PHY_POWER_MGMT, data);
967 return ret_val;
968}
969
970/**
971 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
972 * @hw: pointer to the HW structure
973 * @active: boolean used to enable/disable lplu
974 *
975 * Success returns 0, Failure returns 1
976 *
977 * The low power link up (lplu) state is set to the power management level D3
978 * and SmartSpeed is disabled when active is true, else clear lplu for D3
979 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
980 * is used during Dx states where the power conservation is most important.
981 * During driver activity, SmartSpeed should be enabled so performance is
982 * maintained.
983 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000984static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000985{
986 struct e1000_phy_info *phy = &hw->phy;
987 s32 ret_val = 0;
988 u16 data;
989
990 data = rd32(E1000_82580_PHY_POWER_MGMT);
991
992 if (!active) {
993 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000994 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000995 * during Dx states where the power conservation is most
996 * important. During driver activity we should enable
997 * SmartSpeed, so performance is maintained.
998 */
999 if (phy->smart_speed == e1000_smart_speed_on)
1000 data |= E1000_82580_PM_SPD;
1001 else if (phy->smart_speed == e1000_smart_speed_off)
1002 data &= ~E1000_82580_PM_SPD;
1003 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1004 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1005 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1006 data |= E1000_82580_PM_D3_LPLU;
1007 /* When LPLU is enabled, we should disable SmartSpeed */
1008 data &= ~E1000_82580_PM_SPD;
1009 }
1010
1011 wr32(E1000_82580_PHY_POWER_MGMT, data);
1012 return ret_val;
1013}
1014
1015/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001016 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001017 * @hw: pointer to the HW structure
1018 *
Auke Kok652fff32008-06-27 11:00:18 -07001019 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001020 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1021 * Return successful if access grant bit set, else clear the request for
1022 * EEPROM access and return -E1000_ERR_NVM (-1).
1023 **/
1024static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1025{
1026 s32 ret_val;
1027
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001028 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001029 if (ret_val)
1030 goto out;
1031
1032 ret_val = igb_acquire_nvm(hw);
1033
1034 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001035 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001036
1037out:
1038 return ret_val;
1039}
1040
1041/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001042 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001043 * @hw: pointer to the HW structure
1044 *
1045 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1046 * then release the semaphores acquired.
1047 **/
1048static void igb_release_nvm_82575(struct e1000_hw *hw)
1049{
1050 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001051 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001052}
1053
1054/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001055 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001056 * @hw: pointer to the HW structure
1057 * @mask: specifies which semaphore to acquire
1058 *
1059 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1060 * will also specify which port we're acquiring the lock for.
1061 **/
1062static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1063{
1064 u32 swfw_sync;
1065 u32 swmask = mask;
1066 u32 fwmask = mask << 16;
1067 s32 ret_val = 0;
1068 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
1069
1070 while (i < timeout) {
1071 if (igb_get_hw_semaphore(hw)) {
1072 ret_val = -E1000_ERR_SWFW_SYNC;
1073 goto out;
1074 }
1075
1076 swfw_sync = rd32(E1000_SW_FW_SYNC);
1077 if (!(swfw_sync & (fwmask | swmask)))
1078 break;
1079
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001080 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001081 * or other software thread using resource (swmask)
1082 */
1083 igb_put_hw_semaphore(hw);
1084 mdelay(5);
1085 i++;
1086 }
1087
1088 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001089 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001090 ret_val = -E1000_ERR_SWFW_SYNC;
1091 goto out;
1092 }
1093
1094 swfw_sync |= swmask;
1095 wr32(E1000_SW_FW_SYNC, swfw_sync);
1096
1097 igb_put_hw_semaphore(hw);
1098
1099out:
1100 return ret_val;
1101}
1102
1103/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001104 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001105 * @hw: pointer to the HW structure
1106 * @mask: specifies which semaphore to acquire
1107 *
1108 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1109 * will also specify which port we're releasing the lock for.
1110 **/
1111static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1112{
1113 u32 swfw_sync;
1114
1115 while (igb_get_hw_semaphore(hw) != 0);
1116 /* Empty */
1117
1118 swfw_sync = rd32(E1000_SW_FW_SYNC);
1119 swfw_sync &= ~mask;
1120 wr32(E1000_SW_FW_SYNC, swfw_sync);
1121
1122 igb_put_hw_semaphore(hw);
1123}
1124
1125/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001126 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001127 * @hw: pointer to the HW structure
1128 *
1129 * Read the management control register for the config done bit for
1130 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1131 * to read the config done bit, so an error is *ONLY* logged and returns
1132 * 0. If we were to return with error, EEPROM-less silicon
1133 * would not be able to be reset or change link.
1134 **/
1135static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1136{
1137 s32 timeout = PHY_CFG_TIMEOUT;
1138 s32 ret_val = 0;
1139 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1140
1141 if (hw->bus.func == 1)
1142 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001143 else if (hw->bus.func == E1000_FUNC_2)
1144 mask = E1000_NVM_CFG_DONE_PORT_2;
1145 else if (hw->bus.func == E1000_FUNC_3)
1146 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001147
1148 while (timeout) {
1149 if (rd32(E1000_EEMNGCTL) & mask)
1150 break;
1151 msleep(1);
1152 timeout--;
1153 }
1154 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001155 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001156
1157 /* If EEPROM is not marked present, init the PHY manually */
1158 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1159 (hw->phy.type == e1000_phy_igp_3))
1160 igb_phy_init_script_igp3(hw);
1161
1162 return ret_val;
1163}
1164
1165/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001166 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001167 * @hw: pointer to the HW structure
1168 *
1169 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1170 * use the generic interface for determining link.
1171 **/
1172static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1173{
1174 s32 ret_val;
1175 u16 speed, duplex;
1176
Alexander Duyck70d92f82009-10-05 06:31:47 +00001177 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001178 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001179 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001180 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001181 * not. If we have link clear the flag so that we do not
1182 * continue to check for link.
1183 */
1184 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001185
1186 /* Configure Flow Control now that Auto-Neg has completed.
1187 * First, we need to restore the desired flow control
1188 * settings because we may have had to re-autoneg with a
1189 * different link partner.
1190 */
1191 ret_val = igb_config_fc_after_link_up(hw);
1192 if (ret_val)
1193 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001194 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001196 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001197
1198 return ret_val;
1199}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001200
Auke Kok9d5c8242008-01-24 02:22:38 -08001201/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001202 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1203 * @hw: pointer to the HW structure
1204 **/
1205void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1206{
1207 u32 reg;
1208
1209
1210 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1211 !igb_sgmii_active_82575(hw))
1212 return;
1213
1214 /* Enable PCS to turn on link */
1215 reg = rd32(E1000_PCS_CFG0);
1216 reg |= E1000_PCS_CFG_PCS_EN;
1217 wr32(E1000_PCS_CFG0, reg);
1218
1219 /* Power up the laser */
1220 reg = rd32(E1000_CTRL_EXT);
1221 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1222 wr32(E1000_CTRL_EXT, reg);
1223
1224 /* flush the write to verify completion */
1225 wrfl();
1226 msleep(1);
1227}
1228
1229/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001230 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001231 * @hw: pointer to the HW structure
1232 * @speed: stores the current speed
1233 * @duplex: stores the current duplex
1234 *
Auke Kok652fff32008-06-27 11:00:18 -07001235 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001236 * duplex, then store the values in the pointers provided.
1237 **/
1238static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1239 u16 *duplex)
1240{
1241 struct e1000_mac_info *mac = &hw->mac;
1242 u32 pcs;
1243
1244 /* Set up defaults for the return values of this function */
1245 mac->serdes_has_link = false;
1246 *speed = 0;
1247 *duplex = 0;
1248
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001249 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001250 * the status register is not accurate. The PCS status register is
1251 * used instead.
1252 */
1253 pcs = rd32(E1000_PCS_LSTAT);
1254
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001255 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001256 * gets set once both sides sync up and agree upon link. Stable link
1257 * can be determined by checking for both link up and link sync ok
1258 */
1259 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1260 mac->serdes_has_link = true;
1261
1262 /* Detect and store PCS speed */
1263 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
1264 *speed = SPEED_1000;
1265 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
1266 *speed = SPEED_100;
1267 } else {
1268 *speed = SPEED_10;
1269 }
1270
1271 /* Detect and store PCS duplex */
1272 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
1273 *duplex = FULL_DUPLEX;
1274 } else {
1275 *duplex = HALF_DUPLEX;
1276 }
1277 }
1278
1279 return 0;
1280}
1281
1282/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001283 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001284 * @hw: pointer to the HW structure
1285 *
1286 * In the case of fiber serdes, shut down optics and PCS on driver unload
1287 * when management pass thru is not enabled.
1288 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001289void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001290{
1291 u32 reg;
1292
Nick Nunley53c992f2010-02-17 01:01:40 +00001293 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001294 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001295 return;
1296
Nick Nunley53c992f2010-02-17 01:01:40 +00001297 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001298 /* Disable PCS to turn off link */
1299 reg = rd32(E1000_PCS_CFG0);
1300 reg &= ~E1000_PCS_CFG_PCS_EN;
1301 wr32(E1000_PCS_CFG0, reg);
1302
1303 /* shutdown the laser */
1304 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001305 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001306 wr32(E1000_CTRL_EXT, reg);
1307
1308 /* flush the write to verify completion */
1309 wrfl();
1310 msleep(1);
1311 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001312}
1313
1314/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001315 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001316 * @hw: pointer to the HW structure
1317 *
1318 * This resets the hardware into a known state. This is a
1319 * function pointer entry point called by the api module.
1320 **/
1321static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1322{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001323 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 s32 ret_val;
1325
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001326 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001327 * on the last TLP read/write transaction when MAC is reset.
1328 */
1329 ret_val = igb_disable_pcie_master(hw);
1330 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001331 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001332
Alexander Duyck009bc062009-07-23 18:08:35 +00001333 /* set the completion timeout for interface */
1334 ret_val = igb_set_pcie_completion_timeout(hw);
1335 if (ret_val) {
1336 hw_dbg("PCI-E Set completion timeout has failed.\n");
1337 }
1338
Auke Kok652fff32008-06-27 11:00:18 -07001339 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001340 wr32(E1000_IMC, 0xffffffff);
1341
1342 wr32(E1000_RCTL, 0);
1343 wr32(E1000_TCTL, E1000_TCTL_PSP);
1344 wrfl();
1345
1346 msleep(10);
1347
1348 ctrl = rd32(E1000_CTRL);
1349
Auke Kok652fff32008-06-27 11:00:18 -07001350 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001351 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1352
1353 ret_val = igb_get_auto_rd_done(hw);
1354 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001355 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001356 * return with an error. This can happen in situations
1357 * where there is no eeprom and prevents getting link.
1358 */
Auke Kok652fff32008-06-27 11:00:18 -07001359 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001360 }
1361
1362 /* If EEPROM is not present, run manual init scripts */
1363 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1364 igb_reset_init_script_82575(hw);
1365
1366 /* Clear any pending interrupt events. */
1367 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001368 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001369
Alexander Duyck5ac16652009-07-23 18:09:12 +00001370 /* Install any alternate MAC address into RAR0 */
1371 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001372
1373 return ret_val;
1374}
1375
1376/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001377 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001378 * @hw: pointer to the HW structure
1379 *
1380 * This inits the hardware readying it for operation.
1381 **/
1382static s32 igb_init_hw_82575(struct e1000_hw *hw)
1383{
1384 struct e1000_mac_info *mac = &hw->mac;
1385 s32 ret_val;
1386 u16 i, rar_count = mac->rar_entry_count;
1387
1388 /* Initialize identification LED */
1389 ret_val = igb_id_led_init(hw);
1390 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001391 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001392 /* This is not fatal and we should not stop init due to this */
1393 }
1394
1395 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001396 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001397 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001398 igb_clear_vfta_i350(hw);
1399 else
1400 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001401
1402 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001403 igb_init_rx_addrs(hw, rar_count);
1404
Auke Kok9d5c8242008-01-24 02:22:38 -08001405 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001406 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001407 for (i = 0; i < mac->mta_reg_count; i++)
1408 array_wr32(E1000_MTA, i, 0);
1409
Alexander Duyck68d480c2009-10-05 06:33:08 +00001410 /* Zero out the Unicast HASH table */
1411 hw_dbg("Zeroing the UTA\n");
1412 for (i = 0; i < mac->uta_reg_count; i++)
1413 array_wr32(E1000_UTA, i, 0);
1414
Auke Kok9d5c8242008-01-24 02:22:38 -08001415 /* Setup link and flow control */
1416 ret_val = igb_setup_link(hw);
1417
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001418 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001419 * important that we do this after we have tried to establish link
1420 * because the symbol error count will increment wildly if there
1421 * is no link.
1422 */
1423 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001424 return ret_val;
1425}
1426
1427/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001428 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001429 * @hw: pointer to the HW structure
1430 *
1431 * Configures the link for auto-neg or forced speed and duplex. Then we check
1432 * for link, once link is established calls to configure collision distance
1433 * and flow control are called.
1434 **/
1435static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1436{
Alexander Duyck12645a12009-07-23 18:08:16 +00001437 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001438 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001439 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001440
1441 ctrl = rd32(E1000_CTRL);
1442 ctrl |= E1000_CTRL_SLU;
1443 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1444 wr32(E1000_CTRL, ctrl);
1445
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001446 /* Clear Go Link Disconnect bit */
1447 if (hw->mac.type >= e1000_82580) {
1448 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1449 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1450 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
1451 }
1452
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001453 ret_val = igb_setup_serdes_link_82575(hw);
1454 if (ret_val)
1455 goto out;
1456
1457 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001458 /* allow time for SFP cage time to power up phy */
1459 msleep(300);
1460
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001461 ret_val = hw->phy.ops.reset(hw);
1462 if (ret_val) {
1463 hw_dbg("Error resetting the PHY.\n");
1464 goto out;
1465 }
1466 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001467 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001468 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001469 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001470 switch (hw->phy.id) {
1471 case I347AT4_E_PHY_ID:
1472 case M88E1112_E_PHY_ID:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001473 case M88E1545_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001474 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001475 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001476 break;
1477 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001478 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001479 break;
1480 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001481 break;
1482 case e1000_phy_igp_3:
1483 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001484 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001485 case e1000_phy_82580:
1486 ret_val = igb_copper_link_setup_82580(hw);
1487 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001488 default:
1489 ret_val = -E1000_ERR_PHY;
1490 break;
1491 }
1492
1493 if (ret_val)
1494 goto out;
1495
Alexander Duyck81fadd82009-10-05 06:35:03 +00001496 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001497out:
1498 return ret_val;
1499}
1500
1501/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001502 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001503 * @hw: pointer to the HW structure
1504 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001505 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1506 * used on copper connections where the serialized gigabit media independent
1507 * interface (sgmii), or serdes fiber is being used. Configures the link
1508 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001509 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001510static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001511{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001512 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001513 bool pcs_autoneg;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001514 s32 ret_val = E1000_SUCCESS;
1515 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001516
1517 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1518 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001519 return ret_val;
1520
Auke Kok9d5c8242008-01-24 02:22:38 -08001521
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001522 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001523 * explicitly turned off or a power cycle is performed. A read to
1524 * the register does not indicate its status. Therefore, we ensure
1525 * loopback mode is disabled during initialization.
1526 */
1527 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1528
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001529 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001530 ctrl_ext = rd32(E1000_CTRL_EXT);
1531 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001532 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001533 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001534
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001535 ctrl_reg = rd32(E1000_CTRL);
1536 ctrl_reg |= E1000_CTRL_SLU;
1537
1538 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1539 /* set both sw defined pins */
1540 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1541
1542 /* Set switch control to serdes energy detect */
1543 reg = rd32(E1000_CONNSW);
1544 reg |= E1000_CONNSW_ENRGSRC;
1545 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001546 }
1547
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001548 reg = rd32(E1000_PCS_LCTL);
1549
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001550 /* default pcs_autoneg to the same setting as mac autoneg */
1551 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001552
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001553 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1554 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1555 /* sgmii mode lets the phy handle forcing speed/duplex */
1556 pcs_autoneg = true;
1557 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001558 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001559 break;
1560 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1561 /* disable PCS autoneg and support parallel detect only */
1562 pcs_autoneg = false;
1563 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001564 if (hw->mac.type == e1000_82575 ||
1565 hw->mac.type == e1000_82576) {
1566 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1567 if (ret_val) {
1568 printk(KERN_DEBUG "NVM Read Error\n\n");
1569 return ret_val;
1570 }
1571
1572 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1573 pcs_autoneg = false;
1574 }
1575
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001576 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001577 * link so it is best to just force the MAC and let the pcs
1578 * link either autoneg or be forced to 1000/Full
1579 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001580 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1581 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001582
1583 /* set speed of 1000/Full if speed/duplex is forced */
1584 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1585 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001586 }
1587
1588 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001589
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001590 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001591 * at 1gb. Autoneg should be default set by most drivers. This is the
1592 * mode that will be compatible with older link partners and switches.
1593 * However, both are supported by the hardware and some drivers/tools.
1594 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001595 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1596 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1597
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001598 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001599 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001600 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001601 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001602
1603 /* Disable force flow control for autoneg */
1604 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1605
1606 /* Configure flow control advertisement for autoneg */
1607 anadv_reg = rd32(E1000_PCS_ANADV);
1608 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1609 switch (hw->fc.requested_mode) {
1610 case e1000_fc_full:
1611 case e1000_fc_rx_pause:
1612 anadv_reg |= E1000_TXCW_ASM_DIR;
1613 anadv_reg |= E1000_TXCW_PAUSE;
1614 break;
1615 case e1000_fc_tx_pause:
1616 anadv_reg |= E1000_TXCW_ASM_DIR;
1617 break;
1618 default:
1619 break;
1620 }
1621 wr32(E1000_PCS_ANADV, anadv_reg);
1622
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001623 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001625 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001626 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001627
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001628 /* Force flow control for forced link */
1629 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1630
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001631 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001632 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001633
Auke Kok9d5c8242008-01-24 02:22:38 -08001634 wr32(E1000_PCS_LCTL, reg);
1635
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001636 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001637 igb_force_mac_fc(hw);
1638
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001639 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001640}
1641
1642/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001643 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 * @hw: pointer to the HW structure
1645 *
1646 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1647 * which can be enabled for use in the embedded applications. Simply
1648 * return the current state of the sgmii interface.
1649 **/
1650static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1651{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001652 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001653 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001654}
1655
1656/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001657 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001658 * @hw: pointer to the HW structure
1659 *
1660 * Inits recommended HW defaults after a reset when there is no EEPROM
1661 * detected. This is only for the 82575.
1662 **/
1663static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1664{
1665 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001666 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001667 /* SerDes configuration via SERDESCTRL */
1668 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1669 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1670 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1671 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1672
1673 /* CCM configuration via CCMCTL register */
1674 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1675 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1676
1677 /* PCIe lanes configuration */
1678 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1679 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1680 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1681 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1682
1683 /* PCIe PLL Configuration */
1684 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1685 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1686 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1687 }
1688
1689 return 0;
1690}
1691
1692/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001693 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001694 * @hw: pointer to the HW structure
1695 **/
1696static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1697{
1698 s32 ret_val = 0;
1699
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001700 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001701 * so that it will override the Si installed default perm
1702 * address.
1703 */
1704 ret_val = igb_check_alt_mac_addr(hw);
1705 if (ret_val)
1706 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001707
Alexander Duyck22896632009-10-05 06:34:25 +00001708 ret_val = igb_read_mac_addr(hw);
1709
1710out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001711 return ret_val;
1712}
1713
1714/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001715 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1716 * @hw: pointer to the HW structure
1717 *
1718 * In the case of a PHY power down to save power, or to turn off link during a
1719 * driver unload, or wake on lan is not enabled, remove the link.
1720 **/
1721void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1722{
1723 /* If the management interface is not enabled, then power down */
1724 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1725 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001726}
1727
1728/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001729 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001730 * @hw: pointer to the HW structure
1731 *
1732 * Clears the hardware counters by reading the counter registers.
1733 **/
1734static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1735{
Auke Kok9d5c8242008-01-24 02:22:38 -08001736 igb_clear_hw_cntrs_base(hw);
1737
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001738 rd32(E1000_PRC64);
1739 rd32(E1000_PRC127);
1740 rd32(E1000_PRC255);
1741 rd32(E1000_PRC511);
1742 rd32(E1000_PRC1023);
1743 rd32(E1000_PRC1522);
1744 rd32(E1000_PTC64);
1745 rd32(E1000_PTC127);
1746 rd32(E1000_PTC255);
1747 rd32(E1000_PTC511);
1748 rd32(E1000_PTC1023);
1749 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001750
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001751 rd32(E1000_ALGNERRC);
1752 rd32(E1000_RXERRC);
1753 rd32(E1000_TNCRS);
1754 rd32(E1000_CEXTERR);
1755 rd32(E1000_TSCTC);
1756 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001757
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001758 rd32(E1000_MGTPRC);
1759 rd32(E1000_MGTPDC);
1760 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001761
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001762 rd32(E1000_IAC);
1763 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001764
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001765 rd32(E1000_ICRXPTC);
1766 rd32(E1000_ICRXATC);
1767 rd32(E1000_ICTXPTC);
1768 rd32(E1000_ICTXATC);
1769 rd32(E1000_ICTXQEC);
1770 rd32(E1000_ICTXQMTC);
1771 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001772
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001773 rd32(E1000_CBTMPC);
1774 rd32(E1000_HTDPMC);
1775 rd32(E1000_CBRMPC);
1776 rd32(E1000_RPTHC);
1777 rd32(E1000_HGPTC);
1778 rd32(E1000_HTCBDPC);
1779 rd32(E1000_HGORCL);
1780 rd32(E1000_HGORCH);
1781 rd32(E1000_HGOTCL);
1782 rd32(E1000_HGOTCH);
1783 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001784
1785 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001786 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1787 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001788 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001789}
1790
Alexander Duyck662d7202008-06-27 11:00:29 -07001791/**
1792 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1793 * @hw: pointer to the HW structure
1794 *
1795 * After rx enable if managability is enabled then there is likely some
1796 * bad data at the start of the fifo and possibly in the DMA fifo. This
1797 * function clears the fifos and flushes any packets that came in as rx was
1798 * being enabled.
1799 **/
1800void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1801{
1802 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1803 int i, ms_wait;
1804
1805 if (hw->mac.type != e1000_82575 ||
1806 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1807 return;
1808
1809 /* Disable all RX queues */
1810 for (i = 0; i < 4; i++) {
1811 rxdctl[i] = rd32(E1000_RXDCTL(i));
1812 wr32(E1000_RXDCTL(i),
1813 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1814 }
1815 /* Poll all queues to verify they have shut down */
1816 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1817 msleep(1);
1818 rx_enabled = 0;
1819 for (i = 0; i < 4; i++)
1820 rx_enabled |= rd32(E1000_RXDCTL(i));
1821 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1822 break;
1823 }
1824
1825 if (ms_wait == 10)
1826 hw_dbg("Queue disable timed out after 10ms\n");
1827
1828 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1829 * incoming packets are rejected. Set enable and wait 2ms so that
1830 * any packet that was coming in as RCTL.EN was set is flushed
1831 */
1832 rfctl = rd32(E1000_RFCTL);
1833 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1834
1835 rlpml = rd32(E1000_RLPML);
1836 wr32(E1000_RLPML, 0);
1837
1838 rctl = rd32(E1000_RCTL);
1839 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1840 temp_rctl |= E1000_RCTL_LPE;
1841
1842 wr32(E1000_RCTL, temp_rctl);
1843 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1844 wrfl();
1845 msleep(2);
1846
1847 /* Enable RX queues that were previously enabled and restore our
1848 * previous state
1849 */
1850 for (i = 0; i < 4; i++)
1851 wr32(E1000_RXDCTL(i), rxdctl[i]);
1852 wr32(E1000_RCTL, rctl);
1853 wrfl();
1854
1855 wr32(E1000_RLPML, rlpml);
1856 wr32(E1000_RFCTL, rfctl);
1857
1858 /* Flush receive errors generated by workaround */
1859 rd32(E1000_ROC);
1860 rd32(E1000_RNBC);
1861 rd32(E1000_MPC);
1862}
1863
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001864/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001865 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1866 * @hw: pointer to the HW structure
1867 *
1868 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1869 * however the hardware default for these parts is 500us to 1ms which is less
1870 * than the 10ms recommended by the pci-e spec. To address this we need to
1871 * increase the value to either 10ms to 200ms for capability version 1 config,
1872 * or 16ms to 55ms for version 2.
1873 **/
1874static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1875{
1876 u32 gcr = rd32(E1000_GCR);
1877 s32 ret_val = 0;
1878 u16 pcie_devctl2;
1879
1880 /* only take action if timeout value is defaulted to 0 */
1881 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1882 goto out;
1883
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001884 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00001885 * timeout of 10ms to 200ms through the GCR register
1886 */
1887 if (!(gcr & E1000_GCR_CAP_VER2)) {
1888 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1889 goto out;
1890 }
1891
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001892 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00001893 * directly in order to set the completion timeout value for
1894 * 16ms to 55ms
1895 */
1896 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1897 &pcie_devctl2);
1898 if (ret_val)
1899 goto out;
1900
1901 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1902
1903 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1904 &pcie_devctl2);
1905out:
1906 /* disable completion timeout resend */
1907 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1908
1909 wr32(E1000_GCR, gcr);
1910 return ret_val;
1911}
1912
1913/**
Greg Rose13800462010-11-06 02:08:26 +00001914 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
1915 * @hw: pointer to the hardware struct
1916 * @enable: state to enter, either enabled or disabled
1917 * @pf: Physical Function pool - do not set anti-spoofing for the PF
1918 *
1919 * enables/disables L2 switch anti-spoofing functionality.
1920 **/
1921void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
1922{
Lior Levy22c12752013-03-12 15:49:32 +00001923 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00001924
1925 switch (hw->mac.type) {
1926 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00001927 reg_offset = E1000_DTXSWC;
1928 break;
Greg Rose13800462010-11-06 02:08:26 +00001929 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001930 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00001931 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00001932 break;
1933 default:
Lior Levy22c12752013-03-12 15:49:32 +00001934 return;
Greg Rose13800462010-11-06 02:08:26 +00001935 }
Lior Levy22c12752013-03-12 15:49:32 +00001936
1937 reg_val = rd32(reg_offset);
1938 if (enable) {
1939 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
1940 E1000_DTXSWC_VLAN_SPOOF_MASK);
1941 /* The PF can spoof - it has to in order to
1942 * support emulation mode NICs
1943 */
1944 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
1945 } else {
1946 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
1947 E1000_DTXSWC_VLAN_SPOOF_MASK);
1948 }
1949 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00001950}
1951
1952/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001953 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1954 * @hw: pointer to the hardware struct
1955 * @enable: state to enter, either enabled or disabled
1956 *
1957 * enables/disables L2 switch loopback functionality.
1958 **/
1959void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1960{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001961 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001962
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001963 switch (hw->mac.type) {
1964 case e1000_82576:
1965 dtxswc = rd32(E1000_DTXSWC);
1966 if (enable)
1967 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1968 else
1969 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1970 wr32(E1000_DTXSWC, dtxswc);
1971 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001972 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001973 case e1000_i350:
1974 dtxswc = rd32(E1000_TXSWC);
1975 if (enable)
1976 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1977 else
1978 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1979 wr32(E1000_TXSWC, dtxswc);
1980 break;
1981 default:
1982 /* Currently no other hardware supports loopback */
1983 break;
1984 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001985
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001986}
1987
1988/**
1989 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1990 * @hw: pointer to the hardware struct
1991 * @enable: state to enter, either enabled or disabled
1992 *
1993 * enables/disables replication of packets across multiple pools.
1994 **/
1995void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1996{
1997 u32 vt_ctl = rd32(E1000_VT_CTL);
1998
1999 if (enable)
2000 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2001 else
2002 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2003
2004 wr32(E1000_VT_CTL, vt_ctl);
2005}
2006
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002007/**
2008 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2009 * @hw: pointer to the HW structure
2010 * @offset: register offset to be read
2011 * @data: pointer to the read data
2012 *
2013 * Reads the MDI control register in the PHY at offset and stores the
2014 * information read to data.
2015 **/
2016static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2017{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002018 s32 ret_val;
2019
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002020 ret_val = hw->phy.ops.acquire(hw);
2021 if (ret_val)
2022 goto out;
2023
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002024 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2025
2026 hw->phy.ops.release(hw);
2027
2028out:
2029 return ret_val;
2030}
2031
2032/**
2033 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2034 * @hw: pointer to the HW structure
2035 * @offset: register offset to write to
2036 * @data: data to write to register at offset
2037 *
2038 * Writes data to MDI control register in the PHY at offset.
2039 **/
2040static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2041{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002042 s32 ret_val;
2043
2044
2045 ret_val = hw->phy.ops.acquire(hw);
2046 if (ret_val)
2047 goto out;
2048
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002049 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2050
2051 hw->phy.ops.release(hw);
2052
2053out:
2054 return ret_val;
2055}
2056
2057/**
Nick Nunley08451e22010-07-26 13:15:29 +00002058 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2059 * @hw: pointer to the HW structure
2060 *
2061 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2062 * the values found in the EEPROM. This addresses an issue in which these
2063 * bits are not restored from EEPROM after reset.
2064 **/
2065static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2066{
2067 s32 ret_val = 0;
2068 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002069 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002070
2071 if (hw->mac.type != e1000_82580)
2072 goto out;
2073 if (!igb_sgmii_active_82575(hw))
2074 goto out;
2075
2076 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2077 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2078 &nvm_data);
2079 if (ret_val) {
2080 hw_dbg("NVM Read Error\n");
2081 goto out;
2082 }
2083
2084 mdicnfg = rd32(E1000_MDICNFG);
2085 if (nvm_data & NVM_WORD24_EXT_MDIO)
2086 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2087 if (nvm_data & NVM_WORD24_COM_MDIO)
2088 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2089 wr32(E1000_MDICNFG, mdicnfg);
2090out:
2091 return ret_val;
2092}
2093
2094/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002095 * igb_reset_hw_82580 - Reset hardware
2096 * @hw: pointer to the HW structure
2097 *
2098 * This resets function or entire device (all ports, etc.)
2099 * to a known state.
2100 **/
2101static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2102{
2103 s32 ret_val = 0;
2104 /* BH SW mailbox bit in SW_FW_SYNC */
2105 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002106 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002107 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2108
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002109 hw->dev_spec._82575.global_device_reset = false;
2110
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002111 /* due to hw errata, global device reset doesn't always
2112 * work on 82580
2113 */
2114 if (hw->mac.type == e1000_82580)
2115 global_device_reset = false;
2116
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002117 /* Get current control state. */
2118 ctrl = rd32(E1000_CTRL);
2119
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002120 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002121 * on the last TLP read/write transaction when MAC is reset.
2122 */
2123 ret_val = igb_disable_pcie_master(hw);
2124 if (ret_val)
2125 hw_dbg("PCI-E Master disable polling has failed.\n");
2126
2127 hw_dbg("Masking off all interrupts\n");
2128 wr32(E1000_IMC, 0xffffffff);
2129 wr32(E1000_RCTL, 0);
2130 wr32(E1000_TCTL, E1000_TCTL_PSP);
2131 wrfl();
2132
2133 msleep(10);
2134
2135 /* Determine whether or not a global dev reset is requested */
2136 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002137 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002138 global_device_reset = false;
2139
2140 if (global_device_reset &&
2141 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2142 ctrl |= E1000_CTRL_DEV_RST;
2143 else
2144 ctrl |= E1000_CTRL_RST;
2145
2146 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002147 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002148
2149 /* Add delay to insure DEV_RST has time to complete */
2150 if (global_device_reset)
2151 msleep(5);
2152
2153 ret_val = igb_get_auto_rd_done(hw);
2154 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002155 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002156 * return with an error. This can happen in situations
2157 * where there is no eeprom and prevents getting link.
2158 */
2159 hw_dbg("Auto Read Done did not complete\n");
2160 }
2161
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002162 /* clear global device reset status bit */
2163 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2164
2165 /* Clear any pending interrupt events. */
2166 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002167 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002168
Nick Nunley08451e22010-07-26 13:15:29 +00002169 ret_val = igb_reset_mdicnfg_82580(hw);
2170 if (ret_val)
2171 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2172
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002173 /* Install any alternate MAC address into RAR0 */
2174 ret_val = igb_check_alt_mac_addr(hw);
2175
2176 /* Release semaphore */
2177 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002178 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002179
2180 return ret_val;
2181}
2182
2183/**
2184 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2185 * @data: data received by reading RXPBS register
2186 *
2187 * The 82580 uses a table based approach for packet buffer allocation sizes.
2188 * This function converts the retrieved value into the correct table value
2189 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2190 * 0x0 36 72 144 1 2 4 8 16
2191 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2192 */
2193u16 igb_rxpbs_adjust_82580(u32 data)
2194{
2195 u16 ret_val = 0;
2196
2197 if (data < E1000_82580_RXPBS_TABLE_SIZE)
2198 ret_val = e1000_82580_rxpbs_table[data];
2199
2200 return ret_val;
2201}
2202
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002203/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002204 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2205 * checksum
2206 * @hw: pointer to the HW structure
2207 * @offset: offset in words of the checksum protected region
2208 *
2209 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2210 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2211 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002212static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2213 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002214{
2215 s32 ret_val = 0;
2216 u16 checksum = 0;
2217 u16 i, nvm_data;
2218
2219 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2220 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2221 if (ret_val) {
2222 hw_dbg("NVM Read Error\n");
2223 goto out;
2224 }
2225 checksum += nvm_data;
2226 }
2227
2228 if (checksum != (u16) NVM_SUM) {
2229 hw_dbg("NVM Checksum Invalid\n");
2230 ret_val = -E1000_ERR_NVM;
2231 goto out;
2232 }
2233
2234out:
2235 return ret_val;
2236}
2237
2238/**
2239 * igb_update_nvm_checksum_with_offset - Update EEPROM
2240 * checksum
2241 * @hw: pointer to the HW structure
2242 * @offset: offset in words of the checksum protected region
2243 *
2244 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2245 * up to the checksum. Then calculates the EEPROM checksum and writes the
2246 * value to the EEPROM.
2247 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002248static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002249{
2250 s32 ret_val;
2251 u16 checksum = 0;
2252 u16 i, nvm_data;
2253
2254 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2255 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2256 if (ret_val) {
2257 hw_dbg("NVM Read Error while updating checksum.\n");
2258 goto out;
2259 }
2260 checksum += nvm_data;
2261 }
2262 checksum = (u16) NVM_SUM - checksum;
2263 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2264 &checksum);
2265 if (ret_val)
2266 hw_dbg("NVM Write Error while updating checksum.\n");
2267
2268out:
2269 return ret_val;
2270}
2271
2272/**
2273 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2274 * @hw: pointer to the HW structure
2275 *
2276 * Calculates the EEPROM section checksum by reading/adding each word of
2277 * the EEPROM and then verifies that the sum of the EEPROM is
2278 * equal to 0xBABA.
2279 **/
2280static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2281{
2282 s32 ret_val = 0;
2283 u16 eeprom_regions_count = 1;
2284 u16 j, nvm_data;
2285 u16 nvm_offset;
2286
2287 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2288 if (ret_val) {
2289 hw_dbg("NVM Read Error\n");
2290 goto out;
2291 }
2292
2293 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002294 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002295 * for all 4 ports.
2296 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002297 eeprom_regions_count = 4;
2298 }
2299
2300 for (j = 0; j < eeprom_regions_count; j++) {
2301 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2302 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2303 nvm_offset);
2304 if (ret_val != 0)
2305 goto out;
2306 }
2307
2308out:
2309 return ret_val;
2310}
2311
2312/**
2313 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2314 * @hw: pointer to the HW structure
2315 *
2316 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2317 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2318 * checksum and writes the value to the EEPROM.
2319 **/
2320static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2321{
2322 s32 ret_val;
2323 u16 j, nvm_data;
2324 u16 nvm_offset;
2325
2326 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2327 if (ret_val) {
2328 hw_dbg("NVM Read Error while updating checksum"
2329 " compatibility bit.\n");
2330 goto out;
2331 }
2332
2333 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2334 /* set compatibility bit to validate checksums appropriately */
2335 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2336 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2337 &nvm_data);
2338 if (ret_val) {
2339 hw_dbg("NVM Write Error while updating checksum"
2340 " compatibility bit.\n");
2341 goto out;
2342 }
2343 }
2344
2345 for (j = 0; j < 4; j++) {
2346 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2347 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2348 if (ret_val)
2349 goto out;
2350 }
2351
2352out:
2353 return ret_val;
2354}
2355
2356/**
2357 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2358 * @hw: pointer to the HW structure
2359 *
2360 * Calculates the EEPROM section checksum by reading/adding each word of
2361 * the EEPROM and then verifies that the sum of the EEPROM is
2362 * equal to 0xBABA.
2363 **/
2364static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2365{
2366 s32 ret_val = 0;
2367 u16 j;
2368 u16 nvm_offset;
2369
2370 for (j = 0; j < 4; j++) {
2371 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2372 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2373 nvm_offset);
2374 if (ret_val != 0)
2375 goto out;
2376 }
2377
2378out:
2379 return ret_val;
2380}
2381
2382/**
2383 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2384 * @hw: pointer to the HW structure
2385 *
2386 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2387 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2388 * checksum and writes the value to the EEPROM.
2389 **/
2390static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2391{
2392 s32 ret_val = 0;
2393 u16 j;
2394 u16 nvm_offset;
2395
2396 for (j = 0; j < 4; j++) {
2397 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2398 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2399 if (ret_val != 0)
2400 goto out;
2401 }
2402
2403out:
2404 return ret_val;
2405}
Stefan Assmann34a03262011-04-05 04:27:05 +00002406
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002407/**
Matthew Vick87371b92013-02-21 03:32:52 +00002408 * __igb_access_emi_reg - Read/write EMI register
2409 * @hw: pointer to the HW structure
2410 * @addr: EMI address to program
2411 * @data: pointer to value to read/write from/to the EMI address
2412 * @read: boolean flag to indicate read or write
2413 **/
2414static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2415 u16 *data, bool read)
2416{
2417 s32 ret_val = E1000_SUCCESS;
2418
2419 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2420 if (ret_val)
2421 return ret_val;
2422
2423 if (read)
2424 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2425 else
2426 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2427
2428 return ret_val;
2429}
2430
2431/**
2432 * igb_read_emi_reg - Read Extended Management Interface register
2433 * @hw: pointer to the HW structure
2434 * @addr: EMI address to program
2435 * @data: value to be read from the EMI address
2436 **/
2437s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2438{
2439 return __igb_access_emi_reg(hw, addr, data, true);
2440}
2441
2442/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002443 * igb_set_eee_i350 - Enable/disable EEE support
2444 * @hw: pointer to the HW structure
2445 *
2446 * Enable/disable EEE based on setting in dev_spec structure.
2447 *
2448 **/
2449s32 igb_set_eee_i350(struct e1000_hw *hw)
2450{
2451 s32 ret_val = 0;
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002452 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002453
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002454 if ((hw->mac.type < e1000_i350) ||
2455 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002456 goto out;
2457 ipcnfg = rd32(E1000_IPCNFG);
2458 eeer = rd32(E1000_EEER);
2459
2460 /* enable or disable per user setting */
2461 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002462 u32 eee_su = rd32(E1000_EEE_SU);
2463
2464 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2465 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002466 E1000_EEER_LPI_FC);
2467
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002468 /* This bit should not be set in normal operation. */
2469 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2470 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2471
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002472 } else {
2473 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2474 E1000_IPCNFG_EEE_100M_AN);
2475 eeer &= ~(E1000_EEER_TX_LPI_EN |
2476 E1000_EEER_RX_LPI_EN |
2477 E1000_EEER_LPI_FC);
2478 }
2479 wr32(E1000_IPCNFG, ipcnfg);
2480 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002481 rd32(E1000_IPCNFG);
2482 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002483out:
2484
2485 return ret_val;
2486}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002487
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002488/**
2489 * igb_set_eee_i354 - Enable/disable EEE support
2490 * @hw: pointer to the HW structure
2491 *
2492 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2493 *
2494 **/
2495s32 igb_set_eee_i354(struct e1000_hw *hw)
2496{
2497 struct e1000_phy_info *phy = &hw->phy;
2498 s32 ret_val = 0;
2499 u16 phy_data;
2500
2501 if ((hw->phy.media_type != e1000_media_type_copper) ||
2502 (phy->id != M88E1545_E_PHY_ID))
2503 goto out;
2504
2505 if (!hw->dev_spec._82575.eee_disable) {
2506 /* Switch to PHY page 18. */
2507 ret_val = phy->ops.write_reg(hw, E1000_M88E1545_PAGE_ADDR, 18);
2508 if (ret_val)
2509 goto out;
2510
2511 ret_val = phy->ops.read_reg(hw, E1000_M88E1545_EEE_CTRL_1,
2512 &phy_data);
2513 if (ret_val)
2514 goto out;
2515
2516 phy_data |= E1000_M88E1545_EEE_CTRL_1_MS;
2517 ret_val = phy->ops.write_reg(hw, E1000_M88E1545_EEE_CTRL_1,
2518 phy_data);
2519 if (ret_val)
2520 goto out;
2521
2522 /* Return the PHY to page 0. */
2523 ret_val = phy->ops.write_reg(hw, E1000_M88E1545_PAGE_ADDR, 0);
2524 if (ret_val)
2525 goto out;
2526
2527 /* Turn on EEE advertisement. */
2528 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2529 E1000_EEE_ADV_DEV_I354,
2530 &phy_data);
2531 if (ret_val)
2532 goto out;
2533
2534 phy_data |= E1000_EEE_ADV_100_SUPPORTED |
2535 E1000_EEE_ADV_1000_SUPPORTED;
2536 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2537 E1000_EEE_ADV_DEV_I354,
2538 phy_data);
2539 } else {
2540 /* Turn off EEE advertisement. */
2541 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2542 E1000_EEE_ADV_DEV_I354,
2543 &phy_data);
2544 if (ret_val)
2545 goto out;
2546
2547 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2548 E1000_EEE_ADV_1000_SUPPORTED);
2549 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2550 E1000_EEE_ADV_DEV_I354,
2551 phy_data);
2552 }
2553
2554out:
2555 return ret_val;
2556}
2557
2558/**
2559 * igb_get_eee_status_i354 - Get EEE status
2560 * @hw: pointer to the HW structure
2561 * @status: EEE status
2562 *
2563 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2564 * been received.
2565 **/
2566s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2567{
2568 struct e1000_phy_info *phy = &hw->phy;
2569 s32 ret_val = 0;
2570 u16 phy_data;
2571
2572 /* Check if EEE is supported on this device. */
2573 if ((hw->phy.media_type != e1000_media_type_copper) ||
2574 (phy->id != M88E1545_E_PHY_ID))
2575 goto out;
2576
2577 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2578 E1000_PCS_STATUS_DEV_I354,
2579 &phy_data);
2580 if (ret_val)
2581 goto out;
2582
2583 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2584 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2585
2586out:
2587 return ret_val;
2588}
2589
Carolyn Wybornye4288932012-12-07 03:01:42 +00002590static const u8 e1000_emc_temp_data[4] = {
2591 E1000_EMC_INTERNAL_DATA,
2592 E1000_EMC_DIODE1_DATA,
2593 E1000_EMC_DIODE2_DATA,
2594 E1000_EMC_DIODE3_DATA
2595};
2596static const u8 e1000_emc_therm_limit[4] = {
2597 E1000_EMC_INTERNAL_THERM_LIMIT,
2598 E1000_EMC_DIODE1_THERM_LIMIT,
2599 E1000_EMC_DIODE2_THERM_LIMIT,
2600 E1000_EMC_DIODE3_THERM_LIMIT
2601};
2602
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002603/**
2604 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002605 * @hw: pointer to hardware structure
2606 *
2607 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002608 **/
Carolyn Wybornye4288932012-12-07 03:01:42 +00002609s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
2610{
2611 s32 status = E1000_SUCCESS;
2612 u16 ets_offset;
2613 u16 ets_cfg;
2614 u16 ets_sensor;
2615 u8 num_sensors;
2616 u8 sensor_index;
2617 u8 sensor_location;
2618 u8 i;
2619 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2620
2621 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2622 return E1000_NOT_IMPLEMENTED;
2623
2624 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2625
2626 /* Return the internal sensor only if ETS is unsupported */
2627 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2628 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2629 return status;
2630
2631 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2632 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2633 != NVM_ETS_TYPE_EMC)
2634 return E1000_NOT_IMPLEMENTED;
2635
2636 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2637 if (num_sensors > E1000_MAX_SENSORS)
2638 num_sensors = E1000_MAX_SENSORS;
2639
2640 for (i = 1; i < num_sensors; i++) {
2641 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2642 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2643 NVM_ETS_DATA_INDEX_SHIFT);
2644 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2645 NVM_ETS_DATA_LOC_SHIFT);
2646
2647 if (sensor_location != 0)
2648 hw->phy.ops.read_i2c_byte(hw,
2649 e1000_emc_temp_data[sensor_index],
2650 E1000_I2C_THERMAL_SENSOR_ADDR,
2651 &data->sensor[i].temp);
2652 }
2653 return status;
2654}
2655
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002656/**
2657 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002658 * @hw: pointer to hardware structure
2659 *
2660 * Sets the thermal sensor thresholds according to the NVM map
2661 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002662 **/
Carolyn Wybornye4288932012-12-07 03:01:42 +00002663s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
2664{
2665 s32 status = E1000_SUCCESS;
2666 u16 ets_offset;
2667 u16 ets_cfg;
2668 u16 ets_sensor;
2669 u8 low_thresh_delta;
2670 u8 num_sensors;
2671 u8 sensor_index;
2672 u8 sensor_location;
2673 u8 therm_limit;
2674 u8 i;
2675 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2676
2677 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2678 return E1000_NOT_IMPLEMENTED;
2679
2680 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2681
2682 data->sensor[0].location = 0x1;
2683 data->sensor[0].caution_thresh =
2684 (rd32(E1000_THHIGHTC) & 0xFF);
2685 data->sensor[0].max_op_thresh =
2686 (rd32(E1000_THLOWTC) & 0xFF);
2687
2688 /* Return the internal sensor only if ETS is unsupported */
2689 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2690 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2691 return status;
2692
2693 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2694 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2695 != NVM_ETS_TYPE_EMC)
2696 return E1000_NOT_IMPLEMENTED;
2697
2698 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2699 NVM_ETS_LTHRES_DELTA_SHIFT);
2700 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2701
2702 for (i = 1; i <= num_sensors; i++) {
2703 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2704 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2705 NVM_ETS_DATA_INDEX_SHIFT);
2706 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2707 NVM_ETS_DATA_LOC_SHIFT);
2708 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2709
2710 hw->phy.ops.write_i2c_byte(hw,
2711 e1000_emc_therm_limit[sensor_index],
2712 E1000_I2C_THERMAL_SENSOR_ADDR,
2713 therm_limit);
2714
2715 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2716 data->sensor[i].location = sensor_location;
2717 data->sensor[i].caution_thresh = therm_limit;
2718 data->sensor[i].max_op_thresh = therm_limit -
2719 low_thresh_delta;
2720 }
2721 }
2722 return status;
2723}
2724
Auke Kok9d5c8242008-01-24 02:22:38 -08002725static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002726 .init_hw = igb_init_hw_82575,
2727 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002728 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002729 .read_mac_addr = igb_read_mac_addr_82575,
2730 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002731#ifdef CONFIG_IGB_HWMON
2732 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2733 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2734#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002735};
2736
2737static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002738 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002739 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002740 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002741 .write_i2c_byte = igb_write_i2c_byte,
2742 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002743};
2744
2745static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002746 .acquire = igb_acquire_nvm_82575,
2747 .read = igb_read_nvm_eerd,
2748 .release = igb_release_nvm_82575,
2749 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002750};
2751
2752const struct e1000_info e1000_82575_info = {
2753 .get_invariants = igb_get_invariants_82575,
2754 .mac_ops = &e1000_mac_ops_82575,
2755 .phy_ops = &e1000_phy_ops_82575,
2756 .nvm_ops = &e1000_nvm_ops_82575,
2757};
2758