175eba5b6SRobert Mustacchi /******************************************************************************
275eba5b6SRobert Mustacchi 
3*49b78600SRobert Mustacchi   Copyright (c) 2001-2015, Intel Corporation
475eba5b6SRobert Mustacchi   All rights reserved.
575eba5b6SRobert Mustacchi 
675eba5b6SRobert Mustacchi   Redistribution and use in source and binary forms, with or without
775eba5b6SRobert Mustacchi   modification, are permitted provided that the following conditions are met:
875eba5b6SRobert Mustacchi 
975eba5b6SRobert Mustacchi    1. Redistributions of source code must retain the above copyright notice,
1075eba5b6SRobert Mustacchi       this list of conditions and the following disclaimer.
1175eba5b6SRobert Mustacchi 
1275eba5b6SRobert Mustacchi    2. Redistributions in binary form must reproduce the above copyright
1375eba5b6SRobert Mustacchi       notice, this list of conditions and the following disclaimer in the
1475eba5b6SRobert Mustacchi       documentation and/or other materials provided with the distribution.
1575eba5b6SRobert Mustacchi 
1675eba5b6SRobert Mustacchi    3. Neither the name of the Intel Corporation nor the names of its
1775eba5b6SRobert Mustacchi       contributors may be used to endorse or promote products derived from
1875eba5b6SRobert Mustacchi       this software without specific prior written permission.
1975eba5b6SRobert Mustacchi 
2075eba5b6SRobert Mustacchi   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2175eba5b6SRobert Mustacchi   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2275eba5b6SRobert Mustacchi   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2375eba5b6SRobert Mustacchi   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2475eba5b6SRobert Mustacchi   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2575eba5b6SRobert Mustacchi   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2675eba5b6SRobert Mustacchi   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2775eba5b6SRobert Mustacchi   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2875eba5b6SRobert Mustacchi   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2975eba5b6SRobert Mustacchi   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3075eba5b6SRobert Mustacchi   POSSIBILITY OF SUCH DAMAGE.
3175eba5b6SRobert Mustacchi 
3275eba5b6SRobert Mustacchi ******************************************************************************/
3375eba5b6SRobert Mustacchi /*$FreeBSD$*/
34592a4d85Scc 
3525f2d433Sxy /*
36d5c3073dSchenlu chen - Sun Microsystems - Beijing China  * 82542 Gigabit Ethernet Controller
3725f2d433Sxy  */
3825f2d433Sxy 
3925f2d433Sxy #include "e1000_api.h"
4025f2d433Sxy 
4175eba5b6SRobert Mustacchi static s32  e1000_init_phy_params_82542(struct e1000_hw *hw);
4275eba5b6SRobert Mustacchi static s32  e1000_init_nvm_params_82542(struct e1000_hw *hw);
4375eba5b6SRobert Mustacchi static s32  e1000_init_mac_params_82542(struct e1000_hw *hw);
4475eba5b6SRobert Mustacchi static s32  e1000_get_bus_info_82542(struct e1000_hw *hw);
4575eba5b6SRobert Mustacchi static s32  e1000_reset_hw_82542(struct e1000_hw *hw);
4675eba5b6SRobert Mustacchi static s32  e1000_init_hw_82542(struct e1000_hw *hw);
4775eba5b6SRobert Mustacchi static s32  e1000_setup_link_82542(struct e1000_hw *hw);
4875eba5b6SRobert Mustacchi static s32  e1000_led_on_82542(struct e1000_hw *hw);
4975eba5b6SRobert Mustacchi static s32  e1000_led_off_82542(struct e1000_hw *hw);
50c124a83eSRobert Mustacchi static int  e1000_rar_set_82542(struct e1000_hw *hw, u8 *addr, u32 index);
5125f2d433Sxy static void e1000_clear_hw_cntrs_82542(struct e1000_hw *hw);
52caf05df5SMiles Xu, Sun Microsystems static s32  e1000_read_mac_addr_82542(struct e1000_hw *hw);
5325f2d433Sxy 
5475eba5b6SRobert Mustacchi /**
5575eba5b6SRobert Mustacchi  *  e1000_init_phy_params_82542 - Init PHY func ptrs.
5675eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
5775eba5b6SRobert Mustacchi  **/
e1000_init_phy_params_82542(struct e1000_hw * hw)5875eba5b6SRobert Mustacchi static s32 e1000_init_phy_params_82542(struct e1000_hw *hw)
5925f2d433Sxy {
6025f2d433Sxy 	struct e1000_phy_info *phy = &hw->phy;
6125f2d433Sxy 	s32 ret_val = E1000_SUCCESS;
6225f2d433Sxy 
6325f2d433Sxy 	DEBUGFUNC("e1000_init_phy_params_82542");
6425f2d433Sxy 
65*49b78600SRobert Mustacchi 	phy->type = e1000_phy_none;
6625f2d433Sxy 
6775eba5b6SRobert Mustacchi 	return ret_val;
6825f2d433Sxy }
6925f2d433Sxy 
7075eba5b6SRobert Mustacchi /**
7175eba5b6SRobert Mustacchi  *  e1000_init_nvm_params_82542 - Init NVM func ptrs.
7275eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
7375eba5b6SRobert Mustacchi  **/
e1000_init_nvm_params_82542(struct e1000_hw * hw)7475eba5b6SRobert Mustacchi static s32 e1000_init_nvm_params_82542(struct e1000_hw *hw)
7525f2d433Sxy {
7625f2d433Sxy 	struct e1000_nvm_info *nvm = &hw->nvm;
7725f2d433Sxy 
7825f2d433Sxy 	DEBUGFUNC("e1000_init_nvm_params_82542");
7925f2d433Sxy 
80*49b78600SRobert Mustacchi 	nvm->address_bits	=  6;
81*49b78600SRobert Mustacchi 	nvm->delay_usec		= 50;
82*49b78600SRobert Mustacchi 	nvm->opcode_bits	=  3;
83*49b78600SRobert Mustacchi 	nvm->type		= e1000_nvm_eeprom_microwire;
84*49b78600SRobert Mustacchi 	nvm->word_size		= 64;
8525f2d433Sxy 
8625f2d433Sxy 	/* Function Pointers */
87*49b78600SRobert Mustacchi 	nvm->ops.read		= e1000_read_nvm_microwire;
88*49b78600SRobert Mustacchi 	nvm->ops.release	= e1000_stop_nvm;
89*49b78600SRobert Mustacchi 	nvm->ops.write		= e1000_write_nvm_microwire;
90*49b78600SRobert Mustacchi 	nvm->ops.update		= e1000_update_nvm_checksum_generic;
91*49b78600SRobert Mustacchi 	nvm->ops.validate	= e1000_validate_nvm_checksum_generic;
9225f2d433Sxy 
9375eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
9425f2d433Sxy }
9525f2d433Sxy 
9675eba5b6SRobert Mustacchi /**
9775eba5b6SRobert Mustacchi  *  e1000_init_mac_params_82542 - Init MAC func ptrs.
9875eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
9975eba5b6SRobert Mustacchi  **/
e1000_init_mac_params_82542(struct e1000_hw * hw)10075eba5b6SRobert Mustacchi static s32 e1000_init_mac_params_82542(struct e1000_hw *hw)
10125f2d433Sxy {
10225f2d433Sxy 	struct e1000_mac_info *mac = &hw->mac;
10325f2d433Sxy 
10425f2d433Sxy 	DEBUGFUNC("e1000_init_mac_params_82542");
10525f2d433Sxy 
10625f2d433Sxy 	/* Set media type */
107592a4d85Scc 	hw->phy.media_type = e1000_media_type_fiber;
10825f2d433Sxy 
10925f2d433Sxy 	/* Set mta register count */
11025f2d433Sxy 	mac->mta_reg_count = 128;
11125f2d433Sxy 	/* Set rar entry count */
11225f2d433Sxy 	mac->rar_entry_count = E1000_RAR_ENTRIES;
11325f2d433Sxy 
11425f2d433Sxy 	/* Function pointers */
11525f2d433Sxy 
11625f2d433Sxy 	/* bus type/speed/width */
117592a4d85Scc 	mac->ops.get_bus_info = e1000_get_bus_info_82542;
118caf05df5SMiles Xu, Sun Microsystems 	/* function id */
119caf05df5SMiles Xu, Sun Microsystems 	mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pci;
12025f2d433Sxy 	/* reset */
121592a4d85Scc 	mac->ops.reset_hw = e1000_reset_hw_82542;
12225f2d433Sxy 	/* hw initialization */
123592a4d85Scc 	mac->ops.init_hw = e1000_init_hw_82542;
12425f2d433Sxy 	/* link setup */
125592a4d85Scc 	mac->ops.setup_link = e1000_setup_link_82542;
12625f2d433Sxy 	/* phy/fiber/serdes setup */
127*49b78600SRobert Mustacchi 	mac->ops.setup_physical_interface =
128*49b78600SRobert Mustacchi 					e1000_setup_fiber_serdes_link_generic;
12925f2d433Sxy 	/* check for link */
130592a4d85Scc 	mac->ops.check_for_link = e1000_check_for_fiber_link_generic;
13125f2d433Sxy 	/* multicast address update */
132592a4d85Scc 	mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
13325f2d433Sxy 	/* writing VFTA */
134592a4d85Scc 	mac->ops.write_vfta = e1000_write_vfta_generic;
13525f2d433Sxy 	/* clearing VFTA */
136592a4d85Scc 	mac->ops.clear_vfta = e1000_clear_vfta_generic;
137caf05df5SMiles Xu, Sun Microsystems 	/* read mac address */
138caf05df5SMiles Xu, Sun Microsystems 	mac->ops.read_mac_addr = e1000_read_mac_addr_82542;
1394d737963Sxiangtao you - Sun Microsystems - Beijing China 	/* set RAR */
1404d737963Sxiangtao you - Sun Microsystems - Beijing China 	mac->ops.rar_set = e1000_rar_set_82542;
14125f2d433Sxy 	/* turn on/off LED */
142592a4d85Scc 	mac->ops.led_on = e1000_led_on_82542;
143592a4d85Scc 	mac->ops.led_off = e1000_led_off_82542;
14425f2d433Sxy 	/* clear hardware counters */
145592a4d85Scc 	mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82542;
14625f2d433Sxy 	/* link info */
147*49b78600SRobert Mustacchi 	mac->ops.get_link_up_info =
148*49b78600SRobert Mustacchi 				e1000_get_speed_and_duplex_fiber_serdes_generic;
14925f2d433Sxy 
15075eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
15125f2d433Sxy }
15225f2d433Sxy 
15375eba5b6SRobert Mustacchi /**
15475eba5b6SRobert Mustacchi  *  e1000_init_function_pointers_82542 - Init func ptrs.
15575eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
15625f2d433Sxy  *
15775eba5b6SRobert Mustacchi  *  Called to initialize all function pointers and parameters.
15875eba5b6SRobert Mustacchi  **/
e1000_init_function_pointers_82542(struct e1000_hw * hw)15975eba5b6SRobert Mustacchi void e1000_init_function_pointers_82542(struct e1000_hw *hw)
16025f2d433Sxy {
16125f2d433Sxy 	DEBUGFUNC("e1000_init_function_pointers_82542");
16225f2d433Sxy 
163592a4d85Scc 	hw->mac.ops.init_params = e1000_init_mac_params_82542;
164592a4d85Scc 	hw->nvm.ops.init_params = e1000_init_nvm_params_82542;
165592a4d85Scc 	hw->phy.ops.init_params = e1000_init_phy_params_82542;
16625f2d433Sxy }
16725f2d433Sxy 
16875eba5b6SRobert Mustacchi /**
16975eba5b6SRobert Mustacchi  *  e1000_get_bus_info_82542 - Obtain bus information for adapter
17075eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
17125f2d433Sxy  *
17275eba5b6SRobert Mustacchi  *  This will obtain information about the HW bus for which the
17375eba5b6SRobert Mustacchi  *  adapter is attached and stores it in the hw structure.
17475eba5b6SRobert Mustacchi  **/
e1000_get_bus_info_82542(struct e1000_hw * hw)17575eba5b6SRobert Mustacchi static s32 e1000_get_bus_info_82542(struct e1000_hw *hw)
17625f2d433Sxy {
17725f2d433Sxy 	DEBUGFUNC("e1000_get_bus_info_82542");
17825f2d433Sxy 
17925f2d433Sxy 	hw->bus.type = e1000_bus_type_pci;
18025f2d433Sxy 	hw->bus.speed = e1000_bus_speed_unknown;
18125f2d433Sxy 	hw->bus.width = e1000_bus_width_unknown;
18225f2d433Sxy 
18375eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
18425f2d433Sxy }
18525f2d433Sxy 
18675eba5b6SRobert Mustacchi /**
18775eba5b6SRobert Mustacchi  *  e1000_reset_hw_82542 - Reset hardware
18875eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
18925f2d433Sxy  *
19075eba5b6SRobert Mustacchi  *  This resets the hardware into a known state.
19175eba5b6SRobert Mustacchi  **/
e1000_reset_hw_82542(struct e1000_hw * hw)19275eba5b6SRobert Mustacchi static s32 e1000_reset_hw_82542(struct e1000_hw *hw)
19325f2d433Sxy {
19425f2d433Sxy 	struct e1000_bus_info *bus = &hw->bus;
19525f2d433Sxy 	s32 ret_val = E1000_SUCCESS;
196fe62dec3SChen-Liang Xu 	u32 ctrl;
19725f2d433Sxy 
19825f2d433Sxy 	DEBUGFUNC("e1000_reset_hw_82542");
19925f2d433Sxy 
20025f2d433Sxy 	if (hw->revision_id == E1000_REVISION_2) {
20125f2d433Sxy 		DEBUGOUT("Disabling MWI on 82542 rev 2\n");
20225f2d433Sxy 		e1000_pci_clear_mwi(hw);
20325f2d433Sxy 	}
20425f2d433Sxy 
20525f2d433Sxy 	DEBUGOUT("Masking off all interrupts\n");
20625f2d433Sxy 	E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
20725f2d433Sxy 
20825f2d433Sxy 	E1000_WRITE_REG(hw, E1000_RCTL, 0);
20925f2d433Sxy 	E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
21025f2d433Sxy 	E1000_WRITE_FLUSH(hw);
21125f2d433Sxy 
21225f2d433Sxy 	/*
21325f2d433Sxy 	 * Delay to allow any outstanding PCI transactions to complete before
21425f2d433Sxy 	 * resetting the device
21525f2d433Sxy 	 */
21625f2d433Sxy 	msec_delay(10);
21725f2d433Sxy 
21825f2d433Sxy 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
21925f2d433Sxy 
22025f2d433Sxy 	DEBUGOUT("Issuing a global reset to 82542/82543 MAC\n");
22125f2d433Sxy 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
22225f2d433Sxy 
223592a4d85Scc 	hw->nvm.ops.reload(hw);
22425f2d433Sxy 	msec_delay(2);
22525f2d433Sxy 
22625f2d433Sxy 	E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
22775eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_ICR);
22825f2d433Sxy 
22925f2d433Sxy 	if (hw->revision_id == E1000_REVISION_2) {
23025f2d433Sxy 		if (bus->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
23125f2d433Sxy 			e1000_pci_set_mwi(hw);
23225f2d433Sxy 	}
23375eba5b6SRobert Mustacchi 
23475eba5b6SRobert Mustacchi 	return ret_val;
23525f2d433Sxy }
23625f2d433Sxy 
23775eba5b6SRobert Mustacchi /**
23875eba5b6SRobert Mustacchi  *  e1000_init_hw_82542 - Initialize hardware
23975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
24025f2d433Sxy  *
24175eba5b6SRobert Mustacchi  *  This inits the hardware readying it for operation.
24275eba5b6SRobert Mustacchi  **/
e1000_init_hw_82542(struct e1000_hw * hw)24375eba5b6SRobert Mustacchi static s32 e1000_init_hw_82542(struct e1000_hw *hw)
24425f2d433Sxy {
24525f2d433Sxy 	struct e1000_mac_info *mac = &hw->mac;
246d5c3073dSchenlu chen - Sun Microsystems - Beijing China 	struct e1000_dev_spec_82542 *dev_spec = &hw->dev_spec._82542;
24725f2d433Sxy 	s32 ret_val = E1000_SUCCESS;
24825f2d433Sxy 	u32 ctrl;
24925f2d433Sxy 	u16 i;
25025f2d433Sxy 
25125f2d433Sxy 	DEBUGFUNC("e1000_init_hw_82542");
25225f2d433Sxy 
25325f2d433Sxy 	/* Disabling VLAN filtering */
25425f2d433Sxy 	E1000_WRITE_REG(hw, E1000_VET, 0);
255592a4d85Scc 	mac->ops.clear_vfta(hw);
25625f2d433Sxy 
25725f2d433Sxy 	/* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
25825f2d433Sxy 	if (hw->revision_id == E1000_REVISION_2) {
25925f2d433Sxy 		DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
26025f2d433Sxy 		e1000_pci_clear_mwi(hw);
26125f2d433Sxy 		E1000_WRITE_REG(hw, E1000_RCTL, E1000_RCTL_RST);
26225f2d433Sxy 		E1000_WRITE_FLUSH(hw);
26325f2d433Sxy 		msec_delay(5);
26425f2d433Sxy 	}
26525f2d433Sxy 
26625f2d433Sxy 	/* Setup the receive address. */
26725f2d433Sxy 	e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
26825f2d433Sxy 
26925f2d433Sxy 	/* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
27025f2d433Sxy 	if (hw->revision_id == E1000_REVISION_2) {
27125f2d433Sxy 		E1000_WRITE_REG(hw, E1000_RCTL, 0);
27225f2d433Sxy 		E1000_WRITE_FLUSH(hw);
27325f2d433Sxy 		msec_delay(1);
27425f2d433Sxy 		if (hw->bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
27525f2d433Sxy 			e1000_pci_set_mwi(hw);
27625f2d433Sxy 	}
27725f2d433Sxy 
27825f2d433Sxy 	/* Zero out the Multicast HASH table */
27925f2d433Sxy 	DEBUGOUT("Zeroing the MTA\n");
28025f2d433Sxy 	for (i = 0; i < mac->mta_reg_count; i++)
28125f2d433Sxy 		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
28225f2d433Sxy 
28325f2d433Sxy 	/*
28425f2d433Sxy 	 * Set the PCI priority bit correctly in the CTRL register.  This
28525f2d433Sxy 	 * determines if the adapter gives priority to receives, or if it
28625f2d433Sxy 	 * gives equal priority to transmits and receives.
28725f2d433Sxy 	 */
28825f2d433Sxy 	if (dev_spec->dma_fairness) {
28925f2d433Sxy 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
29025f2d433Sxy 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR);
29125f2d433Sxy 	}
29225f2d433Sxy 
29325f2d433Sxy 	/* Setup link and flow control */
29425f2d433Sxy 	ret_val = e1000_setup_link_82542(hw);
29525f2d433Sxy 
29625f2d433Sxy 	/*
29725f2d433Sxy 	 * Clear all of the statistics registers (clear on read).  It is
29825f2d433Sxy 	 * important that we do this after we have tried to establish link
29925f2d433Sxy 	 * because the symbol error count will increment wildly if there
30025f2d433Sxy 	 * is no link.
30125f2d433Sxy 	 */
30225f2d433Sxy 	e1000_clear_hw_cntrs_82542(hw);
30325f2d433Sxy 
30475eba5b6SRobert Mustacchi 	return ret_val;
30525f2d433Sxy }
30625f2d433Sxy 
30775eba5b6SRobert Mustacchi /**
30875eba5b6SRobert Mustacchi  *  e1000_setup_link_82542 - Setup flow control and link settings
30975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
31025f2d433Sxy  *
31175eba5b6SRobert Mustacchi  *  Determines which flow control settings to use, then configures flow
31275eba5b6SRobert Mustacchi  *  control.  Calls the appropriate media-specific link configuration
31375eba5b6SRobert Mustacchi  *  function.  Assuming the adapter has a valid link partner, a valid link
31475eba5b6SRobert Mustacchi  *  should be established.  Assumes the hardware has previously been reset
31575eba5b6SRobert Mustacchi  *  and the transmitter and receiver are not enabled.
31675eba5b6SRobert Mustacchi  **/
e1000_setup_link_82542(struct e1000_hw * hw)31775eba5b6SRobert Mustacchi static s32 e1000_setup_link_82542(struct e1000_hw *hw)
31825f2d433Sxy {
31925f2d433Sxy 	struct e1000_mac_info *mac = &hw->mac;
320*49b78600SRobert Mustacchi 	s32 ret_val;
32125f2d433Sxy 
32225f2d433Sxy 	DEBUGFUNC("e1000_setup_link_82542");
32325f2d433Sxy 
32425f2d433Sxy 	ret_val = e1000_set_default_fc_generic(hw);
32525f2d433Sxy 	if (ret_val)
32625f2d433Sxy 		goto out;
32725f2d433Sxy 
328623ff785Schenlu chen - Sun Microsystems - Beijing China 	hw->fc.requested_mode &= ~e1000_fc_tx_pause;
32925f2d433Sxy 
330*49b78600SRobert Mustacchi 	if (mac->report_tx_early)
331623ff785Schenlu chen - Sun Microsystems - Beijing China 		hw->fc.requested_mode &= ~e1000_fc_rx_pause;
33225f2d433Sxy 
33325f2d433Sxy 	/*
334d5c3073dSchenlu chen - Sun Microsystems - Beijing China 	 * Save off the requested flow control mode for use later.  Depending
335d5c3073dSchenlu chen - Sun Microsystems - Beijing China 	 * on the link partner's capabilities, we may or may not use this mode.
33625f2d433Sxy 	 */
337623ff785Schenlu chen - Sun Microsystems - Beijing China 	hw->fc.current_mode = hw->fc.requested_mode;
33825f2d433Sxy 
339d5c3073dSchenlu chen - Sun Microsystems - Beijing China 	DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
340*49b78600SRobert Mustacchi 		  hw->fc.current_mode);
34125f2d433Sxy 
34225f2d433Sxy 	/* Call the necessary subroutine to configure the link. */
343592a4d85Scc 	ret_val = mac->ops.setup_physical_interface(hw);
34425f2d433Sxy 	if (ret_val)
34525f2d433Sxy 		goto out;
34625f2d433Sxy 
34725f2d433Sxy 	/*
34825f2d433Sxy 	 * Initialize the flow control address, type, and PAUSE timer
34925f2d433Sxy 	 * registers to their default values.  This is done even if flow
35025f2d433Sxy 	 * control is disabled, because it does not hurt anything to
35125f2d433Sxy 	 * initialize these registers.
35225f2d433Sxy 	 */
35325f2d433Sxy 	DEBUGOUT("Initializing Flow Control address, type and timer regs\n");
35425f2d433Sxy 
35525f2d433Sxy 	E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
35625f2d433Sxy 	E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
35725f2d433Sxy 	E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE);
35825f2d433Sxy 
359592a4d85Scc 	E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
36025f2d433Sxy 
36125f2d433Sxy 	ret_val = e1000_set_fc_watermarks_generic(hw);
36225f2d433Sxy 
36325f2d433Sxy out:
36475eba5b6SRobert Mustacchi 	return ret_val;
36525f2d433Sxy }
36625f2d433Sxy 
36775eba5b6SRobert Mustacchi /**
36875eba5b6SRobert Mustacchi  *  e1000_led_on_82542 - Turn on SW controllable LED
36975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
37025f2d433Sxy  *
37175eba5b6SRobert Mustacchi  *  Turns the SW defined LED on.
37275eba5b6SRobert Mustacchi  **/
e1000_led_on_82542(struct e1000_hw * hw)37375eba5b6SRobert Mustacchi static s32 e1000_led_on_82542(struct e1000_hw *hw)
37425f2d433Sxy {
37525f2d433Sxy 	u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
37625f2d433Sxy 
37725f2d433Sxy 	DEBUGFUNC("e1000_led_on_82542");
37825f2d433Sxy 
37925f2d433Sxy 	ctrl |= E1000_CTRL_SWDPIN0;
38025f2d433Sxy 	ctrl |= E1000_CTRL_SWDPIO0;
38125f2d433Sxy 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
38225f2d433Sxy 
38375eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
38425f2d433Sxy }
38525f2d433Sxy 
38675eba5b6SRobert Mustacchi /**
38775eba5b6SRobert Mustacchi  *  e1000_led_off_82542 - Turn off SW controllable LED
38875eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
38925f2d433Sxy  *
39075eba5b6SRobert Mustacchi  *  Turns the SW defined LED off.
39175eba5b6SRobert Mustacchi  **/
e1000_led_off_82542(struct e1000_hw * hw)39275eba5b6SRobert Mustacchi static s32 e1000_led_off_82542(struct e1000_hw *hw)
39325f2d433Sxy {
39425f2d433Sxy 	u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
39525f2d433Sxy 
39625f2d433Sxy 	DEBUGFUNC("e1000_led_off_82542");
39725f2d433Sxy 
39825f2d433Sxy 	ctrl &= ~E1000_CTRL_SWDPIN0;
39925f2d433Sxy 	ctrl |= E1000_CTRL_SWDPIO0;
40025f2d433Sxy 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
40125f2d433Sxy 
40275eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
40325f2d433Sxy }
40425f2d433Sxy 
40575eba5b6SRobert Mustacchi /**
40675eba5b6SRobert Mustacchi  *  e1000_rar_set_82542 - Set receive address register
40775eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
40875eba5b6SRobert Mustacchi  *  @addr: pointer to the receive address
40975eba5b6SRobert Mustacchi  *  @index: receive address array register
4104d737963Sxiangtao you - Sun Microsystems - Beijing China  *
41175eba5b6SRobert Mustacchi  *  Sets the receive address array register at index to the address passed
41275eba5b6SRobert Mustacchi  *  in by addr.
41375eba5b6SRobert Mustacchi  **/
e1000_rar_set_82542(struct e1000_hw * hw,u8 * addr,u32 index)414c124a83eSRobert Mustacchi static int e1000_rar_set_82542(struct e1000_hw *hw, u8 *addr, u32 index)
4154d737963Sxiangtao you - Sun Microsystems - Beijing China {
4164d737963Sxiangtao you - Sun Microsystems - Beijing China 	u32 rar_low, rar_high;
4174d737963Sxiangtao you - Sun Microsystems - Beijing China 
4184d737963Sxiangtao you - Sun Microsystems - Beijing China 	DEBUGFUNC("e1000_rar_set_82542");
4194d737963Sxiangtao you - Sun Microsystems - Beijing China 
4204d737963Sxiangtao you - Sun Microsystems - Beijing China 	/*
4214d737963Sxiangtao you - Sun Microsystems - Beijing China 	 * HW expects these in little endian so we reverse the byte order
4224d737963Sxiangtao you - Sun Microsystems - Beijing China 	 * from network order (big endian) to little endian
4234d737963Sxiangtao you - Sun Microsystems - Beijing China 	 */
424*49b78600SRobert Mustacchi 	rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
425*49b78600SRobert Mustacchi 		   ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4264d737963Sxiangtao you - Sun Microsystems - Beijing China 
4274d737963Sxiangtao you - Sun Microsystems - Beijing China 	rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4284d737963Sxiangtao you - Sun Microsystems - Beijing China 
4294d737963Sxiangtao you - Sun Microsystems - Beijing China 	/* If MAC address zero, no need to set the AV bit */
430d5c3073dSchenlu chen - Sun Microsystems - Beijing China 	if (rar_low || rar_high)
431d5c3073dSchenlu chen - Sun Microsystems - Beijing China 		rar_high |= E1000_RAH_AV;
4324d737963Sxiangtao you - Sun Microsystems - Beijing China 
4334d737963Sxiangtao you - Sun Microsystems - Beijing China 	E1000_WRITE_REG_ARRAY(hw, E1000_RA, (index << 1), rar_low);
4344d737963Sxiangtao you - Sun Microsystems - Beijing China 	E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((index << 1) + 1), rar_high);
435*49b78600SRobert Mustacchi 
436c124a83eSRobert Mustacchi 	return E1000_SUCCESS;
4374d737963Sxiangtao you - Sun Microsystems - Beijing China }
4384d737963Sxiangtao you - Sun Microsystems - Beijing China 
43975eba5b6SRobert Mustacchi /**
44075eba5b6SRobert Mustacchi  *  e1000_translate_register_82542 - Translate the proper register offset
44175eba5b6SRobert Mustacchi  *  @reg: e1000 register to be read
44225f2d433Sxy  *
44375eba5b6SRobert Mustacchi  *  Registers in 82542 are located in different offsets than other adapters
44475eba5b6SRobert Mustacchi  *  even though they function in the same manner.  This function takes in
44575eba5b6SRobert Mustacchi  *  the name of the register to read and returns the correct offset for
44675eba5b6SRobert Mustacchi  *  82542 silicon.
44775eba5b6SRobert Mustacchi  **/
e1000_translate_register_82542(u32 reg)44875eba5b6SRobert Mustacchi u32 e1000_translate_register_82542(u32 reg)
44925f2d433Sxy {
45025f2d433Sxy 	/*
45125f2d433Sxy 	 * Some of the 82542 registers are located at different
45225f2d433Sxy 	 * offsets than they are in newer adapters.
45325f2d433Sxy 	 * Despite the difference in location, the registers
45425f2d433Sxy 	 * function in the same manner.
45525f2d433Sxy 	 */
45625f2d433Sxy 	switch (reg) {
45775eba5b6SRobert Mustacchi 	case E1000_RA:
45825f2d433Sxy 		reg = 0x00040;
45925f2d433Sxy 		break;
46025f2d433Sxy 	case E1000_RDTR:
46125f2d433Sxy 		reg = 0x00108;
46225f2d433Sxy 		break;
463592a4d85Scc 	case E1000_RDBAL(0):
46425f2d433Sxy 		reg = 0x00110;
46525f2d433Sxy 		break;
466592a4d85Scc 	case E1000_RDBAH(0):
46725f2d433Sxy 		reg = 0x00114;
46825f2d433Sxy 		break;
469592a4d85Scc 	case E1000_RDLEN(0):
47025f2d433Sxy 		reg = 0x00118;
47125f2d433Sxy 		break;
472592a4d85Scc 	case E1000_RDH(0):
47325f2d433Sxy 		reg = 0x00120;
47425f2d433Sxy 		break;
475592a4d85Scc 	case E1000_RDT(0):
47625f2d433Sxy 		reg = 0x00128;
47725f2d433Sxy 		break;
478592a4d85Scc 	case E1000_RDBAL(1):
47925f2d433Sxy 		reg = 0x00138;
48025f2d433Sxy 		break;
481592a4d85Scc 	case E1000_RDBAH(1):
48225f2d433Sxy 		reg = 0x0013C;
48325f2d433Sxy 		break;
484592a4d85Scc 	case E1000_RDLEN(1):
48525f2d433Sxy 		reg = 0x00140;
48625f2d433Sxy 		break;
487592a4d85Scc 	case E1000_RDH(1):
48825f2d433Sxy 		reg = 0x00148;
48925f2d433Sxy 		break;
490592a4d85Scc 	case E1000_RDT(1):
49125f2d433Sxy 		reg = 0x00150;
49225f2d433Sxy 		break;
49325f2d433Sxy 	case E1000_FCRTH:
49425f2d433Sxy 		reg = 0x00160;
49525f2d433Sxy 		break;
49625f2d433Sxy 	case E1000_FCRTL:
49725f2d433Sxy 		reg = 0x00168;
49825f2d433Sxy 		break;
49925f2d433Sxy 	case E1000_MTA:
50025f2d433Sxy 		reg = 0x00200;
50125f2d433Sxy 		break;
502592a4d85Scc 	case E1000_TDBAL(0):
50325f2d433Sxy 		reg = 0x00420;
50425f2d433Sxy 		break;
505592a4d85Scc 	case E1000_TDBAH(0):
50625f2d433Sxy 		reg = 0x00424;
50725f2d433Sxy 		break;
508592a4d85Scc 	case E1000_TDLEN(0):
50925f2d433Sxy 		reg = 0x00428;
51025f2d433Sxy 		break;
511592a4d85Scc 	case E1000_TDH(0):
51225f2d433Sxy 		reg = 0x00430;
51325f2d433Sxy 		break;
514592a4d85Scc 	case E1000_TDT(0):
51525f2d433Sxy 		reg = 0x00438;
51625f2d433Sxy 		break;
51725f2d433Sxy 	case E1000_TIDV:
51825f2d433Sxy 		reg = 0x00440;
51925f2d433Sxy 		break;
52025f2d433Sxy 	case E1000_VFTA:
52125f2d433Sxy 		reg = 0x00600;
52225f2d433Sxy 		break;
52325f2d433Sxy 	case E1000_TDFH:
52425f2d433Sxy 		reg = 0x08010;
52525f2d433Sxy 		break;
52625f2d433Sxy 	case E1000_TDFT:
52725f2d433Sxy 		reg = 0x08018;
52825f2d433Sxy 		break;
52925f2d433Sxy 	default:
53025f2d433Sxy 		break;
53125f2d433Sxy 	}
53225f2d433Sxy 
53375eba5b6SRobert Mustacchi 	return reg;
53425f2d433Sxy }
53525f2d433Sxy 
53675eba5b6SRobert Mustacchi /**
53775eba5b6SRobert Mustacchi  *  e1000_clear_hw_cntrs_82542 - Clear device specific hardware counters
53875eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
53925f2d433Sxy  *
54075eba5b6SRobert Mustacchi  *  Clears the hardware counters by reading the counter registers.
54175eba5b6SRobert Mustacchi  **/
e1000_clear_hw_cntrs_82542(struct e1000_hw * hw)54275eba5b6SRobert Mustacchi static void e1000_clear_hw_cntrs_82542(struct e1000_hw *hw)
54325f2d433Sxy {
54425f2d433Sxy 	DEBUGFUNC("e1000_clear_hw_cntrs_82542");
54525f2d433Sxy 
54625f2d433Sxy 	e1000_clear_hw_cntrs_base_generic(hw);
54725f2d433Sxy 
54875eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC64);
54975eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC127);
55075eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC255);
55175eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC511);
55275eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC1023);
55375eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PRC1522);
55475eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC64);
55575eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC127);
55675eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC255);
55775eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC511);
55875eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC1023);
55975eba5b6SRobert Mustacchi 	E1000_READ_REG(hw, E1000_PTC1522);
56025f2d433Sxy }
561caf05df5SMiles Xu, Sun Microsystems 
56275eba5b6SRobert Mustacchi /**
56375eba5b6SRobert Mustacchi  *  e1000_read_mac_addr_82542 - Read device MAC address
56475eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
565caf05df5SMiles Xu, Sun Microsystems  *
56675eba5b6SRobert Mustacchi  *  Reads the device MAC address from the EEPROM and stores the value.
56775eba5b6SRobert Mustacchi  **/
e1000_read_mac_addr_82542(struct e1000_hw * hw)568*49b78600SRobert Mustacchi s32 e1000_read_mac_addr_82542(struct e1000_hw *hw)
569caf05df5SMiles Xu, Sun Microsystems {
570caf05df5SMiles Xu, Sun Microsystems 	s32  ret_val = E1000_SUCCESS;
571caf05df5SMiles Xu, Sun Microsystems 	u16 offset, nvm_data, i;
572caf05df5SMiles Xu, Sun Microsystems 
573caf05df5SMiles Xu, Sun Microsystems 	DEBUGFUNC("e1000_read_mac_addr");
574caf05df5SMiles Xu, Sun Microsystems 
575caf05df5SMiles Xu, Sun Microsystems 	for (i = 0; i < ETH_ADDR_LEN; i += 2) {
576caf05df5SMiles Xu, Sun Microsystems 		offset = i >> 1;
577caf05df5SMiles Xu, Sun Microsystems 		ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
578caf05df5SMiles Xu, Sun Microsystems 		if (ret_val) {
579caf05df5SMiles Xu, Sun Microsystems 			DEBUGOUT("NVM Read Error\n");
580caf05df5SMiles Xu, Sun Microsystems 			goto out;
581caf05df5SMiles Xu, Sun Microsystems 		}
582caf05df5SMiles Xu, Sun Microsystems 		hw->mac.perm_addr[i] = (u8)(nvm_data & 0xFF);
583caf05df5SMiles Xu, Sun Microsystems 		hw->mac.perm_addr[i+1] = (u8)(nvm_data >> 8);
584caf05df5SMiles Xu, Sun Microsystems 	}
585caf05df5SMiles Xu, Sun Microsystems 
586caf05df5SMiles Xu, Sun Microsystems 	for (i = 0; i < ETH_ADDR_LEN; i++)
587caf05df5SMiles Xu, Sun Microsystems 		hw->mac.addr[i] = hw->mac.perm_addr[i];
588caf05df5SMiles Xu, Sun Microsystems 
58975eba5b6SRobert Mustacchi out:
59075eba5b6SRobert Mustacchi 	return ret_val;
591caf05df5SMiles Xu, Sun Microsystems }
592