blob: 606c25c56a01e1cc7bc1305d33fd1f3c5096cd0c [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 *);
52static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *);
53static 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);
Alexander Duyckf3e78412009-07-23 18:07:58 +000056static void igb_configure_pcs_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080057static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
58 u16 *);
59static s32 igb_get_phy_id_82575(struct e1000_hw *);
60static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
61static bool igb_sgmii_active_82575(struct e1000_hw *);
62static s32 igb_reset_init_script_82575(struct e1000_hw *);
63static s32 igb_read_mac_addr_82575(struct e1000_hw *);
64
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 Duyck2d064c02008-07-08 15:10:12 -070084 case E1000_DEV_ID_82576_FIBER:
85 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +000086 case E1000_DEV_ID_82576_QUAD_COPPER:
Alexander Duyck2d064c02008-07-08 15:10:12 -070087 mac->type = e1000_82576;
88 break;
Auke Kok9d5c8242008-01-24 02:22:38 -080089 default:
90 return -E1000_ERR_MAC_INIT;
91 break;
92 }
93
Auke Kok9d5c8242008-01-24 02:22:38 -080094 /* Set media type */
95 /*
96 * The 82575 uses bits 22:23 for link mode. The mode can be changed
97 * based on the EEPROM. We cannot rely upon device ID. There
98 * is no distinguishable difference between fiber and internal
99 * SerDes mode on the 82575. There can be an external PHY attached
100 * on the SGMII interface. For this, we'll set sgmii_active to true.
101 */
102 phy->media_type = e1000_media_type_copper;
103 dev_spec->sgmii_active = false;
104
105 ctrl_ext = rd32(E1000_CTRL_EXT);
106 if ((ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) ==
107 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES) {
108 hw->phy.media_type = e1000_media_type_internal_serdes;
109 ctrl_ext |= E1000_CTRL_I2C_ENA;
110 } else if (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII) {
111 dev_spec->sgmii_active = true;
112 ctrl_ext |= E1000_CTRL_I2C_ENA;
113 } else {
114 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
115 }
116 wr32(E1000_CTRL_EXT, ctrl_ext);
117
118 /* Set mta register count */
119 mac->mta_reg_count = 128;
120 /* Set rar entry count */
121 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700122 if (mac->type == e1000_82576)
123 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Auke Kok9d5c8242008-01-24 02:22:38 -0800124 /* Set if part includes ASF firmware */
125 mac->asf_firmware_present = true;
126 /* Set if manageability features are enabled. */
127 mac->arc_subsystem_valid =
128 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
129 ? true : false;
130
131 /* physical interface link setup */
132 mac->ops.setup_physical_interface =
133 (hw->phy.media_type == e1000_media_type_copper)
134 ? igb_setup_copper_link_82575
135 : igb_setup_fiber_serdes_link_82575;
136
137 /* NVM initialization */
138 eecd = rd32(E1000_EECD);
139
140 nvm->opcode_bits = 8;
141 nvm->delay_usec = 1;
142 switch (nvm->override) {
143 case e1000_nvm_override_spi_large:
144 nvm->page_size = 32;
145 nvm->address_bits = 16;
146 break;
147 case e1000_nvm_override_spi_small:
148 nvm->page_size = 8;
149 nvm->address_bits = 8;
150 break;
151 default:
152 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
153 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
154 break;
155 }
156
157 nvm->type = e1000_nvm_eeprom_spi;
158
159 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
160 E1000_EECD_SIZE_EX_SHIFT);
161
162 /*
163 * Added to a constant, "size" becomes the left-shift value
164 * for setting word_size.
165 */
166 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700167
168 /* EEPROM access above 16k is unsupported */
169 if (size > 14)
170 size = 14;
Auke Kok9d5c8242008-01-24 02:22:38 -0800171 nvm->word_size = 1 << size;
172
173 /* setup PHY parameters */
174 if (phy->media_type != e1000_media_type_copper) {
175 phy->type = e1000_phy_none;
176 return 0;
177 }
178
179 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
180 phy->reset_delay_us = 100;
181
182 /* PHY function pointers */
183 if (igb_sgmii_active_82575(hw)) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000184 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
185 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
186 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800187 } else {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000188 phy->ops.reset = igb_phy_hw_reset;
189 phy->ops.read_reg = igb_read_phy_reg_igp;
190 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800191 }
192
Alexander Duyck19e588e2009-07-07 13:01:55 +0000193 /* set lan id */
194 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
195 E1000_STATUS_FUNC_SHIFT;
196
Auke Kok9d5c8242008-01-24 02:22:38 -0800197 /* Set phy->phy_addr and phy->id. */
198 ret_val = igb_get_phy_id_82575(hw);
199 if (ret_val)
200 return ret_val;
201
202 /* Verify phy id and set remaining function pointers */
203 switch (phy->id) {
204 case M88E1111_I_PHY_ID:
205 phy->type = e1000_phy_m88;
206 phy->ops.get_phy_info = igb_get_phy_info_m88;
207 phy->ops.get_cable_length = igb_get_cable_length_m88;
208 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
209 break;
210 case IGP03E1000_E_PHY_ID:
211 phy->type = e1000_phy_igp_3;
212 phy->ops.get_phy_info = igb_get_phy_info_igp;
213 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
214 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
215 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
216 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
217 break;
218 default:
219 return -E1000_ERR_PHY;
220 }
221
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800222 /* if 82576 then initialize mailbox parameters */
223 if (mac->type == e1000_82576)
224 igb_init_mbx_params_pf(hw);
225
Auke Kok9d5c8242008-01-24 02:22:38 -0800226 return 0;
227}
228
229/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700230 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800231 * @hw: pointer to the HW structure
232 *
233 * Acquire access rights to the correct PHY. This is a
234 * function pointer entry point called by the api module.
235 **/
236static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
237{
238 u16 mask;
239
240 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
241
242 return igb_acquire_swfw_sync_82575(hw, mask);
243}
244
245/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700246 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800247 * @hw: pointer to the HW structure
248 *
249 * A wrapper to release access rights to the correct PHY. This is a
250 * function pointer entry point called by the api module.
251 **/
252static void igb_release_phy_82575(struct e1000_hw *hw)
253{
254 u16 mask;
255
256 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
257 igb_release_swfw_sync_82575(hw, mask);
258}
259
260/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700261 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800262 * @hw: pointer to the HW structure
263 * @offset: register offset to be read
264 * @data: pointer to the read data
265 *
266 * Reads the PHY register at offset using the serial gigabit media independent
267 * interface and stores the retrieved information in data.
268 **/
269static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
270 u16 *data)
271{
272 struct e1000_phy_info *phy = &hw->phy;
273 u32 i, i2ccmd = 0;
274
275 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700276 hw_dbg("PHY Address %u is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800277 return -E1000_ERR_PARAM;
278 }
279
280 /*
281 * Set up Op-code, Phy Address, and register address in the I2CCMD
282 * register. The MAC will take care of interfacing with the
283 * PHY to retrieve the desired data.
284 */
285 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
286 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
287 (E1000_I2CCMD_OPCODE_READ));
288
289 wr32(E1000_I2CCMD, i2ccmd);
290
291 /* Poll the ready bit to see if the I2C read completed */
292 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
293 udelay(50);
294 i2ccmd = rd32(E1000_I2CCMD);
295 if (i2ccmd & E1000_I2CCMD_READY)
296 break;
297 }
298 if (!(i2ccmd & E1000_I2CCMD_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700299 hw_dbg("I2CCMD Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800300 return -E1000_ERR_PHY;
301 }
302 if (i2ccmd & E1000_I2CCMD_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700303 hw_dbg("I2CCMD Error bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800304 return -E1000_ERR_PHY;
305 }
306
307 /* Need to byte-swap the 16-bit value. */
308 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
309
310 return 0;
311}
312
313/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700314 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800315 * @hw: pointer to the HW structure
316 * @offset: register offset to write to
317 * @data: data to write at register offset
318 *
319 * Writes the data to PHY register at the offset using the serial gigabit
320 * media independent interface.
321 **/
322static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
323 u16 data)
324{
325 struct e1000_phy_info *phy = &hw->phy;
326 u32 i, i2ccmd = 0;
327 u16 phy_data_swapped;
328
329 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700330 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800331 return -E1000_ERR_PARAM;
332 }
333
334 /* Swap the data bytes for the I2C interface */
335 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
336
337 /*
338 * Set up Op-code, Phy Address, and register address in the I2CCMD
339 * register. The MAC will take care of interfacing with the
340 * PHY to retrieve the desired data.
341 */
342 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
343 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
344 E1000_I2CCMD_OPCODE_WRITE |
345 phy_data_swapped);
346
347 wr32(E1000_I2CCMD, i2ccmd);
348
349 /* Poll the ready bit to see if the I2C read completed */
350 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
351 udelay(50);
352 i2ccmd = rd32(E1000_I2CCMD);
353 if (i2ccmd & E1000_I2CCMD_READY)
354 break;
355 }
356 if (!(i2ccmd & E1000_I2CCMD_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700357 hw_dbg("I2CCMD Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800358 return -E1000_ERR_PHY;
359 }
360 if (i2ccmd & E1000_I2CCMD_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700361 hw_dbg("I2CCMD Error bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800362 return -E1000_ERR_PHY;
363 }
364
365 return 0;
366}
367
368/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700369 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800370 * @hw: pointer to the HW structure
371 *
Auke Kok652fff32008-06-27 11:00:18 -0700372 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800373 * sgmi interface.
374 **/
375static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
376{
377 struct e1000_phy_info *phy = &hw->phy;
378 s32 ret_val = 0;
379 u16 phy_id;
380
381 /*
382 * For SGMII PHYs, we try the list of possible addresses until
383 * we find one that works. For non-SGMII PHYs
384 * (e.g. integrated copper PHYs), an address of 1 should
385 * work. The result of this function should mean phy->phy_addr
386 * and phy->id are set correctly.
387 */
388 if (!(igb_sgmii_active_82575(hw))) {
389 phy->addr = 1;
390 ret_val = igb_get_phy_id(hw);
391 goto out;
392 }
393
394 /*
395 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
396 * Therefore, we need to test 1-7
397 */
398 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
399 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
400 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700401 hw_dbg("Vendor ID 0x%08X read at address %u\n",
402 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800403 /*
404 * At the time of this writing, The M88 part is
405 * the only supported SGMII PHY product.
406 */
407 if (phy_id == M88_VENDOR)
408 break;
409 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700410 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800411 }
412 }
413
414 /* A valid PHY type couldn't be found. */
415 if (phy->addr == 8) {
416 phy->addr = 0;
417 ret_val = -E1000_ERR_PHY;
418 goto out;
419 }
420
421 ret_val = igb_get_phy_id(hw);
422
423out:
424 return ret_val;
425}
426
427/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700428 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800429 * @hw: pointer to the HW structure
430 *
431 * Resets the PHY using the serial gigabit media independent interface.
432 **/
433static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
434{
435 s32 ret_val;
436
437 /*
438 * This isn't a true "hard" reset, but is the only reset
439 * available to us at this time.
440 */
441
Auke Kok652fff32008-06-27 11:00:18 -0700442 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800443
444 /*
445 * SFP documentation requires the following to configure the SPF module
446 * to work on SGMII. No further documentation is given.
447 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000448 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800449 if (ret_val)
450 goto out;
451
452 ret_val = igb_phy_sw_reset(hw);
453
454out:
455 return ret_val;
456}
457
458/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700459 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800460 * @hw: pointer to the HW structure
461 * @active: true to enable LPLU, false to disable
462 *
463 * Sets the LPLU D0 state according to the active flag. When
464 * activating LPLU this function also disables smart speed
465 * and vice versa. LPLU will not be activated unless the
466 * device autonegotiation advertisement meets standards of
467 * either 10 or 10/100 or 10/100/1000 at all duplexes.
468 * This is a function pointer entry point only called by
469 * PHY setup routines.
470 **/
471static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
472{
473 struct e1000_phy_info *phy = &hw->phy;
474 s32 ret_val;
475 u16 data;
476
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000477 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800478 if (ret_val)
479 goto out;
480
481 if (active) {
482 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000483 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700484 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800485 if (ret_val)
486 goto out;
487
488 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000489 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700490 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800491 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000492 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700493 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800494 if (ret_val)
495 goto out;
496 } else {
497 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000498 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700499 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800500 /*
501 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
502 * during Dx states where the power conservation is most
503 * important. During driver activity we should enable
504 * SmartSpeed, so performance is maintained.
505 */
506 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000507 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700508 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800509 if (ret_val)
510 goto out;
511
512 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000513 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700514 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800515 if (ret_val)
516 goto out;
517 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000518 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700519 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800520 if (ret_val)
521 goto out;
522
523 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000524 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700525 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 if (ret_val)
527 goto out;
528 }
529 }
530
531out:
532 return ret_val;
533}
534
535/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700536 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800537 * @hw: pointer to the HW structure
538 *
Auke Kok652fff32008-06-27 11:00:18 -0700539 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800540 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
541 * Return successful if access grant bit set, else clear the request for
542 * EEPROM access and return -E1000_ERR_NVM (-1).
543 **/
544static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
545{
546 s32 ret_val;
547
548 ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
549 if (ret_val)
550 goto out;
551
552 ret_val = igb_acquire_nvm(hw);
553
554 if (ret_val)
555 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
556
557out:
558 return ret_val;
559}
560
561/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700562 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800563 * @hw: pointer to the HW structure
564 *
565 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
566 * then release the semaphores acquired.
567 **/
568static void igb_release_nvm_82575(struct e1000_hw *hw)
569{
570 igb_release_nvm(hw);
571 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
572}
573
574/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700575 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800576 * @hw: pointer to the HW structure
577 * @mask: specifies which semaphore to acquire
578 *
579 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
580 * will also specify which port we're acquiring the lock for.
581 **/
582static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
583{
584 u32 swfw_sync;
585 u32 swmask = mask;
586 u32 fwmask = mask << 16;
587 s32 ret_val = 0;
588 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
589
590 while (i < timeout) {
591 if (igb_get_hw_semaphore(hw)) {
592 ret_val = -E1000_ERR_SWFW_SYNC;
593 goto out;
594 }
595
596 swfw_sync = rd32(E1000_SW_FW_SYNC);
597 if (!(swfw_sync & (fwmask | swmask)))
598 break;
599
600 /*
601 * Firmware currently using resource (fwmask)
602 * or other software thread using resource (swmask)
603 */
604 igb_put_hw_semaphore(hw);
605 mdelay(5);
606 i++;
607 }
608
609 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -0700610 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800611 ret_val = -E1000_ERR_SWFW_SYNC;
612 goto out;
613 }
614
615 swfw_sync |= swmask;
616 wr32(E1000_SW_FW_SYNC, swfw_sync);
617
618 igb_put_hw_semaphore(hw);
619
620out:
621 return ret_val;
622}
623
624/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700625 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800626 * @hw: pointer to the HW structure
627 * @mask: specifies which semaphore to acquire
628 *
629 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
630 * will also specify which port we're releasing the lock for.
631 **/
632static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
633{
634 u32 swfw_sync;
635
636 while (igb_get_hw_semaphore(hw) != 0);
637 /* Empty */
638
639 swfw_sync = rd32(E1000_SW_FW_SYNC);
640 swfw_sync &= ~mask;
641 wr32(E1000_SW_FW_SYNC, swfw_sync);
642
643 igb_put_hw_semaphore(hw);
644}
645
646/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700647 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -0800648 * @hw: pointer to the HW structure
649 *
650 * Read the management control register for the config done bit for
651 * completion status. NOTE: silicon which is EEPROM-less will fail trying
652 * to read the config done bit, so an error is *ONLY* logged and returns
653 * 0. If we were to return with error, EEPROM-less silicon
654 * would not be able to be reset or change link.
655 **/
656static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
657{
658 s32 timeout = PHY_CFG_TIMEOUT;
659 s32 ret_val = 0;
660 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
661
662 if (hw->bus.func == 1)
663 mask = E1000_NVM_CFG_DONE_PORT_1;
664
665 while (timeout) {
666 if (rd32(E1000_EEMNGCTL) & mask)
667 break;
668 msleep(1);
669 timeout--;
670 }
671 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -0700672 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800673
674 /* If EEPROM is not marked present, init the PHY manually */
675 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
676 (hw->phy.type == e1000_phy_igp_3))
677 igb_phy_init_script_igp3(hw);
678
679 return ret_val;
680}
681
682/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700683 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -0800684 * @hw: pointer to the HW structure
685 *
686 * If sgmii is enabled, then use the pcs register to determine link, otherwise
687 * use the generic interface for determining link.
688 **/
689static s32 igb_check_for_link_82575(struct e1000_hw *hw)
690{
691 s32 ret_val;
692 u16 speed, duplex;
693
694 /* SGMII link check is done through the PCS register. */
695 if ((hw->phy.media_type != e1000_media_type_copper) ||
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800696 (igb_sgmii_active_82575(hw))) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800697 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -0700698 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800699 /*
700 * Use this flag to determine if link needs to be checked or
701 * not. If we have link clear the flag so that we do not
702 * continue to check for link.
703 */
704 hw->mac.get_link_status = !hw->mac.serdes_has_link;
705 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800706 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800707 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800708
709 return ret_val;
710}
Auke Kok9d5c8242008-01-24 02:22:38 -0800711/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700712 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800713 * @hw: pointer to the HW structure
714 * @speed: stores the current speed
715 * @duplex: stores the current duplex
716 *
Auke Kok652fff32008-06-27 11:00:18 -0700717 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -0800718 * duplex, then store the values in the pointers provided.
719 **/
720static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
721 u16 *duplex)
722{
723 struct e1000_mac_info *mac = &hw->mac;
724 u32 pcs;
725
726 /* Set up defaults for the return values of this function */
727 mac->serdes_has_link = false;
728 *speed = 0;
729 *duplex = 0;
730
731 /*
732 * Read the PCS Status register for link state. For non-copper mode,
733 * the status register is not accurate. The PCS status register is
734 * used instead.
735 */
736 pcs = rd32(E1000_PCS_LSTAT);
737
738 /*
739 * The link up bit determines when link is up on autoneg. The sync ok
740 * gets set once both sides sync up and agree upon link. Stable link
741 * can be determined by checking for both link up and link sync ok
742 */
743 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
744 mac->serdes_has_link = true;
745
746 /* Detect and store PCS speed */
747 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
748 *speed = SPEED_1000;
749 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
750 *speed = SPEED_100;
751 } else {
752 *speed = SPEED_10;
753 }
754
755 /* Detect and store PCS duplex */
756 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
757 *duplex = FULL_DUPLEX;
758 } else {
759 *duplex = HALF_DUPLEX;
760 }
761 }
762
763 return 0;
764}
765
766/**
Alexander Duyck2d064c02008-07-08 15:10:12 -0700767 * igb_init_rx_addrs_82575 - Initialize receive address's
Auke Kok9d5c8242008-01-24 02:22:38 -0800768 * @hw: pointer to the HW structure
Alexander Duyck2d064c02008-07-08 15:10:12 -0700769 * @rar_count: receive address registers
Auke Kok9d5c8242008-01-24 02:22:38 -0800770 *
Alexander Duyck2d064c02008-07-08 15:10:12 -0700771 * Setups the receive address registers by setting the base receive address
772 * register to the devices MAC address and clearing all the other receive
773 * address registers to 0.
Auke Kok9d5c8242008-01-24 02:22:38 -0800774 **/
Alexander Duyck2d064c02008-07-08 15:10:12 -0700775static void igb_init_rx_addrs_82575(struct e1000_hw *hw, u16 rar_count)
Auke Kok9d5c8242008-01-24 02:22:38 -0800776{
Alexander Duyck2d064c02008-07-08 15:10:12 -0700777 u32 i;
778 u8 addr[6] = {0,0,0,0,0,0};
779 /*
780 * This function is essentially the same as that of
781 * e1000_init_rx_addrs_generic. However it also takes care
782 * of the special case where the register offset of the
783 * second set of RARs begins elsewhere. This is implicitly taken care by
784 * function e1000_rar_set_generic.
785 */
786
787 hw_dbg("e1000_init_rx_addrs_82575");
788
789 /* Setup the receive address */
790 hw_dbg("Programming MAC Address into RAR[0]\n");
791 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
792
793 /* Zero out the other (rar_entry_count - 1) receive addresses */
794 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
795 for (i = 1; i < rar_count; i++)
796 hw->mac.ops.rar_set(hw, addr, i);
797}
798
799/**
Alexander Duyck8a900862009-02-06 23:20:10 +0000800 * igb_update_mc_addr_list - Update Multicast addresses
Alexander Duyck2d064c02008-07-08 15:10:12 -0700801 * @hw: pointer to the HW structure
802 * @mc_addr_list: array of multicast addresses to program
803 * @mc_addr_count: number of multicast addresses to program
804 * @rar_used_count: the first RAR register free to program
805 * @rar_count: total number of supported Receive Address Registers
806 *
807 * Updates the Receive Address Registers and Multicast Table Array.
808 * The caller must have a packed mc_addr_list of multicast addresses.
809 * The parameter rar_count will usually be hw->mac.rar_entry_count
810 * unless there are workarounds that change this.
811 **/
Alexander Duyck8a900862009-02-06 23:20:10 +0000812void igb_update_mc_addr_list(struct e1000_hw *hw,
813 u8 *mc_addr_list, u32 mc_addr_count,
814 u32 rar_used_count, u32 rar_count)
Alexander Duyck2d064c02008-07-08 15:10:12 -0700815{
816 u32 hash_value;
817 u32 i;
818 u8 addr[6] = {0,0,0,0,0,0};
819 /*
820 * This function is essentially the same as that of
821 * igb_update_mc_addr_list_generic. However it also takes care
822 * of the special case where the register offset of the
823 * second set of RARs begins elsewhere. This is implicitly taken care by
824 * function e1000_rar_set_generic.
825 */
826
827 /*
828 * Load the first set of multicast addresses into the exact
829 * filters (RAR). If there are not enough to fill the RAR
830 * array, clear the filters.
831 */
832 for (i = rar_used_count; i < rar_count; i++) {
833 if (mc_addr_count) {
834 igb_rar_set(hw, mc_addr_list, i);
835 mc_addr_count--;
836 mc_addr_list += ETH_ALEN;
837 } else {
838 igb_rar_set(hw, addr, i);
839 }
840 }
841
842 /* Clear the old settings from the MTA */
843 hw_dbg("Clearing MTA\n");
844 for (i = 0; i < hw->mac.mta_reg_count; i++) {
845 array_wr32(E1000_MTA, i, 0);
846 wrfl();
847 }
848
849 /* Load any remaining multicast addresses into the hash table. */
850 for (; mc_addr_count > 0; mc_addr_count--) {
851 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
852 hw_dbg("Hash value = 0x%03X\n", hash_value);
Alexander Duyck549bdd82008-08-04 15:00:06 -0700853 igb_mta_set(hw, hash_value);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700854 mc_addr_list += ETH_ALEN;
855 }
856}
857
858/**
859 * igb_shutdown_fiber_serdes_link_82575 - Remove link during power down
860 * @hw: pointer to the HW structure
861 *
862 * In the case of fiber serdes, shut down optics and PCS on driver unload
863 * when management pass thru is not enabled.
864 **/
865void igb_shutdown_fiber_serdes_link_82575(struct e1000_hw *hw)
866{
867 u32 reg;
868
Alexander Duyck099e1cb2009-07-23 18:07:40 +0000869 if (hw->phy.media_type != e1000_media_type_internal_serdes)
Alexander Duyck2d064c02008-07-08 15:10:12 -0700870 return;
871
872 /* if the management interface is not enabled, then power down */
873 if (!igb_enable_mng_pass_thru(hw)) {
874 /* Disable PCS to turn off link */
875 reg = rd32(E1000_PCS_CFG0);
876 reg &= ~E1000_PCS_CFG_PCS_EN;
877 wr32(E1000_PCS_CFG0, reg);
878
879 /* shutdown the laser */
880 reg = rd32(E1000_CTRL_EXT);
881 reg |= E1000_CTRL_EXT_SDP7_DATA;
882 wr32(E1000_CTRL_EXT, reg);
883
884 /* flush the write to verify completion */
885 wrfl();
886 msleep(1);
887 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800888
889 return;
890}
891
892/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700893 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800894 * @hw: pointer to the HW structure
895 *
896 * This resets the hardware into a known state. This is a
897 * function pointer entry point called by the api module.
898 **/
899static s32 igb_reset_hw_82575(struct e1000_hw *hw)
900{
901 u32 ctrl, icr;
902 s32 ret_val;
903
904 /*
905 * Prevent the PCI-E bus from sticking if there is no TLP connection
906 * on the last TLP read/write transaction when MAC is reset.
907 */
908 ret_val = igb_disable_pcie_master(hw);
909 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700910 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800911
Auke Kok652fff32008-06-27 11:00:18 -0700912 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800913 wr32(E1000_IMC, 0xffffffff);
914
915 wr32(E1000_RCTL, 0);
916 wr32(E1000_TCTL, E1000_TCTL_PSP);
917 wrfl();
918
919 msleep(10);
920
921 ctrl = rd32(E1000_CTRL);
922
Auke Kok652fff32008-06-27 11:00:18 -0700923 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800924 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
925
926 ret_val = igb_get_auto_rd_done(hw);
927 if (ret_val) {
928 /*
929 * When auto config read does not complete, do not
930 * return with an error. This can happen in situations
931 * where there is no eeprom and prevents getting link.
932 */
Auke Kok652fff32008-06-27 11:00:18 -0700933 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 }
935
936 /* If EEPROM is not present, run manual init scripts */
937 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
938 igb_reset_init_script_82575(hw);
939
940 /* Clear any pending interrupt events. */
941 wr32(E1000_IMC, 0xffffffff);
942 icr = rd32(E1000_ICR);
943
944 igb_check_alt_mac_addr(hw);
945
946 return ret_val;
947}
948
949/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700950 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800951 * @hw: pointer to the HW structure
952 *
953 * This inits the hardware readying it for operation.
954 **/
955static s32 igb_init_hw_82575(struct e1000_hw *hw)
956{
957 struct e1000_mac_info *mac = &hw->mac;
958 s32 ret_val;
959 u16 i, rar_count = mac->rar_entry_count;
960
961 /* Initialize identification LED */
962 ret_val = igb_id_led_init(hw);
963 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700964 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800965 /* This is not fatal and we should not stop init due to this */
966 }
967
968 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -0700969 hw_dbg("Initializing the IEEE VLAN\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 igb_clear_vfta(hw);
971
972 /* Setup the receive address */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700973 igb_init_rx_addrs_82575(hw, rar_count);
Auke Kok9d5c8242008-01-24 02:22:38 -0800974 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -0700975 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800976 for (i = 0; i < mac->mta_reg_count; i++)
977 array_wr32(E1000_MTA, i, 0);
978
979 /* Setup link and flow control */
980 ret_val = igb_setup_link(hw);
981
982 /*
983 * Clear all of the statistics registers (clear on read). It is
984 * important that we do this after we have tried to establish link
985 * because the symbol error count will increment wildly if there
986 * is no link.
987 */
988 igb_clear_hw_cntrs_82575(hw);
989
990 return ret_val;
991}
992
993/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700994 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800995 * @hw: pointer to the HW structure
996 *
997 * Configures the link for auto-neg or forced speed and duplex. Then we check
998 * for link, once link is established calls to configure collision distance
999 * and flow control are called.
1000 **/
1001static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1002{
Alexander Duyck12645a12009-07-23 18:08:16 +00001003 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001004 s32 ret_val;
1005 bool link;
1006
1007 ctrl = rd32(E1000_CTRL);
1008 ctrl |= E1000_CTRL_SLU;
1009 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1010 wr32(E1000_CTRL, ctrl);
1011
1012 switch (hw->phy.type) {
1013 case e1000_phy_m88:
1014 ret_val = igb_copper_link_setup_m88(hw);
1015 break;
1016 case e1000_phy_igp_3:
1017 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001018 break;
1019 default:
1020 ret_val = -E1000_ERR_PHY;
1021 break;
1022 }
1023
1024 if (ret_val)
1025 goto out;
1026
1027 if (hw->mac.autoneg) {
1028 /*
1029 * Setup autoneg and flow control advertisement
1030 * and perform autonegotiation.
1031 */
1032 ret_val = igb_copper_link_autoneg(hw);
1033 if (ret_val)
1034 goto out;
1035 } else {
1036 /*
1037 * PHY will be set to 10H, 10F, 100H or 100F
1038 * depending on user settings.
1039 */
Auke Kok652fff32008-06-27 11:00:18 -07001040 hw_dbg("Forcing Speed and Duplex\n");
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001041 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001042 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001043 hw_dbg("Error Forcing Speed and Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001044 goto out;
1045 }
1046 }
1047
Alexander Duyckf3e78412009-07-23 18:07:58 +00001048 igb_configure_pcs_link_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001049
1050 /*
1051 * Check link status. Wait up to 100 microseconds for link to become
1052 * valid.
1053 */
Auke Kok652fff32008-06-27 11:00:18 -07001054 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001055 if (ret_val)
1056 goto out;
1057
1058 if (link) {
Auke Kok652fff32008-06-27 11:00:18 -07001059 hw_dbg("Valid link established!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001060 /* Config the MAC and PHY after link is up */
1061 igb_config_collision_dist(hw);
1062 ret_val = igb_config_fc_after_link_up(hw);
1063 } else {
Auke Kok652fff32008-06-27 11:00:18 -07001064 hw_dbg("Unable to establish link!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001065 }
1066
1067out:
1068 return ret_val;
1069}
1070
1071/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001072 * igb_setup_fiber_serdes_link_82575 - Setup link for fiber/serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001073 * @hw: pointer to the HW structure
1074 *
1075 * Configures speed and duplex for fiber and serdes links.
1076 **/
1077static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *hw)
1078{
1079 u32 reg;
1080
1081 /*
1082 * On the 82575, SerDes loopback mode persists until it is
1083 * explicitly turned off or a power cycle is performed. A read to
1084 * the register does not indicate its status. Therefore, we ensure
1085 * loopback mode is disabled during initialization.
1086 */
1087 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1088
1089 /* Force link up, set 1gb, set both sw defined pins */
1090 reg = rd32(E1000_CTRL);
1091 reg |= E1000_CTRL_SLU |
1092 E1000_CTRL_SPD_1000 |
1093 E1000_CTRL_FRCSPD |
1094 E1000_CTRL_SWDPIN0 |
1095 E1000_CTRL_SWDPIN1;
1096 wr32(E1000_CTRL, reg);
1097
Alexander Duyck921aa742009-01-21 14:42:28 -08001098 /* Power on phy for 82576 fiber adapters */
1099 if (hw->mac.type == e1000_82576) {
1100 reg = rd32(E1000_CTRL_EXT);
1101 reg &= ~E1000_CTRL_EXT_SDP7_DATA;
1102 wr32(E1000_CTRL_EXT, reg);
1103 }
1104
Auke Kok9d5c8242008-01-24 02:22:38 -08001105 /* Set switch control to serdes energy detect */
1106 reg = rd32(E1000_CONNSW);
1107 reg |= E1000_CONNSW_ENRGSRC;
1108 wr32(E1000_CONNSW, reg);
1109
1110 /*
1111 * New SerDes mode allows for forcing speed or autonegotiating speed
1112 * at 1gb. Autoneg should be default set by most drivers. This is the
1113 * mode that will be compatible with older link partners and switches.
1114 * However, both are supported by the hardware and some drivers/tools.
1115 */
1116 reg = rd32(E1000_PCS_LCTL);
1117
1118 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1119 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1120
1121 if (hw->mac.autoneg) {
1122 /* Set PCS register for autoneg */
1123 reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1124 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1125 E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1126 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Auke Kok652fff32008-06-27 11:00:18 -07001127 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001128 } else {
1129 /* Set PCS register for forced speed */
1130 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1131 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1132 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1133 E1000_PCS_LCTL_FSD | /* Force Speed */
1134 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
Auke Kok652fff32008-06-27 11:00:18 -07001135 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001136 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001137
1138 if (hw->mac.type == e1000_82576) {
1139 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1140 igb_force_mac_fc(hw);
1141 }
1142
Auke Kok9d5c8242008-01-24 02:22:38 -08001143 wr32(E1000_PCS_LCTL, reg);
1144
1145 return 0;
1146}
1147
1148/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001149 * igb_configure_pcs_link_82575 - Configure PCS link
Auke Kok9d5c8242008-01-24 02:22:38 -08001150 * @hw: pointer to the HW structure
1151 *
1152 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1153 * only used on copper connections where the serialized gigabit media
1154 * independent interface (sgmii) is being used. Configures the link
1155 * for auto-negotiation or forces speed/duplex.
1156 **/
Alexander Duyckf3e78412009-07-23 18:07:58 +00001157static void igb_configure_pcs_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001158{
1159 struct e1000_mac_info *mac = &hw->mac;
1160 u32 reg = 0;
1161
1162 if (hw->phy.media_type != e1000_media_type_copper ||
1163 !(igb_sgmii_active_82575(hw)))
Alexander Duyckf3e78412009-07-23 18:07:58 +00001164 return;
Auke Kok9d5c8242008-01-24 02:22:38 -08001165
1166 /* For SGMII, we need to issue a PCS autoneg restart */
1167 reg = rd32(E1000_PCS_LCTL);
1168
1169 /* AN time out should be disabled for SGMII mode */
1170 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1171
1172 if (mac->autoneg) {
1173 /* Make sure forced speed and force link are not set */
1174 reg &= ~(E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1175
1176 /*
1177 * The PHY should be setup prior to calling this function.
1178 * All we need to do is restart autoneg and enable autoneg.
1179 */
1180 reg |= E1000_PCS_LCTL_AN_RESTART | E1000_PCS_LCTL_AN_ENABLE;
1181 } else {
Auke Kok652fff32008-06-27 11:00:18 -07001182 /* Set PCS register for forced speed */
Auke Kok9d5c8242008-01-24 02:22:38 -08001183
1184 /* Turn off bits for full duplex, speed, and autoneg */
1185 reg &= ~(E1000_PCS_LCTL_FSV_1000 |
1186 E1000_PCS_LCTL_FSV_100 |
1187 E1000_PCS_LCTL_FDV_FULL |
1188 E1000_PCS_LCTL_AN_ENABLE);
1189
1190 /* Check for duplex first */
1191 if (mac->forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1192 reg |= E1000_PCS_LCTL_FDV_FULL;
1193
1194 /* Now set speed */
1195 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED)
1196 reg |= E1000_PCS_LCTL_FSV_100;
1197
1198 /* Force speed and force link */
1199 reg |= E1000_PCS_LCTL_FSD |
1200 E1000_PCS_LCTL_FORCE_LINK |
1201 E1000_PCS_LCTL_FLV_LINK_UP;
1202
Auke Kok652fff32008-06-27 11:00:18 -07001203 hw_dbg("Wrote 0x%08X to PCS_LCTL to configure forced link\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001204 reg);
1205 }
1206 wr32(E1000_PCS_LCTL, reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001207}
1208
1209/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001210 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001211 * @hw: pointer to the HW structure
1212 *
1213 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1214 * which can be enabled for use in the embedded applications. Simply
1215 * return the current state of the sgmii interface.
1216 **/
1217static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1218{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001219 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001220 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001221}
1222
1223/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001224 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001225 * @hw: pointer to the HW structure
1226 *
1227 * Inits recommended HW defaults after a reset when there is no EEPROM
1228 * detected. This is only for the 82575.
1229 **/
1230static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1231{
1232 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001233 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001234 /* SerDes configuration via SERDESCTRL */
1235 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1236 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1237 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1238 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1239
1240 /* CCM configuration via CCMCTL register */
1241 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1242 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1243
1244 /* PCIe lanes configuration */
1245 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1246 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1247 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1248 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1249
1250 /* PCIe PLL Configuration */
1251 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1252 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1253 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1254 }
1255
1256 return 0;
1257}
1258
1259/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001260 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001261 * @hw: pointer to the HW structure
1262 **/
1263static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1264{
1265 s32 ret_val = 0;
1266
1267 if (igb_check_alt_mac_addr(hw))
1268 ret_val = igb_read_mac_addr(hw);
1269
1270 return ret_val;
1271}
1272
1273/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001274 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001275 * @hw: pointer to the HW structure
1276 *
1277 * Clears the hardware counters by reading the counter registers.
1278 **/
1279static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1280{
1281 u32 temp;
1282
1283 igb_clear_hw_cntrs_base(hw);
1284
1285 temp = rd32(E1000_PRC64);
1286 temp = rd32(E1000_PRC127);
1287 temp = rd32(E1000_PRC255);
1288 temp = rd32(E1000_PRC511);
1289 temp = rd32(E1000_PRC1023);
1290 temp = rd32(E1000_PRC1522);
1291 temp = rd32(E1000_PTC64);
1292 temp = rd32(E1000_PTC127);
1293 temp = rd32(E1000_PTC255);
1294 temp = rd32(E1000_PTC511);
1295 temp = rd32(E1000_PTC1023);
1296 temp = rd32(E1000_PTC1522);
1297
1298 temp = rd32(E1000_ALGNERRC);
1299 temp = rd32(E1000_RXERRC);
1300 temp = rd32(E1000_TNCRS);
1301 temp = rd32(E1000_CEXTERR);
1302 temp = rd32(E1000_TSCTC);
1303 temp = rd32(E1000_TSCTFC);
1304
1305 temp = rd32(E1000_MGTPRC);
1306 temp = rd32(E1000_MGTPDC);
1307 temp = rd32(E1000_MGTPTC);
1308
1309 temp = rd32(E1000_IAC);
1310 temp = rd32(E1000_ICRXOC);
1311
1312 temp = rd32(E1000_ICRXPTC);
1313 temp = rd32(E1000_ICRXATC);
1314 temp = rd32(E1000_ICTXPTC);
1315 temp = rd32(E1000_ICTXATC);
1316 temp = rd32(E1000_ICTXQEC);
1317 temp = rd32(E1000_ICTXQMTC);
1318 temp = rd32(E1000_ICRXDMTC);
1319
1320 temp = rd32(E1000_CBTMPC);
1321 temp = rd32(E1000_HTDPMC);
1322 temp = rd32(E1000_CBRMPC);
1323 temp = rd32(E1000_RPTHC);
1324 temp = rd32(E1000_HGPTC);
1325 temp = rd32(E1000_HTCBDPC);
1326 temp = rd32(E1000_HGORCL);
1327 temp = rd32(E1000_HGORCH);
1328 temp = rd32(E1000_HGOTCL);
1329 temp = rd32(E1000_HGOTCH);
1330 temp = rd32(E1000_LENERRS);
1331
1332 /* This register should not be read in copper configurations */
1333 if (hw->phy.media_type == e1000_media_type_internal_serdes)
1334 temp = rd32(E1000_SCVPC);
1335}
1336
Alexander Duyck662d7202008-06-27 11:00:29 -07001337/**
1338 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1339 * @hw: pointer to the HW structure
1340 *
1341 * After rx enable if managability is enabled then there is likely some
1342 * bad data at the start of the fifo and possibly in the DMA fifo. This
1343 * function clears the fifos and flushes any packets that came in as rx was
1344 * being enabled.
1345 **/
1346void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1347{
1348 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1349 int i, ms_wait;
1350
1351 if (hw->mac.type != e1000_82575 ||
1352 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1353 return;
1354
1355 /* Disable all RX queues */
1356 for (i = 0; i < 4; i++) {
1357 rxdctl[i] = rd32(E1000_RXDCTL(i));
1358 wr32(E1000_RXDCTL(i),
1359 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1360 }
1361 /* Poll all queues to verify they have shut down */
1362 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1363 msleep(1);
1364 rx_enabled = 0;
1365 for (i = 0; i < 4; i++)
1366 rx_enabled |= rd32(E1000_RXDCTL(i));
1367 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1368 break;
1369 }
1370
1371 if (ms_wait == 10)
1372 hw_dbg("Queue disable timed out after 10ms\n");
1373
1374 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1375 * incoming packets are rejected. Set enable and wait 2ms so that
1376 * any packet that was coming in as RCTL.EN was set is flushed
1377 */
1378 rfctl = rd32(E1000_RFCTL);
1379 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1380
1381 rlpml = rd32(E1000_RLPML);
1382 wr32(E1000_RLPML, 0);
1383
1384 rctl = rd32(E1000_RCTL);
1385 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1386 temp_rctl |= E1000_RCTL_LPE;
1387
1388 wr32(E1000_RCTL, temp_rctl);
1389 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1390 wrfl();
1391 msleep(2);
1392
1393 /* Enable RX queues that were previously enabled and restore our
1394 * previous state
1395 */
1396 for (i = 0; i < 4; i++)
1397 wr32(E1000_RXDCTL(i), rxdctl[i]);
1398 wr32(E1000_RCTL, rctl);
1399 wrfl();
1400
1401 wr32(E1000_RLPML, rlpml);
1402 wr32(E1000_RFCTL, rfctl);
1403
1404 /* Flush receive errors generated by workaround */
1405 rd32(E1000_ROC);
1406 rd32(E1000_RNBC);
1407 rd32(E1000_MPC);
1408}
1409
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001410/**
1411 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1412 * @hw: pointer to the hardware struct
1413 * @enable: state to enter, either enabled or disabled
1414 *
1415 * enables/disables L2 switch loopback functionality.
1416 **/
1417void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1418{
1419 u32 dtxswc = rd32(E1000_DTXSWC);
1420
1421 if (enable)
1422 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1423 else
1424 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1425
1426 wr32(E1000_DTXSWC, dtxswc);
1427}
1428
1429/**
1430 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1431 * @hw: pointer to the hardware struct
1432 * @enable: state to enter, either enabled or disabled
1433 *
1434 * enables/disables replication of packets across multiple pools.
1435 **/
1436void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1437{
1438 u32 vt_ctl = rd32(E1000_VT_CTL);
1439
1440 if (enable)
1441 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1442 else
1443 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1444
1445 wr32(E1000_VT_CTL, vt_ctl);
1446}
1447
Auke Kok9d5c8242008-01-24 02:22:38 -08001448static struct e1000_mac_operations e1000_mac_ops_82575 = {
1449 .reset_hw = igb_reset_hw_82575,
1450 .init_hw = igb_init_hw_82575,
1451 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001452 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08001453 .read_mac_addr = igb_read_mac_addr_82575,
1454 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1455};
1456
1457static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001458 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001459 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001460 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001461};
1462
1463static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001464 .acquire = igb_acquire_nvm_82575,
1465 .read = igb_read_nvm_eerd,
1466 .release = igb_release_nvm_82575,
1467 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08001468};
1469
1470const struct e1000_info e1000_82575_info = {
1471 .get_invariants = igb_get_invariants_82575,
1472 .mac_ops = &e1000_mac_ops_82575,
1473 .phy_ops = &e1000_phy_ops_82575,
1474 .nvm_ops = &e1000_nvm_ops_82575,
1475};
1476