xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000_osdep.c (revision 10805:3651cd54ec3f)
14919Sxy150489 /*
24919Sxy150489  * This file is provided under a CDDLv1 license.  When using or
34919Sxy150489  * redistributing this file, you may do so under this license.
44919Sxy150489  * In redistributing this file this license must be included
54919Sxy150489  * and no other modification of this header file is permitted.
64919Sxy150489  *
74919Sxy150489  * CDDL LICENSE SUMMARY
84919Sxy150489  *
98479SChenlu.Chen@Sun.COM  * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
104919Sxy150489  *
114919Sxy150489  * The contents of this file are subject to the terms of Version
124919Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
134919Sxy150489  *
144919Sxy150489  * You should have received a copy of the License with this software.
154919Sxy150489  * You can obtain a copy of the License at
164919Sxy150489  *	http://www.opensolaris.org/os/licensing.
174919Sxy150489  * See the License for the specific language governing permissions
184919Sxy150489  * and limitations under the License.
194919Sxy150489  */
204919Sxy150489 
214919Sxy150489 /*
228479SChenlu.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*10805SChangqing.Li@Sun.COM  * Use is subject to license terms.
244919Sxy150489  */
254919Sxy150489 
264919Sxy150489 #include "e1000_osdep.h"
274919Sxy150489 #include "e1000_api.h"
284919Sxy150489 
294919Sxy150489 void
e1000_pci_set_mwi(struct e1000_hw * hw)304919Sxy150489 e1000_pci_set_mwi(struct e1000_hw *hw)
314919Sxy150489 {
324919Sxy150489 	uint16_t val = hw->bus.pci_cmd_word | CMD_MEM_WRT_INVALIDATE;
334919Sxy150489 
344919Sxy150489 	e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
354919Sxy150489 }
364919Sxy150489 
374919Sxy150489 void
e1000_pci_clear_mwi(struct e1000_hw * hw)384919Sxy150489 e1000_pci_clear_mwi(struct e1000_hw *hw)
394919Sxy150489 {
404919Sxy150489 	uint16_t val = hw->bus.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE;
414919Sxy150489 
424919Sxy150489 	e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
434919Sxy150489 }
444919Sxy150489 
454919Sxy150489 void
e1000_write_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)464919Sxy150489 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
474919Sxy150489 {
484919Sxy150489 	pci_config_put16(OS_DEP(hw)->cfg_handle, reg, *value);
494919Sxy150489 }
504919Sxy150489 
514919Sxy150489 void
e1000_read_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)524919Sxy150489 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
534919Sxy150489 {
544919Sxy150489 	*value =
554919Sxy150489 	    pci_config_get16(OS_DEP(hw)->cfg_handle, reg);
564919Sxy150489 }
574919Sxy150489 
584919Sxy150489 /*
594919Sxy150489  * phy_spd_state - set smart-power-down (SPD) state
604919Sxy150489  *
6110680SMin.Xu@Sun.COM  * This only acts on the silicon families that have the SPD feature.
624919Sxy150489  * For any others, return without doing anything.
634919Sxy150489  */
644919Sxy150489 void
phy_spd_state(struct e1000_hw * hw,boolean_t enable)654919Sxy150489 phy_spd_state(struct e1000_hw *hw, boolean_t enable)
664919Sxy150489 {
674919Sxy150489 	int32_t offset;		/* offset to register */
684919Sxy150489 	uint16_t spd_bit;	/* bit to be set */
694919Sxy150489 	uint16_t reg;		/* register contents */
704919Sxy150489 
714919Sxy150489 	switch (hw->mac.type) {
724919Sxy150489 	case e1000_82541:
734919Sxy150489 	case e1000_82547:
744919Sxy150489 	case e1000_82541_rev_2:
754919Sxy150489 	case e1000_82547_rev_2:
764919Sxy150489 		offset = IGP01E1000_GMII_FIFO;
774919Sxy150489 		spd_bit = IGP01E1000_GMII_SPD;
784919Sxy150489 		break;
794919Sxy150489 	case e1000_82571:
804919Sxy150489 	case e1000_82572:
8110680SMin.Xu@Sun.COM 	case e1000_82573:
8210680SMin.Xu@Sun.COM 	case e1000_82574:
8310680SMin.Xu@Sun.COM 	case e1000_82583:
844919Sxy150489 		offset = IGP02E1000_PHY_POWER_MGMT;
854919Sxy150489 		spd_bit = IGP02E1000_PM_SPD;
864919Sxy150489 		break;
874919Sxy150489 	default:
884919Sxy150489 		return;		/* no action */
894919Sxy150489 	}
904919Sxy150489 
917426SChenliang.Xu@Sun.COM 	(void) e1000_read_phy_reg(hw, offset, &reg);
924919Sxy150489 
934919Sxy150489 	if (enable)
944919Sxy150489 		reg |= spd_bit;		/* enable: set the spd bit */
954919Sxy150489 	else
964919Sxy150489 		reg &= ~spd_bit;	/* disable: clear the spd bit */
974919Sxy150489 
987426SChenliang.Xu@Sun.COM 	(void) e1000_write_phy_reg(hw, offset, reg);
994919Sxy150489 }
1004919Sxy150489 
1014919Sxy150489 /*
1024919Sxy150489  * The real intent of this routine is to return the value from pci-e
1034919Sxy150489  * config space at offset reg into the capability space.
1044919Sxy150489  * ICH devices are "PCI Express"-ish.  They have a configuration space,
1054919Sxy150489  * but do not contain PCI Express Capability registers, so this returns
1064919Sxy150489  * the equivalent of "not supported"
1074919Sxy150489  */
1084919Sxy150489 int32_t
e1000_read_pcie_cap_reg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)1094919Sxy150489 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
1104919Sxy150489 {
1114919Sxy150489 	*value = pci_config_get16(OS_DEP(hw)->cfg_handle,
1124919Sxy150489 	    PCI_EX_CONF_CAP + reg);
1134919Sxy150489 
1144919Sxy150489 	return (0);
1154919Sxy150489 }
1164919Sxy150489 
1174919Sxy150489 /*
11810680SMin.Xu@Sun.COM  * For some hardware types, access to NVM & PHY need to be serialized by mutex.
11910680SMin.Xu@Sun.COM  * The necessary mutexes will have been created by shared code.  Here we destroy
12010680SMin.Xu@Sun.COM  * that mutexes for just the hardware types that need it.
1214919Sxy150489  */
1224919Sxy150489 void
e1000_destroy_hw_mutex(struct e1000_hw * hw)12310680SMin.Xu@Sun.COM e1000_destroy_hw_mutex(struct e1000_hw *hw)
1244919Sxy150489 {
12510680SMin.Xu@Sun.COM 	struct e1000_dev_spec_ich8lan *dev_spec;
1264919Sxy150489 
12710680SMin.Xu@Sun.COM 	switch (hw->mac.type) {
12810680SMin.Xu@Sun.COM 	case e1000_ich8lan:
12910680SMin.Xu@Sun.COM 	case e1000_ich9lan:
13010680SMin.Xu@Sun.COM 	case e1000_ich10lan:
13110680SMin.Xu@Sun.COM 	case e1000_pchlan:
13210680SMin.Xu@Sun.COM 		dev_spec = &hw->dev_spec.ich8lan;
13310680SMin.Xu@Sun.COM 		E1000_MUTEX_DESTROY(&dev_spec->nvm_mutex);
13410680SMin.Xu@Sun.COM 		E1000_MUTEX_DESTROY(&dev_spec->swflag_mutex);
13510680SMin.Xu@Sun.COM 		break;
1364919Sxy150489 
13710680SMin.Xu@Sun.COM 	default:
13810680SMin.Xu@Sun.COM 		break;	/* no action */
13910680SMin.Xu@Sun.COM 	}
1404919Sxy150489 }
141