2010-09-10 15:03:56 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2010-09-10 15:03:56 +00:00
|
|
|
* Copyright (c) 2009 Yahoo! Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2015-02-24 22:07:42 +00:00
|
|
|
/* PCI/PCI-X/PCIe bus interface for the Avago Tech (LSI) MPT2 controllers */
|
2010-09-10 15:03:56 +00:00
|
|
|
|
2012-01-26 18:17:21 +00:00
|
|
|
/* TODO Move headers to mpsvar */
|
2010-09-10 15:03:56 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/sysctl.h>
|
Add Serial Management Protocol (SMP) passthrough support to CAM.
This includes support in the kernel, camcontrol(8), libcam and the mps(4)
driver for SMP passthrough.
The CAM SCSI probe code has been modified to fetch Inquiry VPD page 0x00
to determine supported pages, and will now fetch page 0x83 in addition to
page 0x80 if supported.
Add two new CAM CCBs, XPT_SMP_IO, and XPT_GDEV_ADVINFO. The SMP CCB is
intended for SMP requests and responses. The ADVINFO is currently used to
fetch cached VPD page 0x83 data from the transport layer, but is intended
to be extensible to fetch other types of device-specific data.
SMP-only devices are not currently represented in the CAM topology, and so
the current semantics are that the SIM will route SMP CCBs to either the
addressed device, if it contains an SMP target, or its parent, if it
contains an SMP target. (This is noted in cam_ccb.h, since it will change
later once we have the ability to have SMP-only devices in CAM's topology.)
smp_all.c,
smp_all.h: New helper routines for SMP. This includes
SMP request building routines, response parsing
routines, error decoding routines, and structure
definitions for a number of SMP commands.
libcam/Makefile: Add smp_all.c to libcam, so that SMP functionality
is available to userland applications.
camcontrol.8,
camcontrol.c: Add smp passthrough support to camcontrol. Several
new subcommands are now available:
'smpcmd' functions much like 'cmd', except that it
allows the user to send generic SMP commands.
'smprg' sends the SMP report general command, and
displays the decoded output. It will automatically
fetch extended output if it is available.
'smppc' sends the SMP phy control command, with any
number of potential options. Among other things,
this allows the user to reset a phy on a SAS
expander, or disable a phy on an expander.
'smpmaninfo' sends the SMP report manufacturer
information and displays the decoded output.
'smpphylist' displays a list of phys on an
expander, and the CAM devices attached to those
phys, if any.
cam.h,
cam.c: Add a status value for SMP errors
(CAM_SMP_STATUS_ERROR).
Add a missing description for CAM_SCSI_IT_NEXUS_LOST.
Add support for SMP commands to cam_error_string().
cam_ccb.h: Rename the CAM_DIR_RESV flag to CAM_DIR_BOTH. SMP
commands are by nature bi-directional, and we may
need to support bi-directional SCSI commands later.
Add the XPT_SMP_IO CCB. Since SMP commands are
bi-directional, there are pointers for both the
request and response.
Add a fill routine for SMP CCBs.
Add the XPT_GDEV_ADVINFO CCB. This is currently
used to fetch cached page 0x83 data from the
transport later, but is extensible to fetch many
other types of data.
cam_periph.c: Add support in cam_periph_mapmem() for XPT_SMP_IO
and XPT_GDEV_ADVINFO CCBs.
cam_xpt.c: Add support for executing XPT_SMP_IO CCBs.
cam_xpt_internal.h: Add fields for VPD pages 0x00 and 0x83 in struct
cam_ed.
scsi_all.c: Add scsi_get_sas_addr(), a function that parses
VPD page 0x83 data and pulls out a SAS address.
scsi_all.h: Add VPD page 0x00 and 0x83 structures, and a
prototype for scsi_get_sas_addr().
scsi_pass.c: Add support for mapping buffers in XPT_SMP_IO and
XPT_GDEV_ADVINFO CCBs.
scsi_xpt.c: In the SCSI probe code, first ask the device for
VPD page 0x00. If any VPD pages are supported,
that page is required to be implemented. Based on
the response, we may probe for the serial number
(page 0x80) or device id (page 0x83).
Add support for the XPT_GDEV_ADVINFO CCB.
sys/conf/files: Add smp_all.c.
mps.c: Add support for passing in a uio in mps_map_command(),
so we can map a S/G list at once.
Add support for SMP passthrough commands in
mps_data_cb(). SMP is a special case, because the
first buffer in the S/G list is outbound and the
second buffer is inbound.
Add support for warning the user if the busdma code
comes back with more buffers than will work for the
command. This will, for example, help the user
determine why an SMP command failed if busdma comes
back with three buffers.
mps_pci.c: Add sys/uio.h.
mps_sas.c: Add the SAS address and the parent handle to the
list of fields we pull from device page 0 and cache
in struct mpssas_target. These are needed for SMP
passthrough.
Add support for the XPT_SMP_IO CCB. For now, this
CCB is routed to the addressed device if it supports
SMP, or to its parent if it does not and the parent
does. This is necessary because CAM does not
currently support SMP-only nodes in the topology.
Make SMP passthrough support conditional on
__FreeBSD_version >= 900026. This will make it
easier to MFC this change to the driver without
MFCing the CAM changes as well.
mps_user.c: Un-staticize mpi_init_sge() so we can use it for
the SMP passthrough code.
mpsvar.h: Add a uio and iovecs into struct mps_command for
SMP passthrough commands.
Add a cm_max_segs field to struct mps_command so
that we can warn the user if busdma comes back with
too many segments.
Clear the cm_reply when a command gets freed. If
it is not cleared, reply frames will eventually get
freed into the pool multiple times and corrupt the
pool. (This fix is from scottl.)
Add a prototype for mpi_init_sge().
sys/param.h: Bump __FreeBSD_version to 900026 for the for the
inclusion of the XPT_GDEV_ADVINFO and XPT_SMP_IO
CAM CCBs.
2010-11-30 22:39:46 +00:00
|
|
|
#include <sys/uio.h>
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2012-01-26 18:17:21 +00:00
|
|
|
#include <dev/pci/pci_private.h>
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
#include <dev/mps/mpi/mpi2_type.h>
|
|
|
|
#include <dev/mps/mpi/mpi2.h>
|
|
|
|
#include <dev/mps/mpi/mpi2_ioc.h>
|
|
|
|
#include <dev/mps/mpi/mpi2_cnfg.h>
|
2012-01-26 18:17:21 +00:00
|
|
|
#include <dev/mps/mpi/mpi2_tool.h>
|
2010-09-10 15:03:56 +00:00
|
|
|
|
2012-01-26 18:17:21 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <dev/mps/mps_ioctl.h>
|
2010-09-10 15:03:56 +00:00
|
|
|
#include <dev/mps/mpsvar.h>
|
|
|
|
|
|
|
|
static int mps_pci_probe(device_t);
|
|
|
|
static int mps_pci_attach(device_t);
|
|
|
|
static int mps_pci_detach(device_t);
|
|
|
|
static int mps_pci_suspend(device_t);
|
|
|
|
static int mps_pci_resume(device_t);
|
|
|
|
static void mps_pci_free(struct mps_softc *);
|
|
|
|
static int mps_alloc_msix(struct mps_softc *sc, int msgs);
|
|
|
|
static int mps_alloc_msi(struct mps_softc *sc, int msgs);
|
2017-07-30 06:53:58 +00:00
|
|
|
static int mps_pci_alloc_interrupts(struct mps_softc *sc);
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
static device_method_t mps_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, mps_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, mps_pci_attach),
|
|
|
|
DEVMETHOD(device_detach, mps_pci_detach),
|
|
|
|
DEVMETHOD(device_suspend, mps_pci_suspend),
|
|
|
|
DEVMETHOD(device_resume, mps_pci_resume),
|
2011-11-22 21:28:20 +00:00
|
|
|
|
|
|
|
DEVMETHOD_END
|
2010-09-10 15:03:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t mps_pci_driver = {
|
|
|
|
"mps",
|
|
|
|
mps_methods,
|
|
|
|
sizeof(struct mps_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mps_ident {
|
|
|
|
uint16_t vendor;
|
|
|
|
uint16_t device;
|
|
|
|
uint16_t subvendor;
|
|
|
|
uint16_t subdevice;
|
|
|
|
u_int flags;
|
|
|
|
const char *desc;
|
|
|
|
} mps_identifiers[] = {
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2004" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2008" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" },
|
2012-01-26 18:17:21 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" },
|
2012-01-26 18:17:21 +00:00
|
|
|
// Add Customer specific vender/subdevice id before generic
|
|
|
|
// (0xffff) vender/subdevice id.
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
|
|
|
|
0x8086, 0x3516, 0, "Intel(R) Integrated RAID Module RMS25JB080" },
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
|
|
|
|
0x8086, 0x3517, 0, "Intel(R) Integrated RAID Module RMS25JB040" },
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
|
|
|
|
0x8086, 0x3518, 0, "Intel(R) Integrated RAID Module RMS25KB080" },
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
|
|
|
|
0x8086, 0x3519, 0, "Intel(R) Integrated RAID Module RMS25KB040" },
|
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" },
|
2012-01-26 18:17:21 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" },
|
2012-01-26 18:17:21 +00:00
|
|
|
{ MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
|
2015-02-24 22:07:42 +00:00
|
|
|
0xffff, 0xffff, 0, "Avago Technologies (LSI) SSS6200" },
|
2010-09-10 15:03:56 +00:00
|
|
|
{ 0, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
Add PNP info to PCI attachments of cbb, cxgb, ida, iwn, ixl, ixlv,
mfi, mps, mpr, mvs, my, oce, pcn, ral, rl. This only labels existing
pci device tables, and has no probe / attach code changes.
Reviewed by: imp, chuck
Submitted by: Lakhan Shiva Kamireddy <lakhanshiva@gmail.com>
Sponsored by: Google, Inc. (GSoC 2018)
Approved by: re (glen)
2018-09-26 17:12:30 +00:00
|
|
|
static devclass_t mps_devclass;
|
|
|
|
DRIVER_MODULE(mps, pci, mps_pci_driver, mps_devclass, 0, 0);
|
2020-01-19 22:52:36 +00:00
|
|
|
MODULE_DEPEND(mps, cam, 1, 1, 1);
|
Add PNP info to PCI attachments of cbb, cxgb, ida, iwn, ixl, ixlv,
mfi, mps, mpr, mvs, my, oce, pcn, ral, rl. This only labels existing
pci device tables, and has no probe / attach code changes.
Reviewed by: imp, chuck
Submitted by: Lakhan Shiva Kamireddy <lakhanshiva@gmail.com>
Sponsored by: Google, Inc. (GSoC 2018)
Approved by: re (glen)
2018-09-26 17:12:30 +00:00
|
|
|
MODULE_PNP_INFO("U16:vendor;U16:device;U16:subvendor;U16:subdevice", pci, mps,
|
|
|
|
mps_identifiers, nitems(mps_identifiers) - 1);
|
2010-09-10 15:03:56 +00:00
|
|
|
static struct mps_ident *
|
|
|
|
mps_find_ident(device_t dev)
|
|
|
|
{
|
|
|
|
struct mps_ident *m;
|
|
|
|
|
|
|
|
for (m = mps_identifiers; m->vendor != 0; m++) {
|
|
|
|
if (m->vendor != pci_get_vendor(dev))
|
|
|
|
continue;
|
|
|
|
if (m->device != pci_get_device(dev))
|
|
|
|
continue;
|
|
|
|
if ((m->subvendor != 0xffff) &&
|
|
|
|
(m->subvendor != pci_get_subvendor(dev)))
|
|
|
|
continue;
|
|
|
|
if ((m->subdevice != 0xffff) &&
|
|
|
|
(m->subdevice != pci_get_subdevice(dev)))
|
|
|
|
continue;
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_pci_probe(device_t dev)
|
|
|
|
{
|
|
|
|
struct mps_ident *id;
|
|
|
|
|
|
|
|
if ((id = mps_find_ident(dev)) != NULL) {
|
|
|
|
device_set_desc(dev, id->desc);
|
2012-02-11 00:28:30 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2010-09-10 15:03:56 +00:00
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_pci_attach(device_t dev)
|
|
|
|
{
|
2020-09-14 05:58:12 +00:00
|
|
|
bus_dma_template_t t;
|
2010-09-10 15:03:56 +00:00
|
|
|
struct mps_softc *sc;
|
|
|
|
struct mps_ident *m;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
bzero(sc, sizeof(*sc));
|
|
|
|
sc->mps_dev = dev;
|
|
|
|
m = mps_find_ident(dev);
|
|
|
|
sc->mps_flags = m->flags;
|
|
|
|
|
2017-07-30 06:53:58 +00:00
|
|
|
mps_get_tunables(sc);
|
|
|
|
|
2010-09-10 15:03:56 +00:00
|
|
|
/* Twiddle basic PCI config bits for a sanity check */
|
2013-08-12 23:30:01 +00:00
|
|
|
pci_enable_busmaster(dev);
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
/* Allocate the System Interface Register Set */
|
|
|
|
sc->mps_regs_rid = PCIR_BAR(1);
|
|
|
|
if ((sc->mps_regs_resource = bus_alloc_resource_any(dev,
|
|
|
|
SYS_RES_MEMORY, &sc->mps_regs_rid, RF_ACTIVE)) == NULL) {
|
2013-07-19 00:12:41 +00:00
|
|
|
mps_printf(sc, "Cannot allocate PCI registers\n");
|
2010-09-10 15:03:56 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
sc->mps_btag = rman_get_bustag(sc->mps_regs_resource);
|
|
|
|
sc->mps_bhandle = rman_get_bushandle(sc->mps_regs_resource);
|
|
|
|
|
|
|
|
/* Allocate the parent DMA tag */
|
2020-09-11 22:27:35 +00:00
|
|
|
bus_dma_template_init(&t, bus_get_dma_tag(dev));
|
|
|
|
if (bus_dma_template_tag(&t, &sc->mps_parent_dmat)) {
|
2013-07-19 00:12:41 +00:00
|
|
|
mps_printf(sc, "Cannot allocate parent DMA tag\n");
|
2010-09-10 15:03:56 +00:00
|
|
|
mps_pci_free(sc);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2017-07-30 06:53:58 +00:00
|
|
|
if (((error = mps_pci_alloc_interrupts(sc)) != 0) ||
|
|
|
|
((error = mps_attach(sc)) != 0))
|
2010-09-10 15:03:56 +00:00
|
|
|
mps_pci_free(sc);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2017-07-30 06:53:58 +00:00
|
|
|
/*
|
|
|
|
* Allocate, but don't assign interrupts early. Doing it before requesting
|
|
|
|
* the IOCFacts message informs the firmware that we want to do MSI-X
|
|
|
|
* multiqueue. We might not use all of the available messages, but there's
|
|
|
|
* no reason to re-alloc if we don't.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mps_pci_alloc_interrupts(struct mps_softc *sc)
|
2010-09-10 15:03:56 +00:00
|
|
|
{
|
|
|
|
device_t dev;
|
2017-07-30 06:53:58 +00:00
|
|
|
int error, msgs;
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
dev = sc->mps_dev;
|
2017-07-30 06:53:58 +00:00
|
|
|
error = 0;
|
2017-07-31 16:55:56 +00:00
|
|
|
msgs = 0;
|
2017-07-30 06:53:58 +00:00
|
|
|
|
2017-09-11 01:51:27 +00:00
|
|
|
if (sc->disable_msix == 0) {
|
|
|
|
msgs = pci_msix_count(dev);
|
|
|
|
mps_dprint(sc, MPS_INIT, "Counted %d MSI-X messages\n", msgs);
|
|
|
|
msgs = min(msgs, sc->max_msix);
|
|
|
|
msgs = min(msgs, MPS_MSIX_MAX);
|
|
|
|
msgs = min(msgs, 1); /* XXX */
|
|
|
|
if (msgs != 0) {
|
2017-09-15 20:58:52 +00:00
|
|
|
mps_dprint(sc, MPS_INIT, "Attempting to allocate %d "
|
|
|
|
"MSI-X messages\n", msgs);
|
2017-09-11 01:51:27 +00:00
|
|
|
error = mps_alloc_msix(sc, msgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (((error != 0) || (msgs == 0)) && (sc->disable_msi == 0)) {
|
|
|
|
msgs = pci_msi_count(dev);
|
|
|
|
mps_dprint(sc, MPS_INIT, "Counted %d MSI messages\n", msgs);
|
|
|
|
msgs = min(msgs, MPS_MSI_MAX);
|
|
|
|
if (msgs != 0) {
|
2017-09-15 20:58:52 +00:00
|
|
|
mps_dprint(sc, MPS_INIT, "Attempting to allocate %d "
|
|
|
|
"MSI messages\n", MPS_MSI_MAX);
|
2017-09-11 01:51:27 +00:00
|
|
|
error = mps_alloc_msi(sc, MPS_MSI_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((error != 0) || (msgs == 0)) {
|
2017-09-08 20:20:35 +00:00
|
|
|
/*
|
|
|
|
* If neither MSI or MSI-X are avaiable, assume legacy INTx.
|
|
|
|
* This also implies that there will be only 1 queue.
|
|
|
|
*/
|
2017-09-11 01:51:27 +00:00
|
|
|
mps_dprint(sc, MPS_INIT, "Falling back to legacy INTx\n");
|
2017-09-08 20:20:35 +00:00
|
|
|
sc->mps_flags |= MPS_FLAGS_INTX;
|
|
|
|
msgs = 1;
|
2017-09-11 01:51:27 +00:00
|
|
|
} else
|
2017-09-08 20:20:35 +00:00
|
|
|
sc->mps_flags |= MPS_FLAGS_MSI;
|
2017-07-30 06:53:58 +00:00
|
|
|
|
|
|
|
sc->msi_msgs = msgs;
|
2017-09-08 20:20:35 +00:00
|
|
|
mps_dprint(sc, MPS_INIT, "Allocated %d interrupts\n", msgs);
|
|
|
|
|
2017-07-30 06:53:58 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mps_pci_setup_interrupts(struct mps_softc *sc)
|
|
|
|
{
|
|
|
|
device_t dev;
|
2017-09-09 18:03:40 +00:00
|
|
|
struct mps_queue *q;
|
2017-09-08 20:20:35 +00:00
|
|
|
void *ihandler;
|
|
|
|
int i, error, rid, initial_rid;
|
2017-07-30 06:53:58 +00:00
|
|
|
|
|
|
|
dev = sc->mps_dev;
|
|
|
|
error = ENXIO;
|
2010-09-10 15:03:56 +00:00
|
|
|
|
2017-09-08 20:20:35 +00:00
|
|
|
if (sc->mps_flags & MPS_FLAGS_INTX) {
|
|
|
|
initial_rid = 0;
|
|
|
|
ihandler = mps_intr;
|
|
|
|
} else if (sc->mps_flags & MPS_FLAGS_MSI) {
|
|
|
|
initial_rid = 1;
|
|
|
|
ihandler = mps_intr_msi;
|
2010-09-10 15:03:56 +00:00
|
|
|
} else {
|
2017-09-08 20:20:35 +00:00
|
|
|
mps_dprint(sc, MPS_ERROR|MPS_INIT,
|
|
|
|
"Unable to set up interrupts\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sc->msi_msgs; i++) {
|
2017-09-09 18:03:40 +00:00
|
|
|
q = &sc->queues[i];
|
2017-09-08 20:20:35 +00:00
|
|
|
rid = i + initial_rid;
|
2017-09-09 18:03:40 +00:00
|
|
|
q->irq_rid = rid;
|
|
|
|
q->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
|
|
|
|
&q->irq_rid, RF_ACTIVE);
|
|
|
|
if (q->irq == NULL) {
|
2017-09-08 20:20:35 +00:00
|
|
|
mps_dprint(sc, MPS_ERROR|MPS_INIT,
|
2017-09-11 01:51:27 +00:00
|
|
|
"Cannot allocate interrupt RID %d\n", rid);
|
|
|
|
sc->msi_msgs = i;
|
2017-09-08 20:20:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-09 18:03:40 +00:00
|
|
|
error = bus_setup_intr(dev, q->irq,
|
2017-09-08 20:20:35 +00:00
|
|
|
INTR_TYPE_BIO | INTR_MPSAFE, NULL, ihandler,
|
2017-09-09 18:03:40 +00:00
|
|
|
sc, &q->intrhand);
|
2017-09-08 20:20:35 +00:00
|
|
|
if (error) {
|
|
|
|
mps_dprint(sc, MPS_ERROR|MPS_INIT,
|
|
|
|
"Cannot setup interrupt RID %d\n", rid);
|
2017-09-11 01:51:27 +00:00
|
|
|
sc->msi_msgs = i;
|
2017-09-08 20:20:35 +00:00
|
|
|
break;
|
2010-09-10 15:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:20:35 +00:00
|
|
|
mps_dprint(sc, MPS_INIT, "Set up %d interrupts\n", sc->msi_msgs);
|
|
|
|
|
2010-09-10 15:03:56 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_pci_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct mps_softc *sc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
if ((error = mps_free(sc)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
mps_pci_free(sc);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-09-09 18:03:40 +00:00
|
|
|
void
|
|
|
|
mps_pci_free_interrupts(struct mps_softc *sc)
|
2010-09-10 15:03:56 +00:00
|
|
|
{
|
2017-09-09 18:03:40 +00:00
|
|
|
struct mps_queue *q;
|
2010-09-10 15:03:56 +00:00
|
|
|
int i;
|
|
|
|
|
2017-09-09 18:03:40 +00:00
|
|
|
if (sc->queues == NULL)
|
|
|
|
return;
|
2010-09-10 15:03:56 +00:00
|
|
|
|
2017-09-08 20:20:35 +00:00
|
|
|
for (i = 0; i < sc->msi_msgs; i++) {
|
2017-09-09 18:03:40 +00:00
|
|
|
q = &sc->queues[i];
|
|
|
|
if (q->irq != NULL) {
|
|
|
|
bus_teardown_intr(sc->mps_dev, q->irq,
|
|
|
|
q->intrhand);
|
2017-09-08 20:20:35 +00:00
|
|
|
bus_release_resource(sc->mps_dev, SYS_RES_IRQ,
|
2017-09-09 18:03:40 +00:00
|
|
|
q->irq_rid, q->irq);
|
2010-09-10 15:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-09 18:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mps_pci_free(struct mps_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sc->mps_parent_dmat != NULL) {
|
|
|
|
bus_dma_tag_destroy(sc->mps_parent_dmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
mps_pci_free_interrupts(sc);
|
2010-09-10 15:03:56 +00:00
|
|
|
|
2017-09-08 20:20:35 +00:00
|
|
|
if (sc->mps_flags & MPS_FLAGS_MSI)
|
|
|
|
pci_release_msi(sc->mps_dev);
|
2010-09-10 15:03:56 +00:00
|
|
|
|
|
|
|
if (sc->mps_regs_resource != NULL) {
|
|
|
|
bus_release_resource(sc->mps_dev, SYS_RES_MEMORY,
|
|
|
|
sc->mps_regs_rid, sc->mps_regs_resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_pci_suspend(device_t dev)
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_pci_resume(device_t dev)
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_alloc_msix(struct mps_softc *sc, int msgs)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = pci_alloc_msix(sc->mps_dev, &msgs);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mps_alloc_msi(struct mps_softc *sc, int msgs)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = pci_alloc_msi(sc->mps_dev, &msgs);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2012-01-26 18:17:21 +00:00
|
|
|
int
|
|
|
|
mps_pci_restore(struct mps_softc *sc)
|
|
|
|
{
|
|
|
|
struct pci_devinfo *dinfo;
|
|
|
|
|
|
|
|
mps_dprint(sc, MPS_TRACE, "%s\n", __func__);
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(sc->mps_dev);
|
|
|
|
if (dinfo == NULL) {
|
|
|
|
mps_dprint(sc, MPS_FAULT, "%s: NULL dinfo\n", __func__);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_cfg_restore(sc->mps_dev, dinfo);
|
|
|
|
return (0);
|
|
|
|
}
|