blob: ea63a215c9099013ff71f18078d596a32175b49c [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);
56static s32 igb_configure_pcs_link_82575(struct e1000_hw *);
57static 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:
83 case E1000_DEV_ID_82576_FIBER:
84 case E1000_DEV_ID_82576_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -070085 mac->type = e1000_82576;
86 break;
Auke Kok9d5c8242008-01-24 02:22:38 -080087 default:
88 return -E1000_ERR_MAC_INIT;
89 break;
90 }
91
Auke Kok9d5c8242008-01-24 02:22:38 -080092 /* Set media type */
93 /*
94 * The 82575 uses bits 22:23 for link mode. The mode can be changed
95 * based on the EEPROM. We cannot rely upon device ID. There
96 * is no distinguishable difference between fiber and internal
97 * SerDes mode on the 82575. There can be an external PHY attached
98 * on the SGMII interface. For this, we'll set sgmii_active to true.
99 */
100 phy->media_type = e1000_media_type_copper;
101 dev_spec->sgmii_active = false;
102
103 ctrl_ext = rd32(E1000_CTRL_EXT);
104 if ((ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) ==
105 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES) {
106 hw->phy.media_type = e1000_media_type_internal_serdes;
107 ctrl_ext |= E1000_CTRL_I2C_ENA;
108 } else if (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII) {
109 dev_spec->sgmii_active = true;
110 ctrl_ext |= E1000_CTRL_I2C_ENA;
111 } else {
112 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
113 }
114 wr32(E1000_CTRL_EXT, ctrl_ext);
115
116 /* Set mta register count */
117 mac->mta_reg_count = 128;
118 /* Set rar entry count */
119 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700120 if (mac->type == e1000_82576)
121 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Auke Kok9d5c8242008-01-24 02:22:38 -0800122 /* Set if part includes ASF firmware */
123 mac->asf_firmware_present = true;
124 /* Set if manageability features are enabled. */
125 mac->arc_subsystem_valid =
126 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
127 ? true : false;
128
129 /* physical interface link setup */
130 mac->ops.setup_physical_interface =
131 (hw->phy.media_type == e1000_media_type_copper)
132 ? igb_setup_copper_link_82575
133 : igb_setup_fiber_serdes_link_82575;
134
135 /* NVM initialization */
136 eecd = rd32(E1000_EECD);
137
138 nvm->opcode_bits = 8;
139 nvm->delay_usec = 1;
140 switch (nvm->override) {
141 case e1000_nvm_override_spi_large:
142 nvm->page_size = 32;
143 nvm->address_bits = 16;
144 break;
145 case e1000_nvm_override_spi_small:
146 nvm->page_size = 8;
147 nvm->address_bits = 8;
148 break;
149 default:
150 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
151 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
152 break;
153 }
154
155 nvm->type = e1000_nvm_eeprom_spi;
156
157 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
158 E1000_EECD_SIZE_EX_SHIFT);
159
160 /*
161 * Added to a constant, "size" becomes the left-shift value
162 * for setting word_size.
163 */
164 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700165
166 /* EEPROM access above 16k is unsupported */
167 if (size > 14)
168 size = 14;
Auke Kok9d5c8242008-01-24 02:22:38 -0800169 nvm->word_size = 1 << size;
170
171 /* setup PHY parameters */
172 if (phy->media_type != e1000_media_type_copper) {
173 phy->type = e1000_phy_none;
174 return 0;
175 }
176
177 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
178 phy->reset_delay_us = 100;
179
180 /* PHY function pointers */
181 if (igb_sgmii_active_82575(hw)) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000182 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
183 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
184 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800185 } else {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000186 phy->ops.reset = igb_phy_hw_reset;
187 phy->ops.read_reg = igb_read_phy_reg_igp;
188 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800189 }
190
191 /* Set phy->phy_addr and phy->id. */
192 ret_val = igb_get_phy_id_82575(hw);
193 if (ret_val)
194 return ret_val;
195
196 /* Verify phy id and set remaining function pointers */
197 switch (phy->id) {
198 case M88E1111_I_PHY_ID:
199 phy->type = e1000_phy_m88;
200 phy->ops.get_phy_info = igb_get_phy_info_m88;
201 phy->ops.get_cable_length = igb_get_cable_length_m88;
202 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
203 break;
204 case IGP03E1000_E_PHY_ID:
205 phy->type = e1000_phy_igp_3;
206 phy->ops.get_phy_info = igb_get_phy_info_igp;
207 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
208 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
209 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
210 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
211 break;
212 default:
213 return -E1000_ERR_PHY;
214 }
215
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800216 /* if 82576 then initialize mailbox parameters */
217 if (mac->type == e1000_82576)
218 igb_init_mbx_params_pf(hw);
219
Auke Kok9d5c8242008-01-24 02:22:38 -0800220 return 0;
221}
222
223/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700224 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800225 * @hw: pointer to the HW structure
226 *
227 * Acquire access rights to the correct PHY. This is a
228 * function pointer entry point called by the api module.
229 **/
230static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
231{
232 u16 mask;
233
234 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
235
236 return igb_acquire_swfw_sync_82575(hw, mask);
237}
238
239/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700240 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800241 * @hw: pointer to the HW structure
242 *
243 * A wrapper to release access rights to the correct PHY. This is a
244 * function pointer entry point called by the api module.
245 **/
246static void igb_release_phy_82575(struct e1000_hw *hw)
247{
248 u16 mask;
249
250 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
251 igb_release_swfw_sync_82575(hw, mask);
252}
253
254/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700255 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800256 * @hw: pointer to the HW structure
257 * @offset: register offset to be read
258 * @data: pointer to the read data
259 *
260 * Reads the PHY register at offset using the serial gigabit media independent
261 * interface and stores the retrieved information in data.
262 **/
263static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
264 u16 *data)
265{
266 struct e1000_phy_info *phy = &hw->phy;
267 u32 i, i2ccmd = 0;
268
269 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700270 hw_dbg("PHY Address %u is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800271 return -E1000_ERR_PARAM;
272 }
273
274 /*
275 * Set up Op-code, Phy Address, and register address in the I2CCMD
276 * register. The MAC will take care of interfacing with the
277 * PHY to retrieve the desired data.
278 */
279 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
280 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
281 (E1000_I2CCMD_OPCODE_READ));
282
283 wr32(E1000_I2CCMD, i2ccmd);
284
285 /* Poll the ready bit to see if the I2C read completed */
286 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
287 udelay(50);
288 i2ccmd = rd32(E1000_I2CCMD);
289 if (i2ccmd & E1000_I2CCMD_READY)
290 break;
291 }
292 if (!(i2ccmd & E1000_I2CCMD_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700293 hw_dbg("I2CCMD Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800294 return -E1000_ERR_PHY;
295 }
296 if (i2ccmd & E1000_I2CCMD_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700297 hw_dbg("I2CCMD Error bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800298 return -E1000_ERR_PHY;
299 }
300
301 /* Need to byte-swap the 16-bit value. */
302 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
303
304 return 0;
305}
306
307/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700308 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800309 * @hw: pointer to the HW structure
310 * @offset: register offset to write to
311 * @data: data to write at register offset
312 *
313 * Writes the data to PHY register at the offset using the serial gigabit
314 * media independent interface.
315 **/
316static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
317 u16 data)
318{
319 struct e1000_phy_info *phy = &hw->phy;
320 u32 i, i2ccmd = 0;
321 u16 phy_data_swapped;
322
323 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700324 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800325 return -E1000_ERR_PARAM;
326 }
327
328 /* Swap the data bytes for the I2C interface */
329 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
330
331 /*
332 * Set up Op-code, Phy Address, and register address in the I2CCMD
333 * register. The MAC will take care of interfacing with the
334 * PHY to retrieve the desired data.
335 */
336 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
337 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
338 E1000_I2CCMD_OPCODE_WRITE |
339 phy_data_swapped);
340
341 wr32(E1000_I2CCMD, i2ccmd);
342
343 /* Poll the ready bit to see if the I2C read completed */
344 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
345 udelay(50);
346 i2ccmd = rd32(E1000_I2CCMD);
347 if (i2ccmd & E1000_I2CCMD_READY)
348 break;
349 }
350 if (!(i2ccmd & E1000_I2CCMD_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700351 hw_dbg("I2CCMD Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800352 return -E1000_ERR_PHY;
353 }
354 if (i2ccmd & E1000_I2CCMD_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700355 hw_dbg("I2CCMD Error bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800356 return -E1000_ERR_PHY;
357 }
358
359 return 0;
360}
361
362/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700363 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800364 * @hw: pointer to the HW structure
365 *
Auke Kok652fff32008-06-27 11:00:18 -0700366 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800367 * sgmi interface.
368 **/
369static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
370{
371 struct e1000_phy_info *phy = &hw->phy;
372 s32 ret_val = 0;
373 u16 phy_id;
374
375 /*
376 * For SGMII PHYs, we try the list of possible addresses until
377 * we find one that works. For non-SGMII PHYs
378 * (e.g. integrated copper PHYs), an address of 1 should
379 * work. The result of this function should mean phy->phy_addr
380 * and phy->id are set correctly.
381 */
382 if (!(igb_sgmii_active_82575(hw))) {
383 phy->addr = 1;
384 ret_val = igb_get_phy_id(hw);
385 goto out;
386 }
387
388 /*
389 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
390 * Therefore, we need to test 1-7
391 */
392 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
393 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
394 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700395 hw_dbg("Vendor ID 0x%08X read at address %u\n",
396 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800397 /*
398 * At the time of this writing, The M88 part is
399 * the only supported SGMII PHY product.
400 */
401 if (phy_id == M88_VENDOR)
402 break;
403 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700404 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800405 }
406 }
407
408 /* A valid PHY type couldn't be found. */
409 if (phy->addr == 8) {
410 phy->addr = 0;
411 ret_val = -E1000_ERR_PHY;
412 goto out;
413 }
414
415 ret_val = igb_get_phy_id(hw);
416
417out:
418 return ret_val;
419}
420
421/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700422 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800423 * @hw: pointer to the HW structure
424 *
425 * Resets the PHY using the serial gigabit media independent interface.
426 **/
427static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
428{
429 s32 ret_val;
430
431 /*
432 * This isn't a true "hard" reset, but is the only reset
433 * available to us at this time.
434 */
435
Auke Kok652fff32008-06-27 11:00:18 -0700436 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800437
438 /*
439 * SFP documentation requires the following to configure the SPF module
440 * to work on SGMII. No further documentation is given.
441 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000442 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800443 if (ret_val)
444 goto out;
445
446 ret_val = igb_phy_sw_reset(hw);
447
448out:
449 return ret_val;
450}
451
452/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700453 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800454 * @hw: pointer to the HW structure
455 * @active: true to enable LPLU, false to disable
456 *
457 * Sets the LPLU D0 state according to the active flag. When
458 * activating LPLU this function also disables smart speed
459 * and vice versa. LPLU will not be activated unless the
460 * device autonegotiation advertisement meets standards of
461 * either 10 or 10/100 or 10/100/1000 at all duplexes.
462 * This is a function pointer entry point only called by
463 * PHY setup routines.
464 **/
465static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
466{
467 struct e1000_phy_info *phy = &hw->phy;
468 s32 ret_val;
469 u16 data;
470
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000471 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800472 if (ret_val)
473 goto out;
474
475 if (active) {
476 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000477 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700478 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800479 if (ret_val)
480 goto out;
481
482 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000483 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700484 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800485 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000486 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700487 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800488 if (ret_val)
489 goto out;
490 } else {
491 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000492 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700493 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800494 /*
495 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
496 * during Dx states where the power conservation is most
497 * important. During driver activity we should enable
498 * SmartSpeed, so performance is maintained.
499 */
500 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000501 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700502 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800503 if (ret_val)
504 goto out;
505
506 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000507 ret_val = phy->ops.write_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 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000512 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700513 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800514 if (ret_val)
515 goto out;
516
517 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000518 ret_val = phy->ops.write_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 }
524
525out:
526 return ret_val;
527}
528
529/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700530 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800531 * @hw: pointer to the HW structure
532 *
Auke Kok652fff32008-06-27 11:00:18 -0700533 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800534 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
535 * Return successful if access grant bit set, else clear the request for
536 * EEPROM access and return -E1000_ERR_NVM (-1).
537 **/
538static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
539{
540 s32 ret_val;
541
542 ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
543 if (ret_val)
544 goto out;
545
546 ret_val = igb_acquire_nvm(hw);
547
548 if (ret_val)
549 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
550
551out:
552 return ret_val;
553}
554
555/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700556 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800557 * @hw: pointer to the HW structure
558 *
559 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
560 * then release the semaphores acquired.
561 **/
562static void igb_release_nvm_82575(struct e1000_hw *hw)
563{
564 igb_release_nvm(hw);
565 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
566}
567
568/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700569 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800570 * @hw: pointer to the HW structure
571 * @mask: specifies which semaphore to acquire
572 *
573 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
574 * will also specify which port we're acquiring the lock for.
575 **/
576static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
577{
578 u32 swfw_sync;
579 u32 swmask = mask;
580 u32 fwmask = mask << 16;
581 s32 ret_val = 0;
582 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
583
584 while (i < timeout) {
585 if (igb_get_hw_semaphore(hw)) {
586 ret_val = -E1000_ERR_SWFW_SYNC;
587 goto out;
588 }
589
590 swfw_sync = rd32(E1000_SW_FW_SYNC);
591 if (!(swfw_sync & (fwmask | swmask)))
592 break;
593
594 /*
595 * Firmware currently using resource (fwmask)
596 * or other software thread using resource (swmask)
597 */
598 igb_put_hw_semaphore(hw);
599 mdelay(5);
600 i++;
601 }
602
603 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -0700604 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800605 ret_val = -E1000_ERR_SWFW_SYNC;
606 goto out;
607 }
608
609 swfw_sync |= swmask;
610 wr32(E1000_SW_FW_SYNC, swfw_sync);
611
612 igb_put_hw_semaphore(hw);
613
614out:
615 return ret_val;
616}
617
618/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700619 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800620 * @hw: pointer to the HW structure
621 * @mask: specifies which semaphore to acquire
622 *
623 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
624 * will also specify which port we're releasing the lock for.
625 **/
626static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
627{
628 u32 swfw_sync;
629
630 while (igb_get_hw_semaphore(hw) != 0);
631 /* Empty */
632
633 swfw_sync = rd32(E1000_SW_FW_SYNC);
634 swfw_sync &= ~mask;
635 wr32(E1000_SW_FW_SYNC, swfw_sync);
636
637 igb_put_hw_semaphore(hw);
638}
639
640/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700641 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -0800642 * @hw: pointer to the HW structure
643 *
644 * Read the management control register for the config done bit for
645 * completion status. NOTE: silicon which is EEPROM-less will fail trying
646 * to read the config done bit, so an error is *ONLY* logged and returns
647 * 0. If we were to return with error, EEPROM-less silicon
648 * would not be able to be reset or change link.
649 **/
650static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
651{
652 s32 timeout = PHY_CFG_TIMEOUT;
653 s32 ret_val = 0;
654 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
655
656 if (hw->bus.func == 1)
657 mask = E1000_NVM_CFG_DONE_PORT_1;
658
659 while (timeout) {
660 if (rd32(E1000_EEMNGCTL) & mask)
661 break;
662 msleep(1);
663 timeout--;
664 }
665 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -0700666 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800667
668 /* If EEPROM is not marked present, init the PHY manually */
669 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
670 (hw->phy.type == e1000_phy_igp_3))
671 igb_phy_init_script_igp3(hw);
672
673 return ret_val;
674}
675
676/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700677 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -0800678 * @hw: pointer to the HW structure
679 *
680 * If sgmii is enabled, then use the pcs register to determine link, otherwise
681 * use the generic interface for determining link.
682 **/
683static s32 igb_check_for_link_82575(struct e1000_hw *hw)
684{
685 s32 ret_val;
686 u16 speed, duplex;
687
688 /* SGMII link check is done through the PCS register. */
689 if ((hw->phy.media_type != e1000_media_type_copper) ||
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800690 (igb_sgmii_active_82575(hw))) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800691 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -0700692 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800693 /*
694 * Use this flag to determine if link needs to be checked or
695 * not. If we have link clear the flag so that we do not
696 * continue to check for link.
697 */
698 hw->mac.get_link_status = !hw->mac.serdes_has_link;
699 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800700 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800701 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800702
703 return ret_val;
704}
Auke Kok9d5c8242008-01-24 02:22:38 -0800705/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700706 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800707 * @hw: pointer to the HW structure
708 * @speed: stores the current speed
709 * @duplex: stores the current duplex
710 *
Auke Kok652fff32008-06-27 11:00:18 -0700711 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 * duplex, then store the values in the pointers provided.
713 **/
714static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
715 u16 *duplex)
716{
717 struct e1000_mac_info *mac = &hw->mac;
718 u32 pcs;
719
720 /* Set up defaults for the return values of this function */
721 mac->serdes_has_link = false;
722 *speed = 0;
723 *duplex = 0;
724
725 /*
726 * Read the PCS Status register for link state. For non-copper mode,
727 * the status register is not accurate. The PCS status register is
728 * used instead.
729 */
730 pcs = rd32(E1000_PCS_LSTAT);
731
732 /*
733 * The link up bit determines when link is up on autoneg. The sync ok
734 * gets set once both sides sync up and agree upon link. Stable link
735 * can be determined by checking for both link up and link sync ok
736 */
737 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
738 mac->serdes_has_link = true;
739
740 /* Detect and store PCS speed */
741 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
742 *speed = SPEED_1000;
743 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
744 *speed = SPEED_100;
745 } else {
746 *speed = SPEED_10;
747 }
748
749 /* Detect and store PCS duplex */
750 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
751 *duplex = FULL_DUPLEX;
752 } else {
753 *duplex = HALF_DUPLEX;
754 }
755 }
756
757 return 0;
758}
759
760/**
Alexander Duyck2d064c02008-07-08 15:10:12 -0700761 * igb_init_rx_addrs_82575 - Initialize receive address's
Auke Kok9d5c8242008-01-24 02:22:38 -0800762 * @hw: pointer to the HW structure
Alexander Duyck2d064c02008-07-08 15:10:12 -0700763 * @rar_count: receive address registers
Auke Kok9d5c8242008-01-24 02:22:38 -0800764 *
Alexander Duyck2d064c02008-07-08 15:10:12 -0700765 * Setups the receive address registers by setting the base receive address
766 * register to the devices MAC address and clearing all the other receive
767 * address registers to 0.
Auke Kok9d5c8242008-01-24 02:22:38 -0800768 **/
Alexander Duyck2d064c02008-07-08 15:10:12 -0700769static void igb_init_rx_addrs_82575(struct e1000_hw *hw, u16 rar_count)
Auke Kok9d5c8242008-01-24 02:22:38 -0800770{
Alexander Duyck2d064c02008-07-08 15:10:12 -0700771 u32 i;
772 u8 addr[6] = {0,0,0,0,0,0};
773 /*
774 * This function is essentially the same as that of
775 * e1000_init_rx_addrs_generic. However it also takes care
776 * of the special case where the register offset of the
777 * second set of RARs begins elsewhere. This is implicitly taken care by
778 * function e1000_rar_set_generic.
779 */
780
781 hw_dbg("e1000_init_rx_addrs_82575");
782
783 /* Setup the receive address */
784 hw_dbg("Programming MAC Address into RAR[0]\n");
785 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
786
787 /* Zero out the other (rar_entry_count - 1) receive addresses */
788 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
789 for (i = 1; i < rar_count; i++)
790 hw->mac.ops.rar_set(hw, addr, i);
791}
792
793/**
Alexander Duyck8a900862009-02-06 23:20:10 +0000794 * igb_update_mc_addr_list - Update Multicast addresses
Alexander Duyck2d064c02008-07-08 15:10:12 -0700795 * @hw: pointer to the HW structure
796 * @mc_addr_list: array of multicast addresses to program
797 * @mc_addr_count: number of multicast addresses to program
798 * @rar_used_count: the first RAR register free to program
799 * @rar_count: total number of supported Receive Address Registers
800 *
801 * Updates the Receive Address Registers and Multicast Table Array.
802 * The caller must have a packed mc_addr_list of multicast addresses.
803 * The parameter rar_count will usually be hw->mac.rar_entry_count
804 * unless there are workarounds that change this.
805 **/
Alexander Duyck8a900862009-02-06 23:20:10 +0000806void igb_update_mc_addr_list(struct e1000_hw *hw,
807 u8 *mc_addr_list, u32 mc_addr_count,
808 u32 rar_used_count, u32 rar_count)
Alexander Duyck2d064c02008-07-08 15:10:12 -0700809{
810 u32 hash_value;
811 u32 i;
812 u8 addr[6] = {0,0,0,0,0,0};
813 /*
814 * This function is essentially the same as that of
815 * igb_update_mc_addr_list_generic. However it also takes care
816 * of the special case where the register offset of the
817 * second set of RARs begins elsewhere. This is implicitly taken care by
818 * function e1000_rar_set_generic.
819 */
820
821 /*
822 * Load the first set of multicast addresses into the exact
823 * filters (RAR). If there are not enough to fill the RAR
824 * array, clear the filters.
825 */
826 for (i = rar_used_count; i < rar_count; i++) {
827 if (mc_addr_count) {
828 igb_rar_set(hw, mc_addr_list, i);
829 mc_addr_count--;
830 mc_addr_list += ETH_ALEN;
831 } else {
832 igb_rar_set(hw, addr, i);
833 }
834 }
835
836 /* Clear the old settings from the MTA */
837 hw_dbg("Clearing MTA\n");
838 for (i = 0; i < hw->mac.mta_reg_count; i++) {
839 array_wr32(E1000_MTA, i, 0);
840 wrfl();
841 }
842
843 /* Load any remaining multicast addresses into the hash table. */
844 for (; mc_addr_count > 0; mc_addr_count--) {
845 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
846 hw_dbg("Hash value = 0x%03X\n", hash_value);
Alexander Duyck549bdd82008-08-04 15:00:06 -0700847 igb_mta_set(hw, hash_value);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700848 mc_addr_list += ETH_ALEN;
849 }
850}
851
852/**
853 * igb_shutdown_fiber_serdes_link_82575 - Remove link during power down
854 * @hw: pointer to the HW structure
855 *
856 * In the case of fiber serdes, shut down optics and PCS on driver unload
857 * when management pass thru is not enabled.
858 **/
859void igb_shutdown_fiber_serdes_link_82575(struct e1000_hw *hw)
860{
861 u32 reg;
862
863 if (hw->mac.type != e1000_82576 ||
864 (hw->phy.media_type != e1000_media_type_fiber &&
865 hw->phy.media_type != e1000_media_type_internal_serdes))
866 return;
867
868 /* if the management interface is not enabled, then power down */
869 if (!igb_enable_mng_pass_thru(hw)) {
870 /* Disable PCS to turn off link */
871 reg = rd32(E1000_PCS_CFG0);
872 reg &= ~E1000_PCS_CFG_PCS_EN;
873 wr32(E1000_PCS_CFG0, reg);
874
875 /* shutdown the laser */
876 reg = rd32(E1000_CTRL_EXT);
877 reg |= E1000_CTRL_EXT_SDP7_DATA;
878 wr32(E1000_CTRL_EXT, reg);
879
880 /* flush the write to verify completion */
881 wrfl();
882 msleep(1);
883 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800884
885 return;
886}
887
888/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700889 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800890 * @hw: pointer to the HW structure
891 *
892 * This resets the hardware into a known state. This is a
893 * function pointer entry point called by the api module.
894 **/
895static s32 igb_reset_hw_82575(struct e1000_hw *hw)
896{
897 u32 ctrl, icr;
898 s32 ret_val;
899
900 /*
901 * Prevent the PCI-E bus from sticking if there is no TLP connection
902 * on the last TLP read/write transaction when MAC is reset.
903 */
904 ret_val = igb_disable_pcie_master(hw);
905 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700906 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800907
Auke Kok652fff32008-06-27 11:00:18 -0700908 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800909 wr32(E1000_IMC, 0xffffffff);
910
911 wr32(E1000_RCTL, 0);
912 wr32(E1000_TCTL, E1000_TCTL_PSP);
913 wrfl();
914
915 msleep(10);
916
917 ctrl = rd32(E1000_CTRL);
918
Auke Kok652fff32008-06-27 11:00:18 -0700919 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800920 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
921
922 ret_val = igb_get_auto_rd_done(hw);
923 if (ret_val) {
924 /*
925 * When auto config read does not complete, do not
926 * return with an error. This can happen in situations
927 * where there is no eeprom and prevents getting link.
928 */
Auke Kok652fff32008-06-27 11:00:18 -0700929 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800930 }
931
932 /* If EEPROM is not present, run manual init scripts */
933 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
934 igb_reset_init_script_82575(hw);
935
936 /* Clear any pending interrupt events. */
937 wr32(E1000_IMC, 0xffffffff);
938 icr = rd32(E1000_ICR);
939
940 igb_check_alt_mac_addr(hw);
941
942 return ret_val;
943}
944
945/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700946 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800947 * @hw: pointer to the HW structure
948 *
949 * This inits the hardware readying it for operation.
950 **/
951static s32 igb_init_hw_82575(struct e1000_hw *hw)
952{
953 struct e1000_mac_info *mac = &hw->mac;
954 s32 ret_val;
955 u16 i, rar_count = mac->rar_entry_count;
956
957 /* Initialize identification LED */
958 ret_val = igb_id_led_init(hw);
959 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700960 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800961 /* This is not fatal and we should not stop init due to this */
962 }
963
964 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -0700965 hw_dbg("Initializing the IEEE VLAN\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800966 igb_clear_vfta(hw);
967
968 /* Setup the receive address */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700969 igb_init_rx_addrs_82575(hw, rar_count);
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -0700971 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800972 for (i = 0; i < mac->mta_reg_count; i++)
973 array_wr32(E1000_MTA, i, 0);
974
975 /* Setup link and flow control */
976 ret_val = igb_setup_link(hw);
977
978 /*
979 * Clear all of the statistics registers (clear on read). It is
980 * important that we do this after we have tried to establish link
981 * because the symbol error count will increment wildly if there
982 * is no link.
983 */
984 igb_clear_hw_cntrs_82575(hw);
985
986 return ret_val;
987}
988
989/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700990 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800991 * @hw: pointer to the HW structure
992 *
993 * Configures the link for auto-neg or forced speed and duplex. Then we check
994 * for link, once link is established calls to configure collision distance
995 * and flow control are called.
996 **/
997static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
998{
999 u32 ctrl, led_ctrl;
1000 s32 ret_val;
1001 bool link;
1002
1003 ctrl = rd32(E1000_CTRL);
1004 ctrl |= E1000_CTRL_SLU;
1005 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1006 wr32(E1000_CTRL, ctrl);
1007
1008 switch (hw->phy.type) {
1009 case e1000_phy_m88:
1010 ret_val = igb_copper_link_setup_m88(hw);
1011 break;
1012 case e1000_phy_igp_3:
1013 ret_val = igb_copper_link_setup_igp(hw);
1014 /* Setup activity LED */
1015 led_ctrl = rd32(E1000_LEDCTL);
1016 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1017 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1018 wr32(E1000_LEDCTL, led_ctrl);
1019 break;
1020 default:
1021 ret_val = -E1000_ERR_PHY;
1022 break;
1023 }
1024
1025 if (ret_val)
1026 goto out;
1027
1028 if (hw->mac.autoneg) {
1029 /*
1030 * Setup autoneg and flow control advertisement
1031 * and perform autonegotiation.
1032 */
1033 ret_val = igb_copper_link_autoneg(hw);
1034 if (ret_val)
1035 goto out;
1036 } else {
1037 /*
1038 * PHY will be set to 10H, 10F, 100H or 100F
1039 * depending on user settings.
1040 */
Auke Kok652fff32008-06-27 11:00:18 -07001041 hw_dbg("Forcing Speed and Duplex\n");
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001042 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001043 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001044 hw_dbg("Error Forcing Speed and Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001045 goto out;
1046 }
1047 }
1048
1049 ret_val = igb_configure_pcs_link_82575(hw);
1050 if (ret_val)
1051 goto out;
1052
1053 /*
1054 * Check link status. Wait up to 100 microseconds for link to become
1055 * valid.
1056 */
Auke Kok652fff32008-06-27 11:00:18 -07001057 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001058 if (ret_val)
1059 goto out;
1060
1061 if (link) {
Auke Kok652fff32008-06-27 11:00:18 -07001062 hw_dbg("Valid link established!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001063 /* Config the MAC and PHY after link is up */
1064 igb_config_collision_dist(hw);
1065 ret_val = igb_config_fc_after_link_up(hw);
1066 } else {
Auke Kok652fff32008-06-27 11:00:18 -07001067 hw_dbg("Unable to establish link!!!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001068 }
1069
1070out:
1071 return ret_val;
1072}
1073
1074/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001075 * igb_setup_fiber_serdes_link_82575 - Setup link for fiber/serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001076 * @hw: pointer to the HW structure
1077 *
1078 * Configures speed and duplex for fiber and serdes links.
1079 **/
1080static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *hw)
1081{
1082 u32 reg;
1083
1084 /*
1085 * On the 82575, SerDes loopback mode persists until it is
1086 * explicitly turned off or a power cycle is performed. A read to
1087 * the register does not indicate its status. Therefore, we ensure
1088 * loopback mode is disabled during initialization.
1089 */
1090 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1091
1092 /* Force link up, set 1gb, set both sw defined pins */
1093 reg = rd32(E1000_CTRL);
1094 reg |= E1000_CTRL_SLU |
1095 E1000_CTRL_SPD_1000 |
1096 E1000_CTRL_FRCSPD |
1097 E1000_CTRL_SWDPIN0 |
1098 E1000_CTRL_SWDPIN1;
1099 wr32(E1000_CTRL, reg);
1100
Alexander Duyck921aa742009-01-21 14:42:28 -08001101 /* Power on phy for 82576 fiber adapters */
1102 if (hw->mac.type == e1000_82576) {
1103 reg = rd32(E1000_CTRL_EXT);
1104 reg &= ~E1000_CTRL_EXT_SDP7_DATA;
1105 wr32(E1000_CTRL_EXT, reg);
1106 }
1107
Auke Kok9d5c8242008-01-24 02:22:38 -08001108 /* Set switch control to serdes energy detect */
1109 reg = rd32(E1000_CONNSW);
1110 reg |= E1000_CONNSW_ENRGSRC;
1111 wr32(E1000_CONNSW, reg);
1112
1113 /*
1114 * New SerDes mode allows for forcing speed or autonegotiating speed
1115 * at 1gb. Autoneg should be default set by most drivers. This is the
1116 * mode that will be compatible with older link partners and switches.
1117 * However, both are supported by the hardware and some drivers/tools.
1118 */
1119 reg = rd32(E1000_PCS_LCTL);
1120
1121 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1122 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1123
1124 if (hw->mac.autoneg) {
1125 /* Set PCS register for autoneg */
1126 reg |= E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1127 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1128 E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
1129 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Auke Kok652fff32008-06-27 11:00:18 -07001130 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001131 } else {
1132 /* Set PCS register for forced speed */
1133 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1134 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1135 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1136 E1000_PCS_LCTL_FSD | /* Force Speed */
1137 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
Auke Kok652fff32008-06-27 11:00:18 -07001138 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001139 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001140
1141 if (hw->mac.type == e1000_82576) {
1142 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1143 igb_force_mac_fc(hw);
1144 }
1145
Auke Kok9d5c8242008-01-24 02:22:38 -08001146 wr32(E1000_PCS_LCTL, reg);
1147
1148 return 0;
1149}
1150
1151/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001152 * igb_configure_pcs_link_82575 - Configure PCS link
Auke Kok9d5c8242008-01-24 02:22:38 -08001153 * @hw: pointer to the HW structure
1154 *
1155 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1156 * only used on copper connections where the serialized gigabit media
1157 * independent interface (sgmii) is being used. Configures the link
1158 * for auto-negotiation or forces speed/duplex.
1159 **/
1160static s32 igb_configure_pcs_link_82575(struct e1000_hw *hw)
1161{
1162 struct e1000_mac_info *mac = &hw->mac;
1163 u32 reg = 0;
1164
1165 if (hw->phy.media_type != e1000_media_type_copper ||
1166 !(igb_sgmii_active_82575(hw)))
1167 goto out;
1168
1169 /* For SGMII, we need to issue a PCS autoneg restart */
1170 reg = rd32(E1000_PCS_LCTL);
1171
1172 /* AN time out should be disabled for SGMII mode */
1173 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1174
1175 if (mac->autoneg) {
1176 /* Make sure forced speed and force link are not set */
1177 reg &= ~(E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1178
1179 /*
1180 * The PHY should be setup prior to calling this function.
1181 * All we need to do is restart autoneg and enable autoneg.
1182 */
1183 reg |= E1000_PCS_LCTL_AN_RESTART | E1000_PCS_LCTL_AN_ENABLE;
1184 } else {
Auke Kok652fff32008-06-27 11:00:18 -07001185 /* Set PCS register for forced speed */
Auke Kok9d5c8242008-01-24 02:22:38 -08001186
1187 /* Turn off bits for full duplex, speed, and autoneg */
1188 reg &= ~(E1000_PCS_LCTL_FSV_1000 |
1189 E1000_PCS_LCTL_FSV_100 |
1190 E1000_PCS_LCTL_FDV_FULL |
1191 E1000_PCS_LCTL_AN_ENABLE);
1192
1193 /* Check for duplex first */
1194 if (mac->forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1195 reg |= E1000_PCS_LCTL_FDV_FULL;
1196
1197 /* Now set speed */
1198 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED)
1199 reg |= E1000_PCS_LCTL_FSV_100;
1200
1201 /* Force speed and force link */
1202 reg |= E1000_PCS_LCTL_FSD |
1203 E1000_PCS_LCTL_FORCE_LINK |
1204 E1000_PCS_LCTL_FLV_LINK_UP;
1205
Auke Kok652fff32008-06-27 11:00:18 -07001206 hw_dbg("Wrote 0x%08X to PCS_LCTL to configure forced link\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001207 reg);
1208 }
1209 wr32(E1000_PCS_LCTL, reg);
1210
1211out:
1212 return 0;
1213}
1214
1215/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001216 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001217 * @hw: pointer to the HW structure
1218 *
1219 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1220 * which can be enabled for use in the embedded applications. Simply
1221 * return the current state of the sgmii interface.
1222 **/
1223static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1224{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001225 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -08001226
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001227 if (hw->mac.type != e1000_82575 && hw->mac.type != e1000_82576)
1228 return false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001229
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001230 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001231}
1232
1233/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001234 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001235 * @hw: pointer to the HW structure
1236 *
1237 * Inits recommended HW defaults after a reset when there is no EEPROM
1238 * detected. This is only for the 82575.
1239 **/
1240static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1241{
1242 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001243 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001244 /* SerDes configuration via SERDESCTRL */
1245 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1246 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1247 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1248 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1249
1250 /* CCM configuration via CCMCTL register */
1251 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1252 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1253
1254 /* PCIe lanes configuration */
1255 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1256 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1257 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1258 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1259
1260 /* PCIe PLL Configuration */
1261 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1262 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1263 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1264 }
1265
1266 return 0;
1267}
1268
1269/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001270 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001271 * @hw: pointer to the HW structure
1272 **/
1273static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1274{
1275 s32 ret_val = 0;
1276
1277 if (igb_check_alt_mac_addr(hw))
1278 ret_val = igb_read_mac_addr(hw);
1279
1280 return ret_val;
1281}
1282
1283/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001284 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001285 * @hw: pointer to the HW structure
1286 *
1287 * Clears the hardware counters by reading the counter registers.
1288 **/
1289static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1290{
1291 u32 temp;
1292
1293 igb_clear_hw_cntrs_base(hw);
1294
1295 temp = rd32(E1000_PRC64);
1296 temp = rd32(E1000_PRC127);
1297 temp = rd32(E1000_PRC255);
1298 temp = rd32(E1000_PRC511);
1299 temp = rd32(E1000_PRC1023);
1300 temp = rd32(E1000_PRC1522);
1301 temp = rd32(E1000_PTC64);
1302 temp = rd32(E1000_PTC127);
1303 temp = rd32(E1000_PTC255);
1304 temp = rd32(E1000_PTC511);
1305 temp = rd32(E1000_PTC1023);
1306 temp = rd32(E1000_PTC1522);
1307
1308 temp = rd32(E1000_ALGNERRC);
1309 temp = rd32(E1000_RXERRC);
1310 temp = rd32(E1000_TNCRS);
1311 temp = rd32(E1000_CEXTERR);
1312 temp = rd32(E1000_TSCTC);
1313 temp = rd32(E1000_TSCTFC);
1314
1315 temp = rd32(E1000_MGTPRC);
1316 temp = rd32(E1000_MGTPDC);
1317 temp = rd32(E1000_MGTPTC);
1318
1319 temp = rd32(E1000_IAC);
1320 temp = rd32(E1000_ICRXOC);
1321
1322 temp = rd32(E1000_ICRXPTC);
1323 temp = rd32(E1000_ICRXATC);
1324 temp = rd32(E1000_ICTXPTC);
1325 temp = rd32(E1000_ICTXATC);
1326 temp = rd32(E1000_ICTXQEC);
1327 temp = rd32(E1000_ICTXQMTC);
1328 temp = rd32(E1000_ICRXDMTC);
1329
1330 temp = rd32(E1000_CBTMPC);
1331 temp = rd32(E1000_HTDPMC);
1332 temp = rd32(E1000_CBRMPC);
1333 temp = rd32(E1000_RPTHC);
1334 temp = rd32(E1000_HGPTC);
1335 temp = rd32(E1000_HTCBDPC);
1336 temp = rd32(E1000_HGORCL);
1337 temp = rd32(E1000_HGORCH);
1338 temp = rd32(E1000_HGOTCL);
1339 temp = rd32(E1000_HGOTCH);
1340 temp = rd32(E1000_LENERRS);
1341
1342 /* This register should not be read in copper configurations */
1343 if (hw->phy.media_type == e1000_media_type_internal_serdes)
1344 temp = rd32(E1000_SCVPC);
1345}
1346
Alexander Duyck662d7202008-06-27 11:00:29 -07001347/**
1348 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1349 * @hw: pointer to the HW structure
1350 *
1351 * After rx enable if managability is enabled then there is likely some
1352 * bad data at the start of the fifo and possibly in the DMA fifo. This
1353 * function clears the fifos and flushes any packets that came in as rx was
1354 * being enabled.
1355 **/
1356void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1357{
1358 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1359 int i, ms_wait;
1360
1361 if (hw->mac.type != e1000_82575 ||
1362 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1363 return;
1364
1365 /* Disable all RX queues */
1366 for (i = 0; i < 4; i++) {
1367 rxdctl[i] = rd32(E1000_RXDCTL(i));
1368 wr32(E1000_RXDCTL(i),
1369 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1370 }
1371 /* Poll all queues to verify they have shut down */
1372 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1373 msleep(1);
1374 rx_enabled = 0;
1375 for (i = 0; i < 4; i++)
1376 rx_enabled |= rd32(E1000_RXDCTL(i));
1377 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1378 break;
1379 }
1380
1381 if (ms_wait == 10)
1382 hw_dbg("Queue disable timed out after 10ms\n");
1383
1384 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1385 * incoming packets are rejected. Set enable and wait 2ms so that
1386 * any packet that was coming in as RCTL.EN was set is flushed
1387 */
1388 rfctl = rd32(E1000_RFCTL);
1389 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1390
1391 rlpml = rd32(E1000_RLPML);
1392 wr32(E1000_RLPML, 0);
1393
1394 rctl = rd32(E1000_RCTL);
1395 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1396 temp_rctl |= E1000_RCTL_LPE;
1397
1398 wr32(E1000_RCTL, temp_rctl);
1399 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1400 wrfl();
1401 msleep(2);
1402
1403 /* Enable RX queues that were previously enabled and restore our
1404 * previous state
1405 */
1406 for (i = 0; i < 4; i++)
1407 wr32(E1000_RXDCTL(i), rxdctl[i]);
1408 wr32(E1000_RCTL, rctl);
1409 wrfl();
1410
1411 wr32(E1000_RLPML, rlpml);
1412 wr32(E1000_RFCTL, rfctl);
1413
1414 /* Flush receive errors generated by workaround */
1415 rd32(E1000_ROC);
1416 rd32(E1000_RNBC);
1417 rd32(E1000_MPC);
1418}
1419
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001420/**
1421 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1422 * @hw: pointer to the hardware struct
1423 * @enable: state to enter, either enabled or disabled
1424 *
1425 * enables/disables L2 switch loopback functionality.
1426 **/
1427void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1428{
1429 u32 dtxswc = rd32(E1000_DTXSWC);
1430
1431 if (enable)
1432 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1433 else
1434 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1435
1436 wr32(E1000_DTXSWC, dtxswc);
1437}
1438
1439/**
1440 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1441 * @hw: pointer to the hardware struct
1442 * @enable: state to enter, either enabled or disabled
1443 *
1444 * enables/disables replication of packets across multiple pools.
1445 **/
1446void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1447{
1448 u32 vt_ctl = rd32(E1000_VT_CTL);
1449
1450 if (enable)
1451 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1452 else
1453 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1454
1455 wr32(E1000_VT_CTL, vt_ctl);
1456}
1457
Auke Kok9d5c8242008-01-24 02:22:38 -08001458static struct e1000_mac_operations e1000_mac_ops_82575 = {
1459 .reset_hw = igb_reset_hw_82575,
1460 .init_hw = igb_init_hw_82575,
1461 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001462 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08001463 .read_mac_addr = igb_read_mac_addr_82575,
1464 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1465};
1466
1467static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001468 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001469 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001470 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001471};
1472
1473static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001474 .acquire = igb_acquire_nvm_82575,
1475 .read = igb_read_nvm_eerd,
1476 .release = igb_release_nvm_82575,
1477 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08001478};
1479
1480const struct e1000_info e1000_82575_info = {
1481 .get_invariants = igb_get_invariants_82575,
1482 .mac_ops = &e1000_mac_ops_82575,
1483 .phy_ops = &e1000_phy_ops_82575,
1484 .nvm_ops = &e1000_nvm_ops_82575,
1485};
1486