]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/igb/e1000_82575.c
igb: add support for another dual port 82576 non-security nic
[linux-2.6-omap-h63xx.git] / drivers / net / igb / e1000_82575.c
1 /*******************************************************************************
2
3   Intel(R) Gigabit Ethernet Linux driver
4   Copyright(c) 2007-2009 Intel Corporation.
5
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
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/if_ether.h>
35
36 #include "e1000_mac.h"
37 #include "e1000_82575.h"
38
39 static s32  igb_get_invariants_82575(struct e1000_hw *);
40 static s32  igb_acquire_phy_82575(struct e1000_hw *);
41 static void igb_release_phy_82575(struct e1000_hw *);
42 static s32  igb_acquire_nvm_82575(struct e1000_hw *);
43 static void igb_release_nvm_82575(struct e1000_hw *);
44 static s32  igb_check_for_link_82575(struct e1000_hw *);
45 static s32  igb_get_cfg_done_82575(struct e1000_hw *);
46 static s32  igb_init_hw_82575(struct e1000_hw *);
47 static s32  igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
48 static s32  igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
49 static s32  igb_reset_hw_82575(struct e1000_hw *);
50 static s32  igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
51 static s32  igb_setup_copper_link_82575(struct e1000_hw *);
52 static s32  igb_setup_fiber_serdes_link_82575(struct e1000_hw *);
53 static s32  igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
54 static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
55 static s32  igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
56 static s32  igb_configure_pcs_link_82575(struct e1000_hw *);
57 static s32  igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
58                                                  u16 *);
59 static s32  igb_get_phy_id_82575(struct e1000_hw *);
60 static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
61 static bool igb_sgmii_active_82575(struct e1000_hw *);
62 static s32  igb_reset_init_script_82575(struct e1000_hw *);
63 static s32  igb_read_mac_addr_82575(struct e1000_hw *);
64
65 static s32 igb_get_invariants_82575(struct e1000_hw *hw)
66 {
67         struct e1000_phy_info *phy = &hw->phy;
68         struct e1000_nvm_info *nvm = &hw->nvm;
69         struct e1000_mac_info *mac = &hw->mac;
70         struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
71         u32 eecd;
72         s32 ret_val;
73         u16 size;
74         u32 ctrl_ext = 0;
75
76         switch (hw->device_id) {
77         case E1000_DEV_ID_82575EB_COPPER:
78         case E1000_DEV_ID_82575EB_FIBER_SERDES:
79         case E1000_DEV_ID_82575GB_QUAD_COPPER:
80                 mac->type = e1000_82575;
81                 break;
82         case E1000_DEV_ID_82576:
83         case E1000_DEV_ID_82576_NS:
84         case E1000_DEV_ID_82576_FIBER:
85         case E1000_DEV_ID_82576_SERDES:
86                 mac->type = e1000_82576;
87                 break;
88         default:
89                 return -E1000_ERR_MAC_INIT;
90                 break;
91         }
92
93         /* Set media type */
94         /*
95          * The 82575 uses bits 22:23 for link mode. The mode can be changed
96          * based on the EEPROM. We cannot rely upon device ID. There
97          * is no distinguishable difference between fiber and internal
98          * SerDes mode on the 82575. There can be an external PHY attached
99          * on the SGMII interface. For this, we'll set sgmii_active to true.
100          */
101         phy->media_type = e1000_media_type_copper;
102         dev_spec->sgmii_active = false;
103
104         ctrl_ext = rd32(E1000_CTRL_EXT);
105         if ((ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) ==
106             E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES) {
107                 hw->phy.media_type = e1000_media_type_internal_serdes;
108                 ctrl_ext |= E1000_CTRL_I2C_ENA;
109         } else if (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII) {
110                 dev_spec->sgmii_active = true;
111                 ctrl_ext |= E1000_CTRL_I2C_ENA;
112         } else {
113                 ctrl_ext &= ~E1000_CTRL_I2C_ENA;
114         }
115         wr32(E1000_CTRL_EXT, ctrl_ext);
116
117         /* Set mta register count */
118         mac->mta_reg_count = 128;
119         /* Set rar entry count */
120         mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
121         if (mac->type == e1000_82576)
122                 mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
123         /* Set if part includes ASF firmware */
124         mac->asf_firmware_present = true;
125         /* Set if manageability features are enabled. */
126         mac->arc_subsystem_valid =
127                 (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
128                         ? true : false;
129
130         /* physical interface link setup */
131         mac->ops.setup_physical_interface =
132                 (hw->phy.media_type == e1000_media_type_copper)
133                         ? igb_setup_copper_link_82575
134                         : igb_setup_fiber_serdes_link_82575;
135
136         /* NVM initialization */
137         eecd = rd32(E1000_EECD);
138
139         nvm->opcode_bits        = 8;
140         nvm->delay_usec         = 1;
141         switch (nvm->override) {
142         case e1000_nvm_override_spi_large:
143                 nvm->page_size    = 32;
144                 nvm->address_bits = 16;
145                 break;
146         case e1000_nvm_override_spi_small:
147                 nvm->page_size    = 8;
148                 nvm->address_bits = 8;
149                 break;
150         default:
151                 nvm->page_size    = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
152                 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
153                 break;
154         }
155
156         nvm->type = e1000_nvm_eeprom_spi;
157
158         size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
159                      E1000_EECD_SIZE_EX_SHIFT);
160
161         /*
162          * Added to a constant, "size" becomes the left-shift value
163          * for setting word_size.
164          */
165         size += NVM_WORD_SIZE_BASE_SHIFT;
166
167         /* EEPROM access above 16k is unsupported */
168         if (size > 14)
169                 size = 14;
170         nvm->word_size = 1 << size;
171
172         /* setup PHY parameters */
173         if (phy->media_type != e1000_media_type_copper) {
174                 phy->type = e1000_phy_none;
175                 return 0;
176         }
177
178         phy->autoneg_mask        = AUTONEG_ADVERTISE_SPEED_DEFAULT;
179         phy->reset_delay_us      = 100;
180
181         /* PHY function pointers */
182         if (igb_sgmii_active_82575(hw)) {
183                 phy->ops.reset              = igb_phy_hw_reset_sgmii_82575;
184                 phy->ops.read_reg           = igb_read_phy_reg_sgmii_82575;
185                 phy->ops.write_reg          = igb_write_phy_reg_sgmii_82575;
186         } else {
187                 phy->ops.reset              = igb_phy_hw_reset;
188                 phy->ops.read_reg           = igb_read_phy_reg_igp;
189                 phy->ops.write_reg          = igb_write_phy_reg_igp;
190         }
191
192         /* Set phy->phy_addr and phy->id. */
193         ret_val = igb_get_phy_id_82575(hw);
194         if (ret_val)
195                 return ret_val;
196
197         /* Verify phy id and set remaining function pointers */
198         switch (phy->id) {
199         case M88E1111_I_PHY_ID:
200                 phy->type                   = e1000_phy_m88;
201                 phy->ops.get_phy_info       = igb_get_phy_info_m88;
202                 phy->ops.get_cable_length   = igb_get_cable_length_m88;
203                 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
204                 break;
205         case IGP03E1000_E_PHY_ID:
206                 phy->type                   = e1000_phy_igp_3;
207                 phy->ops.get_phy_info       = igb_get_phy_info_igp;
208                 phy->ops.get_cable_length   = igb_get_cable_length_igp_2;
209                 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
210                 phy->ops.set_d0_lplu_state  = igb_set_d0_lplu_state_82575;
211                 phy->ops.set_d3_lplu_state  = igb_set_d3_lplu_state;
212                 break;
213         default:
214                 return -E1000_ERR_PHY;
215         }
216
217         /* if 82576 then initialize mailbox parameters */
218         if (mac->type == e1000_82576)
219                 igb_init_mbx_params_pf(hw);
220
221         return 0;
222 }
223
224 /**
225  *  igb_acquire_phy_82575 - Acquire rights to access PHY
226  *  @hw: pointer to the HW structure
227  *
228  *  Acquire access rights to the correct PHY.  This is a
229  *  function pointer entry point called by the api module.
230  **/
231 static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
232 {
233         u16 mask;
234
235         mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
236
237         return igb_acquire_swfw_sync_82575(hw, mask);
238 }
239
240 /**
241  *  igb_release_phy_82575 - Release rights to access PHY
242  *  @hw: pointer to the HW structure
243  *
244  *  A wrapper to release access rights to the correct PHY.  This is a
245  *  function pointer entry point called by the api module.
246  **/
247 static void igb_release_phy_82575(struct e1000_hw *hw)
248 {
249         u16 mask;
250
251         mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
252         igb_release_swfw_sync_82575(hw, mask);
253 }
254
255 /**
256  *  igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
257  *  @hw: pointer to the HW structure
258  *  @offset: register offset to be read
259  *  @data: pointer to the read data
260  *
261  *  Reads the PHY register at offset using the serial gigabit media independent
262  *  interface and stores the retrieved information in data.
263  **/
264 static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
265                                           u16 *data)
266 {
267         struct e1000_phy_info *phy = &hw->phy;
268         u32 i, i2ccmd = 0;
269
270         if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
271                 hw_dbg("PHY Address %u is out of range\n", offset);
272                 return -E1000_ERR_PARAM;
273         }
274
275         /*
276          * Set up Op-code, Phy Address, and register address in the I2CCMD
277          * register.  The MAC will take care of interfacing with the
278          * PHY to retrieve the desired data.
279          */
280         i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
281                   (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
282                   (E1000_I2CCMD_OPCODE_READ));
283
284         wr32(E1000_I2CCMD, i2ccmd);
285
286         /* Poll the ready bit to see if the I2C read completed */
287         for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
288                 udelay(50);
289                 i2ccmd = rd32(E1000_I2CCMD);
290                 if (i2ccmd & E1000_I2CCMD_READY)
291                         break;
292         }
293         if (!(i2ccmd & E1000_I2CCMD_READY)) {
294                 hw_dbg("I2CCMD Read did not complete\n");
295                 return -E1000_ERR_PHY;
296         }
297         if (i2ccmd & E1000_I2CCMD_ERROR) {
298                 hw_dbg("I2CCMD Error bit set\n");
299                 return -E1000_ERR_PHY;
300         }
301
302         /* Need to byte-swap the 16-bit value. */
303         *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
304
305         return 0;
306 }
307
308 /**
309  *  igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
310  *  @hw: pointer to the HW structure
311  *  @offset: register offset to write to
312  *  @data: data to write at register offset
313  *
314  *  Writes the data to PHY register at the offset using the serial gigabit
315  *  media independent interface.
316  **/
317 static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
318                                            u16 data)
319 {
320         struct e1000_phy_info *phy = &hw->phy;
321         u32 i, i2ccmd = 0;
322         u16 phy_data_swapped;
323
324         if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
325                 hw_dbg("PHY Address %d is out of range\n", offset);
326                 return -E1000_ERR_PARAM;
327         }
328
329         /* Swap the data bytes for the I2C interface */
330         phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
331
332         /*
333          * Set up Op-code, Phy Address, and register address in the I2CCMD
334          * register.  The MAC will take care of interfacing with the
335          * PHY to retrieve the desired data.
336          */
337         i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
338                   (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
339                   E1000_I2CCMD_OPCODE_WRITE |
340                   phy_data_swapped);
341
342         wr32(E1000_I2CCMD, i2ccmd);
343
344         /* Poll the ready bit to see if the I2C read completed */
345         for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
346                 udelay(50);
347                 i2ccmd = rd32(E1000_I2CCMD);
348                 if (i2ccmd & E1000_I2CCMD_READY)
349                         break;
350         }
351         if (!(i2ccmd & E1000_I2CCMD_READY)) {
352                 hw_dbg("I2CCMD Write did not complete\n");
353                 return -E1000_ERR_PHY;
354         }
355         if (i2ccmd & E1000_I2CCMD_ERROR) {
356                 hw_dbg("I2CCMD Error bit set\n");
357                 return -E1000_ERR_PHY;
358         }
359
360         return 0;
361 }
362
363 /**
364  *  igb_get_phy_id_82575 - Retrieve PHY addr and id
365  *  @hw: pointer to the HW structure
366  *
367  *  Retrieves the PHY address and ID for both PHY's which do and do not use
368  *  sgmi interface.
369  **/
370 static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
371 {
372         struct e1000_phy_info *phy = &hw->phy;
373         s32  ret_val = 0;
374         u16 phy_id;
375
376         /*
377          * For SGMII PHYs, we try the list of possible addresses until
378          * we find one that works.  For non-SGMII PHYs
379          * (e.g. integrated copper PHYs), an address of 1 should
380          * work.  The result of this function should mean phy->phy_addr
381          * and phy->id are set correctly.
382          */
383         if (!(igb_sgmii_active_82575(hw))) {
384                 phy->addr = 1;
385                 ret_val = igb_get_phy_id(hw);
386                 goto out;
387         }
388
389         /*
390          * The address field in the I2CCMD register is 3 bits and 0 is invalid.
391          * Therefore, we need to test 1-7
392          */
393         for (phy->addr = 1; phy->addr < 8; phy->addr++) {
394                 ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
395                 if (ret_val == 0) {
396                         hw_dbg("Vendor ID 0x%08X read at address %u\n",
397                                phy_id, phy->addr);
398                         /*
399                          * At the time of this writing, The M88 part is
400                          * the only supported SGMII PHY product.
401                          */
402                         if (phy_id == M88_VENDOR)
403                                 break;
404                 } else {
405                         hw_dbg("PHY address %u was unreadable\n", phy->addr);
406                 }
407         }
408
409         /* A valid PHY type couldn't be found. */
410         if (phy->addr == 8) {
411                 phy->addr = 0;
412                 ret_val = -E1000_ERR_PHY;
413                 goto out;
414         }
415
416         ret_val = igb_get_phy_id(hw);
417
418 out:
419         return ret_val;
420 }
421
422 /**
423  *  igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
424  *  @hw: pointer to the HW structure
425  *
426  *  Resets the PHY using the serial gigabit media independent interface.
427  **/
428 static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
429 {
430         s32 ret_val;
431
432         /*
433          * This isn't a true "hard" reset, but is the only reset
434          * available to us at this time.
435          */
436
437         hw_dbg("Soft resetting SGMII attached PHY...\n");
438
439         /*
440          * SFP documentation requires the following to configure the SPF module
441          * to work on SGMII.  No further documentation is given.
442          */
443         ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
444         if (ret_val)
445                 goto out;
446
447         ret_val = igb_phy_sw_reset(hw);
448
449 out:
450         return ret_val;
451 }
452
453 /**
454  *  igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
455  *  @hw: pointer to the HW structure
456  *  @active: true to enable LPLU, false to disable
457  *
458  *  Sets the LPLU D0 state according to the active flag.  When
459  *  activating LPLU this function also disables smart speed
460  *  and vice versa.  LPLU will not be activated unless the
461  *  device autonegotiation advertisement meets standards of
462  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
463  *  This is a function pointer entry point only called by
464  *  PHY setup routines.
465  **/
466 static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
467 {
468         struct e1000_phy_info *phy = &hw->phy;
469         s32 ret_val;
470         u16 data;
471
472         ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
473         if (ret_val)
474                 goto out;
475
476         if (active) {
477                 data |= IGP02E1000_PM_D0_LPLU;
478                 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
479                                                  data);
480                 if (ret_val)
481                         goto out;
482
483                 /* When LPLU is enabled, we should disable SmartSpeed */
484                 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
485                                                 &data);
486                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
487                 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
488                                                  data);
489                 if (ret_val)
490                         goto out;
491         } else {
492                 data &= ~IGP02E1000_PM_D0_LPLU;
493                 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
494                                                  data);
495                 /*
496                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
497                  * during Dx states where the power conservation is most
498                  * important.  During driver activity we should enable
499                  * SmartSpeed, so performance is maintained.
500                  */
501                 if (phy->smart_speed == e1000_smart_speed_on) {
502                         ret_val = phy->ops.read_reg(hw,
503                                         IGP01E1000_PHY_PORT_CONFIG, &data);
504                         if (ret_val)
505                                 goto out;
506
507                         data |= IGP01E1000_PSCFR_SMART_SPEED;
508                         ret_val = phy->ops.write_reg(hw,
509                                         IGP01E1000_PHY_PORT_CONFIG, data);
510                         if (ret_val)
511                                 goto out;
512                 } else if (phy->smart_speed == e1000_smart_speed_off) {
513                         ret_val = phy->ops.read_reg(hw,
514                                         IGP01E1000_PHY_PORT_CONFIG, &data);
515                         if (ret_val)
516                                 goto out;
517
518                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
519                         ret_val = phy->ops.write_reg(hw,
520                                         IGP01E1000_PHY_PORT_CONFIG, data);
521                         if (ret_val)
522                                 goto out;
523                 }
524         }
525
526 out:
527         return ret_val;
528 }
529
530 /**
531  *  igb_acquire_nvm_82575 - Request for access to EEPROM
532  *  @hw: pointer to the HW structure
533  *
534  *  Acquire the necessary semaphores for exclusive access to the EEPROM.
535  *  Set the EEPROM access request bit and wait for EEPROM access grant bit.
536  *  Return successful if access grant bit set, else clear the request for
537  *  EEPROM access and return -E1000_ERR_NVM (-1).
538  **/
539 static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
540 {
541         s32 ret_val;
542
543         ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
544         if (ret_val)
545                 goto out;
546
547         ret_val = igb_acquire_nvm(hw);
548
549         if (ret_val)
550                 igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
551
552 out:
553         return ret_val;
554 }
555
556 /**
557  *  igb_release_nvm_82575 - Release exclusive access to EEPROM
558  *  @hw: pointer to the HW structure
559  *
560  *  Stop any current commands to the EEPROM and clear the EEPROM request bit,
561  *  then release the semaphores acquired.
562  **/
563 static void igb_release_nvm_82575(struct e1000_hw *hw)
564 {
565         igb_release_nvm(hw);
566         igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
567 }
568
569 /**
570  *  igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
571  *  @hw: pointer to the HW structure
572  *  @mask: specifies which semaphore to acquire
573  *
574  *  Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
575  *  will also specify which port we're acquiring the lock for.
576  **/
577 static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
578 {
579         u32 swfw_sync;
580         u32 swmask = mask;
581         u32 fwmask = mask << 16;
582         s32 ret_val = 0;
583         s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
584
585         while (i < timeout) {
586                 if (igb_get_hw_semaphore(hw)) {
587                         ret_val = -E1000_ERR_SWFW_SYNC;
588                         goto out;
589                 }
590
591                 swfw_sync = rd32(E1000_SW_FW_SYNC);
592                 if (!(swfw_sync & (fwmask | swmask)))
593                         break;
594
595                 /*
596                  * Firmware currently using resource (fwmask)
597                  * or other software thread using resource (swmask)
598                  */
599                 igb_put_hw_semaphore(hw);
600                 mdelay(5);
601                 i++;
602         }
603
604         if (i == timeout) {
605                 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
606                 ret_val = -E1000_ERR_SWFW_SYNC;
607                 goto out;
608         }
609
610         swfw_sync |= swmask;
611         wr32(E1000_SW_FW_SYNC, swfw_sync);
612
613         igb_put_hw_semaphore(hw);
614
615 out:
616         return ret_val;
617 }
618
619 /**
620  *  igb_release_swfw_sync_82575 - Release SW/FW semaphore
621  *  @hw: pointer to the HW structure
622  *  @mask: specifies which semaphore to acquire
623  *
624  *  Release the SW/FW semaphore used to access the PHY or NVM.  The mask
625  *  will also specify which port we're releasing the lock for.
626  **/
627 static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
628 {
629         u32 swfw_sync;
630
631         while (igb_get_hw_semaphore(hw) != 0);
632         /* Empty */
633
634         swfw_sync = rd32(E1000_SW_FW_SYNC);
635         swfw_sync &= ~mask;
636         wr32(E1000_SW_FW_SYNC, swfw_sync);
637
638         igb_put_hw_semaphore(hw);
639 }
640
641 /**
642  *  igb_get_cfg_done_82575 - Read config done bit
643  *  @hw: pointer to the HW structure
644  *
645  *  Read the management control register for the config done bit for
646  *  completion status.  NOTE: silicon which is EEPROM-less will fail trying
647  *  to read the config done bit, so an error is *ONLY* logged and returns
648  *  0.  If we were to return with error, EEPROM-less silicon
649  *  would not be able to be reset or change link.
650  **/
651 static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
652 {
653         s32 timeout = PHY_CFG_TIMEOUT;
654         s32 ret_val = 0;
655         u32 mask = E1000_NVM_CFG_DONE_PORT_0;
656
657         if (hw->bus.func == 1)
658                 mask = E1000_NVM_CFG_DONE_PORT_1;
659
660         while (timeout) {
661                 if (rd32(E1000_EEMNGCTL) & mask)
662                         break;
663                 msleep(1);
664                 timeout--;
665         }
666         if (!timeout)
667                 hw_dbg("MNG configuration cycle has not completed.\n");
668
669         /* If EEPROM is not marked present, init the PHY manually */
670         if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
671             (hw->phy.type == e1000_phy_igp_3))
672                 igb_phy_init_script_igp3(hw);
673
674         return ret_val;
675 }
676
677 /**
678  *  igb_check_for_link_82575 - Check for link
679  *  @hw: pointer to the HW structure
680  *
681  *  If sgmii is enabled, then use the pcs register to determine link, otherwise
682  *  use the generic interface for determining link.
683  **/
684 static s32 igb_check_for_link_82575(struct e1000_hw *hw)
685 {
686         s32 ret_val;
687         u16 speed, duplex;
688
689         /* SGMII link check is done through the PCS register. */
690         if ((hw->phy.media_type != e1000_media_type_copper) ||
691             (igb_sgmii_active_82575(hw))) {
692                 ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
693                                                              &duplex);
694                 /*
695                  * Use this flag to determine if link needs to be checked or
696                  * not.  If  we have link clear the flag so that we do not
697                  * continue to check for link.
698                  */
699                 hw->mac.get_link_status = !hw->mac.serdes_has_link;
700         } else {
701                 ret_val = igb_check_for_copper_link(hw);
702         }
703
704         return ret_val;
705 }
706 /**
707  *  igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
708  *  @hw: pointer to the HW structure
709  *  @speed: stores the current speed
710  *  @duplex: stores the current duplex
711  *
712  *  Using the physical coding sub-layer (PCS), retrieve the current speed and
713  *  duplex, then store the values in the pointers provided.
714  **/
715 static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
716                                                 u16 *duplex)
717 {
718         struct e1000_mac_info *mac = &hw->mac;
719         u32 pcs;
720
721         /* Set up defaults for the return values of this function */
722         mac->serdes_has_link = false;
723         *speed = 0;
724         *duplex = 0;
725
726         /*
727          * Read the PCS Status register for link state. For non-copper mode,
728          * the status register is not accurate. The PCS status register is
729          * used instead.
730          */
731         pcs = rd32(E1000_PCS_LSTAT);
732
733         /*
734          * The link up bit determines when link is up on autoneg. The sync ok
735          * gets set once both sides sync up and agree upon link. Stable link
736          * can be determined by checking for both link up and link sync ok
737          */
738         if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
739                 mac->serdes_has_link = true;
740
741                 /* Detect and store PCS speed */
742                 if (pcs & E1000_PCS_LSTS_SPEED_1000) {
743                         *speed = SPEED_1000;
744                 } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
745                         *speed = SPEED_100;
746                 } else {
747                         *speed = SPEED_10;
748                 }
749
750                 /* Detect and store PCS duplex */
751                 if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
752                         *duplex = FULL_DUPLEX;
753                 } else {
754                         *duplex = HALF_DUPLEX;
755                 }
756         }
757
758         return 0;
759 }
760
761 /**
762  *  igb_init_rx_addrs_82575 - Initialize receive address's
763  *  @hw: pointer to the HW structure
764  *  @rar_count: receive address registers
765  *
766  *  Setups the receive address registers by setting the base receive address
767  *  register to the devices MAC address and clearing all the other receive
768  *  address registers to 0.
769  **/
770 static void igb_init_rx_addrs_82575(struct e1000_hw *hw, u16 rar_count)
771 {
772         u32 i;
773         u8 addr[6] = {0,0,0,0,0,0};
774         /*
775          * This function is essentially the same as that of
776          * e1000_init_rx_addrs_generic. However it also takes care
777          * of the special case where the register offset of the
778          * second set of RARs begins elsewhere. This is implicitly taken care by
779          * function e1000_rar_set_generic.
780          */
781
782         hw_dbg("e1000_init_rx_addrs_82575");
783
784         /* Setup the receive address */
785         hw_dbg("Programming MAC Address into RAR[0]\n");
786         hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
787
788         /* Zero out the other (rar_entry_count - 1) receive addresses */
789         hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
790         for (i = 1; i < rar_count; i++)
791             hw->mac.ops.rar_set(hw, addr, i);
792 }
793
794 /**
795  *  igb_update_mc_addr_list - Update Multicast addresses
796  *  @hw: pointer to the HW structure
797  *  @mc_addr_list: array of multicast addresses to program
798  *  @mc_addr_count: number of multicast addresses to program
799  *  @rar_used_count: the first RAR register free to program
800  *  @rar_count: total number of supported Receive Address Registers
801  *
802  *  Updates the Receive Address Registers and Multicast Table Array.
803  *  The caller must have a packed mc_addr_list of multicast addresses.
804  *  The parameter rar_count will usually be hw->mac.rar_entry_count
805  *  unless there are workarounds that change this.
806  **/
807 void igb_update_mc_addr_list(struct e1000_hw *hw,
808                              u8 *mc_addr_list, u32 mc_addr_count,
809                              u32 rar_used_count, u32 rar_count)
810 {
811         u32 hash_value;
812         u32 i;
813         u8 addr[6] = {0,0,0,0,0,0};
814         /*
815          * This function is essentially the same as that of 
816          * igb_update_mc_addr_list_generic. However it also takes care 
817          * of the special case where the register offset of the 
818          * second set of RARs begins elsewhere. This is implicitly taken care by 
819          * function e1000_rar_set_generic.
820          */
821
822         /*
823          * Load the first set of multicast addresses into the exact
824          * filters (RAR).  If there are not enough to fill the RAR
825          * array, clear the filters.
826          */
827         for (i = rar_used_count; i < rar_count; i++) {
828                 if (mc_addr_count) {
829                         igb_rar_set(hw, mc_addr_list, i);
830                         mc_addr_count--;
831                         mc_addr_list += ETH_ALEN;
832                 } else {
833                         igb_rar_set(hw, addr, i);
834                 }
835         }
836
837         /* Clear the old settings from the MTA */
838         hw_dbg("Clearing MTA\n");
839         for (i = 0; i < hw->mac.mta_reg_count; i++) {
840                 array_wr32(E1000_MTA, i, 0);
841                 wrfl();
842         }
843
844         /* Load any remaining multicast addresses into the hash table. */
845         for (; mc_addr_count > 0; mc_addr_count--) {
846                 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
847                 hw_dbg("Hash value = 0x%03X\n", hash_value);
848                 igb_mta_set(hw, hash_value);
849                 mc_addr_list += ETH_ALEN;
850         }
851 }
852
853 /**
854  *  igb_shutdown_fiber_serdes_link_82575 - Remove link during power down
855  *  @hw: pointer to the HW structure
856  *
857  *  In the case of fiber serdes, shut down optics and PCS on driver unload
858  *  when management pass thru is not enabled.
859  **/
860 void igb_shutdown_fiber_serdes_link_82575(struct e1000_hw *hw)
861 {
862         u32 reg;
863
864         if (hw->mac.type != e1000_82576 ||
865             (hw->phy.media_type != e1000_media_type_fiber &&
866              hw->phy.media_type != e1000_media_type_internal_serdes))
867                 return;
868
869         /* if the management interface is not enabled, then power down */
870         if (!igb_enable_mng_pass_thru(hw)) {
871                 /* Disable PCS to turn off link */
872                 reg = rd32(E1000_PCS_CFG0);
873                 reg &= ~E1000_PCS_CFG_PCS_EN;
874                 wr32(E1000_PCS_CFG0, reg);
875
876                 /* shutdown the laser */
877                 reg = rd32(E1000_CTRL_EXT);
878                 reg |= E1000_CTRL_EXT_SDP7_DATA;
879                 wr32(E1000_CTRL_EXT, reg);
880
881                 /* flush the write to verify completion */
882                 wrfl();
883                 msleep(1);
884         }
885
886         return;
887 }
888
889 /**
890  *  igb_reset_hw_82575 - Reset hardware
891  *  @hw: pointer to the HW structure
892  *
893  *  This resets the hardware into a known state.  This is a
894  *  function pointer entry point called by the api module.
895  **/
896 static s32 igb_reset_hw_82575(struct e1000_hw *hw)
897 {
898         u32 ctrl, icr;
899         s32 ret_val;
900
901         /*
902          * Prevent the PCI-E bus from sticking if there is no TLP connection
903          * on the last TLP read/write transaction when MAC is reset.
904          */
905         ret_val = igb_disable_pcie_master(hw);
906         if (ret_val)
907                 hw_dbg("PCI-E Master disable polling has failed.\n");
908
909         hw_dbg("Masking off all interrupts\n");
910         wr32(E1000_IMC, 0xffffffff);
911
912         wr32(E1000_RCTL, 0);
913         wr32(E1000_TCTL, E1000_TCTL_PSP);
914         wrfl();
915
916         msleep(10);
917
918         ctrl = rd32(E1000_CTRL);
919
920         hw_dbg("Issuing a global reset to MAC\n");
921         wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
922
923         ret_val = igb_get_auto_rd_done(hw);
924         if (ret_val) {
925                 /*
926                  * When auto config read does not complete, do not
927                  * return with an error. This can happen in situations
928                  * where there is no eeprom and prevents getting link.
929                  */
930                 hw_dbg("Auto Read Done did not complete\n");
931         }
932
933         /* If EEPROM is not present, run manual init scripts */
934         if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
935                 igb_reset_init_script_82575(hw);
936
937         /* Clear any pending interrupt events. */
938         wr32(E1000_IMC, 0xffffffff);
939         icr = rd32(E1000_ICR);
940
941         igb_check_alt_mac_addr(hw);
942
943         return ret_val;
944 }
945
946 /**
947  *  igb_init_hw_82575 - Initialize hardware
948  *  @hw: pointer to the HW structure
949  *
950  *  This inits the hardware readying it for operation.
951  **/
952 static s32 igb_init_hw_82575(struct e1000_hw *hw)
953 {
954         struct e1000_mac_info *mac = &hw->mac;
955         s32 ret_val;
956         u16 i, rar_count = mac->rar_entry_count;
957
958         /* Initialize identification LED */
959         ret_val = igb_id_led_init(hw);
960         if (ret_val) {
961                 hw_dbg("Error initializing identification LED\n");
962                 /* This is not fatal and we should not stop init due to this */
963         }
964
965         /* Disabling VLAN filtering */
966         hw_dbg("Initializing the IEEE VLAN\n");
967         igb_clear_vfta(hw);
968
969         /* Setup the receive address */
970         igb_init_rx_addrs_82575(hw, rar_count);
971         /* Zero out the Multicast HASH table */
972         hw_dbg("Zeroing the MTA\n");
973         for (i = 0; i < mac->mta_reg_count; i++)
974                 array_wr32(E1000_MTA, i, 0);
975
976         /* Setup link and flow control */
977         ret_val = igb_setup_link(hw);
978
979         /*
980          * Clear all of the statistics registers (clear on read).  It is
981          * important that we do this after we have tried to establish link
982          * because the symbol error count will increment wildly if there
983          * is no link.
984          */
985         igb_clear_hw_cntrs_82575(hw);
986
987         return ret_val;
988 }
989
990 /**
991  *  igb_setup_copper_link_82575 - Configure copper link settings
992  *  @hw: pointer to the HW structure
993  *
994  *  Configures the link for auto-neg or forced speed and duplex.  Then we check
995  *  for link, once link is established calls to configure collision distance
996  *  and flow control are called.
997  **/
998 static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
999 {
1000         u32 ctrl, led_ctrl;
1001         s32  ret_val;
1002         bool link;
1003
1004         ctrl = rd32(E1000_CTRL);
1005         ctrl |= E1000_CTRL_SLU;
1006         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1007         wr32(E1000_CTRL, ctrl);
1008
1009         switch (hw->phy.type) {
1010         case e1000_phy_m88:
1011                 ret_val = igb_copper_link_setup_m88(hw);
1012                 break;
1013         case e1000_phy_igp_3:
1014                 ret_val = igb_copper_link_setup_igp(hw);
1015                 /* Setup activity LED */
1016                 led_ctrl = rd32(E1000_LEDCTL);
1017                 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1018                 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1019                 wr32(E1000_LEDCTL, led_ctrl);
1020                 break;
1021         default:
1022                 ret_val = -E1000_ERR_PHY;
1023                 break;
1024         }
1025
1026         if (ret_val)
1027                 goto out;
1028
1029         if (hw->mac.autoneg) {
1030                 /*
1031                  * Setup autoneg and flow control advertisement
1032                  * and perform autonegotiation.
1033                  */
1034                 ret_val = igb_copper_link_autoneg(hw);
1035                 if (ret_val)
1036                         goto out;
1037         } else {
1038                 /*
1039                  * PHY will be set to 10H, 10F, 100H or 100F
1040                  * depending on user settings.
1041                  */
1042                 hw_dbg("Forcing Speed and Duplex\n");
1043                 ret_val = hw->phy.ops.force_speed_duplex(hw);
1044                 if (ret_val) {
1045                         hw_dbg("Error Forcing Speed and Duplex\n");
1046                         goto out;
1047                 }
1048         }
1049
1050         ret_val = igb_configure_pcs_link_82575(hw);
1051         if (ret_val)
1052                 goto out;
1053
1054         /*
1055          * Check link status. Wait up to 100 microseconds for link to become
1056          * valid.
1057          */
1058         ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
1059         if (ret_val)
1060                 goto out;
1061
1062         if (link) {
1063                 hw_dbg("Valid link established!!!\n");
1064                 /* Config the MAC and PHY after link is up */
1065                 igb_config_collision_dist(hw);
1066                 ret_val = igb_config_fc_after_link_up(hw);
1067         } else {
1068                 hw_dbg("Unable to establish link!!!\n");
1069         }
1070
1071 out:
1072         return ret_val;
1073 }
1074
1075 /**
1076  *  igb_setup_fiber_serdes_link_82575 - Setup link for fiber/serdes
1077  *  @hw: pointer to the HW structure
1078  *
1079  *  Configures speed and duplex for fiber and serdes links.
1080  **/
1081 static s32 igb_setup_fiber_serdes_link_82575(struct e1000_hw *hw)
1082 {
1083         u32 reg;
1084
1085         /*
1086          * On the 82575, SerDes loopback mode persists until it is
1087          * explicitly turned off or a power cycle is performed.  A read to
1088          * the register does not indicate its status.  Therefore, we ensure
1089          * loopback mode is disabled during initialization.
1090          */
1091         wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1092
1093         /* Force link up, set 1gb, set both sw defined pins */
1094         reg = rd32(E1000_CTRL);
1095         reg |= E1000_CTRL_SLU |
1096                E1000_CTRL_SPD_1000 |
1097                E1000_CTRL_FRCSPD |
1098                E1000_CTRL_SWDPIN0 |
1099                E1000_CTRL_SWDPIN1;
1100         wr32(E1000_CTRL, reg);
1101
1102         /* Power on phy for 82576 fiber adapters */
1103         if (hw->mac.type == e1000_82576) {
1104                 reg = rd32(E1000_CTRL_EXT);
1105                 reg &= ~E1000_CTRL_EXT_SDP7_DATA;
1106                 wr32(E1000_CTRL_EXT, reg);
1107         }
1108
1109         /* Set switch control to serdes energy detect */
1110         reg = rd32(E1000_CONNSW);
1111         reg |= E1000_CONNSW_ENRGSRC;
1112         wr32(E1000_CONNSW, reg);
1113
1114         /*
1115          * New SerDes mode allows for forcing speed or autonegotiating speed
1116          * at 1gb. Autoneg should be default set by most drivers. This is the
1117          * mode that will be compatible with older link partners and switches.
1118          * However, both are supported by the hardware and some drivers/tools.
1119          */
1120         reg = rd32(E1000_PCS_LCTL);
1121
1122         reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
1123                 E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1124
1125         if (hw->mac.autoneg) {
1126                 /* Set PCS register for autoneg */
1127                 reg |= E1000_PCS_LCTL_FSV_1000 |      /* Force 1000    */
1128                        E1000_PCS_LCTL_FDV_FULL |      /* SerDes Full duplex */
1129                        E1000_PCS_LCTL_AN_ENABLE |     /* Enable Autoneg */
1130                        E1000_PCS_LCTL_AN_RESTART;     /* Restart autoneg */
1131                 hw_dbg("Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
1132         } else {
1133                 /* Set PCS register for forced speed */
1134                 reg |= E1000_PCS_LCTL_FLV_LINK_UP |   /* Force link up */
1135                        E1000_PCS_LCTL_FSV_1000 |      /* Force 1000    */
1136                        E1000_PCS_LCTL_FDV_FULL |      /* SerDes Full duplex */
1137                        E1000_PCS_LCTL_FSD |           /* Force Speed */
1138                        E1000_PCS_LCTL_FORCE_LINK;     /* Force Link */
1139                 hw_dbg("Configuring Forced Link; PCS_LCTL = 0x%08X\n", reg);
1140         }
1141
1142         if (hw->mac.type == e1000_82576) {
1143                 reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1144                 igb_force_mac_fc(hw);
1145         }
1146
1147         wr32(E1000_PCS_LCTL, reg);
1148
1149         return 0;
1150 }
1151
1152 /**
1153  *  igb_configure_pcs_link_82575 - Configure PCS link
1154  *  @hw: pointer to the HW structure
1155  *
1156  *  Configure the physical coding sub-layer (PCS) link.  The PCS link is
1157  *  only used on copper connections where the serialized gigabit media
1158  *  independent interface (sgmii) is being used.  Configures the link
1159  *  for auto-negotiation or forces speed/duplex.
1160  **/
1161 static s32 igb_configure_pcs_link_82575(struct e1000_hw *hw)
1162 {
1163         struct e1000_mac_info *mac = &hw->mac;
1164         u32 reg = 0;
1165
1166         if (hw->phy.media_type != e1000_media_type_copper ||
1167             !(igb_sgmii_active_82575(hw)))
1168                 goto out;
1169
1170         /* For SGMII, we need to issue a PCS autoneg restart */
1171         reg = rd32(E1000_PCS_LCTL);
1172
1173         /* AN time out should be disabled for SGMII mode */
1174         reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
1175
1176         if (mac->autoneg) {
1177                 /* Make sure forced speed and force link are not set */
1178                 reg &= ~(E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
1179
1180                 /*
1181                  * The PHY should be setup prior to calling this function.
1182                  * All we need to do is restart autoneg and enable autoneg.
1183                  */
1184                 reg |= E1000_PCS_LCTL_AN_RESTART | E1000_PCS_LCTL_AN_ENABLE;
1185         } else {
1186                 /* Set PCS register for forced speed */
1187
1188                 /* Turn off bits for full duplex, speed, and autoneg */
1189                 reg &= ~(E1000_PCS_LCTL_FSV_1000 |
1190                          E1000_PCS_LCTL_FSV_100 |
1191                          E1000_PCS_LCTL_FDV_FULL |
1192                          E1000_PCS_LCTL_AN_ENABLE);
1193
1194                 /* Check for duplex first */
1195                 if (mac->forced_speed_duplex & E1000_ALL_FULL_DUPLEX)
1196                         reg |= E1000_PCS_LCTL_FDV_FULL;
1197
1198                 /* Now set speed */
1199                 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED)
1200                         reg |= E1000_PCS_LCTL_FSV_100;
1201
1202                 /* Force speed and force link */
1203                 reg |= E1000_PCS_LCTL_FSD |
1204                        E1000_PCS_LCTL_FORCE_LINK |
1205                        E1000_PCS_LCTL_FLV_LINK_UP;
1206
1207                 hw_dbg("Wrote 0x%08X to PCS_LCTL to configure forced link\n",
1208                        reg);
1209         }
1210         wr32(E1000_PCS_LCTL, reg);
1211
1212 out:
1213         return 0;
1214 }
1215
1216 /**
1217  *  igb_sgmii_active_82575 - Return sgmii state
1218  *  @hw: pointer to the HW structure
1219  *
1220  *  82575 silicon has a serialized gigabit media independent interface (sgmii)
1221  *  which can be enabled for use in the embedded applications.  Simply
1222  *  return the current state of the sgmii interface.
1223  **/
1224 static bool igb_sgmii_active_82575(struct e1000_hw *hw)
1225 {
1226         struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
1227
1228         if (hw->mac.type != e1000_82575 && hw->mac.type != e1000_82576)
1229                 return false;
1230
1231         return dev_spec->sgmii_active;
1232 }
1233
1234 /**
1235  *  igb_reset_init_script_82575 - Inits HW defaults after reset
1236  *  @hw: pointer to the HW structure
1237  *
1238  *  Inits recommended HW defaults after a reset when there is no EEPROM
1239  *  detected. This is only for the 82575.
1240  **/
1241 static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
1242 {
1243         if (hw->mac.type == e1000_82575) {
1244                 hw_dbg("Running reset init script for 82575\n");
1245                 /* SerDes configuration via SERDESCTRL */
1246                 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
1247                 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
1248                 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
1249                 igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
1250
1251                 /* CCM configuration via CCMCTL register */
1252                 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
1253                 igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
1254
1255                 /* PCIe lanes configuration */
1256                 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
1257                 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
1258                 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
1259                 igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
1260
1261                 /* PCIe PLL Configuration */
1262                 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
1263                 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
1264                 igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
1265         }
1266
1267         return 0;
1268 }
1269
1270 /**
1271  *  igb_read_mac_addr_82575 - Read device MAC address
1272  *  @hw: pointer to the HW structure
1273  **/
1274 static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
1275 {
1276         s32 ret_val = 0;
1277
1278         if (igb_check_alt_mac_addr(hw))
1279                 ret_val = igb_read_mac_addr(hw);
1280
1281         return ret_val;
1282 }
1283
1284 /**
1285  *  igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
1286  *  @hw: pointer to the HW structure
1287  *
1288  *  Clears the hardware counters by reading the counter registers.
1289  **/
1290 static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
1291 {
1292         u32 temp;
1293
1294         igb_clear_hw_cntrs_base(hw);
1295
1296         temp = rd32(E1000_PRC64);
1297         temp = rd32(E1000_PRC127);
1298         temp = rd32(E1000_PRC255);
1299         temp = rd32(E1000_PRC511);
1300         temp = rd32(E1000_PRC1023);
1301         temp = rd32(E1000_PRC1522);
1302         temp = rd32(E1000_PTC64);
1303         temp = rd32(E1000_PTC127);
1304         temp = rd32(E1000_PTC255);
1305         temp = rd32(E1000_PTC511);
1306         temp = rd32(E1000_PTC1023);
1307         temp = rd32(E1000_PTC1522);
1308
1309         temp = rd32(E1000_ALGNERRC);
1310         temp = rd32(E1000_RXERRC);
1311         temp = rd32(E1000_TNCRS);
1312         temp = rd32(E1000_CEXTERR);
1313         temp = rd32(E1000_TSCTC);
1314         temp = rd32(E1000_TSCTFC);
1315
1316         temp = rd32(E1000_MGTPRC);
1317         temp = rd32(E1000_MGTPDC);
1318         temp = rd32(E1000_MGTPTC);
1319
1320         temp = rd32(E1000_IAC);
1321         temp = rd32(E1000_ICRXOC);
1322
1323         temp = rd32(E1000_ICRXPTC);
1324         temp = rd32(E1000_ICRXATC);
1325         temp = rd32(E1000_ICTXPTC);
1326         temp = rd32(E1000_ICTXATC);
1327         temp = rd32(E1000_ICTXQEC);
1328         temp = rd32(E1000_ICTXQMTC);
1329         temp = rd32(E1000_ICRXDMTC);
1330
1331         temp = rd32(E1000_CBTMPC);
1332         temp = rd32(E1000_HTDPMC);
1333         temp = rd32(E1000_CBRMPC);
1334         temp = rd32(E1000_RPTHC);
1335         temp = rd32(E1000_HGPTC);
1336         temp = rd32(E1000_HTCBDPC);
1337         temp = rd32(E1000_HGORCL);
1338         temp = rd32(E1000_HGORCH);
1339         temp = rd32(E1000_HGOTCL);
1340         temp = rd32(E1000_HGOTCH);
1341         temp = rd32(E1000_LENERRS);
1342
1343         /* This register should not be read in copper configurations */
1344         if (hw->phy.media_type == e1000_media_type_internal_serdes)
1345                 temp = rd32(E1000_SCVPC);
1346 }
1347
1348 /**
1349  *  igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
1350  *  @hw: pointer to the HW structure
1351  *
1352  *  After rx enable if managability is enabled then there is likely some
1353  *  bad data at the start of the fifo and possibly in the DMA fifo.  This
1354  *  function clears the fifos and flushes any packets that came in as rx was
1355  *  being enabled.
1356  **/
1357 void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
1358 {
1359         u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
1360         int i, ms_wait;
1361
1362         if (hw->mac.type != e1000_82575 ||
1363             !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
1364                 return;
1365
1366         /* Disable all RX queues */
1367         for (i = 0; i < 4; i++) {
1368                 rxdctl[i] = rd32(E1000_RXDCTL(i));
1369                 wr32(E1000_RXDCTL(i),
1370                      rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
1371         }
1372         /* Poll all queues to verify they have shut down */
1373         for (ms_wait = 0; ms_wait < 10; ms_wait++) {
1374                 msleep(1);
1375                 rx_enabled = 0;
1376                 for (i = 0; i < 4; i++)
1377                         rx_enabled |= rd32(E1000_RXDCTL(i));
1378                 if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
1379                         break;
1380         }
1381
1382         if (ms_wait == 10)
1383                 hw_dbg("Queue disable timed out after 10ms\n");
1384
1385         /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
1386          * incoming packets are rejected.  Set enable and wait 2ms so that
1387          * any packet that was coming in as RCTL.EN was set is flushed
1388          */
1389         rfctl = rd32(E1000_RFCTL);
1390         wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
1391
1392         rlpml = rd32(E1000_RLPML);
1393         wr32(E1000_RLPML, 0);
1394
1395         rctl = rd32(E1000_RCTL);
1396         temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
1397         temp_rctl |= E1000_RCTL_LPE;
1398
1399         wr32(E1000_RCTL, temp_rctl);
1400         wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
1401         wrfl();
1402         msleep(2);
1403
1404         /* Enable RX queues that were previously enabled and restore our
1405          * previous state
1406          */
1407         for (i = 0; i < 4; i++)
1408                 wr32(E1000_RXDCTL(i), rxdctl[i]);
1409         wr32(E1000_RCTL, rctl);
1410         wrfl();
1411
1412         wr32(E1000_RLPML, rlpml);
1413         wr32(E1000_RFCTL, rfctl);
1414
1415         /* Flush receive errors generated by workaround */
1416         rd32(E1000_ROC);
1417         rd32(E1000_RNBC);
1418         rd32(E1000_MPC);
1419 }
1420
1421 /**
1422  *  igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
1423  *  @hw: pointer to the hardware struct
1424  *  @enable: state to enter, either enabled or disabled
1425  *
1426  *  enables/disables L2 switch loopback functionality.
1427  **/
1428 void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
1429 {
1430         u32 dtxswc = rd32(E1000_DTXSWC);
1431
1432         if (enable)
1433                 dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1434         else
1435                 dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
1436
1437         wr32(E1000_DTXSWC, dtxswc);
1438 }
1439
1440 /**
1441  *  igb_vmdq_set_replication_pf - enable or disable vmdq replication
1442  *  @hw: pointer to the hardware struct
1443  *  @enable: state to enter, either enabled or disabled
1444  *
1445  *  enables/disables replication of packets across multiple pools.
1446  **/
1447 void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
1448 {
1449         u32 vt_ctl = rd32(E1000_VT_CTL);
1450
1451         if (enable)
1452                 vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
1453         else
1454                 vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
1455
1456         wr32(E1000_VT_CTL, vt_ctl);
1457 }
1458
1459 static struct e1000_mac_operations e1000_mac_ops_82575 = {
1460         .reset_hw             = igb_reset_hw_82575,
1461         .init_hw              = igb_init_hw_82575,
1462         .check_for_link       = igb_check_for_link_82575,
1463         .rar_set              = igb_rar_set,
1464         .read_mac_addr        = igb_read_mac_addr_82575,
1465         .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
1466 };
1467
1468 static struct e1000_phy_operations e1000_phy_ops_82575 = {
1469         .acquire              = igb_acquire_phy_82575,
1470         .get_cfg_done         = igb_get_cfg_done_82575,
1471         .release              = igb_release_phy_82575,
1472 };
1473
1474 static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
1475         .acquire              = igb_acquire_nvm_82575,
1476         .read                 = igb_read_nvm_eerd,
1477         .release              = igb_release_nvm_82575,
1478         .write                = igb_write_nvm_spi,
1479 };
1480
1481 const struct e1000_info e1000_82575_info = {
1482         .get_invariants = igb_get_invariants_82575,
1483         .mac_ops = &e1000_mac_ops_82575,
1484         .phy_ops = &e1000_phy_ops_82575,
1485         .nvm_ops = &e1000_nvm_ops_82575,
1486 };
1487