blob: 362911d024b5d8237070413cc722d65adab58451 [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;
Todd Fujinaka08c99122015-09-18 15:43:51 -0700302 phy->ops.get_cfg_done = igb_get_cfg_done_i210;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000303 phy->ops.get_phy_info = igb_get_phy_info_m88;
304 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
305 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
306 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
307 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
308 break;
309 default:
310 ret_val = -E1000_ERR_PHY;
311 goto out;
312 }
313
314out:
315 return ret_val;
316}
317
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000318/**
319 * igb_init_nvm_params_82575 - Init NVM func ptrs.
320 * @hw: pointer to the HW structure
321 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000322static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000323{
324 struct e1000_nvm_info *nvm = &hw->nvm;
325 u32 eecd = rd32(E1000_EECD);
326 u16 size;
327
328 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
329 E1000_EECD_SIZE_EX_SHIFT);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000330
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000331 /* Added to a constant, "size" becomes the left-shift value
332 * for setting word_size.
333 */
334 size += NVM_WORD_SIZE_BASE_SHIFT;
335
336 /* Just in case size is out of range, cap it to the largest
337 * EEPROM size supported
338 */
339 if (size > 15)
340 size = 15;
341
342 nvm->word_size = 1 << size;
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000343 nvm->opcode_bits = 8;
344 nvm->delay_usec = 1;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000345
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000346 switch (nvm->override) {
347 case e1000_nvm_override_spi_large:
348 nvm->page_size = 32;
349 nvm->address_bits = 16;
350 break;
351 case e1000_nvm_override_spi_small:
352 nvm->page_size = 8;
353 nvm->address_bits = 8;
354 break;
355 default:
356 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
357 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
358 16 : 8;
359 break;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000360 }
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000361 if (nvm->word_size == (1 << 15))
362 nvm->page_size = 128;
363
364 nvm->type = e1000_nvm_eeprom_spi;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000365
366 /* NVM Function Pointers */
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000367 nvm->ops.acquire = igb_acquire_nvm_82575;
368 nvm->ops.release = igb_release_nvm_82575;
369 nvm->ops.write = igb_write_nvm_spi;
370 nvm->ops.validate = igb_validate_nvm_checksum;
371 nvm->ops.update = igb_update_nvm_checksum;
372 if (nvm->word_size < (1 << 15))
373 nvm->ops.read = igb_read_nvm_eerd;
374 else
375 nvm->ops.read = igb_read_nvm_spi;
376
377 /* override generic family function pointers for specific descendants */
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000378 switch (hw->mac.type) {
379 case e1000_82580:
380 nvm->ops.validate = igb_validate_nvm_checksum_82580;
381 nvm->ops.update = igb_update_nvm_checksum_82580;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000382 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000383 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000384 case e1000_i350:
385 nvm->ops.validate = igb_validate_nvm_checksum_i350;
386 nvm->ops.update = igb_update_nvm_checksum_i350;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000387 break;
388 default:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000389 break;
390 }
391
392 return 0;
393}
394
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000395/**
396 * igb_init_mac_params_82575 - Init MAC func ptrs.
397 * @hw: pointer to the HW structure
398 **/
399static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
400{
401 struct e1000_mac_info *mac = &hw->mac;
402 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
403
404 /* Set mta register count */
405 mac->mta_reg_count = 128;
406 /* Set rar entry count */
407 switch (mac->type) {
408 case e1000_82576:
409 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
410 break;
411 case e1000_82580:
412 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
413 break;
414 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000415 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000416 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
417 break;
418 default:
419 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
420 break;
421 }
422 /* reset */
423 if (mac->type >= e1000_82580)
424 mac->ops.reset_hw = igb_reset_hw_82580;
425 else
426 mac->ops.reset_hw = igb_reset_hw_82575;
427
428 if (mac->type >= e1000_i210) {
429 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
430 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
431
432 } else {
433 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
434 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
435 }
436
437 /* Set if part includes ASF firmware */
438 mac->asf_firmware_present = true;
439 /* Set if manageability features are enabled. */
440 mac->arc_subsystem_valid =
441 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
442 ? true : false;
443 /* enable EEE on i350 parts and later parts */
444 if (mac->type >= e1000_i350)
445 dev_spec->eee_disable = false;
446 else
447 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000448 /* Allow a single clear of the SW semaphore on I210 and newer */
449 if (mac->type >= e1000_i210)
450 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000451 /* physical interface link setup */
452 mac->ops.setup_physical_interface =
453 (hw->phy.media_type == e1000_media_type_copper)
454 ? igb_setup_copper_link_82575
455 : igb_setup_serdes_link_82575;
456
Carolyn Wyborny56cec242013-10-17 05:36:26 +0000457 if (mac->type == e1000_82580) {
458 switch (hw->device_id) {
459 /* feature not supported on these id's */
460 case E1000_DEV_ID_DH89XXCC_SGMII:
461 case E1000_DEV_ID_DH89XXCC_SERDES:
462 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
463 case E1000_DEV_ID_DH89XXCC_SFP:
464 break;
465 default:
466 hw->dev_spec._82575.mas_capable = true;
467 break;
468 }
469 }
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000470 return 0;
471}
472
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000473/**
474 * igb_set_sfp_media_type_82575 - derives SFP module media type.
475 * @hw: pointer to the HW structure
476 *
477 * The media type is chosen based on SFP module.
478 * compatibility flags retrieved from SFP ID EEPROM.
479 **/
480static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
481{
482 s32 ret_val = E1000_ERR_CONFIG;
483 u32 ctrl_ext = 0;
484 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
485 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
486 u8 tranceiver_type = 0;
487 s32 timeout = 3;
488
489 /* Turn I2C interface ON and power on sfp cage */
490 ctrl_ext = rd32(E1000_CTRL_EXT);
491 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
492 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
493
494 wrfl();
495
496 /* Read SFP module data */
497 while (timeout) {
498 ret_val = igb_read_sfp_data_byte(hw,
499 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
500 &tranceiver_type);
501 if (ret_val == 0)
502 break;
503 msleep(100);
504 timeout--;
505 }
506 if (ret_val != 0)
507 goto out;
508
509 ret_val = igb_read_sfp_data_byte(hw,
510 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
511 (u8 *)eth_flags);
512 if (ret_val != 0)
513 goto out;
514
515 /* Check if there is some SFP module plugged and powered */
516 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
517 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
518 dev_spec->module_plugged = true;
519 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
520 hw->phy.media_type = e1000_media_type_internal_serdes;
521 } else if (eth_flags->e100_base_fx) {
522 dev_spec->sgmii_active = true;
523 hw->phy.media_type = e1000_media_type_internal_serdes;
524 } else if (eth_flags->e1000_base_t) {
525 dev_spec->sgmii_active = true;
526 hw->phy.media_type = e1000_media_type_copper;
527 } else {
528 hw->phy.media_type = e1000_media_type_unknown;
529 hw_dbg("PHY module has not been recognized\n");
530 goto out;
531 }
532 } else {
533 hw->phy.media_type = e1000_media_type_unknown;
534 }
535 ret_val = 0;
536out:
537 /* Restore I2C interface setting */
538 wr32(E1000_CTRL_EXT, ctrl_ext);
539 return ret_val;
540}
541
Auke Kok9d5c8242008-01-24 02:22:38 -0800542static s32 igb_get_invariants_82575(struct e1000_hw *hw)
543{
Auke Kok9d5c8242008-01-24 02:22:38 -0800544 struct e1000_mac_info *mac = &hw->mac;
Carolyn Wybornyc4917c62014-04-11 01:45:48 +0000545 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800546 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800547 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000548 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800549
550 switch (hw->device_id) {
551 case E1000_DEV_ID_82575EB_COPPER:
552 case E1000_DEV_ID_82575EB_FIBER_SERDES:
553 case E1000_DEV_ID_82575GB_QUAD_COPPER:
554 mac->type = e1000_82575;
555 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700556 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000557 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000558 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700559 case E1000_DEV_ID_82576_FIBER:
560 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000561 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000562 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000563 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700564 mac->type = e1000_82576;
565 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000566 case E1000_DEV_ID_82580_COPPER:
567 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000568 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000569 case E1000_DEV_ID_82580_SERDES:
570 case E1000_DEV_ID_82580_SGMII:
571 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000572 case E1000_DEV_ID_DH89XXCC_SGMII:
573 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000574 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
575 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000576 mac->type = e1000_82580;
577 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000578 case E1000_DEV_ID_I350_COPPER:
579 case E1000_DEV_ID_I350_FIBER:
580 case E1000_DEV_ID_I350_SERDES:
581 case E1000_DEV_ID_I350_SGMII:
582 mac->type = e1000_i350;
583 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000584 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000585 case E1000_DEV_ID_I210_FIBER:
586 case E1000_DEV_ID_I210_SERDES:
587 case E1000_DEV_ID_I210_SGMII:
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +0000588 case E1000_DEV_ID_I210_COPPER_FLASHLESS:
589 case E1000_DEV_ID_I210_SERDES_FLASHLESS:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000590 mac->type = e1000_i210;
591 break;
592 case E1000_DEV_ID_I211_COPPER:
593 mac->type = e1000_i211;
594 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000595 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
596 case E1000_DEV_ID_I354_SGMII:
597 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
598 mac->type = e1000_i354;
599 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800600 default:
601 return -E1000_ERR_MAC_INIT;
Auke Kok9d5c8242008-01-24 02:22:38 -0800602 }
603
Auke Kok9d5c8242008-01-24 02:22:38 -0800604 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000605 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800606 * based on the EEPROM. We cannot rely upon device ID. There
607 * is no distinguishable difference between fiber and internal
608 * SerDes mode on the 82575. There can be an external PHY attached
609 * on the SGMII interface. For this, we'll set sgmii_active to true.
610 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000611 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800612 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000613 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800614
615 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000616
617 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
618 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000619 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000620 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000621 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000622 case E1000_CTRL_EXT_LINK_MODE_SGMII:
623 /* Get phy control interface type set (MDIO vs. I2C)*/
624 if (igb_sgmii_uses_mdio_82575(hw)) {
625 hw->phy.media_type = e1000_media_type_copper;
626 dev_spec->sgmii_active = true;
627 break;
628 }
629 /* fall through for I2C based SGMII */
630 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
631 /* read media type from SFP EEPROM */
632 ret_val = igb_set_sfp_media_type_82575(hw);
633 if ((ret_val != 0) ||
634 (hw->phy.media_type == e1000_media_type_unknown)) {
635 /* If media type was not identified then return media
636 * type defined by the CTRL_EXT settings.
637 */
638 hw->phy.media_type = e1000_media_type_internal_serdes;
639
640 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
641 hw->phy.media_type = e1000_media_type_copper;
642 dev_spec->sgmii_active = true;
643 }
644
645 break;
646 }
647
648 /* do not change link mode for 100BaseFX */
649 if (dev_spec->eth_flags.e100_base_fx)
650 break;
651
652 /* change current link mode setting */
653 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
654
655 if (hw->phy.media_type == e1000_media_type_copper)
656 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
657 else
658 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
659
660 wr32(E1000_CTRL_EXT, ctrl_ext);
661
662 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000663 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000664 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800665 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000666
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000667 /* mac initialization and operations */
668 ret_val = igb_init_mac_params_82575(hw);
669 if (ret_val)
670 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800671
672 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000673 ret_val = igb_init_nvm_params_82575(hw);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000674 switch (hw->mac.type) {
675 case e1000_i210:
676 case e1000_i211:
677 ret_val = igb_init_nvm_params_i210(hw);
678 break;
679 default:
680 break;
681 }
682
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000683 if (ret_val)
684 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800685
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000686 /* if part supports SR-IOV then initialize mailbox parameters */
687 switch (mac->type) {
688 case e1000_82576:
689 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000690 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000691 break;
692 default:
693 break;
694 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000695
Auke Kok9d5c8242008-01-24 02:22:38 -0800696 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000697 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800698
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000699out:
700 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800701}
702
703/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700704 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800705 * @hw: pointer to the HW structure
706 *
707 * Acquire access rights to the correct PHY. This is a
708 * function pointer entry point called by the api module.
709 **/
710static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
711{
Alexander Duyck008c3422009-10-05 06:32:07 +0000712 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800713
Alexander Duyck008c3422009-10-05 06:32:07 +0000714 if (hw->bus.func == E1000_FUNC_1)
715 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000716 else if (hw->bus.func == E1000_FUNC_2)
717 mask = E1000_SWFW_PHY2_SM;
718 else if (hw->bus.func == E1000_FUNC_3)
719 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800720
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000721 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800722}
723
724/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700725 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800726 * @hw: pointer to the HW structure
727 *
728 * A wrapper to release access rights to the correct PHY. This is a
729 * function pointer entry point called by the api module.
730 **/
731static void igb_release_phy_82575(struct e1000_hw *hw)
732{
Alexander Duyck008c3422009-10-05 06:32:07 +0000733 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800734
Alexander Duyck008c3422009-10-05 06:32:07 +0000735 if (hw->bus.func == E1000_FUNC_1)
736 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000737 else if (hw->bus.func == E1000_FUNC_2)
738 mask = E1000_SWFW_PHY2_SM;
739 else if (hw->bus.func == E1000_FUNC_3)
740 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000741
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000742 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800743}
744
745/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700746 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800747 * @hw: pointer to the HW structure
748 * @offset: register offset to be read
749 * @data: pointer to the read data
750 *
751 * Reads the PHY register at offset using the serial gigabit media independent
752 * interface and stores the retrieved information in data.
753 **/
754static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
755 u16 *data)
756{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000757 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800758
759 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700760 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000761 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800762 }
763
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000764 ret_val = hw->phy.ops.acquire(hw);
765 if (ret_val)
766 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800767
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000768 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800769
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000770 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800771
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000772out:
773 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800774}
775
776/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700777 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 * @hw: pointer to the HW structure
779 * @offset: register offset to write to
780 * @data: data to write at register offset
781 *
782 * Writes the data to PHY register at the offset using the serial gigabit
783 * media independent interface.
784 **/
785static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
786 u16 data)
787{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000788 s32 ret_val = -E1000_ERR_PARAM;
789
Auke Kok9d5c8242008-01-24 02:22:38 -0800790
791 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700792 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000793 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800794 }
795
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000796 ret_val = hw->phy.ops.acquire(hw);
797 if (ret_val)
798 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800799
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000800 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800801
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000802 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800803
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000804out:
805 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800806}
807
808/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700809 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800810 * @hw: pointer to the HW structure
811 *
Auke Kok652fff32008-06-27 11:00:18 -0700812 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800813 * sgmi interface.
814 **/
815static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
816{
817 struct e1000_phy_info *phy = &hw->phy;
818 s32 ret_val = 0;
819 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000820 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000821 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800822
Carolyn Wybornybb1d18d2013-09-10 11:57:16 -0700823 /* Extra read required for some PHY's on i354 */
824 if (hw->mac.type == e1000_i354)
825 igb_get_phy_id(hw);
826
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000827 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800828 * we find one that works. For non-SGMII PHYs
829 * (e.g. integrated copper PHYs), an address of 1 should
830 * work. The result of this function should mean phy->phy_addr
831 * and phy->id are set correctly.
832 */
833 if (!(igb_sgmii_active_82575(hw))) {
834 phy->addr = 1;
835 ret_val = igb_get_phy_id(hw);
836 goto out;
837 }
838
Nick Nunley4085f742010-07-26 13:15:06 +0000839 if (igb_sgmii_uses_mdio_82575(hw)) {
840 switch (hw->mac.type) {
841 case e1000_82575:
842 case e1000_82576:
843 mdic = rd32(E1000_MDIC);
844 mdic &= E1000_MDIC_PHY_MASK;
845 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
846 break;
847 case e1000_82580:
848 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000849 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000850 case e1000_i210:
851 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000852 mdic = rd32(E1000_MDICNFG);
853 mdic &= E1000_MDICNFG_PHY_MASK;
854 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
855 break;
856 default:
857 ret_val = -E1000_ERR_PHY;
858 goto out;
Nick Nunley4085f742010-07-26 13:15:06 +0000859 }
860 ret_val = igb_get_phy_id(hw);
861 goto out;
862 }
863
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000864 /* Power on sgmii phy if it is disabled */
865 ctrl_ext = rd32(E1000_CTRL_EXT);
866 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
867 wrfl();
868 msleep(300);
869
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000870 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800871 * Therefore, we need to test 1-7
872 */
873 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
874 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
875 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700876 hw_dbg("Vendor ID 0x%08X read at address %u\n",
877 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000878 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800879 * the only supported SGMII PHY product.
880 */
881 if (phy_id == M88_VENDOR)
882 break;
883 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700884 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800885 }
886 }
887
888 /* A valid PHY type couldn't be found. */
889 if (phy->addr == 8) {
890 phy->addr = 0;
891 ret_val = -E1000_ERR_PHY;
892 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000893 } else {
894 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800895 }
896
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000897 /* restore previous sfp cage power state */
898 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800899
900out:
901 return ret_val;
902}
903
904/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700905 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800906 * @hw: pointer to the HW structure
907 *
908 * Resets the PHY using the serial gigabit media independent interface.
909 **/
910static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
911{
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700912 struct e1000_phy_info *phy = &hw->phy;
Auke Kok9d5c8242008-01-24 02:22:38 -0800913 s32 ret_val;
914
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000915 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800916 * available to us at this time.
917 */
918
Auke Kok652fff32008-06-27 11:00:18 -0700919 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800920
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000921 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800922 * to work on SGMII. No further documentation is given.
923 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000924 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800925 if (ret_val)
926 goto out;
927
928 ret_val = igb_phy_sw_reset(hw);
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700929 if (ret_val)
930 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800931
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700932 if (phy->id == M88E1512_E_PHY_ID)
933 ret_val = igb_initialize_M88E1512_phy(hw);
Todd Fujinaka18f7ce52015-09-02 16:54:20 -0700934 if (phy->id == M88E1543_E_PHY_ID)
935 ret_val = igb_initialize_M88E1543_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800936out:
937 return ret_val;
938}
939
940/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700941 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800942 * @hw: pointer to the HW structure
943 * @active: true to enable LPLU, false to disable
944 *
945 * Sets the LPLU D0 state according to the active flag. When
946 * activating LPLU this function also disables smart speed
947 * and vice versa. LPLU will not be activated unless the
948 * device autonegotiation advertisement meets standards of
949 * either 10 or 10/100 or 10/100/1000 at all duplexes.
950 * This is a function pointer entry point only called by
951 * PHY setup routines.
952 **/
953static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
954{
955 struct e1000_phy_info *phy = &hw->phy;
956 s32 ret_val;
957 u16 data;
958
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000959 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800960 if (ret_val)
961 goto out;
962
963 if (active) {
964 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000965 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700966 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800967 if (ret_val)
968 goto out;
969
970 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000971 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700972 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800973 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000974 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700975 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800976 if (ret_val)
977 goto out;
978 } else {
979 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000980 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700981 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000982 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -0800983 * during Dx states where the power conservation is most
984 * important. During driver activity we should enable
985 * SmartSpeed, so performance is maintained.
986 */
987 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000988 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700989 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800990 if (ret_val)
991 goto out;
992
993 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000994 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700995 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800996 if (ret_val)
997 goto out;
998 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000999 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001000 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001001 if (ret_val)
1002 goto out;
1003
1004 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001005 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001006 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001007 if (ret_val)
1008 goto out;
1009 }
1010 }
1011
1012out:
1013 return ret_val;
1014}
1015
1016/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001017 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
1018 * @hw: pointer to the HW structure
1019 * @active: true to enable LPLU, false to disable
1020 *
1021 * Sets the LPLU D0 state according to the active flag. When
1022 * activating LPLU this function also disables smart speed
1023 * and vice versa. LPLU will not be activated unless the
1024 * device autonegotiation advertisement meets standards of
1025 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1026 * This is a function pointer entry point only called by
1027 * PHY setup routines.
1028 **/
1029static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
1030{
1031 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001032 u16 data;
1033
1034 data = rd32(E1000_82580_PHY_POWER_MGMT);
1035
1036 if (active) {
1037 data |= E1000_82580_PM_D0_LPLU;
1038
1039 /* When LPLU is enabled, we should disable SmartSpeed */
1040 data &= ~E1000_82580_PM_SPD;
1041 } else {
1042 data &= ~E1000_82580_PM_D0_LPLU;
1043
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001044 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001045 * during Dx states where the power conservation is most
1046 * important. During driver activity we should enable
1047 * SmartSpeed, so performance is maintained.
1048 */
1049 if (phy->smart_speed == e1000_smart_speed_on)
1050 data |= E1000_82580_PM_SPD;
1051 else if (phy->smart_speed == e1000_smart_speed_off)
1052 data &= ~E1000_82580_PM_SPD; }
1053
1054 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001055 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001056}
1057
1058/**
1059 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1060 * @hw: pointer to the HW structure
1061 * @active: boolean used to enable/disable lplu
1062 *
1063 * Success returns 0, Failure returns 1
1064 *
1065 * The low power link up (lplu) state is set to the power management level D3
1066 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1067 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1068 * is used during Dx states where the power conservation is most important.
1069 * During driver activity, SmartSpeed should be enabled so performance is
1070 * maintained.
1071 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +00001072static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001073{
1074 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001075 u16 data;
1076
1077 data = rd32(E1000_82580_PHY_POWER_MGMT);
1078
1079 if (!active) {
1080 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001081 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001082 * during Dx states where the power conservation is most
1083 * important. During driver activity we should enable
1084 * SmartSpeed, so performance is maintained.
1085 */
1086 if (phy->smart_speed == e1000_smart_speed_on)
1087 data |= E1000_82580_PM_SPD;
1088 else if (phy->smart_speed == e1000_smart_speed_off)
1089 data &= ~E1000_82580_PM_SPD;
1090 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1091 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1092 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1093 data |= E1000_82580_PM_D3_LPLU;
1094 /* When LPLU is enabled, we should disable SmartSpeed */
1095 data &= ~E1000_82580_PM_SPD;
1096 }
1097
1098 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001099 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001100}
1101
1102/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001103 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001104 * @hw: pointer to the HW structure
1105 *
Auke Kok652fff32008-06-27 11:00:18 -07001106 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001107 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1108 * Return successful if access grant bit set, else clear the request for
1109 * EEPROM access and return -E1000_ERR_NVM (-1).
1110 **/
1111static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1112{
1113 s32 ret_val;
1114
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001115 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001116 if (ret_val)
1117 goto out;
1118
1119 ret_val = igb_acquire_nvm(hw);
1120
1121 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001122 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001123
1124out:
1125 return ret_val;
1126}
1127
1128/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001129 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001130 * @hw: pointer to the HW structure
1131 *
1132 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1133 * then release the semaphores acquired.
1134 **/
1135static void igb_release_nvm_82575(struct e1000_hw *hw)
1136{
1137 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001138 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001139}
1140
1141/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001142 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001143 * @hw: pointer to the HW structure
1144 * @mask: specifies which semaphore to acquire
1145 *
1146 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1147 * will also specify which port we're acquiring the lock for.
1148 **/
1149static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1150{
1151 u32 swfw_sync;
1152 u32 swmask = mask;
1153 u32 fwmask = mask << 16;
1154 s32 ret_val = 0;
Todd Fujinaka2184aa32014-11-27 01:00:02 +00001155 s32 i = 0, timeout = 200;
Auke Kok9d5c8242008-01-24 02:22:38 -08001156
1157 while (i < timeout) {
1158 if (igb_get_hw_semaphore(hw)) {
1159 ret_val = -E1000_ERR_SWFW_SYNC;
1160 goto out;
1161 }
1162
1163 swfw_sync = rd32(E1000_SW_FW_SYNC);
1164 if (!(swfw_sync & (fwmask | swmask)))
1165 break;
1166
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001167 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001168 * or other software thread using resource (swmask)
1169 */
1170 igb_put_hw_semaphore(hw);
1171 mdelay(5);
1172 i++;
1173 }
1174
1175 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001176 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001177 ret_val = -E1000_ERR_SWFW_SYNC;
1178 goto out;
1179 }
1180
1181 swfw_sync |= swmask;
1182 wr32(E1000_SW_FW_SYNC, swfw_sync);
1183
1184 igb_put_hw_semaphore(hw);
1185
1186out:
1187 return ret_val;
1188}
1189
1190/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001191 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001192 * @hw: pointer to the HW structure
1193 * @mask: specifies which semaphore to acquire
1194 *
1195 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1196 * will also specify which port we're releasing the lock for.
1197 **/
1198static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1199{
1200 u32 swfw_sync;
1201
Carolyn Wybornybed83e92014-04-11 01:45:55 +00001202 while (igb_get_hw_semaphore(hw) != 0)
1203 ; /* Empty */
Auke Kok9d5c8242008-01-24 02:22:38 -08001204
1205 swfw_sync = rd32(E1000_SW_FW_SYNC);
1206 swfw_sync &= ~mask;
1207 wr32(E1000_SW_FW_SYNC, swfw_sync);
1208
1209 igb_put_hw_semaphore(hw);
1210}
1211
1212/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001213 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 * @hw: pointer to the HW structure
1215 *
1216 * Read the management control register for the config done bit for
1217 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1218 * to read the config done bit, so an error is *ONLY* logged and returns
1219 * 0. If we were to return with error, EEPROM-less silicon
1220 * would not be able to be reset or change link.
1221 **/
1222static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1223{
1224 s32 timeout = PHY_CFG_TIMEOUT;
Auke Kok9d5c8242008-01-24 02:22:38 -08001225 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1226
1227 if (hw->bus.func == 1)
1228 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001229 else if (hw->bus.func == E1000_FUNC_2)
1230 mask = E1000_NVM_CFG_DONE_PORT_2;
1231 else if (hw->bus.func == E1000_FUNC_3)
1232 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001233
1234 while (timeout) {
1235 if (rd32(E1000_EEMNGCTL) & mask)
1236 break;
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001237 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001238 timeout--;
1239 }
1240 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001241 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001242
1243 /* If EEPROM is not marked present, init the PHY manually */
1244 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1245 (hw->phy.type == e1000_phy_igp_3))
1246 igb_phy_init_script_igp3(hw);
1247
Todd Fujinaka23d87822014-06-04 07:12:15 +00001248 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001249}
1250
1251/**
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00001252 * igb_get_link_up_info_82575 - Get link speed/duplex info
1253 * @hw: pointer to the HW structure
1254 * @speed: stores the current speed
1255 * @duplex: stores the current duplex
1256 *
1257 * This is a wrapper function, if using the serial gigabit media independent
1258 * interface, use PCS to retrieve the link speed and duplex information.
1259 * Otherwise, use the generic function to get the link speed and duplex info.
1260 **/
1261static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1262 u16 *duplex)
1263{
1264 s32 ret_val;
1265
1266 if (hw->phy.media_type != e1000_media_type_copper)
1267 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
1268 duplex);
1269 else
1270 ret_val = igb_get_speed_and_duplex_copper(hw, speed,
1271 duplex);
1272
1273 return ret_val;
1274}
1275
1276/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001277 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001278 * @hw: pointer to the HW structure
1279 *
1280 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1281 * use the generic interface for determining link.
1282 **/
1283static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1284{
1285 s32 ret_val;
1286 u16 speed, duplex;
1287
Alexander Duyck70d92f82009-10-05 06:31:47 +00001288 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001289 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001290 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001291 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001292 * not. If we have link clear the flag so that we do not
1293 * continue to check for link.
1294 */
1295 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001296
1297 /* Configure Flow Control now that Auto-Neg has completed.
1298 * First, we need to restore the desired flow control
1299 * settings because we may have had to re-autoneg with a
1300 * different link partner.
1301 */
1302 ret_val = igb_config_fc_after_link_up(hw);
1303 if (ret_val)
1304 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001305 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001306 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001307 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001308
1309 return ret_val;
1310}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001311
Auke Kok9d5c8242008-01-24 02:22:38 -08001312/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001313 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1314 * @hw: pointer to the HW structure
1315 **/
1316void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1317{
1318 u32 reg;
1319
1320
1321 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1322 !igb_sgmii_active_82575(hw))
1323 return;
1324
1325 /* Enable PCS to turn on link */
1326 reg = rd32(E1000_PCS_CFG0);
1327 reg |= E1000_PCS_CFG_PCS_EN;
1328 wr32(E1000_PCS_CFG0, reg);
1329
1330 /* Power up the laser */
1331 reg = rd32(E1000_CTRL_EXT);
1332 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1333 wr32(E1000_CTRL_EXT, reg);
1334
1335 /* flush the write to verify completion */
1336 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001337 usleep_range(1000, 2000);
Nick Nunley88a268c2010-02-17 01:01:59 +00001338}
1339
1340/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001341 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001342 * @hw: pointer to the HW structure
1343 * @speed: stores the current speed
1344 * @duplex: stores the current duplex
1345 *
Auke Kok652fff32008-06-27 11:00:18 -07001346 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001347 * duplex, then store the values in the pointers provided.
1348 **/
1349static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1350 u16 *duplex)
1351{
1352 struct e1000_mac_info *mac = &hw->mac;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001353 u32 pcs, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08001354
1355 /* Set up defaults for the return values of this function */
1356 mac->serdes_has_link = false;
1357 *speed = 0;
1358 *duplex = 0;
1359
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001360 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001361 * the status register is not accurate. The PCS status register is
1362 * used instead.
1363 */
1364 pcs = rd32(E1000_PCS_LSTAT);
1365
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001366 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001367 * gets set once both sides sync up and agree upon link. Stable link
1368 * can be determined by checking for both link up and link sync ok
1369 */
1370 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1371 mac->serdes_has_link = true;
1372
1373 /* Detect and store PCS speed */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001374 if (pcs & E1000_PCS_LSTS_SPEED_1000)
Auke Kok9d5c8242008-01-24 02:22:38 -08001375 *speed = SPEED_1000;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001376 else if (pcs & E1000_PCS_LSTS_SPEED_100)
Auke Kok9d5c8242008-01-24 02:22:38 -08001377 *speed = SPEED_100;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001378 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001379 *speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -08001380
1381 /* Detect and store PCS duplex */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001382 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
Auke Kok9d5c8242008-01-24 02:22:38 -08001383 *duplex = FULL_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001384 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001385 *duplex = HALF_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001386
1387 /* Check if it is an I354 2.5Gb backplane connection. */
1388 if (mac->type == e1000_i354) {
1389 status = rd32(E1000_STATUS);
1390 if ((status & E1000_STATUS_2P5_SKU) &&
1391 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1392 *speed = SPEED_2500;
1393 *duplex = FULL_DUPLEX;
1394 hw_dbg("2500 Mbs, ");
1395 hw_dbg("Full Duplex\n");
1396 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001397 }
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001398
Auke Kok9d5c8242008-01-24 02:22:38 -08001399 }
1400
1401 return 0;
1402}
1403
1404/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001405 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001406 * @hw: pointer to the HW structure
1407 *
1408 * In the case of fiber serdes, shut down optics and PCS on driver unload
1409 * when management pass thru is not enabled.
1410 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001411void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001412{
1413 u32 reg;
1414
Nick Nunley53c992f2010-02-17 01:01:40 +00001415 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001416 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001417 return;
1418
Nick Nunley53c992f2010-02-17 01:01:40 +00001419 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001420 /* Disable PCS to turn off link */
1421 reg = rd32(E1000_PCS_CFG0);
1422 reg &= ~E1000_PCS_CFG_PCS_EN;
1423 wr32(E1000_PCS_CFG0, reg);
1424
1425 /* shutdown the laser */
1426 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001427 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001428 wr32(E1000_CTRL_EXT, reg);
1429
1430 /* flush the write to verify completion */
1431 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001432 usleep_range(1000, 2000);
Alexander Duyck2d064c02008-07-08 15:10:12 -07001433 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001434}
1435
1436/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001437 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001438 * @hw: pointer to the HW structure
1439 *
1440 * This resets the hardware into a known state. This is a
1441 * function pointer entry point called by the api module.
1442 **/
1443static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1444{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001445 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 s32 ret_val;
1447
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001448 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001449 * on the last TLP read/write transaction when MAC is reset.
1450 */
1451 ret_val = igb_disable_pcie_master(hw);
1452 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001453 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001454
Alexander Duyck009bc062009-07-23 18:08:35 +00001455 /* set the completion timeout for interface */
1456 ret_val = igb_set_pcie_completion_timeout(hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001457 if (ret_val)
Alexander Duyck009bc062009-07-23 18:08:35 +00001458 hw_dbg("PCI-E Set completion timeout has failed.\n");
Alexander Duyck009bc062009-07-23 18:08:35 +00001459
Auke Kok652fff32008-06-27 11:00:18 -07001460 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001461 wr32(E1000_IMC, 0xffffffff);
1462
1463 wr32(E1000_RCTL, 0);
1464 wr32(E1000_TCTL, E1000_TCTL_PSP);
1465 wrfl();
1466
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001467 usleep_range(10000, 20000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001468
1469 ctrl = rd32(E1000_CTRL);
1470
Auke Kok652fff32008-06-27 11:00:18 -07001471 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001472 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1473
1474 ret_val = igb_get_auto_rd_done(hw);
1475 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001476 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001477 * return with an error. This can happen in situations
1478 * where there is no eeprom and prevents getting link.
1479 */
Auke Kok652fff32008-06-27 11:00:18 -07001480 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001481 }
1482
1483 /* If EEPROM is not present, run manual init scripts */
1484 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1485 igb_reset_init_script_82575(hw);
1486
1487 /* Clear any pending interrupt events. */
1488 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001489 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001490
Alexander Duyck5ac16652009-07-23 18:09:12 +00001491 /* Install any alternate MAC address into RAR0 */
1492 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001493
1494 return ret_val;
1495}
1496
1497/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001498 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001499 * @hw: pointer to the HW structure
1500 *
1501 * This inits the hardware readying it for operation.
1502 **/
1503static s32 igb_init_hw_82575(struct e1000_hw *hw)
1504{
1505 struct e1000_mac_info *mac = &hw->mac;
1506 s32 ret_val;
1507 u16 i, rar_count = mac->rar_entry_count;
1508
Todd Fujinaka94826482014-07-10 01:47:15 -07001509 if ((hw->mac.type >= e1000_i210) &&
1510 !(igb_get_flash_presence_i210(hw))) {
1511 ret_val = igb_pll_workaround_i210(hw);
1512 if (ret_val)
1513 return ret_val;
1514 }
1515
Auke Kok9d5c8242008-01-24 02:22:38 -08001516 /* Initialize identification LED */
1517 ret_val = igb_id_led_init(hw);
1518 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001519 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001520 /* This is not fatal and we should not stop init due to this */
1521 }
1522
1523 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001524 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001525 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001526 igb_clear_vfta_i350(hw);
1527 else
1528 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001529
1530 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001531 igb_init_rx_addrs(hw, rar_count);
1532
Auke Kok9d5c8242008-01-24 02:22:38 -08001533 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001534 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001535 for (i = 0; i < mac->mta_reg_count; i++)
1536 array_wr32(E1000_MTA, i, 0);
1537
Alexander Duyck68d480c2009-10-05 06:33:08 +00001538 /* Zero out the Unicast HASH table */
1539 hw_dbg("Zeroing the UTA\n");
1540 for (i = 0; i < mac->uta_reg_count; i++)
1541 array_wr32(E1000_UTA, i, 0);
1542
Auke Kok9d5c8242008-01-24 02:22:38 -08001543 /* Setup link and flow control */
1544 ret_val = igb_setup_link(hw);
1545
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001546 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001547 * important that we do this after we have tried to establish link
1548 * because the symbol error count will increment wildly if there
1549 * is no link.
1550 */
1551 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001552 return ret_val;
1553}
1554
1555/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001556 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001557 * @hw: pointer to the HW structure
1558 *
1559 * Configures the link for auto-neg or forced speed and duplex. Then we check
1560 * for link, once link is established calls to configure collision distance
1561 * and flow control are called.
1562 **/
1563static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1564{
Alexander Duyck12645a12009-07-23 18:08:16 +00001565 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001566 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001567 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001568
1569 ctrl = rd32(E1000_CTRL);
1570 ctrl |= E1000_CTRL_SLU;
1571 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1572 wr32(E1000_CTRL, ctrl);
1573
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001574 /* Clear Go Link Disconnect bit on supported devices */
1575 switch (hw->mac.type) {
1576 case e1000_82580:
1577 case e1000_i350:
1578 case e1000_i210:
1579 case e1000_i211:
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001580 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1581 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1582 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001583 break;
1584 default:
1585 break;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001586 }
1587
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001588 ret_val = igb_setup_serdes_link_82575(hw);
1589 if (ret_val)
1590 goto out;
1591
1592 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001593 /* allow time for SFP cage time to power up phy */
1594 msleep(300);
1595
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001596 ret_val = hw->phy.ops.reset(hw);
1597 if (ret_val) {
1598 hw_dbg("Error resetting the PHY.\n");
1599 goto out;
1600 }
1601 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001602 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001603 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001604 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001605 switch (hw->phy.id) {
1606 case I347AT4_E_PHY_ID:
1607 case M88E1112_E_PHY_ID:
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001608 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001609 case M88E1512_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001610 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001611 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001612 break;
1613 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001614 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001615 break;
1616 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001617 break;
1618 case e1000_phy_igp_3:
1619 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001620 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001621 case e1000_phy_82580:
1622 ret_val = igb_copper_link_setup_82580(hw);
1623 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 default:
1625 ret_val = -E1000_ERR_PHY;
1626 break;
1627 }
1628
1629 if (ret_val)
1630 goto out;
1631
Alexander Duyck81fadd82009-10-05 06:35:03 +00001632 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001633out:
1634 return ret_val;
1635}
1636
1637/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001638 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001639 * @hw: pointer to the HW structure
1640 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001641 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1642 * used on copper connections where the serialized gigabit media independent
1643 * interface (sgmii), or serdes fiber is being used. Configures the link
1644 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001645 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001646static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001647{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001648 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001649 bool pcs_autoneg;
Todd Fujinaka23d87822014-06-04 07:12:15 +00001650 s32 ret_val = 0;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001651 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001652
1653 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1654 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001655 return ret_val;
1656
Auke Kok9d5c8242008-01-24 02:22:38 -08001657
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001658 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001659 * explicitly turned off or a power cycle is performed. A read to
1660 * the register does not indicate its status. Therefore, we ensure
1661 * loopback mode is disabled during initialization.
1662 */
1663 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1664
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001665 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001666 ctrl_ext = rd32(E1000_CTRL_EXT);
1667 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001668 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001669 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001670
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001671 ctrl_reg = rd32(E1000_CTRL);
1672 ctrl_reg |= E1000_CTRL_SLU;
1673
1674 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1675 /* set both sw defined pins */
1676 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1677
1678 /* Set switch control to serdes energy detect */
1679 reg = rd32(E1000_CONNSW);
1680 reg |= E1000_CONNSW_ENRGSRC;
1681 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001682 }
1683
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001684 reg = rd32(E1000_PCS_LCTL);
1685
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001686 /* default pcs_autoneg to the same setting as mac autoneg */
1687 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001688
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001689 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1690 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1691 /* sgmii mode lets the phy handle forcing speed/duplex */
1692 pcs_autoneg = true;
1693 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001694 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001695 break;
1696 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1697 /* disable PCS autoneg and support parallel detect only */
1698 pcs_autoneg = false;
1699 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001700 if (hw->mac.type == e1000_82575 ||
1701 hw->mac.type == e1000_82576) {
1702 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1703 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00001704 hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001705 return ret_val;
1706 }
1707
1708 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1709 pcs_autoneg = false;
1710 }
1711
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001712 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001713 * link so it is best to just force the MAC and let the pcs
1714 * link either autoneg or be forced to 1000/Full
1715 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001716 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001717 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001718
1719 /* set speed of 1000/Full if speed/duplex is forced */
1720 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1721 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001722 }
1723
1724 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001725
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001726 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001727 * at 1gb. Autoneg should be default set by most drivers. This is the
1728 * mode that will be compatible with older link partners and switches.
1729 * However, both are supported by the hardware and some drivers/tools.
1730 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001731 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1732 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1733
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001734 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001735 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001736 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001737 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001738
1739 /* Disable force flow control for autoneg */
1740 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1741
1742 /* Configure flow control advertisement for autoneg */
1743 anadv_reg = rd32(E1000_PCS_ANADV);
1744 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1745 switch (hw->fc.requested_mode) {
1746 case e1000_fc_full:
1747 case e1000_fc_rx_pause:
1748 anadv_reg |= E1000_TXCW_ASM_DIR;
1749 anadv_reg |= E1000_TXCW_PAUSE;
1750 break;
1751 case e1000_fc_tx_pause:
1752 anadv_reg |= E1000_TXCW_ASM_DIR;
1753 break;
1754 default:
1755 break;
1756 }
1757 wr32(E1000_PCS_ANADV, anadv_reg);
1758
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001759 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001760 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001761 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001762 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001763
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001764 /* Force flow control for forced link */
1765 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1766
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001767 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001768 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001769
Auke Kok9d5c8242008-01-24 02:22:38 -08001770 wr32(E1000_PCS_LCTL, reg);
1771
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001772 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001773 igb_force_mac_fc(hw);
1774
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001775 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001776}
1777
1778/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001779 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001780 * @hw: pointer to the HW structure
1781 *
1782 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1783 * which can be enabled for use in the embedded applications. Simply
1784 * return the current state of the sgmii interface.
1785 **/
1786static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1787{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001788 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001789 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001790}
1791
1792/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001793 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001794 * @hw: pointer to the HW structure
1795 *
1796 * Inits recommended HW defaults after a reset when there is no EEPROM
1797 * detected. This is only for the 82575.
1798 **/
1799static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1800{
1801 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001802 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001803 /* SerDes configuration via SERDESCTRL */
1804 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1805 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1806 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1807 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1808
1809 /* CCM configuration via CCMCTL register */
1810 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1811 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1812
1813 /* PCIe lanes configuration */
1814 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1815 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1816 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1817 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1818
1819 /* PCIe PLL Configuration */
1820 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1821 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1822 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1823 }
1824
1825 return 0;
1826}
1827
1828/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001829 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001830 * @hw: pointer to the HW structure
1831 **/
1832static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1833{
1834 s32 ret_val = 0;
1835
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001836 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001837 * so that it will override the Si installed default perm
1838 * address.
1839 */
1840 ret_val = igb_check_alt_mac_addr(hw);
1841 if (ret_val)
1842 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001843
Alexander Duyck22896632009-10-05 06:34:25 +00001844 ret_val = igb_read_mac_addr(hw);
1845
1846out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001847 return ret_val;
1848}
1849
1850/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001851 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1852 * @hw: pointer to the HW structure
1853 *
1854 * In the case of a PHY power down to save power, or to turn off link during a
1855 * driver unload, or wake on lan is not enabled, remove the link.
1856 **/
1857void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1858{
1859 /* If the management interface is not enabled, then power down */
1860 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1861 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001862}
1863
1864/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001865 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001866 * @hw: pointer to the HW structure
1867 *
1868 * Clears the hardware counters by reading the counter registers.
1869 **/
1870static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1871{
Auke Kok9d5c8242008-01-24 02:22:38 -08001872 igb_clear_hw_cntrs_base(hw);
1873
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001874 rd32(E1000_PRC64);
1875 rd32(E1000_PRC127);
1876 rd32(E1000_PRC255);
1877 rd32(E1000_PRC511);
1878 rd32(E1000_PRC1023);
1879 rd32(E1000_PRC1522);
1880 rd32(E1000_PTC64);
1881 rd32(E1000_PTC127);
1882 rd32(E1000_PTC255);
1883 rd32(E1000_PTC511);
1884 rd32(E1000_PTC1023);
1885 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001886
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001887 rd32(E1000_ALGNERRC);
1888 rd32(E1000_RXERRC);
1889 rd32(E1000_TNCRS);
1890 rd32(E1000_CEXTERR);
1891 rd32(E1000_TSCTC);
1892 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001893
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001894 rd32(E1000_MGTPRC);
1895 rd32(E1000_MGTPDC);
1896 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001897
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001898 rd32(E1000_IAC);
1899 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001900
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001901 rd32(E1000_ICRXPTC);
1902 rd32(E1000_ICRXATC);
1903 rd32(E1000_ICTXPTC);
1904 rd32(E1000_ICTXATC);
1905 rd32(E1000_ICTXQEC);
1906 rd32(E1000_ICTXQMTC);
1907 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001908
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001909 rd32(E1000_CBTMPC);
1910 rd32(E1000_HTDPMC);
1911 rd32(E1000_CBRMPC);
1912 rd32(E1000_RPTHC);
1913 rd32(E1000_HGPTC);
1914 rd32(E1000_HTCBDPC);
1915 rd32(E1000_HGORCL);
1916 rd32(E1000_HGORCH);
1917 rd32(E1000_HGOTCL);
1918 rd32(E1000_HGOTCH);
1919 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001920
1921 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001922 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1923 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001924 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001925}
1926
Alexander Duyck662d7202008-06-27 11:00:29 -07001927/**
1928 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1929 * @hw: pointer to the HW structure
1930 *
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001931 * After rx enable if manageability is enabled then there is likely some
1932 * bad data at the start of the fifo and possibly in the DMA fifo. This
Alexander Duyck662d7202008-06-27 11:00:29 -07001933 * function clears the fifos and flushes any packets that came in as rx was
1934 * being enabled.
1935 **/
1936void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1937{
1938 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1939 int i, ms_wait;
1940
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001941 /* disable IPv6 options as per hardware errata */
1942 rfctl = rd32(E1000_RFCTL);
1943 rfctl |= E1000_RFCTL_IPV6_EX_DIS;
1944 wr32(E1000_RFCTL, rfctl);
1945
Alexander Duyck662d7202008-06-27 11:00:29 -07001946 if (hw->mac.type != e1000_82575 ||
1947 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1948 return;
1949
1950 /* Disable all RX queues */
1951 for (i = 0; i < 4; i++) {
1952 rxdctl[i] = rd32(E1000_RXDCTL(i));
1953 wr32(E1000_RXDCTL(i),
1954 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1955 }
1956 /* Poll all queues to verify they have shut down */
1957 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001958 usleep_range(1000, 2000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001959 rx_enabled = 0;
1960 for (i = 0; i < 4; i++)
1961 rx_enabled |= rd32(E1000_RXDCTL(i));
1962 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1963 break;
1964 }
1965
1966 if (ms_wait == 10)
1967 hw_dbg("Queue disable timed out after 10ms\n");
1968
1969 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1970 * incoming packets are rejected. Set enable and wait 2ms so that
1971 * any packet that was coming in as RCTL.EN was set is flushed
1972 */
Alexander Duyck662d7202008-06-27 11:00:29 -07001973 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1974
1975 rlpml = rd32(E1000_RLPML);
1976 wr32(E1000_RLPML, 0);
1977
1978 rctl = rd32(E1000_RCTL);
1979 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1980 temp_rctl |= E1000_RCTL_LPE;
1981
1982 wr32(E1000_RCTL, temp_rctl);
1983 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1984 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001985 usleep_range(2000, 3000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001986
1987 /* Enable RX queues that were previously enabled and restore our
1988 * previous state
1989 */
1990 for (i = 0; i < 4; i++)
1991 wr32(E1000_RXDCTL(i), rxdctl[i]);
1992 wr32(E1000_RCTL, rctl);
1993 wrfl();
1994
1995 wr32(E1000_RLPML, rlpml);
1996 wr32(E1000_RFCTL, rfctl);
1997
1998 /* Flush receive errors generated by workaround */
1999 rd32(E1000_ROC);
2000 rd32(E1000_RNBC);
2001 rd32(E1000_MPC);
2002}
2003
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002004/**
Alexander Duyck009bc062009-07-23 18:08:35 +00002005 * igb_set_pcie_completion_timeout - set pci-e completion timeout
2006 * @hw: pointer to the HW structure
2007 *
2008 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2009 * however the hardware default for these parts is 500us to 1ms which is less
2010 * than the 10ms recommended by the pci-e spec. To address this we need to
2011 * increase the value to either 10ms to 200ms for capability version 1 config,
2012 * or 16ms to 55ms for version 2.
2013 **/
2014static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
2015{
2016 u32 gcr = rd32(E1000_GCR);
2017 s32 ret_val = 0;
2018 u16 pcie_devctl2;
2019
2020 /* only take action if timeout value is defaulted to 0 */
2021 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2022 goto out;
2023
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002024 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00002025 * timeout of 10ms to 200ms through the GCR register
2026 */
2027 if (!(gcr & E1000_GCR_CAP_VER2)) {
2028 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2029 goto out;
2030 }
2031
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002032 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00002033 * directly in order to set the completion timeout value for
2034 * 16ms to 55ms
2035 */
2036 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002037 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002038 if (ret_val)
2039 goto out;
2040
2041 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2042
2043 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002044 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002045out:
2046 /* disable completion timeout resend */
2047 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2048
2049 wr32(E1000_GCR, gcr);
2050 return ret_val;
2051}
2052
2053/**
Greg Rose13800462010-11-06 02:08:26 +00002054 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2055 * @hw: pointer to the hardware struct
2056 * @enable: state to enter, either enabled or disabled
2057 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2058 *
2059 * enables/disables L2 switch anti-spoofing functionality.
2060 **/
2061void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2062{
Lior Levy22c12752013-03-12 15:49:32 +00002063 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00002064
2065 switch (hw->mac.type) {
2066 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00002067 reg_offset = E1000_DTXSWC;
2068 break;
Greg Rose13800462010-11-06 02:08:26 +00002069 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002070 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00002071 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00002072 break;
2073 default:
Lior Levy22c12752013-03-12 15:49:32 +00002074 return;
Greg Rose13800462010-11-06 02:08:26 +00002075 }
Lior Levy22c12752013-03-12 15:49:32 +00002076
2077 reg_val = rd32(reg_offset);
2078 if (enable) {
2079 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2080 E1000_DTXSWC_VLAN_SPOOF_MASK);
2081 /* The PF can spoof - it has to in order to
2082 * support emulation mode NICs
2083 */
2084 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2085 } else {
2086 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2087 E1000_DTXSWC_VLAN_SPOOF_MASK);
2088 }
2089 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00002090}
2091
2092/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002093 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2094 * @hw: pointer to the hardware struct
2095 * @enable: state to enter, either enabled or disabled
2096 *
2097 * enables/disables L2 switch loopback functionality.
2098 **/
2099void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2100{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002101 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002102
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002103 switch (hw->mac.type) {
2104 case e1000_82576:
2105 dtxswc = rd32(E1000_DTXSWC);
2106 if (enable)
2107 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2108 else
2109 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2110 wr32(E1000_DTXSWC, dtxswc);
2111 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002112 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002113 case e1000_i350:
2114 dtxswc = rd32(E1000_TXSWC);
2115 if (enable)
2116 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2117 else
2118 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2119 wr32(E1000_TXSWC, dtxswc);
2120 break;
2121 default:
2122 /* Currently no other hardware supports loopback */
2123 break;
2124 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002125
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002126}
2127
2128/**
2129 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2130 * @hw: pointer to the hardware struct
2131 * @enable: state to enter, either enabled or disabled
2132 *
2133 * enables/disables replication of packets across multiple pools.
2134 **/
2135void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2136{
2137 u32 vt_ctl = rd32(E1000_VT_CTL);
2138
2139 if (enable)
2140 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2141 else
2142 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2143
2144 wr32(E1000_VT_CTL, vt_ctl);
2145}
2146
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002147/**
2148 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2149 * @hw: pointer to the HW structure
2150 * @offset: register offset to be read
2151 * @data: pointer to the read data
2152 *
2153 * Reads the MDI control register in the PHY at offset and stores the
2154 * information read to data.
2155 **/
2156static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2157{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002158 s32 ret_val;
2159
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002160 ret_val = hw->phy.ops.acquire(hw);
2161 if (ret_val)
2162 goto out;
2163
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002164 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2165
2166 hw->phy.ops.release(hw);
2167
2168out:
2169 return ret_val;
2170}
2171
2172/**
2173 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2174 * @hw: pointer to the HW structure
2175 * @offset: register offset to write to
2176 * @data: data to write to register at offset
2177 *
2178 * Writes data to MDI control register in the PHY at offset.
2179 **/
2180static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2181{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002182 s32 ret_val;
2183
2184
2185 ret_val = hw->phy.ops.acquire(hw);
2186 if (ret_val)
2187 goto out;
2188
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002189 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2190
2191 hw->phy.ops.release(hw);
2192
2193out:
2194 return ret_val;
2195}
2196
2197/**
Nick Nunley08451e22010-07-26 13:15:29 +00002198 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2199 * @hw: pointer to the HW structure
2200 *
2201 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2202 * the values found in the EEPROM. This addresses an issue in which these
2203 * bits are not restored from EEPROM after reset.
2204 **/
2205static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2206{
2207 s32 ret_val = 0;
2208 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002209 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002210
2211 if (hw->mac.type != e1000_82580)
2212 goto out;
2213 if (!igb_sgmii_active_82575(hw))
2214 goto out;
2215
2216 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2217 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2218 &nvm_data);
2219 if (ret_val) {
2220 hw_dbg("NVM Read Error\n");
2221 goto out;
2222 }
2223
2224 mdicnfg = rd32(E1000_MDICNFG);
2225 if (nvm_data & NVM_WORD24_EXT_MDIO)
2226 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2227 if (nvm_data & NVM_WORD24_COM_MDIO)
2228 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2229 wr32(E1000_MDICNFG, mdicnfg);
2230out:
2231 return ret_val;
2232}
2233
2234/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002235 * igb_reset_hw_82580 - Reset hardware
2236 * @hw: pointer to the HW structure
2237 *
2238 * This resets function or entire device (all ports, etc.)
2239 * to a known state.
2240 **/
2241static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2242{
2243 s32 ret_val = 0;
2244 /* BH SW mailbox bit in SW_FW_SYNC */
2245 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002246 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002247 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2248
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002249 hw->dev_spec._82575.global_device_reset = false;
2250
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002251 /* due to hw errata, global device reset doesn't always
2252 * work on 82580
2253 */
2254 if (hw->mac.type == e1000_82580)
2255 global_device_reset = false;
2256
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002257 /* Get current control state. */
2258 ctrl = rd32(E1000_CTRL);
2259
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002260 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002261 * on the last TLP read/write transaction when MAC is reset.
2262 */
2263 ret_val = igb_disable_pcie_master(hw);
2264 if (ret_val)
2265 hw_dbg("PCI-E Master disable polling has failed.\n");
2266
2267 hw_dbg("Masking off all interrupts\n");
2268 wr32(E1000_IMC, 0xffffffff);
2269 wr32(E1000_RCTL, 0);
2270 wr32(E1000_TCTL, E1000_TCTL_PSP);
2271 wrfl();
2272
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002273 usleep_range(10000, 11000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002274
2275 /* Determine whether or not a global dev reset is requested */
2276 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002277 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002278 global_device_reset = false;
2279
2280 if (global_device_reset &&
2281 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2282 ctrl |= E1000_CTRL_DEV_RST;
2283 else
2284 ctrl |= E1000_CTRL_RST;
2285
2286 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002287 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002288
2289 /* Add delay to insure DEV_RST has time to complete */
2290 if (global_device_reset)
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002291 usleep_range(5000, 6000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002292
2293 ret_val = igb_get_auto_rd_done(hw);
2294 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002295 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002296 * return with an error. This can happen in situations
2297 * where there is no eeprom and prevents getting link.
2298 */
2299 hw_dbg("Auto Read Done did not complete\n");
2300 }
2301
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002302 /* clear global device reset status bit */
2303 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2304
2305 /* Clear any pending interrupt events. */
2306 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002307 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002308
Nick Nunley08451e22010-07-26 13:15:29 +00002309 ret_val = igb_reset_mdicnfg_82580(hw);
2310 if (ret_val)
2311 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2312
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002313 /* Install any alternate MAC address into RAR0 */
2314 ret_val = igb_check_alt_mac_addr(hw);
2315
2316 /* Release semaphore */
2317 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002318 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002319
2320 return ret_val;
2321}
2322
2323/**
2324 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2325 * @data: data received by reading RXPBS register
2326 *
2327 * The 82580 uses a table based approach for packet buffer allocation sizes.
2328 * This function converts the retrieved value into the correct table value
2329 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2330 * 0x0 36 72 144 1 2 4 8 16
2331 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2332 */
2333u16 igb_rxpbs_adjust_82580(u32 data)
2334{
2335 u16 ret_val = 0;
2336
Todd Fujinaka72b36722014-03-04 02:25:22 +00002337 if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002338 ret_val = e1000_82580_rxpbs_table[data];
2339
2340 return ret_val;
2341}
2342
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002343/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002344 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2345 * checksum
2346 * @hw: pointer to the HW structure
2347 * @offset: offset in words of the checksum protected region
2348 *
2349 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2350 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2351 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002352static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2353 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002354{
2355 s32 ret_val = 0;
2356 u16 checksum = 0;
2357 u16 i, nvm_data;
2358
2359 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2360 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2361 if (ret_val) {
2362 hw_dbg("NVM Read Error\n");
2363 goto out;
2364 }
2365 checksum += nvm_data;
2366 }
2367
2368 if (checksum != (u16) NVM_SUM) {
2369 hw_dbg("NVM Checksum Invalid\n");
2370 ret_val = -E1000_ERR_NVM;
2371 goto out;
2372 }
2373
2374out:
2375 return ret_val;
2376}
2377
2378/**
2379 * igb_update_nvm_checksum_with_offset - Update EEPROM
2380 * checksum
2381 * @hw: pointer to the HW structure
2382 * @offset: offset in words of the checksum protected region
2383 *
2384 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2385 * up to the checksum. Then calculates the EEPROM checksum and writes the
2386 * value to the EEPROM.
2387 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002388static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002389{
2390 s32 ret_val;
2391 u16 checksum = 0;
2392 u16 i, nvm_data;
2393
2394 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2395 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2396 if (ret_val) {
2397 hw_dbg("NVM Read Error while updating checksum.\n");
2398 goto out;
2399 }
2400 checksum += nvm_data;
2401 }
2402 checksum = (u16) NVM_SUM - checksum;
2403 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2404 &checksum);
2405 if (ret_val)
2406 hw_dbg("NVM Write Error while updating checksum.\n");
2407
2408out:
2409 return ret_val;
2410}
2411
2412/**
2413 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2414 * @hw: pointer to the HW structure
2415 *
2416 * Calculates the EEPROM section checksum by reading/adding each word of
2417 * the EEPROM and then verifies that the sum of the EEPROM is
2418 * equal to 0xBABA.
2419 **/
2420static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2421{
2422 s32 ret_val = 0;
2423 u16 eeprom_regions_count = 1;
2424 u16 j, nvm_data;
2425 u16 nvm_offset;
2426
2427 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2428 if (ret_val) {
2429 hw_dbg("NVM Read Error\n");
2430 goto out;
2431 }
2432
2433 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002434 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002435 * for all 4 ports.
2436 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002437 eeprom_regions_count = 4;
2438 }
2439
2440 for (j = 0; j < eeprom_regions_count; j++) {
2441 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2442 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2443 nvm_offset);
2444 if (ret_val != 0)
2445 goto out;
2446 }
2447
2448out:
2449 return ret_val;
2450}
2451
2452/**
2453 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2454 * @hw: pointer to the HW structure
2455 *
2456 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2457 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2458 * checksum and writes the value to the EEPROM.
2459 **/
2460static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2461{
2462 s32 ret_val;
2463 u16 j, nvm_data;
2464 u16 nvm_offset;
2465
2466 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2467 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002468 hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002469 goto out;
2470 }
2471
2472 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2473 /* set compatibility bit to validate checksums appropriately */
2474 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2475 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2476 &nvm_data);
2477 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002478 hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002479 goto out;
2480 }
2481 }
2482
2483 for (j = 0; j < 4; j++) {
2484 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2485 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2486 if (ret_val)
2487 goto out;
2488 }
2489
2490out:
2491 return ret_val;
2492}
2493
2494/**
2495 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2496 * @hw: pointer to the HW structure
2497 *
2498 * Calculates the EEPROM section checksum by reading/adding each word of
2499 * the EEPROM and then verifies that the sum of the EEPROM is
2500 * equal to 0xBABA.
2501 **/
2502static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2503{
2504 s32 ret_val = 0;
2505 u16 j;
2506 u16 nvm_offset;
2507
2508 for (j = 0; j < 4; j++) {
2509 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2510 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2511 nvm_offset);
2512 if (ret_val != 0)
2513 goto out;
2514 }
2515
2516out:
2517 return ret_val;
2518}
2519
2520/**
2521 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2522 * @hw: pointer to the HW structure
2523 *
2524 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2525 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2526 * checksum and writes the value to the EEPROM.
2527 **/
2528static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2529{
2530 s32 ret_val = 0;
2531 u16 j;
2532 u16 nvm_offset;
2533
2534 for (j = 0; j < 4; j++) {
2535 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2536 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2537 if (ret_val != 0)
2538 goto out;
2539 }
2540
2541out:
2542 return ret_val;
2543}
Stefan Assmann34a03262011-04-05 04:27:05 +00002544
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002545/**
Matthew Vick87371b92013-02-21 03:32:52 +00002546 * __igb_access_emi_reg - Read/write EMI register
2547 * @hw: pointer to the HW structure
2548 * @addr: EMI address to program
2549 * @data: pointer to value to read/write from/to the EMI address
2550 * @read: boolean flag to indicate read or write
2551 **/
2552static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2553 u16 *data, bool read)
2554{
Todd Fujinaka23d87822014-06-04 07:12:15 +00002555 s32 ret_val = 0;
Matthew Vick87371b92013-02-21 03:32:52 +00002556
2557 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2558 if (ret_val)
2559 return ret_val;
2560
2561 if (read)
2562 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2563 else
2564 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2565
2566 return ret_val;
2567}
2568
2569/**
2570 * igb_read_emi_reg - Read Extended Management Interface register
2571 * @hw: pointer to the HW structure
2572 * @addr: EMI address to program
2573 * @data: value to be read from the EMI address
2574 **/
2575s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2576{
2577 return __igb_access_emi_reg(hw, addr, data, true);
2578}
2579
2580/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002581 * igb_set_eee_i350 - Enable/disable EEE support
2582 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002583 * @adv1G: boolean flag enabling 1G EEE advertisement
2584 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002585 *
2586 * Enable/disable EEE based on setting in dev_spec structure.
2587 *
2588 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002589s32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002590{
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002591 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002592
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002593 if ((hw->mac.type < e1000_i350) ||
2594 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002595 goto out;
2596 ipcnfg = rd32(E1000_IPCNFG);
2597 eeer = rd32(E1000_EEER);
2598
2599 /* enable or disable per user setting */
2600 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002601 u32 eee_su = rd32(E1000_EEE_SU);
2602
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002603 if (adv100M)
2604 ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
2605 else
2606 ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
2607
2608 if (adv1G)
2609 ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
2610 else
2611 ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
2612
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002613 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002614 E1000_EEER_LPI_FC);
2615
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002616 /* This bit should not be set in normal operation. */
2617 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2618 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2619
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002620 } else {
2621 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2622 E1000_IPCNFG_EEE_100M_AN);
2623 eeer &= ~(E1000_EEER_TX_LPI_EN |
2624 E1000_EEER_RX_LPI_EN |
2625 E1000_EEER_LPI_FC);
2626 }
2627 wr32(E1000_IPCNFG, ipcnfg);
2628 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002629 rd32(E1000_IPCNFG);
2630 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002631out:
2632
Todd Fujinaka23d87822014-06-04 07:12:15 +00002633 return 0;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002634}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002635
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002636/**
2637 * igb_set_eee_i354 - Enable/disable EEE support
2638 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002639 * @adv1G: boolean flag enabling 1G EEE advertisement
2640 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002641 *
2642 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2643 *
2644 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002645s32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002646{
2647 struct e1000_phy_info *phy = &hw->phy;
2648 s32 ret_val = 0;
2649 u16 phy_data;
2650
2651 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002652 ((phy->id != M88E1543_E_PHY_ID) &&
2653 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002654 goto out;
2655
2656 if (!hw->dev_spec._82575.eee_disable) {
2657 /* Switch to PHY page 18. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002658 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002659 if (ret_val)
2660 goto out;
2661
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002662 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002663 &phy_data);
2664 if (ret_val)
2665 goto out;
2666
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002667 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2668 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002669 phy_data);
2670 if (ret_val)
2671 goto out;
2672
2673 /* Return the PHY to page 0. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002674 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002675 if (ret_val)
2676 goto out;
2677
2678 /* Turn on EEE advertisement. */
2679 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2680 E1000_EEE_ADV_DEV_I354,
2681 &phy_data);
2682 if (ret_val)
2683 goto out;
2684
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002685 if (adv100M)
2686 phy_data |= E1000_EEE_ADV_100_SUPPORTED;
2687 else
2688 phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
2689
2690 if (adv1G)
2691 phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
2692 else
2693 phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
2694
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002695 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2696 E1000_EEE_ADV_DEV_I354,
2697 phy_data);
2698 } else {
2699 /* Turn off EEE advertisement. */
2700 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2701 E1000_EEE_ADV_DEV_I354,
2702 &phy_data);
2703 if (ret_val)
2704 goto out;
2705
2706 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2707 E1000_EEE_ADV_1000_SUPPORTED);
2708 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2709 E1000_EEE_ADV_DEV_I354,
2710 phy_data);
2711 }
2712
2713out:
2714 return ret_val;
2715}
2716
2717/**
2718 * igb_get_eee_status_i354 - Get EEE status
2719 * @hw: pointer to the HW structure
2720 * @status: EEE status
2721 *
2722 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2723 * been received.
2724 **/
2725s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2726{
2727 struct e1000_phy_info *phy = &hw->phy;
2728 s32 ret_val = 0;
2729 u16 phy_data;
2730
2731 /* Check if EEE is supported on this device. */
2732 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002733 ((phy->id != M88E1543_E_PHY_ID) &&
2734 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002735 goto out;
2736
2737 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2738 E1000_PCS_STATUS_DEV_I354,
2739 &phy_data);
2740 if (ret_val)
2741 goto out;
2742
2743 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2744 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2745
2746out:
2747 return ret_val;
2748}
2749
Carolyn Wybornye4288932012-12-07 03:01:42 +00002750static const u8 e1000_emc_temp_data[4] = {
2751 E1000_EMC_INTERNAL_DATA,
2752 E1000_EMC_DIODE1_DATA,
2753 E1000_EMC_DIODE2_DATA,
2754 E1000_EMC_DIODE3_DATA
2755};
2756static const u8 e1000_emc_therm_limit[4] = {
2757 E1000_EMC_INTERNAL_THERM_LIMIT,
2758 E1000_EMC_DIODE1_THERM_LIMIT,
2759 E1000_EMC_DIODE2_THERM_LIMIT,
2760 E1000_EMC_DIODE3_THERM_LIMIT
2761};
2762
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002763#ifdef CONFIG_IGB_HWMON
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002764/**
2765 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002766 * @hw: pointer to hardware structure
2767 *
2768 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002769 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002770static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002771{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002772 u16 ets_offset;
2773 u16 ets_cfg;
2774 u16 ets_sensor;
2775 u8 num_sensors;
2776 u8 sensor_index;
2777 u8 sensor_location;
2778 u8 i;
2779 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2780
2781 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2782 return E1000_NOT_IMPLEMENTED;
2783
2784 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2785
2786 /* Return the internal sensor only if ETS is unsupported */
2787 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2788 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002789 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002790
2791 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2792 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2793 != NVM_ETS_TYPE_EMC)
2794 return E1000_NOT_IMPLEMENTED;
2795
2796 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2797 if (num_sensors > E1000_MAX_SENSORS)
2798 num_sensors = E1000_MAX_SENSORS;
2799
2800 for (i = 1; i < num_sensors; i++) {
2801 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2802 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2803 NVM_ETS_DATA_INDEX_SHIFT);
2804 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2805 NVM_ETS_DATA_LOC_SHIFT);
2806
2807 if (sensor_location != 0)
2808 hw->phy.ops.read_i2c_byte(hw,
2809 e1000_emc_temp_data[sensor_index],
2810 E1000_I2C_THERMAL_SENSOR_ADDR,
2811 &data->sensor[i].temp);
2812 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002813 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002814}
2815
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002816/**
2817 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002818 * @hw: pointer to hardware structure
2819 *
2820 * Sets the thermal sensor thresholds according to the NVM map
2821 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002822 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002823static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002824{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002825 u16 ets_offset;
2826 u16 ets_cfg;
2827 u16 ets_sensor;
2828 u8 low_thresh_delta;
2829 u8 num_sensors;
2830 u8 sensor_index;
2831 u8 sensor_location;
2832 u8 therm_limit;
2833 u8 i;
2834 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2835
2836 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2837 return E1000_NOT_IMPLEMENTED;
2838
2839 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2840
2841 data->sensor[0].location = 0x1;
2842 data->sensor[0].caution_thresh =
2843 (rd32(E1000_THHIGHTC) & 0xFF);
2844 data->sensor[0].max_op_thresh =
2845 (rd32(E1000_THLOWTC) & 0xFF);
2846
2847 /* Return the internal sensor only if ETS is unsupported */
2848 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2849 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002850 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002851
2852 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2853 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2854 != NVM_ETS_TYPE_EMC)
2855 return E1000_NOT_IMPLEMENTED;
2856
2857 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2858 NVM_ETS_LTHRES_DELTA_SHIFT);
2859 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2860
2861 for (i = 1; i <= num_sensors; i++) {
2862 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2863 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2864 NVM_ETS_DATA_INDEX_SHIFT);
2865 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2866 NVM_ETS_DATA_LOC_SHIFT);
2867 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2868
2869 hw->phy.ops.write_i2c_byte(hw,
2870 e1000_emc_therm_limit[sensor_index],
2871 E1000_I2C_THERMAL_SENSOR_ADDR,
2872 therm_limit);
2873
2874 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2875 data->sensor[i].location = sensor_location;
2876 data->sensor[i].caution_thresh = therm_limit;
2877 data->sensor[i].max_op_thresh = therm_limit -
2878 low_thresh_delta;
2879 }
2880 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002881 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002882}
2883
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002884#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002885static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002886 .init_hw = igb_init_hw_82575,
2887 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002888 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002889 .read_mac_addr = igb_read_mac_addr_82575,
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00002890 .get_speed_and_duplex = igb_get_link_up_info_82575,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002891#ifdef CONFIG_IGB_HWMON
2892 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2893 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2894#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002895};
2896
2897static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002898 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002899 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002900 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002901 .write_i2c_byte = igb_write_i2c_byte,
2902 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002903};
2904
2905static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002906 .acquire = igb_acquire_nvm_82575,
2907 .read = igb_read_nvm_eerd,
2908 .release = igb_release_nvm_82575,
2909 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002910};
2911
2912const struct e1000_info e1000_82575_info = {
2913 .get_invariants = igb_get_invariants_82575,
2914 .mac_ops = &e1000_mac_ops_82575,
2915 .phy_ops = &e1000_phy_ops_82575,
2916 .nvm_ops = &e1000_nvm_ops_82575,
2917};
2918