blob: b94634f4168950d8750bfb7ee4076a2ffbb7e57e [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
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070050static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
Don Skidmore7b25cdb2009-08-25 04:47:32 +000051static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
Auke Kok9a799d72007-09-15 14:07:45 -070052
53/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070054 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070055 * @hw: pointer to hardware structure
56 *
57 * Starts the hardware by filling the bus info structure and media type, clears
58 * all on chip counters, initializes receive address registers, multicast
59 * table, VLAN filter table, calls routine to set up link and flow control
60 * settings, and leaves transmit and receive units disabled and uninitialized
61 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070062s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070063{
64 u32 ctrl_ext;
65
66 /* Set the media type */
67 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
68
69 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070070 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070071
Auke Kok9a799d72007-09-15 14:07:45 -070072 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070073 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070074
Auke Kok9a799d72007-09-15 14:07:45 -070075 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070076 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070077
78 /* Set No Snoop Disable */
79 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
80 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
81 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070082 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070083
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000084 /* Setup flow control */
85 ixgbe_setup_fc(hw, 0);
86
Auke Kok9a799d72007-09-15 14:07:45 -070087 /* Clear adapter stopped flag */
88 hw->adapter_stopped = false;
89
90 return 0;
91}
92
93/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070094 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -070095 * @hw: pointer to hardware structure
96 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070097 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -070098 * structure and media type, clears all on chip counters, initializes receive
99 * address registers, multicast table, VLAN filter table, calls routine to set
100 * up link and flow control settings, and leaves transmit and receive units
101 * disabled and uninitialized
102 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700103s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700104{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000105 s32 status;
106
Auke Kok9a799d72007-09-15 14:07:45 -0700107 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000108 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700109
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000110 if (status == 0) {
111 /* Start the HW */
112 status = hw->mac.ops.start_hw(hw);
113 }
Auke Kok9a799d72007-09-15 14:07:45 -0700114
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000115 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700116}
117
118/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700119 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700120 * @hw: pointer to hardware structure
121 *
122 * Clears all hardware statistics counters by reading them from the hardware
123 * Statistics counters are clear on read.
124 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700125s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700126{
127 u16 i = 0;
128
129 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
130 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
131 IXGBE_READ_REG(hw, IXGBE_ERRBC);
132 IXGBE_READ_REG(hw, IXGBE_MSPDC);
133 for (i = 0; i < 8; i++)
134 IXGBE_READ_REG(hw, IXGBE_MPC(i));
135
136 IXGBE_READ_REG(hw, IXGBE_MLFC);
137 IXGBE_READ_REG(hw, IXGBE_MRFC);
138 IXGBE_READ_REG(hw, IXGBE_RLEC);
139 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
140 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
141 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
142 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
143
144 for (i = 0; i < 8; i++) {
145 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
146 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
147 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
148 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
149 }
150
151 IXGBE_READ_REG(hw, IXGBE_PRC64);
152 IXGBE_READ_REG(hw, IXGBE_PRC127);
153 IXGBE_READ_REG(hw, IXGBE_PRC255);
154 IXGBE_READ_REG(hw, IXGBE_PRC511);
155 IXGBE_READ_REG(hw, IXGBE_PRC1023);
156 IXGBE_READ_REG(hw, IXGBE_PRC1522);
157 IXGBE_READ_REG(hw, IXGBE_GPRC);
158 IXGBE_READ_REG(hw, IXGBE_BPRC);
159 IXGBE_READ_REG(hw, IXGBE_MPRC);
160 IXGBE_READ_REG(hw, IXGBE_GPTC);
161 IXGBE_READ_REG(hw, IXGBE_GORCL);
162 IXGBE_READ_REG(hw, IXGBE_GORCH);
163 IXGBE_READ_REG(hw, IXGBE_GOTCL);
164 IXGBE_READ_REG(hw, IXGBE_GOTCH);
165 for (i = 0; i < 8; i++)
166 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
167 IXGBE_READ_REG(hw, IXGBE_RUC);
168 IXGBE_READ_REG(hw, IXGBE_RFC);
169 IXGBE_READ_REG(hw, IXGBE_ROC);
170 IXGBE_READ_REG(hw, IXGBE_RJC);
171 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
172 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
173 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
174 IXGBE_READ_REG(hw, IXGBE_TORL);
175 IXGBE_READ_REG(hw, IXGBE_TORH);
176 IXGBE_READ_REG(hw, IXGBE_TPR);
177 IXGBE_READ_REG(hw, IXGBE_TPT);
178 IXGBE_READ_REG(hw, IXGBE_PTC64);
179 IXGBE_READ_REG(hw, IXGBE_PTC127);
180 IXGBE_READ_REG(hw, IXGBE_PTC255);
181 IXGBE_READ_REG(hw, IXGBE_PTC511);
182 IXGBE_READ_REG(hw, IXGBE_PTC1023);
183 IXGBE_READ_REG(hw, IXGBE_PTC1522);
184 IXGBE_READ_REG(hw, IXGBE_MPTC);
185 IXGBE_READ_REG(hw, IXGBE_BPTC);
186 for (i = 0; i < 16; i++) {
187 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
188 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
189 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
190 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
191 }
192
193 return 0;
194}
195
196/**
Don Skidmore289700db2010-12-03 03:32:58 +0000197 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700198 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000199 * @pba_num: stores the part number string from the EEPROM
200 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700201 *
Don Skidmore289700db2010-12-03 03:32:58 +0000202 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700203 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000204s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
205 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700206{
207 s32 ret_val;
208 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000209 u16 pba_ptr;
210 u16 offset;
211 u16 length;
212
213 if (pba_num == NULL) {
214 hw_dbg(hw, "PBA string buffer was null\n");
215 return IXGBE_ERR_INVALID_ARGUMENT;
216 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700217
218 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
219 if (ret_val) {
220 hw_dbg(hw, "NVM Read Error\n");
221 return ret_val;
222 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700223
Don Skidmore289700db2010-12-03 03:32:58 +0000224 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700225 if (ret_val) {
226 hw_dbg(hw, "NVM Read Error\n");
227 return ret_val;
228 }
Don Skidmore289700db2010-12-03 03:32:58 +0000229
230 /*
231 * if data is not ptr guard the PBA must be in legacy format which
232 * means pba_ptr is actually our second data word for the PBA number
233 * and we can decode it into an ascii string
234 */
235 if (data != IXGBE_PBANUM_PTR_GUARD) {
236 hw_dbg(hw, "NVM PBA number is not stored as string\n");
237
238 /* we will need 11 characters to store the PBA */
239 if (pba_num_size < 11) {
240 hw_dbg(hw, "PBA string buffer too small\n");
241 return IXGBE_ERR_NO_SPACE;
242 }
243
244 /* extract hex string from data and pba_ptr */
245 pba_num[0] = (data >> 12) & 0xF;
246 pba_num[1] = (data >> 8) & 0xF;
247 pba_num[2] = (data >> 4) & 0xF;
248 pba_num[3] = data & 0xF;
249 pba_num[4] = (pba_ptr >> 12) & 0xF;
250 pba_num[5] = (pba_ptr >> 8) & 0xF;
251 pba_num[6] = '-';
252 pba_num[7] = 0;
253 pba_num[8] = (pba_ptr >> 4) & 0xF;
254 pba_num[9] = pba_ptr & 0xF;
255
256 /* put a null character on the end of our string */
257 pba_num[10] = '\0';
258
259 /* switch all the data but the '-' to hex char */
260 for (offset = 0; offset < 10; offset++) {
261 if (pba_num[offset] < 0xA)
262 pba_num[offset] += '0';
263 else if (pba_num[offset] < 0x10)
264 pba_num[offset] += 'A' - 0xA;
265 }
266
267 return 0;
268 }
269
270 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
271 if (ret_val) {
272 hw_dbg(hw, "NVM Read Error\n");
273 return ret_val;
274 }
275
276 if (length == 0xFFFF || length == 0) {
277 hw_dbg(hw, "NVM PBA number section invalid length\n");
278 return IXGBE_ERR_PBA_SECTION;
279 }
280
281 /* check if pba_num buffer is big enough */
282 if (pba_num_size < (((u32)length * 2) - 1)) {
283 hw_dbg(hw, "PBA string buffer too small\n");
284 return IXGBE_ERR_NO_SPACE;
285 }
286
287 /* trim pba length from start of string */
288 pba_ptr++;
289 length--;
290
291 for (offset = 0; offset < length; offset++) {
292 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
293 if (ret_val) {
294 hw_dbg(hw, "NVM Read Error\n");
295 return ret_val;
296 }
297 pba_num[offset * 2] = (u8)(data >> 8);
298 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
299 }
300 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700301
302 return 0;
303}
304
305/**
306 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700307 * @hw: pointer to hardware structure
308 * @mac_addr: Adapter MAC address
309 *
310 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
311 * A reset of the adapter must be performed prior to calling this function
312 * in order for the MAC address to have been loaded from the EEPROM into RAR0
313 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700314s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700315{
316 u32 rar_high;
317 u32 rar_low;
318 u16 i;
319
320 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
321 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
322
323 for (i = 0; i < 4; i++)
324 mac_addr[i] = (u8)(rar_low >> (i*8));
325
326 for (i = 0; i < 2; i++)
327 mac_addr[i+4] = (u8)(rar_high >> (i*8));
328
329 return 0;
330}
331
Auke Kok9a799d72007-09-15 14:07:45 -0700332/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000333 * ixgbe_get_bus_info_generic - Generic set PCI bus info
334 * @hw: pointer to hardware structure
335 *
336 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
337 **/
338s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
339{
340 struct ixgbe_adapter *adapter = hw->back;
341 struct ixgbe_mac_info *mac = &hw->mac;
342 u16 link_status;
343
344 hw->bus.type = ixgbe_bus_type_pci_express;
345
346 /* Get the negotiated link width and speed from PCI config space */
347 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
348 &link_status);
349
350 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
351 case IXGBE_PCI_LINK_WIDTH_1:
352 hw->bus.width = ixgbe_bus_width_pcie_x1;
353 break;
354 case IXGBE_PCI_LINK_WIDTH_2:
355 hw->bus.width = ixgbe_bus_width_pcie_x2;
356 break;
357 case IXGBE_PCI_LINK_WIDTH_4:
358 hw->bus.width = ixgbe_bus_width_pcie_x4;
359 break;
360 case IXGBE_PCI_LINK_WIDTH_8:
361 hw->bus.width = ixgbe_bus_width_pcie_x8;
362 break;
363 default:
364 hw->bus.width = ixgbe_bus_width_unknown;
365 break;
366 }
367
368 switch (link_status & IXGBE_PCI_LINK_SPEED) {
369 case IXGBE_PCI_LINK_SPEED_2500:
370 hw->bus.speed = ixgbe_bus_speed_2500;
371 break;
372 case IXGBE_PCI_LINK_SPEED_5000:
373 hw->bus.speed = ixgbe_bus_speed_5000;
374 break;
375 default:
376 hw->bus.speed = ixgbe_bus_speed_unknown;
377 break;
378 }
379
380 mac->ops.set_lan_id(hw);
381
382 return 0;
383}
384
385/**
386 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
387 * @hw: pointer to the HW structure
388 *
389 * Determines the LAN function id by reading memory-mapped registers
390 * and swaps the port value if requested.
391 **/
392void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
393{
394 struct ixgbe_bus_info *bus = &hw->bus;
395 u32 reg;
396
397 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
398 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
399 bus->lan_id = bus->func;
400
401 /* check for a port swap */
402 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
403 if (reg & IXGBE_FACTPS_LFS)
404 bus->func ^= 0x1;
405}
406
407/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700408 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700409 * @hw: pointer to hardware structure
410 *
411 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
412 * disables transmit and receive units. The adapter_stopped flag is used by
413 * the shared code and drivers to determine if the adapter is in a stopped
414 * state and should not touch the hardware.
415 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700416s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700417{
418 u32 number_of_queues;
419 u32 reg_val;
420 u16 i;
421
422 /*
423 * Set the adapter_stopped flag so other driver functions stop touching
424 * the hardware
425 */
426 hw->adapter_stopped = true;
427
428 /* Disable the receive unit */
429 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
430 reg_val &= ~(IXGBE_RXCTRL_RXEN);
431 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700432 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700433 msleep(2);
434
435 /* Clear interrupt mask to stop from interrupts being generated */
436 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
437
438 /* Clear any pending interrupts */
439 IXGBE_READ_REG(hw, IXGBE_EICR);
440
441 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700442 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700443 for (i = 0; i < number_of_queues; i++) {
444 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
445 if (reg_val & IXGBE_TXDCTL_ENABLE) {
446 reg_val &= ~IXGBE_TXDCTL_ENABLE;
447 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
448 }
449 }
450
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700451 /*
452 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
453 * access and verify no pending requests
454 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000455 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700456
Auke Kok9a799d72007-09-15 14:07:45 -0700457 return 0;
458}
459
460/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700461 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700462 * @hw: pointer to hardware structure
463 * @index: led number to turn on
464 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700465s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700466{
467 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
468
469 /* To turn on the LED, set mode to ON. */
470 led_reg &= ~IXGBE_LED_MODE_MASK(index);
471 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
472 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700473 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700474
475 return 0;
476}
477
478/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700479 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700480 * @hw: pointer to hardware structure
481 * @index: led number to turn off
482 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700483s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700484{
485 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
486
487 /* To turn off the LED, set mode to OFF. */
488 led_reg &= ~IXGBE_LED_MODE_MASK(index);
489 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
490 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700491 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700492
493 return 0;
494}
495
Auke Kok9a799d72007-09-15 14:07:45 -0700496/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700497 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700498 * @hw: pointer to hardware structure
499 *
500 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
501 * ixgbe_hw struct in order to set up EEPROM access.
502 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700503s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700504{
505 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
506 u32 eec;
507 u16 eeprom_size;
508
509 if (eeprom->type == ixgbe_eeprom_uninitialized) {
510 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700511 /* Set default semaphore delay to 10ms which is a well
512 * tested value */
513 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700514
515 /*
516 * Check for EEPROM present first.
517 * If not present leave as none
518 */
519 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
520 if (eec & IXGBE_EEC_PRES) {
521 eeprom->type = ixgbe_eeprom_spi;
522
523 /*
524 * SPI EEPROM is assumed here. This code would need to
525 * change if a future EEPROM is not SPI.
526 */
527 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
528 IXGBE_EEC_SIZE_SHIFT);
529 eeprom->word_size = 1 << (eeprom_size +
530 IXGBE_EEPROM_WORD_SIZE_SHIFT);
531 }
532
533 if (eec & IXGBE_EEC_ADDR_SIZE)
534 eeprom->address_bits = 16;
535 else
536 eeprom->address_bits = 8;
537 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
538 "%d\n", eeprom->type, eeprom->word_size,
539 eeprom->address_bits);
540 }
541
542 return 0;
543}
544
545/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000546 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
547 * @hw: pointer to hardware structure
548 * @offset: offset within the EEPROM to be written to
549 * @data: 16 bit word to be written to the EEPROM
550 *
551 * If ixgbe_eeprom_update_checksum is not called after this function, the
552 * EEPROM will most likely contain an invalid checksum.
553 **/
554s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
555{
556 s32 status;
557 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
558
559 hw->eeprom.ops.init_params(hw);
560
561 if (offset >= hw->eeprom.word_size) {
562 status = IXGBE_ERR_EEPROM;
563 goto out;
564 }
565
566 /* Prepare the EEPROM for writing */
567 status = ixgbe_acquire_eeprom(hw);
568
569 if (status == 0) {
570 if (ixgbe_ready_eeprom(hw) != 0) {
571 ixgbe_release_eeprom(hw);
572 status = IXGBE_ERR_EEPROM;
573 }
574 }
575
576 if (status == 0) {
577 ixgbe_standby_eeprom(hw);
578
579 /* Send the WRITE ENABLE command (8 bit opcode ) */
580 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
581 IXGBE_EEPROM_OPCODE_BITS);
582
583 ixgbe_standby_eeprom(hw);
584
585 /*
586 * Some SPI eeproms use the 8th address bit embedded in the
587 * opcode
588 */
589 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
590 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
591
592 /* Send the Write command (8-bit opcode + addr) */
593 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
594 IXGBE_EEPROM_OPCODE_BITS);
595 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
596 hw->eeprom.address_bits);
597
598 /* Send the data */
599 data = (data >> 8) | (data << 8);
600 ixgbe_shift_out_eeprom_bits(hw, data, 16);
601 ixgbe_standby_eeprom(hw);
602
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000603 /* Done with writing - release the EEPROM */
604 ixgbe_release_eeprom(hw);
605 }
606
607out:
608 return status;
609}
610
611/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700612 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
613 * @hw: pointer to hardware structure
614 * @offset: offset within the EEPROM to be read
615 * @data: read 16 bit value from EEPROM
616 *
617 * Reads 16 bit value from EEPROM through bit-bang method
618 **/
619s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
620 u16 *data)
621{
622 s32 status;
623 u16 word_in;
624 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
625
626 hw->eeprom.ops.init_params(hw);
627
628 if (offset >= hw->eeprom.word_size) {
629 status = IXGBE_ERR_EEPROM;
630 goto out;
631 }
632
633 /* Prepare the EEPROM for reading */
634 status = ixgbe_acquire_eeprom(hw);
635
636 if (status == 0) {
637 if (ixgbe_ready_eeprom(hw) != 0) {
638 ixgbe_release_eeprom(hw);
639 status = IXGBE_ERR_EEPROM;
640 }
641 }
642
643 if (status == 0) {
644 ixgbe_standby_eeprom(hw);
645
646 /*
647 * Some SPI eeproms use the 8th address bit embedded in the
648 * opcode
649 */
650 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
651 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
652
653 /* Send the READ command (opcode + addr) */
654 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
655 IXGBE_EEPROM_OPCODE_BITS);
656 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
657 hw->eeprom.address_bits);
658
659 /* Read the data. */
660 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
661 *data = (word_in >> 8) | (word_in << 8);
662
663 /* End this read operation */
664 ixgbe_release_eeprom(hw);
665 }
666
667out:
668 return status;
669}
670
671/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000672 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700673 * @hw: pointer to hardware structure
674 * @offset: offset of word in the EEPROM to read
675 * @data: word read from the EEPROM
676 *
677 * Reads a 16 bit word from the EEPROM using the EERD register.
678 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000679s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700680{
681 u32 eerd;
682 s32 status;
683
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700684 hw->eeprom.ops.init_params(hw);
685
686 if (offset >= hw->eeprom.word_size) {
687 status = IXGBE_ERR_EEPROM;
688 goto out;
689 }
690
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000691 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
692 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700693
694 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000695 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700696
697 if (status == 0)
698 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000699 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700700 else
701 hw_dbg(hw, "Eeprom read timed out\n");
702
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700703out:
Auke Kok9a799d72007-09-15 14:07:45 -0700704 return status;
705}
706
707/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000708 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700709 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000710 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700711 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000712 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
713 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700714 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800715s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700716{
717 u32 i;
718 u32 reg;
719 s32 status = IXGBE_ERR_EEPROM;
720
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000721 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
722 if (ee_reg == IXGBE_NVM_POLL_READ)
723 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
724 else
725 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
726
727 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700728 status = 0;
729 break;
730 }
731 udelay(5);
732 }
733 return status;
734}
735
736/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700737 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
738 * @hw: pointer to hardware structure
739 *
740 * Prepares EEPROM for access using bit-bang method. This function should
741 * be called before issuing a command to the EEPROM.
742 **/
743static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
744{
745 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000746 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700747 u32 i;
748
749 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
750 status = IXGBE_ERR_SWFW_SYNC;
751
752 if (status == 0) {
753 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
754
755 /* Request EEPROM Access */
756 eec |= IXGBE_EEC_REQ;
757 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
758
759 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
760 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
761 if (eec & IXGBE_EEC_GNT)
762 break;
763 udelay(5);
764 }
765
766 /* Release if grant not acquired */
767 if (!(eec & IXGBE_EEC_GNT)) {
768 eec &= ~IXGBE_EEC_REQ;
769 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
770 hw_dbg(hw, "Could not acquire EEPROM grant\n");
771
772 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
773 status = IXGBE_ERR_EEPROM;
774 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700775
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000776 /* Setup EEPROM for Read/Write */
777 if (status == 0) {
778 /* Clear CS and SK */
779 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
780 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
781 IXGBE_WRITE_FLUSH(hw);
782 udelay(1);
783 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700784 }
785 return status;
786}
787
788/**
Auke Kok9a799d72007-09-15 14:07:45 -0700789 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
790 * @hw: pointer to hardware structure
791 *
792 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
793 **/
794static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
795{
796 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000797 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700798 u32 i;
799 u32 swsm;
800
Auke Kok9a799d72007-09-15 14:07:45 -0700801 /* Get SMBI software semaphore between device drivers first */
802 for (i = 0; i < timeout; i++) {
803 /*
804 * If the SMBI bit is 0 when we read it, then the bit will be
805 * set and we have the semaphore
806 */
807 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
808 if (!(swsm & IXGBE_SWSM_SMBI)) {
809 status = 0;
810 break;
811 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000812 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700813 }
814
815 /* Now get the semaphore between SW/FW through the SWESMBI bit */
816 if (status == 0) {
817 for (i = 0; i < timeout; i++) {
818 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
819
820 /* Set the SW EEPROM semaphore bit to request access */
821 swsm |= IXGBE_SWSM_SWESMBI;
822 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
823
824 /*
825 * If we set the bit successfully then we got the
826 * semaphore.
827 */
828 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
829 if (swsm & IXGBE_SWSM_SWESMBI)
830 break;
831
832 udelay(50);
833 }
834
835 /*
836 * Release semaphores and return error if SW EEPROM semaphore
837 * was not granted because we don't have access to the EEPROM
838 */
839 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000840 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700841 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700842 ixgbe_release_eeprom_semaphore(hw);
843 status = IXGBE_ERR_EEPROM;
844 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000845 } else {
846 hw_dbg(hw, "Software semaphore SMBI between device drivers "
847 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700848 }
849
850 return status;
851}
852
853/**
854 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
855 * @hw: pointer to hardware structure
856 *
857 * This function clears hardware semaphore bits.
858 **/
859static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
860{
861 u32 swsm;
862
863 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
864
865 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
866 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
867 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700868 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700869}
870
871/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700872 * ixgbe_ready_eeprom - Polls for EEPROM ready
873 * @hw: pointer to hardware structure
874 **/
875static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
876{
877 s32 status = 0;
878 u16 i;
879 u8 spi_stat_reg;
880
881 /*
882 * Read "Status Register" repeatedly until the LSB is cleared. The
883 * EEPROM will signal that the command has been completed by clearing
884 * bit 0 of the internal status register. If it's not cleared within
885 * 5 milliseconds, then error out.
886 */
887 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
888 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
889 IXGBE_EEPROM_OPCODE_BITS);
890 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
891 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
892 break;
893
894 udelay(5);
895 ixgbe_standby_eeprom(hw);
896 };
897
898 /*
899 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
900 * devices (and only 0-5mSec on 5V devices)
901 */
902 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
903 hw_dbg(hw, "SPI EEPROM Status error\n");
904 status = IXGBE_ERR_EEPROM;
905 }
906
907 return status;
908}
909
910/**
911 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
912 * @hw: pointer to hardware structure
913 **/
914static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
915{
916 u32 eec;
917
918 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
919
920 /* Toggle CS to flush commands */
921 eec |= IXGBE_EEC_CS;
922 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
923 IXGBE_WRITE_FLUSH(hw);
924 udelay(1);
925 eec &= ~IXGBE_EEC_CS;
926 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
927 IXGBE_WRITE_FLUSH(hw);
928 udelay(1);
929}
930
931/**
932 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
933 * @hw: pointer to hardware structure
934 * @data: data to send to the EEPROM
935 * @count: number of bits to shift out
936 **/
937static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
938 u16 count)
939{
940 u32 eec;
941 u32 mask;
942 u32 i;
943
944 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
945
946 /*
947 * Mask is used to shift "count" bits of "data" out to the EEPROM
948 * one bit at a time. Determine the starting bit based on count
949 */
950 mask = 0x01 << (count - 1);
951
952 for (i = 0; i < count; i++) {
953 /*
954 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
955 * "1", and then raising and then lowering the clock (the SK
956 * bit controls the clock input to the EEPROM). A "0" is
957 * shifted out to the EEPROM by setting "DI" to "0" and then
958 * raising and then lowering the clock.
959 */
960 if (data & mask)
961 eec |= IXGBE_EEC_DI;
962 else
963 eec &= ~IXGBE_EEC_DI;
964
965 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
966 IXGBE_WRITE_FLUSH(hw);
967
968 udelay(1);
969
970 ixgbe_raise_eeprom_clk(hw, &eec);
971 ixgbe_lower_eeprom_clk(hw, &eec);
972
973 /*
974 * Shift mask to signify next bit of data to shift in to the
975 * EEPROM
976 */
977 mask = mask >> 1;
978 };
979
980 /* We leave the "DI" bit set to "0" when we leave this routine. */
981 eec &= ~IXGBE_EEC_DI;
982 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
983 IXGBE_WRITE_FLUSH(hw);
984}
985
986/**
987 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
988 * @hw: pointer to hardware structure
989 **/
990static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
991{
992 u32 eec;
993 u32 i;
994 u16 data = 0;
995
996 /*
997 * In order to read a register from the EEPROM, we need to shift
998 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
999 * the clock input to the EEPROM (setting the SK bit), and then reading
1000 * the value of the "DO" bit. During this "shifting in" process the
1001 * "DI" bit should always be clear.
1002 */
1003 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1004
1005 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1006
1007 for (i = 0; i < count; i++) {
1008 data = data << 1;
1009 ixgbe_raise_eeprom_clk(hw, &eec);
1010
1011 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1012
1013 eec &= ~(IXGBE_EEC_DI);
1014 if (eec & IXGBE_EEC_DO)
1015 data |= 1;
1016
1017 ixgbe_lower_eeprom_clk(hw, &eec);
1018 }
1019
1020 return data;
1021}
1022
1023/**
1024 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1025 * @hw: pointer to hardware structure
1026 * @eec: EEC register's current value
1027 **/
1028static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1029{
1030 /*
1031 * Raise the clock input to the EEPROM
1032 * (setting the SK bit), then delay
1033 */
1034 *eec = *eec | IXGBE_EEC_SK;
1035 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1036 IXGBE_WRITE_FLUSH(hw);
1037 udelay(1);
1038}
1039
1040/**
1041 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1042 * @hw: pointer to hardware structure
1043 * @eecd: EECD's current value
1044 **/
1045static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1046{
1047 /*
1048 * Lower the clock input to the EEPROM (clearing the SK bit), then
1049 * delay
1050 */
1051 *eec = *eec & ~IXGBE_EEC_SK;
1052 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1053 IXGBE_WRITE_FLUSH(hw);
1054 udelay(1);
1055}
1056
1057/**
1058 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1059 * @hw: pointer to hardware structure
1060 **/
1061static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1062{
1063 u32 eec;
1064
1065 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1066
1067 eec |= IXGBE_EEC_CS; /* Pull CS high */
1068 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1069
1070 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1071 IXGBE_WRITE_FLUSH(hw);
1072
1073 udelay(1);
1074
1075 /* Stop requesting EEPROM access */
1076 eec &= ~IXGBE_EEC_REQ;
1077 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1078
1079 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001080
1081 /* Delay before attempt to obtain semaphore again to allow FW access */
1082 msleep(hw->eeprom.semaphore_delay);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001083}
1084
1085/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001086 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001087 * @hw: pointer to hardware structure
1088 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001089u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001090{
1091 u16 i;
1092 u16 j;
1093 u16 checksum = 0;
1094 u16 length = 0;
1095 u16 pointer = 0;
1096 u16 word = 0;
1097
1098 /* Include 0x0-0x3F in the checksum */
1099 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001100 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001101 hw_dbg(hw, "EEPROM read failed\n");
1102 break;
1103 }
1104 checksum += word;
1105 }
1106
1107 /* Include all data from pointers except for the fw pointer */
1108 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001109 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001110
1111 /* Make sure the pointer seems valid */
1112 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001113 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001114
1115 if (length != 0xFFFF && length != 0) {
1116 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001117 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001118 checksum += word;
1119 }
1120 }
1121 }
1122 }
1123
1124 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1125
1126 return checksum;
1127}
1128
1129/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001130 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001131 * @hw: pointer to hardware structure
1132 * @checksum_val: calculated checksum
1133 *
1134 * Performs checksum calculation and validates the EEPROM checksum. If the
1135 * caller does not need checksum_val, the value can be NULL.
1136 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001137s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1138 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001139{
1140 s32 status;
1141 u16 checksum;
1142 u16 read_checksum = 0;
1143
1144 /*
1145 * Read the first word from the EEPROM. If this times out or fails, do
1146 * not continue or we could be in for a very long wait while every
1147 * EEPROM read fails
1148 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001149 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001150
1151 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001152 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001153
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001154 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001155
1156 /*
1157 * Verify read checksum from EEPROM is the same as
1158 * calculated checksum
1159 */
1160 if (read_checksum != checksum)
1161 status = IXGBE_ERR_EEPROM_CHECKSUM;
1162
1163 /* If the user cares, return the calculated checksum */
1164 if (checksum_val)
1165 *checksum_val = checksum;
1166 } else {
1167 hw_dbg(hw, "EEPROM read failed\n");
1168 }
1169
1170 return status;
1171}
1172
1173/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001174 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1175 * @hw: pointer to hardware structure
1176 **/
1177s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1178{
1179 s32 status;
1180 u16 checksum;
1181
1182 /*
1183 * Read the first word from the EEPROM. If this times out or fails, do
1184 * not continue or we could be in for a very long wait while every
1185 * EEPROM read fails
1186 */
1187 status = hw->eeprom.ops.read(hw, 0, &checksum);
1188
1189 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001190 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001191 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1192 checksum);
1193 } else {
1194 hw_dbg(hw, "EEPROM read failed\n");
1195 }
1196
1197 return status;
1198}
1199
1200/**
Auke Kok9a799d72007-09-15 14:07:45 -07001201 * ixgbe_validate_mac_addr - Validate MAC address
1202 * @mac_addr: pointer to MAC address.
1203 *
1204 * Tests a MAC address to ensure it is a valid Individual Address
1205 **/
1206s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1207{
1208 s32 status = 0;
1209
1210 /* Make sure it is not a multicast address */
1211 if (IXGBE_IS_MULTICAST(mac_addr))
1212 status = IXGBE_ERR_INVALID_MAC_ADDR;
1213 /* Not a broadcast address */
1214 else if (IXGBE_IS_BROADCAST(mac_addr))
1215 status = IXGBE_ERR_INVALID_MAC_ADDR;
1216 /* Reject the zero address */
1217 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001218 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001219 status = IXGBE_ERR_INVALID_MAC_ADDR;
1220
1221 return status;
1222}
1223
1224/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001225 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001226 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001227 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001228 * @addr: Address to put into receive address register
1229 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001230 * @enable_addr: set flag that address is active
1231 *
1232 * Puts an ethernet address into a receive address register.
1233 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001234s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1235 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001236{
1237 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001238 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001239
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001240 /* Make sure we are using a valid rar index range */
1241 if (index >= rar_entries) {
1242 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1243 return IXGBE_ERR_INVALID_ARGUMENT;
1244 }
1245
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001246 /* setup VMDq pool selection before this RAR gets enabled */
1247 hw->mac.ops.set_vmdq(hw, index, vmdq);
1248
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001249 /*
1250 * HW expects these in little endian so we reverse the byte
1251 * order from network order (big endian) to little endian
1252 */
1253 rar_low = ((u32)addr[0] |
1254 ((u32)addr[1] << 8) |
1255 ((u32)addr[2] << 16) |
1256 ((u32)addr[3] << 24));
1257 /*
1258 * Some parts put the VMDq setting in the extra RAH bits,
1259 * so save everything except the lower 16 bits that hold part
1260 * of the address and the address valid bit.
1261 */
1262 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1263 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1264 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001265
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001266 if (enable_addr != 0)
1267 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001268
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001269 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1270 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001271
1272 return 0;
1273}
1274
1275/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001276 * ixgbe_clear_rar_generic - Remove Rx address register
1277 * @hw: pointer to hardware structure
1278 * @index: Receive address register to write
1279 *
1280 * Clears an ethernet address from a receive address register.
1281 **/
1282s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1283{
1284 u32 rar_high;
1285 u32 rar_entries = hw->mac.num_rar_entries;
1286
1287 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001288 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001289 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001290 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001291 }
1292
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001293 /*
1294 * Some parts put the VMDq setting in the extra RAH bits,
1295 * so save everything except the lower 16 bits that hold part
1296 * of the address and the address valid bit.
1297 */
1298 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1299 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1300
1301 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1302 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1303
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001304 /* clear VMDq pool/queue selection for this RAR */
1305 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1306
1307 return 0;
1308}
1309
1310/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001311 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001312 * @hw: pointer to hardware structure
1313 *
1314 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001315 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001316 * the receiver is in reset when the routine is called.
1317 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001318s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001319{
1320 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001321 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001322
1323 /*
1324 * If the current mac address is valid, assume it is a software override
1325 * to the permanent address.
1326 * Otherwise, use the permanent address from the eeprom.
1327 */
1328 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1329 IXGBE_ERR_INVALID_MAC_ADDR) {
1330 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001331 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001332
hartleysce7194d2010-01-05 06:56:52 +00001333 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001334 } else {
1335 /* Setup the receive address. */
1336 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001337 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001338
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001339 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001340
1341 /* clear VMDq pool/queue selection for RAR 0 */
1342 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001343 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001344 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001345
1346 hw->addr_ctrl.rar_used_count = 1;
1347
1348 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001349 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001350 for (i = 1; i < rar_entries; i++) {
1351 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1352 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1353 }
1354
1355 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001356 hw->addr_ctrl.mta_in_use = 0;
1357 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1358
1359 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001360 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001361 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1362
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001363 if (hw->mac.ops.init_uta_tables)
1364 hw->mac.ops.init_uta_tables(hw);
1365
Auke Kok9a799d72007-09-15 14:07:45 -07001366 return 0;
1367}
1368
1369/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001370 * ixgbe_add_uc_addr - Adds a secondary unicast address.
1371 * @hw: pointer to hardware structure
1372 * @addr: new address
1373 *
1374 * Adds it to unused receive address register or goes into promiscuous mode.
1375 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001376static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001377{
1378 u32 rar_entries = hw->mac.num_rar_entries;
1379 u32 rar;
1380
1381 hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1382 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1383
1384 /*
1385 * Place this address in the RAR if there is room,
1386 * else put the controller into promiscuous mode
1387 */
1388 if (hw->addr_ctrl.rar_used_count < rar_entries) {
Emil Tantilov80960ab2011-02-18 08:58:27 +00001389 rar = hw->addr_ctrl.rar_used_count;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001390 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001391 hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
1392 hw->addr_ctrl.rar_used_count++;
1393 } else {
1394 hw->addr_ctrl.overflow_promisc++;
1395 }
1396
1397 hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
1398}
1399
1400/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001401 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001402 * @hw: pointer to hardware structure
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001403 * @netdev: pointer to net device structure
Christopher Leech2c5645c2008-08-26 04:27:02 -07001404 *
1405 * The given list replaces any existing list. Clears the secondary addrs from
1406 * receive address registers. Uses unused receive address registers for the
1407 * first secondary addresses, and falls back to promiscuous mode as needed.
1408 *
1409 * Drivers using secondary unicast addresses must set user_set_promisc when
1410 * manually putting the device into promiscuous mode.
1411 **/
Jiri Pirkoccffad252009-05-22 23:22:17 +00001412s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001413 struct net_device *netdev)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001414{
Christopher Leech2c5645c2008-08-26 04:27:02 -07001415 u32 i;
1416 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
1417 u32 uc_addr_in_use;
1418 u32 fctrl;
Jiri Pirkoccffad252009-05-22 23:22:17 +00001419 struct netdev_hw_addr *ha;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001420
1421 /*
1422 * Clear accounting of old secondary address list,
1423 * don't count RAR[0]
1424 */
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00001425 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001426 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
1427 hw->addr_ctrl.overflow_promisc = 0;
1428
1429 /* Zero out the other receive addresses */
Shannon Nelson91152c32009-11-24 18:52:10 +00001430 hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use + 1);
1431 for (i = 0; i < uc_addr_in_use; i++) {
1432 IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
1433 IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001434 }
1435
1436 /* Add the new addresses */
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08001437 netdev_for_each_uc_addr(ha, netdev) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001438 hw_dbg(hw, " Adding the secondary addresses:\n");
Jiri Pirkoccffad252009-05-22 23:22:17 +00001439 ixgbe_add_uc_addr(hw, ha->addr, 0);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001440 }
1441
1442 if (hw->addr_ctrl.overflow_promisc) {
1443 /* enable promisc if not already in overflow or set by user */
1444 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1445 hw_dbg(hw, " Entering address overflow promisc mode\n");
1446 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1447 fctrl |= IXGBE_FCTRL_UPE;
1448 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Emil Tantilove433ea12010-05-13 17:33:00 +00001449 hw->addr_ctrl.uc_set_promisc = true;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001450 }
1451 } else {
1452 /* only disable if set by overflow, not by user */
Emil Tantilove433ea12010-05-13 17:33:00 +00001453 if ((old_promisc_setting && hw->addr_ctrl.uc_set_promisc) &&
1454 !(hw->addr_ctrl.user_set_promisc)) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001455 hw_dbg(hw, " Leaving address overflow promisc mode\n");
1456 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1457 fctrl &= ~IXGBE_FCTRL_UPE;
1458 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Emil Tantilove433ea12010-05-13 17:33:00 +00001459 hw->addr_ctrl.uc_set_promisc = false;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001460 }
1461 }
1462
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001463 hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001464 return 0;
1465}
1466
1467/**
Auke Kok9a799d72007-09-15 14:07:45 -07001468 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1469 * @hw: pointer to hardware structure
1470 * @mc_addr: the multicast address
1471 *
1472 * Extracts the 12 bits, from a multicast address, to determine which
1473 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1474 * incoming rx multicast addresses, to determine the bit-vector to check in
1475 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001476 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001477 * to mc_filter_type.
1478 **/
1479static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1480{
1481 u32 vector = 0;
1482
1483 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001484 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001485 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1486 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001487 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001488 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1489 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001490 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001491 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1492 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001493 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001494 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1495 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001496 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001497 hw_dbg(hw, "MC filter type param set incorrectly\n");
1498 break;
1499 }
1500
1501 /* vector can only be 12-bits or boundary will be exceeded */
1502 vector &= 0xFFF;
1503 return vector;
1504}
1505
1506/**
1507 * ixgbe_set_mta - Set bit-vector in multicast table
1508 * @hw: pointer to hardware structure
1509 * @hash_value: Multicast address hash value
1510 *
1511 * Sets the bit-vector in the multicast table.
1512 **/
1513static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1514{
1515 u32 vector;
1516 u32 vector_bit;
1517 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001518
1519 hw->addr_ctrl.mta_in_use++;
1520
1521 vector = ixgbe_mta_vector(hw, mc_addr);
1522 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1523
1524 /*
1525 * The MTA is a register array of 128 32-bit registers. It is treated
1526 * like an array of 4096 bits. We want to set bit
1527 * BitArray[vector_value]. So we figure out what register the bit is
1528 * in, read it, OR in the new bit, then write back the new value. The
1529 * register is determined by the upper 7 bits of the vector value and
1530 * the bit within that register are determined by the lower 5 bits of
1531 * the value.
1532 */
1533 vector_reg = (vector >> 5) & 0x7F;
1534 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00001535 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001536}
1537
1538/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001539 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001540 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001541 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001542 *
1543 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001544 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001545 * registers for the first multicast addresses, and hashes the rest into the
1546 * multicast table.
1547 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001548s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1549 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001550{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001551 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001552 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001553
1554 /*
1555 * Set the new number of MC addresses that we are being requested to
1556 * use.
1557 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001558 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001559 hw->addr_ctrl.mta_in_use = 0;
1560
Emil Tantilov80960ab2011-02-18 08:58:27 +00001561 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001562 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001563 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001564
Emil Tantilov80960ab2011-02-18 08:58:27 +00001565 /* Update mta shadow */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001566 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001567 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad32010-04-01 21:22:57 +00001568 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001569 }
1570
1571 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001572 for (i = 0; i < hw->mac.mcft_size; i++)
1573 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1574 hw->mac.mta_shadow[i]);
1575
Auke Kok9a799d72007-09-15 14:07:45 -07001576 if (hw->addr_ctrl.mta_in_use > 0)
1577 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001578 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001579
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001580 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001581 return 0;
1582}
1583
1584/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001585 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001586 * @hw: pointer to hardware structure
1587 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001588 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001589 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001590s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001591{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001592 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001593
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001594 if (a->mta_in_use > 0)
1595 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1596 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001597
1598 return 0;
1599}
1600
1601/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001602 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001603 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001604 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001605 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001606 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001607s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001608{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001609 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001610
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001611 if (a->mta_in_use > 0)
1612 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001613
1614 return 0;
1615}
1616
1617/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001618 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001619 * @hw: pointer to hardware structure
1620 * @packetbuf_num: packet buffer number (0-7)
1621 *
1622 * Enable flow control according to the current settings.
1623 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001624s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001625{
1626 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001627 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001628 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001629 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001630 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001631
1632#ifdef CONFIG_DCB
1633 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1634 goto out;
1635
1636#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001637 /* Negotiate the fc mode to use */
1638 ret_val = ixgbe_fc_autoneg(hw);
1639 if (ret_val)
1640 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001641
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001642 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001643 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1644 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1645
1646 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1647 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1648
1649 /*
1650 * The possible values of fc.current_mode are:
1651 * 0: Flow control is completely disabled
1652 * 1: Rx flow control is enabled (we can receive pause frames,
1653 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001654 * 2: Tx flow control is enabled (we can send pause frames but
1655 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001656 * 3: Both Rx and Tx flow control (symmetric) are enabled.
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001657 * 4: Priority Flow Control is enabled.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001658 * other: Invalid.
1659 */
1660 switch (hw->fc.current_mode) {
1661 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001662 /*
1663 * Flow control is disabled by software override or autoneg.
1664 * The code below will actually disable it in the HW.
1665 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001666 break;
1667 case ixgbe_fc_rx_pause:
1668 /*
1669 * Rx Flow control is enabled and Tx Flow control is
1670 * disabled by software override. Since there really
1671 * isn't a way to advertise that we are capable of RX
1672 * Pause ONLY, we will advertise that we support both
1673 * symmetric and asymmetric Rx PAUSE. Later, we will
1674 * disable the adapter's ability to send PAUSE frames.
1675 */
1676 mflcn_reg |= IXGBE_MFLCN_RFCE;
1677 break;
1678 case ixgbe_fc_tx_pause:
1679 /*
1680 * Tx Flow control is enabled, and Rx Flow control is
1681 * disabled by software override.
1682 */
1683 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1684 break;
1685 case ixgbe_fc_full:
1686 /* Flow control (both Rx and Tx) is enabled by SW override. */
1687 mflcn_reg |= IXGBE_MFLCN_RFCE;
1688 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1689 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001690#ifdef CONFIG_DCB
1691 case ixgbe_fc_pfc:
1692 goto out;
1693 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001694#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001695 default:
1696 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001697 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001698 goto out;
1699 break;
1700 }
1701
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001702 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001703 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001704 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1705 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1706
John Fastabend16b61be2010-11-16 19:26:44 -08001707 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1708 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001709
John Fastabend16b61be2010-11-16 19:26:44 -08001710 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1711 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001712
John Fastabend16b61be2010-11-16 19:26:44 -08001713 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1714 fcrth |= IXGBE_FCRTH_FCEN;
1715 if (hw->fc.send_xon)
1716 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001717 }
1718
John Fastabend16b61be2010-11-16 19:26:44 -08001719 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1720 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1721
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001722 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001723 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001724 if ((packetbuf_num & 1) == 0)
1725 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1726 else
1727 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1728 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1729
1730 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1731
1732out:
1733 return ret_val;
1734}
1735
1736/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001737 * ixgbe_fc_autoneg - Configure flow control
1738 * @hw: pointer to hardware structure
1739 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001740 * Compares our advertised flow control capabilities to those advertised by
1741 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001742 **/
1743s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1744{
1745 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001746 ixgbe_link_speed speed;
1747 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001748 u32 links2, anlp1_reg, autoc_reg, links;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001749 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001750
1751 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001752 * AN should have completed when the cable was plugged in.
1753 * Look for reasons to bail out. Bail out if:
1754 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001755 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001756 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001757 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001758 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001759 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001760 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001761
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001762 if (hw->fc.disable_fc_autoneg || (!link_up)) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001763 hw->fc.fc_was_autonegged = false;
1764 hw->fc.current_mode = hw->fc.requested_mode;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001765 goto out;
1766 }
1767
1768 /*
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001769 * On backplane, bail out if
1770 * - backplane autoneg was not completed, or if
Don Skidmore000c4862009-11-24 18:51:48 +00001771 * - we are 82599 and link partner is not AN enabled
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001772 */
1773 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1774 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Don Skidmore000c4862009-11-24 18:51:48 +00001775 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001776 hw->fc.fc_was_autonegged = false;
1777 hw->fc.current_mode = hw->fc.requested_mode;
1778 goto out;
1779 }
Don Skidmore000c4862009-11-24 18:51:48 +00001780
1781 if (hw->mac.type == ixgbe_mac_82599EB) {
1782 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1783 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1784 hw->fc.fc_was_autonegged = false;
1785 hw->fc.current_mode = hw->fc.requested_mode;
1786 goto out;
1787 }
1788 }
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001789 }
1790
1791 /*
1792 * On multispeed fiber at 1g, bail out if
1793 * - link is up but AN did not complete, or if
1794 * - link is up and AN completed but timed out
1795 */
1796 if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
1797 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1798 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1799 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1800 hw->fc.fc_was_autonegged = false;
1801 hw->fc.current_mode = hw->fc.requested_mode;
1802 goto out;
1803 }
1804 }
1805
1806 /*
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00001807 * Bail out on
1808 * - copper or CX4 adapters
1809 * - fiber adapters running at 10gig
1810 */
1811 if ((hw->phy.media_type == ixgbe_media_type_copper) ||
1812 (hw->phy.media_type == ixgbe_media_type_cx4) ||
1813 ((hw->phy.media_type == ixgbe_media_type_fiber) &&
1814 (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
1815 hw->fc.fc_was_autonegged = false;
1816 hw->fc.current_mode = hw->fc.requested_mode;
1817 goto out;
1818 }
1819
1820 /*
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001821 * Read the AN advertisement and LP ability registers and resolve
1822 * local flow control settings accordingly
1823 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001824 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
1825 (hw->phy.media_type != ixgbe_media_type_backplane)) {
1826 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1827 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1828 if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1829 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1830 /*
1831 * Now we need to check if the user selected Rx ONLY
1832 * of pause frames. In this case, we had to advertise
1833 * FULL flow control because we could not advertise RX
1834 * ONLY. Hence, we must now check to see if we need to
1835 * turn OFF the TRANSMISSION of PAUSE frames.
1836 */
1837 if (hw->fc.requested_mode == ixgbe_fc_full) {
1838 hw->fc.current_mode = ixgbe_fc_full;
1839 hw_dbg(hw, "Flow Control = FULL.\n");
1840 } else {
1841 hw->fc.current_mode = ixgbe_fc_rx_pause;
1842 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1843 }
1844 } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1845 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1846 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1847 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1848 hw->fc.current_mode = ixgbe_fc_tx_pause;
1849 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1850 } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1851 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1852 !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1853 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001854 hw->fc.current_mode = ixgbe_fc_rx_pause;
1855 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001856 } else {
1857 hw->fc.current_mode = ixgbe_fc_none;
1858 hw_dbg(hw, "Flow Control = NONE.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001859 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001860 }
1861
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001862 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1863 /*
1864 * Read the 10g AN autoc and LP ability registers and resolve
1865 * local flow control settings accordingly
1866 */
1867 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1868 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1869
1870 if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1871 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
1872 /*
1873 * Now we need to check if the user selected Rx ONLY
1874 * of pause frames. In this case, we had to advertise
1875 * FULL flow control because we could not advertise RX
1876 * ONLY. Hence, we must now check to see if we need to
1877 * turn OFF the TRANSMISSION of PAUSE frames.
1878 */
1879 if (hw->fc.requested_mode == ixgbe_fc_full) {
1880 hw->fc.current_mode = ixgbe_fc_full;
1881 hw_dbg(hw, "Flow Control = FULL.\n");
1882 } else {
1883 hw->fc.current_mode = ixgbe_fc_rx_pause;
1884 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1885 }
1886 } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1887 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1888 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1889 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1890 hw->fc.current_mode = ixgbe_fc_tx_pause;
1891 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1892 } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1893 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1894 !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1895 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1896 hw->fc.current_mode = ixgbe_fc_rx_pause;
1897 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1898 } else {
1899 hw->fc.current_mode = ixgbe_fc_none;
1900 hw_dbg(hw, "Flow Control = NONE.\n");
1901 }
1902 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001903 /* Record that current_mode is the result of a successful autoneg */
1904 hw->fc.fc_was_autonegged = true;
1905
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001906out:
1907 return ret_val;
1908}
1909
1910/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001911 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001912 * @hw: pointer to hardware structure
1913 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001914 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001915 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001916static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001917{
1918 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001919 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001920
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001921#ifdef CONFIG_DCB
1922 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1923 hw->fc.current_mode = hw->fc.requested_mode;
1924 goto out;
1925 }
1926
1927#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001928 /* Validate the packetbuf configuration */
1929 if (packetbuf_num < 0 || packetbuf_num > 7) {
1930 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1931 "is 0-7\n", packetbuf_num);
1932 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1933 goto out;
1934 }
1935
1936 /*
1937 * Validate the water mark configuration. Zero water marks are invalid
1938 * because it causes the controller to just blast out fc packets.
1939 */
1940 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001941 hw_dbg(hw, "Invalid water mark configuration\n");
1942 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1943 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001944 }
1945
1946 /*
1947 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001948 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001949 */
1950 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1951 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
1952 "IEEE mode\n");
1953 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1954 goto out;
1955 }
1956
1957 /*
1958 * 10gig parts do not have a word in the EEPROM to determine the
1959 * default flow control setting, so we explicitly set it to full.
1960 */
1961 if (hw->fc.requested_mode == ixgbe_fc_default)
1962 hw->fc.requested_mode = ixgbe_fc_full;
1963
1964 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001965 * Set up the 1G flow control advertisement registers so the HW will be
1966 * able to do fc autoneg once the cable is plugged in. If we end up
1967 * using 10g instead, this is harmless.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001968 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001969 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001970
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001971 /*
1972 * The possible values of fc.requested_mode are:
1973 * 0: Flow control is completely disabled
1974 * 1: Rx flow control is enabled (we can receive pause frames,
1975 * but not send pause frames).
1976 * 2: Tx flow control is enabled (we can send pause frames but
1977 * we do not support receiving pause frames).
1978 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1979#ifdef CONFIG_DCB
1980 * 4: Priority Flow Control is enabled.
1981#endif
1982 * other: Invalid.
1983 */
1984 switch (hw->fc.requested_mode) {
1985 case ixgbe_fc_none:
1986 /* Flow control completely disabled by software override. */
1987 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1988 break;
1989 case ixgbe_fc_rx_pause:
1990 /*
1991 * Rx Flow control is enabled and Tx Flow control is
1992 * disabled by software override. Since there really
1993 * isn't a way to advertise that we are capable of RX
1994 * Pause ONLY, we will advertise that we support both
1995 * symmetric and asymmetric Rx PAUSE. Later, we will
1996 * disable the adapter's ability to send PAUSE frames.
1997 */
1998 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1999 break;
2000 case ixgbe_fc_tx_pause:
2001 /*
2002 * Tx Flow control is enabled, and Rx Flow control is
2003 * disabled by software override.
2004 */
2005 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2006 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
2007 break;
2008 case ixgbe_fc_full:
2009 /* Flow control (both Rx and Tx) is enabled by SW override. */
2010 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2011 break;
2012#ifdef CONFIG_DCB
2013 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002014 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002015 break;
2016#endif /* CONFIG_DCB */
2017 default:
2018 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002019 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002020 goto out;
2021 break;
2022 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002023
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002024 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2025 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2026
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002027 /* Disable AN timeout */
2028 if (hw->fc.strict_ieee)
2029 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2030
2031 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2032 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002033
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002034 /*
2035 * Set up the 10G flow control advertisement registers so the HW
2036 * can do fc autoneg once the cable is plugged in. If we end up
2037 * using 1g instead, this is harmless.
2038 */
2039 reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2040
2041 /*
2042 * The possible values of fc.requested_mode are:
2043 * 0: Flow control is completely disabled
2044 * 1: Rx flow control is enabled (we can receive pause frames,
2045 * but not send pause frames).
2046 * 2: Tx flow control is enabled (we can send pause frames but
2047 * we do not support receiving pause frames).
2048 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2049 * other: Invalid.
2050 */
2051 switch (hw->fc.requested_mode) {
2052 case ixgbe_fc_none:
2053 /* Flow control completely disabled by software override. */
2054 reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2055 break;
2056 case ixgbe_fc_rx_pause:
2057 /*
2058 * Rx Flow control is enabled and Tx Flow control is
2059 * disabled by software override. Since there really
2060 * isn't a way to advertise that we are capable of RX
2061 * Pause ONLY, we will advertise that we support both
2062 * symmetric and asymmetric Rx PAUSE. Later, we will
2063 * disable the adapter's ability to send PAUSE frames.
2064 */
2065 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2066 break;
2067 case ixgbe_fc_tx_pause:
2068 /*
2069 * Tx Flow control is enabled, and Rx Flow control is
2070 * disabled by software override.
2071 */
2072 reg |= (IXGBE_AUTOC_ASM_PAUSE);
2073 reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
2074 break;
2075 case ixgbe_fc_full:
2076 /* Flow control (both Rx and Tx) is enabled by SW override. */
2077 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2078 break;
2079#ifdef CONFIG_DCB
2080 case ixgbe_fc_pfc:
2081 goto out;
2082 break;
2083#endif /* CONFIG_DCB */
2084 default:
2085 hw_dbg(hw, "Flow control param set incorrectly\n");
2086 ret_val = IXGBE_ERR_CONFIG;
2087 goto out;
2088 break;
2089 }
2090 /*
2091 * AUTOC restart handles negotiation of 1G and 10G. There is
2092 * no need to set the PCS1GCTL register.
2093 */
2094 reg |= IXGBE_AUTOC_AN_RESTART;
2095 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
2096 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
2097
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002098out:
2099 return ret_val;
2100}
2101
2102/**
Auke Kok9a799d72007-09-15 14:07:45 -07002103 * ixgbe_disable_pcie_master - Disable PCI-express master access
2104 * @hw: pointer to hardware structure
2105 *
2106 * Disables PCI-Express master access and verifies there are no pending
2107 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2108 * bit hasn't caused the master requests to be disabled, else 0
2109 * is returned signifying master requests disabled.
2110 **/
2111s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2112{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002113 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002114 u32 i;
2115 u32 reg_val;
2116 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002117 s32 status = 0;
2118 u16 dev_status = 0;
2119
2120 /* Just jump out if bus mastering is already disabled */
2121 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2122 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002123
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002124 /* Disable the receive unit by stopping each queue */
2125 number_of_queues = hw->mac.max_rx_queues;
2126 for (i = 0; i < number_of_queues; i++) {
2127 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2128 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2129 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2130 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2131 }
2132 }
2133
2134 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2135 reg_val |= IXGBE_CTRL_GIO_DIS;
2136 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002137
2138 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002139 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2140 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002141 udelay(100);
2142 }
2143
Emil Tantilova4297dc2011-02-14 08:45:13 +00002144 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2145 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2146
2147 /*
2148 * Before proceeding, make sure that the PCIe block does not have
2149 * transactions pending.
2150 */
2151check_device_status:
2152 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2153 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2154 &dev_status);
2155 if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2156 break;
2157 udelay(100);
2158 }
2159
2160 if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
2161 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2162 else
2163 goto out;
2164
2165 /*
2166 * Two consecutive resets are required via CTRL.RST per datasheet
2167 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2168 * of this need. The first reset prevents new master requests from
2169 * being issued by our device. We then must wait 1usec for any
2170 * remaining completions from the PCIe bus to trickle in, and then reset
2171 * again to clear out any effects they may have had on our device.
2172 */
2173 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2174
2175out:
Auke Kok9a799d72007-09-15 14:07:45 -07002176 return status;
2177}
2178
2179
2180/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002181 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002182 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002183 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002184 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002185 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002186 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2187 **/
2188s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2189{
2190 u32 gssr;
2191 u32 swmask = mask;
2192 u32 fwmask = mask << 5;
2193 s32 timeout = 200;
2194
2195 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002196 /*
2197 * SW EEPROM semaphore bit is used for access to all
2198 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2199 */
Auke Kok9a799d72007-09-15 14:07:45 -07002200 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002201 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002202
2203 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2204 if (!(gssr & (fwmask | swmask)))
2205 break;
2206
2207 /*
2208 * Firmware currently using resource (fwmask) or other software
2209 * thread currently using resource (swmask)
2210 */
2211 ixgbe_release_eeprom_semaphore(hw);
2212 msleep(5);
2213 timeout--;
2214 }
2215
2216 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002217 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002218 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002219 }
2220
2221 gssr |= swmask;
2222 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2223
2224 ixgbe_release_eeprom_semaphore(hw);
2225 return 0;
2226}
2227
2228/**
2229 * ixgbe_release_swfw_sync - Release SWFW semaphore
2230 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002231 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002232 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002233 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002234 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2235 **/
2236void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2237{
2238 u32 gssr;
2239 u32 swmask = mask;
2240
2241 ixgbe_get_eeprom_semaphore(hw);
2242
2243 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2244 gssr &= ~swmask;
2245 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2246
2247 ixgbe_release_eeprom_semaphore(hw);
2248}
2249
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002250/**
2251 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2252 * @hw: pointer to hardware structure
2253 * @regval: register value to write to RXCTRL
2254 *
2255 * Enables the Rx DMA unit
2256 **/
2257s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2258{
2259 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2260
2261 return 0;
2262}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002263
2264/**
2265 * ixgbe_blink_led_start_generic - Blink LED based on index.
2266 * @hw: pointer to hardware structure
2267 * @index: led number to blink
2268 **/
2269s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2270{
2271 ixgbe_link_speed speed = 0;
2272 bool link_up = 0;
2273 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2274 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2275
2276 /*
2277 * Link must be up to auto-blink the LEDs;
2278 * Force it if link is down.
2279 */
2280 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2281
2282 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002283 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002284 autoc_reg |= IXGBE_AUTOC_FLU;
2285 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2286 msleep(10);
2287 }
2288
2289 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2290 led_reg |= IXGBE_LED_BLINK(index);
2291 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2292 IXGBE_WRITE_FLUSH(hw);
2293
2294 return 0;
2295}
2296
2297/**
2298 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2299 * @hw: pointer to hardware structure
2300 * @index: led number to stop blinking
2301 **/
2302s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2303{
2304 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2305 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2306
2307 autoc_reg &= ~IXGBE_AUTOC_FLU;
2308 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2309 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2310
2311 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2312 led_reg &= ~IXGBE_LED_BLINK(index);
2313 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2314 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2315 IXGBE_WRITE_FLUSH(hw);
2316
2317 return 0;
2318}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002319
2320/**
2321 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2322 * @hw: pointer to hardware structure
2323 * @san_mac_offset: SAN MAC address offset
2324 *
2325 * This function will read the EEPROM location for the SAN MAC address
2326 * pointer, and returns the value at that location. This is used in both
2327 * get and set mac_addr routines.
2328 **/
2329static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2330 u16 *san_mac_offset)
2331{
2332 /*
2333 * First read the EEPROM pointer to see if the MAC addresses are
2334 * available.
2335 */
2336 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2337
2338 return 0;
2339}
2340
2341/**
2342 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2343 * @hw: pointer to hardware structure
2344 * @san_mac_addr: SAN MAC address
2345 *
2346 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2347 * per-port, so set_lan_id() must be called before reading the addresses.
2348 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2349 * upon for non-SFP connections, so we must call it here.
2350 **/
2351s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2352{
2353 u16 san_mac_data, san_mac_offset;
2354 u8 i;
2355
2356 /*
2357 * First read the EEPROM pointer to see if the MAC addresses are
2358 * available. If they're not, no point in calling set_lan_id() here.
2359 */
2360 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2361
2362 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2363 /*
2364 * No addresses available in this EEPROM. It's not an
2365 * error though, so just wipe the local address and return.
2366 */
2367 for (i = 0; i < 6; i++)
2368 san_mac_addr[i] = 0xFF;
2369
2370 goto san_mac_addr_out;
2371 }
2372
2373 /* make sure we know which port we need to program */
2374 hw->mac.ops.set_lan_id(hw);
2375 /* apply the port offset to the address offset */
2376 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2377 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2378 for (i = 0; i < 3; i++) {
2379 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2380 san_mac_addr[i * 2] = (u8)(san_mac_data);
2381 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2382 san_mac_offset++;
2383 }
2384
2385san_mac_addr_out:
2386 return 0;
2387}
2388
2389/**
2390 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2391 * @hw: pointer to hardware structure
2392 *
2393 * Read PCIe configuration space, and get the MSI-X vector count from
2394 * the capabilities table.
2395 **/
2396u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2397{
2398 struct ixgbe_adapter *adapter = hw->back;
2399 u16 msix_count;
2400 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2401 &msix_count);
2402 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2403
2404 /* MSI-X count is zero-based in HW, so increment to give proper value */
2405 msix_count++;
2406
2407 return msix_count;
2408}
2409
2410/**
2411 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2412 * @hw: pointer to hardware struct
2413 * @rar: receive address register index to disassociate
2414 * @vmdq: VMDq pool index to remove from the rar
2415 **/
2416s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2417{
2418 u32 mpsar_lo, mpsar_hi;
2419 u32 rar_entries = hw->mac.num_rar_entries;
2420
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002421 /* Make sure we are using a valid rar index range */
2422 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002423 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002424 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002425 }
2426
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002427 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2428 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2429
2430 if (!mpsar_lo && !mpsar_hi)
2431 goto done;
2432
2433 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2434 if (mpsar_lo) {
2435 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2436 mpsar_lo = 0;
2437 }
2438 if (mpsar_hi) {
2439 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2440 mpsar_hi = 0;
2441 }
2442 } else if (vmdq < 32) {
2443 mpsar_lo &= ~(1 << vmdq);
2444 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2445 } else {
2446 mpsar_hi &= ~(1 << (vmdq - 32));
2447 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2448 }
2449
2450 /* was that the last pool using this rar? */
2451 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2452 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002453done:
2454 return 0;
2455}
2456
2457/**
2458 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2459 * @hw: pointer to hardware struct
2460 * @rar: receive address register index to associate with a VMDq index
2461 * @vmdq: VMDq pool index
2462 **/
2463s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2464{
2465 u32 mpsar;
2466 u32 rar_entries = hw->mac.num_rar_entries;
2467
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002468 /* Make sure we are using a valid rar index range */
2469 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002470 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002471 return IXGBE_ERR_INVALID_ARGUMENT;
2472 }
2473
2474 if (vmdq < 32) {
2475 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2476 mpsar |= 1 << vmdq;
2477 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2478 } else {
2479 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2480 mpsar |= 1 << (vmdq - 32);
2481 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002482 }
2483 return 0;
2484}
2485
2486/**
2487 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2488 * @hw: pointer to hardware structure
2489 **/
2490s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2491{
2492 int i;
2493
2494
2495 for (i = 0; i < 128; i++)
2496 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2497
2498 return 0;
2499}
2500
2501/**
2502 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2503 * @hw: pointer to hardware structure
2504 * @vlan: VLAN id to write to VLAN filter
2505 *
2506 * return the VLVF index where this VLAN id should be placed
2507 *
2508 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002509static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002510{
2511 u32 bits = 0;
2512 u32 first_empty_slot = 0;
2513 s32 regindex;
2514
2515 /* short cut the special case */
2516 if (vlan == 0)
2517 return 0;
2518
2519 /*
2520 * Search for the vlan id in the VLVF entries. Save off the first empty
2521 * slot found along the way
2522 */
2523 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2524 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2525 if (!bits && !(first_empty_slot))
2526 first_empty_slot = regindex;
2527 else if ((bits & 0x0FFF) == vlan)
2528 break;
2529 }
2530
2531 /*
2532 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2533 * in the VLVF. Else use the first empty VLVF register for this
2534 * vlan id.
2535 */
2536 if (regindex >= IXGBE_VLVF_ENTRIES) {
2537 if (first_empty_slot)
2538 regindex = first_empty_slot;
2539 else {
2540 hw_dbg(hw, "No space in VLVF.\n");
2541 regindex = IXGBE_ERR_NO_SPACE;
2542 }
2543 }
2544
2545 return regindex;
2546}
2547
2548/**
2549 * ixgbe_set_vfta_generic - Set VLAN filter table
2550 * @hw: pointer to hardware structure
2551 * @vlan: VLAN id to write to VLAN filter
2552 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2553 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2554 *
2555 * Turn on/off specified VLAN in the VLAN filter table.
2556 **/
2557s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2558 bool vlan_on)
2559{
2560 s32 regindex;
2561 u32 bitindex;
2562 u32 vfta;
2563 u32 bits;
2564 u32 vt;
2565 u32 targetbit;
2566 bool vfta_changed = false;
2567
2568 if (vlan > 4095)
2569 return IXGBE_ERR_PARAM;
2570
2571 /*
2572 * this is a 2 part operation - first the VFTA, then the
2573 * VLVF and VLVFB if VT Mode is set
2574 * We don't write the VFTA until we know the VLVF part succeeded.
2575 */
2576
2577 /* Part 1
2578 * The VFTA is a bitstring made up of 128 32-bit registers
2579 * that enable the particular VLAN id, much like the MTA:
2580 * bits[11-5]: which register
2581 * bits[4-0]: which bit in the register
2582 */
2583 regindex = (vlan >> 5) & 0x7F;
2584 bitindex = vlan & 0x1F;
2585 targetbit = (1 << bitindex);
2586 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2587
2588 if (vlan_on) {
2589 if (!(vfta & targetbit)) {
2590 vfta |= targetbit;
2591 vfta_changed = true;
2592 }
2593 } else {
2594 if ((vfta & targetbit)) {
2595 vfta &= ~targetbit;
2596 vfta_changed = true;
2597 }
2598 }
2599
2600 /* Part 2
2601 * If VT Mode is set
2602 * Either vlan_on
2603 * make sure the vlan is in VLVF
2604 * set the vind bit in the matching VLVFB
2605 * Or !vlan_on
2606 * clear the pool bit and possibly the vind
2607 */
2608 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2609 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2610 s32 vlvf_index;
2611
2612 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2613 if (vlvf_index < 0)
2614 return vlvf_index;
2615
2616 if (vlan_on) {
2617 /* set the pool bit */
2618 if (vind < 32) {
2619 bits = IXGBE_READ_REG(hw,
2620 IXGBE_VLVFB(vlvf_index*2));
2621 bits |= (1 << vind);
2622 IXGBE_WRITE_REG(hw,
2623 IXGBE_VLVFB(vlvf_index*2),
2624 bits);
2625 } else {
2626 bits = IXGBE_READ_REG(hw,
2627 IXGBE_VLVFB((vlvf_index*2)+1));
2628 bits |= (1 << (vind-32));
2629 IXGBE_WRITE_REG(hw,
2630 IXGBE_VLVFB((vlvf_index*2)+1),
2631 bits);
2632 }
2633 } else {
2634 /* clear the pool bit */
2635 if (vind < 32) {
2636 bits = IXGBE_READ_REG(hw,
2637 IXGBE_VLVFB(vlvf_index*2));
2638 bits &= ~(1 << vind);
2639 IXGBE_WRITE_REG(hw,
2640 IXGBE_VLVFB(vlvf_index*2),
2641 bits);
2642 bits |= IXGBE_READ_REG(hw,
2643 IXGBE_VLVFB((vlvf_index*2)+1));
2644 } else {
2645 bits = IXGBE_READ_REG(hw,
2646 IXGBE_VLVFB((vlvf_index*2)+1));
2647 bits &= ~(1 << (vind-32));
2648 IXGBE_WRITE_REG(hw,
2649 IXGBE_VLVFB((vlvf_index*2)+1),
2650 bits);
2651 bits |= IXGBE_READ_REG(hw,
2652 IXGBE_VLVFB(vlvf_index*2));
2653 }
2654 }
2655
2656 /*
2657 * If there are still bits set in the VLVFB registers
2658 * for the VLAN ID indicated we need to see if the
2659 * caller is requesting that we clear the VFTA entry bit.
2660 * If the caller has requested that we clear the VFTA
2661 * entry bit but there are still pools/VFs using this VLAN
2662 * ID entry then ignore the request. We're not worried
2663 * about the case where we're turning the VFTA VLAN ID
2664 * entry bit on, only when requested to turn it off as
2665 * there may be multiple pools and/or VFs using the
2666 * VLAN ID entry. In that case we cannot clear the
2667 * VFTA bit until all pools/VFs using that VLAN ID have also
2668 * been cleared. This will be indicated by "bits" being
2669 * zero.
2670 */
2671 if (bits) {
2672 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2673 (IXGBE_VLVF_VIEN | vlan));
2674 if (!vlan_on) {
2675 /* someone wants to clear the vfta entry
2676 * but some pools/VFs are still using it.
2677 * Ignore it. */
2678 vfta_changed = false;
2679 }
2680 }
2681 else
2682 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
2683 }
2684
2685 if (vfta_changed)
2686 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
2687
2688 return 0;
2689}
2690
2691/**
2692 * ixgbe_clear_vfta_generic - Clear VLAN filter table
2693 * @hw: pointer to hardware structure
2694 *
2695 * Clears the VLAN filer table, and the VMDq index associated with the filter
2696 **/
2697s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
2698{
2699 u32 offset;
2700
2701 for (offset = 0; offset < hw->mac.vft_size; offset++)
2702 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
2703
2704 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
2705 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
2706 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
2707 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
2708 }
2709
2710 return 0;
2711}
2712
2713/**
2714 * ixgbe_check_mac_link_generic - Determine link and speed status
2715 * @hw: pointer to hardware structure
2716 * @speed: pointer to link speed
2717 * @link_up: true when link is up
2718 * @link_up_wait_to_complete: bool used to wait for link up or not
2719 *
2720 * Reads the links register to determine if link is up and the current speed
2721 **/
2722s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
2723 bool *link_up, bool link_up_wait_to_complete)
2724{
Emil Tantilov48de36c2011-02-16 01:38:08 +00002725 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002726 u32 i;
2727
Emil Tantilov48de36c2011-02-16 01:38:08 +00002728 /* clear the old state */
2729 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
2730
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002731 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00002732
2733 if (links_orig != links_reg) {
2734 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
2735 links_orig, links_reg);
2736 }
2737
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002738 if (link_up_wait_to_complete) {
2739 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2740 if (links_reg & IXGBE_LINKS_UP) {
2741 *link_up = true;
2742 break;
2743 } else {
2744 *link_up = false;
2745 }
2746 msleep(100);
2747 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2748 }
2749 } else {
2750 if (links_reg & IXGBE_LINKS_UP)
2751 *link_up = true;
2752 else
2753 *link_up = false;
2754 }
2755
2756 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2757 IXGBE_LINKS_SPEED_10G_82599)
2758 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2759 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2760 IXGBE_LINKS_SPEED_1G_82599)
2761 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2762 else
2763 *speed = IXGBE_LINK_SPEED_100_FULL;
2764
2765 /* if link is down, zero out the current_mode */
2766 if (*link_up == false) {
2767 hw->fc.current_mode = ixgbe_fc_none;
2768 hw->fc.fc_was_autonegged = false;
2769 }
2770
2771 return 0;
2772}
Don Skidmorea391f1d2010-11-16 19:27:15 -08002773
2774/**
2775 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
2776 * the EEPROM
2777 * @hw: pointer to hardware structure
2778 * @wwnn_prefix: the alternative WWNN prefix
2779 * @wwpn_prefix: the alternative WWPN prefix
2780 *
2781 * This function will read the EEPROM from the alternative SAN MAC address
2782 * block to check the support for the alternative WWNN/WWPN prefix support.
2783 **/
2784s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2785 u16 *wwpn_prefix)
2786{
2787 u16 offset, caps;
2788 u16 alt_san_mac_blk_offset;
2789
2790 /* clear output first */
2791 *wwnn_prefix = 0xFFFF;
2792 *wwpn_prefix = 0xFFFF;
2793
2794 /* check if alternative SAN MAC is supported */
2795 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2796 &alt_san_mac_blk_offset);
2797
2798 if ((alt_san_mac_blk_offset == 0) ||
2799 (alt_san_mac_blk_offset == 0xFFFF))
2800 goto wwn_prefix_out;
2801
2802 /* check capability in alternative san mac address block */
2803 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2804 hw->eeprom.ops.read(hw, offset, &caps);
2805 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2806 goto wwn_prefix_out;
2807
2808 /* get the corresponding prefix for WWNN/WWPN */
2809 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2810 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2811
2812 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2813 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2814
2815wwn_prefix_out:
2816 return 0;
2817}
Greg Rosea985b6c32010-11-18 03:02:52 +00002818
2819/**
2820 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2821 * @hw: pointer to hardware structure
2822 * @enable: enable or disable switch for anti-spoofing
2823 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
2824 *
2825 **/
2826void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
2827{
2828 int j;
2829 int pf_target_reg = pf >> 3;
2830 int pf_target_shift = pf % 8;
2831 u32 pfvfspoof = 0;
2832
2833 if (hw->mac.type == ixgbe_mac_82598EB)
2834 return;
2835
2836 if (enable)
2837 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
2838
2839 /*
2840 * PFVFSPOOF register array is size 8 with 8 bits assigned to
2841 * MAC anti-spoof enables in each register array element.
2842 */
2843 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
2844 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
2845
2846 /* If not enabling anti-spoofing then done */
2847 if (!enable)
2848 return;
2849
2850 /*
2851 * The PF should be allowed to spoof so that it can support
2852 * emulation mode NICs. Reset the bit assigned to the PF
2853 */
2854 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
2855 pfvfspoof ^= (1 << pf_target_shift);
2856 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
2857}
2858
2859/**
2860 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
2861 * @hw: pointer to hardware structure
2862 * @enable: enable or disable switch for VLAN anti-spoofing
2863 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
2864 *
2865 **/
2866void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
2867{
2868 int vf_target_reg = vf >> 3;
2869 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
2870 u32 pfvfspoof;
2871
2872 if (hw->mac.type == ixgbe_mac_82598EB)
2873 return;
2874
2875 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2876 if (enable)
2877 pfvfspoof |= (1 << vf_target_shift);
2878 else
2879 pfvfspoof &= ~(1 << vf_target_shift);
2880 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2881}