blob: fe9db48f9084e0b1374de3d3d966c8317cce0ca2 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Akeem G. Abodunrin4b9ea462013-01-08 18:31:12 +00004 Copyright(c) 2007-2013 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28/* e1000_82575
29 * e1000_82576
30 */
31
Joe Perches82bbcde2011-10-21 20:04:09 +000032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Auke Kok9d5c8242008-01-24 02:22:38 -080034#include <linux/types.h>
Alexander Duyck2d064c02008-07-08 15:10:12 -070035#include <linux/if_ether.h>
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +000036#include <linux/i2c.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080037
38#include "e1000_mac.h"
39#include "e1000_82575.h"
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000040#include "e1000_i210.h"
Auke Kok9d5c8242008-01-24 02:22:38 -080041
42static s32 igb_get_invariants_82575(struct e1000_hw *);
43static s32 igb_acquire_phy_82575(struct e1000_hw *);
44static void igb_release_phy_82575(struct e1000_hw *);
45static s32 igb_acquire_nvm_82575(struct e1000_hw *);
46static void igb_release_nvm_82575(struct e1000_hw *);
47static s32 igb_check_for_link_82575(struct e1000_hw *);
48static s32 igb_get_cfg_done_82575(struct e1000_hw *);
49static s32 igb_init_hw_82575(struct e1000_hw *);
50static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
51static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000052static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
53static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080054static s32 igb_reset_hw_82575(struct e1000_hw *);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000055static s32 igb_reset_hw_82580(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080056static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
Carolyn Wybornyda02cde2012-03-04 03:26:26 +000057static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
58static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
Auke Kok9d5c8242008-01-24 02:22:38 -080059static s32 igb_setup_copper_link_82575(struct e1000_hw *);
Alexander Duyck2fb02a22009-09-14 08:22:54 +000060static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
Auke Kok9d5c8242008-01-24 02:22:38 -080061static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
62static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
63static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -080064static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
65 u16 *);
66static s32 igb_get_phy_id_82575(struct e1000_hw *);
67static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
68static bool igb_sgmii_active_82575(struct e1000_hw *);
69static s32 igb_reset_init_script_82575(struct e1000_hw *);
70static s32 igb_read_mac_addr_82575(struct e1000_hw *);
Alexander Duyck009bc062009-07-23 18:08:35 +000071static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
Alexander Duyck99870a72010-08-03 11:50:08 +000072static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080073static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
74static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
Carolyn Wyborny4322e562011-03-11 20:43:18 -080075static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
76static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
Alexander Duyckbb2ac472009-11-19 12:42:01 +000077static const u16 e1000_82580_rxpbs_table[] =
78 { 36, 72, 144, 1, 2, 4, 8, 16,
79 35, 70, 140 };
80#define E1000_82580_RXPBS_TABLE_SIZE \
81 (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
82
Nick Nunley4085f742010-07-26 13:15:06 +000083/**
84 * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
85 * @hw: pointer to the HW structure
86 *
87 * Called to determine if the I2C pins are being used for I2C or as an
88 * external MDIO interface since the two options are mutually exclusive.
89 **/
90static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
91{
92 u32 reg = 0;
93 bool ext_mdio = false;
94
95 switch (hw->mac.type) {
96 case e1000_82575:
97 case e1000_82576:
98 reg = rd32(E1000_MDIC);
99 ext_mdio = !!(reg & E1000_MDIC_DEST);
100 break;
101 case e1000_82580:
102 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000103 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000104 case e1000_i210:
105 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000106 reg = rd32(E1000_MDICNFG);
107 ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
108 break;
109 default:
110 break;
111 }
112 return ext_mdio;
113}
114
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000115/**
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000116 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
117 * @hw: pointer to the HW structure
118 *
119 * Poll the M88E1112 interfaces to see which interface achieved link.
120 */
121static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
122{
123 struct e1000_phy_info *phy = &hw->phy;
124 s32 ret_val;
125 u16 data;
126 u8 port = 0;
127
128 /* Check the copper medium. */
129 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
130 if (ret_val)
131 return ret_val;
132
133 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
134 if (ret_val)
135 return ret_val;
136
137 if (data & E1000_M88E1112_STATUS_LINK)
138 port = E1000_MEDIA_PORT_COPPER;
139
140 /* Check the other medium. */
141 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
142 if (ret_val)
143 return ret_val;
144
145 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
146 if (ret_val)
147 return ret_val;
148
149 /* reset page to 0 */
150 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
151 if (ret_val)
152 return ret_val;
153
154 if (data & E1000_M88E1112_STATUS_LINK)
155 port = E1000_MEDIA_PORT_OTHER;
156
157 /* Determine if a swap needs to happen. */
158 if (port && (hw->dev_spec._82575.media_port != port)) {
159 hw->dev_spec._82575.media_port = port;
160 hw->dev_spec._82575.media_changed = true;
161 } else {
162 ret_val = igb_check_for_link_82575(hw);
163 }
164
165 return E1000_SUCCESS;
166}
167
168/**
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000169 * igb_init_phy_params_82575 - Init PHY func ptrs.
170 * @hw: pointer to the HW structure
171 **/
172static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
173{
174 struct e1000_phy_info *phy = &hw->phy;
175 s32 ret_val = 0;
176 u32 ctrl_ext;
177
178 if (hw->phy.media_type != e1000_media_type_copper) {
179 phy->type = e1000_phy_none;
180 goto out;
181 }
182
183 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
184 phy->reset_delay_us = 100;
185
186 ctrl_ext = rd32(E1000_CTRL_EXT);
187
188 if (igb_sgmii_active_82575(hw)) {
189 phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
190 ctrl_ext |= E1000_CTRL_I2C_ENA;
191 } else {
192 phy->ops.reset = igb_phy_hw_reset;
193 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
194 }
195
196 wr32(E1000_CTRL_EXT, ctrl_ext);
197 igb_reset_mdicnfg_82580(hw);
198
199 if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
200 phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
201 phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
202 } else {
203 switch (hw->mac.type) {
204 case e1000_82580:
205 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000206 case e1000_i354:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000207 phy->ops.read_reg = igb_read_phy_reg_82580;
208 phy->ops.write_reg = igb_write_phy_reg_82580;
209 break;
210 case e1000_i210:
211 case e1000_i211:
212 phy->ops.read_reg = igb_read_phy_reg_gs40g;
213 phy->ops.write_reg = igb_write_phy_reg_gs40g;
214 break;
215 default:
216 phy->ops.read_reg = igb_read_phy_reg_igp;
217 phy->ops.write_reg = igb_write_phy_reg_igp;
218 }
219 }
220
221 /* set lan id */
222 hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
223 E1000_STATUS_FUNC_SHIFT;
224
225 /* Set phy->phy_addr and phy->id. */
226 ret_val = igb_get_phy_id_82575(hw);
227 if (ret_val)
228 return ret_val;
229
230 /* Verify phy id and set remaining function pointers */
231 switch (phy->id) {
Akeem G Abodunrin99af4722013-08-28 02:22:58 +0000232 case M88E1543_E_PHY_ID:
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000233 case I347AT4_E_PHY_ID:
234 case M88E1112_E_PHY_ID:
235 case M88E1111_I_PHY_ID:
236 phy->type = e1000_phy_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000237 phy->ops.check_polarity = igb_check_polarity_m88;
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000238 phy->ops.get_phy_info = igb_get_phy_info_m88;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000239 if (phy->id != M88E1111_I_PHY_ID)
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000240 phy->ops.get_cable_length =
241 igb_get_cable_length_m88_gen2;
242 else
243 phy->ops.get_cable_length = igb_get_cable_length_m88;
244 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
Carolyn Wyborny2bdfc4e2013-10-17 05:23:01 +0000245 /* Check if this PHY is confgured for media swap. */
246 if (phy->id == M88E1112_E_PHY_ID) {
247 u16 data;
248
249 ret_val = phy->ops.write_reg(hw,
250 E1000_M88E1112_PAGE_ADDR,
251 2);
252 if (ret_val)
253 goto out;
254
255 ret_val = phy->ops.read_reg(hw,
256 E1000_M88E1112_MAC_CTRL_1,
257 &data);
258 if (ret_val)
259 goto out;
260
261 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
262 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
263 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
264 data == E1000_M88E1112_AUTO_COPPER_BASEX)
265 hw->mac.ops.check_for_link =
266 igb_check_for_link_media_swap;
267 }
Akeem G. Abodunrin73bfcd92013-01-29 10:14:55 +0000268 break;
269 case IGP03E1000_E_PHY_ID:
270 phy->type = e1000_phy_igp_3;
271 phy->ops.get_phy_info = igb_get_phy_info_igp;
272 phy->ops.get_cable_length = igb_get_cable_length_igp_2;
273 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
274 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
275 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
276 break;
277 case I82580_I_PHY_ID:
278 case I350_I_PHY_ID:
279 phy->type = e1000_phy_82580;
280 phy->ops.force_speed_duplex =
281 igb_phy_force_speed_duplex_82580;
282 phy->ops.get_cable_length = igb_get_cable_length_82580;
283 phy->ops.get_phy_info = igb_get_phy_info_82580;
284 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
285 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
286 break;
287 case I210_I_PHY_ID:
288 phy->type = e1000_phy_i210;
289 phy->ops.check_polarity = igb_check_polarity_m88;
290 phy->ops.get_phy_info = igb_get_phy_info_m88;
291 phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
292 phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
293 phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
294 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
295 break;
296 default:
297 ret_val = -E1000_ERR_PHY;
298 goto out;
299 }
300
301out:
302 return ret_val;
303}
304
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000305/**
306 * igb_init_nvm_params_82575 - Init NVM func ptrs.
307 * @hw: pointer to the HW structure
308 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +0000309static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000310{
311 struct e1000_nvm_info *nvm = &hw->nvm;
312 u32 eecd = rd32(E1000_EECD);
313 u16 size;
314
315 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
316 E1000_EECD_SIZE_EX_SHIFT);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000317
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000318 /* Added to a constant, "size" becomes the left-shift value
319 * for setting word_size.
320 */
321 size += NVM_WORD_SIZE_BASE_SHIFT;
322
323 /* Just in case size is out of range, cap it to the largest
324 * EEPROM size supported
325 */
326 if (size > 15)
327 size = 15;
328
329 nvm->word_size = 1 << size;
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000330 nvm->opcode_bits = 8;
331 nvm->delay_usec = 1;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000332
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000333 switch (nvm->override) {
334 case e1000_nvm_override_spi_large:
335 nvm->page_size = 32;
336 nvm->address_bits = 16;
337 break;
338 case e1000_nvm_override_spi_small:
339 nvm->page_size = 8;
340 nvm->address_bits = 8;
341 break;
342 default:
343 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
344 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
345 16 : 8;
346 break;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000347 }
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000348 if (nvm->word_size == (1 << 15))
349 nvm->page_size = 128;
350
351 nvm->type = e1000_nvm_eeprom_spi;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000352
353 /* NVM Function Pointers */
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000354 nvm->ops.acquire = igb_acquire_nvm_82575;
355 nvm->ops.release = igb_release_nvm_82575;
356 nvm->ops.write = igb_write_nvm_spi;
357 nvm->ops.validate = igb_validate_nvm_checksum;
358 nvm->ops.update = igb_update_nvm_checksum;
359 if (nvm->word_size < (1 << 15))
360 nvm->ops.read = igb_read_nvm_eerd;
361 else
362 nvm->ops.read = igb_read_nvm_spi;
363
364 /* override generic family function pointers for specific descendants */
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000365 switch (hw->mac.type) {
366 case e1000_82580:
367 nvm->ops.validate = igb_validate_nvm_checksum_82580;
368 nvm->ops.update = igb_update_nvm_checksum_82580;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000369 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000370 case e1000_i354:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000371 case e1000_i350:
372 nvm->ops.validate = igb_validate_nvm_checksum_i350;
373 nvm->ops.update = igb_update_nvm_checksum_i350;
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000374 break;
375 default:
Akeem G. Abodunrin56d8c272013-01-29 10:15:00 +0000376 break;
377 }
378
379 return 0;
380}
381
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000382/**
383 * igb_init_mac_params_82575 - Init MAC func ptrs.
384 * @hw: pointer to the HW structure
385 **/
386static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
387{
388 struct e1000_mac_info *mac = &hw->mac;
389 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
390
391 /* Set mta register count */
392 mac->mta_reg_count = 128;
393 /* Set rar entry count */
394 switch (mac->type) {
395 case e1000_82576:
396 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
397 break;
398 case e1000_82580:
399 mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
400 break;
401 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000402 case e1000_i354:
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000403 mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
404 break;
405 default:
406 mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
407 break;
408 }
409 /* reset */
410 if (mac->type >= e1000_82580)
411 mac->ops.reset_hw = igb_reset_hw_82580;
412 else
413 mac->ops.reset_hw = igb_reset_hw_82575;
414
415 if (mac->type >= e1000_i210) {
416 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
417 mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
418
419 } else {
420 mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
421 mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
422 }
423
424 /* Set if part includes ASF firmware */
425 mac->asf_firmware_present = true;
426 /* Set if manageability features are enabled. */
427 mac->arc_subsystem_valid =
428 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
429 ? true : false;
430 /* enable EEE on i350 parts and later parts */
431 if (mac->type >= e1000_i350)
432 dev_spec->eee_disable = false;
433 else
434 dev_spec->eee_disable = true;
Matthew Vickd44e7a92013-03-22 07:34:20 +0000435 /* Allow a single clear of the SW semaphore on I210 and newer */
436 if (mac->type >= e1000_i210)
437 dev_spec->clear_semaphore_once = true;
Akeem G. Abodunrina1bf1f42013-01-29 10:15:05 +0000438 /* physical interface link setup */
439 mac->ops.setup_physical_interface =
440 (hw->phy.media_type == e1000_media_type_copper)
441 ? igb_setup_copper_link_82575
442 : igb_setup_serdes_link_82575;
443
444 return 0;
445}
446
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000447/**
448 * igb_set_sfp_media_type_82575 - derives SFP module media type.
449 * @hw: pointer to the HW structure
450 *
451 * The media type is chosen based on SFP module.
452 * compatibility flags retrieved from SFP ID EEPROM.
453 **/
454static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
455{
456 s32 ret_val = E1000_ERR_CONFIG;
457 u32 ctrl_ext = 0;
458 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
459 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
460 u8 tranceiver_type = 0;
461 s32 timeout = 3;
462
463 /* Turn I2C interface ON and power on sfp cage */
464 ctrl_ext = rd32(E1000_CTRL_EXT);
465 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
466 wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
467
468 wrfl();
469
470 /* Read SFP module data */
471 while (timeout) {
472 ret_val = igb_read_sfp_data_byte(hw,
473 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
474 &tranceiver_type);
475 if (ret_val == 0)
476 break;
477 msleep(100);
478 timeout--;
479 }
480 if (ret_val != 0)
481 goto out;
482
483 ret_val = igb_read_sfp_data_byte(hw,
484 E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
485 (u8 *)eth_flags);
486 if (ret_val != 0)
487 goto out;
488
489 /* Check if there is some SFP module plugged and powered */
490 if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
491 (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
492 dev_spec->module_plugged = true;
493 if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
494 hw->phy.media_type = e1000_media_type_internal_serdes;
495 } else if (eth_flags->e100_base_fx) {
496 dev_spec->sgmii_active = true;
497 hw->phy.media_type = e1000_media_type_internal_serdes;
498 } else if (eth_flags->e1000_base_t) {
499 dev_spec->sgmii_active = true;
500 hw->phy.media_type = e1000_media_type_copper;
501 } else {
502 hw->phy.media_type = e1000_media_type_unknown;
503 hw_dbg("PHY module has not been recognized\n");
504 goto out;
505 }
506 } else {
507 hw->phy.media_type = e1000_media_type_unknown;
508 }
509 ret_val = 0;
510out:
511 /* Restore I2C interface setting */
512 wr32(E1000_CTRL_EXT, ctrl_ext);
513 return ret_val;
514}
515
Auke Kok9d5c8242008-01-24 02:22:38 -0800516static s32 igb_get_invariants_82575(struct e1000_hw *hw)
517{
Auke Kok9d5c8242008-01-24 02:22:38 -0800518 struct e1000_mac_info *mac = &hw->mac;
Alexander Duyckc1889bf2009-02-06 23:16:45 +0000519 struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
Auke Kok9d5c8242008-01-24 02:22:38 -0800520 s32 ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800521 u32 ctrl_ext = 0;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000522 u32 link_mode = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800523
524 switch (hw->device_id) {
525 case E1000_DEV_ID_82575EB_COPPER:
526 case E1000_DEV_ID_82575EB_FIBER_SERDES:
527 case E1000_DEV_ID_82575GB_QUAD_COPPER:
528 mac->type = e1000_82575;
529 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700530 case E1000_DEV_ID_82576:
Alexander Duyck9eb23412009-03-13 20:42:15 +0000531 case E1000_DEV_ID_82576_NS:
Alexander Duyck747d49b2009-10-05 06:33:27 +0000532 case E1000_DEV_ID_82576_NS_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700533 case E1000_DEV_ID_82576_FIBER:
534 case E1000_DEV_ID_82576_SERDES:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000535 case E1000_DEV_ID_82576_QUAD_COPPER:
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000536 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyck4703bf72009-07-23 18:09:48 +0000537 case E1000_DEV_ID_82576_SERDES_QUAD:
Alexander Duyck2d064c02008-07-08 15:10:12 -0700538 mac->type = e1000_82576;
539 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000540 case E1000_DEV_ID_82580_COPPER:
541 case E1000_DEV_ID_82580_FIBER:
Carolyn Wyborny6493d242011-01-14 05:33:46 +0000542 case E1000_DEV_ID_82580_QUAD_FIBER:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000543 case E1000_DEV_ID_82580_SERDES:
544 case E1000_DEV_ID_82580_SGMII:
545 case E1000_DEV_ID_82580_COPPER_DUAL:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000546 case E1000_DEV_ID_DH89XXCC_SGMII:
547 case E1000_DEV_ID_DH89XXCC_SERDES:
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +0000548 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
549 case E1000_DEV_ID_DH89XXCC_SFP:
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000550 mac->type = e1000_82580;
551 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000552 case E1000_DEV_ID_I350_COPPER:
553 case E1000_DEV_ID_I350_FIBER:
554 case E1000_DEV_ID_I350_SERDES:
555 case E1000_DEV_ID_I350_SGMII:
556 mac->type = e1000_i350;
557 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000558 case E1000_DEV_ID_I210_COPPER:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000559 case E1000_DEV_ID_I210_FIBER:
560 case E1000_DEV_ID_I210_SERDES:
561 case E1000_DEV_ID_I210_SGMII:
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +0000562 case E1000_DEV_ID_I210_COPPER_FLASHLESS:
563 case E1000_DEV_ID_I210_SERDES_FLASHLESS:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000564 mac->type = e1000_i210;
565 break;
566 case E1000_DEV_ID_I211_COPPER:
567 mac->type = e1000_i211;
568 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000569 case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
570 case E1000_DEV_ID_I354_SGMII:
571 case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
572 mac->type = e1000_i354;
573 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800574 default:
575 return -E1000_ERR_MAC_INIT;
576 break;
577 }
578
Auke Kok9d5c8242008-01-24 02:22:38 -0800579 /* Set media type */
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000580 /* The 82575 uses bits 22:23 for link mode. The mode can be changed
Auke Kok9d5c8242008-01-24 02:22:38 -0800581 * based on the EEPROM. We cannot rely upon device ID. There
582 * is no distinguishable difference between fiber and internal
583 * SerDes mode on the 82575. There can be an external PHY attached
584 * on the SGMII interface. For this, we'll set sgmii_active to true.
585 */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000586 hw->phy.media_type = e1000_media_type_copper;
Auke Kok9d5c8242008-01-24 02:22:38 -0800587 dev_spec->sgmii_active = false;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000588 dev_spec->module_plugged = false;
Auke Kok9d5c8242008-01-24 02:22:38 -0800589
590 ctrl_ext = rd32(E1000_CTRL_EXT);
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000591
592 link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
593 switch (link_mode) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000594 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000595 hw->phy.media_type = e1000_media_type_internal_serdes;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000596 break;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000597 case E1000_CTRL_EXT_LINK_MODE_SGMII:
598 /* Get phy control interface type set (MDIO vs. I2C)*/
599 if (igb_sgmii_uses_mdio_82575(hw)) {
600 hw->phy.media_type = e1000_media_type_copper;
601 dev_spec->sgmii_active = true;
602 break;
603 }
604 /* fall through for I2C based SGMII */
605 case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
606 /* read media type from SFP EEPROM */
607 ret_val = igb_set_sfp_media_type_82575(hw);
608 if ((ret_val != 0) ||
609 (hw->phy.media_type == e1000_media_type_unknown)) {
610 /* If media type was not identified then return media
611 * type defined by the CTRL_EXT settings.
612 */
613 hw->phy.media_type = e1000_media_type_internal_serdes;
614
615 if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
616 hw->phy.media_type = e1000_media_type_copper;
617 dev_spec->sgmii_active = true;
618 }
619
620 break;
621 }
622
623 /* do not change link mode for 100BaseFX */
624 if (dev_spec->eth_flags.e100_base_fx)
625 break;
626
627 /* change current link mode setting */
628 ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
629
630 if (hw->phy.media_type == e1000_media_type_copper)
631 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
632 else
633 ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
634
635 wr32(E1000_CTRL_EXT, ctrl_ext);
636
637 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000638 default:
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000639 break;
Auke Kok9d5c8242008-01-24 02:22:38 -0800640 }
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000641
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000642 /* mac initialization and operations */
643 ret_val = igb_init_mac_params_82575(hw);
644 if (ret_val)
645 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800646
647 /* NVM initialization */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000648 ret_val = igb_init_nvm_params_82575(hw);
Carolyn Wyborny5a823d82013-07-16 19:17:32 +0000649 switch (hw->mac.type) {
650 case e1000_i210:
651 case e1000_i211:
652 ret_val = igb_init_nvm_params_i210(hw);
653 break;
654 default:
655 break;
656 }
657
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000658 if (ret_val)
659 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800660
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000661 /* if part supports SR-IOV then initialize mailbox parameters */
662 switch (mac->type) {
663 case e1000_82576:
664 case e1000_i350:
Alexander Duycka0c98602009-07-23 18:10:43 +0000665 igb_init_mbx_params_pf(hw);
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +0000666 break;
667 default:
668 break;
669 }
Alexander Duycka0c98602009-07-23 18:10:43 +0000670
Auke Kok9d5c8242008-01-24 02:22:38 -0800671 /* setup PHY parameters */
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000672 ret_val = igb_init_phy_params_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800673
Akeem G. Abodunrina6053d72013-01-29 10:15:10 +0000674out:
675 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800676}
677
678/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700679 * igb_acquire_phy_82575 - Acquire rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800680 * @hw: pointer to the HW structure
681 *
682 * Acquire access rights to the correct PHY. This is a
683 * function pointer entry point called by the api module.
684 **/
685static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
686{
Alexander Duyck008c3422009-10-05 06:32:07 +0000687 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800688
Alexander Duyck008c3422009-10-05 06:32:07 +0000689 if (hw->bus.func == E1000_FUNC_1)
690 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000691 else if (hw->bus.func == E1000_FUNC_2)
692 mask = E1000_SWFW_PHY2_SM;
693 else if (hw->bus.func == E1000_FUNC_3)
694 mask = E1000_SWFW_PHY3_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800695
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000696 return hw->mac.ops.acquire_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800697}
698
699/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700700 * igb_release_phy_82575 - Release rights to access PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800701 * @hw: pointer to the HW structure
702 *
703 * A wrapper to release access rights to the correct PHY. This is a
704 * function pointer entry point called by the api module.
705 **/
706static void igb_release_phy_82575(struct e1000_hw *hw)
707{
Alexander Duyck008c3422009-10-05 06:32:07 +0000708 u16 mask = E1000_SWFW_PHY0_SM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800709
Alexander Duyck008c3422009-10-05 06:32:07 +0000710 if (hw->bus.func == E1000_FUNC_1)
711 mask = E1000_SWFW_PHY1_SM;
Nick Nunleyede3ef02010-07-01 13:37:54 +0000712 else if (hw->bus.func == E1000_FUNC_2)
713 mask = E1000_SWFW_PHY2_SM;
714 else if (hw->bus.func == E1000_FUNC_3)
715 mask = E1000_SWFW_PHY3_SM;
Alexander Duyck008c3422009-10-05 06:32:07 +0000716
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000717 hw->mac.ops.release_swfw_sync(hw, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800718}
719
720/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700721 * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800722 * @hw: pointer to the HW structure
723 * @offset: register offset to be read
724 * @data: pointer to the read data
725 *
726 * Reads the PHY register at offset using the serial gigabit media independent
727 * interface and stores the retrieved information in data.
728 **/
729static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
730 u16 *data)
731{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000732 s32 ret_val = -E1000_ERR_PARAM;
Auke Kok9d5c8242008-01-24 02:22:38 -0800733
734 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700735 hw_dbg("PHY Address %u is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000736 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800737 }
738
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000739 ret_val = hw->phy.ops.acquire(hw);
740 if (ret_val)
741 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800742
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000743 ret_val = igb_read_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800744
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000745 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800746
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000747out:
748 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800749}
750
751/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700752 * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
Auke Kok9d5c8242008-01-24 02:22:38 -0800753 * @hw: pointer to the HW structure
754 * @offset: register offset to write to
755 * @data: data to write at register offset
756 *
757 * Writes the data to PHY register at the offset using the serial gigabit
758 * media independent interface.
759 **/
760static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
761 u16 data)
762{
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000763 s32 ret_val = -E1000_ERR_PARAM;
764
Auke Kok9d5c8242008-01-24 02:22:38 -0800765
766 if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
Auke Kok652fff32008-06-27 11:00:18 -0700767 hw_dbg("PHY Address %d is out of range\n", offset);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000768 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800769 }
770
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000771 ret_val = hw->phy.ops.acquire(hw);
772 if (ret_val)
773 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800774
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000775 ret_val = igb_write_phy_reg_i2c(hw, offset, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800776
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000777 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800778
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000779out:
780 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -0800781}
782
783/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700784 * igb_get_phy_id_82575 - Retrieve PHY addr and id
Auke Kok9d5c8242008-01-24 02:22:38 -0800785 * @hw: pointer to the HW structure
786 *
Auke Kok652fff32008-06-27 11:00:18 -0700787 * Retrieves the PHY address and ID for both PHY's which do and do not use
Auke Kok9d5c8242008-01-24 02:22:38 -0800788 * sgmi interface.
789 **/
790static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
791{
792 struct e1000_phy_info *phy = &hw->phy;
793 s32 ret_val = 0;
794 u16 phy_id;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000795 u32 ctrl_ext;
Nick Nunley4085f742010-07-26 13:15:06 +0000796 u32 mdic;
Auke Kok9d5c8242008-01-24 02:22:38 -0800797
Carolyn Wybornybb1d18d2013-09-10 11:57:16 -0700798 /* Extra read required for some PHY's on i354 */
799 if (hw->mac.type == e1000_i354)
800 igb_get_phy_id(hw);
801
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000802 /* For SGMII PHYs, we try the list of possible addresses until
Auke Kok9d5c8242008-01-24 02:22:38 -0800803 * we find one that works. For non-SGMII PHYs
804 * (e.g. integrated copper PHYs), an address of 1 should
805 * work. The result of this function should mean phy->phy_addr
806 * and phy->id are set correctly.
807 */
808 if (!(igb_sgmii_active_82575(hw))) {
809 phy->addr = 1;
810 ret_val = igb_get_phy_id(hw);
811 goto out;
812 }
813
Nick Nunley4085f742010-07-26 13:15:06 +0000814 if (igb_sgmii_uses_mdio_82575(hw)) {
815 switch (hw->mac.type) {
816 case e1000_82575:
817 case e1000_82576:
818 mdic = rd32(E1000_MDIC);
819 mdic &= E1000_MDIC_PHY_MASK;
820 phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
821 break;
822 case e1000_82580:
823 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000824 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000825 case e1000_i210:
826 case e1000_i211:
Nick Nunley4085f742010-07-26 13:15:06 +0000827 mdic = rd32(E1000_MDICNFG);
828 mdic &= E1000_MDICNFG_PHY_MASK;
829 phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
830 break;
831 default:
832 ret_val = -E1000_ERR_PHY;
833 goto out;
834 break;
835 }
836 ret_val = igb_get_phy_id(hw);
837 goto out;
838 }
839
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000840 /* Power on sgmii phy if it is disabled */
841 ctrl_ext = rd32(E1000_CTRL_EXT);
842 wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
843 wrfl();
844 msleep(300);
845
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000846 /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
Auke Kok9d5c8242008-01-24 02:22:38 -0800847 * Therefore, we need to test 1-7
848 */
849 for (phy->addr = 1; phy->addr < 8; phy->addr++) {
850 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
851 if (ret_val == 0) {
Auke Kok652fff32008-06-27 11:00:18 -0700852 hw_dbg("Vendor ID 0x%08X read at address %u\n",
853 phy_id, phy->addr);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000854 /* At the time of this writing, The M88 part is
Auke Kok9d5c8242008-01-24 02:22:38 -0800855 * the only supported SGMII PHY product.
856 */
857 if (phy_id == M88_VENDOR)
858 break;
859 } else {
Auke Kok652fff32008-06-27 11:00:18 -0700860 hw_dbg("PHY address %u was unreadable\n", phy->addr);
Auke Kok9d5c8242008-01-24 02:22:38 -0800861 }
862 }
863
864 /* A valid PHY type couldn't be found. */
865 if (phy->addr == 8) {
866 phy->addr = 0;
867 ret_val = -E1000_ERR_PHY;
868 goto out;
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000869 } else {
870 ret_val = igb_get_phy_id(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800871 }
872
Alexander Duyck2fb02a22009-09-14 08:22:54 +0000873 /* restore previous sfp cage power state */
874 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -0800875
876out:
877 return ret_val;
878}
879
880/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700881 * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800882 * @hw: pointer to the HW structure
883 *
884 * Resets the PHY using the serial gigabit media independent interface.
885 **/
886static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
887{
888 s32 ret_val;
889
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000890 /* This isn't a true "hard" reset, but is the only reset
Auke Kok9d5c8242008-01-24 02:22:38 -0800891 * available to us at this time.
892 */
893
Auke Kok652fff32008-06-27 11:00:18 -0700894 hw_dbg("Soft resetting SGMII attached PHY...\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800895
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000896 /* SFP documentation requires the following to configure the SPF module
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 * to work on SGMII. No further documentation is given.
898 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000899 ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
Auke Kok9d5c8242008-01-24 02:22:38 -0800900 if (ret_val)
901 goto out;
902
903 ret_val = igb_phy_sw_reset(hw);
904
905out:
906 return ret_val;
907}
908
909/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700910 * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
Auke Kok9d5c8242008-01-24 02:22:38 -0800911 * @hw: pointer to the HW structure
912 * @active: true to enable LPLU, false to disable
913 *
914 * Sets the LPLU D0 state according to the active flag. When
915 * activating LPLU this function also disables smart speed
916 * and vice versa. LPLU will not be activated unless the
917 * device autonegotiation advertisement meets standards of
918 * either 10 or 10/100 or 10/100/1000 at all duplexes.
919 * This is a function pointer entry point only called by
920 * PHY setup routines.
921 **/
922static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
923{
924 struct e1000_phy_info *phy = &hw->phy;
925 s32 ret_val;
926 u16 data;
927
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000928 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800929 if (ret_val)
930 goto out;
931
932 if (active) {
933 data |= IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000934 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700935 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800936 if (ret_val)
937 goto out;
938
939 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000940 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700941 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800942 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000943 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok652fff32008-06-27 11:00:18 -0700944 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800945 if (ret_val)
946 goto out;
947 } else {
948 data &= ~IGP02E1000_PM_D0_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000949 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok652fff32008-06-27 11:00:18 -0700950 data);
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000951 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -0800952 * during Dx states where the power conservation is most
953 * important. During driver activity we should enable
954 * SmartSpeed, so performance is maintained.
955 */
956 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000957 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700958 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800959 if (ret_val)
960 goto out;
961
962 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000963 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700964 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800965 if (ret_val)
966 goto out;
967 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000968 ret_val = phy->ops.read_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700969 IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 if (ret_val)
971 goto out;
972
973 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000974 ret_val = phy->ops.write_reg(hw,
Auke Kok652fff32008-06-27 11:00:18 -0700975 IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800976 if (ret_val)
977 goto out;
978 }
979 }
980
981out:
982 return ret_val;
983}
984
985/**
Carolyn Wybornyda02cde2012-03-04 03:26:26 +0000986 * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
987 * @hw: pointer to the HW structure
988 * @active: true to enable LPLU, false to disable
989 *
990 * Sets the LPLU D0 state according to the active flag. When
991 * activating LPLU this function also disables smart speed
992 * and vice versa. LPLU will not be activated unless the
993 * device autonegotiation advertisement meets standards of
994 * either 10 or 10/100 or 10/100/1000 at all duplexes.
995 * This is a function pointer entry point only called by
996 * PHY setup routines.
997 **/
998static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
999{
1000 struct e1000_phy_info *phy = &hw->phy;
1001 s32 ret_val = 0;
1002 u16 data;
1003
1004 data = rd32(E1000_82580_PHY_POWER_MGMT);
1005
1006 if (active) {
1007 data |= E1000_82580_PM_D0_LPLU;
1008
1009 /* When LPLU is enabled, we should disable SmartSpeed */
1010 data &= ~E1000_82580_PM_SPD;
1011 } else {
1012 data &= ~E1000_82580_PM_D0_LPLU;
1013
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001014 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001015 * during Dx states where the power conservation is most
1016 * important. During driver activity we should enable
1017 * SmartSpeed, so performance is maintained.
1018 */
1019 if (phy->smart_speed == e1000_smart_speed_on)
1020 data |= E1000_82580_PM_SPD;
1021 else if (phy->smart_speed == e1000_smart_speed_off)
1022 data &= ~E1000_82580_PM_SPD; }
1023
1024 wr32(E1000_82580_PHY_POWER_MGMT, data);
1025 return ret_val;
1026}
1027
1028/**
1029 * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
1030 * @hw: pointer to the HW structure
1031 * @active: boolean used to enable/disable lplu
1032 *
1033 * Success returns 0, Failure returns 1
1034 *
1035 * The low power link up (lplu) state is set to the power management level D3
1036 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1037 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1038 * is used during Dx states where the power conservation is most important.
1039 * During driver activity, SmartSpeed should be enabled so performance is
1040 * maintained.
1041 **/
Akeem G. Abodunrinc8268922013-02-16 07:09:06 +00001042static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001043{
1044 struct e1000_phy_info *phy = &hw->phy;
1045 s32 ret_val = 0;
1046 u16 data;
1047
1048 data = rd32(E1000_82580_PHY_POWER_MGMT);
1049
1050 if (!active) {
1051 data &= ~E1000_82580_PM_D3_LPLU;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001052 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Carolyn Wybornyda02cde2012-03-04 03:26:26 +00001053 * during Dx states where the power conservation is most
1054 * important. During driver activity we should enable
1055 * SmartSpeed, so performance is maintained.
1056 */
1057 if (phy->smart_speed == e1000_smart_speed_on)
1058 data |= E1000_82580_PM_SPD;
1059 else if (phy->smart_speed == e1000_smart_speed_off)
1060 data &= ~E1000_82580_PM_SPD;
1061 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1062 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1063 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1064 data |= E1000_82580_PM_D3_LPLU;
1065 /* When LPLU is enabled, we should disable SmartSpeed */
1066 data &= ~E1000_82580_PM_SPD;
1067 }
1068
1069 wr32(E1000_82580_PHY_POWER_MGMT, data);
1070 return ret_val;
1071}
1072
1073/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001074 * igb_acquire_nvm_82575 - Request for access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001075 * @hw: pointer to the HW structure
1076 *
Auke Kok652fff32008-06-27 11:00:18 -07001077 * Acquire the necessary semaphores for exclusive access to the EEPROM.
Auke Kok9d5c8242008-01-24 02:22:38 -08001078 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1079 * Return successful if access grant bit set, else clear the request for
1080 * EEPROM access and return -E1000_ERR_NVM (-1).
1081 **/
1082static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
1083{
1084 s32 ret_val;
1085
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001086 ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001087 if (ret_val)
1088 goto out;
1089
1090 ret_val = igb_acquire_nvm(hw);
1091
1092 if (ret_val)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001093 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001094
1095out:
1096 return ret_val;
1097}
1098
1099/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001100 * igb_release_nvm_82575 - Release exclusive access to EEPROM
Auke Kok9d5c8242008-01-24 02:22:38 -08001101 * @hw: pointer to the HW structure
1102 *
1103 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
1104 * then release the semaphores acquired.
1105 **/
1106static void igb_release_nvm_82575(struct e1000_hw *hw)
1107{
1108 igb_release_nvm(hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001109 hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
Auke Kok9d5c8242008-01-24 02:22:38 -08001110}
1111
1112/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001113 * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 * @hw: pointer to the HW structure
1115 * @mask: specifies which semaphore to acquire
1116 *
1117 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
1118 * will also specify which port we're acquiring the lock for.
1119 **/
1120static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1121{
1122 u32 swfw_sync;
1123 u32 swmask = mask;
1124 u32 fwmask = mask << 16;
1125 s32 ret_val = 0;
1126 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
1127
1128 while (i < timeout) {
1129 if (igb_get_hw_semaphore(hw)) {
1130 ret_val = -E1000_ERR_SWFW_SYNC;
1131 goto out;
1132 }
1133
1134 swfw_sync = rd32(E1000_SW_FW_SYNC);
1135 if (!(swfw_sync & (fwmask | swmask)))
1136 break;
1137
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001138 /* Firmware currently using resource (fwmask)
Auke Kok9d5c8242008-01-24 02:22:38 -08001139 * or other software thread using resource (swmask)
1140 */
1141 igb_put_hw_semaphore(hw);
1142 mdelay(5);
1143 i++;
1144 }
1145
1146 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001147 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001148 ret_val = -E1000_ERR_SWFW_SYNC;
1149 goto out;
1150 }
1151
1152 swfw_sync |= swmask;
1153 wr32(E1000_SW_FW_SYNC, swfw_sync);
1154
1155 igb_put_hw_semaphore(hw);
1156
1157out:
1158 return ret_val;
1159}
1160
1161/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001162 * igb_release_swfw_sync_82575 - Release SW/FW semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001163 * @hw: pointer to the HW structure
1164 * @mask: specifies which semaphore to acquire
1165 *
1166 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
1167 * will also specify which port we're releasing the lock for.
1168 **/
1169static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1170{
1171 u32 swfw_sync;
1172
1173 while (igb_get_hw_semaphore(hw) != 0);
1174 /* Empty */
1175
1176 swfw_sync = rd32(E1000_SW_FW_SYNC);
1177 swfw_sync &= ~mask;
1178 wr32(E1000_SW_FW_SYNC, swfw_sync);
1179
1180 igb_put_hw_semaphore(hw);
1181}
1182
1183/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001184 * igb_get_cfg_done_82575 - Read config done bit
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 * @hw: pointer to the HW structure
1186 *
1187 * Read the management control register for the config done bit for
1188 * completion status. NOTE: silicon which is EEPROM-less will fail trying
1189 * to read the config done bit, so an error is *ONLY* logged and returns
1190 * 0. If we were to return with error, EEPROM-less silicon
1191 * would not be able to be reset or change link.
1192 **/
1193static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
1194{
1195 s32 timeout = PHY_CFG_TIMEOUT;
1196 s32 ret_val = 0;
1197 u32 mask = E1000_NVM_CFG_DONE_PORT_0;
1198
1199 if (hw->bus.func == 1)
1200 mask = E1000_NVM_CFG_DONE_PORT_1;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001201 else if (hw->bus.func == E1000_FUNC_2)
1202 mask = E1000_NVM_CFG_DONE_PORT_2;
1203 else if (hw->bus.func == E1000_FUNC_3)
1204 mask = E1000_NVM_CFG_DONE_PORT_3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001205
1206 while (timeout) {
1207 if (rd32(E1000_EEMNGCTL) & mask)
1208 break;
1209 msleep(1);
1210 timeout--;
1211 }
1212 if (!timeout)
Auke Kok652fff32008-06-27 11:00:18 -07001213 hw_dbg("MNG configuration cycle has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001214
1215 /* If EEPROM is not marked present, init the PHY manually */
1216 if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
1217 (hw->phy.type == e1000_phy_igp_3))
1218 igb_phy_init_script_igp3(hw);
1219
1220 return ret_val;
1221}
1222
1223/**
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00001224 * igb_get_link_up_info_82575 - Get link speed/duplex info
1225 * @hw: pointer to the HW structure
1226 * @speed: stores the current speed
1227 * @duplex: stores the current duplex
1228 *
1229 * This is a wrapper function, if using the serial gigabit media independent
1230 * interface, use PCS to retrieve the link speed and duplex information.
1231 * Otherwise, use the generic function to get the link speed and duplex info.
1232 **/
1233static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
1234 u16 *duplex)
1235{
1236 s32 ret_val;
1237
1238 if (hw->phy.media_type != e1000_media_type_copper)
1239 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
1240 duplex);
1241 else
1242 ret_val = igb_get_speed_and_duplex_copper(hw, speed,
1243 duplex);
1244
1245 return ret_val;
1246}
1247
1248/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001249 * igb_check_for_link_82575 - Check for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001250 * @hw: pointer to the HW structure
1251 *
1252 * If sgmii is enabled, then use the pcs register to determine link, otherwise
1253 * use the generic interface for determining link.
1254 **/
1255static s32 igb_check_for_link_82575(struct e1000_hw *hw)
1256{
1257 s32 ret_val;
1258 u16 speed, duplex;
1259
Alexander Duyck70d92f82009-10-05 06:31:47 +00001260 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001261 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
Alexander Duyck2d064c02008-07-08 15:10:12 -07001262 &duplex);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001263 /* Use this flag to determine if link needs to be checked or
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001264 * not. If we have link clear the flag so that we do not
1265 * continue to check for link.
1266 */
1267 hw->mac.get_link_status = !hw->mac.serdes_has_link;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001268
1269 /* Configure Flow Control now that Auto-Neg has completed.
1270 * First, we need to restore the desired flow control
1271 * settings because we may have had to re-autoneg with a
1272 * different link partner.
1273 */
1274 ret_val = igb_config_fc_after_link_up(hw);
1275 if (ret_val)
1276 hw_dbg("Error configuring flow control\n");
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001277 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -08001278 ret_val = igb_check_for_copper_link(hw);
Alexander Duyck5d0932a2009-01-31 00:53:18 -08001279 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001280
1281 return ret_val;
1282}
Alexander Duyck70d92f82009-10-05 06:31:47 +00001283
Auke Kok9d5c8242008-01-24 02:22:38 -08001284/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001285 * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
1286 * @hw: pointer to the HW structure
1287 **/
1288void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
1289{
1290 u32 reg;
1291
1292
1293 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1294 !igb_sgmii_active_82575(hw))
1295 return;
1296
1297 /* Enable PCS to turn on link */
1298 reg = rd32(E1000_PCS_CFG0);
1299 reg |= E1000_PCS_CFG_PCS_EN;
1300 wr32(E1000_PCS_CFG0, reg);
1301
1302 /* Power up the laser */
1303 reg = rd32(E1000_CTRL_EXT);
1304 reg &= ~E1000_CTRL_EXT_SDP3_DATA;
1305 wr32(E1000_CTRL_EXT, reg);
1306
1307 /* flush the write to verify completion */
1308 wrfl();
1309 msleep(1);
1310}
1311
1312/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001313 * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001314 * @hw: pointer to the HW structure
1315 * @speed: stores the current speed
1316 * @duplex: stores the current duplex
1317 *
Auke Kok652fff32008-06-27 11:00:18 -07001318 * Using the physical coding sub-layer (PCS), retrieve the current speed and
Auke Kok9d5c8242008-01-24 02:22:38 -08001319 * duplex, then store the values in the pointers provided.
1320 **/
1321static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
1322 u16 *duplex)
1323{
1324 struct e1000_mac_info *mac = &hw->mac;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001325 u32 pcs, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08001326
1327 /* Set up defaults for the return values of this function */
1328 mac->serdes_has_link = false;
1329 *speed = 0;
1330 *duplex = 0;
1331
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001332 /* Read the PCS Status register for link state. For non-copper mode,
Auke Kok9d5c8242008-01-24 02:22:38 -08001333 * the status register is not accurate. The PCS status register is
1334 * used instead.
1335 */
1336 pcs = rd32(E1000_PCS_LSTAT);
1337
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001338 /* The link up bit determines when link is up on autoneg. The sync ok
Auke Kok9d5c8242008-01-24 02:22:38 -08001339 * gets set once both sides sync up and agree upon link. Stable link
1340 * can be determined by checking for both link up and link sync ok
1341 */
1342 if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
1343 mac->serdes_has_link = true;
1344
1345 /* Detect and store PCS speed */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001346 if (pcs & E1000_PCS_LSTS_SPEED_1000)
Auke Kok9d5c8242008-01-24 02:22:38 -08001347 *speed = SPEED_1000;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001348 else if (pcs & E1000_PCS_LSTS_SPEED_100)
Auke Kok9d5c8242008-01-24 02:22:38 -08001349 *speed = SPEED_100;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001350 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001351 *speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -08001352
1353 /* Detect and store PCS duplex */
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001354 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
Auke Kok9d5c8242008-01-24 02:22:38 -08001355 *duplex = FULL_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001356 else
Auke Kok9d5c8242008-01-24 02:22:38 -08001357 *duplex = HALF_DUPLEX;
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001358
1359 /* Check if it is an I354 2.5Gb backplane connection. */
1360 if (mac->type == e1000_i354) {
1361 status = rd32(E1000_STATUS);
1362 if ((status & E1000_STATUS_2P5_SKU) &&
1363 !(status & E1000_STATUS_2P5_SKU_OVER)) {
1364 *speed = SPEED_2500;
1365 *duplex = FULL_DUPLEX;
1366 hw_dbg("2500 Mbs, ");
1367 hw_dbg("Full Duplex\n");
1368 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001369 }
Akeem G Abodunrinf1b4d622013-08-28 02:23:04 +00001370
Auke Kok9d5c8242008-01-24 02:22:38 -08001371 }
1372
1373 return 0;
1374}
1375
1376/**
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001377 * igb_shutdown_serdes_link_82575 - Remove link during power down
Alexander Duyck2d064c02008-07-08 15:10:12 -07001378 * @hw: pointer to the HW structure
1379 *
1380 * In the case of fiber serdes, shut down optics and PCS on driver unload
1381 * when management pass thru is not enabled.
1382 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001383void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001384{
1385 u32 reg;
1386
Nick Nunley53c992f2010-02-17 01:01:40 +00001387 if (hw->phy.media_type != e1000_media_type_internal_serdes &&
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001388 igb_sgmii_active_82575(hw))
Alexander Duyck2d064c02008-07-08 15:10:12 -07001389 return;
1390
Nick Nunley53c992f2010-02-17 01:01:40 +00001391 if (!igb_enable_mng_pass_thru(hw)) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001392 /* Disable PCS to turn off link */
1393 reg = rd32(E1000_PCS_CFG0);
1394 reg &= ~E1000_PCS_CFG_PCS_EN;
1395 wr32(E1000_PCS_CFG0, reg);
1396
1397 /* shutdown the laser */
1398 reg = rd32(E1000_CTRL_EXT);
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001399 reg |= E1000_CTRL_EXT_SDP3_DATA;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001400 wr32(E1000_CTRL_EXT, reg);
1401
1402 /* flush the write to verify completion */
1403 wrfl();
1404 msleep(1);
1405 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001406}
1407
1408/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001409 * igb_reset_hw_82575 - Reset hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001410 * @hw: pointer to the HW structure
1411 *
1412 * This resets the hardware into a known state. This is a
1413 * function pointer entry point called by the api module.
1414 **/
1415static s32 igb_reset_hw_82575(struct e1000_hw *hw)
1416{
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001417 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001418 s32 ret_val;
1419
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001420 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kok9d5c8242008-01-24 02:22:38 -08001421 * on the last TLP read/write transaction when MAC is reset.
1422 */
1423 ret_val = igb_disable_pcie_master(hw);
1424 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -07001425 hw_dbg("PCI-E Master disable polling has failed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001426
Alexander Duyck009bc062009-07-23 18:08:35 +00001427 /* set the completion timeout for interface */
1428 ret_val = igb_set_pcie_completion_timeout(hw);
1429 if (ret_val) {
1430 hw_dbg("PCI-E Set completion timeout has failed.\n");
1431 }
1432
Auke Kok652fff32008-06-27 11:00:18 -07001433 hw_dbg("Masking off all interrupts\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001434 wr32(E1000_IMC, 0xffffffff);
1435
1436 wr32(E1000_RCTL, 0);
1437 wr32(E1000_TCTL, E1000_TCTL_PSP);
1438 wrfl();
1439
1440 msleep(10);
1441
1442 ctrl = rd32(E1000_CTRL);
1443
Auke Kok652fff32008-06-27 11:00:18 -07001444 hw_dbg("Issuing a global reset to MAC\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001445 wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
1446
1447 ret_val = igb_get_auto_rd_done(hw);
1448 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001449 /* When auto config read does not complete, do not
Auke Kok9d5c8242008-01-24 02:22:38 -08001450 * return with an error. This can happen in situations
1451 * where there is no eeprom and prevents getting link.
1452 */
Auke Kok652fff32008-06-27 11:00:18 -07001453 hw_dbg("Auto Read Done did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001454 }
1455
1456 /* If EEPROM is not present, run manual init scripts */
1457 if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
1458 igb_reset_init_script_82575(hw);
1459
1460 /* Clear any pending interrupt events. */
1461 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00001462 rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08001463
Alexander Duyck5ac16652009-07-23 18:09:12 +00001464 /* Install any alternate MAC address into RAR0 */
1465 ret_val = igb_check_alt_mac_addr(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001466
1467 return ret_val;
1468}
1469
1470/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001471 * igb_init_hw_82575 - Initialize hardware
Auke Kok9d5c8242008-01-24 02:22:38 -08001472 * @hw: pointer to the HW structure
1473 *
1474 * This inits the hardware readying it for operation.
1475 **/
1476static s32 igb_init_hw_82575(struct e1000_hw *hw)
1477{
1478 struct e1000_mac_info *mac = &hw->mac;
1479 s32 ret_val;
1480 u16 i, rar_count = mac->rar_entry_count;
1481
1482 /* Initialize identification LED */
1483 ret_val = igb_id_led_init(hw);
1484 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001485 hw_dbg("Error initializing identification LED\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001486 /* This is not fatal and we should not stop init due to this */
1487 }
1488
1489 /* Disabling VLAN filtering */
Auke Kok652fff32008-06-27 11:00:18 -07001490 hw_dbg("Initializing the IEEE VLAN\n");
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001491 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +00001492 igb_clear_vfta_i350(hw);
1493 else
1494 igb_clear_vfta(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001495
1496 /* Setup the receive address */
Alexander Duyck5ac16652009-07-23 18:09:12 +00001497 igb_init_rx_addrs(hw, rar_count);
1498
Auke Kok9d5c8242008-01-24 02:22:38 -08001499 /* Zero out the Multicast HASH table */
Auke Kok652fff32008-06-27 11:00:18 -07001500 hw_dbg("Zeroing the MTA\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001501 for (i = 0; i < mac->mta_reg_count; i++)
1502 array_wr32(E1000_MTA, i, 0);
1503
Alexander Duyck68d480c2009-10-05 06:33:08 +00001504 /* Zero out the Unicast HASH table */
1505 hw_dbg("Zeroing the UTA\n");
1506 for (i = 0; i < mac->uta_reg_count; i++)
1507 array_wr32(E1000_UTA, i, 0);
1508
Auke Kok9d5c8242008-01-24 02:22:38 -08001509 /* Setup link and flow control */
1510 ret_val = igb_setup_link(hw);
1511
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001512 /* Clear all of the statistics registers (clear on read). It is
Auke Kok9d5c8242008-01-24 02:22:38 -08001513 * important that we do this after we have tried to establish link
1514 * because the symbol error count will increment wildly if there
1515 * is no link.
1516 */
1517 igb_clear_hw_cntrs_82575(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001518 return ret_val;
1519}
1520
1521/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001522 * igb_setup_copper_link_82575 - Configure copper link settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001523 * @hw: pointer to the HW structure
1524 *
1525 * Configures the link for auto-neg or forced speed and duplex. Then we check
1526 * for link, once link is established calls to configure collision distance
1527 * and flow control are called.
1528 **/
1529static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
1530{
Alexander Duyck12645a12009-07-23 18:08:16 +00001531 u32 ctrl;
Auke Kok9d5c8242008-01-24 02:22:38 -08001532 s32 ret_val;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001533 u32 phpm_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001534
1535 ctrl = rd32(E1000_CTRL);
1536 ctrl |= E1000_CTRL_SLU;
1537 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1538 wr32(E1000_CTRL, ctrl);
1539
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001540 /* Clear Go Link Disconnect bit on supported devices */
1541 switch (hw->mac.type) {
1542 case e1000_82580:
1543 case e1000_i350:
1544 case e1000_i210:
1545 case e1000_i211:
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001546 phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
1547 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1548 wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
Akeem G Abodunrindb476e82013-08-28 02:22:53 +00001549 break;
1550 default:
1551 break;
Carolyn Wyborny867eb392012-11-13 04:03:20 +00001552 }
1553
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001554 ret_val = igb_setup_serdes_link_82575(hw);
1555 if (ret_val)
1556 goto out;
1557
1558 if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001559 /* allow time for SFP cage time to power up phy */
1560 msleep(300);
1561
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001562 ret_val = hw->phy.ops.reset(hw);
1563 if (ret_val) {
1564 hw_dbg("Error resetting the PHY.\n");
1565 goto out;
1566 }
1567 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001568 switch (hw->phy.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001569 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001570 case e1000_phy_m88:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001571 switch (hw->phy.id) {
1572 case I347AT4_E_PHY_ID:
1573 case M88E1112_E_PHY_ID:
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001574 case M88E1543_E_PHY_ID:
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001575 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001576 ret_val = igb_copper_link_setup_m88_gen2(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001577 break;
1578 default:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001579 ret_val = igb_copper_link_setup_m88(hw);
Carolyn Wybornyed65bdd2013-02-06 03:35:27 +00001580 break;
1581 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001582 break;
1583 case e1000_phy_igp_3:
1584 ret_val = igb_copper_link_setup_igp(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001585 break;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001586 case e1000_phy_82580:
1587 ret_val = igb_copper_link_setup_82580(hw);
1588 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001589 default:
1590 ret_val = -E1000_ERR_PHY;
1591 break;
1592 }
1593
1594 if (ret_val)
1595 goto out;
1596
Alexander Duyck81fadd82009-10-05 06:35:03 +00001597 ret_val = igb_setup_copper_link(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001598out:
1599 return ret_val;
1600}
1601
1602/**
Alexander Duyck70d92f82009-10-05 06:31:47 +00001603 * igb_setup_serdes_link_82575 - Setup link for serdes
Auke Kok9d5c8242008-01-24 02:22:38 -08001604 * @hw: pointer to the HW structure
1605 *
Alexander Duyck70d92f82009-10-05 06:31:47 +00001606 * Configure the physical coding sub-layer (PCS) link. The PCS link is
1607 * used on copper connections where the serialized gigabit media independent
1608 * interface (sgmii), or serdes fiber is being used. Configures the link
1609 * for auto-negotiation or forces speed/duplex.
Auke Kok9d5c8242008-01-24 02:22:38 -08001610 **/
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001611static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001612{
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001613 u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001614 bool pcs_autoneg;
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001615 s32 ret_val = E1000_SUCCESS;
1616 u16 data;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001617
1618 if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
1619 !igb_sgmii_active_82575(hw))
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001620 return ret_val;
1621
Auke Kok9d5c8242008-01-24 02:22:38 -08001622
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001623 /* On the 82575, SerDes loopback mode persists until it is
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 * explicitly turned off or a power cycle is performed. A read to
1625 * the register does not indicate its status. Therefore, we ensure
1626 * loopback mode is disabled during initialization.
1627 */
1628 wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1629
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001630 /* power on the sfp cage if present and turn on I2C */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001631 ctrl_ext = rd32(E1000_CTRL_EXT);
1632 ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
Akeem G. Abodunrine00bf602013-01-29 10:15:26 +00001633 ctrl_ext |= E1000_CTRL_I2C_ENA;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001634 wr32(E1000_CTRL_EXT, ctrl_ext);
Auke Kok9d5c8242008-01-24 02:22:38 -08001635
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001636 ctrl_reg = rd32(E1000_CTRL);
1637 ctrl_reg |= E1000_CTRL_SLU;
1638
1639 if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
1640 /* set both sw defined pins */
1641 ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
1642
1643 /* Set switch control to serdes energy detect */
1644 reg = rd32(E1000_CONNSW);
1645 reg |= E1000_CONNSW_ENRGSRC;
1646 wr32(E1000_CONNSW, reg);
Alexander Duyck921aa742009-01-21 14:42:28 -08001647 }
1648
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001649 reg = rd32(E1000_PCS_LCTL);
1650
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001651 /* default pcs_autoneg to the same setting as mac autoneg */
1652 pcs_autoneg = hw->mac.autoneg;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001653
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001654 switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
1655 case E1000_CTRL_EXT_LINK_MODE_SGMII:
1656 /* sgmii mode lets the phy handle forcing speed/duplex */
1657 pcs_autoneg = true;
1658 /* autoneg time out should be disabled for SGMII mode */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001659 reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001660 break;
1661 case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
1662 /* disable PCS autoneg and support parallel detect only */
1663 pcs_autoneg = false;
1664 default:
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001665 if (hw->mac.type == e1000_82575 ||
1666 hw->mac.type == e1000_82576) {
1667 ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
1668 if (ret_val) {
1669 printk(KERN_DEBUG "NVM Read Error\n\n");
1670 return ret_val;
1671 }
1672
1673 if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
1674 pcs_autoneg = false;
1675 }
1676
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001677 /* non-SGMII modes only supports a speed of 1000/Full for the
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001678 * link so it is best to just force the MAC and let the pcs
1679 * link either autoneg or be forced to 1000/Full
1680 */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001681 ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
1682 E1000_CTRL_FD | E1000_CTRL_FRCDPX;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001683
1684 /* set speed of 1000/Full if speed/duplex is forced */
1685 reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
1686 break;
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001687 }
1688
1689 wr32(E1000_CTRL, ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001690
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001691 /* New SerDes mode allows for forcing speed or autonegotiating speed
Auke Kok9d5c8242008-01-24 02:22:38 -08001692 * at 1gb. Autoneg should be default set by most drivers. This is the
1693 * mode that will be compatible with older link partners and switches.
1694 * However, both are supported by the hardware and some drivers/tools.
1695 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001696 reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1697 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1698
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001699 if (pcs_autoneg) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001700 /* Set PCS register for autoneg */
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001701 reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001702 E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001703
1704 /* Disable force flow control for autoneg */
1705 reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
1706
1707 /* Configure flow control advertisement for autoneg */
1708 anadv_reg = rd32(E1000_PCS_ANADV);
1709 anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
1710 switch (hw->fc.requested_mode) {
1711 case e1000_fc_full:
1712 case e1000_fc_rx_pause:
1713 anadv_reg |= E1000_TXCW_ASM_DIR;
1714 anadv_reg |= E1000_TXCW_PAUSE;
1715 break;
1716 case e1000_fc_tx_pause:
1717 anadv_reg |= E1000_TXCW_ASM_DIR;
1718 break;
1719 default:
1720 break;
1721 }
1722 wr32(E1000_PCS_ANADV, anadv_reg);
1723
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001724 hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001725 } else {
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001726 /* Set PCS register for forced link */
Alexander Duyckd68caec2009-12-23 13:20:47 +00001727 reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
Alexander Duyck70d92f82009-10-05 06:31:47 +00001728
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001729 /* Force flow control for forced link */
1730 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1731
Alexander Duyckbb2ac472009-11-19 12:42:01 +00001732 hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001733 }
Alexander Duyck726c09e2008-08-04 14:59:56 -07001734
Auke Kok9d5c8242008-01-24 02:22:38 -08001735 wr32(E1000_PCS_LCTL, reg);
1736
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001737 if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001738 igb_force_mac_fc(hw);
1739
Carolyn Wyborny2c670b52011-05-24 06:52:51 +00001740 return ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001741}
1742
1743/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001744 * igb_sgmii_active_82575 - Return sgmii state
Auke Kok9d5c8242008-01-24 02:22:38 -08001745 * @hw: pointer to the HW structure
1746 *
1747 * 82575 silicon has a serialized gigabit media independent interface (sgmii)
1748 * which can be enabled for use in the embedded applications. Simply
1749 * return the current state of the sgmii interface.
1750 **/
1751static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1752{
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001753 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
Alexander Duyckc1889bf2009-02-06 23:16:45 +00001754 return dev_spec->sgmii_active;
Auke Kok9d5c8242008-01-24 02:22:38 -08001755}
1756
1757/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001758 * igb_reset_init_script_82575 - Inits HW defaults after reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001759 * @hw: pointer to the HW structure
1760 *
1761 * Inits recommended HW defaults after a reset when there is no EEPROM
1762 * detected. This is only for the 82575.
1763 **/
1764static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1765{
1766 if (hw->mac.type == e1000_82575) {
Auke Kok652fff32008-06-27 11:00:18 -07001767 hw_dbg("Running reset init script for 82575\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001768 /* SerDes configuration via SERDESCTRL */
1769 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1770 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1771 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1772 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1773
1774 /* CCM configuration via CCMCTL register */
1775 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1776 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1777
1778 /* PCIe lanes configuration */
1779 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1780 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1781 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1782 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1783
1784 /* PCIe PLL Configuration */
1785 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1786 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1787 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1788 }
1789
1790 return 0;
1791}
1792
1793/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001794 * igb_read_mac_addr_82575 - Read device MAC address
Auke Kok9d5c8242008-01-24 02:22:38 -08001795 * @hw: pointer to the HW structure
1796 **/
1797static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1798{
1799 s32 ret_val = 0;
1800
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001801 /* If there's an alternate MAC address place it in RAR0
Alexander Duyck22896632009-10-05 06:34:25 +00001802 * so that it will override the Si installed default perm
1803 * address.
1804 */
1805 ret_val = igb_check_alt_mac_addr(hw);
1806 if (ret_val)
1807 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001808
Alexander Duyck22896632009-10-05 06:34:25 +00001809 ret_val = igb_read_mac_addr(hw);
1810
1811out:
Auke Kok9d5c8242008-01-24 02:22:38 -08001812 return ret_val;
1813}
1814
1815/**
Nick Nunley88a268c2010-02-17 01:01:59 +00001816 * igb_power_down_phy_copper_82575 - Remove link during PHY power down
1817 * @hw: pointer to the HW structure
1818 *
1819 * In the case of a PHY power down to save power, or to turn off link during a
1820 * driver unload, or wake on lan is not enabled, remove the link.
1821 **/
1822void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
1823{
1824 /* If the management interface is not enabled, then power down */
1825 if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
1826 igb_power_down_phy_copper(hw);
Nick Nunley88a268c2010-02-17 01:01:59 +00001827}
1828
1829/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001830 * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -08001831 * @hw: pointer to the HW structure
1832 *
1833 * Clears the hardware counters by reading the counter registers.
1834 **/
1835static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1836{
Auke Kok9d5c8242008-01-24 02:22:38 -08001837 igb_clear_hw_cntrs_base(hw);
1838
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001839 rd32(E1000_PRC64);
1840 rd32(E1000_PRC127);
1841 rd32(E1000_PRC255);
1842 rd32(E1000_PRC511);
1843 rd32(E1000_PRC1023);
1844 rd32(E1000_PRC1522);
1845 rd32(E1000_PTC64);
1846 rd32(E1000_PTC127);
1847 rd32(E1000_PTC255);
1848 rd32(E1000_PTC511);
1849 rd32(E1000_PTC1023);
1850 rd32(E1000_PTC1522);
Auke Kok9d5c8242008-01-24 02:22:38 -08001851
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001852 rd32(E1000_ALGNERRC);
1853 rd32(E1000_RXERRC);
1854 rd32(E1000_TNCRS);
1855 rd32(E1000_CEXTERR);
1856 rd32(E1000_TSCTC);
1857 rd32(E1000_TSCTFC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001858
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001859 rd32(E1000_MGTPRC);
1860 rd32(E1000_MGTPDC);
1861 rd32(E1000_MGTPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001862
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001863 rd32(E1000_IAC);
1864 rd32(E1000_ICRXOC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001865
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001866 rd32(E1000_ICRXPTC);
1867 rd32(E1000_ICRXATC);
1868 rd32(E1000_ICTXPTC);
1869 rd32(E1000_ICTXATC);
1870 rd32(E1000_ICTXQEC);
1871 rd32(E1000_ICTXQMTC);
1872 rd32(E1000_ICRXDMTC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001873
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001874 rd32(E1000_CBTMPC);
1875 rd32(E1000_HTDPMC);
1876 rd32(E1000_CBRMPC);
1877 rd32(E1000_RPTHC);
1878 rd32(E1000_HGPTC);
1879 rd32(E1000_HTCBDPC);
1880 rd32(E1000_HGORCL);
1881 rd32(E1000_HGORCH);
1882 rd32(E1000_HGOTCL);
1883 rd32(E1000_HGOTCH);
1884 rd32(E1000_LENERRS);
Auke Kok9d5c8242008-01-24 02:22:38 -08001885
1886 /* This register should not be read in copper configurations */
Alexander Duyck2fb02a22009-09-14 08:22:54 +00001887 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
1888 igb_sgmii_active_82575(hw))
Alexander Duyckcc9073b2009-10-05 06:31:25 +00001889 rd32(E1000_SCVPC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001890}
1891
Alexander Duyck662d7202008-06-27 11:00:29 -07001892/**
1893 * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1894 * @hw: pointer to the HW structure
1895 *
1896 * After rx enable if managability is enabled then there is likely some
1897 * bad data at the start of the fifo and possibly in the DMA fifo. This
1898 * function clears the fifos and flushes any packets that came in as rx was
1899 * being enabled.
1900 **/
1901void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1902{
1903 u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1904 int i, ms_wait;
1905
1906 if (hw->mac.type != e1000_82575 ||
1907 !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1908 return;
1909
1910 /* Disable all RX queues */
1911 for (i = 0; i < 4; i++) {
1912 rxdctl[i] = rd32(E1000_RXDCTL(i));
1913 wr32(E1000_RXDCTL(i),
1914 rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1915 }
1916 /* Poll all queues to verify they have shut down */
1917 for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1918 msleep(1);
1919 rx_enabled = 0;
1920 for (i = 0; i < 4; i++)
1921 rx_enabled |= rd32(E1000_RXDCTL(i));
1922 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1923 break;
1924 }
1925
1926 if (ms_wait == 10)
1927 hw_dbg("Queue disable timed out after 10ms\n");
1928
1929 /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1930 * incoming packets are rejected. Set enable and wait 2ms so that
1931 * any packet that was coming in as RCTL.EN was set is flushed
1932 */
1933 rfctl = rd32(E1000_RFCTL);
1934 wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1935
1936 rlpml = rd32(E1000_RLPML);
1937 wr32(E1000_RLPML, 0);
1938
1939 rctl = rd32(E1000_RCTL);
1940 temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1941 temp_rctl |= E1000_RCTL_LPE;
1942
1943 wr32(E1000_RCTL, temp_rctl);
1944 wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1945 wrfl();
1946 msleep(2);
1947
1948 /* Enable RX queues that were previously enabled and restore our
1949 * previous state
1950 */
1951 for (i = 0; i < 4; i++)
1952 wr32(E1000_RXDCTL(i), rxdctl[i]);
1953 wr32(E1000_RCTL, rctl);
1954 wrfl();
1955
1956 wr32(E1000_RLPML, rlpml);
1957 wr32(E1000_RFCTL, rfctl);
1958
1959 /* Flush receive errors generated by workaround */
1960 rd32(E1000_ROC);
1961 rd32(E1000_RNBC);
1962 rd32(E1000_MPC);
1963}
1964
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001965/**
Alexander Duyck009bc062009-07-23 18:08:35 +00001966 * igb_set_pcie_completion_timeout - set pci-e completion timeout
1967 * @hw: pointer to the HW structure
1968 *
1969 * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
1970 * however the hardware default for these parts is 500us to 1ms which is less
1971 * than the 10ms recommended by the pci-e spec. To address this we need to
1972 * increase the value to either 10ms to 200ms for capability version 1 config,
1973 * or 16ms to 55ms for version 2.
1974 **/
1975static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
1976{
1977 u32 gcr = rd32(E1000_GCR);
1978 s32 ret_val = 0;
1979 u16 pcie_devctl2;
1980
1981 /* only take action if timeout value is defaulted to 0 */
1982 if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
1983 goto out;
1984
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001985 /* if capabilities version is type 1 we can write the
Alexander Duyck009bc062009-07-23 18:08:35 +00001986 * timeout of 10ms to 200ms through the GCR register
1987 */
1988 if (!(gcr & E1000_GCR_CAP_VER2)) {
1989 gcr |= E1000_GCR_CMPL_TMOUT_10ms;
1990 goto out;
1991 }
1992
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001993 /* for version 2 capabilities we need to write the config space
Alexander Duyck009bc062009-07-23 18:08:35 +00001994 * directly in order to set the completion timeout value for
1995 * 16ms to 55ms
1996 */
1997 ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
1998 &pcie_devctl2);
1999 if (ret_val)
2000 goto out;
2001
2002 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
2003
2004 ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
2005 &pcie_devctl2);
2006out:
2007 /* disable completion timeout resend */
2008 gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
2009
2010 wr32(E1000_GCR, gcr);
2011 return ret_val;
2012}
2013
2014/**
Greg Rose13800462010-11-06 02:08:26 +00002015 * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
2016 * @hw: pointer to the hardware struct
2017 * @enable: state to enter, either enabled or disabled
2018 * @pf: Physical Function pool - do not set anti-spoofing for the PF
2019 *
2020 * enables/disables L2 switch anti-spoofing functionality.
2021 **/
2022void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
2023{
Lior Levy22c12752013-03-12 15:49:32 +00002024 u32 reg_val, reg_offset;
Greg Rose13800462010-11-06 02:08:26 +00002025
2026 switch (hw->mac.type) {
2027 case e1000_82576:
Lior Levy22c12752013-03-12 15:49:32 +00002028 reg_offset = E1000_DTXSWC;
2029 break;
Greg Rose13800462010-11-06 02:08:26 +00002030 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002031 case e1000_i354:
Lior Levy22c12752013-03-12 15:49:32 +00002032 reg_offset = E1000_TXSWC;
Greg Rose13800462010-11-06 02:08:26 +00002033 break;
2034 default:
Lior Levy22c12752013-03-12 15:49:32 +00002035 return;
Greg Rose13800462010-11-06 02:08:26 +00002036 }
Lior Levy22c12752013-03-12 15:49:32 +00002037
2038 reg_val = rd32(reg_offset);
2039 if (enable) {
2040 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
2041 E1000_DTXSWC_VLAN_SPOOF_MASK);
2042 /* The PF can spoof - it has to in order to
2043 * support emulation mode NICs
2044 */
2045 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
2046 } else {
2047 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
2048 E1000_DTXSWC_VLAN_SPOOF_MASK);
2049 }
2050 wr32(reg_offset, reg_val);
Greg Rose13800462010-11-06 02:08:26 +00002051}
2052
2053/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002054 * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
2055 * @hw: pointer to the hardware struct
2056 * @enable: state to enter, either enabled or disabled
2057 *
2058 * enables/disables L2 switch loopback functionality.
2059 **/
2060void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
2061{
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002062 u32 dtxswc;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002063
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002064 switch (hw->mac.type) {
2065 case e1000_82576:
2066 dtxswc = rd32(E1000_DTXSWC);
2067 if (enable)
2068 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2069 else
2070 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2071 wr32(E1000_DTXSWC, dtxswc);
2072 break;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002073 case e1000_i354:
Akeem G. Abodunrinca2e3e72011-09-08 20:39:48 +00002074 case e1000_i350:
2075 dtxswc = rd32(E1000_TXSWC);
2076 if (enable)
2077 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2078 else
2079 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
2080 wr32(E1000_TXSWC, dtxswc);
2081 break;
2082 default:
2083 /* Currently no other hardware supports loopback */
2084 break;
2085 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002086
Alexander Duyck4ae196d2009-02-19 20:40:07 -08002087}
2088
2089/**
2090 * igb_vmdq_set_replication_pf - enable or disable vmdq replication
2091 * @hw: pointer to the hardware struct
2092 * @enable: state to enter, either enabled or disabled
2093 *
2094 * enables/disables replication of packets across multiple pools.
2095 **/
2096void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
2097{
2098 u32 vt_ctl = rd32(E1000_VT_CTL);
2099
2100 if (enable)
2101 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
2102 else
2103 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
2104
2105 wr32(E1000_VT_CTL, vt_ctl);
2106}
2107
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002108/**
2109 * igb_read_phy_reg_82580 - Read 82580 MDI control register
2110 * @hw: pointer to the HW structure
2111 * @offset: register offset to be read
2112 * @data: pointer to the read data
2113 *
2114 * Reads the MDI control register in the PHY at offset and stores the
2115 * information read to data.
2116 **/
2117static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
2118{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002119 s32 ret_val;
2120
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002121 ret_val = hw->phy.ops.acquire(hw);
2122 if (ret_val)
2123 goto out;
2124
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002125 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2126
2127 hw->phy.ops.release(hw);
2128
2129out:
2130 return ret_val;
2131}
2132
2133/**
2134 * igb_write_phy_reg_82580 - Write 82580 MDI control register
2135 * @hw: pointer to the HW structure
2136 * @offset: register offset to write to
2137 * @data: data to write to register at offset
2138 *
2139 * Writes data to MDI control register in the PHY at offset.
2140 **/
2141static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
2142{
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002143 s32 ret_val;
2144
2145
2146 ret_val = hw->phy.ops.acquire(hw);
2147 if (ret_val)
2148 goto out;
2149
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002150 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2151
2152 hw->phy.ops.release(hw);
2153
2154out:
2155 return ret_val;
2156}
2157
2158/**
Nick Nunley08451e22010-07-26 13:15:29 +00002159 * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
2160 * @hw: pointer to the HW structure
2161 *
2162 * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
2163 * the values found in the EEPROM. This addresses an issue in which these
2164 * bits are not restored from EEPROM after reset.
2165 **/
2166static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
2167{
2168 s32 ret_val = 0;
2169 u32 mdicnfg;
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +00002170 u16 nvm_data = 0;
Nick Nunley08451e22010-07-26 13:15:29 +00002171
2172 if (hw->mac.type != e1000_82580)
2173 goto out;
2174 if (!igb_sgmii_active_82575(hw))
2175 goto out;
2176
2177 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2178 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2179 &nvm_data);
2180 if (ret_val) {
2181 hw_dbg("NVM Read Error\n");
2182 goto out;
2183 }
2184
2185 mdicnfg = rd32(E1000_MDICNFG);
2186 if (nvm_data & NVM_WORD24_EXT_MDIO)
2187 mdicnfg |= E1000_MDICNFG_EXT_MDIO;
2188 if (nvm_data & NVM_WORD24_COM_MDIO)
2189 mdicnfg |= E1000_MDICNFG_COM_MDIO;
2190 wr32(E1000_MDICNFG, mdicnfg);
2191out:
2192 return ret_val;
2193}
2194
2195/**
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002196 * igb_reset_hw_82580 - Reset hardware
2197 * @hw: pointer to the HW structure
2198 *
2199 * This resets function or entire device (all ports, etc.)
2200 * to a known state.
2201 **/
2202static s32 igb_reset_hw_82580(struct e1000_hw *hw)
2203{
2204 s32 ret_val = 0;
2205 /* BH SW mailbox bit in SW_FW_SYNC */
2206 u16 swmbsw_mask = E1000_SW_SYNCH_MB;
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002207 u32 ctrl;
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002208 bool global_device_reset = hw->dev_spec._82575.global_device_reset;
2209
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002210 hw->dev_spec._82575.global_device_reset = false;
2211
Carolyn Wybornya0483e22012-11-22 01:24:08 +00002212 /* due to hw errata, global device reset doesn't always
2213 * work on 82580
2214 */
2215 if (hw->mac.type == e1000_82580)
2216 global_device_reset = false;
2217
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002218 /* Get current control state. */
2219 ctrl = rd32(E1000_CTRL);
2220
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002221 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002222 * on the last TLP read/write transaction when MAC is reset.
2223 */
2224 ret_val = igb_disable_pcie_master(hw);
2225 if (ret_val)
2226 hw_dbg("PCI-E Master disable polling has failed.\n");
2227
2228 hw_dbg("Masking off all interrupts\n");
2229 wr32(E1000_IMC, 0xffffffff);
2230 wr32(E1000_RCTL, 0);
2231 wr32(E1000_TCTL, E1000_TCTL_PSP);
2232 wrfl();
2233
2234 msleep(10);
2235
2236 /* Determine whether or not a global dev reset is requested */
2237 if (global_device_reset &&
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002238 hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002239 global_device_reset = false;
2240
2241 if (global_device_reset &&
2242 !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
2243 ctrl |= E1000_CTRL_DEV_RST;
2244 else
2245 ctrl |= E1000_CTRL_RST;
2246
2247 wr32(E1000_CTRL, ctrl);
Carolyn Wyborny064b4332011-06-25 13:18:12 +00002248 wrfl();
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002249
2250 /* Add delay to insure DEV_RST has time to complete */
2251 if (global_device_reset)
2252 msleep(5);
2253
2254 ret_val = igb_get_auto_rd_done(hw);
2255 if (ret_val) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002256 /* When auto config read does not complete, do not
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002257 * return with an error. This can happen in situations
2258 * where there is no eeprom and prevents getting link.
2259 */
2260 hw_dbg("Auto Read Done did not complete\n");
2261 }
2262
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002263 /* clear global device reset status bit */
2264 wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
2265
2266 /* Clear any pending interrupt events. */
2267 wr32(E1000_IMC, 0xffffffff);
Akeem G Abodunrine5c33702013-06-06 01:31:09 +00002268 rd32(E1000_ICR);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002269
Nick Nunley08451e22010-07-26 13:15:29 +00002270 ret_val = igb_reset_mdicnfg_82580(hw);
2271 if (ret_val)
2272 hw_dbg("Could not reset MDICNFG based on EEPROM\n");
2273
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002274 /* Install any alternate MAC address into RAR0 */
2275 ret_val = igb_check_alt_mac_addr(hw);
2276
2277 /* Release semaphore */
2278 if (global_device_reset)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002279 hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002280
2281 return ret_val;
2282}
2283
2284/**
2285 * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
2286 * @data: data received by reading RXPBS register
2287 *
2288 * The 82580 uses a table based approach for packet buffer allocation sizes.
2289 * This function converts the retrieved value into the correct table value
2290 * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
2291 * 0x0 36 72 144 1 2 4 8 16
2292 * 0x8 35 70 140 rsv rsv rsv rsv rsv
2293 */
2294u16 igb_rxpbs_adjust_82580(u32 data)
2295{
2296 u16 ret_val = 0;
2297
2298 if (data < E1000_82580_RXPBS_TABLE_SIZE)
2299 ret_val = e1000_82580_rxpbs_table[data];
2300
2301 return ret_val;
2302}
2303
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002304/**
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002305 * igb_validate_nvm_checksum_with_offset - Validate EEPROM
2306 * checksum
2307 * @hw: pointer to the HW structure
2308 * @offset: offset in words of the checksum protected region
2309 *
2310 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2311 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2312 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002313static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
2314 u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002315{
2316 s32 ret_val = 0;
2317 u16 checksum = 0;
2318 u16 i, nvm_data;
2319
2320 for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
2321 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2322 if (ret_val) {
2323 hw_dbg("NVM Read Error\n");
2324 goto out;
2325 }
2326 checksum += nvm_data;
2327 }
2328
2329 if (checksum != (u16) NVM_SUM) {
2330 hw_dbg("NVM Checksum Invalid\n");
2331 ret_val = -E1000_ERR_NVM;
2332 goto out;
2333 }
2334
2335out:
2336 return ret_val;
2337}
2338
2339/**
2340 * igb_update_nvm_checksum_with_offset - Update EEPROM
2341 * checksum
2342 * @hw: pointer to the HW structure
2343 * @offset: offset in words of the checksum protected region
2344 *
2345 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2346 * up to the checksum. Then calculates the EEPROM checksum and writes the
2347 * value to the EEPROM.
2348 **/
Emil Tantilovbed45a62011-08-30 06:35:04 +00002349static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002350{
2351 s32 ret_val;
2352 u16 checksum = 0;
2353 u16 i, nvm_data;
2354
2355 for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
2356 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
2357 if (ret_val) {
2358 hw_dbg("NVM Read Error while updating checksum.\n");
2359 goto out;
2360 }
2361 checksum += nvm_data;
2362 }
2363 checksum = (u16) NVM_SUM - checksum;
2364 ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
2365 &checksum);
2366 if (ret_val)
2367 hw_dbg("NVM Write Error while updating checksum.\n");
2368
2369out:
2370 return ret_val;
2371}
2372
2373/**
2374 * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
2375 * @hw: pointer to the HW structure
2376 *
2377 * Calculates the EEPROM section checksum by reading/adding each word of
2378 * the EEPROM and then verifies that the sum of the EEPROM is
2379 * equal to 0xBABA.
2380 **/
2381static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
2382{
2383 s32 ret_val = 0;
2384 u16 eeprom_regions_count = 1;
2385 u16 j, nvm_data;
2386 u16 nvm_offset;
2387
2388 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2389 if (ret_val) {
2390 hw_dbg("NVM Read Error\n");
2391 goto out;
2392 }
2393
2394 if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
Stefan Assmann34a03262011-04-05 04:27:05 +00002395 /* if checksums compatibility bit is set validate checksums
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002396 * for all 4 ports.
2397 */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002398 eeprom_regions_count = 4;
2399 }
2400
2401 for (j = 0; j < eeprom_regions_count; j++) {
2402 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2403 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2404 nvm_offset);
2405 if (ret_val != 0)
2406 goto out;
2407 }
2408
2409out:
2410 return ret_val;
2411}
2412
2413/**
2414 * igb_update_nvm_checksum_82580 - Update EEPROM checksum
2415 * @hw: pointer to the HW structure
2416 *
2417 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2418 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2419 * checksum and writes the value to the EEPROM.
2420 **/
2421static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
2422{
2423 s32 ret_val;
2424 u16 j, nvm_data;
2425 u16 nvm_offset;
2426
2427 ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
2428 if (ret_val) {
2429 hw_dbg("NVM Read Error while updating checksum"
2430 " compatibility bit.\n");
2431 goto out;
2432 }
2433
2434 if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
2435 /* set compatibility bit to validate checksums appropriately */
2436 nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
2437 ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
2438 &nvm_data);
2439 if (ret_val) {
2440 hw_dbg("NVM Write Error while updating checksum"
2441 " compatibility bit.\n");
2442 goto out;
2443 }
2444 }
2445
2446 for (j = 0; j < 4; j++) {
2447 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2448 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2449 if (ret_val)
2450 goto out;
2451 }
2452
2453out:
2454 return ret_val;
2455}
2456
2457/**
2458 * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
2459 * @hw: pointer to the HW structure
2460 *
2461 * Calculates the EEPROM section checksum by reading/adding each word of
2462 * the EEPROM and then verifies that the sum of the EEPROM is
2463 * equal to 0xBABA.
2464 **/
2465static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
2466{
2467 s32 ret_val = 0;
2468 u16 j;
2469 u16 nvm_offset;
2470
2471 for (j = 0; j < 4; j++) {
2472 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2473 ret_val = igb_validate_nvm_checksum_with_offset(hw,
2474 nvm_offset);
2475 if (ret_val != 0)
2476 goto out;
2477 }
2478
2479out:
2480 return ret_val;
2481}
2482
2483/**
2484 * igb_update_nvm_checksum_i350 - Update EEPROM checksum
2485 * @hw: pointer to the HW structure
2486 *
2487 * Updates the EEPROM section checksums for all 4 ports by reading/adding
2488 * each word of the EEPROM up to the checksum. Then calculates the EEPROM
2489 * checksum and writes the value to the EEPROM.
2490 **/
2491static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
2492{
2493 s32 ret_val = 0;
2494 u16 j;
2495 u16 nvm_offset;
2496
2497 for (j = 0; j < 4; j++) {
2498 nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
2499 ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
2500 if (ret_val != 0)
2501 goto out;
2502 }
2503
2504out:
2505 return ret_val;
2506}
Stefan Assmann34a03262011-04-05 04:27:05 +00002507
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002508/**
Matthew Vick87371b92013-02-21 03:32:52 +00002509 * __igb_access_emi_reg - Read/write EMI register
2510 * @hw: pointer to the HW structure
2511 * @addr: EMI address to program
2512 * @data: pointer to value to read/write from/to the EMI address
2513 * @read: boolean flag to indicate read or write
2514 **/
2515static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
2516 u16 *data, bool read)
2517{
2518 s32 ret_val = E1000_SUCCESS;
2519
2520 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
2521 if (ret_val)
2522 return ret_val;
2523
2524 if (read)
2525 ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
2526 else
2527 ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
2528
2529 return ret_val;
2530}
2531
2532/**
2533 * igb_read_emi_reg - Read Extended Management Interface register
2534 * @hw: pointer to the HW structure
2535 * @addr: EMI address to program
2536 * @data: value to be read from the EMI address
2537 **/
2538s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
2539{
2540 return __igb_access_emi_reg(hw, addr, data, true);
2541}
2542
2543/**
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002544 * igb_set_eee_i350 - Enable/disable EEE support
2545 * @hw: pointer to the HW structure
2546 *
2547 * Enable/disable EEE based on setting in dev_spec structure.
2548 *
2549 **/
2550s32 igb_set_eee_i350(struct e1000_hw *hw)
2551{
2552 s32 ret_val = 0;
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002553 u32 ipcnfg, eeer;
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002554
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002555 if ((hw->mac.type < e1000_i350) ||
2556 (hw->phy.media_type != e1000_media_type_copper))
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002557 goto out;
2558 ipcnfg = rd32(E1000_IPCNFG);
2559 eeer = rd32(E1000_EEER);
2560
2561 /* enable or disable per user setting */
2562 if (!(hw->dev_spec._82575.eee_disable)) {
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002563 u32 eee_su = rd32(E1000_EEE_SU);
2564
2565 ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN);
2566 eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002567 E1000_EEER_LPI_FC);
2568
Carolyn Wyborny40b20122012-10-19 05:31:43 +00002569 /* This bit should not be set in normal operation. */
2570 if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
2571 hw_dbg("LPI Clock Stop Bit should not be set!\n");
2572
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002573 } else {
2574 ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
2575 E1000_IPCNFG_EEE_100M_AN);
2576 eeer &= ~(E1000_EEER_TX_LPI_EN |
2577 E1000_EEER_RX_LPI_EN |
2578 E1000_EEER_LPI_FC);
2579 }
2580 wr32(E1000_IPCNFG, ipcnfg);
2581 wr32(E1000_EEER, eeer);
Akeem G. Abodunrine5461112012-09-06 01:28:31 +00002582 rd32(E1000_IPCNFG);
2583 rd32(E1000_EEER);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002584out:
2585
2586 return ret_val;
2587}
Carolyn Wyborny4322e562011-03-11 20:43:18 -08002588
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002589/**
2590 * igb_set_eee_i354 - Enable/disable EEE support
2591 * @hw: pointer to the HW structure
2592 *
2593 * Enable/disable EEE legacy mode based on setting in dev_spec structure.
2594 *
2595 **/
2596s32 igb_set_eee_i354(struct e1000_hw *hw)
2597{
2598 struct e1000_phy_info *phy = &hw->phy;
2599 s32 ret_val = 0;
2600 u16 phy_data;
2601
2602 if ((hw->phy.media_type != e1000_media_type_copper) ||
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002603 (phy->id != M88E1543_E_PHY_ID))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002604 goto out;
2605
2606 if (!hw->dev_spec._82575.eee_disable) {
2607 /* Switch to PHY page 18. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002608 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002609 if (ret_val)
2610 goto out;
2611
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002612 ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002613 &phy_data);
2614 if (ret_val)
2615 goto out;
2616
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002617 phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
2618 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002619 phy_data);
2620 if (ret_val)
2621 goto out;
2622
2623 /* Return the PHY to page 0. */
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002624 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002625 if (ret_val)
2626 goto out;
2627
2628 /* Turn on EEE advertisement. */
2629 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2630 E1000_EEE_ADV_DEV_I354,
2631 &phy_data);
2632 if (ret_val)
2633 goto out;
2634
2635 phy_data |= E1000_EEE_ADV_100_SUPPORTED |
2636 E1000_EEE_ADV_1000_SUPPORTED;
2637 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2638 E1000_EEE_ADV_DEV_I354,
2639 phy_data);
2640 } else {
2641 /* Turn off EEE advertisement. */
2642 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2643 E1000_EEE_ADV_DEV_I354,
2644 &phy_data);
2645 if (ret_val)
2646 goto out;
2647
2648 phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
2649 E1000_EEE_ADV_1000_SUPPORTED);
2650 ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
2651 E1000_EEE_ADV_DEV_I354,
2652 phy_data);
2653 }
2654
2655out:
2656 return ret_val;
2657}
2658
2659/**
2660 * igb_get_eee_status_i354 - Get EEE status
2661 * @hw: pointer to the HW structure
2662 * @status: EEE status
2663 *
2664 * Get EEE status by guessing based on whether Tx or Rx LPI indications have
2665 * been received.
2666 **/
2667s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
2668{
2669 struct e1000_phy_info *phy = &hw->phy;
2670 s32 ret_val = 0;
2671 u16 phy_data;
2672
2673 /* Check if EEE is supported on this device. */
2674 if ((hw->phy.media_type != e1000_media_type_copper) ||
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00002675 (phy->id != M88E1543_E_PHY_ID))
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002676 goto out;
2677
2678 ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
2679 E1000_PCS_STATUS_DEV_I354,
2680 &phy_data);
2681 if (ret_val)
2682 goto out;
2683
2684 *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
2685 E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
2686
2687out:
2688 return ret_val;
2689}
2690
Carolyn Wybornye4288932012-12-07 03:01:42 +00002691static const u8 e1000_emc_temp_data[4] = {
2692 E1000_EMC_INTERNAL_DATA,
2693 E1000_EMC_DIODE1_DATA,
2694 E1000_EMC_DIODE2_DATA,
2695 E1000_EMC_DIODE3_DATA
2696};
2697static const u8 e1000_emc_therm_limit[4] = {
2698 E1000_EMC_INTERNAL_THERM_LIMIT,
2699 E1000_EMC_DIODE1_THERM_LIMIT,
2700 E1000_EMC_DIODE2_THERM_LIMIT,
2701 E1000_EMC_DIODE3_THERM_LIMIT
2702};
2703
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002704/**
2705 * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
Carolyn Wybornye4288932012-12-07 03:01:42 +00002706 * @hw: pointer to hardware structure
2707 *
2708 * Updates the temperatures in mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002709 **/
Carolyn Wybornye4288932012-12-07 03:01:42 +00002710s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
2711{
2712 s32 status = E1000_SUCCESS;
2713 u16 ets_offset;
2714 u16 ets_cfg;
2715 u16 ets_sensor;
2716 u8 num_sensors;
2717 u8 sensor_index;
2718 u8 sensor_location;
2719 u8 i;
2720 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2721
2722 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2723 return E1000_NOT_IMPLEMENTED;
2724
2725 data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
2726
2727 /* Return the internal sensor only if ETS is unsupported */
2728 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2729 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2730 return status;
2731
2732 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2733 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2734 != NVM_ETS_TYPE_EMC)
2735 return E1000_NOT_IMPLEMENTED;
2736
2737 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2738 if (num_sensors > E1000_MAX_SENSORS)
2739 num_sensors = E1000_MAX_SENSORS;
2740
2741 for (i = 1; i < num_sensors; i++) {
2742 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2743 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2744 NVM_ETS_DATA_INDEX_SHIFT);
2745 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2746 NVM_ETS_DATA_LOC_SHIFT);
2747
2748 if (sensor_location != 0)
2749 hw->phy.ops.read_i2c_byte(hw,
2750 e1000_emc_temp_data[sensor_index],
2751 E1000_I2C_THERMAL_SENSOR_ADDR,
2752 &data->sensor[i].temp);
2753 }
2754 return status;
2755}
2756
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002757/**
2758 * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
Carolyn Wybornye4288932012-12-07 03:01:42 +00002759 * @hw: pointer to hardware structure
2760 *
2761 * Sets the thermal sensor thresholds according to the NVM map
2762 * and save off the threshold and location values into mac.thermal_sensor_data
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002763 **/
Carolyn Wybornye4288932012-12-07 03:01:42 +00002764s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
2765{
2766 s32 status = E1000_SUCCESS;
2767 u16 ets_offset;
2768 u16 ets_cfg;
2769 u16 ets_sensor;
2770 u8 low_thresh_delta;
2771 u8 num_sensors;
2772 u8 sensor_index;
2773 u8 sensor_location;
2774 u8 therm_limit;
2775 u8 i;
2776 struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2777
2778 if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
2779 return E1000_NOT_IMPLEMENTED;
2780
2781 memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
2782
2783 data->sensor[0].location = 0x1;
2784 data->sensor[0].caution_thresh =
2785 (rd32(E1000_THHIGHTC) & 0xFF);
2786 data->sensor[0].max_op_thresh =
2787 (rd32(E1000_THLOWTC) & 0xFF);
2788
2789 /* Return the internal sensor only if ETS is unsupported */
2790 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
2791 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
2792 return status;
2793
2794 hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
2795 if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
2796 != NVM_ETS_TYPE_EMC)
2797 return E1000_NOT_IMPLEMENTED;
2798
2799 low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
2800 NVM_ETS_LTHRES_DELTA_SHIFT);
2801 num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
2802
2803 for (i = 1; i <= num_sensors; i++) {
2804 hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
2805 sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
2806 NVM_ETS_DATA_INDEX_SHIFT);
2807 sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
2808 NVM_ETS_DATA_LOC_SHIFT);
2809 therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
2810
2811 hw->phy.ops.write_i2c_byte(hw,
2812 e1000_emc_therm_limit[sensor_index],
2813 E1000_I2C_THERMAL_SENSOR_ADDR,
2814 therm_limit);
2815
2816 if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
2817 data->sensor[i].location = sensor_location;
2818 data->sensor[i].caution_thresh = therm_limit;
2819 data->sensor[i].max_op_thresh = therm_limit -
2820 low_thresh_delta;
2821 }
2822 }
2823 return status;
2824}
2825
Auke Kok9d5c8242008-01-24 02:22:38 -08002826static struct e1000_mac_operations e1000_mac_ops_82575 = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002827 .init_hw = igb_init_hw_82575,
2828 .check_for_link = igb_check_for_link_82575,
Alexander Duyck2d064c02008-07-08 15:10:12 -07002829 .rar_set = igb_rar_set,
Auke Kok9d5c8242008-01-24 02:22:38 -08002830 .read_mac_addr = igb_read_mac_addr_82575,
Akeem G Abodunrinf6878e392013-08-28 02:23:09 +00002831 .get_speed_and_duplex = igb_get_link_up_info_82575,
Carolyn Wybornye4288932012-12-07 03:01:42 +00002832#ifdef CONFIG_IGB_HWMON
2833 .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
2834 .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
2835#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08002836};
2837
2838static struct e1000_phy_operations e1000_phy_ops_82575 = {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002839 .acquire = igb_acquire_phy_82575,
Auke Kok9d5c8242008-01-24 02:22:38 -08002840 .get_cfg_done = igb_get_cfg_done_82575,
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002841 .release = igb_release_phy_82575,
Carolyn Wyborny441fc6f2012-12-07 03:00:30 +00002842 .write_i2c_byte = igb_write_i2c_byte,
2843 .read_i2c_byte = igb_read_i2c_byte,
Auke Kok9d5c8242008-01-24 02:22:38 -08002844};
2845
2846static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
Alexander Duyck312c75a2009-02-06 23:17:47 +00002847 .acquire = igb_acquire_nvm_82575,
2848 .read = igb_read_nvm_eerd,
2849 .release = igb_release_nvm_82575,
2850 .write = igb_write_nvm_spi,
Auke Kok9d5c8242008-01-24 02:22:38 -08002851};
2852
2853const struct e1000_info e1000_82575_info = {
2854 .get_invariants = igb_get_invariants_82575,
2855 .mac_ops = &e1000_mac_ops_82575,
2856 .phy_ops = &e1000_phy_ops_82575,
2857 .nvm_ops = &e1000_nvm_ops_82575,
2858};
2859