blob: 85cc3014373833c847ddcb1e3db58452d35df5ab [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
Jiri Pirkoccffad22009-05-22 23:22:17 +000031#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_common.h"
35#include "ixgbe_phy.h"
36
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070037static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070040static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Don Skidmore7b25cdb2009-08-25 04:47:32 +000050static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
Auke Kok9a799d72007-09-15 14:07:45 -070051
52/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070053 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070054 * @hw: pointer to hardware structure
55 *
56 * Starts the hardware by filling the bus info structure and media type, clears
57 * all on chip counters, initializes receive address registers, multicast
58 * table, VLAN filter table, calls routine to set up link and flow control
59 * settings, and leaves transmit and receive units disabled and uninitialized
60 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070061s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070062{
63 u32 ctrl_ext;
64
65 /* Set the media type */
66 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
67
68 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070069 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070070
Auke Kok9a799d72007-09-15 14:07:45 -070071 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070072 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070073
Auke Kok9a799d72007-09-15 14:07:45 -070074 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070075 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070076
77 /* Set No Snoop Disable */
78 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
79 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
80 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070081 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070082
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000083 /* Setup flow control */
84 ixgbe_setup_fc(hw, 0);
85
Auke Kok9a799d72007-09-15 14:07:45 -070086 /* Clear adapter stopped flag */
87 hw->adapter_stopped = false;
88
89 return 0;
90}
91
92/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070093 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -070094 * @hw: pointer to hardware structure
95 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070096 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -070097 * structure and media type, clears all on chip counters, initializes receive
98 * address registers, multicast table, VLAN filter table, calls routine to set
99 * up link and flow control settings, and leaves transmit and receive units
100 * disabled and uninitialized
101 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700102s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700103{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000104 s32 status;
105
Auke Kok9a799d72007-09-15 14:07:45 -0700106 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000107 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700108
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000109 if (status == 0) {
110 /* Start the HW */
111 status = hw->mac.ops.start_hw(hw);
112 }
Auke Kok9a799d72007-09-15 14:07:45 -0700113
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000114 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700115}
116
117/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700118 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700119 * @hw: pointer to hardware structure
120 *
121 * Clears all hardware statistics counters by reading them from the hardware
122 * Statistics counters are clear on read.
123 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700124s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700125{
126 u16 i = 0;
127
128 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
129 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
130 IXGBE_READ_REG(hw, IXGBE_ERRBC);
131 IXGBE_READ_REG(hw, IXGBE_MSPDC);
132 for (i = 0; i < 8; i++)
133 IXGBE_READ_REG(hw, IXGBE_MPC(i));
134
135 IXGBE_READ_REG(hw, IXGBE_MLFC);
136 IXGBE_READ_REG(hw, IXGBE_MRFC);
137 IXGBE_READ_REG(hw, IXGBE_RLEC);
138 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Auke Kok9a799d72007-09-15 14:07:45 -0700139 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Emil Tantilov667c7562011-02-26 06:40:05 +0000140 if (hw->mac.type >= ixgbe_mac_82599EB) {
141 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
142 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
143 } else {
144 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
145 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
146 }
Auke Kok9a799d72007-09-15 14:07:45 -0700147
148 for (i = 0; i < 8; i++) {
149 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700150 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000151 if (hw->mac.type >= ixgbe_mac_82599EB) {
152 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
153 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
154 } else {
155 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
156 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
157 }
Auke Kok9a799d72007-09-15 14:07:45 -0700158 }
Emil Tantilov667c7562011-02-26 06:40:05 +0000159 if (hw->mac.type >= ixgbe_mac_82599EB)
160 for (i = 0; i < 8; i++)
161 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700162 IXGBE_READ_REG(hw, IXGBE_PRC64);
163 IXGBE_READ_REG(hw, IXGBE_PRC127);
164 IXGBE_READ_REG(hw, IXGBE_PRC255);
165 IXGBE_READ_REG(hw, IXGBE_PRC511);
166 IXGBE_READ_REG(hw, IXGBE_PRC1023);
167 IXGBE_READ_REG(hw, IXGBE_PRC1522);
168 IXGBE_READ_REG(hw, IXGBE_GPRC);
169 IXGBE_READ_REG(hw, IXGBE_BPRC);
170 IXGBE_READ_REG(hw, IXGBE_MPRC);
171 IXGBE_READ_REG(hw, IXGBE_GPTC);
172 IXGBE_READ_REG(hw, IXGBE_GORCL);
173 IXGBE_READ_REG(hw, IXGBE_GORCH);
174 IXGBE_READ_REG(hw, IXGBE_GOTCL);
175 IXGBE_READ_REG(hw, IXGBE_GOTCH);
176 for (i = 0; i < 8; i++)
177 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
178 IXGBE_READ_REG(hw, IXGBE_RUC);
179 IXGBE_READ_REG(hw, IXGBE_RFC);
180 IXGBE_READ_REG(hw, IXGBE_ROC);
181 IXGBE_READ_REG(hw, IXGBE_RJC);
182 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
183 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
184 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
185 IXGBE_READ_REG(hw, IXGBE_TORL);
186 IXGBE_READ_REG(hw, IXGBE_TORH);
187 IXGBE_READ_REG(hw, IXGBE_TPR);
188 IXGBE_READ_REG(hw, IXGBE_TPT);
189 IXGBE_READ_REG(hw, IXGBE_PTC64);
190 IXGBE_READ_REG(hw, IXGBE_PTC127);
191 IXGBE_READ_REG(hw, IXGBE_PTC255);
192 IXGBE_READ_REG(hw, IXGBE_PTC511);
193 IXGBE_READ_REG(hw, IXGBE_PTC1023);
194 IXGBE_READ_REG(hw, IXGBE_PTC1522);
195 IXGBE_READ_REG(hw, IXGBE_MPTC);
196 IXGBE_READ_REG(hw, IXGBE_BPTC);
197 for (i = 0; i < 16; i++) {
198 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700199 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000200 if (hw->mac.type >= ixgbe_mac_82599EB) {
201 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
202 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
203 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
204 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
205 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
206 } else {
207 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
208 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
209 }
Auke Kok9a799d72007-09-15 14:07:45 -0700210 }
211
212 return 0;
213}
214
215/**
Don Skidmore289700db2010-12-03 03:32:58 +0000216 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700217 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000218 * @pba_num: stores the part number string from the EEPROM
219 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700220 *
Don Skidmore289700db2010-12-03 03:32:58 +0000221 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700222 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000223s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
224 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700225{
226 s32 ret_val;
227 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000228 u16 pba_ptr;
229 u16 offset;
230 u16 length;
231
232 if (pba_num == NULL) {
233 hw_dbg(hw, "PBA string buffer was null\n");
234 return IXGBE_ERR_INVALID_ARGUMENT;
235 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700236
237 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
238 if (ret_val) {
239 hw_dbg(hw, "NVM Read Error\n");
240 return ret_val;
241 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700242
Don Skidmore289700db2010-12-03 03:32:58 +0000243 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700244 if (ret_val) {
245 hw_dbg(hw, "NVM Read Error\n");
246 return ret_val;
247 }
Don Skidmore289700db2010-12-03 03:32:58 +0000248
249 /*
250 * if data is not ptr guard the PBA must be in legacy format which
251 * means pba_ptr is actually our second data word for the PBA number
252 * and we can decode it into an ascii string
253 */
254 if (data != IXGBE_PBANUM_PTR_GUARD) {
255 hw_dbg(hw, "NVM PBA number is not stored as string\n");
256
257 /* we will need 11 characters to store the PBA */
258 if (pba_num_size < 11) {
259 hw_dbg(hw, "PBA string buffer too small\n");
260 return IXGBE_ERR_NO_SPACE;
261 }
262
263 /* extract hex string from data and pba_ptr */
264 pba_num[0] = (data >> 12) & 0xF;
265 pba_num[1] = (data >> 8) & 0xF;
266 pba_num[2] = (data >> 4) & 0xF;
267 pba_num[3] = data & 0xF;
268 pba_num[4] = (pba_ptr >> 12) & 0xF;
269 pba_num[5] = (pba_ptr >> 8) & 0xF;
270 pba_num[6] = '-';
271 pba_num[7] = 0;
272 pba_num[8] = (pba_ptr >> 4) & 0xF;
273 pba_num[9] = pba_ptr & 0xF;
274
275 /* put a null character on the end of our string */
276 pba_num[10] = '\0';
277
278 /* switch all the data but the '-' to hex char */
279 for (offset = 0; offset < 10; offset++) {
280 if (pba_num[offset] < 0xA)
281 pba_num[offset] += '0';
282 else if (pba_num[offset] < 0x10)
283 pba_num[offset] += 'A' - 0xA;
284 }
285
286 return 0;
287 }
288
289 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
290 if (ret_val) {
291 hw_dbg(hw, "NVM Read Error\n");
292 return ret_val;
293 }
294
295 if (length == 0xFFFF || length == 0) {
296 hw_dbg(hw, "NVM PBA number section invalid length\n");
297 return IXGBE_ERR_PBA_SECTION;
298 }
299
300 /* check if pba_num buffer is big enough */
301 if (pba_num_size < (((u32)length * 2) - 1)) {
302 hw_dbg(hw, "PBA string buffer too small\n");
303 return IXGBE_ERR_NO_SPACE;
304 }
305
306 /* trim pba length from start of string */
307 pba_ptr++;
308 length--;
309
310 for (offset = 0; offset < length; offset++) {
311 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
312 if (ret_val) {
313 hw_dbg(hw, "NVM Read Error\n");
314 return ret_val;
315 }
316 pba_num[offset * 2] = (u8)(data >> 8);
317 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
318 }
319 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700320
321 return 0;
322}
323
324/**
325 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700326 * @hw: pointer to hardware structure
327 * @mac_addr: Adapter MAC address
328 *
329 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
330 * A reset of the adapter must be performed prior to calling this function
331 * in order for the MAC address to have been loaded from the EEPROM into RAR0
332 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700333s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700334{
335 u32 rar_high;
336 u32 rar_low;
337 u16 i;
338
339 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
340 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
341
342 for (i = 0; i < 4; i++)
343 mac_addr[i] = (u8)(rar_low >> (i*8));
344
345 for (i = 0; i < 2; i++)
346 mac_addr[i+4] = (u8)(rar_high >> (i*8));
347
348 return 0;
349}
350
Auke Kok9a799d72007-09-15 14:07:45 -0700351/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000352 * ixgbe_get_bus_info_generic - Generic set PCI bus info
353 * @hw: pointer to hardware structure
354 *
355 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
356 **/
357s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
358{
359 struct ixgbe_adapter *adapter = hw->back;
360 struct ixgbe_mac_info *mac = &hw->mac;
361 u16 link_status;
362
363 hw->bus.type = ixgbe_bus_type_pci_express;
364
365 /* Get the negotiated link width and speed from PCI config space */
366 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
367 &link_status);
368
369 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
370 case IXGBE_PCI_LINK_WIDTH_1:
371 hw->bus.width = ixgbe_bus_width_pcie_x1;
372 break;
373 case IXGBE_PCI_LINK_WIDTH_2:
374 hw->bus.width = ixgbe_bus_width_pcie_x2;
375 break;
376 case IXGBE_PCI_LINK_WIDTH_4:
377 hw->bus.width = ixgbe_bus_width_pcie_x4;
378 break;
379 case IXGBE_PCI_LINK_WIDTH_8:
380 hw->bus.width = ixgbe_bus_width_pcie_x8;
381 break;
382 default:
383 hw->bus.width = ixgbe_bus_width_unknown;
384 break;
385 }
386
387 switch (link_status & IXGBE_PCI_LINK_SPEED) {
388 case IXGBE_PCI_LINK_SPEED_2500:
389 hw->bus.speed = ixgbe_bus_speed_2500;
390 break;
391 case IXGBE_PCI_LINK_SPEED_5000:
392 hw->bus.speed = ixgbe_bus_speed_5000;
393 break;
394 default:
395 hw->bus.speed = ixgbe_bus_speed_unknown;
396 break;
397 }
398
399 mac->ops.set_lan_id(hw);
400
401 return 0;
402}
403
404/**
405 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
406 * @hw: pointer to the HW structure
407 *
408 * Determines the LAN function id by reading memory-mapped registers
409 * and swaps the port value if requested.
410 **/
411void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
412{
413 struct ixgbe_bus_info *bus = &hw->bus;
414 u32 reg;
415
416 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
417 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
418 bus->lan_id = bus->func;
419
420 /* check for a port swap */
421 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
422 if (reg & IXGBE_FACTPS_LFS)
423 bus->func ^= 0x1;
424}
425
426/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700427 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700428 * @hw: pointer to hardware structure
429 *
430 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
431 * disables transmit and receive units. The adapter_stopped flag is used by
432 * the shared code and drivers to determine if the adapter is in a stopped
433 * state and should not touch the hardware.
434 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700435s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700436{
437 u32 number_of_queues;
438 u32 reg_val;
439 u16 i;
440
441 /*
442 * Set the adapter_stopped flag so other driver functions stop touching
443 * the hardware
444 */
445 hw->adapter_stopped = true;
446
447 /* Disable the receive unit */
448 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
449 reg_val &= ~(IXGBE_RXCTRL_RXEN);
450 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700451 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700452 msleep(2);
453
454 /* Clear interrupt mask to stop from interrupts being generated */
455 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
456
457 /* Clear any pending interrupts */
458 IXGBE_READ_REG(hw, IXGBE_EICR);
459
460 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700461 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700462 for (i = 0; i < number_of_queues; i++) {
463 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
464 if (reg_val & IXGBE_TXDCTL_ENABLE) {
465 reg_val &= ~IXGBE_TXDCTL_ENABLE;
466 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
467 }
468 }
469
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700470 /*
471 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
472 * access and verify no pending requests
473 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000474 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700475
Auke Kok9a799d72007-09-15 14:07:45 -0700476 return 0;
477}
478
479/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700480 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700481 * @hw: pointer to hardware structure
482 * @index: led number to turn on
483 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700484s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700485{
486 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
487
488 /* To turn on the LED, set mode to ON. */
489 led_reg &= ~IXGBE_LED_MODE_MASK(index);
490 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
491 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700492 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700493
494 return 0;
495}
496
497/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700498 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700499 * @hw: pointer to hardware structure
500 * @index: led number to turn off
501 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700502s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700503{
504 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
505
506 /* To turn off the LED, set mode to OFF. */
507 led_reg &= ~IXGBE_LED_MODE_MASK(index);
508 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
509 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700510 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700511
512 return 0;
513}
514
Auke Kok9a799d72007-09-15 14:07:45 -0700515/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700516 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700517 * @hw: pointer to hardware structure
518 *
519 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
520 * ixgbe_hw struct in order to set up EEPROM access.
521 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700522s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700523{
524 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
525 u32 eec;
526 u16 eeprom_size;
527
528 if (eeprom->type == ixgbe_eeprom_uninitialized) {
529 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700530 /* Set default semaphore delay to 10ms which is a well
531 * tested value */
532 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700533
534 /*
535 * Check for EEPROM present first.
536 * If not present leave as none
537 */
538 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
539 if (eec & IXGBE_EEC_PRES) {
540 eeprom->type = ixgbe_eeprom_spi;
541
542 /*
543 * SPI EEPROM is assumed here. This code would need to
544 * change if a future EEPROM is not SPI.
545 */
546 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
547 IXGBE_EEC_SIZE_SHIFT);
548 eeprom->word_size = 1 << (eeprom_size +
549 IXGBE_EEPROM_WORD_SIZE_SHIFT);
550 }
551
552 if (eec & IXGBE_EEC_ADDR_SIZE)
553 eeprom->address_bits = 16;
554 else
555 eeprom->address_bits = 8;
556 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
557 "%d\n", eeprom->type, eeprom->word_size,
558 eeprom->address_bits);
559 }
560
561 return 0;
562}
563
564/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000565 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
566 * @hw: pointer to hardware structure
567 * @offset: offset within the EEPROM to be written to
568 * @data: 16 bit word to be written to the EEPROM
569 *
570 * If ixgbe_eeprom_update_checksum is not called after this function, the
571 * EEPROM will most likely contain an invalid checksum.
572 **/
573s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
574{
575 s32 status;
576 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
577
578 hw->eeprom.ops.init_params(hw);
579
580 if (offset >= hw->eeprom.word_size) {
581 status = IXGBE_ERR_EEPROM;
582 goto out;
583 }
584
585 /* Prepare the EEPROM for writing */
586 status = ixgbe_acquire_eeprom(hw);
587
588 if (status == 0) {
589 if (ixgbe_ready_eeprom(hw) != 0) {
590 ixgbe_release_eeprom(hw);
591 status = IXGBE_ERR_EEPROM;
592 }
593 }
594
595 if (status == 0) {
596 ixgbe_standby_eeprom(hw);
597
598 /* Send the WRITE ENABLE command (8 bit opcode ) */
599 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
600 IXGBE_EEPROM_OPCODE_BITS);
601
602 ixgbe_standby_eeprom(hw);
603
604 /*
605 * Some SPI eeproms use the 8th address bit embedded in the
606 * opcode
607 */
608 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
609 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
610
611 /* Send the Write command (8-bit opcode + addr) */
612 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
613 IXGBE_EEPROM_OPCODE_BITS);
614 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
615 hw->eeprom.address_bits);
616
617 /* Send the data */
618 data = (data >> 8) | (data << 8);
619 ixgbe_shift_out_eeprom_bits(hw, data, 16);
620 ixgbe_standby_eeprom(hw);
621
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000622 /* Done with writing - release the EEPROM */
623 ixgbe_release_eeprom(hw);
624 }
625
626out:
627 return status;
628}
629
630/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700631 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
632 * @hw: pointer to hardware structure
633 * @offset: offset within the EEPROM to be read
634 * @data: read 16 bit value from EEPROM
635 *
636 * Reads 16 bit value from EEPROM through bit-bang method
637 **/
638s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
639 u16 *data)
640{
641 s32 status;
642 u16 word_in;
643 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
644
645 hw->eeprom.ops.init_params(hw);
646
647 if (offset >= hw->eeprom.word_size) {
648 status = IXGBE_ERR_EEPROM;
649 goto out;
650 }
651
652 /* Prepare the EEPROM for reading */
653 status = ixgbe_acquire_eeprom(hw);
654
655 if (status == 0) {
656 if (ixgbe_ready_eeprom(hw) != 0) {
657 ixgbe_release_eeprom(hw);
658 status = IXGBE_ERR_EEPROM;
659 }
660 }
661
662 if (status == 0) {
663 ixgbe_standby_eeprom(hw);
664
665 /*
666 * Some SPI eeproms use the 8th address bit embedded in the
667 * opcode
668 */
669 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
670 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
671
672 /* Send the READ command (opcode + addr) */
673 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
674 IXGBE_EEPROM_OPCODE_BITS);
675 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
676 hw->eeprom.address_bits);
677
678 /* Read the data. */
679 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
680 *data = (word_in >> 8) | (word_in << 8);
681
682 /* End this read operation */
683 ixgbe_release_eeprom(hw);
684 }
685
686out:
687 return status;
688}
689
690/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000691 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700692 * @hw: pointer to hardware structure
693 * @offset: offset of word in the EEPROM to read
694 * @data: word read from the EEPROM
695 *
696 * Reads a 16 bit word from the EEPROM using the EERD register.
697 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000698s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700699{
700 u32 eerd;
701 s32 status;
702
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700703 hw->eeprom.ops.init_params(hw);
704
705 if (offset >= hw->eeprom.word_size) {
706 status = IXGBE_ERR_EEPROM;
707 goto out;
708 }
709
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000710 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
711 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700712
713 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000714 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700715
716 if (status == 0)
717 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000718 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700719 else
720 hw_dbg(hw, "Eeprom read timed out\n");
721
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700722out:
Auke Kok9a799d72007-09-15 14:07:45 -0700723 return status;
724}
725
726/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000727 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700728 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000729 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700730 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000731 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
732 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700733 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800734s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700735{
736 u32 i;
737 u32 reg;
738 s32 status = IXGBE_ERR_EEPROM;
739
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000740 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
741 if (ee_reg == IXGBE_NVM_POLL_READ)
742 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
743 else
744 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
745
746 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700747 status = 0;
748 break;
749 }
750 udelay(5);
751 }
752 return status;
753}
754
755/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700756 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
757 * @hw: pointer to hardware structure
758 *
759 * Prepares EEPROM for access using bit-bang method. This function should
760 * be called before issuing a command to the EEPROM.
761 **/
762static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
763{
764 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000765 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700766 u32 i;
767
Don Skidmore5e655102011-02-25 01:58:04 +0000768 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700769 status = IXGBE_ERR_SWFW_SYNC;
770
771 if (status == 0) {
772 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
773
774 /* Request EEPROM Access */
775 eec |= IXGBE_EEC_REQ;
776 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
777
778 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
779 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
780 if (eec & IXGBE_EEC_GNT)
781 break;
782 udelay(5);
783 }
784
785 /* Release if grant not acquired */
786 if (!(eec & IXGBE_EEC_GNT)) {
787 eec &= ~IXGBE_EEC_REQ;
788 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
789 hw_dbg(hw, "Could not acquire EEPROM grant\n");
790
Don Skidmore5e655102011-02-25 01:58:04 +0000791 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700792 status = IXGBE_ERR_EEPROM;
793 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700794
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000795 /* Setup EEPROM for Read/Write */
796 if (status == 0) {
797 /* Clear CS and SK */
798 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
799 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
800 IXGBE_WRITE_FLUSH(hw);
801 udelay(1);
802 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700803 }
804 return status;
805}
806
807/**
Auke Kok9a799d72007-09-15 14:07:45 -0700808 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
809 * @hw: pointer to hardware structure
810 *
811 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
812 **/
813static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
814{
815 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000816 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700817 u32 i;
818 u32 swsm;
819
Auke Kok9a799d72007-09-15 14:07:45 -0700820 /* Get SMBI software semaphore between device drivers first */
821 for (i = 0; i < timeout; i++) {
822 /*
823 * If the SMBI bit is 0 when we read it, then the bit will be
824 * set and we have the semaphore
825 */
826 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
827 if (!(swsm & IXGBE_SWSM_SMBI)) {
828 status = 0;
829 break;
830 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000831 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700832 }
833
834 /* Now get the semaphore between SW/FW through the SWESMBI bit */
835 if (status == 0) {
836 for (i = 0; i < timeout; i++) {
837 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
838
839 /* Set the SW EEPROM semaphore bit to request access */
840 swsm |= IXGBE_SWSM_SWESMBI;
841 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
842
843 /*
844 * If we set the bit successfully then we got the
845 * semaphore.
846 */
847 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
848 if (swsm & IXGBE_SWSM_SWESMBI)
849 break;
850
851 udelay(50);
852 }
853
854 /*
855 * Release semaphores and return error if SW EEPROM semaphore
856 * was not granted because we don't have access to the EEPROM
857 */
858 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000859 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700860 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700861 ixgbe_release_eeprom_semaphore(hw);
862 status = IXGBE_ERR_EEPROM;
863 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000864 } else {
865 hw_dbg(hw, "Software semaphore SMBI between device drivers "
866 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700867 }
868
869 return status;
870}
871
872/**
873 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
874 * @hw: pointer to hardware structure
875 *
876 * This function clears hardware semaphore bits.
877 **/
878static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
879{
880 u32 swsm;
881
882 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
883
884 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
885 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
886 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700887 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700888}
889
890/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700891 * ixgbe_ready_eeprom - Polls for EEPROM ready
892 * @hw: pointer to hardware structure
893 **/
894static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
895{
896 s32 status = 0;
897 u16 i;
898 u8 spi_stat_reg;
899
900 /*
901 * Read "Status Register" repeatedly until the LSB is cleared. The
902 * EEPROM will signal that the command has been completed by clearing
903 * bit 0 of the internal status register. If it's not cleared within
904 * 5 milliseconds, then error out.
905 */
906 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
907 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
908 IXGBE_EEPROM_OPCODE_BITS);
909 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
910 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
911 break;
912
913 udelay(5);
914 ixgbe_standby_eeprom(hw);
915 };
916
917 /*
918 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
919 * devices (and only 0-5mSec on 5V devices)
920 */
921 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
922 hw_dbg(hw, "SPI EEPROM Status error\n");
923 status = IXGBE_ERR_EEPROM;
924 }
925
926 return status;
927}
928
929/**
930 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
931 * @hw: pointer to hardware structure
932 **/
933static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
934{
935 u32 eec;
936
937 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
938
939 /* Toggle CS to flush commands */
940 eec |= IXGBE_EEC_CS;
941 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
942 IXGBE_WRITE_FLUSH(hw);
943 udelay(1);
944 eec &= ~IXGBE_EEC_CS;
945 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
946 IXGBE_WRITE_FLUSH(hw);
947 udelay(1);
948}
949
950/**
951 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
952 * @hw: pointer to hardware structure
953 * @data: data to send to the EEPROM
954 * @count: number of bits to shift out
955 **/
956static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
957 u16 count)
958{
959 u32 eec;
960 u32 mask;
961 u32 i;
962
963 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
964
965 /*
966 * Mask is used to shift "count" bits of "data" out to the EEPROM
967 * one bit at a time. Determine the starting bit based on count
968 */
969 mask = 0x01 << (count - 1);
970
971 for (i = 0; i < count; i++) {
972 /*
973 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
974 * "1", and then raising and then lowering the clock (the SK
975 * bit controls the clock input to the EEPROM). A "0" is
976 * shifted out to the EEPROM by setting "DI" to "0" and then
977 * raising and then lowering the clock.
978 */
979 if (data & mask)
980 eec |= IXGBE_EEC_DI;
981 else
982 eec &= ~IXGBE_EEC_DI;
983
984 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
985 IXGBE_WRITE_FLUSH(hw);
986
987 udelay(1);
988
989 ixgbe_raise_eeprom_clk(hw, &eec);
990 ixgbe_lower_eeprom_clk(hw, &eec);
991
992 /*
993 * Shift mask to signify next bit of data to shift in to the
994 * EEPROM
995 */
996 mask = mask >> 1;
997 };
998
999 /* We leave the "DI" bit set to "0" when we leave this routine. */
1000 eec &= ~IXGBE_EEC_DI;
1001 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1002 IXGBE_WRITE_FLUSH(hw);
1003}
1004
1005/**
1006 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1007 * @hw: pointer to hardware structure
1008 **/
1009static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1010{
1011 u32 eec;
1012 u32 i;
1013 u16 data = 0;
1014
1015 /*
1016 * In order to read a register from the EEPROM, we need to shift
1017 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1018 * the clock input to the EEPROM (setting the SK bit), and then reading
1019 * the value of the "DO" bit. During this "shifting in" process the
1020 * "DI" bit should always be clear.
1021 */
1022 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1023
1024 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1025
1026 for (i = 0; i < count; i++) {
1027 data = data << 1;
1028 ixgbe_raise_eeprom_clk(hw, &eec);
1029
1030 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1031
1032 eec &= ~(IXGBE_EEC_DI);
1033 if (eec & IXGBE_EEC_DO)
1034 data |= 1;
1035
1036 ixgbe_lower_eeprom_clk(hw, &eec);
1037 }
1038
1039 return data;
1040}
1041
1042/**
1043 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1044 * @hw: pointer to hardware structure
1045 * @eec: EEC register's current value
1046 **/
1047static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1048{
1049 /*
1050 * Raise the clock input to the EEPROM
1051 * (setting the SK bit), then delay
1052 */
1053 *eec = *eec | IXGBE_EEC_SK;
1054 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1055 IXGBE_WRITE_FLUSH(hw);
1056 udelay(1);
1057}
1058
1059/**
1060 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1061 * @hw: pointer to hardware structure
1062 * @eecd: EECD's current value
1063 **/
1064static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1065{
1066 /*
1067 * Lower the clock input to the EEPROM (clearing the SK bit), then
1068 * delay
1069 */
1070 *eec = *eec & ~IXGBE_EEC_SK;
1071 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1072 IXGBE_WRITE_FLUSH(hw);
1073 udelay(1);
1074}
1075
1076/**
1077 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1078 * @hw: pointer to hardware structure
1079 **/
1080static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1081{
1082 u32 eec;
1083
1084 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1085
1086 eec |= IXGBE_EEC_CS; /* Pull CS high */
1087 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1088
1089 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1090 IXGBE_WRITE_FLUSH(hw);
1091
1092 udelay(1);
1093
1094 /* Stop requesting EEPROM access */
1095 eec &= ~IXGBE_EEC_REQ;
1096 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1097
Don Skidmore90827992011-03-05 18:59:20 -08001098 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001099
1100 /* Delay before attempt to obtain semaphore again to allow FW access */
1101 msleep(hw->eeprom.semaphore_delay);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001102}
1103
1104/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001105 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001106 * @hw: pointer to hardware structure
1107 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001108u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001109{
1110 u16 i;
1111 u16 j;
1112 u16 checksum = 0;
1113 u16 length = 0;
1114 u16 pointer = 0;
1115 u16 word = 0;
1116
1117 /* Include 0x0-0x3F in the checksum */
1118 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001119 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001120 hw_dbg(hw, "EEPROM read failed\n");
1121 break;
1122 }
1123 checksum += word;
1124 }
1125
1126 /* Include all data from pointers except for the fw pointer */
1127 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001128 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001129
1130 /* Make sure the pointer seems valid */
1131 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001132 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001133
1134 if (length != 0xFFFF && length != 0) {
1135 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001136 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001137 checksum += word;
1138 }
1139 }
1140 }
1141 }
1142
1143 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1144
1145 return checksum;
1146}
1147
1148/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001149 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001150 * @hw: pointer to hardware structure
1151 * @checksum_val: calculated checksum
1152 *
1153 * Performs checksum calculation and validates the EEPROM checksum. If the
1154 * caller does not need checksum_val, the value can be NULL.
1155 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001156s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1157 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001158{
1159 s32 status;
1160 u16 checksum;
1161 u16 read_checksum = 0;
1162
1163 /*
1164 * Read the first word from the EEPROM. If this times out or fails, do
1165 * not continue or we could be in for a very long wait while every
1166 * EEPROM read fails
1167 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001168 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001169
1170 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001171 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001172
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001173 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001174
1175 /*
1176 * Verify read checksum from EEPROM is the same as
1177 * calculated checksum
1178 */
1179 if (read_checksum != checksum)
1180 status = IXGBE_ERR_EEPROM_CHECKSUM;
1181
1182 /* If the user cares, return the calculated checksum */
1183 if (checksum_val)
1184 *checksum_val = checksum;
1185 } else {
1186 hw_dbg(hw, "EEPROM read failed\n");
1187 }
1188
1189 return status;
1190}
1191
1192/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001193 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1194 * @hw: pointer to hardware structure
1195 **/
1196s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1197{
1198 s32 status;
1199 u16 checksum;
1200
1201 /*
1202 * Read the first word from the EEPROM. If this times out or fails, do
1203 * not continue or we could be in for a very long wait while every
1204 * EEPROM read fails
1205 */
1206 status = hw->eeprom.ops.read(hw, 0, &checksum);
1207
1208 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001209 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001210 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001211 checksum);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001212 } else {
1213 hw_dbg(hw, "EEPROM read failed\n");
1214 }
1215
1216 return status;
1217}
1218
1219/**
Auke Kok9a799d72007-09-15 14:07:45 -07001220 * ixgbe_validate_mac_addr - Validate MAC address
1221 * @mac_addr: pointer to MAC address.
1222 *
1223 * Tests a MAC address to ensure it is a valid Individual Address
1224 **/
1225s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1226{
1227 s32 status = 0;
1228
1229 /* Make sure it is not a multicast address */
1230 if (IXGBE_IS_MULTICAST(mac_addr))
1231 status = IXGBE_ERR_INVALID_MAC_ADDR;
1232 /* Not a broadcast address */
1233 else if (IXGBE_IS_BROADCAST(mac_addr))
1234 status = IXGBE_ERR_INVALID_MAC_ADDR;
1235 /* Reject the zero address */
1236 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001237 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001238 status = IXGBE_ERR_INVALID_MAC_ADDR;
1239
1240 return status;
1241}
1242
1243/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001244 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001245 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001246 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001247 * @addr: Address to put into receive address register
1248 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001249 * @enable_addr: set flag that address is active
1250 *
1251 * Puts an ethernet address into a receive address register.
1252 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001253s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1254 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001255{
1256 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001257 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001258
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001259 /* Make sure we are using a valid rar index range */
1260 if (index >= rar_entries) {
1261 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1262 return IXGBE_ERR_INVALID_ARGUMENT;
1263 }
1264
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001265 /* setup VMDq pool selection before this RAR gets enabled */
1266 hw->mac.ops.set_vmdq(hw, index, vmdq);
1267
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001268 /*
1269 * HW expects these in little endian so we reverse the byte
1270 * order from network order (big endian) to little endian
1271 */
1272 rar_low = ((u32)addr[0] |
1273 ((u32)addr[1] << 8) |
1274 ((u32)addr[2] << 16) |
1275 ((u32)addr[3] << 24));
1276 /*
1277 * Some parts put the VMDq setting in the extra RAH bits,
1278 * so save everything except the lower 16 bits that hold part
1279 * of the address and the address valid bit.
1280 */
1281 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1282 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1283 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001284
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001285 if (enable_addr != 0)
1286 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001287
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001288 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1289 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001290
1291 return 0;
1292}
1293
1294/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001295 * ixgbe_clear_rar_generic - Remove Rx address register
1296 * @hw: pointer to hardware structure
1297 * @index: Receive address register to write
1298 *
1299 * Clears an ethernet address from a receive address register.
1300 **/
1301s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1302{
1303 u32 rar_high;
1304 u32 rar_entries = hw->mac.num_rar_entries;
1305
1306 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001307 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001308 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001309 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001310 }
1311
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001312 /*
1313 * Some parts put the VMDq setting in the extra RAH bits,
1314 * so save everything except the lower 16 bits that hold part
1315 * of the address and the address valid bit.
1316 */
1317 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1318 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1319
1320 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1321 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1322
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001323 /* clear VMDq pool/queue selection for this RAR */
1324 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1325
1326 return 0;
1327}
1328
1329/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001330 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001331 * @hw: pointer to hardware structure
1332 *
1333 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001334 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001335 * the receiver is in reset when the routine is called.
1336 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001337s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001338{
1339 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001340 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001341
1342 /*
1343 * If the current mac address is valid, assume it is a software override
1344 * to the permanent address.
1345 * Otherwise, use the permanent address from the eeprom.
1346 */
1347 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1348 IXGBE_ERR_INVALID_MAC_ADDR) {
1349 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001350 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001351
hartleysce7194d2010-01-05 06:56:52 +00001352 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001353 } else {
1354 /* Setup the receive address. */
1355 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001356 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001357
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001358 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001359
1360 /* clear VMDq pool/queue selection for RAR 0 */
1361 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001362 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001363 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001364
1365 hw->addr_ctrl.rar_used_count = 1;
1366
1367 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001368 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001369 for (i = 1; i < rar_entries; i++) {
1370 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1371 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1372 }
1373
1374 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001375 hw->addr_ctrl.mta_in_use = 0;
1376 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1377
1378 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001379 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001380 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1381
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001382 if (hw->mac.ops.init_uta_tables)
1383 hw->mac.ops.init_uta_tables(hw);
1384
Auke Kok9a799d72007-09-15 14:07:45 -07001385 return 0;
1386}
1387
1388/**
1389 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1390 * @hw: pointer to hardware structure
1391 * @mc_addr: the multicast address
1392 *
1393 * Extracts the 12 bits, from a multicast address, to determine which
1394 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1395 * incoming rx multicast addresses, to determine the bit-vector to check in
1396 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001397 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001398 * to mc_filter_type.
1399 **/
1400static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1401{
1402 u32 vector = 0;
1403
1404 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001405 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001406 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1407 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001408 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001409 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1410 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001411 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001412 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1413 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001414 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001415 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1416 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001417 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001418 hw_dbg(hw, "MC filter type param set incorrectly\n");
1419 break;
1420 }
1421
1422 /* vector can only be 12-bits or boundary will be exceeded */
1423 vector &= 0xFFF;
1424 return vector;
1425}
1426
1427/**
1428 * ixgbe_set_mta - Set bit-vector in multicast table
1429 * @hw: pointer to hardware structure
1430 * @hash_value: Multicast address hash value
1431 *
1432 * Sets the bit-vector in the multicast table.
1433 **/
1434static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1435{
1436 u32 vector;
1437 u32 vector_bit;
1438 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001439
1440 hw->addr_ctrl.mta_in_use++;
1441
1442 vector = ixgbe_mta_vector(hw, mc_addr);
1443 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1444
1445 /*
1446 * The MTA is a register array of 128 32-bit registers. It is treated
1447 * like an array of 4096 bits. We want to set bit
1448 * BitArray[vector_value]. So we figure out what register the bit is
1449 * in, read it, OR in the new bit, then write back the new value. The
1450 * register is determined by the upper 7 bits of the vector value and
1451 * the bit within that register are determined by the lower 5 bits of
1452 * the value.
1453 */
1454 vector_reg = (vector >> 5) & 0x7F;
1455 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00001456 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001457}
1458
1459/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001460 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001461 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001462 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001463 *
1464 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001465 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001466 * registers for the first multicast addresses, and hashes the rest into the
1467 * multicast table.
1468 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001469s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1470 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001471{
Jiri Pirko22bedad2010-04-01 21:22:57 +00001472 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001473 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001474
1475 /*
1476 * Set the new number of MC addresses that we are being requested to
1477 * use.
1478 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001479 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001480 hw->addr_ctrl.mta_in_use = 0;
1481
Emil Tantilov80960ab2011-02-18 08:58:27 +00001482 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001483 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001484 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001485
Emil Tantilov80960ab2011-02-18 08:58:27 +00001486 /* Update mta shadow */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001487 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001488 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad2010-04-01 21:22:57 +00001489 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001490 }
1491
1492 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001493 for (i = 0; i < hw->mac.mcft_size; i++)
1494 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1495 hw->mac.mta_shadow[i]);
1496
Auke Kok9a799d72007-09-15 14:07:45 -07001497 if (hw->addr_ctrl.mta_in_use > 0)
1498 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001499 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001500
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001501 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001502 return 0;
1503}
1504
1505/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001506 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001507 * @hw: pointer to hardware structure
1508 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001509 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001510 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001511s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001512{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001513 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001514
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001515 if (a->mta_in_use > 0)
1516 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1517 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001518
1519 return 0;
1520}
1521
1522/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001523 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001524 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001525 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001526 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001527 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001528s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001529{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001530 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001531
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001532 if (a->mta_in_use > 0)
1533 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001534
1535 return 0;
1536}
1537
1538/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001539 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001540 * @hw: pointer to hardware structure
1541 * @packetbuf_num: packet buffer number (0-7)
1542 *
1543 * Enable flow control according to the current settings.
1544 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001545s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001546{
1547 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001548 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001549 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001550 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001551 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001552
1553#ifdef CONFIG_DCB
1554 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1555 goto out;
1556
1557#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001558 /* Negotiate the fc mode to use */
1559 ret_val = ixgbe_fc_autoneg(hw);
1560 if (ret_val)
1561 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001562
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001563 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001564 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1565 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1566
1567 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1568 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1569
1570 /*
1571 * The possible values of fc.current_mode are:
1572 * 0: Flow control is completely disabled
1573 * 1: Rx flow control is enabled (we can receive pause frames,
1574 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001575 * 2: Tx flow control is enabled (we can send pause frames but
1576 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001577 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001578#ifdef CONFIG_DCB
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001579 * 4: Priority Flow Control is enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001580#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001581 * other: Invalid.
1582 */
1583 switch (hw->fc.current_mode) {
1584 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001585 /*
1586 * Flow control is disabled by software override or autoneg.
1587 * The code below will actually disable it in the HW.
1588 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001589 break;
1590 case ixgbe_fc_rx_pause:
1591 /*
1592 * Rx Flow control is enabled and Tx Flow control is
1593 * disabled by software override. Since there really
1594 * isn't a way to advertise that we are capable of RX
1595 * Pause ONLY, we will advertise that we support both
1596 * symmetric and asymmetric Rx PAUSE. Later, we will
1597 * disable the adapter's ability to send PAUSE frames.
1598 */
1599 mflcn_reg |= IXGBE_MFLCN_RFCE;
1600 break;
1601 case ixgbe_fc_tx_pause:
1602 /*
1603 * Tx Flow control is enabled, and Rx Flow control is
1604 * disabled by software override.
1605 */
1606 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1607 break;
1608 case ixgbe_fc_full:
1609 /* Flow control (both Rx and Tx) is enabled by SW override. */
1610 mflcn_reg |= IXGBE_MFLCN_RFCE;
1611 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1612 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001613#ifdef CONFIG_DCB
1614 case ixgbe_fc_pfc:
1615 goto out;
1616 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001617#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001618 default:
1619 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001620 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001621 goto out;
1622 break;
1623 }
1624
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001625 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001626 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001627 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1628 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1629
John Fastabend16b61be2010-11-16 19:26:44 -08001630 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1631 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001632
John Fastabend16b61be2010-11-16 19:26:44 -08001633 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1634 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001635
John Fastabend16b61be2010-11-16 19:26:44 -08001636 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1637 fcrth |= IXGBE_FCRTH_FCEN;
1638 if (hw->fc.send_xon)
1639 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001640 }
1641
John Fastabend16b61be2010-11-16 19:26:44 -08001642 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1643 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1644
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001645 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001646 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001647 if ((packetbuf_num & 1) == 0)
1648 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1649 else
1650 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1651 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1652
1653 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1654
1655out:
1656 return ret_val;
1657}
1658
1659/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001660 * ixgbe_fc_autoneg - Configure flow control
1661 * @hw: pointer to hardware structure
1662 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001663 * Compares our advertised flow control capabilities to those advertised by
1664 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001665 **/
1666s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1667{
1668 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001669 ixgbe_link_speed speed;
1670 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001671 u32 links2, anlp1_reg, autoc_reg, links;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001672 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001673
1674 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001675 * AN should have completed when the cable was plugged in.
1676 * Look for reasons to bail out. Bail out if:
1677 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001678 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001679 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001680 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001681 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001682 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001683 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001684
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001685 if (hw->fc.disable_fc_autoneg || (!link_up)) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001686 hw->fc.fc_was_autonegged = false;
1687 hw->fc.current_mode = hw->fc.requested_mode;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001688 goto out;
1689 }
1690
1691 /*
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001692 * On backplane, bail out if
1693 * - backplane autoneg was not completed, or if
Don Skidmore000c4862009-11-24 18:51:48 +00001694 * - we are 82599 and link partner is not AN enabled
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001695 */
1696 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1697 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Don Skidmore000c4862009-11-24 18:51:48 +00001698 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001699 hw->fc.fc_was_autonegged = false;
1700 hw->fc.current_mode = hw->fc.requested_mode;
1701 goto out;
1702 }
Don Skidmore000c4862009-11-24 18:51:48 +00001703
1704 if (hw->mac.type == ixgbe_mac_82599EB) {
1705 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1706 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1707 hw->fc.fc_was_autonegged = false;
1708 hw->fc.current_mode = hw->fc.requested_mode;
1709 goto out;
1710 }
1711 }
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001712 }
1713
1714 /*
1715 * On multispeed fiber at 1g, bail out if
1716 * - link is up but AN did not complete, or if
1717 * - link is up and AN completed but timed out
1718 */
1719 if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
1720 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1721 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1722 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1723 hw->fc.fc_was_autonegged = false;
1724 hw->fc.current_mode = hw->fc.requested_mode;
1725 goto out;
1726 }
1727 }
1728
1729 /*
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00001730 * Bail out on
1731 * - copper or CX4 adapters
1732 * - fiber adapters running at 10gig
1733 */
1734 if ((hw->phy.media_type == ixgbe_media_type_copper) ||
1735 (hw->phy.media_type == ixgbe_media_type_cx4) ||
1736 ((hw->phy.media_type == ixgbe_media_type_fiber) &&
1737 (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
1738 hw->fc.fc_was_autonegged = false;
1739 hw->fc.current_mode = hw->fc.requested_mode;
1740 goto out;
1741 }
1742
1743 /*
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001744 * Read the AN advertisement and LP ability registers and resolve
1745 * local flow control settings accordingly
1746 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001747 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
1748 (hw->phy.media_type != ixgbe_media_type_backplane)) {
1749 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1750 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1751 if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1752 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1753 /*
1754 * Now we need to check if the user selected Rx ONLY
1755 * of pause frames. In this case, we had to advertise
1756 * FULL flow control because we could not advertise RX
1757 * ONLY. Hence, we must now check to see if we need to
1758 * turn OFF the TRANSMISSION of PAUSE frames.
1759 */
1760 if (hw->fc.requested_mode == ixgbe_fc_full) {
1761 hw->fc.current_mode = ixgbe_fc_full;
1762 hw_dbg(hw, "Flow Control = FULL.\n");
1763 } else {
1764 hw->fc.current_mode = ixgbe_fc_rx_pause;
1765 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1766 }
1767 } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1768 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1769 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1770 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1771 hw->fc.current_mode = ixgbe_fc_tx_pause;
1772 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1773 } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1774 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1775 !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1776 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001777 hw->fc.current_mode = ixgbe_fc_rx_pause;
1778 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001779 } else {
1780 hw->fc.current_mode = ixgbe_fc_none;
1781 hw_dbg(hw, "Flow Control = NONE.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001782 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001783 }
1784
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001785 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1786 /*
1787 * Read the 10g AN autoc and LP ability registers and resolve
1788 * local flow control settings accordingly
1789 */
1790 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1791 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1792
1793 if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1794 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
1795 /*
1796 * Now we need to check if the user selected Rx ONLY
1797 * of pause frames. In this case, we had to advertise
1798 * FULL flow control because we could not advertise RX
1799 * ONLY. Hence, we must now check to see if we need to
1800 * turn OFF the TRANSMISSION of PAUSE frames.
1801 */
1802 if (hw->fc.requested_mode == ixgbe_fc_full) {
1803 hw->fc.current_mode = ixgbe_fc_full;
1804 hw_dbg(hw, "Flow Control = FULL.\n");
1805 } else {
1806 hw->fc.current_mode = ixgbe_fc_rx_pause;
1807 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1808 }
1809 } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1810 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1811 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1812 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1813 hw->fc.current_mode = ixgbe_fc_tx_pause;
1814 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1815 } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1816 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1817 !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1818 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1819 hw->fc.current_mode = ixgbe_fc_rx_pause;
1820 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1821 } else {
1822 hw->fc.current_mode = ixgbe_fc_none;
1823 hw_dbg(hw, "Flow Control = NONE.\n");
1824 }
1825 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001826 /* Record that current_mode is the result of a successful autoneg */
1827 hw->fc.fc_was_autonegged = true;
1828
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001829out:
1830 return ret_val;
1831}
1832
1833/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001834 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001835 * @hw: pointer to hardware structure
1836 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001837 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001838 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001839static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001840{
1841 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001842 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001843
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001844#ifdef CONFIG_DCB
1845 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1846 hw->fc.current_mode = hw->fc.requested_mode;
1847 goto out;
1848 }
1849
1850#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001851 /* Validate the packetbuf configuration */
1852 if (packetbuf_num < 0 || packetbuf_num > 7) {
1853 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1854 "is 0-7\n", packetbuf_num);
1855 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1856 goto out;
1857 }
1858
1859 /*
1860 * Validate the water mark configuration. Zero water marks are invalid
1861 * because it causes the controller to just blast out fc packets.
1862 */
1863 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001864 hw_dbg(hw, "Invalid water mark configuration\n");
1865 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1866 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001867 }
1868
1869 /*
1870 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001871 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001872 */
1873 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1874 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
1875 "IEEE mode\n");
1876 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1877 goto out;
1878 }
1879
1880 /*
1881 * 10gig parts do not have a word in the EEPROM to determine the
1882 * default flow control setting, so we explicitly set it to full.
1883 */
1884 if (hw->fc.requested_mode == ixgbe_fc_default)
1885 hw->fc.requested_mode = ixgbe_fc_full;
1886
1887 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001888 * Set up the 1G flow control advertisement registers so the HW will be
1889 * able to do fc autoneg once the cable is plugged in. If we end up
1890 * using 10g instead, this is harmless.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001891 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001892 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001893
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001894 /*
1895 * The possible values of fc.requested_mode are:
1896 * 0: Flow control is completely disabled
1897 * 1: Rx flow control is enabled (we can receive pause frames,
1898 * but not send pause frames).
1899 * 2: Tx flow control is enabled (we can send pause frames but
1900 * we do not support receiving pause frames).
1901 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1902#ifdef CONFIG_DCB
1903 * 4: Priority Flow Control is enabled.
1904#endif
1905 * other: Invalid.
1906 */
1907 switch (hw->fc.requested_mode) {
1908 case ixgbe_fc_none:
1909 /* Flow control completely disabled by software override. */
1910 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1911 break;
1912 case ixgbe_fc_rx_pause:
1913 /*
1914 * Rx Flow control is enabled and Tx Flow control is
1915 * disabled by software override. Since there really
1916 * isn't a way to advertise that we are capable of RX
1917 * Pause ONLY, we will advertise that we support both
1918 * symmetric and asymmetric Rx PAUSE. Later, we will
1919 * disable the adapter's ability to send PAUSE frames.
1920 */
1921 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1922 break;
1923 case ixgbe_fc_tx_pause:
1924 /*
1925 * Tx Flow control is enabled, and Rx Flow control is
1926 * disabled by software override.
1927 */
1928 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
1929 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
1930 break;
1931 case ixgbe_fc_full:
1932 /* Flow control (both Rx and Tx) is enabled by SW override. */
1933 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1934 break;
1935#ifdef CONFIG_DCB
1936 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001937 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001938 break;
1939#endif /* CONFIG_DCB */
1940 default:
1941 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001942 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001943 goto out;
1944 break;
1945 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001946
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001947 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
1948 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
1949
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001950 /* Disable AN timeout */
1951 if (hw->fc.strict_ieee)
1952 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
1953
1954 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
1955 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001956
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001957 /*
1958 * Set up the 10G flow control advertisement registers so the HW
1959 * can do fc autoneg once the cable is plugged in. If we end up
1960 * using 1g instead, this is harmless.
1961 */
1962 reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1963
1964 /*
1965 * The possible values of fc.requested_mode are:
1966 * 0: Flow control is completely disabled
1967 * 1: Rx flow control is enabled (we can receive pause frames,
1968 * but not send pause frames).
1969 * 2: Tx flow control is enabled (we can send pause frames but
1970 * we do not support receiving pause frames).
1971 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1972 * other: Invalid.
1973 */
1974 switch (hw->fc.requested_mode) {
1975 case ixgbe_fc_none:
1976 /* Flow control completely disabled by software override. */
1977 reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
1978 break;
1979 case ixgbe_fc_rx_pause:
1980 /*
1981 * Rx Flow control is enabled and Tx Flow control is
1982 * disabled by software override. Since there really
1983 * isn't a way to advertise that we are capable of RX
1984 * Pause ONLY, we will advertise that we support both
1985 * symmetric and asymmetric Rx PAUSE. Later, we will
1986 * disable the adapter's ability to send PAUSE frames.
1987 */
1988 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
1989 break;
1990 case ixgbe_fc_tx_pause:
1991 /*
1992 * Tx Flow control is enabled, and Rx Flow control is
1993 * disabled by software override.
1994 */
1995 reg |= (IXGBE_AUTOC_ASM_PAUSE);
1996 reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
1997 break;
1998 case ixgbe_fc_full:
1999 /* Flow control (both Rx and Tx) is enabled by SW override. */
2000 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2001 break;
2002#ifdef CONFIG_DCB
2003 case ixgbe_fc_pfc:
2004 goto out;
2005 break;
2006#endif /* CONFIG_DCB */
2007 default:
2008 hw_dbg(hw, "Flow control param set incorrectly\n");
2009 ret_val = IXGBE_ERR_CONFIG;
2010 goto out;
2011 break;
2012 }
2013 /*
2014 * AUTOC restart handles negotiation of 1G and 10G. There is
2015 * no need to set the PCS1GCTL register.
2016 */
2017 reg |= IXGBE_AUTOC_AN_RESTART;
2018 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
2019 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
2020
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002021out:
2022 return ret_val;
2023}
2024
2025/**
Auke Kok9a799d72007-09-15 14:07:45 -07002026 * ixgbe_disable_pcie_master - Disable PCI-express master access
2027 * @hw: pointer to hardware structure
2028 *
2029 * Disables PCI-Express master access and verifies there are no pending
2030 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2031 * bit hasn't caused the master requests to be disabled, else 0
2032 * is returned signifying master requests disabled.
2033 **/
2034s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2035{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002036 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002037 u32 i;
2038 u32 reg_val;
2039 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002040 s32 status = 0;
2041 u16 dev_status = 0;
2042
2043 /* Just jump out if bus mastering is already disabled */
2044 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2045 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002046
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002047 /* Disable the receive unit by stopping each queue */
2048 number_of_queues = hw->mac.max_rx_queues;
2049 for (i = 0; i < number_of_queues; i++) {
2050 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2051 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2052 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2053 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2054 }
2055 }
2056
2057 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2058 reg_val |= IXGBE_CTRL_GIO_DIS;
2059 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002060
2061 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002062 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2063 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002064 udelay(100);
2065 }
2066
Emil Tantilova4297dc2011-02-14 08:45:13 +00002067 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2068 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2069
2070 /*
2071 * Before proceeding, make sure that the PCIe block does not have
2072 * transactions pending.
2073 */
2074check_device_status:
2075 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2076 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2077 &dev_status);
2078 if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2079 break;
2080 udelay(100);
2081 }
2082
2083 if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
2084 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2085 else
2086 goto out;
2087
2088 /*
2089 * Two consecutive resets are required via CTRL.RST per datasheet
2090 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2091 * of this need. The first reset prevents new master requests from
2092 * being issued by our device. We then must wait 1usec for any
2093 * remaining completions from the PCIe bus to trickle in, and then reset
2094 * again to clear out any effects they may have had on our device.
2095 */
2096 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2097
2098out:
Auke Kok9a799d72007-09-15 14:07:45 -07002099 return status;
2100}
2101
2102
2103/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002104 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002105 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002106 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002107 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002108 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002109 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2110 **/
2111s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2112{
2113 u32 gssr;
2114 u32 swmask = mask;
2115 u32 fwmask = mask << 5;
2116 s32 timeout = 200;
2117
2118 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002119 /*
2120 * SW EEPROM semaphore bit is used for access to all
2121 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2122 */
Auke Kok9a799d72007-09-15 14:07:45 -07002123 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002124 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002125
2126 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2127 if (!(gssr & (fwmask | swmask)))
2128 break;
2129
2130 /*
2131 * Firmware currently using resource (fwmask) or other software
2132 * thread currently using resource (swmask)
2133 */
2134 ixgbe_release_eeprom_semaphore(hw);
2135 msleep(5);
2136 timeout--;
2137 }
2138
2139 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002140 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002141 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002142 }
2143
2144 gssr |= swmask;
2145 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2146
2147 ixgbe_release_eeprom_semaphore(hw);
2148 return 0;
2149}
2150
2151/**
2152 * ixgbe_release_swfw_sync - Release SWFW semaphore
2153 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002154 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002155 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002156 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002157 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2158 **/
2159void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2160{
2161 u32 gssr;
2162 u32 swmask = mask;
2163
2164 ixgbe_get_eeprom_semaphore(hw);
2165
2166 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2167 gssr &= ~swmask;
2168 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2169
2170 ixgbe_release_eeprom_semaphore(hw);
2171}
2172
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002173/**
2174 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2175 * @hw: pointer to hardware structure
2176 * @regval: register value to write to RXCTRL
2177 *
2178 * Enables the Rx DMA unit
2179 **/
2180s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2181{
2182 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2183
2184 return 0;
2185}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002186
2187/**
2188 * ixgbe_blink_led_start_generic - Blink LED based on index.
2189 * @hw: pointer to hardware structure
2190 * @index: led number to blink
2191 **/
2192s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2193{
2194 ixgbe_link_speed speed = 0;
2195 bool link_up = 0;
2196 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2197 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2198
2199 /*
2200 * Link must be up to auto-blink the LEDs;
2201 * Force it if link is down.
2202 */
2203 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2204
2205 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002206 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002207 autoc_reg |= IXGBE_AUTOC_FLU;
2208 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2209 msleep(10);
2210 }
2211
2212 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2213 led_reg |= IXGBE_LED_BLINK(index);
2214 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2215 IXGBE_WRITE_FLUSH(hw);
2216
2217 return 0;
2218}
2219
2220/**
2221 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2222 * @hw: pointer to hardware structure
2223 * @index: led number to stop blinking
2224 **/
2225s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2226{
2227 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2228 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2229
2230 autoc_reg &= ~IXGBE_AUTOC_FLU;
2231 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2232 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2233
2234 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2235 led_reg &= ~IXGBE_LED_BLINK(index);
2236 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2237 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2238 IXGBE_WRITE_FLUSH(hw);
2239
2240 return 0;
2241}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002242
2243/**
2244 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2245 * @hw: pointer to hardware structure
2246 * @san_mac_offset: SAN MAC address offset
2247 *
2248 * This function will read the EEPROM location for the SAN MAC address
2249 * pointer, and returns the value at that location. This is used in both
2250 * get and set mac_addr routines.
2251 **/
2252static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2253 u16 *san_mac_offset)
2254{
2255 /*
2256 * First read the EEPROM pointer to see if the MAC addresses are
2257 * available.
2258 */
2259 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2260
2261 return 0;
2262}
2263
2264/**
2265 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2266 * @hw: pointer to hardware structure
2267 * @san_mac_addr: SAN MAC address
2268 *
2269 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2270 * per-port, so set_lan_id() must be called before reading the addresses.
2271 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2272 * upon for non-SFP connections, so we must call it here.
2273 **/
2274s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2275{
2276 u16 san_mac_data, san_mac_offset;
2277 u8 i;
2278
2279 /*
2280 * First read the EEPROM pointer to see if the MAC addresses are
2281 * available. If they're not, no point in calling set_lan_id() here.
2282 */
2283 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2284
2285 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2286 /*
2287 * No addresses available in this EEPROM. It's not an
2288 * error though, so just wipe the local address and return.
2289 */
2290 for (i = 0; i < 6; i++)
2291 san_mac_addr[i] = 0xFF;
2292
2293 goto san_mac_addr_out;
2294 }
2295
2296 /* make sure we know which port we need to program */
2297 hw->mac.ops.set_lan_id(hw);
2298 /* apply the port offset to the address offset */
2299 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2300 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2301 for (i = 0; i < 3; i++) {
2302 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2303 san_mac_addr[i * 2] = (u8)(san_mac_data);
2304 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2305 san_mac_offset++;
2306 }
2307
2308san_mac_addr_out:
2309 return 0;
2310}
2311
2312/**
2313 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2314 * @hw: pointer to hardware structure
2315 *
2316 * Read PCIe configuration space, and get the MSI-X vector count from
2317 * the capabilities table.
2318 **/
2319u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2320{
2321 struct ixgbe_adapter *adapter = hw->back;
2322 u16 msix_count;
2323 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2324 &msix_count);
2325 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2326
2327 /* MSI-X count is zero-based in HW, so increment to give proper value */
2328 msix_count++;
2329
2330 return msix_count;
2331}
2332
2333/**
2334 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2335 * @hw: pointer to hardware struct
2336 * @rar: receive address register index to disassociate
2337 * @vmdq: VMDq pool index to remove from the rar
2338 **/
2339s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2340{
2341 u32 mpsar_lo, mpsar_hi;
2342 u32 rar_entries = hw->mac.num_rar_entries;
2343
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002344 /* Make sure we are using a valid rar index range */
2345 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002346 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002347 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002348 }
2349
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002350 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2351 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2352
2353 if (!mpsar_lo && !mpsar_hi)
2354 goto done;
2355
2356 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2357 if (mpsar_lo) {
2358 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2359 mpsar_lo = 0;
2360 }
2361 if (mpsar_hi) {
2362 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2363 mpsar_hi = 0;
2364 }
2365 } else if (vmdq < 32) {
2366 mpsar_lo &= ~(1 << vmdq);
2367 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2368 } else {
2369 mpsar_hi &= ~(1 << (vmdq - 32));
2370 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2371 }
2372
2373 /* was that the last pool using this rar? */
2374 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2375 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002376done:
2377 return 0;
2378}
2379
2380/**
2381 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2382 * @hw: pointer to hardware struct
2383 * @rar: receive address register index to associate with a VMDq index
2384 * @vmdq: VMDq pool index
2385 **/
2386s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2387{
2388 u32 mpsar;
2389 u32 rar_entries = hw->mac.num_rar_entries;
2390
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002391 /* Make sure we are using a valid rar index range */
2392 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002393 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002394 return IXGBE_ERR_INVALID_ARGUMENT;
2395 }
2396
2397 if (vmdq < 32) {
2398 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2399 mpsar |= 1 << vmdq;
2400 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2401 } else {
2402 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2403 mpsar |= 1 << (vmdq - 32);
2404 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002405 }
2406 return 0;
2407}
2408
2409/**
2410 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2411 * @hw: pointer to hardware structure
2412 **/
2413s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2414{
2415 int i;
2416
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002417 for (i = 0; i < 128; i++)
2418 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2419
2420 return 0;
2421}
2422
2423/**
2424 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2425 * @hw: pointer to hardware structure
2426 * @vlan: VLAN id to write to VLAN filter
2427 *
2428 * return the VLVF index where this VLAN id should be placed
2429 *
2430 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002431static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002432{
2433 u32 bits = 0;
2434 u32 first_empty_slot = 0;
2435 s32 regindex;
2436
2437 /* short cut the special case */
2438 if (vlan == 0)
2439 return 0;
2440
2441 /*
2442 * Search for the vlan id in the VLVF entries. Save off the first empty
2443 * slot found along the way
2444 */
2445 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2446 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2447 if (!bits && !(first_empty_slot))
2448 first_empty_slot = regindex;
2449 else if ((bits & 0x0FFF) == vlan)
2450 break;
2451 }
2452
2453 /*
2454 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2455 * in the VLVF. Else use the first empty VLVF register for this
2456 * vlan id.
2457 */
2458 if (regindex >= IXGBE_VLVF_ENTRIES) {
2459 if (first_empty_slot)
2460 regindex = first_empty_slot;
2461 else {
2462 hw_dbg(hw, "No space in VLVF.\n");
2463 regindex = IXGBE_ERR_NO_SPACE;
2464 }
2465 }
2466
2467 return regindex;
2468}
2469
2470/**
2471 * ixgbe_set_vfta_generic - Set VLAN filter table
2472 * @hw: pointer to hardware structure
2473 * @vlan: VLAN id to write to VLAN filter
2474 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2475 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2476 *
2477 * Turn on/off specified VLAN in the VLAN filter table.
2478 **/
2479s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2480 bool vlan_on)
2481{
2482 s32 regindex;
2483 u32 bitindex;
2484 u32 vfta;
2485 u32 bits;
2486 u32 vt;
2487 u32 targetbit;
2488 bool vfta_changed = false;
2489
2490 if (vlan > 4095)
2491 return IXGBE_ERR_PARAM;
2492
2493 /*
2494 * this is a 2 part operation - first the VFTA, then the
2495 * VLVF and VLVFB if VT Mode is set
2496 * We don't write the VFTA until we know the VLVF part succeeded.
2497 */
2498
2499 /* Part 1
2500 * The VFTA is a bitstring made up of 128 32-bit registers
2501 * that enable the particular VLAN id, much like the MTA:
2502 * bits[11-5]: which register
2503 * bits[4-0]: which bit in the register
2504 */
2505 regindex = (vlan >> 5) & 0x7F;
2506 bitindex = vlan & 0x1F;
2507 targetbit = (1 << bitindex);
2508 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2509
2510 if (vlan_on) {
2511 if (!(vfta & targetbit)) {
2512 vfta |= targetbit;
2513 vfta_changed = true;
2514 }
2515 } else {
2516 if ((vfta & targetbit)) {
2517 vfta &= ~targetbit;
2518 vfta_changed = true;
2519 }
2520 }
2521
2522 /* Part 2
2523 * If VT Mode is set
2524 * Either vlan_on
2525 * make sure the vlan is in VLVF
2526 * set the vind bit in the matching VLVFB
2527 * Or !vlan_on
2528 * clear the pool bit and possibly the vind
2529 */
2530 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2531 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2532 s32 vlvf_index;
2533
2534 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2535 if (vlvf_index < 0)
2536 return vlvf_index;
2537
2538 if (vlan_on) {
2539 /* set the pool bit */
2540 if (vind < 32) {
2541 bits = IXGBE_READ_REG(hw,
2542 IXGBE_VLVFB(vlvf_index*2));
2543 bits |= (1 << vind);
2544 IXGBE_WRITE_REG(hw,
2545 IXGBE_VLVFB(vlvf_index*2),
2546 bits);
2547 } else {
2548 bits = IXGBE_READ_REG(hw,
2549 IXGBE_VLVFB((vlvf_index*2)+1));
2550 bits |= (1 << (vind-32));
2551 IXGBE_WRITE_REG(hw,
2552 IXGBE_VLVFB((vlvf_index*2)+1),
2553 bits);
2554 }
2555 } else {
2556 /* clear the pool bit */
2557 if (vind < 32) {
2558 bits = IXGBE_READ_REG(hw,
2559 IXGBE_VLVFB(vlvf_index*2));
2560 bits &= ~(1 << vind);
2561 IXGBE_WRITE_REG(hw,
2562 IXGBE_VLVFB(vlvf_index*2),
2563 bits);
2564 bits |= IXGBE_READ_REG(hw,
2565 IXGBE_VLVFB((vlvf_index*2)+1));
2566 } else {
2567 bits = IXGBE_READ_REG(hw,
2568 IXGBE_VLVFB((vlvf_index*2)+1));
2569 bits &= ~(1 << (vind-32));
2570 IXGBE_WRITE_REG(hw,
2571 IXGBE_VLVFB((vlvf_index*2)+1),
2572 bits);
2573 bits |= IXGBE_READ_REG(hw,
2574 IXGBE_VLVFB(vlvf_index*2));
2575 }
2576 }
2577
2578 /*
2579 * If there are still bits set in the VLVFB registers
2580 * for the VLAN ID indicated we need to see if the
2581 * caller is requesting that we clear the VFTA entry bit.
2582 * If the caller has requested that we clear the VFTA
2583 * entry bit but there are still pools/VFs using this VLAN
2584 * ID entry then ignore the request. We're not worried
2585 * about the case where we're turning the VFTA VLAN ID
2586 * entry bit on, only when requested to turn it off as
2587 * there may be multiple pools and/or VFs using the
2588 * VLAN ID entry. In that case we cannot clear the
2589 * VFTA bit until all pools/VFs using that VLAN ID have also
2590 * been cleared. This will be indicated by "bits" being
2591 * zero.
2592 */
2593 if (bits) {
2594 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2595 (IXGBE_VLVF_VIEN | vlan));
2596 if (!vlan_on) {
2597 /* someone wants to clear the vfta entry
2598 * but some pools/VFs are still using it.
2599 * Ignore it. */
2600 vfta_changed = false;
2601 }
2602 }
2603 else
2604 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
2605 }
2606
2607 if (vfta_changed)
2608 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
2609
2610 return 0;
2611}
2612
2613/**
2614 * ixgbe_clear_vfta_generic - Clear VLAN filter table
2615 * @hw: pointer to hardware structure
2616 *
2617 * Clears the VLAN filer table, and the VMDq index associated with the filter
2618 **/
2619s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
2620{
2621 u32 offset;
2622
2623 for (offset = 0; offset < hw->mac.vft_size; offset++)
2624 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
2625
2626 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
2627 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
2628 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
2629 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
2630 }
2631
2632 return 0;
2633}
2634
2635/**
2636 * ixgbe_check_mac_link_generic - Determine link and speed status
2637 * @hw: pointer to hardware structure
2638 * @speed: pointer to link speed
2639 * @link_up: true when link is up
2640 * @link_up_wait_to_complete: bool used to wait for link up or not
2641 *
2642 * Reads the links register to determine if link is up and the current speed
2643 **/
2644s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00002645 bool *link_up, bool link_up_wait_to_complete)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002646{
Emil Tantilov48de36c2011-02-16 01:38:08 +00002647 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002648 u32 i;
2649
Emil Tantilov48de36c2011-02-16 01:38:08 +00002650 /* clear the old state */
2651 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
2652
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002653 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00002654
2655 if (links_orig != links_reg) {
2656 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
2657 links_orig, links_reg);
2658 }
2659
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002660 if (link_up_wait_to_complete) {
2661 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2662 if (links_reg & IXGBE_LINKS_UP) {
2663 *link_up = true;
2664 break;
2665 } else {
2666 *link_up = false;
2667 }
2668 msleep(100);
2669 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2670 }
2671 } else {
2672 if (links_reg & IXGBE_LINKS_UP)
2673 *link_up = true;
2674 else
2675 *link_up = false;
2676 }
2677
2678 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2679 IXGBE_LINKS_SPEED_10G_82599)
2680 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2681 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
Emil Tantilov63d778d2011-02-19 08:43:39 +00002682 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002683 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002684 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2685 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002686 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002687 else
2688 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002689
2690 /* if link is down, zero out the current_mode */
2691 if (*link_up == false) {
2692 hw->fc.current_mode = ixgbe_fc_none;
2693 hw->fc.fc_was_autonegged = false;
2694 }
2695
2696 return 0;
2697}
Don Skidmorea391f1d2010-11-16 19:27:15 -08002698
2699/**
2700 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
2701 * the EEPROM
2702 * @hw: pointer to hardware structure
2703 * @wwnn_prefix: the alternative WWNN prefix
2704 * @wwpn_prefix: the alternative WWPN prefix
2705 *
2706 * This function will read the EEPROM from the alternative SAN MAC address
2707 * block to check the support for the alternative WWNN/WWPN prefix support.
2708 **/
2709s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2710 u16 *wwpn_prefix)
2711{
2712 u16 offset, caps;
2713 u16 alt_san_mac_blk_offset;
2714
2715 /* clear output first */
2716 *wwnn_prefix = 0xFFFF;
2717 *wwpn_prefix = 0xFFFF;
2718
2719 /* check if alternative SAN MAC is supported */
2720 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2721 &alt_san_mac_blk_offset);
2722
2723 if ((alt_san_mac_blk_offset == 0) ||
2724 (alt_san_mac_blk_offset == 0xFFFF))
2725 goto wwn_prefix_out;
2726
2727 /* check capability in alternative san mac address block */
2728 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2729 hw->eeprom.ops.read(hw, offset, &caps);
2730 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2731 goto wwn_prefix_out;
2732
2733 /* get the corresponding prefix for WWNN/WWPN */
2734 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2735 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2736
2737 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2738 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2739
2740wwn_prefix_out:
2741 return 0;
2742}
Greg Rosea985b6c32010-11-18 03:02:52 +00002743
2744/**
2745 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2746 * @hw: pointer to hardware structure
2747 * @enable: enable or disable switch for anti-spoofing
2748 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
2749 *
2750 **/
2751void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
2752{
2753 int j;
2754 int pf_target_reg = pf >> 3;
2755 int pf_target_shift = pf % 8;
2756 u32 pfvfspoof = 0;
2757
2758 if (hw->mac.type == ixgbe_mac_82598EB)
2759 return;
2760
2761 if (enable)
2762 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
2763
2764 /*
2765 * PFVFSPOOF register array is size 8 with 8 bits assigned to
2766 * MAC anti-spoof enables in each register array element.
2767 */
2768 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
2769 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
2770
2771 /* If not enabling anti-spoofing then done */
2772 if (!enable)
2773 return;
2774
2775 /*
2776 * The PF should be allowed to spoof so that it can support
2777 * emulation mode NICs. Reset the bit assigned to the PF
2778 */
2779 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
2780 pfvfspoof ^= (1 << pf_target_shift);
2781 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
2782}
2783
2784/**
2785 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
2786 * @hw: pointer to hardware structure
2787 * @enable: enable or disable switch for VLAN anti-spoofing
2788 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
2789 *
2790 **/
2791void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
2792{
2793 int vf_target_reg = vf >> 3;
2794 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
2795 u32 pfvfspoof;
2796
2797 if (hw->mac.type == ixgbe_mac_82598EB)
2798 return;
2799
2800 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2801 if (enable)
2802 pfvfspoof |= (1 << vf_target_shift);
2803 else
2804 pfvfspoof &= ~(1 << vf_target_shift);
2805 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2806}