blob: 345c32eab4a543a0e473f25e53023887a50dc96b [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Shannon Nelson8c47eaa2010-01-13 01:49:34 +00004 Copyright(c) 1999 - 2010 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
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070049static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
50static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
Auke Kok9a799d72007-09-15 14:07:45 -070051static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070052static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
Don Skidmore7b25cdb2009-08-25 04:47:32 +000053static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
Auke Kok9a799d72007-09-15 14:07:45 -070054
55/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070056 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070057 * @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 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070064s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070065{
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 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070072 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070073
Auke Kok9a799d72007-09-15 14:07:45 -070074 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070075 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070076
Auke Kok9a799d72007-09-15 14:07:45 -070077 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070078 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070079
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);
Auke Kok3957d632007-10-31 15:22:10 -070084 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070085
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000086 /* Setup flow control */
87 ixgbe_setup_fc(hw, 0);
88
Auke Kok9a799d72007-09-15 14:07:45 -070089 /* Clear adapter stopped flag */
90 hw->adapter_stopped = false;
91
92 return 0;
93}
94
95/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070096 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -070097 * @hw: pointer to hardware structure
98 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070099 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700100 * 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 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700105s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700106{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000107 s32 status;
108
Auke Kok9a799d72007-09-15 14:07:45 -0700109 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000110 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700111
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000112 if (status == 0) {
113 /* Start the HW */
114 status = hw->mac.ops.start_hw(hw);
115 }
Auke Kok9a799d72007-09-15 14:07:45 -0700116
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000117 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700118}
119
120/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700121 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700122 * @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 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700127s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700128{
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/**
Don Skidmore289700db2010-12-03 03:32:58 +0000199 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700200 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000201 * @pba_num: stores the part number string from the EEPROM
202 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700203 *
Don Skidmore289700db2010-12-03 03:32:58 +0000204 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700205 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000206s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
207 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700208{
209 s32 ret_val;
210 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000211 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 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700219
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 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700225
Don Skidmore289700db2010-12-03 03:32:58 +0000226 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700227 if (ret_val) {
228 hw_dbg(hw, "NVM Read Error\n");
229 return ret_val;
230 }
Don Skidmore289700db2010-12-03 03:32:58 +0000231
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';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700303
304 return 0;
305}
306
307/**
308 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700309 * @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 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700316s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700317{
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
Auke Kok9a799d72007-09-15 14:07:45 -0700334/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000335 * 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 **/
340s32 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 **/
394void 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/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700410 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700411 * @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 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700418s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700419{
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);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700434 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700435 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. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700444 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700445 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
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700453 /*
454 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
455 * access and verify no pending requests
456 */
457 if (ixgbe_disable_pcie_master(hw) != 0)
458 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
459
Auke Kok9a799d72007-09-15 14:07:45 -0700460 return 0;
461}
462
463/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700464 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700465 * @hw: pointer to hardware structure
466 * @index: led number to turn on
467 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700468s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700469{
470 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
471
472 /* To turn on the LED, set mode to ON. */
473 led_reg &= ~IXGBE_LED_MODE_MASK(index);
474 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
475 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700476 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700477
478 return 0;
479}
480
481/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700482 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700483 * @hw: pointer to hardware structure
484 * @index: led number to turn off
485 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700486s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700487{
488 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
489
490 /* To turn off the LED, set mode to OFF. */
491 led_reg &= ~IXGBE_LED_MODE_MASK(index);
492 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
493 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700494 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700495
496 return 0;
497}
498
Auke Kok9a799d72007-09-15 14:07:45 -0700499/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700500 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700501 * @hw: pointer to hardware structure
502 *
503 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
504 * ixgbe_hw struct in order to set up EEPROM access.
505 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700506s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700507{
508 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
509 u32 eec;
510 u16 eeprom_size;
511
512 if (eeprom->type == ixgbe_eeprom_uninitialized) {
513 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700514 /* Set default semaphore delay to 10ms which is a well
515 * tested value */
516 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700517
518 /*
519 * Check for EEPROM present first.
520 * If not present leave as none
521 */
522 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
523 if (eec & IXGBE_EEC_PRES) {
524 eeprom->type = ixgbe_eeprom_spi;
525
526 /*
527 * SPI EEPROM is assumed here. This code would need to
528 * change if a future EEPROM is not SPI.
529 */
530 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
531 IXGBE_EEC_SIZE_SHIFT);
532 eeprom->word_size = 1 << (eeprom_size +
533 IXGBE_EEPROM_WORD_SIZE_SHIFT);
534 }
535
536 if (eec & IXGBE_EEC_ADDR_SIZE)
537 eeprom->address_bits = 16;
538 else
539 eeprom->address_bits = 8;
540 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
541 "%d\n", eeprom->type, eeprom->word_size,
542 eeprom->address_bits);
543 }
544
545 return 0;
546}
547
548/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000549 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
550 * @hw: pointer to hardware structure
551 * @offset: offset within the EEPROM to be written to
552 * @data: 16 bit word to be written to the EEPROM
553 *
554 * If ixgbe_eeprom_update_checksum is not called after this function, the
555 * EEPROM will most likely contain an invalid checksum.
556 **/
557s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
558{
559 s32 status;
560 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
561
562 hw->eeprom.ops.init_params(hw);
563
564 if (offset >= hw->eeprom.word_size) {
565 status = IXGBE_ERR_EEPROM;
566 goto out;
567 }
568
569 /* Prepare the EEPROM for writing */
570 status = ixgbe_acquire_eeprom(hw);
571
572 if (status == 0) {
573 if (ixgbe_ready_eeprom(hw) != 0) {
574 ixgbe_release_eeprom(hw);
575 status = IXGBE_ERR_EEPROM;
576 }
577 }
578
579 if (status == 0) {
580 ixgbe_standby_eeprom(hw);
581
582 /* Send the WRITE ENABLE command (8 bit opcode ) */
583 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
584 IXGBE_EEPROM_OPCODE_BITS);
585
586 ixgbe_standby_eeprom(hw);
587
588 /*
589 * Some SPI eeproms use the 8th address bit embedded in the
590 * opcode
591 */
592 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
593 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
594
595 /* Send the Write command (8-bit opcode + addr) */
596 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
597 IXGBE_EEPROM_OPCODE_BITS);
598 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
599 hw->eeprom.address_bits);
600
601 /* Send the data */
602 data = (data >> 8) | (data << 8);
603 ixgbe_shift_out_eeprom_bits(hw, data, 16);
604 ixgbe_standby_eeprom(hw);
605
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000606 /* Done with writing - release the EEPROM */
607 ixgbe_release_eeprom(hw);
608 }
609
610out:
611 return status;
612}
613
614/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700615 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
616 * @hw: pointer to hardware structure
617 * @offset: offset within the EEPROM to be read
618 * @data: read 16 bit value from EEPROM
619 *
620 * Reads 16 bit value from EEPROM through bit-bang method
621 **/
622s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
623 u16 *data)
624{
625 s32 status;
626 u16 word_in;
627 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
628
629 hw->eeprom.ops.init_params(hw);
630
631 if (offset >= hw->eeprom.word_size) {
632 status = IXGBE_ERR_EEPROM;
633 goto out;
634 }
635
636 /* Prepare the EEPROM for reading */
637 status = ixgbe_acquire_eeprom(hw);
638
639 if (status == 0) {
640 if (ixgbe_ready_eeprom(hw) != 0) {
641 ixgbe_release_eeprom(hw);
642 status = IXGBE_ERR_EEPROM;
643 }
644 }
645
646 if (status == 0) {
647 ixgbe_standby_eeprom(hw);
648
649 /*
650 * Some SPI eeproms use the 8th address bit embedded in the
651 * opcode
652 */
653 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
654 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
655
656 /* Send the READ command (opcode + addr) */
657 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
658 IXGBE_EEPROM_OPCODE_BITS);
659 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
660 hw->eeprom.address_bits);
661
662 /* Read the data. */
663 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
664 *data = (word_in >> 8) | (word_in << 8);
665
666 /* End this read operation */
667 ixgbe_release_eeprom(hw);
668 }
669
670out:
671 return status;
672}
673
674/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000675 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700676 * @hw: pointer to hardware structure
677 * @offset: offset of word in the EEPROM to read
678 * @data: word read from the EEPROM
679 *
680 * Reads a 16 bit word from the EEPROM using the EERD register.
681 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000682s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700683{
684 u32 eerd;
685 s32 status;
686
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700687 hw->eeprom.ops.init_params(hw);
688
689 if (offset >= hw->eeprom.word_size) {
690 status = IXGBE_ERR_EEPROM;
691 goto out;
692 }
693
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000694 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
695 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700696
697 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000698 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700699
700 if (status == 0)
701 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000702 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700703 else
704 hw_dbg(hw, "Eeprom read timed out\n");
705
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700706out:
Auke Kok9a799d72007-09-15 14:07:45 -0700707 return status;
708}
709
710/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000711 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700712 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000713 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700714 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000715 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
716 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700717 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800718s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700719{
720 u32 i;
721 u32 reg;
722 s32 status = IXGBE_ERR_EEPROM;
723
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000724 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
725 if (ee_reg == IXGBE_NVM_POLL_READ)
726 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
727 else
728 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
729
730 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700731 status = 0;
732 break;
733 }
734 udelay(5);
735 }
736 return status;
737}
738
739/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700740 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
741 * @hw: pointer to hardware structure
742 *
743 * Prepares EEPROM for access using bit-bang method. This function should
744 * be called before issuing a command to the EEPROM.
745 **/
746static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
747{
748 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000749 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700750 u32 i;
751
752 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
753 status = IXGBE_ERR_SWFW_SYNC;
754
755 if (status == 0) {
756 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
757
758 /* Request EEPROM Access */
759 eec |= IXGBE_EEC_REQ;
760 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
761
762 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
763 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
764 if (eec & IXGBE_EEC_GNT)
765 break;
766 udelay(5);
767 }
768
769 /* Release if grant not acquired */
770 if (!(eec & IXGBE_EEC_GNT)) {
771 eec &= ~IXGBE_EEC_REQ;
772 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
773 hw_dbg(hw, "Could not acquire EEPROM grant\n");
774
775 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
776 status = IXGBE_ERR_EEPROM;
777 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700778
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000779 /* Setup EEPROM for Read/Write */
780 if (status == 0) {
781 /* Clear CS and SK */
782 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
783 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
784 IXGBE_WRITE_FLUSH(hw);
785 udelay(1);
786 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700787 }
788 return status;
789}
790
791/**
Auke Kok9a799d72007-09-15 14:07:45 -0700792 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
793 * @hw: pointer to hardware structure
794 *
795 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
796 **/
797static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
798{
799 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000800 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700801 u32 i;
802 u32 swsm;
803
Auke Kok9a799d72007-09-15 14:07:45 -0700804 /* Get SMBI software semaphore between device drivers first */
805 for (i = 0; i < timeout; i++) {
806 /*
807 * If the SMBI bit is 0 when we read it, then the bit will be
808 * set and we have the semaphore
809 */
810 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
811 if (!(swsm & IXGBE_SWSM_SMBI)) {
812 status = 0;
813 break;
814 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000815 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700816 }
817
818 /* Now get the semaphore between SW/FW through the SWESMBI bit */
819 if (status == 0) {
820 for (i = 0; i < timeout; i++) {
821 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
822
823 /* Set the SW EEPROM semaphore bit to request access */
824 swsm |= IXGBE_SWSM_SWESMBI;
825 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
826
827 /*
828 * If we set the bit successfully then we got the
829 * semaphore.
830 */
831 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
832 if (swsm & IXGBE_SWSM_SWESMBI)
833 break;
834
835 udelay(50);
836 }
837
838 /*
839 * Release semaphores and return error if SW EEPROM semaphore
840 * was not granted because we don't have access to the EEPROM
841 */
842 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000843 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700844 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700845 ixgbe_release_eeprom_semaphore(hw);
846 status = IXGBE_ERR_EEPROM;
847 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000848 } else {
849 hw_dbg(hw, "Software semaphore SMBI between device drivers "
850 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700851 }
852
853 return status;
854}
855
856/**
857 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
858 * @hw: pointer to hardware structure
859 *
860 * This function clears hardware semaphore bits.
861 **/
862static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
863{
864 u32 swsm;
865
866 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
867
868 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
869 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
870 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700871 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700872}
873
874/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700875 * ixgbe_ready_eeprom - Polls for EEPROM ready
876 * @hw: pointer to hardware structure
877 **/
878static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
879{
880 s32 status = 0;
881 u16 i;
882 u8 spi_stat_reg;
883
884 /*
885 * Read "Status Register" repeatedly until the LSB is cleared. The
886 * EEPROM will signal that the command has been completed by clearing
887 * bit 0 of the internal status register. If it's not cleared within
888 * 5 milliseconds, then error out.
889 */
890 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
891 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
892 IXGBE_EEPROM_OPCODE_BITS);
893 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
894 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
895 break;
896
897 udelay(5);
898 ixgbe_standby_eeprom(hw);
899 };
900
901 /*
902 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
903 * devices (and only 0-5mSec on 5V devices)
904 */
905 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
906 hw_dbg(hw, "SPI EEPROM Status error\n");
907 status = IXGBE_ERR_EEPROM;
908 }
909
910 return status;
911}
912
913/**
914 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
915 * @hw: pointer to hardware structure
916 **/
917static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
918{
919 u32 eec;
920
921 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
922
923 /* Toggle CS to flush commands */
924 eec |= IXGBE_EEC_CS;
925 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
926 IXGBE_WRITE_FLUSH(hw);
927 udelay(1);
928 eec &= ~IXGBE_EEC_CS;
929 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
930 IXGBE_WRITE_FLUSH(hw);
931 udelay(1);
932}
933
934/**
935 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
936 * @hw: pointer to hardware structure
937 * @data: data to send to the EEPROM
938 * @count: number of bits to shift out
939 **/
940static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
941 u16 count)
942{
943 u32 eec;
944 u32 mask;
945 u32 i;
946
947 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
948
949 /*
950 * Mask is used to shift "count" bits of "data" out to the EEPROM
951 * one bit at a time. Determine the starting bit based on count
952 */
953 mask = 0x01 << (count - 1);
954
955 for (i = 0; i < count; i++) {
956 /*
957 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
958 * "1", and then raising and then lowering the clock (the SK
959 * bit controls the clock input to the EEPROM). A "0" is
960 * shifted out to the EEPROM by setting "DI" to "0" and then
961 * raising and then lowering the clock.
962 */
963 if (data & mask)
964 eec |= IXGBE_EEC_DI;
965 else
966 eec &= ~IXGBE_EEC_DI;
967
968 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
969 IXGBE_WRITE_FLUSH(hw);
970
971 udelay(1);
972
973 ixgbe_raise_eeprom_clk(hw, &eec);
974 ixgbe_lower_eeprom_clk(hw, &eec);
975
976 /*
977 * Shift mask to signify next bit of data to shift in to the
978 * EEPROM
979 */
980 mask = mask >> 1;
981 };
982
983 /* We leave the "DI" bit set to "0" when we leave this routine. */
984 eec &= ~IXGBE_EEC_DI;
985 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
986 IXGBE_WRITE_FLUSH(hw);
987}
988
989/**
990 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
991 * @hw: pointer to hardware structure
992 **/
993static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
994{
995 u32 eec;
996 u32 i;
997 u16 data = 0;
998
999 /*
1000 * In order to read a register from the EEPROM, we need to shift
1001 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1002 * the clock input to the EEPROM (setting the SK bit), and then reading
1003 * the value of the "DO" bit. During this "shifting in" process the
1004 * "DI" bit should always be clear.
1005 */
1006 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1007
1008 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1009
1010 for (i = 0; i < count; i++) {
1011 data = data << 1;
1012 ixgbe_raise_eeprom_clk(hw, &eec);
1013
1014 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1015
1016 eec &= ~(IXGBE_EEC_DI);
1017 if (eec & IXGBE_EEC_DO)
1018 data |= 1;
1019
1020 ixgbe_lower_eeprom_clk(hw, &eec);
1021 }
1022
1023 return data;
1024}
1025
1026/**
1027 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1028 * @hw: pointer to hardware structure
1029 * @eec: EEC register's current value
1030 **/
1031static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1032{
1033 /*
1034 * Raise the clock input to the EEPROM
1035 * (setting the SK bit), then delay
1036 */
1037 *eec = *eec | IXGBE_EEC_SK;
1038 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1039 IXGBE_WRITE_FLUSH(hw);
1040 udelay(1);
1041}
1042
1043/**
1044 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1045 * @hw: pointer to hardware structure
1046 * @eecd: EECD's current value
1047 **/
1048static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1049{
1050 /*
1051 * Lower the clock input to the EEPROM (clearing the SK bit), then
1052 * delay
1053 */
1054 *eec = *eec & ~IXGBE_EEC_SK;
1055 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1056 IXGBE_WRITE_FLUSH(hw);
1057 udelay(1);
1058}
1059
1060/**
1061 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1062 * @hw: pointer to hardware structure
1063 **/
1064static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1065{
1066 u32 eec;
1067
1068 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1069
1070 eec |= IXGBE_EEC_CS; /* Pull CS high */
1071 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1072
1073 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1074 IXGBE_WRITE_FLUSH(hw);
1075
1076 udelay(1);
1077
1078 /* Stop requesting EEPROM access */
1079 eec &= ~IXGBE_EEC_REQ;
1080 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1081
1082 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001083
1084 /* Delay before attempt to obtain semaphore again to allow FW access */
1085 msleep(hw->eeprom.semaphore_delay);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001086}
1087
1088/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001089 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001090 * @hw: pointer to hardware structure
1091 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001092u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001093{
1094 u16 i;
1095 u16 j;
1096 u16 checksum = 0;
1097 u16 length = 0;
1098 u16 pointer = 0;
1099 u16 word = 0;
1100
1101 /* Include 0x0-0x3F in the checksum */
1102 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001103 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001104 hw_dbg(hw, "EEPROM read failed\n");
1105 break;
1106 }
1107 checksum += word;
1108 }
1109
1110 /* Include all data from pointers except for the fw pointer */
1111 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001112 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001113
1114 /* Make sure the pointer seems valid */
1115 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001116 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001117
1118 if (length != 0xFFFF && length != 0) {
1119 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001120 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001121 checksum += word;
1122 }
1123 }
1124 }
1125 }
1126
1127 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1128
1129 return checksum;
1130}
1131
1132/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001133 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001134 * @hw: pointer to hardware structure
1135 * @checksum_val: calculated checksum
1136 *
1137 * Performs checksum calculation and validates the EEPROM checksum. If the
1138 * caller does not need checksum_val, the value can be NULL.
1139 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001140s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1141 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001142{
1143 s32 status;
1144 u16 checksum;
1145 u16 read_checksum = 0;
1146
1147 /*
1148 * Read the first word from the EEPROM. If this times out or fails, do
1149 * not continue or we could be in for a very long wait while every
1150 * EEPROM read fails
1151 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001152 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001153
1154 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001155 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001156
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001157 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001158
1159 /*
1160 * Verify read checksum from EEPROM is the same as
1161 * calculated checksum
1162 */
1163 if (read_checksum != checksum)
1164 status = IXGBE_ERR_EEPROM_CHECKSUM;
1165
1166 /* If the user cares, return the calculated checksum */
1167 if (checksum_val)
1168 *checksum_val = checksum;
1169 } else {
1170 hw_dbg(hw, "EEPROM read failed\n");
1171 }
1172
1173 return status;
1174}
1175
1176/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001177 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1178 * @hw: pointer to hardware structure
1179 **/
1180s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1181{
1182 s32 status;
1183 u16 checksum;
1184
1185 /*
1186 * Read the first word from the EEPROM. If this times out or fails, do
1187 * not continue or we could be in for a very long wait while every
1188 * EEPROM read fails
1189 */
1190 status = hw->eeprom.ops.read(hw, 0, &checksum);
1191
1192 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001193 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001194 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1195 checksum);
1196 } else {
1197 hw_dbg(hw, "EEPROM read failed\n");
1198 }
1199
1200 return status;
1201}
1202
1203/**
Auke Kok9a799d72007-09-15 14:07:45 -07001204 * ixgbe_validate_mac_addr - Validate MAC address
1205 * @mac_addr: pointer to MAC address.
1206 *
1207 * Tests a MAC address to ensure it is a valid Individual Address
1208 **/
1209s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1210{
1211 s32 status = 0;
1212
1213 /* Make sure it is not a multicast address */
1214 if (IXGBE_IS_MULTICAST(mac_addr))
1215 status = IXGBE_ERR_INVALID_MAC_ADDR;
1216 /* Not a broadcast address */
1217 else if (IXGBE_IS_BROADCAST(mac_addr))
1218 status = IXGBE_ERR_INVALID_MAC_ADDR;
1219 /* Reject the zero address */
1220 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001221 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001222 status = IXGBE_ERR_INVALID_MAC_ADDR;
1223
1224 return status;
1225}
1226
1227/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001228 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001229 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001230 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001231 * @addr: Address to put into receive address register
1232 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001233 * @enable_addr: set flag that address is active
1234 *
1235 * Puts an ethernet address into a receive address register.
1236 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001237s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1238 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001239{
1240 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001241 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001242
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001243 /* setup VMDq pool selection before this RAR gets enabled */
1244 hw->mac.ops.set_vmdq(hw, index, vmdq);
1245
1246 /* Make sure we are using a valid rar index range */
1247 if (index < rar_entries) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001248 /*
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001249 * HW expects these in little endian so we reverse the byte
1250 * order from network order (big endian) to little endian
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001251 */
1252 rar_low = ((u32)addr[0] |
1253 ((u32)addr[1] << 8) |
1254 ((u32)addr[2] << 16) |
1255 ((u32)addr[3] << 24));
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001256 /*
1257 * Some parts put the VMDq setting in the extra RAH bits,
1258 * so save everything except the lower 16 bits that hold part
1259 * of the address and the address valid bit.
1260 */
1261 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1262 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1263 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001264
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001265 if (enable_addr != 0)
1266 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001267
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001268 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1269 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001270 } else {
1271 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Jeff Kirshera1868dc2010-06-02 12:44:05 +00001272 return IXGBE_ERR_RAR_INDEX;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001273 }
Auke Kok9a799d72007-09-15 14:07:45 -07001274
1275 return 0;
1276}
1277
1278/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001279 * ixgbe_clear_rar_generic - Remove Rx address register
1280 * @hw: pointer to hardware structure
1281 * @index: Receive address register to write
1282 *
1283 * Clears an ethernet address from a receive address register.
1284 **/
1285s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1286{
1287 u32 rar_high;
1288 u32 rar_entries = hw->mac.num_rar_entries;
1289
1290 /* Make sure we are using a valid rar index range */
1291 if (index < rar_entries) {
1292 /*
1293 * Some parts put the VMDq setting in the extra RAH bits,
1294 * so save everything except the lower 16 bits that hold part
1295 * of the address and the address valid bit.
1296 */
1297 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1298 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1299
1300 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1301 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1302 } else {
1303 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Jeff Kirshera1868dc2010-06-02 12:44:05 +00001304 return IXGBE_ERR_RAR_INDEX;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001305 }
1306
1307 /* clear VMDq pool/queue selection for this RAR */
1308 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1309
1310 return 0;
1311}
1312
1313/**
1314 * ixgbe_enable_rar - Enable Rx address register
1315 * @hw: pointer to hardware structure
1316 * @index: index into the RAR table
1317 *
1318 * Enables the select receive address register.
1319 **/
1320static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
1321{
1322 u32 rar_high;
1323
1324 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1325 rar_high |= IXGBE_RAH_AV;
1326 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1327}
1328
1329/**
1330 * ixgbe_disable_rar - Disable Rx address register
1331 * @hw: pointer to hardware structure
1332 * @index: index into the RAR table
1333 *
1334 * Disables the select receive address register.
1335 **/
1336static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
1337{
1338 u32 rar_high;
1339
1340 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1341 rar_high &= (~IXGBE_RAH_AV);
1342 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1343}
1344
1345/**
1346 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001347 * @hw: pointer to hardware structure
1348 *
1349 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001350 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001351 * the receiver is in reset when the routine is called.
1352 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001353s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001354{
1355 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001356 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001357
1358 /*
1359 * If the current mac address is valid, assume it is a software override
1360 * to the permanent address.
1361 * Otherwise, use the permanent address from the eeprom.
1362 */
1363 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1364 IXGBE_ERR_INVALID_MAC_ADDR) {
1365 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001366 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001367
hartleysce7194d2010-01-05 06:56:52 +00001368 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001369 } else {
1370 /* Setup the receive address. */
1371 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001372 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001373
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001374 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001375
1376 /* clear VMDq pool/queue selection for RAR 0 */
1377 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001378 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001379 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001380
1381 hw->addr_ctrl.rar_used_count = 1;
1382
1383 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001384 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001385 for (i = 1; i < rar_entries; i++) {
1386 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1387 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1388 }
1389
1390 /* Clear the MTA */
1391 hw->addr_ctrl.mc_addr_in_rar_count = 0;
1392 hw->addr_ctrl.mta_in_use = 0;
1393 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1394
1395 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001396 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001397 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1398
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001399 if (hw->mac.ops.init_uta_tables)
1400 hw->mac.ops.init_uta_tables(hw);
1401
Auke Kok9a799d72007-09-15 14:07:45 -07001402 return 0;
1403}
1404
1405/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001406 * ixgbe_add_uc_addr - Adds a secondary unicast address.
1407 * @hw: pointer to hardware structure
1408 * @addr: new address
1409 *
1410 * Adds it to unused receive address register or goes into promiscuous mode.
1411 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001412static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001413{
1414 u32 rar_entries = hw->mac.num_rar_entries;
1415 u32 rar;
1416
1417 hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1418 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1419
1420 /*
1421 * Place this address in the RAR if there is room,
1422 * else put the controller into promiscuous mode
1423 */
1424 if (hw->addr_ctrl.rar_used_count < rar_entries) {
1425 rar = hw->addr_ctrl.rar_used_count -
1426 hw->addr_ctrl.mc_addr_in_rar_count;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001427 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001428 hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
1429 hw->addr_ctrl.rar_used_count++;
1430 } else {
1431 hw->addr_ctrl.overflow_promisc++;
1432 }
1433
1434 hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
1435}
1436
1437/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001438 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001439 * @hw: pointer to hardware structure
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001440 * @netdev: pointer to net device structure
Christopher Leech2c5645c2008-08-26 04:27:02 -07001441 *
1442 * The given list replaces any existing list. Clears the secondary addrs from
1443 * receive address registers. Uses unused receive address registers for the
1444 * first secondary addresses, and falls back to promiscuous mode as needed.
1445 *
1446 * Drivers using secondary unicast addresses must set user_set_promisc when
1447 * manually putting the device into promiscuous mode.
1448 **/
Jiri Pirkoccffad252009-05-22 23:22:17 +00001449s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001450 struct net_device *netdev)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001451{
Christopher Leech2c5645c2008-08-26 04:27:02 -07001452 u32 i;
1453 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
1454 u32 uc_addr_in_use;
1455 u32 fctrl;
Jiri Pirkoccffad252009-05-22 23:22:17 +00001456 struct netdev_hw_addr *ha;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001457
1458 /*
1459 * Clear accounting of old secondary address list,
1460 * don't count RAR[0]
1461 */
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00001462 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001463 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
1464 hw->addr_ctrl.overflow_promisc = 0;
1465
1466 /* Zero out the other receive addresses */
Shannon Nelson91152c32009-11-24 18:52:10 +00001467 hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use + 1);
1468 for (i = 0; i < uc_addr_in_use; i++) {
1469 IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
1470 IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001471 }
1472
1473 /* Add the new addresses */
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001474 netdev_for_each_uc_addr(ha, netdev) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001475 hw_dbg(hw, " Adding the secondary addresses:\n");
Jiri Pirkoccffad252009-05-22 23:22:17 +00001476 ixgbe_add_uc_addr(hw, ha->addr, 0);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001477 }
1478
1479 if (hw->addr_ctrl.overflow_promisc) {
1480 /* enable promisc if not already in overflow or set by user */
1481 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1482 hw_dbg(hw, " Entering address overflow promisc mode\n");
1483 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1484 fctrl |= IXGBE_FCTRL_UPE;
1485 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Emil Tantilove433ea12010-05-13 17:33:00 +00001486 hw->addr_ctrl.uc_set_promisc = true;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001487 }
1488 } else {
1489 /* only disable if set by overflow, not by user */
Emil Tantilove433ea12010-05-13 17:33:00 +00001490 if ((old_promisc_setting && hw->addr_ctrl.uc_set_promisc) &&
1491 !(hw->addr_ctrl.user_set_promisc)) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001492 hw_dbg(hw, " Leaving address overflow promisc mode\n");
1493 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1494 fctrl &= ~IXGBE_FCTRL_UPE;
1495 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Emil Tantilove433ea12010-05-13 17:33:00 +00001496 hw->addr_ctrl.uc_set_promisc = false;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001497 }
1498 }
1499
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001500 hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001501 return 0;
1502}
1503
1504/**
Auke Kok9a799d72007-09-15 14:07:45 -07001505 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1506 * @hw: pointer to hardware structure
1507 * @mc_addr: the multicast address
1508 *
1509 * Extracts the 12 bits, from a multicast address, to determine which
1510 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1511 * incoming rx multicast addresses, to determine the bit-vector to check in
1512 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001513 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001514 * to mc_filter_type.
1515 **/
1516static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1517{
1518 u32 vector = 0;
1519
1520 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001521 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001522 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1523 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001524 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001525 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1526 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001527 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001528 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1529 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001530 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001531 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1532 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001533 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001534 hw_dbg(hw, "MC filter type param set incorrectly\n");
1535 break;
1536 }
1537
1538 /* vector can only be 12-bits or boundary will be exceeded */
1539 vector &= 0xFFF;
1540 return vector;
1541}
1542
1543/**
1544 * ixgbe_set_mta - Set bit-vector in multicast table
1545 * @hw: pointer to hardware structure
1546 * @hash_value: Multicast address hash value
1547 *
1548 * Sets the bit-vector in the multicast table.
1549 **/
1550static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1551{
1552 u32 vector;
1553 u32 vector_bit;
1554 u32 vector_reg;
1555 u32 mta_reg;
1556
1557 hw->addr_ctrl.mta_in_use++;
1558
1559 vector = ixgbe_mta_vector(hw, mc_addr);
1560 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1561
1562 /*
1563 * The MTA is a register array of 128 32-bit registers. It is treated
1564 * like an array of 4096 bits. We want to set bit
1565 * BitArray[vector_value]. So we figure out what register the bit is
1566 * in, read it, OR in the new bit, then write back the new value. The
1567 * register is determined by the upper 7 bits of the vector value and
1568 * the bit within that register are determined by the lower 5 bits of
1569 * the value.
1570 */
1571 vector_reg = (vector >> 5) & 0x7F;
1572 vector_bit = vector & 0x1F;
1573 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
1574 mta_reg |= (1 << vector_bit);
1575 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
1576}
1577
1578/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001579 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001580 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001581 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001582 *
1583 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001584 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001585 * registers for the first multicast addresses, and hashes the rest into the
1586 * multicast table.
1587 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001588s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1589 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001590{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001591 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001592 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001593
1594 /*
1595 * Set the new number of MC addresses that we are being requested to
1596 * use.
1597 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001598 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001599 hw->addr_ctrl.mta_in_use = 0;
1600
Auke Kok9a799d72007-09-15 14:07:45 -07001601 /* Clear the MTA */
1602 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001603 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001604 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1605
1606 /* Add the new addresses */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001607 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001608 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad32010-04-01 21:22:57 +00001609 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001610 }
1611
1612 /* Enable mta */
1613 if (hw->addr_ctrl.mta_in_use > 0)
1614 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001615 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001616
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001617 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001618 return 0;
1619}
1620
1621/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001622 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001623 * @hw: pointer to hardware structure
1624 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001625 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001626 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001627s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001628{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001629 u32 i;
1630 u32 rar_entries = hw->mac.num_rar_entries;
1631 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001632
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001633 if (a->mc_addr_in_rar_count > 0)
1634 for (i = (rar_entries - a->mc_addr_in_rar_count);
1635 i < rar_entries; i++)
1636 ixgbe_enable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001637
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001638 if (a->mta_in_use > 0)
1639 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1640 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001641
1642 return 0;
1643}
1644
1645/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001646 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001647 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001648 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001649 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001650 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001651s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001652{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001653 u32 i;
1654 u32 rar_entries = hw->mac.num_rar_entries;
1655 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001656
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001657 if (a->mc_addr_in_rar_count > 0)
1658 for (i = (rar_entries - a->mc_addr_in_rar_count);
1659 i < rar_entries; i++)
1660 ixgbe_disable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001661
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001662 if (a->mta_in_use > 0)
1663 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001664
1665 return 0;
1666}
1667
1668/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001669 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001670 * @hw: pointer to hardware structure
1671 * @packetbuf_num: packet buffer number (0-7)
1672 *
1673 * Enable flow control according to the current settings.
1674 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001675s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001676{
1677 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001678 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001679 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001680 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001681 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001682
1683#ifdef CONFIG_DCB
1684 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1685 goto out;
1686
1687#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001688 /* Negotiate the fc mode to use */
1689 ret_val = ixgbe_fc_autoneg(hw);
1690 if (ret_val)
1691 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001692
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001693 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001694 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1695 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1696
1697 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1698 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1699
1700 /*
1701 * The possible values of fc.current_mode are:
1702 * 0: Flow control is completely disabled
1703 * 1: Rx flow control is enabled (we can receive pause frames,
1704 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001705 * 2: Tx flow control is enabled (we can send pause frames but
1706 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001707 * 3: Both Rx and Tx flow control (symmetric) are enabled.
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001708 * 4: Priority Flow Control is enabled.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001709 * other: Invalid.
1710 */
1711 switch (hw->fc.current_mode) {
1712 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001713 /*
1714 * Flow control is disabled by software override or autoneg.
1715 * The code below will actually disable it in the HW.
1716 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001717 break;
1718 case ixgbe_fc_rx_pause:
1719 /*
1720 * Rx Flow control is enabled and Tx Flow control is
1721 * disabled by software override. Since there really
1722 * isn't a way to advertise that we are capable of RX
1723 * Pause ONLY, we will advertise that we support both
1724 * symmetric and asymmetric Rx PAUSE. Later, we will
1725 * disable the adapter's ability to send PAUSE frames.
1726 */
1727 mflcn_reg |= IXGBE_MFLCN_RFCE;
1728 break;
1729 case ixgbe_fc_tx_pause:
1730 /*
1731 * Tx Flow control is enabled, and Rx Flow control is
1732 * disabled by software override.
1733 */
1734 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1735 break;
1736 case ixgbe_fc_full:
1737 /* Flow control (both Rx and Tx) is enabled by SW override. */
1738 mflcn_reg |= IXGBE_MFLCN_RFCE;
1739 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1740 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001741#ifdef CONFIG_DCB
1742 case ixgbe_fc_pfc:
1743 goto out;
1744 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001745#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001746 default:
1747 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001748 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001749 goto out;
1750 break;
1751 }
1752
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001753 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001754 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001755 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1756 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1757
John Fastabend16b61be2010-11-16 19:26:44 -08001758 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1759 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001760
John Fastabend16b61be2010-11-16 19:26:44 -08001761 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1762 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001763
John Fastabend16b61be2010-11-16 19:26:44 -08001764 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1765 fcrth |= IXGBE_FCRTH_FCEN;
1766 if (hw->fc.send_xon)
1767 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001768 }
1769
John Fastabend16b61be2010-11-16 19:26:44 -08001770 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1771 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1772
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001773 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001774 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001775 if ((packetbuf_num & 1) == 0)
1776 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1777 else
1778 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1779 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1780
1781 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1782
1783out:
1784 return ret_val;
1785}
1786
1787/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001788 * ixgbe_fc_autoneg - Configure flow control
1789 * @hw: pointer to hardware structure
1790 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001791 * Compares our advertised flow control capabilities to those advertised by
1792 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001793 **/
1794s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1795{
1796 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001797 ixgbe_link_speed speed;
1798 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001799 u32 links2, anlp1_reg, autoc_reg, links;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001800 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001801
1802 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001803 * AN should have completed when the cable was plugged in.
1804 * Look for reasons to bail out. Bail out if:
1805 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001806 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001807 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001808 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001809 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001810 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001811 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001812
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001813 if (hw->fc.disable_fc_autoneg || (!link_up)) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001814 hw->fc.fc_was_autonegged = false;
1815 hw->fc.current_mode = hw->fc.requested_mode;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001816 goto out;
1817 }
1818
1819 /*
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001820 * On backplane, bail out if
1821 * - backplane autoneg was not completed, or if
Don Skidmore000c4862009-11-24 18:51:48 +00001822 * - we are 82599 and link partner is not AN enabled
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001823 */
1824 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1825 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Don Skidmore000c4862009-11-24 18:51:48 +00001826 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001827 hw->fc.fc_was_autonegged = false;
1828 hw->fc.current_mode = hw->fc.requested_mode;
1829 goto out;
1830 }
Don Skidmore000c4862009-11-24 18:51:48 +00001831
1832 if (hw->mac.type == ixgbe_mac_82599EB) {
1833 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1834 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1835 hw->fc.fc_was_autonegged = false;
1836 hw->fc.current_mode = hw->fc.requested_mode;
1837 goto out;
1838 }
1839 }
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001840 }
1841
1842 /*
1843 * On multispeed fiber at 1g, bail out if
1844 * - link is up but AN did not complete, or if
1845 * - link is up and AN completed but timed out
1846 */
1847 if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
1848 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1849 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1850 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1851 hw->fc.fc_was_autonegged = false;
1852 hw->fc.current_mode = hw->fc.requested_mode;
1853 goto out;
1854 }
1855 }
1856
1857 /*
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00001858 * Bail out on
1859 * - copper or CX4 adapters
1860 * - fiber adapters running at 10gig
1861 */
1862 if ((hw->phy.media_type == ixgbe_media_type_copper) ||
1863 (hw->phy.media_type == ixgbe_media_type_cx4) ||
1864 ((hw->phy.media_type == ixgbe_media_type_fiber) &&
1865 (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
1866 hw->fc.fc_was_autonegged = false;
1867 hw->fc.current_mode = hw->fc.requested_mode;
1868 goto out;
1869 }
1870
1871 /*
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001872 * Read the AN advertisement and LP ability registers and resolve
1873 * local flow control settings accordingly
1874 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001875 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
1876 (hw->phy.media_type != ixgbe_media_type_backplane)) {
1877 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1878 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1879 if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1880 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1881 /*
1882 * Now we need to check if the user selected Rx ONLY
1883 * of pause frames. In this case, we had to advertise
1884 * FULL flow control because we could not advertise RX
1885 * ONLY. Hence, we must now check to see if we need to
1886 * turn OFF the TRANSMISSION of PAUSE frames.
1887 */
1888 if (hw->fc.requested_mode == ixgbe_fc_full) {
1889 hw->fc.current_mode = ixgbe_fc_full;
1890 hw_dbg(hw, "Flow Control = FULL.\n");
1891 } else {
1892 hw->fc.current_mode = ixgbe_fc_rx_pause;
1893 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1894 }
1895 } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1896 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1897 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1898 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1899 hw->fc.current_mode = ixgbe_fc_tx_pause;
1900 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1901 } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1902 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1903 !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1904 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001905 hw->fc.current_mode = ixgbe_fc_rx_pause;
1906 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001907 } else {
1908 hw->fc.current_mode = ixgbe_fc_none;
1909 hw_dbg(hw, "Flow Control = NONE.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001910 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001911 }
1912
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001913 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1914 /*
1915 * Read the 10g AN autoc and LP ability registers and resolve
1916 * local flow control settings accordingly
1917 */
1918 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1919 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1920
1921 if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1922 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
1923 /*
1924 * Now we need to check if the user selected Rx ONLY
1925 * of pause frames. In this case, we had to advertise
1926 * FULL flow control because we could not advertise RX
1927 * ONLY. Hence, we must now check to see if we need to
1928 * turn OFF the TRANSMISSION of PAUSE frames.
1929 */
1930 if (hw->fc.requested_mode == ixgbe_fc_full) {
1931 hw->fc.current_mode = ixgbe_fc_full;
1932 hw_dbg(hw, "Flow Control = FULL.\n");
1933 } else {
1934 hw->fc.current_mode = ixgbe_fc_rx_pause;
1935 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1936 }
1937 } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1938 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1939 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1940 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1941 hw->fc.current_mode = ixgbe_fc_tx_pause;
1942 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1943 } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1944 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1945 !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1946 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1947 hw->fc.current_mode = ixgbe_fc_rx_pause;
1948 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1949 } else {
1950 hw->fc.current_mode = ixgbe_fc_none;
1951 hw_dbg(hw, "Flow Control = NONE.\n");
1952 }
1953 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001954 /* Record that current_mode is the result of a successful autoneg */
1955 hw->fc.fc_was_autonegged = true;
1956
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001957out:
1958 return ret_val;
1959}
1960
1961/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001962 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001963 * @hw: pointer to hardware structure
1964 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001965 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001966 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001967static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001968{
1969 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001970 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001971
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001972#ifdef CONFIG_DCB
1973 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1974 hw->fc.current_mode = hw->fc.requested_mode;
1975 goto out;
1976 }
1977
1978#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001979 /* Validate the packetbuf configuration */
1980 if (packetbuf_num < 0 || packetbuf_num > 7) {
1981 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1982 "is 0-7\n", packetbuf_num);
1983 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1984 goto out;
1985 }
1986
1987 /*
1988 * Validate the water mark configuration. Zero water marks are invalid
1989 * because it causes the controller to just blast out fc packets.
1990 */
1991 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001992 hw_dbg(hw, "Invalid water mark configuration\n");
1993 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1994 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001995 }
1996
1997 /*
1998 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001999 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002000 */
2001 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2002 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
2003 "IEEE mode\n");
2004 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2005 goto out;
2006 }
2007
2008 /*
2009 * 10gig parts do not have a word in the EEPROM to determine the
2010 * default flow control setting, so we explicitly set it to full.
2011 */
2012 if (hw->fc.requested_mode == ixgbe_fc_default)
2013 hw->fc.requested_mode = ixgbe_fc_full;
2014
2015 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002016 * Set up the 1G flow control advertisement registers so the HW will be
2017 * able to do fc autoneg once the cable is plugged in. If we end up
2018 * using 10g instead, this is harmless.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002019 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002020 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002021
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002022 /*
2023 * The possible values of fc.requested_mode are:
2024 * 0: Flow control is completely disabled
2025 * 1: Rx flow control is enabled (we can receive pause frames,
2026 * but not send pause frames).
2027 * 2: Tx flow control is enabled (we can send pause frames but
2028 * we do not support receiving pause frames).
2029 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2030#ifdef CONFIG_DCB
2031 * 4: Priority Flow Control is enabled.
2032#endif
2033 * other: Invalid.
2034 */
2035 switch (hw->fc.requested_mode) {
2036 case ixgbe_fc_none:
2037 /* Flow control completely disabled by software override. */
2038 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2039 break;
2040 case ixgbe_fc_rx_pause:
2041 /*
2042 * Rx Flow control is enabled and Tx Flow control is
2043 * disabled by software override. Since there really
2044 * isn't a way to advertise that we are capable of RX
2045 * Pause ONLY, we will advertise that we support both
2046 * symmetric and asymmetric Rx PAUSE. Later, we will
2047 * disable the adapter's ability to send PAUSE frames.
2048 */
2049 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2050 break;
2051 case ixgbe_fc_tx_pause:
2052 /*
2053 * Tx Flow control is enabled, and Rx Flow control is
2054 * disabled by software override.
2055 */
2056 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2057 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
2058 break;
2059 case ixgbe_fc_full:
2060 /* Flow control (both Rx and Tx) is enabled by SW override. */
2061 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2062 break;
2063#ifdef CONFIG_DCB
2064 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002065 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002066 break;
2067#endif /* CONFIG_DCB */
2068 default:
2069 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002070 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002071 goto out;
2072 break;
2073 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002074
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002075 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2076 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2077
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002078 /* Disable AN timeout */
2079 if (hw->fc.strict_ieee)
2080 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2081
2082 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2083 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002084
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002085 /*
2086 * Set up the 10G flow control advertisement registers so the HW
2087 * can do fc autoneg once the cable is plugged in. If we end up
2088 * using 1g instead, this is harmless.
2089 */
2090 reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2091
2092 /*
2093 * The possible values of fc.requested_mode are:
2094 * 0: Flow control is completely disabled
2095 * 1: Rx flow control is enabled (we can receive pause frames,
2096 * but not send pause frames).
2097 * 2: Tx flow control is enabled (we can send pause frames but
2098 * we do not support receiving pause frames).
2099 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2100 * other: Invalid.
2101 */
2102 switch (hw->fc.requested_mode) {
2103 case ixgbe_fc_none:
2104 /* Flow control completely disabled by software override. */
2105 reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2106 break;
2107 case ixgbe_fc_rx_pause:
2108 /*
2109 * Rx Flow control is enabled and Tx Flow control is
2110 * disabled by software override. Since there really
2111 * isn't a way to advertise that we are capable of RX
2112 * Pause ONLY, we will advertise that we support both
2113 * symmetric and asymmetric Rx PAUSE. Later, we will
2114 * disable the adapter's ability to send PAUSE frames.
2115 */
2116 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2117 break;
2118 case ixgbe_fc_tx_pause:
2119 /*
2120 * Tx Flow control is enabled, and Rx Flow control is
2121 * disabled by software override.
2122 */
2123 reg |= (IXGBE_AUTOC_ASM_PAUSE);
2124 reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
2125 break;
2126 case ixgbe_fc_full:
2127 /* Flow control (both Rx and Tx) is enabled by SW override. */
2128 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2129 break;
2130#ifdef CONFIG_DCB
2131 case ixgbe_fc_pfc:
2132 goto out;
2133 break;
2134#endif /* CONFIG_DCB */
2135 default:
2136 hw_dbg(hw, "Flow control param set incorrectly\n");
2137 ret_val = IXGBE_ERR_CONFIG;
2138 goto out;
2139 break;
2140 }
2141 /*
2142 * AUTOC restart handles negotiation of 1G and 10G. There is
2143 * no need to set the PCS1GCTL register.
2144 */
2145 reg |= IXGBE_AUTOC_AN_RESTART;
2146 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
2147 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
2148
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002149out:
2150 return ret_val;
2151}
2152
2153/**
Auke Kok9a799d72007-09-15 14:07:45 -07002154 * ixgbe_disable_pcie_master - Disable PCI-express master access
2155 * @hw: pointer to hardware structure
2156 *
2157 * Disables PCI-Express master access and verifies there are no pending
2158 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2159 * bit hasn't caused the master requests to be disabled, else 0
2160 * is returned signifying master requests disabled.
2161 **/
2162s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2163{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002164 u32 i;
2165 u32 reg_val;
2166 u32 number_of_queues;
Auke Kok9a799d72007-09-15 14:07:45 -07002167 s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2168
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002169 /* Disable the receive unit by stopping each queue */
2170 number_of_queues = hw->mac.max_rx_queues;
2171 for (i = 0; i < number_of_queues; i++) {
2172 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2173 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2174 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2175 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2176 }
2177 }
2178
2179 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2180 reg_val |= IXGBE_CTRL_GIO_DIS;
2181 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002182
2183 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2184 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
2185 status = 0;
2186 break;
2187 }
2188 udelay(100);
2189 }
2190
2191 return status;
2192}
2193
2194
2195/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002196 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002197 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002198 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002199 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002200 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002201 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2202 **/
2203s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2204{
2205 u32 gssr;
2206 u32 swmask = mask;
2207 u32 fwmask = mask << 5;
2208 s32 timeout = 200;
2209
2210 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002211 /*
2212 * SW EEPROM semaphore bit is used for access to all
2213 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2214 */
Auke Kok9a799d72007-09-15 14:07:45 -07002215 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002216 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002217
2218 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2219 if (!(gssr & (fwmask | swmask)))
2220 break;
2221
2222 /*
2223 * Firmware currently using resource (fwmask) or other software
2224 * thread currently using resource (swmask)
2225 */
2226 ixgbe_release_eeprom_semaphore(hw);
2227 msleep(5);
2228 timeout--;
2229 }
2230
2231 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002232 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002233 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002234 }
2235
2236 gssr |= swmask;
2237 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2238
2239 ixgbe_release_eeprom_semaphore(hw);
2240 return 0;
2241}
2242
2243/**
2244 * ixgbe_release_swfw_sync - Release SWFW semaphore
2245 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002246 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002247 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002248 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002249 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2250 **/
2251void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2252{
2253 u32 gssr;
2254 u32 swmask = mask;
2255
2256 ixgbe_get_eeprom_semaphore(hw);
2257
2258 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2259 gssr &= ~swmask;
2260 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2261
2262 ixgbe_release_eeprom_semaphore(hw);
2263}
2264
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002265/**
2266 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2267 * @hw: pointer to hardware structure
2268 * @regval: register value to write to RXCTRL
2269 *
2270 * Enables the Rx DMA unit
2271 **/
2272s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2273{
2274 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2275
2276 return 0;
2277}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002278
2279/**
2280 * ixgbe_blink_led_start_generic - Blink LED based on index.
2281 * @hw: pointer to hardware structure
2282 * @index: led number to blink
2283 **/
2284s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2285{
2286 ixgbe_link_speed speed = 0;
2287 bool link_up = 0;
2288 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2289 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2290
2291 /*
2292 * Link must be up to auto-blink the LEDs;
2293 * Force it if link is down.
2294 */
2295 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2296
2297 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002298 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002299 autoc_reg |= IXGBE_AUTOC_FLU;
2300 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2301 msleep(10);
2302 }
2303
2304 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2305 led_reg |= IXGBE_LED_BLINK(index);
2306 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2307 IXGBE_WRITE_FLUSH(hw);
2308
2309 return 0;
2310}
2311
2312/**
2313 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2314 * @hw: pointer to hardware structure
2315 * @index: led number to stop blinking
2316 **/
2317s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2318{
2319 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2320 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2321
2322 autoc_reg &= ~IXGBE_AUTOC_FLU;
2323 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2324 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2325
2326 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2327 led_reg &= ~IXGBE_LED_BLINK(index);
2328 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2329 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2330 IXGBE_WRITE_FLUSH(hw);
2331
2332 return 0;
2333}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002334
2335/**
2336 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2337 * @hw: pointer to hardware structure
2338 * @san_mac_offset: SAN MAC address offset
2339 *
2340 * This function will read the EEPROM location for the SAN MAC address
2341 * pointer, and returns the value at that location. This is used in both
2342 * get and set mac_addr routines.
2343 **/
2344static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2345 u16 *san_mac_offset)
2346{
2347 /*
2348 * First read the EEPROM pointer to see if the MAC addresses are
2349 * available.
2350 */
2351 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2352
2353 return 0;
2354}
2355
2356/**
2357 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2358 * @hw: pointer to hardware structure
2359 * @san_mac_addr: SAN MAC address
2360 *
2361 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2362 * per-port, so set_lan_id() must be called before reading the addresses.
2363 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2364 * upon for non-SFP connections, so we must call it here.
2365 **/
2366s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2367{
2368 u16 san_mac_data, san_mac_offset;
2369 u8 i;
2370
2371 /*
2372 * First read the EEPROM pointer to see if the MAC addresses are
2373 * available. If they're not, no point in calling set_lan_id() here.
2374 */
2375 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2376
2377 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2378 /*
2379 * No addresses available in this EEPROM. It's not an
2380 * error though, so just wipe the local address and return.
2381 */
2382 for (i = 0; i < 6; i++)
2383 san_mac_addr[i] = 0xFF;
2384
2385 goto san_mac_addr_out;
2386 }
2387
2388 /* make sure we know which port we need to program */
2389 hw->mac.ops.set_lan_id(hw);
2390 /* apply the port offset to the address offset */
2391 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2392 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2393 for (i = 0; i < 3; i++) {
2394 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2395 san_mac_addr[i * 2] = (u8)(san_mac_data);
2396 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2397 san_mac_offset++;
2398 }
2399
2400san_mac_addr_out:
2401 return 0;
2402}
2403
2404/**
2405 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2406 * @hw: pointer to hardware structure
2407 *
2408 * Read PCIe configuration space, and get the MSI-X vector count from
2409 * the capabilities table.
2410 **/
2411u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2412{
2413 struct ixgbe_adapter *adapter = hw->back;
2414 u16 msix_count;
2415 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2416 &msix_count);
2417 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2418
2419 /* MSI-X count is zero-based in HW, so increment to give proper value */
2420 msix_count++;
2421
2422 return msix_count;
2423}
2424
2425/**
2426 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2427 * @hw: pointer to hardware struct
2428 * @rar: receive address register index to disassociate
2429 * @vmdq: VMDq pool index to remove from the rar
2430 **/
2431s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2432{
2433 u32 mpsar_lo, mpsar_hi;
2434 u32 rar_entries = hw->mac.num_rar_entries;
2435
2436 if (rar < rar_entries) {
2437 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2438 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2439
2440 if (!mpsar_lo && !mpsar_hi)
2441 goto done;
2442
2443 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2444 if (mpsar_lo) {
2445 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2446 mpsar_lo = 0;
2447 }
2448 if (mpsar_hi) {
2449 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2450 mpsar_hi = 0;
2451 }
2452 } else if (vmdq < 32) {
2453 mpsar_lo &= ~(1 << vmdq);
2454 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2455 } else {
2456 mpsar_hi &= ~(1 << (vmdq - 32));
2457 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2458 }
2459
2460 /* was that the last pool using this rar? */
2461 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2462 hw->mac.ops.clear_rar(hw, rar);
2463 } else {
2464 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
2465 }
2466
2467done:
2468 return 0;
2469}
2470
2471/**
2472 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2473 * @hw: pointer to hardware struct
2474 * @rar: receive address register index to associate with a VMDq index
2475 * @vmdq: VMDq pool index
2476 **/
2477s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2478{
2479 u32 mpsar;
2480 u32 rar_entries = hw->mac.num_rar_entries;
2481
2482 if (rar < rar_entries) {
2483 if (vmdq < 32) {
2484 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2485 mpsar |= 1 << vmdq;
2486 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2487 } else {
2488 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2489 mpsar |= 1 << (vmdq - 32);
2490 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
2491 }
2492 } else {
2493 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
2494 }
2495 return 0;
2496}
2497
2498/**
2499 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2500 * @hw: pointer to hardware structure
2501 **/
2502s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2503{
2504 int i;
2505
2506
2507 for (i = 0; i < 128; i++)
2508 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2509
2510 return 0;
2511}
2512
2513/**
2514 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2515 * @hw: pointer to hardware structure
2516 * @vlan: VLAN id to write to VLAN filter
2517 *
2518 * return the VLVF index where this VLAN id should be placed
2519 *
2520 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002521static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002522{
2523 u32 bits = 0;
2524 u32 first_empty_slot = 0;
2525 s32 regindex;
2526
2527 /* short cut the special case */
2528 if (vlan == 0)
2529 return 0;
2530
2531 /*
2532 * Search for the vlan id in the VLVF entries. Save off the first empty
2533 * slot found along the way
2534 */
2535 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2536 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2537 if (!bits && !(first_empty_slot))
2538 first_empty_slot = regindex;
2539 else if ((bits & 0x0FFF) == vlan)
2540 break;
2541 }
2542
2543 /*
2544 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2545 * in the VLVF. Else use the first empty VLVF register for this
2546 * vlan id.
2547 */
2548 if (regindex >= IXGBE_VLVF_ENTRIES) {
2549 if (first_empty_slot)
2550 regindex = first_empty_slot;
2551 else {
2552 hw_dbg(hw, "No space in VLVF.\n");
2553 regindex = IXGBE_ERR_NO_SPACE;
2554 }
2555 }
2556
2557 return regindex;
2558}
2559
2560/**
2561 * ixgbe_set_vfta_generic - Set VLAN filter table
2562 * @hw: pointer to hardware structure
2563 * @vlan: VLAN id to write to VLAN filter
2564 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2565 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2566 *
2567 * Turn on/off specified VLAN in the VLAN filter table.
2568 **/
2569s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2570 bool vlan_on)
2571{
2572 s32 regindex;
2573 u32 bitindex;
2574 u32 vfta;
2575 u32 bits;
2576 u32 vt;
2577 u32 targetbit;
2578 bool vfta_changed = false;
2579
2580 if (vlan > 4095)
2581 return IXGBE_ERR_PARAM;
2582
2583 /*
2584 * this is a 2 part operation - first the VFTA, then the
2585 * VLVF and VLVFB if VT Mode is set
2586 * We don't write the VFTA until we know the VLVF part succeeded.
2587 */
2588
2589 /* Part 1
2590 * The VFTA is a bitstring made up of 128 32-bit registers
2591 * that enable the particular VLAN id, much like the MTA:
2592 * bits[11-5]: which register
2593 * bits[4-0]: which bit in the register
2594 */
2595 regindex = (vlan >> 5) & 0x7F;
2596 bitindex = vlan & 0x1F;
2597 targetbit = (1 << bitindex);
2598 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2599
2600 if (vlan_on) {
2601 if (!(vfta & targetbit)) {
2602 vfta |= targetbit;
2603 vfta_changed = true;
2604 }
2605 } else {
2606 if ((vfta & targetbit)) {
2607 vfta &= ~targetbit;
2608 vfta_changed = true;
2609 }
2610 }
2611
2612 /* Part 2
2613 * If VT Mode is set
2614 * Either vlan_on
2615 * make sure the vlan is in VLVF
2616 * set the vind bit in the matching VLVFB
2617 * Or !vlan_on
2618 * clear the pool bit and possibly the vind
2619 */
2620 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2621 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2622 s32 vlvf_index;
2623
2624 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2625 if (vlvf_index < 0)
2626 return vlvf_index;
2627
2628 if (vlan_on) {
2629 /* set the pool bit */
2630 if (vind < 32) {
2631 bits = IXGBE_READ_REG(hw,
2632 IXGBE_VLVFB(vlvf_index*2));
2633 bits |= (1 << vind);
2634 IXGBE_WRITE_REG(hw,
2635 IXGBE_VLVFB(vlvf_index*2),
2636 bits);
2637 } else {
2638 bits = IXGBE_READ_REG(hw,
2639 IXGBE_VLVFB((vlvf_index*2)+1));
2640 bits |= (1 << (vind-32));
2641 IXGBE_WRITE_REG(hw,
2642 IXGBE_VLVFB((vlvf_index*2)+1),
2643 bits);
2644 }
2645 } else {
2646 /* clear the pool bit */
2647 if (vind < 32) {
2648 bits = IXGBE_READ_REG(hw,
2649 IXGBE_VLVFB(vlvf_index*2));
2650 bits &= ~(1 << vind);
2651 IXGBE_WRITE_REG(hw,
2652 IXGBE_VLVFB(vlvf_index*2),
2653 bits);
2654 bits |= IXGBE_READ_REG(hw,
2655 IXGBE_VLVFB((vlvf_index*2)+1));
2656 } else {
2657 bits = IXGBE_READ_REG(hw,
2658 IXGBE_VLVFB((vlvf_index*2)+1));
2659 bits &= ~(1 << (vind-32));
2660 IXGBE_WRITE_REG(hw,
2661 IXGBE_VLVFB((vlvf_index*2)+1),
2662 bits);
2663 bits |= IXGBE_READ_REG(hw,
2664 IXGBE_VLVFB(vlvf_index*2));
2665 }
2666 }
2667
2668 /*
2669 * If there are still bits set in the VLVFB registers
2670 * for the VLAN ID indicated we need to see if the
2671 * caller is requesting that we clear the VFTA entry bit.
2672 * If the caller has requested that we clear the VFTA
2673 * entry bit but there are still pools/VFs using this VLAN
2674 * ID entry then ignore the request. We're not worried
2675 * about the case where we're turning the VFTA VLAN ID
2676 * entry bit on, only when requested to turn it off as
2677 * there may be multiple pools and/or VFs using the
2678 * VLAN ID entry. In that case we cannot clear the
2679 * VFTA bit until all pools/VFs using that VLAN ID have also
2680 * been cleared. This will be indicated by "bits" being
2681 * zero.
2682 */
2683 if (bits) {
2684 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2685 (IXGBE_VLVF_VIEN | vlan));
2686 if (!vlan_on) {
2687 /* someone wants to clear the vfta entry
2688 * but some pools/VFs are still using it.
2689 * Ignore it. */
2690 vfta_changed = false;
2691 }
2692 }
2693 else
2694 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
2695 }
2696
2697 if (vfta_changed)
2698 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
2699
2700 return 0;
2701}
2702
2703/**
2704 * ixgbe_clear_vfta_generic - Clear VLAN filter table
2705 * @hw: pointer to hardware structure
2706 *
2707 * Clears the VLAN filer table, and the VMDq index associated with the filter
2708 **/
2709s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
2710{
2711 u32 offset;
2712
2713 for (offset = 0; offset < hw->mac.vft_size; offset++)
2714 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
2715
2716 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
2717 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
2718 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
2719 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
2720 }
2721
2722 return 0;
2723}
2724
2725/**
2726 * ixgbe_check_mac_link_generic - Determine link and speed status
2727 * @hw: pointer to hardware structure
2728 * @speed: pointer to link speed
2729 * @link_up: true when link is up
2730 * @link_up_wait_to_complete: bool used to wait for link up or not
2731 *
2732 * Reads the links register to determine if link is up and the current speed
2733 **/
2734s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
2735 bool *link_up, bool link_up_wait_to_complete)
2736{
2737 u32 links_reg;
2738 u32 i;
2739
2740 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2741 if (link_up_wait_to_complete) {
2742 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2743 if (links_reg & IXGBE_LINKS_UP) {
2744 *link_up = true;
2745 break;
2746 } else {
2747 *link_up = false;
2748 }
2749 msleep(100);
2750 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2751 }
2752 } else {
2753 if (links_reg & IXGBE_LINKS_UP)
2754 *link_up = true;
2755 else
2756 *link_up = false;
2757 }
2758
2759 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2760 IXGBE_LINKS_SPEED_10G_82599)
2761 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2762 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2763 IXGBE_LINKS_SPEED_1G_82599)
2764 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2765 else
2766 *speed = IXGBE_LINK_SPEED_100_FULL;
2767
2768 /* if link is down, zero out the current_mode */
2769 if (*link_up == false) {
2770 hw->fc.current_mode = ixgbe_fc_none;
2771 hw->fc.fc_was_autonegged = false;
2772 }
2773
2774 return 0;
2775}
Don Skidmorea391f1d2010-11-16 19:27:15 -08002776
2777/**
2778 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
2779 * the EEPROM
2780 * @hw: pointer to hardware structure
2781 * @wwnn_prefix: the alternative WWNN prefix
2782 * @wwpn_prefix: the alternative WWPN prefix
2783 *
2784 * This function will read the EEPROM from the alternative SAN MAC address
2785 * block to check the support for the alternative WWNN/WWPN prefix support.
2786 **/
2787s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2788 u16 *wwpn_prefix)
2789{
2790 u16 offset, caps;
2791 u16 alt_san_mac_blk_offset;
2792
2793 /* clear output first */
2794 *wwnn_prefix = 0xFFFF;
2795 *wwpn_prefix = 0xFFFF;
2796
2797 /* check if alternative SAN MAC is supported */
2798 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2799 &alt_san_mac_blk_offset);
2800
2801 if ((alt_san_mac_blk_offset == 0) ||
2802 (alt_san_mac_blk_offset == 0xFFFF))
2803 goto wwn_prefix_out;
2804
2805 /* check capability in alternative san mac address block */
2806 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2807 hw->eeprom.ops.read(hw, offset, &caps);
2808 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2809 goto wwn_prefix_out;
2810
2811 /* get the corresponding prefix for WWNN/WWPN */
2812 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2813 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2814
2815 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2816 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2817
2818wwn_prefix_out:
2819 return 0;
2820}
Greg Rosea985b6c32010-11-18 03:02:52 +00002821
2822/**
2823 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2824 * @hw: pointer to hardware structure
2825 * @enable: enable or disable switch for anti-spoofing
2826 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
2827 *
2828 **/
2829void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
2830{
2831 int j;
2832 int pf_target_reg = pf >> 3;
2833 int pf_target_shift = pf % 8;
2834 u32 pfvfspoof = 0;
2835
2836 if (hw->mac.type == ixgbe_mac_82598EB)
2837 return;
2838
2839 if (enable)
2840 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
2841
2842 /*
2843 * PFVFSPOOF register array is size 8 with 8 bits assigned to
2844 * MAC anti-spoof enables in each register array element.
2845 */
2846 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
2847 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
2848
2849 /* If not enabling anti-spoofing then done */
2850 if (!enable)
2851 return;
2852
2853 /*
2854 * The PF should be allowed to spoof so that it can support
2855 * emulation mode NICs. Reset the bit assigned to the PF
2856 */
2857 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
2858 pfvfspoof ^= (1 << pf_target_shift);
2859 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
2860}
2861
2862/**
2863 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
2864 * @hw: pointer to hardware structure
2865 * @enable: enable or disable switch for VLAN anti-spoofing
2866 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
2867 *
2868 **/
2869void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
2870{
2871 int vf_target_reg = vf >> 3;
2872 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
2873 u32 pfvfspoof;
2874
2875 if (hw->mac.type == ixgbe_mac_82598EB)
2876 return;
2877
2878 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2879 if (enable)
2880 pfvfspoof |= (1 << vf_target_shift);
2881 else
2882 pfvfspoof &= ~(1 << vf_target_shift);
2883 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2884}