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