blob: a67cba5149d112a461027c0c4259f5b7ff23e530 [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);
Auke Kok9a799d72007-09-15 14:07:45 -070057
58/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070059 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -070060 * @hw: pointer to hardware structure
61 *
62 * Starts the hardware by filling the bus info structure and media type, clears
63 * all on chip counters, initializes receive address registers, multicast
64 * table, VLAN filter table, calls routine to set up link and flow control
65 * settings, and leaves transmit and receive units disabled and uninitialized
66 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070067s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -070068{
69 u32 ctrl_ext;
70
71 /* Set the media type */
72 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
73
74 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070075 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070076
Auke Kok9a799d72007-09-15 14:07:45 -070077 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070078 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070079
Auke Kok9a799d72007-09-15 14:07:45 -070080 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070081 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070082
83 /* Set No Snoop Disable */
84 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
85 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
86 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -070087 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -070088
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +000089 /* Setup flow control */
90 ixgbe_setup_fc(hw, 0);
91
Auke Kok9a799d72007-09-15 14:07:45 -070092 /* Clear adapter stopped flag */
93 hw->adapter_stopped = false;
94
95 return 0;
96}
97
98/**
Emil Tantilov7184b7c2011-03-18 08:18:22 +000099 * ixgbe_start_hw_gen2 - Init sequence for common device family
100 * @hw: pointer to hw structure
101 *
102 * Performs the init sequence common to the second generation
103 * of 10 GbE devices.
104 * Devices in the second generation:
105 * 82599
106 * X540
107 **/
108s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
109{
110 u32 i;
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000111 u32 regval;
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000112
113 /* Clear the rate limiters */
114 for (i = 0; i < hw->mac.max_tx_queues; i++) {
115 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
116 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
117 }
118 IXGBE_WRITE_FLUSH(hw);
119
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000120 /* Disable relaxed ordering */
121 for (i = 0; i < hw->mac.max_tx_queues; i++) {
122 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
123 regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
124 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
125 }
126
127 for (i = 0; i < hw->mac.max_rx_queues; i++) {
128 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
129 regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
130 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
131 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
132 }
133
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000134 return 0;
135}
136
137/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700138 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -0700139 * @hw: pointer to hardware structure
140 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700141 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700142 * structure and media type, clears all on chip counters, initializes receive
143 * address registers, multicast table, VLAN filter table, calls routine to set
144 * up link and flow control settings, and leaves transmit and receive units
145 * disabled and uninitialized
146 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700147s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700148{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000149 s32 status;
150
Auke Kok9a799d72007-09-15 14:07:45 -0700151 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000152 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700153
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000154 if (status == 0) {
155 /* Start the HW */
156 status = hw->mac.ops.start_hw(hw);
157 }
Auke Kok9a799d72007-09-15 14:07:45 -0700158
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000159 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700160}
161
162/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700163 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700164 * @hw: pointer to hardware structure
165 *
166 * Clears all hardware statistics counters by reading them from the hardware
167 * Statistics counters are clear on read.
168 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700169s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700170{
171 u16 i = 0;
172
173 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
174 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
175 IXGBE_READ_REG(hw, IXGBE_ERRBC);
176 IXGBE_READ_REG(hw, IXGBE_MSPDC);
177 for (i = 0; i < 8; i++)
178 IXGBE_READ_REG(hw, IXGBE_MPC(i));
179
180 IXGBE_READ_REG(hw, IXGBE_MLFC);
181 IXGBE_READ_REG(hw, IXGBE_MRFC);
182 IXGBE_READ_REG(hw, IXGBE_RLEC);
183 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Auke Kok9a799d72007-09-15 14:07:45 -0700184 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Emil Tantilov667c7562011-02-26 06:40:05 +0000185 if (hw->mac.type >= ixgbe_mac_82599EB) {
186 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
187 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
188 } else {
189 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
190 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
191 }
Auke Kok9a799d72007-09-15 14:07:45 -0700192
193 for (i = 0; i < 8; i++) {
194 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700195 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000196 if (hw->mac.type >= ixgbe_mac_82599EB) {
197 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
198 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
199 } else {
200 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
201 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
202 }
Auke Kok9a799d72007-09-15 14:07:45 -0700203 }
Emil Tantilov667c7562011-02-26 06:40:05 +0000204 if (hw->mac.type >= ixgbe_mac_82599EB)
205 for (i = 0; i < 8; i++)
206 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700207 IXGBE_READ_REG(hw, IXGBE_PRC64);
208 IXGBE_READ_REG(hw, IXGBE_PRC127);
209 IXGBE_READ_REG(hw, IXGBE_PRC255);
210 IXGBE_READ_REG(hw, IXGBE_PRC511);
211 IXGBE_READ_REG(hw, IXGBE_PRC1023);
212 IXGBE_READ_REG(hw, IXGBE_PRC1522);
213 IXGBE_READ_REG(hw, IXGBE_GPRC);
214 IXGBE_READ_REG(hw, IXGBE_BPRC);
215 IXGBE_READ_REG(hw, IXGBE_MPRC);
216 IXGBE_READ_REG(hw, IXGBE_GPTC);
217 IXGBE_READ_REG(hw, IXGBE_GORCL);
218 IXGBE_READ_REG(hw, IXGBE_GORCH);
219 IXGBE_READ_REG(hw, IXGBE_GOTCL);
220 IXGBE_READ_REG(hw, IXGBE_GOTCH);
221 for (i = 0; i < 8; i++)
222 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
223 IXGBE_READ_REG(hw, IXGBE_RUC);
224 IXGBE_READ_REG(hw, IXGBE_RFC);
225 IXGBE_READ_REG(hw, IXGBE_ROC);
226 IXGBE_READ_REG(hw, IXGBE_RJC);
227 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
228 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
229 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
230 IXGBE_READ_REG(hw, IXGBE_TORL);
231 IXGBE_READ_REG(hw, IXGBE_TORH);
232 IXGBE_READ_REG(hw, IXGBE_TPR);
233 IXGBE_READ_REG(hw, IXGBE_TPT);
234 IXGBE_READ_REG(hw, IXGBE_PTC64);
235 IXGBE_READ_REG(hw, IXGBE_PTC127);
236 IXGBE_READ_REG(hw, IXGBE_PTC255);
237 IXGBE_READ_REG(hw, IXGBE_PTC511);
238 IXGBE_READ_REG(hw, IXGBE_PTC1023);
239 IXGBE_READ_REG(hw, IXGBE_PTC1522);
240 IXGBE_READ_REG(hw, IXGBE_MPTC);
241 IXGBE_READ_REG(hw, IXGBE_BPTC);
242 for (i = 0; i < 16; i++) {
243 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700244 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000245 if (hw->mac.type >= ixgbe_mac_82599EB) {
246 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
247 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
248 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
249 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
250 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
251 } else {
252 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
253 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
254 }
Auke Kok9a799d72007-09-15 14:07:45 -0700255 }
256
Emil Tantilova3aeea02011-02-26 06:40:11 +0000257 if (hw->mac.type == ixgbe_mac_X540) {
258 if (hw->phy.id == 0)
259 hw->phy.ops.identify(hw);
260 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i);
261 hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i);
262 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i);
263 hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i);
264 }
265
Auke Kok9a799d72007-09-15 14:07:45 -0700266 return 0;
267}
268
269/**
Don Skidmore289700d2010-12-03 03:32:58 +0000270 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700271 * @hw: pointer to hardware structure
Don Skidmore289700d2010-12-03 03:32:58 +0000272 * @pba_num: stores the part number string from the EEPROM
273 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700274 *
Don Skidmore289700d2010-12-03 03:32:58 +0000275 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700276 **/
Don Skidmore289700d2010-12-03 03:32:58 +0000277s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
278 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700279{
280 s32 ret_val;
281 u16 data;
Don Skidmore289700d2010-12-03 03:32:58 +0000282 u16 pba_ptr;
283 u16 offset;
284 u16 length;
285
286 if (pba_num == NULL) {
287 hw_dbg(hw, "PBA string buffer was null\n");
288 return IXGBE_ERR_INVALID_ARGUMENT;
289 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700290
291 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
292 if (ret_val) {
293 hw_dbg(hw, "NVM Read Error\n");
294 return ret_val;
295 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700296
Don Skidmore289700d2010-12-03 03:32:58 +0000297 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700298 if (ret_val) {
299 hw_dbg(hw, "NVM Read Error\n");
300 return ret_val;
301 }
Don Skidmore289700d2010-12-03 03:32:58 +0000302
303 /*
304 * if data is not ptr guard the PBA must be in legacy format which
305 * means pba_ptr is actually our second data word for the PBA number
306 * and we can decode it into an ascii string
307 */
308 if (data != IXGBE_PBANUM_PTR_GUARD) {
309 hw_dbg(hw, "NVM PBA number is not stored as string\n");
310
311 /* we will need 11 characters to store the PBA */
312 if (pba_num_size < 11) {
313 hw_dbg(hw, "PBA string buffer too small\n");
314 return IXGBE_ERR_NO_SPACE;
315 }
316
317 /* extract hex string from data and pba_ptr */
318 pba_num[0] = (data >> 12) & 0xF;
319 pba_num[1] = (data >> 8) & 0xF;
320 pba_num[2] = (data >> 4) & 0xF;
321 pba_num[3] = data & 0xF;
322 pba_num[4] = (pba_ptr >> 12) & 0xF;
323 pba_num[5] = (pba_ptr >> 8) & 0xF;
324 pba_num[6] = '-';
325 pba_num[7] = 0;
326 pba_num[8] = (pba_ptr >> 4) & 0xF;
327 pba_num[9] = pba_ptr & 0xF;
328
329 /* put a null character on the end of our string */
330 pba_num[10] = '\0';
331
332 /* switch all the data but the '-' to hex char */
333 for (offset = 0; offset < 10; offset++) {
334 if (pba_num[offset] < 0xA)
335 pba_num[offset] += '0';
336 else if (pba_num[offset] < 0x10)
337 pba_num[offset] += 'A' - 0xA;
338 }
339
340 return 0;
341 }
342
343 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
344 if (ret_val) {
345 hw_dbg(hw, "NVM Read Error\n");
346 return ret_val;
347 }
348
349 if (length == 0xFFFF || length == 0) {
350 hw_dbg(hw, "NVM PBA number section invalid length\n");
351 return IXGBE_ERR_PBA_SECTION;
352 }
353
354 /* check if pba_num buffer is big enough */
355 if (pba_num_size < (((u32)length * 2) - 1)) {
356 hw_dbg(hw, "PBA string buffer too small\n");
357 return IXGBE_ERR_NO_SPACE;
358 }
359
360 /* trim pba length from start of string */
361 pba_ptr++;
362 length--;
363
364 for (offset = 0; offset < length; offset++) {
365 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
366 if (ret_val) {
367 hw_dbg(hw, "NVM Read Error\n");
368 return ret_val;
369 }
370 pba_num[offset * 2] = (u8)(data >> 8);
371 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
372 }
373 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700374
375 return 0;
376}
377
378/**
379 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700380 * @hw: pointer to hardware structure
381 * @mac_addr: Adapter MAC address
382 *
383 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
384 * A reset of the adapter must be performed prior to calling this function
385 * in order for the MAC address to have been loaded from the EEPROM into RAR0
386 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700387s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700388{
389 u32 rar_high;
390 u32 rar_low;
391 u16 i;
392
393 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
394 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
395
396 for (i = 0; i < 4; i++)
397 mac_addr[i] = (u8)(rar_low >> (i*8));
398
399 for (i = 0; i < 2; i++)
400 mac_addr[i+4] = (u8)(rar_high >> (i*8));
401
402 return 0;
403}
404
Auke Kok9a799d72007-09-15 14:07:45 -0700405/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000406 * ixgbe_get_bus_info_generic - Generic set PCI bus info
407 * @hw: pointer to hardware structure
408 *
409 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
410 **/
411s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
412{
413 struct ixgbe_adapter *adapter = hw->back;
414 struct ixgbe_mac_info *mac = &hw->mac;
415 u16 link_status;
416
417 hw->bus.type = ixgbe_bus_type_pci_express;
418
419 /* Get the negotiated link width and speed from PCI config space */
420 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
421 &link_status);
422
423 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
424 case IXGBE_PCI_LINK_WIDTH_1:
425 hw->bus.width = ixgbe_bus_width_pcie_x1;
426 break;
427 case IXGBE_PCI_LINK_WIDTH_2:
428 hw->bus.width = ixgbe_bus_width_pcie_x2;
429 break;
430 case IXGBE_PCI_LINK_WIDTH_4:
431 hw->bus.width = ixgbe_bus_width_pcie_x4;
432 break;
433 case IXGBE_PCI_LINK_WIDTH_8:
434 hw->bus.width = ixgbe_bus_width_pcie_x8;
435 break;
436 default:
437 hw->bus.width = ixgbe_bus_width_unknown;
438 break;
439 }
440
441 switch (link_status & IXGBE_PCI_LINK_SPEED) {
442 case IXGBE_PCI_LINK_SPEED_2500:
443 hw->bus.speed = ixgbe_bus_speed_2500;
444 break;
445 case IXGBE_PCI_LINK_SPEED_5000:
446 hw->bus.speed = ixgbe_bus_speed_5000;
447 break;
448 default:
449 hw->bus.speed = ixgbe_bus_speed_unknown;
450 break;
451 }
452
453 mac->ops.set_lan_id(hw);
454
455 return 0;
456}
457
458/**
459 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
460 * @hw: pointer to the HW structure
461 *
462 * Determines the LAN function id by reading memory-mapped registers
463 * and swaps the port value if requested.
464 **/
465void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
466{
467 struct ixgbe_bus_info *bus = &hw->bus;
468 u32 reg;
469
470 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
471 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
472 bus->lan_id = bus->func;
473
474 /* check for a port swap */
475 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
476 if (reg & IXGBE_FACTPS_LFS)
477 bus->func ^= 0x1;
478}
479
480/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700481 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700482 * @hw: pointer to hardware structure
483 *
484 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
485 * disables transmit and receive units. The adapter_stopped flag is used by
486 * the shared code and drivers to determine if the adapter is in a stopped
487 * state and should not touch the hardware.
488 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700489s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700490{
491 u32 number_of_queues;
492 u32 reg_val;
493 u16 i;
494
495 /*
496 * Set the adapter_stopped flag so other driver functions stop touching
497 * the hardware
498 */
499 hw->adapter_stopped = true;
500
501 /* Disable the receive unit */
502 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
503 reg_val &= ~(IXGBE_RXCTRL_RXEN);
504 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700505 IXGBE_WRITE_FLUSH(hw);
Don Skidmore032b4322011-03-18 09:32:53 +0000506 usleep_range(2000, 4000);
Auke Kok9a799d72007-09-15 14:07:45 -0700507
508 /* Clear interrupt mask to stop from interrupts being generated */
509 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
510
511 /* Clear any pending interrupts */
512 IXGBE_READ_REG(hw, IXGBE_EICR);
513
514 /* Disable the transmit unit. Each queue must be disabled. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700515 number_of_queues = hw->mac.max_tx_queues;
Auke Kok9a799d72007-09-15 14:07:45 -0700516 for (i = 0; i < number_of_queues; i++) {
517 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
518 if (reg_val & IXGBE_TXDCTL_ENABLE) {
519 reg_val &= ~IXGBE_TXDCTL_ENABLE;
520 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
521 }
522 }
523
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700524 /*
525 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
526 * access and verify no pending requests
527 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000528 ixgbe_disable_pcie_master(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700529
Auke Kok9a799d72007-09-15 14:07:45 -0700530 return 0;
531}
532
533/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700534 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700535 * @hw: pointer to hardware structure
536 * @index: led number to turn on
537 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700538s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700539{
540 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
541
542 /* To turn on the LED, set mode to ON. */
543 led_reg &= ~IXGBE_LED_MODE_MASK(index);
544 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
545 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700546 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700547
548 return 0;
549}
550
551/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700552 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700553 * @hw: pointer to hardware structure
554 * @index: led number to turn off
555 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700556s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700557{
558 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
559
560 /* To turn off the LED, set mode to OFF. */
561 led_reg &= ~IXGBE_LED_MODE_MASK(index);
562 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
563 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700564 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700565
566 return 0;
567}
568
Auke Kok9a799d72007-09-15 14:07:45 -0700569/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700570 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700571 * @hw: pointer to hardware structure
572 *
573 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
574 * ixgbe_hw struct in order to set up EEPROM access.
575 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700576s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700577{
578 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
579 u32 eec;
580 u16 eeprom_size;
581
582 if (eeprom->type == ixgbe_eeprom_uninitialized) {
583 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700584 /* Set default semaphore delay to 10ms which is a well
585 * tested value */
586 eeprom->semaphore_delay = 10;
Auke Kok9a799d72007-09-15 14:07:45 -0700587
588 /*
589 * Check for EEPROM present first.
590 * If not present leave as none
591 */
592 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
593 if (eec & IXGBE_EEC_PRES) {
594 eeprom->type = ixgbe_eeprom_spi;
595
596 /*
597 * SPI EEPROM is assumed here. This code would need to
598 * change if a future EEPROM is not SPI.
599 */
600 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
601 IXGBE_EEC_SIZE_SHIFT);
602 eeprom->word_size = 1 << (eeprom_size +
603 IXGBE_EEPROM_WORD_SIZE_SHIFT);
604 }
605
606 if (eec & IXGBE_EEC_ADDR_SIZE)
607 eeprom->address_bits = 16;
608 else
609 eeprom->address_bits = 8;
610 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
611 "%d\n", eeprom->type, eeprom->word_size,
612 eeprom->address_bits);
613 }
614
615 return 0;
616}
617
618/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000619 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
620 * @hw: pointer to hardware structure
621 * @offset: offset within the EEPROM to be written to
622 * @data: 16 bit word to be written to the EEPROM
623 *
624 * If ixgbe_eeprom_update_checksum is not called after this function, the
625 * EEPROM will most likely contain an invalid checksum.
626 **/
627s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
628{
629 s32 status;
630 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
631
632 hw->eeprom.ops.init_params(hw);
633
634 if (offset >= hw->eeprom.word_size) {
635 status = IXGBE_ERR_EEPROM;
636 goto out;
637 }
638
639 /* Prepare the EEPROM for writing */
640 status = ixgbe_acquire_eeprom(hw);
641
642 if (status == 0) {
643 if (ixgbe_ready_eeprom(hw) != 0) {
644 ixgbe_release_eeprom(hw);
645 status = IXGBE_ERR_EEPROM;
646 }
647 }
648
649 if (status == 0) {
650 ixgbe_standby_eeprom(hw);
651
652 /* Send the WRITE ENABLE command (8 bit opcode ) */
653 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
654 IXGBE_EEPROM_OPCODE_BITS);
655
656 ixgbe_standby_eeprom(hw);
657
658 /*
659 * Some SPI eeproms use the 8th address bit embedded in the
660 * opcode
661 */
662 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
663 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
664
665 /* Send the Write command (8-bit opcode + addr) */
666 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
667 IXGBE_EEPROM_OPCODE_BITS);
668 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
669 hw->eeprom.address_bits);
670
671 /* Send the data */
672 data = (data >> 8) | (data << 8);
673 ixgbe_shift_out_eeprom_bits(hw, data, 16);
674 ixgbe_standby_eeprom(hw);
675
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000676 /* Done with writing - release the EEPROM */
677 ixgbe_release_eeprom(hw);
678 }
679
680out:
681 return status;
682}
683
684/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700685 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
686 * @hw: pointer to hardware structure
687 * @offset: offset within the EEPROM to be read
688 * @data: read 16 bit value from EEPROM
689 *
690 * Reads 16 bit value from EEPROM through bit-bang method
691 **/
692s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
693 u16 *data)
694{
695 s32 status;
696 u16 word_in;
697 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
698
699 hw->eeprom.ops.init_params(hw);
700
701 if (offset >= hw->eeprom.word_size) {
702 status = IXGBE_ERR_EEPROM;
703 goto out;
704 }
705
706 /* Prepare the EEPROM for reading */
707 status = ixgbe_acquire_eeprom(hw);
708
709 if (status == 0) {
710 if (ixgbe_ready_eeprom(hw) != 0) {
711 ixgbe_release_eeprom(hw);
712 status = IXGBE_ERR_EEPROM;
713 }
714 }
715
716 if (status == 0) {
717 ixgbe_standby_eeprom(hw);
718
719 /*
720 * Some SPI eeproms use the 8th address bit embedded in the
721 * opcode
722 */
723 if ((hw->eeprom.address_bits == 8) && (offset >= 128))
724 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
725
726 /* Send the READ command (opcode + addr) */
727 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
728 IXGBE_EEPROM_OPCODE_BITS);
729 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
730 hw->eeprom.address_bits);
731
732 /* Read the data. */
733 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
734 *data = (word_in >> 8) | (word_in << 8);
735
736 /* End this read operation */
737 ixgbe_release_eeprom(hw);
738 }
739
740out:
741 return status;
742}
743
744/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000745 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -0700746 * @hw: pointer to hardware structure
747 * @offset: offset of word in the EEPROM to read
748 * @data: word read from the EEPROM
749 *
750 * Reads a 16 bit word from the EEPROM using the EERD register.
751 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000752s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -0700753{
754 u32 eerd;
755 s32 status;
756
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700757 hw->eeprom.ops.init_params(hw);
758
759 if (offset >= hw->eeprom.word_size) {
760 status = IXGBE_ERR_EEPROM;
761 goto out;
762 }
763
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000764 eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
765 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -0700766
767 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000768 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
Auke Kok9a799d72007-09-15 14:07:45 -0700769
770 if (status == 0)
771 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000772 IXGBE_EEPROM_RW_REG_DATA);
Auke Kok9a799d72007-09-15 14:07:45 -0700773 else
774 hw_dbg(hw, "Eeprom read timed out\n");
775
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700776out:
Auke Kok9a799d72007-09-15 14:07:45 -0700777 return status;
778}
779
780/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000781 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -0700782 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000783 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -0700784 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000785 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
786 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -0700787 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -0800788s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -0700789{
790 u32 i;
791 u32 reg;
792 s32 status = IXGBE_ERR_EEPROM;
793
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000794 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
795 if (ee_reg == IXGBE_NVM_POLL_READ)
796 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
797 else
798 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
799
800 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -0700801 status = 0;
802 break;
803 }
804 udelay(5);
805 }
806 return status;
807}
808
809/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700810 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
811 * @hw: pointer to hardware structure
812 *
813 * Prepares EEPROM for access using bit-bang method. This function should
814 * be called before issuing a command to the EEPROM.
815 **/
816static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
817{
818 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000819 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700820 u32 i;
821
Don Skidmore5e655102011-02-25 01:58:04 +0000822 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700823 status = IXGBE_ERR_SWFW_SYNC;
824
825 if (status == 0) {
826 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
827
828 /* Request EEPROM Access */
829 eec |= IXGBE_EEC_REQ;
830 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
831
832 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
833 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
834 if (eec & IXGBE_EEC_GNT)
835 break;
836 udelay(5);
837 }
838
839 /* Release if grant not acquired */
840 if (!(eec & IXGBE_EEC_GNT)) {
841 eec &= ~IXGBE_EEC_REQ;
842 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
843 hw_dbg(hw, "Could not acquire EEPROM grant\n");
844
Don Skidmore5e655102011-02-25 01:58:04 +0000845 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700846 status = IXGBE_ERR_EEPROM;
847 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700848
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000849 /* Setup EEPROM for Read/Write */
850 if (status == 0) {
851 /* Clear CS and SK */
852 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
853 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
854 IXGBE_WRITE_FLUSH(hw);
855 udelay(1);
856 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700857 }
858 return status;
859}
860
861/**
Auke Kok9a799d72007-09-15 14:07:45 -0700862 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
863 * @hw: pointer to hardware structure
864 *
865 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
866 **/
867static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
868{
869 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000870 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -0700871 u32 i;
872 u32 swsm;
873
Auke Kok9a799d72007-09-15 14:07:45 -0700874 /* Get SMBI software semaphore between device drivers first */
875 for (i = 0; i < timeout; i++) {
876 /*
877 * If the SMBI bit is 0 when we read it, then the bit will be
878 * set and we have the semaphore
879 */
880 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
881 if (!(swsm & IXGBE_SWSM_SMBI)) {
882 status = 0;
883 break;
884 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000885 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -0700886 }
887
888 /* Now get the semaphore between SW/FW through the SWESMBI bit */
889 if (status == 0) {
890 for (i = 0; i < timeout; i++) {
891 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
892
893 /* Set the SW EEPROM semaphore bit to request access */
894 swsm |= IXGBE_SWSM_SWESMBI;
895 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
896
897 /*
898 * If we set the bit successfully then we got the
899 * semaphore.
900 */
901 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
902 if (swsm & IXGBE_SWSM_SWESMBI)
903 break;
904
905 udelay(50);
906 }
907
908 /*
909 * Release semaphores and return error if SW EEPROM semaphore
910 * was not granted because we don't have access to the EEPROM
911 */
912 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000913 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700914 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700915 ixgbe_release_eeprom_semaphore(hw);
916 status = IXGBE_ERR_EEPROM;
917 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +0000918 } else {
919 hw_dbg(hw, "Software semaphore SMBI between device drivers "
920 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700921 }
922
923 return status;
924}
925
926/**
927 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
928 * @hw: pointer to hardware structure
929 *
930 * This function clears hardware semaphore bits.
931 **/
932static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
933{
934 u32 swsm;
935
936 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
937
938 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
939 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
940 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -0700941 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700942}
943
944/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700945 * ixgbe_ready_eeprom - Polls for EEPROM ready
946 * @hw: pointer to hardware structure
947 **/
948static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
949{
950 s32 status = 0;
951 u16 i;
952 u8 spi_stat_reg;
953
954 /*
955 * Read "Status Register" repeatedly until the LSB is cleared. The
956 * EEPROM will signal that the command has been completed by clearing
957 * bit 0 of the internal status register. If it's not cleared within
958 * 5 milliseconds, then error out.
959 */
960 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
961 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
962 IXGBE_EEPROM_OPCODE_BITS);
963 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
964 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
965 break;
966
967 udelay(5);
968 ixgbe_standby_eeprom(hw);
969 };
970
971 /*
972 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
973 * devices (and only 0-5mSec on 5V devices)
974 */
975 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
976 hw_dbg(hw, "SPI EEPROM Status error\n");
977 status = IXGBE_ERR_EEPROM;
978 }
979
980 return status;
981}
982
983/**
984 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
985 * @hw: pointer to hardware structure
986 **/
987static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
988{
989 u32 eec;
990
991 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
992
993 /* Toggle CS to flush commands */
994 eec |= IXGBE_EEC_CS;
995 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
996 IXGBE_WRITE_FLUSH(hw);
997 udelay(1);
998 eec &= ~IXGBE_EEC_CS;
999 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1000 IXGBE_WRITE_FLUSH(hw);
1001 udelay(1);
1002}
1003
1004/**
1005 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1006 * @hw: pointer to hardware structure
1007 * @data: data to send to the EEPROM
1008 * @count: number of bits to shift out
1009 **/
1010static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1011 u16 count)
1012{
1013 u32 eec;
1014 u32 mask;
1015 u32 i;
1016
1017 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1018
1019 /*
1020 * Mask is used to shift "count" bits of "data" out to the EEPROM
1021 * one bit at a time. Determine the starting bit based on count
1022 */
1023 mask = 0x01 << (count - 1);
1024
1025 for (i = 0; i < count; i++) {
1026 /*
1027 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1028 * "1", and then raising and then lowering the clock (the SK
1029 * bit controls the clock input to the EEPROM). A "0" is
1030 * shifted out to the EEPROM by setting "DI" to "0" and then
1031 * raising and then lowering the clock.
1032 */
1033 if (data & mask)
1034 eec |= IXGBE_EEC_DI;
1035 else
1036 eec &= ~IXGBE_EEC_DI;
1037
1038 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1039 IXGBE_WRITE_FLUSH(hw);
1040
1041 udelay(1);
1042
1043 ixgbe_raise_eeprom_clk(hw, &eec);
1044 ixgbe_lower_eeprom_clk(hw, &eec);
1045
1046 /*
1047 * Shift mask to signify next bit of data to shift in to the
1048 * EEPROM
1049 */
1050 mask = mask >> 1;
1051 };
1052
1053 /* We leave the "DI" bit set to "0" when we leave this routine. */
1054 eec &= ~IXGBE_EEC_DI;
1055 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1056 IXGBE_WRITE_FLUSH(hw);
1057}
1058
1059/**
1060 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1061 * @hw: pointer to hardware structure
1062 **/
1063static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1064{
1065 u32 eec;
1066 u32 i;
1067 u16 data = 0;
1068
1069 /*
1070 * In order to read a register from the EEPROM, we need to shift
1071 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1072 * the clock input to the EEPROM (setting the SK bit), and then reading
1073 * the value of the "DO" bit. During this "shifting in" process the
1074 * "DI" bit should always be clear.
1075 */
1076 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1077
1078 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1079
1080 for (i = 0; i < count; i++) {
1081 data = data << 1;
1082 ixgbe_raise_eeprom_clk(hw, &eec);
1083
1084 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1085
1086 eec &= ~(IXGBE_EEC_DI);
1087 if (eec & IXGBE_EEC_DO)
1088 data |= 1;
1089
1090 ixgbe_lower_eeprom_clk(hw, &eec);
1091 }
1092
1093 return data;
1094}
1095
1096/**
1097 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1098 * @hw: pointer to hardware structure
1099 * @eec: EEC register's current value
1100 **/
1101static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1102{
1103 /*
1104 * Raise the clock input to the EEPROM
1105 * (setting the SK bit), then delay
1106 */
1107 *eec = *eec | IXGBE_EEC_SK;
1108 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1109 IXGBE_WRITE_FLUSH(hw);
1110 udelay(1);
1111}
1112
1113/**
1114 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1115 * @hw: pointer to hardware structure
1116 * @eecd: EECD's current value
1117 **/
1118static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1119{
1120 /*
1121 * Lower the clock input to the EEPROM (clearing the SK bit), then
1122 * delay
1123 */
1124 *eec = *eec & ~IXGBE_EEC_SK;
1125 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1126 IXGBE_WRITE_FLUSH(hw);
1127 udelay(1);
1128}
1129
1130/**
1131 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1132 * @hw: pointer to hardware structure
1133 **/
1134static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1135{
1136 u32 eec;
1137
1138 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1139
1140 eec |= IXGBE_EEC_CS; /* Pull CS high */
1141 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1142
1143 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1144 IXGBE_WRITE_FLUSH(hw);
1145
1146 udelay(1);
1147
1148 /* Stop requesting EEPROM access */
1149 eec &= ~IXGBE_EEC_REQ;
1150 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1151
Don Skidmore90827992011-03-05 18:59:20 -08001152 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001153
Don Skidmore032b4322011-03-18 09:32:53 +00001154 /*
1155 * Delay before attempt to obtain semaphore again to allow FW
1156 * access. semaphore_delay is in ms we need us for usleep_range
1157 */
1158 usleep_range(hw->eeprom.semaphore_delay * 1000,
1159 hw->eeprom.semaphore_delay * 2000);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001160}
1161
1162/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001163 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001164 * @hw: pointer to hardware structure
1165 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001166u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001167{
1168 u16 i;
1169 u16 j;
1170 u16 checksum = 0;
1171 u16 length = 0;
1172 u16 pointer = 0;
1173 u16 word = 0;
1174
1175 /* Include 0x0-0x3F in the checksum */
1176 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001177 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001178 hw_dbg(hw, "EEPROM read failed\n");
1179 break;
1180 }
1181 checksum += word;
1182 }
1183
1184 /* Include all data from pointers except for the fw pointer */
1185 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001186 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001187
1188 /* Make sure the pointer seems valid */
1189 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001190 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001191
1192 if (length != 0xFFFF && length != 0) {
1193 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001194 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001195 checksum += word;
1196 }
1197 }
1198 }
1199 }
1200
1201 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1202
1203 return checksum;
1204}
1205
1206/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001207 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001208 * @hw: pointer to hardware structure
1209 * @checksum_val: calculated checksum
1210 *
1211 * Performs checksum calculation and validates the EEPROM checksum. If the
1212 * caller does not need checksum_val, the value can be NULL.
1213 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001214s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1215 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001216{
1217 s32 status;
1218 u16 checksum;
1219 u16 read_checksum = 0;
1220
1221 /*
1222 * Read the first word from the EEPROM. If this times out or fails, do
1223 * not continue or we could be in for a very long wait while every
1224 * EEPROM read fails
1225 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001226 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001227
1228 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001229 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001230
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001231 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001232
1233 /*
1234 * Verify read checksum from EEPROM is the same as
1235 * calculated checksum
1236 */
1237 if (read_checksum != checksum)
1238 status = IXGBE_ERR_EEPROM_CHECKSUM;
1239
1240 /* If the user cares, return the calculated checksum */
1241 if (checksum_val)
1242 *checksum_val = checksum;
1243 } else {
1244 hw_dbg(hw, "EEPROM read failed\n");
1245 }
1246
1247 return status;
1248}
1249
1250/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001251 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1252 * @hw: pointer to hardware structure
1253 **/
1254s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1255{
1256 s32 status;
1257 u16 checksum;
1258
1259 /*
1260 * Read the first word from the EEPROM. If this times out or fails, do
1261 * not continue or we could be in for a very long wait while every
1262 * EEPROM read fails
1263 */
1264 status = hw->eeprom.ops.read(hw, 0, &checksum);
1265
1266 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001267 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001268 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001269 checksum);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001270 } else {
1271 hw_dbg(hw, "EEPROM read failed\n");
1272 }
1273
1274 return status;
1275}
1276
1277/**
Auke Kok9a799d72007-09-15 14:07:45 -07001278 * ixgbe_validate_mac_addr - Validate MAC address
1279 * @mac_addr: pointer to MAC address.
1280 *
1281 * Tests a MAC address to ensure it is a valid Individual Address
1282 **/
1283s32 ixgbe_validate_mac_addr(u8 *mac_addr)
1284{
1285 s32 status = 0;
1286
1287 /* Make sure it is not a multicast address */
1288 if (IXGBE_IS_MULTICAST(mac_addr))
1289 status = IXGBE_ERR_INVALID_MAC_ADDR;
1290 /* Not a broadcast address */
1291 else if (IXGBE_IS_BROADCAST(mac_addr))
1292 status = IXGBE_ERR_INVALID_MAC_ADDR;
1293 /* Reject the zero address */
1294 else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001295 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
Auke Kok9a799d72007-09-15 14:07:45 -07001296 status = IXGBE_ERR_INVALID_MAC_ADDR;
1297
1298 return status;
1299}
1300
1301/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001302 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001303 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001304 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001305 * @addr: Address to put into receive address register
1306 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001307 * @enable_addr: set flag that address is active
1308 *
1309 * Puts an ethernet address into a receive address register.
1310 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001311s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1312 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001313{
1314 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001315 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001316
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001317 /* Make sure we are using a valid rar index range */
1318 if (index >= rar_entries) {
1319 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1320 return IXGBE_ERR_INVALID_ARGUMENT;
1321 }
1322
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001323 /* setup VMDq pool selection before this RAR gets enabled */
1324 hw->mac.ops.set_vmdq(hw, index, vmdq);
1325
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001326 /*
1327 * HW expects these in little endian so we reverse the byte
1328 * order from network order (big endian) to little endian
1329 */
1330 rar_low = ((u32)addr[0] |
1331 ((u32)addr[1] << 8) |
1332 ((u32)addr[2] << 16) |
1333 ((u32)addr[3] << 24));
1334 /*
1335 * Some parts put the VMDq setting in the extra RAH bits,
1336 * so save everything except the lower 16 bits that hold part
1337 * of the address and the address valid bit.
1338 */
1339 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1340 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1341 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001342
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001343 if (enable_addr != 0)
1344 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001345
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001346 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1347 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001348
1349 return 0;
1350}
1351
1352/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001353 * ixgbe_clear_rar_generic - Remove Rx address register
1354 * @hw: pointer to hardware structure
1355 * @index: Receive address register to write
1356 *
1357 * Clears an ethernet address from a receive address register.
1358 **/
1359s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1360{
1361 u32 rar_high;
1362 u32 rar_entries = hw->mac.num_rar_entries;
1363
1364 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001365 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001366 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001367 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001368 }
1369
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001370 /*
1371 * Some parts put the VMDq setting in the extra RAH bits,
1372 * so save everything except the lower 16 bits that hold part
1373 * of the address and the address valid bit.
1374 */
1375 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1376 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1377
1378 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1379 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1380
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001381 /* clear VMDq pool/queue selection for this RAR */
1382 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1383
1384 return 0;
1385}
1386
1387/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001388 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001389 * @hw: pointer to hardware structure
1390 *
1391 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001392 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001393 * the receiver is in reset when the routine is called.
1394 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001395s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001396{
1397 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001398 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001399
1400 /*
1401 * If the current mac address is valid, assume it is a software override
1402 * to the permanent address.
1403 * Otherwise, use the permanent address from the eeprom.
1404 */
1405 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
1406 IXGBE_ERR_INVALID_MAC_ADDR) {
1407 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001408 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001409
hartleysce7194d2010-01-05 06:56:52 +00001410 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001411 } else {
1412 /* Setup the receive address. */
1413 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001414 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001415
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001416 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001417
1418 /* clear VMDq pool/queue selection for RAR 0 */
1419 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001420 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001421 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001422
1423 hw->addr_ctrl.rar_used_count = 1;
1424
1425 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001426 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001427 for (i = 1; i < rar_entries; i++) {
1428 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1429 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1430 }
1431
1432 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001433 hw->addr_ctrl.mta_in_use = 0;
1434 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1435
1436 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001437 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001438 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1439
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001440 if (hw->mac.ops.init_uta_tables)
1441 hw->mac.ops.init_uta_tables(hw);
1442
Auke Kok9a799d72007-09-15 14:07:45 -07001443 return 0;
1444}
1445
1446/**
1447 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1448 * @hw: pointer to hardware structure
1449 * @mc_addr: the multicast address
1450 *
1451 * Extracts the 12 bits, from a multicast address, to determine which
1452 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1453 * incoming rx multicast addresses, to determine the bit-vector to check in
1454 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001455 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001456 * to mc_filter_type.
1457 **/
1458static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1459{
1460 u32 vector = 0;
1461
1462 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001463 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001464 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1465 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001466 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001467 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1468 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001469 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001470 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1471 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001472 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001473 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1474 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001475 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001476 hw_dbg(hw, "MC filter type param set incorrectly\n");
1477 break;
1478 }
1479
1480 /* vector can only be 12-bits or boundary will be exceeded */
1481 vector &= 0xFFF;
1482 return vector;
1483}
1484
1485/**
1486 * ixgbe_set_mta - Set bit-vector in multicast table
1487 * @hw: pointer to hardware structure
1488 * @hash_value: Multicast address hash value
1489 *
1490 * Sets the bit-vector in the multicast table.
1491 **/
1492static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
1493{
1494 u32 vector;
1495 u32 vector_bit;
1496 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07001497
1498 hw->addr_ctrl.mta_in_use++;
1499
1500 vector = ixgbe_mta_vector(hw, mc_addr);
1501 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
1502
1503 /*
1504 * The MTA is a register array of 128 32-bit registers. It is treated
1505 * like an array of 4096 bits. We want to set bit
1506 * BitArray[vector_value]. So we figure out what register the bit is
1507 * in, read it, OR in the new bit, then write back the new value. The
1508 * register is determined by the upper 7 bits of the vector value and
1509 * the bit within that register are determined by the lower 5 bits of
1510 * the value.
1511 */
1512 vector_reg = (vector >> 5) & 0x7F;
1513 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00001514 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07001515}
1516
1517/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001518 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07001519 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00001520 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001521 *
1522 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001523 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07001524 * registers for the first multicast addresses, and hashes the rest into the
1525 * multicast table.
1526 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00001527s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
1528 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001529{
Jiri Pirko22bedad2010-04-01 21:22:57 +00001530 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07001531 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001532
1533 /*
1534 * Set the new number of MC addresses that we are being requested to
1535 * use.
1536 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00001537 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001538 hw->addr_ctrl.mta_in_use = 0;
1539
Emil Tantilov80960ab2011-02-18 08:58:27 +00001540 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07001541 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00001542 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07001543
Emil Tantilov80960ab2011-02-18 08:58:27 +00001544 /* Update mta shadow */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001545 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07001546 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad2010-04-01 21:22:57 +00001547 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001548 }
1549
1550 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00001551 for (i = 0; i < hw->mac.mcft_size; i++)
1552 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1553 hw->mac.mta_shadow[i]);
1554
Auke Kok9a799d72007-09-15 14:07:45 -07001555 if (hw->addr_ctrl.mta_in_use > 0)
1556 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001557 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001558
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001559 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001560 return 0;
1561}
1562
1563/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001564 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001565 * @hw: pointer to hardware structure
1566 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001567 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001568 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001569s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001570{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001571 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001572
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001573 if (a->mta_in_use > 0)
1574 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1575 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001576
1577 return 0;
1578}
1579
1580/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001581 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07001582 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001583 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001584 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07001585 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001586s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001587{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001588 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001589
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001590 if (a->mta_in_use > 0)
1591 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07001592
1593 return 0;
1594}
1595
1596/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001597 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001598 * @hw: pointer to hardware structure
1599 * @packetbuf_num: packet buffer number (0-7)
1600 *
1601 * Enable flow control according to the current settings.
1602 **/
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001603s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001604{
1605 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001606 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001607 u32 reg;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001608 u32 rx_pba_size;
John Fastabend16b61be2010-11-16 19:26:44 -08001609 u32 fcrtl, fcrth;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001610
1611#ifdef CONFIG_DCB
1612 if (hw->fc.requested_mode == ixgbe_fc_pfc)
1613 goto out;
1614
1615#endif /* CONFIG_DCB */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001616 /* Negotiate the fc mode to use */
1617 ret_val = ixgbe_fc_autoneg(hw);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001618 if (ret_val == IXGBE_ERR_FLOW_CONTROL)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001619 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001620
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001621 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001622 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
1623 mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
1624
1625 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
1626 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
1627
1628 /*
1629 * The possible values of fc.current_mode are:
1630 * 0: Flow control is completely disabled
1631 * 1: Rx flow control is enabled (we can receive pause frames,
1632 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001633 * 2: Tx flow control is enabled (we can send pause frames but
1634 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001635 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001636#ifdef CONFIG_DCB
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001637 * 4: Priority Flow Control is enabled.
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001638#endif
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001639 * other: Invalid.
1640 */
1641 switch (hw->fc.current_mode) {
1642 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001643 /*
1644 * Flow control is disabled by software override or autoneg.
1645 * The code below will actually disable it in the HW.
1646 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001647 break;
1648 case ixgbe_fc_rx_pause:
1649 /*
1650 * Rx Flow control is enabled and Tx Flow control is
1651 * disabled by software override. Since there really
1652 * isn't a way to advertise that we are capable of RX
1653 * Pause ONLY, we will advertise that we support both
1654 * symmetric and asymmetric Rx PAUSE. Later, we will
1655 * disable the adapter's ability to send PAUSE frames.
1656 */
1657 mflcn_reg |= IXGBE_MFLCN_RFCE;
1658 break;
1659 case ixgbe_fc_tx_pause:
1660 /*
1661 * Tx Flow control is enabled, and Rx Flow control is
1662 * disabled by software override.
1663 */
1664 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1665 break;
1666 case ixgbe_fc_full:
1667 /* Flow control (both Rx and Tx) is enabled by SW override. */
1668 mflcn_reg |= IXGBE_MFLCN_RFCE;
1669 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
1670 break;
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001671#ifdef CONFIG_DCB
1672 case ixgbe_fc_pfc:
1673 goto out;
1674 break;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001675#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001676 default:
1677 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001678 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001679 goto out;
1680 break;
1681 }
1682
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001683 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00001684 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001685 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
1686 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
1687
John Fastabend16b61be2010-11-16 19:26:44 -08001688 rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
1689 rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001690
John Fastabend16b61be2010-11-16 19:26:44 -08001691 fcrth = (rx_pba_size - hw->fc.high_water) << 10;
1692 fcrtl = (rx_pba_size - hw->fc.low_water) << 10;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001693
John Fastabend16b61be2010-11-16 19:26:44 -08001694 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
1695 fcrth |= IXGBE_FCRTH_FCEN;
1696 if (hw->fc.send_xon)
1697 fcrtl |= IXGBE_FCRTL_XONE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001698 }
1699
John Fastabend16b61be2010-11-16 19:26:44 -08001700 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), fcrth);
1701 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), fcrtl);
1702
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001703 /* Configure pause time (2 TCs per register) */
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00001704 reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001705 if ((packetbuf_num & 1) == 0)
1706 reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
1707 else
1708 reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
1709 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
1710
1711 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
1712
1713out:
1714 return ret_val;
1715}
1716
1717/**
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001718 * ixgbe_fc_autoneg - Configure flow control
1719 * @hw: pointer to hardware structure
1720 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001721 * Compares our advertised flow control capabilities to those advertised by
1722 * our link partner, and determines the proper flow control mode to use.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001723 **/
1724s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1725{
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001726 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001727 ixgbe_link_speed speed;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001728 bool link_up;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001729
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001730 if (hw->fc.disable_fc_autoneg)
1731 goto out;
1732
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001733 /*
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001734 * AN should have completed when the cable was plugged in.
1735 * Look for reasons to bail out. Bail out if:
1736 * - FC autoneg is disabled, or if
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001737 * - link is not up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001738 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001739 * Since we're being called from an LSC, link is already known to be up.
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001740 * So use link_up_wait_to_complete=false.
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001741 */
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001742 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001743 if (!link_up) {
1744 ret_val = IXGBE_ERR_FLOW_CONTROL;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001745 goto out;
1746 }
1747
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001748 switch (hw->phy.media_type) {
1749 /* Autoneg flow control on fiber adapters */
1750 case ixgbe_media_type_fiber:
1751 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
1752 ret_val = ixgbe_fc_autoneg_fiber(hw);
1753 break;
Don Skidmore000c4862009-11-24 18:51:48 +00001754
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001755 /* Autoneg flow control on backplane adapters */
1756 case ixgbe_media_type_backplane:
1757 ret_val = ixgbe_fc_autoneg_backplane(hw);
1758 break;
1759
1760 /* Autoneg flow control on copper adapters */
1761 case ixgbe_media_type_copper:
1762 if (ixgbe_device_supports_autoneg_fc(hw) == 0)
1763 ret_val = ixgbe_fc_autoneg_copper(hw);
1764 break;
1765
1766 default:
1767 break;
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001768 }
1769
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001770out:
1771 if (ret_val == 0) {
1772 hw->fc.fc_was_autonegged = true;
1773 } else {
1774 hw->fc.fc_was_autonegged = false;
1775 hw->fc.current_mode = hw->fc.requested_mode;
1776 }
1777 return ret_val;
1778}
1779
1780/**
1781 * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
1782 * @hw: pointer to hardware structure
1783 *
1784 * Enable flow control according on 1 gig fiber.
1785 **/
1786static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
1787{
1788 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
1789 s32 ret_val;
1790
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001791 /*
1792 * On multispeed fiber at 1g, bail out if
1793 * - link is up but AN did not complete, or if
1794 * - link is up and AN completed but timed out
1795 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00001796
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001797 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1798 if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1799 ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1800 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00001801 goto out;
1802 }
1803
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001804 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1805 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001806
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001807 ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
1808 pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
1809 IXGBE_PCS1GANA_ASM_PAUSE,
1810 IXGBE_PCS1GANA_SYM_PAUSE,
1811 IXGBE_PCS1GANA_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001812
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001813out:
1814 return ret_val;
1815}
1816
1817/**
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001818 * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
1819 * @hw: pointer to hardware structure
1820 *
1821 * Enable flow control according to IEEE clause 37.
1822 **/
1823static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
1824{
1825 u32 links2, anlp1_reg, autoc_reg, links;
1826 s32 ret_val;
1827
1828 /*
1829 * On backplane, bail out if
1830 * - backplane autoneg was not completed, or if
1831 * - we are 82599 and link partner is not AN enabled
1832 */
1833 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
1834 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
1835 hw->fc.fc_was_autonegged = false;
1836 hw->fc.current_mode = hw->fc.requested_mode;
1837 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1838 goto out;
1839 }
1840
1841 if (hw->mac.type == ixgbe_mac_82599EB) {
1842 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1843 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1844 hw->fc.fc_was_autonegged = false;
1845 hw->fc.current_mode = hw->fc.requested_mode;
1846 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1847 goto out;
1848 }
1849 }
1850 /*
1851 * Read the 10g AN autoc and LP ability registers and resolve
1852 * local flow control settings accordingly
1853 */
1854 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1855 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1856
1857 ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
1858 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
1859 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
1860
1861out:
1862 return ret_val;
1863}
1864
1865/**
1866 * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
1867 * @hw: pointer to hardware structure
1868 *
1869 * Enable flow control according to IEEE clause 37.
1870 **/
1871static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
1872{
1873 u16 technology_ability_reg = 0;
1874 u16 lp_technology_ability_reg = 0;
1875
1876 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
1877 MDIO_MMD_AN,
1878 &technology_ability_reg);
1879 hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
1880 MDIO_MMD_AN,
1881 &lp_technology_ability_reg);
1882
1883 return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
1884 (u32)lp_technology_ability_reg,
1885 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
1886 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
1887}
1888
1889/**
1890 * ixgbe_negotiate_fc - Negotiate flow control
1891 * @hw: pointer to hardware structure
1892 * @adv_reg: flow control advertised settings
1893 * @lp_reg: link partner's flow control settings
1894 * @adv_sym: symmetric pause bit in advertisement
1895 * @adv_asm: asymmetric pause bit in advertisement
1896 * @lp_sym: symmetric pause bit in link partner advertisement
1897 * @lp_asm: asymmetric pause bit in link partner advertisement
1898 *
1899 * Find the intersection between advertised settings and link partner's
1900 * advertised settings
1901 **/
1902static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
1903 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
1904{
1905 if ((!(adv_reg)) || (!(lp_reg)))
1906 return IXGBE_ERR_FC_NOT_NEGOTIATED;
1907
1908 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
1909 /*
1910 * Now we need to check if the user selected Rx ONLY
1911 * of pause frames. In this case, we had to advertise
1912 * FULL flow control because we could not advertise RX
1913 * ONLY. Hence, we must now check to see if we need to
1914 * turn OFF the TRANSMISSION of PAUSE frames.
1915 */
1916 if (hw->fc.requested_mode == ixgbe_fc_full) {
1917 hw->fc.current_mode = ixgbe_fc_full;
1918 hw_dbg(hw, "Flow Control = FULL.\n");
1919 } else {
1920 hw->fc.current_mode = ixgbe_fc_rx_pause;
1921 hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
1922 }
1923 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1924 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1925 hw->fc.current_mode = ixgbe_fc_tx_pause;
1926 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1927 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1928 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1929 hw->fc.current_mode = ixgbe_fc_rx_pause;
1930 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1931 } else {
1932 hw->fc.current_mode = ixgbe_fc_none;
1933 hw_dbg(hw, "Flow Control = NONE.\n");
1934 }
1935 return 0;
1936}
1937
1938/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001939 * ixgbe_setup_fc - Set up flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001940 * @hw: pointer to hardware structure
1941 *
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001942 * Called at init time to set up flow control.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001943 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001944static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001945{
1946 s32 ret_val = 0;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001947 u32 reg = 0, reg_bp = 0;
1948 u16 reg_cu = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001949
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00001950#ifdef CONFIG_DCB
1951 if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1952 hw->fc.current_mode = hw->fc.requested_mode;
1953 goto out;
1954 }
1955
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001956#endif /* CONFIG_DCB */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001957 /* Validate the packetbuf configuration */
1958 if (packetbuf_num < 0 || packetbuf_num > 7) {
1959 hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
1960 "is 0-7\n", packetbuf_num);
1961 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1962 goto out;
1963 }
1964
1965 /*
1966 * Validate the water mark configuration. Zero water marks are invalid
1967 * because it causes the controller to just blast out fc packets.
1968 */
1969 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001970 hw_dbg(hw, "Invalid water mark configuration\n");
1971 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1972 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001973 }
1974
1975 /*
1976 * Validate the requested mode. Strict IEEE mode does not allow
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00001977 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001978 */
1979 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1980 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
1981 "IEEE mode\n");
1982 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
1983 goto out;
1984 }
1985
1986 /*
1987 * 10gig parts do not have a word in the EEPROM to determine the
1988 * default flow control setting, so we explicitly set it to full.
1989 */
1990 if (hw->fc.requested_mode == ixgbe_fc_default)
1991 hw->fc.requested_mode = ixgbe_fc_full;
1992
1993 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001994 * Set up the 1G and 10G flow control advertisement registers so the
1995 * HW will be able to do fc autoneg once the cable is plugged in. If
1996 * we link at 10G, the 1G advertisement is harmless and vice versa.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001997 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00001998
1999 switch (hw->phy.media_type) {
2000 case ixgbe_media_type_fiber:
2001 case ixgbe_media_type_backplane:
2002 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2003 reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2004 break;
2005
2006 case ixgbe_media_type_copper:
2007 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
2008 MDIO_MMD_AN, &reg_cu);
2009 break;
2010
2011 default:
2012 ;
2013 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002014
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002015 /*
2016 * The possible values of fc.requested_mode are:
2017 * 0: Flow control is completely disabled
2018 * 1: Rx flow control is enabled (we can receive pause frames,
2019 * but not send pause frames).
2020 * 2: Tx flow control is enabled (we can send pause frames but
2021 * we do not support receiving pause frames).
2022 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2023#ifdef CONFIG_DCB
2024 * 4: Priority Flow Control is enabled.
2025#endif
2026 * other: Invalid.
2027 */
2028 switch (hw->fc.requested_mode) {
2029 case ixgbe_fc_none:
2030 /* Flow control completely disabled by software override. */
2031 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002032 if (hw->phy.media_type == ixgbe_media_type_backplane)
2033 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
2034 IXGBE_AUTOC_ASM_PAUSE);
2035 else if (hw->phy.media_type == ixgbe_media_type_copper)
2036 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002037 break;
2038 case ixgbe_fc_rx_pause:
2039 /*
2040 * Rx Flow control is enabled and Tx Flow control is
2041 * disabled by software override. Since there really
2042 * isn't a way to advertise that we are capable of RX
2043 * Pause ONLY, we will advertise that we support both
2044 * symmetric and asymmetric Rx PAUSE. Later, we will
2045 * disable the adapter's ability to send PAUSE frames.
2046 */
2047 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002048 if (hw->phy.media_type == ixgbe_media_type_backplane)
2049 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2050 IXGBE_AUTOC_ASM_PAUSE);
2051 else if (hw->phy.media_type == ixgbe_media_type_copper)
2052 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002053 break;
2054 case ixgbe_fc_tx_pause:
2055 /*
2056 * Tx Flow control is enabled, and Rx Flow control is
2057 * disabled by software override.
2058 */
2059 reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2060 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002061 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2062 reg_bp |= (IXGBE_AUTOC_ASM_PAUSE);
2063 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE);
2064 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
2065 reg_cu |= (IXGBE_TAF_ASM_PAUSE);
2066 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE);
2067 }
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002068 break;
2069 case ixgbe_fc_full:
2070 /* Flow control (both Rx and Tx) is enabled by SW override. */
2071 reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002072 if (hw->phy.media_type == ixgbe_media_type_backplane)
2073 reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2074 IXGBE_AUTOC_ASM_PAUSE);
2075 else if (hw->phy.media_type == ixgbe_media_type_copper)
2076 reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002077 break;
2078#ifdef CONFIG_DCB
2079 case ixgbe_fc_pfc:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002080 goto out;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002081 break;
2082#endif /* CONFIG_DCB */
2083 default:
2084 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002085 ret_val = IXGBE_ERR_CONFIG;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002086 goto out;
2087 break;
2088 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002089
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002090 if (hw->mac.type != ixgbe_mac_X540) {
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002091 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002092 * Enable auto-negotiation between the MAC & PHY;
2093 * the MAC will advertise clause 37 flow control.
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002094 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002095 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2096 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2097
2098 /* Disable AN timeout */
2099 if (hw->fc.strict_ieee)
2100 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2101
2102 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2103 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002104 }
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002105
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002106 /*
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002107 * AUTOC restart handles negotiation of 1G and 10G on backplane
2108 * and copper. There is no need to set the PCS1GCTL register.
2109 *
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002110 */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002111 if (hw->phy.media_type == ixgbe_media_type_backplane) {
2112 reg_bp |= IXGBE_AUTOC_AN_RESTART;
2113 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
2114 } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
2115 (ixgbe_device_supports_autoneg_fc(hw) == 0)) {
2116 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
2117 MDIO_MMD_AN, reg_cu);
2118 }
2119
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002120 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002121out:
2122 return ret_val;
2123}
2124
2125/**
Auke Kok9a799d72007-09-15 14:07:45 -07002126 * ixgbe_disable_pcie_master - Disable PCI-express master access
2127 * @hw: pointer to hardware structure
2128 *
2129 * Disables PCI-Express master access and verifies there are no pending
2130 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2131 * bit hasn't caused the master requests to be disabled, else 0
2132 * is returned signifying master requests disabled.
2133 **/
2134s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2135{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002136 struct ixgbe_adapter *adapter = hw->back;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002137 u32 i;
2138 u32 reg_val;
2139 u32 number_of_queues;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002140 s32 status = 0;
2141 u16 dev_status = 0;
2142
2143 /* Just jump out if bus mastering is already disabled */
2144 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2145 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002146
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002147 /* Disable the receive unit by stopping each queue */
2148 number_of_queues = hw->mac.max_rx_queues;
2149 for (i = 0; i < number_of_queues; i++) {
2150 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
2151 if (reg_val & IXGBE_RXDCTL_ENABLE) {
2152 reg_val &= ~IXGBE_RXDCTL_ENABLE;
2153 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
2154 }
2155 }
2156
2157 reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
2158 reg_val |= IXGBE_CTRL_GIO_DIS;
2159 IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -07002160
2161 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilova4297dc2011-02-14 08:45:13 +00002162 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2163 goto check_device_status;
Auke Kok9a799d72007-09-15 14:07:45 -07002164 udelay(100);
2165 }
2166
Emil Tantilova4297dc2011-02-14 08:45:13 +00002167 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2168 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
2169
2170 /*
2171 * Before proceeding, make sure that the PCIe block does not have
2172 * transactions pending.
2173 */
2174check_device_status:
2175 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2176 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2177 &dev_status);
2178 if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2179 break;
2180 udelay(100);
2181 }
2182
2183 if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
2184 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2185 else
2186 goto out;
2187
2188 /*
2189 * Two consecutive resets are required via CTRL.RST per datasheet
2190 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2191 * of this need. The first reset prevents new master requests from
2192 * being issued by our device. We then must wait 1usec for any
2193 * remaining completions from the PCIe bus to trickle in, and then reset
2194 * again to clear out any effects they may have had on our device.
2195 */
2196 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2197
2198out:
Auke Kok9a799d72007-09-15 14:07:45 -07002199 return status;
2200}
2201
2202
2203/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002204 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002205 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002206 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002207 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002208 * Acquires the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002209 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2210 **/
2211s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2212{
2213 u32 gssr;
2214 u32 swmask = mask;
2215 u32 fwmask = mask << 5;
2216 s32 timeout = 200;
2217
2218 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002219 /*
2220 * SW EEPROM semaphore bit is used for access to all
2221 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2222 */
Auke Kok9a799d72007-09-15 14:07:45 -07002223 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002224 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002225
2226 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2227 if (!(gssr & (fwmask | swmask)))
2228 break;
2229
2230 /*
2231 * Firmware currently using resource (fwmask) or other software
2232 * thread currently using resource (swmask)
2233 */
2234 ixgbe_release_eeprom_semaphore(hw);
Don Skidmore032b4322011-03-18 09:32:53 +00002235 usleep_range(5000, 10000);
Auke Kok9a799d72007-09-15 14:07:45 -07002236 timeout--;
2237 }
2238
2239 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002240 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002241 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002242 }
2243
2244 gssr |= swmask;
2245 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2246
2247 ixgbe_release_eeprom_semaphore(hw);
2248 return 0;
2249}
2250
2251/**
2252 * ixgbe_release_swfw_sync - Release SWFW semaphore
2253 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002254 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002255 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002256 * Releases the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002257 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2258 **/
2259void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2260{
2261 u32 gssr;
2262 u32 swmask = mask;
2263
2264 ixgbe_get_eeprom_semaphore(hw);
2265
2266 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2267 gssr &= ~swmask;
2268 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2269
2270 ixgbe_release_eeprom_semaphore(hw);
2271}
2272
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002273/**
2274 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2275 * @hw: pointer to hardware structure
2276 * @regval: register value to write to RXCTRL
2277 *
2278 * Enables the Rx DMA unit
2279 **/
2280s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2281{
2282 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2283
2284 return 0;
2285}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002286
2287/**
2288 * ixgbe_blink_led_start_generic - Blink LED based on index.
2289 * @hw: pointer to hardware structure
2290 * @index: led number to blink
2291 **/
2292s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2293{
2294 ixgbe_link_speed speed = 0;
2295 bool link_up = 0;
2296 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2297 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2298
2299 /*
2300 * Link must be up to auto-blink the LEDs;
2301 * Force it if link is down.
2302 */
2303 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2304
2305 if (!link_up) {
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002306 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002307 autoc_reg |= IXGBE_AUTOC_FLU;
2308 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
Don Skidmore032b4322011-03-18 09:32:53 +00002309 usleep_range(10000, 20000);
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002310 }
2311
2312 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2313 led_reg |= IXGBE_LED_BLINK(index);
2314 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2315 IXGBE_WRITE_FLUSH(hw);
2316
2317 return 0;
2318}
2319
2320/**
2321 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2322 * @hw: pointer to hardware structure
2323 * @index: led number to stop blinking
2324 **/
2325s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2326{
2327 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2328 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2329
2330 autoc_reg &= ~IXGBE_AUTOC_FLU;
2331 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2332 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2333
2334 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2335 led_reg &= ~IXGBE_LED_BLINK(index);
2336 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2337 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2338 IXGBE_WRITE_FLUSH(hw);
2339
2340 return 0;
2341}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002342
2343/**
2344 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2345 * @hw: pointer to hardware structure
2346 * @san_mac_offset: SAN MAC address offset
2347 *
2348 * This function will read the EEPROM location for the SAN MAC address
2349 * pointer, and returns the value at that location. This is used in both
2350 * get and set mac_addr routines.
2351 **/
2352static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2353 u16 *san_mac_offset)
2354{
2355 /*
2356 * First read the EEPROM pointer to see if the MAC addresses are
2357 * available.
2358 */
2359 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2360
2361 return 0;
2362}
2363
2364/**
2365 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2366 * @hw: pointer to hardware structure
2367 * @san_mac_addr: SAN MAC address
2368 *
2369 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2370 * per-port, so set_lan_id() must be called before reading the addresses.
2371 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2372 * upon for non-SFP connections, so we must call it here.
2373 **/
2374s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2375{
2376 u16 san_mac_data, san_mac_offset;
2377 u8 i;
2378
2379 /*
2380 * First read the EEPROM pointer to see if the MAC addresses are
2381 * available. If they're not, no point in calling set_lan_id() here.
2382 */
2383 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2384
2385 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2386 /*
2387 * No addresses available in this EEPROM. It's not an
2388 * error though, so just wipe the local address and return.
2389 */
2390 for (i = 0; i < 6; i++)
2391 san_mac_addr[i] = 0xFF;
2392
2393 goto san_mac_addr_out;
2394 }
2395
2396 /* make sure we know which port we need to program */
2397 hw->mac.ops.set_lan_id(hw);
2398 /* apply the port offset to the address offset */
2399 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2400 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2401 for (i = 0; i < 3; i++) {
2402 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2403 san_mac_addr[i * 2] = (u8)(san_mac_data);
2404 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2405 san_mac_offset++;
2406 }
2407
2408san_mac_addr_out:
2409 return 0;
2410}
2411
2412/**
2413 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2414 * @hw: pointer to hardware structure
2415 *
2416 * Read PCIe configuration space, and get the MSI-X vector count from
2417 * the capabilities table.
2418 **/
2419u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2420{
2421 struct ixgbe_adapter *adapter = hw->back;
2422 u16 msix_count;
2423 pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
2424 &msix_count);
2425 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2426
2427 /* MSI-X count is zero-based in HW, so increment to give proper value */
2428 msix_count++;
2429
2430 return msix_count;
2431}
2432
2433/**
2434 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2435 * @hw: pointer to hardware struct
2436 * @rar: receive address register index to disassociate
2437 * @vmdq: VMDq pool index to remove from the rar
2438 **/
2439s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2440{
2441 u32 mpsar_lo, mpsar_hi;
2442 u32 rar_entries = hw->mac.num_rar_entries;
2443
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002444 /* Make sure we are using a valid rar index range */
2445 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002446 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002447 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002448 }
2449
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002450 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2451 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2452
2453 if (!mpsar_lo && !mpsar_hi)
2454 goto done;
2455
2456 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2457 if (mpsar_lo) {
2458 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2459 mpsar_lo = 0;
2460 }
2461 if (mpsar_hi) {
2462 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2463 mpsar_hi = 0;
2464 }
2465 } else if (vmdq < 32) {
2466 mpsar_lo &= ~(1 << vmdq);
2467 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2468 } else {
2469 mpsar_hi &= ~(1 << (vmdq - 32));
2470 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2471 }
2472
2473 /* was that the last pool using this rar? */
2474 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2475 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002476done:
2477 return 0;
2478}
2479
2480/**
2481 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2482 * @hw: pointer to hardware struct
2483 * @rar: receive address register index to associate with a VMDq index
2484 * @vmdq: VMDq pool index
2485 **/
2486s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2487{
2488 u32 mpsar;
2489 u32 rar_entries = hw->mac.num_rar_entries;
2490
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002491 /* Make sure we are using a valid rar index range */
2492 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002493 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002494 return IXGBE_ERR_INVALID_ARGUMENT;
2495 }
2496
2497 if (vmdq < 32) {
2498 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2499 mpsar |= 1 << vmdq;
2500 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2501 } else {
2502 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2503 mpsar |= 1 << (vmdq - 32);
2504 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002505 }
2506 return 0;
2507}
2508
2509/**
2510 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2511 * @hw: pointer to hardware structure
2512 **/
2513s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2514{
2515 int i;
2516
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002517 for (i = 0; i < 128; i++)
2518 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2519
2520 return 0;
2521}
2522
2523/**
2524 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2525 * @hw: pointer to hardware structure
2526 * @vlan: VLAN id to write to VLAN filter
2527 *
2528 * return the VLVF index where this VLAN id should be placed
2529 *
2530 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002531static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002532{
2533 u32 bits = 0;
2534 u32 first_empty_slot = 0;
2535 s32 regindex;
2536
2537 /* short cut the special case */
2538 if (vlan == 0)
2539 return 0;
2540
2541 /*
2542 * Search for the vlan id in the VLVF entries. Save off the first empty
2543 * slot found along the way
2544 */
2545 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2546 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2547 if (!bits && !(first_empty_slot))
2548 first_empty_slot = regindex;
2549 else if ((bits & 0x0FFF) == vlan)
2550 break;
2551 }
2552
2553 /*
2554 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2555 * in the VLVF. Else use the first empty VLVF register for this
2556 * vlan id.
2557 */
2558 if (regindex >= IXGBE_VLVF_ENTRIES) {
2559 if (first_empty_slot)
2560 regindex = first_empty_slot;
2561 else {
2562 hw_dbg(hw, "No space in VLVF.\n");
2563 regindex = IXGBE_ERR_NO_SPACE;
2564 }
2565 }
2566
2567 return regindex;
2568}
2569
2570/**
2571 * ixgbe_set_vfta_generic - Set VLAN filter table
2572 * @hw: pointer to hardware structure
2573 * @vlan: VLAN id to write to VLAN filter
2574 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
2575 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
2576 *
2577 * Turn on/off specified VLAN in the VLAN filter table.
2578 **/
2579s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
2580 bool vlan_on)
2581{
2582 s32 regindex;
2583 u32 bitindex;
2584 u32 vfta;
2585 u32 bits;
2586 u32 vt;
2587 u32 targetbit;
2588 bool vfta_changed = false;
2589
2590 if (vlan > 4095)
2591 return IXGBE_ERR_PARAM;
2592
2593 /*
2594 * this is a 2 part operation - first the VFTA, then the
2595 * VLVF and VLVFB if VT Mode is set
2596 * We don't write the VFTA until we know the VLVF part succeeded.
2597 */
2598
2599 /* Part 1
2600 * The VFTA is a bitstring made up of 128 32-bit registers
2601 * that enable the particular VLAN id, much like the MTA:
2602 * bits[11-5]: which register
2603 * bits[4-0]: which bit in the register
2604 */
2605 regindex = (vlan >> 5) & 0x7F;
2606 bitindex = vlan & 0x1F;
2607 targetbit = (1 << bitindex);
2608 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
2609
2610 if (vlan_on) {
2611 if (!(vfta & targetbit)) {
2612 vfta |= targetbit;
2613 vfta_changed = true;
2614 }
2615 } else {
2616 if ((vfta & targetbit)) {
2617 vfta &= ~targetbit;
2618 vfta_changed = true;
2619 }
2620 }
2621
2622 /* Part 2
2623 * If VT Mode is set
2624 * Either vlan_on
2625 * make sure the vlan is in VLVF
2626 * set the vind bit in the matching VLVFB
2627 * Or !vlan_on
2628 * clear the pool bit and possibly the vind
2629 */
2630 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2631 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
2632 s32 vlvf_index;
2633
2634 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
2635 if (vlvf_index < 0)
2636 return vlvf_index;
2637
2638 if (vlan_on) {
2639 /* set the pool bit */
2640 if (vind < 32) {
2641 bits = IXGBE_READ_REG(hw,
2642 IXGBE_VLVFB(vlvf_index*2));
2643 bits |= (1 << vind);
2644 IXGBE_WRITE_REG(hw,
2645 IXGBE_VLVFB(vlvf_index*2),
2646 bits);
2647 } else {
2648 bits = IXGBE_READ_REG(hw,
2649 IXGBE_VLVFB((vlvf_index*2)+1));
2650 bits |= (1 << (vind-32));
2651 IXGBE_WRITE_REG(hw,
2652 IXGBE_VLVFB((vlvf_index*2)+1),
2653 bits);
2654 }
2655 } else {
2656 /* clear the pool bit */
2657 if (vind < 32) {
2658 bits = IXGBE_READ_REG(hw,
2659 IXGBE_VLVFB(vlvf_index*2));
2660 bits &= ~(1 << vind);
2661 IXGBE_WRITE_REG(hw,
2662 IXGBE_VLVFB(vlvf_index*2),
2663 bits);
2664 bits |= IXGBE_READ_REG(hw,
2665 IXGBE_VLVFB((vlvf_index*2)+1));
2666 } else {
2667 bits = IXGBE_READ_REG(hw,
2668 IXGBE_VLVFB((vlvf_index*2)+1));
2669 bits &= ~(1 << (vind-32));
2670 IXGBE_WRITE_REG(hw,
2671 IXGBE_VLVFB((vlvf_index*2)+1),
2672 bits);
2673 bits |= IXGBE_READ_REG(hw,
2674 IXGBE_VLVFB(vlvf_index*2));
2675 }
2676 }
2677
2678 /*
2679 * If there are still bits set in the VLVFB registers
2680 * for the VLAN ID indicated we need to see if the
2681 * caller is requesting that we clear the VFTA entry bit.
2682 * If the caller has requested that we clear the VFTA
2683 * entry bit but there are still pools/VFs using this VLAN
2684 * ID entry then ignore the request. We're not worried
2685 * about the case where we're turning the VFTA VLAN ID
2686 * entry bit on, only when requested to turn it off as
2687 * there may be multiple pools and/or VFs using the
2688 * VLAN ID entry. In that case we cannot clear the
2689 * VFTA bit until all pools/VFs using that VLAN ID have also
2690 * been cleared. This will be indicated by "bits" being
2691 * zero.
2692 */
2693 if (bits) {
2694 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
2695 (IXGBE_VLVF_VIEN | vlan));
2696 if (!vlan_on) {
2697 /* someone wants to clear the vfta entry
2698 * but some pools/VFs are still using it.
2699 * Ignore it. */
2700 vfta_changed = false;
2701 }
2702 }
2703 else
2704 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
2705 }
2706
2707 if (vfta_changed)
2708 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
2709
2710 return 0;
2711}
2712
2713/**
2714 * ixgbe_clear_vfta_generic - Clear VLAN filter table
2715 * @hw: pointer to hardware structure
2716 *
2717 * Clears the VLAN filer table, and the VMDq index associated with the filter
2718 **/
2719s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
2720{
2721 u32 offset;
2722
2723 for (offset = 0; offset < hw->mac.vft_size; offset++)
2724 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
2725
2726 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
2727 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
2728 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
2729 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
2730 }
2731
2732 return 0;
2733}
2734
2735/**
2736 * ixgbe_check_mac_link_generic - Determine link and speed status
2737 * @hw: pointer to hardware structure
2738 * @speed: pointer to link speed
2739 * @link_up: true when link is up
2740 * @link_up_wait_to_complete: bool used to wait for link up or not
2741 *
2742 * Reads the links register to determine if link is up and the current speed
2743 **/
2744s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00002745 bool *link_up, bool link_up_wait_to_complete)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002746{
Emil Tantilov48de36c2011-02-16 01:38:08 +00002747 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002748 u32 i;
2749
Emil Tantilov48de36c2011-02-16 01:38:08 +00002750 /* clear the old state */
2751 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
2752
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002753 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00002754
2755 if (links_orig != links_reg) {
2756 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
2757 links_orig, links_reg);
2758 }
2759
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002760 if (link_up_wait_to_complete) {
2761 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2762 if (links_reg & IXGBE_LINKS_UP) {
2763 *link_up = true;
2764 break;
2765 } else {
2766 *link_up = false;
2767 }
2768 msleep(100);
2769 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
2770 }
2771 } else {
2772 if (links_reg & IXGBE_LINKS_UP)
2773 *link_up = true;
2774 else
2775 *link_up = false;
2776 }
2777
2778 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2779 IXGBE_LINKS_SPEED_10G_82599)
2780 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2781 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
Emil Tantilov63d778d2011-02-19 08:43:39 +00002782 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002783 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002784 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2785 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002786 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00002787 else
2788 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002789
2790 /* if link is down, zero out the current_mode */
2791 if (*link_up == false) {
2792 hw->fc.current_mode = ixgbe_fc_none;
2793 hw->fc.fc_was_autonegged = false;
2794 }
2795
2796 return 0;
2797}
Don Skidmorea391f1d2010-11-16 19:27:15 -08002798
2799/**
2800 * ixgbe_get_wwn_prefix_generic Get alternative WWNN/WWPN prefix from
2801 * the EEPROM
2802 * @hw: pointer to hardware structure
2803 * @wwnn_prefix: the alternative WWNN prefix
2804 * @wwpn_prefix: the alternative WWPN prefix
2805 *
2806 * This function will read the EEPROM from the alternative SAN MAC address
2807 * block to check the support for the alternative WWNN/WWPN prefix support.
2808 **/
2809s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
2810 u16 *wwpn_prefix)
2811{
2812 u16 offset, caps;
2813 u16 alt_san_mac_blk_offset;
2814
2815 /* clear output first */
2816 *wwnn_prefix = 0xFFFF;
2817 *wwpn_prefix = 0xFFFF;
2818
2819 /* check if alternative SAN MAC is supported */
2820 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
2821 &alt_san_mac_blk_offset);
2822
2823 if ((alt_san_mac_blk_offset == 0) ||
2824 (alt_san_mac_blk_offset == 0xFFFF))
2825 goto wwn_prefix_out;
2826
2827 /* check capability in alternative san mac address block */
2828 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
2829 hw->eeprom.ops.read(hw, offset, &caps);
2830 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
2831 goto wwn_prefix_out;
2832
2833 /* get the corresponding prefix for WWNN/WWPN */
2834 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
2835 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
2836
2837 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
2838 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
2839
2840wwn_prefix_out:
2841 return 0;
2842}
Greg Rosea985b6c32010-11-18 03:02:52 +00002843
2844/**
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002845 * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
2846 * control
2847 * @hw: pointer to hardware structure
2848 *
2849 * There are several phys that do not support autoneg flow control. This
2850 * function check the device id to see if the associated phy supports
2851 * autoneg flow control.
2852 **/
2853static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
2854{
2855
2856 switch (hw->device_id) {
2857 case IXGBE_DEV_ID_X540T:
2858 return 0;
2859 case IXGBE_DEV_ID_82599_T3_LOM:
2860 return 0;
2861 default:
2862 return IXGBE_ERR_FC_NOT_SUPPORTED;
2863 }
2864}
2865
2866/**
Greg Rosea985b6c32010-11-18 03:02:52 +00002867 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2868 * @hw: pointer to hardware structure
2869 * @enable: enable or disable switch for anti-spoofing
2870 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
2871 *
2872 **/
2873void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
2874{
2875 int j;
2876 int pf_target_reg = pf >> 3;
2877 int pf_target_shift = pf % 8;
2878 u32 pfvfspoof = 0;
2879
2880 if (hw->mac.type == ixgbe_mac_82598EB)
2881 return;
2882
2883 if (enable)
2884 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
2885
2886 /*
2887 * PFVFSPOOF register array is size 8 with 8 bits assigned to
2888 * MAC anti-spoof enables in each register array element.
2889 */
2890 for (j = 0; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
2891 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
2892
2893 /* If not enabling anti-spoofing then done */
2894 if (!enable)
2895 return;
2896
2897 /*
2898 * The PF should be allowed to spoof so that it can support
2899 * emulation mode NICs. Reset the bit assigned to the PF
2900 */
2901 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg));
2902 pfvfspoof ^= (1 << pf_target_shift);
2903 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(pf_target_reg), pfvfspoof);
2904}
2905
2906/**
2907 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
2908 * @hw: pointer to hardware structure
2909 * @enable: enable or disable switch for VLAN anti-spoofing
2910 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
2911 *
2912 **/
2913void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
2914{
2915 int vf_target_reg = vf >> 3;
2916 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
2917 u32 pfvfspoof;
2918
2919 if (hw->mac.type == ixgbe_mac_82598EB)
2920 return;
2921
2922 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2923 if (enable)
2924 pfvfspoof |= (1 << vf_target_shift);
2925 else
2926 pfvfspoof &= ~(1 << vf_target_shift);
2927 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2928}