Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 Intel Corporation. |
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: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/sched.h> |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 31 | #include <linux/netdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 32 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 33 | #include "ixgbe.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 34 | #include "ixgbe_common.h" |
| 35 | #include "ixgbe_phy.h" |
| 36 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 37 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 38 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); |
| 39 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 40 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw); |
| 41 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw); |
| 42 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, |
| 43 | u16 count); |
| 44 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count); |
| 45 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); |
| 46 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); |
| 47 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr); |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 50 | static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 53 | * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | * @hw: pointer to hardware structure |
| 55 | * |
| 56 | * Starts the hardware by filling the bus info structure and media type, clears |
| 57 | * all on chip counters, initializes receive address registers, multicast |
| 58 | * table, VLAN filter table, calls routine to set up link and flow control |
| 59 | * settings, and leaves transmit and receive units disabled and uninitialized |
| 60 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 61 | s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 62 | { |
| 63 | u32 ctrl_ext; |
| 64 | |
| 65 | /* Set the media type */ |
| 66 | hw->phy.media_type = hw->mac.ops.get_media_type(hw); |
| 67 | |
| 68 | /* Identify the PHY */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 69 | hw->phy.ops.identify(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 70 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | /* Clear the VLAN filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 72 | hw->mac.ops.clear_vfta(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 74 | /* Clear statistics registers */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 75 | hw->mac.ops.clear_hw_cntrs(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 76 | |
| 77 | /* Set No Snoop Disable */ |
| 78 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 79 | ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS; |
| 80 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 81 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 83 | /* Setup flow control */ |
| 84 | ixgbe_setup_fc(hw, 0); |
| 85 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 86 | /* Clear adapter stopped flag */ |
| 87 | hw->adapter_stopped = false; |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 93 | * ixgbe_init_hw_generic - Generic hardware initialization |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 94 | * @hw: pointer to hardware structure |
| 95 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 96 | * Initialize the hardware by resetting the hardware, filling the bus info |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 97 | * structure and media type, clears all on chip counters, initializes receive |
| 98 | * address registers, multicast table, VLAN filter table, calls routine to set |
| 99 | * up link and flow control settings, and leaves transmit and receive units |
| 100 | * disabled and uninitialized |
| 101 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 102 | s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 103 | { |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 104 | s32 status; |
| 105 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 106 | /* Reset the hardware */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 107 | status = hw->mac.ops.reset_hw(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 108 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 109 | if (status == 0) { |
| 110 | /* Start the HW */ |
| 111 | status = hw->mac.ops.start_hw(hw); |
| 112 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 113 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 114 | return status; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 118 | * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 119 | * @hw: pointer to hardware structure |
| 120 | * |
| 121 | * Clears all hardware statistics counters by reading them from the hardware |
| 122 | * Statistics counters are clear on read. |
| 123 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 124 | s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 125 | { |
| 126 | u16 i = 0; |
| 127 | |
| 128 | IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
| 129 | IXGBE_READ_REG(hw, IXGBE_ILLERRC); |
| 130 | IXGBE_READ_REG(hw, IXGBE_ERRBC); |
| 131 | IXGBE_READ_REG(hw, IXGBE_MSPDC); |
| 132 | for (i = 0; i < 8; i++) |
| 133 | IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 134 | |
| 135 | IXGBE_READ_REG(hw, IXGBE_MLFC); |
| 136 | IXGBE_READ_REG(hw, IXGBE_MRFC); |
| 137 | IXGBE_READ_REG(hw, IXGBE_RLEC); |
| 138 | IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 139 | IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 140 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 141 | IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 142 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 143 | } else { |
| 144 | IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 145 | IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 146 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 147 | |
| 148 | for (i = 0; i < 8; i++) { |
| 149 | IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 150 | IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 151 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 152 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
| 153 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 154 | } else { |
| 155 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
| 156 | IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 157 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 158 | } |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 159 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 160 | for (i = 0; i < 8; i++) |
| 161 | IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 162 | IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 163 | IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 164 | IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 165 | IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 166 | IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 167 | IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 168 | IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 169 | IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 170 | IXGBE_READ_REG(hw, IXGBE_MPRC); |
| 171 | IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 172 | IXGBE_READ_REG(hw, IXGBE_GORCL); |
| 173 | IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 174 | IXGBE_READ_REG(hw, IXGBE_GOTCL); |
| 175 | IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 176 | for (i = 0; i < 8; i++) |
| 177 | IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 178 | IXGBE_READ_REG(hw, IXGBE_RUC); |
| 179 | IXGBE_READ_REG(hw, IXGBE_RFC); |
| 180 | IXGBE_READ_REG(hw, IXGBE_ROC); |
| 181 | IXGBE_READ_REG(hw, IXGBE_RJC); |
| 182 | IXGBE_READ_REG(hw, IXGBE_MNGPRC); |
| 183 | IXGBE_READ_REG(hw, IXGBE_MNGPDC); |
| 184 | IXGBE_READ_REG(hw, IXGBE_MNGPTC); |
| 185 | IXGBE_READ_REG(hw, IXGBE_TORL); |
| 186 | IXGBE_READ_REG(hw, IXGBE_TORH); |
| 187 | IXGBE_READ_REG(hw, IXGBE_TPR); |
| 188 | IXGBE_READ_REG(hw, IXGBE_TPT); |
| 189 | IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 190 | IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 191 | IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 192 | IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 193 | IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 194 | IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 195 | IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 196 | IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 197 | for (i = 0; i < 16; i++) { |
| 198 | IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 199 | IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
Emil Tantilov | 667c756 | 2011-02-26 06:40:05 +0000 | [diff] [blame] | 200 | if (hw->mac.type >= ixgbe_mac_82599EB) { |
| 201 | IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 202 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); |
| 203 | IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 204 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); |
| 205 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
| 206 | } else { |
| 207 | IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
| 208 | IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 209 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Emil Tantilov | a3aeea0 | 2011-02-26 06:40:11 +0000 | [diff] [blame^] | 212 | if (hw->mac.type == ixgbe_mac_X540) { |
| 213 | if (hw->phy.id == 0) |
| 214 | hw->phy.ops.identify(hw); |
| 215 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i); |
| 216 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i); |
| 217 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i); |
| 218 | hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i); |
| 219 | } |
| 220 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /** |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 225 | * ixgbe_read_pba_string_generic - Reads part number string from EEPROM |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 226 | * @hw: pointer to hardware structure |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 227 | * @pba_num: stores the part number string from the EEPROM |
| 228 | * @pba_num_size: part number string buffer length |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 229 | * |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 230 | * Reads the part number string from the EEPROM. |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 231 | **/ |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 232 | s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num, |
| 233 | u32 pba_num_size) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 234 | { |
| 235 | s32 ret_val; |
| 236 | u16 data; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 237 | u16 pba_ptr; |
| 238 | u16 offset; |
| 239 | u16 length; |
| 240 | |
| 241 | if (pba_num == NULL) { |
| 242 | hw_dbg(hw, "PBA string buffer was null\n"); |
| 243 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 244 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 245 | |
| 246 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data); |
| 247 | if (ret_val) { |
| 248 | hw_dbg(hw, "NVM Read Error\n"); |
| 249 | return ret_val; |
| 250 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 251 | |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 252 | ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 253 | if (ret_val) { |
| 254 | hw_dbg(hw, "NVM Read Error\n"); |
| 255 | return ret_val; |
| 256 | } |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 257 | |
| 258 | /* |
| 259 | * if data is not ptr guard the PBA must be in legacy format which |
| 260 | * means pba_ptr is actually our second data word for the PBA number |
| 261 | * and we can decode it into an ascii string |
| 262 | */ |
| 263 | if (data != IXGBE_PBANUM_PTR_GUARD) { |
| 264 | hw_dbg(hw, "NVM PBA number is not stored as string\n"); |
| 265 | |
| 266 | /* we will need 11 characters to store the PBA */ |
| 267 | if (pba_num_size < 11) { |
| 268 | hw_dbg(hw, "PBA string buffer too small\n"); |
| 269 | return IXGBE_ERR_NO_SPACE; |
| 270 | } |
| 271 | |
| 272 | /* extract hex string from data and pba_ptr */ |
| 273 | pba_num[0] = (data >> 12) & 0xF; |
| 274 | pba_num[1] = (data >> 8) & 0xF; |
| 275 | pba_num[2] = (data >> 4) & 0xF; |
| 276 | pba_num[3] = data & 0xF; |
| 277 | pba_num[4] = (pba_ptr >> 12) & 0xF; |
| 278 | pba_num[5] = (pba_ptr >> 8) & 0xF; |
| 279 | pba_num[6] = '-'; |
| 280 | pba_num[7] = 0; |
| 281 | pba_num[8] = (pba_ptr >> 4) & 0xF; |
| 282 | pba_num[9] = pba_ptr & 0xF; |
| 283 | |
| 284 | /* put a null character on the end of our string */ |
| 285 | pba_num[10] = '\0'; |
| 286 | |
| 287 | /* switch all the data but the '-' to hex char */ |
| 288 | for (offset = 0; offset < 10; offset++) { |
| 289 | if (pba_num[offset] < 0xA) |
| 290 | pba_num[offset] += '0'; |
| 291 | else if (pba_num[offset] < 0x10) |
| 292 | pba_num[offset] += 'A' - 0xA; |
| 293 | } |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length); |
| 299 | if (ret_val) { |
| 300 | hw_dbg(hw, "NVM Read Error\n"); |
| 301 | return ret_val; |
| 302 | } |
| 303 | |
| 304 | if (length == 0xFFFF || length == 0) { |
| 305 | hw_dbg(hw, "NVM PBA number section invalid length\n"); |
| 306 | return IXGBE_ERR_PBA_SECTION; |
| 307 | } |
| 308 | |
| 309 | /* check if pba_num buffer is big enough */ |
| 310 | if (pba_num_size < (((u32)length * 2) - 1)) { |
| 311 | hw_dbg(hw, "PBA string buffer too small\n"); |
| 312 | return IXGBE_ERR_NO_SPACE; |
| 313 | } |
| 314 | |
| 315 | /* trim pba length from start of string */ |
| 316 | pba_ptr++; |
| 317 | length--; |
| 318 | |
| 319 | for (offset = 0; offset < length; offset++) { |
| 320 | ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data); |
| 321 | if (ret_val) { |
| 322 | hw_dbg(hw, "NVM Read Error\n"); |
| 323 | return ret_val; |
| 324 | } |
| 325 | pba_num[offset * 2] = (u8)(data >> 8); |
| 326 | pba_num[(offset * 2) + 1] = (u8)(data & 0xFF); |
| 327 | } |
| 328 | pba_num[offset * 2] = '\0'; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * ixgbe_get_mac_addr_generic - Generic get MAC address |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 335 | * @hw: pointer to hardware structure |
| 336 | * @mac_addr: Adapter MAC address |
| 337 | * |
| 338 | * Reads the adapter's MAC address from first Receive Address Register (RAR0) |
| 339 | * A reset of the adapter must be performed prior to calling this function |
| 340 | * in order for the MAC address to have been loaded from the EEPROM into RAR0 |
| 341 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 342 | 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] | 343 | { |
| 344 | u32 rar_high; |
| 345 | u32 rar_low; |
| 346 | u16 i; |
| 347 | |
| 348 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0)); |
| 349 | rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0)); |
| 350 | |
| 351 | for (i = 0; i < 4; i++) |
| 352 | mac_addr[i] = (u8)(rar_low >> (i*8)); |
| 353 | |
| 354 | for (i = 0; i < 2; i++) |
| 355 | mac_addr[i+4] = (u8)(rar_high >> (i*8)); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 360 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 361 | * ixgbe_get_bus_info_generic - Generic set PCI bus info |
| 362 | * @hw: pointer to hardware structure |
| 363 | * |
| 364 | * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure |
| 365 | **/ |
| 366 | s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw) |
| 367 | { |
| 368 | struct ixgbe_adapter *adapter = hw->back; |
| 369 | struct ixgbe_mac_info *mac = &hw->mac; |
| 370 | u16 link_status; |
| 371 | |
| 372 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 373 | |
| 374 | /* Get the negotiated link width and speed from PCI config space */ |
| 375 | pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS, |
| 376 | &link_status); |
| 377 | |
| 378 | switch (link_status & IXGBE_PCI_LINK_WIDTH) { |
| 379 | case IXGBE_PCI_LINK_WIDTH_1: |
| 380 | hw->bus.width = ixgbe_bus_width_pcie_x1; |
| 381 | break; |
| 382 | case IXGBE_PCI_LINK_WIDTH_2: |
| 383 | hw->bus.width = ixgbe_bus_width_pcie_x2; |
| 384 | break; |
| 385 | case IXGBE_PCI_LINK_WIDTH_4: |
| 386 | hw->bus.width = ixgbe_bus_width_pcie_x4; |
| 387 | break; |
| 388 | case IXGBE_PCI_LINK_WIDTH_8: |
| 389 | hw->bus.width = ixgbe_bus_width_pcie_x8; |
| 390 | break; |
| 391 | default: |
| 392 | hw->bus.width = ixgbe_bus_width_unknown; |
| 393 | break; |
| 394 | } |
| 395 | |
| 396 | switch (link_status & IXGBE_PCI_LINK_SPEED) { |
| 397 | case IXGBE_PCI_LINK_SPEED_2500: |
| 398 | hw->bus.speed = ixgbe_bus_speed_2500; |
| 399 | break; |
| 400 | case IXGBE_PCI_LINK_SPEED_5000: |
| 401 | hw->bus.speed = ixgbe_bus_speed_5000; |
| 402 | break; |
| 403 | default: |
| 404 | hw->bus.speed = ixgbe_bus_speed_unknown; |
| 405 | break; |
| 406 | } |
| 407 | |
| 408 | mac->ops.set_lan_id(hw); |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices |
| 415 | * @hw: pointer to the HW structure |
| 416 | * |
| 417 | * Determines the LAN function id by reading memory-mapped registers |
| 418 | * and swaps the port value if requested. |
| 419 | **/ |
| 420 | void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw) |
| 421 | { |
| 422 | struct ixgbe_bus_info *bus = &hw->bus; |
| 423 | u32 reg; |
| 424 | |
| 425 | reg = IXGBE_READ_REG(hw, IXGBE_STATUS); |
| 426 | bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT; |
| 427 | bus->lan_id = bus->func; |
| 428 | |
| 429 | /* check for a port swap */ |
| 430 | reg = IXGBE_READ_REG(hw, IXGBE_FACTPS); |
| 431 | if (reg & IXGBE_FACTPS_LFS) |
| 432 | bus->func ^= 0x1; |
| 433 | } |
| 434 | |
| 435 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 436 | * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 437 | * @hw: pointer to hardware structure |
| 438 | * |
| 439 | * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, |
| 440 | * disables transmit and receive units. The adapter_stopped flag is used by |
| 441 | * the shared code and drivers to determine if the adapter is in a stopped |
| 442 | * state and should not touch the hardware. |
| 443 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 444 | s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 445 | { |
| 446 | u32 number_of_queues; |
| 447 | u32 reg_val; |
| 448 | u16 i; |
| 449 | |
| 450 | /* |
| 451 | * Set the adapter_stopped flag so other driver functions stop touching |
| 452 | * the hardware |
| 453 | */ |
| 454 | hw->adapter_stopped = true; |
| 455 | |
| 456 | /* Disable the receive unit */ |
| 457 | reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 458 | reg_val &= ~(IXGBE_RXCTRL_RXEN); |
| 459 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 460 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 461 | msleep(2); |
| 462 | |
| 463 | /* Clear interrupt mask to stop from interrupts being generated */ |
| 464 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 465 | |
| 466 | /* Clear any pending interrupts */ |
| 467 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 468 | |
| 469 | /* Disable the transmit unit. Each queue must be disabled. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 470 | number_of_queues = hw->mac.max_tx_queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 471 | for (i = 0; i < number_of_queues; i++) { |
| 472 | reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 473 | if (reg_val & IXGBE_TXDCTL_ENABLE) { |
| 474 | reg_val &= ~IXGBE_TXDCTL_ENABLE; |
| 475 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val); |
| 476 | } |
| 477 | } |
| 478 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Prevent the PCI-E bus from from hanging by disabling PCI-E master |
| 481 | * access and verify no pending requests |
| 482 | */ |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 483 | ixgbe_disable_pcie_master(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 484 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 489 | * ixgbe_led_on_generic - Turns on the software controllable LEDs. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 490 | * @hw: pointer to hardware structure |
| 491 | * @index: led number to turn on |
| 492 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 493 | s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 494 | { |
| 495 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 496 | |
| 497 | /* To turn on the LED, set mode to ON. */ |
| 498 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 499 | led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index); |
| 500 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 501 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 507 | * ixgbe_led_off_generic - Turns off the software controllable LEDs. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 508 | * @hw: pointer to hardware structure |
| 509 | * @index: led number to turn off |
| 510 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 511 | s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 512 | { |
| 513 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 514 | |
| 515 | /* To turn off the LED, set mode to OFF. */ |
| 516 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 517 | led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index); |
| 518 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 519 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 524 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 525 | * ixgbe_init_eeprom_params_generic - Initialize EEPROM params |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 526 | * @hw: pointer to hardware structure |
| 527 | * |
| 528 | * Initializes the EEPROM parameters ixgbe_eeprom_info within the |
| 529 | * ixgbe_hw struct in order to set up EEPROM access. |
| 530 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 531 | s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 532 | { |
| 533 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; |
| 534 | u32 eec; |
| 535 | u16 eeprom_size; |
| 536 | |
| 537 | if (eeprom->type == ixgbe_eeprom_uninitialized) { |
| 538 | eeprom->type = ixgbe_eeprom_none; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 539 | /* Set default semaphore delay to 10ms which is a well |
| 540 | * tested value */ |
| 541 | eeprom->semaphore_delay = 10; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * Check for EEPROM present first. |
| 545 | * If not present leave as none |
| 546 | */ |
| 547 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 548 | if (eec & IXGBE_EEC_PRES) { |
| 549 | eeprom->type = ixgbe_eeprom_spi; |
| 550 | |
| 551 | /* |
| 552 | * SPI EEPROM is assumed here. This code would need to |
| 553 | * change if a future EEPROM is not SPI. |
| 554 | */ |
| 555 | eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> |
| 556 | IXGBE_EEC_SIZE_SHIFT); |
| 557 | eeprom->word_size = 1 << (eeprom_size + |
| 558 | IXGBE_EEPROM_WORD_SIZE_SHIFT); |
| 559 | } |
| 560 | |
| 561 | if (eec & IXGBE_EEC_ADDR_SIZE) |
| 562 | eeprom->address_bits = 16; |
| 563 | else |
| 564 | eeprom->address_bits = 8; |
| 565 | hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: " |
| 566 | "%d\n", eeprom->type, eeprom->word_size, |
| 567 | eeprom->address_bits); |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | /** |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 574 | * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM |
| 575 | * @hw: pointer to hardware structure |
| 576 | * @offset: offset within the EEPROM to be written to |
| 577 | * @data: 16 bit word to be written to the EEPROM |
| 578 | * |
| 579 | * If ixgbe_eeprom_update_checksum is not called after this function, the |
| 580 | * EEPROM will most likely contain an invalid checksum. |
| 581 | **/ |
| 582 | s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data) |
| 583 | { |
| 584 | s32 status; |
| 585 | u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI; |
| 586 | |
| 587 | hw->eeprom.ops.init_params(hw); |
| 588 | |
| 589 | if (offset >= hw->eeprom.word_size) { |
| 590 | status = IXGBE_ERR_EEPROM; |
| 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | /* Prepare the EEPROM for writing */ |
| 595 | status = ixgbe_acquire_eeprom(hw); |
| 596 | |
| 597 | if (status == 0) { |
| 598 | if (ixgbe_ready_eeprom(hw) != 0) { |
| 599 | ixgbe_release_eeprom(hw); |
| 600 | status = IXGBE_ERR_EEPROM; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | if (status == 0) { |
| 605 | ixgbe_standby_eeprom(hw); |
| 606 | |
| 607 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 608 | ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI, |
| 609 | IXGBE_EEPROM_OPCODE_BITS); |
| 610 | |
| 611 | ixgbe_standby_eeprom(hw); |
| 612 | |
| 613 | /* |
| 614 | * Some SPI eeproms use the 8th address bit embedded in the |
| 615 | * opcode |
| 616 | */ |
| 617 | if ((hw->eeprom.address_bits == 8) && (offset >= 128)) |
| 618 | write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; |
| 619 | |
| 620 | /* Send the Write command (8-bit opcode + addr) */ |
| 621 | ixgbe_shift_out_eeprom_bits(hw, write_opcode, |
| 622 | IXGBE_EEPROM_OPCODE_BITS); |
| 623 | ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), |
| 624 | hw->eeprom.address_bits); |
| 625 | |
| 626 | /* Send the data */ |
| 627 | data = (data >> 8) | (data << 8); |
| 628 | ixgbe_shift_out_eeprom_bits(hw, data, 16); |
| 629 | ixgbe_standby_eeprom(hw); |
| 630 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 631 | /* Done with writing - release the EEPROM */ |
| 632 | ixgbe_release_eeprom(hw); |
| 633 | } |
| 634 | |
| 635 | out: |
| 636 | return status; |
| 637 | } |
| 638 | |
| 639 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 640 | * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang |
| 641 | * @hw: pointer to hardware structure |
| 642 | * @offset: offset within the EEPROM to be read |
| 643 | * @data: read 16 bit value from EEPROM |
| 644 | * |
| 645 | * Reads 16 bit value from EEPROM through bit-bang method |
| 646 | **/ |
| 647 | s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, |
| 648 | u16 *data) |
| 649 | { |
| 650 | s32 status; |
| 651 | u16 word_in; |
| 652 | u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI; |
| 653 | |
| 654 | hw->eeprom.ops.init_params(hw); |
| 655 | |
| 656 | if (offset >= hw->eeprom.word_size) { |
| 657 | status = IXGBE_ERR_EEPROM; |
| 658 | goto out; |
| 659 | } |
| 660 | |
| 661 | /* Prepare the EEPROM for reading */ |
| 662 | status = ixgbe_acquire_eeprom(hw); |
| 663 | |
| 664 | if (status == 0) { |
| 665 | if (ixgbe_ready_eeprom(hw) != 0) { |
| 666 | ixgbe_release_eeprom(hw); |
| 667 | status = IXGBE_ERR_EEPROM; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if (status == 0) { |
| 672 | ixgbe_standby_eeprom(hw); |
| 673 | |
| 674 | /* |
| 675 | * Some SPI eeproms use the 8th address bit embedded in the |
| 676 | * opcode |
| 677 | */ |
| 678 | if ((hw->eeprom.address_bits == 8) && (offset >= 128)) |
| 679 | read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; |
| 680 | |
| 681 | /* Send the READ command (opcode + addr) */ |
| 682 | ixgbe_shift_out_eeprom_bits(hw, read_opcode, |
| 683 | IXGBE_EEPROM_OPCODE_BITS); |
| 684 | ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), |
| 685 | hw->eeprom.address_bits); |
| 686 | |
| 687 | /* Read the data. */ |
| 688 | word_in = ixgbe_shift_in_eeprom_bits(hw, 16); |
| 689 | *data = (word_in >> 8) | (word_in << 8); |
| 690 | |
| 691 | /* End this read operation */ |
| 692 | ixgbe_release_eeprom(hw); |
| 693 | } |
| 694 | |
| 695 | out: |
| 696 | return status; |
| 697 | } |
| 698 | |
| 699 | /** |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 700 | * ixgbe_read_eerd_generic - Read EEPROM word using EERD |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 701 | * @hw: pointer to hardware structure |
| 702 | * @offset: offset of word in the EEPROM to read |
| 703 | * @data: word read from the EEPROM |
| 704 | * |
| 705 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 706 | **/ |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 707 | 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] | 708 | { |
| 709 | u32 eerd; |
| 710 | s32 status; |
| 711 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 712 | hw->eeprom.ops.init_params(hw); |
| 713 | |
| 714 | if (offset >= hw->eeprom.word_size) { |
| 715 | status = IXGBE_ERR_EEPROM; |
| 716 | goto out; |
| 717 | } |
| 718 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 719 | eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) + |
| 720 | IXGBE_EEPROM_RW_REG_START; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | |
| 722 | IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 723 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 724 | |
| 725 | if (status == 0) |
| 726 | *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >> |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 727 | IXGBE_EEPROM_RW_REG_DATA); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 728 | else |
| 729 | hw_dbg(hw, "Eeprom read timed out\n"); |
| 730 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 731 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 732 | return status; |
| 733 | } |
| 734 | |
| 735 | /** |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 736 | * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 737 | * @hw: pointer to hardware structure |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 738 | * @ee_reg: EEPROM flag for polling |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 739 | * |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 740 | * Polls the status bit (bit 1) of the EERD or EEWR to determine when the |
| 741 | * read or write is done respectively. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 742 | **/ |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 743 | 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] | 744 | { |
| 745 | u32 i; |
| 746 | u32 reg; |
| 747 | s32 status = IXGBE_ERR_EEPROM; |
| 748 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 749 | for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) { |
| 750 | if (ee_reg == IXGBE_NVM_POLL_READ) |
| 751 | reg = IXGBE_READ_REG(hw, IXGBE_EERD); |
| 752 | else |
| 753 | reg = IXGBE_READ_REG(hw, IXGBE_EEWR); |
| 754 | |
| 755 | if (reg & IXGBE_EEPROM_RW_REG_DONE) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 756 | status = 0; |
| 757 | break; |
| 758 | } |
| 759 | udelay(5); |
| 760 | } |
| 761 | return status; |
| 762 | } |
| 763 | |
| 764 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 765 | * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang |
| 766 | * @hw: pointer to hardware structure |
| 767 | * |
| 768 | * Prepares EEPROM for access using bit-bang method. This function should |
| 769 | * be called before issuing a command to the EEPROM. |
| 770 | **/ |
| 771 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw) |
| 772 | { |
| 773 | s32 status = 0; |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 774 | u32 eec; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 775 | u32 i; |
| 776 | |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 777 | 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] | 778 | status = IXGBE_ERR_SWFW_SYNC; |
| 779 | |
| 780 | if (status == 0) { |
| 781 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 782 | |
| 783 | /* Request EEPROM Access */ |
| 784 | eec |= IXGBE_EEC_REQ; |
| 785 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 786 | |
| 787 | for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) { |
| 788 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 789 | if (eec & IXGBE_EEC_GNT) |
| 790 | break; |
| 791 | udelay(5); |
| 792 | } |
| 793 | |
| 794 | /* Release if grant not acquired */ |
| 795 | if (!(eec & IXGBE_EEC_GNT)) { |
| 796 | eec &= ~IXGBE_EEC_REQ; |
| 797 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 798 | hw_dbg(hw, "Could not acquire EEPROM grant\n"); |
| 799 | |
Don Skidmore | 5e65510 | 2011-02-25 01:58:04 +0000 | [diff] [blame] | 800 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 801 | status = IXGBE_ERR_EEPROM; |
| 802 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 803 | |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 804 | /* Setup EEPROM for Read/Write */ |
| 805 | if (status == 0) { |
| 806 | /* Clear CS and SK */ |
| 807 | eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK); |
| 808 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 809 | IXGBE_WRITE_FLUSH(hw); |
| 810 | udelay(1); |
| 811 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 812 | } |
| 813 | return status; |
| 814 | } |
| 815 | |
| 816 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 817 | * ixgbe_get_eeprom_semaphore - Get hardware semaphore |
| 818 | * @hw: pointer to hardware structure |
| 819 | * |
| 820 | * Sets the hardware semaphores so EEPROM access can occur for bit-bang method |
| 821 | **/ |
| 822 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw) |
| 823 | { |
| 824 | s32 status = IXGBE_ERR_EEPROM; |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 825 | u32 timeout = 2000; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 826 | u32 i; |
| 827 | u32 swsm; |
| 828 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | /* Get SMBI software semaphore between device drivers first */ |
| 830 | for (i = 0; i < timeout; i++) { |
| 831 | /* |
| 832 | * If the SMBI bit is 0 when we read it, then the bit will be |
| 833 | * set and we have the semaphore |
| 834 | */ |
| 835 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 836 | if (!(swsm & IXGBE_SWSM_SMBI)) { |
| 837 | status = 0; |
| 838 | break; |
| 839 | } |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 840 | udelay(50); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* Now get the semaphore between SW/FW through the SWESMBI bit */ |
| 844 | if (status == 0) { |
| 845 | for (i = 0; i < timeout; i++) { |
| 846 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 847 | |
| 848 | /* Set the SW EEPROM semaphore bit to request access */ |
| 849 | swsm |= IXGBE_SWSM_SWESMBI; |
| 850 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); |
| 851 | |
| 852 | /* |
| 853 | * If we set the bit successfully then we got the |
| 854 | * semaphore. |
| 855 | */ |
| 856 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 857 | if (swsm & IXGBE_SWSM_SWESMBI) |
| 858 | break; |
| 859 | |
| 860 | udelay(50); |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * Release semaphores and return error if SW EEPROM semaphore |
| 865 | * was not granted because we don't have access to the EEPROM |
| 866 | */ |
| 867 | if (i >= timeout) { |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 868 | hw_dbg(hw, "SWESMBI Software EEPROM semaphore " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 869 | "not granted.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 870 | ixgbe_release_eeprom_semaphore(hw); |
| 871 | status = IXGBE_ERR_EEPROM; |
| 872 | } |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 873 | } else { |
| 874 | hw_dbg(hw, "Software semaphore SMBI between device drivers " |
| 875 | "not granted.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | return status; |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * ixgbe_release_eeprom_semaphore - Release hardware semaphore |
| 883 | * @hw: pointer to hardware structure |
| 884 | * |
| 885 | * This function clears hardware semaphore bits. |
| 886 | **/ |
| 887 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw) |
| 888 | { |
| 889 | u32 swsm; |
| 890 | |
| 891 | swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); |
| 892 | |
| 893 | /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */ |
| 894 | swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI); |
| 895 | IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 896 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 900 | * ixgbe_ready_eeprom - Polls for EEPROM ready |
| 901 | * @hw: pointer to hardware structure |
| 902 | **/ |
| 903 | static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw) |
| 904 | { |
| 905 | s32 status = 0; |
| 906 | u16 i; |
| 907 | u8 spi_stat_reg; |
| 908 | |
| 909 | /* |
| 910 | * Read "Status Register" repeatedly until the LSB is cleared. The |
| 911 | * EEPROM will signal that the command has been completed by clearing |
| 912 | * bit 0 of the internal status register. If it's not cleared within |
| 913 | * 5 milliseconds, then error out. |
| 914 | */ |
| 915 | for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) { |
| 916 | ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI, |
| 917 | IXGBE_EEPROM_OPCODE_BITS); |
| 918 | spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8); |
| 919 | if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI)) |
| 920 | break; |
| 921 | |
| 922 | udelay(5); |
| 923 | ixgbe_standby_eeprom(hw); |
| 924 | }; |
| 925 | |
| 926 | /* |
| 927 | * On some parts, SPI write time could vary from 0-20mSec on 3.3V |
| 928 | * devices (and only 0-5mSec on 5V devices) |
| 929 | */ |
| 930 | if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) { |
| 931 | hw_dbg(hw, "SPI EEPROM Status error\n"); |
| 932 | status = IXGBE_ERR_EEPROM; |
| 933 | } |
| 934 | |
| 935 | return status; |
| 936 | } |
| 937 | |
| 938 | /** |
| 939 | * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state |
| 940 | * @hw: pointer to hardware structure |
| 941 | **/ |
| 942 | static void ixgbe_standby_eeprom(struct ixgbe_hw *hw) |
| 943 | { |
| 944 | u32 eec; |
| 945 | |
| 946 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 947 | |
| 948 | /* Toggle CS to flush commands */ |
| 949 | eec |= IXGBE_EEC_CS; |
| 950 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 951 | IXGBE_WRITE_FLUSH(hw); |
| 952 | udelay(1); |
| 953 | eec &= ~IXGBE_EEC_CS; |
| 954 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 955 | IXGBE_WRITE_FLUSH(hw); |
| 956 | udelay(1); |
| 957 | } |
| 958 | |
| 959 | /** |
| 960 | * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM. |
| 961 | * @hw: pointer to hardware structure |
| 962 | * @data: data to send to the EEPROM |
| 963 | * @count: number of bits to shift out |
| 964 | **/ |
| 965 | static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, |
| 966 | u16 count) |
| 967 | { |
| 968 | u32 eec; |
| 969 | u32 mask; |
| 970 | u32 i; |
| 971 | |
| 972 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 973 | |
| 974 | /* |
| 975 | * Mask is used to shift "count" bits of "data" out to the EEPROM |
| 976 | * one bit at a time. Determine the starting bit based on count |
| 977 | */ |
| 978 | mask = 0x01 << (count - 1); |
| 979 | |
| 980 | for (i = 0; i < count; i++) { |
| 981 | /* |
| 982 | * A "1" is shifted out to the EEPROM by setting bit "DI" to a |
| 983 | * "1", and then raising and then lowering the clock (the SK |
| 984 | * bit controls the clock input to the EEPROM). A "0" is |
| 985 | * shifted out to the EEPROM by setting "DI" to "0" and then |
| 986 | * raising and then lowering the clock. |
| 987 | */ |
| 988 | if (data & mask) |
| 989 | eec |= IXGBE_EEC_DI; |
| 990 | else |
| 991 | eec &= ~IXGBE_EEC_DI; |
| 992 | |
| 993 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 994 | IXGBE_WRITE_FLUSH(hw); |
| 995 | |
| 996 | udelay(1); |
| 997 | |
| 998 | ixgbe_raise_eeprom_clk(hw, &eec); |
| 999 | ixgbe_lower_eeprom_clk(hw, &eec); |
| 1000 | |
| 1001 | /* |
| 1002 | * Shift mask to signify next bit of data to shift in to the |
| 1003 | * EEPROM |
| 1004 | */ |
| 1005 | mask = mask >> 1; |
| 1006 | }; |
| 1007 | |
| 1008 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 1009 | eec &= ~IXGBE_EEC_DI; |
| 1010 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1011 | IXGBE_WRITE_FLUSH(hw); |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM |
| 1016 | * @hw: pointer to hardware structure |
| 1017 | **/ |
| 1018 | static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count) |
| 1019 | { |
| 1020 | u32 eec; |
| 1021 | u32 i; |
| 1022 | u16 data = 0; |
| 1023 | |
| 1024 | /* |
| 1025 | * In order to read a register from the EEPROM, we need to shift |
| 1026 | * 'count' bits in from the EEPROM. Bits are "shifted in" by raising |
| 1027 | * the clock input to the EEPROM (setting the SK bit), and then reading |
| 1028 | * the value of the "DO" bit. During this "shifting in" process the |
| 1029 | * "DI" bit should always be clear. |
| 1030 | */ |
| 1031 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1032 | |
| 1033 | eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI); |
| 1034 | |
| 1035 | for (i = 0; i < count; i++) { |
| 1036 | data = data << 1; |
| 1037 | ixgbe_raise_eeprom_clk(hw, &eec); |
| 1038 | |
| 1039 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1040 | |
| 1041 | eec &= ~(IXGBE_EEC_DI); |
| 1042 | if (eec & IXGBE_EEC_DO) |
| 1043 | data |= 1; |
| 1044 | |
| 1045 | ixgbe_lower_eeprom_clk(hw, &eec); |
| 1046 | } |
| 1047 | |
| 1048 | return data; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input. |
| 1053 | * @hw: pointer to hardware structure |
| 1054 | * @eec: EEC register's current value |
| 1055 | **/ |
| 1056 | static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) |
| 1057 | { |
| 1058 | /* |
| 1059 | * Raise the clock input to the EEPROM |
| 1060 | * (setting the SK bit), then delay |
| 1061 | */ |
| 1062 | *eec = *eec | IXGBE_EEC_SK; |
| 1063 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); |
| 1064 | IXGBE_WRITE_FLUSH(hw); |
| 1065 | udelay(1); |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input. |
| 1070 | * @hw: pointer to hardware structure |
| 1071 | * @eecd: EECD's current value |
| 1072 | **/ |
| 1073 | static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) |
| 1074 | { |
| 1075 | /* |
| 1076 | * Lower the clock input to the EEPROM (clearing the SK bit), then |
| 1077 | * delay |
| 1078 | */ |
| 1079 | *eec = *eec & ~IXGBE_EEC_SK; |
| 1080 | IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); |
| 1081 | IXGBE_WRITE_FLUSH(hw); |
| 1082 | udelay(1); |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * ixgbe_release_eeprom - Release EEPROM, release semaphores |
| 1087 | * @hw: pointer to hardware structure |
| 1088 | **/ |
| 1089 | static void ixgbe_release_eeprom(struct ixgbe_hw *hw) |
| 1090 | { |
| 1091 | u32 eec; |
| 1092 | |
| 1093 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 1094 | |
| 1095 | eec |= IXGBE_EEC_CS; /* Pull CS high */ |
| 1096 | eec &= ~IXGBE_EEC_SK; /* Lower SCK */ |
| 1097 | |
| 1098 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1099 | IXGBE_WRITE_FLUSH(hw); |
| 1100 | |
| 1101 | udelay(1); |
| 1102 | |
| 1103 | /* Stop requesting EEPROM access */ |
| 1104 | eec &= ~IXGBE_EEC_REQ; |
| 1105 | IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); |
| 1106 | |
Don Skidmore | 9082799 | 2011-03-05 18:59:20 -0800 | [diff] [blame] | 1107 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* Delay before attempt to obtain semaphore again to allow FW access */ |
| 1110 | msleep(hw->eeprom.semaphore_delay); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /** |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 1114 | * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1115 | * @hw: pointer to hardware structure |
| 1116 | **/ |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1117 | u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1118 | { |
| 1119 | u16 i; |
| 1120 | u16 j; |
| 1121 | u16 checksum = 0; |
| 1122 | u16 length = 0; |
| 1123 | u16 pointer = 0; |
| 1124 | u16 word = 0; |
| 1125 | |
| 1126 | /* Include 0x0-0x3F in the checksum */ |
| 1127 | for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1128 | if (hw->eeprom.ops.read(hw, i, &word) != 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1129 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1130 | break; |
| 1131 | } |
| 1132 | checksum += word; |
| 1133 | } |
| 1134 | |
| 1135 | /* Include all data from pointers except for the fw pointer */ |
| 1136 | for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1137 | hw->eeprom.ops.read(hw, i, &pointer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1138 | |
| 1139 | /* Make sure the pointer seems valid */ |
| 1140 | if (pointer != 0xFFFF && pointer != 0) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1141 | hw->eeprom.ops.read(hw, pointer, &length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1142 | |
| 1143 | if (length != 0xFFFF && length != 0) { |
| 1144 | for (j = pointer+1; j <= pointer+length; j++) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1145 | hw->eeprom.ops.read(hw, j, &word); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | checksum += word; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | checksum = (u16)IXGBE_EEPROM_SUM - checksum; |
| 1153 | |
| 1154 | return checksum; |
| 1155 | } |
| 1156 | |
| 1157 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1158 | * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1159 | * @hw: pointer to hardware structure |
| 1160 | * @checksum_val: calculated checksum |
| 1161 | * |
| 1162 | * Performs checksum calculation and validates the EEPROM checksum. If the |
| 1163 | * caller does not need checksum_val, the value can be NULL. |
| 1164 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1165 | s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, |
| 1166 | u16 *checksum_val) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1167 | { |
| 1168 | s32 status; |
| 1169 | u16 checksum; |
| 1170 | u16 read_checksum = 0; |
| 1171 | |
| 1172 | /* |
| 1173 | * Read the first word from the EEPROM. If this times out or fails, do |
| 1174 | * not continue or we could be in for a very long wait while every |
| 1175 | * EEPROM read fails |
| 1176 | */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1177 | status = hw->eeprom.ops.read(hw, 0, &checksum); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (status == 0) { |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1180 | checksum = hw->eeprom.ops.calc_checksum(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1181 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1182 | hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1183 | |
| 1184 | /* |
| 1185 | * Verify read checksum from EEPROM is the same as |
| 1186 | * calculated checksum |
| 1187 | */ |
| 1188 | if (read_checksum != checksum) |
| 1189 | status = IXGBE_ERR_EEPROM_CHECKSUM; |
| 1190 | |
| 1191 | /* If the user cares, return the calculated checksum */ |
| 1192 | if (checksum_val) |
| 1193 | *checksum_val = checksum; |
| 1194 | } else { |
| 1195 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1196 | } |
| 1197 | |
| 1198 | return status; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1202 | * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum |
| 1203 | * @hw: pointer to hardware structure |
| 1204 | **/ |
| 1205 | s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw) |
| 1206 | { |
| 1207 | s32 status; |
| 1208 | u16 checksum; |
| 1209 | |
| 1210 | /* |
| 1211 | * Read the first word from the EEPROM. If this times out or fails, do |
| 1212 | * not continue or we could be in for a very long wait while every |
| 1213 | * EEPROM read fails |
| 1214 | */ |
| 1215 | status = hw->eeprom.ops.read(hw, 0, &checksum); |
| 1216 | |
| 1217 | if (status == 0) { |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 1218 | checksum = hw->eeprom.ops.calc_checksum(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1219 | status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 1220 | checksum); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1221 | } else { |
| 1222 | hw_dbg(hw, "EEPROM read failed\n"); |
| 1223 | } |
| 1224 | |
| 1225 | return status; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1229 | * ixgbe_validate_mac_addr - Validate MAC address |
| 1230 | * @mac_addr: pointer to MAC address. |
| 1231 | * |
| 1232 | * Tests a MAC address to ensure it is a valid Individual Address |
| 1233 | **/ |
| 1234 | s32 ixgbe_validate_mac_addr(u8 *mac_addr) |
| 1235 | { |
| 1236 | s32 status = 0; |
| 1237 | |
| 1238 | /* Make sure it is not a multicast address */ |
| 1239 | if (IXGBE_IS_MULTICAST(mac_addr)) |
| 1240 | status = IXGBE_ERR_INVALID_MAC_ADDR; |
| 1241 | /* Not a broadcast address */ |
| 1242 | else if (IXGBE_IS_BROADCAST(mac_addr)) |
| 1243 | status = IXGBE_ERR_INVALID_MAC_ADDR; |
| 1244 | /* Reject the zero address */ |
| 1245 | else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1246 | mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1247 | status = IXGBE_ERR_INVALID_MAC_ADDR; |
| 1248 | |
| 1249 | return status; |
| 1250 | } |
| 1251 | |
| 1252 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1253 | * ixgbe_set_rar_generic - Set Rx address register |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1254 | * @hw: pointer to hardware structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1255 | * @index: Receive address register to write |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1256 | * @addr: Address to put into receive address register |
| 1257 | * @vmdq: VMDq "set" or "pool" index |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1258 | * @enable_addr: set flag that address is active |
| 1259 | * |
| 1260 | * Puts an ethernet address into a receive address register. |
| 1261 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1262 | s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, |
| 1263 | u32 enable_addr) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1264 | { |
| 1265 | u32 rar_low, rar_high; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1266 | u32 rar_entries = hw->mac.num_rar_entries; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1267 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1268 | /* Make sure we are using a valid rar index range */ |
| 1269 | if (index >= rar_entries) { |
| 1270 | hw_dbg(hw, "RAR index %d is out of range.\n", index); |
| 1271 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 1272 | } |
| 1273 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1274 | /* setup VMDq pool selection before this RAR gets enabled */ |
| 1275 | hw->mac.ops.set_vmdq(hw, index, vmdq); |
| 1276 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1277 | /* |
| 1278 | * HW expects these in little endian so we reverse the byte |
| 1279 | * order from network order (big endian) to little endian |
| 1280 | */ |
| 1281 | rar_low = ((u32)addr[0] | |
| 1282 | ((u32)addr[1] << 8) | |
| 1283 | ((u32)addr[2] << 16) | |
| 1284 | ((u32)addr[3] << 24)); |
| 1285 | /* |
| 1286 | * Some parts put the VMDq setting in the extra RAH bits, |
| 1287 | * so save everything except the lower 16 bits that hold part |
| 1288 | * of the address and the address valid bit. |
| 1289 | */ |
| 1290 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); |
| 1291 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); |
| 1292 | rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1293 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1294 | if (enable_addr != 0) |
| 1295 | rar_high |= IXGBE_RAH_AV; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1296 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1297 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low); |
| 1298 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1304 | * ixgbe_clear_rar_generic - Remove Rx address register |
| 1305 | * @hw: pointer to hardware structure |
| 1306 | * @index: Receive address register to write |
| 1307 | * |
| 1308 | * Clears an ethernet address from a receive address register. |
| 1309 | **/ |
| 1310 | s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index) |
| 1311 | { |
| 1312 | u32 rar_high; |
| 1313 | u32 rar_entries = hw->mac.num_rar_entries; |
| 1314 | |
| 1315 | /* Make sure we are using a valid rar index range */ |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1316 | if (index >= rar_entries) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1317 | hw_dbg(hw, "RAR index %d is out of range.\n", index); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1318 | return IXGBE_ERR_INVALID_ARGUMENT; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 1321 | /* |
| 1322 | * Some parts put the VMDq setting in the extra RAH bits, |
| 1323 | * so save everything except the lower 16 bits that hold part |
| 1324 | * of the address and the address valid bit. |
| 1325 | */ |
| 1326 | rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); |
| 1327 | rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); |
| 1328 | |
| 1329 | IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0); |
| 1330 | IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); |
| 1331 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1332 | /* clear VMDq pool/queue selection for this RAR */ |
| 1333 | hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL); |
| 1334 | |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
| 1338 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1339 | * ixgbe_init_rx_addrs_generic - Initializes receive address filters. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1340 | * @hw: pointer to hardware structure |
| 1341 | * |
| 1342 | * 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] | 1343 | * of the receive address registers. Clears the multicast table. Assumes |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1344 | * the receiver is in reset when the routine is called. |
| 1345 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1346 | s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1347 | { |
| 1348 | u32 i; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1349 | u32 rar_entries = hw->mac.num_rar_entries; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1350 | |
| 1351 | /* |
| 1352 | * If the current mac address is valid, assume it is a software override |
| 1353 | * to the permanent address. |
| 1354 | * Otherwise, use the permanent address from the eeprom. |
| 1355 | */ |
| 1356 | if (ixgbe_validate_mac_addr(hw->mac.addr) == |
| 1357 | IXGBE_ERR_INVALID_MAC_ADDR) { |
| 1358 | /* Get the MAC address from the RAR0 for later reference */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1359 | hw->mac.ops.get_mac_addr(hw, hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1360 | |
hartleys | ce7194d | 2010-01-05 06:56:52 +0000 | [diff] [blame] | 1361 | hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1362 | } else { |
| 1363 | /* Setup the receive address. */ |
| 1364 | hw_dbg(hw, "Overriding MAC Address in RAR[0]\n"); |
hartleys | ce7194d | 2010-01-05 06:56:52 +0000 | [diff] [blame] | 1365 | hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1366 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1367 | 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] | 1368 | |
| 1369 | /* clear VMDq pool/queue selection for RAR 0 */ |
| 1370 | hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1371 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1372 | hw->addr_ctrl.overflow_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1373 | |
| 1374 | hw->addr_ctrl.rar_used_count = 1; |
| 1375 | |
| 1376 | /* Zero out the other receive addresses. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1377 | hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1378 | for (i = 1; i < rar_entries; i++) { |
| 1379 | IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); |
| 1380 | IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); |
| 1381 | } |
| 1382 | |
| 1383 | /* Clear the MTA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1384 | hw->addr_ctrl.mta_in_use = 0; |
| 1385 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); |
| 1386 | |
| 1387 | hw_dbg(hw, " Clearing MTA\n"); |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1388 | for (i = 0; i < hw->mac.mcft_size; i++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1389 | IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); |
| 1390 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1391 | if (hw->mac.ops.init_uta_tables) |
| 1392 | hw->mac.ops.init_uta_tables(hw); |
| 1393 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1394 | return 0; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * ixgbe_mta_vector - Determines bit-vector in multicast table to set |
| 1399 | * @hw: pointer to hardware structure |
| 1400 | * @mc_addr: the multicast address |
| 1401 | * |
| 1402 | * Extracts the 12 bits, from a multicast address, to determine which |
| 1403 | * bit-vector to set in the multicast table. The hardware uses 12 bits, from |
| 1404 | * incoming rx multicast addresses, to determine the bit-vector to check in |
| 1405 | * 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] | 1406 | * 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] | 1407 | * to mc_filter_type. |
| 1408 | **/ |
| 1409 | static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) |
| 1410 | { |
| 1411 | u32 vector = 0; |
| 1412 | |
| 1413 | switch (hw->mac.mc_filter_type) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1414 | case 0: /* use bits [47:36] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1415 | vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); |
| 1416 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1417 | case 1: /* use bits [46:35] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1418 | vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); |
| 1419 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1420 | case 2: /* use bits [45:34] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1421 | vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); |
| 1422 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1423 | case 3: /* use bits [43:32] of the address */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1424 | vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); |
| 1425 | break; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1426 | default: /* Invalid mc_filter_type */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1427 | hw_dbg(hw, "MC filter type param set incorrectly\n"); |
| 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | /* vector can only be 12-bits or boundary will be exceeded */ |
| 1432 | vector &= 0xFFF; |
| 1433 | return vector; |
| 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * ixgbe_set_mta - Set bit-vector in multicast table |
| 1438 | * @hw: pointer to hardware structure |
| 1439 | * @hash_value: Multicast address hash value |
| 1440 | * |
| 1441 | * Sets the bit-vector in the multicast table. |
| 1442 | **/ |
| 1443 | static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) |
| 1444 | { |
| 1445 | u32 vector; |
| 1446 | u32 vector_bit; |
| 1447 | u32 vector_reg; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1448 | |
| 1449 | hw->addr_ctrl.mta_in_use++; |
| 1450 | |
| 1451 | vector = ixgbe_mta_vector(hw, mc_addr); |
| 1452 | hw_dbg(hw, " bit-vector = 0x%03X\n", vector); |
| 1453 | |
| 1454 | /* |
| 1455 | * The MTA is a register array of 128 32-bit registers. It is treated |
| 1456 | * like an array of 4096 bits. We want to set bit |
| 1457 | * BitArray[vector_value]. So we figure out what register the bit is |
| 1458 | * in, read it, OR in the new bit, then write back the new value. The |
| 1459 | * register is determined by the upper 7 bits of the vector value and |
| 1460 | * the bit within that register are determined by the lower 5 bits of |
| 1461 | * the value. |
| 1462 | */ |
| 1463 | vector_reg = (vector >> 5) & 0x7F; |
| 1464 | vector_bit = vector & 0x1F; |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 1465 | hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1469 | * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1470 | * @hw: pointer to hardware structure |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 1471 | * @netdev: pointer to net device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1472 | * |
| 1473 | * 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] | 1474 | * address registers and the multicast table. Uses unused receive address |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1475 | * registers for the first multicast addresses, and hashes the rest into the |
| 1476 | * multicast table. |
| 1477 | **/ |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 1478 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, |
| 1479 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1480 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1481 | struct netdev_hw_addr *ha; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1482 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1483 | |
| 1484 | /* |
| 1485 | * Set the new number of MC addresses that we are being requested to |
| 1486 | * use. |
| 1487 | */ |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame] | 1488 | hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1489 | hw->addr_ctrl.mta_in_use = 0; |
| 1490 | |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 1491 | /* Clear mta_shadow */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1492 | hw_dbg(hw, " Clearing MTA\n"); |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 1493 | memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1494 | |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 1495 | /* Update mta shadow */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1496 | netdev_for_each_mc_addr(ha, netdev) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1497 | hw_dbg(hw, " Adding the multicast addresses:\n"); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1498 | ixgbe_set_mta(hw, ha->addr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /* Enable mta */ |
Emil Tantilov | 80960ab | 2011-02-18 08:58:27 +0000 | [diff] [blame] | 1502 | for (i = 0; i < hw->mac.mcft_size; i++) |
| 1503 | IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i, |
| 1504 | hw->mac.mta_shadow[i]); |
| 1505 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1506 | if (hw->addr_ctrl.mta_in_use > 0) |
| 1507 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1508 | IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1509 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1510 | hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1515 | * ixgbe_enable_mc_generic - Enable multicast address in RAR |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1516 | * @hw: pointer to hardware structure |
| 1517 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1518 | * 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] | 1519 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1520 | s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1521 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1522 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1523 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1524 | if (a->mta_in_use > 0) |
| 1525 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE | |
| 1526 | hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1527 | |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1532 | * ixgbe_disable_mc_generic - Disable multicast address in RAR |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1533 | * @hw: pointer to hardware structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1534 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1535 | * 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] | 1536 | **/ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1537 | s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1538 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1539 | struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1540 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1541 | if (a->mta_in_use > 0) |
| 1542 | IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1543 | |
| 1544 | return 0; |
| 1545 | } |
| 1546 | |
| 1547 | /** |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1548 | * ixgbe_fc_enable_generic - Enable flow control |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1549 | * @hw: pointer to hardware structure |
| 1550 | * @packetbuf_num: packet buffer number (0-7) |
| 1551 | * |
| 1552 | * Enable flow control according to the current settings. |
| 1553 | **/ |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1554 | s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1555 | { |
| 1556 | s32 ret_val = 0; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1557 | u32 mflcn_reg, fccfg_reg; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1558 | u32 reg; |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 1559 | u32 rx_pba_size; |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 1560 | u32 fcrtl, fcrth; |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 1561 | |
| 1562 | #ifdef CONFIG_DCB |
| 1563 | if (hw->fc.requested_mode == ixgbe_fc_pfc) |
| 1564 | goto out; |
| 1565 | |
| 1566 | #endif /* CONFIG_DCB */ |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1567 | /* Negotiate the fc mode to use */ |
| 1568 | ret_val = ixgbe_fc_autoneg(hw); |
| 1569 | if (ret_val) |
| 1570 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1571 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1572 | /* Disable any previous flow control settings */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1573 | mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 1574 | mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE); |
| 1575 | |
| 1576 | fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 1577 | fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY); |
| 1578 | |
| 1579 | /* |
| 1580 | * The possible values of fc.current_mode are: |
| 1581 | * 0: Flow control is completely disabled |
| 1582 | * 1: Rx flow control is enabled (we can receive pause frames, |
| 1583 | * but not send pause frames). |
PJ Waskiewicz | bb3daa4 | 2009-03-25 22:10:42 +0000 | [diff] [blame] | 1584 | * 2: Tx flow control is enabled (we can send pause frames but |
| 1585 | * we do not support receiving pause frames). |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1586 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 1587 | #ifdef CONFIG_DCB |
PJ Waskiewicz | bb3daa4 | 2009-03-25 22:10:42 +0000 | [diff] [blame] | 1588 | * 4: Priority Flow Control is enabled. |
Emil Tantilov | 8c7bea3 | 2011-02-19 08:43:44 +0000 | [diff] [blame] | 1589 | #endif |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1590 | * other: Invalid. |
| 1591 | */ |
| 1592 | switch (hw->fc.current_mode) { |
| 1593 | case ixgbe_fc_none: |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1594 | /* |
| 1595 | * Flow control is disabled by software override or autoneg. |
| 1596 | * The code below will actually disable it in the HW. |
| 1597 | */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1598 | break; |
| 1599 | case ixgbe_fc_rx_pause: |
| 1600 | /* |
| 1601 | * Rx Flow control is enabled and Tx Flow control is |
| 1602 | * disabled by software override. Since there really |
| 1603 | * isn't a way to advertise that we are capable of RX |
| 1604 | * Pause ONLY, we will advertise that we support both |
| 1605 | * symmetric and asymmetric Rx PAUSE. Later, we will |
| 1606 | * disable the adapter's ability to send PAUSE frames. |
| 1607 | */ |
| 1608 | mflcn_reg |= IXGBE_MFLCN_RFCE; |
| 1609 | break; |
| 1610 | case ixgbe_fc_tx_pause: |
| 1611 | /* |
| 1612 | * Tx Flow control is enabled, and Rx Flow control is |
| 1613 | * disabled by software override. |
| 1614 | */ |
| 1615 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; |
| 1616 | break; |
| 1617 | case ixgbe_fc_full: |
| 1618 | /* Flow control (both Rx and Tx) is enabled by SW override. */ |
| 1619 | mflcn_reg |= IXGBE_MFLCN_RFCE; |
| 1620 | fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; |
| 1621 | break; |
PJ Waskiewicz | bb3daa4 | 2009-03-25 22:10:42 +0000 | [diff] [blame] | 1622 | #ifdef CONFIG_DCB |
| 1623 | case ixgbe_fc_pfc: |
| 1624 | goto out; |
| 1625 | break; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1626 | #endif /* CONFIG_DCB */ |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1627 | default: |
| 1628 | hw_dbg(hw, "Flow control param set incorrectly\n"); |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1629 | ret_val = IXGBE_ERR_CONFIG; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1630 | goto out; |
| 1631 | break; |
| 1632 | } |
| 1633 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1634 | /* Set 802.3x based flow control settings. */ |
PJ Waskiewicz | 2132d38 | 2009-04-09 22:26:21 +0000 | [diff] [blame] | 1635 | mflcn_reg |= IXGBE_MFLCN_DPF; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1636 | IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg); |
| 1637 | IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg); |
| 1638 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 1639 | rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num)); |
| 1640 | rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1641 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 1642 | fcrth = (rx_pba_size - hw->fc.high_water) << 10; |
| 1643 | fcrtl = (rx_pba_size - hw->fc.low_water) << 10; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1644 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 1645 | if (hw->fc.current_mode & ixgbe_fc_tx_pause) { |
| 1646 | fcrth |= IXGBE_FCRTH_FCEN; |
| 1647 | if (hw->fc.send_xon) |
| 1648 | fcrtl |= IXGBE_FCRTL_XONE; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 1651 | IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth); |
| 1652 | IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl); |
| 1653 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1654 | /* Configure pause time (2 TCs per register) */ |
Peter P Waskiewicz Jr | 70b7762 | 2009-05-17 12:34:55 +0000 | [diff] [blame] | 1655 | reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2)); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1656 | if ((packetbuf_num & 1) == 0) |
| 1657 | reg = (reg & 0xFFFF0000) | hw->fc.pause_time; |
| 1658 | else |
| 1659 | reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16); |
| 1660 | IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg); |
| 1661 | |
| 1662 | IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1)); |
| 1663 | |
| 1664 | out: |
| 1665 | return ret_val; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1669 | * ixgbe_fc_autoneg - Configure flow control |
| 1670 | * @hw: pointer to hardware structure |
| 1671 | * |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1672 | * Compares our advertised flow control capabilities to those advertised by |
| 1673 | * our link partner, and determines the proper flow control mode to use. |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1674 | **/ |
| 1675 | s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw) |
| 1676 | { |
| 1677 | s32 ret_val = 0; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1678 | ixgbe_link_speed speed; |
| 1679 | u32 pcs_anadv_reg, pcs_lpab_reg, linkstat; |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1680 | u32 links2, anlp1_reg, autoc_reg, links; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1681 | bool link_up; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1682 | |
| 1683 | /* |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1684 | * AN should have completed when the cable was plugged in. |
| 1685 | * Look for reasons to bail out. Bail out if: |
| 1686 | * - FC autoneg is disabled, or if |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1687 | * - link is not up. |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1688 | * |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1689 | * Since we're being called from an LSC, link is already known to be up. |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1690 | * So use link_up_wait_to_complete=false. |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1691 | */ |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1692 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1693 | |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1694 | if (hw->fc.disable_fc_autoneg || (!link_up)) { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1695 | hw->fc.fc_was_autonegged = false; |
| 1696 | hw->fc.current_mode = hw->fc.requested_mode; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1697 | goto out; |
| 1698 | } |
| 1699 | |
| 1700 | /* |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1701 | * On backplane, bail out if |
| 1702 | * - backplane autoneg was not completed, or if |
Don Skidmore | 000c486 | 2009-11-24 18:51:48 +0000 | [diff] [blame] | 1703 | * - we are 82599 and link partner is not AN enabled |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1704 | */ |
| 1705 | if (hw->phy.media_type == ixgbe_media_type_backplane) { |
| 1706 | links = IXGBE_READ_REG(hw, IXGBE_LINKS); |
Don Skidmore | 000c486 | 2009-11-24 18:51:48 +0000 | [diff] [blame] | 1707 | if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) { |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1708 | hw->fc.fc_was_autonegged = false; |
| 1709 | hw->fc.current_mode = hw->fc.requested_mode; |
| 1710 | goto out; |
| 1711 | } |
Don Skidmore | 000c486 | 2009-11-24 18:51:48 +0000 | [diff] [blame] | 1712 | |
| 1713 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1714 | links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2); |
| 1715 | if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) { |
| 1716 | hw->fc.fc_was_autonegged = false; |
| 1717 | hw->fc.current_mode = hw->fc.requested_mode; |
| 1718 | goto out; |
| 1719 | } |
| 1720 | } |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /* |
| 1724 | * On multispeed fiber at 1g, bail out if |
| 1725 | * - link is up but AN did not complete, or if |
| 1726 | * - link is up and AN completed but timed out |
| 1727 | */ |
| 1728 | if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) { |
| 1729 | linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); |
| 1730 | if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) || |
| 1731 | ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) { |
| 1732 | hw->fc.fc_was_autonegged = false; |
| 1733 | hw->fc.current_mode = hw->fc.requested_mode; |
| 1734 | goto out; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | /* |
PJ Waskiewicz | 9bbe3a5 | 2009-11-24 18:51:28 +0000 | [diff] [blame] | 1739 | * Bail out on |
| 1740 | * - copper or CX4 adapters |
| 1741 | * - fiber adapters running at 10gig |
| 1742 | */ |
| 1743 | if ((hw->phy.media_type == ixgbe_media_type_copper) || |
| 1744 | (hw->phy.media_type == ixgbe_media_type_cx4) || |
| 1745 | ((hw->phy.media_type == ixgbe_media_type_fiber) && |
| 1746 | (speed == IXGBE_LINK_SPEED_10GB_FULL))) { |
| 1747 | hw->fc.fc_was_autonegged = false; |
| 1748 | hw->fc.current_mode = hw->fc.requested_mode; |
| 1749 | goto out; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1753 | * Read the AN advertisement and LP ability registers and resolve |
| 1754 | * local flow control settings accordingly |
| 1755 | */ |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1756 | if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && |
| 1757 | (hw->phy.media_type != ixgbe_media_type_backplane)) { |
| 1758 | pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); |
| 1759 | pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); |
| 1760 | if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && |
| 1761 | (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) { |
| 1762 | /* |
| 1763 | * Now we need to check if the user selected Rx ONLY |
| 1764 | * of pause frames. In this case, we had to advertise |
| 1765 | * FULL flow control because we could not advertise RX |
| 1766 | * ONLY. Hence, we must now check to see if we need to |
| 1767 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 1768 | */ |
| 1769 | if (hw->fc.requested_mode == ixgbe_fc_full) { |
| 1770 | hw->fc.current_mode = ixgbe_fc_full; |
| 1771 | hw_dbg(hw, "Flow Control = FULL.\n"); |
| 1772 | } else { |
| 1773 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 1774 | hw_dbg(hw, "Flow Control=RX PAUSE only\n"); |
| 1775 | } |
| 1776 | } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && |
| 1777 | (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) && |
| 1778 | (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) && |
| 1779 | (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) { |
| 1780 | hw->fc.current_mode = ixgbe_fc_tx_pause; |
| 1781 | hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n"); |
| 1782 | } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && |
| 1783 | (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) && |
| 1784 | !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) && |
| 1785 | (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) { |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1786 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 1787 | hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n"); |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1788 | } else { |
| 1789 | hw->fc.current_mode = ixgbe_fc_none; |
| 1790 | hw_dbg(hw, "Flow Control = NONE.\n"); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1791 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1792 | } |
| 1793 | |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1794 | if (hw->phy.media_type == ixgbe_media_type_backplane) { |
| 1795 | /* |
| 1796 | * Read the 10g AN autoc and LP ability registers and resolve |
| 1797 | * local flow control settings accordingly |
| 1798 | */ |
| 1799 | autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 1800 | anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1); |
| 1801 | |
| 1802 | if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) && |
| 1803 | (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) { |
| 1804 | /* |
| 1805 | * Now we need to check if the user selected Rx ONLY |
| 1806 | * of pause frames. In this case, we had to advertise |
| 1807 | * FULL flow control because we could not advertise RX |
| 1808 | * ONLY. Hence, we must now check to see if we need to |
| 1809 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 1810 | */ |
| 1811 | if (hw->fc.requested_mode == ixgbe_fc_full) { |
| 1812 | hw->fc.current_mode = ixgbe_fc_full; |
| 1813 | hw_dbg(hw, "Flow Control = FULL.\n"); |
| 1814 | } else { |
| 1815 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 1816 | hw_dbg(hw, "Flow Control=RX PAUSE only\n"); |
| 1817 | } |
| 1818 | } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) && |
| 1819 | (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) && |
| 1820 | (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) && |
| 1821 | (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) { |
| 1822 | hw->fc.current_mode = ixgbe_fc_tx_pause; |
| 1823 | hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n"); |
| 1824 | } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) && |
| 1825 | (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) && |
| 1826 | !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) && |
| 1827 | (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) { |
| 1828 | hw->fc.current_mode = ixgbe_fc_rx_pause; |
| 1829 | hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n"); |
| 1830 | } else { |
| 1831 | hw->fc.current_mode = ixgbe_fc_none; |
| 1832 | hw_dbg(hw, "Flow Control = NONE.\n"); |
| 1833 | } |
| 1834 | } |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1835 | /* Record that current_mode is the result of a successful autoneg */ |
| 1836 | hw->fc.fc_was_autonegged = true; |
| 1837 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1838 | out: |
| 1839 | return ret_val; |
| 1840 | } |
| 1841 | |
| 1842 | /** |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1843 | * ixgbe_setup_fc - Set up flow control |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1844 | * @hw: pointer to hardware structure |
| 1845 | * |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1846 | * Called at init time to set up flow control. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1847 | **/ |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 1848 | static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num) |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1849 | { |
| 1850 | s32 ret_val = 0; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1851 | u32 reg; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1852 | |
PJ Waskiewicz | bb3daa4 | 2009-03-25 22:10:42 +0000 | [diff] [blame] | 1853 | #ifdef CONFIG_DCB |
| 1854 | if (hw->fc.requested_mode == ixgbe_fc_pfc) { |
| 1855 | hw->fc.current_mode = hw->fc.requested_mode; |
| 1856 | goto out; |
| 1857 | } |
| 1858 | |
| 1859 | #endif |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1860 | /* Validate the packetbuf configuration */ |
| 1861 | if (packetbuf_num < 0 || packetbuf_num > 7) { |
| 1862 | hw_dbg(hw, "Invalid packet buffer number [%d], expected range " |
| 1863 | "is 0-7\n", packetbuf_num); |
| 1864 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 1865 | goto out; |
| 1866 | } |
| 1867 | |
| 1868 | /* |
| 1869 | * Validate the water mark configuration. Zero water marks are invalid |
| 1870 | * because it causes the controller to just blast out fc packets. |
| 1871 | */ |
| 1872 | if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1873 | hw_dbg(hw, "Invalid water mark configuration\n"); |
| 1874 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 1875 | goto out; |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | /* |
| 1879 | * Validate the requested mode. Strict IEEE mode does not allow |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1880 | * ixgbe_fc_rx_pause because it will cause us to fail at UNH. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1881 | */ |
| 1882 | if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) { |
| 1883 | hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict " |
| 1884 | "IEEE mode\n"); |
| 1885 | ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 1886 | goto out; |
| 1887 | } |
| 1888 | |
| 1889 | /* |
| 1890 | * 10gig parts do not have a word in the EEPROM to determine the |
| 1891 | * default flow control setting, so we explicitly set it to full. |
| 1892 | */ |
| 1893 | if (hw->fc.requested_mode == ixgbe_fc_default) |
| 1894 | hw->fc.requested_mode = ixgbe_fc_full; |
| 1895 | |
| 1896 | /* |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1897 | * Set up the 1G flow control advertisement registers so the HW will be |
| 1898 | * able to do fc autoneg once the cable is plugged in. If we end up |
| 1899 | * using 10g instead, this is harmless. |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1900 | */ |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1901 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1902 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1903 | /* |
| 1904 | * The possible values of fc.requested_mode are: |
| 1905 | * 0: Flow control is completely disabled |
| 1906 | * 1: Rx flow control is enabled (we can receive pause frames, |
| 1907 | * but not send pause frames). |
| 1908 | * 2: Tx flow control is enabled (we can send pause frames but |
| 1909 | * we do not support receiving pause frames). |
| 1910 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
| 1911 | #ifdef CONFIG_DCB |
| 1912 | * 4: Priority Flow Control is enabled. |
| 1913 | #endif |
| 1914 | * other: Invalid. |
| 1915 | */ |
| 1916 | switch (hw->fc.requested_mode) { |
| 1917 | case ixgbe_fc_none: |
| 1918 | /* Flow control completely disabled by software override. */ |
| 1919 | reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); |
| 1920 | break; |
| 1921 | case ixgbe_fc_rx_pause: |
| 1922 | /* |
| 1923 | * Rx Flow control is enabled and Tx Flow control is |
| 1924 | * disabled by software override. Since there really |
| 1925 | * isn't a way to advertise that we are capable of RX |
| 1926 | * Pause ONLY, we will advertise that we support both |
| 1927 | * symmetric and asymmetric Rx PAUSE. Later, we will |
| 1928 | * disable the adapter's ability to send PAUSE frames. |
| 1929 | */ |
| 1930 | reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); |
| 1931 | break; |
| 1932 | case ixgbe_fc_tx_pause: |
| 1933 | /* |
| 1934 | * Tx Flow control is enabled, and Rx Flow control is |
| 1935 | * disabled by software override. |
| 1936 | */ |
| 1937 | reg |= (IXGBE_PCS1GANA_ASM_PAUSE); |
| 1938 | reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE); |
| 1939 | break; |
| 1940 | case ixgbe_fc_full: |
| 1941 | /* Flow control (both Rx and Tx) is enabled by SW override. */ |
| 1942 | reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); |
| 1943 | break; |
| 1944 | #ifdef CONFIG_DCB |
| 1945 | case ixgbe_fc_pfc: |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1946 | goto out; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | #endif /* CONFIG_DCB */ |
| 1949 | default: |
| 1950 | hw_dbg(hw, "Flow control param set incorrectly\n"); |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1951 | ret_val = IXGBE_ERR_CONFIG; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1952 | goto out; |
| 1953 | break; |
| 1954 | } |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1955 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1956 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg); |
| 1957 | reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); |
| 1958 | |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 1959 | /* Disable AN timeout */ |
| 1960 | if (hw->fc.strict_ieee) |
| 1961 | reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN; |
| 1962 | |
| 1963 | IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg); |
| 1964 | hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 1965 | |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 1966 | /* |
| 1967 | * Set up the 10G flow control advertisement registers so the HW |
| 1968 | * can do fc autoneg once the cable is plugged in. If we end up |
| 1969 | * using 1g instead, this is harmless. |
| 1970 | */ |
| 1971 | reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 1972 | |
| 1973 | /* |
| 1974 | * The possible values of fc.requested_mode are: |
| 1975 | * 0: Flow control is completely disabled |
| 1976 | * 1: Rx flow control is enabled (we can receive pause frames, |
| 1977 | * but not send pause frames). |
| 1978 | * 2: Tx flow control is enabled (we can send pause frames but |
| 1979 | * we do not support receiving pause frames). |
| 1980 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
| 1981 | * other: Invalid. |
| 1982 | */ |
| 1983 | switch (hw->fc.requested_mode) { |
| 1984 | case ixgbe_fc_none: |
| 1985 | /* Flow control completely disabled by software override. */ |
| 1986 | reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE); |
| 1987 | break; |
| 1988 | case ixgbe_fc_rx_pause: |
| 1989 | /* |
| 1990 | * Rx Flow control is enabled and Tx Flow control is |
| 1991 | * disabled by software override. Since there really |
| 1992 | * isn't a way to advertise that we are capable of RX |
| 1993 | * Pause ONLY, we will advertise that we support both |
| 1994 | * symmetric and asymmetric Rx PAUSE. Later, we will |
| 1995 | * disable the adapter's ability to send PAUSE frames. |
| 1996 | */ |
| 1997 | reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE); |
| 1998 | break; |
| 1999 | case ixgbe_fc_tx_pause: |
| 2000 | /* |
| 2001 | * Tx Flow control is enabled, and Rx Flow control is |
| 2002 | * disabled by software override. |
| 2003 | */ |
| 2004 | reg |= (IXGBE_AUTOC_ASM_PAUSE); |
| 2005 | reg &= ~(IXGBE_AUTOC_SYM_PAUSE); |
| 2006 | break; |
| 2007 | case ixgbe_fc_full: |
| 2008 | /* Flow control (both Rx and Tx) is enabled by SW override. */ |
| 2009 | reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE); |
| 2010 | break; |
| 2011 | #ifdef CONFIG_DCB |
| 2012 | case ixgbe_fc_pfc: |
| 2013 | goto out; |
| 2014 | break; |
| 2015 | #endif /* CONFIG_DCB */ |
| 2016 | default: |
| 2017 | hw_dbg(hw, "Flow control param set incorrectly\n"); |
| 2018 | ret_val = IXGBE_ERR_CONFIG; |
| 2019 | goto out; |
| 2020 | break; |
| 2021 | } |
| 2022 | /* |
| 2023 | * AUTOC restart handles negotiation of 1G and 10G. There is |
| 2024 | * no need to set the PCS1GCTL register. |
| 2025 | */ |
| 2026 | reg |= IXGBE_AUTOC_AN_RESTART; |
| 2027 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg); |
| 2028 | hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg); |
| 2029 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2030 | out: |
| 2031 | return ret_val; |
| 2032 | } |
| 2033 | |
| 2034 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2035 | * ixgbe_disable_pcie_master - Disable PCI-express master access |
| 2036 | * @hw: pointer to hardware structure |
| 2037 | * |
| 2038 | * Disables PCI-Express master access and verifies there are no pending |
| 2039 | * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable |
| 2040 | * bit hasn't caused the master requests to be disabled, else 0 |
| 2041 | * is returned signifying master requests disabled. |
| 2042 | **/ |
| 2043 | s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw) |
| 2044 | { |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2045 | struct ixgbe_adapter *adapter = hw->back; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2046 | u32 i; |
| 2047 | u32 reg_val; |
| 2048 | u32 number_of_queues; |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2049 | s32 status = 0; |
| 2050 | u16 dev_status = 0; |
| 2051 | |
| 2052 | /* Just jump out if bus mastering is already disabled */ |
| 2053 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) |
| 2054 | goto out; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2055 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2056 | /* Disable the receive unit by stopping each queue */ |
| 2057 | number_of_queues = hw->mac.max_rx_queues; |
| 2058 | for (i = 0; i < number_of_queues; i++) { |
| 2059 | reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 2060 | if (reg_val & IXGBE_RXDCTL_ENABLE) { |
| 2061 | reg_val &= ~IXGBE_RXDCTL_ENABLE; |
| 2062 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 2067 | reg_val |= IXGBE_CTRL_GIO_DIS; |
| 2068 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2069 | |
| 2070 | for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2071 | if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) |
| 2072 | goto check_device_status; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2073 | udelay(100); |
| 2074 | } |
| 2075 | |
Emil Tantilov | a4297dc | 2011-02-14 08:45:13 +0000 | [diff] [blame] | 2076 | hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n"); |
| 2077 | status = IXGBE_ERR_MASTER_REQUESTS_PENDING; |
| 2078 | |
| 2079 | /* |
| 2080 | * Before proceeding, make sure that the PCIe block does not have |
| 2081 | * transactions pending. |
| 2082 | */ |
| 2083 | check_device_status: |
| 2084 | for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { |
| 2085 | pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS, |
| 2086 | &dev_status); |
| 2087 | if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING)) |
| 2088 | break; |
| 2089 | udelay(100); |
| 2090 | } |
| 2091 | |
| 2092 | if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT) |
| 2093 | hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n"); |
| 2094 | else |
| 2095 | goto out; |
| 2096 | |
| 2097 | /* |
| 2098 | * Two consecutive resets are required via CTRL.RST per datasheet |
| 2099 | * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine |
| 2100 | * of this need. The first reset prevents new master requests from |
| 2101 | * being issued by our device. We then must wait 1usec for any |
| 2102 | * remaining completions from the PCIe bus to trickle in, and then reset |
| 2103 | * again to clear out any effects they may have had on our device. |
| 2104 | */ |
| 2105 | hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; |
| 2106 | |
| 2107 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2108 | return status; |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | /** |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2113 | * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2114 | * @hw: pointer to hardware structure |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2115 | * @mask: Mask to specify which semaphore to acquire |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2116 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2117 | * Acquires the SWFW semaphore thought the GSSR register for the specified |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2118 | * function (CSR, PHY0, PHY1, EEPROM, Flash) |
| 2119 | **/ |
| 2120 | s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask) |
| 2121 | { |
| 2122 | u32 gssr; |
| 2123 | u32 swmask = mask; |
| 2124 | u32 fwmask = mask << 5; |
| 2125 | s32 timeout = 200; |
| 2126 | |
| 2127 | while (timeout) { |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 2128 | /* |
| 2129 | * SW EEPROM semaphore bit is used for access to all |
| 2130 | * SW_FW_SYNC/GSSR bits (not just EEPROM) |
| 2131 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2132 | if (ixgbe_get_eeprom_semaphore(hw)) |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2133 | return IXGBE_ERR_SWFW_SYNC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2134 | |
| 2135 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); |
| 2136 | if (!(gssr & (fwmask | swmask))) |
| 2137 | break; |
| 2138 | |
| 2139 | /* |
| 2140 | * Firmware currently using resource (fwmask) or other software |
| 2141 | * thread currently using resource (swmask) |
| 2142 | */ |
| 2143 | ixgbe_release_eeprom_semaphore(hw); |
| 2144 | msleep(5); |
| 2145 | timeout--; |
| 2146 | } |
| 2147 | |
| 2148 | if (!timeout) { |
Emil Tantilov | dbf893e | 2011-02-08 09:42:41 +0000 | [diff] [blame] | 2149 | hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n"); |
Peter P Waskiewicz Jr | 539e5f0 | 2009-09-30 12:07:38 +0000 | [diff] [blame] | 2150 | return IXGBE_ERR_SWFW_SYNC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | gssr |= swmask; |
| 2154 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); |
| 2155 | |
| 2156 | ixgbe_release_eeprom_semaphore(hw); |
| 2157 | return 0; |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * ixgbe_release_swfw_sync - Release SWFW semaphore |
| 2162 | * @hw: pointer to hardware structure |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2163 | * @mask: Mask to specify which semaphore to release |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2164 | * |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2165 | * Releases the SWFW semaphore thought the GSSR register for the specified |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2166 | * function (CSR, PHY0, PHY1, EEPROM, Flash) |
| 2167 | **/ |
| 2168 | void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask) |
| 2169 | { |
| 2170 | u32 gssr; |
| 2171 | u32 swmask = mask; |
| 2172 | |
| 2173 | ixgbe_get_eeprom_semaphore(hw); |
| 2174 | |
| 2175 | gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); |
| 2176 | gssr &= ~swmask; |
| 2177 | IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); |
| 2178 | |
| 2179 | ixgbe_release_eeprom_semaphore(hw); |
| 2180 | } |
| 2181 | |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 2182 | /** |
| 2183 | * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit |
| 2184 | * @hw: pointer to hardware structure |
| 2185 | * @regval: register value to write to RXCTRL |
| 2186 | * |
| 2187 | * Enables the Rx DMA unit |
| 2188 | **/ |
| 2189 | s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval) |
| 2190 | { |
| 2191 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); |
| 2192 | |
| 2193 | return 0; |
| 2194 | } |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2195 | |
| 2196 | /** |
| 2197 | * ixgbe_blink_led_start_generic - Blink LED based on index. |
| 2198 | * @hw: pointer to hardware structure |
| 2199 | * @index: led number to blink |
| 2200 | **/ |
| 2201 | s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index) |
| 2202 | { |
| 2203 | ixgbe_link_speed speed = 0; |
| 2204 | bool link_up = 0; |
| 2205 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 2206 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 2207 | |
| 2208 | /* |
| 2209 | * Link must be up to auto-blink the LEDs; |
| 2210 | * Force it if link is down. |
| 2211 | */ |
| 2212 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
| 2213 | |
| 2214 | if (!link_up) { |
Peter P Waskiewicz Jr | 50ac58b | 2009-06-04 11:10:53 +0000 | [diff] [blame] | 2215 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; |
PJ Waskiewicz | 87c1201 | 2009-04-08 13:20:31 +0000 | [diff] [blame] | 2216 | autoc_reg |= IXGBE_AUTOC_FLU; |
| 2217 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); |
| 2218 | msleep(10); |
| 2219 | } |
| 2220 | |
| 2221 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 2222 | led_reg |= IXGBE_LED_BLINK(index); |
| 2223 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
| 2224 | IXGBE_WRITE_FLUSH(hw); |
| 2225 | |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | /** |
| 2230 | * ixgbe_blink_led_stop_generic - Stop blinking LED based on index. |
| 2231 | * @hw: pointer to hardware structure |
| 2232 | * @index: led number to stop blinking |
| 2233 | **/ |
| 2234 | s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index) |
| 2235 | { |
| 2236 | u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 2237 | u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 2238 | |
| 2239 | autoc_reg &= ~IXGBE_AUTOC_FLU; |
| 2240 | autoc_reg |= IXGBE_AUTOC_AN_RESTART; |
| 2241 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); |
| 2242 | |
| 2243 | led_reg &= ~IXGBE_LED_MODE_MASK(index); |
| 2244 | led_reg &= ~IXGBE_LED_BLINK(index); |
| 2245 | led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index); |
| 2246 | IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); |
| 2247 | IXGBE_WRITE_FLUSH(hw); |
| 2248 | |
| 2249 | return 0; |
| 2250 | } |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2251 | |
| 2252 | /** |
| 2253 | * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM |
| 2254 | * @hw: pointer to hardware structure |
| 2255 | * @san_mac_offset: SAN MAC address offset |
| 2256 | * |
| 2257 | * This function will read the EEPROM location for the SAN MAC address |
| 2258 | * pointer, and returns the value at that location. This is used in both |
| 2259 | * get and set mac_addr routines. |
| 2260 | **/ |
| 2261 | static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw, |
| 2262 | u16 *san_mac_offset) |
| 2263 | { |
| 2264 | /* |
| 2265 | * First read the EEPROM pointer to see if the MAC addresses are |
| 2266 | * available. |
| 2267 | */ |
| 2268 | hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset); |
| 2269 | |
| 2270 | return 0; |
| 2271 | } |
| 2272 | |
| 2273 | /** |
| 2274 | * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM |
| 2275 | * @hw: pointer to hardware structure |
| 2276 | * @san_mac_addr: SAN MAC address |
| 2277 | * |
| 2278 | * Reads the SAN MAC address from the EEPROM, if it's available. This is |
| 2279 | * per-port, so set_lan_id() must be called before reading the addresses. |
| 2280 | * set_lan_id() is called by identify_sfp(), but this cannot be relied |
| 2281 | * upon for non-SFP connections, so we must call it here. |
| 2282 | **/ |
| 2283 | s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr) |
| 2284 | { |
| 2285 | u16 san_mac_data, san_mac_offset; |
| 2286 | u8 i; |
| 2287 | |
| 2288 | /* |
| 2289 | * First read the EEPROM pointer to see if the MAC addresses are |
| 2290 | * available. If they're not, no point in calling set_lan_id() here. |
| 2291 | */ |
| 2292 | ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset); |
| 2293 | |
| 2294 | if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) { |
| 2295 | /* |
| 2296 | * No addresses available in this EEPROM. It's not an |
| 2297 | * error though, so just wipe the local address and return. |
| 2298 | */ |
| 2299 | for (i = 0; i < 6; i++) |
| 2300 | san_mac_addr[i] = 0xFF; |
| 2301 | |
| 2302 | goto san_mac_addr_out; |
| 2303 | } |
| 2304 | |
| 2305 | /* make sure we know which port we need to program */ |
| 2306 | hw->mac.ops.set_lan_id(hw); |
| 2307 | /* apply the port offset to the address offset */ |
| 2308 | (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) : |
| 2309 | (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET); |
| 2310 | for (i = 0; i < 3; i++) { |
| 2311 | hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data); |
| 2312 | san_mac_addr[i * 2] = (u8)(san_mac_data); |
| 2313 | san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8); |
| 2314 | san_mac_offset++; |
| 2315 | } |
| 2316 | |
| 2317 | san_mac_addr_out: |
| 2318 | return 0; |
| 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count |
| 2323 | * @hw: pointer to hardware structure |
| 2324 | * |
| 2325 | * Read PCIe configuration space, and get the MSI-X vector count from |
| 2326 | * the capabilities table. |
| 2327 | **/ |
| 2328 | u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw) |
| 2329 | { |
| 2330 | struct ixgbe_adapter *adapter = hw->back; |
| 2331 | u16 msix_count; |
| 2332 | pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS, |
| 2333 | &msix_count); |
| 2334 | msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK; |
| 2335 | |
| 2336 | /* MSI-X count is zero-based in HW, so increment to give proper value */ |
| 2337 | msix_count++; |
| 2338 | |
| 2339 | return msix_count; |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address |
| 2344 | * @hw: pointer to hardware struct |
| 2345 | * @rar: receive address register index to disassociate |
| 2346 | * @vmdq: VMDq pool index to remove from the rar |
| 2347 | **/ |
| 2348 | s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) |
| 2349 | { |
| 2350 | u32 mpsar_lo, mpsar_hi; |
| 2351 | u32 rar_entries = hw->mac.num_rar_entries; |
| 2352 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2353 | /* Make sure we are using a valid rar index range */ |
| 2354 | if (rar >= rar_entries) { |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2355 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2356 | return IXGBE_ERR_INVALID_ARGUMENT; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2359 | mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); |
| 2360 | mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); |
| 2361 | |
| 2362 | if (!mpsar_lo && !mpsar_hi) |
| 2363 | goto done; |
| 2364 | |
| 2365 | if (vmdq == IXGBE_CLEAR_VMDQ_ALL) { |
| 2366 | if (mpsar_lo) { |
| 2367 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0); |
| 2368 | mpsar_lo = 0; |
| 2369 | } |
| 2370 | if (mpsar_hi) { |
| 2371 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0); |
| 2372 | mpsar_hi = 0; |
| 2373 | } |
| 2374 | } else if (vmdq < 32) { |
| 2375 | mpsar_lo &= ~(1 << vmdq); |
| 2376 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo); |
| 2377 | } else { |
| 2378 | mpsar_hi &= ~(1 << (vmdq - 32)); |
| 2379 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi); |
| 2380 | } |
| 2381 | |
| 2382 | /* was that the last pool using this rar? */ |
| 2383 | if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0) |
| 2384 | hw->mac.ops.clear_rar(hw, rar); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2385 | done: |
| 2386 | return 0; |
| 2387 | } |
| 2388 | |
| 2389 | /** |
| 2390 | * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address |
| 2391 | * @hw: pointer to hardware struct |
| 2392 | * @rar: receive address register index to associate with a VMDq index |
| 2393 | * @vmdq: VMDq pool index |
| 2394 | **/ |
| 2395 | s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) |
| 2396 | { |
| 2397 | u32 mpsar; |
| 2398 | u32 rar_entries = hw->mac.num_rar_entries; |
| 2399 | |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2400 | /* Make sure we are using a valid rar index range */ |
| 2401 | if (rar >= rar_entries) { |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2402 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); |
Emil Tantilov | c700f4e | 2011-02-17 11:34:58 +0000 | [diff] [blame] | 2403 | return IXGBE_ERR_INVALID_ARGUMENT; |
| 2404 | } |
| 2405 | |
| 2406 | if (vmdq < 32) { |
| 2407 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); |
| 2408 | mpsar |= 1 << vmdq; |
| 2409 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar); |
| 2410 | } else { |
| 2411 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); |
| 2412 | mpsar |= 1 << (vmdq - 32); |
| 2413 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar); |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2414 | } |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array |
| 2420 | * @hw: pointer to hardware structure |
| 2421 | **/ |
| 2422 | s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw) |
| 2423 | { |
| 2424 | int i; |
| 2425 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2426 | for (i = 0; i < 128; i++) |
| 2427 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0); |
| 2428 | |
| 2429 | return 0; |
| 2430 | } |
| 2431 | |
| 2432 | /** |
| 2433 | * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot |
| 2434 | * @hw: pointer to hardware structure |
| 2435 | * @vlan: VLAN id to write to VLAN filter |
| 2436 | * |
| 2437 | * return the VLVF index where this VLAN id should be placed |
| 2438 | * |
| 2439 | **/ |
Emil Tantilov | 5d5b7c3 | 2010-10-12 22:20:59 +0000 | [diff] [blame] | 2440 | 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] | 2441 | { |
| 2442 | u32 bits = 0; |
| 2443 | u32 first_empty_slot = 0; |
| 2444 | s32 regindex; |
| 2445 | |
| 2446 | /* short cut the special case */ |
| 2447 | if (vlan == 0) |
| 2448 | return 0; |
| 2449 | |
| 2450 | /* |
| 2451 | * Search for the vlan id in the VLVF entries. Save off the first empty |
| 2452 | * slot found along the way |
| 2453 | */ |
| 2454 | for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) { |
| 2455 | bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex)); |
| 2456 | if (!bits && !(first_empty_slot)) |
| 2457 | first_empty_slot = regindex; |
| 2458 | else if ((bits & 0x0FFF) == vlan) |
| 2459 | break; |
| 2460 | } |
| 2461 | |
| 2462 | /* |
| 2463 | * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan |
| 2464 | * in the VLVF. Else use the first empty VLVF register for this |
| 2465 | * vlan id. |
| 2466 | */ |
| 2467 | if (regindex >= IXGBE_VLVF_ENTRIES) { |
| 2468 | if (first_empty_slot) |
| 2469 | regindex = first_empty_slot; |
| 2470 | else { |
| 2471 | hw_dbg(hw, "No space in VLVF.\n"); |
| 2472 | regindex = IXGBE_ERR_NO_SPACE; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | return regindex; |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * ixgbe_set_vfta_generic - Set VLAN filter table |
| 2481 | * @hw: pointer to hardware structure |
| 2482 | * @vlan: VLAN id to write to VLAN filter |
| 2483 | * @vind: VMDq output index that maps queue to VLAN id in VFVFB |
| 2484 | * @vlan_on: boolean flag to turn on/off VLAN in VFVF |
| 2485 | * |
| 2486 | * Turn on/off specified VLAN in the VLAN filter table. |
| 2487 | **/ |
| 2488 | s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, |
| 2489 | bool vlan_on) |
| 2490 | { |
| 2491 | s32 regindex; |
| 2492 | u32 bitindex; |
| 2493 | u32 vfta; |
| 2494 | u32 bits; |
| 2495 | u32 vt; |
| 2496 | u32 targetbit; |
| 2497 | bool vfta_changed = false; |
| 2498 | |
| 2499 | if (vlan > 4095) |
| 2500 | return IXGBE_ERR_PARAM; |
| 2501 | |
| 2502 | /* |
| 2503 | * this is a 2 part operation - first the VFTA, then the |
| 2504 | * VLVF and VLVFB if VT Mode is set |
| 2505 | * We don't write the VFTA until we know the VLVF part succeeded. |
| 2506 | */ |
| 2507 | |
| 2508 | /* Part 1 |
| 2509 | * The VFTA is a bitstring made up of 128 32-bit registers |
| 2510 | * that enable the particular VLAN id, much like the MTA: |
| 2511 | * bits[11-5]: which register |
| 2512 | * bits[4-0]: which bit in the register |
| 2513 | */ |
| 2514 | regindex = (vlan >> 5) & 0x7F; |
| 2515 | bitindex = vlan & 0x1F; |
| 2516 | targetbit = (1 << bitindex); |
| 2517 | vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex)); |
| 2518 | |
| 2519 | if (vlan_on) { |
| 2520 | if (!(vfta & targetbit)) { |
| 2521 | vfta |= targetbit; |
| 2522 | vfta_changed = true; |
| 2523 | } |
| 2524 | } else { |
| 2525 | if ((vfta & targetbit)) { |
| 2526 | vfta &= ~targetbit; |
| 2527 | vfta_changed = true; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | /* Part 2 |
| 2532 | * If VT Mode is set |
| 2533 | * Either vlan_on |
| 2534 | * make sure the vlan is in VLVF |
| 2535 | * set the vind bit in the matching VLVFB |
| 2536 | * Or !vlan_on |
| 2537 | * clear the pool bit and possibly the vind |
| 2538 | */ |
| 2539 | vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 2540 | if (vt & IXGBE_VT_CTL_VT_ENABLE) { |
| 2541 | s32 vlvf_index; |
| 2542 | |
| 2543 | vlvf_index = ixgbe_find_vlvf_slot(hw, vlan); |
| 2544 | if (vlvf_index < 0) |
| 2545 | return vlvf_index; |
| 2546 | |
| 2547 | if (vlan_on) { |
| 2548 | /* set the pool bit */ |
| 2549 | if (vind < 32) { |
| 2550 | bits = IXGBE_READ_REG(hw, |
| 2551 | IXGBE_VLVFB(vlvf_index*2)); |
| 2552 | bits |= (1 << vind); |
| 2553 | IXGBE_WRITE_REG(hw, |
| 2554 | IXGBE_VLVFB(vlvf_index*2), |
| 2555 | bits); |
| 2556 | } else { |
| 2557 | bits = IXGBE_READ_REG(hw, |
| 2558 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 2559 | bits |= (1 << (vind-32)); |
| 2560 | IXGBE_WRITE_REG(hw, |
| 2561 | IXGBE_VLVFB((vlvf_index*2)+1), |
| 2562 | bits); |
| 2563 | } |
| 2564 | } else { |
| 2565 | /* clear the pool bit */ |
| 2566 | if (vind < 32) { |
| 2567 | bits = IXGBE_READ_REG(hw, |
| 2568 | IXGBE_VLVFB(vlvf_index*2)); |
| 2569 | bits &= ~(1 << vind); |
| 2570 | IXGBE_WRITE_REG(hw, |
| 2571 | IXGBE_VLVFB(vlvf_index*2), |
| 2572 | bits); |
| 2573 | bits |= IXGBE_READ_REG(hw, |
| 2574 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 2575 | } else { |
| 2576 | bits = IXGBE_READ_REG(hw, |
| 2577 | IXGBE_VLVFB((vlvf_index*2)+1)); |
| 2578 | bits &= ~(1 << (vind-32)); |
| 2579 | IXGBE_WRITE_REG(hw, |
| 2580 | IXGBE_VLVFB((vlvf_index*2)+1), |
| 2581 | bits); |
| 2582 | bits |= IXGBE_READ_REG(hw, |
| 2583 | IXGBE_VLVFB(vlvf_index*2)); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | /* |
| 2588 | * If there are still bits set in the VLVFB registers |
| 2589 | * for the VLAN ID indicated we need to see if the |
| 2590 | * caller is requesting that we clear the VFTA entry bit. |
| 2591 | * If the caller has requested that we clear the VFTA |
| 2592 | * entry bit but there are still pools/VFs using this VLAN |
| 2593 | * ID entry then ignore the request. We're not worried |
| 2594 | * about the case where we're turning the VFTA VLAN ID |
| 2595 | * entry bit on, only when requested to turn it off as |
| 2596 | * there may be multiple pools and/or VFs using the |
| 2597 | * VLAN ID entry. In that case we cannot clear the |
| 2598 | * VFTA bit until all pools/VFs using that VLAN ID have also |
| 2599 | * been cleared. This will be indicated by "bits" being |
| 2600 | * zero. |
| 2601 | */ |
| 2602 | if (bits) { |
| 2603 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), |
| 2604 | (IXGBE_VLVF_VIEN | vlan)); |
| 2605 | if (!vlan_on) { |
| 2606 | /* someone wants to clear the vfta entry |
| 2607 | * but some pools/VFs are still using it. |
| 2608 | * Ignore it. */ |
| 2609 | vfta_changed = false; |
| 2610 | } |
| 2611 | } |
| 2612 | else |
| 2613 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0); |
| 2614 | } |
| 2615 | |
| 2616 | if (vfta_changed) |
| 2617 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta); |
| 2618 | |
| 2619 | return 0; |
| 2620 | } |
| 2621 | |
| 2622 | /** |
| 2623 | * ixgbe_clear_vfta_generic - Clear VLAN filter table |
| 2624 | * @hw: pointer to hardware structure |
| 2625 | * |
| 2626 | * Clears the VLAN filer table, and the VMDq index associated with the filter |
| 2627 | **/ |
| 2628 | s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw) |
| 2629 | { |
| 2630 | u32 offset; |
| 2631 | |
| 2632 | for (offset = 0; offset < hw->mac.vft_size; offset++) |
| 2633 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); |
| 2634 | |
| 2635 | for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) { |
| 2636 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0); |
| 2637 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0); |
| 2638 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0); |
| 2639 | } |
| 2640 | |
| 2641 | return 0; |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * ixgbe_check_mac_link_generic - Determine link and speed status |
| 2646 | * @hw: pointer to hardware structure |
| 2647 | * @speed: pointer to link speed |
| 2648 | * @link_up: true when link is up |
| 2649 | * @link_up_wait_to_complete: bool used to wait for link up or not |
| 2650 | * |
| 2651 | * Reads the links register to determine if link is up and the current speed |
| 2652 | **/ |
| 2653 | 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] | 2654 | bool *link_up, bool link_up_wait_to_complete) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2655 | { |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 2656 | u32 links_reg, links_orig; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2657 | u32 i; |
| 2658 | |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 2659 | /* clear the old state */ |
| 2660 | links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 2661 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2662 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); |
Emil Tantilov | 48de36c | 2011-02-16 01:38:08 +0000 | [diff] [blame] | 2663 | |
| 2664 | if (links_orig != links_reg) { |
| 2665 | hw_dbg(hw, "LINKS changed from %08X to %08X\n", |
| 2666 | links_orig, links_reg); |
| 2667 | } |
| 2668 | |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2669 | if (link_up_wait_to_complete) { |
| 2670 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { |
| 2671 | if (links_reg & IXGBE_LINKS_UP) { |
| 2672 | *link_up = true; |
| 2673 | break; |
| 2674 | } else { |
| 2675 | *link_up = false; |
| 2676 | } |
| 2677 | msleep(100); |
| 2678 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 2679 | } |
| 2680 | } else { |
| 2681 | if (links_reg & IXGBE_LINKS_UP) |
| 2682 | *link_up = true; |
| 2683 | else |
| 2684 | *link_up = false; |
| 2685 | } |
| 2686 | |
| 2687 | if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
| 2688 | IXGBE_LINKS_SPEED_10G_82599) |
| 2689 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 2690 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 2691 | IXGBE_LINKS_SPEED_1G_82599) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2692 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 2693 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == |
| 2694 | IXGBE_LINKS_SPEED_100_82599) |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2695 | *speed = IXGBE_LINK_SPEED_100_FULL; |
Emil Tantilov | 63d778d | 2011-02-19 08:43:39 +0000 | [diff] [blame] | 2696 | else |
| 2697 | *speed = IXGBE_LINK_SPEED_UNKNOWN; |
Mallikarjuna R Chilakala | 21ce849 | 2010-05-13 17:33:41 +0000 | [diff] [blame] | 2698 | |
| 2699 | /* if link is down, zero out the current_mode */ |
| 2700 | if (*link_up == false) { |
| 2701 | hw->fc.current_mode = ixgbe_fc_none; |
| 2702 | hw->fc.fc_was_autonegged = false; |
| 2703 | } |
| 2704 | |
| 2705 | return 0; |
| 2706 | } |
Don Skidmore | a391f1d | 2010-11-16 19:27:15 -0800 | [diff] [blame] | 2707 | |
| 2708 | /** |
| 2709 | * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from |
| 2710 | * the EEPROM |
| 2711 | * @hw: pointer to hardware structure |
| 2712 | * @wwnn_prefix: the alternative WWNN prefix |
| 2713 | * @wwpn_prefix: the alternative WWPN prefix |
| 2714 | * |
| 2715 | * This function will read the EEPROM from the alternative SAN MAC address |
| 2716 | * block to check the support for the alternative WWNN/WWPN prefix support. |
| 2717 | **/ |
| 2718 | s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix, |
| 2719 | u16 *wwpn_prefix) |
| 2720 | { |
| 2721 | u16 offset, caps; |
| 2722 | u16 alt_san_mac_blk_offset; |
| 2723 | |
| 2724 | /* clear output first */ |
| 2725 | *wwnn_prefix = 0xFFFF; |
| 2726 | *wwpn_prefix = 0xFFFF; |
| 2727 | |
| 2728 | /* check if alternative SAN MAC is supported */ |
| 2729 | hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR, |
| 2730 | &alt_san_mac_blk_offset); |
| 2731 | |
| 2732 | if ((alt_san_mac_blk_offset == 0) || |
| 2733 | (alt_san_mac_blk_offset == 0xFFFF)) |
| 2734 | goto wwn_prefix_out; |
| 2735 | |
| 2736 | /* check capability in alternative san mac address block */ |
| 2737 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET; |
| 2738 | hw->eeprom.ops.read(hw, offset, &caps); |
| 2739 | if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN)) |
| 2740 | goto wwn_prefix_out; |
| 2741 | |
| 2742 | /* get the corresponding prefix for WWNN/WWPN */ |
| 2743 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET; |
| 2744 | hw->eeprom.ops.read(hw, offset, wwnn_prefix); |
| 2745 | |
| 2746 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET; |
| 2747 | hw->eeprom.ops.read(hw, offset, wwpn_prefix); |
| 2748 | |
| 2749 | wwn_prefix_out: |
| 2750 | return 0; |
| 2751 | } |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 2752 | |
| 2753 | /** |
| 2754 | * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing |
| 2755 | * @hw: pointer to hardware structure |
| 2756 | * @enable: enable or disable switch for anti-spoofing |
| 2757 | * @pf: Physical Function pool - do not enable anti-spoofing for the PF |
| 2758 | * |
| 2759 | **/ |
| 2760 | void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf) |
| 2761 | { |
| 2762 | int j; |
| 2763 | int pf_target_reg = pf >> 3; |
| 2764 | int pf_target_shift = pf % 8; |
| 2765 | u32 pfvfspoof = 0; |
| 2766 | |
| 2767 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2768 | return; |
| 2769 | |
| 2770 | if (enable) |
| 2771 | pfvfspoof = IXGBE_SPOOF_MACAS_MASK; |
| 2772 | |
| 2773 | /* |
| 2774 | * PFVFSPOOF register array is size 8 with 8 bits assigned to |
| 2775 | * MAC anti-spoof enables in each register array element. |
| 2776 | */ |
| 2777 | for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++) |
| 2778 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof); |
| 2779 | |
| 2780 | /* If not enabling anti-spoofing then done */ |
| 2781 | if (!enable) |
| 2782 | return; |
| 2783 | |
| 2784 | /* |
| 2785 | * The PF should be allowed to spoof so that it can support |
| 2786 | * emulation mode NICs. Reset the bit assigned to the PF |
| 2787 | */ |
| 2788 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg)); |
| 2789 | pfvfspoof ^= (1 << pf_target_shift); |
| 2790 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof); |
| 2791 | } |
| 2792 | |
| 2793 | /** |
| 2794 | * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing |
| 2795 | * @hw: pointer to hardware structure |
| 2796 | * @enable: enable or disable switch for VLAN anti-spoofing |
| 2797 | * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing |
| 2798 | * |
| 2799 | **/ |
| 2800 | void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf) |
| 2801 | { |
| 2802 | int vf_target_reg = vf >> 3; |
| 2803 | int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT; |
| 2804 | u32 pfvfspoof; |
| 2805 | |
| 2806 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2807 | return; |
| 2808 | |
| 2809 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); |
| 2810 | if (enable) |
| 2811 | pfvfspoof |= (1 << vf_target_shift); |
| 2812 | else |
| 2813 | pfvfspoof &= ~(1 << vf_target_shift); |
| 2814 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof); |
| 2815 | } |