blob: fc69414f8250c42f5244b93498f00634839b6162 [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 Wybornyf96a8a02012-04-06 23:25:19 +0000103 case e1000_i210:
104 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000105 reg = rd32(E1000_MDICNFG);
106 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
107 break;
108 default:
109 break;
110 }
111 return ext_mdio;
112}
113
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000114/**
115 * igb_init_phy_params_82575 - Init PHY func ptrs.
116 * @hw: pointer to the HW structure
117 **/
118static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
119{
120 struct e1000_phy_info *phy = &hw->phy;
121 s32 ret_val = 0;
122 u32 ctrl_ext;
123
124 if (hw->phy.media_type != e1000_media_type_copper) {
125 phy->type = e1000_phy_none;
126 goto out;
127 }
128
129 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
130 phy->reset_delay_us = 100;
131
132 ctrl_ext = rd32(E1000_CTRL_EXT);
133
134 if (igb_sgmii_active_82575(hw)) {
135 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
136 ctrl_ext |= E1000_CTRL_I2C_ENA;
137 } else {
138 phy->ops.reset = igb_phy_hw_reset;
139 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
140 }
141
142 wr32(E1000_CTRL_EXT, ctrl_ext);
143 igb_reset_mdicnfg_82580(hw);
144
145 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
146 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
147 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
148 } else {
149 switch (hw->mac.type) {
150 case e1000_82580:
151 case e1000_i350:
152 phy->ops.read_reg = igb_read_phy_reg_82580;
153 phy->ops.write_reg = igb_write_phy_reg_82580;
154 break;
155 case e1000_i210:
156 case e1000_i211:
157 phy->ops.read_reg = igb_read_phy_reg_gs40g;
158 phy->ops.write_reg = igb_write_phy_reg_gs40g;
159 break;
160 default:
161 phy->ops.read_reg = igb_read_phy_reg_igp;
162 phy->ops.write_reg = igb_write_phy_reg_igp;
163 }
164 }
165
166 /* set lan id */
167 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
168 E1000_STATUS_FUNC_SHIFT;
169
170 /* Set phy->phy_addr and phy->id. */
171 ret_val = igb_get_phy_id_82575(hw);
172 if (ret_val)
173 return ret_val;
174
175 /* Verify phy id and set remaining function pointers */
176 switch (phy->id) {
177 case I347AT4_E_PHY_ID:
178 case M88E1112_E_PHY_ID:
179 case M88E1111_I_PHY_ID:
180 phy->type = e1000_phy_m88;
181 phy->ops.get_phy_info = igb_get_phy_info_m88;
182 if (phy->id == I347AT4_E_PHY_ID ||
183 phy->id == M88E1112_E_PHY_ID)
184 phy->ops.get_cable_length =
185 igb_get_cable_length_m88_gen2;
186 else
187 phy->ops.get_cable_length = igb_get_cable_length_m88;
188 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
189 break;
190 case IGP03E1000_E_PHY_ID:
191 phy->type = e1000_phy_igp_3;
192 phy->ops.get_phy_info = igb_get_phy_info_igp;
193 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
194 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
195 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
196 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
197 break;
198 case I82580_I_PHY_ID:
199 case I350_I_PHY_ID:
200 phy->type = e1000_phy_82580;
201 phy->ops.force_speed_duplex =
202 igb_phy_force_speed_duplex_82580;
203 phy->ops.get_cable_length = igb_get_cable_length_82580;
204 phy->ops.get_phy_info = igb_get_phy_info_82580;
205 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
206 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
207 break;
208 case I210_I_PHY_ID:
209 phy->type = e1000_phy_i210;
210 phy->ops.check_polarity = igb_check_polarity_m88;
211 phy->ops.get_phy_info = igb_get_phy_info_m88;
212 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
213 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
214 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
215 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
216 break;
217 default:
218 ret_val = -E1000_ERR_PHY;
219 goto out;
220 }
221
222out:
223 return ret_val;
224}
225
Auke Kok9d5c8242008-01-24 02:22:38 -0800226static s32 igb_get_invariants_82575(struct e1000_hw *hw)
227{
228 struct e1000_phy_info *phy = &hw->phy;
229 struct e1000_nvm_info *nvm = &hw->nvm;
230 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +0000231 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800232 u32 eecd;
233 s32 ret_val;
234 u16 size;
235 u32 ctrl_ext = 0;
236
237 switch (hw->device_id) {
238 case E1000_DEV_ID_82575EB_COPPER:
239 case E1000_DEV_ID_82575EB_FIBER_SERDES:
240 case E1000_DEV_ID_82575GB_QUAD_COPPER:
241 mac->type = e1000_82575;
242 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700243 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000244 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000245 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700246 case E1000_DEV_ID_82576_FIBER:
247 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000248 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000249 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000250 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700251 mac->type = e1000_82576;
252 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000253 case E1000_DEV_ID_82580_COPPER:
254 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000255 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000256 case E1000_DEV_ID_82580_SERDES:
257 case E1000_DEV_ID_82580_SGMII:
258 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000259 case E1000_DEV_ID_DH89XXCC_SGMII:
260 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000261 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
262 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000263 mac->type = e1000_82580;
264 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000265 case E1000_DEV_ID_I350_COPPER:
266 case E1000_DEV_ID_I350_FIBER:
267 case E1000_DEV_ID_I350_SERDES:
268 case E1000_DEV_ID_I350_SGMII:
269 mac->type = e1000_i350;
270 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000271 case E1000_DEV_ID_I210_COPPER:
272 case E1000_DEV_ID_I210_COPPER_OEM1:
273 case E1000_DEV_ID_I210_COPPER_IT:
274 case E1000_DEV_ID_I210_FIBER:
275 case E1000_DEV_ID_I210_SERDES:
276 case E1000_DEV_ID_I210_SGMII:
277 mac->type = e1000_i210;
278 break;
279 case E1000_DEV_ID_I211_COPPER:
280 mac->type = e1000_i211;
281 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800282 default:
283 return -E1000_ERR_MAC_INIT;
284 break;
285 }
286
Auke Kok9d5c8242008-01-24 02:22:38 -0800287 /* Set media type */
288 /*
289 * The 82575 uses bits 22:23 for link mode. The mode can be changed
290 * based on the EEPROM. We cannot rely upon device ID. There
291 * is no distinguishable difference between fiber and internal
292 * SerDes mode on the 82575. There can be an external PHY attached
293 * on the SGMII interface. For this, we'll set sgmii_active to true.
294 */
295 phy->media_type = e1000_media_type_copper;
296 dev_spec->sgmii_active = false;
297
298 ctrl_ext = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000299 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
300 case E1000_CTRL_EXT_LINK_MODE_SGMII:
Auke Kok9d5c8242008-01-24 02:22:38 -0800301 dev_spec->sgmii_active = true;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000302 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000303 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000304 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
305 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000306 break;
307 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000308 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800309 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000310
Auke Kok9d5c8242008-01-24 02:22:38 -0800311 /* Set mta register count */
312 mac->mta_reg_count = 128;
313 /* Set rar entry count */
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000314 switch (mac->type) {
315 case e1000_82576:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700316 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000317 break;
318 case e1000_82580:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000319 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000320 break;
321 case e1000_i350:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000322 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000323 break;
324 default:
325 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
326 break;
327 }
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000328 /* reset */
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000329 if (mac->type >= e1000_82580)
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000330 mac->ops.reset_hw = igb_reset_hw_82580;
331 else
332 mac->ops.reset_hw = igb_reset_hw_82575;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000333
334 if (mac->type >= e1000_i210) {
335 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
336 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
337 } else {
338 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
339 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
340 }
341
Auke Kok9d5c8242008-01-24 02:22:38 -0800342 /* Set if part includes ASF firmware */
343 mac->asf_firmware_present = true;
344 /* Set if manageability features are enabled. */
345 mac->arc_subsystem_valid =
346 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
347 ? true : false;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000348 /* enable EEE on i350 parts and later parts */
349 if (mac->type >= e1000_i350)
Carolyn Wyborny09b068d2011-03-11 20:42:13 -0800350 dev_spec->eee_disable = false;
351 else
352 dev_spec->eee_disable = true;
Auke Kok9d5c8242008-01-24 02:22:38 -0800353 /* physical interface link setup */
354 mac->ops.setup_physical_interface =
355 (hw->phy.media_type == e1000_media_type_copper)
356 ? igb_setup_copper_link_82575
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000357 : igb_setup_serdes_link_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800358
359 /* NVM initialization */
360 eecd = rd32(E1000_EECD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800361 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
362 E1000_EECD_SIZE_EX_SHIFT);
363
364 /*
365 * Added to a constant, "size" becomes the left-shift value
366 * for setting word_size.
367 */
368 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700369
Carolyn Wyborny925b11f2012-07-31 01:01:23 +0000370 /*
371 * Check for invalid size
372 */
373 if ((hw->mac.type == e1000_82576) && (size > 15)) {
374 pr_notice("The NVM size is not valid, defaulting to 32K\n");
375 size = 15;
376 }
377
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000378 nvm->word_size = 1 << size;
379 if (hw->mac.type < e1000_i210) {
380 nvm->opcode_bits = 8;
381 nvm->delay_usec = 1;
382 switch (nvm->override) {
383 case e1000_nvm_override_spi_large:
384 nvm->page_size = 32;
385 nvm->address_bits = 16;
386 break;
387 case e1000_nvm_override_spi_small:
388 nvm->page_size = 8;
389 nvm->address_bits = 8;
390 break;
391 default:
392 nvm->page_size = eecd
393 & E1000_EECD_ADDR_BITS ? 32 : 8;
394 nvm->address_bits = eecd
395 & E1000_EECD_ADDR_BITS ? 16 : 8;
396 break;
397 }
398 if (nvm->word_size == (1 << 15))
399 nvm->page_size = 128;
400
401 nvm->type = e1000_nvm_eeprom_spi;
402 } else
403 nvm->type = e1000_nvm_flash_hw;
404
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800405 /* NVM Function Pointers */
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800406 switch (hw->mac.type) {
407 case e1000_82580:
408 nvm->ops.validate = igb_validate_nvm_checksum_82580;
409 nvm->ops.update = igb_update_nvm_checksum_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000410 nvm->ops.acquire = igb_acquire_nvm_82575;
411 nvm->ops.release = igb_release_nvm_82575;
412 if (nvm->word_size < (1 << 15))
413 nvm->ops.read = igb_read_nvm_eerd;
414 else
415 nvm->ops.read = igb_read_nvm_spi;
416 nvm->ops.write = igb_write_nvm_spi;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800417 break;
418 case e1000_i350:
419 nvm->ops.validate = igb_validate_nvm_checksum_i350;
420 nvm->ops.update = igb_update_nvm_checksum_i350;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000421 nvm->ops.acquire = igb_acquire_nvm_82575;
422 nvm->ops.release = igb_release_nvm_82575;
423 if (nvm->word_size < (1 << 15))
424 nvm->ops.read = igb_read_nvm_eerd;
425 else
426 nvm->ops.read = igb_read_nvm_spi;
427 nvm->ops.write = igb_write_nvm_spi;
428 break;
429 case e1000_i210:
430 nvm->ops.validate = igb_validate_nvm_checksum_i210;
431 nvm->ops.update = igb_update_nvm_checksum_i210;
432 nvm->ops.acquire = igb_acquire_nvm_i210;
433 nvm->ops.release = igb_release_nvm_i210;
434 nvm->ops.read = igb_read_nvm_srrd_i210;
Carolyn Wybornyede41262012-10-24 03:56:21 +0000435 nvm->ops.write = igb_write_nvm_srwr_i210;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000436 nvm->ops.valid_led_default = igb_valid_led_default_i210;
437 break;
438 case e1000_i211:
439 nvm->ops.acquire = igb_acquire_nvm_i210;
440 nvm->ops.release = igb_release_nvm_i210;
441 nvm->ops.read = igb_read_nvm_i211;
442 nvm->ops.valid_led_default = igb_valid_led_default_i210;
443 nvm->ops.validate = NULL;
444 nvm->ops.update = NULL;
445 nvm->ops.write = NULL;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800446 break;
447 default:
448 nvm->ops.validate = igb_validate_nvm_checksum;
449 nvm->ops.update = igb_update_nvm_checksum;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000450 nvm->ops.acquire = igb_acquire_nvm_82575;
451 nvm->ops.release = igb_release_nvm_82575;
452 if (nvm->word_size < (1 << 15))
453 nvm->ops.read = igb_read_nvm_eerd;
454 else
455 nvm->ops.read = igb_read_nvm_spi;
456 nvm->ops.write = igb_write_nvm_spi;
457 break;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800458 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800459
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000460 /* if part supports SR-IOV then initialize mailbox parameters */
461 switch (mac->type) {
462 case e1000_82576:
463 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000464 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000465 break;
466 default:
467 break;
468 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000469
Auke Kok9d5c8242008-01-24 02:22:38 -0800470 /* setup PHY parameters */
471 if (phy->media_type != e1000_media_type_copper) {
472 phy->type = e1000_phy_none;
473 return 0;
474 }
475
476 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
477 phy->reset_delay_us = 100;
478
Alexander Duyck99870a72010-08-03 11:50:08 +0000479 ctrl_ext = rd32(E1000_CTRL_EXT);
480
Auke Kok9d5c8242008-01-24 02:22:38 -0800481 /* PHY function pointers */
Alexander Duyck99870a72010-08-03 11:50:08 +0000482 if (igb_sgmii_active_82575(hw)) {
Nick Nunley4085f742010-07-26 13:15:06 +0000483 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
Alexander Duyck99870a72010-08-03 11:50:08 +0000484 ctrl_ext |= E1000_CTRL_I2C_ENA;
485 } else {
Nick Nunley4085f742010-07-26 13:15:06 +0000486 phy->ops.reset = igb_phy_hw_reset;
Alexander Duyck99870a72010-08-03 11:50:08 +0000487 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
488 }
489
490 wr32(E1000_CTRL_EXT, ctrl_ext);
491 igb_reset_mdicnfg_82580(hw);
Nick Nunley4085f742010-07-26 13:15:06 +0000492
493 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
494 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
495 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000496 } else if ((hw->mac.type == e1000_82580)
497 || (hw->mac.type == e1000_i350)) {
Nick Nunley4085f742010-07-26 13:15:06 +0000498 phy->ops.read_reg = igb_read_phy_reg_82580;
499 phy->ops.write_reg = igb_write_phy_reg_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000500 } else if (hw->phy.type >= e1000_phy_i210) {
501 phy->ops.read_reg = igb_read_phy_reg_gs40g;
502 phy->ops.write_reg = igb_write_phy_reg_gs40g;
Auke Kok9d5c8242008-01-24 02:22:38 -0800503 } else {
Nick Nunley4085f742010-07-26 13:15:06 +0000504 phy->ops.read_reg = igb_read_phy_reg_igp;
505 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800506 }
507
Alexander Duyck19e588e2009-07-07 13:01:55 +0000508 /* set lan id */
509 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
510 E1000_STATUS_FUNC_SHIFT;
511
Auke Kok9d5c8242008-01-24 02:22:38 -0800512 /* Set phy->phy_addr and phy->id. */
513 ret_val = igb_get_phy_id_82575(hw);
514 if (ret_val)
515 return ret_val;
516
517 /* Verify phy id and set remaining function pointers */
518 switch (phy->id) {
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000519 case I347AT4_E_PHY_ID:
520 case M88E1112_E_PHY_ID:
Auke Kok9d5c8242008-01-24 02:22:38 -0800521 case M88E1111_I_PHY_ID:
522 phy->type = e1000_phy_m88;
523 phy->ops.get_phy_info = igb_get_phy_info_m88;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000524
525 if (phy->id == I347AT4_E_PHY_ID ||
526 phy->id == M88E1112_E_PHY_ID)
527 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
528 else
529 phy->ops.get_cable_length = igb_get_cable_length_m88;
530
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000531 if (phy->id == I210_I_PHY_ID) {
532 phy->ops.get_cable_length =
533 igb_get_cable_length_m88_gen2;
534 phy->ops.set_d0_lplu_state =
535 igb_set_d0_lplu_state_82580;
536 phy->ops.set_d3_lplu_state =
537 igb_set_d3_lplu_state_82580;
538 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800539 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
540 break;
541 case IGP03E1000_E_PHY_ID:
542 phy->type = e1000_phy_igp_3;
543 phy->ops.get_phy_info = igb_get_phy_info_igp;
544 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
545 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
546 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
547 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
548 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000549 case I82580_I_PHY_ID:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000550 case I350_I_PHY_ID:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000551 phy->type = e1000_phy_82580;
552 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580;
553 phy->ops.get_cable_length = igb_get_cable_length_82580;
554 phy->ops.get_phy_info = igb_get_phy_info_82580;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000555 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
556 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000557 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000558 case I210_I_PHY_ID:
559 phy->type = e1000_phy_i210;
560 phy->ops.get_phy_info = igb_get_phy_info_m88;
561 phy->ops.check_polarity = igb_check_polarity_m88;
562 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
563 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
564 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
565 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
566 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800567 default:
568 return -E1000_ERR_PHY;
569 }
570
571 return 0;
572}
573
574/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700575 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800576 * @hw: pointer to the HW structure
577 *
578 * Acquire access rights to the correct PHY. This is a
579 * function pointer entry point called by the api module.
580 **/
581static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
582{
Alexander Duyck008c3422009-10-05 06:32:07 +0000583 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800584
Alexander Duyck008c3422009-10-05 06:32:07 +0000585 if (hw->bus.func == E1000_FUNC_1)
586 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000587 else if (hw->bus.func == E1000_FUNC_2)
588 mask = E1000_SWFW_PHY2_SM;
589 else if (hw->bus.func == E1000_FUNC_3)
590 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800591
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000592 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800593}
594
595/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700596 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800597 * @hw: pointer to the HW structure
598 *
599 * A wrapper to release access rights to the correct PHY. This is a
600 * function pointer entry point called by the api module.
601 **/
602static void igb_release_phy_82575(struct e1000_hw *hw)
603{
Alexander Duyck008c3422009-10-05 06:32:07 +0000604 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800605
Alexander Duyck008c3422009-10-05 06:32:07 +0000606 if (hw->bus.func == E1000_FUNC_1)
607 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000608 else if (hw->bus.func == E1000_FUNC_2)
609 mask = E1000_SWFW_PHY2_SM;
610 else if (hw->bus.func == E1000_FUNC_3)
611 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000612
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000613 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800614}
615
616/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700617 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800618 * @hw: pointer to the HW structure
619 * @offset: register offset to be read
620 * @data: pointer to the read data
621 *
622 * Reads the PHY register at offset using the serial gigabit media independent
623 * interface and stores the retrieved information in data.
624 **/
625static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
626 u16 *data)
627{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000628 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800629
630 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700631 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000632 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800633 }
634
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000635 ret_val = hw->phy.ops.acquire(hw);
636 if (ret_val)
637 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800638
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000639 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800640
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000641 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800642
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000643out:
644 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800645}
646
647/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700648 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800649 * @hw: pointer to the HW structure
650 * @offset: register offset to write to
651 * @data: data to write at register offset
652 *
653 * Writes the data to PHY register at the offset using the serial gigabit
654 * media independent interface.
655 **/
656static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
657 u16 data)
658{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000659 s32 ret_val = -E1000_ERR_PARAM;
660
Auke Kok9d5c8242008-01-24 02:22:38 -0800661
662 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700663 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000664 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800665 }
666
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000667 ret_val = hw->phy.ops.acquire(hw);
668 if (ret_val)
669 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800670
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000671 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800672
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000673 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800674
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000675out:
676 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800677}
678
679/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700680 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800681 * @hw: pointer to the HW structure
682 *
Auke Kok652fff32008-06-27 11:00:18 -0700683 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800684 * sgmi interface.
685 **/
686static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
687{
688 struct e1000_phy_info *phy = &hw->phy;
689 s32 ret_val = 0;
690 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000691 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000692 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800693
694 /*
695 * For SGMII PHYs, we try the list of possible addresses until
696 * we find one that works. For non-SGMII PHYs
697 * (e.g. integrated copper PHYs), an address of 1 should
698 * work. The result of this function should mean phy->phy_addr
699 * and phy->id are set correctly.
700 */
701 if (!(igb_sgmii_active_82575(hw))) {
702 phy->addr = 1;
703 ret_val = igb_get_phy_id(hw);
704 goto out;
705 }
706
Nick Nunley4085f742010-07-26 13:15:06 +0000707 if (igb_sgmii_uses_mdio_82575(hw)) {
708 switch (hw->mac.type) {
709 case e1000_82575:
710 case e1000_82576:
711 mdic = rd32(E1000_MDIC);
712 mdic &= E1000_MDIC_PHY_MASK;
713 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
714 break;
715 case e1000_82580:
716 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000717 case e1000_i210:
718 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000719 mdic = rd32(E1000_MDICNFG);
720 mdic &= E1000_MDICNFG_PHY_MASK;
721 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
722 break;
723 default:
724 ret_val = -E1000_ERR_PHY;
725 goto out;
726 break;
727 }
728 ret_val = igb_get_phy_id(hw);
729 goto out;
730 }
731
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000732 /* Power on sgmii phy if it is disabled */
733 ctrl_ext = rd32(E1000_CTRL_EXT);
734 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
735 wrfl();
736 msleep(300);
737
Auke Kok9d5c8242008-01-24 02:22:38 -0800738 /*
739 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
740 * Therefore, we need to test 1-7
741 */
742 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
743 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
744 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700745 hw_dbg("Vendor ID 0x%08X read at address %u\n",
746 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800747 /*
748 * At the time of this writing, The M88 part is
749 * the only supported SGMII PHY product.
750 */
751 if (phy_id == M88_VENDOR)
752 break;
753 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700754 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800755 }
756 }
757
758 /* A valid PHY type couldn't be found. */
759 if (phy->addr == 8) {
760 phy->addr = 0;
761 ret_val = -E1000_ERR_PHY;
762 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000763 } else {
764 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800765 }
766
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000767 /* restore previous sfp cage power state */
768 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800769
770out:
771 return ret_val;
772}
773
774/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700775 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800776 * @hw: pointer to the HW structure
777 *
778 * Resets the PHY using the serial gigabit media independent interface.
779 **/
780static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
781{
782 s32 ret_val;
783
784 /*
785 * This isn't a true "hard" reset, but is the only reset
786 * available to us at this time.
787 */
788
Auke Kok652fff32008-06-27 11:00:18 -0700789 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800790
791 /*
792 * SFP documentation requires the following to configure the SPF module
793 * to work on SGMII. No further documentation is given.
794 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000795 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800796 if (ret_val)
797 goto out;
798
799 ret_val = igb_phy_sw_reset(hw);
800
801out:
802 return ret_val;
803}
804
805/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700806 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800807 * @hw: pointer to the HW structure
808 * @active: true to enable LPLU, false to disable
809 *
810 * Sets the LPLU D0 state according to the active flag. When
811 * activating LPLU this function also disables smart speed
812 * and vice versa. LPLU will not be activated unless the
813 * device autonegotiation advertisement meets standards of
814 * either 10 or 10/100 or 10/100/1000 at all duplexes.
815 * This is a function pointer entry point only called by
816 * PHY setup routines.
817 **/
818static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
819{
820 struct e1000_phy_info *phy = &hw->phy;
821 s32 ret_val;
822 u16 data;
823
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000824 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800825 if (ret_val)
826 goto out;
827
828 if (active) {
829 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000830 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700831 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800832 if (ret_val)
833 goto out;
834
835 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000836 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700837 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800838 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000839 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700840 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800841 if (ret_val)
842 goto out;
843 } else {
844 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000845 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700846 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800847 /*
848 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
849 * during Dx states where the power conservation is most
850 * important. During driver activity we should enable
851 * SmartSpeed, so performance is maintained.
852 */
853 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000854 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700855 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800856 if (ret_val)
857 goto out;
858
859 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000860 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700861 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800862 if (ret_val)
863 goto out;
864 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000865 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700866 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800867 if (ret_val)
868 goto out;
869
870 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000871 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700872 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800873 if (ret_val)
874 goto out;
875 }
876 }
877
878out:
879 return ret_val;
880}
881
882/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000883 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
884 * @hw: pointer to the HW structure
885 * @active: true to enable LPLU, false to disable
886 *
887 * Sets the LPLU D0 state according to the active flag. When
888 * activating LPLU this function also disables smart speed
889 * and vice versa. LPLU will not be activated unless the
890 * device autonegotiation advertisement meets standards of
891 * either 10 or 10/100 or 10/100/1000 at all duplexes.
892 * This is a function pointer entry point only called by
893 * PHY setup routines.
894 **/
895static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
896{
897 struct e1000_phy_info *phy = &hw->phy;
898 s32 ret_val = 0;
899 u16 data;
900
901 data = rd32(E1000_82580_PHY_POWER_MGMT);
902
903 if (active) {
904 data |= E1000_82580_PM_D0_LPLU;
905
906 /* When LPLU is enabled, we should disable SmartSpeed */
907 data &= ~E1000_82580_PM_SPD;
908 } else {
909 data &= ~E1000_82580_PM_D0_LPLU;
910
911 /*
912 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
913 * during Dx states where the power conservation is most
914 * important. During driver activity we should enable
915 * SmartSpeed, so performance is maintained.
916 */
917 if (phy->smart_speed == e1000_smart_speed_on)
918 data |= E1000_82580_PM_SPD;
919 else if (phy->smart_speed == e1000_smart_speed_off)
920 data &= ~E1000_82580_PM_SPD; }
921
922 wr32(E1000_82580_PHY_POWER_MGMT, data);
923 return ret_val;
924}
925
926/**
927 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
928 * @hw: pointer to the HW structure
929 * @active: boolean used to enable/disable lplu
930 *
931 * Success returns 0, Failure returns 1
932 *
933 * The low power link up (lplu) state is set to the power management level D3
934 * and SmartSpeed is disabled when active is true, else clear lplu for D3
935 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
936 * is used during Dx states where the power conservation is most important.
937 * During driver activity, SmartSpeed should be enabled so performance is
938 * maintained.
939 **/
940s32 igb_set_d3_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_D3_LPLU;
950 /*
951 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
952 * during Dx states where the power conservation is most
953 * important. During driver activity we should enable
954 * SmartSpeed, so performance is maintained.
955 */
956 if (phy->smart_speed == e1000_smart_speed_on)
957 data |= E1000_82580_PM_SPD;
958 else if (phy->smart_speed == e1000_smart_speed_off)
959 data &= ~E1000_82580_PM_SPD;
960 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
961 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
962 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
963 data |= E1000_82580_PM_D3_LPLU;
964 /* When LPLU is enabled, we should disable SmartSpeed */
965 data &= ~E1000_82580_PM_SPD;
966 }
967
968 wr32(E1000_82580_PHY_POWER_MGMT, data);
969 return ret_val;
970}
971
972/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700973 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800974 * @hw: pointer to the HW structure
975 *
Auke Kok652fff32008-06-27 11:00:18 -0700976 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800977 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
978 * Return successful if access grant bit set, else clear the request for
979 * EEPROM access and return -E1000_ERR_NVM (-1).
980 **/
981static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
982{
983 s32 ret_val;
984
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000985 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800986 if (ret_val)
987 goto out;
988
989 ret_val = igb_acquire_nvm(hw);
990
991 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000992 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800993
994out:
995 return ret_val;
996}
997
998/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700999 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 * @hw: pointer to the HW structure
1001 *
1002 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1003 * then release the semaphores acquired.
1004 **/
1005static void igb_release_nvm_82575(struct e1000_hw *hw)
1006{
1007 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001008 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001009}
1010
1011/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001012 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001013 * @hw: pointer to the HW structure
1014 * @mask: specifies which semaphore to acquire
1015 *
1016 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1017 * will also specify which port we're acquiring the lock for.
1018 **/
1019static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1020{
1021 u32 swfw_sync;
1022 u32 swmask = mask;
1023 u32 fwmask = mask << 16;
1024 s32 ret_val = 0;
1025 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
1026
1027 while (i < timeout) {
1028 if (igb_get_hw_semaphore(hw)) {
1029 ret_val = -E1000_ERR_SWFW_SYNC;
1030 goto out;
1031 }
1032
1033 swfw_sync = rd32(E1000_SW_FW_SYNC);
1034 if (!(swfw_sync & (fwmask | swmask)))
1035 break;
1036
1037 /*
1038 * Firmware currently using resource (fwmask)
1039 * or other software thread using resource (swmask)
1040 */
1041 igb_put_hw_semaphore(hw);
1042 mdelay(5);
1043 i++;
1044 }
1045
1046 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001047 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001048 ret_val = -E1000_ERR_SWFW_SYNC;
1049 goto out;
1050 }
1051
1052 swfw_sync |= swmask;
1053 wr32(E1000_SW_FW_SYNC, swfw_sync);
1054
1055 igb_put_hw_semaphore(hw);
1056
1057out:
1058 return ret_val;
1059}
1060
1061/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001062 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001063 * @hw: pointer to the HW structure
1064 * @mask: specifies which semaphore to acquire
1065 *
1066 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1067 * will also specify which port we're releasing the lock for.
1068 **/
1069static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1070{
1071 u32 swfw_sync;
1072
1073 while (igb_get_hw_semaphore(hw) != 0);
1074 /* Empty */
1075
1076 swfw_sync = rd32(E1000_SW_FW_SYNC);
1077 swfw_sync &= ~mask;
1078 wr32(E1000_SW_FW_SYNC, swfw_sync);
1079
1080 igb_put_hw_semaphore(hw);
1081}
1082
1083/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001084 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001085 * @hw: pointer to the HW structure
1086 *
1087 * Read the management control register for the config done bit for
1088 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1089 * to read the config done bit, so an error is *ONLY* logged and returns
1090 * 0. If we were to return with error, EEPROM-less silicon
1091 * would not be able to be reset or change link.
1092 **/
1093static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1094{
1095 s32 timeout = PHY_CFG_TIMEOUT;
1096 s32 ret_val = 0;
1097 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1098
1099 if (hw->bus.func == 1)
1100 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001101 else if (hw->bus.func == E1000_FUNC_2)
1102 mask = E1000_NVM_CFG_DONE_PORT_2;
1103 else if (hw->bus.func == E1000_FUNC_3)
1104 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001105
1106 while (timeout) {
1107 if (rd32(E1000_EEMNGCTL) & mask)
1108 break;
1109 msleep(1);
1110 timeout--;
1111 }
1112 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001113 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001114
1115 /* If EEPROM is not marked present, init the PHY manually */
1116 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1117 (hw->phy.type == e1000_phy_igp_3))
1118 igb_phy_init_script_igp3(hw);
1119
1120 return ret_val;
1121}
1122
1123/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001124 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 * @hw: pointer to the HW structure
1126 *
1127 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1128 * use the generic interface for determining link.
1129 **/
1130static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1131{
1132 s32 ret_val;
1133 u16 speed, duplex;
1134
Alexander Duyck70d92f82009-10-05 06:31:47 +00001135 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001136 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001137 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001138 /*
1139 * Use this flag to determine if link needs to be checked or
1140 * not. If we have link clear the flag so that we do not
1141 * continue to check for link.
1142 */
1143 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001144
1145 /* Configure Flow Control now that Auto-Neg has completed.
1146 * First, we need to restore the desired flow control
1147 * settings because we may have had to re-autoneg with a
1148 * different link partner.
1149 */
1150 ret_val = igb_config_fc_after_link_up(hw);
1151 if (ret_val)
1152 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001153 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001154 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001155 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001156
1157 return ret_val;
1158}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001159
Auke Kok9d5c8242008-01-24 02:22:38 -08001160/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001161 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1162 * @hw: pointer to the HW structure
1163 **/
1164void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1165{
1166 u32 reg;
1167
1168
1169 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1170 !igb_sgmii_active_82575(hw))
1171 return;
1172
1173 /* Enable PCS to turn on link */
1174 reg = rd32(E1000_PCS_CFG0);
1175 reg |= E1000_PCS_CFG_PCS_EN;
1176 wr32(E1000_PCS_CFG0, reg);
1177
1178 /* Power up the laser */
1179 reg = rd32(E1000_CTRL_EXT);
1180 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1181 wr32(E1000_CTRL_EXT, reg);
1182
1183 /* flush the write to verify completion */
1184 wrfl();
1185 msleep(1);
1186}
1187
1188/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001189 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001190 * @hw: pointer to the HW structure
1191 * @speed: stores the current speed
1192 * @duplex: stores the current duplex
1193 *
Auke Kok652fff32008-06-27 11:00:18 -07001194 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 * duplex, then store the values in the pointers provided.
1196 **/
1197static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1198 u16 *duplex)
1199{
1200 struct e1000_mac_info *mac = &hw->mac;
1201 u32 pcs;
1202
1203 /* Set up defaults for the return values of this function */
1204 mac->serdes_has_link = false;
1205 *speed = 0;
1206 *duplex = 0;
1207
1208 /*
1209 * Read the PCS Status register for link state. For non-copper mode,
1210 * the status register is not accurate. The PCS status register is
1211 * used instead.
1212 */
1213 pcs = rd32(E1000_PCS_LSTAT);
1214
1215 /*
1216 * The link up bit determines when link is up on autoneg. The sync ok
1217 * gets set once both sides sync up and agree upon link. Stable link
1218 * can be determined by checking for both link up and link sync ok
1219 */
1220 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1221 mac->serdes_has_link = true;
1222
1223 /* Detect and store PCS speed */
1224 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
1225 *speed = SPEED_1000;
1226 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
1227 *speed = SPEED_100;
1228 } else {
1229 *speed = SPEED_10;
1230 }
1231
1232 /* Detect and store PCS duplex */
1233 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
1234 *duplex = FULL_DUPLEX;
1235 } else {
1236 *duplex = HALF_DUPLEX;
1237 }
1238 }
1239
1240 return 0;
1241}
1242
1243/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001244 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001245 * @hw: pointer to the HW structure
1246 *
1247 * In the case of fiber serdes, shut down optics and PCS on driver unload
1248 * when management pass thru is not enabled.
1249 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001250void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001251{
1252 u32 reg;
1253
Nick Nunley53c992f2010-02-17 01:01:40 +00001254 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001255 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001256 return;
1257
Nick Nunley53c992f2010-02-17 01:01:40 +00001258 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001259 /* Disable PCS to turn off link */
1260 reg = rd32(E1000_PCS_CFG0);
1261 reg &= ~E1000_PCS_CFG_PCS_EN;
1262 wr32(E1000_PCS_CFG0, reg);
1263
1264 /* shutdown the laser */
1265 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001266 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001267 wr32(E1000_CTRL_EXT, reg);
1268
1269 /* flush the write to verify completion */
1270 wrfl();
1271 msleep(1);
1272 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001273}
1274
1275/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001276 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001277 * @hw: pointer to the HW structure
1278 *
1279 * This resets the hardware into a known state. This is a
1280 * function pointer entry point called by the api module.
1281 **/
1282static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1283{
1284 u32 ctrl, icr;
1285 s32 ret_val;
1286
1287 /*
1288 * Prevent the PCI-E bus from sticking if there is no TLP connection
1289 * on the last TLP read/write transaction when MAC is reset.
1290 */
1291 ret_val = igb_disable_pcie_master(hw);
1292 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001293 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001294
Alexander Duyck009bc062009-07-23 18:08:35 +00001295 /* set the completion timeout for interface */
1296 ret_val = igb_set_pcie_completion_timeout(hw);
1297 if (ret_val) {
1298 hw_dbg("PCI-E Set completion timeout has failed.\n");
1299 }
1300
Auke Kok652fff32008-06-27 11:00:18 -07001301 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001302 wr32(E1000_IMC, 0xffffffff);
1303
1304 wr32(E1000_RCTL, 0);
1305 wr32(E1000_TCTL, E1000_TCTL_PSP);
1306 wrfl();
1307
1308 msleep(10);
1309
1310 ctrl = rd32(E1000_CTRL);
1311
Auke Kok652fff32008-06-27 11:00:18 -07001312 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001313 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1314
1315 ret_val = igb_get_auto_rd_done(hw);
1316 if (ret_val) {
1317 /*
1318 * When auto config read does not complete, do not
1319 * return with an error. This can happen in situations
1320 * where there is no eeprom and prevents getting link.
1321 */
Auke Kok652fff32008-06-27 11:00:18 -07001322 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001323 }
1324
1325 /* If EEPROM is not present, run manual init scripts */
1326 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1327 igb_reset_init_script_82575(hw);
1328
1329 /* Clear any pending interrupt events. */
1330 wr32(E1000_IMC, 0xffffffff);
1331 icr = rd32(E1000_ICR);
1332
Alexander Duyck5ac16652009-07-23 18:09:12 +00001333 /* Install any alternate MAC address into RAR0 */
1334 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001335
1336 return ret_val;
1337}
1338
1339/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001340 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001341 * @hw: pointer to the HW structure
1342 *
1343 * This inits the hardware readying it for operation.
1344 **/
1345static s32 igb_init_hw_82575(struct e1000_hw *hw)
1346{
1347 struct e1000_mac_info *mac = &hw->mac;
1348 s32 ret_val;
1349 u16 i, rar_count = mac->rar_entry_count;
1350
1351 /* Initialize identification LED */
1352 ret_val = igb_id_led_init(hw);
1353 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001354 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001355 /* This is not fatal and we should not stop init due to this */
1356 }
1357
1358 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001359 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001360 if (hw->mac.type == e1000_i350)
1361 igb_clear_vfta_i350(hw);
1362 else
1363 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001364
1365 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001366 igb_init_rx_addrs(hw, rar_count);
1367
Auke Kok9d5c8242008-01-24 02:22:38 -08001368 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001369 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001370 for (i = 0; i < mac->mta_reg_count; i++)
1371 array_wr32(E1000_MTA, i, 0);
1372
Alexander Duyck68d480c2009-10-05 06:33:08 +00001373 /* Zero out the Unicast HASH table */
1374 hw_dbg("Zeroing the UTA\n");
1375 for (i = 0; i < mac->uta_reg_count; i++)
1376 array_wr32(E1000_UTA, i, 0);
1377
Auke Kok9d5c8242008-01-24 02:22:38 -08001378 /* Setup link and flow control */
1379 ret_val = igb_setup_link(hw);
1380
1381 /*
1382 * Clear all of the statistics registers (clear on read). It is
1383 * important that we do this after we have tried to establish link
1384 * because the symbol error count will increment wildly if there
1385 * is no link.
1386 */
1387 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001388 return ret_val;
1389}
1390
1391/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001392 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001393 * @hw: pointer to the HW structure
1394 *
1395 * Configures the link for auto-neg or forced speed and duplex. Then we check
1396 * for link, once link is established calls to configure collision distance
1397 * and flow control are called.
1398 **/
1399static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1400{
Alexander Duyck12645a12009-07-23 18:08:16 +00001401 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001402 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001403 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001404
1405 ctrl = rd32(E1000_CTRL);
1406 ctrl |= E1000_CTRL_SLU;
1407 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1408 wr32(E1000_CTRL, ctrl);
1409
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001410 /* Clear Go Link Disconnect bit */
1411 if (hw->mac.type >= e1000_82580) {
1412 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1413 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1414 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
1415 }
1416
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001417 ret_val = igb_setup_serdes_link_82575(hw);
1418 if (ret_val)
1419 goto out;
1420
1421 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001422 /* allow time for SFP cage time to power up phy */
1423 msleep(300);
1424
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001425 ret_val = hw->phy.ops.reset(hw);
1426 if (ret_val) {
1427 hw_dbg("Error resetting the PHY.\n");
1428 goto out;
1429 }
1430 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001431 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001432 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001433 case e1000_phy_m88:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001434 if (hw->phy.id == I347AT4_E_PHY_ID ||
1435 hw->phy.id == M88E1112_E_PHY_ID)
1436 ret_val = igb_copper_link_setup_m88_gen2(hw);
1437 else
1438 ret_val = igb_copper_link_setup_m88(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001439 break;
1440 case e1000_phy_igp_3:
1441 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001442 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001443 case e1000_phy_82580:
1444 ret_val = igb_copper_link_setup_82580(hw);
1445 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 default:
1447 ret_val = -E1000_ERR_PHY;
1448 break;
1449 }
1450
1451 if (ret_val)
1452 goto out;
1453
Alexander Duyck81fadd82009-10-05 06:35:03 +00001454 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001455out:
1456 return ret_val;
1457}
1458
1459/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001460 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001461 * @hw: pointer to the HW structure
1462 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001463 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1464 * used on copper connections where the serialized gigabit media independent
1465 * interface (sgmii), or serdes fiber is being used. Configures the link
1466 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001467 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001468static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001469{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001470 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001471 bool pcs_autoneg;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001472 s32 ret_val = E1000_SUCCESS;
1473 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001474
1475 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1476 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001477 return ret_val;
1478
Auke Kok9d5c8242008-01-24 02:22:38 -08001479
1480 /*
1481 * On the 82575, SerDes loopback mode persists until it is
1482 * explicitly turned off or a power cycle is performed. A read to
1483 * the register does not indicate its status. Therefore, we ensure
1484 * loopback mode is disabled during initialization.
1485 */
1486 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1487
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001488 /* power on the sfp cage if present */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001489 ctrl_ext = rd32(E1000_CTRL_EXT);
1490 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1491 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001492
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001493 ctrl_reg = rd32(E1000_CTRL);
1494 ctrl_reg |= E1000_CTRL_SLU;
1495
1496 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1497 /* set both sw defined pins */
1498 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1499
1500 /* Set switch control to serdes energy detect */
1501 reg = rd32(E1000_CONNSW);
1502 reg |= E1000_CONNSW_ENRGSRC;
1503 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001504 }
1505
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001506 reg = rd32(E1000_PCS_LCTL);
1507
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001508 /* default pcs_autoneg to the same setting as mac autoneg */
1509 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001510
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001511 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1512 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1513 /* sgmii mode lets the phy handle forcing speed/duplex */
1514 pcs_autoneg = true;
1515 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001516 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001517 break;
1518 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1519 /* disable PCS autoneg and support parallel detect only */
1520 pcs_autoneg = false;
1521 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001522 if (hw->mac.type == e1000_82575 ||
1523 hw->mac.type == e1000_82576) {
1524 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1525 if (ret_val) {
1526 printk(KERN_DEBUG "NVM Read Error\n\n");
1527 return ret_val;
1528 }
1529
1530 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1531 pcs_autoneg = false;
1532 }
1533
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001534 /*
1535 * non-SGMII modes only supports a speed of 1000/Full for the
1536 * link so it is best to just force the MAC and let the pcs
1537 * link either autoneg or be forced to 1000/Full
1538 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001539 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1540 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001541
1542 /* set speed of 1000/Full if speed/duplex is forced */
1543 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1544 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001545 }
1546
1547 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001548
1549 /*
1550 * New SerDes mode allows for forcing speed or autonegotiating speed
1551 * at 1gb. Autoneg should be default set by most drivers. This is the
1552 * mode that will be compatible with older link partners and switches.
1553 * However, both are supported by the hardware and some drivers/tools.
1554 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001555 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1556 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1557
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001558 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001559 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001560 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001561 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001562
1563 /* Disable force flow control for autoneg */
1564 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1565
1566 /* Configure flow control advertisement for autoneg */
1567 anadv_reg = rd32(E1000_PCS_ANADV);
1568 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1569 switch (hw->fc.requested_mode) {
1570 case e1000_fc_full:
1571 case e1000_fc_rx_pause:
1572 anadv_reg |= E1000_TXCW_ASM_DIR;
1573 anadv_reg |= E1000_TXCW_PAUSE;
1574 break;
1575 case e1000_fc_tx_pause:
1576 anadv_reg |= E1000_TXCW_ASM_DIR;
1577 break;
1578 default:
1579 break;
1580 }
1581 wr32(E1000_PCS_ANADV, anadv_reg);
1582
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001583 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001584 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001585 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001586 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001587
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001588 /* Force flow control for forced link */
1589 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1590
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001591 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001592 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001593
Auke Kok9d5c8242008-01-24 02:22:38 -08001594 wr32(E1000_PCS_LCTL, reg);
1595
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001596 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001597 igb_force_mac_fc(hw);
1598
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001599 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001600}
1601
1602/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001603 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001604 * @hw: pointer to the HW structure
1605 *
1606 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1607 * which can be enabled for use in the embedded applications. Simply
1608 * return the current state of the sgmii interface.
1609 **/
1610static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1611{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001612 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001613 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001614}
1615
1616/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001617 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001618 * @hw: pointer to the HW structure
1619 *
1620 * Inits recommended HW defaults after a reset when there is no EEPROM
1621 * detected. This is only for the 82575.
1622 **/
1623static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1624{
1625 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001626 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001627 /* SerDes configuration via SERDESCTRL */
1628 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1629 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1630 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1631 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1632
1633 /* CCM configuration via CCMCTL register */
1634 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1635 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1636
1637 /* PCIe lanes configuration */
1638 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1639 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1640 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1641 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1642
1643 /* PCIe PLL Configuration */
1644 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1645 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1646 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1647 }
1648
1649 return 0;
1650}
1651
1652/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001653 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001654 * @hw: pointer to the HW structure
1655 **/
1656static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1657{
1658 s32 ret_val = 0;
1659
Alexander Duyck22896632009-10-05 06:34:25 +00001660 /*
1661 * If there's an alternate MAC address place it in RAR0
1662 * so that it will override the Si installed default perm
1663 * address.
1664 */
1665 ret_val = igb_check_alt_mac_addr(hw);
1666 if (ret_val)
1667 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001668
Alexander Duyck22896632009-10-05 06:34:25 +00001669 ret_val = igb_read_mac_addr(hw);
1670
1671out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001672 return ret_val;
1673}
1674
1675/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001676 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1677 * @hw: pointer to the HW structure
1678 *
1679 * In the case of a PHY power down to save power, or to turn off link during a
1680 * driver unload, or wake on lan is not enabled, remove the link.
1681 **/
1682void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1683{
1684 /* If the management interface is not enabled, then power down */
1685 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1686 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001687}
1688
1689/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001690 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001691 * @hw: pointer to the HW structure
1692 *
1693 * Clears the hardware counters by reading the counter registers.
1694 **/
1695static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1696{
Auke Kok9d5c8242008-01-24 02:22:38 -08001697 igb_clear_hw_cntrs_base(hw);
1698
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001699 rd32(E1000_PRC64);
1700 rd32(E1000_PRC127);
1701 rd32(E1000_PRC255);
1702 rd32(E1000_PRC511);
1703 rd32(E1000_PRC1023);
1704 rd32(E1000_PRC1522);
1705 rd32(E1000_PTC64);
1706 rd32(E1000_PTC127);
1707 rd32(E1000_PTC255);
1708 rd32(E1000_PTC511);
1709 rd32(E1000_PTC1023);
1710 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001711
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001712 rd32(E1000_ALGNERRC);
1713 rd32(E1000_RXERRC);
1714 rd32(E1000_TNCRS);
1715 rd32(E1000_CEXTERR);
1716 rd32(E1000_TSCTC);
1717 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001718
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001719 rd32(E1000_MGTPRC);
1720 rd32(E1000_MGTPDC);
1721 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001722
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001723 rd32(E1000_IAC);
1724 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001725
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001726 rd32(E1000_ICRXPTC);
1727 rd32(E1000_ICRXATC);
1728 rd32(E1000_ICTXPTC);
1729 rd32(E1000_ICTXATC);
1730 rd32(E1000_ICTXQEC);
1731 rd32(E1000_ICTXQMTC);
1732 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001733
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001734 rd32(E1000_CBTMPC);
1735 rd32(E1000_HTDPMC);
1736 rd32(E1000_CBRMPC);
1737 rd32(E1000_RPTHC);
1738 rd32(E1000_HGPTC);
1739 rd32(E1000_HTCBDPC);
1740 rd32(E1000_HGORCL);
1741 rd32(E1000_HGORCH);
1742 rd32(E1000_HGOTCL);
1743 rd32(E1000_HGOTCH);
1744 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001745
1746 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001747 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1748 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001749 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001750}
1751
Alexander Duyck662d7202008-06-27 11:00:29 -07001752/**
1753 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1754 * @hw: pointer to the HW structure
1755 *
1756 * After rx enable if managability is enabled then there is likely some
1757 * bad data at the start of the fifo and possibly in the DMA fifo. This
1758 * function clears the fifos and flushes any packets that came in as rx was
1759 * being enabled.
1760 **/
1761void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1762{
1763 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1764 int i, ms_wait;
1765
1766 if (hw->mac.type != e1000_82575 ||
1767 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1768 return;
1769
1770 /* Disable all RX queues */
1771 for (i = 0; i < 4; i++) {
1772 rxdctl[i] = rd32(E1000_RXDCTL(i));
1773 wr32(E1000_RXDCTL(i),
1774 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1775 }
1776 /* Poll all queues to verify they have shut down */
1777 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1778 msleep(1);
1779 rx_enabled = 0;
1780 for (i = 0; i < 4; i++)
1781 rx_enabled |= rd32(E1000_RXDCTL(i));
1782 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1783 break;
1784 }
1785
1786 if (ms_wait == 10)
1787 hw_dbg("Queue disable timed out after 10ms\n");
1788
1789 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1790 * incoming packets are rejected. Set enable and wait 2ms so that
1791 * any packet that was coming in as RCTL.EN was set is flushed
1792 */
1793 rfctl = rd32(E1000_RFCTL);
1794 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1795
1796 rlpml = rd32(E1000_RLPML);
1797 wr32(E1000_RLPML, 0);
1798
1799 rctl = rd32(E1000_RCTL);
1800 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1801 temp_rctl |= E1000_RCTL_LPE;
1802
1803 wr32(E1000_RCTL, temp_rctl);
1804 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1805 wrfl();
1806 msleep(2);
1807
1808 /* Enable RX queues that were previously enabled and restore our
1809 * previous state
1810 */
1811 for (i = 0; i < 4; i++)
1812 wr32(E1000_RXDCTL(i), rxdctl[i]);
1813 wr32(E1000_RCTL, rctl);
1814 wrfl();
1815
1816 wr32(E1000_RLPML, rlpml);
1817 wr32(E1000_RFCTL, rfctl);
1818
1819 /* Flush receive errors generated by workaround */
1820 rd32(E1000_ROC);
1821 rd32(E1000_RNBC);
1822 rd32(E1000_MPC);
1823}
1824
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001825/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001826 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1827 * @hw: pointer to the HW structure
1828 *
1829 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1830 * however the hardware default for these parts is 500us to 1ms which is less
1831 * than the 10ms recommended by the pci-e spec. To address this we need to
1832 * increase the value to either 10ms to 200ms for capability version 1 config,
1833 * or 16ms to 55ms for version 2.
1834 **/
1835static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1836{
1837 u32 gcr = rd32(E1000_GCR);
1838 s32 ret_val = 0;
1839 u16 pcie_devctl2;
1840
1841 /* only take action if timeout value is defaulted to 0 */
1842 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1843 goto out;
1844
1845 /*
1846 * if capababilities version is type 1 we can write the
1847 * timeout of 10ms to 200ms through the GCR register
1848 */
1849 if (!(gcr & E1000_GCR_CAP_VER2)) {
1850 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1851 goto out;
1852 }
1853
1854 /*
1855 * for version 2 capabilities we need to write the config space
1856 * directly in order to set the completion timeout value for
1857 * 16ms to 55ms
1858 */
1859 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1860 &pcie_devctl2);
1861 if (ret_val)
1862 goto out;
1863
1864 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1865
1866 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1867 &pcie_devctl2);
1868out:
1869 /* disable completion timeout resend */
1870 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1871
1872 wr32(E1000_GCR, gcr);
1873 return ret_val;
1874}
1875
1876/**
Greg Rose13800462010-11-06 02:08:26 +00001877 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
1878 * @hw: pointer to the hardware struct
1879 * @enable: state to enter, either enabled or disabled
1880 * @pf: Physical Function pool - do not set anti-spoofing for the PF
1881 *
1882 * enables/disables L2 switch anti-spoofing functionality.
1883 **/
1884void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
1885{
1886 u32 dtxswc;
1887
1888 switch (hw->mac.type) {
1889 case e1000_82576:
1890 case e1000_i350:
1891 dtxswc = rd32(E1000_DTXSWC);
1892 if (enable) {
1893 dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK |
1894 E1000_DTXSWC_VLAN_SPOOF_MASK);
1895 /* The PF can spoof - it has to in order to
1896 * support emulation mode NICs */
1897 dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
1898 } else {
1899 dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
1900 E1000_DTXSWC_VLAN_SPOOF_MASK);
1901 }
1902 wr32(E1000_DTXSWC, dtxswc);
1903 break;
1904 default:
1905 break;
1906 }
1907}
1908
1909/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001910 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1911 * @hw: pointer to the hardware struct
1912 * @enable: state to enter, either enabled or disabled
1913 *
1914 * enables/disables L2 switch loopback functionality.
1915 **/
1916void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1917{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001918 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001919
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001920 switch (hw->mac.type) {
1921 case e1000_82576:
1922 dtxswc = rd32(E1000_DTXSWC);
1923 if (enable)
1924 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1925 else
1926 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1927 wr32(E1000_DTXSWC, dtxswc);
1928 break;
1929 case e1000_i350:
1930 dtxswc = rd32(E1000_TXSWC);
1931 if (enable)
1932 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1933 else
1934 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1935 wr32(E1000_TXSWC, dtxswc);
1936 break;
1937 default:
1938 /* Currently no other hardware supports loopback */
1939 break;
1940 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001941
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001942
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001943}
1944
1945/**
1946 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1947 * @hw: pointer to the hardware struct
1948 * @enable: state to enter, either enabled or disabled
1949 *
1950 * enables/disables replication of packets across multiple pools.
1951 **/
1952void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1953{
1954 u32 vt_ctl = rd32(E1000_VT_CTL);
1955
1956 if (enable)
1957 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1958 else
1959 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1960
1961 wr32(E1000_VT_CTL, vt_ctl);
1962}
1963
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001964/**
1965 * igb_read_phy_reg_82580 - Read 82580 MDI control register
1966 * @hw: pointer to the HW structure
1967 * @offset: register offset to be read
1968 * @data: pointer to the read data
1969 *
1970 * Reads the MDI control register in the PHY at offset and stores the
1971 * information read to data.
1972 **/
1973static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
1974{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001975 s32 ret_val;
1976
1977
1978 ret_val = hw->phy.ops.acquire(hw);
1979 if (ret_val)
1980 goto out;
1981
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001982 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
1983
1984 hw->phy.ops.release(hw);
1985
1986out:
1987 return ret_val;
1988}
1989
1990/**
1991 * igb_write_phy_reg_82580 - Write 82580 MDI control register
1992 * @hw: pointer to the HW structure
1993 * @offset: register offset to write to
1994 * @data: data to write to register at offset
1995 *
1996 * Writes data to MDI control register in the PHY at offset.
1997 **/
1998static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
1999{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002000 s32 ret_val;
2001
2002
2003 ret_val = hw->phy.ops.acquire(hw);
2004 if (ret_val)
2005 goto out;
2006
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002007 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2008
2009 hw->phy.ops.release(hw);
2010
2011out:
2012 return ret_val;
2013}
2014
2015/**
Nick Nunley08451e22010-07-26 13:15:29 +00002016 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2017 * @hw: pointer to the HW structure
2018 *
2019 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2020 * the values found in the EEPROM. This addresses an issue in which these
2021 * bits are not restored from EEPROM after reset.
2022 **/
2023static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2024{
2025 s32 ret_val = 0;
2026 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002027 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002028
2029 if (hw->mac.type != e1000_82580)
2030 goto out;
2031 if (!igb_sgmii_active_82575(hw))
2032 goto out;
2033
2034 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2035 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2036 &nvm_data);
2037 if (ret_val) {
2038 hw_dbg("NVM Read Error\n");
2039 goto out;
2040 }
2041
2042 mdicnfg = rd32(E1000_MDICNFG);
2043 if (nvm_data & NVM_WORD24_EXT_MDIO)
2044 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2045 if (nvm_data & NVM_WORD24_COM_MDIO)
2046 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2047 wr32(E1000_MDICNFG, mdicnfg);
2048out:
2049 return ret_val;
2050}
2051
2052/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002053 * igb_reset_hw_82580 - Reset hardware
2054 * @hw: pointer to the HW structure
2055 *
2056 * This resets function or entire device (all ports, etc.)
2057 * to a known state.
2058 **/
2059static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2060{
2061 s32 ret_val = 0;
2062 /* BH SW mailbox bit in SW_FW_SYNC */
2063 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
2064 u32 ctrl, icr;
2065 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2066
2067
2068 hw->dev_spec._82575.global_device_reset = false;
2069
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002070 /* due to hw errata, global device reset doesn't always
2071 * work on 82580
2072 */
2073 if (hw->mac.type == e1000_82580)
2074 global_device_reset = false;
2075
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002076 /* Get current control state. */
2077 ctrl = rd32(E1000_CTRL);
2078
2079 /*
2080 * Prevent the PCI-E bus from sticking if there is no TLP connection
2081 * on the last TLP read/write transaction when MAC is reset.
2082 */
2083 ret_val = igb_disable_pcie_master(hw);
2084 if (ret_val)
2085 hw_dbg("PCI-E Master disable polling has failed.\n");
2086
2087 hw_dbg("Masking off all interrupts\n");
2088 wr32(E1000_IMC, 0xffffffff);
2089 wr32(E1000_RCTL, 0);
2090 wr32(E1000_TCTL, E1000_TCTL_PSP);
2091 wrfl();
2092
2093 msleep(10);
2094
2095 /* Determine whether or not a global dev reset is requested */
2096 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002097 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002098 global_device_reset = false;
2099
2100 if (global_device_reset &&
2101 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2102 ctrl |= E1000_CTRL_DEV_RST;
2103 else
2104 ctrl |= E1000_CTRL_RST;
2105
2106 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002107 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002108
2109 /* Add delay to insure DEV_RST has time to complete */
2110 if (global_device_reset)
2111 msleep(5);
2112
2113 ret_val = igb_get_auto_rd_done(hw);
2114 if (ret_val) {
2115 /*
2116 * When auto config read does not complete, do not
2117 * return with an error. This can happen in situations
2118 * where there is no eeprom and prevents getting link.
2119 */
2120 hw_dbg("Auto Read Done did not complete\n");
2121 }
2122
2123 /* If EEPROM is not present, run manual init scripts */
2124 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
2125 igb_reset_init_script_82575(hw);
2126
2127 /* clear global device reset status bit */
2128 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2129
2130 /* Clear any pending interrupt events. */
2131 wr32(E1000_IMC, 0xffffffff);
2132 icr = rd32(E1000_ICR);
2133
Nick Nunley08451e22010-07-26 13:15:29 +00002134 ret_val = igb_reset_mdicnfg_82580(hw);
2135 if (ret_val)
2136 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2137
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002138 /* Install any alternate MAC address into RAR0 */
2139 ret_val = igb_check_alt_mac_addr(hw);
2140
2141 /* Release semaphore */
2142 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002143 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002144
2145 return ret_val;
2146}
2147
2148/**
2149 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2150 * @data: data received by reading RXPBS register
2151 *
2152 * The 82580 uses a table based approach for packet buffer allocation sizes.
2153 * This function converts the retrieved value into the correct table value
2154 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2155 * 0x0 36 72 144 1 2 4 8 16
2156 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2157 */
2158u16 igb_rxpbs_adjust_82580(u32 data)
2159{
2160 u16 ret_val = 0;
2161
2162 if (data < E1000_82580_RXPBS_TABLE_SIZE)
2163 ret_val = e1000_82580_rxpbs_table[data];
2164
2165 return ret_val;
2166}
2167
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002168/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002169 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2170 * checksum
2171 * @hw: pointer to the HW structure
2172 * @offset: offset in words of the checksum protected region
2173 *
2174 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2175 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2176 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002177static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2178 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002179{
2180 s32 ret_val = 0;
2181 u16 checksum = 0;
2182 u16 i, nvm_data;
2183
2184 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2185 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2186 if (ret_val) {
2187 hw_dbg("NVM Read Error\n");
2188 goto out;
2189 }
2190 checksum += nvm_data;
2191 }
2192
2193 if (checksum != (u16) NVM_SUM) {
2194 hw_dbg("NVM Checksum Invalid\n");
2195 ret_val = -E1000_ERR_NVM;
2196 goto out;
2197 }
2198
2199out:
2200 return ret_val;
2201}
2202
2203/**
2204 * igb_update_nvm_checksum_with_offset - Update EEPROM
2205 * checksum
2206 * @hw: pointer to the HW structure
2207 * @offset: offset in words of the checksum protected region
2208 *
2209 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2210 * up to the checksum. Then calculates the EEPROM checksum and writes the
2211 * value to the EEPROM.
2212 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002213static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002214{
2215 s32 ret_val;
2216 u16 checksum = 0;
2217 u16 i, nvm_data;
2218
2219 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2220 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2221 if (ret_val) {
2222 hw_dbg("NVM Read Error while updating checksum.\n");
2223 goto out;
2224 }
2225 checksum += nvm_data;
2226 }
2227 checksum = (u16) NVM_SUM - checksum;
2228 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2229 &checksum);
2230 if (ret_val)
2231 hw_dbg("NVM Write Error while updating checksum.\n");
2232
2233out:
2234 return ret_val;
2235}
2236
2237/**
2238 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2239 * @hw: pointer to the HW structure
2240 *
2241 * Calculates the EEPROM section checksum by reading/adding each word of
2242 * the EEPROM and then verifies that the sum of the EEPROM is
2243 * equal to 0xBABA.
2244 **/
2245static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2246{
2247 s32 ret_val = 0;
2248 u16 eeprom_regions_count = 1;
2249 u16 j, nvm_data;
2250 u16 nvm_offset;
2251
2252 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2253 if (ret_val) {
2254 hw_dbg("NVM Read Error\n");
2255 goto out;
2256 }
2257
2258 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002259 /* if checksums compatibility bit is set validate checksums
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002260 * for all 4 ports. */
2261 eeprom_regions_count = 4;
2262 }
2263
2264 for (j = 0; j < eeprom_regions_count; j++) {
2265 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2266 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2267 nvm_offset);
2268 if (ret_val != 0)
2269 goto out;
2270 }
2271
2272out:
2273 return ret_val;
2274}
2275
2276/**
2277 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2278 * @hw: pointer to the HW structure
2279 *
2280 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2281 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2282 * checksum and writes the value to the EEPROM.
2283 **/
2284static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2285{
2286 s32 ret_val;
2287 u16 j, nvm_data;
2288 u16 nvm_offset;
2289
2290 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2291 if (ret_val) {
2292 hw_dbg("NVM Read Error while updating checksum"
2293 " compatibility bit.\n");
2294 goto out;
2295 }
2296
2297 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2298 /* set compatibility bit to validate checksums appropriately */
2299 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2300 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2301 &nvm_data);
2302 if (ret_val) {
2303 hw_dbg("NVM Write Error while updating checksum"
2304 " compatibility bit.\n");
2305 goto out;
2306 }
2307 }
2308
2309 for (j = 0; j < 4; j++) {
2310 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2311 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2312 if (ret_val)
2313 goto out;
2314 }
2315
2316out:
2317 return ret_val;
2318}
2319
2320/**
2321 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2322 * @hw: pointer to the HW structure
2323 *
2324 * Calculates the EEPROM section checksum by reading/adding each word of
2325 * the EEPROM and then verifies that the sum of the EEPROM is
2326 * equal to 0xBABA.
2327 **/
2328static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2329{
2330 s32 ret_val = 0;
2331 u16 j;
2332 u16 nvm_offset;
2333
2334 for (j = 0; j < 4; j++) {
2335 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2336 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2337 nvm_offset);
2338 if (ret_val != 0)
2339 goto out;
2340 }
2341
2342out:
2343 return ret_val;
2344}
2345
2346/**
2347 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2348 * @hw: pointer to the HW structure
2349 *
2350 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2351 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2352 * checksum and writes the value to the EEPROM.
2353 **/
2354static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2355{
2356 s32 ret_val = 0;
2357 u16 j;
2358 u16 nvm_offset;
2359
2360 for (j = 0; j < 4; j++) {
2361 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2362 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2363 if (ret_val != 0)
2364 goto out;
2365 }
2366
2367out:
2368 return ret_val;
2369}
Stefan Assmann34a03262011-04-05 04:27:05 +00002370
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002371/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002372 * igb_set_eee_i350 - Enable/disable EEE support
2373 * @hw: pointer to the HW structure
2374 *
2375 * Enable/disable EEE based on setting in dev_spec structure.
2376 *
2377 **/
2378s32 igb_set_eee_i350(struct e1000_hw *hw)
2379{
2380 s32 ret_val = 0;
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002381 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002382
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002383 if ((hw->mac.type < e1000_i350) ||
2384 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002385 goto out;
2386 ipcnfg = rd32(E1000_IPCNFG);
2387 eeer = rd32(E1000_EEER);
2388
2389 /* enable or disable per user setting */
2390 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002391 u32 eee_su = rd32(E1000_EEE_SU);
2392
2393 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2394 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002395 E1000_EEER_LPI_FC);
2396
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002397 /* This bit should not be set in normal operation. */
2398 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2399 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2400
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002401
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002402 } else {
2403 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2404 E1000_IPCNFG_EEE_100M_AN);
2405 eeer &= ~(E1000_EEER_TX_LPI_EN |
2406 E1000_EEER_RX_LPI_EN |
2407 E1000_EEER_LPI_FC);
2408 }
2409 wr32(E1000_IPCNFG, ipcnfg);
2410 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002411 rd32(E1000_IPCNFG);
2412 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002413out:
2414
2415 return ret_val;
2416}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002417
Carolyn Wybornye4288932012-12-07 03:01:42 +00002418static const u8 e1000_emc_temp_data[4] = {
2419 E1000_EMC_INTERNAL_DATA,
2420 E1000_EMC_DIODE1_DATA,
2421 E1000_EMC_DIODE2_DATA,
2422 E1000_EMC_DIODE3_DATA
2423};
2424static const u8 e1000_emc_therm_limit[4] = {
2425 E1000_EMC_INTERNAL_THERM_LIMIT,
2426 E1000_EMC_DIODE1_THERM_LIMIT,
2427 E1000_EMC_DIODE2_THERM_LIMIT,
2428 E1000_EMC_DIODE3_THERM_LIMIT
2429};
2430
2431/* igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
2432 * @hw: pointer to hardware structure
2433 *
2434 * Updates the temperatures in mac.thermal_sensor_data
2435 */
2436s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
2437{
2438 s32 status = E1000_SUCCESS;
2439 u16 ets_offset;
2440 u16 ets_cfg;
2441 u16 ets_sensor;
2442 u8 num_sensors;
2443 u8 sensor_index;
2444 u8 sensor_location;
2445 u8 i;
2446 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2447
2448 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2449 return E1000_NOT_IMPLEMENTED;
2450
2451 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2452
2453 /* Return the internal sensor only if ETS is unsupported */
2454 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2455 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2456 return status;
2457
2458 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2459 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2460 != NVM_ETS_TYPE_EMC)
2461 return E1000_NOT_IMPLEMENTED;
2462
2463 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2464 if (num_sensors > E1000_MAX_SENSORS)
2465 num_sensors = E1000_MAX_SENSORS;
2466
2467 for (i = 1; i < num_sensors; i++) {
2468 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2469 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2470 NVM_ETS_DATA_INDEX_SHIFT);
2471 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2472 NVM_ETS_DATA_LOC_SHIFT);
2473
2474 if (sensor_location != 0)
2475 hw->phy.ops.read_i2c_byte(hw,
2476 e1000_emc_temp_data[sensor_index],
2477 E1000_I2C_THERMAL_SENSOR_ADDR,
2478 &data->sensor[i].temp);
2479 }
2480 return status;
2481}
2482
2483/* igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
2484 * @hw: pointer to hardware structure
2485 *
2486 * Sets the thermal sensor thresholds according to the NVM map
2487 * and save off the threshold and location values into mac.thermal_sensor_data
2488 */
2489s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
2490{
2491 s32 status = E1000_SUCCESS;
2492 u16 ets_offset;
2493 u16 ets_cfg;
2494 u16 ets_sensor;
2495 u8 low_thresh_delta;
2496 u8 num_sensors;
2497 u8 sensor_index;
2498 u8 sensor_location;
2499 u8 therm_limit;
2500 u8 i;
2501 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2502
2503 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2504 return E1000_NOT_IMPLEMENTED;
2505
2506 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2507
2508 data->sensor[0].location = 0x1;
2509 data->sensor[0].caution_thresh =
2510 (rd32(E1000_THHIGHTC) & 0xFF);
2511 data->sensor[0].max_op_thresh =
2512 (rd32(E1000_THLOWTC) & 0xFF);
2513
2514 /* Return the internal sensor only if ETS is unsupported */
2515 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2516 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2517 return status;
2518
2519 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2520 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2521 != NVM_ETS_TYPE_EMC)
2522 return E1000_NOT_IMPLEMENTED;
2523
2524 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2525 NVM_ETS_LTHRES_DELTA_SHIFT);
2526 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2527
2528 for (i = 1; i <= num_sensors; i++) {
2529 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2530 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2531 NVM_ETS_DATA_INDEX_SHIFT);
2532 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2533 NVM_ETS_DATA_LOC_SHIFT);
2534 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2535
2536 hw->phy.ops.write_i2c_byte(hw,
2537 e1000_emc_therm_limit[sensor_index],
2538 E1000_I2C_THERMAL_SENSOR_ADDR,
2539 therm_limit);
2540
2541 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2542 data->sensor[i].location = sensor_location;
2543 data->sensor[i].caution_thresh = therm_limit;
2544 data->sensor[i].max_op_thresh = therm_limit -
2545 low_thresh_delta;
2546 }
2547 }
2548 return status;
2549}
2550
Auke Kok9d5c8242008-01-24 02:22:38 -08002551static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002552 .init_hw = igb_init_hw_82575,
2553 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002554 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002555 .read_mac_addr = igb_read_mac_addr_82575,
2556 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002557#ifdef CONFIG_IGB_HWMON
2558 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2559 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2560#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002561};
2562
2563static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002564 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002565 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002566 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002567 .write_i2c_byte = igb_write_i2c_byte,
2568 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002569};
2570
2571static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002572 .acquire = igb_acquire_nvm_82575,
2573 .read = igb_read_nvm_eerd,
2574 .release = igb_release_nvm_82575,
2575 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002576};
2577
2578const struct e1000_info e1000_82575_info = {
2579 .get_invariants = igb_get_invariants_82575,
2580 .mac_ops = &e1000_mac_ops_82575,
2581 .phy_ops = &e1000_phy_ops_82575,
2582 .nvm_ops = &e1000_nvm_ops_82575,
2583};
2584