freebsd-skq/sys/dev/smartpqi/smartpqi_intr.c
sbruno 0804f0eef0 martpqi(4):
- Microsemi SCSI driver for PQI controllers.
- Found on newer model HP servers.
- Restrict to AMD64 only as per developer request.

The driver provides support for the new generation of PQI controllers
from Microsemi. This driver is the first SCSI driver to implement the PQI
queuing model and it will replace the aacraid driver for Adaptec Series 9
controllers.  HARDWARE Controllers supported by the driver include:

    HPE Gen10 Smart Array Controller Family
    OEM Controllers based on the Microsemi Chipset.

Submitted by:   deepak.ukey@microsemi.com
Relnotes:       yes
Sponsored by:   Microsemi
Differential Revision:   https://reviews.freebsd.org/D14514
> Description of fields to fill in above:                     76 columns --|
> PR:                       If and which Problem Report is related.
> Submitted by:             If someone else sent in the change.
> Reported by:              If someone else reported the issue.
> Reviewed by:              If someone else reviewed your modification.
> Approved by:              If you needed approval for this commit.
> Obtained from:            If the change is from a third party.
> MFC after:                N [day[s]|week[s]|month[s]].  Request a reminder email.
> MFH:                      Ports tree branch name.  Request approval for merge.
> Relnotes:                 Set to 'yes' for mention in release notes.
> Security:                 Vulnerability reference (one per line) or description.
> Sponsored by:             If the change was sponsored by an organization.
> Pull Request:             https://github.com/freebsd/freebsd/pull/### (*full* GitHub URL needed).
> Differential Revision:    https://reviews.freebsd.org/D### (*full* phabric URL needed).
> Empty fields above will be automatically removed.

M    share/man/man4/Makefile
AM   share/man/man4/smartpqi.4
M    sys/amd64/conf/GENERIC
M    sys/conf/NOTES
M    sys/conf/files.amd64
A    sys/dev/smartpqi
AM   sys/dev/smartpqi/smartpqi_cam.c
AM   sys/dev/smartpqi/smartpqi_cmd.c
AM   sys/dev/smartpqi/smartpqi_defines.h
AM   sys/dev/smartpqi/smartpqi_discovery.c
AM   sys/dev/smartpqi/smartpqi_event.c
AM   sys/dev/smartpqi/smartpqi_helper.c
AM   sys/dev/smartpqi/smartpqi_includes.h
AM   sys/dev/smartpqi/smartpqi_init.c
AM   sys/dev/smartpqi/smartpqi_intr.c
AM   sys/dev/smartpqi/smartpqi_ioctl.c
AM   sys/dev/smartpqi/smartpqi_ioctl.h
AM   sys/dev/smartpqi/smartpqi_main.c
AM   sys/dev/smartpqi/smartpqi_mem.c
AM   sys/dev/smartpqi/smartpqi_misc.c
AM   sys/dev/smartpqi/smartpqi_prototypes.h
AM   sys/dev/smartpqi/smartpqi_queue.c
AM   sys/dev/smartpqi/smartpqi_request.c
AM   sys/dev/smartpqi/smartpqi_response.c
AM   sys/dev/smartpqi/smartpqi_sis.c
AM   sys/dev/smartpqi/smartpqi_structures.h
AM   sys/dev/smartpqi/smartpqi_tag.c
M    sys/modules/Makefile
A    sys/modules/smartpqi
AM   sys/modules/smartpqi/Makefile
2018-04-26 16:59:06 +00:00

438 lines
11 KiB
C

/*-
* Copyright (c) 2018 Microsemi Corporation.
* 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.
*/
/* $FreeBSD$ */
#include "smartpqi_includes.h"
/*
* Function to get processor count
*/
int os_get_processor_config(pqisrc_softstate_t *softs)
{
DBG_FUNC("IN\n");
softs->num_cpus_online = mp_ncpus;
DBG_FUNC("OUT\n");
return PQI_STATUS_SUCCESS;
}
/*
* Function to get interrupt count and type supported
*/
int os_get_intr_config(pqisrc_softstate_t *softs)
{
device_t dev;
int msi_count = 0;
int error = 0;
int ret = PQI_STATUS_SUCCESS;
dev = softs->os_specific.pqi_dev;
DBG_FUNC("IN\n");
msi_count = pci_msix_count(dev);
if (msi_count > softs->num_cpus_online)
msi_count = softs->num_cpus_online;
if (msi_count > PQI_MAX_MSIX)
msi_count = PQI_MAX_MSIX;
if (msi_count == 0 || (error = pci_alloc_msix(dev, &msi_count)) != 0) {
device_printf(dev, "alloc msix failed - msi_count=%d, err=%d; "
"will try MSI\n", msi_count, error);
pci_release_msi(dev);
} else {
softs->intr_count = msi_count;
softs->intr_type = INTR_TYPE_MSIX;
softs->os_specific.msi_enabled = TRUE;
device_printf(dev, "using MSI-X interrupts (%d vectors)\n",
msi_count);
}
if (!softs->intr_type) {
msi_count = 1;
if ((error = pci_alloc_msi(dev, &msi_count)) != 0) {
device_printf(dev, "alloc msi failed - err=%d; "
"will use INTx\n", error);
pci_release_msi(dev);
} else {
softs->os_specific.msi_enabled = TRUE;
softs->intr_count = msi_count;
softs->intr_type = INTR_TYPE_MSI;
device_printf(dev, "using MSI interrupts\n");
}
}
if (!softs->intr_type) {
device_printf(dev, "using legacy interrupts\n");
softs->intr_type = INTR_TYPE_FIXED;
softs->intr_count = 1;
}
if(!softs->intr_type) {
DBG_FUNC("OUT failed\n");
ret = PQI_STATUS_FAILURE;
return ret;
}
DBG_FUNC("OUT\n");
return ret;
}
void os_eventtaskqueue_enqueue(pqisrc_softstate_t *sc)
{
taskqueue_enqueue(taskqueue_swi, &sc->os_specific.event_task);
}
void pqisrc_event_worker(void *arg1, int arg2)
{
pqisrc_ack_all_events(arg1);
}
/*
* ithread routine to handle uniprocessor systems
*/
static void shared_ithread_routine(void *arg)
{
pqi_intr_ctx_t *intr_ctx = (pqi_intr_ctx_t *)arg;
pqisrc_softstate_t *softs = device_get_softc(intr_ctx->pqi_dev);
int oq_id = intr_ctx->oq_id;
DBG_FUNC("IN\n");
pqisrc_process_response_queue(softs, oq_id);
pqisrc_process_event_intr_src(softs, oq_id - 1);
DBG_FUNC("OUT\n");
}
/*
* ithread routine to process non event response
*/
static void common_ithread_routine(void *arg)
{
pqi_intr_ctx_t *intr_ctx = (pqi_intr_ctx_t *)arg;
pqisrc_softstate_t *softs = device_get_softc(intr_ctx->pqi_dev);
int oq_id = intr_ctx->oq_id;
DBG_FUNC("IN\n");
pqisrc_process_response_queue(softs, oq_id);
DBG_FUNC("OUT\n");
}
static void event_ithread_routine(void *arg)
{
pqi_intr_ctx_t *intr_ctx = (pqi_intr_ctx_t *)arg;
pqisrc_softstate_t *softs = device_get_softc(intr_ctx->pqi_dev);
int oq_id = intr_ctx->oq_id;
DBG_FUNC("IN\n");
pqisrc_process_event_intr_src(softs, oq_id);
DBG_FUNC("OUT\n");
}
/*
* Registration of legacy interrupt in case MSI is unsupported
*/
int register_legacy_intr(pqisrc_softstate_t *softs)
{
int error = 0;
device_t dev;
DBG_FUNC("IN\n");
dev = softs->os_specific.pqi_dev;
softs->os_specific.pqi_irq_rid[0] = 0;
softs->os_specific.pqi_irq[0] = bus_alloc_resource_any(dev, \
SYS_RES_IRQ, &softs->os_specific.pqi_irq_rid[0],
RF_ACTIVE | RF_SHAREABLE);
if (NULL == softs->os_specific.pqi_irq[0]) {
DBG_ERR("Failed to allocate resource for interrupt\n");
return PQI_STATUS_FAILURE;
}
if ((softs->os_specific.msi_ctx = os_mem_alloc(softs,sizeof(pqi_intr_ctx_t))) == NULL) {
DBG_ERR("Failed to allocate memory for msi_ctx\n");
return PQI_STATUS_FAILURE;
}
softs->os_specific.msi_ctx[0].pqi_dev = dev;
softs->os_specific.msi_ctx[0].oq_id = 0;
error = bus_setup_intr(dev, softs->os_specific.pqi_irq[0],
INTR_TYPE_CAM | INTR_MPSAFE, \
NULL, shared_ithread_routine,
&softs->os_specific.msi_ctx[0],
&softs->os_specific.intrcookie[0]);
if (error) {
DBG_ERR("Failed to setup legacy interrupt err = %d\n", error);
return error;
}
softs->os_specific.intr_registered[0] = TRUE;
DBG_FUNC("OUT error = %d\n", error);
return error;
}
/*
* Registration of MSIx
*/
int register_msix_intr(pqisrc_softstate_t *softs)
{
int error = 0;
int i = 0;
device_t dev;
dev = softs->os_specific.pqi_dev;
int msix_count = softs->intr_count;
DBG_FUNC("IN\n");
softs->os_specific.msi_ctx = os_mem_alloc(softs, sizeof(pqi_intr_ctx_t) * msix_count);
/*Add shared handler */
if (softs->share_opq_and_eventq) {
softs->os_specific.pqi_irq_rid[i] = i+1;
softs->os_specific.pqi_irq[i] = bus_alloc_resource_any(dev, \
SYS_RES_IRQ,
&softs->os_specific.pqi_irq_rid[i],
RF_SHAREABLE | RF_ACTIVE);
if (NULL == softs->os_specific.pqi_irq[i]) {
DBG_ERR("Failed to allocate \
event interrupt resource\n");
return PQI_STATUS_FAILURE;
}
softs->os_specific.msi_ctx[i].pqi_dev = dev;
softs->os_specific.msi_ctx[i].oq_id = i;
error = bus_setup_intr(dev,softs->os_specific.pqi_irq[i],
INTR_TYPE_CAM | INTR_MPSAFE,\
NULL,
shared_ithread_routine,
&softs->os_specific.msi_ctx[i],
&softs->os_specific.intrcookie[i]);
if (error) {
DBG_ERR("Failed to setup interrupt for events r=%d\n",
error);
return error;
}
softs->os_specific.intr_registered[i] = TRUE;
}
else {
/* Add event handler */
softs->os_specific.pqi_irq_rid[i] = i+1;
softs->os_specific.pqi_irq[i] = bus_alloc_resource_any(dev, \
SYS_RES_IRQ,
&softs->os_specific.pqi_irq_rid[i],
RF_SHAREABLE | RF_ACTIVE);
if (NULL == softs->os_specific.pqi_irq[i]) {
DBG_ERR("ERR : Failed to allocate \
event interrupt resource\n");
return PQI_STATUS_FAILURE;
}
softs->os_specific.msi_ctx[i].pqi_dev = dev;
softs->os_specific.msi_ctx[i].oq_id = i;
error = bus_setup_intr(dev,softs->os_specific.pqi_irq[i],
INTR_TYPE_CAM | INTR_MPSAFE,\
NULL,
event_ithread_routine,
&softs->os_specific.msi_ctx[i],
&softs->os_specific.intrcookie[i]);
if (error) {
DBG_ERR("Failed to setup interrupt for events err=%d\n",
error);
return error;
}
softs->os_specific.intr_registered[i] = TRUE;
/* Add interrupt handlers*/
for (i = 1; i < msix_count; ++i) {
softs->os_specific.pqi_irq_rid[i] = i+1;
softs->os_specific.pqi_irq[i] = \
bus_alloc_resource_any(dev,
SYS_RES_IRQ,
&softs->os_specific.pqi_irq_rid[i],
RF_SHAREABLE | RF_ACTIVE);
if (NULL == softs->os_specific.pqi_irq[i]) {
DBG_ERR("Failed to allocate \
msi/x interrupt resource\n");
return PQI_STATUS_FAILURE;
}
softs->os_specific.msi_ctx[i].pqi_dev = dev;
softs->os_specific.msi_ctx[i].oq_id = i;
error = bus_setup_intr(dev,
softs->os_specific.pqi_irq[i],
INTR_TYPE_CAM | INTR_MPSAFE,\
NULL,
common_ithread_routine,
&softs->os_specific.msi_ctx[i],
&softs->os_specific.intrcookie[i]);
if (error) {
DBG_ERR("Failed to setup \
msi/x interrupt error = %d\n", error);
return error;
}
softs->os_specific.intr_registered[i] = TRUE;
}
}
DBG_FUNC("OUT error = %d\n", error);
return error;
}
/*
* Setup interrupt depending on the configuration
*/
int os_setup_intr(pqisrc_softstate_t *softs)
{
int error = 0;
DBG_FUNC("IN\n");
if (softs->intr_type == INTR_TYPE_FIXED) {
error = register_legacy_intr(softs);
}
else {
error = register_msix_intr(softs);
}
if (error) {
DBG_FUNC("OUT failed error = %d\n", error);
return error;
}
DBG_FUNC("OUT error = %d\n", error);
return error;
}
/*
* Deregistration of legacy interrupt
*/
void deregister_pqi_intx(pqisrc_softstate_t *softs)
{
device_t dev;
DBG_FUNC("IN\n");
dev = softs->os_specific.pqi_dev;
if (softs->os_specific.pqi_irq[0] != NULL) {
if (softs->os_specific.intr_registered[0]) {
bus_teardown_intr(dev, softs->os_specific.pqi_irq[0],
softs->os_specific.intrcookie[0]);
softs->os_specific.intr_registered[0] = FALSE;
}
bus_release_resource(dev, SYS_RES_IRQ,
softs->os_specific.pqi_irq_rid[0],
softs->os_specific.pqi_irq[0]);
softs->os_specific.pqi_irq[0] = NULL;
os_mem_free(softs, (char*)softs->os_specific.msi_ctx, sizeof(pqi_intr_ctx_t));
}
DBG_FUNC("OUT\n");
}
/*
* Deregistration of MSIx interrupt
*/
void deregister_pqi_msix(pqisrc_softstate_t *softs)
{
device_t dev;
dev = softs->os_specific.pqi_dev;
int msix_count = softs->intr_count;
int i = 0;
DBG_FUNC("IN\n");
os_mem_free(softs, (char*)softs->os_specific.msi_ctx, sizeof(pqi_intr_ctx_t) * msix_count);
softs->os_specific.msi_ctx = NULL;
for (; i < msix_count; ++i) {
if (softs->os_specific.pqi_irq[i] != NULL) {
if (softs->os_specific.intr_registered[i]) {
bus_teardown_intr(dev,
softs->os_specific.pqi_irq[i],
softs->os_specific.intrcookie[i]);
softs->os_specific.intr_registered[i] = FALSE;
}
bus_release_resource(dev, SYS_RES_IRQ,
softs->os_specific.pqi_irq_rid[i],
softs->os_specific.pqi_irq[i]);
softs->os_specific.pqi_irq[i] = NULL;
}
}
DBG_FUNC("OUT\n");
}
/*
* Function to destroy interrupts registered
*/
int os_destroy_intr(pqisrc_softstate_t *softs)
{
device_t dev;
dev = softs->os_specific.pqi_dev;
DBG_FUNC("IN\n");
if (softs->intr_type == INTR_TYPE_FIXED) {
deregister_pqi_intx(softs);
} else if (softs->intr_type == INTR_TYPE_MSIX) {
deregister_pqi_msix(softs);
}
if (softs->os_specific.msi_enabled) {
pci_release_msi(dev);
softs->os_specific.msi_enabled = FALSE;
}
DBG_FUNC("OUT\n");
return PQI_STATUS_SUCCESS;
}
/*
* Free interrupt related resources for the adapter
*/
void os_free_intr_config(pqisrc_softstate_t *softs)
{
device_t dev;
dev = softs->os_specific.pqi_dev;
DBG_FUNC("IN\n");
if (softs->os_specific.msi_enabled) {
pci_release_msi(dev);
softs->os_specific.msi_enabled = FALSE;
}
DBG_FUNC("OUT\n");
}