/*
* mr_sas.c: source for mr_sas driver
*
* Solaris MegaRAID device driver for SAS2.0 controllers
* Copyright (c) 2008-2012, LSI Logic Corporation.
* All rights reserved.
*
* Version:
* Author:
* Swaminathan K S
* Arun Chandrashekhar
* Manju R
* Rasheed
* Shakeel Bukhari
*
* 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
*
* 3. Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*/
/*
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
* Copyright 2015 Citrus IT Limited. All rights reserved.
* Copyright 2015 Garrett D'Amore <garrett@damore.org>
*/
#include <sys/byteorder.h>
#include "mr_sas.h"
/*
* FMA header files
*/
/* Macros to help Skinny and stock 2108/MFI live together. */
WR_IB_HIGH_QPORT(0, (instance)); \
} else { \
}
/*
* Local static data
*/
/* Default Timeout value to issue online controller reset */
/* Simulate consecutive firmware fault */
static volatile int debug_fw_faults_after_ocr_g = 0;
#ifdef OCRDEBUG
/* Simulate three consecutive timeout for an IO */
static volatile int debug_consecutive_timeout_after_ocr_g = 0;
#endif
/* Local static prototypes. */
#ifdef __sparc
#else
static int mrsas_quiesce(dev_info_t *);
#endif
scsi_hba_tran_t *, struct scsi_device *);
int (*)(), caddr_t);
static int mrsas_tran_start(struct scsi_address *,
register struct scsi_pkt *);
static int mrsas_tran_reset(struct scsi_address *, int);
static int mrsas_tran_getcap(struct scsi_address *, char *, int);
static int mrsas_tran_setcap(struct scsi_address *, char *, int, int);
static void mrsas_tran_destroy_pkt(struct scsi_address *,
struct scsi_pkt *);
static uint_t mrsas_softintr();
static void free_space_for_mfi(struct mrsas_instance *);
static int issue_cmd_in_poll_mode_ppc(struct mrsas_instance *,
struct mrsas_cmd *);
static int issue_cmd_in_sync_mode_ppc(struct mrsas_instance *,
struct mrsas_cmd *);
static void enable_intr_ppc(struct mrsas_instance *);
static void disable_intr_ppc(struct mrsas_instance *);
static int intr_ack_ppc(struct mrsas_instance *);
void display_scsi_inquiry(caddr_t);
static int alloc_additional_dma_buffer(struct mrsas_instance *);
static void complete_cmd_in_sync_mode(struct mrsas_instance *,
struct mrsas_cmd *);
static int mrsas_kill_adapter(struct mrsas_instance *);
static int mrsas_issue_init_mfi(struct mrsas_instance *);
static int mrsas_reset_ppc(struct mrsas_instance *);
struct mrsas_cmd *cmd_to_abort);
scsi_hba_tran_t *, struct scsi_device *);
ddi_bus_config_op_t, void *, dev_info_t **);
static int mrsas_parse_devname(char *, int *, int *);
static int mrsas_config_all_devices(struct mrsas_instance *);
uint8_t, dev_info_t **);
static int mrsas_name_node(dev_info_t *, char *, int);
static void mrsas_issue_evt_taskq(struct mrsas_eventinfo *);
static void free_additional_dma_buffer(struct mrsas_instance *);
static void io_timeout_checker(void *);
static void mrsas_fm_init(struct mrsas_instance *);
static void mrsas_fm_fini(struct mrsas_instance *);
.intr_ack = intr_ack_ppc,
};
};
DMA_ATTR_V0, /* dma_attr_version */
0, /* low DMA address range */
0xFFFFFFFFU, /* high DMA address range */
0xFFFFFFFFU, /* DMA counter register */
8, /* DMA address alignment */
0x07, /* DMA burstsizes */
1, /* min DMA size */
0xFFFFFFFFU, /* max DMA size */
0xFFFFFFFFU, /* segment boundary */
MRSAS_MAX_SGE_CNT, /* dma_attr_sglen */
512, /* granularity of device */
0 /* bus specific DMA flags */
};
/*
* Fix for: Thunderbolt controller IO timeout when IO write size is 1MEG,
* Limit size to 256K
*/
/*
* cb_ops contains base level routines
*/
mrsas_open, /* open */
mrsas_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
mrsas_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
nodev, /* cb_prop_op */
0, /* streamtab */
CB_REV, /* cb_rev */
nodev, /* cb_aread */
nodev /* cb_awrite */
};
/*
* dev_ops contains configuration routines
*/
DEVO_REV, /* rev, */
0, /* refcnt */
mrsas_getinfo, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
mrsas_attach, /* attach */
mrsas_detach, /* detach */
#ifdef __sparc
mrsas_reset, /* reset */
#else /* __sparc */
#endif /* __sparc */
&mrsas_cb_ops, /* char/block ops */
NULL, /* bus ops */
NULL, /* power */
#ifdef __sparc
#else /* __sparc */
mrsas_quiesce /* quiesce */
#endif /* __sparc */
};
&mod_driverops, /* module type - driver */
&mrsas_ops, /* driver ops */
};
MODREV_1, /* ml_rev - must be MODREV_1 */
&modldrv, /* ml_linkage */
NULL /* end of driver linkage */
};
};
/* Use the LSI Fast Path for the 2208 (tbolt) commands. */
/*
* ************************************************************************** *
* *
* common entry points - for loadable kernel modules *
* *
* ************************************************************************** *
*/
/*
* _init - initialize a loadable module
* @void
*
* The driver should perform any one-time resource allocation or data
* initialization during driver loading in _init(). For example, the driver
* should initialize any mutexes global to the driver in this routine.
* The driver should not, however, use _init() to allocate or initialize
* anything that has to do with a particular instance of the device.
* Per-instance initialization must be done in attach().
*/
int
_init(void)
{
int ret;
sizeof (struct mrsas_instance), 0);
if (ret != DDI_SUCCESS) {
return (ret);
}
return (ret);
}
if (ret != DDI_SUCCESS) {
}
return (ret);
}
/*
* _info - returns information about a loadable module.
* @void
*
* _info() is called to return module information. This is a typical entry
* point that does predefined role. It simply calls mod_info().
*/
int
{
}
/*
* _fini - prepare a loadable module for unloading
* @void
*
* In _fini(), the driver should release any resources that were allocated in
* _init(). The driver must remove itself from the system module list.
*/
int
_fini(void)
{
int ret;
return (ret);
}
return (ret);
}
/*
* ************************************************************************** *
* *
* common entry points - for autoconfiguration *
* *
* ************************************************************************** *
*/
/*
* attach - adds a device to the system as part of initialization
* @dip:
* @cmd:
*
* The kernel calls a driver's attach() entry point to attach an instance of
* a device (for MegaRAID, it is instance of a controller) or to resume
* operation for an instance of a device that has been suspended or has been
* shut down by the power management framework
* The attach() entry point typically includes the following types of
* processing:
* - allocate a soft-state structure for the device instance (for MegaRAID,
* controller instance)
* - initialize per-instance mutexes
* - initialize condition variables
* - register the device's interrupts (for MegaRAID, controller's interrupts)
* - map the registers and memory of the device instance (for MegaRAID,
* controller instance)
* - create minor device nodes for the device instance (for MegaRAID,
* controller instance)
* - report that the device instance (for MegaRAID, controller instance) has
* attached
*/
static int
{
int instance_no;
int nregs;
int i = 0;
int intr_types = 0;
char *data;
/* CONSTCOND */
/*
* check to see whether this device is in a DMA-capable slot.
*/
return (DDI_FAILURE);
}
switch (cmd) {
case DDI_ATTACH:
/* allocate the soft state for the instance */
!= DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/* Setup the PCI configuration space handles */
DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
PCI_CONF_COMM) | PCI_COMM_ME));
"?0x%x:0x%x 0x%x:0x%x, irq:%d drv-ver:%s\n",
/* enable bus-mastering */
if (!(command & PCI_COMM_ME)) {
command |= PCI_COMM_ME;
"enable bus-mastering", instance_no));
} else {
"bus-mastering already set", instance_no));
}
/* initialize function pointers */
switch (device_id) {
case PCI_DEVICE_ID_LSI_TBOLT:
case PCI_DEVICE_ID_LSI_FURY:
break;
case PCI_DEVICE_ID_LSI_SKINNY:
/*
* FALLTHRU to PPC-style functions, but mark this
* instance as Skinny, because the register set is
* slightly different (See WR_IB_PICK_QPORT), and
* certain other features are available to a Skinny
* HBA.
*/
/* FALLTHRU */
case PCI_DEVICE_ID_LSI_2108V:
"?2108 Liberator device detected\n");
break;
default:
return (DDI_FAILURE);
}
/* Initialize FMA */
"fm-capable", DDI_FM_EREPORT_CAPABLE |
/* Setup register map */
goto fail_attach;
}
if (reglength > DEFAULT_MFI_MEM_SZ) {
"mr_sas: register length to map is 0x%lx bytes",
reglength));
}
!= DDI_SUCCESS) {
goto fail_attach;
}
/*
* Disable Interrupt Now.
* Setup Software interrupt
*/
msi_enable = 0;
"msi_enable = %d disabled", msi_enable));
}
}
enable_fp = 0;
"enable_fp = %d, Fast-Path disabled.\n",
}
}
/* Check for all supported interrupt types */
"ddi_intr_get_supported_types() failed");
goto fail_attach;
}
"ddi_intr_get_supported_types() ret: 0x%x", intr_types));
/* Initialize and Setup Interrupt handler */
DDI_SUCCESS) {
"MSIX interrupt query failed");
goto fail_attach;
}
DDI_SUCCESS) {
"MSI interrupt query failed");
goto fail_attach;
}
} else if (intr_types & DDI_INTR_TYPE_FIXED) {
msi_enable = 0;
DDI_SUCCESS) {
"FIXED interrupt query failed");
goto fail_attach;
}
} else {
"suppport either FIXED or MSI/X "
"interrupts");
goto fail_attach;
}
ctio_enable = 0;
"ctio_enable = %d disabled", ctio_enable));
}
}
/* setup the mfi based low level driver */
"could not initialize the low level driver");
goto fail_attach;
}
/* Initialize all Mutex */
}
/* Register our soft-isr for highlevel interrupts. */
if (ddi_add_softintr(dip,
DDI_SUCCESS) {
"Software ISR did not register");
goto fail_attach;
}
}
}
instance->softint_running = 0;
/* Allocate a transport structure */
"scsi_hba_tran_alloc failed");
goto fail_attach;
}
else
/* Attach this instance of the hba */
!= DDI_SUCCESS) {
"scsi_hba_attach failed");
goto fail_attach;
}
(CE_CONT, "scsi_hba_attach_setup() done."));
/* create devctl node for cfgadm command */
DDI_NT_SCSI_NEXUS, 0) == DDI_FAILURE) {
goto fail_attach;
}
/* create scsi node for cfgadm command */
DDI_FAILURE) {
goto fail_attach;
}
/*
* Create a node for applications
* for issuing ioctl to the driver.
*/
DDI_FAILURE) {
goto fail_attach;
}
/* Create a taskq to handle dr events */
goto fail_attach;
}
/* enable interrupt */
/* initiate AEN */
if (start_mfi_aen(instance)) {
goto fail_attach;
}
/* Finally! We are on the air. */
/* FMA handle checking. */
DDI_SUCCESS) {
goto fail_attach;
}
DDI_SUCCESS) {
goto fail_attach;
}
KM_SLEEP);
#ifdef PDSUPPORT
sizeof (struct mrsas_tbolt_pd), KM_SLEEP);
for (i = 0; i < instance->mr_tbolt_pd_max; i++) {
(uint8_t)i;
}
}
#endif
break;
case DDI_PM_RESUME:
break;
case DDI_RESUME:
break;
default:
return (DDI_FAILURE);
}
(CE_NOTE, "mrsas_attach() return SUCCESS instance_num %d",
instance_no));
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* getinfo - gets device information
* @dip:
* @cmd:
* @arg:
* @resultp:
*
* The system calls getinfo() to obtain configuration information that only
* the driver knows. The mapping of minor numbers to device instance is
* entirely under the control of the driver. The system sometimes needs to ask
* the driver which device a particular dev_t represents.
* Given the device number return the devinfo pointer from the scsi_device
* structure.
*/
/*ARGSUSED*/
static int
{
int rval;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
instance = (struct mrsas_instance *)
rval = DDI_FAILURE;
} else {
rval = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
rval = DDI_SUCCESS;
break;
default:
rval = DDI_FAILURE;
}
return (rval);
}
/*
* detach - detaches a device from the system
* @dip: pointer to the device's dev_info structure
* @cmd: type of detach
*
* A driver's detach() entry point is called to detach an instance of a device
* that is bound to the driver. The entry point is called with the instance of
* the device node to be detached and with DDI_DETACH, which is specified as
* the cmd argument to the entry point.
* This routine is called during driver unload. We free all the allocated
* resources and call the corresponding LLD so that it can also release all
* its resources.
*/
static int
{
int instance_no;
/* CONSTCOND */
if (!instance) {
return (DDI_FAILURE);
}
switch (cmd) {
case DDI_DETACH:
"mrsas_detach: DDI_DETACH"));
}
"failed to detach");
return (DDI_FAILURE);
}
(CE_CONT, "scsi_hba_dettach() done."));
}
break;
case DDI_PM_SUSPEND:
"mrsas_detach: DDI_PM_SUSPEND"));
break;
case DDI_SUSPEND:
"mrsas_detach: DDI_SUSPEND"));
break;
default:
"invalid detach command:0x%x", cmd));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
{
}
}
}
return; /* DDI_FAILURE */
}
}
}
instance->map_update_cmd)) {
"failed to abort previous syncmap command");
}
}
}
"failed to abort prevous AEN command");
/* This means the controller is fully initialized and running */
/* Shutdown should be a last command to controller. */
/* shutdown_controller(); */
}
}
}
}
}
}
}
}
}
/*
* free dma memory allocated for
*/
}
sizeof (struct mrsas_tbolt_pd));
}
}
* sizeof (struct mrsas_ld));
}
}
}
} else {
}
}
}
}
/*
* ************************************************************************** *
* *
* common entry points - for character driver types *
* *
* ************************************************************************** *
*/
/*
* open - gets access to a device
* @dev:
* @openflags:
* @otyp:
* @credp:
*
* Access to a device by one or more application programs is controlled
* through the open() and close() entry points. The primary function of
* open() is to verify that the open request is allowed.
*/
static int
{
int rval = 0;
/* Check root permissions */
"mr_sas: Non-root ioctl access denied!"));
return (EPERM);
}
/* Verify we are being opened as a character device */
"mr_sas: ioctl node must be a char node"));
return (EINVAL);
}
== NULL) {
return (ENXIO);
}
if (scsi_hba_open) {
}
return (rval);
}
/*
* close - gives up access to a device
* @dev:
* @openflags:
* @otyp:
* @credp:
*
* close() should perform any cleanup necessary to finish using the minor
* device, and prepare the device (and driver) to be opened again.
*/
static int
{
int rval = 0;
/* no need for locks! */
if (scsi_hba_close) {
}
return (rval);
}
/*
* ioctl - performs a range of I/O commands for character drivers
* @dev:
* @cmd:
* @arg:
* @mode:
* @credp:
* @rvalp:
*
* ioctl() routine must make sure that user data is copied into or out of the
* kernel address space explicitly using copyin(), copyout(), ddi_copyin(),
* and ddi_copyout(), as appropriate.
* This is a wrapper routine to serialize access to the actual ioctl routine.
* ioctl() should return 0 on success, or the appropriate error number. The
* driver may also set the value returned to the calling process through rvalp.
*/
static int
int *rvalp)
{
int rval = 0;
/* invalid minor number */
return (ENXIO);
}
KM_SLEEP);
case MRSAS_IOCTL_FIRMWARE:
sizeof (struct mrsas_ioctl), mode)) {
"ERROR IOCTL copyin"));
return (EFAULT);
}
} else {
}
"mrsas_ioctl: copy_to_user failed"));
rval = 1;
}
break;
case MRSAS_IOCTL_AEN:
"mrsas_ioctl: ERROR AEN copyin"));
return (EFAULT);
}
"mrsas_ioctl: copy_to_user failed"));
rval = 1;
}
break;
default:
"scsi_hba_ioctl called, ret = %x.", rval));
}
return (rval);
}
/*
* ************************************************************************** *
* *
* common entry points - for block driver types *
* *
* ************************************************************************** *
*/
#ifdef __sparc
/*
* reset - TBD
* @dip:
* @cmd:
*
* TBD
*/
/*ARGSUSED*/
static int
{
int instance_no;
if (!instance) {
"in reset", instance_no));
return (DDI_FAILURE);
}
instance_no));
return (DDI_SUCCESS);
}
#else /* __sparc */
/*ARGSUSED*/
static int
{
int instance_no;
if (!instance) {
"in quiesce", instance_no));
return (DDI_FAILURE);
}
"healthy state", instance_no));
return (DDI_FAILURE);
}
"failed to abort prevous AEN command QUIESCE"));
}
instance->map_update_cmd)) {
"mrsas_detach: failed to abort "
"previous syncmap command");
return (DDI_FAILURE);
}
}
instance_no));
if (wait_for_outstanding(instance)) {
(CE_CONT, "wait_for_outstanding: return FAIL.\n"));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
#endif /* __sparc */
/*
* ************************************************************************** *
* *
* entry points (SCSI HBA) *
* *
* ************************************************************************** *
*/
/*
* tran_tgt_init - initialize a target device instance
* @hba_dip:
* @tgt_dip:
* @tran:
* @sd:
*
* The tran_tgt_init() entry point enables the HBA to allocate and initialize
* any per-target resources. tran_tgt_init() also enables the HBA to qualify
* the device's address as valid and supportable for that particular HBA.
* By returning DDI_FAILURE, the instance of the target driver for that device
* is not probed or attached.
*/
/*ARGSUSED*/
static int
{
if (ndi_dev_is_persistent_node(tgt_dip) == 0) {
/*
* If no persistent node exists, we don't allow .conf node
* to be created.
*/
(CE_NOTE, "mrsas_tgt_init find child ="
/* Create this .conf node */
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
}
}
#ifdef PDSUPPORT
}
}
#endif
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static void
{
}
}
#ifdef PDSUPPORT
"for tgt:%x", tgt));
}
#endif
}
{
if (ndi_dev_is_persistent_node(child) == 0) {
continue;
}
DDI_SUCCESS) {
continue;
}
break;
}
}
(void *)child));
return (child);
}
/*
* mrsas_name_node -
* @dip:
* @name:
* @len:
*/
static int
{
if (tgt == -1) {
return (DDI_FAILURE);
}
"lun", -1);
if (lun == -1) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* tran_init_pkt - allocate & initialize a scsi_pkt structure
* @ap:
* @pkt:
* @bp:
* @cmdlen:
* @statuslen:
* @tgtlen:
* @flags:
* @callback:
*
* The tran_init_pkt() entry point allocates and initializes a scsi_pkt
* structure and DMA resources for a target driver request. The
* tran_init_pkt() entry point is called when the target driver calls the
* SCSA function scsi_init_pkt(). Each call of the tran_init_pkt() entry point
* is a request to perform one or more of three possible services:
* - allocation and initialization of a scsi_pkt structure
* - allocation of DMA resources for data transfer
* - reallocation of DMA resources for the next portion of the data transfer
*/
static struct scsi_pkt *
{
/* step #1 : pkt allocation */
return (NULL);
}
/*
* Initialize the new pkt - we redundantly initialize
* all the fields for illustrative purposes.
*/
acmd->cmd_ncookies = 0;
acmd->cmd_cookie = 0;
acmd->cmd_cookiecnt = 0;
pkt->pkt_statistics = 0;
pkt->pkt_reason = 0;
} else {
}
/* step #2 : dma allocation/move */
callback) == DDI_FAILURE) {
if (new_pkt) {
}
}
} else {
}
}
}
return (pkt);
}
/*
* tran_start - transport a SCSI command to the addressed target
* @ap:
* @pkt:
*
* The tran_start() entry point for a SCSI HBA driver is called to transport a
* SCSI command to the addressed target. The SCSI command is described
* entirely within the scsi_pkt structure, which the target driver allocated
* through the HBA driver's tran_init_pkt() entry point. If the command
* involves a data transfer, DMA resources must also have been allocated for
* the scsi_pkt structure.
*
* Return Values :
* TRAN_BUSY - request queue is full, no more free scbs
* TRAN_ACCEPT - pkt has been submitted to the instance
*/
static int
{
"mrsas_tran_start: return TRAN_FATAL_ERROR "
"for IO, as the HBA doesnt take any more IOs"));
if (pkt) {
}
return (TRAN_FATAL_ERROR);
}
if (instance->adapterresetinprogress) {
"returning mfi_pkt and setting TRAN_BUSY\n"));
return (TRAN_BUSY);
}
/*
* Check if the command is already completed by the mrsas_build_cmd()
* routine. In which case the busy_flag would be clear and scb will be
* NULL and appropriate reason provided in pkt_reason field
*/
if (cmd_done) {
}
return (TRAN_ACCEPT);
}
return (TRAN_BUSY);
}
return (TRAN_BUSY);
}
/* Synchronize the Cmd frame for the controller */
} else {
pkt->pkt_statistics = 0;
&hdr->cmd_status)) {
case MFI_STAT_OK:
break;
"mrsas_tran_start: scsi done with error"));
pkt->pkt_statistics = 0;
break;
"mrsas_tran_start: device not found error"));
break;
default:
}
}
}
return (TRAN_ACCEPT);
}
/*
* tran_abort - Abort any commands that are currently in transport
* @ap:
* @pkt:
*
* The tran_abort() entry point for a SCSI HBA driver is called to abort any
* commands that are currently in transport for a particular target. This entry
* point is called when a target driver calls scsi_abort(). The tran_abort()
* entry point should attempt to abort the command denoted by the pkt
* parameter. If the pkt parameter is NULL, tran_abort() should attempt to
* abort all outstanding commands in the transport layer for the particular
* target or logical unit.
*/
/*ARGSUSED*/
static int
{
/* abort command not supported by H/W */
return (DDI_FAILURE);
}
/*
* tran_reset - reset either the SCSI bus or target
* @ap:
* @level:
*
* The tran_reset() entry point for a SCSI HBA driver is called to reset either
* the SCSI bus or a particular SCSI target device. This entry point is called
* when a target driver calls scsi_reset(). The tran_reset() entry point must
* reset the SCSI bus if level is RESET_ALL. If level is RESET_TARGET, just the
* particular target or logical unit must be reset.
*/
/*ARGSUSED*/
static int
{
if (wait_for_outstanding(instance)) {
(CE_CONT, "wait_for_outstanding: return FAIL.\n"));
return (DDI_FAILURE);
} else {
return (DDI_SUCCESS);
}
}
/*
* tran_getcap - get one of a set of SCSA-defined capabilities
* @ap:
* @cap:
* @whom:
*
* The target driver can request the current setting of the capability for a
* particular target by setting the whom parameter to nonzero. A whom value of
* zero indicates a request for the current setting of the general capability
* for the SCSI bus or for adapter hardware. The tran_getcap() should return -1
* for undefined capabilities or the current value of the requested capability.
*/
/*ARGSUSED*/
static int
{
int rval = 0;
/* we do allow inquiring about capabilities for other targets */
return (-1);
}
switch (scsi_hba_lookup_capstr(cap)) {
case SCSI_CAP_DMA_MAX:
/* Limit to 256k max transfer */
} else {
/* Limit to 16MB max transfer */
}
break;
case SCSI_CAP_MSG_OUT:
rval = 1;
break;
case SCSI_CAP_DISCONNECT:
rval = 0;
break;
case SCSI_CAP_SYNCHRONOUS:
rval = 0;
break;
case SCSI_CAP_WIDE_XFER:
rval = 1;
break;
case SCSI_CAP_TAGGED_QING:
rval = 1;
break;
case SCSI_CAP_UNTAGGED_QING:
rval = 1;
break;
case SCSI_CAP_PARITY:
rval = 1;
break;
case SCSI_CAP_INITIATOR_ID:
break;
case SCSI_CAP_ARQ:
rval = 1;
break;
case SCSI_CAP_LINKED_CMDS:
rval = 0;
break;
rval = 1;
break;
case SCSI_CAP_GEOMETRY:
rval = -1;
break;
default:
rval = -1;
break;
}
return (rval);
}
/*
* tran_setcap - set one of a set of SCSA-defined capabilities
* @ap:
* @cap:
* @value:
* @whom:
*
* The target driver might request that the new value be set for a particular
* target by setting the whom parameter to nonzero. A whom value of zero
* means that request is to set the new value for the SCSI bus or for adapter
* hardware in general.
* The tran_setcap() should return the following values as appropriate:
* - -1 for undefined capabilities
* - 0 if the HBA driver cannot set the capability to the requested value
* - 1 if the HBA driver is able to set the capability to the requested value
*/
/*ARGSUSED*/
static int
{
/* We don't allow setting capabilities for other targets */
return (-1);
}
switch (scsi_hba_lookup_capstr(cap)) {
case SCSI_CAP_DMA_MAX:
case SCSI_CAP_MSG_OUT:
case SCSI_CAP_PARITY:
case SCSI_CAP_LINKED_CMDS:
case SCSI_CAP_DISCONNECT:
case SCSI_CAP_SYNCHRONOUS:
case SCSI_CAP_UNTAGGED_QING:
case SCSI_CAP_WIDE_XFER:
case SCSI_CAP_INITIATOR_ID:
case SCSI_CAP_ARQ:
/*
* None of these are settable via
* the capability interface.
*/
break;
case SCSI_CAP_TAGGED_QING:
rval = 1;
break;
case SCSI_CAP_SECTOR_SIZE:
rval = 1;
break;
case SCSI_CAP_TOTAL_SECTORS:
rval = 1;
break;
default:
rval = -1;
break;
}
return (rval);
}
/*
* tran_destroy_pkt - deallocate scsi_pkt structure
* @ap:
* @pkt:
*
* The tran_destroy_pkt() entry point is the HBA driver function that
* deallocates scsi_pkt structures. The tran_destroy_pkt() entry point is
* called when the target driver calls scsi_destroy_pkt(). The
* tran_destroy_pkt() entry point must free any DMA resources that have been
* allocated for the packet. An implicit DMA synchronization occurs if the
* DMA resources are freed and any cached data remains after the completion
* of the transfer.
*/
static void
{
}
/* free the pkt */
}
/*
* tran_dmafree - deallocates DMA resources
* @ap:
* @pkt:
*
* The tran_dmafree() entry point deallocates DMAQ resources that have been
* allocated for a scsi_pkt structure. The tran_dmafree() entry point is
* called when the target driver calls scsi_dmafree(). The tran_dmafree() must
* free only DMA resources allocated for a scsi_pkt structure, not the
* scsi_pkt itself. When DMA resources are freed, a DMA synchronization is
* implicitly performed.
*/
/*ARGSUSED*/
static void
{
}
}
/*
* tran_sync_pkt - synchronize the DMA object allocated
* @ap:
* @pkt:
*
* The tran_sync_pkt() entry point synchronizes the DMA object allocated for
* the scsi_pkt structure before or after a DMA transfer. The tran_sync_pkt()
* entry point is called when the target driver calls scsi_sync_pkt(). If the
* data transfer direction is a DMA read from device to memory, tran_sync_pkt()
* must synchronize the CPU's view of the data. If the data transfer direction
* is a DMA write from memory to device, tran_sync_pkt() must synchronize the
* device's view of the data.
*/
/*ARGSUSED*/
static void
{
}
}
/*ARGSUSED*/
static int
{
return (1);
}
/*ARGSUSED*/
static int
{
return (1);
}
/*
* mrsas_isr(caddr_t)
*
* The Interrupt Service Routine
*
* Collect status for all completed commands and do callback
*
*/
static uint_t
{
int need_softintr;
int retval;
return (DDI_INTR_UNCLAIMED);
}
return (retval);
} else {
return (DDI_INTR_UNCLAIMED);
}
}
0, 0, DDI_DMA_SYNC_FORCPU);
!= DDI_SUCCESS) {
"mr_sas_isr(): FMA check, returning DDI_INTR_UNCLAIMED"));
return (DDI_INTR_CLAIMED);
}
#ifdef OCRDEBUG
if (debug_consecutive_timeout_after_ocr_g == 1) {
"simulating consecutive timeout after ocr"));
return (DDI_INTR_CLAIMED);
}
#endif
return (DDI_INTR_CLAIMED);
}
if (hdr) {
}
} else {
if (pkt) {
}
}
consumer++;
consumer = 0;
}
}
0, 0, DDI_DMA_SYNC_FORDEV);
if (instance->softint_running) {
need_softintr = 0;
} else {
need_softintr = 1;
}
if (need_softintr) {
}
} else {
/*
* Not a high-level interrupt, therefore call the soft level
* interrupt explicitly
*/
(void) mrsas_softintr(instance);
}
return (DDI_INTR_CLAIMED);
}
/*
* ************************************************************************** *
* *
* libraries *
* *
* ************************************************************************** *
*/
/*
* get_mfi_pkt : Get a command from the free pool
* After successful allocation, the caller of this routine
* must clear the frame buffer (memset to zero) before
* using the packet further.
*
* ***** Note *****
* After clearing the frame buffer the context id of the
* frame buffer SHOULD be restored back.
*/
struct mrsas_cmd *
{
if (!mlist_empty(head)) {
}
cmd->retry_count_for_ocr = 0;
cmd->drv_pkt_time = 0;
}
return (cmd);
}
static struct mrsas_cmd *
{
if (!mlist_empty(head)) {
}
cmd->retry_count_for_ocr = 0;
cmd->drv_pkt_time = 0;
}
return (cmd);
}
/*
* return_mfi_pkt : Return a cmd to free command pool
*/
void
{
/* use mlist_add_tail for debug assistance */
}
static void
{
}
void
{
if (hdr) {
"push_pending_mfi_pkt: "
"cmd %p index %x "
"time %llx",
gethrtime()));
/* Wait for specified interval */
"push_pending_pkt(): "
"Called IO Timeout Value %x\n",
cmd->drv_pkt_time));
}
}
} else {
if (pkt) {
"push_pending_mfi_pkt: "
"cmd %p index %x pkt %p, "
"time %llx",
gethrtime()));
}
}
}
}
int
{
int saved_level;
int cmd_count = 0;
"mrsas_print_pending_cmds(): Called");
while (flag) {
flag = 0;
" NO MORE CMDS PENDING....\n"));
break;
} else {
if (cmd) {
hdr = (struct mrsas_header *)
if (hdr) {
"print: cmd %p index 0x%x "
"drv_pkt_time 0x%x (NO-PKT)"
" hdr %p\n", (void *)cmd,
(void *)hdr));
}
} else {
if (pkt) {
"print: cmd %p index 0x%x "
"drv_pkt_time 0x%x pkt %p \n",
}
}
if (++cmd_count == 1) {
0xDD);
} else {
1);
}
}
}
}
return (DDI_SUCCESS);
}
int
{
"mrsas_complete_pending_cmds(): Called"));
if (cmd) {
if (pkt) { /* for IO */
= CMD_DEV_GONE;
= STAT_DISCON;
"fail and posting to scsa "
"cmd %p index %x"
" pkt %p "
"time : %llx",
}
} else { /* for DCMDS */
"posting invalid status to application "
"cmd %p index %x"
" hdr %p "
"time : %llx",
}
}
} else {
"mrsas_complete_pending_cmds:"
"NULL command\n"));
}
"mrsas_complete_pending_cmds:"
"looping for more commands\n"));
}
return (DDI_SUCCESS);
}
void
int detail)
{
int i;
int saved_level;
if (detail == 0xDD) {
}
"cmd->index 0x%x SMID 0x%x timer 0x%x sec\n",
} else {
"cmd->index 0x%x timer 0x%x sec\n",
}
if (pkt) {
} else {
}
"IoFlags=0x%X SGLFlags=0x%X DataLength=0x%X\n",
for (i = 0; i < 32; i++) {
}
"ldTargetId=0x%X timeoutValue=0x%X regLockFlags=0x%X "
"RAIDFlags=0x%X regLockRowLBA=0x%" PRIu64
" regLockLength=0x%X spanArm=0x%X\n",
}
if (detail == 0xDD) {
}
}
int
{
if (cmd) {
"mrsas_issue_pending_cmds(): "
"Got a cmd: cmd %p index 0x%x drv_pkt_time 0x%x ",
/* Reset command timeout value */
"cmd retry count = %d\n",
CE_WARN, "mrsas_issue_pending_cmds(): "
"cmd->retry_count exceeded limit >%d\n",
"mrsas_issue_pending_cmds():"
"Calling KILL Adapter");
else
(void) mrsas_kill_adapter(instance);
return (DDI_FAILURE);
}
if (pkt) {
"PENDING PKT-CMD ISSUE: cmd %p index %x "
"pkt %p time %llx",
(void *)pkt,
gethrtime()));
} else {
"mrsas_issue_pending_cmds(): NO-PKT, "
"cmd %p index 0x%x drv_pkt_time 0x%x",
}
"mrsas_issue_pending_cmds(): "
"SYNC_CMD == TRUE \n");
} else {
}
} else {
"mrsas_issue_pending_cmds: NULL command\n"));
}
"mrsas_issue_pending_cmds:"
"looping for more commands"));
}
return (DDI_SUCCESS);
}
/*
* destroy_mfi_frame_pool
*/
void
{
int i;
/* return all frames to pool */
for (i = 0; i < max_cmd; i++) {
}
}
/*
* create_mfi_frame_pool
*/
int
{
int i = 0;
int cookie_cnt;
sge_sz = sizeof (struct mrsas_sge_ieee);
/* calculated the number of 64byte frames required for SGL */
while (i < max_cmd) {
"create_mfi_frame_pool: could not alloc.");
goto mrsas_undo_frame_pool;
}
"pci_pool_alloc failed");
goto mrsas_undo_frame_pool;
}
i++;
}
return (DDI_SUCCESS);
if (i > 0)
return (retval);
}
/*
* free_additional_dma_buffer
*/
static void
{
(void) mrsas_free_dma_obj(instance,
}
(void) mrsas_free_dma_obj(instance,
}
}
/*
* alloc_additional_dma_buffer
*/
static int
{
/* max cmds plus 1 + producer & consumer */
0xFFFFFFFFU;
"could not alloc reply queue");
return (DDI_FAILURE);
}
(reply_q_sz + 8);
(reply_q_sz + 8);
/* allocate evt_detail */
"could not allocate data transfer buffer.");
goto mrsas_undo_internal_buff;
}
sizeof (struct mrsas_evt_detail));
return (DDI_SUCCESS);
(void) mrsas_free_dma_obj(instance,
}
return (DDI_FAILURE);
}
void
{
int i;
/* already freed */
return;
}
/* size of cmd_list array */
/* First free each cmd */
for (i = 0; i < max_cmd; i++) {
sizeof (struct mrsas_cmd));
}
}
/* Now, free cmd_list array */
} else {
}
}
/*
* mrsas_alloc_cmd_pool
*/
int
{
int i;
int count;
"max_cmd %x", max_cmd));
/*
* instance->cmd_list is an array of struct mrsas_cmd pointers.
* Allocate the dynamic array first and then allocate individual
* commands.
*/
/* create a frame pool and assign one frame to each cmd */
}
/* add all the commands to command pool */
/*
* When max_cmd is lower than MRSAS_APP_RESERVED_CMDS, how do I split
* into app_cmd and regular cmd? For now, just take
* max(1/8th of max, 4);
*/
for (i = 0; i < reserve_cmd; i++) {
}
for (i = reserve_cmd; i < max_cmd; i++) {
}
return (DDI_SUCCESS);
if (count > 0) {
/* free each cmd */
for (i = 0; i < count; i++) {
sizeof (struct mrsas_cmd));
}
}
}
return (DDI_FAILURE);
}
/*
* free_space_for_mfi
*/
static void
{
/* already freed */
return;
}
/* Free additional dma buffer */
/* Free the MFI frame pool */
/* Free all the commands in the cmd_list */
/* Free the cmd_list buffer itself */
}
/*
* alloc_space_for_mfi
*/
static int
{
/* Allocate command pool (memory for cmd_list & individual commands) */
if (mrsas_alloc_cmd_pool(instance)) {
return (DDI_FAILURE);
}
/* Allocate MFI Frame pool */
if (create_mfi_frame_pool(instance)) {
"error creating frame DMA pool");
goto mfi_undo_cmd_pool;
}
/* Allocate additional DMA buffer */
if (alloc_additional_dma_buffer(instance)) {
"error creating frame DMA pool");
goto mfi_undo_frame_pool;
}
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* get_ctrl_info
*/
static int
struct mrsas_ctrl_info *ctrl_info)
{
int ret = 0;
} else {
}
if (!cmd) {
"Failed to get a cmd for ctrl info"));
return (DDI_FAILURE);
}
/* Clear the frame buffer and assign back the context id */
if (!ci) {
"Failed to alloc mem for ctrl info");
return (DDI_FAILURE);
}
/* for( i = 0; i < DCMD_MBOX_SZ; i++ ) dcmd->mbox.b[i] = 0; */
sizeof (struct mrsas_ctrl_info));
sizeof (struct mrsas_ctrl_info));
}
ret = 0;
/* should get more members of ci with ddi_get when needed */
} else {
"get_ctrl_info: Ctrl info failed");
ret = -1;
}
ret = -1;
}
} else {
}
return (ret);
}
/*
* abort_aen_cmd
*/
static int
struct mrsas_cmd *cmd_to_abort)
{
int ret = 0;
} else {
}
if (!cmd) {
"abort_aen_cmd():Failed to get a cmd for abort_aen_cmd"));
return (DDI_FAILURE);
}
/* Clear the frame buffer and assign back the context id */
/* prepare and issue the abort frame */
&abort_fr->abort_mfi_phys_addr_hi, 0);
}
"abort_aen_cmd: issue_cmd_in_poll_mode failed"));
ret = -1;
} else {
ret = 0;
}
} else {
}
return (ret);
}
static int
{
/*
* Prepare a init frame. Note the init frame points to queue info
* structure. Each frame has SGL allocated after first 64 bytes. For
* this frame - since we don't need any SGL - we use SGL's space as
* queue info structure
*/
/* Clear the frame buffer and assign back the context id */
initq_info = (struct mrsas_init_queue_info *)
((unsigned long)init_frame + 64);
/* fill driver version information */
/* allocate the driver version data transfer buffer */
"init_mfi : Could not allocate driver version buffer."));
return (DDI_FAILURE);
}
/* copy driver version to dma buffer */
sizeof (drv_ver_info.drv_ver));
/* copy driver version physical address to init frame */
sizeof (struct mrsas_init_queue_info));
return (DDI_SUCCESS);
}
/*
* mrsas_init_adapter_ppc - Initialize MFI interface adapter.
*/
int
{
/*
* allocate memory for mfi adapter(cmd pool, individual commands, mfi
* frames etc
*/
"Error, failed to allocate memory for MFI adapter"));
return (DDI_FAILURE);
}
/* Build INIT command */
return (DDI_FAILURE);
}
(CE_NOTE, "Error, failed to build INIT command"));
}
/*
* Disable interrupt before sending init frame ( see linux driver code)
* send INIT MFI frame in polled mode
*/
goto fail_fw_init;
}
goto fail_fw_init;
if (ctio_enable &&
} else {
}
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*
* mrsas_init_adapter - Initialize adapter.
*/
int
{
/* we expect the FW state to be READY */
return (DDI_FAILURE);
}
/* get various operational parameters from status register */
0xFF0000) >> 0x10;
/*
* Reduce the max supported cmds by 1. This is to ensure that the
* reply_q_sz (1 more than the max cmd that driver may send)
* does not exceed max cmds that the FW can support
*/
/* Initialize adapter */
(CE_WARN, "mr_sas: could not initialize adapter"));
return (DDI_FAILURE);
}
/* gather misc FW related information */
"product name %s ld present %d",
} else {
PAGESIZE / 512;
}
return (DDI_SUCCESS);
}
static int
{
/*
* Prepare a init frame. Note the init frame points to queue info
* structure. Each frame has SGL allocated after first 64 bytes. For
* this frame - since we don't need any SGL - we use SGL's space as
* queue info structure
*/
"mrsas_issue_init_mfi: entry\n"));
if (!cmd) {
"mrsas_issue_init_mfi: get_pkt failed\n"));
return (DDI_FAILURE);
}
/* Clear the frame buffer and assign back the context id */
initq_info = (struct mrsas_init_queue_info *)
((unsigned long)init_frame + 64);
sizeof (struct mrsas_init_queue_info));
/* issue the init frame in polled mode */
"mrsas_issue_init_mfi():failed to "
"init firmware"));
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* mfi_state_transition_to_ready : Move the FW to READY state
*
* @reg_set : MFI register set
*/
int
{
int i;
fw_state =
"mfi_state_transition_to_ready:FW state = 0x%x", fw_state));
while (fw_state != MFI_STATE_READY) {
"mfi_state_transition_to_ready:FW state%x", fw_state));
switch (fw_state) {
case MFI_STATE_FAULT:
"mr_sas: FW in FAULT state!!"));
return (ENODEV);
case MFI_STATE_WAIT_HANDSHAKE:
/* set the CLR bit in IMR0 */
"mr_sas: FW waiting for HANDSHAKE"));
/*
* PCI_Hot Plug: MFI F/W requires
* (MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG)
* to be set
*/
/* WR_IB_MSG_0(MFI_INIT_CLEAR_HANDSHAKE, instance); */
} else {
}
break;
/* set the CLR bit in IMR0 */
"mr_sas: FW state boot message pending"));
/*
* PCI_Hot Plug: MFI F/W requires
* (MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG)
* to be set
*/
} else {
instance);
}
break;
case MFI_STATE_OPERATIONAL:
/* bring it to READY state; assuming max wait 2 secs */
"mr_sas: FW in OPERATIONAL state"));
/*
* PCI_Hot Plug: MFI F/W requires
* (MFI_INIT_READY | MFI_INIT_MFIMODE | MFI_INIT_ABORT)
* to be set
*/
/* WR_IB_DOORBELL(MFI_INIT_READY, instance); */
} else {
instance);
for (i = 0; i < (10 * 1000); i++) {
status =
if (status & 1) {
delay(1 *
} else {
break;
}
}
}
break;
case MFI_STATE_UNDEFINED:
/* this state should not last for more than 2 seconds */
break;
case MFI_STATE_BB_INIT:
break;
case MFI_STATE_FW_INIT:
break;
case MFI_STATE_FW_INIT_2:
max_wait = 180;
break;
case MFI_STATE_DEVICE_SCAN:
max_wait = 180;
"Device scan in progress ...\n"));
break;
case MFI_STATE_FLUSH_CACHE:
max_wait = 180;
break;
default:
"mr_sas: Unknown state 0x%x", fw_state));
return (ENODEV);
}
/* the cur_state should not last for more than max_wait secs */
/* fw_state = RD_OB_MSG_0(instance) & MFI_STATE_MASK; */
} else {
break;
}
}
if (fw_state == MFI_STATE_DEVICE_SCAN) {
if (prev_abs_reg_val != cur_abs_reg_val) {
continue;
}
}
/* return error if fw_state hasn't changed after max_wait */
"FW state hasn't changed in %d secs", max_wait));
return (ENODEV);
}
};
/* This may also need to apply to Skinny, but for now, don't worry. */
"mfi_state_transition_to_ready:FW ctrl = 0x%x", fw_ctrl));
/*
* Write 0xF to the doorbell register to do the following.
* - Abort all outstanding commands (bit 0).
* - Transition from OPERATIONAL to READY state (bit 1).
* - Discard (possible) low MFA posted in 64-bit mode (bit-2).
* - Set to release FW to continue running (i.e. BIOS handshake
* (bit 3).
*/
}
return (EIO);
}
return (DDI_SUCCESS);
}
/*
* get_seq_num
*/
static int
struct mrsas_evt_log_info *eli)
{
} else {
}
if (!cmd) {
return (ENOMEM);
}
/* Clear the frame buffer and assign back the context id */
/* allocate the data transfer buffer */
"get_seq_num: could not allocate data transfer buffer.");
return (DDI_FAILURE);
}
sizeof (struct mrsas_evt_log_info));
sizeof (struct mrsas_evt_log_info));
sizeof (struct mrsas_evt_log_info));
}
"failed to issue MRSAS_DCMD_CTRL_EVENT_GET_INFO");
ret = DDI_FAILURE;
} else {
ret = DDI_SUCCESS;
}
ret = DDI_FAILURE;
} else {
}
return (ret);
}
/*
* start_mfi_aen
*/
static int
{
int ret = 0;
/* get the latest sequence number from FW */
"start_mfi_aen: failed to get seq num");
return (-1);
}
/* register AEN with FW for latest sequence number plus 1 */
if (ret) {
"start_mfi_aen: aen registration failed");
return (-1);
}
return (ret);
}
/*
* flush_cache
*/
static void
{
} else {
}
if (!cmd) {
"flush_cache():Failed to get a cmd for flush_cache"));
return;
}
/* Clear the frame buffer and assign back the context id */
}
"flush_cache: failed to issue MFI_DCMD_CTRL_CACHE_FLUSH"));
}
} else {
}
}
/*
* service_mfi_aen- Completes an AEN command
* @instance: Adapter soft state
* @cmd: Command to be completed
*
*/
void
{
int rval = 0;
int tgt = 0;
#ifdef PDSUPPORT
#endif
cmd->cmd_status = 0;
}
/*
* log the MFI AEN event to the sysevent queue so that
* application will get noticed
*/
"mr_sas%d: Failed to log AEN event", instance_no));
}
/*
* Check for any ld devices that has changed state. i.e. online
* or offline.
*/
"AEN: code = %x class = %x locale = %x args = %x",
case MR_EVT_CFG_CLEARED: {
"mr_sas: CFG CLEARED AEN rval = %d "
}
}
break;
}
case MR_EVT_LD_DELETED: {
"tgt id = %d index = %d", rval,
break;
} /* End of MR_EVT_LD_DELETED */
case MR_EVT_LD_CREATED: {
"tgt id = %d index = %d", rval,
break;
} /* End of MR_EVT_LD_CREATED */
#ifdef PDSUPPORT
case MR_EVT_PD_REMOVED_EXT: {
" MR_EVT_PD_REMOVED_EXT: dtype = %x,"
"rval = %d tgt id = %d ", rval,
}
break;
} /* End of MR_EVT_PD_REMOVED_EXT */
case MR_EVT_PD_INSERTED_EXT: {
"rval = %d tgt id = %d ", rval,
}
break;
} /* End of MR_EVT_PD_INSERTED_EXT */
case MR_EVT_PD_STATE_CHANGE: {
PD_SYSTEM) &&
"rval = %d tgt id = %d ", rval,
break;
}
== UNCONFIGURED_GOOD) &&
"mr_sas: PD_INSERTED: rval = %d "
" tgt id = %d ", rval,
break;
}
}
break;
}
#endif
} /* End of Main Switch */
seq_num++;
sizeof (struct mrsas_evt_detail));
cmd->retry_count_for_ocr = 0;
cmd->drv_pkt_time = 0;
/* Issue the aen registration frame */
}
/*
* complete_cmd_in_sync_mode - Completes an internal command
* @instance: Adapter soft state
* @cmd: Command to be completed
*
* The issue_cmd_in_sync_mode() function waits for a command to complete
* after it issues a command. This function wakes up that waiting routine by
* calling wake_up() on the wait queue.
*/
static void
{
(void *)cmd));
cmd->cmd_status = 0;
}
}
/*
* Call this function inside mrsas_softintr.
* mrsas_initiate_ocr_if_fw_is_faulty - Initiates OCR if FW status is faulty
* @instance: Adapter soft state
*/
static uint32_t
{
if (fw_state == MFI_STATE_FAULT) {
"mrsas_initiate_ocr_if_fw_is_faulty: "
"FW in Fault state, detected in ISR: "
"FW doesn't support ocr ");
return (ADAPTER_RESET_NOT_REQUIRED);
} else {
"mrsas_initiate_ocr_if_fw_is_faulty: FW in Fault "
"state, detected in ISR: FW supports ocr "));
return (ADAPTER_RESET_REQUIRED);
}
}
return (ADAPTER_RESET_NOT_REQUIRED);
}
/*
* mrsas_softintr - The Software ISR
* @param arg : HBA soft state
*
* called from high-level interrupt if hi-level interrupt are not there,
* otherwise triggered as a soft interrupt
*/
static uint_t
{
return (DDI_INTR_CLAIMED);
}
/* perform all callbacks first, before releasing the SCBs */
/* syncronize the Cmd frame for the controller */
0, 0, DDI_DMA_SYNC_FORCPU);
DDI_SUCCESS) {
"mrsas_softintr: "
"FMA check reports DMA handle failure"));
return (DDI_INTR_CLAIMED);
}
/* remove the internal command from the process list */
case MFI_CMD_OP_PD_SCSI:
case MFI_CMD_OP_LD_SCSI:
case MFI_CMD_OP_LD_READ:
case MFI_CMD_OP_LD_WRITE:
/*
* MFI_CMD_OP_PD_SCSI and MFI_CMD_OP_LD_SCSI
* could have been issued either through an
* IO path or an IOCTL path. If it was via IOCTL,
* we will send it to internal completion.
*/
break;
}
/* regular commands */
}
}
pkt->pkt_statistics = 0;
"CDB[0] = %x completed for %s: size %lx context %x",
acmd->cmd_dmacount);
if (acmd->cmd_dmacount != 0) {
inq = (struct scsi_inquiry *)
#ifdef PDSUPPORT
}
#else
/* don't expose physical drives to OS */
} else if ((hdr->cmd_status ==
DTYPE_DIRECT) {
/* for physical disk */
hdr->cmd_status =
}
#endif /* PDSUPPORT */
}
}
switch (hdr->cmd_status) {
case MFI_STAT_OK:
break;
break;
(CE_WARN, "Initialization in Progress"));
break;
((struct scsi_status *)
(CE_WARN, "TEST_UNIT_READY fail"));
} else {
arqstat->sts_rqpkt_resid = 0;
(uint8_t *)
&(arqstat->sts_sensedata),
sizeof (struct scsi_extended_sense),
}
break;
case MFI_STAT_LD_OFFLINE:
"mrsas_softintr:device not found error"));
break;
((struct scsi_status *)
arqstat->sts_rqpkt_resid = 0;
/*
* LOGICAL BLOCK ADDRESS OUT OF RANGE:
* ASC: 0x21h; ASCQ: 0x00h;
*/
break;
default:
break;
}
if (acmd->cmd_dmahandle) {
pkt->pkt_statistics = 0;
}
}
/* Call the callback routine */
}
break;
case MFI_CMD_OP_SMP:
case MFI_CMD_OP_STP:
break;
case MFI_CMD_OP_DCMD:
/* see if got an event notification */
"mrsas_softintr: "
"aborted_aen returned"));
} else {
(-1));
}
} else {
}
break;
case MFI_CMD_OP_ABORT:
/*
* MFI_CMD_OP_ABORT successfully completed
* in the synchronous mode
*/
break;
default:
"scsa cmd %p index %x pkt %p"
"time %llx, default ", (void *)cmd,
gethrtime()));
}
}
break;
}
}
instance->softint_running = 0;
return (DDI_INTR_CLAIMED);
}
/*
* mrsas_alloc_dma_obj
*
* Allocate the memory and other resources for an dma object.
*/
int
{
int i;
if (i != DDI_SUCCESS) {
switch (i) {
case DDI_DMA_BADATTR :
"Failed ddi_dma_alloc_handle- Bad attribute"));
break;
case DDI_DMA_NORESOURCES :
"Failed ddi_dma_alloc_handle- No Resources"));
break;
default :
"Failed ddi_dma_alloc_handle: "
"unknown status %d", i));
break;
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (cookie_cnt);
}
/*
* mrsas_free_dma_obj(struct mrsas_instance *, dma_obj_t)
*
* De-allocate the memory and other resources for an dma object, which must
* have been alloated by a previous call to mrsas_alloc_dma_obj()
*/
int
{
return (DDI_SUCCESS);
}
/*
* NOTE: These check-handle functions fail if *_handle == NULL, but
* this function succeeds because of the previous check.
*/
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* mrsas_dma_alloc(instance_t *, struct scsi_pkt *, struct buf *,
* int, int (*)())
*
* Allocate dma resources for a new scsi command
*/
int
{
int dma_flags;
int i;
} else {
}
if (flags & PKT_CONSISTENT) {
}
if (flags & PKT_DMA_PARTIAL) {
}
/* OCR-RESET FIX */
}
switch (i) {
case DDI_DMA_BADATTR:
return (DDI_FAILURE);
case DDI_DMA_NORESOURCES:
return (DDI_FAILURE);
default:
"impossible result (0x%x)", i));
return (DDI_FAILURE);
}
}
switch (i) {
case DDI_DMA_PARTIAL_MAP:
if ((dma_flags & DDI_DMA_PARTIAL) == 0) {
"DDI_DMA_PARTIAL_MAP impossible"));
goto no_dma_cookies;
}
DDI_FAILURE) {
goto no_dma_cookies;
}
DDI_FAILURE) {
goto no_dma_cookies;
}
goto get_dma_cookies;
case DDI_DMA_MAPPED:
acmd->cmd_dma_len = 0;
acmd->cmd_dma_offset = 0;
i = 0;
acmd->cmd_dmacount = 0;
for (;;) {
acmd->cmd_dmacount +=
if (i == instance->max_num_sge ||
i == acmd->cmd_ncookies)
break;
&acmd->cmd_dmacookies[i]);
}
acmd->cmd_cookie = i;
acmd->cmd_cookiecnt = i;
} else {
}
return (DDI_SUCCESS);
case DDI_DMA_NORESOURCES:
break;
case DDI_DMA_NOMAPPING:
break;
case DDI_DMA_TOOBIG:
break;
case DDI_DMA_INUSE:
" DDI_DMA_INUSE impossible"));
break;
default:
"impossible result (0x%x)", i));
break;
}
return (DDI_FAILURE);
}
/*
* mrsas_dma_move(struct mrsas_instance *, struct scsi_pkt *, struct buf *)
*
* move dma resources to next dma window
*
*/
int
{
int i = 0;
/*
* If there are no more cookies remaining in this window,
* must move to the next window first.
*/
return (DDI_SUCCESS);
}
/* at last window, cannot move */
return (DDI_FAILURE);
}
DDI_FAILURE) {
return (DDI_FAILURE);
}
acmd->cmd_cookie = 0;
} else {
/* still more cookies in this window - get the next one */
&acmd->cmd_dmacookies[0]);
}
/* get remaining cookies in this window, up to our maximum */
for (;;) {
acmd->cmd_cookie++;
if (i == instance->max_num_sge ||
break;
}
&acmd->cmd_dmacookies[i]);
}
acmd->cmd_cookiecnt = i;
} else {
}
return (DDI_SUCCESS);
}
/*
* build_cmd
*/
static struct mrsas_cmd *
{
uint32_t i;
/* find out if this is logical or physical drive command. */
*cmd_done = 0;
/* get the command packet */
return (NULL);
}
/* Clear the frame buffer and assign back the context id */
/* lets get the command directions */
}
}
} else {
}
flags |= MFI_FRAME_IEEE;
}
flags |= MFI_FRAME_SGL64;
/*
* case SCMD_SYNCHRONIZE_CACHE:
* flush_cache(instance);
* mrsas_return_mfi_pkt(instance, cmd);
* *cmd_done = 1;
*
* return (NULL);
*/
case SCMD_READ:
case SCMD_WRITE:
case SCMD_READ_G1:
case SCMD_WRITE_G1:
case SCMD_READ_G4:
case SCMD_WRITE_G4:
case SCMD_READ_G5:
case SCMD_WRITE_G5:
/*
* preare the Logical IO frame:
* 2nd bit is zero for all read cmds
*/
/* Initialize sense Information */
} else {
}
/* 6-byte cdb */
<< 16)));
/* 10-byte cdb */
/* 12-byte cdb */
/* 16-byte cdb */
}
break;
}
default:
case SCMD_MODE_SENSE:
case SCMD_MODE_SENSE_G1: {
switch (page_code) {
case 0x3:
case 0x4:
(void) mrsas_mode_sense_build(pkt);
*cmd_done = 1;
return (NULL);
}
break;
}
default:
break;
}
/* prepare the DCDB frame */
tmp_data_xfer_len = 0;
for (i = 0; i < acmd->cmd_cookiecnt; i++) {
}
} else {
}
break;
}
#ifdef lint
#endif
/* prepare the scatter-gather list for the firmware */
}
} else {
}
}
}
return (cmd);
}
/*
* wait_for_outstanding - Wait for all outstanding cmds
* @instance: Adapter soft state
*
* This function waits for upto MRDRV_RESET_WAIT_TIME seconds for FW to
* complete all its outstanding commands. Returns error if one or more IOs
* are pending after this time period.
*/
static int
{
int i;
for (i = 0; i < wait_time; i++) {
if (!instance->fw_outstanding) {
break;
}
}
if (instance->fw_outstanding) {
return (1);
}
return (0);
}
/*
* issue_mfi_pthru
*/
static int
{
void *ubuf;
int i;
if (instance->adapterresetinprogress) {
"returning mfi_pkt and setting TRAN_BUSY\n"));
return (DDI_FAILURE);
}
if (model == DDI_MODEL_ILP32) {
} else {
#ifdef _ILP32
#else
#endif
}
if (xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* pthru_dma_obj.size = xferlen; */
PAGESIZE);
/* allocate kernel buffer for DMA */
"could not allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < xferlen; i++) {
1, mode)) {
"issue_mfi_pthru : "
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
}
/* ddi_put32(acc_handle, &pthru->sense_buf_phys_addr_lo, 0); */
}
"issue_mfi_pthru: fw_ioctl failed"));
} else {
for (i = 0; i < xferlen; i++) {
if (ddi_copyout(
"issue_mfi_pthru : "
"copy to user space failed"));
return (DDI_FAILURE);
}
}
}
}
void *sense_ubuf =
}
for (i = 0; i < sense_len; i++) {
if (ddi_copyout(
"issue_mfi_pthru : "
"copy to user space failed"));
}
"Copying Sense info sense_buff[%d] = 0x%X",
}
}
if (xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* issue_mfi_dcmd
*/
static int
{
void *ubuf;
int i;
if (instance->adapterresetinprogress) {
"returning mfi_pkt and setting TRAN_BUSY"));
return (DDI_FAILURE);
}
if (model == DDI_MODEL_ILP32) {
} else {
#ifdef _ILP32
#else
#endif
}
if (xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* dcmd_dma_obj.size = xferlen; */
PAGESIZE);
/* allocate kernel buffer for DMA */
(CE_WARN, "issue_mfi_dcmd: could not "
"allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < xferlen; i++) {
1, mode)) {
"issue_mfi_dcmd : "
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
}
}
} else {
for (i = 0; i < xferlen; i++) {
if (ddi_copyout(
1, mode)) {
"issue_mfi_dcmd : "
"copy to user space failed"));
return (DDI_FAILURE);
}
}
}
}
if (xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* issue_mfi_smp
*/
static int
{
void *request_ubuf;
void *response_ubuf;
#ifndef _ILP32
#endif
int i;
if (instance->adapterresetinprogress) {
"returning mfi_pkt and setting TRAN_BUSY\n"));
return (DDI_FAILURE);
}
if (model == DDI_MODEL_ILP32) {
"response_xferlen = %x, request_xferlen = %x",
"response_ubuf = %p, request_ubuf = %p",
} else {
#ifdef _ILP32
"response_xferlen = %x, request_xferlen = %x",
"response_ubuf = %p, request_ubuf = %p",
#else
#endif
}
if (request_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* request_dma_obj.size = request_xferlen; */
/* allocate kernel buffer for DMA */
"could not allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < request_xferlen; i++) {
1, mode)) {
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
if (response_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* response_dma_obj.size = response_xferlen; */
/* allocate kernel buffer for DMA */
"could not allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < response_xferlen; i++) {
1, mode)) {
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
/* smp->context = ksmp->context; */
sizeof (uint64_t));
if (model == DDI_MODEL_ILP32) {
"issue_mfi_smp: DDI_MODEL_ILP32"));
} else {
#ifdef _ILP32
"issue_mfi_smp: DDI_MODEL_ILP32"));
#else
"issue_mfi_smp: DDI_MODEL_LP64"));
#endif
}
"smp->response_xferlen = %d, smp->request_xferlen = %d "
}
"issue_mfi_smp: fw_ioctl failed"));
} else {
"issue_mfi_smp: copy to user space"));
if (request_xferlen) {
for (i = 0; i < request_xferlen; i++) {
if (ddi_copyout(
i, (uint8_t *)request_ubuf + i,
1, mode)) {
"issue_mfi_smp : copy to user space"
" failed"));
return (DDI_FAILURE);
}
}
}
if (response_xferlen) {
for (i = 0; i < response_xferlen; i++) {
if (ddi_copyout(
+ i, (uint8_t *)response_ubuf
+ i, 1, mode)) {
"issue_mfi_smp : copy to "
"user space failed"));
return (DDI_FAILURE);
}
}
}
}
ksmp->cmd_status));
if (request_xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
if (response_xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* issue_mfi_stp
*/
static int
{
void *fis_ubuf;
void *data_ubuf;
int i;
if (instance->adapterresetinprogress) {
"returning mfi_pkt and setting TRAN_BUSY\n"));
return (DDI_FAILURE);
}
if (model == DDI_MODEL_ILP32) {
} else {
#ifdef _ILP32
#else
#endif
}
if (fis_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* fis_dma_obj.size = fis_xferlen; */
/* allocate kernel buffer for DMA */
"could not allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < fis_xferlen; i++) {
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
if (data_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* data_dma_obj.size = data_xferlen; */
PAGESIZE);
/* allocate kernel buffer for DMA */
"could not allocate data transfer buffer."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
for (i = 0; i < data_xferlen; i++) {
"copy from user space failed"));
return (DDI_FAILURE);
}
}
}
}
} else {
if (fis_xferlen) {
for (i = 0; i < fis_xferlen; i++) {
if (ddi_copyout(
"issue_mfi_stp : copy to "
"user space failed"));
return (DDI_FAILURE);
}
}
}
}
if (data_xferlen) {
for (i = 0; i < data_xferlen; i++) {
if (ddi_copyout(
"issue_mfi_stp : copy to"
" user space failed"));
return (DDI_FAILURE);
}
}
}
kstp->cmd_status));
if (fis_xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
if (data_xferlen) {
/* free kernel buffer */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* fill_up_drv_ver
*/
void
{
}
/*
* handle_drv_ioctl
*/
static int
int mode)
{
int i;
void *ubuf;
if (model == DDI_MODEL_ILP32) {
"handle_drv_ioctl: DDI_MODEL_ILP32"));
} else {
#ifdef _ILP32
"handle_drv_ioctl: DDI_MODEL_ILP32"));
#else
"handle_drv_ioctl: DDI_MODEL_LP64"));
#endif
}
"MRSAS_DRIVER_IOCTL_DRIVER_VERSION"));
"MRSAS_DRIVER_IOCTL_DRIVER_VERSION : "
"copy to user space failed"));
rval = 1;
} else {
kdcmd->cmd_status = 0;
}
break;
"MRSAS_DRIVER_IOCTL_PCI_INFORMAITON"));
"MRSAS_DRIVER_IOCTL_PCI_INFORMATION : "
"ddi_prop_look_int_array failed"));
rval = DDI_FAILURE;
} else {
ddi_prop_free((void *)props);
}
for (i = 0; i < (sizeof (struct mrsas_pci_information) -
i++) {
pci_conf_buf[i] =
}
"MRSAS_DRIVER_IOCTL_PCI_INFORMATION : "
"copy to user space failed"));
rval = 1;
} else {
kdcmd->cmd_status = 0;
}
break;
default:
"invalid driver specific IOCTL opcode = 0x%x",
rval = DDI_FAILURE;
break;
}
return (rval);
}
/*
* handle_mfi_ioctl
*/
static int
int mode)
{
} else {
}
if (!cmd) {
"failed to get a cmd packet"));
return (DDI_FAILURE);
}
/* Clear the frame buffer and assign back the context id */
case MFI_CMD_OP_DCMD:
break;
case MFI_CMD_OP_SMP:
break;
case MFI_CMD_OP_STP:
break;
case MFI_CMD_OP_LD_SCSI:
case MFI_CMD_OP_PD_SCSI:
break;
default:
rval = DDI_FAILURE;
break;
}
rval = DDI_FAILURE;
} else {
}
return (rval);
}
/*
* AEN
*/
static int
{
int rval = 0;
return (rval);
}
static int
{
int ret_val;
/*
* If there an AEN pending already (aen_cmd), check if the
* class_locale of that pending AEN is inclusive of the new
* AEN request we currently have. If it is, then we don't have
* to do anything. In other words, whichever events the current
* AEN request is subscribing to, have already been subscribed
* to.
*
* If the old_cmd is _not_ inclusive, then we have to abort
* that command, form a class_locale that is superset of both
* old and current and re-issue to the FW
*/
if (aen_cmd) {
/*
* A class whose enum value is smaller is inclusive of all
* higher values. If a PROGRESS (= -1) was previously
* registered, then a new registration requests for higher
* classes need not be sent to FW. They are automatically
* included.
*
* Locale numbers don't have such hierarchy. They are bitmap
* values
*/
/*
* Previously issued event registration includes
* current request. Nothing to do.
*/
return (0);
} else {
if (ret_val) {
"failed to abort prevous AEN command"));
return (ret_val);
}
}
} else {
}
} else {
}
if (!cmd) {
return (ENOMEM);
}
/* Clear the frame buffer and assign back the context id */
/* for(i = 0; i < DCMD_MBOX_SZ; i++) dcmd->mbox.b[i] = 0; */
sizeof (struct mrsas_evt_detail));
/* Prepare DCMD for aen registration */
sizeof (struct mrsas_evt_detail));
sizeof (struct mrsas_evt_detail));
/*
* Store reference to the cmd used to register for AEN. When an
* application wants us to register for AEN, we have to abort this
* cmd and re-register with a new EVENT LOCALE supplied by that app
*/
/* Issue the aen registration frame */
/* atomic_add_16 (&instance->fw_outstanding, 1); */
}
return (0);
}
void
{
int i;
int len;
const char *const scsi_device_types[] = {
"Direct-Access ",
"Sequential-Access",
"Printer ",
"Processor ",
"WORM ",
"CD-ROM ",
"Scanner ",
"Optical Device ",
"Medium Changer ",
"Communications ",
"Unknown ",
"Unknown ",
"Unknown ",
"Enclosure ",
};
len = 0;
for (i = 8; i < 16; i++) {
scsi_inq[i]);
}
for (i = 16; i < 32; i++) {
scsi_inq[i]);
}
for (i = 32; i < 36; i++) {
scsi_inq[i]);
}
i = scsi_inq[0] & 0x1f;
i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] :
"Unknown ");
} else {
}
}
static void
{
int time = 0;
int counter = 0;
" reset in progress"));
return;
}
/* See if this check needs to be in the beginning or last in ISR */
"FW Fault, calling reset adapter");
"fw_outstanding 0x%X max_fw_cmds 0x%X",
if (instance->adapterresetinprogress == 0) {
(void) mrsas_tbolt_reset_ppc(instance);
else
(void) mrsas_reset_ppc(instance);
}
return;
}
continue;
}
continue;
}
} else {
continue;
}
}
if (time <= 0) {
"io_timeout_checker: TIMING OUT: pkt: %p, "
"cmd %p fw_outstanding 0x%X max_fw_cmds 0x%X",
counter++;
break;
}
}
if (counter) {
"supported by Firmware, KILL adapter!!!",
__func__);
else
(void) mrsas_kill_adapter(instance);
return;
} else {
if (instance->adapterresetinprogress == 0) {
(void) mrsas_tbolt_reset_ppc(
instance);
} else {
(void) mrsas_reset_ppc(
instance);
}
}
} else {
"io_timeout_checker: "
"cmd %p cmd->index %d "
"timed out even after 3 resets: "
else
(void) mrsas_kill_adapter(instance);
return;
}
}
}
"schedule next timeout check: "
"do timeout \n"));
}
static uint32_t
{
}
static void
{
if (pkt) {
"ISSUED CMD TO FW : called : cmd:"
": %p instance : %p pkt : %p pkt_time : %x\n",
if (instance->adapterresetinprogress) {
} else {
}
} else {
"ISSUED CMD TO FW : called : cmd : %p, instance: %p"
}
/* Issue the command to the FW */
}
/*
* issue_cmd_in_sync_mode
*/
static int
{
int i;
if (instance->adapterresetinprogress) {
"issue and return in reset case\n"));
return (DDI_SUCCESS);
} else {
}
/* Issue the command to the FW */
}
if (i < (msecs -1)) {
return (DDI_SUCCESS);
} else {
return (DDI_FAILURE);
}
}
/*
* issue_cmd_in_poll_mode
*/
static int
{
int i;
/* issue the frame using inbound queue port */
/* wait for cmd_status to change from 0xFF */
for (i = 0; i < msecs && (
== MFI_CMD_STATUS_POLL_MODE); i++) {
}
== MFI_CMD_STATUS_POLL_MODE) {
"cmd polling timed out"));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
{
/* For SKINNY, write ~0x1, from BSD's mfi driver. */
} else {
/* WR_OB_DOORBELL_CLEAR(0xFFFFFFFF, instance); */
/* WR_OB_INTR_MASK(~0x80000000, instance); */
}
/* dummy read to force PCI flush */
"outbound_intr_mask = 0x%x", mask));
}
static void
{
/* For now, assume there are no extras needed for Skinny support. */
/* dummy read to force PCI flush */
#ifdef lint
#endif
}
static int
{
/* check if it is our interrupt */
/*
* NOTE: Some drivers call out SKINNY here, but the return is the same
* for SKINNY and 2108.
*/
if (!(status & MFI_REPLY_2108_MESSAGE_INTR)) {
}
}
if (ret == DDI_INTR_UNCLAIMED) {
return (ret);
}
/*
* Clear the interrupt by writing back the same value.
* Another case where SKINNY is slightly different.
*/
} else {
}
/* dummy READ */
return (ret);
}
/*
* Marks HBA as bad. This will be called either when an
* IO packet times out even after 3 FW resets
* or FW is found to be fault even after 3 continuous resets.
*/
static int
{
return (DDI_FAILURE);
"Writing to doorbell with MFI_STOP_ADP "));
(void) mrsas_complete_pending_cmds(instance);
return (DDI_SUCCESS);
}
static int
{
"no more resets as HBA has been marked dead ");
return (DDI_FAILURE);
}
"flag set, time %llx", gethrtime()));
WR_IB_WRITE_SEQ(0, instance);
"to write sequence register\n"));
while (!(status & DIAG_WRITE_ENABLE)) {
if (retry++ == 100) {
"mrsas_reset_ppc: DRWE bit "
"check retry count %d", retry);
return (DDI_FAILURE);
}
}
while (status & DIAG_RESET_ADAPTER) {
if (retry++ == 100) {
"RESET FAILED. KILL adapter called.");
(void) mrsas_kill_adapter(instance);
return (DDI_FAILURE);
}
}
"Calling mfi_state_transition_to_ready"));
/* Mark HBA as bad, if FW is fault after 3 continuous resets */
debug_fw_faults_after_ocr_g == 1) {
#ifdef OCRDEBUG
"mrsas_reset_ppc :before fake: FW is not ready "
"FW state = 0x%x", fw_state));
if (debug_fw_faults_after_ocr_g == 1)
#endif
"FW state = 0x%x", fw_state));
if (fw_state == MFI_STATE_FAULT) {
/* increment the count */
< MAX_FW_RESET_COUNT) {
"mrsas_reset_ppc: "
"FW is in fault after OCR count %d "
"Retry Reset",
goto retry_reset;
} else {
"mrsas_reset_ppc: "
"Max Reset Count exceeded >%d"
"Mark HBA as bad, KILL adapter",
(void) mrsas_kill_adapter(instance);
return (DDI_FAILURE);
}
}
}
/* reset the counter as FW is up after OCR */
" after resetting produconsumer chck indexs:"
"Calling mrsas_issue_init_mfi"));
(void) mrsas_issue_init_mfi(instance);
"mrsas_issue_init_mfi Done"));
"Calling mrsas_print_pending_cmd\n"));
(void) mrsas_print_pending_cmds(instance);
"mrsas_print_pending_cmd done\n"));
instance->fw_outstanding = 0;
"Calling mrsas_issue_pending_cmds"));
(void) mrsas_issue_pending_cmds(instance);
"issue_pending_cmds done.\n"));
"Calling aen registration"));
"adpterresetinprogress flag unset"));
return (DDI_SUCCESS);
}
/*
* FMA functions.
*/
int
{
DDI_SUCCESS) {
}
ret = DDI_FAILURE;
}
!= DDI_SUCCESS) {
}
ret = DDI_FAILURE;
}
DDI_SUCCESS) {
}
ret = DDI_FAILURE;
}
}
ret = DDI_FAILURE;
}
return (ret);
}
/*ARGSUSED*/
static int
{
/*
* as the driver can always deal with an error in any dma or
* access handle, we can just return the fme_status value.
*/
return (err->fme_status);
}
static void
{
/* Need to change iblock to priority for new MSI intr */
/* Only register with IO Fault Services if we have some capability */
if (instance->fm_capabilities) {
/* Adjust access and dma attributes for FMA */
/*
* Register capabilities with IO Fault Services.
* fm_capabilities will be updated to indicate
* capabilities actually supported (not requested.)
*/
/*
* Initialize pci ereport capabilities if ereport
* capable (should always be.)
*/
}
/*
* Register error callback if error callback capable.
*/
mrsas_fm_error_cb, (void*) instance);
}
} else {
}
}
static void
{
/* Only unregister FMA capabilities if registered */
if (instance->fm_capabilities) {
/*
* Un-register error callback if error callback capable.
*/
}
/*
* Release any resources allocated by pci_ereport_setup()
*/
}
/* Unregister from IO Fault Services */
/* Adjust access and dma attributes for FMA */
}
}
int
{
return (DDI_FAILURE);
}
return (de.fme_status);
}
int
{
return (DDI_FAILURE);
}
return (de.fme_status);
}
void
{
}
}
static int
{
intr_type));
/* Get number of interrupts */
return (DDI_FAILURE);
}
/* Get number of available interrupts */
return (DDI_FAILURE);
}
/* Only one interrupt routine. So limit the count to 1 */
if (count > 1) {
count = 1;
}
/*
* Allocate an array of interrupt handlers. Currently we support
* only one interrupt. The framework can be extended later.
*/
KM_SLEEP);
(intr_type == DDI_INTR_TYPE_MSIX)) ?
/* Allocate interrupt */
"avail = %d", avail));
goto mrsas_free_htable;
}
}
/*
* Get the priority of the interrupt allocated.
*/
"get priority call failed"));
goto mrsas_free_handles;
}
/*
* Test for high level mutex. we don't support them.
*/
"High level interrupts not supported."));
goto mrsas_free_handles;
}
/* Call ddi_intr_add_handler() */
for (i = 0; i < actual; i++) {
if (ret != DDI_SUCCESS) {
"failed %d", ret));
goto mrsas_free_handles;
}
}
ret));
goto mrsas_free_handlers;
}
} else {
"%d", i));
}
}
return (DDI_SUCCESS);
for (i = 0; i < actual; i++)
for (i = 0; i < actual; i++)
instance->intr_htable_size = 0;
return (DDI_FAILURE);
}
static void
{
int i;
/* Disable all interrupts first */
} else {
}
}
/* Remove all the handlers */
}
instance->intr_htable_size = 0;
}
static int
{
int config;
return (NDI_FAILURE);
}
/* Hold nexus during bus_config */
switch (op) {
case BUS_CONFIG_ONE: {
rval = NDI_FAILURE;
break;
}
ptr++;
rval = NDI_FAILURE;
break;
}
if (lun == 0) {
#ifdef PDSUPPORT
#endif
} else {
rval = NDI_FAILURE;
}
break;
}
case BUS_CONFIG_DRIVER:
case BUS_CONFIG_ALL: {
rval = NDI_SUCCESS;
break;
}
}
if (rval == NDI_SUCCESS) {
}
rval));
return (rval);
}
static int
{
}
#ifdef PDSUPPORT
/* Config PD devices connected to the card */
}
}
#endif
rval = NDI_SUCCESS;
return (rval);
}
static int
{
char *addr;
long num;
/* Parse dev name and address */
addr = "";
for (p = devbuf; *p != '\0'; p++) {
if (*p == '@') {
addr = p + 1;
*p = '\0';
} else if (*p == ':') {
*p = '\0';
break;
}
}
/* Parse target and lun */
if (*p == ',') {
lp = p + 1;
*p = '\0';
break;
}
}
return (DDI_FAILURE); /* Can declare this as constant */
}
}
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS); /* Success case */
}
static int
{
int rval;
if (ldip) {
}
"mr_sas: DELETING STALE ENTRY rval = %d "
return (NDI_FAILURE);
}
return (NDI_SUCCESS);
}
else
rval = NDI_FAILURE;
/* sd_unprobe is blank now. Free buffer manually */
}
rval));
return (rval);
}
int
{
int ncompatible = 0;
char *childname;
int rval;
rval = NDI_FAILURE;
goto finish;
}
/* Create a dev node */
"mr_sas_config_scsi_device: ndi_devi_alloc rval = %x", rval));
if (rval == NDI_SUCCESS) {
rval = NDI_FAILURE;
goto finish;
}
rval = NDI_FAILURE;
goto finish;
}
rval = NDI_FAILURE;
goto finish;
}
if (rval != NDI_SUCCESS) {
(void) ndi_devi_free(ldip);
} else {
}
}
if (dipp) {
}
"mr_sas: config_scsi_device rval = %d t%dL%d",
return (rval);
}
/*ARGSUSED*/
int
{
"mrsas_service_evt called for t%dl%d event = %d",
return (ENOMEM);
}
DDI_SUCCESS) {
"mr_sas: Event task failed for t%dl%d event = %d",
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
{
int circ1 = 0;
char *devname;
" tgt %d lun %d event %d",
#ifdef PDSUPPORT
} else {
#endif
}
case MRSAS_EVT_CONFIG_TGT:
0, NULL);
#ifdef PDSUPPORT
(void) mrsas_tbolt_config_pd(instance,
1, NULL);
#endif
}
"mr_sas: EVT_CONFIG_TGT called:"
" for tgt %d lun %d event %d",
} else {
"mr_sas: EVT_CONFIG_TGT dip != NULL:"
" for tgt %d lun %d event %d",
}
break;
case MRSAS_EVT_UNCONFIG_TGT:
if (dip) {
if (i_ddi_devi_attached(dip)) {
}
"mr_sas: EVT_UNCONFIG_TGT called:"
" for tgt %d lun %d event %d",
} else {
"mr_sas: EVT_UNCONFIG_TGT dip == NULL:"
" for tgt %d lun %d event %d",
}
break;
}
}
int
{
/* ADD pkt statistics as Command failed. */
return (NULL);
}
switch (page_code) {
case 0x3: {
(uchar_t)(sizeof (struct mode_format));
break;
}
case 0x4: {
(uchar_t)(sizeof (struct mode_geometry));
break;
}
default:
break;
}
return (NULL);
}