blob: c4730cd39b22434a3165ad09bf61c1cd03f41f02 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
Jiri Pirkoccffad22009-05-22 23:22:17 +000031#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_common.h"
35#include "ixgbe_phy.h"
36
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070037static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070040static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +000050static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw);
51static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw);
52static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw);
53static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
54static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
55 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm);
Don Skidmore7b25cdb2009-08-25 04:47:32 +000056static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
Emil Tantiloveb9c3e32011-03-24 00:57:50 +000057static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
Emil Tantilov68c70052011-04-20 08:49:06 +000058static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
59 u16 words, u16 *data);
60static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
61 u16 words, u16 *data);
62static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
63 u16 offset);
Auke Kok9a799d72007-09-15 14:07:45 -070064
65/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070066 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070067 * @hw: pointer to hardware structure
68 *
69 * Starts the hardware by filling the bus info structure and media type, clears
70 * all on chip counters, initializes receive address registers, multicast
71 * table, VLAN filter table, calls routine to set up link and flow control
72 * settings, and leaves transmit and receive units disabled and uninitialized
73 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070074s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070075{
76 u32 ctrl_ext;
77
78 /* Set the media type */
79 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
80
81 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070082 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070083
Auke Kok9a799d72007-09-15 14:07:45 -070084 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070085 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070086
Auke Kok9a799d72007-09-15 14:07:45 -070087 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070088 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070089
90 /* Set No Snoop Disable */
91 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
92 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
93 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070094 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070095
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000096 /* Setup flow control */
97 ixgbe_setup_fc(hw, 0);
98
Auke Kok9a799d72007-09-15 14:07:45 -070099 /* Clear adapter stopped flag */
100 hw->adapter_stopped = false;
101
102 return 0;
103}
104
105/**
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000106 * ixgbe_start_hw_gen2 - Init sequence for common device family
107 * @hw: pointer to hw structure
108 *
109 * Performs the init sequence common to the second generation
110 * of 10 GbE devices.
111 * Devices in the second generation:
112 * 82599
113 * X540
114 **/
115s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
116{
117 u32 i;
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000118 u32 regval;
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000119
120 /* Clear the rate limiters */
121 for (i = 0; i < hw->mac.max_tx_queues; i++) {
122 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
123 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
124 }
125 IXGBE_WRITE_FLUSH(hw);
126
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000127 /* Disable relaxed ordering */
128 for (i = 0; i < hw->mac.max_tx_queues; i++) {
129 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
130 regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
131 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
132 }
133
134 for (i = 0; i < hw->mac.max_rx_queues; i++) {
135 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
136 regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
137 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
138 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
139 }
140
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000141 return 0;
142}
143
144/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700145 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -0700146 * @hw: pointer to hardware structure
147 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700148 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700149 * structure and media type, clears all on chip counters, initializes receive
150 * address registers, multicast table, VLAN filter table, calls routine to set
151 * up link and flow control settings, and leaves transmit and receive units
152 * disabled and uninitialized
153 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700154s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700155{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000156 s32 status;
157
Auke Kok9a799d72007-09-15 14:07:45 -0700158 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000159 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700160
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000161 if (status == 0) {
162 /* Start the HW */
163 status = hw->mac.ops.start_hw(hw);
164 }
Auke Kok9a799d72007-09-15 14:07:45 -0700165
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000166 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700167}
168
169/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700170 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700171 * @hw: pointer to hardware structure
172 *
173 * Clears all hardware statistics counters by reading them from the hardware
174 * Statistics counters are clear on read.
175 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700176s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700177{
178 u16 i = 0;
179
180 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
181 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
182 IXGBE_READ_REG(hw, IXGBE_ERRBC);
183 IXGBE_READ_REG(hw, IXGBE_MSPDC);
184 for (i = 0; i < 8; i++)
185 IXGBE_READ_REG(hw, IXGBE_MPC(i));
186
187 IXGBE_READ_REG(hw, IXGBE_MLFC);
188 IXGBE_READ_REG(hw, IXGBE_MRFC);
189 IXGBE_READ_REG(hw, IXGBE_RLEC);
190 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Auke Kok9a799d72007-09-15 14:07:45 -0700191 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Emil Tantilov667c7562011-02-26 06:40:05 +0000192 if (hw->mac.type >= ixgbe_mac_82599EB) {
193 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
194 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
195 } else {
196 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
197 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
198 }
Auke Kok9a799d72007-09-15 14:07:45 -0700199
200 for (i = 0; i < 8; i++) {
201 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700202 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000203 if (hw->mac.type >= ixgbe_mac_82599EB) {
204 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
205 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
206 } else {
207 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
208 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
209 }
Auke Kok9a799d72007-09-15 14:07:45 -0700210 }
Emil Tantilov667c7562011-02-26 06:40:05 +0000211 if (hw->mac.type >= ixgbe_mac_82599EB)
212 for (i = 0; i < 8; i++)
213 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700214 IXGBE_READ_REG(hw, IXGBE_PRC64);
215 IXGBE_READ_REG(hw, IXGBE_PRC127);
216 IXGBE_READ_REG(hw, IXGBE_PRC255);
217 IXGBE_READ_REG(hw, IXGBE_PRC511);
218 IXGBE_READ_REG(hw, IXGBE_PRC1023);
219 IXGBE_READ_REG(hw, IXGBE_PRC1522);
220 IXGBE_READ_REG(hw, IXGBE_GPRC);
221 IXGBE_READ_REG(hw, IXGBE_BPRC);
222 IXGBE_READ_REG(hw, IXGBE_MPRC);
223 IXGBE_READ_REG(hw, IXGBE_GPTC);
224 IXGBE_READ_REG(hw, IXGBE_GORCL);
225 IXGBE_READ_REG(hw, IXGBE_GORCH);
226 IXGBE_READ_REG(hw, IXGBE_GOTCL);
227 IXGBE_READ_REG(hw, IXGBE_GOTCH);
228 for (i = 0; i < 8; i++)
229 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
230 IXGBE_READ_REG(hw, IXGBE_RUC);
231 IXGBE_READ_REG(hw, IXGBE_RFC);
232 IXGBE_READ_REG(hw, IXGBE_ROC);
233 IXGBE_READ_REG(hw, IXGBE_RJC);
234 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
235 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
236 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
237 IXGBE_READ_REG(hw, IXGBE_TORL);
238 IXGBE_READ_REG(hw, IXGBE_TORH);
239 IXGBE_READ_REG(hw, IXGBE_TPR);
240 IXGBE_READ_REG(hw, IXGBE_TPT);
241 IXGBE_READ_REG(hw, IXGBE_PTC64);
242 IXGBE_READ_REG(hw, IXGBE_PTC127);
243 IXGBE_READ_REG(hw, IXGBE_PTC255);
244 IXGBE_READ_REG(hw, IXGBE_PTC511);
245 IXGBE_READ_REG(hw, IXGBE_PTC1023);
246 IXGBE_READ_REG(hw, IXGBE_PTC1522);
247 IXGBE_READ_REG(hw, IXGBE_MPTC);
248 IXGBE_READ_REG(hw, IXGBE_BPTC);
249 for (i = 0; i < 16; i++) {
250 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700251 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000252 if (hw->mac.type >= ixgbe_mac_82599EB) {
253 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
254 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
255 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
256 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
257 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
258 } else {
259 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
260 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
261 }
Auke Kok9a799d72007-09-15 14:07:45 -0700262 }
263
Emil Tantilova3aeea02011-02-26 06:40:11 +0000264 if (hw->mac.type == ixgbe_mac_X540) {
265 if (hw->phy.id == 0)
266 hw->phy.ops.identify(hw);
267 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i);
268 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i);
269 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i);
270 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i);
271 }
272
Auke Kok9a799d72007-09-15 14:07:45 -0700273 return 0;
274}
275
276/**
Don Skidmore289700d2010-12-03 03:32:58 +0000277 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700278 * @hw: pointer to hardware structure
Don Skidmore289700d2010-12-03 03:32:58 +0000279 * @pba_num: stores the part number string from the EEPROM
280 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700281 *
Don Skidmore289700d2010-12-03 03:32:58 +0000282 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700283 **/
Don Skidmore289700d2010-12-03 03:32:58 +0000284s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
285 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700286{
287 s32 ret_val;
288 u16 data;
Don Skidmore289700d2010-12-03 03:32:58 +0000289 u16 pba_ptr;
290 u16 offset;
291 u16 length;
292
293 if (pba_num == NULL) {
294 hw_dbg(hw, "PBA string buffer was null\n");
295 return IXGBE_ERR_INVALID_ARGUMENT;
296 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700297
298 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
299 if (ret_val) {
300 hw_dbg(hw, "NVM Read Error\n");
301 return ret_val;
302 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700303
Don Skidmore289700d2010-12-03 03:32:58 +0000304 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700305 if (ret_val) {
306 hw_dbg(hw, "NVM Read Error\n");
307 return ret_val;
308 }
Don Skidmore289700d2010-12-03 03:32:58 +0000309
310 /*
311 * if data is not ptr guard the PBA must be in legacy format which
312 * means pba_ptr is actually our second data word for the PBA number
313 * and we can decode it into an ascii string
314 */
315 if (data != IXGBE_PBANUM_PTR_GUARD) {
316 hw_dbg(hw, "NVM PBA number is not stored as string\n");
317
318 /* we will need 11 characters to store the PBA */
319 if (pba_num_size < 11) {
320 hw_dbg(hw, "PBA string buffer too small\n");
321 return IXGBE_ERR_NO_SPACE;
322 }
323
324 /* extract hex string from data and pba_ptr */
325 pba_num[0] = (data >> 12) & 0xF;
326 pba_num[1] = (data >> 8) & 0xF;
327 pba_num[2] = (data >> 4) & 0xF;
328 pba_num[3] = data & 0xF;
329 pba_num[4] = (pba_ptr >> 12) & 0xF;
330 pba_num[5] = (pba_ptr >> 8) & 0xF;
331 pba_num[6] = '-';
332 pba_num[7] = 0;
333 pba_num[8] = (pba_ptr >> 4) & 0xF;
334 pba_num[9] = pba_ptr & 0xF;
335
336 /* put a null character on the end of our string */
337 pba_num[10] = '\0';
338
339 /* switch all the data but the '-' to hex char */
340 for (offset = 0; offset < 10; offset++) {
341 if (pba_num[offset] < 0xA)
342 pba_num[offset] += '0';
343 else if (pba_num[offset] < 0x10)
344 pba_num[offset] += 'A' - 0xA;
345 }
346
347 return 0;
348 }
349
350 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
351 if (ret_val) {
352 hw_dbg(hw, "NVM Read Error\n");
353 return ret_val;
354 }
355
356 if (length == 0xFFFF || length == 0) {
357 hw_dbg(hw, "NVM PBA number section invalid length\n");
358 return IXGBE_ERR_PBA_SECTION;
359 }
360
361 /* check if pba_num buffer is big enough */
362 if (pba_num_size < (((u32)length * 2) - 1)) {
363 hw_dbg(hw, "PBA string buffer too small\n");
364 return IXGBE_ERR_NO_SPACE;
365 }
366
367 /* trim pba length from start of string */
368 pba_ptr++;
369 length--;
370
371 for (offset = 0; offset < length; offset++) {
372 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
373 if (ret_val) {
374 hw_dbg(hw, "NVM Read Error\n");
375 return ret_val;
376 }
377 pba_num[offset * 2] = (u8)(data >> 8);
378 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
379 }
380 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700381
382 return 0;
383}
384
385/**
386 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700387 * @hw: pointer to hardware structure
388 * @mac_addr: Adapter MAC address
389 *
390 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
391 * A reset of the adapter must be performed prior to calling this function
392 * in order for the MAC address to have been loaded from the EEPROM into RAR0
393 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700394s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700395{
396 u32 rar_high;
397 u32 rar_low;
398 u16 i;
399
400 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
401 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
402
403 for (i = 0; i < 4; i++)
404 mac_addr[i] = (u8)(rar_low >> (i*8));
405
406 for (i = 0; i < 2; i++)
407 mac_addr[i+4] = (u8)(rar_high >> (i*8));
408
409 return 0;
410}
411
Auke Kok9a799d72007-09-15 14:07:45 -0700412/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000413 * ixgbe_get_bus_info_generic - Generic set PCI bus info
414 * @hw: pointer to hardware structure
415 *
416 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
417 **/
418s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
419{
420 struct ixgbe_adapter *adapter = hw->back;
421 struct ixgbe_mac_info *mac = &hw->mac;
422 u16 link_status;
423
424 hw->bus.type = ixgbe_bus_type_pci_express;
425
426 /* Get the negotiated link width and speed from PCI config space */
427 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
428 &link_status);
429
430 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
431 case IXGBE_PCI_LINK_WIDTH_1:
432 hw->bus.width = ixgbe_bus_width_pcie_x1;
433 break;
434 case IXGBE_PCI_LINK_WIDTH_2:
435 hw->bus.width = ixgbe_bus_width_pcie_x2;
436 break;
437 case IXGBE_PCI_LINK_WIDTH_4:
438 hw->bus.width = ixgbe_bus_width_pcie_x4;
439 break;
440 case IXGBE_PCI_LINK_WIDTH_8:
441 hw->bus.width = ixgbe_bus_width_pcie_x8;
442 break;
443 default:
444 hw->bus.width = ixgbe_bus_width_unknown;
445 break;
446 }
447
448 switch (link_status & IXGBE_PCI_LINK_SPEED) {
449 case IXGBE_PCI_LINK_SPEED_2500:
450 hw->bus.speed = ixgbe_bus_speed_2500;
451 break;
452 case IXGBE_PCI_LINK_SPEED_5000:
453 hw->bus.speed = ixgbe_bus_speed_5000;
454 break;
455 default:
456 hw->bus.speed = ixgbe_bus_speed_unknown;
457 break;
458 }
459
460 mac->ops.set_lan_id(hw);
461
462 return 0;
463}
464
465/**
466 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
467 * @hw: pointer to the HW structure
468 *
469 * Determines the LAN function id by reading memory-mapped registers
470 * and swaps the port value if requested.
471 **/
472void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
473{
474 struct ixgbe_bus_info *bus = &hw->bus;
475 u32 reg;
476
477 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
478 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
479 bus->lan_id = bus->func;
480
481 /* check for a port swap */
482 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
483 if (reg & IXGBE_FACTPS_LFS)
484 bus->func ^= 0x1;
485}
486
487/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700488 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700489 * @hw: pointer to hardware structure
490 *
491 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
492 * disables transmit and receive units. The adapter_stopped flag is used by
493 * the shared code and drivers to determine if the adapter is in a stopped
494 * state and should not touch the hardware.
495 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700496s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700497{
498 u32 number_of_queues;
499 u32 reg_val;
500 u16 i;
501
502 /*
503 * Set the adapter_stopped flag so other driver functions stop touching
504 * the hardware
505 */
506 hw->adapter_stopped = true;
507
508 /* Disable the receive unit */
509 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
510 reg_val &= ~(IXGBE_RXCTRL_RXEN);
511 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700512 IXGBE_WRITE_FLUSH(hw);
Don Skidmore032b4322011-03-18 09:32:53 +0000513 usleep_range(2000, 4000);
Auke Kok9a799d72007-09-15 14:07:45 -0700514
515 /* Clear interrupt mask to stop from interrupts being generated */
516 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
517
518 /* Clear any pending interrupts */
519 IXGBE_READ_REG(hw, IXGBE_EICR);
520
521 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700522 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700523 for (i = 0; i < number_of_queues; i++) {
524 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
525 if (reg_val & IXGBE_TXDCTL_ENABLE) {
526 reg_val &= ~IXGBE_TXDCTL_ENABLE;
527 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
528 }
529 }
530
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700531 /*
532 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
533 * access and verify no pending requests
534 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000535 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700536
Auke Kok9a799d72007-09-15 14:07:45 -0700537 return 0;
538}
539
540/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700541 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700542 * @hw: pointer to hardware structure
543 * @index: led number to turn on
544 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700545s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700546{
547 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
548
549 /* To turn on the LED, set mode to ON. */
550 led_reg &= ~IXGBE_LED_MODE_MASK(index);
551 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
552 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700553 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700554
555 return 0;
556}
557
558/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700559 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700560 * @hw: pointer to hardware structure
561 * @index: led number to turn off
562 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700563s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700564{
565 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
566
567 /* To turn off the LED, set mode to OFF. */
568 led_reg &= ~IXGBE_LED_MODE_MASK(index);
569 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
570 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700571 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700572
573 return 0;
574}
575
Auke Kok9a799d72007-09-15 14:07:45 -0700576/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700577 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700578 * @hw: pointer to hardware structure
579 *
580 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
581 * ixgbe_hw struct in order to set up EEPROM access.
582 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700583s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700584{
585 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
586 u32 eec;
587 u16 eeprom_size;
588
589 if (eeprom->type == ixgbe_eeprom_uninitialized) {
590 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700591 /* Set default semaphore delay to 10ms which is a well
592 * tested value */
593 eeprom->semaphore_delay = 10;
Emil Tantilov68c70052011-04-20 08:49:06 +0000594 /* Clear EEPROM page size, it will be initialized as needed */
595 eeprom->word_page_size = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700596
597 /*
598 * Check for EEPROM present first.
599 * If not present leave as none
600 */
601 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
602 if (eec & IXGBE_EEC_PRES) {
603 eeprom->type = ixgbe_eeprom_spi;
604
605 /*
606 * SPI EEPROM is assumed here. This code would need to
607 * change if a future EEPROM is not SPI.
608 */
609 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
610 IXGBE_EEC_SIZE_SHIFT);
611 eeprom->word_size = 1 << (eeprom_size +
612 IXGBE_EEPROM_WORD_SIZE_SHIFT);
613 }
614
615 if (eec & IXGBE_EEC_ADDR_SIZE)
616 eeprom->address_bits = 16;
617 else
618 eeprom->address_bits = 8;
619 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
620 "%d\n", eeprom->type, eeprom->word_size,
621 eeprom->address_bits);
622 }
623
624 return 0;
625}
626
627/**
Emil Tantilov68c70052011-04-20 08:49:06 +0000628 * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
629 * @hw: pointer to hardware structure
630 * @offset: offset within the EEPROM to write
631 * @words: number of words
632 * @data: 16 bit word(s) to write to EEPROM
633 *
634 * Reads 16 bit word(s) from EEPROM through bit-bang method
635 **/
636s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
637 u16 words, u16 *data)
638{
639 s32 status = 0;
640 u16 i, count;
641
642 hw->eeprom.ops.init_params(hw);
643
644 if (words == 0) {
645 status = IXGBE_ERR_INVALID_ARGUMENT;
646 goto out;
647 }
648
649 if (offset + words > hw->eeprom.word_size) {
650 status = IXGBE_ERR_EEPROM;
651 goto out;
652 }
653
654 /*
655 * The EEPROM page size cannot be queried from the chip. We do lazy
656 * initialization. It is worth to do that when we write large buffer.
657 */
658 if ((hw->eeprom.word_page_size == 0) &&
659 (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
660 ixgbe_detect_eeprom_page_size_generic(hw, offset);
661
662 /*
663 * We cannot hold synchronization semaphores for too long
664 * to avoid other entity starvation. However it is more efficient
665 * to read in bursts than synchronizing access for each word.
666 */
667 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
668 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
669 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
670 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
671 count, &data[i]);
672
673 if (status != 0)
674 break;
675 }
676
677out:
678 return status;
679}
680
681/**
682 * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000683 * @hw: pointer to hardware structure
684 * @offset: offset within the EEPROM to be written to
Emil Tantilov68c70052011-04-20 08:49:06 +0000685 * @words: number of word(s)
686 * @data: 16 bit word(s) to be written to the EEPROM
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000687 *
688 * If ixgbe_eeprom_update_checksum is not called after this function, the
689 * EEPROM will most likely contain an invalid checksum.
690 **/
Emil Tantilov68c70052011-04-20 08:49:06 +0000691static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
692 u16 words, u16 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000693{
694 s32 status;
Emil Tantilov68c70052011-04-20 08:49:06 +0000695 u16 word;
696 u16 page_size;
697 u16 i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000698 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
699
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000700 /* Prepare the EEPROM for writing */
701 status = ixgbe_acquire_eeprom(hw);
702
703 if (status == 0) {
704 if (ixgbe_ready_eeprom(hw) != 0) {
705 ixgbe_release_eeprom(hw);
706 status = IXGBE_ERR_EEPROM;
707 }
708 }
709
710 if (status == 0) {
Emil Tantilov68c70052011-04-20 08:49:06 +0000711 for (i = 0; i < words; i++) {
712 ixgbe_standby_eeprom(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000713
Emil Tantilov68c70052011-04-20 08:49:06 +0000714 /* Send the WRITE ENABLE command (8 bit opcode ) */
715 ixgbe_shift_out_eeprom_bits(hw,
716 IXGBE_EEPROM_WREN_OPCODE_SPI,
717 IXGBE_EEPROM_OPCODE_BITS);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000718
Emil Tantilov68c70052011-04-20 08:49:06 +0000719 ixgbe_standby_eeprom(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000720
Emil Tantilov68c70052011-04-20 08:49:06 +0000721 /*
722 * Some SPI eeproms use the 8th address bit embedded
723 * in the opcode
724 */
725 if ((hw->eeprom.address_bits == 8) &&
726 ((offset + i) >= 128))
727 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000728
Emil Tantilov68c70052011-04-20 08:49:06 +0000729 /* Send the Write command (8-bit opcode + addr) */
730 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
731 IXGBE_EEPROM_OPCODE_BITS);
732 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
733 hw->eeprom.address_bits);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000734
Emil Tantilov68c70052011-04-20 08:49:06 +0000735 page_size = hw->eeprom.word_page_size;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000736
Emil Tantilov68c70052011-04-20 08:49:06 +0000737 /* Send the data in burst via SPI*/
738 do {
739 word = data[i];
740 word = (word >> 8) | (word << 8);
741 ixgbe_shift_out_eeprom_bits(hw, word, 16);
742
743 if (page_size == 0)
744 break;
745
746 /* do not wrap around page */
747 if (((offset + i) & (page_size - 1)) ==
748 (page_size - 1))
749 break;
750 } while (++i < words);
751
752 ixgbe_standby_eeprom(hw);
753 usleep_range(10000, 20000);
754 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000755 /* Done with writing - release the EEPROM */
756 ixgbe_release_eeprom(hw);
757 }
758
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000759 return status;
760}
761
762/**
Emil Tantilov68c70052011-04-20 08:49:06 +0000763 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700764 * @hw: pointer to hardware structure
Emil Tantilov68c70052011-04-20 08:49:06 +0000765 * @offset: offset within the EEPROM to be written to
766 * @data: 16 bit word to be written to the EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700767 *
Emil Tantilov68c70052011-04-20 08:49:06 +0000768 * If ixgbe_eeprom_update_checksum is not called after this function, the
769 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700770 **/
Emil Tantilov68c70052011-04-20 08:49:06 +0000771s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700772{
773 s32 status;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700774
775 hw->eeprom.ops.init_params(hw);
776
777 if (offset >= hw->eeprom.word_size) {
778 status = IXGBE_ERR_EEPROM;
779 goto out;
780 }
781
Emil Tantilov68c70052011-04-20 08:49:06 +0000782 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
783
784out:
785 return status;
786}
787
788/**
789 * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
790 * @hw: pointer to hardware structure
791 * @offset: offset within the EEPROM to be read
792 * @words: number of word(s)
793 * @data: read 16 bit words(s) from EEPROM
794 *
795 * Reads 16 bit word(s) from EEPROM through bit-bang method
796 **/
797s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
798 u16 words, u16 *data)
799{
800 s32 status = 0;
801 u16 i, count;
802
803 hw->eeprom.ops.init_params(hw);
804
805 if (words == 0) {
806 status = IXGBE_ERR_INVALID_ARGUMENT;
807 goto out;
808 }
809
810 if (offset + words > hw->eeprom.word_size) {
811 status = IXGBE_ERR_EEPROM;
812 goto out;
813 }
814
815 /*
816 * We cannot hold synchronization semaphores for too long
817 * to avoid other entity starvation. However it is more efficient
818 * to read in bursts than synchronizing access for each word.
819 */
820 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
821 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
822 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
823
824 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
825 count, &data[i]);
826
827 if (status != 0)
828 break;
829 }
830
831out:
832 return status;
833}
834
835/**
836 * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
837 * @hw: pointer to hardware structure
838 * @offset: offset within the EEPROM to be read
839 * @words: number of word(s)
840 * @data: read 16 bit word(s) from EEPROM
841 *
842 * Reads 16 bit word(s) from EEPROM through bit-bang method
843 **/
844static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
845 u16 words, u16 *data)
846{
847 s32 status;
848 u16 word_in;
849 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
850 u16 i;
851
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700852 /* Prepare the EEPROM for reading */
853 status = ixgbe_acquire_eeprom(hw);
854
855 if (status == 0) {
856 if (ixgbe_ready_eeprom(hw) != 0) {
857 ixgbe_release_eeprom(hw);
858 status = IXGBE_ERR_EEPROM;
859 }
860 }
861
862 if (status == 0) {
Emil Tantilov68c70052011-04-20 08:49:06 +0000863 for (i = 0; i < words; i++) {
864 ixgbe_standby_eeprom(hw);
865 /*
866 * Some SPI eeproms use the 8th address bit embedded
867 * in the opcode
868 */
869 if ((hw->eeprom.address_bits == 8) &&
870 ((offset + i) >= 128))
871 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700872
Emil Tantilov68c70052011-04-20 08:49:06 +0000873 /* Send the READ command (opcode + addr) */
874 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
875 IXGBE_EEPROM_OPCODE_BITS);
876 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
877 hw->eeprom.address_bits);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700878
Emil Tantilov68c70052011-04-20 08:49:06 +0000879 /* Read the data. */
880 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
881 data[i] = (word_in >> 8) | (word_in << 8);
882 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700883
884 /* End this read operation */
885 ixgbe_release_eeprom(hw);
886 }
887
Emil Tantilov68c70052011-04-20 08:49:06 +0000888 return status;
889}
890
891/**
892 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
893 * @hw: pointer to hardware structure
894 * @offset: offset within the EEPROM to be read
895 * @data: read 16 bit value from EEPROM
896 *
897 * Reads 16 bit value from EEPROM through bit-bang method
898 **/
899s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
900 u16 *data)
901{
902 s32 status;
903
904 hw->eeprom.ops.init_params(hw);
905
906 if (offset >= hw->eeprom.word_size) {
907 status = IXGBE_ERR_EEPROM;
908 goto out;
909 }
910
911 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
912
913out:
914 return status;
915}
916
917/**
918 * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
919 * @hw: pointer to hardware structure
920 * @offset: offset of word in the EEPROM to read
921 * @words: number of word(s)
922 * @data: 16 bit word(s) from the EEPROM
923 *
924 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
925 **/
926s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
927 u16 words, u16 *data)
928{
929 u32 eerd;
930 s32 status = 0;
931 u32 i;
932
933 hw->eeprom.ops.init_params(hw);
934
935 if (words == 0) {
936 status = IXGBE_ERR_INVALID_ARGUMENT;
937 goto out;
938 }
939
940 if (offset >= hw->eeprom.word_size) {
941 status = IXGBE_ERR_EEPROM;
942 goto out;
943 }
944
945 for (i = 0; i < words; i++) {
946 eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) +
947 IXGBE_EEPROM_RW_REG_START;
948
949 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
950 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
951
952 if (status == 0) {
953 data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
954 IXGBE_EEPROM_RW_REG_DATA);
955 } else {
956 hw_dbg(hw, "Eeprom read timed out\n");
957 goto out;
958 }
959 }
960out:
961 return status;
962}
963
964/**
965 * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
966 * @hw: pointer to hardware structure
967 * @offset: offset within the EEPROM to be used as a scratch pad
968 *
969 * Discover EEPROM page size by writing marching data at given offset.
970 * This function is called only when we are writing a new large buffer
971 * at given offset so the data would be overwritten anyway.
972 **/
973static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
974 u16 offset)
975{
976 u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
977 s32 status = 0;
978 u16 i;
979
980 for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
981 data[i] = i;
982
983 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
984 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
985 IXGBE_EEPROM_PAGE_SIZE_MAX, data);
986 hw->eeprom.word_page_size = 0;
987 if (status != 0)
988 goto out;
989
990 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
991 if (status != 0)
992 goto out;
993
994 /*
995 * When writing in burst more than the actual page size
996 * EEPROM address wraps around current page.
997 */
998 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
999
1000 hw_dbg(hw, "Detected EEPROM page size = %d words.",
1001 hw->eeprom.word_page_size);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001002out:
1003 return status;
1004}
1005
1006/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001007 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -07001008 * @hw: pointer to hardware structure
1009 * @offset: offset of word in the EEPROM to read
1010 * @data: word read from the EEPROM
1011 *
1012 * Reads a 16 bit word from the EEPROM using the EERD register.
1013 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001014s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -07001015{
Emil Tantilov68c70052011-04-20 08:49:06 +00001016 return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1017}
1018
1019/**
1020 * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1021 * @hw: pointer to hardware structure
1022 * @offset: offset of word in the EEPROM to write
1023 * @words: number of words
1024 * @data: word(s) write to the EEPROM
1025 *
1026 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
1027 **/
1028s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1029 u16 words, u16 *data)
1030{
1031 u32 eewr;
1032 s32 status = 0;
1033 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001034
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001035 hw->eeprom.ops.init_params(hw);
1036
Emil Tantilov68c70052011-04-20 08:49:06 +00001037 if (words == 0) {
1038 status = IXGBE_ERR_INVALID_ARGUMENT;
1039 goto out;
1040 }
1041
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001042 if (offset >= hw->eeprom.word_size) {
1043 status = IXGBE_ERR_EEPROM;
1044 goto out;
1045 }
1046
Emil Tantilov68c70052011-04-20 08:49:06 +00001047 for (i = 0; i < words; i++) {
1048 eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1049 (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1050 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -07001051
Emil Tantilov68c70052011-04-20 08:49:06 +00001052 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1053 if (status != 0) {
1054 hw_dbg(hw, "Eeprom write EEWR timed out\n");
1055 goto out;
1056 }
Auke Kok9a799d72007-09-15 14:07:45 -07001057
Emil Tantilov68c70052011-04-20 08:49:06 +00001058 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1059
1060 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1061 if (status != 0) {
1062 hw_dbg(hw, "Eeprom write EEWR timed out\n");
1063 goto out;
1064 }
1065 }
Auke Kok9a799d72007-09-15 14:07:45 -07001066
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001067out:
Auke Kok9a799d72007-09-15 14:07:45 -07001068 return status;
1069}
1070
1071/**
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001072 * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1073 * @hw: pointer to hardware structure
1074 * @offset: offset of word in the EEPROM to write
1075 * @data: word write to the EEPROM
1076 *
1077 * Write a 16 bit word to the EEPROM using the EEWR register.
1078 **/
1079s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1080{
Emil Tantilov68c70052011-04-20 08:49:06 +00001081 return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001082}
1083
1084/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001085 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -07001086 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001087 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -07001088 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001089 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1090 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -07001091 **/
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001092static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -07001093{
1094 u32 i;
1095 u32 reg;
1096 s32 status = IXGBE_ERR_EEPROM;
1097
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001098 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1099 if (ee_reg == IXGBE_NVM_POLL_READ)
1100 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1101 else
1102 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1103
1104 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -07001105 status = 0;
1106 break;
1107 }
1108 udelay(5);
1109 }
1110 return status;
1111}
1112
1113/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001114 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1115 * @hw: pointer to hardware structure
1116 *
1117 * Prepares EEPROM for access using bit-bang method. This function should
1118 * be called before issuing a command to the EEPROM.
1119 **/
1120static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1121{
1122 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001123 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001124 u32 i;
1125
Don Skidmore5e655102011-02-25 01:58:04 +00001126 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001127 status = IXGBE_ERR_SWFW_SYNC;
1128
1129 if (status == 0) {
1130 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1131
1132 /* Request EEPROM Access */
1133 eec |= IXGBE_EEC_REQ;
1134 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1135
1136 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1137 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1138 if (eec & IXGBE_EEC_GNT)
1139 break;
1140 udelay(5);
1141 }
1142
1143 /* Release if grant not acquired */
1144 if (!(eec & IXGBE_EEC_GNT)) {
1145 eec &= ~IXGBE_EEC_REQ;
1146 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1147 hw_dbg(hw, "Could not acquire EEPROM grant\n");
1148
Don Skidmore5e655102011-02-25 01:58:04 +00001149 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001150 status = IXGBE_ERR_EEPROM;
1151 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001152
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001153 /* Setup EEPROM for Read/Write */
1154 if (status == 0) {
1155 /* Clear CS and SK */
1156 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1157 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1158 IXGBE_WRITE_FLUSH(hw);
1159 udelay(1);
1160 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001161 }
1162 return status;
1163}
1164
1165/**
Auke Kok9a799d72007-09-15 14:07:45 -07001166 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
1167 * @hw: pointer to hardware structure
1168 *
1169 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1170 **/
1171static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1172{
1173 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001174 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -07001175 u32 i;
1176 u32 swsm;
1177
Auke Kok9a799d72007-09-15 14:07:45 -07001178 /* Get SMBI software semaphore between device drivers first */
1179 for (i = 0; i < timeout; i++) {
1180 /*
1181 * If the SMBI bit is 0 when we read it, then the bit will be
1182 * set and we have the semaphore
1183 */
1184 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1185 if (!(swsm & IXGBE_SWSM_SMBI)) {
1186 status = 0;
1187 break;
1188 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001189 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -07001190 }
1191
1192 /* Now get the semaphore between SW/FW through the SWESMBI bit */
1193 if (status == 0) {
1194 for (i = 0; i < timeout; i++) {
1195 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1196
1197 /* Set the SW EEPROM semaphore bit to request access */
1198 swsm |= IXGBE_SWSM_SWESMBI;
1199 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1200
1201 /*
1202 * If we set the bit successfully then we got the
1203 * semaphore.
1204 */
1205 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1206 if (swsm & IXGBE_SWSM_SWESMBI)
1207 break;
1208
1209 udelay(50);
1210 }
1211
1212 /*
1213 * Release semaphores and return error if SW EEPROM semaphore
1214 * was not granted because we don't have access to the EEPROM
1215 */
1216 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001217 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001218 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001219 ixgbe_release_eeprom_semaphore(hw);
1220 status = IXGBE_ERR_EEPROM;
1221 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001222 } else {
1223 hw_dbg(hw, "Software semaphore SMBI between device drivers "
1224 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001225 }
1226
1227 return status;
1228}
1229
1230/**
1231 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
1232 * @hw: pointer to hardware structure
1233 *
1234 * This function clears hardware semaphore bits.
1235 **/
1236static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1237{
1238 u32 swsm;
1239
1240 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1241
1242 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1243 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1244 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -07001245 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001246}
1247
1248/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001249 * ixgbe_ready_eeprom - Polls for EEPROM ready
1250 * @hw: pointer to hardware structure
1251 **/
1252static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1253{
1254 s32 status = 0;
1255 u16 i;
1256 u8 spi_stat_reg;
1257
1258 /*
1259 * Read "Status Register" repeatedly until the LSB is cleared. The
1260 * EEPROM will signal that the command has been completed by clearing
1261 * bit 0 of the internal status register. If it's not cleared within
1262 * 5 milliseconds, then error out.
1263 */
1264 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1265 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1266 IXGBE_EEPROM_OPCODE_BITS);
1267 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1268 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
1269 break;
1270
1271 udelay(5);
1272 ixgbe_standby_eeprom(hw);
1273 };
1274
1275 /*
1276 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
1277 * devices (and only 0-5mSec on 5V devices)
1278 */
1279 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
1280 hw_dbg(hw, "SPI EEPROM Status error\n");
1281 status = IXGBE_ERR_EEPROM;
1282 }
1283
1284 return status;
1285}
1286
1287/**
1288 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
1289 * @hw: pointer to hardware structure
1290 **/
1291static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
1292{
1293 u32 eec;
1294
1295 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1296
1297 /* Toggle CS to flush commands */
1298 eec |= IXGBE_EEC_CS;
1299 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1300 IXGBE_WRITE_FLUSH(hw);
1301 udelay(1);
1302 eec &= ~IXGBE_EEC_CS;
1303 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1304 IXGBE_WRITE_FLUSH(hw);
1305 udelay(1);
1306}
1307
1308/**
1309 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1310 * @hw: pointer to hardware structure
1311 * @data: data to send to the EEPROM
1312 * @count: number of bits to shift out
1313 **/
1314static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1315 u16 count)
1316{
1317 u32 eec;
1318 u32 mask;
1319 u32 i;
1320
1321 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1322
1323 /*
1324 * Mask is used to shift "count" bits of "data" out to the EEPROM
1325 * one bit at a time. Determine the starting bit based on count
1326 */
1327 mask = 0x01 << (count - 1);
1328
1329 for (i = 0; i < count; i++) {
1330 /*
1331 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1332 * "1", and then raising and then lowering the clock (the SK
1333 * bit controls the clock input to the EEPROM). A "0" is
1334 * shifted out to the EEPROM by setting "DI" to "0" and then
1335 * raising and then lowering the clock.
1336 */
1337 if (data & mask)
1338 eec |= IXGBE_EEC_DI;
1339 else
1340 eec &= ~IXGBE_EEC_DI;
1341
1342 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1343 IXGBE_WRITE_FLUSH(hw);
1344
1345 udelay(1);
1346
1347 ixgbe_raise_eeprom_clk(hw, &eec);
1348 ixgbe_lower_eeprom_clk(hw, &eec);
1349
1350 /*
1351 * Shift mask to signify next bit of data to shift in to the
1352 * EEPROM
1353 */
1354 mask = mask >> 1;
1355 };
1356
1357 /* We leave the "DI" bit set to "0" when we leave this routine. */
1358 eec &= ~IXGBE_EEC_DI;
1359 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1360 IXGBE_WRITE_FLUSH(hw);
1361}
1362
1363/**
1364 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1365 * @hw: pointer to hardware structure
1366 **/
1367static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1368{
1369 u32 eec;
1370 u32 i;
1371 u16 data = 0;
1372
1373 /*
1374 * In order to read a register from the EEPROM, we need to shift
1375 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1376 * the clock input to the EEPROM (setting the SK bit), and then reading
1377 * the value of the "DO" bit. During this "shifting in" process the
1378 * "DI" bit should always be clear.
1379 */
1380 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1381
1382 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1383
1384 for (i = 0; i < count; i++) {
1385 data = data << 1;
1386 ixgbe_raise_eeprom_clk(hw, &eec);
1387
1388 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1389
1390 eec &= ~(IXGBE_EEC_DI);
1391 if (eec & IXGBE_EEC_DO)
1392 data |= 1;
1393
1394 ixgbe_lower_eeprom_clk(hw, &eec);
1395 }
1396
1397 return data;
1398}
1399
1400/**
1401 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1402 * @hw: pointer to hardware structure
1403 * @eec: EEC register's current value
1404 **/
1405static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1406{
1407 /*
1408 * Raise the clock input to the EEPROM
1409 * (setting the SK bit), then delay
1410 */
1411 *eec = *eec | IXGBE_EEC_SK;
1412 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1413 IXGBE_WRITE_FLUSH(hw);
1414 udelay(1);
1415}
1416
1417/**
1418 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1419 * @hw: pointer to hardware structure
1420 * @eecd: EECD's current value
1421 **/
1422static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1423{
1424 /*
1425 * Lower the clock input to the EEPROM (clearing the SK bit), then
1426 * delay
1427 */
1428 *eec = *eec & ~IXGBE_EEC_SK;
1429 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1430 IXGBE_WRITE_FLUSH(hw);
1431 udelay(1);
1432}
1433
1434/**
1435 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1436 * @hw: pointer to hardware structure
1437 **/
1438static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1439{
1440 u32 eec;
1441
1442 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1443
1444 eec |= IXGBE_EEC_CS; /* Pull CS high */
1445 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1446
1447 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1448 IXGBE_WRITE_FLUSH(hw);
1449
1450 udelay(1);
1451
1452 /* Stop requesting EEPROM access */
1453 eec &= ~IXGBE_EEC_REQ;
1454 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1455
Don Skidmore90827992011-03-05 18:59:20 -08001456 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001457
Don Skidmore032b4322011-03-18 09:32:53 +00001458 /*
1459 * Delay before attempt to obtain semaphore again to allow FW
1460 * access. semaphore_delay is in ms we need us for usleep_range
1461 */
1462 usleep_range(hw->eeprom.semaphore_delay * 1000,
1463 hw->eeprom.semaphore_delay * 2000);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001464}
1465
1466/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001467 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001468 * @hw: pointer to hardware structure
1469 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001470u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001471{
1472 u16 i;
1473 u16 j;
1474 u16 checksum = 0;
1475 u16 length = 0;
1476 u16 pointer = 0;
1477 u16 word = 0;
1478
1479 /* Include 0x0-0x3F in the checksum */
1480 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001481 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001482 hw_dbg(hw, "EEPROM read failed\n");
1483 break;
1484 }
1485 checksum += word;
1486 }
1487
1488 /* Include all data from pointers except for the fw pointer */
1489 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001490 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001491
1492 /* Make sure the pointer seems valid */
1493 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001494 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001495
1496 if (length != 0xFFFF && length != 0) {
1497 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001498 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001499 checksum += word;
1500 }
1501 }
1502 }
1503 }
1504
1505 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1506
1507 return checksum;
1508}
1509
1510/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001511 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001512 * @hw: pointer to hardware structure
1513 * @checksum_val: calculated checksum
1514 *
1515 * Performs checksum calculation and validates the EEPROM checksum. If the
1516 * caller does not need checksum_val, the value can be NULL.
1517 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001518s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1519 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001520{
1521 s32 status;
1522 u16 checksum;
1523 u16 read_checksum = 0;
1524
1525 /*
1526 * Read the first word from the EEPROM. If this times out or fails, do
1527 * not continue or we could be in for a very long wait while every
1528 * EEPROM read fails
1529 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001530 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001531
1532 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001533 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001534
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001535 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001536
1537 /*
1538 * Verify read checksum from EEPROM is the same as
1539 * calculated checksum
1540 */
1541 if (read_checksum != checksum)
1542 status = IXGBE_ERR_EEPROM_CHECKSUM;
1543
1544 /* If the user cares, return the calculated checksum */
1545 if (checksum_val)
1546 *checksum_val = checksum;
1547 } else {
1548 hw_dbg(hw, "EEPROM read failed\n");
1549 }
1550
1551 return status;
1552}
1553
1554/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001555 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1556 * @hw: pointer to hardware structure
1557 **/
1558s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1559{
1560 s32 status;
1561 u16 checksum;
1562
1563 /*
1564 * Read the first word from the EEPROM. If this times out or fails, do
1565 * not continue or we could be in for a very long wait while every
1566 * EEPROM read fails
1567 */
1568 status = hw->eeprom.ops.read(hw, 0, &checksum);
1569
1570 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001571 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001572 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001573 checksum);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001574 } else {
1575 hw_dbg(hw, "EEPROM read failed\n");
1576 }
1577
1578 return status;
1579}
1580
1581/**
Auke Kok9a799d72007-09-15 14:07:45 -07001582 * ixgbe_validate_mac_addr - Validate MAC address
1583 * @mac_addr: pointer to MAC address.
1584 *
1585 * Tests a MAC address to ensure it is a valid Individual Address
1586 **/
1587s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1588{
1589 s32 status = 0;
1590
1591 /* Make sure it is not a multicast address */
1592 if (IXGBE_IS_MULTICAST(mac_addr))
1593 status = IXGBE_ERR_INVALID_MAC_ADDR;
1594 /* Not a broadcast address */
1595 else if (IXGBE_IS_BROADCAST(mac_addr))
1596 status = IXGBE_ERR_INVALID_MAC_ADDR;
1597 /* Reject the zero address */
1598 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001599 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001600 status = IXGBE_ERR_INVALID_MAC_ADDR;
1601
1602 return status;
1603}
1604
1605/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001606 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001607 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001608 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001609 * @addr: Address to put into receive address register
1610 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001611 * @enable_addr: set flag that address is active
1612 *
1613 * Puts an ethernet address into a receive address register.
1614 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001615s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1616 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001617{
1618 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001619 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001620
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001621 /* Make sure we are using a valid rar index range */
1622 if (index >= rar_entries) {
1623 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1624 return IXGBE_ERR_INVALID_ARGUMENT;
1625 }
1626
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001627 /* setup VMDq pool selection before this RAR gets enabled */
1628 hw->mac.ops.set_vmdq(hw, index, vmdq);
1629
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001630 /*
1631 * HW expects these in little endian so we reverse the byte
1632 * order from network order (big endian) to little endian
1633 */
1634 rar_low = ((u32)addr[0] |
1635 ((u32)addr[1] << 8) |
1636 ((u32)addr[2] << 16) |
1637 ((u32)addr[3] << 24));
1638 /*
1639 * Some parts put the VMDq setting in the extra RAH bits,
1640 * so save everything except the lower 16 bits that hold part
1641 * of the address and the address valid bit.
1642 */
1643 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1644 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1645 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001646
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001647 if (enable_addr != 0)
1648 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001649
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001650 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1651 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001652
1653 return 0;
1654}
1655
1656/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001657 * ixgbe_clear_rar_generic - Remove Rx address register
1658 * @hw: pointer to hardware structure
1659 * @index: Receive address register to write
1660 *
1661 * Clears an ethernet address from a receive address register.
1662 **/
1663s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1664{
1665 u32 rar_high;
1666 u32 rar_entries = hw->mac.num_rar_entries;
1667
1668 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001669 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001670 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001671 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001672 }
1673
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001674 /*
1675 * Some parts put the VMDq setting in the extra RAH bits,
1676 * so save everything except the lower 16 bits that hold part
1677 * of the address and the address valid bit.
1678 */
1679 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1680 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1681
1682 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1683 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1684
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001685 /* clear VMDq pool/queue selection for this RAR */
1686 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1687
1688 return 0;
1689}
1690
1691/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001692 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001693 * @hw: pointer to hardware structure
1694 *
1695 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001696 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001697 * the receiver is in reset when the routine is called.
1698 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001699s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001700{
1701 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001702 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001703
1704 /*
1705 * If the current mac address is valid, assume it is a software override
1706 * to the permanent address.
1707 * Otherwise, use the permanent address from the eeprom.
1708 */
1709 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1710 IXGBE_ERR_INVALID_MAC_ADDR) {
1711 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001712 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001713
hartleysce7194d2010-01-05 06:56:52 +00001714 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001715 } else {
1716 /* Setup the receive address. */
1717 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001718 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001719
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001720 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001721
1722 /* clear VMDq pool/queue selection for RAR 0 */
1723 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001724 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001725 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001726
1727 hw->addr_ctrl.rar_used_count = 1;
1728
1729 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001730 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001731 for (i = 1; i < rar_entries; i++) {
1732 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1733 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1734 }
1735
1736 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001737 hw->addr_ctrl.mta_in_use = 0;
1738 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1739
1740 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001741 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001742 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1743
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001744 if (hw->mac.ops.init_uta_tables)
1745 hw->mac.ops.init_uta_tables(hw);
1746
Auke Kok9a799d72007-09-15 14:07:45 -07001747 return 0;
1748}
1749
1750/**
1751 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1752 * @hw: pointer to hardware structure
1753 * @mc_addr: the multicast address
1754 *
1755 * Extracts the 12 bits, from a multicast address, to determine which
1756 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1757 * incoming rx multicast addresses, to determine the bit-vector to check in
1758 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001759 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001760 * to mc_filter_type.
1761 **/
1762static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1763{
1764 u32 vector = 0;
1765
1766 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001767 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001768 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1769 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001770 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001771 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1772 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001773 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001774 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1775 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001776 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001777 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1778 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001779 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001780 hw_dbg(hw, "MC filter type param set incorrectly\n");
1781 break;
1782 }
1783
1784 /* vector can only be 12-bits or boundary will be exceeded */
1785 vector &= 0xFFF;
1786 return vector;
1787}
1788
1789/**
1790 * ixgbe_set_mta - Set bit-vector in multicast table
1791 * @hw: pointer to hardware structure
1792 * @hash_value: Multicast address hash value
1793 *
1794 * Sets the bit-vector in the multicast table.
1795 **/
1796static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1797{
1798 u32 vector;
1799 u32 vector_bit;
1800 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001801
1802 hw->addr_ctrl.mta_in_use++;
1803
1804 vector = ixgbe_mta_vector(hw, mc_addr);
1805 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1806
1807 /*
1808 * The MTA is a register array of 128 32-bit registers. It is treated
1809 * like an array of 4096 bits. We want to set bit
1810 * BitArray[vector_value]. So we figure out what register the bit is
1811 * in, read it, OR in the new bit, then write back the new value. The
1812 * register is determined by the upper 7 bits of the vector value and
1813 * the bit within that register are determined by the lower 5 bits of
1814 * the value.
1815 */
1816 vector_reg = (vector >> 5) & 0x7F;
1817 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00001818 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001819}
1820
1821/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001822 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001823 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001824 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001825 *
1826 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001827 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001828 * registers for the first multicast addresses, and hashes the rest into the
1829 * multicast table.
1830 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001831s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1832 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001833{
Jiri Pirko22bedad2010-04-01 21:22:57 +00001834 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001835 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001836
1837 /*
1838 * Set the new number of MC addresses that we are being requested to
1839 * use.
1840 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001841 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001842 hw->addr_ctrl.mta_in_use = 0;
1843
Emil Tantilov80960ab2011-02-18 08:58:27 +00001844 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001845 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001846 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001847
Emil Tantilov80960ab2011-02-18 08:58:27 +00001848 /* Update mta shadow */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001849 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001850 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad2010-04-01 21:22:57 +00001851 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001852 }
1853
1854 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001855 for (i = 0; i < hw->mac.mcft_size; i++)
1856 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1857 hw->mac.mta_shadow[i]);
1858
Auke Kok9a799d72007-09-15 14:07:45 -07001859 if (hw->addr_ctrl.mta_in_use > 0)
1860 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001861 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001862
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001863 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001864 return 0;
1865}
1866
1867/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001868 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001869 * @hw: pointer to hardware structure
1870 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001871 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001872 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001873s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001874{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001875 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001876
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001877 if (a->mta_in_use > 0)
1878 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1879 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001880
1881 return 0;
1882}
1883
1884/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001885 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001886 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001887 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001888 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001889 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001890s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001891{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001892 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001893
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001894 if (a->mta_in_use > 0)
1895 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001896
1897 return 0;
1898}
1899
1900/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001901 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001902 * @hw: pointer to hardware structure
1903 * @packetbuf_num: packet buffer number (0-7)
1904 *
1905 * Enable flow control according to the current settings.
1906 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001907s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001908{
1909 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001910 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001911 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001912 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001913 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001914
1915#ifdef CONFIG_DCB
1916 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1917 goto out;
1918
1919#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001920 /* Negotiate the fc mode to use */
1921 ret_val = ixgbe_fc_autoneg(hw);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001922 if (ret_val == IXGBE_ERR_FLOW_CONTROL)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001923 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001924
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001925 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001926 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1927 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1928
1929 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1930 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1931
1932 /*
1933 * The possible values of fc.current_mode are:
1934 * 0: Flow control is completely disabled
1935 * 1: Rx flow control is enabled (we can receive pause frames,
1936 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001937 * 2: Tx flow control is enabled (we can send pause frames but
1938 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001939 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001940#ifdef CONFIG_DCB
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001941 * 4: Priority Flow Control is enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001942#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001943 * other: Invalid.
1944 */
1945 switch (hw->fc.current_mode) {
1946 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001947 /*
1948 * Flow control is disabled by software override or autoneg.
1949 * The code below will actually disable it in the HW.
1950 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001951 break;
1952 case ixgbe_fc_rx_pause:
1953 /*
1954 * Rx Flow control is enabled and Tx Flow control is
1955 * disabled by software override. Since there really
1956 * isn't a way to advertise that we are capable of RX
1957 * Pause ONLY, we will advertise that we support both
1958 * symmetric and asymmetric Rx PAUSE. Later, we will
1959 * disable the adapter's ability to send PAUSE frames.
1960 */
1961 mflcn_reg |= IXGBE_MFLCN_RFCE;
1962 break;
1963 case ixgbe_fc_tx_pause:
1964 /*
1965 * Tx Flow control is enabled, and Rx Flow control is
1966 * disabled by software override.
1967 */
1968 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1969 break;
1970 case ixgbe_fc_full:
1971 /* Flow control (both Rx and Tx) is enabled by SW override. */
1972 mflcn_reg |= IXGBE_MFLCN_RFCE;
1973 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1974 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001975#ifdef CONFIG_DCB
1976 case ixgbe_fc_pfc:
1977 goto out;
1978 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001979#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001980 default:
1981 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001982 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001983 goto out;
1984 break;
1985 }
1986
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001987 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001988 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001989 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1990 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1991
John Fastabend16b61be2010-11-16 19:26:44 -08001992 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1993 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001994
John Fastabend16b61be2010-11-16 19:26:44 -08001995 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1996 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001997
John Fastabend16b61be2010-11-16 19:26:44 -08001998 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1999 fcrth |= IXGBE_FCRTH_FCEN;
2000 if (hw->fc.send_xon)
2001 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002002 }
2003
John Fastabend16b61be2010-11-16 19:26:44 -08002004 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
2005 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
2006
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002007 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00002008 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002009 if ((packetbuf_num & 1) == 0)
2010 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
2011 else
2012 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
2013 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
2014
2015 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
2016
2017out:
2018 return ret_val;
2019}
2020
2021/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002022 * ixgbe_fc_autoneg - Configure flow control
2023 * @hw: pointer to hardware structure
2024 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002025 * Compares our advertised flow control capabilities to those advertised by
2026 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002027 **/
2028s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
2029{
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002030 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002031 ixgbe_link_speed speed;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002032 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002033
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002034 if (hw->fc.disable_fc_autoneg)
2035 goto out;
2036
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002037 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002038 * AN should have completed when the cable was plugged in.
2039 * Look for reasons to bail out. Bail out if:
2040 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002041 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002042 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002043 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002044 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002045 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002046 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002047 if (!link_up) {
2048 ret_val = IXGBE_ERR_FLOW_CONTROL;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002049 goto out;
2050 }
2051
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002052 switch (hw->phy.media_type) {
2053 /* Autoneg flow control on fiber adapters */
2054 case ixgbe_media_type_fiber:
2055 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
2056 ret_val = ixgbe_fc_autoneg_fiber(hw);
2057 break;
Don Skidmore000c4862009-11-24 18:51:48 +00002058
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002059 /* Autoneg flow control on backplane adapters */
2060 case ixgbe_media_type_backplane:
2061 ret_val = ixgbe_fc_autoneg_backplane(hw);
2062 break;
2063
2064 /* Autoneg flow control on copper adapters */
2065 case ixgbe_media_type_copper:
2066 if (ixgbe_device_supports_autoneg_fc(hw) == 0)
2067 ret_val = ixgbe_fc_autoneg_copper(hw);
2068 break;
2069
2070 default:
2071 break;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002072 }
2073
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002074out:
2075 if (ret_val == 0) {
2076 hw->fc.fc_was_autonegged = true;
2077 } else {
2078 hw->fc.fc_was_autonegged = false;
2079 hw->fc.current_mode = hw->fc.requested_mode;
2080 }
2081 return ret_val;
2082}
2083
2084/**
2085 * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2086 * @hw: pointer to hardware structure
2087 *
2088 * Enable flow control according on 1 gig fiber.
2089 **/
2090static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
2091{
2092 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
2093 s32 ret_val;
2094
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002095 /*
2096 * On multispeed fiber at 1g, bail out if
2097 * - link is up but AN did not complete, or if
2098 * - link is up and AN completed but timed out
2099 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002100
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002101 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
2102 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
2103 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
2104 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00002105 goto out;
2106 }
2107
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002108 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2109 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002110
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002111 ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
2112 pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
2113 IXGBE_PCS1GANA_ASM_PAUSE,
2114 IXGBE_PCS1GANA_SYM_PAUSE,
2115 IXGBE_PCS1GANA_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002116
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002117out:
2118 return ret_val;
2119}
2120
2121/**
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002122 * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2123 * @hw: pointer to hardware structure
2124 *
2125 * Enable flow control according to IEEE clause 37.
2126 **/
2127static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2128{
2129 u32 links2, anlp1_reg, autoc_reg, links;
2130 s32 ret_val;
2131
2132 /*
2133 * On backplane, bail out if
2134 * - backplane autoneg was not completed, or if
2135 * - we are 82599 and link partner is not AN enabled
2136 */
2137 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
2138 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
2139 hw->fc.fc_was_autonegged = false;
2140 hw->fc.current_mode = hw->fc.requested_mode;
2141 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2142 goto out;
2143 }
2144
2145 if (hw->mac.type == ixgbe_mac_82599EB) {
2146 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
2147 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
2148 hw->fc.fc_was_autonegged = false;
2149 hw->fc.current_mode = hw->fc.requested_mode;
2150 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2151 goto out;
2152 }
2153 }
2154 /*
2155 * Read the 10g AN autoc and LP ability registers and resolve
2156 * local flow control settings accordingly
2157 */
2158 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2159 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2160
2161 ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2162 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2163 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
2164
2165out:
2166 return ret_val;
2167}
2168
2169/**
2170 * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2171 * @hw: pointer to hardware structure
2172 *
2173 * Enable flow control according to IEEE clause 37.
2174 **/
2175static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2176{
2177 u16 technology_ability_reg = 0;
2178 u16 lp_technology_ability_reg = 0;
2179
2180 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
2181 MDIO_MMD_AN,
2182 &technology_ability_reg);
2183 hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
2184 MDIO_MMD_AN,
2185 &lp_technology_ability_reg);
2186
2187 return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2188 (u32)lp_technology_ability_reg,
2189 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2190 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
2191}
2192
2193/**
2194 * ixgbe_negotiate_fc - Negotiate flow control
2195 * @hw: pointer to hardware structure
2196 * @adv_reg: flow control advertised settings
2197 * @lp_reg: link partner's flow control settings
2198 * @adv_sym: symmetric pause bit in advertisement
2199 * @adv_asm: asymmetric pause bit in advertisement
2200 * @lp_sym: symmetric pause bit in link partner advertisement
2201 * @lp_asm: asymmetric pause bit in link partner advertisement
2202 *
2203 * Find the intersection between advertised settings and link partner's
2204 * advertised settings
2205 **/
2206static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2207 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2208{
2209 if ((!(adv_reg)) || (!(lp_reg)))
2210 return IXGBE_ERR_FC_NOT_NEGOTIATED;
2211
2212 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2213 /*
2214 * Now we need to check if the user selected Rx ONLY
2215 * of pause frames. In this case, we had to advertise
2216 * FULL flow control because we could not advertise RX
2217 * ONLY. Hence, we must now check to see if we need to
2218 * turn OFF the TRANSMISSION of PAUSE frames.
2219 */
2220 if (hw->fc.requested_mode == ixgbe_fc_full) {
2221 hw->fc.current_mode = ixgbe_fc_full;
2222 hw_dbg(hw, "Flow Control = FULL.\n");
2223 } else {
2224 hw->fc.current_mode = ixgbe_fc_rx_pause;
2225 hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
2226 }
2227 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2228 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2229 hw->fc.current_mode = ixgbe_fc_tx_pause;
2230 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
2231 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2232 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2233 hw->fc.current_mode = ixgbe_fc_rx_pause;
2234 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
2235 } else {
2236 hw->fc.current_mode = ixgbe_fc_none;
2237 hw_dbg(hw, "Flow Control = NONE.\n");
2238 }
2239 return 0;
2240}
2241
2242/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002243 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002244 * @hw: pointer to hardware structure
2245 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002246 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002247 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00002248static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002249{
2250 s32 ret_val = 0;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002251 u32 reg = 0, reg_bp = 0;
2252 u16 reg_cu = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002253
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00002254#ifdef CONFIG_DCB
2255 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
2256 hw->fc.current_mode = hw->fc.requested_mode;
2257 goto out;
2258 }
2259
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002260#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002261 /* Validate the packetbuf configuration */
2262 if (packetbuf_num < 0 || packetbuf_num > 7) {
2263 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
2264 "is 0-7\n", packetbuf_num);
2265 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2266 goto out;
2267 }
2268
2269 /*
2270 * Validate the water mark configuration. Zero water marks are invalid
2271 * because it causes the controller to just blast out fc packets.
2272 */
2273 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002274 hw_dbg(hw, "Invalid water mark configuration\n");
2275 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2276 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002277 }
2278
2279 /*
2280 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002281 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002282 */
2283 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2284 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
2285 "IEEE mode\n");
2286 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2287 goto out;
2288 }
2289
2290 /*
2291 * 10gig parts do not have a word in the EEPROM to determine the
2292 * default flow control setting, so we explicitly set it to full.
2293 */
2294 if (hw->fc.requested_mode == ixgbe_fc_default)
2295 hw->fc.requested_mode = ixgbe_fc_full;
2296
2297 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002298 * Set up the 1G and 10G flow control advertisement registers so the
2299 * HW will be able to do fc autoneg once the cable is plugged in. If
2300 * we link at 10G, the 1G advertisement is harmless and vice versa.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002301 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002302
2303 switch (hw->phy.media_type) {
2304 case ixgbe_media_type_fiber:
2305 case ixgbe_media_type_backplane:
2306 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2307 reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2308 break;
2309
2310 case ixgbe_media_type_copper:
2311 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
2312 MDIO_MMD_AN, &reg_cu);
2313 break;
2314
2315 default:
2316 ;
2317 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002318
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002319 /*
2320 * The possible values of fc.requested_mode are:
2321 * 0: Flow control is completely disabled
2322 * 1: Rx flow control is enabled (we can receive pause frames,
2323 * but not send pause frames).
2324 * 2: Tx flow control is enabled (we can send pause frames but
2325 * we do not support receiving pause frames).
2326 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2327#ifdef CONFIG_DCB
2328 * 4: Priority Flow Control is enabled.
2329#endif
2330 * other: Invalid.
2331 */
2332 switch (hw->fc.requested_mode) {
2333 case ixgbe_fc_none:
2334 /* Flow control completely disabled by software override. */
2335 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002336 if (hw->phy.media_type == ixgbe_media_type_backplane)
2337 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
2338 IXGBE_AUTOC_ASM_PAUSE);
2339 else if (hw->phy.media_type == ixgbe_media_type_copper)
2340 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002341 break;
2342 case ixgbe_fc_rx_pause:
2343 /*
2344 * Rx Flow control is enabled and Tx Flow control is
2345 * disabled by software override. Since there really
2346 * isn't a way to advertise that we are capable of RX
2347 * Pause ONLY, we will advertise that we support both
2348 * symmetric and asymmetric Rx PAUSE. Later, we will
2349 * disable the adapter's ability to send PAUSE frames.
2350 */
2351 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002352 if (hw->phy.media_type == ixgbe_media_type_backplane)
2353 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2354 IXGBE_AUTOC_ASM_PAUSE);
2355 else if (hw->phy.media_type == ixgbe_media_type_copper)
2356 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002357 break;
2358 case ixgbe_fc_tx_pause:
2359 /*
2360 * Tx Flow control is enabled, and Rx Flow control is
2361 * disabled by software override.
2362 */
2363 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2364 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002365 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2366 reg_bp |= (IXGBE_AUTOC_ASM_PAUSE);
2367 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE);
2368 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
2369 reg_cu |= (IXGBE_TAF_ASM_PAUSE);
2370 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE);
2371 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002372 break;
2373 case ixgbe_fc_full:
2374 /* Flow control (both Rx and Tx) is enabled by SW override. */
2375 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002376 if (hw->phy.media_type == ixgbe_media_type_backplane)
2377 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2378 IXGBE_AUTOC_ASM_PAUSE);
2379 else if (hw->phy.media_type == ixgbe_media_type_copper)
2380 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002381 break;
2382#ifdef CONFIG_DCB
2383 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002384 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002385 break;
2386#endif /* CONFIG_DCB */
2387 default:
2388 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002389 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002390 goto out;
2391 break;
2392 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002393
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002394 if (hw->mac.type != ixgbe_mac_X540) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002395 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002396 * Enable auto-negotiation between the MAC & PHY;
2397 * the MAC will advertise clause 37 flow control.
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002398 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002399 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2400 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2401
2402 /* Disable AN timeout */
2403 if (hw->fc.strict_ieee)
2404 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2405
2406 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2407 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002408 }
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002409
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002410 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002411 * AUTOC restart handles negotiation of 1G and 10G on backplane
2412 * and copper. There is no need to set the PCS1GCTL register.
2413 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002414 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002415 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2416 reg_bp |= IXGBE_AUTOC_AN_RESTART;
2417 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
2418 } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
2419 (ixgbe_device_supports_autoneg_fc(hw) == 0)) {
2420 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
2421 MDIO_MMD_AN, reg_cu);
2422 }
2423
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002424 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002425out:
2426 return ret_val;
2427}
2428
2429/**
Auke Kok9a799d72007-09-15 14:07:45 -07002430 * ixgbe_disable_pcie_master - Disable PCI-express master access
2431 * @hw: pointer to hardware structure
2432 *
2433 * Disables PCI-Express master access and verifies there are no pending
2434 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2435 * bit hasn't caused the master requests to be disabled, else 0
2436 * is returned signifying master requests disabled.
2437 **/
2438s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2439{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002440 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002441 u32 i;
2442 u32 reg_val;
2443 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002444 s32 status = 0;
2445 u16 dev_status = 0;
2446
2447 /* Just jump out if bus mastering is already disabled */
2448 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2449 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002450
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002451 /* Disable the receive unit by stopping each queue */
2452 number_of_queues = hw->mac.max_rx_queues;
2453 for (i = 0; i < number_of_queues; i++) {
2454 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2455 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2456 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2457 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2458 }
2459 }
2460
2461 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2462 reg_val |= IXGBE_CTRL_GIO_DIS;
2463 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002464
2465 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002466 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2467 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002468 udelay(100);
2469 }
2470
Emil Tantilova4297dc2011-02-14 08:45:13 +00002471 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2472 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2473
2474 /*
2475 * Before proceeding, make sure that the PCIe block does not have
2476 * transactions pending.
2477 */
2478check_device_status:
2479 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2480 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2481 &dev_status);
2482 if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2483 break;
2484 udelay(100);
2485 }
2486
2487 if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
2488 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2489 else
2490 goto out;
2491
2492 /*
2493 * Two consecutive resets are required via CTRL.RST per datasheet
2494 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2495 * of this need. The first reset prevents new master requests from
2496 * being issued by our device. We then must wait 1usec for any
2497 * remaining completions from the PCIe bus to trickle in, and then reset
2498 * again to clear out any effects they may have had on our device.
2499 */
2500 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2501
2502out:
Auke Kok9a799d72007-09-15 14:07:45 -07002503 return status;
2504}
2505
2506
2507/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002508 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002509 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002510 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002511 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002512 * Acquires the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002513 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2514 **/
2515s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2516{
2517 u32 gssr;
2518 u32 swmask = mask;
2519 u32 fwmask = mask << 5;
2520 s32 timeout = 200;
2521
2522 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002523 /*
2524 * SW EEPROM semaphore bit is used for access to all
2525 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2526 */
Auke Kok9a799d72007-09-15 14:07:45 -07002527 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002528 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002529
2530 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2531 if (!(gssr & (fwmask | swmask)))
2532 break;
2533
2534 /*
2535 * Firmware currently using resource (fwmask) or other software
2536 * thread currently using resource (swmask)
2537 */
2538 ixgbe_release_eeprom_semaphore(hw);
Don Skidmore032b4322011-03-18 09:32:53 +00002539 usleep_range(5000, 10000);
Auke Kok9a799d72007-09-15 14:07:45 -07002540 timeout--;
2541 }
2542
2543 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002544 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002545 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002546 }
2547
2548 gssr |= swmask;
2549 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2550
2551 ixgbe_release_eeprom_semaphore(hw);
2552 return 0;
2553}
2554
2555/**
2556 * ixgbe_release_swfw_sync - Release SWFW semaphore
2557 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002558 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002559 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002560 * Releases the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002561 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2562 **/
2563void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2564{
2565 u32 gssr;
2566 u32 swmask = mask;
2567
2568 ixgbe_get_eeprom_semaphore(hw);
2569
2570 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2571 gssr &= ~swmask;
2572 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2573
2574 ixgbe_release_eeprom_semaphore(hw);
2575}
2576
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002577/**
2578 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2579 * @hw: pointer to hardware structure
2580 * @regval: register value to write to RXCTRL
2581 *
2582 * Enables the Rx DMA unit
2583 **/
2584s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2585{
2586 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2587
2588 return 0;
2589}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002590
2591/**
2592 * ixgbe_blink_led_start_generic - Blink LED based on index.
2593 * @hw: pointer to hardware structure
2594 * @index: led number to blink
2595 **/
2596s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2597{
2598 ixgbe_link_speed speed = 0;
2599 bool link_up = 0;
2600 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2601 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2602
2603 /*
2604 * Link must be up to auto-blink the LEDs;
2605 * Force it if link is down.
2606 */
2607 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2608
2609 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002610 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002611 autoc_reg |= IXGBE_AUTOC_FLU;
2612 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
Don Skidmore032b4322011-03-18 09:32:53 +00002613 usleep_range(10000, 20000);
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002614 }
2615
2616 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2617 led_reg |= IXGBE_LED_BLINK(index);
2618 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2619 IXGBE_WRITE_FLUSH(hw);
2620
2621 return 0;
2622}
2623
2624/**
2625 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2626 * @hw: pointer to hardware structure
2627 * @index: led number to stop blinking
2628 **/
2629s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2630{
2631 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2632 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2633
2634 autoc_reg &= ~IXGBE_AUTOC_FLU;
2635 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2636 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2637
2638 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2639 led_reg &= ~IXGBE_LED_BLINK(index);
2640 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2641 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2642 IXGBE_WRITE_FLUSH(hw);
2643
2644 return 0;
2645}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002646
2647/**
2648 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2649 * @hw: pointer to hardware structure
2650 * @san_mac_offset: SAN MAC address offset
2651 *
2652 * This function will read the EEPROM location for the SAN MAC address
2653 * pointer, and returns the value at that location. This is used in both
2654 * get and set mac_addr routines.
2655 **/
2656static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2657 u16 *san_mac_offset)
2658{
2659 /*
2660 * First read the EEPROM pointer to see if the MAC addresses are
2661 * available.
2662 */
2663 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2664
2665 return 0;
2666}
2667
2668/**
2669 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2670 * @hw: pointer to hardware structure
2671 * @san_mac_addr: SAN MAC address
2672 *
2673 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2674 * per-port, so set_lan_id() must be called before reading the addresses.
2675 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2676 * upon for non-SFP connections, so we must call it here.
2677 **/
2678s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2679{
2680 u16 san_mac_data, san_mac_offset;
2681 u8 i;
2682
2683 /*
2684 * First read the EEPROM pointer to see if the MAC addresses are
2685 * available. If they're not, no point in calling set_lan_id() here.
2686 */
2687 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2688
2689 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2690 /*
2691 * No addresses available in this EEPROM. It's not an
2692 * error though, so just wipe the local address and return.
2693 */
2694 for (i = 0; i < 6; i++)
2695 san_mac_addr[i] = 0xFF;
2696
2697 goto san_mac_addr_out;
2698 }
2699
2700 /* make sure we know which port we need to program */
2701 hw->mac.ops.set_lan_id(hw);
2702 /* apply the port offset to the address offset */
2703 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2704 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2705 for (i = 0; i < 3; i++) {
2706 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2707 san_mac_addr[i * 2] = (u8)(san_mac_data);
2708 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2709 san_mac_offset++;
2710 }
2711
2712san_mac_addr_out:
2713 return 0;
2714}
2715
2716/**
2717 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2718 * @hw: pointer to hardware structure
2719 *
2720 * Read PCIe configuration space, and get the MSI-X vector count from
2721 * the capabilities table.
2722 **/
2723u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2724{
2725 struct ixgbe_adapter *adapter = hw->back;
2726 u16 msix_count;
2727 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2728 &msix_count);
2729 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2730
2731 /* MSI-X count is zero-based in HW, so increment to give proper value */
2732 msix_count++;
2733
2734 return msix_count;
2735}
2736
2737/**
2738 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2739 * @hw: pointer to hardware struct
2740 * @rar: receive address register index to disassociate
2741 * @vmdq: VMDq pool index to remove from the rar
2742 **/
2743s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2744{
2745 u32 mpsar_lo, mpsar_hi;
2746 u32 rar_entries = hw->mac.num_rar_entries;
2747
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002748 /* Make sure we are using a valid rar index range */
2749 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002750 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002751 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002752 }
2753
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002754 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2755 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2756
2757 if (!mpsar_lo && !mpsar_hi)
2758 goto done;
2759
2760 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2761 if (mpsar_lo) {
2762 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2763 mpsar_lo = 0;
2764 }
2765 if (mpsar_hi) {
2766 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2767 mpsar_hi = 0;
2768 }
2769 } else if (vmdq < 32) {
2770 mpsar_lo &= ~(1 << vmdq);
2771 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2772 } else {
2773 mpsar_hi &= ~(1 << (vmdq - 32));
2774 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2775 }
2776
2777 /* was that the last pool using this rar? */
2778 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2779 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002780done:
2781 return 0;
2782}
2783
2784/**
2785 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2786 * @hw: pointer to hardware struct
2787 * @rar: receive address register index to associate with a VMDq index
2788 * @vmdq: VMDq pool index
2789 **/
2790s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2791{
2792 u32 mpsar;
2793 u32 rar_entries = hw->mac.num_rar_entries;
2794
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002795 /* Make sure we are using a valid rar index range */
2796 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002797 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002798 return IXGBE_ERR_INVALID_ARGUMENT;
2799 }
2800
2801 if (vmdq < 32) {
2802 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2803 mpsar |= 1 << vmdq;
2804 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2805 } else {
2806 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2807 mpsar |= 1 << (vmdq - 32);
2808 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002809 }
2810 return 0;
2811}
2812
2813/**
2814 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2815 * @hw: pointer to hardware structure
2816 **/
2817s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2818{
2819 int i;
2820
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002821 for (i = 0; i < 128; i++)
2822 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2823
2824 return 0;
2825}
2826
2827/**
2828 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2829 * @hw: pointer to hardware structure
2830 * @vlan: VLAN id to write to VLAN filter
2831 *
2832 * return the VLVF index where this VLAN id should be placed
2833 *
2834 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002835static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002836{
2837 u32 bits = 0;
2838 u32 first_empty_slot = 0;
2839 s32 regindex;
2840
2841 /* short cut the special case */
2842 if (vlan == 0)
2843 return 0;
2844
2845 /*
2846 * Search for the vlan id in the VLVF entries. Save off the first empty
2847 * slot found along the way
2848 */
2849 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2850 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2851 if (!bits && !(first_empty_slot))
2852 first_empty_slot = regindex;
2853 else if ((bits & 0x0FFF) == vlan)
2854 break;
2855 }
2856
2857 /*
2858 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2859 * in the VLVF. Else use the first empty VLVF register for this
2860 * vlan id.
2861 */
2862 if (regindex >= IXGBE_VLVF_ENTRIES) {
2863 if (first_empty_slot)
2864 regindex = first_empty_slot;
2865 else {
2866 hw_dbg(hw, "No space in VLVF.\n");
2867 regindex = IXGBE_ERR_NO_SPACE;
2868 }
2869 }
2870
2871 return regindex;
2872}
2873
2874/**
2875 * ixgbe_set_vfta_generic - Set VLAN filter table
2876 * @hw: pointer to hardware structure
2877 * @vlan: VLAN id to write to VLAN filter
2878 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2879 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2880 *
2881 * Turn on/off specified VLAN in the VLAN filter table.
2882 **/
2883s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2884 bool vlan_on)
2885{
2886 s32 regindex;
2887 u32 bitindex;
2888 u32 vfta;
2889 u32 bits;
2890 u32 vt;
2891 u32 targetbit;
2892 bool vfta_changed = false;
2893
2894 if (vlan > 4095)
2895 return IXGBE_ERR_PARAM;
2896
2897 /*
2898 * this is a 2 part operation - first the VFTA, then the
2899 * VLVF and VLVFB if VT Mode is set
2900 * We don't write the VFTA until we know the VLVF part succeeded.
2901 */
2902
2903 /* Part 1
2904 * The VFTA is a bitstring made up of 128 32-bit registers
2905 * that enable the particular VLAN id, much like the MTA:
2906 * bits[11-5]: which register
2907 * bits[4-0]: which bit in the register
2908 */
2909 regindex = (vlan >> 5) & 0x7F;
2910 bitindex = vlan & 0x1F;
2911 targetbit = (1 << bitindex);
2912 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2913
2914 if (vlan_on) {
2915 if (!(vfta & targetbit)) {
2916 vfta |= targetbit;
2917 vfta_changed = true;
2918 }
2919 } else {
2920 if ((vfta & targetbit)) {
2921 vfta &= ~targetbit;
2922 vfta_changed = true;
2923 }
2924 }
2925
2926 /* Part 2
2927 * If VT Mode is set
2928 * Either vlan_on
2929 * make sure the vlan is in VLVF
2930 * set the vind bit in the matching VLVFB
2931 * Or !vlan_on
2932 * clear the pool bit and possibly the vind
2933 */
2934 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2935 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2936 s32 vlvf_index;
2937
2938 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2939 if (vlvf_index < 0)
2940 return vlvf_index;
2941
2942 if (vlan_on) {
2943 /* set the pool bit */
2944 if (vind < 32) {
2945 bits = IXGBE_READ_REG(hw,
2946 IXGBE_VLVFB(vlvf_index*2));
2947 bits |= (1 << vind);
2948 IXGBE_WRITE_REG(hw,
2949 IXGBE_VLVFB(vlvf_index*2),
2950 bits);
2951 } else {
2952 bits = IXGBE_READ_REG(hw,
2953 IXGBE_VLVFB((vlvf_index*2)+1));
2954 bits |= (1 << (vind-32));
2955 IXGBE_WRITE_REG(hw,
2956 IXGBE_VLVFB((vlvf_index*2)+1),
2957 bits);
2958 }
2959 } else {
2960 /* clear the pool bit */
2961 if (vind < 32) {
2962 bits = IXGBE_READ_REG(hw,
2963 IXGBE_VLVFB(vlvf_index*2));
2964 bits &= ~(1 << vind);
2965 IXGBE_WRITE_REG(hw,
2966 IXGBE_VLVFB(vlvf_index*2),
2967 bits);
2968 bits |= IXGBE_READ_REG(hw,
2969 IXGBE_VLVFB((vlvf_index*2)+1));
2970 } else {
2971 bits = IXGBE_READ_REG(hw,
2972 IXGBE_VLVFB((vlvf_index*2)+1));
2973 bits &= ~(1 << (vind-32));
2974 IXGBE_WRITE_REG(hw,
2975 IXGBE_VLVFB((vlvf_index*2)+1),
2976 bits);
2977 bits |= IXGBE_READ_REG(hw,
2978 IXGBE_VLVFB(vlvf_index*2));
2979 }
2980 }
2981
2982 /*
2983 * If there are still bits set in the VLVFB registers
2984 * for the VLAN ID indicated we need to see if the
2985 * caller is requesting that we clear the VFTA entry bit.
2986 * If the caller has requested that we clear the VFTA
2987 * entry bit but there are still pools/VFs using this VLAN
2988 * ID entry then ignore the request. We're not worried
2989 * about the case where we're turning the VFTA VLAN ID
2990 * entry bit on, only when requested to turn it off as
2991 * there may be multiple pools and/or VFs using the
2992 * VLAN ID entry. In that case we cannot clear the
2993 * VFTA bit until all pools/VFs using that VLAN ID have also
2994 * been cleared. This will be indicated by "bits" being
2995 * zero.
2996 */
2997 if (bits) {
2998 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2999 (IXGBE_VLVF_VIEN | vlan));
3000 if (!vlan_on) {
3001 /* someone wants to clear the vfta entry
3002 * but some pools/VFs are still using it.
3003 * Ignore it. */
3004 vfta_changed = false;
3005 }
3006 }
3007 else
3008 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
3009 }
3010
3011 if (vfta_changed)
3012 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
3013
3014 return 0;
3015}
3016
3017/**
3018 * ixgbe_clear_vfta_generic - Clear VLAN filter table
3019 * @hw: pointer to hardware structure
3020 *
3021 * Clears the VLAN filer table, and the VMDq index associated with the filter
3022 **/
3023s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
3024{
3025 u32 offset;
3026
3027 for (offset = 0; offset < hw->mac.vft_size; offset++)
3028 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
3029
3030 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
3031 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
3032 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
3033 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
3034 }
3035
3036 return 0;
3037}
3038
3039/**
3040 * ixgbe_check_mac_link_generic - Determine link and speed status
3041 * @hw: pointer to hardware structure
3042 * @speed: pointer to link speed
3043 * @link_up: true when link is up
3044 * @link_up_wait_to_complete: bool used to wait for link up or not
3045 *
3046 * Reads the links register to determine if link is up and the current speed
3047 **/
3048s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00003049 bool *link_up, bool link_up_wait_to_complete)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003050{
Emil Tantilov48de36c2011-02-16 01:38:08 +00003051 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003052 u32 i;
3053
Emil Tantilov48de36c2011-02-16 01:38:08 +00003054 /* clear the old state */
3055 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
3056
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003057 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00003058
3059 if (links_orig != links_reg) {
3060 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
3061 links_orig, links_reg);
3062 }
3063
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003064 if (link_up_wait_to_complete) {
3065 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
3066 if (links_reg & IXGBE_LINKS_UP) {
3067 *link_up = true;
3068 break;
3069 } else {
3070 *link_up = false;
3071 }
3072 msleep(100);
3073 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3074 }
3075 } else {
3076 if (links_reg & IXGBE_LINKS_UP)
3077 *link_up = true;
3078 else
3079 *link_up = false;
3080 }
3081
3082 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3083 IXGBE_LINKS_SPEED_10G_82599)
3084 *speed = IXGBE_LINK_SPEED_10GB_FULL;
3085 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
Emil Tantilov63d778d2011-02-19 08:43:39 +00003086 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003087 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00003088 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3089 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003090 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00003091 else
3092 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003093
3094 /* if link is down, zero out the current_mode */
3095 if (*link_up == false) {
3096 hw->fc.current_mode = ixgbe_fc_none;
3097 hw->fc.fc_was_autonegged = false;
3098 }
3099
3100 return 0;
3101}
Don Skidmorea391f1d2010-11-16 19:27:15 -08003102
3103/**
3104 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
3105 * the EEPROM
3106 * @hw: pointer to hardware structure
3107 * @wwnn_prefix: the alternative WWNN prefix
3108 * @wwpn_prefix: the alternative WWPN prefix
3109 *
3110 * This function will read the EEPROM from the alternative SAN MAC address
3111 * block to check the support for the alternative WWNN/WWPN prefix support.
3112 **/
3113s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
3114 u16 *wwpn_prefix)
3115{
3116 u16 offset, caps;
3117 u16 alt_san_mac_blk_offset;
3118
3119 /* clear output first */
3120 *wwnn_prefix = 0xFFFF;
3121 *wwpn_prefix = 0xFFFF;
3122
3123 /* check if alternative SAN MAC is supported */
3124 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
3125 &alt_san_mac_blk_offset);
3126
3127 if ((alt_san_mac_blk_offset == 0) ||
3128 (alt_san_mac_blk_offset == 0xFFFF))
3129 goto wwn_prefix_out;
3130
3131 /* check capability in alternative san mac address block */
3132 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
3133 hw->eeprom.ops.read(hw, offset, &caps);
3134 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
3135 goto wwn_prefix_out;
3136
3137 /* get the corresponding prefix for WWNN/WWPN */
3138 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
3139 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
3140
3141 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
3142 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
3143
3144wwn_prefix_out:
3145 return 0;
3146}
Greg Rosea985b6c32010-11-18 03:02:52 +00003147
3148/**
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003149 * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
3150 * control
3151 * @hw: pointer to hardware structure
3152 *
3153 * There are several phys that do not support autoneg flow control. This
3154 * function check the device id to see if the associated phy supports
3155 * autoneg flow control.
3156 **/
3157static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
3158{
3159
3160 switch (hw->device_id) {
3161 case IXGBE_DEV_ID_X540T:
3162 return 0;
3163 case IXGBE_DEV_ID_82599_T3_LOM:
3164 return 0;
3165 default:
3166 return IXGBE_ERR_FC_NOT_SUPPORTED;
3167 }
3168}
3169
3170/**
Greg Rosea985b6c32010-11-18 03:02:52 +00003171 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
3172 * @hw: pointer to hardware structure
3173 * @enable: enable or disable switch for anti-spoofing
3174 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
3175 *
3176 **/
3177void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
3178{
3179 int j;
3180 int pf_target_reg = pf >> 3;
3181 int pf_target_shift = pf % 8;
3182 u32 pfvfspoof = 0;
3183
3184 if (hw->mac.type == ixgbe_mac_82598EB)
3185 return;
3186
3187 if (enable)
3188 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
3189
3190 /*
3191 * PFVFSPOOF register array is size 8 with 8 bits assigned to
3192 * MAC anti-spoof enables in each register array element.
3193 */
3194 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
3195 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
3196
3197 /* If not enabling anti-spoofing then done */
3198 if (!enable)
3199 return;
3200
3201 /*
3202 * The PF should be allowed to spoof so that it can support
3203 * emulation mode NICs. Reset the bit assigned to the PF
3204 */
3205 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
3206 pfvfspoof ^= (1 << pf_target_shift);
3207 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
3208}
3209
3210/**
3211 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
3212 * @hw: pointer to hardware structure
3213 * @enable: enable or disable switch for VLAN anti-spoofing
3214 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
3215 *
3216 **/
3217void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
3218{
3219 int vf_target_reg = vf >> 3;
3220 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
3221 u32 pfvfspoof;
3222
3223 if (hw->mac.type == ixgbe_mac_82598EB)
3224 return;
3225
3226 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3227 if (enable)
3228 pfvfspoof |= (1 << vf_target_shift);
3229 else
3230 pfvfspoof &= ~(1 << vf_target_shift);
3231 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3232}
Emil Tantilovb776d102011-03-31 09:36:18 +00003233
3234/**
3235 * ixgbe_get_device_caps_generic - Get additional device capabilities
3236 * @hw: pointer to hardware structure
3237 * @device_caps: the EEPROM word with the extra device capabilities
3238 *
3239 * This function will read the EEPROM location for the device capabilities,
3240 * and return the word through device_caps.
3241 **/
3242s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
3243{
3244 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
3245
3246 return 0;
3247}