2006-03-25 06:14:32 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 IronPort Systems
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2007-08-25 23:58:45 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2007 LSI Corp.
|
|
|
|
* Copyright (c) 2007 Rajesh Prabhakaran.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
#include "opt_compat.h"
|
2006-03-25 06:14:32 +00:00
|
|
|
#include "opt_mfi.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2006-09-07 18:40:49 +00:00
|
|
|
#include <sys/sysctl.h>
|
2006-03-25 06:14:32 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2006-05-18 23:30:48 +00:00
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/selinfo.h>
|
2006-03-25 06:14:32 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/eventhandler.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/bus_dma.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/ioccom.h>
|
2006-05-18 23:30:48 +00:00
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/proc.h>
|
2006-10-16 04:18:38 +00:00
|
|
|
#include <sys/signalvar.h>
|
2012-07-03 16:12:57 +00:00
|
|
|
#include <sys/sysent.h>
|
2012-03-30 23:05:48 +00:00
|
|
|
#include <sys/taskqueue.h>
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
|
|
|
#include <dev/mfi/mfireg.h>
|
|
|
|
#include <dev/mfi/mfi_ioctl.h>
|
|
|
|
#include <dev/mfi/mfivar.h>
|
2011-11-04 02:34:52 +00:00
|
|
|
#include <sys/interrupt.h>
|
|
|
|
#include <sys/priority.h>
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
static int mfi_alloc_commands(struct mfi_softc *);
|
|
|
|
static int mfi_comms_init(struct mfi_softc *);
|
|
|
|
static int mfi_get_controller_info(struct mfi_softc *);
|
2006-05-18 23:30:48 +00:00
|
|
|
static int mfi_get_log_state(struct mfi_softc *,
|
2006-06-20 21:06:05 +00:00
|
|
|
struct mfi_evt_log_state **);
|
2008-06-26 22:33:24 +00:00
|
|
|
static int mfi_parse_entries(struct mfi_softc *, int, int);
|
2006-03-25 06:14:32 +00:00
|
|
|
static void mfi_data_cb(void *, bus_dma_segment_t *, int, int);
|
|
|
|
static void mfi_startup(void *arg);
|
|
|
|
static void mfi_intr(void *arg);
|
2006-06-20 22:41:44 +00:00
|
|
|
static void mfi_ldprobe(struct mfi_softc *sc);
|
2011-11-04 02:34:52 +00:00
|
|
|
static void mfi_syspdprobe(struct mfi_softc *sc);
|
2012-03-30 23:05:48 +00:00
|
|
|
static void mfi_handle_evt(void *context, int pending);
|
2006-05-18 23:30:48 +00:00
|
|
|
static int mfi_aen_register(struct mfi_softc *sc, int seq, int locale);
|
|
|
|
static void mfi_aen_complete(struct mfi_command *);
|
2006-06-20 22:41:44 +00:00
|
|
|
static int mfi_add_ld(struct mfi_softc *sc, int);
|
|
|
|
static void mfi_add_ld_complete(struct mfi_command *);
|
2011-11-04 02:34:52 +00:00
|
|
|
static int mfi_add_sys_pd(struct mfi_softc *sc, int);
|
|
|
|
static void mfi_add_sys_pd_complete(struct mfi_command *);
|
2006-03-25 06:14:32 +00:00
|
|
|
static struct mfi_command * mfi_bio_command(struct mfi_softc *);
|
|
|
|
static void mfi_bio_complete(struct mfi_command *);
|
2011-11-04 02:34:52 +00:00
|
|
|
static struct mfi_command *mfi_build_ldio(struct mfi_softc *,struct bio*);
|
|
|
|
static struct mfi_command *mfi_build_syspdio(struct mfi_softc *,struct bio*);
|
2006-03-25 06:14:32 +00:00
|
|
|
static int mfi_send_frame(struct mfi_softc *, struct mfi_command *);
|
2012-11-06 23:25:06 +00:00
|
|
|
static int mfi_abort(struct mfi_softc *, struct mfi_command **);
|
2009-05-20 17:29:21 +00:00
|
|
|
static int mfi_linux_ioctl_int(struct cdev *, u_long, caddr_t, int, struct thread *);
|
2006-09-25 11:35:34 +00:00
|
|
|
static void mfi_timeout(void *);
|
2008-05-12 14:09:19 +00:00
|
|
|
static int mfi_user_command(struct mfi_softc *,
|
|
|
|
struct mfi_ioc_passthru *);
|
2012-03-30 23:05:48 +00:00
|
|
|
static void mfi_enable_intr_xscale(struct mfi_softc *sc);
|
|
|
|
static void mfi_enable_intr_ppc(struct mfi_softc *sc);
|
2011-11-04 02:34:52 +00:00
|
|
|
static int32_t mfi_read_fw_status_xscale(struct mfi_softc *sc);
|
|
|
|
static int32_t mfi_read_fw_status_ppc(struct mfi_softc *sc);
|
2012-03-30 23:05:48 +00:00
|
|
|
static int mfi_check_clear_intr_xscale(struct mfi_softc *sc);
|
|
|
|
static int mfi_check_clear_intr_ppc(struct mfi_softc *sc);
|
|
|
|
static void mfi_issue_cmd_xscale(struct mfi_softc *sc, bus_addr_t bus_add,
|
|
|
|
uint32_t frame_cnt);
|
|
|
|
static void mfi_issue_cmd_ppc(struct mfi_softc *sc, bus_addr_t bus_add,
|
|
|
|
uint32_t frame_cnt);
|
2011-11-04 02:34:52 +00:00
|
|
|
static int mfi_config_lock(struct mfi_softc *sc, uint32_t opcode);
|
|
|
|
static void mfi_config_unlock(struct mfi_softc *sc, int locked);
|
|
|
|
static int mfi_check_command_pre(struct mfi_softc *sc, struct mfi_command *cm);
|
|
|
|
static void mfi_check_command_post(struct mfi_softc *sc, struct mfi_command *cm);
|
|
|
|
static int mfi_check_for_sscd(struct mfi_softc *sc, struct mfi_command *cm);
|
2006-09-07 18:40:49 +00:00
|
|
|
|
2011-11-16 15:39:27 +00:00
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, mfi, CTLFLAG_RD, 0, "MFI driver parameters");
|
2006-09-07 18:40:49 +00:00
|
|
|
static int mfi_event_locale = MFI_EVT_LOCALE_ALL;
|
2006-09-20 18:49:35 +00:00
|
|
|
TUNABLE_INT("hw.mfi.event_locale", &mfi_event_locale);
|
2006-09-07 18:40:49 +00:00
|
|
|
SYSCTL_INT(_hw_mfi, OID_AUTO, event_locale, CTLFLAG_RW, &mfi_event_locale,
|
|
|
|
0, "event message locale");
|
2006-09-20 18:49:35 +00:00
|
|
|
|
2007-01-07 06:43:25 +00:00
|
|
|
static int mfi_event_class = MFI_EVT_CLASS_INFO;
|
2006-09-20 18:49:35 +00:00
|
|
|
TUNABLE_INT("hw.mfi.event_class", &mfi_event_class);
|
2006-09-07 18:40:49 +00:00
|
|
|
SYSCTL_INT(_hw_mfi, OID_AUTO, event_class, CTLFLAG_RW, &mfi_event_class,
|
|
|
|
0, "event message class");
|
|
|
|
|
2008-05-12 14:09:19 +00:00
|
|
|
static int mfi_max_cmds = 128;
|
|
|
|
TUNABLE_INT("hw.mfi.max_cmds", &mfi_max_cmds);
|
|
|
|
SYSCTL_INT(_hw_mfi, OID_AUTO, max_cmds, CTLFLAG_RD, &mfi_max_cmds,
|
|
|
|
0, "Max commands");
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
static int mfi_detect_jbod_change = 1;
|
|
|
|
TUNABLE_INT("hw.mfi.detect_jbod_change", &mfi_detect_jbod_change);
|
|
|
|
SYSCTL_INT(_hw_mfi, OID_AUTO, detect_jbod_change, CTLFLAG_RW,
|
|
|
|
&mfi_detect_jbod_change, 0, "Detect a change to a JBOD");
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
/* Management interface */
|
|
|
|
static d_open_t mfi_open;
|
|
|
|
static d_close_t mfi_close;
|
|
|
|
static d_ioctl_t mfi_ioctl;
|
2006-05-18 23:30:48 +00:00
|
|
|
static d_poll_t mfi_poll;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
static struct cdevsw mfi_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = 0,
|
|
|
|
.d_open = mfi_open,
|
|
|
|
.d_close = mfi_close,
|
|
|
|
.d_ioctl = mfi_ioctl,
|
2006-05-18 23:30:48 +00:00
|
|
|
.d_poll = mfi_poll,
|
2006-03-25 06:14:32 +00:00
|
|
|
.d_name = "mfi",
|
|
|
|
};
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_MFIBUF, "mfibuf", "Buffers for the MFI driver");
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
#define MFI_INQ_LENGTH SHORT_INQUIRY_LENGTH
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_skinny_dma_info mfi_skinny;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-08-25 23:58:45 +00:00
|
|
|
static void
|
|
|
|
mfi_enable_intr_xscale(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
MFI_WRITE4(sc, MFI_OMSK, 0x01);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_enable_intr_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
2008-11-12 22:44:50 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_1078) {
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_WRITE4(sc, MFI_ODCR0, 0xFFFFFFFF);
|
2008-11-12 22:44:50 +00:00
|
|
|
MFI_WRITE4(sc, MFI_OMSK, ~MFI_1078_EIM);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
else if (sc->mfi_flags & MFI_FLAGS_GEN2) {
|
|
|
|
MFI_WRITE4(sc, MFI_ODCR0, 0xFFFFFFFF);
|
2008-11-12 22:44:50 +00:00
|
|
|
MFI_WRITE4(sc, MFI_OMSK, ~MFI_GEN2_EIM);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
else if (sc->mfi_flags & MFI_FLAGS_SKINNY) {
|
|
|
|
MFI_WRITE4(sc, MFI_OMSK, ~0x00000001);
|
|
|
|
}
|
2007-08-25 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
mfi_read_fw_status_xscale(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
return MFI_READ4(sc, MFI_OMSG0);
|
|
|
|
}
|
2008-11-12 22:44:50 +00:00
|
|
|
|
2007-08-25 23:58:45 +00:00
|
|
|
static int32_t
|
|
|
|
mfi_read_fw_status_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
return MFI_READ4(sc, MFI_OSP0);
|
|
|
|
}
|
|
|
|
|
2008-11-12 22:44:50 +00:00
|
|
|
static int
|
2007-08-25 23:58:45 +00:00
|
|
|
mfi_check_clear_intr_xscale(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
status = MFI_READ4(sc, MFI_OSTS);
|
|
|
|
if ((status & MFI_OSTS_INTR_VALID) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
MFI_WRITE4(sc, MFI_OSTS, status);
|
|
|
|
return 0;
|
2008-08-23 23:30:54 +00:00
|
|
|
}
|
2007-08-25 23:58:45 +00:00
|
|
|
|
2008-11-12 22:44:50 +00:00
|
|
|
static int
|
2007-08-25 23:58:45 +00:00
|
|
|
mfi_check_clear_intr_ppc(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
status = MFI_READ4(sc, MFI_OSTS);
|
2008-11-12 22:44:50 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_1078) {
|
|
|
|
if (!(status & MFI_1078_RM)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
else if (sc->mfi_flags & MFI_FLAGS_GEN2) {
|
2008-11-12 22:44:50 +00:00
|
|
|
if (!(status & MFI_GEN2_RM)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
else if (sc->mfi_flags & MFI_FLAGS_SKINNY) {
|
|
|
|
if (!(status & MFI_SKINNY_RM)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY)
|
|
|
|
MFI_WRITE4(sc, MFI_OSTS, status);
|
|
|
|
else
|
|
|
|
MFI_WRITE4(sc, MFI_ODCR0, status);
|
2007-08-25 23:58:45 +00:00
|
|
|
return 0;
|
2008-08-23 23:30:54 +00:00
|
|
|
}
|
2007-08-25 23:58:45 +00:00
|
|
|
|
2008-11-12 22:44:50 +00:00
|
|
|
static void
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_issue_cmd_xscale(struct mfi_softc *sc, bus_addr_t bus_add, uint32_t frame_cnt)
|
2007-08-25 23:58:45 +00:00
|
|
|
{
|
|
|
|
MFI_WRITE4(sc, MFI_IQP,(bus_add >>3)|frame_cnt);
|
|
|
|
}
|
2008-11-12 22:44:50 +00:00
|
|
|
|
|
|
|
static void
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_issue_cmd_ppc(struct mfi_softc *sc, bus_addr_t bus_add, uint32_t frame_cnt)
|
2007-08-25 23:58:45 +00:00
|
|
|
{
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY) {
|
|
|
|
MFI_WRITE4(sc, MFI_IQPL, (bus_add | frame_cnt <<1)|1 );
|
|
|
|
MFI_WRITE4(sc, MFI_IQPH, 0x00000000);
|
|
|
|
} else {
|
|
|
|
MFI_WRITE4(sc, MFI_IQP, (bus_add | frame_cnt <<1)|1 );
|
|
|
|
}
|
2007-08-25 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
int
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_transition_firmware(struct mfi_softc *sc)
|
|
|
|
{
|
2009-06-24 16:11:29 +00:00
|
|
|
uint32_t fw_state, cur_state;
|
2006-03-25 06:14:32 +00:00
|
|
|
int max_wait, i;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t cur_abs_reg_val = 0;
|
|
|
|
uint32_t prev_abs_reg_val = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
cur_abs_reg_val = sc->mfi_read_fw_status(sc);
|
|
|
|
fw_state = cur_abs_reg_val & MFI_FWSTATE_MASK;
|
2006-03-25 06:14:32 +00:00
|
|
|
while (fw_state != MFI_FWSTATE_READY) {
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->mfi_dev, "Waiting for firmware to "
|
2007-08-25 23:58:45 +00:00
|
|
|
"become ready\n");
|
2006-03-25 06:14:32 +00:00
|
|
|
cur_state = fw_state;
|
|
|
|
switch (fw_state) {
|
|
|
|
case MFI_FWSTATE_FAULT:
|
|
|
|
device_printf(sc->mfi_dev, "Firmware fault\n");
|
|
|
|
return (ENXIO);
|
|
|
|
case MFI_FWSTATE_WAIT_HANDSHAKE:
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY || sc->mfi_flags & MFI_FLAGS_TBOLT)
|
|
|
|
MFI_WRITE4(sc, MFI_SKINNY_IDB, MFI_FWINIT_CLEAR_HANDSHAKE);
|
|
|
|
else
|
|
|
|
MFI_WRITE4(sc, MFI_IDB, MFI_FWINIT_CLEAR_HANDSHAKE);
|
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
|
|
|
case MFI_FWSTATE_OPERATIONAL:
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY || sc->mfi_flags & MFI_FLAGS_TBOLT)
|
|
|
|
MFI_WRITE4(sc, MFI_SKINNY_IDB, 7);
|
|
|
|
else
|
|
|
|
MFI_WRITE4(sc, MFI_IDB, MFI_FWINIT_READY);
|
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
|
|
|
case MFI_FWSTATE_UNDEFINED:
|
|
|
|
case MFI_FWSTATE_BB_INIT:
|
2011-11-04 02:34:52 +00:00
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
|
|
|
break;
|
|
|
|
case MFI_FWSTATE_FW_INIT_2:
|
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
|
|
|
case MFI_FWSTATE_FW_INIT:
|
|
|
|
case MFI_FWSTATE_FLUSH_CACHE:
|
2011-11-04 02:34:52 +00:00
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
|
|
|
break;
|
|
|
|
case MFI_FWSTATE_DEVICE_SCAN:
|
|
|
|
max_wait = MFI_RESET_WAIT_TIME; /* wait for 180 seconds */
|
|
|
|
prev_abs_reg_val = cur_abs_reg_val;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
2011-07-14 20:20:33 +00:00
|
|
|
case MFI_FWSTATE_BOOT_MESSAGE_PENDING:
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY || sc->mfi_flags & MFI_FLAGS_TBOLT)
|
|
|
|
MFI_WRITE4(sc, MFI_SKINNY_IDB, MFI_FWINIT_HOTPLUG);
|
|
|
|
else
|
|
|
|
MFI_WRITE4(sc, MFI_IDB, MFI_FWINIT_HOTPLUG);
|
|
|
|
max_wait = MFI_RESET_WAIT_TIME;
|
2011-07-14 20:20:33 +00:00
|
|
|
break;
|
2006-03-25 06:14:32 +00:00
|
|
|
default:
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "Unknown firmware state %#x\n",
|
2006-03-25 06:14:32 +00:00
|
|
|
fw_state);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
for (i = 0; i < (max_wait * 10); i++) {
|
2011-11-04 02:34:52 +00:00
|
|
|
cur_abs_reg_val = sc->mfi_read_fw_status(sc);
|
|
|
|
fw_state = cur_abs_reg_val & MFI_FWSTATE_MASK;
|
2006-03-25 06:14:32 +00:00
|
|
|
if (fw_state == cur_state)
|
|
|
|
DELAY(100000);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
if (fw_state == MFI_FWSTATE_DEVICE_SCAN) {
|
|
|
|
/* Check the device scanning progress */
|
|
|
|
if (prev_abs_reg_val != cur_abs_reg_val) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
if (fw_state == cur_state) {
|
2011-07-14 20:20:33 +00:00
|
|
|
device_printf(sc->mfi_dev, "Firmware stuck in state "
|
2006-03-25 06:14:32 +00:00
|
|
|
"%#x\n", fw_state);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_addr_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
2011-11-04 02:34:52 +00:00
|
|
|
bus_addr_t *addr;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
addr = arg;
|
|
|
|
*addr = segs[0].ds_addr;
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
int
|
|
|
|
mfi_attach(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
int error, commsz, framessz, sensesz;
|
2006-09-20 06:58:02 +00:00
|
|
|
int frames, unit, max_fw_sge;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t tb_mem_size = 0;
|
2008-12-15 17:11:40 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc == NULL)
|
|
|
|
return EINVAL;
|
2008-12-15 17:11:40 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "Megaraid SAS driver Ver %s \n",
|
|
|
|
MEGASAS_VERSION);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
mtx_init(&sc->mfi_io_lock, "MFI I/O lock", NULL, MTX_DEF);
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_init(&sc->mfi_config_lock, "MFI config");
|
2006-03-25 06:14:32 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_ld_tqh);
|
2011-11-04 02:34:52 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_syspd_tqh);
|
2012-11-06 23:25:06 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_ld_pend_tqh);
|
|
|
|
TAILQ_INIT(&sc->mfi_syspd_pend_tqh);
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_evt_queue);
|
|
|
|
TASK_INIT(&sc->mfi_evt_task, 0, mfi_handle_evt, sc);
|
2012-05-04 16:00:39 +00:00
|
|
|
TASK_INIT(&sc->mfi_map_sync_task, 0, mfi_handle_map_sync, sc);
|
2006-05-18 23:30:48 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_aen_pids);
|
2007-05-16 17:23:36 +00:00
|
|
|
TAILQ_INIT(&sc->mfi_cam_ccbq);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
mfi_initq_free(sc);
|
|
|
|
mfi_initq_ready(sc);
|
|
|
|
mfi_initq_busy(sc);
|
|
|
|
mfi_initq_bio(sc);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->adpreset = 0;
|
|
|
|
sc->last_seq_num = 0;
|
|
|
|
sc->disableOnlineCtrlReset = 1;
|
|
|
|
sc->issuepend_done = 1;
|
|
|
|
sc->hw_crit_error = 0;
|
|
|
|
|
2007-08-25 23:58:45 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_1064R) {
|
|
|
|
sc->mfi_enable_intr = mfi_enable_intr_xscale;
|
|
|
|
sc->mfi_read_fw_status = mfi_read_fw_status_xscale;
|
|
|
|
sc->mfi_check_clear_intr = mfi_check_clear_intr_xscale;
|
|
|
|
sc->mfi_issue_cmd = mfi_issue_cmd_xscale;
|
2012-03-30 23:05:48 +00:00
|
|
|
} else if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_enable_intr = mfi_tbolt_enable_intr_ppc;
|
|
|
|
sc->mfi_disable_intr = mfi_tbolt_disable_intr_ppc;
|
|
|
|
sc->mfi_read_fw_status = mfi_tbolt_read_fw_status_ppc;
|
|
|
|
sc->mfi_check_clear_intr = mfi_tbolt_check_clear_intr_ppc;
|
|
|
|
sc->mfi_issue_cmd = mfi_tbolt_issue_cmd_ppc;
|
|
|
|
sc->mfi_adp_reset = mfi_tbolt_adp_reset;
|
|
|
|
sc->mfi_tbolt = 1;
|
|
|
|
TAILQ_INIT(&sc->mfi_cmd_tbolt_tqh);
|
2012-03-30 23:05:48 +00:00
|
|
|
} else {
|
2007-08-25 23:58:45 +00:00
|
|
|
sc->mfi_enable_intr = mfi_enable_intr_ppc;
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_read_fw_status = mfi_read_fw_status_ppc;
|
2007-08-25 23:58:45 +00:00
|
|
|
sc->mfi_check_clear_intr = mfi_check_clear_intr_ppc;
|
|
|
|
sc->mfi_issue_cmd = mfi_issue_cmd_ppc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
/* Before we get too far, see if the firmware is working */
|
|
|
|
if ((error = mfi_transition_firmware(sc)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Firmware not in READY state, "
|
|
|
|
"error %d\n", error);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
/* Start: LSIP200113393 */
|
2011-11-04 02:34:52 +00:00
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MEGASAS_MAX_NAME*sizeof(bus_addr_t), /* maxsize */
|
|
|
|
1, /* msegments */
|
|
|
|
MEGASAS_MAX_NAME*sizeof(bus_addr_t), /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->verbuf_h_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate verbuf_h_dmat DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->verbuf_h_dmat, (void **)&sc->verbuf,
|
|
|
|
BUS_DMA_NOWAIT, &sc->verbuf_h_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate verbuf_h_dmamap memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->verbuf, MEGASAS_MAX_NAME*sizeof(bus_addr_t));
|
|
|
|
bus_dmamap_load(sc->verbuf_h_dmat, sc->verbuf_h_dmamap,
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->verbuf, MEGASAS_MAX_NAME*sizeof(bus_addr_t),
|
|
|
|
mfi_addr_cb, &sc->verbuf_h_busaddr, 0);
|
|
|
|
/* End: LSIP200113393 */
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get information needed for sizing the contiguous memory for the
|
|
|
|
* frame pool. Size down the sgl parameter since we know that
|
|
|
|
* we will never need more than what's required for MAXPHYS.
|
|
|
|
* It would be nice if these constants were available at runtime
|
|
|
|
* instead of compile time.
|
|
|
|
*/
|
2007-08-25 23:58:45 +00:00
|
|
|
status = sc->mfi_read_fw_status(sc);
|
2006-03-25 06:14:32 +00:00
|
|
|
sc->mfi_max_fw_cmds = status & MFI_FWSTATE_MAXCMD_MASK;
|
2006-09-20 06:58:02 +00:00
|
|
|
max_fw_sge = (status & MFI_FWSTATE_MAXSGL_MASK) >> 16;
|
Separate the parallel scsi knowledge out of the core of the XPT, and
modularize it so that new transports can be created.
Add a transport for SATA
Add a periph+protocol layer for ATA
Add a driver for AHCI-compliant hardware.
Add a maxio field to CAM so that drivers can advertise their max
I/O capability. Modify various drivers so that they are insulated
from the value of MAXPHYS.
The new ATA/SATA code supports AHCI-compliant hardware, and will override
the classic ATA driver if it is loaded as a module at boot time or compiled
into the kernel. The stack now support NCQ (tagged queueing) for increased
performance on modern SATA drives. It also supports port multipliers.
ATA drives are accessed via 'ada' device nodes. ATAPI drives are
accessed via 'cd' device nodes. They can all be enumerated and manipulated
via camcontrol, just like SCSI drives. SCSI commands are not translated to
their ATA equivalents; ATA native commands are used throughout the entire
stack, including camcontrol. See the camcontrol manpage for further
details. Testing this code may require that you update your fstab, and
possibly modify your BIOS to enable AHCI functionality, if available.
This code is very experimental at the moment. The userland ABI/API has
changed, so applications will need to be recompiled. It may change
further in the near future. The 'ada' device name may also change as
more infrastructure is completed in this project. The goal is to
eventually put all CAM busses and devices until newbus, allowing for
interesting topology and management options.
Few functional changes will be seen with existing SCSI/SAS/FC drivers,
though the userland ABI has still changed. In the future, transports
specific modules for SAS and FC may appear in order to better support
the topologies and capabilities of these technologies.
The modularization of CAM and the addition of the ATA/SATA modules is
meant to break CAM out of the mold of being specific to SCSI, letting it
grow to be a framework for arbitrary transports and protocols. It also
allows drivers to be written to support discrete hardware without
jeopardizing the stability of non-related hardware. While only an AHCI
driver is provided now, a Silicon Image driver is also in the works.
Drivers for ICH1-4, ICH5-6, PIIX, classic IDE, and any other hardware
is possible and encouraged. Help with new transports is also encouraged.
Submitted by: scottl, mav
Approved by: re
2009-07-10 08:18:08 +00:00
|
|
|
sc->mfi_max_sge = min(max_fw_sge, ((MFI_MAXPHYS / PAGE_SIZE) + 1));
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* ThunderBolt Support get the contiguous memory */
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_tbolt_init_globals(sc);
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "MaxCmd = %x MaxSgl = %x state = %x \n",
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_max_fw_cmds, sc->mfi_max_sge, status);
|
|
|
|
tb_mem_size = mfi_tbolt_get_memory_requirement(sc);
|
|
|
|
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
2012-03-30 23:05:48 +00:00
|
|
|
tb_mem_size, /* maxsize */
|
2011-11-04 02:34:52 +00:00
|
|
|
1, /* msegments */
|
2012-03-30 23:05:48 +00:00
|
|
|
tb_mem_size, /* maxsegsize */
|
2011-11-04 02:34:52 +00:00
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_tb_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate comms DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->mfi_tb_dmat, (void **)&sc->request_message_pool,
|
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_tb_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate comms memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->request_message_pool, tb_mem_size);
|
|
|
|
bus_dmamap_load(sc->mfi_tb_dmat, sc->mfi_tb_dmamap,
|
|
|
|
sc->request_message_pool, tb_mem_size, mfi_addr_cb, &sc->mfi_tb_busaddr, 0);
|
|
|
|
|
|
|
|
/* For ThunderBolt memory init */
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
2012-03-30 23:05:48 +00:00
|
|
|
0x100, 0, /* alignmnt, boundary */
|
2011-11-04 02:34:52 +00:00
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
2012-03-30 23:05:48 +00:00
|
|
|
NULL, NULL, /* filter, filterarg */
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_FRAME_SIZE, /* maxsize */
|
2012-03-30 23:05:48 +00:00
|
|
|
1, /* msegments */
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_FRAME_SIZE, /* maxsegsize */
|
2012-03-30 23:05:48 +00:00
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
2011-11-04 02:34:52 +00:00
|
|
|
&sc->mfi_tb_init_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate init DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->mfi_tb_init_dmat, (void **)&sc->mfi_tb_init,
|
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_tb_init_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate init memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->mfi_tb_init, MFI_FRAME_SIZE);
|
|
|
|
bus_dmamap_load(sc->mfi_tb_init_dmat, sc->mfi_tb_init_dmamap,
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->mfi_tb_init, MFI_FRAME_SIZE, mfi_addr_cb,
|
|
|
|
&sc->mfi_tb_init_busaddr, 0);
|
|
|
|
if (mfi_tbolt_init_desc_pool(sc, sc->request_message_pool,
|
|
|
|
tb_mem_size)) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Thunderbolt pool preparation error\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Allocate DMA memory mapping for MPI2 IOC Init descriptor,
|
|
|
|
we are taking it diffrent from what we have allocated for Request
|
|
|
|
and reply descriptors to avoid confusion later
|
|
|
|
*/
|
|
|
|
tb_mem_size = sizeof(struct MPI2_IOC_INIT_REQUEST);
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
2012-03-30 23:05:48 +00:00
|
|
|
tb_mem_size, /* maxsize */
|
2011-11-04 02:34:52 +00:00
|
|
|
1, /* msegments */
|
2012-03-30 23:05:48 +00:00
|
|
|
tb_mem_size, /* maxsegsize */
|
2011-11-04 02:34:52 +00:00
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_tb_ioc_init_dmat)) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Cannot allocate comms DMA tag\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (bus_dmamem_alloc(sc->mfi_tb_ioc_init_dmat,
|
|
|
|
(void **)&sc->mfi_tb_ioc_init_desc,
|
2011-11-04 02:34:52 +00:00
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_tb_ioc_init_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate comms memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->mfi_tb_ioc_init_desc, tb_mem_size);
|
|
|
|
bus_dmamap_load(sc->mfi_tb_ioc_init_dmat, sc->mfi_tb_ioc_init_dmamap,
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->mfi_tb_ioc_init_desc, tb_mem_size, mfi_addr_cb,
|
|
|
|
&sc->mfi_tb_ioc_init_busaddr, 0);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
/*
|
|
|
|
* Create the dma tag for data buffers. Used both for block I/O
|
|
|
|
* and for various internal data queries.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_max_sge, /* nsegments */
|
2006-03-25 06:14:32 +00:00
|
|
|
BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
busdma_lock_mutex, /* lockfunc */
|
|
|
|
&sc->mfi_io_lock, /* lockfuncarg */
|
|
|
|
&sc->mfi_buffer_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate buffer DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate DMA memory for the comms queues. Keep it under 4GB for
|
|
|
|
* efficiency. The mfi_hwcomms struct includes space for 1 reply queue
|
|
|
|
* entry, so the calculated size here will be will be 1 more than
|
|
|
|
* mfi_max_fw_cmds. This is apparently a requirement of the hardware.
|
|
|
|
*/
|
|
|
|
commsz = (sizeof(uint32_t) * sc->mfi_max_fw_cmds) +
|
|
|
|
sizeof(struct mfi_hwcomms);
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
commsz, /* maxsize */
|
|
|
|
1, /* msegments */
|
|
|
|
commsz, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_comms_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate comms DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->mfi_comms_dmat, (void **)&sc->mfi_comms,
|
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_comms_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate comms memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->mfi_comms, commsz);
|
|
|
|
bus_dmamap_load(sc->mfi_comms_dmat, sc->mfi_comms_dmamap,
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_comms, commsz, mfi_addr_cb, &sc->mfi_comms_busaddr, 0);
|
2006-03-25 06:14:32 +00:00
|
|
|
/*
|
|
|
|
* Allocate DMA memory for the command frames. Keep them in the
|
2006-09-20 06:58:02 +00:00
|
|
|
* lower 4GB for efficiency. Calculate the size of the commands at
|
|
|
|
* the same time; each command is one 64 byte frame plus a set of
|
|
|
|
* additional frames for holding sg lists or other data.
|
2006-03-25 06:14:32 +00:00
|
|
|
* The assumption here is that the SG list will start at the second
|
2006-09-20 06:58:02 +00:00
|
|
|
* frame and not use the unused bytes in the first frame. While this
|
|
|
|
* isn't technically correct, it simplifies the calculation and allows
|
|
|
|
* for command frames that might be larger than an mfi_io_frame.
|
2006-03-25 06:14:32 +00:00
|
|
|
*/
|
|
|
|
if (sizeof(bus_addr_t) == 8) {
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_sge_size = sizeof(struct mfi_sg64);
|
2006-03-25 06:14:32 +00:00
|
|
|
sc->mfi_flags |= MFI_FLAGS_SG64;
|
|
|
|
} else {
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_sge_size = sizeof(struct mfi_sg32);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY)
|
|
|
|
sc->mfi_sge_size = sizeof(struct mfi_sg_skinny);
|
2006-09-20 06:58:02 +00:00
|
|
|
frames = (sc->mfi_sge_size * sc->mfi_max_sge - 1) / MFI_FRAME_SIZE + 2;
|
|
|
|
sc->mfi_cmd_size = frames * MFI_FRAME_SIZE;
|
|
|
|
framessz = sc->mfi_cmd_size * sc->mfi_max_fw_cmds;
|
2006-03-25 06:14:32 +00:00
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
64, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
framessz, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
framessz, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_frames_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate frame DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->mfi_frames_dmat, (void **)&sc->mfi_frames,
|
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_frames_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate frames memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bzero(sc->mfi_frames, framessz);
|
|
|
|
bus_dmamap_load(sc->mfi_frames_dmat, sc->mfi_frames_dmamap,
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_frames, framessz, mfi_addr_cb, &sc->mfi_frames_busaddr,0);
|
2006-03-25 06:14:32 +00:00
|
|
|
/*
|
|
|
|
* Allocate DMA memory for the frame sense data. Keep them in the
|
|
|
|
* lower 4GB for efficiency
|
|
|
|
*/
|
|
|
|
sensesz = sc->mfi_max_fw_cmds * MFI_SENSE_LEN;
|
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
4, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
sensesz, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
sensesz, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_sense_dmat)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate sense DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->mfi_sense_dmat, (void **)&sc->mfi_sense,
|
|
|
|
BUS_DMA_NOWAIT, &sc->mfi_sense_dmamap)) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot allocate sense memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
bus_dmamap_load(sc->mfi_sense_dmat, sc->mfi_sense_dmamap,
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_sense, sensesz, mfi_addr_cb, &sc->mfi_sense_busaddr, 0);
|
2006-03-25 06:14:32 +00:00
|
|
|
if ((error = mfi_alloc_commands(sc)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Before moving the FW to operational state, check whether
|
|
|
|
* hostmemory is required by the FW or not
|
|
|
|
*/
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* ThunderBolt MFI_IOC2 INIT */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_disable_intr(sc);
|
2012-03-30 23:05:48 +00:00
|
|
|
if ((error = mfi_tbolt_init_MFI_queue(sc)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"TB Init has failed with error %d\n",error);
|
2011-11-04 02:34:52 +00:00
|
|
|
return error;
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if ((error = mfi_tbolt_alloc_cmd(sc)) != 0)
|
2011-11-04 02:34:52 +00:00
|
|
|
return error;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (bus_setup_intr(sc->mfi_dev, sc->mfi_irq,
|
|
|
|
INTR_MPSAFE|INTR_TYPE_BIO, NULL, mfi_intr_tbolt, sc,
|
|
|
|
&sc->mfi_intr)) {
|
2011-11-04 02:34:52 +00:00
|
|
|
device_printf(sc->mfi_dev, "Cannot set up interrupt\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
sc->mfi_intr_ptr = mfi_intr_tbolt;
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_enable_intr(sc);
|
2012-03-30 23:05:48 +00:00
|
|
|
} else {
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((error = mfi_comms_init(sc)) != 0)
|
|
|
|
return (error);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (bus_setup_intr(sc->mfi_dev, sc->mfi_irq,
|
|
|
|
INTR_MPSAFE|INTR_TYPE_BIO, NULL, mfi_intr, sc, &sc->mfi_intr)) {
|
2011-11-04 02:34:52 +00:00
|
|
|
device_printf(sc->mfi_dev, "Cannot set up interrupt\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
sc->mfi_intr_ptr = mfi_intr;
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_enable_intr(sc);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((error = mfi_get_controller_info(sc)) != 0)
|
|
|
|
return (error);
|
|
|
|
sc->disableOnlineCtrlReset = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
/* Register a config hook to probe the bus for arrays */
|
|
|
|
sc->mfi_ich.ich_func = mfi_startup;
|
|
|
|
sc->mfi_ich.ich_arg = sc;
|
|
|
|
if (config_intrhook_establish(&sc->mfi_ich) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Cannot establish configuration "
|
|
|
|
"hook\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2013-02-27 00:35:40 +00:00
|
|
|
if ((error = mfi_aen_setup(sc, 0), 0) != 0)
|
2011-11-04 02:34:52 +00:00
|
|
|
return (error);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a shutdown handler.
|
|
|
|
*/
|
|
|
|
if ((sc->mfi_eh = EVENTHANDLER_REGISTER(shutdown_final, mfi_shutdown,
|
|
|
|
sc, SHUTDOWN_PRI_DEFAULT)) == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Warning: shutdown event "
|
|
|
|
"registration failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the control device for doing management
|
|
|
|
*/
|
|
|
|
unit = device_get_unit(sc->mfi_dev);
|
|
|
|
sc->mfi_cdev = make_dev(&mfi_cdevsw, unit, UID_ROOT, GID_OPERATOR,
|
|
|
|
0640, "mfi%d", unit);
|
2006-05-18 23:30:48 +00:00
|
|
|
if (unit == 0)
|
|
|
|
make_dev_alias(sc->mfi_cdev, "megaraid_sas_ioctl_node");
|
2006-03-25 06:14:32 +00:00
|
|
|
if (sc->mfi_cdev != NULL)
|
|
|
|
sc->mfi_cdev->si_drv1 = sc;
|
2007-08-13 19:29:17 +00:00
|
|
|
SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->mfi_dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->mfi_dev)),
|
|
|
|
OID_AUTO, "delete_busy_volumes", CTLFLAG_RW,
|
|
|
|
&sc->mfi_delete_busy_volumes, 0, "Allow removal of busy volumes");
|
|
|
|
SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->mfi_dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->mfi_dev)),
|
|
|
|
OID_AUTO, "keep_deleted_volumes", CTLFLAG_RW,
|
|
|
|
&sc->mfi_keep_deleted_volumes, 0,
|
|
|
|
"Don't detach the mfid device for a busy volume that is deleted");
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-05-16 17:23:36 +00:00
|
|
|
device_add_child(sc->mfi_dev, "mfip", -1);
|
|
|
|
bus_generic_attach(sc->mfi_dev);
|
|
|
|
|
2006-09-25 11:35:34 +00:00
|
|
|
/* Start the timeout watchdog */
|
2008-04-16 16:47:14 +00:00
|
|
|
callout_init(&sc->mfi_watchdog_callout, CALLOUT_MPSAFE);
|
2006-09-25 11:35:34 +00:00
|
|
|
callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz,
|
|
|
|
mfi_timeout, sc);
|
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
|
|
|
mfi_tbolt_sync_map_info(sc);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mfi_alloc_commands(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
int i, ncmds;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should we allocate all the commands up front, or allocate on
|
|
|
|
* demand later like 'aac' does?
|
|
|
|
*/
|
2008-05-12 14:09:19 +00:00
|
|
|
ncmds = MIN(mfi_max_cmds, sc->mfi_max_fw_cmds);
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->mfi_dev, "Max fw cmds= %d, sizing driver "
|
|
|
|
"pool to %d\n", sc->mfi_max_fw_cmds, ncmds);
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
sc->mfi_commands = malloc(sizeof(struct mfi_command) * ncmds, M_MFIBUF,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
for (i = 0; i < ncmds; i++) {
|
|
|
|
cm = &sc->mfi_commands[i];
|
2006-05-18 23:30:48 +00:00
|
|
|
cm->cm_frame = (union mfi_frame *)((uintptr_t)sc->mfi_frames +
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_cmd_size * i);
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_frame_busaddr = sc->mfi_frames_busaddr +
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_cmd_size * i;
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_frame->header.context = i;
|
|
|
|
cm->cm_sense = &sc->mfi_sense[i];
|
|
|
|
cm->cm_sense_busaddr= sc->mfi_sense_busaddr + MFI_SENSE_LEN * i;
|
|
|
|
cm->cm_sc = sc;
|
2006-09-25 11:35:34 +00:00
|
|
|
cm->cm_index = i;
|
2006-03-25 06:14:32 +00:00
|
|
|
if (bus_dmamap_create(sc->mfi_buffer_dmat, 0,
|
2011-11-04 02:34:52 +00:00
|
|
|
&cm->cm_dmamap) == 0) {
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
sc->mfi_total_cmds++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-05-16 17:23:36 +00:00
|
|
|
void
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(struct mfi_command *cm)
|
|
|
|
{
|
2006-10-16 04:18:38 +00:00
|
|
|
struct mfi_frame_header *hdr;
|
2006-03-25 06:14:32 +00:00
|
|
|
uint32_t *hdr_data;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_assert(&cm->cm_sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
/*
|
|
|
|
* Zero out the important fields of the frame, but make sure the
|
2007-01-02 04:12:34 +00:00
|
|
|
* context field is preserved. For efficiency, handle the fields
|
|
|
|
* as 32 bit words. Clear out the first S/G entry too for safety.
|
2006-03-25 06:14:32 +00:00
|
|
|
*/
|
2006-10-16 04:18:38 +00:00
|
|
|
hdr = &cm->cm_frame->header;
|
2008-02-02 17:29:28 +00:00
|
|
|
if (cm->cm_data != NULL && hdr->sg_count) {
|
2006-10-16 04:18:38 +00:00
|
|
|
cm->cm_sg->sg32[0].len = 0;
|
|
|
|
cm->cm_sg->sg32[0].addr = 0;
|
|
|
|
}
|
2007-01-02 04:12:34 +00:00
|
|
|
|
|
|
|
hdr_data = (uint32_t *)cm->cm_frame;
|
|
|
|
hdr_data[0] = 0; /* cmd, sense_len, cmd_status, scsi_status */
|
|
|
|
hdr_data[1] = 0; /* target_id, lun_id, cdb_len, sg_count */
|
|
|
|
hdr_data[4] = 0; /* flags, timeout */
|
|
|
|
hdr_data[5] = 0; /* data_len */
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_extra_frames = 0;
|
|
|
|
cm->cm_flags = 0;
|
|
|
|
cm->cm_complete = NULL;
|
|
|
|
cm->cm_private = NULL;
|
2007-05-16 17:23:36 +00:00
|
|
|
cm->cm_data = NULL;
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_sg = 0;
|
|
|
|
cm->cm_total_frame_size = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->retry_for_fw_reset = 0;
|
2006-10-16 04:18:38 +00:00
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_enqueue_free(cm);
|
|
|
|
}
|
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
int
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_dcmd_command(struct mfi_softc *sc, struct mfi_command **cmp,
|
|
|
|
uint32_t opcode, void **bufp, size_t bufsize)
|
2006-06-20 21:06:05 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_dcmd_frame *dcmd;
|
|
|
|
void *buf = NULL;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
cm = mfi_dequeue_free(sc);
|
|
|
|
if (cm == NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Zero out the MFI frame */
|
|
|
|
context = cm->cm_frame->header.context;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
if ((bufsize > 0) && (bufp != NULL)) {
|
|
|
|
if (*bufp == NULL) {
|
|
|
|
buf = malloc(bufsize, M_MFIBUF, M_NOWAIT|M_ZERO);
|
|
|
|
if (buf == NULL) {
|
|
|
|
mfi_release_command(cm);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
*bufp = buf;
|
|
|
|
} else {
|
|
|
|
buf = *bufp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
bzero(dcmd->mbox, MFI_MBOX_SIZE);
|
|
|
|
dcmd->header.cmd = MFI_CMD_DCMD;
|
|
|
|
dcmd->header.timeout = 0;
|
|
|
|
dcmd->header.flags = 0;
|
|
|
|
dcmd->header.data_len = bufsize;
|
2011-11-04 02:34:52 +00:00
|
|
|
dcmd->header.scsi_status = 0;
|
2006-06-20 21:06:05 +00:00
|
|
|
dcmd->opcode = opcode;
|
|
|
|
cm->cm_sg = &dcmd->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_DCMD_FRAME_SIZE;
|
|
|
|
cm->cm_flags = 0;
|
|
|
|
cm->cm_data = buf;
|
|
|
|
cm->cm_private = buf;
|
|
|
|
cm->cm_len = bufsize;
|
|
|
|
|
|
|
|
*cmp = cm;
|
|
|
|
if ((bufp != NULL) && (*bufp == NULL) && (buf != NULL))
|
|
|
|
*bufp = buf;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
static int
|
|
|
|
mfi_comms_init(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_init_frame *init;
|
|
|
|
struct mfi_init_qinfo *qinfo;
|
|
|
|
int error;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Zero out the MFI frame */
|
|
|
|
context = cm->cm_frame->header.context;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
/*
|
|
|
|
* Abuse the SG list area of the frame to hold the init_qinfo
|
|
|
|
* object;
|
|
|
|
*/
|
|
|
|
init = &cm->cm_frame->init;
|
|
|
|
qinfo = (struct mfi_init_qinfo *)((uintptr_t)init + MFI_FRAME_SIZE);
|
|
|
|
|
|
|
|
bzero(qinfo, sizeof(struct mfi_init_qinfo));
|
|
|
|
qinfo->rq_entries = sc->mfi_max_fw_cmds + 1;
|
|
|
|
qinfo->rq_addr_lo = sc->mfi_comms_busaddr +
|
|
|
|
offsetof(struct mfi_hwcomms, hw_reply_q);
|
|
|
|
qinfo->pi_addr_lo = sc->mfi_comms_busaddr +
|
|
|
|
offsetof(struct mfi_hwcomms, hw_pi);
|
|
|
|
qinfo->ci_addr_lo = sc->mfi_comms_busaddr +
|
|
|
|
offsetof(struct mfi_hwcomms, hw_ci);
|
|
|
|
|
|
|
|
init->header.cmd = MFI_CMD_INIT;
|
|
|
|
init->header.data_len = sizeof(struct mfi_init_qinfo);
|
|
|
|
init->qinfo_new_addr_lo = cm->cm_frame_busaddr + MFI_FRAME_SIZE;
|
2006-11-18 07:33:53 +00:00
|
|
|
cm->cm_data = NULL;
|
|
|
|
cm->cm_flags = MFI_CMD_POLLED;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-11-18 07:33:53 +00:00
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
2006-03-25 06:14:32 +00:00
|
|
|
device_printf(sc->mfi_dev, "failed to send init command\n");
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
mfi_release_command(cm);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mfi_get_controller_info(struct mfi_softc *sc)
|
|
|
|
{
|
2006-06-20 21:06:05 +00:00
|
|
|
struct mfi_command *cm = NULL;
|
|
|
|
struct mfi_ctrl_info *ci = NULL;
|
2006-03-25 06:14:32 +00:00
|
|
|
uint32_t max_sectors_1, max_sectors_2;
|
|
|
|
int error;
|
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_CTRL_GETINFO,
|
|
|
|
(void **)&ci, sizeof(*ci));
|
|
|
|
if (error)
|
|
|
|
goto out;
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_POLLED;
|
|
|
|
|
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to get controller info\n");
|
2006-09-20 06:58:02 +00:00
|
|
|
sc->mfi_max_io = (sc->mfi_max_sge - 1) * PAGE_SIZE /
|
2006-03-25 06:14:32 +00:00
|
|
|
MFI_SECTOR_LEN;
|
2006-06-20 21:06:05 +00:00
|
|
|
error = 0;
|
|
|
|
goto out;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
max_sectors_1 = (1 << ci->stripe_sz_ops.max) * ci->max_strips_per_io;
|
2006-03-25 06:14:32 +00:00
|
|
|
max_sectors_2 = ci->max_request_size;
|
|
|
|
sc->mfi_max_io = min(max_sectors_1, max_sectors_2);
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->disableOnlineCtrlReset =
|
|
|
|
ci->properties.OnOffProperties.disableOnlineCtrlReset;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
out:
|
|
|
|
if (ci)
|
|
|
|
free(ci, M_MFIBUF);
|
|
|
|
if (cm)
|
|
|
|
mfi_release_command(cm);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
static int
|
2006-06-20 21:06:05 +00:00
|
|
|
mfi_get_log_state(struct mfi_softc *sc, struct mfi_evt_log_state **log_state)
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
2006-06-20 23:08:35 +00:00
|
|
|
struct mfi_command *cm = NULL;
|
2006-05-18 23:30:48 +00:00
|
|
|
int error;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-06-20 21:06:05 +00:00
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_CTRL_EVENT_GETINFO,
|
|
|
|
(void **)log_state, sizeof(**log_state));
|
|
|
|
if (error)
|
|
|
|
goto out;
|
2006-06-20 22:17:54 +00:00
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_POLLED;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
2006-06-20 20:41:54 +00:00
|
|
|
device_printf(sc->mfi_dev, "Failed to get log state\n");
|
2006-06-20 21:06:05 +00:00
|
|
|
goto out;
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
out:
|
2006-06-20 23:08:35 +00:00
|
|
|
if (cm)
|
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
int
|
2006-05-18 23:30:48 +00:00
|
|
|
mfi_aen_setup(struct mfi_softc *sc, uint32_t seq_start)
|
|
|
|
{
|
2006-06-20 21:06:05 +00:00
|
|
|
struct mfi_evt_log_state *log_state = NULL;
|
2006-05-18 23:30:48 +00:00
|
|
|
union mfi_evt class_locale;
|
|
|
|
int error = 0;
|
|
|
|
uint32_t seq;
|
|
|
|
|
|
|
|
class_locale.members.reserved = 0;
|
2006-09-07 18:40:49 +00:00
|
|
|
class_locale.members.locale = mfi_event_locale;
|
2011-06-02 00:43:16 +00:00
|
|
|
class_locale.members.evt_class = mfi_event_class;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
if (seq_start == 0) {
|
|
|
|
error = mfi_get_log_state(sc, &log_state);
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->mfi_boot_seq_num = log_state->boot_seq_num;
|
2006-06-20 21:06:05 +00:00
|
|
|
if (error) {
|
|
|
|
if (log_state)
|
|
|
|
free(log_state, M_MFIBUF);
|
2006-05-18 23:30:48 +00:00
|
|
|
return (error);
|
2006-06-20 21:06:05 +00:00
|
|
|
}
|
2008-06-26 22:33:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk through any events that fired since the last
|
|
|
|
* shutdown.
|
|
|
|
*/
|
|
|
|
mfi_parse_entries(sc, log_state->shutdown_seq_num,
|
|
|
|
log_state->newest_seq_num);
|
|
|
|
seq = log_state->newest_seq_num;
|
2006-05-18 23:30:48 +00:00
|
|
|
} else
|
|
|
|
seq = seq_start;
|
|
|
|
mfi_aen_register(sc, seq, class_locale.word);
|
2006-06-20 21:06:05 +00:00
|
|
|
free(log_state, M_MFIBUF);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
int
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_wait_command(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
cm->cm_complete = NULL;
|
|
|
|
|
2007-06-04 16:39:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MegaCli can issue a DCMD of 0. In this case do nothing
|
|
|
|
* and return 0 to it as status
|
|
|
|
*/
|
|
|
|
if (cm->cm_frame->dcmd.opcode == 0) {
|
|
|
|
cm->cm_frame->header.cmd_status = MFI_STAT_OK;
|
|
|
|
cm->cm_error = 0;
|
|
|
|
return (cm->cm_error);
|
|
|
|
}
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_enqueue_ready(cm);
|
|
|
|
mfi_startio(sc);
|
2007-06-04 16:39:22 +00:00
|
|
|
if ((cm->cm_flags & MFI_CMD_COMPLETED) == 0)
|
|
|
|
msleep(cm, &sc->mfi_io_lock, PRIBIO, "mfiwait", 0);
|
|
|
|
return (cm->cm_error);
|
2006-06-20 22:41:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
void
|
|
|
|
mfi_free(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
int i;
|
|
|
|
|
2006-09-25 11:35:34 +00:00
|
|
|
callout_drain(&sc->mfi_watchdog_callout);
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
if (sc->mfi_cdev != NULL)
|
|
|
|
destroy_dev(sc->mfi_cdev);
|
|
|
|
|
|
|
|
if (sc->mfi_total_cmds != 0) {
|
|
|
|
for (i = 0; i < sc->mfi_total_cmds; i++) {
|
|
|
|
cm = &sc->mfi_commands[i];
|
|
|
|
bus_dmamap_destroy(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
}
|
|
|
|
free(sc->mfi_commands, M_MFIBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->mfi_intr)
|
|
|
|
bus_teardown_intr(sc->mfi_dev, sc->mfi_irq, sc->mfi_intr);
|
|
|
|
if (sc->mfi_irq != NULL)
|
|
|
|
bus_release_resource(sc->mfi_dev, SYS_RES_IRQ, sc->mfi_irq_rid,
|
|
|
|
sc->mfi_irq);
|
|
|
|
|
|
|
|
if (sc->mfi_sense_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->mfi_sense_dmat, sc->mfi_sense_dmamap);
|
|
|
|
if (sc->mfi_sense != NULL)
|
|
|
|
bus_dmamem_free(sc->mfi_sense_dmat, sc->mfi_sense,
|
|
|
|
sc->mfi_sense_dmamap);
|
|
|
|
if (sc->mfi_sense_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_sense_dmat);
|
|
|
|
|
|
|
|
if (sc->mfi_frames_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->mfi_frames_dmat, sc->mfi_frames_dmamap);
|
|
|
|
if (sc->mfi_frames != NULL)
|
|
|
|
bus_dmamem_free(sc->mfi_frames_dmat, sc->mfi_frames,
|
|
|
|
sc->mfi_frames_dmamap);
|
|
|
|
if (sc->mfi_frames_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_frames_dmat);
|
|
|
|
|
|
|
|
if (sc->mfi_comms_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->mfi_comms_dmat, sc->mfi_comms_dmamap);
|
|
|
|
if (sc->mfi_comms != NULL)
|
|
|
|
bus_dmamem_free(sc->mfi_comms_dmat, sc->mfi_comms,
|
|
|
|
sc->mfi_comms_dmamap);
|
|
|
|
if (sc->mfi_comms_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_comms_dmat);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* ThunderBolt contiguous memory free here */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_tb_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->mfi_tb_dmat, sc->mfi_tb_dmamap);
|
|
|
|
if (sc->request_message_pool != NULL)
|
|
|
|
bus_dmamem_free(sc->mfi_tb_dmat, sc->request_message_pool,
|
|
|
|
sc->mfi_tb_dmamap);
|
|
|
|
if (sc->mfi_tb_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_tb_dmat);
|
2012-03-30 23:05:48 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Version buffer memory free */
|
2012-03-30 23:05:48 +00:00
|
|
|
/* Start LSIP200113393 */
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->verbuf_h_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->verbuf_h_dmat, sc->verbuf_h_dmamap);
|
|
|
|
if (sc->verbuf != NULL)
|
|
|
|
bus_dmamem_free(sc->verbuf_h_dmat, sc->verbuf,
|
|
|
|
sc->verbuf_h_dmamap);
|
|
|
|
if (sc->verbuf_h_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->verbuf_h_dmat);
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
/* End LSIP200113393 */
|
|
|
|
/* ThunderBolt INIT packet memory Free */
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_tb_init_busaddr != 0)
|
|
|
|
bus_dmamap_unload(sc->mfi_tb_init_dmat, sc->mfi_tb_init_dmamap);
|
|
|
|
if (sc->mfi_tb_init != NULL)
|
|
|
|
bus_dmamem_free(sc->mfi_tb_init_dmat, sc->mfi_tb_init,
|
|
|
|
sc->mfi_tb_init_dmamap);
|
|
|
|
if (sc->mfi_tb_init_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_tb_init_dmat);
|
|
|
|
|
|
|
|
/* ThunderBolt IOC Init Desc memory free here */
|
|
|
|
if (sc->mfi_tb_ioc_init_busaddr != 0)
|
2012-03-30 23:05:48 +00:00
|
|
|
bus_dmamap_unload(sc->mfi_tb_ioc_init_dmat,
|
|
|
|
sc->mfi_tb_ioc_init_dmamap);
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_tb_ioc_init_desc != NULL)
|
2012-03-30 23:05:48 +00:00
|
|
|
bus_dmamem_free(sc->mfi_tb_ioc_init_dmat,
|
|
|
|
sc->mfi_tb_ioc_init_desc,
|
|
|
|
sc->mfi_tb_ioc_init_dmamap);
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_tb_ioc_init_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_tb_ioc_init_dmat);
|
2012-03-30 23:05:48 +00:00
|
|
|
for (int i = 0; i < sc->mfi_max_fw_cmds; i++) {
|
|
|
|
if (sc->mfi_cmd_pool_tbolt != NULL) {
|
|
|
|
if (sc->mfi_cmd_pool_tbolt[i] != NULL) {
|
|
|
|
free(sc->mfi_cmd_pool_tbolt[i],
|
|
|
|
M_MFIBUF);
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->mfi_cmd_pool_tbolt[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->mfi_cmd_pool_tbolt != NULL) {
|
2011-11-04 02:34:52 +00:00
|
|
|
free(sc->mfi_cmd_pool_tbolt, M_MFIBUF);
|
|
|
|
sc->mfi_cmd_pool_tbolt = NULL;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->request_desc_pool != NULL) {
|
2011-11-04 02:34:52 +00:00
|
|
|
free(sc->request_desc_pool, M_MFIBUF);
|
|
|
|
sc->request_desc_pool = NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
if (sc->mfi_buffer_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_buffer_dmat);
|
|
|
|
if (sc->mfi_parent_dmat != NULL)
|
|
|
|
bus_dma_tag_destroy(sc->mfi_parent_dmat);
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
if (mtx_initialized(&sc->mfi_io_lock)) {
|
2006-03-25 06:14:32 +00:00
|
|
|
mtx_destroy(&sc->mfi_io_lock);
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_destroy(&sc->mfi_config_lock);
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_startup(void *arg)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct mfi_softc *)arg;
|
|
|
|
|
|
|
|
config_intrhook_disestablish(&sc->mfi_ich);
|
|
|
|
|
2007-08-25 23:58:45 +00:00
|
|
|
sc->mfi_enable_intr(sc);
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_xlock(&sc->mfi_config_lock);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_ldprobe(sc);
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->mfi_flags & MFI_FLAGS_SKINNY)
|
|
|
|
mfi_syspdprobe(sc);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_xunlock(&sc->mfi_config_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
struct mfi_command *cm;
|
2007-08-25 23:58:45 +00:00
|
|
|
uint32_t pi, ci, context;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
sc = (struct mfi_softc *)arg;
|
|
|
|
|
2007-08-25 23:58:45 +00:00
|
|
|
if (sc->mfi_check_clear_intr(sc))
|
2006-03-25 06:14:32 +00:00
|
|
|
return;
|
2006-10-16 04:18:38 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
restart:
|
2006-03-25 06:14:32 +00:00
|
|
|
pi = sc->mfi_comms->hw_pi;
|
|
|
|
ci = sc->mfi_comms->hw_ci;
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
while (ci != pi) {
|
|
|
|
context = sc->mfi_comms->hw_reply_q[ci];
|
2007-06-04 16:39:22 +00:00
|
|
|
if (context < sc->mfi_max_fw_cmds) {
|
|
|
|
cm = &sc->mfi_commands[context];
|
|
|
|
mfi_remove_busy(cm);
|
|
|
|
cm->cm_error = 0;
|
|
|
|
mfi_complete(sc, cm);
|
|
|
|
}
|
2006-09-07 05:05:41 +00:00
|
|
|
if (++ci == (sc->mfi_max_fw_cmds + 1)) {
|
2006-03-25 06:14:32 +00:00
|
|
|
ci = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->mfi_comms->hw_ci = ci;
|
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
/* Give defered I/O a chance to run */
|
|
|
|
if (sc->mfi_flags & MFI_FLAGS_QFRZN)
|
|
|
|
sc->mfi_flags &= ~MFI_FLAGS_QFRZN;
|
|
|
|
mfi_startio(sc);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
/*
|
|
|
|
* Dummy read to flush the bus; this ensures that the indexes are up
|
|
|
|
* to date. Restart processing if more commands have come it.
|
|
|
|
*/
|
|
|
|
(void)sc->mfi_read_fw_status(sc);
|
|
|
|
if (pi != sc->mfi_comms->hw_pi)
|
|
|
|
goto restart;
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mfi_shutdown(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_dcmd_frame *dcmd;
|
|
|
|
struct mfi_command *cm;
|
|
|
|
int error;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
|
|
|
|
if (sc->mfi_aen_cm)
|
|
|
|
sc->cm_aen_abort = 1;
|
|
|
|
if (sc->mfi_aen_cm != NULL)
|
|
|
|
mfi_abort(sc, &sc->mfi_aen_cm);
|
|
|
|
|
|
|
|
if (sc->mfi_map_sync_cm)
|
|
|
|
sc->cm_map_abort = 1;
|
|
|
|
if (sc->mfi_map_sync_cm != NULL)
|
|
|
|
mfi_abort(sc, &sc->mfi_map_sync_cm);
|
|
|
|
|
2006-06-20 21:06:05 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_CTRL_SHUTDOWN, NULL, 0);
|
2006-10-16 04:18:38 +00:00
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-06-20 21:06:05 +00:00
|
|
|
return (error);
|
2006-10-16 04:18:38 +00:00
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
dcmd->header.flags = MFI_FRAME_DIR_NONE;
|
2006-11-18 07:33:53 +00:00
|
|
|
cm->cm_flags = MFI_CMD_POLLED;
|
|
|
|
cm->cm_data = NULL;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-11-18 07:33:53 +00:00
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
2006-03-25 06:14:32 +00:00
|
|
|
device_printf(sc->mfi_dev, "Failed to shutdown controller\n");
|
|
|
|
}
|
|
|
|
|
2006-06-20 23:08:35 +00:00
|
|
|
mfi_release_command(cm);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
static void
|
|
|
|
mfi_syspdprobe(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_command *cm = NULL;
|
|
|
|
struct mfi_pd_list *pdlist = NULL;
|
2012-03-30 23:05:48 +00:00
|
|
|
struct mfi_system_pd *syspd, *tmp;
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_system_pending *syspd_pend;
|
2012-03-30 23:05:48 +00:00
|
|
|
int error, i, found;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
sx_assert(&sc->mfi_config_lock, SA_XLOCKED);
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Add SYSTEM PD's */
|
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_PD_LIST_QUERY,
|
|
|
|
(void **)&pdlist, sizeof(*pdlist));
|
2012-05-04 16:22:13 +00:00
|
|
|
if (error) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Error while forming SYSTEM PD list\n");
|
|
|
|
goto out;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_POLLED;
|
|
|
|
cm->cm_frame->dcmd.mbox[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST;
|
|
|
|
cm->cm_frame->dcmd.mbox[1] = 0;
|
|
|
|
if (mfi_mapcmd(sc, cm) != 0) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to get syspd device listing\n");
|
|
|
|
goto out;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat,cm->cm_dmamap,
|
2012-03-30 23:05:48 +00:00
|
|
|
BUS_DMASYNC_POSTREAD);
|
2011-11-04 02:34:52 +00:00
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
if (hdr->cmd_status != MFI_STAT_OK) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"MFI_DCMD_PD_LIST_QUERY failed %x\n", hdr->cmd_status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Get each PD and add it to the system */
|
|
|
|
for (i = 0; i < pdlist->count; i++) {
|
|
|
|
if (pdlist->addr[i].device_id ==
|
|
|
|
pdlist->addr[i].encl_device_id)
|
|
|
|
continue;
|
|
|
|
found = 0;
|
|
|
|
TAILQ_FOREACH(syspd, &sc->mfi_syspd_tqh, pd_link) {
|
|
|
|
if (syspd->pd_id == pdlist->addr[i].device_id)
|
|
|
|
found = 1;
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
TAILQ_FOREACH(syspd_pend, &sc->mfi_syspd_pend_tqh, pd_link) {
|
|
|
|
if (syspd_pend->pd_id == pdlist->addr[i].device_id)
|
|
|
|
found = 1;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (found == 0)
|
|
|
|
mfi_add_sys_pd(sc, pdlist->addr[i].device_id);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
/* Delete SYSPD's whose state has been changed */
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_FOREACH_SAFE(syspd, &sc->mfi_syspd_tqh, pd_link, tmp) {
|
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < pdlist->count; i++) {
|
|
|
|
if (syspd->pd_id == pdlist->addr[i].device_id)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
if (found == 0) {
|
|
|
|
printf("DELETE\n");
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&Giant);
|
2012-03-30 23:05:48 +00:00
|
|
|
device_delete_child(sc->mfi_dev, syspd->pd_dev);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&Giant);
|
2012-03-30 23:05:48 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (pdlist)
|
|
|
|
free(pdlist, M_MFIBUF);
|
|
|
|
if (cm)
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
static void
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_ldprobe(struct mfi_softc *sc)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
2006-06-20 22:41:44 +00:00
|
|
|
struct mfi_command *cm = NULL;
|
|
|
|
struct mfi_ld_list *list = NULL;
|
2007-08-13 19:29:17 +00:00
|
|
|
struct mfi_disk *ld;
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_disk_pending *ld_pend;
|
2006-06-20 22:41:44 +00:00
|
|
|
int error, i;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_assert(&sc->mfi_config_lock, SA_XLOCKED);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2006-06-20 22:41:44 +00:00
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_LD_GET_LIST,
|
|
|
|
(void **)&list, sizeof(*list));
|
|
|
|
if (error)
|
|
|
|
goto out;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-06-20 22:41:44 +00:00
|
|
|
cm->cm_flags = MFI_CMD_DATAIN;
|
|
|
|
if (mfi_wait_command(sc, cm) != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to get device listing\n");
|
|
|
|
goto out;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hdr = &cm->cm_frame->header;
|
2006-06-20 22:41:44 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
for (i = 0; i < list->ld_count; i++) {
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld->ld_id == list->ld_list[i].ld.v.target_id)
|
|
|
|
goto skip_add;
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
TAILQ_FOREACH(ld_pend, &sc->mfi_ld_pend_tqh, ld_link) {
|
|
|
|
if (ld_pend->ld_id == list->ld_list[i].ld.v.target_id)
|
|
|
|
goto skip_add;
|
|
|
|
}
|
2006-10-16 04:18:38 +00:00
|
|
|
mfi_add_ld(sc, list->ld_list[i].ld.v.target_id);
|
2007-08-13 19:29:17 +00:00
|
|
|
skip_add:;
|
|
|
|
}
|
2006-06-20 22:41:44 +00:00
|
|
|
out:
|
|
|
|
if (list)
|
|
|
|
free(list, M_MFIBUF);
|
|
|
|
if (cm)
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(cm);
|
2006-10-16 04:18:38 +00:00
|
|
|
|
2006-06-20 22:41:44 +00:00
|
|
|
return;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 22:36:38 +00:00
|
|
|
/*
|
|
|
|
* The timestamp is the number of seconds since 00:00 Jan 1, 2000. If
|
|
|
|
* the bits in 24-31 are all set, then it is the number of seconds since
|
|
|
|
* boot.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
format_timestamp(uint32_t timestamp)
|
|
|
|
{
|
|
|
|
static char buffer[32];
|
|
|
|
|
|
|
|
if ((timestamp & 0xff000000) == 0xff000000)
|
|
|
|
snprintf(buffer, sizeof(buffer), "boot + %us", timestamp &
|
|
|
|
0x00ffffff);
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer), "%us", timestamp);
|
|
|
|
return (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
format_class(int8_t class)
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
2008-06-26 22:36:38 +00:00
|
|
|
static char buffer[6];
|
|
|
|
|
|
|
|
switch (class) {
|
|
|
|
case MFI_EVT_CLASS_DEBUG:
|
|
|
|
return ("debug");
|
|
|
|
case MFI_EVT_CLASS_PROGRESS:
|
|
|
|
return ("progress");
|
|
|
|
case MFI_EVT_CLASS_INFO:
|
|
|
|
return ("info");
|
|
|
|
case MFI_EVT_CLASS_WARNING:
|
|
|
|
return ("WARN");
|
|
|
|
case MFI_EVT_CLASS_CRITICAL:
|
|
|
|
return ("CRIT");
|
|
|
|
case MFI_EVT_CLASS_FATAL:
|
|
|
|
return ("FATAL");
|
|
|
|
case MFI_EVT_CLASS_DEAD:
|
|
|
|
return ("DEAD");
|
2006-05-18 23:30:48 +00:00
|
|
|
default:
|
2008-06-26 22:36:38 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%d", class);
|
|
|
|
return (buffer);
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:36:38 +00:00
|
|
|
static void
|
|
|
|
mfi_decode_evt(struct mfi_softc *sc, struct mfi_evt_detail *detail)
|
|
|
|
{
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_system_pd *syspd = NULL;
|
2008-06-26 22:36:38 +00:00
|
|
|
|
2009-12-07 21:24:07 +00:00
|
|
|
device_printf(sc->mfi_dev, "%d (%s/0x%04x/%s) - %s\n", detail->seq,
|
2011-06-02 00:43:16 +00:00
|
|
|
format_timestamp(detail->time), detail->evt_class.members.locale,
|
2012-03-30 23:05:48 +00:00
|
|
|
format_class(detail->evt_class.members.evt_class),
|
|
|
|
detail->description);
|
|
|
|
|
|
|
|
/* Don't act on old AEN's or while shutting down */
|
|
|
|
if (detail->seq < sc->mfi_boot_seq_num || sc->mfi_detaching)
|
|
|
|
return;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
switch (detail->arg_type) {
|
|
|
|
case MR_EVT_ARGS_NONE:
|
|
|
|
if (detail->code == MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "HostBus scan raised\n");
|
|
|
|
if (mfi_detect_jbod_change) {
|
|
|
|
/*
|
|
|
|
* Probe for new SYSPD's and Delete
|
|
|
|
* invalid SYSPD's
|
|
|
|
*/
|
|
|
|
sx_xlock(&sc->mfi_config_lock);
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_syspdprobe(sc);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
sx_xunlock(&sc->mfi_config_lock);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MR_EVT_ARGS_LD_STATE:
|
2012-03-30 23:05:48 +00:00
|
|
|
/* During load time driver reads all the events starting
|
|
|
|
* from the one that has been logged after shutdown. Avoid
|
|
|
|
* these old events.
|
|
|
|
*/
|
|
|
|
if (detail->args.ld_state.new_state == MFI_LD_STATE_OFFLINE ) {
|
|
|
|
/* Remove the LD */
|
|
|
|
struct mfi_disk *ld;
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld->ld_id ==
|
|
|
|
detail->args.ld_state.ld.target_id)
|
|
|
|
break;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
/*
|
|
|
|
Fix: for kernel panics when SSCD is removed
|
|
|
|
KASSERT(ld != NULL, ("volume dissappeared"));
|
|
|
|
*/
|
|
|
|
if (ld != NULL) {
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
device_delete_child(sc->mfi_dev, ld->ld_dev);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
}
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
case MR_EVT_ARGS_PD:
|
|
|
|
if (detail->code == MR_EVT_PD_REMOVED) {
|
2012-03-30 23:05:48 +00:00
|
|
|
if (mfi_detect_jbod_change) {
|
|
|
|
/*
|
|
|
|
* If the removed device is a SYSPD then
|
|
|
|
* delete it
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(syspd, &sc->mfi_syspd_tqh,
|
|
|
|
pd_link) {
|
|
|
|
if (syspd->pd_id ==
|
|
|
|
detail->args.pd.device_id) {
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
device_delete_child(
|
|
|
|
sc->mfi_dev,
|
|
|
|
syspd->pd_dev);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
if (detail->code == MR_EVT_PD_INSERTED) {
|
2012-03-30 23:05:48 +00:00
|
|
|
if (mfi_detect_jbod_change) {
|
|
|
|
/* Probe for new SYSPD's */
|
|
|
|
sx_xlock(&sc->mfi_config_lock);
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_syspdprobe(sc);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
sx_xunlock(&sc->mfi_config_lock);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
2012-11-08 00:32:36 +00:00
|
|
|
if (sc->mfi_cam_rescan_cb != NULL &&
|
|
|
|
(detail->code == MR_EVT_PD_INSERTED ||
|
|
|
|
detail->code == MR_EVT_PD_REMOVED)) {
|
|
|
|
sc->mfi_cam_rescan_cb(sc, detail->args.pd.device_id);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
}
|
2008-06-26 22:36:38 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
static void
|
|
|
|
mfi_queue_evt(struct mfi_softc *sc, struct mfi_evt_detail *detail)
|
|
|
|
{
|
|
|
|
struct mfi_evt_queue_elm *elm;
|
|
|
|
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
elm = malloc(sizeof(*elm), M_MFIBUF, M_NOWAIT|M_ZERO);
|
|
|
|
if (elm == NULL)
|
|
|
|
return;
|
|
|
|
memcpy(&elm->detail, detail, sizeof(*detail));
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mfi_evt_queue, elm, link);
|
|
|
|
taskqueue_enqueue(taskqueue_swi, &sc->mfi_evt_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_handle_evt(void *context, int pending)
|
|
|
|
{
|
|
|
|
TAILQ_HEAD(,mfi_evt_queue_elm) queue;
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
struct mfi_evt_queue_elm *elm;
|
|
|
|
|
|
|
|
sc = context;
|
|
|
|
TAILQ_INIT(&queue);
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
TAILQ_CONCAT(&queue, &sc->mfi_evt_queue, link);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
while ((elm = TAILQ_FIRST(&queue)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&queue, elm, link);
|
|
|
|
mfi_decode_evt(sc, &elm->detail);
|
|
|
|
free(elm, M_MFIBUF);
|
|
|
|
}
|
2008-06-26 22:36:38 +00:00
|
|
|
}
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
static int
|
|
|
|
mfi_aen_register(struct mfi_softc *sc, int seq, int locale)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_dcmd_frame *dcmd;
|
|
|
|
union mfi_evt current_aen, prior_aen;
|
2006-06-20 21:06:05 +00:00
|
|
|
struct mfi_evt_detail *ed = NULL;
|
2006-10-16 04:18:38 +00:00
|
|
|
int error = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
current_aen.word = locale;
|
|
|
|
if (sc->mfi_aen_cm != NULL) {
|
|
|
|
prior_aen.word =
|
|
|
|
((uint32_t *)&sc->mfi_aen_cm->cm_frame->dcmd.mbox)[1];
|
2011-06-02 00:43:16 +00:00
|
|
|
if (prior_aen.members.evt_class <= current_aen.members.evt_class &&
|
2006-05-18 23:30:48 +00:00
|
|
|
!((prior_aen.members.locale & current_aen.members.locale)
|
|
|
|
^current_aen.members.locale)) {
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
prior_aen.members.locale |= current_aen.members.locale;
|
2011-06-02 00:43:16 +00:00
|
|
|
if (prior_aen.members.evt_class
|
|
|
|
< current_aen.members.evt_class)
|
|
|
|
current_aen.members.evt_class =
|
|
|
|
prior_aen.members.evt_class;
|
2012-11-06 23:25:06 +00:00
|
|
|
mfi_abort(sc, &sc->mfi_aen_cm);
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-06-20 21:06:05 +00:00
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_CTRL_EVENT_WAIT,
|
|
|
|
(void **)&ed, sizeof(*ed));
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-10-16 04:18:38 +00:00
|
|
|
if (error) {
|
|
|
|
goto out;
|
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
((uint32_t *)&dcmd->mbox)[0] = seq;
|
|
|
|
((uint32_t *)&dcmd->mbox)[1] = locale;
|
|
|
|
cm->cm_flags = MFI_CMD_DATAIN;
|
|
|
|
cm->cm_complete = mfi_aen_complete;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
sc->last_seq_num = seq;
|
2006-05-18 23:30:48 +00:00
|
|
|
sc->mfi_aen_cm = cm;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
mfi_enqueue_ready(cm);
|
|
|
|
mfi_startio(sc);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
out:
|
|
|
|
return (error);
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_aen_complete(struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
struct mfi_evt_detail *detail;
|
2006-10-16 04:18:38 +00:00
|
|
|
struct mfi_aen *mfi_aen_entry, *tmp;
|
2006-05-18 23:30:48 +00:00
|
|
|
int seq = 0, aborted = 0;
|
|
|
|
|
|
|
|
sc = cm->cm_sc;
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
|
|
|
|
if (sc->mfi_aen_cm == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 16:00:39 +00:00
|
|
|
if (sc->cm_aen_abort ||
|
2011-07-14 20:11:27 +00:00
|
|
|
hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
2012-05-04 16:00:39 +00:00
|
|
|
sc->cm_aen_abort = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
aborted = 1;
|
|
|
|
} else {
|
|
|
|
sc->mfi_aen_triggered = 1;
|
2006-10-16 04:18:38 +00:00
|
|
|
if (sc->mfi_poll_waiting) {
|
|
|
|
sc->mfi_poll_waiting = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
selwakeup(&sc->mfi_select);
|
2006-10-16 04:18:38 +00:00
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
detail = cm->cm_data;
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_queue_evt(sc, detail);
|
2006-05-18 23:30:48 +00:00
|
|
|
seq = detail->seq + 1;
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_FOREACH_SAFE(mfi_aen_entry, &sc->mfi_aen_pids, aen_link,
|
|
|
|
tmp) {
|
2006-05-18 23:30:48 +00:00
|
|
|
TAILQ_REMOVE(&sc->mfi_aen_pids, mfi_aen_entry,
|
|
|
|
aen_link);
|
2006-10-16 04:18:38 +00:00
|
|
|
PROC_LOCK(mfi_aen_entry->p);
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_psignal(mfi_aen_entry->p, SIGIO);
|
2006-10-16 04:18:38 +00:00
|
|
|
PROC_UNLOCK(mfi_aen_entry->p);
|
2006-05-18 23:30:48 +00:00
|
|
|
free(mfi_aen_entry, M_MFIBUF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cm->cm_data, M_MFIBUF);
|
|
|
|
sc->mfi_aen_cm = NULL;
|
|
|
|
wakeup(&sc->mfi_aen_cm);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
/* set it up again so the driver can catch more events */
|
|
|
|
if (!aborted) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
mfi_aen_setup(sc, seq);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:33:24 +00:00
|
|
|
#define MAX_EVENTS 15
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
static int
|
2008-06-26 22:33:24 +00:00
|
|
|
mfi_parse_entries(struct mfi_softc *sc, int start_seq, int stop_seq)
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_dcmd_frame *dcmd;
|
2006-09-07 18:40:49 +00:00
|
|
|
struct mfi_evt_list *el;
|
2008-06-26 22:33:24 +00:00
|
|
|
union mfi_evt class_locale;
|
|
|
|
int error, i, seq, size;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2008-06-26 22:33:24 +00:00
|
|
|
class_locale.members.reserved = 0;
|
|
|
|
class_locale.members.locale = mfi_event_locale;
|
2011-06-02 00:43:16 +00:00
|
|
|
class_locale.members.evt_class = mfi_event_class;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2006-09-07 18:40:49 +00:00
|
|
|
size = sizeof(struct mfi_evt_list) + sizeof(struct mfi_evt_detail)
|
|
|
|
* (MAX_EVENTS - 1);
|
|
|
|
el = malloc(size, M_MFIBUF, M_NOWAIT | M_ZERO);
|
2008-06-26 22:33:24 +00:00
|
|
|
if (el == NULL)
|
2006-05-18 23:30:48 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
|
2008-06-26 22:33:24 +00:00
|
|
|
for (seq = start_seq;;) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL) {
|
|
|
|
free(el, M_MFIBUF);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2008-06-26 22:33:24 +00:00
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
bzero(dcmd->mbox, MFI_MBOX_SIZE);
|
|
|
|
dcmd->header.cmd = MFI_CMD_DCMD;
|
|
|
|
dcmd->header.timeout = 0;
|
|
|
|
dcmd->header.data_len = size;
|
|
|
|
dcmd->opcode = MFI_DCMD_CTRL_EVENT_GET;
|
|
|
|
((uint32_t *)&dcmd->mbox)[0] = seq;
|
|
|
|
((uint32_t *)&dcmd->mbox)[1] = class_locale.word;
|
|
|
|
cm->cm_sg = &dcmd->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_DCMD_FRAME_SIZE;
|
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_POLLED;
|
|
|
|
cm->cm_data = el;
|
|
|
|
cm->cm_len = size;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
if ((error = mfi_mapcmd(sc, cm)) != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to get controller entries\n");
|
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
|
|
|
|
if (dcmd->header.cmd_status == MFI_STAT_NOT_FOUND) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dcmd->header.cmd_status != MFI_STAT_OK) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Error %d fetching controller entries\n",
|
|
|
|
dcmd->header.cmd_status);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2008-06-26 22:33:24 +00:00
|
|
|
mfi_release_command(cm);
|
2011-11-04 02:34:52 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2006-09-20 18:49:35 +00:00
|
|
|
for (i = 0; i < el->count; i++) {
|
2008-06-26 22:33:24 +00:00
|
|
|
/*
|
|
|
|
* If this event is newer than 'stop_seq' then
|
|
|
|
* break out of the loop. Note that the log
|
|
|
|
* is a circular buffer so we have to handle
|
|
|
|
* the case that our stop point is earlier in
|
|
|
|
* the buffer than our start point.
|
|
|
|
*/
|
|
|
|
if (el->event[i].seq >= stop_seq) {
|
|
|
|
if (start_seq <= stop_seq)
|
|
|
|
break;
|
|
|
|
else if (el->event[i].seq < start_seq)
|
|
|
|
break;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_queue_evt(sc, &el->event[i]);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-09-20 18:49:35 +00:00
|
|
|
}
|
2008-06-26 22:33:24 +00:00
|
|
|
seq = el->event[el->count - 1].seq + 1;
|
2006-09-07 18:40:49 +00:00
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2008-06-26 22:33:24 +00:00
|
|
|
free(el, M_MFIBUF);
|
2006-05-18 23:30:48 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
static int
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_add_ld(struct mfi_softc *sc, int id)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
2006-06-20 22:41:44 +00:00
|
|
|
struct mfi_dcmd_frame *dcmd = NULL;
|
|
|
|
struct mfi_ld_info *ld_info = NULL;
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_disk_pending *ld_pend;
|
2006-06-20 22:41:44 +00:00
|
|
|
int error;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2006-06-20 22:41:44 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
ld_pend = malloc(sizeof(*ld_pend), M_MFIBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (ld_pend != NULL) {
|
|
|
|
ld_pend->ld_id = id;
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mfi_ld_pend_tqh, ld_pend, ld_link);
|
|
|
|
}
|
|
|
|
|
2006-06-20 22:41:44 +00:00
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_LD_GET_INFO,
|
|
|
|
(void **)&ld_info, sizeof(*ld_info));
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to allocate for MFI_DCMD_LD_GET_INFO %d\n", error);
|
|
|
|
if (ld_info)
|
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
return (error);
|
2006-04-10 06:44:30 +00:00
|
|
|
}
|
2006-06-20 22:41:44 +00:00
|
|
|
cm->cm_flags = MFI_CMD_DATAIN;
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
dcmd->mbox[0] = id;
|
2006-06-30 18:59:08 +00:00
|
|
|
if (mfi_wait_command(sc, cm) != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to get logical drive: %d\n", id);
|
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
return (0);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
if (ld_info->ld_config.params.isSSCD != 1)
|
|
|
|
mfi_add_ld_complete(cm);
|
2012-03-30 23:05:48 +00:00
|
|
|
else {
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_release_command(cm);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (ld_info) /* SSCD drives ld_info free here */
|
2011-11-04 02:34:52 +00:00
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-20 22:41:44 +00:00
|
|
|
mfi_add_ld_complete(struct mfi_command *cm)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
2006-06-20 22:41:44 +00:00
|
|
|
struct mfi_ld_info *ld_info;
|
2006-03-25 06:14:32 +00:00
|
|
|
struct mfi_softc *sc;
|
2006-06-20 22:41:44 +00:00
|
|
|
device_t child;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
sc = cm->cm_sc;
|
|
|
|
hdr = &cm->cm_frame->header;
|
2006-06-20 22:41:44 +00:00
|
|
|
ld_info = cm->cm_private;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
if (sc->cm_map_abort || hdr->cmd_status != MFI_STAT_OK) {
|
2006-06-20 22:41:44 +00:00
|
|
|
free(ld_info, M_MFIBUF);
|
2012-11-06 23:25:06 +00:00
|
|
|
wakeup(&sc->mfi_map_sync_cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(cm);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
wakeup(&sc->mfi_map_sync_cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(cm);
|
2006-03-28 01:59:11 +00:00
|
|
|
|
2007-05-16 17:23:36 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2006-03-25 06:14:32 +00:00
|
|
|
if ((child = device_add_child(sc->mfi_dev, "mfid", -1)) == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Failed to add logical disk\n");
|
2006-06-20 22:41:44 +00:00
|
|
|
free(ld_info, M_MFIBUF);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2007-05-16 17:23:36 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-06-20 22:41:44 +00:00
|
|
|
return;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 15:33:41 +00:00
|
|
|
device_set_ivars(child, ld_info);
|
2006-03-25 06:14:32 +00:00
|
|
|
device_set_desc(child, "MFI Logical Disk");
|
|
|
|
bus_generic_attach(sc->mfi_dev);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2006-03-25 06:14:32 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
}
|
2006-10-16 04:30:09 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
static int mfi_add_sys_pd(struct mfi_softc *sc, int id)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_dcmd_frame *dcmd = NULL;
|
|
|
|
struct mfi_pd_info *pd_info = NULL;
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_system_pending *syspd_pend;
|
2011-11-04 02:34:52 +00:00
|
|
|
int error;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
syspd_pend = malloc(sizeof(*syspd_pend), M_MFIBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (syspd_pend != NULL) {
|
|
|
|
syspd_pend->pd_id = id;
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mfi_syspd_pend_tqh, syspd_pend, pd_link);
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
error = mfi_dcmd_command(sc, &cm, MFI_DCMD_PD_GET_INFO,
|
2011-11-04 02:34:52 +00:00
|
|
|
(void **)&pd_info, sizeof(*pd_info));
|
|
|
|
if (error) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to allocated for MFI_DCMD_PD_GET_INFO %d\n",
|
|
|
|
error);
|
|
|
|
if (pd_info)
|
|
|
|
free(pd_info, M_MFIBUF);
|
|
|
|
return (error);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_POLLED;
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
dcmd->mbox[0]=id;
|
|
|
|
dcmd->header.scsi_status = 0;
|
|
|
|
dcmd->header.pad0 = 0;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (mfi_mapcmd(sc, cm) != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Failed to get physical drive info %d\n", id);
|
|
|
|
free(pd_info, M_MFIBUF);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_add_sys_pd_complete(cm);
|
|
|
|
return (0);
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
static void
|
|
|
|
mfi_add_sys_pd_complete(struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_pd_info *pd_info;
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
sc = cm->cm_sc;
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
pd_info = cm->cm_private;
|
|
|
|
|
|
|
|
if (hdr->cmd_status != MFI_STAT_OK) {
|
2012-03-30 23:05:48 +00:00
|
|
|
free(pd_info, M_MFIBUF);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
return;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
if (pd_info->fw_state != MFI_PD_STATE_SYSTEM) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "PD=%x is not SYSTEM PD\n",
|
|
|
|
pd_info->ref.v.device_id);
|
|
|
|
free(pd_info, M_MFIBUF);
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_release_command(cm);
|
2012-03-30 23:05:48 +00:00
|
|
|
return;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
if ((child = device_add_child(sc->mfi_dev, "mfisyspd", -1)) == NULL) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "Failed to add system pd\n");
|
|
|
|
free(pd_info, M_MFIBUF);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
return;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_set_ivars(child, pd_info);
|
|
|
|
device_set_desc(child, "MFI System PD");
|
|
|
|
bus_generic_attach(sc->mfi_dev);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
}
|
2012-05-04 16:22:13 +00:00
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
static struct mfi_command *
|
|
|
|
mfi_bio_command(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_command *cm = NULL;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/*reserving two commands to avoid starvation for IOCTL*/
|
2012-05-04 16:22:13 +00:00
|
|
|
if (sc->mfi_qstat[MFIQ_FREE].q_length < 2) {
|
2006-03-25 06:14:32 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if ((bio = mfi_dequeue_bio(sc)) == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((uintptr_t)bio->bio_driver2 == MFI_LD_IO) {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm = mfi_build_ldio(sc, bio);
|
2011-11-04 02:34:52 +00:00
|
|
|
} else if ((uintptr_t) bio->bio_driver2 == MFI_SYS_PD_IO) {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm = mfi_build_syspdio(sc, bio);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
if (!cm)
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_enqueue_bio(sc, bio);
|
2011-11-04 02:34:52 +00:00
|
|
|
return cm;
|
|
|
|
}
|
2012-11-02 22:07:45 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
/*
|
|
|
|
* mostly copied from cam/scsi/scsi_all.c:scsi_read_write
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
mfi_build_cdb(int readop, uint8_t byte2, u_int64_t lba, u_int32_t block_count, uint8_t *cdb)
|
2012-11-02 22:07:45 +00:00
|
|
|
{
|
|
|
|
int cdb_len;
|
|
|
|
|
|
|
|
if (((lba & 0x1fffff) == lba)
|
|
|
|
&& ((block_count & 0xff) == block_count)
|
|
|
|
&& (byte2 == 0)) {
|
|
|
|
/* We can fit in a 6 byte cdb */
|
|
|
|
struct scsi_rw_6 *scsi_cmd;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
scsi_cmd = (struct scsi_rw_6 *)cdb;
|
2012-11-02 22:07:45 +00:00
|
|
|
scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
|
|
|
|
scsi_ulto3b(lba, scsi_cmd->addr);
|
|
|
|
scsi_cmd->length = block_count & 0xff;
|
|
|
|
scsi_cmd->control = 0;
|
|
|
|
cdb_len = sizeof(*scsi_cmd);
|
|
|
|
} else if (((block_count & 0xffff) == block_count) && ((lba & 0xffffffff) == lba)) {
|
|
|
|
/* Need a 10 byte CDB */
|
|
|
|
struct scsi_rw_10 *scsi_cmd;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
scsi_cmd = (struct scsi_rw_10 *)cdb;
|
2012-11-02 22:07:45 +00:00
|
|
|
scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
|
|
|
|
scsi_cmd->byte2 = byte2;
|
|
|
|
scsi_ulto4b(lba, scsi_cmd->addr);
|
|
|
|
scsi_cmd->reserved = 0;
|
|
|
|
scsi_ulto2b(block_count, scsi_cmd->length);
|
|
|
|
scsi_cmd->control = 0;
|
|
|
|
cdb_len = sizeof(*scsi_cmd);
|
|
|
|
} else if (((block_count & 0xffffffff) == block_count) &&
|
|
|
|
((lba & 0xffffffff) == lba)) {
|
|
|
|
/* Block count is too big for 10 byte CDB use a 12 byte CDB */
|
|
|
|
struct scsi_rw_12 *scsi_cmd;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
scsi_cmd = (struct scsi_rw_12 *)cdb;
|
2012-11-02 22:07:45 +00:00
|
|
|
scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
|
|
|
|
scsi_cmd->byte2 = byte2;
|
|
|
|
scsi_ulto4b(lba, scsi_cmd->addr);
|
|
|
|
scsi_cmd->reserved = 0;
|
|
|
|
scsi_ulto4b(block_count, scsi_cmd->length);
|
|
|
|
scsi_cmd->control = 0;
|
|
|
|
cdb_len = sizeof(*scsi_cmd);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* 16 byte CDB. We'll only get here if the LBA is larger
|
|
|
|
* than 2^32
|
|
|
|
*/
|
|
|
|
struct scsi_rw_16 *scsi_cmd;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
scsi_cmd = (struct scsi_rw_16 *)cdb;
|
2012-11-02 22:07:45 +00:00
|
|
|
scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
|
|
|
|
scsi_cmd->byte2 = byte2;
|
|
|
|
scsi_u64to8b(lba, scsi_cmd->addr);
|
|
|
|
scsi_cmd->reserved = 0;
|
|
|
|
scsi_ulto4b(block_count, scsi_cmd->length);
|
|
|
|
scsi_cmd->control = 0;
|
|
|
|
cdb_len = sizeof(*scsi_cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cdb_len;
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
static struct mfi_command *
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_build_syspdio(struct mfi_softc *sc, struct bio *bio)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_pass_frame *pass;
|
2012-11-06 23:25:06 +00:00
|
|
|
uint32_t context = 0;
|
|
|
|
int flags = 0, blkcount = 0, readop;
|
2012-11-02 22:07:45 +00:00
|
|
|
uint8_t cdb_len;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* Zero out the MFI frame */
|
2012-11-06 23:25:06 +00:00
|
|
|
context = cm->cm_frame->header.context;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
|
|
|
cm->cm_frame->header.context = context;
|
2011-11-04 02:34:52 +00:00
|
|
|
pass = &cm->cm_frame->pass;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(pass->cdb, 16);
|
2011-11-04 02:34:52 +00:00
|
|
|
pass->header.cmd = MFI_CMD_PD_SCSI_IO;
|
|
|
|
switch (bio->bio_cmd & 0x03) {
|
|
|
|
case BIO_READ:
|
|
|
|
flags = MFI_CMD_DATAIN;
|
2012-11-06 23:25:06 +00:00
|
|
|
readop = 1;
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
case BIO_WRITE:
|
|
|
|
flags = MFI_CMD_DATAOUT;
|
2012-11-06 23:25:06 +00:00
|
|
|
readop = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-11-02 22:07:45 +00:00
|
|
|
/* TODO: what about BIO_DELETE??? */
|
2012-11-06 23:25:06 +00:00
|
|
|
panic("Unsupported bio command %x\n", bio->bio_cmd);
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cheat with the sector length to avoid a non-constant division */
|
2012-11-06 23:25:06 +00:00
|
|
|
blkcount = (bio->bio_bcount + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Fill the LBA and Transfer length in CDB */
|
2012-11-06 23:25:06 +00:00
|
|
|
cdb_len = mfi_build_cdb(readop, 0, bio->bio_pblkno, blkcount,
|
|
|
|
pass->cdb);
|
2011-11-04 02:34:52 +00:00
|
|
|
pass->header.target_id = (uintptr_t)bio->bio_driver1;
|
2012-11-06 23:25:06 +00:00
|
|
|
pass->header.lun_id = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
pass->header.timeout = 0;
|
|
|
|
pass->header.flags = 0;
|
|
|
|
pass->header.scsi_status = 0;
|
|
|
|
pass->header.sense_len = MFI_SENSE_LEN;
|
|
|
|
pass->header.data_len = bio->bio_bcount;
|
2012-11-02 22:07:45 +00:00
|
|
|
pass->header.cdb_len = cdb_len;
|
2012-03-30 23:05:48 +00:00
|
|
|
pass->sense_addr_lo = (uint32_t)cm->cm_sense_busaddr;
|
|
|
|
pass->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_complete = mfi_bio_complete;
|
|
|
|
cm->cm_private = bio;
|
|
|
|
cm->cm_data = bio->bio_data;
|
|
|
|
cm->cm_len = bio->bio_bcount;
|
|
|
|
cm->cm_sg = &pass->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_PASS_FRAME_SIZE;
|
|
|
|
cm->cm_flags = flags;
|
|
|
|
return (cm);
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
static struct mfi_command *
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_build_ldio(struct mfi_softc *sc, struct bio *bio)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_io_frame *io;
|
|
|
|
struct mfi_command *cm;
|
2012-11-02 22:07:45 +00:00
|
|
|
int flags;
|
|
|
|
uint32_t blkcount;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
return (NULL);
|
2012-03-30 23:05:48 +00:00
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Zero out the MFI frame */
|
2012-03-30 23:05:48 +00:00
|
|
|
context = cm->cm_frame->header.context;
|
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
|
|
|
cm->cm_frame->header.context = context;
|
2006-03-25 06:14:32 +00:00
|
|
|
io = &cm->cm_frame->io;
|
|
|
|
switch (bio->bio_cmd & 0x03) {
|
|
|
|
case BIO_READ:
|
|
|
|
io->header.cmd = MFI_CMD_LD_READ;
|
|
|
|
flags = MFI_CMD_DATAIN;
|
|
|
|
break;
|
|
|
|
case BIO_WRITE:
|
|
|
|
io->header.cmd = MFI_CMD_LD_WRITE;
|
|
|
|
flags = MFI_CMD_DATAOUT;
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-02 22:07:45 +00:00
|
|
|
/* TODO: what about BIO_DELETE??? */
|
2012-11-06 23:25:06 +00:00
|
|
|
panic("Unsupported bio command %x\n", bio->bio_cmd);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cheat with the sector length to avoid a non-constant division */
|
|
|
|
blkcount = (bio->bio_bcount + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
|
|
|
|
io->header.target_id = (uintptr_t)bio->bio_driver1;
|
|
|
|
io->header.timeout = 0;
|
|
|
|
io->header.flags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
io->header.scsi_status = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
io->header.sense_len = MFI_SENSE_LEN;
|
|
|
|
io->header.data_len = blkcount;
|
2012-03-30 23:05:48 +00:00
|
|
|
io->sense_addr_lo = (uint32_t)cm->cm_sense_busaddr;
|
|
|
|
io->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2006-03-25 06:14:32 +00:00
|
|
|
io->lba_hi = (bio->bio_pblkno & 0xffffffff00000000) >> 32;
|
|
|
|
io->lba_lo = bio->bio_pblkno & 0xffffffff;
|
|
|
|
cm->cm_complete = mfi_bio_complete;
|
|
|
|
cm->cm_private = bio;
|
|
|
|
cm->cm_data = bio->bio_data;
|
|
|
|
cm->cm_len = bio->bio_bcount;
|
|
|
|
cm->cm_sg = &io->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_IO_FRAME_SIZE;
|
|
|
|
cm->cm_flags = flags;
|
|
|
|
return (cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_bio_complete(struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
|
|
|
|
bio = cm->cm_private;
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
sc = cm->cm_sc;
|
|
|
|
|
2011-07-14 20:11:27 +00:00
|
|
|
if ((hdr->cmd_status != MFI_STAT_OK) || (hdr->scsi_status != 0)) {
|
2006-03-25 06:14:32 +00:00
|
|
|
bio->bio_flags |= BIO_ERROR;
|
|
|
|
bio->bio_error = EIO;
|
|
|
|
device_printf(sc->mfi_dev, "I/O error, status= %d "
|
|
|
|
"scsi_status= %d\n", hdr->cmd_status, hdr->scsi_status);
|
|
|
|
mfi_print_sense(cm->cm_sc, cm->cm_sense);
|
2008-11-12 22:44:50 +00:00
|
|
|
} else if (cm->cm_error != 0) {
|
|
|
|
bio->bio_flags |= BIO_ERROR;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mfi_release_command(cm);
|
|
|
|
mfi_disk_complete(bio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mfi_startio(struct mfi_softc *sc)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
2007-05-16 17:23:36 +00:00
|
|
|
struct ccb_hdr *ccbh;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* Don't bother if we're short on resources */
|
|
|
|
if (sc->mfi_flags & MFI_FLAGS_QFRZN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Try a command that has already been prepared */
|
|
|
|
cm = mfi_dequeue_ready(sc);
|
|
|
|
|
2007-05-16 17:23:36 +00:00
|
|
|
if (cm == NULL) {
|
|
|
|
if ((ccbh = TAILQ_FIRST(&sc->mfi_cam_ccbq)) != NULL)
|
|
|
|
cm = sc->mfi_cam_start(ccbh);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
/* Nope, so look for work on the bioq */
|
|
|
|
if (cm == NULL)
|
|
|
|
cm = mfi_bio_command(sc);
|
|
|
|
|
|
|
|
/* No work available, so exit */
|
|
|
|
if (cm == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Send the command to the controller */
|
|
|
|
if (mfi_mapcmd(sc, cm) != 0) {
|
|
|
|
mfi_requeue_ready(cm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
int
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_mapcmd(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
int error, polled;
|
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((cm->cm_data != NULL) && (cm->cm_frame->header.cmd != MFI_CMD_STP )) {
|
2006-03-25 06:14:32 +00:00
|
|
|
polled = (cm->cm_flags & MFI_CMD_POLLED) ? BUS_DMA_NOWAIT : 0;
|
2013-02-12 16:57:20 +00:00
|
|
|
if (cm->cm_flags & MFI_CMD_CCB)
|
|
|
|
error = bus_dmamap_load_ccb(sc->mfi_buffer_dmat,
|
|
|
|
cm->cm_dmamap, cm->cm_data, mfi_data_cb, cm,
|
|
|
|
polled);
|
|
|
|
else
|
|
|
|
error = bus_dmamap_load(sc->mfi_buffer_dmat,
|
|
|
|
cm->cm_dmamap, cm->cm_data, cm->cm_len,
|
|
|
|
mfi_data_cb, cm, polled);
|
2006-03-25 06:14:32 +00:00
|
|
|
if (error == EINPROGRESS) {
|
|
|
|
sc->mfi_flags |= MFI_FLAGS_QFRZN;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
} else {
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->MFA_enabled)
|
2011-11-04 02:34:52 +00:00
|
|
|
error = mfi_tbolt_send_frame(sc, cm);
|
|
|
|
else
|
|
|
|
error = mfi_send_frame(sc, cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_data_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
|
|
|
|
{
|
|
|
|
struct mfi_frame_header *hdr;
|
|
|
|
struct mfi_command *cm;
|
2006-03-28 23:59:07 +00:00
|
|
|
union mfi_sgl *sgl;
|
2006-03-25 06:14:32 +00:00
|
|
|
struct mfi_softc *sc;
|
2011-09-29 08:37:53 +00:00
|
|
|
int i, j, first, dir;
|
2012-03-30 23:05:48 +00:00
|
|
|
int sge_size;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
cm = (struct mfi_command *)arg;
|
|
|
|
sc = cm->cm_sc;
|
2006-03-28 23:59:07 +00:00
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
sgl = cm->cm_sg;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-06-04 16:39:22 +00:00
|
|
|
if (error) {
|
|
|
|
printf("error %d in callback\n", error);
|
|
|
|
cm->cm_error = error;
|
|
|
|
mfi_complete(sc, cm);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Use IEEE sgl only for IO's on a SKINNY controller
|
|
|
|
* For other commands on a SKINNY controller use either
|
|
|
|
* sg32 or sg64 based on the sizeof(bus_addr_t).
|
|
|
|
* Also calculate the total frame size based on the type
|
|
|
|
* of SGL used.
|
|
|
|
*/
|
|
|
|
if (((cm->cm_frame->header.cmd == MFI_CMD_PD_SCSI_IO) ||
|
|
|
|
(cm->cm_frame->header.cmd == MFI_CMD_LD_READ) ||
|
|
|
|
(cm->cm_frame->header.cmd == MFI_CMD_LD_WRITE)) &&
|
|
|
|
(sc->mfi_flags & MFI_FLAGS_SKINNY)) {
|
2006-03-28 23:59:07 +00:00
|
|
|
for (i = 0; i < nsegs; i++) {
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl->sg_skinny[i].addr = segs[i].ds_addr;
|
|
|
|
sgl->sg_skinny[i].len = segs[i].ds_len;
|
|
|
|
sgl->sg_skinny[i].flag = 0;
|
2006-03-28 23:59:07 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
hdr->flags |= MFI_FRAME_IEEE_SGL | MFI_FRAME_SGL64;
|
|
|
|
sge_size = sizeof(struct mfi_sg_skinny);
|
2012-03-30 23:05:48 +00:00
|
|
|
hdr->sg_count = nsegs;
|
2006-03-28 23:59:07 +00:00
|
|
|
} else {
|
2011-11-04 02:34:52 +00:00
|
|
|
j = 0;
|
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_STP) {
|
|
|
|
first = cm->cm_stp_len;
|
|
|
|
if ((sc->mfi_flags & MFI_FLAGS_SG64) == 0) {
|
|
|
|
sgl->sg32[j].addr = segs[0].ds_addr;
|
|
|
|
sgl->sg32[j++].len = first;
|
|
|
|
} else {
|
|
|
|
sgl->sg64[j].addr = segs[0].ds_addr;
|
|
|
|
sgl->sg64[j++].len = first;
|
|
|
|
}
|
|
|
|
} else
|
2011-09-29 08:37:53 +00:00
|
|
|
first = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
if ((sc->mfi_flags & MFI_FLAGS_SG64) == 0) {
|
|
|
|
for (i = 0; i < nsegs; i++) {
|
|
|
|
sgl->sg32[j].addr = segs[i].ds_addr + first;
|
|
|
|
sgl->sg32[j++].len = segs[i].ds_len - first;
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < nsegs; i++) {
|
|
|
|
sgl->sg64[j].addr = segs[i].ds_addr + first;
|
|
|
|
sgl->sg64[j++].len = segs[i].ds_len - first;
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
hdr->flags |= MFI_FRAME_SGL64;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
hdr->sg_count = j;
|
2012-03-30 23:05:48 +00:00
|
|
|
sge_size = sc->mfi_sge_size;
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir = 0;
|
|
|
|
if (cm->cm_flags & MFI_CMD_DATAIN) {
|
|
|
|
dir |= BUS_DMASYNC_PREREAD;
|
|
|
|
hdr->flags |= MFI_FRAME_DIR_READ;
|
|
|
|
}
|
|
|
|
if (cm->cm_flags & MFI_CMD_DATAOUT) {
|
|
|
|
dir |= BUS_DMASYNC_PREWRITE;
|
|
|
|
hdr->flags |= MFI_FRAME_DIR_WRITE;
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap, dir);
|
|
|
|
cm->cm_flags |= MFI_CMD_MAPPED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instead of calculating the total number of frames in the
|
|
|
|
* compound frame, it's already assumed that there will be at
|
|
|
|
* least 1 frame, so don't compensate for the modulo of the
|
|
|
|
* following division.
|
|
|
|
*/
|
2006-09-20 06:58:02 +00:00
|
|
|
cm->cm_total_frame_size += (sc->mfi_sge_size * nsegs);
|
2006-03-25 06:14:32 +00:00
|
|
|
cm->cm_extra_frames = (cm->cm_total_frame_size - 1) / MFI_FRAME_SIZE;
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->MFA_enabled)
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_tbolt_send_frame(sc, cm);
|
|
|
|
else
|
|
|
|
mfi_send_frame(sc, cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mfi_send_frame(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
2006-11-18 07:33:53 +00:00
|
|
|
struct mfi_frame_header *hdr;
|
2006-12-14 18:29:08 +00:00
|
|
|
int tm = MFI_POLL_TIMEOUT_SECS * 1000;
|
2006-11-18 07:33:53 +00:00
|
|
|
|
|
|
|
hdr = &cm->cm_frame->header;
|
|
|
|
|
|
|
|
if ((cm->cm_flags & MFI_CMD_POLLED) == 0) {
|
|
|
|
cm->cm_timestamp = time_uptime;
|
|
|
|
mfi_enqueue_busy(cm);
|
|
|
|
} else {
|
2011-07-14 20:11:27 +00:00
|
|
|
hdr->cmd_status = MFI_STAT_INVALID_STATUS;
|
2006-11-18 07:33:53 +00:00
|
|
|
hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
|
|
|
|
}
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The bus address of the command is aligned on a 64 byte boundary,
|
|
|
|
* leaving the least 6 bits as zero. For whatever reason, the
|
|
|
|
* hardware wants the address shifted right by three, leaving just
|
2006-09-20 06:58:02 +00:00
|
|
|
* 3 zero bits. These three bits are then used as a prefetching
|
|
|
|
* hint for the hardware to predict how many frames need to be
|
|
|
|
* fetched across the bus. If a command has more than 8 frames
|
|
|
|
* then the 3 bits are set to 0x7 and the firmware uses other
|
|
|
|
* information in the command to determine the total amount to fetch.
|
|
|
|
* However, FreeBSD doesn't support I/O larger than 128K, so 8 frames
|
|
|
|
* is enough for both 32bit and 64bit systems.
|
2006-03-25 06:14:32 +00:00
|
|
|
*/
|
2006-09-20 06:58:02 +00:00
|
|
|
if (cm->cm_extra_frames > 7)
|
|
|
|
cm->cm_extra_frames = 7;
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
sc->mfi_issue_cmd(sc, cm->cm_frame_busaddr, cm->cm_extra_frames);
|
2006-11-18 07:33:53 +00:00
|
|
|
|
|
|
|
if ((cm->cm_flags & MFI_CMD_POLLED) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* This is a polled command, so busy-wait for it to complete. */
|
2011-07-14 20:11:27 +00:00
|
|
|
while (hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
2006-11-18 07:33:53 +00:00
|
|
|
DELAY(1000);
|
2006-12-14 18:29:08 +00:00
|
|
|
tm -= 1;
|
2006-11-18 07:33:53 +00:00
|
|
|
if (tm <= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-14 20:11:27 +00:00
|
|
|
if (hdr->cmd_status == MFI_STAT_INVALID_STATUS) {
|
2006-12-14 18:29:08 +00:00
|
|
|
device_printf(sc->mfi_dev, "Frame %p timed out "
|
2012-03-30 23:05:48 +00:00
|
|
|
"command 0x%X\n", hdr, cm->cm_frame->dcmd.opcode);
|
2006-11-18 07:33:53 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
void
|
2006-03-25 06:14:32 +00:00
|
|
|
mfi_complete(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
if ((cm->cm_flags & MFI_CMD_MAPPED) != 0) {
|
|
|
|
dir = 0;
|
2011-09-29 08:37:53 +00:00
|
|
|
if ((cm->cm_flags & MFI_CMD_DATAIN) ||
|
|
|
|
(cm->cm_frame->header.cmd == MFI_CMD_STP))
|
2006-03-25 06:14:32 +00:00
|
|
|
dir |= BUS_DMASYNC_POSTREAD;
|
|
|
|
if (cm->cm_flags & MFI_CMD_DATAOUT)
|
|
|
|
dir |= BUS_DMASYNC_POSTWRITE;
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap, dir);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
cm->cm_flags &= ~MFI_CMD_MAPPED;
|
|
|
|
}
|
|
|
|
|
2007-06-04 16:39:22 +00:00
|
|
|
cm->cm_flags |= MFI_CMD_COMPLETED;
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
if (cm->cm_complete != NULL)
|
|
|
|
cm->cm_complete(cm);
|
2006-06-20 22:41:44 +00:00
|
|
|
else
|
|
|
|
wakeup(cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
static int
|
2012-11-06 23:25:06 +00:00
|
|
|
mfi_abort(struct mfi_softc *sc, struct mfi_command **cm_abort)
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_abort_frame *abort;
|
2006-12-14 18:29:08 +00:00
|
|
|
int i = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL) {
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Zero out the MFI frame */
|
|
|
|
context = cm->cm_frame->header.context;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
2006-05-18 23:30:48 +00:00
|
|
|
abort = &cm->cm_frame->abort;
|
|
|
|
abort->header.cmd = MFI_CMD_ABORT;
|
|
|
|
abort->header.flags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
abort->header.scsi_status = 0;
|
2012-11-06 23:25:06 +00:00
|
|
|
abort->abort_context = (*cm_abort)->cm_frame->header.context;
|
|
|
|
abort->abort_mfi_addr_lo = (uint32_t)(*cm_abort)->cm_frame_busaddr;
|
2012-03-30 23:05:48 +00:00
|
|
|
abort->abort_mfi_addr_hi =
|
2012-11-06 23:25:06 +00:00
|
|
|
(uint32_t)((uint64_t)(*cm_abort)->cm_frame_busaddr >> 32);
|
2006-05-18 23:30:48 +00:00
|
|
|
cm->cm_data = NULL;
|
2006-11-18 07:33:53 +00:00
|
|
|
cm->cm_flags = MFI_CMD_POLLED;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
mfi_mapcmd(sc, cm);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
while (i < 5 && *cm_abort != NULL) {
|
|
|
|
tsleep(cm_abort, 0, "mfiabort",
|
2012-03-30 23:05:48 +00:00
|
|
|
5 * hz);
|
2006-12-14 18:29:08 +00:00
|
|
|
i++;
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
2012-11-06 23:25:06 +00:00
|
|
|
if (*cm_abort != NULL) {
|
|
|
|
/* Force a complete if command didn't abort */
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
(*cm_abort)->cm_complete(*cm_abort);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2012-05-04 16:00:39 +00:00
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
int
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_dump_blocks(struct mfi_softc *sc, int id, uint64_t lba, void *virt,
|
|
|
|
int len)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_io_frame *io;
|
|
|
|
int error;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Zero out the MFI frame */
|
|
|
|
context = cm->cm_frame->header.context;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(cm->cm_frame, sizeof(union mfi_frame));
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
io = &cm->cm_frame->io;
|
|
|
|
io->header.cmd = MFI_CMD_LD_WRITE;
|
|
|
|
io->header.target_id = id;
|
|
|
|
io->header.timeout = 0;
|
|
|
|
io->header.flags = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
io->header.scsi_status = 0;
|
2006-03-25 06:14:32 +00:00
|
|
|
io->header.sense_len = MFI_SENSE_LEN;
|
|
|
|
io->header.data_len = (len + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
|
2012-03-30 23:05:48 +00:00
|
|
|
io->sense_addr_lo = (uint32_t)cm->cm_sense_busaddr;
|
|
|
|
io->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2006-03-25 06:14:32 +00:00
|
|
|
io->lba_hi = (lba & 0xffffffff00000000) >> 32;
|
|
|
|
io->lba_lo = lba & 0xffffffff;
|
|
|
|
cm->cm_data = virt;
|
|
|
|
cm->cm_len = len;
|
|
|
|
cm->cm_sg = &io->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_IO_FRAME_SIZE;
|
|
|
|
cm->cm_flags = MFI_CMD_POLLED | MFI_CMD_DATAOUT;
|
|
|
|
|
2006-11-18 07:33:53 +00:00
|
|
|
error = mfi_mapcmd(sc, cm);
|
2006-03-25 06:14:32 +00:00
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
int
|
2012-03-30 23:05:48 +00:00
|
|
|
mfi_dump_syspd_blocks(struct mfi_softc *sc, int id, uint64_t lba, void *virt,
|
|
|
|
int len)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_pass_frame *pass;
|
2012-11-06 23:25:06 +00:00
|
|
|
int error, readop, cdb_len;
|
2012-11-02 22:07:45 +00:00
|
|
|
uint32_t blkcount;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
pass = &cm->cm_frame->pass;
|
2012-03-30 23:05:48 +00:00
|
|
|
bzero(pass->cdb, 16);
|
2011-11-04 02:34:52 +00:00
|
|
|
pass->header.cmd = MFI_CMD_PD_SCSI_IO;
|
2012-11-06 23:25:06 +00:00
|
|
|
|
|
|
|
readop = 0;
|
2011-11-04 02:34:52 +00:00
|
|
|
blkcount = (len + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
|
2012-11-06 23:25:06 +00:00
|
|
|
cdb_len = mfi_build_cdb(readop, 0, lba, blkcount, pass->cdb);
|
2011-11-04 02:34:52 +00:00
|
|
|
pass->header.target_id = id;
|
|
|
|
pass->header.timeout = 0;
|
|
|
|
pass->header.flags = 0;
|
|
|
|
pass->header.scsi_status = 0;
|
|
|
|
pass->header.sense_len = MFI_SENSE_LEN;
|
|
|
|
pass->header.data_len = len;
|
2012-11-06 23:25:06 +00:00
|
|
|
pass->header.cdb_len = cdb_len;
|
2012-03-30 23:05:48 +00:00
|
|
|
pass->sense_addr_lo = (uint32_t)cm->cm_sense_busaddr;
|
|
|
|
pass->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_data = virt;
|
|
|
|
cm->cm_len = len;
|
|
|
|
cm->cm_sg = &pass->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_PASS_FRAME_SIZE;
|
2012-11-06 23:25:06 +00:00
|
|
|
cm->cm_flags = MFI_CMD_POLLED | MFI_CMD_DATAOUT | MFI_CMD_SCSI;
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
error = mfi_mapcmd(sc, cm);
|
|
|
|
bus_dmamap_sync(sc->mfi_buffer_dmat, cm->cm_dmamap,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->mfi_buffer_dmat, cm->cm_dmamap);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
mfi_open(struct cdev *dev, int flags, int fmt, struct thread *td)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
2007-08-13 21:14:16 +00:00
|
|
|
int error;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
sc = dev->si_drv1;
|
2006-10-16 04:18:38 +00:00
|
|
|
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2007-08-13 21:14:16 +00:00
|
|
|
if (sc->mfi_detaching)
|
|
|
|
error = ENXIO;
|
|
|
|
else {
|
|
|
|
sc->mfi_flags |= MFI_FLAGS_OPEN;
|
|
|
|
error = 0;
|
|
|
|
}
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
|
2007-08-13 21:14:16 +00:00
|
|
|
return (error);
|
2006-03-25 06:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
mfi_close(struct cdev *dev, int flags, int fmt, struct thread *td)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
2006-10-16 04:18:38 +00:00
|
|
|
struct mfi_aen *mfi_aen_entry, *tmp;
|
2006-03-25 06:14:32 +00:00
|
|
|
|
|
|
|
sc = dev->si_drv1;
|
2006-10-16 04:18:38 +00:00
|
|
|
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
sc->mfi_flags &= ~MFI_FLAGS_OPEN;
|
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
TAILQ_FOREACH_SAFE(mfi_aen_entry, &sc->mfi_aen_pids, aen_link, tmp) {
|
2006-05-18 23:30:48 +00:00
|
|
|
if (mfi_aen_entry->p == curproc) {
|
|
|
|
TAILQ_REMOVE(&sc->mfi_aen_pids, mfi_aen_entry,
|
|
|
|
aen_link);
|
|
|
|
free(mfi_aen_entry, M_MFIBUF);
|
|
|
|
}
|
|
|
|
}
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-03-25 06:14:32 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
static int
|
|
|
|
mfi_config_lock(struct mfi_softc *sc, uint32_t opcode)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case MFI_DCMD_LD_DELETE:
|
|
|
|
case MFI_DCMD_CFG_ADD:
|
|
|
|
case MFI_DCMD_CFG_CLEAR:
|
2012-09-26 14:14:06 +00:00
|
|
|
case MFI_DCMD_CFG_FOREIGN_IMPORT:
|
2007-08-13 19:29:17 +00:00
|
|
|
sx_xlock(&sc->mfi_config_lock);
|
|
|
|
return (1);
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mfi_config_unlock(struct mfi_softc *sc, int locked)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (locked)
|
|
|
|
sx_xunlock(&sc->mfi_config_lock);
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
/*
|
|
|
|
* Perform pre-issue checks on commands from userland and possibly veto
|
|
|
|
* them.
|
|
|
|
*/
|
2007-08-13 19:29:17 +00:00
|
|
|
static int
|
|
|
|
mfi_check_command_pre(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_disk *ld, *ld2;
|
|
|
|
int error;
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_system_pd *syspd = NULL;
|
|
|
|
uint16_t syspd_id;
|
|
|
|
uint16_t *mbox;
|
2007-08-13 19:29:17 +00:00
|
|
|
|
|
|
|
mtx_assert(&sc->mfi_io_lock, MA_OWNED);
|
|
|
|
error = 0;
|
|
|
|
switch (cm->cm_frame->dcmd.opcode) {
|
|
|
|
case MFI_DCMD_LD_DELETE:
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld->ld_id == cm->cm_frame->dcmd.mbox[0])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ld == NULL)
|
|
|
|
error = ENOENT;
|
|
|
|
else
|
|
|
|
error = mfi_disk_disable(ld);
|
|
|
|
break;
|
|
|
|
case MFI_DCMD_CFG_CLEAR:
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
error = mfi_disk_disable(ld);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
TAILQ_FOREACH(ld2, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld2 == ld)
|
|
|
|
break;
|
|
|
|
mfi_disk_enable(ld2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-11-04 02:34:52 +00:00
|
|
|
case MFI_DCMD_PD_STATE_SET:
|
|
|
|
mbox = (uint16_t *) cm->cm_frame->dcmd.mbox;
|
|
|
|
syspd_id = mbox[0];
|
|
|
|
if (mbox[2] == MFI_PD_STATE_UNCONFIGURED_GOOD) {
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_FOREACH(syspd, &sc->mfi_syspd_tqh, pd_link) {
|
|
|
|
if (syspd->pd_id == syspd_id)
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (syspd)
|
2011-11-04 02:34:52 +00:00
|
|
|
error = mfi_syspd_disable(syspd);
|
|
|
|
break;
|
2007-08-13 19:29:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform post-issue checks on commands from userland. */
|
|
|
|
static void
|
|
|
|
mfi_check_command_post(struct mfi_softc *sc, struct mfi_command *cm)
|
|
|
|
{
|
|
|
|
struct mfi_disk *ld, *ldn;
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_system_pd *syspd = NULL;
|
|
|
|
uint16_t syspd_id;
|
|
|
|
uint16_t *mbox;
|
2007-08-13 19:29:17 +00:00
|
|
|
|
|
|
|
switch (cm->cm_frame->dcmd.opcode) {
|
|
|
|
case MFI_DCMD_LD_DELETE:
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld->ld_id == cm->cm_frame->dcmd.mbox[0])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
KASSERT(ld != NULL, ("volume dissappeared"));
|
|
|
|
if (cm->cm_frame->header.cmd_status == MFI_STAT_OK) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2007-08-13 19:29:17 +00:00
|
|
|
device_delete_child(sc->mfi_dev, ld->ld_dev);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2007-08-13 19:29:17 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
} else
|
|
|
|
mfi_disk_enable(ld);
|
|
|
|
break;
|
|
|
|
case MFI_DCMD_CFG_CLEAR:
|
|
|
|
if (cm->cm_frame->header.cmd_status == MFI_STAT_OK) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2007-08-13 19:29:17 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ld, &sc->mfi_ld_tqh, ld_link, ldn) {
|
|
|
|
device_delete_child(sc->mfi_dev, ld->ld_dev);
|
|
|
|
}
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2007-08-13 19:29:17 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link)
|
|
|
|
mfi_disk_enable(ld);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MFI_DCMD_CFG_ADD:
|
|
|
|
mfi_ldprobe(sc);
|
|
|
|
break;
|
2008-11-12 22:44:50 +00:00
|
|
|
case MFI_DCMD_CFG_FOREIGN_IMPORT:
|
|
|
|
mfi_ldprobe(sc);
|
|
|
|
break;
|
2011-11-04 02:34:52 +00:00
|
|
|
case MFI_DCMD_PD_STATE_SET:
|
|
|
|
mbox = (uint16_t *) cm->cm_frame->dcmd.mbox;
|
|
|
|
syspd_id = mbox[0];
|
|
|
|
if (mbox[2] == MFI_PD_STATE_UNCONFIGURED_GOOD) {
|
2012-03-30 23:05:48 +00:00
|
|
|
TAILQ_FOREACH(syspd, &sc->mfi_syspd_tqh,pd_link) {
|
|
|
|
if (syspd->pd_id == syspd_id)
|
2011-11-04 02:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
/* If the transition fails then enable the syspd again */
|
2012-03-30 23:05:48 +00:00
|
|
|
if (syspd && cm->cm_frame->header.cmd_status != MFI_STAT_OK)
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_syspd_enable(syspd);
|
|
|
|
break;
|
2007-08-13 19:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
static int
|
|
|
|
mfi_check_for_sscd(struct mfi_softc *sc, struct mfi_command *cm)
|
2011-11-04 02:34:52 +00:00
|
|
|
{
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_config_data *conf_data;
|
2011-11-04 02:34:52 +00:00
|
|
|
struct mfi_command *ld_cm = NULL;
|
|
|
|
struct mfi_ld_info *ld_info = NULL;
|
2012-11-06 23:25:06 +00:00
|
|
|
struct mfi_ld_config *ld;
|
|
|
|
char *p;
|
2011-11-04 02:34:52 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2012-11-06 23:25:06 +00:00
|
|
|
conf_data = (struct mfi_config_data *)cm->cm_data;
|
|
|
|
|
|
|
|
if (cm->cm_frame->dcmd.opcode == MFI_DCMD_CFG_ADD) {
|
|
|
|
p = (char *)conf_data->array;
|
|
|
|
p += conf_data->array_size * conf_data->array_count;
|
|
|
|
ld = (struct mfi_ld_config *)p;
|
|
|
|
if (ld->params.isSSCD == 1)
|
|
|
|
error = 1;
|
2012-03-30 23:05:48 +00:00
|
|
|
} else if (cm->cm_frame->dcmd.opcode == MFI_DCMD_LD_DELETE) {
|
2011-11-04 02:34:52 +00:00
|
|
|
error = mfi_dcmd_command (sc, &ld_cm, MFI_DCMD_LD_GET_INFO,
|
2012-03-30 23:05:48 +00:00
|
|
|
(void **)&ld_info, sizeof(*ld_info));
|
2012-05-04 16:22:13 +00:00
|
|
|
if (error) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "Failed to allocate"
|
|
|
|
"MFI_DCMD_LD_GET_INFO %d", error);
|
2011-11-04 02:34:52 +00:00
|
|
|
if (ld_info)
|
2012-03-30 23:05:48 +00:00
|
|
|
free(ld_info, M_MFIBUF);
|
2011-11-04 02:34:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ld_cm->cm_flags = MFI_CMD_DATAIN;
|
|
|
|
ld_cm->cm_frame->dcmd.mbox[0]= cm->cm_frame->dcmd.mbox[0];
|
|
|
|
ld_cm->cm_frame->header.target_id = cm->cm_frame->dcmd.mbox[0];
|
2012-05-04 16:22:13 +00:00
|
|
|
if (mfi_wait_command(sc, ld_cm) != 0) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev, "failed to get log drv\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_release_command(ld_cm);
|
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (ld_cm->cm_frame->header.cmd_status != MFI_STAT_OK) {
|
2011-11-04 02:34:52 +00:00
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
mfi_release_command(ld_cm);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ld_info = (struct mfi_ld_info *)ld_cm->cm_private;
|
|
|
|
|
|
|
|
if (ld_info->ld_config.params.isSSCD == 1)
|
|
|
|
error = 1;
|
|
|
|
|
|
|
|
mfi_release_command(ld_cm);
|
|
|
|
free(ld_info, M_MFIBUF);
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
return error;
|
2007-08-13 19:29:17 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
static int
|
|
|
|
mfi_stp_cmd(struct mfi_softc *sc, struct mfi_command *cm,caddr_t arg)
|
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
struct mfi_ioc_packet *ioc;
|
|
|
|
ioc = (struct mfi_ioc_packet *)arg;
|
|
|
|
int sge_size, error;
|
|
|
|
struct megasas_sge *kern_sge;
|
|
|
|
|
|
|
|
memset(sc->kbuff_arr, 0, sizeof(sc->kbuff_arr));
|
|
|
|
kern_sge =(struct megasas_sge *) ((uintptr_t)cm->cm_frame + ioc->mfi_sgl_off);
|
|
|
|
cm->cm_frame->header.sg_count = ioc->mfi_sge_count;
|
|
|
|
|
|
|
|
if (sizeof(bus_addr_t) == 8) {
|
|
|
|
cm->cm_frame->header.flags |= MFI_FRAME_SGL64;
|
|
|
|
cm->cm_extra_frames = 2;
|
|
|
|
sge_size = sizeof(struct mfi_sg64);
|
|
|
|
} else {
|
|
|
|
cm->cm_extra_frames = (cm->cm_total_frame_size - 1) / MFI_FRAME_SIZE;
|
|
|
|
sge_size = sizeof(struct mfi_sg32);
|
|
|
|
}
|
|
|
|
|
|
|
|
cm->cm_total_frame_size += (sge_size * ioc->mfi_sge_count);
|
2012-03-30 23:05:48 +00:00
|
|
|
for (i = 0; i < ioc->mfi_sge_count; i++) {
|
2011-11-04 02:34:52 +00:00
|
|
|
if (bus_dma_tag_create( sc->mfi_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
2012-03-30 23:05:48 +00:00
|
|
|
ioc->mfi_sgl[i].iov_len,/* maxsize */
|
2011-11-04 02:34:52 +00:00
|
|
|
2, /* nsegments */
|
2012-03-30 23:05:48 +00:00
|
|
|
ioc->mfi_sgl[i].iov_len,/* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
2011-11-04 02:34:52 +00:00
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->mfi_kbuff_arr_dmat[i])) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Cannot allocate mfi_kbuff_arr_dmat tag\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
if (bus_dmamem_alloc(sc->mfi_kbuff_arr_dmat[i],
|
|
|
|
(void **)&sc->kbuff_arr[i], BUS_DMA_NOWAIT,
|
|
|
|
&sc->mfi_kbuff_arr_dmamap[i])) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Cannot allocate mfi_kbuff_arr_dmamap memory\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2012-03-30 23:05:48 +00:00
|
|
|
bus_dmamap_load(sc->mfi_kbuff_arr_dmat[i],
|
|
|
|
sc->mfi_kbuff_arr_dmamap[i], sc->kbuff_arr[i],
|
|
|
|
ioc->mfi_sgl[i].iov_len, mfi_addr_cb,
|
|
|
|
&sc->mfi_kbuff_arr_busaddr[i], 0);
|
2011-11-04 02:34:52 +00:00
|
|
|
|
|
|
|
if (!sc->kbuff_arr[i]) {
|
2012-03-30 23:05:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Could not allocate memory for kbuff_arr info\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
kern_sge[i].phys_addr = sc->mfi_kbuff_arr_busaddr[i];
|
|
|
|
kern_sge[i].length = ioc->mfi_sgl[i].iov_len;
|
|
|
|
|
|
|
|
if (sizeof(bus_addr_t) == 8) {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm->cm_frame->stp.sgl.sg64[i].addr =
|
|
|
|
kern_sge[i].phys_addr;
|
|
|
|
cm->cm_frame->stp.sgl.sg64[i].len =
|
|
|
|
ioc->mfi_sgl[i].iov_len;
|
2011-11-04 02:34:52 +00:00
|
|
|
} else {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm->cm_frame->stp.sgl.sg32[i].len =
|
|
|
|
kern_sge[i].phys_addr;
|
|
|
|
cm->cm_frame->stp.sgl.sg32[i].len =
|
|
|
|
ioc->mfi_sgl[i].iov_len;
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error = copyin(ioc->mfi_sgl[i].iov_base,
|
|
|
|
sc->kbuff_arr[i],
|
|
|
|
ioc->mfi_sgl[i].iov_len);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev, "Copy in failed\n");
|
2011-11-04 02:34:52 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cm->cm_flags |=MFI_CMD_MAPPED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-12 14:09:19 +00:00
|
|
|
static int
|
|
|
|
mfi_user_command(struct mfi_softc *sc, struct mfi_ioc_passthru *ioc)
|
|
|
|
{
|
|
|
|
struct mfi_command *cm;
|
|
|
|
struct mfi_dcmd_frame *dcmd;
|
|
|
|
void *ioc_buf = NULL;
|
|
|
|
uint32_t context;
|
|
|
|
int error = 0, locked;
|
|
|
|
|
|
|
|
|
|
|
|
if (ioc->buf_size > 0) {
|
2012-07-03 16:12:57 +00:00
|
|
|
if (ioc->buf_size > 1024 * 1024)
|
2008-05-12 14:09:19 +00:00
|
|
|
return (ENOMEM);
|
2012-07-03 16:12:57 +00:00
|
|
|
ioc_buf = malloc(ioc->buf_size, M_MFIBUF, M_WAITOK);
|
2008-05-12 14:09:19 +00:00
|
|
|
error = copyin(ioc->buf, ioc_buf, ioc->buf_size);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->mfi_dev, "failed to copyin\n");
|
|
|
|
free(ioc_buf, M_MFIBUF);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locked = mfi_config_lock(sc, ioc->ioc_frame.opcode);
|
|
|
|
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
while ((cm = mfi_dequeue_free(sc)) == NULL)
|
|
|
|
msleep(mfi_user_command, &sc->mfi_io_lock, 0, "mfiioc", hz);
|
|
|
|
|
|
|
|
/* Save context for later */
|
|
|
|
context = cm->cm_frame->header.context;
|
|
|
|
|
|
|
|
dcmd = &cm->cm_frame->dcmd;
|
|
|
|
bcopy(&ioc->ioc_frame, dcmd, sizeof(struct mfi_dcmd_frame));
|
|
|
|
|
|
|
|
cm->cm_sg = &dcmd->sgl;
|
|
|
|
cm->cm_total_frame_size = MFI_DCMD_FRAME_SIZE;
|
|
|
|
cm->cm_data = ioc_buf;
|
|
|
|
cm->cm_len = ioc->buf_size;
|
|
|
|
|
|
|
|
/* restore context */
|
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
|
|
|
/* Cheat since we don't know if we're writing or reading */
|
|
|
|
cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_DATAOUT;
|
|
|
|
|
|
|
|
error = mfi_check_command_pre(sc, cm);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = mfi_wait_command(sc, cm);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->mfi_dev, "ioctl failed %d\n", error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
bcopy(dcmd, &ioc->ioc_frame, sizeof(struct mfi_dcmd_frame));
|
|
|
|
mfi_check_command_post(sc, cm);
|
|
|
|
out:
|
|
|
|
mfi_release_command(cm);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
mfi_config_unlock(sc, locked);
|
|
|
|
if (ioc->buf_size > 0)
|
|
|
|
error = copyout(ioc_buf, ioc->buf, ioc->buf_size);
|
|
|
|
if (ioc_buf)
|
|
|
|
free(ioc_buf, M_MFIBUF);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PTRIN(p) ((void *)(uintptr_t)(p))
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
mfi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
|
2006-03-25 06:14:32 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
union mfi_statrequest *ms;
|
2006-11-14 16:48:00 +00:00
|
|
|
struct mfi_ioc_packet *ioc;
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-05-28 23:19:27 +00:00
|
|
|
struct mfi_ioc_packet32 *ioc32;
|
|
|
|
#endif
|
2006-11-14 16:48:00 +00:00
|
|
|
struct mfi_ioc_aen *aen;
|
|
|
|
struct mfi_command *cm = NULL;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2008-11-12 22:44:50 +00:00
|
|
|
union mfi_sense_ptr sense_ptr;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint8_t *data = NULL, *temp, *addr, skip_pre_post = 0;
|
2011-09-29 08:37:53 +00:00
|
|
|
size_t len;
|
2011-11-04 02:34:52 +00:00
|
|
|
int i, res;
|
2008-05-12 14:09:19 +00:00
|
|
|
struct mfi_ioc_passthru *iop = (struct mfi_ioc_passthru *)arg;
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-05-12 14:09:19 +00:00
|
|
|
struct mfi_ioc_passthru32 *iop32 = (struct mfi_ioc_passthru32 *)arg;
|
|
|
|
struct mfi_ioc_passthru iop_swab;
|
|
|
|
#endif
|
2007-08-13 19:29:17 +00:00
|
|
|
int error, locked;
|
2011-11-04 02:34:52 +00:00
|
|
|
union mfi_sgl *sgl;
|
2006-03-25 06:14:32 +00:00
|
|
|
sc = dev->si_drv1;
|
|
|
|
error = 0;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
if (sc->adpreset)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
if (sc->hw_crit_error)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
if (sc->issuepend_done == 0)
|
|
|
|
return EBUSY;
|
|
|
|
|
2006-03-25 06:14:32 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case MFIIO_STATS:
|
|
|
|
ms = (union mfi_statrequest *)arg;
|
|
|
|
switch (ms->ms_item) {
|
|
|
|
case MFIQ_FREE:
|
|
|
|
case MFIQ_BIO:
|
|
|
|
case MFIQ_READY:
|
|
|
|
case MFIQ_BUSY:
|
|
|
|
bcopy(&sc->mfi_qstat[ms->ms_item], &ms->ms_qstat,
|
|
|
|
sizeof(struct mfi_qstat));
|
|
|
|
break;
|
|
|
|
default:
|
2006-05-18 23:30:48 +00:00
|
|
|
error = ENOIOCTL;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2007-05-10 15:33:41 +00:00
|
|
|
case MFIIO_QUERY_DISK:
|
|
|
|
{
|
|
|
|
struct mfi_query_disk *qd;
|
|
|
|
struct mfi_disk *ld;
|
|
|
|
|
|
|
|
qd = (struct mfi_query_disk *)arg;
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
TAILQ_FOREACH(ld, &sc->mfi_ld_tqh, ld_link) {
|
|
|
|
if (ld->ld_id == qd->array_id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ld == NULL) {
|
|
|
|
qd->present = 0;
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
qd->present = 1;
|
|
|
|
if (ld->ld_flags & MFI_DISK_FLAGS_OPEN)
|
|
|
|
qd->open = 1;
|
|
|
|
bzero(qd->devname, SPECNAMELEN + 1);
|
|
|
|
snprintf(qd->devname, SPECNAMELEN, "mfid%d", ld->ld_unit);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
break;
|
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
case MFI_CMD:
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-05-28 23:19:27 +00:00
|
|
|
case MFI_CMD32:
|
|
|
|
#endif
|
2008-03-22 02:57:49 +00:00
|
|
|
{
|
|
|
|
devclass_t devclass;
|
2006-11-14 16:48:00 +00:00
|
|
|
ioc = (struct mfi_ioc_packet *)arg;
|
2008-03-22 02:57:49 +00:00
|
|
|
int adapter;
|
2006-11-14 16:48:00 +00:00
|
|
|
|
2008-03-22 02:57:49 +00:00
|
|
|
adapter = ioc->mfi_adapter_no;
|
|
|
|
if (device_get_unit(sc->mfi_dev) == 0 && adapter != 0) {
|
|
|
|
devclass = devclass_find("mfi");
|
|
|
|
sc = devclass_get_softc(devclass, adapter);
|
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2007-08-13 19:29:17 +00:00
|
|
|
locked = 0;
|
2006-11-14 16:48:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* save off original context since copying from user
|
|
|
|
* will clobber some data
|
|
|
|
*/
|
|
|
|
context = cm->cm_frame->header.context;
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.context = cm->cm_index;
|
2006-11-14 16:48:00 +00:00
|
|
|
|
2006-12-14 18:29:08 +00:00
|
|
|
bcopy(ioc->mfi_frame.raw, cm->cm_frame,
|
2011-11-04 02:34:52 +00:00
|
|
|
2 * MEGAMFI_FRAME_SIZE);
|
2008-11-12 22:44:50 +00:00
|
|
|
cm->cm_total_frame_size = (sizeof(union mfi_sgl)
|
|
|
|
* ioc->mfi_sge_count) + ioc->mfi_sgl_off;
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.scsi_status = 0;
|
|
|
|
cm->cm_frame->header.pad0 = 0;
|
2008-02-02 17:29:28 +00:00
|
|
|
if (ioc->mfi_sge_count) {
|
|
|
|
cm->cm_sg =
|
|
|
|
(union mfi_sgl *)&cm->cm_frame->bytes[ioc->mfi_sgl_off];
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
sgl = cm->cm_sg;
|
2008-02-02 17:29:28 +00:00
|
|
|
cm->cm_flags = 0;
|
|
|
|
if (cm->cm_frame->header.flags & MFI_FRAME_DATAIN)
|
|
|
|
cm->cm_flags |= MFI_CMD_DATAIN;
|
|
|
|
if (cm->cm_frame->header.flags & MFI_FRAME_DATAOUT)
|
|
|
|
cm->cm_flags |= MFI_CMD_DATAOUT;
|
|
|
|
/* Legacy app shim */
|
|
|
|
if (cm->cm_flags == 0)
|
|
|
|
cm->cm_flags |= MFI_CMD_DATAIN | MFI_CMD_DATAOUT;
|
2006-11-14 16:48:00 +00:00
|
|
|
cm->cm_len = cm->cm_frame->header.data_len;
|
2011-09-29 08:37:53 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_STP) {
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-09-29 08:37:53 +00:00
|
|
|
if (cmd == MFI_CMD) {
|
|
|
|
#endif
|
|
|
|
/* Native */
|
|
|
|
cm->cm_stp_len = ioc->mfi_sgl[0].iov_len;
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-09-29 08:37:53 +00:00
|
|
|
} else {
|
|
|
|
/* 32bit on 64bit */
|
|
|
|
ioc32 = (struct mfi_ioc_packet32 *)ioc;
|
|
|
|
cm->cm_stp_len = ioc32->mfi_sgl[0].iov_len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
cm->cm_len += cm->cm_stp_len;
|
|
|
|
}
|
2008-11-12 22:44:50 +00:00
|
|
|
if (cm->cm_len &&
|
|
|
|
(cm->cm_flags & (MFI_CMD_DATAIN | MFI_CMD_DATAOUT))) {
|
2008-02-02 17:29:28 +00:00
|
|
|
cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
if (cm->cm_data == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Malloc failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cm->cm_data = 0;
|
2006-12-14 18:29:08 +00:00
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
|
|
|
|
/* restore header context */
|
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_STP) {
|
2012-03-30 23:05:48 +00:00
|
|
|
res = mfi_stp_cmd(sc, cm, arg);
|
|
|
|
if (res != 0)
|
2011-11-04 02:34:52 +00:00
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
temp = data;
|
|
|
|
if ((cm->cm_flags & MFI_CMD_DATAOUT) ||
|
|
|
|
(cm->cm_frame->header.cmd == MFI_CMD_STP)) {
|
|
|
|
for (i = 0; i < ioc->mfi_sge_count; i++) {
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-11-04 02:34:52 +00:00
|
|
|
if (cmd == MFI_CMD) {
|
2011-09-29 08:37:53 +00:00
|
|
|
#endif
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Native */
|
|
|
|
addr = ioc->mfi_sgl[i].iov_base;
|
|
|
|
len = ioc->mfi_sgl[i].iov_len;
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-11-04 02:34:52 +00:00
|
|
|
} else {
|
|
|
|
/* 32bit on 64bit */
|
|
|
|
ioc32 = (struct mfi_ioc_packet32 *)ioc;
|
|
|
|
addr = PTRIN(ioc32->mfi_sgl[i].iov_base);
|
|
|
|
len = ioc32->mfi_sgl[i].iov_len;
|
|
|
|
}
|
2008-05-28 23:19:27 +00:00
|
|
|
#endif
|
2011-11-04 02:34:52 +00:00
|
|
|
error = copyin(addr, temp, len);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Copy in failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
temp = &temp[len];
|
2008-02-02 17:29:28 +00:00
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_DCMD)
|
2012-03-30 23:05:48 +00:00
|
|
|
locked = mfi_config_lock(sc,
|
|
|
|
cm->cm_frame->dcmd.opcode);
|
2007-08-13 19:29:17 +00:00
|
|
|
|
2008-11-13 17:13:16 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_PD_SCSI_IO) {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm->cm_frame->pass.sense_addr_lo =
|
|
|
|
(uint32_t)cm->cm_sense_busaddr;
|
|
|
|
cm->cm_frame->pass.sense_addr_hi =
|
|
|
|
(uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2008-11-13 17:13:16 +00:00
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2011-11-04 02:34:52 +00:00
|
|
|
skip_pre_post = mfi_check_for_sscd (sc, cm);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (!skip_pre_post) {
|
2011-11-04 02:34:52 +00:00
|
|
|
error = mfi_check_command_pre(sc, cm);
|
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
goto out;
|
|
|
|
}
|
2007-08-13 19:29:17 +00:00
|
|
|
}
|
2007-06-04 16:39:22 +00:00
|
|
|
if ((error = mfi_wait_command(sc, cm)) != 0) {
|
2006-11-14 16:48:00 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
2006-12-14 18:29:08 +00:00
|
|
|
"Controller polled failed\n");
|
2006-11-14 16:48:00 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
if (!skip_pre_post) {
|
2011-11-04 02:34:52 +00:00
|
|
|
mfi_check_command_post(sc, cm);
|
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
|
2011-11-04 02:34:52 +00:00
|
|
|
if (cm->cm_frame->header.cmd != MFI_CMD_STP) {
|
|
|
|
temp = data;
|
|
|
|
if ((cm->cm_flags & MFI_CMD_DATAIN) ||
|
|
|
|
(cm->cm_frame->header.cmd == MFI_CMD_STP)) {
|
|
|
|
for (i = 0; i < ioc->mfi_sge_count; i++) {
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-11-04 02:34:52 +00:00
|
|
|
if (cmd == MFI_CMD) {
|
2011-09-29 08:37:53 +00:00
|
|
|
#endif
|
2011-11-04 02:34:52 +00:00
|
|
|
/* Native */
|
|
|
|
addr = ioc->mfi_sgl[i].iov_base;
|
|
|
|
len = ioc->mfi_sgl[i].iov_len;
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2011-11-04 02:34:52 +00:00
|
|
|
} else {
|
|
|
|
/* 32bit on 64bit */
|
|
|
|
ioc32 = (struct mfi_ioc_packet32 *)ioc;
|
|
|
|
addr = PTRIN(ioc32->mfi_sgl[i].iov_base);
|
|
|
|
len = ioc32->mfi_sgl[i].iov_len;
|
|
|
|
}
|
2008-05-28 23:19:27 +00:00
|
|
|
#endif
|
2011-11-04 02:34:52 +00:00
|
|
|
error = copyout(temp, addr, len);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Copy out failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
temp = &temp[len];
|
2008-02-02 17:29:28 +00:00
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-14 18:29:08 +00:00
|
|
|
if (ioc->mfi_sense_len) {
|
2008-11-12 22:44:50 +00:00
|
|
|
/* get user-space sense ptr then copy out sense */
|
2011-09-07 00:43:28 +00:00
|
|
|
bcopy(&ioc->mfi_frame.raw[ioc->mfi_sense_off],
|
2008-11-12 22:44:50 +00:00
|
|
|
&sense_ptr.sense_ptr_data[0],
|
|
|
|
sizeof(sense_ptr.sense_ptr_data));
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-11-14 21:05:45 +00:00
|
|
|
if (cmd != MFI_CMD) {
|
|
|
|
/*
|
|
|
|
* not 64bit native so zero out any address
|
|
|
|
* over 32bit */
|
2008-11-14 23:32:31 +00:00
|
|
|
sense_ptr.addr.high = 0;
|
2008-11-14 21:05:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-11-12 22:44:50 +00:00
|
|
|
error = copyout(cm->cm_sense, sense_ptr.user_space,
|
2006-12-14 18:29:08 +00:00
|
|
|
ioc->mfi_sense_len);
|
2006-11-14 16:48:00 +00:00
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
2006-12-14 18:29:08 +00:00
|
|
|
"Copy out failed\n");
|
2006-11-14 16:48:00 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-14 18:29:08 +00:00
|
|
|
ioc->mfi_frame.hdr.cmd_status = cm->cm_frame->header.cmd_status;
|
2006-11-14 16:48:00 +00:00
|
|
|
out:
|
2007-08-13 19:29:17 +00:00
|
|
|
mfi_config_unlock(sc, locked);
|
2006-11-14 16:48:00 +00:00
|
|
|
if (data)
|
|
|
|
free(data, M_MFIBUF);
|
2012-03-30 23:05:48 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_STP) {
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (sc->kbuff_arr[i]) {
|
|
|
|
if (sc->mfi_kbuff_arr_busaddr != 0)
|
|
|
|
bus_dmamap_unload(
|
|
|
|
sc->mfi_kbuff_arr_dmat[i],
|
|
|
|
sc->mfi_kbuff_arr_dmamap[i]
|
|
|
|
);
|
|
|
|
if (sc->kbuff_arr[i] != NULL)
|
|
|
|
bus_dmamem_free(
|
|
|
|
sc->mfi_kbuff_arr_dmat[i],
|
|
|
|
sc->kbuff_arr[i],
|
|
|
|
sc->mfi_kbuff_arr_dmamap[i]
|
|
|
|
);
|
|
|
|
if (sc->mfi_kbuff_arr_dmat[i] != NULL)
|
|
|
|
bus_dma_tag_destroy(
|
|
|
|
sc->mfi_kbuff_arr_dmat[i]);
|
|
|
|
}
|
2011-11-04 02:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
if (cm) {
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-03-22 02:57:49 +00:00
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
case MFI_SET_AEN:
|
|
|
|
aen = (struct mfi_ioc_aen *)arg;
|
|
|
|
error = mfi_aen_register(sc, aen->aen_seq_num,
|
|
|
|
aen->aen_class_locale);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case MFI_LINUX_CMD_2: /* Firmware Linux ioctl shim */
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
|
|
|
devclass_t devclass;
|
|
|
|
struct mfi_linux_ioc_packet l_ioc;
|
|
|
|
int adapter;
|
|
|
|
|
|
|
|
devclass = devclass_find("mfi");
|
|
|
|
if (devclass == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
error = copyin(arg, &l_ioc, sizeof(l_ioc));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
adapter = l_ioc.lioc_adapter_no;
|
|
|
|
sc = devclass_get_softc(devclass, adapter);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
return (mfi_linux_ioctl_int(sc->mfi_cdev,
|
|
|
|
cmd, arg, flag, td));
|
|
|
|
break;
|
|
|
|
}
|
2006-11-14 16:48:00 +00:00
|
|
|
case MFI_LINUX_SET_AEN_2: /* AEN Linux ioctl shim */
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
|
|
|
devclass_t devclass;
|
|
|
|
struct mfi_linux_ioc_aen l_aen;
|
|
|
|
int adapter;
|
|
|
|
|
|
|
|
devclass = devclass_find("mfi");
|
|
|
|
if (devclass == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
error = copyin(arg, &l_aen, sizeof(l_aen));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
adapter = l_aen.laen_adapter_no;
|
|
|
|
sc = devclass_get_softc(devclass, adapter);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
return (mfi_linux_ioctl_int(sc->mfi_cdev,
|
|
|
|
cmd, arg, flag, td));
|
|
|
|
break;
|
|
|
|
}
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-05-12 14:09:19 +00:00
|
|
|
case MFIIO_PASSTHRU32:
|
2012-07-03 16:12:57 +00:00
|
|
|
if (!SV_CURPROC_FLAG(SV_ILP32)) {
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-12 14:09:19 +00:00
|
|
|
iop_swab.ioc_frame = iop32->ioc_frame;
|
|
|
|
iop_swab.buf_size = iop32->buf_size;
|
|
|
|
iop_swab.buf = PTRIN(iop32->buf);
|
|
|
|
iop = &iop_swab;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
#endif
|
|
|
|
case MFIIO_PASSTHRU:
|
|
|
|
error = mfi_user_command(sc, iop);
|
2012-03-30 23:05:48 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2008-05-12 14:09:19 +00:00
|
|
|
if (cmd == MFIIO_PASSTHRU32)
|
|
|
|
iop32->ioc_frame = iop_swab.ioc_frame;
|
|
|
|
#endif
|
|
|
|
break;
|
2006-03-25 06:14:32 +00:00
|
|
|
default:
|
2006-10-16 04:18:38 +00:00
|
|
|
device_printf(sc->mfi_dev, "IOCTL 0x%lx not handled\n", cmd);
|
2012-07-03 16:12:57 +00:00
|
|
|
error = ENOTTY;
|
2006-03-25 06:14:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
mfi_linux_ioctl_int(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
|
2006-05-18 23:30:48 +00:00
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
struct mfi_linux_ioc_packet l_ioc;
|
|
|
|
struct mfi_linux_ioc_aen l_aen;
|
|
|
|
struct mfi_command *cm = NULL;
|
|
|
|
struct mfi_aen *mfi_aen_entry;
|
2008-11-12 22:44:50 +00:00
|
|
|
union mfi_sense_ptr sense_ptr;
|
2011-11-04 02:34:52 +00:00
|
|
|
uint32_t context = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
uint8_t *data = NULL, *temp;
|
|
|
|
int i;
|
2007-08-13 19:29:17 +00:00
|
|
|
int error, locked;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
sc = dev->si_drv1;
|
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
2006-11-14 16:48:00 +00:00
|
|
|
case MFI_LINUX_CMD_2: /* Firmware Linux ioctl shim */
|
2006-05-18 23:30:48 +00:00
|
|
|
error = copyin(arg, &l_ioc, sizeof(l_ioc));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (l_ioc.lioc_sge_count > MAX_LINUX_IOCTL_SGE) {
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
if ((cm = mfi_dequeue_free(sc)) == NULL) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2007-08-13 19:29:17 +00:00
|
|
|
locked = 0;
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* save off original context since copying from user
|
|
|
|
* will clobber some data
|
|
|
|
*/
|
|
|
|
context = cm->cm_frame->header.context;
|
|
|
|
|
|
|
|
bcopy(l_ioc.lioc_frame.raw, cm->cm_frame,
|
2008-02-02 17:29:28 +00:00
|
|
|
2 * MFI_DCMD_FRAME_SIZE); /* this isn't quite right */
|
2008-11-12 22:44:50 +00:00
|
|
|
cm->cm_total_frame_size = (sizeof(union mfi_sgl)
|
|
|
|
* l_ioc.lioc_sge_count) + l_ioc.lioc_sgl_off;
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_frame->header.scsi_status = 0;
|
|
|
|
cm->cm_frame->header.pad0 = 0;
|
2008-02-02 17:29:28 +00:00
|
|
|
if (l_ioc.lioc_sge_count)
|
|
|
|
cm->cm_sg =
|
|
|
|
(union mfi_sgl *)&cm->cm_frame->bytes[l_ioc.lioc_sgl_off];
|
|
|
|
cm->cm_flags = 0;
|
|
|
|
if (cm->cm_frame->header.flags & MFI_FRAME_DATAIN)
|
|
|
|
cm->cm_flags |= MFI_CMD_DATAIN;
|
|
|
|
if (cm->cm_frame->header.flags & MFI_FRAME_DATAOUT)
|
|
|
|
cm->cm_flags |= MFI_CMD_DATAOUT;
|
2006-05-18 23:30:48 +00:00
|
|
|
cm->cm_len = cm->cm_frame->header.data_len;
|
2008-11-12 22:44:50 +00:00
|
|
|
if (cm->cm_len &&
|
|
|
|
(cm->cm_flags & (MFI_CMD_DATAIN | MFI_CMD_DATAOUT))) {
|
2008-02-02 17:29:28 +00:00
|
|
|
cm->cm_data = data = malloc(cm->cm_len, M_MFIBUF,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
if (cm->cm_data == NULL) {
|
|
|
|
device_printf(sc->mfi_dev, "Malloc failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cm->cm_data = 0;
|
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
/* restore header context */
|
|
|
|
cm->cm_frame->header.context = context;
|
|
|
|
|
|
|
|
temp = data;
|
2008-02-02 17:29:28 +00:00
|
|
|
if (cm->cm_flags & MFI_CMD_DATAOUT) {
|
|
|
|
for (i = 0; i < l_ioc.lioc_sge_count; i++) {
|
2008-05-12 14:09:19 +00:00
|
|
|
error = copyin(PTRIN(l_ioc.lioc_sgl[i].iov_base),
|
2008-02-02 17:29:28 +00:00
|
|
|
temp,
|
|
|
|
l_ioc.lioc_sgl[i].iov_len);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Copy in failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
temp = &temp[l_ioc.lioc_sgl[i].iov_len];
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_DCMD)
|
|
|
|
locked = mfi_config_lock(sc, cm->cm_frame->dcmd.opcode);
|
|
|
|
|
2008-11-13 17:13:16 +00:00
|
|
|
if (cm->cm_frame->header.cmd == MFI_CMD_PD_SCSI_IO) {
|
2012-03-30 23:05:48 +00:00
|
|
|
cm->cm_frame->pass.sense_addr_lo =
|
|
|
|
(uint32_t)cm->cm_sense_busaddr;
|
|
|
|
cm->cm_frame->pass.sense_addr_hi =
|
|
|
|
(uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
|
2008-11-13 17:13:16 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2007-08-13 19:29:17 +00:00
|
|
|
error = mfi_check_command_pre(sc, cm);
|
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-06-04 16:39:22 +00:00
|
|
|
if ((error = mfi_wait_command(sc, cm)) != 0) {
|
2006-05-18 23:30:48 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
2006-12-14 18:29:08 +00:00
|
|
|
"Controller polled failed\n");
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-08-13 19:29:17 +00:00
|
|
|
mfi_check_command_post(sc, cm);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
temp = data;
|
2008-02-02 17:29:28 +00:00
|
|
|
if (cm->cm_flags & MFI_CMD_DATAIN) {
|
|
|
|
for (i = 0; i < l_ioc.lioc_sge_count; i++) {
|
|
|
|
error = copyout(temp,
|
2008-05-12 14:09:19 +00:00
|
|
|
PTRIN(l_ioc.lioc_sgl[i].iov_base),
|
2008-02-02 17:29:28 +00:00
|
|
|
l_ioc.lioc_sgl[i].iov_len);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
|
|
|
"Copy out failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
temp = &temp[l_ioc.lioc_sgl[i].iov_len];
|
2006-05-18 23:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_ioc.lioc_sense_len) {
|
2008-11-12 22:44:50 +00:00
|
|
|
/* get user-space sense ptr then copy out sense */
|
|
|
|
bcopy(&((struct mfi_linux_ioc_packet*)arg)
|
|
|
|
->lioc_frame.raw[l_ioc.lioc_sense_off],
|
|
|
|
&sense_ptr.sense_ptr_data[0],
|
|
|
|
sizeof(sense_ptr.sense_ptr_data));
|
2008-11-14 21:05:45 +00:00
|
|
|
#ifdef __amd64__
|
|
|
|
/*
|
|
|
|
* only 32bit Linux support so zero out any
|
|
|
|
* address over 32bit
|
|
|
|
*/
|
2008-11-14 23:32:31 +00:00
|
|
|
sense_ptr.addr.high = 0;
|
2008-11-14 21:05:45 +00:00
|
|
|
#endif
|
2008-11-12 22:44:50 +00:00
|
|
|
error = copyout(cm->cm_sense, sense_ptr.user_space,
|
2006-05-18 23:30:48 +00:00
|
|
|
l_ioc.lioc_sense_len);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
2006-12-14 18:29:08 +00:00
|
|
|
"Copy out failed\n");
|
2006-05-18 23:30:48 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = copyout(&cm->cm_frame->header.cmd_status,
|
|
|
|
&((struct mfi_linux_ioc_packet*)arg)
|
|
|
|
->lioc_frame.hdr.cmd_status,
|
|
|
|
1);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->mfi_dev,
|
2006-12-14 18:29:08 +00:00
|
|
|
"Copy out failed\n");
|
2006-05-18 23:30:48 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2007-08-13 19:29:17 +00:00
|
|
|
mfi_config_unlock(sc, locked);
|
2006-05-18 23:30:48 +00:00
|
|
|
if (data)
|
|
|
|
free(data, M_MFIBUF);
|
|
|
|
if (cm) {
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
mfi_release_command(cm);
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
2006-11-14 16:48:00 +00:00
|
|
|
case MFI_LINUX_SET_AEN_2: /* AEN Linux ioctl shim */
|
2006-05-18 23:30:48 +00:00
|
|
|
error = copyin(arg, &l_aen, sizeof(l_aen));
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
printf("AEN IMPLEMENTED for pid %d\n", curproc->p_pid);
|
|
|
|
mfi_aen_entry = malloc(sizeof(struct mfi_aen), M_MFIBUF,
|
|
|
|
M_WAITOK);
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
if (mfi_aen_entry != NULL) {
|
|
|
|
mfi_aen_entry->p = curproc;
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mfi_aen_pids, mfi_aen_entry,
|
|
|
|
aen_link);
|
|
|
|
}
|
|
|
|
error = mfi_aen_register(sc, l_aen.laen_seq_num,
|
|
|
|
l_aen.laen_class_locale);
|
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
TAILQ_REMOVE(&sc->mfi_aen_pids, mfi_aen_entry,
|
|
|
|
aen_link);
|
|
|
|
free(mfi_aen_entry, M_MFIBUF);
|
|
|
|
}
|
2006-10-16 04:18:38 +00:00
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
2006-05-18 23:30:48 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
default:
|
|
|
|
device_printf(sc->mfi_dev, "IOCTL 0x%lx not handled\n", cmd);
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mfi_poll(struct cdev *dev, int poll_events, struct thread *td)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
int revents = 0;
|
|
|
|
|
|
|
|
sc = dev->si_drv1;
|
|
|
|
|
|
|
|
if (poll_events & (POLLIN | POLLRDNORM)) {
|
2006-10-16 04:18:38 +00:00
|
|
|
if (sc->mfi_aen_triggered != 0) {
|
2006-05-18 23:30:48 +00:00
|
|
|
revents |= poll_events & (POLLIN | POLLRDNORM);
|
2006-10-16 04:18:38 +00:00
|
|
|
sc->mfi_aen_triggered = 0;
|
|
|
|
}
|
2006-05-18 23:30:48 +00:00
|
|
|
if (sc->mfi_aen_triggered == 0 && sc->mfi_aen_cm == NULL) {
|
|
|
|
revents |= POLLERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (revents == 0) {
|
|
|
|
if (poll_events & (POLLIN | POLLRDNORM)) {
|
|
|
|
sc->mfi_poll_waiting = 1;
|
|
|
|
selrecord(td, &sc->mfi_select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return revents;
|
|
|
|
}
|
2006-09-25 11:35:34 +00:00
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
static void
|
|
|
|
mfi_dump_all(void)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc;
|
|
|
|
struct mfi_command *cm;
|
|
|
|
devclass_t dc;
|
|
|
|
time_t deadline;
|
|
|
|
int timedout;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dc = devclass_find("mfi");
|
|
|
|
if (dc == NULL) {
|
|
|
|
printf("No mfi dev class\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
sc = devclass_get_softc(dc, i);
|
|
|
|
if (sc == NULL)
|
|
|
|
break;
|
|
|
|
device_printf(sc->mfi_dev, "Dumping\n\n");
|
|
|
|
timedout = 0;
|
|
|
|
deadline = time_uptime - MFI_CMD_TIMEOUT;
|
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
TAILQ_FOREACH(cm, &sc->mfi_busy, cm_link) {
|
|
|
|
if (cm->cm_timestamp < deadline) {
|
|
|
|
device_printf(sc->mfi_dev,
|
2012-03-30 23:05:48 +00:00
|
|
|
"COMMAND %p TIMEOUT AFTER %d SECONDS\n",
|
|
|
|
cm, (int)(time_uptime - cm->cm_timestamp));
|
2006-10-16 04:18:38 +00:00
|
|
|
MFI_PRINT_CMD(cm);
|
|
|
|
timedout++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (timedout)
|
|
|
|
MFI_DUMP_CMDS(SC);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-25 11:35:34 +00:00
|
|
|
static void
|
|
|
|
mfi_timeout(void *data)
|
|
|
|
{
|
|
|
|
struct mfi_softc *sc = (struct mfi_softc *)data;
|
|
|
|
struct mfi_command *cm;
|
|
|
|
time_t deadline;
|
|
|
|
int timedout = 0;
|
|
|
|
|
|
|
|
deadline = time_uptime - MFI_CMD_TIMEOUT;
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->adpreset == 0) {
|
|
|
|
if (!mfi_tbolt_reset(sc)) {
|
2011-11-04 02:34:52 +00:00
|
|
|
callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz, mfi_timeout, sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-09-25 11:35:34 +00:00
|
|
|
mtx_lock(&sc->mfi_io_lock);
|
|
|
|
TAILQ_FOREACH(cm, &sc->mfi_busy, cm_link) {
|
2012-05-04 16:00:39 +00:00
|
|
|
if (sc->mfi_aen_cm == cm || sc->mfi_map_sync_cm == cm)
|
2006-09-27 05:00:10 +00:00
|
|
|
continue;
|
2012-05-04 16:00:39 +00:00
|
|
|
if (cm->cm_timestamp < deadline) {
|
2012-03-30 23:05:48 +00:00
|
|
|
if (sc->adpreset != 0 && sc->issuepend_done == 0) {
|
2011-11-04 02:34:52 +00:00
|
|
|
cm->cm_timestamp = time_uptime;
|
2012-03-30 23:05:48 +00:00
|
|
|
} else {
|
2011-11-04 02:34:52 +00:00
|
|
|
device_printf(sc->mfi_dev,
|
2012-03-30 23:05:48 +00:00
|
|
|
"COMMAND %p TIMEOUT AFTER %d SECONDS\n",
|
|
|
|
cm, (int)(time_uptime - cm->cm_timestamp)
|
|
|
|
);
|
2011-11-04 02:34:52 +00:00
|
|
|
MFI_PRINT_CMD(cm);
|
|
|
|
MFI_VALIDATE_CMD(sc, cm);
|
|
|
|
timedout++;
|
|
|
|
}
|
2006-09-25 11:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (timedout)
|
|
|
|
MFI_DUMP_CMDS(SC);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mtx_unlock(&sc->mfi_io_lock);
|
|
|
|
|
|
|
|
callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz,
|
|
|
|
mfi_timeout, sc);
|
|
|
|
|
2006-10-16 04:18:38 +00:00
|
|
|
if (0)
|
|
|
|
mfi_dump_all();
|
2006-09-25 11:35:34 +00:00
|
|
|
return;
|
|
|
|
}
|