1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
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.
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
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
34 #include "ixgbe_phy.h"
36 #define IXGBE_82598_MAX_TX_QUEUES 32
37 #define IXGBE_82598_MAX_RX_QUEUES 64
38 #define IXGBE_82598_RAR_ENTRIES 16
39 #define IXGBE_82598_MC_TBL_SIZE 128
40 #define IXGBE_82598_VFT_TBL_SIZE 128
42 static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw);
43 static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,
45 static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,
46 u32 *speed, bool *autoneg);
47 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw);
48 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw);
49 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,
51 static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
53 bool autoneg_wait_to_complete);
54 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw);
55 static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
57 bool autoneg_wait_to_complete);
58 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);
61 static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
63 hw->mac.num_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
64 hw->mac.num_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
65 hw->mac.mcft_size = IXGBE_82598_MC_TBL_SIZE;
66 hw->mac.vft_size = IXGBE_82598_VFT_TBL_SIZE;
67 hw->mac.num_rar_entries = IXGBE_82598_RAR_ENTRIES;
69 /* PHY ops are filled in by default properly for Fiber only */
70 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
71 hw->mac.ops.setup_link = &ixgbe_setup_copper_link_82598;
72 hw->mac.ops.setup_link_speed = &ixgbe_setup_copper_link_speed_82598;
73 hw->mac.ops.get_link_settings =
74 &ixgbe_get_copper_link_settings_82598;
76 /* Call PHY identify routine to get the phy type */
77 ixgbe_identify_phy(hw);
79 switch (hw->phy.type) {
81 hw->phy.ops.setup_link = &ixgbe_setup_tnx_phy_link;
82 hw->phy.ops.check_link = &ixgbe_check_tnx_phy_link;
83 hw->phy.ops.setup_link_speed =
84 &ixgbe_setup_tnx_phy_link_speed;
95 * ixgbe_get_link_settings_82598 - Determines default link settings
96 * @hw: pointer to hardware structure
97 * @speed: pointer to link speed
98 * @autoneg: boolean auto-negotiation value
100 * Determines the default link settings by reading the AUTOC register.
102 static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,
108 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
110 if (hw->mac.link_settings_loaded) {
111 autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
112 autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
113 autoc_reg |= hw->mac.link_attach_type;
114 autoc_reg |= hw->mac.link_mode_select;
117 switch (autoc_reg & IXGBE_AUTOC_LMS_MASK) {
118 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
119 *speed = IXGBE_LINK_SPEED_1GB_FULL;
123 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
124 *speed = IXGBE_LINK_SPEED_10GB_FULL;
128 case IXGBE_AUTOC_LMS_1G_AN:
129 *speed = IXGBE_LINK_SPEED_1GB_FULL;
133 case IXGBE_AUTOC_LMS_KX4_AN:
134 case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
135 *speed = IXGBE_LINK_SPEED_UNKNOWN;
136 if (autoc_reg & IXGBE_AUTOC_KX4_SUPP)
137 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
138 if (autoc_reg & IXGBE_AUTOC_KX_SUPP)
139 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
144 status = IXGBE_ERR_LINK_SETUP;
152 * ixgbe_get_copper_link_settings_82598 - Determines default link settings
153 * @hw: pointer to hardware structure
154 * @speed: pointer to link speed
155 * @autoneg: boolean auto-negotiation value
157 * Determines the default link settings by reading the AUTOC register.
159 static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,
160 u32 *speed, bool *autoneg)
162 s32 status = IXGBE_ERR_LINK_SETUP;
168 status = ixgbe_read_phy_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
169 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
173 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
174 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
175 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
176 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
183 * ixgbe_get_media_type_82598 - Determines media type
184 * @hw: pointer to hardware structure
186 * Returns the media type (fiber, copper, backplane)
188 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
190 enum ixgbe_media_type media_type;
192 /* Media type for I82598 is based on device ID */
193 switch (hw->device_id) {
194 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
195 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
196 case IXGBE_DEV_ID_82598EB_CX4:
197 case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
198 media_type = ixgbe_media_type_fiber;
200 case IXGBE_DEV_ID_82598AT_DUAL_PORT:
201 media_type = ixgbe_media_type_copper;
204 media_type = ixgbe_media_type_unknown;
212 * ixgbe_setup_mac_link_82598 - Configures MAC link settings
213 * @hw: pointer to hardware structure
215 * Configures link settings based on values in the ixgbe_hw struct.
216 * Restarts the link. Performs autonegotiation if needed.
218 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw)
225 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
227 if (hw->mac.link_settings_loaded) {
228 autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
229 autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
230 autoc_reg |= hw->mac.link_attach_type;
231 autoc_reg |= hw->mac.link_mode_select;
233 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
234 IXGBE_WRITE_FLUSH(hw);
239 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
240 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
242 /* Only poll for autoneg to complete if specified to do so */
243 if (hw->phy.autoneg_wait_to_complete) {
244 if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||
245 hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
246 links_reg = 0; /* Just in case Autoneg time = 0 */
247 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
248 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
249 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
253 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
254 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
256 "Autonegotiation did not complete.\n");
262 * We want to save off the original Flow Control configuration just in
263 * case we get disconnected and then reconnected into a different hub
264 * or switch with different Flow Control capabilities.
266 hw->fc.type = hw->fc.original_type;
267 ixgbe_setup_fc(hw, 0);
269 /* Add delay to filter out noises during initial link setup */
276 * ixgbe_check_mac_link_82598 - Get link/speed status
277 * @hw: pointer to hardware structure
278 * @speed: pointer to link speed
279 * @link_up: true is link is up, false otherwise
281 * Reads the links register to determine if link is up and the current speed
283 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,
288 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
290 if (links_reg & IXGBE_LINKS_UP)
295 if (links_reg & IXGBE_LINKS_SPEED)
296 *speed = IXGBE_LINK_SPEED_10GB_FULL;
298 *speed = IXGBE_LINK_SPEED_1GB_FULL;
304 * ixgbe_setup_mac_link_speed_82598 - Set MAC link speed
305 * @hw: pointer to hardware structure
306 * @speed: new link speed
307 * @autoneg: true if auto-negotiation enabled
308 * @autoneg_wait_to_complete: true if waiting is needed to complete
310 * Set the link speed in the AUTOC register and restarts link.
312 static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,
313 u32 speed, bool autoneg,
314 bool autoneg_wait_to_complete)
318 /* If speed is 10G, then check for CX4 or XAUI. */
319 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
320 (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4)))
321 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
322 else if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && (!autoneg))
323 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
325 /* BX mode - Autonegotiate 1G */
326 if (!(hw->mac.link_attach_type & IXGBE_AUTOC_1G_PMA_PMD))
327 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_AN;
328 else /* KX/KX4 mode */
329 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN_1G_AN;
331 status = IXGBE_ERR_LINK_SETUP;
335 hw->phy.autoneg_wait_to_complete = autoneg_wait_to_complete;
337 hw->mac.link_settings_loaded = true;
339 * Setup and restart the link based on the new values in
340 * ixgbe_hw This will write the AUTOC register based on the new
343 hw->mac.ops.setup_link(hw);
351 * ixgbe_setup_copper_link_82598 - Setup copper link settings
352 * @hw: pointer to hardware structure
354 * Configures link settings based on values in the ixgbe_hw struct.
355 * Restarts the link. Performs autonegotiation if needed. Restart
356 * phy and wait for autonegotiate to finish. Then synchronize the
359 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw)
363 /* Restart autonegotiation on PHY */
364 if (hw->phy.ops.setup_link)
365 status = hw->phy.ops.setup_link(hw);
367 /* Set MAC to KX/KX4 autoneg, which defaultis to Parallel detection */
368 hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
369 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
372 hw->mac.ops.setup_link(hw);
378 * ixgbe_setup_copper_link_speed_82598 - Set the PHY autoneg advertised field
379 * @hw: pointer to hardware structure
380 * @speed: new link speed
381 * @autoneg: true if autonegotiation enabled
382 * @autoneg_wait_to_complete: true if waiting is needed to complete
384 * Sets the link speed in the AUTOC register in the MAC and restarts link.
386 static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
388 bool autoneg_wait_to_complete)
392 /* Setup the PHY according to input speed */
393 if (hw->phy.ops.setup_link_speed)
394 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
395 autoneg_wait_to_complete);
397 /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
398 hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
399 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
402 hw->mac.ops.setup_link(hw);
408 * ixgbe_reset_hw_82598 - Performs hardware reset
409 * @hw: pointer to hardware structure
411 * Resets the hardware by reseting the transmit and receive units, masks and
412 * clears all interrupts, performing a PHY reset, and performing a link (MAC)
415 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
424 /* Call adapter stop to disable tx/rx and clear interrupts */
425 ixgbe_stop_adapter(hw);
428 * Power up the Atlas TX lanes if they are currently powered down.
429 * Atlas TX lanes are powered down for MAC loopback tests, but
430 * they are not automatically restored on reset.
432 ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
433 if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
434 /* Enable TX Atlas so packets can be transmitted again */
435 ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
436 analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
437 ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, analog_val);
439 ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &analog_val);
440 analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
441 ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, analog_val);
443 ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &analog_val);
444 analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
445 ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, analog_val);
447 ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &analog_val);
448 analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
449 ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, analog_val);
456 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
457 * access and verify no pending requests before reset
459 if (ixgbe_disable_pcie_master(hw) != 0) {
460 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
461 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
465 * Issue global reset to the MAC. This needs to be a SW reset.
466 * If link reset is used, it might reset the MAC when mng is using it
468 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
469 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
470 IXGBE_WRITE_FLUSH(hw);
472 /* Poll for reset bit to self-clear indicating reset is complete */
473 for (i = 0; i < 10; i++) {
475 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
476 if (!(ctrl & IXGBE_CTRL_RST))
479 if (ctrl & IXGBE_CTRL_RST) {
480 status = IXGBE_ERR_RESET_FAILED;
481 hw_dbg(hw, "Reset polling failed to complete.\n");
486 gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
487 gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
488 IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
491 * AUTOC register which stores link settings gets cleared
492 * and reloaded from EEPROM after reset. We need to restore
493 * our stored value from init in case SW changed the attach
494 * type or speed. If this is the first time and link settings
495 * have not been stored, store default settings from AUTOC.
497 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
498 if (hw->mac.link_settings_loaded) {
499 autoc &= ~(IXGBE_AUTOC_LMS_ATTACH_TYPE);
500 autoc &= ~(IXGBE_AUTOC_LMS_MASK);
501 autoc |= hw->mac.link_attach_type;
502 autoc |= hw->mac.link_mode_select;
503 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
505 hw->mac.link_attach_type =
506 (autoc & IXGBE_AUTOC_LMS_ATTACH_TYPE);
507 hw->mac.link_mode_select = (autoc & IXGBE_AUTOC_LMS_MASK);
508 hw->mac.link_settings_loaded = true;
511 /* Store the permanent mac address */
512 ixgbe_get_mac_addr(hw, hw->mac.perm_addr);
517 static struct ixgbe_mac_operations mac_ops_82598 = {
518 .reset = &ixgbe_reset_hw_82598,
519 .get_media_type = &ixgbe_get_media_type_82598,
520 .setup_link = &ixgbe_setup_mac_link_82598,
521 .check_link = &ixgbe_check_mac_link_82598,
522 .setup_link_speed = &ixgbe_setup_mac_link_speed_82598,
523 .get_link_settings = &ixgbe_get_link_settings_82598,
526 struct ixgbe_info ixgbe_82598_info = {
527 .mac = ixgbe_mac_82598EB,
528 .get_invariants = &ixgbe_get_invariants_82598,
529 .mac_ops = &mac_ops_82598,