1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2008 Intel Corporation. */
5 * Shared functions for accessing and configuring the adapter
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/pci_ids.h>
14 #include <linux/etherdevice.h>
16 /* Local function prototypes */
18 static u32
ixgb_hash_mc_addr(struct ixgb_hw
*hw
, u8
* mc_addr
);
20 static void ixgb_mta_set(struct ixgb_hw
*hw
, u32 hash_value
);
22 static void ixgb_get_bus_info(struct ixgb_hw
*hw
);
24 static bool ixgb_link_reset(struct ixgb_hw
*hw
);
26 static void ixgb_optics_reset(struct ixgb_hw
*hw
);
28 static void ixgb_optics_reset_bcm(struct ixgb_hw
*hw
);
30 static ixgb_phy_type
ixgb_identify_phy(struct ixgb_hw
*hw
);
32 static void ixgb_clear_hw_cntrs(struct ixgb_hw
*hw
);
34 static void ixgb_clear_vfta(struct ixgb_hw
*hw
);
36 static void ixgb_init_rx_addrs(struct ixgb_hw
*hw
);
38 static u16
ixgb_read_phy_reg(struct ixgb_hw
*hw
,
43 static bool ixgb_setup_fc(struct ixgb_hw
*hw
);
45 static bool mac_addr_valid(u8
*mac_addr
);
47 static u32
ixgb_mac_reset(struct ixgb_hw
*hw
)
51 ctrl_reg
= IXGB_CTRL0_RST
|
52 IXGB_CTRL0_SDP3_DIR
| /* All pins are Output=1 */
56 IXGB_CTRL0_SDP3
| /* Initial value 1101 */
61 /* Workaround for 82597EX reset errata */
62 IXGB_WRITE_REG_IO(hw
, CTRL0
, ctrl_reg
);
64 IXGB_WRITE_REG(hw
, CTRL0
, ctrl_reg
);
67 /* Delay a few ms just to allow the reset to complete */
68 msleep(IXGB_DELAY_AFTER_RESET
);
69 ctrl_reg
= IXGB_READ_REG(hw
, CTRL0
);
71 /* Make sure the self-clearing global reset bit did self clear */
72 ASSERT(!(ctrl_reg
& IXGB_CTRL0_RST
));
75 if (hw
->subsystem_vendor_id
== PCI_VENDOR_ID_SUN
) {
76 ctrl_reg
= /* Enable interrupt from XFP and SerDes */
82 IXGB_WRITE_REG(hw
, CTRL1
, ctrl_reg
);
83 ixgb_optics_reset_bcm(hw
);
86 if (hw
->phy_type
== ixgb_phy_type_txn17401
)
87 ixgb_optics_reset(hw
);
92 /******************************************************************************
93 * Reset the transmit and receive units; mask and clear all interrupts.
95 * hw - Struct containing variables accessed by shared code
96 *****************************************************************************/
98 ixgb_adapter_stop(struct ixgb_hw
*hw
)
105 /* If we are stopped or resetting exit gracefully and wait to be
106 * started again before accessing the hardware.
108 if (hw
->adapter_stopped
) {
109 pr_debug("Exiting because the adapter is already stopped!!!\n");
113 /* Set the Adapter Stopped flag so other driver functions stop
114 * touching the Hardware.
116 hw
->adapter_stopped
= true;
118 /* Clear interrupt mask to stop board from generating interrupts */
119 pr_debug("Masking off all interrupts\n");
120 IXGB_WRITE_REG(hw
, IMC
, 0xFFFFFFFF);
122 /* Disable the Transmit and Receive units. Then delay to allow
123 * any pending transactions to complete before we hit the MAC with
126 IXGB_WRITE_REG(hw
, RCTL
, IXGB_READ_REG(hw
, RCTL
) & ~IXGB_RCTL_RXEN
);
127 IXGB_WRITE_REG(hw
, TCTL
, IXGB_READ_REG(hw
, TCTL
) & ~IXGB_TCTL_TXEN
);
128 IXGB_WRITE_FLUSH(hw
);
129 msleep(IXGB_DELAY_BEFORE_RESET
);
131 /* Issue a global reset to the MAC. This will reset the chip's
132 * transmit, receive, DMA, and link units. It will not effect
133 * the current PCI configuration. The global reset bit is self-
134 * clearing, and should clear within a microsecond.
136 pr_debug("Issuing a global reset to MAC\n");
138 ctrl_reg
= ixgb_mac_reset(hw
);
140 /* Clear interrupt mask to stop board from generating interrupts */
141 pr_debug("Masking off all interrupts\n");
142 IXGB_WRITE_REG(hw
, IMC
, 0xffffffff);
144 /* Clear any pending interrupt events. */
145 icr_reg
= IXGB_READ_REG(hw
, ICR
);
147 return ctrl_reg
& IXGB_CTRL0_RST
;
151 /******************************************************************************
152 * Identifies the vendor of the optics module on the adapter. The SR adapters
153 * support two different types of XPAK optics, so it is necessary to determine
154 * which optics are present before applying any optics-specific workarounds.
156 * hw - Struct containing variables accessed by shared code.
158 * Returns: the vendor of the XPAK optics module.
159 *****************************************************************************/
160 static ixgb_xpak_vendor
161 ixgb_identify_xpak_vendor(struct ixgb_hw
*hw
)
165 ixgb_xpak_vendor xpak_vendor
;
169 /* Read the first few bytes of the vendor string from the XPAK NVR
170 * registers. These are standard XENPAK/XPAK registers, so all XPAK
171 * devices should implement them. */
172 for (i
= 0; i
< 5; i
++) {
173 vendor_name
[i
] = ixgb_read_phy_reg(hw
,
174 MDIO_PMA_PMD_XPAK_VENDOR_NAME
175 + i
, IXGB_PHY_ADDRESS
,
179 /* Determine the actual vendor */
180 if (vendor_name
[0] == 'I' &&
181 vendor_name
[1] == 'N' &&
182 vendor_name
[2] == 'T' &&
183 vendor_name
[3] == 'E' && vendor_name
[4] == 'L') {
184 xpak_vendor
= ixgb_xpak_vendor_intel
;
186 xpak_vendor
= ixgb_xpak_vendor_infineon
;
192 /******************************************************************************
193 * Determine the physical layer module on the adapter.
195 * hw - Struct containing variables accessed by shared code. The device_id
196 * field must be (correctly) populated before calling this routine.
198 * Returns: the phy type of the adapter.
199 *****************************************************************************/
201 ixgb_identify_phy(struct ixgb_hw
*hw
)
203 ixgb_phy_type phy_type
;
204 ixgb_xpak_vendor xpak_vendor
;
208 /* Infer the transceiver/phy type from the device id */
209 switch (hw
->device_id
) {
210 case IXGB_DEVICE_ID_82597EX
:
211 pr_debug("Identified TXN17401 optics\n");
212 phy_type
= ixgb_phy_type_txn17401
;
215 case IXGB_DEVICE_ID_82597EX_SR
:
216 /* The SR adapters carry two different types of XPAK optics
217 * modules; read the vendor identifier to determine the exact
219 xpak_vendor
= ixgb_identify_xpak_vendor(hw
);
220 if (xpak_vendor
== ixgb_xpak_vendor_intel
) {
221 pr_debug("Identified TXN17201 optics\n");
222 phy_type
= ixgb_phy_type_txn17201
;
224 pr_debug("Identified G6005 optics\n");
225 phy_type
= ixgb_phy_type_g6005
;
228 case IXGB_DEVICE_ID_82597EX_LR
:
229 pr_debug("Identified G6104 optics\n");
230 phy_type
= ixgb_phy_type_g6104
;
232 case IXGB_DEVICE_ID_82597EX_CX4
:
233 pr_debug("Identified CX4\n");
234 xpak_vendor
= ixgb_identify_xpak_vendor(hw
);
235 if (xpak_vendor
== ixgb_xpak_vendor_intel
) {
236 pr_debug("Identified TXN17201 optics\n");
237 phy_type
= ixgb_phy_type_txn17201
;
239 pr_debug("Identified G6005 optics\n");
240 phy_type
= ixgb_phy_type_g6005
;
244 pr_debug("Unknown physical layer module\n");
245 phy_type
= ixgb_phy_type_unknown
;
249 /* update phy type for sun specific board */
250 if (hw
->subsystem_vendor_id
== PCI_VENDOR_ID_SUN
)
251 phy_type
= ixgb_phy_type_bcm
;
256 /******************************************************************************
257 * Performs basic configuration of the adapter.
259 * hw - Struct containing variables accessed by shared code
261 * Resets the controller.
262 * Reads and validates the EEPROM.
263 * Initializes the receive address registers.
264 * Initializes the multicast table.
265 * Clears all on-chip counters.
266 * Calls routine to setup flow control settings.
267 * Leaves the transmit and receive units disabled and uninitialized.
270 * true if successful,
271 * false if unrecoverable problems were encountered.
272 *****************************************************************************/
274 ixgb_init_hw(struct ixgb_hw
*hw
)
282 /* Issue a global reset to the MAC. This will reset the chip's
283 * transmit, receive, DMA, and link units. It will not effect
284 * the current PCI configuration. The global reset bit is self-
285 * clearing, and should clear within a microsecond.
287 pr_debug("Issuing a global reset to MAC\n");
289 ctrl_reg
= ixgb_mac_reset(hw
);
291 pr_debug("Issuing an EE reset to MAC\n");
293 /* Workaround for 82597EX reset errata */
294 IXGB_WRITE_REG_IO(hw
, CTRL1
, IXGB_CTRL1_EE_RST
);
296 IXGB_WRITE_REG(hw
, CTRL1
, IXGB_CTRL1_EE_RST
);
299 /* Delay a few ms just to allow the reset to complete */
300 msleep(IXGB_DELAY_AFTER_EE_RESET
);
302 if (!ixgb_get_eeprom_data(hw
))
305 /* Use the device id to determine the type of phy/transceiver. */
306 hw
->device_id
= ixgb_get_ee_device_id(hw
);
307 hw
->phy_type
= ixgb_identify_phy(hw
);
309 /* Setup the receive addresses.
310 * Receive Address Registers (RARs 0 - 15).
312 ixgb_init_rx_addrs(hw
);
315 * Check that a valid MAC address has been set.
316 * If it is not valid, we fail hardware init.
318 if (!mac_addr_valid(hw
->curr_mac_addr
)) {
319 pr_debug("MAC address invalid after ixgb_init_rx_addrs\n");
323 /* tell the routines in this file they can access hardware again */
324 hw
->adapter_stopped
= false;
326 /* Fill in the bus_info structure */
327 ixgb_get_bus_info(hw
);
329 /* Zero out the Multicast HASH table */
330 pr_debug("Zeroing the MTA\n");
331 for (i
= 0; i
< IXGB_MC_TBL_SIZE
; i
++)
332 IXGB_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
334 /* Zero out the VLAN Filter Table Array */
337 /* Zero all of the hardware counters */
338 ixgb_clear_hw_cntrs(hw
);
340 /* Call a subroutine to setup flow control. */
341 status
= ixgb_setup_fc(hw
);
343 /* 82597EX errata: Call check-for-link in case lane deskew is locked */
344 ixgb_check_for_link(hw
);
349 /******************************************************************************
350 * Initializes receive address filters.
352 * hw - Struct containing variables accessed by shared code
354 * Places the MAC address in receive address register 0 and clears the rest
355 * of the receive address registers. Clears the multicast table. Assumes
356 * the receiver is in reset when the routine is called.
357 *****************************************************************************/
359 ixgb_init_rx_addrs(struct ixgb_hw
*hw
)
366 * If the current mac address is valid, assume it is a software override
367 * to the permanent address.
368 * Otherwise, use the permanent address from the eeprom.
370 if (!mac_addr_valid(hw
->curr_mac_addr
)) {
372 /* Get the MAC address from the eeprom for later reference */
373 ixgb_get_ee_mac_addr(hw
, hw
->curr_mac_addr
);
375 pr_debug("Keeping Permanent MAC Addr = %pM\n",
379 /* Setup the receive address. */
380 pr_debug("Overriding MAC Address in RAR[0]\n");
381 pr_debug("New MAC Addr = %pM\n", hw
->curr_mac_addr
);
383 ixgb_rar_set(hw
, hw
->curr_mac_addr
, 0);
386 /* Zero out the other 15 receive addresses. */
387 pr_debug("Clearing RAR[1-15]\n");
388 for (i
= 1; i
< IXGB_RAR_ENTRIES
; i
++) {
389 /* Write high reg first to disable the AV bit first */
390 IXGB_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
391 IXGB_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
395 /******************************************************************************
396 * Updates the MAC's list of multicast addresses.
398 * hw - Struct containing variables accessed by shared code
399 * mc_addr_list - the list of new multicast addresses
400 * mc_addr_count - number of addresses
401 * pad - number of bytes between addresses in the list
403 * The given list replaces any existing list. Clears the last 15 receive
404 * address registers and the multicast table. Uses receive address registers
405 * for the first 15 multicast addresses, and hashes the rest into the
407 *****************************************************************************/
409 ixgb_mc_addr_list_update(struct ixgb_hw
*hw
,
416 u32 rar_used_count
= 1; /* RAR[0] is used for our MAC address */
421 /* Set the new number of MC addresses that we are being requested to use. */
422 hw
->num_mc_addrs
= mc_addr_count
;
424 /* Clear RAR[1-15] */
425 pr_debug("Clearing RAR[1-15]\n");
426 for (i
= rar_used_count
; i
< IXGB_RAR_ENTRIES
; i
++) {
427 IXGB_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
428 IXGB_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
432 pr_debug("Clearing MTA\n");
433 for (i
= 0; i
< IXGB_MC_TBL_SIZE
; i
++)
434 IXGB_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
436 /* Add the new addresses */
438 for (i
= 0; i
< mc_addr_count
; i
++) {
439 pr_debug("Adding the multicast addresses:\n");
440 pr_debug("MC Addr #%d = %pM\n", i
, mca
);
442 /* Place this multicast address in the RAR if there is room, *
443 * else put it in the MTA
445 if (rar_used_count
< IXGB_RAR_ENTRIES
) {
446 ixgb_rar_set(hw
, mca
, rar_used_count
);
447 pr_debug("Added a multicast address to RAR[%d]\n", i
);
450 hash_value
= ixgb_hash_mc_addr(hw
, mca
);
452 pr_debug("Hash value = 0x%03X\n", hash_value
);
454 ixgb_mta_set(hw
, hash_value
);
457 mca
+= ETH_ALEN
+ pad
;
460 pr_debug("MC Update Complete\n");
463 /******************************************************************************
464 * Hashes an address to determine its location in the multicast table
466 * hw - Struct containing variables accessed by shared code
467 * mc_addr - the multicast address to hash
471 *****************************************************************************/
473 ixgb_hash_mc_addr(struct ixgb_hw
*hw
,
480 /* The portion of the address that is used for the hash table is
481 * determined by the mc_filter_type setting.
483 switch (hw
->mc_filter_type
) {
484 /* [0] [1] [2] [3] [4] [5]
486 * LSB MSB - According to H/W docs */
488 /* [47:36] i.e. 0x563 for above example address */
490 ((mc_addr
[4] >> 4) | (((u16
) mc_addr
[5]) << 4));
492 case 1: /* [46:35] i.e. 0xAC6 for above example address */
494 ((mc_addr
[4] >> 3) | (((u16
) mc_addr
[5]) << 5));
496 case 2: /* [45:34] i.e. 0x5D8 for above example address */
498 ((mc_addr
[4] >> 2) | (((u16
) mc_addr
[5]) << 6));
500 case 3: /* [43:32] i.e. 0x634 for above example address */
501 hash_value
= ((mc_addr
[4]) | (((u16
) mc_addr
[5]) << 8));
504 /* Invalid mc_filter_type, what should we do? */
505 pr_debug("MC filter type param set incorrectly\n");
514 /******************************************************************************
515 * Sets the bit in the multicast table corresponding to the hash value.
517 * hw - Struct containing variables accessed by shared code
518 * hash_value - Multicast address hash value
519 *****************************************************************************/
521 ixgb_mta_set(struct ixgb_hw
*hw
,
524 u32 hash_bit
, hash_reg
;
527 /* The MTA is a register array of 128 32-bit registers.
528 * It is treated like an array of 4096 bits. We want to set
529 * bit BitArray[hash_value]. So we figure out what register
530 * the bit is in, read it, OR in the new bit, then write
531 * back the new value. The register is determined by the
532 * upper 7 bits of the hash value and the bit within that
533 * register are determined by the lower 5 bits of the value.
535 hash_reg
= (hash_value
>> 5) & 0x7F;
536 hash_bit
= hash_value
& 0x1F;
538 mta_reg
= IXGB_READ_REG_ARRAY(hw
, MTA
, hash_reg
);
540 mta_reg
|= (1 << hash_bit
);
542 IXGB_WRITE_REG_ARRAY(hw
, MTA
, hash_reg
, mta_reg
);
545 /******************************************************************************
546 * Puts an ethernet address into a receive address register.
548 * hw - Struct containing variables accessed by shared code
549 * addr - Address to put into receive address register
550 * index - Receive address register to write
551 *****************************************************************************/
553 ixgb_rar_set(struct ixgb_hw
*hw
,
557 u32 rar_low
, rar_high
;
561 /* HW expects these in little endian so we reverse the byte order
562 * from network order (big endian) to little endian
564 rar_low
= ((u32
) addr
[0] |
565 ((u32
)addr
[1] << 8) |
566 ((u32
)addr
[2] << 16) |
567 ((u32
)addr
[3] << 24));
569 rar_high
= ((u32
) addr
[4] |
570 ((u32
)addr
[5] << 8) |
573 IXGB_WRITE_REG_ARRAY(hw
, RA
, (index
<< 1), rar_low
);
574 IXGB_WRITE_REG_ARRAY(hw
, RA
, ((index
<< 1) + 1), rar_high
);
577 /******************************************************************************
578 * Writes a value to the specified offset in the VLAN filter table.
580 * hw - Struct containing variables accessed by shared code
581 * offset - Offset in VLAN filer table to write
582 * value - Value to write into VLAN filter table
583 *****************************************************************************/
585 ixgb_write_vfta(struct ixgb_hw
*hw
,
589 IXGB_WRITE_REG_ARRAY(hw
, VFTA
, offset
, value
);
592 /******************************************************************************
593 * Clears the VLAN filer table
595 * hw - Struct containing variables accessed by shared code
596 *****************************************************************************/
598 ixgb_clear_vfta(struct ixgb_hw
*hw
)
602 for (offset
= 0; offset
< IXGB_VLAN_FILTER_TBL_SIZE
; offset
++)
603 IXGB_WRITE_REG_ARRAY(hw
, VFTA
, offset
, 0);
606 /******************************************************************************
607 * Configures the flow control settings based on SW configuration.
609 * hw - Struct containing variables accessed by shared code
610 *****************************************************************************/
613 ixgb_setup_fc(struct ixgb_hw
*hw
)
616 u32 pap_reg
= 0; /* by default, assume no pause time */
621 /* Get the current control reg 0 settings */
622 ctrl_reg
= IXGB_READ_REG(hw
, CTRL0
);
624 /* Clear the Receive Pause Enable and Transmit Pause Enable bits */
625 ctrl_reg
&= ~(IXGB_CTRL0_RPE
| IXGB_CTRL0_TPE
);
627 /* The possible values of the "flow_control" parameter are:
628 * 0: Flow control is completely disabled
629 * 1: Rx flow control is enabled (we can receive pause frames
630 * but not send pause frames).
631 * 2: Tx flow control is enabled (we can send pause frames
632 * but we do not support receiving pause frames).
633 * 3: Both Rx and TX flow control (symmetric) are enabled.
636 switch (hw
->fc
.type
) {
637 case ixgb_fc_none
: /* 0 */
638 /* Set CMDC bit to disable Rx Flow control */
639 ctrl_reg
|= (IXGB_CTRL0_CMDC
);
641 case ixgb_fc_rx_pause
: /* 1 */
642 /* RX Flow control is enabled, and TX Flow control is
645 ctrl_reg
|= (IXGB_CTRL0_RPE
);
647 case ixgb_fc_tx_pause
: /* 2 */
648 /* TX Flow control is enabled, and RX Flow control is
649 * disabled, by a software over-ride.
651 ctrl_reg
|= (IXGB_CTRL0_TPE
);
652 pap_reg
= hw
->fc
.pause_time
;
654 case ixgb_fc_full
: /* 3 */
655 /* Flow control (both RX and TX) is enabled by a software
658 ctrl_reg
|= (IXGB_CTRL0_RPE
| IXGB_CTRL0_TPE
);
659 pap_reg
= hw
->fc
.pause_time
;
662 /* We should never get here. The value should be 0-3. */
663 pr_debug("Flow control param set incorrectly\n");
668 /* Write the new settings */
669 IXGB_WRITE_REG(hw
, CTRL0
, ctrl_reg
);
672 IXGB_WRITE_REG(hw
, PAP
, pap_reg
);
674 /* Set the flow control receive threshold registers. Normally,
675 * these registers will be set to a default threshold that may be
676 * adjusted later by the driver's runtime code. However, if the
677 * ability to transmit pause frames in not enabled, then these
678 * registers will be set to 0.
680 if (!(hw
->fc
.type
& ixgb_fc_tx_pause
)) {
681 IXGB_WRITE_REG(hw
, FCRTL
, 0);
682 IXGB_WRITE_REG(hw
, FCRTH
, 0);
684 /* We need to set up the Receive Threshold high and low water
685 * marks as well as (optionally) enabling the transmission of XON
687 if (hw
->fc
.send_xon
) {
688 IXGB_WRITE_REG(hw
, FCRTL
,
689 (hw
->fc
.low_water
| IXGB_FCRTL_XONE
));
691 IXGB_WRITE_REG(hw
, FCRTL
, hw
->fc
.low_water
);
693 IXGB_WRITE_REG(hw
, FCRTH
, hw
->fc
.high_water
);
698 /******************************************************************************
699 * Reads a word from a device over the Management Data Interface (MDI) bus.
700 * This interface is used to manage Physical layer devices.
702 * hw - Struct containing variables accessed by hw code
703 * reg_address - Offset of device register being read.
704 * phy_address - Address of device on MDI.
706 * Returns: Data word (16 bits) from MDI device.
708 * The 82597EX has support for several MDI access methods. This routine
709 * uses the new protocol MDI Single Command and Address Operation.
710 * This requires that first an address cycle command is sent, followed by a
712 *****************************************************************************/
714 ixgb_read_phy_reg(struct ixgb_hw
*hw
,
723 ASSERT(reg_address
<= IXGB_MAX_PHY_REG_ADDRESS
);
724 ASSERT(phy_address
<= IXGB_MAX_PHY_ADDRESS
);
725 ASSERT(device_type
<= IXGB_MAX_PHY_DEV_TYPE
);
727 /* Setup and write the address cycle command */
728 command
= ((reg_address
<< IXGB_MSCA_NP_ADDR_SHIFT
) |
729 (device_type
<< IXGB_MSCA_DEV_TYPE_SHIFT
) |
730 (phy_address
<< IXGB_MSCA_PHY_ADDR_SHIFT
) |
731 (IXGB_MSCA_ADDR_CYCLE
| IXGB_MSCA_MDI_COMMAND
));
733 IXGB_WRITE_REG(hw
, MSCA
, command
);
735 /**************************************************************
736 ** Check every 10 usec to see if the address cycle completed
737 ** The COMMAND bit will clear when the operation is complete.
738 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
739 ** from the CPU Write to the Ready bit assertion.
740 **************************************************************/
742 for (i
= 0; i
< 10; i
++)
746 command
= IXGB_READ_REG(hw
, MSCA
);
748 if ((command
& IXGB_MSCA_MDI_COMMAND
) == 0)
752 ASSERT((command
& IXGB_MSCA_MDI_COMMAND
) == 0);
754 /* Address cycle complete, setup and write the read command */
755 command
= ((reg_address
<< IXGB_MSCA_NP_ADDR_SHIFT
) |
756 (device_type
<< IXGB_MSCA_DEV_TYPE_SHIFT
) |
757 (phy_address
<< IXGB_MSCA_PHY_ADDR_SHIFT
) |
758 (IXGB_MSCA_READ
| IXGB_MSCA_MDI_COMMAND
));
760 IXGB_WRITE_REG(hw
, MSCA
, command
);
762 /**************************************************************
763 ** Check every 10 usec to see if the read command completed
764 ** The COMMAND bit will clear when the operation is complete.
765 ** The read may take as long as 64 usecs (we'll wait 100 usecs max)
766 ** from the CPU Write to the Ready bit assertion.
767 **************************************************************/
769 for (i
= 0; i
< 10; i
++)
773 command
= IXGB_READ_REG(hw
, MSCA
);
775 if ((command
& IXGB_MSCA_MDI_COMMAND
) == 0)
779 ASSERT((command
& IXGB_MSCA_MDI_COMMAND
) == 0);
781 /* Operation is complete, get the data from the MDIO Read/Write Data
782 * register and return.
784 data
= IXGB_READ_REG(hw
, MSRWD
);
785 data
>>= IXGB_MSRWD_READ_DATA_SHIFT
;
789 /******************************************************************************
790 * Writes a word to a device over the Management Data Interface (MDI) bus.
791 * This interface is used to manage Physical layer devices.
793 * hw - Struct containing variables accessed by hw code
794 * reg_address - Offset of device register being read.
795 * phy_address - Address of device on MDI.
796 * device_type - Also known as the Device ID or DID.
797 * data - 16-bit value to be written
801 * The 82597EX has support for several MDI access methods. This routine
802 * uses the new protocol MDI Single Command and Address Operation.
803 * This requires that first an address cycle command is sent, followed by a
805 *****************************************************************************/
807 ixgb_write_phy_reg(struct ixgb_hw
*hw
,
816 ASSERT(reg_address
<= IXGB_MAX_PHY_REG_ADDRESS
);
817 ASSERT(phy_address
<= IXGB_MAX_PHY_ADDRESS
);
818 ASSERT(device_type
<= IXGB_MAX_PHY_DEV_TYPE
);
820 /* Put the data in the MDIO Read/Write Data register */
821 IXGB_WRITE_REG(hw
, MSRWD
, (u32
)data
);
823 /* Setup and write the address cycle command */
824 command
= ((reg_address
<< IXGB_MSCA_NP_ADDR_SHIFT
) |
825 (device_type
<< IXGB_MSCA_DEV_TYPE_SHIFT
) |
826 (phy_address
<< IXGB_MSCA_PHY_ADDR_SHIFT
) |
827 (IXGB_MSCA_ADDR_CYCLE
| IXGB_MSCA_MDI_COMMAND
));
829 IXGB_WRITE_REG(hw
, MSCA
, command
);
831 /**************************************************************
832 ** Check every 10 usec to see if the address cycle completed
833 ** The COMMAND bit will clear when the operation is complete.
834 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
835 ** from the CPU Write to the Ready bit assertion.
836 **************************************************************/
838 for (i
= 0; i
< 10; i
++)
842 command
= IXGB_READ_REG(hw
, MSCA
);
844 if ((command
& IXGB_MSCA_MDI_COMMAND
) == 0)
848 ASSERT((command
& IXGB_MSCA_MDI_COMMAND
) == 0);
850 /* Address cycle complete, setup and write the write command */
851 command
= ((reg_address
<< IXGB_MSCA_NP_ADDR_SHIFT
) |
852 (device_type
<< IXGB_MSCA_DEV_TYPE_SHIFT
) |
853 (phy_address
<< IXGB_MSCA_PHY_ADDR_SHIFT
) |
854 (IXGB_MSCA_WRITE
| IXGB_MSCA_MDI_COMMAND
));
856 IXGB_WRITE_REG(hw
, MSCA
, command
);
858 /**************************************************************
859 ** Check every 10 usec to see if the read command completed
860 ** The COMMAND bit will clear when the operation is complete.
861 ** The write may take as long as 64 usecs (we'll wait 100 usecs max)
862 ** from the CPU Write to the Ready bit assertion.
863 **************************************************************/
865 for (i
= 0; i
< 10; i
++)
869 command
= IXGB_READ_REG(hw
, MSCA
);
871 if ((command
& IXGB_MSCA_MDI_COMMAND
) == 0)
875 ASSERT((command
& IXGB_MSCA_MDI_COMMAND
) == 0);
877 /* Operation is complete, return. */
880 /******************************************************************************
881 * Checks to see if the link status of the hardware has changed.
883 * hw - Struct containing variables accessed by hw code
885 * Called by any function that needs to check the link status of the adapter.
886 *****************************************************************************/
888 ixgb_check_for_link(struct ixgb_hw
*hw
)
895 xpcss_reg
= IXGB_READ_REG(hw
, XPCSS
);
896 status_reg
= IXGB_READ_REG(hw
, STATUS
);
898 if ((xpcss_reg
& IXGB_XPCSS_ALIGN_STATUS
) &&
899 (status_reg
& IXGB_STATUS_LU
)) {
901 } else if (!(xpcss_reg
& IXGB_XPCSS_ALIGN_STATUS
) &&
902 (status_reg
& IXGB_STATUS_LU
)) {
903 pr_debug("XPCSS Not Aligned while Status:LU is set\n");
904 hw
->link_up
= ixgb_link_reset(hw
);
907 * 82597EX errata. Since the lane deskew problem may prevent
908 * link, reset the link before reporting link down.
910 hw
->link_up
= ixgb_link_reset(hw
);
912 /* Anything else for 10 Gig?? */
915 /******************************************************************************
916 * Check for a bad link condition that may have occurred.
917 * The indication is that the RFC / LFC registers may be incrementing
918 * continually. A full adapter reset is required to recover.
920 * hw - Struct containing variables accessed by hw code
922 * Called by any function that needs to check the link status of the adapter.
923 *****************************************************************************/
924 bool ixgb_check_for_bad_link(struct ixgb_hw
*hw
)
927 bool bad_link_returncode
= false;
929 if (hw
->phy_type
== ixgb_phy_type_txn17401
) {
930 newLFC
= IXGB_READ_REG(hw
, LFC
);
931 newRFC
= IXGB_READ_REG(hw
, RFC
);
932 if ((hw
->lastLFC
+ 250 < newLFC
)
933 || (hw
->lastRFC
+ 250 < newRFC
)) {
934 pr_debug("BAD LINK! too many LFC/RFC since last check\n");
935 bad_link_returncode
= true;
937 hw
->lastLFC
= newLFC
;
938 hw
->lastRFC
= newRFC
;
941 return bad_link_returncode
;
944 /******************************************************************************
945 * Clears all hardware statistics counters.
947 * hw - Struct containing variables accessed by shared code
948 *****************************************************************************/
950 ixgb_clear_hw_cntrs(struct ixgb_hw
*hw
)
952 volatile u32 temp_reg
;
956 /* if we are stopped or resetting exit gracefully */
957 if (hw
->adapter_stopped
) {
958 pr_debug("Exiting because the adapter is stopped!!!\n");
962 temp_reg
= IXGB_READ_REG(hw
, TPRL
);
963 temp_reg
= IXGB_READ_REG(hw
, TPRH
);
964 temp_reg
= IXGB_READ_REG(hw
, GPRCL
);
965 temp_reg
= IXGB_READ_REG(hw
, GPRCH
);
966 temp_reg
= IXGB_READ_REG(hw
, BPRCL
);
967 temp_reg
= IXGB_READ_REG(hw
, BPRCH
);
968 temp_reg
= IXGB_READ_REG(hw
, MPRCL
);
969 temp_reg
= IXGB_READ_REG(hw
, MPRCH
);
970 temp_reg
= IXGB_READ_REG(hw
, UPRCL
);
971 temp_reg
= IXGB_READ_REG(hw
, UPRCH
);
972 temp_reg
= IXGB_READ_REG(hw
, VPRCL
);
973 temp_reg
= IXGB_READ_REG(hw
, VPRCH
);
974 temp_reg
= IXGB_READ_REG(hw
, JPRCL
);
975 temp_reg
= IXGB_READ_REG(hw
, JPRCH
);
976 temp_reg
= IXGB_READ_REG(hw
, GORCL
);
977 temp_reg
= IXGB_READ_REG(hw
, GORCH
);
978 temp_reg
= IXGB_READ_REG(hw
, TORL
);
979 temp_reg
= IXGB_READ_REG(hw
, TORH
);
980 temp_reg
= IXGB_READ_REG(hw
, RNBC
);
981 temp_reg
= IXGB_READ_REG(hw
, RUC
);
982 temp_reg
= IXGB_READ_REG(hw
, ROC
);
983 temp_reg
= IXGB_READ_REG(hw
, RLEC
);
984 temp_reg
= IXGB_READ_REG(hw
, CRCERRS
);
985 temp_reg
= IXGB_READ_REG(hw
, ICBC
);
986 temp_reg
= IXGB_READ_REG(hw
, ECBC
);
987 temp_reg
= IXGB_READ_REG(hw
, MPC
);
988 temp_reg
= IXGB_READ_REG(hw
, TPTL
);
989 temp_reg
= IXGB_READ_REG(hw
, TPTH
);
990 temp_reg
= IXGB_READ_REG(hw
, GPTCL
);
991 temp_reg
= IXGB_READ_REG(hw
, GPTCH
);
992 temp_reg
= IXGB_READ_REG(hw
, BPTCL
);
993 temp_reg
= IXGB_READ_REG(hw
, BPTCH
);
994 temp_reg
= IXGB_READ_REG(hw
, MPTCL
);
995 temp_reg
= IXGB_READ_REG(hw
, MPTCH
);
996 temp_reg
= IXGB_READ_REG(hw
, UPTCL
);
997 temp_reg
= IXGB_READ_REG(hw
, UPTCH
);
998 temp_reg
= IXGB_READ_REG(hw
, VPTCL
);
999 temp_reg
= IXGB_READ_REG(hw
, VPTCH
);
1000 temp_reg
= IXGB_READ_REG(hw
, JPTCL
);
1001 temp_reg
= IXGB_READ_REG(hw
, JPTCH
);
1002 temp_reg
= IXGB_READ_REG(hw
, GOTCL
);
1003 temp_reg
= IXGB_READ_REG(hw
, GOTCH
);
1004 temp_reg
= IXGB_READ_REG(hw
, TOTL
);
1005 temp_reg
= IXGB_READ_REG(hw
, TOTH
);
1006 temp_reg
= IXGB_READ_REG(hw
, DC
);
1007 temp_reg
= IXGB_READ_REG(hw
, PLT64C
);
1008 temp_reg
= IXGB_READ_REG(hw
, TSCTC
);
1009 temp_reg
= IXGB_READ_REG(hw
, TSCTFC
);
1010 temp_reg
= IXGB_READ_REG(hw
, IBIC
);
1011 temp_reg
= IXGB_READ_REG(hw
, RFC
);
1012 temp_reg
= IXGB_READ_REG(hw
, LFC
);
1013 temp_reg
= IXGB_READ_REG(hw
, PFRC
);
1014 temp_reg
= IXGB_READ_REG(hw
, PFTC
);
1015 temp_reg
= IXGB_READ_REG(hw
, MCFRC
);
1016 temp_reg
= IXGB_READ_REG(hw
, MCFTC
);
1017 temp_reg
= IXGB_READ_REG(hw
, XONRXC
);
1018 temp_reg
= IXGB_READ_REG(hw
, XONTXC
);
1019 temp_reg
= IXGB_READ_REG(hw
, XOFFRXC
);
1020 temp_reg
= IXGB_READ_REG(hw
, XOFFTXC
);
1021 temp_reg
= IXGB_READ_REG(hw
, RJC
);
1024 /******************************************************************************
1025 * Turns on the software controllable LED
1027 * hw - Struct containing variables accessed by shared code
1028 *****************************************************************************/
1030 ixgb_led_on(struct ixgb_hw
*hw
)
1032 u32 ctrl0_reg
= IXGB_READ_REG(hw
, CTRL0
);
1034 /* To turn on the LED, clear software-definable pin 0 (SDP0). */
1035 ctrl0_reg
&= ~IXGB_CTRL0_SDP0
;
1036 IXGB_WRITE_REG(hw
, CTRL0
, ctrl0_reg
);
1039 /******************************************************************************
1040 * Turns off the software controllable LED
1042 * hw - Struct containing variables accessed by shared code
1043 *****************************************************************************/
1045 ixgb_led_off(struct ixgb_hw
*hw
)
1047 u32 ctrl0_reg
= IXGB_READ_REG(hw
, CTRL0
);
1049 /* To turn off the LED, set software-definable pin 0 (SDP0). */
1050 ctrl0_reg
|= IXGB_CTRL0_SDP0
;
1051 IXGB_WRITE_REG(hw
, CTRL0
, ctrl0_reg
);
1054 /******************************************************************************
1055 * Gets the current PCI bus type, speed, and width of the hardware
1057 * hw - Struct containing variables accessed by shared code
1058 *****************************************************************************/
1060 ixgb_get_bus_info(struct ixgb_hw
*hw
)
1064 status_reg
= IXGB_READ_REG(hw
, STATUS
);
1066 hw
->bus
.type
= (status_reg
& IXGB_STATUS_PCIX_MODE
) ?
1067 ixgb_bus_type_pcix
: ixgb_bus_type_pci
;
1069 if (hw
->bus
.type
== ixgb_bus_type_pci
) {
1070 hw
->bus
.speed
= (status_reg
& IXGB_STATUS_PCI_SPD
) ?
1071 ixgb_bus_speed_66
: ixgb_bus_speed_33
;
1073 switch (status_reg
& IXGB_STATUS_PCIX_SPD_MASK
) {
1074 case IXGB_STATUS_PCIX_SPD_66
:
1075 hw
->bus
.speed
= ixgb_bus_speed_66
;
1077 case IXGB_STATUS_PCIX_SPD_100
:
1078 hw
->bus
.speed
= ixgb_bus_speed_100
;
1080 case IXGB_STATUS_PCIX_SPD_133
:
1081 hw
->bus
.speed
= ixgb_bus_speed_133
;
1084 hw
->bus
.speed
= ixgb_bus_speed_reserved
;
1089 hw
->bus
.width
= (status_reg
& IXGB_STATUS_BUS64
) ?
1090 ixgb_bus_width_64
: ixgb_bus_width_32
;
1093 /******************************************************************************
1094 * Tests a MAC address to ensure it is a valid Individual Address
1096 * mac_addr - pointer to MAC address.
1098 *****************************************************************************/
1100 mac_addr_valid(u8
*mac_addr
)
1102 bool is_valid
= true;
1105 /* Make sure it is not a multicast address */
1106 if (is_multicast_ether_addr(mac_addr
)) {
1107 pr_debug("MAC address is multicast\n");
1110 /* Not a broadcast address */
1111 else if (is_broadcast_ether_addr(mac_addr
)) {
1112 pr_debug("MAC address is broadcast\n");
1115 /* Reject the zero address */
1116 else if (is_zero_ether_addr(mac_addr
)) {
1117 pr_debug("MAC address is all zeros\n");
1123 /******************************************************************************
1124 * Resets the 10GbE link. Waits the settle time and returns the state of
1127 * hw - Struct containing variables accessed by shared code
1128 *****************************************************************************/
1130 ixgb_link_reset(struct ixgb_hw
*hw
)
1132 bool link_status
= false;
1133 u8 wait_retries
= MAX_RESET_ITERATIONS
;
1134 u8 lrst_retries
= MAX_RESET_ITERATIONS
;
1137 /* Reset the link */
1138 IXGB_WRITE_REG(hw
, CTRL0
,
1139 IXGB_READ_REG(hw
, CTRL0
) | IXGB_CTRL0_LRST
);
1141 /* Wait for link-up and lane re-alignment */
1143 udelay(IXGB_DELAY_USECS_AFTER_LINK_RESET
);
1145 ((IXGB_READ_REG(hw
, STATUS
) & IXGB_STATUS_LU
)
1146 && (IXGB_READ_REG(hw
, XPCSS
) &
1147 IXGB_XPCSS_ALIGN_STATUS
)) ? true : false;
1148 } while (!link_status
&& --wait_retries
);
1150 } while (!link_status
&& --lrst_retries
);
1155 /******************************************************************************
1156 * Resets the 10GbE optics module.
1158 * hw - Struct containing variables accessed by shared code
1159 *****************************************************************************/
1161 ixgb_optics_reset(struct ixgb_hw
*hw
)
1163 if (hw
->phy_type
== ixgb_phy_type_txn17401
) {
1166 ixgb_write_phy_reg(hw
,
1172 mdio_reg
= ixgb_read_phy_reg(hw
,
1179 /******************************************************************************
1180 * Resets the 10GbE optics module for Sun variant NIC.
1182 * hw - Struct containing variables accessed by shared code
1183 *****************************************************************************/
1185 #define IXGB_BCM8704_USER_PMD_TX_CTRL_REG 0xC803
1186 #define IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL 0x0164
1187 #define IXGB_BCM8704_USER_CTRL_REG 0xC800
1188 #define IXGB_BCM8704_USER_CTRL_REG_VAL 0x7FBF
1189 #define IXGB_BCM8704_USER_DEV3_ADDR 0x0003
1190 #define IXGB_SUN_PHY_ADDRESS 0x0000
1191 #define IXGB_SUN_PHY_RESET_DELAY 305
1194 ixgb_optics_reset_bcm(struct ixgb_hw
*hw
)
1196 u32 ctrl
= IXGB_READ_REG(hw
, CTRL0
);
1197 ctrl
&= ~IXGB_CTRL0_SDP2
;
1198 ctrl
|= IXGB_CTRL0_SDP3
;
1199 IXGB_WRITE_REG(hw
, CTRL0
, ctrl
);
1200 IXGB_WRITE_FLUSH(hw
);
1202 /* SerDes needs extra delay */
1203 msleep(IXGB_SUN_PHY_RESET_DELAY
);
1205 /* Broadcom 7408L configuration */
1206 /* Reference clock config */
1207 ixgb_write_phy_reg(hw
,
1208 IXGB_BCM8704_USER_PMD_TX_CTRL_REG
,
1209 IXGB_SUN_PHY_ADDRESS
,
1210 IXGB_BCM8704_USER_DEV3_ADDR
,
1211 IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL
);
1212 /* we must read the registers twice */
1213 ixgb_read_phy_reg(hw
,
1214 IXGB_BCM8704_USER_PMD_TX_CTRL_REG
,
1215 IXGB_SUN_PHY_ADDRESS
,
1216 IXGB_BCM8704_USER_DEV3_ADDR
);
1217 ixgb_read_phy_reg(hw
,
1218 IXGB_BCM8704_USER_PMD_TX_CTRL_REG
,
1219 IXGB_SUN_PHY_ADDRESS
,
1220 IXGB_BCM8704_USER_DEV3_ADDR
);
1222 ixgb_write_phy_reg(hw
,
1223 IXGB_BCM8704_USER_CTRL_REG
,
1224 IXGB_SUN_PHY_ADDRESS
,
1225 IXGB_BCM8704_USER_DEV3_ADDR
,
1226 IXGB_BCM8704_USER_CTRL_REG_VAL
);
1227 ixgb_read_phy_reg(hw
,
1228 IXGB_BCM8704_USER_CTRL_REG
,
1229 IXGB_SUN_PHY_ADDRESS
,
1230 IXGB_BCM8704_USER_DEV3_ADDR
);
1231 ixgb_read_phy_reg(hw
,
1232 IXGB_BCM8704_USER_CTRL_REG
,
1233 IXGB_SUN_PHY_ADDRESS
,
1234 IXGB_BCM8704_USER_DEV3_ADDR
);
1236 /* SerDes needs extra delay */
1237 msleep(IXGB_SUN_PHY_RESET_DELAY
);