1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2010 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/pci.h>
29 #include <linux/delay.h>
30 #include <linux/sched.h>
33 #include "ixgbe_phy.h"
34 #include "ixgbe_mbx.h"
36 #define IXGBE_82599_MAX_TX_QUEUES 128
37 #define IXGBE_82599_MAX_RX_QUEUES 128
38 #define IXGBE_82599_RAR_ENTRIES 128
39 #define IXGBE_82599_MC_TBL_SIZE 128
40 #define IXGBE_82599_VFT_TBL_SIZE 128
42 static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
43 static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
44 static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
45 static s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
46 ixgbe_link_speed speed,
48 bool autoneg_wait_to_complete);
49 static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
50 ixgbe_link_speed speed,
52 bool autoneg_wait_to_complete);
53 static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
54 bool autoneg_wait_to_complete);
55 static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
56 ixgbe_link_speed speed,
58 bool autoneg_wait_to_complete);
59 static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
60 ixgbe_link_speed speed,
62 bool autoneg_wait_to_complete);
63 static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
65 static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
67 struct ixgbe_mac_info *mac = &hw->mac;
68 if (hw->phy.multispeed_fiber) {
69 /* Set up dual speed SFP+ support */
70 mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
71 mac->ops.disable_tx_laser =
72 &ixgbe_disable_tx_laser_multispeed_fiber;
73 mac->ops.enable_tx_laser =
74 &ixgbe_enable_tx_laser_multispeed_fiber;
75 mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
77 mac->ops.disable_tx_laser = NULL;
78 mac->ops.enable_tx_laser = NULL;
79 mac->ops.flap_tx_laser = NULL;
80 if ((mac->ops.get_media_type(hw) ==
81 ixgbe_media_type_backplane) &&
82 (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
83 hw->phy.smart_speed == ixgbe_smart_speed_on))
84 mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
86 mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
90 static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
93 u16 list_offset, data_offset, data_value;
95 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
96 ixgbe_init_mac_link_ops_82599(hw);
98 hw->phy.ops.reset = NULL;
100 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
106 /* PHY config will finish before releasing the semaphore */
107 ret_val = ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
109 ret_val = IXGBE_ERR_SWFW_SYNC;
113 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
114 while (data_value != 0xffff) {
115 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
116 IXGBE_WRITE_FLUSH(hw);
117 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
119 /* Now restart DSP by setting Restart_AN */
120 IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
121 (IXGBE_READ_REG(hw, IXGBE_AUTOC) | IXGBE_AUTOC_AN_RESTART));
123 /* Release the semaphore */
124 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
125 /* Delay obtaining semaphore again to allow FW access */
126 msleep(hw->eeprom.semaphore_delay);
133 static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
135 struct ixgbe_mac_info *mac = &hw->mac;
137 ixgbe_init_mac_link_ops_82599(hw);
139 mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
140 mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
141 mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
142 mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
143 mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
144 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
150 * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
151 * @hw: pointer to hardware structure
153 * Initialize any function pointers that were not able to be
154 * set during get_invariants because the PHY/SFP type was
155 * not known. Perform the SFP init if necessary.
158 static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
160 struct ixgbe_mac_info *mac = &hw->mac;
161 struct ixgbe_phy_info *phy = &hw->phy;
164 /* Identify the PHY or SFP module */
165 ret_val = phy->ops.identify(hw);
167 /* Setup function pointers based on detected SFP module and speeds */
168 ixgbe_init_mac_link_ops_82599(hw);
170 /* If copper media, overwrite with copper function pointers */
171 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
172 mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
173 mac->ops.get_link_capabilities =
174 &ixgbe_get_copper_link_capabilities_generic;
177 /* Set necessary function pointers based on phy type */
178 switch (hw->phy.type) {
180 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
181 phy->ops.get_firmware_version =
182 &ixgbe_get_phy_firmware_version_tnx;
192 * ixgbe_get_link_capabilities_82599 - Determines link capabilities
193 * @hw: pointer to hardware structure
194 * @speed: pointer to link speed
195 * @negotiation: true when autoneg or autotry is enabled
197 * Determines the link capabilities by reading the AUTOC register.
199 static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
200 ixgbe_link_speed *speed,
206 /* Determine 1G link capabilities off of SFP+ type */
207 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
208 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) {
209 *speed = IXGBE_LINK_SPEED_1GB_FULL;
215 * Determine link capabilities based on the stored value of AUTOC,
216 * which represents EEPROM defaults. If AUTOC value has not been
217 * stored, use the current register value.
219 if (hw->mac.orig_link_settings_stored)
220 autoc = hw->mac.orig_autoc;
222 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
224 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
225 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
226 *speed = IXGBE_LINK_SPEED_1GB_FULL;
227 *negotiation = false;
230 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
231 *speed = IXGBE_LINK_SPEED_10GB_FULL;
232 *negotiation = false;
235 case IXGBE_AUTOC_LMS_1G_AN:
236 *speed = IXGBE_LINK_SPEED_1GB_FULL;
240 case IXGBE_AUTOC_LMS_10G_SERIAL:
241 *speed = IXGBE_LINK_SPEED_10GB_FULL;
242 *negotiation = false;
245 case IXGBE_AUTOC_LMS_KX4_KX_KR:
246 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
247 *speed = IXGBE_LINK_SPEED_UNKNOWN;
248 if (autoc & IXGBE_AUTOC_KR_SUPP)
249 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
250 if (autoc & IXGBE_AUTOC_KX4_SUPP)
251 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
252 if (autoc & IXGBE_AUTOC_KX_SUPP)
253 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
257 case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
258 *speed = IXGBE_LINK_SPEED_100_FULL;
259 if (autoc & IXGBE_AUTOC_KR_SUPP)
260 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
261 if (autoc & IXGBE_AUTOC_KX4_SUPP)
262 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
263 if (autoc & IXGBE_AUTOC_KX_SUPP)
264 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
268 case IXGBE_AUTOC_LMS_SGMII_1G_100M:
269 *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
270 *negotiation = false;
274 status = IXGBE_ERR_LINK_SETUP;
279 if (hw->phy.multispeed_fiber) {
280 *speed |= IXGBE_LINK_SPEED_10GB_FULL |
281 IXGBE_LINK_SPEED_1GB_FULL;
290 * ixgbe_get_media_type_82599 - Get media type
291 * @hw: pointer to hardware structure
293 * Returns the media type (fiber, copper, backplane)
295 static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
297 enum ixgbe_media_type media_type;
299 /* Detect if there is a copper PHY attached. */
300 if (hw->phy.type == ixgbe_phy_cu_unknown ||
301 hw->phy.type == ixgbe_phy_tn) {
302 media_type = ixgbe_media_type_copper;
306 switch (hw->device_id) {
307 case IXGBE_DEV_ID_82599_KX4:
308 case IXGBE_DEV_ID_82599_KX4_MEZZ:
309 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
310 case IXGBE_DEV_ID_82599_KR:
311 case IXGBE_DEV_ID_82599_XAUI_LOM:
312 /* Default device ID is mezzanine card KX/KX4 */
313 media_type = ixgbe_media_type_backplane;
315 case IXGBE_DEV_ID_82599_SFP:
316 case IXGBE_DEV_ID_82599_SFP_EM:
317 media_type = ixgbe_media_type_fiber;
319 case IXGBE_DEV_ID_82599_CX4:
320 media_type = ixgbe_media_type_cx4;
323 media_type = ixgbe_media_type_unknown;
331 * ixgbe_start_mac_link_82599 - Setup MAC link settings
332 * @hw: pointer to hardware structure
333 * @autoneg_wait_to_complete: true when waiting for completion is needed
335 * Configures link settings based on values in the ixgbe_hw struct.
336 * Restarts the link. Performs autonegotiation if needed.
338 static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
339 bool autoneg_wait_to_complete)
347 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
348 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
349 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
351 /* Only poll for autoneg to complete if specified to do so */
352 if (autoneg_wait_to_complete) {
353 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
354 IXGBE_AUTOC_LMS_KX4_KX_KR ||
355 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
356 IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
357 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
358 IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
359 links_reg = 0; /* Just in case Autoneg time = 0 */
360 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
361 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
362 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
366 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
367 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
368 hw_dbg(hw, "Autoneg did not complete.\n");
373 /* Add delay to filter out noises during initial link setup */
380 * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
381 * @hw: pointer to hardware structure
383 * The base drivers may require better control over SFP+ module
384 * PHY states. This includes selectively shutting down the Tx
385 * laser on the PHY, effectively halting physical link.
387 static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
389 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
391 /* Disable tx laser; allow 100us to go dark per spec */
392 esdp_reg |= IXGBE_ESDP_SDP3;
393 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
394 IXGBE_WRITE_FLUSH(hw);
399 * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
400 * @hw: pointer to hardware structure
402 * The base drivers may require better control over SFP+ module
403 * PHY states. This includes selectively turning on the Tx
404 * laser on the PHY, effectively starting physical link.
406 static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
408 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
410 /* Enable tx laser; allow 100ms to light up */
411 esdp_reg &= ~IXGBE_ESDP_SDP3;
412 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
413 IXGBE_WRITE_FLUSH(hw);
418 * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
419 * @hw: pointer to hardware structure
421 * When the driver changes the link speeds that it can support,
422 * it sets autotry_restart to true to indicate that we need to
423 * initiate a new autotry session with the link partner. To do
424 * so, we set the speed then disable and re-enable the tx laser, to
425 * alert the link partner that it also needs to restart autotry on its
426 * end. This is consistent with true clause 37 autoneg, which also
427 * involves a loss of signal.
429 static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
431 hw_dbg(hw, "ixgbe_flap_tx_laser_multispeed_fiber\n");
433 if (hw->mac.autotry_restart) {
434 ixgbe_disable_tx_laser_multispeed_fiber(hw);
435 ixgbe_enable_tx_laser_multispeed_fiber(hw);
436 hw->mac.autotry_restart = false;
441 * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
442 * @hw: pointer to hardware structure
443 * @speed: new link speed
444 * @autoneg: true if autonegotiation enabled
445 * @autoneg_wait_to_complete: true when waiting for completion is needed
447 * Set the link speed in the AUTOC register and restarts link.
449 s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
450 ixgbe_link_speed speed,
452 bool autoneg_wait_to_complete)
455 ixgbe_link_speed phy_link_speed;
456 ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
458 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
459 bool link_up = false;
463 /* Mask off requested but non-supported speeds */
464 hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
465 speed &= phy_link_speed;
468 * Try each speed one by one, highest priority first. We do this in
469 * software because 10gb fiber doesn't support speed autonegotiation.
471 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
473 highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
475 /* If we already have link at this speed, just jump out */
476 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
478 if ((phy_link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
481 /* Set the module link speed */
482 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
483 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
484 IXGBE_WRITE_FLUSH(hw);
486 /* Allow module to change analog characteristics (1G->10G) */
489 status = ixgbe_setup_mac_link_82599(hw,
490 IXGBE_LINK_SPEED_10GB_FULL,
492 autoneg_wait_to_complete);
496 /* Flap the tx laser if it has not already been done */
497 hw->mac.ops.flap_tx_laser(hw);
500 * Wait for the controller to acquire link. Per IEEE 802.3ap,
501 * Section 73.10.2, we may have to wait up to 500ms if KR is
502 * attempted. 82599 uses the same timing for 10g SFI.
505 for (i = 0; i < 5; i++) {
506 /* Wait for the link partner to also set speed */
509 /* If we have link, just jump out */
510 hw->mac.ops.check_link(hw, &phy_link_speed,
517 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
519 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
520 highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
522 /* If we already have link at this speed, just jump out */
523 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
525 if ((phy_link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
528 /* Set the module link speed */
529 esdp_reg &= ~IXGBE_ESDP_SDP5;
530 esdp_reg |= IXGBE_ESDP_SDP5_DIR;
531 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
532 IXGBE_WRITE_FLUSH(hw);
534 /* Allow module to change analog characteristics (10G->1G) */
537 status = ixgbe_setup_mac_link_82599(hw,
538 IXGBE_LINK_SPEED_1GB_FULL,
540 autoneg_wait_to_complete);
544 /* Flap the tx laser if it has not already been done */
545 hw->mac.ops.flap_tx_laser(hw);
547 /* Wait for the link partner to also set speed */
550 /* If we have link, just jump out */
551 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
557 * We didn't get link. Configure back to the highest speed we tried,
558 * (if there was more than one). We call ourselves back with just the
559 * single highest speed that the user requested.
562 status = ixgbe_setup_mac_link_multispeed_fiber(hw,
565 autoneg_wait_to_complete);
568 /* Set autoneg_advertised value based on input link speed */
569 hw->phy.autoneg_advertised = 0;
571 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
572 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
574 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
575 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
581 * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
582 * @hw: pointer to hardware structure
583 * @speed: new link speed
584 * @autoneg: true if autonegotiation enabled
585 * @autoneg_wait_to_complete: true when waiting for completion is needed
587 * Implements the Intel SmartSpeed algorithm.
589 static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
590 ixgbe_link_speed speed, bool autoneg,
591 bool autoneg_wait_to_complete)
594 ixgbe_link_speed link_speed;
596 bool link_up = false;
597 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
598 struct ixgbe_adapter *adapter = hw->back;
600 hw_dbg(hw, "ixgbe_setup_mac_link_smartspeed.\n");
602 /* Set autoneg_advertised value based on input link speed */
603 hw->phy.autoneg_advertised = 0;
605 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
606 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
608 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
609 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
611 if (speed & IXGBE_LINK_SPEED_100_FULL)
612 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
615 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
616 * autoneg advertisement if link is unable to be established at the
617 * highest negotiated rate. This can sometimes happen due to integrity
618 * issues with the physical media connection.
621 /* First, try to get link with full advertisement */
622 hw->phy.smart_speed_active = false;
623 for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
624 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
625 autoneg_wait_to_complete);
630 * Wait for the controller to acquire link. Per IEEE 802.3ap,
631 * Section 73.10.2, we may have to wait up to 500ms if KR is
632 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
633 * Table 9 in the AN MAS.
635 for (i = 0; i < 5; i++) {
638 /* If we have link, just jump out */
639 hw->mac.ops.check_link(hw, &link_speed,
647 * We didn't get link. If we advertised KR plus one of KX4/KX
648 * (or BX4/BX), then disable KR and try again.
650 if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
651 ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
654 /* Turn SmartSpeed on to disable KR support */
655 hw->phy.smart_speed_active = true;
656 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
657 autoneg_wait_to_complete);
662 * Wait for the controller to acquire link. 600ms will allow for
663 * the AN link_fail_inhibit_timer as well for multiple cycles of
664 * parallel detect, both 10g and 1g. This allows for the maximum
665 * connect attempts as defined in the AN MAS table 73-7.
667 for (i = 0; i < 6; i++) {
670 /* If we have link, just jump out */
671 hw->mac.ops.check_link(hw, &link_speed,
677 /* We didn't get link. Turn SmartSpeed back off. */
678 hw->phy.smart_speed_active = false;
679 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
680 autoneg_wait_to_complete);
683 if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
684 e_info(hw, "Smartspeed has downgraded the link speed from "
685 "the maximum advertised\n");
690 * ixgbe_setup_mac_link_82599 - Set MAC link speed
691 * @hw: pointer to hardware structure
692 * @speed: new link speed
693 * @autoneg: true if autonegotiation enabled
694 * @autoneg_wait_to_complete: true when waiting for completion is needed
696 * Set the link speed in the AUTOC register and restarts link.
698 static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
699 ixgbe_link_speed speed, bool autoneg,
700 bool autoneg_wait_to_complete)
703 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
704 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
705 u32 start_autoc = autoc;
707 u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
708 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
709 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
712 ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
714 /* Check to see if speed passed in is supported. */
715 hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
716 speed &= link_capabilities;
718 if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
719 status = IXGBE_ERR_LINK_SETUP;
723 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
724 if (hw->mac.orig_link_settings_stored)
725 orig_autoc = hw->mac.orig_autoc;
730 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
731 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
732 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
733 /* Set KX4/KX/KR support according to speed requested */
734 autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
735 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
736 if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
737 autoc |= IXGBE_AUTOC_KX4_SUPP;
738 if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
739 (hw->phy.smart_speed_active == false))
740 autoc |= IXGBE_AUTOC_KR_SUPP;
741 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
742 autoc |= IXGBE_AUTOC_KX_SUPP;
743 } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
744 (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
745 link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
746 /* Switch from 1G SFI to 10G SFI if requested */
747 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
748 (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
749 autoc &= ~IXGBE_AUTOC_LMS_MASK;
750 autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
752 } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
753 (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
754 /* Switch from 10G SFI to 1G SFI if requested */
755 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
756 (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
757 autoc &= ~IXGBE_AUTOC_LMS_MASK;
759 autoc |= IXGBE_AUTOC_LMS_1G_AN;
761 autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
765 if (autoc != start_autoc) {
767 autoc |= IXGBE_AUTOC_AN_RESTART;
768 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
770 /* Only poll for autoneg to complete if specified to do so */
771 if (autoneg_wait_to_complete) {
772 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
773 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
774 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
775 links_reg = 0; /*Just in case Autoneg time=0*/
776 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
778 IXGBE_READ_REG(hw, IXGBE_LINKS);
779 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
783 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
785 IXGBE_ERR_AUTONEG_NOT_COMPLETE;
786 hw_dbg(hw, "Autoneg did not "
792 /* Add delay to filter out noises during initial link setup */
801 * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
802 * @hw: pointer to hardware structure
803 * @speed: new link speed
804 * @autoneg: true if autonegotiation enabled
805 * @autoneg_wait_to_complete: true if waiting is needed to complete
807 * Restarts link on PHY and MAC based on settings passed in.
809 static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
810 ixgbe_link_speed speed,
812 bool autoneg_wait_to_complete)
816 /* Setup the PHY according to input speed */
817 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
818 autoneg_wait_to_complete);
820 ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
826 * ixgbe_reset_hw_82599 - Perform hardware reset
827 * @hw: pointer to hardware structure
829 * Resets the hardware by resetting the transmit and receive units, masks
830 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
833 static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
841 /* Call adapter stop to disable tx/rx and clear interrupts */
842 hw->mac.ops.stop_adapter(hw);
844 /* PHY ops must be identified and initialized prior to reset */
846 /* Init PHY and function pointers, perform SFP setup */
847 status = hw->phy.ops.init(hw);
849 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
852 /* Setup SFP module if there is one present. */
853 if (hw->phy.sfp_setup_needed) {
854 status = hw->mac.ops.setup_sfp(hw);
855 hw->phy.sfp_setup_needed = false;
859 if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
860 hw->phy.ops.reset(hw);
863 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
864 * access and verify no pending requests before reset
866 status = ixgbe_disable_pcie_master(hw);
868 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
869 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
873 * Issue global reset to the MAC. This needs to be a SW reset.
874 * If link reset is used, it might reset the MAC when mng is using it
876 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
877 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
878 IXGBE_WRITE_FLUSH(hw);
880 /* Poll for reset bit to self-clear indicating reset is complete */
881 for (i = 0; i < 10; i++) {
883 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
884 if (!(ctrl & IXGBE_CTRL_RST))
887 if (ctrl & IXGBE_CTRL_RST) {
888 status = IXGBE_ERR_RESET_FAILED;
889 hw_dbg(hw, "Reset polling failed to complete.\n");
895 * Store the original AUTOC/AUTOC2 values if they have not been
896 * stored off yet. Otherwise restore the stored original
897 * values since the reset operation sets back to defaults.
899 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
900 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
901 if (hw->mac.orig_link_settings_stored == false) {
902 hw->mac.orig_autoc = autoc;
903 hw->mac.orig_autoc2 = autoc2;
904 hw->mac.orig_link_settings_stored = true;
906 if (autoc != hw->mac.orig_autoc)
907 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
908 IXGBE_AUTOC_AN_RESTART));
910 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
911 (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
912 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
913 autoc2 |= (hw->mac.orig_autoc2 &
914 IXGBE_AUTOC2_UPPER_MASK);
915 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
920 * Store MAC address from RAR0, clear receive address registers, and
921 * clear the multicast table. Also reset num_rar_entries to 128,
922 * since we modify this value when programming the SAN MAC address.
924 hw->mac.num_rar_entries = 128;
925 hw->mac.ops.init_rx_addrs(hw);
927 /* Store the permanent mac address */
928 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
930 /* Store the permanent SAN mac address */
931 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
933 /* Add the SAN MAC address to the RAR only if it's a valid address */
934 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
935 hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
936 hw->mac.san_addr, 0, IXGBE_RAH_AV);
938 /* Reserve the last RAR for the SAN MAC address */
939 hw->mac.num_rar_entries--;
942 /* Store the alternative WWNN/WWPN prefix */
943 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
944 &hw->mac.wwpn_prefix);
951 * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
952 * @hw: pointer to hardware structure
954 s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
957 u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
958 fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
961 * Before starting reinitialization process,
962 * FDIRCMD.CMD must be zero.
964 for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
965 if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
966 IXGBE_FDIRCMD_CMD_MASK))
970 if (i >= IXGBE_FDIRCMD_CMD_POLL) {
971 hw_dbg(hw ,"Flow Director previous command isn't complete, "
972 "aborting table re-initialization.\n");
973 return IXGBE_ERR_FDIR_REINIT_FAILED;
976 IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
977 IXGBE_WRITE_FLUSH(hw);
979 * 82599 adapters flow director init flow cannot be restarted,
980 * Workaround 82599 silicon errata by performing the following steps
981 * before re-writing the FDIRCTRL control register with the same value.
982 * - write 1 to bit 8 of FDIRCMD register &
983 * - write 0 to bit 8 of FDIRCMD register
985 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
986 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
987 IXGBE_FDIRCMD_CLEARHT));
988 IXGBE_WRITE_FLUSH(hw);
989 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
990 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
991 ~IXGBE_FDIRCMD_CLEARHT));
992 IXGBE_WRITE_FLUSH(hw);
994 * Clear FDIR Hash register to clear any leftover hashes
995 * waiting to be programmed.
997 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
998 IXGBE_WRITE_FLUSH(hw);
1000 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1001 IXGBE_WRITE_FLUSH(hw);
1003 /* Poll init-done after we write FDIRCTRL register */
1004 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1005 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1006 IXGBE_FDIRCTRL_INIT_DONE)
1010 if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
1011 hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
1012 return IXGBE_ERR_FDIR_REINIT_FAILED;
1015 /* Clear FDIR statistics registers (read to clear) */
1016 IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
1017 IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
1018 IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
1019 IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
1020 IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
1026 * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
1027 * @hw: pointer to hardware structure
1028 * @pballoc: which mode to allocate filters with
1030 s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc)
1037 * Before enabling Flow Director, the Rx Packet Buffer size
1038 * must be reduced. The new value is the current size minus
1039 * flow director memory usage size.
1041 pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
1042 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
1043 (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
1046 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1047 * intialized to zero for non DCB mode otherwise actual total RX PB
1048 * would be bigger than programmed and filter space would run into
1051 for (i = 1; i < 8; i++)
1052 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
1054 /* Send interrupt when 64 filters are left */
1055 fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
1057 /* Set the maximum length per hash bucket to 0xA filters */
1058 fdirctrl |= 0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT;
1061 case IXGBE_FDIR_PBALLOC_64K:
1062 /* 8k - 1 signature filters */
1063 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
1065 case IXGBE_FDIR_PBALLOC_128K:
1066 /* 16k - 1 signature filters */
1067 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
1069 case IXGBE_FDIR_PBALLOC_256K:
1070 /* 32k - 1 signature filters */
1071 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
1075 return IXGBE_ERR_CONFIG;
1078 /* Move the flexible bytes to use the ethertype - shift 6 words */
1079 fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
1081 fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
1083 /* Prime the keys for hashing */
1084 IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
1085 htonl(IXGBE_ATR_BUCKET_HASH_KEY));
1086 IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
1087 htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
1090 * Poll init-done after we write the register. Estimated times:
1091 * 10G: PBALLOC = 11b, timing is 60us
1092 * 1G: PBALLOC = 11b, timing is 600us
1093 * 100M: PBALLOC = 11b, timing is 6ms
1095 * Multiple these timings by 4 if under full Rx load
1097 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1098 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1099 * this might not finish in our poll time, but we can live with that
1102 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1103 IXGBE_WRITE_FLUSH(hw);
1104 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1105 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1106 IXGBE_FDIRCTRL_INIT_DONE)
1110 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
1111 hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
1117 * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
1118 * @hw: pointer to hardware structure
1119 * @pballoc: which mode to allocate filters with
1121 s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
1128 * Before enabling Flow Director, the Rx Packet Buffer size
1129 * must be reduced. The new value is the current size minus
1130 * flow director memory usage size.
1132 pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
1133 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
1134 (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
1137 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1138 * intialized to zero for non DCB mode otherwise actual total RX PB
1139 * would be bigger than programmed and filter space would run into
1142 for (i = 1; i < 8; i++)
1143 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
1145 /* Send interrupt when 64 filters are left */
1146 fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
1148 /* Initialize the drop queue to Rx queue 127 */
1149 fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
1152 case IXGBE_FDIR_PBALLOC_64K:
1153 /* 2k - 1 perfect filters */
1154 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
1156 case IXGBE_FDIR_PBALLOC_128K:
1157 /* 4k - 1 perfect filters */
1158 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
1160 case IXGBE_FDIR_PBALLOC_256K:
1161 /* 8k - 1 perfect filters */
1162 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
1166 return IXGBE_ERR_CONFIG;
1169 /* Turn perfect match filtering on */
1170 fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH;
1171 fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
1173 /* Move the flexible bytes to use the ethertype - shift 6 words */
1174 fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
1176 /* Prime the keys for hashing */
1177 IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
1178 htonl(IXGBE_ATR_BUCKET_HASH_KEY));
1179 IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
1180 htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
1183 * Poll init-done after we write the register. Estimated times:
1184 * 10G: PBALLOC = 11b, timing is 60us
1185 * 1G: PBALLOC = 11b, timing is 600us
1186 * 100M: PBALLOC = 11b, timing is 6ms
1188 * Multiple these timings by 4 if under full Rx load
1190 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1191 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1192 * this might not finish in our poll time, but we can live with that
1196 /* Set the maximum length per hash bucket to 0xA filters */
1197 fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT);
1199 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1200 IXGBE_WRITE_FLUSH(hw);
1201 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1202 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1203 IXGBE_FDIRCTRL_INIT_DONE)
1207 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
1208 hw_dbg(hw, "Flow Director Perfect poll time exceeded!\n");
1215 * ixgbe_atr_compute_hash_82599 - Compute the hashes for SW ATR
1216 * @stream: input bitstream to compute the hash on
1217 * @key: 32-bit hash key
1219 static u16 ixgbe_atr_compute_hash_82599(struct ixgbe_atr_input *atr_input,
1223 * The algorithm is as follows:
1224 * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
1225 * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
1226 * and A[n] x B[n] is bitwise AND between same length strings
1228 * K[n] is 16 bits, defined as:
1229 * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
1230 * for n modulo 32 < 15, K[n] =
1231 * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
1233 * S[n] is 16 bits, defined as:
1234 * for n >= 15, S[n] = S[n:n - 15]
1235 * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
1237 * To simplify for programming, the algorithm is implemented
1238 * in software this way:
1240 * Key[31:0], Stream[335:0]
1242 * tmp_key[11 * 32 - 1:0] = 11{Key[31:0] = key concatenated 11 times
1243 * int_key[350:0] = tmp_key[351:1]
1244 * int_stream[365:0] = Stream[14:0] | Stream[335:0] | Stream[335:321]
1247 * for (i = 0; i < 351; i++) {
1249 * hash ^= int_stream[(i + 15):i];
1259 u8 *stream = (u8 *)atr_input;
1260 u8 int_key[44]; /* upper-most bit unused */
1261 u8 hash_str[46]; /* upper-most 2 bits unused */
1262 u16 hash_result = 0;
1266 * Initialize the fill member to prevent warnings
1269 tmp_key.fill[0] = 0;
1271 /* First load the temporary key stream */
1272 for (i = 0; i < 6; i++) {
1273 u64 fillkey = ((u64)key << 32) | key;
1274 tmp_key.fill[i] = fillkey;
1278 * Set the interim key for the hashing. Bit 352 is unused, so we must
1279 * shift and compensate when building the key.
1282 int_key[0] = tmp_key.key_stream[0] >> 1;
1283 for (i = 1, j = 0; i < 44; i++) {
1284 unsigned int this_key = tmp_key.key_stream[j] << 7;
1286 int_key[i] = (u8)(this_key | (tmp_key.key_stream[j] >> 1));
1290 * Set the interim bit string for the hashing. Bits 368 and 367 are
1291 * unused, so shift and compensate when building the string.
1293 hash_str[0] = (stream[40] & 0x7f) >> 1;
1294 for (i = 1, j = 40; i < 46; i++) {
1295 unsigned int this_str = stream[j] << 7;
1299 hash_str[i] = (u8)(this_str | (stream[j] >> 1));
1303 * Now compute the hash. i is the index into hash_str, j is into our
1304 * key stream, k is counting the number of bits, and h interates within
1307 for (i = 45, j = 43, k = 0; k < 351 && i >= 2 && j >= 0; i--, j--) {
1308 for (h = 0; h < 8 && k < 351; h++, k++) {
1309 if (int_key[j] & (1 << h)) {
1311 * Key bit is set, XOR in the current 16-bit
1312 * string. Example of processing:
1314 * tmp = (hash_str[i - 2] & 0 << 16) |
1315 * (hash_str[i - 1] & 0xff << 8) |
1316 * (hash_str[i] & 0xff >> 0)
1317 * So tmp = hash_str[15 + k:k], since the
1318 * i + 2 clause rolls off the 16-bit value
1320 * tmp = (hash_str[i - 2] & 0x7f << 9) |
1321 * (hash_str[i - 1] & 0xff << 1) |
1322 * (hash_str[i] & 0x80 >> 7)
1324 int tmp = (hash_str[i] >> h);
1325 tmp |= (hash_str[i - 1] << (8 - h));
1326 tmp |= (int)(hash_str[i - 2] & ((1 << h) - 1))
1328 hash_result ^= (u16)tmp;
1337 * ixgbe_atr_set_vlan_id_82599 - Sets the VLAN id in the ATR input stream
1338 * @input: input stream to modify
1339 * @vlan: the VLAN id to load
1341 s32 ixgbe_atr_set_vlan_id_82599(struct ixgbe_atr_input *input, u16 vlan)
1343 input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] = vlan >> 8;
1344 input->byte_stream[IXGBE_ATR_VLAN_OFFSET] = vlan & 0xff;
1350 * ixgbe_atr_set_src_ipv4_82599 - Sets the source IPv4 address
1351 * @input: input stream to modify
1352 * @src_addr: the IP address to load
1354 s32 ixgbe_atr_set_src_ipv4_82599(struct ixgbe_atr_input *input, u32 src_addr)
1356 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] = src_addr >> 24;
1357 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] =
1358 (src_addr >> 16) & 0xff;
1359 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] =
1360 (src_addr >> 8) & 0xff;
1361 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET] = src_addr & 0xff;
1367 * ixgbe_atr_set_dst_ipv4_82599 - Sets the destination IPv4 address
1368 * @input: input stream to modify
1369 * @dst_addr: the IP address to load
1371 s32 ixgbe_atr_set_dst_ipv4_82599(struct ixgbe_atr_input *input, u32 dst_addr)
1373 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] = dst_addr >> 24;
1374 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] =
1375 (dst_addr >> 16) & 0xff;
1376 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] =
1377 (dst_addr >> 8) & 0xff;
1378 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET] = dst_addr & 0xff;
1384 * ixgbe_atr_set_src_port_82599 - Sets the source port
1385 * @input: input stream to modify
1386 * @src_port: the source port to load
1388 s32 ixgbe_atr_set_src_port_82599(struct ixgbe_atr_input *input, u16 src_port)
1390 input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1] = src_port >> 8;
1391 input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] = src_port & 0xff;
1397 * ixgbe_atr_set_dst_port_82599 - Sets the destination port
1398 * @input: input stream to modify
1399 * @dst_port: the destination port to load
1401 s32 ixgbe_atr_set_dst_port_82599(struct ixgbe_atr_input *input, u16 dst_port)
1403 input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1] = dst_port >> 8;
1404 input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] = dst_port & 0xff;
1410 * ixgbe_atr_set_flex_byte_82599 - Sets the flexible bytes
1411 * @input: input stream to modify
1412 * @flex_bytes: the flexible bytes to load
1414 s32 ixgbe_atr_set_flex_byte_82599(struct ixgbe_atr_input *input, u16 flex_byte)
1416 input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] = flex_byte >> 8;
1417 input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET] = flex_byte & 0xff;
1423 * ixgbe_atr_set_l4type_82599 - Sets the layer 4 packet type
1424 * @input: input stream to modify
1425 * @l4type: the layer 4 type value to load
1427 s32 ixgbe_atr_set_l4type_82599(struct ixgbe_atr_input *input, u8 l4type)
1429 input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET] = l4type;
1435 * ixgbe_atr_get_vlan_id_82599 - Gets the VLAN id from the ATR input stream
1436 * @input: input stream to search
1437 * @vlan: the VLAN id to load
1439 static s32 ixgbe_atr_get_vlan_id_82599(struct ixgbe_atr_input *input, u16 *vlan)
1441 *vlan = input->byte_stream[IXGBE_ATR_VLAN_OFFSET];
1442 *vlan |= input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] << 8;
1448 * ixgbe_atr_get_src_ipv4_82599 - Gets the source IPv4 address
1449 * @input: input stream to search
1450 * @src_addr: the IP address to load
1452 static s32 ixgbe_atr_get_src_ipv4_82599(struct ixgbe_atr_input *input,
1455 *src_addr = input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET];
1456 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] << 8;
1457 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] << 16;
1458 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] << 24;
1464 * ixgbe_atr_get_dst_ipv4_82599 - Gets the destination IPv4 address
1465 * @input: input stream to search
1466 * @dst_addr: the IP address to load
1468 static s32 ixgbe_atr_get_dst_ipv4_82599(struct ixgbe_atr_input *input,
1471 *dst_addr = input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET];
1472 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] << 8;
1473 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] << 16;
1474 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] << 24;
1480 * ixgbe_atr_get_src_ipv6_82599 - Gets the source IPv6 address
1481 * @input: input stream to search
1482 * @src_addr_1: the first 4 bytes of the IP address to load
1483 * @src_addr_2: the second 4 bytes of the IP address to load
1484 * @src_addr_3: the third 4 bytes of the IP address to load
1485 * @src_addr_4: the fourth 4 bytes of the IP address to load
1487 static s32 ixgbe_atr_get_src_ipv6_82599(struct ixgbe_atr_input *input,
1488 u32 *src_addr_1, u32 *src_addr_2,
1489 u32 *src_addr_3, u32 *src_addr_4)
1491 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12];
1492 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] << 8;
1493 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] << 16;
1494 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] << 24;
1496 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8];
1497 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] << 8;
1498 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] << 16;
1499 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] << 24;
1501 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4];
1502 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] << 8;
1503 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] << 16;
1504 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] << 24;
1506 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET];
1507 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] << 8;
1508 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] << 16;
1509 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] << 24;
1515 * ixgbe_atr_get_src_port_82599 - Gets the source port
1516 * @input: input stream to modify
1517 * @src_port: the source port to load
1519 * Even though the input is given in big-endian, the FDIRPORT registers
1520 * expect the ports to be programmed in little-endian. Hence the need to swap
1521 * endianness when retrieving the data. This can be confusing since the
1522 * internal hash engine expects it to be big-endian.
1524 static s32 ixgbe_atr_get_src_port_82599(struct ixgbe_atr_input *input,
1527 *src_port = input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] << 8;
1528 *src_port |= input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1];
1534 * ixgbe_atr_get_dst_port_82599 - Gets the destination port
1535 * @input: input stream to modify
1536 * @dst_port: the destination port to load
1538 * Even though the input is given in big-endian, the FDIRPORT registers
1539 * expect the ports to be programmed in little-endian. Hence the need to swap
1540 * endianness when retrieving the data. This can be confusing since the
1541 * internal hash engine expects it to be big-endian.
1543 static s32 ixgbe_atr_get_dst_port_82599(struct ixgbe_atr_input *input,
1546 *dst_port = input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] << 8;
1547 *dst_port |= input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1];
1553 * ixgbe_atr_get_flex_byte_82599 - Gets the flexible bytes
1554 * @input: input stream to modify
1555 * @flex_bytes: the flexible bytes to load
1557 static s32 ixgbe_atr_get_flex_byte_82599(struct ixgbe_atr_input *input,
1560 *flex_byte = input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET];
1561 *flex_byte |= input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] << 8;
1567 * ixgbe_atr_get_l4type_82599 - Gets the layer 4 packet type
1568 * @input: input stream to modify
1569 * @l4type: the layer 4 type value to load
1571 static s32 ixgbe_atr_get_l4type_82599(struct ixgbe_atr_input *input,
1574 *l4type = input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET];
1580 * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
1581 * @hw: pointer to hardware structure
1582 * @stream: input bitstream
1583 * @queue: queue index to direct traffic to
1585 s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
1586 struct ixgbe_atr_input *input,
1592 u16 bucket_hash, sig_hash;
1595 bucket_hash = ixgbe_atr_compute_hash_82599(input,
1596 IXGBE_ATR_BUCKET_HASH_KEY);
1598 /* bucket_hash is only 15 bits */
1599 bucket_hash &= IXGBE_ATR_HASH_MASK;
1601 sig_hash = ixgbe_atr_compute_hash_82599(input,
1602 IXGBE_ATR_SIGNATURE_HASH_KEY);
1604 /* Get the l4type in order to program FDIRCMD properly */
1605 /* lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 */
1606 ixgbe_atr_get_l4type_82599(input, &l4type);
1609 * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
1610 * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
1612 fdirhash = sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
1614 fdircmd = (IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
1615 IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN);
1617 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
1618 case IXGBE_ATR_L4TYPE_TCP:
1619 fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
1621 case IXGBE_ATR_L4TYPE_UDP:
1622 fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
1624 case IXGBE_ATR_L4TYPE_SCTP:
1625 fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
1628 hw_dbg(hw, "Error on l4type input\n");
1629 return IXGBE_ERR_CONFIG;
1632 if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK)
1633 fdircmd |= IXGBE_FDIRCMD_IPV6;
1635 fdircmd |= ((u64)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT);
1636 fdirhashcmd = ((fdircmd << 32) | fdirhash);
1638 IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
1644 * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
1645 * @hw: pointer to hardware structure
1646 * @input: input bitstream
1647 * @input_masks: bitwise masks for relevant fields
1648 * @soft_id: software index into the silicon hash tables for filter storage
1649 * @queue: queue index to direct traffic to
1651 * Note that the caller to this function must lock before calling, since the
1652 * hardware writes must be protected from one another.
1654 s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
1655 struct ixgbe_atr_input *input,
1656 struct ixgbe_atr_input_masks *input_masks,
1657 u16 soft_id, u8 queue)
1661 u32 src_ipv4 = 0, dst_ipv4 = 0;
1662 u32 src_ipv6_1, src_ipv6_2, src_ipv6_3, src_ipv6_4;
1663 u16 src_port, dst_port, vlan_id, flex_bytes;
1668 /* Get our input values */
1669 ixgbe_atr_get_l4type_82599(input, &l4type);
1672 * Check l4type formatting, and bail out before we touch the hardware
1673 * if there's a configuration issue
1675 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
1676 case IXGBE_ATR_L4TYPE_TCP:
1677 fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
1679 case IXGBE_ATR_L4TYPE_UDP:
1680 fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
1682 case IXGBE_ATR_L4TYPE_SCTP:
1683 fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
1686 hw_dbg(hw, "Error on l4type input\n");
1687 return IXGBE_ERR_CONFIG;
1690 bucket_hash = ixgbe_atr_compute_hash_82599(input,
1691 IXGBE_ATR_BUCKET_HASH_KEY);
1693 /* bucket_hash is only 15 bits */
1694 bucket_hash &= IXGBE_ATR_HASH_MASK;
1696 ixgbe_atr_get_vlan_id_82599(input, &vlan_id);
1697 ixgbe_atr_get_src_port_82599(input, &src_port);
1698 ixgbe_atr_get_dst_port_82599(input, &dst_port);
1699 ixgbe_atr_get_flex_byte_82599(input, &flex_bytes);
1701 fdirhash = soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
1703 /* Now figure out if we're IPv4 or IPv6 */
1704 if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK) {
1706 ixgbe_atr_get_src_ipv6_82599(input, &src_ipv6_1, &src_ipv6_2,
1707 &src_ipv6_3, &src_ipv6_4);
1709 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), src_ipv6_1);
1710 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), src_ipv6_2);
1711 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), src_ipv6_3);
1712 /* The last 4 bytes is the same register as IPv4 */
1713 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv6_4);
1715 fdircmd |= IXGBE_FDIRCMD_IPV6;
1716 fdircmd |= IXGBE_FDIRCMD_IPv6DMATCH;
1719 ixgbe_atr_get_src_ipv4_82599(input, &src_ipv4);
1720 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv4);
1723 ixgbe_atr_get_dst_ipv4_82599(input, &dst_ipv4);
1724 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, dst_ipv4);
1726 IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, (vlan_id |
1727 (flex_bytes << IXGBE_FDIRVLAN_FLEX_SHIFT)));
1728 IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, (src_port |
1729 (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
1732 * Program the relevant mask registers. L4type cannot be
1733 * masked out in this implementation.
1735 * This also assumes IPv4 only. IPv6 masking isn't supported at this
1738 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, input_masks->src_ip_mask);
1739 IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, input_masks->dst_ip_mask);
1741 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
1742 case IXGBE_ATR_L4TYPE_TCP:
1743 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, input_masks->src_port_mask);
1744 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
1745 (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
1746 (input_masks->dst_port_mask << 16)));
1748 case IXGBE_ATR_L4TYPE_UDP:
1749 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, input_masks->src_port_mask);
1750 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
1751 (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
1752 (input_masks->src_port_mask << 16)));
1755 /* this already would have failed above */
1759 /* Program the last mask register, FDIRM */
1760 if (input_masks->vlan_id_mask)
1761 /* Mask both VLAN and VLANP - bits 0 and 1 */
1764 if (input_masks->data_mask)
1765 /* Flex bytes need masking, so mask the whole thing - bit 4 */
1768 /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
1771 IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
1773 fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW;
1774 fdircmd |= IXGBE_FDIRCMD_FILTER_UPDATE;
1775 fdircmd |= IXGBE_FDIRCMD_LAST;
1776 fdircmd |= IXGBE_FDIRCMD_QUEUE_EN;
1777 fdircmd |= queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
1779 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
1780 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
1785 * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
1786 * @hw: pointer to hardware structure
1787 * @reg: analog register to read
1790 * Performs read operation to Omer analog register specified.
1792 static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
1796 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
1798 IXGBE_WRITE_FLUSH(hw);
1800 core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
1801 *val = (u8)core_ctl;
1807 * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
1808 * @hw: pointer to hardware structure
1809 * @reg: atlas register to write
1810 * @val: value to write
1812 * Performs write operation to Omer analog register specified.
1814 static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
1818 core_ctl = (reg << 8) | val;
1819 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
1820 IXGBE_WRITE_FLUSH(hw);
1827 * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
1828 * @hw: pointer to hardware structure
1830 * Starts the hardware using the generic start_hw function.
1831 * Then performs device-specific:
1832 * Clears the rate limiter registers.
1834 static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
1839 ret_val = ixgbe_start_hw_generic(hw);
1841 /* Clear the rate limiters */
1842 for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
1843 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
1844 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
1846 IXGBE_WRITE_FLUSH(hw);
1848 /* We need to run link autotry after the driver loads */
1849 hw->mac.autotry_restart = true;
1852 ret_val = ixgbe_verify_fw_version_82599(hw);
1858 * ixgbe_identify_phy_82599 - Get physical layer module
1859 * @hw: pointer to hardware structure
1861 * Determines the physical layer module found on the current adapter.
1863 static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
1865 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
1866 status = ixgbe_identify_phy_generic(hw);
1868 status = ixgbe_identify_sfp_module_generic(hw);
1873 * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
1874 * @hw: pointer to hardware structure
1876 * Determines physical layer capabilities of the current configuration.
1878 static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
1880 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1881 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1882 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
1883 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
1884 u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
1885 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
1886 u16 ext_ability = 0;
1887 u8 comp_codes_10g = 0;
1888 u8 comp_codes_1g = 0;
1890 hw->phy.ops.identify(hw);
1892 if (hw->phy.type == ixgbe_phy_tn ||
1893 hw->phy.type == ixgbe_phy_cu_unknown) {
1894 hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
1896 if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
1897 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
1898 if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
1899 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
1900 if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
1901 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
1905 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
1906 case IXGBE_AUTOC_LMS_1G_AN:
1907 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
1908 if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
1909 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
1910 IXGBE_PHYSICAL_LAYER_1000BASE_BX;
1913 /* SFI mode so read SFP module */
1916 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
1917 if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
1918 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
1919 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
1920 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1921 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
1922 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
1925 case IXGBE_AUTOC_LMS_10G_SERIAL:
1926 if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
1927 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
1929 } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
1932 case IXGBE_AUTOC_LMS_KX4_KX_KR:
1933 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
1934 if (autoc & IXGBE_AUTOC_KX_SUPP)
1935 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
1936 if (autoc & IXGBE_AUTOC_KX4_SUPP)
1937 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1938 if (autoc & IXGBE_AUTOC_KR_SUPP)
1939 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
1948 /* SFP check must be done last since DA modules are sometimes used to
1949 * test KR mode - we need to id KR mode correctly before SFP module.
1950 * Call identify_sfp because the pluggable module may have changed */
1951 hw->phy.ops.identify_sfp(hw);
1952 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
1955 switch (hw->phy.type) {
1956 case ixgbe_phy_sfp_passive_tyco:
1957 case ixgbe_phy_sfp_passive_unknown:
1958 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1960 case ixgbe_phy_sfp_ftl_active:
1961 case ixgbe_phy_sfp_active_unknown:
1962 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
1964 case ixgbe_phy_sfp_avago:
1965 case ixgbe_phy_sfp_ftl:
1966 case ixgbe_phy_sfp_intel:
1967 case ixgbe_phy_sfp_unknown:
1968 hw->phy.ops.read_i2c_eeprom(hw,
1969 IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
1970 hw->phy.ops.read_i2c_eeprom(hw,
1971 IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
1972 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
1973 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1974 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
1975 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1976 else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
1977 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
1984 return physical_layer;
1988 * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
1989 * @hw: pointer to hardware structure
1990 * @regval: register value to write to RXCTRL
1992 * Enables the Rx DMA unit for 82599
1994 static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
1996 #define IXGBE_MAX_SECRX_POLL 30
2001 * Workaround for 82599 silicon errata when enabling the Rx datapath.
2002 * If traffic is incoming before we enable the Rx unit, it could hang
2003 * the Rx DMA unit. Therefore, make sure the security engine is
2004 * completely disabled prior to enabling the Rx unit.
2006 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2007 secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
2008 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2009 for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
2010 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
2011 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
2017 /* For informational purposes only */
2018 if (i >= IXGBE_MAX_SECRX_POLL)
2019 hw_dbg(hw, "Rx unit being enabled before security "
2020 "path fully disabled. Continuing with init.\n");
2022 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2023 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2024 secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
2025 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2026 IXGBE_WRITE_FLUSH(hw);
2032 * ixgbe_get_device_caps_82599 - Get additional device capabilities
2033 * @hw: pointer to hardware structure
2034 * @device_caps: the EEPROM word with the extra device capabilities
2036 * This function will read the EEPROM location for the device capabilities,
2037 * and return the word through device_caps.
2039 static s32 ixgbe_get_device_caps_82599(struct ixgbe_hw *hw, u16 *device_caps)
2041 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
2047 * ixgbe_verify_fw_version_82599 - verify fw version for 82599
2048 * @hw: pointer to hardware structure
2050 * Verifies that installed the firmware version is 0.6 or higher
2051 * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
2053 * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
2054 * if the FW version is not supported.
2056 static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
2058 s32 status = IXGBE_ERR_EEPROM_VERSION;
2059 u16 fw_offset, fw_ptp_cfg_offset;
2062 /* firmware check is only necessary for SFI devices */
2063 if (hw->phy.media_type != ixgbe_media_type_fiber) {
2065 goto fw_version_out;
2068 /* get the offset to the Firmware Module block */
2069 hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
2071 if ((fw_offset == 0) || (fw_offset == 0xFFFF))
2072 goto fw_version_out;
2074 /* get the offset to the Pass Through Patch Configuration block */
2075 hw->eeprom.ops.read(hw, (fw_offset +
2076 IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
2077 &fw_ptp_cfg_offset);
2079 if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
2080 goto fw_version_out;
2082 /* get the firmware version */
2083 hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
2084 IXGBE_FW_PATCH_VERSION_4),
2087 if (fw_version > 0x5)
2094 static struct ixgbe_mac_operations mac_ops_82599 = {
2095 .init_hw = &ixgbe_init_hw_generic,
2096 .reset_hw = &ixgbe_reset_hw_82599,
2097 .start_hw = &ixgbe_start_hw_82599,
2098 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
2099 .get_media_type = &ixgbe_get_media_type_82599,
2100 .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
2101 .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
2102 .get_mac_addr = &ixgbe_get_mac_addr_generic,
2103 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
2104 .get_device_caps = &ixgbe_get_device_caps_82599,
2105 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
2106 .stop_adapter = &ixgbe_stop_adapter_generic,
2107 .get_bus_info = &ixgbe_get_bus_info_generic,
2108 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
2109 .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
2110 .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
2111 .setup_link = &ixgbe_setup_mac_link_82599,
2112 .check_link = &ixgbe_check_mac_link_generic,
2113 .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
2114 .led_on = &ixgbe_led_on_generic,
2115 .led_off = &ixgbe_led_off_generic,
2116 .blink_led_start = &ixgbe_blink_led_start_generic,
2117 .blink_led_stop = &ixgbe_blink_led_stop_generic,
2118 .set_rar = &ixgbe_set_rar_generic,
2119 .clear_rar = &ixgbe_clear_rar_generic,
2120 .set_vmdq = &ixgbe_set_vmdq_generic,
2121 .clear_vmdq = &ixgbe_clear_vmdq_generic,
2122 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
2123 .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
2124 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
2125 .enable_mc = &ixgbe_enable_mc_generic,
2126 .disable_mc = &ixgbe_disable_mc_generic,
2127 .clear_vfta = &ixgbe_clear_vfta_generic,
2128 .set_vfta = &ixgbe_set_vfta_generic,
2129 .fc_enable = &ixgbe_fc_enable_generic,
2130 .init_uta_tables = &ixgbe_init_uta_tables_generic,
2131 .setup_sfp = &ixgbe_setup_sfp_modules_82599,
2134 static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
2135 .init_params = &ixgbe_init_eeprom_params_generic,
2136 .read = &ixgbe_read_eerd_generic,
2137 .write = &ixgbe_write_eeprom_generic,
2138 .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
2139 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
2140 .update_checksum = &ixgbe_update_eeprom_checksum_generic,
2143 static struct ixgbe_phy_operations phy_ops_82599 = {
2144 .identify = &ixgbe_identify_phy_82599,
2145 .identify_sfp = &ixgbe_identify_sfp_module_generic,
2146 .init = &ixgbe_init_phy_ops_82599,
2147 .reset = &ixgbe_reset_phy_generic,
2148 .read_reg = &ixgbe_read_phy_reg_generic,
2149 .write_reg = &ixgbe_write_phy_reg_generic,
2150 .setup_link = &ixgbe_setup_phy_link_generic,
2151 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
2152 .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
2153 .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
2154 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
2155 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
2156 .check_overtemp = &ixgbe_tn_check_overtemp,
2159 struct ixgbe_info ixgbe_82599_info = {
2160 .mac = ixgbe_mac_82599EB,
2161 .get_invariants = &ixgbe_get_invariants_82599,
2162 .mac_ops = &mac_ops_82599,
2163 .eeprom_ops = &eeprom_ops_82599,
2164 .phy_ops = &phy_ops_82599,
2165 .mbx_ops = &mbx_ops_generic,