blob: 168a5ee5e0ba767aa23264b5152183660bcc88d8 [file] [log] [blame]
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00001/* Intel(R) Gigabit Ethernet Linux driver
2 * Copyright(c) 2007-2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
18 *
19 * Contact Information:
20 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
21 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 */
Auke Kok9d5c8242008-01-24 02:22:38 -080023
24/* e1000_82575
25 * e1000_82576
26 */
27
Joe Perches82bbcde2011-10-21 20:04:09 +000028#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
Auke Kok9d5c8242008-01-24 02:22:38 -080030#include <linux/types.h>
Alexander Duyck2d064c02008-07-08 15:10:12 -070031#include <linux/if_ether.h>
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +000032#include <linux/i2c.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080033
34#include "e1000_mac.h"
35#include "e1000_82575.h"
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000036#include "e1000_i210.h"
Auke Kok9d5c8242008-01-24 02:22:38 -080037
38static s32 igb_get_invariants_82575(struct e1000_hw *);
39static s32 igb_acquire_phy_82575(struct e1000_hw *);
40static void igb_release_phy_82575(struct e1000_hw *);
41static s32 igb_acquire_nvm_82575(struct e1000_hw *);
42static void igb_release_nvm_82575(struct e1000_hw *);
43static s32 igb_check_for_link_82575(struct e1000_hw *);
44static s32 igb_get_cfg_done_82575(struct e1000_hw *);
45static s32 igb_init_hw_82575(struct e1000_hw *);
46static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
47static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000048static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
49static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080050static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000051static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080052static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
Carolyn Wybornyda02cde2012-03-04 03:26:26 +000053static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
54static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
Auke Kok9d5c8242008-01-24 02:22:38 -080055static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000056static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080057static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
58static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
59static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080060static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
61 u16 *);
62static s32 igb_get_phy_id_82575(struct e1000_hw *);
63static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
64static bool igb_sgmii_active_82575(struct e1000_hw *);
65static s32 igb_reset_init_script_82575(struct e1000_hw *);
66static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000067static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Alexander Duyck99870a72010-08-03 11:50:08 +000068static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080069static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
70static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080071static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
72static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +000073static const u16 e1000_82580_rxpbs_table[] = {
74 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
Alexander Duyckbb2ac472009-11-19 12:42:01 +000075
Nick Nunley4085f742010-07-26 13:15:06 +000076/**
77 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
78 * @hw: pointer to the HW structure
79 *
80 * Called to determine if the I2C pins are being used for I2C or as an
81 * external MDIO interface since the two options are mutually exclusive.
82 **/
83static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
84{
85 u32 reg = 0;
86 bool ext_mdio = false;
87
88 switch (hw->mac.type) {
89 case e1000_82575:
90 case e1000_82576:
91 reg = rd32(E1000_MDIC);
92 ext_mdio = !!(reg & E1000_MDIC_DEST);
93 break;
94 case e1000_82580:
95 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +000096 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000097 case e1000_i210:
98 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +000099 reg = rd32(E1000_MDICNFG);
100 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
101 break;
102 default:
103 break;
104 }
105 return ext_mdio;
106}
107
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000108/**
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000109 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
110 * @hw: pointer to the HW structure
111 *
112 * Poll the M88E1112 interfaces to see which interface achieved link.
113 */
114static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
115{
116 struct e1000_phy_info *phy = &hw->phy;
117 s32 ret_val;
118 u16 data;
119 u8 port = 0;
120
121 /* Check the copper medium. */
122 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
123 if (ret_val)
124 return ret_val;
125
126 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
127 if (ret_val)
128 return ret_val;
129
130 if (data & E1000_M88E1112_STATUS_LINK)
131 port = E1000_MEDIA_PORT_COPPER;
132
133 /* Check the other medium. */
134 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
135 if (ret_val)
136 return ret_val;
137
138 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
139 if (ret_val)
140 return ret_val;
141
142 /* reset page to 0 */
143 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
144 if (ret_val)
145 return ret_val;
146
147 if (data & E1000_M88E1112_STATUS_LINK)
148 port = E1000_MEDIA_PORT_OTHER;
149
150 /* Determine if a swap needs to happen. */
151 if (port && (hw->dev_spec._82575.media_port != port)) {
152 hw->dev_spec._82575.media_port = port;
153 hw->dev_spec._82575.media_changed = true;
154 } else {
155 ret_val = igb_check_for_link_82575(hw);
156 }
157
Todd Fujinaka23d87822014-06-04 07:12:15 +0000158 return 0;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000159}
160
161/**
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000162 * igb_init_phy_params_82575 - Init PHY func ptrs.
163 * @hw: pointer to the HW structure
164 **/
165static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
166{
167 struct e1000_phy_info *phy = &hw->phy;
168 s32 ret_val = 0;
169 u32 ctrl_ext;
170
171 if (hw->phy.media_type != e1000_media_type_copper) {
172 phy->type = e1000_phy_none;
173 goto out;
174 }
175
176 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
177 phy->reset_delay_us = 100;
178
179 ctrl_ext = rd32(E1000_CTRL_EXT);
180
181 if (igb_sgmii_active_82575(hw)) {
182 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
183 ctrl_ext |= E1000_CTRL_I2C_ENA;
184 } else {
185 phy->ops.reset = igb_phy_hw_reset;
186 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
187 }
188
189 wr32(E1000_CTRL_EXT, ctrl_ext);
190 igb_reset_mdicnfg_82580(hw);
191
192 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
193 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
194 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
195 } else {
196 switch (hw->mac.type) {
197 case e1000_82580:
198 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000199 case e1000_i354:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000200 phy->ops.read_reg = igb_read_phy_reg_82580;
201 phy->ops.write_reg = igb_write_phy_reg_82580;
202 break;
203 case e1000_i210:
204 case e1000_i211:
205 phy->ops.read_reg = igb_read_phy_reg_gs40g;
206 phy->ops.write_reg = igb_write_phy_reg_gs40g;
207 break;
208 default:
209 phy->ops.read_reg = igb_read_phy_reg_igp;
210 phy->ops.write_reg = igb_write_phy_reg_igp;
211 }
212 }
213
214 /* set lan id */
215 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
216 E1000_STATUS_FUNC_SHIFT;
217
218 /* Set phy->phy_addr and phy->id. */
219 ret_val = igb_get_phy_id_82575(hw);
220 if (ret_val)
221 return ret_val;
222
223 /* Verify phy id and set remaining function pointers */
224 switch (phy->id) {
Akeem G Abodunrin99af4722013-08-28 02:22:58 +0000225 case M88E1543_E_PHY_ID:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000226 case I347AT4_E_PHY_ID:
227 case M88E1112_E_PHY_ID:
228 case M88E1111_I_PHY_ID:
229 phy->type = e1000_phy_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000230 phy->ops.check_polarity = igb_check_polarity_m88;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000231 phy->ops.get_phy_info = igb_get_phy_info_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000232 if (phy->id != M88E1111_I_PHY_ID)
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000233 phy->ops.get_cable_length =
234 igb_get_cable_length_m88_gen2;
235 else
236 phy->ops.get_cable_length = igb_get_cable_length_m88;
237 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000238 /* Check if this PHY is confgured for media swap. */
239 if (phy->id == M88E1112_E_PHY_ID) {
240 u16 data;
241
242 ret_val = phy->ops.write_reg(hw,
243 E1000_M88E1112_PAGE_ADDR,
244 2);
245 if (ret_val)
246 goto out;
247
248 ret_val = phy->ops.read_reg(hw,
249 E1000_M88E1112_MAC_CTRL_1,
250 &data);
251 if (ret_val)
252 goto out;
253
254 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
255 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
256 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
257 data == E1000_M88E1112_AUTO_COPPER_BASEX)
258 hw->mac.ops.check_for_link =
259 igb_check_for_link_media_swap;
260 }
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000261 break;
262 case IGP03E1000_E_PHY_ID:
263 phy->type = e1000_phy_igp_3;
264 phy->ops.get_phy_info = igb_get_phy_info_igp;
265 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
266 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
267 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
268 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
269 break;
270 case I82580_I_PHY_ID:
271 case I350_I_PHY_ID:
272 phy->type = e1000_phy_82580;
273 phy->ops.force_speed_duplex =
274 igb_phy_force_speed_duplex_82580;
275 phy->ops.get_cable_length = igb_get_cable_length_82580;
276 phy->ops.get_phy_info = igb_get_phy_info_82580;
277 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
278 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
279 break;
280 case I210_I_PHY_ID:
281 phy->type = e1000_phy_i210;
282 phy->ops.check_polarity = igb_check_polarity_m88;
283 phy->ops.get_phy_info = igb_get_phy_info_m88;
284 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
285 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
286 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
287 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
288 break;
289 default:
290 ret_val = -E1000_ERR_PHY;
291 goto out;
292 }
293
294out:
295 return ret_val;
296}
297
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000298/**
299 * igb_init_nvm_params_82575 - Init NVM func ptrs.
300 * @hw: pointer to the HW structure
301 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000302static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000303{
304 struct e1000_nvm_info *nvm = &hw->nvm;
305 u32 eecd = rd32(E1000_EECD);
306 u16 size;
307
308 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
309 E1000_EECD_SIZE_EX_SHIFT);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000310
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000311 /* Added to a constant, "size" becomes the left-shift value
312 * for setting word_size.
313 */
314 size += NVM_WORD_SIZE_BASE_SHIFT;
315
316 /* Just in case size is out of range, cap it to the largest
317 * EEPROM size supported
318 */
319 if (size > 15)
320 size = 15;
321
322 nvm->word_size = 1 << size;
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000323 nvm->opcode_bits = 8;
324 nvm->delay_usec = 1;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000325
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000326 switch (nvm->override) {
327 case e1000_nvm_override_spi_large:
328 nvm->page_size = 32;
329 nvm->address_bits = 16;
330 break;
331 case e1000_nvm_override_spi_small:
332 nvm->page_size = 8;
333 nvm->address_bits = 8;
334 break;
335 default:
336 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
337 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
338 16 : 8;
339 break;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000340 }
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000341 if (nvm->word_size == (1 << 15))
342 nvm->page_size = 128;
343
344 nvm->type = e1000_nvm_eeprom_spi;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000345
346 /* NVM Function Pointers */
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000347 nvm->ops.acquire = igb_acquire_nvm_82575;
348 nvm->ops.release = igb_release_nvm_82575;
349 nvm->ops.write = igb_write_nvm_spi;
350 nvm->ops.validate = igb_validate_nvm_checksum;
351 nvm->ops.update = igb_update_nvm_checksum;
352 if (nvm->word_size < (1 << 15))
353 nvm->ops.read = igb_read_nvm_eerd;
354 else
355 nvm->ops.read = igb_read_nvm_spi;
356
357 /* override generic family function pointers for specific descendants */
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000358 switch (hw->mac.type) {
359 case e1000_82580:
360 nvm->ops.validate = igb_validate_nvm_checksum_82580;
361 nvm->ops.update = igb_update_nvm_checksum_82580;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000362 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000363 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000364 case e1000_i350:
365 nvm->ops.validate = igb_validate_nvm_checksum_i350;
366 nvm->ops.update = igb_update_nvm_checksum_i350;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000367 break;
368 default:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000369 break;
370 }
371
372 return 0;
373}
374
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000375/**
376 * igb_init_mac_params_82575 - Init MAC func ptrs.
377 * @hw: pointer to the HW structure
378 **/
379static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
380{
381 struct e1000_mac_info *mac = &hw->mac;
382 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
383
384 /* Set mta register count */
385 mac->mta_reg_count = 128;
386 /* Set rar entry count */
387 switch (mac->type) {
388 case e1000_82576:
389 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
390 break;
391 case e1000_82580:
392 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
393 break;
394 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000395 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000396 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
397 break;
398 default:
399 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
400 break;
401 }
402 /* reset */
403 if (mac->type >= e1000_82580)
404 mac->ops.reset_hw = igb_reset_hw_82580;
405 else
406 mac->ops.reset_hw = igb_reset_hw_82575;
407
408 if (mac->type >= e1000_i210) {
409 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
410 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
411
412 } else {
413 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
414 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
415 }
416
417 /* Set if part includes ASF firmware */
418 mac->asf_firmware_present = true;
419 /* Set if manageability features are enabled. */
420 mac->arc_subsystem_valid =
421 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
422 ? true : false;
423 /* enable EEE on i350 parts and later parts */
424 if (mac->type >= e1000_i350)
425 dev_spec->eee_disable = false;
426 else
427 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000428 /* Allow a single clear of the SW semaphore on I210 and newer */
429 if (mac->type >= e1000_i210)
430 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000431 /* physical interface link setup */
432 mac->ops.setup_physical_interface =
433 (hw->phy.media_type == e1000_media_type_copper)
434 ? igb_setup_copper_link_82575
435 : igb_setup_serdes_link_82575;
436
Carolyn Wyborny56cec242013-10-17 05:36:26 +0000437 if (mac->type == e1000_82580) {
438 switch (hw->device_id) {
439 /* feature not supported on these id's */
440 case E1000_DEV_ID_DH89XXCC_SGMII:
441 case E1000_DEV_ID_DH89XXCC_SERDES:
442 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
443 case E1000_DEV_ID_DH89XXCC_SFP:
444 break;
445 default:
446 hw->dev_spec._82575.mas_capable = true;
447 break;
448 }
449 }
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000450 return 0;
451}
452
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000453/**
454 * igb_set_sfp_media_type_82575 - derives SFP module media type.
455 * @hw: pointer to the HW structure
456 *
457 * The media type is chosen based on SFP module.
458 * compatibility flags retrieved from SFP ID EEPROM.
459 **/
460static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
461{
462 s32 ret_val = E1000_ERR_CONFIG;
463 u32 ctrl_ext = 0;
464 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
465 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
466 u8 tranceiver_type = 0;
467 s32 timeout = 3;
468
469 /* Turn I2C interface ON and power on sfp cage */
470 ctrl_ext = rd32(E1000_CTRL_EXT);
471 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
472 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
473
474 wrfl();
475
476 /* Read SFP module data */
477 while (timeout) {
478 ret_val = igb_read_sfp_data_byte(hw,
479 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
480 &tranceiver_type);
481 if (ret_val == 0)
482 break;
483 msleep(100);
484 timeout--;
485 }
486 if (ret_val != 0)
487 goto out;
488
489 ret_val = igb_read_sfp_data_byte(hw,
490 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
491 (u8 *)eth_flags);
492 if (ret_val != 0)
493 goto out;
494
495 /* Check if there is some SFP module plugged and powered */
496 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
497 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
498 dev_spec->module_plugged = true;
499 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
500 hw->phy.media_type = e1000_media_type_internal_serdes;
501 } else if (eth_flags->e100_base_fx) {
502 dev_spec->sgmii_active = true;
503 hw->phy.media_type = e1000_media_type_internal_serdes;
504 } else if (eth_flags->e1000_base_t) {
505 dev_spec->sgmii_active = true;
506 hw->phy.media_type = e1000_media_type_copper;
507 } else {
508 hw->phy.media_type = e1000_media_type_unknown;
509 hw_dbg("PHY module has not been recognized\n");
510 goto out;
511 }
512 } else {
513 hw->phy.media_type = e1000_media_type_unknown;
514 }
515 ret_val = 0;
516out:
517 /* Restore I2C interface setting */
518 wr32(E1000_CTRL_EXT, ctrl_ext);
519 return ret_val;
520}
521
Auke Kok9d5c8242008-01-24 02:22:38 -0800522static s32 igb_get_invariants_82575(struct e1000_hw *hw)
523{
Auke Kok9d5c8242008-01-24 02:22:38 -0800524 struct e1000_mac_info *mac = &hw->mac;
Carolyn Wybornyc4917c62014-04-11 01:45:48 +0000525 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800527 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000528 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800529
530 switch (hw->device_id) {
531 case E1000_DEV_ID_82575EB_COPPER:
532 case E1000_DEV_ID_82575EB_FIBER_SERDES:
533 case E1000_DEV_ID_82575GB_QUAD_COPPER:
534 mac->type = e1000_82575;
535 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700536 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000537 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000538 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700539 case E1000_DEV_ID_82576_FIBER:
540 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000541 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000542 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000543 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700544 mac->type = e1000_82576;
545 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000546 case E1000_DEV_ID_82580_COPPER:
547 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000548 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000549 case E1000_DEV_ID_82580_SERDES:
550 case E1000_DEV_ID_82580_SGMII:
551 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000552 case E1000_DEV_ID_DH89XXCC_SGMII:
553 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000554 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
555 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000556 mac->type = e1000_82580;
557 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000558 case E1000_DEV_ID_I350_COPPER:
559 case E1000_DEV_ID_I350_FIBER:
560 case E1000_DEV_ID_I350_SERDES:
561 case E1000_DEV_ID_I350_SGMII:
562 mac->type = e1000_i350;
563 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000564 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000565 case E1000_DEV_ID_I210_FIBER:
566 case E1000_DEV_ID_I210_SERDES:
567 case E1000_DEV_ID_I210_SGMII:
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +0000568 case E1000_DEV_ID_I210_COPPER_FLASHLESS:
569 case E1000_DEV_ID_I210_SERDES_FLASHLESS:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000570 mac->type = e1000_i210;
571 break;
572 case E1000_DEV_ID_I211_COPPER:
573 mac->type = e1000_i211;
574 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000575 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
576 case E1000_DEV_ID_I354_SGMII:
577 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
578 mac->type = e1000_i354;
579 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800580 default:
581 return -E1000_ERR_MAC_INIT;
582 break;
583 }
584
Auke Kok9d5c8242008-01-24 02:22:38 -0800585 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000586 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800587 * based on the EEPROM. We cannot rely upon device ID. There
588 * is no distinguishable difference between fiber and internal
589 * SerDes mode on the 82575. There can be an external PHY attached
590 * on the SGMII interface. For this, we'll set sgmii_active to true.
591 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000592 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800593 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000594 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800595
596 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000597
598 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
599 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000600 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000601 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000602 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000603 case E1000_CTRL_EXT_LINK_MODE_SGMII:
604 /* Get phy control interface type set (MDIO vs. I2C)*/
605 if (igb_sgmii_uses_mdio_82575(hw)) {
606 hw->phy.media_type = e1000_media_type_copper;
607 dev_spec->sgmii_active = true;
608 break;
609 }
610 /* fall through for I2C based SGMII */
611 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
612 /* read media type from SFP EEPROM */
613 ret_val = igb_set_sfp_media_type_82575(hw);
614 if ((ret_val != 0) ||
615 (hw->phy.media_type == e1000_media_type_unknown)) {
616 /* If media type was not identified then return media
617 * type defined by the CTRL_EXT settings.
618 */
619 hw->phy.media_type = e1000_media_type_internal_serdes;
620
621 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
622 hw->phy.media_type = e1000_media_type_copper;
623 dev_spec->sgmii_active = true;
624 }
625
626 break;
627 }
628
629 /* do not change link mode for 100BaseFX */
630 if (dev_spec->eth_flags.e100_base_fx)
631 break;
632
633 /* change current link mode setting */
634 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
635
636 if (hw->phy.media_type == e1000_media_type_copper)
637 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
638 else
639 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
640
641 wr32(E1000_CTRL_EXT, ctrl_ext);
642
643 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000644 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000645 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800646 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000647
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000648 /* mac initialization and operations */
649 ret_val = igb_init_mac_params_82575(hw);
650 if (ret_val)
651 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800652
653 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000654 ret_val = igb_init_nvm_params_82575(hw);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000655 switch (hw->mac.type) {
656 case e1000_i210:
657 case e1000_i211:
658 ret_val = igb_init_nvm_params_i210(hw);
659 break;
660 default:
661 break;
662 }
663
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000664 if (ret_val)
665 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800666
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000667 /* if part supports SR-IOV then initialize mailbox parameters */
668 switch (mac->type) {
669 case e1000_82576:
670 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000671 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000672 break;
673 default:
674 break;
675 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000676
Auke Kok9d5c8242008-01-24 02:22:38 -0800677 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000678 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800679
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000680out:
681 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800682}
683
684/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700685 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800686 * @hw: pointer to the HW structure
687 *
688 * Acquire access rights to the correct PHY. This is a
689 * function pointer entry point called by the api module.
690 **/
691static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
692{
Alexander Duyck008c3422009-10-05 06:32:07 +0000693 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800694
Alexander Duyck008c3422009-10-05 06:32:07 +0000695 if (hw->bus.func == E1000_FUNC_1)
696 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000697 else if (hw->bus.func == E1000_FUNC_2)
698 mask = E1000_SWFW_PHY2_SM;
699 else if (hw->bus.func == E1000_FUNC_3)
700 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800701
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000702 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800703}
704
705/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700706 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800707 * @hw: pointer to the HW structure
708 *
709 * A wrapper to release access rights to the correct PHY. This is a
710 * function pointer entry point called by the api module.
711 **/
712static void igb_release_phy_82575(struct e1000_hw *hw)
713{
Alexander Duyck008c3422009-10-05 06:32:07 +0000714 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800715
Alexander Duyck008c3422009-10-05 06:32:07 +0000716 if (hw->bus.func == E1000_FUNC_1)
717 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000718 else if (hw->bus.func == E1000_FUNC_2)
719 mask = E1000_SWFW_PHY2_SM;
720 else if (hw->bus.func == E1000_FUNC_3)
721 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000722
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000723 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800724}
725
726/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700727 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800728 * @hw: pointer to the HW structure
729 * @offset: register offset to be read
730 * @data: pointer to the read data
731 *
732 * Reads the PHY register at offset using the serial gigabit media independent
733 * interface and stores the retrieved information in data.
734 **/
735static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
736 u16 *data)
737{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000738 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800739
740 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700741 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000742 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800743 }
744
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000745 ret_val = hw->phy.ops.acquire(hw);
746 if (ret_val)
747 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800748
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000749 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800750
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000751 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800752
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000753out:
754 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800755}
756
757/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700758 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800759 * @hw: pointer to the HW structure
760 * @offset: register offset to write to
761 * @data: data to write at register offset
762 *
763 * Writes the data to PHY register at the offset using the serial gigabit
764 * media independent interface.
765 **/
766static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
767 u16 data)
768{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000769 s32 ret_val = -E1000_ERR_PARAM;
770
Auke Kok9d5c8242008-01-24 02:22:38 -0800771
772 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700773 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000774 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 }
776
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000777 ret_val = hw->phy.ops.acquire(hw);
778 if (ret_val)
779 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800780
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000781 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800782
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000783 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800784
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000785out:
786 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800787}
788
789/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700790 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800791 * @hw: pointer to the HW structure
792 *
Auke Kok652fff32008-06-27 11:00:18 -0700793 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800794 * sgmi interface.
795 **/
796static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
797{
798 struct e1000_phy_info *phy = &hw->phy;
799 s32 ret_val = 0;
800 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000801 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000802 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800803
Carolyn Wybornybb1d18d2013-09-10 11:57:16 -0700804 /* Extra read required for some PHY's on i354 */
805 if (hw->mac.type == e1000_i354)
806 igb_get_phy_id(hw);
807
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000808 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800809 * we find one that works. For non-SGMII PHYs
810 * (e.g. integrated copper PHYs), an address of 1 should
811 * work. The result of this function should mean phy->phy_addr
812 * and phy->id are set correctly.
813 */
814 if (!(igb_sgmii_active_82575(hw))) {
815 phy->addr = 1;
816 ret_val = igb_get_phy_id(hw);
817 goto out;
818 }
819
Nick Nunley4085f742010-07-26 13:15:06 +0000820 if (igb_sgmii_uses_mdio_82575(hw)) {
821 switch (hw->mac.type) {
822 case e1000_82575:
823 case e1000_82576:
824 mdic = rd32(E1000_MDIC);
825 mdic &= E1000_MDIC_PHY_MASK;
826 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
827 break;
828 case e1000_82580:
829 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000830 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000831 case e1000_i210:
832 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000833 mdic = rd32(E1000_MDICNFG);
834 mdic &= E1000_MDICNFG_PHY_MASK;
835 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
836 break;
837 default:
838 ret_val = -E1000_ERR_PHY;
839 goto out;
Nick Nunley4085f742010-07-26 13:15:06 +0000840 }
841 ret_val = igb_get_phy_id(hw);
842 goto out;
843 }
844
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000845 /* Power on sgmii phy if it is disabled */
846 ctrl_ext = rd32(E1000_CTRL_EXT);
847 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
848 wrfl();
849 msleep(300);
850
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000851 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800852 * Therefore, we need to test 1-7
853 */
854 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
855 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
856 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700857 hw_dbg("Vendor ID 0x%08X read at address %u\n",
858 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000859 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800860 * the only supported SGMII PHY product.
861 */
862 if (phy_id == M88_VENDOR)
863 break;
864 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700865 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800866 }
867 }
868
869 /* A valid PHY type couldn't be found. */
870 if (phy->addr == 8) {
871 phy->addr = 0;
872 ret_val = -E1000_ERR_PHY;
873 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000874 } else {
875 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800876 }
877
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000878 /* restore previous sfp cage power state */
879 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800880
881out:
882 return ret_val;
883}
884
885/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700886 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 * @hw: pointer to the HW structure
888 *
889 * Resets the PHY using the serial gigabit media independent interface.
890 **/
891static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
892{
893 s32 ret_val;
894
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000895 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800896 * available to us at this time.
897 */
898
Auke Kok652fff32008-06-27 11:00:18 -0700899 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800900
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000901 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800902 * to work on SGMII. No further documentation is given.
903 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000904 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800905 if (ret_val)
906 goto out;
907
908 ret_val = igb_phy_sw_reset(hw);
909
910out:
911 return ret_val;
912}
913
914/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700915 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800916 * @hw: pointer to the HW structure
917 * @active: true to enable LPLU, false to disable
918 *
919 * Sets the LPLU D0 state according to the active flag. When
920 * activating LPLU this function also disables smart speed
921 * and vice versa. LPLU will not be activated unless the
922 * device autonegotiation advertisement meets standards of
923 * either 10 or 10/100 or 10/100/1000 at all duplexes.
924 * This is a function pointer entry point only called by
925 * PHY setup routines.
926 **/
927static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
928{
929 struct e1000_phy_info *phy = &hw->phy;
930 s32 ret_val;
931 u16 data;
932
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000933 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 if (ret_val)
935 goto out;
936
937 if (active) {
938 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000939 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700940 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800941 if (ret_val)
942 goto out;
943
944 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000945 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700946 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800947 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000948 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700949 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800950 if (ret_val)
951 goto out;
952 } else {
953 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000954 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700955 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000956 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -0800957 * during Dx states where the power conservation is most
958 * important. During driver activity we should enable
959 * SmartSpeed, so performance is maintained.
960 */
961 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000962 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700963 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800964 if (ret_val)
965 goto out;
966
967 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000968 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700969 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 if (ret_val)
971 goto out;
972 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000973 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700974 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800975 if (ret_val)
976 goto out;
977
978 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000979 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700980 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800981 if (ret_val)
982 goto out;
983 }
984 }
985
986out:
987 return ret_val;
988}
989
990/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000991 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
992 * @hw: pointer to the HW structure
993 * @active: true to enable LPLU, false to disable
994 *
995 * Sets the LPLU D0 state according to the active flag. When
996 * activating LPLU this function also disables smart speed
997 * and vice versa. LPLU will not be activated unless the
998 * device autonegotiation advertisement meets standards of
999 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1000 * This is a function pointer entry point only called by
1001 * PHY setup routines.
1002 **/
1003static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
1004{
1005 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001006 u16 data;
1007
1008 data = rd32(E1000_82580_PHY_POWER_MGMT);
1009
1010 if (active) {
1011 data |= E1000_82580_PM_D0_LPLU;
1012
1013 /* When LPLU is enabled, we should disable SmartSpeed */
1014 data &= ~E1000_82580_PM_SPD;
1015 } else {
1016 data &= ~E1000_82580_PM_D0_LPLU;
1017
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001018 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001019 * during Dx states where the power conservation is most
1020 * important. During driver activity we should enable
1021 * SmartSpeed, so performance is maintained.
1022 */
1023 if (phy->smart_speed == e1000_smart_speed_on)
1024 data |= E1000_82580_PM_SPD;
1025 else if (phy->smart_speed == e1000_smart_speed_off)
1026 data &= ~E1000_82580_PM_SPD; }
1027
1028 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001029 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001030}
1031
1032/**
1033 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1034 * @hw: pointer to the HW structure
1035 * @active: boolean used to enable/disable lplu
1036 *
1037 * Success returns 0, Failure returns 1
1038 *
1039 * The low power link up (lplu) state is set to the power management level D3
1040 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1041 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1042 * is used during Dx states where the power conservation is most important.
1043 * During driver activity, SmartSpeed should be enabled so performance is
1044 * maintained.
1045 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +00001046static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001047{
1048 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001049 u16 data;
1050
1051 data = rd32(E1000_82580_PHY_POWER_MGMT);
1052
1053 if (!active) {
1054 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001055 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001056 * during Dx states where the power conservation is most
1057 * important. During driver activity we should enable
1058 * SmartSpeed, so performance is maintained.
1059 */
1060 if (phy->smart_speed == e1000_smart_speed_on)
1061 data |= E1000_82580_PM_SPD;
1062 else if (phy->smart_speed == e1000_smart_speed_off)
1063 data &= ~E1000_82580_PM_SPD;
1064 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1065 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1066 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1067 data |= E1000_82580_PM_D3_LPLU;
1068 /* When LPLU is enabled, we should disable SmartSpeed */
1069 data &= ~E1000_82580_PM_SPD;
1070 }
1071
1072 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001073 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001074}
1075
1076/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001077 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001078 * @hw: pointer to the HW structure
1079 *
Auke Kok652fff32008-06-27 11:00:18 -07001080 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001081 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1082 * Return successful if access grant bit set, else clear the request for
1083 * EEPROM access and return -E1000_ERR_NVM (-1).
1084 **/
1085static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1086{
1087 s32 ret_val;
1088
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001089 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001090 if (ret_val)
1091 goto out;
1092
1093 ret_val = igb_acquire_nvm(hw);
1094
1095 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001096 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001097
1098out:
1099 return ret_val;
1100}
1101
1102/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001103 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001104 * @hw: pointer to the HW structure
1105 *
1106 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1107 * then release the semaphores acquired.
1108 **/
1109static void igb_release_nvm_82575(struct e1000_hw *hw)
1110{
1111 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001112 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001113}
1114
1115/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001116 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001117 * @hw: pointer to the HW structure
1118 * @mask: specifies which semaphore to acquire
1119 *
1120 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1121 * will also specify which port we're acquiring the lock for.
1122 **/
1123static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1124{
1125 u32 swfw_sync;
1126 u32 swmask = mask;
1127 u32 fwmask = mask << 16;
1128 s32 ret_val = 0;
1129 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
1130
1131 while (i < timeout) {
1132 if (igb_get_hw_semaphore(hw)) {
1133 ret_val = -E1000_ERR_SWFW_SYNC;
1134 goto out;
1135 }
1136
1137 swfw_sync = rd32(E1000_SW_FW_SYNC);
1138 if (!(swfw_sync & (fwmask | swmask)))
1139 break;
1140
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001141 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001142 * or other software thread using resource (swmask)
1143 */
1144 igb_put_hw_semaphore(hw);
1145 mdelay(5);
1146 i++;
1147 }
1148
1149 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001150 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001151 ret_val = -E1000_ERR_SWFW_SYNC;
1152 goto out;
1153 }
1154
1155 swfw_sync |= swmask;
1156 wr32(E1000_SW_FW_SYNC, swfw_sync);
1157
1158 igb_put_hw_semaphore(hw);
1159
1160out:
1161 return ret_val;
1162}
1163
1164/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001165 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001166 * @hw: pointer to the HW structure
1167 * @mask: specifies which semaphore to acquire
1168 *
1169 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1170 * will also specify which port we're releasing the lock for.
1171 **/
1172static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1173{
1174 u32 swfw_sync;
1175
Carolyn Wybornybed83e92014-04-11 01:45:55 +00001176 while (igb_get_hw_semaphore(hw) != 0)
1177 ; /* Empty */
Auke Kok9d5c8242008-01-24 02:22:38 -08001178
1179 swfw_sync = rd32(E1000_SW_FW_SYNC);
1180 swfw_sync &= ~mask;
1181 wr32(E1000_SW_FW_SYNC, swfw_sync);
1182
1183 igb_put_hw_semaphore(hw);
1184}
1185
1186/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001187 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001188 * @hw: pointer to the HW structure
1189 *
1190 * Read the management control register for the config done bit for
1191 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1192 * to read the config done bit, so an error is *ONLY* logged and returns
1193 * 0. If we were to return with error, EEPROM-less silicon
1194 * would not be able to be reset or change link.
1195 **/
1196static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1197{
1198 s32 timeout = PHY_CFG_TIMEOUT;
Auke Kok9d5c8242008-01-24 02:22:38 -08001199 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1200
1201 if (hw->bus.func == 1)
1202 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001203 else if (hw->bus.func == E1000_FUNC_2)
1204 mask = E1000_NVM_CFG_DONE_PORT_2;
1205 else if (hw->bus.func == E1000_FUNC_3)
1206 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001207
1208 while (timeout) {
1209 if (rd32(E1000_EEMNGCTL) & mask)
1210 break;
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001211 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001212 timeout--;
1213 }
1214 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001215 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001216
1217 /* If EEPROM is not marked present, init the PHY manually */
1218 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1219 (hw->phy.type == e1000_phy_igp_3))
1220 igb_phy_init_script_igp3(hw);
1221
Todd Fujinaka23d87822014-06-04 07:12:15 +00001222 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001223}
1224
1225/**
Akeem G Abodunrinf6878e32013-08-28 02:23:09 +00001226 * igb_get_link_up_info_82575 - Get link speed/duplex info
1227 * @hw: pointer to the HW structure
1228 * @speed: stores the current speed
1229 * @duplex: stores the current duplex
1230 *
1231 * This is a wrapper function, if using the serial gigabit media independent
1232 * interface, use PCS to retrieve the link speed and duplex information.
1233 * Otherwise, use the generic function to get the link speed and duplex info.
1234 **/
1235static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1236 u16 *duplex)
1237{
1238 s32 ret_val;
1239
1240 if (hw->phy.media_type != e1000_media_type_copper)
1241 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
1242 duplex);
1243 else
1244 ret_val = igb_get_speed_and_duplex_copper(hw, speed,
1245 duplex);
1246
1247 return ret_val;
1248}
1249
1250/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001251 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001252 * @hw: pointer to the HW structure
1253 *
1254 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1255 * use the generic interface for determining link.
1256 **/
1257static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1258{
1259 s32 ret_val;
1260 u16 speed, duplex;
1261
Alexander Duyck70d92f82009-10-05 06:31:47 +00001262 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001263 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001264 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001265 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001266 * not. If we have link clear the flag so that we do not
1267 * continue to check for link.
1268 */
1269 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001270
1271 /* Configure Flow Control now that Auto-Neg has completed.
1272 * First, we need to restore the desired flow control
1273 * settings because we may have had to re-autoneg with a
1274 * different link partner.
1275 */
1276 ret_val = igb_config_fc_after_link_up(hw);
1277 if (ret_val)
1278 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001279 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001280 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001281 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001282
1283 return ret_val;
1284}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001285
Auke Kok9d5c8242008-01-24 02:22:38 -08001286/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001287 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1288 * @hw: pointer to the HW structure
1289 **/
1290void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1291{
1292 u32 reg;
1293
1294
1295 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1296 !igb_sgmii_active_82575(hw))
1297 return;
1298
1299 /* Enable PCS to turn on link */
1300 reg = rd32(E1000_PCS_CFG0);
1301 reg |= E1000_PCS_CFG_PCS_EN;
1302 wr32(E1000_PCS_CFG0, reg);
1303
1304 /* Power up the laser */
1305 reg = rd32(E1000_CTRL_EXT);
1306 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1307 wr32(E1000_CTRL_EXT, reg);
1308
1309 /* flush the write to verify completion */
1310 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001311 usleep_range(1000, 2000);
Nick Nunley88a268c2010-02-17 01:01:59 +00001312}
1313
1314/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001315 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001316 * @hw: pointer to the HW structure
1317 * @speed: stores the current speed
1318 * @duplex: stores the current duplex
1319 *
Auke Kok652fff32008-06-27 11:00:18 -07001320 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001321 * duplex, then store the values in the pointers provided.
1322 **/
1323static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1324 u16 *duplex)
1325{
1326 struct e1000_mac_info *mac = &hw->mac;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001327 u32 pcs, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08001328
1329 /* Set up defaults for the return values of this function */
1330 mac->serdes_has_link = false;
1331 *speed = 0;
1332 *duplex = 0;
1333
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001334 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001335 * the status register is not accurate. The PCS status register is
1336 * used instead.
1337 */
1338 pcs = rd32(E1000_PCS_LSTAT);
1339
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001340 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001341 * gets set once both sides sync up and agree upon link. Stable link
1342 * can be determined by checking for both link up and link sync ok
1343 */
1344 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1345 mac->serdes_has_link = true;
1346
1347 /* Detect and store PCS speed */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001348 if (pcs & E1000_PCS_LSTS_SPEED_1000)
Auke Kok9d5c8242008-01-24 02:22:38 -08001349 *speed = SPEED_1000;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001350 else if (pcs & E1000_PCS_LSTS_SPEED_100)
Auke Kok9d5c8242008-01-24 02:22:38 -08001351 *speed = SPEED_100;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001352 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001353 *speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -08001354
1355 /* Detect and store PCS duplex */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001356 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
Auke Kok9d5c8242008-01-24 02:22:38 -08001357 *duplex = FULL_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001358 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001359 *duplex = HALF_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001360
1361 /* Check if it is an I354 2.5Gb backplane connection. */
1362 if (mac->type == e1000_i354) {
1363 status = rd32(E1000_STATUS);
1364 if ((status & E1000_STATUS_2P5_SKU) &&
1365 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1366 *speed = SPEED_2500;
1367 *duplex = FULL_DUPLEX;
1368 hw_dbg("2500 Mbs, ");
1369 hw_dbg("Full Duplex\n");
1370 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001371 }
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001372
Auke Kok9d5c8242008-01-24 02:22:38 -08001373 }
1374
1375 return 0;
1376}
1377
1378/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001379 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001380 * @hw: pointer to the HW structure
1381 *
1382 * In the case of fiber serdes, shut down optics and PCS on driver unload
1383 * when management pass thru is not enabled.
1384 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001385void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001386{
1387 u32 reg;
1388
Nick Nunley53c992f2010-02-17 01:01:40 +00001389 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001390 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001391 return;
1392
Nick Nunley53c992f2010-02-17 01:01:40 +00001393 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001394 /* Disable PCS to turn off link */
1395 reg = rd32(E1000_PCS_CFG0);
1396 reg &= ~E1000_PCS_CFG_PCS_EN;
1397 wr32(E1000_PCS_CFG0, reg);
1398
1399 /* shutdown the laser */
1400 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001401 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001402 wr32(E1000_CTRL_EXT, reg);
1403
1404 /* flush the write to verify completion */
1405 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001406 usleep_range(1000, 2000);
Alexander Duyck2d064c02008-07-08 15:10:12 -07001407 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001408}
1409
1410/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001411 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001412 * @hw: pointer to the HW structure
1413 *
1414 * This resets the hardware into a known state. This is a
1415 * function pointer entry point called by the api module.
1416 **/
1417static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1418{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001419 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001420 s32 ret_val;
1421
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001422 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001423 * on the last TLP read/write transaction when MAC is reset.
1424 */
1425 ret_val = igb_disable_pcie_master(hw);
1426 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001427 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001428
Alexander Duyck009bc062009-07-23 18:08:35 +00001429 /* set the completion timeout for interface */
1430 ret_val = igb_set_pcie_completion_timeout(hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001431 if (ret_val)
Alexander Duyck009bc062009-07-23 18:08:35 +00001432 hw_dbg("PCI-E Set completion timeout has failed.\n");
Alexander Duyck009bc062009-07-23 18:08:35 +00001433
Auke Kok652fff32008-06-27 11:00:18 -07001434 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001435 wr32(E1000_IMC, 0xffffffff);
1436
1437 wr32(E1000_RCTL, 0);
1438 wr32(E1000_TCTL, E1000_TCTL_PSP);
1439 wrfl();
1440
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001441 usleep_range(10000, 20000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001442
1443 ctrl = rd32(E1000_CTRL);
1444
Auke Kok652fff32008-06-27 11:00:18 -07001445 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1447
1448 ret_val = igb_get_auto_rd_done(hw);
1449 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001450 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001451 * return with an error. This can happen in situations
1452 * where there is no eeprom and prevents getting link.
1453 */
Auke Kok652fff32008-06-27 11:00:18 -07001454 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001455 }
1456
1457 /* If EEPROM is not present, run manual init scripts */
1458 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1459 igb_reset_init_script_82575(hw);
1460
1461 /* Clear any pending interrupt events. */
1462 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001463 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001464
Alexander Duyck5ac16652009-07-23 18:09:12 +00001465 /* Install any alternate MAC address into RAR0 */
1466 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001467
1468 return ret_val;
1469}
1470
1471/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001472 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001473 * @hw: pointer to the HW structure
1474 *
1475 * This inits the hardware readying it for operation.
1476 **/
1477static s32 igb_init_hw_82575(struct e1000_hw *hw)
1478{
1479 struct e1000_mac_info *mac = &hw->mac;
1480 s32 ret_val;
1481 u16 i, rar_count = mac->rar_entry_count;
1482
1483 /* Initialize identification LED */
1484 ret_val = igb_id_led_init(hw);
1485 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001486 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001487 /* This is not fatal and we should not stop init due to this */
1488 }
1489
1490 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001491 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001492 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001493 igb_clear_vfta_i350(hw);
1494 else
1495 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001496
1497 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001498 igb_init_rx_addrs(hw, rar_count);
1499
Auke Kok9d5c8242008-01-24 02:22:38 -08001500 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001501 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001502 for (i = 0; i < mac->mta_reg_count; i++)
1503 array_wr32(E1000_MTA, i, 0);
1504
Alexander Duyck68d480c2009-10-05 06:33:08 +00001505 /* Zero out the Unicast HASH table */
1506 hw_dbg("Zeroing the UTA\n");
1507 for (i = 0; i < mac->uta_reg_count; i++)
1508 array_wr32(E1000_UTA, i, 0);
1509
Auke Kok9d5c8242008-01-24 02:22:38 -08001510 /* Setup link and flow control */
1511 ret_val = igb_setup_link(hw);
1512
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001513 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001514 * important that we do this after we have tried to establish link
1515 * because the symbol error count will increment wildly if there
1516 * is no link.
1517 */
1518 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001519 return ret_val;
1520}
1521
1522/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001523 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001524 * @hw: pointer to the HW structure
1525 *
1526 * Configures the link for auto-neg or forced speed and duplex. Then we check
1527 * for link, once link is established calls to configure collision distance
1528 * and flow control are called.
1529 **/
1530static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1531{
Alexander Duyck12645a12009-07-23 18:08:16 +00001532 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001533 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001534 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001535
1536 ctrl = rd32(E1000_CTRL);
1537 ctrl |= E1000_CTRL_SLU;
1538 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1539 wr32(E1000_CTRL, ctrl);
1540
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001541 /* Clear Go Link Disconnect bit on supported devices */
1542 switch (hw->mac.type) {
1543 case e1000_82580:
1544 case e1000_i350:
1545 case e1000_i210:
1546 case e1000_i211:
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001547 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1548 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1549 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001550 break;
1551 default:
1552 break;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001553 }
1554
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001555 ret_val = igb_setup_serdes_link_82575(hw);
1556 if (ret_val)
1557 goto out;
1558
1559 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001560 /* allow time for SFP cage time to power up phy */
1561 msleep(300);
1562
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001563 ret_val = hw->phy.ops.reset(hw);
1564 if (ret_val) {
1565 hw_dbg("Error resetting the PHY.\n");
1566 goto out;
1567 }
1568 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001569 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001570 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001571 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001572 switch (hw->phy.id) {
1573 case I347AT4_E_PHY_ID:
1574 case M88E1112_E_PHY_ID:
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001575 case M88E1543_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001576 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001577 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001578 break;
1579 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001580 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001581 break;
1582 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001583 break;
1584 case e1000_phy_igp_3:
1585 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001586 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001587 case e1000_phy_82580:
1588 ret_val = igb_copper_link_setup_82580(hw);
1589 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001590 default:
1591 ret_val = -E1000_ERR_PHY;
1592 break;
1593 }
1594
1595 if (ret_val)
1596 goto out;
1597
Alexander Duyck81fadd82009-10-05 06:35:03 +00001598 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001599out:
1600 return ret_val;
1601}
1602
1603/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001604 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001605 * @hw: pointer to the HW structure
1606 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001607 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1608 * used on copper connections where the serialized gigabit media independent
1609 * interface (sgmii), or serdes fiber is being used. Configures the link
1610 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001611 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001612static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001613{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001614 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001615 bool pcs_autoneg;
Todd Fujinaka23d87822014-06-04 07:12:15 +00001616 s32 ret_val = 0;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001617 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001618
1619 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1620 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001621 return ret_val;
1622
Auke Kok9d5c8242008-01-24 02:22:38 -08001623
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001624 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001625 * explicitly turned off or a power cycle is performed. A read to
1626 * the register does not indicate its status. Therefore, we ensure
1627 * loopback mode is disabled during initialization.
1628 */
1629 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1630
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001631 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001632 ctrl_ext = rd32(E1000_CTRL_EXT);
1633 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001634 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001635 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001636
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001637 ctrl_reg = rd32(E1000_CTRL);
1638 ctrl_reg |= E1000_CTRL_SLU;
1639
1640 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1641 /* set both sw defined pins */
1642 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1643
1644 /* Set switch control to serdes energy detect */
1645 reg = rd32(E1000_CONNSW);
1646 reg |= E1000_CONNSW_ENRGSRC;
1647 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001648 }
1649
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001650 reg = rd32(E1000_PCS_LCTL);
1651
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001652 /* default pcs_autoneg to the same setting as mac autoneg */
1653 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001654
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001655 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1656 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1657 /* sgmii mode lets the phy handle forcing speed/duplex */
1658 pcs_autoneg = true;
1659 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001660 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001661 break;
1662 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1663 /* disable PCS autoneg and support parallel detect only */
1664 pcs_autoneg = false;
1665 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001666 if (hw->mac.type == e1000_82575 ||
1667 hw->mac.type == e1000_82576) {
1668 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1669 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00001670 hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001671 return ret_val;
1672 }
1673
1674 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1675 pcs_autoneg = false;
1676 }
1677
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001678 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001679 * link so it is best to just force the MAC and let the pcs
1680 * link either autoneg or be forced to 1000/Full
1681 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001682 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001683 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001684
1685 /* set speed of 1000/Full if speed/duplex is forced */
1686 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1687 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001688 }
1689
1690 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001691
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001692 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001693 * at 1gb. Autoneg should be default set by most drivers. This is the
1694 * mode that will be compatible with older link partners and switches.
1695 * However, both are supported by the hardware and some drivers/tools.
1696 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001697 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1698 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1699
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001700 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001701 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001702 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001703 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001704
1705 /* Disable force flow control for autoneg */
1706 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1707
1708 /* Configure flow control advertisement for autoneg */
1709 anadv_reg = rd32(E1000_PCS_ANADV);
1710 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1711 switch (hw->fc.requested_mode) {
1712 case e1000_fc_full:
1713 case e1000_fc_rx_pause:
1714 anadv_reg |= E1000_TXCW_ASM_DIR;
1715 anadv_reg |= E1000_TXCW_PAUSE;
1716 break;
1717 case e1000_fc_tx_pause:
1718 anadv_reg |= E1000_TXCW_ASM_DIR;
1719 break;
1720 default:
1721 break;
1722 }
1723 wr32(E1000_PCS_ANADV, anadv_reg);
1724
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001725 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001726 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001727 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001728 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001729
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001730 /* Force flow control for forced link */
1731 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1732
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001733 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001734 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001735
Auke Kok9d5c8242008-01-24 02:22:38 -08001736 wr32(E1000_PCS_LCTL, reg);
1737
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001738 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001739 igb_force_mac_fc(hw);
1740
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001741 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001742}
1743
1744/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001745 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001746 * @hw: pointer to the HW structure
1747 *
1748 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1749 * which can be enabled for use in the embedded applications. Simply
1750 * return the current state of the sgmii interface.
1751 **/
1752static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1753{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001754 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001755 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001756}
1757
1758/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001759 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001760 * @hw: pointer to the HW structure
1761 *
1762 * Inits recommended HW defaults after a reset when there is no EEPROM
1763 * detected. This is only for the 82575.
1764 **/
1765static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1766{
1767 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001768 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001769 /* SerDes configuration via SERDESCTRL */
1770 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1771 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1772 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1773 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1774
1775 /* CCM configuration via CCMCTL register */
1776 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1777 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1778
1779 /* PCIe lanes configuration */
1780 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1781 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1782 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1783 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1784
1785 /* PCIe PLL Configuration */
1786 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1787 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1788 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1789 }
1790
1791 return 0;
1792}
1793
1794/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001795 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001796 * @hw: pointer to the HW structure
1797 **/
1798static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1799{
1800 s32 ret_val = 0;
1801
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001802 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001803 * so that it will override the Si installed default perm
1804 * address.
1805 */
1806 ret_val = igb_check_alt_mac_addr(hw);
1807 if (ret_val)
1808 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001809
Alexander Duyck22896632009-10-05 06:34:25 +00001810 ret_val = igb_read_mac_addr(hw);
1811
1812out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001813 return ret_val;
1814}
1815
1816/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001817 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1818 * @hw: pointer to the HW structure
1819 *
1820 * In the case of a PHY power down to save power, or to turn off link during a
1821 * driver unload, or wake on lan is not enabled, remove the link.
1822 **/
1823void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1824{
1825 /* If the management interface is not enabled, then power down */
1826 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1827 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001828}
1829
1830/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001831 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001832 * @hw: pointer to the HW structure
1833 *
1834 * Clears the hardware counters by reading the counter registers.
1835 **/
1836static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1837{
Auke Kok9d5c8242008-01-24 02:22:38 -08001838 igb_clear_hw_cntrs_base(hw);
1839
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001840 rd32(E1000_PRC64);
1841 rd32(E1000_PRC127);
1842 rd32(E1000_PRC255);
1843 rd32(E1000_PRC511);
1844 rd32(E1000_PRC1023);
1845 rd32(E1000_PRC1522);
1846 rd32(E1000_PTC64);
1847 rd32(E1000_PTC127);
1848 rd32(E1000_PTC255);
1849 rd32(E1000_PTC511);
1850 rd32(E1000_PTC1023);
1851 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001852
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001853 rd32(E1000_ALGNERRC);
1854 rd32(E1000_RXERRC);
1855 rd32(E1000_TNCRS);
1856 rd32(E1000_CEXTERR);
1857 rd32(E1000_TSCTC);
1858 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001859
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001860 rd32(E1000_MGTPRC);
1861 rd32(E1000_MGTPDC);
1862 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001863
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001864 rd32(E1000_IAC);
1865 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001866
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001867 rd32(E1000_ICRXPTC);
1868 rd32(E1000_ICRXATC);
1869 rd32(E1000_ICTXPTC);
1870 rd32(E1000_ICTXATC);
1871 rd32(E1000_ICTXQEC);
1872 rd32(E1000_ICTXQMTC);
1873 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001874
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001875 rd32(E1000_CBTMPC);
1876 rd32(E1000_HTDPMC);
1877 rd32(E1000_CBRMPC);
1878 rd32(E1000_RPTHC);
1879 rd32(E1000_HGPTC);
1880 rd32(E1000_HTCBDPC);
1881 rd32(E1000_HGORCL);
1882 rd32(E1000_HGORCH);
1883 rd32(E1000_HGOTCL);
1884 rd32(E1000_HGOTCH);
1885 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001886
1887 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001888 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1889 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001890 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001891}
1892
Alexander Duyck662d7202008-06-27 11:00:29 -07001893/**
1894 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1895 * @hw: pointer to the HW structure
1896 *
1897 * After rx enable if managability is enabled then there is likely some
1898 * bad data at the start of the fifo and possibly in the DMA fifo. This
1899 * function clears the fifos and flushes any packets that came in as rx was
1900 * being enabled.
1901 **/
1902void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1903{
1904 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1905 int i, ms_wait;
1906
1907 if (hw->mac.type != e1000_82575 ||
1908 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1909 return;
1910
1911 /* Disable all RX queues */
1912 for (i = 0; i < 4; i++) {
1913 rxdctl[i] = rd32(E1000_RXDCTL(i));
1914 wr32(E1000_RXDCTL(i),
1915 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1916 }
1917 /* Poll all queues to verify they have shut down */
1918 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001919 usleep_range(1000, 2000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001920 rx_enabled = 0;
1921 for (i = 0; i < 4; i++)
1922 rx_enabled |= rd32(E1000_RXDCTL(i));
1923 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1924 break;
1925 }
1926
1927 if (ms_wait == 10)
1928 hw_dbg("Queue disable timed out after 10ms\n");
1929
1930 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1931 * incoming packets are rejected. Set enable and wait 2ms so that
1932 * any packet that was coming in as RCTL.EN was set is flushed
1933 */
1934 rfctl = rd32(E1000_RFCTL);
1935 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1936
1937 rlpml = rd32(E1000_RLPML);
1938 wr32(E1000_RLPML, 0);
1939
1940 rctl = rd32(E1000_RCTL);
1941 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1942 temp_rctl |= E1000_RCTL_LPE;
1943
1944 wr32(E1000_RCTL, temp_rctl);
1945 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1946 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001947 usleep_range(2000, 3000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001948
1949 /* Enable RX queues that were previously enabled and restore our
1950 * previous state
1951 */
1952 for (i = 0; i < 4; i++)
1953 wr32(E1000_RXDCTL(i), rxdctl[i]);
1954 wr32(E1000_RCTL, rctl);
1955 wrfl();
1956
1957 wr32(E1000_RLPML, rlpml);
1958 wr32(E1000_RFCTL, rfctl);
1959
1960 /* Flush receive errors generated by workaround */
1961 rd32(E1000_ROC);
1962 rd32(E1000_RNBC);
1963 rd32(E1000_MPC);
1964}
1965
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001966/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001967 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1968 * @hw: pointer to the HW structure
1969 *
1970 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1971 * however the hardware default for these parts is 500us to 1ms which is less
1972 * than the 10ms recommended by the pci-e spec. To address this we need to
1973 * increase the value to either 10ms to 200ms for capability version 1 config,
1974 * or 16ms to 55ms for version 2.
1975 **/
1976static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1977{
1978 u32 gcr = rd32(E1000_GCR);
1979 s32 ret_val = 0;
1980 u16 pcie_devctl2;
1981
1982 /* only take action if timeout value is defaulted to 0 */
1983 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1984 goto out;
1985
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001986 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00001987 * timeout of 10ms to 200ms through the GCR register
1988 */
1989 if (!(gcr & E1000_GCR_CAP_VER2)) {
1990 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1991 goto out;
1992 }
1993
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001994 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00001995 * directly in order to set the completion timeout value for
1996 * 16ms to 55ms
1997 */
1998 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001999 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002000 if (ret_val)
2001 goto out;
2002
2003 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2004
2005 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002006 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002007out:
2008 /* disable completion timeout resend */
2009 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2010
2011 wr32(E1000_GCR, gcr);
2012 return ret_val;
2013}
2014
2015/**
Greg Rose13800462010-11-06 02:08:26 +00002016 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2017 * @hw: pointer to the hardware struct
2018 * @enable: state to enter, either enabled or disabled
2019 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2020 *
2021 * enables/disables L2 switch anti-spoofing functionality.
2022 **/
2023void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2024{
Lior Levy22c12752013-03-12 15:49:32 +00002025 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00002026
2027 switch (hw->mac.type) {
2028 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00002029 reg_offset = E1000_DTXSWC;
2030 break;
Greg Rose13800462010-11-06 02:08:26 +00002031 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002032 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00002033 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00002034 break;
2035 default:
Lior Levy22c12752013-03-12 15:49:32 +00002036 return;
Greg Rose13800462010-11-06 02:08:26 +00002037 }
Lior Levy22c12752013-03-12 15:49:32 +00002038
2039 reg_val = rd32(reg_offset);
2040 if (enable) {
2041 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2042 E1000_DTXSWC_VLAN_SPOOF_MASK);
2043 /* The PF can spoof - it has to in order to
2044 * support emulation mode NICs
2045 */
2046 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2047 } else {
2048 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2049 E1000_DTXSWC_VLAN_SPOOF_MASK);
2050 }
2051 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00002052}
2053
2054/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002055 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2056 * @hw: pointer to the hardware struct
2057 * @enable: state to enter, either enabled or disabled
2058 *
2059 * enables/disables L2 switch loopback functionality.
2060 **/
2061void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2062{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002063 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002064
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002065 switch (hw->mac.type) {
2066 case e1000_82576:
2067 dtxswc = rd32(E1000_DTXSWC);
2068 if (enable)
2069 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2070 else
2071 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2072 wr32(E1000_DTXSWC, dtxswc);
2073 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002074 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002075 case e1000_i350:
2076 dtxswc = rd32(E1000_TXSWC);
2077 if (enable)
2078 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2079 else
2080 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2081 wr32(E1000_TXSWC, dtxswc);
2082 break;
2083 default:
2084 /* Currently no other hardware supports loopback */
2085 break;
2086 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002087
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002088}
2089
2090/**
2091 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2092 * @hw: pointer to the hardware struct
2093 * @enable: state to enter, either enabled or disabled
2094 *
2095 * enables/disables replication of packets across multiple pools.
2096 **/
2097void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2098{
2099 u32 vt_ctl = rd32(E1000_VT_CTL);
2100
2101 if (enable)
2102 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2103 else
2104 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2105
2106 wr32(E1000_VT_CTL, vt_ctl);
2107}
2108
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002109/**
2110 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2111 * @hw: pointer to the HW structure
2112 * @offset: register offset to be read
2113 * @data: pointer to the read data
2114 *
2115 * Reads the MDI control register in the PHY at offset and stores the
2116 * information read to data.
2117 **/
2118static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2119{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002120 s32 ret_val;
2121
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002122 ret_val = hw->phy.ops.acquire(hw);
2123 if (ret_val)
2124 goto out;
2125
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002126 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2127
2128 hw->phy.ops.release(hw);
2129
2130out:
2131 return ret_val;
2132}
2133
2134/**
2135 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2136 * @hw: pointer to the HW structure
2137 * @offset: register offset to write to
2138 * @data: data to write to register at offset
2139 *
2140 * Writes data to MDI control register in the PHY at offset.
2141 **/
2142static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2143{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002144 s32 ret_val;
2145
2146
2147 ret_val = hw->phy.ops.acquire(hw);
2148 if (ret_val)
2149 goto out;
2150
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002151 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2152
2153 hw->phy.ops.release(hw);
2154
2155out:
2156 return ret_val;
2157}
2158
2159/**
Nick Nunley08451e22010-07-26 13:15:29 +00002160 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2161 * @hw: pointer to the HW structure
2162 *
2163 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2164 * the values found in the EEPROM. This addresses an issue in which these
2165 * bits are not restored from EEPROM after reset.
2166 **/
2167static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2168{
2169 s32 ret_val = 0;
2170 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002171 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002172
2173 if (hw->mac.type != e1000_82580)
2174 goto out;
2175 if (!igb_sgmii_active_82575(hw))
2176 goto out;
2177
2178 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2179 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2180 &nvm_data);
2181 if (ret_val) {
2182 hw_dbg("NVM Read Error\n");
2183 goto out;
2184 }
2185
2186 mdicnfg = rd32(E1000_MDICNFG);
2187 if (nvm_data & NVM_WORD24_EXT_MDIO)
2188 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2189 if (nvm_data & NVM_WORD24_COM_MDIO)
2190 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2191 wr32(E1000_MDICNFG, mdicnfg);
2192out:
2193 return ret_val;
2194}
2195
2196/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002197 * igb_reset_hw_82580 - Reset hardware
2198 * @hw: pointer to the HW structure
2199 *
2200 * This resets function or entire device (all ports, etc.)
2201 * to a known state.
2202 **/
2203static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2204{
2205 s32 ret_val = 0;
2206 /* BH SW mailbox bit in SW_FW_SYNC */
2207 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002208 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002209 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2210
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002211 hw->dev_spec._82575.global_device_reset = false;
2212
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002213 /* due to hw errata, global device reset doesn't always
2214 * work on 82580
2215 */
2216 if (hw->mac.type == e1000_82580)
2217 global_device_reset = false;
2218
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002219 /* Get current control state. */
2220 ctrl = rd32(E1000_CTRL);
2221
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002222 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002223 * on the last TLP read/write transaction when MAC is reset.
2224 */
2225 ret_val = igb_disable_pcie_master(hw);
2226 if (ret_val)
2227 hw_dbg("PCI-E Master disable polling has failed.\n");
2228
2229 hw_dbg("Masking off all interrupts\n");
2230 wr32(E1000_IMC, 0xffffffff);
2231 wr32(E1000_RCTL, 0);
2232 wr32(E1000_TCTL, E1000_TCTL_PSP);
2233 wrfl();
2234
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002235 usleep_range(10000, 11000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002236
2237 /* Determine whether or not a global dev reset is requested */
2238 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002239 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002240 global_device_reset = false;
2241
2242 if (global_device_reset &&
2243 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2244 ctrl |= E1000_CTRL_DEV_RST;
2245 else
2246 ctrl |= E1000_CTRL_RST;
2247
2248 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002249 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002250
2251 /* Add delay to insure DEV_RST has time to complete */
2252 if (global_device_reset)
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002253 usleep_range(5000, 6000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002254
2255 ret_val = igb_get_auto_rd_done(hw);
2256 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002257 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002258 * return with an error. This can happen in situations
2259 * where there is no eeprom and prevents getting link.
2260 */
2261 hw_dbg("Auto Read Done did not complete\n");
2262 }
2263
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002264 /* clear global device reset status bit */
2265 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2266
2267 /* Clear any pending interrupt events. */
2268 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002269 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002270
Nick Nunley08451e22010-07-26 13:15:29 +00002271 ret_val = igb_reset_mdicnfg_82580(hw);
2272 if (ret_val)
2273 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2274
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002275 /* Install any alternate MAC address into RAR0 */
2276 ret_val = igb_check_alt_mac_addr(hw);
2277
2278 /* Release semaphore */
2279 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002280 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002281
2282 return ret_val;
2283}
2284
2285/**
2286 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2287 * @data: data received by reading RXPBS register
2288 *
2289 * The 82580 uses a table based approach for packet buffer allocation sizes.
2290 * This function converts the retrieved value into the correct table value
2291 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2292 * 0x0 36 72 144 1 2 4 8 16
2293 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2294 */
2295u16 igb_rxpbs_adjust_82580(u32 data)
2296{
2297 u16 ret_val = 0;
2298
Todd Fujinaka72b36722014-03-04 02:25:22 +00002299 if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002300 ret_val = e1000_82580_rxpbs_table[data];
2301
2302 return ret_val;
2303}
2304
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002305/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002306 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2307 * checksum
2308 * @hw: pointer to the HW structure
2309 * @offset: offset in words of the checksum protected region
2310 *
2311 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2312 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2313 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002314static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2315 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002316{
2317 s32 ret_val = 0;
2318 u16 checksum = 0;
2319 u16 i, nvm_data;
2320
2321 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2322 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2323 if (ret_val) {
2324 hw_dbg("NVM Read Error\n");
2325 goto out;
2326 }
2327 checksum += nvm_data;
2328 }
2329
2330 if (checksum != (u16) NVM_SUM) {
2331 hw_dbg("NVM Checksum Invalid\n");
2332 ret_val = -E1000_ERR_NVM;
2333 goto out;
2334 }
2335
2336out:
2337 return ret_val;
2338}
2339
2340/**
2341 * igb_update_nvm_checksum_with_offset - Update EEPROM
2342 * checksum
2343 * @hw: pointer to the HW structure
2344 * @offset: offset in words of the checksum protected region
2345 *
2346 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2347 * up to the checksum. Then calculates the EEPROM checksum and writes the
2348 * value to the EEPROM.
2349 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002350static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002351{
2352 s32 ret_val;
2353 u16 checksum = 0;
2354 u16 i, nvm_data;
2355
2356 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2357 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2358 if (ret_val) {
2359 hw_dbg("NVM Read Error while updating checksum.\n");
2360 goto out;
2361 }
2362 checksum += nvm_data;
2363 }
2364 checksum = (u16) NVM_SUM - checksum;
2365 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2366 &checksum);
2367 if (ret_val)
2368 hw_dbg("NVM Write Error while updating checksum.\n");
2369
2370out:
2371 return ret_val;
2372}
2373
2374/**
2375 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2376 * @hw: pointer to the HW structure
2377 *
2378 * Calculates the EEPROM section checksum by reading/adding each word of
2379 * the EEPROM and then verifies that the sum of the EEPROM is
2380 * equal to 0xBABA.
2381 **/
2382static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2383{
2384 s32 ret_val = 0;
2385 u16 eeprom_regions_count = 1;
2386 u16 j, nvm_data;
2387 u16 nvm_offset;
2388
2389 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2390 if (ret_val) {
2391 hw_dbg("NVM Read Error\n");
2392 goto out;
2393 }
2394
2395 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002396 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002397 * for all 4 ports.
2398 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002399 eeprom_regions_count = 4;
2400 }
2401
2402 for (j = 0; j < eeprom_regions_count; j++) {
2403 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2404 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2405 nvm_offset);
2406 if (ret_val != 0)
2407 goto out;
2408 }
2409
2410out:
2411 return ret_val;
2412}
2413
2414/**
2415 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2416 * @hw: pointer to the HW structure
2417 *
2418 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2419 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2420 * checksum and writes the value to the EEPROM.
2421 **/
2422static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2423{
2424 s32 ret_val;
2425 u16 j, nvm_data;
2426 u16 nvm_offset;
2427
2428 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2429 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002430 hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002431 goto out;
2432 }
2433
2434 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2435 /* set compatibility bit to validate checksums appropriately */
2436 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2437 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2438 &nvm_data);
2439 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002440 hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002441 goto out;
2442 }
2443 }
2444
2445 for (j = 0; j < 4; j++) {
2446 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2447 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2448 if (ret_val)
2449 goto out;
2450 }
2451
2452out:
2453 return ret_val;
2454}
2455
2456/**
2457 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2458 * @hw: pointer to the HW structure
2459 *
2460 * Calculates the EEPROM section checksum by reading/adding each word of
2461 * the EEPROM and then verifies that the sum of the EEPROM is
2462 * equal to 0xBABA.
2463 **/
2464static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2465{
2466 s32 ret_val = 0;
2467 u16 j;
2468 u16 nvm_offset;
2469
2470 for (j = 0; j < 4; j++) {
2471 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2472 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2473 nvm_offset);
2474 if (ret_val != 0)
2475 goto out;
2476 }
2477
2478out:
2479 return ret_val;
2480}
2481
2482/**
2483 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2484 * @hw: pointer to the HW structure
2485 *
2486 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2487 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2488 * checksum and writes the value to the EEPROM.
2489 **/
2490static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2491{
2492 s32 ret_val = 0;
2493 u16 j;
2494 u16 nvm_offset;
2495
2496 for (j = 0; j < 4; j++) {
2497 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2498 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2499 if (ret_val != 0)
2500 goto out;
2501 }
2502
2503out:
2504 return ret_val;
2505}
Stefan Assmann34a03262011-04-05 04:27:05 +00002506
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002507/**
Matthew Vick87371b92013-02-21 03:32:52 +00002508 * __igb_access_emi_reg - Read/write EMI register
2509 * @hw: pointer to the HW structure
2510 * @addr: EMI address to program
2511 * @data: pointer to value to read/write from/to the EMI address
2512 * @read: boolean flag to indicate read or write
2513 **/
2514static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2515 u16 *data, bool read)
2516{
Todd Fujinaka23d87822014-06-04 07:12:15 +00002517 s32 ret_val = 0;
Matthew Vick87371b92013-02-21 03:32:52 +00002518
2519 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2520 if (ret_val)
2521 return ret_val;
2522
2523 if (read)
2524 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2525 else
2526 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2527
2528 return ret_val;
2529}
2530
2531/**
2532 * igb_read_emi_reg - Read Extended Management Interface register
2533 * @hw: pointer to the HW structure
2534 * @addr: EMI address to program
2535 * @data: value to be read from the EMI address
2536 **/
2537s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2538{
2539 return __igb_access_emi_reg(hw, addr, data, true);
2540}
2541
2542/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002543 * igb_set_eee_i350 - Enable/disable EEE support
2544 * @hw: pointer to the HW structure
2545 *
2546 * Enable/disable EEE based on setting in dev_spec structure.
2547 *
2548 **/
2549s32 igb_set_eee_i350(struct e1000_hw *hw)
2550{
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002551 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002552
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002553 if ((hw->mac.type < e1000_i350) ||
2554 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002555 goto out;
2556 ipcnfg = rd32(E1000_IPCNFG);
2557 eeer = rd32(E1000_EEER);
2558
2559 /* enable or disable per user setting */
2560 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002561 u32 eee_su = rd32(E1000_EEE_SU);
2562
2563 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2564 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002565 E1000_EEER_LPI_FC);
2566
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002567 /* This bit should not be set in normal operation. */
2568 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2569 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2570
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002571 } else {
2572 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2573 E1000_IPCNFG_EEE_100M_AN);
2574 eeer &= ~(E1000_EEER_TX_LPI_EN |
2575 E1000_EEER_RX_LPI_EN |
2576 E1000_EEER_LPI_FC);
2577 }
2578 wr32(E1000_IPCNFG, ipcnfg);
2579 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002580 rd32(E1000_IPCNFG);
2581 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002582out:
2583
Todd Fujinaka23d87822014-06-04 07:12:15 +00002584 return 0;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002585}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002586
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002587/**
2588 * igb_set_eee_i354 - Enable/disable EEE support
2589 * @hw: pointer to the HW structure
2590 *
2591 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2592 *
2593 **/
2594s32 igb_set_eee_i354(struct e1000_hw *hw)
2595{
2596 struct e1000_phy_info *phy = &hw->phy;
2597 s32 ret_val = 0;
2598 u16 phy_data;
2599
2600 if ((hw->phy.media_type != e1000_media_type_copper) ||
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002601 (phy->id != M88E1543_E_PHY_ID))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002602 goto out;
2603
2604 if (!hw->dev_spec._82575.eee_disable) {
2605 /* Switch to PHY page 18. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002606 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002607 if (ret_val)
2608 goto out;
2609
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002610 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002611 &phy_data);
2612 if (ret_val)
2613 goto out;
2614
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002615 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2616 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002617 phy_data);
2618 if (ret_val)
2619 goto out;
2620
2621 /* Return the PHY to page 0. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002622 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002623 if (ret_val)
2624 goto out;
2625
2626 /* Turn on EEE advertisement. */
2627 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2628 E1000_EEE_ADV_DEV_I354,
2629 &phy_data);
2630 if (ret_val)
2631 goto out;
2632
2633 phy_data |= E1000_EEE_ADV_100_SUPPORTED |
2634 E1000_EEE_ADV_1000_SUPPORTED;
2635 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2636 E1000_EEE_ADV_DEV_I354,
2637 phy_data);
2638 } else {
2639 /* Turn off EEE advertisement. */
2640 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2641 E1000_EEE_ADV_DEV_I354,
2642 &phy_data);
2643 if (ret_val)
2644 goto out;
2645
2646 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2647 E1000_EEE_ADV_1000_SUPPORTED);
2648 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2649 E1000_EEE_ADV_DEV_I354,
2650 phy_data);
2651 }
2652
2653out:
2654 return ret_val;
2655}
2656
2657/**
2658 * igb_get_eee_status_i354 - Get EEE status
2659 * @hw: pointer to the HW structure
2660 * @status: EEE status
2661 *
2662 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2663 * been received.
2664 **/
2665s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2666{
2667 struct e1000_phy_info *phy = &hw->phy;
2668 s32 ret_val = 0;
2669 u16 phy_data;
2670
2671 /* Check if EEE is supported on this device. */
2672 if ((hw->phy.media_type != e1000_media_type_copper) ||
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002673 (phy->id != M88E1543_E_PHY_ID))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002674 goto out;
2675
2676 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2677 E1000_PCS_STATUS_DEV_I354,
2678 &phy_data);
2679 if (ret_val)
2680 goto out;
2681
2682 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2683 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2684
2685out:
2686 return ret_val;
2687}
2688
Carolyn Wybornye4288932012-12-07 03:01:42 +00002689static const u8 e1000_emc_temp_data[4] = {
2690 E1000_EMC_INTERNAL_DATA,
2691 E1000_EMC_DIODE1_DATA,
2692 E1000_EMC_DIODE2_DATA,
2693 E1000_EMC_DIODE3_DATA
2694};
2695static const u8 e1000_emc_therm_limit[4] = {
2696 E1000_EMC_INTERNAL_THERM_LIMIT,
2697 E1000_EMC_DIODE1_THERM_LIMIT,
2698 E1000_EMC_DIODE2_THERM_LIMIT,
2699 E1000_EMC_DIODE3_THERM_LIMIT
2700};
2701
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002702#ifdef CONFIG_IGB_HWMON
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002703/**
2704 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002705 * @hw: pointer to hardware structure
2706 *
2707 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002708 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002709static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002710{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002711 u16 ets_offset;
2712 u16 ets_cfg;
2713 u16 ets_sensor;
2714 u8 num_sensors;
2715 u8 sensor_index;
2716 u8 sensor_location;
2717 u8 i;
2718 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2719
2720 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2721 return E1000_NOT_IMPLEMENTED;
2722
2723 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2724
2725 /* Return the internal sensor only if ETS is unsupported */
2726 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2727 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002728 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002729
2730 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2731 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2732 != NVM_ETS_TYPE_EMC)
2733 return E1000_NOT_IMPLEMENTED;
2734
2735 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2736 if (num_sensors > E1000_MAX_SENSORS)
2737 num_sensors = E1000_MAX_SENSORS;
2738
2739 for (i = 1; i < num_sensors; i++) {
2740 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2741 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2742 NVM_ETS_DATA_INDEX_SHIFT);
2743 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2744 NVM_ETS_DATA_LOC_SHIFT);
2745
2746 if (sensor_location != 0)
2747 hw->phy.ops.read_i2c_byte(hw,
2748 e1000_emc_temp_data[sensor_index],
2749 E1000_I2C_THERMAL_SENSOR_ADDR,
2750 &data->sensor[i].temp);
2751 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002752 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002753}
2754
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002755/**
2756 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002757 * @hw: pointer to hardware structure
2758 *
2759 * Sets the thermal sensor thresholds according to the NVM map
2760 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002761 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002762static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002763{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002764 u16 ets_offset;
2765 u16 ets_cfg;
2766 u16 ets_sensor;
2767 u8 low_thresh_delta;
2768 u8 num_sensors;
2769 u8 sensor_index;
2770 u8 sensor_location;
2771 u8 therm_limit;
2772 u8 i;
2773 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2774
2775 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2776 return E1000_NOT_IMPLEMENTED;
2777
2778 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2779
2780 data->sensor[0].location = 0x1;
2781 data->sensor[0].caution_thresh =
2782 (rd32(E1000_THHIGHTC) & 0xFF);
2783 data->sensor[0].max_op_thresh =
2784 (rd32(E1000_THLOWTC) & 0xFF);
2785
2786 /* Return the internal sensor only if ETS is unsupported */
2787 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2788 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002789 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002790
2791 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2792 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2793 != NVM_ETS_TYPE_EMC)
2794 return E1000_NOT_IMPLEMENTED;
2795
2796 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2797 NVM_ETS_LTHRES_DELTA_SHIFT);
2798 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2799
2800 for (i = 1; i <= num_sensors; i++) {
2801 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2802 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2803 NVM_ETS_DATA_INDEX_SHIFT);
2804 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2805 NVM_ETS_DATA_LOC_SHIFT);
2806 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2807
2808 hw->phy.ops.write_i2c_byte(hw,
2809 e1000_emc_therm_limit[sensor_index],
2810 E1000_I2C_THERMAL_SENSOR_ADDR,
2811 therm_limit);
2812
2813 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2814 data->sensor[i].location = sensor_location;
2815 data->sensor[i].caution_thresh = therm_limit;
2816 data->sensor[i].max_op_thresh = therm_limit -
2817 low_thresh_delta;
2818 }
2819 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002820 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002821}
2822
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002823#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002824static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002825 .init_hw = igb_init_hw_82575,
2826 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002827 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002828 .read_mac_addr = igb_read_mac_addr_82575,
Akeem G Abodunrinf6878e32013-08-28 02:23:09 +00002829 .get_speed_and_duplex = igb_get_link_up_info_82575,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002830#ifdef CONFIG_IGB_HWMON
2831 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2832 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2833#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002834};
2835
2836static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002837 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002838 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002839 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002840 .write_i2c_byte = igb_write_i2c_byte,
2841 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002842};
2843
2844static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002845 .acquire = igb_acquire_nvm_82575,
2846 .read = igb_read_nvm_eerd,
2847 .release = igb_release_nvm_82575,
2848 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002849};
2850
2851const struct e1000_info e1000_82575_info = {
2852 .get_invariants = igb_get_invariants_82575,
2853 .mac_ops = &e1000_mac_ops_82575,
2854 .phy_ops = &e1000_phy_ops_82575,
2855 .nvm_ops = &e1000_nvm_ops_82575,
2856};
2857