19da57d7bSbt /*
29da57d7bSbt  * CDDL HEADER START
39da57d7bSbt  *
473cd555cSBin Tu - Sun Microsystems - Beijing China  * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
59da57d7bSbt  * The contents of this file are subject to the terms of the
69da57d7bSbt  * Common Development and Distribution License (the "License").
79da57d7bSbt  * You may not use this file except in compliance with the License.
89da57d7bSbt  *
99da57d7bSbt  * You can obtain a copy of the license at:
109da57d7bSbt  *      http://www.opensolaris.org/os/licensing.
119da57d7bSbt  * See the License for the specific language governing permissions
129da57d7bSbt  * and limitations under the License.
139da57d7bSbt  *
149da57d7bSbt  * When using or redistributing this file, you may do so under the
159da57d7bSbt  * License only. No other modification of this header is permitted.
169da57d7bSbt  *
179da57d7bSbt  * If applicable, add the following below this CDDL HEADER, with the
189da57d7bSbt  * fields enclosed by brackets "[]" replaced with your own identifying
199da57d7bSbt  * information: Portions Copyright [yyyy] [name of copyright owner]
209da57d7bSbt  *
219da57d7bSbt  * CDDL HEADER END
229da57d7bSbt  */
239da57d7bSbt 
249da57d7bSbt /*
2573cd555cSBin Tu - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2673cd555cSBin Tu - Sun Microsystems - Beijing China  * Use is subject to license terms.
27*74b989c3SRobert Mustacchi  * Copyright (c) 2017, Joyent, Inc.
289da57d7bSbt  */
299da57d7bSbt 
30*74b989c3SRobert Mustacchi #include "ixgbe_sw.h"
319da57d7bSbt 
329da57d7bSbt uint16_t
ixgbe_read_pci_cfg(struct ixgbe_hw * hw,uint32_t reg)339da57d7bSbt ixgbe_read_pci_cfg(struct ixgbe_hw *hw, uint32_t reg)
349da57d7bSbt {
359da57d7bSbt 	return (pci_config_get16(OS_DEP(hw)->cfg_handle, reg));
369da57d7bSbt }
3773cd555cSBin Tu - Sun Microsystems - Beijing China 
3873cd555cSBin Tu - Sun Microsystems - Beijing China void
ixgbe_write_pci_cfg(struct ixgbe_hw * hw,uint32_t reg,uint32_t val)3973cd555cSBin Tu - Sun Microsystems - Beijing China ixgbe_write_pci_cfg(struct ixgbe_hw *hw, uint32_t reg, uint32_t val)
4073cd555cSBin Tu - Sun Microsystems - Beijing China {
4173cd555cSBin Tu - Sun Microsystems - Beijing China 	pci_config_put16(OS_DEP(hw)->cfg_handle, reg, val);
4273cd555cSBin Tu - Sun Microsystems - Beijing China }
43*74b989c3SRobert Mustacchi 
44*74b989c3SRobert Mustacchi /*
45*74b989c3SRobert Mustacchi  * This is our last line of defense against a hardware device that has decided
46*74b989c3SRobert Mustacchi  * to somehow disappear without our knowledge of it. To try and deal with this,
47*74b989c3SRobert Mustacchi  * we'll read the status register and see if it returns all 1s, indicating an
48*74b989c3SRobert Mustacchi  * invalid read. Note the status register is defined to have bits in all current
49*74b989c3SRobert Mustacchi  * revisions that are hardwired to zero.
50*74b989c3SRobert Mustacchi  */
51*74b989c3SRobert Mustacchi boolean_t
ixgbe_removed(struct ixgbe_hw * hw)52*74b989c3SRobert Mustacchi ixgbe_removed(struct ixgbe_hw *hw)
53*74b989c3SRobert Mustacchi {
54*74b989c3SRobert Mustacchi 	uint32_t val;
55*74b989c3SRobert Mustacchi 
56*74b989c3SRobert Mustacchi 	val = IXGBE_READ_REG(hw, IXGBE_STATUS);
57*74b989c3SRobert Mustacchi 	if (val == PCI_EINVAL32) {
58*74b989c3SRobert Mustacchi 		ixgbe_t *ixgbe = OS_DEP(hw)->ixgbe;
59*74b989c3SRobert Mustacchi 
60*74b989c3SRobert Mustacchi 		ixgbe_error(ixgbe, "failed to read status register: device "
61*74b989c3SRobert Mustacchi 		    "may be gone");
62*74b989c3SRobert Mustacchi 		if (ixgbe->ixgbe_ks != NULL) {
63*74b989c3SRobert Mustacchi 			ixgbe_stat_t *s = ixgbe->ixgbe_ks->ks_data;
64*74b989c3SRobert Mustacchi 			s->dev_gone.value.ui64++;
65*74b989c3SRobert Mustacchi 		}
66*74b989c3SRobert Mustacchi 		return (B_TRUE);
67*74b989c3SRobert Mustacchi 	}
68*74b989c3SRobert Mustacchi 	return (B_FALSE);
69*74b989c3SRobert Mustacchi }
70