blob: a12f7c73e27dbf8183ec28f51a01d392a314a5be [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Shannon Nelson8c47eaa2010-01-13 01:49:34 +00004 Copyright(c) 1999 - 2010 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000031#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_common.h"
35#include "ixgbe_phy.h"
36
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070037static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070040static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
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);
139 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
140 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
141 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
142
143 for (i = 0; i < 8; i++) {
144 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
145 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
146 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
147 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
148 }
149
150 IXGBE_READ_REG(hw, IXGBE_PRC64);
151 IXGBE_READ_REG(hw, IXGBE_PRC127);
152 IXGBE_READ_REG(hw, IXGBE_PRC255);
153 IXGBE_READ_REG(hw, IXGBE_PRC511);
154 IXGBE_READ_REG(hw, IXGBE_PRC1023);
155 IXGBE_READ_REG(hw, IXGBE_PRC1522);
156 IXGBE_READ_REG(hw, IXGBE_GPRC);
157 IXGBE_READ_REG(hw, IXGBE_BPRC);
158 IXGBE_READ_REG(hw, IXGBE_MPRC);
159 IXGBE_READ_REG(hw, IXGBE_GPTC);
160 IXGBE_READ_REG(hw, IXGBE_GORCL);
161 IXGBE_READ_REG(hw, IXGBE_GORCH);
162 IXGBE_READ_REG(hw, IXGBE_GOTCL);
163 IXGBE_READ_REG(hw, IXGBE_GOTCH);
164 for (i = 0; i < 8; i++)
165 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
166 IXGBE_READ_REG(hw, IXGBE_RUC);
167 IXGBE_READ_REG(hw, IXGBE_RFC);
168 IXGBE_READ_REG(hw, IXGBE_ROC);
169 IXGBE_READ_REG(hw, IXGBE_RJC);
170 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
171 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
172 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
173 IXGBE_READ_REG(hw, IXGBE_TORL);
174 IXGBE_READ_REG(hw, IXGBE_TORH);
175 IXGBE_READ_REG(hw, IXGBE_TPR);
176 IXGBE_READ_REG(hw, IXGBE_TPT);
177 IXGBE_READ_REG(hw, IXGBE_PTC64);
178 IXGBE_READ_REG(hw, IXGBE_PTC127);
179 IXGBE_READ_REG(hw, IXGBE_PTC255);
180 IXGBE_READ_REG(hw, IXGBE_PTC511);
181 IXGBE_READ_REG(hw, IXGBE_PTC1023);
182 IXGBE_READ_REG(hw, IXGBE_PTC1522);
183 IXGBE_READ_REG(hw, IXGBE_MPTC);
184 IXGBE_READ_REG(hw, IXGBE_BPTC);
185 for (i = 0; i < 16; i++) {
186 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
187 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
188 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
189 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
190 }
191
192 return 0;
193}
194
195/**
Don Skidmore289700db2010-12-03 03:32:58 +0000196 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700197 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000198 * @pba_num: stores the part number string from the EEPROM
199 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700200 *
Don Skidmore289700db2010-12-03 03:32:58 +0000201 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700202 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000203s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
204 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700205{
206 s32 ret_val;
207 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000208 u16 pba_ptr;
209 u16 offset;
210 u16 length;
211
212 if (pba_num == NULL) {
213 hw_dbg(hw, "PBA string buffer was null\n");
214 return IXGBE_ERR_INVALID_ARGUMENT;
215 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700216
217 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
218 if (ret_val) {
219 hw_dbg(hw, "NVM Read Error\n");
220 return ret_val;
221 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700222
Don Skidmore289700db2010-12-03 03:32:58 +0000223 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700224 if (ret_val) {
225 hw_dbg(hw, "NVM Read Error\n");
226 return ret_val;
227 }
Don Skidmore289700db2010-12-03 03:32:58 +0000228
229 /*
230 * if data is not ptr guard the PBA must be in legacy format which
231 * means pba_ptr is actually our second data word for the PBA number
232 * and we can decode it into an ascii string
233 */
234 if (data != IXGBE_PBANUM_PTR_GUARD) {
235 hw_dbg(hw, "NVM PBA number is not stored as string\n");
236
237 /* we will need 11 characters to store the PBA */
238 if (pba_num_size < 11) {
239 hw_dbg(hw, "PBA string buffer too small\n");
240 return IXGBE_ERR_NO_SPACE;
241 }
242
243 /* extract hex string from data and pba_ptr */
244 pba_num[0] = (data >> 12) & 0xF;
245 pba_num[1] = (data >> 8) & 0xF;
246 pba_num[2] = (data >> 4) & 0xF;
247 pba_num[3] = data & 0xF;
248 pba_num[4] = (pba_ptr >> 12) & 0xF;
249 pba_num[5] = (pba_ptr >> 8) & 0xF;
250 pba_num[6] = '-';
251 pba_num[7] = 0;
252 pba_num[8] = (pba_ptr >> 4) & 0xF;
253 pba_num[9] = pba_ptr & 0xF;
254
255 /* put a null character on the end of our string */
256 pba_num[10] = '\0';
257
258 /* switch all the data but the '-' to hex char */
259 for (offset = 0; offset < 10; offset++) {
260 if (pba_num[offset] < 0xA)
261 pba_num[offset] += '0';
262 else if (pba_num[offset] < 0x10)
263 pba_num[offset] += 'A' - 0xA;
264 }
265
266 return 0;
267 }
268
269 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
270 if (ret_val) {
271 hw_dbg(hw, "NVM Read Error\n");
272 return ret_val;
273 }
274
275 if (length == 0xFFFF || length == 0) {
276 hw_dbg(hw, "NVM PBA number section invalid length\n");
277 return IXGBE_ERR_PBA_SECTION;
278 }
279
280 /* check if pba_num buffer is big enough */
281 if (pba_num_size < (((u32)length * 2) - 1)) {
282 hw_dbg(hw, "PBA string buffer too small\n");
283 return IXGBE_ERR_NO_SPACE;
284 }
285
286 /* trim pba length from start of string */
287 pba_ptr++;
288 length--;
289
290 for (offset = 0; offset < length; offset++) {
291 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
292 if (ret_val) {
293 hw_dbg(hw, "NVM Read Error\n");
294 return ret_val;
295 }
296 pba_num[offset * 2] = (u8)(data >> 8);
297 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
298 }
299 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700300
301 return 0;
302}
303
304/**
305 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700306 * @hw: pointer to hardware structure
307 * @mac_addr: Adapter MAC address
308 *
309 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
310 * A reset of the adapter must be performed prior to calling this function
311 * in order for the MAC address to have been loaded from the EEPROM into RAR0
312 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700313s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700314{
315 u32 rar_high;
316 u32 rar_low;
317 u16 i;
318
319 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
320 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
321
322 for (i = 0; i < 4; i++)
323 mac_addr[i] = (u8)(rar_low >> (i*8));
324
325 for (i = 0; i < 2; i++)
326 mac_addr[i+4] = (u8)(rar_high >> (i*8));
327
328 return 0;
329}
330
Auke Kok9a799d72007-09-15 14:07:45 -0700331/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000332 * ixgbe_get_bus_info_generic - Generic set PCI bus info
333 * @hw: pointer to hardware structure
334 *
335 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
336 **/
337s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
338{
339 struct ixgbe_adapter *adapter = hw->back;
340 struct ixgbe_mac_info *mac = &hw->mac;
341 u16 link_status;
342
343 hw->bus.type = ixgbe_bus_type_pci_express;
344
345 /* Get the negotiated link width and speed from PCI config space */
346 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
347 &link_status);
348
349 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
350 case IXGBE_PCI_LINK_WIDTH_1:
351 hw->bus.width = ixgbe_bus_width_pcie_x1;
352 break;
353 case IXGBE_PCI_LINK_WIDTH_2:
354 hw->bus.width = ixgbe_bus_width_pcie_x2;
355 break;
356 case IXGBE_PCI_LINK_WIDTH_4:
357 hw->bus.width = ixgbe_bus_width_pcie_x4;
358 break;
359 case IXGBE_PCI_LINK_WIDTH_8:
360 hw->bus.width = ixgbe_bus_width_pcie_x8;
361 break;
362 default:
363 hw->bus.width = ixgbe_bus_width_unknown;
364 break;
365 }
366
367 switch (link_status & IXGBE_PCI_LINK_SPEED) {
368 case IXGBE_PCI_LINK_SPEED_2500:
369 hw->bus.speed = ixgbe_bus_speed_2500;
370 break;
371 case IXGBE_PCI_LINK_SPEED_5000:
372 hw->bus.speed = ixgbe_bus_speed_5000;
373 break;
374 default:
375 hw->bus.speed = ixgbe_bus_speed_unknown;
376 break;
377 }
378
379 mac->ops.set_lan_id(hw);
380
381 return 0;
382}
383
384/**
385 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
386 * @hw: pointer to the HW structure
387 *
388 * Determines the LAN function id by reading memory-mapped registers
389 * and swaps the port value if requested.
390 **/
391void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
392{
393 struct ixgbe_bus_info *bus = &hw->bus;
394 u32 reg;
395
396 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
397 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
398 bus->lan_id = bus->func;
399
400 /* check for a port swap */
401 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
402 if (reg & IXGBE_FACTPS_LFS)
403 bus->func ^= 0x1;
404}
405
406/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700407 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700408 * @hw: pointer to hardware structure
409 *
410 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
411 * disables transmit and receive units. The adapter_stopped flag is used by
412 * the shared code and drivers to determine if the adapter is in a stopped
413 * state and should not touch the hardware.
414 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700415s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700416{
417 u32 number_of_queues;
418 u32 reg_val;
419 u16 i;
420
421 /*
422 * Set the adapter_stopped flag so other driver functions stop touching
423 * the hardware
424 */
425 hw->adapter_stopped = true;
426
427 /* Disable the receive unit */
428 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
429 reg_val &= ~(IXGBE_RXCTRL_RXEN);
430 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700431 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700432 msleep(2);
433
434 /* Clear interrupt mask to stop from interrupts being generated */
435 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
436
437 /* Clear any pending interrupts */
438 IXGBE_READ_REG(hw, IXGBE_EICR);
439
440 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700441 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700442 for (i = 0; i < number_of_queues; i++) {
443 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
444 if (reg_val & IXGBE_TXDCTL_ENABLE) {
445 reg_val &= ~IXGBE_TXDCTL_ENABLE;
446 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
447 }
448 }
449
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700450 /*
451 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
452 * access and verify no pending requests
453 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000454 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700455
Auke Kok9a799d72007-09-15 14:07:45 -0700456 return 0;
457}
458
459/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700460 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700461 * @hw: pointer to hardware structure
462 * @index: led number to turn on
463 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700464s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700465{
466 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
467
468 /* To turn on the LED, set mode to ON. */
469 led_reg &= ~IXGBE_LED_MODE_MASK(index);
470 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
471 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700472 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700473
474 return 0;
475}
476
477/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700478 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700479 * @hw: pointer to hardware structure
480 * @index: led number to turn off
481 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700482s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700483{
484 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
485
486 /* To turn off the LED, set mode to OFF. */
487 led_reg &= ~IXGBE_LED_MODE_MASK(index);
488 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
489 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700490 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700491
492 return 0;
493}
494
Auke Kok9a799d72007-09-15 14:07:45 -0700495/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700496 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700497 * @hw: pointer to hardware structure
498 *
499 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
500 * ixgbe_hw struct in order to set up EEPROM access.
501 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700502s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700503{
504 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
505 u32 eec;
506 u16 eeprom_size;
507
508 if (eeprom->type == ixgbe_eeprom_uninitialized) {
509 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700510 /* Set default semaphore delay to 10ms which is a well
511 * tested value */
512 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700513
514 /*
515 * Check for EEPROM present first.
516 * If not present leave as none
517 */
518 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
519 if (eec & IXGBE_EEC_PRES) {
520 eeprom->type = ixgbe_eeprom_spi;
521
522 /*
523 * SPI EEPROM is assumed here. This code would need to
524 * change if a future EEPROM is not SPI.
525 */
526 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
527 IXGBE_EEC_SIZE_SHIFT);
528 eeprom->word_size = 1 << (eeprom_size +
529 IXGBE_EEPROM_WORD_SIZE_SHIFT);
530 }
531
532 if (eec & IXGBE_EEC_ADDR_SIZE)
533 eeprom->address_bits = 16;
534 else
535 eeprom->address_bits = 8;
536 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
537 "%d\n", eeprom->type, eeprom->word_size,
538 eeprom->address_bits);
539 }
540
541 return 0;
542}
543
544/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000545 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
546 * @hw: pointer to hardware structure
547 * @offset: offset within the EEPROM to be written to
548 * @data: 16 bit word to be written to the EEPROM
549 *
550 * If ixgbe_eeprom_update_checksum is not called after this function, the
551 * EEPROM will most likely contain an invalid checksum.
552 **/
553s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
554{
555 s32 status;
556 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
557
558 hw->eeprom.ops.init_params(hw);
559
560 if (offset >= hw->eeprom.word_size) {
561 status = IXGBE_ERR_EEPROM;
562 goto out;
563 }
564
565 /* Prepare the EEPROM for writing */
566 status = ixgbe_acquire_eeprom(hw);
567
568 if (status == 0) {
569 if (ixgbe_ready_eeprom(hw) != 0) {
570 ixgbe_release_eeprom(hw);
571 status = IXGBE_ERR_EEPROM;
572 }
573 }
574
575 if (status == 0) {
576 ixgbe_standby_eeprom(hw);
577
578 /* Send the WRITE ENABLE command (8 bit opcode ) */
579 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
580 IXGBE_EEPROM_OPCODE_BITS);
581
582 ixgbe_standby_eeprom(hw);
583
584 /*
585 * Some SPI eeproms use the 8th address bit embedded in the
586 * opcode
587 */
588 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
589 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
590
591 /* Send the Write command (8-bit opcode + addr) */
592 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
593 IXGBE_EEPROM_OPCODE_BITS);
594 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
595 hw->eeprom.address_bits);
596
597 /* Send the data */
598 data = (data >> 8) | (data << 8);
599 ixgbe_shift_out_eeprom_bits(hw, data, 16);
600 ixgbe_standby_eeprom(hw);
601
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000602 /* Done with writing - release the EEPROM */
603 ixgbe_release_eeprom(hw);
604 }
605
606out:
607 return status;
608}
609
610/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700611 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
612 * @hw: pointer to hardware structure
613 * @offset: offset within the EEPROM to be read
614 * @data: read 16 bit value from EEPROM
615 *
616 * Reads 16 bit value from EEPROM through bit-bang method
617 **/
618s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
619 u16 *data)
620{
621 s32 status;
622 u16 word_in;
623 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
624
625 hw->eeprom.ops.init_params(hw);
626
627 if (offset >= hw->eeprom.word_size) {
628 status = IXGBE_ERR_EEPROM;
629 goto out;
630 }
631
632 /* Prepare the EEPROM for reading */
633 status = ixgbe_acquire_eeprom(hw);
634
635 if (status == 0) {
636 if (ixgbe_ready_eeprom(hw) != 0) {
637 ixgbe_release_eeprom(hw);
638 status = IXGBE_ERR_EEPROM;
639 }
640 }
641
642 if (status == 0) {
643 ixgbe_standby_eeprom(hw);
644
645 /*
646 * Some SPI eeproms use the 8th address bit embedded in the
647 * opcode
648 */
649 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
650 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
651
652 /* Send the READ command (opcode + addr) */
653 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
654 IXGBE_EEPROM_OPCODE_BITS);
655 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
656 hw->eeprom.address_bits);
657
658 /* Read the data. */
659 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
660 *data = (word_in >> 8) | (word_in << 8);
661
662 /* End this read operation */
663 ixgbe_release_eeprom(hw);
664 }
665
666out:
667 return status;
668}
669
670/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000671 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700672 * @hw: pointer to hardware structure
673 * @offset: offset of word in the EEPROM to read
674 * @data: word read from the EEPROM
675 *
676 * Reads a 16 bit word from the EEPROM using the EERD register.
677 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000678s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700679{
680 u32 eerd;
681 s32 status;
682
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700683 hw->eeprom.ops.init_params(hw);
684
685 if (offset >= hw->eeprom.word_size) {
686 status = IXGBE_ERR_EEPROM;
687 goto out;
688 }
689
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000690 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
691 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700692
693 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000694 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700695
696 if (status == 0)
697 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000698 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700699 else
700 hw_dbg(hw, "Eeprom read timed out\n");
701
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700702out:
Auke Kok9a799d72007-09-15 14:07:45 -0700703 return status;
704}
705
706/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000707 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700708 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000709 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700710 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000711 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
712 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700713 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800714s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700715{
716 u32 i;
717 u32 reg;
718 s32 status = IXGBE_ERR_EEPROM;
719
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000720 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
721 if (ee_reg == IXGBE_NVM_POLL_READ)
722 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
723 else
724 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
725
726 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700727 status = 0;
728 break;
729 }
730 udelay(5);
731 }
732 return status;
733}
734
735/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700736 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
737 * @hw: pointer to hardware structure
738 *
739 * Prepares EEPROM for access using bit-bang method. This function should
740 * be called before issuing a command to the EEPROM.
741 **/
742static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
743{
744 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000745 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700746 u32 i;
747
748 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
749 status = IXGBE_ERR_SWFW_SYNC;
750
751 if (status == 0) {
752 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
753
754 /* Request EEPROM Access */
755 eec |= IXGBE_EEC_REQ;
756 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
757
758 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
759 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
760 if (eec & IXGBE_EEC_GNT)
761 break;
762 udelay(5);
763 }
764
765 /* Release if grant not acquired */
766 if (!(eec & IXGBE_EEC_GNT)) {
767 eec &= ~IXGBE_EEC_REQ;
768 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
769 hw_dbg(hw, "Could not acquire EEPROM grant\n");
770
771 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
772 status = IXGBE_ERR_EEPROM;
773 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700774
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000775 /* Setup EEPROM for Read/Write */
776 if (status == 0) {
777 /* Clear CS and SK */
778 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
779 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
780 IXGBE_WRITE_FLUSH(hw);
781 udelay(1);
782 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700783 }
784 return status;
785}
786
787/**
Auke Kok9a799d72007-09-15 14:07:45 -0700788 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
789 * @hw: pointer to hardware structure
790 *
791 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
792 **/
793static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
794{
795 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000796 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700797 u32 i;
798 u32 swsm;
799
Auke Kok9a799d72007-09-15 14:07:45 -0700800 /* Get SMBI software semaphore between device drivers first */
801 for (i = 0; i < timeout; i++) {
802 /*
803 * If the SMBI bit is 0 when we read it, then the bit will be
804 * set and we have the semaphore
805 */
806 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
807 if (!(swsm & IXGBE_SWSM_SMBI)) {
808 status = 0;
809 break;
810 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000811 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700812 }
813
814 /* Now get the semaphore between SW/FW through the SWESMBI bit */
815 if (status == 0) {
816 for (i = 0; i < timeout; i++) {
817 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
818
819 /* Set the SW EEPROM semaphore bit to request access */
820 swsm |= IXGBE_SWSM_SWESMBI;
821 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
822
823 /*
824 * If we set the bit successfully then we got the
825 * semaphore.
826 */
827 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
828 if (swsm & IXGBE_SWSM_SWESMBI)
829 break;
830
831 udelay(50);
832 }
833
834 /*
835 * Release semaphores and return error if SW EEPROM semaphore
836 * was not granted because we don't have access to the EEPROM
837 */
838 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000839 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700840 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700841 ixgbe_release_eeprom_semaphore(hw);
842 status = IXGBE_ERR_EEPROM;
843 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000844 } else {
845 hw_dbg(hw, "Software semaphore SMBI between device drivers "
846 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700847 }
848
849 return status;
850}
851
852/**
853 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
854 * @hw: pointer to hardware structure
855 *
856 * This function clears hardware semaphore bits.
857 **/
858static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
859{
860 u32 swsm;
861
862 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
863
864 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
865 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
866 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700867 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700868}
869
870/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700871 * ixgbe_ready_eeprom - Polls for EEPROM ready
872 * @hw: pointer to hardware structure
873 **/
874static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
875{
876 s32 status = 0;
877 u16 i;
878 u8 spi_stat_reg;
879
880 /*
881 * Read "Status Register" repeatedly until the LSB is cleared. The
882 * EEPROM will signal that the command has been completed by clearing
883 * bit 0 of the internal status register. If it's not cleared within
884 * 5 milliseconds, then error out.
885 */
886 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
887 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
888 IXGBE_EEPROM_OPCODE_BITS);
889 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
890 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
891 break;
892
893 udelay(5);
894 ixgbe_standby_eeprom(hw);
895 };
896
897 /*
898 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
899 * devices (and only 0-5mSec on 5V devices)
900 */
901 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
902 hw_dbg(hw, "SPI EEPROM Status error\n");
903 status = IXGBE_ERR_EEPROM;
904 }
905
906 return status;
907}
908
909/**
910 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
911 * @hw: pointer to hardware structure
912 **/
913static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
914{
915 u32 eec;
916
917 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
918
919 /* Toggle CS to flush commands */
920 eec |= IXGBE_EEC_CS;
921 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
922 IXGBE_WRITE_FLUSH(hw);
923 udelay(1);
924 eec &= ~IXGBE_EEC_CS;
925 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
926 IXGBE_WRITE_FLUSH(hw);
927 udelay(1);
928}
929
930/**
931 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
932 * @hw: pointer to hardware structure
933 * @data: data to send to the EEPROM
934 * @count: number of bits to shift out
935 **/
936static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
937 u16 count)
938{
939 u32 eec;
940 u32 mask;
941 u32 i;
942
943 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
944
945 /*
946 * Mask is used to shift "count" bits of "data" out to the EEPROM
947 * one bit at a time. Determine the starting bit based on count
948 */
949 mask = 0x01 << (count - 1);
950
951 for (i = 0; i < count; i++) {
952 /*
953 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
954 * "1", and then raising and then lowering the clock (the SK
955 * bit controls the clock input to the EEPROM). A "0" is
956 * shifted out to the EEPROM by setting "DI" to "0" and then
957 * raising and then lowering the clock.
958 */
959 if (data & mask)
960 eec |= IXGBE_EEC_DI;
961 else
962 eec &= ~IXGBE_EEC_DI;
963
964 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
965 IXGBE_WRITE_FLUSH(hw);
966
967 udelay(1);
968
969 ixgbe_raise_eeprom_clk(hw, &eec);
970 ixgbe_lower_eeprom_clk(hw, &eec);
971
972 /*
973 * Shift mask to signify next bit of data to shift in to the
974 * EEPROM
975 */
976 mask = mask >> 1;
977 };
978
979 /* We leave the "DI" bit set to "0" when we leave this routine. */
980 eec &= ~IXGBE_EEC_DI;
981 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
982 IXGBE_WRITE_FLUSH(hw);
983}
984
985/**
986 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
987 * @hw: pointer to hardware structure
988 **/
989static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
990{
991 u32 eec;
992 u32 i;
993 u16 data = 0;
994
995 /*
996 * In order to read a register from the EEPROM, we need to shift
997 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
998 * the clock input to the EEPROM (setting the SK bit), and then reading
999 * the value of the "DO" bit. During this "shifting in" process the
1000 * "DI" bit should always be clear.
1001 */
1002 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1003
1004 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1005
1006 for (i = 0; i < count; i++) {
1007 data = data << 1;
1008 ixgbe_raise_eeprom_clk(hw, &eec);
1009
1010 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1011
1012 eec &= ~(IXGBE_EEC_DI);
1013 if (eec & IXGBE_EEC_DO)
1014 data |= 1;
1015
1016 ixgbe_lower_eeprom_clk(hw, &eec);
1017 }
1018
1019 return data;
1020}
1021
1022/**
1023 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1024 * @hw: pointer to hardware structure
1025 * @eec: EEC register's current value
1026 **/
1027static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1028{
1029 /*
1030 * Raise the clock input to the EEPROM
1031 * (setting the SK bit), then delay
1032 */
1033 *eec = *eec | IXGBE_EEC_SK;
1034 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1035 IXGBE_WRITE_FLUSH(hw);
1036 udelay(1);
1037}
1038
1039/**
1040 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1041 * @hw: pointer to hardware structure
1042 * @eecd: EECD's current value
1043 **/
1044static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1045{
1046 /*
1047 * Lower the clock input to the EEPROM (clearing the SK bit), then
1048 * delay
1049 */
1050 *eec = *eec & ~IXGBE_EEC_SK;
1051 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1052 IXGBE_WRITE_FLUSH(hw);
1053 udelay(1);
1054}
1055
1056/**
1057 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1058 * @hw: pointer to hardware structure
1059 **/
1060static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1061{
1062 u32 eec;
1063
1064 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1065
1066 eec |= IXGBE_EEC_CS; /* Pull CS high */
1067 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1068
1069 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1070 IXGBE_WRITE_FLUSH(hw);
1071
1072 udelay(1);
1073
1074 /* Stop requesting EEPROM access */
1075 eec &= ~IXGBE_EEC_REQ;
1076 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1077
1078 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001079
1080 /* Delay before attempt to obtain semaphore again to allow FW access */
1081 msleep(hw->eeprom.semaphore_delay);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001082}
1083
1084/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001085 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001086 * @hw: pointer to hardware structure
1087 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001088u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001089{
1090 u16 i;
1091 u16 j;
1092 u16 checksum = 0;
1093 u16 length = 0;
1094 u16 pointer = 0;
1095 u16 word = 0;
1096
1097 /* Include 0x0-0x3F in the checksum */
1098 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001099 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001100 hw_dbg(hw, "EEPROM read failed\n");
1101 break;
1102 }
1103 checksum += word;
1104 }
1105
1106 /* Include all data from pointers except for the fw pointer */
1107 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001108 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001109
1110 /* Make sure the pointer seems valid */
1111 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001112 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001113
1114 if (length != 0xFFFF && length != 0) {
1115 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001116 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001117 checksum += word;
1118 }
1119 }
1120 }
1121 }
1122
1123 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1124
1125 return checksum;
1126}
1127
1128/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001129 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001130 * @hw: pointer to hardware structure
1131 * @checksum_val: calculated checksum
1132 *
1133 * Performs checksum calculation and validates the EEPROM checksum. If the
1134 * caller does not need checksum_val, the value can be NULL.
1135 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001136s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1137 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001138{
1139 s32 status;
1140 u16 checksum;
1141 u16 read_checksum = 0;
1142
1143 /*
1144 * Read the first word from the EEPROM. If this times out or fails, do
1145 * not continue or we could be in for a very long wait while every
1146 * EEPROM read fails
1147 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001148 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001149
1150 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001151 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001152
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001153 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001154
1155 /*
1156 * Verify read checksum from EEPROM is the same as
1157 * calculated checksum
1158 */
1159 if (read_checksum != checksum)
1160 status = IXGBE_ERR_EEPROM_CHECKSUM;
1161
1162 /* If the user cares, return the calculated checksum */
1163 if (checksum_val)
1164 *checksum_val = checksum;
1165 } else {
1166 hw_dbg(hw, "EEPROM read failed\n");
1167 }
1168
1169 return status;
1170}
1171
1172/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001173 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1174 * @hw: pointer to hardware structure
1175 **/
1176s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1177{
1178 s32 status;
1179 u16 checksum;
1180
1181 /*
1182 * Read the first word from the EEPROM. If this times out or fails, do
1183 * not continue or we could be in for a very long wait while every
1184 * EEPROM read fails
1185 */
1186 status = hw->eeprom.ops.read(hw, 0, &checksum);
1187
1188 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001189 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001190 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1191 checksum);
1192 } else {
1193 hw_dbg(hw, "EEPROM read failed\n");
1194 }
1195
1196 return status;
1197}
1198
1199/**
Auke Kok9a799d72007-09-15 14:07:45 -07001200 * ixgbe_validate_mac_addr - Validate MAC address
1201 * @mac_addr: pointer to MAC address.
1202 *
1203 * Tests a MAC address to ensure it is a valid Individual Address
1204 **/
1205s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1206{
1207 s32 status = 0;
1208
1209 /* Make sure it is not a multicast address */
1210 if (IXGBE_IS_MULTICAST(mac_addr))
1211 status = IXGBE_ERR_INVALID_MAC_ADDR;
1212 /* Not a broadcast address */
1213 else if (IXGBE_IS_BROADCAST(mac_addr))
1214 status = IXGBE_ERR_INVALID_MAC_ADDR;
1215 /* Reject the zero address */
1216 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001217 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001218 status = IXGBE_ERR_INVALID_MAC_ADDR;
1219
1220 return status;
1221}
1222
1223/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001224 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001225 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001226 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001227 * @addr: Address to put into receive address register
1228 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001229 * @enable_addr: set flag that address is active
1230 *
1231 * Puts an ethernet address into a receive address register.
1232 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001233s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1234 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001235{
1236 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001237 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001238
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001239 /* Make sure we are using a valid rar index range */
1240 if (index >= rar_entries) {
1241 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1242 return IXGBE_ERR_INVALID_ARGUMENT;
1243 }
1244
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001245 /* setup VMDq pool selection before this RAR gets enabled */
1246 hw->mac.ops.set_vmdq(hw, index, vmdq);
1247
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001248 /*
1249 * HW expects these in little endian so we reverse the byte
1250 * order from network order (big endian) to little endian
1251 */
1252 rar_low = ((u32)addr[0] |
1253 ((u32)addr[1] << 8) |
1254 ((u32)addr[2] << 16) |
1255 ((u32)addr[3] << 24));
1256 /*
1257 * Some parts put the VMDq setting in the extra RAH bits,
1258 * so save everything except the lower 16 bits that hold part
1259 * of the address and the address valid bit.
1260 */
1261 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1262 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1263 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001264
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001265 if (enable_addr != 0)
1266 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001267
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001268 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1269 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001270
1271 return 0;
1272}
1273
1274/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001275 * ixgbe_clear_rar_generic - Remove Rx address register
1276 * @hw: pointer to hardware structure
1277 * @index: Receive address register to write
1278 *
1279 * Clears an ethernet address from a receive address register.
1280 **/
1281s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1282{
1283 u32 rar_high;
1284 u32 rar_entries = hw->mac.num_rar_entries;
1285
1286 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001287 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001288 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001289 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001290 }
1291
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001292 /*
1293 * Some parts put the VMDq setting in the extra RAH bits,
1294 * so save everything except the lower 16 bits that hold part
1295 * of the address and the address valid bit.
1296 */
1297 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1298 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1299
1300 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1301 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1302
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001303 /* clear VMDq pool/queue selection for this RAR */
1304 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1305
1306 return 0;
1307}
1308
1309/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001310 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001311 * @hw: pointer to hardware structure
1312 *
1313 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001314 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001315 * the receiver is in reset when the routine is called.
1316 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001317s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001318{
1319 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001320 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001321
1322 /*
1323 * If the current mac address is valid, assume it is a software override
1324 * to the permanent address.
1325 * Otherwise, use the permanent address from the eeprom.
1326 */
1327 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1328 IXGBE_ERR_INVALID_MAC_ADDR) {
1329 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001330 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001331
hartleysce7194d2010-01-05 06:56:52 +00001332 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001333 } else {
1334 /* Setup the receive address. */
1335 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001336 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001337
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001338 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001339
1340 /* clear VMDq pool/queue selection for RAR 0 */
1341 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001342 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001343 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001344
1345 hw->addr_ctrl.rar_used_count = 1;
1346
1347 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001348 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001349 for (i = 1; i < rar_entries; i++) {
1350 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1351 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1352 }
1353
1354 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001355 hw->addr_ctrl.mta_in_use = 0;
1356 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1357
1358 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001359 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001360 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1361
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001362 if (hw->mac.ops.init_uta_tables)
1363 hw->mac.ops.init_uta_tables(hw);
1364
Auke Kok9a799d72007-09-15 14:07:45 -07001365 return 0;
1366}
1367
1368/**
1369 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1370 * @hw: pointer to hardware structure
1371 * @mc_addr: the multicast address
1372 *
1373 * Extracts the 12 bits, from a multicast address, to determine which
1374 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1375 * incoming rx multicast addresses, to determine the bit-vector to check in
1376 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001377 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001378 * to mc_filter_type.
1379 **/
1380static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1381{
1382 u32 vector = 0;
1383
1384 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001385 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001386 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1387 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001388 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001389 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1390 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001391 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001392 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1393 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001394 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001395 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1396 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001397 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001398 hw_dbg(hw, "MC filter type param set incorrectly\n");
1399 break;
1400 }
1401
1402 /* vector can only be 12-bits or boundary will be exceeded */
1403 vector &= 0xFFF;
1404 return vector;
1405}
1406
1407/**
1408 * ixgbe_set_mta - Set bit-vector in multicast table
1409 * @hw: pointer to hardware structure
1410 * @hash_value: Multicast address hash value
1411 *
1412 * Sets the bit-vector in the multicast table.
1413 **/
1414static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1415{
1416 u32 vector;
1417 u32 vector_bit;
1418 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001419
1420 hw->addr_ctrl.mta_in_use++;
1421
1422 vector = ixgbe_mta_vector(hw, mc_addr);
1423 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1424
1425 /*
1426 * The MTA is a register array of 128 32-bit registers. It is treated
1427 * like an array of 4096 bits. We want to set bit
1428 * BitArray[vector_value]. So we figure out what register the bit is
1429 * in, read it, OR in the new bit, then write back the new value. The
1430 * register is determined by the upper 7 bits of the vector value and
1431 * the bit within that register are determined by the lower 5 bits of
1432 * the value.
1433 */
1434 vector_reg = (vector >> 5) & 0x7F;
1435 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00001436 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001437}
1438
1439/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001440 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001441 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001442 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001443 *
1444 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001445 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001446 * registers for the first multicast addresses, and hashes the rest into the
1447 * multicast table.
1448 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001449s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1450 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001451{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001452 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001453 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001454
1455 /*
1456 * Set the new number of MC addresses that we are being requested to
1457 * use.
1458 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001459 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001460 hw->addr_ctrl.mta_in_use = 0;
1461
Emil Tantilov80960ab2011-02-18 08:58:27 +00001462 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001463 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001464 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001465
Emil Tantilov80960ab2011-02-18 08:58:27 +00001466 /* Update mta shadow */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001467 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001468 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad32010-04-01 21:22:57 +00001469 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001470 }
1471
1472 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001473 for (i = 0; i < hw->mac.mcft_size; i++)
1474 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1475 hw->mac.mta_shadow[i]);
1476
Auke Kok9a799d72007-09-15 14:07:45 -07001477 if (hw->addr_ctrl.mta_in_use > 0)
1478 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001479 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001480
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001481 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001482 return 0;
1483}
1484
1485/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001486 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001487 * @hw: pointer to hardware structure
1488 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001489 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001490 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001491s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001492{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001493 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001495 if (a->mta_in_use > 0)
1496 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1497 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001498
1499 return 0;
1500}
1501
1502/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001503 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001504 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001505 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001506 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001507 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001508s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001509{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001510 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001511
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001512 if (a->mta_in_use > 0)
1513 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001514
1515 return 0;
1516}
1517
1518/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001519 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001520 * @hw: pointer to hardware structure
1521 * @packetbuf_num: packet buffer number (0-7)
1522 *
1523 * Enable flow control according to the current settings.
1524 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001525s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001526{
1527 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001528 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001529 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001530 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001531 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001532
1533#ifdef CONFIG_DCB
1534 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1535 goto out;
1536
1537#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001538 /* Negotiate the fc mode to use */
1539 ret_val = ixgbe_fc_autoneg(hw);
1540 if (ret_val)
1541 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001542
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001543 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001544 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1545 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1546
1547 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1548 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1549
1550 /*
1551 * The possible values of fc.current_mode are:
1552 * 0: Flow control is completely disabled
1553 * 1: Rx flow control is enabled (we can receive pause frames,
1554 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001555 * 2: Tx flow control is enabled (we can send pause frames but
1556 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001557 * 3: Both Rx and Tx flow control (symmetric) are enabled.
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001558 * 4: Priority Flow Control is enabled.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001559 * other: Invalid.
1560 */
1561 switch (hw->fc.current_mode) {
1562 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001563 /*
1564 * Flow control is disabled by software override or autoneg.
1565 * The code below will actually disable it in the HW.
1566 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001567 break;
1568 case ixgbe_fc_rx_pause:
1569 /*
1570 * Rx Flow control is enabled and Tx Flow control is
1571 * disabled by software override. Since there really
1572 * isn't a way to advertise that we are capable of RX
1573 * Pause ONLY, we will advertise that we support both
1574 * symmetric and asymmetric Rx PAUSE. Later, we will
1575 * disable the adapter's ability to send PAUSE frames.
1576 */
1577 mflcn_reg |= IXGBE_MFLCN_RFCE;
1578 break;
1579 case ixgbe_fc_tx_pause:
1580 /*
1581 * Tx Flow control is enabled, and Rx Flow control is
1582 * disabled by software override.
1583 */
1584 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1585 break;
1586 case ixgbe_fc_full:
1587 /* Flow control (both Rx and Tx) is enabled by SW override. */
1588 mflcn_reg |= IXGBE_MFLCN_RFCE;
1589 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1590 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001591#ifdef CONFIG_DCB
1592 case ixgbe_fc_pfc:
1593 goto out;
1594 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001595#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001596 default:
1597 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001598 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001599 goto out;
1600 break;
1601 }
1602
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001603 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001604 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001605 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1606 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1607
John Fastabend16b61be2010-11-16 19:26:44 -08001608 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1609 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001610
John Fastabend16b61be2010-11-16 19:26:44 -08001611 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1612 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001613
John Fastabend16b61be2010-11-16 19:26:44 -08001614 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1615 fcrth |= IXGBE_FCRTH_FCEN;
1616 if (hw->fc.send_xon)
1617 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001618 }
1619
John Fastabend16b61be2010-11-16 19:26:44 -08001620 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1621 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1622
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001623 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001624 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001625 if ((packetbuf_num & 1) == 0)
1626 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1627 else
1628 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1629 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1630
1631 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1632
1633out:
1634 return ret_val;
1635}
1636
1637/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001638 * ixgbe_fc_autoneg - Configure flow control
1639 * @hw: pointer to hardware structure
1640 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001641 * Compares our advertised flow control capabilities to those advertised by
1642 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001643 **/
1644s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1645{
1646 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001647 ixgbe_link_speed speed;
1648 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001649 u32 links2, anlp1_reg, autoc_reg, links;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001650 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001651
1652 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001653 * AN should have completed when the cable was plugged in.
1654 * Look for reasons to bail out. Bail out if:
1655 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001656 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001657 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001658 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001659 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001660 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001661 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001662
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001663 if (hw->fc.disable_fc_autoneg || (!link_up)) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001664 hw->fc.fc_was_autonegged = false;
1665 hw->fc.current_mode = hw->fc.requested_mode;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001666 goto out;
1667 }
1668
1669 /*
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001670 * On backplane, bail out if
1671 * - backplane autoneg was not completed, or if
Don Skidmore000c4862009-11-24 18:51:48 +00001672 * - we are 82599 and link partner is not AN enabled
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001673 */
1674 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1675 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Don Skidmore000c4862009-11-24 18:51:48 +00001676 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001677 hw->fc.fc_was_autonegged = false;
1678 hw->fc.current_mode = hw->fc.requested_mode;
1679 goto out;
1680 }
Don Skidmore000c4862009-11-24 18:51:48 +00001681
1682 if (hw->mac.type == ixgbe_mac_82599EB) {
1683 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1684 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1685 hw->fc.fc_was_autonegged = false;
1686 hw->fc.current_mode = hw->fc.requested_mode;
1687 goto out;
1688 }
1689 }
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001690 }
1691
1692 /*
1693 * On multispeed fiber at 1g, bail out if
1694 * - link is up but AN did not complete, or if
1695 * - link is up and AN completed but timed out
1696 */
1697 if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
1698 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1699 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1700 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1701 hw->fc.fc_was_autonegged = false;
1702 hw->fc.current_mode = hw->fc.requested_mode;
1703 goto out;
1704 }
1705 }
1706
1707 /*
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00001708 * Bail out on
1709 * - copper or CX4 adapters
1710 * - fiber adapters running at 10gig
1711 */
1712 if ((hw->phy.media_type == ixgbe_media_type_copper) ||
1713 (hw->phy.media_type == ixgbe_media_type_cx4) ||
1714 ((hw->phy.media_type == ixgbe_media_type_fiber) &&
1715 (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
1716 hw->fc.fc_was_autonegged = false;
1717 hw->fc.current_mode = hw->fc.requested_mode;
1718 goto out;
1719 }
1720
1721 /*
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001722 * Read the AN advertisement and LP ability registers and resolve
1723 * local flow control settings accordingly
1724 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001725 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
1726 (hw->phy.media_type != ixgbe_media_type_backplane)) {
1727 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1728 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1729 if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1730 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1731 /*
1732 * Now we need to check if the user selected Rx ONLY
1733 * of pause frames. In this case, we had to advertise
1734 * FULL flow control because we could not advertise RX
1735 * ONLY. Hence, we must now check to see if we need to
1736 * turn OFF the TRANSMISSION of PAUSE frames.
1737 */
1738 if (hw->fc.requested_mode == ixgbe_fc_full) {
1739 hw->fc.current_mode = ixgbe_fc_full;
1740 hw_dbg(hw, "Flow Control = FULL.\n");
1741 } else {
1742 hw->fc.current_mode = ixgbe_fc_rx_pause;
1743 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1744 }
1745 } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1746 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1747 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1748 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1749 hw->fc.current_mode = ixgbe_fc_tx_pause;
1750 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1751 } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1752 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1753 !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1754 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001755 hw->fc.current_mode = ixgbe_fc_rx_pause;
1756 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001757 } else {
1758 hw->fc.current_mode = ixgbe_fc_none;
1759 hw_dbg(hw, "Flow Control = NONE.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001760 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001761 }
1762
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001763 if (hw->phy.media_type == ixgbe_media_type_backplane) {
1764 /*
1765 * Read the 10g AN autoc and LP ability registers and resolve
1766 * local flow control settings accordingly
1767 */
1768 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1769 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1770
1771 if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1772 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
1773 /*
1774 * Now we need to check if the user selected Rx ONLY
1775 * of pause frames. In this case, we had to advertise
1776 * FULL flow control because we could not advertise RX
1777 * ONLY. Hence, we must now check to see if we need to
1778 * turn OFF the TRANSMISSION of PAUSE frames.
1779 */
1780 if (hw->fc.requested_mode == ixgbe_fc_full) {
1781 hw->fc.current_mode = ixgbe_fc_full;
1782 hw_dbg(hw, "Flow Control = FULL.\n");
1783 } else {
1784 hw->fc.current_mode = ixgbe_fc_rx_pause;
1785 hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1786 }
1787 } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1788 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1789 (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1790 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1791 hw->fc.current_mode = ixgbe_fc_tx_pause;
1792 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1793 } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1794 (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1795 !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1796 (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1797 hw->fc.current_mode = ixgbe_fc_rx_pause;
1798 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1799 } else {
1800 hw->fc.current_mode = ixgbe_fc_none;
1801 hw_dbg(hw, "Flow Control = NONE.\n");
1802 }
1803 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001804 /* Record that current_mode is the result of a successful autoneg */
1805 hw->fc.fc_was_autonegged = true;
1806
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001807out:
1808 return ret_val;
1809}
1810
1811/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001812 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001813 * @hw: pointer to hardware structure
1814 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001815 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001816 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001817static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001818{
1819 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001820 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001821
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001822#ifdef CONFIG_DCB
1823 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1824 hw->fc.current_mode = hw->fc.requested_mode;
1825 goto out;
1826 }
1827
1828#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001829 /* Validate the packetbuf configuration */
1830 if (packetbuf_num < 0 || packetbuf_num > 7) {
1831 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1832 "is 0-7\n", packetbuf_num);
1833 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1834 goto out;
1835 }
1836
1837 /*
1838 * Validate the water mark configuration. Zero water marks are invalid
1839 * because it causes the controller to just blast out fc packets.
1840 */
1841 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001842 hw_dbg(hw, "Invalid water mark configuration\n");
1843 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1844 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001845 }
1846
1847 /*
1848 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001849 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001850 */
1851 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1852 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
1853 "IEEE mode\n");
1854 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1855 goto out;
1856 }
1857
1858 /*
1859 * 10gig parts do not have a word in the EEPROM to determine the
1860 * default flow control setting, so we explicitly set it to full.
1861 */
1862 if (hw->fc.requested_mode == ixgbe_fc_default)
1863 hw->fc.requested_mode = ixgbe_fc_full;
1864
1865 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001866 * Set up the 1G flow control advertisement registers so the HW will be
1867 * able to do fc autoneg once the cable is plugged in. If we end up
1868 * using 10g instead, this is harmless.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001869 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001870 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001871
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001872 /*
1873 * The possible values of fc.requested_mode are:
1874 * 0: Flow control is completely disabled
1875 * 1: Rx flow control is enabled (we can receive pause frames,
1876 * but not send pause frames).
1877 * 2: Tx flow control is enabled (we can send pause frames but
1878 * we do not support receiving pause frames).
1879 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1880#ifdef CONFIG_DCB
1881 * 4: Priority Flow Control is enabled.
1882#endif
1883 * other: Invalid.
1884 */
1885 switch (hw->fc.requested_mode) {
1886 case ixgbe_fc_none:
1887 /* Flow control completely disabled by software override. */
1888 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1889 break;
1890 case ixgbe_fc_rx_pause:
1891 /*
1892 * Rx Flow control is enabled and Tx Flow control is
1893 * disabled by software override. Since there really
1894 * isn't a way to advertise that we are capable of RX
1895 * Pause ONLY, we will advertise that we support both
1896 * symmetric and asymmetric Rx PAUSE. Later, we will
1897 * disable the adapter's ability to send PAUSE frames.
1898 */
1899 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1900 break;
1901 case ixgbe_fc_tx_pause:
1902 /*
1903 * Tx Flow control is enabled, and Rx Flow control is
1904 * disabled by software override.
1905 */
1906 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
1907 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
1908 break;
1909 case ixgbe_fc_full:
1910 /* Flow control (both Rx and Tx) is enabled by SW override. */
1911 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1912 break;
1913#ifdef CONFIG_DCB
1914 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001915 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001916 break;
1917#endif /* CONFIG_DCB */
1918 default:
1919 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001920 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001921 goto out;
1922 break;
1923 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001924
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001925 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
1926 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
1927
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001928 /* Disable AN timeout */
1929 if (hw->fc.strict_ieee)
1930 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
1931
1932 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
1933 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001934
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001935 /*
1936 * Set up the 10G flow control advertisement registers so the HW
1937 * can do fc autoneg once the cable is plugged in. If we end up
1938 * using 1g instead, this is harmless.
1939 */
1940 reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1941
1942 /*
1943 * The possible values of fc.requested_mode are:
1944 * 0: Flow control is completely disabled
1945 * 1: Rx flow control is enabled (we can receive pause frames,
1946 * but not send pause frames).
1947 * 2: Tx flow control is enabled (we can send pause frames but
1948 * we do not support receiving pause frames).
1949 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1950 * other: Invalid.
1951 */
1952 switch (hw->fc.requested_mode) {
1953 case ixgbe_fc_none:
1954 /* Flow control completely disabled by software override. */
1955 reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
1956 break;
1957 case ixgbe_fc_rx_pause:
1958 /*
1959 * Rx Flow control is enabled and Tx Flow control is
1960 * disabled by software override. Since there really
1961 * isn't a way to advertise that we are capable of RX
1962 * Pause ONLY, we will advertise that we support both
1963 * symmetric and asymmetric Rx PAUSE. Later, we will
1964 * disable the adapter's ability to send PAUSE frames.
1965 */
1966 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
1967 break;
1968 case ixgbe_fc_tx_pause:
1969 /*
1970 * Tx Flow control is enabled, and Rx Flow control is
1971 * disabled by software override.
1972 */
1973 reg |= (IXGBE_AUTOC_ASM_PAUSE);
1974 reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
1975 break;
1976 case ixgbe_fc_full:
1977 /* Flow control (both Rx and Tx) is enabled by SW override. */
1978 reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
1979 break;
1980#ifdef CONFIG_DCB
1981 case ixgbe_fc_pfc:
1982 goto out;
1983 break;
1984#endif /* CONFIG_DCB */
1985 default:
1986 hw_dbg(hw, "Flow control param set incorrectly\n");
1987 ret_val = IXGBE_ERR_CONFIG;
1988 goto out;
1989 break;
1990 }
1991 /*
1992 * AUTOC restart handles negotiation of 1G and 10G. There is
1993 * no need to set the PCS1GCTL register.
1994 */
1995 reg |= IXGBE_AUTOC_AN_RESTART;
1996 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
1997 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
1998
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001999out:
2000 return ret_val;
2001}
2002
2003/**
Auke Kok9a799d72007-09-15 14:07:45 -07002004 * ixgbe_disable_pcie_master - Disable PCI-express master access
2005 * @hw: pointer to hardware structure
2006 *
2007 * Disables PCI-Express master access and verifies there are no pending
2008 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2009 * bit hasn't caused the master requests to be disabled, else 0
2010 * is returned signifying master requests disabled.
2011 **/
2012s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2013{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002014 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002015 u32 i;
2016 u32 reg_val;
2017 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002018 s32 status = 0;
2019 u16 dev_status = 0;
2020
2021 /* Just jump out if bus mastering is already disabled */
2022 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2023 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002024
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002025 /* Disable the receive unit by stopping each queue */
2026 number_of_queues = hw->mac.max_rx_queues;
2027 for (i = 0; i < number_of_queues; i++) {
2028 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2029 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2030 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2031 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2032 }
2033 }
2034
2035 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2036 reg_val |= IXGBE_CTRL_GIO_DIS;
2037 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002038
2039 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002040 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2041 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002042 udelay(100);
2043 }
2044
Emil Tantilova4297dc2011-02-14 08:45:13 +00002045 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2046 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2047
2048 /*
2049 * Before proceeding, make sure that the PCIe block does not have
2050 * transactions pending.
2051 */
2052check_device_status:
2053 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2054 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2055 &dev_status);
2056 if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2057 break;
2058 udelay(100);
2059 }
2060
2061 if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
2062 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2063 else
2064 goto out;
2065
2066 /*
2067 * Two consecutive resets are required via CTRL.RST per datasheet
2068 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2069 * of this need. The first reset prevents new master requests from
2070 * being issued by our device. We then must wait 1usec for any
2071 * remaining completions from the PCIe bus to trickle in, and then reset
2072 * again to clear out any effects they may have had on our device.
2073 */
2074 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2075
2076out:
Auke Kok9a799d72007-09-15 14:07:45 -07002077 return status;
2078}
2079
2080
2081/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002082 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002083 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002084 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002085 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002086 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002087 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2088 **/
2089s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2090{
2091 u32 gssr;
2092 u32 swmask = mask;
2093 u32 fwmask = mask << 5;
2094 s32 timeout = 200;
2095
2096 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002097 /*
2098 * SW EEPROM semaphore bit is used for access to all
2099 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2100 */
Auke Kok9a799d72007-09-15 14:07:45 -07002101 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002102 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002103
2104 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2105 if (!(gssr & (fwmask | swmask)))
2106 break;
2107
2108 /*
2109 * Firmware currently using resource (fwmask) or other software
2110 * thread currently using resource (swmask)
2111 */
2112 ixgbe_release_eeprom_semaphore(hw);
2113 msleep(5);
2114 timeout--;
2115 }
2116
2117 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002118 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002119 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002120 }
2121
2122 gssr |= swmask;
2123 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2124
2125 ixgbe_release_eeprom_semaphore(hw);
2126 return 0;
2127}
2128
2129/**
2130 * ixgbe_release_swfw_sync - Release SWFW semaphore
2131 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002132 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002133 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002134 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002135 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2136 **/
2137void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2138{
2139 u32 gssr;
2140 u32 swmask = mask;
2141
2142 ixgbe_get_eeprom_semaphore(hw);
2143
2144 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2145 gssr &= ~swmask;
2146 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2147
2148 ixgbe_release_eeprom_semaphore(hw);
2149}
2150
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002151/**
2152 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2153 * @hw: pointer to hardware structure
2154 * @regval: register value to write to RXCTRL
2155 *
2156 * Enables the Rx DMA unit
2157 **/
2158s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2159{
2160 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2161
2162 return 0;
2163}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002164
2165/**
2166 * ixgbe_blink_led_start_generic - Blink LED based on index.
2167 * @hw: pointer to hardware structure
2168 * @index: led number to blink
2169 **/
2170s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2171{
2172 ixgbe_link_speed speed = 0;
2173 bool link_up = 0;
2174 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2175 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2176
2177 /*
2178 * Link must be up to auto-blink the LEDs;
2179 * Force it if link is down.
2180 */
2181 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2182
2183 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002184 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002185 autoc_reg |= IXGBE_AUTOC_FLU;
2186 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2187 msleep(10);
2188 }
2189
2190 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2191 led_reg |= IXGBE_LED_BLINK(index);
2192 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2193 IXGBE_WRITE_FLUSH(hw);
2194
2195 return 0;
2196}
2197
2198/**
2199 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2200 * @hw: pointer to hardware structure
2201 * @index: led number to stop blinking
2202 **/
2203s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2204{
2205 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2206 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2207
2208 autoc_reg &= ~IXGBE_AUTOC_FLU;
2209 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2210 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2211
2212 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2213 led_reg &= ~IXGBE_LED_BLINK(index);
2214 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2215 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2216 IXGBE_WRITE_FLUSH(hw);
2217
2218 return 0;
2219}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002220
2221/**
2222 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2223 * @hw: pointer to hardware structure
2224 * @san_mac_offset: SAN MAC address offset
2225 *
2226 * This function will read the EEPROM location for the SAN MAC address
2227 * pointer, and returns the value at that location. This is used in both
2228 * get and set mac_addr routines.
2229 **/
2230static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2231 u16 *san_mac_offset)
2232{
2233 /*
2234 * First read the EEPROM pointer to see if the MAC addresses are
2235 * available.
2236 */
2237 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2238
2239 return 0;
2240}
2241
2242/**
2243 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2244 * @hw: pointer to hardware structure
2245 * @san_mac_addr: SAN MAC address
2246 *
2247 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2248 * per-port, so set_lan_id() must be called before reading the addresses.
2249 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2250 * upon for non-SFP connections, so we must call it here.
2251 **/
2252s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2253{
2254 u16 san_mac_data, san_mac_offset;
2255 u8 i;
2256
2257 /*
2258 * First read the EEPROM pointer to see if the MAC addresses are
2259 * available. If they're not, no point in calling set_lan_id() here.
2260 */
2261 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2262
2263 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2264 /*
2265 * No addresses available in this EEPROM. It's not an
2266 * error though, so just wipe the local address and return.
2267 */
2268 for (i = 0; i < 6; i++)
2269 san_mac_addr[i] = 0xFF;
2270
2271 goto san_mac_addr_out;
2272 }
2273
2274 /* make sure we know which port we need to program */
2275 hw->mac.ops.set_lan_id(hw);
2276 /* apply the port offset to the address offset */
2277 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2278 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2279 for (i = 0; i < 3; i++) {
2280 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2281 san_mac_addr[i * 2] = (u8)(san_mac_data);
2282 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2283 san_mac_offset++;
2284 }
2285
2286san_mac_addr_out:
2287 return 0;
2288}
2289
2290/**
2291 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2292 * @hw: pointer to hardware structure
2293 *
2294 * Read PCIe configuration space, and get the MSI-X vector count from
2295 * the capabilities table.
2296 **/
2297u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2298{
2299 struct ixgbe_adapter *adapter = hw->back;
2300 u16 msix_count;
2301 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2302 &msix_count);
2303 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2304
2305 /* MSI-X count is zero-based in HW, so increment to give proper value */
2306 msix_count++;
2307
2308 return msix_count;
2309}
2310
2311/**
2312 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2313 * @hw: pointer to hardware struct
2314 * @rar: receive address register index to disassociate
2315 * @vmdq: VMDq pool index to remove from the rar
2316 **/
2317s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2318{
2319 u32 mpsar_lo, mpsar_hi;
2320 u32 rar_entries = hw->mac.num_rar_entries;
2321
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002322 /* Make sure we are using a valid rar index range */
2323 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002324 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002325 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002326 }
2327
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002328 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2329 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2330
2331 if (!mpsar_lo && !mpsar_hi)
2332 goto done;
2333
2334 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2335 if (mpsar_lo) {
2336 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2337 mpsar_lo = 0;
2338 }
2339 if (mpsar_hi) {
2340 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2341 mpsar_hi = 0;
2342 }
2343 } else if (vmdq < 32) {
2344 mpsar_lo &= ~(1 << vmdq);
2345 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2346 } else {
2347 mpsar_hi &= ~(1 << (vmdq - 32));
2348 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2349 }
2350
2351 /* was that the last pool using this rar? */
2352 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2353 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002354done:
2355 return 0;
2356}
2357
2358/**
2359 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2360 * @hw: pointer to hardware struct
2361 * @rar: receive address register index to associate with a VMDq index
2362 * @vmdq: VMDq pool index
2363 **/
2364s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2365{
2366 u32 mpsar;
2367 u32 rar_entries = hw->mac.num_rar_entries;
2368
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002369 /* Make sure we are using a valid rar index range */
2370 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002371 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002372 return IXGBE_ERR_INVALID_ARGUMENT;
2373 }
2374
2375 if (vmdq < 32) {
2376 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2377 mpsar |= 1 << vmdq;
2378 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2379 } else {
2380 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2381 mpsar |= 1 << (vmdq - 32);
2382 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002383 }
2384 return 0;
2385}
2386
2387/**
2388 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2389 * @hw: pointer to hardware structure
2390 **/
2391s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2392{
2393 int i;
2394
2395
2396 for (i = 0; i < 128; i++)
2397 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2398
2399 return 0;
2400}
2401
2402/**
2403 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2404 * @hw: pointer to hardware structure
2405 * @vlan: VLAN id to write to VLAN filter
2406 *
2407 * return the VLVF index where this VLAN id should be placed
2408 *
2409 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002410static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002411{
2412 u32 bits = 0;
2413 u32 first_empty_slot = 0;
2414 s32 regindex;
2415
2416 /* short cut the special case */
2417 if (vlan == 0)
2418 return 0;
2419
2420 /*
2421 * Search for the vlan id in the VLVF entries. Save off the first empty
2422 * slot found along the way
2423 */
2424 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2425 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2426 if (!bits && !(first_empty_slot))
2427 first_empty_slot = regindex;
2428 else if ((bits & 0x0FFF) == vlan)
2429 break;
2430 }
2431
2432 /*
2433 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2434 * in the VLVF. Else use the first empty VLVF register for this
2435 * vlan id.
2436 */
2437 if (regindex >= IXGBE_VLVF_ENTRIES) {
2438 if (first_empty_slot)
2439 regindex = first_empty_slot;
2440 else {
2441 hw_dbg(hw, "No space in VLVF.\n");
2442 regindex = IXGBE_ERR_NO_SPACE;
2443 }
2444 }
2445
2446 return regindex;
2447}
2448
2449/**
2450 * ixgbe_set_vfta_generic - Set VLAN filter table
2451 * @hw: pointer to hardware structure
2452 * @vlan: VLAN id to write to VLAN filter
2453 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2454 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2455 *
2456 * Turn on/off specified VLAN in the VLAN filter table.
2457 **/
2458s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2459 bool vlan_on)
2460{
2461 s32 regindex;
2462 u32 bitindex;
2463 u32 vfta;
2464 u32 bits;
2465 u32 vt;
2466 u32 targetbit;
2467 bool vfta_changed = false;
2468
2469 if (vlan > 4095)
2470 return IXGBE_ERR_PARAM;
2471
2472 /*
2473 * this is a 2 part operation - first the VFTA, then the
2474 * VLVF and VLVFB if VT Mode is set
2475 * We don't write the VFTA until we know the VLVF part succeeded.
2476 */
2477
2478 /* Part 1
2479 * The VFTA is a bitstring made up of 128 32-bit registers
2480 * that enable the particular VLAN id, much like the MTA:
2481 * bits[11-5]: which register
2482 * bits[4-0]: which bit in the register
2483 */
2484 regindex = (vlan >> 5) & 0x7F;
2485 bitindex = vlan & 0x1F;
2486 targetbit = (1 << bitindex);
2487 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2488
2489 if (vlan_on) {
2490 if (!(vfta & targetbit)) {
2491 vfta |= targetbit;
2492 vfta_changed = true;
2493 }
2494 } else {
2495 if ((vfta & targetbit)) {
2496 vfta &= ~targetbit;
2497 vfta_changed = true;
2498 }
2499 }
2500
2501 /* Part 2
2502 * If VT Mode is set
2503 * Either vlan_on
2504 * make sure the vlan is in VLVF
2505 * set the vind bit in the matching VLVFB
2506 * Or !vlan_on
2507 * clear the pool bit and possibly the vind
2508 */
2509 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2510 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2511 s32 vlvf_index;
2512
2513 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2514 if (vlvf_index < 0)
2515 return vlvf_index;
2516
2517 if (vlan_on) {
2518 /* set the pool bit */
2519 if (vind < 32) {
2520 bits = IXGBE_READ_REG(hw,
2521 IXGBE_VLVFB(vlvf_index*2));
2522 bits |= (1 << vind);
2523 IXGBE_WRITE_REG(hw,
2524 IXGBE_VLVFB(vlvf_index*2),
2525 bits);
2526 } else {
2527 bits = IXGBE_READ_REG(hw,
2528 IXGBE_VLVFB((vlvf_index*2)+1));
2529 bits |= (1 << (vind-32));
2530 IXGBE_WRITE_REG(hw,
2531 IXGBE_VLVFB((vlvf_index*2)+1),
2532 bits);
2533 }
2534 } else {
2535 /* clear the pool bit */
2536 if (vind < 32) {
2537 bits = IXGBE_READ_REG(hw,
2538 IXGBE_VLVFB(vlvf_index*2));
2539 bits &= ~(1 << vind);
2540 IXGBE_WRITE_REG(hw,
2541 IXGBE_VLVFB(vlvf_index*2),
2542 bits);
2543 bits |= IXGBE_READ_REG(hw,
2544 IXGBE_VLVFB((vlvf_index*2)+1));
2545 } else {
2546 bits = IXGBE_READ_REG(hw,
2547 IXGBE_VLVFB((vlvf_index*2)+1));
2548 bits &= ~(1 << (vind-32));
2549 IXGBE_WRITE_REG(hw,
2550 IXGBE_VLVFB((vlvf_index*2)+1),
2551 bits);
2552 bits |= IXGBE_READ_REG(hw,
2553 IXGBE_VLVFB(vlvf_index*2));
2554 }
2555 }
2556
2557 /*
2558 * If there are still bits set in the VLVFB registers
2559 * for the VLAN ID indicated we need to see if the
2560 * caller is requesting that we clear the VFTA entry bit.
2561 * If the caller has requested that we clear the VFTA
2562 * entry bit but there are still pools/VFs using this VLAN
2563 * ID entry then ignore the request. We're not worried
2564 * about the case where we're turning the VFTA VLAN ID
2565 * entry bit on, only when requested to turn it off as
2566 * there may be multiple pools and/or VFs using the
2567 * VLAN ID entry. In that case we cannot clear the
2568 * VFTA bit until all pools/VFs using that VLAN ID have also
2569 * been cleared. This will be indicated by "bits" being
2570 * zero.
2571 */
2572 if (bits) {
2573 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2574 (IXGBE_VLVF_VIEN | vlan));
2575 if (!vlan_on) {
2576 /* someone wants to clear the vfta entry
2577 * but some pools/VFs are still using it.
2578 * Ignore it. */
2579 vfta_changed = false;
2580 }
2581 }
2582 else
2583 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
2584 }
2585
2586 if (vfta_changed)
2587 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
2588
2589 return 0;
2590}
2591
2592/**
2593 * ixgbe_clear_vfta_generic - Clear VLAN filter table
2594 * @hw: pointer to hardware structure
2595 *
2596 * Clears the VLAN filer table, and the VMDq index associated with the filter
2597 **/
2598s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
2599{
2600 u32 offset;
2601
2602 for (offset = 0; offset < hw->mac.vft_size; offset++)
2603 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
2604
2605 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
2606 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
2607 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
2608 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
2609 }
2610
2611 return 0;
2612}
2613
2614/**
2615 * ixgbe_check_mac_link_generic - Determine link and speed status
2616 * @hw: pointer to hardware structure
2617 * @speed: pointer to link speed
2618 * @link_up: true when link is up
2619 * @link_up_wait_to_complete: bool used to wait for link up or not
2620 *
2621 * Reads the links register to determine if link is up and the current speed
2622 **/
2623s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
2624 bool *link_up, bool link_up_wait_to_complete)
2625{
Emil Tantilov48de36c2011-02-16 01:38:08 +00002626 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002627 u32 i;
2628
Emil Tantilov48de36c2011-02-16 01:38:08 +00002629 /* clear the old state */
2630 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
2631
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002632 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00002633
2634 if (links_orig != links_reg) {
2635 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
2636 links_orig, links_reg);
2637 }
2638
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002639 if (link_up_wait_to_complete) {
2640 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2641 if (links_reg & IXGBE_LINKS_UP) {
2642 *link_up = true;
2643 break;
2644 } else {
2645 *link_up = false;
2646 }
2647 msleep(100);
2648 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2649 }
2650 } else {
2651 if (links_reg & IXGBE_LINKS_UP)
2652 *link_up = true;
2653 else
2654 *link_up = false;
2655 }
2656
2657 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2658 IXGBE_LINKS_SPEED_10G_82599)
2659 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2660 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
Emil Tantilov63d778d2011-02-19 08:43:39 +00002661 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002662 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002663 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2664 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002665 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002666 else
2667 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002668
2669 /* if link is down, zero out the current_mode */
2670 if (*link_up == false) {
2671 hw->fc.current_mode = ixgbe_fc_none;
2672 hw->fc.fc_was_autonegged = false;
2673 }
2674
2675 return 0;
2676}
Don Skidmorea391f1d2010-11-16 19:27:15 -08002677
2678/**
2679 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
2680 * the EEPROM
2681 * @hw: pointer to hardware structure
2682 * @wwnn_prefix: the alternative WWNN prefix
2683 * @wwpn_prefix: the alternative WWPN prefix
2684 *
2685 * This function will read the EEPROM from the alternative SAN MAC address
2686 * block to check the support for the alternative WWNN/WWPN prefix support.
2687 **/
2688s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2689 u16 *wwpn_prefix)
2690{
2691 u16 offset, caps;
2692 u16 alt_san_mac_blk_offset;
2693
2694 /* clear output first */
2695 *wwnn_prefix = 0xFFFF;
2696 *wwpn_prefix = 0xFFFF;
2697
2698 /* check if alternative SAN MAC is supported */
2699 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2700 &alt_san_mac_blk_offset);
2701
2702 if ((alt_san_mac_blk_offset == 0) ||
2703 (alt_san_mac_blk_offset == 0xFFFF))
2704 goto wwn_prefix_out;
2705
2706 /* check capability in alternative san mac address block */
2707 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2708 hw->eeprom.ops.read(hw, offset, &caps);
2709 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2710 goto wwn_prefix_out;
2711
2712 /* get the corresponding prefix for WWNN/WWPN */
2713 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2714 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2715
2716 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2717 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2718
2719wwn_prefix_out:
2720 return 0;
2721}
Greg Rosea985b6c32010-11-18 03:02:52 +00002722
2723/**
2724 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2725 * @hw: pointer to hardware structure
2726 * @enable: enable or disable switch for anti-spoofing
2727 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
2728 *
2729 **/
2730void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
2731{
2732 int j;
2733 int pf_target_reg = pf >> 3;
2734 int pf_target_shift = pf % 8;
2735 u32 pfvfspoof = 0;
2736
2737 if (hw->mac.type == ixgbe_mac_82598EB)
2738 return;
2739
2740 if (enable)
2741 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
2742
2743 /*
2744 * PFVFSPOOF register array is size 8 with 8 bits assigned to
2745 * MAC anti-spoof enables in each register array element.
2746 */
2747 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
2748 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
2749
2750 /* If not enabling anti-spoofing then done */
2751 if (!enable)
2752 return;
2753
2754 /*
2755 * The PF should be allowed to spoof so that it can support
2756 * emulation mode NICs. Reset the bit assigned to the PF
2757 */
2758 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
2759 pfvfspoof ^= (1 << pf_target_shift);
2760 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
2761}
2762
2763/**
2764 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
2765 * @hw: pointer to hardware structure
2766 * @enable: enable or disable switch for VLAN anti-spoofing
2767 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
2768 *
2769 **/
2770void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
2771{
2772 int vf_target_reg = vf >> 3;
2773 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
2774 u32 pfvfspoof;
2775
2776 if (hw->mac.type == ixgbe_mac_82598EB)
2777 return;
2778
2779 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2780 if (enable)
2781 pfvfspoof |= (1 << vf_target_shift);
2782 else
2783 pfvfspoof &= ~(1 << vf_target_shift);
2784 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2785}