blob: fff50523b4408d2580b244b6f873eee45496e9b7 [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"
Alexander Duyck832e8212016-01-06 23:10:30 -080037#include "igb.h"
Auke Kok9d5c8242008-01-24 02:22:38 -080038
39static s32 igb_get_invariants_82575(struct e1000_hw *);
40static s32 igb_acquire_phy_82575(struct e1000_hw *);
41static void igb_release_phy_82575(struct e1000_hw *);
42static s32 igb_acquire_nvm_82575(struct e1000_hw *);
43static void igb_release_nvm_82575(struct e1000_hw *);
44static s32 igb_check_for_link_82575(struct e1000_hw *);
45static s32 igb_get_cfg_done_82575(struct e1000_hw *);
46static s32 igb_init_hw_82575(struct e1000_hw *);
47static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
48static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Auke Kok9d5c8242008-01-24 02:22:38 -080049static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000050static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080051static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
Carolyn Wybornyda02cde2012-03-04 03:26:26 +000052static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
53static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
Auke Kok9d5c8242008-01-24 02:22:38 -080054static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000055static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080056static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
57static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
58static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080059static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
60 u16 *);
61static s32 igb_get_phy_id_82575(struct e1000_hw *);
62static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
63static bool igb_sgmii_active_82575(struct e1000_hw *);
64static s32 igb_reset_init_script_82575(struct e1000_hw *);
65static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000066static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Alexander Duyck99870a72010-08-03 11:50:08 +000067static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080068static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
69static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080070static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
71static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +000072static const u16 e1000_82580_rxpbs_table[] = {
73 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
Alexander Duyckbb2ac472009-11-19 12:42:01 +000074
Alexander Duyck832e8212016-01-06 23:10:30 -080075/* Due to a hw errata, if the host tries to configure the VFTA register
76 * while performing queries from the BMC or DMA, then the VFTA in some
77 * cases won't be written.
78 */
79
80/**
81 * igb_write_vfta_i350 - Write value to VLAN filter table
82 * @hw: pointer to the HW structure
83 * @offset: register offset in VLAN filter table
84 * @value: register value written to VLAN filter table
85 *
86 * Writes value at the given offset in the register array which stores
87 * the VLAN filter table.
88 **/
89static void igb_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
90{
91 struct igb_adapter *adapter = hw->back;
92 int i;
93
94 for (i = 10; i--;)
95 array_wr32(E1000_VFTA, offset, value);
96
97 wrfl();
98 adapter->shadow_vfta[offset] = value;
99}
100
Nick Nunley4085f742010-07-26 13:15:06 +0000101/**
102 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
103 * @hw: pointer to the HW structure
104 *
105 * Called to determine if the I2C pins are being used for I2C or as an
106 * external MDIO interface since the two options are mutually exclusive.
107 **/
108static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
109{
110 u32 reg = 0;
111 bool ext_mdio = false;
112
113 switch (hw->mac.type) {
114 case e1000_82575:
115 case e1000_82576:
116 reg = rd32(E1000_MDIC);
117 ext_mdio = !!(reg & E1000_MDIC_DEST);
118 break;
119 case e1000_82580:
120 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000121 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000122 case e1000_i210:
123 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000124 reg = rd32(E1000_MDICNFG);
125 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
126 break;
127 default:
128 break;
129 }
130 return ext_mdio;
131}
132
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000133/**
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000134 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
135 * @hw: pointer to the HW structure
136 *
137 * Poll the M88E1112 interfaces to see which interface achieved link.
138 */
139static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
140{
141 struct e1000_phy_info *phy = &hw->phy;
142 s32 ret_val;
143 u16 data;
144 u8 port = 0;
145
146 /* Check the copper medium. */
147 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
148 if (ret_val)
149 return ret_val;
150
151 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
152 if (ret_val)
153 return ret_val;
154
155 if (data & E1000_M88E1112_STATUS_LINK)
156 port = E1000_MEDIA_PORT_COPPER;
157
158 /* Check the other medium. */
159 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
160 if (ret_val)
161 return ret_val;
162
163 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
164 if (ret_val)
165 return ret_val;
166
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000167
168 if (data & E1000_M88E1112_STATUS_LINK)
169 port = E1000_MEDIA_PORT_OTHER;
170
171 /* Determine if a swap needs to happen. */
172 if (port && (hw->dev_spec._82575.media_port != port)) {
173 hw->dev_spec._82575.media_port = port;
174 hw->dev_spec._82575.media_changed = true;
Todd Fujinaka2ba6c072015-04-29 15:23:28 -0700175 }
176
177 if (port == E1000_MEDIA_PORT_COPPER) {
178 /* reset page to 0 */
179 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
180 if (ret_val)
181 return ret_val;
182 igb_check_for_link_82575(hw);
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000183 } else {
Todd Fujinaka2ba6c072015-04-29 15:23:28 -0700184 igb_check_for_link_82575(hw);
185 /* reset page to 0 */
186 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
187 if (ret_val)
188 return ret_val;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000189 }
190
Todd Fujinaka23d87822014-06-04 07:12:15 +0000191 return 0;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000192}
193
194/**
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000195 * igb_init_phy_params_82575 - Init PHY func ptrs.
196 * @hw: pointer to the HW structure
197 **/
198static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
199{
200 struct e1000_phy_info *phy = &hw->phy;
201 s32 ret_val = 0;
202 u32 ctrl_ext;
203
204 if (hw->phy.media_type != e1000_media_type_copper) {
205 phy->type = e1000_phy_none;
206 goto out;
207 }
208
209 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
210 phy->reset_delay_us = 100;
211
212 ctrl_ext = rd32(E1000_CTRL_EXT);
213
214 if (igb_sgmii_active_82575(hw)) {
215 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
216 ctrl_ext |= E1000_CTRL_I2C_ENA;
217 } else {
218 phy->ops.reset = igb_phy_hw_reset;
219 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
220 }
221
222 wr32(E1000_CTRL_EXT, ctrl_ext);
223 igb_reset_mdicnfg_82580(hw);
224
225 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
226 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
227 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
228 } else {
229 switch (hw->mac.type) {
230 case e1000_82580:
231 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000232 case e1000_i354:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000233 case e1000_i210:
234 case e1000_i211:
Aaron Sierra2a3cdea2015-11-03 12:37:09 -0600235 phy->ops.read_reg = igb_read_phy_reg_82580;
236 phy->ops.write_reg = igb_write_phy_reg_82580;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000237 break;
238 default:
239 phy->ops.read_reg = igb_read_phy_reg_igp;
240 phy->ops.write_reg = igb_write_phy_reg_igp;
241 }
242 }
243
244 /* set lan id */
245 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
246 E1000_STATUS_FUNC_SHIFT;
247
248 /* Set phy->phy_addr and phy->id. */
249 ret_val = igb_get_phy_id_82575(hw);
250 if (ret_val)
251 return ret_val;
252
253 /* Verify phy id and set remaining function pointers */
254 switch (phy->id) {
Akeem G Abodunrin99af4722013-08-28 02:22:58 +0000255 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700256 case M88E1512_E_PHY_ID:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000257 case I347AT4_E_PHY_ID:
258 case M88E1112_E_PHY_ID:
259 case M88E1111_I_PHY_ID:
260 phy->type = e1000_phy_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000261 phy->ops.check_polarity = igb_check_polarity_m88;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000262 phy->ops.get_phy_info = igb_get_phy_info_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000263 if (phy->id != M88E1111_I_PHY_ID)
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000264 phy->ops.get_cable_length =
265 igb_get_cable_length_m88_gen2;
266 else
267 phy->ops.get_cable_length = igb_get_cable_length_m88;
268 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700269 /* Check if this PHY is configured for media swap. */
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000270 if (phy->id == M88E1112_E_PHY_ID) {
271 u16 data;
272
273 ret_val = phy->ops.write_reg(hw,
274 E1000_M88E1112_PAGE_ADDR,
275 2);
276 if (ret_val)
277 goto out;
278
279 ret_val = phy->ops.read_reg(hw,
280 E1000_M88E1112_MAC_CTRL_1,
281 &data);
282 if (ret_val)
283 goto out;
284
285 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
286 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
287 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
288 data == E1000_M88E1112_AUTO_COPPER_BASEX)
289 hw->mac.ops.check_for_link =
290 igb_check_for_link_media_swap;
291 }
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700292 if (phy->id == M88E1512_E_PHY_ID) {
293 ret_val = igb_initialize_M88E1512_phy(hw);
294 if (ret_val)
295 goto out;
296 }
Todd Fujinaka18f7ce52015-09-02 16:54:20 -0700297 if (phy->id == M88E1543_E_PHY_ID) {
298 ret_val = igb_initialize_M88E1543_phy(hw);
299 if (ret_val)
300 goto out;
301 }
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000302 break;
303 case IGP03E1000_E_PHY_ID:
304 phy->type = e1000_phy_igp_3;
305 phy->ops.get_phy_info = igb_get_phy_info_igp;
306 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
307 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
308 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
309 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
310 break;
311 case I82580_I_PHY_ID:
312 case I350_I_PHY_ID:
313 phy->type = e1000_phy_82580;
314 phy->ops.force_speed_duplex =
315 igb_phy_force_speed_duplex_82580;
316 phy->ops.get_cable_length = igb_get_cable_length_82580;
317 phy->ops.get_phy_info = igb_get_phy_info_82580;
318 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
319 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
320 break;
321 case I210_I_PHY_ID:
322 phy->type = e1000_phy_i210;
323 phy->ops.check_polarity = igb_check_polarity_m88;
Todd Fujinaka08c99122015-09-18 15:43:51 -0700324 phy->ops.get_cfg_done = igb_get_cfg_done_i210;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000325 phy->ops.get_phy_info = igb_get_phy_info_m88;
326 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
327 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
328 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
329 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
330 break;
331 default:
332 ret_val = -E1000_ERR_PHY;
333 goto out;
334 }
335
336out:
337 return ret_val;
338}
339
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000340/**
341 * igb_init_nvm_params_82575 - Init NVM func ptrs.
342 * @hw: pointer to the HW structure
343 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000344static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000345{
346 struct e1000_nvm_info *nvm = &hw->nvm;
347 u32 eecd = rd32(E1000_EECD);
348 u16 size;
349
350 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
351 E1000_EECD_SIZE_EX_SHIFT);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000352
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000353 /* Added to a constant, "size" becomes the left-shift value
354 * for setting word_size.
355 */
356 size += NVM_WORD_SIZE_BASE_SHIFT;
357
358 /* Just in case size is out of range, cap it to the largest
359 * EEPROM size supported
360 */
361 if (size > 15)
362 size = 15;
363
364 nvm->word_size = 1 << size;
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000365 nvm->opcode_bits = 8;
366 nvm->delay_usec = 1;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000367
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000368 switch (nvm->override) {
369 case e1000_nvm_override_spi_large:
370 nvm->page_size = 32;
371 nvm->address_bits = 16;
372 break;
373 case e1000_nvm_override_spi_small:
374 nvm->page_size = 8;
375 nvm->address_bits = 8;
376 break;
377 default:
378 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
379 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
380 16 : 8;
381 break;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000382 }
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000383 if (nvm->word_size == (1 << 15))
384 nvm->page_size = 128;
385
386 nvm->type = e1000_nvm_eeprom_spi;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000387
388 /* NVM Function Pointers */
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000389 nvm->ops.acquire = igb_acquire_nvm_82575;
390 nvm->ops.release = igb_release_nvm_82575;
391 nvm->ops.write = igb_write_nvm_spi;
392 nvm->ops.validate = igb_validate_nvm_checksum;
393 nvm->ops.update = igb_update_nvm_checksum;
394 if (nvm->word_size < (1 << 15))
395 nvm->ops.read = igb_read_nvm_eerd;
396 else
397 nvm->ops.read = igb_read_nvm_spi;
398
399 /* override generic family function pointers for specific descendants */
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000400 switch (hw->mac.type) {
401 case e1000_82580:
402 nvm->ops.validate = igb_validate_nvm_checksum_82580;
403 nvm->ops.update = igb_update_nvm_checksum_82580;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000404 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000405 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000406 case e1000_i350:
407 nvm->ops.validate = igb_validate_nvm_checksum_i350;
408 nvm->ops.update = igb_update_nvm_checksum_i350;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000409 break;
410 default:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000411 break;
412 }
413
414 return 0;
415}
416
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000417/**
418 * igb_init_mac_params_82575 - Init MAC func ptrs.
419 * @hw: pointer to the HW structure
420 **/
421static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
422{
423 struct e1000_mac_info *mac = &hw->mac;
424 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
425
426 /* Set mta register count */
427 mac->mta_reg_count = 128;
428 /* Set rar entry count */
429 switch (mac->type) {
430 case e1000_82576:
431 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
432 break;
433 case e1000_82580:
434 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
435 break;
436 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000437 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000438 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
439 break;
440 default:
441 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
442 break;
443 }
444 /* reset */
445 if (mac->type >= e1000_82580)
446 mac->ops.reset_hw = igb_reset_hw_82580;
447 else
448 mac->ops.reset_hw = igb_reset_hw_82575;
449
450 if (mac->type >= e1000_i210) {
451 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
452 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
453
454 } else {
455 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
456 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
457 }
458
Alexander Duyck832e8212016-01-06 23:10:30 -0800459 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
460 mac->ops.write_vfta = igb_write_vfta_i350;
461 else
462 mac->ops.write_vfta = igb_write_vfta;
463
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000464 /* Set if part includes ASF firmware */
465 mac->asf_firmware_present = true;
466 /* Set if manageability features are enabled. */
467 mac->arc_subsystem_valid =
468 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
469 ? true : false;
470 /* enable EEE on i350 parts and later parts */
471 if (mac->type >= e1000_i350)
472 dev_spec->eee_disable = false;
473 else
474 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000475 /* Allow a single clear of the SW semaphore on I210 and newer */
476 if (mac->type >= e1000_i210)
477 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000478 /* physical interface link setup */
479 mac->ops.setup_physical_interface =
480 (hw->phy.media_type == e1000_media_type_copper)
481 ? igb_setup_copper_link_82575
482 : igb_setup_serdes_link_82575;
483
Carolyn Wyborny56cec242013-10-17 05:36:26 +0000484 if (mac->type == e1000_82580) {
485 switch (hw->device_id) {
486 /* feature not supported on these id's */
487 case E1000_DEV_ID_DH89XXCC_SGMII:
488 case E1000_DEV_ID_DH89XXCC_SERDES:
489 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
490 case E1000_DEV_ID_DH89XXCC_SFP:
491 break;
492 default:
493 hw->dev_spec._82575.mas_capable = true;
494 break;
495 }
496 }
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000497 return 0;
498}
499
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000500/**
501 * igb_set_sfp_media_type_82575 - derives SFP module media type.
502 * @hw: pointer to the HW structure
503 *
504 * The media type is chosen based on SFP module.
505 * compatibility flags retrieved from SFP ID EEPROM.
506 **/
507static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
508{
509 s32 ret_val = E1000_ERR_CONFIG;
510 u32 ctrl_ext = 0;
511 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
512 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
513 u8 tranceiver_type = 0;
514 s32 timeout = 3;
515
516 /* Turn I2C interface ON and power on sfp cage */
517 ctrl_ext = rd32(E1000_CTRL_EXT);
518 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
519 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
520
521 wrfl();
522
523 /* Read SFP module data */
524 while (timeout) {
525 ret_val = igb_read_sfp_data_byte(hw,
526 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
527 &tranceiver_type);
528 if (ret_val == 0)
529 break;
530 msleep(100);
531 timeout--;
532 }
533 if (ret_val != 0)
534 goto out;
535
536 ret_val = igb_read_sfp_data_byte(hw,
537 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
538 (u8 *)eth_flags);
539 if (ret_val != 0)
540 goto out;
541
542 /* Check if there is some SFP module plugged and powered */
543 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
544 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
545 dev_spec->module_plugged = true;
546 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
547 hw->phy.media_type = e1000_media_type_internal_serdes;
548 } else if (eth_flags->e100_base_fx) {
549 dev_spec->sgmii_active = true;
550 hw->phy.media_type = e1000_media_type_internal_serdes;
551 } else if (eth_flags->e1000_base_t) {
552 dev_spec->sgmii_active = true;
553 hw->phy.media_type = e1000_media_type_copper;
554 } else {
555 hw->phy.media_type = e1000_media_type_unknown;
556 hw_dbg("PHY module has not been recognized\n");
557 goto out;
558 }
559 } else {
560 hw->phy.media_type = e1000_media_type_unknown;
561 }
562 ret_val = 0;
563out:
564 /* Restore I2C interface setting */
565 wr32(E1000_CTRL_EXT, ctrl_ext);
566 return ret_val;
567}
568
Auke Kok9d5c8242008-01-24 02:22:38 -0800569static s32 igb_get_invariants_82575(struct e1000_hw *hw)
570{
Auke Kok9d5c8242008-01-24 02:22:38 -0800571 struct e1000_mac_info *mac = &hw->mac;
Carolyn Wybornyc4917c62014-04-11 01:45:48 +0000572 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800573 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800574 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000575 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800576
577 switch (hw->device_id) {
578 case E1000_DEV_ID_82575EB_COPPER:
579 case E1000_DEV_ID_82575EB_FIBER_SERDES:
580 case E1000_DEV_ID_82575GB_QUAD_COPPER:
581 mac->type = e1000_82575;
582 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700583 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000584 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000585 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700586 case E1000_DEV_ID_82576_FIBER:
587 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000588 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000589 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000590 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700591 mac->type = e1000_82576;
592 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000593 case E1000_DEV_ID_82580_COPPER:
594 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000595 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000596 case E1000_DEV_ID_82580_SERDES:
597 case E1000_DEV_ID_82580_SGMII:
598 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000599 case E1000_DEV_ID_DH89XXCC_SGMII:
600 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000601 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
602 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000603 mac->type = e1000_82580;
604 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000605 case E1000_DEV_ID_I350_COPPER:
606 case E1000_DEV_ID_I350_FIBER:
607 case E1000_DEV_ID_I350_SERDES:
608 case E1000_DEV_ID_I350_SGMII:
609 mac->type = e1000_i350;
610 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000611 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000612 case E1000_DEV_ID_I210_FIBER:
613 case E1000_DEV_ID_I210_SERDES:
614 case E1000_DEV_ID_I210_SGMII:
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +0000615 case E1000_DEV_ID_I210_COPPER_FLASHLESS:
616 case E1000_DEV_ID_I210_SERDES_FLASHLESS:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000617 mac->type = e1000_i210;
618 break;
619 case E1000_DEV_ID_I211_COPPER:
620 mac->type = e1000_i211;
621 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000622 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
623 case E1000_DEV_ID_I354_SGMII:
624 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
625 mac->type = e1000_i354;
626 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800627 default:
628 return -E1000_ERR_MAC_INIT;
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 }
630
Auke Kok9d5c8242008-01-24 02:22:38 -0800631 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000632 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800633 * based on the EEPROM. We cannot rely upon device ID. There
634 * is no distinguishable difference between fiber and internal
635 * SerDes mode on the 82575. There can be an external PHY attached
636 * on the SGMII interface. For this, we'll set sgmii_active to true.
637 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000638 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800639 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000640 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800641
642 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000643
644 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
645 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000646 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000647 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000648 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000649 case E1000_CTRL_EXT_LINK_MODE_SGMII:
650 /* Get phy control interface type set (MDIO vs. I2C)*/
651 if (igb_sgmii_uses_mdio_82575(hw)) {
652 hw->phy.media_type = e1000_media_type_copper;
653 dev_spec->sgmii_active = true;
654 break;
655 }
656 /* fall through for I2C based SGMII */
657 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
658 /* read media type from SFP EEPROM */
659 ret_val = igb_set_sfp_media_type_82575(hw);
660 if ((ret_val != 0) ||
661 (hw->phy.media_type == e1000_media_type_unknown)) {
662 /* If media type was not identified then return media
663 * type defined by the CTRL_EXT settings.
664 */
665 hw->phy.media_type = e1000_media_type_internal_serdes;
666
667 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
668 hw->phy.media_type = e1000_media_type_copper;
669 dev_spec->sgmii_active = true;
670 }
671
672 break;
673 }
674
675 /* do not change link mode for 100BaseFX */
676 if (dev_spec->eth_flags.e100_base_fx)
677 break;
678
679 /* change current link mode setting */
680 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
681
682 if (hw->phy.media_type == e1000_media_type_copper)
683 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
684 else
685 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
686
687 wr32(E1000_CTRL_EXT, ctrl_ext);
688
689 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000690 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000691 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800692 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000693
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000694 /* mac initialization and operations */
695 ret_val = igb_init_mac_params_82575(hw);
696 if (ret_val)
697 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800698
699 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000700 ret_val = igb_init_nvm_params_82575(hw);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000701 switch (hw->mac.type) {
702 case e1000_i210:
703 case e1000_i211:
704 ret_val = igb_init_nvm_params_i210(hw);
705 break;
706 default:
707 break;
708 }
709
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000710 if (ret_val)
711 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800712
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000713 /* if part supports SR-IOV then initialize mailbox parameters */
714 switch (mac->type) {
715 case e1000_82576:
716 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000717 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000718 break;
719 default:
720 break;
721 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000722
Auke Kok9d5c8242008-01-24 02:22:38 -0800723 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000724 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800725
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000726out:
727 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800728}
729
730/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700731 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800732 * @hw: pointer to the HW structure
733 *
734 * Acquire access rights to the correct PHY. This is a
735 * function pointer entry point called by the api module.
736 **/
737static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
738{
Alexander Duyck008c3422009-10-05 06:32:07 +0000739 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800740
Alexander Duyck008c3422009-10-05 06:32:07 +0000741 if (hw->bus.func == E1000_FUNC_1)
742 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000743 else if (hw->bus.func == E1000_FUNC_2)
744 mask = E1000_SWFW_PHY2_SM;
745 else if (hw->bus.func == E1000_FUNC_3)
746 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800747
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000748 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800749}
750
751/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700752 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800753 * @hw: pointer to the HW structure
754 *
755 * A wrapper to release access rights to the correct PHY. This is a
756 * function pointer entry point called by the api module.
757 **/
758static void igb_release_phy_82575(struct e1000_hw *hw)
759{
Alexander Duyck008c3422009-10-05 06:32:07 +0000760 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800761
Alexander Duyck008c3422009-10-05 06:32:07 +0000762 if (hw->bus.func == E1000_FUNC_1)
763 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000764 else if (hw->bus.func == E1000_FUNC_2)
765 mask = E1000_SWFW_PHY2_SM;
766 else if (hw->bus.func == E1000_FUNC_3)
767 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000768
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000769 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800770}
771
772/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700773 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800774 * @hw: pointer to the HW structure
775 * @offset: register offset to be read
776 * @data: pointer to the read data
777 *
778 * Reads the PHY register at offset using the serial gigabit media independent
779 * interface and stores the retrieved information in data.
780 **/
781static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
782 u16 *data)
783{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000784 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800785
786 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700787 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000788 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800789 }
790
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000791 ret_val = hw->phy.ops.acquire(hw);
792 if (ret_val)
793 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800794
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000795 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800796
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000797 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800798
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000799out:
800 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800801}
802
803/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700804 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800805 * @hw: pointer to the HW structure
806 * @offset: register offset to write to
807 * @data: data to write at register offset
808 *
809 * Writes the data to PHY register at the offset using the serial gigabit
810 * media independent interface.
811 **/
812static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
813 u16 data)
814{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000815 s32 ret_val = -E1000_ERR_PARAM;
816
Auke Kok9d5c8242008-01-24 02:22:38 -0800817
818 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700819 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000820 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800821 }
822
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000823 ret_val = hw->phy.ops.acquire(hw);
824 if (ret_val)
825 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800826
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000827 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800828
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000829 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800830
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000831out:
832 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800833}
834
835/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700836 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800837 * @hw: pointer to the HW structure
838 *
Auke Kok652fff32008-06-27 11:00:18 -0700839 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800840 * sgmi interface.
841 **/
842static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
843{
844 struct e1000_phy_info *phy = &hw->phy;
845 s32 ret_val = 0;
846 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000847 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000848 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800849
Carolyn Wybornybb1d18d2013-09-10 11:57:16 -0700850 /* Extra read required for some PHY's on i354 */
851 if (hw->mac.type == e1000_i354)
852 igb_get_phy_id(hw);
853
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000854 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800855 * we find one that works. For non-SGMII PHYs
856 * (e.g. integrated copper PHYs), an address of 1 should
857 * work. The result of this function should mean phy->phy_addr
858 * and phy->id are set correctly.
859 */
860 if (!(igb_sgmii_active_82575(hw))) {
861 phy->addr = 1;
862 ret_val = igb_get_phy_id(hw);
863 goto out;
864 }
865
Nick Nunley4085f742010-07-26 13:15:06 +0000866 if (igb_sgmii_uses_mdio_82575(hw)) {
867 switch (hw->mac.type) {
868 case e1000_82575:
869 case e1000_82576:
870 mdic = rd32(E1000_MDIC);
871 mdic &= E1000_MDIC_PHY_MASK;
872 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
873 break;
874 case e1000_82580:
875 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000876 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000877 case e1000_i210:
878 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000879 mdic = rd32(E1000_MDICNFG);
880 mdic &= E1000_MDICNFG_PHY_MASK;
881 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
882 break;
883 default:
884 ret_val = -E1000_ERR_PHY;
885 goto out;
Nick Nunley4085f742010-07-26 13:15:06 +0000886 }
887 ret_val = igb_get_phy_id(hw);
888 goto out;
889 }
890
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000891 /* Power on sgmii phy if it is disabled */
892 ctrl_ext = rd32(E1000_CTRL_EXT);
893 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
894 wrfl();
895 msleep(300);
896
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000897 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800898 * Therefore, we need to test 1-7
899 */
900 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
901 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
902 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700903 hw_dbg("Vendor ID 0x%08X read at address %u\n",
904 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000905 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800906 * the only supported SGMII PHY product.
907 */
908 if (phy_id == M88_VENDOR)
909 break;
910 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700911 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800912 }
913 }
914
915 /* A valid PHY type couldn't be found. */
916 if (phy->addr == 8) {
917 phy->addr = 0;
918 ret_val = -E1000_ERR_PHY;
919 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000920 } else {
921 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800922 }
923
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000924 /* restore previous sfp cage power state */
925 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800926
927out:
928 return ret_val;
929}
930
931/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700932 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800933 * @hw: pointer to the HW structure
934 *
935 * Resets the PHY using the serial gigabit media independent interface.
936 **/
937static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
938{
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700939 struct e1000_phy_info *phy = &hw->phy;
Auke Kok9d5c8242008-01-24 02:22:38 -0800940 s32 ret_val;
941
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000942 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800943 * available to us at this time.
944 */
945
Auke Kok652fff32008-06-27 11:00:18 -0700946 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800947
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000948 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800949 * to work on SGMII. No further documentation is given.
950 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000951 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800952 if (ret_val)
953 goto out;
954
955 ret_val = igb_phy_sw_reset(hw);
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700956 if (ret_val)
957 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800958
Todd Fujinaka51045ec2015-07-29 07:32:06 -0700959 if (phy->id == M88E1512_E_PHY_ID)
960 ret_val = igb_initialize_M88E1512_phy(hw);
Todd Fujinaka18f7ce52015-09-02 16:54:20 -0700961 if (phy->id == M88E1543_E_PHY_ID)
962 ret_val = igb_initialize_M88E1543_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800963out:
964 return ret_val;
965}
966
967/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700968 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800969 * @hw: pointer to the HW structure
970 * @active: true to enable LPLU, false to disable
971 *
972 * Sets the LPLU D0 state according to the active flag. When
973 * activating LPLU this function also disables smart speed
974 * and vice versa. LPLU will not be activated unless the
975 * device autonegotiation advertisement meets standards of
976 * either 10 or 10/100 or 10/100/1000 at all duplexes.
977 * This is a function pointer entry point only called by
978 * PHY setup routines.
979 **/
980static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
981{
982 struct e1000_phy_info *phy = &hw->phy;
983 s32 ret_val;
984 u16 data;
985
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000986 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800987 if (ret_val)
988 goto out;
989
990 if (active) {
991 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000992 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700993 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800994 if (ret_val)
995 goto out;
996
997 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000998 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700999 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001001 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -07001002 data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001003 if (ret_val)
1004 goto out;
1005 } else {
1006 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001007 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -07001008 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001009 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 * during Dx states where the power conservation is most
1011 * important. During driver activity we should enable
1012 * SmartSpeed, so performance is maintained.
1013 */
1014 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001015 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001016 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001017 if (ret_val)
1018 goto out;
1019
1020 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001021 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001022 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001023 if (ret_val)
1024 goto out;
1025 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001026 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001027 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001028 if (ret_val)
1029 goto out;
1030
1031 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001032 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -07001033 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001034 if (ret_val)
1035 goto out;
1036 }
1037 }
1038
1039out:
1040 return ret_val;
1041}
1042
1043/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001044 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
1045 * @hw: pointer to the HW structure
1046 * @active: true to enable LPLU, false to disable
1047 *
1048 * Sets the LPLU D0 state according to the active flag. When
1049 * activating LPLU this function also disables smart speed
1050 * and vice versa. LPLU will not be activated unless the
1051 * device autonegotiation advertisement meets standards of
1052 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1053 * This is a function pointer entry point only called by
1054 * PHY setup routines.
1055 **/
1056static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
1057{
1058 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001059 u16 data;
1060
1061 data = rd32(E1000_82580_PHY_POWER_MGMT);
1062
1063 if (active) {
1064 data |= E1000_82580_PM_D0_LPLU;
1065
1066 /* When LPLU is enabled, we should disable SmartSpeed */
1067 data &= ~E1000_82580_PM_SPD;
1068 } else {
1069 data &= ~E1000_82580_PM_D0_LPLU;
1070
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001071 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001072 * during Dx states where the power conservation is most
1073 * important. During driver activity we should enable
1074 * SmartSpeed, so performance is maintained.
1075 */
1076 if (phy->smart_speed == e1000_smart_speed_on)
1077 data |= E1000_82580_PM_SPD;
1078 else if (phy->smart_speed == e1000_smart_speed_off)
1079 data &= ~E1000_82580_PM_SPD; }
1080
1081 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001082 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001083}
1084
1085/**
1086 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1087 * @hw: pointer to the HW structure
1088 * @active: boolean used to enable/disable lplu
1089 *
1090 * Success returns 0, Failure returns 1
1091 *
1092 * The low power link up (lplu) state is set to the power management level D3
1093 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1094 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1095 * is used during Dx states where the power conservation is most important.
1096 * During driver activity, SmartSpeed should be enabled so performance is
1097 * maintained.
1098 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +00001099static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001100{
1101 struct e1000_phy_info *phy = &hw->phy;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001102 u16 data;
1103
1104 data = rd32(E1000_82580_PHY_POWER_MGMT);
1105
1106 if (!active) {
1107 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001108 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001109 * during Dx states where the power conservation is most
1110 * important. During driver activity we should enable
1111 * SmartSpeed, so performance is maintained.
1112 */
1113 if (phy->smart_speed == e1000_smart_speed_on)
1114 data |= E1000_82580_PM_SPD;
1115 else if (phy->smart_speed == e1000_smart_speed_off)
1116 data &= ~E1000_82580_PM_SPD;
1117 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1118 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1119 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1120 data |= E1000_82580_PM_D3_LPLU;
1121 /* When LPLU is enabled, we should disable SmartSpeed */
1122 data &= ~E1000_82580_PM_SPD;
1123 }
1124
1125 wr32(E1000_82580_PHY_POWER_MGMT, data);
Todd Fujinaka23d87822014-06-04 07:12:15 +00001126 return 0;
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001127}
1128
1129/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001130 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001131 * @hw: pointer to the HW structure
1132 *
Auke Kok652fff32008-06-27 11:00:18 -07001133 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001134 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1135 * Return successful if access grant bit set, else clear the request for
1136 * EEPROM access and return -E1000_ERR_NVM (-1).
1137 **/
1138static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1139{
1140 s32 ret_val;
1141
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001142 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001143 if (ret_val)
1144 goto out;
1145
1146 ret_val = igb_acquire_nvm(hw);
1147
1148 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001149 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001150
1151out:
1152 return ret_val;
1153}
1154
1155/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001156 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001157 * @hw: pointer to the HW structure
1158 *
1159 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1160 * then release the semaphores acquired.
1161 **/
1162static void igb_release_nvm_82575(struct e1000_hw *hw)
1163{
1164 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001165 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001166}
1167
1168/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001169 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001170 * @hw: pointer to the HW structure
1171 * @mask: specifies which semaphore to acquire
1172 *
1173 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1174 * will also specify which port we're acquiring the lock for.
1175 **/
1176static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1177{
1178 u32 swfw_sync;
1179 u32 swmask = mask;
1180 u32 fwmask = mask << 16;
1181 s32 ret_val = 0;
Todd Fujinaka2184aa32014-11-27 01:00:02 +00001182 s32 i = 0, timeout = 200;
Auke Kok9d5c8242008-01-24 02:22:38 -08001183
1184 while (i < timeout) {
1185 if (igb_get_hw_semaphore(hw)) {
1186 ret_val = -E1000_ERR_SWFW_SYNC;
1187 goto out;
1188 }
1189
1190 swfw_sync = rd32(E1000_SW_FW_SYNC);
1191 if (!(swfw_sync & (fwmask | swmask)))
1192 break;
1193
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001194 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 * or other software thread using resource (swmask)
1196 */
1197 igb_put_hw_semaphore(hw);
1198 mdelay(5);
1199 i++;
1200 }
1201
1202 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001203 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001204 ret_val = -E1000_ERR_SWFW_SYNC;
1205 goto out;
1206 }
1207
1208 swfw_sync |= swmask;
1209 wr32(E1000_SW_FW_SYNC, swfw_sync);
1210
1211 igb_put_hw_semaphore(hw);
1212
1213out:
1214 return ret_val;
1215}
1216
1217/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001218 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001219 * @hw: pointer to the HW structure
1220 * @mask: specifies which semaphore to acquire
1221 *
1222 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1223 * will also specify which port we're releasing the lock for.
1224 **/
1225static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1226{
1227 u32 swfw_sync;
1228
Carolyn Wybornybed83e92014-04-11 01:45:55 +00001229 while (igb_get_hw_semaphore(hw) != 0)
1230 ; /* Empty */
Auke Kok9d5c8242008-01-24 02:22:38 -08001231
1232 swfw_sync = rd32(E1000_SW_FW_SYNC);
1233 swfw_sync &= ~mask;
1234 wr32(E1000_SW_FW_SYNC, swfw_sync);
1235
1236 igb_put_hw_semaphore(hw);
1237}
1238
1239/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001240 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001241 * @hw: pointer to the HW structure
1242 *
1243 * Read the management control register for the config done bit for
1244 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1245 * to read the config done bit, so an error is *ONLY* logged and returns
1246 * 0. If we were to return with error, EEPROM-less silicon
1247 * would not be able to be reset or change link.
1248 **/
1249static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1250{
1251 s32 timeout = PHY_CFG_TIMEOUT;
Auke Kok9d5c8242008-01-24 02:22:38 -08001252 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1253
1254 if (hw->bus.func == 1)
1255 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001256 else if (hw->bus.func == E1000_FUNC_2)
1257 mask = E1000_NVM_CFG_DONE_PORT_2;
1258 else if (hw->bus.func == E1000_FUNC_3)
1259 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001260
1261 while (timeout) {
1262 if (rd32(E1000_EEMNGCTL) & mask)
1263 break;
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001264 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001265 timeout--;
1266 }
1267 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001268 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001269
1270 /* If EEPROM is not marked present, init the PHY manually */
1271 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1272 (hw->phy.type == e1000_phy_igp_3))
1273 igb_phy_init_script_igp3(hw);
1274
Todd Fujinaka23d87822014-06-04 07:12:15 +00001275 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001276}
1277
1278/**
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00001279 * igb_get_link_up_info_82575 - Get link speed/duplex info
1280 * @hw: pointer to the HW structure
1281 * @speed: stores the current speed
1282 * @duplex: stores the current duplex
1283 *
1284 * This is a wrapper function, if using the serial gigabit media independent
1285 * interface, use PCS to retrieve the link speed and duplex information.
1286 * Otherwise, use the generic function to get the link speed and duplex info.
1287 **/
1288static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1289 u16 *duplex)
1290{
1291 s32 ret_val;
1292
1293 if (hw->phy.media_type != e1000_media_type_copper)
1294 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
1295 duplex);
1296 else
1297 ret_val = igb_get_speed_and_duplex_copper(hw, speed,
1298 duplex);
1299
1300 return ret_val;
1301}
1302
1303/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001304 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001305 * @hw: pointer to the HW structure
1306 *
1307 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1308 * use the generic interface for determining link.
1309 **/
1310static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1311{
1312 s32 ret_val;
1313 u16 speed, duplex;
1314
Alexander Duyck70d92f82009-10-05 06:31:47 +00001315 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001316 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001317 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001318 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001319 * not. If we have link clear the flag so that we do not
1320 * continue to check for link.
1321 */
1322 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001323
1324 /* Configure Flow Control now that Auto-Neg has completed.
1325 * First, we need to restore the desired flow control
1326 * settings because we may have had to re-autoneg with a
1327 * different link partner.
1328 */
1329 ret_val = igb_config_fc_after_link_up(hw);
1330 if (ret_val)
1331 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001332 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001333 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001334 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001335
1336 return ret_val;
1337}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001338
Auke Kok9d5c8242008-01-24 02:22:38 -08001339/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001340 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1341 * @hw: pointer to the HW structure
1342 **/
1343void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1344{
1345 u32 reg;
1346
1347
1348 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1349 !igb_sgmii_active_82575(hw))
1350 return;
1351
1352 /* Enable PCS to turn on link */
1353 reg = rd32(E1000_PCS_CFG0);
1354 reg |= E1000_PCS_CFG_PCS_EN;
1355 wr32(E1000_PCS_CFG0, reg);
1356
1357 /* Power up the laser */
1358 reg = rd32(E1000_CTRL_EXT);
1359 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1360 wr32(E1000_CTRL_EXT, reg);
1361
1362 /* flush the write to verify completion */
1363 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001364 usleep_range(1000, 2000);
Nick Nunley88a268c2010-02-17 01:01:59 +00001365}
1366
1367/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001368 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001369 * @hw: pointer to the HW structure
1370 * @speed: stores the current speed
1371 * @duplex: stores the current duplex
1372 *
Auke Kok652fff32008-06-27 11:00:18 -07001373 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001374 * duplex, then store the values in the pointers provided.
1375 **/
1376static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1377 u16 *duplex)
1378{
1379 struct e1000_mac_info *mac = &hw->mac;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001380 u32 pcs, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08001381
1382 /* Set up defaults for the return values of this function */
1383 mac->serdes_has_link = false;
1384 *speed = 0;
1385 *duplex = 0;
1386
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001387 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001388 * the status register is not accurate. The PCS status register is
1389 * used instead.
1390 */
1391 pcs = rd32(E1000_PCS_LSTAT);
1392
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001393 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001394 * gets set once both sides sync up and agree upon link. Stable link
1395 * can be determined by checking for both link up and link sync ok
1396 */
1397 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1398 mac->serdes_has_link = true;
1399
1400 /* Detect and store PCS speed */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001401 if (pcs & E1000_PCS_LSTS_SPEED_1000)
Auke Kok9d5c8242008-01-24 02:22:38 -08001402 *speed = SPEED_1000;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001403 else if (pcs & E1000_PCS_LSTS_SPEED_100)
Auke Kok9d5c8242008-01-24 02:22:38 -08001404 *speed = SPEED_100;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001405 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001406 *speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -08001407
1408 /* Detect and store PCS duplex */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001409 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
Auke Kok9d5c8242008-01-24 02:22:38 -08001410 *duplex = FULL_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001411 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001412 *duplex = HALF_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001413
1414 /* Check if it is an I354 2.5Gb backplane connection. */
1415 if (mac->type == e1000_i354) {
1416 status = rd32(E1000_STATUS);
1417 if ((status & E1000_STATUS_2P5_SKU) &&
1418 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1419 *speed = SPEED_2500;
1420 *duplex = FULL_DUPLEX;
1421 hw_dbg("2500 Mbs, ");
1422 hw_dbg("Full Duplex\n");
1423 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001424 }
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001425
Auke Kok9d5c8242008-01-24 02:22:38 -08001426 }
1427
1428 return 0;
1429}
1430
1431/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001432 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001433 * @hw: pointer to the HW structure
1434 *
1435 * In the case of fiber serdes, shut down optics and PCS on driver unload
1436 * when management pass thru is not enabled.
1437 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001438void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001439{
1440 u32 reg;
1441
Nick Nunley53c992f2010-02-17 01:01:40 +00001442 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001443 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001444 return;
1445
Nick Nunley53c992f2010-02-17 01:01:40 +00001446 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001447 /* Disable PCS to turn off link */
1448 reg = rd32(E1000_PCS_CFG0);
1449 reg &= ~E1000_PCS_CFG_PCS_EN;
1450 wr32(E1000_PCS_CFG0, reg);
1451
1452 /* shutdown the laser */
1453 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001454 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001455 wr32(E1000_CTRL_EXT, reg);
1456
1457 /* flush the write to verify completion */
1458 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001459 usleep_range(1000, 2000);
Alexander Duyck2d064c02008-07-08 15:10:12 -07001460 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001461}
1462
1463/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001464 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 * @hw: pointer to the HW structure
1466 *
1467 * This resets the hardware into a known state. This is a
1468 * function pointer entry point called by the api module.
1469 **/
1470static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1471{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001472 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001473 s32 ret_val;
1474
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001475 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001476 * on the last TLP read/write transaction when MAC is reset.
1477 */
1478 ret_val = igb_disable_pcie_master(hw);
1479 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001480 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001481
Alexander Duyck009bc062009-07-23 18:08:35 +00001482 /* set the completion timeout for interface */
1483 ret_val = igb_set_pcie_completion_timeout(hw);
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001484 if (ret_val)
Alexander Duyck009bc062009-07-23 18:08:35 +00001485 hw_dbg("PCI-E Set completion timeout has failed.\n");
Alexander Duyck009bc062009-07-23 18:08:35 +00001486
Auke Kok652fff32008-06-27 11:00:18 -07001487 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001488 wr32(E1000_IMC, 0xffffffff);
1489
1490 wr32(E1000_RCTL, 0);
1491 wr32(E1000_TCTL, E1000_TCTL_PSP);
1492 wrfl();
1493
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001494 usleep_range(10000, 20000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001495
1496 ctrl = rd32(E1000_CTRL);
1497
Auke Kok652fff32008-06-27 11:00:18 -07001498 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001499 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1500
1501 ret_val = igb_get_auto_rd_done(hw);
1502 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001503 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001504 * return with an error. This can happen in situations
1505 * where there is no eeprom and prevents getting link.
1506 */
Auke Kok652fff32008-06-27 11:00:18 -07001507 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001508 }
1509
1510 /* If EEPROM is not present, run manual init scripts */
1511 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1512 igb_reset_init_script_82575(hw);
1513
1514 /* Clear any pending interrupt events. */
1515 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001516 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001517
Alexander Duyck5ac16652009-07-23 18:09:12 +00001518 /* Install any alternate MAC address into RAR0 */
1519 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001520
1521 return ret_val;
1522}
1523
1524/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001525 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001526 * @hw: pointer to the HW structure
1527 *
1528 * This inits the hardware readying it for operation.
1529 **/
1530static s32 igb_init_hw_82575(struct e1000_hw *hw)
1531{
1532 struct e1000_mac_info *mac = &hw->mac;
1533 s32 ret_val;
1534 u16 i, rar_count = mac->rar_entry_count;
1535
Todd Fujinaka94826482014-07-10 01:47:15 -07001536 if ((hw->mac.type >= e1000_i210) &&
1537 !(igb_get_flash_presence_i210(hw))) {
1538 ret_val = igb_pll_workaround_i210(hw);
1539 if (ret_val)
1540 return ret_val;
1541 }
1542
Auke Kok9d5c8242008-01-24 02:22:38 -08001543 /* Initialize identification LED */
1544 ret_val = igb_id_led_init(hw);
1545 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001546 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001547 /* This is not fatal and we should not stop init due to this */
1548 }
1549
1550 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001551 hw_dbg("Initializing the IEEE VLAN\n");
Alexander Duyck832e8212016-01-06 23:10:30 -08001552 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001553
1554 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001555 igb_init_rx_addrs(hw, rar_count);
1556
Auke Kok9d5c8242008-01-24 02:22:38 -08001557 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001558 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001559 for (i = 0; i < mac->mta_reg_count; i++)
1560 array_wr32(E1000_MTA, i, 0);
1561
Alexander Duyck68d480c2009-10-05 06:33:08 +00001562 /* Zero out the Unicast HASH table */
1563 hw_dbg("Zeroing the UTA\n");
1564 for (i = 0; i < mac->uta_reg_count; i++)
1565 array_wr32(E1000_UTA, i, 0);
1566
Auke Kok9d5c8242008-01-24 02:22:38 -08001567 /* Setup link and flow control */
1568 ret_val = igb_setup_link(hw);
1569
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001570 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001571 * important that we do this after we have tried to establish link
1572 * because the symbol error count will increment wildly if there
1573 * is no link.
1574 */
1575 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001576 return ret_val;
1577}
1578
1579/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001580 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001581 * @hw: pointer to the HW structure
1582 *
1583 * Configures the link for auto-neg or forced speed and duplex. Then we check
1584 * for link, once link is established calls to configure collision distance
1585 * and flow control are called.
1586 **/
1587static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1588{
Alexander Duyck12645a12009-07-23 18:08:16 +00001589 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001590 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001591 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001592
1593 ctrl = rd32(E1000_CTRL);
1594 ctrl |= E1000_CTRL_SLU;
1595 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1596 wr32(E1000_CTRL, ctrl);
1597
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001598 /* Clear Go Link Disconnect bit on supported devices */
1599 switch (hw->mac.type) {
1600 case e1000_82580:
1601 case e1000_i350:
1602 case e1000_i210:
1603 case e1000_i211:
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001604 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1605 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1606 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001607 break;
1608 default:
1609 break;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001610 }
1611
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001612 ret_val = igb_setup_serdes_link_82575(hw);
1613 if (ret_val)
1614 goto out;
1615
1616 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001617 /* allow time for SFP cage time to power up phy */
1618 msleep(300);
1619
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001620 ret_val = hw->phy.ops.reset(hw);
1621 if (ret_val) {
1622 hw_dbg("Error resetting the PHY.\n");
1623 goto out;
1624 }
1625 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001626 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001627 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001628 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001629 switch (hw->phy.id) {
1630 case I347AT4_E_PHY_ID:
1631 case M88E1112_E_PHY_ID:
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001632 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001633 case M88E1512_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001634 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001635 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001636 break;
1637 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001638 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001639 break;
1640 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001641 break;
1642 case e1000_phy_igp_3:
1643 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001645 case e1000_phy_82580:
1646 ret_val = igb_copper_link_setup_82580(hw);
1647 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001648 default:
1649 ret_val = -E1000_ERR_PHY;
1650 break;
1651 }
1652
1653 if (ret_val)
1654 goto out;
1655
Alexander Duyck81fadd82009-10-05 06:35:03 +00001656 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001657out:
1658 return ret_val;
1659}
1660
1661/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001662 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001663 * @hw: pointer to the HW structure
1664 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001665 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1666 * used on copper connections where the serialized gigabit media independent
1667 * interface (sgmii), or serdes fiber is being used. Configures the link
1668 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001669 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001670static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001671{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001672 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001673 bool pcs_autoneg;
Todd Fujinaka23d87822014-06-04 07:12:15 +00001674 s32 ret_val = 0;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001675 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001676
1677 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1678 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001679 return ret_val;
1680
Auke Kok9d5c8242008-01-24 02:22:38 -08001681
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001682 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001683 * explicitly turned off or a power cycle is performed. A read to
1684 * the register does not indicate its status. Therefore, we ensure
1685 * loopback mode is disabled during initialization.
1686 */
1687 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1688
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001689 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001690 ctrl_ext = rd32(E1000_CTRL_EXT);
1691 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001692 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001693 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001694
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001695 ctrl_reg = rd32(E1000_CTRL);
1696 ctrl_reg |= E1000_CTRL_SLU;
1697
1698 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1699 /* set both sw defined pins */
1700 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1701
1702 /* Set switch control to serdes energy detect */
1703 reg = rd32(E1000_CONNSW);
1704 reg |= E1000_CONNSW_ENRGSRC;
1705 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001706 }
1707
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001708 reg = rd32(E1000_PCS_LCTL);
1709
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001710 /* default pcs_autoneg to the same setting as mac autoneg */
1711 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001712
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001713 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1714 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1715 /* sgmii mode lets the phy handle forcing speed/duplex */
1716 pcs_autoneg = true;
1717 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001718 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001719 break;
1720 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1721 /* disable PCS autoneg and support parallel detect only */
1722 pcs_autoneg = false;
1723 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001724 if (hw->mac.type == e1000_82575 ||
1725 hw->mac.type == e1000_82576) {
1726 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1727 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00001728 hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001729 return ret_val;
1730 }
1731
1732 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1733 pcs_autoneg = false;
1734 }
1735
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001736 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001737 * link so it is best to just force the MAC and let the pcs
1738 * link either autoneg or be forced to 1000/Full
1739 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001740 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001741 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001742
1743 /* set speed of 1000/Full if speed/duplex is forced */
1744 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1745 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001746 }
1747
1748 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001749
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001750 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001751 * at 1gb. Autoneg should be default set by most drivers. This is the
1752 * mode that will be compatible with older link partners and switches.
1753 * However, both are supported by the hardware and some drivers/tools.
1754 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001755 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1756 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1757
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001758 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001759 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001760 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001761 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001762
1763 /* Disable force flow control for autoneg */
1764 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1765
1766 /* Configure flow control advertisement for autoneg */
1767 anadv_reg = rd32(E1000_PCS_ANADV);
1768 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1769 switch (hw->fc.requested_mode) {
1770 case e1000_fc_full:
1771 case e1000_fc_rx_pause:
1772 anadv_reg |= E1000_TXCW_ASM_DIR;
1773 anadv_reg |= E1000_TXCW_PAUSE;
1774 break;
1775 case e1000_fc_tx_pause:
1776 anadv_reg |= E1000_TXCW_ASM_DIR;
1777 break;
1778 default:
1779 break;
1780 }
1781 wr32(E1000_PCS_ANADV, anadv_reg);
1782
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001783 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001784 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001785 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001786 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001787
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001788 /* Force flow control for forced link */
1789 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1790
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001791 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001792 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001793
Auke Kok9d5c8242008-01-24 02:22:38 -08001794 wr32(E1000_PCS_LCTL, reg);
1795
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001796 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001797 igb_force_mac_fc(hw);
1798
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001799 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001800}
1801
1802/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001803 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001804 * @hw: pointer to the HW structure
1805 *
1806 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1807 * which can be enabled for use in the embedded applications. Simply
1808 * return the current state of the sgmii interface.
1809 **/
1810static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1811{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001812 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001813 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001814}
1815
1816/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001817 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001818 * @hw: pointer to the HW structure
1819 *
1820 * Inits recommended HW defaults after a reset when there is no EEPROM
1821 * detected. This is only for the 82575.
1822 **/
1823static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1824{
1825 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001826 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001827 /* SerDes configuration via SERDESCTRL */
1828 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1829 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1830 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1831 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1832
1833 /* CCM configuration via CCMCTL register */
1834 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1835 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1836
1837 /* PCIe lanes configuration */
1838 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1839 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1840 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1841 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1842
1843 /* PCIe PLL Configuration */
1844 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1845 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1846 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1847 }
1848
1849 return 0;
1850}
1851
1852/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001853 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001854 * @hw: pointer to the HW structure
1855 **/
1856static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1857{
1858 s32 ret_val = 0;
1859
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001860 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001861 * so that it will override the Si installed default perm
1862 * address.
1863 */
1864 ret_val = igb_check_alt_mac_addr(hw);
1865 if (ret_val)
1866 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001867
Alexander Duyck22896632009-10-05 06:34:25 +00001868 ret_val = igb_read_mac_addr(hw);
1869
1870out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001871 return ret_val;
1872}
1873
1874/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001875 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1876 * @hw: pointer to the HW structure
1877 *
1878 * In the case of a PHY power down to save power, or to turn off link during a
1879 * driver unload, or wake on lan is not enabled, remove the link.
1880 **/
1881void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1882{
1883 /* If the management interface is not enabled, then power down */
1884 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1885 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001886}
1887
1888/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001889 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001890 * @hw: pointer to the HW structure
1891 *
1892 * Clears the hardware counters by reading the counter registers.
1893 **/
1894static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1895{
Auke Kok9d5c8242008-01-24 02:22:38 -08001896 igb_clear_hw_cntrs_base(hw);
1897
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001898 rd32(E1000_PRC64);
1899 rd32(E1000_PRC127);
1900 rd32(E1000_PRC255);
1901 rd32(E1000_PRC511);
1902 rd32(E1000_PRC1023);
1903 rd32(E1000_PRC1522);
1904 rd32(E1000_PTC64);
1905 rd32(E1000_PTC127);
1906 rd32(E1000_PTC255);
1907 rd32(E1000_PTC511);
1908 rd32(E1000_PTC1023);
1909 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001910
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001911 rd32(E1000_ALGNERRC);
1912 rd32(E1000_RXERRC);
1913 rd32(E1000_TNCRS);
1914 rd32(E1000_CEXTERR);
1915 rd32(E1000_TSCTC);
1916 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001917
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001918 rd32(E1000_MGTPRC);
1919 rd32(E1000_MGTPDC);
1920 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001921
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001922 rd32(E1000_IAC);
1923 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001924
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001925 rd32(E1000_ICRXPTC);
1926 rd32(E1000_ICRXATC);
1927 rd32(E1000_ICTXPTC);
1928 rd32(E1000_ICTXATC);
1929 rd32(E1000_ICTXQEC);
1930 rd32(E1000_ICTXQMTC);
1931 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001932
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001933 rd32(E1000_CBTMPC);
1934 rd32(E1000_HTDPMC);
1935 rd32(E1000_CBRMPC);
1936 rd32(E1000_RPTHC);
1937 rd32(E1000_HGPTC);
1938 rd32(E1000_HTCBDPC);
1939 rd32(E1000_HGORCL);
1940 rd32(E1000_HGORCH);
1941 rd32(E1000_HGOTCL);
1942 rd32(E1000_HGOTCH);
1943 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001944
1945 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001946 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1947 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001948 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001949}
1950
Alexander Duyck662d7202008-06-27 11:00:29 -07001951/**
1952 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1953 * @hw: pointer to the HW structure
1954 *
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001955 * After rx enable if manageability is enabled then there is likely some
1956 * bad data at the start of the fifo and possibly in the DMA fifo. This
Alexander Duyck662d7202008-06-27 11:00:29 -07001957 * function clears the fifos and flushes any packets that came in as rx was
1958 * being enabled.
1959 **/
1960void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1961{
1962 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1963 int i, ms_wait;
1964
Todd Fujinaka8d0a88a2015-04-17 11:24:38 -07001965 /* disable IPv6 options as per hardware errata */
1966 rfctl = rd32(E1000_RFCTL);
1967 rfctl |= E1000_RFCTL_IPV6_EX_DIS;
1968 wr32(E1000_RFCTL, rfctl);
1969
Alexander Duyck662d7202008-06-27 11:00:29 -07001970 if (hw->mac.type != e1000_82575 ||
1971 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1972 return;
1973
1974 /* Disable all RX queues */
1975 for (i = 0; i < 4; i++) {
1976 rxdctl[i] = rd32(E1000_RXDCTL(i));
1977 wr32(E1000_RXDCTL(i),
1978 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1979 }
1980 /* Poll all queues to verify they have shut down */
1981 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001982 usleep_range(1000, 2000);
Alexander Duyck662d7202008-06-27 11:00:29 -07001983 rx_enabled = 0;
1984 for (i = 0; i < 4; i++)
1985 rx_enabled |= rd32(E1000_RXDCTL(i));
1986 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1987 break;
1988 }
1989
1990 if (ms_wait == 10)
1991 hw_dbg("Queue disable timed out after 10ms\n");
1992
1993 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1994 * incoming packets are rejected. Set enable and wait 2ms so that
1995 * any packet that was coming in as RCTL.EN was set is flushed
1996 */
Alexander Duyck662d7202008-06-27 11:00:29 -07001997 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1998
1999 rlpml = rd32(E1000_RLPML);
2000 wr32(E1000_RLPML, 0);
2001
2002 rctl = rd32(E1000_RCTL);
2003 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
2004 temp_rctl |= E1000_RCTL_LPE;
2005
2006 wr32(E1000_RCTL, temp_rctl);
2007 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
2008 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002009 usleep_range(2000, 3000);
Alexander Duyck662d7202008-06-27 11:00:29 -07002010
2011 /* Enable RX queues that were previously enabled and restore our
2012 * previous state
2013 */
2014 for (i = 0; i < 4; i++)
2015 wr32(E1000_RXDCTL(i), rxdctl[i]);
2016 wr32(E1000_RCTL, rctl);
2017 wrfl();
2018
2019 wr32(E1000_RLPML, rlpml);
2020 wr32(E1000_RFCTL, rfctl);
2021
2022 /* Flush receive errors generated by workaround */
2023 rd32(E1000_ROC);
2024 rd32(E1000_RNBC);
2025 rd32(E1000_MPC);
2026}
2027
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002028/**
Alexander Duyck009bc062009-07-23 18:08:35 +00002029 * igb_set_pcie_completion_timeout - set pci-e completion timeout
2030 * @hw: pointer to the HW structure
2031 *
2032 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
2033 * however the hardware default for these parts is 500us to 1ms which is less
2034 * than the 10ms recommended by the pci-e spec. To address this we need to
2035 * increase the value to either 10ms to 200ms for capability version 1 config,
2036 * or 16ms to 55ms for version 2.
2037 **/
2038static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
2039{
2040 u32 gcr = rd32(E1000_GCR);
2041 s32 ret_val = 0;
2042 u16 pcie_devctl2;
2043
2044 /* only take action if timeout value is defaulted to 0 */
2045 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
2046 goto out;
2047
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002048 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00002049 * timeout of 10ms to 200ms through the GCR register
2050 */
2051 if (!(gcr & E1000_GCR_CAP_VER2)) {
2052 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
2053 goto out;
2054 }
2055
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002056 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00002057 * directly in order to set the completion timeout value for
2058 * 16ms to 55ms
2059 */
2060 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002061 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002062 if (ret_val)
2063 goto out;
2064
2065 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2066
2067 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00002068 &pcie_devctl2);
Alexander Duyck009bc062009-07-23 18:08:35 +00002069out:
2070 /* disable completion timeout resend */
2071 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2072
2073 wr32(E1000_GCR, gcr);
2074 return ret_val;
2075}
2076
2077/**
Greg Rose13800462010-11-06 02:08:26 +00002078 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2079 * @hw: pointer to the hardware struct
2080 * @enable: state to enter, either enabled or disabled
2081 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2082 *
2083 * enables/disables L2 switch anti-spoofing functionality.
2084 **/
2085void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2086{
Lior Levy22c12752013-03-12 15:49:32 +00002087 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00002088
2089 switch (hw->mac.type) {
2090 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00002091 reg_offset = E1000_DTXSWC;
2092 break;
Greg Rose13800462010-11-06 02:08:26 +00002093 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002094 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00002095 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00002096 break;
2097 default:
Lior Levy22c12752013-03-12 15:49:32 +00002098 return;
Greg Rose13800462010-11-06 02:08:26 +00002099 }
Lior Levy22c12752013-03-12 15:49:32 +00002100
2101 reg_val = rd32(reg_offset);
2102 if (enable) {
2103 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2104 E1000_DTXSWC_VLAN_SPOOF_MASK);
2105 /* The PF can spoof - it has to in order to
2106 * support emulation mode NICs
2107 */
2108 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2109 } else {
2110 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2111 E1000_DTXSWC_VLAN_SPOOF_MASK);
2112 }
2113 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00002114}
2115
2116/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002117 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2118 * @hw: pointer to the hardware struct
2119 * @enable: state to enter, either enabled or disabled
2120 *
2121 * enables/disables L2 switch loopback functionality.
2122 **/
2123void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2124{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002125 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002126
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002127 switch (hw->mac.type) {
2128 case e1000_82576:
2129 dtxswc = rd32(E1000_DTXSWC);
2130 if (enable)
2131 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2132 else
2133 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2134 wr32(E1000_DTXSWC, dtxswc);
2135 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002136 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002137 case e1000_i350:
2138 dtxswc = rd32(E1000_TXSWC);
2139 if (enable)
2140 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2141 else
2142 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2143 wr32(E1000_TXSWC, dtxswc);
2144 break;
2145 default:
2146 /* Currently no other hardware supports loopback */
2147 break;
2148 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002149
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002150}
2151
2152/**
2153 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2154 * @hw: pointer to the hardware struct
2155 * @enable: state to enter, either enabled or disabled
2156 *
2157 * enables/disables replication of packets across multiple pools.
2158 **/
2159void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2160{
2161 u32 vt_ctl = rd32(E1000_VT_CTL);
2162
2163 if (enable)
2164 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2165 else
2166 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2167
2168 wr32(E1000_VT_CTL, vt_ctl);
2169}
2170
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002171/**
2172 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2173 * @hw: pointer to the HW structure
2174 * @offset: register offset to be read
2175 * @data: pointer to the read data
2176 *
2177 * Reads the MDI control register in the PHY at offset and stores the
2178 * information read to data.
2179 **/
Aaron Sierra2a3cdea2015-11-03 12:37:09 -06002180s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002181{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002182 s32 ret_val;
2183
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002184 ret_val = hw->phy.ops.acquire(hw);
2185 if (ret_val)
2186 goto out;
2187
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002188 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2189
2190 hw->phy.ops.release(hw);
2191
2192out:
2193 return ret_val;
2194}
2195
2196/**
2197 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2198 * @hw: pointer to the HW structure
2199 * @offset: register offset to write to
2200 * @data: data to write to register at offset
2201 *
2202 * Writes data to MDI control register in the PHY at offset.
2203 **/
Aaron Sierra2a3cdea2015-11-03 12:37:09 -06002204s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002205{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002206 s32 ret_val;
2207
2208
2209 ret_val = hw->phy.ops.acquire(hw);
2210 if (ret_val)
2211 goto out;
2212
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002213 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2214
2215 hw->phy.ops.release(hw);
2216
2217out:
2218 return ret_val;
2219}
2220
2221/**
Nick Nunley08451e22010-07-26 13:15:29 +00002222 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2223 * @hw: pointer to the HW structure
2224 *
2225 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2226 * the values found in the EEPROM. This addresses an issue in which these
2227 * bits are not restored from EEPROM after reset.
2228 **/
2229static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2230{
2231 s32 ret_val = 0;
2232 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002233 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002234
2235 if (hw->mac.type != e1000_82580)
2236 goto out;
2237 if (!igb_sgmii_active_82575(hw))
2238 goto out;
2239
2240 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2241 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2242 &nvm_data);
2243 if (ret_val) {
2244 hw_dbg("NVM Read Error\n");
2245 goto out;
2246 }
2247
2248 mdicnfg = rd32(E1000_MDICNFG);
2249 if (nvm_data & NVM_WORD24_EXT_MDIO)
2250 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2251 if (nvm_data & NVM_WORD24_COM_MDIO)
2252 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2253 wr32(E1000_MDICNFG, mdicnfg);
2254out:
2255 return ret_val;
2256}
2257
2258/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002259 * igb_reset_hw_82580 - Reset hardware
2260 * @hw: pointer to the HW structure
2261 *
2262 * This resets function or entire device (all ports, etc.)
2263 * to a known state.
2264 **/
2265static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2266{
2267 s32 ret_val = 0;
2268 /* BH SW mailbox bit in SW_FW_SYNC */
2269 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002270 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002271 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2272
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002273 hw->dev_spec._82575.global_device_reset = false;
2274
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002275 /* due to hw errata, global device reset doesn't always
2276 * work on 82580
2277 */
2278 if (hw->mac.type == e1000_82580)
2279 global_device_reset = false;
2280
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002281 /* Get current control state. */
2282 ctrl = rd32(E1000_CTRL);
2283
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002284 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002285 * on the last TLP read/write transaction when MAC is reset.
2286 */
2287 ret_val = igb_disable_pcie_master(hw);
2288 if (ret_val)
2289 hw_dbg("PCI-E Master disable polling has failed.\n");
2290
2291 hw_dbg("Masking off all interrupts\n");
2292 wr32(E1000_IMC, 0xffffffff);
2293 wr32(E1000_RCTL, 0);
2294 wr32(E1000_TCTL, E1000_TCTL_PSP);
2295 wrfl();
2296
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002297 usleep_range(10000, 11000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002298
2299 /* Determine whether or not a global dev reset is requested */
2300 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002301 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002302 global_device_reset = false;
2303
2304 if (global_device_reset &&
2305 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2306 ctrl |= E1000_CTRL_DEV_RST;
2307 else
2308 ctrl |= E1000_CTRL_RST;
2309
2310 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002311 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002312
2313 /* Add delay to insure DEV_RST has time to complete */
2314 if (global_device_reset)
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002315 usleep_range(5000, 6000);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002316
2317 ret_val = igb_get_auto_rd_done(hw);
2318 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002319 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002320 * return with an error. This can happen in situations
2321 * where there is no eeprom and prevents getting link.
2322 */
2323 hw_dbg("Auto Read Done did not complete\n");
2324 }
2325
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002326 /* clear global device reset status bit */
2327 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2328
2329 /* Clear any pending interrupt events. */
2330 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002331 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002332
Nick Nunley08451e22010-07-26 13:15:29 +00002333 ret_val = igb_reset_mdicnfg_82580(hw);
2334 if (ret_val)
2335 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2336
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002337 /* Install any alternate MAC address into RAR0 */
2338 ret_val = igb_check_alt_mac_addr(hw);
2339
2340 /* Release semaphore */
2341 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002342 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002343
2344 return ret_val;
2345}
2346
2347/**
2348 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2349 * @data: data received by reading RXPBS register
2350 *
2351 * The 82580 uses a table based approach for packet buffer allocation sizes.
2352 * This function converts the retrieved value into the correct table value
2353 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2354 * 0x0 36 72 144 1 2 4 8 16
2355 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2356 */
2357u16 igb_rxpbs_adjust_82580(u32 data)
2358{
2359 u16 ret_val = 0;
2360
Todd Fujinaka72b36722014-03-04 02:25:22 +00002361 if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002362 ret_val = e1000_82580_rxpbs_table[data];
2363
2364 return ret_val;
2365}
2366
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002367/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002368 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2369 * checksum
2370 * @hw: pointer to the HW structure
2371 * @offset: offset in words of the checksum protected region
2372 *
2373 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2374 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2375 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002376static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2377 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002378{
2379 s32 ret_val = 0;
2380 u16 checksum = 0;
2381 u16 i, nvm_data;
2382
2383 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2384 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2385 if (ret_val) {
2386 hw_dbg("NVM Read Error\n");
2387 goto out;
2388 }
2389 checksum += nvm_data;
2390 }
2391
2392 if (checksum != (u16) NVM_SUM) {
2393 hw_dbg("NVM Checksum Invalid\n");
2394 ret_val = -E1000_ERR_NVM;
2395 goto out;
2396 }
2397
2398out:
2399 return ret_val;
2400}
2401
2402/**
2403 * igb_update_nvm_checksum_with_offset - Update EEPROM
2404 * checksum
2405 * @hw: pointer to the HW structure
2406 * @offset: offset in words of the checksum protected region
2407 *
2408 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2409 * up to the checksum. Then calculates the EEPROM checksum and writes the
2410 * value to the EEPROM.
2411 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002412static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002413{
2414 s32 ret_val;
2415 u16 checksum = 0;
2416 u16 i, nvm_data;
2417
2418 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2419 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2420 if (ret_val) {
2421 hw_dbg("NVM Read Error while updating checksum.\n");
2422 goto out;
2423 }
2424 checksum += nvm_data;
2425 }
2426 checksum = (u16) NVM_SUM - checksum;
2427 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2428 &checksum);
2429 if (ret_val)
2430 hw_dbg("NVM Write Error while updating checksum.\n");
2431
2432out:
2433 return ret_val;
2434}
2435
2436/**
2437 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2438 * @hw: pointer to the HW structure
2439 *
2440 * Calculates the EEPROM section checksum by reading/adding each word of
2441 * the EEPROM and then verifies that the sum of the EEPROM is
2442 * equal to 0xBABA.
2443 **/
2444static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2445{
2446 s32 ret_val = 0;
2447 u16 eeprom_regions_count = 1;
2448 u16 j, nvm_data;
2449 u16 nvm_offset;
2450
2451 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2452 if (ret_val) {
2453 hw_dbg("NVM Read Error\n");
2454 goto out;
2455 }
2456
2457 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002458 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002459 * for all 4 ports.
2460 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002461 eeprom_regions_count = 4;
2462 }
2463
2464 for (j = 0; j < eeprom_regions_count; j++) {
2465 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2466 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2467 nvm_offset);
2468 if (ret_val != 0)
2469 goto out;
2470 }
2471
2472out:
2473 return ret_val;
2474}
2475
2476/**
2477 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2478 * @hw: pointer to the HW structure
2479 *
2480 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2481 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2482 * checksum and writes the value to the EEPROM.
2483 **/
2484static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2485{
2486 s32 ret_val;
2487 u16 j, nvm_data;
2488 u16 nvm_offset;
2489
2490 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2491 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002492 hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002493 goto out;
2494 }
2495
2496 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2497 /* set compatibility bit to validate checksums appropriately */
2498 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2499 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2500 &nvm_data);
2501 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +00002502 hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002503 goto out;
2504 }
2505 }
2506
2507 for (j = 0; j < 4; j++) {
2508 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2509 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2510 if (ret_val)
2511 goto out;
2512 }
2513
2514out:
2515 return ret_val;
2516}
2517
2518/**
2519 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2520 * @hw: pointer to the HW structure
2521 *
2522 * Calculates the EEPROM section checksum by reading/adding each word of
2523 * the EEPROM and then verifies that the sum of the EEPROM is
2524 * equal to 0xBABA.
2525 **/
2526static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2527{
2528 s32 ret_val = 0;
2529 u16 j;
2530 u16 nvm_offset;
2531
2532 for (j = 0; j < 4; j++) {
2533 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2534 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2535 nvm_offset);
2536 if (ret_val != 0)
2537 goto out;
2538 }
2539
2540out:
2541 return ret_val;
2542}
2543
2544/**
2545 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2546 * @hw: pointer to the HW structure
2547 *
2548 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2549 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2550 * checksum and writes the value to the EEPROM.
2551 **/
2552static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2553{
2554 s32 ret_val = 0;
2555 u16 j;
2556 u16 nvm_offset;
2557
2558 for (j = 0; j < 4; j++) {
2559 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2560 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2561 if (ret_val != 0)
2562 goto out;
2563 }
2564
2565out:
2566 return ret_val;
2567}
Stefan Assmann34a03262011-04-05 04:27:05 +00002568
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002569/**
Matthew Vick87371b92013-02-21 03:32:52 +00002570 * __igb_access_emi_reg - Read/write EMI register
2571 * @hw: pointer to the HW structure
2572 * @addr: EMI address to program
2573 * @data: pointer to value to read/write from/to the EMI address
2574 * @read: boolean flag to indicate read or write
2575 **/
2576static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2577 u16 *data, bool read)
2578{
Todd Fujinaka23d87822014-06-04 07:12:15 +00002579 s32 ret_val = 0;
Matthew Vick87371b92013-02-21 03:32:52 +00002580
2581 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2582 if (ret_val)
2583 return ret_val;
2584
2585 if (read)
2586 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2587 else
2588 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2589
2590 return ret_val;
2591}
2592
2593/**
2594 * igb_read_emi_reg - Read Extended Management Interface register
2595 * @hw: pointer to the HW structure
2596 * @addr: EMI address to program
2597 * @data: value to be read from the EMI address
2598 **/
2599s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2600{
2601 return __igb_access_emi_reg(hw, addr, data, true);
2602}
2603
2604/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002605 * igb_set_eee_i350 - Enable/disable EEE support
2606 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002607 * @adv1G: boolean flag enabling 1G EEE advertisement
2608 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002609 *
2610 * Enable/disable EEE based on setting in dev_spec structure.
2611 *
2612 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002613s32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002614{
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002615 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002616
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002617 if ((hw->mac.type < e1000_i350) ||
2618 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002619 goto out;
2620 ipcnfg = rd32(E1000_IPCNFG);
2621 eeer = rd32(E1000_EEER);
2622
2623 /* enable or disable per user setting */
2624 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002625 u32 eee_su = rd32(E1000_EEE_SU);
2626
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002627 if (adv100M)
2628 ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
2629 else
2630 ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
2631
2632 if (adv1G)
2633 ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
2634 else
2635 ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
2636
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002637 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002638 E1000_EEER_LPI_FC);
2639
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002640 /* This bit should not be set in normal operation. */
2641 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2642 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2643
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002644 } else {
2645 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2646 E1000_IPCNFG_EEE_100M_AN);
2647 eeer &= ~(E1000_EEER_TX_LPI_EN |
2648 E1000_EEER_RX_LPI_EN |
2649 E1000_EEER_LPI_FC);
2650 }
2651 wr32(E1000_IPCNFG, ipcnfg);
2652 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002653 rd32(E1000_IPCNFG);
2654 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002655out:
2656
Todd Fujinaka23d87822014-06-04 07:12:15 +00002657 return 0;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002658}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002659
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002660/**
2661 * igb_set_eee_i354 - Enable/disable EEE support
2662 * @hw: pointer to the HW structure
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002663 * @adv1G: boolean flag enabling 1G EEE advertisement
2664 * @adv100m: boolean flag enabling 100M EEE advertisement
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002665 *
2666 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2667 *
2668 **/
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002669s32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002670{
2671 struct e1000_phy_info *phy = &hw->phy;
2672 s32 ret_val = 0;
2673 u16 phy_data;
2674
2675 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002676 ((phy->id != M88E1543_E_PHY_ID) &&
2677 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002678 goto out;
2679
2680 if (!hw->dev_spec._82575.eee_disable) {
2681 /* Switch to PHY page 18. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002682 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002683 if (ret_val)
2684 goto out;
2685
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002686 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002687 &phy_data);
2688 if (ret_val)
2689 goto out;
2690
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002691 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2692 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002693 phy_data);
2694 if (ret_val)
2695 goto out;
2696
2697 /* Return the PHY to page 0. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002698 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002699 if (ret_val)
2700 goto out;
2701
2702 /* Turn on EEE advertisement. */
2703 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2704 E1000_EEE_ADV_DEV_I354,
2705 &phy_data);
2706 if (ret_val)
2707 goto out;
2708
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002709 if (adv100M)
2710 phy_data |= E1000_EEE_ADV_100_SUPPORTED;
2711 else
2712 phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
2713
2714 if (adv1G)
2715 phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
2716 else
2717 phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
2718
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002719 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2720 E1000_EEE_ADV_DEV_I354,
2721 phy_data);
2722 } else {
2723 /* Turn off EEE advertisement. */
2724 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2725 E1000_EEE_ADV_DEV_I354,
2726 &phy_data);
2727 if (ret_val)
2728 goto out;
2729
2730 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2731 E1000_EEE_ADV_1000_SUPPORTED);
2732 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2733 E1000_EEE_ADV_DEV_I354,
2734 phy_data);
2735 }
2736
2737out:
2738 return ret_val;
2739}
2740
2741/**
2742 * igb_get_eee_status_i354 - Get EEE status
2743 * @hw: pointer to the HW structure
2744 * @status: EEE status
2745 *
2746 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2747 * been received.
2748 **/
2749s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2750{
2751 struct e1000_phy_info *phy = &hw->phy;
2752 s32 ret_val = 0;
2753 u16 phy_data;
2754
2755 /* Check if EEE is supported on this device. */
2756 if ((hw->phy.media_type != e1000_media_type_copper) ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002757 ((phy->id != M88E1543_E_PHY_ID) &&
2758 (phy->id != M88E1512_E_PHY_ID)))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002759 goto out;
2760
2761 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2762 E1000_PCS_STATUS_DEV_I354,
2763 &phy_data);
2764 if (ret_val)
2765 goto out;
2766
2767 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2768 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2769
2770out:
2771 return ret_val;
2772}
2773
Carolyn Wybornye4288932012-12-07 03:01:42 +00002774static const u8 e1000_emc_temp_data[4] = {
2775 E1000_EMC_INTERNAL_DATA,
2776 E1000_EMC_DIODE1_DATA,
2777 E1000_EMC_DIODE2_DATA,
2778 E1000_EMC_DIODE3_DATA
2779};
2780static const u8 e1000_emc_therm_limit[4] = {
2781 E1000_EMC_INTERNAL_THERM_LIMIT,
2782 E1000_EMC_DIODE1_THERM_LIMIT,
2783 E1000_EMC_DIODE2_THERM_LIMIT,
2784 E1000_EMC_DIODE3_THERM_LIMIT
2785};
2786
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002787#ifdef CONFIG_IGB_HWMON
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002788/**
2789 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002790 * @hw: pointer to hardware structure
2791 *
2792 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002793 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002794static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002795{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002796 u16 ets_offset;
2797 u16 ets_cfg;
2798 u16 ets_sensor;
2799 u8 num_sensors;
2800 u8 sensor_index;
2801 u8 sensor_location;
2802 u8 i;
2803 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2804
2805 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2806 return E1000_NOT_IMPLEMENTED;
2807
2808 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2809
2810 /* Return the internal sensor only if ETS is unsupported */
2811 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2812 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002813 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002814
2815 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2816 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2817 != NVM_ETS_TYPE_EMC)
2818 return E1000_NOT_IMPLEMENTED;
2819
2820 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2821 if (num_sensors > E1000_MAX_SENSORS)
2822 num_sensors = E1000_MAX_SENSORS;
2823
2824 for (i = 1; i < num_sensors; i++) {
2825 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2826 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2827 NVM_ETS_DATA_INDEX_SHIFT);
2828 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2829 NVM_ETS_DATA_LOC_SHIFT);
2830
2831 if (sensor_location != 0)
2832 hw->phy.ops.read_i2c_byte(hw,
2833 e1000_emc_temp_data[sensor_index],
2834 E1000_I2C_THERMAL_SENSOR_ADDR,
2835 &data->sensor[i].temp);
2836 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002837 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002838}
2839
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002840/**
2841 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002842 * @hw: pointer to hardware structure
2843 *
2844 * Sets the thermal sensor thresholds according to the NVM map
2845 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002846 **/
Jeff Kirsher167f3f72014-02-25 17:58:56 -08002847static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
Carolyn Wybornye4288932012-12-07 03:01:42 +00002848{
Carolyn Wybornye4288932012-12-07 03:01:42 +00002849 u16 ets_offset;
2850 u16 ets_cfg;
2851 u16 ets_sensor;
2852 u8 low_thresh_delta;
2853 u8 num_sensors;
2854 u8 sensor_index;
2855 u8 sensor_location;
2856 u8 therm_limit;
2857 u8 i;
2858 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2859
2860 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2861 return E1000_NOT_IMPLEMENTED;
2862
2863 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2864
2865 data->sensor[0].location = 0x1;
2866 data->sensor[0].caution_thresh =
2867 (rd32(E1000_THHIGHTC) & 0xFF);
2868 data->sensor[0].max_op_thresh =
2869 (rd32(E1000_THLOWTC) & 0xFF);
2870
2871 /* Return the internal sensor only if ETS is unsupported */
2872 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2873 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
Todd Fujinaka23d87822014-06-04 07:12:15 +00002874 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002875
2876 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2877 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2878 != NVM_ETS_TYPE_EMC)
2879 return E1000_NOT_IMPLEMENTED;
2880
2881 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2882 NVM_ETS_LTHRES_DELTA_SHIFT);
2883 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2884
2885 for (i = 1; i <= num_sensors; i++) {
2886 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2887 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2888 NVM_ETS_DATA_INDEX_SHIFT);
2889 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2890 NVM_ETS_DATA_LOC_SHIFT);
2891 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2892
2893 hw->phy.ops.write_i2c_byte(hw,
2894 e1000_emc_therm_limit[sensor_index],
2895 E1000_I2C_THERMAL_SENSOR_ADDR,
2896 therm_limit);
2897
2898 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2899 data->sensor[i].location = sensor_location;
2900 data->sensor[i].caution_thresh = therm_limit;
2901 data->sensor[i].max_op_thresh = therm_limit -
2902 low_thresh_delta;
2903 }
2904 }
Todd Fujinaka23d87822014-06-04 07:12:15 +00002905 return 0;
Carolyn Wybornye4288932012-12-07 03:01:42 +00002906}
2907
Jeff Kirsher9b143d12014-03-06 05:28:06 +00002908#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002909static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002910 .init_hw = igb_init_hw_82575,
2911 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002912 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002913 .read_mac_addr = igb_read_mac_addr_82575,
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00002914 .get_speed_and_duplex = igb_get_link_up_info_82575,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002915#ifdef CONFIG_IGB_HWMON
2916 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2917 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2918#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002919};
2920
2921static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002922 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002923 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002924 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002925 .write_i2c_byte = igb_write_i2c_byte,
2926 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002927};
2928
2929static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002930 .acquire = igb_acquire_nvm_82575,
2931 .read = igb_read_nvm_eerd,
2932 .release = igb_release_nvm_82575,
2933 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002934};
2935
2936const struct e1000_info e1000_82575_info = {
2937 .get_invariants = igb_get_invariants_82575,
2938 .mac_ops = &e1000_mac_ops_82575,
2939 .phy_ops = &e1000_phy_ops_82575,
2940 .nvm_ops = &e1000_nvm_ops_82575,
2941};
2942