blob: 8c12dbd0d6ce8927274b08ea560081b2a3459d15 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Carolyn Wyborny6e861322012-01-18 22:13:27 +00004 Copyright(c) 2007-2012 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>
Auke Kok9d5c8242008-01-24 02:22:38 -080036
37#include "e1000_mac.h"
38#include "e1000_82575.h"
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000039#include "e1000_i210.h"
Auke Kok9d5c8242008-01-24 02:22:38 -080040
41static s32 igb_get_invariants_82575(struct e1000_hw *);
42static s32 igb_acquire_phy_82575(struct e1000_hw *);
43static void igb_release_phy_82575(struct e1000_hw *);
44static s32 igb_acquire_nvm_82575(struct e1000_hw *);
45static void igb_release_nvm_82575(struct e1000_hw *);
46static s32 igb_check_for_link_82575(struct e1000_hw *);
47static s32 igb_get_cfg_done_82575(struct e1000_hw *);
48static s32 igb_init_hw_82575(struct e1000_hw *);
49static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
50static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000051static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
52static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080053static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000054static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080055static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
Carolyn Wybornyda02cde2012-03-04 03:26:26 +000056static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
57static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
Auke Kok9d5c8242008-01-24 02:22:38 -080058static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000059static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080060static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
61static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
62static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080063static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
64 u16 *);
65static s32 igb_get_phy_id_82575(struct e1000_hw *);
66static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
67static bool igb_sgmii_active_82575(struct e1000_hw *);
68static s32 igb_reset_init_script_82575(struct e1000_hw *);
69static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000070static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Alexander Duyck99870a72010-08-03 11:50:08 +000071static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080072static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
73static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080074static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
75static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000076static const u16 e1000_82580_rxpbs_table[] =
77 { 36, 72, 144, 1, 2, 4, 8, 16,
78 35, 70, 140 };
79#define E1000_82580_RXPBS_TABLE_SIZE \
80 (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
81
Nick Nunley4085f742010-07-26 13:15:06 +000082/**
83 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
84 * @hw: pointer to the HW structure
85 *
86 * Called to determine if the I2C pins are being used for I2C or as an
87 * external MDIO interface since the two options are mutually exclusive.
88 **/
89static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
90{
91 u32 reg = 0;
92 bool ext_mdio = false;
93
94 switch (hw->mac.type) {
95 case e1000_82575:
96 case e1000_82576:
97 reg = rd32(E1000_MDIC);
98 ext_mdio = !!(reg & E1000_MDIC_DEST);
99 break;
100 case e1000_82580:
101 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000102 case e1000_i210:
103 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000104 reg = rd32(E1000_MDICNFG);
105 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
106 break;
107 default:
108 break;
109 }
110 return ext_mdio;
111}
112
Auke Kok9d5c8242008-01-24 02:22:38 -0800113static s32 igb_get_invariants_82575(struct e1000_hw *hw)
114{
115 struct e1000_phy_info *phy = &hw->phy;
116 struct e1000_nvm_info *nvm = &hw->nvm;
117 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +0000118 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800119 u32 eecd;
120 s32 ret_val;
121 u16 size;
122 u32 ctrl_ext = 0;
123
124 switch (hw->device_id) {
125 case E1000_DEV_ID_82575EB_COPPER:
126 case E1000_DEV_ID_82575EB_FIBER_SERDES:
127 case E1000_DEV_ID_82575GB_QUAD_COPPER:
128 mac->type = e1000_82575;
129 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700130 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000131 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000132 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700133 case E1000_DEV_ID_82576_FIBER:
134 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000135 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000136 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000137 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700138 mac->type = e1000_82576;
139 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000140 case E1000_DEV_ID_82580_COPPER:
141 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000142 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000143 case E1000_DEV_ID_82580_SERDES:
144 case E1000_DEV_ID_82580_SGMII:
145 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000146 case E1000_DEV_ID_DH89XXCC_SGMII:
147 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000148 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
149 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000150 mac->type = e1000_82580;
151 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000152 case E1000_DEV_ID_I350_COPPER:
153 case E1000_DEV_ID_I350_FIBER:
154 case E1000_DEV_ID_I350_SERDES:
155 case E1000_DEV_ID_I350_SGMII:
156 mac->type = e1000_i350;
157 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000158 case E1000_DEV_ID_I210_COPPER:
159 case E1000_DEV_ID_I210_COPPER_OEM1:
160 case E1000_DEV_ID_I210_COPPER_IT:
161 case E1000_DEV_ID_I210_FIBER:
162 case E1000_DEV_ID_I210_SERDES:
163 case E1000_DEV_ID_I210_SGMII:
164 mac->type = e1000_i210;
165 break;
166 case E1000_DEV_ID_I211_COPPER:
167 mac->type = e1000_i211;
168 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800169 default:
170 return -E1000_ERR_MAC_INIT;
171 break;
172 }
173
Auke Kok9d5c8242008-01-24 02:22:38 -0800174 /* Set media type */
175 /*
176 * The 82575 uses bits 22:23 for link mode. The mode can be changed
177 * based on the EEPROM. We cannot rely upon device ID. There
178 * is no distinguishable difference between fiber and internal
179 * SerDes mode on the 82575. There can be an external PHY attached
180 * on the SGMII interface. For this, we'll set sgmii_active to true.
181 */
182 phy->media_type = e1000_media_type_copper;
183 dev_spec->sgmii_active = false;
184
185 ctrl_ext = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000186 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
187 case E1000_CTRL_EXT_LINK_MODE_SGMII:
Auke Kok9d5c8242008-01-24 02:22:38 -0800188 dev_spec->sgmii_active = true;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000189 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000190 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000191 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
192 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000193 break;
194 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000195 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800196 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000197
Auke Kok9d5c8242008-01-24 02:22:38 -0800198 /* Set mta register count */
199 mac->mta_reg_count = 128;
200 /* Set rar entry count */
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000201 switch (mac->type) {
202 case e1000_82576:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700203 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000204 break;
205 case e1000_82580:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000206 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000207 break;
208 case e1000_i350:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000209 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000210 break;
211 default:
212 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
213 break;
214 }
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000215 /* reset */
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000216 if (mac->type >= e1000_82580)
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000217 mac->ops.reset_hw = igb_reset_hw_82580;
218 else
219 mac->ops.reset_hw = igb_reset_hw_82575;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000220
221 if (mac->type >= e1000_i210) {
222 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
223 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
224 } else {
225 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
226 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
227 }
228
Auke Kok9d5c8242008-01-24 02:22:38 -0800229 /* Set if part includes ASF firmware */
230 mac->asf_firmware_present = true;
231 /* Set if manageability features are enabled. */
232 mac->arc_subsystem_valid =
233 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
234 ? true : false;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000235 /* enable EEE on i350 parts and later parts */
236 if (mac->type >= e1000_i350)
Carolyn Wyborny09b068d2011-03-11 20:42:13 -0800237 dev_spec->eee_disable = false;
238 else
239 dev_spec->eee_disable = true;
Auke Kok9d5c8242008-01-24 02:22:38 -0800240 /* physical interface link setup */
241 mac->ops.setup_physical_interface =
242 (hw->phy.media_type == e1000_media_type_copper)
243 ? igb_setup_copper_link_82575
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000244 : igb_setup_serdes_link_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800245
246 /* NVM initialization */
247 eecd = rd32(E1000_EECD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800248 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
249 E1000_EECD_SIZE_EX_SHIFT);
250
251 /*
252 * Added to a constant, "size" becomes the left-shift value
253 * for setting word_size.
254 */
255 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700256
Carolyn Wyborny925b11f2012-07-31 01:01:23 +0000257 /*
258 * Check for invalid size
259 */
260 if ((hw->mac.type == e1000_82576) && (size > 15)) {
261 pr_notice("The NVM size is not valid, defaulting to 32K\n");
262 size = 15;
263 }
264
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000265 nvm->word_size = 1 << size;
266 if (hw->mac.type < e1000_i210) {
267 nvm->opcode_bits = 8;
268 nvm->delay_usec = 1;
269 switch (nvm->override) {
270 case e1000_nvm_override_spi_large:
271 nvm->page_size = 32;
272 nvm->address_bits = 16;
273 break;
274 case e1000_nvm_override_spi_small:
275 nvm->page_size = 8;
276 nvm->address_bits = 8;
277 break;
278 default:
279 nvm->page_size = eecd
280 & E1000_EECD_ADDR_BITS ? 32 : 8;
281 nvm->address_bits = eecd
282 & E1000_EECD_ADDR_BITS ? 16 : 8;
283 break;
284 }
285 if (nvm->word_size == (1 << 15))
286 nvm->page_size = 128;
287
288 nvm->type = e1000_nvm_eeprom_spi;
289 } else
290 nvm->type = e1000_nvm_flash_hw;
291
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800292 /* NVM Function Pointers */
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800293 switch (hw->mac.type) {
294 case e1000_82580:
295 nvm->ops.validate = igb_validate_nvm_checksum_82580;
296 nvm->ops.update = igb_update_nvm_checksum_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000297 nvm->ops.acquire = igb_acquire_nvm_82575;
298 nvm->ops.release = igb_release_nvm_82575;
299 if (nvm->word_size < (1 << 15))
300 nvm->ops.read = igb_read_nvm_eerd;
301 else
302 nvm->ops.read = igb_read_nvm_spi;
303 nvm->ops.write = igb_write_nvm_spi;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800304 break;
305 case e1000_i350:
306 nvm->ops.validate = igb_validate_nvm_checksum_i350;
307 nvm->ops.update = igb_update_nvm_checksum_i350;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000308 nvm->ops.acquire = igb_acquire_nvm_82575;
309 nvm->ops.release = igb_release_nvm_82575;
310 if (nvm->word_size < (1 << 15))
311 nvm->ops.read = igb_read_nvm_eerd;
312 else
313 nvm->ops.read = igb_read_nvm_spi;
314 nvm->ops.write = igb_write_nvm_spi;
315 break;
316 case e1000_i210:
317 nvm->ops.validate = igb_validate_nvm_checksum_i210;
318 nvm->ops.update = igb_update_nvm_checksum_i210;
319 nvm->ops.acquire = igb_acquire_nvm_i210;
320 nvm->ops.release = igb_release_nvm_i210;
321 nvm->ops.read = igb_read_nvm_srrd_i210;
Carolyn Wybornyede41262012-10-24 03:56:21 +0000322 nvm->ops.write = igb_write_nvm_srwr_i210;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000323 nvm->ops.valid_led_default = igb_valid_led_default_i210;
324 break;
325 case e1000_i211:
326 nvm->ops.acquire = igb_acquire_nvm_i210;
327 nvm->ops.release = igb_release_nvm_i210;
328 nvm->ops.read = igb_read_nvm_i211;
329 nvm->ops.valid_led_default = igb_valid_led_default_i210;
330 nvm->ops.validate = NULL;
331 nvm->ops.update = NULL;
332 nvm->ops.write = NULL;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800333 break;
334 default:
335 nvm->ops.validate = igb_validate_nvm_checksum;
336 nvm->ops.update = igb_update_nvm_checksum;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000337 nvm->ops.acquire = igb_acquire_nvm_82575;
338 nvm->ops.release = igb_release_nvm_82575;
339 if (nvm->word_size < (1 << 15))
340 nvm->ops.read = igb_read_nvm_eerd;
341 else
342 nvm->ops.read = igb_read_nvm_spi;
343 nvm->ops.write = igb_write_nvm_spi;
344 break;
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800345 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800346
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000347 /* if part supports SR-IOV then initialize mailbox parameters */
348 switch (mac->type) {
349 case e1000_82576:
350 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000351 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000352 break;
353 default:
354 break;
355 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000356
Auke Kok9d5c8242008-01-24 02:22:38 -0800357 /* setup PHY parameters */
358 if (phy->media_type != e1000_media_type_copper) {
359 phy->type = e1000_phy_none;
360 return 0;
361 }
362
363 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
364 phy->reset_delay_us = 100;
365
Alexander Duyck99870a72010-08-03 11:50:08 +0000366 ctrl_ext = rd32(E1000_CTRL_EXT);
367
Auke Kok9d5c8242008-01-24 02:22:38 -0800368 /* PHY function pointers */
Alexander Duyck99870a72010-08-03 11:50:08 +0000369 if (igb_sgmii_active_82575(hw)) {
Nick Nunley4085f742010-07-26 13:15:06 +0000370 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
Alexander Duyck99870a72010-08-03 11:50:08 +0000371 ctrl_ext |= E1000_CTRL_I2C_ENA;
372 } else {
Nick Nunley4085f742010-07-26 13:15:06 +0000373 phy->ops.reset = igb_phy_hw_reset;
Alexander Duyck99870a72010-08-03 11:50:08 +0000374 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
375 }
376
377 wr32(E1000_CTRL_EXT, ctrl_ext);
378 igb_reset_mdicnfg_82580(hw);
Nick Nunley4085f742010-07-26 13:15:06 +0000379
380 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
381 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
382 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000383 } else if ((hw->mac.type == e1000_82580)
384 || (hw->mac.type == e1000_i350)) {
Nick Nunley4085f742010-07-26 13:15:06 +0000385 phy->ops.read_reg = igb_read_phy_reg_82580;
386 phy->ops.write_reg = igb_write_phy_reg_82580;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000387 } else if (hw->phy.type >= e1000_phy_i210) {
388 phy->ops.read_reg = igb_read_phy_reg_gs40g;
389 phy->ops.write_reg = igb_write_phy_reg_gs40g;
Auke Kok9d5c8242008-01-24 02:22:38 -0800390 } else {
Nick Nunley4085f742010-07-26 13:15:06 +0000391 phy->ops.read_reg = igb_read_phy_reg_igp;
392 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800393 }
394
Alexander Duyck19e588e2009-07-07 13:01:55 +0000395 /* set lan id */
396 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
397 E1000_STATUS_FUNC_SHIFT;
398
Auke Kok9d5c8242008-01-24 02:22:38 -0800399 /* Set phy->phy_addr and phy->id. */
400 ret_val = igb_get_phy_id_82575(hw);
401 if (ret_val)
402 return ret_val;
403
404 /* Verify phy id and set remaining function pointers */
405 switch (phy->id) {
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000406 case I347AT4_E_PHY_ID:
407 case M88E1112_E_PHY_ID:
Auke Kok9d5c8242008-01-24 02:22:38 -0800408 case M88E1111_I_PHY_ID:
409 phy->type = e1000_phy_m88;
410 phy->ops.get_phy_info = igb_get_phy_info_m88;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000411
412 if (phy->id == I347AT4_E_PHY_ID ||
413 phy->id == M88E1112_E_PHY_ID)
414 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
415 else
416 phy->ops.get_cable_length = igb_get_cable_length_m88;
417
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000418 if (phy->id == I210_I_PHY_ID) {
419 phy->ops.get_cable_length =
420 igb_get_cable_length_m88_gen2;
421 phy->ops.set_d0_lplu_state =
422 igb_set_d0_lplu_state_82580;
423 phy->ops.set_d3_lplu_state =
424 igb_set_d3_lplu_state_82580;
425 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800426 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
427 break;
428 case IGP03E1000_E_PHY_ID:
429 phy->type = e1000_phy_igp_3;
430 phy->ops.get_phy_info = igb_get_phy_info_igp;
431 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
432 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
433 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
434 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
435 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000436 case I82580_I_PHY_ID:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000437 case I350_I_PHY_ID:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000438 phy->type = e1000_phy_82580;
439 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580;
440 phy->ops.get_cable_length = igb_get_cable_length_82580;
441 phy->ops.get_phy_info = igb_get_phy_info_82580;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000442 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
443 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000444 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000445 case I210_I_PHY_ID:
446 phy->type = e1000_phy_i210;
447 phy->ops.get_phy_info = igb_get_phy_info_m88;
448 phy->ops.check_polarity = igb_check_polarity_m88;
449 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
450 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
451 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
452 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
453 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800454 default:
455 return -E1000_ERR_PHY;
456 }
457
458 return 0;
459}
460
461/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700462 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800463 * @hw: pointer to the HW structure
464 *
465 * Acquire access rights to the correct PHY. This is a
466 * function pointer entry point called by the api module.
467 **/
468static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
469{
Alexander Duyck008c3422009-10-05 06:32:07 +0000470 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800471
Alexander Duyck008c3422009-10-05 06:32:07 +0000472 if (hw->bus.func == E1000_FUNC_1)
473 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000474 else if (hw->bus.func == E1000_FUNC_2)
475 mask = E1000_SWFW_PHY2_SM;
476 else if (hw->bus.func == E1000_FUNC_3)
477 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800478
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000479 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800480}
481
482/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700483 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800484 * @hw: pointer to the HW structure
485 *
486 * A wrapper to release access rights to the correct PHY. This is a
487 * function pointer entry point called by the api module.
488 **/
489static void igb_release_phy_82575(struct e1000_hw *hw)
490{
Alexander Duyck008c3422009-10-05 06:32:07 +0000491 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800492
Alexander Duyck008c3422009-10-05 06:32:07 +0000493 if (hw->bus.func == E1000_FUNC_1)
494 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000495 else if (hw->bus.func == E1000_FUNC_2)
496 mask = E1000_SWFW_PHY2_SM;
497 else if (hw->bus.func == E1000_FUNC_3)
498 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000499
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000500 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800501}
502
503/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700504 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800505 * @hw: pointer to the HW structure
506 * @offset: register offset to be read
507 * @data: pointer to the read data
508 *
509 * Reads the PHY register at offset using the serial gigabit media independent
510 * interface and stores the retrieved information in data.
511 **/
512static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
513 u16 *data)
514{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000515 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800516
517 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700518 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000519 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800520 }
521
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000522 ret_val = hw->phy.ops.acquire(hw);
523 if (ret_val)
524 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800525
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000526 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800527
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000528 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800529
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000530out:
531 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800532}
533
534/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700535 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800536 * @hw: pointer to the HW structure
537 * @offset: register offset to write to
538 * @data: data to write at register offset
539 *
540 * Writes the data to PHY register at the offset using the serial gigabit
541 * media independent interface.
542 **/
543static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
544 u16 data)
545{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000546 s32 ret_val = -E1000_ERR_PARAM;
547
Auke Kok9d5c8242008-01-24 02:22:38 -0800548
549 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700550 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000551 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800552 }
553
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000554 ret_val = hw->phy.ops.acquire(hw);
555 if (ret_val)
556 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800557
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000558 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800559
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000560 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800561
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000562out:
563 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800564}
565
566/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700567 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800568 * @hw: pointer to the HW structure
569 *
Auke Kok652fff32008-06-27 11:00:18 -0700570 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800571 * sgmi interface.
572 **/
573static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
574{
575 struct e1000_phy_info *phy = &hw->phy;
576 s32 ret_val = 0;
577 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000578 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000579 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800580
581 /*
582 * For SGMII PHYs, we try the list of possible addresses until
583 * we find one that works. For non-SGMII PHYs
584 * (e.g. integrated copper PHYs), an address of 1 should
585 * work. The result of this function should mean phy->phy_addr
586 * and phy->id are set correctly.
587 */
588 if (!(igb_sgmii_active_82575(hw))) {
589 phy->addr = 1;
590 ret_val = igb_get_phy_id(hw);
591 goto out;
592 }
593
Nick Nunley4085f742010-07-26 13:15:06 +0000594 if (igb_sgmii_uses_mdio_82575(hw)) {
595 switch (hw->mac.type) {
596 case e1000_82575:
597 case e1000_82576:
598 mdic = rd32(E1000_MDIC);
599 mdic &= E1000_MDIC_PHY_MASK;
600 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
601 break;
602 case e1000_82580:
603 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000604 case e1000_i210:
605 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000606 mdic = rd32(E1000_MDICNFG);
607 mdic &= E1000_MDICNFG_PHY_MASK;
608 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
609 break;
610 default:
611 ret_val = -E1000_ERR_PHY;
612 goto out;
613 break;
614 }
615 ret_val = igb_get_phy_id(hw);
616 goto out;
617 }
618
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000619 /* Power on sgmii phy if it is disabled */
620 ctrl_ext = rd32(E1000_CTRL_EXT);
621 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
622 wrfl();
623 msleep(300);
624
Auke Kok9d5c8242008-01-24 02:22:38 -0800625 /*
626 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
627 * Therefore, we need to test 1-7
628 */
629 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
630 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
631 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700632 hw_dbg("Vendor ID 0x%08X read at address %u\n",
633 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800634 /*
635 * At the time of this writing, The M88 part is
636 * the only supported SGMII PHY product.
637 */
638 if (phy_id == M88_VENDOR)
639 break;
640 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700641 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800642 }
643 }
644
645 /* A valid PHY type couldn't be found. */
646 if (phy->addr == 8) {
647 phy->addr = 0;
648 ret_val = -E1000_ERR_PHY;
649 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000650 } else {
651 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800652 }
653
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000654 /* restore previous sfp cage power state */
655 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800656
657out:
658 return ret_val;
659}
660
661/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700662 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800663 * @hw: pointer to the HW structure
664 *
665 * Resets the PHY using the serial gigabit media independent interface.
666 **/
667static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
668{
669 s32 ret_val;
670
671 /*
672 * This isn't a true "hard" reset, but is the only reset
673 * available to us at this time.
674 */
675
Auke Kok652fff32008-06-27 11:00:18 -0700676 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800677
678 /*
679 * SFP documentation requires the following to configure the SPF module
680 * to work on SGMII. No further documentation is given.
681 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000682 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800683 if (ret_val)
684 goto out;
685
686 ret_val = igb_phy_sw_reset(hw);
687
688out:
689 return ret_val;
690}
691
692/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700693 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800694 * @hw: pointer to the HW structure
695 * @active: true to enable LPLU, false to disable
696 *
697 * Sets the LPLU D0 state according to the active flag. When
698 * activating LPLU this function also disables smart speed
699 * and vice versa. LPLU will not be activated unless the
700 * device autonegotiation advertisement meets standards of
701 * either 10 or 10/100 or 10/100/1000 at all duplexes.
702 * This is a function pointer entry point only called by
703 * PHY setup routines.
704 **/
705static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
706{
707 struct e1000_phy_info *phy = &hw->phy;
708 s32 ret_val;
709 u16 data;
710
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000711 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 if (ret_val)
713 goto out;
714
715 if (active) {
716 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000717 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700718 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800719 if (ret_val)
720 goto out;
721
722 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000723 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700724 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800725 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000726 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700727 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800728 if (ret_val)
729 goto out;
730 } else {
731 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000732 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700733 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800734 /*
735 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
736 * during Dx states where the power conservation is most
737 * important. During driver activity we should enable
738 * SmartSpeed, so performance is maintained.
739 */
740 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000741 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700742 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800743 if (ret_val)
744 goto out;
745
746 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000747 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700748 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800749 if (ret_val)
750 goto out;
751 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000752 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700753 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800754 if (ret_val)
755 goto out;
756
757 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000758 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700759 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800760 if (ret_val)
761 goto out;
762 }
763 }
764
765out:
766 return ret_val;
767}
768
769/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000770 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
771 * @hw: pointer to the HW structure
772 * @active: true to enable LPLU, false to disable
773 *
774 * Sets the LPLU D0 state according to the active flag. When
775 * activating LPLU this function also disables smart speed
776 * and vice versa. LPLU will not be activated unless the
777 * device autonegotiation advertisement meets standards of
778 * either 10 or 10/100 or 10/100/1000 at all duplexes.
779 * This is a function pointer entry point only called by
780 * PHY setup routines.
781 **/
782static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
783{
784 struct e1000_phy_info *phy = &hw->phy;
785 s32 ret_val = 0;
786 u16 data;
787
788 data = rd32(E1000_82580_PHY_POWER_MGMT);
789
790 if (active) {
791 data |= E1000_82580_PM_D0_LPLU;
792
793 /* When LPLU is enabled, we should disable SmartSpeed */
794 data &= ~E1000_82580_PM_SPD;
795 } else {
796 data &= ~E1000_82580_PM_D0_LPLU;
797
798 /*
799 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
800 * during Dx states where the power conservation is most
801 * important. During driver activity we should enable
802 * SmartSpeed, so performance is maintained.
803 */
804 if (phy->smart_speed == e1000_smart_speed_on)
805 data |= E1000_82580_PM_SPD;
806 else if (phy->smart_speed == e1000_smart_speed_off)
807 data &= ~E1000_82580_PM_SPD; }
808
809 wr32(E1000_82580_PHY_POWER_MGMT, data);
810 return ret_val;
811}
812
813/**
814 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
815 * @hw: pointer to the HW structure
816 * @active: boolean used to enable/disable lplu
817 *
818 * Success returns 0, Failure returns 1
819 *
820 * The low power link up (lplu) state is set to the power management level D3
821 * and SmartSpeed is disabled when active is true, else clear lplu for D3
822 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
823 * is used during Dx states where the power conservation is most important.
824 * During driver activity, SmartSpeed should be enabled so performance is
825 * maintained.
826 **/
827s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
828{
829 struct e1000_phy_info *phy = &hw->phy;
830 s32 ret_val = 0;
831 u16 data;
832
833 data = rd32(E1000_82580_PHY_POWER_MGMT);
834
835 if (!active) {
836 data &= ~E1000_82580_PM_D3_LPLU;
837 /*
838 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
839 * during Dx states where the power conservation is most
840 * important. During driver activity we should enable
841 * SmartSpeed, so performance is maintained.
842 */
843 if (phy->smart_speed == e1000_smart_speed_on)
844 data |= E1000_82580_PM_SPD;
845 else if (phy->smart_speed == e1000_smart_speed_off)
846 data &= ~E1000_82580_PM_SPD;
847 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
848 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
849 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
850 data |= E1000_82580_PM_D3_LPLU;
851 /* When LPLU is enabled, we should disable SmartSpeed */
852 data &= ~E1000_82580_PM_SPD;
853 }
854
855 wr32(E1000_82580_PHY_POWER_MGMT, data);
856 return ret_val;
857}
858
859/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700860 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800861 * @hw: pointer to the HW structure
862 *
Auke Kok652fff32008-06-27 11:00:18 -0700863 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800864 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
865 * Return successful if access grant bit set, else clear the request for
866 * EEPROM access and return -E1000_ERR_NVM (-1).
867 **/
868static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
869{
870 s32 ret_val;
871
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000872 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800873 if (ret_val)
874 goto out;
875
876 ret_val = igb_acquire_nvm(hw);
877
878 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000879 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800880
881out:
882 return ret_val;
883}
884
885/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700886 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 * @hw: pointer to the HW structure
888 *
889 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
890 * then release the semaphores acquired.
891 **/
892static void igb_release_nvm_82575(struct e1000_hw *hw)
893{
894 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000895 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800896}
897
898/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700899 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800900 * @hw: pointer to the HW structure
901 * @mask: specifies which semaphore to acquire
902 *
903 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
904 * will also specify which port we're acquiring the lock for.
905 **/
906static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
907{
908 u32 swfw_sync;
909 u32 swmask = mask;
910 u32 fwmask = mask << 16;
911 s32 ret_val = 0;
912 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
913
914 while (i < timeout) {
915 if (igb_get_hw_semaphore(hw)) {
916 ret_val = -E1000_ERR_SWFW_SYNC;
917 goto out;
918 }
919
920 swfw_sync = rd32(E1000_SW_FW_SYNC);
921 if (!(swfw_sync & (fwmask | swmask)))
922 break;
923
924 /*
925 * Firmware currently using resource (fwmask)
926 * or other software thread using resource (swmask)
927 */
928 igb_put_hw_semaphore(hw);
929 mdelay(5);
930 i++;
931 }
932
933 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -0700934 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800935 ret_val = -E1000_ERR_SWFW_SYNC;
936 goto out;
937 }
938
939 swfw_sync |= swmask;
940 wr32(E1000_SW_FW_SYNC, swfw_sync);
941
942 igb_put_hw_semaphore(hw);
943
944out:
945 return ret_val;
946}
947
948/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700949 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800950 * @hw: pointer to the HW structure
951 * @mask: specifies which semaphore to acquire
952 *
953 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
954 * will also specify which port we're releasing the lock for.
955 **/
956static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
957{
958 u32 swfw_sync;
959
960 while (igb_get_hw_semaphore(hw) != 0);
961 /* Empty */
962
963 swfw_sync = rd32(E1000_SW_FW_SYNC);
964 swfw_sync &= ~mask;
965 wr32(E1000_SW_FW_SYNC, swfw_sync);
966
967 igb_put_hw_semaphore(hw);
968}
969
970/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700971 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -0800972 * @hw: pointer to the HW structure
973 *
974 * Read the management control register for the config done bit for
975 * completion status. NOTE: silicon which is EEPROM-less will fail trying
976 * to read the config done bit, so an error is *ONLY* logged and returns
977 * 0. If we were to return with error, EEPROM-less silicon
978 * would not be able to be reset or change link.
979 **/
980static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
981{
982 s32 timeout = PHY_CFG_TIMEOUT;
983 s32 ret_val = 0;
984 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
985
986 if (hw->bus.func == 1)
987 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000988 else if (hw->bus.func == E1000_FUNC_2)
989 mask = E1000_NVM_CFG_DONE_PORT_2;
990 else if (hw->bus.func == E1000_FUNC_3)
991 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -0800992
993 while (timeout) {
994 if (rd32(E1000_EEMNGCTL) & mask)
995 break;
996 msleep(1);
997 timeout--;
998 }
999 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001000 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001001
1002 /* If EEPROM is not marked present, init the PHY manually */
1003 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1004 (hw->phy.type == e1000_phy_igp_3))
1005 igb_phy_init_script_igp3(hw);
1006
1007 return ret_val;
1008}
1009
1010/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001011 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001012 * @hw: pointer to the HW structure
1013 *
1014 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1015 * use the generic interface for determining link.
1016 **/
1017static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1018{
1019 s32 ret_val;
1020 u16 speed, duplex;
1021
Alexander Duyck70d92f82009-10-05 06:31:47 +00001022 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001023 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001024 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001025 /*
1026 * Use this flag to determine if link needs to be checked or
1027 * not. If we have link clear the flag so that we do not
1028 * continue to check for link.
1029 */
1030 hw->mac.get_link_status = !hw->mac.serdes_has_link;
1031 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001032 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001033 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001034
1035 return ret_val;
1036}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001037
Auke Kok9d5c8242008-01-24 02:22:38 -08001038/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001039 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1040 * @hw: pointer to the HW structure
1041 **/
1042void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1043{
1044 u32 reg;
1045
1046
1047 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1048 !igb_sgmii_active_82575(hw))
1049 return;
1050
1051 /* Enable PCS to turn on link */
1052 reg = rd32(E1000_PCS_CFG0);
1053 reg |= E1000_PCS_CFG_PCS_EN;
1054 wr32(E1000_PCS_CFG0, reg);
1055
1056 /* Power up the laser */
1057 reg = rd32(E1000_CTRL_EXT);
1058 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1059 wr32(E1000_CTRL_EXT, reg);
1060
1061 /* flush the write to verify completion */
1062 wrfl();
1063 msleep(1);
1064}
1065
1066/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001067 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001068 * @hw: pointer to the HW structure
1069 * @speed: stores the current speed
1070 * @duplex: stores the current duplex
1071 *
Auke Kok652fff32008-06-27 11:00:18 -07001072 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001073 * duplex, then store the values in the pointers provided.
1074 **/
1075static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1076 u16 *duplex)
1077{
1078 struct e1000_mac_info *mac = &hw->mac;
1079 u32 pcs;
1080
1081 /* Set up defaults for the return values of this function */
1082 mac->serdes_has_link = false;
1083 *speed = 0;
1084 *duplex = 0;
1085
1086 /*
1087 * Read the PCS Status register for link state. For non-copper mode,
1088 * the status register is not accurate. The PCS status register is
1089 * used instead.
1090 */
1091 pcs = rd32(E1000_PCS_LSTAT);
1092
1093 /*
1094 * The link up bit determines when link is up on autoneg. The sync ok
1095 * gets set once both sides sync up and agree upon link. Stable link
1096 * can be determined by checking for both link up and link sync ok
1097 */
1098 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1099 mac->serdes_has_link = true;
1100
1101 /* Detect and store PCS speed */
1102 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
1103 *speed = SPEED_1000;
1104 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
1105 *speed = SPEED_100;
1106 } else {
1107 *speed = SPEED_10;
1108 }
1109
1110 /* Detect and store PCS duplex */
1111 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
1112 *duplex = FULL_DUPLEX;
1113 } else {
1114 *duplex = HALF_DUPLEX;
1115 }
1116 }
1117
1118 return 0;
1119}
1120
1121/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001122 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001123 * @hw: pointer to the HW structure
1124 *
1125 * In the case of fiber serdes, shut down optics and PCS on driver unload
1126 * when management pass thru is not enabled.
1127 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001128void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001129{
1130 u32 reg;
1131
Nick Nunley53c992f2010-02-17 01:01:40 +00001132 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001133 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001134 return;
1135
Nick Nunley53c992f2010-02-17 01:01:40 +00001136 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001137 /* Disable PCS to turn off link */
1138 reg = rd32(E1000_PCS_CFG0);
1139 reg &= ~E1000_PCS_CFG_PCS_EN;
1140 wr32(E1000_PCS_CFG0, reg);
1141
1142 /* shutdown the laser */
1143 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001144 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001145 wr32(E1000_CTRL_EXT, reg);
1146
1147 /* flush the write to verify completion */
1148 wrfl();
1149 msleep(1);
1150 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001151}
1152
1153/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001154 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001155 * @hw: pointer to the HW structure
1156 *
1157 * This resets the hardware into a known state. This is a
1158 * function pointer entry point called by the api module.
1159 **/
1160static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1161{
1162 u32 ctrl, icr;
1163 s32 ret_val;
1164
1165 /*
1166 * Prevent the PCI-E bus from sticking if there is no TLP connection
1167 * on the last TLP read/write transaction when MAC is reset.
1168 */
1169 ret_val = igb_disable_pcie_master(hw);
1170 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001171 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001172
Alexander Duyck009bc062009-07-23 18:08:35 +00001173 /* set the completion timeout for interface */
1174 ret_val = igb_set_pcie_completion_timeout(hw);
1175 if (ret_val) {
1176 hw_dbg("PCI-E Set completion timeout has failed.\n");
1177 }
1178
Auke Kok652fff32008-06-27 11:00:18 -07001179 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001180 wr32(E1000_IMC, 0xffffffff);
1181
1182 wr32(E1000_RCTL, 0);
1183 wr32(E1000_TCTL, E1000_TCTL_PSP);
1184 wrfl();
1185
1186 msleep(10);
1187
1188 ctrl = rd32(E1000_CTRL);
1189
Auke Kok652fff32008-06-27 11:00:18 -07001190 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001191 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1192
1193 ret_val = igb_get_auto_rd_done(hw);
1194 if (ret_val) {
1195 /*
1196 * When auto config read does not complete, do not
1197 * return with an error. This can happen in situations
1198 * where there is no eeprom and prevents getting link.
1199 */
Auke Kok652fff32008-06-27 11:00:18 -07001200 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001201 }
1202
1203 /* If EEPROM is not present, run manual init scripts */
1204 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1205 igb_reset_init_script_82575(hw);
1206
1207 /* Clear any pending interrupt events. */
1208 wr32(E1000_IMC, 0xffffffff);
1209 icr = rd32(E1000_ICR);
1210
Alexander Duyck5ac16652009-07-23 18:09:12 +00001211 /* Install any alternate MAC address into RAR0 */
1212 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001213
1214 return ret_val;
1215}
1216
1217/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001218 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001219 * @hw: pointer to the HW structure
1220 *
1221 * This inits the hardware readying it for operation.
1222 **/
1223static s32 igb_init_hw_82575(struct e1000_hw *hw)
1224{
1225 struct e1000_mac_info *mac = &hw->mac;
1226 s32 ret_val;
1227 u16 i, rar_count = mac->rar_entry_count;
1228
1229 /* Initialize identification LED */
1230 ret_val = igb_id_led_init(hw);
1231 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001232 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001233 /* This is not fatal and we should not stop init due to this */
1234 }
1235
1236 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001237 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001238 if (hw->mac.type == e1000_i350)
1239 igb_clear_vfta_i350(hw);
1240 else
1241 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001242
1243 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001244 igb_init_rx_addrs(hw, rar_count);
1245
Auke Kok9d5c8242008-01-24 02:22:38 -08001246 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001247 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001248 for (i = 0; i < mac->mta_reg_count; i++)
1249 array_wr32(E1000_MTA, i, 0);
1250
Alexander Duyck68d480c2009-10-05 06:33:08 +00001251 /* Zero out the Unicast HASH table */
1252 hw_dbg("Zeroing the UTA\n");
1253 for (i = 0; i < mac->uta_reg_count; i++)
1254 array_wr32(E1000_UTA, i, 0);
1255
Auke Kok9d5c8242008-01-24 02:22:38 -08001256 /* Setup link and flow control */
1257 ret_val = igb_setup_link(hw);
1258
1259 /*
1260 * Clear all of the statistics registers (clear on read). It is
1261 * important that we do this after we have tried to establish link
1262 * because the symbol error count will increment wildly if there
1263 * is no link.
1264 */
1265 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001266 return ret_val;
1267}
1268
1269/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001270 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001271 * @hw: pointer to the HW structure
1272 *
1273 * Configures the link for auto-neg or forced speed and duplex. Then we check
1274 * for link, once link is established calls to configure collision distance
1275 * and flow control are called.
1276 **/
1277static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1278{
Alexander Duyck12645a12009-07-23 18:08:16 +00001279 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001280 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001281 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001282
1283 ctrl = rd32(E1000_CTRL);
1284 ctrl |= E1000_CTRL_SLU;
1285 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1286 wr32(E1000_CTRL, ctrl);
1287
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001288 /* Clear Go Link Disconnect bit */
1289 if (hw->mac.type >= e1000_82580) {
1290 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1291 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1292 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
1293 }
1294
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001295 ret_val = igb_setup_serdes_link_82575(hw);
1296 if (ret_val)
1297 goto out;
1298
1299 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001300 /* allow time for SFP cage time to power up phy */
1301 msleep(300);
1302
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001303 ret_val = hw->phy.ops.reset(hw);
1304 if (ret_val) {
1305 hw_dbg("Error resetting the PHY.\n");
1306 goto out;
1307 }
1308 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001309 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001310 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001311 case e1000_phy_m88:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001312 if (hw->phy.id == I347AT4_E_PHY_ID ||
1313 hw->phy.id == M88E1112_E_PHY_ID)
1314 ret_val = igb_copper_link_setup_m88_gen2(hw);
1315 else
1316 ret_val = igb_copper_link_setup_m88(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001317 break;
1318 case e1000_phy_igp_3:
1319 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001320 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001321 case e1000_phy_82580:
1322 ret_val = igb_copper_link_setup_82580(hw);
1323 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 default:
1325 ret_val = -E1000_ERR_PHY;
1326 break;
1327 }
1328
1329 if (ret_val)
1330 goto out;
1331
Alexander Duyck81fadd82009-10-05 06:35:03 +00001332 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001333out:
1334 return ret_val;
1335}
1336
1337/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001338 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001339 * @hw: pointer to the HW structure
1340 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001341 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1342 * used on copper connections where the serialized gigabit media independent
1343 * interface (sgmii), or serdes fiber is being used. Configures the link
1344 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001345 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001346static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001347{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001348 u32 ctrl_ext, ctrl_reg, reg;
1349 bool pcs_autoneg;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001350 s32 ret_val = E1000_SUCCESS;
1351 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001352
1353 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1354 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001355 return ret_val;
1356
Auke Kok9d5c8242008-01-24 02:22:38 -08001357
1358 /*
1359 * On the 82575, SerDes loopback mode persists until it is
1360 * explicitly turned off or a power cycle is performed. A read to
1361 * the register does not indicate its status. Therefore, we ensure
1362 * loopback mode is disabled during initialization.
1363 */
1364 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1365
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001366 /* power on the sfp cage if present */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001367 ctrl_ext = rd32(E1000_CTRL_EXT);
1368 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1369 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001370
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001371 ctrl_reg = rd32(E1000_CTRL);
1372 ctrl_reg |= E1000_CTRL_SLU;
1373
1374 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1375 /* set both sw defined pins */
1376 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1377
1378 /* Set switch control to serdes energy detect */
1379 reg = rd32(E1000_CONNSW);
1380 reg |= E1000_CONNSW_ENRGSRC;
1381 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001382 }
1383
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001384 reg = rd32(E1000_PCS_LCTL);
1385
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001386 /* default pcs_autoneg to the same setting as mac autoneg */
1387 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001388
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001389 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1390 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1391 /* sgmii mode lets the phy handle forcing speed/duplex */
1392 pcs_autoneg = true;
1393 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001394 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001395 break;
1396 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1397 /* disable PCS autoneg and support parallel detect only */
1398 pcs_autoneg = false;
1399 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001400 if (hw->mac.type == e1000_82575 ||
1401 hw->mac.type == e1000_82576) {
1402 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1403 if (ret_val) {
1404 printk(KERN_DEBUG "NVM Read Error\n\n");
1405 return ret_val;
1406 }
1407
1408 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1409 pcs_autoneg = false;
1410 }
1411
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001412 /*
1413 * non-SGMII modes only supports a speed of 1000/Full for the
1414 * link so it is best to just force the MAC and let the pcs
1415 * link either autoneg or be forced to 1000/Full
1416 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001417 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1418 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001419
1420 /* set speed of 1000/Full if speed/duplex is forced */
1421 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1422 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001423 }
1424
1425 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001426
1427 /*
1428 * New SerDes mode allows for forcing speed or autonegotiating speed
1429 * at 1gb. Autoneg should be default set by most drivers. This is the
1430 * mode that will be compatible with older link partners and switches.
1431 * However, both are supported by the hardware and some drivers/tools.
1432 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001433 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1434 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1435
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001436 /*
1437 * We force flow control to prevent the CTRL register values from being
1438 * overwritten by the autonegotiated flow control values
1439 */
1440 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1441
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001442 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001443 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001444 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001445 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001446 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001447 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001448 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001449 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001450
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001451 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001452 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001453
Auke Kok9d5c8242008-01-24 02:22:38 -08001454 wr32(E1000_PCS_LCTL, reg);
1455
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001456 if (!igb_sgmii_active_82575(hw))
1457 igb_force_mac_fc(hw);
1458
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001459 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001460}
1461
1462/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001463 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001464 * @hw: pointer to the HW structure
1465 *
1466 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1467 * which can be enabled for use in the embedded applications. Simply
1468 * return the current state of the sgmii interface.
1469 **/
1470static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1471{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001472 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001473 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001474}
1475
1476/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001477 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001478 * @hw: pointer to the HW structure
1479 *
1480 * Inits recommended HW defaults after a reset when there is no EEPROM
1481 * detected. This is only for the 82575.
1482 **/
1483static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1484{
1485 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001486 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001487 /* SerDes configuration via SERDESCTRL */
1488 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1489 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1490 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1491 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1492
1493 /* CCM configuration via CCMCTL register */
1494 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1495 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1496
1497 /* PCIe lanes configuration */
1498 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1499 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1500 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1501 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1502
1503 /* PCIe PLL Configuration */
1504 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1505 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1506 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1507 }
1508
1509 return 0;
1510}
1511
1512/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001513 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001514 * @hw: pointer to the HW structure
1515 **/
1516static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1517{
1518 s32 ret_val = 0;
1519
Alexander Duyck22896632009-10-05 06:34:25 +00001520 /*
1521 * If there's an alternate MAC address place it in RAR0
1522 * so that it will override the Si installed default perm
1523 * address.
1524 */
1525 ret_val = igb_check_alt_mac_addr(hw);
1526 if (ret_val)
1527 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001528
Alexander Duyck22896632009-10-05 06:34:25 +00001529 ret_val = igb_read_mac_addr(hw);
1530
1531out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001532 return ret_val;
1533}
1534
1535/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001536 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1537 * @hw: pointer to the HW structure
1538 *
1539 * In the case of a PHY power down to save power, or to turn off link during a
1540 * driver unload, or wake on lan is not enabled, remove the link.
1541 **/
1542void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1543{
1544 /* If the management interface is not enabled, then power down */
1545 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1546 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001547}
1548
1549/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001550 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001551 * @hw: pointer to the HW structure
1552 *
1553 * Clears the hardware counters by reading the counter registers.
1554 **/
1555static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1556{
Auke Kok9d5c8242008-01-24 02:22:38 -08001557 igb_clear_hw_cntrs_base(hw);
1558
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001559 rd32(E1000_PRC64);
1560 rd32(E1000_PRC127);
1561 rd32(E1000_PRC255);
1562 rd32(E1000_PRC511);
1563 rd32(E1000_PRC1023);
1564 rd32(E1000_PRC1522);
1565 rd32(E1000_PTC64);
1566 rd32(E1000_PTC127);
1567 rd32(E1000_PTC255);
1568 rd32(E1000_PTC511);
1569 rd32(E1000_PTC1023);
1570 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001571
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001572 rd32(E1000_ALGNERRC);
1573 rd32(E1000_RXERRC);
1574 rd32(E1000_TNCRS);
1575 rd32(E1000_CEXTERR);
1576 rd32(E1000_TSCTC);
1577 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001578
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001579 rd32(E1000_MGTPRC);
1580 rd32(E1000_MGTPDC);
1581 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001582
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001583 rd32(E1000_IAC);
1584 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001585
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001586 rd32(E1000_ICRXPTC);
1587 rd32(E1000_ICRXATC);
1588 rd32(E1000_ICTXPTC);
1589 rd32(E1000_ICTXATC);
1590 rd32(E1000_ICTXQEC);
1591 rd32(E1000_ICTXQMTC);
1592 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001593
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001594 rd32(E1000_CBTMPC);
1595 rd32(E1000_HTDPMC);
1596 rd32(E1000_CBRMPC);
1597 rd32(E1000_RPTHC);
1598 rd32(E1000_HGPTC);
1599 rd32(E1000_HTCBDPC);
1600 rd32(E1000_HGORCL);
1601 rd32(E1000_HGORCH);
1602 rd32(E1000_HGOTCL);
1603 rd32(E1000_HGOTCH);
1604 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001605
1606 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001607 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1608 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001609 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001610}
1611
Alexander Duyck662d7202008-06-27 11:00:29 -07001612/**
1613 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1614 * @hw: pointer to the HW structure
1615 *
1616 * After rx enable if managability is enabled then there is likely some
1617 * bad data at the start of the fifo and possibly in the DMA fifo. This
1618 * function clears the fifos and flushes any packets that came in as rx was
1619 * being enabled.
1620 **/
1621void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1622{
1623 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1624 int i, ms_wait;
1625
1626 if (hw->mac.type != e1000_82575 ||
1627 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1628 return;
1629
1630 /* Disable all RX queues */
1631 for (i = 0; i < 4; i++) {
1632 rxdctl[i] = rd32(E1000_RXDCTL(i));
1633 wr32(E1000_RXDCTL(i),
1634 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1635 }
1636 /* Poll all queues to verify they have shut down */
1637 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1638 msleep(1);
1639 rx_enabled = 0;
1640 for (i = 0; i < 4; i++)
1641 rx_enabled |= rd32(E1000_RXDCTL(i));
1642 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1643 break;
1644 }
1645
1646 if (ms_wait == 10)
1647 hw_dbg("Queue disable timed out after 10ms\n");
1648
1649 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1650 * incoming packets are rejected. Set enable and wait 2ms so that
1651 * any packet that was coming in as RCTL.EN was set is flushed
1652 */
1653 rfctl = rd32(E1000_RFCTL);
1654 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1655
1656 rlpml = rd32(E1000_RLPML);
1657 wr32(E1000_RLPML, 0);
1658
1659 rctl = rd32(E1000_RCTL);
1660 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1661 temp_rctl |= E1000_RCTL_LPE;
1662
1663 wr32(E1000_RCTL, temp_rctl);
1664 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1665 wrfl();
1666 msleep(2);
1667
1668 /* Enable RX queues that were previously enabled and restore our
1669 * previous state
1670 */
1671 for (i = 0; i < 4; i++)
1672 wr32(E1000_RXDCTL(i), rxdctl[i]);
1673 wr32(E1000_RCTL, rctl);
1674 wrfl();
1675
1676 wr32(E1000_RLPML, rlpml);
1677 wr32(E1000_RFCTL, rfctl);
1678
1679 /* Flush receive errors generated by workaround */
1680 rd32(E1000_ROC);
1681 rd32(E1000_RNBC);
1682 rd32(E1000_MPC);
1683}
1684
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001685/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001686 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1687 * @hw: pointer to the HW structure
1688 *
1689 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1690 * however the hardware default for these parts is 500us to 1ms which is less
1691 * than the 10ms recommended by the pci-e spec. To address this we need to
1692 * increase the value to either 10ms to 200ms for capability version 1 config,
1693 * or 16ms to 55ms for version 2.
1694 **/
1695static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1696{
1697 u32 gcr = rd32(E1000_GCR);
1698 s32 ret_val = 0;
1699 u16 pcie_devctl2;
1700
1701 /* only take action if timeout value is defaulted to 0 */
1702 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1703 goto out;
1704
1705 /*
1706 * if capababilities version is type 1 we can write the
1707 * timeout of 10ms to 200ms through the GCR register
1708 */
1709 if (!(gcr & E1000_GCR_CAP_VER2)) {
1710 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1711 goto out;
1712 }
1713
1714 /*
1715 * for version 2 capabilities we need to write the config space
1716 * directly in order to set the completion timeout value for
1717 * 16ms to 55ms
1718 */
1719 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1720 &pcie_devctl2);
1721 if (ret_val)
1722 goto out;
1723
1724 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1725
1726 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1727 &pcie_devctl2);
1728out:
1729 /* disable completion timeout resend */
1730 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1731
1732 wr32(E1000_GCR, gcr);
1733 return ret_val;
1734}
1735
1736/**
Greg Rose13800462010-11-06 02:08:26 +00001737 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
1738 * @hw: pointer to the hardware struct
1739 * @enable: state to enter, either enabled or disabled
1740 * @pf: Physical Function pool - do not set anti-spoofing for the PF
1741 *
1742 * enables/disables L2 switch anti-spoofing functionality.
1743 **/
1744void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
1745{
1746 u32 dtxswc;
1747
1748 switch (hw->mac.type) {
1749 case e1000_82576:
1750 case e1000_i350:
1751 dtxswc = rd32(E1000_DTXSWC);
1752 if (enable) {
1753 dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK |
1754 E1000_DTXSWC_VLAN_SPOOF_MASK);
1755 /* The PF can spoof - it has to in order to
1756 * support emulation mode NICs */
1757 dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
1758 } else {
1759 dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
1760 E1000_DTXSWC_VLAN_SPOOF_MASK);
1761 }
1762 wr32(E1000_DTXSWC, dtxswc);
1763 break;
1764 default:
1765 break;
1766 }
1767}
1768
1769/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001770 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1771 * @hw: pointer to the hardware struct
1772 * @enable: state to enter, either enabled or disabled
1773 *
1774 * enables/disables L2 switch loopback functionality.
1775 **/
1776void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1777{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001778 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001779
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001780 switch (hw->mac.type) {
1781 case e1000_82576:
1782 dtxswc = rd32(E1000_DTXSWC);
1783 if (enable)
1784 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1785 else
1786 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1787 wr32(E1000_DTXSWC, dtxswc);
1788 break;
1789 case e1000_i350:
1790 dtxswc = rd32(E1000_TXSWC);
1791 if (enable)
1792 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1793 else
1794 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1795 wr32(E1000_TXSWC, dtxswc);
1796 break;
1797 default:
1798 /* Currently no other hardware supports loopback */
1799 break;
1800 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001801
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00001802
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001803}
1804
1805/**
1806 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1807 * @hw: pointer to the hardware struct
1808 * @enable: state to enter, either enabled or disabled
1809 *
1810 * enables/disables replication of packets across multiple pools.
1811 **/
1812void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1813{
1814 u32 vt_ctl = rd32(E1000_VT_CTL);
1815
1816 if (enable)
1817 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1818 else
1819 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1820
1821 wr32(E1000_VT_CTL, vt_ctl);
1822}
1823
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001824/**
1825 * igb_read_phy_reg_82580 - Read 82580 MDI control register
1826 * @hw: pointer to the HW structure
1827 * @offset: register offset to be read
1828 * @data: pointer to the read data
1829 *
1830 * Reads the MDI control register in the PHY at offset and stores the
1831 * information read to data.
1832 **/
1833static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
1834{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001835 s32 ret_val;
1836
1837
1838 ret_val = hw->phy.ops.acquire(hw);
1839 if (ret_val)
1840 goto out;
1841
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001842 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
1843
1844 hw->phy.ops.release(hw);
1845
1846out:
1847 return ret_val;
1848}
1849
1850/**
1851 * igb_write_phy_reg_82580 - Write 82580 MDI control register
1852 * @hw: pointer to the HW structure
1853 * @offset: register offset to write to
1854 * @data: data to write to register at offset
1855 *
1856 * Writes data to MDI control register in the PHY at offset.
1857 **/
1858static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
1859{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001860 s32 ret_val;
1861
1862
1863 ret_val = hw->phy.ops.acquire(hw);
1864 if (ret_val)
1865 goto out;
1866
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001867 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
1868
1869 hw->phy.ops.release(hw);
1870
1871out:
1872 return ret_val;
1873}
1874
1875/**
Nick Nunley08451e22010-07-26 13:15:29 +00001876 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
1877 * @hw: pointer to the HW structure
1878 *
1879 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
1880 * the values found in the EEPROM. This addresses an issue in which these
1881 * bits are not restored from EEPROM after reset.
1882 **/
1883static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
1884{
1885 s32 ret_val = 0;
1886 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00001887 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00001888
1889 if (hw->mac.type != e1000_82580)
1890 goto out;
1891 if (!igb_sgmii_active_82575(hw))
1892 goto out;
1893
1894 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
1895 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
1896 &nvm_data);
1897 if (ret_val) {
1898 hw_dbg("NVM Read Error\n");
1899 goto out;
1900 }
1901
1902 mdicnfg = rd32(E1000_MDICNFG);
1903 if (nvm_data & NVM_WORD24_EXT_MDIO)
1904 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
1905 if (nvm_data & NVM_WORD24_COM_MDIO)
1906 mdicnfg |= E1000_MDICNFG_COM_MDIO;
1907 wr32(E1000_MDICNFG, mdicnfg);
1908out:
1909 return ret_val;
1910}
1911
1912/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001913 * igb_reset_hw_82580 - Reset hardware
1914 * @hw: pointer to the HW structure
1915 *
1916 * This resets function or entire device (all ports, etc.)
1917 * to a known state.
1918 **/
1919static s32 igb_reset_hw_82580(struct e1000_hw *hw)
1920{
1921 s32 ret_val = 0;
1922 /* BH SW mailbox bit in SW_FW_SYNC */
1923 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
1924 u32 ctrl, icr;
1925 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
1926
1927
1928 hw->dev_spec._82575.global_device_reset = false;
1929
1930 /* Get current control state. */
1931 ctrl = rd32(E1000_CTRL);
1932
1933 /*
1934 * Prevent the PCI-E bus from sticking if there is no TLP connection
1935 * on the last TLP read/write transaction when MAC is reset.
1936 */
1937 ret_val = igb_disable_pcie_master(hw);
1938 if (ret_val)
1939 hw_dbg("PCI-E Master disable polling has failed.\n");
1940
1941 hw_dbg("Masking off all interrupts\n");
1942 wr32(E1000_IMC, 0xffffffff);
1943 wr32(E1000_RCTL, 0);
1944 wr32(E1000_TCTL, E1000_TCTL_PSP);
1945 wrfl();
1946
1947 msleep(10);
1948
1949 /* Determine whether or not a global dev reset is requested */
1950 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001951 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001952 global_device_reset = false;
1953
1954 if (global_device_reset &&
1955 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
1956 ctrl |= E1000_CTRL_DEV_RST;
1957 else
1958 ctrl |= E1000_CTRL_RST;
1959
1960 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00001961 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001962
1963 /* Add delay to insure DEV_RST has time to complete */
1964 if (global_device_reset)
1965 msleep(5);
1966
1967 ret_val = igb_get_auto_rd_done(hw);
1968 if (ret_val) {
1969 /*
1970 * When auto config read does not complete, do not
1971 * return with an error. This can happen in situations
1972 * where there is no eeprom and prevents getting link.
1973 */
1974 hw_dbg("Auto Read Done did not complete\n");
1975 }
1976
1977 /* If EEPROM is not present, run manual init scripts */
1978 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1979 igb_reset_init_script_82575(hw);
1980
1981 /* clear global device reset status bit */
1982 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
1983
1984 /* Clear any pending interrupt events. */
1985 wr32(E1000_IMC, 0xffffffff);
1986 icr = rd32(E1000_ICR);
1987
Nick Nunley08451e22010-07-26 13:15:29 +00001988 ret_val = igb_reset_mdicnfg_82580(hw);
1989 if (ret_val)
1990 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
1991
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001992 /* Install any alternate MAC address into RAR0 */
1993 ret_val = igb_check_alt_mac_addr(hw);
1994
1995 /* Release semaphore */
1996 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001997 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001998
1999 return ret_val;
2000}
2001
2002/**
2003 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2004 * @data: data received by reading RXPBS register
2005 *
2006 * The 82580 uses a table based approach for packet buffer allocation sizes.
2007 * This function converts the retrieved value into the correct table value
2008 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2009 * 0x0 36 72 144 1 2 4 8 16
2010 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2011 */
2012u16 igb_rxpbs_adjust_82580(u32 data)
2013{
2014 u16 ret_val = 0;
2015
2016 if (data < E1000_82580_RXPBS_TABLE_SIZE)
2017 ret_val = e1000_82580_rxpbs_table[data];
2018
2019 return ret_val;
2020}
2021
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002022/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002023 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2024 * checksum
2025 * @hw: pointer to the HW structure
2026 * @offset: offset in words of the checksum protected region
2027 *
2028 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2029 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2030 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002031static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2032 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002033{
2034 s32 ret_val = 0;
2035 u16 checksum = 0;
2036 u16 i, nvm_data;
2037
2038 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2039 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2040 if (ret_val) {
2041 hw_dbg("NVM Read Error\n");
2042 goto out;
2043 }
2044 checksum += nvm_data;
2045 }
2046
2047 if (checksum != (u16) NVM_SUM) {
2048 hw_dbg("NVM Checksum Invalid\n");
2049 ret_val = -E1000_ERR_NVM;
2050 goto out;
2051 }
2052
2053out:
2054 return ret_val;
2055}
2056
2057/**
2058 * igb_update_nvm_checksum_with_offset - Update EEPROM
2059 * checksum
2060 * @hw: pointer to the HW structure
2061 * @offset: offset in words of the checksum protected region
2062 *
2063 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2064 * up to the checksum. Then calculates the EEPROM checksum and writes the
2065 * value to the EEPROM.
2066 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002067static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002068{
2069 s32 ret_val;
2070 u16 checksum = 0;
2071 u16 i, nvm_data;
2072
2073 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2074 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2075 if (ret_val) {
2076 hw_dbg("NVM Read Error while updating checksum.\n");
2077 goto out;
2078 }
2079 checksum += nvm_data;
2080 }
2081 checksum = (u16) NVM_SUM - checksum;
2082 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2083 &checksum);
2084 if (ret_val)
2085 hw_dbg("NVM Write Error while updating checksum.\n");
2086
2087out:
2088 return ret_val;
2089}
2090
2091/**
2092 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2093 * @hw: pointer to the HW structure
2094 *
2095 * Calculates the EEPROM section checksum by reading/adding each word of
2096 * the EEPROM and then verifies that the sum of the EEPROM is
2097 * equal to 0xBABA.
2098 **/
2099static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2100{
2101 s32 ret_val = 0;
2102 u16 eeprom_regions_count = 1;
2103 u16 j, nvm_data;
2104 u16 nvm_offset;
2105
2106 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2107 if (ret_val) {
2108 hw_dbg("NVM Read Error\n");
2109 goto out;
2110 }
2111
2112 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002113 /* if checksums compatibility bit is set validate checksums
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002114 * for all 4 ports. */
2115 eeprom_regions_count = 4;
2116 }
2117
2118 for (j = 0; j < eeprom_regions_count; j++) {
2119 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2120 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2121 nvm_offset);
2122 if (ret_val != 0)
2123 goto out;
2124 }
2125
2126out:
2127 return ret_val;
2128}
2129
2130/**
2131 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2132 * @hw: pointer to the HW structure
2133 *
2134 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2135 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2136 * checksum and writes the value to the EEPROM.
2137 **/
2138static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2139{
2140 s32 ret_val;
2141 u16 j, nvm_data;
2142 u16 nvm_offset;
2143
2144 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2145 if (ret_val) {
2146 hw_dbg("NVM Read Error while updating checksum"
2147 " compatibility bit.\n");
2148 goto out;
2149 }
2150
2151 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2152 /* set compatibility bit to validate checksums appropriately */
2153 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2154 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2155 &nvm_data);
2156 if (ret_val) {
2157 hw_dbg("NVM Write Error while updating checksum"
2158 " compatibility bit.\n");
2159 goto out;
2160 }
2161 }
2162
2163 for (j = 0; j < 4; j++) {
2164 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2165 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2166 if (ret_val)
2167 goto out;
2168 }
2169
2170out:
2171 return ret_val;
2172}
2173
2174/**
2175 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2176 * @hw: pointer to the HW structure
2177 *
2178 * Calculates the EEPROM section checksum by reading/adding each word of
2179 * the EEPROM and then verifies that the sum of the EEPROM is
2180 * equal to 0xBABA.
2181 **/
2182static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2183{
2184 s32 ret_val = 0;
2185 u16 j;
2186 u16 nvm_offset;
2187
2188 for (j = 0; j < 4; j++) {
2189 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2190 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2191 nvm_offset);
2192 if (ret_val != 0)
2193 goto out;
2194 }
2195
2196out:
2197 return ret_val;
2198}
2199
2200/**
2201 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2202 * @hw: pointer to the HW structure
2203 *
2204 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2205 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2206 * checksum and writes the value to the EEPROM.
2207 **/
2208static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2209{
2210 s32 ret_val = 0;
2211 u16 j;
2212 u16 nvm_offset;
2213
2214 for (j = 0; j < 4; j++) {
2215 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2216 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2217 if (ret_val != 0)
2218 goto out;
2219 }
2220
2221out:
2222 return ret_val;
2223}
Stefan Assmann34a03262011-04-05 04:27:05 +00002224
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002225/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002226 * igb_set_eee_i350 - Enable/disable EEE support
2227 * @hw: pointer to the HW structure
2228 *
2229 * Enable/disable EEE based on setting in dev_spec structure.
2230 *
2231 **/
2232s32 igb_set_eee_i350(struct e1000_hw *hw)
2233{
2234 s32 ret_val = 0;
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002235 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002236
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002237 if ((hw->mac.type < e1000_i350) ||
2238 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002239 goto out;
2240 ipcnfg = rd32(E1000_IPCNFG);
2241 eeer = rd32(E1000_EEER);
2242
2243 /* enable or disable per user setting */
2244 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002245 u32 eee_su = rd32(E1000_EEE_SU);
2246
2247 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2248 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002249 E1000_EEER_LPI_FC);
2250
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002251 /* This bit should not be set in normal operation. */
2252 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2253 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2254
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002255
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002256 } else {
2257 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2258 E1000_IPCNFG_EEE_100M_AN);
2259 eeer &= ~(E1000_EEER_TX_LPI_EN |
2260 E1000_EEER_RX_LPI_EN |
2261 E1000_EEER_LPI_FC);
2262 }
2263 wr32(E1000_IPCNFG, ipcnfg);
2264 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002265 rd32(E1000_IPCNFG);
2266 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002267out:
2268
2269 return ret_val;
2270}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002271
Auke Kok9d5c8242008-01-24 02:22:38 -08002272static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002273 .init_hw = igb_init_hw_82575,
2274 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002275 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002276 .read_mac_addr = igb_read_mac_addr_82575,
2277 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
2278};
2279
2280static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002281 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002282 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002283 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002284};
2285
2286static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002287 .acquire = igb_acquire_nvm_82575,
2288 .read = igb_read_nvm_eerd,
2289 .release = igb_release_nvm_82575,
2290 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002291};
2292
2293const struct e1000_info e1000_82575_info = {
2294 .get_invariants = igb_get_invariants_82575,
2295 .mac_ops = &e1000_mac_ops_82575,
2296 .phy_ops = &e1000_phy_ops_82575,
2297 .nvm_ops = &e1000_nvm_ops_82575,
2298};
2299