blob: 430631f49d9d52981a539fb9907a4041dacbe06a [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 *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000049static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
50static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080051static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000052static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080053static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
54static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000055static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080056static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
57static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
58static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080059static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
60 u16 *);
61static s32 igb_get_phy_id_82575(struct e1000_hw *);
62static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
63static bool igb_sgmii_active_82575(struct e1000_hw *);
64static s32 igb_reset_init_script_82575(struct e1000_hw *);
65static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000066static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080067
Alexander Duyckbb2ac472009-11-19 12:42:01 +000068static const u16 e1000_82580_rxpbs_table[] =
69 { 36, 72, 144, 1, 2, 4, 8, 16,
70 35, 70, 140 };
71#define E1000_82580_RXPBS_TABLE_SIZE \
72 (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
73
Auke Kok9d5c8242008-01-24 02:22:38 -080074static s32 igb_get_invariants_82575(struct e1000_hw *hw)
75{
76 struct e1000_phy_info *phy = &hw->phy;
77 struct e1000_nvm_info *nvm = &hw->nvm;
78 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +000079 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -080080 u32 eecd;
81 s32 ret_val;
82 u16 size;
83 u32 ctrl_ext = 0;
84
85 switch (hw->device_id) {
86 case E1000_DEV_ID_82575EB_COPPER:
87 case E1000_DEV_ID_82575EB_FIBER_SERDES:
88 case E1000_DEV_ID_82575GB_QUAD_COPPER:
89 mac->type = e1000_82575;
90 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -070091 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +000092 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +000093 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -070094 case E1000_DEV_ID_82576_FIBER:
95 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +000096 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +000097 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +000098 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -070099 mac->type = e1000_82576;
100 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000101 case E1000_DEV_ID_82580_COPPER:
102 case E1000_DEV_ID_82580_FIBER:
103 case E1000_DEV_ID_82580_SERDES:
104 case E1000_DEV_ID_82580_SGMII:
105 case E1000_DEV_ID_82580_COPPER_DUAL:
106 mac->type = e1000_82580;
107 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000108 case E1000_DEV_ID_I350_COPPER:
109 case E1000_DEV_ID_I350_FIBER:
110 case E1000_DEV_ID_I350_SERDES:
111 case E1000_DEV_ID_I350_SGMII:
112 mac->type = e1000_i350;
113 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800114 default:
115 return -E1000_ERR_MAC_INIT;
116 break;
117 }
118
Auke Kok9d5c8242008-01-24 02:22:38 -0800119 /* Set media type */
120 /*
121 * The 82575 uses bits 22:23 for link mode. The mode can be changed
122 * based on the EEPROM. We cannot rely upon device ID. There
123 * is no distinguishable difference between fiber and internal
124 * SerDes mode on the 82575. There can be an external PHY attached
125 * on the SGMII interface. For this, we'll set sgmii_active to true.
126 */
127 phy->media_type = e1000_media_type_copper;
128 dev_spec->sgmii_active = false;
129
130 ctrl_ext = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000131 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
132 case E1000_CTRL_EXT_LINK_MODE_SGMII:
Auke Kok9d5c8242008-01-24 02:22:38 -0800133 dev_spec->sgmii_active = true;
134 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000135 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000136 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000137 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
138 hw->phy.media_type = e1000_media_type_internal_serdes;
139 ctrl_ext |= E1000_CTRL_I2C_ENA;
140 break;
141 default:
Auke Kok9d5c8242008-01-24 02:22:38 -0800142 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000143 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800144 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000145
Auke Kok9d5c8242008-01-24 02:22:38 -0800146 wr32(E1000_CTRL_EXT, ctrl_ext);
147
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000148 /*
149 * if using i2c make certain the MDICNFG register is cleared to prevent
150 * communications from being misrouted to the mdic registers
151 */
152 if ((ctrl_ext & E1000_CTRL_I2C_ENA) && (hw->mac.type == e1000_82580))
153 wr32(E1000_MDICNFG, 0);
154
Auke Kok9d5c8242008-01-24 02:22:38 -0800155 /* Set mta register count */
156 mac->mta_reg_count = 128;
157 /* Set rar entry count */
158 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700159 if (mac->type == e1000_82576)
160 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000161 if (mac->type == e1000_82580)
162 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000163 if (mac->type == e1000_i350)
164 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000165 /* reset */
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000166 if (mac->type >= e1000_82580)
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000167 mac->ops.reset_hw = igb_reset_hw_82580;
168 else
169 mac->ops.reset_hw = igb_reset_hw_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800170 /* Set if part includes ASF firmware */
171 mac->asf_firmware_present = true;
172 /* Set if manageability features are enabled. */
173 mac->arc_subsystem_valid =
174 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
175 ? true : false;
176
177 /* physical interface link setup */
178 mac->ops.setup_physical_interface =
179 (hw->phy.media_type == e1000_media_type_copper)
180 ? igb_setup_copper_link_82575
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000181 : igb_setup_serdes_link_82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800182
183 /* NVM initialization */
184 eecd = rd32(E1000_EECD);
185
186 nvm->opcode_bits = 8;
187 nvm->delay_usec = 1;
188 switch (nvm->override) {
189 case e1000_nvm_override_spi_large:
190 nvm->page_size = 32;
191 nvm->address_bits = 16;
192 break;
193 case e1000_nvm_override_spi_small:
194 nvm->page_size = 8;
195 nvm->address_bits = 8;
196 break;
197 default:
198 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
199 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
200 break;
201 }
202
203 nvm->type = e1000_nvm_eeprom_spi;
204
205 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
206 E1000_EECD_SIZE_EX_SHIFT);
207
208 /*
209 * Added to a constant, "size" becomes the left-shift value
210 * for setting word_size.
211 */
212 size += NVM_WORD_SIZE_BASE_SHIFT;
Jeff Kirsher5c3cad72008-06-27 10:59:33 -0700213
214 /* EEPROM access above 16k is unsupported */
215 if (size > 14)
216 size = 14;
Auke Kok9d5c8242008-01-24 02:22:38 -0800217 nvm->word_size = 1 << size;
218
Alexander Duycka0c98602009-07-23 18:10:43 +0000219 /* if 82576 then initialize mailbox parameters */
220 if (mac->type == e1000_82576)
221 igb_init_mbx_params_pf(hw);
222
Auke Kok9d5c8242008-01-24 02:22:38 -0800223 /* setup PHY parameters */
224 if (phy->media_type != e1000_media_type_copper) {
225 phy->type = e1000_phy_none;
226 return 0;
227 }
228
229 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
230 phy->reset_delay_us = 100;
231
232 /* PHY function pointers */
233 if (igb_sgmii_active_82575(hw)) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000234 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
235 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
236 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000237 } else if (hw->mac.type >= e1000_82580) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000238 phy->ops.reset = igb_phy_hw_reset;
239 phy->ops.read_reg = igb_read_phy_reg_82580;
240 phy->ops.write_reg = igb_write_phy_reg_82580;
Auke Kok9d5c8242008-01-24 02:22:38 -0800241 } else {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000242 phy->ops.reset = igb_phy_hw_reset;
243 phy->ops.read_reg = igb_read_phy_reg_igp;
244 phy->ops.write_reg = igb_write_phy_reg_igp;
Auke Kok9d5c8242008-01-24 02:22:38 -0800245 }
246
Alexander Duyck19e588e2009-07-07 13:01:55 +0000247 /* set lan id */
248 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
249 E1000_STATUS_FUNC_SHIFT;
250
Auke Kok9d5c8242008-01-24 02:22:38 -0800251 /* Set phy->phy_addr and phy->id. */
252 ret_val = igb_get_phy_id_82575(hw);
253 if (ret_val)
254 return ret_val;
255
256 /* Verify phy id and set remaining function pointers */
257 switch (phy->id) {
258 case M88E1111_I_PHY_ID:
259 phy->type = e1000_phy_m88;
260 phy->ops.get_phy_info = igb_get_phy_info_m88;
261 phy->ops.get_cable_length = igb_get_cable_length_m88;
262 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
263 break;
264 case IGP03E1000_E_PHY_ID:
265 phy->type = e1000_phy_igp_3;
266 phy->ops.get_phy_info = igb_get_phy_info_igp;
267 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
268 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
269 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
270 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
271 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000272 case I82580_I_PHY_ID:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000273 case I350_I_PHY_ID:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000274 phy->type = e1000_phy_82580;
275 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580;
276 phy->ops.get_cable_length = igb_get_cable_length_82580;
277 phy->ops.get_phy_info = igb_get_phy_info_82580;
278 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800279 default:
280 return -E1000_ERR_PHY;
281 }
282
283 return 0;
284}
285
286/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700287 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800288 * @hw: pointer to the HW structure
289 *
290 * Acquire access rights to the correct PHY. This is a
291 * function pointer entry point called by the api module.
292 **/
293static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
294{
Alexander Duyck008c3422009-10-05 06:32:07 +0000295 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800296
Alexander Duyck008c3422009-10-05 06:32:07 +0000297 if (hw->bus.func == E1000_FUNC_1)
298 mask = E1000_SWFW_PHY1_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800299
300 return igb_acquire_swfw_sync_82575(hw, mask);
301}
302
303/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700304 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800305 * @hw: pointer to the HW structure
306 *
307 * A wrapper to release access rights to the correct PHY. This is a
308 * function pointer entry point called by the api module.
309 **/
310static void igb_release_phy_82575(struct e1000_hw *hw)
311{
Alexander Duyck008c3422009-10-05 06:32:07 +0000312 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800313
Alexander Duyck008c3422009-10-05 06:32:07 +0000314 if (hw->bus.func == E1000_FUNC_1)
315 mask = E1000_SWFW_PHY1_SM;
316
Auke Kok9d5c8242008-01-24 02:22:38 -0800317 igb_release_swfw_sync_82575(hw, mask);
318}
319
320/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700321 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800322 * @hw: pointer to the HW structure
323 * @offset: register offset to be read
324 * @data: pointer to the read data
325 *
326 * Reads the PHY register at offset using the serial gigabit media independent
327 * interface and stores the retrieved information in data.
328 **/
329static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
330 u16 *data)
331{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000332 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800333
334 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700335 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000336 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800337 }
338
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000339 ret_val = hw->phy.ops.acquire(hw);
340 if (ret_val)
341 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800342
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000343 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800344
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000345 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800346
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000347out:
348 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800349}
350
351/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700352 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800353 * @hw: pointer to the HW structure
354 * @offset: register offset to write to
355 * @data: data to write at register offset
356 *
357 * Writes the data to PHY register at the offset using the serial gigabit
358 * media independent interface.
359 **/
360static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
361 u16 data)
362{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000363 s32 ret_val = -E1000_ERR_PARAM;
364
Auke Kok9d5c8242008-01-24 02:22:38 -0800365
366 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700367 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000368 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800369 }
370
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000371 ret_val = hw->phy.ops.acquire(hw);
372 if (ret_val)
373 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800374
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000375 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800376
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000377 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800378
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000379out:
380 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800381}
382
383/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700384 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800385 * @hw: pointer to the HW structure
386 *
Auke Kok652fff32008-06-27 11:00:18 -0700387 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800388 * sgmi interface.
389 **/
390static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
391{
392 struct e1000_phy_info *phy = &hw->phy;
393 s32 ret_val = 0;
394 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000395 u32 ctrl_ext;
Auke Kok9d5c8242008-01-24 02:22:38 -0800396
397 /*
398 * For SGMII PHYs, we try the list of possible addresses until
399 * we find one that works. For non-SGMII PHYs
400 * (e.g. integrated copper PHYs), an address of 1 should
401 * work. The result of this function should mean phy->phy_addr
402 * and phy->id are set correctly.
403 */
404 if (!(igb_sgmii_active_82575(hw))) {
405 phy->addr = 1;
406 ret_val = igb_get_phy_id(hw);
407 goto out;
408 }
409
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000410 /* Power on sgmii phy if it is disabled */
411 ctrl_ext = rd32(E1000_CTRL_EXT);
412 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
413 wrfl();
414 msleep(300);
415
Auke Kok9d5c8242008-01-24 02:22:38 -0800416 /*
417 * The address field in the I2CCMD register is 3 bits and 0 is invalid.
418 * Therefore, we need to test 1-7
419 */
420 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
421 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
422 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700423 hw_dbg("Vendor ID 0x%08X read at address %u\n",
424 phy_id, phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800425 /*
426 * At the time of this writing, The M88 part is
427 * the only supported SGMII PHY product.
428 */
429 if (phy_id == M88_VENDOR)
430 break;
431 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700432 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800433 }
434 }
435
436 /* A valid PHY type couldn't be found. */
437 if (phy->addr == 8) {
438 phy->addr = 0;
439 ret_val = -E1000_ERR_PHY;
440 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000441 } else {
442 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800443 }
444
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000445 /* restore previous sfp cage power state */
446 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800447
448out:
449 return ret_val;
450}
451
452/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700453 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800454 * @hw: pointer to the HW structure
455 *
456 * Resets the PHY using the serial gigabit media independent interface.
457 **/
458static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
459{
460 s32 ret_val;
461
462 /*
463 * This isn't a true "hard" reset, but is the only reset
464 * available to us at this time.
465 */
466
Auke Kok652fff32008-06-27 11:00:18 -0700467 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800468
469 /*
470 * SFP documentation requires the following to configure the SPF module
471 * to work on SGMII. No further documentation is given.
472 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000473 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800474 if (ret_val)
475 goto out;
476
477 ret_val = igb_phy_sw_reset(hw);
478
479out:
480 return ret_val;
481}
482
483/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700484 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800485 * @hw: pointer to the HW structure
486 * @active: true to enable LPLU, false to disable
487 *
488 * Sets the LPLU D0 state according to the active flag. When
489 * activating LPLU this function also disables smart speed
490 * and vice versa. LPLU will not be activated unless the
491 * device autonegotiation advertisement meets standards of
492 * either 10 or 10/100 or 10/100/1000 at all duplexes.
493 * This is a function pointer entry point only called by
494 * PHY setup routines.
495 **/
496static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
497{
498 struct e1000_phy_info *phy = &hw->phy;
499 s32 ret_val;
500 u16 data;
501
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000502 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800503 if (ret_val)
504 goto out;
505
506 if (active) {
507 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000508 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700509 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800510 if (ret_val)
511 goto out;
512
513 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000514 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700515 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800516 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000517 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700518 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800519 if (ret_val)
520 goto out;
521 } else {
522 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000523 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700524 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800525 /*
526 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
527 * during Dx states where the power conservation is most
528 * important. During driver activity we should enable
529 * SmartSpeed, so performance is maintained.
530 */
531 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000532 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700533 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800534 if (ret_val)
535 goto out;
536
537 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000538 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700539 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800540 if (ret_val)
541 goto out;
542 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000543 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700544 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800545 if (ret_val)
546 goto out;
547
548 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000549 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700550 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800551 if (ret_val)
552 goto out;
553 }
554 }
555
556out:
557 return ret_val;
558}
559
560/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700561 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800562 * @hw: pointer to the HW structure
563 *
Auke Kok652fff32008-06-27 11:00:18 -0700564 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -0800565 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
566 * Return successful if access grant bit set, else clear the request for
567 * EEPROM access and return -E1000_ERR_NVM (-1).
568 **/
569static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
570{
571 s32 ret_val;
572
573 ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
574 if (ret_val)
575 goto out;
576
577 ret_val = igb_acquire_nvm(hw);
578
579 if (ret_val)
580 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
581
582out:
583 return ret_val;
584}
585
586/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700587 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -0800588 * @hw: pointer to the HW structure
589 *
590 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
591 * then release the semaphores acquired.
592 **/
593static void igb_release_nvm_82575(struct e1000_hw *hw)
594{
595 igb_release_nvm(hw);
596 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
597}
598
599/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700600 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800601 * @hw: pointer to the HW structure
602 * @mask: specifies which semaphore to acquire
603 *
604 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
605 * will also specify which port we're acquiring the lock for.
606 **/
607static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
608{
609 u32 swfw_sync;
610 u32 swmask = mask;
611 u32 fwmask = mask << 16;
612 s32 ret_val = 0;
613 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
614
615 while (i < timeout) {
616 if (igb_get_hw_semaphore(hw)) {
617 ret_val = -E1000_ERR_SWFW_SYNC;
618 goto out;
619 }
620
621 swfw_sync = rd32(E1000_SW_FW_SYNC);
622 if (!(swfw_sync & (fwmask | swmask)))
623 break;
624
625 /*
626 * Firmware currently using resource (fwmask)
627 * or other software thread using resource (swmask)
628 */
629 igb_put_hw_semaphore(hw);
630 mdelay(5);
631 i++;
632 }
633
634 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -0700635 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800636 ret_val = -E1000_ERR_SWFW_SYNC;
637 goto out;
638 }
639
640 swfw_sync |= swmask;
641 wr32(E1000_SW_FW_SYNC, swfw_sync);
642
643 igb_put_hw_semaphore(hw);
644
645out:
646 return ret_val;
647}
648
649/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700650 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -0800651 * @hw: pointer to the HW structure
652 * @mask: specifies which semaphore to acquire
653 *
654 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
655 * will also specify which port we're releasing the lock for.
656 **/
657static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
658{
659 u32 swfw_sync;
660
661 while (igb_get_hw_semaphore(hw) != 0);
662 /* Empty */
663
664 swfw_sync = rd32(E1000_SW_FW_SYNC);
665 swfw_sync &= ~mask;
666 wr32(E1000_SW_FW_SYNC, swfw_sync);
667
668 igb_put_hw_semaphore(hw);
669}
670
671/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700672 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -0800673 * @hw: pointer to the HW structure
674 *
675 * Read the management control register for the config done bit for
676 * completion status. NOTE: silicon which is EEPROM-less will fail trying
677 * to read the config done bit, so an error is *ONLY* logged and returns
678 * 0. If we were to return with error, EEPROM-less silicon
679 * would not be able to be reset or change link.
680 **/
681static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
682{
683 s32 timeout = PHY_CFG_TIMEOUT;
684 s32 ret_val = 0;
685 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
686
687 if (hw->bus.func == 1)
688 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000689 else if (hw->bus.func == E1000_FUNC_2)
690 mask = E1000_NVM_CFG_DONE_PORT_2;
691 else if (hw->bus.func == E1000_FUNC_3)
692 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -0800693
694 while (timeout) {
695 if (rd32(E1000_EEMNGCTL) & mask)
696 break;
697 msleep(1);
698 timeout--;
699 }
700 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -0700701 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800702
703 /* If EEPROM is not marked present, init the PHY manually */
704 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
705 (hw->phy.type == e1000_phy_igp_3))
706 igb_phy_init_script_igp3(hw);
707
708 return ret_val;
709}
710
711/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700712 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -0800713 * @hw: pointer to the HW structure
714 *
715 * If sgmii is enabled, then use the pcs register to determine link, otherwise
716 * use the generic interface for determining link.
717 **/
718static s32 igb_check_for_link_82575(struct e1000_hw *hw)
719{
720 s32 ret_val;
721 u16 speed, duplex;
722
Alexander Duyck70d92f82009-10-05 06:31:47 +0000723 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800724 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -0700725 &duplex);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800726 /*
727 * Use this flag to determine if link needs to be checked or
728 * not. If we have link clear the flag so that we do not
729 * continue to check for link.
730 */
731 hw->mac.get_link_status = !hw->mac.serdes_has_link;
732 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800733 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -0800734 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800735
736 return ret_val;
737}
Alexander Duyck70d92f82009-10-05 06:31:47 +0000738
Auke Kok9d5c8242008-01-24 02:22:38 -0800739/**
Nick Nunley88a268c2010-02-17 01:01:59 +0000740 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
741 * @hw: pointer to the HW structure
742 **/
743void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
744{
745 u32 reg;
746
747
748 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
749 !igb_sgmii_active_82575(hw))
750 return;
751
752 /* Enable PCS to turn on link */
753 reg = rd32(E1000_PCS_CFG0);
754 reg |= E1000_PCS_CFG_PCS_EN;
755 wr32(E1000_PCS_CFG0, reg);
756
757 /* Power up the laser */
758 reg = rd32(E1000_CTRL_EXT);
759 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
760 wr32(E1000_CTRL_EXT, reg);
761
762 /* flush the write to verify completion */
763 wrfl();
764 msleep(1);
765}
766
767/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700768 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800769 * @hw: pointer to the HW structure
770 * @speed: stores the current speed
771 * @duplex: stores the current duplex
772 *
Auke Kok652fff32008-06-27 11:00:18 -0700773 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -0800774 * duplex, then store the values in the pointers provided.
775 **/
776static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
777 u16 *duplex)
778{
779 struct e1000_mac_info *mac = &hw->mac;
780 u32 pcs;
781
782 /* Set up defaults for the return values of this function */
783 mac->serdes_has_link = false;
784 *speed = 0;
785 *duplex = 0;
786
787 /*
788 * Read the PCS Status register for link state. For non-copper mode,
789 * the status register is not accurate. The PCS status register is
790 * used instead.
791 */
792 pcs = rd32(E1000_PCS_LSTAT);
793
794 /*
795 * The link up bit determines when link is up on autoneg. The sync ok
796 * gets set once both sides sync up and agree upon link. Stable link
797 * can be determined by checking for both link up and link sync ok
798 */
799 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
800 mac->serdes_has_link = true;
801
802 /* Detect and store PCS speed */
803 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
804 *speed = SPEED_1000;
805 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
806 *speed = SPEED_100;
807 } else {
808 *speed = SPEED_10;
809 }
810
811 /* Detect and store PCS duplex */
812 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
813 *duplex = FULL_DUPLEX;
814 } else {
815 *duplex = HALF_DUPLEX;
816 }
817 }
818
819 return 0;
820}
821
822/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000823 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -0700824 * @hw: pointer to the HW structure
825 *
826 * In the case of fiber serdes, shut down optics and PCS on driver unload
827 * when management pass thru is not enabled.
828 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000829void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -0700830{
831 u32 reg;
832
Nick Nunley53c992f2010-02-17 01:01:40 +0000833 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000834 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -0700835 return;
836
Nick Nunley53c992f2010-02-17 01:01:40 +0000837 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -0700838 /* Disable PCS to turn off link */
839 reg = rd32(E1000_PCS_CFG0);
840 reg &= ~E1000_PCS_CFG_PCS_EN;
841 wr32(E1000_PCS_CFG0, reg);
842
843 /* shutdown the laser */
844 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000845 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700846 wr32(E1000_CTRL_EXT, reg);
847
848 /* flush the write to verify completion */
849 wrfl();
850 msleep(1);
851 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800852}
853
854/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700855 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800856 * @hw: pointer to the HW structure
857 *
858 * This resets the hardware into a known state. This is a
859 * function pointer entry point called by the api module.
860 **/
861static s32 igb_reset_hw_82575(struct e1000_hw *hw)
862{
863 u32 ctrl, icr;
864 s32 ret_val;
865
866 /*
867 * Prevent the PCI-E bus from sticking if there is no TLP connection
868 * on the last TLP read/write transaction when MAC is reset.
869 */
870 ret_val = igb_disable_pcie_master(hw);
871 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700872 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800873
Alexander Duyck009bc062009-07-23 18:08:35 +0000874 /* set the completion timeout for interface */
875 ret_val = igb_set_pcie_completion_timeout(hw);
876 if (ret_val) {
877 hw_dbg("PCI-E Set completion timeout has failed.\n");
878 }
879
Auke Kok652fff32008-06-27 11:00:18 -0700880 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800881 wr32(E1000_IMC, 0xffffffff);
882
883 wr32(E1000_RCTL, 0);
884 wr32(E1000_TCTL, E1000_TCTL_PSP);
885 wrfl();
886
887 msleep(10);
888
889 ctrl = rd32(E1000_CTRL);
890
Auke Kok652fff32008-06-27 11:00:18 -0700891 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800892 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
893
894 ret_val = igb_get_auto_rd_done(hw);
895 if (ret_val) {
896 /*
897 * When auto config read does not complete, do not
898 * return with an error. This can happen in situations
899 * where there is no eeprom and prevents getting link.
900 */
Auke Kok652fff32008-06-27 11:00:18 -0700901 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800902 }
903
904 /* If EEPROM is not present, run manual init scripts */
905 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
906 igb_reset_init_script_82575(hw);
907
908 /* Clear any pending interrupt events. */
909 wr32(E1000_IMC, 0xffffffff);
910 icr = rd32(E1000_ICR);
911
Alexander Duyck5ac16652009-07-23 18:09:12 +0000912 /* Install any alternate MAC address into RAR0 */
913 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800914
915 return ret_val;
916}
917
918/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700919 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -0800920 * @hw: pointer to the HW structure
921 *
922 * This inits the hardware readying it for operation.
923 **/
924static s32 igb_init_hw_82575(struct e1000_hw *hw)
925{
926 struct e1000_mac_info *mac = &hw->mac;
927 s32 ret_val;
928 u16 i, rar_count = mac->rar_entry_count;
929
930 /* Initialize identification LED */
931 ret_val = igb_id_led_init(hw);
932 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700933 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 /* This is not fatal and we should not stop init due to this */
935 }
936
937 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -0700938 hw_dbg("Initializing the IEEE VLAN\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800939 igb_clear_vfta(hw);
940
941 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +0000942 igb_init_rx_addrs(hw, rar_count);
943
Auke Kok9d5c8242008-01-24 02:22:38 -0800944 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -0700945 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800946 for (i = 0; i < mac->mta_reg_count; i++)
947 array_wr32(E1000_MTA, i, 0);
948
Alexander Duyck68d480c42009-10-05 06:33:08 +0000949 /* Zero out the Unicast HASH table */
950 hw_dbg("Zeroing the UTA\n");
951 for (i = 0; i < mac->uta_reg_count; i++)
952 array_wr32(E1000_UTA, i, 0);
953
Auke Kok9d5c8242008-01-24 02:22:38 -0800954 /* Setup link and flow control */
955 ret_val = igb_setup_link(hw);
956
957 /*
958 * Clear all of the statistics registers (clear on read). It is
959 * important that we do this after we have tried to establish link
960 * because the symbol error count will increment wildly if there
961 * is no link.
962 */
963 igb_clear_hw_cntrs_82575(hw);
964
965 return ret_val;
966}
967
968/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700969 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 * @hw: pointer to the HW structure
971 *
972 * Configures the link for auto-neg or forced speed and duplex. Then we check
973 * for link, once link is established calls to configure collision distance
974 * and flow control are called.
975 **/
976static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
977{
Alexander Duyck12645a12009-07-23 18:08:16 +0000978 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -0800979 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800980
981 ctrl = rd32(E1000_CTRL);
982 ctrl |= E1000_CTRL_SLU;
983 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
984 wr32(E1000_CTRL, ctrl);
985
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000986 ret_val = igb_setup_serdes_link_82575(hw);
987 if (ret_val)
988 goto out;
989
990 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000991 /* allow time for SFP cage time to power up phy */
992 msleep(300);
993
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000994 ret_val = hw->phy.ops.reset(hw);
995 if (ret_val) {
996 hw_dbg("Error resetting the PHY.\n");
997 goto out;
998 }
999 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 switch (hw->phy.type) {
1001 case e1000_phy_m88:
1002 ret_val = igb_copper_link_setup_m88(hw);
1003 break;
1004 case e1000_phy_igp_3:
1005 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001006 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001007 case e1000_phy_82580:
1008 ret_val = igb_copper_link_setup_82580(hw);
1009 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 default:
1011 ret_val = -E1000_ERR_PHY;
1012 break;
1013 }
1014
1015 if (ret_val)
1016 goto out;
1017
Alexander Duyck81fadd82009-10-05 06:35:03 +00001018 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001019out:
1020 return ret_val;
1021}
1022
1023/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001024 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001025 * @hw: pointer to the HW structure
1026 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001027 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1028 * used on copper connections where the serialized gigabit media independent
1029 * interface (sgmii), or serdes fiber is being used. Configures the link
1030 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001031 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001032static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001033{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001034 u32 ctrl_ext, ctrl_reg, reg;
1035 bool pcs_autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001036
1037 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1038 !igb_sgmii_active_82575(hw))
1039 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001040
1041 /*
1042 * On the 82575, SerDes loopback mode persists until it is
1043 * explicitly turned off or a power cycle is performed. A read to
1044 * the register does not indicate its status. Therefore, we ensure
1045 * loopback mode is disabled during initialization.
1046 */
1047 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1048
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001049 /* power on the sfp cage if present */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001050 ctrl_ext = rd32(E1000_CTRL_EXT);
1051 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
1052 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001053
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001054 ctrl_reg = rd32(E1000_CTRL);
1055 ctrl_reg |= E1000_CTRL_SLU;
1056
1057 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1058 /* set both sw defined pins */
1059 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1060
1061 /* Set switch control to serdes energy detect */
1062 reg = rd32(E1000_CONNSW);
1063 reg |= E1000_CONNSW_ENRGSRC;
1064 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001065 }
1066
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001067 reg = rd32(E1000_PCS_LCTL);
1068
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001069 /* default pcs_autoneg to the same setting as mac autoneg */
1070 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001071
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001072 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1073 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1074 /* sgmii mode lets the phy handle forcing speed/duplex */
1075 pcs_autoneg = true;
1076 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001077 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001078 break;
1079 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1080 /* disable PCS autoneg and support parallel detect only */
1081 pcs_autoneg = false;
1082 default:
1083 /*
1084 * non-SGMII modes only supports a speed of 1000/Full for the
1085 * link so it is best to just force the MAC and let the pcs
1086 * link either autoneg or be forced to 1000/Full
1087 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001088 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1089 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001090
1091 /* set speed of 1000/Full if speed/duplex is forced */
1092 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1093 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001094 }
1095
1096 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001097
1098 /*
1099 * New SerDes mode allows for forcing speed or autonegotiating speed
1100 * at 1gb. Autoneg should be default set by most drivers. This is the
1101 * mode that will be compatible with older link partners and switches.
1102 * However, both are supported by the hardware and some drivers/tools.
1103 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001104 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1105 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1106
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001107 /*
1108 * We force flow control to prevent the CTRL register values from being
1109 * overwritten by the autonegotiated flow control values
1110 */
1111 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1112
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001113 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001115 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001116 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001117 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001118 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001119 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001120 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001121
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001122 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001123 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001124
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 wr32(E1000_PCS_LCTL, reg);
1126
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001127 if (!igb_sgmii_active_82575(hw))
1128 igb_force_mac_fc(hw);
1129
Auke Kok9d5c8242008-01-24 02:22:38 -08001130 return 0;
1131}
1132
1133/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001134 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001135 * @hw: pointer to the HW structure
1136 *
1137 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1138 * which can be enabled for use in the embedded applications. Simply
1139 * return the current state of the sgmii interface.
1140 **/
1141static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1142{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001143 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001144 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001145}
1146
1147/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001148 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001149 * @hw: pointer to the HW structure
1150 *
1151 * Inits recommended HW defaults after a reset when there is no EEPROM
1152 * detected. This is only for the 82575.
1153 **/
1154static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1155{
1156 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001157 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001158 /* SerDes configuration via SERDESCTRL */
1159 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1160 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1161 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1162 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1163
1164 /* CCM configuration via CCMCTL register */
1165 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1166 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1167
1168 /* PCIe lanes configuration */
1169 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1170 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1171 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1172 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1173
1174 /* PCIe PLL Configuration */
1175 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1176 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1177 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1178 }
1179
1180 return 0;
1181}
1182
1183/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001184 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 * @hw: pointer to the HW structure
1186 **/
1187static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1188{
1189 s32 ret_val = 0;
1190
Alexander Duyck22896632009-10-05 06:34:25 +00001191 /*
1192 * If there's an alternate MAC address place it in RAR0
1193 * so that it will override the Si installed default perm
1194 * address.
1195 */
1196 ret_val = igb_check_alt_mac_addr(hw);
1197 if (ret_val)
1198 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001199
Alexander Duyck22896632009-10-05 06:34:25 +00001200 ret_val = igb_read_mac_addr(hw);
1201
1202out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001203 return ret_val;
1204}
1205
1206/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001207 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1208 * @hw: pointer to the HW structure
1209 *
1210 * In the case of a PHY power down to save power, or to turn off link during a
1211 * driver unload, or wake on lan is not enabled, remove the link.
1212 **/
1213void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1214{
1215 /* If the management interface is not enabled, then power down */
1216 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1217 igb_power_down_phy_copper(hw);
1218
1219 return;
1220}
1221
1222/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001223 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001224 * @hw: pointer to the HW structure
1225 *
1226 * Clears the hardware counters by reading the counter registers.
1227 **/
1228static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1229{
Auke Kok9d5c8242008-01-24 02:22:38 -08001230 igb_clear_hw_cntrs_base(hw);
1231
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001232 rd32(E1000_PRC64);
1233 rd32(E1000_PRC127);
1234 rd32(E1000_PRC255);
1235 rd32(E1000_PRC511);
1236 rd32(E1000_PRC1023);
1237 rd32(E1000_PRC1522);
1238 rd32(E1000_PTC64);
1239 rd32(E1000_PTC127);
1240 rd32(E1000_PTC255);
1241 rd32(E1000_PTC511);
1242 rd32(E1000_PTC1023);
1243 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001244
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001245 rd32(E1000_ALGNERRC);
1246 rd32(E1000_RXERRC);
1247 rd32(E1000_TNCRS);
1248 rd32(E1000_CEXTERR);
1249 rd32(E1000_TSCTC);
1250 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001251
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001252 rd32(E1000_MGTPRC);
1253 rd32(E1000_MGTPDC);
1254 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001255
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001256 rd32(E1000_IAC);
1257 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001258
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001259 rd32(E1000_ICRXPTC);
1260 rd32(E1000_ICRXATC);
1261 rd32(E1000_ICTXPTC);
1262 rd32(E1000_ICTXATC);
1263 rd32(E1000_ICTXQEC);
1264 rd32(E1000_ICTXQMTC);
1265 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001266
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001267 rd32(E1000_CBTMPC);
1268 rd32(E1000_HTDPMC);
1269 rd32(E1000_CBRMPC);
1270 rd32(E1000_RPTHC);
1271 rd32(E1000_HGPTC);
1272 rd32(E1000_HTCBDPC);
1273 rd32(E1000_HGORCL);
1274 rd32(E1000_HGORCH);
1275 rd32(E1000_HGOTCL);
1276 rd32(E1000_HGOTCH);
1277 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001278
1279 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001280 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1281 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001282 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001283}
1284
Alexander Duyck662d7202008-06-27 11:00:29 -07001285/**
1286 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1287 * @hw: pointer to the HW structure
1288 *
1289 * After rx enable if managability is enabled then there is likely some
1290 * bad data at the start of the fifo and possibly in the DMA fifo. This
1291 * function clears the fifos and flushes any packets that came in as rx was
1292 * being enabled.
1293 **/
1294void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1295{
1296 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1297 int i, ms_wait;
1298
1299 if (hw->mac.type != e1000_82575 ||
1300 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1301 return;
1302
1303 /* Disable all RX queues */
1304 for (i = 0; i < 4; i++) {
1305 rxdctl[i] = rd32(E1000_RXDCTL(i));
1306 wr32(E1000_RXDCTL(i),
1307 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1308 }
1309 /* Poll all queues to verify they have shut down */
1310 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1311 msleep(1);
1312 rx_enabled = 0;
1313 for (i = 0; i < 4; i++)
1314 rx_enabled |= rd32(E1000_RXDCTL(i));
1315 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1316 break;
1317 }
1318
1319 if (ms_wait == 10)
1320 hw_dbg("Queue disable timed out after 10ms\n");
1321
1322 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1323 * incoming packets are rejected. Set enable and wait 2ms so that
1324 * any packet that was coming in as RCTL.EN was set is flushed
1325 */
1326 rfctl = rd32(E1000_RFCTL);
1327 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1328
1329 rlpml = rd32(E1000_RLPML);
1330 wr32(E1000_RLPML, 0);
1331
1332 rctl = rd32(E1000_RCTL);
1333 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1334 temp_rctl |= E1000_RCTL_LPE;
1335
1336 wr32(E1000_RCTL, temp_rctl);
1337 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1338 wrfl();
1339 msleep(2);
1340
1341 /* Enable RX queues that were previously enabled and restore our
1342 * previous state
1343 */
1344 for (i = 0; i < 4; i++)
1345 wr32(E1000_RXDCTL(i), rxdctl[i]);
1346 wr32(E1000_RCTL, rctl);
1347 wrfl();
1348
1349 wr32(E1000_RLPML, rlpml);
1350 wr32(E1000_RFCTL, rfctl);
1351
1352 /* Flush receive errors generated by workaround */
1353 rd32(E1000_ROC);
1354 rd32(E1000_RNBC);
1355 rd32(E1000_MPC);
1356}
1357
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001358/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001359 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1360 * @hw: pointer to the HW structure
1361 *
1362 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1363 * however the hardware default for these parts is 500us to 1ms which is less
1364 * than the 10ms recommended by the pci-e spec. To address this we need to
1365 * increase the value to either 10ms to 200ms for capability version 1 config,
1366 * or 16ms to 55ms for version 2.
1367 **/
1368static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1369{
1370 u32 gcr = rd32(E1000_GCR);
1371 s32 ret_val = 0;
1372 u16 pcie_devctl2;
1373
1374 /* only take action if timeout value is defaulted to 0 */
1375 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1376 goto out;
1377
1378 /*
1379 * if capababilities version is type 1 we can write the
1380 * timeout of 10ms to 200ms through the GCR register
1381 */
1382 if (!(gcr & E1000_GCR_CAP_VER2)) {
1383 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1384 goto out;
1385 }
1386
1387 /*
1388 * for version 2 capabilities we need to write the config space
1389 * directly in order to set the completion timeout value for
1390 * 16ms to 55ms
1391 */
1392 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1393 &pcie_devctl2);
1394 if (ret_val)
1395 goto out;
1396
1397 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
1398
1399 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1400 &pcie_devctl2);
1401out:
1402 /* disable completion timeout resend */
1403 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
1404
1405 wr32(E1000_GCR, gcr);
1406 return ret_val;
1407}
1408
1409/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001410 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1411 * @hw: pointer to the hardware struct
1412 * @enable: state to enter, either enabled or disabled
1413 *
1414 * enables/disables L2 switch loopback functionality.
1415 **/
1416void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1417{
1418 u32 dtxswc = rd32(E1000_DTXSWC);
1419
1420 if (enable)
1421 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1422 else
1423 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1424
1425 wr32(E1000_DTXSWC, dtxswc);
1426}
1427
1428/**
1429 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
1430 * @hw: pointer to the hardware struct
1431 * @enable: state to enter, either enabled or disabled
1432 *
1433 * enables/disables replication of packets across multiple pools.
1434 **/
1435void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1436{
1437 u32 vt_ctl = rd32(E1000_VT_CTL);
1438
1439 if (enable)
1440 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1441 else
1442 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1443
1444 wr32(E1000_VT_CTL, vt_ctl);
1445}
1446
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001447/**
1448 * igb_read_phy_reg_82580 - Read 82580 MDI control register
1449 * @hw: pointer to the HW structure
1450 * @offset: register offset to be read
1451 * @data: pointer to the read data
1452 *
1453 * Reads the MDI control register in the PHY at offset and stores the
1454 * information read to data.
1455 **/
1456static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
1457{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001458 s32 ret_val;
1459
1460
1461 ret_val = hw->phy.ops.acquire(hw);
1462 if (ret_val)
1463 goto out;
1464
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001465 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
1466
1467 hw->phy.ops.release(hw);
1468
1469out:
1470 return ret_val;
1471}
1472
1473/**
1474 * igb_write_phy_reg_82580 - Write 82580 MDI control register
1475 * @hw: pointer to the HW structure
1476 * @offset: register offset to write to
1477 * @data: data to write to register at offset
1478 *
1479 * Writes data to MDI control register in the PHY at offset.
1480 **/
1481static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
1482{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001483 s32 ret_val;
1484
1485
1486 ret_val = hw->phy.ops.acquire(hw);
1487 if (ret_val)
1488 goto out;
1489
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001490 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
1491
1492 hw->phy.ops.release(hw);
1493
1494out:
1495 return ret_val;
1496}
1497
1498/**
1499 * igb_reset_hw_82580 - Reset hardware
1500 * @hw: pointer to the HW structure
1501 *
1502 * This resets function or entire device (all ports, etc.)
1503 * to a known state.
1504 **/
1505static s32 igb_reset_hw_82580(struct e1000_hw *hw)
1506{
1507 s32 ret_val = 0;
1508 /* BH SW mailbox bit in SW_FW_SYNC */
1509 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
1510 u32 ctrl, icr;
1511 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
1512
1513
1514 hw->dev_spec._82575.global_device_reset = false;
1515
1516 /* Get current control state. */
1517 ctrl = rd32(E1000_CTRL);
1518
1519 /*
1520 * Prevent the PCI-E bus from sticking if there is no TLP connection
1521 * on the last TLP read/write transaction when MAC is reset.
1522 */
1523 ret_val = igb_disable_pcie_master(hw);
1524 if (ret_val)
1525 hw_dbg("PCI-E Master disable polling has failed.\n");
1526
1527 hw_dbg("Masking off all interrupts\n");
1528 wr32(E1000_IMC, 0xffffffff);
1529 wr32(E1000_RCTL, 0);
1530 wr32(E1000_TCTL, E1000_TCTL_PSP);
1531 wrfl();
1532
1533 msleep(10);
1534
1535 /* Determine whether or not a global dev reset is requested */
1536 if (global_device_reset &&
1537 igb_acquire_swfw_sync_82575(hw, swmbsw_mask))
1538 global_device_reset = false;
1539
1540 if (global_device_reset &&
1541 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
1542 ctrl |= E1000_CTRL_DEV_RST;
1543 else
1544 ctrl |= E1000_CTRL_RST;
1545
1546 wr32(E1000_CTRL, ctrl);
1547
1548 /* Add delay to insure DEV_RST has time to complete */
1549 if (global_device_reset)
1550 msleep(5);
1551
1552 ret_val = igb_get_auto_rd_done(hw);
1553 if (ret_val) {
1554 /*
1555 * When auto config read does not complete, do not
1556 * return with an error. This can happen in situations
1557 * where there is no eeprom and prevents getting link.
1558 */
1559 hw_dbg("Auto Read Done did not complete\n");
1560 }
1561
1562 /* If EEPROM is not present, run manual init scripts */
1563 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1564 igb_reset_init_script_82575(hw);
1565
1566 /* clear global device reset status bit */
1567 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
1568
1569 /* Clear any pending interrupt events. */
1570 wr32(E1000_IMC, 0xffffffff);
1571 icr = rd32(E1000_ICR);
1572
1573 /* Install any alternate MAC address into RAR0 */
1574 ret_val = igb_check_alt_mac_addr(hw);
1575
1576 /* Release semaphore */
1577 if (global_device_reset)
1578 igb_release_swfw_sync_82575(hw, swmbsw_mask);
1579
1580 return ret_val;
1581}
1582
1583/**
1584 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
1585 * @data: data received by reading RXPBS register
1586 *
1587 * The 82580 uses a table based approach for packet buffer allocation sizes.
1588 * This function converts the retrieved value into the correct table value
1589 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
1590 * 0x0 36 72 144 1 2 4 8 16
1591 * 0x8 35 70 140 rsv rsv rsv rsv rsv
1592 */
1593u16 igb_rxpbs_adjust_82580(u32 data)
1594{
1595 u16 ret_val = 0;
1596
1597 if (data < E1000_82580_RXPBS_TABLE_SIZE)
1598 ret_val = e1000_82580_rxpbs_table[data];
1599
1600 return ret_val;
1601}
1602
Auke Kok9d5c8242008-01-24 02:22:38 -08001603static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08001604 .init_hw = igb_init_hw_82575,
1605 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001606 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08001607 .read_mac_addr = igb_read_mac_addr_82575,
1608 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1609};
1610
1611static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001612 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001613 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001614 .release = igb_release_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08001615};
1616
1617static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001618 .acquire = igb_acquire_nvm_82575,
1619 .read = igb_read_nvm_eerd,
1620 .release = igb_release_nvm_82575,
1621 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08001622};
1623
1624const struct e1000_info e1000_82575_info = {
1625 .get_invariants = igb_get_invariants_82575,
1626 .mac_ops = &e1000_mac_ops_82575,
1627 .phy_ops = &e1000_phy_ops_82575,
1628 .nvm_ops = &e1000_nvm_ops_82575,
1629};
1630