PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 Intel Corporation. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/sched.h> |
| 31 | |
| 32 | #include "ixgbe.h" |
| 33 | #include "ixgbe_phy.h" |
Greg Rose | 096a58f | 2010-01-09 02:26:26 +0000 | [diff] [blame] | 34 | #include "ixgbe_mbx.h" |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 35 | |
| 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 |
| 41 | |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 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, |
| 47 | bool autoneg, |
| 48 | bool autoneg_wait_to_complete); |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 49 | static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw, |
| 50 | ixgbe_link_speed speed, |
| 51 | bool autoneg, |
| 52 | bool autoneg_wait_to_complete); |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 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, |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 56 | ixgbe_link_speed speed, |
| 57 | bool autoneg, |
| 58 | bool autoneg_wait_to_complete); |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 59 | static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw, |
| 60 | ixgbe_link_speed speed, |
| 61 | bool autoneg, |
| 62 | bool autoneg_wait_to_complete); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 63 | static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw); |
Emil Tantilov | 0fa6d83 | 2011-03-18 08:18:32 +0000 | [diff] [blame^] | 64 | static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 65 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 66 | static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 67 | { |
| 68 | struct ixgbe_mac_info *mac = &hw->mac; |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 69 | |
| 70 | /* enable the laser control functions for SFP+ fiber */ |
| 71 | if (mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) { |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 72 | mac->ops.disable_tx_laser = |
| 73 | &ixgbe_disable_tx_laser_multispeed_fiber; |
| 74 | mac->ops.enable_tx_laser = |
| 75 | &ixgbe_enable_tx_laser_multispeed_fiber; |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 76 | mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 77 | } else { |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 78 | mac->ops.disable_tx_laser = NULL; |
| 79 | mac->ops.enable_tx_laser = NULL; |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 80 | mac->ops.flap_tx_laser = NULL; |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if (hw->phy.multispeed_fiber) { |
| 84 | /* Set up dual speed SFP+ support */ |
| 85 | mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber; |
| 86 | } else { |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 87 | if ((mac->ops.get_media_type(hw) == |
| 88 | ixgbe_media_type_backplane) && |
| 89 | (hw->phy.smart_speed == ixgbe_smart_speed_auto || |
Emil Tantilov | 0fa6d83 | 2011-03-18 08:18:32 +0000 | [diff] [blame^] | 90 | hw->phy.smart_speed == ixgbe_smart_speed_on) && |
| 91 | !ixgbe_verify_lesm_fw_enabled_82599(hw)) |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 92 | mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed; |
| 93 | else |
| 94 | mac->ops.setup_link = &ixgbe_setup_mac_link_82599; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 98 | static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 99 | { |
| 100 | s32 ret_val = 0; |
Don Skidmore | a7f5a5f | 2010-12-03 13:23:30 +0000 | [diff] [blame] | 101 | u32 reg_anlp1 = 0; |
| 102 | u32 i = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 103 | u16 list_offset, data_offset, data_value; |
| 104 | |
| 105 | if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) { |
| 106 | ixgbe_init_mac_link_ops_82599(hw); |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 107 | |
| 108 | hw->phy.ops.reset = NULL; |
| 109 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 110 | ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset, |
| 111 | &data_offset); |
| 112 | |
| 113 | if (ret_val != 0) |
| 114 | goto setup_sfp_out; |
| 115 | |
Peter P Waskiewicz Jr | aa5aec8 | 2009-05-19 09:18:34 +0000 | [diff] [blame] | 116 | /* PHY config will finish before releasing the semaphore */ |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 117 | ret_val = hw->mac.ops.acquire_swfw_sync(hw, |
| 118 | IXGBE_GSSR_MAC_CSR_SM); |
Peter P Waskiewicz Jr | aa5aec8 | 2009-05-19 09:18:34 +0000 | [diff] [blame] | 119 | if (ret_val != 0) { |
| 120 | ret_val = IXGBE_ERR_SWFW_SYNC; |
| 121 | goto setup_sfp_out; |
| 122 | } |
| 123 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 124 | hw->eeprom.ops.read(hw, ++data_offset, &data_value); |
| 125 | while (data_value != 0xffff) { |
| 126 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value); |
| 127 | IXGBE_WRITE_FLUSH(hw); |
| 128 | hw->eeprom.ops.read(hw, ++data_offset, &data_value); |
| 129 | } |
Peter P Waskiewicz Jr | aa5aec8 | 2009-05-19 09:18:34 +0000 | [diff] [blame] | 130 | |
| 131 | /* Release the semaphore */ |
| 132 | ixgbe_release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM); |
| 133 | /* Delay obtaining semaphore again to allow FW access */ |
| 134 | msleep(hw->eeprom.semaphore_delay); |
Don Skidmore | a7f5a5f | 2010-12-03 13:23:30 +0000 | [diff] [blame] | 135 | |
| 136 | /* Now restart DSP by setting Restart_AN and clearing LMS */ |
| 137 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, ((IXGBE_READ_REG(hw, |
| 138 | IXGBE_AUTOC) & ~IXGBE_AUTOC_LMS_MASK) | |
| 139 | IXGBE_AUTOC_AN_RESTART)); |
| 140 | |
| 141 | /* Wait for AN to leave state 0 */ |
| 142 | for (i = 0; i < 10; i++) { |
| 143 | msleep(4); |
| 144 | reg_anlp1 = IXGBE_READ_REG(hw, IXGBE_ANLP1); |
| 145 | if (reg_anlp1 & IXGBE_ANLP1_AN_STATE_MASK) |
| 146 | break; |
| 147 | } |
| 148 | if (!(reg_anlp1 & IXGBE_ANLP1_AN_STATE_MASK)) { |
| 149 | hw_dbg(hw, "sfp module setup not complete\n"); |
| 150 | ret_val = IXGBE_ERR_SFP_SETUP_NOT_COMPLETE; |
| 151 | goto setup_sfp_out; |
| 152 | } |
| 153 | |
| 154 | /* Restart DSP by setting Restart_AN and return to SFI mode */ |
| 155 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (IXGBE_READ_REG(hw, |
| 156 | IXGBE_AUTOC) | IXGBE_AUTOC_LMS_10G_SERIAL | |
| 157 | IXGBE_AUTOC_AN_RESTART)); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | setup_sfp_out: |
| 161 | return ret_val; |
| 162 | } |
| 163 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 164 | static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw) |
| 165 | { |
| 166 | struct ixgbe_mac_info *mac = &hw->mac; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 167 | |
| 168 | ixgbe_init_mac_link_ops_82599(hw); |
| 169 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 170 | mac->mcft_size = IXGBE_82599_MC_TBL_SIZE; |
| 171 | mac->vft_size = IXGBE_82599_VFT_TBL_SIZE; |
| 172 | mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES; |
| 173 | mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES; |
| 174 | mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 175 | mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 176 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * ixgbe_init_phy_ops_82599 - PHY/SFP specific init |
| 182 | * @hw: pointer to hardware structure |
| 183 | * |
| 184 | * Initialize any function pointers that were not able to be |
| 185 | * set during get_invariants because the PHY/SFP type was |
| 186 | * not known. Perform the SFP init if necessary. |
| 187 | * |
| 188 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 189 | static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 190 | { |
| 191 | struct ixgbe_mac_info *mac = &hw->mac; |
| 192 | struct ixgbe_phy_info *phy = &hw->phy; |
| 193 | s32 ret_val = 0; |
| 194 | |
| 195 | /* Identify the PHY or SFP module */ |
| 196 | ret_val = phy->ops.identify(hw); |
| 197 | |
| 198 | /* Setup function pointers based on detected SFP module and speeds */ |
| 199 | ixgbe_init_mac_link_ops_82599(hw); |
| 200 | |
| 201 | /* If copper media, overwrite with copper function pointers */ |
| 202 | if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) { |
| 203 | mac->ops.setup_link = &ixgbe_setup_copper_link_82599; |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 204 | mac->ops.get_link_capabilities = |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 205 | &ixgbe_get_copper_link_capabilities_generic; |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* Set necessary function pointers based on phy type */ |
| 209 | switch (hw->phy.type) { |
| 210 | case ixgbe_phy_tn: |
| 211 | phy->ops.check_link = &ixgbe_check_phy_link_tnx; |
| 212 | phy->ops.get_firmware_version = |
| 213 | &ixgbe_get_phy_firmware_version_tnx; |
| 214 | break; |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 215 | case ixgbe_phy_aq: |
| 216 | phy->ops.get_firmware_version = |
| 217 | &ixgbe_get_phy_firmware_version_generic; |
| 218 | break; |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 219 | default: |
| 220 | break; |
| 221 | } |
| 222 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 223 | return ret_val; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * ixgbe_get_link_capabilities_82599 - Determines link capabilities |
| 228 | * @hw: pointer to hardware structure |
| 229 | * @speed: pointer to link speed |
| 230 | * @negotiation: true when autoneg or autotry is enabled |
| 231 | * |
| 232 | * Determines the link capabilities by reading the AUTOC register. |
| 233 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 234 | static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw, |
| 235 | ixgbe_link_speed *speed, |
| 236 | bool *negotiation) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 237 | { |
| 238 | s32 status = 0; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 239 | u32 autoc = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 240 | |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 241 | /* Determine 1G link capabilities off of SFP+ type */ |
| 242 | if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 || |
| 243 | hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) { |
| 244 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 245 | *negotiation = true; |
| 246 | goto out; |
| 247 | } |
| 248 | |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 249 | /* |
| 250 | * Determine link capabilities based on the stored value of AUTOC, |
| 251 | * which represents EEPROM defaults. If AUTOC value has not been |
| 252 | * stored, use the current register value. |
| 253 | */ |
| 254 | if (hw->mac.orig_link_settings_stored) |
| 255 | autoc = hw->mac.orig_autoc; |
| 256 | else |
| 257 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 258 | |
| 259 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 260 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: |
| 261 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 262 | *negotiation = false; |
| 263 | break; |
| 264 | |
| 265 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: |
| 266 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 267 | *negotiation = false; |
| 268 | break; |
| 269 | |
| 270 | case IXGBE_AUTOC_LMS_1G_AN: |
| 271 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 272 | *negotiation = true; |
| 273 | break; |
| 274 | |
| 275 | case IXGBE_AUTOC_LMS_10G_SERIAL: |
| 276 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 277 | *negotiation = false; |
| 278 | break; |
| 279 | |
| 280 | case IXGBE_AUTOC_LMS_KX4_KX_KR: |
| 281 | case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN: |
| 282 | *speed = IXGBE_LINK_SPEED_UNKNOWN; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 283 | if (autoc & IXGBE_AUTOC_KR_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 284 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 285 | if (autoc & IXGBE_AUTOC_KX4_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 286 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 287 | if (autoc & IXGBE_AUTOC_KX_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 288 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; |
| 289 | *negotiation = true; |
| 290 | break; |
| 291 | |
| 292 | case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII: |
| 293 | *speed = IXGBE_LINK_SPEED_100_FULL; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 294 | if (autoc & IXGBE_AUTOC_KR_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 295 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 296 | if (autoc & IXGBE_AUTOC_KX4_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 297 | *speed |= IXGBE_LINK_SPEED_10GB_FULL; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 298 | if (autoc & IXGBE_AUTOC_KX_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 299 | *speed |= IXGBE_LINK_SPEED_1GB_FULL; |
| 300 | *negotiation = true; |
| 301 | break; |
| 302 | |
| 303 | case IXGBE_AUTOC_LMS_SGMII_1G_100M: |
| 304 | *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL; |
| 305 | *negotiation = false; |
| 306 | break; |
| 307 | |
| 308 | default: |
| 309 | status = IXGBE_ERR_LINK_SETUP; |
| 310 | goto out; |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | if (hw->phy.multispeed_fiber) { |
| 315 | *speed |= IXGBE_LINK_SPEED_10GB_FULL | |
| 316 | IXGBE_LINK_SPEED_1GB_FULL; |
| 317 | *negotiation = true; |
| 318 | } |
| 319 | |
| 320 | out: |
| 321 | return status; |
| 322 | } |
| 323 | |
| 324 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 325 | * ixgbe_get_media_type_82599 - Get media type |
| 326 | * @hw: pointer to hardware structure |
| 327 | * |
| 328 | * Returns the media type (fiber, copper, backplane) |
| 329 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 330 | static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 331 | { |
| 332 | enum ixgbe_media_type media_type; |
| 333 | |
| 334 | /* Detect if there is a copper PHY attached. */ |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 335 | switch (hw->phy.type) { |
| 336 | case ixgbe_phy_cu_unknown: |
| 337 | case ixgbe_phy_tn: |
| 338 | case ixgbe_phy_aq: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 339 | media_type = ixgbe_media_type_copper; |
| 340 | goto out; |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 341 | default: |
| 342 | break; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | switch (hw->device_id) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 346 | case IXGBE_DEV_ID_82599_KX4: |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 347 | case IXGBE_DEV_ID_82599_KX4_MEZZ: |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 348 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 349 | case IXGBE_DEV_ID_82599_KR: |
Don Skidmore | dbffcb2 | 2010-12-03 03:32:34 +0000 | [diff] [blame] | 350 | case IXGBE_DEV_ID_82599_BACKPLANE_FCOE: |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 351 | case IXGBE_DEV_ID_82599_XAUI_LOM: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 352 | /* Default device ID is mezzanine card KX/KX4 */ |
| 353 | media_type = ixgbe_media_type_backplane; |
| 354 | break; |
| 355 | case IXGBE_DEV_ID_82599_SFP: |
Don Skidmore | dbffcb2 | 2010-12-03 03:32:34 +0000 | [diff] [blame] | 356 | case IXGBE_DEV_ID_82599_SFP_FCOE: |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 357 | case IXGBE_DEV_ID_82599_SFP_EM: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 358 | media_type = ixgbe_media_type_fiber; |
| 359 | break; |
Peter P Waskiewicz Jr | 8911184f | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 360 | case IXGBE_DEV_ID_82599_CX4: |
Peter P Waskiewicz Jr | 6b1be19 | 2009-09-14 07:48:10 +0000 | [diff] [blame] | 361 | media_type = ixgbe_media_type_cx4; |
Peter P Waskiewicz Jr | 8911184f | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 362 | break; |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 363 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 364 | media_type = ixgbe_media_type_copper; |
| 365 | break; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 366 | default: |
| 367 | media_type = ixgbe_media_type_unknown; |
| 368 | break; |
| 369 | } |
| 370 | out: |
| 371 | return media_type; |
| 372 | } |
| 373 | |
| 374 | /** |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 375 | * ixgbe_start_mac_link_82599 - Setup MAC link settings |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 376 | * @hw: pointer to hardware structure |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 377 | * @autoneg_wait_to_complete: true when waiting for completion is needed |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 378 | * |
| 379 | * Configures link settings based on values in the ixgbe_hw struct. |
| 380 | * Restarts the link. Performs autonegotiation if needed. |
| 381 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 382 | static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw, |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 383 | bool autoneg_wait_to_complete) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 384 | { |
| 385 | u32 autoc_reg; |
| 386 | u32 links_reg; |
| 387 | u32 i; |
| 388 | s32 status = 0; |
| 389 | |
| 390 | /* Restart link */ |
| 391 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 392 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; |
| 393 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); |
| 394 | |
| 395 | /* Only poll for autoneg to complete if specified to do so */ |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 396 | if (autoneg_wait_to_complete) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 397 | if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) == |
| 398 | IXGBE_AUTOC_LMS_KX4_KX_KR || |
| 399 | (autoc_reg & IXGBE_AUTOC_LMS_MASK) == |
| 400 | IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || |
| 401 | (autoc_reg & IXGBE_AUTOC_LMS_MASK) == |
| 402 | IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { |
| 403 | links_reg = 0; /* Just in case Autoneg time = 0 */ |
| 404 | for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) { |
| 405 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 406 | if (links_reg & IXGBE_LINKS_KX_AN_COMP) |
| 407 | break; |
| 408 | msleep(100); |
| 409 | } |
| 410 | if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) { |
| 411 | status = IXGBE_ERR_AUTONEG_NOT_COMPLETE; |
| 412 | hw_dbg(hw, "Autoneg did not complete.\n"); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 417 | /* Add delay to filter out noises during initial link setup */ |
| 418 | msleep(50); |
| 419 | |
| 420 | return status; |
| 421 | } |
| 422 | |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 423 | /** |
| 424 | * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser |
| 425 | * @hw: pointer to hardware structure |
| 426 | * |
| 427 | * The base drivers may require better control over SFP+ module |
| 428 | * PHY states. This includes selectively shutting down the Tx |
| 429 | * laser on the PHY, effectively halting physical link. |
| 430 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 431 | static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 432 | { |
| 433 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 434 | |
| 435 | /* Disable tx laser; allow 100us to go dark per spec */ |
| 436 | esdp_reg |= IXGBE_ESDP_SDP3; |
| 437 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); |
| 438 | IXGBE_WRITE_FLUSH(hw); |
| 439 | udelay(100); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser |
| 444 | * @hw: pointer to hardware structure |
| 445 | * |
| 446 | * The base drivers may require better control over SFP+ module |
| 447 | * PHY states. This includes selectively turning on the Tx |
| 448 | * laser on the PHY, effectively starting physical link. |
| 449 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 450 | static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 451 | { |
| 452 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 453 | |
| 454 | /* Enable tx laser; allow 100ms to light up */ |
| 455 | esdp_reg &= ~IXGBE_ESDP_SDP3; |
| 456 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); |
| 457 | IXGBE_WRITE_FLUSH(hw); |
| 458 | msleep(100); |
| 459 | } |
| 460 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 461 | /** |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 462 | * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser |
| 463 | * @hw: pointer to hardware structure |
| 464 | * |
| 465 | * When the driver changes the link speeds that it can support, |
| 466 | * it sets autotry_restart to true to indicate that we need to |
| 467 | * initiate a new autotry session with the link partner. To do |
| 468 | * so, we set the speed then disable and re-enable the tx laser, to |
| 469 | * alert the link partner that it also needs to restart autotry on its |
| 470 | * end. This is consistent with true clause 37 autoneg, which also |
| 471 | * involves a loss of signal. |
| 472 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 473 | static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw) |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 474 | { |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 475 | if (hw->mac.autotry_restart) { |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 476 | ixgbe_disable_tx_laser_multispeed_fiber(hw); |
| 477 | ixgbe_enable_tx_laser_multispeed_fiber(hw); |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 478 | hw->mac.autotry_restart = false; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /** |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 483 | * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 484 | * @hw: pointer to hardware structure |
| 485 | * @speed: new link speed |
| 486 | * @autoneg: true if autonegotiation enabled |
| 487 | * @autoneg_wait_to_complete: true when waiting for completion is needed |
| 488 | * |
| 489 | * Set the link speed in the AUTOC register and restarts link. |
| 490 | **/ |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 491 | s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw, |
| 492 | ixgbe_link_speed speed, |
| 493 | bool autoneg, |
| 494 | bool autoneg_wait_to_complete) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 495 | { |
| 496 | s32 status = 0; |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 497 | ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 498 | ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN; |
| 499 | u32 speedcnt = 0; |
| 500 | u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP); |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 501 | u32 i = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 502 | bool link_up = false; |
| 503 | bool negotiation; |
| 504 | |
| 505 | /* Mask off requested but non-supported speeds */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 506 | status = hw->mac.ops.get_link_capabilities(hw, &link_speed, |
| 507 | &negotiation); |
| 508 | if (status != 0) |
| 509 | return status; |
| 510 | |
| 511 | speed &= link_speed; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * Try each speed one by one, highest priority first. We do this in |
| 515 | * software because 10gb fiber doesn't support speed autonegotiation. |
| 516 | */ |
| 517 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) { |
| 518 | speedcnt++; |
| 519 | highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 520 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 521 | /* If we already have link at this speed, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 522 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, |
| 523 | false); |
| 524 | if (status != 0) |
| 525 | return status; |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 526 | |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 527 | if ((link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up) |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 528 | goto out; |
| 529 | |
| 530 | /* Set the module link speed */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 531 | esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5); |
| 532 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 533 | IXGBE_WRITE_FLUSH(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 534 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 535 | /* Allow module to change analog characteristics (1G->10G) */ |
| 536 | msleep(40); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 537 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 538 | status = ixgbe_setup_mac_link_82599(hw, |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 539 | IXGBE_LINK_SPEED_10GB_FULL, |
| 540 | autoneg, |
| 541 | autoneg_wait_to_complete); |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 542 | if (status != 0) |
Mallikarjuna R Chilakala | c3c7432 | 2009-09-01 13:50:14 +0000 | [diff] [blame] | 543 | return status; |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 544 | |
| 545 | /* Flap the tx laser if it has not already been done */ |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 546 | hw->mac.ops.flap_tx_laser(hw); |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 547 | |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 548 | /* |
| 549 | * Wait for the controller to acquire link. Per IEEE 802.3ap, |
| 550 | * Section 73.10.2, we may have to wait up to 500ms if KR is |
| 551 | * attempted. 82599 uses the same timing for 10g SFI. |
| 552 | */ |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 553 | for (i = 0; i < 5; i++) { |
| 554 | /* Wait for the link partner to also set speed */ |
| 555 | msleep(100); |
| 556 | |
| 557 | /* If we have link, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 558 | status = hw->mac.ops.check_link(hw, &link_speed, |
| 559 | &link_up, false); |
| 560 | if (status != 0) |
| 561 | return status; |
| 562 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 563 | if (link_up) |
| 564 | goto out; |
| 565 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) { |
| 569 | speedcnt++; |
| 570 | if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN) |
| 571 | highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 572 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 573 | /* If we already have link at this speed, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 574 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, |
| 575 | false); |
| 576 | if (status != 0) |
| 577 | return status; |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 578 | |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 579 | if ((link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up) |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 580 | goto out; |
| 581 | |
| 582 | /* Set the module link speed */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 583 | esdp_reg &= ~IXGBE_ESDP_SDP5; |
| 584 | esdp_reg |= IXGBE_ESDP_SDP5_DIR; |
| 585 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg); |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 586 | IXGBE_WRITE_FLUSH(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 587 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 588 | /* Allow module to change analog characteristics (10G->1G) */ |
| 589 | msleep(40); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 590 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 591 | status = ixgbe_setup_mac_link_82599(hw, |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 592 | IXGBE_LINK_SPEED_1GB_FULL, |
| 593 | autoneg, |
| 594 | autoneg_wait_to_complete); |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 595 | if (status != 0) |
Mallikarjuna R Chilakala | c3c7432 | 2009-09-01 13:50:14 +0000 | [diff] [blame] | 596 | return status; |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 597 | |
| 598 | /* Flap the tx laser if it has not already been done */ |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 599 | hw->mac.ops.flap_tx_laser(hw); |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 600 | |
| 601 | /* Wait for the link partner to also set speed */ |
| 602 | msleep(100); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 603 | |
| 604 | /* If we have link, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 605 | status = hw->mac.ops.check_link(hw, &link_speed, &link_up, |
| 606 | false); |
| 607 | if (status != 0) |
| 608 | return status; |
| 609 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 610 | if (link_up) |
| 611 | goto out; |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * We didn't get link. Configure back to the highest speed we tried, |
| 616 | * (if there was more than one). We call ourselves back with just the |
| 617 | * single highest speed that the user requested. |
| 618 | */ |
| 619 | if (speedcnt > 1) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 620 | status = ixgbe_setup_mac_link_multispeed_fiber(hw, |
| 621 | highest_link_speed, |
| 622 | autoneg, |
| 623 | autoneg_wait_to_complete); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 624 | |
| 625 | out: |
Mallikarjuna R Chilakala | c3c7432 | 2009-09-01 13:50:14 +0000 | [diff] [blame] | 626 | /* Set autoneg_advertised value based on input link speed */ |
| 627 | hw->phy.autoneg_advertised = 0; |
| 628 | |
| 629 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 630 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; |
| 631 | |
| 632 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) |
| 633 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; |
| 634 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 635 | return status; |
| 636 | } |
| 637 | |
| 638 | /** |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 639 | * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed |
| 640 | * @hw: pointer to hardware structure |
| 641 | * @speed: new link speed |
| 642 | * @autoneg: true if autonegotiation enabled |
| 643 | * @autoneg_wait_to_complete: true when waiting for completion is needed |
| 644 | * |
| 645 | * Implements the Intel SmartSpeed algorithm. |
| 646 | **/ |
| 647 | static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw, |
| 648 | ixgbe_link_speed speed, bool autoneg, |
| 649 | bool autoneg_wait_to_complete) |
| 650 | { |
| 651 | s32 status = 0; |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 652 | ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN; |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 653 | s32 i, j; |
| 654 | bool link_up = false; |
| 655 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 656 | |
| 657 | /* Set autoneg_advertised value based on input link speed */ |
| 658 | hw->phy.autoneg_advertised = 0; |
| 659 | |
| 660 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 661 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL; |
| 662 | |
| 663 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) |
| 664 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; |
| 665 | |
| 666 | if (speed & IXGBE_LINK_SPEED_100_FULL) |
| 667 | hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL; |
| 668 | |
| 669 | /* |
| 670 | * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the |
| 671 | * autoneg advertisement if link is unable to be established at the |
| 672 | * highest negotiated rate. This can sometimes happen due to integrity |
| 673 | * issues with the physical media connection. |
| 674 | */ |
| 675 | |
| 676 | /* First, try to get link with full advertisement */ |
| 677 | hw->phy.smart_speed_active = false; |
| 678 | for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) { |
| 679 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, |
| 680 | autoneg_wait_to_complete); |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 681 | if (status != 0) |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 682 | goto out; |
| 683 | |
| 684 | /* |
| 685 | * Wait for the controller to acquire link. Per IEEE 802.3ap, |
| 686 | * Section 73.10.2, we may have to wait up to 500ms if KR is |
| 687 | * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per |
| 688 | * Table 9 in the AN MAS. |
| 689 | */ |
| 690 | for (i = 0; i < 5; i++) { |
| 691 | mdelay(100); |
| 692 | |
| 693 | /* If we have link, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 694 | status = hw->mac.ops.check_link(hw, &link_speed, |
| 695 | &link_up, false); |
| 696 | if (status != 0) |
| 697 | goto out; |
| 698 | |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 699 | if (link_up) |
| 700 | goto out; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * We didn't get link. If we advertised KR plus one of KX4/KX |
| 706 | * (or BX4/BX), then disable KR and try again. |
| 707 | */ |
| 708 | if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) || |
| 709 | ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0)) |
| 710 | goto out; |
| 711 | |
| 712 | /* Turn SmartSpeed on to disable KR support */ |
| 713 | hw->phy.smart_speed_active = true; |
| 714 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, |
| 715 | autoneg_wait_to_complete); |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 716 | if (status != 0) |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 717 | goto out; |
| 718 | |
| 719 | /* |
| 720 | * Wait for the controller to acquire link. 600ms will allow for |
| 721 | * the AN link_fail_inhibit_timer as well for multiple cycles of |
| 722 | * parallel detect, both 10g and 1g. This allows for the maximum |
| 723 | * connect attempts as defined in the AN MAS table 73-7. |
| 724 | */ |
| 725 | for (i = 0; i < 6; i++) { |
| 726 | mdelay(100); |
| 727 | |
| 728 | /* If we have link, just jump out */ |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 729 | status = hw->mac.ops.check_link(hw, &link_speed, |
| 730 | &link_up, false); |
| 731 | if (status != 0) |
| 732 | goto out; |
| 733 | |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 734 | if (link_up) |
| 735 | goto out; |
| 736 | } |
| 737 | |
| 738 | /* We didn't get link. Turn SmartSpeed back off. */ |
| 739 | hw->phy.smart_speed_active = false; |
| 740 | status = ixgbe_setup_mac_link_82599(hw, speed, autoneg, |
| 741 | autoneg_wait_to_complete); |
| 742 | |
| 743 | out: |
Anjali Singhai | c4ee6a5 | 2010-04-27 11:31:25 +0000 | [diff] [blame] | 744 | if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL)) |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 745 | hw_dbg(hw, "Smartspeed has downgraded the link speed from " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 746 | "the maximum advertised\n"); |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 747 | return status; |
| 748 | } |
| 749 | |
| 750 | /** |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 751 | * ixgbe_setup_mac_link_82599 - Set MAC link speed |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 752 | * @hw: pointer to hardware structure |
| 753 | * @speed: new link speed |
| 754 | * @autoneg: true if autonegotiation enabled |
| 755 | * @autoneg_wait_to_complete: true when waiting for completion is needed |
| 756 | * |
| 757 | * Set the link speed in the AUTOC register and restarts link. |
| 758 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 759 | static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw, |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 760 | ixgbe_link_speed speed, bool autoneg, |
| 761 | bool autoneg_wait_to_complete) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 762 | { |
| 763 | s32 status = 0; |
| 764 | u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 765 | u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 766 | u32 start_autoc = autoc; |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 767 | u32 orig_autoc = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 768 | u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK; |
| 769 | u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK; |
| 770 | u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK; |
| 771 | u32 links_reg; |
| 772 | u32 i; |
| 773 | ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN; |
| 774 | |
| 775 | /* Check to see if speed passed in is supported. */ |
| 776 | hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg); |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 777 | if (status != 0) |
| 778 | goto out; |
| 779 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 780 | speed &= link_capabilities; |
| 781 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 782 | if (speed == IXGBE_LINK_SPEED_UNKNOWN) { |
| 783 | status = IXGBE_ERR_LINK_SETUP; |
| 784 | goto out; |
| 785 | } |
| 786 | |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 787 | /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/ |
| 788 | if (hw->mac.orig_link_settings_stored) |
| 789 | orig_autoc = hw->mac.orig_autoc; |
| 790 | else |
| 791 | orig_autoc = autoc; |
| 792 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 793 | if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || |
| 794 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || |
| 795 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 796 | /* Set KX4/KX/KR support according to speed requested */ |
| 797 | autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP); |
| 798 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
PJ Waskiewicz | 1eb99d5 | 2009-04-09 22:28:33 +0000 | [diff] [blame] | 799 | if (orig_autoc & IXGBE_AUTOC_KX4_SUPP) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 800 | autoc |= IXGBE_AUTOC_KX4_SUPP; |
Don Skidmore | cd7e1f0 | 2009-10-08 15:36:22 +0000 | [diff] [blame] | 801 | if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) && |
| 802 | (hw->phy.smart_speed_active == false)) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 803 | autoc |= IXGBE_AUTOC_KR_SUPP; |
| 804 | if (speed & IXGBE_LINK_SPEED_1GB_FULL) |
| 805 | autoc |= IXGBE_AUTOC_KX_SUPP; |
| 806 | } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) && |
| 807 | (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN || |
| 808 | link_mode == IXGBE_AUTOC_LMS_1G_AN)) { |
| 809 | /* Switch from 1G SFI to 10G SFI if requested */ |
| 810 | if ((speed == IXGBE_LINK_SPEED_10GB_FULL) && |
| 811 | (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) { |
| 812 | autoc &= ~IXGBE_AUTOC_LMS_MASK; |
| 813 | autoc |= IXGBE_AUTOC_LMS_10G_SERIAL; |
| 814 | } |
| 815 | } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) && |
| 816 | (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) { |
| 817 | /* Switch from 10G SFI to 1G SFI if requested */ |
| 818 | if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && |
| 819 | (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) { |
| 820 | autoc &= ~IXGBE_AUTOC_LMS_MASK; |
| 821 | if (autoneg) |
| 822 | autoc |= IXGBE_AUTOC_LMS_1G_AN; |
| 823 | else |
| 824 | autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN; |
| 825 | } |
| 826 | } |
| 827 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 828 | if (autoc != start_autoc) { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 829 | /* Restart link */ |
| 830 | autoc |= IXGBE_AUTOC_AN_RESTART; |
| 831 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc); |
| 832 | |
| 833 | /* Only poll for autoneg to complete if specified to do so */ |
| 834 | if (autoneg_wait_to_complete) { |
| 835 | if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR || |
| 836 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN || |
| 837 | link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) { |
| 838 | links_reg = 0; /*Just in case Autoneg time=0*/ |
| 839 | for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) { |
| 840 | links_reg = |
| 841 | IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 842 | if (links_reg & IXGBE_LINKS_KX_AN_COMP) |
| 843 | break; |
| 844 | msleep(100); |
| 845 | } |
| 846 | if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) { |
| 847 | status = |
| 848 | IXGBE_ERR_AUTONEG_NOT_COMPLETE; |
| 849 | hw_dbg(hw, "Autoneg did not " |
| 850 | "complete.\n"); |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 855 | /* Add delay to filter out noises during initial link setup */ |
| 856 | msleep(50); |
| 857 | } |
| 858 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 859 | out: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 860 | return status; |
| 861 | } |
| 862 | |
| 863 | /** |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 864 | * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 865 | * @hw: pointer to hardware structure |
| 866 | * @speed: new link speed |
| 867 | * @autoneg: true if autonegotiation enabled |
| 868 | * @autoneg_wait_to_complete: true if waiting is needed to complete |
| 869 | * |
| 870 | * Restarts link on PHY and MAC based on settings passed in. |
| 871 | **/ |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 872 | static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw, |
| 873 | ixgbe_link_speed speed, |
| 874 | bool autoneg, |
| 875 | bool autoneg_wait_to_complete) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 876 | { |
| 877 | s32 status; |
| 878 | |
| 879 | /* Setup the PHY according to input speed */ |
| 880 | status = hw->phy.ops.setup_link_speed(hw, speed, autoneg, |
| 881 | autoneg_wait_to_complete); |
| 882 | /* Set up MAC */ |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 883 | ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 884 | |
| 885 | return status; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * ixgbe_reset_hw_82599 - Perform hardware reset |
| 890 | * @hw: pointer to hardware structure |
| 891 | * |
| 892 | * Resets the hardware by resetting the transmit and receive units, masks |
| 893 | * and clears all interrupts, perform a PHY reset, and perform a link (MAC) |
| 894 | * reset. |
| 895 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 896 | static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 897 | { |
| 898 | s32 status = 0; |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 899 | u32 ctrl; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 900 | u32 i; |
| 901 | u32 autoc; |
| 902 | u32 autoc2; |
| 903 | |
| 904 | /* Call adapter stop to disable tx/rx and clear interrupts */ |
| 905 | hw->mac.ops.stop_adapter(hw); |
| 906 | |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 907 | /* PHY ops must be identified and initialized prior to reset */ |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 908 | |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 909 | /* Identify PHY and related function pointers */ |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 910 | status = hw->phy.ops.init(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 911 | |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 912 | if (status == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 913 | goto reset_hw_out; |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 914 | |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 915 | /* Setup SFP module if there is one present. */ |
| 916 | if (hw->phy.sfp_setup_needed) { |
| 917 | status = hw->mac.ops.setup_sfp(hw); |
| 918 | hw->phy.sfp_setup_needed = false; |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 919 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 920 | |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 921 | if (status == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 922 | goto reset_hw_out; |
| 923 | |
PJ Waskiewicz | 553b449 | 2009-04-09 22:28:15 +0000 | [diff] [blame] | 924 | /* Reset PHY */ |
| 925 | if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL) |
| 926 | hw->phy.ops.reset(hw); |
| 927 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 928 | /* |
| 929 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master |
| 930 | * access and verify no pending requests before reset |
| 931 | */ |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 932 | ixgbe_disable_pcie_master(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 933 | |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 934 | mac_reset_top: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 935 | /* |
| 936 | * Issue global reset to the MAC. This needs to be a SW reset. |
| 937 | * If link reset is used, it might reset the MAC when mng is using it |
| 938 | */ |
| 939 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 940 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST)); |
| 941 | IXGBE_WRITE_FLUSH(hw); |
| 942 | |
| 943 | /* Poll for reset bit to self-clear indicating reset is complete */ |
| 944 | for (i = 0; i < 10; i++) { |
| 945 | udelay(1); |
| 946 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 947 | if (!(ctrl & IXGBE_CTRL_RST)) |
| 948 | break; |
| 949 | } |
| 950 | if (ctrl & IXGBE_CTRL_RST) { |
| 951 | status = IXGBE_ERR_RESET_FAILED; |
| 952 | hw_dbg(hw, "Reset polling failed to complete.\n"); |
| 953 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 954 | |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 955 | /* |
| 956 | * Double resets are required for recovery from certain error |
| 957 | * conditions. Between resets, it is necessary to stall to allow time |
| 958 | * for any pending HW events to complete. We use 1usec since that is |
| 959 | * what is needed for ixgbe_disable_pcie_master(). The second reset |
| 960 | * then clears out any effects of those events. |
| 961 | */ |
| 962 | if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { |
| 963 | hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; |
| 964 | udelay(1); |
| 965 | goto mac_reset_top; |
| 966 | } |
| 967 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 968 | msleep(50); |
| 969 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 970 | /* |
| 971 | * Store the original AUTOC/AUTOC2 values if they have not been |
| 972 | * stored off yet. Otherwise restore the stored original |
| 973 | * values since the reset operation sets back to defaults. |
| 974 | */ |
| 975 | autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 976 | autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); |
| 977 | if (hw->mac.orig_link_settings_stored == false) { |
| 978 | hw->mac.orig_autoc = autoc; |
| 979 | hw->mac.orig_autoc2 = autoc2; |
| 980 | hw->mac.orig_link_settings_stored = true; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 981 | } else { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 982 | if (autoc != hw->mac.orig_autoc) |
| 983 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc | |
| 984 | IXGBE_AUTOC_AN_RESTART)); |
| 985 | |
| 986 | if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) != |
| 987 | (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) { |
| 988 | autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK; |
| 989 | autoc2 |= (hw->mac.orig_autoc2 & |
| 990 | IXGBE_AUTOC2_UPPER_MASK); |
| 991 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2); |
| 992 | } |
| 993 | } |
| 994 | |
Emil Tantilov | 278675d | 2011-02-19 08:43:49 +0000 | [diff] [blame] | 995 | /* Store the permanent mac address */ |
| 996 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); |
| 997 | |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 998 | /* |
| 999 | * Store MAC address from RAR0, clear receive address registers, and |
| 1000 | * clear the multicast table. Also reset num_rar_entries to 128, |
| 1001 | * since we modify this value when programming the SAN MAC address. |
| 1002 | */ |
| 1003 | hw->mac.num_rar_entries = 128; |
| 1004 | hw->mac.ops.init_rx_addrs(hw); |
| 1005 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 1006 | /* Store the permanent SAN mac address */ |
| 1007 | hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr); |
| 1008 | |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 1009 | /* Add the SAN MAC address to the RAR only if it's a valid address */ |
| 1010 | if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) { |
| 1011 | hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1, |
| 1012 | hw->mac.san_addr, 0, IXGBE_RAH_AV); |
| 1013 | |
| 1014 | /* Reserve the last RAR for the SAN MAC address */ |
| 1015 | hw->mac.num_rar_entries--; |
| 1016 | } |
| 1017 | |
Yi Zou | 383ff34 | 2009-10-28 18:23:57 +0000 | [diff] [blame] | 1018 | /* Store the alternative WWNN/WWPN prefix */ |
| 1019 | hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix, |
| 1020 | &hw->mac.wwpn_prefix); |
| 1021 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 1022 | reset_hw_out: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1023 | return status; |
| 1024 | } |
| 1025 | |
| 1026 | /** |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1027 | * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables. |
| 1028 | * @hw: pointer to hardware structure |
| 1029 | **/ |
| 1030 | s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw) |
| 1031 | { |
| 1032 | int i; |
| 1033 | u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL); |
| 1034 | fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE; |
| 1035 | |
| 1036 | /* |
| 1037 | * Before starting reinitialization process, |
| 1038 | * FDIRCMD.CMD must be zero. |
| 1039 | */ |
| 1040 | for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) { |
| 1041 | if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) & |
| 1042 | IXGBE_FDIRCMD_CMD_MASK)) |
| 1043 | break; |
| 1044 | udelay(10); |
| 1045 | } |
| 1046 | if (i >= IXGBE_FDIRCMD_CMD_POLL) { |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1047 | hw_dbg(hw, "Flow Director previous command isn't complete, " |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 1048 | "aborting table re-initialization.\n"); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1049 | return IXGBE_ERR_FDIR_REINIT_FAILED; |
| 1050 | } |
| 1051 | |
| 1052 | IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0); |
| 1053 | IXGBE_WRITE_FLUSH(hw); |
| 1054 | /* |
| 1055 | * 82599 adapters flow director init flow cannot be restarted, |
| 1056 | * Workaround 82599 silicon errata by performing the following steps |
| 1057 | * before re-writing the FDIRCTRL control register with the same value. |
| 1058 | * - write 1 to bit 8 of FDIRCMD register & |
| 1059 | * - write 0 to bit 8 of FDIRCMD register |
| 1060 | */ |
| 1061 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, |
| 1062 | (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) | |
| 1063 | IXGBE_FDIRCMD_CLEARHT)); |
| 1064 | IXGBE_WRITE_FLUSH(hw); |
| 1065 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, |
| 1066 | (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) & |
| 1067 | ~IXGBE_FDIRCMD_CLEARHT)); |
| 1068 | IXGBE_WRITE_FLUSH(hw); |
| 1069 | /* |
| 1070 | * Clear FDIR Hash register to clear any leftover hashes |
| 1071 | * waiting to be programmed. |
| 1072 | */ |
| 1073 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00); |
| 1074 | IXGBE_WRITE_FLUSH(hw); |
| 1075 | |
| 1076 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl); |
| 1077 | IXGBE_WRITE_FLUSH(hw); |
| 1078 | |
| 1079 | /* Poll init-done after we write FDIRCTRL register */ |
| 1080 | for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) { |
| 1081 | if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) & |
| 1082 | IXGBE_FDIRCTRL_INIT_DONE) |
| 1083 | break; |
| 1084 | udelay(10); |
| 1085 | } |
| 1086 | if (i >= IXGBE_FDIR_INIT_DONE_POLL) { |
| 1087 | hw_dbg(hw, "Flow Director Signature poll time exceeded!\n"); |
| 1088 | return IXGBE_ERR_FDIR_REINIT_FAILED; |
| 1089 | } |
| 1090 | |
| 1091 | /* Clear FDIR statistics registers (read to clear) */ |
| 1092 | IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT); |
| 1093 | IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT); |
| 1094 | IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 1095 | IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
| 1096 | IXGBE_READ_REG(hw, IXGBE_FDIRLEN); |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters |
| 1103 | * @hw: pointer to hardware structure |
| 1104 | * @pballoc: which mode to allocate filters with |
| 1105 | **/ |
| 1106 | s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc) |
| 1107 | { |
| 1108 | u32 fdirctrl = 0; |
| 1109 | u32 pbsize; |
| 1110 | int i; |
| 1111 | |
| 1112 | /* |
| 1113 | * Before enabling Flow Director, the Rx Packet Buffer size |
| 1114 | * must be reduced. The new value is the current size minus |
| 1115 | * flow director memory usage size. |
| 1116 | */ |
| 1117 | pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc)); |
| 1118 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), |
| 1119 | (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize)); |
| 1120 | |
| 1121 | /* |
| 1122 | * The defaults in the HW for RX PB 1-7 are not zero and so should be |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 1123 | * initialized to zero for non DCB mode otherwise actual total RX PB |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1124 | * would be bigger than programmed and filter space would run into |
| 1125 | * the PB 0 region. |
| 1126 | */ |
| 1127 | for (i = 1; i < 8; i++) |
| 1128 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0); |
| 1129 | |
| 1130 | /* Send interrupt when 64 filters are left */ |
| 1131 | fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT; |
| 1132 | |
| 1133 | /* Set the maximum length per hash bucket to 0xA filters */ |
| 1134 | fdirctrl |= 0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT; |
| 1135 | |
| 1136 | switch (pballoc) { |
| 1137 | case IXGBE_FDIR_PBALLOC_64K: |
| 1138 | /* 8k - 1 signature filters */ |
| 1139 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K; |
| 1140 | break; |
| 1141 | case IXGBE_FDIR_PBALLOC_128K: |
| 1142 | /* 16k - 1 signature filters */ |
| 1143 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K; |
| 1144 | break; |
| 1145 | case IXGBE_FDIR_PBALLOC_256K: |
| 1146 | /* 32k - 1 signature filters */ |
| 1147 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K; |
| 1148 | break; |
| 1149 | default: |
| 1150 | /* bad value */ |
| 1151 | return IXGBE_ERR_CONFIG; |
| 1152 | }; |
| 1153 | |
| 1154 | /* Move the flexible bytes to use the ethertype - shift 6 words */ |
| 1155 | fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT); |
| 1156 | |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1157 | |
| 1158 | /* Prime the keys for hashing */ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1159 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY); |
| 1160 | IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1161 | |
| 1162 | /* |
| 1163 | * Poll init-done after we write the register. Estimated times: |
| 1164 | * 10G: PBALLOC = 11b, timing is 60us |
| 1165 | * 1G: PBALLOC = 11b, timing is 600us |
| 1166 | * 100M: PBALLOC = 11b, timing is 6ms |
| 1167 | * |
| 1168 | * Multiple these timings by 4 if under full Rx load |
| 1169 | * |
| 1170 | * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for |
| 1171 | * 1 msec per poll time. If we're at line rate and drop to 100M, then |
| 1172 | * this might not finish in our poll time, but we can live with that |
| 1173 | * for now. |
| 1174 | */ |
| 1175 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl); |
| 1176 | IXGBE_WRITE_FLUSH(hw); |
| 1177 | for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) { |
| 1178 | if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) & |
| 1179 | IXGBE_FDIRCTRL_INIT_DONE) |
| 1180 | break; |
| 1181 | msleep(1); |
| 1182 | } |
| 1183 | if (i >= IXGBE_FDIR_INIT_DONE_POLL) |
| 1184 | hw_dbg(hw, "Flow Director Signature poll time exceeded!\n"); |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters |
| 1191 | * @hw: pointer to hardware structure |
| 1192 | * @pballoc: which mode to allocate filters with |
| 1193 | **/ |
| 1194 | s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc) |
| 1195 | { |
| 1196 | u32 fdirctrl = 0; |
| 1197 | u32 pbsize; |
| 1198 | int i; |
| 1199 | |
| 1200 | /* |
| 1201 | * Before enabling Flow Director, the Rx Packet Buffer size |
| 1202 | * must be reduced. The new value is the current size minus |
| 1203 | * flow director memory usage size. |
| 1204 | */ |
| 1205 | pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc)); |
| 1206 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), |
| 1207 | (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize)); |
| 1208 | |
| 1209 | /* |
| 1210 | * The defaults in the HW for RX PB 1-7 are not zero and so should be |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 1211 | * initialized to zero for non DCB mode otherwise actual total RX PB |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1212 | * would be bigger than programmed and filter space would run into |
| 1213 | * the PB 0 region. |
| 1214 | */ |
| 1215 | for (i = 1; i < 8; i++) |
| 1216 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0); |
| 1217 | |
| 1218 | /* Send interrupt when 64 filters are left */ |
| 1219 | fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT; |
| 1220 | |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1221 | /* Initialize the drop queue to Rx queue 127 */ |
| 1222 | fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT); |
| 1223 | |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1224 | switch (pballoc) { |
| 1225 | case IXGBE_FDIR_PBALLOC_64K: |
| 1226 | /* 2k - 1 perfect filters */ |
| 1227 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K; |
| 1228 | break; |
| 1229 | case IXGBE_FDIR_PBALLOC_128K: |
| 1230 | /* 4k - 1 perfect filters */ |
| 1231 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K; |
| 1232 | break; |
| 1233 | case IXGBE_FDIR_PBALLOC_256K: |
| 1234 | /* 8k - 1 perfect filters */ |
| 1235 | fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K; |
| 1236 | break; |
| 1237 | default: |
| 1238 | /* bad value */ |
| 1239 | return IXGBE_ERR_CONFIG; |
| 1240 | }; |
| 1241 | |
| 1242 | /* Turn perfect match filtering on */ |
| 1243 | fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH; |
| 1244 | fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS; |
| 1245 | |
| 1246 | /* Move the flexible bytes to use the ethertype - shift 6 words */ |
| 1247 | fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT); |
| 1248 | |
| 1249 | /* Prime the keys for hashing */ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1250 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY); |
| 1251 | IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1252 | |
| 1253 | /* |
| 1254 | * Poll init-done after we write the register. Estimated times: |
| 1255 | * 10G: PBALLOC = 11b, timing is 60us |
| 1256 | * 1G: PBALLOC = 11b, timing is 600us |
| 1257 | * 100M: PBALLOC = 11b, timing is 6ms |
| 1258 | * |
| 1259 | * Multiple these timings by 4 if under full Rx load |
| 1260 | * |
| 1261 | * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for |
| 1262 | * 1 msec per poll time. If we're at line rate and drop to 100M, then |
| 1263 | * this might not finish in our poll time, but we can live with that |
| 1264 | * for now. |
| 1265 | */ |
| 1266 | |
| 1267 | /* Set the maximum length per hash bucket to 0xA filters */ |
| 1268 | fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT); |
| 1269 | |
| 1270 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl); |
| 1271 | IXGBE_WRITE_FLUSH(hw); |
| 1272 | for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) { |
| 1273 | if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) & |
| 1274 | IXGBE_FDIRCTRL_INIT_DONE) |
| 1275 | break; |
| 1276 | msleep(1); |
| 1277 | } |
| 1278 | if (i >= IXGBE_FDIR_INIT_DONE_POLL) |
| 1279 | hw_dbg(hw, "Flow Director Perfect poll time exceeded!\n"); |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | /** |
| 1286 | * ixgbe_atr_compute_hash_82599 - Compute the hashes for SW ATR |
| 1287 | * @stream: input bitstream to compute the hash on |
| 1288 | * @key: 32-bit hash key |
| 1289 | **/ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1290 | static u32 ixgbe_atr_compute_hash_82599(union ixgbe_atr_input *atr_input, |
| 1291 | u32 key) |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1292 | { |
| 1293 | /* |
| 1294 | * The algorithm is as follows: |
| 1295 | * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350 |
| 1296 | * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n] |
| 1297 | * and A[n] x B[n] is bitwise AND between same length strings |
| 1298 | * |
| 1299 | * K[n] is 16 bits, defined as: |
| 1300 | * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15] |
| 1301 | * for n modulo 32 < 15, K[n] = |
| 1302 | * K[(n % 32:0) | (31:31 - (14 - (n % 32)))] |
| 1303 | * |
| 1304 | * S[n] is 16 bits, defined as: |
| 1305 | * for n >= 15, S[n] = S[n:n - 15] |
| 1306 | * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))] |
| 1307 | * |
| 1308 | * To simplify for programming, the algorithm is implemented |
| 1309 | * in software this way: |
| 1310 | * |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1311 | * key[31:0], hi_hash_dword[31:0], lo_hash_dword[31:0], hash[15:0] |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1312 | * |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1313 | * for (i = 0; i < 352; i+=32) |
| 1314 | * hi_hash_dword[31:0] ^= Stream[(i+31):i]; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1315 | * |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1316 | * lo_hash_dword[15:0] ^= Stream[15:0]; |
| 1317 | * lo_hash_dword[15:0] ^= hi_hash_dword[31:16]; |
| 1318 | * lo_hash_dword[31:16] ^= hi_hash_dword[15:0]; |
| 1319 | * |
| 1320 | * hi_hash_dword[31:0] ^= Stream[351:320]; |
| 1321 | * |
| 1322 | * if(key[0]) |
| 1323 | * hash[15:0] ^= Stream[15:0]; |
| 1324 | * |
| 1325 | * for (i = 0; i < 16; i++) { |
| 1326 | * if (key[i]) |
| 1327 | * hash[15:0] ^= lo_hash_dword[(i+15):i]; |
| 1328 | * if (key[i + 16]) |
| 1329 | * hash[15:0] ^= hi_hash_dword[(i+15):i]; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1330 | * } |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1331 | * |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1332 | */ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1333 | __be32 common_hash_dword = 0; |
| 1334 | u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan; |
| 1335 | u32 hash_result = 0; |
| 1336 | u8 i; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1337 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1338 | /* record the flow_vm_vlan bits as they are a key part to the hash */ |
| 1339 | flow_vm_vlan = ntohl(atr_input->dword_stream[0]); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1340 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1341 | /* generate common hash dword */ |
| 1342 | for (i = 10; i; i -= 2) |
| 1343 | common_hash_dword ^= atr_input->dword_stream[i] ^ |
| 1344 | atr_input->dword_stream[i - 1]; |
| 1345 | |
| 1346 | hi_hash_dword = ntohl(common_hash_dword); |
| 1347 | |
| 1348 | /* low dword is word swapped version of common */ |
| 1349 | lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16); |
| 1350 | |
| 1351 | /* apply flow ID/VM pool/VLAN ID bits to hash words */ |
| 1352 | hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16); |
| 1353 | |
| 1354 | /* Process bits 0 and 16 */ |
| 1355 | if (key & 0x0001) hash_result ^= lo_hash_dword; |
| 1356 | if (key & 0x00010000) hash_result ^= hi_hash_dword; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1357 | |
| 1358 | /* |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1359 | * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to |
| 1360 | * delay this because bit 0 of the stream should not be processed |
| 1361 | * so we do not add the vlan until after bit 0 was processed |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1362 | */ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1363 | lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1364 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1365 | |
| 1366 | /* process the remaining 30 bits in the key 2 bits at a time */ |
| 1367 | for (i = 15; i; i-- ) { |
| 1368 | if (key & (0x0001 << i)) hash_result ^= lo_hash_dword >> i; |
| 1369 | if (key & (0x00010000 << i)) hash_result ^= hi_hash_dword >> i; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1372 | return hash_result & IXGBE_ATR_HASH_MASK; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1375 | /* |
| 1376 | * These defines allow us to quickly generate all of the necessary instructions |
| 1377 | * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION |
| 1378 | * for values 0 through 15 |
| 1379 | */ |
| 1380 | #define IXGBE_ATR_COMMON_HASH_KEY \ |
| 1381 | (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY) |
| 1382 | #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \ |
| 1383 | do { \ |
| 1384 | u32 n = (_n); \ |
| 1385 | if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \ |
| 1386 | common_hash ^= lo_hash_dword >> n; \ |
| 1387 | else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \ |
| 1388 | bucket_hash ^= lo_hash_dword >> n; \ |
| 1389 | else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \ |
| 1390 | sig_hash ^= lo_hash_dword << (16 - n); \ |
| 1391 | if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \ |
| 1392 | common_hash ^= hi_hash_dword >> n; \ |
| 1393 | else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \ |
| 1394 | bucket_hash ^= hi_hash_dword >> n; \ |
| 1395 | else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \ |
| 1396 | sig_hash ^= hi_hash_dword << (16 - n); \ |
| 1397 | } while (0); |
| 1398 | |
| 1399 | /** |
| 1400 | * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash |
| 1401 | * @stream: input bitstream to compute the hash on |
| 1402 | * |
| 1403 | * This function is almost identical to the function above but contains |
| 1404 | * several optomizations such as unwinding all of the loops, letting the |
| 1405 | * compiler work out all of the conditional ifs since the keys are static |
| 1406 | * defines, and computing two keys at once since the hashed dword stream |
| 1407 | * will be the same for both keys. |
| 1408 | **/ |
| 1409 | static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input, |
| 1410 | union ixgbe_atr_hash_dword common) |
| 1411 | { |
| 1412 | u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan; |
| 1413 | u32 sig_hash = 0, bucket_hash = 0, common_hash = 0; |
| 1414 | |
| 1415 | /* record the flow_vm_vlan bits as they are a key part to the hash */ |
| 1416 | flow_vm_vlan = ntohl(input.dword); |
| 1417 | |
| 1418 | /* generate common hash dword */ |
| 1419 | hi_hash_dword = ntohl(common.dword); |
| 1420 | |
| 1421 | /* low dword is word swapped version of common */ |
| 1422 | lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16); |
| 1423 | |
| 1424 | /* apply flow ID/VM pool/VLAN ID bits to hash words */ |
| 1425 | hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16); |
| 1426 | |
| 1427 | /* Process bits 0 and 16 */ |
| 1428 | IXGBE_COMPUTE_SIG_HASH_ITERATION(0); |
| 1429 | |
| 1430 | /* |
| 1431 | * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to |
| 1432 | * delay this because bit 0 of the stream should not be processed |
| 1433 | * so we do not add the vlan until after bit 0 was processed |
| 1434 | */ |
| 1435 | lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16); |
| 1436 | |
| 1437 | /* Process remaining 30 bit of the key */ |
| 1438 | IXGBE_COMPUTE_SIG_HASH_ITERATION(1); |
| 1439 | IXGBE_COMPUTE_SIG_HASH_ITERATION(2); |
| 1440 | IXGBE_COMPUTE_SIG_HASH_ITERATION(3); |
| 1441 | IXGBE_COMPUTE_SIG_HASH_ITERATION(4); |
| 1442 | IXGBE_COMPUTE_SIG_HASH_ITERATION(5); |
| 1443 | IXGBE_COMPUTE_SIG_HASH_ITERATION(6); |
| 1444 | IXGBE_COMPUTE_SIG_HASH_ITERATION(7); |
| 1445 | IXGBE_COMPUTE_SIG_HASH_ITERATION(8); |
| 1446 | IXGBE_COMPUTE_SIG_HASH_ITERATION(9); |
| 1447 | IXGBE_COMPUTE_SIG_HASH_ITERATION(10); |
| 1448 | IXGBE_COMPUTE_SIG_HASH_ITERATION(11); |
| 1449 | IXGBE_COMPUTE_SIG_HASH_ITERATION(12); |
| 1450 | IXGBE_COMPUTE_SIG_HASH_ITERATION(13); |
| 1451 | IXGBE_COMPUTE_SIG_HASH_ITERATION(14); |
| 1452 | IXGBE_COMPUTE_SIG_HASH_ITERATION(15); |
| 1453 | |
| 1454 | /* combine common_hash result with signature and bucket hashes */ |
| 1455 | bucket_hash ^= common_hash; |
| 1456 | bucket_hash &= IXGBE_ATR_HASH_MASK; |
| 1457 | |
| 1458 | sig_hash ^= common_hash << 16; |
| 1459 | sig_hash &= IXGBE_ATR_HASH_MASK << 16; |
| 1460 | |
| 1461 | /* return completed signature hash */ |
| 1462 | return sig_hash ^ bucket_hash; |
| 1463 | } |
| 1464 | |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1465 | /** |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1466 | * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter |
| 1467 | * @hw: pointer to hardware structure |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1468 | * @input: unique input dword |
| 1469 | * @common: compressed common input dword |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1470 | * @queue: queue index to direct traffic to |
| 1471 | **/ |
| 1472 | s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw, |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1473 | union ixgbe_atr_hash_dword input, |
| 1474 | union ixgbe_atr_hash_dword common, |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1475 | u8 queue) |
| 1476 | { |
| 1477 | u64 fdirhashcmd; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1478 | u32 fdircmd; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1479 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1480 | /* |
| 1481 | * Get the flow_type in order to program FDIRCMD properly |
| 1482 | * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 |
| 1483 | */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1484 | switch (input.formatted.flow_type) { |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1485 | case IXGBE_ATR_FLOW_TYPE_TCPV4: |
| 1486 | case IXGBE_ATR_FLOW_TYPE_UDPV4: |
| 1487 | case IXGBE_ATR_FLOW_TYPE_SCTPV4: |
| 1488 | case IXGBE_ATR_FLOW_TYPE_TCPV6: |
| 1489 | case IXGBE_ATR_FLOW_TYPE_UDPV6: |
| 1490 | case IXGBE_ATR_FLOW_TYPE_SCTPV6: |
| 1491 | break; |
| 1492 | default: |
| 1493 | hw_dbg(hw, " Error on flow type input\n"); |
| 1494 | return IXGBE_ERR_CONFIG; |
| 1495 | } |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1496 | |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1497 | /* configure FDIRCMD register */ |
| 1498 | fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE | |
| 1499 | IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1500 | fdircmd |= input.formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1501 | fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1502 | |
| 1503 | /* |
| 1504 | * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits |
| 1505 | * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH. |
| 1506 | */ |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1507 | fdirhashcmd = (u64)fdircmd << 32; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1508 | fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1509 | |
| 1510 | IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd); |
| 1511 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 1512 | hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd); |
| 1513 | |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1518 | * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks |
| 1519 | * @input_mask: mask to be bit swapped |
| 1520 | * |
| 1521 | * The source and destination port masks for flow director are bit swapped |
| 1522 | * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to |
| 1523 | * generate a correctly swapped value we need to bit swap the mask and that |
| 1524 | * is what is accomplished by this function. |
| 1525 | **/ |
| 1526 | static u32 ixgbe_get_fdirtcpm_82599(struct ixgbe_atr_input_masks *input_masks) |
| 1527 | { |
| 1528 | u32 mask = ntohs(input_masks->dst_port_mask); |
| 1529 | mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT; |
| 1530 | mask |= ntohs(input_masks->src_port_mask); |
| 1531 | mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1); |
| 1532 | mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2); |
| 1533 | mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4); |
| 1534 | return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8); |
| 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * These two macros are meant to address the fact that we have registers |
| 1539 | * that are either all or in part big-endian. As a result on big-endian |
| 1540 | * systems we will end up byte swapping the value to little-endian before |
| 1541 | * it is byte swapped again and written to the hardware in the original |
| 1542 | * big-endian format. |
| 1543 | */ |
| 1544 | #define IXGBE_STORE_AS_BE32(_value) \ |
| 1545 | (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \ |
| 1546 | (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24)) |
| 1547 | |
| 1548 | #define IXGBE_WRITE_REG_BE32(a, reg, value) \ |
| 1549 | IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value))) |
| 1550 | |
| 1551 | #define IXGBE_STORE_AS_BE16(_value) \ |
| 1552 | (((u16)(_value) >> 8) | ((u16)(_value) << 8)) |
| 1553 | |
| 1554 | /** |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1555 | * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter |
| 1556 | * @hw: pointer to hardware structure |
| 1557 | * @input: input bitstream |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1558 | * @input_masks: bitwise masks for relevant fields |
| 1559 | * @soft_id: software index into the silicon hash tables for filter storage |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1560 | * @queue: queue index to direct traffic to |
| 1561 | * |
| 1562 | * Note that the caller to this function must lock before calling, since the |
| 1563 | * hardware writes must be protected from one another. |
| 1564 | **/ |
| 1565 | s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw, |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 1566 | union ixgbe_atr_input *input, |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1567 | struct ixgbe_atr_input_masks *input_masks, |
| 1568 | u16 soft_id, u8 queue) |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1569 | { |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1570 | u32 fdirhash; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1571 | u32 fdircmd; |
| 1572 | u32 fdirport, fdirtcpm; |
| 1573 | u32 fdirvlan; |
| 1574 | /* start with VLAN, flex bytes, VM pool, and IPv6 destination masked */ |
| 1575 | u32 fdirm = IXGBE_FDIRM_VLANID | IXGBE_FDIRM_VLANP | IXGBE_FDIRM_FLEX | |
| 1576 | IXGBE_FDIRM_POOL | IXGBE_FDIRM_DIPv6; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1577 | |
| 1578 | /* |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1579 | * Check flow_type formatting, and bail out before we touch the hardware |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1580 | * if there's a configuration issue |
| 1581 | */ |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1582 | switch (input->formatted.flow_type) { |
| 1583 | case IXGBE_ATR_FLOW_TYPE_IPV4: |
| 1584 | /* use the L4 protocol mask for raw IPv4/IPv6 traffic */ |
| 1585 | fdirm |= IXGBE_FDIRM_L4P; |
| 1586 | case IXGBE_ATR_FLOW_TYPE_SCTPV4: |
| 1587 | if (input_masks->dst_port_mask || input_masks->src_port_mask) { |
| 1588 | hw_dbg(hw, " Error on src/dst port mask\n"); |
| 1589 | return IXGBE_ERR_CONFIG; |
| 1590 | } |
| 1591 | case IXGBE_ATR_FLOW_TYPE_TCPV4: |
| 1592 | case IXGBE_ATR_FLOW_TYPE_UDPV4: |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1593 | break; |
| 1594 | default: |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1595 | hw_dbg(hw, " Error on flow type input\n"); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1596 | return IXGBE_ERR_CONFIG; |
| 1597 | } |
| 1598 | |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1599 | /* |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1600 | * Program the relevant mask registers. If src/dst_port or src/dst_addr |
| 1601 | * are zero, then assume a full mask for that field. Also assume that |
| 1602 | * a VLAN of 0 is unspecified, so mask that out as well. L4type |
| 1603 | * cannot be masked out in this implementation. |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1604 | * |
| 1605 | * This also assumes IPv4 only. IPv6 masking isn't supported at this |
| 1606 | * point in time. |
| 1607 | */ |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1608 | |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1609 | /* Program FDIRM */ |
| 1610 | switch (ntohs(input_masks->vlan_id_mask) & 0xEFFF) { |
| 1611 | case 0xEFFF: |
| 1612 | /* Unmask VLAN ID - bit 0 and fall through to unmask prio */ |
| 1613 | fdirm &= ~IXGBE_FDIRM_VLANID; |
| 1614 | case 0xE000: |
| 1615 | /* Unmask VLAN prio - bit 1 */ |
| 1616 | fdirm &= ~IXGBE_FDIRM_VLANP; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1617 | break; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1618 | case 0x0FFF: |
| 1619 | /* Unmask VLAN ID - bit 0 */ |
| 1620 | fdirm &= ~IXGBE_FDIRM_VLANID; |
| 1621 | break; |
| 1622 | case 0x0000: |
| 1623 | /* do nothing, vlans already masked */ |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1624 | break; |
| 1625 | default: |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1626 | hw_dbg(hw, " Error on VLAN mask\n"); |
| 1627 | return IXGBE_ERR_CONFIG; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1630 | if (input_masks->flex_mask & 0xFFFF) { |
| 1631 | if ((input_masks->flex_mask & 0xFFFF) != 0xFFFF) { |
| 1632 | hw_dbg(hw, " Error on flexible byte mask\n"); |
| 1633 | return IXGBE_ERR_CONFIG; |
| 1634 | } |
| 1635 | /* Unmask Flex Bytes - bit 4 */ |
| 1636 | fdirm &= ~IXGBE_FDIRM_FLEX; |
| 1637 | } |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1638 | |
| 1639 | /* Now mask VM pool and destination IPv6 - bits 5 and 2 */ |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 1640 | IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm); |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1641 | |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1642 | /* store the TCP/UDP port masks, bit reversed from port layout */ |
| 1643 | fdirtcpm = ixgbe_get_fdirtcpm_82599(input_masks); |
| 1644 | |
| 1645 | /* write both the same so that UDP and TCP use the same mask */ |
| 1646 | IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm); |
| 1647 | IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm); |
| 1648 | |
| 1649 | /* store source and destination IP masks (big-enian) */ |
| 1650 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M, |
| 1651 | ~input_masks->src_ip_mask[0]); |
| 1652 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M, |
| 1653 | ~input_masks->dst_ip_mask[0]); |
| 1654 | |
| 1655 | /* Apply masks to input data */ |
| 1656 | input->formatted.vlan_id &= input_masks->vlan_id_mask; |
| 1657 | input->formatted.flex_bytes &= input_masks->flex_mask; |
| 1658 | input->formatted.src_port &= input_masks->src_port_mask; |
| 1659 | input->formatted.dst_port &= input_masks->dst_port_mask; |
| 1660 | input->formatted.src_ip[0] &= input_masks->src_ip_mask[0]; |
| 1661 | input->formatted.dst_ip[0] &= input_masks->dst_ip_mask[0]; |
| 1662 | |
| 1663 | /* record vlan (little-endian) and flex_bytes(big-endian) */ |
| 1664 | fdirvlan = |
| 1665 | IXGBE_STORE_AS_BE16(ntohs(input->formatted.flex_bytes)); |
| 1666 | fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT; |
| 1667 | fdirvlan |= ntohs(input->formatted.vlan_id); |
| 1668 | IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan); |
| 1669 | |
| 1670 | /* record source and destination port (little-endian)*/ |
| 1671 | fdirport = ntohs(input->formatted.dst_port); |
| 1672 | fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT; |
| 1673 | fdirport |= ntohs(input->formatted.src_port); |
| 1674 | IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport); |
| 1675 | |
| 1676 | /* record the first 32 bits of the destination address (big-endian) */ |
| 1677 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]); |
| 1678 | |
| 1679 | /* record the source address (big-endian) */ |
| 1680 | IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]); |
| 1681 | |
| 1682 | /* configure FDIRCMD register */ |
| 1683 | fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE | |
| 1684 | IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN; |
| 1685 | fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT; |
| 1686 | fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT; |
| 1687 | |
| 1688 | /* we only want the bucket hash so drop the upper 16 bits */ |
| 1689 | fdirhash = ixgbe_atr_compute_hash_82599(input, |
| 1690 | IXGBE_ATR_BUCKET_HASH_KEY); |
| 1691 | fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT; |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1692 | |
| 1693 | IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash); |
| 1694 | IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd); |
| 1695 | |
| 1696 | return 0; |
| 1697 | } |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 1698 | |
Peter P Waskiewicz Jr | ffff477 | 2009-06-04 16:01:25 +0000 | [diff] [blame] | 1699 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1700 | * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register |
| 1701 | * @hw: pointer to hardware structure |
| 1702 | * @reg: analog register to read |
| 1703 | * @val: read value |
| 1704 | * |
| 1705 | * Performs read operation to Omer analog register specified. |
| 1706 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1707 | static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1708 | { |
| 1709 | u32 core_ctl; |
| 1710 | |
| 1711 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD | |
| 1712 | (reg << 8)); |
| 1713 | IXGBE_WRITE_FLUSH(hw); |
| 1714 | udelay(10); |
| 1715 | core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL); |
| 1716 | *val = (u8)core_ctl; |
| 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register |
| 1723 | * @hw: pointer to hardware structure |
| 1724 | * @reg: atlas register to write |
| 1725 | * @val: value to write |
| 1726 | * |
| 1727 | * Performs write operation to Omer analog register specified. |
| 1728 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1729 | static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1730 | { |
| 1731 | u32 core_ctl; |
| 1732 | |
| 1733 | core_ctl = (reg << 8) | val; |
| 1734 | IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl); |
| 1735 | IXGBE_WRITE_FLUSH(hw); |
| 1736 | udelay(10); |
| 1737 | |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx |
| 1743 | * @hw: pointer to hardware structure |
| 1744 | * |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 1745 | * Starts the hardware using the generic start_hw function |
| 1746 | * and the generation start_hw function. |
| 1747 | * Then performs revision-specific operations, if any. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1748 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1749 | static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1750 | { |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 1751 | s32 ret_val = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1752 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 1753 | ret_val = ixgbe_start_hw_generic(hw); |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 1754 | if (ret_val != 0) |
| 1755 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1756 | |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 1757 | ret_val = ixgbe_start_hw_gen2(hw); |
| 1758 | if (ret_val != 0) |
| 1759 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1760 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 1761 | /* We need to run link autotry after the driver loads */ |
| 1762 | hw->mac.autotry_restart = true; |
| 1763 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 1764 | if (ret_val == 0) |
| 1765 | ret_val = ixgbe_verify_fw_version_82599(hw); |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 1766 | out: |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 1767 | return ret_val; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * ixgbe_identify_phy_82599 - Get physical layer module |
| 1772 | * @hw: pointer to hardware structure |
| 1773 | * |
| 1774 | * Determines the physical layer module found on the current adapter. |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1775 | * If PHY already detected, maintains current PHY type in hw struct, |
| 1776 | * otherwise executes the PHY detection routine. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1777 | **/ |
Emil Tantilov | d6cd8e0 | 2011-03-16 01:58:20 +0000 | [diff] [blame] | 1778 | static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1779 | { |
| 1780 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1781 | |
| 1782 | /* Detect PHY if not unknown - returns success if already detected. */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1783 | status = ixgbe_identify_phy_generic(hw); |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1784 | if (status != 0) { |
| 1785 | /* 82599 10GBASE-T requires an external PHY */ |
| 1786 | if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) |
| 1787 | goto out; |
| 1788 | else |
| 1789 | status = ixgbe_identify_sfp_module_generic(hw); |
| 1790 | } |
| 1791 | |
| 1792 | /* Set PHY type none if no PHY detected */ |
| 1793 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 1794 | hw->phy.type = ixgbe_phy_none; |
| 1795 | status = 0; |
| 1796 | } |
| 1797 | |
| 1798 | /* Return error if SFP module has been detected but is not supported */ |
| 1799 | if (hw->phy.type == ixgbe_phy_sfp_unsupported) |
| 1800 | status = IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 1801 | |
| 1802 | out: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1803 | return status; |
| 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type |
| 1808 | * @hw: pointer to hardware structure |
| 1809 | * |
| 1810 | * Determines physical layer capabilities of the current configuration. |
| 1811 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1812 | static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1813 | { |
| 1814 | u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN; |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1815 | u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 1816 | u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2); |
| 1817 | u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK; |
| 1818 | u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK; |
| 1819 | u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK; |
| 1820 | u16 ext_ability = 0; |
PJ Waskiewicz | 1339b9e | 2009-03-13 22:12:29 +0000 | [diff] [blame] | 1821 | u8 comp_codes_10g = 0; |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 1822 | u8 comp_codes_1g = 0; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1823 | |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1824 | hw->phy.ops.identify(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1825 | |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1826 | switch (hw->phy.type) { |
| 1827 | case ixgbe_phy_tn: |
| 1828 | case ixgbe_phy_aq: |
| 1829 | case ixgbe_phy_cu_unknown: |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1830 | hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD, |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1831 | &ext_ability); |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1832 | if (ext_ability & MDIO_PMA_EXTABLE_10GBT) |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1833 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1834 | if (ext_ability & MDIO_PMA_EXTABLE_1000BT) |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1835 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 1836 | if (ext_ability & MDIO_PMA_EXTABLE_100BTX) |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1837 | physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX; |
| 1838 | goto out; |
Emil Tantilov | 21cc5b4 | 2011-02-12 10:52:07 +0000 | [diff] [blame] | 1839 | default: |
| 1840 | break; |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | switch (autoc & IXGBE_AUTOC_LMS_MASK) { |
| 1844 | case IXGBE_AUTOC_LMS_1G_AN: |
| 1845 | case IXGBE_AUTOC_LMS_1G_LINK_NO_AN: |
| 1846 | if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) { |
| 1847 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX | |
| 1848 | IXGBE_PHYSICAL_LAYER_1000BASE_BX; |
| 1849 | goto out; |
| 1850 | } else |
| 1851 | /* SFI mode so read SFP module */ |
| 1852 | goto sfp_check; |
| 1853 | break; |
| 1854 | case IXGBE_AUTOC_LMS_10G_LINK_NO_AN: |
| 1855 | if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4) |
| 1856 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4; |
| 1857 | else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4) |
| 1858 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4; |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 1859 | else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI) |
| 1860 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI; |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1861 | goto out; |
| 1862 | break; |
| 1863 | case IXGBE_AUTOC_LMS_10G_SERIAL: |
| 1864 | if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) { |
| 1865 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR; |
| 1866 | goto out; |
| 1867 | } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) |
| 1868 | goto sfp_check; |
| 1869 | break; |
| 1870 | case IXGBE_AUTOC_LMS_KX4_KX_KR: |
| 1871 | case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN: |
| 1872 | if (autoc & IXGBE_AUTOC_KX_SUPP) |
| 1873 | physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX; |
| 1874 | if (autoc & IXGBE_AUTOC_KX4_SUPP) |
| 1875 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4; |
| 1876 | if (autoc & IXGBE_AUTOC_KR_SUPP) |
| 1877 | physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR; |
| 1878 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1879 | break; |
| 1880 | default: |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1881 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1882 | break; |
| 1883 | } |
| 1884 | |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1885 | sfp_check: |
| 1886 | /* SFP check must be done last since DA modules are sometimes used to |
| 1887 | * test KR mode - we need to id KR mode correctly before SFP module. |
| 1888 | * Call identify_sfp because the pluggable module may have changed */ |
| 1889 | hw->phy.ops.identify_sfp(hw); |
| 1890 | if (hw->phy.sfp_type == ixgbe_sfp_type_not_present) |
| 1891 | goto out; |
| 1892 | |
| 1893 | switch (hw->phy.type) { |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 1894 | case ixgbe_phy_sfp_passive_tyco: |
| 1895 | case ixgbe_phy_sfp_passive_unknown: |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1896 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU; |
| 1897 | break; |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 1898 | case ixgbe_phy_sfp_ftl_active: |
| 1899 | case ixgbe_phy_sfp_active_unknown: |
| 1900 | physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA; |
| 1901 | break; |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1902 | case ixgbe_phy_sfp_avago: |
| 1903 | case ixgbe_phy_sfp_ftl: |
| 1904 | case ixgbe_phy_sfp_intel: |
| 1905 | case ixgbe_phy_sfp_unknown: |
| 1906 | hw->phy.ops.read_i2c_eeprom(hw, |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 1907 | IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g); |
| 1908 | hw->phy.ops.read_i2c_eeprom(hw, |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1909 | IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g); |
| 1910 | if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE) |
| 1911 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR; |
| 1912 | else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE) |
| 1913 | physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR; |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 1914 | else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) |
| 1915 | physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T; |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | default: |
| 1918 | break; |
| 1919 | } |
| 1920 | |
| 1921 | out: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1922 | return physical_layer; |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599 |
| 1927 | * @hw: pointer to hardware structure |
| 1928 | * @regval: register value to write to RXCTRL |
| 1929 | * |
| 1930 | * Enables the Rx DMA unit for 82599 |
| 1931 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1932 | static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1933 | { |
| 1934 | #define IXGBE_MAX_SECRX_POLL 30 |
| 1935 | int i; |
| 1936 | int secrxreg; |
| 1937 | |
| 1938 | /* |
| 1939 | * Workaround for 82599 silicon errata when enabling the Rx datapath. |
| 1940 | * If traffic is incoming before we enable the Rx unit, it could hang |
| 1941 | * the Rx DMA unit. Therefore, make sure the security engine is |
| 1942 | * completely disabled prior to enabling the Rx unit. |
| 1943 | */ |
| 1944 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); |
| 1945 | secrxreg |= IXGBE_SECRXCTRL_RX_DIS; |
| 1946 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); |
| 1947 | for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) { |
| 1948 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT); |
| 1949 | if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY) |
| 1950 | break; |
| 1951 | else |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 1952 | /* Use interrupt-safe sleep just in case */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1953 | udelay(10); |
| 1954 | } |
| 1955 | |
| 1956 | /* For informational purposes only */ |
| 1957 | if (i >= IXGBE_MAX_SECRX_POLL) |
| 1958 | hw_dbg(hw, "Rx unit being enabled before security " |
| 1959 | "path fully disabled. Continuing with init.\n"); |
| 1960 | |
| 1961 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); |
| 1962 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); |
| 1963 | secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS; |
| 1964 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); |
| 1965 | IXGBE_WRITE_FLUSH(hw); |
| 1966 | |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1970 | /** |
| 1971 | * ixgbe_get_device_caps_82599 - Get additional device capabilities |
| 1972 | * @hw: pointer to hardware structure |
| 1973 | * @device_caps: the EEPROM word with the extra device capabilities |
| 1974 | * |
| 1975 | * This function will read the EEPROM location for the device capabilities, |
| 1976 | * and return the word through device_caps. |
| 1977 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1978 | static s32 ixgbe_get_device_caps_82599(struct ixgbe_hw *hw, u16 *device_caps) |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 1979 | { |
| 1980 | hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps); |
| 1981 | |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 1985 | /** |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 1986 | * ixgbe_verify_fw_version_82599 - verify fw version for 82599 |
| 1987 | * @hw: pointer to hardware structure |
| 1988 | * |
| 1989 | * Verifies that installed the firmware version is 0.6 or higher |
| 1990 | * for SFI devices. All 82599 SFI devices should have version 0.6 or higher. |
| 1991 | * |
| 1992 | * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or |
| 1993 | * if the FW version is not supported. |
| 1994 | **/ |
| 1995 | static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw) |
| 1996 | { |
| 1997 | s32 status = IXGBE_ERR_EEPROM_VERSION; |
| 1998 | u16 fw_offset, fw_ptp_cfg_offset; |
| 1999 | u16 fw_version = 0; |
| 2000 | |
| 2001 | /* firmware check is only necessary for SFI devices */ |
| 2002 | if (hw->phy.media_type != ixgbe_media_type_fiber) { |
| 2003 | status = 0; |
| 2004 | goto fw_version_out; |
| 2005 | } |
| 2006 | |
| 2007 | /* get the offset to the Firmware Module block */ |
| 2008 | hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset); |
| 2009 | |
| 2010 | if ((fw_offset == 0) || (fw_offset == 0xFFFF)) |
| 2011 | goto fw_version_out; |
| 2012 | |
| 2013 | /* get the offset to the Pass Through Patch Configuration block */ |
| 2014 | hw->eeprom.ops.read(hw, (fw_offset + |
| 2015 | IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR), |
| 2016 | &fw_ptp_cfg_offset); |
| 2017 | |
| 2018 | if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF)) |
| 2019 | goto fw_version_out; |
| 2020 | |
| 2021 | /* get the firmware version */ |
| 2022 | hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset + |
| 2023 | IXGBE_FW_PATCH_VERSION_4), |
| 2024 | &fw_version); |
| 2025 | |
| 2026 | if (fw_version > 0x5) |
| 2027 | status = 0; |
| 2028 | |
| 2029 | fw_version_out: |
| 2030 | return status; |
| 2031 | } |
| 2032 | |
Emil Tantilov | 0fa6d83 | 2011-03-18 08:18:32 +0000 | [diff] [blame^] | 2033 | /** |
| 2034 | * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state. |
| 2035 | * @hw: pointer to hardware structure |
| 2036 | * |
| 2037 | * Returns true if the LESM FW module is present and enabled. Otherwise |
| 2038 | * returns false. Smart Speed must be disabled if LESM FW module is enabled. |
| 2039 | **/ |
| 2040 | static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw) |
| 2041 | { |
| 2042 | bool lesm_enabled = false; |
| 2043 | u16 fw_offset, fw_lesm_param_offset, fw_lesm_state; |
| 2044 | s32 status; |
| 2045 | |
| 2046 | /* get the offset to the Firmware Module block */ |
| 2047 | status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset); |
| 2048 | |
| 2049 | if ((status != 0) || |
| 2050 | (fw_offset == 0) || (fw_offset == 0xFFFF)) |
| 2051 | goto out; |
| 2052 | |
| 2053 | /* get the offset to the LESM Parameters block */ |
| 2054 | status = hw->eeprom.ops.read(hw, (fw_offset + |
| 2055 | IXGBE_FW_LESM_PARAMETERS_PTR), |
| 2056 | &fw_lesm_param_offset); |
| 2057 | |
| 2058 | if ((status != 0) || |
| 2059 | (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF)) |
| 2060 | goto out; |
| 2061 | |
| 2062 | /* get the lesm state word */ |
| 2063 | status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset + |
| 2064 | IXGBE_FW_LESM_STATE_1), |
| 2065 | &fw_lesm_state); |
| 2066 | |
| 2067 | if ((status == 0) && |
| 2068 | (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED)) |
| 2069 | lesm_enabled = true; |
| 2070 | |
| 2071 | out: |
| 2072 | return lesm_enabled; |
| 2073 | } |
| 2074 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2075 | static struct ixgbe_mac_operations mac_ops_82599 = { |
| 2076 | .init_hw = &ixgbe_init_hw_generic, |
| 2077 | .reset_hw = &ixgbe_reset_hw_82599, |
| 2078 | .start_hw = &ixgbe_start_hw_82599, |
| 2079 | .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, |
| 2080 | .get_media_type = &ixgbe_get_media_type_82599, |
| 2081 | .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599, |
| 2082 | .enable_rx_dma = &ixgbe_enable_rx_dma_82599, |
| 2083 | .get_mac_addr = &ixgbe_get_mac_addr_generic, |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2084 | .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic, |
Peter P Waskiewicz Jr | 0419305 | 2009-04-09 22:28:50 +0000 | [diff] [blame] | 2085 | .get_device_caps = &ixgbe_get_device_caps_82599, |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 2086 | .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2087 | .stop_adapter = &ixgbe_stop_adapter_generic, |
| 2088 | .get_bus_info = &ixgbe_get_bus_info_generic, |
| 2089 | .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, |
| 2090 | .read_analog_reg8 = &ixgbe_read_analog_reg8_82599, |
| 2091 | .write_analog_reg8 = &ixgbe_write_analog_reg8_82599, |
| 2092 | .setup_link = &ixgbe_setup_mac_link_82599, |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2093 | .check_link = &ixgbe_check_mac_link_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2094 | .get_link_capabilities = &ixgbe_get_link_capabilities_82599, |
| 2095 | .led_on = &ixgbe_led_on_generic, |
| 2096 | .led_off = &ixgbe_led_off_generic, |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2097 | .blink_led_start = &ixgbe_blink_led_start_generic, |
| 2098 | .blink_led_stop = &ixgbe_blink_led_stop_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2099 | .set_rar = &ixgbe_set_rar_generic, |
| 2100 | .clear_rar = &ixgbe_clear_rar_generic, |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2101 | .set_vmdq = &ixgbe_set_vmdq_generic, |
| 2102 | .clear_vmdq = &ixgbe_clear_vmdq_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2103 | .init_rx_addrs = &ixgbe_init_rx_addrs_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2104 | .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, |
| 2105 | .enable_mc = &ixgbe_enable_mc_generic, |
| 2106 | .disable_mc = &ixgbe_disable_mc_generic, |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2107 | .clear_vfta = &ixgbe_clear_vfta_generic, |
| 2108 | .set_vfta = &ixgbe_set_vfta_generic, |
| 2109 | .fc_enable = &ixgbe_fc_enable_generic, |
| 2110 | .init_uta_tables = &ixgbe_init_uta_tables_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2111 | .setup_sfp = &ixgbe_setup_sfp_modules_82599, |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 2112 | .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, |
| 2113 | .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 2114 | .acquire_swfw_sync = &ixgbe_acquire_swfw_sync, |
| 2115 | .release_swfw_sync = &ixgbe_release_swfw_sync, |
| 2116 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2117 | }; |
| 2118 | |
| 2119 | static struct ixgbe_eeprom_operations eeprom_ops_82599 = { |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 2120 | .init_params = &ixgbe_init_eeprom_params_generic, |
| 2121 | .read = &ixgbe_read_eerd_generic, |
| 2122 | .write = &ixgbe_write_eeprom_generic, |
| 2123 | .calc_checksum = &ixgbe_calc_eeprom_checksum_generic, |
| 2124 | .validate_checksum = &ixgbe_validate_eeprom_checksum_generic, |
| 2125 | .update_checksum = &ixgbe_update_eeprom_checksum_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2126 | }; |
| 2127 | |
| 2128 | static struct ixgbe_phy_operations phy_ops_82599 = { |
Emil Tantilov | 037c6d0 | 2011-02-25 07:49:39 +0000 | [diff] [blame] | 2129 | .identify = &ixgbe_identify_phy_82599, |
| 2130 | .identify_sfp = &ixgbe_identify_sfp_module_generic, |
| 2131 | .init = &ixgbe_init_phy_ops_82599, |
| 2132 | .reset = &ixgbe_reset_phy_generic, |
| 2133 | .read_reg = &ixgbe_read_phy_reg_generic, |
| 2134 | .write_reg = &ixgbe_write_phy_reg_generic, |
| 2135 | .setup_link = &ixgbe_setup_phy_link_generic, |
| 2136 | .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, |
| 2137 | .read_i2c_byte = &ixgbe_read_i2c_byte_generic, |
| 2138 | .write_i2c_byte = &ixgbe_write_i2c_byte_generic, |
| 2139 | .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, |
| 2140 | .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, |
| 2141 | .check_overtemp = &ixgbe_tn_check_overtemp, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2142 | }; |
| 2143 | |
| 2144 | struct ixgbe_info ixgbe_82599_info = { |
| 2145 | .mac = ixgbe_mac_82599EB, |
| 2146 | .get_invariants = &ixgbe_get_invariants_82599, |
| 2147 | .mac_ops = &mac_ops_82599, |
| 2148 | .eeprom_ops = &eeprom_ops_82599, |
| 2149 | .phy_ops = &phy_ops_82599, |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 2150 | .mbx_ops = &mbx_ops_generic, |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2151 | }; |