blob: e07f66c6a1cf1ecc97c14d62ed390bdb727b306b [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 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
32#include <linux/types.h>
33#include <linux/slab.h>
Alexander Duyck2d064c02008-07-08 15:10:12 -070034#include <linux/if_ether.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080035
36#include "e1000_mac.h"
37#include "e1000_82575.h"
38
39static s32 igb_get_invariants_82575(struct e1000_hw *);
40static s32 igb_acquire_phy_82575(struct e1000_hw *);
41static void igb_release_phy_82575(struct e1000_hw *);
42static s32 igb_acquire_nvm_82575(struct e1000_hw *);
43static void igb_release_nvm_82575(struct e1000_hw *);
44static s32 igb_check_for_link_82575(struct e1000_hw *);
45static s32 igb_get_cfg_done_82575(struct e1000_hw *);
46static s32 igb_init_hw_82575(struct e1000_hw *);
47static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
48static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Auke Kok9d5c8242008-01-24 02:22:38 -080049static s32 igb_reset_hw_82575(struct e1000_hw *);
50static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
51static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000052static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080053static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
54static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
55static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080056static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
57 u16 *);
58static s32 igb_get_phy_id_82575(struct e1000_hw *);
59static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
60static bool igb_sgmii_active_82575(struct e1000_hw *);
61static s32 igb_reset_init_script_82575(struct e1000_hw *);
62static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000063static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080064
Auke Kok9d5c8242008-01-24 02:22:38 -080065static s32 igb_get_invariants_82575(struct e1000_hw *hw)
66{
67 struct e1000_phy_info *phy = &hw->phy;
68 struct e1000_nvm_info *nvm = &hw->nvm;
69 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +000070 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -080071 u32 eecd;
72 s32 ret_val;
73 u16 size;
74 u32 ctrl_ext = 0;
75
76 switch (hw->device_id) {
77 case E1000_DEV_ID_82575EB_COPPER:
78 case E1000_DEV_ID_82575EB_FIBER_SERDES:
79 case E1000_DEV_ID_82575GB_QUAD_COPPER:
80 mac->type = e1000_82575;
81 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -070082 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +000083 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +000084 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -070085 case E1000_DEV_ID_82576_FIBER:
86 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +000087 case E1000_DEV_ID_82576_QUAD_COPPER:
Alexander Duyck4703bf72009-07-23 18:09:48 +000088 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -070089 mac->type = e1000_82576;
90 break;
Auke Kok9d5c8242008-01-24 02:22:38 -080091 default:
92 return -E1000_ERR_MAC_INIT;
93 break;
94 }
95
Auke Kok9d5c8242008-01-24 02:22:38 -080096 /* Set media type */
97 /*
98 * The 82575 uses bits 22:23 for link mode. The mode can be changed
99 * based on the EEPROM. We cannot rely upon device ID. There
100 * is no distinguishable difference between fiber and internal
101 * SerDes mode on the 82575. There can be an external PHY attached
102 * on the SGMII interface. For this, we'll set sgmii_active to true.
103 */
104 phy->media_type = e1000_media_type_copper;
105 dev_spec->sgmii_active = false;
106
107 ctrl_ext = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000108 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
109 case E1000_CTRL_EXT_LINK_MODE_SGMII:
Auke Kok9d5c8242008-01-24 02:22:38 -0800110 dev_spec->sgmii_active = true;
111 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000112 break;
113 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
114 hw->phy.media_type = e1000_media_type_internal_serdes;
115 ctrl_ext |= E1000_CTRL_I2C_ENA;
116 break;
117 default:
Auke Kok9d5c8242008-01-24 02:22:38 -0800118 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000119 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800120 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000121
Auke Kok9d5c8242008-01-24 02:22:38 -0800122 wr32(E1000_CTRL_EXT, ctrl_ext);
123
124 /* Set mta register count */
125 mac->mta_reg_count = 128;
126 /* Set rar entry count */
127 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700128 if (mac->type == e1000_82576)
129 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Auke Kok9d5c8242008-01-24 02:22:38 -0800130 /* Set if part includes ASF firmware */
131 mac->asf_firmware_present = true;
132 /* Set if manageability features are enabled. */
133 mac->arc_subsystem_valid =
134 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
135 ? true : false;
136
137 /* physical interface link setup */
138 mac->ops.setup_physical_interface =
139 (hw->phy.media_type == e1000_media_type_copper)
140 ? igb_setup_copper_link_82575
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000141 : igb_setup_serdes_link_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800142
143 /* NVM initialization */
144 eecd = rd32(E1000_EECD);
145
146 nvm->opcode_bits = 8;
147 nvm->delay_usec = 1;
148 switch (nvm->override) {
149 case e1000_nvm_override_spi_large:
150 nvm->page_size = 32;
151 nvm->address_bits = 16;
152 break;
153 case e1000_nvm_override_spi_small:
154 nvm->page_size = 8;
155 nvm->address_bits = 8;
156 break;
157 default:
158 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
159 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
160 break;
161 }
162
163 nvm->type = e1000_nvm_eeprom_spi;
164
165 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
166 E1000_EECD_SIZE_EX_SHIFT);
167
168 /*
169 * Added to a constant, "size" becomes the left-shift value
170 * for setting word_size.
171 */
172 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700173
174 /* EEPROM access above 16k is unsupported */
175 if (size > 14)
176 size = 14;
Auke Kok9d5c8242008-01-24 02:22:38 -0800177 nvm->word_size = 1 << size;
178
Alexander Duycka0c98602009-07-23 18:10:43 +0000179 /* if 82576 then initialize mailbox parameters */
180 if (mac->type == e1000_82576)
181 igb_init_mbx_params_pf(hw);
182
Auke Kok9d5c8242008-01-24 02:22:38 -0800183 /* setup PHY parameters */
184 if (phy->media_type != e1000_media_type_copper) {
185 phy->type = e1000_phy_none;
186 return 0;
187 }
188
189 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
190 phy->reset_delay_us = 100;
191
192 /* PHY function pointers */
193 if (igb_sgmii_active_82575(hw)) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000194 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
195 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
196 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800197 } else {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000198 phy->ops.reset = igb_phy_hw_reset;
199 phy->ops.read_reg = igb_read_phy_reg_igp;
200 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800201 }
202
Alexander Duyck19e588e2009-07-07 13:01:55 +0000203 /* set lan id */
204 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
205 E1000_STATUS_FUNC_SHIFT;
206
Auke Kok9d5c8242008-01-24 02:22:38 -0800207 /* Set phy->phy_addr and phy->id. */
208 ret_val = igb_get_phy_id_82575(hw);
209 if (ret_val)
210 return ret_val;
211
212 /* Verify phy id and set remaining function pointers */
213 switch (phy->id) {
214 case M88E1111_I_PHY_ID:
215 phy->type = e1000_phy_m88;
216 phy->ops.get_phy_info = igb_get_phy_info_m88;
217 phy->ops.get_cable_length = igb_get_cable_length_m88;
218 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
219 break;
220 case IGP03E1000_E_PHY_ID:
221 phy->type = e1000_phy_igp_3;
222 phy->ops.get_phy_info = igb_get_phy_info_igp;
223 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
224 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
225 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
226 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
227 break;
228 default:
229 return -E1000_ERR_PHY;
230 }
231
232 return 0;
233}
234
235/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700236 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800237 * @hw: pointer to the HW structure
238 *
239 * Acquire access rights to the correct PHY. This is a
240 * function pointer entry point called by the api module.
241 **/
242static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
243{
Alexander Duyck008c3422009-10-05 06:32:07 +0000244 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800245
Alexander Duyck008c3422009-10-05 06:32:07 +0000246 if (hw->bus.func == E1000_FUNC_1)
247 mask = E1000_SWFW_PHY1_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800248
249 return igb_acquire_swfw_sync_82575(hw, mask);
250}
251
252/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700253 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800254 * @hw: pointer to the HW structure
255 *
256 * A wrapper to release access rights to the correct PHY. This is a
257 * function pointer entry point called by the api module.
258 **/
259static void igb_release_phy_82575(struct e1000_hw *hw)
260{
Alexander Duyck008c3422009-10-05 06:32:07 +0000261 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800262
Alexander Duyck008c3422009-10-05 06:32:07 +0000263 if (hw->bus.func == E1000_FUNC_1)
264 mask = E1000_SWFW_PHY1_SM;
265
Auke Kok9d5c8242008-01-24 02:22:38 -0800266 igb_release_swfw_sync_82575(hw, mask);
267}
268
269/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700270 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800271 * @hw: pointer to the HW structure
272 * @offset: register offset to be read
273 * @data: pointer to the read data
274 *
275 * Reads the PHY register at offset using the serial gigabit media independent
276 * interface and stores the retrieved information in data.
277 **/
278static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
279 u16 *data)
280{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000281 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800282
283 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700284 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000285 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800286 }
287
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000288 ret_val = hw->phy.ops.acquire(hw);
289 if (ret_val)
290 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800291
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000292 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800293
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000294 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800295
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000296out:
297 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800298}
299
300/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700301 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800302 * @hw: pointer to the HW structure
303 * @offset: register offset to write to
304 * @data: data to write at register offset
305 *
306 * Writes the data to PHY register at the offset using the serial gigabit
307 * media independent interface.
308 **/
309static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
310 u16 data)
311{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000312 s32 ret_val = -E1000_ERR_PARAM;
313
Auke Kok9d5c8242008-01-24 02:22:38 -0800314
315 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700316 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000317 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800318 }
319
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000320 ret_val = hw->phy.ops.acquire(hw);
321 if (ret_val)
322 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800323
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000324 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800325
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000326 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800327
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000328out:
329 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800330}
331
332/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700333 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800334 * @hw: pointer to the HW structure
335 *
Auke Kok652fff32008-06-27 11:00:18 -0700336 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800337 * sgmi interface.
338 **/
339static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
340{
341 struct e1000_phy_info *phy = &hw->phy;
342 s32 ret_val = 0;
343 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000344 u32 ctrl_ext;
Auke Kok9d5c8242008-01-24 02:22:38 -0800345
346 /*
347 * For SGMII PHYs, we try the list of possible addresses until
348 * we find one that works. For non-SGMII PHYs
349 * (e.g. integrated copper PHYs), an address of 1 should
350 * work. The result of this function should mean phy->phy_addr
351 * and phy->id are set correctly.
352 */
353 if (!(igb_sgmii_active_82575(hw))) {
354 phy->addr = 1;
355 ret_val = igb_get_phy_id(hw);
356 goto out;
357 }
358
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000359 /* Power on sgmii phy if it is disabled */
360 ctrl_ext = rd32(E1000_CTRL_EXT);
361 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
362 wrfl();
363 msleep(300);
364
Auke Kok9d5c8242008-01-24 02:22:38 -0800365 /*
366 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
367 * Therefore, we need to test 1-7
368 */
369 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
370 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
371 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700372 hw_dbg("Vendor ID 0x%08X read at address %u\n",
373 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800374 /*
375 * At the time of this writing, The M88 part is
376 * the only supported SGMII PHY product.
377 */
378 if (phy_id == M88_VENDOR)
379 break;
380 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700381 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800382 }
383 }
384
385 /* A valid PHY type couldn't be found. */
386 if (phy->addr == 8) {
387 phy->addr = 0;
388 ret_val = -E1000_ERR_PHY;
389 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000390 } else {
391 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800392 }
393
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000394 /* restore previous sfp cage power state */
395 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800396
397out:
398 return ret_val;
399}
400
401/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700402 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800403 * @hw: pointer to the HW structure
404 *
405 * Resets the PHY using the serial gigabit media independent interface.
406 **/
407static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
408{
409 s32 ret_val;
410
411 /*
412 * This isn't a true "hard" reset, but is the only reset
413 * available to us at this time.
414 */
415
Auke Kok652fff32008-06-27 11:00:18 -0700416 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800417
418 /*
419 * SFP documentation requires the following to configure the SPF module
420 * to work on SGMII. No further documentation is given.
421 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000422 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800423 if (ret_val)
424 goto out;
425
426 ret_val = igb_phy_sw_reset(hw);
427
428out:
429 return ret_val;
430}
431
432/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700433 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800434 * @hw: pointer to the HW structure
435 * @active: true to enable LPLU, false to disable
436 *
437 * Sets the LPLU D0 state according to the active flag. When
438 * activating LPLU this function also disables smart speed
439 * and vice versa. LPLU will not be activated unless the
440 * device autonegotiation advertisement meets standards of
441 * either 10 or 10/100 or 10/100/1000 at all duplexes.
442 * This is a function pointer entry point only called by
443 * PHY setup routines.
444 **/
445static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
446{
447 struct e1000_phy_info *phy = &hw->phy;
448 s32 ret_val;
449 u16 data;
450
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000451 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800452 if (ret_val)
453 goto out;
454
455 if (active) {
456 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000457 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700458 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800459 if (ret_val)
460 goto out;
461
462 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000463 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700464 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800465 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000466 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700467 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800468 if (ret_val)
469 goto out;
470 } else {
471 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000472 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700473 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800474 /*
475 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
476 * during Dx states where the power conservation is most
477 * important. During driver activity we should enable
478 * SmartSpeed, so performance is maintained.
479 */
480 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000481 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700482 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800483 if (ret_val)
484 goto out;
485
486 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000487 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700488 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800489 if (ret_val)
490 goto out;
491 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000492 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700493 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800494 if (ret_val)
495 goto out;
496
497 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000498 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700499 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800500 if (ret_val)
501 goto out;
502 }
503 }
504
505out:
506 return ret_val;
507}
508
509/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700510 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800511 * @hw: pointer to the HW structure
512 *
Auke Kok652fff32008-06-27 11:00:18 -0700513 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800514 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
515 * Return successful if access grant bit set, else clear the request for
516 * EEPROM access and return -E1000_ERR_NVM (-1).
517 **/
518static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
519{
520 s32 ret_val;
521
522 ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
523 if (ret_val)
524 goto out;
525
526 ret_val = igb_acquire_nvm(hw);
527
528 if (ret_val)
529 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
530
531out:
532 return ret_val;
533}
534
535/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700536 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800537 * @hw: pointer to the HW structure
538 *
539 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
540 * then release the semaphores acquired.
541 **/
542static void igb_release_nvm_82575(struct e1000_hw *hw)
543{
544 igb_release_nvm(hw);
545 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
546}
547
548/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700549 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800550 * @hw: pointer to the HW structure
551 * @mask: specifies which semaphore to acquire
552 *
553 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
554 * will also specify which port we're acquiring the lock for.
555 **/
556static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
557{
558 u32 swfw_sync;
559 u32 swmask = mask;
560 u32 fwmask = mask << 16;
561 s32 ret_val = 0;
562 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
563
564 while (i < timeout) {
565 if (igb_get_hw_semaphore(hw)) {
566 ret_val = -E1000_ERR_SWFW_SYNC;
567 goto out;
568 }
569
570 swfw_sync = rd32(E1000_SW_FW_SYNC);
571 if (!(swfw_sync & (fwmask | swmask)))
572 break;
573
574 /*
575 * Firmware currently using resource (fwmask)
576 * or other software thread using resource (swmask)
577 */
578 igb_put_hw_semaphore(hw);
579 mdelay(5);
580 i++;
581 }
582
583 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -0700584 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800585 ret_val = -E1000_ERR_SWFW_SYNC;
586 goto out;
587 }
588
589 swfw_sync |= swmask;
590 wr32(E1000_SW_FW_SYNC, swfw_sync);
591
592 igb_put_hw_semaphore(hw);
593
594out:
595 return ret_val;
596}
597
598/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700599 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800600 * @hw: pointer to the HW structure
601 * @mask: specifies which semaphore to acquire
602 *
603 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
604 * will also specify which port we're releasing the lock for.
605 **/
606static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
607{
608 u32 swfw_sync;
609
610 while (igb_get_hw_semaphore(hw) != 0);
611 /* Empty */
612
613 swfw_sync = rd32(E1000_SW_FW_SYNC);
614 swfw_sync &= ~mask;
615 wr32(E1000_SW_FW_SYNC, swfw_sync);
616
617 igb_put_hw_semaphore(hw);
618}
619
620/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700621 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -0800622 * @hw: pointer to the HW structure
623 *
624 * Read the management control register for the config done bit for
625 * completion status. NOTE: silicon which is EEPROM-less will fail trying
626 * to read the config done bit, so an error is *ONLY* logged and returns
627 * 0. If we were to return with error, EEPROM-less silicon
628 * would not be able to be reset or change link.
629 **/
630static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
631{
632 s32 timeout = PHY_CFG_TIMEOUT;
633 s32 ret_val = 0;
634 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
635
636 if (hw->bus.func == 1)
637 mask = E1000_NVM_CFG_DONE_PORT_1;
638
639 while (timeout) {
640 if (rd32(E1000_EEMNGCTL) & mask)
641 break;
642 msleep(1);
643 timeout--;
644 }
645 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -0700646 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800647
648 /* If EEPROM is not marked present, init the PHY manually */
649 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
650 (hw->phy.type == e1000_phy_igp_3))
651 igb_phy_init_script_igp3(hw);
652
653 return ret_val;
654}
655
656/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700657 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -0800658 * @hw: pointer to the HW structure
659 *
660 * If sgmii is enabled, then use the pcs register to determine link, otherwise
661 * use the generic interface for determining link.
662 **/
663static s32 igb_check_for_link_82575(struct e1000_hw *hw)
664{
665 s32 ret_val;
666 u16 speed, duplex;
667
Alexander Duyck70d92f82009-10-05 06:31:47 +0000668 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800669 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -0700670 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800671 /*
672 * Use this flag to determine if link needs to be checked or
673 * not. If we have link clear the flag so that we do not
674 * continue to check for link.
675 */
676 hw->mac.get_link_status = !hw->mac.serdes_has_link;
677 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800678 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800679 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800680
681 return ret_val;
682}
Alexander Duyck70d92f82009-10-05 06:31:47 +0000683
Auke Kok9d5c8242008-01-24 02:22:38 -0800684/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700685 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800686 * @hw: pointer to the HW structure
687 * @speed: stores the current speed
688 * @duplex: stores the current duplex
689 *
Auke Kok652fff32008-06-27 11:00:18 -0700690 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -0800691 * duplex, then store the values in the pointers provided.
692 **/
693static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
694 u16 *duplex)
695{
696 struct e1000_mac_info *mac = &hw->mac;
697 u32 pcs;
698
699 /* Set up defaults for the return values of this function */
700 mac->serdes_has_link = false;
701 *speed = 0;
702 *duplex = 0;
703
704 /*
705 * Read the PCS Status register for link state. For non-copper mode,
706 * the status register is not accurate. The PCS status register is
707 * used instead.
708 */
709 pcs = rd32(E1000_PCS_LSTAT);
710
711 /*
712 * The link up bit determines when link is up on autoneg. The sync ok
713 * gets set once both sides sync up and agree upon link. Stable link
714 * can be determined by checking for both link up and link sync ok
715 */
716 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
717 mac->serdes_has_link = true;
718
719 /* Detect and store PCS speed */
720 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
721 *speed = SPEED_1000;
722 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
723 *speed = SPEED_100;
724 } else {
725 *speed = SPEED_10;
726 }
727
728 /* Detect and store PCS duplex */
729 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
730 *duplex = FULL_DUPLEX;
731 } else {
732 *duplex = HALF_DUPLEX;
733 }
734 }
735
736 return 0;
737}
738
739/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000740 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -0700741 * @hw: pointer to the HW structure
742 *
743 * In the case of fiber serdes, shut down optics and PCS on driver unload
744 * when management pass thru is not enabled.
745 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000746void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -0700747{
748 u32 reg;
Alexander Duyck70d92f82009-10-05 06:31:47 +0000749 u16 eeprom_data = 0;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700750
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000751 if (hw->phy.media_type != e1000_media_type_internal_serdes ||
752 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -0700753 return;
754
Alexander Duyck70d92f82009-10-05 06:31:47 +0000755 if (hw->bus.func == E1000_FUNC_0)
756 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
757 else if (hw->bus.func == E1000_FUNC_1)
758 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
759
760 /*
761 * If APM is not enabled in the EEPROM and management interface is
762 * not enabled, then power down.
763 */
764 if (!(eeprom_data & E1000_NVM_APME_82575) &&
765 !igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -0700766 /* Disable PCS to turn off link */
767 reg = rd32(E1000_PCS_CFG0);
768 reg &= ~E1000_PCS_CFG_PCS_EN;
769 wr32(E1000_PCS_CFG0, reg);
770
771 /* shutdown the laser */
772 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000773 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700774 wr32(E1000_CTRL_EXT, reg);
775
776 /* flush the write to verify completion */
777 wrfl();
778 msleep(1);
779 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800780
781 return;
782}
783
784/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700785 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800786 * @hw: pointer to the HW structure
787 *
788 * This resets the hardware into a known state. This is a
789 * function pointer entry point called by the api module.
790 **/
791static s32 igb_reset_hw_82575(struct e1000_hw *hw)
792{
793 u32 ctrl, icr;
794 s32 ret_val;
795
796 /*
797 * Prevent the PCI-E bus from sticking if there is no TLP connection
798 * on the last TLP read/write transaction when MAC is reset.
799 */
800 ret_val = igb_disable_pcie_master(hw);
801 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700802 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800803
Alexander Duyck009bc062009-07-23 18:08:35 +0000804 /* set the completion timeout for interface */
805 ret_val = igb_set_pcie_completion_timeout(hw);
806 if (ret_val) {
807 hw_dbg("PCI-E Set completion timeout has failed.\n");
808 }
809
Auke Kok652fff32008-06-27 11:00:18 -0700810 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800811 wr32(E1000_IMC, 0xffffffff);
812
813 wr32(E1000_RCTL, 0);
814 wr32(E1000_TCTL, E1000_TCTL_PSP);
815 wrfl();
816
817 msleep(10);
818
819 ctrl = rd32(E1000_CTRL);
820
Auke Kok652fff32008-06-27 11:00:18 -0700821 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800822 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
823
824 ret_val = igb_get_auto_rd_done(hw);
825 if (ret_val) {
826 /*
827 * When auto config read does not complete, do not
828 * return with an error. This can happen in situations
829 * where there is no eeprom and prevents getting link.
830 */
Auke Kok652fff32008-06-27 11:00:18 -0700831 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800832 }
833
834 /* If EEPROM is not present, run manual init scripts */
835 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
836 igb_reset_init_script_82575(hw);
837
838 /* Clear any pending interrupt events. */
839 wr32(E1000_IMC, 0xffffffff);
840 icr = rd32(E1000_ICR);
841
Alexander Duyck5ac16652009-07-23 18:09:12 +0000842 /* Install any alternate MAC address into RAR0 */
843 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800844
845 return ret_val;
846}
847
848/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700849 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800850 * @hw: pointer to the HW structure
851 *
852 * This inits the hardware readying it for operation.
853 **/
854static s32 igb_init_hw_82575(struct e1000_hw *hw)
855{
856 struct e1000_mac_info *mac = &hw->mac;
857 s32 ret_val;
858 u16 i, rar_count = mac->rar_entry_count;
859
860 /* Initialize identification LED */
861 ret_val = igb_id_led_init(hw);
862 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700863 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800864 /* This is not fatal and we should not stop init due to this */
865 }
866
867 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -0700868 hw_dbg("Initializing the IEEE VLAN\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800869 igb_clear_vfta(hw);
870
871 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +0000872 igb_init_rx_addrs(hw, rar_count);
873
Auke Kok9d5c8242008-01-24 02:22:38 -0800874 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -0700875 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800876 for (i = 0; i < mac->mta_reg_count; i++)
877 array_wr32(E1000_MTA, i, 0);
878
Alexander Duyck68d480c2009-10-05 06:33:08 +0000879 /* Zero out the Unicast HASH table */
880 hw_dbg("Zeroing the UTA\n");
881 for (i = 0; i < mac->uta_reg_count; i++)
882 array_wr32(E1000_UTA, i, 0);
883
Auke Kok9d5c8242008-01-24 02:22:38 -0800884 /* Setup link and flow control */
885 ret_val = igb_setup_link(hw);
886
887 /*
888 * Clear all of the statistics registers (clear on read). It is
889 * important that we do this after we have tried to establish link
890 * because the symbol error count will increment wildly if there
891 * is no link.
892 */
893 igb_clear_hw_cntrs_82575(hw);
894
895 return ret_val;
896}
897
898/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700899 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800900 * @hw: pointer to the HW structure
901 *
902 * Configures the link for auto-neg or forced speed and duplex. Then we check
903 * for link, once link is established calls to configure collision distance
904 * and flow control are called.
905 **/
906static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
907{
Alexander Duyck12645a12009-07-23 18:08:16 +0000908 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -0800909 s32 ret_val;
910 bool link;
911
912 ctrl = rd32(E1000_CTRL);
913 ctrl |= E1000_CTRL_SLU;
914 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
915 wr32(E1000_CTRL, ctrl);
916
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000917 ret_val = igb_setup_serdes_link_82575(hw);
918 if (ret_val)
919 goto out;
920
921 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
922 ret_val = hw->phy.ops.reset(hw);
923 if (ret_val) {
924 hw_dbg("Error resetting the PHY.\n");
925 goto out;
926 }
927 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800928 switch (hw->phy.type) {
929 case e1000_phy_m88:
930 ret_val = igb_copper_link_setup_m88(hw);
931 break;
932 case e1000_phy_igp_3:
933 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 break;
935 default:
936 ret_val = -E1000_ERR_PHY;
937 break;
938 }
939
940 if (ret_val)
941 goto out;
942
943 if (hw->mac.autoneg) {
944 /*
945 * Setup autoneg and flow control advertisement
946 * and perform autonegotiation.
947 */
948 ret_val = igb_copper_link_autoneg(hw);
949 if (ret_val)
950 goto out;
951 } else {
952 /*
953 * PHY will be set to 10H, 10F, 100H or 100F
954 * depending on user settings.
955 */
Auke Kok652fff32008-06-27 11:00:18 -0700956 hw_dbg("Forcing Speed and Duplex\n");
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000957 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800958 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700959 hw_dbg("Error Forcing Speed and Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800960 goto out;
961 }
962 }
963
Auke Kok9d5c8242008-01-24 02:22:38 -0800964 /*
965 * Check link status. Wait up to 100 microseconds for link to become
966 * valid.
967 */
Auke Kok652fff32008-06-27 11:00:18 -0700968 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -0800969 if (ret_val)
970 goto out;
971
972 if (link) {
Auke Kok652fff32008-06-27 11:00:18 -0700973 hw_dbg("Valid link established!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800974 /* Config the MAC and PHY after link is up */
975 igb_config_collision_dist(hw);
976 ret_val = igb_config_fc_after_link_up(hw);
977 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700978 hw_dbg("Unable to establish link!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800979 }
980
981out:
982 return ret_val;
983}
984
985/**
Alexander Duyck70d92f82009-10-05 06:31:47 +0000986 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -0800987 * @hw: pointer to the HW structure
988 *
Alexander Duyck70d92f82009-10-05 06:31:47 +0000989 * Configure the physical coding sub-layer (PCS) link. The PCS link is
990 * used on copper connections where the serialized gigabit media independent
991 * interface (sgmii), or serdes fiber is being used. Configures the link
992 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -0800993 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000994static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800995{
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000996 u32 ctrl_reg, reg;
997
998 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
999 !igb_sgmii_active_82575(hw))
1000 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001001
1002 /*
1003 * On the 82575, SerDes loopback mode persists until it is
1004 * explicitly turned off or a power cycle is performed. A read to
1005 * the register does not indicate its status. Therefore, we ensure
1006 * loopback mode is disabled during initialization.
1007 */
1008 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1009
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001010 /* power on the sfp cage if present */
1011 reg = rd32(E1000_CTRL_EXT);
1012 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1013 wr32(E1000_CTRL_EXT, reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001014
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001015 ctrl_reg = rd32(E1000_CTRL);
1016 ctrl_reg |= E1000_CTRL_SLU;
1017
1018 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1019 /* set both sw defined pins */
1020 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1021
1022 /* Set switch control to serdes energy detect */
1023 reg = rd32(E1000_CONNSW);
1024 reg |= E1000_CONNSW_ENRGSRC;
1025 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001026 }
1027
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001028 reg = rd32(E1000_PCS_LCTL);
1029
1030 if (igb_sgmii_active_82575(hw)) {
1031 /* allow time for SFP cage to power up phy */
1032 msleep(300);
1033
1034 /* AN time out should be disabled for SGMII mode */
1035 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1036 } else {
1037 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1038 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
1039 }
1040
1041 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001042
1043 /*
1044 * New SerDes mode allows for forcing speed or autonegotiating speed
1045 * at 1gb. Autoneg should be default set by most drivers. This is the
1046 * mode that will be compatible with older link partners and switches.
1047 * However, both are supported by the hardware and some drivers/tools.
1048 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001049
1050 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1051 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1052
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001053 /*
1054 * We force flow control to prevent the CTRL register values from being
1055 * overwritten by the autonegotiated flow control values
1056 */
1057 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1058
1059 /*
1060 * we always set sgmii to autoneg since it is the phy that will be
1061 * forcing the link and the serdes is just a go-between
1062 */
1063 if (hw->mac.autoneg || igb_sgmii_active_82575(hw)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001064 /* Set PCS register for autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001065 reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1066 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full dplx */
1067 E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1068 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Auke Kok652fff32008-06-27 11:00:18 -07001069 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001070 } else {
Alexander Duyck70d92f82009-10-05 06:31:47 +00001071 /* Check for duplex first */
1072 if (hw->mac.forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1073 reg |= E1000_PCS_LCTL_FDV_FULL;
1074
1075 /* No need to check for 1000/full since the spec states that
1076 * it requires autoneg to be enabled */
1077 /* Now set speed */
1078 if (hw->mac.forced_speed_duplex & E1000_ALL_100_SPEED)
1079 reg |= E1000_PCS_LCTL_FSV_100;
1080
1081 /* Force speed and force link */
1082 reg |= E1000_PCS_LCTL_FSD |
1083 E1000_PCS_LCTL_FORCE_LINK |
1084 E1000_PCS_LCTL_FLV_LINK_UP;
1085
Auke Kok652fff32008-06-27 11:00:18 -07001086 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001087 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001088
Auke Kok9d5c8242008-01-24 02:22:38 -08001089 wr32(E1000_PCS_LCTL, reg);
1090
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001091 if (!igb_sgmii_active_82575(hw))
1092 igb_force_mac_fc(hw);
1093
Auke Kok9d5c8242008-01-24 02:22:38 -08001094 return 0;
1095}
1096
1097/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001098 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001099 * @hw: pointer to the HW structure
1100 *
1101 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1102 * which can be enabled for use in the embedded applications. Simply
1103 * return the current state of the sgmii interface.
1104 **/
1105static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1106{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001107 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001108 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001109}
1110
1111/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001112 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001113 * @hw: pointer to the HW structure
1114 *
1115 * Inits recommended HW defaults after a reset when there is no EEPROM
1116 * detected. This is only for the 82575.
1117 **/
1118static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1119{
1120 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001121 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001122 /* SerDes configuration via SERDESCTRL */
1123 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1124 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1125 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1126 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1127
1128 /* CCM configuration via CCMCTL register */
1129 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1130 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1131
1132 /* PCIe lanes configuration */
1133 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1134 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1135 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1136 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1137
1138 /* PCIe PLL Configuration */
1139 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1140 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1141 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1142 }
1143
1144 return 0;
1145}
1146
1147/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001148 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001149 * @hw: pointer to the HW structure
1150 **/
1151static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1152{
1153 s32 ret_val = 0;
1154
1155 if (igb_check_alt_mac_addr(hw))
1156 ret_val = igb_read_mac_addr(hw);
1157
1158 return ret_val;
1159}
1160
1161/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001162 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001163 * @hw: pointer to the HW structure
1164 *
1165 * Clears the hardware counters by reading the counter registers.
1166 **/
1167static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1168{
Auke Kok9d5c8242008-01-24 02:22:38 -08001169 igb_clear_hw_cntrs_base(hw);
1170
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001171 rd32(E1000_PRC64);
1172 rd32(E1000_PRC127);
1173 rd32(E1000_PRC255);
1174 rd32(E1000_PRC511);
1175 rd32(E1000_PRC1023);
1176 rd32(E1000_PRC1522);
1177 rd32(E1000_PTC64);
1178 rd32(E1000_PTC127);
1179 rd32(E1000_PTC255);
1180 rd32(E1000_PTC511);
1181 rd32(E1000_PTC1023);
1182 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001183
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001184 rd32(E1000_ALGNERRC);
1185 rd32(E1000_RXERRC);
1186 rd32(E1000_TNCRS);
1187 rd32(E1000_CEXTERR);
1188 rd32(E1000_TSCTC);
1189 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001190
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001191 rd32(E1000_MGTPRC);
1192 rd32(E1000_MGTPDC);
1193 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001194
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001195 rd32(E1000_IAC);
1196 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001197
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001198 rd32(E1000_ICRXPTC);
1199 rd32(E1000_ICRXATC);
1200 rd32(E1000_ICTXPTC);
1201 rd32(E1000_ICTXATC);
1202 rd32(E1000_ICTXQEC);
1203 rd32(E1000_ICTXQMTC);
1204 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001205
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001206 rd32(E1000_CBTMPC);
1207 rd32(E1000_HTDPMC);
1208 rd32(E1000_CBRMPC);
1209 rd32(E1000_RPTHC);
1210 rd32(E1000_HGPTC);
1211 rd32(E1000_HTCBDPC);
1212 rd32(E1000_HGORCL);
1213 rd32(E1000_HGORCH);
1214 rd32(E1000_HGOTCL);
1215 rd32(E1000_HGOTCH);
1216 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001217
1218 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001219 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1220 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001221 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001222}
1223
Alexander Duyck662d7202008-06-27 11:00:29 -07001224/**
1225 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1226 * @hw: pointer to the HW structure
1227 *
1228 * After rx enable if managability is enabled then there is likely some
1229 * bad data at the start of the fifo and possibly in the DMA fifo. This
1230 * function clears the fifos and flushes any packets that came in as rx was
1231 * being enabled.
1232 **/
1233void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1234{
1235 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1236 int i, ms_wait;
1237
1238 if (hw->mac.type != e1000_82575 ||
1239 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1240 return;
1241
1242 /* Disable all RX queues */
1243 for (i = 0; i < 4; i++) {
1244 rxdctl[i] = rd32(E1000_RXDCTL(i));
1245 wr32(E1000_RXDCTL(i),
1246 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1247 }
1248 /* Poll all queues to verify they have shut down */
1249 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1250 msleep(1);
1251 rx_enabled = 0;
1252 for (i = 0; i < 4; i++)
1253 rx_enabled |= rd32(E1000_RXDCTL(i));
1254 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1255 break;
1256 }
1257
1258 if (ms_wait == 10)
1259 hw_dbg("Queue disable timed out after 10ms\n");
1260
1261 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1262 * incoming packets are rejected. Set enable and wait 2ms so that
1263 * any packet that was coming in as RCTL.EN was set is flushed
1264 */
1265 rfctl = rd32(E1000_RFCTL);
1266 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1267
1268 rlpml = rd32(E1000_RLPML);
1269 wr32(E1000_RLPML, 0);
1270
1271 rctl = rd32(E1000_RCTL);
1272 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1273 temp_rctl |= E1000_RCTL_LPE;
1274
1275 wr32(E1000_RCTL, temp_rctl);
1276 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1277 wrfl();
1278 msleep(2);
1279
1280 /* Enable RX queues that were previously enabled and restore our
1281 * previous state
1282 */
1283 for (i = 0; i < 4; i++)
1284 wr32(E1000_RXDCTL(i), rxdctl[i]);
1285 wr32(E1000_RCTL, rctl);
1286 wrfl();
1287
1288 wr32(E1000_RLPML, rlpml);
1289 wr32(E1000_RFCTL, rfctl);
1290
1291 /* Flush receive errors generated by workaround */
1292 rd32(E1000_ROC);
1293 rd32(E1000_RNBC);
1294 rd32(E1000_MPC);
1295}
1296
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001297/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001298 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1299 * @hw: pointer to the HW structure
1300 *
1301 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1302 * however the hardware default for these parts is 500us to 1ms which is less
1303 * than the 10ms recommended by the pci-e spec. To address this we need to
1304 * increase the value to either 10ms to 200ms for capability version 1 config,
1305 * or 16ms to 55ms for version 2.
1306 **/
1307static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1308{
1309 u32 gcr = rd32(E1000_GCR);
1310 s32 ret_val = 0;
1311 u16 pcie_devctl2;
1312
1313 /* only take action if timeout value is defaulted to 0 */
1314 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1315 goto out;
1316
1317 /*
1318 * if capababilities version is type 1 we can write the
1319 * timeout of 10ms to 200ms through the GCR register
1320 */
1321 if (!(gcr & E1000_GCR_CAP_VER2)) {
1322 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1323 goto out;
1324 }
1325
1326 /*
1327 * for version 2 capabilities we need to write the config space
1328 * directly in order to set the completion timeout value for
1329 * 16ms to 55ms
1330 */
1331 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1332 &pcie_devctl2);
1333 if (ret_val)
1334 goto out;
1335
1336 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1337
1338 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1339 &pcie_devctl2);
1340out:
1341 /* disable completion timeout resend */
1342 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1343
1344 wr32(E1000_GCR, gcr);
1345 return ret_val;
1346}
1347
1348/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001349 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1350 * @hw: pointer to the hardware struct
1351 * @enable: state to enter, either enabled or disabled
1352 *
1353 * enables/disables L2 switch loopback functionality.
1354 **/
1355void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1356{
1357 u32 dtxswc = rd32(E1000_DTXSWC);
1358
1359 if (enable)
1360 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1361 else
1362 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1363
1364 wr32(E1000_DTXSWC, dtxswc);
1365}
1366
1367/**
1368 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1369 * @hw: pointer to the hardware struct
1370 * @enable: state to enter, either enabled or disabled
1371 *
1372 * enables/disables replication of packets across multiple pools.
1373 **/
1374void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1375{
1376 u32 vt_ctl = rd32(E1000_VT_CTL);
1377
1378 if (enable)
1379 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1380 else
1381 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1382
1383 wr32(E1000_VT_CTL, vt_ctl);
1384}
1385
Auke Kok9d5c8242008-01-24 02:22:38 -08001386static struct e1000_mac_operations e1000_mac_ops_82575 = {
1387 .reset_hw = igb_reset_hw_82575,
1388 .init_hw = igb_init_hw_82575,
1389 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001390 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08001391 .read_mac_addr = igb_read_mac_addr_82575,
1392 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1393};
1394
1395static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001396 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001397 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001398 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001399};
1400
1401static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001402 .acquire = igb_acquire_nvm_82575,
1403 .read = igb_read_nvm_eerd,
1404 .release = igb_release_nvm_82575,
1405 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08001406};
1407
1408const struct e1000_info e1000_82575_info = {
1409 .get_invariants = igb_get_invariants_82575,
1410 .mac_ops = &e1000_mac_ops_82575,
1411 .phy_ops = &e1000_phy_ops_82575,
1412 .nvm_ops = &e1000_nvm_ops_82575,
1413};
1414