e1000_osdep.c revision 4914a7d0d1ee59f8cc21b19bfd7979cb65681eac
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley/*
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * This file is provided under a CDDLv1 license. When using or
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * redistributing this file, you may do so under this license.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * In redistributing this file this license must be included
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * and no other modification of this header file is permitted.
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley *
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * CDDL LICENSE SUMMARY
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * The contents of this file are subject to the terms of Version
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * 1.0 of the Common Development and Distribution License (the "License").
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * You should have received a copy of the License with this software.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * You can obtain a copy of the License at
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * http://www.opensolaris.org/os/licensing.
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * See the License for the specific language governing permissions
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * and limitations under the License.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley/*
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Use is subject to license terms of the CDDLv1.
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley */
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#pragma ident "%Z%%M% %I% %E% SMI"
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley#include "e1000_osdep.h"
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley#include "e1000_api.h"
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleys32
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrencee1000_alloc_zeroed_dev_spec_struct(struct e1000_hw *hw, u32 size)
802aa6f2b70cc0b4e69ef0a1dcab0a8d68a0fdeaDavid Lawrence{
454e318ef670fe9e426e17c6a8907b4a12d2d399David Lawrence hw->dev_spec = kmem_zalloc(size, KM_SLEEP);
364a82f7c25b62967678027043425201a5e5171aBob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley return (E1000_SUCCESS);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein}
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleyvoid
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleye1000_free_dev_spec_struct(struct e1000_hw *hw)
80a63e1574114b7e4e42d023f3a92cd9c7f252feMichael Graff{
80a63e1574114b7e4e42d023f3a92cd9c7f252feMichael Graff if (hw->dev_spec == NULL)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley return;
00c6365ade24779db7844792cea313e628012be4Bob Halley
00c6365ade24779db7844792cea313e628012be4Bob Halley kmem_free(hw->dev_spec, hw->dev_spec_size);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein hw->dev_spec = NULL;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley}
00c6365ade24779db7844792cea313e628012be4Bob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleyvoid
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrencee1000_pci_set_mwi(struct e1000_hw *hw)
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence{
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley uint16_t val = hw->bus.pci_cmd_word | CMD_MEM_WRT_INVALIDATE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
34b26adb24ea63e325e3e75437988264ba060117Andreas Gustafsson}
34b26adb24ea63e325e3e75437988264ba060117Andreas Gustafsson
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafssonvoid
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafssone1000_pci_clear_mwi(struct e1000_hw *hw)
34b26adb24ea63e325e3e75437988264ba060117Andreas Gustafsson{
34b26adb24ea63e325e3e75437988264ba060117Andreas Gustafsson uint16_t val = hw->bus.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE;
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein e1000_write_pci_cfg(hw, PCI_COMMAND_REGISTER, &val);
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley}
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
8dcce6f92254680aaa9b66afb927a30316b9e46eBob Halleyvoid
00c6365ade24779db7844792cea313e628012be4Bob Halleye1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
00c6365ade24779db7844792cea313e628012be4Bob Halley{
00c6365ade24779db7844792cea313e628012be4Bob Halley pci_config_put16(OS_DEP(hw)->cfg_handle, reg, *value);
00c6365ade24779db7844792cea313e628012be4Bob Halley}
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halleyvoid
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleye1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley{
a2a072eb23b0d0167bf573625ce41a65fe135afdBob Halley *value =
8dcce6f92254680aaa9b66afb927a30316b9e46eBob Halley pci_config_get16(OS_DEP(hw)->cfg_handle, reg);
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob Halley}
3740b569ae76295b941d57a724a43beb75b533baBob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley/*
3740b569ae76295b941d57a724a43beb75b533baBob Halley * phy_spd_state - set smart-power-down (SPD) state
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley *
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley * This only acts on the 82541/47 family and the 82571/72 family.
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley * For any others, return without doing anything.
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley */
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafssonvoid
298523461941e171ce97ea8b76892ac01bb7a49fBob Halleyphy_spd_state(struct e1000_hw *hw, boolean_t enable)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley{
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley int32_t offset; /* offset to register */
82ebb6cf503c3db679b93a7de11b736e5c5fabd1Bob Halley uint16_t spd_bit; /* bit to be set */
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley uint16_t reg; /* register contents */
00c6365ade24779db7844792cea313e628012be4Bob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley switch (hw->mac.type) {
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley case e1000_82541:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley case e1000_82547:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley case e1000_82541_rev_2:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley case e1000_82547_rev_2:
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley offset = IGP01E1000_GMII_FIFO;
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley spd_bit = IGP01E1000_GMII_SPD;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley break;
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley case e1000_82571:
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence case e1000_82572:
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley offset = IGP02E1000_PHY_POWER_MGMT;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley spd_bit = IGP02E1000_PM_SPD;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley break;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley default:
3740b569ae76295b941d57a724a43beb75b533baBob Halley return; /* no action */
3740b569ae76295b941d57a724a43beb75b533baBob Halley }
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley e1000_read_phy_reg(hw, offset, &reg);
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley if (enable)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley reg |= spd_bit; /* enable: set the spd bit */
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley else
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob Halley reg &= ~spd_bit; /* disable: clear the spd bit */
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley e1000_write_phy_reg(hw, offset, reg);
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson}
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley/*
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * The real intent of this routine is to return the value from pci-e
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * config space at offset reg into the capability space.
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley * ICH devices are "PCI Express"-ish. They have a configuration space,
3740b569ae76295b941d57a724a43beb75b533baBob Halley * but do not contain PCI Express Capability registers, so this returns
00c6365ade24779db7844792cea313e628012be4Bob Halley * the equivalent of "not supported"
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley */
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleyint32_t
298523461941e171ce97ea8b76892ac01bb7a49fBob Halleye1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley{
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley *value = pci_config_get16(OS_DEP(hw)->cfg_handle,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson PCI_EX_CONF_CAP + reg);
00c6365ade24779db7844792cea313e628012be4Bob Halley
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley return (0);
82ebb6cf503c3db679b93a7de11b736e5c5fabd1Bob Halley}
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence/*
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson * Enables PCI-Express master access.
82ebb6cf503c3db679b93a7de11b736e5c5fabd1Bob Halley *
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley * hw: Struct containing variables accessed by shared code
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley *
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley * returns: - none.
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley */
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleyvoid
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleye1000_enable_pciex_master(struct e1000_hw *hw)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley{
3740b569ae76295b941d57a724a43beb75b533baBob Halley uint32_t ctrl;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley if (hw->bus.type != e1000_bus_type_pci_express)
80a63e1574114b7e4e42d023f3a92cd9c7f252feMichael Graff return;
80a63e1574114b7e4e42d023f3a92cd9c7f252feMichael Graff
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson ctrl = E1000_READ_REG(hw, E1000_CTRL);
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley}
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley/*
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley * e1000g_get_driver_control - tell manageability firmware that the driver
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley * has control.
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson */
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafssonvoid
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halleye1000g_get_driver_control(struct e1000_hw *hw)
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley{
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley uint32_t ctrl_ext;
3740b569ae76295b941d57a724a43beb75b533baBob Halley uint32_t swsm;
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley /* tell manageability firmware the driver has taken over */
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley switch (hw->mac.type) {
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley case e1000_82573:
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson swsm = E1000_READ_REG(hw, E1000_SWSM);
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD);
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley break;
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson case e1000_82571:
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley case e1000_82572:
f47bb8d1f3a2e3edae11942d0d7e62e96caa5720Bob Halley case e1000_80003es2lan:
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley case e1000_ich8lan:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley case e1000_ich9lan:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley E1000_WRITE_REG(hw, E1000_CTRL_EXT,
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
7bae6a079bb304bf69ffb83a5ac4cfaec9967ffcBob Halley break;
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley default:
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley break;
298523461941e171ce97ea8b76892ac01bb7a49fBob Halley }
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson}
4c9406964425ecc33fac38bb093e236b43b449e6Andreas Gustafsson