blob: db339d6fe63d06b6e95c60e96e78a247aa409c2c [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -08004 Copyright(c) 1999 - 2009 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/list.h>
32#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070033
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000034#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070035#include "ixgbe_common.h"
36#include "ixgbe_phy.h"
37
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070039static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070040static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
41static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070042static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
43static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
44static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
45 u16 count);
46static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
47static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
48static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
49static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070050static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
51
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070052static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
53static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
Auke Kok9a799d72007-09-15 14:07:45 -070054static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070055static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
Auke Kok9a799d72007-09-15 14:07:45 -070056
57/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070058 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070059 * @hw: pointer to hardware structure
60 *
61 * Starts the hardware by filling the bus info structure and media type, clears
62 * all on chip counters, initializes receive address registers, multicast
63 * table, VLAN filter table, calls routine to set up link and flow control
64 * settings, and leaves transmit and receive units disabled and uninitialized
65 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070066s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070067{
68 u32 ctrl_ext;
69
70 /* Set the media type */
71 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
72
73 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070074 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070075
Auke Kok9a799d72007-09-15 14:07:45 -070076 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070077 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070078
Auke Kok9a799d72007-09-15 14:07:45 -070079 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070080 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070081
82 /* Set No Snoop Disable */
83 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
84 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
85 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070086 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070087
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000088 /* Setup flow control */
89 ixgbe_setup_fc(hw, 0);
90
Auke Kok9a799d72007-09-15 14:07:45 -070091 /* Clear adapter stopped flag */
92 hw->adapter_stopped = false;
93
94 return 0;
95}
96
97/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070098 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -070099 * @hw: pointer to hardware structure
100 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700101 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700102 * structure and media type, clears all on chip counters, initializes receive
103 * address registers, multicast table, VLAN filter table, calls routine to set
104 * up link and flow control settings, and leaves transmit and receive units
105 * disabled and uninitialized
106 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700107s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700108{
109 /* Reset the hardware */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700110 hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700111
112 /* Start the HW */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700113 hw->mac.ops.start_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700114
115 return 0;
116}
117
118/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700119 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700120 * @hw: pointer to hardware structure
121 *
122 * Clears all hardware statistics counters by reading them from the hardware
123 * Statistics counters are clear on read.
124 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700125s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700126{
127 u16 i = 0;
128
129 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
130 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
131 IXGBE_READ_REG(hw, IXGBE_ERRBC);
132 IXGBE_READ_REG(hw, IXGBE_MSPDC);
133 for (i = 0; i < 8; i++)
134 IXGBE_READ_REG(hw, IXGBE_MPC(i));
135
136 IXGBE_READ_REG(hw, IXGBE_MLFC);
137 IXGBE_READ_REG(hw, IXGBE_MRFC);
138 IXGBE_READ_REG(hw, IXGBE_RLEC);
139 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
140 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
141 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
142 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
143
144 for (i = 0; i < 8; i++) {
145 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
146 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
147 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
148 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
149 }
150
151 IXGBE_READ_REG(hw, IXGBE_PRC64);
152 IXGBE_READ_REG(hw, IXGBE_PRC127);
153 IXGBE_READ_REG(hw, IXGBE_PRC255);
154 IXGBE_READ_REG(hw, IXGBE_PRC511);
155 IXGBE_READ_REG(hw, IXGBE_PRC1023);
156 IXGBE_READ_REG(hw, IXGBE_PRC1522);
157 IXGBE_READ_REG(hw, IXGBE_GPRC);
158 IXGBE_READ_REG(hw, IXGBE_BPRC);
159 IXGBE_READ_REG(hw, IXGBE_MPRC);
160 IXGBE_READ_REG(hw, IXGBE_GPTC);
161 IXGBE_READ_REG(hw, IXGBE_GORCL);
162 IXGBE_READ_REG(hw, IXGBE_GORCH);
163 IXGBE_READ_REG(hw, IXGBE_GOTCL);
164 IXGBE_READ_REG(hw, IXGBE_GOTCH);
165 for (i = 0; i < 8; i++)
166 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
167 IXGBE_READ_REG(hw, IXGBE_RUC);
168 IXGBE_READ_REG(hw, IXGBE_RFC);
169 IXGBE_READ_REG(hw, IXGBE_ROC);
170 IXGBE_READ_REG(hw, IXGBE_RJC);
171 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
172 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
173 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
174 IXGBE_READ_REG(hw, IXGBE_TORL);
175 IXGBE_READ_REG(hw, IXGBE_TORH);
176 IXGBE_READ_REG(hw, IXGBE_TPR);
177 IXGBE_READ_REG(hw, IXGBE_TPT);
178 IXGBE_READ_REG(hw, IXGBE_PTC64);
179 IXGBE_READ_REG(hw, IXGBE_PTC127);
180 IXGBE_READ_REG(hw, IXGBE_PTC255);
181 IXGBE_READ_REG(hw, IXGBE_PTC511);
182 IXGBE_READ_REG(hw, IXGBE_PTC1023);
183 IXGBE_READ_REG(hw, IXGBE_PTC1522);
184 IXGBE_READ_REG(hw, IXGBE_MPTC);
185 IXGBE_READ_REG(hw, IXGBE_BPTC);
186 for (i = 0; i < 16; i++) {
187 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
188 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
189 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
190 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
191 }
192
193 return 0;
194}
195
196/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700197 * ixgbe_read_pba_num_generic - Reads part number from EEPROM
198 * @hw: pointer to hardware structure
199 * @pba_num: stores the part number from the EEPROM
200 *
201 * Reads the part number from the EEPROM.
202 **/
203s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
204{
205 s32 ret_val;
206 u16 data;
207
208 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
209 if (ret_val) {
210 hw_dbg(hw, "NVM Read Error\n");
211 return ret_val;
212 }
213 *pba_num = (u32)(data << 16);
214
215 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
216 if (ret_val) {
217 hw_dbg(hw, "NVM Read Error\n");
218 return ret_val;
219 }
220 *pba_num |= data;
221
222 return 0;
223}
224
225/**
226 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700227 * @hw: pointer to hardware structure
228 * @mac_addr: Adapter MAC address
229 *
230 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
231 * A reset of the adapter must be performed prior to calling this function
232 * in order for the MAC address to have been loaded from the EEPROM into RAR0
233 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700234s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700235{
236 u32 rar_high;
237 u32 rar_low;
238 u16 i;
239
240 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
241 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
242
243 for (i = 0; i < 4; i++)
244 mac_addr[i] = (u8)(rar_low >> (i*8));
245
246 for (i = 0; i < 2; i++)
247 mac_addr[i+4] = (u8)(rar_high >> (i*8));
248
249 return 0;
250}
251
Auke Kok9a799d72007-09-15 14:07:45 -0700252/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000253 * ixgbe_get_bus_info_generic - Generic set PCI bus info
254 * @hw: pointer to hardware structure
255 *
256 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
257 **/
258s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
259{
260 struct ixgbe_adapter *adapter = hw->back;
261 struct ixgbe_mac_info *mac = &hw->mac;
262 u16 link_status;
263
264 hw->bus.type = ixgbe_bus_type_pci_express;
265
266 /* Get the negotiated link width and speed from PCI config space */
267 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
268 &link_status);
269
270 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
271 case IXGBE_PCI_LINK_WIDTH_1:
272 hw->bus.width = ixgbe_bus_width_pcie_x1;
273 break;
274 case IXGBE_PCI_LINK_WIDTH_2:
275 hw->bus.width = ixgbe_bus_width_pcie_x2;
276 break;
277 case IXGBE_PCI_LINK_WIDTH_4:
278 hw->bus.width = ixgbe_bus_width_pcie_x4;
279 break;
280 case IXGBE_PCI_LINK_WIDTH_8:
281 hw->bus.width = ixgbe_bus_width_pcie_x8;
282 break;
283 default:
284 hw->bus.width = ixgbe_bus_width_unknown;
285 break;
286 }
287
288 switch (link_status & IXGBE_PCI_LINK_SPEED) {
289 case IXGBE_PCI_LINK_SPEED_2500:
290 hw->bus.speed = ixgbe_bus_speed_2500;
291 break;
292 case IXGBE_PCI_LINK_SPEED_5000:
293 hw->bus.speed = ixgbe_bus_speed_5000;
294 break;
295 default:
296 hw->bus.speed = ixgbe_bus_speed_unknown;
297 break;
298 }
299
300 mac->ops.set_lan_id(hw);
301
302 return 0;
303}
304
305/**
306 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
307 * @hw: pointer to the HW structure
308 *
309 * Determines the LAN function id by reading memory-mapped registers
310 * and swaps the port value if requested.
311 **/
312void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
313{
314 struct ixgbe_bus_info *bus = &hw->bus;
315 u32 reg;
316
317 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
318 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
319 bus->lan_id = bus->func;
320
321 /* check for a port swap */
322 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
323 if (reg & IXGBE_FACTPS_LFS)
324 bus->func ^= 0x1;
325}
326
327/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700328 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700329 * @hw: pointer to hardware structure
330 *
331 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
332 * disables transmit and receive units. The adapter_stopped flag is used by
333 * the shared code and drivers to determine if the adapter is in a stopped
334 * state and should not touch the hardware.
335 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700336s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700337{
338 u32 number_of_queues;
339 u32 reg_val;
340 u16 i;
341
342 /*
343 * Set the adapter_stopped flag so other driver functions stop touching
344 * the hardware
345 */
346 hw->adapter_stopped = true;
347
348 /* Disable the receive unit */
349 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
350 reg_val &= ~(IXGBE_RXCTRL_RXEN);
351 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700352 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700353 msleep(2);
354
355 /* Clear interrupt mask to stop from interrupts being generated */
356 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
357
358 /* Clear any pending interrupts */
359 IXGBE_READ_REG(hw, IXGBE_EICR);
360
361 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700362 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700363 for (i = 0; i < number_of_queues; i++) {
364 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
365 if (reg_val & IXGBE_TXDCTL_ENABLE) {
366 reg_val &= ~IXGBE_TXDCTL_ENABLE;
367 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
368 }
369 }
370
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700371 /*
372 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
373 * access and verify no pending requests
374 */
375 if (ixgbe_disable_pcie_master(hw) != 0)
376 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
377
Auke Kok9a799d72007-09-15 14:07:45 -0700378 return 0;
379}
380
381/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700382 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700383 * @hw: pointer to hardware structure
384 * @index: led number to turn on
385 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700386s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700387{
388 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
389
390 /* To turn on the LED, set mode to ON. */
391 led_reg &= ~IXGBE_LED_MODE_MASK(index);
392 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
393 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700394 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700395
396 return 0;
397}
398
399/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700400 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700401 * @hw: pointer to hardware structure
402 * @index: led number to turn off
403 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700404s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700405{
406 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
407
408 /* To turn off the LED, set mode to OFF. */
409 led_reg &= ~IXGBE_LED_MODE_MASK(index);
410 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
411 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700412 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700413
414 return 0;
415}
416
Auke Kok9a799d72007-09-15 14:07:45 -0700417/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700418 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700419 * @hw: pointer to hardware structure
420 *
421 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
422 * ixgbe_hw struct in order to set up EEPROM access.
423 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700424s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700425{
426 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
427 u32 eec;
428 u16 eeprom_size;
429
430 if (eeprom->type == ixgbe_eeprom_uninitialized) {
431 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700432 /* Set default semaphore delay to 10ms which is a well
433 * tested value */
434 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700435
436 /*
437 * Check for EEPROM present first.
438 * If not present leave as none
439 */
440 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
441 if (eec & IXGBE_EEC_PRES) {
442 eeprom->type = ixgbe_eeprom_spi;
443
444 /*
445 * SPI EEPROM is assumed here. This code would need to
446 * change if a future EEPROM is not SPI.
447 */
448 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
449 IXGBE_EEC_SIZE_SHIFT);
450 eeprom->word_size = 1 << (eeprom_size +
451 IXGBE_EEPROM_WORD_SIZE_SHIFT);
452 }
453
454 if (eec & IXGBE_EEC_ADDR_SIZE)
455 eeprom->address_bits = 16;
456 else
457 eeprom->address_bits = 8;
458 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
459 "%d\n", eeprom->type, eeprom->word_size,
460 eeprom->address_bits);
461 }
462
463 return 0;
464}
465
466/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000467 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
468 * @hw: pointer to hardware structure
469 * @offset: offset within the EEPROM to be written to
470 * @data: 16 bit word to be written to the EEPROM
471 *
472 * If ixgbe_eeprom_update_checksum is not called after this function, the
473 * EEPROM will most likely contain an invalid checksum.
474 **/
475s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
476{
477 s32 status;
478 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
479
480 hw->eeprom.ops.init_params(hw);
481
482 if (offset >= hw->eeprom.word_size) {
483 status = IXGBE_ERR_EEPROM;
484 goto out;
485 }
486
487 /* Prepare the EEPROM for writing */
488 status = ixgbe_acquire_eeprom(hw);
489
490 if (status == 0) {
491 if (ixgbe_ready_eeprom(hw) != 0) {
492 ixgbe_release_eeprom(hw);
493 status = IXGBE_ERR_EEPROM;
494 }
495 }
496
497 if (status == 0) {
498 ixgbe_standby_eeprom(hw);
499
500 /* Send the WRITE ENABLE command (8 bit opcode ) */
501 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
502 IXGBE_EEPROM_OPCODE_BITS);
503
504 ixgbe_standby_eeprom(hw);
505
506 /*
507 * Some SPI eeproms use the 8th address bit embedded in the
508 * opcode
509 */
510 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
511 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
512
513 /* Send the Write command (8-bit opcode + addr) */
514 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
515 IXGBE_EEPROM_OPCODE_BITS);
516 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
517 hw->eeprom.address_bits);
518
519 /* Send the data */
520 data = (data >> 8) | (data << 8);
521 ixgbe_shift_out_eeprom_bits(hw, data, 16);
522 ixgbe_standby_eeprom(hw);
523
524 msleep(hw->eeprom.semaphore_delay);
525 /* Done with writing - release the EEPROM */
526 ixgbe_release_eeprom(hw);
527 }
528
529out:
530 return status;
531}
532
533/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700534 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
535 * @hw: pointer to hardware structure
536 * @offset: offset within the EEPROM to be read
537 * @data: read 16 bit value from EEPROM
538 *
539 * Reads 16 bit value from EEPROM through bit-bang method
540 **/
541s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
542 u16 *data)
543{
544 s32 status;
545 u16 word_in;
546 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
547
548 hw->eeprom.ops.init_params(hw);
549
550 if (offset >= hw->eeprom.word_size) {
551 status = IXGBE_ERR_EEPROM;
552 goto out;
553 }
554
555 /* Prepare the EEPROM for reading */
556 status = ixgbe_acquire_eeprom(hw);
557
558 if (status == 0) {
559 if (ixgbe_ready_eeprom(hw) != 0) {
560 ixgbe_release_eeprom(hw);
561 status = IXGBE_ERR_EEPROM;
562 }
563 }
564
565 if (status == 0) {
566 ixgbe_standby_eeprom(hw);
567
568 /*
569 * Some SPI eeproms use the 8th address bit embedded in the
570 * opcode
571 */
572 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
573 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
574
575 /* Send the READ command (opcode + addr) */
576 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
577 IXGBE_EEPROM_OPCODE_BITS);
578 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
579 hw->eeprom.address_bits);
580
581 /* Read the data. */
582 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
583 *data = (word_in >> 8) | (word_in << 8);
584
585 /* End this read operation */
586 ixgbe_release_eeprom(hw);
587 }
588
589out:
590 return status;
591}
592
593/**
594 * ixgbe_read_eeprom_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700595 * @hw: pointer to hardware structure
596 * @offset: offset of word in the EEPROM to read
597 * @data: word read from the EEPROM
598 *
599 * Reads a 16 bit word from the EEPROM using the EERD register.
600 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700601s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700602{
603 u32 eerd;
604 s32 status;
605
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700606 hw->eeprom.ops.init_params(hw);
607
608 if (offset >= hw->eeprom.word_size) {
609 status = IXGBE_ERR_EEPROM;
610 goto out;
611 }
612
Auke Kok9a799d72007-09-15 14:07:45 -0700613 eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
614 IXGBE_EEPROM_READ_REG_START;
615
616 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
617 status = ixgbe_poll_eeprom_eerd_done(hw);
618
619 if (status == 0)
620 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700621 IXGBE_EEPROM_READ_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700622 else
623 hw_dbg(hw, "Eeprom read timed out\n");
624
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700625out:
Auke Kok9a799d72007-09-15 14:07:45 -0700626 return status;
627}
628
629/**
630 * ixgbe_poll_eeprom_eerd_done - Poll EERD status
631 * @hw: pointer to hardware structure
632 *
633 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
634 **/
635static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
636{
637 u32 i;
638 u32 reg;
639 s32 status = IXGBE_ERR_EEPROM;
640
641 for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
642 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
643 if (reg & IXGBE_EEPROM_READ_REG_DONE) {
644 status = 0;
645 break;
646 }
647 udelay(5);
648 }
649 return status;
650}
651
652/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700653 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
654 * @hw: pointer to hardware structure
655 *
656 * Prepares EEPROM for access using bit-bang method. This function should
657 * be called before issuing a command to the EEPROM.
658 **/
659static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
660{
661 s32 status = 0;
David S. Millerfc1f2092009-03-01 20:32:39 -0800662 u32 eec = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700663 u32 i;
664
665 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
666 status = IXGBE_ERR_SWFW_SYNC;
667
668 if (status == 0) {
669 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
670
671 /* Request EEPROM Access */
672 eec |= IXGBE_EEC_REQ;
673 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
674
675 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
676 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
677 if (eec & IXGBE_EEC_GNT)
678 break;
679 udelay(5);
680 }
681
682 /* Release if grant not acquired */
683 if (!(eec & IXGBE_EEC_GNT)) {
684 eec &= ~IXGBE_EEC_REQ;
685 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
686 hw_dbg(hw, "Could not acquire EEPROM grant\n");
687
688 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
689 status = IXGBE_ERR_EEPROM;
690 }
691 }
692
693 /* Setup EEPROM for Read/Write */
694 if (status == 0) {
695 /* Clear CS and SK */
696 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
697 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
698 IXGBE_WRITE_FLUSH(hw);
699 udelay(1);
700 }
701 return status;
702}
703
704/**
Auke Kok9a799d72007-09-15 14:07:45 -0700705 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
706 * @hw: pointer to hardware structure
707 *
708 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
709 **/
710static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
711{
712 s32 status = IXGBE_ERR_EEPROM;
713 u32 timeout;
714 u32 i;
715 u32 swsm;
716
717 /* Set timeout value based on size of EEPROM */
718 timeout = hw->eeprom.word_size + 1;
719
720 /* Get SMBI software semaphore between device drivers first */
721 for (i = 0; i < timeout; i++) {
722 /*
723 * If the SMBI bit is 0 when we read it, then the bit will be
724 * set and we have the semaphore
725 */
726 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
727 if (!(swsm & IXGBE_SWSM_SMBI)) {
728 status = 0;
729 break;
730 }
731 msleep(1);
732 }
733
734 /* Now get the semaphore between SW/FW through the SWESMBI bit */
735 if (status == 0) {
736 for (i = 0; i < timeout; i++) {
737 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
738
739 /* Set the SW EEPROM semaphore bit to request access */
740 swsm |= IXGBE_SWSM_SWESMBI;
741 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
742
743 /*
744 * If we set the bit successfully then we got the
745 * semaphore.
746 */
747 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
748 if (swsm & IXGBE_SWSM_SWESMBI)
749 break;
750
751 udelay(50);
752 }
753
754 /*
755 * Release semaphores and return error if SW EEPROM semaphore
756 * was not granted because we don't have access to the EEPROM
757 */
758 if (i >= timeout) {
759 hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700760 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700761 ixgbe_release_eeprom_semaphore(hw);
762 status = IXGBE_ERR_EEPROM;
763 }
764 }
765
766 return status;
767}
768
769/**
770 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
771 * @hw: pointer to hardware structure
772 *
773 * This function clears hardware semaphore bits.
774 **/
775static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
776{
777 u32 swsm;
778
779 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
780
781 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
782 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
783 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700784 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700785}
786
787/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700788 * ixgbe_ready_eeprom - Polls for EEPROM ready
789 * @hw: pointer to hardware structure
790 **/
791static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
792{
793 s32 status = 0;
794 u16 i;
795 u8 spi_stat_reg;
796
797 /*
798 * Read "Status Register" repeatedly until the LSB is cleared. The
799 * EEPROM will signal that the command has been completed by clearing
800 * bit 0 of the internal status register. If it's not cleared within
801 * 5 milliseconds, then error out.
802 */
803 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
804 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
805 IXGBE_EEPROM_OPCODE_BITS);
806 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
807 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
808 break;
809
810 udelay(5);
811 ixgbe_standby_eeprom(hw);
812 };
813
814 /*
815 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
816 * devices (and only 0-5mSec on 5V devices)
817 */
818 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
819 hw_dbg(hw, "SPI EEPROM Status error\n");
820 status = IXGBE_ERR_EEPROM;
821 }
822
823 return status;
824}
825
826/**
827 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
828 * @hw: pointer to hardware structure
829 **/
830static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
831{
832 u32 eec;
833
834 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
835
836 /* Toggle CS to flush commands */
837 eec |= IXGBE_EEC_CS;
838 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
839 IXGBE_WRITE_FLUSH(hw);
840 udelay(1);
841 eec &= ~IXGBE_EEC_CS;
842 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
843 IXGBE_WRITE_FLUSH(hw);
844 udelay(1);
845}
846
847/**
848 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
849 * @hw: pointer to hardware structure
850 * @data: data to send to the EEPROM
851 * @count: number of bits to shift out
852 **/
853static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
854 u16 count)
855{
856 u32 eec;
857 u32 mask;
858 u32 i;
859
860 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
861
862 /*
863 * Mask is used to shift "count" bits of "data" out to the EEPROM
864 * one bit at a time. Determine the starting bit based on count
865 */
866 mask = 0x01 << (count - 1);
867
868 for (i = 0; i < count; i++) {
869 /*
870 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
871 * "1", and then raising and then lowering the clock (the SK
872 * bit controls the clock input to the EEPROM). A "0" is
873 * shifted out to the EEPROM by setting "DI" to "0" and then
874 * raising and then lowering the clock.
875 */
876 if (data & mask)
877 eec |= IXGBE_EEC_DI;
878 else
879 eec &= ~IXGBE_EEC_DI;
880
881 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
882 IXGBE_WRITE_FLUSH(hw);
883
884 udelay(1);
885
886 ixgbe_raise_eeprom_clk(hw, &eec);
887 ixgbe_lower_eeprom_clk(hw, &eec);
888
889 /*
890 * Shift mask to signify next bit of data to shift in to the
891 * EEPROM
892 */
893 mask = mask >> 1;
894 };
895
896 /* We leave the "DI" bit set to "0" when we leave this routine. */
897 eec &= ~IXGBE_EEC_DI;
898 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
899 IXGBE_WRITE_FLUSH(hw);
900}
901
902/**
903 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
904 * @hw: pointer to hardware structure
905 **/
906static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
907{
908 u32 eec;
909 u32 i;
910 u16 data = 0;
911
912 /*
913 * In order to read a register from the EEPROM, we need to shift
914 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
915 * the clock input to the EEPROM (setting the SK bit), and then reading
916 * the value of the "DO" bit. During this "shifting in" process the
917 * "DI" bit should always be clear.
918 */
919 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
920
921 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
922
923 for (i = 0; i < count; i++) {
924 data = data << 1;
925 ixgbe_raise_eeprom_clk(hw, &eec);
926
927 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
928
929 eec &= ~(IXGBE_EEC_DI);
930 if (eec & IXGBE_EEC_DO)
931 data |= 1;
932
933 ixgbe_lower_eeprom_clk(hw, &eec);
934 }
935
936 return data;
937}
938
939/**
940 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
941 * @hw: pointer to hardware structure
942 * @eec: EEC register's current value
943 **/
944static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
945{
946 /*
947 * Raise the clock input to the EEPROM
948 * (setting the SK bit), then delay
949 */
950 *eec = *eec | IXGBE_EEC_SK;
951 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
952 IXGBE_WRITE_FLUSH(hw);
953 udelay(1);
954}
955
956/**
957 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
958 * @hw: pointer to hardware structure
959 * @eecd: EECD's current value
960 **/
961static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
962{
963 /*
964 * Lower the clock input to the EEPROM (clearing the SK bit), then
965 * delay
966 */
967 *eec = *eec & ~IXGBE_EEC_SK;
968 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
969 IXGBE_WRITE_FLUSH(hw);
970 udelay(1);
971}
972
973/**
974 * ixgbe_release_eeprom - Release EEPROM, release semaphores
975 * @hw: pointer to hardware structure
976 **/
977static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
978{
979 u32 eec;
980
981 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
982
983 eec |= IXGBE_EEC_CS; /* Pull CS high */
984 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
985
986 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
987 IXGBE_WRITE_FLUSH(hw);
988
989 udelay(1);
990
991 /* Stop requesting EEPROM access */
992 eec &= ~IXGBE_EEC_REQ;
993 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
994
995 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
996}
997
998/**
Auke Kok9a799d72007-09-15 14:07:45 -0700999 * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
1000 * @hw: pointer to hardware structure
1001 **/
1002static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
1003{
1004 u16 i;
1005 u16 j;
1006 u16 checksum = 0;
1007 u16 length = 0;
1008 u16 pointer = 0;
1009 u16 word = 0;
1010
1011 /* Include 0x0-0x3F in the checksum */
1012 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001013 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001014 hw_dbg(hw, "EEPROM read failed\n");
1015 break;
1016 }
1017 checksum += word;
1018 }
1019
1020 /* Include all data from pointers except for the fw pointer */
1021 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001022 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001023
1024 /* Make sure the pointer seems valid */
1025 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001026 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001027
1028 if (length != 0xFFFF && length != 0) {
1029 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001030 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001031 checksum += word;
1032 }
1033 }
1034 }
1035 }
1036
1037 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1038
1039 return checksum;
1040}
1041
1042/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001043 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001044 * @hw: pointer to hardware structure
1045 * @checksum_val: calculated checksum
1046 *
1047 * Performs checksum calculation and validates the EEPROM checksum. If the
1048 * caller does not need checksum_val, the value can be NULL.
1049 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001050s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1051 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001052{
1053 s32 status;
1054 u16 checksum;
1055 u16 read_checksum = 0;
1056
1057 /*
1058 * Read the first word from the EEPROM. If this times out or fails, do
1059 * not continue or we could be in for a very long wait while every
1060 * EEPROM read fails
1061 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001062 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001063
1064 if (status == 0) {
1065 checksum = ixgbe_calc_eeprom_checksum(hw);
1066
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001067 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001068
1069 /*
1070 * Verify read checksum from EEPROM is the same as
1071 * calculated checksum
1072 */
1073 if (read_checksum != checksum)
1074 status = IXGBE_ERR_EEPROM_CHECKSUM;
1075
1076 /* If the user cares, return the calculated checksum */
1077 if (checksum_val)
1078 *checksum_val = checksum;
1079 } else {
1080 hw_dbg(hw, "EEPROM read failed\n");
1081 }
1082
1083 return status;
1084}
1085
1086/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001087 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1088 * @hw: pointer to hardware structure
1089 **/
1090s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1091{
1092 s32 status;
1093 u16 checksum;
1094
1095 /*
1096 * Read the first word from the EEPROM. If this times out or fails, do
1097 * not continue or we could be in for a very long wait while every
1098 * EEPROM read fails
1099 */
1100 status = hw->eeprom.ops.read(hw, 0, &checksum);
1101
1102 if (status == 0) {
1103 checksum = ixgbe_calc_eeprom_checksum(hw);
1104 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1105 checksum);
1106 } else {
1107 hw_dbg(hw, "EEPROM read failed\n");
1108 }
1109
1110 return status;
1111}
1112
1113/**
Auke Kok9a799d72007-09-15 14:07:45 -07001114 * ixgbe_validate_mac_addr - Validate MAC address
1115 * @mac_addr: pointer to MAC address.
1116 *
1117 * Tests a MAC address to ensure it is a valid Individual Address
1118 **/
1119s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1120{
1121 s32 status = 0;
1122
1123 /* Make sure it is not a multicast address */
1124 if (IXGBE_IS_MULTICAST(mac_addr))
1125 status = IXGBE_ERR_INVALID_MAC_ADDR;
1126 /* Not a broadcast address */
1127 else if (IXGBE_IS_BROADCAST(mac_addr))
1128 status = IXGBE_ERR_INVALID_MAC_ADDR;
1129 /* Reject the zero address */
1130 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001131 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001132 status = IXGBE_ERR_INVALID_MAC_ADDR;
1133
1134 return status;
1135}
1136
1137/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001138 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001139 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001140 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001141 * @addr: Address to put into receive address register
1142 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001143 * @enable_addr: set flag that address is active
1144 *
1145 * Puts an ethernet address into a receive address register.
1146 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001147s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1148 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001149{
1150 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001151 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001152
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001153 /* setup VMDq pool selection before this RAR gets enabled */
1154 hw->mac.ops.set_vmdq(hw, index, vmdq);
1155
1156 /* Make sure we are using a valid rar index range */
1157 if (index < rar_entries) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001158 /*
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001159 * HW expects these in little endian so we reverse the byte
1160 * order from network order (big endian) to little endian
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001161 */
1162 rar_low = ((u32)addr[0] |
1163 ((u32)addr[1] << 8) |
1164 ((u32)addr[2] << 16) |
1165 ((u32)addr[3] << 24));
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001166 /*
1167 * Some parts put the VMDq setting in the extra RAH bits,
1168 * so save everything except the lower 16 bits that hold part
1169 * of the address and the address valid bit.
1170 */
1171 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1172 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1173 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001174
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001175 if (enable_addr != 0)
1176 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001177
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001178 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1179 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001180 } else {
1181 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1182 }
Auke Kok9a799d72007-09-15 14:07:45 -07001183
1184 return 0;
1185}
1186
1187/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001188 * ixgbe_clear_rar_generic - Remove Rx address register
1189 * @hw: pointer to hardware structure
1190 * @index: Receive address register to write
1191 *
1192 * Clears an ethernet address from a receive address register.
1193 **/
1194s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1195{
1196 u32 rar_high;
1197 u32 rar_entries = hw->mac.num_rar_entries;
1198
1199 /* Make sure we are using a valid rar index range */
1200 if (index < rar_entries) {
1201 /*
1202 * Some parts put the VMDq setting in the extra RAH bits,
1203 * so save everything except the lower 16 bits that hold part
1204 * of the address and the address valid bit.
1205 */
1206 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1207 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1208
1209 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1210 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1211 } else {
1212 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1213 }
1214
1215 /* clear VMDq pool/queue selection for this RAR */
1216 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1217
1218 return 0;
1219}
1220
1221/**
1222 * ixgbe_enable_rar - Enable Rx address register
1223 * @hw: pointer to hardware structure
1224 * @index: index into the RAR table
1225 *
1226 * Enables the select receive address register.
1227 **/
1228static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
1229{
1230 u32 rar_high;
1231
1232 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1233 rar_high |= IXGBE_RAH_AV;
1234 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1235}
1236
1237/**
1238 * ixgbe_disable_rar - Disable Rx address register
1239 * @hw: pointer to hardware structure
1240 * @index: index into the RAR table
1241 *
1242 * Disables the select receive address register.
1243 **/
1244static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
1245{
1246 u32 rar_high;
1247
1248 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1249 rar_high &= (~IXGBE_RAH_AV);
1250 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1251}
1252
1253/**
1254 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001255 * @hw: pointer to hardware structure
1256 *
1257 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001258 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001259 * the receiver is in reset when the routine is called.
1260 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001261s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001262{
1263 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001264 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001265
1266 /*
1267 * If the current mac address is valid, assume it is a software override
1268 * to the permanent address.
1269 * Otherwise, use the permanent address from the eeprom.
1270 */
1271 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1272 IXGBE_ERR_INVALID_MAC_ADDR) {
1273 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001274 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001275
1276 hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001277 hw->mac.addr[0], hw->mac.addr[1],
1278 hw->mac.addr[2]);
Auke Kok9a799d72007-09-15 14:07:45 -07001279 hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001280 hw->mac.addr[4], hw->mac.addr[5]);
Auke Kok9a799d72007-09-15 14:07:45 -07001281 } else {
1282 /* Setup the receive address. */
1283 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
1284 hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001285 hw->mac.addr[0], hw->mac.addr[1],
1286 hw->mac.addr[2]);
Auke Kok9a799d72007-09-15 14:07:45 -07001287 hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001288 hw->mac.addr[4], hw->mac.addr[5]);
Auke Kok9a799d72007-09-15 14:07:45 -07001289
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001290 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07001291 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001292 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001293
1294 hw->addr_ctrl.rar_used_count = 1;
1295
1296 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001297 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001298 for (i = 1; i < rar_entries; i++) {
1299 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1300 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1301 }
1302
1303 /* Clear the MTA */
1304 hw->addr_ctrl.mc_addr_in_rar_count = 0;
1305 hw->addr_ctrl.mta_in_use = 0;
1306 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1307
1308 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001309 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001310 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1311
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001312 if (hw->mac.ops.init_uta_tables)
1313 hw->mac.ops.init_uta_tables(hw);
1314
Auke Kok9a799d72007-09-15 14:07:45 -07001315 return 0;
1316}
1317
1318/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001319 * ixgbe_add_uc_addr - Adds a secondary unicast address.
1320 * @hw: pointer to hardware structure
1321 * @addr: new address
1322 *
1323 * Adds it to unused receive address register or goes into promiscuous mode.
1324 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001325static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001326{
1327 u32 rar_entries = hw->mac.num_rar_entries;
1328 u32 rar;
1329
1330 hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1331 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1332
1333 /*
1334 * Place this address in the RAR if there is room,
1335 * else put the controller into promiscuous mode
1336 */
1337 if (hw->addr_ctrl.rar_used_count < rar_entries) {
1338 rar = hw->addr_ctrl.rar_used_count -
1339 hw->addr_ctrl.mc_addr_in_rar_count;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001340 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001341 hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
1342 hw->addr_ctrl.rar_used_count++;
1343 } else {
1344 hw->addr_ctrl.overflow_promisc++;
1345 }
1346
1347 hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
1348}
1349
1350/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001351 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001352 * @hw: pointer to hardware structure
1353 * @addr_list: the list of new addresses
1354 * @addr_count: number of addresses
1355 * @next: iterator function to walk the address list
1356 *
1357 * The given list replaces any existing list. Clears the secondary addrs from
1358 * receive address registers. Uses unused receive address registers for the
1359 * first secondary addresses, and falls back to promiscuous mode as needed.
1360 *
1361 * Drivers using secondary unicast addresses must set user_set_promisc when
1362 * manually putting the device into promiscuous mode.
1363 **/
Jiri Pirkoccffad252009-05-22 23:22:17 +00001364s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
1365 struct list_head *uc_list)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001366{
Christopher Leech2c5645c2008-08-26 04:27:02 -07001367 u32 i;
1368 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
1369 u32 uc_addr_in_use;
1370 u32 fctrl;
Jiri Pirkoccffad252009-05-22 23:22:17 +00001371 struct netdev_hw_addr *ha;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001372
1373 /*
1374 * Clear accounting of old secondary address list,
1375 * don't count RAR[0]
1376 */
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00001377 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001378 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
1379 hw->addr_ctrl.overflow_promisc = 0;
1380
1381 /* Zero out the other receive addresses */
1382 hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use);
1383 for (i = 1; i <= uc_addr_in_use; i++) {
1384 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1385 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1386 }
1387
1388 /* Add the new addresses */
Jiri Pirkoccffad252009-05-22 23:22:17 +00001389 list_for_each_entry(ha, uc_list, list) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001390 hw_dbg(hw, " Adding the secondary addresses:\n");
Jiri Pirkoccffad252009-05-22 23:22:17 +00001391 ixgbe_add_uc_addr(hw, ha->addr, 0);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001392 }
1393
1394 if (hw->addr_ctrl.overflow_promisc) {
1395 /* enable promisc if not already in overflow or set by user */
1396 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1397 hw_dbg(hw, " Entering address overflow promisc mode\n");
1398 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1399 fctrl |= IXGBE_FCTRL_UPE;
1400 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1401 }
1402 } else {
1403 /* only disable if set by overflow, not by user */
1404 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1405 hw_dbg(hw, " Leaving address overflow promisc mode\n");
1406 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1407 fctrl &= ~IXGBE_FCTRL_UPE;
1408 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1409 }
1410 }
1411
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001412 hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001413 return 0;
1414}
1415
1416/**
Auke Kok9a799d72007-09-15 14:07:45 -07001417 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1418 * @hw: pointer to hardware structure
1419 * @mc_addr: the multicast address
1420 *
1421 * Extracts the 12 bits, from a multicast address, to determine which
1422 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1423 * incoming rx multicast addresses, to determine the bit-vector to check in
1424 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001425 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001426 * to mc_filter_type.
1427 **/
1428static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1429{
1430 u32 vector = 0;
1431
1432 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001433 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001434 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1435 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001436 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001437 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1438 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001439 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001440 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1441 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001442 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001443 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1444 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001445 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001446 hw_dbg(hw, "MC filter type param set incorrectly\n");
1447 break;
1448 }
1449
1450 /* vector can only be 12-bits or boundary will be exceeded */
1451 vector &= 0xFFF;
1452 return vector;
1453}
1454
1455/**
1456 * ixgbe_set_mta - Set bit-vector in multicast table
1457 * @hw: pointer to hardware structure
1458 * @hash_value: Multicast address hash value
1459 *
1460 * Sets the bit-vector in the multicast table.
1461 **/
1462static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1463{
1464 u32 vector;
1465 u32 vector_bit;
1466 u32 vector_reg;
1467 u32 mta_reg;
1468
1469 hw->addr_ctrl.mta_in_use++;
1470
1471 vector = ixgbe_mta_vector(hw, mc_addr);
1472 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1473
1474 /*
1475 * The MTA is a register array of 128 32-bit registers. It is treated
1476 * like an array of 4096 bits. We want to set bit
1477 * BitArray[vector_value]. So we figure out what register the bit is
1478 * in, read it, OR in the new bit, then write back the new value. The
1479 * register is determined by the upper 7 bits of the vector value and
1480 * the bit within that register are determined by the lower 5 bits of
1481 * the value.
1482 */
1483 vector_reg = (vector >> 5) & 0x7F;
1484 vector_bit = vector & 0x1F;
1485 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
1486 mta_reg |= (1 << vector_bit);
1487 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
1488}
1489
1490/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001491 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001492 * @hw: pointer to hardware structure
1493 * @mc_addr_list: the list of new multicast addresses
1494 * @mc_addr_count: number of addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001495 * @next: iterator function to walk the multicast address list
Auke Kok9a799d72007-09-15 14:07:45 -07001496 *
1497 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001498 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001499 * registers for the first multicast addresses, and hashes the rest into the
1500 * multicast table.
1501 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001502s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001503 u32 mc_addr_count, ixgbe_mc_addr_itr next)
Auke Kok9a799d72007-09-15 14:07:45 -07001504{
1505 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001506 u32 vmdq;
Auke Kok9a799d72007-09-15 14:07:45 -07001507
1508 /*
1509 * Set the new number of MC addresses that we are being requested to
1510 * use.
1511 */
1512 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
Auke Kok9a799d72007-09-15 14:07:45 -07001513 hw->addr_ctrl.mta_in_use = 0;
1514
Auke Kok9a799d72007-09-15 14:07:45 -07001515 /* Clear the MTA */
1516 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001517 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001518 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1519
1520 /* Add the new addresses */
1521 for (i = 0; i < mc_addr_count; i++) {
1522 hw_dbg(hw, " Adding the multicast addresses:\n");
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00001523 ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
Auke Kok9a799d72007-09-15 14:07:45 -07001524 }
1525
1526 /* Enable mta */
1527 if (hw->addr_ctrl.mta_in_use > 0)
1528 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001529 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001530
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001531 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001532 return 0;
1533}
1534
1535/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001536 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001537 * @hw: pointer to hardware structure
1538 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001539 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001540 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001541s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001542{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001543 u32 i;
1544 u32 rar_entries = hw->mac.num_rar_entries;
1545 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001546
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001547 if (a->mc_addr_in_rar_count > 0)
1548 for (i = (rar_entries - a->mc_addr_in_rar_count);
1549 i < rar_entries; i++)
1550 ixgbe_enable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001551
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001552 if (a->mta_in_use > 0)
1553 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1554 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001555
1556 return 0;
1557}
1558
1559/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001560 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001561 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001562 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001563 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001564 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001565s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001566{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001567 u32 i;
1568 u32 rar_entries = hw->mac.num_rar_entries;
1569 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001570
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001571 if (a->mc_addr_in_rar_count > 0)
1572 for (i = (rar_entries - a->mc_addr_in_rar_count);
1573 i < rar_entries; i++)
1574 ixgbe_disable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001575
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001576 if (a->mta_in_use > 0)
1577 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001578
1579 return 0;
1580}
1581
1582/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001583 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001584 * @hw: pointer to hardware structure
1585 * @packetbuf_num: packet buffer number (0-7)
1586 *
1587 * Enable flow control according to the current settings.
1588 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001589s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001590{
1591 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001592 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001593 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001594 u32 rx_pba_size;
1595
1596#ifdef CONFIG_DCB
1597 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1598 goto out;
1599
1600#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001601 /* Negotiate the fc mode to use */
1602 ret_val = ixgbe_fc_autoneg(hw);
1603 if (ret_val)
1604 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001605
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001606 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001607 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1608 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1609
1610 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1611 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1612
1613 /*
1614 * The possible values of fc.current_mode are:
1615 * 0: Flow control is completely disabled
1616 * 1: Rx flow control is enabled (we can receive pause frames,
1617 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001618 * 2: Tx flow control is enabled (we can send pause frames but
1619 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001620 * 3: Both Rx and Tx flow control (symmetric) are enabled.
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001621 * 4: Priority Flow Control is enabled.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001622 * other: Invalid.
1623 */
1624 switch (hw->fc.current_mode) {
1625 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001626 /*
1627 * Flow control is disabled by software override or autoneg.
1628 * The code below will actually disable it in the HW.
1629 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001630 break;
1631 case ixgbe_fc_rx_pause:
1632 /*
1633 * Rx Flow control is enabled and Tx Flow control is
1634 * disabled by software override. Since there really
1635 * isn't a way to advertise that we are capable of RX
1636 * Pause ONLY, we will advertise that we support both
1637 * symmetric and asymmetric Rx PAUSE. Later, we will
1638 * disable the adapter's ability to send PAUSE frames.
1639 */
1640 mflcn_reg |= IXGBE_MFLCN_RFCE;
1641 break;
1642 case ixgbe_fc_tx_pause:
1643 /*
1644 * Tx Flow control is enabled, and Rx Flow control is
1645 * disabled by software override.
1646 */
1647 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1648 break;
1649 case ixgbe_fc_full:
1650 /* Flow control (both Rx and Tx) is enabled by SW override. */
1651 mflcn_reg |= IXGBE_MFLCN_RFCE;
1652 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1653 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001654#ifdef CONFIG_DCB
1655 case ixgbe_fc_pfc:
1656 goto out;
1657 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001658#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001659 default:
1660 hw_dbg(hw, "Flow control param set incorrectly\n");
1661 ret_val = -IXGBE_ERR_CONFIG;
1662 goto out;
1663 break;
1664 }
1665
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001666 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001667 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001668 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1669 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1670
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001671 reg = IXGBE_READ_REG(hw, IXGBE_MTQC);
1672 /* Thresholds are different for link flow control when in DCB mode */
1673 if (reg & IXGBE_MTQC_RT_ENA) {
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00001674 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001675
1676 /* Always disable XON for LFC when in DCB mode */
1677 reg = (rx_pba_size >> 5) & 0xFFE0;
1678 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), reg);
1679
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001680 reg = (rx_pba_size >> 2) & 0xFFE0;
1681 if (hw->fc.current_mode & ixgbe_fc_tx_pause)
1682 reg |= IXGBE_FCRTH_FCEN;
1683 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), reg);
1684 } else {
1685 /*
1686 * Set up and enable Rx high/low water mark thresholds,
1687 * enable XON.
1688 */
1689 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1690 if (hw->fc.send_xon) {
1691 IXGBE_WRITE_REG(hw,
1692 IXGBE_FCRTL_82599(packetbuf_num),
1693 (hw->fc.low_water |
1694 IXGBE_FCRTL_XONE));
1695 } else {
1696 IXGBE_WRITE_REG(hw,
1697 IXGBE_FCRTL_82599(packetbuf_num),
1698 hw->fc.low_water);
1699 }
1700
1701 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num),
1702 (hw->fc.high_water | IXGBE_FCRTH_FCEN));
1703 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001704 }
1705
1706 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001707 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001708 if ((packetbuf_num & 1) == 0)
1709 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1710 else
1711 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1712 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1713
1714 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1715
1716out:
1717 return ret_val;
1718}
1719
1720/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001721 * ixgbe_fc_autoneg - Configure flow control
1722 * @hw: pointer to hardware structure
1723 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001724 * Compares our advertised flow control capabilities to those advertised by
1725 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001726 **/
1727s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1728{
1729 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001730 ixgbe_link_speed speed;
1731 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
1732 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001733
1734 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001735 * AN should have completed when the cable was plugged in.
1736 * Look for reasons to bail out. Bail out if:
1737 * - FC autoneg is disabled, or if
1738 * - we don't have multispeed fiber, or if
1739 * - we're not running at 1G, or if
1740 * - link is not up, or if
1741 * - link is up but AN did not complete, or if
1742 * - link is up and AN completed but timed out
1743 *
1744 * Since we're being called from an LSC, link is already know to be up.
1745 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001746 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001747 hw->mac.ops.check_link(hw, &speed, &link_up, false);
1748 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001749
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001750 if (hw->fc.disable_fc_autoneg ||
1751 !hw->phy.multispeed_fiber ||
1752 (speed != IXGBE_LINK_SPEED_1GB_FULL) ||
1753 !link_up ||
1754 ((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1755 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1756 hw->fc.fc_was_autonegged = false;
1757 hw->fc.current_mode = hw->fc.requested_mode;
1758 hw_dbg(hw, "Autoneg FC was skipped.\n");
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001759 goto out;
1760 }
1761
1762 /*
1763 * Read the AN advertisement and LP ability registers and resolve
1764 * local flow control settings accordingly
1765 */
1766 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1767 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1768 if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1769 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1770 /*
1771 * Now we need to check if the user selected Rx ONLY
1772 * of pause frames. In this case, we had to advertise
1773 * FULL flow control because we could not advertise RX
1774 * ONLY. Hence, we must now check to see if we need to
1775 * turn OFF the TRANSMISSION of PAUSE frames.
1776 */
1777 if (hw->fc.requested_mode == ixgbe_fc_full) {
1778 hw->fc.current_mode = ixgbe_fc_full;
1779 hw_dbg(hw, "Flow Control = FULL.\n");
1780 } else {
1781 hw->fc.current_mode = ixgbe_fc_rx_pause;
1782 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1783 }
1784 } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1785 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1786 (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1787 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1788 hw->fc.current_mode = ixgbe_fc_tx_pause;
1789 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1790 } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1791 (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1792 !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1793 (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1794 hw->fc.current_mode = ixgbe_fc_rx_pause;
1795 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1796 } else {
1797 hw->fc.current_mode = ixgbe_fc_none;
1798 hw_dbg(hw, "Flow Control = NONE.\n");
1799 }
1800
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001801 /* Record that current_mode is the result of a successful autoneg */
1802 hw->fc.fc_was_autonegged = true;
1803
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001804out:
1805 return ret_val;
1806}
1807
1808/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001809 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001810 * @hw: pointer to hardware structure
1811 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001812 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001813 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001814s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001815{
1816 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001817 u32 reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001818
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001819#ifdef CONFIG_DCB
1820 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1821 hw->fc.current_mode = hw->fc.requested_mode;
1822 goto out;
1823 }
1824
1825#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001826 /* Validate the packetbuf configuration */
1827 if (packetbuf_num < 0 || packetbuf_num > 7) {
1828 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1829 "is 0-7\n", packetbuf_num);
1830 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1831 goto out;
1832 }
1833
1834 /*
1835 * Validate the water mark configuration. Zero water marks are invalid
1836 * because it causes the controller to just blast out fc packets.
1837 */
1838 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001839 hw_dbg(hw, "Invalid water mark configuration\n");
1840 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1841 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001842 }
1843
1844 /*
1845 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001846 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001847 */
1848 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1849 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
1850 "IEEE mode\n");
1851 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1852 goto out;
1853 }
1854
1855 /*
1856 * 10gig parts do not have a word in the EEPROM to determine the
1857 * default flow control setting, so we explicitly set it to full.
1858 */
1859 if (hw->fc.requested_mode == ixgbe_fc_default)
1860 hw->fc.requested_mode = ixgbe_fc_full;
1861
1862 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001863 * Set up the 1G flow control advertisement registers so the HW will be
1864 * able to do fc autoneg once the cable is plugged in. If we end up
1865 * using 10g instead, this is harmless.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001866 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001867 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001868
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001869 /*
1870 * The possible values of fc.requested_mode are:
1871 * 0: Flow control is completely disabled
1872 * 1: Rx flow control is enabled (we can receive pause frames,
1873 * but not send pause frames).
1874 * 2: Tx flow control is enabled (we can send pause frames but
1875 * we do not support receiving pause frames).
1876 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1877#ifdef CONFIG_DCB
1878 * 4: Priority Flow Control is enabled.
1879#endif
1880 * other: Invalid.
1881 */
1882 switch (hw->fc.requested_mode) {
1883 case ixgbe_fc_none:
1884 /* Flow control completely disabled by software override. */
1885 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1886 break;
1887 case ixgbe_fc_rx_pause:
1888 /*
1889 * Rx Flow control is enabled and Tx Flow control is
1890 * disabled by software override. Since there really
1891 * isn't a way to advertise that we are capable of RX
1892 * Pause ONLY, we will advertise that we support both
1893 * symmetric and asymmetric Rx PAUSE. Later, we will
1894 * disable the adapter's ability to send PAUSE frames.
1895 */
1896 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1897 break;
1898 case ixgbe_fc_tx_pause:
1899 /*
1900 * Tx Flow control is enabled, and Rx Flow control is
1901 * disabled by software override.
1902 */
1903 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
1904 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
1905 break;
1906 case ixgbe_fc_full:
1907 /* Flow control (both Rx and Tx) is enabled by SW override. */
1908 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
1909 break;
1910#ifdef CONFIG_DCB
1911 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001912 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001913 break;
1914#endif /* CONFIG_DCB */
1915 default:
1916 hw_dbg(hw, "Flow control param set incorrectly\n");
1917 ret_val = -IXGBE_ERR_CONFIG;
1918 goto out;
1919 break;
1920 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001921
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001922 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
1923 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
1924
1925 /* Enable and restart autoneg to inform the link partner */
1926 reg |= IXGBE_PCS1GLCTL_AN_ENABLE | IXGBE_PCS1GLCTL_AN_RESTART;
1927
1928 /* 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
1935out:
1936 return ret_val;
1937}
1938
1939/**
Auke Kok9a799d72007-09-15 14:07:45 -07001940 * ixgbe_disable_pcie_master - Disable PCI-express master access
1941 * @hw: pointer to hardware structure
1942 *
1943 * Disables PCI-Express master access and verifies there are no pending
1944 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
1945 * bit hasn't caused the master requests to be disabled, else 0
1946 * is returned signifying master requests disabled.
1947 **/
1948s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
1949{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001950 u32 i;
1951 u32 reg_val;
1952 u32 number_of_queues;
Auke Kok9a799d72007-09-15 14:07:45 -07001953 s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
1954
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001955 /* Disable the receive unit by stopping each queue */
1956 number_of_queues = hw->mac.max_rx_queues;
1957 for (i = 0; i < number_of_queues; i++) {
1958 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1959 if (reg_val & IXGBE_RXDCTL_ENABLE) {
1960 reg_val &= ~IXGBE_RXDCTL_ENABLE;
1961 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
1962 }
1963 }
1964
1965 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
1966 reg_val |= IXGBE_CTRL_GIO_DIS;
1967 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07001968
1969 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
1970 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
1971 status = 0;
1972 break;
1973 }
1974 udelay(100);
1975 }
1976
1977 return status;
1978}
1979
1980
1981/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001982 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07001983 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001984 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07001985 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001986 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07001987 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1988 **/
1989s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
1990{
1991 u32 gssr;
1992 u32 swmask = mask;
1993 u32 fwmask = mask << 5;
1994 s32 timeout = 200;
1995
1996 while (timeout) {
1997 if (ixgbe_get_eeprom_semaphore(hw))
1998 return -IXGBE_ERR_SWFW_SYNC;
1999
2000 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2001 if (!(gssr & (fwmask | swmask)))
2002 break;
2003
2004 /*
2005 * Firmware currently using resource (fwmask) or other software
2006 * thread currently using resource (swmask)
2007 */
2008 ixgbe_release_eeprom_semaphore(hw);
2009 msleep(5);
2010 timeout--;
2011 }
2012
2013 if (!timeout) {
2014 hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
2015 return -IXGBE_ERR_SWFW_SYNC;
2016 }
2017
2018 gssr |= swmask;
2019 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2020
2021 ixgbe_release_eeprom_semaphore(hw);
2022 return 0;
2023}
2024
2025/**
2026 * ixgbe_release_swfw_sync - Release SWFW semaphore
2027 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002028 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002029 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002030 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002031 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2032 **/
2033void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2034{
2035 u32 gssr;
2036 u32 swmask = mask;
2037
2038 ixgbe_get_eeprom_semaphore(hw);
2039
2040 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2041 gssr &= ~swmask;
2042 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2043
2044 ixgbe_release_eeprom_semaphore(hw);
2045}
2046
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002047/**
2048 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2049 * @hw: pointer to hardware structure
2050 * @regval: register value to write to RXCTRL
2051 *
2052 * Enables the Rx DMA unit
2053 **/
2054s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2055{
2056 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2057
2058 return 0;
2059}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002060
2061/**
2062 * ixgbe_blink_led_start_generic - Blink LED based on index.
2063 * @hw: pointer to hardware structure
2064 * @index: led number to blink
2065 **/
2066s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2067{
2068 ixgbe_link_speed speed = 0;
2069 bool link_up = 0;
2070 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2071 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2072
2073 /*
2074 * Link must be up to auto-blink the LEDs;
2075 * Force it if link is down.
2076 */
2077 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2078
2079 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002080 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002081 autoc_reg |= IXGBE_AUTOC_FLU;
2082 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2083 msleep(10);
2084 }
2085
2086 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2087 led_reg |= IXGBE_LED_BLINK(index);
2088 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2089 IXGBE_WRITE_FLUSH(hw);
2090
2091 return 0;
2092}
2093
2094/**
2095 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2096 * @hw: pointer to hardware structure
2097 * @index: led number to stop blinking
2098 **/
2099s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2100{
2101 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2102 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2103
2104 autoc_reg &= ~IXGBE_AUTOC_FLU;
2105 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2106 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2107
2108 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2109 led_reg &= ~IXGBE_LED_BLINK(index);
2110 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2111 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2112 IXGBE_WRITE_FLUSH(hw);
2113
2114 return 0;
2115}