blob: 561f666618e439b585139ac9674a16aa6cd21c4f [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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 Kok9a799d72007-09-15 14:07:45 -070023 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 Pirkoccffad252009-05-22 23:22:17 +000031#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_common.h"
35#include "ixgbe_phy.h"
36
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070037static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070040static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Don Skidmore7b25cdb2009-08-25 04:47:32 +000050static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
Auke Kok9a799d72007-09-15 14:07:45 -070051
52/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070053 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070054 * @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 Brandeburgc44ade92008-09-11 19:59:59 -070061s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070062{
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 Brandeburgc44ade92008-09-11 19:59:59 -070069 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070070
Auke Kok9a799d72007-09-15 14:07:45 -070071 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070072 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070073
Auke Kok9a799d72007-09-15 14:07:45 -070074 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070075 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070076
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 Kok3957d632007-10-31 15:22:10 -070081 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070082
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000083 /* Setup flow control */
84 ixgbe_setup_fc(hw, 0);
85
Auke Kok9a799d72007-09-15 14:07:45 -070086 /* Clear adapter stopped flag */
87 hw->adapter_stopped = false;
88
89 return 0;
90}
91
92/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070093 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -070094 * @hw: pointer to hardware structure
95 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070096 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -070097 * 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 Brandeburgc44ade92008-09-11 19:59:59 -0700102s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700103{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000104 s32 status;
105
Auke Kok9a799d72007-09-15 14:07:45 -0700106 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000107 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700108
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000109 if (status == 0) {
110 /* Start the HW */
111 status = hw->mac.ops.start_hw(hw);
112 }
Auke Kok9a799d72007-09-15 14:07:45 -0700113
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000114 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700115}
116
117/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700118 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700119 * @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 Brandeburgc44ade92008-09-11 19:59:59 -0700124s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700125{
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 Kok9a799d72007-09-15 14:07:45 -0700139 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Emil Tantilov667c7562011-02-26 06:40:05 +0000140 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 Kok9a799d72007-09-15 14:07:45 -0700147
148 for (i = 0; i < 8; i++) {
149 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700150 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000151 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 Kok9a799d72007-09-15 14:07:45 -0700158 }
Emil Tantilov667c7562011-02-26 06:40:05 +0000159 if (hw->mac.type >= ixgbe_mac_82599EB)
160 for (i = 0; i < 8; i++)
161 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700162 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 Kok9a799d72007-09-15 14:07:45 -0700199 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000200 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 Kok9a799d72007-09-15 14:07:45 -0700210 }
211
Emil Tantilova3aeea02011-02-26 06:40:11 +0000212 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 Kok9a799d72007-09-15 14:07:45 -0700221 return 0;
222}
223
224/**
Don Skidmore289700db2010-12-03 03:32:58 +0000225 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700226 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000227 * @pba_num: stores the part number string from the EEPROM
228 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700229 *
Don Skidmore289700db2010-12-03 03:32:58 +0000230 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700231 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000232s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
233 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700234{
235 s32 ret_val;
236 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000237 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 Brandeburgc44ade92008-09-11 19:59:59 -0700245
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 Brandeburgc44ade92008-09-11 19:59:59 -0700251
Don Skidmore289700db2010-12-03 03:32:58 +0000252 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700253 if (ret_val) {
254 hw_dbg(hw, "NVM Read Error\n");
255 return ret_val;
256 }
Don Skidmore289700db2010-12-03 03:32:58 +0000257
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 Brandeburgc44ade92008-09-11 19:59:59 -0700329
330 return 0;
331}
332
333/**
334 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700335 * @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 Brandeburgc44ade92008-09-11 19:59:59 -0700342s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700343{
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 Kok9a799d72007-09-15 14:07:45 -0700360/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000361 * 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 **/
366s32 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 **/
420void 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 Brandeburgc44ade92008-09-11 19:59:59 -0700436 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700437 * @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 Brandeburgc44ade92008-09-11 19:59:59 -0700444s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700445{
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 Brandeburgc44ade92008-09-11 19:59:59 -0700460 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700461 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 Brandeburgc44ade92008-09-11 19:59:59 -0700470 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700471 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 Brandeburgc44ade92008-09-11 19:59:59 -0700479 /*
480 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
481 * access and verify no pending requests
482 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000483 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700484
Auke Kok9a799d72007-09-15 14:07:45 -0700485 return 0;
486}
487
488/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700489 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700490 * @hw: pointer to hardware structure
491 * @index: led number to turn on
492 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700493s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700494{
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 Kok3957d632007-10-31 15:22:10 -0700501 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700502
503 return 0;
504}
505
506/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700507 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700508 * @hw: pointer to hardware structure
509 * @index: led number to turn off
510 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700511s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700512{
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 Kok3957d632007-10-31 15:22:10 -0700519 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700520
521 return 0;
522}
523
Auke Kok9a799d72007-09-15 14:07:45 -0700524/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700525 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700526 * @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 Brandeburgc44ade92008-09-11 19:59:59 -0700531s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700532{
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 Brandeburgc44ade92008-09-11 19:59:59 -0700539 /* Set default semaphore delay to 10ms which is a well
540 * tested value */
541 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700542
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 Waskiewicz11afc1b2009-02-27 15:44:30 +0000574 * 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 **/
582s32 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 Waskiewicz11afc1b2009-02-27 15:44:30 +0000631 /* Done with writing - release the EEPROM */
632 ixgbe_release_eeprom(hw);
633 }
634
635out:
636 return status;
637}
638
639/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700640 * 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 **/
647s32 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
695out:
696 return status;
697}
698
699/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000700 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700701 * @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 Chilakala21ce8492010-05-13 17:33:41 +0000707s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700708{
709 u32 eerd;
710 s32 status;
711
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700712 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 Chilakala21ce8492010-05-13 17:33:41 +0000719 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
720 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700721
722 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000723 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700724
725 if (status == 0)
726 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000727 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700728 else
729 hw_dbg(hw, "Eeprom read timed out\n");
730
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700731out:
Auke Kok9a799d72007-09-15 14:07:45 -0700732 return status;
733}
734
735/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000736 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700737 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000738 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700739 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000740 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
741 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700742 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800743s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700744{
745 u32 i;
746 u32 reg;
747 s32 status = IXGBE_ERR_EEPROM;
748
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000749 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 Kok9a799d72007-09-15 14:07:45 -0700756 status = 0;
757 break;
758 }
759 udelay(5);
760 }
761 return status;
762}
763
764/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700765 * 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 **/
771static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
772{
773 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000774 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700775 u32 i;
776
Don Skidmore5e655102011-02-25 01:58:04 +0000777 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700778 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 Skidmore5e655102011-02-25 01:58:04 +0000800 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700801 status = IXGBE_ERR_EEPROM;
802 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700803
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000804 /* 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 Brandeburgc44ade92008-09-11 19:59:59 -0700812 }
813 return status;
814}
815
816/**
Auke Kok9a799d72007-09-15 14:07:45 -0700817 * 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 **/
822static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
823{
824 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000825 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700826 u32 i;
827 u32 swsm;
828
Auke Kok9a799d72007-09-15 14:07:45 -0700829 /* 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 Tantilovdbf893e2011-02-08 09:42:41 +0000840 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700841 }
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 Tantilovdbf893e2011-02-08 09:42:41 +0000868 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700869 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700870 ixgbe_release_eeprom_semaphore(hw);
871 status = IXGBE_ERR_EEPROM;
872 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000873 } else {
874 hw_dbg(hw, "Software semaphore SMBI between device drivers "
875 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700876 }
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 **/
887static 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 Kok3957d632007-10-31 15:22:10 -0700896 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700897}
898
899/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700900 * ixgbe_ready_eeprom - Polls for EEPROM ready
901 * @hw: pointer to hardware structure
902 **/
903static 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 **/
942static 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 **/
965static 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 **/
1018static 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 **/
1056static 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 **/
1073static 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 **/
1089static 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 Skidmore90827992011-03-05 18:59:20 -08001107 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001108
1109 /* Delay before attempt to obtain semaphore again to allow FW access */
1110 msleep(hw->eeprom.semaphore_delay);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001111}
1112
1113/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001114 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001115 * @hw: pointer to hardware structure
1116 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001117u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001118{
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 Brandeburgc44ade92008-09-11 19:59:59 -07001128 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001129 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 Brandeburgc44ade92008-09-11 19:59:59 -07001137 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001138
1139 /* Make sure the pointer seems valid */
1140 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001141 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001142
1143 if (length != 0xFFFF && length != 0) {
1144 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001145 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001146 checksum += word;
1147 }
1148 }
1149 }
1150 }
1151
1152 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1153
1154 return checksum;
1155}
1156
1157/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001158 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001159 * @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 Brandeburgc44ade92008-09-11 19:59:59 -07001165s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1166 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001167{
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 Brandeburgc44ade92008-09-11 19:59:59 -07001177 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001178
1179 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001180 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001181
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001182 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001183
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 Brandeburgc44ade92008-09-11 19:59:59 -07001202 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1203 * @hw: pointer to hardware structure
1204 **/
1205s32 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 Skidmorea391f1d2010-11-16 19:27:15 -08001218 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001219 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001220 checksum);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001221 } else {
1222 hw_dbg(hw, "EEPROM read failed\n");
1223 }
1224
1225 return status;
1226}
1227
1228/**
Auke Kok9a799d72007-09-15 14:07:45 -07001229 * 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 **/
1234s32 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 Brandeburgc44ade92008-09-11 19:59:59 -07001246 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001247 status = IXGBE_ERR_INVALID_MAC_ADDR;
1248
1249 return status;
1250}
1251
1252/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001253 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001254 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001255 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001256 * @addr: Address to put into receive address register
1257 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001258 * @enable_addr: set flag that address is active
1259 *
1260 * Puts an ethernet address into a receive address register.
1261 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001262s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1263 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001264{
1265 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001266 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001267
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001268 /* 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 Brandeburgc44ade92008-09-11 19:59:59 -07001274 /* setup VMDq pool selection before this RAR gets enabled */
1275 hw->mac.ops.set_vmdq(hw, index, vmdq);
1276
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001277 /*
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 Kok9a799d72007-09-15 14:07:45 -07001293
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001294 if (enable_addr != 0)
1295 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001296
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001297 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1298 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001299
1300 return 0;
1301}
1302
1303/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001304 * 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 **/
1310s32 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 Tantilovc700f4e2011-02-17 11:34:58 +00001316 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001317 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001318 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001319 }
1320
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001321 /*
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 Brandeburgc44ade92008-09-11 19:59:59 -07001332 /* 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 Brandeburgc44ade92008-09-11 19:59:59 -07001339 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001340 * @hw: pointer to hardware structure
1341 *
1342 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001343 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001344 * the receiver is in reset when the routine is called.
1345 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001346s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001347{
1348 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001349 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001350
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 Brandeburgc44ade92008-09-11 19:59:59 -07001359 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001360
hartleysce7194d2010-01-05 06:56:52 +00001361 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001362 } else {
1363 /* Setup the receive address. */
1364 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001365 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001366
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001367 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001368
1369 /* clear VMDq pool/queue selection for RAR 0 */
1370 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001371 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001372 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001373
1374 hw->addr_ctrl.rar_used_count = 1;
1375
1376 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001377 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001378 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 Kok9a799d72007-09-15 14:07:45 -07001384 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 Leech2c5645c2008-08-26 04:27:02 -07001388 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001389 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1390
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001391 if (hw->mac.ops.init_uta_tables)
1392 hw->mac.ops.init_uta_tables(hw);
1393
Auke Kok9a799d72007-09-15 14:07:45 -07001394 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 Brandeburgc44ade92008-09-11 19:59:59 -07001406 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001407 * to mc_filter_type.
1408 **/
1409static 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 Waskiewiczb4617242008-09-11 20:04:46 -07001414 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001415 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1416 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001417 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001418 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1419 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001420 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001421 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1422 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001423 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001424 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1425 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001426 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001427 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 **/
1443static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1444{
1445 u32 vector;
1446 u32 vector_bit;
1447 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001448
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 Tantilov80960ab2011-02-18 08:58:27 +00001465 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001466}
1467
1468/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001469 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001470 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001471 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001472 *
1473 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001474 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001475 * registers for the first multicast addresses, and hashes the rest into the
1476 * multicast table.
1477 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001478s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1479 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001480{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001481 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001482 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001483
1484 /*
1485 * Set the new number of MC addresses that we are being requested to
1486 * use.
1487 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001488 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001489 hw->addr_ctrl.mta_in_use = 0;
1490
Emil Tantilov80960ab2011-02-18 08:58:27 +00001491 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001492 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001493 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Emil Tantilov80960ab2011-02-18 08:58:27 +00001495 /* Update mta shadow */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001496 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001497 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad32010-04-01 21:22:57 +00001498 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001499 }
1500
1501 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001502 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 Kok9a799d72007-09-15 14:07:45 -07001506 if (hw->addr_ctrl.mta_in_use > 0)
1507 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001508 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001509
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001510 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001511 return 0;
1512}
1513
1514/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001515 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001516 * @hw: pointer to hardware structure
1517 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001518 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001519 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001520s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001521{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001522 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001523
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001524 if (a->mta_in_use > 0)
1525 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1526 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001527
1528 return 0;
1529}
1530
1531/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001532 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001533 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001534 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001535 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001536 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001537s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001538{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001539 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001540
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001541 if (a->mta_in_use > 0)
1542 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001543
1544 return 0;
1545}
1546
1547/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001548 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001549 * @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 Chilakala620fa032009-06-04 11:11:13 +00001554s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001555{
1556 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001557 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001558 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001559 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001560 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001561
1562#ifdef CONFIG_DCB
1563 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1564 goto out;
1565
1566#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001567 /* Negotiate the fc mode to use */
1568 ret_val = ixgbe_fc_autoneg(hw);
1569 if (ret_val)
1570 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001571
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001572 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001573 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 Waskiewiczbb3daa42009-03-25 22:10:42 +00001584 * 2: Tx flow control is enabled (we can send pause frames but
1585 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001586 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001587#ifdef CONFIG_DCB
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001588 * 4: Priority Flow Control is enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001589#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001590 * other: Invalid.
1591 */
1592 switch (hw->fc.current_mode) {
1593 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001594 /*
1595 * Flow control is disabled by software override or autoneg.
1596 * The code below will actually disable it in the HW.
1597 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001598 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 Waskiewiczbb3daa42009-03-25 22:10:42 +00001622#ifdef CONFIG_DCB
1623 case ixgbe_fc_pfc:
1624 goto out;
1625 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001626#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001627 default:
1628 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001629 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001630 goto out;
1631 break;
1632 }
1633
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001634 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001635 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001636 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1637 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1638
John Fastabend16b61be2010-11-16 19:26:44 -08001639 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1640 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001641
John Fastabend16b61be2010-11-16 19:26:44 -08001642 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1643 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001644
John Fastabend16b61be2010-11-16 19:26:44 -08001645 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 Waskiewicz11afc1b2009-02-27 15:44:30 +00001649 }
1650
John Fastabend16b61be2010-11-16 19:26:44 -08001651 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1652 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1653
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001654 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001655 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001656 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
1664out:
1665 return ret_val;
1666}
1667
1668/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001669 * ixgbe_fc_autoneg - Configure flow control
1670 * @hw: pointer to hardware structure
1671 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001672 * 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 Jr0ecc0612009-02-06 21:46:54 -08001674 **/
1675s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1676{
1677 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001678 ixgbe_link_speed speed;
1679 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001680 u32 links2, anlp1_reg, autoc_reg, links;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001681 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001682
1683 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001684 * 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 Jr539e5f02009-09-30 12:07:38 +00001687 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001688 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001689 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001690 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001691 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001692 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001693
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001694 if (hw->fc.disable_fc_autoneg || (!link_up)) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001695 hw->fc.fc_was_autonegged = false;
1696 hw->fc.current_mode = hw->fc.requested_mode;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001697 goto out;
1698 }
1699
1700 /*
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001701 * On backplane, bail out if
1702 * - backplane autoneg was not completed, or if
Don Skidmore000c4862009-11-24 18:51:48 +00001703 * - we are 82599 and link partner is not AN enabled
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001704 */
1705 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1706 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Don Skidmore000c4862009-11-24 18:51:48 +00001707 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001708 hw->fc.fc_was_autonegged = false;
1709 hw->fc.current_mode = hw->fc.requested_mode;
1710 goto out;
1711 }
Don Skidmore000c4862009-11-24 18:51:48 +00001712
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 Jr539e5f02009-09-30 12:07:38 +00001721 }
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 Waskiewicz9bbe3a52009-11-24 18:51:28 +00001739 * 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 Jr0ecc0612009-02-06 21:46:54 -08001753 * Read the AN advertisement and LP ability registers and resolve
1754 * local flow control settings accordingly
1755 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001756 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 Jr0ecc0612009-02-06 21:46:54 -08001786 hw->fc.current_mode = ixgbe_fc_rx_pause;
1787 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001788 } else {
1789 hw->fc.current_mode = ixgbe_fc_none;
1790 hw_dbg(hw, "Flow Control = NONE.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001791 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001792 }
1793
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001794 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 Chilakala620fa032009-06-04 11:11:13 +00001835 /* Record that current_mode is the result of a successful autoneg */
1836 hw->fc.fc_was_autonegged = true;
1837
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001838out:
1839 return ret_val;
1840}
1841
1842/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001843 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001844 * @hw: pointer to hardware structure
1845 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001846 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001847 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001848static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001849{
1850 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001851 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001852
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001853#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 Waskiewicz11afc1b2009-02-27 15:44:30 +00001860 /* 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 Chilakala620fa032009-06-04 11:11:13 +00001873 hw_dbg(hw, "Invalid water mark configuration\n");
1874 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1875 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001876 }
1877
1878 /*
1879 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001880 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001881 */
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 Chilakala620fa032009-06-04 11:11:13 +00001897 * 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 Waskiewicz11afc1b2009-02-27 15:44:30 +00001900 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001901 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001902
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001903 /*
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 Waskiewicz11afc1b2009-02-27 15:44:30 +00001946 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001947 break;
1948#endif /* CONFIG_DCB */
1949 default:
1950 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001951 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001952 goto out;
1953 break;
1954 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001955
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001956 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
1957 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
1958
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001959 /* 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 Waskiewicz11afc1b2009-02-27 15:44:30 +00001965
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001966 /*
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 Waskiewicz11afc1b2009-02-27 15:44:30 +00002030out:
2031 return ret_val;
2032}
2033
2034/**
Auke Kok9a799d72007-09-15 14:07:45 -07002035 * 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 **/
2043s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2044{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002045 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002046 u32 i;
2047 u32 reg_val;
2048 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002049 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 Kok9a799d72007-09-15 14:07:45 -07002055
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002056 /* 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 Kok9a799d72007-09-15 14:07:45 -07002069
2070 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002071 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2072 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002073 udelay(100);
2074 }
2075
Emil Tantilova4297dc2011-02-14 08:45:13 +00002076 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 */
2083check_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
2107out:
Auke Kok9a799d72007-09-15 14:07:45 -07002108 return status;
2109}
2110
2111
2112/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002113 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002114 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002115 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002116 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002117 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002118 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2119 **/
2120s32 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 Tantilovdbf893e2011-02-08 09:42:41 +00002128 /*
2129 * SW EEPROM semaphore bit is used for access to all
2130 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2131 */
Auke Kok9a799d72007-09-15 14:07:45 -07002132 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002133 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002134
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 Tantilovdbf893e2011-02-08 09:42:41 +00002149 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002150 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002151 }
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 Brandeburgc44ade92008-09-11 19:59:59 -07002163 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002164 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002165 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002166 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2167 **/
2168void 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 Waskiewicz11afc1b2009-02-27 15:44:30 +00002182/**
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 **/
2189s32 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 Waskiewicz87c12012009-04-08 13:20:31 +00002195
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 **/
2201s32 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 Jr50ac58b2009-06-04 11:10:53 +00002215 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002216 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 **/
2234s32 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 Chilakala21ce8492010-05-13 17:33:41 +00002251
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 **/
2261static 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 **/
2283s32 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
2317san_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 **/
2328u32 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 **/
2348s32 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 Tantilovc700f4e2011-02-17 11:34:58 +00002353 /* Make sure we are using a valid rar index range */
2354 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002355 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002356 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002357 }
2358
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002359 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 Chilakala21ce8492010-05-13 17:33:41 +00002385done:
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 **/
2395s32 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 Tantilovc700f4e2011-02-17 11:34:58 +00002400 /* Make sure we are using a valid rar index range */
2401 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002402 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002403 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 Chilakala21ce8492010-05-13 17:33:41 +00002414 }
2415 return 0;
2416}
2417
2418/**
2419 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2420 * @hw: pointer to hardware structure
2421 **/
2422s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2423{
2424 int i;
2425
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002426 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 Tantilov5d5b7c32010-10-12 22:20:59 +00002440static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002441{
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 **/
2488s32 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 **/
2628s32 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 **/
2653s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00002654 bool *link_up, bool link_up_wait_to_complete)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002655{
Emil Tantilov48de36c2011-02-16 01:38:08 +00002656 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002657 u32 i;
2658
Emil Tantilov48de36c2011-02-16 01:38:08 +00002659 /* clear the old state */
2660 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
2661
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002662 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00002663
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 Chilakala21ce8492010-05-13 17:33:41 +00002669 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 Tantilov63d778d2011-02-19 08:43:39 +00002691 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002692 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002693 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2694 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002695 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002696 else
2697 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002698
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 Skidmorea391f1d2010-11-16 19:27:15 -08002707
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 **/
2718s32 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
2749wwn_prefix_out:
2750 return 0;
2751}
Greg Rosea985b6c32010-11-18 03:02:52 +00002752
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 **/
2760void 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 **/
2800void 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}