megaraid_sas.c revision 837c1ac4e72b7d86278cca88b1075af557f7d161
/*
* megaraid_sas.c: source for mega_sas driver
*
* MegaRAID device driver for SAS controllers
* Copyright (c) 2005-2008, LSI Logic Corporation.
* All rights reserved.
*
* Version:
* Author:
* Rajesh Prabhakaran<Rajesh.Prabhakaran@lsil.com>
* Seokmann Ju
*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "megaraid_sas.h"
/*
* FMA header files
*/
/*
* Local static data
*/
static void *megasas_state = NULL;
static int debug_level_g = CL_ANN;
#pragma weak scsi_hba_open
#pragma weak scsi_hba_close
#pragma weak scsi_hba_ioctl
static ddi_dma_attr_t megasas_generic_dma_attr = {
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 */
MEGASAS_MAX_SGE_CNT, /* dma_attr_sglen */
512, /* granularity of device */
0 /* bus specific DMA flags */
};
/*
* cb_ops contains base level routines
*/
static struct cb_ops megasas_cb_ops = {
megasas_open, /* open */
megasas_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
megasas_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
*/
static struct dev_ops megasas_ops = {
DEVO_REV, /* rev, */
0, /* refcnt */
megasas_getinfo, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
megasas_attach, /* attach */
megasas_detach, /* detach */
megasas_reset, /* reset */
&megasas_cb_ops, /* char/block ops */
NULL, /* bus ops */
NULL, /* power */
ddi_quiesce_not_supported, /* devo_quiesce */
};
char _depends_on[] = "misc/scsi";
&mod_driverops, /* module type - driver */
&megasas_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
MODREV_1, /* ml_rev - must be MODREV_1 */
&modldrv, /* ml_linkage */
NULL /* end of driver linkage */
};
static struct ddi_device_acc_attr endian_attr = {
};
/*
* ************************************************************************** *
* *
* 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 megasas_instance), 0);
if (ret != 0) {
return (ret);
}
return (ret);
}
if (ret != 0) {
}
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;
uint8_t added_isr_f = 0;
uint8_t added_soft_isr_f = 0;
uint8_t create_ioc_node_f = 0;
uint8_t tran_alloc_f = 0;
struct megasas_instance *instance;
/* CONSTCOND */
/*
* Since we know that some instantiations of this device can be
* plugged into slave-only SBus slots, check to see whether this is
* one such.
*/
"mega%d: Device in slave-only slot, unused", instance_no));
return (DDI_FAILURE);
}
switch (cmd) {
case DDI_ATTACH:
/* allocate the soft state for the instance */
!= DDI_SUCCESS) {
"mega%d: Failed to allocate soft state",
instance_no));
return (DDI_FAILURE);
}
"mega%d: Bad soft state", instance_no));
return (DDI_FAILURE);
}
sizeof (struct megasas_instance));
sizeof (struct megasas_func_ptr), KM_SLEEP);
/* Setup the PCI configuration space handles */
DDI_SUCCESS) {
"mega%d: pci config setup failed ",
instance_no));
sizeof (struct megasas_func_ptr));
return (DDI_FAILURE);
}
"megaraid: failed to get registers."));
sizeof (struct megasas_func_ptr));
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\n", instance_no));
} else {
"bus-mastering already set\n", instance_no));
}
/* initialize function pointers */
if ((device_id == PCI_DEVICE_ID_LSI_1078) ||
(device_id == PCI_DEVICE_ID_LSI_1078DE)) {
"1078R/DE detected\n", instance_no));
} else {
"1064/8R detected\n", instance_no));
}
/* Initialize FMA */
"fm-capable", DDI_FM_EREPORT_CAPABLE |
/* setup the mfi based low level driver */
"could not initialize the low level driver"));
goto fail_attach;
}
/*
* Allocate the interrupt blocking cookie.
* It represents the information the framework
* needs to block interrupts. This cookie will
* be used by the locks shared accross our ISR.
* These locks must be initialized before we
* register our ISR.
* ddi_add_intr(9F)
*/
if (ddi_get_iblock_cookie(dip, 0,
goto fail_attach;
}
goto fail_attach;
}
/*
* Initialize the driver mutexes common to
*/
if (ddi_intr_hilevel(dip, 0)) {
"cmd_pool_mtx", MUTEX_DRIVER,
"cmd_pend_mtx", MUTEX_DRIVER,
} else {
/*
* Initialize the driver mutexes
* specific to soft-isr
*/
"cmd_pool_mtx", MUTEX_DRIVER,
"cmd_pend_mtx", MUTEX_DRIVER,
}
"completed_pool_mtx", MUTEX_DRIVER,
/* Register our isr. */
" ISR did not register"));
goto fail_attach;
}
added_isr_f = 1;
/* Register our soft-isr for highlevel interrupts. */
DDI_SUCCESS) {
" Software ISR did not register"));
goto fail_attach;
}
added_soft_isr_f = 1;
}
/* Allocate a transport structure */
"scsi_hba_tran_alloc failed"));
goto fail_attach;
}
tran_alloc_f = 1;
/* Attach this instance of the hba */
!= DDI_SUCCESS) {
"scsi_hba_attach failed\n"));
goto fail_attach;
}
/* create devctl node for cfgadm command */
DDI_NT_SCSI_NEXUS, 0) == DDI_FAILURE) {
"megaraid: failed to create devctl node."));
goto fail_attach;
}
create_devctl_node_f = 1;
/* create scsi node for cfgadm command */
DDI_NT_SCSI_ATTACHMENT_POINT, 0) ==
DDI_FAILURE) {
"megaraid: failed to create scsi node."));
goto fail_attach;
}
create_scsi_node_f = 1;
/*
* Create a node for applications
* for issuing ioctl to the driver.
*/
DDI_PSEUDO, 0) == DDI_FAILURE) {
"megaraid: failed to create ioctl node."));
goto fail_attach;
}
create_ioc_node_f = 1;
/* enable interrupt */
/* initiate AEN */
if (start_mfi_aen(instance)) {
"megaraid: failed to initiate AEN."));
goto fail_initiate_aen;
}
"AEN started for instance %d.", instance_no));
/* Finally! We are on the air. */
DDI_SUCCESS) {
goto fail_attach;
}
DDI_SUCCESS) {
goto fail_attach;
}
break;
case DDI_PM_RESUME:
"megasas: DDI_PM_RESUME"));
break;
case DDI_RESUME:
"megasas: DDI_RESUME"));
break;
default:
"megasas: invalid attach cmd=%x", cmd));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
if (create_devctl_node_f) {
}
if (create_scsi_node_f) {
}
if (create_ioc_node_f) {
}
if (tran_alloc_f) {
}
if (added_soft_isr_f) {
}
if (added_isr_f) {
}
"megasas: return failure from mega_attach\n"));
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;
struct megasas_instance *instance;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
instance = (struct megasas_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;
struct megasas_instance *instance;
/* CONSTCOND */
if (!instance) {
"megasas:%d could not get instance in detach",
instance_no));
return (DDI_FAILURE);
}
"megasas%d: detaching device 0x%4x:0x%4x:0x%4x:0x%4x\n",
switch (cmd) {
case DDI_DETACH:
"megasas_detach: DDI_DETACH\n"));
"megasas:%d failed to detach",
instance_no));
return (DDI_FAILURE);
}
"failed to abort prevous AEN command\n"));
return (DDI_FAILURE);
}
}
sizeof (struct megasas_func_ptr));
break;
case DDI_PM_SUSPEND:
"megasas_detach: DDI_PM_SUSPEND\n"));
break;
case DDI_SUSPEND:
"megasas_detach: DDI_SUSPEND\n"));
break;
default:
"invalid detach command:0x%x", cmd));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* ************************************************************************** *
* *
* 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 */
"megaraid: Non-root ioctl access tried!"));
return (EPERM);
}
/* Verify we are being opened as a character device */
"megaraid: ioctl node must be a char node\n"));
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;
struct megasas_instance *instance;
struct megasas_ioctl ioctl;
struct megasas_aen aen;
/* invalid minor number */
return (ENXIO);
}
case MEGASAS_IOCTL_FIRMWARE:
sizeof (struct megasas_ioctl), mode)) {
"ERROR IOCTL copyin"));
return (EFAULT);
}
} else {
}
"megasas_ioctl: copy_to_user failed\n"));
rval = 1;
}
break;
case MEGASAS_IOCTL_AEN:
sizeof (struct megasas_aen), mode)) {
"megasas_ioctl: ERROR AEN copyin"));
return (EFAULT);
}
sizeof (struct megasas_aen), mode)) {
"megasas_ioctl: copy_to_user failed\n"));
rval = 1;
}
break;
default:
"scsi_hba_ioctl called, ret = %x.", rval));
}
return (rval);
}
/*
* ************************************************************************** *
* *
* common entry points - for block driver types *
* *
* ************************************************************************** *
*/
/*
* reset - TBD
* @dip:
* @cmd:
*
* TBD
*/
/*ARGSUSED*/
static int
{
int instance_no;
struct megasas_instance *instance;
if (!instance) {
"megaraid:%d could not get adapter in reset",
instance_no));
return (DDI_FAILURE);
}
instance_no));
return (DDI_SUCCESS);
}
/*
* ************************************************************************** *
* *
* 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
{
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 *
{
struct megasas_instance *instance;
/* 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) == -1) {
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
{
struct megasas_cmd *cmd;
/*
* Check if the command is already completed by the mega_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);
}
/* Syncronize the Cmd frame for the controller */
} else {
pkt->pkt_statistics = 0;
switch (hdr->cmd_status) {
case MFI_STAT_OK:
break;
pkt->pkt_statistics = 0;
break;
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
{
/* aborting 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)) {
return (DDI_FAILURE);
} else {
return (DDI_SUCCESS);
}
}
/*
* tran_bus_reset - reset the SCSI bus
* @dip:
* @level:
*
* The tran_bus_reset() vector in the scsi_hba_tran structure should be
* initialized during the HBA driver's attach(). The vector should point to
* an HBA entry point that is to be called when a user initiates a bus reset.
* Implementation is hardware specific. If the HBA driver cannot reset the
* SCSI bus without affecting the targets, the driver should fail RESET_BUS
* or not initialize this vector.
*/
/*ARGSUSED*/
static int
{
if (wait_for_outstanding(instance)) {
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 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
{
int rval = 1;
/* 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
{
/*
* following 'ddi_dma_sync()' API call
* already called for each I/O in the ISR
*/
#if 0
int i;
}
#endif
}
/*ARGSUSED*/
static int
{
return (1);
}
/*ARGSUSED*/
static int
{
return (1);
}
/*
* megasas_isr(caddr_t)
*
* The Interrupt Service Routine
*
* Collect status for all completed commands and do callback
*
*/
static uint_t
{
int need_softintr;
struct megasas_cmd *cmd;
return (DDI_INTR_UNCLAIMED);
}
0, 0, DDI_DMA_SYNC_FORCPU);
!= DDI_SUCCESS) {
return (DDI_INTR_UNCLAIMED);
}
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) megasas_softintr(instance);
}
return (DDI_INTR_CLAIMED);
}
/*
* ************************************************************************** *
* *
* libraries *
* *
* ************************************************************************** *
*/
/*
* get_mfi_pkt : Get a command from the free pool
*/
static struct megasas_cmd *
{
if (!mlist_empty(head)) {
}
return (cmd);
}
/*
* return_mfi_pkt : Return a cmd to free command pool
*/
static void
{
}
/*
* destroy_mfi_frame_pool
*/
static void
{
int i;
struct megasas_cmd *cmd;
/* return all frames to pool */
for (i = 0; i < max_cmd; i++) {
}
}
/*
* create_mfi_frame_pool
*/
static int
{
int i = 0;
int cookie_cnt;
struct megasas_cmd *cmd;
sge_sz = sizeof (struct megasas_sge64);
/* calculated the number of 64byte frames required for SGL */
while (i < max_cmd) {
"create_mfi_frame_pool: could not alloc."));
return (DDI_FAILURE);
}
"megasas: pci_pool_alloc failed \n"));
return (-ENOMEM);
}
i++;
}
return (DDI_SUCCESS);
}
/*
* free_additional_dma_buffer
*/
static void
{
(void) mega_free_dma_obj(instance,
}
(void) mega_free_dma_obj(instance,
}
}
/*
* alloc_additional_dma_buffer
*/
static int
{
/* max cmds plus 1 + producer & consumer */
0xFFFFFFFFU;
!= 1) {
return (DDI_FAILURE);
}
(reply_q_sz + 8);
/* allocate evt_detail */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
sizeof (struct megasas_evt_detail));
return (DDI_SUCCESS);
}
/*
* free_space_for_mfi
*/
static void
{
int i;
/* already freed */
return;
}
/* first free the MFI frame pool */
/* free all the commands in the cmd_list */
for (i = 0; i < instance->max_fw_cmds; i++) {
sizeof (struct megasas_cmd));
}
/* free the cmd_list buffer itself */
sizeof (struct megasas_cmd *) * max_cmd);
}
/*
* alloc_space_for_mfi
*/
static int
{
int i;
struct megasas_cmd *cmd;
/*
* instance->cmd_list is an array of struct megasas_cmd pointers.
* Allocate the dynamic array first and then allocate individual
* commands.
*/
for (i = 0; i < max_cmd; i++) {
KM_SLEEP);
}
/* add all the commands to command pool (instance->cmd_pool) */
for (i = 0; i < max_cmd; i++) {
}
/* create a frame pool and assign one frame to each cmd */
if (create_mfi_frame_pool(instance)) {
return (DDI_FAILURE);
}
/* create a frame pool and assign one frame to each cmd */
if (alloc_additional_dma_buffer(instance)) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* get_ctrl_info
*/
static int
struct megasas_ctrl_info *ctrl_info)
{
int ret = 0;
struct megasas_cmd *cmd;
struct megasas_dcmd_frame *dcmd;
struct megasas_ctrl_info *ci;
if (!cmd) {
"Failed to get a cmd for ctrl info\n"));
return (DDI_FAILURE);
}
if (!ci) {
"Failed to alloc mem for ctrl info\n"));
return (DDI_FAILURE);
}
/* for( i = 0; i < DCMD_MBOX_SZ; i++ ) dcmd->mbox.b[i] = 0; */
ret = 0;
} else {
ret = -1;
}
ret = -1;
}
return (ret);
}
/*
* abort_aen_cmd
*/
static int
struct megasas_cmd *cmd_to_abort)
{
int ret = 0;
struct megasas_cmd *cmd;
struct megasas_abort_frame *abort_fr;
if (!cmd) {
"Failed to get a cmd for ctrl info\n"));
return (DDI_FAILURE);
}
/* prepare and issue the abort frame */
"abort_aen_cmd: issue_cmd_in_sync_mode failed\n"));
ret = -1;
} else {
ret = 0;
}
return (ret);
}
/*
* init_mfi
*/
static int
{
struct megasas_cmd *cmd;
struct megasas_ctrl_info ctrl_info;
struct megasas_init_frame *init_frame;
struct megasas_init_queue_info *initq_info;
return (DDI_FAILURE);
}
if (reglength > DEFAULT_MFI_MEM_SZ) {
"mega: register length to map is 0x%lx bytes", reglength));
}
"megaraid: couldn't map control registers"));
goto fail_mfi_reg_setup;
}
/* we expect the FW state to be READY */
goto fail_ready_state;
}
/* 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
*/
/* create a pool of commands */
if (alloc_space_for_mfi(instance))
goto fail_alloc_fw_space;
/* disable interrupt for initial preparation */
/*
* 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
*/
initq_info = (struct megasas_init_queue_info *)
((unsigned long)init_frame + 64);
initq_info->init_flags = 0;
init_frame->flags = 0;
/* issue the init frame in polled mode */
goto fail_fw_init;
}
goto fail_fw_init;
}
/* gather misc FW related information */
} else {
PAGESIZE / 512;
}
goto fail_fw_init;
}
return (0);
return (DDI_FAILURE);
}
/*
* mfi_state_transition_to_ready : Move the FW to READY state
*
* @reg_set : MFI register set
*/
static 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:
"megasas: FW in FAULT state!!"));
return (-ENODEV);
case MFI_STATE_WAIT_HANDSHAKE:
/* set the CLR bit in IMR0 */
"megasas: 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); */
max_wait = 2;
break;
/* set the CLR bit in IMR0 */
"megasas: FW state boot message pending"));
/*
* PCI_Hot Plug: MFI F/W requires
* (MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG)
* to be set
*/
max_wait = 10;
break;
case MFI_STATE_OPERATIONAL:
/* bring it to READY state; assuming max wait 2 secs */
"megasas: 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); */
max_wait = 10;
break;
case MFI_STATE_UNDEFINED:
/* this state should not last for more than 2 seconds */
max_wait = 2;
break;
case MFI_STATE_BB_INIT:
max_wait = 2;
break;
case MFI_STATE_FW_INIT:
max_wait = 2;
break;
case MFI_STATE_DEVICE_SCAN:
max_wait = 10;
break;
default:
"megasas: Unknown state 0x%x\n", 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; */
fw_state =
} else {
break;
}
}
/* return error if fw_state hasn't changed after max_wait */
"FW state hasn't changed in %d secs\n", max_wait));
return (-ENODEV);
}
};
"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 (-ENODEV);
}
return (0);
}
/*
* get_seq_num
*/
static int
struct megasas_evt_log_info *eli)
{
int ret = 0;
struct megasas_cmd *cmd;
struct megasas_dcmd_frame *dcmd;
if (!cmd) {
return (-ENOMEM);
}
/* allocate the data transfer buffer */
"get_seq_num: could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
sizeof (struct megasas_evt_log_info));
dcmd->cmd_status = 0;
"failed to issue MR_DCMD_CTRL_EVENT_GET_INFO\n");
ret = -1;
} else {
/* copy the data back into callers buffer */
sizeof (struct megasas_evt_log_info));
ret = 0;
}
ret = -1;
ret = -1;
}
return (ret);
}
/*
* start_mfi_aen
*/
static int
{
int ret = 0;
struct megasas_evt_log_info eli;
/* get the latest sequence number from FW */
return (-1);
}
/* register AEN with FW for latest sequence number plus 1 */
if (ret) {
return (-1);
}
return (ret);
}
/*
* flush_cache
*/
static void
{
struct megasas_cmd *cmd;
struct megasas_dcmd_frame *dcmd;
return;
dcmd->data_xfer_len = 0;
"flush_cache: failed to issue MFI_DCMD_CTRL_CACHE_FLUSH\n");
}
}
/*
* service_mfi_aen- Completes an AEN command
* @instance: Adapter soft state
* @cmd: Command to be completed
*
*/
static void
{
struct megasas_evt_detail *evt_detail =
cmd->cmd_status = 0;
}
/*
* log the MFI AEN event to the sysevent queue so that
* application will get noticed
*/
"mega%d: Failed to log AEN event", instance_no));
}
seq_num++;
sizeof (struct megasas_evt_detail));
/* 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
struct megasas_cmd *cmd)
{
cmd->cmd_status = 0;
}
}
/*
* megasas_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
{
struct megasas_cmd *cmd;
struct megasas_header *hdr;
struct scsi_arq_status *arqstat;
return (DDI_INTR_UNCLAIMED);
}
/* perform all callbacks first, before releasing the SCBs */
/* syncronize the Cmd frame for the controller */
0, 0, DDI_DMA_SYNC_FORCPU);
DDI_SUCCESS) {
return (DDI_INTR_UNCLAIMED);
}
/* 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",
struct scsi_inquiry *inq;
if (acmd->cmd_dmacount != 0) {
inq = (struct scsi_inquiry *)
/* don't expose physical drives to OS */
} else if ((hdr->cmd_status ==
DTYPE_DIRECT) {
/* for physical disk */
hdr->cmd_status =
}
}
}
switch (hdr->cmd_status) {
case MFI_STAT_OK:
break;
/* SJ - these are not correct way */
break;
(CE_WARN, "Initialization in Progress"));
break;
((struct scsi_status *)
(CE_WARN, "TEST_UNIT_READY fail"));
} else {
arqstat->sts_rqpkt_resid = 0;
&(arqstat->sts_sensedata),
acmd->cmd_scblen -
offsetof(struct scsi_arq_status,
}
break;
case MFI_STAT_LD_OFFLINE:
"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 */
"megasas_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:
}
}
break;
}
}
instance->softint_running = 0;
return (DDI_INTR_CLAIMED);
}
/*
* mega_alloc_dma_obj
*
* Allocate the memory and other resources for an dma object.
*/
static int
{
int i;
struct ddi_device_acc_attr tmp_endian_attr;
if (i != DDI_SUCCESS) {
switch (i) {
case DDI_DMA_BADATTR :
"Failed ddi_dma_alloc_handle- Bad atrib"));
break;
case DDI_DMA_NORESOURCES :
"Failed ddi_dma_alloc_handle- No Resources"));
break;
default :
"Failed ddi_dma_alloc_handle :unknown %d", i));
break;
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (cookie_cnt);
}
/*
* mega_free_dma_obj(struct megasas_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 mega_alloc_dma_obj()
*/
static int
{
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* megasas_dma_alloc(instance_t *, struct scsi_pkt *, struct buf *,
* int, int (*)())
*
* Allocate dma resources for a new scsi command
*/
static int
{
int dma_flags;
int i;
} else {
}
if (flags & PKT_CONSISTENT) {
}
if (flags & PKT_DMA_PARTIAL) {
}
switch (i) {
case DDI_DMA_BADATTR:
return (-1);
case DDI_DMA_NORESOURCES:
return (-1);
default:
"0x%x impossible\n", i));
return (-1);
}
}
switch (i) {
case DDI_DMA_PARTIAL_MAP:
if ((dma_flags & DDI_DMA_PARTIAL) == 0) {
"DDI_DMA_PARTIAL_MAP impossible\n"));
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 (0);
case DDI_DMA_NORESOURCES:
break;
case DDI_DMA_NOMAPPING:
break;
case DDI_DMA_TOOBIG:
break;
case DDI_DMA_INUSE:
" DDI_DMA_INUSE impossible\n"));
break;
default:
"0x%x impossible\n", i));
break;
}
return (-1);
}
/*
* megasas_dma_move(struct megasas_instance *, struct scsi_pkt *, struct buf *)
*
* move dma resources to next dma window
*
*/
static int
{
int i = 0;
/*
* If there are no more cookies remaining in this window,
* must move to the next window first.
*/
return (0);
}
/* at last window, cannot move */
return (-1);
}
DDI_FAILURE) {
return (-1);
}
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 (0);
}
/*
* build_cmd
*/
static struct megasas_cmd *
{
uint32_t i;
struct megasas_cmd *cmd;
struct megasas_sge64 *mfi_sgl;
struct megasas_pthru_frame *pthru;
struct megasas_io_frame *ldio;
/* find out if this is logical or physical drive command. */
*cmd_done = 0;
/* get the command packet */
return (NULL);
}
/* lets get the command directions */
}
}
} else {
}
flags |= MFI_FRAME_SGL64;
/*
* case SCMD_SYNCHRONIZE_CACHE:
* flush_cache(instance);
* return_mfi_pkt(instance, cmd);
* *cmd_done = 1;
*
* return (NULL);
*/
case SCMD_READ:
case SCMD_WRITE:
case SCMD_READ_G1:
case SCMD_WRITE_G1:
/*
* preare the Logical IO frame:
* 2nd bit is zero for all read cmds
*/
ldio->reserved_0 = 0;
/* Initialize sense Information */
ldio->sense_buf_phys_addr_hi = 0;
ldio->start_lba_hi = 0;
<< 16));
}
break;
}
default:
/* prepare the DCDB frame */
pthru->sense_buf_phys_addr_hi = 0;
break;
}
#ifdef lint
#endif
/* bzero(mfi_sgl, sizeof (struct megasas_sge64) * MAX_SGL); */
/* prepare the scatter-gather list for the firmware */
}
}
return (cmd);
}
/*
* wait_for_outstanding - Wait for all outstanding cmds
* @instance: Adapter soft state
*
* This function waits for upto MEGASAS_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;
uint32_t kphys_addr = 0;
struct megasas_pthru_frame *kpthru;
struct megasas_pthru_frame *pthru;
if (model == DDI_MODEL_ILP32) {
/* SJ! - ubuf needs to be virtual address. */
} else {
#ifdef _ILP32
/* SJ! - ubuf needs to be virtual address. */
#else
/* SJ! - ubuf needs to be virtual address. */
#endif
}
if (xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
"copy from user space failed\n"));
return (1);
}
}
}
pthru->sense_buf_phys_addr_hi = 0;
/* pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; */
pthru->sense_buf_phys_addr_lo = 0;
"issue_mfi_pthru: fw_ioctl failed\n"));
} else {
"copy to user space failed\n"));
return (1);
}
}
}
if (xferlen) {
/* free kernel buffer */
return (1);
}
return (0);
}
/*
* issue_mfi_dcmd
*/
static int
{
void *ubuf;
uint32_t kphys_addr = 0;
struct megasas_dcmd_frame *kdcmd;
struct megasas_dcmd_frame *dcmd;
if (model == DDI_MODEL_ILP32) {
/* SJ! - ubuf needs to be virtual address. */
}
else
{
#ifdef _ILP32
/* SJ! - ubuf needs to be virtual address. */
#else
/* SJ! - ubuf needs to be virtual address. */
#endif
}
if (xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
"copy from user space failed\n"));
return (1);
}
}
}
} else {
"copy to user space failed\n"));
return (1);
}
}
}
if (xferlen) {
/* free kernel buffer */
return (1);
}
return (0);
}
/*
* issue_mfi_smp
*/
static int
{
void *request_ubuf;
void *response_ubuf;
uint32_t request_xferlen = 0;
uint32_t response_xferlen = 0;
struct megasas_smp_frame *ksmp;
struct megasas_smp_frame *smp;
struct megasas_sge32 *sge32;
#ifndef _ILP32
struct megasas_sge64 *sge64;
#endif
if (model == DDI_MODEL_ILP32) {
"response_xferlen = %x, request_xferlen = %x",
/* SJ! - ubuf needs to be virtual address. */
"response_ubuf = %p, request_ubuf = %p",
} else {
#ifdef _ILP32
"response_xferlen = %x, request_xferlen = %x",
/* SJ! - ubuf needs to be virtual address. */
"response_ubuf = %p, request_ubuf = %p",
#else
/* SJ! - ubuf needs to be virtual address. */
#endif
}
if (request_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
request_xferlen, mode)) {
"copy from user space failed\n"));
return (1);
}
}
if (response_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
response_xferlen, mode)) {
"copy from user space failed\n"));
return (1);
}
}
/* smp->context = ksmp->context; */
sizeof (uint64_t));
if (model == DDI_MODEL_ILP32) {
"handle_drv_ioctl: DDI_MODEL_ILP32"));
} else {
#ifdef _ILP32
"handle_drv_ioctl: DDI_MODEL_ILP32"));
#else
"issue_mfi_smp: DDI_MODEL_LP64"));
#endif
}
"smp->response_xferlen = %d, smp->request_xferlen = %d "
smp->data_xfer_len));
"issue_mfi_smp: fw_ioctl failed\n"));
} else {
"issue_mfi_smp: copy to user space\n"));
if (request_xferlen) {
request_xferlen, mode)) {
"copy to user space failed\n"));
return (1);
}
}
if (response_xferlen) {
response_xferlen, mode)) {
"copy to user space failed\n"));
return (1);
}
}
}
smp->cmd_status));
if (request_xferlen) {
/* free kernel buffer */
return (1);
}
if (response_xferlen) {
/* free kernel buffer */
return (1);
}
return (0);
}
/*
* issue_mfi_stp
*/
static int
{
void *fis_ubuf;
void *data_ubuf;
uint32_t fis_xferlen = 0;
uint32_t data_xferlen = 0;
struct megasas_stp_frame *kstp;
struct megasas_stp_frame *stp;
if (model == DDI_MODEL_ILP32) {
/* SJ! - ubuf needs to be virtual address. */
}
else
{
#ifdef _ILP32
/* SJ! - ubuf needs to be virtual address. */
#else
/* SJ! - ubuf needs to be virtual address. */
#endif
}
if (fis_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
fis_xferlen, mode)) {
"copy from user space failed\n"));
return (1);
}
}
if (data_xferlen) {
/* means IOCTL requires DMA */
/* allocate the data transfer buffer */
/* allocate kernel buffer for DMA */
"could not data transfer buffer alloc."));
return (DDI_FAILURE);
}
/* If IOCTL requires DMA WRITE, do ddi_copyin IOCTL data copy */
data_xferlen, mode)) {
"copy from user space failed\n"));
return (1);
}
}
/* stp->context = kstp->context; */
} else {
if (fis_xferlen) {
fis_xferlen, mode)) {
"copy to user space failed\n"));
return (1);
}
}
if (data_xferlen) {
data_xferlen, mode)) {
"copy to user space failed\n"));
return (1);
}
}
}
if (fis_xferlen) {
/* free kernel buffer */
return (1);
}
if (data_xferlen) {
/* free kernel buffer */
return (1);
}
return (0);
}
/*
* fill_up_drv_ver
*/
static void
{
}
/*
* handle_drv_ioctl
*/
static int
int mode)
{
int i;
int rval = 0;
void *ubuf;
struct megasas_dcmd_frame *kdcmd;
struct megasas_drv_ver dv;
struct megasas_pci_information pi;
if (model == DDI_MODEL_ILP32) {
"handle_drv_ioctl: DDI_MODEL_ILP32"));
/* SJ! - ubuf needs to be virtual address. */
} else {
#ifdef _ILP32
"handle_drv_ioctl: DDI_MODEL_ILP32"));
/* SJ! - ubuf needs to be virtual address. */
#else
"handle_drv_ioctl: DDI_MODEL_LP64"));
/* SJ! - ubuf needs to be virtual address. */
#endif
}
"MR_DRIVER_IOCTL_DRIVER_VERSION"));
"MR_DRIVER_IOCTL_DRIVER_VERSION : "
"copy to user space failed\n"));
rval = 1;
} else {
kdcmd->cmd_status = 0;
}
break;
"MR_DRIVER_IOCTL_PCI_INFORMAITON"));
"MR_DRIVER_IOCTL_PCI_INFORMATION : "
"ddi_prop_look_int_array failed\n"));
rval = 1;
} else {
ddi_prop_free((void *)props);
}
for (i = 0; i < (sizeof (struct megasas_pci_information) -
i++) {
pci_conf_buf[i] =
}
"MR_DRIVER_IOCTL_PCI_INFORMATION : "
"copy to user space failed\n"));
rval = 1;
} else {
kdcmd->cmd_status = 0;
}
break;
default:
"invalid driver specific IOCTL opcode = 0x%x",
rval = 1;
break;
}
return (rval);
}
/*
* handle_mfi_ioctl
*/
static int
int mode)
{
int rval = 0;
struct megasas_header *hdr;
struct megasas_cmd *cmd;
if (!cmd) {
"failed to get a cmd packet\n"));
return (1);
}
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 = 1;
break;
}
rval = 1;
return (rval);
}
/*
* AEN
*/
static int
{
int rval = 0;
return (rval);
}
static int
{
int ret_val;
struct megasas_cmd *cmd;
struct megasas_dcmd_frame *dcmd;
union megasas_evt_class_locale curr_aen;
union megasas_evt_class_locale prev_aen;
/*
* 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
*/
/*
* 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\n"));
return (ret_val);
}
}
} else {
}
if (!cmd)
return (-ENOMEM);
/* for(i = 0; i < DCMD_MBOX_SZ; i++) dcmd->mbox.b[i] = 0; */
sizeof (struct megasas_evt_detail));
/* Prepare DCMD for aen registration */
/*
* 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);
}
static void
{
#define MAX_SCSI_DEVICE_CODE 14
int i;
char inquiry_buf[256] = {0};
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 int
{
return ((int)RD_OB_MSG_0(instance));
}
static int
{
return ((int)RD_OB_SCRATCH_PAD_0(instance));
}
static void
{
/* Issue the command to the FW */
}
static void
{
/* Issue the command to the FW */
}
/*
* issue_cmd_in_sync_mode
*/
static int
struct megasas_cmd *cmd)
{
int i;
}
if (i < (msecs -1)) {
return (0);
} else {
return (1);
}
}
static int
struct megasas_cmd *cmd)
{
int i;
}
if (i < (msecs -1)) {
return (0);
} else {
return (1);
}
}
/*
* issue_cmd_in_poll_mode
*/
static int
struct megasas_cmd *cmd)
{
int i;
struct megasas_header *frame_hdr;
/* issue the frame using inbound queue port */
/* wait for cmd_status to change from 0xFF */
MFI_CMD_STATUS_POLL_MODE); i++) {
}
"cmd polling timed out"));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
struct megasas_cmd *cmd)
{
int i;
struct megasas_header *frame_hdr;
/* issue the frame using inbound queue port */
/* wait for cmd_status to change from 0xFF */
MFI_CMD_STATUS_POLL_MODE); i++) {
}
"cmd polling timed out"));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
{
}
static void
{
/* WR_OB_DOORBELL_CLEAR(0xFFFFFFFF, instance); */
/*
* As 1078DE is same as 1078 chip, the interrupt mask
* remains the same.
*/
/* WR_OB_INTR_MASK(~0x80000000, instance); */
/* dummy read to force PCI flush */
"outbound_intr_mask = 0x%x\n", mask));
}
static void
{
}
static void
{
/* WR_OB_INTR_MASK(0xFFFFFFFF, instance); */
/* dummy read to force PCI flush */
#ifdef lint
#endif
}
static int
{
/* check if it is our interrupt */
if (!(status & MFI_OB_INTR_STATUS_MASK)) {
return (DDI_INTR_UNCLAIMED);
}
/* clear the interrupt by writing back the same value */
return (DDI_INTR_CLAIMED);
}
static int
{
/* check if it is our interrupt */
/*
* As 1078DE is same as 1078 chip, the status field
* remains the same.
*/
if (!(status & MFI_REPLY_1078_MESSAGE_INTR)) {
return (DDI_INTR_UNCLAIMED);
}
/* clear the interrupt by writing back the same value */
/* dummy READ */
return (DDI_INTR_CLAIMED);
}
static int
struct megasas_cmd *cmd)
{
int ret = DDI_SUCCESS;
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.
*/
megasas_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
{
char buf[FM_MAX_CLASS];
}
}