blob: f67c68404bb382462662ea664749b080a280ab6a [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004 Copyright(c) 1999 - 2008 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>
31
32#include "ixgbe_common.h"
33#include "ixgbe_phy.h"
34
Auke Kok9a799d72007-09-15 14:07:45 -070035static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070036static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070037static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
38static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070039static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
40static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
42 u16 count);
43static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
44static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
45static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070047static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
48
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070049static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
50static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
Auke Kok9a799d72007-09-15 14:07:45 -070051static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
52static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070053static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
Auke Kok9a799d72007-09-15 14:07:45 -070054
55/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070056 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070057 * @hw: pointer to hardware structure
58 *
59 * Starts the hardware by filling the bus info structure and media type, clears
60 * all on chip counters, initializes receive address registers, multicast
61 * table, VLAN filter table, calls routine to set up link and flow control
62 * settings, and leaves transmit and receive units disabled and uninitialized
63 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070064s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070065{
66 u32 ctrl_ext;
67
68 /* Set the media type */
69 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
70
71 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070072 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070073
74 /*
75 * Store MAC address from RAR0, clear receive address registers, and
76 * clear the multicast table
77 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070078 hw->mac.ops.init_rx_addrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070079
80 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070081 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070082
83 /* Set up link */
Auke Kok3957d632007-10-31 15:22:10 -070084 hw->mac.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070085
86 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070087 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070088
89 /* Set No Snoop Disable */
90 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
91 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
92 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070093 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070094
95 /* Clear adapter stopped flag */
96 hw->adapter_stopped = false;
97
98 return 0;
99}
100
101/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700102 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -0700103 * @hw: pointer to hardware structure
104 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700105 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700106 * structure and media type, clears all on chip counters, initializes receive
107 * address registers, multicast table, VLAN filter table, calls routine to set
108 * up link and flow control settings, and leaves transmit and receive units
109 * disabled and uninitialized
110 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700111s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700112{
113 /* Reset the hardware */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700114 hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700115
116 /* Start the HW */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700117 hw->mac.ops.start_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700118
119 return 0;
120}
121
122/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700123 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700124 * @hw: pointer to hardware structure
125 *
126 * Clears all hardware statistics counters by reading them from the hardware
127 * Statistics counters are clear on read.
128 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700129s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700130{
131 u16 i = 0;
132
133 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
134 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
135 IXGBE_READ_REG(hw, IXGBE_ERRBC);
136 IXGBE_READ_REG(hw, IXGBE_MSPDC);
137 for (i = 0; i < 8; i++)
138 IXGBE_READ_REG(hw, IXGBE_MPC(i));
139
140 IXGBE_READ_REG(hw, IXGBE_MLFC);
141 IXGBE_READ_REG(hw, IXGBE_MRFC);
142 IXGBE_READ_REG(hw, IXGBE_RLEC);
143 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
144 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
145 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
146 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
147
148 for (i = 0; i < 8; i++) {
149 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
150 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
151 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
152 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
153 }
154
155 IXGBE_READ_REG(hw, IXGBE_PRC64);
156 IXGBE_READ_REG(hw, IXGBE_PRC127);
157 IXGBE_READ_REG(hw, IXGBE_PRC255);
158 IXGBE_READ_REG(hw, IXGBE_PRC511);
159 IXGBE_READ_REG(hw, IXGBE_PRC1023);
160 IXGBE_READ_REG(hw, IXGBE_PRC1522);
161 IXGBE_READ_REG(hw, IXGBE_GPRC);
162 IXGBE_READ_REG(hw, IXGBE_BPRC);
163 IXGBE_READ_REG(hw, IXGBE_MPRC);
164 IXGBE_READ_REG(hw, IXGBE_GPTC);
165 IXGBE_READ_REG(hw, IXGBE_GORCL);
166 IXGBE_READ_REG(hw, IXGBE_GORCH);
167 IXGBE_READ_REG(hw, IXGBE_GOTCL);
168 IXGBE_READ_REG(hw, IXGBE_GOTCH);
169 for (i = 0; i < 8; i++)
170 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
171 IXGBE_READ_REG(hw, IXGBE_RUC);
172 IXGBE_READ_REG(hw, IXGBE_RFC);
173 IXGBE_READ_REG(hw, IXGBE_ROC);
174 IXGBE_READ_REG(hw, IXGBE_RJC);
175 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
176 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
177 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
178 IXGBE_READ_REG(hw, IXGBE_TORL);
179 IXGBE_READ_REG(hw, IXGBE_TORH);
180 IXGBE_READ_REG(hw, IXGBE_TPR);
181 IXGBE_READ_REG(hw, IXGBE_TPT);
182 IXGBE_READ_REG(hw, IXGBE_PTC64);
183 IXGBE_READ_REG(hw, IXGBE_PTC127);
184 IXGBE_READ_REG(hw, IXGBE_PTC255);
185 IXGBE_READ_REG(hw, IXGBE_PTC511);
186 IXGBE_READ_REG(hw, IXGBE_PTC1023);
187 IXGBE_READ_REG(hw, IXGBE_PTC1522);
188 IXGBE_READ_REG(hw, IXGBE_MPTC);
189 IXGBE_READ_REG(hw, IXGBE_BPTC);
190 for (i = 0; i < 16; i++) {
191 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
192 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
193 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
194 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
195 }
196
197 return 0;
198}
199
200/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700201 * ixgbe_read_pba_num_generic - Reads part number from EEPROM
202 * @hw: pointer to hardware structure
203 * @pba_num: stores the part number from the EEPROM
204 *
205 * Reads the part number from the EEPROM.
206 **/
207s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
208{
209 s32 ret_val;
210 u16 data;
211
212 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
213 if (ret_val) {
214 hw_dbg(hw, "NVM Read Error\n");
215 return ret_val;
216 }
217 *pba_num = (u32)(data << 16);
218
219 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
220 if (ret_val) {
221 hw_dbg(hw, "NVM Read Error\n");
222 return ret_val;
223 }
224 *pba_num |= data;
225
226 return 0;
227}
228
229/**
230 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700231 * @hw: pointer to hardware structure
232 * @mac_addr: Adapter MAC address
233 *
234 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
235 * A reset of the adapter must be performed prior to calling this function
236 * in order for the MAC address to have been loaded from the EEPROM into RAR0
237 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700238s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700239{
240 u32 rar_high;
241 u32 rar_low;
242 u16 i;
243
244 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
245 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
246
247 for (i = 0; i < 4; i++)
248 mac_addr[i] = (u8)(rar_low >> (i*8));
249
250 for (i = 0; i < 2; i++)
251 mac_addr[i+4] = (u8)(rar_high >> (i*8));
252
253 return 0;
254}
255
Auke Kok9a799d72007-09-15 14:07:45 -0700256/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700257 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700258 * @hw: pointer to hardware structure
259 *
260 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
261 * disables transmit and receive units. The adapter_stopped flag is used by
262 * the shared code and drivers to determine if the adapter is in a stopped
263 * state and should not touch the hardware.
264 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700265s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700266{
267 u32 number_of_queues;
268 u32 reg_val;
269 u16 i;
270
271 /*
272 * Set the adapter_stopped flag so other driver functions stop touching
273 * the hardware
274 */
275 hw->adapter_stopped = true;
276
277 /* Disable the receive unit */
278 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
279 reg_val &= ~(IXGBE_RXCTRL_RXEN);
280 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700281 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700282 msleep(2);
283
284 /* Clear interrupt mask to stop from interrupts being generated */
285 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
286
287 /* Clear any pending interrupts */
288 IXGBE_READ_REG(hw, IXGBE_EICR);
289
290 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700291 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700292 for (i = 0; i < number_of_queues; i++) {
293 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
294 if (reg_val & IXGBE_TXDCTL_ENABLE) {
295 reg_val &= ~IXGBE_TXDCTL_ENABLE;
296 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
297 }
298 }
299
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700300 /*
301 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
302 * access and verify no pending requests
303 */
304 if (ixgbe_disable_pcie_master(hw) != 0)
305 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
306
Auke Kok9a799d72007-09-15 14:07:45 -0700307 return 0;
308}
309
310/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700311 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700312 * @hw: pointer to hardware structure
313 * @index: led number to turn on
314 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700315s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700316{
317 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
318
319 /* To turn on the LED, set mode to ON. */
320 led_reg &= ~IXGBE_LED_MODE_MASK(index);
321 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
322 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700323 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700324
325 return 0;
326}
327
328/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700329 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700330 * @hw: pointer to hardware structure
331 * @index: led number to turn off
332 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700333s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700334{
335 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
336
337 /* To turn off the LED, set mode to OFF. */
338 led_reg &= ~IXGBE_LED_MODE_MASK(index);
339 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
340 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700341 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700342
343 return 0;
344}
345
Auke Kok9a799d72007-09-15 14:07:45 -0700346/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700347 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700348 * @hw: pointer to hardware structure
349 *
350 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
351 * ixgbe_hw struct in order to set up EEPROM access.
352 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700353s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700354{
355 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
356 u32 eec;
357 u16 eeprom_size;
358
359 if (eeprom->type == ixgbe_eeprom_uninitialized) {
360 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700361 /* Set default semaphore delay to 10ms which is a well
362 * tested value */
363 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700364
365 /*
366 * Check for EEPROM present first.
367 * If not present leave as none
368 */
369 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
370 if (eec & IXGBE_EEC_PRES) {
371 eeprom->type = ixgbe_eeprom_spi;
372
373 /*
374 * SPI EEPROM is assumed here. This code would need to
375 * change if a future EEPROM is not SPI.
376 */
377 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
378 IXGBE_EEC_SIZE_SHIFT);
379 eeprom->word_size = 1 << (eeprom_size +
380 IXGBE_EEPROM_WORD_SIZE_SHIFT);
381 }
382
383 if (eec & IXGBE_EEC_ADDR_SIZE)
384 eeprom->address_bits = 16;
385 else
386 eeprom->address_bits = 8;
387 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
388 "%d\n", eeprom->type, eeprom->word_size,
389 eeprom->address_bits);
390 }
391
392 return 0;
393}
394
395/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700396 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
397 * @hw: pointer to hardware structure
398 * @offset: offset within the EEPROM to be read
399 * @data: read 16 bit value from EEPROM
400 *
401 * Reads 16 bit value from EEPROM through bit-bang method
402 **/
403s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
404 u16 *data)
405{
406 s32 status;
407 u16 word_in;
408 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
409
410 hw->eeprom.ops.init_params(hw);
411
412 if (offset >= hw->eeprom.word_size) {
413 status = IXGBE_ERR_EEPROM;
414 goto out;
415 }
416
417 /* Prepare the EEPROM for reading */
418 status = ixgbe_acquire_eeprom(hw);
419
420 if (status == 0) {
421 if (ixgbe_ready_eeprom(hw) != 0) {
422 ixgbe_release_eeprom(hw);
423 status = IXGBE_ERR_EEPROM;
424 }
425 }
426
427 if (status == 0) {
428 ixgbe_standby_eeprom(hw);
429
430 /*
431 * Some SPI eeproms use the 8th address bit embedded in the
432 * opcode
433 */
434 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
435 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
436
437 /* Send the READ command (opcode + addr) */
438 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
439 IXGBE_EEPROM_OPCODE_BITS);
440 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
441 hw->eeprom.address_bits);
442
443 /* Read the data. */
444 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
445 *data = (word_in >> 8) | (word_in << 8);
446
447 /* End this read operation */
448 ixgbe_release_eeprom(hw);
449 }
450
451out:
452 return status;
453}
454
455/**
456 * ixgbe_read_eeprom_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700457 * @hw: pointer to hardware structure
458 * @offset: offset of word in the EEPROM to read
459 * @data: word read from the EEPROM
460 *
461 * Reads a 16 bit word from the EEPROM using the EERD register.
462 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700463s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700464{
465 u32 eerd;
466 s32 status;
467
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700468 hw->eeprom.ops.init_params(hw);
469
470 if (offset >= hw->eeprom.word_size) {
471 status = IXGBE_ERR_EEPROM;
472 goto out;
473 }
474
Auke Kok9a799d72007-09-15 14:07:45 -0700475 eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
476 IXGBE_EEPROM_READ_REG_START;
477
478 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
479 status = ixgbe_poll_eeprom_eerd_done(hw);
480
481 if (status == 0)
482 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700483 IXGBE_EEPROM_READ_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700484 else
485 hw_dbg(hw, "Eeprom read timed out\n");
486
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700487out:
Auke Kok9a799d72007-09-15 14:07:45 -0700488 return status;
489}
490
491/**
492 * ixgbe_poll_eeprom_eerd_done - Poll EERD status
493 * @hw: pointer to hardware structure
494 *
495 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
496 **/
497static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
498{
499 u32 i;
500 u32 reg;
501 s32 status = IXGBE_ERR_EEPROM;
502
503 for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
504 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
505 if (reg & IXGBE_EEPROM_READ_REG_DONE) {
506 status = 0;
507 break;
508 }
509 udelay(5);
510 }
511 return status;
512}
513
514/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700515 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
516 * @hw: pointer to hardware structure
517 *
518 * Prepares EEPROM for access using bit-bang method. This function should
519 * be called before issuing a command to the EEPROM.
520 **/
521static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
522{
523 s32 status = 0;
524 u32 eec;
525 u32 i;
526
527 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
528 status = IXGBE_ERR_SWFW_SYNC;
529
530 if (status == 0) {
531 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
532
533 /* Request EEPROM Access */
534 eec |= IXGBE_EEC_REQ;
535 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
536
537 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
538 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
539 if (eec & IXGBE_EEC_GNT)
540 break;
541 udelay(5);
542 }
543
544 /* Release if grant not acquired */
545 if (!(eec & IXGBE_EEC_GNT)) {
546 eec &= ~IXGBE_EEC_REQ;
547 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
548 hw_dbg(hw, "Could not acquire EEPROM grant\n");
549
550 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
551 status = IXGBE_ERR_EEPROM;
552 }
553 }
554
555 /* Setup EEPROM for Read/Write */
556 if (status == 0) {
557 /* Clear CS and SK */
558 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
559 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
560 IXGBE_WRITE_FLUSH(hw);
561 udelay(1);
562 }
563 return status;
564}
565
566/**
Auke Kok9a799d72007-09-15 14:07:45 -0700567 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
568 * @hw: pointer to hardware structure
569 *
570 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
571 **/
572static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
573{
574 s32 status = IXGBE_ERR_EEPROM;
575 u32 timeout;
576 u32 i;
577 u32 swsm;
578
579 /* Set timeout value based on size of EEPROM */
580 timeout = hw->eeprom.word_size + 1;
581
582 /* Get SMBI software semaphore between device drivers first */
583 for (i = 0; i < timeout; i++) {
584 /*
585 * If the SMBI bit is 0 when we read it, then the bit will be
586 * set and we have the semaphore
587 */
588 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
589 if (!(swsm & IXGBE_SWSM_SMBI)) {
590 status = 0;
591 break;
592 }
593 msleep(1);
594 }
595
596 /* Now get the semaphore between SW/FW through the SWESMBI bit */
597 if (status == 0) {
598 for (i = 0; i < timeout; i++) {
599 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
600
601 /* Set the SW EEPROM semaphore bit to request access */
602 swsm |= IXGBE_SWSM_SWESMBI;
603 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
604
605 /*
606 * If we set the bit successfully then we got the
607 * semaphore.
608 */
609 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
610 if (swsm & IXGBE_SWSM_SWESMBI)
611 break;
612
613 udelay(50);
614 }
615
616 /*
617 * Release semaphores and return error if SW EEPROM semaphore
618 * was not granted because we don't have access to the EEPROM
619 */
620 if (i >= timeout) {
621 hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700622 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700623 ixgbe_release_eeprom_semaphore(hw);
624 status = IXGBE_ERR_EEPROM;
625 }
626 }
627
628 return status;
629}
630
631/**
632 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
633 * @hw: pointer to hardware structure
634 *
635 * This function clears hardware semaphore bits.
636 **/
637static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
638{
639 u32 swsm;
640
641 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
642
643 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
644 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
645 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700646 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700647}
648
649/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700650 * ixgbe_ready_eeprom - Polls for EEPROM ready
651 * @hw: pointer to hardware structure
652 **/
653static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
654{
655 s32 status = 0;
656 u16 i;
657 u8 spi_stat_reg;
658
659 /*
660 * Read "Status Register" repeatedly until the LSB is cleared. The
661 * EEPROM will signal that the command has been completed by clearing
662 * bit 0 of the internal status register. If it's not cleared within
663 * 5 milliseconds, then error out.
664 */
665 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
666 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
667 IXGBE_EEPROM_OPCODE_BITS);
668 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
669 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
670 break;
671
672 udelay(5);
673 ixgbe_standby_eeprom(hw);
674 };
675
676 /*
677 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
678 * devices (and only 0-5mSec on 5V devices)
679 */
680 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
681 hw_dbg(hw, "SPI EEPROM Status error\n");
682 status = IXGBE_ERR_EEPROM;
683 }
684
685 return status;
686}
687
688/**
689 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
690 * @hw: pointer to hardware structure
691 **/
692static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
693{
694 u32 eec;
695
696 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
697
698 /* Toggle CS to flush commands */
699 eec |= IXGBE_EEC_CS;
700 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
701 IXGBE_WRITE_FLUSH(hw);
702 udelay(1);
703 eec &= ~IXGBE_EEC_CS;
704 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
705 IXGBE_WRITE_FLUSH(hw);
706 udelay(1);
707}
708
709/**
710 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
711 * @hw: pointer to hardware structure
712 * @data: data to send to the EEPROM
713 * @count: number of bits to shift out
714 **/
715static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
716 u16 count)
717{
718 u32 eec;
719 u32 mask;
720 u32 i;
721
722 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
723
724 /*
725 * Mask is used to shift "count" bits of "data" out to the EEPROM
726 * one bit at a time. Determine the starting bit based on count
727 */
728 mask = 0x01 << (count - 1);
729
730 for (i = 0; i < count; i++) {
731 /*
732 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
733 * "1", and then raising and then lowering the clock (the SK
734 * bit controls the clock input to the EEPROM). A "0" is
735 * shifted out to the EEPROM by setting "DI" to "0" and then
736 * raising and then lowering the clock.
737 */
738 if (data & mask)
739 eec |= IXGBE_EEC_DI;
740 else
741 eec &= ~IXGBE_EEC_DI;
742
743 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
744 IXGBE_WRITE_FLUSH(hw);
745
746 udelay(1);
747
748 ixgbe_raise_eeprom_clk(hw, &eec);
749 ixgbe_lower_eeprom_clk(hw, &eec);
750
751 /*
752 * Shift mask to signify next bit of data to shift in to the
753 * EEPROM
754 */
755 mask = mask >> 1;
756 };
757
758 /* We leave the "DI" bit set to "0" when we leave this routine. */
759 eec &= ~IXGBE_EEC_DI;
760 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
761 IXGBE_WRITE_FLUSH(hw);
762}
763
764/**
765 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
766 * @hw: pointer to hardware structure
767 **/
768static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
769{
770 u32 eec;
771 u32 i;
772 u16 data = 0;
773
774 /*
775 * In order to read a register from the EEPROM, we need to shift
776 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
777 * the clock input to the EEPROM (setting the SK bit), and then reading
778 * the value of the "DO" bit. During this "shifting in" process the
779 * "DI" bit should always be clear.
780 */
781 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
782
783 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
784
785 for (i = 0; i < count; i++) {
786 data = data << 1;
787 ixgbe_raise_eeprom_clk(hw, &eec);
788
789 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
790
791 eec &= ~(IXGBE_EEC_DI);
792 if (eec & IXGBE_EEC_DO)
793 data |= 1;
794
795 ixgbe_lower_eeprom_clk(hw, &eec);
796 }
797
798 return data;
799}
800
801/**
802 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
803 * @hw: pointer to hardware structure
804 * @eec: EEC register's current value
805 **/
806static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
807{
808 /*
809 * Raise the clock input to the EEPROM
810 * (setting the SK bit), then delay
811 */
812 *eec = *eec | IXGBE_EEC_SK;
813 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
814 IXGBE_WRITE_FLUSH(hw);
815 udelay(1);
816}
817
818/**
819 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
820 * @hw: pointer to hardware structure
821 * @eecd: EECD's current value
822 **/
823static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
824{
825 /*
826 * Lower the clock input to the EEPROM (clearing the SK bit), then
827 * delay
828 */
829 *eec = *eec & ~IXGBE_EEC_SK;
830 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
831 IXGBE_WRITE_FLUSH(hw);
832 udelay(1);
833}
834
835/**
836 * ixgbe_release_eeprom - Release EEPROM, release semaphores
837 * @hw: pointer to hardware structure
838 **/
839static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
840{
841 u32 eec;
842
843 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
844
845 eec |= IXGBE_EEC_CS; /* Pull CS high */
846 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
847
848 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
849 IXGBE_WRITE_FLUSH(hw);
850
851 udelay(1);
852
853 /* Stop requesting EEPROM access */
854 eec &= ~IXGBE_EEC_REQ;
855 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
856
857 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
858}
859
860/**
Auke Kok9a799d72007-09-15 14:07:45 -0700861 * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
862 * @hw: pointer to hardware structure
863 **/
864static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
865{
866 u16 i;
867 u16 j;
868 u16 checksum = 0;
869 u16 length = 0;
870 u16 pointer = 0;
871 u16 word = 0;
872
873 /* Include 0x0-0x3F in the checksum */
874 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700875 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -0700876 hw_dbg(hw, "EEPROM read failed\n");
877 break;
878 }
879 checksum += word;
880 }
881
882 /* Include all data from pointers except for the fw pointer */
883 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700884 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -0700885
886 /* Make sure the pointer seems valid */
887 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700888 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -0700889
890 if (length != 0xFFFF && length != 0) {
891 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700892 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -0700893 checksum += word;
894 }
895 }
896 }
897 }
898
899 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
900
901 return checksum;
902}
903
904/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700905 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -0700906 * @hw: pointer to hardware structure
907 * @checksum_val: calculated checksum
908 *
909 * Performs checksum calculation and validates the EEPROM checksum. If the
910 * caller does not need checksum_val, the value can be NULL.
911 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700912s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
913 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -0700914{
915 s32 status;
916 u16 checksum;
917 u16 read_checksum = 0;
918
919 /*
920 * Read the first word from the EEPROM. If this times out or fails, do
921 * not continue or we could be in for a very long wait while every
922 * EEPROM read fails
923 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700924 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -0700925
926 if (status == 0) {
927 checksum = ixgbe_calc_eeprom_checksum(hw);
928
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700929 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -0700930
931 /*
932 * Verify read checksum from EEPROM is the same as
933 * calculated checksum
934 */
935 if (read_checksum != checksum)
936 status = IXGBE_ERR_EEPROM_CHECKSUM;
937
938 /* If the user cares, return the calculated checksum */
939 if (checksum_val)
940 *checksum_val = checksum;
941 } else {
942 hw_dbg(hw, "EEPROM read failed\n");
943 }
944
945 return status;
946}
947
948/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700949 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
950 * @hw: pointer to hardware structure
951 **/
952s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
953{
954 s32 status;
955 u16 checksum;
956
957 /*
958 * Read the first word from the EEPROM. If this times out or fails, do
959 * not continue or we could be in for a very long wait while every
960 * EEPROM read fails
961 */
962 status = hw->eeprom.ops.read(hw, 0, &checksum);
963
964 if (status == 0) {
965 checksum = ixgbe_calc_eeprom_checksum(hw);
966 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
967 checksum);
968 } else {
969 hw_dbg(hw, "EEPROM read failed\n");
970 }
971
972 return status;
973}
974
975/**
Auke Kok9a799d72007-09-15 14:07:45 -0700976 * ixgbe_validate_mac_addr - Validate MAC address
977 * @mac_addr: pointer to MAC address.
978 *
979 * Tests a MAC address to ensure it is a valid Individual Address
980 **/
981s32 ixgbe_validate_mac_addr(u8 *mac_addr)
982{
983 s32 status = 0;
984
985 /* Make sure it is not a multicast address */
986 if (IXGBE_IS_MULTICAST(mac_addr))
987 status = IXGBE_ERR_INVALID_MAC_ADDR;
988 /* Not a broadcast address */
989 else if (IXGBE_IS_BROADCAST(mac_addr))
990 status = IXGBE_ERR_INVALID_MAC_ADDR;
991 /* Reject the zero address */
992 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700993 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -0700994 status = IXGBE_ERR_INVALID_MAC_ADDR;
995
996 return status;
997}
998
999/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001000 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001001 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001002 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001003 * @addr: Address to put into receive address register
1004 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001005 * @enable_addr: set flag that address is active
1006 *
1007 * Puts an ethernet address into a receive address register.
1008 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001009s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1010 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001011{
1012 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001013 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001014
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001015 /* setup VMDq pool selection before this RAR gets enabled */
1016 hw->mac.ops.set_vmdq(hw, index, vmdq);
1017
1018 /* Make sure we are using a valid rar index range */
1019 if (index < rar_entries) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001020 /*
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001021 * HW expects these in little endian so we reverse the byte
1022 * order from network order (big endian) to little endian
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001023 */
1024 rar_low = ((u32)addr[0] |
1025 ((u32)addr[1] << 8) |
1026 ((u32)addr[2] << 16) |
1027 ((u32)addr[3] << 24));
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001028 /*
1029 * Some parts put the VMDq setting in the extra RAH bits,
1030 * so save everything except the lower 16 bits that hold part
1031 * of the address and the address valid bit.
1032 */
1033 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1034 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1035 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001036
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001037 if (enable_addr != 0)
1038 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001039
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001040 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1041 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001042 } else {
1043 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1044 }
Auke Kok9a799d72007-09-15 14:07:45 -07001045
1046 return 0;
1047}
1048
1049/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001050 * ixgbe_clear_rar_generic - Remove Rx address register
1051 * @hw: pointer to hardware structure
1052 * @index: Receive address register to write
1053 *
1054 * Clears an ethernet address from a receive address register.
1055 **/
1056s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1057{
1058 u32 rar_high;
1059 u32 rar_entries = hw->mac.num_rar_entries;
1060
1061 /* Make sure we are using a valid rar index range */
1062 if (index < rar_entries) {
1063 /*
1064 * Some parts put the VMDq setting in the extra RAH bits,
1065 * so save everything except the lower 16 bits that hold part
1066 * of the address and the address valid bit.
1067 */
1068 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1069 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1070
1071 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1072 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1073 } else {
1074 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1075 }
1076
1077 /* clear VMDq pool/queue selection for this RAR */
1078 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1079
1080 return 0;
1081}
1082
1083/**
1084 * ixgbe_enable_rar - Enable Rx address register
1085 * @hw: pointer to hardware structure
1086 * @index: index into the RAR table
1087 *
1088 * Enables the select receive address register.
1089 **/
1090static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
1091{
1092 u32 rar_high;
1093
1094 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1095 rar_high |= IXGBE_RAH_AV;
1096 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1097}
1098
1099/**
1100 * ixgbe_disable_rar - Disable Rx address register
1101 * @hw: pointer to hardware structure
1102 * @index: index into the RAR table
1103 *
1104 * Disables the select receive address register.
1105 **/
1106static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
1107{
1108 u32 rar_high;
1109
1110 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1111 rar_high &= (~IXGBE_RAH_AV);
1112 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1113}
1114
1115/**
1116 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001117 * @hw: pointer to hardware structure
1118 *
1119 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001120 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001121 * the receiver is in reset when the routine is called.
1122 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001123s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001124{
1125 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001126 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001127
1128 /*
1129 * If the current mac address is valid, assume it is a software override
1130 * to the permanent address.
1131 * Otherwise, use the permanent address from the eeprom.
1132 */
1133 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1134 IXGBE_ERR_INVALID_MAC_ADDR) {
1135 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001136 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001137
1138 hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001139 hw->mac.addr[0], hw->mac.addr[1],
1140 hw->mac.addr[2]);
Auke Kok9a799d72007-09-15 14:07:45 -07001141 hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001142 hw->mac.addr[4], hw->mac.addr[5]);
Auke Kok9a799d72007-09-15 14:07:45 -07001143 } else {
1144 /* Setup the receive address. */
1145 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
1146 hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001147 hw->mac.addr[0], hw->mac.addr[1],
1148 hw->mac.addr[2]);
Auke Kok9a799d72007-09-15 14:07:45 -07001149 hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001150 hw->mac.addr[4], hw->mac.addr[5]);
Auke Kok9a799d72007-09-15 14:07:45 -07001151
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001152 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07001153 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001154 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001155
1156 hw->addr_ctrl.rar_used_count = 1;
1157
1158 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001159 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001160 for (i = 1; i < rar_entries; i++) {
1161 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1162 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1163 }
1164
1165 /* Clear the MTA */
1166 hw->addr_ctrl.mc_addr_in_rar_count = 0;
1167 hw->addr_ctrl.mta_in_use = 0;
1168 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1169
1170 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001171 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001172 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1173
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001174 if (hw->mac.ops.init_uta_tables)
1175 hw->mac.ops.init_uta_tables(hw);
1176
Auke Kok9a799d72007-09-15 14:07:45 -07001177 return 0;
1178}
1179
1180/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001181 * ixgbe_add_uc_addr - Adds a secondary unicast address.
1182 * @hw: pointer to hardware structure
1183 * @addr: new address
1184 *
1185 * Adds it to unused receive address register or goes into promiscuous mode.
1186 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001187static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
Christopher Leech2c5645c2008-08-26 04:27:02 -07001188{
1189 u32 rar_entries = hw->mac.num_rar_entries;
1190 u32 rar;
1191
1192 hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1193 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1194
1195 /*
1196 * Place this address in the RAR if there is room,
1197 * else put the controller into promiscuous mode
1198 */
1199 if (hw->addr_ctrl.rar_used_count < rar_entries) {
1200 rar = hw->addr_ctrl.rar_used_count -
1201 hw->addr_ctrl.mc_addr_in_rar_count;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001202 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001203 hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
1204 hw->addr_ctrl.rar_used_count++;
1205 } else {
1206 hw->addr_ctrl.overflow_promisc++;
1207 }
1208
1209 hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
1210}
1211
1212/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001213 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001214 * @hw: pointer to hardware structure
1215 * @addr_list: the list of new addresses
1216 * @addr_count: number of addresses
1217 * @next: iterator function to walk the address list
1218 *
1219 * The given list replaces any existing list. Clears the secondary addrs from
1220 * receive address registers. Uses unused receive address registers for the
1221 * first secondary addresses, and falls back to promiscuous mode as needed.
1222 *
1223 * Drivers using secondary unicast addresses must set user_set_promisc when
1224 * manually putting the device into promiscuous mode.
1225 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001226s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
Christopher Leech2c5645c2008-08-26 04:27:02 -07001227 u32 addr_count, ixgbe_mc_addr_itr next)
1228{
1229 u8 *addr;
1230 u32 i;
1231 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
1232 u32 uc_addr_in_use;
1233 u32 fctrl;
1234 u32 vmdq;
1235
1236 /*
1237 * Clear accounting of old secondary address list,
1238 * don't count RAR[0]
1239 */
1240 uc_addr_in_use = hw->addr_ctrl.rar_used_count -
1241 hw->addr_ctrl.mc_addr_in_rar_count - 1;
1242 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
1243 hw->addr_ctrl.overflow_promisc = 0;
1244
1245 /* Zero out the other receive addresses */
1246 hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use);
1247 for (i = 1; i <= uc_addr_in_use; i++) {
1248 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1249 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1250 }
1251
1252 /* Add the new addresses */
1253 for (i = 0; i < addr_count; i++) {
1254 hw_dbg(hw, " Adding the secondary addresses:\n");
1255 addr = next(hw, &addr_list, &vmdq);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001256 ixgbe_add_uc_addr(hw, addr, vmdq);
Christopher Leech2c5645c2008-08-26 04:27:02 -07001257 }
1258
1259 if (hw->addr_ctrl.overflow_promisc) {
1260 /* enable promisc if not already in overflow or set by user */
1261 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1262 hw_dbg(hw, " Entering address overflow promisc mode\n");
1263 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1264 fctrl |= IXGBE_FCTRL_UPE;
1265 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1266 }
1267 } else {
1268 /* only disable if set by overflow, not by user */
1269 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1270 hw_dbg(hw, " Leaving address overflow promisc mode\n");
1271 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1272 fctrl &= ~IXGBE_FCTRL_UPE;
1273 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1274 }
1275 }
1276
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001277 hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001278 return 0;
1279}
1280
1281/**
Auke Kok9a799d72007-09-15 14:07:45 -07001282 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1283 * @hw: pointer to hardware structure
1284 * @mc_addr: the multicast address
1285 *
1286 * Extracts the 12 bits, from a multicast address, to determine which
1287 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1288 * incoming rx multicast addresses, to determine the bit-vector to check in
1289 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001290 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001291 * to mc_filter_type.
1292 **/
1293static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1294{
1295 u32 vector = 0;
1296
1297 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001298 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001299 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1300 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001301 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001302 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1303 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001304 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001305 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1306 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001307 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001308 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1309 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001310 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001311 hw_dbg(hw, "MC filter type param set incorrectly\n");
1312 break;
1313 }
1314
1315 /* vector can only be 12-bits or boundary will be exceeded */
1316 vector &= 0xFFF;
1317 return vector;
1318}
1319
1320/**
1321 * ixgbe_set_mta - Set bit-vector in multicast table
1322 * @hw: pointer to hardware structure
1323 * @hash_value: Multicast address hash value
1324 *
1325 * Sets the bit-vector in the multicast table.
1326 **/
1327static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1328{
1329 u32 vector;
1330 u32 vector_bit;
1331 u32 vector_reg;
1332 u32 mta_reg;
1333
1334 hw->addr_ctrl.mta_in_use++;
1335
1336 vector = ixgbe_mta_vector(hw, mc_addr);
1337 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1338
1339 /*
1340 * The MTA is a register array of 128 32-bit registers. It is treated
1341 * like an array of 4096 bits. We want to set bit
1342 * BitArray[vector_value]. So we figure out what register the bit is
1343 * in, read it, OR in the new bit, then write back the new value. The
1344 * register is determined by the upper 7 bits of the vector value and
1345 * the bit within that register are determined by the lower 5 bits of
1346 * the value.
1347 */
1348 vector_reg = (vector >> 5) & 0x7F;
1349 vector_bit = vector & 0x1F;
1350 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
1351 mta_reg |= (1 << vector_bit);
1352 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
1353}
1354
1355/**
1356 * ixgbe_add_mc_addr - Adds a multicast address.
1357 * @hw: pointer to hardware structure
1358 * @mc_addr: new multicast address
1359 *
1360 * Adds it to unused receive address register or to the multicast table.
1361 **/
1362static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr)
1363{
Christopher Leech2c5645c2008-08-26 04:27:02 -07001364 u32 rar_entries = hw->mac.num_rar_entries;
Jesse Brandeburgce94bf42008-09-11 19:55:14 -07001365 u32 rar;
Auke Kok9a799d72007-09-15 14:07:45 -07001366
1367 hw_dbg(hw, " MC Addr =%.2X %.2X %.2X %.2X %.2X %.2X\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001368 mc_addr[0], mc_addr[1], mc_addr[2],
1369 mc_addr[3], mc_addr[4], mc_addr[5]);
Auke Kok9a799d72007-09-15 14:07:45 -07001370
1371 /*
1372 * Place this multicast address in the RAR if there is room,
1373 * else put it in the MTA
1374 */
1375 if (hw->addr_ctrl.rar_used_count < rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001376 /* use RAR from the end up for multicast */
Jesse Brandeburgce94bf42008-09-11 19:55:14 -07001377 rar = rar_entries - hw->addr_ctrl.mc_addr_in_rar_count - 1;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001378 hw->mac.ops.set_rar(hw, rar, mc_addr, 0, IXGBE_RAH_AV);
1379 hw_dbg(hw, "Added a multicast address to RAR[%d]\n", rar);
Auke Kok9a799d72007-09-15 14:07:45 -07001380 hw->addr_ctrl.rar_used_count++;
1381 hw->addr_ctrl.mc_addr_in_rar_count++;
1382 } else {
1383 ixgbe_set_mta(hw, mc_addr);
1384 }
1385
1386 hw_dbg(hw, "ixgbe_add_mc_addr Complete\n");
1387}
1388
1389/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001390 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001391 * @hw: pointer to hardware structure
1392 * @mc_addr_list: the list of new multicast addresses
1393 * @mc_addr_count: number of addresses
Christopher Leech2c5645c2008-08-26 04:27:02 -07001394 * @next: iterator function to walk the multicast address list
Auke Kok9a799d72007-09-15 14:07:45 -07001395 *
1396 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001397 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001398 * registers for the first multicast addresses, and hashes the rest into the
1399 * multicast table.
1400 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001401s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001402 u32 mc_addr_count, ixgbe_mc_addr_itr next)
Auke Kok9a799d72007-09-15 14:07:45 -07001403{
1404 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001405 u32 rar_entries = hw->mac.num_rar_entries;
1406 u32 vmdq;
Auke Kok9a799d72007-09-15 14:07:45 -07001407
1408 /*
1409 * Set the new number of MC addresses that we are being requested to
1410 * use.
1411 */
1412 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
1413 hw->addr_ctrl.rar_used_count -= hw->addr_ctrl.mc_addr_in_rar_count;
1414 hw->addr_ctrl.mc_addr_in_rar_count = 0;
1415 hw->addr_ctrl.mta_in_use = 0;
1416
1417 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001418 hw_dbg(hw, "Clearing RAR[%d-%d]\n", hw->addr_ctrl.rar_used_count,
1419 rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001420 for (i = hw->addr_ctrl.rar_used_count; i < rar_entries; i++) {
1421 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1422 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1423 }
1424
1425 /* Clear the MTA */
1426 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001427 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001428 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1429
1430 /* Add the new addresses */
1431 for (i = 0; i < mc_addr_count; i++) {
1432 hw_dbg(hw, " Adding the multicast addresses:\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001433 ixgbe_add_mc_addr(hw, next(hw, &mc_addr_list, &vmdq));
Auke Kok9a799d72007-09-15 14:07:45 -07001434 }
1435
1436 /* Enable mta */
1437 if (hw->addr_ctrl.mta_in_use > 0)
1438 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001439 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001440
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001441 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001442 return 0;
1443}
1444
1445/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001446 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001447 * @hw: pointer to hardware structure
1448 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001449 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001450 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001451s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001452{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001453 u32 i;
1454 u32 rar_entries = hw->mac.num_rar_entries;
1455 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001456
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001457 if (a->mc_addr_in_rar_count > 0)
1458 for (i = (rar_entries - a->mc_addr_in_rar_count);
1459 i < rar_entries; i++)
1460 ixgbe_enable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001461
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001462 if (a->mta_in_use > 0)
1463 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1464 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001465
1466 return 0;
1467}
1468
1469/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001470 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001471 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001472 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001473 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001474 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001475s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001476{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001477 u32 i;
1478 u32 rar_entries = hw->mac.num_rar_entries;
1479 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001480
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001481 if (a->mc_addr_in_rar_count > 0)
1482 for (i = (rar_entries - a->mc_addr_in_rar_count);
1483 i < rar_entries; i++)
1484 ixgbe_disable_rar(hw, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001485
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001486 if (a->mta_in_use > 0)
1487 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001488
1489 return 0;
1490}
1491
1492/**
1493 * ixgbe_disable_pcie_master - Disable PCI-express master access
1494 * @hw: pointer to hardware structure
1495 *
1496 * Disables PCI-Express master access and verifies there are no pending
1497 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
1498 * bit hasn't caused the master requests to be disabled, else 0
1499 * is returned signifying master requests disabled.
1500 **/
1501s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
1502{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001503 u32 i;
1504 u32 reg_val;
1505 u32 number_of_queues;
Auke Kok9a799d72007-09-15 14:07:45 -07001506 s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
1507
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001508 /* Disable the receive unit by stopping each queue */
1509 number_of_queues = hw->mac.max_rx_queues;
1510 for (i = 0; i < number_of_queues; i++) {
1511 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1512 if (reg_val & IXGBE_RXDCTL_ENABLE) {
1513 reg_val &= ~IXGBE_RXDCTL_ENABLE;
1514 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
1515 }
1516 }
1517
1518 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
1519 reg_val |= IXGBE_CTRL_GIO_DIS;
1520 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07001521
1522 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
1523 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
1524 status = 0;
1525 break;
1526 }
1527 udelay(100);
1528 }
1529
1530 return status;
1531}
1532
1533
1534/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001535 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07001536 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001537 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07001538 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001539 * Acquires the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07001540 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1541 **/
1542s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
1543{
1544 u32 gssr;
1545 u32 swmask = mask;
1546 u32 fwmask = mask << 5;
1547 s32 timeout = 200;
1548
1549 while (timeout) {
1550 if (ixgbe_get_eeprom_semaphore(hw))
1551 return -IXGBE_ERR_SWFW_SYNC;
1552
1553 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
1554 if (!(gssr & (fwmask | swmask)))
1555 break;
1556
1557 /*
1558 * Firmware currently using resource (fwmask) or other software
1559 * thread currently using resource (swmask)
1560 */
1561 ixgbe_release_eeprom_semaphore(hw);
1562 msleep(5);
1563 timeout--;
1564 }
1565
1566 if (!timeout) {
1567 hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
1568 return -IXGBE_ERR_SWFW_SYNC;
1569 }
1570
1571 gssr |= swmask;
1572 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
1573
1574 ixgbe_release_eeprom_semaphore(hw);
1575 return 0;
1576}
1577
1578/**
1579 * ixgbe_release_swfw_sync - Release SWFW semaphore
1580 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001581 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07001582 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001583 * Releases the SWFW semaphore thought the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07001584 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1585 **/
1586void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
1587{
1588 u32 gssr;
1589 u32 swmask = mask;
1590
1591 ixgbe_get_eeprom_semaphore(hw);
1592
1593 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
1594 gssr &= ~swmask;
1595 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
1596
1597 ixgbe_release_eeprom_semaphore(hw);
1598}
1599