blob: 50b399c1e87f7c43139c7439f7df636c68839efb [file] [log] [blame]
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
31
32#include "ixgbe.h"
33#include "ixgbe_phy.h"
34
35#define IXGBE_82599_MAX_TX_QUEUES 128
36#define IXGBE_82599_MAX_RX_QUEUES 128
37#define IXGBE_82599_RAR_ENTRIES 128
38#define IXGBE_82599_MC_TBL_SIZE 128
39#define IXGBE_82599_VFT_TBL_SIZE 128
40
41s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
42 ixgbe_link_speed *speed,
43 bool *autoneg);
44enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw);
45s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw);
46s32 ixgbe_setup_mac_link_speed_multispeed_fiber(struct ixgbe_hw *hw,
47 ixgbe_link_speed speed, bool autoneg,
48 bool autoneg_wait_to_complete);
49s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw);
50s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw,
51 ixgbe_link_speed *speed,
52 bool *link_up, bool link_up_wait_to_complete);
53s32 ixgbe_setup_mac_link_speed_82599(struct ixgbe_hw *hw,
54 ixgbe_link_speed speed,
55 bool autoneg,
56 bool autoneg_wait_to_complete);
57static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
58 ixgbe_link_speed *speed,
59 bool *autoneg);
60static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw);
61static s32 ixgbe_setup_copper_link_speed_82599(struct ixgbe_hw *hw,
62 ixgbe_link_speed speed,
63 bool autoneg,
64 bool autoneg_wait_to_complete);
65s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw);
66s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
67s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
68s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan,
69 u32 vind, bool vlan_on);
70s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw);
71s32 ixgbe_blink_led_stop_82599(struct ixgbe_hw *hw, u32 index);
72s32 ixgbe_blink_led_start_82599(struct ixgbe_hw *hw, u32 index);
73s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw);
74s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val);
75s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val);
76s32 ixgbe_start_hw_rev_0_82599(struct ixgbe_hw *hw);
77s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw);
78s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw);
79u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw);
80
81void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
82{
83 struct ixgbe_mac_info *mac = &hw->mac;
84 if (hw->phy.multispeed_fiber) {
85 /* Set up dual speed SFP+ support */
86 mac->ops.setup_link =
87 &ixgbe_setup_mac_link_multispeed_fiber;
88 mac->ops.setup_link_speed =
89 &ixgbe_setup_mac_link_speed_multispeed_fiber;
90 } else {
91 mac->ops.setup_link =
92 &ixgbe_setup_mac_link_82599;
93 mac->ops.setup_link_speed =
94 &ixgbe_setup_mac_link_speed_82599;
95 }
96}
97
98s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
99{
100 s32 ret_val = 0;
101 u16 list_offset, data_offset, data_value;
102
103 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
104 ixgbe_init_mac_link_ops_82599(hw);
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000105
106 hw->phy.ops.reset = NULL;
107
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000108 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
109 &data_offset);
110
111 if (ret_val != 0)
112 goto setup_sfp_out;
113
114 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
115 while (data_value != 0xffff) {
116 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
117 IXGBE_WRITE_FLUSH(hw);
118 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
119 }
120 /* Now restart DSP */
121 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, 0x00000102);
122 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, 0x00000b1d);
123 IXGBE_WRITE_FLUSH(hw);
124 }
125
126setup_sfp_out:
127 return ret_val;
128}
129
130/**
131 * ixgbe_get_pcie_msix_count_82599 - Gets MSI-X vector count
132 * @hw: pointer to hardware structure
133 *
134 * Read PCIe configuration space, and get the MSI-X vector count from
135 * the capabilities table.
136 **/
137u32 ixgbe_get_pcie_msix_count_82599(struct ixgbe_hw *hw)
138{
139 struct ixgbe_adapter *adapter = hw->back;
140 u16 msix_count;
141 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
142 &msix_count);
143 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
144
145 /* MSI-X count is zero-based in HW, so increment to give proper value */
146 msix_count++;
147
148 return msix_count;
149}
150
151static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
152{
153 struct ixgbe_mac_info *mac = &hw->mac;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000154
155 ixgbe_init_mac_link_ops_82599(hw);
156
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000157 mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
158 mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
159 mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
160 mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
161 mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
162 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82599(hw);
163
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000164 return 0;
165}
166
167/**
168 * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
169 * @hw: pointer to hardware structure
170 *
171 * Initialize any function pointers that were not able to be
172 * set during get_invariants because the PHY/SFP type was
173 * not known. Perform the SFP init if necessary.
174 *
175 **/
176s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
177{
178 struct ixgbe_mac_info *mac = &hw->mac;
179 struct ixgbe_phy_info *phy = &hw->phy;
180 s32 ret_val = 0;
181
182 /* Identify the PHY or SFP module */
183 ret_val = phy->ops.identify(hw);
184
185 /* Setup function pointers based on detected SFP module and speeds */
186 ixgbe_init_mac_link_ops_82599(hw);
187
188 /* If copper media, overwrite with copper function pointers */
189 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
190 mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
191 mac->ops.setup_link_speed =
192 &ixgbe_setup_copper_link_speed_82599;
193 mac->ops.get_link_capabilities =
194 &ixgbe_get_copper_link_capabilities_82599;
195 }
196
197 /* Set necessary function pointers based on phy type */
198 switch (hw->phy.type) {
199 case ixgbe_phy_tn:
200 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
201 phy->ops.get_firmware_version =
202 &ixgbe_get_phy_firmware_version_tnx;
203 break;
204 default:
205 break;
206 }
207
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000208 return ret_val;
209}
210
211/**
212 * ixgbe_get_link_capabilities_82599 - Determines link capabilities
213 * @hw: pointer to hardware structure
214 * @speed: pointer to link speed
215 * @negotiation: true when autoneg or autotry is enabled
216 *
217 * Determines the link capabilities by reading the AUTOC register.
218 **/
219s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
220 ixgbe_link_speed *speed,
221 bool *negotiation)
222{
223 s32 status = 0;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000224 u32 autoc = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000225
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000226 /*
227 * Determine link capabilities based on the stored value of AUTOC,
228 * which represents EEPROM defaults. If AUTOC value has not been
229 * stored, use the current register value.
230 */
231 if (hw->mac.orig_link_settings_stored)
232 autoc = hw->mac.orig_autoc;
233 else
234 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
235
236 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000237 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
238 *speed = IXGBE_LINK_SPEED_1GB_FULL;
239 *negotiation = false;
240 break;
241
242 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
243 *speed = IXGBE_LINK_SPEED_10GB_FULL;
244 *negotiation = false;
245 break;
246
247 case IXGBE_AUTOC_LMS_1G_AN:
248 *speed = IXGBE_LINK_SPEED_1GB_FULL;
249 *negotiation = true;
250 break;
251
252 case IXGBE_AUTOC_LMS_10G_SERIAL:
253 *speed = IXGBE_LINK_SPEED_10GB_FULL;
254 *negotiation = false;
255 break;
256
257 case IXGBE_AUTOC_LMS_KX4_KX_KR:
258 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
259 *speed = IXGBE_LINK_SPEED_UNKNOWN;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000260 if (autoc & IXGBE_AUTOC_KR_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000261 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000262 if (autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000263 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000264 if (autoc & IXGBE_AUTOC_KX_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000265 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
266 *negotiation = true;
267 break;
268
269 case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
270 *speed = IXGBE_LINK_SPEED_100_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000271 if (autoc & IXGBE_AUTOC_KR_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000272 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000273 if (autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000274 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000275 if (autoc & IXGBE_AUTOC_KX_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000276 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
277 *negotiation = true;
278 break;
279
280 case IXGBE_AUTOC_LMS_SGMII_1G_100M:
281 *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
282 *negotiation = false;
283 break;
284
285 default:
286 status = IXGBE_ERR_LINK_SETUP;
287 goto out;
288 break;
289 }
290
291 if (hw->phy.multispeed_fiber) {
292 *speed |= IXGBE_LINK_SPEED_10GB_FULL |
293 IXGBE_LINK_SPEED_1GB_FULL;
294 *negotiation = true;
295 }
296
297out:
298 return status;
299}
300
301/**
302 * ixgbe_get_copper_link_capabilities_82599 - Determines link capabilities
303 * @hw: pointer to hardware structure
304 * @speed: pointer to link speed
305 * @autoneg: boolean auto-negotiation value
306 *
307 * Determines the link capabilities by reading the AUTOC register.
308 **/
309static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
310 ixgbe_link_speed *speed,
311 bool *autoneg)
312{
313 s32 status = IXGBE_ERR_LINK_SETUP;
314 u16 speed_ability;
315
316 *speed = 0;
317 *autoneg = true;
318
319 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
320 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
321 &speed_ability);
322
323 if (status == 0) {
324 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
325 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
326 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
327 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
328 }
329
330 return status;
331}
332
333/**
334 * ixgbe_get_media_type_82599 - Get media type
335 * @hw: pointer to hardware structure
336 *
337 * Returns the media type (fiber, copper, backplane)
338 **/
339enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
340{
341 enum ixgbe_media_type media_type;
342
343 /* Detect if there is a copper PHY attached. */
344 if (hw->phy.type == ixgbe_phy_cu_unknown ||
345 hw->phy.type == ixgbe_phy_tn) {
346 media_type = ixgbe_media_type_copper;
347 goto out;
348 }
349
350 switch (hw->device_id) {
351 case IXGBE_DEV_ID_82599:
352 case IXGBE_DEV_ID_82599_KX4:
353 /* Default device ID is mezzanine card KX/KX4 */
354 media_type = ixgbe_media_type_backplane;
355 break;
356 case IXGBE_DEV_ID_82599_SFP:
357 media_type = ixgbe_media_type_fiber;
358 break;
359 default:
360 media_type = ixgbe_media_type_unknown;
361 break;
362 }
363out:
364 return media_type;
365}
366
367/**
368 * ixgbe_setup_mac_link_82599 - Setup MAC link settings
369 * @hw: pointer to hardware structure
370 *
371 * Configures link settings based on values in the ixgbe_hw struct.
372 * Restarts the link. Performs autonegotiation if needed.
373 **/
374s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw)
375{
376 u32 autoc_reg;
377 u32 links_reg;
378 u32 i;
379 s32 status = 0;
380
381 /* Restart link */
382 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
383 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
384 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
385
386 /* Only poll for autoneg to complete if specified to do so */
387 if (hw->phy.autoneg_wait_to_complete) {
388 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
389 IXGBE_AUTOC_LMS_KX4_KX_KR ||
390 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
391 IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
392 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
393 IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
394 links_reg = 0; /* Just in case Autoneg time = 0 */
395 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
396 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
397 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
398 break;
399 msleep(100);
400 }
401 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
402 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
403 hw_dbg(hw, "Autoneg did not complete.\n");
404 }
405 }
406 }
407
408 /* Set up flow control */
409 status = ixgbe_setup_fc_generic(hw, 0);
410
411 /* Add delay to filter out noises during initial link setup */
412 msleep(50);
413
414 return status;
415}
416
417/**
418 * ixgbe_setup_mac_link_multispeed_fiber - Setup MAC link settings
419 * @hw: pointer to hardware structure
420 *
421 * Configures link settings based on values in the ixgbe_hw struct.
422 * Restarts the link for multi-speed fiber at 1G speed, if link
423 * fails at 10G.
424 * Performs autonegotiation if needed.
425 **/
426s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw)
427{
428 s32 status = 0;
429 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_82599_AUTONEG;
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000430 status = ixgbe_setup_mac_link_speed_multispeed_fiber(hw, link_speed,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000431 true, true);
432 return status;
433}
434
435/**
436 * ixgbe_setup_mac_link_speed_multispeed_fiber - Set MAC link speed
437 * @hw: pointer to hardware structure
438 * @speed: new link speed
439 * @autoneg: true if autonegotiation enabled
440 * @autoneg_wait_to_complete: true when waiting for completion is needed
441 *
442 * Set the link speed in the AUTOC register and restarts link.
443 **/
444s32 ixgbe_setup_mac_link_speed_multispeed_fiber(struct ixgbe_hw *hw,
445 ixgbe_link_speed speed,
446 bool autoneg,
447 bool autoneg_wait_to_complete)
448{
449 s32 status = 0;
450 ixgbe_link_speed phy_link_speed;
451 ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
452 u32 speedcnt = 0;
453 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
454 bool link_up = false;
455 bool negotiation;
456
457 /* Mask off requested but non-supported speeds */
458 hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
459 speed &= phy_link_speed;
460
461 /*
462 * Try each speed one by one, highest priority first. We do this in
463 * software because 10gb fiber doesn't support speed autonegotiation.
464 */
465 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
466 speedcnt++;
467 highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
468
469 /* Set hardware SDP's */
470 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
471 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
472
473 ixgbe_setup_mac_link_speed_82599(hw,
474 IXGBE_LINK_SPEED_10GB_FULL,
475 autoneg,
476 autoneg_wait_to_complete);
477
478 msleep(50);
479
480 /* If we have link, just jump out */
481 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
482 if (link_up)
483 goto out;
484 }
485
486 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
487 speedcnt++;
488 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
489 highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
490
491 /* Set hardware SDP's */
492 esdp_reg &= ~IXGBE_ESDP_SDP5;
493 esdp_reg |= IXGBE_ESDP_SDP5_DIR;
494 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
495
496 ixgbe_setup_mac_link_speed_82599(
497 hw, IXGBE_LINK_SPEED_1GB_FULL, autoneg,
498 autoneg_wait_to_complete);
499
500 msleep(50);
501
502 /* If we have link, just jump out */
503 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
504 if (link_up)
505 goto out;
506 }
507
508 /*
509 * We didn't get link. Configure back to the highest speed we tried,
510 * (if there was more than one). We call ourselves back with just the
511 * single highest speed that the user requested.
512 */
513 if (speedcnt > 1)
514 status = ixgbe_setup_mac_link_speed_multispeed_fiber(hw,
515 highest_link_speed,
516 autoneg,
517 autoneg_wait_to_complete);
518
519out:
520 return status;
521}
522
523/**
524 * ixgbe_check_mac_link_82599 - Determine link and speed status
525 * @hw: pointer to hardware structure
526 * @speed: pointer to link speed
527 * @link_up: true when link is up
528 * @link_up_wait_to_complete: bool used to wait for link up or not
529 *
530 * Reads the links register to determine if link is up and the current speed
531 **/
532s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
533 bool *link_up, bool link_up_wait_to_complete)
534{
535 u32 links_reg;
536 u32 i;
537
538 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
539 if (link_up_wait_to_complete) {
540 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
541 if (links_reg & IXGBE_LINKS_UP) {
542 *link_up = true;
543 break;
544 } else {
545 *link_up = false;
546 }
547 msleep(100);
548 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
549 }
550 } else {
551 if (links_reg & IXGBE_LINKS_UP)
552 *link_up = true;
553 else
554 *link_up = false;
555 }
556
557 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
558 IXGBE_LINKS_SPEED_10G_82599)
559 *speed = IXGBE_LINK_SPEED_10GB_FULL;
560 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
561 IXGBE_LINKS_SPEED_1G_82599)
562 *speed = IXGBE_LINK_SPEED_1GB_FULL;
563 else
564 *speed = IXGBE_LINK_SPEED_100_FULL;
565
566
567 return 0;
568}
569
570/**
571 * ixgbe_setup_mac_link_speed_82599 - Set MAC link speed
572 * @hw: pointer to hardware structure
573 * @speed: new link speed
574 * @autoneg: true if autonegotiation enabled
575 * @autoneg_wait_to_complete: true when waiting for completion is needed
576 *
577 * Set the link speed in the AUTOC register and restarts link.
578 **/
579s32 ixgbe_setup_mac_link_speed_82599(struct ixgbe_hw *hw,
580 ixgbe_link_speed speed, bool autoneg,
581 bool autoneg_wait_to_complete)
582{
583 s32 status = 0;
584 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
585 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000586 u32 orig_autoc = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000587 u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
588 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
589 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
590 u32 links_reg;
591 u32 i;
592 ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
593
594 /* Check to see if speed passed in is supported. */
595 hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
596 speed &= link_capabilities;
597
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000598 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
599 if (hw->mac.orig_link_settings_stored)
600 orig_autoc = hw->mac.orig_autoc;
601 else
602 orig_autoc = autoc;
603
604
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000605 if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
606 status = IXGBE_ERR_LINK_SETUP;
607 } else if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
608 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
609 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
610 /* Set KX4/KX/KR support according to speed requested */
611 autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
612 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000613 if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000614 autoc |= IXGBE_AUTOC_KX4_SUPP;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000615 if (orig_autoc & IXGBE_AUTOC_KR_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000616 autoc |= IXGBE_AUTOC_KR_SUPP;
617 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
618 autoc |= IXGBE_AUTOC_KX_SUPP;
619 } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
620 (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
621 link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
622 /* Switch from 1G SFI to 10G SFI if requested */
623 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
624 (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
625 autoc &= ~IXGBE_AUTOC_LMS_MASK;
626 autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
627 }
628 } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
629 (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
630 /* Switch from 10G SFI to 1G SFI if requested */
631 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
632 (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
633 autoc &= ~IXGBE_AUTOC_LMS_MASK;
634 if (autoneg)
635 autoc |= IXGBE_AUTOC_LMS_1G_AN;
636 else
637 autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
638 }
639 }
640
641 if (status == 0) {
642 /* Restart link */
643 autoc |= IXGBE_AUTOC_AN_RESTART;
644 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
645
646 /* Only poll for autoneg to complete if specified to do so */
647 if (autoneg_wait_to_complete) {
648 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
649 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
650 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
651 links_reg = 0; /*Just in case Autoneg time=0*/
652 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
653 links_reg =
654 IXGBE_READ_REG(hw, IXGBE_LINKS);
655 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
656 break;
657 msleep(100);
658 }
659 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
660 status =
661 IXGBE_ERR_AUTONEG_NOT_COMPLETE;
662 hw_dbg(hw, "Autoneg did not "
663 "complete.\n");
664 }
665 }
666 }
667
668 /* Set up flow control */
669 status = ixgbe_setup_fc_generic(hw, 0);
670
671 /* Add delay to filter out noises during initial link setup */
672 msleep(50);
673 }
674
675 return status;
676}
677
678/**
679 * ixgbe_setup_copper_link_82599 - Setup copper link settings
680 * @hw: pointer to hardware structure
681 *
682 * Restarts the link on PHY and then MAC. Performs autonegotiation if needed.
683 **/
684static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw)
685{
686 s32 status;
687
688 /* Restart autonegotiation on PHY */
689 status = hw->phy.ops.setup_link(hw);
690
691 /* Set up MAC */
692 ixgbe_setup_mac_link_82599(hw);
693
694 return status;
695}
696
697/**
698 * ixgbe_setup_copper_link_speed_82599 - Set the PHY autoneg advertised field
699 * @hw: pointer to hardware structure
700 * @speed: new link speed
701 * @autoneg: true if autonegotiation enabled
702 * @autoneg_wait_to_complete: true if waiting is needed to complete
703 *
704 * Restarts link on PHY and MAC based on settings passed in.
705 **/
706static s32 ixgbe_setup_copper_link_speed_82599(struct ixgbe_hw *hw,
707 ixgbe_link_speed speed,
708 bool autoneg,
709 bool autoneg_wait_to_complete)
710{
711 s32 status;
712
713 /* Setup the PHY according to input speed */
714 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
715 autoneg_wait_to_complete);
716 /* Set up MAC */
717 ixgbe_setup_mac_link_82599(hw);
718
719 return status;
720}
721
722/**
723 * ixgbe_reset_hw_82599 - Perform hardware reset
724 * @hw: pointer to hardware structure
725 *
726 * Resets the hardware by resetting the transmit and receive units, masks
727 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
728 * reset.
729 **/
730s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
731{
732 s32 status = 0;
733 u32 ctrl, ctrl_ext;
734 u32 i;
735 u32 autoc;
736 u32 autoc2;
737
738 /* Call adapter stop to disable tx/rx and clear interrupts */
739 hw->mac.ops.stop_adapter(hw);
740
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000741 /* PHY ops must be identified and initialized prior to reset */
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000742
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000743 /* Init PHY and function pointers, perform SFP setup */
744 status = hw->phy.ops.init(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000745
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000746 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
747 goto reset_hw_out;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000748
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000749 /* Setup SFP module if there is one present. */
750 if (hw->phy.sfp_setup_needed) {
751 status = hw->mac.ops.setup_sfp(hw);
752 hw->phy.sfp_setup_needed = false;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000753 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000754
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000755 /* Reset PHY */
756 if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
757 hw->phy.ops.reset(hw);
758
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000759 /*
760 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
761 * access and verify no pending requests before reset
762 */
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000763 status = ixgbe_disable_pcie_master(hw);
764 if (status != 0) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000765 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
766 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
767 }
768
769 /*
770 * Issue global reset to the MAC. This needs to be a SW reset.
771 * If link reset is used, it might reset the MAC when mng is using it
772 */
773 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
774 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
775 IXGBE_WRITE_FLUSH(hw);
776
777 /* Poll for reset bit to self-clear indicating reset is complete */
778 for (i = 0; i < 10; i++) {
779 udelay(1);
780 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
781 if (!(ctrl & IXGBE_CTRL_RST))
782 break;
783 }
784 if (ctrl & IXGBE_CTRL_RST) {
785 status = IXGBE_ERR_RESET_FAILED;
786 hw_dbg(hw, "Reset polling failed to complete.\n");
787 }
788 /* Clear PF Reset Done bit so PF/VF Mail Ops can work */
789 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
790 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
791 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
792
793 msleep(50);
794
795
796
797 /*
798 * Store the original AUTOC/AUTOC2 values if they have not been
799 * stored off yet. Otherwise restore the stored original
800 * values since the reset operation sets back to defaults.
801 */
802 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
803 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
804 if (hw->mac.orig_link_settings_stored == false) {
805 hw->mac.orig_autoc = autoc;
806 hw->mac.orig_autoc2 = autoc2;
807 hw->mac.orig_link_settings_stored = true;
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000808 } else {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000809 if (autoc != hw->mac.orig_autoc)
810 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
811 IXGBE_AUTOC_AN_RESTART));
812
813 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
814 (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
815 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
816 autoc2 |= (hw->mac.orig_autoc2 &
817 IXGBE_AUTOC2_UPPER_MASK);
818 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
819 }
820 }
821
822 /* Store the permanent mac address */
823 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
824
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000825reset_hw_out:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000826 return status;
827}
828
829/**
830 * ixgbe_clear_vmdq_82599 - Disassociate a VMDq pool index from a rx address
831 * @hw: pointer to hardware struct
832 * @rar: receive address register index to disassociate
833 * @vmdq: VMDq pool index to remove from the rar
834 **/
835s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
836{
837 u32 mpsar_lo, mpsar_hi;
838 u32 rar_entries = hw->mac.num_rar_entries;
839
840 if (rar < rar_entries) {
841 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
842 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
843
844 if (!mpsar_lo && !mpsar_hi)
845 goto done;
846
847 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
848 if (mpsar_lo) {
849 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
850 mpsar_lo = 0;
851 }
852 if (mpsar_hi) {
853 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
854 mpsar_hi = 0;
855 }
856 } else if (vmdq < 32) {
857 mpsar_lo &= ~(1 << vmdq);
858 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
859 } else {
860 mpsar_hi &= ~(1 << (vmdq - 32));
861 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
862 }
863
864 /* was that the last pool using this rar? */
865 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
866 hw->mac.ops.clear_rar(hw, rar);
867 } else {
868 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
869 }
870
871done:
872 return 0;
873}
874
875/**
876 * ixgbe_set_vmdq_82599 - Associate a VMDq pool index with a rx address
877 * @hw: pointer to hardware struct
878 * @rar: receive address register index to associate with a VMDq index
879 * @vmdq: VMDq pool index
880 **/
881s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
882{
883 u32 mpsar;
884 u32 rar_entries = hw->mac.num_rar_entries;
885
886 if (rar < rar_entries) {
887 if (vmdq < 32) {
888 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
889 mpsar |= 1 << vmdq;
890 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
891 } else {
892 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
893 mpsar |= 1 << (vmdq - 32);
894 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
895 }
896 } else {
897 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
898 }
899 return 0;
900}
901
902/**
903 * ixgbe_set_vfta_82599 - Set VLAN filter table
904 * @hw: pointer to hardware structure
905 * @vlan: VLAN id to write to VLAN filter
906 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
907 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
908 *
909 * Turn on/off specified VLAN in the VLAN filter table.
910 **/
911s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan, u32 vind,
912 bool vlan_on)
913{
914 u32 regindex;
915 u32 bitindex;
916 u32 bits;
917 u32 first_empty_slot;
918
919 if (vlan > 4095)
920 return IXGBE_ERR_PARAM;
921
922 /*
923 * this is a 2 part operation - first the VFTA, then the
924 * VLVF and VLVFB if vind is set
925 */
926
927 /* Part 1
928 * The VFTA is a bitstring made up of 128 32-bit registers
929 * that enable the particular VLAN id, much like the MTA:
930 * bits[11-5]: which register
931 * bits[4-0]: which bit in the register
932 */
933 regindex = (vlan >> 5) & 0x7F;
934 bitindex = vlan & 0x1F;
935 bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
936 if (vlan_on)
937 bits |= (1 << bitindex);
938 else
939 bits &= ~(1 << bitindex);
940 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
941
942
943 /* Part 2
944 * If the vind is set
945 * Either vlan_on
946 * make sure the vlan is in VLVF
947 * set the vind bit in the matching VLVFB
948 * Or !vlan_on
949 * clear the pool bit and possibly the vind
950 */
951 if (vind) {
952 /* find the vlanid or the first empty slot */
953 first_empty_slot = 0;
954
955 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
956 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
957 if (!bits && !first_empty_slot)
958 first_empty_slot = regindex;
959 else if ((bits & 0x0FFF) == vlan)
960 break;
961 }
962
963 if (regindex >= IXGBE_VLVF_ENTRIES) {
964 if (first_empty_slot)
965 regindex = first_empty_slot;
966 else {
967 hw_dbg(hw, "No space in VLVF.\n");
968 goto out;
969 }
970 }
971
972 if (vlan_on) {
973 /* set the pool bit */
974 if (vind < 32) {
975 bits = IXGBE_READ_REG(hw,
976 IXGBE_VLVFB(regindex * 2));
977 bits |= (1 << vind);
978 IXGBE_WRITE_REG(hw,
979 IXGBE_VLVFB(regindex * 2), bits);
980 } else {
981 bits = IXGBE_READ_REG(hw,
982 IXGBE_VLVFB((regindex * 2) + 1));
983 bits |= (1 << vind);
984 IXGBE_WRITE_REG(hw,
985 IXGBE_VLVFB((regindex * 2) + 1), bits);
986 }
987 } else {
988 /* clear the pool bit */
989 if (vind < 32) {
990 bits = IXGBE_READ_REG(hw,
991 IXGBE_VLVFB(regindex * 2));
992 bits &= ~(1 << vind);
993 IXGBE_WRITE_REG(hw,
994 IXGBE_VLVFB(regindex * 2), bits);
995 bits |= IXGBE_READ_REG(hw,
996 IXGBE_VLVFB((regindex * 2) + 1));
997 } else {
998 bits = IXGBE_READ_REG(hw,
999 IXGBE_VLVFB((regindex * 2) + 1));
1000 bits &= ~(1 << vind);
1001 IXGBE_WRITE_REG(hw,
1002 IXGBE_VLVFB((regindex * 2) + 1), bits);
1003 bits |= IXGBE_READ_REG(hw,
1004 IXGBE_VLVFB(regindex * 2));
1005 }
1006 }
1007
1008 if (bits)
1009 IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex),
1010 (IXGBE_VLVF_VIEN | vlan));
1011 else
1012 IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex), 0);
1013 }
1014
1015out:
1016 return 0;
1017}
1018
1019/**
1020 * ixgbe_clear_vfta_82599 - Clear VLAN filter table
1021 * @hw: pointer to hardware structure
1022 *
1023 * Clears the VLAN filer table, and the VMDq index associated with the filter
1024 **/
1025s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw)
1026{
1027 u32 offset;
1028
1029 for (offset = 0; offset < hw->mac.vft_size; offset++)
1030 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
1031
1032 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
1033 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
1034 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
1035 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
1036 }
1037
1038 return 0;
1039}
1040
1041/**
1042 * ixgbe_blink_led_start_82599 - Blink LED based on index.
1043 * @hw: pointer to hardware structure
1044 * @index: led number to blink
1045 **/
1046s32 ixgbe_blink_led_start_82599(struct ixgbe_hw *hw, u32 index)
1047{
1048 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1049
1050 led_reg &= ~IXGBE_LED_MODE_MASK(index);
1051 led_reg |= IXGBE_LED_BLINK(index);
1052 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1053 IXGBE_WRITE_FLUSH(hw);
1054
1055 return 0;
1056}
1057
1058/**
1059 * ixgbe_blink_led_stop_82599 - Stop blinking LED based on index.
1060 * @hw: pointer to hardware structure
1061 * @index: led number to stop blinking
1062 **/
1063s32 ixgbe_blink_led_stop_82599(struct ixgbe_hw *hw, u32 index)
1064{
1065 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1066
1067 led_reg &= ~IXGBE_LED_MODE_MASK(index);
1068 led_reg &= ~IXGBE_LED_BLINK(index);
1069 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1070 IXGBE_WRITE_FLUSH(hw);
1071
1072 return 0;
1073}
1074
1075/**
1076 * ixgbe_init_uta_tables_82599 - Initialize the Unicast Table Array
1077 * @hw: pointer to hardware structure
1078 **/
1079s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw)
1080{
1081 int i;
1082 hw_dbg(hw, " Clearing UTA\n");
1083
1084 for (i = 0; i < 128; i++)
1085 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
1086
1087 return 0;
1088}
1089
1090/**
1091 * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
1092 * @hw: pointer to hardware structure
1093 * @reg: analog register to read
1094 * @val: read value
1095 *
1096 * Performs read operation to Omer analog register specified.
1097 **/
1098s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
1099{
1100 u32 core_ctl;
1101
1102 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
1103 (reg << 8));
1104 IXGBE_WRITE_FLUSH(hw);
1105 udelay(10);
1106 core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
1107 *val = (u8)core_ctl;
1108
1109 return 0;
1110}
1111
1112/**
1113 * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
1114 * @hw: pointer to hardware structure
1115 * @reg: atlas register to write
1116 * @val: value to write
1117 *
1118 * Performs write operation to Omer analog register specified.
1119 **/
1120s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
1121{
1122 u32 core_ctl;
1123
1124 core_ctl = (reg << 8) | val;
1125 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
1126 IXGBE_WRITE_FLUSH(hw);
1127 udelay(10);
1128
1129 return 0;
1130}
1131
1132/**
1133 * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
1134 * @hw: pointer to hardware structure
1135 *
1136 * Starts the hardware using the generic start_hw function.
1137 * Then performs device-specific:
1138 * Clears the rate limiter registers.
1139 **/
1140s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
1141{
1142 u32 q_num;
1143
1144 ixgbe_start_hw_generic(hw);
1145
1146 /* Clear the rate limiters */
1147 for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
1148 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
1149 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
1150 }
1151 IXGBE_WRITE_FLUSH(hw);
1152
1153 return 0;
1154}
1155
1156/**
1157 * ixgbe_identify_phy_82599 - Get physical layer module
1158 * @hw: pointer to hardware structure
1159 *
1160 * Determines the physical layer module found on the current adapter.
1161 **/
1162s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
1163{
1164 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1165 status = ixgbe_identify_phy_generic(hw);
1166 if (status != 0)
1167 status = ixgbe_identify_sfp_module_generic(hw);
1168 return status;
1169}
1170
1171/**
1172 * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
1173 * @hw: pointer to hardware structure
1174 *
1175 * Determines physical layer capabilities of the current configuration.
1176 **/
1177u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
1178{
1179 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
PJ Waskiewicz1339b9e2009-03-13 22:12:29 +00001180 u8 comp_codes_10g = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001181
1182 switch (hw->device_id) {
1183 case IXGBE_DEV_ID_82599:
1184 case IXGBE_DEV_ID_82599_KX4:
1185 /* Default device ID is mezzanine card KX/KX4 */
1186 physical_layer = (IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
1187 IXGBE_PHYSICAL_LAYER_1000BASE_KX);
1188 break;
1189 case IXGBE_DEV_ID_82599_SFP:
1190 hw->phy.ops.identify_sfp(hw);
1191
1192 switch (hw->phy.sfp_type) {
1193 case ixgbe_sfp_type_da_cu:
PJ Waskiewicz1339b9e2009-03-13 22:12:29 +00001194 case ixgbe_sfp_type_da_cu_core0:
1195 case ixgbe_sfp_type_da_cu_core1:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001196 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1197 break;
1198 case ixgbe_sfp_type_sr:
1199 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1200 break;
1201 case ixgbe_sfp_type_lr:
1202 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1203 break;
PJ Waskiewicz1339b9e2009-03-13 22:12:29 +00001204 case ixgbe_sfp_type_srlr_core0:
1205 case ixgbe_sfp_type_srlr_core1:
1206 hw->phy.ops.read_i2c_eeprom(hw,
1207 IXGBE_SFF_10GBE_COMP_CODES,
1208 &comp_codes_10g);
1209 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1210 physical_layer =
1211 IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1212 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1213 physical_layer =
1214 IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1215 else
1216 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001217 default:
1218 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1219 break;
1220 }
1221 break;
1222 default:
1223 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1224 break;
1225 }
1226
1227 return physical_layer;
1228}
1229
1230/**
1231 * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
1232 * @hw: pointer to hardware structure
1233 * @regval: register value to write to RXCTRL
1234 *
1235 * Enables the Rx DMA unit for 82599
1236 **/
1237s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
1238{
1239#define IXGBE_MAX_SECRX_POLL 30
1240 int i;
1241 int secrxreg;
1242
1243 /*
1244 * Workaround for 82599 silicon errata when enabling the Rx datapath.
1245 * If traffic is incoming before we enable the Rx unit, it could hang
1246 * the Rx DMA unit. Therefore, make sure the security engine is
1247 * completely disabled prior to enabling the Rx unit.
1248 */
1249 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
1250 secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
1251 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
1252 for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
1253 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
1254 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
1255 break;
1256 else
1257 udelay(10);
1258 }
1259
1260 /* For informational purposes only */
1261 if (i >= IXGBE_MAX_SECRX_POLL)
1262 hw_dbg(hw, "Rx unit being enabled before security "
1263 "path fully disabled. Continuing with init.\n");
1264
1265 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
1266 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
1267 secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
1268 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
1269 IXGBE_WRITE_FLUSH(hw);
1270
1271 return 0;
1272}
1273
1274static struct ixgbe_mac_operations mac_ops_82599 = {
1275 .init_hw = &ixgbe_init_hw_generic,
1276 .reset_hw = &ixgbe_reset_hw_82599,
1277 .start_hw = &ixgbe_start_hw_82599,
1278 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
1279 .get_media_type = &ixgbe_get_media_type_82599,
1280 .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
1281 .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
1282 .get_mac_addr = &ixgbe_get_mac_addr_generic,
1283 .stop_adapter = &ixgbe_stop_adapter_generic,
1284 .get_bus_info = &ixgbe_get_bus_info_generic,
1285 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
1286 .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
1287 .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
1288 .setup_link = &ixgbe_setup_mac_link_82599,
1289 .setup_link_speed = &ixgbe_setup_mac_link_speed_82599,
1290 .check_link = &ixgbe_check_mac_link_82599,
1291 .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
1292 .led_on = &ixgbe_led_on_generic,
1293 .led_off = &ixgbe_led_off_generic,
1294 .blink_led_start = &ixgbe_blink_led_start_82599,
1295 .blink_led_stop = &ixgbe_blink_led_stop_82599,
1296 .set_rar = &ixgbe_set_rar_generic,
1297 .clear_rar = &ixgbe_clear_rar_generic,
1298 .set_vmdq = &ixgbe_set_vmdq_82599,
1299 .clear_vmdq = &ixgbe_clear_vmdq_82599,
1300 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
1301 .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
1302 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
1303 .enable_mc = &ixgbe_enable_mc_generic,
1304 .disable_mc = &ixgbe_disable_mc_generic,
1305 .clear_vfta = &ixgbe_clear_vfta_82599,
1306 .set_vfta = &ixgbe_set_vfta_82599,
1307 .setup_fc = &ixgbe_setup_fc_generic,
1308 .init_uta_tables = &ixgbe_init_uta_tables_82599,
1309 .setup_sfp = &ixgbe_setup_sfp_modules_82599,
1310};
1311
1312static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
1313 .init_params = &ixgbe_init_eeprom_params_generic,
1314 .read = &ixgbe_read_eeprom_generic,
1315 .write = &ixgbe_write_eeprom_generic,
1316 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
1317 .update_checksum = &ixgbe_update_eeprom_checksum_generic,
1318};
1319
1320static struct ixgbe_phy_operations phy_ops_82599 = {
1321 .identify = &ixgbe_identify_phy_82599,
1322 .identify_sfp = &ixgbe_identify_sfp_module_generic,
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00001323 .init = &ixgbe_init_phy_ops_82599,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001324 .reset = &ixgbe_reset_phy_generic,
1325 .read_reg = &ixgbe_read_phy_reg_generic,
1326 .write_reg = &ixgbe_write_phy_reg_generic,
1327 .setup_link = &ixgbe_setup_phy_link_generic,
1328 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
1329 .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
1330 .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
1331 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
1332 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
1333};
1334
1335struct ixgbe_info ixgbe_82599_info = {
1336 .mac = ixgbe_mac_82599EB,
1337 .get_invariants = &ixgbe_get_invariants_82599,
1338 .mac_ops = &mac_ops_82599,
1339 .eeprom_ops = &eeprom_ops_82599,
1340 .phy_ops = &phy_ops_82599,
1341};