Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2014 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [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: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/sched.h> |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 32 | #include <linux/netdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 33 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 34 | #include "ixgbe.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 35 | #include "ixgbe_common.h" |
| 36 | #include "ixgbe_phy.h" |
| 37 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 38 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 39 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); |
| 40 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 41 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw); |
| 42 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw); |
| 43 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 44 | u16 count); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 45 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count); |
| 46 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); |
| 47 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); |
| 48 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 50 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr); |
Emil Tantilov | eb9c3e3 | 2011-03-24 00:57:50 +0000 | [diff] [blame] | 51 | static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg); |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 52 | static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, |
| 53 | u16 words, u16 *data); |
| 54 | static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, |
| 55 | u16 words, u16 *data); |
| 56 | static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw, |
| 57 | u16 offset); |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 58 | static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 61 | * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow |
| 62 | * control |
| 63 | * @hw: pointer to hardware structure |
| 64 | * |
| 65 | * There are several phys that do not support autoneg flow control. This |
| 66 | * function check the device id to see if the associated phy supports |
| 67 | * autoneg flow control. |
| 68 | **/ |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 69 | bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw) |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 70 | { |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 71 | bool supported = false; |
| 72 | ixgbe_link_speed speed; |
| 73 | bool link_up; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 74 | |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 75 | switch (hw->phy.media_type) { |
| 76 | case ixgbe_media_type_fiber: |
| 77 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
| 78 | /* if link is down, assume supported */ |
| 79 | if (link_up) |
| 80 | supported = speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 81 | true : false; |
| 82 | else |
| 83 | supported = true; |
| 84 | break; |
| 85 | case ixgbe_media_type_backplane: |
| 86 | supported = true; |
| 87 | break; |
| 88 | case ixgbe_media_type_copper: |
| 89 | /* only some copper devices support flow control autoneg */ |
| 90 | switch (hw->device_id) { |
| 91 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 92 | case IXGBE_DEV_ID_X540T: |
| 93 | case IXGBE_DEV_ID_X540T1: |
| 94 | supported = true; |
| 95 | break; |
| 96 | default: |
| 97 | break; |
| 98 | } |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 99 | default: |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 100 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 101 | } |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 102 | |
| 103 | return supported; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * ixgbe_setup_fc - Set up flow control |
| 108 | * @hw: pointer to hardware structure |
| 109 | * |
| 110 | * Called at init time to set up flow control. |
| 111 | **/ |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 112 | static s32 ixgbe_setup_fc(struct ixgbe_hw *hw) |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 113 | { |
| 114 | s32 ret_val = 0; |
| 115 | u32 reg = 0, reg_bp = 0; |
| 116 | u16 reg_cu = 0; |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 117 | bool locked = false; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 118 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 119 | /* |
| 120 | * Validate the requested mode. Strict IEEE mode does not allow |
| 121 | * ixgbe_fc_rx_pause because it will cause us to fail at UNH. |
| 122 | */ |
| 123 | if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) { |
| 124 | hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n"); |
| 125 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 126 | goto out; |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * 10gig parts do not have a word in the EEPROM to determine the |
| 131 | * default flow control setting, so we explicitly set it to full. |
| 132 | */ |
| 133 | if (hw->fc.requested_mode == ixgbe_fc_default) |
| 134 | hw->fc.requested_mode = ixgbe_fc_full; |
| 135 | |
| 136 | /* |
| 137 | * Set up the 1G and 10G flow control advertisement registers so the |
| 138 | * HW will be able to do fc autoneg once the cable is plugged in. If |
| 139 | * we link at 10G, the 1G advertisement is harmless and vice versa. |
| 140 | */ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 141 | switch (hw->phy.media_type) { |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 142 | case ixgbe_media_type_backplane: |
| 143 | /* some MAC's need RMW protection on AUTOC */ |
| 144 | ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, ®_bp); |
Don Skidmore | f8cf7a0 | 2014-03-19 09:16:26 +0000 | [diff] [blame] | 145 | if (ret_val) |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 146 | goto out; |
| 147 | |
| 148 | /* only backplane uses autoc so fall though */ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 149 | case ixgbe_media_type_fiber: |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 150 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 151 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 152 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 153 | case ixgbe_media_type_copper: |
| 154 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, |
| 155 | MDIO_MMD_AN, ®_cu); |
| 156 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 157 | default: |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 158 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
| 162 | * The possible values of fc.requested_mode are: |
| 163 | * 0: Flow control is completely disabled |
| 164 | * 1: Rx flow control is enabled (we can receive pause frames, |
| 165 | * but not send pause frames). |
| 166 | * 2: Tx flow control is enabled (we can send pause frames but |
| 167 | * we do not support receiving pause frames). |
| 168 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 169 | * other: Invalid. |
| 170 | */ |
| 171 | switch (hw->fc.requested_mode) { |
| 172 | case ixgbe_fc_none: |
| 173 | /* Flow control completely disabled by software override. */ |
| 174 | reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); |
| 175 | if (hw->phy.media_type == ixgbe_media_type_backplane) |
| 176 | reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE | |
| 177 | IXGBE_AUTOC_ASM_PAUSE); |
| 178 | else if (hw->phy.media_type == ixgbe_media_type_copper) |
| 179 | reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE); |
| 180 | break; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 181 | case ixgbe_fc_tx_pause: |
| 182 | /* |
| 183 | * Tx Flow control is enabled, and Rx Flow control is |
| 184 | * disabled by software override. |
| 185 | */ |
| 186 | reg |= IXGBE_PCS1GANA_ASM_PAUSE; |
| 187 | reg &= ~IXGBE_PCS1GANA_SYM_PAUSE; |
| 188 | if (hw->phy.media_type == ixgbe_media_type_backplane) { |
| 189 | reg_bp |= IXGBE_AUTOC_ASM_PAUSE; |
| 190 | reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE; |
| 191 | } else if (hw->phy.media_type == ixgbe_media_type_copper) { |
| 192 | reg_cu |= IXGBE_TAF_ASM_PAUSE; |
| 193 | reg_cu &= ~IXGBE_TAF_SYM_PAUSE; |
| 194 | } |
| 195 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 196 | case ixgbe_fc_rx_pause: |
| 197 | /* |
| 198 | * Rx Flow control is enabled and Tx Flow control is |
| 199 | * disabled by software override. Since there really |
| 200 | * isn't a way to advertise that we are capable of RX |
| 201 | * Pause ONLY, we will advertise that we support both |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 202 | * symmetric and asymmetric Rx PAUSE, as such we fall |
| 203 | * through to the fc_full statement. Later, we will |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 204 | * disable the adapter's ability to send PAUSE frames. |
| 205 | */ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 206 | case ixgbe_fc_full: |
| 207 | /* Flow control (both Rx and Tx) is enabled by SW override. */ |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 208 | reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 209 | if (hw->phy.media_type == ixgbe_media_type_backplane) |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 210 | reg_bp |= IXGBE_AUTOC_SYM_PAUSE | |
| 211 | IXGBE_AUTOC_ASM_PAUSE; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 212 | else if (hw->phy.media_type == ixgbe_media_type_copper) |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 213 | reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 214 | break; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 215 | default: |
| 216 | hw_dbg(hw, "Flow control param set incorrectly\n"); |
| 217 | ret_val = IXGBE_ERR_CONFIG; |
| 218 | goto out; |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | if (hw->mac.type != ixgbe_mac_X540) { |
| 222 | /* |
| 223 | * Enable auto-negotiation between the MAC & PHY; |
| 224 | * the MAC will advertise clause 37 flow control. |
| 225 | */ |
| 226 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg); |
| 227 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); |
| 228 | |
| 229 | /* Disable AN timeout */ |
| 230 | if (hw->fc.strict_ieee) |
| 231 | reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN; |
| 232 | |
| 233 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg); |
| 234 | hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg); |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * AUTOC restart handles negotiation of 1G and 10G on backplane |
| 239 | * and copper. There is no need to set the PCS1GCTL register. |
| 240 | * |
| 241 | */ |
| 242 | if (hw->phy.media_type == ixgbe_media_type_backplane) { |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 243 | /* Need the SW/FW semaphore around AUTOC writes if 82599 and |
| 244 | * LESM is on, likewise reset_pipeline requries the lock as |
| 245 | * it also writes AUTOC. |
| 246 | */ |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 247 | ret_val = hw->mac.ops.prot_autoc_write(hw, reg_bp, locked); |
| 248 | if (ret_val) |
| 249 | goto out; |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 250 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 251 | } else if ((hw->phy.media_type == ixgbe_media_type_copper) && |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 252 | ixgbe_device_supports_autoneg_fc(hw)) { |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 253 | hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, |
| 254 | MDIO_MMD_AN, reg_cu); |
| 255 | } |
| 256 | |
| 257 | hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg); |
| 258 | out: |
| 259 | return ret_val; |
| 260 | } |
| 261 | |
| 262 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 263 | * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 264 | * @hw: pointer to hardware structure |
| 265 | * |
| 266 | * Starts the hardware by filling the bus info structure and media type, clears |
| 267 | * all on chip counters, initializes receive address registers, multicast |
| 268 | * table, VLAN filter table, calls routine to set up link and flow control |
| 269 | * settings, and leaves transmit and receive units disabled and uninitialized |
| 270 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 271 | s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 272 | { |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 273 | s32 ret_val; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 274 | u32 ctrl_ext; |
| 275 | |
| 276 | /* Set the media type */ |
| 277 | hw->phy.media_type = hw->mac.ops.get_media_type(hw); |
| 278 | |
| 279 | /* Identify the PHY */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 280 | hw->phy.ops.identify(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 281 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 282 | /* Clear the VLAN filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 283 | hw->mac.ops.clear_vfta(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 284 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 285 | /* Clear statistics registers */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 286 | hw->mac.ops.clear_hw_cntrs(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 287 | |
| 288 | /* Set No Snoop Disable */ |
| 289 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 290 | ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS; |
| 291 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 292 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 293 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 294 | /* Setup flow control */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 295 | ret_val = ixgbe_setup_fc(hw); |
| 296 | if (!ret_val) |
| 297 | goto out; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 298 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 299 | /* Clear adapter stopped flag */ |
| 300 | hw->adapter_stopped = false; |
| 301 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 302 | out: |
| 303 | return ret_val; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 307 | * ixgbe_start_hw_gen2 - Init sequence for common device family |
| 308 | * @hw: pointer to hw structure |
| 309 | * |
| 310 | * Performs the init sequence common to the second generation |
| 311 | * of 10 GbE devices. |
| 312 | * Devices in the second generation: |
| 313 | * 82599 |
| 314 | * X540 |
| 315 | **/ |
| 316 | s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw) |
| 317 | { |
| 318 | u32 i; |
Emil Tantilov | 3d5c520 | 2011-03-19 01:32:46 +0000 | [diff] [blame] | 319 | u32 regval; |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 320 | |
| 321 | /* Clear the rate limiters */ |
| 322 | for (i = 0; i < hw->mac.max_tx_queues; i++) { |
| 323 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i); |
| 324 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0); |
| 325 | } |
| 326 | IXGBE_WRITE_FLUSH(hw); |
| 327 | |
Emil Tantilov | 3d5c520 | 2011-03-19 01:32:46 +0000 | [diff] [blame] | 328 | /* Disable relaxed ordering */ |
| 329 | for (i = 0; i < hw->mac.max_tx_queues; i++) { |
| 330 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i)); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 331 | regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN; |
Emil Tantilov | 3d5c520 | 2011-03-19 01:32:46 +0000 | [diff] [blame] | 332 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval); |
| 333 | } |
| 334 | |
| 335 | for (i = 0; i < hw->mac.max_rx_queues; i++) { |
| 336 | regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 337 | regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN | |
| 338 | IXGBE_DCA_RXCTRL_HEAD_WRO_EN); |
Emil Tantilov | 3d5c520 | 2011-03-19 01:32:46 +0000 | [diff] [blame] | 339 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval); |
| 340 | } |
| 341 | |
Emil Tantilov | 7184b7c | 2011-03-18 08:18:22 +0000 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 346 | * ixgbe_init_hw_generic - Generic hardware initialization |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 347 | * @hw: pointer to hardware structure |
| 348 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 349 | * Initialize the hardware by resetting the hardware, filling the bus info |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 350 | * structure and media type, clears all on chip counters, initializes receive |
| 351 | * address registers, multicast table, VLAN filter table, calls routine to set |
| 352 | * up link and flow control settings, and leaves transmit and receive units |
| 353 | * disabled and uninitialized |
| 354 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 355 | s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 356 | { |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 357 | s32 status; |
| 358 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 359 | /* Reset the hardware */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 360 | status = hw->mac.ops.reset_hw(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 361 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 362 | if (status == 0) { |
| 363 | /* Start the HW */ |
| 364 | status = hw->mac.ops.start_hw(hw); |
| 365 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 366 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 367 | return status; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 371 | * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 372 | * @hw: pointer to hardware structure |
| 373 | * |
| 374 | * Clears all hardware statistics counters by reading them from the hardware |
| 375 | * Statistics counters are clear on read. |
| 376 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 377 | s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 378 | { |
| 379 | u16 i = 0; |
| 380 | |
| 381 | IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
| 382 | IXGBE_READ_REG(hw, IXGBE_ILLERRC); |
| 383 | IXGBE_READ_REG(hw, IXGBE_ERRBC); |
| 384 | IXGBE_READ_REG(hw, IXGBE_MSPDC); |
| 385 | for (i = 0; i < 8; i++) |
| 386 | IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 387 | |
| 388 | IXGBE_READ_REG(hw, IXGBE_MLFC); |
| 389 | IXGBE_READ_REG(hw, IXGBE_MRFC); |
| 390 | IXGBE_READ_REG(hw, IXGBE_RLEC); |
| 391 | IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 392 | IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 393 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 394 | IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 395 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 396 | } else { |
| 397 | IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 398 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 399 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 400 | |
| 401 | for (i = 0; i < 8; i++) { |
| 402 | IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 403 | IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 404 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 405 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
| 406 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 407 | } else { |
| 408 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
| 409 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 410 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 411 | } |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 412 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 413 | for (i = 0; i < 8; i++) |
| 414 | IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 415 | IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 416 | IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 417 | IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 418 | IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 419 | IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 420 | IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 421 | IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 422 | IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 423 | IXGBE_READ_REG(hw, IXGBE_MPRC); |
| 424 | IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 425 | IXGBE_READ_REG(hw, IXGBE_GORCL); |
| 426 | IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 427 | IXGBE_READ_REG(hw, IXGBE_GOTCL); |
| 428 | IXGBE_READ_REG(hw, IXGBE_GOTCH); |
Emil Tantilov | f3116f6 | 2011-07-29 06:46:15 +0000 | [diff] [blame] | 429 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 430 | for (i = 0; i < 8; i++) |
| 431 | IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 432 | IXGBE_READ_REG(hw, IXGBE_RUC); |
| 433 | IXGBE_READ_REG(hw, IXGBE_RFC); |
| 434 | IXGBE_READ_REG(hw, IXGBE_ROC); |
| 435 | IXGBE_READ_REG(hw, IXGBE_RJC); |
| 436 | IXGBE_READ_REG(hw, IXGBE_MNGPRC); |
| 437 | IXGBE_READ_REG(hw, IXGBE_MNGPDC); |
| 438 | IXGBE_READ_REG(hw, IXGBE_MNGPTC); |
| 439 | IXGBE_READ_REG(hw, IXGBE_TORL); |
| 440 | IXGBE_READ_REG(hw, IXGBE_TORH); |
| 441 | IXGBE_READ_REG(hw, IXGBE_TPR); |
| 442 | IXGBE_READ_REG(hw, IXGBE_TPT); |
| 443 | IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 444 | IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 445 | IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 446 | IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 447 | IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 448 | IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 449 | IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 450 | IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 451 | for (i = 0; i < 16; i++) { |
| 452 | IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 453 | IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 454 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 455 | IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 456 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); |
| 457 | IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 458 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); |
| 459 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
| 460 | } else { |
| 461 | IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
| 462 | IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 463 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Emil Tantilov | a3aeea0 | 2011-02-26 06:40:11 +0000 | [diff] [blame] | 466 | if (hw->mac.type == ixgbe_mac_X540) { |
| 467 | if (hw->phy.id == 0) |
| 468 | hw->phy.ops.identify(hw); |
Emil Tantilov | c1085b1 | 2011-12-10 08:21:47 +0000 | [diff] [blame] | 469 | hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL, MDIO_MMD_PCS, &i); |
| 470 | hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH, MDIO_MMD_PCS, &i); |
| 471 | hw->phy.ops.read_reg(hw, IXGBE_LDPCECL, MDIO_MMD_PCS, &i); |
| 472 | hw->phy.ops.read_reg(hw, IXGBE_LDPCECH, MDIO_MMD_PCS, &i); |
Emil Tantilov | a3aeea0 | 2011-02-26 06:40:11 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | /** |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 479 | * ixgbe_read_pba_string_generic - Reads part number string from EEPROM |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 480 | * @hw: pointer to hardware structure |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 481 | * @pba_num: stores the part number string from the EEPROM |
| 482 | * @pba_num_size: part number string buffer length |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 483 | * |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 484 | * Reads the part number string from the EEPROM. |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 485 | **/ |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 486 | s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 487 | u32 pba_num_size) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 488 | { |
| 489 | s32 ret_val; |
| 490 | u16 data; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 491 | u16 pba_ptr; |
| 492 | u16 offset; |
| 493 | u16 length; |
| 494 | |
| 495 | if (pba_num == NULL) { |
| 496 | hw_dbg(hw, "PBA string buffer was null\n"); |
| 497 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 498 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 499 | |
| 500 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data); |
| 501 | if (ret_val) { |
| 502 | hw_dbg(hw, "NVM Read Error\n"); |
| 503 | return ret_val; |
| 504 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 505 | |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 506 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 507 | if (ret_val) { |
| 508 | hw_dbg(hw, "NVM Read Error\n"); |
| 509 | return ret_val; |
| 510 | } |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * if data is not ptr guard the PBA must be in legacy format which |
| 514 | * means pba_ptr is actually our second data word for the PBA number |
| 515 | * and we can decode it into an ascii string |
| 516 | */ |
| 517 | if (data != IXGBE_PBANUM_PTR_GUARD) { |
| 518 | hw_dbg(hw, "NVM PBA number is not stored as string\n"); |
| 519 | |
| 520 | /* we will need 11 characters to store the PBA */ |
| 521 | if (pba_num_size < 11) { |
| 522 | hw_dbg(hw, "PBA string buffer too small\n"); |
| 523 | return IXGBE_ERR_NO_SPACE; |
| 524 | } |
| 525 | |
| 526 | /* extract hex string from data and pba_ptr */ |
| 527 | pba_num[0] = (data >> 12) & 0xF; |
| 528 | pba_num[1] = (data >> 8) & 0xF; |
| 529 | pba_num[2] = (data >> 4) & 0xF; |
| 530 | pba_num[3] = data & 0xF; |
| 531 | pba_num[4] = (pba_ptr >> 12) & 0xF; |
| 532 | pba_num[5] = (pba_ptr >> 8) & 0xF; |
| 533 | pba_num[6] = '-'; |
| 534 | pba_num[7] = 0; |
| 535 | pba_num[8] = (pba_ptr >> 4) & 0xF; |
| 536 | pba_num[9] = pba_ptr & 0xF; |
| 537 | |
| 538 | /* put a null character on the end of our string */ |
| 539 | pba_num[10] = '\0'; |
| 540 | |
| 541 | /* switch all the data but the '-' to hex char */ |
| 542 | for (offset = 0; offset < 10; offset++) { |
| 543 | if (pba_num[offset] < 0xA) |
| 544 | pba_num[offset] += '0'; |
| 545 | else if (pba_num[offset] < 0x10) |
| 546 | pba_num[offset] += 'A' - 0xA; |
| 547 | } |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length); |
| 553 | if (ret_val) { |
| 554 | hw_dbg(hw, "NVM Read Error\n"); |
| 555 | return ret_val; |
| 556 | } |
| 557 | |
| 558 | if (length == 0xFFFF || length == 0) { |
| 559 | hw_dbg(hw, "NVM PBA number section invalid length\n"); |
| 560 | return IXGBE_ERR_PBA_SECTION; |
| 561 | } |
| 562 | |
| 563 | /* check if pba_num buffer is big enough */ |
| 564 | if (pba_num_size < (((u32)length * 2) - 1)) { |
| 565 | hw_dbg(hw, "PBA string buffer too small\n"); |
| 566 | return IXGBE_ERR_NO_SPACE; |
| 567 | } |
| 568 | |
| 569 | /* trim pba length from start of string */ |
| 570 | pba_ptr++; |
| 571 | length--; |
| 572 | |
| 573 | for (offset = 0; offset < length; offset++) { |
| 574 | ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data); |
| 575 | if (ret_val) { |
| 576 | hw_dbg(hw, "NVM Read Error\n"); |
| 577 | return ret_val; |
| 578 | } |
| 579 | pba_num[offset * 2] = (u8)(data >> 8); |
| 580 | pba_num[(offset * 2) + 1] = (u8)(data & 0xFF); |
| 581 | } |
| 582 | pba_num[offset * 2] = '\0'; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * ixgbe_get_mac_addr_generic - Generic get MAC address |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 589 | * @hw: pointer to hardware structure |
| 590 | * @mac_addr: Adapter MAC address |
| 591 | * |
| 592 | * Reads the adapter's MAC address from first Receive Address Register (RAR0) |
| 593 | * A reset of the adapter must be performed prior to calling this function |
| 594 | * in order for the MAC address to have been loaded from the EEPROM into RAR0 |
| 595 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 596 | s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 597 | { |
| 598 | u32 rar_high; |
| 599 | u32 rar_low; |
| 600 | u16 i; |
| 601 | |
| 602 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0)); |
| 603 | rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0)); |
| 604 | |
| 605 | for (i = 0; i < 4; i++) |
| 606 | mac_addr[i] = (u8)(rar_low >> (i*8)); |
| 607 | |
| 608 | for (i = 0; i < 2; i++) |
| 609 | mac_addr[i+4] = (u8)(rar_high >> (i*8)); |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Jacob Keller | ef1889d | 2013-02-15 09:18:15 +0000 | [diff] [blame] | 614 | enum ixgbe_bus_width ixgbe_convert_bus_width(u16 link_status) |
| 615 | { |
| 616 | switch (link_status & IXGBE_PCI_LINK_WIDTH) { |
| 617 | case IXGBE_PCI_LINK_WIDTH_1: |
| 618 | return ixgbe_bus_width_pcie_x1; |
| 619 | case IXGBE_PCI_LINK_WIDTH_2: |
| 620 | return ixgbe_bus_width_pcie_x2; |
| 621 | case IXGBE_PCI_LINK_WIDTH_4: |
| 622 | return ixgbe_bus_width_pcie_x4; |
| 623 | case IXGBE_PCI_LINK_WIDTH_8: |
| 624 | return ixgbe_bus_width_pcie_x8; |
| 625 | default: |
| 626 | return ixgbe_bus_width_unknown; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | enum ixgbe_bus_speed ixgbe_convert_bus_speed(u16 link_status) |
| 631 | { |
| 632 | switch (link_status & IXGBE_PCI_LINK_SPEED) { |
| 633 | case IXGBE_PCI_LINK_SPEED_2500: |
| 634 | return ixgbe_bus_speed_2500; |
| 635 | case IXGBE_PCI_LINK_SPEED_5000: |
| 636 | return ixgbe_bus_speed_5000; |
| 637 | case IXGBE_PCI_LINK_SPEED_8000: |
| 638 | return ixgbe_bus_speed_8000; |
| 639 | default: |
| 640 | return ixgbe_bus_speed_unknown; |
| 641 | } |
| 642 | } |
| 643 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 644 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 645 | * ixgbe_get_bus_info_generic - Generic set PCI bus info |
| 646 | * @hw: pointer to hardware structure |
| 647 | * |
| 648 | * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure |
| 649 | **/ |
| 650 | s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw) |
| 651 | { |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 652 | u16 link_status; |
| 653 | |
| 654 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 655 | |
| 656 | /* Get the negotiated link width and speed from PCI config space */ |
Jacob Keller | 0d7c6e0 | 2014-02-22 01:23:58 +0000 | [diff] [blame] | 657 | link_status = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_LINK_STATUS); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 658 | |
Jacob Keller | ef1889d | 2013-02-15 09:18:15 +0000 | [diff] [blame] | 659 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 660 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 661 | |
Jacob Keller | 0d7c6e0 | 2014-02-22 01:23:58 +0000 | [diff] [blame] | 662 | hw->mac.ops.set_lan_id(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices |
| 669 | * @hw: pointer to the HW structure |
| 670 | * |
| 671 | * Determines the LAN function id by reading memory-mapped registers |
| 672 | * and swaps the port value if requested. |
| 673 | **/ |
| 674 | void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw) |
| 675 | { |
| 676 | struct ixgbe_bus_info *bus = &hw->bus; |
| 677 | u32 reg; |
| 678 | |
| 679 | reg = IXGBE_READ_REG(hw, IXGBE_STATUS); |
| 680 | bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT; |
| 681 | bus->lan_id = bus->func; |
| 682 | |
| 683 | /* check for a port swap */ |
| 684 | reg = IXGBE_READ_REG(hw, IXGBE_FACTPS); |
| 685 | if (reg & IXGBE_FACTPS_LFS) |
| 686 | bus->func ^= 0x1; |
| 687 | } |
| 688 | |
| 689 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 690 | * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 691 | * @hw: pointer to hardware structure |
| 692 | * |
| 693 | * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, |
| 694 | * disables transmit and receive units. The adapter_stopped flag is used by |
| 695 | * the shared code and drivers to determine if the adapter is in a stopped |
| 696 | * state and should not touch the hardware. |
| 697 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 698 | s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 699 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 700 | u32 reg_val; |
| 701 | u16 i; |
| 702 | |
| 703 | /* |
| 704 | * Set the adapter_stopped flag so other driver functions stop touching |
| 705 | * the hardware |
| 706 | */ |
| 707 | hw->adapter_stopped = true; |
| 708 | |
| 709 | /* Disable the receive unit */ |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 710 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 711 | |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 712 | /* Clear interrupt mask to stop interrupts from being generated */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 713 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 714 | |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 715 | /* Clear any pending interrupts, flush previous writes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 716 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 717 | |
| 718 | /* Disable the transmit unit. Each queue must be disabled. */ |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 719 | for (i = 0; i < hw->mac.max_tx_queues; i++) |
| 720 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH); |
| 721 | |
| 722 | /* Disable the receive unit by stopping each queue */ |
| 723 | for (i = 0; i < hw->mac.max_rx_queues; i++) { |
| 724 | reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 725 | reg_val &= ~IXGBE_RXDCTL_ENABLE; |
| 726 | reg_val |= IXGBE_RXDCTL_SWFLSH; |
| 727 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 730 | /* flush all queues disables */ |
| 731 | IXGBE_WRITE_FLUSH(hw); |
| 732 | usleep_range(1000, 2000); |
| 733 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 734 | /* |
| 735 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master |
| 736 | * access and verify no pending requests |
| 737 | */ |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 738 | return ixgbe_disable_pcie_master(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 742 | * ixgbe_led_on_generic - Turns on the software controllable LEDs. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 743 | * @hw: pointer to hardware structure |
| 744 | * @index: led number to turn on |
| 745 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 746 | s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 747 | { |
| 748 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 749 | |
| 750 | /* To turn on the LED, set mode to ON. */ |
| 751 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 752 | led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index); |
| 753 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 754 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 760 | * ixgbe_led_off_generic - Turns off the software controllable LEDs. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 761 | * @hw: pointer to hardware structure |
| 762 | * @index: led number to turn off |
| 763 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 764 | s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 765 | { |
| 766 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 767 | |
| 768 | /* To turn off the LED, set mode to OFF. */ |
| 769 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 770 | led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index); |
| 771 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 772 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 777 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 778 | * ixgbe_init_eeprom_params_generic - Initialize EEPROM params |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 779 | * @hw: pointer to hardware structure |
| 780 | * |
| 781 | * Initializes the EEPROM parameters ixgbe_eeprom_info within the |
| 782 | * ixgbe_hw struct in order to set up EEPROM access. |
| 783 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 784 | s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 785 | { |
| 786 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; |
| 787 | u32 eec; |
| 788 | u16 eeprom_size; |
| 789 | |
| 790 | if (eeprom->type == ixgbe_eeprom_uninitialized) { |
| 791 | eeprom->type = ixgbe_eeprom_none; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 792 | /* Set default semaphore delay to 10ms which is a well |
| 793 | * tested value */ |
| 794 | eeprom->semaphore_delay = 10; |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 795 | /* Clear EEPROM page size, it will be initialized as needed */ |
| 796 | eeprom->word_page_size = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 797 | |
| 798 | /* |
| 799 | * Check for EEPROM present first. |
| 800 | * If not present leave as none |
| 801 | */ |
| 802 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 803 | if (eec & IXGBE_EEC_PRES) { |
| 804 | eeprom->type = ixgbe_eeprom_spi; |
| 805 | |
| 806 | /* |
| 807 | * SPI EEPROM is assumed here. This code would need to |
| 808 | * change if a future EEPROM is not SPI. |
| 809 | */ |
| 810 | eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> |
| 811 | IXGBE_EEC_SIZE_SHIFT); |
| 812 | eeprom->word_size = 1 << (eeprom_size + |
| 813 | IXGBE_EEPROM_WORD_SIZE_SHIFT); |
| 814 | } |
| 815 | |
| 816 | if (eec & IXGBE_EEC_ADDR_SIZE) |
| 817 | eeprom->address_bits = 16; |
| 818 | else |
| 819 | eeprom->address_bits = 8; |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 820 | hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: %d\n", |
| 821 | eeprom->type, eeprom->word_size, eeprom->address_bits); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | /** |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 828 | * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang |
| 829 | * @hw: pointer to hardware structure |
| 830 | * @offset: offset within the EEPROM to write |
| 831 | * @words: number of words |
| 832 | * @data: 16 bit word(s) to write to EEPROM |
| 833 | * |
| 834 | * Reads 16 bit word(s) from EEPROM through bit-bang method |
| 835 | **/ |
| 836 | s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, |
| 837 | u16 words, u16 *data) |
| 838 | { |
| 839 | s32 status = 0; |
| 840 | u16 i, count; |
| 841 | |
| 842 | hw->eeprom.ops.init_params(hw); |
| 843 | |
| 844 | if (words == 0) { |
| 845 | status = IXGBE_ERR_INVALID_ARGUMENT; |
| 846 | goto out; |
| 847 | } |
| 848 | |
| 849 | if (offset + words > hw->eeprom.word_size) { |
| 850 | status = IXGBE_ERR_EEPROM; |
| 851 | goto out; |
| 852 | } |
| 853 | |
| 854 | /* |
| 855 | * The EEPROM page size cannot be queried from the chip. We do lazy |
| 856 | * initialization. It is worth to do that when we write large buffer. |
| 857 | */ |
| 858 | if ((hw->eeprom.word_page_size == 0) && |
| 859 | (words > IXGBE_EEPROM_PAGE_SIZE_MAX)) |
| 860 | ixgbe_detect_eeprom_page_size_generic(hw, offset); |
| 861 | |
| 862 | /* |
| 863 | * We cannot hold synchronization semaphores for too long |
| 864 | * to avoid other entity starvation. However it is more efficient |
| 865 | * to read in bursts than synchronizing access for each word. |
| 866 | */ |
| 867 | for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) { |
| 868 | count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ? |
| 869 | IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i); |
| 870 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i, |
| 871 | count, &data[i]); |
| 872 | |
| 873 | if (status != 0) |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | out: |
| 878 | return status; |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 883 | * @hw: pointer to hardware structure |
| 884 | * @offset: offset within the EEPROM to be written to |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 885 | * @words: number of word(s) |
| 886 | * @data: 16 bit word(s) to be written to the EEPROM |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 887 | * |
| 888 | * If ixgbe_eeprom_update_checksum is not called after this function, the |
| 889 | * EEPROM will most likely contain an invalid checksum. |
| 890 | **/ |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 891 | static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, |
| 892 | u16 words, u16 *data) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 893 | { |
| 894 | s32 status; |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 895 | u16 word; |
| 896 | u16 page_size; |
| 897 | u16 i; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 898 | u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI; |
| 899 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 900 | /* Prepare the EEPROM for writing */ |
| 901 | status = ixgbe_acquire_eeprom(hw); |
| 902 | |
| 903 | if (status == 0) { |
| 904 | if (ixgbe_ready_eeprom(hw) != 0) { |
| 905 | ixgbe_release_eeprom(hw); |
| 906 | status = IXGBE_ERR_EEPROM; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | if (status == 0) { |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 911 | for (i = 0; i < words; i++) { |
| 912 | ixgbe_standby_eeprom(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 913 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 914 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 915 | ixgbe_shift_out_eeprom_bits(hw, |
| 916 | IXGBE_EEPROM_WREN_OPCODE_SPI, |
| 917 | IXGBE_EEPROM_OPCODE_BITS); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 918 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 919 | ixgbe_standby_eeprom(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 920 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 921 | /* |
| 922 | * Some SPI eeproms use the 8th address bit embedded |
| 923 | * in the opcode |
| 924 | */ |
| 925 | if ((hw->eeprom.address_bits == 8) && |
| 926 | ((offset + i) >= 128)) |
| 927 | write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 928 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 929 | /* Send the Write command (8-bit opcode + addr) */ |
| 930 | ixgbe_shift_out_eeprom_bits(hw, write_opcode, |
| 931 | IXGBE_EEPROM_OPCODE_BITS); |
| 932 | ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2), |
| 933 | hw->eeprom.address_bits); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 934 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 935 | page_size = hw->eeprom.word_page_size; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 936 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 937 | /* Send the data in burst via SPI*/ |
| 938 | do { |
| 939 | word = data[i]; |
| 940 | word = (word >> 8) | (word << 8); |
| 941 | ixgbe_shift_out_eeprom_bits(hw, word, 16); |
| 942 | |
| 943 | if (page_size == 0) |
| 944 | break; |
| 945 | |
| 946 | /* do not wrap around page */ |
| 947 | if (((offset + i) & (page_size - 1)) == |
| 948 | (page_size - 1)) |
| 949 | break; |
| 950 | } while (++i < words); |
| 951 | |
| 952 | ixgbe_standby_eeprom(hw); |
| 953 | usleep_range(10000, 20000); |
| 954 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 955 | /* Done with writing - release the EEPROM */ |
| 956 | ixgbe_release_eeprom(hw); |
| 957 | } |
| 958 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 959 | return status; |
| 960 | } |
| 961 | |
| 962 | /** |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 963 | * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 964 | * @hw: pointer to hardware structure |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 965 | * @offset: offset within the EEPROM to be written to |
| 966 | * @data: 16 bit word to be written to the EEPROM |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 967 | * |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 968 | * If ixgbe_eeprom_update_checksum is not called after this function, the |
| 969 | * EEPROM will most likely contain an invalid checksum. |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 970 | **/ |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 971 | s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 972 | { |
| 973 | s32 status; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 974 | |
| 975 | hw->eeprom.ops.init_params(hw); |
| 976 | |
| 977 | if (offset >= hw->eeprom.word_size) { |
| 978 | status = IXGBE_ERR_EEPROM; |
| 979 | goto out; |
| 980 | } |
| 981 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 982 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data); |
| 983 | |
| 984 | out: |
| 985 | return status; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang |
| 990 | * @hw: pointer to hardware structure |
| 991 | * @offset: offset within the EEPROM to be read |
| 992 | * @words: number of word(s) |
| 993 | * @data: read 16 bit words(s) from EEPROM |
| 994 | * |
| 995 | * Reads 16 bit word(s) from EEPROM through bit-bang method |
| 996 | **/ |
| 997 | s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, |
| 998 | u16 words, u16 *data) |
| 999 | { |
| 1000 | s32 status = 0; |
| 1001 | u16 i, count; |
| 1002 | |
| 1003 | hw->eeprom.ops.init_params(hw); |
| 1004 | |
| 1005 | if (words == 0) { |
| 1006 | status = IXGBE_ERR_INVALID_ARGUMENT; |
| 1007 | goto out; |
| 1008 | } |
| 1009 | |
| 1010 | if (offset + words > hw->eeprom.word_size) { |
| 1011 | status = IXGBE_ERR_EEPROM; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * We cannot hold synchronization semaphores for too long |
| 1017 | * to avoid other entity starvation. However it is more efficient |
| 1018 | * to read in bursts than synchronizing access for each word. |
| 1019 | */ |
| 1020 | for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) { |
| 1021 | count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ? |
| 1022 | IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i); |
| 1023 | |
| 1024 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i, |
| 1025 | count, &data[i]); |
| 1026 | |
| 1027 | if (status != 0) |
| 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | out: |
| 1032 | return status; |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang |
| 1037 | * @hw: pointer to hardware structure |
| 1038 | * @offset: offset within the EEPROM to be read |
| 1039 | * @words: number of word(s) |
| 1040 | * @data: read 16 bit word(s) from EEPROM |
| 1041 | * |
| 1042 | * Reads 16 bit word(s) from EEPROM through bit-bang method |
| 1043 | **/ |
| 1044 | static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset, |
| 1045 | u16 words, u16 *data) |
| 1046 | { |
| 1047 | s32 status; |
| 1048 | u16 word_in; |
| 1049 | u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI; |
| 1050 | u16 i; |
| 1051 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1052 | /* Prepare the EEPROM for reading */ |
| 1053 | status = ixgbe_acquire_eeprom(hw); |
| 1054 | |
| 1055 | if (status == 0) { |
| 1056 | if (ixgbe_ready_eeprom(hw) != 0) { |
| 1057 | ixgbe_release_eeprom(hw); |
| 1058 | status = IXGBE_ERR_EEPROM; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | if (status == 0) { |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1063 | for (i = 0; i < words; i++) { |
| 1064 | ixgbe_standby_eeprom(hw); |
| 1065 | /* |
| 1066 | * Some SPI eeproms use the 8th address bit embedded |
| 1067 | * in the opcode |
| 1068 | */ |
| 1069 | if ((hw->eeprom.address_bits == 8) && |
| 1070 | ((offset + i) >= 128)) |
| 1071 | read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1072 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1073 | /* Send the READ command (opcode + addr) */ |
| 1074 | ixgbe_shift_out_eeprom_bits(hw, read_opcode, |
| 1075 | IXGBE_EEPROM_OPCODE_BITS); |
| 1076 | ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2), |
| 1077 | hw->eeprom.address_bits); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1078 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1079 | /* Read the data. */ |
| 1080 | word_in = ixgbe_shift_in_eeprom_bits(hw, 16); |
| 1081 | data[i] = (word_in >> 8) | (word_in << 8); |
| 1082 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1083 | |
| 1084 | /* End this read operation */ |
| 1085 | ixgbe_release_eeprom(hw); |
| 1086 | } |
| 1087 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1088 | return status; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang |
| 1093 | * @hw: pointer to hardware structure |
| 1094 | * @offset: offset within the EEPROM to be read |
| 1095 | * @data: read 16 bit value from EEPROM |
| 1096 | * |
| 1097 | * Reads 16 bit value from EEPROM through bit-bang method |
| 1098 | **/ |
| 1099 | s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, |
| 1100 | u16 *data) |
| 1101 | { |
| 1102 | s32 status; |
| 1103 | |
| 1104 | hw->eeprom.ops.init_params(hw); |
| 1105 | |
| 1106 | if (offset >= hw->eeprom.word_size) { |
| 1107 | status = IXGBE_ERR_EEPROM; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
| 1111 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data); |
| 1112 | |
| 1113 | out: |
| 1114 | return status; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD |
| 1119 | * @hw: pointer to hardware structure |
| 1120 | * @offset: offset of word in the EEPROM to read |
| 1121 | * @words: number of word(s) |
| 1122 | * @data: 16 bit word(s) from the EEPROM |
| 1123 | * |
| 1124 | * Reads a 16 bit word(s) from the EEPROM using the EERD register. |
| 1125 | **/ |
| 1126 | s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset, |
| 1127 | u16 words, u16 *data) |
| 1128 | { |
| 1129 | u32 eerd; |
| 1130 | s32 status = 0; |
| 1131 | u32 i; |
| 1132 | |
| 1133 | hw->eeprom.ops.init_params(hw); |
| 1134 | |
| 1135 | if (words == 0) { |
| 1136 | status = IXGBE_ERR_INVALID_ARGUMENT; |
| 1137 | goto out; |
| 1138 | } |
| 1139 | |
| 1140 | if (offset >= hw->eeprom.word_size) { |
| 1141 | status = IXGBE_ERR_EEPROM; |
| 1142 | goto out; |
| 1143 | } |
| 1144 | |
| 1145 | for (i = 0; i < words; i++) { |
Emil Tantilov | d011157 | 2013-02-05 09:43:26 +0000 | [diff] [blame] | 1146 | eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1147 | IXGBE_EEPROM_RW_REG_START; |
| 1148 | |
| 1149 | IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); |
| 1150 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ); |
| 1151 | |
| 1152 | if (status == 0) { |
| 1153 | data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >> |
| 1154 | IXGBE_EEPROM_RW_REG_DATA); |
| 1155 | } else { |
| 1156 | hw_dbg(hw, "Eeprom read timed out\n"); |
| 1157 | goto out; |
| 1158 | } |
| 1159 | } |
| 1160 | out: |
| 1161 | return status; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size |
| 1166 | * @hw: pointer to hardware structure |
| 1167 | * @offset: offset within the EEPROM to be used as a scratch pad |
| 1168 | * |
| 1169 | * Discover EEPROM page size by writing marching data at given offset. |
| 1170 | * This function is called only when we are writing a new large buffer |
| 1171 | * at given offset so the data would be overwritten anyway. |
| 1172 | **/ |
| 1173 | static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw, |
| 1174 | u16 offset) |
| 1175 | { |
| 1176 | u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX]; |
| 1177 | s32 status = 0; |
| 1178 | u16 i; |
| 1179 | |
| 1180 | for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++) |
| 1181 | data[i] = i; |
| 1182 | |
| 1183 | hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX; |
| 1184 | status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, |
| 1185 | IXGBE_EEPROM_PAGE_SIZE_MAX, data); |
| 1186 | hw->eeprom.word_page_size = 0; |
| 1187 | if (status != 0) |
| 1188 | goto out; |
| 1189 | |
| 1190 | status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data); |
| 1191 | if (status != 0) |
| 1192 | goto out; |
| 1193 | |
| 1194 | /* |
| 1195 | * When writing in burst more than the actual page size |
| 1196 | * EEPROM address wraps around current page. |
| 1197 | */ |
| 1198 | hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0]; |
| 1199 | |
Jakub Kicinski | c5ffe7e | 2014-04-02 10:33:22 +0000 | [diff] [blame] | 1200 | hw_dbg(hw, "Detected EEPROM page size = %d words.\n", |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1201 | hw->eeprom.word_page_size); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1202 | out: |
| 1203 | return status; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1207 | * ixgbe_read_eerd_generic - Read EEPROM word using EERD |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1208 | * @hw: pointer to hardware structure |
| 1209 | * @offset: offset of word in the EEPROM to read |
| 1210 | * @data: word read from the EEPROM |
| 1211 | * |
| 1212 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 1213 | **/ |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1214 | s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1215 | { |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1216 | return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data); |
| 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR |
| 1221 | * @hw: pointer to hardware structure |
| 1222 | * @offset: offset of word in the EEPROM to write |
| 1223 | * @words: number of words |
| 1224 | * @data: word(s) write to the EEPROM |
| 1225 | * |
| 1226 | * Write a 16 bit word(s) to the EEPROM using the EEWR register. |
| 1227 | **/ |
| 1228 | s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset, |
| 1229 | u16 words, u16 *data) |
| 1230 | { |
| 1231 | u32 eewr; |
| 1232 | s32 status = 0; |
| 1233 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1234 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1235 | hw->eeprom.ops.init_params(hw); |
| 1236 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1237 | if (words == 0) { |
| 1238 | status = IXGBE_ERR_INVALID_ARGUMENT; |
| 1239 | goto out; |
| 1240 | } |
| 1241 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1242 | if (offset >= hw->eeprom.word_size) { |
| 1243 | status = IXGBE_ERR_EEPROM; |
| 1244 | goto out; |
| 1245 | } |
| 1246 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1247 | for (i = 0; i < words; i++) { |
| 1248 | eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) | |
| 1249 | (data[i] << IXGBE_EEPROM_RW_REG_DATA) | |
| 1250 | IXGBE_EEPROM_RW_REG_START; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1251 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1252 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE); |
| 1253 | if (status != 0) { |
| 1254 | hw_dbg(hw, "Eeprom write EEWR timed out\n"); |
| 1255 | goto out; |
| 1256 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1257 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1258 | IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr); |
| 1259 | |
| 1260 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE); |
| 1261 | if (status != 0) { |
| 1262 | hw_dbg(hw, "Eeprom write EEWR timed out\n"); |
| 1263 | goto out; |
| 1264 | } |
| 1265 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1266 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1267 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1268 | return status; |
| 1269 | } |
| 1270 | |
| 1271 | /** |
Emil Tantilov | eb9c3e3 | 2011-03-24 00:57:50 +0000 | [diff] [blame] | 1272 | * ixgbe_write_eewr_generic - Write EEPROM word using EEWR |
| 1273 | * @hw: pointer to hardware structure |
| 1274 | * @offset: offset of word in the EEPROM to write |
| 1275 | * @data: word write to the EEPROM |
| 1276 | * |
| 1277 | * Write a 16 bit word to the EEPROM using the EEWR register. |
| 1278 | **/ |
| 1279 | s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data) |
| 1280 | { |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 1281 | return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data); |
Emil Tantilov | eb9c3e3 | 2011-03-24 00:57:50 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | /** |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1285 | * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1286 | * @hw: pointer to hardware structure |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1287 | * @ee_reg: EEPROM flag for polling |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1288 | * |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1289 | * Polls the status bit (bit 1) of the EERD or EEWR to determine when the |
| 1290 | * read or write is done respectively. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1291 | **/ |
Emil Tantilov | eb9c3e3 | 2011-03-24 00:57:50 +0000 | [diff] [blame] | 1292 | static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1293 | { |
| 1294 | u32 i; |
| 1295 | u32 reg; |
| 1296 | s32 status = IXGBE_ERR_EEPROM; |
| 1297 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 1298 | for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) { |
| 1299 | if (ee_reg == IXGBE_NVM_POLL_READ) |
| 1300 | reg = IXGBE_READ_REG(hw, IXGBE_EERD); |
| 1301 | else |
| 1302 | reg = IXGBE_READ_REG(hw, IXGBE_EEWR); |
| 1303 | |
| 1304 | if (reg & IXGBE_EEPROM_RW_REG_DONE) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1305 | status = 0; |
| 1306 | break; |
| 1307 | } |
| 1308 | udelay(5); |
| 1309 | } |
| 1310 | return status; |
| 1311 | } |
| 1312 | |
| 1313 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1314 | * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang |
| 1315 | * @hw: pointer to hardware structure |
| 1316 | * |
| 1317 | * Prepares EEPROM for access using bit-bang method. This function should |
| 1318 | * be called before issuing a command to the EEPROM. |
| 1319 | **/ |
| 1320 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw) |
| 1321 | { |
| 1322 | s32 status = 0; |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1323 | u32 eec; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1324 | u32 i; |
| 1325 | |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 1326 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1327 | status = IXGBE_ERR_SWFW_SYNC; |
| 1328 | |
| 1329 | if (status == 0) { |
| 1330 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1331 | |
| 1332 | /* Request EEPROM Access */ |
| 1333 | eec |= IXGBE_EEC_REQ; |
| 1334 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1335 | |
| 1336 | for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) { |
| 1337 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1338 | if (eec & IXGBE_EEC_GNT) |
| 1339 | break; |
| 1340 | udelay(5); |
| 1341 | } |
| 1342 | |
| 1343 | /* Release if grant not acquired */ |
| 1344 | if (!(eec & IXGBE_EEC_GNT)) { |
| 1345 | eec &= ~IXGBE_EEC_REQ; |
| 1346 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1347 | hw_dbg(hw, "Could not acquire EEPROM grant\n"); |
| 1348 | |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 1349 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1350 | status = IXGBE_ERR_EEPROM; |
| 1351 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1352 | |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1353 | /* Setup EEPROM for Read/Write */ |
| 1354 | if (status == 0) { |
| 1355 | /* Clear CS and SK */ |
| 1356 | eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK); |
| 1357 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1358 | IXGBE_WRITE_FLUSH(hw); |
| 1359 | udelay(1); |
| 1360 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1361 | } |
| 1362 | return status; |
| 1363 | } |
| 1364 | |
| 1365 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1366 | * ixgbe_get_eeprom_semaphore - Get hardware semaphore |
| 1367 | * @hw: pointer to hardware structure |
| 1368 | * |
| 1369 | * Sets the hardware semaphores so EEPROM access can occur for bit-bang method |
| 1370 | **/ |
| 1371 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw) |
| 1372 | { |
| 1373 | s32 status = IXGBE_ERR_EEPROM; |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1374 | u32 timeout = 2000; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1375 | u32 i; |
| 1376 | u32 swsm; |
| 1377 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1378 | /* Get SMBI software semaphore between device drivers first */ |
| 1379 | for (i = 0; i < timeout; i++) { |
| 1380 | /* |
| 1381 | * If the SMBI bit is 0 when we read it, then the bit will be |
| 1382 | * set and we have the semaphore |
| 1383 | */ |
| 1384 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 1385 | if (!(swsm & IXGBE_SWSM_SMBI)) { |
| 1386 | status = 0; |
| 1387 | break; |
| 1388 | } |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1389 | udelay(50); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Emil Tantilov | 51275d3 | 2011-04-08 01:23:59 +0000 | [diff] [blame] | 1392 | if (i == timeout) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1393 | hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore not granted.\n"); |
Emil Tantilov | 51275d3 | 2011-04-08 01:23:59 +0000 | [diff] [blame] | 1394 | /* |
| 1395 | * this release is particularly important because our attempts |
| 1396 | * above to get the semaphore may have succeeded, and if there |
| 1397 | * was a timeout, we should unconditionally clear the semaphore |
| 1398 | * bits to free the driver to make progress |
| 1399 | */ |
| 1400 | ixgbe_release_eeprom_semaphore(hw); |
| 1401 | |
| 1402 | udelay(50); |
| 1403 | /* |
| 1404 | * one last try |
| 1405 | * If the SMBI bit is 0 when we read it, then the bit will be |
| 1406 | * set and we have the semaphore |
| 1407 | */ |
| 1408 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 1409 | if (!(swsm & IXGBE_SWSM_SMBI)) |
| 1410 | status = 0; |
| 1411 | } |
| 1412 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1413 | /* Now get the semaphore between SW/FW through the SWESMBI bit */ |
| 1414 | if (status == 0) { |
| 1415 | for (i = 0; i < timeout; i++) { |
| 1416 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 1417 | |
| 1418 | /* Set the SW EEPROM semaphore bit to request access */ |
| 1419 | swsm |= IXGBE_SWSM_SWESMBI; |
| 1420 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); |
| 1421 | |
| 1422 | /* |
| 1423 | * If we set the bit successfully then we got the |
| 1424 | * semaphore. |
| 1425 | */ |
| 1426 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 1427 | if (swsm & IXGBE_SWSM_SWESMBI) |
| 1428 | break; |
| 1429 | |
| 1430 | udelay(50); |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | * Release semaphores and return error if SW EEPROM semaphore |
| 1435 | * was not granted because we don't have access to the EEPROM |
| 1436 | */ |
| 1437 | if (i >= timeout) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1438 | hw_dbg(hw, "SWESMBI Software EEPROM semaphore not granted.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1439 | ixgbe_release_eeprom_semaphore(hw); |
| 1440 | status = IXGBE_ERR_EEPROM; |
| 1441 | } |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1442 | } else { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1443 | hw_dbg(hw, "Software semaphore SMBI between device drivers not granted.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | return status; |
| 1447 | } |
| 1448 | |
| 1449 | /** |
| 1450 | * ixgbe_release_eeprom_semaphore - Release hardware semaphore |
| 1451 | * @hw: pointer to hardware structure |
| 1452 | * |
| 1453 | * This function clears hardware semaphore bits. |
| 1454 | **/ |
| 1455 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw) |
| 1456 | { |
| 1457 | u32 swsm; |
| 1458 | |
| 1459 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 1460 | |
| 1461 | /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */ |
| 1462 | swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI); |
| 1463 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 1464 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1468 | * ixgbe_ready_eeprom - Polls for EEPROM ready |
| 1469 | * @hw: pointer to hardware structure |
| 1470 | **/ |
| 1471 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw) |
| 1472 | { |
| 1473 | s32 status = 0; |
| 1474 | u16 i; |
| 1475 | u8 spi_stat_reg; |
| 1476 | |
| 1477 | /* |
| 1478 | * Read "Status Register" repeatedly until the LSB is cleared. The |
| 1479 | * EEPROM will signal that the command has been completed by clearing |
| 1480 | * bit 0 of the internal status register. If it's not cleared within |
| 1481 | * 5 milliseconds, then error out. |
| 1482 | */ |
| 1483 | for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) { |
| 1484 | ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1485 | IXGBE_EEPROM_OPCODE_BITS); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1486 | spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8); |
| 1487 | if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI)) |
| 1488 | break; |
| 1489 | |
| 1490 | udelay(5); |
| 1491 | ixgbe_standby_eeprom(hw); |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1492 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1493 | |
| 1494 | /* |
| 1495 | * On some parts, SPI write time could vary from 0-20mSec on 3.3V |
| 1496 | * devices (and only 0-5mSec on 5V devices) |
| 1497 | */ |
| 1498 | if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) { |
| 1499 | hw_dbg(hw, "SPI EEPROM Status error\n"); |
| 1500 | status = IXGBE_ERR_EEPROM; |
| 1501 | } |
| 1502 | |
| 1503 | return status; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
| 1507 | * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state |
| 1508 | * @hw: pointer to hardware structure |
| 1509 | **/ |
| 1510 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw) |
| 1511 | { |
| 1512 | u32 eec; |
| 1513 | |
| 1514 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1515 | |
| 1516 | /* Toggle CS to flush commands */ |
| 1517 | eec |= IXGBE_EEC_CS; |
| 1518 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1519 | IXGBE_WRITE_FLUSH(hw); |
| 1520 | udelay(1); |
| 1521 | eec &= ~IXGBE_EEC_CS; |
| 1522 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1523 | IXGBE_WRITE_FLUSH(hw); |
| 1524 | udelay(1); |
| 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM. |
| 1529 | * @hw: pointer to hardware structure |
| 1530 | * @data: data to send to the EEPROM |
| 1531 | * @count: number of bits to shift out |
| 1532 | **/ |
| 1533 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1534 | u16 count) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1535 | { |
| 1536 | u32 eec; |
| 1537 | u32 mask; |
| 1538 | u32 i; |
| 1539 | |
| 1540 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1541 | |
| 1542 | /* |
| 1543 | * Mask is used to shift "count" bits of "data" out to the EEPROM |
| 1544 | * one bit at a time. Determine the starting bit based on count |
| 1545 | */ |
| 1546 | mask = 0x01 << (count - 1); |
| 1547 | |
| 1548 | for (i = 0; i < count; i++) { |
| 1549 | /* |
| 1550 | * A "1" is shifted out to the EEPROM by setting bit "DI" to a |
| 1551 | * "1", and then raising and then lowering the clock (the SK |
| 1552 | * bit controls the clock input to the EEPROM). A "0" is |
| 1553 | * shifted out to the EEPROM by setting "DI" to "0" and then |
| 1554 | * raising and then lowering the clock. |
| 1555 | */ |
| 1556 | if (data & mask) |
| 1557 | eec |= IXGBE_EEC_DI; |
| 1558 | else |
| 1559 | eec &= ~IXGBE_EEC_DI; |
| 1560 | |
| 1561 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1562 | IXGBE_WRITE_FLUSH(hw); |
| 1563 | |
| 1564 | udelay(1); |
| 1565 | |
| 1566 | ixgbe_raise_eeprom_clk(hw, &eec); |
| 1567 | ixgbe_lower_eeprom_clk(hw, &eec); |
| 1568 | |
| 1569 | /* |
| 1570 | * Shift mask to signify next bit of data to shift in to the |
| 1571 | * EEPROM |
| 1572 | */ |
| 1573 | mask = mask >> 1; |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1574 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1575 | |
| 1576 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 1577 | eec &= ~IXGBE_EEC_DI; |
| 1578 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1579 | IXGBE_WRITE_FLUSH(hw); |
| 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM |
| 1584 | * @hw: pointer to hardware structure |
| 1585 | **/ |
| 1586 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count) |
| 1587 | { |
| 1588 | u32 eec; |
| 1589 | u32 i; |
| 1590 | u16 data = 0; |
| 1591 | |
| 1592 | /* |
| 1593 | * In order to read a register from the EEPROM, we need to shift |
| 1594 | * 'count' bits in from the EEPROM. Bits are "shifted in" by raising |
| 1595 | * the clock input to the EEPROM (setting the SK bit), and then reading |
| 1596 | * the value of the "DO" bit. During this "shifting in" process the |
| 1597 | * "DI" bit should always be clear. |
| 1598 | */ |
| 1599 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1600 | |
| 1601 | eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI); |
| 1602 | |
| 1603 | for (i = 0; i < count; i++) { |
| 1604 | data = data << 1; |
| 1605 | ixgbe_raise_eeprom_clk(hw, &eec); |
| 1606 | |
| 1607 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1608 | |
| 1609 | eec &= ~(IXGBE_EEC_DI); |
| 1610 | if (eec & IXGBE_EEC_DO) |
| 1611 | data |= 1; |
| 1612 | |
| 1613 | ixgbe_lower_eeprom_clk(hw, &eec); |
| 1614 | } |
| 1615 | |
| 1616 | return data; |
| 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input. |
| 1621 | * @hw: pointer to hardware structure |
| 1622 | * @eec: EEC register's current value |
| 1623 | **/ |
| 1624 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) |
| 1625 | { |
| 1626 | /* |
| 1627 | * Raise the clock input to the EEPROM |
| 1628 | * (setting the SK bit), then delay |
| 1629 | */ |
| 1630 | *eec = *eec | IXGBE_EEC_SK; |
| 1631 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); |
| 1632 | IXGBE_WRITE_FLUSH(hw); |
| 1633 | udelay(1); |
| 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input. |
| 1638 | * @hw: pointer to hardware structure |
| 1639 | * @eecd: EECD's current value |
| 1640 | **/ |
| 1641 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) |
| 1642 | { |
| 1643 | /* |
| 1644 | * Lower the clock input to the EEPROM (clearing the SK bit), then |
| 1645 | * delay |
| 1646 | */ |
| 1647 | *eec = *eec & ~IXGBE_EEC_SK; |
| 1648 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); |
| 1649 | IXGBE_WRITE_FLUSH(hw); |
| 1650 | udelay(1); |
| 1651 | } |
| 1652 | |
| 1653 | /** |
| 1654 | * ixgbe_release_eeprom - Release EEPROM, release semaphores |
| 1655 | * @hw: pointer to hardware structure |
| 1656 | **/ |
| 1657 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw) |
| 1658 | { |
| 1659 | u32 eec; |
| 1660 | |
| 1661 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1662 | |
| 1663 | eec |= IXGBE_EEC_CS; /* Pull CS high */ |
| 1664 | eec &= ~IXGBE_EEC_SK; /* Lower SCK */ |
| 1665 | |
| 1666 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1667 | IXGBE_WRITE_FLUSH(hw); |
| 1668 | |
| 1669 | udelay(1); |
| 1670 | |
| 1671 | /* Stop requesting EEPROM access */ |
| 1672 | eec &= ~IXGBE_EEC_REQ; |
| 1673 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1674 | |
Don Skidmore | 9082799 | 2011-03-05 18:59:20 -0800 | [diff] [blame] | 1675 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1676 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1677 | /* |
| 1678 | * Delay before attempt to obtain semaphore again to allow FW |
| 1679 | * access. semaphore_delay is in ms we need us for usleep_range |
| 1680 | */ |
| 1681 | usleep_range(hw->eeprom.semaphore_delay * 1000, |
| 1682 | hw->eeprom.semaphore_delay * 2000); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | /** |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1686 | * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1687 | * @hw: pointer to hardware structure |
| 1688 | **/ |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1689 | u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1690 | { |
| 1691 | u16 i; |
| 1692 | u16 j; |
| 1693 | u16 checksum = 0; |
| 1694 | u16 length = 0; |
| 1695 | u16 pointer = 0; |
| 1696 | u16 word = 0; |
| 1697 | |
| 1698 | /* Include 0x0-0x3F in the checksum */ |
| 1699 | for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1700 | if (hw->eeprom.ops.read(hw, i, &word) != 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1701 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1702 | break; |
| 1703 | } |
| 1704 | checksum += word; |
| 1705 | } |
| 1706 | |
| 1707 | /* Include all data from pointers except for the fw pointer */ |
| 1708 | for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1709 | hw->eeprom.ops.read(hw, i, &pointer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1710 | |
| 1711 | /* Make sure the pointer seems valid */ |
| 1712 | if (pointer != 0xFFFF && pointer != 0) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1713 | hw->eeprom.ops.read(hw, pointer, &length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1714 | |
| 1715 | if (length != 0xFFFF && length != 0) { |
| 1716 | for (j = pointer+1; j <= pointer+length; j++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1717 | hw->eeprom.ops.read(hw, j, &word); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1718 | checksum += word; |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | checksum = (u16)IXGBE_EEPROM_SUM - checksum; |
| 1725 | |
| 1726 | return checksum; |
| 1727 | } |
| 1728 | |
| 1729 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1730 | * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1731 | * @hw: pointer to hardware structure |
| 1732 | * @checksum_val: calculated checksum |
| 1733 | * |
| 1734 | * Performs checksum calculation and validates the EEPROM checksum. If the |
| 1735 | * caller does not need checksum_val, the value can be NULL. |
| 1736 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1737 | s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1738 | u16 *checksum_val) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1739 | { |
| 1740 | s32 status; |
| 1741 | u16 checksum; |
| 1742 | u16 read_checksum = 0; |
| 1743 | |
| 1744 | /* |
| 1745 | * Read the first word from the EEPROM. If this times out or fails, do |
| 1746 | * not continue or we could be in for a very long wait while every |
| 1747 | * EEPROM read fails |
| 1748 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1749 | status = hw->eeprom.ops.read(hw, 0, &checksum); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1750 | |
| 1751 | if (status == 0) { |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1752 | checksum = hw->eeprom.ops.calc_checksum(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1753 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1754 | hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1755 | |
| 1756 | /* |
| 1757 | * Verify read checksum from EEPROM is the same as |
| 1758 | * calculated checksum |
| 1759 | */ |
| 1760 | if (read_checksum != checksum) |
| 1761 | status = IXGBE_ERR_EEPROM_CHECKSUM; |
| 1762 | |
| 1763 | /* If the user cares, return the calculated checksum */ |
| 1764 | if (checksum_val) |
| 1765 | *checksum_val = checksum; |
| 1766 | } else { |
| 1767 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1768 | } |
| 1769 | |
| 1770 | return status; |
| 1771 | } |
| 1772 | |
| 1773 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1774 | * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum |
| 1775 | * @hw: pointer to hardware structure |
| 1776 | **/ |
| 1777 | s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw) |
| 1778 | { |
| 1779 | s32 status; |
| 1780 | u16 checksum; |
| 1781 | |
| 1782 | /* |
| 1783 | * Read the first word from the EEPROM. If this times out or fails, do |
| 1784 | * not continue or we could be in for a very long wait while every |
| 1785 | * EEPROM read fails |
| 1786 | */ |
| 1787 | status = hw->eeprom.ops.read(hw, 0, &checksum); |
| 1788 | |
| 1789 | if (status == 0) { |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1790 | checksum = hw->eeprom.ops.calc_checksum(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1791 | status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 1792 | checksum); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1793 | } else { |
| 1794 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1795 | } |
| 1796 | |
| 1797 | return status; |
| 1798 | } |
| 1799 | |
| 1800 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1801 | * ixgbe_set_rar_generic - Set Rx address register |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1802 | * @hw: pointer to hardware structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1803 | * @index: Receive address register to write |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1804 | * @addr: Address to put into receive address register |
| 1805 | * @vmdq: VMDq "set" or "pool" index |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1806 | * @enable_addr: set flag that address is active |
| 1807 | * |
| 1808 | * Puts an ethernet address into a receive address register. |
| 1809 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1810 | s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1811 | u32 enable_addr) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1812 | { |
| 1813 | u32 rar_low, rar_high; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1814 | u32 rar_entries = hw->mac.num_rar_entries; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1815 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1816 | /* Make sure we are using a valid rar index range */ |
| 1817 | if (index >= rar_entries) { |
| 1818 | hw_dbg(hw, "RAR index %d is out of range.\n", index); |
| 1819 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 1820 | } |
| 1821 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1822 | /* setup VMDq pool selection before this RAR gets enabled */ |
| 1823 | hw->mac.ops.set_vmdq(hw, index, vmdq); |
| 1824 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1825 | /* |
| 1826 | * HW expects these in little endian so we reverse the byte |
| 1827 | * order from network order (big endian) to little endian |
| 1828 | */ |
| 1829 | rar_low = ((u32)addr[0] | |
| 1830 | ((u32)addr[1] << 8) | |
| 1831 | ((u32)addr[2] << 16) | |
| 1832 | ((u32)addr[3] << 24)); |
| 1833 | /* |
| 1834 | * Some parts put the VMDq setting in the extra RAH bits, |
| 1835 | * so save everything except the lower 16 bits that hold part |
| 1836 | * of the address and the address valid bit. |
| 1837 | */ |
| 1838 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); |
| 1839 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); |
| 1840 | rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1841 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1842 | if (enable_addr != 0) |
| 1843 | rar_high |= IXGBE_RAH_AV; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1844 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1845 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low); |
| 1846 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1847 | |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1852 | * ixgbe_clear_rar_generic - Remove Rx address register |
| 1853 | * @hw: pointer to hardware structure |
| 1854 | * @index: Receive address register to write |
| 1855 | * |
| 1856 | * Clears an ethernet address from a receive address register. |
| 1857 | **/ |
| 1858 | s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index) |
| 1859 | { |
| 1860 | u32 rar_high; |
| 1861 | u32 rar_entries = hw->mac.num_rar_entries; |
| 1862 | |
| 1863 | /* Make sure we are using a valid rar index range */ |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1864 | if (index >= rar_entries) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1865 | hw_dbg(hw, "RAR index %d is out of range.\n", index); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1866 | return IXGBE_ERR_INVALID_ARGUMENT; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1869 | /* |
| 1870 | * Some parts put the VMDq setting in the extra RAH bits, |
| 1871 | * so save everything except the lower 16 bits that hold part |
| 1872 | * of the address and the address valid bit. |
| 1873 | */ |
| 1874 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); |
| 1875 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); |
| 1876 | |
| 1877 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0); |
| 1878 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); |
| 1879 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1880 | /* clear VMDq pool/queue selection for this RAR */ |
| 1881 | hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL); |
| 1882 | |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
| 1886 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1887 | * ixgbe_init_rx_addrs_generic - Initializes receive address filters. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1888 | * @hw: pointer to hardware structure |
| 1889 | * |
| 1890 | * Places the MAC address in receive address register 0 and clears the rest |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1891 | * of the receive address registers. Clears the multicast table. Assumes |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1892 | * the receiver is in reset when the routine is called. |
| 1893 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1894 | s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1895 | { |
| 1896 | u32 i; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1897 | u32 rar_entries = hw->mac.num_rar_entries; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1898 | |
| 1899 | /* |
| 1900 | * If the current mac address is valid, assume it is a software override |
| 1901 | * to the permanent address. |
| 1902 | * Otherwise, use the permanent address from the eeprom. |
| 1903 | */ |
Joe Perches | f8ebc68 | 2012-10-24 17:19:02 +0000 | [diff] [blame] | 1904 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1905 | /* Get the MAC address from the RAR0 for later reference */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1906 | hw->mac.ops.get_mac_addr(hw, hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1907 | |
hartleys | ce7194d | 2010-01-05 06:56:52 +0000 | [diff] [blame] | 1908 | hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1909 | } else { |
| 1910 | /* Setup the receive address. */ |
| 1911 | hw_dbg(hw, "Overriding MAC Address in RAR[0]\n"); |
hartleys | ce7194d | 2010-01-05 06:56:52 +0000 | [diff] [blame] | 1912 | hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1913 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1914 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); |
Alexander Duyck | 96cc637 | 2011-01-19 18:33:05 +0000 | [diff] [blame] | 1915 | |
| 1916 | /* clear VMDq pool/queue selection for RAR 0 */ |
| 1917 | hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1918 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1919 | hw->addr_ctrl.overflow_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1920 | |
| 1921 | hw->addr_ctrl.rar_used_count = 1; |
| 1922 | |
| 1923 | /* Zero out the other receive addresses. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1924 | hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1925 | for (i = 1; i < rar_entries; i++) { |
| 1926 | IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); |
| 1927 | IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); |
| 1928 | } |
| 1929 | |
| 1930 | /* Clear the MTA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1931 | hw->addr_ctrl.mta_in_use = 0; |
| 1932 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); |
| 1933 | |
| 1934 | hw_dbg(hw, " Clearing MTA\n"); |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1935 | for (i = 0; i < hw->mac.mcft_size; i++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1936 | IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); |
| 1937 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1938 | if (hw->mac.ops.init_uta_tables) |
| 1939 | hw->mac.ops.init_uta_tables(hw); |
| 1940 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1941 | return 0; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * ixgbe_mta_vector - Determines bit-vector in multicast table to set |
| 1946 | * @hw: pointer to hardware structure |
| 1947 | * @mc_addr: the multicast address |
| 1948 | * |
| 1949 | * Extracts the 12 bits, from a multicast address, to determine which |
| 1950 | * bit-vector to set in the multicast table. The hardware uses 12 bits, from |
| 1951 | * incoming rx multicast addresses, to determine the bit-vector to check in |
| 1952 | * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1953 | * by the MO field of the MCSTCTRL. The MO field is set during initialization |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1954 | * to mc_filter_type. |
| 1955 | **/ |
| 1956 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) |
| 1957 | { |
| 1958 | u32 vector = 0; |
| 1959 | |
| 1960 | switch (hw->mac.mc_filter_type) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1961 | case 0: /* use bits [47:36] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1962 | vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); |
| 1963 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1964 | case 1: /* use bits [46:35] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1965 | vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); |
| 1966 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1967 | case 2: /* use bits [45:34] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1968 | vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); |
| 1969 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1970 | case 3: /* use bits [43:32] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1971 | vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); |
| 1972 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1973 | default: /* Invalid mc_filter_type */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1974 | hw_dbg(hw, "MC filter type param set incorrectly\n"); |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | /* vector can only be 12-bits or boundary will be exceeded */ |
| 1979 | vector &= 0xFFF; |
| 1980 | return vector; |
| 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * ixgbe_set_mta - Set bit-vector in multicast table |
| 1985 | * @hw: pointer to hardware structure |
| 1986 | * @hash_value: Multicast address hash value |
| 1987 | * |
| 1988 | * Sets the bit-vector in the multicast table. |
| 1989 | **/ |
| 1990 | static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) |
| 1991 | { |
| 1992 | u32 vector; |
| 1993 | u32 vector_bit; |
| 1994 | u32 vector_reg; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1995 | |
| 1996 | hw->addr_ctrl.mta_in_use++; |
| 1997 | |
| 1998 | vector = ixgbe_mta_vector(hw, mc_addr); |
| 1999 | hw_dbg(hw, " bit-vector = 0x%03X\n", vector); |
| 2000 | |
| 2001 | /* |
| 2002 | * The MTA is a register array of 128 32-bit registers. It is treated |
| 2003 | * like an array of 4096 bits. We want to set bit |
| 2004 | * BitArray[vector_value]. So we figure out what register the bit is |
| 2005 | * in, read it, OR in the new bit, then write back the new value. The |
| 2006 | * register is determined by the upper 7 bits of the vector value and |
| 2007 | * the bit within that register are determined by the lower 5 bits of |
| 2008 | * the value. |
| 2009 | */ |
| 2010 | vector_reg = (vector >> 5) & 0x7F; |
| 2011 | vector_bit = vector & 0x1F; |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 2012 | hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2016 | * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2017 | * @hw: pointer to hardware structure |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 2018 | * @netdev: pointer to net device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2019 | * |
| 2020 | * The given list replaces any existing list. Clears the MC addrs from receive |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2021 | * address registers and the multicast table. Uses unused receive address |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2022 | * registers for the first multicast addresses, and hashes the rest into the |
| 2023 | * multicast table. |
| 2024 | **/ |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 2025 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, |
| 2026 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2027 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2028 | struct netdev_hw_addr *ha; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2029 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2030 | |
| 2031 | /* |
| 2032 | * Set the new number of MC addresses that we are being requested to |
| 2033 | * use. |
| 2034 | */ |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 2035 | hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2036 | hw->addr_ctrl.mta_in_use = 0; |
| 2037 | |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 2038 | /* Clear mta_shadow */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2039 | hw_dbg(hw, " Clearing MTA\n"); |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 2040 | memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2041 | |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 2042 | /* Update mta shadow */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2043 | netdev_for_each_mc_addr(ha, netdev) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2044 | hw_dbg(hw, " Adding the multicast addresses:\n"); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2045 | ixgbe_set_mta(hw, ha->addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /* Enable mta */ |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 2049 | for (i = 0; i < hw->mac.mcft_size; i++) |
| 2050 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i, |
| 2051 | hw->mac.mta_shadow[i]); |
| 2052 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2053 | if (hw->addr_ctrl.mta_in_use > 0) |
| 2054 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2055 | IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2056 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2057 | hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2058 | return 0; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2062 | * ixgbe_enable_mc_generic - Enable multicast address in RAR |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2063 | * @hw: pointer to hardware structure |
| 2064 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2065 | * Enables multicast address in RAR and the use of the multicast hash table. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2066 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2067 | s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2068 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2069 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2070 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2071 | if (a->mta_in_use > 0) |
| 2072 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE | |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2073 | hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2074 | |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
| 2078 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2079 | * ixgbe_disable_mc_generic - Disable multicast address in RAR |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2080 | * @hw: pointer to hardware structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2081 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2082 | * Disables multicast address in RAR and the use of the multicast hash table. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2083 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2084 | s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2085 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2086 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2087 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2088 | if (a->mta_in_use > 0) |
| 2089 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2090 | |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2095 | * ixgbe_fc_enable_generic - Enable flow control |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2096 | * @hw: pointer to hardware structure |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2097 | * |
| 2098 | * Enable flow control according to the current settings. |
| 2099 | **/ |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2100 | s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2101 | { |
| 2102 | s32 ret_val = 0; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2103 | u32 mflcn_reg, fccfg_reg; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2104 | u32 reg; |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 2105 | u32 fcrtl, fcrth; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2106 | int i; |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 2107 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 2108 | /* Validate the water mark configuration. */ |
| 2109 | if (!hw->fc.pause_time) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2110 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 2111 | goto out; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2112 | } |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 2113 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 2114 | /* Low water mark of zero causes XOFF floods */ |
| 2115 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 2116 | if ((hw->fc.current_mode & ixgbe_fc_tx_pause) && |
| 2117 | hw->fc.high_water[i]) { |
| 2118 | if (!hw->fc.low_water[i] || |
| 2119 | hw->fc.low_water[i] >= hw->fc.high_water[i]) { |
| 2120 | hw_dbg(hw, "Invalid water mark configuration\n"); |
| 2121 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 2122 | goto out; |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2127 | /* Negotiate the fc mode to use */ |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2128 | ixgbe_fc_autoneg(hw); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2129 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2130 | /* Disable any previous flow control settings */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2131 | mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2132 | mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2133 | |
| 2134 | fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 2135 | fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY); |
| 2136 | |
| 2137 | /* |
| 2138 | * The possible values of fc.current_mode are: |
| 2139 | * 0: Flow control is completely disabled |
| 2140 | * 1: Rx flow control is enabled (we can receive pause frames, |
| 2141 | * but not send pause frames). |
PJ Waskiewicz | bb3daa4 | 2009-03-25 22:10:42 +0000 | [diff] [blame] | 2142 | * 2: Tx flow control is enabled (we can send pause frames but |
| 2143 | * we do not support receiving pause frames). |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2144 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
| 2145 | * other: Invalid. |
| 2146 | */ |
| 2147 | switch (hw->fc.current_mode) { |
| 2148 | case ixgbe_fc_none: |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2149 | /* |
| 2150 | * Flow control is disabled by software override or autoneg. |
| 2151 | * The code below will actually disable it in the HW. |
| 2152 | */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2153 | break; |
| 2154 | case ixgbe_fc_rx_pause: |
| 2155 | /* |
| 2156 | * Rx Flow control is enabled and Tx Flow control is |
| 2157 | * disabled by software override. Since there really |
| 2158 | * isn't a way to advertise that we are capable of RX |
| 2159 | * Pause ONLY, we will advertise that we support both |
| 2160 | * symmetric and asymmetric Rx PAUSE. Later, we will |
| 2161 | * disable the adapter's ability to send PAUSE frames. |
| 2162 | */ |
| 2163 | mflcn_reg |= IXGBE_MFLCN_RFCE; |
| 2164 | break; |
| 2165 | case ixgbe_fc_tx_pause: |
| 2166 | /* |
| 2167 | * Tx Flow control is enabled, and Rx Flow control is |
| 2168 | * disabled by software override. |
| 2169 | */ |
| 2170 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; |
| 2171 | break; |
| 2172 | case ixgbe_fc_full: |
| 2173 | /* Flow control (both Rx and Tx) is enabled by SW override. */ |
| 2174 | mflcn_reg |= IXGBE_MFLCN_RFCE; |
| 2175 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; |
| 2176 | break; |
| 2177 | default: |
| 2178 | hw_dbg(hw, "Flow control param set incorrectly\n"); |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2179 | ret_val = IXGBE_ERR_CONFIG; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2180 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2183 | /* Set 802.3x based flow control settings. */ |
PJ Waskiewicz | 2132d38 | 2009-04-09 22:26:21 +0000 | [diff] [blame] | 2184 | mflcn_reg |= IXGBE_MFLCN_DPF; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2185 | IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg); |
| 2186 | IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg); |
| 2187 | |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2188 | /* Set up and enable Rx high/low water mark thresholds, enable XON. */ |
| 2189 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 2190 | if ((hw->fc.current_mode & ixgbe_fc_tx_pause) && |
| 2191 | hw->fc.high_water[i]) { |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 2192 | fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2193 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl); |
| 2194 | fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN; |
| 2195 | } else { |
| 2196 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0); |
| 2197 | /* |
| 2198 | * In order to prevent Tx hangs when the internal Tx |
| 2199 | * switch is enabled we must set the high water mark |
| 2200 | * to the maximum FCRTH value. This allows the Tx |
| 2201 | * switch to function even under heavy Rx workloads. |
| 2202 | */ |
| 2203 | fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32; |
| 2204 | } |
| 2205 | |
| 2206 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | /* Configure pause time (2 TCs per register) */ |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2210 | reg = hw->fc.pause_time * 0x00010001; |
| 2211 | for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++) |
| 2212 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2213 | |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 2214 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2215 | |
| 2216 | out: |
| 2217 | return ret_val; |
| 2218 | } |
| 2219 | |
| 2220 | /** |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2221 | * ixgbe_negotiate_fc - Negotiate flow control |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2222 | * @hw: pointer to hardware structure |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2223 | * @adv_reg: flow control advertised settings |
| 2224 | * @lp_reg: link partner's flow control settings |
| 2225 | * @adv_sym: symmetric pause bit in advertisement |
| 2226 | * @adv_asm: asymmetric pause bit in advertisement |
| 2227 | * @lp_sym: symmetric pause bit in link partner advertisement |
| 2228 | * @lp_asm: asymmetric pause bit in link partner advertisement |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2229 | * |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2230 | * Find the intersection between advertised settings and link partner's |
| 2231 | * advertised settings |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2232 | **/ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2233 | static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg, |
| 2234 | u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm) |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2235 | { |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2236 | if ((!(adv_reg)) || (!(lp_reg))) |
| 2237 | return IXGBE_ERR_FC_NOT_NEGOTIATED; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2238 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2239 | if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) { |
| 2240 | /* |
| 2241 | * Now we need to check if the user selected Rx ONLY |
| 2242 | * of pause frames. In this case, we had to advertise |
| 2243 | * FULL flow control because we could not advertise RX |
| 2244 | * ONLY. Hence, we must now check to see if we need to |
| 2245 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2246 | */ |
| 2247 | if (hw->fc.requested_mode == ixgbe_fc_full) { |
| 2248 | hw->fc.current_mode = ixgbe_fc_full; |
| 2249 | hw_dbg(hw, "Flow Control = FULL.\n"); |
| 2250 | } else { |
| 2251 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 2252 | hw_dbg(hw, "Flow Control=RX PAUSE frames only\n"); |
| 2253 | } |
| 2254 | } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) && |
| 2255 | (lp_reg & lp_sym) && (lp_reg & lp_asm)) { |
| 2256 | hw->fc.current_mode = ixgbe_fc_tx_pause; |
| 2257 | hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n"); |
| 2258 | } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) && |
| 2259 | !(lp_reg & lp_sym) && (lp_reg & lp_asm)) { |
| 2260 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 2261 | hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n"); |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2262 | } else { |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2263 | hw->fc.current_mode = ixgbe_fc_none; |
| 2264 | hw_dbg(hw, "Flow Control = NONE.\n"); |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2265 | } |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2266 | return 0; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /** |
| 2270 | * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber |
| 2271 | * @hw: pointer to hardware structure |
| 2272 | * |
| 2273 | * Enable flow control according on 1 gig fiber. |
| 2274 | **/ |
| 2275 | static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw) |
| 2276 | { |
| 2277 | u32 pcs_anadv_reg, pcs_lpab_reg, linkstat; |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2278 | s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2279 | |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2280 | /* |
| 2281 | * On multispeed fiber at 1g, bail out if |
| 2282 | * - link is up but AN did not complete, or if |
| 2283 | * - link is up and AN completed but timed out |
| 2284 | */ |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2285 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2286 | linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); |
Don Skidmore | 53f096d | 2011-07-28 01:00:58 +0000 | [diff] [blame] | 2287 | if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) || |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2288 | (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) |
PJ Waskiewicz | 9bbe3a5 | 2009-11-24 18:51:28 +0000 | [diff] [blame] | 2289 | goto out; |
PJ Waskiewicz | 9bbe3a5 | 2009-11-24 18:51:28 +0000 | [diff] [blame] | 2290 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2291 | pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); |
| 2292 | pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2293 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2294 | ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg, |
| 2295 | pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE, |
| 2296 | IXGBE_PCS1GANA_ASM_PAUSE, |
| 2297 | IXGBE_PCS1GANA_SYM_PAUSE, |
| 2298 | IXGBE_PCS1GANA_ASM_PAUSE); |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2299 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2300 | out: |
| 2301 | return ret_val; |
| 2302 | } |
| 2303 | |
| 2304 | /** |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2305 | * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37 |
| 2306 | * @hw: pointer to hardware structure |
| 2307 | * |
| 2308 | * Enable flow control according to IEEE clause 37. |
| 2309 | **/ |
| 2310 | static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw) |
| 2311 | { |
| 2312 | u32 links2, anlp1_reg, autoc_reg, links; |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2313 | s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2314 | |
| 2315 | /* |
| 2316 | * On backplane, bail out if |
| 2317 | * - backplane autoneg was not completed, or if |
| 2318 | * - we are 82599 and link partner is not AN enabled |
| 2319 | */ |
| 2320 | links = IXGBE_READ_REG(hw, IXGBE_LINKS); |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2321 | if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2322 | goto out; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2323 | |
| 2324 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2325 | links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2); |
Alexander Duyck | 786e9a5 | 2012-03-28 08:03:48 +0000 | [diff] [blame] | 2326 | if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2327 | goto out; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2328 | } |
| 2329 | /* |
| 2330 | * Read the 10g AN autoc and LP ability registers and resolve |
| 2331 | * local flow control settings accordingly |
| 2332 | */ |
| 2333 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 2334 | anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1); |
| 2335 | |
| 2336 | ret_val = ixgbe_negotiate_fc(hw, autoc_reg, |
| 2337 | anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE, |
| 2338 | IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE); |
| 2339 | |
| 2340 | out: |
| 2341 | return ret_val; |
| 2342 | } |
| 2343 | |
| 2344 | /** |
| 2345 | * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37 |
| 2346 | * @hw: pointer to hardware structure |
| 2347 | * |
| 2348 | * Enable flow control according to IEEE clause 37. |
| 2349 | **/ |
| 2350 | static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw) |
| 2351 | { |
| 2352 | u16 technology_ability_reg = 0; |
| 2353 | u16 lp_technology_ability_reg = 0; |
| 2354 | |
| 2355 | hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, |
| 2356 | MDIO_MMD_AN, |
| 2357 | &technology_ability_reg); |
| 2358 | hw->phy.ops.read_reg(hw, MDIO_AN_LPA, |
| 2359 | MDIO_MMD_AN, |
| 2360 | &lp_technology_ability_reg); |
| 2361 | |
| 2362 | return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg, |
| 2363 | (u32)lp_technology_ability_reg, |
| 2364 | IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE, |
| 2365 | IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE); |
| 2366 | } |
| 2367 | |
| 2368 | /** |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2369 | * ixgbe_fc_autoneg - Configure flow control |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2370 | * @hw: pointer to hardware structure |
| 2371 | * |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2372 | * Compares our advertised flow control capabilities to those advertised by |
| 2373 | * our link partner, and determines the proper flow control mode to use. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2374 | **/ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2375 | void ixgbe_fc_autoneg(struct ixgbe_hw *hw) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2376 | { |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2377 | s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED; |
| 2378 | ixgbe_link_speed speed; |
| 2379 | bool link_up; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2380 | |
| 2381 | /* |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2382 | * AN should have completed when the cable was plugged in. |
| 2383 | * Look for reasons to bail out. Bail out if: |
| 2384 | * - FC autoneg is disabled, or if |
| 2385 | * - link is not up. |
| 2386 | * |
| 2387 | * Since we're being called from an LSC, link is already known to be up. |
| 2388 | * So use link_up_wait_to_complete=false. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2389 | */ |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2390 | if (hw->fc.disable_fc_autoneg) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2391 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2392 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2393 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
| 2394 | if (!link_up) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2395 | goto out; |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2396 | |
| 2397 | switch (hw->phy.media_type) { |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2398 | /* Autoneg flow control on fiber adapters */ |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2399 | case ixgbe_media_type_fiber: |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2400 | if (speed == IXGBE_LINK_SPEED_1GB_FULL) |
| 2401 | ret_val = ixgbe_fc_autoneg_fiber(hw); |
| 2402 | break; |
| 2403 | |
| 2404 | /* Autoneg flow control on backplane adapters */ |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2405 | case ixgbe_media_type_backplane: |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2406 | ret_val = ixgbe_fc_autoneg_backplane(hw); |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2407 | break; |
| 2408 | |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2409 | /* Autoneg flow control on copper adapters */ |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2410 | case ixgbe_media_type_copper: |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 2411 | if (ixgbe_device_supports_autoneg_fc(hw)) |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2412 | ret_val = ixgbe_fc_autoneg_copper(hw); |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 2413 | break; |
| 2414 | |
| 2415 | default: |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2418 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2419 | out: |
Alexander Duyck | 67a79df | 2012-04-19 17:49:56 +0000 | [diff] [blame] | 2420 | if (ret_val == 0) { |
| 2421 | hw->fc.fc_was_autonegged = true; |
| 2422 | } else { |
| 2423 | hw->fc.fc_was_autonegged = false; |
| 2424 | hw->fc.current_mode = hw->fc.requested_mode; |
| 2425 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | /** |
Don Skidmore | 1f86c98 | 2014-02-27 20:32:40 -0800 | [diff] [blame] | 2429 | * ixgbe_pcie_timeout_poll - Return number of times to poll for completion |
| 2430 | * @hw: pointer to hardware structure |
| 2431 | * |
| 2432 | * System-wide timeout range is encoded in PCIe Device Control2 register. |
| 2433 | * |
| 2434 | * Add 10% to specified maximum and return the number of times to poll for |
| 2435 | * completion timeout, in units of 100 microsec. Never return less than |
| 2436 | * 800 = 80 millisec. |
| 2437 | **/ |
| 2438 | static u32 ixgbe_pcie_timeout_poll(struct ixgbe_hw *hw) |
| 2439 | { |
Don Skidmore | 1f86c98 | 2014-02-27 20:32:40 -0800 | [diff] [blame] | 2440 | s16 devctl2; |
| 2441 | u32 pollcnt; |
| 2442 | |
Jacob Keller | 0d7c6e0 | 2014-02-22 01:23:58 +0000 | [diff] [blame] | 2443 | devctl2 = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_CONTROL2); |
Don Skidmore | 1f86c98 | 2014-02-27 20:32:40 -0800 | [diff] [blame] | 2444 | devctl2 &= IXGBE_PCIDEVCTRL2_TIMEO_MASK; |
| 2445 | |
| 2446 | switch (devctl2) { |
| 2447 | case IXGBE_PCIDEVCTRL2_65_130ms: |
| 2448 | pollcnt = 1300; /* 130 millisec */ |
| 2449 | break; |
| 2450 | case IXGBE_PCIDEVCTRL2_260_520ms: |
| 2451 | pollcnt = 5200; /* 520 millisec */ |
| 2452 | break; |
| 2453 | case IXGBE_PCIDEVCTRL2_1_2s: |
| 2454 | pollcnt = 20000; /* 2 sec */ |
| 2455 | break; |
| 2456 | case IXGBE_PCIDEVCTRL2_4_8s: |
| 2457 | pollcnt = 80000; /* 8 sec */ |
| 2458 | break; |
| 2459 | case IXGBE_PCIDEVCTRL2_17_34s: |
| 2460 | pollcnt = 34000; /* 34 sec */ |
| 2461 | break; |
| 2462 | case IXGBE_PCIDEVCTRL2_50_100us: /* 100 microsecs */ |
| 2463 | case IXGBE_PCIDEVCTRL2_1_2ms: /* 2 millisecs */ |
| 2464 | case IXGBE_PCIDEVCTRL2_16_32ms: /* 32 millisec */ |
| 2465 | case IXGBE_PCIDEVCTRL2_16_32ms_def: /* 32 millisec default */ |
| 2466 | default: |
| 2467 | pollcnt = 800; /* 80 millisec minimum */ |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | /* add 10% to spec maximum */ |
| 2472 | return (pollcnt * 11) / 10; |
| 2473 | } |
| 2474 | |
| 2475 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2476 | * ixgbe_disable_pcie_master - Disable PCI-express master access |
| 2477 | * @hw: pointer to hardware structure |
| 2478 | * |
| 2479 | * Disables PCI-Express master access and verifies there are no pending |
| 2480 | * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable |
| 2481 | * bit hasn't caused the master requests to be disabled, else 0 |
| 2482 | * is returned signifying master requests disabled. |
| 2483 | **/ |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2484 | static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2485 | { |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2486 | s32 status = 0; |
Don Skidmore | 1f86c98 | 2014-02-27 20:32:40 -0800 | [diff] [blame] | 2487 | u32 i, poll; |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2488 | u16 value; |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2489 | |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2490 | /* Always set this bit to ensure any future transactions are blocked */ |
| 2491 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS); |
| 2492 | |
| 2493 | /* Exit if master requests are blocked */ |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 2494 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO) || |
| 2495 | ixgbe_removed(hw->hw_addr)) |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2496 | goto out; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2497 | |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2498 | /* Poll for master request bit to clear */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2499 | for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2500 | udelay(100); |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2501 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2502 | goto out; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2505 | /* |
| 2506 | * Two consecutive resets are required via CTRL.RST per datasheet |
| 2507 | * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine |
| 2508 | * of this need. The first reset prevents new master requests from |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2509 | * being issued by our device. We then must wait 1usec or more for any |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2510 | * remaining completions from the PCIe bus to trickle in, and then reset |
| 2511 | * again to clear out any effects they may have had on our device. |
| 2512 | */ |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2513 | hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n"); |
| 2514 | hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; |
| 2515 | |
| 2516 | /* |
| 2517 | * Before proceeding, make sure that the PCIe block does not have |
| 2518 | * transactions pending. |
| 2519 | */ |
Don Skidmore | 1f86c98 | 2014-02-27 20:32:40 -0800 | [diff] [blame] | 2520 | poll = ixgbe_pcie_timeout_poll(hw); |
| 2521 | for (i = 0; i < poll; i++) { |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2522 | udelay(100); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 2523 | value = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_STATUS); |
| 2524 | if (ixgbe_removed(hw->hw_addr)) |
| 2525 | goto out; |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 2526 | if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING)) |
| 2527 | goto out; |
| 2528 | } |
| 2529 | |
| 2530 | hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n"); |
| 2531 | status = IXGBE_ERR_MASTER_REQUESTS_PENDING; |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2532 | |
| 2533 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2534 | return status; |
| 2535 | } |
| 2536 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2537 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2538 | * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2539 | * @hw: pointer to hardware structure |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2540 | * @mask: Mask to specify which semaphore to acquire |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2541 | * |
Emil Tantilov | da74cd4 | 2011-03-03 09:25:07 +0000 | [diff] [blame] | 2542 | * Acquires the SWFW semaphore through the GSSR register for the specified |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2543 | * function (CSR, PHY0, PHY1, EEPROM, Flash) |
| 2544 | **/ |
| 2545 | s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask) |
| 2546 | { |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2547 | u32 gssr = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2548 | u32 swmask = mask; |
| 2549 | u32 fwmask = mask << 5; |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2550 | u32 timeout = 200; |
| 2551 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2552 | |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2553 | for (i = 0; i < timeout; i++) { |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 2554 | /* |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2555 | * SW NVM semaphore bit is used for access to all |
| 2556 | * SW_FW_SYNC bits (not just NVM) |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 2557 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2558 | if (ixgbe_get_eeprom_semaphore(hw)) |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2559 | return IXGBE_ERR_SWFW_SYNC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2560 | |
| 2561 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2562 | if (!(gssr & (fwmask | swmask))) { |
| 2563 | gssr |= swmask; |
| 2564 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); |
| 2565 | ixgbe_release_eeprom_semaphore(hw); |
| 2566 | return 0; |
| 2567 | } else { |
| 2568 | /* Resource is currently in use by FW or SW */ |
| 2569 | ixgbe_release_eeprom_semaphore(hw); |
| 2570 | usleep_range(5000, 10000); |
| 2571 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2574 | /* If time expired clear the bits holding the lock and retry */ |
| 2575 | if (gssr & (fwmask | swmask)) |
| 2576 | ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2577 | |
Emil Tantilov | 674c18b | 2013-07-23 01:57:03 +0000 | [diff] [blame] | 2578 | usleep_range(5000, 10000); |
| 2579 | return IXGBE_ERR_SWFW_SYNC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * ixgbe_release_swfw_sync - Release SWFW semaphore |
| 2584 | * @hw: pointer to hardware structure |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2585 | * @mask: Mask to specify which semaphore to release |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2586 | * |
Emil Tantilov | da74cd4 | 2011-03-03 09:25:07 +0000 | [diff] [blame] | 2587 | * Releases the SWFW semaphore through the GSSR register for the specified |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2588 | * function (CSR, PHY0, PHY1, EEPROM, Flash) |
| 2589 | **/ |
| 2590 | void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask) |
| 2591 | { |
| 2592 | u32 gssr; |
| 2593 | u32 swmask = mask; |
| 2594 | |
| 2595 | ixgbe_get_eeprom_semaphore(hw); |
| 2596 | |
| 2597 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); |
| 2598 | gssr &= ~swmask; |
| 2599 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); |
| 2600 | |
| 2601 | ixgbe_release_eeprom_semaphore(hw); |
| 2602 | } |
| 2603 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2604 | /** |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2605 | * prot_autoc_read_generic - Hides MAC differences needed for AUTOC read |
| 2606 | * @hw: pointer to hardware structure |
| 2607 | * @reg_val: Value we read from AUTOC |
| 2608 | * @locked: bool to indicate whether the SW/FW lock should be taken. Never |
| 2609 | * true in this the generic case. |
| 2610 | * |
| 2611 | * The default case requires no protection so just to the register read. |
| 2612 | **/ |
| 2613 | s32 prot_autoc_read_generic(struct ixgbe_hw *hw, bool *locked, u32 *reg_val) |
| 2614 | { |
| 2615 | *locked = false; |
| 2616 | *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 2617 | return 0; |
| 2618 | } |
| 2619 | |
| 2620 | /** |
| 2621 | * prot_autoc_write_generic - Hides MAC differences needed for AUTOC write |
| 2622 | * @hw: pointer to hardware structure |
| 2623 | * @reg_val: value to write to AUTOC |
| 2624 | * @locked: bool to indicate whether the SW/FW lock was already taken by |
| 2625 | * previous read. |
| 2626 | **/ |
| 2627 | s32 prot_autoc_write_generic(struct ixgbe_hw *hw, u32 reg_val, bool locked) |
| 2628 | { |
| 2629 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_val); |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
| 2633 | /** |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 2634 | * ixgbe_disable_rx_buff_generic - Stops the receive data path |
| 2635 | * @hw: pointer to hardware structure |
| 2636 | * |
| 2637 | * Stops the receive data path and waits for the HW to internally |
| 2638 | * empty the Rx security block. |
| 2639 | **/ |
| 2640 | s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw) |
| 2641 | { |
| 2642 | #define IXGBE_MAX_SECRX_POLL 40 |
| 2643 | int i; |
| 2644 | int secrxreg; |
| 2645 | |
| 2646 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); |
| 2647 | secrxreg |= IXGBE_SECRXCTRL_RX_DIS; |
| 2648 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); |
| 2649 | for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) { |
| 2650 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT); |
| 2651 | if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY) |
| 2652 | break; |
| 2653 | else |
| 2654 | /* Use interrupt-safe sleep just in case */ |
Jacob Keller | db76ad4 | 2012-05-03 01:44:12 +0000 | [diff] [blame] | 2655 | udelay(1000); |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /* For informational purposes only */ |
| 2659 | if (i >= IXGBE_MAX_SECRX_POLL) |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 2660 | hw_dbg(hw, "Rx unit being enabled before security path fully disabled. Continuing with init.\n"); |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 2661 | |
| 2662 | return 0; |
| 2663 | |
| 2664 | } |
| 2665 | |
| 2666 | /** |
| 2667 | * ixgbe_enable_rx_buff - Enables the receive data path |
| 2668 | * @hw: pointer to hardware structure |
| 2669 | * |
| 2670 | * Enables the receive data path |
| 2671 | **/ |
| 2672 | s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw) |
| 2673 | { |
| 2674 | int secrxreg; |
| 2675 | |
| 2676 | secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL); |
| 2677 | secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS; |
| 2678 | IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg); |
| 2679 | IXGBE_WRITE_FLUSH(hw); |
| 2680 | |
| 2681 | return 0; |
| 2682 | } |
| 2683 | |
| 2684 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2685 | * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit |
| 2686 | * @hw: pointer to hardware structure |
| 2687 | * @regval: register value to write to RXCTRL |
| 2688 | * |
| 2689 | * Enables the Rx DMA unit |
| 2690 | **/ |
| 2691 | s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval) |
| 2692 | { |
| 2693 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); |
| 2694 | |
| 2695 | return 0; |
| 2696 | } |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2697 | |
| 2698 | /** |
| 2699 | * ixgbe_blink_led_start_generic - Blink LED based on index. |
| 2700 | * @hw: pointer to hardware structure |
| 2701 | * @index: led number to blink |
| 2702 | **/ |
| 2703 | s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index) |
| 2704 | { |
| 2705 | ixgbe_link_speed speed = 0; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 2706 | bool link_up = false; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2707 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 2708 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2709 | s32 ret_val = 0; |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2710 | bool locked = false; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2711 | |
| 2712 | /* |
| 2713 | * Link must be up to auto-blink the LEDs; |
| 2714 | * Force it if link is down. |
| 2715 | */ |
| 2716 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
| 2717 | |
| 2718 | if (!link_up) { |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2719 | ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg); |
Don Skidmore | f8cf7a0 | 2014-03-19 09:16:26 +0000 | [diff] [blame] | 2720 | if (ret_val) |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2721 | goto out; |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2722 | |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 2723 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2724 | autoc_reg |= IXGBE_AUTOC_FLU; |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2725 | |
| 2726 | ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked); |
Don Skidmore | f8cf7a0 | 2014-03-19 09:16:26 +0000 | [diff] [blame] | 2727 | if (ret_val) |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2728 | goto out; |
| 2729 | |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 2730 | IXGBE_WRITE_FLUSH(hw); |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2731 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2732 | usleep_range(10000, 20000); |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 2736 | led_reg |= IXGBE_LED_BLINK(index); |
| 2737 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
| 2738 | IXGBE_WRITE_FLUSH(hw); |
| 2739 | |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2740 | out: |
| 2741 | return ret_val; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * ixgbe_blink_led_stop_generic - Stop blinking LED based on index. |
| 2746 | * @hw: pointer to hardware structure |
| 2747 | * @index: led number to stop blinking |
| 2748 | **/ |
| 2749 | s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index) |
| 2750 | { |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2751 | u32 autoc_reg = 0; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2752 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2753 | s32 ret_val = 0; |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2754 | bool locked = false; |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2755 | |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2756 | ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg); |
Don Skidmore | f8cf7a0 | 2014-03-19 09:16:26 +0000 | [diff] [blame] | 2757 | if (ret_val) |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2758 | goto out; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2759 | |
| 2760 | autoc_reg &= ~IXGBE_AUTOC_FLU; |
| 2761 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2762 | |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2763 | ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked); |
Don Skidmore | f8cf7a0 | 2014-03-19 09:16:26 +0000 | [diff] [blame] | 2764 | if (ret_val) |
Don Skidmore | 429d6a3 | 2014-02-27 20:32:41 -0800 | [diff] [blame] | 2765 | goto out; |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2766 | |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2767 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 2768 | led_reg &= ~IXGBE_LED_BLINK(index); |
| 2769 | led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index); |
| 2770 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
| 2771 | IXGBE_WRITE_FLUSH(hw); |
| 2772 | |
Don Skidmore | d7bbcd3 | 2012-10-24 06:19:01 +0000 | [diff] [blame] | 2773 | out: |
| 2774 | return ret_val; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2775 | } |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2776 | |
| 2777 | /** |
| 2778 | * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM |
| 2779 | * @hw: pointer to hardware structure |
| 2780 | * @san_mac_offset: SAN MAC address offset |
| 2781 | * |
| 2782 | * This function will read the EEPROM location for the SAN MAC address |
| 2783 | * pointer, and returns the value at that location. This is used in both |
| 2784 | * get and set mac_addr routines. |
| 2785 | **/ |
| 2786 | static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2787 | u16 *san_mac_offset) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2788 | { |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2789 | s32 ret_val; |
| 2790 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2791 | /* |
| 2792 | * First read the EEPROM pointer to see if the MAC addresses are |
| 2793 | * available. |
| 2794 | */ |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2795 | ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, |
| 2796 | san_mac_offset); |
| 2797 | if (ret_val) |
| 2798 | hw_err(hw, "eeprom read at offset %d failed\n", |
| 2799 | IXGBE_SAN_MAC_ADDR_PTR); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2800 | |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2801 | return ret_val; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | /** |
| 2805 | * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM |
| 2806 | * @hw: pointer to hardware structure |
| 2807 | * @san_mac_addr: SAN MAC address |
| 2808 | * |
| 2809 | * Reads the SAN MAC address from the EEPROM, if it's available. This is |
| 2810 | * per-port, so set_lan_id() must be called before reading the addresses. |
| 2811 | * set_lan_id() is called by identify_sfp(), but this cannot be relied |
| 2812 | * upon for non-SFP connections, so we must call it here. |
| 2813 | **/ |
| 2814 | s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr) |
| 2815 | { |
| 2816 | u16 san_mac_data, san_mac_offset; |
| 2817 | u8 i; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2818 | s32 ret_val; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2819 | |
| 2820 | /* |
| 2821 | * First read the EEPROM pointer to see if the MAC addresses are |
| 2822 | * available. If they're not, no point in calling set_lan_id() here. |
| 2823 | */ |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2824 | ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset); |
| 2825 | if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2826 | |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2827 | goto san_mac_addr_clr; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2828 | |
| 2829 | /* make sure we know which port we need to program */ |
| 2830 | hw->mac.ops.set_lan_id(hw); |
| 2831 | /* apply the port offset to the address offset */ |
| 2832 | (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) : |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2833 | (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2834 | for (i = 0; i < 3; i++) { |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2835 | ret_val = hw->eeprom.ops.read(hw, san_mac_offset, |
| 2836 | &san_mac_data); |
| 2837 | if (ret_val) { |
| 2838 | hw_err(hw, "eeprom read at offset %d failed\n", |
| 2839 | san_mac_offset); |
| 2840 | goto san_mac_addr_clr; |
| 2841 | } |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2842 | san_mac_addr[i * 2] = (u8)(san_mac_data); |
| 2843 | san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8); |
| 2844 | san_mac_offset++; |
| 2845 | } |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2846 | return 0; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 2847 | |
| 2848 | san_mac_addr_clr: |
| 2849 | /* No addresses available in this EEPROM. It's not necessarily an |
| 2850 | * error though, so just wipe the local address and return. |
| 2851 | */ |
| 2852 | for (i = 0; i < 6; i++) |
| 2853 | san_mac_addr[i] = 0xFF; |
| 2854 | return ret_val; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /** |
| 2858 | * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count |
| 2859 | * @hw: pointer to hardware structure |
| 2860 | * |
| 2861 | * Read PCIe configuration space, and get the MSI-X vector count from |
| 2862 | * the capabilities table. |
| 2863 | **/ |
Emil Tantilov | 7116130 | 2012-03-22 03:00:29 +0000 | [diff] [blame] | 2864 | u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2865 | { |
Emil Tantilov | 7116130 | 2012-03-22 03:00:29 +0000 | [diff] [blame] | 2866 | u16 msix_count = 1; |
| 2867 | u16 max_msix_count; |
| 2868 | u16 pcie_offset; |
| 2869 | |
| 2870 | switch (hw->mac.type) { |
| 2871 | case ixgbe_mac_82598EB: |
| 2872 | pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS; |
| 2873 | max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598; |
| 2874 | break; |
| 2875 | case ixgbe_mac_82599EB: |
| 2876 | case ixgbe_mac_X540: |
| 2877 | pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS; |
| 2878 | max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599; |
| 2879 | break; |
| 2880 | default: |
| 2881 | return msix_count; |
| 2882 | } |
| 2883 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 2884 | msix_count = ixgbe_read_pci_cfg_word(hw, pcie_offset); |
| 2885 | if (ixgbe_removed(hw->hw_addr)) |
| 2886 | msix_count = 0; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2887 | msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK; |
| 2888 | |
Emil Tantilov | 7116130 | 2012-03-22 03:00:29 +0000 | [diff] [blame] | 2889 | /* MSI-X count is zero-based in HW */ |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2890 | msix_count++; |
| 2891 | |
Emil Tantilov | 7116130 | 2012-03-22 03:00:29 +0000 | [diff] [blame] | 2892 | if (msix_count > max_msix_count) |
| 2893 | msix_count = max_msix_count; |
| 2894 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2895 | return msix_count; |
| 2896 | } |
| 2897 | |
| 2898 | /** |
| 2899 | * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address |
| 2900 | * @hw: pointer to hardware struct |
| 2901 | * @rar: receive address register index to disassociate |
| 2902 | * @vmdq: VMDq pool index to remove from the rar |
| 2903 | **/ |
| 2904 | s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) |
| 2905 | { |
| 2906 | u32 mpsar_lo, mpsar_hi; |
| 2907 | u32 rar_entries = hw->mac.num_rar_entries; |
| 2908 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2909 | /* Make sure we are using a valid rar index range */ |
| 2910 | if (rar >= rar_entries) { |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2911 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2912 | return IXGBE_ERR_INVALID_ARGUMENT; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2915 | mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); |
| 2916 | mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); |
| 2917 | |
Mark Rustad | 19458bd | 2014-03-01 05:21:00 +0000 | [diff] [blame] | 2918 | if (ixgbe_removed(hw->hw_addr)) |
| 2919 | goto done; |
| 2920 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2921 | if (!mpsar_lo && !mpsar_hi) |
| 2922 | goto done; |
| 2923 | |
| 2924 | if (vmdq == IXGBE_CLEAR_VMDQ_ALL) { |
| 2925 | if (mpsar_lo) { |
| 2926 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0); |
| 2927 | mpsar_lo = 0; |
| 2928 | } |
| 2929 | if (mpsar_hi) { |
| 2930 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0); |
| 2931 | mpsar_hi = 0; |
| 2932 | } |
| 2933 | } else if (vmdq < 32) { |
| 2934 | mpsar_lo &= ~(1 << vmdq); |
| 2935 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo); |
| 2936 | } else { |
| 2937 | mpsar_hi &= ~(1 << (vmdq - 32)); |
| 2938 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi); |
| 2939 | } |
| 2940 | |
| 2941 | /* was that the last pool using this rar? */ |
| 2942 | if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0) |
| 2943 | hw->mac.ops.clear_rar(hw, rar); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2944 | done: |
| 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | /** |
| 2949 | * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address |
| 2950 | * @hw: pointer to hardware struct |
| 2951 | * @rar: receive address register index to associate with a VMDq index |
| 2952 | * @vmdq: VMDq pool index |
| 2953 | **/ |
| 2954 | s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) |
| 2955 | { |
| 2956 | u32 mpsar; |
| 2957 | u32 rar_entries = hw->mac.num_rar_entries; |
| 2958 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2959 | /* Make sure we are using a valid rar index range */ |
| 2960 | if (rar >= rar_entries) { |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2961 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2962 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 2963 | } |
| 2964 | |
| 2965 | if (vmdq < 32) { |
| 2966 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); |
| 2967 | mpsar |= 1 << vmdq; |
| 2968 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar); |
| 2969 | } else { |
| 2970 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); |
| 2971 | mpsar |= 1 << (vmdq - 32); |
| 2972 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2973 | } |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | /** |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 2978 | * This function should only be involved in the IOV mode. |
| 2979 | * In IOV mode, Default pool is next pool after the number of |
| 2980 | * VFs advertized and not 0. |
| 2981 | * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index] |
| 2982 | * |
| 2983 | * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address |
| 2984 | * @hw: pointer to hardware struct |
| 2985 | * @vmdq: VMDq pool index |
| 2986 | **/ |
| 2987 | s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq) |
| 2988 | { |
| 2989 | u32 rar = hw->mac.san_mac_rar_index; |
| 2990 | |
| 2991 | if (vmdq < 32) { |
| 2992 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq); |
| 2993 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0); |
| 2994 | } else { |
| 2995 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0); |
| 2996 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32)); |
| 2997 | } |
| 2998 | |
| 2999 | return 0; |
| 3000 | } |
| 3001 | |
| 3002 | /** |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3003 | * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array |
| 3004 | * @hw: pointer to hardware structure |
| 3005 | **/ |
| 3006 | s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw) |
| 3007 | { |
| 3008 | int i; |
| 3009 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3010 | for (i = 0; i < 128; i++) |
| 3011 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0); |
| 3012 | |
| 3013 | return 0; |
| 3014 | } |
| 3015 | |
| 3016 | /** |
| 3017 | * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot |
| 3018 | * @hw: pointer to hardware structure |
| 3019 | * @vlan: VLAN id to write to VLAN filter |
| 3020 | * |
| 3021 | * return the VLVF index where this VLAN id should be placed |
| 3022 | * |
| 3023 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 3024 | static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3025 | { |
| 3026 | u32 bits = 0; |
| 3027 | u32 first_empty_slot = 0; |
| 3028 | s32 regindex; |
| 3029 | |
| 3030 | /* short cut the special case */ |
| 3031 | if (vlan == 0) |
| 3032 | return 0; |
| 3033 | |
| 3034 | /* |
| 3035 | * Search for the vlan id in the VLVF entries. Save off the first empty |
| 3036 | * slot found along the way |
| 3037 | */ |
| 3038 | for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) { |
| 3039 | bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex)); |
| 3040 | if (!bits && !(first_empty_slot)) |
| 3041 | first_empty_slot = regindex; |
| 3042 | else if ((bits & 0x0FFF) == vlan) |
| 3043 | break; |
| 3044 | } |
| 3045 | |
| 3046 | /* |
| 3047 | * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan |
| 3048 | * in the VLVF. Else use the first empty VLVF register for this |
| 3049 | * vlan id. |
| 3050 | */ |
| 3051 | if (regindex >= IXGBE_VLVF_ENTRIES) { |
| 3052 | if (first_empty_slot) |
| 3053 | regindex = first_empty_slot; |
| 3054 | else { |
| 3055 | hw_dbg(hw, "No space in VLVF.\n"); |
| 3056 | regindex = IXGBE_ERR_NO_SPACE; |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | return regindex; |
| 3061 | } |
| 3062 | |
| 3063 | /** |
| 3064 | * ixgbe_set_vfta_generic - Set VLAN filter table |
| 3065 | * @hw: pointer to hardware structure |
| 3066 | * @vlan: VLAN id to write to VLAN filter |
| 3067 | * @vind: VMDq output index that maps queue to VLAN id in VFVFB |
| 3068 | * @vlan_on: boolean flag to turn on/off VLAN in VFVF |
| 3069 | * |
| 3070 | * Turn on/off specified VLAN in the VLAN filter table. |
| 3071 | **/ |
| 3072 | s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 3073 | bool vlan_on) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3074 | { |
| 3075 | s32 regindex; |
| 3076 | u32 bitindex; |
| 3077 | u32 vfta; |
| 3078 | u32 bits; |
| 3079 | u32 vt; |
| 3080 | u32 targetbit; |
| 3081 | bool vfta_changed = false; |
| 3082 | |
| 3083 | if (vlan > 4095) |
| 3084 | return IXGBE_ERR_PARAM; |
| 3085 | |
| 3086 | /* |
| 3087 | * this is a 2 part operation - first the VFTA, then the |
| 3088 | * VLVF and VLVFB if VT Mode is set |
| 3089 | * We don't write the VFTA until we know the VLVF part succeeded. |
| 3090 | */ |
| 3091 | |
| 3092 | /* Part 1 |
| 3093 | * The VFTA is a bitstring made up of 128 32-bit registers |
| 3094 | * that enable the particular VLAN id, much like the MTA: |
| 3095 | * bits[11-5]: which register |
| 3096 | * bits[4-0]: which bit in the register |
| 3097 | */ |
| 3098 | regindex = (vlan >> 5) & 0x7F; |
| 3099 | bitindex = vlan & 0x1F; |
| 3100 | targetbit = (1 << bitindex); |
| 3101 | vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex)); |
| 3102 | |
| 3103 | if (vlan_on) { |
| 3104 | if (!(vfta & targetbit)) { |
| 3105 | vfta |= targetbit; |
| 3106 | vfta_changed = true; |
| 3107 | } |
| 3108 | } else { |
| 3109 | if ((vfta & targetbit)) { |
| 3110 | vfta &= ~targetbit; |
| 3111 | vfta_changed = true; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /* Part 2 |
| 3116 | * If VT Mode is set |
| 3117 | * Either vlan_on |
| 3118 | * make sure the vlan is in VLVF |
| 3119 | * set the vind bit in the matching VLVFB |
| 3120 | * Or !vlan_on |
| 3121 | * clear the pool bit and possibly the vind |
| 3122 | */ |
| 3123 | vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3124 | if (vt & IXGBE_VT_CTL_VT_ENABLE) { |
| 3125 | s32 vlvf_index; |
| 3126 | |
| 3127 | vlvf_index = ixgbe_find_vlvf_slot(hw, vlan); |
| 3128 | if (vlvf_index < 0) |
| 3129 | return vlvf_index; |
| 3130 | |
| 3131 | if (vlan_on) { |
| 3132 | /* set the pool bit */ |
| 3133 | if (vind < 32) { |
| 3134 | bits = IXGBE_READ_REG(hw, |
| 3135 | IXGBE_VLVFB(vlvf_index*2)); |
| 3136 | bits |= (1 << vind); |
| 3137 | IXGBE_WRITE_REG(hw, |
| 3138 | IXGBE_VLVFB(vlvf_index*2), |
| 3139 | bits); |
| 3140 | } else { |
| 3141 | bits = IXGBE_READ_REG(hw, |
| 3142 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 3143 | bits |= (1 << (vind-32)); |
| 3144 | IXGBE_WRITE_REG(hw, |
| 3145 | IXGBE_VLVFB((vlvf_index*2)+1), |
| 3146 | bits); |
| 3147 | } |
| 3148 | } else { |
| 3149 | /* clear the pool bit */ |
| 3150 | if (vind < 32) { |
| 3151 | bits = IXGBE_READ_REG(hw, |
| 3152 | IXGBE_VLVFB(vlvf_index*2)); |
| 3153 | bits &= ~(1 << vind); |
| 3154 | IXGBE_WRITE_REG(hw, |
| 3155 | IXGBE_VLVFB(vlvf_index*2), |
| 3156 | bits); |
| 3157 | bits |= IXGBE_READ_REG(hw, |
| 3158 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 3159 | } else { |
| 3160 | bits = IXGBE_READ_REG(hw, |
| 3161 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 3162 | bits &= ~(1 << (vind-32)); |
| 3163 | IXGBE_WRITE_REG(hw, |
| 3164 | IXGBE_VLVFB((vlvf_index*2)+1), |
| 3165 | bits); |
| 3166 | bits |= IXGBE_READ_REG(hw, |
| 3167 | IXGBE_VLVFB(vlvf_index*2)); |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | /* |
| 3172 | * If there are still bits set in the VLVFB registers |
| 3173 | * for the VLAN ID indicated we need to see if the |
| 3174 | * caller is requesting that we clear the VFTA entry bit. |
| 3175 | * If the caller has requested that we clear the VFTA |
| 3176 | * entry bit but there are still pools/VFs using this VLAN |
| 3177 | * ID entry then ignore the request. We're not worried |
| 3178 | * about the case where we're turning the VFTA VLAN ID |
| 3179 | * entry bit on, only when requested to turn it off as |
| 3180 | * there may be multiple pools and/or VFs using the |
| 3181 | * VLAN ID entry. In that case we cannot clear the |
| 3182 | * VFTA bit until all pools/VFs using that VLAN ID have also |
| 3183 | * been cleared. This will be indicated by "bits" being |
| 3184 | * zero. |
| 3185 | */ |
| 3186 | if (bits) { |
| 3187 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), |
| 3188 | (IXGBE_VLVF_VIEN | vlan)); |
| 3189 | if (!vlan_on) { |
| 3190 | /* someone wants to clear the vfta entry |
| 3191 | * but some pools/VFs are still using it. |
| 3192 | * Ignore it. */ |
| 3193 | vfta_changed = false; |
| 3194 | } |
Jacob Keller | 63b64de | 2014-04-09 06:03:14 +0000 | [diff] [blame] | 3195 | } else { |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3196 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0); |
Jacob Keller | 63b64de | 2014-04-09 06:03:14 +0000 | [diff] [blame] | 3197 | } |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | if (vfta_changed) |
| 3201 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta); |
| 3202 | |
| 3203 | return 0; |
| 3204 | } |
| 3205 | |
| 3206 | /** |
| 3207 | * ixgbe_clear_vfta_generic - Clear VLAN filter table |
| 3208 | * @hw: pointer to hardware structure |
| 3209 | * |
| 3210 | * Clears the VLAN filer table, and the VMDq index associated with the filter |
| 3211 | **/ |
| 3212 | s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw) |
| 3213 | { |
| 3214 | u32 offset; |
| 3215 | |
| 3216 | for (offset = 0; offset < hw->mac.vft_size; offset++) |
| 3217 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); |
| 3218 | |
| 3219 | for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) { |
| 3220 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0); |
| 3221 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0); |
| 3222 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0); |
| 3223 | } |
| 3224 | |
| 3225 | return 0; |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * ixgbe_check_mac_link_generic - Determine link and speed status |
| 3230 | * @hw: pointer to hardware structure |
| 3231 | * @speed: pointer to link speed |
| 3232 | * @link_up: true when link is up |
| 3233 | * @link_up_wait_to_complete: bool used to wait for link up or not |
| 3234 | * |
| 3235 | * Reads the links register to determine if link is up and the current speed |
| 3236 | **/ |
| 3237 | s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed, |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 3238 | bool *link_up, bool link_up_wait_to_complete) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3239 | { |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 3240 | u32 links_reg, links_orig; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3241 | u32 i; |
| 3242 | |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 3243 | /* clear the old state */ |
| 3244 | links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 3245 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3246 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 3247 | |
| 3248 | if (links_orig != links_reg) { |
| 3249 | hw_dbg(hw, "LINKS changed from %08X to %08X\n", |
| 3250 | links_orig, links_reg); |
| 3251 | } |
| 3252 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3253 | if (link_up_wait_to_complete) { |
| 3254 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { |
| 3255 | if (links_reg & IXGBE_LINKS_UP) { |
| 3256 | *link_up = true; |
| 3257 | break; |
| 3258 | } else { |
| 3259 | *link_up = false; |
| 3260 | } |
| 3261 | msleep(100); |
| 3262 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 3263 | } |
| 3264 | } else { |
| 3265 | if (links_reg & IXGBE_LINKS_UP) |
| 3266 | *link_up = true; |
| 3267 | else |
| 3268 | *link_up = false; |
| 3269 | } |
| 3270 | |
| 3271 | if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
| 3272 | IXGBE_LINKS_SPEED_10G_82599) |
| 3273 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 3274 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 3275 | IXGBE_LINKS_SPEED_1G_82599) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3276 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 3277 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
| 3278 | IXGBE_LINKS_SPEED_100_82599) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3279 | *speed = IXGBE_LINK_SPEED_100_FULL; |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 3280 | else |
| 3281 | *speed = IXGBE_LINK_SPEED_UNKNOWN; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3282 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 3283 | return 0; |
| 3284 | } |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3285 | |
| 3286 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3287 | * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3288 | * the EEPROM |
| 3289 | * @hw: pointer to hardware structure |
| 3290 | * @wwnn_prefix: the alternative WWNN prefix |
| 3291 | * @wwpn_prefix: the alternative WWPN prefix |
| 3292 | * |
| 3293 | * This function will read the EEPROM from the alternative SAN MAC address |
| 3294 | * block to check the support for the alternative WWNN/WWPN prefix support. |
| 3295 | **/ |
| 3296 | s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 3297 | u16 *wwpn_prefix) |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3298 | { |
| 3299 | u16 offset, caps; |
| 3300 | u16 alt_san_mac_blk_offset; |
| 3301 | |
| 3302 | /* clear output first */ |
| 3303 | *wwnn_prefix = 0xFFFF; |
| 3304 | *wwpn_prefix = 0xFFFF; |
| 3305 | |
| 3306 | /* check if alternative SAN MAC is supported */ |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3307 | offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR; |
| 3308 | if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset)) |
| 3309 | goto wwn_prefix_err; |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3310 | |
| 3311 | if ((alt_san_mac_blk_offset == 0) || |
| 3312 | (alt_san_mac_blk_offset == 0xFFFF)) |
| 3313 | goto wwn_prefix_out; |
| 3314 | |
| 3315 | /* check capability in alternative san mac address block */ |
| 3316 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3317 | if (hw->eeprom.ops.read(hw, offset, &caps)) |
| 3318 | goto wwn_prefix_err; |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3319 | if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN)) |
| 3320 | goto wwn_prefix_out; |
| 3321 | |
| 3322 | /* get the corresponding prefix for WWNN/WWPN */ |
| 3323 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3324 | if (hw->eeprom.ops.read(hw, offset, wwnn_prefix)) |
| 3325 | hw_err(hw, "eeprom read at offset %d failed\n", offset); |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3326 | |
| 3327 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3328 | if (hw->eeprom.ops.read(hw, offset, wwpn_prefix)) |
| 3329 | goto wwn_prefix_err; |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3330 | |
| 3331 | wwn_prefix_out: |
| 3332 | return 0; |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3333 | |
| 3334 | wwn_prefix_err: |
| 3335 | hw_err(hw, "eeprom read at offset %d failed\n", offset); |
| 3336 | return 0; |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 3337 | } |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3338 | |
| 3339 | /** |
| 3340 | * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing |
| 3341 | * @hw: pointer to hardware structure |
| 3342 | * @enable: enable or disable switch for anti-spoofing |
| 3343 | * @pf: Physical Function pool - do not enable anti-spoofing for the PF |
| 3344 | * |
| 3345 | **/ |
| 3346 | void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf) |
| 3347 | { |
| 3348 | int j; |
| 3349 | int pf_target_reg = pf >> 3; |
| 3350 | int pf_target_shift = pf % 8; |
| 3351 | u32 pfvfspoof = 0; |
| 3352 | |
| 3353 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3354 | return; |
| 3355 | |
| 3356 | if (enable) |
| 3357 | pfvfspoof = IXGBE_SPOOF_MACAS_MASK; |
| 3358 | |
| 3359 | /* |
| 3360 | * PFVFSPOOF register array is size 8 with 8 bits assigned to |
| 3361 | * MAC anti-spoof enables in each register array element. |
| 3362 | */ |
Alexander Duyck | ef89e0a | 2012-05-05 05:32:58 +0000 | [diff] [blame] | 3363 | for (j = 0; j < pf_target_reg; j++) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3364 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof); |
| 3365 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3366 | /* |
| 3367 | * The PF should be allowed to spoof so that it can support |
Alexander Duyck | ef89e0a | 2012-05-05 05:32:58 +0000 | [diff] [blame] | 3368 | * emulation mode NICs. Do not set the bits assigned to the PF |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3369 | */ |
Alexander Duyck | ef89e0a | 2012-05-05 05:32:58 +0000 | [diff] [blame] | 3370 | pfvfspoof &= (1 << pf_target_shift) - 1; |
| 3371 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof); |
| 3372 | |
| 3373 | /* |
| 3374 | * Remaining pools belong to the PF so they do not need to have |
| 3375 | * anti-spoofing enabled. |
| 3376 | */ |
| 3377 | for (j++; j < IXGBE_PFVFSPOOF_REG_COUNT; j++) |
| 3378 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), 0); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | /** |
| 3382 | * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing |
| 3383 | * @hw: pointer to hardware structure |
| 3384 | * @enable: enable or disable switch for VLAN anti-spoofing |
| 3385 | * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing |
| 3386 | * |
| 3387 | **/ |
| 3388 | void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf) |
| 3389 | { |
| 3390 | int vf_target_reg = vf >> 3; |
| 3391 | int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT; |
| 3392 | u32 pfvfspoof; |
| 3393 | |
| 3394 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3395 | return; |
| 3396 | |
| 3397 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); |
| 3398 | if (enable) |
| 3399 | pfvfspoof |= (1 << vf_target_shift); |
| 3400 | else |
| 3401 | pfvfspoof &= ~(1 << vf_target_shift); |
| 3402 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof); |
| 3403 | } |
Emil Tantilov | b776d10 | 2011-03-31 09:36:18 +0000 | [diff] [blame] | 3404 | |
| 3405 | /** |
| 3406 | * ixgbe_get_device_caps_generic - Get additional device capabilities |
| 3407 | * @hw: pointer to hardware structure |
| 3408 | * @device_caps: the EEPROM word with the extra device capabilities |
| 3409 | * |
| 3410 | * This function will read the EEPROM location for the device capabilities, |
| 3411 | * and return the word through device_caps. |
| 3412 | **/ |
| 3413 | s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps) |
| 3414 | { |
| 3415 | hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps); |
| 3416 | |
| 3417 | return 0; |
| 3418 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3419 | |
| 3420 | /** |
| 3421 | * ixgbe_set_rxpba_generic - Initialize RX packet buffer |
| 3422 | * @hw: pointer to hardware structure |
| 3423 | * @num_pb: number of packet buffers to allocate |
| 3424 | * @headroom: reserve n KB of headroom |
| 3425 | * @strategy: packet buffer allocation strategy |
| 3426 | **/ |
| 3427 | void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, |
| 3428 | int num_pb, |
| 3429 | u32 headroom, |
| 3430 | int strategy) |
| 3431 | { |
| 3432 | u32 pbsize = hw->mac.rx_pb_size; |
| 3433 | int i = 0; |
| 3434 | u32 rxpktsize, txpktsize, txpbthresh; |
| 3435 | |
| 3436 | /* Reserve headroom */ |
| 3437 | pbsize -= headroom; |
| 3438 | |
| 3439 | if (!num_pb) |
| 3440 | num_pb = 1; |
| 3441 | |
| 3442 | /* Divide remaining packet buffer space amongst the number |
| 3443 | * of packet buffers requested using supplied strategy. |
| 3444 | */ |
| 3445 | switch (strategy) { |
| 3446 | case (PBA_STRATEGY_WEIGHTED): |
| 3447 | /* pba_80_48 strategy weight first half of packet buffer with |
| 3448 | * 5/8 of the packet buffer space. |
| 3449 | */ |
| 3450 | rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8)); |
| 3451 | pbsize -= rxpktsize * (num_pb / 2); |
| 3452 | rxpktsize <<= IXGBE_RXPBSIZE_SHIFT; |
| 3453 | for (; i < (num_pb / 2); i++) |
| 3454 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); |
| 3455 | /* Fall through to configure remaining packet buffers */ |
| 3456 | case (PBA_STRATEGY_EQUAL): |
| 3457 | /* Divide the remaining Rx packet buffer evenly among the TCs */ |
| 3458 | rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT; |
| 3459 | for (; i < num_pb; i++) |
| 3460 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize); |
| 3461 | break; |
| 3462 | default: |
| 3463 | break; |
| 3464 | } |
| 3465 | |
| 3466 | /* |
| 3467 | * Setup Tx packet buffer and threshold equally for all TCs |
| 3468 | * TXPBTHRESH register is set in K so divide by 1024 and subtract |
| 3469 | * 10 since the largest packet we support is just over 9K. |
| 3470 | */ |
| 3471 | txpktsize = IXGBE_TXPBSIZE_MAX / num_pb; |
| 3472 | txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX; |
| 3473 | for (i = 0; i < num_pb; i++) { |
| 3474 | IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize); |
| 3475 | IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh); |
| 3476 | } |
| 3477 | |
| 3478 | /* Clear unused TCs, if any, to zero buffer size*/ |
| 3479 | for (; i < IXGBE_MAX_PB; i++) { |
| 3480 | IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0); |
| 3481 | IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0); |
| 3482 | IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0); |
| 3483 | } |
| 3484 | } |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3485 | |
| 3486 | /** |
| 3487 | * ixgbe_calculate_checksum - Calculate checksum for buffer |
| 3488 | * @buffer: pointer to EEPROM |
| 3489 | * @length: size of EEPROM to calculate a checksum for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3490 | * |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3491 | * Calculates the checksum for some buffer on a specified length. The |
| 3492 | * checksum calculated is returned. |
| 3493 | **/ |
| 3494 | static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length) |
| 3495 | { |
| 3496 | u32 i; |
| 3497 | u8 sum = 0; |
| 3498 | |
| 3499 | if (!buffer) |
| 3500 | return 0; |
| 3501 | |
| 3502 | for (i = 0; i < length; i++) |
| 3503 | sum += buffer[i]; |
| 3504 | |
| 3505 | return (u8) (0 - sum); |
| 3506 | } |
| 3507 | |
| 3508 | /** |
| 3509 | * ixgbe_host_interface_command - Issue command to manageability block |
| 3510 | * @hw: pointer to the HW structure |
| 3511 | * @buffer: contains the command to write and where the return status will |
| 3512 | * be placed |
Don Skidmore | c466d7a | 2012-02-28 06:35:54 +0000 | [diff] [blame] | 3513 | * @length: length of buffer, must be multiple of 4 bytes |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3514 | * |
| 3515 | * Communicates with the manageability block. On success return 0 |
| 3516 | * else return IXGBE_ERR_HOST_INTERFACE_COMMAND. |
| 3517 | **/ |
Emil Tantilov | 79488c5 | 2011-10-11 08:24:57 +0000 | [diff] [blame] | 3518 | static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer, |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3519 | u32 length) |
| 3520 | { |
Emil Tantilov | 331bcf4 | 2011-10-22 05:21:32 +0000 | [diff] [blame] | 3521 | u32 hicr, i, bi; |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3522 | u32 hdr_size = sizeof(struct ixgbe_hic_hdr); |
| 3523 | u8 buf_len, dword_len; |
| 3524 | |
| 3525 | s32 ret_val = 0; |
| 3526 | |
| 3527 | if (length == 0 || length & 0x3 || |
| 3528 | length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) { |
| 3529 | hw_dbg(hw, "Buffer length failure.\n"); |
| 3530 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; |
| 3531 | goto out; |
| 3532 | } |
| 3533 | |
| 3534 | /* Check that the host interface is enabled. */ |
| 3535 | hicr = IXGBE_READ_REG(hw, IXGBE_HICR); |
| 3536 | if ((hicr & IXGBE_HICR_EN) == 0) { |
| 3537 | hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n"); |
| 3538 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; |
| 3539 | goto out; |
| 3540 | } |
| 3541 | |
| 3542 | /* Calculate length in DWORDs */ |
| 3543 | dword_len = length >> 2; |
| 3544 | |
| 3545 | /* |
| 3546 | * The device driver writes the relevant command block |
| 3547 | * into the ram area. |
| 3548 | */ |
| 3549 | for (i = 0; i < dword_len; i++) |
| 3550 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG, |
Emil Tantilov | 79488c5 | 2011-10-11 08:24:57 +0000 | [diff] [blame] | 3551 | i, cpu_to_le32(buffer[i])); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3552 | |
| 3553 | /* Setting this bit tells the ARC that a new command is pending. */ |
| 3554 | IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C); |
| 3555 | |
| 3556 | for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) { |
| 3557 | hicr = IXGBE_READ_REG(hw, IXGBE_HICR); |
| 3558 | if (!(hicr & IXGBE_HICR_C)) |
| 3559 | break; |
| 3560 | usleep_range(1000, 2000); |
| 3561 | } |
| 3562 | |
| 3563 | /* Check command successful completion. */ |
| 3564 | if (i == IXGBE_HI_COMMAND_TIMEOUT || |
| 3565 | (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) { |
| 3566 | hw_dbg(hw, "Command has failed with no status valid.\n"); |
| 3567 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; |
| 3568 | goto out; |
| 3569 | } |
| 3570 | |
| 3571 | /* Calculate length in DWORDs */ |
| 3572 | dword_len = hdr_size >> 2; |
| 3573 | |
| 3574 | /* first pull in the header so we know the buffer length */ |
Emil Tantilov | 331bcf4 | 2011-10-22 05:21:32 +0000 | [diff] [blame] | 3575 | for (bi = 0; bi < dword_len; bi++) { |
| 3576 | buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi); |
| 3577 | le32_to_cpus(&buffer[bi]); |
Emil Tantilov | 79488c5 | 2011-10-11 08:24:57 +0000 | [diff] [blame] | 3578 | } |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3579 | |
| 3580 | /* If there is any thing in data position pull it in */ |
| 3581 | buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len; |
| 3582 | if (buf_len == 0) |
| 3583 | goto out; |
| 3584 | |
| 3585 | if (length < (buf_len + hdr_size)) { |
| 3586 | hw_dbg(hw, "Buffer not large enough for reply message.\n"); |
| 3587 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; |
| 3588 | goto out; |
| 3589 | } |
| 3590 | |
Emil Tantilov | 331bcf4 | 2011-10-22 05:21:32 +0000 | [diff] [blame] | 3591 | /* Calculate length in DWORDs, add 3 for odd lengths */ |
| 3592 | dword_len = (buf_len + 3) >> 2; |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3593 | |
Emil Tantilov | 331bcf4 | 2011-10-22 05:21:32 +0000 | [diff] [blame] | 3594 | /* Pull in the rest of the buffer (bi is where we left off)*/ |
| 3595 | for (; bi <= dword_len; bi++) { |
| 3596 | buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi); |
| 3597 | le32_to_cpus(&buffer[bi]); |
| 3598 | } |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3599 | |
| 3600 | out: |
| 3601 | return ret_val; |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware |
| 3606 | * @hw: pointer to the HW structure |
| 3607 | * @maj: driver version major number |
| 3608 | * @min: driver version minor number |
| 3609 | * @build: driver version build number |
| 3610 | * @sub: driver version sub build number |
| 3611 | * |
| 3612 | * Sends driver version number to firmware through the manageability |
| 3613 | * block. On success return 0 |
| 3614 | * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring |
| 3615 | * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails. |
| 3616 | **/ |
| 3617 | s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min, |
| 3618 | u8 build, u8 sub) |
| 3619 | { |
| 3620 | struct ixgbe_hic_drv_info fw_cmd; |
| 3621 | int i; |
| 3622 | s32 ret_val = 0; |
| 3623 | |
| 3624 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM) != 0) { |
| 3625 | ret_val = IXGBE_ERR_SWFW_SYNC; |
| 3626 | goto out; |
| 3627 | } |
| 3628 | |
| 3629 | fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO; |
| 3630 | fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN; |
| 3631 | fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED; |
| 3632 | fw_cmd.port_num = (u8)hw->bus.func; |
| 3633 | fw_cmd.ver_maj = maj; |
| 3634 | fw_cmd.ver_min = min; |
| 3635 | fw_cmd.ver_build = build; |
| 3636 | fw_cmd.ver_sub = sub; |
| 3637 | fw_cmd.hdr.checksum = 0; |
| 3638 | fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd, |
| 3639 | (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len)); |
| 3640 | fw_cmd.pad = 0; |
| 3641 | fw_cmd.pad2 = 0; |
| 3642 | |
| 3643 | for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) { |
Emil Tantilov | 79488c5 | 2011-10-11 08:24:57 +0000 | [diff] [blame] | 3644 | ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd, |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 3645 | sizeof(fw_cmd)); |
| 3646 | if (ret_val != 0) |
| 3647 | continue; |
| 3648 | |
| 3649 | if (fw_cmd.hdr.cmd_or_resp.ret_status == |
| 3650 | FW_CEM_RESP_STATUS_SUCCESS) |
| 3651 | ret_val = 0; |
| 3652 | else |
| 3653 | ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND; |
| 3654 | |
| 3655 | break; |
| 3656 | } |
| 3657 | |
| 3658 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM); |
| 3659 | out: |
| 3660 | return ret_val; |
| 3661 | } |
Emil Tantilov | ff9d1a5 | 2011-08-16 04:35:11 +0000 | [diff] [blame] | 3662 | |
| 3663 | /** |
| 3664 | * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo |
| 3665 | * @hw: pointer to the hardware structure |
| 3666 | * |
| 3667 | * The 82599 and x540 MACs can experience issues if TX work is still pending |
| 3668 | * when a reset occurs. This function prevents this by flushing the PCIe |
| 3669 | * buffers on the system. |
| 3670 | **/ |
| 3671 | void ixgbe_clear_tx_pending(struct ixgbe_hw *hw) |
| 3672 | { |
| 3673 | u32 gcr_ext, hlreg0; |
| 3674 | |
| 3675 | /* |
| 3676 | * If double reset is not requested then all transactions should |
| 3677 | * already be clear and as such there is no work to do |
| 3678 | */ |
| 3679 | if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED)) |
| 3680 | return; |
| 3681 | |
| 3682 | /* |
| 3683 | * Set loopback enable to prevent any transmits from being sent |
| 3684 | * should the link come up. This assumes that the RXCTRL.RXEN bit |
| 3685 | * has already been cleared. |
| 3686 | */ |
| 3687 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 3688 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK); |
| 3689 | |
| 3690 | /* initiate cleaning flow for buffers in the PCIe transaction layer */ |
| 3691 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3692 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, |
| 3693 | gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR); |
| 3694 | |
| 3695 | /* Flush all writes and allow 20usec for all transactions to clear */ |
| 3696 | IXGBE_WRITE_FLUSH(hw); |
| 3697 | udelay(20); |
| 3698 | |
| 3699 | /* restore previous register values */ |
| 3700 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3701 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3702 | } |
Don Skidmore | e1ea915 | 2012-02-17 02:38:58 +0000 | [diff] [blame] | 3703 | |
| 3704 | static const u8 ixgbe_emc_temp_data[4] = { |
| 3705 | IXGBE_EMC_INTERNAL_DATA, |
| 3706 | IXGBE_EMC_DIODE1_DATA, |
| 3707 | IXGBE_EMC_DIODE2_DATA, |
| 3708 | IXGBE_EMC_DIODE3_DATA |
| 3709 | }; |
| 3710 | static const u8 ixgbe_emc_therm_limit[4] = { |
| 3711 | IXGBE_EMC_INTERNAL_THERM_LIMIT, |
| 3712 | IXGBE_EMC_DIODE1_THERM_LIMIT, |
| 3713 | IXGBE_EMC_DIODE2_THERM_LIMIT, |
| 3714 | IXGBE_EMC_DIODE3_THERM_LIMIT |
| 3715 | }; |
| 3716 | |
| 3717 | /** |
| 3718 | * ixgbe_get_ets_data - Extracts the ETS bit data |
| 3719 | * @hw: pointer to hardware structure |
| 3720 | * @ets_cfg: extected ETS data |
| 3721 | * @ets_offset: offset of ETS data |
| 3722 | * |
| 3723 | * Returns error code. |
| 3724 | **/ |
| 3725 | static s32 ixgbe_get_ets_data(struct ixgbe_hw *hw, u16 *ets_cfg, |
| 3726 | u16 *ets_offset) |
| 3727 | { |
| 3728 | s32 status = 0; |
| 3729 | |
| 3730 | status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, ets_offset); |
| 3731 | if (status) |
| 3732 | goto out; |
| 3733 | |
| 3734 | if ((*ets_offset == 0x0000) || (*ets_offset == 0xFFFF)) { |
| 3735 | status = IXGBE_NOT_IMPLEMENTED; |
| 3736 | goto out; |
| 3737 | } |
| 3738 | |
| 3739 | status = hw->eeprom.ops.read(hw, *ets_offset, ets_cfg); |
| 3740 | if (status) |
| 3741 | goto out; |
| 3742 | |
| 3743 | if ((*ets_cfg & IXGBE_ETS_TYPE_MASK) != IXGBE_ETS_TYPE_EMC_SHIFTED) { |
| 3744 | status = IXGBE_NOT_IMPLEMENTED; |
| 3745 | goto out; |
| 3746 | } |
| 3747 | |
| 3748 | out: |
| 3749 | return status; |
| 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data |
| 3754 | * @hw: pointer to hardware structure |
| 3755 | * |
| 3756 | * Returns the thermal sensor data structure |
| 3757 | **/ |
| 3758 | s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw) |
| 3759 | { |
| 3760 | s32 status = 0; |
| 3761 | u16 ets_offset; |
| 3762 | u16 ets_cfg; |
| 3763 | u16 ets_sensor; |
| 3764 | u8 num_sensors; |
| 3765 | u8 i; |
| 3766 | struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data; |
| 3767 | |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 3768 | /* Only support thermal sensors attached to physical port 0 */ |
| 3769 | if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) { |
Don Skidmore | e1ea915 | 2012-02-17 02:38:58 +0000 | [diff] [blame] | 3770 | status = IXGBE_NOT_IMPLEMENTED; |
| 3771 | goto out; |
| 3772 | } |
| 3773 | |
| 3774 | status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset); |
| 3775 | if (status) |
| 3776 | goto out; |
| 3777 | |
| 3778 | num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK); |
| 3779 | if (num_sensors > IXGBE_MAX_SENSORS) |
| 3780 | num_sensors = IXGBE_MAX_SENSORS; |
| 3781 | |
| 3782 | for (i = 0; i < num_sensors; i++) { |
| 3783 | u8 sensor_index; |
| 3784 | u8 sensor_location; |
| 3785 | |
| 3786 | status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i), |
| 3787 | &ets_sensor); |
| 3788 | if (status) |
| 3789 | goto out; |
| 3790 | |
| 3791 | sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >> |
| 3792 | IXGBE_ETS_DATA_INDEX_SHIFT); |
| 3793 | sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >> |
| 3794 | IXGBE_ETS_DATA_LOC_SHIFT); |
| 3795 | |
| 3796 | if (sensor_location != 0) { |
| 3797 | status = hw->phy.ops.read_i2c_byte(hw, |
| 3798 | ixgbe_emc_temp_data[sensor_index], |
| 3799 | IXGBE_I2C_THERMAL_SENSOR_ADDR, |
| 3800 | &data->sensor[i].temp); |
| 3801 | if (status) |
| 3802 | goto out; |
| 3803 | } |
| 3804 | } |
| 3805 | out: |
| 3806 | return status; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds |
| 3811 | * @hw: pointer to hardware structure |
| 3812 | * |
| 3813 | * Inits the thermal sensor thresholds according to the NVM map |
| 3814 | * and save off the threshold and location values into mac.thermal_sensor_data |
| 3815 | **/ |
| 3816 | s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw) |
| 3817 | { |
| 3818 | s32 status = 0; |
| 3819 | u16 ets_offset; |
| 3820 | u16 ets_cfg; |
| 3821 | u16 ets_sensor; |
| 3822 | u8 low_thresh_delta; |
| 3823 | u8 num_sensors; |
| 3824 | u8 therm_limit; |
| 3825 | u8 i; |
| 3826 | struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data; |
| 3827 | |
| 3828 | memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data)); |
| 3829 | |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 3830 | /* Only support thermal sensors attached to physical port 0 */ |
| 3831 | if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) { |
Don Skidmore | e1ea915 | 2012-02-17 02:38:58 +0000 | [diff] [blame] | 3832 | status = IXGBE_NOT_IMPLEMENTED; |
| 3833 | goto out; |
| 3834 | } |
| 3835 | |
| 3836 | status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset); |
| 3837 | if (status) |
| 3838 | goto out; |
| 3839 | |
| 3840 | low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >> |
| 3841 | IXGBE_ETS_LTHRES_DELTA_SHIFT); |
| 3842 | num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK); |
| 3843 | if (num_sensors > IXGBE_MAX_SENSORS) |
| 3844 | num_sensors = IXGBE_MAX_SENSORS; |
| 3845 | |
| 3846 | for (i = 0; i < num_sensors; i++) { |
| 3847 | u8 sensor_index; |
| 3848 | u8 sensor_location; |
| 3849 | |
Mark Rustad | be0c27b | 2013-05-24 07:31:09 +0000 | [diff] [blame] | 3850 | if (hw->eeprom.ops.read(hw, ets_offset + 1 + i, &ets_sensor)) { |
| 3851 | hw_err(hw, "eeprom read at offset %d failed\n", |
| 3852 | ets_offset + 1 + i); |
| 3853 | continue; |
| 3854 | } |
Don Skidmore | e1ea915 | 2012-02-17 02:38:58 +0000 | [diff] [blame] | 3855 | sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >> |
| 3856 | IXGBE_ETS_DATA_INDEX_SHIFT); |
| 3857 | sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >> |
| 3858 | IXGBE_ETS_DATA_LOC_SHIFT); |
| 3859 | therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK; |
| 3860 | |
| 3861 | hw->phy.ops.write_i2c_byte(hw, |
| 3862 | ixgbe_emc_therm_limit[sensor_index], |
| 3863 | IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit); |
| 3864 | |
| 3865 | if (sensor_location == 0) |
| 3866 | continue; |
| 3867 | |
| 3868 | data->sensor[i].location = sensor_location; |
| 3869 | data->sensor[i].caution_thresh = therm_limit; |
| 3870 | data->sensor[i].max_op_thresh = therm_limit - low_thresh_delta; |
| 3871 | } |
| 3872 | out: |
| 3873 | return status; |
| 3874 | } |
| 3875 | |