blob: cd247b8d2b732f4f1531715ee1e73346f0a77a24 [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
Jesse Brandeburgf731a9e2008-07-08 15:53:09 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kok0abb6eb2006-09-27 12:53:14 -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
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
Joe Perchesd328bc82010-04-27 00:50:58 +000033#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "ixgb_hw.h"
36#include "ixgb_ids.h"
37
Joe Perchesd328bc82010-04-27 00:50:58 +000038#include <linux/etherdevice.h>
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/* Local function prototypes */
41
Joe Perches222441a2008-04-03 10:06:25 -070042static u32 ixgb_hash_mc_addr(struct ixgb_hw *hw, u8 * mc_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Joe Perches222441a2008-04-03 10:06:25 -070044static void ixgb_mta_set(struct ixgb_hw *hw, u32 hash_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46static void ixgb_get_bus_info(struct ixgb_hw *hw);
47
Joe Perches446490c2008-03-21 11:06:37 -070048static bool ixgb_link_reset(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50static void ixgb_optics_reset(struct ixgb_hw *hw);
51
Matheos Worku8b32e632007-12-14 11:48:36 -080052static void ixgb_optics_reset_bcm(struct ixgb_hw *hw);
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054static ixgb_phy_type ixgb_identify_phy(struct ixgb_hw *hw);
55
Adrian Bunke9ab1d12005-10-30 16:53:30 +010056static void ixgb_clear_hw_cntrs(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Adrian Bunke9ab1d12005-10-30 16:53:30 +010058static void ixgb_clear_vfta(struct ixgb_hw *hw);
59
60static void ixgb_init_rx_addrs(struct ixgb_hw *hw);
61
Joe Perches222441a2008-04-03 10:06:25 -070062static u16 ixgb_read_phy_reg(struct ixgb_hw *hw,
63 u32 reg_address,
64 u32 phy_address,
65 u32 device_type);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010066
Joe Perches446490c2008-03-21 11:06:37 -070067static bool ixgb_setup_fc(struct ixgb_hw *hw);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010068
Joe Perches222441a2008-04-03 10:06:25 -070069static bool mac_addr_valid(u8 *mac_addr);
Adrian Bunke9ab1d12005-10-30 16:53:30 +010070
Joe Perches222441a2008-04-03 10:06:25 -070071static u32 ixgb_mac_reset(struct ixgb_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Joe Perches222441a2008-04-03 10:06:25 -070073 u32 ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 ctrl_reg = IXGB_CTRL0_RST |
76 IXGB_CTRL0_SDP3_DIR | /* All pins are Output=1 */
77 IXGB_CTRL0_SDP2_DIR |
78 IXGB_CTRL0_SDP1_DIR |
79 IXGB_CTRL0_SDP0_DIR |
80 IXGB_CTRL0_SDP3 | /* Initial value 1101 */
81 IXGB_CTRL0_SDP2 |
82 IXGB_CTRL0_SDP0;
83
84#ifdef HP_ZX1
85 /* Workaround for 82597EX reset errata */
86 IXGB_WRITE_REG_IO(hw, CTRL0, ctrl_reg);
87#else
88 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
89#endif
90
91 /* Delay a few ms just to allow the reset to complete */
Jeff Garzikf8ec4732006-09-19 15:27:07 -040092 msleep(IXGB_DELAY_AFTER_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
94#ifdef DBG
95 /* Make sure the self-clearing global reset bit did self clear */
96 ASSERT(!(ctrl_reg & IXGB_CTRL0_RST));
97#endif
98
Matheos Worku8b32e632007-12-14 11:48:36 -080099 if (hw->subsystem_vendor_id == SUN_SUBVENDOR_ID) {
100 ctrl_reg = /* Enable interrupt from XFP and SerDes */
101 IXGB_CTRL1_GPI0_EN |
102 IXGB_CTRL1_SDP6_DIR |
103 IXGB_CTRL1_SDP7_DIR |
104 IXGB_CTRL1_SDP6 |
105 IXGB_CTRL1_SDP7;
106 IXGB_WRITE_REG(hw, CTRL1, ctrl_reg);
107 ixgb_optics_reset_bcm(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109
Matheos Worku8b32e632007-12-14 11:48:36 -0800110 if (hw->phy_type == ixgb_phy_type_txn17401)
111 ixgb_optics_reset(hw);
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return ctrl_reg;
114}
115
116/******************************************************************************
117 * Reset the transmit and receive units; mask and clear all interrupts.
118 *
119 * hw - Struct containing variables accessed by shared code
120 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700121bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122ixgb_adapter_stop(struct ixgb_hw *hw)
123{
Joe Perches222441a2008-04-03 10:06:25 -0700124 u32 ctrl_reg;
125 u32 icr_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Joe Perchesd328bc82010-04-27 00:50:58 +0000127 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 /* If we are stopped or resetting exit gracefully and wait to be
130 * started again before accessing the hardware.
131 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700132 if (hw->adapter_stopped) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000133 pr_debug("Exiting because the adapter is already stopped!!!\n");
Joe Perches446490c2008-03-21 11:06:37 -0700134 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
137 /* Set the Adapter Stopped flag so other driver functions stop
138 * touching the Hardware.
139 */
Joe Perches446490c2008-03-21 11:06:37 -0700140 hw->adapter_stopped = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 /* Clear interrupt mask to stop board from generating interrupts */
Joe Perchesd328bc82010-04-27 00:50:58 +0000143 pr_debug("Masking off all interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 IXGB_WRITE_REG(hw, IMC, 0xFFFFFFFF);
145
146 /* Disable the Transmit and Receive units. Then delay to allow
147 * any pending transactions to complete before we hit the MAC with
148 * the global reset.
149 */
150 IXGB_WRITE_REG(hw, RCTL, IXGB_READ_REG(hw, RCTL) & ~IXGB_RCTL_RXEN);
151 IXGB_WRITE_REG(hw, TCTL, IXGB_READ_REG(hw, TCTL) & ~IXGB_TCTL_TXEN);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400152 msleep(IXGB_DELAY_BEFORE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /* Issue a global reset to the MAC. This will reset the chip's
155 * transmit, receive, DMA, and link units. It will not effect
156 * the current PCI configuration. The global reset bit is self-
157 * clearing, and should clear within a microsecond.
158 */
Joe Perchesd328bc82010-04-27 00:50:58 +0000159 pr_debug("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 ctrl_reg = ixgb_mac_reset(hw);
162
163 /* Clear interrupt mask to stop board from generating interrupts */
Joe Perchesd328bc82010-04-27 00:50:58 +0000164 pr_debug("Masking off all interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 IXGB_WRITE_REG(hw, IMC, 0xffffffff);
166
167 /* Clear any pending interrupt events. */
168 icr_reg = IXGB_READ_REG(hw, ICR);
169
170 return (ctrl_reg & IXGB_CTRL0_RST);
171}
172
173
174/******************************************************************************
175 * Identifies the vendor of the optics module on the adapter. The SR adapters
176 * support two different types of XPAK optics, so it is necessary to determine
177 * which optics are present before applying any optics-specific workarounds.
178 *
179 * hw - Struct containing variables accessed by shared code.
180 *
181 * Returns: the vendor of the XPAK optics module.
182 *****************************************************************************/
183static ixgb_xpak_vendor
184ixgb_identify_xpak_vendor(struct ixgb_hw *hw)
185{
Joe Perches222441a2008-04-03 10:06:25 -0700186 u32 i;
187 u16 vendor_name[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 ixgb_xpak_vendor xpak_vendor;
189
Joe Perchesd328bc82010-04-27 00:50:58 +0000190 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* Read the first few bytes of the vendor string from the XPAK NVR
193 * registers. These are standard XENPAK/XPAK registers, so all XPAK
194 * devices should implement them. */
195 for (i = 0; i < 5; i++) {
196 vendor_name[i] = ixgb_read_phy_reg(hw,
197 MDIO_PMA_PMD_XPAK_VENDOR_NAME
198 + i, IXGB_PHY_ADDRESS,
Ben Hutchingscdbf0eb2009-04-29 08:11:05 +0000199 MDIO_MMD_PMAPMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 /* Determine the actual vendor */
203 if (vendor_name[0] == 'I' &&
204 vendor_name[1] == 'N' &&
205 vendor_name[2] == 'T' &&
206 vendor_name[3] == 'E' && vendor_name[4] == 'L') {
207 xpak_vendor = ixgb_xpak_vendor_intel;
208 } else {
209 xpak_vendor = ixgb_xpak_vendor_infineon;
210 }
211
212 return (xpak_vendor);
213}
214
215/******************************************************************************
216 * Determine the physical layer module on the adapter.
217 *
218 * hw - Struct containing variables accessed by shared code. The device_id
219 * field must be (correctly) populated before calling this routine.
220 *
221 * Returns: the phy type of the adapter.
222 *****************************************************************************/
223static ixgb_phy_type
224ixgb_identify_phy(struct ixgb_hw *hw)
225{
226 ixgb_phy_type phy_type;
227 ixgb_xpak_vendor xpak_vendor;
228
Joe Perchesd328bc82010-04-27 00:50:58 +0000229 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Infer the transceiver/phy type from the device id */
232 switch (hw->device_id) {
233 case IXGB_DEVICE_ID_82597EX:
Joe Perchesd328bc82010-04-27 00:50:58 +0000234 pr_debug("Identified TXN17401 optics\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 phy_type = ixgb_phy_type_txn17401;
236 break;
237
238 case IXGB_DEVICE_ID_82597EX_SR:
239 /* The SR adapters carry two different types of XPAK optics
240 * modules; read the vendor identifier to determine the exact
241 * type of optics. */
242 xpak_vendor = ixgb_identify_xpak_vendor(hw);
243 if (xpak_vendor == ixgb_xpak_vendor_intel) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000244 pr_debug("Identified TXN17201 optics\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 phy_type = ixgb_phy_type_txn17201;
246 } else {
Joe Perchesd328bc82010-04-27 00:50:58 +0000247 pr_debug("Identified G6005 optics\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 phy_type = ixgb_phy_type_g6005;
249 }
250 break;
251 case IXGB_DEVICE_ID_82597EX_LR:
Joe Perchesd328bc82010-04-27 00:50:58 +0000252 pr_debug("Identified G6104 optics\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 phy_type = ixgb_phy_type_g6104;
254 break;
Manasi Deval0fe198a2006-08-16 13:47:20 -0700255 case IXGB_DEVICE_ID_82597EX_CX4:
Joe Perchesd328bc82010-04-27 00:50:58 +0000256 pr_debug("Identified CX4\n");
Manasi Deval0fe198a2006-08-16 13:47:20 -0700257 xpak_vendor = ixgb_identify_xpak_vendor(hw);
258 if (xpak_vendor == ixgb_xpak_vendor_intel) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000259 pr_debug("Identified TXN17201 optics\n");
Manasi Deval0fe198a2006-08-16 13:47:20 -0700260 phy_type = ixgb_phy_type_txn17201;
261 } else {
Joe Perchesd328bc82010-04-27 00:50:58 +0000262 pr_debug("Identified G6005 optics\n");
Manasi Deval0fe198a2006-08-16 13:47:20 -0700263 phy_type = ixgb_phy_type_g6005;
264 }
265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 default:
Joe Perchesd328bc82010-04-27 00:50:58 +0000267 pr_debug("Unknown physical layer module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 phy_type = ixgb_phy_type_unknown;
269 break;
270 }
271
Matheos Worku8b32e632007-12-14 11:48:36 -0800272 /* update phy type for sun specific board */
273 if (hw->subsystem_vendor_id == SUN_SUBVENDOR_ID)
274 phy_type = ixgb_phy_type_bcm;
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return (phy_type);
277}
278
279/******************************************************************************
280 * Performs basic configuration of the adapter.
281 *
282 * hw - Struct containing variables accessed by shared code
283 *
284 * Resets the controller.
285 * Reads and validates the EEPROM.
286 * Initializes the receive address registers.
287 * Initializes the multicast table.
288 * Clears all on-chip counters.
289 * Calls routine to setup flow control settings.
290 * Leaves the transmit and receive units disabled and uninitialized.
291 *
292 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700293 * true if successful,
294 * false if unrecoverable problems were encountered.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700296bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297ixgb_init_hw(struct ixgb_hw *hw)
298{
Joe Perches222441a2008-04-03 10:06:25 -0700299 u32 i;
300 u32 ctrl_reg;
Joe Perches446490c2008-03-21 11:06:37 -0700301 bool status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Joe Perchesd328bc82010-04-27 00:50:58 +0000303 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* Issue a global reset to the MAC. This will reset the chip's
306 * transmit, receive, DMA, and link units. It will not effect
307 * the current PCI configuration. The global reset bit is self-
308 * clearing, and should clear within a microsecond.
309 */
Joe Perchesd328bc82010-04-27 00:50:58 +0000310 pr_debug("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 ctrl_reg = ixgb_mac_reset(hw);
313
Joe Perchesd328bc82010-04-27 00:50:58 +0000314 pr_debug("Issuing an EE reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#ifdef HP_ZX1
316 /* Workaround for 82597EX reset errata */
317 IXGB_WRITE_REG_IO(hw, CTRL1, IXGB_CTRL1_EE_RST);
318#else
319 IXGB_WRITE_REG(hw, CTRL1, IXGB_CTRL1_EE_RST);
320#endif
321
322 /* Delay a few ms just to allow the reset to complete */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400323 msleep(IXGB_DELAY_AFTER_EE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Joe Perches446490c2008-03-21 11:06:37 -0700325 if (!ixgb_get_eeprom_data(hw))
326 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Use the device id to determine the type of phy/transceiver. */
329 hw->device_id = ixgb_get_ee_device_id(hw);
330 hw->phy_type = ixgb_identify_phy(hw);
331
332 /* Setup the receive addresses.
333 * Receive Address Registers (RARs 0 - 15).
334 */
335 ixgb_init_rx_addrs(hw);
336
337 /*
338 * Check that a valid MAC address has been set.
339 * If it is not valid, we fail hardware init.
340 */
341 if (!mac_addr_valid(hw->curr_mac_addr)) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000342 pr_debug("MAC address invalid after ixgb_init_rx_addrs\n");
Joe Perches446490c2008-03-21 11:06:37 -0700343 return(false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
346 /* tell the routines in this file they can access hardware again */
Joe Perches446490c2008-03-21 11:06:37 -0700347 hw->adapter_stopped = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /* Fill in the bus_info structure */
350 ixgb_get_bus_info(hw);
351
352 /* Zero out the Multicast HASH table */
Joe Perchesd328bc82010-04-27 00:50:58 +0000353 pr_debug("Zeroing the MTA\n");
Jesse Brandeburg14593362008-07-08 15:52:33 -0700354 for (i = 0; i < IXGB_MC_TBL_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
356
357 /* Zero out the VLAN Filter Table Array */
358 ixgb_clear_vfta(hw);
359
360 /* Zero all of the hardware counters */
361 ixgb_clear_hw_cntrs(hw);
362
363 /* Call a subroutine to setup flow control. */
364 status = ixgb_setup_fc(hw);
365
366 /* 82597EX errata: Call check-for-link in case lane deskew is locked */
367 ixgb_check_for_link(hw);
368
369 return (status);
370}
371
372/******************************************************************************
373 * Initializes receive address filters.
374 *
375 * hw - Struct containing variables accessed by shared code
376 *
377 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700378 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 * the receiver is in reset when the routine is called.
380 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100381static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382ixgb_init_rx_addrs(struct ixgb_hw *hw)
383{
Joe Perches222441a2008-04-03 10:06:25 -0700384 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Joe Perchesd328bc82010-04-27 00:50:58 +0000386 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 /*
389 * If the current mac address is valid, assume it is a software override
390 * to the permanent address.
391 * Otherwise, use the permanent address from the eeprom.
392 */
393 if (!mac_addr_valid(hw->curr_mac_addr)) {
394
395 /* Get the MAC address from the eeprom for later reference */
396 ixgb_get_ee_mac_addr(hw, hw->curr_mac_addr);
397
Joe Perchesd328bc82010-04-27 00:50:58 +0000398 pr_debug("Keeping Permanent MAC Addr = %pM\n",
399 hw->curr_mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 } else {
401
402 /* Setup the receive address. */
Joe Perchesd328bc82010-04-27 00:50:58 +0000403 pr_debug("Overriding MAC Address in RAR[0]\n");
404 pr_debug("New MAC Addr = %pM\n", hw->curr_mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 ixgb_rar_set(hw, hw->curr_mac_addr, 0);
407 }
408
409 /* Zero out the other 15 receive addresses. */
Joe Perchesd328bc82010-04-27 00:50:58 +0000410 pr_debug("Clearing RAR[1-15]\n");
Jesse Brandeburg14593362008-07-08 15:52:33 -0700411 for (i = 1; i < IXGB_RAR_ENTRIES; i++) {
Aaron Saltera3ffab82007-01-06 09:51:41 -0800412 /* Write high reg first to disable the AV bit first */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Aaron Saltera3ffab82007-01-06 09:51:41 -0800414 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
417 return;
418}
419
420/******************************************************************************
421 * Updates the MAC's list of multicast addresses.
422 *
423 * hw - Struct containing variables accessed by shared code
424 * mc_addr_list - the list of new multicast addresses
425 * mc_addr_count - number of addresses
426 * pad - number of bytes between addresses in the list
427 *
428 * The given list replaces any existing list. Clears the last 15 receive
429 * address registers and the multicast table. Uses receive address registers
430 * for the first 15 multicast addresses, and hashes the rest into the
431 * multicast table.
432 *****************************************************************************/
433void
434ixgb_mc_addr_list_update(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700435 u8 *mc_addr_list,
436 u32 mc_addr_count,
437 u32 pad)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Joe Perches222441a2008-04-03 10:06:25 -0700439 u32 hash_value;
440 u32 i;
441 u32 rar_used_count = 1; /* RAR[0] is used for our MAC address */
Joe Perchesd328bc82010-04-27 00:50:58 +0000442 u8 *mca;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Joe Perchesd328bc82010-04-27 00:50:58 +0000444 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /* Set the new number of MC addresses that we are being requested to use. */
447 hw->num_mc_addrs = mc_addr_count;
448
449 /* Clear RAR[1-15] */
Joe Perchesd328bc82010-04-27 00:50:58 +0000450 pr_debug("Clearing RAR[1-15]\n");
Jesse Brandeburg14593362008-07-08 15:52:33 -0700451 for (i = rar_used_count; i < IXGB_RAR_ENTRIES; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
453 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
454 }
455
456 /* Clear the MTA */
Joe Perchesd328bc82010-04-27 00:50:58 +0000457 pr_debug("Clearing MTA\n");
Jesse Brandeburg14593362008-07-08 15:52:33 -0700458 for (i = 0; i < IXGB_MC_TBL_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 /* Add the new addresses */
Joe Perchesd328bc82010-04-27 00:50:58 +0000462 mca = mc_addr_list;
Jesse Brandeburg14593362008-07-08 15:52:33 -0700463 for (i = 0; i < mc_addr_count; i++) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000464 pr_debug("Adding the multicast addresses:\n");
465 pr_debug("MC Addr #%d = %pM\n", i, mca);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 /* Place this multicast address in the RAR if there is room, *
468 * else put it in the MTA
469 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700470 if (rar_used_count < IXGB_RAR_ENTRIES) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000471 ixgb_rar_set(hw, mca, rar_used_count);
472 pr_debug("Added a multicast address to RAR[%d]\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 rar_used_count++;
474 } else {
Joe Perchesd328bc82010-04-27 00:50:58 +0000475 hash_value = ixgb_hash_mc_addr(hw, mca);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Joe Perchesd328bc82010-04-27 00:50:58 +0000477 pr_debug("Hash value = 0x%03X\n", hash_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 ixgb_mta_set(hw, hash_value);
480 }
Joe Perchesd328bc82010-04-27 00:50:58 +0000481
482 mca += IXGB_ETH_LENGTH_OF_ADDRESS + pad;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
484
Joe Perchesd328bc82010-04-27 00:50:58 +0000485 pr_debug("MC Update Complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return;
487}
488
489/******************************************************************************
490 * Hashes an address to determine its location in the multicast table
491 *
492 * hw - Struct containing variables accessed by shared code
493 * mc_addr - the multicast address to hash
494 *
495 * Returns:
496 * The hash value
497 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700498static u32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499ixgb_hash_mc_addr(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700500 u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Joe Perches222441a2008-04-03 10:06:25 -0700502 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Joe Perchesd328bc82010-04-27 00:50:58 +0000504 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 /* The portion of the address that is used for the hash table is
507 * determined by the mc_filter_type setting.
508 */
509 switch (hw->mc_filter_type) {
510 /* [0] [1] [2] [3] [4] [5]
511 * 01 AA 00 12 34 56
512 * LSB MSB - According to H/W docs */
513 case 0:
514 /* [47:36] i.e. 0x563 for above example address */
515 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700516 ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 break;
518 case 1: /* [46:35] i.e. 0xAC6 for above example address */
519 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700520 ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 break;
522 case 2: /* [45:34] i.e. 0x5D8 for above example address */
523 hash_value =
Joe Perches222441a2008-04-03 10:06:25 -0700524 ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 break;
526 case 3: /* [43:32] i.e. 0x634 for above example address */
Joe Perches222441a2008-04-03 10:06:25 -0700527 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529 default:
530 /* Invalid mc_filter_type, what should we do? */
Joe Perchesd328bc82010-04-27 00:50:58 +0000531 pr_debug("MC filter type param set incorrectly\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 ASSERT(0);
533 break;
534 }
535
536 hash_value &= 0xFFF;
537 return (hash_value);
538}
539
540/******************************************************************************
541 * Sets the bit in the multicast table corresponding to the hash value.
542 *
543 * hw - Struct containing variables accessed by shared code
544 * hash_value - Multicast address hash value
545 *****************************************************************************/
546static void
547ixgb_mta_set(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700548 u32 hash_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Joe Perches222441a2008-04-03 10:06:25 -0700550 u32 hash_bit, hash_reg;
551 u32 mta_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 /* The MTA is a register array of 128 32-bit registers.
554 * It is treated like an array of 4096 bits. We want to set
555 * bit BitArray[hash_value]. So we figure out what register
556 * the bit is in, read it, OR in the new bit, then write
557 * back the new value. The register is determined by the
558 * upper 7 bits of the hash value and the bit within that
559 * register are determined by the lower 5 bits of the value.
560 */
561 hash_reg = (hash_value >> 5) & 0x7F;
562 hash_bit = hash_value & 0x1F;
563
564 mta_reg = IXGB_READ_REG_ARRAY(hw, MTA, hash_reg);
565
566 mta_reg |= (1 << hash_bit);
567
568 IXGB_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta_reg);
569
570 return;
571}
572
573/******************************************************************************
574 * Puts an ethernet address into a receive address register.
575 *
576 * hw - Struct containing variables accessed by shared code
577 * addr - Address to put into receive address register
578 * index - Receive address register to write
579 *****************************************************************************/
580void
581ixgb_rar_set(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700582 u8 *addr,
583 u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Joe Perches222441a2008-04-03 10:06:25 -0700585 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Joe Perchesd328bc82010-04-27 00:50:58 +0000587 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 /* HW expects these in little endian so we reverse the byte order
590 * from network order (big endian) to little endian
591 */
Joe Perches222441a2008-04-03 10:06:25 -0700592 rar_low = ((u32) addr[0] |
593 ((u32)addr[1] << 8) |
594 ((u32)addr[2] << 16) |
595 ((u32)addr[3] << 24));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Joe Perches222441a2008-04-03 10:06:25 -0700597 rar_high = ((u32) addr[4] |
598 ((u32)addr[5] << 8) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 IXGB_RAH_AV);
600
601 IXGB_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
602 IXGB_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
603 return;
604}
605
606/******************************************************************************
607 * Writes a value to the specified offset in the VLAN filter table.
608 *
609 * hw - Struct containing variables accessed by shared code
610 * offset - Offset in VLAN filer table to write
611 * value - Value to write into VLAN filter table
612 *****************************************************************************/
613void
614ixgb_write_vfta(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700615 u32 offset,
616 u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
618 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, value);
619 return;
620}
621
622/******************************************************************************
623 * Clears the VLAN filer table
624 *
625 * hw - Struct containing variables accessed by shared code
626 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100627static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628ixgb_clear_vfta(struct ixgb_hw *hw)
629{
Joe Perches222441a2008-04-03 10:06:25 -0700630 u32 offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Jesse Brandeburg14593362008-07-08 15:52:33 -0700632 for (offset = 0; offset < IXGB_VLAN_FILTER_TBL_SIZE; offset++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
634 return;
635}
636
637/******************************************************************************
638 * Configures the flow control settings based on SW configuration.
639 *
640 * hw - Struct containing variables accessed by shared code
641 *****************************************************************************/
642
Joe Perches446490c2008-03-21 11:06:37 -0700643static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644ixgb_setup_fc(struct ixgb_hw *hw)
645{
Joe Perches222441a2008-04-03 10:06:25 -0700646 u32 ctrl_reg;
647 u32 pap_reg = 0; /* by default, assume no pause time */
Joe Perches446490c2008-03-21 11:06:37 -0700648 bool status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Joe Perchesd328bc82010-04-27 00:50:58 +0000650 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 /* Get the current control reg 0 settings */
653 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
654
655 /* Clear the Receive Pause Enable and Transmit Pause Enable bits */
656 ctrl_reg &= ~(IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
657
658 /* The possible values of the "flow_control" parameter are:
659 * 0: Flow control is completely disabled
660 * 1: Rx flow control is enabled (we can receive pause frames
661 * but not send pause frames).
662 * 2: Tx flow control is enabled (we can send pause frames
663 * but we do not support receiving pause frames).
664 * 3: Both Rx and TX flow control (symmetric) are enabled.
665 * other: Invalid.
666 */
667 switch (hw->fc.type) {
668 case ixgb_fc_none: /* 0 */
669 /* Set CMDC bit to disable Rx Flow control */
670 ctrl_reg |= (IXGB_CTRL0_CMDC);
671 break;
672 case ixgb_fc_rx_pause: /* 1 */
673 /* RX Flow control is enabled, and TX Flow control is
674 * disabled.
675 */
676 ctrl_reg |= (IXGB_CTRL0_RPE);
677 break;
678 case ixgb_fc_tx_pause: /* 2 */
679 /* TX Flow control is enabled, and RX Flow control is
680 * disabled, by a software over-ride.
681 */
682 ctrl_reg |= (IXGB_CTRL0_TPE);
683 pap_reg = hw->fc.pause_time;
684 break;
685 case ixgb_fc_full: /* 3 */
686 /* Flow control (both RX and TX) is enabled by a software
687 * over-ride.
688 */
689 ctrl_reg |= (IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
690 pap_reg = hw->fc.pause_time;
691 break;
692 default:
693 /* We should never get here. The value should be 0-3. */
Joe Perchesd328bc82010-04-27 00:50:58 +0000694 pr_debug("Flow control param set incorrectly\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 ASSERT(0);
696 break;
697 }
698
699 /* Write the new settings */
700 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
701
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700702 if (pap_reg != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 IXGB_WRITE_REG(hw, PAP, pap_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 /* Set the flow control receive threshold registers. Normally,
706 * these registers will be set to a default threshold that may be
707 * adjusted later by the driver's runtime code. However, if the
708 * ability to transmit pause frames in not enabled, then these
709 * registers will be set to 0.
710 */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700711 if (!(hw->fc.type & ixgb_fc_tx_pause)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 IXGB_WRITE_REG(hw, FCRTL, 0);
713 IXGB_WRITE_REG(hw, FCRTH, 0);
714 } else {
715 /* We need to set up the Receive Threshold high and low water
716 * marks as well as (optionally) enabling the transmission of XON
717 * frames. */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700718 if (hw->fc.send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 IXGB_WRITE_REG(hw, FCRTL,
720 (hw->fc.low_water | IXGB_FCRTL_XONE));
721 } else {
722 IXGB_WRITE_REG(hw, FCRTL, hw->fc.low_water);
723 }
724 IXGB_WRITE_REG(hw, FCRTH, hw->fc.high_water);
725 }
726 return (status);
727}
728
729/******************************************************************************
730 * Reads a word from a device over the Management Data Interface (MDI) bus.
731 * This interface is used to manage Physical layer devices.
732 *
733 * hw - Struct containing variables accessed by hw code
734 * reg_address - Offset of device register being read.
735 * phy_address - Address of device on MDI.
736 *
737 * Returns: Data word (16 bits) from MDI device.
738 *
739 * The 82597EX has support for several MDI access methods. This routine
740 * uses the new protocol MDI Single Command and Address Operation.
741 * This requires that first an address cycle command is sent, followed by a
742 * read command.
743 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700744static u16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745ixgb_read_phy_reg(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700746 u32 reg_address,
747 u32 phy_address,
748 u32 device_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
Joe Perches222441a2008-04-03 10:06:25 -0700750 u32 i;
751 u32 data;
752 u32 command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
755 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
756 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
757
758 /* Setup and write the address cycle command */
759 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
760 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
761 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
762 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
763
764 IXGB_WRITE_REG(hw, MSCA, command);
765
766 /**************************************************************
767 ** Check every 10 usec to see if the address cycle completed
768 ** The COMMAND bit will clear when the operation is complete.
769 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
770 ** from the CPU Write to the Ready bit assertion.
771 **************************************************************/
772
Jesse Brandeburg14593362008-07-08 15:52:33 -0700773 for (i = 0; i < 10; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 {
775 udelay(10);
776
777 command = IXGB_READ_REG(hw, MSCA);
778
779 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
780 break;
781 }
782
783 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
784
785 /* Address cycle complete, setup and write the read command */
786 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
787 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
788 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
789 (IXGB_MSCA_READ | IXGB_MSCA_MDI_COMMAND));
790
791 IXGB_WRITE_REG(hw, MSCA, command);
792
793 /**************************************************************
794 ** Check every 10 usec to see if the read command completed
795 ** The COMMAND bit will clear when the operation is complete.
796 ** The read may take as long as 64 usecs (we'll wait 100 usecs max)
797 ** from the CPU Write to the Ready bit assertion.
798 **************************************************************/
799
Jesse Brandeburg14593362008-07-08 15:52:33 -0700800 for (i = 0; i < 10; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 {
802 udelay(10);
803
804 command = IXGB_READ_REG(hw, MSCA);
805
806 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
807 break;
808 }
809
810 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
811
812 /* Operation is complete, get the data from the MDIO Read/Write Data
813 * register and return.
814 */
815 data = IXGB_READ_REG(hw, MSRWD);
816 data >>= IXGB_MSRWD_READ_DATA_SHIFT;
Joe Perches222441a2008-04-03 10:06:25 -0700817 return((u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820/******************************************************************************
821 * Writes a word to a device over the Management Data Interface (MDI) bus.
822 * This interface is used to manage Physical layer devices.
823 *
824 * hw - Struct containing variables accessed by hw code
825 * reg_address - Offset of device register being read.
826 * phy_address - Address of device on MDI.
827 * device_type - Also known as the Device ID or DID.
828 * data - 16-bit value to be written
829 *
830 * Returns: void.
831 *
832 * The 82597EX has support for several MDI access methods. This routine
833 * uses the new protocol MDI Single Command and Address Operation.
834 * This requires that first an address cycle command is sent, followed by a
835 * write command.
836 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100837static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838ixgb_write_phy_reg(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700839 u32 reg_address,
840 u32 phy_address,
841 u32 device_type,
842 u16 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Joe Perches222441a2008-04-03 10:06:25 -0700844 u32 i;
845 u32 command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
848 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
849 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
850
851 /* Put the data in the MDIO Read/Write Data register */
Joe Perches222441a2008-04-03 10:06:25 -0700852 IXGB_WRITE_REG(hw, MSRWD, (u32)data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* Setup and write the address cycle command */
855 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
856 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
857 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
858 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
859
860 IXGB_WRITE_REG(hw, MSCA, command);
861
862 /**************************************************************
863 ** Check every 10 usec to see if the address cycle completed
864 ** The COMMAND bit will clear when the operation is complete.
865 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
866 ** from the CPU Write to the Ready bit assertion.
867 **************************************************************/
868
Jesse Brandeburg14593362008-07-08 15:52:33 -0700869 for (i = 0; i < 10; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 {
871 udelay(10);
872
873 command = IXGB_READ_REG(hw, MSCA);
874
875 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
876 break;
877 }
878
879 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
880
881 /* Address cycle complete, setup and write the write command */
882 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
883 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
884 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
885 (IXGB_MSCA_WRITE | IXGB_MSCA_MDI_COMMAND));
886
887 IXGB_WRITE_REG(hw, MSCA, command);
888
889 /**************************************************************
890 ** Check every 10 usec to see if the read command completed
891 ** The COMMAND bit will clear when the operation is complete.
892 ** The write may take as long as 64 usecs (we'll wait 100 usecs max)
893 ** from the CPU Write to the Ready bit assertion.
894 **************************************************************/
895
Jesse Brandeburg14593362008-07-08 15:52:33 -0700896 for (i = 0; i < 10; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 {
898 udelay(10);
899
900 command = IXGB_READ_REG(hw, MSCA);
901
902 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
903 break;
904 }
905
906 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
907
908 /* Operation is complete, return. */
909}
910
911/******************************************************************************
912 * Checks to see if the link status of the hardware has changed.
913 *
914 * hw - Struct containing variables accessed by hw code
915 *
916 * Called by any function that needs to check the link status of the adapter.
917 *****************************************************************************/
918void
919ixgb_check_for_link(struct ixgb_hw *hw)
920{
Joe Perches222441a2008-04-03 10:06:25 -0700921 u32 status_reg;
922 u32 xpcss_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Joe Perchesd328bc82010-04-27 00:50:58 +0000924 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 xpcss_reg = IXGB_READ_REG(hw, XPCSS);
927 status_reg = IXGB_READ_REG(hw, STATUS);
928
929 if ((xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
930 (status_reg & IXGB_STATUS_LU)) {
Joe Perches446490c2008-03-21 11:06:37 -0700931 hw->link_up = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 } else if (!(xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
933 (status_reg & IXGB_STATUS_LU)) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000934 pr_debug("XPCSS Not Aligned while Status:LU is set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 hw->link_up = ixgb_link_reset(hw);
936 } else {
937 /*
938 * 82597EX errata. Since the lane deskew problem may prevent
939 * link, reset the link before reporting link down.
940 */
941 hw->link_up = ixgb_link_reset(hw);
942 }
943 /* Anything else for 10 Gig?? */
944}
945
946/******************************************************************************
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700947 * Check for a bad link condition that may have occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 * The indication is that the RFC / LFC registers may be incrementing
949 * continually. A full adapter reset is required to recover.
950 *
951 * hw - Struct containing variables accessed by hw code
952 *
953 * Called by any function that needs to check the link status of the adapter.
954 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700955bool ixgb_check_for_bad_link(struct ixgb_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Joe Perches222441a2008-04-03 10:06:25 -0700957 u32 newLFC, newRFC;
Joe Perches446490c2008-03-21 11:06:37 -0700958 bool bad_link_returncode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 if (hw->phy_type == ixgb_phy_type_txn17401) {
961 newLFC = IXGB_READ_REG(hw, LFC);
962 newRFC = IXGB_READ_REG(hw, RFC);
963 if ((hw->lastLFC + 250 < newLFC)
964 || (hw->lastRFC + 250 < newRFC)) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000965 pr_debug("BAD LINK! too many LFC/RFC since last check\n");
Joe Perches446490c2008-03-21 11:06:37 -0700966 bad_link_returncode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968 hw->lastLFC = newLFC;
969 hw->lastRFC = newRFC;
970 }
971
972 return bad_link_returncode;
973}
974
975/******************************************************************************
976 * Clears all hardware statistics counters.
977 *
978 * hw - Struct containing variables accessed by shared code
979 *****************************************************************************/
Adrian Bunke9ab1d12005-10-30 16:53:30 +0100980static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981ixgb_clear_hw_cntrs(struct ixgb_hw *hw)
982{
Joe Perches222441a2008-04-03 10:06:25 -0700983 volatile u32 temp_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Joe Perchesd328bc82010-04-27 00:50:58 +0000985 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 /* if we are stopped or resetting exit gracefully */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700988 if (hw->adapter_stopped) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000989 pr_debug("Exiting because the adapter is stopped!!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 return;
991 }
992
993 temp_reg = IXGB_READ_REG(hw, TPRL);
994 temp_reg = IXGB_READ_REG(hw, TPRH);
995 temp_reg = IXGB_READ_REG(hw, GPRCL);
996 temp_reg = IXGB_READ_REG(hw, GPRCH);
997 temp_reg = IXGB_READ_REG(hw, BPRCL);
998 temp_reg = IXGB_READ_REG(hw, BPRCH);
999 temp_reg = IXGB_READ_REG(hw, MPRCL);
1000 temp_reg = IXGB_READ_REG(hw, MPRCH);
1001 temp_reg = IXGB_READ_REG(hw, UPRCL);
1002 temp_reg = IXGB_READ_REG(hw, UPRCH);
1003 temp_reg = IXGB_READ_REG(hw, VPRCL);
1004 temp_reg = IXGB_READ_REG(hw, VPRCH);
1005 temp_reg = IXGB_READ_REG(hw, JPRCL);
1006 temp_reg = IXGB_READ_REG(hw, JPRCH);
1007 temp_reg = IXGB_READ_REG(hw, GORCL);
1008 temp_reg = IXGB_READ_REG(hw, GORCH);
1009 temp_reg = IXGB_READ_REG(hw, TORL);
1010 temp_reg = IXGB_READ_REG(hw, TORH);
1011 temp_reg = IXGB_READ_REG(hw, RNBC);
1012 temp_reg = IXGB_READ_REG(hw, RUC);
1013 temp_reg = IXGB_READ_REG(hw, ROC);
1014 temp_reg = IXGB_READ_REG(hw, RLEC);
1015 temp_reg = IXGB_READ_REG(hw, CRCERRS);
1016 temp_reg = IXGB_READ_REG(hw, ICBC);
1017 temp_reg = IXGB_READ_REG(hw, ECBC);
1018 temp_reg = IXGB_READ_REG(hw, MPC);
1019 temp_reg = IXGB_READ_REG(hw, TPTL);
1020 temp_reg = IXGB_READ_REG(hw, TPTH);
1021 temp_reg = IXGB_READ_REG(hw, GPTCL);
1022 temp_reg = IXGB_READ_REG(hw, GPTCH);
1023 temp_reg = IXGB_READ_REG(hw, BPTCL);
1024 temp_reg = IXGB_READ_REG(hw, BPTCH);
1025 temp_reg = IXGB_READ_REG(hw, MPTCL);
1026 temp_reg = IXGB_READ_REG(hw, MPTCH);
1027 temp_reg = IXGB_READ_REG(hw, UPTCL);
1028 temp_reg = IXGB_READ_REG(hw, UPTCH);
1029 temp_reg = IXGB_READ_REG(hw, VPTCL);
1030 temp_reg = IXGB_READ_REG(hw, VPTCH);
1031 temp_reg = IXGB_READ_REG(hw, JPTCL);
1032 temp_reg = IXGB_READ_REG(hw, JPTCH);
1033 temp_reg = IXGB_READ_REG(hw, GOTCL);
1034 temp_reg = IXGB_READ_REG(hw, GOTCH);
1035 temp_reg = IXGB_READ_REG(hw, TOTL);
1036 temp_reg = IXGB_READ_REG(hw, TOTH);
1037 temp_reg = IXGB_READ_REG(hw, DC);
1038 temp_reg = IXGB_READ_REG(hw, PLT64C);
1039 temp_reg = IXGB_READ_REG(hw, TSCTC);
1040 temp_reg = IXGB_READ_REG(hw, TSCTFC);
1041 temp_reg = IXGB_READ_REG(hw, IBIC);
1042 temp_reg = IXGB_READ_REG(hw, RFC);
1043 temp_reg = IXGB_READ_REG(hw, LFC);
1044 temp_reg = IXGB_READ_REG(hw, PFRC);
1045 temp_reg = IXGB_READ_REG(hw, PFTC);
1046 temp_reg = IXGB_READ_REG(hw, MCFRC);
1047 temp_reg = IXGB_READ_REG(hw, MCFTC);
1048 temp_reg = IXGB_READ_REG(hw, XONRXC);
1049 temp_reg = IXGB_READ_REG(hw, XONTXC);
1050 temp_reg = IXGB_READ_REG(hw, XOFFRXC);
1051 temp_reg = IXGB_READ_REG(hw, XOFFTXC);
1052 temp_reg = IXGB_READ_REG(hw, RJC);
1053 return;
1054}
1055
1056/******************************************************************************
1057 * Turns on the software controllable LED
1058 *
1059 * hw - Struct containing variables accessed by shared code
1060 *****************************************************************************/
1061void
1062ixgb_led_on(struct ixgb_hw *hw)
1063{
Joe Perches222441a2008-04-03 10:06:25 -07001064 u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 /* To turn on the LED, clear software-definable pin 0 (SDP0). */
1067 ctrl0_reg &= ~IXGB_CTRL0_SDP0;
1068 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1069 return;
1070}
1071
1072/******************************************************************************
1073 * Turns off the software controllable LED
1074 *
1075 * hw - Struct containing variables accessed by shared code
1076 *****************************************************************************/
1077void
1078ixgb_led_off(struct ixgb_hw *hw)
1079{
Joe Perches222441a2008-04-03 10:06:25 -07001080 u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 /* To turn off the LED, set software-definable pin 0 (SDP0). */
1083 ctrl0_reg |= IXGB_CTRL0_SDP0;
1084 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1085 return;
1086}
1087
1088/******************************************************************************
1089 * Gets the current PCI bus type, speed, and width of the hardware
1090 *
1091 * hw - Struct containing variables accessed by shared code
1092 *****************************************************************************/
1093static void
1094ixgb_get_bus_info(struct ixgb_hw *hw)
1095{
Joe Perches222441a2008-04-03 10:06:25 -07001096 u32 status_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 status_reg = IXGB_READ_REG(hw, STATUS);
1099
1100 hw->bus.type = (status_reg & IXGB_STATUS_PCIX_MODE) ?
1101 ixgb_bus_type_pcix : ixgb_bus_type_pci;
1102
1103 if (hw->bus.type == ixgb_bus_type_pci) {
1104 hw->bus.speed = (status_reg & IXGB_STATUS_PCI_SPD) ?
1105 ixgb_bus_speed_66 : ixgb_bus_speed_33;
1106 } else {
1107 switch (status_reg & IXGB_STATUS_PCIX_SPD_MASK) {
1108 case IXGB_STATUS_PCIX_SPD_66:
1109 hw->bus.speed = ixgb_bus_speed_66;
1110 break;
1111 case IXGB_STATUS_PCIX_SPD_100:
1112 hw->bus.speed = ixgb_bus_speed_100;
1113 break;
1114 case IXGB_STATUS_PCIX_SPD_133:
1115 hw->bus.speed = ixgb_bus_speed_133;
1116 break;
1117 default:
1118 hw->bus.speed = ixgb_bus_speed_reserved;
1119 break;
1120 }
1121 }
1122
1123 hw->bus.width = (status_reg & IXGB_STATUS_BUS64) ?
1124 ixgb_bus_width_64 : ixgb_bus_width_32;
1125
1126 return;
1127}
1128
1129/******************************************************************************
1130 * Tests a MAC address to ensure it is a valid Individual Address
1131 *
1132 * mac_addr - pointer to MAC address.
1133 *
1134 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -07001135static bool
Joe Perches222441a2008-04-03 10:06:25 -07001136mac_addr_valid(u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Joe Perches446490c2008-03-21 11:06:37 -07001138 bool is_valid = true;
Joe Perchesd328bc82010-04-27 00:50:58 +00001139 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 /* Make sure it is not a multicast address */
Joe Perchesd328bc82010-04-27 00:50:58 +00001142 if (is_multicast_ether_addr(mac_addr)) {
1143 pr_debug("MAC address is multicast\n");
Joe Perches446490c2008-03-21 11:06:37 -07001144 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 /* Not a broadcast address */
Joe Perchesd328bc82010-04-27 00:50:58 +00001147 else if (is_broadcast_ether_addr(mac_addr)) {
1148 pr_debug("MAC address is broadcast\n");
Joe Perches446490c2008-03-21 11:06:37 -07001149 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 }
1151 /* Reject the zero address */
Joe Perchesd328bc82010-04-27 00:50:58 +00001152 else if (is_zero_ether_addr(mac_addr)) {
1153 pr_debug("MAC address is all zeros\n");
Joe Perches446490c2008-03-21 11:06:37 -07001154 is_valid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
1156 return (is_valid);
1157}
1158
1159/******************************************************************************
1160 * Resets the 10GbE link. Waits the settle time and returns the state of
1161 * the link.
1162 *
1163 * hw - Struct containing variables accessed by shared code
1164 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -07001165static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166ixgb_link_reset(struct ixgb_hw *hw)
1167{
Joe Perches446490c2008-03-21 11:06:37 -07001168 bool link_status = false;
Joe Perches222441a2008-04-03 10:06:25 -07001169 u8 wait_retries = MAX_RESET_ITERATIONS;
1170 u8 lrst_retries = MAX_RESET_ITERATIONS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 do {
1173 /* Reset the link */
1174 IXGB_WRITE_REG(hw, CTRL0,
1175 IXGB_READ_REG(hw, CTRL0) | IXGB_CTRL0_LRST);
1176
1177 /* Wait for link-up and lane re-alignment */
1178 do {
1179 udelay(IXGB_DELAY_USECS_AFTER_LINK_RESET);
1180 link_status =
1181 ((IXGB_READ_REG(hw, STATUS) & IXGB_STATUS_LU)
1182 && (IXGB_READ_REG(hw, XPCSS) &
Joe Perches446490c2008-03-21 11:06:37 -07001183 IXGB_XPCSS_ALIGN_STATUS)) ? true : false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 } while (!link_status && --wait_retries);
1185
1186 } while (!link_status && --lrst_retries);
1187
1188 return link_status;
1189}
1190
1191/******************************************************************************
1192 * Resets the 10GbE optics module.
1193 *
1194 * hw - Struct containing variables accessed by shared code
1195 *****************************************************************************/
Stephen Hemminger273dc742007-10-29 10:46:13 -07001196static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197ixgb_optics_reset(struct ixgb_hw *hw)
1198{
1199 if (hw->phy_type == ixgb_phy_type_txn17401) {
Joe Perches222441a2008-04-03 10:06:25 -07001200 u16 mdio_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 ixgb_write_phy_reg(hw,
Ben Hutchingscdbf0eb2009-04-29 08:11:05 +00001203 MDIO_CTRL1,
1204 IXGB_PHY_ADDRESS,
1205 MDIO_MMD_PMAPMD,
1206 MDIO_CTRL1_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Ben Hutchingscdbf0eb2009-04-29 08:11:05 +00001208 mdio_reg = ixgb_read_phy_reg(hw,
1209 MDIO_CTRL1,
1210 IXGB_PHY_ADDRESS,
1211 MDIO_MMD_PMAPMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213
1214 return;
1215}
Matheos Worku8b32e632007-12-14 11:48:36 -08001216
1217/******************************************************************************
1218 * Resets the 10GbE optics module for Sun variant NIC.
1219 *
1220 * hw - Struct containing variables accessed by shared code
1221 *****************************************************************************/
1222
1223#define IXGB_BCM8704_USER_PMD_TX_CTRL_REG 0xC803
1224#define IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL 0x0164
1225#define IXGB_BCM8704_USER_CTRL_REG 0xC800
1226#define IXGB_BCM8704_USER_CTRL_REG_VAL 0x7FBF
1227#define IXGB_BCM8704_USER_DEV3_ADDR 0x0003
1228#define IXGB_SUN_PHY_ADDRESS 0x0000
1229#define IXGB_SUN_PHY_RESET_DELAY 305
1230
1231static void
1232ixgb_optics_reset_bcm(struct ixgb_hw *hw)
1233{
1234 u32 ctrl = IXGB_READ_REG(hw, CTRL0);
1235 ctrl &= ~IXGB_CTRL0_SDP2;
1236 ctrl |= IXGB_CTRL0_SDP3;
1237 IXGB_WRITE_REG(hw, CTRL0, ctrl);
1238
1239 /* SerDes needs extra delay */
1240 msleep(IXGB_SUN_PHY_RESET_DELAY);
1241
1242 /* Broadcom 7408L configuration */
1243 /* Reference clock config */
1244 ixgb_write_phy_reg(hw,
1245 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1246 IXGB_SUN_PHY_ADDRESS,
1247 IXGB_BCM8704_USER_DEV3_ADDR,
1248 IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL);
1249 /* we must read the registers twice */
1250 ixgb_read_phy_reg(hw,
1251 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1252 IXGB_SUN_PHY_ADDRESS,
1253 IXGB_BCM8704_USER_DEV3_ADDR);
1254 ixgb_read_phy_reg(hw,
1255 IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
1256 IXGB_SUN_PHY_ADDRESS,
1257 IXGB_BCM8704_USER_DEV3_ADDR);
1258
1259 ixgb_write_phy_reg(hw,
1260 IXGB_BCM8704_USER_CTRL_REG,
1261 IXGB_SUN_PHY_ADDRESS,
1262 IXGB_BCM8704_USER_DEV3_ADDR,
1263 IXGB_BCM8704_USER_CTRL_REG_VAL);
1264 ixgb_read_phy_reg(hw,
1265 IXGB_BCM8704_USER_CTRL_REG,
1266 IXGB_SUN_PHY_ADDRESS,
1267 IXGB_BCM8704_USER_DEV3_ADDR);
1268 ixgb_read_phy_reg(hw,
1269 IXGB_BCM8704_USER_CTRL_REG,
1270 IXGB_SUN_PHY_ADDRESS,
1271 IXGB_BCM8704_USER_DEV3_ADDR);
1272
1273 /* SerDes needs extra delay */
1274 msleep(IXGB_SUN_PHY_RESET_DELAY);
1275
1276 return;
1277}