e1000: minor changes
[dpdk.git] / lib / librte_pmd_e1000 / e1000 / e1000_80003es2lan.c
1 /*******************************************************************************
2
3 Copyright (c) 2001-2012, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in the
14     documentation and/or other materials provided with the distribution.
15
16  3. Neither the name of the Intel Corporation nor the names of its
17     contributors may be used to endorse or promote products derived from
18     this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ***************************************************************************/
33
34 /* 80003ES2LAN Gigabit Ethernet Controller (Copper)
35  * 80003ES2LAN Gigabit Ethernet Controller (Serdes)
36  */
37
38 #include "e1000_api.h"
39
40 STATIC s32  e1000_acquire_phy_80003es2lan(struct e1000_hw *hw);
41 STATIC void e1000_release_phy_80003es2lan(struct e1000_hw *hw);
42 STATIC s32  e1000_acquire_nvm_80003es2lan(struct e1000_hw *hw);
43 STATIC void e1000_release_nvm_80003es2lan(struct e1000_hw *hw);
44 STATIC s32  e1000_read_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
45                                                    u32 offset,
46                                                    u16 *data);
47 STATIC s32  e1000_write_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
48                                                     u32 offset,
49                                                     u16 data);
50 STATIC s32  e1000_write_nvm_80003es2lan(struct e1000_hw *hw, u16 offset,
51                                         u16 words, u16 *data);
52 STATIC s32  e1000_get_cfg_done_80003es2lan(struct e1000_hw *hw);
53 STATIC s32  e1000_phy_force_speed_duplex_80003es2lan(struct e1000_hw *hw);
54 STATIC s32  e1000_get_cable_length_80003es2lan(struct e1000_hw *hw);
55 STATIC s32  e1000_get_link_up_info_80003es2lan(struct e1000_hw *hw, u16 *speed,
56                                                u16 *duplex);
57 STATIC s32  e1000_reset_hw_80003es2lan(struct e1000_hw *hw);
58 STATIC s32  e1000_init_hw_80003es2lan(struct e1000_hw *hw);
59 STATIC s32  e1000_setup_copper_link_80003es2lan(struct e1000_hw *hw);
60 STATIC void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw);
61 static s32  e1000_acquire_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask);
62 static s32  e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex);
63 static s32  e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw);
64 static s32  e1000_cfg_on_link_up_80003es2lan(struct e1000_hw *hw);
65 static s32  e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
66                                             u16 *data);
67 static s32  e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
68                                              u16 data);
69 static void e1000_initialize_hw_bits_80003es2lan(struct e1000_hw *hw);
70 static void e1000_release_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask);
71 STATIC s32  e1000_read_mac_addr_80003es2lan(struct e1000_hw *hw);
72 STATIC void e1000_power_down_phy_copper_80003es2lan(struct e1000_hw *hw);
73
74 /* A table for the GG82563 cable length where the range is defined
75  * with a lower bound at "index" and the upper bound at
76  * "index + 5".
77  */
78 static const u16 e1000_gg82563_cable_length_table[] = {
79         0, 60, 115, 150, 150, 60, 115, 150, 180, 180, 0xFF };
80 #define GG82563_CABLE_LENGTH_TABLE_SIZE \
81                 (sizeof(e1000_gg82563_cable_length_table) / \
82                  sizeof(e1000_gg82563_cable_length_table[0]))
83
84 /**
85  *  e1000_init_phy_params_80003es2lan - Init ESB2 PHY func ptrs.
86  *  @hw: pointer to the HW structure
87  **/
88 STATIC s32 e1000_init_phy_params_80003es2lan(struct e1000_hw *hw)
89 {
90         struct e1000_phy_info *phy = &hw->phy;
91         s32 ret_val;
92
93         DEBUGFUNC("e1000_init_phy_params_80003es2lan");
94
95         if (hw->phy.media_type != e1000_media_type_copper) {
96                 phy->type = e1000_phy_none;
97                 return E1000_SUCCESS;
98         } else {
99                 phy->ops.power_up = e1000_power_up_phy_copper;
100                 phy->ops.power_down = e1000_power_down_phy_copper_80003es2lan;
101         }
102
103         phy->addr               = 1;
104         phy->autoneg_mask       = AUTONEG_ADVERTISE_SPEED_DEFAULT;
105         phy->reset_delay_us     = 100;
106         phy->type               = e1000_phy_gg82563;
107
108         phy->ops.acquire        = e1000_acquire_phy_80003es2lan;
109         phy->ops.check_polarity = e1000_check_polarity_m88;
110         phy->ops.check_reset_block = e1000_check_reset_block_generic;
111         phy->ops.commit         = e1000_phy_sw_reset_generic;
112         phy->ops.get_cfg_done   = e1000_get_cfg_done_80003es2lan;
113         phy->ops.get_info       = e1000_get_phy_info_m88;
114         phy->ops.release        = e1000_release_phy_80003es2lan;
115         phy->ops.reset          = e1000_phy_hw_reset_generic;
116         phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_generic;
117
118         phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_80003es2lan;
119         phy->ops.get_cable_length = e1000_get_cable_length_80003es2lan;
120         phy->ops.read_reg       = e1000_read_phy_reg_gg82563_80003es2lan;
121         phy->ops.write_reg      = e1000_write_phy_reg_gg82563_80003es2lan;
122
123         phy->ops.cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan;
124
125         /* This can only be done after all function pointers are setup. */
126         ret_val = e1000_get_phy_id(hw);
127
128         /* Verify phy id */
129         if (phy->id != GG82563_E_PHY_ID)
130                 return -E1000_ERR_PHY;
131
132         return ret_val;
133 }
134
135 /**
136  *  e1000_init_nvm_params_80003es2lan - Init ESB2 NVM func ptrs.
137  *  @hw: pointer to the HW structure
138  **/
139 STATIC s32 e1000_init_nvm_params_80003es2lan(struct e1000_hw *hw)
140 {
141         struct e1000_nvm_info *nvm = &hw->nvm;
142         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
143         u16 size;
144
145         DEBUGFUNC("e1000_init_nvm_params_80003es2lan");
146
147         nvm->opcode_bits = 8;
148         nvm->delay_usec = 1;
149         switch (nvm->override) {
150         case e1000_nvm_override_spi_large:
151                 nvm->page_size = 32;
152                 nvm->address_bits = 16;
153                 break;
154         case e1000_nvm_override_spi_small:
155                 nvm->page_size = 8;
156                 nvm->address_bits = 8;
157                 break;
158         default:
159                 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
160                 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
161                 break;
162         }
163
164         nvm->type = e1000_nvm_eeprom_spi;
165
166         size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
167                      E1000_EECD_SIZE_EX_SHIFT);
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         /* Function Pointers */
180         nvm->ops.acquire        = e1000_acquire_nvm_80003es2lan;
181         nvm->ops.read           = e1000_read_nvm_eerd;
182         nvm->ops.release        = e1000_release_nvm_80003es2lan;
183         nvm->ops.update         = e1000_update_nvm_checksum_generic;
184         nvm->ops.valid_led_default = e1000_valid_led_default_generic;
185         nvm->ops.validate       = e1000_validate_nvm_checksum_generic;
186         nvm->ops.write          = e1000_write_nvm_80003es2lan;
187
188         return E1000_SUCCESS;
189 }
190
191 /**
192  *  e1000_init_mac_params_80003es2lan - Init ESB2 MAC func ptrs.
193  *  @hw: pointer to the HW structure
194  **/
195 STATIC s32 e1000_init_mac_params_80003es2lan(struct e1000_hw *hw)
196 {
197         struct e1000_mac_info *mac = &hw->mac;
198
199         DEBUGFUNC("e1000_init_mac_params_80003es2lan");
200
201         /* Set media type and media-dependent function pointers */
202         switch (hw->device_id) {
203         case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
204                 hw->phy.media_type = e1000_media_type_internal_serdes;
205                 mac->ops.check_for_link = e1000_check_for_serdes_link_generic;
206                 mac->ops.setup_physical_interface =
207                                         e1000_setup_fiber_serdes_link_generic;
208                 break;
209         default:
210                 hw->phy.media_type = e1000_media_type_copper;
211                 mac->ops.check_for_link = e1000_check_for_copper_link_generic;
212                 mac->ops.setup_physical_interface =
213                                         e1000_setup_copper_link_80003es2lan;
214                 break;
215         }
216
217         /* Set mta register count */
218         mac->mta_reg_count = 128;
219         /* Set rar entry count */
220         mac->rar_entry_count = E1000_RAR_ENTRIES;
221         /* Set if part includes ASF firmware */
222         mac->asf_firmware_present = true;
223         /* FWSM register */
224         mac->has_fwsm = true;
225         /* ARC supported; valid only if manageability features are enabled. */
226         mac->arc_subsystem_valid = !!(E1000_READ_REG(hw, E1000_FWSM) &
227                                       E1000_FWSM_MODE_MASK);
228         /* Adaptive IFS not supported */
229         mac->adaptive_ifs = false;
230
231         /* Function pointers */
232
233         /* bus type/speed/width */
234         mac->ops.get_bus_info = e1000_get_bus_info_pcie_generic;
235         /* reset */
236         mac->ops.reset_hw = e1000_reset_hw_80003es2lan;
237         /* hw initialization */
238         mac->ops.init_hw = e1000_init_hw_80003es2lan;
239         /* link setup */
240         mac->ops.setup_link = e1000_setup_link_generic;
241         /* check management mode */
242         mac->ops.check_mng_mode = e1000_check_mng_mode_generic;
243         /* multicast address update */
244         mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
245         /* writing VFTA */
246         mac->ops.write_vfta = e1000_write_vfta_generic;
247         /* clearing VFTA */
248         mac->ops.clear_vfta = e1000_clear_vfta_generic;
249         /* read mac address */
250         mac->ops.read_mac_addr = e1000_read_mac_addr_80003es2lan;
251         /* ID LED init */
252         mac->ops.id_led_init = e1000_id_led_init_generic;
253         /* blink LED */
254         mac->ops.blink_led = e1000_blink_led_generic;
255         /* setup LED */
256         mac->ops.setup_led = e1000_setup_led_generic;
257         /* cleanup LED */
258         mac->ops.cleanup_led = e1000_cleanup_led_generic;
259         /* turn on/off LED */
260         mac->ops.led_on = e1000_led_on_generic;
261         mac->ops.led_off = e1000_led_off_generic;
262         /* clear hardware counters */
263         mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_80003es2lan;
264         /* link info */
265         mac->ops.get_link_up_info = e1000_get_link_up_info_80003es2lan;
266
267         /* set lan id for port to determine which phy lock to use */
268         hw->mac.ops.set_lan_id(hw);
269
270         return E1000_SUCCESS;
271 }
272
273 /**
274  *  e1000_init_function_pointers_80003es2lan - Init ESB2 func ptrs.
275  *  @hw: pointer to the HW structure
276  *
277  *  Called to initialize all function pointers and parameters.
278  **/
279 void e1000_init_function_pointers_80003es2lan(struct e1000_hw *hw)
280 {
281         DEBUGFUNC("e1000_init_function_pointers_80003es2lan");
282
283         hw->mac.ops.init_params = e1000_init_mac_params_80003es2lan;
284         hw->nvm.ops.init_params = e1000_init_nvm_params_80003es2lan;
285         hw->phy.ops.init_params = e1000_init_phy_params_80003es2lan;
286 }
287
288 /**
289  *  e1000_acquire_phy_80003es2lan - Acquire rights to access PHY
290  *  @hw: pointer to the HW structure
291  *
292  *  A wrapper to acquire access rights to the correct PHY.
293  **/
294 STATIC s32 e1000_acquire_phy_80003es2lan(struct e1000_hw *hw)
295 {
296         u16 mask;
297
298         DEBUGFUNC("e1000_acquire_phy_80003es2lan");
299
300         mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
301         return e1000_acquire_swfw_sync_80003es2lan(hw, mask);
302 }
303
304 /**
305  *  e1000_release_phy_80003es2lan - Release rights to access PHY
306  *  @hw: pointer to the HW structure
307  *
308  *  A wrapper to release access rights to the correct PHY.
309  **/
310 STATIC void e1000_release_phy_80003es2lan(struct e1000_hw *hw)
311 {
312         u16 mask;
313
314         DEBUGFUNC("e1000_release_phy_80003es2lan");
315
316         mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
317         e1000_release_swfw_sync_80003es2lan(hw, mask);
318 }
319
320 /**
321  *  e1000_acquire_mac_csr_80003es2lan - Acquire right to access Kumeran register
322  *  @hw: pointer to the HW structure
323  *
324  *  Acquire the semaphore to access the Kumeran interface.
325  *
326  **/
327 STATIC s32 e1000_acquire_mac_csr_80003es2lan(struct e1000_hw *hw)
328 {
329         u16 mask;
330
331         DEBUGFUNC("e1000_acquire_mac_csr_80003es2lan");
332
333         mask = E1000_SWFW_CSR_SM;
334
335         return e1000_acquire_swfw_sync_80003es2lan(hw, mask);
336 }
337
338 /**
339  *  e1000_release_mac_csr_80003es2lan - Release right to access Kumeran Register
340  *  @hw: pointer to the HW structure
341  *
342  *  Release the semaphore used to access the Kumeran interface
343  **/
344 STATIC void e1000_release_mac_csr_80003es2lan(struct e1000_hw *hw)
345 {
346         u16 mask;
347
348         DEBUGFUNC("e1000_release_mac_csr_80003es2lan");
349
350         mask = E1000_SWFW_CSR_SM;
351
352         e1000_release_swfw_sync_80003es2lan(hw, mask);
353 }
354
355 /**
356  *  e1000_acquire_nvm_80003es2lan - Acquire rights to access NVM
357  *  @hw: pointer to the HW structure
358  *
359  *  Acquire the semaphore to access the EEPROM.
360  **/
361 STATIC s32 e1000_acquire_nvm_80003es2lan(struct e1000_hw *hw)
362 {
363         s32 ret_val;
364
365         DEBUGFUNC("e1000_acquire_nvm_80003es2lan");
366
367         ret_val = e1000_acquire_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
368         if (ret_val)
369                 return ret_val;
370
371         ret_val = e1000_acquire_nvm_generic(hw);
372
373         if (ret_val)
374                 e1000_release_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
375
376         return ret_val;
377 }
378
379 /**
380  *  e1000_release_nvm_80003es2lan - Relinquish rights to access NVM
381  *  @hw: pointer to the HW structure
382  *
383  *  Release the semaphore used to access the EEPROM.
384  **/
385 STATIC void e1000_release_nvm_80003es2lan(struct e1000_hw *hw)
386 {
387         DEBUGFUNC("e1000_release_nvm_80003es2lan");
388
389         e1000_release_nvm_generic(hw);
390         e1000_release_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
391 }
392
393 /**
394  *  e1000_acquire_swfw_sync_80003es2lan - Acquire SW/FW semaphore
395  *  @hw: pointer to the HW structure
396  *  @mask: specifies which semaphore to acquire
397  *
398  *  Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
399  *  will also specify which port we're acquiring the lock for.
400  **/
401 static s32 e1000_acquire_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask)
402 {
403         u32 swfw_sync;
404         u32 swmask = mask;
405         u32 fwmask = mask << 16;
406         s32 i = 0;
407         s32 timeout = 50;
408
409         DEBUGFUNC("e1000_acquire_swfw_sync_80003es2lan");
410
411         while (i < timeout) {
412                 if (e1000_get_hw_semaphore_generic(hw))
413                         return -E1000_ERR_SWFW_SYNC;
414
415                 swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
416                 if (!(swfw_sync & (fwmask | swmask)))
417                         break;
418
419                 /* Firmware currently using resource (fwmask)
420                  * or other software thread using resource (swmask)
421                  */
422                 e1000_put_hw_semaphore_generic(hw);
423                 msec_delay_irq(5);
424                 i++;
425         }
426
427         if (i == timeout) {
428                 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
429                 return -E1000_ERR_SWFW_SYNC;
430         }
431
432         swfw_sync |= swmask;
433         E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
434
435         e1000_put_hw_semaphore_generic(hw);
436
437         return E1000_SUCCESS;
438 }
439
440 /**
441  *  e1000_release_swfw_sync_80003es2lan - Release SW/FW semaphore
442  *  @hw: pointer to the HW structure
443  *  @mask: specifies which semaphore to acquire
444  *
445  *  Release the SW/FW semaphore used to access the PHY or NVM.  The mask
446  *  will also specify which port we're releasing the lock for.
447  **/
448 static void e1000_release_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask)
449 {
450         u32 swfw_sync;
451
452         DEBUGFUNC("e1000_release_swfw_sync_80003es2lan");
453
454         while (e1000_get_hw_semaphore_generic(hw) != E1000_SUCCESS)
455                 ; /* Empty */
456
457         swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
458         swfw_sync &= ~mask;
459         E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
460
461         e1000_put_hw_semaphore_generic(hw);
462 }
463
464 /**
465  *  e1000_read_phy_reg_gg82563_80003es2lan - Read GG82563 PHY register
466  *  @hw: pointer to the HW structure
467  *  @offset: offset of the register to read
468  *  @data: pointer to the data returned from the operation
469  *
470  *  Read the GG82563 PHY register.
471  **/
472 STATIC s32 e1000_read_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
473                                                   u32 offset, u16 *data)
474 {
475         s32 ret_val;
476         u32 page_select;
477         u16 temp;
478
479         DEBUGFUNC("e1000_read_phy_reg_gg82563_80003es2lan");
480
481         ret_val = e1000_acquire_phy_80003es2lan(hw);
482         if (ret_val)
483                 return ret_val;
484
485         /* Select Configuration Page */
486         if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
487                 page_select = GG82563_PHY_PAGE_SELECT;
488         } else {
489                 /* Use Alternative Page Select register to access
490                  * registers 30 and 31
491                  */
492                 page_select = GG82563_PHY_PAGE_SELECT_ALT;
493         }
494
495         temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
496         ret_val = e1000_write_phy_reg_mdic(hw, page_select, temp);
497         if (ret_val) {
498                 e1000_release_phy_80003es2lan(hw);
499                 return ret_val;
500         }
501
502         if (hw->dev_spec._80003es2lan.mdic_wa_enable) {
503                 /* The "ready" bit in the MDIC register may be incorrectly set
504                  * before the device has completed the "Page Select" MDI
505                  * transaction.  So we wait 200us after each MDI command...
506                  */
507                 usec_delay(200);
508
509                 /* ...and verify the command was successful. */
510                 ret_val = e1000_read_phy_reg_mdic(hw, page_select, &temp);
511
512                 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
513                         e1000_release_phy_80003es2lan(hw);
514                         return -E1000_ERR_PHY;
515                 }
516
517                 usec_delay(200);
518
519                 ret_val = e1000_read_phy_reg_mdic(hw,
520                                                   MAX_PHY_REG_ADDRESS & offset,
521                                                   data);
522
523                 usec_delay(200);
524         } else {
525                 ret_val = e1000_read_phy_reg_mdic(hw,
526                                                   MAX_PHY_REG_ADDRESS & offset,
527                                                   data);
528         }
529
530         e1000_release_phy_80003es2lan(hw);
531
532         return ret_val;
533 }
534
535 /**
536  *  e1000_write_phy_reg_gg82563_80003es2lan - Write GG82563 PHY register
537  *  @hw: pointer to the HW structure
538  *  @offset: offset of the register to read
539  *  @data: value to write to the register
540  *
541  *  Write to the GG82563 PHY register.
542  **/
543 STATIC s32 e1000_write_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
544                                                    u32 offset, u16 data)
545 {
546         s32 ret_val;
547         u32 page_select;
548         u16 temp;
549
550         DEBUGFUNC("e1000_write_phy_reg_gg82563_80003es2lan");
551
552         ret_val = e1000_acquire_phy_80003es2lan(hw);
553         if (ret_val)
554                 return ret_val;
555
556         /* Select Configuration Page */
557         if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
558                 page_select = GG82563_PHY_PAGE_SELECT;
559         } else {
560                 /* Use Alternative Page Select register to access
561                  * registers 30 and 31
562                  */
563                 page_select = GG82563_PHY_PAGE_SELECT_ALT;
564         }
565
566         temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
567         ret_val = e1000_write_phy_reg_mdic(hw, page_select, temp);
568         if (ret_val) {
569                 e1000_release_phy_80003es2lan(hw);
570                 return ret_val;
571         }
572
573         if (hw->dev_spec._80003es2lan.mdic_wa_enable) {
574                 /* The "ready" bit in the MDIC register may be incorrectly set
575                  * before the device has completed the "Page Select" MDI
576                  * transaction.  So we wait 200us after each MDI command...
577                  */
578                 usec_delay(200);
579
580                 /* ...and verify the command was successful. */
581                 ret_val = e1000_read_phy_reg_mdic(hw, page_select, &temp);
582
583                 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
584                         e1000_release_phy_80003es2lan(hw);
585                         return -E1000_ERR_PHY;
586                 }
587
588                 usec_delay(200);
589
590                 ret_val = e1000_write_phy_reg_mdic(hw,
591                                                   MAX_PHY_REG_ADDRESS & offset,
592                                                   data);
593
594                 usec_delay(200);
595         } else {
596                 ret_val = e1000_write_phy_reg_mdic(hw,
597                                                   MAX_PHY_REG_ADDRESS & offset,
598                                                   data);
599         }
600
601         e1000_release_phy_80003es2lan(hw);
602
603         return ret_val;
604 }
605
606 /**
607  *  e1000_write_nvm_80003es2lan - Write to ESB2 NVM
608  *  @hw: pointer to the HW structure
609  *  @offset: offset of the register to read
610  *  @words: number of words to write
611  *  @data: buffer of data to write to the NVM
612  *
613  *  Write "words" of data to the ESB2 NVM.
614  **/
615 STATIC s32 e1000_write_nvm_80003es2lan(struct e1000_hw *hw, u16 offset,
616                                        u16 words, u16 *data)
617 {
618         DEBUGFUNC("e1000_write_nvm_80003es2lan");
619
620         return e1000_write_nvm_spi(hw, offset, words, data);
621 }
622
623 /**
624  *  e1000_get_cfg_done_80003es2lan - Wait for configuration to complete
625  *  @hw: pointer to the HW structure
626  *
627  *  Wait a specific amount of time for manageability processes to complete.
628  *  This is a function pointer entry point called by the phy module.
629  **/
630 STATIC s32 e1000_get_cfg_done_80003es2lan(struct e1000_hw *hw)
631 {
632         s32 timeout = PHY_CFG_TIMEOUT;
633         u32 mask = E1000_NVM_CFG_DONE_PORT_0;
634
635         DEBUGFUNC("e1000_get_cfg_done_80003es2lan");
636
637         if (hw->bus.func == 1)
638                 mask = E1000_NVM_CFG_DONE_PORT_1;
639
640         while (timeout) {
641                 if (E1000_READ_REG(hw, E1000_EEMNGCTL) & mask)
642                         break;
643                 msec_delay(1);
644                 timeout--;
645         }
646         if (!timeout) {
647                 DEBUGOUT("MNG configuration cycle has not completed.\n");
648                 return -E1000_ERR_RESET;
649         }
650
651         return E1000_SUCCESS;
652 }
653
654 /**
655  *  e1000_phy_force_speed_duplex_80003es2lan - Force PHY speed and duplex
656  *  @hw: pointer to the HW structure
657  *
658  *  Force the speed and duplex settings onto the PHY.  This is a
659  *  function pointer entry point called by the phy module.
660  **/
661 STATIC s32 e1000_phy_force_speed_duplex_80003es2lan(struct e1000_hw *hw)
662 {
663         s32 ret_val;
664         u16 phy_data;
665         bool link;
666
667         DEBUGFUNC("e1000_phy_force_speed_duplex_80003es2lan");
668
669         if (!(hw->phy.ops.read_reg))
670                 return E1000_SUCCESS;
671
672         /* Clear Auto-Crossover to force MDI manually.  M88E1000 requires MDI
673          * forced whenever speed and duplex are forced.
674          */
675         ret_val = hw->phy.ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
676         if (ret_val)
677                 return ret_val;
678
679         phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_AUTO;
680         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
681         if (ret_val)
682                 return ret_val;
683
684         DEBUGOUT1("GG82563 PSCR: %X\n", phy_data);
685
686         ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_data);
687         if (ret_val)
688                 return ret_val;
689
690         e1000_phy_force_speed_duplex_setup(hw, &phy_data);
691
692         /* Reset the phy to commit changes. */
693         phy_data |= MII_CR_RESET;
694
695         ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_data);
696         if (ret_val)
697                 return ret_val;
698
699         usec_delay(1);
700
701         if (hw->phy.autoneg_wait_to_complete) {
702                 DEBUGOUT("Waiting for forced speed/duplex link on GG82563 phy.\n");
703
704                 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
705                                                      100000, &link);
706                 if (ret_val)
707                         return ret_val;
708
709                 if (!link) {
710                         /* We didn't get link.
711                          * Reset the DSP and cross our fingers.
712                          */
713                         ret_val = e1000_phy_reset_dsp_generic(hw);
714                         if (ret_val)
715                                 return ret_val;
716                 }
717
718                 /* Try once more */
719                 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
720                                                      100000, &link);
721                 if (ret_val)
722                         return ret_val;
723         }
724
725         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
726                                        &phy_data);
727         if (ret_val)
728                 return ret_val;
729
730         /* Resetting the phy means we need to verify the TX_CLK corresponds
731          * to the link speed.  10Mbps -> 2.5MHz, else 25MHz.
732          */
733         phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
734         if (hw->mac.forced_speed_duplex & E1000_ALL_10_SPEED)
735                 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5;
736         else
737                 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25;
738
739         /* In addition, we must re-enable CRS on Tx for both half and full
740          * duplex.
741          */
742         phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
743         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
744                                         phy_data);
745
746         return ret_val;
747 }
748
749 /**
750  *  e1000_get_cable_length_80003es2lan - Set approximate cable length
751  *  @hw: pointer to the HW structure
752  *
753  *  Find the approximate cable length as measured by the GG82563 PHY.
754  *  This is a function pointer entry point called by the phy module.
755  **/
756 STATIC s32 e1000_get_cable_length_80003es2lan(struct e1000_hw *hw)
757 {
758         struct e1000_phy_info *phy = &hw->phy;
759         s32 ret_val;
760         u16 phy_data, index;
761
762         DEBUGFUNC("e1000_get_cable_length_80003es2lan");
763
764         if (!(hw->phy.ops.read_reg))
765                 return E1000_SUCCESS;
766
767         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_DSP_DISTANCE, &phy_data);
768         if (ret_val)
769                 return ret_val;
770
771         index = phy_data & GG82563_DSPD_CABLE_LENGTH;
772
773         if (index >= GG82563_CABLE_LENGTH_TABLE_SIZE - 5)
774                 return -E1000_ERR_PHY;
775
776         phy->min_cable_length = e1000_gg82563_cable_length_table[index];
777         phy->max_cable_length = e1000_gg82563_cable_length_table[index + 5];
778
779         phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
780
781         return E1000_SUCCESS;
782 }
783
784 /**
785  *  e1000_get_link_up_info_80003es2lan - Report speed and duplex
786  *  @hw: pointer to the HW structure
787  *  @speed: pointer to speed buffer
788  *  @duplex: pointer to duplex buffer
789  *
790  *  Retrieve the current speed and duplex configuration.
791  **/
792 STATIC s32 e1000_get_link_up_info_80003es2lan(struct e1000_hw *hw, u16 *speed,
793                                               u16 *duplex)
794 {
795         s32 ret_val;
796
797         DEBUGFUNC("e1000_get_link_up_info_80003es2lan");
798
799         if (hw->phy.media_type == e1000_media_type_copper) {
800                 ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed,
801                                                                     duplex);
802                 hw->phy.ops.cfg_on_link_up(hw);
803         } else {
804                 ret_val = e1000_get_speed_and_duplex_fiber_serdes_generic(hw,
805                                                                   speed,
806                                                                   duplex);
807         }
808
809         return ret_val;
810 }
811
812 /**
813  *  e1000_reset_hw_80003es2lan - Reset the ESB2 controller
814  *  @hw: pointer to the HW structure
815  *
816  *  Perform a global reset to the ESB2 controller.
817  **/
818 STATIC s32 e1000_reset_hw_80003es2lan(struct e1000_hw *hw)
819 {
820         u32 ctrl;
821         s32 ret_val;
822         u16 kum_reg_data;
823
824         DEBUGFUNC("e1000_reset_hw_80003es2lan");
825
826         /* Prevent the PCI-E bus from sticking if there is no TLP connection
827          * on the last TLP read/write transaction when MAC is reset.
828          */
829         ret_val = e1000_disable_pcie_master_generic(hw);
830         if (ret_val)
831                 DEBUGOUT("PCI-E Master disable polling has failed.\n");
832
833         DEBUGOUT("Masking off all interrupts\n");
834         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
835
836         E1000_WRITE_REG(hw, E1000_RCTL, 0);
837         E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
838         E1000_WRITE_FLUSH(hw);
839
840         msec_delay(10);
841
842         ctrl = E1000_READ_REG(hw, E1000_CTRL);
843
844         ret_val = e1000_acquire_phy_80003es2lan(hw);
845         DEBUGOUT("Issuing a global reset to MAC\n");
846         E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
847         e1000_release_phy_80003es2lan(hw);
848
849         /* Disable IBIST slave mode (far-end loopback) */
850         e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
851                                         &kum_reg_data);
852         kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
853         e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
854                                         kum_reg_data);
855
856         ret_val = e1000_get_auto_rd_done_generic(hw);
857         if (ret_val)
858                 /* We don't want to continue accessing MAC registers. */
859                 return ret_val;
860
861         /* Clear any pending interrupt events. */
862         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
863         E1000_READ_REG(hw, E1000_ICR);
864
865         return e1000_check_alt_mac_addr_generic(hw);
866 }
867
868 /**
869  *  e1000_init_hw_80003es2lan - Initialize the ESB2 controller
870  *  @hw: pointer to the HW structure
871  *
872  *  Initialize the hw bits, LED, VFTA, MTA, link and hw counters.
873  **/
874 STATIC s32 e1000_init_hw_80003es2lan(struct e1000_hw *hw)
875 {
876         struct e1000_mac_info *mac = &hw->mac;
877         u32 reg_data;
878         s32 ret_val;
879         u16 kum_reg_data;
880         u16 i;
881
882         DEBUGFUNC("e1000_init_hw_80003es2lan");
883
884         e1000_initialize_hw_bits_80003es2lan(hw);
885
886         /* Initialize identification LED */
887         ret_val = mac->ops.id_led_init(hw);
888         /* An error is not fatal and we should not stop init due to this */
889         if (ret_val)
890                 DEBUGOUT("Error initializing identification LED\n");
891
892         /* Disabling VLAN filtering */
893         DEBUGOUT("Initializing the IEEE VLAN\n");
894         mac->ops.clear_vfta(hw);
895
896         /* Setup the receive address. */
897         e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
898
899         /* Zero out the Multicast HASH table */
900         DEBUGOUT("Zeroing the MTA\n");
901         for (i = 0; i < mac->mta_reg_count; i++)
902                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
903
904         /* Setup link and flow control */
905         ret_val = mac->ops.setup_link(hw);
906
907         /* Disable IBIST slave mode (far-end loopback) */
908         e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
909                                         &kum_reg_data);
910         kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
911         e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
912                                          kum_reg_data);
913
914         /* Set the transmit descriptor write-back policy */
915         reg_data = E1000_READ_REG(hw, E1000_TXDCTL(0));
916         reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
917                     E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
918         E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg_data);
919
920         /* ...for both queues. */
921         reg_data = E1000_READ_REG(hw, E1000_TXDCTL(1));
922         reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
923                     E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
924         E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg_data);
925
926         /* Enable retransmit on late collisions */
927         reg_data = E1000_READ_REG(hw, E1000_TCTL);
928         reg_data |= E1000_TCTL_RTLC;
929         E1000_WRITE_REG(hw, E1000_TCTL, reg_data);
930
931         /* Configure Gigabit Carry Extend Padding */
932         reg_data = E1000_READ_REG(hw, E1000_TCTL_EXT);
933         reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
934         reg_data |= DEFAULT_TCTL_EXT_GCEX_80003ES2LAN;
935         E1000_WRITE_REG(hw, E1000_TCTL_EXT, reg_data);
936
937         /* Configure Transmit Inter-Packet Gap */
938         reg_data = E1000_READ_REG(hw, E1000_TIPG);
939         reg_data &= ~E1000_TIPG_IPGT_MASK;
940         reg_data |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
941         E1000_WRITE_REG(hw, E1000_TIPG, reg_data);
942
943         reg_data = E1000_READ_REG_ARRAY(hw, E1000_FFLT, 0x0001);
944         reg_data &= ~0x00100000;
945         E1000_WRITE_REG_ARRAY(hw, E1000_FFLT, 0x0001, reg_data);
946
947         /* default to true to enable the MDIC W/A */
948         hw->dev_spec._80003es2lan.mdic_wa_enable = true;
949
950         ret_val =
951             e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_OFFSET >>
952                                             E1000_KMRNCTRLSTA_OFFSET_SHIFT, &i);
953         if (!ret_val) {
954                 if ((i & E1000_KMRNCTRLSTA_OPMODE_MASK) ==
955                      E1000_KMRNCTRLSTA_OPMODE_INBAND_MDIO)
956                         hw->dev_spec._80003es2lan.mdic_wa_enable = false;
957         }
958
959         /* Clear all of the statistics registers (clear on read).  It is
960          * important that we do this after we have tried to establish link
961          * because the symbol error count will increment wildly if there
962          * is no link.
963          */
964         e1000_clear_hw_cntrs_80003es2lan(hw);
965
966         return ret_val;
967 }
968
969 /**
970  *  e1000_initialize_hw_bits_80003es2lan - Init hw bits of ESB2
971  *  @hw: pointer to the HW structure
972  *
973  *  Initializes required hardware-dependent bits needed for normal operation.
974  **/
975 static void e1000_initialize_hw_bits_80003es2lan(struct e1000_hw *hw)
976 {
977         u32 reg;
978
979         DEBUGFUNC("e1000_initialize_hw_bits_80003es2lan");
980
981         /* Transmit Descriptor Control 0 */
982         reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
983         reg |= (1 << 22);
984         E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
985
986         /* Transmit Descriptor Control 1 */
987         reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
988         reg |= (1 << 22);
989         E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
990
991         /* Transmit Arbitration Control 0 */
992         reg = E1000_READ_REG(hw, E1000_TARC(0));
993         reg &= ~(0xF << 27); /* 30:27 */
994         if (hw->phy.media_type != e1000_media_type_copper)
995                 reg &= ~(1 << 20);
996         E1000_WRITE_REG(hw, E1000_TARC(0), reg);
997
998         /* Transmit Arbitration Control 1 */
999         reg = E1000_READ_REG(hw, E1000_TARC(1));
1000         if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
1001                 reg &= ~(1 << 28);
1002         else
1003                 reg |= (1 << 28);
1004         E1000_WRITE_REG(hw, E1000_TARC(1), reg);
1005
1006         /* Disable IPv6 extension header parsing because some malformed
1007          * IPv6 headers can hang the Rx.
1008          */
1009         reg = E1000_READ_REG(hw, E1000_RFCTL);
1010         reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
1011         E1000_WRITE_REG(hw, E1000_RFCTL, reg);
1012
1013         return;
1014 }
1015
1016 /**
1017  *  e1000_copper_link_setup_gg82563_80003es2lan - Configure GG82563 Link
1018  *  @hw: pointer to the HW structure
1019  *
1020  *  Setup some GG82563 PHY registers for obtaining link
1021  **/
1022 static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
1023 {
1024         struct e1000_phy_info *phy = &hw->phy;
1025         s32 ret_val;
1026         u32 reg;
1027         u16 data;
1028
1029         DEBUGFUNC("e1000_copper_link_setup_gg82563_80003es2lan");
1030
1031         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &data);
1032         if (ret_val)
1033                 return ret_val;
1034
1035         data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1036         /* Use 25MHz for both link down and 1000Base-T for Tx clock. */
1037         data |= GG82563_MSCR_TX_CLK_1000MBPS_25;
1038
1039         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, data);
1040         if (ret_val)
1041                 return ret_val;
1042
1043         /* Options:
1044          *   MDI/MDI-X = 0 (default)
1045          *   0 - Auto for all speeds
1046          *   1 - MDI mode
1047          *   2 - MDI-X mode
1048          *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1049          */
1050         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_SPEC_CTRL, &data);
1051         if (ret_val)
1052                 return ret_val;
1053
1054         data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1055
1056         switch (phy->mdix) {
1057         case 1:
1058                 data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1059                 break;
1060         case 2:
1061                 data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1062                 break;
1063         case 0:
1064         default:
1065                 data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1066                 break;
1067         }
1068
1069         /* Options:
1070          *   disable_polarity_correction = 0 (default)
1071          *       Automatic Correction for Reversed Cable Polarity
1072          *   0 - Disabled
1073          *   1 - Enabled
1074          */
1075         data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1076         if (phy->disable_polarity_correction)
1077                 data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1078
1079         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_SPEC_CTRL, data);
1080         if (ret_val)
1081                 return ret_val;
1082
1083         /* SW Reset the PHY so all changes take effect */
1084         ret_val = hw->phy.ops.commit(hw);
1085         if (ret_val) {
1086                 DEBUGOUT("Error Resetting the PHY\n");
1087                 return ret_val;
1088         }
1089
1090         /* Bypass Rx and Tx FIFO's */
1091         reg = E1000_KMRNCTRLSTA_OFFSET_FIFO_CTRL;
1092         data = (E1000_KMRNCTRLSTA_FIFO_CTRL_RX_BYPASS |
1093                 E1000_KMRNCTRLSTA_FIFO_CTRL_TX_BYPASS);
1094         ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
1095         if (ret_val)
1096                 return ret_val;
1097
1098         reg = E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE;
1099         ret_val = e1000_read_kmrn_reg_80003es2lan(hw, reg, &data);
1100         if (ret_val)
1101                 return ret_val;
1102         data |= E1000_KMRNCTRLSTA_OPMODE_E_IDLE;
1103         ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
1104         if (ret_val)
1105                 return ret_val;
1106
1107         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_SPEC_CTRL_2, &data);
1108         if (ret_val)
1109                 return ret_val;
1110
1111         data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1112         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_SPEC_CTRL_2, data);
1113         if (ret_val)
1114                 return ret_val;
1115
1116         reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1117         reg &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
1118         E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1119
1120         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_PWR_MGMT_CTRL, &data);
1121         if (ret_val)
1122                 return ret_val;
1123
1124         /* Do not init these registers when the HW is in IAMT mode, since the
1125          * firmware will have already initialized them.  We only initialize
1126          * them if the HW is not in IAMT mode.
1127          */
1128         if (!hw->mac.ops.check_mng_mode(hw)) {
1129                 /* Enable Electrical Idle on the PHY */
1130                 data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1131                 ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1132                                                 data);
1133                 if (ret_val)
1134                         return ret_val;
1135
1136                 ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1137                                                &data);
1138                 if (ret_val)
1139                         return ret_val;
1140
1141                 data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1142                 ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1143                                                 data);
1144                 if (ret_val)
1145                         return ret_val;
1146         }
1147
1148         /* Workaround: Disable padding in Kumeran interface in the MAC
1149          * and in the PHY to avoid CRC errors.
1150          */
1151         ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_INBAND_CTRL, &data);
1152         if (ret_val)
1153                 return ret_val;
1154
1155         data |= GG82563_ICR_DIS_PADDING;
1156         ret_val = hw->phy.ops.write_reg(hw, GG82563_PHY_INBAND_CTRL, data);
1157         if (ret_val)
1158                 return ret_val;
1159
1160         return E1000_SUCCESS;
1161 }
1162
1163 /**
1164  *  e1000_setup_copper_link_80003es2lan - Setup Copper Link for ESB2
1165  *  @hw: pointer to the HW structure
1166  *
1167  *  Essentially a wrapper for setting up all things "copper" related.
1168  *  This is a function pointer entry point called by the mac module.
1169  **/
1170 STATIC s32 e1000_setup_copper_link_80003es2lan(struct e1000_hw *hw)
1171 {
1172         u32 ctrl;
1173         s32 ret_val;
1174         u16 reg_data;
1175
1176         DEBUGFUNC("e1000_setup_copper_link_80003es2lan");
1177
1178         ctrl = E1000_READ_REG(hw, E1000_CTRL);
1179         ctrl |= E1000_CTRL_SLU;
1180         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1181         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1182
1183         /* Set the mac to wait the maximum time between each
1184          * iteration and increase the max iterations when
1185          * polling the phy; this fixes erroneous timeouts at 10Mbps.
1186          */
1187         ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 4),
1188                                                    0xFFFF);
1189         if (ret_val)
1190                 return ret_val;
1191         ret_val = e1000_read_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
1192                                                   &reg_data);
1193         if (ret_val)
1194                 return ret_val;
1195         reg_data |= 0x3F;
1196         ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
1197                                                    reg_data);
1198         if (ret_val)
1199                 return ret_val;
1200         ret_val =
1201             e1000_read_kmrn_reg_80003es2lan(hw,
1202                                             E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
1203                                             &reg_data);
1204         if (ret_val)
1205                 return ret_val;
1206         reg_data |= E1000_KMRNCTRLSTA_INB_CTRL_DIS_PADDING;
1207         ret_val =
1208             e1000_write_kmrn_reg_80003es2lan(hw,
1209                                              E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
1210                                              reg_data);
1211         if (ret_val)
1212                 return ret_val;
1213
1214         ret_val = e1000_copper_link_setup_gg82563_80003es2lan(hw);
1215         if (ret_val)
1216                 return ret_val;
1217
1218         return e1000_setup_copper_link_generic(hw);
1219 }
1220
1221 /**
1222  *  e1000_cfg_on_link_up_80003es2lan - es2 link configuration after link-up
1223  *  @hw: pointer to the HW structure
1224  *  @duplex: current duplex setting
1225  *
1226  *  Configure the KMRN interface by applying last minute quirks for
1227  *  10/100 operation.
1228  **/
1229 static s32 e1000_cfg_on_link_up_80003es2lan(struct e1000_hw *hw)
1230 {
1231         s32 ret_val = E1000_SUCCESS;
1232         u16 speed;
1233         u16 duplex;
1234
1235         DEBUGFUNC("e1000_configure_on_link_up");
1236
1237         if (hw->phy.media_type == e1000_media_type_copper) {
1238                 ret_val = e1000_get_speed_and_duplex_copper_generic(hw, &speed,
1239                                                                     &duplex);
1240                 if (ret_val)
1241                         return ret_val;
1242
1243                 if (speed == SPEED_1000)
1244                         ret_val = e1000_cfg_kmrn_1000_80003es2lan(hw);
1245                 else
1246                         ret_val = e1000_cfg_kmrn_10_100_80003es2lan(hw, duplex);
1247         }
1248
1249         return ret_val;
1250 }
1251
1252 /**
1253  *  e1000_cfg_kmrn_10_100_80003es2lan - Apply "quirks" for 10/100 operation
1254  *  @hw: pointer to the HW structure
1255  *  @duplex: current duplex setting
1256  *
1257  *  Configure the KMRN interface by applying last minute quirks for
1258  *  10/100 operation.
1259  **/
1260 static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
1261 {
1262         s32 ret_val;
1263         u32 tipg;
1264         u32 i = 0;
1265         u16 reg_data, reg_data2;
1266
1267         DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1268
1269         reg_data = E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT;
1270         ret_val =
1271             e1000_write_kmrn_reg_80003es2lan(hw,
1272                                              E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
1273                                              reg_data);
1274         if (ret_val)
1275                 return ret_val;
1276
1277         /* Configure Transmit Inter-Packet Gap */
1278         tipg = E1000_READ_REG(hw, E1000_TIPG);
1279         tipg &= ~E1000_TIPG_IPGT_MASK;
1280         tipg |= DEFAULT_TIPG_IPGT_10_100_80003ES2LAN;
1281         E1000_WRITE_REG(hw, E1000_TIPG, tipg);
1282
1283         do {
1284                 ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1285                                                &reg_data);
1286                 if (ret_val)
1287                         return ret_val;
1288
1289                 ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1290                                                &reg_data2);
1291                 if (ret_val)
1292                         return ret_val;
1293                 i++;
1294         } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
1295
1296         if (duplex == HALF_DUPLEX)
1297                 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1298         else
1299                 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1300
1301         return hw->phy.ops.write_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1302 }
1303
1304 /**
1305  *  e1000_cfg_kmrn_1000_80003es2lan - Apply "quirks" for gigabit operation
1306  *  @hw: pointer to the HW structure
1307  *
1308  *  Configure the KMRN interface by applying last minute quirks for
1309  *  gigabit operation.
1310  **/
1311 static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw)
1312 {
1313         s32 ret_val;
1314         u16 reg_data, reg_data2;
1315         u32 tipg;
1316         u32 i = 0;
1317
1318         DEBUGFUNC("e1000_configure_kmrn_for_1000");
1319
1320         reg_data = E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT;
1321         ret_val =
1322             e1000_write_kmrn_reg_80003es2lan(hw,
1323                                              E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
1324                                              reg_data);
1325         if (ret_val)
1326                 return ret_val;
1327
1328         /* Configure Transmit Inter-Packet Gap */
1329         tipg = E1000_READ_REG(hw, E1000_TIPG);
1330         tipg &= ~E1000_TIPG_IPGT_MASK;
1331         tipg |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
1332         E1000_WRITE_REG(hw, E1000_TIPG, tipg);
1333
1334         do {
1335                 ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1336                                                &reg_data);
1337                 if (ret_val)
1338                         return ret_val;
1339
1340                 ret_val = hw->phy.ops.read_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1341                                                &reg_data2);
1342                 if (ret_val)
1343                         return ret_val;
1344                 i++;
1345         } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
1346
1347         reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1348
1349         return hw->phy.ops.write_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1350 }
1351
1352 /**
1353  *  e1000_read_kmrn_reg_80003es2lan - Read kumeran register
1354  *  @hw: pointer to the HW structure
1355  *  @offset: register offset to be read
1356  *  @data: pointer to the read data
1357  *
1358  *  Acquire semaphore, then read the PHY register at offset
1359  *  using the kumeran interface.  The information retrieved is stored in data.
1360  *  Release the semaphore before exiting.
1361  **/
1362 static s32 e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
1363                                            u16 *data)
1364 {
1365         u32 kmrnctrlsta;
1366         s32 ret_val;
1367
1368         DEBUGFUNC("e1000_read_kmrn_reg_80003es2lan");
1369
1370         ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
1371         if (ret_val)
1372                 return ret_val;
1373
1374         kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
1375                        E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
1376         E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
1377         E1000_WRITE_FLUSH(hw);
1378
1379         usec_delay(2);
1380
1381         kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
1382         *data = (u16)kmrnctrlsta;
1383
1384         e1000_release_mac_csr_80003es2lan(hw);
1385
1386         return ret_val;
1387 }
1388
1389 /**
1390  *  e1000_write_kmrn_reg_80003es2lan - Write kumeran register
1391  *  @hw: pointer to the HW structure
1392  *  @offset: register offset to write to
1393  *  @data: data to write at register offset
1394  *
1395  *  Acquire semaphore, then write the data to PHY register
1396  *  at the offset using the kumeran interface.  Release semaphore
1397  *  before exiting.
1398  **/
1399 static s32 e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
1400                                             u16 data)
1401 {
1402         u32 kmrnctrlsta;
1403         s32 ret_val;
1404
1405         DEBUGFUNC("e1000_write_kmrn_reg_80003es2lan");
1406
1407         ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
1408         if (ret_val)
1409                 return ret_val;
1410
1411         kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
1412                        E1000_KMRNCTRLSTA_OFFSET) | data;
1413         E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
1414         E1000_WRITE_FLUSH(hw);
1415
1416         usec_delay(2);
1417
1418         e1000_release_mac_csr_80003es2lan(hw);
1419
1420         return ret_val;
1421 }
1422
1423 /**
1424  *  e1000_read_mac_addr_80003es2lan - Read device MAC address
1425  *  @hw: pointer to the HW structure
1426  **/
1427 STATIC s32 e1000_read_mac_addr_80003es2lan(struct e1000_hw *hw)
1428 {
1429         s32 ret_val;
1430
1431         DEBUGFUNC("e1000_read_mac_addr_80003es2lan");
1432
1433         /* If there's an alternate MAC address place it in RAR0
1434          * so that it will override the Si installed default perm
1435          * address.
1436          */
1437         ret_val = e1000_check_alt_mac_addr_generic(hw);
1438         if (ret_val)
1439                 return ret_val;
1440
1441         return e1000_read_mac_addr_generic(hw);
1442 }
1443
1444 /**
1445  * e1000_power_down_phy_copper_80003es2lan - Remove link during PHY power down
1446  * @hw: pointer to the HW structure
1447  *
1448  * In the case of a PHY power down to save power, or to turn off link during a
1449  * driver unload, or wake on lan is not enabled, remove the link.
1450  **/
1451 STATIC void e1000_power_down_phy_copper_80003es2lan(struct e1000_hw *hw)
1452 {
1453         /* If the management interface is not enabled, then power down */
1454         if (!(hw->mac.ops.check_mng_mode(hw) ||
1455               hw->phy.ops.check_reset_block(hw)))
1456                 e1000_power_down_phy_copper(hw);
1457
1458         return;
1459 }
1460
1461 /**
1462  *  e1000_clear_hw_cntrs_80003es2lan - Clear device specific hardware counters
1463  *  @hw: pointer to the HW structure
1464  *
1465  *  Clears the hardware counters by reading the counter registers.
1466  **/
1467 STATIC void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
1468 {
1469         DEBUGFUNC("e1000_clear_hw_cntrs_80003es2lan");
1470
1471         e1000_clear_hw_cntrs_base_generic(hw);
1472
1473         E1000_READ_REG(hw, E1000_PRC64);
1474         E1000_READ_REG(hw, E1000_PRC127);
1475         E1000_READ_REG(hw, E1000_PRC255);
1476         E1000_READ_REG(hw, E1000_PRC511);
1477         E1000_READ_REG(hw, E1000_PRC1023);
1478         E1000_READ_REG(hw, E1000_PRC1522);
1479         E1000_READ_REG(hw, E1000_PTC64);
1480         E1000_READ_REG(hw, E1000_PTC127);
1481         E1000_READ_REG(hw, E1000_PTC255);
1482         E1000_READ_REG(hw, E1000_PTC511);
1483         E1000_READ_REG(hw, E1000_PTC1023);
1484         E1000_READ_REG(hw, E1000_PTC1522);
1485
1486         E1000_READ_REG(hw, E1000_ALGNERRC);
1487         E1000_READ_REG(hw, E1000_RXERRC);
1488         E1000_READ_REG(hw, E1000_TNCRS);
1489         E1000_READ_REG(hw, E1000_CEXTERR);
1490         E1000_READ_REG(hw, E1000_TSCTC);
1491         E1000_READ_REG(hw, E1000_TSCTFC);
1492
1493         E1000_READ_REG(hw, E1000_MGTPRC);
1494         E1000_READ_REG(hw, E1000_MGTPDC);
1495         E1000_READ_REG(hw, E1000_MGTPTC);
1496
1497         E1000_READ_REG(hw, E1000_IAC);
1498         E1000_READ_REG(hw, E1000_ICRXOC);
1499
1500         E1000_READ_REG(hw, E1000_ICRXPTC);
1501         E1000_READ_REG(hw, E1000_ICRXATC);
1502         E1000_READ_REG(hw, E1000_ICTXPTC);
1503         E1000_READ_REG(hw, E1000_ICTXATC);
1504         E1000_READ_REG(hw, E1000_ICTXQEC);
1505         E1000_READ_REG(hw, E1000_ICTXQMTC);
1506         E1000_READ_REG(hw, E1000_ICRXDMTC);
1507 }