blob: 3694e8c7b00517dafd5f6c8b940ba1af14b3891f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok0abb6eb2006-09-27 12:53:14 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ixgb_hw.c
30 * Shared functions for accessing and configuring the adapter
31 */
32
33#include "ixgb_hw.h"
34#include "ixgb_ids.h"
35
36/* Local function prototypes */
37
Joe Perches222441a2008-04-03 10:06:25 -070038static u32 ixgb_hash_mc_addr(struct ixgb_hw *hw, u8 * mc_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Joe Perches222441a2008-04-03 10:06:25 -070040static void ixgb_mta_set(struct ixgb_hw *hw, u32 hash_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42static void ixgb_get_bus_info(struct ixgb_hw *hw);
43
Joe Perches446490c2008-03-21 11:06:37 -070044static bool ixgb_link_reset(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46static void ixgb_optics_reset(struct ixgb_hw *hw);
47
Matheos Worku8b32e632007-12-14 11:48:36 -080048static void ixgb_optics_reset_bcm(struct ixgb_hw *hw);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static ixgb_phy_type ixgb_identify_phy(struct ixgb_hw *hw);
51
Adrian Bunke9ab1d12005-10-30 16:53:30 +010052static void ixgb_clear_hw_cntrs(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Adrian Bunke9ab1d12005-10-30 16:53:30 +010054static void ixgb_clear_vfta(struct ixgb_hw *hw);
55
56static void ixgb_init_rx_addrs(struct ixgb_hw *hw);
57
Joe Perches222441a2008-04-03 10:06:25 -070058static u16 ixgb_read_phy_reg(struct ixgb_hw *hw,
59 u32 reg_address,
60 u32 phy_address,
61 u32 device_type);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010062
Joe Perches446490c2008-03-21 11:06:37 -070063static bool ixgb_setup_fc(struct ixgb_hw *hw);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010064
Joe Perches222441a2008-04-03 10:06:25 -070065static bool mac_addr_valid(u8 *mac_addr);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010066
Joe Perches222441a2008-04-03 10:06:25 -070067static u32 ixgb_mac_reset(struct ixgb_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Joe Perches222441a2008-04-03 10:06:25 -070069 u32 ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 ctrl_reg = IXGB_CTRL0_RST |
72 IXGB_CTRL0_SDP3_DIR | /* All pins are Output=1 */
73 IXGB_CTRL0_SDP2_DIR |
74 IXGB_CTRL0_SDP1_DIR |
75 IXGB_CTRL0_SDP0_DIR |
76 IXGB_CTRL0_SDP3 | /* Initial value 1101 */
77 IXGB_CTRL0_SDP2 |
78 IXGB_CTRL0_SDP0;
79
80#ifdef HP_ZX1
81 /* Workaround for 82597EX reset errata */
82 IXGB_WRITE_REG_IO(hw, CTRL0, ctrl_reg);
83#else
84 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
85#endif
86
87 /* Delay a few ms just to allow the reset to complete */
Jeff Garzikf8ec4732006-09-19 15:27:07 -040088 msleep(IXGB_DELAY_AFTER_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
90#ifdef DBG
91 /* Make sure the self-clearing global reset bit did self clear */
92 ASSERT(!(ctrl_reg & IXGB_CTRL0_RST));
93#endif
94
Matheos Worku8b32e632007-12-14 11:48:36 -080095 if (hw->subsystem_vendor_id == SUN_SUBVENDOR_ID) {
96 ctrl_reg = /* Enable interrupt from XFP and SerDes */
97 IXGB_CTRL1_GPI0_EN |
98 IXGB_CTRL1_SDP6_DIR |
99 IXGB_CTRL1_SDP7_DIR |
100 IXGB_CTRL1_SDP6 |
101 IXGB_CTRL1_SDP7;
102 IXGB_WRITE_REG(hw, CTRL1, ctrl_reg);
103 ixgb_optics_reset_bcm(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
Matheos Worku8b32e632007-12-14 11:48:36 -0800106 if (hw->phy_type == ixgb_phy_type_txn17401)
107 ixgb_optics_reset(hw);
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return ctrl_reg;
110}
111
112/******************************************************************************
113 * Reset the transmit and receive units; mask and clear all interrupts.
114 *
115 * hw - Struct containing variables accessed by shared code
116 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700117bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118ixgb_adapter_stop(struct ixgb_hw *hw)
119{
Joe Perches222441a2008-04-03 10:06:25 -0700120 u32 ctrl_reg;
121 u32 icr_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 DEBUGFUNC("ixgb_adapter_stop");
124
125 /* If we are stopped or resetting exit gracefully and wait to be
126 * started again before accessing the hardware.
127 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700128 if (hw->adapter_stopped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 DEBUGOUT("Exiting because the adapter is already stopped!!!\n");
Joe Perches446490c2008-03-21 11:06:37 -0700130 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
133 /* Set the Adapter Stopped flag so other driver functions stop
134 * touching the Hardware.
135 */
Joe Perches446490c2008-03-21 11:06:37 -0700136 hw->adapter_stopped = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 /* Clear interrupt mask to stop board from generating interrupts */
139 DEBUGOUT("Masking off all interrupts\n");
140 IXGB_WRITE_REG(hw, IMC, 0xFFFFFFFF);
141
142 /* Disable the Transmit and Receive units. Then delay to allow
143 * any pending transactions to complete before we hit the MAC with
144 * the global reset.
145 */
146 IXGB_WRITE_REG(hw, RCTL, IXGB_READ_REG(hw, RCTL) & ~IXGB_RCTL_RXEN);
147 IXGB_WRITE_REG(hw, TCTL, IXGB_READ_REG(hw, TCTL) & ~IXGB_TCTL_TXEN);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400148 msleep(IXGB_DELAY_BEFORE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* Issue a global reset to the MAC. This will reset the chip's
151 * transmit, receive, DMA, and link units. It will not effect
152 * the current PCI configuration. The global reset bit is self-
153 * clearing, and should clear within a microsecond.
154 */
155 DEBUGOUT("Issuing a global reset to MAC\n");
156
157 ctrl_reg = ixgb_mac_reset(hw);
158
159 /* Clear interrupt mask to stop board from generating interrupts */
160 DEBUGOUT("Masking off all interrupts\n");
161 IXGB_WRITE_REG(hw, IMC, 0xffffffff);
162
163 /* Clear any pending interrupt events. */
164 icr_reg = IXGB_READ_REG(hw, ICR);
165
166 return (ctrl_reg & IXGB_CTRL0_RST);
167}
168
169
170/******************************************************************************
171 * Identifies the vendor of the optics module on the adapter. The SR adapters
172 * support two different types of XPAK optics, so it is necessary to determine
173 * which optics are present before applying any optics-specific workarounds.
174 *
175 * hw - Struct containing variables accessed by shared code.
176 *
177 * Returns: the vendor of the XPAK optics module.
178 *****************************************************************************/
179static ixgb_xpak_vendor
180ixgb_identify_xpak_vendor(struct ixgb_hw *hw)
181{
Joe Perches222441a2008-04-03 10:06:25 -0700182 u32 i;
183 u16 vendor_name[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 ixgb_xpak_vendor xpak_vendor;
185
186 DEBUGFUNC("ixgb_identify_xpak_vendor");
187
188 /* Read the first few bytes of the vendor string from the XPAK NVR
189 * registers. These are standard XENPAK/XPAK registers, so all XPAK
190 * devices should implement them. */
191 for (i = 0; i < 5; i++) {
192 vendor_name[i] = ixgb_read_phy_reg(hw,
193 MDIO_PMA_PMD_XPAK_VENDOR_NAME
194 + i, IXGB_PHY_ADDRESS,
195 MDIO_PMA_PMD_DID);
196 }
197
198 /* Determine the actual vendor */
199 if (vendor_name[0] == 'I' &&
200 vendor_name[1] == 'N' &&
201 vendor_name[2] == 'T' &&
202 vendor_name[3] == 'E' && vendor_name[4] == 'L') {
203 xpak_vendor = ixgb_xpak_vendor_intel;
204 } else {
205 xpak_vendor = ixgb_xpak_vendor_infineon;
206 }
207
208 return (xpak_vendor);
209}
210
211/******************************************************************************
212 * Determine the physical layer module on the adapter.
213 *
214 * hw - Struct containing variables accessed by shared code. The device_id
215 * field must be (correctly) populated before calling this routine.
216 *
217 * Returns: the phy type of the adapter.
218 *****************************************************************************/
219static ixgb_phy_type
220ixgb_identify_phy(struct ixgb_hw *hw)
221{
222 ixgb_phy_type phy_type;
223 ixgb_xpak_vendor xpak_vendor;
224
225 DEBUGFUNC("ixgb_identify_phy");
226
227 /* Infer the transceiver/phy type from the device id */
228 switch (hw->device_id) {
229 case IXGB_DEVICE_ID_82597EX:
230 DEBUGOUT("Identified TXN17401 optics\n");
231 phy_type = ixgb_phy_type_txn17401;
232 break;
233
234 case IXGB_DEVICE_ID_82597EX_SR:
235 /* The SR adapters carry two different types of XPAK optics
236 * modules; read the vendor identifier to determine the exact
237 * type of optics. */
238 xpak_vendor = ixgb_identify_xpak_vendor(hw);
239 if (xpak_vendor == ixgb_xpak_vendor_intel) {
240 DEBUGOUT("Identified TXN17201 optics\n");
241 phy_type = ixgb_phy_type_txn17201;
242 } else {
243 DEBUGOUT("Identified G6005 optics\n");
244 phy_type = ixgb_phy_type_g6005;
245 }
246 break;
247 case IXGB_DEVICE_ID_82597EX_LR:
248 DEBUGOUT("Identified G6104 optics\n");
249 phy_type = ixgb_phy_type_g6104;
250 break;
Manasi Deval0fe198a2006-08-16 13:47:20 -0700251 case IXGB_DEVICE_ID_82597EX_CX4:
252 DEBUGOUT("Identified CX4\n");
253 xpak_vendor = ixgb_identify_xpak_vendor(hw);
254 if (xpak_vendor == ixgb_xpak_vendor_intel) {
255 DEBUGOUT("Identified TXN17201 optics\n");
256 phy_type = ixgb_phy_type_txn17201;
257 } else {
258 DEBUGOUT("Identified G6005 optics\n");
259 phy_type = ixgb_phy_type_g6005;
260 }
261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 default:
263 DEBUGOUT("Unknown physical layer module\n");
264 phy_type = ixgb_phy_type_unknown;
265 break;
266 }
267
Matheos Worku8b32e632007-12-14 11:48:36 -0800268 /* update phy type for sun specific board */
269 if (hw->subsystem_vendor_id == SUN_SUBVENDOR_ID)
270 phy_type = ixgb_phy_type_bcm;
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return (phy_type);
273}
274
275/******************************************************************************
276 * Performs basic configuration of the adapter.
277 *
278 * hw - Struct containing variables accessed by shared code
279 *
280 * Resets the controller.
281 * Reads and validates the EEPROM.
282 * Initializes the receive address registers.
283 * Initializes the multicast table.
284 * Clears all on-chip counters.
285 * Calls routine to setup flow control settings.
286 * Leaves the transmit and receive units disabled and uninitialized.
287 *
288 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700289 * true if successful,
290 * false if unrecoverable problems were encountered.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700292bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293ixgb_init_hw(struct ixgb_hw *hw)
294{
Joe Perches222441a2008-04-03 10:06:25 -0700295 u32 i;
296 u32 ctrl_reg;
Joe Perches446490c2008-03-21 11:06:37 -0700297 bool status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 DEBUGFUNC("ixgb_init_hw");
300
301 /* Issue a global reset to the MAC. This will reset the chip's
302 * transmit, receive, DMA, and link units. It will not effect
303 * the current PCI configuration. The global reset bit is self-
304 * clearing, and should clear within a microsecond.
305 */
306 DEBUGOUT("Issuing a global reset to MAC\n");
307
308 ctrl_reg = ixgb_mac_reset(hw);
309
310 DEBUGOUT("Issuing an EE reset to MAC\n");
311#ifdef HP_ZX1
312 /* Workaround for 82597EX reset errata */
313 IXGB_WRITE_REG_IO(hw, CTRL1, IXGB_CTRL1_EE_RST);
314#else
315 IXGB_WRITE_REG(hw, CTRL1, IXGB_CTRL1_EE_RST);
316#endif
317
318 /* Delay a few ms just to allow the reset to complete */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400319 msleep(IXGB_DELAY_AFTER_EE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Joe Perches446490c2008-03-21 11:06:37 -0700321 if (!ixgb_get_eeprom_data(hw))
322 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Use the device id to determine the type of phy/transceiver. */
325 hw->device_id = ixgb_get_ee_device_id(hw);
326 hw->phy_type = ixgb_identify_phy(hw);
327
328 /* Setup the receive addresses.
329 * Receive Address Registers (RARs 0 - 15).
330 */
331 ixgb_init_rx_addrs(hw);
332
333 /*
334 * Check that a valid MAC address has been set.
335 * If it is not valid, we fail hardware init.
336 */
337 if (!mac_addr_valid(hw->curr_mac_addr)) {
338 DEBUGOUT("MAC address invalid after ixgb_init_rx_addrs\n");
Joe Perches446490c2008-03-21 11:06:37 -0700339 return(false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
342 /* tell the routines in this file they can access hardware again */
Joe Perches446490c2008-03-21 11:06:37 -0700343 hw->adapter_stopped = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* Fill in the bus_info structure */
346 ixgb_get_bus_info(hw);
347
348 /* Zero out the Multicast HASH table */
349 DEBUGOUT("Zeroing the MTA\n");
350 for(i = 0; i < IXGB_MC_TBL_SIZE; i++)
351 IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
352
353 /* Zero out the VLAN Filter Table Array */
354 ixgb_clear_vfta(hw);
355
356 /* Zero all of the hardware counters */
357 ixgb_clear_hw_cntrs(hw);
358
359 /* Call a subroutine to setup flow control. */
360 status = ixgb_setup_fc(hw);
361
362 /* 82597EX errata: Call check-for-link in case lane deskew is locked */
363 ixgb_check_for_link(hw);
364
365 return (status);
366}
367
368/******************************************************************************
369 * Initializes receive address filters.
370 *
371 * hw - Struct containing variables accessed by shared code
372 *
373 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700374 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 * the receiver is in reset when the routine is called.
376 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100377static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378ixgb_init_rx_addrs(struct ixgb_hw *hw)
379{
Joe Perches222441a2008-04-03 10:06:25 -0700380 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 DEBUGFUNC("ixgb_init_rx_addrs");
383
384 /*
385 * If the current mac address is valid, assume it is a software override
386 * to the permanent address.
387 * Otherwise, use the permanent address from the eeprom.
388 */
389 if (!mac_addr_valid(hw->curr_mac_addr)) {
390
391 /* Get the MAC address from the eeprom for later reference */
392 ixgb_get_ee_mac_addr(hw, hw->curr_mac_addr);
393
394 DEBUGOUT3(" Keeping Permanent MAC Addr =%.2X %.2X %.2X ",
395 hw->curr_mac_addr[0],
396 hw->curr_mac_addr[1], hw->curr_mac_addr[2]);
397 DEBUGOUT3("%.2X %.2X %.2X\n",
398 hw->curr_mac_addr[3],
399 hw->curr_mac_addr[4], hw->curr_mac_addr[5]);
400 } else {
401
402 /* Setup the receive address. */
403 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
404 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
405 hw->curr_mac_addr[0],
406 hw->curr_mac_addr[1], hw->curr_mac_addr[2]);
407 DEBUGOUT3("%.2X %.2X %.2X\n",
408 hw->curr_mac_addr[3],
409 hw->curr_mac_addr[4], hw->curr_mac_addr[5]);
410
411 ixgb_rar_set(hw, hw->curr_mac_addr, 0);
412 }
413
414 /* Zero out the other 15 receive addresses. */
415 DEBUGOUT("Clearing RAR[1-15]\n");
416 for(i = 1; i < IXGB_RAR_ENTRIES; i++) {
Aaron Saltera3ffab82007-01-06 09:51:41 -0800417 /* Write high reg first to disable the AV bit first */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Aaron Saltera3ffab82007-01-06 09:51:41 -0800419 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421
422 return;
423}
424
425/******************************************************************************
426 * Updates the MAC's list of multicast addresses.
427 *
428 * hw - Struct containing variables accessed by shared code
429 * mc_addr_list - the list of new multicast addresses
430 * mc_addr_count - number of addresses
431 * pad - number of bytes between addresses in the list
432 *
433 * The given list replaces any existing list. Clears the last 15 receive
434 * address registers and the multicast table. Uses receive address registers
435 * for the first 15 multicast addresses, and hashes the rest into the
436 * multicast table.
437 *****************************************************************************/
438void
439ixgb_mc_addr_list_update(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700440 u8 *mc_addr_list,
441 u32 mc_addr_count,
442 u32 pad)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Joe Perches222441a2008-04-03 10:06:25 -0700444 u32 hash_value;
445 u32 i;
446 u32 rar_used_count = 1; /* RAR[0] is used for our MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 DEBUGFUNC("ixgb_mc_addr_list_update");
449
450 /* Set the new number of MC addresses that we are being requested to use. */
451 hw->num_mc_addrs = mc_addr_count;
452
453 /* Clear RAR[1-15] */
454 DEBUGOUT(" Clearing RAR[1-15]\n");
455 for(i = rar_used_count; i < IXGB_RAR_ENTRIES; i++) {
456 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
457 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
458 }
459
460 /* Clear the MTA */
461 DEBUGOUT(" Clearing MTA\n");
462 for(i = 0; i < IXGB_MC_TBL_SIZE; i++) {
463 IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
464 }
465
466 /* Add the new addresses */
467 for(i = 0; i < mc_addr_count; i++) {
468 DEBUGOUT(" Adding the multicast addresses:\n");
469 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
470 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad)],
471 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) +
472 1],
473 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) +
474 2],
475 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) +
476 3],
477 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) +
478 4],
479 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) +
480 5]);
481
482 /* Place this multicast address in the RAR if there is room, *
483 * else put it in the MTA
484 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700485 if (rar_used_count < IXGB_RAR_ENTRIES) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 ixgb_rar_set(hw,
487 mc_addr_list +
488 (i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad)),
489 rar_used_count);
490 DEBUGOUT1("Added a multicast address to RAR[%d]\n", i);
491 rar_used_count++;
492 } else {
493 hash_value = ixgb_hash_mc_addr(hw,
494 mc_addr_list +
495 (i *
496 (IXGB_ETH_LENGTH_OF_ADDRESS
497 + pad)));
498
499 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
500
501 ixgb_mta_set(hw, hash_value);
502 }
503 }
504
505 DEBUGOUT("MC Update Complete\n");
506 return;
507}
508
509/******************************************************************************
510 * Hashes an address to determine its location in the multicast table
511 *
512 * hw - Struct containing variables accessed by shared code
513 * mc_addr - the multicast address to hash
514 *
515 * Returns:
516 * The hash value
517 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700518static u32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519ixgb_hash_mc_addr(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700520 u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Joe Perches222441a2008-04-03 10:06:25 -0700522 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 DEBUGFUNC("ixgb_hash_mc_addr");
525
526 /* The portion of the address that is used for the hash table is
527 * determined by the mc_filter_type setting.
528 */
529 switch (hw->mc_filter_type) {
530 /* [0] [1] [2] [3] [4] [5]
531 * 01 AA 00 12 34 56
532 * LSB MSB - According to H/W docs */
533 case 0:
534 /* [47:36] i.e. 0x563 for above example address */
535 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700536 ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 break;
538 case 1: /* [46:35] i.e. 0xAC6 for above example address */
539 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700540 ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 break;
542 case 2: /* [45:34] i.e. 0x5D8 for above example address */
543 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700544 ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 break;
546 case 3: /* [43:32] i.e. 0x634 for above example address */
Joe Perches222441a2008-04-03 10:06:25 -0700547 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 break;
549 default:
550 /* Invalid mc_filter_type, what should we do? */
551 DEBUGOUT("MC filter type param set incorrectly\n");
552 ASSERT(0);
553 break;
554 }
555
556 hash_value &= 0xFFF;
557 return (hash_value);
558}
559
560/******************************************************************************
561 * Sets the bit in the multicast table corresponding to the hash value.
562 *
563 * hw - Struct containing variables accessed by shared code
564 * hash_value - Multicast address hash value
565 *****************************************************************************/
566static void
567ixgb_mta_set(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700568 u32 hash_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Joe Perches222441a2008-04-03 10:06:25 -0700570 u32 hash_bit, hash_reg;
571 u32 mta_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 /* The MTA is a register array of 128 32-bit registers.
574 * It is treated like an array of 4096 bits. We want to set
575 * bit BitArray[hash_value]. So we figure out what register
576 * the bit is in, read it, OR in the new bit, then write
577 * back the new value. The register is determined by the
578 * upper 7 bits of the hash value and the bit within that
579 * register are determined by the lower 5 bits of the value.
580 */
581 hash_reg = (hash_value >> 5) & 0x7F;
582 hash_bit = hash_value & 0x1F;
583
584 mta_reg = IXGB_READ_REG_ARRAY(hw, MTA, hash_reg);
585
586 mta_reg |= (1 << hash_bit);
587
588 IXGB_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta_reg);
589
590 return;
591}
592
593/******************************************************************************
594 * Puts an ethernet address into a receive address register.
595 *
596 * hw - Struct containing variables accessed by shared code
597 * addr - Address to put into receive address register
598 * index - Receive address register to write
599 *****************************************************************************/
600void
601ixgb_rar_set(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700602 u8 *addr,
603 u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Joe Perches222441a2008-04-03 10:06:25 -0700605 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 DEBUGFUNC("ixgb_rar_set");
608
609 /* HW expects these in little endian so we reverse the byte order
610 * from network order (big endian) to little endian
611 */
Joe Perches222441a2008-04-03 10:06:25 -0700612 rar_low = ((u32) addr[0] |
613 ((u32)addr[1] << 8) |
614 ((u32)addr[2] << 16) |
615 ((u32)addr[3] << 24));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Joe Perches222441a2008-04-03 10:06:25 -0700617 rar_high = ((u32) addr[4] |
618 ((u32)addr[5] << 8) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 IXGB_RAH_AV);
620
621 IXGB_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
622 IXGB_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
623 return;
624}
625
626/******************************************************************************
627 * Writes a value to the specified offset in the VLAN filter table.
628 *
629 * hw - Struct containing variables accessed by shared code
630 * offset - Offset in VLAN filer table to write
631 * value - Value to write into VLAN filter table
632 *****************************************************************************/
633void
634ixgb_write_vfta(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700635 u32 offset,
636 u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, value);
639 return;
640}
641
642/******************************************************************************
643 * Clears the VLAN filer table
644 *
645 * hw - Struct containing variables accessed by shared code
646 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100647static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648ixgb_clear_vfta(struct ixgb_hw *hw)
649{
Joe Perches222441a2008-04-03 10:06:25 -0700650 u32 offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 for(offset = 0; offset < IXGB_VLAN_FILTER_TBL_SIZE; offset++)
653 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
654 return;
655}
656
657/******************************************************************************
658 * Configures the flow control settings based on SW configuration.
659 *
660 * hw - Struct containing variables accessed by shared code
661 *****************************************************************************/
662
Joe Perches446490c2008-03-21 11:06:37 -0700663static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664ixgb_setup_fc(struct ixgb_hw *hw)
665{
Joe Perches222441a2008-04-03 10:06:25 -0700666 u32 ctrl_reg;
667 u32 pap_reg = 0; /* by default, assume no pause time */
Joe Perches446490c2008-03-21 11:06:37 -0700668 bool status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 DEBUGFUNC("ixgb_setup_fc");
671
672 /* Get the current control reg 0 settings */
673 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
674
675 /* Clear the Receive Pause Enable and Transmit Pause Enable bits */
676 ctrl_reg &= ~(IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
677
678 /* The possible values of the "flow_control" parameter are:
679 * 0: Flow control is completely disabled
680 * 1: Rx flow control is enabled (we can receive pause frames
681 * but not send pause frames).
682 * 2: Tx flow control is enabled (we can send pause frames
683 * but we do not support receiving pause frames).
684 * 3: Both Rx and TX flow control (symmetric) are enabled.
685 * other: Invalid.
686 */
687 switch (hw->fc.type) {
688 case ixgb_fc_none: /* 0 */
689 /* Set CMDC bit to disable Rx Flow control */
690 ctrl_reg |= (IXGB_CTRL0_CMDC);
691 break;
692 case ixgb_fc_rx_pause: /* 1 */
693 /* RX Flow control is enabled, and TX Flow control is
694 * disabled.
695 */
696 ctrl_reg |= (IXGB_CTRL0_RPE);
697 break;
698 case ixgb_fc_tx_pause: /* 2 */
699 /* TX Flow control is enabled, and RX Flow control is
700 * disabled, by a software over-ride.
701 */
702 ctrl_reg |= (IXGB_CTRL0_TPE);
703 pap_reg = hw->fc.pause_time;
704 break;
705 case ixgb_fc_full: /* 3 */
706 /* Flow control (both RX and TX) is enabled by a software
707 * over-ride.
708 */
709 ctrl_reg |= (IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
710 pap_reg = hw->fc.pause_time;
711 break;
712 default:
713 /* We should never get here. The value should be 0-3. */
714 DEBUGOUT("Flow control param set incorrectly\n");
715 ASSERT(0);
716 break;
717 }
718
719 /* Write the new settings */
720 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
721
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700722 if (pap_reg != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 IXGB_WRITE_REG(hw, PAP, pap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 /* Set the flow control receive threshold registers. Normally,
726 * these registers will be set to a default threshold that may be
727 * adjusted later by the driver's runtime code. However, if the
728 * ability to transmit pause frames in not enabled, then these
729 * registers will be set to 0.
730 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700731 if (!(hw->fc.type & ixgb_fc_tx_pause)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 IXGB_WRITE_REG(hw, FCRTL, 0);
733 IXGB_WRITE_REG(hw, FCRTH, 0);
734 } else {
735 /* We need to set up the Receive Threshold high and low water
736 * marks as well as (optionally) enabling the transmission of XON
737 * frames. */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700738 if (hw->fc.send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 IXGB_WRITE_REG(hw, FCRTL,
740 (hw->fc.low_water | IXGB_FCRTL_XONE));
741 } else {
742 IXGB_WRITE_REG(hw, FCRTL, hw->fc.low_water);
743 }
744 IXGB_WRITE_REG(hw, FCRTH, hw->fc.high_water);
745 }
746 return (status);
747}
748
749/******************************************************************************
750 * Reads a word from a device over the Management Data Interface (MDI) bus.
751 * This interface is used to manage Physical layer devices.
752 *
753 * hw - Struct containing variables accessed by hw code
754 * reg_address - Offset of device register being read.
755 * phy_address - Address of device on MDI.
756 *
757 * Returns: Data word (16 bits) from MDI device.
758 *
759 * The 82597EX has support for several MDI access methods. This routine
760 * uses the new protocol MDI Single Command and Address Operation.
761 * This requires that first an address cycle command is sent, followed by a
762 * read command.
763 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700764static u16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765ixgb_read_phy_reg(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700766 u32 reg_address,
767 u32 phy_address,
768 u32 device_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
Joe Perches222441a2008-04-03 10:06:25 -0700770 u32 i;
771 u32 data;
772 u32 command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
775 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
776 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
777
778 /* Setup and write the address cycle command */
779 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
780 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
781 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
782 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
783
784 IXGB_WRITE_REG(hw, MSCA, command);
785
786 /**************************************************************
787 ** Check every 10 usec to see if the address cycle completed
788 ** The COMMAND bit will clear when the operation is complete.
789 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
790 ** from the CPU Write to the Ready bit assertion.
791 **************************************************************/
792
793 for(i = 0; i < 10; i++)
794 {
795 udelay(10);
796
797 command = IXGB_READ_REG(hw, MSCA);
798
799 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
800 break;
801 }
802
803 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
804
805 /* Address cycle complete, setup and write the read command */
806 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
807 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
808 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
809 (IXGB_MSCA_READ | IXGB_MSCA_MDI_COMMAND));
810
811 IXGB_WRITE_REG(hw, MSCA, command);
812
813 /**************************************************************
814 ** Check every 10 usec to see if the read command completed
815 ** The COMMAND bit will clear when the operation is complete.
816 ** The read may take as long as 64 usecs (we'll wait 100 usecs max)
817 ** from the CPU Write to the Ready bit assertion.
818 **************************************************************/
819
820 for(i = 0; i < 10; i++)
821 {
822 udelay(10);
823
824 command = IXGB_READ_REG(hw, MSCA);
825
826 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
827 break;
828 }
829
830 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
831
832 /* Operation is complete, get the data from the MDIO Read/Write Data
833 * register and return.
834 */
835 data = IXGB_READ_REG(hw, MSRWD);
836 data >>= IXGB_MSRWD_READ_DATA_SHIFT;
Joe Perches222441a2008-04-03 10:06:25 -0700837 return((u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
839
840/******************************************************************************
841 * Writes a word to a device over the Management Data Interface (MDI) bus.
842 * This interface is used to manage Physical layer devices.
843 *
844 * hw - Struct containing variables accessed by hw code
845 * reg_address - Offset of device register being read.
846 * phy_address - Address of device on MDI.
847 * device_type - Also known as the Device ID or DID.
848 * data - 16-bit value to be written
849 *
850 * Returns: void.
851 *
852 * The 82597EX has support for several MDI access methods. This routine
853 * uses the new protocol MDI Single Command and Address Operation.
854 * This requires that first an address cycle command is sent, followed by a
855 * write command.
856 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100857static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858ixgb_write_phy_reg(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700859 u32 reg_address,
860 u32 phy_address,
861 u32 device_type,
862 u16 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Joe Perches222441a2008-04-03 10:06:25 -0700864 u32 i;
865 u32 command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
868 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
869 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
870
871 /* Put the data in the MDIO Read/Write Data register */
Joe Perches222441a2008-04-03 10:06:25 -0700872 IXGB_WRITE_REG(hw, MSRWD, (u32)data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 /* Setup and write the address cycle command */
875 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
876 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
877 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
878 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
879
880 IXGB_WRITE_REG(hw, MSCA, command);
881
882 /**************************************************************
883 ** Check every 10 usec to see if the address cycle completed
884 ** The COMMAND bit will clear when the operation is complete.
885 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
886 ** from the CPU Write to the Ready bit assertion.
887 **************************************************************/
888
889 for(i = 0; i < 10; i++)
890 {
891 udelay(10);
892
893 command = IXGB_READ_REG(hw, MSCA);
894
895 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
896 break;
897 }
898
899 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
900
901 /* Address cycle complete, setup and write the write command */
902 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
903 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
904 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
905 (IXGB_MSCA_WRITE | IXGB_MSCA_MDI_COMMAND));
906
907 IXGB_WRITE_REG(hw, MSCA, command);
908
909 /**************************************************************
910 ** Check every 10 usec to see if the read command completed
911 ** The COMMAND bit will clear when the operation is complete.
912 ** The write may take as long as 64 usecs (we'll wait 100 usecs max)
913 ** from the CPU Write to the Ready bit assertion.
914 **************************************************************/
915
916 for(i = 0; i < 10; i++)
917 {
918 udelay(10);
919
920 command = IXGB_READ_REG(hw, MSCA);
921
922 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
923 break;
924 }
925
926 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
927
928 /* Operation is complete, return. */
929}
930
931/******************************************************************************
932 * Checks to see if the link status of the hardware has changed.
933 *
934 * hw - Struct containing variables accessed by hw code
935 *
936 * Called by any function that needs to check the link status of the adapter.
937 *****************************************************************************/
938void
939ixgb_check_for_link(struct ixgb_hw *hw)
940{
Joe Perches222441a2008-04-03 10:06:25 -0700941 u32 status_reg;
942 u32 xpcss_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 DEBUGFUNC("ixgb_check_for_link");
945
946 xpcss_reg = IXGB_READ_REG(hw, XPCSS);
947 status_reg = IXGB_READ_REG(hw, STATUS);
948
949 if ((xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
950 (status_reg & IXGB_STATUS_LU)) {
Joe Perches446490c2008-03-21 11:06:37 -0700951 hw->link_up = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 } else if (!(xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
953 (status_reg & IXGB_STATUS_LU)) {
954 DEBUGOUT("XPCSS Not Aligned while Status:LU is set.\n");
955 hw->link_up = ixgb_link_reset(hw);
956 } else {
957 /*
958 * 82597EX errata. Since the lane deskew problem may prevent
959 * link, reset the link before reporting link down.
960 */
961 hw->link_up = ixgb_link_reset(hw);
962 }
963 /* Anything else for 10 Gig?? */
964}
965
966/******************************************************************************
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700967 * Check for a bad link condition that may have occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 * The indication is that the RFC / LFC registers may be incrementing
969 * continually. A full adapter reset is required to recover.
970 *
971 * hw - Struct containing variables accessed by hw code
972 *
973 * Called by any function that needs to check the link status of the adapter.
974 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700975bool ixgb_check_for_bad_link(struct ixgb_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Joe Perches222441a2008-04-03 10:06:25 -0700977 u32 newLFC, newRFC;
Joe Perches446490c2008-03-21 11:06:37 -0700978 bool bad_link_returncode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 if (hw->phy_type == ixgb_phy_type_txn17401) {
981 newLFC = IXGB_READ_REG(hw, LFC);
982 newRFC = IXGB_READ_REG(hw, RFC);
983 if ((hw->lastLFC + 250 < newLFC)
984 || (hw->lastRFC + 250 < newRFC)) {
985 DEBUGOUT
986 ("BAD LINK! too many LFC/RFC since last check\n");
Joe Perches446490c2008-03-21 11:06:37 -0700987 bad_link_returncode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 hw->lastLFC = newLFC;
990 hw->lastRFC = newRFC;
991 }
992
993 return bad_link_returncode;
994}
995
996/******************************************************************************
997 * Clears all hardware statistics counters.
998 *
999 * hw - Struct containing variables accessed by shared code
1000 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +01001001static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002ixgb_clear_hw_cntrs(struct ixgb_hw *hw)
1003{
Joe Perches222441a2008-04-03 10:06:25 -07001004 volatile u32 temp_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 DEBUGFUNC("ixgb_clear_hw_cntrs");
1007
1008 /* if we are stopped or resetting exit gracefully */
Jesse Brandeburg03f83042008-07-08 15:52:13 -07001009 if (hw->adapter_stopped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 DEBUGOUT("Exiting because the adapter is stopped!!!\n");
1011 return;
1012 }
1013
1014 temp_reg = IXGB_READ_REG(hw, TPRL);
1015 temp_reg = IXGB_READ_REG(hw, TPRH);
1016 temp_reg = IXGB_READ_REG(hw, GPRCL);
1017 temp_reg = IXGB_READ_REG(hw, GPRCH);
1018 temp_reg = IXGB_READ_REG(hw, BPRCL);
1019 temp_reg = IXGB_READ_REG(hw, BPRCH);
1020 temp_reg = IXGB_READ_REG(hw, MPRCL);
1021 temp_reg = IXGB_READ_REG(hw, MPRCH);
1022 temp_reg = IXGB_READ_REG(hw, UPRCL);
1023 temp_reg = IXGB_READ_REG(hw, UPRCH);
1024 temp_reg = IXGB_READ_REG(hw, VPRCL);
1025 temp_reg = IXGB_READ_REG(hw, VPRCH);
1026 temp_reg = IXGB_READ_REG(hw, JPRCL);
1027 temp_reg = IXGB_READ_REG(hw, JPRCH);
1028 temp_reg = IXGB_READ_REG(hw, GORCL);
1029 temp_reg = IXGB_READ_REG(hw, GORCH);
1030 temp_reg = IXGB_READ_REG(hw, TORL);
1031 temp_reg = IXGB_READ_REG(hw, TORH);
1032 temp_reg = IXGB_READ_REG(hw, RNBC);
1033 temp_reg = IXGB_READ_REG(hw, RUC);
1034 temp_reg = IXGB_READ_REG(hw, ROC);
1035 temp_reg = IXGB_READ_REG(hw, RLEC);
1036 temp_reg = IXGB_READ_REG(hw, CRCERRS);
1037 temp_reg = IXGB_READ_REG(hw, ICBC);
1038 temp_reg = IXGB_READ_REG(hw, ECBC);
1039 temp_reg = IXGB_READ_REG(hw, MPC);
1040 temp_reg = IXGB_READ_REG(hw, TPTL);
1041 temp_reg = IXGB_READ_REG(hw, TPTH);
1042 temp_reg = IXGB_READ_REG(hw, GPTCL);
1043 temp_reg = IXGB_READ_REG(hw, GPTCH);
1044 temp_reg = IXGB_READ_REG(hw, BPTCL);
1045 temp_reg = IXGB_READ_REG(hw, BPTCH);
1046 temp_reg = IXGB_READ_REG(hw, MPTCL);
1047 temp_reg = IXGB_READ_REG(hw, MPTCH);
1048 temp_reg = IXGB_READ_REG(hw, UPTCL);
1049 temp_reg = IXGB_READ_REG(hw, UPTCH);
1050 temp_reg = IXGB_READ_REG(hw, VPTCL);
1051 temp_reg = IXGB_READ_REG(hw, VPTCH);
1052 temp_reg = IXGB_READ_REG(hw, JPTCL);
1053 temp_reg = IXGB_READ_REG(hw, JPTCH);
1054 temp_reg = IXGB_READ_REG(hw, GOTCL);
1055 temp_reg = IXGB_READ_REG(hw, GOTCH);
1056 temp_reg = IXGB_READ_REG(hw, TOTL);
1057 temp_reg = IXGB_READ_REG(hw, TOTH);
1058 temp_reg = IXGB_READ_REG(hw, DC);
1059 temp_reg = IXGB_READ_REG(hw, PLT64C);
1060 temp_reg = IXGB_READ_REG(hw, TSCTC);
1061 temp_reg = IXGB_READ_REG(hw, TSCTFC);
1062 temp_reg = IXGB_READ_REG(hw, IBIC);
1063 temp_reg = IXGB_READ_REG(hw, RFC);
1064 temp_reg = IXGB_READ_REG(hw, LFC);
1065 temp_reg = IXGB_READ_REG(hw, PFRC);
1066 temp_reg = IXGB_READ_REG(hw, PFTC);
1067 temp_reg = IXGB_READ_REG(hw, MCFRC);
1068 temp_reg = IXGB_READ_REG(hw, MCFTC);
1069 temp_reg = IXGB_READ_REG(hw, XONRXC);
1070 temp_reg = IXGB_READ_REG(hw, XONTXC);
1071 temp_reg = IXGB_READ_REG(hw, XOFFRXC);
1072 temp_reg = IXGB_READ_REG(hw, XOFFTXC);
1073 temp_reg = IXGB_READ_REG(hw, RJC);
1074 return;
1075}
1076
1077/******************************************************************************
1078 * Turns on the software controllable LED
1079 *
1080 * hw - Struct containing variables accessed by shared code
1081 *****************************************************************************/
1082void
1083ixgb_led_on(struct ixgb_hw *hw)
1084{
Joe Perches222441a2008-04-03 10:06:25 -07001085 u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /* To turn on the LED, clear software-definable pin 0 (SDP0). */
1088 ctrl0_reg &= ~IXGB_CTRL0_SDP0;
1089 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1090 return;
1091}
1092
1093/******************************************************************************
1094 * Turns off the software controllable LED
1095 *
1096 * hw - Struct containing variables accessed by shared code
1097 *****************************************************************************/
1098void
1099ixgb_led_off(struct ixgb_hw *hw)
1100{
Joe Perches222441a2008-04-03 10:06:25 -07001101 u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 /* To turn off the LED, set software-definable pin 0 (SDP0). */
1104 ctrl0_reg |= IXGB_CTRL0_SDP0;
1105 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1106 return;
1107}
1108
1109/******************************************************************************
1110 * Gets the current PCI bus type, speed, and width of the hardware
1111 *
1112 * hw - Struct containing variables accessed by shared code
1113 *****************************************************************************/
1114static void
1115ixgb_get_bus_info(struct ixgb_hw *hw)
1116{
Joe Perches222441a2008-04-03 10:06:25 -07001117 u32 status_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 status_reg = IXGB_READ_REG(hw, STATUS);
1120
1121 hw->bus.type = (status_reg & IXGB_STATUS_PCIX_MODE) ?
1122 ixgb_bus_type_pcix : ixgb_bus_type_pci;
1123
1124 if (hw->bus.type == ixgb_bus_type_pci) {
1125 hw->bus.speed = (status_reg & IXGB_STATUS_PCI_SPD) ?
1126 ixgb_bus_speed_66 : ixgb_bus_speed_33;
1127 } else {
1128 switch (status_reg & IXGB_STATUS_PCIX_SPD_MASK) {
1129 case IXGB_STATUS_PCIX_SPD_66:
1130 hw->bus.speed = ixgb_bus_speed_66;
1131 break;
1132 case IXGB_STATUS_PCIX_SPD_100:
1133 hw->bus.speed = ixgb_bus_speed_100;
1134 break;
1135 case IXGB_STATUS_PCIX_SPD_133:
1136 hw->bus.speed = ixgb_bus_speed_133;
1137 break;
1138 default:
1139 hw->bus.speed = ixgb_bus_speed_reserved;
1140 break;
1141 }
1142 }
1143
1144 hw->bus.width = (status_reg & IXGB_STATUS_BUS64) ?
1145 ixgb_bus_width_64 : ixgb_bus_width_32;
1146
1147 return;
1148}
1149
1150/******************************************************************************
1151 * Tests a MAC address to ensure it is a valid Individual Address
1152 *
1153 * mac_addr - pointer to MAC address.
1154 *
1155 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -07001156static bool
Joe Perches222441a2008-04-03 10:06:25 -07001157mac_addr_valid(u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
Joe Perches446490c2008-03-21 11:06:37 -07001159 bool is_valid = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 DEBUGFUNC("mac_addr_valid");
1161
1162 /* Make sure it is not a multicast address */
1163 if (IS_MULTICAST(mac_addr)) {
1164 DEBUGOUT("MAC address is multicast\n");
Joe Perches446490c2008-03-21 11:06:37 -07001165 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 }
1167 /* Not a broadcast address */
1168 else if (IS_BROADCAST(mac_addr)) {
1169 DEBUGOUT("MAC address is broadcast\n");
Joe Perches446490c2008-03-21 11:06:37 -07001170 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172 /* Reject the zero address */
1173 else if (mac_addr[0] == 0 &&
1174 mac_addr[1] == 0 &&
1175 mac_addr[2] == 0 &&
1176 mac_addr[3] == 0 &&
1177 mac_addr[4] == 0 &&
1178 mac_addr[5] == 0) {
1179 DEBUGOUT("MAC address is all zeros\n");
Joe Perches446490c2008-03-21 11:06:37 -07001180 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 }
1182 return (is_valid);
1183}
1184
1185/******************************************************************************
1186 * Resets the 10GbE link. Waits the settle time and returns the state of
1187 * the link.
1188 *
1189 * hw - Struct containing variables accessed by shared code
1190 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -07001191static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192ixgb_link_reset(struct ixgb_hw *hw)
1193{
Joe Perches446490c2008-03-21 11:06:37 -07001194 bool link_status = false;
Joe Perches222441a2008-04-03 10:06:25 -07001195 u8 wait_retries = MAX_RESET_ITERATIONS;
1196 u8 lrst_retries = MAX_RESET_ITERATIONS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 do {
1199 /* Reset the link */
1200 IXGB_WRITE_REG(hw, CTRL0,
1201 IXGB_READ_REG(hw, CTRL0) | IXGB_CTRL0_LRST);
1202
1203 /* Wait for link-up and lane re-alignment */
1204 do {
1205 udelay(IXGB_DELAY_USECS_AFTER_LINK_RESET);
1206 link_status =
1207 ((IXGB_READ_REG(hw, STATUS) & IXGB_STATUS_LU)
1208 && (IXGB_READ_REG(hw, XPCSS) &
Joe Perches446490c2008-03-21 11:06:37 -07001209 IXGB_XPCSS_ALIGN_STATUS)) ? true : false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 } while (!link_status && --wait_retries);
1211
1212 } while (!link_status && --lrst_retries);
1213
1214 return link_status;
1215}
1216
1217/******************************************************************************
1218 * Resets the 10GbE optics module.
1219 *
1220 * hw - Struct containing variables accessed by shared code
1221 *****************************************************************************/
Stephen Hemminger273dc742007-10-29 10:46:13 -07001222static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223ixgb_optics_reset(struct ixgb_hw *hw)
1224{
1225 if (hw->phy_type == ixgb_phy_type_txn17401) {
Joe Perches222441a2008-04-03 10:06:25 -07001226 u16 mdio_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 ixgb_write_phy_reg(hw,
1229 MDIO_PMA_PMD_CR1,
1230 IXGB_PHY_ADDRESS,
1231 MDIO_PMA_PMD_DID,
1232 MDIO_PMA_PMD_CR1_RESET);
1233
1234 mdio_reg = ixgb_read_phy_reg( hw,
1235 MDIO_PMA_PMD_CR1,
1236 IXGB_PHY_ADDRESS,
1237 MDIO_PMA_PMD_DID);
1238 }
1239
1240 return;
1241}
Matheos Worku8b32e632007-12-14 11:48:36 -08001242
1243/******************************************************************************
1244 * Resets the 10GbE optics module for Sun variant NIC.
1245 *
1246 * hw - Struct containing variables accessed by shared code
1247 *****************************************************************************/
1248
1249#define IXGB_BCM8704_USER_PMD_TX_CTRL_REG 0xC803
1250#define IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL 0x0164
1251#define IXGB_BCM8704_USER_CTRL_REG 0xC800
1252#define IXGB_BCM8704_USER_CTRL_REG_VAL 0x7FBF
1253#define IXGB_BCM8704_USER_DEV3_ADDR 0x0003
1254#define IXGB_SUN_PHY_ADDRESS 0x0000
1255#define IXGB_SUN_PHY_RESET_DELAY 305
1256
1257static void
1258ixgb_optics_reset_bcm(struct ixgb_hw *hw)
1259{
1260 u32 ctrl = IXGB_READ_REG(hw, CTRL0);
1261 ctrl &= ~IXGB_CTRL0_SDP2;
1262 ctrl |= IXGB_CTRL0_SDP3;
1263 IXGB_WRITE_REG(hw, CTRL0, ctrl);
1264
1265 /* SerDes needs extra delay */
1266 msleep(IXGB_SUN_PHY_RESET_DELAY);
1267
1268 /* Broadcom 7408L configuration */
1269 /* Reference clock config */
1270 ixgb_write_phy_reg(hw,
1271 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1272 IXGB_SUN_PHY_ADDRESS,
1273 IXGB_BCM8704_USER_DEV3_ADDR,
1274 IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL);
1275 /* we must read the registers twice */
1276 ixgb_read_phy_reg(hw,
1277 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1278 IXGB_SUN_PHY_ADDRESS,
1279 IXGB_BCM8704_USER_DEV3_ADDR);
1280 ixgb_read_phy_reg(hw,
1281 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1282 IXGB_SUN_PHY_ADDRESS,
1283 IXGB_BCM8704_USER_DEV3_ADDR);
1284
1285 ixgb_write_phy_reg(hw,
1286 IXGB_BCM8704_USER_CTRL_REG,
1287 IXGB_SUN_PHY_ADDRESS,
1288 IXGB_BCM8704_USER_DEV3_ADDR,
1289 IXGB_BCM8704_USER_CTRL_REG_VAL);
1290 ixgb_read_phy_reg(hw,
1291 IXGB_BCM8704_USER_CTRL_REG,
1292 IXGB_SUN_PHY_ADDRESS,
1293 IXGB_BCM8704_USER_DEV3_ADDR);
1294 ixgb_read_phy_reg(hw,
1295 IXGB_BCM8704_USER_CTRL_REG,
1296 IXGB_SUN_PHY_ADDRESS,
1297 IXGB_BCM8704_USER_DEV3_ADDR);
1298
1299 /* SerDes needs extra delay */
1300 msleep(IXGB_SUN_PHY_RESET_DELAY);
1301
1302 return;
1303}