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