17c478bd9Sstevel@tonic-gate /**************************************************************************
27c478bd9Sstevel@tonic-gate Etherboot -  BOOTP/TFTP Bootstrap Program
37c478bd9Sstevel@tonic-gate Inter Pro 1000 for Etherboot
47c478bd9Sstevel@tonic-gate Drivers are port from Intel's Linux driver e1000-4.3.15
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate ***************************************************************************/
77c478bd9Sstevel@tonic-gate /*******************************************************************************
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate 
107c478bd9Sstevel@tonic-gate   Copyright(c) 1999 - 2003 Intel Corporation. All rights reserved.
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate   This program is free software; you can redistribute it and/or modify it
137c478bd9Sstevel@tonic-gate   under the terms of the GNU General Public License as published by the Free
147c478bd9Sstevel@tonic-gate   Software Foundation; either version 2 of the License, or (at your option)
157c478bd9Sstevel@tonic-gate   any later version.
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate   This program is distributed in the hope that it will be useful, but WITHOUT
187c478bd9Sstevel@tonic-gate   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
197c478bd9Sstevel@tonic-gate   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
207c478bd9Sstevel@tonic-gate   more details.
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate   You should have received a copy of the GNU General Public License along with
237c478bd9Sstevel@tonic-gate   this program; if not, write to the Free Software Foundation, Inc., 59
247c478bd9Sstevel@tonic-gate   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate   The full GNU General Public License is included in this distribution in the
277c478bd9Sstevel@tonic-gate   file called LICENSE.
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate   Contact Information:
307c478bd9Sstevel@tonic-gate   Linux NICS <linux.nics@intel.com>
317c478bd9Sstevel@tonic-gate   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate *******************************************************************************/
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  *  Copyright (C) Archway Digital Solutions.
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  *  written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
387c478bd9Sstevel@tonic-gate  *  2/9/2002
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  *  Copyright (C) Linux Networx.
417c478bd9Sstevel@tonic-gate  *  Massive upgrade to work with the new intel gigabit NICs.
427c478bd9Sstevel@tonic-gate  *  <ebiederman at lnxi dot com>
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  *  Support for 82541ei & 82547ei chips from Intel's Linux driver 5.1.13 added by
457c478bd9Sstevel@tonic-gate  *  Georg Baum <gbaum@users.sf.net>, sponsored by PetaMem GmbH and linkLINE Communications, Inc.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  *  01/2004: Updated to Linux driver 5.2.22 by Georg Baum <gbaum@users.sf.net>
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /* to get some global routines like printf */
517c478bd9Sstevel@tonic-gate #include "etherboot.h"
527c478bd9Sstevel@tonic-gate /* to get the interface to the body of the program */
537c478bd9Sstevel@tonic-gate #include "nic.h"
547c478bd9Sstevel@tonic-gate /* to get the PCI support functions, if this is a PCI NIC */
557c478bd9Sstevel@tonic-gate #include "pci.h"
567c478bd9Sstevel@tonic-gate #include "timer.h"
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef unsigned char *dma_addr_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef enum {
617c478bd9Sstevel@tonic-gate 	FALSE = 0,
627c478bd9Sstevel@tonic-gate 	TRUE = 1
637c478bd9Sstevel@tonic-gate } boolean_t;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define DEBUG 0
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* Some pieces of code are disabled with #if 0 ... #endif.
697c478bd9Sstevel@tonic-gate  * They are not deleted to show where the etherboot driver differs
707c478bd9Sstevel@tonic-gate  * from the linux driver below the function level.
717c478bd9Sstevel@tonic-gate  * Some member variables of the hw struct have been eliminated
727c478bd9Sstevel@tonic-gate  * and the corresponding inplace checks inserted instead.
737c478bd9Sstevel@tonic-gate  * Pieces such as LED handling that we definitely don't need are deleted.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  * The following defines should not be needed normally,
767c478bd9Sstevel@tonic-gate  * but may be helpful for debugging purposes. */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /* Define this if you want to program the transmission control register
797c478bd9Sstevel@tonic-gate  * the way the Linux driver does it. */
807c478bd9Sstevel@tonic-gate #undef LINUX_DRIVER_TCTL
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /* Define this to behave more like the Linux driver. */
837c478bd9Sstevel@tonic-gate #undef LINUX_DRIVER
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #include "e1000_hw.h"
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /* NIC specific static variables go here */
887c478bd9Sstevel@tonic-gate static struct e1000_hw hw;
897c478bd9Sstevel@tonic-gate static char tx_pool[128 + 16];
907c478bd9Sstevel@tonic-gate static char rx_pool[128 + 16];
917c478bd9Sstevel@tonic-gate static char packet[2096];
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate static struct e1000_tx_desc *tx_base;
947c478bd9Sstevel@tonic-gate static struct e1000_rx_desc *rx_base;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate static int tx_tail;
977c478bd9Sstevel@tonic-gate static int rx_tail, rx_last;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* Function forward declarations */
1007c478bd9Sstevel@tonic-gate static int e1000_setup_link(struct e1000_hw *hw);
1017c478bd9Sstevel@tonic-gate static int e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
1027c478bd9Sstevel@tonic-gate static int e1000_setup_copper_link(struct e1000_hw *hw);
1037c478bd9Sstevel@tonic-gate static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
1047c478bd9Sstevel@tonic-gate static void e1000_config_collision_dist(struct e1000_hw *hw);
1057c478bd9Sstevel@tonic-gate static int e1000_config_mac_to_phy(struct e1000_hw *hw);
1067c478bd9Sstevel@tonic-gate static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
1077c478bd9Sstevel@tonic-gate static int e1000_check_for_link(struct e1000_hw *hw);
1087c478bd9Sstevel@tonic-gate static int e1000_wait_autoneg(struct e1000_hw *hw);
1097c478bd9Sstevel@tonic-gate static void e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed, uint16_t *duplex);
1107c478bd9Sstevel@tonic-gate static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy_data);
1117c478bd9Sstevel@tonic-gate static int e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy_data);
1127c478bd9Sstevel@tonic-gate static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data);
1137c478bd9Sstevel@tonic-gate static int e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data);
1147c478bd9Sstevel@tonic-gate static void e1000_phy_hw_reset(struct e1000_hw *hw);
1157c478bd9Sstevel@tonic-gate static int e1000_phy_reset(struct e1000_hw *hw);
1167c478bd9Sstevel@tonic-gate static int e1000_detect_gig_phy(struct e1000_hw *hw);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /* Printing macros... */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define E1000_ERR(args...) printf("e1000: " args)
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #if DEBUG >= 3
1237c478bd9Sstevel@tonic-gate #define E1000_DBG(args...) printf("e1000: " args)
1247c478bd9Sstevel@tonic-gate #else
1257c478bd9Sstevel@tonic-gate #define E1000_DBG(args...)
1267c478bd9Sstevel@tonic-gate #endif
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define MSGOUT(S, A, B)     printk(S "\n", A, B)
1297c478bd9Sstevel@tonic-gate #if DEBUG >= 2
1307c478bd9Sstevel@tonic-gate #define DEBUGFUNC(F)        DEBUGOUT(F "\n");
1317c478bd9Sstevel@tonic-gate #else
1327c478bd9Sstevel@tonic-gate #define DEBUGFUNC(F)
1337c478bd9Sstevel@tonic-gate #endif
1347c478bd9Sstevel@tonic-gate #if DEBUG >= 1
1357c478bd9Sstevel@tonic-gate #define DEBUGOUT(S) printf(S)
1367c478bd9Sstevel@tonic-gate #define DEBUGOUT1(S,A) printf(S,A)
1377c478bd9Sstevel@tonic-gate #define DEBUGOUT2(S,A,B) printf(S,A,B)
1387c478bd9Sstevel@tonic-gate #define DEBUGOUT3(S,A,B,C) printf(S,A,B,C)
1397c478bd9Sstevel@tonic-gate #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S,A,B,C,D,E,F,G)
1407c478bd9Sstevel@tonic-gate #else
1417c478bd9Sstevel@tonic-gate #define DEBUGOUT(S)
1427c478bd9Sstevel@tonic-gate #define DEBUGOUT1(S,A)
1437c478bd9Sstevel@tonic-gate #define DEBUGOUT2(S,A,B)
1447c478bd9Sstevel@tonic-gate #define DEBUGOUT3(S,A,B,C)
1457c478bd9Sstevel@tonic-gate #define DEBUGOUT7(S,A,B,C,D,E,F,G)
1467c478bd9Sstevel@tonic-gate #endif
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define E1000_WRITE_REG(a, reg, value) ( \
1497c478bd9Sstevel@tonic-gate     ((a)->mac_type >= e1000_82543) ? \
1507c478bd9Sstevel@tonic-gate         (writel((value), ((a)->hw_addr + E1000_##reg))) : \
1517c478bd9Sstevel@tonic-gate         (writel((value), ((a)->hw_addr + E1000_82542_##reg))))
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #define E1000_READ_REG(a, reg) ( \
1547c478bd9Sstevel@tonic-gate     ((a)->mac_type >= e1000_82543) ? \
1557c478bd9Sstevel@tonic-gate         readl((a)->hw_addr + E1000_##reg) : \
1567c478bd9Sstevel@tonic-gate         readl((a)->hw_addr + E1000_82542_##reg))
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) ( \
1597c478bd9Sstevel@tonic-gate     ((a)->mac_type >= e1000_82543) ? \
1607c478bd9Sstevel@tonic-gate         writel((value), ((a)->hw_addr + E1000_##reg + ((offset) << 2))) : \
1617c478bd9Sstevel@tonic-gate         writel((value), ((a)->hw_addr + E1000_82542_##reg + ((offset) << 2))))
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #define E1000_READ_REG_ARRAY(a, reg, offset) ( \
1647c478bd9Sstevel@tonic-gate     ((a)->mac_type >= e1000_82543) ? \
1657c478bd9Sstevel@tonic-gate         readl((a)->hw_addr + E1000_##reg + ((offset) << 2)) : \
1667c478bd9Sstevel@tonic-gate         readl((a)->hw_addr + E1000_82542_##reg + ((offset) << 2)))
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #define E1000_WRITE_FLUSH(a) {uint32_t x; x = E1000_READ_REG(a, STATUS);}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate uint32_t
e1000_io_read(struct e1000_hw * hw __unused,uint32_t port)1717c478bd9Sstevel@tonic-gate e1000_io_read(struct e1000_hw *hw __unused, uint32_t port)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate         return inl(port);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate void
e1000_io_write(struct e1000_hw * hw __unused,uint32_t port,uint32_t value)1777c478bd9Sstevel@tonic-gate e1000_io_write(struct e1000_hw *hw __unused, uint32_t port, uint32_t value)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate         outl(value, port);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate 
e1000_pci_set_mwi(struct e1000_hw * hw)1827c478bd9Sstevel@tonic-gate static inline void e1000_pci_set_mwi(struct e1000_hw *hw)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate 
e1000_pci_clear_mwi(struct e1000_hw * hw)1877c478bd9Sstevel@tonic-gate static inline void e1000_pci_clear_mwi(struct e1000_hw *hw)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate 	pci_write_config_word(hw->pdev, PCI_COMMAND,
1907c478bd9Sstevel@tonic-gate 			      hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /******************************************************************************
1947c478bd9Sstevel@tonic-gate  * Raises the EEPROM's clock input.
1957c478bd9Sstevel@tonic-gate  *
1967c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
1977c478bd9Sstevel@tonic-gate  * eecd - EECD's current value
1987c478bd9Sstevel@tonic-gate  *****************************************************************************/
1997c478bd9Sstevel@tonic-gate static void
e1000_raise_ee_clk(struct e1000_hw * hw,uint32_t * eecd)2007c478bd9Sstevel@tonic-gate e1000_raise_ee_clk(struct e1000_hw *hw,
2017c478bd9Sstevel@tonic-gate                    uint32_t *eecd)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate 	/* Raise the clock input to the EEPROM (by setting the SK bit), and then
2047c478bd9Sstevel@tonic-gate 	 * wait <delay> microseconds.
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate 	*eecd = *eecd | E1000_EECD_SK;
2077c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, EECD, *eecd);
2087c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
2097c478bd9Sstevel@tonic-gate 	udelay(hw->eeprom.delay_usec);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /******************************************************************************
2137c478bd9Sstevel@tonic-gate  * Lowers the EEPROM's clock input.
2147c478bd9Sstevel@tonic-gate  *
2157c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
2167c478bd9Sstevel@tonic-gate  * eecd - EECD's current value
2177c478bd9Sstevel@tonic-gate  *****************************************************************************/
2187c478bd9Sstevel@tonic-gate static void
e1000_lower_ee_clk(struct e1000_hw * hw,uint32_t * eecd)2197c478bd9Sstevel@tonic-gate e1000_lower_ee_clk(struct e1000_hw *hw,
2207c478bd9Sstevel@tonic-gate                    uint32_t *eecd)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate 	/* Lower the clock input to the EEPROM (by clearing the SK bit), and then
2237c478bd9Sstevel@tonic-gate 	 * wait 50 microseconds.
2247c478bd9Sstevel@tonic-gate 	 */
2257c478bd9Sstevel@tonic-gate 	*eecd = *eecd & ~E1000_EECD_SK;
2267c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, EECD, *eecd);
2277c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
2287c478bd9Sstevel@tonic-gate 	udelay(hw->eeprom.delay_usec);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /******************************************************************************
2327c478bd9Sstevel@tonic-gate  * Shift data bits out to the EEPROM.
2337c478bd9Sstevel@tonic-gate  *
2347c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
2357c478bd9Sstevel@tonic-gate  * data - data to send to the EEPROM
2367c478bd9Sstevel@tonic-gate  * count - number of bits to shift out
2377c478bd9Sstevel@tonic-gate  *****************************************************************************/
2387c478bd9Sstevel@tonic-gate static void
e1000_shift_out_ee_bits(struct e1000_hw * hw,uint16_t data,uint16_t count)2397c478bd9Sstevel@tonic-gate e1000_shift_out_ee_bits(struct e1000_hw *hw,
2407c478bd9Sstevel@tonic-gate                         uint16_t data,
2417c478bd9Sstevel@tonic-gate                         uint16_t count)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate 	struct e1000_eeprom_info *eeprom = &hw->eeprom;
2447c478bd9Sstevel@tonic-gate 	uint32_t eecd;
2457c478bd9Sstevel@tonic-gate 	uint32_t mask;
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	/* We need to shift "count" bits out to the EEPROM. So, value in the
2487c478bd9Sstevel@tonic-gate 	 * "data" parameter will be shifted out to the EEPROM one bit at a time.
2497c478bd9Sstevel@tonic-gate 	 * In order to do this, "data" must be broken down into bits.
2507c478bd9Sstevel@tonic-gate 	 */
2517c478bd9Sstevel@tonic-gate 	mask = 0x01 << (count - 1);
2527c478bd9Sstevel@tonic-gate 	eecd = E1000_READ_REG(hw, EECD);
2537c478bd9Sstevel@tonic-gate 	if (eeprom->type == e1000_eeprom_microwire) {
2547c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_DO;
2557c478bd9Sstevel@tonic-gate 	} else if (eeprom->type == e1000_eeprom_spi) {
2567c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_DO;
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate 	do {
2597c478bd9Sstevel@tonic-gate 		/* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
2607c478bd9Sstevel@tonic-gate 		 * and then raising and then lowering the clock (the SK bit controls
2617c478bd9Sstevel@tonic-gate 		 * the clock input to the EEPROM).  A "0" is shifted out to the EEPROM
2627c478bd9Sstevel@tonic-gate 		 * by setting "DI" to "0" and then raising and then lowering the clock.
2637c478bd9Sstevel@tonic-gate 		 */
2647c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_DI;
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 		if(data & mask)
2677c478bd9Sstevel@tonic-gate 			eecd |= E1000_EECD_DI;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
2707c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 		e1000_raise_ee_clk(hw, &eecd);
2757c478bd9Sstevel@tonic-gate 		e1000_lower_ee_clk(hw, &eecd);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		mask = mask >> 1;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	} while(mask);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	/* We leave the "DI" bit set to "0" when we leave this routine. */
2827c478bd9Sstevel@tonic-gate 	eecd &= ~E1000_EECD_DI;
2837c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, EECD, eecd);
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate /******************************************************************************
2877c478bd9Sstevel@tonic-gate  * Shift data bits in from the EEPROM
2887c478bd9Sstevel@tonic-gate  *
2897c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
2907c478bd9Sstevel@tonic-gate  *****************************************************************************/
2917c478bd9Sstevel@tonic-gate static uint16_t
e1000_shift_in_ee_bits(struct e1000_hw * hw,uint16_t count)2927c478bd9Sstevel@tonic-gate e1000_shift_in_ee_bits(struct e1000_hw *hw,
2937c478bd9Sstevel@tonic-gate                        uint16_t count)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate 	uint32_t eecd;
2967c478bd9Sstevel@tonic-gate 	uint32_t i;
2977c478bd9Sstevel@tonic-gate 	uint16_t data;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	/* In order to read a register from the EEPROM, we need to shift 'count'
3007c478bd9Sstevel@tonic-gate 	 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3017c478bd9Sstevel@tonic-gate 	 * input to the EEPROM (setting the SK bit), and then reading the value of
3027c478bd9Sstevel@tonic-gate 	 * the "DO" bit.  During this "shifting in" process the "DI" bit should
3037c478bd9Sstevel@tonic-gate 	 * always be clear.
3047c478bd9Sstevel@tonic-gate 	 */
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	eecd = E1000_READ_REG(hw, EECD);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3097c478bd9Sstevel@tonic-gate 	data = 0;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	for(i = 0; i < count; i++) {
3127c478bd9Sstevel@tonic-gate 		data = data << 1;
3137c478bd9Sstevel@tonic-gate 		e1000_raise_ee_clk(hw, &eecd);
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 		eecd = E1000_READ_REG(hw, EECD);
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 		eecd &= ~(E1000_EECD_DI);
3187c478bd9Sstevel@tonic-gate 		if(eecd & E1000_EECD_DO)
3197c478bd9Sstevel@tonic-gate 			data |= 1;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 		e1000_lower_ee_clk(hw, &eecd);
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	return data;
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /******************************************************************************
3287c478bd9Sstevel@tonic-gate  * Prepares EEPROM for access
3297c478bd9Sstevel@tonic-gate  *
3307c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
3317c478bd9Sstevel@tonic-gate  *
3327c478bd9Sstevel@tonic-gate  * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3337c478bd9Sstevel@tonic-gate  * function should be called before issuing a command to the EEPROM.
3347c478bd9Sstevel@tonic-gate  *****************************************************************************/
3357c478bd9Sstevel@tonic-gate static int32_t
e1000_acquire_eeprom(struct e1000_hw * hw)3367c478bd9Sstevel@tonic-gate e1000_acquire_eeprom(struct e1000_hw *hw)
3377c478bd9Sstevel@tonic-gate {
3387c478bd9Sstevel@tonic-gate 	struct e1000_eeprom_info *eeprom = &hw->eeprom;
3397c478bd9Sstevel@tonic-gate 	uint32_t eecd, i=0;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	eecd = E1000_READ_REG(hw, EECD);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	/* Request EEPROM Access */
3447c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82544) {
3457c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_REQ;
3467c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
3477c478bd9Sstevel@tonic-gate 		eecd = E1000_READ_REG(hw, EECD);
3487c478bd9Sstevel@tonic-gate 		while((!(eecd & E1000_EECD_GNT)) &&
3497c478bd9Sstevel@tonic-gate 		      (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3507c478bd9Sstevel@tonic-gate 			i++;
3517c478bd9Sstevel@tonic-gate 			udelay(5);
3527c478bd9Sstevel@tonic-gate 			eecd = E1000_READ_REG(hw, EECD);
3537c478bd9Sstevel@tonic-gate 		}
3547c478bd9Sstevel@tonic-gate 		if(!(eecd & E1000_EECD_GNT)) {
3557c478bd9Sstevel@tonic-gate 			eecd &= ~E1000_EECD_REQ;
3567c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, EECD, eecd);
3577c478bd9Sstevel@tonic-gate 			DEBUGOUT("Could not acquire EEPROM grant\n");
3587c478bd9Sstevel@tonic-gate 			return -E1000_ERR_EEPROM;
3597c478bd9Sstevel@tonic-gate 		}
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	/* Setup EEPROM for Read/Write */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	if (eeprom->type == e1000_eeprom_microwire) {
3657c478bd9Sstevel@tonic-gate 		/* Clear SK and DI */
3667c478bd9Sstevel@tonic-gate 		eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3677c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		/* Set CS */
3707c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_CS;
3717c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
3727c478bd9Sstevel@tonic-gate 	} else if (eeprom->type == e1000_eeprom_spi) {
3737c478bd9Sstevel@tonic-gate 		/* Clear SK and CS */
3747c478bd9Sstevel@tonic-gate 		eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3757c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
3767c478bd9Sstevel@tonic-gate 		udelay(1);
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /******************************************************************************
3837c478bd9Sstevel@tonic-gate  * Returns EEPROM to a "standby" state
3847c478bd9Sstevel@tonic-gate  *
3857c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
3867c478bd9Sstevel@tonic-gate  *****************************************************************************/
3877c478bd9Sstevel@tonic-gate static void
e1000_standby_eeprom(struct e1000_hw * hw)3887c478bd9Sstevel@tonic-gate e1000_standby_eeprom(struct e1000_hw *hw)
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 	struct e1000_eeprom_info *eeprom = &hw->eeprom;
3917c478bd9Sstevel@tonic-gate 	uint32_t eecd;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	eecd = E1000_READ_REG(hw, EECD);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	if(eeprom->type == e1000_eeprom_microwire) {
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 		/* Deselect EEPROM */
3987c478bd9Sstevel@tonic-gate 		eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3997c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4007c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4017c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 		/* Clock high */
4047c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_SK;
4057c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4067c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4077c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 		/* Select EEPROM */
4107c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_CS;
4117c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4127c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4137c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 		/* Clock low */
4167c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_SK;
4177c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4187c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4197c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4207c478bd9Sstevel@tonic-gate 	} else if(eeprom->type == e1000_eeprom_spi) {
4217c478bd9Sstevel@tonic-gate 		/* Toggle CS to flush commands */
4227c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_CS;
4237c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4247c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4257c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4267c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_CS;
4277c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4287c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4297c478bd9Sstevel@tonic-gate 		udelay(eeprom->delay_usec);
4307c478bd9Sstevel@tonic-gate 	}
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate /******************************************************************************
4347c478bd9Sstevel@tonic-gate  * Terminates a command by inverting the EEPROM's chip select pin
4357c478bd9Sstevel@tonic-gate  *
4367c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
4377c478bd9Sstevel@tonic-gate  *****************************************************************************/
4387c478bd9Sstevel@tonic-gate static void
e1000_release_eeprom(struct e1000_hw * hw)4397c478bd9Sstevel@tonic-gate e1000_release_eeprom(struct e1000_hw *hw)
4407c478bd9Sstevel@tonic-gate {
4417c478bd9Sstevel@tonic-gate 	uint32_t eecd;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	eecd = E1000_READ_REG(hw, EECD);
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	if (hw->eeprom.type == e1000_eeprom_spi) {
4467c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_CS;  /* Pull CS high */
4477c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_SK; /* Lower SCK */
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 		udelay(hw->eeprom.delay_usec);
4527c478bd9Sstevel@tonic-gate 	} else if(hw->eeprom.type == e1000_eeprom_microwire) {
4537c478bd9Sstevel@tonic-gate 		/* cleanup eeprom */
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 		/* CS on Microwire is active-high */
4567c478bd9Sstevel@tonic-gate 		eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 		/* Rising edge of clock */
4617c478bd9Sstevel@tonic-gate 		eecd |= E1000_EECD_SK;
4627c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4637c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4647c478bd9Sstevel@tonic-gate 		udelay(hw->eeprom.delay_usec);
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 		/* Falling edge of clock */
4677c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_SK;
4687c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4697c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
4707c478bd9Sstevel@tonic-gate 		udelay(hw->eeprom.delay_usec);
4717c478bd9Sstevel@tonic-gate 	}
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	/* Stop requesting EEPROM access */
4747c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82544) {
4757c478bd9Sstevel@tonic-gate 		eecd &= ~E1000_EECD_REQ;
4767c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, EECD, eecd);
4777c478bd9Sstevel@tonic-gate 	}
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate /******************************************************************************
4817c478bd9Sstevel@tonic-gate  * Reads a 16 bit word from the EEPROM.
4827c478bd9Sstevel@tonic-gate  *
4837c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
4847c478bd9Sstevel@tonic-gate  *****************************************************************************/
4857c478bd9Sstevel@tonic-gate static int32_t
e1000_spi_eeprom_ready(struct e1000_hw * hw)4867c478bd9Sstevel@tonic-gate e1000_spi_eeprom_ready(struct e1000_hw *hw)
4877c478bd9Sstevel@tonic-gate {
4887c478bd9Sstevel@tonic-gate 	uint16_t retry_count = 0;
4897c478bd9Sstevel@tonic-gate 	uint8_t spi_stat_reg;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	/* Read "Status Register" repeatedly until the LSB is cleared.  The
4927c478bd9Sstevel@tonic-gate 	 * EEPROM will signal that the command has been completed by clearing
4937c478bd9Sstevel@tonic-gate 	 * bit 0 of the internal status register.  If it's not cleared within
4947c478bd9Sstevel@tonic-gate 	 * 5 milliseconds, then error out.
4957c478bd9Sstevel@tonic-gate 	 */
4967c478bd9Sstevel@tonic-gate 	retry_count = 0;
4977c478bd9Sstevel@tonic-gate 	do {
4987c478bd9Sstevel@tonic-gate 		e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4997c478bd9Sstevel@tonic-gate 		hw->eeprom.opcode_bits);
5007c478bd9Sstevel@tonic-gate 		spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
5017c478bd9Sstevel@tonic-gate 		if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
5027c478bd9Sstevel@tonic-gate 			break;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 		udelay(5);
5057c478bd9Sstevel@tonic-gate 		retry_count += 5;
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	} while(retry_count < EEPROM_MAX_RETRY_SPI);
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 	/* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
5107c478bd9Sstevel@tonic-gate 	 * only 0-5mSec on 5V devices)
5117c478bd9Sstevel@tonic-gate 	 */
5127c478bd9Sstevel@tonic-gate 	if(retry_count >= EEPROM_MAX_RETRY_SPI) {
5137c478bd9Sstevel@tonic-gate 		DEBUGOUT("SPI EEPROM Status error\n");
5147c478bd9Sstevel@tonic-gate 		return -E1000_ERR_EEPROM;
5157c478bd9Sstevel@tonic-gate 	}
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate /******************************************************************************
5217c478bd9Sstevel@tonic-gate  * Reads a 16 bit word from the EEPROM.
5227c478bd9Sstevel@tonic-gate  *
5237c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
5247c478bd9Sstevel@tonic-gate  * offset - offset of  word in the EEPROM to read
5257c478bd9Sstevel@tonic-gate  * data - word read from the EEPROM
5267c478bd9Sstevel@tonic-gate  * words - number of words to read
5277c478bd9Sstevel@tonic-gate  *****************************************************************************/
5287c478bd9Sstevel@tonic-gate static int
e1000_read_eeprom(struct e1000_hw * hw,uint16_t offset,uint16_t words,uint16_t * data)5297c478bd9Sstevel@tonic-gate e1000_read_eeprom(struct e1000_hw *hw,
5307c478bd9Sstevel@tonic-gate                   uint16_t offset,
5317c478bd9Sstevel@tonic-gate 		  uint16_t words,
5327c478bd9Sstevel@tonic-gate                   uint16_t *data)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	struct e1000_eeprom_info *eeprom = &hw->eeprom;
5357c478bd9Sstevel@tonic-gate 	uint32_t i = 0;
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_read_eeprom");
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	/* A check for invalid values:  offset too large, too many words, and not
5407c478bd9Sstevel@tonic-gate 	 * enough words.
5417c478bd9Sstevel@tonic-gate 	 */
5427c478bd9Sstevel@tonic-gate 	if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
5437c478bd9Sstevel@tonic-gate 	   (words == 0)) {
5447c478bd9Sstevel@tonic-gate 		DEBUGOUT("\"words\" parameter out of bounds\n");
5457c478bd9Sstevel@tonic-gate 		return -E1000_ERR_EEPROM;
5467c478bd9Sstevel@tonic-gate 	}
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	/*  Prepare the EEPROM for reading  */
5497c478bd9Sstevel@tonic-gate 	if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5507c478bd9Sstevel@tonic-gate 		return -E1000_ERR_EEPROM;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	if(eeprom->type == e1000_eeprom_spi) {
5537c478bd9Sstevel@tonic-gate 		uint16_t word_in;
5547c478bd9Sstevel@tonic-gate 		uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 		if(e1000_spi_eeprom_ready(hw)) {
5577c478bd9Sstevel@tonic-gate 			e1000_release_eeprom(hw);
5587c478bd9Sstevel@tonic-gate 			return -E1000_ERR_EEPROM;
5597c478bd9Sstevel@tonic-gate 		}
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 		e1000_standby_eeprom(hw);
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 		/* Some SPI eeproms use the 8th address bit embedded in the opcode */
5647c478bd9Sstevel@tonic-gate 		if((eeprom->address_bits == 8) && (offset >= 128))
5657c478bd9Sstevel@tonic-gate 			read_opcode |= EEPROM_A8_OPCODE_SPI;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 		/* Send the READ command (opcode + addr)  */
5687c478bd9Sstevel@tonic-gate 		e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5697c478bd9Sstevel@tonic-gate 		e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 		/* Read the data.  The address of the eeprom internally increments with
5727c478bd9Sstevel@tonic-gate 		 * each byte (spi) being read, saving on the overhead of eeprom setup
5737c478bd9Sstevel@tonic-gate 		 * and tear-down.  The address counter will roll over if reading beyond
5747c478bd9Sstevel@tonic-gate 		 * the size of the eeprom, thus allowing the entire memory to be read
5757c478bd9Sstevel@tonic-gate 		 * starting from any offset. */
5767c478bd9Sstevel@tonic-gate 		for (i = 0; i < words; i++) {
5777c478bd9Sstevel@tonic-gate 			word_in = e1000_shift_in_ee_bits(hw, 16);
5787c478bd9Sstevel@tonic-gate 			data[i] = (word_in >> 8) | (word_in << 8);
5797c478bd9Sstevel@tonic-gate 		}
5807c478bd9Sstevel@tonic-gate 	} else if(eeprom->type == e1000_eeprom_microwire) {
5817c478bd9Sstevel@tonic-gate 		for (i = 0; i < words; i++) {
5827c478bd9Sstevel@tonic-gate 			/*  Send the READ command (opcode + addr)  */
5837c478bd9Sstevel@tonic-gate 			e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5847c478bd9Sstevel@tonic-gate 						eeprom->opcode_bits);
5857c478bd9Sstevel@tonic-gate 			e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5867c478bd9Sstevel@tonic-gate 			                        eeprom->address_bits);
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 			/* Read the data.  For microwire, each word requires the overhead
5897c478bd9Sstevel@tonic-gate 			 * of eeprom setup and tear-down. */
5907c478bd9Sstevel@tonic-gate 			data[i] = e1000_shift_in_ee_bits(hw, 16);
5917c478bd9Sstevel@tonic-gate 			e1000_standby_eeprom(hw);
5927c478bd9Sstevel@tonic-gate 		}
5937c478bd9Sstevel@tonic-gate 	}
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	/* End this read operation */
5967c478bd9Sstevel@tonic-gate 	e1000_release_eeprom(hw);
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate /******************************************************************************
6027c478bd9Sstevel@tonic-gate  * Verifies that the EEPROM has a valid checksum
6037c478bd9Sstevel@tonic-gate  *
6047c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
6057c478bd9Sstevel@tonic-gate  *
6067c478bd9Sstevel@tonic-gate  * Reads the first 64 16 bit words of the EEPROM and sums the values read.
6077c478bd9Sstevel@tonic-gate  * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
6087c478bd9Sstevel@tonic-gate  * valid.
6097c478bd9Sstevel@tonic-gate  *****************************************************************************/
6107c478bd9Sstevel@tonic-gate static int
e1000_validate_eeprom_checksum(struct e1000_hw * hw)6117c478bd9Sstevel@tonic-gate e1000_validate_eeprom_checksum(struct e1000_hw *hw)
6127c478bd9Sstevel@tonic-gate {
6137c478bd9Sstevel@tonic-gate 	uint16_t checksum = 0;
6147c478bd9Sstevel@tonic-gate 	uint16_t i, eeprom_data;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_validate_eeprom_checksum");
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
6197c478bd9Sstevel@tonic-gate 		if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
6207c478bd9Sstevel@tonic-gate 			DEBUGOUT("EEPROM Read Error\n");
6217c478bd9Sstevel@tonic-gate 			return -E1000_ERR_EEPROM;
6227c478bd9Sstevel@tonic-gate 		}
6237c478bd9Sstevel@tonic-gate 		checksum += eeprom_data;
6247c478bd9Sstevel@tonic-gate 	}
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	if(checksum == (uint16_t) EEPROM_SUM)
6277c478bd9Sstevel@tonic-gate 		return E1000_SUCCESS;
6287c478bd9Sstevel@tonic-gate 	else {
6297c478bd9Sstevel@tonic-gate 		DEBUGOUT("EEPROM Checksum Invalid\n");
6307c478bd9Sstevel@tonic-gate 		return -E1000_ERR_EEPROM;
6317c478bd9Sstevel@tonic-gate 	}
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate /******************************************************************************
6357c478bd9Sstevel@tonic-gate  * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
6367c478bd9Sstevel@tonic-gate  * second function of dual function devices
6377c478bd9Sstevel@tonic-gate  *
6387c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
6397c478bd9Sstevel@tonic-gate  *****************************************************************************/
6407c478bd9Sstevel@tonic-gate static int
e1000_read_mac_addr(struct e1000_hw * hw)6417c478bd9Sstevel@tonic-gate e1000_read_mac_addr(struct e1000_hw *hw)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate 	uint16_t offset;
6447c478bd9Sstevel@tonic-gate 	uint16_t eeprom_data;
6457c478bd9Sstevel@tonic-gate 	int i;
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_read_mac_addr");
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 	for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
6507c478bd9Sstevel@tonic-gate 		offset = i >> 1;
6517c478bd9Sstevel@tonic-gate 		if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
6527c478bd9Sstevel@tonic-gate 			DEBUGOUT("EEPROM Read Error\n");
6537c478bd9Sstevel@tonic-gate 			return -E1000_ERR_EEPROM;
6547c478bd9Sstevel@tonic-gate 		}
6557c478bd9Sstevel@tonic-gate 		hw->mac_addr[i] = eeprom_data & 0xff;
6567c478bd9Sstevel@tonic-gate 		hw->mac_addr[i+1] = (eeprom_data >> 8) & 0xff;
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 	if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
6597c478bd9Sstevel@tonic-gate 		(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
6607c478bd9Sstevel@tonic-gate 		/* Invert the last bit if this is the second device */
6617c478bd9Sstevel@tonic-gate 		hw->mac_addr[5] ^= 1;
6627c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate /******************************************************************************
6667c478bd9Sstevel@tonic-gate  * Initializes receive address filters.
6677c478bd9Sstevel@tonic-gate  *
6687c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
6697c478bd9Sstevel@tonic-gate  *
6707c478bd9Sstevel@tonic-gate  * Places the MAC address in receive address register 0 and clears the rest
6717c478bd9Sstevel@tonic-gate  * of the receive addresss registers. Clears the multicast table. Assumes
6727c478bd9Sstevel@tonic-gate  * the receiver is in reset when the routine is called.
6737c478bd9Sstevel@tonic-gate  *****************************************************************************/
6747c478bd9Sstevel@tonic-gate static void
e1000_init_rx_addrs(struct e1000_hw * hw)6757c478bd9Sstevel@tonic-gate e1000_init_rx_addrs(struct e1000_hw *hw)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate 	uint32_t i;
6787c478bd9Sstevel@tonic-gate 	uint32_t addr_low;
6797c478bd9Sstevel@tonic-gate 	uint32_t addr_high;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_init_rx_addrs");
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	/* Setup the receive address. */
6847c478bd9Sstevel@tonic-gate 	DEBUGOUT("Programming MAC Address into RAR[0]\n");
6857c478bd9Sstevel@tonic-gate 	addr_low = (hw->mac_addr[0] |
6867c478bd9Sstevel@tonic-gate 		(hw->mac_addr[1] << 8) |
6877c478bd9Sstevel@tonic-gate 		(hw->mac_addr[2] << 16) | (hw->mac_addr[3] << 24));
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	addr_high = (hw->mac_addr[4] |
6907c478bd9Sstevel@tonic-gate 		(hw->mac_addr[5] << 8) | E1000_RAH_AV);
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
6937c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 	/* Zero out the other 15 receive addresses. */
6967c478bd9Sstevel@tonic-gate 	DEBUGOUT("Clearing RAR[1-15]\n");
6977c478bd9Sstevel@tonic-gate 	for(i = 1; i < E1000_RAR_ENTRIES; i++) {
6987c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
6997c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
7007c478bd9Sstevel@tonic-gate 	}
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate /******************************************************************************
7047c478bd9Sstevel@tonic-gate  * Clears the VLAN filer table
7057c478bd9Sstevel@tonic-gate  *
7067c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
7077c478bd9Sstevel@tonic-gate  *****************************************************************************/
7087c478bd9Sstevel@tonic-gate static void
e1000_clear_vfta(struct e1000_hw * hw)7097c478bd9Sstevel@tonic-gate e1000_clear_vfta(struct e1000_hw *hw)
7107c478bd9Sstevel@tonic-gate {
7117c478bd9Sstevel@tonic-gate 	uint32_t offset;
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 	for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
7147c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate /******************************************************************************
7187c478bd9Sstevel@tonic-gate * Writes a value to one of the devices registers using port I/O (as opposed to
7197c478bd9Sstevel@tonic-gate * memory mapped I/O). Only 82544 and newer devices support port I/O. *
7207c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
7217c478bd9Sstevel@tonic-gate * offset - offset to write to * value - value to write
7227c478bd9Sstevel@tonic-gate *****************************************************************************/
e1000_write_reg_io(struct e1000_hw * hw,uint32_t offset,uint32_t value)7237c478bd9Sstevel@tonic-gate void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value){
7247c478bd9Sstevel@tonic-gate 	uint32_t io_addr = hw->io_base;
7257c478bd9Sstevel@tonic-gate 	uint32_t io_data = hw->io_base + 4;
7267c478bd9Sstevel@tonic-gate 	e1000_io_write(hw, io_addr, offset);
7277c478bd9Sstevel@tonic-gate 	e1000_io_write(hw, io_data, value);
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate /******************************************************************************
7317c478bd9Sstevel@tonic-gate  * Set the phy type member in the hw struct.
7327c478bd9Sstevel@tonic-gate  *
7337c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
7347c478bd9Sstevel@tonic-gate  *****************************************************************************/
7357c478bd9Sstevel@tonic-gate static int32_t
e1000_set_phy_type(struct e1000_hw * hw)7367c478bd9Sstevel@tonic-gate e1000_set_phy_type(struct e1000_hw *hw)
7377c478bd9Sstevel@tonic-gate {
7387c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_set_phy_type");
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	switch(hw->phy_id) {
7417c478bd9Sstevel@tonic-gate 	case M88E1000_E_PHY_ID:
7427c478bd9Sstevel@tonic-gate 	case M88E1000_I_PHY_ID:
7437c478bd9Sstevel@tonic-gate 	case M88E1011_I_PHY_ID:
7447c478bd9Sstevel@tonic-gate 		hw->phy_type = e1000_phy_m88;
7457c478bd9Sstevel@tonic-gate 		break;
7467c478bd9Sstevel@tonic-gate 	case IGP01E1000_I_PHY_ID:
7477c478bd9Sstevel@tonic-gate 		hw->phy_type = e1000_phy_igp;
7487c478bd9Sstevel@tonic-gate 		break;
7497c478bd9Sstevel@tonic-gate 	default:
7507c478bd9Sstevel@tonic-gate 		/* Should never have loaded on this device */
7517c478bd9Sstevel@tonic-gate 		hw->phy_type = e1000_phy_undefined;
7527c478bd9Sstevel@tonic-gate 		return -E1000_ERR_PHY_TYPE;
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate /******************************************************************************
7597c478bd9Sstevel@tonic-gate  * IGP phy init script - initializes the GbE PHY
7607c478bd9Sstevel@tonic-gate  *
7617c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
7627c478bd9Sstevel@tonic-gate  *****************************************************************************/
7637c478bd9Sstevel@tonic-gate static void
e1000_phy_init_script(struct e1000_hw * hw)7647c478bd9Sstevel@tonic-gate e1000_phy_init_script(struct e1000_hw *hw)
7657c478bd9Sstevel@tonic-gate {
7667c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_phy_init_script");
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate #if 0
7697c478bd9Sstevel@tonic-gate 	/* See e1000_sw_init() of the Linux driver */
7707c478bd9Sstevel@tonic-gate 	if(hw->phy_init_script) {
7717c478bd9Sstevel@tonic-gate #else
7727c478bd9Sstevel@tonic-gate 	if((hw->mac_type == e1000_82541) ||
7737c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82547) ||
7747c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82541_rev_2) ||
7757c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82547_rev_2)) {
7767c478bd9Sstevel@tonic-gate #endif
7777c478bd9Sstevel@tonic-gate 		mdelay(20);
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 		e1000_write_phy_reg(hw,0x0000,0x0140);
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 		mdelay(5);
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 		if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
7847c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F95, 0x0001);
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F79, 0x0018);
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F30, 0x1600);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F31, 0x0014);
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F32, 0x161C);
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F94, 0x0003);
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F96, 0x003F);
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x2010, 0x0008);
8017c478bd9Sstevel@tonic-gate 		} else {
8027c478bd9Sstevel@tonic-gate 			e1000_write_phy_reg(hw, 0x1F73, 0x0099);
8037c478bd9Sstevel@tonic-gate 		}
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate 		e1000_write_phy_reg(hw, 0x0000, 0x3300);
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 		if(hw->mac_type == e1000_82547) {
8097c478bd9Sstevel@tonic-gate 			uint16_t fused, fine, coarse;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 			/* Move to analog registers page */
8127c478bd9Sstevel@tonic-gate 			e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 			if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
8157c478bd9Sstevel@tonic-gate 				e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 				fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
8187c478bd9Sstevel@tonic-gate 				coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 				if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
8217c478bd9Sstevel@tonic-gate 					coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
8227c478bd9Sstevel@tonic-gate 					fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
8237c478bd9Sstevel@tonic-gate 				} else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
8247c478bd9Sstevel@tonic-gate 					fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 				fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
8277c478bd9Sstevel@tonic-gate 					(fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
8287c478bd9Sstevel@tonic-gate 					(coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 				e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
8317c478bd9Sstevel@tonic-gate 				e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
8327c478bd9Sstevel@tonic-gate 						IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
8337c478bd9Sstevel@tonic-gate 			}
8347c478bd9Sstevel@tonic-gate 		}
8357c478bd9Sstevel@tonic-gate 	}
8367c478bd9Sstevel@tonic-gate }
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate /******************************************************************************
8397c478bd9Sstevel@tonic-gate  * Set the mac type member in the hw struct.
8407c478bd9Sstevel@tonic-gate  *
8417c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
8427c478bd9Sstevel@tonic-gate  *****************************************************************************/
8437c478bd9Sstevel@tonic-gate static int
8447c478bd9Sstevel@tonic-gate e1000_set_mac_type(struct e1000_hw *hw)
8457c478bd9Sstevel@tonic-gate {
8467c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_set_mac_type");
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate 	switch (hw->device_id) {
8497c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82542:
8507c478bd9Sstevel@tonic-gate 		switch (hw->revision_id) {
8517c478bd9Sstevel@tonic-gate 		case E1000_82542_2_0_REV_ID:
8527c478bd9Sstevel@tonic-gate 			hw->mac_type = e1000_82542_rev2_0;
8537c478bd9Sstevel@tonic-gate 			break;
8547c478bd9Sstevel@tonic-gate 		case E1000_82542_2_1_REV_ID:
8557c478bd9Sstevel@tonic-gate 			hw->mac_type = e1000_82542_rev2_1;
8567c478bd9Sstevel@tonic-gate 			break;
8577c478bd9Sstevel@tonic-gate 		default:
8587c478bd9Sstevel@tonic-gate 			/* Invalid 82542 revision ID */
8597c478bd9Sstevel@tonic-gate 			return -E1000_ERR_MAC_TYPE;
8607c478bd9Sstevel@tonic-gate 		}
8617c478bd9Sstevel@tonic-gate 		break;
8627c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82543GC_FIBER:
8637c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82543GC_COPPER:
8647c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82543;
8657c478bd9Sstevel@tonic-gate 		break;
8667c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82544EI_COPPER:
8677c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82544EI_FIBER:
8687c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82544GC_COPPER:
8697c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82544GC_LOM:
8707c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82544;
8717c478bd9Sstevel@tonic-gate 		break;
8727c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82540EM:
8737c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82540EM_LOM:
8747c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82540EP:
8757c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82540EP_LOM:
8767c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82540EP_LP:
8777c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82540;
8787c478bd9Sstevel@tonic-gate 		break;
8797c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82545EM_COPPER:
8807c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82545EM_FIBER:
8817c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82545;
8827c478bd9Sstevel@tonic-gate 		break;
8837c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82545GM_COPPER:
8847c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82545GM_FIBER:
8857c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82545GM_SERDES:
8867c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82545_rev_3;
8877c478bd9Sstevel@tonic-gate 		break;
8887c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546EB_COPPER:
8897c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546EB_FIBER:
8907c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546EB_QUAD_COPPER:
8917c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82546;
8927c478bd9Sstevel@tonic-gate 		break;
8937c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546GB_COPPER:
8947c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546GB_FIBER:
8957c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82546GB_SERDES:
8967c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82546_rev_3;
8977c478bd9Sstevel@tonic-gate 		break;
8987c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82541EI:
8997c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82541EI_MOBILE:
9007c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82541;
9017c478bd9Sstevel@tonic-gate 		break;
9027c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82541ER:
9037c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82541GI:
9047c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82541GI_MOBILE:
9057c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82541_rev_2;
9067c478bd9Sstevel@tonic-gate 		break;
9077c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82547EI:
9087c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82547;
9097c478bd9Sstevel@tonic-gate 		break;
9107c478bd9Sstevel@tonic-gate 	case E1000_DEV_ID_82547GI:
9117c478bd9Sstevel@tonic-gate 		hw->mac_type = e1000_82547_rev_2;
9127c478bd9Sstevel@tonic-gate 		break;
9137c478bd9Sstevel@tonic-gate 	default:
9147c478bd9Sstevel@tonic-gate 		/* Should never have loaded on this device */
9157c478bd9Sstevel@tonic-gate 		return -E1000_ERR_MAC_TYPE;
9167c478bd9Sstevel@tonic-gate 	}
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate /*****************************************************************************
9227c478bd9Sstevel@tonic-gate  * Set media type and TBI compatibility.
9237c478bd9Sstevel@tonic-gate  *
9247c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
9257c478bd9Sstevel@tonic-gate  * **************************************************************************/
9267c478bd9Sstevel@tonic-gate static void
9277c478bd9Sstevel@tonic-gate e1000_set_media_type(struct e1000_hw *hw)
9287c478bd9Sstevel@tonic-gate {
9297c478bd9Sstevel@tonic-gate 	uint32_t status;
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_set_media_type");
9327c478bd9Sstevel@tonic-gate 
9337c478bd9Sstevel@tonic-gate 	if(hw->mac_type != e1000_82543) {
9347c478bd9Sstevel@tonic-gate 		/* tbi_compatibility is only valid on 82543 */
9357c478bd9Sstevel@tonic-gate 		hw->tbi_compatibility_en = FALSE;
9367c478bd9Sstevel@tonic-gate 	}
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	switch (hw->device_id) {
9397c478bd9Sstevel@tonic-gate 		case E1000_DEV_ID_82545GM_SERDES:
9407c478bd9Sstevel@tonic-gate 		case E1000_DEV_ID_82546GB_SERDES:
9417c478bd9Sstevel@tonic-gate 			hw->media_type = e1000_media_type_internal_serdes;
9427c478bd9Sstevel@tonic-gate 			break;
9437c478bd9Sstevel@tonic-gate 		default:
9447c478bd9Sstevel@tonic-gate 			if(hw->mac_type >= e1000_82543) {
9457c478bd9Sstevel@tonic-gate 				status = E1000_READ_REG(hw, STATUS);
9467c478bd9Sstevel@tonic-gate 				if(status & E1000_STATUS_TBIMODE) {
9477c478bd9Sstevel@tonic-gate 					hw->media_type = e1000_media_type_fiber;
9487c478bd9Sstevel@tonic-gate 					/* tbi_compatibility not valid on fiber */
9497c478bd9Sstevel@tonic-gate 					hw->tbi_compatibility_en = FALSE;
9507c478bd9Sstevel@tonic-gate 				} else {
9517c478bd9Sstevel@tonic-gate 					hw->media_type = e1000_media_type_copper;
9527c478bd9Sstevel@tonic-gate 				}
9537c478bd9Sstevel@tonic-gate 			} else {
9547c478bd9Sstevel@tonic-gate 				/* This is an 82542 (fiber only) */
9557c478bd9Sstevel@tonic-gate 				hw->media_type = e1000_media_type_fiber;
9567c478bd9Sstevel@tonic-gate 			}
9577c478bd9Sstevel@tonic-gate 	}
9587c478bd9Sstevel@tonic-gate }
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate /******************************************************************************
9617c478bd9Sstevel@tonic-gate  * Reset the transmit and receive units; mask and clear all interrupts.
9627c478bd9Sstevel@tonic-gate  *
9637c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
9647c478bd9Sstevel@tonic-gate  *****************************************************************************/
9657c478bd9Sstevel@tonic-gate static void
9667c478bd9Sstevel@tonic-gate e1000_reset_hw(struct e1000_hw *hw)
9677c478bd9Sstevel@tonic-gate {
9687c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
9697c478bd9Sstevel@tonic-gate 	uint32_t ctrl_ext;
9707c478bd9Sstevel@tonic-gate 	uint32_t icr;
9717c478bd9Sstevel@tonic-gate 	uint32_t manc;
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_reset_hw");
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 	/* For 82542 (rev 2.0), disable MWI before issuing a device reset */
9767c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0) {
9777c478bd9Sstevel@tonic-gate 		DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
9787c478bd9Sstevel@tonic-gate 		e1000_pci_clear_mwi(hw);
9797c478bd9Sstevel@tonic-gate 	}
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 	/* Clear interrupt mask to stop board from generating interrupts */
9827c478bd9Sstevel@tonic-gate 	DEBUGOUT("Masking off all interrupts\n");
9837c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, IMC, 0xffffffff);
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate 	/* Disable the Transmit and Receive units.  Then delay to allow
9867c478bd9Sstevel@tonic-gate 	 * any pending transactions to complete before we hit the MAC with
9877c478bd9Sstevel@tonic-gate 	 * the global reset.
9887c478bd9Sstevel@tonic-gate 	 */
9897c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, RCTL, 0);
9907c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
9917c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate 	/* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
9947c478bd9Sstevel@tonic-gate 	hw->tbi_compatibility_on = FALSE;
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 	/* Delay to allow any outstanding PCI transactions to complete before
9977c478bd9Sstevel@tonic-gate 	 * resetting the device
9987c478bd9Sstevel@tonic-gate 	 */
9997c478bd9Sstevel@tonic-gate 	mdelay(10);
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	/* Must reset the PHY before resetting the MAC */
10047c478bd9Sstevel@tonic-gate 	if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
10057c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
10067c478bd9Sstevel@tonic-gate 		mdelay(5);
10077c478bd9Sstevel@tonic-gate 	}
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 	/* Issue a global reset to the MAC.  This will reset the chip's
10107c478bd9Sstevel@tonic-gate 	 * transmit, receive, DMA, and link units.  It will not effect
10117c478bd9Sstevel@tonic-gate 	 * the current PCI configuration.  The global reset bit is self-
10127c478bd9Sstevel@tonic-gate 	 * clearing, and should clear within a microsecond.
10137c478bd9Sstevel@tonic-gate 	 */
10147c478bd9Sstevel@tonic-gate 	DEBUGOUT("Issuing a global reset to MAC\n");
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 	switch(hw->mac_type) {
10177c478bd9Sstevel@tonic-gate 		case e1000_82544:
10187c478bd9Sstevel@tonic-gate 		case e1000_82540:
10197c478bd9Sstevel@tonic-gate 		case e1000_82545:
10207c478bd9Sstevel@tonic-gate 		case e1000_82546:
10217c478bd9Sstevel@tonic-gate 		case e1000_82541:
10227c478bd9Sstevel@tonic-gate 		case e1000_82541_rev_2:
10237c478bd9Sstevel@tonic-gate 			/* These controllers can't ack the 64-bit write when issuing the
10247c478bd9Sstevel@tonic-gate 			 * reset, so use IO-mapping as a workaround to issue the reset */
10257c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
10267c478bd9Sstevel@tonic-gate 			break;
10277c478bd9Sstevel@tonic-gate 		case e1000_82545_rev_3:
10287c478bd9Sstevel@tonic-gate 		case e1000_82546_rev_3:
10297c478bd9Sstevel@tonic-gate 			/* Reset is performed on a shadow of the control register */
10307c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
10317c478bd9Sstevel@tonic-gate 			break;
10327c478bd9Sstevel@tonic-gate 		default:
10337c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
10347c478bd9Sstevel@tonic-gate 			break;
10357c478bd9Sstevel@tonic-gate 	}
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate 	/* After MAC reset, force reload of EEPROM to restore power-on settings to
10387c478bd9Sstevel@tonic-gate 	 * device.  Later controllers reload the EEPROM automatically, so just wait
10397c478bd9Sstevel@tonic-gate 	 * for reload to complete.
10407c478bd9Sstevel@tonic-gate 	 */
10417c478bd9Sstevel@tonic-gate 	switch(hw->mac_type) {
10427c478bd9Sstevel@tonic-gate 		case e1000_82542_rev2_0:
10437c478bd9Sstevel@tonic-gate 		case e1000_82542_rev2_1:
10447c478bd9Sstevel@tonic-gate 		case e1000_82543:
10457c478bd9Sstevel@tonic-gate 		case e1000_82544:
10467c478bd9Sstevel@tonic-gate 			/* Wait for reset to complete */
10477c478bd9Sstevel@tonic-gate 			udelay(10);
10487c478bd9Sstevel@tonic-gate 			ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
10497c478bd9Sstevel@tonic-gate 			ctrl_ext |= E1000_CTRL_EXT_EE_RST;
10507c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
10517c478bd9Sstevel@tonic-gate 			E1000_WRITE_FLUSH(hw);
10527c478bd9Sstevel@tonic-gate 			/* Wait for EEPROM reload */
10537c478bd9Sstevel@tonic-gate 			mdelay(2);
10547c478bd9Sstevel@tonic-gate 			break;
10557c478bd9Sstevel@tonic-gate 		case e1000_82541:
10567c478bd9Sstevel@tonic-gate 		case e1000_82541_rev_2:
10577c478bd9Sstevel@tonic-gate 		case e1000_82547:
10587c478bd9Sstevel@tonic-gate 		case e1000_82547_rev_2:
10597c478bd9Sstevel@tonic-gate 			/* Wait for EEPROM reload */
10607c478bd9Sstevel@tonic-gate 			mdelay(20);
10617c478bd9Sstevel@tonic-gate 			break;
10627c478bd9Sstevel@tonic-gate 		default:
10637c478bd9Sstevel@tonic-gate 			/* Wait for EEPROM reload (it happens automatically) */
10647c478bd9Sstevel@tonic-gate 			mdelay(5);
10657c478bd9Sstevel@tonic-gate 			break;
10667c478bd9Sstevel@tonic-gate 	}
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate 	/* Disable HW ARPs on ASF enabled adapters */
10697c478bd9Sstevel@tonic-gate 	if(hw->mac_type >= e1000_82540) {
10707c478bd9Sstevel@tonic-gate 		manc = E1000_READ_REG(hw, MANC);
10717c478bd9Sstevel@tonic-gate 		manc &= ~(E1000_MANC_ARP_EN);
10727c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, MANC, manc);
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate 	if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
10767c478bd9Sstevel@tonic-gate 		e1000_phy_init_script(hw);
10777c478bd9Sstevel@tonic-gate 	}
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 	/* Clear interrupt mask to stop board from generating interrupts */
10807c478bd9Sstevel@tonic-gate 	DEBUGOUT("Masking off all interrupts\n");
10817c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, IMC, 0xffffffff);
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate 	/* Clear any pending interrupt events. */
10847c478bd9Sstevel@tonic-gate 	icr = E1000_READ_REG(hw, ICR);
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate 	/* If MWI was previously enabled, reenable it. */
10877c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0) {
10887c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER
10897c478bd9Sstevel@tonic-gate 		if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
10907c478bd9Sstevel@tonic-gate #endif
10917c478bd9Sstevel@tonic-gate 			e1000_pci_set_mwi(hw);
10927c478bd9Sstevel@tonic-gate 	}
10937c478bd9Sstevel@tonic-gate }
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate /******************************************************************************
10967c478bd9Sstevel@tonic-gate  * Performs basic configuration of the adapter.
10977c478bd9Sstevel@tonic-gate  *
10987c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
10997c478bd9Sstevel@tonic-gate  *
11007c478bd9Sstevel@tonic-gate  * Assumes that the controller has previously been reset and is in a
11017c478bd9Sstevel@tonic-gate  * post-reset uninitialized state. Initializes the receive address registers,
11027c478bd9Sstevel@tonic-gate  * multicast table, and VLAN filter table. Calls routines to setup link
11037c478bd9Sstevel@tonic-gate  * configuration and flow control settings. Clears all on-chip counters. Leaves
11047c478bd9Sstevel@tonic-gate  * the transmit and receive units disabled and uninitialized.
11057c478bd9Sstevel@tonic-gate  *****************************************************************************/
11067c478bd9Sstevel@tonic-gate static int
11077c478bd9Sstevel@tonic-gate e1000_init_hw(struct e1000_hw *hw)
11087c478bd9Sstevel@tonic-gate {
11097c478bd9Sstevel@tonic-gate 	uint32_t ctrl, status;
11107c478bd9Sstevel@tonic-gate 	uint32_t i;
11117c478bd9Sstevel@tonic-gate 	int32_t ret_val;
11127c478bd9Sstevel@tonic-gate 	uint16_t pcix_cmd_word;
11137c478bd9Sstevel@tonic-gate 	uint16_t pcix_stat_hi_word;
11147c478bd9Sstevel@tonic-gate 	uint16_t cmd_mmrbc;
11157c478bd9Sstevel@tonic-gate 	uint16_t stat_mmrbc;
11167c478bd9Sstevel@tonic-gate 	e1000_bus_type bus_type = e1000_bus_type_unknown;
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_init_hw");
11197c478bd9Sstevel@tonic-gate 
11207c478bd9Sstevel@tonic-gate 	/* Set the media type and TBI compatibility */
11217c478bd9Sstevel@tonic-gate 	e1000_set_media_type(hw);
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	/* Disabling VLAN filtering. */
11247c478bd9Sstevel@tonic-gate 	DEBUGOUT("Initializing the IEEE VLAN\n");
11257c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, VET, 0);
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate 	e1000_clear_vfta(hw);
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate 	/* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
11307c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0) {
11317c478bd9Sstevel@tonic-gate 		DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
11327c478bd9Sstevel@tonic-gate 		e1000_pci_clear_mwi(hw);
11337c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
11347c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
11357c478bd9Sstevel@tonic-gate 		mdelay(5);
11367c478bd9Sstevel@tonic-gate 	}
11377c478bd9Sstevel@tonic-gate 
11387c478bd9Sstevel@tonic-gate 	/* Setup the receive address. This involves initializing all of the Receive
11397c478bd9Sstevel@tonic-gate 	 * Address Registers (RARs 0 - 15).
11407c478bd9Sstevel@tonic-gate 	 */
11417c478bd9Sstevel@tonic-gate 	e1000_init_rx_addrs(hw);
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 	/* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
11447c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0) {
11457c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, RCTL, 0);
11467c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
11477c478bd9Sstevel@tonic-gate 		mdelay(1);
11487c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER
11497c478bd9Sstevel@tonic-gate 		if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
11507c478bd9Sstevel@tonic-gate #endif
11517c478bd9Sstevel@tonic-gate 			e1000_pci_set_mwi(hw);
11527c478bd9Sstevel@tonic-gate 	}
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 	/* Zero out the Multicast HASH table */
11557c478bd9Sstevel@tonic-gate 	DEBUGOUT("Zeroing the MTA\n");
11567c478bd9Sstevel@tonic-gate 	for(i = 0; i < E1000_MC_TBL_SIZE; i++)
11577c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate #if 0
11607c478bd9Sstevel@tonic-gate 	/* Set the PCI priority bit correctly in the CTRL register.  This
11617c478bd9Sstevel@tonic-gate 	 * determines if the adapter gives priority to receives, or if it
11627c478bd9Sstevel@tonic-gate 	 * gives equal priority to transmits and receives.
11637c478bd9Sstevel@tonic-gate 	 */
11647c478bd9Sstevel@tonic-gate 	if(hw->dma_fairness) {
11657c478bd9Sstevel@tonic-gate 		ctrl = E1000_READ_REG(hw, CTRL);
11667c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
11677c478bd9Sstevel@tonic-gate 	}
11687c478bd9Sstevel@tonic-gate #endif
11697c478bd9Sstevel@tonic-gate 
11707c478bd9Sstevel@tonic-gate 	switch(hw->mac_type) {
11717c478bd9Sstevel@tonic-gate 		case e1000_82545_rev_3:
11727c478bd9Sstevel@tonic-gate 		case e1000_82546_rev_3:
11737c478bd9Sstevel@tonic-gate 			break;
11747c478bd9Sstevel@tonic-gate 		default:
11757c478bd9Sstevel@tonic-gate 			if (hw->mac_type >= e1000_82543) {
11767c478bd9Sstevel@tonic-gate 				/* See e1000_get_bus_info() of the Linux driver */
11777c478bd9Sstevel@tonic-gate 				status = E1000_READ_REG(hw, STATUS);
11787c478bd9Sstevel@tonic-gate 				bus_type = (status & E1000_STATUS_PCIX_MODE) ?
11797c478bd9Sstevel@tonic-gate 					e1000_bus_type_pcix : e1000_bus_type_pci;
11807c478bd9Sstevel@tonic-gate 			}
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 			/* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
11837c478bd9Sstevel@tonic-gate 			if(bus_type == e1000_bus_type_pcix) {
11847c478bd9Sstevel@tonic-gate 				pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
11857c478bd9Sstevel@tonic-gate 				pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
11867c478bd9Sstevel@tonic-gate 				cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
11877c478bd9Sstevel@tonic-gate 					PCIX_COMMAND_MMRBC_SHIFT;
11887c478bd9Sstevel@tonic-gate 				stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
11897c478bd9Sstevel@tonic-gate 					PCIX_STATUS_HI_MMRBC_SHIFT;
11907c478bd9Sstevel@tonic-gate 				if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
11917c478bd9Sstevel@tonic-gate 					stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
11927c478bd9Sstevel@tonic-gate 				if(cmd_mmrbc > stat_mmrbc) {
11937c478bd9Sstevel@tonic-gate 					pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
11947c478bd9Sstevel@tonic-gate 					pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
11957c478bd9Sstevel@tonic-gate 					pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER, pcix_cmd_word);
11967c478bd9Sstevel@tonic-gate 				}
11977c478bd9Sstevel@tonic-gate 			}
11987c478bd9Sstevel@tonic-gate 			break;
11997c478bd9Sstevel@tonic-gate 	}
12007c478bd9Sstevel@tonic-gate 
12017c478bd9Sstevel@tonic-gate 	/* Call a subroutine to configure the link and setup flow control. */
12027c478bd9Sstevel@tonic-gate 	ret_val = e1000_setup_link(hw);
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate 	/* Set the transmit descriptor write-back policy */
12057c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82544) {
12067c478bd9Sstevel@tonic-gate 		ctrl = E1000_READ_REG(hw, TXDCTL);
12077c478bd9Sstevel@tonic-gate 		ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
12087c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, TXDCTL, ctrl);
12097c478bd9Sstevel@tonic-gate 	}
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate #if 0
12127c478bd9Sstevel@tonic-gate 	/* Clear all of the statistics registers (clear on read).  It is
12137c478bd9Sstevel@tonic-gate 	 * important that we do this after we have tried to establish link
12147c478bd9Sstevel@tonic-gate 	 * because the symbol error count will increment wildly if there
12157c478bd9Sstevel@tonic-gate 	 * is no link.
12167c478bd9Sstevel@tonic-gate 	 */
12177c478bd9Sstevel@tonic-gate 	e1000_clear_hw_cntrs(hw);
12187c478bd9Sstevel@tonic-gate #endif
12197c478bd9Sstevel@tonic-gate 
12207c478bd9Sstevel@tonic-gate 	return ret_val;
12217c478bd9Sstevel@tonic-gate }
12227c478bd9Sstevel@tonic-gate 
12237c478bd9Sstevel@tonic-gate /******************************************************************************
12247c478bd9Sstevel@tonic-gate  * Adjust SERDES output amplitude based on EEPROM setting.
12257c478bd9Sstevel@tonic-gate  *
12267c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code.
12277c478bd9Sstevel@tonic-gate  *****************************************************************************/
12287c478bd9Sstevel@tonic-gate static int32_t
12297c478bd9Sstevel@tonic-gate e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
12307c478bd9Sstevel@tonic-gate {
12317c478bd9Sstevel@tonic-gate 	uint16_t eeprom_data;
12327c478bd9Sstevel@tonic-gate 	int32_t  ret_val;
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_adjust_serdes_amplitude");
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 	if(hw->media_type != e1000_media_type_internal_serdes)
12377c478bd9Sstevel@tonic-gate 		return E1000_SUCCESS;
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate 	switch(hw->mac_type) {
12407c478bd9Sstevel@tonic-gate 		case e1000_82545_rev_3:
12417c478bd9Sstevel@tonic-gate 		case e1000_82546_rev_3:
12427c478bd9Sstevel@tonic-gate 			break;
12437c478bd9Sstevel@tonic-gate 		default:
12447c478bd9Sstevel@tonic-gate 			return E1000_SUCCESS;
12457c478bd9Sstevel@tonic-gate 	}
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate 	if ((ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
12487c478bd9Sstevel@tonic-gate 					&eeprom_data))) {
12497c478bd9Sstevel@tonic-gate 		return ret_val;
12507c478bd9Sstevel@tonic-gate 	}
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	if(eeprom_data != EEPROM_RESERVED_WORD) {
12537c478bd9Sstevel@tonic-gate 		/* Adjust SERDES output amplitude only. */
12547c478bd9Sstevel@tonic-gate 		eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
12557c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL,
12567c478bd9Sstevel@tonic-gate 		                                  eeprom_data)))
12577c478bd9Sstevel@tonic-gate 			return ret_val;
12587c478bd9Sstevel@tonic-gate 	}
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
12617c478bd9Sstevel@tonic-gate }
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate /******************************************************************************
12647c478bd9Sstevel@tonic-gate  * Configures flow control and link settings.
12657c478bd9Sstevel@tonic-gate  *
12667c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
12677c478bd9Sstevel@tonic-gate  *
12687c478bd9Sstevel@tonic-gate  * Determines which flow control settings to use. Calls the apropriate media-
12697c478bd9Sstevel@tonic-gate  * specific link configuration function. Configures the flow control settings.
12707c478bd9Sstevel@tonic-gate  * Assuming the adapter has a valid link partner, a valid link should be
12717c478bd9Sstevel@tonic-gate  * established. Assumes the hardware has previously been reset and the
12727c478bd9Sstevel@tonic-gate  * transmitter and receiver are not enabled.
12737c478bd9Sstevel@tonic-gate  *****************************************************************************/
12747c478bd9Sstevel@tonic-gate static int
12757c478bd9Sstevel@tonic-gate e1000_setup_link(struct e1000_hw *hw)
12767c478bd9Sstevel@tonic-gate {
12777c478bd9Sstevel@tonic-gate 	uint32_t ctrl_ext;
12787c478bd9Sstevel@tonic-gate 	int32_t ret_val;
12797c478bd9Sstevel@tonic-gate 	uint16_t eeprom_data;
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_setup_link");
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	/* Read and store word 0x0F of the EEPROM. This word contains bits
12847c478bd9Sstevel@tonic-gate 	 * that determine the hardware's default PAUSE (flow control) mode,
12857c478bd9Sstevel@tonic-gate 	 * a bit that determines whether the HW defaults to enabling or
12867c478bd9Sstevel@tonic-gate 	 * disabling auto-negotiation, and the direction of the
12877c478bd9Sstevel@tonic-gate 	 * SW defined pins. If there is no SW over-ride of the flow
12887c478bd9Sstevel@tonic-gate 	 * control setting, then the variable hw->fc will
12897c478bd9Sstevel@tonic-gate 	 * be initialized based on a value in the EEPROM.
12907c478bd9Sstevel@tonic-gate 	 */
12917c478bd9Sstevel@tonic-gate 	if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
12927c478bd9Sstevel@tonic-gate 		DEBUGOUT("EEPROM Read Error\n");
12937c478bd9Sstevel@tonic-gate 		return -E1000_ERR_EEPROM;
12947c478bd9Sstevel@tonic-gate 	}
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 	if(hw->fc == e1000_fc_default) {
12977c478bd9Sstevel@tonic-gate 		if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
12987c478bd9Sstevel@tonic-gate 			hw->fc = e1000_fc_none;
12997c478bd9Sstevel@tonic-gate 		else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
13007c478bd9Sstevel@tonic-gate 			EEPROM_WORD0F_ASM_DIR)
13017c478bd9Sstevel@tonic-gate 			hw->fc = e1000_fc_tx_pause;
13027c478bd9Sstevel@tonic-gate 		else
13037c478bd9Sstevel@tonic-gate 			hw->fc = e1000_fc_full;
13047c478bd9Sstevel@tonic-gate 	}
13057c478bd9Sstevel@tonic-gate 
13067c478bd9Sstevel@tonic-gate 	/* We want to save off the original Flow Control configuration just
13077c478bd9Sstevel@tonic-gate 	 * in case we get disconnected and then reconnected into a different
13087c478bd9Sstevel@tonic-gate 	 * hub or switch with different Flow Control capabilities.
13097c478bd9Sstevel@tonic-gate 	 */
13107c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0)
13117c478bd9Sstevel@tonic-gate 		hw->fc &= (~e1000_fc_tx_pause);
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate #if 0
13147c478bd9Sstevel@tonic-gate 	/* See e1000_sw_init() of the Linux driver */
13157c478bd9Sstevel@tonic-gate 	if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
13167c478bd9Sstevel@tonic-gate #else
13177c478bd9Sstevel@tonic-gate 	if((hw->mac_type < e1000_82543) && (hw->mac_type >= e1000_82543))
13187c478bd9Sstevel@tonic-gate #endif
13197c478bd9Sstevel@tonic-gate 		hw->fc &= (~e1000_fc_rx_pause);
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate #if 0
13227c478bd9Sstevel@tonic-gate 	hw->original_fc = hw->fc;
13237c478bd9Sstevel@tonic-gate #endif
13247c478bd9Sstevel@tonic-gate 
13257c478bd9Sstevel@tonic-gate 	DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
13267c478bd9Sstevel@tonic-gate 
13277c478bd9Sstevel@tonic-gate 	/* Take the 4 bits from EEPROM word 0x0F that determine the initial
13287c478bd9Sstevel@tonic-gate 	 * polarity value for the SW controlled pins, and setup the
13297c478bd9Sstevel@tonic-gate 	 * Extended Device Control reg with that info.
13307c478bd9Sstevel@tonic-gate 	 * This is needed because one of the SW controlled pins is used for
13317c478bd9Sstevel@tonic-gate 	 * signal detection.  So this should be done before e1000_setup_pcs_link()
13327c478bd9Sstevel@tonic-gate 	 * or e1000_phy_setup() is called.
13337c478bd9Sstevel@tonic-gate 	 */
13347c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82543) {
13357c478bd9Sstevel@tonic-gate 		ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
13367c478bd9Sstevel@tonic-gate 			SWDPIO__EXT_SHIFT);
13377c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
13387c478bd9Sstevel@tonic-gate 	}
13397c478bd9Sstevel@tonic-gate 
13407c478bd9Sstevel@tonic-gate 	/* Call the necessary subroutine to configure the link. */
13417c478bd9Sstevel@tonic-gate 	ret_val = (hw->media_type == e1000_media_type_copper) ?
13427c478bd9Sstevel@tonic-gate 		e1000_setup_copper_link(hw) :
13437c478bd9Sstevel@tonic-gate 		e1000_setup_fiber_serdes_link(hw);
13447c478bd9Sstevel@tonic-gate 	if (ret_val < 0) {
13457c478bd9Sstevel@tonic-gate 		return ret_val;
13467c478bd9Sstevel@tonic-gate 	}
13477c478bd9Sstevel@tonic-gate 
13487c478bd9Sstevel@tonic-gate 	/* Initialize the flow control address, type, and PAUSE timer
13497c478bd9Sstevel@tonic-gate 	 * registers to their default values.  This is done even if flow
13507c478bd9Sstevel@tonic-gate 	 * control is disabled, because it does not hurt anything to
13517c478bd9Sstevel@tonic-gate 	 * initialize these registers.
13527c478bd9Sstevel@tonic-gate 	 */
13537c478bd9Sstevel@tonic-gate 	DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
13567c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
13577c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
13587c478bd9Sstevel@tonic-gate #if 0
13597c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
13607c478bd9Sstevel@tonic-gate #else
13617c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, FCTTV, FC_DEFAULT_TX_TIMER);
13627c478bd9Sstevel@tonic-gate #endif
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 	/* Set the flow control receive threshold registers.  Normally,
13657c478bd9Sstevel@tonic-gate 	 * these registers will be set to a default threshold that may be
13667c478bd9Sstevel@tonic-gate 	 * adjusted later by the driver's runtime code.  However, if the
13677c478bd9Sstevel@tonic-gate 	 * ability to transmit pause frames in not enabled, then these
13687c478bd9Sstevel@tonic-gate 	 * registers will be set to 0.
13697c478bd9Sstevel@tonic-gate 	 */
13707c478bd9Sstevel@tonic-gate 	if(!(hw->fc & e1000_fc_tx_pause)) {
13717c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, FCRTL, 0);
13727c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, FCRTH, 0);
13737c478bd9Sstevel@tonic-gate 	} else {
13747c478bd9Sstevel@tonic-gate 		/* We need to set up the Receive Threshold high and low water marks
13757c478bd9Sstevel@tonic-gate 		 * as well as (optionally) enabling the transmission of XON frames.
13767c478bd9Sstevel@tonic-gate 		 */
13777c478bd9Sstevel@tonic-gate #if 0
13787c478bd9Sstevel@tonic-gate 		if(hw->fc_send_xon) {
13797c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
13807c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
13817c478bd9Sstevel@tonic-gate 		} else {
13827c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
13837c478bd9Sstevel@tonic-gate 			E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
13847c478bd9Sstevel@tonic-gate 		}
13857c478bd9Sstevel@tonic-gate #else
13867c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, FCRTL, (FC_DEFAULT_LO_THRESH | E1000_FCRTL_XONE));
13877c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, FCRTH, FC_DEFAULT_HI_THRESH);
13887c478bd9Sstevel@tonic-gate #endif
13897c478bd9Sstevel@tonic-gate 	}
13907c478bd9Sstevel@tonic-gate 	return ret_val;
13917c478bd9Sstevel@tonic-gate }
13927c478bd9Sstevel@tonic-gate 
13937c478bd9Sstevel@tonic-gate /******************************************************************************
13947c478bd9Sstevel@tonic-gate  * Sets up link for a fiber based or serdes based adapter
13957c478bd9Sstevel@tonic-gate  *
13967c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
13977c478bd9Sstevel@tonic-gate  *
13987c478bd9Sstevel@tonic-gate  * Manipulates Physical Coding Sublayer functions in order to configure
13997c478bd9Sstevel@tonic-gate  * link. Assumes the hardware has been previously reset and the transmitter
14007c478bd9Sstevel@tonic-gate  * and receiver are not enabled.
14017c478bd9Sstevel@tonic-gate  *****************************************************************************/
14027c478bd9Sstevel@tonic-gate static int
14037c478bd9Sstevel@tonic-gate e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
14047c478bd9Sstevel@tonic-gate {
14057c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
14067c478bd9Sstevel@tonic-gate 	uint32_t status;
14077c478bd9Sstevel@tonic-gate 	uint32_t txcw = 0;
14087c478bd9Sstevel@tonic-gate 	uint32_t i;
14097c478bd9Sstevel@tonic-gate 	uint32_t signal = 0;
14107c478bd9Sstevel@tonic-gate 	int32_t ret_val;
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_setup_fiber_serdes_link");
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate 	/* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
14157c478bd9Sstevel@tonic-gate 	 * set when the optics detect a signal. On older adapters, it will be
14167c478bd9Sstevel@tonic-gate 	 * cleared when there is a signal.  This applies to fiber media only.
14177c478bd9Sstevel@tonic-gate 	 * If we're on serdes media, adjust the output amplitude to value set in
14187c478bd9Sstevel@tonic-gate 	 * the EEPROM.
14197c478bd9Sstevel@tonic-gate 	 */
14207c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
14217c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_fiber)
14227c478bd9Sstevel@tonic-gate 		signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
14237c478bd9Sstevel@tonic-gate 
14247c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_adjust_serdes_amplitude(hw)))
14257c478bd9Sstevel@tonic-gate 		return ret_val;
14267c478bd9Sstevel@tonic-gate 
14277c478bd9Sstevel@tonic-gate 	/* Take the link out of reset */
14287c478bd9Sstevel@tonic-gate 	ctrl &= ~(E1000_CTRL_LRST);
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate #if 0
14317c478bd9Sstevel@tonic-gate 	/* Adjust VCO speed to improve BER performance */
14327c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_set_vco_speed(hw)))
14337c478bd9Sstevel@tonic-gate 		return ret_val;
14347c478bd9Sstevel@tonic-gate #endif
14357c478bd9Sstevel@tonic-gate 
14367c478bd9Sstevel@tonic-gate 	e1000_config_collision_dist(hw);
14377c478bd9Sstevel@tonic-gate 
14387c478bd9Sstevel@tonic-gate 	/* Check for a software override of the flow control settings, and setup
14397c478bd9Sstevel@tonic-gate 	 * the device accordingly.  If auto-negotiation is enabled, then software
14407c478bd9Sstevel@tonic-gate 	 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
14417c478bd9Sstevel@tonic-gate 	 * Config Word Register (TXCW) and re-start auto-negotiation.  However, if
14427c478bd9Sstevel@tonic-gate 	 * auto-negotiation is disabled, then software will have to manually
14437c478bd9Sstevel@tonic-gate 	 * configure the two flow control enable bits in the CTRL register.
14447c478bd9Sstevel@tonic-gate 	 *
14457c478bd9Sstevel@tonic-gate 	 * The possible values of the "fc" parameter are:
14467c478bd9Sstevel@tonic-gate 	 *      0:  Flow control is completely disabled
14477c478bd9Sstevel@tonic-gate 	 *      1:  Rx flow control is enabled (we can receive pause frames, but
14487c478bd9Sstevel@tonic-gate 	 *          not send pause frames).
14497c478bd9Sstevel@tonic-gate 	 *      2:  Tx flow control is enabled (we can send pause frames but we do
14507c478bd9Sstevel@tonic-gate 	 *          not support receiving pause frames).
14517c478bd9Sstevel@tonic-gate 	 *      3:  Both Rx and TX flow control (symmetric) are enabled.
14527c478bd9Sstevel@tonic-gate 	 */
14537c478bd9Sstevel@tonic-gate 	switch (hw->fc) {
14547c478bd9Sstevel@tonic-gate 	case e1000_fc_none:
14557c478bd9Sstevel@tonic-gate 		/* Flow control is completely disabled by a software over-ride. */
14567c478bd9Sstevel@tonic-gate 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
14577c478bd9Sstevel@tonic-gate 		break;
14587c478bd9Sstevel@tonic-gate 	case e1000_fc_rx_pause:
14597c478bd9Sstevel@tonic-gate 		/* RX Flow control is enabled and TX Flow control is disabled by a
14607c478bd9Sstevel@tonic-gate 		 * software over-ride. Since there really isn't a way to advertise
14617c478bd9Sstevel@tonic-gate 		 * that we are capable of RX Pause ONLY, we will advertise that we
14627c478bd9Sstevel@tonic-gate 		 * support both symmetric and asymmetric RX PAUSE. Later, we will
14637c478bd9Sstevel@tonic-gate 		 *  disable the adapter's ability to send PAUSE frames.
14647c478bd9Sstevel@tonic-gate 		 */
14657c478bd9Sstevel@tonic-gate 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
14667c478bd9Sstevel@tonic-gate 		break;
14677c478bd9Sstevel@tonic-gate 	case e1000_fc_tx_pause:
14687c478bd9Sstevel@tonic-gate 		/* TX Flow control is enabled, and RX Flow control is disabled, by a
14697c478bd9Sstevel@tonic-gate 		 * software over-ride.
14707c478bd9Sstevel@tonic-gate 		 */
14717c478bd9Sstevel@tonic-gate 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
14727c478bd9Sstevel@tonic-gate 		break;
14737c478bd9Sstevel@tonic-gate 	case e1000_fc_full:
14747c478bd9Sstevel@tonic-gate 		/* Flow control (both RX and TX) is enabled by a software over-ride. */
14757c478bd9Sstevel@tonic-gate 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
14767c478bd9Sstevel@tonic-gate 		break;
14777c478bd9Sstevel@tonic-gate 	default:
14787c478bd9Sstevel@tonic-gate 		DEBUGOUT("Flow control param set incorrectly\n");
14797c478bd9Sstevel@tonic-gate 		return -E1000_ERR_CONFIG;
14807c478bd9Sstevel@tonic-gate 		break;
14817c478bd9Sstevel@tonic-gate 	}
14827c478bd9Sstevel@tonic-gate 
14837c478bd9Sstevel@tonic-gate 	/* Since auto-negotiation is enabled, take the link out of reset (the link
14847c478bd9Sstevel@tonic-gate 	 * will be in reset, because we previously reset the chip). This will
14857c478bd9Sstevel@tonic-gate 	 * restart auto-negotiation.  If auto-neogtiation is successful then the
14867c478bd9Sstevel@tonic-gate 	 * link-up status bit will be set and the flow control enable bits (RFCE
14877c478bd9Sstevel@tonic-gate 	 * and TFCE) will be set according to their negotiated value.
14887c478bd9Sstevel@tonic-gate 	 */
14897c478bd9Sstevel@tonic-gate 	DEBUGOUT("Auto-negotiation enabled\n");
14907c478bd9Sstevel@tonic-gate 
14917c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, TXCW, txcw);
14927c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, ctrl);
14937c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate 	hw->txcw = txcw;
14967c478bd9Sstevel@tonic-gate 	mdelay(1);
14977c478bd9Sstevel@tonic-gate 
14987c478bd9Sstevel@tonic-gate 	/* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
14997c478bd9Sstevel@tonic-gate 	 * indication in the Device Status Register.  Time-out if a link isn't
15007c478bd9Sstevel@tonic-gate 	 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
15017c478bd9Sstevel@tonic-gate 	 * less than 500 milliseconds even if the other end is doing it in SW).
15027c478bd9Sstevel@tonic-gate 	 * For internal serdes, we just assume a signal is present, then poll.
15037c478bd9Sstevel@tonic-gate 	 */
15047c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_internal_serdes ||
15057c478bd9Sstevel@tonic-gate 	   (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
15067c478bd9Sstevel@tonic-gate 		DEBUGOUT("Looking for Link\n");
15077c478bd9Sstevel@tonic-gate 		for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
15087c478bd9Sstevel@tonic-gate 			mdelay(10);
15097c478bd9Sstevel@tonic-gate 			status = E1000_READ_REG(hw, STATUS);
15107c478bd9Sstevel@tonic-gate 			if(status & E1000_STATUS_LU) break;
15117c478bd9Sstevel@tonic-gate 		}
15127c478bd9Sstevel@tonic-gate 		if(i == (LINK_UP_TIMEOUT / 10)) {
15137c478bd9Sstevel@tonic-gate 			DEBUGOUT("Never got a valid link from auto-neg!!!\n");
15147c478bd9Sstevel@tonic-gate 			hw->autoneg_failed = 1;
15157c478bd9Sstevel@tonic-gate 			/* AutoNeg failed to achieve a link, so we'll call
15167c478bd9Sstevel@tonic-gate 			 * e1000_check_for_link. This routine will force the link up if
15177c478bd9Sstevel@tonic-gate 			 * we detect a signal. This will allow us to communicate with
15187c478bd9Sstevel@tonic-gate 			 * non-autonegotiating link partners.
15197c478bd9Sstevel@tonic-gate 			 */
15207c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_check_for_link(hw))) {
15217c478bd9Sstevel@tonic-gate 				DEBUGOUT("Error while checking for link\n");
15227c478bd9Sstevel@tonic-gate 				return ret_val;
15237c478bd9Sstevel@tonic-gate 			}
15247c478bd9Sstevel@tonic-gate 			hw->autoneg_failed = 0;
15257c478bd9Sstevel@tonic-gate 		} else {
15267c478bd9Sstevel@tonic-gate 			hw->autoneg_failed = 0;
15277c478bd9Sstevel@tonic-gate 			DEBUGOUT("Valid Link Found\n");
15287c478bd9Sstevel@tonic-gate 		}
15297c478bd9Sstevel@tonic-gate 	} else {
15307c478bd9Sstevel@tonic-gate 		DEBUGOUT("No Signal Detected\n");
15317c478bd9Sstevel@tonic-gate 	}
15327c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
15337c478bd9Sstevel@tonic-gate }
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate /******************************************************************************
15367c478bd9Sstevel@tonic-gate * Detects which PHY is present and the speed and duplex
15377c478bd9Sstevel@tonic-gate *
15387c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
15397c478bd9Sstevel@tonic-gate ******************************************************************************/
15407c478bd9Sstevel@tonic-gate static int
15417c478bd9Sstevel@tonic-gate e1000_setup_copper_link(struct e1000_hw *hw)
15427c478bd9Sstevel@tonic-gate {
15437c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
15447c478bd9Sstevel@tonic-gate 	int32_t ret_val;
15457c478bd9Sstevel@tonic-gate 	uint16_t i;
15467c478bd9Sstevel@tonic-gate 	uint16_t phy_data;
15477c478bd9Sstevel@tonic-gate 
15487c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_setup_copper_link");
15497c478bd9Sstevel@tonic-gate 
15507c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
15517c478bd9Sstevel@tonic-gate 	/* With 82543, we need to force speed and duplex on the MAC equal to what
15527c478bd9Sstevel@tonic-gate 	 * the PHY speed and duplex configuration is. In addition, we need to
15537c478bd9Sstevel@tonic-gate 	 * perform a hardware reset on the PHY to take it out of reset.
15547c478bd9Sstevel@tonic-gate 	 */
15557c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82543) {
15567c478bd9Sstevel@tonic-gate 		ctrl |= E1000_CTRL_SLU;
15577c478bd9Sstevel@tonic-gate 		ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
15587c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl);
15597c478bd9Sstevel@tonic-gate 	} else {
15607c478bd9Sstevel@tonic-gate 		ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
15617c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl);
15627c478bd9Sstevel@tonic-gate 		e1000_phy_hw_reset(hw);
15637c478bd9Sstevel@tonic-gate 	}
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate 	/* Make sure we have a valid PHY */
15667c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_detect_gig_phy(hw))) {
15677c478bd9Sstevel@tonic-gate 		DEBUGOUT("Error, did not detect valid phy.\n");
15687c478bd9Sstevel@tonic-gate 		return ret_val;
15697c478bd9Sstevel@tonic-gate 	}
15707c478bd9Sstevel@tonic-gate 	DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
15717c478bd9Sstevel@tonic-gate 
15727c478bd9Sstevel@tonic-gate 	if(hw->mac_type <= e1000_82543 ||
15737c478bd9Sstevel@tonic-gate 	   hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
15747c478bd9Sstevel@tonic-gate #if 0
15757c478bd9Sstevel@tonic-gate 	   hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
15767c478bd9Sstevel@tonic-gate 		hw->phy_reset_disable = FALSE;
15777c478bd9Sstevel@tonic-gate 
15787c478bd9Sstevel@tonic-gate 	if(!hw->phy_reset_disable) {
15797c478bd9Sstevel@tonic-gate #else
15807c478bd9Sstevel@tonic-gate 	   hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
15817c478bd9Sstevel@tonic-gate #endif
15827c478bd9Sstevel@tonic-gate 	if (hw->phy_type == e1000_phy_igp) {
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_phy_reset(hw))) {
15857c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error Resetting the PHY\n");
15867c478bd9Sstevel@tonic-gate 			return ret_val;
15877c478bd9Sstevel@tonic-gate 		}
15887c478bd9Sstevel@tonic-gate 
15897c478bd9Sstevel@tonic-gate 		/* Wait 10ms for MAC to configure PHY from eeprom settings */
15907c478bd9Sstevel@tonic-gate 		mdelay(15);
15917c478bd9Sstevel@tonic-gate 
15927c478bd9Sstevel@tonic-gate #if 0
15937c478bd9Sstevel@tonic-gate 		/* disable lplu d3 during driver init */
15947c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_set_d3_lplu_state(hw, FALSE))) {
15957c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error Disabling LPLU D3\n");
15967c478bd9Sstevel@tonic-gate 			return ret_val;
15977c478bd9Sstevel@tonic-gate 		}
15987c478bd9Sstevel@tonic-gate 
15997c478bd9Sstevel@tonic-gate 		/* Configure mdi-mdix settings */
16007c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
16017c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
16027c478bd9Sstevel@tonic-gate 			return ret_val;
16037c478bd9Sstevel@tonic-gate 
16047c478bd9Sstevel@tonic-gate 		if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
16057c478bd9Sstevel@tonic-gate 			hw->dsp_config_state = e1000_dsp_config_disabled;
16067c478bd9Sstevel@tonic-gate 			/* Force MDI for IGP B-0 PHY */
16077c478bd9Sstevel@tonic-gate 			phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
16087c478bd9Sstevel@tonic-gate 			              IGP01E1000_PSCR_FORCE_MDI_MDIX);
16097c478bd9Sstevel@tonic-gate 			hw->mdix = 1;
16107c478bd9Sstevel@tonic-gate 
16117c478bd9Sstevel@tonic-gate 		} else {
16127c478bd9Sstevel@tonic-gate 			hw->dsp_config_state = e1000_dsp_config_enabled;
16137c478bd9Sstevel@tonic-gate 			phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate 			switch (hw->mdix) {
16167c478bd9Sstevel@tonic-gate 			case 1:
16177c478bd9Sstevel@tonic-gate 				phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
16187c478bd9Sstevel@tonic-gate 				break;
16197c478bd9Sstevel@tonic-gate 			case 2:
16207c478bd9Sstevel@tonic-gate 				phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
16217c478bd9Sstevel@tonic-gate 				break;
16227c478bd9Sstevel@tonic-gate 			case 0:
16237c478bd9Sstevel@tonic-gate 			default:
16247c478bd9Sstevel@tonic-gate 				phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
16257c478bd9Sstevel@tonic-gate 				break;
16267c478bd9Sstevel@tonic-gate 			}
16277c478bd9Sstevel@tonic-gate 		}
16287c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
16297c478bd9Sstevel@tonic-gate 		                                  phy_data)))
16307c478bd9Sstevel@tonic-gate 			return ret_val;
16317c478bd9Sstevel@tonic-gate 
16327c478bd9Sstevel@tonic-gate 		/* set auto-master slave resolution settings */
16337c478bd9Sstevel@tonic-gate 		e1000_ms_type phy_ms_setting = hw->master_slave;
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate 		if(hw->ffe_config_state == e1000_ffe_config_active)
16367c478bd9Sstevel@tonic-gate 			hw->ffe_config_state = e1000_ffe_config_enabled;
16377c478bd9Sstevel@tonic-gate 
16387c478bd9Sstevel@tonic-gate 		if(hw->dsp_config_state == e1000_dsp_config_activated)
16397c478bd9Sstevel@tonic-gate 			hw->dsp_config_state = e1000_dsp_config_enabled;
16407c478bd9Sstevel@tonic-gate #endif
16417c478bd9Sstevel@tonic-gate 
16427c478bd9Sstevel@tonic-gate 		/* when autonegotiation advertisment is only 1000Mbps then we
16437c478bd9Sstevel@tonic-gate 		 * should disable SmartSpeed and enable Auto MasterSlave
16447c478bd9Sstevel@tonic-gate 		 * resolution as hardware default. */
16457c478bd9Sstevel@tonic-gate 		if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
16467c478bd9Sstevel@tonic-gate 			/* Disable SmartSpeed */
16477c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_read_phy_reg(hw,
16487c478bd9Sstevel@tonic-gate 			                                 IGP01E1000_PHY_PORT_CONFIG,
16497c478bd9Sstevel@tonic-gate 			                                 &phy_data)))
16507c478bd9Sstevel@tonic-gate 				return ret_val;
16517c478bd9Sstevel@tonic-gate 			phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
16527c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_write_phy_reg(hw,
16537c478bd9Sstevel@tonic-gate 			                                  IGP01E1000_PHY_PORT_CONFIG,
16547c478bd9Sstevel@tonic-gate 			                                  phy_data)))
16557c478bd9Sstevel@tonic-gate 				return ret_val;
16567c478bd9Sstevel@tonic-gate 			/* Set auto Master/Slave resolution process */
16577c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
16587c478bd9Sstevel@tonic-gate 			                                 &phy_data)))
16597c478bd9Sstevel@tonic-gate 				return ret_val;
16607c478bd9Sstevel@tonic-gate 			phy_data &= ~CR_1000T_MS_ENABLE;
16617c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
16627c478bd9Sstevel@tonic-gate 			                                  phy_data)))
16637c478bd9Sstevel@tonic-gate 				return ret_val;
16647c478bd9Sstevel@tonic-gate 		}
16657c478bd9Sstevel@tonic-gate 
16667c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
16677c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
16687c478bd9Sstevel@tonic-gate 			return ret_val;
16697c478bd9Sstevel@tonic-gate 
16707c478bd9Sstevel@tonic-gate #if 0
16717c478bd9Sstevel@tonic-gate 		/* load defaults for future use */
16727c478bd9Sstevel@tonic-gate 		hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
16737c478bd9Sstevel@tonic-gate 		                            ((phy_data & CR_1000T_MS_VALUE) ?
16747c478bd9Sstevel@tonic-gate 		                             e1000_ms_force_master :
16757c478bd9Sstevel@tonic-gate 		                             e1000_ms_force_slave) :
16767c478bd9Sstevel@tonic-gate 		                             e1000_ms_auto;
16777c478bd9Sstevel@tonic-gate 
16787c478bd9Sstevel@tonic-gate 		switch (phy_ms_setting) {
16797c478bd9Sstevel@tonic-gate 		case e1000_ms_force_master:
16807c478bd9Sstevel@tonic-gate 			phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
16817c478bd9Sstevel@tonic-gate 			break;
16827c478bd9Sstevel@tonic-gate 		case e1000_ms_force_slave:
16837c478bd9Sstevel@tonic-gate 			phy_data |= CR_1000T_MS_ENABLE;
16847c478bd9Sstevel@tonic-gate 			phy_data &= ~(CR_1000T_MS_VALUE);
16857c478bd9Sstevel@tonic-gate 			break;
16867c478bd9Sstevel@tonic-gate 		case e1000_ms_auto:
16877c478bd9Sstevel@tonic-gate 			phy_data &= ~CR_1000T_MS_ENABLE;
16887c478bd9Sstevel@tonic-gate 		default:
16897c478bd9Sstevel@tonic-gate 			break;
16907c478bd9Sstevel@tonic-gate 		}
16917c478bd9Sstevel@tonic-gate #endif
16927c478bd9Sstevel@tonic-gate 
16937c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
16947c478bd9Sstevel@tonic-gate 		                                  phy_data)))
16957c478bd9Sstevel@tonic-gate 			return ret_val;
16967c478bd9Sstevel@tonic-gate 	} else {
16977c478bd9Sstevel@tonic-gate 		/* Enable CRS on TX. This must be set for half-duplex operation. */
16987c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
16997c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
17007c478bd9Sstevel@tonic-gate 			return ret_val;
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 		phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate 		/* Options:
17057c478bd9Sstevel@tonic-gate 		 *   MDI/MDI-X = 0 (default)
17067c478bd9Sstevel@tonic-gate 		 *   0 - Auto for all speeds
17077c478bd9Sstevel@tonic-gate 		 *   1 - MDI mode
17087c478bd9Sstevel@tonic-gate 		 *   2 - MDI-X mode
17097c478bd9Sstevel@tonic-gate 		 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
17107c478bd9Sstevel@tonic-gate 		 */
17117c478bd9Sstevel@tonic-gate #if 0
17127c478bd9Sstevel@tonic-gate 		phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
17137c478bd9Sstevel@tonic-gate 
17147c478bd9Sstevel@tonic-gate 		switch (hw->mdix) {
17157c478bd9Sstevel@tonic-gate 		case 1:
17167c478bd9Sstevel@tonic-gate 			phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
17177c478bd9Sstevel@tonic-gate 			break;
17187c478bd9Sstevel@tonic-gate 		case 2:
17197c478bd9Sstevel@tonic-gate 			phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
17207c478bd9Sstevel@tonic-gate 			break;
17217c478bd9Sstevel@tonic-gate 		case 3:
17227c478bd9Sstevel@tonic-gate 			phy_data |= M88E1000_PSCR_AUTO_X_1000T;
17237c478bd9Sstevel@tonic-gate 			break;
17247c478bd9Sstevel@tonic-gate 		case 0:
17257c478bd9Sstevel@tonic-gate 		default:
17267c478bd9Sstevel@tonic-gate #endif
17277c478bd9Sstevel@tonic-gate 			phy_data |= M88E1000_PSCR_AUTO_X_MODE;
17287c478bd9Sstevel@tonic-gate #if 0
17297c478bd9Sstevel@tonic-gate 			break;
17307c478bd9Sstevel@tonic-gate 		}
17317c478bd9Sstevel@tonic-gate #endif
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate 		/* Options:
17347c478bd9Sstevel@tonic-gate 		 *   disable_polarity_correction = 0 (default)
17357c478bd9Sstevel@tonic-gate 		 *       Automatic Correction for Reversed Cable Polarity
17367c478bd9Sstevel@tonic-gate 		 *   0 - Disabled
17377c478bd9Sstevel@tonic-gate 		 *   1 - Enabled
17387c478bd9Sstevel@tonic-gate 		 */
17397c478bd9Sstevel@tonic-gate 		phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
17407c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
17417c478bd9Sstevel@tonic-gate 		                                  phy_data)))
17427c478bd9Sstevel@tonic-gate 			return ret_val;
17437c478bd9Sstevel@tonic-gate 
17447c478bd9Sstevel@tonic-gate 		/* Force TX_CLK in the Extended PHY Specific Control Register
17457c478bd9Sstevel@tonic-gate 		 * to 25MHz clock.
17467c478bd9Sstevel@tonic-gate 		 */
17477c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
17487c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
17497c478bd9Sstevel@tonic-gate 			return ret_val;
17507c478bd9Sstevel@tonic-gate 
17517c478bd9Sstevel@tonic-gate 		phy_data |= M88E1000_EPSCR_TX_CLK_25;
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER
17547c478bd9Sstevel@tonic-gate 		if (hw->phy_revision < M88E1011_I_REV_4) {
17557c478bd9Sstevel@tonic-gate #endif
17567c478bd9Sstevel@tonic-gate 			/* Configure Master and Slave downshift values */
17577c478bd9Sstevel@tonic-gate 			phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
17587c478bd9Sstevel@tonic-gate 				M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
17597c478bd9Sstevel@tonic-gate 			phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
17607c478bd9Sstevel@tonic-gate 				M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
17617c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_write_phy_reg(hw,
17627c478bd9Sstevel@tonic-gate 			                                  M88E1000_EXT_PHY_SPEC_CTRL,
17637c478bd9Sstevel@tonic-gate 			                                  phy_data)))
17647c478bd9Sstevel@tonic-gate 				return ret_val;
17657c478bd9Sstevel@tonic-gate 		}
17667c478bd9Sstevel@tonic-gate 
17677c478bd9Sstevel@tonic-gate 		/* SW Reset the PHY so all changes take effect */
17687c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_phy_reset(hw))) {
17697c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error Resetting the PHY\n");
17707c478bd9Sstevel@tonic-gate 			return ret_val;
17717c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER
17727c478bd9Sstevel@tonic-gate 		}
17737c478bd9Sstevel@tonic-gate #endif
17747c478bd9Sstevel@tonic-gate 	}
17757c478bd9Sstevel@tonic-gate 
17767c478bd9Sstevel@tonic-gate 	/* Options:
17777c478bd9Sstevel@tonic-gate 	 *   autoneg = 1 (default)
17787c478bd9Sstevel@tonic-gate 	 *      PHY will advertise value(s) parsed from
17797c478bd9Sstevel@tonic-gate 	 *      autoneg_advertised and fc
17807c478bd9Sstevel@tonic-gate 	 *   autoneg = 0
17817c478bd9Sstevel@tonic-gate 	 *      PHY will be set to 10H, 10F, 100H, or 100F
17827c478bd9Sstevel@tonic-gate 	 *      depending on value parsed from forced_speed_duplex.
17837c478bd9Sstevel@tonic-gate 	 */
17847c478bd9Sstevel@tonic-gate 
17857c478bd9Sstevel@tonic-gate 	/* Is autoneg enabled?  This is enabled by default or by software
17867c478bd9Sstevel@tonic-gate 	 * override.  If so, call e1000_phy_setup_autoneg routine to parse the
17877c478bd9Sstevel@tonic-gate 	 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
17887c478bd9Sstevel@tonic-gate 	 * the user should have provided a speed/duplex override.  If so, then
17897c478bd9Sstevel@tonic-gate 	 * call e1000_phy_force_speed_duplex to parse and set this up.
17907c478bd9Sstevel@tonic-gate 	 */
17917c478bd9Sstevel@tonic-gate 	/* Perform some bounds checking on the hw->autoneg_advertised
17927c478bd9Sstevel@tonic-gate 	 * parameter.  If this variable is zero, then set it to the default.
17937c478bd9Sstevel@tonic-gate 	 */
17947c478bd9Sstevel@tonic-gate 	hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 	/* If autoneg_advertised is zero, we assume it was not defaulted
17977c478bd9Sstevel@tonic-gate 	 * by the calling code so we set to advertise full capability.
17987c478bd9Sstevel@tonic-gate 	 */
17997c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised == 0)
18007c478bd9Sstevel@tonic-gate 		hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
18017c478bd9Sstevel@tonic-gate 
18027c478bd9Sstevel@tonic-gate 	DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
18037c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_phy_setup_autoneg(hw))) {
18047c478bd9Sstevel@tonic-gate 		DEBUGOUT("Error Setting up Auto-Negotiation\n");
18057c478bd9Sstevel@tonic-gate 		return ret_val;
18067c478bd9Sstevel@tonic-gate 	}
18077c478bd9Sstevel@tonic-gate 	DEBUGOUT("Restarting Auto-Neg\n");
18087c478bd9Sstevel@tonic-gate 
18097c478bd9Sstevel@tonic-gate 	/* Restart auto-negotiation by setting the Auto Neg Enable bit and
18107c478bd9Sstevel@tonic-gate 	 * the Auto Neg Restart bit in the PHY control register.
18117c478bd9Sstevel@tonic-gate 	 */
18127c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
18137c478bd9Sstevel@tonic-gate 		return ret_val;
18147c478bd9Sstevel@tonic-gate 
18157c478bd9Sstevel@tonic-gate 	phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
18167c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
18177c478bd9Sstevel@tonic-gate 		return ret_val;
18187c478bd9Sstevel@tonic-gate 
18197c478bd9Sstevel@tonic-gate #if 0
18207c478bd9Sstevel@tonic-gate 	/* Does the user want to wait for Auto-Neg to complete here, or
18217c478bd9Sstevel@tonic-gate 	 * check at a later time (for example, callback routine).
18227c478bd9Sstevel@tonic-gate 	 */
18237c478bd9Sstevel@tonic-gate 	if(hw->wait_autoneg_complete) {
18247c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_wait_autoneg(hw))) {
18257c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error while waiting for autoneg to complete\n");
18267c478bd9Sstevel@tonic-gate 			return ret_val;
18277c478bd9Sstevel@tonic-gate 		}
18287c478bd9Sstevel@tonic-gate 	}
18297c478bd9Sstevel@tonic-gate #else
18307c478bd9Sstevel@tonic-gate 	/* If we do not wait for autonegotiation to complete I
18317c478bd9Sstevel@tonic-gate 	 * do not see a valid link status.
18327c478bd9Sstevel@tonic-gate 	 */
18337c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_wait_autoneg(hw))) {
18347c478bd9Sstevel@tonic-gate 		DEBUGOUT("Error while waiting for autoneg to complete\n");
18357c478bd9Sstevel@tonic-gate 		return ret_val;
18367c478bd9Sstevel@tonic-gate 	}
18377c478bd9Sstevel@tonic-gate #endif
18387c478bd9Sstevel@tonic-gate 	} /* !hw->phy_reset_disable */
18397c478bd9Sstevel@tonic-gate 
18407c478bd9Sstevel@tonic-gate 	/* Check link status. Wait up to 100 microseconds for link to become
18417c478bd9Sstevel@tonic-gate 	 * valid.
18427c478bd9Sstevel@tonic-gate 	 */
18437c478bd9Sstevel@tonic-gate 	for(i = 0; i < 10; i++) {
18447c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
18457c478bd9Sstevel@tonic-gate 			return ret_val;
18467c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
18477c478bd9Sstevel@tonic-gate 			return ret_val;
18487c478bd9Sstevel@tonic-gate 
18497c478bd9Sstevel@tonic-gate 		if(phy_data & MII_SR_LINK_STATUS) {
18507c478bd9Sstevel@tonic-gate 			/* We have link, so we need to finish the config process:
18517c478bd9Sstevel@tonic-gate 			 *   1) Set up the MAC to the current PHY speed/duplex
18527c478bd9Sstevel@tonic-gate 			 *      if we are on 82543.  If we
18537c478bd9Sstevel@tonic-gate 			 *      are on newer silicon, we only need to configure
18547c478bd9Sstevel@tonic-gate 			 *      collision distance in the Transmit Control Register.
18557c478bd9Sstevel@tonic-gate 			 *   2) Set up flow control on the MAC to that established with
18567c478bd9Sstevel@tonic-gate 			 *      the link partner.
18577c478bd9Sstevel@tonic-gate 			 */
18587c478bd9Sstevel@tonic-gate 			if(hw->mac_type >= e1000_82544) {
18597c478bd9Sstevel@tonic-gate 				e1000_config_collision_dist(hw);
18607c478bd9Sstevel@tonic-gate 			} else {
18617c478bd9Sstevel@tonic-gate 				if((ret_val = e1000_config_mac_to_phy(hw))) {
18627c478bd9Sstevel@tonic-gate 					DEBUGOUT("Error configuring MAC to PHY settings\n");
18637c478bd9Sstevel@tonic-gate 					return ret_val;
18647c478bd9Sstevel@tonic-gate 				}
18657c478bd9Sstevel@tonic-gate 			}
18667c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_config_fc_after_link_up(hw))) {
18677c478bd9Sstevel@tonic-gate 				DEBUGOUT("Error Configuring Flow Control\n");
18687c478bd9Sstevel@tonic-gate 				return ret_val;
18697c478bd9Sstevel@tonic-gate 			}
18707c478bd9Sstevel@tonic-gate #if 0
18717c478bd9Sstevel@tonic-gate 			if(hw->phy_type == e1000_phy_igp) {
18727c478bd9Sstevel@tonic-gate 				if((ret_val = e1000_config_dsp_after_link_change(hw, TRUE))) {
18737c478bd9Sstevel@tonic-gate 					DEBUGOUT("Error Configuring DSP after link up\n");
18747c478bd9Sstevel@tonic-gate 					return ret_val;
18757c478bd9Sstevel@tonic-gate 				}
18767c478bd9Sstevel@tonic-gate 			}
18777c478bd9Sstevel@tonic-gate #endif
18787c478bd9Sstevel@tonic-gate 			DEBUGOUT("Valid link established!!!\n");
18797c478bd9Sstevel@tonic-gate 			return E1000_SUCCESS;
18807c478bd9Sstevel@tonic-gate 		}
18817c478bd9Sstevel@tonic-gate 		udelay(10);
18827c478bd9Sstevel@tonic-gate 	}
18837c478bd9Sstevel@tonic-gate 
18847c478bd9Sstevel@tonic-gate 	DEBUGOUT("Unable to establish link!!!\n");
18857c478bd9Sstevel@tonic-gate 	return -E1000_ERR_NOLINK;
18867c478bd9Sstevel@tonic-gate }
18877c478bd9Sstevel@tonic-gate 
18887c478bd9Sstevel@tonic-gate /******************************************************************************
18897c478bd9Sstevel@tonic-gate * Configures PHY autoneg and flow control advertisement settings
18907c478bd9Sstevel@tonic-gate *
18917c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
18927c478bd9Sstevel@tonic-gate ******************************************************************************/
18937c478bd9Sstevel@tonic-gate static int
18947c478bd9Sstevel@tonic-gate e1000_phy_setup_autoneg(struct e1000_hw *hw)
18957c478bd9Sstevel@tonic-gate {
18967c478bd9Sstevel@tonic-gate 	int32_t ret_val;
18977c478bd9Sstevel@tonic-gate 	uint16_t mii_autoneg_adv_reg;
18987c478bd9Sstevel@tonic-gate 	uint16_t mii_1000t_ctrl_reg;
18997c478bd9Sstevel@tonic-gate 
19007c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_phy_setup_autoneg");
19017c478bd9Sstevel@tonic-gate 
19027c478bd9Sstevel@tonic-gate 	/* Read the MII Auto-Neg Advertisement Register (Address 4). */
19037c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
19047c478bd9Sstevel@tonic-gate 	                                 &mii_autoneg_adv_reg)))
19057c478bd9Sstevel@tonic-gate 		return ret_val;
19067c478bd9Sstevel@tonic-gate 
19077c478bd9Sstevel@tonic-gate 	/* Read the MII 1000Base-T Control Register (Address 9). */
19087c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg)))
19097c478bd9Sstevel@tonic-gate 		return ret_val;
19107c478bd9Sstevel@tonic-gate 
19117c478bd9Sstevel@tonic-gate 	/* Need to parse both autoneg_advertised and fc and set up
19127c478bd9Sstevel@tonic-gate 	 * the appropriate PHY registers.  First we will parse for
19137c478bd9Sstevel@tonic-gate 	 * autoneg_advertised software override.  Since we can advertise
19147c478bd9Sstevel@tonic-gate 	 * a plethora of combinations, we need to check each bit
19157c478bd9Sstevel@tonic-gate 	 * individually.
19167c478bd9Sstevel@tonic-gate 	 */
19177c478bd9Sstevel@tonic-gate 
19187c478bd9Sstevel@tonic-gate 	/* First we clear all the 10/100 mb speed bits in the Auto-Neg
19197c478bd9Sstevel@tonic-gate 	 * Advertisement Register (Address 4) and the 1000 mb speed bits in
19207c478bd9Sstevel@tonic-gate 	 * the  1000Base-T Control Register (Address 9).
19217c478bd9Sstevel@tonic-gate 	 */
19227c478bd9Sstevel@tonic-gate 	mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
19237c478bd9Sstevel@tonic-gate 	mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
19247c478bd9Sstevel@tonic-gate 
19257c478bd9Sstevel@tonic-gate 	DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
19267c478bd9Sstevel@tonic-gate 
19277c478bd9Sstevel@tonic-gate 	/* Do we want to advertise 10 Mb Half Duplex? */
19287c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
19297c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 10mb Half duplex\n");
19307c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
19317c478bd9Sstevel@tonic-gate 	}
19327c478bd9Sstevel@tonic-gate 
19337c478bd9Sstevel@tonic-gate 	/* Do we want to advertise 10 Mb Full Duplex? */
19347c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
19357c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 10mb Full duplex\n");
19367c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
19377c478bd9Sstevel@tonic-gate 	}
19387c478bd9Sstevel@tonic-gate 
19397c478bd9Sstevel@tonic-gate 	/* Do we want to advertise 100 Mb Half Duplex? */
19407c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
19417c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 100mb Half duplex\n");
19427c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
19437c478bd9Sstevel@tonic-gate 	}
19447c478bd9Sstevel@tonic-gate 
19457c478bd9Sstevel@tonic-gate 	/* Do we want to advertise 100 Mb Full Duplex? */
19467c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
19477c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 100mb Full duplex\n");
19487c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
19497c478bd9Sstevel@tonic-gate 	}
19507c478bd9Sstevel@tonic-gate 
19517c478bd9Sstevel@tonic-gate 	/* We do not allow the Phy to advertise 1000 Mb Half Duplex */
19527c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
19537c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
19547c478bd9Sstevel@tonic-gate 	}
19557c478bd9Sstevel@tonic-gate 
19567c478bd9Sstevel@tonic-gate 	/* Do we want to advertise 1000 Mb Full Duplex? */
19577c478bd9Sstevel@tonic-gate 	if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
19587c478bd9Sstevel@tonic-gate 		DEBUGOUT("Advertise 1000mb Full duplex\n");
19597c478bd9Sstevel@tonic-gate 		mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
19607c478bd9Sstevel@tonic-gate 	}
19617c478bd9Sstevel@tonic-gate 
19627c478bd9Sstevel@tonic-gate 	/* Check for a software override of the flow control settings, and
19637c478bd9Sstevel@tonic-gate 	 * setup the PHY advertisement registers accordingly.  If
19647c478bd9Sstevel@tonic-gate 	 * auto-negotiation is enabled, then software will have to set the
19657c478bd9Sstevel@tonic-gate 	 * "PAUSE" bits to the correct value in the Auto-Negotiation
19667c478bd9Sstevel@tonic-gate 	 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
19677c478bd9Sstevel@tonic-gate 	 *
19687c478bd9Sstevel@tonic-gate 	 * The possible values of the "fc" parameter are:
19697c478bd9Sstevel@tonic-gate 	 *      0:  Flow control is completely disabled
19707c478bd9Sstevel@tonic-gate 	 *      1:  Rx flow control is enabled (we can receive pause frames
19717c478bd9Sstevel@tonic-gate 	 *          but not send pause frames).
19727c478bd9Sstevel@tonic-gate 	 *      2:  Tx flow control is enabled (we can send pause frames
19737c478bd9Sstevel@tonic-gate 	 *          but we do not support receiving pause frames).
19747c478bd9Sstevel@tonic-gate 	 *      3:  Both Rx and TX flow control (symmetric) are enabled.
19757c478bd9Sstevel@tonic-gate 	 *  other:  No software override.  The flow control configuration
19767c478bd9Sstevel@tonic-gate 	 *          in the EEPROM is used.
19777c478bd9Sstevel@tonic-gate 	 */
19787c478bd9Sstevel@tonic-gate 	switch (hw->fc) {
19797c478bd9Sstevel@tonic-gate 	case e1000_fc_none: /* 0 */
19807c478bd9Sstevel@tonic-gate 		/* Flow control (RX & TX) is completely disabled by a
19817c478bd9Sstevel@tonic-gate 		 * software over-ride.
19827c478bd9Sstevel@tonic-gate 		 */
19837c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
19847c478bd9Sstevel@tonic-gate 		break;
19857c478bd9Sstevel@tonic-gate 	case e1000_fc_rx_pause: /* 1 */
19867c478bd9Sstevel@tonic-gate 		/* RX Flow control is enabled, and TX Flow control is
19877c478bd9Sstevel@tonic-gate 		 * disabled, by a software over-ride.
19887c478bd9Sstevel@tonic-gate 		 */
19897c478bd9Sstevel@tonic-gate 		/* Since there really isn't a way to advertise that we are
19907c478bd9Sstevel@tonic-gate 		 * capable of RX Pause ONLY, we will advertise that we
19917c478bd9Sstevel@tonic-gate 		 * support both symmetric and asymmetric RX PAUSE.  Later
19927c478bd9Sstevel@tonic-gate 		 * (in e1000_config_fc_after_link_up) we will disable the
19937c478bd9Sstevel@tonic-gate 		 *hw's ability to send PAUSE frames.
19947c478bd9Sstevel@tonic-gate 		 */
19957c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
19967c478bd9Sstevel@tonic-gate 		break;
19977c478bd9Sstevel@tonic-gate 	case e1000_fc_tx_pause: /* 2 */
19987c478bd9Sstevel@tonic-gate 		/* TX Flow control is enabled, and RX Flow control is
19997c478bd9Sstevel@tonic-gate 		 * disabled, by a software over-ride.
20007c478bd9Sstevel@tonic-gate 		 */
20017c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
20027c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
20037c478bd9Sstevel@tonic-gate 		break;
20047c478bd9Sstevel@tonic-gate 	case e1000_fc_full: /* 3 */
20057c478bd9Sstevel@tonic-gate 		/* Flow control (both RX and TX) is enabled by a software
20067c478bd9Sstevel@tonic-gate 		 * over-ride.
20077c478bd9Sstevel@tonic-gate 		 */
20087c478bd9Sstevel@tonic-gate 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
20097c478bd9Sstevel@tonic-gate 		break;
20107c478bd9Sstevel@tonic-gate 	default:
20117c478bd9Sstevel@tonic-gate 		DEBUGOUT("Flow control param set incorrectly\n");
20127c478bd9Sstevel@tonic-gate 		return -E1000_ERR_CONFIG;
20137c478bd9Sstevel@tonic-gate 	}
20147c478bd9Sstevel@tonic-gate 
20157c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV,
20167c478bd9Sstevel@tonic-gate 	                       mii_autoneg_adv_reg)))
20177c478bd9Sstevel@tonic-gate 		return ret_val;
20187c478bd9Sstevel@tonic-gate 
20197c478bd9Sstevel@tonic-gate 	DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
20207c478bd9Sstevel@tonic-gate 
20217c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg)))
20227c478bd9Sstevel@tonic-gate 		return ret_val;
20237c478bd9Sstevel@tonic-gate 
20247c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
20257c478bd9Sstevel@tonic-gate }
20267c478bd9Sstevel@tonic-gate 
20277c478bd9Sstevel@tonic-gate /******************************************************************************
20287c478bd9Sstevel@tonic-gate * Sets the collision distance in the Transmit Control register
20297c478bd9Sstevel@tonic-gate *
20307c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
20317c478bd9Sstevel@tonic-gate *
20327c478bd9Sstevel@tonic-gate * Link should have been established previously. Reads the speed and duplex
20337c478bd9Sstevel@tonic-gate * information from the Device Status register.
20347c478bd9Sstevel@tonic-gate ******************************************************************************/
20357c478bd9Sstevel@tonic-gate static void
20367c478bd9Sstevel@tonic-gate e1000_config_collision_dist(struct e1000_hw *hw)
20377c478bd9Sstevel@tonic-gate {
20387c478bd9Sstevel@tonic-gate 	uint32_t tctl;
20397c478bd9Sstevel@tonic-gate 
20407c478bd9Sstevel@tonic-gate 	tctl = E1000_READ_REG(hw, TCTL);
20417c478bd9Sstevel@tonic-gate 
20427c478bd9Sstevel@tonic-gate 	tctl &= ~E1000_TCTL_COLD;
20437c478bd9Sstevel@tonic-gate 	tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
20447c478bd9Sstevel@tonic-gate 
20457c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, TCTL, tctl);
20467c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
20477c478bd9Sstevel@tonic-gate }
20487c478bd9Sstevel@tonic-gate 
20497c478bd9Sstevel@tonic-gate /******************************************************************************
20507c478bd9Sstevel@tonic-gate * Sets MAC speed and duplex settings to reflect the those in the PHY
20517c478bd9Sstevel@tonic-gate *
20527c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
20537c478bd9Sstevel@tonic-gate * mii_reg - data to write to the MII control register
20547c478bd9Sstevel@tonic-gate *
20557c478bd9Sstevel@tonic-gate * The contents of the PHY register containing the needed information need to
20567c478bd9Sstevel@tonic-gate * be passed in.
20577c478bd9Sstevel@tonic-gate ******************************************************************************/
20587c478bd9Sstevel@tonic-gate static int
20597c478bd9Sstevel@tonic-gate e1000_config_mac_to_phy(struct e1000_hw *hw)
20607c478bd9Sstevel@tonic-gate {
20617c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
20627c478bd9Sstevel@tonic-gate 	int32_t ret_val;
20637c478bd9Sstevel@tonic-gate 	uint16_t phy_data;
20647c478bd9Sstevel@tonic-gate 
20657c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_config_mac_to_phy");
20667c478bd9Sstevel@tonic-gate 
20677c478bd9Sstevel@tonic-gate 	/* Read the Device Control Register and set the bits to Force Speed
20687c478bd9Sstevel@tonic-gate 	 * and Duplex.
20697c478bd9Sstevel@tonic-gate 	 */
20707c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
20717c478bd9Sstevel@tonic-gate 	ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
20727c478bd9Sstevel@tonic-gate 	ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
20737c478bd9Sstevel@tonic-gate 
20747c478bd9Sstevel@tonic-gate 	/* Set up duplex in the Device Control and Transmit Control
20757c478bd9Sstevel@tonic-gate 	 * registers depending on negotiated values.
20767c478bd9Sstevel@tonic-gate 	 */
20777c478bd9Sstevel@tonic-gate 	if (hw->phy_type == e1000_phy_igp) {
20787c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
20797c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
20807c478bd9Sstevel@tonic-gate 			return ret_val;
20817c478bd9Sstevel@tonic-gate 
20827c478bd9Sstevel@tonic-gate 		if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
20837c478bd9Sstevel@tonic-gate 		else ctrl &= ~E1000_CTRL_FD;
20847c478bd9Sstevel@tonic-gate 
20857c478bd9Sstevel@tonic-gate 		e1000_config_collision_dist(hw);
20867c478bd9Sstevel@tonic-gate 
20877c478bd9Sstevel@tonic-gate 		/* Set up speed in the Device Control register depending on
20887c478bd9Sstevel@tonic-gate 		 * negotiated values.
20897c478bd9Sstevel@tonic-gate 		 */
20907c478bd9Sstevel@tonic-gate 		if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
20917c478bd9Sstevel@tonic-gate 		   IGP01E1000_PSSR_SPEED_1000MBPS)
20927c478bd9Sstevel@tonic-gate 			ctrl |= E1000_CTRL_SPD_1000;
20937c478bd9Sstevel@tonic-gate 		else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
20947c478bd9Sstevel@tonic-gate 			IGP01E1000_PSSR_SPEED_100MBPS)
20957c478bd9Sstevel@tonic-gate 			ctrl |= E1000_CTRL_SPD_100;
20967c478bd9Sstevel@tonic-gate 	} else {
20977c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
20987c478bd9Sstevel@tonic-gate 		                                 &phy_data)))
20997c478bd9Sstevel@tonic-gate 			return ret_val;
21007c478bd9Sstevel@tonic-gate 
21017c478bd9Sstevel@tonic-gate 		if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
21027c478bd9Sstevel@tonic-gate 		else ctrl &= ~E1000_CTRL_FD;
21037c478bd9Sstevel@tonic-gate 
21047c478bd9Sstevel@tonic-gate 		e1000_config_collision_dist(hw);
21057c478bd9Sstevel@tonic-gate 
21067c478bd9Sstevel@tonic-gate 		/* Set up speed in the Device Control register depending on
21077c478bd9Sstevel@tonic-gate 		 * negotiated values.
21087c478bd9Sstevel@tonic-gate 		 */
21097c478bd9Sstevel@tonic-gate 		if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
21107c478bd9Sstevel@tonic-gate 			ctrl |= E1000_CTRL_SPD_1000;
21117c478bd9Sstevel@tonic-gate 		else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
21127c478bd9Sstevel@tonic-gate 			ctrl |= E1000_CTRL_SPD_100;
21137c478bd9Sstevel@tonic-gate 	}
21147c478bd9Sstevel@tonic-gate 	/* Write the configured values back to the Device Control Reg. */
21157c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, ctrl);
21167c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
21177c478bd9Sstevel@tonic-gate }
21187c478bd9Sstevel@tonic-gate 
21197c478bd9Sstevel@tonic-gate /******************************************************************************
21207c478bd9Sstevel@tonic-gate  * Forces the MAC's flow control settings.
21217c478bd9Sstevel@tonic-gate  *
21227c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
21237c478bd9Sstevel@tonic-gate  *
21247c478bd9Sstevel@tonic-gate  * Sets the TFCE and RFCE bits in the device control register to reflect
21257c478bd9Sstevel@tonic-gate  * the adapter settings. TFCE and RFCE need to be explicitly set by
21267c478bd9Sstevel@tonic-gate  * software when a Copper PHY is used because autonegotiation is managed
21277c478bd9Sstevel@tonic-gate  * by the PHY rather than the MAC. Software must also configure these
21287c478bd9Sstevel@tonic-gate  * bits when link is forced on a fiber connection.
21297c478bd9Sstevel@tonic-gate  *****************************************************************************/
21307c478bd9Sstevel@tonic-gate static int
21317c478bd9Sstevel@tonic-gate e1000_force_mac_fc(struct e1000_hw *hw)
21327c478bd9Sstevel@tonic-gate {
21337c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
21347c478bd9Sstevel@tonic-gate 
21357c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_force_mac_fc");
21367c478bd9Sstevel@tonic-gate 
21377c478bd9Sstevel@tonic-gate 	/* Get the current configuration of the Device Control Register */
21387c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
21397c478bd9Sstevel@tonic-gate 
21407c478bd9Sstevel@tonic-gate 	/* Because we didn't get link via the internal auto-negotiation
21417c478bd9Sstevel@tonic-gate 	 * mechanism (we either forced link or we got link via PHY
21427c478bd9Sstevel@tonic-gate 	 * auto-neg), we have to manually enable/disable transmit an
21437c478bd9Sstevel@tonic-gate 	 * receive flow control.
21447c478bd9Sstevel@tonic-gate 	 *
21457c478bd9Sstevel@tonic-gate 	 * The "Case" statement below enables/disable flow control
21467c478bd9Sstevel@tonic-gate 	 * according to the "hw->fc" parameter.
21477c478bd9Sstevel@tonic-gate 	 *
21487c478bd9Sstevel@tonic-gate 	 * The possible values of the "fc" parameter are:
21497c478bd9Sstevel@tonic-gate 	 *      0:  Flow control is completely disabled
21507c478bd9Sstevel@tonic-gate 	 *      1:  Rx flow control is enabled (we can receive pause
21517c478bd9Sstevel@tonic-gate 	 *          frames but not send pause frames).
21527c478bd9Sstevel@tonic-gate 	 *      2:  Tx flow control is enabled (we can send pause frames
21537c478bd9Sstevel@tonic-gate 	 *          frames but we do not receive pause frames).
21547c478bd9Sstevel@tonic-gate 	 *      3:  Both Rx and TX flow control (symmetric) is enabled.
21557c478bd9Sstevel@tonic-gate 	 *  other:  No other values should be possible at this point.
21567c478bd9Sstevel@tonic-gate 	 */
21577c478bd9Sstevel@tonic-gate 
21587c478bd9Sstevel@tonic-gate 	switch (hw->fc) {
21597c478bd9Sstevel@tonic-gate 	case e1000_fc_none:
21607c478bd9Sstevel@tonic-gate 		ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
21617c478bd9Sstevel@tonic-gate 		break;
21627c478bd9Sstevel@tonic-gate 	case e1000_fc_rx_pause:
21637c478bd9Sstevel@tonic-gate 		ctrl &= (~E1000_CTRL_TFCE);
21647c478bd9Sstevel@tonic-gate 		ctrl |= E1000_CTRL_RFCE;
21657c478bd9Sstevel@tonic-gate 		break;
21667c478bd9Sstevel@tonic-gate 	case e1000_fc_tx_pause:
21677c478bd9Sstevel@tonic-gate 		ctrl &= (~E1000_CTRL_RFCE);
21687c478bd9Sstevel@tonic-gate 		ctrl |= E1000_CTRL_TFCE;
21697c478bd9Sstevel@tonic-gate 		break;
21707c478bd9Sstevel@tonic-gate 	case e1000_fc_full:
21717c478bd9Sstevel@tonic-gate 		ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
21727c478bd9Sstevel@tonic-gate 		break;
21737c478bd9Sstevel@tonic-gate 	default:
21747c478bd9Sstevel@tonic-gate 		DEBUGOUT("Flow control param set incorrectly\n");
21757c478bd9Sstevel@tonic-gate 		return -E1000_ERR_CONFIG;
21767c478bd9Sstevel@tonic-gate 	}
21777c478bd9Sstevel@tonic-gate 
21787c478bd9Sstevel@tonic-gate 	/* Disable TX Flow Control for 82542 (rev 2.0) */
21797c478bd9Sstevel@tonic-gate 	if(hw->mac_type == e1000_82542_rev2_0)
21807c478bd9Sstevel@tonic-gate 		ctrl &= (~E1000_CTRL_TFCE);
21817c478bd9Sstevel@tonic-gate 
21827c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, ctrl);
21837c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
21847c478bd9Sstevel@tonic-gate }
21857c478bd9Sstevel@tonic-gate 
21867c478bd9Sstevel@tonic-gate /******************************************************************************
21877c478bd9Sstevel@tonic-gate  * Configures flow control settings after link is established
21887c478bd9Sstevel@tonic-gate  *
21897c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
21907c478bd9Sstevel@tonic-gate  *
21917c478bd9Sstevel@tonic-gate  * Should be called immediately after a valid link has been established.
21927c478bd9Sstevel@tonic-gate  * Forces MAC flow control settings if link was forced. When in MII/GMII mode
21937c478bd9Sstevel@tonic-gate  * and autonegotiation is enabled, the MAC flow control settings will be set
21947c478bd9Sstevel@tonic-gate  * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
21957c478bd9Sstevel@tonic-gate  * and RFCE bits will be automaticaly set to the negotiated flow control mode.
21967c478bd9Sstevel@tonic-gate  *****************************************************************************/
21977c478bd9Sstevel@tonic-gate static int
21987c478bd9Sstevel@tonic-gate e1000_config_fc_after_link_up(struct e1000_hw *hw)
21997c478bd9Sstevel@tonic-gate {
22007c478bd9Sstevel@tonic-gate 	int32_t ret_val;
22017c478bd9Sstevel@tonic-gate 	uint16_t mii_status_reg;
22027c478bd9Sstevel@tonic-gate 	uint16_t mii_nway_adv_reg;
22037c478bd9Sstevel@tonic-gate 	uint16_t mii_nway_lp_ability_reg;
22047c478bd9Sstevel@tonic-gate 	uint16_t speed;
22057c478bd9Sstevel@tonic-gate 	uint16_t duplex;
22067c478bd9Sstevel@tonic-gate 
22077c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_config_fc_after_link_up");
22087c478bd9Sstevel@tonic-gate 
22097c478bd9Sstevel@tonic-gate 	/* Check for the case where we have fiber media and auto-neg failed
22107c478bd9Sstevel@tonic-gate 	 * so we had to force link.  In this case, we need to force the
22117c478bd9Sstevel@tonic-gate 	 * configuration of the MAC to match the "fc" parameter.
22127c478bd9Sstevel@tonic-gate 	 */
22137c478bd9Sstevel@tonic-gate 	if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
22147c478bd9Sstevel@tonic-gate 	   ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed))) {
22157c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_force_mac_fc(hw))) {
22167c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error forcing flow control settings\n");
22177c478bd9Sstevel@tonic-gate 			return ret_val;
22187c478bd9Sstevel@tonic-gate 		}
22197c478bd9Sstevel@tonic-gate 	}
22207c478bd9Sstevel@tonic-gate 
22217c478bd9Sstevel@tonic-gate 	/* Check for the case where we have copper media and auto-neg is
22227c478bd9Sstevel@tonic-gate 	 * enabled.  In this case, we need to check and see if Auto-Neg
22237c478bd9Sstevel@tonic-gate 	 * has completed, and if so, how the PHY and link partner has
22247c478bd9Sstevel@tonic-gate 	 * flow control configured.
22257c478bd9Sstevel@tonic-gate 	 */
22267c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_copper) {
22277c478bd9Sstevel@tonic-gate 		/* Read the MII Status Register and check to see if AutoNeg
22287c478bd9Sstevel@tonic-gate 		 * has completed.  We read this twice because this reg has
22297c478bd9Sstevel@tonic-gate 		 * some "sticky" (latched) bits.
22307c478bd9Sstevel@tonic-gate 		 */
22317c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
22327c478bd9Sstevel@tonic-gate 			return ret_val;
22337c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
22347c478bd9Sstevel@tonic-gate 			return ret_val;
22357c478bd9Sstevel@tonic-gate 
22367c478bd9Sstevel@tonic-gate 		if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
22377c478bd9Sstevel@tonic-gate 			/* The AutoNeg process has completed, so we now need to
22387c478bd9Sstevel@tonic-gate 			 * read both the Auto Negotiation Advertisement Register
22397c478bd9Sstevel@tonic-gate 			 * (Address 4) and the Auto_Negotiation Base Page Ability
22407c478bd9Sstevel@tonic-gate 			 * Register (Address 5) to determine how flow control was
22417c478bd9Sstevel@tonic-gate 			 * negotiated.
22427c478bd9Sstevel@tonic-gate 			 */
22437c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
22447c478bd9Sstevel@tonic-gate 			                                 &mii_nway_adv_reg)))
22457c478bd9Sstevel@tonic-gate 				return ret_val;
22467c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
22477c478bd9Sstevel@tonic-gate 			                                 &mii_nway_lp_ability_reg)))
22487c478bd9Sstevel@tonic-gate 				return ret_val;
22497c478bd9Sstevel@tonic-gate 
22507c478bd9Sstevel@tonic-gate 			/* Two bits in the Auto Negotiation Advertisement Register
22517c478bd9Sstevel@tonic-gate 			 * (Address 4) and two bits in the Auto Negotiation Base
22527c478bd9Sstevel@tonic-gate 			 * Page Ability Register (Address 5) determine flow control
22537c478bd9Sstevel@tonic-gate 			 * for both the PHY and the link partner.  The following
22547c478bd9Sstevel@tonic-gate 			 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
22557c478bd9Sstevel@tonic-gate 			 * 1999, describes these PAUSE resolution bits and how flow
22567c478bd9Sstevel@tonic-gate 			 * control is determined based upon these settings.
22577c478bd9Sstevel@tonic-gate 			 * NOTE:  DC = Don't Care
22587c478bd9Sstevel@tonic-gate 			 *
22597c478bd9Sstevel@tonic-gate 			 *   LOCAL DEVICE  |   LINK PARTNER
22607c478bd9Sstevel@tonic-gate 			 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
22617c478bd9Sstevel@tonic-gate 			 *-------|---------|-------|---------|--------------------
22627c478bd9Sstevel@tonic-gate 			 *   0   |    0    |  DC   |   DC    | e1000_fc_none
22637c478bd9Sstevel@tonic-gate 			 *   0   |    1    |   0   |   DC    | e1000_fc_none
22647c478bd9Sstevel@tonic-gate 			 *   0   |    1    |   1   |    0    | e1000_fc_none
22657c478bd9Sstevel@tonic-gate 			 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
22667c478bd9Sstevel@tonic-gate 			 *   1   |    0    |   0   |   DC    | e1000_fc_none
22677c478bd9Sstevel@tonic-gate 			 *   1   |   DC    |   1   |   DC    | e1000_fc_full
22687c478bd9Sstevel@tonic-gate 			 *   1   |    1    |   0   |    0    | e1000_fc_none
22697c478bd9Sstevel@tonic-gate 			 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
22707c478bd9Sstevel@tonic-gate 			 *
22717c478bd9Sstevel@tonic-gate 			 */
22727c478bd9Sstevel@tonic-gate 			/* Are both PAUSE bits set to 1?  If so, this implies
22737c478bd9Sstevel@tonic-gate 			 * Symmetric Flow Control is enabled at both ends.  The
22747c478bd9Sstevel@tonic-gate 			 * ASM_DIR bits are irrelevant per the spec.
22757c478bd9Sstevel@tonic-gate 			 *
22767c478bd9Sstevel@tonic-gate 			 * For Symmetric Flow Control:
22777c478bd9Sstevel@tonic-gate 			 *
22787c478bd9Sstevel@tonic-gate 			 *   LOCAL DEVICE  |   LINK PARTNER
22797c478bd9Sstevel@tonic-gate 			 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
22807c478bd9Sstevel@tonic-gate 			 *-------|---------|-------|---------|--------------------
22817c478bd9Sstevel@tonic-gate 			 *   1   |   DC    |   1   |   DC    | e1000_fc_full
22827c478bd9Sstevel@tonic-gate 			 *
22837c478bd9Sstevel@tonic-gate 			 */
22847c478bd9Sstevel@tonic-gate 			if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
22857c478bd9Sstevel@tonic-gate 				(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
22867c478bd9Sstevel@tonic-gate 				/* Now we need to check if the user selected RX ONLY
22877c478bd9Sstevel@tonic-gate 				 * of pause frames.  In this case, we had to advertise
22887c478bd9Sstevel@tonic-gate 				 * FULL flow control because we could not advertise RX
22897c478bd9Sstevel@tonic-gate 				 * ONLY. Hence, we must now check to see if we need to
22907c478bd9Sstevel@tonic-gate 				 * turn OFF  the TRANSMISSION of PAUSE frames.
22917c478bd9Sstevel@tonic-gate 				 */
22927c478bd9Sstevel@tonic-gate #if 0
22937c478bd9Sstevel@tonic-gate 				if(hw->original_fc == e1000_fc_full) {
22947c478bd9Sstevel@tonic-gate 					hw->fc = e1000_fc_full;
22957c478bd9Sstevel@tonic-gate #else
22967c478bd9Sstevel@tonic-gate 				if(hw->fc == e1000_fc_full) {
22977c478bd9Sstevel@tonic-gate #endif
22987c478bd9Sstevel@tonic-gate 					DEBUGOUT("Flow Control = FULL.\r\n");
22997c478bd9Sstevel@tonic-gate 				} else {
23007c478bd9Sstevel@tonic-gate 					hw->fc = e1000_fc_rx_pause;
23017c478bd9Sstevel@tonic-gate 					DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
23027c478bd9Sstevel@tonic-gate 				}
23037c478bd9Sstevel@tonic-gate 			}
23047c478bd9Sstevel@tonic-gate 			/* For receiving PAUSE frames ONLY.
23057c478bd9Sstevel@tonic-gate 			 *
23067c478bd9Sstevel@tonic-gate 			 *   LOCAL DEVICE  |   LINK PARTNER
23077c478bd9Sstevel@tonic-gate 			 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
23087c478bd9Sstevel@tonic-gate 			 *-------|---------|-------|---------|--------------------
23097c478bd9Sstevel@tonic-gate 			 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
23107c478bd9Sstevel@tonic-gate 			 *
23117c478bd9Sstevel@tonic-gate 			 */
23127c478bd9Sstevel@tonic-gate 			else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
23137c478bd9Sstevel@tonic-gate 				(mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
23147c478bd9Sstevel@tonic-gate 				(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
23157c478bd9Sstevel@tonic-gate 				(mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
23167c478bd9Sstevel@tonic-gate 				hw->fc = e1000_fc_tx_pause;
23177c478bd9Sstevel@tonic-gate 				DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
23187c478bd9Sstevel@tonic-gate 			}
23197c478bd9Sstevel@tonic-gate 			/* For transmitting PAUSE frames ONLY.
23207c478bd9Sstevel@tonic-gate 			 *
23217c478bd9Sstevel@tonic-gate 			 *   LOCAL DEVICE  |   LINK PARTNER
23227c478bd9Sstevel@tonic-gate 			 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
23237c478bd9Sstevel@tonic-gate 			 *-------|---------|-------|---------|--------------------
23247c478bd9Sstevel@tonic-gate 			 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
23257c478bd9Sstevel@tonic-gate 			 *
23267c478bd9Sstevel@tonic-gate 			 */
23277c478bd9Sstevel@tonic-gate 			else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
23287c478bd9Sstevel@tonic-gate 				(mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
23297c478bd9Sstevel@tonic-gate 				!(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
23307c478bd9Sstevel@tonic-gate 				(mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
23317c478bd9Sstevel@tonic-gate 				hw->fc = e1000_fc_rx_pause;
23327c478bd9Sstevel@tonic-gate 				DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
23337c478bd9Sstevel@tonic-gate 			}
23347c478bd9Sstevel@tonic-gate 			/* Per the IEEE spec, at this point flow control should be
23357c478bd9Sstevel@tonic-gate 			 * disabled.  However, we want to consider that we could
23367c478bd9Sstevel@tonic-gate 			 * be connected to a legacy switch that doesn't advertise
23377c478bd9Sstevel@tonic-gate 			 * desired flow control, but can be forced on the link
23387c478bd9Sstevel@tonic-gate 			 * partner.  So if we advertised no flow control, that is
23397c478bd9Sstevel@tonic-gate 			 * what we will resolve to.  If we advertised some kind of
23407c478bd9Sstevel@tonic-gate 			 * receive capability (Rx Pause Only or Full Flow Control)
23417c478bd9Sstevel@tonic-gate 			 * and the link partner advertised none, we will configure
23427c478bd9Sstevel@tonic-gate 			 * ourselves to enable Rx Flow Control only.  We can do
23437c478bd9Sstevel@tonic-gate 			 * this safely for two reasons:  If the link partner really
23447c478bd9Sstevel@tonic-gate 			 * didn't want flow control enabled, and we enable Rx, no
23457c478bd9Sstevel@tonic-gate 			 * harm done since we won't be receiving any PAUSE frames
23467c478bd9Sstevel@tonic-gate 			 * anyway.  If the intent on the link partner was to have
23477c478bd9Sstevel@tonic-gate 			 * flow control enabled, then by us enabling RX only, we
23487c478bd9Sstevel@tonic-gate 			 * can at least receive pause frames and process them.
23497c478bd9Sstevel@tonic-gate 			 * This is a good idea because in most cases, since we are
23507c478bd9Sstevel@tonic-gate 			 * predominantly a server NIC, more times than not we will
23517c478bd9Sstevel@tonic-gate 			 * be asked to delay transmission of packets than asking
23527c478bd9Sstevel@tonic-gate 			 * our link partner to pause transmission of frames.
23537c478bd9Sstevel@tonic-gate 			 */
23547c478bd9Sstevel@tonic-gate #if 0
23557c478bd9Sstevel@tonic-gate 			else if(hw->original_fc == e1000_fc_none ||
23567c478bd9Sstevel@tonic-gate 				hw->original_fc == e1000_fc_tx_pause) {
23577c478bd9Sstevel@tonic-gate #else
23587c478bd9Sstevel@tonic-gate 			else if(hw->fc == e1000_fc_none)
23597c478bd9Sstevel@tonic-gate 				DEBUGOUT("Flow Control = NONE.\r\n");
23607c478bd9Sstevel@tonic-gate 			else if(hw->fc == e1000_fc_tx_pause) {
23617c478bd9Sstevel@tonic-gate #endif
23627c478bd9Sstevel@tonic-gate 				hw->fc = e1000_fc_none;
23637c478bd9Sstevel@tonic-gate 				DEBUGOUT("Flow Control = NONE.\r\n");
23647c478bd9Sstevel@tonic-gate 			} else {
23657c478bd9Sstevel@tonic-gate 				hw->fc = e1000_fc_rx_pause;
23667c478bd9Sstevel@tonic-gate 				DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
23677c478bd9Sstevel@tonic-gate 			}
23687c478bd9Sstevel@tonic-gate 
23697c478bd9Sstevel@tonic-gate 			/* Now we need to do one last check...  If we auto-
23707c478bd9Sstevel@tonic-gate 			 * negotiated to HALF DUPLEX, flow control should not be
23717c478bd9Sstevel@tonic-gate 			 * enabled per IEEE 802.3 spec.
23727c478bd9Sstevel@tonic-gate 			 */
23737c478bd9Sstevel@tonic-gate 			e1000_get_speed_and_duplex(hw, &speed, &duplex);
23747c478bd9Sstevel@tonic-gate 
23757c478bd9Sstevel@tonic-gate 			if(duplex == HALF_DUPLEX)
23767c478bd9Sstevel@tonic-gate 				hw->fc = e1000_fc_none;
23777c478bd9Sstevel@tonic-gate 
23787c478bd9Sstevel@tonic-gate 			/* Now we call a subroutine to actually force the MAC
23797c478bd9Sstevel@tonic-gate 			 * controller to use the correct flow control settings.
23807c478bd9Sstevel@tonic-gate 			 */
23817c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_force_mac_fc(hw))) {
23827c478bd9Sstevel@tonic-gate 				DEBUGOUT("Error forcing flow control settings\n");
23837c478bd9Sstevel@tonic-gate 				return ret_val;
23847c478bd9Sstevel@tonic-gate 			}
23857c478bd9Sstevel@tonic-gate 		} else {
23867c478bd9Sstevel@tonic-gate 			DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
23877c478bd9Sstevel@tonic-gate 		}
23887c478bd9Sstevel@tonic-gate 	}
23897c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
23907c478bd9Sstevel@tonic-gate }
23917c478bd9Sstevel@tonic-gate 
23927c478bd9Sstevel@tonic-gate /******************************************************************************
23937c478bd9Sstevel@tonic-gate  * Checks to see if the link status of the hardware has changed.
23947c478bd9Sstevel@tonic-gate  *
23957c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
23967c478bd9Sstevel@tonic-gate  *
23977c478bd9Sstevel@tonic-gate  * Called by any function that needs to check the link status of the adapter.
23987c478bd9Sstevel@tonic-gate  *****************************************************************************/
23997c478bd9Sstevel@tonic-gate static int
24007c478bd9Sstevel@tonic-gate e1000_check_for_link(struct e1000_hw *hw)
24017c478bd9Sstevel@tonic-gate {
24027c478bd9Sstevel@tonic-gate 	uint32_t rxcw;
24037c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
24047c478bd9Sstevel@tonic-gate 	uint32_t status;
24057c478bd9Sstevel@tonic-gate 	uint32_t rctl;
24067c478bd9Sstevel@tonic-gate 	uint32_t signal = 0;
24077c478bd9Sstevel@tonic-gate 	int32_t ret_val;
24087c478bd9Sstevel@tonic-gate 	uint16_t phy_data;
24097c478bd9Sstevel@tonic-gate 	uint16_t lp_capability;
24107c478bd9Sstevel@tonic-gate 
24117c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_check_for_link");
24127c478bd9Sstevel@tonic-gate 
24137c478bd9Sstevel@tonic-gate 	/* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
24147c478bd9Sstevel@tonic-gate 	 * set when the optics detect a signal. On older adapters, it will be
24157c478bd9Sstevel@tonic-gate 	 * cleared when there is a signal.  This applies to fiber media only.
24167c478bd9Sstevel@tonic-gate 	 */
24177c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_fiber)
24187c478bd9Sstevel@tonic-gate 		signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
24197c478bd9Sstevel@tonic-gate 
24207c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
24217c478bd9Sstevel@tonic-gate 	status = E1000_READ_REG(hw, STATUS);
24227c478bd9Sstevel@tonic-gate 	rxcw = E1000_READ_REG(hw, RXCW);
24237c478bd9Sstevel@tonic-gate 
24247c478bd9Sstevel@tonic-gate 	/* If we have a copper PHY then we only want to go out to the PHY
24257c478bd9Sstevel@tonic-gate 	 * registers to see if Auto-Neg has completed and/or if our link
24267c478bd9Sstevel@tonic-gate 	 * status has changed.  The get_link_status flag will be set if we
24277c478bd9Sstevel@tonic-gate 	 * receive a Link Status Change interrupt or we have Rx Sequence
24287c478bd9Sstevel@tonic-gate 	 * Errors.
24297c478bd9Sstevel@tonic-gate 	 */
24307c478bd9Sstevel@tonic-gate #if 0
24317c478bd9Sstevel@tonic-gate 	if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
24327c478bd9Sstevel@tonic-gate #else
24337c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_copper) {
24347c478bd9Sstevel@tonic-gate #endif
24357c478bd9Sstevel@tonic-gate 		/* First we want to see if the MII Status Register reports
24367c478bd9Sstevel@tonic-gate 		 * link.  If so, then we want to get the current speed/duplex
24377c478bd9Sstevel@tonic-gate 		 * of the PHY.
24387c478bd9Sstevel@tonic-gate 		 * Read the register twice since the link bit is sticky.
24397c478bd9Sstevel@tonic-gate 		 */
24407c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
24417c478bd9Sstevel@tonic-gate 			return ret_val;
24427c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
24437c478bd9Sstevel@tonic-gate 			return ret_val;
24447c478bd9Sstevel@tonic-gate 
24457c478bd9Sstevel@tonic-gate 		if(phy_data & MII_SR_LINK_STATUS) {
24467c478bd9Sstevel@tonic-gate #if 0
24477c478bd9Sstevel@tonic-gate 			hw->get_link_status = FALSE;
24487c478bd9Sstevel@tonic-gate #endif
24497c478bd9Sstevel@tonic-gate 		} else {
24507c478bd9Sstevel@tonic-gate 			/* No link detected */
24517c478bd9Sstevel@tonic-gate 			return -E1000_ERR_NOLINK;
24527c478bd9Sstevel@tonic-gate 		}
24537c478bd9Sstevel@tonic-gate 
24547c478bd9Sstevel@tonic-gate 		/* We have a M88E1000 PHY and Auto-Neg is enabled.  If we
24557c478bd9Sstevel@tonic-gate 		 * have Si on board that is 82544 or newer, Auto
24567c478bd9Sstevel@tonic-gate 		 * Speed Detection takes care of MAC speed/duplex
24577c478bd9Sstevel@tonic-gate 		 * configuration.  So we only need to configure Collision
24587c478bd9Sstevel@tonic-gate 		 * Distance in the MAC.  Otherwise, we need to force
24597c478bd9Sstevel@tonic-gate 		 * speed/duplex on the MAC to the current PHY speed/duplex
24607c478bd9Sstevel@tonic-gate 		 * settings.
24617c478bd9Sstevel@tonic-gate 		 */
24627c478bd9Sstevel@tonic-gate 		if(hw->mac_type >= e1000_82544)
24637c478bd9Sstevel@tonic-gate 			e1000_config_collision_dist(hw);
24647c478bd9Sstevel@tonic-gate 		else {
24657c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_config_mac_to_phy(hw))) {
24667c478bd9Sstevel@tonic-gate 				DEBUGOUT("Error configuring MAC to PHY settings\n");
24677c478bd9Sstevel@tonic-gate 				return ret_val;
24687c478bd9Sstevel@tonic-gate 			}
24697c478bd9Sstevel@tonic-gate 		}
24707c478bd9Sstevel@tonic-gate 
24717c478bd9Sstevel@tonic-gate 		/* Configure Flow Control now that Auto-Neg has completed. First, we
24727c478bd9Sstevel@tonic-gate 		 * need to restore the desired flow control settings because we may
24737c478bd9Sstevel@tonic-gate 		 * have had to re-autoneg with a different link partner.
24747c478bd9Sstevel@tonic-gate 		 */
24757c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_config_fc_after_link_up(hw))) {
24767c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error configuring flow control\n");
24777c478bd9Sstevel@tonic-gate 			return ret_val;
24787c478bd9Sstevel@tonic-gate 		}
24797c478bd9Sstevel@tonic-gate 
24807c478bd9Sstevel@tonic-gate 		/* At this point we know that we are on copper and we have
24817c478bd9Sstevel@tonic-gate 		 * auto-negotiated link.  These are conditions for checking the link
24827c478bd9Sstevel@tonic-gate 		 * parter capability register.  We use the link partner capability to
24837c478bd9Sstevel@tonic-gate 		 * determine if TBI Compatibility needs to be turned on or off.  If
24847c478bd9Sstevel@tonic-gate 		 * the link partner advertises any speed in addition to Gigabit, then
24857c478bd9Sstevel@tonic-gate 		 * we assume that they are GMII-based, and TBI compatibility is not
24867c478bd9Sstevel@tonic-gate 		 * needed. If no other speeds are advertised, we assume the link
24877c478bd9Sstevel@tonic-gate 		 * partner is TBI-based, and we turn on TBI Compatibility.
24887c478bd9Sstevel@tonic-gate 		 */
24897c478bd9Sstevel@tonic-gate 		if(hw->tbi_compatibility_en) {
24907c478bd9Sstevel@tonic-gate 			if((ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
24917c478bd9Sstevel@tonic-gate 			                                 &lp_capability)))
24927c478bd9Sstevel@tonic-gate 				return ret_val;
24937c478bd9Sstevel@tonic-gate 			if(lp_capability & (NWAY_LPAR_10T_HD_CAPS |
24947c478bd9Sstevel@tonic-gate                                 NWAY_LPAR_10T_FD_CAPS |
24957c478bd9Sstevel@tonic-gate                                 NWAY_LPAR_100TX_HD_CAPS |
24967c478bd9Sstevel@tonic-gate                                 NWAY_LPAR_100TX_FD_CAPS |
24977c478bd9Sstevel@tonic-gate                                 NWAY_LPAR_100T4_CAPS)) {
24987c478bd9Sstevel@tonic-gate 				/* If our link partner advertises anything in addition to
24997c478bd9Sstevel@tonic-gate 				 * gigabit, we do not need to enable TBI compatibility.
25007c478bd9Sstevel@tonic-gate 				 */
25017c478bd9Sstevel@tonic-gate 				if(hw->tbi_compatibility_on) {
25027c478bd9Sstevel@tonic-gate 					/* If we previously were in the mode, turn it off. */
25037c478bd9Sstevel@tonic-gate 					rctl = E1000_READ_REG(hw, RCTL);
25047c478bd9Sstevel@tonic-gate 					rctl &= ~E1000_RCTL_SBP;
25057c478bd9Sstevel@tonic-gate 					E1000_WRITE_REG(hw, RCTL, rctl);
25067c478bd9Sstevel@tonic-gate 					hw->tbi_compatibility_on = FALSE;
25077c478bd9Sstevel@tonic-gate 				}
25087c478bd9Sstevel@tonic-gate 			} else {
25097c478bd9Sstevel@tonic-gate 				/* If TBI compatibility is was previously off, turn it on. For
25107c478bd9Sstevel@tonic-gate 				 * compatibility with a TBI link partner, we will store bad
25117c478bd9Sstevel@tonic-gate 				 * packets. Some frames have an additional byte on the end and
25127c478bd9Sstevel@tonic-gate 				 * will look like CRC errors to to the hardware.
25137c478bd9Sstevel@tonic-gate 				 */
25147c478bd9Sstevel@tonic-gate 				if(!hw->tbi_compatibility_on) {
25157c478bd9Sstevel@tonic-gate 					hw->tbi_compatibility_on = TRUE;
25167c478bd9Sstevel@tonic-gate 					rctl = E1000_READ_REG(hw, RCTL);
25177c478bd9Sstevel@tonic-gate 					rctl |= E1000_RCTL_SBP;
25187c478bd9Sstevel@tonic-gate 					E1000_WRITE_REG(hw, RCTL, rctl);
25197c478bd9Sstevel@tonic-gate 				}
25207c478bd9Sstevel@tonic-gate 			}
25217c478bd9Sstevel@tonic-gate 		}
25227c478bd9Sstevel@tonic-gate 	}
25237c478bd9Sstevel@tonic-gate 	/* If we don't have link (auto-negotiation failed or link partner cannot
25247c478bd9Sstevel@tonic-gate 	 * auto-negotiate), the cable is plugged in (we have signal), and our
25257c478bd9Sstevel@tonic-gate 	 * link partner is not trying to auto-negotiate with us (we are receiving
25267c478bd9Sstevel@tonic-gate 	 * idles or data), we need to force link up. We also need to give
25277c478bd9Sstevel@tonic-gate 	 * auto-negotiation time to complete, in case the cable was just plugged
25287c478bd9Sstevel@tonic-gate 	 * in. The autoneg_failed flag does this.
25297c478bd9Sstevel@tonic-gate 	 */
25307c478bd9Sstevel@tonic-gate 	else if((((hw->media_type == e1000_media_type_fiber) &&
25317c478bd9Sstevel@tonic-gate 	        ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
25327c478bd9Sstevel@tonic-gate 	        (hw->media_type == e1000_media_type_internal_serdes)) &&
25337c478bd9Sstevel@tonic-gate 		(!(status & E1000_STATUS_LU)) &&
25347c478bd9Sstevel@tonic-gate 		(!(rxcw & E1000_RXCW_C))) {
25357c478bd9Sstevel@tonic-gate 		if(hw->autoneg_failed == 0) {
25367c478bd9Sstevel@tonic-gate 			hw->autoneg_failed = 1;
25377c478bd9Sstevel@tonic-gate 			return 0;
25387c478bd9Sstevel@tonic-gate 		}
25397c478bd9Sstevel@tonic-gate 		DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
25407c478bd9Sstevel@tonic-gate 
25417c478bd9Sstevel@tonic-gate 		/* Disable auto-negotiation in the TXCW register */
25427c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
25437c478bd9Sstevel@tonic-gate 
25447c478bd9Sstevel@tonic-gate 		/* Force link-up and also force full-duplex. */
25457c478bd9Sstevel@tonic-gate 		ctrl = E1000_READ_REG(hw, CTRL);
25467c478bd9Sstevel@tonic-gate 		ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
25477c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl);
25487c478bd9Sstevel@tonic-gate 
25497c478bd9Sstevel@tonic-gate 		/* Configure Flow Control after forcing link up. */
25507c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_config_fc_after_link_up(hw))) {
25517c478bd9Sstevel@tonic-gate 			DEBUGOUT("Error configuring flow control\n");
25527c478bd9Sstevel@tonic-gate 			return ret_val;
25537c478bd9Sstevel@tonic-gate 		}
25547c478bd9Sstevel@tonic-gate 	}
25557c478bd9Sstevel@tonic-gate 	/* If we are forcing link and we are receiving /C/ ordered sets, re-enable
25567c478bd9Sstevel@tonic-gate 	 * auto-negotiation in the TXCW register and disable forced link in the
25577c478bd9Sstevel@tonic-gate 	 * Device Control register in an attempt to auto-negotiate with our link
25587c478bd9Sstevel@tonic-gate 	 * partner.
25597c478bd9Sstevel@tonic-gate 	 */
25607c478bd9Sstevel@tonic-gate 	else if(((hw->media_type == e1000_media_type_fiber)  ||
25617c478bd9Sstevel@tonic-gate 	         (hw->media_type == e1000_media_type_internal_serdes)) &&
25627c478bd9Sstevel@tonic-gate 		(ctrl & E1000_CTRL_SLU) &&
25637c478bd9Sstevel@tonic-gate 		(rxcw & E1000_RXCW_C)) {
25647c478bd9Sstevel@tonic-gate 		DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
25657c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, TXCW, hw->txcw);
25667c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
25677c478bd9Sstevel@tonic-gate 	}
25687c478bd9Sstevel@tonic-gate #if 0
25697c478bd9Sstevel@tonic-gate 	/* If we force link for non-auto-negotiation switch, check link status
25707c478bd9Sstevel@tonic-gate 	 * based on MAC synchronization for internal serdes media type.
25717c478bd9Sstevel@tonic-gate 	 */
25727c478bd9Sstevel@tonic-gate 	else if((hw->media_type == e1000_media_type_internal_serdes) &&
25737c478bd9Sstevel@tonic-gate 			!(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
25747c478bd9Sstevel@tonic-gate 		/* SYNCH bit and IV bit are sticky. */
25757c478bd9Sstevel@tonic-gate 		udelay(10);
25767c478bd9Sstevel@tonic-gate 		if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
25777c478bd9Sstevel@tonic-gate 			if(!(rxcw & E1000_RXCW_IV)) {
25787c478bd9Sstevel@tonic-gate 				hw->serdes_link_down = FALSE;
25797c478bd9Sstevel@tonic-gate 				DEBUGOUT("SERDES: Link is up.\n");
25807c478bd9Sstevel@tonic-gate 			}
25817c478bd9Sstevel@tonic-gate 		} else {
25827c478bd9Sstevel@tonic-gate 			hw->serdes_link_down = TRUE;
25837c478bd9Sstevel@tonic-gate 			DEBUGOUT("SERDES: Link is down.\n");
25847c478bd9Sstevel@tonic-gate 		}
25857c478bd9Sstevel@tonic-gate 	}
25867c478bd9Sstevel@tonic-gate #endif
25877c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
25887c478bd9Sstevel@tonic-gate }
25897c478bd9Sstevel@tonic-gate 
25907c478bd9Sstevel@tonic-gate /******************************************************************************
25917c478bd9Sstevel@tonic-gate  * Detects the current speed and duplex settings of the hardware.
25927c478bd9Sstevel@tonic-gate  *
25937c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
25947c478bd9Sstevel@tonic-gate  * speed - Speed of the connection
25957c478bd9Sstevel@tonic-gate  * duplex - Duplex setting of the connection
25967c478bd9Sstevel@tonic-gate  *****************************************************************************/
25977c478bd9Sstevel@tonic-gate static void
25987c478bd9Sstevel@tonic-gate e1000_get_speed_and_duplex(struct e1000_hw *hw,
25997c478bd9Sstevel@tonic-gate                            uint16_t *speed,
26007c478bd9Sstevel@tonic-gate                            uint16_t *duplex)
26017c478bd9Sstevel@tonic-gate {
26027c478bd9Sstevel@tonic-gate 	uint32_t status;
26037c478bd9Sstevel@tonic-gate 
26047c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_get_speed_and_duplex");
26057c478bd9Sstevel@tonic-gate 
26067c478bd9Sstevel@tonic-gate 	if(hw->mac_type >= e1000_82543) {
26077c478bd9Sstevel@tonic-gate 		status = E1000_READ_REG(hw, STATUS);
26087c478bd9Sstevel@tonic-gate 		if(status & E1000_STATUS_SPEED_1000) {
26097c478bd9Sstevel@tonic-gate 			*speed = SPEED_1000;
26107c478bd9Sstevel@tonic-gate 			DEBUGOUT("1000 Mbs, ");
26117c478bd9Sstevel@tonic-gate 		} else if(status & E1000_STATUS_SPEED_100) {
26127c478bd9Sstevel@tonic-gate 			*speed = SPEED_100;
26137c478bd9Sstevel@tonic-gate 			DEBUGOUT("100 Mbs, ");
26147c478bd9Sstevel@tonic-gate 		} else {
26157c478bd9Sstevel@tonic-gate 			*speed = SPEED_10;
26167c478bd9Sstevel@tonic-gate 			DEBUGOUT("10 Mbs, ");
26177c478bd9Sstevel@tonic-gate 		}
26187c478bd9Sstevel@tonic-gate 
26197c478bd9Sstevel@tonic-gate 		if(status & E1000_STATUS_FD) {
26207c478bd9Sstevel@tonic-gate 			*duplex = FULL_DUPLEX;
26217c478bd9Sstevel@tonic-gate 			DEBUGOUT("Full Duplex\r\n");
26227c478bd9Sstevel@tonic-gate 		} else {
26237c478bd9Sstevel@tonic-gate 			*duplex = HALF_DUPLEX;
26247c478bd9Sstevel@tonic-gate 			DEBUGOUT(" Half Duplex\r\n");
26257c478bd9Sstevel@tonic-gate 		}
26267c478bd9Sstevel@tonic-gate 	} else {
26277c478bd9Sstevel@tonic-gate 		DEBUGOUT("1000 Mbs, Full Duplex\r\n");
26287c478bd9Sstevel@tonic-gate 		*speed = SPEED_1000;
26297c478bd9Sstevel@tonic-gate 		*duplex = FULL_DUPLEX;
26307c478bd9Sstevel@tonic-gate 	}
26317c478bd9Sstevel@tonic-gate }
26327c478bd9Sstevel@tonic-gate 
26337c478bd9Sstevel@tonic-gate /******************************************************************************
26347c478bd9Sstevel@tonic-gate * Blocks until autoneg completes or times out (~4.5 seconds)
26357c478bd9Sstevel@tonic-gate *
26367c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
26377c478bd9Sstevel@tonic-gate ******************************************************************************/
26387c478bd9Sstevel@tonic-gate static int
26397c478bd9Sstevel@tonic-gate e1000_wait_autoneg(struct e1000_hw *hw)
26407c478bd9Sstevel@tonic-gate {
26417c478bd9Sstevel@tonic-gate 	int32_t ret_val;
26427c478bd9Sstevel@tonic-gate 	uint16_t i;
26437c478bd9Sstevel@tonic-gate 	uint16_t phy_data;
26447c478bd9Sstevel@tonic-gate 
26457c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_wait_autoneg");
26467c478bd9Sstevel@tonic-gate 	DEBUGOUT("Waiting for Auto-Neg to complete.\n");
26477c478bd9Sstevel@tonic-gate 
26487c478bd9Sstevel@tonic-gate 	/* We will wait for autoneg to complete or 4.5 seconds to expire. */
26497c478bd9Sstevel@tonic-gate 	for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
26507c478bd9Sstevel@tonic-gate 		/* Read the MII Status Register and wait for Auto-Neg
26517c478bd9Sstevel@tonic-gate 		 * Complete bit to be set.
26527c478bd9Sstevel@tonic-gate 		 */
26537c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
26547c478bd9Sstevel@tonic-gate 			return ret_val;
26557c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
26567c478bd9Sstevel@tonic-gate 			return ret_val;
26577c478bd9Sstevel@tonic-gate 		if(phy_data & MII_SR_AUTONEG_COMPLETE) {
26587c478bd9Sstevel@tonic-gate 			DEBUGOUT("Auto-Neg complete.\n");
26597c478bd9Sstevel@tonic-gate 			return E1000_SUCCESS;
26607c478bd9Sstevel@tonic-gate 		}
26617c478bd9Sstevel@tonic-gate 		mdelay(100);
26627c478bd9Sstevel@tonic-gate 	}
26637c478bd9Sstevel@tonic-gate 	DEBUGOUT("Auto-Neg timedout.\n");
26647c478bd9Sstevel@tonic-gate 	return -E1000_ERR_TIMEOUT;
26657c478bd9Sstevel@tonic-gate }
26667c478bd9Sstevel@tonic-gate 
26677c478bd9Sstevel@tonic-gate /******************************************************************************
26687c478bd9Sstevel@tonic-gate * Raises the Management Data Clock
26697c478bd9Sstevel@tonic-gate *
26707c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
26717c478bd9Sstevel@tonic-gate * ctrl - Device control register's current value
26727c478bd9Sstevel@tonic-gate ******************************************************************************/
26737c478bd9Sstevel@tonic-gate static void
26747c478bd9Sstevel@tonic-gate e1000_raise_mdi_clk(struct e1000_hw *hw,
26757c478bd9Sstevel@tonic-gate                     uint32_t *ctrl)
26767c478bd9Sstevel@tonic-gate {
26777c478bd9Sstevel@tonic-gate 	/* Raise the clock input to the Management Data Clock (by setting the MDC
26787c478bd9Sstevel@tonic-gate 	 * bit), and then delay 10 microseconds.
26797c478bd9Sstevel@tonic-gate 	 */
26807c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
26817c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
26827c478bd9Sstevel@tonic-gate 	udelay(10);
26837c478bd9Sstevel@tonic-gate }
26847c478bd9Sstevel@tonic-gate 
26857c478bd9Sstevel@tonic-gate /******************************************************************************
26867c478bd9Sstevel@tonic-gate * Lowers the Management Data Clock
26877c478bd9Sstevel@tonic-gate *
26887c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
26897c478bd9Sstevel@tonic-gate * ctrl - Device control register's current value
26907c478bd9Sstevel@tonic-gate ******************************************************************************/
26917c478bd9Sstevel@tonic-gate static void
26927c478bd9Sstevel@tonic-gate e1000_lower_mdi_clk(struct e1000_hw *hw,
26937c478bd9Sstevel@tonic-gate                     uint32_t *ctrl)
26947c478bd9Sstevel@tonic-gate {
26957c478bd9Sstevel@tonic-gate 	/* Lower the clock input to the Management Data Clock (by clearing the MDC
26967c478bd9Sstevel@tonic-gate 	 * bit), and then delay 10 microseconds.
26977c478bd9Sstevel@tonic-gate 	 */
26987c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
26997c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
27007c478bd9Sstevel@tonic-gate 	udelay(10);
27017c478bd9Sstevel@tonic-gate }
27027c478bd9Sstevel@tonic-gate 
27037c478bd9Sstevel@tonic-gate /******************************************************************************
27047c478bd9Sstevel@tonic-gate * Shifts data bits out to the PHY
27057c478bd9Sstevel@tonic-gate *
27067c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
27077c478bd9Sstevel@tonic-gate * data - Data to send out to the PHY
27087c478bd9Sstevel@tonic-gate * count - Number of bits to shift out
27097c478bd9Sstevel@tonic-gate *
27107c478bd9Sstevel@tonic-gate * Bits are shifted out in MSB to LSB order.
27117c478bd9Sstevel@tonic-gate ******************************************************************************/
27127c478bd9Sstevel@tonic-gate static void
27137c478bd9Sstevel@tonic-gate e1000_shift_out_mdi_bits(struct e1000_hw *hw,
27147c478bd9Sstevel@tonic-gate                          uint32_t data,
27157c478bd9Sstevel@tonic-gate                          uint16_t count)
27167c478bd9Sstevel@tonic-gate {
27177c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
27187c478bd9Sstevel@tonic-gate 	uint32_t mask;
27197c478bd9Sstevel@tonic-gate 
27207c478bd9Sstevel@tonic-gate 	/* We need to shift "count" number of bits out to the PHY. So, the value
27217c478bd9Sstevel@tonic-gate 	 * in the "data" parameter will be shifted out to the PHY one bit at a
27227c478bd9Sstevel@tonic-gate 	 * time. In order to do this, "data" must be broken down into bits.
27237c478bd9Sstevel@tonic-gate 	 */
27247c478bd9Sstevel@tonic-gate 	mask = 0x01;
27257c478bd9Sstevel@tonic-gate 	mask <<= (count - 1);
27267c478bd9Sstevel@tonic-gate 
27277c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
27287c478bd9Sstevel@tonic-gate 
27297c478bd9Sstevel@tonic-gate 	/* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
27307c478bd9Sstevel@tonic-gate 	ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
27317c478bd9Sstevel@tonic-gate 
27327c478bd9Sstevel@tonic-gate 	while(mask) {
27337c478bd9Sstevel@tonic-gate 		/* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
27347c478bd9Sstevel@tonic-gate 		 * then raising and lowering the Management Data Clock. A "0" is
27357c478bd9Sstevel@tonic-gate 		 * shifted out to the PHY by setting the MDIO bit to "0" and then
27367c478bd9Sstevel@tonic-gate 		 * raising and lowering the clock.
27377c478bd9Sstevel@tonic-gate 		 */
27387c478bd9Sstevel@tonic-gate 		if(data & mask) ctrl |= E1000_CTRL_MDIO;
27397c478bd9Sstevel@tonic-gate 		else ctrl &= ~E1000_CTRL_MDIO;
27407c478bd9Sstevel@tonic-gate 
27417c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl);
27427c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
27437c478bd9Sstevel@tonic-gate 
27447c478bd9Sstevel@tonic-gate 		udelay(10);
27457c478bd9Sstevel@tonic-gate 
27467c478bd9Sstevel@tonic-gate 		e1000_raise_mdi_clk(hw, &ctrl);
27477c478bd9Sstevel@tonic-gate 		e1000_lower_mdi_clk(hw, &ctrl);
27487c478bd9Sstevel@tonic-gate 
27497c478bd9Sstevel@tonic-gate 		mask = mask >> 1;
27507c478bd9Sstevel@tonic-gate 	}
27517c478bd9Sstevel@tonic-gate }
27527c478bd9Sstevel@tonic-gate 
27537c478bd9Sstevel@tonic-gate /******************************************************************************
27547c478bd9Sstevel@tonic-gate * Shifts data bits in from the PHY
27557c478bd9Sstevel@tonic-gate *
27567c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
27577c478bd9Sstevel@tonic-gate *
27587c478bd9Sstevel@tonic-gate * Bits are shifted in in MSB to LSB order.
27597c478bd9Sstevel@tonic-gate ******************************************************************************/
27607c478bd9Sstevel@tonic-gate static uint16_t
27617c478bd9Sstevel@tonic-gate e1000_shift_in_mdi_bits(struct e1000_hw *hw)
27627c478bd9Sstevel@tonic-gate {
27637c478bd9Sstevel@tonic-gate 	uint32_t ctrl;
27647c478bd9Sstevel@tonic-gate 	uint16_t data = 0;
27657c478bd9Sstevel@tonic-gate 	uint8_t i;
27667c478bd9Sstevel@tonic-gate 
27677c478bd9Sstevel@tonic-gate 	/* In order to read a register from the PHY, we need to shift in a total
27687c478bd9Sstevel@tonic-gate 	 * of 18 bits from the PHY. The first two bit (turnaround) times are used
27697c478bd9Sstevel@tonic-gate 	 * to avoid contention on the MDIO pin when a read operation is performed.
27707c478bd9Sstevel@tonic-gate 	 * These two bits are ignored by us and thrown away. Bits are "shifted in"
27717c478bd9Sstevel@tonic-gate 	 * by raising the input to the Management Data Clock (setting the MDC bit),
27727c478bd9Sstevel@tonic-gate 	 * and then reading the value of the MDIO bit.
27737c478bd9Sstevel@tonic-gate 	 */
27747c478bd9Sstevel@tonic-gate 	ctrl = E1000_READ_REG(hw, CTRL);
27757c478bd9Sstevel@tonic-gate 
27767c478bd9Sstevel@tonic-gate 	/* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
27777c478bd9Sstevel@tonic-gate 	ctrl &= ~E1000_CTRL_MDIO_DIR;
27787c478bd9Sstevel@tonic-gate 	ctrl &= ~E1000_CTRL_MDIO;
27797c478bd9Sstevel@tonic-gate 
27807c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, CTRL, ctrl);
27817c478bd9Sstevel@tonic-gate 	E1000_WRITE_FLUSH(hw);
27827c478bd9Sstevel@tonic-gate 
27837c478bd9Sstevel@tonic-gate 	/* Raise and Lower the clock before reading in the data. This accounts for
27847c478bd9Sstevel@tonic-gate 	 * the turnaround bits. The first clock occurred when we clocked out the
27857c478bd9Sstevel@tonic-gate 	 * last bit of the Register Address.
27867c478bd9Sstevel@tonic-gate 	 */
27877c478bd9Sstevel@tonic-gate 	e1000_raise_mdi_clk(hw, &ctrl);
27887c478bd9Sstevel@tonic-gate 	e1000_lower_mdi_clk(hw, &ctrl);
27897c478bd9Sstevel@tonic-gate 
27907c478bd9Sstevel@tonic-gate 	for(data = 0, i = 0; i < 16; i++) {
27917c478bd9Sstevel@tonic-gate 		data = data << 1;
27927c478bd9Sstevel@tonic-gate 		e1000_raise_mdi_clk(hw, &ctrl);
27937c478bd9Sstevel@tonic-gate 		ctrl = E1000_READ_REG(hw, CTRL);
27947c478bd9Sstevel@tonic-gate 		/* Check to see if we shifted in a "1". */
27957c478bd9Sstevel@tonic-gate 		if(ctrl & E1000_CTRL_MDIO) data |= 1;
27967c478bd9Sstevel@tonic-gate 		e1000_lower_mdi_clk(hw, &ctrl);
27977c478bd9Sstevel@tonic-gate 	}
27987c478bd9Sstevel@tonic-gate 
27997c478bd9Sstevel@tonic-gate 	e1000_raise_mdi_clk(hw, &ctrl);
28007c478bd9Sstevel@tonic-gate 	e1000_lower_mdi_clk(hw, &ctrl);
28017c478bd9Sstevel@tonic-gate 
28027c478bd9Sstevel@tonic-gate 	return data;
28037c478bd9Sstevel@tonic-gate }
28047c478bd9Sstevel@tonic-gate 
28057c478bd9Sstevel@tonic-gate /*****************************************************************************
28067c478bd9Sstevel@tonic-gate * Reads the value from a PHY register, if the value is on a specific non zero
28077c478bd9Sstevel@tonic-gate * page, sets the page first.
28087c478bd9Sstevel@tonic-gate *
28097c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
28107c478bd9Sstevel@tonic-gate * reg_addr - address of the PHY register to read
28117c478bd9Sstevel@tonic-gate ******************************************************************************/
28127c478bd9Sstevel@tonic-gate static int
28137c478bd9Sstevel@tonic-gate e1000_read_phy_reg(struct e1000_hw *hw,
28147c478bd9Sstevel@tonic-gate                    uint32_t reg_addr,
28157c478bd9Sstevel@tonic-gate                    uint16_t *phy_data)
28167c478bd9Sstevel@tonic-gate {
28177c478bd9Sstevel@tonic-gate 	uint32_t ret_val;
28187c478bd9Sstevel@tonic-gate 
28197c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_read_phy_reg");
28207c478bd9Sstevel@tonic-gate 
28217c478bd9Sstevel@tonic-gate 	if(hw->phy_type == e1000_phy_igp &&
28227c478bd9Sstevel@tonic-gate 	   (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
28237c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
28247c478bd9Sstevel@tonic-gate 		                                     (uint16_t)reg_addr)))
28257c478bd9Sstevel@tonic-gate 			return ret_val;
28267c478bd9Sstevel@tonic-gate 	}
28277c478bd9Sstevel@tonic-gate 
28287c478bd9Sstevel@tonic-gate 	ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
28297c478bd9Sstevel@tonic-gate 	                                phy_data);
28307c478bd9Sstevel@tonic-gate 
28317c478bd9Sstevel@tonic-gate 	return ret_val;
28327c478bd9Sstevel@tonic-gate }
28337c478bd9Sstevel@tonic-gate 
28347c478bd9Sstevel@tonic-gate static int
28357c478bd9Sstevel@tonic-gate e1000_read_phy_reg_ex(struct e1000_hw *hw,
28367c478bd9Sstevel@tonic-gate                       uint32_t reg_addr,
28377c478bd9Sstevel@tonic-gate                       uint16_t *phy_data)
28387c478bd9Sstevel@tonic-gate {
28397c478bd9Sstevel@tonic-gate 	uint32_t i;
28407c478bd9Sstevel@tonic-gate 	uint32_t mdic = 0;
28417c478bd9Sstevel@tonic-gate 	const uint32_t phy_addr = 1;
28427c478bd9Sstevel@tonic-gate 
28437c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_read_phy_reg_ex");
28447c478bd9Sstevel@tonic-gate 
28457c478bd9Sstevel@tonic-gate 	if(reg_addr > MAX_PHY_REG_ADDRESS) {
28467c478bd9Sstevel@tonic-gate 		DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
28477c478bd9Sstevel@tonic-gate 		return -E1000_ERR_PARAM;
28487c478bd9Sstevel@tonic-gate 	}
28497c478bd9Sstevel@tonic-gate 
28507c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82543) {
28517c478bd9Sstevel@tonic-gate 		/* Set up Op-code, Phy Address, and register address in the MDI
28527c478bd9Sstevel@tonic-gate 		 * Control register.  The MAC will take care of interfacing with the
28537c478bd9Sstevel@tonic-gate 		 * PHY to retrieve the desired data.
28547c478bd9Sstevel@tonic-gate 		 */
28557c478bd9Sstevel@tonic-gate 		mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
28567c478bd9Sstevel@tonic-gate 			(phy_addr << E1000_MDIC_PHY_SHIFT) |
28577c478bd9Sstevel@tonic-gate 			(E1000_MDIC_OP_READ));
28587c478bd9Sstevel@tonic-gate 
28597c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, MDIC, mdic);
28607c478bd9Sstevel@tonic-gate 
28617c478bd9Sstevel@tonic-gate 		/* Poll the ready bit to see if the MDI read completed */
28627c478bd9Sstevel@tonic-gate 		for(i = 0; i < 64; i++) {
28637c478bd9Sstevel@tonic-gate 			udelay(50);
28647c478bd9Sstevel@tonic-gate 			mdic = E1000_READ_REG(hw, MDIC);
28657c478bd9Sstevel@tonic-gate 			if(mdic & E1000_MDIC_READY) break;
28667c478bd9Sstevel@tonic-gate 		}
28677c478bd9Sstevel@tonic-gate 		if(!(mdic & E1000_MDIC_READY)) {
28687c478bd9Sstevel@tonic-gate 			DEBUGOUT("MDI Read did not complete\n");
28697c478bd9Sstevel@tonic-gate 			return -E1000_ERR_PHY;
28707c478bd9Sstevel@tonic-gate 		}
28717c478bd9Sstevel@tonic-gate 		if(mdic & E1000_MDIC_ERROR) {
28727c478bd9Sstevel@tonic-gate 			DEBUGOUT("MDI Error\n");
28737c478bd9Sstevel@tonic-gate 			return -E1000_ERR_PHY;
28747c478bd9Sstevel@tonic-gate 		}
28757c478bd9Sstevel@tonic-gate 		*phy_data = (uint16_t) mdic;
28767c478bd9Sstevel@tonic-gate 	} else {
28777c478bd9Sstevel@tonic-gate 		/* We must first send a preamble through the MDIO pin to signal the
28787c478bd9Sstevel@tonic-gate 		 * beginning of an MII instruction.  This is done by sending 32
28797c478bd9Sstevel@tonic-gate 		 * consecutive "1" bits.
28807c478bd9Sstevel@tonic-gate 		 */
28817c478bd9Sstevel@tonic-gate 		e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
28827c478bd9Sstevel@tonic-gate 
28837c478bd9Sstevel@tonic-gate 		/* Now combine the next few fields that are required for a read
28847c478bd9Sstevel@tonic-gate 		 * operation.  We use this method instead of calling the
28857c478bd9Sstevel@tonic-gate 		 * e1000_shift_out_mdi_bits routine five different times. The format of
28867c478bd9Sstevel@tonic-gate 		 * a MII read instruction consists of a shift out of 14 bits and is
28877c478bd9Sstevel@tonic-gate 		 * defined as follows:
28887c478bd9Sstevel@tonic-gate 		 *    <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
28897c478bd9Sstevel@tonic-gate 		 * followed by a shift in of 18 bits.  This first two bits shifted in
28907c478bd9Sstevel@tonic-gate 		 * are TurnAround bits used to avoid contention on the MDIO pin when a
28917c478bd9Sstevel@tonic-gate 		 * READ operation is performed.  These two bits are thrown away
28927c478bd9Sstevel@tonic-gate 		 * followed by a shift in of 16 bits which contains the desired data.
28937c478bd9Sstevel@tonic-gate 		 */
28947c478bd9Sstevel@tonic-gate 		mdic = ((reg_addr) | (phy_addr << 5) |
28957c478bd9Sstevel@tonic-gate 			(PHY_OP_READ << 10) | (PHY_SOF << 12));
28967c478bd9Sstevel@tonic-gate 
28977c478bd9Sstevel@tonic-gate 		e1000_shift_out_mdi_bits(hw, mdic, 14);
28987c478bd9Sstevel@tonic-gate 
28997c478bd9Sstevel@tonic-gate 		/* Now that we've shifted out the read command to the MII, we need to
29007c478bd9Sstevel@tonic-gate 		 * "shift in" the 16-bit value (18 total bits) of the requested PHY
29017c478bd9Sstevel@tonic-gate 		 * register address.
29027c478bd9Sstevel@tonic-gate 		 */
29037c478bd9Sstevel@tonic-gate 		*phy_data = e1000_shift_in_mdi_bits(hw);
29047c478bd9Sstevel@tonic-gate 	}
29057c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
29067c478bd9Sstevel@tonic-gate }
29077c478bd9Sstevel@tonic-gate 
29087c478bd9Sstevel@tonic-gate /******************************************************************************
29097c478bd9Sstevel@tonic-gate * Writes a value to a PHY register
29107c478bd9Sstevel@tonic-gate *
29117c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
29127c478bd9Sstevel@tonic-gate * reg_addr - address of the PHY register to write
29137c478bd9Sstevel@tonic-gate * data - data to write to the PHY
29147c478bd9Sstevel@tonic-gate ******************************************************************************/
29157c478bd9Sstevel@tonic-gate static int
29167c478bd9Sstevel@tonic-gate e1000_write_phy_reg(struct e1000_hw *hw,
29177c478bd9Sstevel@tonic-gate                     uint32_t reg_addr,
29187c478bd9Sstevel@tonic-gate                     uint16_t phy_data)
29197c478bd9Sstevel@tonic-gate {
29207c478bd9Sstevel@tonic-gate 	uint32_t ret_val;
29217c478bd9Sstevel@tonic-gate 
29227c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_write_phy_reg");
29237c478bd9Sstevel@tonic-gate 
29247c478bd9Sstevel@tonic-gate 	if(hw->phy_type == e1000_phy_igp &&
29257c478bd9Sstevel@tonic-gate 	   (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
29267c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
29277c478bd9Sstevel@tonic-gate 		                                     (uint16_t)reg_addr)))
29287c478bd9Sstevel@tonic-gate 			return ret_val;
29297c478bd9Sstevel@tonic-gate 	}
29307c478bd9Sstevel@tonic-gate 
29317c478bd9Sstevel@tonic-gate 	ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
29327c478bd9Sstevel@tonic-gate 	                                 phy_data);
29337c478bd9Sstevel@tonic-gate 
29347c478bd9Sstevel@tonic-gate 	return ret_val;
29357c478bd9Sstevel@tonic-gate }
29367c478bd9Sstevel@tonic-gate 
29377c478bd9Sstevel@tonic-gate static int
29387c478bd9Sstevel@tonic-gate e1000_write_phy_reg_ex(struct e1000_hw *hw,
29397c478bd9Sstevel@tonic-gate                        uint32_t reg_addr,
29407c478bd9Sstevel@tonic-gate                        uint16_t phy_data)
29417c478bd9Sstevel@tonic-gate {
29427c478bd9Sstevel@tonic-gate 	uint32_t i;
29437c478bd9Sstevel@tonic-gate 	uint32_t mdic = 0;
29447c478bd9Sstevel@tonic-gate 	const uint32_t phy_addr = 1;
29457c478bd9Sstevel@tonic-gate 
29467c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_write_phy_reg_ex");
29477c478bd9Sstevel@tonic-gate 
29487c478bd9Sstevel@tonic-gate 	if(reg_addr > MAX_PHY_REG_ADDRESS) {
29497c478bd9Sstevel@tonic-gate 		DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
29507c478bd9Sstevel@tonic-gate 		return -E1000_ERR_PARAM;
29517c478bd9Sstevel@tonic-gate 	}
29527c478bd9Sstevel@tonic-gate 
29537c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82543) {
29547c478bd9Sstevel@tonic-gate 		/* Set up Op-code, Phy Address, register address, and data intended
29557c478bd9Sstevel@tonic-gate 		 * for the PHY register in the MDI Control register.  The MAC will take
29567c478bd9Sstevel@tonic-gate 		 * care of interfacing with the PHY to send the desired data.
29577c478bd9Sstevel@tonic-gate 		 */
29587c478bd9Sstevel@tonic-gate 		mdic = (((uint32_t) phy_data) |
29597c478bd9Sstevel@tonic-gate 			(reg_addr << E1000_MDIC_REG_SHIFT) |
29607c478bd9Sstevel@tonic-gate 			(phy_addr << E1000_MDIC_PHY_SHIFT) |
29617c478bd9Sstevel@tonic-gate 			(E1000_MDIC_OP_WRITE));
29627c478bd9Sstevel@tonic-gate 
29637c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, MDIC, mdic);
29647c478bd9Sstevel@tonic-gate 
29657c478bd9Sstevel@tonic-gate 		/* Poll the ready bit to see if the MDI read completed */
29667c478bd9Sstevel@tonic-gate 		for(i = 0; i < 640; i++) {
29677c478bd9Sstevel@tonic-gate 			udelay(5);
29687c478bd9Sstevel@tonic-gate 			mdic = E1000_READ_REG(hw, MDIC);
29697c478bd9Sstevel@tonic-gate 			if(mdic & E1000_MDIC_READY) break;
29707c478bd9Sstevel@tonic-gate 		}
29717c478bd9Sstevel@tonic-gate 		if(!(mdic & E1000_MDIC_READY)) {
29727c478bd9Sstevel@tonic-gate 			DEBUGOUT("MDI Write did not complete\n");
29737c478bd9Sstevel@tonic-gate 			return -E1000_ERR_PHY;
29747c478bd9Sstevel@tonic-gate 		}
29757c478bd9Sstevel@tonic-gate 	} else {
29767c478bd9Sstevel@tonic-gate 		/* We'll need to use the SW defined pins to shift the write command
29777c478bd9Sstevel@tonic-gate 		 * out to the PHY. We first send a preamble to the PHY to signal the
29787c478bd9Sstevel@tonic-gate 		 * beginning of the MII instruction.  This is done by sending 32
29797c478bd9Sstevel@tonic-gate 		 * consecutive "1" bits.
29807c478bd9Sstevel@tonic-gate 		 */
29817c478bd9Sstevel@tonic-gate 		e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
29827c478bd9Sstevel@tonic-gate 
29837c478bd9Sstevel@tonic-gate 		/* Now combine the remaining required fields that will indicate a
29847c478bd9Sstevel@tonic-gate 		 * write operation. We use this method instead of calling the
29857c478bd9Sstevel@tonic-gate 		 * e1000_shift_out_mdi_bits routine for each field in the command. The
29867c478bd9Sstevel@tonic-gate 		 * format of a MII write instruction is as follows:
29877c478bd9Sstevel@tonic-gate 		 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
29887c478bd9Sstevel@tonic-gate 		 */
29897c478bd9Sstevel@tonic-gate 		mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
29907c478bd9Sstevel@tonic-gate 			(PHY_OP_WRITE << 12) | (PHY_SOF << 14));
29917c478bd9Sstevel@tonic-gate 		mdic <<= 16;
29927c478bd9Sstevel@tonic-gate 		mdic |= (uint32_t) phy_data;
29937c478bd9Sstevel@tonic-gate 
29947c478bd9Sstevel@tonic-gate 		e1000_shift_out_mdi_bits(hw, mdic, 32);
29957c478bd9Sstevel@tonic-gate 	}
29967c478bd9Sstevel@tonic-gate 
29977c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
29987c478bd9Sstevel@tonic-gate }
29997c478bd9Sstevel@tonic-gate 
30007c478bd9Sstevel@tonic-gate /******************************************************************************
30017c478bd9Sstevel@tonic-gate * Returns the PHY to the power-on reset state
30027c478bd9Sstevel@tonic-gate *
30037c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
30047c478bd9Sstevel@tonic-gate ******************************************************************************/
30057c478bd9Sstevel@tonic-gate static void
30067c478bd9Sstevel@tonic-gate e1000_phy_hw_reset(struct e1000_hw *hw)
30077c478bd9Sstevel@tonic-gate {
30087c478bd9Sstevel@tonic-gate 	uint32_t ctrl, ctrl_ext;
30097c478bd9Sstevel@tonic-gate 
30107c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_phy_hw_reset");
30117c478bd9Sstevel@tonic-gate 
30127c478bd9Sstevel@tonic-gate 	DEBUGOUT("Resetting Phy...\n");
30137c478bd9Sstevel@tonic-gate 
30147c478bd9Sstevel@tonic-gate 	if(hw->mac_type > e1000_82543) {
30157c478bd9Sstevel@tonic-gate 		/* Read the device control register and assert the E1000_CTRL_PHY_RST
30167c478bd9Sstevel@tonic-gate 		 * bit. Then, take it out of reset.
30177c478bd9Sstevel@tonic-gate 		 */
30187c478bd9Sstevel@tonic-gate 		ctrl = E1000_READ_REG(hw, CTRL);
30197c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
30207c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
30217c478bd9Sstevel@tonic-gate 		mdelay(10);
30227c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL, ctrl);
30237c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
30247c478bd9Sstevel@tonic-gate 	} else {
30257c478bd9Sstevel@tonic-gate 		/* Read the Extended Device Control Register, assert the PHY_RESET_DIR
30267c478bd9Sstevel@tonic-gate 		 * bit to put the PHY into reset. Then, take it out of reset.
30277c478bd9Sstevel@tonic-gate 		 */
30287c478bd9Sstevel@tonic-gate 		ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
30297c478bd9Sstevel@tonic-gate 		ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
30307c478bd9Sstevel@tonic-gate 		ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
30317c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
30327c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
30337c478bd9Sstevel@tonic-gate 		mdelay(10);
30347c478bd9Sstevel@tonic-gate 		ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
30357c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
30367c478bd9Sstevel@tonic-gate 		E1000_WRITE_FLUSH(hw);
30377c478bd9Sstevel@tonic-gate 	}
30387c478bd9Sstevel@tonic-gate 	udelay(150);
30397c478bd9Sstevel@tonic-gate }
30407c478bd9Sstevel@tonic-gate 
30417c478bd9Sstevel@tonic-gate /******************************************************************************
30427c478bd9Sstevel@tonic-gate * Resets the PHY
30437c478bd9Sstevel@tonic-gate *
30447c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
30457c478bd9Sstevel@tonic-gate *
30467c478bd9Sstevel@tonic-gate * Sets bit 15 of the MII Control regiser
30477c478bd9Sstevel@tonic-gate ******************************************************************************/
30487c478bd9Sstevel@tonic-gate static int
30497c478bd9Sstevel@tonic-gate e1000_phy_reset(struct e1000_hw *hw)
30507c478bd9Sstevel@tonic-gate {
30517c478bd9Sstevel@tonic-gate 	int32_t ret_val;
30527c478bd9Sstevel@tonic-gate 	uint16_t phy_data;
30537c478bd9Sstevel@tonic-gate 
30547c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_phy_reset");
30557c478bd9Sstevel@tonic-gate 
30567c478bd9Sstevel@tonic-gate 	if(hw->mac_type != e1000_82541_rev_2) {
30577c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
30587c478bd9Sstevel@tonic-gate 			return ret_val;
30597c478bd9Sstevel@tonic-gate 
30607c478bd9Sstevel@tonic-gate 		phy_data |= MII_CR_RESET;
30617c478bd9Sstevel@tonic-gate 		if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
30627c478bd9Sstevel@tonic-gate 			return ret_val;
30637c478bd9Sstevel@tonic-gate 
30647c478bd9Sstevel@tonic-gate 		udelay(1);
30657c478bd9Sstevel@tonic-gate 	} else e1000_phy_hw_reset(hw);
30667c478bd9Sstevel@tonic-gate 
30677c478bd9Sstevel@tonic-gate 	if(hw->phy_type == e1000_phy_igp)
30687c478bd9Sstevel@tonic-gate 		e1000_phy_init_script(hw);
30697c478bd9Sstevel@tonic-gate 
30707c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
30717c478bd9Sstevel@tonic-gate }
30727c478bd9Sstevel@tonic-gate 
30737c478bd9Sstevel@tonic-gate /******************************************************************************
30747c478bd9Sstevel@tonic-gate * Probes the expected PHY address for known PHY IDs
30757c478bd9Sstevel@tonic-gate *
30767c478bd9Sstevel@tonic-gate * hw - Struct containing variables accessed by shared code
30777c478bd9Sstevel@tonic-gate ******************************************************************************/
30787c478bd9Sstevel@tonic-gate static int
30797c478bd9Sstevel@tonic-gate e1000_detect_gig_phy(struct e1000_hw *hw)
30807c478bd9Sstevel@tonic-gate {
30817c478bd9Sstevel@tonic-gate 	int32_t phy_init_status, ret_val;
30827c478bd9Sstevel@tonic-gate 	uint16_t phy_id_high, phy_id_low;
30837c478bd9Sstevel@tonic-gate 	boolean_t match = FALSE;
30847c478bd9Sstevel@tonic-gate 
30857c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_detect_gig_phy");
30867c478bd9Sstevel@tonic-gate 
30877c478bd9Sstevel@tonic-gate 	/* Read the PHY ID Registers to identify which PHY is onboard. */
30887c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high)))
30897c478bd9Sstevel@tonic-gate 		return ret_val;
30907c478bd9Sstevel@tonic-gate 
30917c478bd9Sstevel@tonic-gate 	hw->phy_id = (uint32_t) (phy_id_high << 16);
30927c478bd9Sstevel@tonic-gate 	udelay(20);
30937c478bd9Sstevel@tonic-gate 	if((ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low)))
30947c478bd9Sstevel@tonic-gate 		return ret_val;
30957c478bd9Sstevel@tonic-gate 
30967c478bd9Sstevel@tonic-gate 	hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
30977c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER
30987c478bd9Sstevel@tonic-gate 	hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
30997c478bd9Sstevel@tonic-gate #endif
31007c478bd9Sstevel@tonic-gate 
31017c478bd9Sstevel@tonic-gate 	switch(hw->mac_type) {
31027c478bd9Sstevel@tonic-gate 	case e1000_82543:
31037c478bd9Sstevel@tonic-gate 		if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
31047c478bd9Sstevel@tonic-gate 		break;
31057c478bd9Sstevel@tonic-gate 	case e1000_82544:
31067c478bd9Sstevel@tonic-gate 		if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
31077c478bd9Sstevel@tonic-gate 		break;
31087c478bd9Sstevel@tonic-gate 	case e1000_82540:
31097c478bd9Sstevel@tonic-gate 	case e1000_82545:
31107c478bd9Sstevel@tonic-gate 	case e1000_82545_rev_3:
31117c478bd9Sstevel@tonic-gate 	case e1000_82546:
31127c478bd9Sstevel@tonic-gate 	case e1000_82546_rev_3:
31137c478bd9Sstevel@tonic-gate 		if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
31147c478bd9Sstevel@tonic-gate 		break;
31157c478bd9Sstevel@tonic-gate 	case e1000_82541:
31167c478bd9Sstevel@tonic-gate 	case e1000_82541_rev_2:
31177c478bd9Sstevel@tonic-gate 	case e1000_82547:
31187c478bd9Sstevel@tonic-gate 	case e1000_82547_rev_2:
31197c478bd9Sstevel@tonic-gate 		if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
31207c478bd9Sstevel@tonic-gate 		break;
31217c478bd9Sstevel@tonic-gate 	default:
31227c478bd9Sstevel@tonic-gate 		DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
31237c478bd9Sstevel@tonic-gate 		return -E1000_ERR_CONFIG;
31247c478bd9Sstevel@tonic-gate 	}
31257c478bd9Sstevel@tonic-gate 	phy_init_status = e1000_set_phy_type(hw);
31267c478bd9Sstevel@tonic-gate 
31277c478bd9Sstevel@tonic-gate 	if ((match) && (phy_init_status == E1000_SUCCESS)) {
31287c478bd9Sstevel@tonic-gate 		DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
31297c478bd9Sstevel@tonic-gate 		return E1000_SUCCESS;
31307c478bd9Sstevel@tonic-gate 	}
31317c478bd9Sstevel@tonic-gate 	DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
31327c478bd9Sstevel@tonic-gate 	return -E1000_ERR_PHY;
31337c478bd9Sstevel@tonic-gate }
31347c478bd9Sstevel@tonic-gate 
31357c478bd9Sstevel@tonic-gate /******************************************************************************
31367c478bd9Sstevel@tonic-gate  * Sets up eeprom variables in the hw struct.  Must be called after mac_type
31377c478bd9Sstevel@tonic-gate  * is configured.
31387c478bd9Sstevel@tonic-gate  *
31397c478bd9Sstevel@tonic-gate  * hw - Struct containing variables accessed by shared code
31407c478bd9Sstevel@tonic-gate  *****************************************************************************/
31417c478bd9Sstevel@tonic-gate static void
31427c478bd9Sstevel@tonic-gate e1000_init_eeprom_params(struct e1000_hw *hw)
31437c478bd9Sstevel@tonic-gate {
31447c478bd9Sstevel@tonic-gate 	struct e1000_eeprom_info *eeprom = &hw->eeprom;
31457c478bd9Sstevel@tonic-gate 	uint32_t eecd = E1000_READ_REG(hw, EECD);
31467c478bd9Sstevel@tonic-gate 	uint16_t eeprom_size;
31477c478bd9Sstevel@tonic-gate 
31487c478bd9Sstevel@tonic-gate 	DEBUGFUNC("e1000_init_eeprom_params");
31497c478bd9Sstevel@tonic-gate 
31507c478bd9Sstevel@tonic-gate 	switch (hw->mac_type) {
31517c478bd9Sstevel@tonic-gate 	case e1000_82542_rev2_0:
31527c478bd9Sstevel@tonic-gate 	case e1000_82542_rev2_1:
31537c478bd9Sstevel@tonic-gate 	case e1000_82543:
31547c478bd9Sstevel@tonic-gate 	case e1000_82544:
31557c478bd9Sstevel@tonic-gate 		eeprom->type = e1000_eeprom_microwire;
31567c478bd9Sstevel@tonic-gate 		eeprom->word_size = 64;
31577c478bd9Sstevel@tonic-gate 		eeprom->opcode_bits = 3;
31587c478bd9Sstevel@tonic-gate 		eeprom->address_bits = 6;
31597c478bd9Sstevel@tonic-gate 		eeprom->delay_usec = 50;
31607c478bd9Sstevel@tonic-gate 		break;
31617c478bd9Sstevel@tonic-gate 	case e1000_82540:
31627c478bd9Sstevel@tonic-gate 	case e1000_82545:
31637c478bd9Sstevel@tonic-gate 	case e1000_82545_rev_3:
31647c478bd9Sstevel@tonic-gate 	case e1000_82546:
31657c478bd9Sstevel@tonic-gate 	case e1000_82546_rev_3:
31667c478bd9Sstevel@tonic-gate 		eeprom->type = e1000_eeprom_microwire;
31677c478bd9Sstevel@tonic-gate 		eeprom->opcode_bits = 3;
31687c478bd9Sstevel@tonic-gate 		eeprom->delay_usec = 50;
31697c478bd9Sstevel@tonic-gate 		if(eecd & E1000_EECD_SIZE) {
31707c478bd9Sstevel@tonic-gate 			eeprom->word_size = 256;
31717c478bd9Sstevel@tonic-gate 			eeprom->address_bits = 8;
31727c478bd9Sstevel@tonic-gate 		} else {
31737c478bd9Sstevel@tonic-gate 			eeprom->word_size = 64;
31747c478bd9Sstevel@tonic-gate 			eeprom->address_bits = 6;
31757c478bd9Sstevel@tonic-gate 		}
31767c478bd9Sstevel@tonic-gate 		break;
31777c478bd9Sstevel@tonic-gate 	case e1000_82541:
31787c478bd9Sstevel@tonic-gate 	case e1000_82541_rev_2:
31797c478bd9Sstevel@tonic-gate 	case e1000_82547:
31807c478bd9Sstevel@tonic-gate 	case e1000_82547_rev_2:
31817c478bd9Sstevel@tonic-gate 		if (eecd & E1000_EECD_TYPE) {
31827c478bd9Sstevel@tonic-gate 			eeprom->type = e1000_eeprom_spi;
31837c478bd9Sstevel@tonic-gate 			if (eecd & E1000_EECD_ADDR_BITS) {
31847c478bd9Sstevel@tonic-gate 				eeprom->page_size = 32;
31857c478bd9Sstevel@tonic-gate 				eeprom->address_bits = 16;
31867c478bd9Sstevel@tonic-gate 			} else {
31877c478bd9Sstevel@tonic-gate 				eeprom->page_size = 8;
31887c478bd9Sstevel@tonic-gate 				eeprom->address_bits = 8;
31897c478bd9Sstevel@tonic-gate 			}
31907c478bd9Sstevel@tonic-gate 		} else {
31917c478bd9Sstevel@tonic-gate 			eeprom->type = e1000_eeprom_microwire;
31927c478bd9Sstevel@tonic-gate 			eeprom->opcode_bits = 3;
31937c478bd9Sstevel@tonic-gate 			eeprom->delay_usec = 50;
31947c478bd9Sstevel@tonic-gate 			if (eecd & E1000_EECD_ADDR_BITS) {
31957c478bd9Sstevel@tonic-gate 				eeprom->word_size = 256;
31967c478bd9Sstevel@tonic-gate 				eeprom->address_bits = 8;
31977c478bd9Sstevel@tonic-gate 			} else {
31987c478bd9Sstevel@tonic-gate 				eeprom->word_size = 64;
31997c478bd9Sstevel@tonic-gate 				eeprom->address_bits = 6;
32007c478bd9Sstevel@tonic-gate 			}
32017c478bd9Sstevel@tonic-gate 		}
32027c478bd9Sstevel@tonic-gate 		break;
32037c478bd9Sstevel@tonic-gate 	default:
32047c478bd9Sstevel@tonic-gate 		eeprom->type = e1000_eeprom_spi;
32057c478bd9Sstevel@tonic-gate 		if (eecd & E1000_EECD_ADDR_BITS) {
32067c478bd9Sstevel@tonic-gate 			eeprom->page_size = 32;
32077c478bd9Sstevel@tonic-gate 			eeprom->address_bits = 16;
32087c478bd9Sstevel@tonic-gate 		} else {
32097c478bd9Sstevel@tonic-gate 			eeprom->page_size = 8;
32107c478bd9Sstevel@tonic-gate 			eeprom->address_bits = 8;
32117c478bd9Sstevel@tonic-gate 		}
32127c478bd9Sstevel@tonic-gate 		break;
32137c478bd9Sstevel@tonic-gate 	}
32147c478bd9Sstevel@tonic-gate 
32157c478bd9Sstevel@tonic-gate 	if (eeprom->type == e1000_eeprom_spi) {
32167c478bd9Sstevel@tonic-gate 		eeprom->opcode_bits = 8;
32177c478bd9Sstevel@tonic-gate 		eeprom->delay_usec = 1;
32187c478bd9Sstevel@tonic-gate 		eeprom->word_size = 64;
32197c478bd9Sstevel@tonic-gate 		if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
32207c478bd9Sstevel@tonic-gate 			eeprom_size &= EEPROM_SIZE_MASK;
32217c478bd9Sstevel@tonic-gate 
32227c478bd9Sstevel@tonic-gate 			switch (eeprom_size) {
32237c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_16KB:
32247c478bd9Sstevel@tonic-gate 				eeprom->word_size = 8192;
32257c478bd9Sstevel@tonic-gate 				break;
32267c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_8KB:
32277c478bd9Sstevel@tonic-gate 				eeprom->word_size = 4096;
32287c478bd9Sstevel@tonic-gate 				break;
32297c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_4KB:
32307c478bd9Sstevel@tonic-gate 				eeprom->word_size = 2048;
32317c478bd9Sstevel@tonic-gate 				break;
32327c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_2KB:
32337c478bd9Sstevel@tonic-gate 				eeprom->word_size = 1024;
32347c478bd9Sstevel@tonic-gate 				break;
32357c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_1KB:
32367c478bd9Sstevel@tonic-gate 				eeprom->word_size = 512;
32377c478bd9Sstevel@tonic-gate 				break;
32387c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_512B:
32397c478bd9Sstevel@tonic-gate 				eeprom->word_size = 256;
32407c478bd9Sstevel@tonic-gate 				break;
32417c478bd9Sstevel@tonic-gate 			case EEPROM_SIZE_128B:
32427c478bd9Sstevel@tonic-gate 			default:
32437c478bd9Sstevel@tonic-gate 				break;
32447c478bd9Sstevel@tonic-gate 			}
32457c478bd9Sstevel@tonic-gate 		}
32467c478bd9Sstevel@tonic-gate 	}
32477c478bd9Sstevel@tonic-gate }
32487c478bd9Sstevel@tonic-gate 
32497c478bd9Sstevel@tonic-gate /**
32507c478bd9Sstevel@tonic-gate  * e1000_reset - Reset the adapter
32517c478bd9Sstevel@tonic-gate  */
32527c478bd9Sstevel@tonic-gate 
32537c478bd9Sstevel@tonic-gate static int
32547c478bd9Sstevel@tonic-gate e1000_reset(struct e1000_hw *hw)
32557c478bd9Sstevel@tonic-gate {
32567c478bd9Sstevel@tonic-gate 	uint32_t pba;
32577c478bd9Sstevel@tonic-gate 	/* Repartition Pba for greater than 9k mtu
32587c478bd9Sstevel@tonic-gate 	 * To take effect CTRL.RST is required.
32597c478bd9Sstevel@tonic-gate 	 */
32607c478bd9Sstevel@tonic-gate 
32617c478bd9Sstevel@tonic-gate 	if(hw->mac_type < e1000_82547) {
32627c478bd9Sstevel@tonic-gate 		pba = E1000_PBA_48K;
32637c478bd9Sstevel@tonic-gate 	} else {
32647c478bd9Sstevel@tonic-gate 		pba = E1000_PBA_30K;
32657c478bd9Sstevel@tonic-gate 	}
32667c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG(hw, PBA, pba);
32677c478bd9Sstevel@tonic-gate 
32687c478bd9Sstevel@tonic-gate 	/* flow control settings */
32697c478bd9Sstevel@tonic-gate #if 0
32707c478bd9Sstevel@tonic-gate 	hw->fc_high_water = FC_DEFAULT_HI_THRESH;
32717c478bd9Sstevel@tonic-gate 	hw->fc_low_water = FC_DEFAULT_LO_THRESH;
32727c478bd9Sstevel@tonic-gate 	hw->fc_pause_time = FC_DEFAULT_TX_TIMER;
32737c478bd9Sstevel@tonic-gate 	hw->fc_send_xon = 1;
32747c478bd9Sstevel@tonic-gate 	hw->fc = hw->original_fc;
32757c478bd9Sstevel@tonic-gate #endif
32767c478bd9Sstevel@tonic-gate 
32777c478bd9Sstevel@tonic-gate 	e1000_reset_hw(hw);
32787c478bd9Sstevel@tonic-gate 	if(hw->mac_type >= e1000_82544)
32797c478bd9Sstevel@tonic-gate 		E1000_WRITE_REG(hw, WUC, 0);
32807c478bd9Sstevel@tonic-gate 	return e1000_init_hw(hw);
32817c478bd9Sstevel@tonic-gate }
32827c478bd9Sstevel@tonic-gate 
32837c478bd9Sstevel@tonic-gate /**
32847c478bd9Sstevel@tonic-gate  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
32857c478bd9Sstevel@tonic-gate  * @adapter: board private structure to initialize
32867c478bd9Sstevel@tonic-gate  *
32877c478bd9Sstevel@tonic-gate  * e1000_sw_init initializes the Adapter private data structure.
32887c478bd9Sstevel@tonic-gate  * Fields are initialized based on PCI device information and
32897c478bd9Sstevel@tonic-gate  * OS network device settings (MTU size).
32907c478bd9Sstevel@tonic-gate  **/
32917c478bd9Sstevel@tonic-gate 
32927c478bd9Sstevel@tonic-gate static int
32937c478bd9Sstevel@tonic-gate e1000_sw_init(struct pci_device *pdev, struct e1000_hw *hw)
32947c478bd9Sstevel@tonic-gate {
32957c478bd9Sstevel@tonic-gate 	int result;
32967c478bd9Sstevel@tonic-gate 
32977c478bd9Sstevel@tonic-gate 	/* PCI config space info */
32987c478bd9Sstevel@tonic-gate 	pci_read_config_word(pdev, PCI_VENDOR_ID, &hw->vendor_id);
32997c478bd9Sstevel@tonic-gate 	pci_read_config_word(pdev, PCI_DEVICE_ID, &hw->device_id);
33007c478bd9Sstevel@tonic-gate 	pci_read_config_byte(pdev, PCI_REVISION, &hw->revision_id);
33017c478bd9Sstevel@tonic-gate #if 0
33027c478bd9Sstevel@tonic-gate 	pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID,
33037c478bd9Sstevel@tonic-gate                              &hw->subsystem_vendor_id);
33047c478bd9Sstevel@tonic-gate 	pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
33057c478bd9Sstevel@tonic-gate #endif
33067c478bd9Sstevel@tonic-gate 
33077c478bd9Sstevel@tonic-gate 	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
33087c478bd9Sstevel@tonic-gate 
33097c478bd9Sstevel@tonic-gate 	/* identify the MAC */
33107c478bd9Sstevel@tonic-gate 
33117c478bd9Sstevel@tonic-gate 	result = e1000_set_mac_type(hw);
33127c478bd9Sstevel@tonic-gate 	if (result) {
33137c478bd9Sstevel@tonic-gate 		E1000_ERR("Unknown MAC Type\n");
33147c478bd9Sstevel@tonic-gate 		return result;
33157c478bd9Sstevel@tonic-gate 	}
33167c478bd9Sstevel@tonic-gate 
33177c478bd9Sstevel@tonic-gate 	/* initialize eeprom parameters */
33187c478bd9Sstevel@tonic-gate 
33197c478bd9Sstevel@tonic-gate 	e1000_init_eeprom_params(hw);
33207c478bd9Sstevel@tonic-gate 
33217c478bd9Sstevel@tonic-gate #if 0
33227c478bd9Sstevel@tonic-gate 	if((hw->mac_type == e1000_82541) ||
33237c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82547) ||
33247c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82541_rev_2) ||
33257c478bd9Sstevel@tonic-gate 	   (hw->mac_type == e1000_82547_rev_2))
33267c478bd9Sstevel@tonic-gate 		hw->phy_init_script = 1;
33277c478bd9Sstevel@tonic-gate #endif
33287c478bd9Sstevel@tonic-gate 
33297c478bd9Sstevel@tonic-gate 	e1000_set_media_type(hw);
33307c478bd9Sstevel@tonic-gate 
33317c478bd9Sstevel@tonic-gate #if 0
33327c478bd9Sstevel@tonic-gate 	if(hw->mac_type < e1000_82543)
33337c478bd9Sstevel@tonic-gate 		hw->report_tx_early = 0;
33347c478bd9Sstevel@tonic-gate 	else
33357c478bd9Sstevel@tonic-gate 		hw->report_tx_early = 1;
33367c478bd9Sstevel@tonic-gate 
33377c478bd9Sstevel@tonic-gate 	hw->wait_autoneg_complete = FALSE;
33387c478bd9Sstevel@tonic-gate #endif
33397c478bd9Sstevel@tonic-gate 	hw->tbi_compatibility_en = TRUE;
33407c478bd9Sstevel@tonic-gate #if 0
33417c478bd9Sstevel@tonic-gate 	hw->adaptive_ifs = TRUE;
33427c478bd9Sstevel@tonic-gate 
33437c478bd9Sstevel@tonic-gate 	/* Copper options */
33447c478bd9Sstevel@tonic-gate 
33457c478bd9Sstevel@tonic-gate 	if(hw->media_type == e1000_media_type_copper) {
33467c478bd9Sstevel@tonic-gate 		hw->mdix = AUTO_ALL_MODES;
33477c478bd9Sstevel@tonic-gate 		hw->disable_polarity_correction = FALSE;
33487c478bd9Sstevel@tonic-gate 		hw->master_slave = E1000_MASTER_SLAVE;
33497c478bd9Sstevel@tonic-gate 	}
33507c478bd9Sstevel@tonic-gate #endif
33517c478bd9Sstevel@tonic-gate 	return E1000_SUCCESS;
33527c478bd9Sstevel@tonic-gate }
33537c478bd9Sstevel@tonic-gate 
33547c478bd9Sstevel@tonic-gate static void fill_rx (void)
33557c478bd9Sstevel@tonic-gate {
33567c478bd9Sstevel@tonic-gate 	struct e1000_rx_desc *rd;
33577c478bd9Sstevel@tonic-gate 	rx_last = rx_tail;
33587c478bd9Sstevel@tonic-gate 	rd = rx_base + rx_tail;
33597c478bd9Sstevel@tonic-gate 	rx_tail = (rx_tail + 1) % 8;
33607c478bd9Sstevel@tonic-gate 	memset (rd, 0, 16);
33617c478bd9Sstevel@tonic-gate 	rd->buffer_addr = virt_to_bus(&packet);
33627c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDT, rx_tail);
33637c478bd9Sstevel@tonic-gate }
33647c478bd9Sstevel@tonic-gate 
33657c478bd9Sstevel@tonic-gate static void init_descriptor (void)
33667c478bd9Sstevel@tonic-gate {
33677c478bd9Sstevel@tonic-gate 	unsigned long ptr;
33687c478bd9Sstevel@tonic-gate 	unsigned long tctl;
33697c478bd9Sstevel@tonic-gate 
33707c478bd9Sstevel@tonic-gate 	ptr = virt_to_phys(tx_pool);
33717c478bd9Sstevel@tonic-gate 	if (ptr & 0xf)
33727c478bd9Sstevel@tonic-gate 		ptr = (ptr + 0x10) & (~0xf);
33737c478bd9Sstevel@tonic-gate 
33747c478bd9Sstevel@tonic-gate 	tx_base = phys_to_virt(ptr);
33757c478bd9Sstevel@tonic-gate 
33767c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDBAL, virt_to_bus(tx_base));
33777c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDBAH, 0);
33787c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDLEN, 128);
33797c478bd9Sstevel@tonic-gate 
33807c478bd9Sstevel@tonic-gate 	/* Setup the HW Tx Head and Tail descriptor pointers */
33817c478bd9Sstevel@tonic-gate 
33827c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDH, 0);
33837c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDT, 0);
33847c478bd9Sstevel@tonic-gate 	tx_tail = 0;
33857c478bd9Sstevel@tonic-gate 
33867c478bd9Sstevel@tonic-gate 	/* Program the Transmit Control Register */
33877c478bd9Sstevel@tonic-gate 
33887c478bd9Sstevel@tonic-gate #ifdef LINUX_DRIVER_TCTL
33897c478bd9Sstevel@tonic-gate 	tctl = E1000_READ_REG(&hw, TCTL);
33907c478bd9Sstevel@tonic-gate 
33917c478bd9Sstevel@tonic-gate 	tctl &= ~E1000_TCTL_CT;
33927c478bd9Sstevel@tonic-gate 	tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
33937c478bd9Sstevel@tonic-gate 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
33947c478bd9Sstevel@tonic-gate #else
33957c478bd9Sstevel@tonic-gate 	tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
33967c478bd9Sstevel@tonic-gate 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
33977c478bd9Sstevel@tonic-gate 		(E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
33987c478bd9Sstevel@tonic-gate #endif
33997c478bd9Sstevel@tonic-gate 
34007c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TCTL, tctl);
34017c478bd9Sstevel@tonic-gate 
34027c478bd9Sstevel@tonic-gate 	e1000_config_collision_dist(&hw);
34037c478bd9Sstevel@tonic-gate 
34047c478bd9Sstevel@tonic-gate 
34057c478bd9Sstevel@tonic-gate 	rx_tail = 0;
34067c478bd9Sstevel@tonic-gate 	/* disable receive */
34077c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RCTL, 0);
34087c478bd9Sstevel@tonic-gate 	ptr = virt_to_phys(rx_pool);
34097c478bd9Sstevel@tonic-gate 	if (ptr & 0xf)
34107c478bd9Sstevel@tonic-gate 		ptr = (ptr + 0x10) & (~0xf);
34117c478bd9Sstevel@tonic-gate 	rx_base = phys_to_virt(ptr);
34127c478bd9Sstevel@tonic-gate 
34137c478bd9Sstevel@tonic-gate 	/* Setup the Base and Length of the Rx Descriptor Ring */
34147c478bd9Sstevel@tonic-gate 
34157c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDBAL, virt_to_bus(rx_base));
34167c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDBAH, 0);
34177c478bd9Sstevel@tonic-gate 
34187c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDLEN, 128);
34197c478bd9Sstevel@tonic-gate 
34207c478bd9Sstevel@tonic-gate 	/* Setup the HW Rx Head and Tail Descriptor Pointers */
34217c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDH, 0);
34227c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDT, 0);
34237c478bd9Sstevel@tonic-gate 
34247c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RCTL,
34257c478bd9Sstevel@tonic-gate 		E1000_RCTL_EN |
34267c478bd9Sstevel@tonic-gate 		E1000_RCTL_BAM |
34277c478bd9Sstevel@tonic-gate 		E1000_RCTL_SZ_2048 |
34287c478bd9Sstevel@tonic-gate 		E1000_RCTL_MPE);
34297c478bd9Sstevel@tonic-gate 	fill_rx();
34307c478bd9Sstevel@tonic-gate }
34317c478bd9Sstevel@tonic-gate 
34327c478bd9Sstevel@tonic-gate 
34337c478bd9Sstevel@tonic-gate 
34347c478bd9Sstevel@tonic-gate /**************************************************************************
34357c478bd9Sstevel@tonic-gate POLL - Wait for a frame
34367c478bd9Sstevel@tonic-gate ***************************************************************************/
34377c478bd9Sstevel@tonic-gate static int
34387c478bd9Sstevel@tonic-gate e1000_poll (struct nic *nic, int retrieve)
34397c478bd9Sstevel@tonic-gate {
34407c478bd9Sstevel@tonic-gate 	/* return true if there's an ethernet packet ready to read */
34417c478bd9Sstevel@tonic-gate 	/* nic->packet should contain data on return */
34427c478bd9Sstevel@tonic-gate 	/* nic->packetlen should contain length of data */
34437c478bd9Sstevel@tonic-gate 	struct e1000_rx_desc *rd;
34447c478bd9Sstevel@tonic-gate 
34457c478bd9Sstevel@tonic-gate 	rd = rx_base + rx_last;
34467c478bd9Sstevel@tonic-gate 	if (!rd->status & E1000_RXD_STAT_DD)
34477c478bd9Sstevel@tonic-gate 		return 0;
34487c478bd9Sstevel@tonic-gate 
34497c478bd9Sstevel@tonic-gate 	if ( ! retrieve ) return 1;
34507c478bd9Sstevel@tonic-gate 
34517c478bd9Sstevel@tonic-gate 	//      printf("recv: packet %! -> %! len=%d \n", packet+6, packet,rd->Length);
34527c478bd9Sstevel@tonic-gate 	memcpy (nic->packet, packet, rd->length);
34537c478bd9Sstevel@tonic-gate 	nic->packetlen = rd->length;
34547c478bd9Sstevel@tonic-gate 	fill_rx ();
34557c478bd9Sstevel@tonic-gate 	return 1;
34567c478bd9Sstevel@tonic-gate }
34577c478bd9Sstevel@tonic-gate 
34587c478bd9Sstevel@tonic-gate /**************************************************************************
34597c478bd9Sstevel@tonic-gate TRANSMIT - Transmit a frame
34607c478bd9Sstevel@tonic-gate ***************************************************************************/
34617c478bd9Sstevel@tonic-gate static void
34627c478bd9Sstevel@tonic-gate e1000_transmit (struct nic *nic, const char *d,	/* Destination */
34637c478bd9Sstevel@tonic-gate 		    unsigned int type,	/* Type */
34647c478bd9Sstevel@tonic-gate 		    unsigned int size,	/* size */
34657c478bd9Sstevel@tonic-gate 		    const char *p)	/* Packet */
34667c478bd9Sstevel@tonic-gate {
34677c478bd9Sstevel@tonic-gate 	/* send the packet to destination */
34687c478bd9Sstevel@tonic-gate 	struct eth_hdr {
34697c478bd9Sstevel@tonic-gate 		unsigned char dst_addr[ETH_ALEN];
34707c478bd9Sstevel@tonic-gate 		unsigned char src_addr[ETH_ALEN];
34717c478bd9Sstevel@tonic-gate 		unsigned short type;
34727c478bd9Sstevel@tonic-gate 	} hdr;
34737c478bd9Sstevel@tonic-gate 	struct e1000_tx_desc *txhd;	/* header */
34747c478bd9Sstevel@tonic-gate 	struct e1000_tx_desc *txp;	/* payload */
34757c478bd9Sstevel@tonic-gate 	DEBUGFUNC("send");
34767c478bd9Sstevel@tonic-gate 
34777c478bd9Sstevel@tonic-gate 	memcpy (&hdr.dst_addr, d, ETH_ALEN);
34787c478bd9Sstevel@tonic-gate 	memcpy (&hdr.src_addr, nic->node_addr, ETH_ALEN);
34797c478bd9Sstevel@tonic-gate 
34807c478bd9Sstevel@tonic-gate 	hdr.type = htons (type);
34817c478bd9Sstevel@tonic-gate 	txhd = tx_base + tx_tail;
34827c478bd9Sstevel@tonic-gate 	tx_tail = (tx_tail + 1) % 8;
34837c478bd9Sstevel@tonic-gate 	txp = tx_base + tx_tail;
34847c478bd9Sstevel@tonic-gate 	tx_tail = (tx_tail + 1) % 8;
34857c478bd9Sstevel@tonic-gate 
34867c478bd9Sstevel@tonic-gate 	txhd->buffer_addr = virt_to_bus (&hdr);
34877c478bd9Sstevel@tonic-gate 	txhd->lower.data = sizeof (hdr);
34887c478bd9Sstevel@tonic-gate 	txhd->upper.data = 0;
34897c478bd9Sstevel@tonic-gate 
34907c478bd9Sstevel@tonic-gate 	txp->buffer_addr = virt_to_bus(p);
34917c478bd9Sstevel@tonic-gate 	txp->lower.data = E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS | size;
34927c478bd9Sstevel@tonic-gate 	txp->upper.data = 0;
34937c478bd9Sstevel@tonic-gate 
34947c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDT, tx_tail);
34957c478bd9Sstevel@tonic-gate 	while (!(txp->upper.data & E1000_TXD_STAT_DD)) {
34967c478bd9Sstevel@tonic-gate 		udelay(10);	/* give the nic a chance to write to the register */
34977c478bd9Sstevel@tonic-gate 		poll_interruptions();
34987c478bd9Sstevel@tonic-gate 	}
34997c478bd9Sstevel@tonic-gate 	DEBUGFUNC("send end");
35007c478bd9Sstevel@tonic-gate }
35017c478bd9Sstevel@tonic-gate 
35027c478bd9Sstevel@tonic-gate 
35037c478bd9Sstevel@tonic-gate /**************************************************************************
35047c478bd9Sstevel@tonic-gate DISABLE - Turn off ethernet interface
35057c478bd9Sstevel@tonic-gate ***************************************************************************/
35067c478bd9Sstevel@tonic-gate static void e1000_disable (struct dev *dev __unused)
35077c478bd9Sstevel@tonic-gate {
35087c478bd9Sstevel@tonic-gate 	/* Clear the transmit ring */
35097c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDH, 0);
35107c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TDT, 0);
35117c478bd9Sstevel@tonic-gate 
35127c478bd9Sstevel@tonic-gate 	/* Clear the receive ring */
35137c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDH, 0);
35147c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RDT, 0);
35157c478bd9Sstevel@tonic-gate 
35167c478bd9Sstevel@tonic-gate 	/* put the card in its initial state */
35177c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, CTRL, E1000_CTRL_RST);
35187c478bd9Sstevel@tonic-gate 
35197c478bd9Sstevel@tonic-gate 	/* Turn off the ethernet interface */
35207c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, RCTL, 0);
35217c478bd9Sstevel@tonic-gate 	E1000_WRITE_REG (&hw, TCTL, 0);
35227c478bd9Sstevel@tonic-gate 	mdelay (10);
35237c478bd9Sstevel@tonic-gate 
35247c478bd9Sstevel@tonic-gate 	/* Unmap my window to the device */
35257c478bd9Sstevel@tonic-gate 	iounmap(hw.hw_addr);
35267c478bd9Sstevel@tonic-gate }
35277c478bd9Sstevel@tonic-gate 
35287c478bd9Sstevel@tonic-gate /**************************************************************************
35297c478bd9Sstevel@tonic-gate IRQ - Enable, Disable, or Force interrupts
35307c478bd9Sstevel@tonic-gate ***************************************************************************/
35317c478bd9Sstevel@tonic-gate static void e1000_irq(struct nic *nic __unused, irq_action_t action __unused)
35327c478bd9Sstevel@tonic-gate {
35337c478bd9Sstevel@tonic-gate   switch ( action ) {
35347c478bd9Sstevel@tonic-gate   case DISABLE :
35357c478bd9Sstevel@tonic-gate     break;
35367c478bd9Sstevel@tonic-gate   case ENABLE :
35377c478bd9Sstevel@tonic-gate     break;
35387c478bd9Sstevel@tonic-gate   case FORCE :
35397c478bd9Sstevel@tonic-gate     break;
35407c478bd9Sstevel@tonic-gate   }
35417c478bd9Sstevel@tonic-gate }
35427c478bd9Sstevel@tonic-gate 
35437c478bd9Sstevel@tonic-gate #define IORESOURCE_IO	0x00000100     /* Resource type */
35447c478bd9Sstevel@tonic-gate #define BAR_0		0
35457c478bd9Sstevel@tonic-gate #define BAR_1		1
35467c478bd9Sstevel@tonic-gate #define BAR_5		5
35477c478bd9Sstevel@tonic-gate 
35487c478bd9Sstevel@tonic-gate /**************************************************************************
35497c478bd9Sstevel@tonic-gate PROBE - Look for an adapter, this routine's visible to the outside
35507c478bd9Sstevel@tonic-gate You should omit the last argument struct pci_device * for a non-PCI NIC
35517c478bd9Sstevel@tonic-gate ***************************************************************************/
35527c478bd9Sstevel@tonic-gate static int e1000_probe(struct dev *dev, struct pci_device *p)
35537c478bd9Sstevel@tonic-gate {
35547c478bd9Sstevel@tonic-gate 	struct nic *nic = (struct nic *)dev;
35557c478bd9Sstevel@tonic-gate 	unsigned long mmio_start, mmio_len;
35567c478bd9Sstevel@tonic-gate 	int ret_val, i;
35577c478bd9Sstevel@tonic-gate 
35587c478bd9Sstevel@tonic-gate 	if (p == 0)
35597c478bd9Sstevel@tonic-gate 		return 0;
35607c478bd9Sstevel@tonic-gate 	/* Initialize hw with default values */
35617c478bd9Sstevel@tonic-gate 	memset(&hw, 0, sizeof(hw));
35627c478bd9Sstevel@tonic-gate 	hw.pdev = p;
35637c478bd9Sstevel@tonic-gate 
35647c478bd9Sstevel@tonic-gate #if 1
35657c478bd9Sstevel@tonic-gate 	/* Are these variables needed? */
35667c478bd9Sstevel@tonic-gate 	hw.fc                    = e1000_fc_none;
35677c478bd9Sstevel@tonic-gate #if 0
35687c478bd9Sstevel@tonic-gate 	hw.original_fc           = e1000_fc_none;
35697c478bd9Sstevel@tonic-gate #endif
35707c478bd9Sstevel@tonic-gate 	hw.autoneg_failed        = 0;
35717c478bd9Sstevel@tonic-gate #if 0
35727c478bd9Sstevel@tonic-gate 	hw.get_link_status       = TRUE;
35737c478bd9Sstevel@tonic-gate #endif
35747c478bd9Sstevel@tonic-gate #endif
35757c478bd9Sstevel@tonic-gate 
35767c478bd9Sstevel@tonic-gate 	mmio_start = pci_bar_start(p, PCI_BASE_ADDRESS_0);
35777c478bd9Sstevel@tonic-gate 	mmio_len   = pci_bar_size(p,  PCI_BASE_ADDRESS_0);
35787c478bd9Sstevel@tonic-gate 	hw.hw_addr = ioremap(mmio_start, mmio_len);
35797c478bd9Sstevel@tonic-gate 
35807c478bd9Sstevel@tonic-gate 	for(i = BAR_1; i <= BAR_5; i++) {
35817c478bd9Sstevel@tonic-gate 		if(pci_bar_size(p, i) == 0)
35827c478bd9Sstevel@tonic-gate 			continue;
35837c478bd9Sstevel@tonic-gate 		if(pci_find_capability(p, i) & IORESOURCE_IO) {
35847c478bd9Sstevel@tonic-gate 			hw.io_base = pci_bar_start(p, i);
35857c478bd9Sstevel@tonic-gate 			break;
35867c478bd9Sstevel@tonic-gate                 }
35877c478bd9Sstevel@tonic-gate 	}
35887c478bd9Sstevel@tonic-gate 
35897c478bd9Sstevel@tonic-gate 	adjust_pci_device(p);
35907c478bd9Sstevel@tonic-gate 
35917c478bd9Sstevel@tonic-gate 	nic->ioaddr   = p->ioaddr & ~3;
35927c478bd9Sstevel@tonic-gate 	nic->irqno    = 0;
35937c478bd9Sstevel@tonic-gate 
35947c478bd9Sstevel@tonic-gate 	/* From Matt Hortman <mbhortman@acpthinclient.com> */
35957c478bd9Sstevel@tonic-gate 	/* MAC and Phy settings */
35967c478bd9Sstevel@tonic-gate 
35977c478bd9Sstevel@tonic-gate 	/* setup the private structure */
35987c478bd9Sstevel@tonic-gate 	if (e1000_sw_init(p, &hw) < 0) {
35997c478bd9Sstevel@tonic-gate 		iounmap(hw.hw_addr);
36007c478bd9Sstevel@tonic-gate 		return 0;
36017c478bd9Sstevel@tonic-gate 	}
36027c478bd9Sstevel@tonic-gate 
36037c478bd9Sstevel@tonic-gate 	/* make sure the EEPROM is good */
36047c478bd9Sstevel@tonic-gate 
36057c478bd9Sstevel@tonic-gate 	if (e1000_validate_eeprom_checksum(&hw) < 0) {
36067c478bd9Sstevel@tonic-gate 		printf ("The EEPROM Checksum Is Not Valid\n");
36077c478bd9Sstevel@tonic-gate 		iounmap(hw.hw_addr);
36087c478bd9Sstevel@tonic-gate 		return 0;
36097c478bd9Sstevel@tonic-gate 	}
36107c478bd9Sstevel@tonic-gate 
36117c478bd9Sstevel@tonic-gate 	/* copy the MAC address out of the EEPROM */
36127c478bd9Sstevel@tonic-gate 
36137c478bd9Sstevel@tonic-gate 	e1000_read_mac_addr(&hw);
36147c478bd9Sstevel@tonic-gate 	memcpy (nic->node_addr, hw.mac_addr, ETH_ALEN);
36157c478bd9Sstevel@tonic-gate 
36167c478bd9Sstevel@tonic-gate 	printf("Ethernet addr: %!\n", nic->node_addr);
36177c478bd9Sstevel@tonic-gate 
36187c478bd9Sstevel@tonic-gate 	/* reset the hardware with the new settings */
36197c478bd9Sstevel@tonic-gate 
36207c478bd9Sstevel@tonic-gate 	ret_val = e1000_reset(&hw);
36217c478bd9Sstevel@tonic-gate 	if (ret_val < 0) {
36227c478bd9Sstevel@tonic-gate 		if ((ret_val == -E1000_ERR_NOLINK) ||
36237c478bd9Sstevel@tonic-gate 			(ret_val == -E1000_ERR_TIMEOUT)) {
36247c478bd9Sstevel@tonic-gate 			E1000_ERR("Valid Link not detected\n");
36257c478bd9Sstevel@tonic-gate 		} else {
36267c478bd9Sstevel@tonic-gate 			E1000_ERR("Hardware Initialization Failed\n");
36277c478bd9Sstevel@tonic-gate 		}
36287c478bd9Sstevel@tonic-gate 		iounmap(hw.hw_addr);
36297c478bd9Sstevel@tonic-gate 		return 0;
36307c478bd9Sstevel@tonic-gate 	}
36317c478bd9Sstevel@tonic-gate 	init_descriptor();
36327c478bd9Sstevel@tonic-gate 
36337c478bd9Sstevel@tonic-gate 	/* point to NIC specific routines */
36347c478bd9Sstevel@tonic-gate 	dev->disable  = e1000_disable;
36357c478bd9Sstevel@tonic-gate 	nic->poll     = e1000_poll;
36367c478bd9Sstevel@tonic-gate 	nic->transmit = e1000_transmit;
36377c478bd9Sstevel@tonic-gate 	nic->irq      = e1000_irq;
36387c478bd9Sstevel@tonic-gate 
36397c478bd9Sstevel@tonic-gate 	return 1;
36407c478bd9Sstevel@tonic-gate }
36417c478bd9Sstevel@tonic-gate 
36427c478bd9Sstevel@tonic-gate static struct pci_id e1000_nics[] = {
36437c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1000, "e1000-82542",               "Intel EtherExpressPro1000"),
36447c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1001, "e1000-82543gc-fiber",       "Intel EtherExpressPro1000 82543GC Fiber"),
36457c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1004, "e1000-82543gc-copper",	     "Intel EtherExpressPro1000 82543GC Copper"),
36467c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1008, "e1000-82544ei-copper",      "Intel EtherExpressPro1000 82544EI Copper"),
36477c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1009, "e1000-82544ei-fiber",       "Intel EtherExpressPro1000 82544EI Fiber"),
36487c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x100C, "e1000-82544gc-copper",      "Intel EtherExpressPro1000 82544GC Copper"),
36497c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x100D, "e1000-82544gc-lom",         "Intel EtherExpressPro1000 82544GC LOM"),
36507c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x100E, "e1000-82540em",     	     "Intel EtherExpressPro1000 82540EM"),
36517c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x100F, "e1000-82545em-copper",      "Intel EtherExpressPro1000 82545EM Copper"),
36527c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1010, "e1000-82546eb-copper",      "Intel EtherExpressPro1000 82546EB Copper"),
36537c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1011, "e1000-82545em-fiber",       "Intel EtherExpressPro1000 82545EM Fiber"),
36547c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1012, "e1000-82546eb-fiber", 	     "Intel EtherExpressPro1000 82546EB Copper"),
36557c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1013, "e1000-82541ei",	     "Intel EtherExpressPro1000 82541EI"),
36567c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1015, "e1000-82540em-lom",  	     "Intel EtherExpressPro1000 82540EM LOM"),
36577c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1016, "e1000-82540ep-lom",	     "Intel EtherExpressPro1000 82540EP LOM"),
36587c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1017, "e1000-82540ep",	     "Intel EtherExpressPro1000 82540EP"),
36597c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1018, "e1000-82541ep",	     "Intel EtherExpressPro1000 82541EP"),
36607c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1019, "e1000-82547ei",	     "Intel EtherExpressPro1000 82547EI"),
36617c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x101d, "e1000-82546eb-quad-copper", "Intel EtherExpressPro1000 82546EB Quad Copper"),
36627c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x101e, "e1000-82540ep-lp",	     "Intel EtherExpressPro1000 82540EP LP"),
36637c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1026, "e1000-82545gm-copper",	     "Intel EtherExpressPro1000 82545GM Copper"),
36647c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1027, "e1000-82545gm-fiber",	     "Intel EtherExpressPro1000 82545GM Fiber"),
36657c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1028, "e1000-82545gm-serdes",	     "Intel EtherExpressPro1000 82545GM SERDES"),
36667c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1075, "e1000-82547gi",	     "Intel EtherExpressPro1000 82547GI"),
36677c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1076, "e1000-82541gi",	     "Intel EtherExpressPro1000 82541GI"),
36687c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1077, "e1000-82541gi-mobile",	     "Intel EtherExpressPro1000 82541GI Mobile"),
36697c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1078, "e1000-82541er",	     "Intel EtherExpressPro1000 82541ER"),
36707c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x1079, "e1000-82546gb-copper",	     "Intel EtherExpressPro1000 82546GB Copper"),
36717c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x107a, "e1000-82546gb-fiber",	     "Intel EtherExpressPro1000 82546GB Fiber"),
36727c478bd9Sstevel@tonic-gate PCI_ROM(0x8086, 0x107b, "e1000-82546gb-serdes",	     "Intel EtherExpressPro1000 82546GB SERDES"),
36737c478bd9Sstevel@tonic-gate };
36747c478bd9Sstevel@tonic-gate 
36757c478bd9Sstevel@tonic-gate struct pci_driver e1000_driver = {
36767c478bd9Sstevel@tonic-gate 	.type     = NIC_DRIVER,
36777c478bd9Sstevel@tonic-gate 	.name     = "E1000",
36787c478bd9Sstevel@tonic-gate 	.probe    = e1000_probe,
36797c478bd9Sstevel@tonic-gate 	.ids      = e1000_nics,
36807c478bd9Sstevel@tonic-gate 	.id_count = sizeof(e1000_nics)/sizeof(e1000_nics[0]),
36817c478bd9Sstevel@tonic-gate 	.class    = 0,
36827c478bd9Sstevel@tonic-gate };
3683