ixgbe: update copyright
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe / ixgbe_82598.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 #include "ixgbe_type.h"
35 #include "ixgbe_api.h"
36 #include "ixgbe_common.h"
37 #include "ixgbe_phy.h"
38
39 u32 ixgbe_get_pcie_msix_count_82598(struct ixgbe_hw *hw);
40 s32 ixgbe_init_ops_82598(struct ixgbe_hw *hw);
41 static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
42                                              ixgbe_link_speed *speed,
43                                              bool *autoneg);
44 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw);
45 s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw, s32 packetbuf_num);
46 static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
47                                         bool autoneg_wait_to_complete);
48 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
49                                       ixgbe_link_speed *speed, bool *link_up,
50                                       bool link_up_wait_to_complete);
51 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
52                                             ixgbe_link_speed speed,
53                                             bool autoneg,
54                                             bool autoneg_wait_to_complete);
55 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
56                                                ixgbe_link_speed speed,
57                                                bool autoneg,
58                                                bool autoneg_wait_to_complete);
59 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);
60 s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw);
61 void ixgbe_enable_relaxed_ordering_82598(struct ixgbe_hw *hw);
62 s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
63 static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
64 s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan,
65                          u32 vind, bool vlan_on);
66 static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw);
67 s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val);
68 s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val);
69 s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
70                                 u8 *eeprom_data);
71 u32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw);
72 s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw);
73 void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw);
74 void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw);
75 static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb,
76                                   u32 headroom, int strategy);
77
78 /**
79  *  ixgbe_set_pcie_completion_timeout - set pci-e completion timeout
80  *  @hw: pointer to the HW structure
81  *
82  *  The defaults for 82598 should be in the range of 50us to 50ms,
83  *  however the hardware default for these parts is 500us to 1ms which is less
84  *  than the 10ms recommended by the pci-e spec.  To address this we need to
85  *  increase the value to either 10ms to 250ms for capability version 1 config,
86  *  or 16ms to 55ms for version 2.
87  **/
88 void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw)
89 {
90         u32 gcr = IXGBE_READ_REG(hw, IXGBE_GCR);
91         u16 pcie_devctl2;
92
93         /* only take action if timeout value is defaulted to 0 */
94         if (gcr & IXGBE_GCR_CMPL_TMOUT_MASK)
95                 goto out;
96
97         /*
98          * if capababilities version is type 1 we can write the
99          * timeout of 10ms to 250ms through the GCR register
100          */
101         if (!(gcr & IXGBE_GCR_CAP_VER2)) {
102                 gcr |= IXGBE_GCR_CMPL_TMOUT_10ms;
103                 goto out;
104         }
105
106         /*
107          * for version 2 capabilities we need to write the config space
108          * directly in order to set the completion timeout value for
109          * 16ms to 55ms
110          */
111         pcie_devctl2 = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2);
112         pcie_devctl2 |= IXGBE_PCI_DEVICE_CONTROL2_16ms;
113         IXGBE_WRITE_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2, pcie_devctl2);
114 out:
115         /* disable completion timeout resend */
116         gcr &= ~IXGBE_GCR_CMPL_TMOUT_RESEND;
117         IXGBE_WRITE_REG(hw, IXGBE_GCR, gcr);
118 }
119
120 /**
121  *  ixgbe_get_pcie_msix_count_82598 - Gets MSI-X vector count
122  *  @hw: pointer to hardware structure
123  *
124  *  Read PCIe configuration space, and get the MSI-X vector count from
125  *  the capabilities table.
126  **/
127 u32 ixgbe_get_pcie_msix_count_82598(struct ixgbe_hw *hw)
128 {
129         u32 msix_count = 18;
130
131         DEBUGFUNC("ixgbe_get_pcie_msix_count_82598");
132
133         if (hw->mac.msix_vectors_from_pcie) {
134                 msix_count = IXGBE_READ_PCIE_WORD(hw,
135                                                   IXGBE_PCIE_MSIX_82598_CAPS);
136                 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
137
138                 /* MSI-X count is zero-based in HW, so increment to give
139                  * proper value */
140                 msix_count++;
141         }
142         return msix_count;
143 }
144
145 /**
146  *  ixgbe_init_ops_82598 - Inits func ptrs and MAC type
147  *  @hw: pointer to hardware structure
148  *
149  *  Initialize the function pointers and assign the MAC type for 82598.
150  *  Does not touch the hardware.
151  **/
152 s32 ixgbe_init_ops_82598(struct ixgbe_hw *hw)
153 {
154         struct ixgbe_mac_info *mac = &hw->mac;
155         struct ixgbe_phy_info *phy = &hw->phy;
156         s32 ret_val;
157
158         DEBUGFUNC("ixgbe_init_ops_82598");
159
160         ret_val = ixgbe_init_phy_ops_generic(hw);
161         ret_val = ixgbe_init_ops_generic(hw);
162
163         /* PHY */
164         phy->ops.init = &ixgbe_init_phy_ops_82598;
165
166         /* MAC */
167         mac->ops.start_hw = &ixgbe_start_hw_82598;
168         mac->ops.enable_relaxed_ordering = &ixgbe_enable_relaxed_ordering_82598;
169         mac->ops.reset_hw = &ixgbe_reset_hw_82598;
170         mac->ops.get_media_type = &ixgbe_get_media_type_82598;
171         mac->ops.get_supported_physical_layer =
172                                     &ixgbe_get_supported_physical_layer_82598;
173         mac->ops.read_analog_reg8 = &ixgbe_read_analog_reg8_82598;
174         mac->ops.write_analog_reg8 = &ixgbe_write_analog_reg8_82598;
175         mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie_82598;
176
177         /* RAR, Multicast, VLAN */
178         mac->ops.set_vmdq = &ixgbe_set_vmdq_82598;
179         mac->ops.clear_vmdq = &ixgbe_clear_vmdq_82598;
180         mac->ops.set_vfta = &ixgbe_set_vfta_82598;
181         mac->ops.clear_vfta = &ixgbe_clear_vfta_82598;
182
183         /* Flow Control */
184         mac->ops.fc_enable = &ixgbe_fc_enable_82598;
185
186         mac->mcft_size       = 128;
187         mac->vft_size        = 128;
188         mac->num_rar_entries = 16;
189         mac->rx_pb_size      = 512;
190         mac->max_tx_queues   = 32;
191         mac->max_rx_queues   = 64;
192         mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82598(hw);
193
194         /* SFP+ Module */
195         phy->ops.read_i2c_eeprom = &ixgbe_read_i2c_eeprom_82598;
196
197         /* Link */
198         mac->ops.check_link = &ixgbe_check_mac_link_82598;
199         mac->ops.setup_link = &ixgbe_setup_mac_link_82598;
200         mac->ops.flap_tx_laser = NULL;
201         mac->ops.get_link_capabilities =
202                                &ixgbe_get_link_capabilities_82598;
203         mac->ops.setup_rxpba = &ixgbe_set_rxpba_82598;
204
205         /* Manageability interface */
206         mac->ops.set_fw_drv_ver = NULL;
207
208         return ret_val;
209 }
210
211 /**
212  *  ixgbe_init_phy_ops_82598 - PHY/SFP specific init
213  *  @hw: pointer to hardware structure
214  *
215  *  Initialize any function pointers that were not able to be
216  *  set during init_shared_code because the PHY/SFP type was
217  *  not known.  Perform the SFP init if necessary.
218  *
219  **/
220 s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw)
221 {
222         struct ixgbe_mac_info *mac = &hw->mac;
223         struct ixgbe_phy_info *phy = &hw->phy;
224         s32 ret_val = IXGBE_SUCCESS;
225         u16 list_offset, data_offset;
226
227         DEBUGFUNC("ixgbe_init_phy_ops_82598");
228
229         /* Identify the PHY */
230         phy->ops.identify(hw);
231
232         /* Overwrite the link function pointers if copper PHY */
233         if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
234                 mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
235                 mac->ops.get_link_capabilities =
236                                   &ixgbe_get_copper_link_capabilities_generic;
237         }
238
239         switch (hw->phy.type) {
240         case ixgbe_phy_tn:
241                 phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
242                 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
243                 phy->ops.get_firmware_version =
244                              &ixgbe_get_phy_firmware_version_tnx;
245                 break;
246         case ixgbe_phy_nl:
247                 phy->ops.reset = &ixgbe_reset_phy_nl;
248
249                 /* Call SFP+ identify routine to get the SFP+ module type */
250                 ret_val = phy->ops.identify_sfp(hw);
251                 if (ret_val != IXGBE_SUCCESS)
252                         goto out;
253                 else if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) {
254                         ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
255                         goto out;
256                 }
257
258                 /* Check to see if SFP+ module is supported */
259                 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw,
260                                                             &list_offset,
261                                                             &data_offset);
262                 if (ret_val != IXGBE_SUCCESS) {
263                         ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
264                         goto out;
265                 }
266                 break;
267         default:
268                 break;
269         }
270
271 out:
272         return ret_val;
273 }
274
275 /**
276  *  ixgbe_start_hw_82598 - Prepare hardware for Tx/Rx
277  *  @hw: pointer to hardware structure
278  *
279  *  Starts the hardware using the generic start_hw function.
280  *  Disables relaxed ordering Then set pcie completion timeout
281  *
282  **/
283 s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
284 {
285         u32 regval;
286         u32 i;
287         s32 ret_val = IXGBE_SUCCESS;
288
289         DEBUGFUNC("ixgbe_start_hw_82598");
290
291         ret_val = ixgbe_start_hw_generic(hw);
292
293         /* Disable relaxed ordering */
294         for (i = 0; ((i < hw->mac.max_tx_queues) &&
295              (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
296                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
297                 regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
298                 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
299         }
300
301         for (i = 0; ((i < hw->mac.max_rx_queues) &&
302              (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
303                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
304                 regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
305                             IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
306                 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
307         }
308
309         /* set the completion timeout for interface */
310         if (ret_val == IXGBE_SUCCESS)
311                 ixgbe_set_pcie_completion_timeout(hw);
312
313         return ret_val;
314 }
315
316 /**
317  *  ixgbe_get_link_capabilities_82598 - Determines link capabilities
318  *  @hw: pointer to hardware structure
319  *  @speed: pointer to link speed
320  *  @autoneg: boolean auto-negotiation value
321  *
322  *  Determines the link capabilities by reading the AUTOC register.
323  **/
324 static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
325                                              ixgbe_link_speed *speed,
326                                              bool *autoneg)
327 {
328         s32 status = IXGBE_SUCCESS;
329         u32 autoc = 0;
330
331         DEBUGFUNC("ixgbe_get_link_capabilities_82598");
332
333         /*
334          * Determine link capabilities based on the stored value of AUTOC,
335          * which represents EEPROM defaults.  If AUTOC value has not been
336          * stored, use the current register value.
337          */
338         if (hw->mac.orig_link_settings_stored)
339                 autoc = hw->mac.orig_autoc;
340         else
341                 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
342
343         switch (autoc & IXGBE_AUTOC_LMS_MASK) {
344         case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
345                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
346                 *autoneg = FALSE;
347                 break;
348
349         case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
350                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
351                 *autoneg = FALSE;
352                 break;
353
354         case IXGBE_AUTOC_LMS_1G_AN:
355                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
356                 *autoneg = TRUE;
357                 break;
358
359         case IXGBE_AUTOC_LMS_KX4_AN:
360         case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
361                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
362                 if (autoc & IXGBE_AUTOC_KX4_SUPP)
363                         *speed |= IXGBE_LINK_SPEED_10GB_FULL;
364                 if (autoc & IXGBE_AUTOC_KX_SUPP)
365                         *speed |= IXGBE_LINK_SPEED_1GB_FULL;
366                 *autoneg = TRUE;
367                 break;
368
369         default:
370                 status = IXGBE_ERR_LINK_SETUP;
371                 break;
372         }
373
374         return status;
375 }
376
377 /**
378  *  ixgbe_get_media_type_82598 - Determines media type
379  *  @hw: pointer to hardware structure
380  *
381  *  Returns the media type (fiber, copper, backplane)
382  **/
383 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
384 {
385         enum ixgbe_media_type media_type;
386
387         DEBUGFUNC("ixgbe_get_media_type_82598");
388
389         /* Detect if there is a copper PHY attached. */
390         switch (hw->phy.type) {
391         case ixgbe_phy_cu_unknown:
392         case ixgbe_phy_tn:
393                 media_type = ixgbe_media_type_copper;
394                 goto out;
395         default:
396                 break;
397         }
398
399         /* Media type for I82598 is based on device ID */
400         switch (hw->device_id) {
401         case IXGBE_DEV_ID_82598:
402         case IXGBE_DEV_ID_82598_BX:
403                 /* Default device ID is mezzanine card KX/KX4 */
404                 media_type = ixgbe_media_type_backplane;
405                 break;
406         case IXGBE_DEV_ID_82598AF_DUAL_PORT:
407         case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
408         case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
409         case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
410         case IXGBE_DEV_ID_82598EB_XF_LR:
411         case IXGBE_DEV_ID_82598EB_SFP_LOM:
412                 media_type = ixgbe_media_type_fiber;
413                 break;
414         case IXGBE_DEV_ID_82598EB_CX4:
415         case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
416                 media_type = ixgbe_media_type_cx4;
417                 break;
418         case IXGBE_DEV_ID_82598AT:
419         case IXGBE_DEV_ID_82598AT2:
420                 media_type = ixgbe_media_type_copper;
421                 break;
422         default:
423                 media_type = ixgbe_media_type_unknown;
424                 break;
425         }
426 out:
427         return media_type;
428 }
429
430 /**
431  *  ixgbe_fc_enable_82598 - Enable flow control
432  *  @hw: pointer to hardware structure
433  *  @packetbuf_num: packet buffer number (0-7)
434  *
435  *  Enable flow control according to the current settings.
436  **/
437 s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw, s32 packetbuf_num)
438 {
439         s32 ret_val = IXGBE_SUCCESS;
440         u32 fctrl_reg;
441         u32 rmcs_reg;
442         u32 reg;
443         u32 link_speed = 0;
444         bool link_up;
445
446         DEBUGFUNC("ixgbe_fc_enable_82598");
447
448         /*
449          * On 82598 having Rx FC on causes resets while doing 1G
450          * so if it's on turn it off once we know link_speed. For
451          * more details see 82598 Specification update.
452          */
453         hw->mac.ops.check_link(hw, &link_speed, &link_up, FALSE);
454         if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) {
455                 switch (hw->fc.requested_mode) {
456                 case ixgbe_fc_full:
457                         hw->fc.requested_mode = ixgbe_fc_tx_pause;
458                         break;
459                 case ixgbe_fc_rx_pause:
460                         hw->fc.requested_mode = ixgbe_fc_none;
461                         break;
462                 default:
463                         /* no change */
464                         break;
465                 }
466         }
467
468         /* Negotiate the fc mode to use */
469         ret_val = ixgbe_fc_autoneg(hw);
470         if (ret_val == IXGBE_ERR_FLOW_CONTROL)
471                 goto out;
472
473         /* Disable any previous flow control settings */
474         fctrl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
475         fctrl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
476
477         rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
478         rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
479
480         /*
481          * The possible values of fc.current_mode are:
482          * 0: Flow control is completely disabled
483          * 1: Rx flow control is enabled (we can receive pause frames,
484          *    but not send pause frames).
485          * 2: Tx flow control is enabled (we can send pause frames but
486          *     we do not support receiving pause frames).
487          * 3: Both Rx and Tx flow control (symmetric) are enabled.
488          * other: Invalid.
489          */
490         switch (hw->fc.current_mode) {
491         case ixgbe_fc_none:
492                 /*
493                  * Flow control is disabled by software override or autoneg.
494                  * The code below will actually disable it in the HW.
495                  */
496                 break;
497         case ixgbe_fc_rx_pause:
498                 /*
499                  * Rx Flow control is enabled and Tx Flow control is
500                  * disabled by software override. Since there really
501                  * isn't a way to advertise that we are capable of RX
502                  * Pause ONLY, we will advertise that we support both
503                  * symmetric and asymmetric Rx PAUSE.  Later, we will
504                  * disable the adapter's ability to send PAUSE frames.
505                  */
506                 fctrl_reg |= IXGBE_FCTRL_RFCE;
507                 break;
508         case ixgbe_fc_tx_pause:
509                 /*
510                  * Tx Flow control is enabled, and Rx Flow control is
511                  * disabled by software override.
512                  */
513                 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
514                 break;
515         case ixgbe_fc_full:
516                 /* Flow control (both Rx and Tx) is enabled by SW override. */
517                 fctrl_reg |= IXGBE_FCTRL_RFCE;
518                 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
519                 break;
520         default:
521                 DEBUGOUT("Flow control param set incorrectly\n");
522                 ret_val = IXGBE_ERR_CONFIG;
523                 goto out;
524                 break;
525         }
526
527         /* Set 802.3x based flow control settings. */
528         fctrl_reg |= IXGBE_FCTRL_DPF;
529         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl_reg);
530         IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
531
532         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
533         if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
534                 reg = hw->fc.low_water << 6;
535                 if (hw->fc.send_xon)
536                         reg |= IXGBE_FCRTL_XONE;
537
538                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num), reg);
539
540                 reg = hw->fc.high_water[packetbuf_num] << 6;
541                 reg |= IXGBE_FCRTH_FCEN;
542
543                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num), reg);
544         }
545
546         /* Configure pause time (2 TCs per register) */
547         reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
548         if ((packetbuf_num & 1) == 0)
549                 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
550         else
551                 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
552         IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
553
554         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
555
556 out:
557         return ret_val;
558 }
559
560 /**
561  *  ixgbe_start_mac_link_82598 - Configures MAC link settings
562  *  @hw: pointer to hardware structure
563  *
564  *  Configures link settings based on values in the ixgbe_hw struct.
565  *  Restarts the link.  Performs autonegotiation if needed.
566  **/
567 static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
568                                       bool autoneg_wait_to_complete)
569 {
570         u32 autoc_reg;
571         u32 links_reg;
572         u32 i;
573         s32 status = IXGBE_SUCCESS;
574
575         DEBUGFUNC("ixgbe_start_mac_link_82598");
576
577         /* Restart link */
578         autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
579         autoc_reg |= IXGBE_AUTOC_AN_RESTART;
580         IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
581
582         /* Only poll for autoneg to complete if specified to do so */
583         if (autoneg_wait_to_complete) {
584                 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
585                      IXGBE_AUTOC_LMS_KX4_AN ||
586                     (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
587                      IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
588                         links_reg = 0; /* Just in case Autoneg time = 0 */
589                         for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
590                                 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
591                                 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
592                                         break;
593                                 msec_delay(100);
594                         }
595                         if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
596                                 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
597                                 DEBUGOUT("Autonegotiation did not complete.\n");
598                         }
599                 }
600         }
601
602         /* Add delay to filter out noises during initial link setup */
603         msec_delay(50);
604
605         return status;
606 }
607
608 /**
609  *  ixgbe_validate_link_ready - Function looks for phy link
610  *  @hw: pointer to hardware structure
611  *
612  *  Function indicates success when phy link is available. If phy is not ready
613  *  within 5 seconds of MAC indicating link, the function returns error.
614  **/
615 static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw)
616 {
617         u32 timeout;
618         u16 an_reg;
619
620         if (hw->device_id != IXGBE_DEV_ID_82598AT2)
621                 return IXGBE_SUCCESS;
622
623         for (timeout = 0;
624              timeout < IXGBE_VALIDATE_LINK_READY_TIMEOUT; timeout++) {
625                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
626                                      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &an_reg);
627
628                 if ((an_reg & IXGBE_MII_AUTONEG_COMPLETE) &&
629                     (an_reg & IXGBE_MII_AUTONEG_LINK_UP))
630                         break;
631
632                 msec_delay(100);
633         }
634
635         if (timeout == IXGBE_VALIDATE_LINK_READY_TIMEOUT) {
636                 DEBUGOUT("Link was indicated but link is down\n");
637                 return IXGBE_ERR_LINK_SETUP;
638         }
639
640         return IXGBE_SUCCESS;
641 }
642
643 /**
644  *  ixgbe_check_mac_link_82598 - Get link/speed status
645  *  @hw: pointer to hardware structure
646  *  @speed: pointer to link speed
647  *  @link_up: TRUE is link is up, FALSE otherwise
648  *  @link_up_wait_to_complete: bool used to wait for link up or not
649  *
650  *  Reads the links register to determine if link is up and the current speed
651  **/
652 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
653                                       ixgbe_link_speed *speed, bool *link_up,
654                                       bool link_up_wait_to_complete)
655 {
656         u32 links_reg;
657         u32 i;
658         u16 link_reg, adapt_comp_reg;
659
660         DEBUGFUNC("ixgbe_check_mac_link_82598");
661
662         /*
663          * SERDES PHY requires us to read link status from undocumented
664          * register 0xC79F.  Bit 0 set indicates link is up/ready; clear
665          * indicates link down.  OxC00C is read to check that the XAUI lanes
666          * are active.  Bit 0 clear indicates active; set indicates inactive.
667          */
668         if (hw->phy.type == ixgbe_phy_nl) {
669                 hw->phy.ops.read_reg(hw, 0xC79F, IXGBE_TWINAX_DEV, &link_reg);
670                 hw->phy.ops.read_reg(hw, 0xC79F, IXGBE_TWINAX_DEV, &link_reg);
671                 hw->phy.ops.read_reg(hw, 0xC00C, IXGBE_TWINAX_DEV,
672                                      &adapt_comp_reg);
673                 if (link_up_wait_to_complete) {
674                         for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
675                                 if ((link_reg & 1) &&
676                                     ((adapt_comp_reg & 1) == 0)) {
677                                         *link_up = TRUE;
678                                         break;
679                                 } else {
680                                         *link_up = FALSE;
681                                 }
682                                 msec_delay(100);
683                                 hw->phy.ops.read_reg(hw, 0xC79F,
684                                                      IXGBE_TWINAX_DEV,
685                                                      &link_reg);
686                                 hw->phy.ops.read_reg(hw, 0xC00C,
687                                                      IXGBE_TWINAX_DEV,
688                                                      &adapt_comp_reg);
689                         }
690                 } else {
691                         if ((link_reg & 1) && ((adapt_comp_reg & 1) == 0))
692                                 *link_up = TRUE;
693                         else
694                                 *link_up = FALSE;
695                 }
696
697                 if (*link_up == FALSE)
698                         goto out;
699         }
700
701         links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
702         if (link_up_wait_to_complete) {
703                 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
704                         if (links_reg & IXGBE_LINKS_UP) {
705                                 *link_up = TRUE;
706                                 break;
707                         } else {
708                                 *link_up = FALSE;
709                         }
710                         msec_delay(100);
711                         links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
712                 }
713         } else {
714                 if (links_reg & IXGBE_LINKS_UP)
715                         *link_up = TRUE;
716                 else
717                         *link_up = FALSE;
718         }
719
720         if (links_reg & IXGBE_LINKS_SPEED)
721                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
722         else
723                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
724
725         if ((hw->device_id == IXGBE_DEV_ID_82598AT2) && (*link_up == TRUE) &&
726             (ixgbe_validate_link_ready(hw) != IXGBE_SUCCESS))
727                 *link_up = FALSE;
728
729         /* if link is down, zero out the current_mode */
730         if (*link_up == FALSE) {
731                 hw->fc.current_mode = ixgbe_fc_none;
732                 hw->fc.fc_was_autonegged = FALSE;
733         }
734 out:
735         return IXGBE_SUCCESS;
736 }
737
738 /**
739  *  ixgbe_setup_mac_link_82598 - Set MAC link speed
740  *  @hw: pointer to hardware structure
741  *  @speed: new link speed
742  *  @autoneg: TRUE if autonegotiation enabled
743  *  @autoneg_wait_to_complete: TRUE when waiting for completion is needed
744  *
745  *  Set the link speed in the AUTOC register and restarts link.
746  **/
747 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
748                                            ixgbe_link_speed speed, bool autoneg,
749                                            bool autoneg_wait_to_complete)
750 {
751         s32              status            = IXGBE_SUCCESS;
752         ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
753         u32              curr_autoc        = IXGBE_READ_REG(hw, IXGBE_AUTOC);
754         u32              autoc             = curr_autoc;
755         u32              link_mode         = autoc & IXGBE_AUTOC_LMS_MASK;
756
757         DEBUGFUNC("ixgbe_setup_mac_link_82598");
758
759         /* Check to see if speed passed in is supported. */
760         ixgbe_get_link_capabilities(hw, &link_capabilities, &autoneg);
761         speed &= link_capabilities;
762
763         if (speed == IXGBE_LINK_SPEED_UNKNOWN)
764                 status = IXGBE_ERR_LINK_SETUP;
765
766         /* Set KX4/KX support according to speed requested */
767         else if (link_mode == IXGBE_AUTOC_LMS_KX4_AN ||
768                  link_mode == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
769                 autoc &= ~IXGBE_AUTOC_KX4_KX_SUPP_MASK;
770                 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
771                         autoc |= IXGBE_AUTOC_KX4_SUPP;
772                 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
773                         autoc |= IXGBE_AUTOC_KX_SUPP;
774                 if (autoc != curr_autoc)
775                         IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
776         }
777
778         if (status == IXGBE_SUCCESS) {
779                 /*
780                  * Setup and restart the link based on the new values in
781                  * ixgbe_hw This will write the AUTOC register based on the new
782                  * stored values
783                  */
784                 status = ixgbe_start_mac_link_82598(hw,
785                                                     autoneg_wait_to_complete);
786         }
787
788         return status;
789 }
790
791
792 /**
793  *  ixgbe_setup_copper_link_82598 - Set the PHY autoneg advertised field
794  *  @hw: pointer to hardware structure
795  *  @speed: new link speed
796  *  @autoneg: TRUE if autonegotiation enabled
797  *  @autoneg_wait_to_complete: TRUE if waiting is needed to complete
798  *
799  *  Sets the link speed in the AUTOC register in the MAC and restarts link.
800  **/
801 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
802                                                ixgbe_link_speed speed,
803                                                bool autoneg,
804                                                bool autoneg_wait_to_complete)
805 {
806         s32 status;
807
808         DEBUGFUNC("ixgbe_setup_copper_link_82598");
809
810         /* Setup the PHY according to input speed */
811         status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
812                                               autoneg_wait_to_complete);
813         /* Set up MAC */
814         ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete);
815
816         return status;
817 }
818
819 /**
820  *  ixgbe_reset_hw_82598 - Performs hardware reset
821  *  @hw: pointer to hardware structure
822  *
823  *  Resets the hardware by resetting the transmit and receive units, masks and
824  *  clears all interrupts, performing a PHY reset, and performing a link (MAC)
825  *  reset.
826  **/
827 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
828 {
829         s32 status = IXGBE_SUCCESS;
830         s32 phy_status = IXGBE_SUCCESS;
831         u32 ctrl;
832         u32 gheccr;
833         u32 i;
834         u32 autoc;
835         u8  analog_val;
836
837         DEBUGFUNC("ixgbe_reset_hw_82598");
838
839         /* Call adapter stop to disable tx/rx and clear interrupts */
840         status = hw->mac.ops.stop_adapter(hw);
841         if (status != IXGBE_SUCCESS)
842                 goto reset_hw_out;
843
844         /*
845          * Power up the Atlas Tx lanes if they are currently powered down.
846          * Atlas Tx lanes are powered down for MAC loopback tests, but
847          * they are not automatically restored on reset.
848          */
849         hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
850         if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
851                 /* Enable Tx Atlas so packets can be transmitted again */
852                 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
853                                              &analog_val);
854                 analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
855                 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
856                                               analog_val);
857
858                 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
859                                              &analog_val);
860                 analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
861                 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
862                                               analog_val);
863
864                 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
865                                              &analog_val);
866                 analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
867                 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
868                                               analog_val);
869
870                 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
871                                              &analog_val);
872                 analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
873                 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
874                                               analog_val);
875         }
876
877         /* Reset PHY */
878         if (hw->phy.reset_disable == FALSE) {
879                 /* PHY ops must be identified and initialized prior to reset */
880
881                 /* Init PHY and function pointers, perform SFP setup */
882                 phy_status = hw->phy.ops.init(hw);
883                 if (phy_status == IXGBE_ERR_SFP_NOT_SUPPORTED)
884                         goto reset_hw_out;
885                 if (phy_status == IXGBE_ERR_SFP_NOT_PRESENT)
886                         goto mac_reset_top;
887
888                 hw->phy.ops.reset(hw);
889         }
890
891 mac_reset_top:
892         /*
893          * Issue global reset to the MAC.  This needs to be a SW reset.
894          * If link reset is used, it might reset the MAC when mng is using it
895          */
896         ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL) | IXGBE_CTRL_RST;
897         IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
898         IXGBE_WRITE_FLUSH(hw);
899
900         /* Poll for reset bit to self-clear indicating reset is complete */
901         for (i = 0; i < 10; i++) {
902                 usec_delay(1);
903                 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
904                 if (!(ctrl & IXGBE_CTRL_RST))
905                         break;
906         }
907         if (ctrl & IXGBE_CTRL_RST) {
908                 status = IXGBE_ERR_RESET_FAILED;
909                 DEBUGOUT("Reset polling failed to complete.\n");
910         }
911
912         msec_delay(50);
913
914         /*
915          * Double resets are required for recovery from certain error
916          * conditions.  Between resets, it is necessary to stall to allow time
917          * for any pending HW events to complete.
918          */
919         if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
920                 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
921                 goto mac_reset_top;
922         }
923
924         gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
925         gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
926         IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
927
928         /*
929          * Store the original AUTOC value if it has not been
930          * stored off yet.  Otherwise restore the stored original
931          * AUTOC value since the reset operation sets back to deaults.
932          */
933         autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
934         if (hw->mac.orig_link_settings_stored == FALSE) {
935                 hw->mac.orig_autoc = autoc;
936                 hw->mac.orig_link_settings_stored = TRUE;
937         } else if (autoc != hw->mac.orig_autoc) {
938                 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc);
939         }
940
941         /* Store the permanent mac address */
942         hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
943
944         /*
945          * Store MAC address from RAR0, clear receive address registers, and
946          * clear the multicast table
947          */
948         hw->mac.ops.init_rx_addrs(hw);
949
950 reset_hw_out:
951         if (phy_status != IXGBE_SUCCESS)
952                 status = phy_status;
953
954         return status;
955 }
956
957 /**
958  *  ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
959  *  @hw: pointer to hardware struct
960  *  @rar: receive address register index to associate with a VMDq index
961  *  @vmdq: VMDq set index
962  **/
963 s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
964 {
965         u32 rar_high;
966         u32 rar_entries = hw->mac.num_rar_entries;
967
968         DEBUGFUNC("ixgbe_set_vmdq_82598");
969
970         /* Make sure we are using a valid rar index range */
971         if (rar >= rar_entries) {
972                 DEBUGOUT1("RAR index %d is out of range.\n", rar);
973                 return IXGBE_ERR_INVALID_ARGUMENT;
974         }
975
976         rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
977         rar_high &= ~IXGBE_RAH_VIND_MASK;
978         rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
979         IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
980         return IXGBE_SUCCESS;
981 }
982
983 /**
984  *  ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
985  *  @hw: pointer to hardware struct
986  *  @rar: receive address register index to associate with a VMDq index
987  *  @vmdq: VMDq clear index (not used in 82598, but elsewhere)
988  **/
989 static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
990 {
991         u32 rar_high;
992         u32 rar_entries = hw->mac.num_rar_entries;
993
994         UNREFERENCED_1PARAMETER(vmdq);
995
996         /* Make sure we are using a valid rar index range */
997         if (rar >= rar_entries) {
998                 DEBUGOUT1("RAR index %d is out of range.\n", rar);
999                 return IXGBE_ERR_INVALID_ARGUMENT;
1000         }
1001
1002         rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
1003         if (rar_high & IXGBE_RAH_VIND_MASK) {
1004                 rar_high &= ~IXGBE_RAH_VIND_MASK;
1005                 IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
1006         }
1007
1008         return IXGBE_SUCCESS;
1009 }
1010
1011 /**
1012  *  ixgbe_set_vfta_82598 - Set VLAN filter table
1013  *  @hw: pointer to hardware structure
1014  *  @vlan: VLAN id to write to VLAN filter
1015  *  @vind: VMDq output index that maps queue to VLAN id in VFTA
1016  *  @vlan_on: boolean flag to turn on/off VLAN in VFTA
1017  *
1018  *  Turn on/off specified VLAN in the VLAN filter table.
1019  **/
1020 s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
1021                                                       bool vlan_on)
1022 {
1023         u32 regindex;
1024         u32 bitindex;
1025         u32 bits;
1026         u32 vftabyte;
1027
1028         DEBUGFUNC("ixgbe_set_vfta_82598");
1029
1030         if (vlan > 4095)
1031                 return IXGBE_ERR_PARAM;
1032
1033         /* Determine 32-bit word position in array */
1034         regindex = (vlan >> 5) & 0x7F;   /* upper seven bits */
1035
1036         /* Determine the location of the (VMD) queue index */
1037         vftabyte =  ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
1038         bitindex = (vlan & 0x7) << 2;    /* lower 3 bits indicate nibble */
1039
1040         /* Set the nibble for VMD queue index */
1041         bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
1042         bits &= (~(0x0F << bitindex));
1043         bits |= (vind << bitindex);
1044         IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
1045
1046         /* Determine the location of the bit for this VLAN id */
1047         bitindex = vlan & 0x1F;   /* lower five bits */
1048
1049         bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
1050         if (vlan_on)
1051                 /* Turn on this VLAN id */
1052                 bits |= (1 << bitindex);
1053         else
1054                 /* Turn off this VLAN id */
1055                 bits &= ~(1 << bitindex);
1056         IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
1057
1058         return IXGBE_SUCCESS;
1059 }
1060
1061 /**
1062  *  ixgbe_clear_vfta_82598 - Clear VLAN filter table
1063  *  @hw: pointer to hardware structure
1064  *
1065  *  Clears the VLAN filer table, and the VMDq index associated with the filter
1066  **/
1067 static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
1068 {
1069         u32 offset;
1070         u32 vlanbyte;
1071
1072         DEBUGFUNC("ixgbe_clear_vfta_82598");
1073
1074         for (offset = 0; offset < hw->mac.vft_size; offset++)
1075                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
1076
1077         for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
1078                 for (offset = 0; offset < hw->mac.vft_size; offset++)
1079                         IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
1080                                         0);
1081
1082         return IXGBE_SUCCESS;
1083 }
1084
1085 /**
1086  *  ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
1087  *  @hw: pointer to hardware structure
1088  *  @reg: analog register to read
1089  *  @val: read value
1090  *
1091  *  Performs read operation to Atlas analog register specified.
1092  **/
1093 s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
1094 {
1095         u32  atlas_ctl;
1096
1097         DEBUGFUNC("ixgbe_read_analog_reg8_82598");
1098
1099         IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
1100                         IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
1101         IXGBE_WRITE_FLUSH(hw);
1102         usec_delay(10);
1103         atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
1104         *val = (u8)atlas_ctl;
1105
1106         return IXGBE_SUCCESS;
1107 }
1108
1109 /**
1110  *  ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
1111  *  @hw: pointer to hardware structure
1112  *  @reg: atlas register to write
1113  *  @val: value to write
1114  *
1115  *  Performs write operation to Atlas analog register specified.
1116  **/
1117 s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
1118 {
1119         u32  atlas_ctl;
1120
1121         DEBUGFUNC("ixgbe_write_analog_reg8_82598");
1122
1123         atlas_ctl = (reg << 8) | val;
1124         IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
1125         IXGBE_WRITE_FLUSH(hw);
1126         usec_delay(10);
1127
1128         return IXGBE_SUCCESS;
1129 }
1130
1131 /**
1132  *  ixgbe_read_i2c_eeprom_82598 - Reads 8 bit word over I2C interface.
1133  *  @hw: pointer to hardware structure
1134  *  @byte_offset: EEPROM byte offset to read
1135  *  @eeprom_data: value read
1136  *
1137  *  Performs 8 byte read operation to SFP module's EEPROM over I2C interface.
1138  **/
1139 s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
1140                                 u8 *eeprom_data)
1141 {
1142         s32 status = IXGBE_SUCCESS;
1143         u16 sfp_addr = 0;
1144         u16 sfp_data = 0;
1145         u16 sfp_stat = 0;
1146         u32 i;
1147
1148         DEBUGFUNC("ixgbe_read_i2c_eeprom_82598");
1149
1150         if (hw->phy.type == ixgbe_phy_nl) {
1151                 /*
1152                  * NetLogic phy SDA/SCL registers are at addresses 0xC30A to
1153                  * 0xC30D. These registers are used to talk to the SFP+
1154                  * module's EEPROM through the SDA/SCL (I2C) interface.
1155                  */
1156                 sfp_addr = (IXGBE_I2C_EEPROM_DEV_ADDR << 8) + byte_offset;
1157                 sfp_addr = (sfp_addr | IXGBE_I2C_EEPROM_READ_MASK);
1158                 hw->phy.ops.write_reg(hw,
1159                                       IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR,
1160                                       IXGBE_MDIO_PMA_PMD_DEV_TYPE,
1161                                       sfp_addr);
1162
1163                 /* Poll status */
1164                 for (i = 0; i < 100; i++) {
1165                         hw->phy.ops.read_reg(hw,
1166                                              IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT,
1167                                              IXGBE_MDIO_PMA_PMD_DEV_TYPE,
1168                                              &sfp_stat);
1169                         sfp_stat = sfp_stat & IXGBE_I2C_EEPROM_STATUS_MASK;
1170                         if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS)
1171                                 break;
1172                         msec_delay(10);
1173                 }
1174
1175                 if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_PASS) {
1176                         DEBUGOUT("EEPROM read did not pass.\n");
1177                         status = IXGBE_ERR_SFP_NOT_PRESENT;
1178                         goto out;
1179                 }
1180
1181                 /* Read data */
1182                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA,
1183                                      IXGBE_MDIO_PMA_PMD_DEV_TYPE, &sfp_data);
1184
1185                 *eeprom_data = (u8)(sfp_data >> 8);
1186         } else {
1187                 status = IXGBE_ERR_PHY;
1188                 goto out;
1189         }
1190
1191 out:
1192         return status;
1193 }
1194
1195 /**
1196  *  ixgbe_get_supported_physical_layer_82598 - Returns physical layer type
1197  *  @hw: pointer to hardware structure
1198  *
1199  *  Determines physical layer capabilities of the current configuration.
1200  **/
1201 u32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw)
1202 {
1203         u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1204         u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1205         u32 pma_pmd_10g = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
1206         u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
1207         u16 ext_ability = 0;
1208
1209         DEBUGFUNC("ixgbe_get_supported_physical_layer_82598");
1210
1211         hw->phy.ops.identify(hw);
1212
1213         /* Copper PHY must be checked before AUTOC LMS to determine correct
1214          * physical layer because 10GBase-T PHYs use LMS = KX4/KX */
1215         switch (hw->phy.type) {
1216         case ixgbe_phy_tn:
1217         case ixgbe_phy_cu_unknown:
1218                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
1219                 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
1220                 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
1221                         physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
1222                 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
1223                         physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
1224                 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
1225                         physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
1226                 goto out;
1227         default:
1228                 break;
1229         }
1230
1231         switch (autoc & IXGBE_AUTOC_LMS_MASK) {
1232         case IXGBE_AUTOC_LMS_1G_AN:
1233         case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
1234                 if (pma_pmd_1g == IXGBE_AUTOC_1G_KX)
1235                         physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX;
1236                 else
1237                         physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_BX;
1238                 break;
1239         case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
1240                 if (pma_pmd_10g == IXGBE_AUTOC_10G_CX4)
1241                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
1242                 else if (pma_pmd_10g == IXGBE_AUTOC_10G_KX4)
1243                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1244                 else /* XAUI */
1245                         physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1246                 break;
1247         case IXGBE_AUTOC_LMS_KX4_AN:
1248         case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
1249                 if (autoc & IXGBE_AUTOC_KX_SUPP)
1250                         physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
1251                 if (autoc & IXGBE_AUTOC_KX4_SUPP)
1252                         physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1253                 break;
1254         default:
1255                 break;
1256         }
1257
1258         if (hw->phy.type == ixgbe_phy_nl) {
1259                 hw->phy.ops.identify_sfp(hw);
1260
1261                 switch (hw->phy.sfp_type) {
1262                 case ixgbe_sfp_type_da_cu:
1263                         physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1264                         break;
1265                 case ixgbe_sfp_type_sr:
1266                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1267                         break;
1268                 case ixgbe_sfp_type_lr:
1269                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1270                         break;
1271                 default:
1272                         physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1273                         break;
1274                 }
1275         }
1276
1277         switch (hw->device_id) {
1278         case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
1279                 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1280                 break;
1281         case IXGBE_DEV_ID_82598AF_DUAL_PORT:
1282         case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
1283         case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
1284                 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1285                 break;
1286         case IXGBE_DEV_ID_82598EB_XF_LR:
1287                 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1288                 break;
1289         default:
1290                 break;
1291         }
1292
1293 out:
1294         return physical_layer;
1295 }
1296
1297 /**
1298  *  ixgbe_set_lan_id_multi_port_pcie_82598 - Set LAN id for PCIe multiple
1299  *  port devices.
1300  *  @hw: pointer to the HW structure
1301  *
1302  *  Calls common function and corrects issue with some single port devices
1303  *  that enable LAN1 but not LAN0.
1304  **/
1305 void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw)
1306 {
1307         struct ixgbe_bus_info *bus = &hw->bus;
1308         u16 pci_gen = 0;
1309         u16 pci_ctrl2 = 0;
1310
1311         DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie_82598");
1312
1313         ixgbe_set_lan_id_multi_port_pcie(hw);
1314
1315         /* check if LAN0 is disabled */
1316         hw->eeprom.ops.read(hw, IXGBE_PCIE_GENERAL_PTR, &pci_gen);
1317         if ((pci_gen != 0) && (pci_gen != 0xFFFF)) {
1318
1319                 hw->eeprom.ops.read(hw, pci_gen + IXGBE_PCIE_CTRL2, &pci_ctrl2);
1320
1321                 /* if LAN0 is completely disabled force function to 0 */
1322                 if ((pci_ctrl2 & IXGBE_PCIE_CTRL2_LAN_DISABLE) &&
1323                     !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DISABLE_SELECT) &&
1324                     !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DUMMY_ENABLE)) {
1325
1326                         bus->func = 0;
1327                 }
1328         }
1329 }
1330
1331 /**
1332  *  ixgbe_enable_relaxed_ordering_82598 - enable relaxed ordering
1333  *  @hw: pointer to hardware structure
1334  *
1335  **/
1336 void ixgbe_enable_relaxed_ordering_82598(struct ixgbe_hw *hw)
1337 {
1338         u32 regval;
1339         u32 i;
1340
1341         DEBUGFUNC("ixgbe_enable_relaxed_ordering_82598");
1342
1343         /* Enable relaxed ordering */
1344         for (i = 0; ((i < hw->mac.max_tx_queues) &&
1345              (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
1346                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
1347                 regval |= IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1348                 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
1349         }
1350
1351         for (i = 0; ((i < hw->mac.max_rx_queues) &&
1352              (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
1353                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
1354                 regval |= (IXGBE_DCA_RXCTRL_DESC_WRO_EN |
1355                            IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
1356                 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
1357         }
1358
1359 }
1360
1361 /**
1362  * ixgbe_set_rxpba_82598 - Initialize RX packet buffer
1363  * @hw: pointer to hardware structure
1364  * @num_pb: number of packet buffers to allocate
1365  * @headroom: reserve n KB of headroom
1366  * @strategy: packet buffer allocation strategy
1367  **/
1368 static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb,
1369                                   u32 headroom, int strategy)
1370 {
1371         u32 rxpktsize = IXGBE_RXPBSIZE_64KB;
1372         u8 i = 0;
1373         UNREFERENCED_1PARAMETER(headroom);
1374
1375         if (!num_pb)
1376                 return;
1377
1378         /* Setup Rx packet buffer sizes */
1379         switch (strategy) {
1380         case PBA_STRATEGY_WEIGHTED:
1381                 /* Setup the first four at 80KB */
1382                 rxpktsize = IXGBE_RXPBSIZE_80KB;
1383                 for (; i < 4; i++)
1384                         IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
1385                 /* Setup the last four at 48KB...don't re-init i */
1386                 rxpktsize = IXGBE_RXPBSIZE_48KB;
1387                 /* Fall Through */
1388         case PBA_STRATEGY_EQUAL:
1389         default:
1390                 /* Divide the remaining Rx packet buffer evenly among the TCs */
1391                 for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
1392                         IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
1393                 break;
1394         }
1395
1396         /* Setup Tx packet buffer sizes */
1397         for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++)
1398                 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), IXGBE_TXPBSIZE_40KB);
1399
1400         return;
1401 }