xref: /titanic_50/usr/src/uts/common/io/e1000g/e1000g_osdep.c (revision 75eba5b6d79ed4d2ce3daf7b2806306b6b69a938)
1*75eba5b6SRobert Mustacchi /*
2*75eba5b6SRobert Mustacchi  * This file is provided under a CDDLv1 license.  When using or
3*75eba5b6SRobert Mustacchi  * redistributing this file, you may do so under this license.
4*75eba5b6SRobert Mustacchi  * In redistributing this file this license must be included
5*75eba5b6SRobert Mustacchi  * and no other modification of this header file is permitted.
6*75eba5b6SRobert Mustacchi  *
7*75eba5b6SRobert Mustacchi  * CDDL LICENSE SUMMARY
8*75eba5b6SRobert Mustacchi  *
9*75eba5b6SRobert Mustacchi  * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
10*75eba5b6SRobert Mustacchi  *
11*75eba5b6SRobert Mustacchi  * The contents of this file are subject to the terms of Version
12*75eba5b6SRobert Mustacchi  * 1.0 of the Common Development and Distribution License (the "License").
13*75eba5b6SRobert Mustacchi  *
14*75eba5b6SRobert Mustacchi  * You should have received a copy of the License with this software.
15*75eba5b6SRobert Mustacchi  * You can obtain a copy of the License at
16*75eba5b6SRobert Mustacchi  *	http://www.opensolaris.org/os/licensing.
17*75eba5b6SRobert Mustacchi  * See the License for the specific language governing permissions
18*75eba5b6SRobert Mustacchi  * and limitations under the License.
19*75eba5b6SRobert Mustacchi  */
20*75eba5b6SRobert Mustacchi 
21*75eba5b6SRobert Mustacchi /*
22*75eba5b6SRobert Mustacchi  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*75eba5b6SRobert Mustacchi  * Use is subject to license terms.
24*75eba5b6SRobert Mustacchi  */
25*75eba5b6SRobert Mustacchi 
26*75eba5b6SRobert Mustacchi #include "e1000_osdep.h"
27*75eba5b6SRobert Mustacchi #include "e1000_api.h"
28*75eba5b6SRobert Mustacchi 
29*75eba5b6SRobert Mustacchi void
e1000_pci_set_mwi(struct e1000_hw * hw)30*75eba5b6SRobert Mustacchi e1000_pci_set_mwi(struct e1000_hw *hw)
31*75eba5b6SRobert Mustacchi {
32*75eba5b6SRobert Mustacchi 	uint16_t val = hw->bus.pci_cmd_word | CMD_MEM_WRT_INVALIDATE;
33*75eba5b6SRobert Mustacchi 
34*75eba5b6SRobert Mustacchi 	e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
35*75eba5b6SRobert Mustacchi }
36*75eba5b6SRobert Mustacchi 
37*75eba5b6SRobert Mustacchi void
e1000_pci_clear_mwi(struct e1000_hw * hw)38*75eba5b6SRobert Mustacchi e1000_pci_clear_mwi(struct e1000_hw *hw)
39*75eba5b6SRobert Mustacchi {
40*75eba5b6SRobert Mustacchi 	uint16_t val = hw->bus.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE;
41*75eba5b6SRobert Mustacchi 
42*75eba5b6SRobert Mustacchi 	e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
43*75eba5b6SRobert Mustacchi }
44*75eba5b6SRobert Mustacchi 
45*75eba5b6SRobert Mustacchi void
e1000_write_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)46*75eba5b6SRobert Mustacchi e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
47*75eba5b6SRobert Mustacchi {
48*75eba5b6SRobert Mustacchi 	pci_config_put16(OS_DEP(hw)->cfg_handle, reg, *value);
49*75eba5b6SRobert Mustacchi }
50*75eba5b6SRobert Mustacchi 
51*75eba5b6SRobert Mustacchi void
e1000_read_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)52*75eba5b6SRobert Mustacchi e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
53*75eba5b6SRobert Mustacchi {
54*75eba5b6SRobert Mustacchi 	*value =
55*75eba5b6SRobert Mustacchi 	    pci_config_get16(OS_DEP(hw)->cfg_handle, reg);
56*75eba5b6SRobert Mustacchi }
57*75eba5b6SRobert Mustacchi 
58*75eba5b6SRobert Mustacchi /*
59*75eba5b6SRobert Mustacchi  * phy_spd_state - set smart-power-down (SPD) state
60*75eba5b6SRobert Mustacchi  *
61*75eba5b6SRobert Mustacchi  * This only acts on the silicon families that have the SPD feature.
62*75eba5b6SRobert Mustacchi  * For any others, return without doing anything.
63*75eba5b6SRobert Mustacchi  */
64*75eba5b6SRobert Mustacchi void
phy_spd_state(struct e1000_hw * hw,boolean_t enable)65*75eba5b6SRobert Mustacchi phy_spd_state(struct e1000_hw *hw, boolean_t enable)
66*75eba5b6SRobert Mustacchi {
67*75eba5b6SRobert Mustacchi 	int32_t offset;		/* offset to register */
68*75eba5b6SRobert Mustacchi 	uint16_t spd_bit;	/* bit to be set */
69*75eba5b6SRobert Mustacchi 	uint16_t reg;		/* register contents */
70*75eba5b6SRobert Mustacchi 
71*75eba5b6SRobert Mustacchi 	switch (hw->mac.type) {
72*75eba5b6SRobert Mustacchi 	case e1000_82541:
73*75eba5b6SRobert Mustacchi 	case e1000_82547:
74*75eba5b6SRobert Mustacchi 	case e1000_82541_rev_2:
75*75eba5b6SRobert Mustacchi 	case e1000_82547_rev_2:
76*75eba5b6SRobert Mustacchi 		offset = IGP01E1000_GMII_FIFO;
77*75eba5b6SRobert Mustacchi 		spd_bit = IGP01E1000_GMII_SPD;
78*75eba5b6SRobert Mustacchi 		break;
79*75eba5b6SRobert Mustacchi 	case e1000_82571:
80*75eba5b6SRobert Mustacchi 	case e1000_82572:
81*75eba5b6SRobert Mustacchi 	case e1000_82573:
82*75eba5b6SRobert Mustacchi 	case e1000_82574:
83*75eba5b6SRobert Mustacchi 	case e1000_82583:
84*75eba5b6SRobert Mustacchi 		offset = IGP02E1000_PHY_POWER_MGMT;
85*75eba5b6SRobert Mustacchi 		spd_bit = IGP02E1000_PM_SPD;
86*75eba5b6SRobert Mustacchi 		break;
87*75eba5b6SRobert Mustacchi 	default:
88*75eba5b6SRobert Mustacchi 		return;		/* no action */
89*75eba5b6SRobert Mustacchi 	}
90*75eba5b6SRobert Mustacchi 
91*75eba5b6SRobert Mustacchi 	(void) e1000_read_phy_reg(hw, offset, &reg);
92*75eba5b6SRobert Mustacchi 
93*75eba5b6SRobert Mustacchi 	if (enable)
94*75eba5b6SRobert Mustacchi 		reg |= spd_bit;		/* enable: set the spd bit */
95*75eba5b6SRobert Mustacchi 	else
96*75eba5b6SRobert Mustacchi 		reg &= ~spd_bit;	/* disable: clear the spd bit */
97*75eba5b6SRobert Mustacchi 
98*75eba5b6SRobert Mustacchi 	(void) e1000_write_phy_reg(hw, offset, reg);
99*75eba5b6SRobert Mustacchi }
100*75eba5b6SRobert Mustacchi 
101*75eba5b6SRobert Mustacchi /*
102*75eba5b6SRobert Mustacchi  * The real intent of this routine is to return the value from pci-e
103*75eba5b6SRobert Mustacchi  * config space at offset reg into the capability space.
104*75eba5b6SRobert Mustacchi  * ICH devices are "PCI Express"-ish.  They have a configuration space,
105*75eba5b6SRobert Mustacchi  * but do not contain PCI Express Capability registers, so this returns
106*75eba5b6SRobert Mustacchi  * the equivalent of "not supported"
107*75eba5b6SRobert Mustacchi  */
108*75eba5b6SRobert Mustacchi int32_t
e1000_read_pcie_cap_reg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)109*75eba5b6SRobert Mustacchi e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
110*75eba5b6SRobert Mustacchi {
111*75eba5b6SRobert Mustacchi 	*value = pci_config_get16(OS_DEP(hw)->cfg_handle,
112*75eba5b6SRobert Mustacchi 	    PCI_EX_CONF_CAP + reg);
113*75eba5b6SRobert Mustacchi 
114*75eba5b6SRobert Mustacchi 	return (0);
115*75eba5b6SRobert Mustacchi }
116*75eba5b6SRobert Mustacchi 
117*75eba5b6SRobert Mustacchi /*
118*75eba5b6SRobert Mustacchi  * Write the given 16-bit value to pci-e config space at offset reg into the
119*75eba5b6SRobert Mustacchi  * pci-e capability block.  Note that this refers to the pci-e capability block
120*75eba5b6SRobert Mustacchi  * in standard pci config space, not the block in pci-e extended config space.
121*75eba5b6SRobert Mustacchi  */
122*75eba5b6SRobert Mustacchi int32_t
e1000_write_pcie_cap_reg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)123*75eba5b6SRobert Mustacchi e1000_write_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
124*75eba5b6SRobert Mustacchi {
125*75eba5b6SRobert Mustacchi 	uint8_t pcie_id = PCI_CAP_ID_PCI_E;
126*75eba5b6SRobert Mustacchi 	uint16_t pcie_cap;
127*75eba5b6SRobert Mustacchi 	int32_t status;
128*75eba5b6SRobert Mustacchi 
129*75eba5b6SRobert Mustacchi 	/* locate the pci-e capability block */
130*75eba5b6SRobert Mustacchi 	status = pci_lcap_locate(OS_DEP(hw)->cfg_handle, pcie_id, &pcie_cap);
131*75eba5b6SRobert Mustacchi 	if (status == DDI_SUCCESS) {
132*75eba5b6SRobert Mustacchi 
133*75eba5b6SRobert Mustacchi 		/* write at given offset into block */
134*75eba5b6SRobert Mustacchi 		pci_config_put16(OS_DEP(hw)->cfg_handle,
135*75eba5b6SRobert Mustacchi 		    (off_t)(pcie_cap + reg), *value);
136*75eba5b6SRobert Mustacchi 	}
137*75eba5b6SRobert Mustacchi 
138*75eba5b6SRobert Mustacchi 	return (status);
139*75eba5b6SRobert Mustacchi }
140*75eba5b6SRobert Mustacchi 
141*75eba5b6SRobert Mustacchi /*
142*75eba5b6SRobert Mustacchi  * e1000_rar_set_vmdq - Clear the RAR registers
143*75eba5b6SRobert Mustacchi  */
144*75eba5b6SRobert Mustacchi void
e1000_rar_clear(struct e1000_hw * hw,uint32_t index)145*75eba5b6SRobert Mustacchi e1000_rar_clear(struct e1000_hw *hw, uint32_t index)
146*75eba5b6SRobert Mustacchi {
147*75eba5b6SRobert Mustacchi 
148*75eba5b6SRobert Mustacchi 	uint32_t rar_high;
149*75eba5b6SRobert Mustacchi 
150*75eba5b6SRobert Mustacchi 	/* Make the hardware the Address invalid by setting the clear bit */
151*75eba5b6SRobert Mustacchi 	rar_high = ~E1000_RAH_AV;
152*75eba5b6SRobert Mustacchi 
153*75eba5b6SRobert Mustacchi 	E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((index << 1) + 1), rar_high);
154*75eba5b6SRobert Mustacchi 	E1000_WRITE_FLUSH(hw);
155*75eba5b6SRobert Mustacchi }
156*75eba5b6SRobert Mustacchi 
157*75eba5b6SRobert Mustacchi /*
158*75eba5b6SRobert Mustacchi  * For some hardware types, access to NVM & PHY need to be serialized by mutex.
159*75eba5b6SRobert Mustacchi  * The necessary mutexes will have been created by shared code.  Here we destroy
160*75eba5b6SRobert Mustacchi  * that mutexes for just the hardware types that need it.
161*75eba5b6SRobert Mustacchi  */
162*75eba5b6SRobert Mustacchi void
e1000_destroy_hw_mutex(struct e1000_hw * hw)163*75eba5b6SRobert Mustacchi e1000_destroy_hw_mutex(struct e1000_hw *hw)
164*75eba5b6SRobert Mustacchi {
165*75eba5b6SRobert Mustacchi 	struct e1000_dev_spec_ich8lan *dev_spec;
166*75eba5b6SRobert Mustacchi 
167*75eba5b6SRobert Mustacchi 	switch (hw->mac.type) {
168*75eba5b6SRobert Mustacchi 	case e1000_ich8lan:
169*75eba5b6SRobert Mustacchi 	case e1000_ich9lan:
170*75eba5b6SRobert Mustacchi 	case e1000_ich10lan:
171*75eba5b6SRobert Mustacchi 	case e1000_pchlan:
172*75eba5b6SRobert Mustacchi 		dev_spec = &hw->dev_spec.ich8lan;
173*75eba5b6SRobert Mustacchi 		E1000_MUTEX_DESTROY(&dev_spec->nvm_mutex);
174*75eba5b6SRobert Mustacchi 		E1000_MUTEX_DESTROY(&dev_spec->swflag_mutex);
175*75eba5b6SRobert Mustacchi 		break;
176*75eba5b6SRobert Mustacchi 
177*75eba5b6SRobert Mustacchi 	default:
178*75eba5b6SRobert Mustacchi 		break;	/* no action */
179*75eba5b6SRobert Mustacchi 	}
180*75eba5b6SRobert Mustacchi }
181