124f93aa0SRavi Pokala /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 324f93aa0SRavi Pokala * 424f93aa0SRavi Pokala * Authors: Joe Kloss; Ravi Pokala (rpokala@freebsd.org) 524f93aa0SRavi Pokala * 624f93aa0SRavi Pokala * Copyright (c) 2017-2018 Panasas 724f93aa0SRavi Pokala * 824f93aa0SRavi Pokala * Redistribution and use in source and binary forms, with or without 924f93aa0SRavi Pokala * modification, are permitted provided that the following conditions 1024f93aa0SRavi Pokala * are met: 1124f93aa0SRavi Pokala * 1. Redistributions of source code must retain the above copyright 1224f93aa0SRavi Pokala * notice, this list of conditions and the following disclaimer. 1324f93aa0SRavi Pokala * 2. Redistributions in binary form must reproduce the above copyright 1424f93aa0SRavi Pokala * notice, this list of conditions and the following disclaimer in the 1524f93aa0SRavi Pokala * documentation and/or other materials provided with the distribution. 1624f93aa0SRavi Pokala * 1724f93aa0SRavi Pokala * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1824f93aa0SRavi Pokala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1924f93aa0SRavi Pokala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2024f93aa0SRavi Pokala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2124f93aa0SRavi Pokala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2224f93aa0SRavi Pokala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2324f93aa0SRavi Pokala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2424f93aa0SRavi Pokala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2524f93aa0SRavi Pokala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2624f93aa0SRavi Pokala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2724f93aa0SRavi Pokala * SUCH DAMAGE. 2824f93aa0SRavi Pokala */ 2924f93aa0SRavi Pokala 3024f93aa0SRavi Pokala #ifndef _DEV__IMCSMB__IMCSMB_VAR_H_ 3124f93aa0SRavi Pokala #define _DEV__IMCSMB__IMCSMB_VAR_H_ 3224f93aa0SRavi Pokala 3324f93aa0SRavi Pokala #include <sys/param.h> 3424f93aa0SRavi Pokala #include <sys/systm.h> 3524f93aa0SRavi Pokala #include <sys/kernel.h> 3624f93aa0SRavi Pokala #include <sys/module.h> 3724f93aa0SRavi Pokala #include <sys/endian.h> 3824f93aa0SRavi Pokala #include <sys/errno.h> 3924f93aa0SRavi Pokala #include <sys/lock.h> 4024f93aa0SRavi Pokala #include <sys/mutex.h> 4124f93aa0SRavi Pokala #include <sys/syslog.h> 4224f93aa0SRavi Pokala #include <sys/bus.h> 4324f93aa0SRavi Pokala 4424f93aa0SRavi Pokala #include <machine/bus.h> 4524f93aa0SRavi Pokala #include <machine/atomic.h> 4624f93aa0SRavi Pokala 4724f93aa0SRavi Pokala #include <dev/pci/pcivar.h> 4824f93aa0SRavi Pokala #include <dev/pci/pcireg.h> 4924f93aa0SRavi Pokala 5024f93aa0SRavi Pokala #include <dev/smbus/smbconf.h> 5124f93aa0SRavi Pokala 5224f93aa0SRavi Pokala #include "smbus_if.h" 5324f93aa0SRavi Pokala 5424f93aa0SRavi Pokala /* A detailed description of this device is present in imcsmb_pci.c */ 5524f93aa0SRavi Pokala 5624f93aa0SRavi Pokala /** 5724f93aa0SRavi Pokala * The softc for a particular instance of the PCI device associated with a pair 5824f93aa0SRavi Pokala * of iMC-SMB controllers. 5924f93aa0SRavi Pokala * 6024f93aa0SRavi Pokala * Ordinarily, locking would be done with a mutex. However, we might have an 6124f93aa0SRavi Pokala * NVDIMM connected to this SMBus, and we might need to issue the SAVE command 6224f93aa0SRavi Pokala * to the NVDIMM from a panic context. Mutex operations are not allowed while 6324f93aa0SRavi Pokala * the scheduler is stopped, so just use a simple semaphore. 6424f93aa0SRavi Pokala * 6524f93aa0SRavi Pokala * If, as described in the manpage, additional steps are needed to stop/restart 6624f93aa0SRavi Pokala * firmware operations before/after using the controller, then additional fields 6724f93aa0SRavi Pokala * can be added to this softc. 6824f93aa0SRavi Pokala */ 6924f93aa0SRavi Pokala struct imcsmb_pci_softc { 7024f93aa0SRavi Pokala device_t dev; 7124f93aa0SRavi Pokala volatile int semaphore; 7224f93aa0SRavi Pokala }; 7324f93aa0SRavi Pokala 7424f93aa0SRavi Pokala void imcsmb_pci_release_bus(device_t dev); 7524f93aa0SRavi Pokala int imcsmb_pci_request_bus(device_t dev); 7624f93aa0SRavi Pokala 7724f93aa0SRavi Pokala /** 7824f93aa0SRavi Pokala * PCI config registers for each individual SMBus controller within the iMC. 7924f93aa0SRavi Pokala * Each iMC-SMB has a separate set of registers. There is an array of these 8024f93aa0SRavi Pokala * structures for the PCI device, and one of them is passed to driver for the 8124f93aa0SRavi Pokala * actual iMC-SMB as the IVAR. 8224f93aa0SRavi Pokala */ 8324f93aa0SRavi Pokala struct imcsmb_reg_set { 8424f93aa0SRavi Pokala uint16_t smb_stat; 8524f93aa0SRavi Pokala uint16_t smb_cmd; 8624f93aa0SRavi Pokala uint16_t smb_cntl; 8724f93aa0SRavi Pokala }; 8824f93aa0SRavi Pokala 8924f93aa0SRavi Pokala /** 9024f93aa0SRavi Pokala * The softc for the device associated with a particular iMC-SMB controller. 9124f93aa0SRavi Pokala * There are two such controllers for each of the PCI devices. The PCI driver 9224f93aa0SRavi Pokala * tells the iMC-SMB driver which set of registers to use via the IVAR. This 9324f93aa0SRavi Pokala * technique was suggested by John Baldwin (jhb@). 9424f93aa0SRavi Pokala */ 9524f93aa0SRavi Pokala struct imcsmb_softc { 9624f93aa0SRavi Pokala device_t dev; 9724f93aa0SRavi Pokala device_t imcsmb_pci; /* The SMBus controller's parent iMC */ 9824f93aa0SRavi Pokala device_t smbus; /* The child smbusX interface */ 9924f93aa0SRavi Pokala struct imcsmb_reg_set *regs; /* The registers this controller uses */ 10024f93aa0SRavi Pokala }; 10124f93aa0SRavi Pokala 10224f93aa0SRavi Pokala #endif /* _DEV__IMCSMB__IMCSMB_VAR_H_ */ 10324f93aa0SRavi Pokala 10424f93aa0SRavi Pokala /* vi: set ts=8 sw=4 sts=8 noet: */ 105