blob: 5d345e3036a42d65674cb2173c692c15183a1bcb [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;
Auke Kok9d5c8242008-01-24 02:22:38 -0800910
911 ctrl = rd32(E1000_CTRL);
912 ctrl |= E1000_CTRL_SLU;
913 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
914 wr32(E1000_CTRL, ctrl);
915
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000916 ret_val = igb_setup_serdes_link_82575(hw);
917 if (ret_val)
918 goto out;
919
920 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
921 ret_val = hw->phy.ops.reset(hw);
922 if (ret_val) {
923 hw_dbg("Error resetting the PHY.\n");
924 goto out;
925 }
926 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800927 switch (hw->phy.type) {
928 case e1000_phy_m88:
929 ret_val = igb_copper_link_setup_m88(hw);
930 break;
931 case e1000_phy_igp_3:
932 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800933 break;
934 default:
935 ret_val = -E1000_ERR_PHY;
936 break;
937 }
938
939 if (ret_val)
940 goto out;
941
Alexander Duyck81fadd82009-10-05 06:35:03 +0000942 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800943out:
944 return ret_val;
945}
946
947/**
Alexander Duyck70d92f82009-10-05 06:31:47 +0000948 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -0800949 * @hw: pointer to the HW structure
950 *
Alexander Duyck70d92f82009-10-05 06:31:47 +0000951 * Configure the physical coding sub-layer (PCS) link. The PCS link is
952 * used on copper connections where the serialized gigabit media independent
953 * interface (sgmii), or serdes fiber is being used. Configures the link
954 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000956static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800957{
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000958 u32 ctrl_reg, reg;
959
960 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
961 !igb_sgmii_active_82575(hw))
962 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800963
964 /*
965 * On the 82575, SerDes loopback mode persists until it is
966 * explicitly turned off or a power cycle is performed. A read to
967 * the register does not indicate its status. Therefore, we ensure
968 * loopback mode is disabled during initialization.
969 */
970 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
971
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000972 /* power on the sfp cage if present */
973 reg = rd32(E1000_CTRL_EXT);
974 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
975 wr32(E1000_CTRL_EXT, reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800976
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000977 ctrl_reg = rd32(E1000_CTRL);
978 ctrl_reg |= E1000_CTRL_SLU;
979
980 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
981 /* set both sw defined pins */
982 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
983
984 /* Set switch control to serdes energy detect */
985 reg = rd32(E1000_CONNSW);
986 reg |= E1000_CONNSW_ENRGSRC;
987 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -0800988 }
989
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000990 reg = rd32(E1000_PCS_LCTL);
991
992 if (igb_sgmii_active_82575(hw)) {
993 /* allow time for SFP cage to power up phy */
994 msleep(300);
995
996 /* AN time out should be disabled for SGMII mode */
997 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
998 } else {
999 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1000 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
1001 }
1002
1003 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001004
1005 /*
1006 * New SerDes mode allows for forcing speed or autonegotiating speed
1007 * at 1gb. Autoneg should be default set by most drivers. This is the
1008 * mode that will be compatible with older link partners and switches.
1009 * However, both are supported by the hardware and some drivers/tools.
1010 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001011
1012 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1013 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1014
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001015 /*
1016 * We force flow control to prevent the CTRL register values from being
1017 * overwritten by the autonegotiated flow control values
1018 */
1019 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1020
1021 /*
1022 * we always set sgmii to autoneg since it is the phy that will be
1023 * forcing the link and the serdes is just a go-between
1024 */
1025 if (hw->mac.autoneg || igb_sgmii_active_82575(hw)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001026 /* Set PCS register for autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001027 reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1028 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full dplx */
1029 E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1030 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Auke Kok652fff32008-06-27 11:00:18 -07001031 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001032 } else {
Alexander Duyck70d92f82009-10-05 06:31:47 +00001033 /* Check for duplex first */
1034 if (hw->mac.forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1035 reg |= E1000_PCS_LCTL_FDV_FULL;
1036
1037 /* No need to check for 1000/full since the spec states that
1038 * it requires autoneg to be enabled */
1039 /* Now set speed */
1040 if (hw->mac.forced_speed_duplex & E1000_ALL_100_SPEED)
1041 reg |= E1000_PCS_LCTL_FSV_100;
1042
1043 /* Force speed and force link */
1044 reg |= E1000_PCS_LCTL_FSD |
1045 E1000_PCS_LCTL_FORCE_LINK |
1046 E1000_PCS_LCTL_FLV_LINK_UP;
1047
Auke Kok652fff32008-06-27 11:00:18 -07001048 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001049 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001050
Auke Kok9d5c8242008-01-24 02:22:38 -08001051 wr32(E1000_PCS_LCTL, reg);
1052
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001053 if (!igb_sgmii_active_82575(hw))
1054 igb_force_mac_fc(hw);
1055
Auke Kok9d5c8242008-01-24 02:22:38 -08001056 return 0;
1057}
1058
1059/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001060 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001061 * @hw: pointer to the HW structure
1062 *
1063 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1064 * which can be enabled for use in the embedded applications. Simply
1065 * return the current state of the sgmii interface.
1066 **/
1067static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1068{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001069 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001070 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001071}
1072
1073/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001074 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001075 * @hw: pointer to the HW structure
1076 *
1077 * Inits recommended HW defaults after a reset when there is no EEPROM
1078 * detected. This is only for the 82575.
1079 **/
1080static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1081{
1082 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001083 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001084 /* SerDes configuration via SERDESCTRL */
1085 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1086 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1087 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1088 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1089
1090 /* CCM configuration via CCMCTL register */
1091 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1092 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1093
1094 /* PCIe lanes configuration */
1095 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1096 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1097 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1098 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1099
1100 /* PCIe PLL Configuration */
1101 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1102 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1103 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1104 }
1105
1106 return 0;
1107}
1108
1109/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001110 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001111 * @hw: pointer to the HW structure
1112 **/
1113static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1114{
1115 s32 ret_val = 0;
1116
Alexander Duyck22896632009-10-05 06:34:25 +00001117 /*
1118 * If there's an alternate MAC address place it in RAR0
1119 * so that it will override the Si installed default perm
1120 * address.
1121 */
1122 ret_val = igb_check_alt_mac_addr(hw);
1123 if (ret_val)
1124 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001125
Alexander Duyck22896632009-10-05 06:34:25 +00001126 ret_val = igb_read_mac_addr(hw);
1127
1128out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001129 return ret_val;
1130}
1131
1132/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001133 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001134 * @hw: pointer to the HW structure
1135 *
1136 * Clears the hardware counters by reading the counter registers.
1137 **/
1138static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1139{
Auke Kok9d5c8242008-01-24 02:22:38 -08001140 igb_clear_hw_cntrs_base(hw);
1141
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001142 rd32(E1000_PRC64);
1143 rd32(E1000_PRC127);
1144 rd32(E1000_PRC255);
1145 rd32(E1000_PRC511);
1146 rd32(E1000_PRC1023);
1147 rd32(E1000_PRC1522);
1148 rd32(E1000_PTC64);
1149 rd32(E1000_PTC127);
1150 rd32(E1000_PTC255);
1151 rd32(E1000_PTC511);
1152 rd32(E1000_PTC1023);
1153 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001154
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001155 rd32(E1000_ALGNERRC);
1156 rd32(E1000_RXERRC);
1157 rd32(E1000_TNCRS);
1158 rd32(E1000_CEXTERR);
1159 rd32(E1000_TSCTC);
1160 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001161
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001162 rd32(E1000_MGTPRC);
1163 rd32(E1000_MGTPDC);
1164 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001165
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001166 rd32(E1000_IAC);
1167 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001168
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001169 rd32(E1000_ICRXPTC);
1170 rd32(E1000_ICRXATC);
1171 rd32(E1000_ICTXPTC);
1172 rd32(E1000_ICTXATC);
1173 rd32(E1000_ICTXQEC);
1174 rd32(E1000_ICTXQMTC);
1175 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001176
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001177 rd32(E1000_CBTMPC);
1178 rd32(E1000_HTDPMC);
1179 rd32(E1000_CBRMPC);
1180 rd32(E1000_RPTHC);
1181 rd32(E1000_HGPTC);
1182 rd32(E1000_HTCBDPC);
1183 rd32(E1000_HGORCL);
1184 rd32(E1000_HGORCH);
1185 rd32(E1000_HGOTCL);
1186 rd32(E1000_HGOTCH);
1187 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001188
1189 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001190 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1191 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001192 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001193}
1194
Alexander Duyck662d7202008-06-27 11:00:29 -07001195/**
1196 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1197 * @hw: pointer to the HW structure
1198 *
1199 * After rx enable if managability is enabled then there is likely some
1200 * bad data at the start of the fifo and possibly in the DMA fifo. This
1201 * function clears the fifos and flushes any packets that came in as rx was
1202 * being enabled.
1203 **/
1204void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1205{
1206 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1207 int i, ms_wait;
1208
1209 if (hw->mac.type != e1000_82575 ||
1210 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1211 return;
1212
1213 /* Disable all RX queues */
1214 for (i = 0; i < 4; i++) {
1215 rxdctl[i] = rd32(E1000_RXDCTL(i));
1216 wr32(E1000_RXDCTL(i),
1217 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1218 }
1219 /* Poll all queues to verify they have shut down */
1220 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1221 msleep(1);
1222 rx_enabled = 0;
1223 for (i = 0; i < 4; i++)
1224 rx_enabled |= rd32(E1000_RXDCTL(i));
1225 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1226 break;
1227 }
1228
1229 if (ms_wait == 10)
1230 hw_dbg("Queue disable timed out after 10ms\n");
1231
1232 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1233 * incoming packets are rejected. Set enable and wait 2ms so that
1234 * any packet that was coming in as RCTL.EN was set is flushed
1235 */
1236 rfctl = rd32(E1000_RFCTL);
1237 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1238
1239 rlpml = rd32(E1000_RLPML);
1240 wr32(E1000_RLPML, 0);
1241
1242 rctl = rd32(E1000_RCTL);
1243 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1244 temp_rctl |= E1000_RCTL_LPE;
1245
1246 wr32(E1000_RCTL, temp_rctl);
1247 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1248 wrfl();
1249 msleep(2);
1250
1251 /* Enable RX queues that were previously enabled and restore our
1252 * previous state
1253 */
1254 for (i = 0; i < 4; i++)
1255 wr32(E1000_RXDCTL(i), rxdctl[i]);
1256 wr32(E1000_RCTL, rctl);
1257 wrfl();
1258
1259 wr32(E1000_RLPML, rlpml);
1260 wr32(E1000_RFCTL, rfctl);
1261
1262 /* Flush receive errors generated by workaround */
1263 rd32(E1000_ROC);
1264 rd32(E1000_RNBC);
1265 rd32(E1000_MPC);
1266}
1267
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001268/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001269 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1270 * @hw: pointer to the HW structure
1271 *
1272 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1273 * however the hardware default for these parts is 500us to 1ms which is less
1274 * than the 10ms recommended by the pci-e spec. To address this we need to
1275 * increase the value to either 10ms to 200ms for capability version 1 config,
1276 * or 16ms to 55ms for version 2.
1277 **/
1278static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1279{
1280 u32 gcr = rd32(E1000_GCR);
1281 s32 ret_val = 0;
1282 u16 pcie_devctl2;
1283
1284 /* only take action if timeout value is defaulted to 0 */
1285 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1286 goto out;
1287
1288 /*
1289 * if capababilities version is type 1 we can write the
1290 * timeout of 10ms to 200ms through the GCR register
1291 */
1292 if (!(gcr & E1000_GCR_CAP_VER2)) {
1293 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1294 goto out;
1295 }
1296
1297 /*
1298 * for version 2 capabilities we need to write the config space
1299 * directly in order to set the completion timeout value for
1300 * 16ms to 55ms
1301 */
1302 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1303 &pcie_devctl2);
1304 if (ret_val)
1305 goto out;
1306
1307 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1308
1309 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1310 &pcie_devctl2);
1311out:
1312 /* disable completion timeout resend */
1313 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1314
1315 wr32(E1000_GCR, gcr);
1316 return ret_val;
1317}
1318
1319/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001320 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1321 * @hw: pointer to the hardware struct
1322 * @enable: state to enter, either enabled or disabled
1323 *
1324 * enables/disables L2 switch loopback functionality.
1325 **/
1326void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1327{
1328 u32 dtxswc = rd32(E1000_DTXSWC);
1329
1330 if (enable)
1331 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1332 else
1333 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1334
1335 wr32(E1000_DTXSWC, dtxswc);
1336}
1337
1338/**
1339 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1340 * @hw: pointer to the hardware struct
1341 * @enable: state to enter, either enabled or disabled
1342 *
1343 * enables/disables replication of packets across multiple pools.
1344 **/
1345void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1346{
1347 u32 vt_ctl = rd32(E1000_VT_CTL);
1348
1349 if (enable)
1350 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1351 else
1352 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1353
1354 wr32(E1000_VT_CTL, vt_ctl);
1355}
1356
Auke Kok9d5c8242008-01-24 02:22:38 -08001357static struct e1000_mac_operations e1000_mac_ops_82575 = {
1358 .reset_hw = igb_reset_hw_82575,
1359 .init_hw = igb_init_hw_82575,
1360 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001361 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08001362 .read_mac_addr = igb_read_mac_addr_82575,
1363 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1364};
1365
1366static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001367 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001368 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001369 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001370};
1371
1372static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001373 .acquire = igb_acquire_nvm_82575,
1374 .read = igb_read_nvm_eerd,
1375 .release = igb_release_nvm_82575,
1376 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08001377};
1378
1379const struct e1000_info e1000_82575_info = {
1380 .get_invariants = igb_get_invariants_82575,
1381 .mac_ops = &e1000_mac_ops_82575,
1382 .phy_ops = &e1000_phy_ops_82575,
1383 .nvm_ops = &e1000_nvm_ops_82575,
1384};
1385