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 void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
43 void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
44 void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
45 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 s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
54 bool autoneg_wait_to_complete);
55 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_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
60 ixgbe_link_speed *speed,
62 static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
63 ixgbe_link_speed speed,
65 bool autoneg_wait_to_complete);
66 static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
68 static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
70 struct ixgbe_mac_info *mac = &hw->mac;
71 if (hw->phy.multispeed_fiber) {
72 /* Set up dual speed SFP+ support */
73 mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
74 mac->ops.disable_tx_laser =
75 &ixgbe_disable_tx_laser_multispeed_fiber;
76 mac->ops.enable_tx_laser =
77 &ixgbe_enable_tx_laser_multispeed_fiber;
78 mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
80 mac->ops.disable_tx_laser = NULL;
81 mac->ops.enable_tx_laser = NULL;
82 mac->ops.flap_tx_laser = NULL;
83 if ((mac->ops.get_media_type(hw) ==
84 ixgbe_media_type_backplane) &&
85 (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
86 hw->phy.smart_speed == ixgbe_smart_speed_on))
87 mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
89 mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
93 static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
96 u16 list_offset, data_offset, data_value;
98 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
99 ixgbe_init_mac_link_ops_82599(hw);
101 hw->phy.ops.reset = NULL;
103 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
109 /* PHY config will finish before releasing the semaphore */
110 ret_val = ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
112 ret_val = IXGBE_ERR_SWFW_SYNC;
116 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
117 while (data_value != 0xffff) {
118 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
119 IXGBE_WRITE_FLUSH(hw);
120 hw->eeprom.ops.read(hw, ++data_offset, &data_value);
122 /* Now restart DSP by setting Restart_AN */
123 IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
124 (IXGBE_READ_REG(hw, IXGBE_AUTOC) | IXGBE_AUTOC_AN_RESTART));
126 /* Release the semaphore */
127 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
128 /* Delay obtaining semaphore again to allow FW access */
129 msleep(hw->eeprom.semaphore_delay);
137 * ixgbe_get_pcie_msix_count_82599 - Gets MSI-X vector count
138 * @hw: pointer to hardware structure
140 * Read PCIe configuration space, and get the MSI-X vector count from
141 * the capabilities table.
143 static u32 ixgbe_get_pcie_msix_count_82599(struct ixgbe_hw *hw)
145 struct ixgbe_adapter *adapter = hw->back;
147 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
149 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
151 /* MSI-X count is zero-based in HW, so increment to give proper value */
157 static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
159 struct ixgbe_mac_info *mac = &hw->mac;
161 ixgbe_init_mac_link_ops_82599(hw);
163 mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
164 mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
165 mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
166 mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
167 mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
168 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82599(hw);
174 * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
175 * @hw: pointer to hardware structure
177 * Initialize any function pointers that were not able to be
178 * set during get_invariants because the PHY/SFP type was
179 * not known. Perform the SFP init if necessary.
182 static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
184 struct ixgbe_mac_info *mac = &hw->mac;
185 struct ixgbe_phy_info *phy = &hw->phy;
188 /* Identify the PHY or SFP module */
189 ret_val = phy->ops.identify(hw);
191 /* Setup function pointers based on detected SFP module and speeds */
192 ixgbe_init_mac_link_ops_82599(hw);
194 /* If copper media, overwrite with copper function pointers */
195 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
196 mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
197 mac->ops.get_link_capabilities =
198 &ixgbe_get_copper_link_capabilities_82599;
201 /* Set necessary function pointers based on phy type */
202 switch (hw->phy.type) {
204 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
205 phy->ops.get_firmware_version =
206 &ixgbe_get_phy_firmware_version_tnx;
216 * ixgbe_get_link_capabilities_82599 - Determines link capabilities
217 * @hw: pointer to hardware structure
218 * @speed: pointer to link speed
219 * @negotiation: true when autoneg or autotry is enabled
221 * Determines the link capabilities by reading the AUTOC register.
223 static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
224 ixgbe_link_speed *speed,
231 * Determine link capabilities based on the stored value of AUTOC,
232 * which represents EEPROM defaults. If AUTOC value has not been
233 * stored, use the current register value.
235 if (hw->mac.orig_link_settings_stored)
236 autoc = hw->mac.orig_autoc;
238 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
240 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
241 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
242 *speed = IXGBE_LINK_SPEED_1GB_FULL;
243 *negotiation = false;
246 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
247 *speed = IXGBE_LINK_SPEED_10GB_FULL;
248 *negotiation = false;
251 case IXGBE_AUTOC_LMS_1G_AN:
252 *speed = IXGBE_LINK_SPEED_1GB_FULL;
256 case IXGBE_AUTOC_LMS_10G_SERIAL:
257 *speed = IXGBE_LINK_SPEED_10GB_FULL;
258 *negotiation = false;
261 case IXGBE_AUTOC_LMS_KX4_KX_KR:
262 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
263 *speed = IXGBE_LINK_SPEED_UNKNOWN;
264 if (autoc & IXGBE_AUTOC_KR_SUPP)
265 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
266 if (autoc & IXGBE_AUTOC_KX4_SUPP)
267 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
268 if (autoc & IXGBE_AUTOC_KX_SUPP)
269 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
273 case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
274 *speed = IXGBE_LINK_SPEED_100_FULL;
275 if (autoc & IXGBE_AUTOC_KR_SUPP)
276 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
277 if (autoc & IXGBE_AUTOC_KX4_SUPP)
278 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
279 if (autoc & IXGBE_AUTOC_KX_SUPP)
280 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
284 case IXGBE_AUTOC_LMS_SGMII_1G_100M:
285 *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
286 *negotiation = false;
290 status = IXGBE_ERR_LINK_SETUP;
295 if (hw->phy.multispeed_fiber) {
296 *speed |= IXGBE_LINK_SPEED_10GB_FULL |
297 IXGBE_LINK_SPEED_1GB_FULL;
306 * ixgbe_get_copper_link_capabilities_82599 - Determines link capabilities
307 * @hw: pointer to hardware structure
308 * @speed: pointer to link speed
309 * @autoneg: boolean auto-negotiation value
311 * Determines the link capabilities by reading the AUTOC register.
313 static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
314 ixgbe_link_speed *speed,
317 s32 status = IXGBE_ERR_LINK_SETUP;
323 status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
327 if (speed_ability & MDIO_SPEED_10G)
328 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
329 if (speed_ability & MDIO_PMA_SPEED_1000)
330 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
337 * ixgbe_get_media_type_82599 - Get media type
338 * @hw: pointer to hardware structure
340 * Returns the media type (fiber, copper, backplane)
342 static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
344 enum ixgbe_media_type media_type;
346 /* Detect if there is a copper PHY attached. */
347 if (hw->phy.type == ixgbe_phy_cu_unknown ||
348 hw->phy.type == ixgbe_phy_tn) {
349 media_type = ixgbe_media_type_copper;
353 switch (hw->device_id) {
354 case IXGBE_DEV_ID_82599_KX4:
355 case IXGBE_DEV_ID_82599_KX4_MEZZ:
356 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
357 case IXGBE_DEV_ID_82599_KR:
358 case IXGBE_DEV_ID_82599_XAUI_LOM:
359 /* Default device ID is mezzanine card KX/KX4 */
360 media_type = ixgbe_media_type_backplane;
362 case IXGBE_DEV_ID_82599_SFP:
363 case IXGBE_DEV_ID_82599_SFP_EM:
364 media_type = ixgbe_media_type_fiber;
366 case IXGBE_DEV_ID_82599_CX4:
367 media_type = ixgbe_media_type_cx4;
370 media_type = ixgbe_media_type_unknown;
378 * ixgbe_start_mac_link_82599 - Setup MAC link settings
379 * @hw: pointer to hardware structure
380 * @autoneg_wait_to_complete: true when waiting for completion is needed
382 * Configures link settings based on values in the ixgbe_hw struct.
383 * Restarts the link. Performs autonegotiation if needed.
385 s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
386 bool autoneg_wait_to_complete)
394 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
395 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
396 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
398 /* Only poll for autoneg to complete if specified to do so */
399 if (autoneg_wait_to_complete) {
400 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
401 IXGBE_AUTOC_LMS_KX4_KX_KR ||
402 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
403 IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
404 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
405 IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
406 links_reg = 0; /* Just in case Autoneg time = 0 */
407 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
408 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
409 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
413 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
414 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
415 hw_dbg(hw, "Autoneg did not complete.\n");
420 /* Add delay to filter out noises during initial link setup */
427 * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
428 * @hw: pointer to hardware structure
430 * The base drivers may require better control over SFP+ module
431 * PHY states. This includes selectively shutting down the Tx
432 * laser on the PHY, effectively halting physical link.
434 void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
436 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
438 /* Disable tx laser; allow 100us to go dark per spec */
439 esdp_reg |= IXGBE_ESDP_SDP3;
440 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
441 IXGBE_WRITE_FLUSH(hw);
446 * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
447 * @hw: pointer to hardware structure
449 * The base drivers may require better control over SFP+ module
450 * PHY states. This includes selectively turning on the Tx
451 * laser on the PHY, effectively starting physical link.
453 void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
455 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
457 /* Enable tx laser; allow 100ms to light up */
458 esdp_reg &= ~IXGBE_ESDP_SDP3;
459 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
460 IXGBE_WRITE_FLUSH(hw);
465 * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
466 * @hw: pointer to hardware structure
468 * When the driver changes the link speeds that it can support,
469 * it sets autotry_restart to true to indicate that we need to
470 * initiate a new autotry session with the link partner. To do
471 * so, we set the speed then disable and re-enable the tx laser, to
472 * alert the link partner that it also needs to restart autotry on its
473 * end. This is consistent with true clause 37 autoneg, which also
474 * involves a loss of signal.
476 void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
478 hw_dbg(hw, "ixgbe_flap_tx_laser_multispeed_fiber\n");
480 if (hw->mac.autotry_restart) {
481 ixgbe_disable_tx_laser_multispeed_fiber(hw);
482 ixgbe_enable_tx_laser_multispeed_fiber(hw);
483 hw->mac.autotry_restart = false;
488 * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
489 * @hw: pointer to hardware structure
490 * @speed: new link speed
491 * @autoneg: true if autonegotiation enabled
492 * @autoneg_wait_to_complete: true when waiting for completion is needed
494 * Set the link speed in the AUTOC register and restarts link.
496 s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
497 ixgbe_link_speed speed,
499 bool autoneg_wait_to_complete)
502 ixgbe_link_speed phy_link_speed;
503 ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
505 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
506 bool link_up = false;
510 /* Mask off requested but non-supported speeds */
511 hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
512 speed &= phy_link_speed;
515 * Try each speed one by one, highest priority first. We do this in
516 * software because 10gb fiber doesn't support speed autonegotiation.
518 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
520 highest_link_speed = IXGBE_LINK_SPEED_10GB_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_10GB_FULL) && link_up)
528 /* Set the module link speed */
529 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
530 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
531 IXGBE_WRITE_FLUSH(hw);
533 /* Allow module to change analog characteristics (1G->10G) */
536 status = ixgbe_setup_mac_link_82599(hw,
537 IXGBE_LINK_SPEED_10GB_FULL,
539 autoneg_wait_to_complete);
543 /* Flap the tx laser if it has not already been done */
544 hw->mac.ops.flap_tx_laser(hw);
547 * Wait for the controller to acquire link. Per IEEE 802.3ap,
548 * Section 73.10.2, we may have to wait up to 500ms if KR is
549 * attempted. 82599 uses the same timing for 10g SFI.
552 for (i = 0; i < 5; i++) {
553 /* Wait for the link partner to also set speed */
556 /* If we have link, just jump out */
557 hw->mac.ops.check_link(hw, &phy_link_speed,
564 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
566 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
567 highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
569 /* If we already have link at this speed, just jump out */
570 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
572 if ((phy_link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
575 /* Set the module link speed */
576 esdp_reg &= ~IXGBE_ESDP_SDP5;
577 esdp_reg |= IXGBE_ESDP_SDP5_DIR;
578 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
579 IXGBE_WRITE_FLUSH(hw);
581 /* Allow module to change analog characteristics (10G->1G) */
584 status = ixgbe_setup_mac_link_82599(hw,
585 IXGBE_LINK_SPEED_1GB_FULL,
587 autoneg_wait_to_complete);
591 /* Flap the tx laser if it has not already been done */
592 hw->mac.ops.flap_tx_laser(hw);
594 /* Wait for the link partner to also set speed */
597 /* If we have link, just jump out */
598 hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
604 * We didn't get link. Configure back to the highest speed we tried,
605 * (if there was more than one). We call ourselves back with just the
606 * single highest speed that the user requested.
609 status = ixgbe_setup_mac_link_multispeed_fiber(hw,
612 autoneg_wait_to_complete);
615 /* Set autoneg_advertised value based on input link speed */
616 hw->phy.autoneg_advertised = 0;
618 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
619 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
621 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
622 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
628 * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
629 * @hw: pointer to hardware structure
630 * @speed: new link speed
631 * @autoneg: true if autonegotiation enabled
632 * @autoneg_wait_to_complete: true when waiting for completion is needed
634 * Implements the Intel SmartSpeed algorithm.
636 static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
637 ixgbe_link_speed speed, bool autoneg,
638 bool autoneg_wait_to_complete)
641 ixgbe_link_speed link_speed;
643 bool link_up = false;
644 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
645 struct ixgbe_adapter *adapter = hw->back;
647 hw_dbg(hw, "ixgbe_setup_mac_link_smartspeed.\n");
649 /* Set autoneg_advertised value based on input link speed */
650 hw->phy.autoneg_advertised = 0;
652 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
653 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
655 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
656 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
658 if (speed & IXGBE_LINK_SPEED_100_FULL)
659 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
662 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
663 * autoneg advertisement if link is unable to be established at the
664 * highest negotiated rate. This can sometimes happen due to integrity
665 * issues with the physical media connection.
668 /* First, try to get link with full advertisement */
669 hw->phy.smart_speed_active = false;
670 for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
671 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
672 autoneg_wait_to_complete);
677 * Wait for the controller to acquire link. Per IEEE 802.3ap,
678 * Section 73.10.2, we may have to wait up to 500ms if KR is
679 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
680 * Table 9 in the AN MAS.
682 for (i = 0; i < 5; i++) {
685 /* If we have link, just jump out */
686 hw->mac.ops.check_link(hw, &link_speed,
694 * We didn't get link. If we advertised KR plus one of KX4/KX
695 * (or BX4/BX), then disable KR and try again.
697 if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
698 ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
701 /* Turn SmartSpeed on to disable KR support */
702 hw->phy.smart_speed_active = true;
703 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
704 autoneg_wait_to_complete);
709 * Wait for the controller to acquire link. 600ms will allow for
710 * the AN link_fail_inhibit_timer as well for multiple cycles of
711 * parallel detect, both 10g and 1g. This allows for the maximum
712 * connect attempts as defined in the AN MAS table 73-7.
714 for (i = 0; i < 6; i++) {
717 /* If we have link, just jump out */
718 hw->mac.ops.check_link(hw, &link_speed,
724 /* We didn't get link. Turn SmartSpeed back off. */
725 hw->phy.smart_speed_active = false;
726 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
727 autoneg_wait_to_complete);
730 if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
731 netif_info(adapter, hw, adapter->netdev, "Smartspeed has"
732 " downgraded the link speed from the maximum"
738 * ixgbe_check_mac_link_82599 - Determine link and speed status
739 * @hw: pointer to hardware structure
740 * @speed: pointer to link speed
741 * @link_up: true when link is up
742 * @link_up_wait_to_complete: bool used to wait for link up or not
744 * Reads the links register to determine if link is up and the current speed
746 static s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw,
747 ixgbe_link_speed *speed,
749 bool link_up_wait_to_complete)
754 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
755 if (link_up_wait_to_complete) {
756 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
757 if (links_reg & IXGBE_LINKS_UP) {
764 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
767 if (links_reg & IXGBE_LINKS_UP)
773 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
774 IXGBE_LINKS_SPEED_10G_82599)
775 *speed = IXGBE_LINK_SPEED_10GB_FULL;
776 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
777 IXGBE_LINKS_SPEED_1G_82599)
778 *speed = IXGBE_LINK_SPEED_1GB_FULL;
780 *speed = IXGBE_LINK_SPEED_100_FULL;
782 /* if link is down, zero out the current_mode */
783 if (*link_up == false) {
784 hw->fc.current_mode = ixgbe_fc_none;
785 hw->fc.fc_was_autonegged = false;
792 * ixgbe_setup_mac_link_82599 - Set MAC link speed
793 * @hw: pointer to hardware structure
794 * @speed: new link speed
795 * @autoneg: true if autonegotiation enabled
796 * @autoneg_wait_to_complete: true when waiting for completion is needed
798 * Set the link speed in the AUTOC register and restarts link.
800 s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
801 ixgbe_link_speed speed, bool autoneg,
802 bool autoneg_wait_to_complete)
805 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
806 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
807 u32 start_autoc = autoc;
809 u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
810 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
811 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
814 ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
816 /* Check to see if speed passed in is supported. */
817 hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
818 speed &= link_capabilities;
820 if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
821 status = IXGBE_ERR_LINK_SETUP;
825 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
826 if (hw->mac.orig_link_settings_stored)
827 orig_autoc = hw->mac.orig_autoc;
832 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
833 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
834 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
835 /* Set KX4/KX/KR support according to speed requested */
836 autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
837 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
838 if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
839 autoc |= IXGBE_AUTOC_KX4_SUPP;
840 if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
841 (hw->phy.smart_speed_active == false))
842 autoc |= IXGBE_AUTOC_KR_SUPP;
843 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
844 autoc |= IXGBE_AUTOC_KX_SUPP;
845 } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
846 (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
847 link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
848 /* Switch from 1G SFI to 10G SFI if requested */
849 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
850 (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
851 autoc &= ~IXGBE_AUTOC_LMS_MASK;
852 autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
854 } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
855 (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
856 /* Switch from 10G SFI to 1G SFI if requested */
857 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
858 (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
859 autoc &= ~IXGBE_AUTOC_LMS_MASK;
861 autoc |= IXGBE_AUTOC_LMS_1G_AN;
863 autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
867 if (autoc != start_autoc) {
869 autoc |= IXGBE_AUTOC_AN_RESTART;
870 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
872 /* Only poll for autoneg to complete if specified to do so */
873 if (autoneg_wait_to_complete) {
874 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
875 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
876 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
877 links_reg = 0; /*Just in case Autoneg time=0*/
878 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
880 IXGBE_READ_REG(hw, IXGBE_LINKS);
881 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
885 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
887 IXGBE_ERR_AUTONEG_NOT_COMPLETE;
888 hw_dbg(hw, "Autoneg did not "
894 /* Add delay to filter out noises during initial link setup */
903 * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
904 * @hw: pointer to hardware structure
905 * @speed: new link speed
906 * @autoneg: true if autonegotiation enabled
907 * @autoneg_wait_to_complete: true if waiting is needed to complete
909 * Restarts link on PHY and MAC based on settings passed in.
911 static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
912 ixgbe_link_speed speed,
914 bool autoneg_wait_to_complete)
918 /* Setup the PHY according to input speed */
919 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
920 autoneg_wait_to_complete);
922 ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
928 * ixgbe_reset_hw_82599 - Perform hardware reset
929 * @hw: pointer to hardware structure
931 * Resets the hardware by resetting the transmit and receive units, masks
932 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
935 static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
943 /* Call adapter stop to disable tx/rx and clear interrupts */
944 hw->mac.ops.stop_adapter(hw);
946 /* PHY ops must be identified and initialized prior to reset */
948 /* Init PHY and function pointers, perform SFP setup */
949 status = hw->phy.ops.init(hw);
951 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
954 /* Setup SFP module if there is one present. */
955 if (hw->phy.sfp_setup_needed) {
956 status = hw->mac.ops.setup_sfp(hw);
957 hw->phy.sfp_setup_needed = false;
961 if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
962 hw->phy.ops.reset(hw);
965 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
966 * access and verify no pending requests before reset
968 status = ixgbe_disable_pcie_master(hw);
970 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
971 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
975 * Issue global reset to the MAC. This needs to be a SW reset.
976 * If link reset is used, it might reset the MAC when mng is using it
978 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
979 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
980 IXGBE_WRITE_FLUSH(hw);
982 /* Poll for reset bit to self-clear indicating reset is complete */
983 for (i = 0; i < 10; i++) {
985 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
986 if (!(ctrl & IXGBE_CTRL_RST))
989 if (ctrl & IXGBE_CTRL_RST) {
990 status = IXGBE_ERR_RESET_FAILED;
991 hw_dbg(hw, "Reset polling failed to complete.\n");
997 * Store the original AUTOC/AUTOC2 values if they have not been
998 * stored off yet. Otherwise restore the stored original
999 * values since the reset operation sets back to defaults.
1001 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1002 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
1003 if (hw->mac.orig_link_settings_stored == false) {
1004 hw->mac.orig_autoc = autoc;
1005 hw->mac.orig_autoc2 = autoc2;
1006 hw->mac.orig_link_settings_stored = true;
1008 if (autoc != hw->mac.orig_autoc)
1009 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
1010 IXGBE_AUTOC_AN_RESTART));
1012 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
1013 (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
1014 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
1015 autoc2 |= (hw->mac.orig_autoc2 &
1016 IXGBE_AUTOC2_UPPER_MASK);
1017 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
1022 * Store MAC address from RAR0, clear receive address registers, and
1023 * clear the multicast table. Also reset num_rar_entries to 128,
1024 * since we modify this value when programming the SAN MAC address.
1026 hw->mac.num_rar_entries = 128;
1027 hw->mac.ops.init_rx_addrs(hw);
1029 /* Store the permanent mac address */
1030 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
1032 /* Store the permanent SAN mac address */
1033 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
1035 /* Add the SAN MAC address to the RAR only if it's a valid address */
1036 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
1037 hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
1038 hw->mac.san_addr, 0, IXGBE_RAH_AV);
1040 /* Reserve the last RAR for the SAN MAC address */
1041 hw->mac.num_rar_entries--;
1044 /* Store the alternative WWNN/WWPN prefix */
1045 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
1046 &hw->mac.wwpn_prefix);
1053 * ixgbe_clear_vmdq_82599 - Disassociate a VMDq pool index from a rx address
1054 * @hw: pointer to hardware struct
1055 * @rar: receive address register index to disassociate
1056 * @vmdq: VMDq pool index to remove from the rar
1058 static s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
1060 u32 mpsar_lo, mpsar_hi;
1061 u32 rar_entries = hw->mac.num_rar_entries;
1063 if (rar < rar_entries) {
1064 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
1065 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
1067 if (!mpsar_lo && !mpsar_hi)
1070 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
1072 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
1076 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
1079 } else if (vmdq < 32) {
1080 mpsar_lo &= ~(1 << vmdq);
1081 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
1083 mpsar_hi &= ~(1 << (vmdq - 32));
1084 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
1087 /* was that the last pool using this rar? */
1088 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
1089 hw->mac.ops.clear_rar(hw, rar);
1091 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
1099 * ixgbe_set_vmdq_82599 - Associate a VMDq pool index with a rx address
1100 * @hw: pointer to hardware struct
1101 * @rar: receive address register index to associate with a VMDq index
1102 * @vmdq: VMDq pool index
1104 static s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
1107 u32 rar_entries = hw->mac.num_rar_entries;
1109 if (rar < rar_entries) {
1111 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
1113 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
1115 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
1116 mpsar |= 1 << (vmdq - 32);
1117 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
1120 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
1126 * ixgbe_set_vfta_82599 - Set VLAN filter table
1127 * @hw: pointer to hardware structure
1128 * @vlan: VLAN id to write to VLAN filter
1129 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
1130 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
1132 * Turn on/off specified VLAN in the VLAN filter table.
1134 static s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan, u32 vind,
1141 u32 first_empty_slot;
1145 return IXGBE_ERR_PARAM;
1148 * this is a 2 part operation - first the VFTA, then the
1149 * VLVF and VLVFB if vind is set
1153 * The VFTA is a bitstring made up of 128 32-bit registers
1154 * that enable the particular VLAN id, much like the MTA:
1155 * bits[11-5]: which register
1156 * bits[4-0]: which bit in the register
1158 regindex = (vlan >> 5) & 0x7F;
1159 bitindex = vlan & 0x1F;
1160 bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
1162 bits |= (1 << bitindex);
1164 bits &= ~(1 << bitindex);
1165 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
1171 * make sure the vlan is in VLVF
1172 * set the vind bit in the matching VLVFB
1174 * clear the pool bit and possibly the vind
1176 vt_ctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
1177 if (!(vt_ctl & IXGBE_VT_CTL_VT_ENABLE))
1180 /* find the vlanid or the first empty slot */
1181 first_empty_slot = 0;
1183 for (vlvf_index = 1; vlvf_index < IXGBE_VLVF_ENTRIES; vlvf_index++) {
1184 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(vlvf_index));
1185 if (!bits && !first_empty_slot)
1186 first_empty_slot = vlvf_index;
1187 else if ((bits & 0x0FFF) == vlan)
1191 if (vlvf_index >= IXGBE_VLVF_ENTRIES) {
1192 if (first_empty_slot)
1193 vlvf_index = first_empty_slot;
1195 hw_dbg(hw, "No space in VLVF.\n");
1201 /* set the pool bit */
1203 bits = IXGBE_READ_REG(hw,
1204 IXGBE_VLVFB(vlvf_index * 2));
1205 bits |= (1 << vind);
1207 IXGBE_VLVFB(vlvf_index * 2), bits);
1209 bits = IXGBE_READ_REG(hw,
1210 IXGBE_VLVFB((vlvf_index * 2) + 1));
1211 bits |= (1 << (vind - 32));
1213 IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
1216 /* clear the pool bit */
1218 bits = IXGBE_READ_REG(hw,
1219 IXGBE_VLVFB(vlvf_index * 2));
1220 bits &= ~(1 << vind);
1222 IXGBE_VLVFB(vlvf_index * 2), bits);
1223 bits |= IXGBE_READ_REG(hw,
1224 IXGBE_VLVFB((vlvf_index * 2) + 1));
1226 bits = IXGBE_READ_REG(hw,
1227 IXGBE_VLVFB((vlvf_index * 2) + 1));
1228 bits &= ~(1 << (vind - 32));
1230 IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
1231 bits |= IXGBE_READ_REG(hw,
1232 IXGBE_VLVFB(vlvf_index * 2));
1237 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
1238 (IXGBE_VLVF_VIEN | vlan));
1239 /* if bits is non-zero then some pools/VFs are still
1240 * using this VLAN ID. Force the VFTA entry to on */
1241 bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
1242 bits |= (1 << bitindex);
1243 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
1246 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
1253 * ixgbe_clear_vfta_82599 - Clear VLAN filter table
1254 * @hw: pointer to hardware structure
1256 * Clears the VLAN filer table, and the VMDq index associated with the filter
1258 static s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw)
1262 for (offset = 0; offset < hw->mac.vft_size; offset++)
1263 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
1265 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
1266 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
1267 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
1268 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
1275 * ixgbe_init_uta_tables_82599 - Initialize the Unicast Table Array
1276 * @hw: pointer to hardware structure
1278 static s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw)
1281 hw_dbg(hw, " Clearing UTA\n");
1283 for (i = 0; i < 128; i++)
1284 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
1290 * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
1291 * @hw: pointer to hardware structure
1293 s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
1296 u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
1297 fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
1300 * Before starting reinitialization process,
1301 * FDIRCMD.CMD must be zero.
1303 for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
1304 if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
1305 IXGBE_FDIRCMD_CMD_MASK))
1309 if (i >= IXGBE_FDIRCMD_CMD_POLL) {
1310 hw_dbg(hw ,"Flow Director previous command isn't complete, "
1311 "aborting table re-initialization.\n");
1312 return IXGBE_ERR_FDIR_REINIT_FAILED;
1315 IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
1316 IXGBE_WRITE_FLUSH(hw);
1318 * 82599 adapters flow director init flow cannot be restarted,
1319 * Workaround 82599 silicon errata by performing the following steps
1320 * before re-writing the FDIRCTRL control register with the same value.
1321 * - write 1 to bit 8 of FDIRCMD register &
1322 * - write 0 to bit 8 of FDIRCMD register
1324 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
1325 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
1326 IXGBE_FDIRCMD_CLEARHT));
1327 IXGBE_WRITE_FLUSH(hw);
1328 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
1329 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
1330 ~IXGBE_FDIRCMD_CLEARHT));
1331 IXGBE_WRITE_FLUSH(hw);
1333 * Clear FDIR Hash register to clear any leftover hashes
1334 * waiting to be programmed.
1336 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
1337 IXGBE_WRITE_FLUSH(hw);
1339 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1340 IXGBE_WRITE_FLUSH(hw);
1342 /* Poll init-done after we write FDIRCTRL register */
1343 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1344 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1345 IXGBE_FDIRCTRL_INIT_DONE)
1349 if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
1350 hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
1351 return IXGBE_ERR_FDIR_REINIT_FAILED;
1354 /* Clear FDIR statistics registers (read to clear) */
1355 IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
1356 IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
1357 IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
1358 IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
1359 IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
1365 * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
1366 * @hw: pointer to hardware structure
1367 * @pballoc: which mode to allocate filters with
1369 s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc)
1376 * Before enabling Flow Director, the Rx Packet Buffer size
1377 * must be reduced. The new value is the current size minus
1378 * flow director memory usage size.
1380 pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
1381 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
1382 (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
1385 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1386 * intialized to zero for non DCB mode otherwise actual total RX PB
1387 * would be bigger than programmed and filter space would run into
1390 for (i = 1; i < 8; i++)
1391 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
1393 /* Send interrupt when 64 filters are left */
1394 fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
1396 /* Set the maximum length per hash bucket to 0xA filters */
1397 fdirctrl |= 0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT;
1400 case IXGBE_FDIR_PBALLOC_64K:
1401 /* 8k - 1 signature filters */
1402 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
1404 case IXGBE_FDIR_PBALLOC_128K:
1405 /* 16k - 1 signature filters */
1406 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
1408 case IXGBE_FDIR_PBALLOC_256K:
1409 /* 32k - 1 signature filters */
1410 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
1414 return IXGBE_ERR_CONFIG;
1417 /* Move the flexible bytes to use the ethertype - shift 6 words */
1418 fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
1420 fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
1422 /* Prime the keys for hashing */
1423 IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
1424 htonl(IXGBE_ATR_BUCKET_HASH_KEY));
1425 IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
1426 htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
1429 * Poll init-done after we write the register. Estimated times:
1430 * 10G: PBALLOC = 11b, timing is 60us
1431 * 1G: PBALLOC = 11b, timing is 600us
1432 * 100M: PBALLOC = 11b, timing is 6ms
1434 * Multiple these timings by 4 if under full Rx load
1436 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1437 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1438 * this might not finish in our poll time, but we can live with that
1441 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1442 IXGBE_WRITE_FLUSH(hw);
1443 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1444 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1445 IXGBE_FDIRCTRL_INIT_DONE)
1449 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
1450 hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
1456 * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
1457 * @hw: pointer to hardware structure
1458 * @pballoc: which mode to allocate filters with
1460 s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
1467 * Before enabling Flow Director, the Rx Packet Buffer size
1468 * must be reduced. The new value is the current size minus
1469 * flow director memory usage size.
1471 pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
1472 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
1473 (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
1476 * The defaults in the HW for RX PB 1-7 are not zero and so should be
1477 * intialized to zero for non DCB mode otherwise actual total RX PB
1478 * would be bigger than programmed and filter space would run into
1481 for (i = 1; i < 8; i++)
1482 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
1484 /* Send interrupt when 64 filters are left */
1485 fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
1487 /* Initialize the drop queue to Rx queue 127 */
1488 fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
1491 case IXGBE_FDIR_PBALLOC_64K:
1492 /* 2k - 1 perfect filters */
1493 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
1495 case IXGBE_FDIR_PBALLOC_128K:
1496 /* 4k - 1 perfect filters */
1497 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
1499 case IXGBE_FDIR_PBALLOC_256K:
1500 /* 8k - 1 perfect filters */
1501 fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
1505 return IXGBE_ERR_CONFIG;
1508 /* Turn perfect match filtering on */
1509 fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH;
1510 fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
1512 /* Move the flexible bytes to use the ethertype - shift 6 words */
1513 fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
1515 /* Prime the keys for hashing */
1516 IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
1517 htonl(IXGBE_ATR_BUCKET_HASH_KEY));
1518 IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
1519 htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
1522 * Poll init-done after we write the register. Estimated times:
1523 * 10G: PBALLOC = 11b, timing is 60us
1524 * 1G: PBALLOC = 11b, timing is 600us
1525 * 100M: PBALLOC = 11b, timing is 6ms
1527 * Multiple these timings by 4 if under full Rx load
1529 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1530 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1531 * this might not finish in our poll time, but we can live with that
1535 /* Set the maximum length per hash bucket to 0xA filters */
1536 fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT);
1538 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1539 IXGBE_WRITE_FLUSH(hw);
1540 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1541 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
1542 IXGBE_FDIRCTRL_INIT_DONE)
1546 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
1547 hw_dbg(hw, "Flow Director Perfect poll time exceeded!\n");
1554 * ixgbe_atr_compute_hash_82599 - Compute the hashes for SW ATR
1555 * @stream: input bitstream to compute the hash on
1556 * @key: 32-bit hash key
1558 static u16 ixgbe_atr_compute_hash_82599(struct ixgbe_atr_input *atr_input,
1562 * The algorithm is as follows:
1563 * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
1564 * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
1565 * and A[n] x B[n] is bitwise AND between same length strings
1567 * K[n] is 16 bits, defined as:
1568 * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
1569 * for n modulo 32 < 15, K[n] =
1570 * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
1572 * S[n] is 16 bits, defined as:
1573 * for n >= 15, S[n] = S[n:n - 15]
1574 * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
1576 * To simplify for programming, the algorithm is implemented
1577 * in software this way:
1579 * Key[31:0], Stream[335:0]
1581 * tmp_key[11 * 32 - 1:0] = 11{Key[31:0] = key concatenated 11 times
1582 * int_key[350:0] = tmp_key[351:1]
1583 * int_stream[365:0] = Stream[14:0] | Stream[335:0] | Stream[335:321]
1586 * for (i = 0; i < 351; i++) {
1588 * hash ^= int_stream[(i + 15):i];
1598 u8 *stream = (u8 *)atr_input;
1599 u8 int_key[44]; /* upper-most bit unused */
1600 u8 hash_str[46]; /* upper-most 2 bits unused */
1601 u16 hash_result = 0;
1605 * Initialize the fill member to prevent warnings
1608 tmp_key.fill[0] = 0;
1610 /* First load the temporary key stream */
1611 for (i = 0; i < 6; i++) {
1612 u64 fillkey = ((u64)key << 32) | key;
1613 tmp_key.fill[i] = fillkey;
1617 * Set the interim key for the hashing. Bit 352 is unused, so we must
1618 * shift and compensate when building the key.
1621 int_key[0] = tmp_key.key_stream[0] >> 1;
1622 for (i = 1, j = 0; i < 44; i++) {
1623 unsigned int this_key = tmp_key.key_stream[j] << 7;
1625 int_key[i] = (u8)(this_key | (tmp_key.key_stream[j] >> 1));
1629 * Set the interim bit string for the hashing. Bits 368 and 367 are
1630 * unused, so shift and compensate when building the string.
1632 hash_str[0] = (stream[40] & 0x7f) >> 1;
1633 for (i = 1, j = 40; i < 46; i++) {
1634 unsigned int this_str = stream[j] << 7;
1638 hash_str[i] = (u8)(this_str | (stream[j] >> 1));
1642 * Now compute the hash. i is the index into hash_str, j is into our
1643 * key stream, k is counting the number of bits, and h interates within
1646 for (i = 45, j = 43, k = 0; k < 351 && i >= 2 && j >= 0; i--, j--) {
1647 for (h = 0; h < 8 && k < 351; h++, k++) {
1648 if (int_key[j] & (1 << h)) {
1650 * Key bit is set, XOR in the current 16-bit
1651 * string. Example of processing:
1653 * tmp = (hash_str[i - 2] & 0 << 16) |
1654 * (hash_str[i - 1] & 0xff << 8) |
1655 * (hash_str[i] & 0xff >> 0)
1656 * So tmp = hash_str[15 + k:k], since the
1657 * i + 2 clause rolls off the 16-bit value
1659 * tmp = (hash_str[i - 2] & 0x7f << 9) |
1660 * (hash_str[i - 1] & 0xff << 1) |
1661 * (hash_str[i] & 0x80 >> 7)
1663 int tmp = (hash_str[i] >> h);
1664 tmp |= (hash_str[i - 1] << (8 - h));
1665 tmp |= (int)(hash_str[i - 2] & ((1 << h) - 1))
1667 hash_result ^= (u16)tmp;
1676 * ixgbe_atr_set_vlan_id_82599 - Sets the VLAN id in the ATR input stream
1677 * @input: input stream to modify
1678 * @vlan: the VLAN id to load
1680 s32 ixgbe_atr_set_vlan_id_82599(struct ixgbe_atr_input *input, u16 vlan)
1682 input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] = vlan >> 8;
1683 input->byte_stream[IXGBE_ATR_VLAN_OFFSET] = vlan & 0xff;
1689 * ixgbe_atr_set_src_ipv4_82599 - Sets the source IPv4 address
1690 * @input: input stream to modify
1691 * @src_addr: the IP address to load
1693 s32 ixgbe_atr_set_src_ipv4_82599(struct ixgbe_atr_input *input, u32 src_addr)
1695 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] = src_addr >> 24;
1696 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] =
1697 (src_addr >> 16) & 0xff;
1698 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] =
1699 (src_addr >> 8) & 0xff;
1700 input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET] = src_addr & 0xff;
1706 * ixgbe_atr_set_dst_ipv4_82599 - Sets the destination IPv4 address
1707 * @input: input stream to modify
1708 * @dst_addr: the IP address to load
1710 s32 ixgbe_atr_set_dst_ipv4_82599(struct ixgbe_atr_input *input, u32 dst_addr)
1712 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] = dst_addr >> 24;
1713 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] =
1714 (dst_addr >> 16) & 0xff;
1715 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] =
1716 (dst_addr >> 8) & 0xff;
1717 input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET] = dst_addr & 0xff;
1723 * ixgbe_atr_set_src_ipv6_82599 - Sets the source IPv6 address
1724 * @input: input stream to modify
1725 * @src_addr_1: the first 4 bytes of the IP address to load
1726 * @src_addr_2: the second 4 bytes of the IP address to load
1727 * @src_addr_3: the third 4 bytes of the IP address to load
1728 * @src_addr_4: the fourth 4 bytes of the IP address to load
1730 s32 ixgbe_atr_set_src_ipv6_82599(struct ixgbe_atr_input *input,
1731 u32 src_addr_1, u32 src_addr_2,
1732 u32 src_addr_3, u32 src_addr_4)
1734 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET] = src_addr_4 & 0xff;
1735 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] =
1736 (src_addr_4 >> 8) & 0xff;
1737 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] =
1738 (src_addr_4 >> 16) & 0xff;
1739 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] = src_addr_4 >> 24;
1741 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4] = src_addr_3 & 0xff;
1742 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] =
1743 (src_addr_3 >> 8) & 0xff;
1744 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] =
1745 (src_addr_3 >> 16) & 0xff;
1746 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] = src_addr_3 >> 24;
1748 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8] = src_addr_2 & 0xff;
1749 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] =
1750 (src_addr_2 >> 8) & 0xff;
1751 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] =
1752 (src_addr_2 >> 16) & 0xff;
1753 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] = src_addr_2 >> 24;
1755 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12] = src_addr_1 & 0xff;
1756 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] =
1757 (src_addr_1 >> 8) & 0xff;
1758 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] =
1759 (src_addr_1 >> 16) & 0xff;
1760 input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] = src_addr_1 >> 24;
1766 * ixgbe_atr_set_dst_ipv6_82599 - Sets the destination IPv6 address
1767 * @input: input stream to modify
1768 * @dst_addr_1: the first 4 bytes of the IP address to load
1769 * @dst_addr_2: the second 4 bytes of the IP address to load
1770 * @dst_addr_3: the third 4 bytes of the IP address to load
1771 * @dst_addr_4: the fourth 4 bytes of the IP address to load
1773 s32 ixgbe_atr_set_dst_ipv6_82599(struct ixgbe_atr_input *input,
1774 u32 dst_addr_1, u32 dst_addr_2,
1775 u32 dst_addr_3, u32 dst_addr_4)
1777 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET] = dst_addr_4 & 0xff;
1778 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] =
1779 (dst_addr_4 >> 8) & 0xff;
1780 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] =
1781 (dst_addr_4 >> 16) & 0xff;
1782 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] = dst_addr_4 >> 24;
1784 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4] = dst_addr_3 & 0xff;
1785 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] =
1786 (dst_addr_3 >> 8) & 0xff;
1787 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] =
1788 (dst_addr_3 >> 16) & 0xff;
1789 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] = dst_addr_3 >> 24;
1791 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8] = dst_addr_2 & 0xff;
1792 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] =
1793 (dst_addr_2 >> 8) & 0xff;
1794 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] =
1795 (dst_addr_2 >> 16) & 0xff;
1796 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] = dst_addr_2 >> 24;
1798 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12] = dst_addr_1 & 0xff;
1799 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] =
1800 (dst_addr_1 >> 8) & 0xff;
1801 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] =
1802 (dst_addr_1 >> 16) & 0xff;
1803 input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] = dst_addr_1 >> 24;
1809 * ixgbe_atr_set_src_port_82599 - Sets the source port
1810 * @input: input stream to modify
1811 * @src_port: the source port to load
1813 s32 ixgbe_atr_set_src_port_82599(struct ixgbe_atr_input *input, u16 src_port)
1815 input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1] = src_port >> 8;
1816 input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] = src_port & 0xff;
1822 * ixgbe_atr_set_dst_port_82599 - Sets the destination port
1823 * @input: input stream to modify
1824 * @dst_port: the destination port to load
1826 s32 ixgbe_atr_set_dst_port_82599(struct ixgbe_atr_input *input, u16 dst_port)
1828 input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1] = dst_port >> 8;
1829 input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] = dst_port & 0xff;
1835 * ixgbe_atr_set_flex_byte_82599 - Sets the flexible bytes
1836 * @input: input stream to modify
1837 * @flex_bytes: the flexible bytes to load
1839 s32 ixgbe_atr_set_flex_byte_82599(struct ixgbe_atr_input *input, u16 flex_byte)
1841 input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] = flex_byte >> 8;
1842 input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET] = flex_byte & 0xff;
1848 * ixgbe_atr_set_vm_pool_82599 - Sets the Virtual Machine pool
1849 * @input: input stream to modify
1850 * @vm_pool: the Virtual Machine pool to load
1852 s32 ixgbe_atr_set_vm_pool_82599(struct ixgbe_atr_input *input,
1855 input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET] = vm_pool;
1861 * ixgbe_atr_set_l4type_82599 - Sets the layer 4 packet type
1862 * @input: input stream to modify
1863 * @l4type: the layer 4 type value to load
1865 s32 ixgbe_atr_set_l4type_82599(struct ixgbe_atr_input *input, u8 l4type)
1867 input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET] = l4type;
1873 * ixgbe_atr_get_vlan_id_82599 - Gets the VLAN id from the ATR input stream
1874 * @input: input stream to search
1875 * @vlan: the VLAN id to load
1877 static s32 ixgbe_atr_get_vlan_id_82599(struct ixgbe_atr_input *input, u16 *vlan)
1879 *vlan = input->byte_stream[IXGBE_ATR_VLAN_OFFSET];
1880 *vlan |= input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] << 8;
1886 * ixgbe_atr_get_src_ipv4_82599 - Gets the source IPv4 address
1887 * @input: input stream to search
1888 * @src_addr: the IP address to load
1890 static s32 ixgbe_atr_get_src_ipv4_82599(struct ixgbe_atr_input *input,
1893 *src_addr = input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET];
1894 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] << 8;
1895 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] << 16;
1896 *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] << 24;
1902 * ixgbe_atr_get_dst_ipv4_82599 - Gets the destination IPv4 address
1903 * @input: input stream to search
1904 * @dst_addr: the IP address to load
1906 static s32 ixgbe_atr_get_dst_ipv4_82599(struct ixgbe_atr_input *input,
1909 *dst_addr = input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET];
1910 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] << 8;
1911 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] << 16;
1912 *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] << 24;
1918 * ixgbe_atr_get_src_ipv6_82599 - Gets the source IPv6 address
1919 * @input: input stream to search
1920 * @src_addr_1: the first 4 bytes of the IP address to load
1921 * @src_addr_2: the second 4 bytes of the IP address to load
1922 * @src_addr_3: the third 4 bytes of the IP address to load
1923 * @src_addr_4: the fourth 4 bytes of the IP address to load
1925 static s32 ixgbe_atr_get_src_ipv6_82599(struct ixgbe_atr_input *input,
1926 u32 *src_addr_1, u32 *src_addr_2,
1927 u32 *src_addr_3, u32 *src_addr_4)
1929 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12];
1930 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] << 8;
1931 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] << 16;
1932 *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] << 24;
1934 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8];
1935 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] << 8;
1936 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] << 16;
1937 *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] << 24;
1939 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4];
1940 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] << 8;
1941 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] << 16;
1942 *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] << 24;
1944 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET];
1945 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] << 8;
1946 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] << 16;
1947 *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] << 24;
1953 * ixgbe_atr_get_dst_ipv6_82599 - Gets the destination IPv6 address
1954 * @input: input stream to search
1955 * @dst_addr_1: the first 4 bytes of the IP address to load
1956 * @dst_addr_2: the second 4 bytes of the IP address to load
1957 * @dst_addr_3: the third 4 bytes of the IP address to load
1958 * @dst_addr_4: the fourth 4 bytes of the IP address to load
1960 s32 ixgbe_atr_get_dst_ipv6_82599(struct ixgbe_atr_input *input,
1961 u32 *dst_addr_1, u32 *dst_addr_2,
1962 u32 *dst_addr_3, u32 *dst_addr_4)
1964 *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12];
1965 *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] << 8;
1966 *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] << 16;
1967 *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] << 24;
1969 *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8];
1970 *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] << 8;
1971 *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] << 16;
1972 *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] << 24;
1974 *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4];
1975 *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] << 8;
1976 *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] << 16;
1977 *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] << 24;
1979 *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET];
1980 *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] << 8;
1981 *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] << 16;
1982 *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] << 24;
1988 * ixgbe_atr_get_src_port_82599 - Gets the source port
1989 * @input: input stream to modify
1990 * @src_port: the source port to load
1992 * Even though the input is given in big-endian, the FDIRPORT registers
1993 * expect the ports to be programmed in little-endian. Hence the need to swap
1994 * endianness when retrieving the data. This can be confusing since the
1995 * internal hash engine expects it to be big-endian.
1997 static s32 ixgbe_atr_get_src_port_82599(struct ixgbe_atr_input *input,
2000 *src_port = input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] << 8;
2001 *src_port |= input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1];
2007 * ixgbe_atr_get_dst_port_82599 - Gets the destination port
2008 * @input: input stream to modify
2009 * @dst_port: the destination port to load
2011 * Even though the input is given in big-endian, the FDIRPORT registers
2012 * expect the ports to be programmed in little-endian. Hence the need to swap
2013 * endianness when retrieving the data. This can be confusing since the
2014 * internal hash engine expects it to be big-endian.
2016 static s32 ixgbe_atr_get_dst_port_82599(struct ixgbe_atr_input *input,
2019 *dst_port = input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] << 8;
2020 *dst_port |= input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1];
2026 * ixgbe_atr_get_flex_byte_82599 - Gets the flexible bytes
2027 * @input: input stream to modify
2028 * @flex_bytes: the flexible bytes to load
2030 static s32 ixgbe_atr_get_flex_byte_82599(struct ixgbe_atr_input *input,
2033 *flex_byte = input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET];
2034 *flex_byte |= input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] << 8;
2040 * ixgbe_atr_get_vm_pool_82599 - Gets the Virtual Machine pool
2041 * @input: input stream to modify
2042 * @vm_pool: the Virtual Machine pool to load
2044 s32 ixgbe_atr_get_vm_pool_82599(struct ixgbe_atr_input *input,
2047 *vm_pool = input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET];
2053 * ixgbe_atr_get_l4type_82599 - Gets the layer 4 packet type
2054 * @input: input stream to modify
2055 * @l4type: the layer 4 type value to load
2057 static s32 ixgbe_atr_get_l4type_82599(struct ixgbe_atr_input *input,
2060 *l4type = input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET];
2066 * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
2067 * @hw: pointer to hardware structure
2068 * @stream: input bitstream
2069 * @queue: queue index to direct traffic to
2071 s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
2072 struct ixgbe_atr_input *input,
2078 u16 bucket_hash, sig_hash;
2081 bucket_hash = ixgbe_atr_compute_hash_82599(input,
2082 IXGBE_ATR_BUCKET_HASH_KEY);
2084 /* bucket_hash is only 15 bits */
2085 bucket_hash &= IXGBE_ATR_HASH_MASK;
2087 sig_hash = ixgbe_atr_compute_hash_82599(input,
2088 IXGBE_ATR_SIGNATURE_HASH_KEY);
2090 /* Get the l4type in order to program FDIRCMD properly */
2091 /* lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 */
2092 ixgbe_atr_get_l4type_82599(input, &l4type);
2095 * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
2096 * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
2098 fdirhash = sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
2100 fdircmd = (IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
2101 IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN);
2103 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
2104 case IXGBE_ATR_L4TYPE_TCP:
2105 fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
2107 case IXGBE_ATR_L4TYPE_UDP:
2108 fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
2110 case IXGBE_ATR_L4TYPE_SCTP:
2111 fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
2114 hw_dbg(hw, "Error on l4type input\n");
2115 return IXGBE_ERR_CONFIG;
2118 if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK)
2119 fdircmd |= IXGBE_FDIRCMD_IPV6;
2121 fdircmd |= ((u64)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT);
2122 fdirhashcmd = ((fdircmd << 32) | fdirhash);
2124 IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
2130 * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
2131 * @hw: pointer to hardware structure
2132 * @input: input bitstream
2133 * @input_masks: bitwise masks for relevant fields
2134 * @soft_id: software index into the silicon hash tables for filter storage
2135 * @queue: queue index to direct traffic to
2137 * Note that the caller to this function must lock before calling, since the
2138 * hardware writes must be protected from one another.
2140 s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
2141 struct ixgbe_atr_input *input,
2142 struct ixgbe_atr_input_masks *input_masks,
2143 u16 soft_id, u8 queue)
2147 u32 src_ipv4 = 0, dst_ipv4 = 0;
2148 u32 src_ipv6_1, src_ipv6_2, src_ipv6_3, src_ipv6_4;
2149 u16 src_port, dst_port, vlan_id, flex_bytes;
2154 /* Get our input values */
2155 ixgbe_atr_get_l4type_82599(input, &l4type);
2158 * Check l4type formatting, and bail out before we touch the hardware
2159 * if there's a configuration issue
2161 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
2162 case IXGBE_ATR_L4TYPE_TCP:
2163 fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
2165 case IXGBE_ATR_L4TYPE_UDP:
2166 fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
2168 case IXGBE_ATR_L4TYPE_SCTP:
2169 fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
2172 hw_dbg(hw, "Error on l4type input\n");
2173 return IXGBE_ERR_CONFIG;
2176 bucket_hash = ixgbe_atr_compute_hash_82599(input,
2177 IXGBE_ATR_BUCKET_HASH_KEY);
2179 /* bucket_hash is only 15 bits */
2180 bucket_hash &= IXGBE_ATR_HASH_MASK;
2182 ixgbe_atr_get_vlan_id_82599(input, &vlan_id);
2183 ixgbe_atr_get_src_port_82599(input, &src_port);
2184 ixgbe_atr_get_dst_port_82599(input, &dst_port);
2185 ixgbe_atr_get_flex_byte_82599(input, &flex_bytes);
2187 fdirhash = soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
2189 /* Now figure out if we're IPv4 or IPv6 */
2190 if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK) {
2192 ixgbe_atr_get_src_ipv6_82599(input, &src_ipv6_1, &src_ipv6_2,
2193 &src_ipv6_3, &src_ipv6_4);
2195 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), src_ipv6_1);
2196 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), src_ipv6_2);
2197 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), src_ipv6_3);
2198 /* The last 4 bytes is the same register as IPv4 */
2199 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv6_4);
2201 fdircmd |= IXGBE_FDIRCMD_IPV6;
2202 fdircmd |= IXGBE_FDIRCMD_IPv6DMATCH;
2205 ixgbe_atr_get_src_ipv4_82599(input, &src_ipv4);
2206 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv4);
2209 ixgbe_atr_get_dst_ipv4_82599(input, &dst_ipv4);
2210 IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, dst_ipv4);
2212 IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, (vlan_id |
2213 (flex_bytes << IXGBE_FDIRVLAN_FLEX_SHIFT)));
2214 IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, (src_port |
2215 (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
2218 * Program the relevant mask registers. If src/dst_port or src/dst_addr
2219 * are zero, then assume a full mask for that field. Also assume that
2220 * a VLAN of 0 is unspecified, so mask that out as well. L4type
2221 * cannot be masked out in this implementation.
2223 * This also assumes IPv4 only. IPv6 masking isn't supported at this
2227 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, 0xffffffff);
2229 IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, input_masks->src_ip_mask);
2232 IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, 0xffffffff);
2234 IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, input_masks->dst_ip_mask);
2236 switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
2237 case IXGBE_ATR_L4TYPE_TCP:
2239 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xffff);
2241 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
2242 input_masks->src_port_mask);
2245 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
2246 (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
2249 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
2250 (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
2251 (input_masks->dst_port_mask << 16)));
2253 case IXGBE_ATR_L4TYPE_UDP:
2255 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xffff);
2257 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
2258 input_masks->src_port_mask);
2261 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
2262 (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
2265 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
2266 (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
2267 (input_masks->src_port_mask << 16)));
2270 /* this already would have failed above */
2274 /* Program the last mask register, FDIRM */
2275 if (input_masks->vlan_id_mask || !vlan_id)
2276 /* Mask both VLAN and VLANP - bits 0 and 1 */
2279 if (input_masks->data_mask || !flex_bytes)
2280 /* Flex bytes need masking, so mask the whole thing - bit 4 */
2283 /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
2286 IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
2288 fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW;
2289 fdircmd |= IXGBE_FDIRCMD_FILTER_UPDATE;
2290 fdircmd |= IXGBE_FDIRCMD_LAST;
2291 fdircmd |= IXGBE_FDIRCMD_QUEUE_EN;
2292 fdircmd |= queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
2294 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
2295 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
2300 * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
2301 * @hw: pointer to hardware structure
2302 * @reg: analog register to read
2305 * Performs read operation to Omer analog register specified.
2307 static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
2311 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
2313 IXGBE_WRITE_FLUSH(hw);
2315 core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
2316 *val = (u8)core_ctl;
2322 * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
2323 * @hw: pointer to hardware structure
2324 * @reg: atlas register to write
2325 * @val: value to write
2327 * Performs write operation to Omer analog register specified.
2329 static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
2333 core_ctl = (reg << 8) | val;
2334 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
2335 IXGBE_WRITE_FLUSH(hw);
2342 * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
2343 * @hw: pointer to hardware structure
2345 * Starts the hardware using the generic start_hw function.
2346 * Then performs device-specific:
2347 * Clears the rate limiter registers.
2349 static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
2354 ret_val = ixgbe_start_hw_generic(hw);
2356 /* Clear the rate limiters */
2357 for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
2358 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
2359 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
2361 IXGBE_WRITE_FLUSH(hw);
2363 /* We need to run link autotry after the driver loads */
2364 hw->mac.autotry_restart = true;
2367 ret_val = ixgbe_verify_fw_version_82599(hw);
2373 * ixgbe_identify_phy_82599 - Get physical layer module
2374 * @hw: pointer to hardware structure
2376 * Determines the physical layer module found on the current adapter.
2378 static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
2380 s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
2381 status = ixgbe_identify_phy_generic(hw);
2383 status = ixgbe_identify_sfp_module_generic(hw);
2388 * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
2389 * @hw: pointer to hardware structure
2391 * Determines physical layer capabilities of the current configuration.
2393 static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
2395 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
2396 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2397 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
2398 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
2399 u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
2400 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
2401 u16 ext_ability = 0;
2402 u8 comp_codes_10g = 0;
2404 hw->phy.ops.identify(hw);
2406 if (hw->phy.type == ixgbe_phy_tn ||
2407 hw->phy.type == ixgbe_phy_cu_unknown) {
2408 hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
2410 if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
2411 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
2412 if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
2413 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
2414 if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
2415 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
2419 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
2420 case IXGBE_AUTOC_LMS_1G_AN:
2421 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
2422 if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
2423 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
2424 IXGBE_PHYSICAL_LAYER_1000BASE_BX;
2427 /* SFI mode so read SFP module */
2430 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
2431 if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
2432 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
2433 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
2434 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2435 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
2436 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
2439 case IXGBE_AUTOC_LMS_10G_SERIAL:
2440 if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
2441 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
2443 } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
2446 case IXGBE_AUTOC_LMS_KX4_KX_KR:
2447 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
2448 if (autoc & IXGBE_AUTOC_KX_SUPP)
2449 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
2450 if (autoc & IXGBE_AUTOC_KX4_SUPP)
2451 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2452 if (autoc & IXGBE_AUTOC_KR_SUPP)
2453 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
2462 /* SFP check must be done last since DA modules are sometimes used to
2463 * test KR mode - we need to id KR mode correctly before SFP module.
2464 * Call identify_sfp because the pluggable module may have changed */
2465 hw->phy.ops.identify_sfp(hw);
2466 if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
2469 switch (hw->phy.type) {
2470 case ixgbe_phy_tw_tyco:
2471 case ixgbe_phy_tw_unknown:
2472 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
2474 case ixgbe_phy_sfp_avago:
2475 case ixgbe_phy_sfp_ftl:
2476 case ixgbe_phy_sfp_intel:
2477 case ixgbe_phy_sfp_unknown:
2478 hw->phy.ops.read_i2c_eeprom(hw,
2479 IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
2480 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
2481 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
2482 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
2483 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
2490 return physical_layer;
2494 * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
2495 * @hw: pointer to hardware structure
2496 * @regval: register value to write to RXCTRL
2498 * Enables the Rx DMA unit for 82599
2500 static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
2502 #define IXGBE_MAX_SECRX_POLL 30
2507 * Workaround for 82599 silicon errata when enabling the Rx datapath.
2508 * If traffic is incoming before we enable the Rx unit, it could hang
2509 * the Rx DMA unit. Therefore, make sure the security engine is
2510 * completely disabled prior to enabling the Rx unit.
2512 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2513 secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
2514 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2515 for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
2516 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
2517 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
2523 /* For informational purposes only */
2524 if (i >= IXGBE_MAX_SECRX_POLL)
2525 hw_dbg(hw, "Rx unit being enabled before security "
2526 "path fully disabled. Continuing with init.\n");
2528 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2529 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2530 secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
2531 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2532 IXGBE_WRITE_FLUSH(hw);
2538 * ixgbe_get_device_caps_82599 - Get additional device capabilities
2539 * @hw: pointer to hardware structure
2540 * @device_caps: the EEPROM word with the extra device capabilities
2542 * This function will read the EEPROM location for the device capabilities,
2543 * and return the word through device_caps.
2545 static s32 ixgbe_get_device_caps_82599(struct ixgbe_hw *hw, u16 *device_caps)
2547 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
2553 * ixgbe_get_san_mac_addr_offset_82599 - SAN MAC address offset for 82599
2554 * @hw: pointer to hardware structure
2555 * @san_mac_offset: SAN MAC address offset
2557 * This function will read the EEPROM location for the SAN MAC address
2558 * pointer, and returns the value at that location. This is used in both
2559 * get and set mac_addr routines.
2561 static s32 ixgbe_get_san_mac_addr_offset_82599(struct ixgbe_hw *hw,
2562 u16 *san_mac_offset)
2565 * First read the EEPROM pointer to see if the MAC addresses are
2568 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2574 * ixgbe_get_san_mac_addr_82599 - SAN MAC address retrieval for 82599
2575 * @hw: pointer to hardware structure
2576 * @san_mac_addr: SAN MAC address
2578 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2579 * per-port, so set_lan_id() must be called before reading the addresses.
2580 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2581 * upon for non-SFP connections, so we must call it here.
2583 static s32 ixgbe_get_san_mac_addr_82599(struct ixgbe_hw *hw, u8 *san_mac_addr)
2585 u16 san_mac_data, san_mac_offset;
2589 * First read the EEPROM pointer to see if the MAC addresses are
2590 * available. If they're not, no point in calling set_lan_id() here.
2592 ixgbe_get_san_mac_addr_offset_82599(hw, &san_mac_offset);
2594 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2596 * No addresses available in this EEPROM. It's not an
2597 * error though, so just wipe the local address and return.
2599 for (i = 0; i < 6; i++)
2600 san_mac_addr[i] = 0xFF;
2602 goto san_mac_addr_out;
2605 /* make sure we know which port we need to program */
2606 hw->mac.ops.set_lan_id(hw);
2607 /* apply the port offset to the address offset */
2608 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2609 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2610 for (i = 0; i < 3; i++) {
2611 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2612 san_mac_addr[i * 2] = (u8)(san_mac_data);
2613 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2622 * ixgbe_verify_fw_version_82599 - verify fw version for 82599
2623 * @hw: pointer to hardware structure
2625 * Verifies that installed the firmware version is 0.6 or higher
2626 * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
2628 * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
2629 * if the FW version is not supported.
2631 static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
2633 s32 status = IXGBE_ERR_EEPROM_VERSION;
2634 u16 fw_offset, fw_ptp_cfg_offset;
2637 /* firmware check is only necessary for SFI devices */
2638 if (hw->phy.media_type != ixgbe_media_type_fiber) {
2640 goto fw_version_out;
2643 /* get the offset to the Firmware Module block */
2644 hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
2646 if ((fw_offset == 0) || (fw_offset == 0xFFFF))
2647 goto fw_version_out;
2649 /* get the offset to the Pass Through Patch Configuration block */
2650 hw->eeprom.ops.read(hw, (fw_offset +
2651 IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
2652 &fw_ptp_cfg_offset);
2654 if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
2655 goto fw_version_out;
2657 /* get the firmware version */
2658 hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
2659 IXGBE_FW_PATCH_VERSION_4),
2662 if (fw_version > 0x5)
2670 * ixgbe_get_wwn_prefix_82599 - Get alternative WWNN/WWPN prefix from
2672 * @hw: pointer to hardware structure
2673 * @wwnn_prefix: the alternative WWNN prefix
2674 * @wwpn_prefix: the alternative WWPN prefix
2676 * This function will read the EEPROM from the alternative SAN MAC address
2677 * block to check the support for the alternative WWNN/WWPN prefix support.
2679 static s32 ixgbe_get_wwn_prefix_82599(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2683 u16 alt_san_mac_blk_offset;
2685 /* clear output first */
2686 *wwnn_prefix = 0xFFFF;
2687 *wwpn_prefix = 0xFFFF;
2689 /* check if alternative SAN MAC is supported */
2690 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2691 &alt_san_mac_blk_offset);
2693 if ((alt_san_mac_blk_offset == 0) ||
2694 (alt_san_mac_blk_offset == 0xFFFF))
2695 goto wwn_prefix_out;
2697 /* check capability in alternative san mac address block */
2698 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2699 hw->eeprom.ops.read(hw, offset, &caps);
2700 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2701 goto wwn_prefix_out;
2703 /* get the corresponding prefix for WWNN/WWPN */
2704 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2705 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2707 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2708 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2714 static struct ixgbe_mac_operations mac_ops_82599 = {
2715 .init_hw = &ixgbe_init_hw_generic,
2716 .reset_hw = &ixgbe_reset_hw_82599,
2717 .start_hw = &ixgbe_start_hw_82599,
2718 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
2719 .get_media_type = &ixgbe_get_media_type_82599,
2720 .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
2721 .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
2722 .get_mac_addr = &ixgbe_get_mac_addr_generic,
2723 .get_san_mac_addr = &ixgbe_get_san_mac_addr_82599,
2724 .get_device_caps = &ixgbe_get_device_caps_82599,
2725 .get_wwn_prefix = &ixgbe_get_wwn_prefix_82599,
2726 .stop_adapter = &ixgbe_stop_adapter_generic,
2727 .get_bus_info = &ixgbe_get_bus_info_generic,
2728 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
2729 .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
2730 .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
2731 .setup_link = &ixgbe_setup_mac_link_82599,
2732 .check_link = &ixgbe_check_mac_link_82599,
2733 .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
2734 .led_on = &ixgbe_led_on_generic,
2735 .led_off = &ixgbe_led_off_generic,
2736 .blink_led_start = &ixgbe_blink_led_start_generic,
2737 .blink_led_stop = &ixgbe_blink_led_stop_generic,
2738 .set_rar = &ixgbe_set_rar_generic,
2739 .clear_rar = &ixgbe_clear_rar_generic,
2740 .set_vmdq = &ixgbe_set_vmdq_82599,
2741 .clear_vmdq = &ixgbe_clear_vmdq_82599,
2742 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
2743 .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
2744 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
2745 .enable_mc = &ixgbe_enable_mc_generic,
2746 .disable_mc = &ixgbe_disable_mc_generic,
2747 .clear_vfta = &ixgbe_clear_vfta_82599,
2748 .set_vfta = &ixgbe_set_vfta_82599,
2749 .fc_enable = &ixgbe_fc_enable_generic,
2750 .init_uta_tables = &ixgbe_init_uta_tables_82599,
2751 .setup_sfp = &ixgbe_setup_sfp_modules_82599,
2754 static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
2755 .init_params = &ixgbe_init_eeprom_params_generic,
2756 .read = &ixgbe_read_eeprom_generic,
2757 .write = &ixgbe_write_eeprom_generic,
2758 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
2759 .update_checksum = &ixgbe_update_eeprom_checksum_generic,
2762 static struct ixgbe_phy_operations phy_ops_82599 = {
2763 .identify = &ixgbe_identify_phy_82599,
2764 .identify_sfp = &ixgbe_identify_sfp_module_generic,
2765 .init = &ixgbe_init_phy_ops_82599,
2766 .reset = &ixgbe_reset_phy_generic,
2767 .read_reg = &ixgbe_read_phy_reg_generic,
2768 .write_reg = &ixgbe_write_phy_reg_generic,
2769 .setup_link = &ixgbe_setup_phy_link_generic,
2770 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
2771 .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
2772 .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
2773 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
2774 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
2777 struct ixgbe_info ixgbe_82599_info = {
2778 .mac = ixgbe_mac_82599EB,
2779 .get_invariants = &ixgbe_get_invariants_82599,
2780 .mac_ops = &mac_ops_82599,
2781 .eeprom_ops = &eeprom_ops_82599,
2782 .phy_ops = &phy_ops_82599,
2783 .mbx_ops = &mbx_ops_82599,