1 /*******************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
4 Copyright (c) 2001-2004, Intel Corporation
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 3. Neither the name of the Intel Corporation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
33 *******************************************************************************/
38 * Shared functions for accessing and configuring the adapter
41 #include <dev/ixgb/ixgb_hw.h>
42 #include <dev/ixgb/ixgb_ids.h>
44 /* Local function prototypes */
46 static uint32_t ixgb_hash_mc_addr(struct ixgb_hw *hw,
49 static void ixgb_mta_set(struct ixgb_hw *hw,
52 static void ixgb_get_bus_info(struct ixgb_hw *hw);
54 static boolean_t ixgb_link_reset(struct ixgb_hw *hw);
56 static void ixgb_optics_reset(struct ixgb_hw *hw);
58 static ixgb_phy_type ixgb_identify_phy(struct ixgb_hw *hw);
60 uint32_t ixgb_mac_reset (struct ixgb_hw* hw);
62 uint32_t ixgb_mac_reset (struct ixgb_hw* hw)
66 /* Setup up hardware to known state with RESET.
67 * SWDPIN settings as per Kemano EPS.
69 ctrl_reg = IXGB_CTRL0_RST |
70 IXGB_CTRL0_SDP3_DIR | /* All pins are Output=1 */
74 IXGB_CTRL0_SDP3 | /* Initial value 1101 */
79 /* Workaround for 82597EX reset errata */
80 IXGB_WRITE_REG_IO(hw, CTRL0, ctrl_reg);
82 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
85 /* Delay a few ms just to allow the reset to complete */
86 msec_delay(IXGB_DELAY_AFTER_RESET);
87 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
89 /* Make sure the self-clearing global reset bit did self clear */
90 ASSERT(!(ctrl_reg & IXGB_CTRL0_RST));
93 if (hw->phy_type == ixgb_phy_type_txn17401) {
94 /* Now reset the optics. This reset is required to ensure link with
95 * the Kemano 003 optical module (TXN17401), as per instructions from
98 ixgb_optics_reset(hw);
105 /******************************************************************************
106 * Reset the transmit and receive units; mask and clear all interrupts.
108 * hw - Struct containing variables accessed by shared code
109 *****************************************************************************/
111 ixgb_adapter_stop(struct ixgb_hw *hw)
116 DEBUGFUNC("ixgb_adapter_stop");
118 /* If we are stopped or resetting exit gracefully and wait to be
119 * started again before accessing the hardware.
121 if(hw->adapter_stopped) {
122 DEBUGOUT("Exiting because the adapter is already stopped!!!\n");
126 /* Set the Adapter Stopped flag so other driver functions stop
127 * touching the Hardware.
129 hw->adapter_stopped = TRUE;
131 /* Clear interrupt mask to stop board from generating interrupts */
132 DEBUGOUT("Masking off all interrupts\n");
133 IXGB_WRITE_REG(hw, IMC, 0xFFFFFFFF);
135 /* Disable the Transmit and Receive units. Then delay to allow
136 * any pending transactions to complete before we hit the MAC with
139 IXGB_WRITE_REG(hw, RCTL, IXGB_READ_REG(hw, RCTL) & ~IXGB_RCTL_RXEN);
140 IXGB_WRITE_REG(hw, TCTL, IXGB_READ_REG(hw, TCTL) & ~IXGB_TCTL_TXEN);
141 msec_delay(IXGB_DELAY_BEFORE_RESET);
143 /* Issue a global reset to the MAC. This will reset the chip's
144 * transmit, receive, DMA, and link units. It will not effect
145 * the current PCI configuration. The global reset bit is self-
146 * clearing, and should clear within a microsecond.
148 DEBUGOUT("Issuing a global reset to MAC\n");
150 ctrl_reg = ixgb_mac_reset(hw);
152 /* Clear interrupt mask to stop board from generating interrupts */
153 DEBUGOUT("Masking off all interrupts\n");
154 IXGB_WRITE_REG(hw, IMC, 0xffffffff);
156 /* Clear any pending interrupt events. */
157 icr_reg = IXGB_READ_REG(hw, ICR);
159 return (ctrl_reg & IXGB_CTRL0_RST);
163 /******************************************************************************
164 * Identifies the vendor of the optics module on the adapter. The SR adapters
165 * support two different types of XPAK optics, so it is necessary to determine
166 * which optics are present before applying any optics-specific workarounds.
168 * hw - Struct containing variables accessed by shared code.
170 * Returns: the vendor of the XPAK optics module.
171 *****************************************************************************/
172 static ixgb_xpak_vendor
173 ixgb_identify_xpak_vendor(struct ixgb_hw *hw)
176 uint16_t vendor_name[5];
177 ixgb_xpak_vendor xpak_vendor;
179 DEBUGFUNC("ixgb_identify_xpak_vendor");
181 /* Read the first few bytes of the vendor string from the XPAK NVR
182 * registers. These are standard XENPAK/XPAK registers, so all XPAK
183 * devices should implement them. */
184 for (i = 0; i < 5; i++) {
185 vendor_name[i] = ixgb_read_phy_reg( hw,
186 MDIO_PMA_PMD_XPAK_VENDOR_NAME + i,
191 /* Determine the actual vendor */
192 if (vendor_name[0] == 'I' &&
193 vendor_name[1] == 'N' &&
194 vendor_name[2] == 'T' &&
195 vendor_name[3] == 'E' &&
196 vendor_name[4] == 'L') {
197 xpak_vendor = ixgb_xpak_vendor_intel;
200 xpak_vendor = ixgb_xpak_vendor_infineon;
203 return (xpak_vendor);
207 /******************************************************************************
208 * Determine the physical layer module on the adapter.
210 * hw - Struct containing variables accessed by shared code. The device_id
211 * field must be (correctly) populated before calling this routine.
213 * Returns: the phy type of the adapter.
214 *****************************************************************************/
216 ixgb_identify_phy(struct ixgb_hw *hw)
218 ixgb_phy_type phy_type;
219 ixgb_xpak_vendor xpak_vendor;
221 DEBUGFUNC("ixgb_identify_phy");
223 /* Infer the transceiver/phy type from the device id */
224 switch (hw->device_id) {
225 case IXGB_DEVICE_ID_82597EX:
226 DEBUGOUT("Identified TXN17401 optics\n");
227 phy_type = ixgb_phy_type_txn17401;
230 case IXGB_DEVICE_ID_82597EX_SR:
231 /* The SR adapters carry two different types of XPAK optics
232 * modules; read the vendor identifier to determine the exact
234 xpak_vendor = ixgb_identify_xpak_vendor(hw);
235 if (xpak_vendor == ixgb_xpak_vendor_intel) {
236 DEBUGOUT("Identified TXN17201 optics\n");
237 phy_type = ixgb_phy_type_txn17201;
240 DEBUGOUT("Identified G6005 optics\n");
241 phy_type = ixgb_phy_type_g6005;
247 DEBUGOUT("Unknown physical layer module\n");
248 phy_type = ixgb_phy_type_unknown;
255 /******************************************************************************
256 * Performs basic configuration of the adapter.
258 * hw - Struct containing variables accessed by shared code
260 * Resets the controller.
261 * Reads and validates the EEPROM.
262 * Initializes the receive address registers.
263 * Initializes the multicast table.
264 * Clears all on-chip counters.
265 * Calls routine to setup flow control settings.
266 * Leaves the transmit and receive units disabled and uninitialized.
269 * TRUE if successful,
270 * FALSE if unrecoverable problems were encountered.
271 *****************************************************************************/
273 ixgb_init_hw(struct ixgb_hw *hw)
279 DEBUGFUNC("ixgb_init_hw");
281 /* Issue a global reset to the MAC. This will reset the chip's
282 * transmit, receive, DMA, and link units. It will not effect
283 * the current PCI configuration. The global reset bit is self-
284 * clearing, and should clear within a microsecond.
286 DEBUGOUT("Issuing a global reset to MAC\n");
288 ctrl_reg = ixgb_mac_reset(hw);
290 DEBUGOUT("Issuing an EE reset to MAC\n");
292 /* Workaround for 82597EX reset errata */
293 IXGB_WRITE_REG_IO(hw, CTRL1, IXGB_CTRL1_EE_RST);
295 IXGB_WRITE_REG(hw, CTRL1, IXGB_CTRL1_EE_RST);
298 /* Delay a few ms just to allow the reset to complete */
299 msec_delay(IXGB_DELAY_AFTER_EE_RESET);
301 if (ixgb_get_eeprom_data(hw) == FALSE) {
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 DEBUGOUT("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 DEBUGOUT("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 addresss 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)
363 DEBUGFUNC("ixgb_init_rx_addrs");
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 DEBUGOUT3(" Keeping Permanent MAC Addr =%.2X %.2X %.2X ",
376 hw->curr_mac_addr[0],
377 hw->curr_mac_addr[1],
378 hw->curr_mac_addr[2]);
379 DEBUGOUT3("%.2X %.2X %.2X\n",
380 hw->curr_mac_addr[3],
381 hw->curr_mac_addr[4],
382 hw->curr_mac_addr[5]);
385 /* Setup the receive address. */
386 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
387 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
388 hw->curr_mac_addr[0],
389 hw->curr_mac_addr[1],
390 hw->curr_mac_addr[2]);
391 DEBUGOUT3("%.2X %.2X %.2X\n",
392 hw->curr_mac_addr[3],
393 hw->curr_mac_addr[4],
394 hw->curr_mac_addr[5]);
397 ixgb_rar_set(hw, hw->curr_mac_addr, 0);
400 /* Zero out the other 15 receive addresses. */
401 DEBUGOUT("Clearing RAR[1-15]\n");
402 for(i = 1; i < IXGB_RAR_ENTRIES; i++) {
403 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
404 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
410 /******************************************************************************
411 * Updates the MAC's list of multicast addresses.
413 * hw - Struct containing variables accessed by shared code
414 * mc_addr_list - the list of new multicast addresses
415 * mc_addr_count - number of addresses
416 * pad - number of bytes between addresses in the list
418 * The given list replaces any existing list. Clears the last 15 receive
419 * address registers and the multicast table. Uses receive address registers
420 * for the first 15 multicast addresses, and hashes the rest into the
422 *****************************************************************************/
424 ixgb_mc_addr_list_update(struct ixgb_hw *hw,
425 uint8_t *mc_addr_list,
426 uint32_t mc_addr_count,
431 uint32_t rar_used_count = 1; /* RAR[0] is used for our MAC address */
433 DEBUGFUNC("ixgb_mc_addr_list_update");
435 /* Set the new number of MC addresses that we are being requested to use. */
436 hw->num_mc_addrs = mc_addr_count;
438 /* Clear RAR[1-15] */
439 DEBUGOUT(" Clearing RAR[1-15]\n");
440 for(i = rar_used_count; i < IXGB_RAR_ENTRIES; i++) {
441 IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
442 IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
446 DEBUGOUT(" Clearing MTA\n");
447 for(i = 0; i < IXGB_MC_TBL_SIZE; i++) {
448 IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
451 /* Add the new addresses */
452 for(i = 0; i < mc_addr_count; i++) {
453 DEBUGOUT(" Adding the multicast addresses:\n");
454 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
455 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad)],
456 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) + 1],
457 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) + 2],
458 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) + 3],
459 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) + 4],
460 mc_addr_list[i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad) + 5]);
462 /* Place this multicast address in the RAR if there is room, *
463 * else put it in the MTA
465 if(rar_used_count < IXGB_RAR_ENTRIES) {
467 mc_addr_list + (i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad)),
469 DEBUGOUT1("Added a multicast address to RAR[%d]\n", i);
472 hash_value = ixgb_hash_mc_addr(hw,
474 (i * (IXGB_ETH_LENGTH_OF_ADDRESS + pad)));
476 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
478 ixgb_mta_set(hw, hash_value);
482 DEBUGOUT("MC Update Complete\n");
486 /******************************************************************************
487 * Hashes an address to determine its location in the multicast table
489 * hw - Struct containing variables accessed by shared code
490 * mc_addr - the multicast address to hash
494 *****************************************************************************/
496 ixgb_hash_mc_addr(struct ixgb_hw *hw,
499 uint32_t hash_value = 0;
501 DEBUGFUNC("ixgb_hash_mc_addr");
503 /* The portion of the address that is used for the hash table is
504 * determined by the mc_filter_type setting.
506 switch (hw->mc_filter_type) {
507 /* [0] [1] [2] [3] [4] [5]
509 * LSB MSB - According to H/W docs */
511 /* [47:36] i.e. 0x563 for above example address */
512 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
514 case 1: /* [46:35] i.e. 0xAC6 for above example address */
515 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
517 case 2: /* [45:34] i.e. 0x5D8 for above example address */
518 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
520 case 3: /* [43:32] i.e. 0x634 for above example address */
521 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
524 /* Invalid mc_filter_type, what should we do? */
525 DEBUGOUT("MC filter type param set incorrectly\n");
534 /******************************************************************************
535 * Sets the bit in the multicast table corresponding to the hash value.
537 * hw - Struct containing variables accessed by shared code
538 * hash_value - Multicast address hash value
539 *****************************************************************************/
541 ixgb_mta_set(struct ixgb_hw *hw,
544 uint32_t hash_bit, hash_reg;
547 /* The MTA is a register array of 128 32-bit registers.
548 * It is treated like an array of 4096 bits. We want to set
549 * bit BitArray[hash_value]. So we figure out what register
550 * the bit is in, read it, OR in the new bit, then write
551 * back the new value. The register is determined by the
552 * upper 7 bits of the hash value and the bit within that
553 * register are determined by the lower 5 bits of the value.
555 hash_reg = (hash_value >> 5) & 0x7F;
556 hash_bit = hash_value & 0x1F;
558 mta_reg = IXGB_READ_REG_ARRAY(hw, MTA, hash_reg);
560 mta_reg |= (1 << hash_bit);
562 IXGB_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta_reg);
567 /******************************************************************************
568 * Puts an ethernet address into a receive address register.
570 * hw - Struct containing variables accessed by shared code
571 * addr - Address to put into receive address register
572 * index - Receive address register to write
573 *****************************************************************************/
575 ixgb_rar_set(struct ixgb_hw *hw,
579 uint32_t rar_low, rar_high;
581 DEBUGFUNC("ixgb_rar_set");
583 /* HW expects these in little endian so we reverse the byte order
584 * from network order (big endian) to little endian
586 rar_low = ((uint32_t) addr[0] |
587 ((uint32_t) addr[1] << 8) |
588 ((uint32_t) addr[2] << 16) |
589 ((uint32_t) addr[3] << 24));
591 rar_high = ((uint32_t) addr[4] |
592 ((uint32_t) addr[5] << 8) |
595 IXGB_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
596 IXGB_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
600 /******************************************************************************
601 * Writes a value to the specified offset in the VLAN filter table.
603 * hw - Struct containing variables accessed by shared code
604 * offset - Offset in VLAN filer table to write
605 * value - Value to write into VLAN filter table
606 *****************************************************************************/
608 ixgb_write_vfta(struct ixgb_hw *hw,
612 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, value);
616 /******************************************************************************
617 * Clears the VLAN filer table
619 * hw - Struct containing variables accessed by shared code
620 *****************************************************************************/
622 ixgb_clear_vfta(struct ixgb_hw *hw)
626 for(offset = 0; offset < IXGB_VLAN_FILTER_TBL_SIZE; offset++)
627 IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
631 /******************************************************************************
632 * Configures the flow control settings based on SW configuration.
634 * hw - Struct containing variables accessed by shared code
635 *****************************************************************************/
638 ixgb_setup_fc(struct ixgb_hw *hw)
641 uint32_t pap_reg = 0; /* by default, assume no pause time */
642 boolean_t status = TRUE;
644 DEBUGFUNC("ixgb_setup_fc");
646 /* Get the current control reg 0 settings */
647 ctrl_reg = IXGB_READ_REG(hw, CTRL0);
649 /* Clear the Receive Pause Enable and Transmit Pause Enable bits */
650 ctrl_reg &= ~(IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
652 /* The possible values of the "flow_control" parameter are:
653 * 0: Flow control is completely disabled
654 * 1: Rx flow control is enabled (we can receive pause frames
655 * but not send pause frames).
656 * 2: Tx flow control is enabled (we can send pause frames
657 * but we do not support receiving pause frames).
658 * 3: Both Rx and TX flow control (symmetric) are enabled.
661 switch (hw->fc.type) {
662 case ixgb_fc_none: /* 0 */
663 /* Set CMDC bit to disable Rx Flow control*/
664 ctrl_reg |= (IXGB_CTRL0_CMDC);
666 case ixgb_fc_rx_pause: /* 1 */
667 /* RX Flow control is enabled, and TX Flow control is
670 ctrl_reg |= (IXGB_CTRL0_RPE);
672 case ixgb_fc_tx_pause: /* 2 */
673 /* TX Flow control is enabled, and RX Flow control is
674 * disabled, by a software over-ride.
676 ctrl_reg |= (IXGB_CTRL0_TPE);
677 pap_reg = hw->fc.pause_time;
679 case ixgb_fc_full: /* 3 */
680 /* Flow control (both RX and TX) is enabled by a software
683 ctrl_reg |= (IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
684 pap_reg = hw->fc.pause_time;
687 /* We should never get here. The value should be 0-3. */
688 DEBUGOUT("Flow control param set incorrectly\n");
693 /* Write the new settings */
694 IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
697 IXGB_WRITE_REG(hw, PAP, pap_reg);
700 /* Set the flow control receive threshold registers. Normally,
701 * these registers will be set to a default threshold that may be
702 * adjusted later by the driver's runtime code. However, if the
703 * ability to transmit pause frames in not enabled, then these
704 * registers will be set to 0.
706 if(!(hw->fc.type & ixgb_fc_tx_pause)) {
707 IXGB_WRITE_REG(hw, FCRTL, 0);
708 IXGB_WRITE_REG(hw, FCRTH, 0);
710 /* We need to set up the Receive Threshold high and low water
711 * marks as well as (optionally) enabling the transmission of XON frames.
713 if(hw->fc.send_xon) {
714 IXGB_WRITE_REG(hw, FCRTL,
715 (hw->fc.low_water | IXGB_FCRTL_XONE));
717 IXGB_WRITE_REG(hw, FCRTL, hw->fc.low_water);
719 IXGB_WRITE_REG(hw, FCRTH, hw->fc.high_water);
724 /******************************************************************************
725 * Reads a word from a device over the Management Data Interface (MDI) bus.
726 * This interface is used to manage Physical layer devices.
728 * hw - Struct containing variables accessed by hw code
729 * reg_address - Offset of device register being read.
730 * phy_address - Address of device on MDI.
732 * Returns: Data word (16 bits) from MDI device.
734 * The 82597EX has support for several MDI access methods. This routine
735 * uses the new protocol MDI Single Command and Address Operation.
736 * This requires that first an address cycle command is sent, followed by a
738 *****************************************************************************/
740 ixgb_read_phy_reg(struct ixgb_hw *hw,
741 uint32_t reg_address,
742 uint32_t phy_address,
743 uint32_t device_type)
747 uint32_t command = 0;
749 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
750 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
751 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
753 /* Setup and write the address cycle command */
754 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
755 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
756 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
757 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
759 IXGB_WRITE_REG(hw, MSCA, command);
761 /**************************************************************
762 ** Check every 10 usec to see if the address cycle completed
763 ** The COMMAND bit will clear when the operation is complete.
764 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
765 ** from the CPU Write to the Ready bit assertion.
766 **************************************************************/
768 for (i = 0; i < 10; i++)
772 command = IXGB_READ_REG(hw, MSCA);
774 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
778 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
780 /* Address cycle complete, setup and write the read command */
781 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
782 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
783 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
784 (IXGB_MSCA_READ | IXGB_MSCA_MDI_COMMAND));
786 IXGB_WRITE_REG(hw, MSCA, command);
788 /**************************************************************
789 ** Check every 10 usec to see if the read command completed
790 ** The COMMAND bit will clear when the operation is complete.
791 ** The read may take as long as 64 usecs (we'll wait 100 usecs max)
792 ** from the CPU Write to the Ready bit assertion.
793 **************************************************************/
795 for (i = 0; i < 10; i++)
799 command = IXGB_READ_REG(hw, MSCA);
801 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
805 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
807 /* Operation is complete, get the data from the MDIO Read/Write Data
808 * register and return.
810 data = IXGB_READ_REG(hw, MSRWD);
811 data >>= IXGB_MSRWD_READ_DATA_SHIFT;
812 return((uint16_t) data);
815 /******************************************************************************
816 * Writes a word to a device over the Management Data Interface (MDI) bus.
817 * This interface is used to manage Physical layer devices.
819 * hw - Struct containing variables accessed by hw code
820 * reg_address - Offset of device register being read.
821 * phy_address - Address of device on MDI.
822 * device_type - Also known as the Device ID or DID.
823 * data - 16-bit value to be written
827 * The 82597EX has support for several MDI access methods. This routine
828 * uses the new protocol MDI Single Command and Address Operation.
829 * This requires that first an address cycle command is sent, followed by a
831 *****************************************************************************/
833 ixgb_write_phy_reg(struct ixgb_hw *hw,
834 uint32_t reg_address,
835 uint32_t phy_address,
836 uint32_t device_type,
840 uint32_t command = 0;
842 ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
843 ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
844 ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
846 /* Put the data in the MDIO Read/Write Data register */
847 IXGB_WRITE_REG(hw, MSRWD, (uint32_t)data);
849 /* Setup and write the address cycle command */
850 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
851 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
852 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
853 (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
855 IXGB_WRITE_REG(hw, MSCA, command);
857 /**************************************************************
858 ** Check every 10 usec to see if the address cycle completed
859 ** The COMMAND bit will clear when the operation is complete.
860 ** This may take as long as 64 usecs (we'll wait 100 usecs max)
861 ** from the CPU Write to the Ready bit assertion.
862 **************************************************************/
864 for (i = 0; i < 10; i++)
868 command = IXGB_READ_REG(hw, MSCA);
870 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
874 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
876 /* Address cycle complete, setup and write the write command */
877 command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
878 (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
879 (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
880 (IXGB_MSCA_WRITE | IXGB_MSCA_MDI_COMMAND));
882 IXGB_WRITE_REG(hw, MSCA, command);
884 /**************************************************************
885 ** Check every 10 usec to see if the read command completed
886 ** The COMMAND bit will clear when the operation is complete.
887 ** The write may take as long as 64 usecs (we'll wait 100 usecs max)
888 ** from the CPU Write to the Ready bit assertion.
889 **************************************************************/
891 for (i = 0; i < 10; i++)
895 command = IXGB_READ_REG(hw, MSCA);
897 if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
901 ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
903 /* Operation is complete, return. */
907 /******************************************************************************
908 * Checks to see if the link status of the hardware has changed.
910 * hw - Struct containing variables accessed by hw code
912 * Called by any function that needs to check the link status of the adapter.
913 *****************************************************************************/
915 ixgb_check_for_link(struct ixgb_hw *hw)
920 DEBUGFUNC("ixgb_check_for_link");
922 xpcss_reg = IXGB_READ_REG(hw, XPCSS);
923 status_reg = IXGB_READ_REG(hw, STATUS);
925 if ((xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
926 (status_reg & IXGB_STATUS_LU)) {
928 } else if (!(xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
929 (status_reg & IXGB_STATUS_LU)) {
930 DEBUGOUT("XPCSS Not Aligned while Status:LU is set.\n");
931 hw->link_up = ixgb_link_reset(hw);
934 * 82597EX errata. Since the lane deskew problem may prevent
935 * link, reset the link before reporting link down.
937 hw->link_up = ixgb_link_reset(hw);
939 /* Anything else for 10 Gig?? */
942 /******************************************************************************
943 * Check for a bad link condition that may have occurred.
944 * The indication is that the RFC / LFC registers may be incrementing
945 * continually. A full adapter reset is required to recover.
947 * hw - Struct containing variables accessed by hw code
949 * Called by any function that needs to check the link status of the adapter.
950 *****************************************************************************/
951 boolean_t ixgb_check_for_bad_link(struct ixgb_hw *hw)
953 uint32_t newLFC, newRFC;
954 boolean_t bad_link_returncode = FALSE;
956 if (hw->phy_type == ixgb_phy_type_txn17401) {
957 newLFC = IXGB_READ_REG(hw, LFC);
958 newRFC = IXGB_READ_REG(hw, RFC);
959 if ((hw->lastLFC + 250 < newLFC) || (hw->lastRFC + 250 < newRFC)) {
960 DEBUGOUT("BAD LINK! too many LFC/RFC since last check\n");
961 bad_link_returncode = TRUE;
963 hw->lastLFC = newLFC;
964 hw->lastRFC = newRFC;
967 return bad_link_returncode;
971 /******************************************************************************
972 * Clears all hardware statistics counters.
974 * hw - Struct containing variables accessed by shared code
975 *****************************************************************************/
977 ixgb_clear_hw_cntrs(struct ixgb_hw *hw)
979 volatile uint32_t temp_reg;
981 DEBUGFUNC("ixgb_clear_hw_cntrs");
983 /* if we are stopped or resetting exit gracefully */
984 if(hw->adapter_stopped) {
985 DEBUGOUT("Exiting because the adapter is stopped!!!\n");
989 temp_reg = IXGB_READ_REG(hw, TPRL);
990 temp_reg = IXGB_READ_REG(hw, TPRH);
991 temp_reg = IXGB_READ_REG(hw, GPRCL);
992 temp_reg = IXGB_READ_REG(hw, GPRCH);
993 temp_reg = IXGB_READ_REG(hw, BPRCL);
994 temp_reg = IXGB_READ_REG(hw, BPRCH);
995 temp_reg = IXGB_READ_REG(hw, MPRCL);
996 temp_reg = IXGB_READ_REG(hw, MPRCH);
997 temp_reg = IXGB_READ_REG(hw, UPRCL);
998 temp_reg = IXGB_READ_REG(hw, UPRCH);
999 temp_reg = IXGB_READ_REG(hw, VPRCL);
1000 temp_reg = IXGB_READ_REG(hw, VPRCH);
1001 temp_reg = IXGB_READ_REG(hw, JPRCL);
1002 temp_reg = IXGB_READ_REG(hw, JPRCH);
1003 temp_reg = IXGB_READ_REG(hw, GORCL);
1004 temp_reg = IXGB_READ_REG(hw, GORCH);
1005 temp_reg = IXGB_READ_REG(hw, TORL);
1006 temp_reg = IXGB_READ_REG(hw, TORH);
1007 temp_reg = IXGB_READ_REG(hw, RNBC);
1008 temp_reg = IXGB_READ_REG(hw, RUC);
1009 temp_reg = IXGB_READ_REG(hw, ROC);
1010 temp_reg = IXGB_READ_REG(hw, RLEC);
1011 temp_reg = IXGB_READ_REG(hw, CRCERRS);
1012 temp_reg = IXGB_READ_REG(hw, ICBC);
1013 temp_reg = IXGB_READ_REG(hw, ECBC);
1014 temp_reg = IXGB_READ_REG(hw, MPC);
1015 temp_reg = IXGB_READ_REG(hw, TPTL);
1016 temp_reg = IXGB_READ_REG(hw, TPTH);
1017 temp_reg = IXGB_READ_REG(hw, GPTCL);
1018 temp_reg = IXGB_READ_REG(hw, GPTCH);
1019 temp_reg = IXGB_READ_REG(hw, BPTCL);
1020 temp_reg = IXGB_READ_REG(hw, BPTCH);
1021 temp_reg = IXGB_READ_REG(hw, MPTCL);
1022 temp_reg = IXGB_READ_REG(hw, MPTCH);
1023 temp_reg = IXGB_READ_REG(hw, UPTCL);
1024 temp_reg = IXGB_READ_REG(hw, UPTCH);
1025 temp_reg = IXGB_READ_REG(hw, VPTCL);
1026 temp_reg = IXGB_READ_REG(hw, VPTCH);
1027 temp_reg = IXGB_READ_REG(hw, JPTCL);
1028 temp_reg = IXGB_READ_REG(hw, JPTCH);
1029 temp_reg = IXGB_READ_REG(hw, GOTCL);
1030 temp_reg = IXGB_READ_REG(hw, GOTCH);
1031 temp_reg = IXGB_READ_REG(hw, TOTL);
1032 temp_reg = IXGB_READ_REG(hw, TOTH);
1033 temp_reg = IXGB_READ_REG(hw, DC);
1034 temp_reg = IXGB_READ_REG(hw, PLT64C);
1035 temp_reg = IXGB_READ_REG(hw, TSCTC);
1036 temp_reg = IXGB_READ_REG(hw, TSCTFC);
1037 temp_reg = IXGB_READ_REG(hw, IBIC);
1038 temp_reg = IXGB_READ_REG(hw, RFC);
1039 temp_reg = IXGB_READ_REG(hw, LFC);
1040 temp_reg = IXGB_READ_REG(hw, PFRC);
1041 temp_reg = IXGB_READ_REG(hw, PFTC);
1042 temp_reg = IXGB_READ_REG(hw, MCFRC);
1043 temp_reg = IXGB_READ_REG(hw, MCFTC);
1044 temp_reg = IXGB_READ_REG(hw, XONRXC);
1045 temp_reg = IXGB_READ_REG(hw, XONTXC);
1046 temp_reg = IXGB_READ_REG(hw, XOFFRXC);
1047 temp_reg = IXGB_READ_REG(hw, XOFFTXC);
1048 temp_reg = IXGB_READ_REG(hw, RJC);
1053 /******************************************************************************
1054 * Turns on the software controllable LED
1056 * hw - Struct containing variables accessed by shared code
1057 *****************************************************************************/
1059 ixgb_led_on(struct ixgb_hw *hw)
1061 uint32_t ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
1063 /* To turn on the LED, clear software-definable pin 0 (SDP0). */
1064 ctrl0_reg &= ~IXGB_CTRL0_SDP0;
1065 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1069 /******************************************************************************
1070 * Turns off the software controllable LED
1072 * hw - Struct containing variables accessed by shared code
1073 *****************************************************************************/
1075 ixgb_led_off(struct ixgb_hw *hw)
1077 uint32_t ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
1079 /* To turn off the LED, set software-definable pin 0 (SDP0). */
1080 ctrl0_reg |= IXGB_CTRL0_SDP0;
1081 IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
1086 /******************************************************************************
1087 * Gets the current PCI bus type, speed, and width of the hardware
1089 * hw - Struct containing variables accessed by shared code
1090 *****************************************************************************/
1092 ixgb_get_bus_info(struct ixgb_hw *hw)
1094 uint32_t status_reg;
1096 status_reg = IXGB_READ_REG(hw, STATUS);
1098 hw->bus.type = (status_reg & IXGB_STATUS_PCIX_MODE) ?
1099 ixgb_bus_type_pcix : ixgb_bus_type_pci;
1101 if (hw->bus.type == ixgb_bus_type_pci) {
1102 hw->bus.speed = (status_reg & IXGB_STATUS_PCI_SPD) ?
1103 ixgb_bus_speed_66 : ixgb_bus_speed_33;
1105 switch (status_reg & IXGB_STATUS_PCIX_SPD_MASK) {
1106 case IXGB_STATUS_PCIX_SPD_66:
1107 hw->bus.speed = ixgb_bus_speed_66;
1109 case IXGB_STATUS_PCIX_SPD_100:
1110 hw->bus.speed = ixgb_bus_speed_100;
1112 case IXGB_STATUS_PCIX_SPD_133:
1113 hw->bus.speed = ixgb_bus_speed_133;
1116 hw->bus.speed = ixgb_bus_speed_reserved;
1121 hw->bus.width = (status_reg & IXGB_STATUS_BUS64) ?
1122 ixgb_bus_width_64 : ixgb_bus_width_32;
1129 /******************************************************************************
1130 * Tests a MAC address to ensure it is a valid Individual Address
1132 * mac_addr - pointer to MAC address.
1134 *****************************************************************************/
1136 mac_addr_valid(uint8_t *mac_addr)
1138 boolean_t is_valid = TRUE;
1139 DEBUGFUNC("mac_addr_valid");
1142 /* Make sure it is not a multicast address */
1143 if (IS_MULTICAST(mac_addr)) {
1144 DEBUGOUT("MAC address is multicast\n");
1147 /* Not a broadcast address */
1148 else if (IS_BROADCAST(mac_addr)) {
1149 DEBUGOUT("MAC address is broadcast\n");
1152 /* Reject the zero address */
1153 else if (mac_addr[0] == 0 &&
1159 DEBUGOUT("MAC address is all zeros\n");
1165 /******************************************************************************
1166 * Resets the 10GbE link. Waits the settle time and returns the state of
1169 * hw - Struct containing variables accessed by shared code
1170 *****************************************************************************/
1172 ixgb_link_reset(struct ixgb_hw *hw)
1174 boolean_t link_status = FALSE;
1175 uint8_t wait_retries = MAX_RESET_ITERATIONS;
1176 uint8_t lrst_retries = MAX_RESET_ITERATIONS;
1180 /* Reset the link */
1181 IXGB_WRITE_REG(hw, CTRL0, IXGB_READ_REG(hw, CTRL0) | IXGB_CTRL0_LRST);
1183 /* Wait for link-up and lane re-alignment */
1185 usec_delay(IXGB_DELAY_USECS_AFTER_LINK_RESET);
1186 link_status = ((IXGB_READ_REG(hw, STATUS) & IXGB_STATUS_LU) &&
1187 (IXGB_READ_REG(hw, XPCSS) & IXGB_XPCSS_ALIGN_STATUS)) ?
1189 } while (!link_status && -- wait_retries);
1191 } while (!link_status && --lrst_retries);
1198 /******************************************************************************
1199 * Resets the 10GbE optics module.
1201 * hw - Struct containing variables accessed by shared code
1202 *****************************************************************************/
1204 ixgb_optics_reset(struct ixgb_hw *hw)
1206 if (hw->phy_type == ixgb_phy_type_txn17401) {
1209 ixgb_write_phy_reg( hw,
1213 MDIO_PMA_PMD_CR1_RESET);
1215 mdio_reg = ixgb_read_phy_reg( hw,