blob: d9664c47fe3a331b9299aa744a1f16dea353d495 [file] [log] [blame]
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00001/* Intel(R) Gigabit Ethernet Linux driver
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07002 * Copyright(c) 2007-2015 Intel Corporation.
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00003 *
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
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000142
143 if (data & E1000_M88E1112_STATUS_LINK)
144 port = E1000_MEDIA_PORT_OTHER;
145
146 /* Determine if a swap needs to happen. */
147 if (port && (hw->dev_spec._82575.media_port != port)) {
148 hw->dev_spec._82575.media_port = port;
149 hw->dev_spec._82575.media_changed = true;
Todd Fujinaka2ba6c072015-04-29 15:23:28 -0700150 }
151
152 if (port == E1000_MEDIA_PORT_COPPER) {
153 /* reset page to 0 */
154 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
155 if (ret_val)
156 return ret_val;
157 igb_check_for_link_82575(hw);
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000158 } else {
Todd Fujinaka2ba6c072015-04-29 15:23:28 -0700159 igb_check_for_link_82575(hw);
160 /* reset page to 0 */
161 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
162 if (ret_val)
163 return ret_val;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000164 }
165
Todd Fujinaka23d87822014-06-04 07:12:15 +0000166 return 0;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000167}
168
169/**
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000170 * igb_init_phy_params_82575 - Init PHY func ptrs.
171 * @hw: pointer to the HW structure
172 **/
173static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
174{
175 struct e1000_phy_info *phy = &hw->phy;
176 s32 ret_val = 0;
177 u32 ctrl_ext;
178
179 if (hw->phy.media_type != e1000_media_type_copper) {
180 phy->type = e1000_phy_none;
181 goto out;
182 }
183
184 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
185 phy->reset_delay_us = 100;
186
187 ctrl_ext = rd32(E1000_CTRL_EXT);
188
189 if (igb_sgmii_active_82575(hw)) {
190 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
191 ctrl_ext |= E1000_CTRL_I2C_ENA;
192 } else {
193 phy->ops.reset = igb_phy_hw_reset;
194 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
195 }
196
197 wr32(E1000_CTRL_EXT, ctrl_ext);
198 igb_reset_mdicnfg_82580(hw);
199
200 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
201 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
202 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
203 } else {
204 switch (hw->mac.type) {
205 case e1000_82580:
206 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000207 case e1000_i354:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000208 phy->ops.read_reg = igb_read_phy_reg_82580;
209 phy->ops.write_reg = igb_write_phy_reg_82580;
210 break;
211 case e1000_i210:
212 case e1000_i211:
213 phy->ops.read_reg = igb_read_phy_reg_gs40g;
214 phy->ops.write_reg = igb_write_phy_reg_gs40g;
215 break;
216 default:
217 phy->ops.read_reg = igb_read_phy_reg_igp;
218 phy->ops.write_reg = igb_write_phy_reg_igp;
219 }
220 }
221
222 /* set lan id */
223 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
224 E1000_STATUS_FUNC_SHIFT;
225
226 /* Set phy->phy_addr and phy->id. */
227 ret_val = igb_get_phy_id_82575(hw);
228 if (ret_val)
229 return ret_val;
230
231 /* Verify phy id and set remaining function pointers */
232 switch (phy->id) {
Akeem G Abodunrin99af4722013-08-28 02:22:58 +0000233 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700234 case M88E1512_E_PHY_ID:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000235 case I347AT4_E_PHY_ID:
236 case M88E1112_E_PHY_ID:
237 case M88E1111_I_PHY_ID:
238 phy->type = e1000_phy_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000239 phy->ops.check_polarity = igb_check_polarity_m88;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000240 phy->ops.get_phy_info = igb_get_phy_info_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000241 if (phy->id != M88E1111_I_PHY_ID)
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000242 phy->ops.get_cable_length =
243 igb_get_cable_length_m88_gen2;
244 else
245 phy->ops.get_cable_length = igb_get_cable_length_m88;
246 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700247 /* Check if this PHY is configured for media swap. */
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000248 if (phy->id == M88E1112_E_PHY_ID) {
249 u16 data;
250
251 ret_val = phy->ops.write_reg(hw,
252 E1000_M88E1112_PAGE_ADDR,
253 2);
254 if (ret_val)
255 goto out;
256
257 ret_val = phy->ops.read_reg(hw,
258 E1000_M88E1112_MAC_CTRL_1,
259 &data);
260 if (ret_val)
261 goto out;
262
263 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
264 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
265 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
266 data == E1000_M88E1112_AUTO_COPPER_BASEX)
267 hw->mac.ops.check_for_link =
268 igb_check_for_link_media_swap;
269 }
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700270 if (phy->id == M88E1512_E_PHY_ID) {
271 ret_val = igb_initialize_M88E1512_phy(hw);
272 if (ret_val)
273 goto out;
274 }
Todd Fujinaka18f7ce52015-09-02 16:54:20 -0700275 if (phy->id == M88E1543_E_PHY_ID) {
276 ret_val = igb_initialize_M88E1543_phy(hw);
277 if (ret_val)
278 goto out;
279 }
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000280 break;
281 case IGP03E1000_E_PHY_ID:
282 phy->type = e1000_phy_igp_3;
283 phy->ops.get_phy_info = igb_get_phy_info_igp;
284 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
285 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
286 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
287 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
288 break;
289 case I82580_I_PHY_ID:
290 case I350_I_PHY_ID:
291 phy->type = e1000_phy_82580;
292 phy->ops.force_speed_duplex =
293 igb_phy_force_speed_duplex_82580;
294 phy->ops.get_cable_length = igb_get_cable_length_82580;
295 phy->ops.get_phy_info = igb_get_phy_info_82580;
296 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
297 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
298 break;
299 case I210_I_PHY_ID:
300 phy->type = e1000_phy_i210;
301 phy->ops.check_polarity = igb_check_polarity_m88;
302 phy->ops.get_phy_info = igb_get_phy_info_m88;
303 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
304 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
305 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
306 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
307 break;
308 default:
309 ret_val = -E1000_ERR_PHY;
310 goto out;
311 }
312
313out:
314 return ret_val;
315}
316
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000317/**
318 * igb_init_nvm_params_82575 - Init NVM func ptrs.
319 * @hw: pointer to the HW structure
320 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000321static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000322{
323 struct e1000_nvm_info *nvm = &hw->nvm;
324 u32 eecd = rd32(E1000_EECD);
325 u16 size;
326
327 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
328 E1000_EECD_SIZE_EX_SHIFT);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000329
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000330 /* Added to a constant, "size" becomes the left-shift value
331 * for setting word_size.
332 */
333 size += NVM_WORD_SIZE_BASE_SHIFT;
334
335 /* Just in case size is out of range, cap it to the largest
336 * EEPROM size supported
337 */
338 if (size > 15)
339 size = 15;
340
341 nvm->word_size = 1 << size;
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000342 nvm->opcode_bits = 8;
343 nvm->delay_usec = 1;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000344
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000345 switch (nvm->override) {
346 case e1000_nvm_override_spi_large:
347 nvm->page_size = 32;
348 nvm->address_bits = 16;
349 break;
350 case e1000_nvm_override_spi_small:
351 nvm->page_size = 8;
352 nvm->address_bits = 8;
353 break;
354 default:
355 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
356 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
357 16 : 8;
358 break;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000359 }
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000360 if (nvm->word_size == (1 << 15))
361 nvm->page_size = 128;
362
363 nvm->type = e1000_nvm_eeprom_spi;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000364
365 /* NVM Function Pointers */
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000366 nvm->ops.acquire = igb_acquire_nvm_82575;
367 nvm->ops.release = igb_release_nvm_82575;
368 nvm->ops.write = igb_write_nvm_spi;
369 nvm->ops.validate = igb_validate_nvm_checksum;
370 nvm->ops.update = igb_update_nvm_checksum;
371 if (nvm->word_size < (1 << 15))
372 nvm->ops.read = igb_read_nvm_eerd;
373 else
374 nvm->ops.read = igb_read_nvm_spi;
375
376 /* override generic family function pointers for specific descendants */
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000377 switch (hw->mac.type) {
378 case e1000_82580:
379 nvm->ops.validate = igb_validate_nvm_checksum_82580;
380 nvm->ops.update = igb_update_nvm_checksum_82580;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000381 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000382 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000383 case e1000_i350:
384 nvm->ops.validate = igb_validate_nvm_checksum_i350;
385 nvm->ops.update = igb_update_nvm_checksum_i350;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000386 break;
387 default:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000388 break;
389 }
390
391 return 0;
392}
393
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000394/**
395 * igb_init_mac_params_82575 - Init MAC func ptrs.
396 * @hw: pointer to the HW structure
397 **/
398static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
399{
400 struct e1000_mac_info *mac = &hw->mac;
401 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
402
403 /* Set mta register count */
404 mac->mta_reg_count = 128;
405 /* Set rar entry count */
406 switch (mac->type) {
407 case e1000_82576:
408 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
409 break;
410 case e1000_82580:
411 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
412 break;
413 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000414 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000415 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
416 break;
417 default:
418 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
419 break;
420 }
421 /* reset */
422 if (mac->type >= e1000_82580)
423 mac->ops.reset_hw = igb_reset_hw_82580;
424 else
425 mac->ops.reset_hw = igb_reset_hw_82575;
426
427 if (mac->type >= e1000_i210) {
428 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
429 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
430
431 } else {
432 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
433 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
434 }
435
436 /* Set if part includes ASF firmware */
437 mac->asf_firmware_present = true;
438 /* Set if manageability features are enabled. */
439 mac->arc_subsystem_valid =
440 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
441 ? true : false;
442 /* enable EEE on i350 parts and later parts */
443 if (mac->type >= e1000_i350)
444 dev_spec->eee_disable = false;
445 else
446 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000447 /* Allow a single clear of the SW semaphore on I210 and newer */
448 if (mac->type >= e1000_i210)
449 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000450 /* physical interface link setup */
451 mac->ops.setup_physical_interface =
452 (hw->phy.media_type == e1000_media_type_copper)
453 ? igb_setup_copper_link_82575
454 : igb_setup_serdes_link_82575;
455
Carolyn Wyborny56cec242013-10-17 05:36:26 +0000456 if (mac->type == e1000_82580) {
457 switch (hw->device_id) {
458 /* feature not supported on these id's */
459 case E1000_DEV_ID_DH89XXCC_SGMII:
460 case E1000_DEV_ID_DH89XXCC_SERDES:
461 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
462 case E1000_DEV_ID_DH89XXCC_SFP:
463 break;
464 default:
465 hw->dev_spec._82575.mas_capable = true;
466 break;
467 }
468 }
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000469 return 0;
470}
471
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000472/**
473 * igb_set_sfp_media_type_82575 - derives SFP module media type.
474 * @hw: pointer to the HW structure
475 *
476 * The media type is chosen based on SFP module.
477 * compatibility flags retrieved from SFP ID EEPROM.
478 **/
479static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
480{
481 s32 ret_val = E1000_ERR_CONFIG;
482 u32 ctrl_ext = 0;
483 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
484 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
485 u8 tranceiver_type = 0;
486 s32 timeout = 3;
487
488 /* Turn I2C interface ON and power on sfp cage */
489 ctrl_ext = rd32(E1000_CTRL_EXT);
490 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
491 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
492
493 wrfl();
494
495 /* Read SFP module data */
496 while (timeout) {
497 ret_val = igb_read_sfp_data_byte(hw,
498 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
499 &tranceiver_type);
500 if (ret_val == 0)
501 break;
502 msleep(100);
503 timeout--;
504 }
505 if (ret_val != 0)
506 goto out;
507
508 ret_val = igb_read_sfp_data_byte(hw,
509 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
510 (u8 *)eth_flags);
511 if (ret_val != 0)
512 goto out;
513
514 /* Check if there is some SFP module plugged and powered */
515 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
516 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
517 dev_spec->module_plugged = true;
518 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
519 hw->phy.media_type = e1000_media_type_internal_serdes;
520 } else if (eth_flags->e100_base_fx) {
521 dev_spec->sgmii_active = true;
522 hw->phy.media_type = e1000_media_type_internal_serdes;
523 } else if (eth_flags->e1000_base_t) {
524 dev_spec->sgmii_active = true;
525 hw->phy.media_type = e1000_media_type_copper;
526 } else {
527 hw->phy.media_type = e1000_media_type_unknown;
528 hw_dbg("PHY module has not been recognized\n");
529 goto out;
530 }
531 } else {
532 hw->phy.media_type = e1000_media_type_unknown;
533 }
534 ret_val = 0;
535out:
536 /* Restore I2C interface setting */
537 wr32(E1000_CTRL_EXT, ctrl_ext);
538 return ret_val;
539}
540
Auke Kok9d5c8242008-01-24 02:22:38 -0800541static s32 igb_get_invariants_82575(struct e1000_hw *hw)
542{
Auke Kok9d5c8242008-01-24 02:22:38 -0800543 struct e1000_mac_info *mac = &hw->mac;
Carolyn Wybornyc4917c62014-04-11 01:45:48 +0000544 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800545 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800546 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000547 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800548
549 switch (hw->device_id) {
550 case E1000_DEV_ID_82575EB_COPPER:
551 case E1000_DEV_ID_82575EB_FIBER_SERDES:
552 case E1000_DEV_ID_82575GB_QUAD_COPPER:
553 mac->type = e1000_82575;
554 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700555 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000556 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000557 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700558 case E1000_DEV_ID_82576_FIBER:
559 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000560 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000561 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000562 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700563 mac->type = e1000_82576;
564 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000565 case E1000_DEV_ID_82580_COPPER:
566 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000567 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000568 case E1000_DEV_ID_82580_SERDES:
569 case E1000_DEV_ID_82580_SGMII:
570 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000571 case E1000_DEV_ID_DH89XXCC_SGMII:
572 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000573 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
574 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000575 mac->type = e1000_82580;
576 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000577 case E1000_DEV_ID_I350_COPPER:
578 case E1000_DEV_ID_I350_FIBER:
579 case E1000_DEV_ID_I350_SERDES:
580 case E1000_DEV_ID_I350_SGMII:
581 mac->type = e1000_i350;
582 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000583 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000584 case E1000_DEV_ID_I210_FIBER:
585 case E1000_DEV_ID_I210_SERDES:
586 case E1000_DEV_ID_I210_SGMII:
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +0000587 case E1000_DEV_ID_I210_COPPER_FLASHLESS:
588 case E1000_DEV_ID_I210_SERDES_FLASHLESS:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000589 mac->type = e1000_i210;
590 break;
591 case E1000_DEV_ID_I211_COPPER:
592 mac->type = e1000_i211;
593 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000594 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
595 case E1000_DEV_ID_I354_SGMII:
596 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
597 mac->type = e1000_i354;
598 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800599 default:
600 return -E1000_ERR_MAC_INIT;
Auke Kok9d5c8242008-01-24 02:22:38 -0800601 }
602
Auke Kok9d5c8242008-01-24 02:22:38 -0800603 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000604 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800605 * based on the EEPROM. We cannot rely upon device ID. There
606 * is no distinguishable difference between fiber and internal
607 * SerDes mode on the 82575. There can be an external PHY attached
608 * on the SGMII interface. For this, we'll set sgmii_active to true.
609 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000610 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800611 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000612 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800613
614 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000615
616 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
617 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000618 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000619 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000620 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000621 case E1000_CTRL_EXT_LINK_MODE_SGMII:
622 /* Get phy control interface type set (MDIO vs. I2C)*/
623 if (igb_sgmii_uses_mdio_82575(hw)) {
624 hw->phy.media_type = e1000_media_type_copper;
625 dev_spec->sgmii_active = true;
626 break;
627 }
628 /* fall through for I2C based SGMII */
629 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
630 /* read media type from SFP EEPROM */
631 ret_val = igb_set_sfp_media_type_82575(hw);
632 if ((ret_val != 0) ||
633 (hw->phy.media_type == e1000_media_type_unknown)) {
634 /* If media type was not identified then return media
635 * type defined by the CTRL_EXT settings.
636 */
637 hw->phy.media_type = e1000_media_type_internal_serdes;
638
639 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
640 hw->phy.media_type = e1000_media_type_copper;
641 dev_spec->sgmii_active = true;
642 }
643
644 break;
645 }
646
647 /* do not change link mode for 100BaseFX */
648 if (dev_spec->eth_flags.e100_base_fx)
649 break;
650
651 /* change current link mode setting */
652 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
653
654 if (hw->phy.media_type == e1000_media_type_copper)
655 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
656 else
657 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
658
659 wr32(E1000_CTRL_EXT, ctrl_ext);
660
661 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000662 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000663 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800664 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000665
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000666 /* mac initialization and operations */
667 ret_val = igb_init_mac_params_82575(hw);
668 if (ret_val)
669 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800670
671 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000672 ret_val = igb_init_nvm_params_82575(hw);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000673 switch (hw->mac.type) {
674 case e1000_i210:
675 case e1000_i211:
676 ret_val = igb_init_nvm_params_i210(hw);
677 break;
678 default:
679 break;
680 }
681
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000682 if (ret_val)
683 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800684
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000685 /* if part supports SR-IOV then initialize mailbox parameters */
686 switch (mac->type) {
687 case e1000_82576:
688 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000689 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000690 break;
691 default:
692 break;
693 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000694
Auke Kok9d5c8242008-01-24 02:22:38 -0800695 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000696 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800697
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000698out:
699 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800700}
701
702/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700703 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800704 * @hw: pointer to the HW structure
705 *
706 * Acquire access rights to the correct PHY. This is a
707 * function pointer entry point called by the api module.
708 **/
709static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
710{
Alexander Duyck008c3422009-10-05 06:32:07 +0000711 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800712
Alexander Duyck008c3422009-10-05 06:32:07 +0000713 if (hw->bus.func == E1000_FUNC_1)
714 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000715 else if (hw->bus.func == E1000_FUNC_2)
716 mask = E1000_SWFW_PHY2_SM;
717 else if (hw->bus.func == E1000_FUNC_3)
718 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800719
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000720 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800721}
722
723/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700724 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800725 * @hw: pointer to the HW structure
726 *
727 * A wrapper to release access rights to the correct PHY. This is a
728 * function pointer entry point called by the api module.
729 **/
730static void igb_release_phy_82575(struct e1000_hw *hw)
731{
Alexander Duyck008c3422009-10-05 06:32:07 +0000732 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800733
Alexander Duyck008c3422009-10-05 06:32:07 +0000734 if (hw->bus.func == E1000_FUNC_1)
735 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000736 else if (hw->bus.func == E1000_FUNC_2)
737 mask = E1000_SWFW_PHY2_SM;
738 else if (hw->bus.func == E1000_FUNC_3)
739 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000740
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000741 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800742}
743
744/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700745 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800746 * @hw: pointer to the HW structure
747 * @offset: register offset to be read
748 * @data: pointer to the read data
749 *
750 * Reads the PHY register at offset using the serial gigabit media independent
751 * interface and stores the retrieved information in data.
752 **/
753static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
754 u16 *data)
755{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000756 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800757
758 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700759 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000760 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800761 }
762
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000763 ret_val = hw->phy.ops.acquire(hw);
764 if (ret_val)
765 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800766
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000767 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800768
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000769 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800770
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000771out:
772 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800773}
774
775/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700776 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800777 * @hw: pointer to the HW structure
778 * @offset: register offset to write to
779 * @data: data to write at register offset
780 *
781 * Writes the data to PHY register at the offset using the serial gigabit
782 * media independent interface.
783 **/
784static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
785 u16 data)
786{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000787 s32 ret_val = -E1000_ERR_PARAM;
788
Auke Kok9d5c8242008-01-24 02:22:38 -0800789
790 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700791 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000792 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800793 }
794
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000795 ret_val = hw->phy.ops.acquire(hw);
796 if (ret_val)
797 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800798
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000799 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800800
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000801 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800802
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000803out:
804 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800805}
806
807/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700808 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800809 * @hw: pointer to the HW structure
810 *
Auke Kok652fff32008-06-27 11:00:18 -0700811 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800812 * sgmi interface.
813 **/
814static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
815{
816 struct e1000_phy_info *phy = &hw->phy;
817 s32 ret_val = 0;
818 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000819 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000820 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800821
Carolyn Wybornybb1d18d2013-09-10 11:57:16 -0700822 /* Extra read required for some PHY's on i354 */
823 if (hw->mac.type == e1000_i354)
824 igb_get_phy_id(hw);
825
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000826 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800827 * we find one that works. For non-SGMII PHYs
828 * (e.g. integrated copper PHYs), an address of 1 should
829 * work. The result of this function should mean phy->phy_addr
830 * and phy->id are set correctly.
831 */
832 if (!(igb_sgmii_active_82575(hw))) {
833 phy->addr = 1;
834 ret_val = igb_get_phy_id(hw);
835 goto out;
836 }
837
Nick Nunley4085f742010-07-26 13:15:06 +0000838 if (igb_sgmii_uses_mdio_82575(hw)) {
839 switch (hw->mac.type) {
840 case e1000_82575:
841 case e1000_82576:
842 mdic = rd32(E1000_MDIC);
843 mdic &= E1000_MDIC_PHY_MASK;
844 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
845 break;
846 case e1000_82580:
847 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000848 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000849 case e1000_i210:
850 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000851 mdic = rd32(E1000_MDICNFG);
852 mdic &= E1000_MDICNFG_PHY_MASK;
853 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
854 break;
855 default:
856 ret_val = -E1000_ERR_PHY;
857 goto out;
Nick Nunley4085f742010-07-26 13:15:06 +0000858 }
859 ret_val = igb_get_phy_id(hw);
860 goto out;
861 }
862
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000863 /* Power on sgmii phy if it is disabled */
864 ctrl_ext = rd32(E1000_CTRL_EXT);
865 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
866 wrfl();
867 msleep(300);
868
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000869 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800870 * Therefore, we need to test 1-7
871 */
872 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
873 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
874 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700875 hw_dbg("Vendor ID 0x%08X read at address %u\n",
876 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000877 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800878 * the only supported SGMII PHY product.
879 */
880 if (phy_id == M88_VENDOR)
881 break;
882 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700883 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800884 }
885 }
886
887 /* A valid PHY type couldn't be found. */
888 if (phy->addr == 8) {
889 phy->addr = 0;
890 ret_val = -E1000_ERR_PHY;
891 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000892 } else {
893 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800894 }
895
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000896 /* restore previous sfp cage power state */
897 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800898
899out:
900 return ret_val;
901}
902
903/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700904 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800905 * @hw: pointer to the HW structure
906 *
907 * Resets the PHY using the serial gigabit media independent interface.
908 **/
909static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
910{
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700911 struct e1000_phy_info *phy = &hw->phy;
Auke Kok9d5c8242008-01-24 02:22:38 -0800912 s32 ret_val;
913
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000914 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800915 * available to us at this time.
916 */
917
Auke Kok652fff32008-06-27 11:00:18 -0700918 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800919
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000920 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800921 * to work on SGMII. No further documentation is given.
922 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000923 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800924 if (ret_val)
925 goto out;
926
927 ret_val = igb_phy_sw_reset(hw);
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700928 if (ret_val)
929 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800930
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700931 if (phy->id == M88E1512_E_PHY_ID)
932 ret_val = igb_initialize_M88E1512_phy(hw);
Todd Fujinaka18f7ce52015-09-02 16:54:20 -0700933 if (phy->id == M88E1543_E_PHY_ID)
934 ret_val = igb_initialize_M88E1543_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800935out:
936 return ret_val;
937}
938
939/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700940 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800941 * @hw: pointer to the HW structure
942 * @active: true to enable LPLU, false to disable
943 *
944 * Sets the LPLU D0 state according to the active flag. When
945 * activating LPLU this function also disables smart speed
946 * and vice versa. LPLU will not be activated unless the
947 * device autonegotiation advertisement meets standards of
948 * either 10 or 10/100 or 10/100/1000 at all duplexes.
949 * This is a function pointer entry point only called by
950 * PHY setup routines.
951 **/
952static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
953{
954 struct e1000_phy_info *phy = &hw->phy;
955 s32 ret_val;
956 u16 data;
957
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000958 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800959 if (ret_val)
960 goto out;
961
962 if (active) {
963 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000964 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700965 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800966 if (ret_val)
967 goto out;
968
969 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000970 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700971 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800972 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000973 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700974 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800975 if (ret_val)
976 goto out;
977 } else {
978 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000979 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700980 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000981 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -0800982 * during Dx states where the power conservation is most
983 * important. During driver activity we should enable
984 * SmartSpeed, so performance is maintained.
985 */
986 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000987 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700988 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800989 if (ret_val)
990 goto out;
991
992 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000993 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700994 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800995 if (ret_val)
996 goto out;
997 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000998 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700999 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 if (ret_val)
1001 goto out;
1002
1003 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001004 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001005 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001006 if (ret_val)
1007 goto out;
1008 }
1009 }
1010
1011out:
1012 return ret_val;
1013}
1014
1015/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001016 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
1017 * @hw: pointer to the HW structure
1018 * @active: true to enable LPLU, false to disable
1019 *
1020 * Sets the LPLU D0 state according to the active flag. When
1021 * activating LPLU this function also disables smart speed
1022 * and vice versa. LPLU will not be activated unless the
1023 * device autonegotiation advertisement meets standards of
1024 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1025 * This is a function pointer entry point only called by
1026 * PHY setup routines.
1027 **/
1028static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
1029{
1030 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001031 u16 data;
1032
1033 data = rd32(E1000_82580_PHY_POWER_MGMT);
1034
1035 if (active) {
1036 data |= E1000_82580_PM_D0_LPLU;
1037
1038 /* When LPLU is enabled, we should disable SmartSpeed */
1039 data &= ~E1000_82580_PM_SPD;
1040 } else {
1041 data &= ~E1000_82580_PM_D0_LPLU;
1042
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001043 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001044 * during Dx states where the power conservation is most
1045 * important. During driver activity we should enable
1046 * SmartSpeed, so performance is maintained.
1047 */
1048 if (phy->smart_speed == e1000_smart_speed_on)
1049 data |= E1000_82580_PM_SPD;
1050 else if (phy->smart_speed == e1000_smart_speed_off)
1051 data &= ~E1000_82580_PM_SPD; }
1052
1053 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001054 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001055}
1056
1057/**
1058 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1059 * @hw: pointer to the HW structure
1060 * @active: boolean used to enable/disable lplu
1061 *
1062 * Success returns 0, Failure returns 1
1063 *
1064 * The low power link up (lplu) state is set to the power management level D3
1065 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1066 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1067 * is used during Dx states where the power conservation is most important.
1068 * During driver activity, SmartSpeed should be enabled so performance is
1069 * maintained.
1070 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +00001071static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001072{
1073 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001074 u16 data;
1075
1076 data = rd32(E1000_82580_PHY_POWER_MGMT);
1077
1078 if (!active) {
1079 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001080 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001081 * during Dx states where the power conservation is most
1082 * important. During driver activity we should enable
1083 * SmartSpeed, so performance is maintained.
1084 */
1085 if (phy->smart_speed == e1000_smart_speed_on)
1086 data |= E1000_82580_PM_SPD;
1087 else if (phy->smart_speed == e1000_smart_speed_off)
1088 data &= ~E1000_82580_PM_SPD;
1089 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1090 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1091 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1092 data |= E1000_82580_PM_D3_LPLU;
1093 /* When LPLU is enabled, we should disable SmartSpeed */
1094 data &= ~E1000_82580_PM_SPD;
1095 }
1096
1097 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001098 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001099}
1100
1101/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001102 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001103 * @hw: pointer to the HW structure
1104 *
Auke Kok652fff32008-06-27 11:00:18 -07001105 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001106 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1107 * Return successful if access grant bit set, else clear the request for
1108 * EEPROM access and return -E1000_ERR_NVM (-1).
1109 **/
1110static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1111{
1112 s32 ret_val;
1113
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001114 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001115 if (ret_val)
1116 goto out;
1117
1118 ret_val = igb_acquire_nvm(hw);
1119
1120 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001121 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001122
1123out:
1124 return ret_val;
1125}
1126
1127/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001128 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001129 * @hw: pointer to the HW structure
1130 *
1131 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1132 * then release the semaphores acquired.
1133 **/
1134static void igb_release_nvm_82575(struct e1000_hw *hw)
1135{
1136 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001137 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001138}
1139
1140/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001141 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001142 * @hw: pointer to the HW structure
1143 * @mask: specifies which semaphore to acquire
1144 *
1145 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1146 * will also specify which port we're acquiring the lock for.
1147 **/
1148static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1149{
1150 u32 swfw_sync;
1151 u32 swmask = mask;
1152 u32 fwmask = mask << 16;
1153 s32 ret_val = 0;
Todd Fujinaka2184aa32014-11-27 01:00:02 +00001154 s32 i = 0, timeout = 200;
Auke Kok9d5c8242008-01-24 02:22:38 -08001155
1156 while (i < timeout) {
1157 if (igb_get_hw_semaphore(hw)) {
1158 ret_val = -E1000_ERR_SWFW_SYNC;
1159 goto out;
1160 }
1161
1162 swfw_sync = rd32(E1000_SW_FW_SYNC);
1163 if (!(swfw_sync & (fwmask | swmask)))
1164 break;
1165
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001166 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001167 * or other software thread using resource (swmask)
1168 */
1169 igb_put_hw_semaphore(hw);
1170 mdelay(5);
1171 i++;
1172 }
1173
1174 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001175 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001176 ret_val = -E1000_ERR_SWFW_SYNC;
1177 goto out;
1178 }
1179
1180 swfw_sync |= swmask;
1181 wr32(E1000_SW_FW_SYNC, swfw_sync);
1182
1183 igb_put_hw_semaphore(hw);
1184
1185out:
1186 return ret_val;
1187}
1188
1189/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001190 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001191 * @hw: pointer to the HW structure
1192 * @mask: specifies which semaphore to acquire
1193 *
1194 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1195 * will also specify which port we're releasing the lock for.
1196 **/
1197static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1198{
1199 u32 swfw_sync;
1200
Carolyn Wybornybed83e92014-04-11 01:45:55 +00001201 while (igb_get_hw_semaphore(hw) != 0)
1202 ; /* Empty */
Auke Kok9d5c8242008-01-24 02:22:38 -08001203
1204 swfw_sync = rd32(E1000_SW_FW_SYNC);
1205 swfw_sync &= ~mask;
1206 wr32(E1000_SW_FW_SYNC, swfw_sync);
1207
1208 igb_put_hw_semaphore(hw);
1209}
1210
1211/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001212 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001213 * @hw: pointer to the HW structure
1214 *
1215 * Read the management control register for the config done bit for
1216 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1217 * to read the config done bit, so an error is *ONLY* logged and returns
1218 * 0. If we were to return with error, EEPROM-less silicon
1219 * would not be able to be reset or change link.
1220 **/
1221static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1222{
1223 s32 timeout = PHY_CFG_TIMEOUT;
Auke Kok9d5c8242008-01-24 02:22:38 -08001224 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1225
1226 if (hw->bus.func == 1)
1227 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001228 else if (hw->bus.func == E1000_FUNC_2)
1229 mask = E1000_NVM_CFG_DONE_PORT_2;
1230 else if (hw->bus.func == E1000_FUNC_3)
1231 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001232
1233 while (timeout) {
1234 if (rd32(E1000_EEMNGCTL) & mask)
1235 break;
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001236 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001237 timeout--;
1238 }
1239 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001240 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001241
1242 /* If EEPROM is not marked present, init the PHY manually */
1243 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1244 (hw->phy.type == e1000_phy_igp_3))
1245 igb_phy_init_script_igp3(hw);
1246
Todd Fujinaka23d87822014-06-04 07:12:15 +00001247 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001248}
1249
1250/**
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00001251 * igb_get_link_up_info_82575 - Get link speed/duplex info
1252 * @hw: pointer to the HW structure
1253 * @speed: stores the current speed
1254 * @duplex: stores the current duplex
1255 *
1256 * This is a wrapper function, if using the serial gigabit media independent
1257 * interface, use PCS to retrieve the link speed and duplex information.
1258 * Otherwise, use the generic function to get the link speed and duplex info.
1259 **/
1260static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1261 u16 *duplex)
1262{
1263 s32 ret_val;
1264
1265 if (hw->phy.media_type != e1000_media_type_copper)
1266 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
1267 duplex);
1268 else
1269 ret_val = igb_get_speed_and_duplex_copper(hw, speed,
1270 duplex);
1271
1272 return ret_val;
1273}
1274
1275/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001276 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001277 * @hw: pointer to the HW structure
1278 *
1279 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1280 * use the generic interface for determining link.
1281 **/
1282static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1283{
1284 s32 ret_val;
1285 u16 speed, duplex;
1286
Alexander Duyck70d92f82009-10-05 06:31:47 +00001287 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001288 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001289 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001290 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001291 * not. If we have link clear the flag so that we do not
1292 * continue to check for link.
1293 */
1294 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001295
1296 /* Configure Flow Control now that Auto-Neg has completed.
1297 * First, we need to restore the desired flow control
1298 * settings because we may have had to re-autoneg with a
1299 * different link partner.
1300 */
1301 ret_val = igb_config_fc_after_link_up(hw);
1302 if (ret_val)
1303 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001304 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001305 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001306 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001307
1308 return ret_val;
1309}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001310
Auke Kok9d5c8242008-01-24 02:22:38 -08001311/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001312 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1313 * @hw: pointer to the HW structure
1314 **/
1315void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1316{
1317 u32 reg;
1318
1319
1320 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1321 !igb_sgmii_active_82575(hw))
1322 return;
1323
1324 /* Enable PCS to turn on link */
1325 reg = rd32(E1000_PCS_CFG0);
1326 reg |= E1000_PCS_CFG_PCS_EN;
1327 wr32(E1000_PCS_CFG0, reg);
1328
1329 /* Power up the laser */
1330 reg = rd32(E1000_CTRL_EXT);
1331 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1332 wr32(E1000_CTRL_EXT, reg);
1333
1334 /* flush the write to verify completion */
1335 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001336 usleep_range(1000, 2000);
Nick Nunley88a268c2010-02-17 01:01:59 +00001337}
1338
1339/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001340 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001341 * @hw: pointer to the HW structure
1342 * @speed: stores the current speed
1343 * @duplex: stores the current duplex
1344 *
Auke Kok652fff32008-06-27 11:00:18 -07001345 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001346 * duplex, then store the values in the pointers provided.
1347 **/
1348static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1349 u16 *duplex)
1350{
1351 struct e1000_mac_info *mac = &hw->mac;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001352 u32 pcs, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08001353
1354 /* Set up defaults for the return values of this function */
1355 mac->serdes_has_link = false;
1356 *speed = 0;
1357 *duplex = 0;
1358
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001359 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001360 * the status register is not accurate. The PCS status register is
1361 * used instead.
1362 */
1363 pcs = rd32(E1000_PCS_LSTAT);
1364
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001365 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001366 * gets set once both sides sync up and agree upon link. Stable link
1367 * can be determined by checking for both link up and link sync ok
1368 */
1369 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1370 mac->serdes_has_link = true;
1371
1372 /* Detect and store PCS speed */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001373 if (pcs & E1000_PCS_LSTS_SPEED_1000)
Auke Kok9d5c8242008-01-24 02:22:38 -08001374 *speed = SPEED_1000;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001375 else if (pcs & E1000_PCS_LSTS_SPEED_100)
Auke Kok9d5c8242008-01-24 02:22:38 -08001376 *speed = SPEED_100;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001377 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001378 *speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -08001379
1380 /* Detect and store PCS duplex */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001381 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
Auke Kok9d5c8242008-01-24 02:22:38 -08001382 *duplex = FULL_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001383 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001384 *duplex = HALF_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001385
1386 /* Check if it is an I354 2.5Gb backplane connection. */
1387 if (mac->type == e1000_i354) {
1388 status = rd32(E1000_STATUS);
1389 if ((status & E1000_STATUS_2P5_SKU) &&
1390 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1391 *speed = SPEED_2500;
1392 *duplex = FULL_DUPLEX;
1393 hw_dbg("2500 Mbs, ");
1394 hw_dbg("Full Duplex\n");
1395 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001396 }
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001397
Auke Kok9d5c8242008-01-24 02:22:38 -08001398 }
1399
1400 return 0;
1401}
1402
1403/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001404 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001405 * @hw: pointer to the HW structure
1406 *
1407 * In the case of fiber serdes, shut down optics and PCS on driver unload
1408 * when management pass thru is not enabled.
1409 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001410void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001411{
1412 u32 reg;
1413
Nick Nunley53c992f2010-02-17 01:01:40 +00001414 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001415 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001416 return;
1417
Nick Nunley53c992f2010-02-17 01:01:40 +00001418 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001419 /* Disable PCS to turn off link */
1420 reg = rd32(E1000_PCS_CFG0);
1421 reg &= ~E1000_PCS_CFG_PCS_EN;
1422 wr32(E1000_PCS_CFG0, reg);
1423
1424 /* shutdown the laser */
1425 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001426 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001427 wr32(E1000_CTRL_EXT, reg);
1428
1429 /* flush the write to verify completion */
1430 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001431 usleep_range(1000, 2000);
Alexander Duyck2d064c02008-07-08 15:10:12 -07001432 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001433}
1434
1435/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001436 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001437 * @hw: pointer to the HW structure
1438 *
1439 * This resets the hardware into a known state. This is a
1440 * function pointer entry point called by the api module.
1441 **/
1442static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1443{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001444 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001445 s32 ret_val;
1446
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001447 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001448 * on the last TLP read/write transaction when MAC is reset.
1449 */
1450 ret_val = igb_disable_pcie_master(hw);
1451 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001452 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001453
Alexander Duyck009bc062009-07-23 18:08:35 +00001454 /* set the completion timeout for interface */
1455 ret_val = igb_set_pcie_completion_timeout(hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001456 if (ret_val)
Alexander Duyck009bc062009-07-23 18:08:35 +00001457 hw_dbg("PCI-E Set completion timeout has failed.\n");
Alexander Duyck009bc062009-07-23 18:08:35 +00001458
Auke Kok652fff32008-06-27 11:00:18 -07001459 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001460 wr32(E1000_IMC, 0xffffffff);
1461
1462 wr32(E1000_RCTL, 0);
1463 wr32(E1000_TCTL, E1000_TCTL_PSP);
1464 wrfl();
1465
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001466 usleep_range(10000, 20000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001467
1468 ctrl = rd32(E1000_CTRL);
1469
Auke Kok652fff32008-06-27 11:00:18 -07001470 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001471 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1472
1473 ret_val = igb_get_auto_rd_done(hw);
1474 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001475 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001476 * return with an error. This can happen in situations
1477 * where there is no eeprom and prevents getting link.
1478 */
Auke Kok652fff32008-06-27 11:00:18 -07001479 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001480 }
1481
1482 /* If EEPROM is not present, run manual init scripts */
1483 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1484 igb_reset_init_script_82575(hw);
1485
1486 /* Clear any pending interrupt events. */
1487 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001488 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001489
Alexander Duyck5ac16652009-07-23 18:09:12 +00001490 /* Install any alternate MAC address into RAR0 */
1491 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001492
1493 return ret_val;
1494}
1495
1496/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001497 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001498 * @hw: pointer to the HW structure
1499 *
1500 * This inits the hardware readying it for operation.
1501 **/
1502static s32 igb_init_hw_82575(struct e1000_hw *hw)
1503{
1504 struct e1000_mac_info *mac = &hw->mac;
1505 s32 ret_val;
1506 u16 i, rar_count = mac->rar_entry_count;
1507
Todd Fujinaka94826482014-07-10 01:47:15 -07001508 if ((hw->mac.type >= e1000_i210) &&
1509 !(igb_get_flash_presence_i210(hw))) {
1510 ret_val = igb_pll_workaround_i210(hw);
1511 if (ret_val)
1512 return ret_val;
1513 }
1514
Auke Kok9d5c8242008-01-24 02:22:38 -08001515 /* Initialize identification LED */
1516 ret_val = igb_id_led_init(hw);
1517 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001518 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001519 /* This is not fatal and we should not stop init due to this */
1520 }
1521
1522 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001523 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001524 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001525 igb_clear_vfta_i350(hw);
1526 else
1527 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001528
1529 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001530 igb_init_rx_addrs(hw, rar_count);
1531
Auke Kok9d5c8242008-01-24 02:22:38 -08001532 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001533 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001534 for (i = 0; i < mac->mta_reg_count; i++)
1535 array_wr32(E1000_MTA, i, 0);
1536
Alexander Duyck68d480c2009-10-05 06:33:08 +00001537 /* Zero out the Unicast HASH table */
1538 hw_dbg("Zeroing the UTA\n");
1539 for (i = 0; i < mac->uta_reg_count; i++)
1540 array_wr32(E1000_UTA, i, 0);
1541
Auke Kok9d5c8242008-01-24 02:22:38 -08001542 /* Setup link and flow control */
1543 ret_val = igb_setup_link(hw);
1544
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001545 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001546 * important that we do this after we have tried to establish link
1547 * because the symbol error count will increment wildly if there
1548 * is no link.
1549 */
1550 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001551 return ret_val;
1552}
1553
1554/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001555 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001556 * @hw: pointer to the HW structure
1557 *
1558 * Configures the link for auto-neg or forced speed and duplex. Then we check
1559 * for link, once link is established calls to configure collision distance
1560 * and flow control are called.
1561 **/
1562static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1563{
Alexander Duyck12645a12009-07-23 18:08:16 +00001564 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001565 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001566 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001567
1568 ctrl = rd32(E1000_CTRL);
1569 ctrl |= E1000_CTRL_SLU;
1570 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1571 wr32(E1000_CTRL, ctrl);
1572
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001573 /* Clear Go Link Disconnect bit on supported devices */
1574 switch (hw->mac.type) {
1575 case e1000_82580:
1576 case e1000_i350:
1577 case e1000_i210:
1578 case e1000_i211:
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001579 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1580 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1581 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001582 break;
1583 default:
1584 break;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001585 }
1586
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001587 ret_val = igb_setup_serdes_link_82575(hw);
1588 if (ret_val)
1589 goto out;
1590
1591 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001592 /* allow time for SFP cage time to power up phy */
1593 msleep(300);
1594
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001595 ret_val = hw->phy.ops.reset(hw);
1596 if (ret_val) {
1597 hw_dbg("Error resetting the PHY.\n");
1598 goto out;
1599 }
1600 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001601 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001602 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001603 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001604 switch (hw->phy.id) {
1605 case I347AT4_E_PHY_ID:
1606 case M88E1112_E_PHY_ID:
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001607 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001608 case M88E1512_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001609 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001610 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001611 break;
1612 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001613 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001614 break;
1615 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001616 break;
1617 case e1000_phy_igp_3:
1618 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001619 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001620 case e1000_phy_82580:
1621 ret_val = igb_copper_link_setup_82580(hw);
1622 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001623 default:
1624 ret_val = -E1000_ERR_PHY;
1625 break;
1626 }
1627
1628 if (ret_val)
1629 goto out;
1630
Alexander Duyck81fadd82009-10-05 06:35:03 +00001631 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001632out:
1633 return ret_val;
1634}
1635
1636/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001637 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001638 * @hw: pointer to the HW structure
1639 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001640 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1641 * used on copper connections where the serialized gigabit media independent
1642 * interface (sgmii), or serdes fiber is being used. Configures the link
1643 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001645static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001646{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001647 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001648 bool pcs_autoneg;
Todd Fujinaka23d87822014-06-04 07:12:15 +00001649 s32 ret_val = 0;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001650 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001651
1652 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1653 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001654 return ret_val;
1655
Auke Kok9d5c8242008-01-24 02:22:38 -08001656
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001657 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001658 * explicitly turned off or a power cycle is performed. A read to
1659 * the register does not indicate its status. Therefore, we ensure
1660 * loopback mode is disabled during initialization.
1661 */
1662 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1663
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001664 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001665 ctrl_ext = rd32(E1000_CTRL_EXT);
1666 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001667 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001668 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001669
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001670 ctrl_reg = rd32(E1000_CTRL);
1671 ctrl_reg |= E1000_CTRL_SLU;
1672
1673 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1674 /* set both sw defined pins */
1675 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1676
1677 /* Set switch control to serdes energy detect */
1678 reg = rd32(E1000_CONNSW);
1679 reg |= E1000_CONNSW_ENRGSRC;
1680 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001681 }
1682
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001683 reg = rd32(E1000_PCS_LCTL);
1684
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001685 /* default pcs_autoneg to the same setting as mac autoneg */
1686 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001687
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001688 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1689 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1690 /* sgmii mode lets the phy handle forcing speed/duplex */
1691 pcs_autoneg = true;
1692 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001693 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001694 break;
1695 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1696 /* disable PCS autoneg and support parallel detect only */
1697 pcs_autoneg = false;
1698 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001699 if (hw->mac.type == e1000_82575 ||
1700 hw->mac.type == e1000_82576) {
1701 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1702 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00001703 hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001704 return ret_val;
1705 }
1706
1707 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1708 pcs_autoneg = false;
1709 }
1710
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001711 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001712 * link so it is best to just force the MAC and let the pcs
1713 * link either autoneg or be forced to 1000/Full
1714 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001715 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001716 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001717
1718 /* set speed of 1000/Full if speed/duplex is forced */
1719 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1720 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001721 }
1722
1723 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001724
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001725 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001726 * at 1gb. Autoneg should be default set by most drivers. This is the
1727 * mode that will be compatible with older link partners and switches.
1728 * However, both are supported by the hardware and some drivers/tools.
1729 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001730 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1731 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1732
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001733 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001734 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001735 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001736 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001737
1738 /* Disable force flow control for autoneg */
1739 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1740
1741 /* Configure flow control advertisement for autoneg */
1742 anadv_reg = rd32(E1000_PCS_ANADV);
1743 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1744 switch (hw->fc.requested_mode) {
1745 case e1000_fc_full:
1746 case e1000_fc_rx_pause:
1747 anadv_reg |= E1000_TXCW_ASM_DIR;
1748 anadv_reg |= E1000_TXCW_PAUSE;
1749 break;
1750 case e1000_fc_tx_pause:
1751 anadv_reg |= E1000_TXCW_ASM_DIR;
1752 break;
1753 default:
1754 break;
1755 }
1756 wr32(E1000_PCS_ANADV, anadv_reg);
1757
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001758 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001759 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001760 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001761 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001762
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001763 /* Force flow control for forced link */
1764 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1765
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001766 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001767 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001768
Auke Kok9d5c8242008-01-24 02:22:38 -08001769 wr32(E1000_PCS_LCTL, reg);
1770
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001771 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001772 igb_force_mac_fc(hw);
1773
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001774 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001775}
1776
1777/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001778 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001779 * @hw: pointer to the HW structure
1780 *
1781 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1782 * which can be enabled for use in the embedded applications. Simply
1783 * return the current state of the sgmii interface.
1784 **/
1785static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1786{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001787 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001788 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001789}
1790
1791/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001792 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001793 * @hw: pointer to the HW structure
1794 *
1795 * Inits recommended HW defaults after a reset when there is no EEPROM
1796 * detected. This is only for the 82575.
1797 **/
1798static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1799{
1800 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001801 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001802 /* SerDes configuration via SERDESCTRL */
1803 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1804 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1805 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1806 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1807
1808 /* CCM configuration via CCMCTL register */
1809 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1810 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1811
1812 /* PCIe lanes configuration */
1813 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1814 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1815 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1816 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1817
1818 /* PCIe PLL Configuration */
1819 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1820 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1821 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1822 }
1823
1824 return 0;
1825}
1826
1827/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001828 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001829 * @hw: pointer to the HW structure
1830 **/
1831static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1832{
1833 s32 ret_val = 0;
1834
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001835 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001836 * so that it will override the Si installed default perm
1837 * address.
1838 */
1839 ret_val = igb_check_alt_mac_addr(hw);
1840 if (ret_val)
1841 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001842
Alexander Duyck22896632009-10-05 06:34:25 +00001843 ret_val = igb_read_mac_addr(hw);
1844
1845out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001846 return ret_val;
1847}
1848
1849/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001850 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1851 * @hw: pointer to the HW structure
1852 *
1853 * In the case of a PHY power down to save power, or to turn off link during a
1854 * driver unload, or wake on lan is not enabled, remove the link.
1855 **/
1856void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1857{
1858 /* If the management interface is not enabled, then power down */
1859 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1860 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001861}
1862
1863/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001864 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001865 * @hw: pointer to the HW structure
1866 *
1867 * Clears the hardware counters by reading the counter registers.
1868 **/
1869static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1870{
Auke Kok9d5c8242008-01-24 02:22:38 -08001871 igb_clear_hw_cntrs_base(hw);
1872
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001873 rd32(E1000_PRC64);
1874 rd32(E1000_PRC127);
1875 rd32(E1000_PRC255);
1876 rd32(E1000_PRC511);
1877 rd32(E1000_PRC1023);
1878 rd32(E1000_PRC1522);
1879 rd32(E1000_PTC64);
1880 rd32(E1000_PTC127);
1881 rd32(E1000_PTC255);
1882 rd32(E1000_PTC511);
1883 rd32(E1000_PTC1023);
1884 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001885
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001886 rd32(E1000_ALGNERRC);
1887 rd32(E1000_RXERRC);
1888 rd32(E1000_TNCRS);
1889 rd32(E1000_CEXTERR);
1890 rd32(E1000_TSCTC);
1891 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001892
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001893 rd32(E1000_MGTPRC);
1894 rd32(E1000_MGTPDC);
1895 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001896
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001897 rd32(E1000_IAC);
1898 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001899
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001900 rd32(E1000_ICRXPTC);
1901 rd32(E1000_ICRXATC);
1902 rd32(E1000_ICTXPTC);
1903 rd32(E1000_ICTXATC);
1904 rd32(E1000_ICTXQEC);
1905 rd32(E1000_ICTXQMTC);
1906 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001907
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001908 rd32(E1000_CBTMPC);
1909 rd32(E1000_HTDPMC);
1910 rd32(E1000_CBRMPC);
1911 rd32(E1000_RPTHC);
1912 rd32(E1000_HGPTC);
1913 rd32(E1000_HTCBDPC);
1914 rd32(E1000_HGORCL);
1915 rd32(E1000_HGORCH);
1916 rd32(E1000_HGOTCL);
1917 rd32(E1000_HGOTCH);
1918 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001919
1920 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001921 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1922 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001923 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001924}
1925
Alexander Duyck662d7202008-06-27 11:00:29 -07001926/**
1927 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1928 * @hw: pointer to the HW structure
1929 *
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001930 * After rx enable if manageability is enabled then there is likely some
1931 * bad data at the start of the fifo and possibly in the DMA fifo. This
Alexander Duyck662d7202008-06-27 11:00:29 -07001932 * function clears the fifos and flushes any packets that came in as rx was
1933 * being enabled.
1934 **/
1935void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1936{
1937 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1938 int i, ms_wait;
1939
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001940 /* disable IPv6 options as per hardware errata */
1941 rfctl = rd32(E1000_RFCTL);
1942 rfctl |= E1000_RFCTL_IPV6_EX_DIS;
1943 wr32(E1000_RFCTL, rfctl);
1944
Alexander Duyck662d7202008-06-27 11:00:29 -07001945 if (hw->mac.type != e1000_82575 ||
1946 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1947 return;
1948
1949 /* Disable all RX queues */
1950 for (i = 0; i < 4; i++) {
1951 rxdctl[i] = rd32(E1000_RXDCTL(i));
1952 wr32(E1000_RXDCTL(i),
1953 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1954 }
1955 /* Poll all queues to verify they have shut down */
1956 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001957 usleep_range(1000, 2000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001958 rx_enabled = 0;
1959 for (i = 0; i < 4; i++)
1960 rx_enabled |= rd32(E1000_RXDCTL(i));
1961 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1962 break;
1963 }
1964
1965 if (ms_wait == 10)
1966 hw_dbg("Queue disable timed out after 10ms\n");
1967
1968 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1969 * incoming packets are rejected. Set enable and wait 2ms so that
1970 * any packet that was coming in as RCTL.EN was set is flushed
1971 */
Alexander Duyck662d7202008-06-27 11:00:29 -07001972 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1973
1974 rlpml = rd32(E1000_RLPML);
1975 wr32(E1000_RLPML, 0);
1976
1977 rctl = rd32(E1000_RCTL);
1978 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1979 temp_rctl |= E1000_RCTL_LPE;
1980
1981 wr32(E1000_RCTL, temp_rctl);
1982 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1983 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001984 usleep_range(2000, 3000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001985
1986 /* Enable RX queues that were previously enabled and restore our
1987 * previous state
1988 */
1989 for (i = 0; i < 4; i++)
1990 wr32(E1000_RXDCTL(i), rxdctl[i]);
1991 wr32(E1000_RCTL, rctl);
1992 wrfl();
1993
1994 wr32(E1000_RLPML, rlpml);
1995 wr32(E1000_RFCTL, rfctl);
1996
1997 /* Flush receive errors generated by workaround */
1998 rd32(E1000_ROC);
1999 rd32(E1000_RNBC);
2000 rd32(E1000_MPC);
2001}
2002
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002003/**
Alexander Duyck009bc062009-07-23 18:08:35 +00002004 * igb_set_pcie_completion_timeout - set pci-e completion timeout
2005 * @hw: pointer to the HW structure
2006 *
2007 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2008 * however the hardware default for these parts is 500us to 1ms which is less
2009 * than the 10ms recommended by the pci-e spec. To address this we need to
2010 * increase the value to either 10ms to 200ms for capability version 1 config,
2011 * or 16ms to 55ms for version 2.
2012 **/
2013static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
2014{
2015 u32 gcr = rd32(E1000_GCR);
2016 s32 ret_val = 0;
2017 u16 pcie_devctl2;
2018
2019 /* only take action if timeout value is defaulted to 0 */
2020 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2021 goto out;
2022
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002023 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00002024 * timeout of 10ms to 200ms through the GCR register
2025 */
2026 if (!(gcr & E1000_GCR_CAP_VER2)) {
2027 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2028 goto out;
2029 }
2030
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002031 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00002032 * directly in order to set the completion timeout value for
2033 * 16ms to 55ms
2034 */
2035 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002036 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002037 if (ret_val)
2038 goto out;
2039
2040 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2041
2042 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002043 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002044out:
2045 /* disable completion timeout resend */
2046 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2047
2048 wr32(E1000_GCR, gcr);
2049 return ret_val;
2050}
2051
2052/**
Greg Rose13800462010-11-06 02:08:26 +00002053 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2054 * @hw: pointer to the hardware struct
2055 * @enable: state to enter, either enabled or disabled
2056 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2057 *
2058 * enables/disables L2 switch anti-spoofing functionality.
2059 **/
2060void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2061{
Lior Levy22c12752013-03-12 15:49:32 +00002062 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00002063
2064 switch (hw->mac.type) {
2065 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00002066 reg_offset = E1000_DTXSWC;
2067 break;
Greg Rose13800462010-11-06 02:08:26 +00002068 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002069 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00002070 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00002071 break;
2072 default:
Lior Levy22c12752013-03-12 15:49:32 +00002073 return;
Greg Rose13800462010-11-06 02:08:26 +00002074 }
Lior Levy22c12752013-03-12 15:49:32 +00002075
2076 reg_val = rd32(reg_offset);
2077 if (enable) {
2078 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2079 E1000_DTXSWC_VLAN_SPOOF_MASK);
2080 /* The PF can spoof - it has to in order to
2081 * support emulation mode NICs
2082 */
2083 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2084 } else {
2085 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2086 E1000_DTXSWC_VLAN_SPOOF_MASK);
2087 }
2088 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00002089}
2090
2091/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002092 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2093 * @hw: pointer to the hardware struct
2094 * @enable: state to enter, either enabled or disabled
2095 *
2096 * enables/disables L2 switch loopback functionality.
2097 **/
2098void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2099{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002100 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002101
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002102 switch (hw->mac.type) {
2103 case e1000_82576:
2104 dtxswc = rd32(E1000_DTXSWC);
2105 if (enable)
2106 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2107 else
2108 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2109 wr32(E1000_DTXSWC, dtxswc);
2110 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002111 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002112 case e1000_i350:
2113 dtxswc = rd32(E1000_TXSWC);
2114 if (enable)
2115 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2116 else
2117 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2118 wr32(E1000_TXSWC, dtxswc);
2119 break;
2120 default:
2121 /* Currently no other hardware supports loopback */
2122 break;
2123 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002124
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002125}
2126
2127/**
2128 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2129 * @hw: pointer to the hardware struct
2130 * @enable: state to enter, either enabled or disabled
2131 *
2132 * enables/disables replication of packets across multiple pools.
2133 **/
2134void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2135{
2136 u32 vt_ctl = rd32(E1000_VT_CTL);
2137
2138 if (enable)
2139 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2140 else
2141 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2142
2143 wr32(E1000_VT_CTL, vt_ctl);
2144}
2145
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002146/**
2147 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2148 * @hw: pointer to the HW structure
2149 * @offset: register offset to be read
2150 * @data: pointer to the read data
2151 *
2152 * Reads the MDI control register in the PHY at offset and stores the
2153 * information read to data.
2154 **/
2155static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2156{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002157 s32 ret_val;
2158
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002159 ret_val = hw->phy.ops.acquire(hw);
2160 if (ret_val)
2161 goto out;
2162
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002163 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2164
2165 hw->phy.ops.release(hw);
2166
2167out:
2168 return ret_val;
2169}
2170
2171/**
2172 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2173 * @hw: pointer to the HW structure
2174 * @offset: register offset to write to
2175 * @data: data to write to register at offset
2176 *
2177 * Writes data to MDI control register in the PHY at offset.
2178 **/
2179static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2180{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002181 s32 ret_val;
2182
2183
2184 ret_val = hw->phy.ops.acquire(hw);
2185 if (ret_val)
2186 goto out;
2187
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002188 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2189
2190 hw->phy.ops.release(hw);
2191
2192out:
2193 return ret_val;
2194}
2195
2196/**
Nick Nunley08451e22010-07-26 13:15:29 +00002197 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2198 * @hw: pointer to the HW structure
2199 *
2200 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2201 * the values found in the EEPROM. This addresses an issue in which these
2202 * bits are not restored from EEPROM after reset.
2203 **/
2204static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2205{
2206 s32 ret_val = 0;
2207 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002208 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002209
2210 if (hw->mac.type != e1000_82580)
2211 goto out;
2212 if (!igb_sgmii_active_82575(hw))
2213 goto out;
2214
2215 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2216 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2217 &nvm_data);
2218 if (ret_val) {
2219 hw_dbg("NVM Read Error\n");
2220 goto out;
2221 }
2222
2223 mdicnfg = rd32(E1000_MDICNFG);
2224 if (nvm_data & NVM_WORD24_EXT_MDIO)
2225 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2226 if (nvm_data & NVM_WORD24_COM_MDIO)
2227 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2228 wr32(E1000_MDICNFG, mdicnfg);
2229out:
2230 return ret_val;
2231}
2232
2233/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002234 * igb_reset_hw_82580 - Reset hardware
2235 * @hw: pointer to the HW structure
2236 *
2237 * This resets function or entire device (all ports, etc.)
2238 * to a known state.
2239 **/
2240static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2241{
2242 s32 ret_val = 0;
2243 /* BH SW mailbox bit in SW_FW_SYNC */
2244 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002245 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002246 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2247
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002248 hw->dev_spec._82575.global_device_reset = false;
2249
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002250 /* due to hw errata, global device reset doesn't always
2251 * work on 82580
2252 */
2253 if (hw->mac.type == e1000_82580)
2254 global_device_reset = false;
2255
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002256 /* Get current control state. */
2257 ctrl = rd32(E1000_CTRL);
2258
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002259 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002260 * on the last TLP read/write transaction when MAC is reset.
2261 */
2262 ret_val = igb_disable_pcie_master(hw);
2263 if (ret_val)
2264 hw_dbg("PCI-E Master disable polling has failed.\n");
2265
2266 hw_dbg("Masking off all interrupts\n");
2267 wr32(E1000_IMC, 0xffffffff);
2268 wr32(E1000_RCTL, 0);
2269 wr32(E1000_TCTL, E1000_TCTL_PSP);
2270 wrfl();
2271
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002272 usleep_range(10000, 11000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002273
2274 /* Determine whether or not a global dev reset is requested */
2275 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002276 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002277 global_device_reset = false;
2278
2279 if (global_device_reset &&
2280 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2281 ctrl |= E1000_CTRL_DEV_RST;
2282 else
2283 ctrl |= E1000_CTRL_RST;
2284
2285 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002286 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002287
2288 /* Add delay to insure DEV_RST has time to complete */
2289 if (global_device_reset)
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002290 usleep_range(5000, 6000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002291
2292 ret_val = igb_get_auto_rd_done(hw);
2293 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002294 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002295 * return with an error. This can happen in situations
2296 * where there is no eeprom and prevents getting link.
2297 */
2298 hw_dbg("Auto Read Done did not complete\n");
2299 }
2300
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002301 /* clear global device reset status bit */
2302 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2303
2304 /* Clear any pending interrupt events. */
2305 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002306 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002307
Nick Nunley08451e22010-07-26 13:15:29 +00002308 ret_val = igb_reset_mdicnfg_82580(hw);
2309 if (ret_val)
2310 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2311
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002312 /* Install any alternate MAC address into RAR0 */
2313 ret_val = igb_check_alt_mac_addr(hw);
2314
2315 /* Release semaphore */
2316 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002317 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002318
2319 return ret_val;
2320}
2321
2322/**
2323 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2324 * @data: data received by reading RXPBS register
2325 *
2326 * The 82580 uses a table based approach for packet buffer allocation sizes.
2327 * This function converts the retrieved value into the correct table value
2328 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2329 * 0x0 36 72 144 1 2 4 8 16
2330 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2331 */
2332u16 igb_rxpbs_adjust_82580(u32 data)
2333{
2334 u16 ret_val = 0;
2335
Todd Fujinaka72b36722014-03-04 02:25:22 +00002336 if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002337 ret_val = e1000_82580_rxpbs_table[data];
2338
2339 return ret_val;
2340}
2341
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002342/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002343 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2344 * checksum
2345 * @hw: pointer to the HW structure
2346 * @offset: offset in words of the checksum protected region
2347 *
2348 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2349 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2350 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002351static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2352 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002353{
2354 s32 ret_val = 0;
2355 u16 checksum = 0;
2356 u16 i, nvm_data;
2357
2358 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2359 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2360 if (ret_val) {
2361 hw_dbg("NVM Read Error\n");
2362 goto out;
2363 }
2364 checksum += nvm_data;
2365 }
2366
2367 if (checksum != (u16) NVM_SUM) {
2368 hw_dbg("NVM Checksum Invalid\n");
2369 ret_val = -E1000_ERR_NVM;
2370 goto out;
2371 }
2372
2373out:
2374 return ret_val;
2375}
2376
2377/**
2378 * igb_update_nvm_checksum_with_offset - Update EEPROM
2379 * checksum
2380 * @hw: pointer to the HW structure
2381 * @offset: offset in words of the checksum protected region
2382 *
2383 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2384 * up to the checksum. Then calculates the EEPROM checksum and writes the
2385 * value to the EEPROM.
2386 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002387static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002388{
2389 s32 ret_val;
2390 u16 checksum = 0;
2391 u16 i, nvm_data;
2392
2393 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2394 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2395 if (ret_val) {
2396 hw_dbg("NVM Read Error while updating checksum.\n");
2397 goto out;
2398 }
2399 checksum += nvm_data;
2400 }
2401 checksum = (u16) NVM_SUM - checksum;
2402 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2403 &checksum);
2404 if (ret_val)
2405 hw_dbg("NVM Write Error while updating checksum.\n");
2406
2407out:
2408 return ret_val;
2409}
2410
2411/**
2412 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2413 * @hw: pointer to the HW structure
2414 *
2415 * Calculates the EEPROM section checksum by reading/adding each word of
2416 * the EEPROM and then verifies that the sum of the EEPROM is
2417 * equal to 0xBABA.
2418 **/
2419static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2420{
2421 s32 ret_val = 0;
2422 u16 eeprom_regions_count = 1;
2423 u16 j, nvm_data;
2424 u16 nvm_offset;
2425
2426 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2427 if (ret_val) {
2428 hw_dbg("NVM Read Error\n");
2429 goto out;
2430 }
2431
2432 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002433 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002434 * for all 4 ports.
2435 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002436 eeprom_regions_count = 4;
2437 }
2438
2439 for (j = 0; j < eeprom_regions_count; j++) {
2440 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2441 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2442 nvm_offset);
2443 if (ret_val != 0)
2444 goto out;
2445 }
2446
2447out:
2448 return ret_val;
2449}
2450
2451/**
2452 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2453 * @hw: pointer to the HW structure
2454 *
2455 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2456 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2457 * checksum and writes the value to the EEPROM.
2458 **/
2459static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2460{
2461 s32 ret_val;
2462 u16 j, nvm_data;
2463 u16 nvm_offset;
2464
2465 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2466 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002467 hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002468 goto out;
2469 }
2470
2471 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2472 /* set compatibility bit to validate checksums appropriately */
2473 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2474 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2475 &nvm_data);
2476 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002477 hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002478 goto out;
2479 }
2480 }
2481
2482 for (j = 0; j < 4; j++) {
2483 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2484 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2485 if (ret_val)
2486 goto out;
2487 }
2488
2489out:
2490 return ret_val;
2491}
2492
2493/**
2494 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2495 * @hw: pointer to the HW structure
2496 *
2497 * Calculates the EEPROM section checksum by reading/adding each word of
2498 * the EEPROM and then verifies that the sum of the EEPROM is
2499 * equal to 0xBABA.
2500 **/
2501static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2502{
2503 s32 ret_val = 0;
2504 u16 j;
2505 u16 nvm_offset;
2506
2507 for (j = 0; j < 4; j++) {
2508 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2509 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2510 nvm_offset);
2511 if (ret_val != 0)
2512 goto out;
2513 }
2514
2515out:
2516 return ret_val;
2517}
2518
2519/**
2520 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2521 * @hw: pointer to the HW structure
2522 *
2523 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2524 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2525 * checksum and writes the value to the EEPROM.
2526 **/
2527static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2528{
2529 s32 ret_val = 0;
2530 u16 j;
2531 u16 nvm_offset;
2532
2533 for (j = 0; j < 4; j++) {
2534 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2535 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2536 if (ret_val != 0)
2537 goto out;
2538 }
2539
2540out:
2541 return ret_val;
2542}
Stefan Assmann34a03262011-04-05 04:27:05 +00002543
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002544/**
Matthew Vick87371b92013-02-21 03:32:52 +00002545 * __igb_access_emi_reg - Read/write EMI register
2546 * @hw: pointer to the HW structure
2547 * @addr: EMI address to program
2548 * @data: pointer to value to read/write from/to the EMI address
2549 * @read: boolean flag to indicate read or write
2550 **/
2551static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2552 u16 *data, bool read)
2553{
Todd Fujinaka23d87822014-06-04 07:12:15 +00002554 s32 ret_val = 0;
Matthew Vick87371b92013-02-21 03:32:52 +00002555
2556 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2557 if (ret_val)
2558 return ret_val;
2559
2560 if (read)
2561 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2562 else
2563 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2564
2565 return ret_val;
2566}
2567
2568/**
2569 * igb_read_emi_reg - Read Extended Management Interface register
2570 * @hw: pointer to the HW structure
2571 * @addr: EMI address to program
2572 * @data: value to be read from the EMI address
2573 **/
2574s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2575{
2576 return __igb_access_emi_reg(hw, addr, data, true);
2577}
2578
2579/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002580 * igb_set_eee_i350 - Enable/disable EEE support
2581 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002582 * @adv1G: boolean flag enabling 1G EEE advertisement
2583 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002584 *
2585 * Enable/disable EEE based on setting in dev_spec structure.
2586 *
2587 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002588s32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002589{
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002590 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002591
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002592 if ((hw->mac.type < e1000_i350) ||
2593 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002594 goto out;
2595 ipcnfg = rd32(E1000_IPCNFG);
2596 eeer = rd32(E1000_EEER);
2597
2598 /* enable or disable per user setting */
2599 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002600 u32 eee_su = rd32(E1000_EEE_SU);
2601
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002602 if (adv100M)
2603 ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
2604 else
2605 ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
2606
2607 if (adv1G)
2608 ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
2609 else
2610 ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
2611
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002612 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002613 E1000_EEER_LPI_FC);
2614
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002615 /* This bit should not be set in normal operation. */
2616 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2617 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2618
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002619 } else {
2620 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2621 E1000_IPCNFG_EEE_100M_AN);
2622 eeer &= ~(E1000_EEER_TX_LPI_EN |
2623 E1000_EEER_RX_LPI_EN |
2624 E1000_EEER_LPI_FC);
2625 }
2626 wr32(E1000_IPCNFG, ipcnfg);
2627 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002628 rd32(E1000_IPCNFG);
2629 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002630out:
2631
Todd Fujinaka23d87822014-06-04 07:12:15 +00002632 return 0;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002633}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002634
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002635/**
2636 * igb_set_eee_i354 - Enable/disable EEE support
2637 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002638 * @adv1G: boolean flag enabling 1G EEE advertisement
2639 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002640 *
2641 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2642 *
2643 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002644s32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002645{
2646 struct e1000_phy_info *phy = &hw->phy;
2647 s32 ret_val = 0;
2648 u16 phy_data;
2649
2650 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002651 ((phy->id != M88E1543_E_PHY_ID) &&
2652 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002653 goto out;
2654
2655 if (!hw->dev_spec._82575.eee_disable) {
2656 /* Switch to PHY page 18. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002657 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002658 if (ret_val)
2659 goto out;
2660
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002661 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002662 &phy_data);
2663 if (ret_val)
2664 goto out;
2665
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002666 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2667 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002668 phy_data);
2669 if (ret_val)
2670 goto out;
2671
2672 /* Return the PHY to page 0. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002673 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002674 if (ret_val)
2675 goto out;
2676
2677 /* Turn on EEE advertisement. */
2678 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2679 E1000_EEE_ADV_DEV_I354,
2680 &phy_data);
2681 if (ret_val)
2682 goto out;
2683
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002684 if (adv100M)
2685 phy_data |= E1000_EEE_ADV_100_SUPPORTED;
2686 else
2687 phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
2688
2689 if (adv1G)
2690 phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
2691 else
2692 phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
2693
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002694 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2695 E1000_EEE_ADV_DEV_I354,
2696 phy_data);
2697 } else {
2698 /* Turn off EEE advertisement. */
2699 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2700 E1000_EEE_ADV_DEV_I354,
2701 &phy_data);
2702 if (ret_val)
2703 goto out;
2704
2705 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2706 E1000_EEE_ADV_1000_SUPPORTED);
2707 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2708 E1000_EEE_ADV_DEV_I354,
2709 phy_data);
2710 }
2711
2712out:
2713 return ret_val;
2714}
2715
2716/**
2717 * igb_get_eee_status_i354 - Get EEE status
2718 * @hw: pointer to the HW structure
2719 * @status: EEE status
2720 *
2721 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2722 * been received.
2723 **/
2724s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2725{
2726 struct e1000_phy_info *phy = &hw->phy;
2727 s32 ret_val = 0;
2728 u16 phy_data;
2729
2730 /* Check if EEE is supported on this device. */
2731 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002732 ((phy->id != M88E1543_E_PHY_ID) &&
2733 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002734 goto out;
2735
2736 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2737 E1000_PCS_STATUS_DEV_I354,
2738 &phy_data);
2739 if (ret_val)
2740 goto out;
2741
2742 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2743 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2744
2745out:
2746 return ret_val;
2747}
2748
Carolyn Wybornye4288932012-12-07 03:01:42 +00002749static const u8 e1000_emc_temp_data[4] = {
2750 E1000_EMC_INTERNAL_DATA,
2751 E1000_EMC_DIODE1_DATA,
2752 E1000_EMC_DIODE2_DATA,
2753 E1000_EMC_DIODE3_DATA
2754};
2755static const u8 e1000_emc_therm_limit[4] = {
2756 E1000_EMC_INTERNAL_THERM_LIMIT,
2757 E1000_EMC_DIODE1_THERM_LIMIT,
2758 E1000_EMC_DIODE2_THERM_LIMIT,
2759 E1000_EMC_DIODE3_THERM_LIMIT
2760};
2761
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002762#ifdef CONFIG_IGB_HWMON
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002763/**
2764 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002765 * @hw: pointer to hardware structure
2766 *
2767 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002768 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002769static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002770{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002771 u16 ets_offset;
2772 u16 ets_cfg;
2773 u16 ets_sensor;
2774 u8 num_sensors;
2775 u8 sensor_index;
2776 u8 sensor_location;
2777 u8 i;
2778 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2779
2780 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2781 return E1000_NOT_IMPLEMENTED;
2782
2783 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2784
2785 /* Return the internal sensor only if ETS is unsupported */
2786 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2787 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002788 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002789
2790 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2791 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2792 != NVM_ETS_TYPE_EMC)
2793 return E1000_NOT_IMPLEMENTED;
2794
2795 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2796 if (num_sensors > E1000_MAX_SENSORS)
2797 num_sensors = E1000_MAX_SENSORS;
2798
2799 for (i = 1; i < num_sensors; i++) {
2800 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2801 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2802 NVM_ETS_DATA_INDEX_SHIFT);
2803 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2804 NVM_ETS_DATA_LOC_SHIFT);
2805
2806 if (sensor_location != 0)
2807 hw->phy.ops.read_i2c_byte(hw,
2808 e1000_emc_temp_data[sensor_index],
2809 E1000_I2C_THERMAL_SENSOR_ADDR,
2810 &data->sensor[i].temp);
2811 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002812 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002813}
2814
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002815/**
2816 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002817 * @hw: pointer to hardware structure
2818 *
2819 * Sets the thermal sensor thresholds according to the NVM map
2820 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002821 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002822static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002823{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002824 u16 ets_offset;
2825 u16 ets_cfg;
2826 u16 ets_sensor;
2827 u8 low_thresh_delta;
2828 u8 num_sensors;
2829 u8 sensor_index;
2830 u8 sensor_location;
2831 u8 therm_limit;
2832 u8 i;
2833 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2834
2835 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2836 return E1000_NOT_IMPLEMENTED;
2837
2838 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2839
2840 data->sensor[0].location = 0x1;
2841 data->sensor[0].caution_thresh =
2842 (rd32(E1000_THHIGHTC) & 0xFF);
2843 data->sensor[0].max_op_thresh =
2844 (rd32(E1000_THLOWTC) & 0xFF);
2845
2846 /* Return the internal sensor only if ETS is unsupported */
2847 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2848 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002849 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002850
2851 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2852 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2853 != NVM_ETS_TYPE_EMC)
2854 return E1000_NOT_IMPLEMENTED;
2855
2856 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2857 NVM_ETS_LTHRES_DELTA_SHIFT);
2858 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2859
2860 for (i = 1; i <= num_sensors; i++) {
2861 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2862 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2863 NVM_ETS_DATA_INDEX_SHIFT);
2864 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2865 NVM_ETS_DATA_LOC_SHIFT);
2866 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2867
2868 hw->phy.ops.write_i2c_byte(hw,
2869 e1000_emc_therm_limit[sensor_index],
2870 E1000_I2C_THERMAL_SENSOR_ADDR,
2871 therm_limit);
2872
2873 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2874 data->sensor[i].location = sensor_location;
2875 data->sensor[i].caution_thresh = therm_limit;
2876 data->sensor[i].max_op_thresh = therm_limit -
2877 low_thresh_delta;
2878 }
2879 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002880 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002881}
2882
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002883#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002884static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002885 .init_hw = igb_init_hw_82575,
2886 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002887 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002888 .read_mac_addr = igb_read_mac_addr_82575,
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00002889 .get_speed_and_duplex = igb_get_link_up_info_82575,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002890#ifdef CONFIG_IGB_HWMON
2891 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2892 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2893#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002894};
2895
2896static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002897 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002898 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002899 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002900 .write_i2c_byte = igb_write_i2c_byte,
2901 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002902};
2903
2904static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002905 .acquire = igb_acquire_nvm_82575,
2906 .read = igb_read_nvm_eerd,
2907 .release = igb_release_nvm_82575,
2908 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002909};
2910
2911const struct e1000_info e1000_82575_info = {
2912 .get_invariants = igb_get_invariants_82575,
2913 .mac_ops = &e1000_mac_ops_82575,
2914 .phy_ops = &e1000_phy_ops_82575,
2915 .nvm_ops = &e1000_nvm_ops_82575,
2916};
2917