2011-11-04 02:34:52 +00:00
|
|
|
/*-
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* Copyright 1994-2009 The FreeBSD Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT``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 FREEBSD PROJECT 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.
|
|
|
|
*
|
|
|
|
* The views and conclusions contained in the software and documentation
|
|
|
|
* are those of the authors and should not be interpreted as representing
|
|
|
|
* official policies,either expressed or implied, of the FreeBSD Project.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2012-03-30 23:05:48 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
#include "opt_mfi.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/selinfo.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/eventhandler.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <machine/bus.h>
|
2012-03-30 23:05:48 +00:00
|
|
|
#include <sys/sysctl.h>
|
2011-11-04 02:34:52 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <dev/mfi/mfireg.h>
|
|
|
|
#include <dev/mfi/mfi_ioctl.h>
|
|
|
|
#include <dev/mfi/mfivar.h>
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_cmd_tbolt *mfi_tbolt_get_cmd(struct mfi_softc *sc, struct mfi_command *);
|
2011-11-04 02:34:52 +00:00
|
|
|
union mfi_mpi2_request_descriptor *
|
|
|
|
mfi_tbolt_get_request_descriptor(struct mfi_softc *sc, uint16_t index);
|
|
|
|
void mfi_tbolt_complete_cmd(struct mfi_softc *sc);
|
|
|
|
int mfi_tbolt_build_io(struct mfi_softc *sc, struct mfi_command *mfi_cmd,
|
|
|
|
struct mfi_cmd_tbolt *cmd);
|
|
|
|
union mfi_mpi2_request_descriptor *mfi_tbolt_build_mpt_cmd(struct mfi_softc
|
|
|
|
*sc, struct mfi_command *cmd);
|
|
|
|
uint8_t
|
|
|
|
mfi_build_mpt_pass_thru(struct mfi_softc *sc, struct mfi_command *mfi_cmd);
|
|
|
|
union mfi_mpi2_request_descriptor *mfi_build_and_issue_cmd(struct mfi_softc
|
|
|
|
*sc, struct mfi_command *mfi_cmd);
|
|
|
|
void mfi_tbolt_build_ldio(struct mfi_softc *sc, struct mfi_command *mfi_cmd,
|
|
|
|
struct mfi_cmd_tbolt *cmd);
|
|
|
|
static int mfi_tbolt_make_sgl(struct mfi_softc *sc, struct mfi_command
|
|
|
|
*mfi_cmd, pMpi25IeeeSgeChain64_t sgl_ptr, struct mfi_cmd_tbolt *cmd);
|
|
|
|
void
|
|
|
|
map_tbolt_cmd_status(struct mfi_command *mfi_cmd, uint8_t status,
|
|
|
|
uint8_t ext_status);
|
|
|
|
static void mfi_issue_pending_cmds_again (struct mfi_softc *sc);
|
|
|
|
static void mfi_kill_hba (struct mfi_softc *sc);
|
|
|
|
static void mfi_process_fw_state_chg_isr(void *arg);
|
2012-05-04 16:00:39 +00:00
|
|
|
static void mfi_sync_map_complete(struct mfi_command *);
|
|
|
|
static void mfi_queue_map_sync(struct mfi_softc *sc);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
#define MFI_FUSION_ENABLE_INTERRUPT_MASK (0x00000008)
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
extern int mfi_polled_cmd_timeout;
|
|
|
|
static int mfi_fw_reset_test = 0;
|
|
|
|
#ifdef MFI_DEBUG
|
|
|
|
SYSCTL_INT(_hw_mfi, OID_AUTO, fw_reset_test, CTLFLAG_RWTUN, &mfi_fw_reset_test,
|
|
|
|
0, "Force a firmware reset condition");
|
|
|
|
#endif
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
void
|
|
|
|
mfi_tbolt_enable_intr_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
MFI_WRITE4(sc, MFI_OMSK, ~MFI_FUSION_ENABLE_INTERRUPT_MASK);
|
|
|
|
MFI_READ4(sc, MFI_OMSK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mfi_tbolt_disable_intr_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
MFI_WRITE4(sc, MFI_OMSK, 0xFFFFFFFF);
|
|
|
|
MFI_READ4(sc, MFI_OMSK);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
mfi_tbolt_read_fw_status_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
return MFI_READ4(sc, MFI_OSP0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
mfi_tbolt_check_clear_intr_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
int32_t status, mfi_status = 0;
|
|
|
|
|
|
|
|
status = MFI_READ4(sc, MFI_OSTS);
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (status & 1) {
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_WRITE4(sc, MFI_OSTS, status);
|
|
|
|
MFI_READ4(sc, MFI_OSTS);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (status & MFI_STATE_CHANGE_INTERRUPT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_status |= MFI_FIRMWARE_STATE_CHANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mfi_status;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
|
2011-11-04 02:34:52 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
MFI_READ4(sc, MFI_OSTS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_tbolt_issue_cmd_ppc(struct mfi_softc *sc, bus_addr_t bus_add,
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t frame_cnt)
|
|
|
|
{
|
|
|
|
bus_add |= (MFI_REQ_DESCRIPT_FLAGS_MFA
|
|
|
|
<< MFI_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
2012-03-30 23:05:48 +00:00
|
|
|
MFI_WRITE4(sc, MFI_IQPL, (uint32_t)bus_add);
|
|
|
|
MFI_WRITE4(sc, MFI_IQPH, (uint32_t)((uint64_t)bus_add >> 32));
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
/*
|
2011-11-04 02:34:52 +00:00
|
|
|
* mfi_tbolt_adp_reset - For controller reset
|
|
|
|
* @regs: MFI register set
|
|
|
|
*/
|
2012-05-04 16:22:13 +00:00
|
|
|
int
|
|
|
|
mfi_tbolt_adp_reset(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
2012-03-30 23:05:48 +00:00
|
|
|
int retry = 0, i = 0;
|
|
|
|
int HostDiag;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
MFI_WRITE4(sc, MFI_WSR, 0xF);
|
|
|
|
MFI_WRITE4(sc, MFI_WSR, 4);
|
|
|
|
MFI_WRITE4(sc, MFI_WSR, 0xB);
|
|
|
|
MFI_WRITE4(sc, MFI_WSR, 2);
|
|
|
|
MFI_WRITE4(sc, MFI_WSR, 7);
|
|
|
|
MFI_WRITE4(sc, MFI_WSR, 0xD);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
for (i = 0; i < 10000; i++) ;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
HostDiag = (uint32_t)MFI_READ4(sc, MFI_HDR);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
while (!( HostDiag & DIAG_WRITE_ENABLE)) {
|
|
|
|
for (i = 0; i < 1000; i++);
|
|
|
|
HostDiag = (uint32_t)MFI_READ4(sc, MFI_HDR);
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "ADP_RESET_TBOLT: retry time=%d, "
|
|
|
|
"hostdiag=%#x\n", retry, HostDiag);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (retry++ >= 100)
|
|
|
|
return 1;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "ADP_RESET_TBOLT: HostDiag=%#x\n", HostDiag);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
MFI_WRITE4(sc, MFI_HDR, (HostDiag | DIAG_RESET_ADAPTER));
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
for (i=0; i < 10; i++) {
|
|
|
|
for (i = 0; i < 10000; i++);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
HostDiag = (uint32_t)MFI_READ4(sc, MFI_RSR);
|
|
|
|
while (HostDiag & DIAG_RESET_ADAPTER) {
|
|
|
|
for (i = 0; i < 1000; i++) ;
|
|
|
|
HostDiag = (uint32_t)MFI_READ4(sc, MFI_RSR);
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "ADP_RESET_TBOLT: retry time=%d, "
|
|
|
|
"hostdiag=%#x\n", retry, HostDiag);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (retry++ >= 1000)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-05-04 16:22:13 +00:00
|
|
|
* This routine initialize Thunderbolt specific device information
|
2011-11-04 02:34:52 +00:00
|
|
|
*/
|
2012-05-04 16:22:13 +00:00
|
|
|
void
|
|
|
|
mfi_tbolt_init_globals(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
/* Initialize single reply size and Message size */
|
|
|
|
sc->reply_size = MEGASAS_THUNDERBOLT_REPLY_SIZE;
|
|
|
|
sc->raid_io_msg_size = MEGASAS_THUNDERBOLT_NEW_MSG_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculating how many SGEs allowed in a allocated main message
|
|
|
|
* (size of the Message - Raid SCSI IO message size(except SGE))
|
|
|
|
* / size of SGE
|
|
|
|
* (0x100 - (0x90 - 0x10)) / 0x10 = 8
|
|
|
|
*/
|
|
|
|
sc->max_SGEs_in_main_message =
|
|
|
|
(uint8_t)((sc->raid_io_msg_size
|
|
|
|
- (sizeof(struct mfi_mpi2_request_raid_scsi_io)
|
|
|
|
- sizeof(MPI2_SGE_IO_UNION))) / sizeof(MPI2_SGE_IO_UNION));
|
|
|
|
/*
|
|
|
|
* (Command frame size allocaed in SRB ext - Raid SCSI IO message size)
|
|
|
|
* / size of SGL ;
|
|
|
|
* (1280 - 256) / 16 = 64
|
|
|
|
*/
|
|
|
|
sc->max_SGEs_in_chain_message = (MR_COMMAND_SIZE
|
|
|
|
- sc->raid_io_msg_size) / sizeof(MPI2_SGE_IO_UNION);
|
|
|
|
/*
|
|
|
|
* (0x08-1) + 0x40 = 0x47 - 0x01 = 0x46 one is left for command
|
|
|
|
* colscing
|
|
|
|
*/
|
|
|
|
sc->mfi_max_sge = (sc->max_SGEs_in_main_message - 1)
|
|
|
|
+ sc->max_SGEs_in_chain_message - 1;
|
|
|
|
/*
|
|
|
|
* This is the offset in number of 4 * 32bit words to the next chain
|
|
|
|
* (0x100 - 0x10)/0x10 = 0xF(15)
|
|
|
|
*/
|
|
|
|
sc->chain_offset_value_for_main_message = (sc->raid_io_msg_size
|
|
|
|
- sizeof(MPI2_SGE_IO_UNION))/16;
|
|
|
|
sc->chain_offset_value_for_mpt_ptmsg
|
|
|
|
= offsetof(struct mfi_mpi2_request_raid_scsi_io, SGL)/16;
|
|
|
|
sc->mfi_cmd_pool_tbolt = NULL;
|
|
|
|
sc->request_desc_pool = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-05-04 16:22:13 +00:00
|
|
|
* This function calculates the memory requirement for Thunderbolt
|
|
|
|
* controller, returns the total required memory in bytes
|
2011-11-04 02:34:52 +00:00
|
|
|
*/
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
uint32_t
|
|
|
|
mfi_tbolt_get_memory_requirement(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
uint32_t size;
|
2012-03-30 23:05:48 +00:00
|
|
|
size = MEGASAS_THUNDERBOLT_MSG_ALLIGNMENT; /* for Alignment */
|
2011-11-04 02:34:52 +00:00
|
|
|
size += sc->raid_io_msg_size * (sc->mfi_max_fw_cmds + 1);
|
|
|
|
size += sc->reply_size * sc->mfi_max_fw_cmds;
|
2012-03-30 23:05:48 +00:00
|
|
|
/* this is for SGL's */
|
2011-11-04 02:34:52 +00:00
|
|
|
size += MEGASAS_MAX_SZ_CHAIN_FRAME * sc->mfi_max_fw_cmds;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Description:
|
|
|
|
* This function will prepare message pools for the Thunderbolt controller
|
|
|
|
* Arguments:
|
|
|
|
* DevExt - HBA miniport driver's adapter data storage structure
|
|
|
|
* pMemLocation - start of the memory allocated for Thunderbolt.
|
|
|
|
* Return Value:
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE if failed
|
|
|
|
*/
|
2012-05-04 16:22:13 +00:00
|
|
|
int
|
|
|
|
mfi_tbolt_init_desc_pool(struct mfi_softc *sc, uint8_t* mem_location,
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t tbolt_contg_length)
|
|
|
|
{
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint8_t *addr = mem_location;
|
|
|
|
|
|
|
|
/* Request Descriptor Base physical Address */
|
|
|
|
|
|
|
|
/* For Request Decriptors Virtual Memory */
|
|
|
|
/* Initialise the aligned IO Frames Virtual Memory Pointer */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (((uintptr_t)addr) & (0xFF)) {
|
2011-11-04 02:34:52 +00:00
|
|
|
addr = &addr[sc->raid_io_msg_size];
|
|
|
|
addr = (uint8_t *)((uintptr_t)addr & (~0xFF));
|
|
|
|
sc->request_message_pool_align = addr;
|
|
|
|
} else
|
|
|
|
sc->request_message_pool_align = addr;
|
|
|
|
|
|
|
|
offset = sc->request_message_pool_align - sc->request_message_pool;
|
|
|
|
sc->request_msg_busaddr = sc->mfi_tb_busaddr + offset;
|
|
|
|
|
|
|
|
/* DJA XXX should this be bus dma ??? */
|
|
|
|
/* Skip request message pool */
|
|
|
|
addr = &addr[sc->raid_io_msg_size * (sc->mfi_max_fw_cmds + 1)];
|
|
|
|
/* Reply Frame Pool is initialized */
|
|
|
|
sc->reply_frame_pool = (struct mfi_mpi2_reply_header *) addr;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (((uintptr_t)addr) & (0xFF)) {
|
2011-11-04 02:34:52 +00:00
|
|
|
addr = &addr[sc->reply_size];
|
|
|
|
addr = (uint8_t *)((uintptr_t)addr & (~0xFF));
|
|
|
|
}
|
|
|
|
sc->reply_frame_pool_align
|
|
|
|
= (struct mfi_mpi2_reply_header *)addr;
|
|
|
|
|
|
|
|
offset = (uintptr_t)sc->reply_frame_pool_align
|
|
|
|
- (uintptr_t)sc->request_message_pool;
|
|
|
|
sc->reply_frame_busaddr = sc->mfi_tb_busaddr + offset;
|
|
|
|
|
|
|
|
/* Skip Reply Frame Pool */
|
|
|
|
addr += sc->reply_size * sc->mfi_max_fw_cmds;
|
|
|
|
sc->reply_pool_limit = addr;
|
|
|
|
|
|
|
|
/* initializing reply address to 0xFFFFFFFF */
|
|
|
|
memset((uint8_t *)sc->reply_frame_pool, 0xFF,
|
|
|
|
(sc->reply_size * sc->mfi_max_fw_cmds));
|
|
|
|
|
|
|
|
offset = sc->reply_size * sc->mfi_max_fw_cmds;
|
|
|
|
sc->sg_frame_busaddr = sc->reply_frame_busaddr + offset;
|
|
|
|
/* initialize the last_reply_idx to 0 */
|
|
|
|
sc->last_reply_idx = 0;
|
2013-02-27 02:21:10 +00:00
|
|
|
MFI_WRITE4(sc, MFI_RFPI, sc->mfi_max_fw_cmds - 1);
|
|
|
|
MFI_WRITE4(sc, MFI_RPI, sc->last_reply_idx);
|
2011-11-04 02:34:52 +00:00
|
|
|
offset = (sc->sg_frame_busaddr + (MEGASAS_MAX_SZ_CHAIN_FRAME *
|
|
|
|
sc->mfi_max_fw_cmds)) - sc->mfi_tb_busaddr;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (offset > tbolt_contg_length)
|
|
|
|
device_printf(sc->mfi_dev, "Error:Initialized more than "
|
2011-11-04 02:34:52 +00:00
|
|
|
"allocated\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-05-04 16:22:13 +00:00
|
|
|
* This routine prepare and issue INIT2 frame to the Firmware
|
2011-11-04 02:34:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
mfi_tbolt_init_MFI_queue(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct MPI2_IOC_INIT_REQUEST *mpi2IocInit;
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_init_frame *mfi_init;
|
2011-11-04 02:34:52 +00:00
|
|
|
uintptr_t offset = 0;
|
2012-03-30 23:05:48 +00:00
|
|
|
bus_addr_t phyAddress;
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_ADDRESS *mfiAddressTemp;
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_command *cm, cmd_tmp;
|
2011-11-04 02:34:52 +00:00
|
|
|
int error;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Check if initialization is already completed */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->MFA_enabled) {
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "tbolt_init already initialised!\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL) {
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "tbolt_init failed to get command "
|
|
|
|
" entry!\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
cmd_tmp.cm_frame = cm->cm_frame;
|
|
|
|
cmd_tmp.cm_frame_busaddr = cm->cm_frame_busaddr;
|
|
|
|
cmd_tmp.cm_dmamap = cm->cm_dmamap;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame = (union mfi_frame *)((uintptr_t)sc->mfi_tb_init);
|
|
|
|
cm->cm_frame_busaddr = sc->mfi_tb_init_busaddr;
|
|
|
|
cm->cm_dmamap = sc->mfi_tb_init_dmamap;
|
|
|
|
cm->cm_frame->header.context = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abuse the SG list area of the frame to hold the init_qinfo
|
|
|
|
* object;
|
|
|
|
*/
|
|
|
|
mfi_init = &cm->cm_frame->init;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
mpi2IocInit = (struct MPI2_IOC_INIT_REQUEST *)sc->mfi_tb_ioc_init_desc;
|
2011-11-04 02:34:52 +00:00
|
|
|
bzero(mpi2IocInit, sizeof(struct MPI2_IOC_INIT_REQUEST));
|
|
|
|
mpi2IocInit->Function = MPI2_FUNCTION_IOC_INIT;
|
|
|
|
mpi2IocInit->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
|
|
|
|
|
|
|
|
/* set MsgVersion and HeaderVersion host driver was built with */
|
|
|
|
mpi2IocInit->MsgVersion = MPI2_VERSION;
|
|
|
|
mpi2IocInit->HeaderVersion = MPI2_HEADER_VERSION;
|
|
|
|
mpi2IocInit->SystemRequestFrameSize = sc->raid_io_msg_size/4;
|
|
|
|
mpi2IocInit->ReplyDescriptorPostQueueDepth
|
|
|
|
= (uint16_t)sc->mfi_max_fw_cmds;
|
|
|
|
mpi2IocInit->ReplyFreeQueueDepth = 0; /* Not supported by MR. */
|
|
|
|
|
|
|
|
/* Get physical address of reply frame pool */
|
|
|
|
offset = (uintptr_t) sc->reply_frame_pool_align
|
|
|
|
- (uintptr_t)sc->request_message_pool;
|
|
|
|
phyAddress = sc->mfi_tb_busaddr + offset;
|
|
|
|
mfiAddressTemp =
|
|
|
|
(MFI_ADDRESS *)&mpi2IocInit->ReplyDescriptorPostQueueAddress;
|
2012-03-30 23:05:48 +00:00
|
|
|
mfiAddressTemp->u.addressLow = (uint32_t)phyAddress;
|
|
|
|
mfiAddressTemp->u.addressHigh = (uint32_t)((uint64_t)phyAddress >> 32);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
/* Get physical address of request message pool */
|
|
|
|
offset = sc->request_message_pool_align - sc->request_message_pool;
|
|
|
|
phyAddress = sc->mfi_tb_busaddr + offset;
|
|
|
|
mfiAddressTemp = (MFI_ADDRESS *)&mpi2IocInit->SystemRequestFrameBaseAddress;
|
2012-03-30 23:05:48 +00:00
|
|
|
mfiAddressTemp->u.addressLow = (uint32_t)phyAddress;
|
|
|
|
mfiAddressTemp->u.addressHigh = (uint32_t)((uint64_t)phyAddress >> 32);
|
|
|
|
mpi2IocInit->ReplyFreeQueueAddress = 0; /* Not supported by MR. */
|
2011-11-04 02:34:52 +00:00
|
|
|
mpi2IocInit->TimeStamp = time_uptime;
|
|
|
|
|
|
|
|
if (sc->verbuf) {
|
|
|
|
snprintf((char *)sc->verbuf, strlen(MEGASAS_VERSION) + 2, "%s\n",
|
|
|
|
MEGASAS_VERSION);
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_init->driver_ver_lo = (uint32_t)sc->verbuf_h_busaddr;
|
|
|
|
mfi_init->driver_ver_hi =
|
|
|
|
(uint32_t)((uint64_t)sc->verbuf_h_busaddr >> 32);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
/* Get the physical address of the mpi2 ioc init command */
|
|
|
|
phyAddress = sc->mfi_tb_ioc_init_busaddr;
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_init->qinfo_new_addr_lo = (uint32_t)phyAddress;
|
|
|
|
mfi_init->qinfo_new_addr_hi = (uint32_t)((uint64_t)phyAddress >> 32);
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_init->header.flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
|
|
|
|
|
|
|
|
mfi_init->header.cmd = MFI_CMD_INIT;
|
|
|
|
mfi_init->header.data_len = sizeof(struct MPI2_IOC_INIT_REQUEST);
|
|
|
|
mfi_init->header.cmd_status = MFI_STAT_INVALID_STATUS;
|
|
|
|
|
|
|
|
cm->cm_data = NULL;
|
|
|
|
cm->cm_flags |= MFI_CMD_POLLED;
|
|
|
|
cm->cm_timestamp = time_uptime;
|
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "failed to send IOC init2 "
|
|
|
|
"command %d at %lx\n", error, (long)cm->cm_frame_busaddr);
|
2013-02-27 02:21:10 +00:00
|
|
|
goto out;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
if (mfi_init->header.cmd_status == MFI_STAT_OK) {
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->MFA_enabled = 1;
|
2013-02-27 02:21:10 +00:00
|
|
|
} else {
|
|
|
|
device_printf(sc->mfi_dev, "Init command Failed %#x\n",
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_init->header.cmd_status);
|
2013-02-27 02:21:10 +00:00
|
|
|
error = mfi_init->header.cmd_status;
|
|
|
|
goto out;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
out:
|
|
|
|
cm->cm_frame = cmd_tmp.cm_frame;
|
|
|
|
cm->cm_frame_busaddr = cmd_tmp.cm_frame_busaddr;
|
|
|
|
cm->cm_dmamap = cmd_tmp.cm_dmamap;
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
return (error);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
int
|
|
|
|
mfi_tbolt_alloc_cmd(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_cmd_tbolt *cmd;
|
2012-03-30 23:05:48 +00:00
|
|
|
bus_addr_t io_req_base_phys;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint8_t *io_req_base;
|
2012-03-30 23:05:48 +00:00
|
|
|
int i = 0, j = 0, offset = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sc->mfi_cmd_pool_tbolt is an array of struct mfi_cmd_tbolt pointers.
|
|
|
|
* Allocate the dynamic array first and then allocate individual
|
|
|
|
* commands.
|
|
|
|
*/
|
|
|
|
sc->request_desc_pool = malloc(sizeof(
|
|
|
|
union mfi_mpi2_request_descriptor) * sc->mfi_max_fw_cmds,
|
|
|
|
M_MFIBUF, M_NOWAIT|M_ZERO);
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
if (sc->request_desc_pool == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Could not alloc "
|
|
|
|
"memory for request_desc_pool\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_cmd_pool_tbolt = malloc(sizeof(struct mfi_cmd_tbolt*)
|
|
|
|
* sc->mfi_max_fw_cmds, M_MFIBUF, M_NOWAIT|M_ZERO);
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
if (sc->mfi_cmd_pool_tbolt == NULL) {
|
|
|
|
free(sc->request_desc_pool, M_MFIBUF);
|
|
|
|
device_printf(sc->mfi_dev, "Could not alloc "
|
|
|
|
"memory for cmd_pool_tbolt\n");
|
|
|
|
return (ENOMEM);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sc->mfi_max_fw_cmds; i++) {
|
|
|
|
sc->mfi_cmd_pool_tbolt[i] = malloc(sizeof(
|
|
|
|
struct mfi_cmd_tbolt),M_MFIBUF, M_NOWAIT|M_ZERO);
|
|
|
|
|
|
|
|
if (!sc->mfi_cmd_pool_tbolt[i]) {
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "Could not alloc "
|
|
|
|
"cmd_pool_tbolt entry\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
free(sc->mfi_cmd_pool_tbolt[j], M_MFIBUF);
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
free(sc->request_desc_pool, M_MFIBUF);
|
|
|
|
sc->request_desc_pool = NULL;
|
2011-11-04 02:34:52 +00:00
|
|
|
free(sc->mfi_cmd_pool_tbolt, M_MFIBUF);
|
|
|
|
sc->mfi_cmd_pool_tbolt = NULL;
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
return (ENOMEM);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first 256 bytes (SMID 0) is not used. Don't add to the cmd
|
2013-02-27 02:21:10 +00:00
|
|
|
* list
|
2011-11-04 02:34:52 +00:00
|
|
|
*/
|
|
|
|
io_req_base = sc->request_message_pool_align
|
|
|
|
+ MEGASAS_THUNDERBOLT_NEW_MSG_SIZE;
|
|
|
|
io_req_base_phys = sc->request_msg_busaddr
|
|
|
|
+ MEGASAS_THUNDERBOLT_NEW_MSG_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all the commands to command pool (instance->cmd_pool)
|
|
|
|
*/
|
|
|
|
/* SMID 0 is reserved. Set SMID/index from 1 */
|
|
|
|
|
|
|
|
for (i = 0; i < sc->mfi_max_fw_cmds; i++) {
|
|
|
|
cmd = sc->mfi_cmd_pool_tbolt[i];
|
|
|
|
offset = MEGASAS_THUNDERBOLT_NEW_MSG_SIZE * i;
|
|
|
|
cmd->index = i + 1;
|
|
|
|
cmd->request_desc = (union mfi_mpi2_request_descriptor *)
|
|
|
|
(sc->request_desc_pool + i);
|
|
|
|
cmd->io_request = (struct mfi_mpi2_request_raid_scsi_io *)
|
|
|
|
(io_req_base + offset);
|
|
|
|
cmd->io_request_phys_addr = io_req_base_phys + offset;
|
|
|
|
cmd->sg_frame = (MPI2_SGE_IO_UNION *)(sc->reply_pool_limit
|
|
|
|
+ i * MEGASAS_MAX_SZ_CHAIN_FRAME);
|
|
|
|
cmd->sg_frame_phys_addr = sc->sg_frame_busaddr + i
|
|
|
|
* MEGASAS_MAX_SZ_CHAIN_FRAME;
|
2012-11-06 23:25:06 +00:00
|
|
|
cmd->sync_cmd_idx = sc->mfi_max_fw_cmds;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&(sc->mfi_cmd_tbolt_tqh), cmd, next);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
int
|
|
|
|
mfi_tbolt_reset(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
uint32_t fw_state;
|
|
|
|
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->hw_crit_error) {
|
|
|
|
device_printf(sc->mfi_dev, "HW CRITICAL ERROR\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
fw_state = sc->mfi_read_fw_status(sc);
|
2013-02-27 02:21:10 +00:00
|
|
|
if ((fw_state & MFI_FWSTATE_FAULT) == MFI_FWSTATE_FAULT ||
|
|
|
|
mfi_fw_reset_test) {
|
2012-03-30 23:05:48 +00:00
|
|
|
if ((sc->disableOnlineCtrlReset == 0)
|
|
|
|
&& (sc->adpreset == 0)) {
|
|
|
|
device_printf(sc->mfi_dev, "Adapter RESET "
|
2011-11-04 02:34:52 +00:00
|
|
|
"condition is detected\n");
|
|
|
|
sc->adpreset = 1;
|
|
|
|
sc->issuepend_done = 0;
|
|
|
|
sc->MFA_enabled = 0;
|
|
|
|
sc->last_reply_idx = 0;
|
|
|
|
mfi_process_fw_state_chg_isr((void *) sc);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mfi_intr_tbolt - isr entry point
|
|
|
|
*/
|
2012-05-04 16:22:13 +00:00
|
|
|
void
|
|
|
|
mfi_intr_tbolt(void *arg)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc = (struct mfi_softc *)arg;
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_check_clear_intr(sc) == 1) {
|
2011-11-04 02:34:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_detaching)
|
2011-11-04 02:34:52 +00:00
|
|
|
return;
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_tbolt_complete_cmd(sc);
|
2013-02-27 02:21:10 +00:00
|
|
|
sc->mfi_flags &= ~MFI_FLAGS_QFRZN;
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_startio(sc);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
/*
|
2011-11-04 02:34:52 +00:00
|
|
|
* map_cmd_status - Maps FW cmd status to OS cmd status
|
|
|
|
* @cmd : Pointer to cmd
|
|
|
|
* @status : status of cmd returned by FW
|
|
|
|
* @ext_status : ext status of cmd returned by FW
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
map_tbolt_cmd_status(struct mfi_command *mfi_cmd, uint8_t status,
|
|
|
|
uint8_t ext_status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
2013-02-27 02:21:10 +00:00
|
|
|
case MFI_STAT_OK:
|
|
|
|
mfi_cmd->cm_frame->header.cmd_status = MFI_STAT_OK;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.cmd_status = MFI_STAT_OK;
|
|
|
|
mfi_cmd->cm_error = MFI_STAT_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MFI_STAT_SCSI_IO_FAILED:
|
|
|
|
case MFI_STAT_LD_INIT_IN_PROGRESS:
|
|
|
|
mfi_cmd->cm_frame->header.cmd_status = status;
|
|
|
|
mfi_cmd->cm_frame->header.scsi_status = ext_status;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.cmd_status = status;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.scsi_status
|
|
|
|
= ext_status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MFI_STAT_SCSI_DONE_WITH_ERROR:
|
|
|
|
mfi_cmd->cm_frame->header.cmd_status = ext_status;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.cmd_status = ext_status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MFI_STAT_LD_OFFLINE:
|
|
|
|
case MFI_STAT_DEVICE_NOT_FOUND:
|
|
|
|
mfi_cmd->cm_frame->header.cmd_status = status;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.cmd_status = status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mfi_cmd->cm_frame->header.cmd_status = status;
|
|
|
|
mfi_cmd->cm_frame->dcmd.header.cmd_status = status;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
/*
|
2012-03-30 23:05:48 +00:00
|
|
|
* mfi_tbolt_return_cmd - Return a cmd to free command pool
|
|
|
|
* @instance: Adapter soft state
|
2013-02-27 02:21:10 +00:00
|
|
|
* @tbolt_cmd: Tbolt command packet to be returned to free command pool
|
|
|
|
* @mfi_cmd: Oning MFI command packe
|
2012-03-30 23:05:48 +00:00
|
|
|
*/
|
2013-02-27 02:21:10 +00:00
|
|
|
void
|
|
|
|
mfi_tbolt_return_cmd(struct mfi_softc *sc, struct mfi_cmd_tbolt *tbolt_cmd,
|
|
|
|
struct mfi_command *mfi_cmd)
|
2012-03-30 23:05:48 +00:00
|
|
|
{
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_cmd->cm_flags &= ~MFI_CMD_TBOLT;
|
|
|
|
mfi_cmd->cm_extra_frames = 0;
|
|
|
|
tbolt_cmd->sync_cmd_idx = sc->mfi_max_fw_cmds;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mfi_cmd_tbolt_tqh, tbolt_cmd, next);
|
2012-03-30 23:05:48 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
void
|
|
|
|
mfi_tbolt_complete_cmd(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_mpi2_reply_header *desc, *reply_desc;
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_command *cmd_mfi; /* For MFA Cmds */
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_cmd_tbolt *cmd_tbolt;
|
|
|
|
uint16_t smid;
|
|
|
|
uint8_t reply_descript_type;
|
|
|
|
struct mfi_mpi2_request_raid_scsi_io *scsi_io_req;
|
|
|
|
uint32_t status, extStatus;
|
|
|
|
uint16_t num_completed;
|
|
|
|
union desc_value val;
|
2013-02-27 02:21:10 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
desc = (struct mfi_mpi2_reply_header *)
|
|
|
|
((uintptr_t)sc->reply_frame_pool_align
|
|
|
|
+ sc->last_reply_idx * sc->reply_size);
|
|
|
|
reply_desc = desc;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
if (reply_desc == NULL) {
|
2011-11-04 02:34:52 +00:00
|
|
|
device_printf(sc->mfi_dev, "reply desc is NULL!!\n");
|
2013-02-27 02:21:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
reply_descript_type = reply_desc->ReplyFlags
|
|
|
|
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
|
|
|
|
if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
num_completed = 0;
|
|
|
|
val.word = ((union mfi_mpi2_reply_descriptor *)desc)->words;
|
|
|
|
|
|
|
|
/* Read Reply descriptor */
|
|
|
|
while ((val.u.low != 0xFFFFFFFF) && (val.u.high != 0xFFFFFFFF)) {
|
|
|
|
smid = reply_desc->SMID;
|
2013-02-27 02:21:10 +00:00
|
|
|
if (smid == 0 || smid > sc->mfi_max_fw_cmds) {
|
|
|
|
device_printf(sc->mfi_dev, "smid is %d cannot "
|
|
|
|
"proceed - skipping\n", smid);
|
|
|
|
goto next;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
cmd_tbolt = sc->mfi_cmd_pool_tbolt[smid - 1];
|
2013-02-27 02:21:10 +00:00
|
|
|
if (cmd_tbolt->sync_cmd_idx == sc->mfi_max_fw_cmds) {
|
|
|
|
device_printf(sc->mfi_dev, "cmd_tbolt %p "
|
|
|
|
"has invalid sync_cmd_idx=%d - skipping\n",
|
|
|
|
cmd_tbolt, cmd_tbolt->sync_cmd_idx);
|
|
|
|
goto next;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
cmd_mfi = &sc->mfi_commands[cmd_tbolt->sync_cmd_idx];
|
|
|
|
scsi_io_req = cmd_tbolt->io_request;
|
|
|
|
|
|
|
|
status = cmd_mfi->cm_frame->dcmd.header.cmd_status;
|
|
|
|
extStatus = cmd_mfi->cm_frame->dcmd.header.scsi_status;
|
2012-05-04 16:00:39 +00:00
|
|
|
map_tbolt_cmd_status(cmd_mfi, status, extStatus);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
/* mfi_tbolt_return_cmd is handled by mfi complete / return */
|
|
|
|
if ((cmd_mfi->cm_flags & MFI_CMD_SCSI) != 0 &&
|
2012-11-06 23:25:06 +00:00
|
|
|
(cmd_mfi->cm_flags & MFI_CMD_POLLED) != 0) {
|
|
|
|
/* polled LD/SYSPD IO command */
|
|
|
|
/* XXX mark okay for now DJA */
|
|
|
|
cmd_mfi->cm_frame->header.cmd_status = MFI_STAT_OK;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
} else {
|
2012-11-06 23:25:06 +00:00
|
|
|
/* remove command from busy queue if not polled */
|
2013-02-27 02:21:10 +00:00
|
|
|
if ((cmd_mfi->cm_flags & MFI_ON_MFIQ_BUSY) != 0)
|
|
|
|
mfi_remove_busy(cmd_mfi);
|
2012-11-06 23:25:06 +00:00
|
|
|
|
|
|
|
/* complete the command */
|
|
|
|
mfi_complete(sc, cmd_mfi);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
next:
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->last_reply_idx++;
|
|
|
|
if (sc->last_reply_idx >= sc->mfi_max_fw_cmds) {
|
|
|
|
MFI_WRITE4(sc, MFI_RPI, sc->last_reply_idx);
|
|
|
|
sc->last_reply_idx = 0;
|
|
|
|
}
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
/* Set it back to all 0xfff */
|
2011-11-04 02:34:52 +00:00
|
|
|
((union mfi_mpi2_reply_descriptor*)desc)->words =
|
|
|
|
~((uint64_t)0x00);
|
|
|
|
|
|
|
|
num_completed++;
|
|
|
|
|
|
|
|
/* Get the next reply descriptor */
|
|
|
|
desc = (struct mfi_mpi2_reply_header *)
|
|
|
|
((uintptr_t)sc->reply_frame_pool_align
|
|
|
|
+ sc->last_reply_idx * sc->reply_size);
|
|
|
|
reply_desc = desc;
|
|
|
|
val.word = ((union mfi_mpi2_reply_descriptor*)desc)->words;
|
|
|
|
reply_descript_type = reply_desc->ReplyFlags
|
|
|
|
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num_completed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* update replyIndex to FW */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->last_reply_idx)
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_WRITE4(sc, MFI_RPI, sc->last_reply_idx);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
/*
|
2011-11-04 02:34:52 +00:00
|
|
|
* mfi_get_cmd - Get a command from the free pool
|
|
|
|
* @instance: Adapter soft state
|
|
|
|
*
|
|
|
|
* Returns a free command from the pool
|
|
|
|
*/
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
struct mfi_cmd_tbolt *
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_tbolt_get_cmd(struct mfi_softc *sc, struct mfi_command *mfi_cmd)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_cmd_tbolt *cmd = NULL;
|
|
|
|
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
if ((cmd = TAILQ_FIRST(&sc->mfi_cmd_tbolt_tqh)) == NULL)
|
|
|
|
return (NULL);
|
2011-11-04 02:34:52 +00:00
|
|
|
TAILQ_REMOVE(&sc->mfi_cmd_tbolt_tqh, cmd, next);
|
|
|
|
memset((uint8_t *)cmd->sg_frame, 0, MEGASAS_MAX_SZ_CHAIN_FRAME);
|
|
|
|
memset((uint8_t *)cmd->io_request, 0,
|
|
|
|
MEGASAS_THUNDERBOLT_NEW_MSG_SIZE);
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
cmd->sync_cmd_idx = mfi_cmd->cm_index;
|
|
|
|
mfi_cmd->cm_extra_frames = cmd->index; /* Frame count used as SMID */
|
|
|
|
mfi_cmd->cm_flags |= MFI_CMD_TBOLT;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
union mfi_mpi2_request_descriptor *
|
|
|
|
mfi_tbolt_get_request_descriptor(struct mfi_softc *sc, uint16_t index)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
if (index >= sc->mfi_max_fw_cmds) {
|
|
|
|
device_printf(sc->mfi_dev, "Invalid SMID (0x%x)request "
|
|
|
|
"for descriptor\n", index);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
p = sc->request_desc_pool + sizeof(union mfi_mpi2_request_descriptor)
|
|
|
|
* index;
|
|
|
|
memset(p, 0, sizeof(union mfi_mpi2_request_descriptor));
|
|
|
|
return (union mfi_mpi2_request_descriptor *)p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
/* Used to build IOCTL cmd */
|
2011-11-04 02:34:52 +00:00
|
|
|
uint8_t
|
|
|
|
mfi_build_mpt_pass_thru(struct mfi_softc *sc, struct mfi_command *mfi_cmd)
|
|
|
|
{
|
|
|
|
MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
|
|
|
|
struct mfi_mpi2_request_raid_scsi_io *io_req;
|
|
|
|
struct mfi_cmd_tbolt *cmd;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
cmd = mfi_tbolt_get_cmd(sc, mfi_cmd);
|
2011-11-04 02:34:52 +00:00
|
|
|
if (!cmd)
|
|
|
|
return EBUSY;
|
|
|
|
io_req = cmd->io_request;
|
|
|
|
mpi25_ieee_chain = (MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
|
|
|
|
|
|
|
|
io_req->Function = MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
|
|
|
|
io_req->SGLOffset0 = offsetof(struct mfi_mpi2_request_raid_scsi_io,
|
|
|
|
SGL) / 4;
|
|
|
|
io_req->ChainOffset = sc->chain_offset_value_for_mpt_ptmsg;
|
|
|
|
|
|
|
|
mpi25_ieee_chain->Address = mfi_cmd->cm_frame_busaddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
In MFI pass thru, nextChainOffset will always be zero to
|
|
|
|
indicate the end of the chain.
|
|
|
|
*/
|
|
|
|
mpi25_ieee_chain->Flags= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
|
|
|
| MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
|
|
|
|
|
|
|
|
/* setting the length to the maximum length */
|
|
|
|
mpi25_ieee_chain->Length = 1024;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mfi_tbolt_build_ldio(struct mfi_softc *sc, struct mfi_command *mfi_cmd,
|
|
|
|
struct mfi_cmd_tbolt *cmd)
|
|
|
|
{
|
|
|
|
uint32_t start_lba_lo = 0, start_lba_hi = 0, device_id;
|
|
|
|
struct mfi_mpi2_request_raid_scsi_io *io_request;
|
|
|
|
struct IO_REQUEST_INFO io_info;
|
|
|
|
|
|
|
|
device_id = mfi_cmd->cm_frame->io.header.target_id;
|
|
|
|
io_request = cmd->io_request;
|
|
|
|
io_request->RaidContext.TargetID = device_id;
|
|
|
|
io_request->RaidContext.Status = 0;
|
2014-02-06 02:54:04 +00:00
|
|
|
io_request->RaidContext.exStatus = 0;
|
|
|
|
io_request->RaidContext.regLockFlags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
start_lba_lo = mfi_cmd->cm_frame->io.lba_lo;
|
|
|
|
start_lba_hi = mfi_cmd->cm_frame->io.lba_hi;
|
|
|
|
|
|
|
|
memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
|
|
|
|
io_info.ldStartBlock = ((uint64_t)start_lba_hi << 32) | start_lba_lo;
|
|
|
|
io_info.numBlocks = mfi_cmd->cm_frame->io.header.data_len;
|
|
|
|
io_info.ldTgtId = device_id;
|
|
|
|
if ((mfi_cmd->cm_frame->header.flags & MFI_FRAME_DIR_READ) ==
|
|
|
|
MFI_FRAME_DIR_READ)
|
|
|
|
io_info.isRead = 1;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
io_request->RaidContext.timeoutValue
|
|
|
|
= MFI_FUSION_FP_DEFAULT_TIMEOUT;
|
|
|
|
io_request->Function = MPI2_FUNCTION_LD_IO_REQUEST;
|
|
|
|
io_request->DevHandle = device_id;
|
|
|
|
cmd->request_desc->header.RequestFlags
|
|
|
|
= (MFI_REQ_DESCRIPT_FLAGS_LD_IO
|
|
|
|
<< MFI_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
2012-03-30 23:05:48 +00:00
|
|
|
if ((io_request->IoFlags == 6) && (io_info.numBlocks == 0))
|
2011-11-04 02:34:52 +00:00
|
|
|
io_request->RaidContext.RegLockLength = 0x100;
|
|
|
|
io_request->DataLength = mfi_cmd->cm_frame->io.header.data_len
|
|
|
|
* MFI_SECTOR_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-05-04 16:22:13 +00:00
|
|
|
mfi_tbolt_build_io(struct mfi_softc *sc, struct mfi_command *mfi_cmd,
|
|
|
|
struct mfi_cmd_tbolt *cmd)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_mpi2_request_raid_scsi_io *io_request;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t sge_count;
|
2012-11-06 23:25:06 +00:00
|
|
|
uint8_t cdb_len;
|
|
|
|
int readop;
|
|
|
|
u_int64_t lba;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
io_request = cmd->io_request;
|
|
|
|
if (!(mfi_cmd->cm_frame->header.cmd == MFI_CMD_LD_READ
|
|
|
|
|| mfi_cmd->cm_frame->header.cmd == MFI_CMD_LD_WRITE))
|
2011-11-04 02:34:52 +00:00
|
|
|
return 1;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
mfi_tbolt_build_ldio(sc, mfi_cmd, cmd);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
/* Convert to SCSI command CDB */
|
|
|
|
bzero(io_request->CDB.CDB32, sizeof(io_request->CDB.CDB32));
|
|
|
|
if (mfi_cmd->cm_frame->header.cmd == MFI_CMD_LD_WRITE)
|
|
|
|
readop = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
else
|
2012-11-06 23:25:06 +00:00
|
|
|
readop = 1;
|
|
|
|
|
|
|
|
lba = mfi_cmd->cm_frame->io.lba_hi;
|
|
|
|
lba = (lba << 32) + mfi_cmd->cm_frame->io.lba_lo;
|
|
|
|
cdb_len = mfi_build_cdb(readop, 0, lba,
|
|
|
|
mfi_cmd->cm_frame->io.header.data_len, io_request->CDB.CDB32);
|
|
|
|
|
|
|
|
/* Just the CDB length, rest of the Flags are zero */
|
|
|
|
io_request->IoFlags = cdb_len;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct SGL
|
|
|
|
*/
|
|
|
|
sge_count = mfi_tbolt_make_sgl(sc, mfi_cmd,
|
|
|
|
(pMpi25IeeeSgeChain64_t) &io_request->SGL, cmd);
|
|
|
|
if (sge_count > sc->mfi_max_sge) {
|
|
|
|
device_printf(sc->mfi_dev, "Error. sge_count (0x%x) exceeds "
|
|
|
|
"max (0x%x) allowed\n", sge_count, sc->mfi_max_sge);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
io_request->RaidContext.numSGE = sge_count;
|
|
|
|
io_request->SGLFlags = MPI2_SGE_FLAGS_64_BIT_ADDRESSING;
|
|
|
|
|
|
|
|
if (mfi_cmd->cm_frame->header.cmd == MFI_CMD_LD_WRITE)
|
|
|
|
io_request->Control = MPI2_SCSIIO_CONTROL_WRITE;
|
|
|
|
else
|
|
|
|
io_request->Control = MPI2_SCSIIO_CONTROL_READ;
|
|
|
|
|
|
|
|
io_request->SGLOffset0 = offsetof(
|
|
|
|
struct mfi_mpi2_request_raid_scsi_io, SGL)/4;
|
|
|
|
|
|
|
|
io_request->SenseBufferLowAddress = mfi_cmd->cm_sense_busaddr;
|
|
|
|
io_request->SenseBufferLength = MFI_SENSE_LEN;
|
2012-11-06 23:25:06 +00:00
|
|
|
io_request->RaidContext.Status = MFI_STAT_INVALID_STATUS;
|
|
|
|
io_request->RaidContext.exStatus = MFI_STAT_INVALID_STATUS;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mfi_tbolt_make_sgl(struct mfi_softc *sc, struct mfi_command *mfi_cmd,
|
2012-03-30 23:05:48 +00:00
|
|
|
pMpi25IeeeSgeChain64_t sgl_ptr, struct mfi_cmd_tbolt *cmd)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
2012-03-30 23:05:48 +00:00
|
|
|
uint8_t i, sg_processed, sg_to_process;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint8_t sge_count, sge_idx;
|
|
|
|
union mfi_sgl *os_sgl;
|
2014-02-06 02:54:04 +00:00
|
|
|
pMpi25IeeeSgeChain64_t sgl_end;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return 0 if there is no data transfer
|
|
|
|
*/
|
|
|
|
if (!mfi_cmd->cm_sg || !mfi_cmd->cm_len) {
|
|
|
|
device_printf(sc->mfi_dev, "Buffer empty \n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
os_sgl = mfi_cmd->cm_sg;
|
|
|
|
sge_count = mfi_cmd->cm_frame->header.sg_count;
|
|
|
|
|
|
|
|
if (sge_count > sc->mfi_max_sge) {
|
|
|
|
device_printf(sc->mfi_dev, "sgl ptr %p sg_cnt %d \n",
|
2012-03-30 23:05:48 +00:00
|
|
|
os_sgl, sge_count);
|
2011-11-04 02:34:52 +00:00
|
|
|
return sge_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sge_count > sc->max_SGEs_in_main_message)
|
|
|
|
/* One element to store the chain info */
|
|
|
|
sge_idx = sc->max_SGEs_in_main_message - 1;
|
|
|
|
else
|
|
|
|
sge_idx = sge_count;
|
|
|
|
|
2014-02-06 02:54:04 +00:00
|
|
|
if (sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY)) {
|
|
|
|
sgl_end = sgl_ptr + (sc->max_SGEs_in_main_message - 1);
|
|
|
|
sgl_end->Flags = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
for (i = 0; i < sge_idx; i++) {
|
|
|
|
/*
|
2012-03-30 23:05:48 +00:00
|
|
|
* For 32bit BSD we are getting 32 bit SGL's from OS
|
|
|
|
* but FW only take 64 bit SGL's so copying from 32 bit
|
|
|
|
* SGL's to 64.
|
|
|
|
*/
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY) {
|
|
|
|
sgl_ptr->Length = os_sgl->sg_skinny[i].len;
|
|
|
|
sgl_ptr->Address = os_sgl->sg_skinny[i].addr;
|
|
|
|
} else {
|
|
|
|
sgl_ptr->Length = os_sgl->sg32[i].len;
|
2012-03-30 23:05:48 +00:00
|
|
|
sgl_ptr->Address = os_sgl->sg32[i].addr;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2014-02-06 02:54:04 +00:00
|
|
|
if (i == sge_count - 1 &&
|
|
|
|
(sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY)))
|
|
|
|
sgl_ptr->Flags = MPI25_IEEE_SGE_FLAGS_END_OF_LIST;
|
|
|
|
else
|
|
|
|
sgl_ptr->Flags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl_ptr++;
|
|
|
|
cmd->io_request->ChainOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sg_processed = i;
|
|
|
|
|
|
|
|
if (sg_processed < sge_count) {
|
|
|
|
pMpi25IeeeSgeChain64_t sg_chain;
|
|
|
|
sg_to_process = sge_count - sg_processed;
|
|
|
|
cmd->io_request->ChainOffset =
|
|
|
|
sc->chain_offset_value_for_main_message;
|
|
|
|
sg_chain = sgl_ptr;
|
|
|
|
/* Prepare chain element */
|
|
|
|
sg_chain->NextChainOffset = 0;
|
2014-02-06 02:54:04 +00:00
|
|
|
if (sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY))
|
|
|
|
sg_chain->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT;
|
|
|
|
else
|
|
|
|
sg_chain->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT |
|
|
|
|
MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
|
2011-11-04 02:34:52 +00:00
|
|
|
sg_chain->Length = (sizeof(MPI2_SGE_IO_UNION) *
|
|
|
|
(sge_count - sg_processed));
|
2012-03-30 23:05:48 +00:00
|
|
|
sg_chain->Address = cmd->sg_frame_phys_addr;
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl_ptr = (pMpi25IeeeSgeChain64_t)cmd->sg_frame;
|
|
|
|
for (; i < sge_count; i++) {
|
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY) {
|
|
|
|
sgl_ptr->Length = os_sgl->sg_skinny[i].len;
|
|
|
|
sgl_ptr->Address = os_sgl->sg_skinny[i].addr;
|
2012-03-30 23:05:48 +00:00
|
|
|
} else {
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl_ptr->Length = os_sgl->sg32[i].len;
|
2012-03-30 23:05:48 +00:00
|
|
|
sgl_ptr->Address = os_sgl->sg32[i].addr;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2014-02-06 02:54:04 +00:00
|
|
|
if (i == sge_count - 1 &&
|
|
|
|
(sc->mfi_flags &
|
|
|
|
(MFI_FLAGS_INVADER | MFI_FLAGS_FURY)))
|
|
|
|
sgl_ptr->Flags =
|
|
|
|
MPI25_IEEE_SGE_FLAGS_END_OF_LIST;
|
|
|
|
else
|
|
|
|
sgl_ptr->Flags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl_ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sge_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
union mfi_mpi2_request_descriptor *
|
|
|
|
mfi_build_and_issue_cmd(struct mfi_softc *sc, struct mfi_command *mfi_cmd)
|
|
|
|
{
|
|
|
|
struct mfi_cmd_tbolt *cmd;
|
|
|
|
union mfi_mpi2_request_descriptor *req_desc = NULL;
|
|
|
|
uint16_t index;
|
2013-02-27 02:21:10 +00:00
|
|
|
cmd = mfi_tbolt_get_cmd(sc, mfi_cmd);
|
|
|
|
if (cmd == NULL)
|
|
|
|
return (NULL);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
index = cmd->index;
|
|
|
|
req_desc = mfi_tbolt_get_request_descriptor(sc, index-1);
|
2013-02-27 02:21:10 +00:00
|
|
|
if (req_desc == NULL) {
|
|
|
|
mfi_tbolt_return_cmd(sc, cmd, mfi_cmd);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mfi_tbolt_build_io(sc, mfi_cmd, cmd) != 0) {
|
|
|
|
mfi_tbolt_return_cmd(sc, cmd, mfi_cmd);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
req_desc->header.SMID = index;
|
|
|
|
return req_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
union mfi_mpi2_request_descriptor *
|
|
|
|
mfi_tbolt_build_mpt_cmd(struct mfi_softc *sc, struct mfi_command *cmd)
|
|
|
|
{
|
|
|
|
union mfi_mpi2_request_descriptor *req_desc = NULL;
|
|
|
|
uint16_t index;
|
|
|
|
if (mfi_build_mpt_pass_thru(sc, cmd)) {
|
|
|
|
device_printf(sc->mfi_dev, "Couldn't build MFI pass thru "
|
|
|
|
"cmd\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* For fusion the frame_count variable is used for SMID */
|
|
|
|
index = cmd->cm_extra_frames;
|
|
|
|
|
|
|
|
req_desc = mfi_tbolt_get_request_descriptor(sc, index - 1);
|
2013-02-27 02:21:10 +00:00
|
|
|
if (req_desc == NULL)
|
2011-11-04 02:34:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-06-25 05:41:16 +00:00
|
|
|
bzero(req_desc, sizeof(*req_desc));
|
2011-11-04 02:34:52 +00:00
|
|
|
req_desc->header.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
|
|
|
|
MFI_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
|
|
|
req_desc->header.SMID = index;
|
|
|
|
return req_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mfi_tbolt_send_frame(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
uint8_t *cdb;
|
|
|
|
union mfi_mpi2_request_descriptor *req_desc = NULL;
|
2013-02-27 02:21:10 +00:00
|
|
|
int tm = mfi_polled_cmd_timeout * 1000;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
cdb = cm->cm_frame->pass.cdb;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->adpreset)
|
2011-11-04 02:34:52 +00:00
|
|
|
return 1;
|
|
|
|
if ((cm->cm_flags & MFI_CMD_POLLED) == 0) {
|
|
|
|
cm->cm_timestamp = time_uptime;
|
|
|
|
mfi_enqueue_busy(cm);
|
2012-11-06 23:25:06 +00:00
|
|
|
} else { /* still get interrupts for it */
|
2012-05-04 16:00:39 +00:00
|
|
|
hdr->cmd_status = MFI_STAT_INVALID_STATUS;
|
2011-11-04 02:34:52 +00:00
|
|
|
hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->cmd == MFI_CMD_PD_SCSI_IO) {
|
|
|
|
/* check for inquiry commands coming from CLI */
|
|
|
|
if (cdb[0] != 0x28 || cdb[0] != 0x2A) {
|
|
|
|
if ((req_desc = mfi_tbolt_build_mpt_cmd(sc, cm)) ==
|
|
|
|
NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Mapping from MFI "
|
|
|
|
"to MPT Failed \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
device_printf(sc->mfi_dev, "DJA NA XXX SYSPDIO\n");
|
2012-11-06 23:25:06 +00:00
|
|
|
} else if (hdr->cmd == MFI_CMD_LD_SCSI_IO ||
|
2011-11-04 02:34:52 +00:00
|
|
|
hdr->cmd == MFI_CMD_LD_READ || hdr->cmd == MFI_CMD_LD_WRITE) {
|
2012-11-06 23:25:06 +00:00
|
|
|
cm->cm_flags |= MFI_CMD_SCSI;
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((req_desc = mfi_build_and_issue_cmd(sc, cm)) == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "LDIO Failed \n");
|
|
|
|
return 1;
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
} else if ((req_desc = mfi_tbolt_build_mpt_cmd(sc, cm)) == NULL) {
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "Mapping from MFI to MPT Failed\n");
|
|
|
|
return (1);
|
2012-11-06 23:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->cm_flags & MFI_CMD_SCSI) {
|
|
|
|
/*
|
|
|
|
* LD IO needs to be posted since it doesn't get
|
|
|
|
* acknowledged via a status update so have the
|
|
|
|
* controller reply via mfi_tbolt_complete_cmd.
|
|
|
|
*/
|
|
|
|
hdr->flags &= ~MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_WRITE4(sc, MFI_ILQP, (req_desc->words & 0xFFFFFFFF));
|
|
|
|
MFI_WRITE4(sc, MFI_IHQP, (req_desc->words >>0x20));
|
|
|
|
|
|
|
|
if ((cm->cm_flags & MFI_CMD_POLLED) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
/*
|
|
|
|
* This is a polled command, so busy-wait for it to complete.
|
|
|
|
*
|
|
|
|
* The value of hdr->cmd_status is updated directly by the hardware
|
|
|
|
* so there is no garantee that mfi_tbolt_complete_cmd is called
|
|
|
|
* prior to this value changing.
|
|
|
|
*/
|
2012-05-04 16:00:39 +00:00
|
|
|
while (hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
2011-11-04 02:34:52 +00:00
|
|
|
DELAY(1000);
|
|
|
|
tm -= 1;
|
|
|
|
if (tm <= 0)
|
2012-11-06 23:25:06 +00:00
|
|
|
break;
|
|
|
|
if (cm->cm_flags & MFI_CMD_SCSI) {
|
2013-02-27 02:21:10 +00:00
|
|
|
/*
|
|
|
|
* Force check reply queue.
|
|
|
|
* This ensures that dump works correctly
|
|
|
|
*/
|
2012-11-06 23:25:06 +00:00
|
|
|
mfi_tbolt_complete_cmd(sc);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2012-05-04 16:22:13 +00:00
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
/* ensure the command cleanup has been processed before returning */
|
|
|
|
mfi_tbolt_complete_cmd(sc);
|
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
if (hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
2011-11-04 02:34:52 +00:00
|
|
|
device_printf(sc->mfi_dev, "Frame %p timed out "
|
2012-05-04 16:00:39 +00:00
|
|
|
"command 0x%X\n", hdr, cm->cm_frame->dcmd.opcode);
|
2011-11-04 02:34:52 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
static void
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_issue_pending_cmds_again(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
2012-03-30 23:05:48 +00:00
|
|
|
struct mfi_command *cm, *tmp;
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_cmd_tbolt *cmd;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_FOREACH_REVERSE_SAFE(cm, &sc->mfi_busy, BUSYQ, cm_link, tmp) {
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
cm->retry_for_fw_reset++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a command has continuously been tried multiple times
|
|
|
|
* and causing a FW reset condition, no further recoveries
|
|
|
|
* should be performed on the controller
|
|
|
|
*/
|
|
|
|
if (cm->retry_for_fw_reset == 3) {
|
2013-02-27 02:21:10 +00:00
|
|
|
device_printf(sc->mfi_dev, "megaraid_sas: command %p "
|
|
|
|
"index=%d was tried multiple times during adapter "
|
|
|
|
"reset - Shutting down the HBA\n", cm, cm->cm_index);
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_kill_hba(sc);
|
|
|
|
sc->hw_crit_error = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_remove_busy(cm);
|
|
|
|
if ((cm->cm_flags & MFI_CMD_TBOLT) != 0) {
|
|
|
|
if (cm->cm_extra_frames != 0 && cm->cm_extra_frames <=
|
|
|
|
sc->mfi_max_fw_cmds) {
|
|
|
|
cmd = sc->mfi_cmd_pool_tbolt[cm->cm_extra_frames - 1];
|
|
|
|
mfi_tbolt_return_cmd(sc, cmd, cm);
|
|
|
|
} else {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Invalid extra_frames: %d detected\n",
|
|
|
|
cm->cm_extra_frames);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
if (cm->cm_frame->dcmd.opcode != MFI_DCMD_CTRL_EVENT_WAIT) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"APJ ****requeue command %p index=%d\n",
|
|
|
|
cm, cm->cm_index);
|
|
|
|
mfi_requeue_ready(cm);
|
|
|
|
} else
|
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
mfi_startio(sc);
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
static void
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_kill_hba(struct mfi_softc *sc)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT)
|
2013-02-27 02:21:10 +00:00
|
|
|
MFI_WRITE4(sc, 0x00, MFI_STOP_ADP);
|
2011-11-04 02:34:52 +00:00
|
|
|
else
|
2013-02-27 02:21:10 +00:00
|
|
|
MFI_WRITE4(sc, MFI_IDB, MFI_STOP_ADP);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 16:22:13 +00:00
|
|
|
static void
|
|
|
|
mfi_process_fw_state_chg_isr(void *arg)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc= (struct mfi_softc *)arg;
|
|
|
|
int error, status;
|
|
|
|
|
|
|
|
if (sc->adpreset == 1) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "First stage of FW reset "
|
2011-11-04 02:34:52 +00:00
|
|
|
"initiated...\n");
|
|
|
|
|
|
|
|
sc->mfi_adp_reset(sc);
|
|
|
|
sc->mfi_enable_intr(sc);
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "First stage of reset complete, "
|
2011-11-04 02:34:52 +00:00
|
|
|
"second stage initiated...\n");
|
|
|
|
|
|
|
|
sc->adpreset = 2;
|
|
|
|
|
|
|
|
/* waiting for about 20 second before start the second init */
|
2012-03-30 23:05:48 +00:00
|
|
|
for (int wait = 0; wait < 20000; wait++)
|
2011-11-04 02:34:52 +00:00
|
|
|
DELAY(1000);
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "Second stage of FW reset "
|
2011-11-04 02:34:52 +00:00
|
|
|
"initiated...\n");
|
2012-03-30 23:05:48 +00:00
|
|
|
while ((status = MFI_READ4(sc, MFI_RSR)) & 0x04);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
sc->mfi_disable_intr(sc);
|
|
|
|
|
|
|
|
/* We expect the FW state to be READY */
|
|
|
|
if (mfi_transition_firmware(sc)) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "controller is not in "
|
|
|
|
"ready state\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_kill_hba(sc);
|
2013-02-27 02:21:10 +00:00
|
|
|
sc->hw_crit_error = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((error = mfi_tbolt_init_MFI_queue(sc)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to initialise MFI "
|
|
|
|
"queue\n");
|
|
|
|
mfi_kill_hba(sc);
|
|
|
|
sc->hw_crit_error = 1;
|
|
|
|
return;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
/* Init last reply index and max */
|
|
|
|
MFI_WRITE4(sc, MFI_RFPI, sc->mfi_max_fw_cmds - 1);
|
|
|
|
MFI_WRITE4(sc, MFI_RPI, sc->last_reply_idx);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
sc->mfi_enable_intr(sc);
|
|
|
|
sc->adpreset = 0;
|
2013-02-27 02:21:10 +00:00
|
|
|
if (sc->mfi_aen_cm != NULL) {
|
|
|
|
free(sc->mfi_aen_cm->cm_data, M_MFIBUF);
|
|
|
|
mfi_remove_busy(sc->mfi_aen_cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_release_command(sc->mfi_aen_cm);
|
|
|
|
sc->mfi_aen_cm = NULL;
|
|
|
|
}
|
2013-02-27 02:21:10 +00:00
|
|
|
|
|
|
|
if (sc->mfi_map_sync_cm != NULL) {
|
|
|
|
mfi_remove_busy(sc->mfi_map_sync_cm);
|
2012-05-04 16:00:39 +00:00
|
|
|
mfi_release_command(sc->mfi_map_sync_cm);
|
|
|
|
sc->mfi_map_sync_cm = NULL;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
mfi_issue_pending_cmds_again(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue pending command can result in adapter being marked
|
|
|
|
* dead because of too many re-tries. Check for that
|
|
|
|
* condition before clearing the reset condition on the FW
|
|
|
|
*/
|
|
|
|
if (!sc->hw_crit_error) {
|
|
|
|
/*
|
2013-02-27 02:21:10 +00:00
|
|
|
* Initiate AEN (Asynchronous Event Notification) &
|
|
|
|
* Sync Map
|
2011-11-04 02:34:52 +00:00
|
|
|
*/
|
|
|
|
mfi_aen_setup(sc, sc->last_seq_num);
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_tbolt_sync_map_info(sc);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->issuepend_done = 1;
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "second stage of reset "
|
2011-11-04 02:34:52 +00:00
|
|
|
"complete, FW is ready now.\n");
|
|
|
|
} else {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "second stage of reset "
|
2011-11-04 02:34:52 +00:00
|
|
|
"never completed, hba was marked offline.\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
device_printf(sc->mfi_dev, "mfi_process_fw_state_chg_isr "
|
|
|
|
"called with unhandled value:%d\n", sc->adpreset);
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 16:00:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The ThunderBolt HW has an option for the driver to directly
|
2012-05-04 16:22:13 +00:00
|
|
|
* access the underlying disks and operate on the RAID. To
|
2012-05-04 16:00:39 +00:00
|
|
|
* do this there needs to be a capability to keep the RAID controller
|
|
|
|
* and driver in sync. The FreeBSD driver does not take advantage
|
|
|
|
* of this feature since it adds a lot of complexity and slows down
|
|
|
|
* performance. Performance is gained by using the controller's
|
|
|
|
* cache etc.
|
|
|
|
*
|
|
|
|
* Even though this driver doesn't access the disks directly, an
|
|
|
|
* AEN like command is used to inform the RAID firmware to "sync"
|
|
|
|
* with all LD's via the MFI_DCMD_LD_MAP_GET_INFO command. This
|
|
|
|
* command in write mode will return when the RAID firmware has
|
|
|
|
* detected a change to the RAID state. Examples of this type
|
|
|
|
* of change are removing a disk. Once the command returns then
|
|
|
|
* the driver needs to acknowledge this and "sync" all LD's again.
|
|
|
|
* This repeats until we shutdown. Then we need to cancel this
|
|
|
|
* pending command.
|
|
|
|
*
|
|
|
|
* If this is not done right the RAID firmware will not remove a
|
|
|
|
* pulled drive and the RAID won't go degraded etc. Effectively,
|
|
|
|
* stopping any RAID mangement to functions.
|
|
|
|
*
|
|
|
|
* Doing another LD sync, requires the use of an event since the
|
|
|
|
* driver needs to do a mfi_wait_command and can't do that in an
|
|
|
|
* interrupt thread.
|
|
|
|
*
|
|
|
|
* The driver could get the RAID state via the MFI_DCMD_LD_MAP_GET_INFO
|
|
|
|
* That requires a bunch of structure and it is simplier to just do
|
|
|
|
* the MFI_DCMD_LD_GET_LIST versus walking the RAID map.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
mfi_tbolt_sync_map_info(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
int error = 0, i;
|
2013-02-27 02:21:10 +00:00
|
|
|
struct mfi_command *cmd = NULL;
|
|
|
|
struct mfi_dcmd_frame *dcmd = NULL;
|
2012-05-04 16:00:39 +00:00
|
|
|
uint32_t context = 0;
|
2013-02-27 02:21:10 +00:00
|
|
|
union mfi_ld_ref *ld_sync = NULL;
|
2012-05-04 16:00:39 +00:00
|
|
|
size_t ld_size;
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_command *cm = NULL;
|
|
|
|
struct mfi_ld_list *list = NULL;
|
|
|
|
|
2013-02-27 02:21:10 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
if (sc->mfi_map_sync_cm != NULL || sc->cm_map_abort)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_LD_GET_LIST,
|
|
|
|
(void **)&list, sizeof(*list));
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
cm->cm_flags = MFI_CMD_POLLED | MFI_CMD_DATAIN;
|
2013-02-27 02:21:10 +00:00
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
if (mfi_wait_command(sc, cm) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to get device listing\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
if (hdr->cmd_status != MFI_STAT_OK) {
|
|
|
|
device_printf(sc->mfi_dev, "MFI_DCMD_LD_GET_LIST failed %x\n",
|
|
|
|
hdr->cmd_status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld_size = sizeof(*ld_sync) * list->ld_count;
|
|
|
|
ld_sync = (union mfi_ld_ref *) malloc(ld_size, M_MFIBUF,
|
2013-02-27 02:21:10 +00:00
|
|
|
M_NOWAIT | M_ZERO);
|
2012-05-04 22:54:54 +00:00
|
|
|
if (ld_sync == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to allocate sync\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2013-02-27 02:21:10 +00:00
|
|
|
for (i = 0; i < list->ld_count; i++)
|
2012-05-04 16:00:39 +00:00
|
|
|
ld_sync[i].ref = list->ld_list[i].ld.ref;
|
|
|
|
|
2012-05-04 22:54:54 +00:00
|
|
|
if ((cmd = mfi_dequeue_free(sc)) == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to get command\n");
|
|
|
|
free(ld_sync, M_MFIBUF);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
context = cmd->cm_frame->header.context;
|
|
|
|
bzero(cmd->cm_frame, sizeof(union mfi_frame));
|
|
|
|
cmd->cm_frame->header.context = context;
|
|
|
|
|
|
|
|
dcmd = &cmd->cm_frame->dcmd;
|
|
|
|
bzero(dcmd->mbox, MFI_MBOX_SIZE);
|
|
|
|
dcmd->header.cmd = MFI_CMD_DCMD;
|
|
|
|
dcmd->header.flags = MFI_FRAME_DIR_WRITE;
|
|
|
|
dcmd->header.timeout = 0;
|
|
|
|
dcmd->header.data_len = ld_size;
|
|
|
|
dcmd->header.scsi_status = 0;
|
|
|
|
dcmd->opcode = MFI_DCMD_LD_MAP_GET_INFO;
|
|
|
|
cmd->cm_sg = &dcmd->sgl;
|
|
|
|
cmd->cm_total_frame_size = MFI_DCMD_FRAME_SIZE;
|
|
|
|
cmd->cm_data = ld_sync;
|
|
|
|
cmd->cm_private = ld_sync;
|
|
|
|
|
|
|
|
cmd->cm_len = ld_size;
|
|
|
|
cmd->cm_complete = mfi_sync_map_complete;
|
|
|
|
sc->mfi_map_sync_cm = cmd;
|
|
|
|
|
|
|
|
cmd->cm_flags = MFI_CMD_DATAOUT;
|
|
|
|
cmd->cm_frame->dcmd.mbox[0] = list->ld_count;
|
|
|
|
cmd->cm_frame->dcmd.mbox[1] = MFI_DCMD_MBOX_PEND_FLAG;
|
|
|
|
|
|
|
|
if ((error = mfi_mapcmd(sc, cmd)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "failed to send map sync\n");
|
2012-05-04 22:54:54 +00:00
|
|
|
free(ld_sync, M_MFIBUF);
|
|
|
|
sc->mfi_map_sync_cm = NULL;
|
2013-02-27 02:21:10 +00:00
|
|
|
mfi_release_command(cmd);
|
2012-05-04 22:54:54 +00:00
|
|
|
goto out;
|
2012-05-04 16:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (list)
|
|
|
|
free(list, M_MFIBUF);
|
|
|
|
if (cm)
|
|
|
|
mfi_release_command(cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_sync_map_complete(struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
int aborted = 0;
|
|
|
|
|
|
|
|
sc = cm->cm_sc;
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
|
|
|
|
if (sc->mfi_map_sync_cm == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->cm_map_abort ||
|
|
|
|
hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
|
|
|
sc->cm_map_abort = 0;
|
|
|
|
aborted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cm->cm_data, M_MFIBUF);
|
|
|
|
wakeup(&sc->mfi_map_sync_cm);
|
2013-02-27 02:21:10 +00:00
|
|
|
sc->mfi_map_sync_cm = NULL;
|
2012-05-04 16:00:39 +00:00
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
/* set it up again so the driver can catch more events */
|
2013-02-27 02:21:10 +00:00
|
|
|
if (!aborted)
|
2012-05-04 16:00:39 +00:00
|
|
|
mfi_queue_map_sync(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_queue_map_sync(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
taskqueue_enqueue(taskqueue_swi, &sc->mfi_map_sync_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mfi_handle_map_sync(void *context, int pending)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
|
|
|
|
sc = context;
|
2013-02-27 02:21:10 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2012-05-04 16:00:39 +00:00
|
|
|
mfi_tbolt_sync_map_info(sc);
|
2013-02-27 02:21:10 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2012-05-04 16:00:39 +00:00
|
|
|
}
|