1999-10-07 02:23:12 +00:00
|
|
|
/*-
|
2000-08-30 07:52:50 +00:00
|
|
|
* Copyright (c) 1999,2000 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
1999-10-07 02:23:12 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2002-10-30 22:00:11 +00:00
|
|
|
* Copyright (c) 2002 Eric Moore
|
|
|
|
* Copyright (c) 2002 LSI Logic Corporation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-10-18 21:29:14 +00:00
|
|
|
* 3. The party using or redistributing the source code and binary forms
|
2002-10-30 22:00:11 +00:00
|
|
|
* agrees to the disclaimer below and the terms and conditions set forth
|
2002-10-18 21:29:14 +00:00
|
|
|
* herein.
|
|
|
|
*
|
2002-10-30 22:00:11 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2002-10-18 21:29:14 +00:00
|
|
|
*
|
1999-10-07 02:23:12 +00:00
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Driver for the AMI MegaRaid family of controllers.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <dev/amr/amr_compat.h>
|
1999-10-07 02:23:12 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/devicestat.h>
|
|
|
|
#include <sys/disk.h>
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <sys/stat.h>
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <machine/bus_memio.h>
|
|
|
|
#include <machine/bus_pio.h>
|
1999-10-07 02:23:12 +00:00
|
|
|
#include <machine/bus.h>
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <machine/resource.h>
|
1999-10-07 02:23:12 +00:00
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
#include <dev/amr/amrio.h>
|
|
|
|
#include <dev/amr/amrreg.h>
|
|
|
|
#include <dev/amr/amrvar.h>
|
2000-08-30 07:52:50 +00:00
|
|
|
#define AMR_DEFINE_TABLES
|
|
|
|
#include <dev/amr/amr_tables.h>
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
#define AMR_CDEV_MAJOR 132
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
static d_open_t amr_open;
|
|
|
|
static d_close_t amr_close;
|
|
|
|
static d_ioctl_t amr_ioctl;
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
static struct cdevsw amr_cdevsw = {
|
|
|
|
/* open */ amr_open,
|
|
|
|
/* close */ amr_close,
|
|
|
|
/* read */ noread,
|
|
|
|
/* write */ nowrite,
|
|
|
|
/* ioctl */ amr_ioctl,
|
|
|
|
/* poll */ nopoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
/* name */ "amr",
|
|
|
|
/* maj */ AMR_CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
|
|
|
};
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* Initialisation, bus interface.
|
|
|
|
*/
|
|
|
|
static void amr_startup(void *arg);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Command wrappers
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static int amr_query_controller(struct amr_softc *sc);
|
|
|
|
static void *amr_enquiry(struct amr_softc *sc, size_t bufsize,
|
|
|
|
u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual);
|
|
|
|
static void amr_completeio(struct amr_command *ac);
|
2002-10-30 22:00:11 +00:00
|
|
|
static int amr_support_ext_cdb(struct amr_softc *sc);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Command buffer allocation.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static void amr_alloccmd_cluster(struct amr_softc *sc);
|
|
|
|
static void amr_freecmd_cluster(struct amr_command_cluster *acc);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Command processing.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static int amr_bio_command(struct amr_softc *sc, struct amr_command **acp);
|
|
|
|
static int amr_wait_command(struct amr_command *ac);
|
|
|
|
static int amr_getslot(struct amr_command *ac);
|
|
|
|
static void amr_mapcmd(struct amr_command *ac);
|
|
|
|
static void amr_unmapcmd(struct amr_command *ac);
|
|
|
|
static int amr_start(struct amr_command *ac);
|
|
|
|
static void amr_complete(void *context, int pending);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/*
|
|
|
|
* Status monitoring
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static void amr_periodic(void *data);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/*
|
|
|
|
* Interface-specific shims
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static int amr_quartz_submit_command(struct amr_softc *sc);
|
|
|
|
static int amr_quartz_get_work(struct amr_softc *sc, struct amr_mailbox *mbsave);
|
2002-12-11 20:59:46 +00:00
|
|
|
static int amr_quartz_poll_command(struct amr_command *ac);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
static int amr_std_submit_command(struct amr_softc *sc);
|
|
|
|
static int amr_std_get_work(struct amr_softc *sc, struct amr_mailbox *mbsave);
|
2002-12-11 20:59:46 +00:00
|
|
|
static int amr_std_poll_command(struct amr_command *ac);
|
2000-08-30 07:52:50 +00:00
|
|
|
static void amr_std_attach_mailbox(struct amr_softc *sc);
|
|
|
|
|
|
|
|
#ifdef AMR_BOARD_INIT
|
|
|
|
static int amr_quartz_init(struct amr_softc *sc);
|
|
|
|
static int amr_std_init(struct amr_softc *sc);
|
|
|
|
#endif
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static void amr_describe_controller(struct amr_softc *sc);
|
|
|
|
#ifdef AMR_DEBUG
|
2002-12-11 20:59:46 +00:00
|
|
|
#if 0
|
2000-08-30 07:52:50 +00:00
|
|
|
static void amr_printcommand(struct amr_command *ac);
|
|
|
|
#endif
|
2002-12-11 20:59:46 +00:00
|
|
|
#endif
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
Inline Glue
|
1999-10-07 02:23:12 +00:00
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
********************************************************************************
|
|
|
|
Public Interfaces
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Initialise the controller and softc.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
amr_attach(struct amr_softc *sc)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
debug_called(1);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise per-controller queues.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
TAILQ_INIT(&sc->amr_completed);
|
1999-10-07 02:23:12 +00:00
|
|
|
TAILQ_INIT(&sc->amr_freecmds);
|
2000-08-30 07:52:50 +00:00
|
|
|
TAILQ_INIT(&sc->amr_cmd_clusters);
|
|
|
|
TAILQ_INIT(&sc->amr_ready);
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_init(&sc->amr_bioq);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#if __FreeBSD_version >= 500005
|
|
|
|
/*
|
|
|
|
* Initialise command-completion task.
|
|
|
|
*/
|
|
|
|
TASK_INIT(&sc->amr_task_complete, 0, amr_complete, sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
debug(2, "queue init done");
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/*
|
|
|
|
* Configure for this controller type.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
if (AMR_IS_QUARTZ(sc)) {
|
1999-10-07 02:23:12 +00:00
|
|
|
sc->amr_submit_command = amr_quartz_submit_command;
|
|
|
|
sc->amr_get_work = amr_quartz_get_work;
|
2002-12-11 20:59:46 +00:00
|
|
|
sc->amr_poll_command = amr_quartz_poll_command;
|
1999-10-07 02:23:12 +00:00
|
|
|
} else {
|
|
|
|
sc->amr_submit_command = amr_std_submit_command;
|
|
|
|
sc->amr_get_work = amr_std_get_work;
|
2002-12-11 20:59:46 +00:00
|
|
|
sc->amr_poll_command = amr_std_poll_command;
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_std_attach_mailbox(sc);;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#ifdef AMR_BOARD_INIT
|
|
|
|
if ((AMR_IS_QUARTZ(sc) ? amr_quartz_init(sc) : amr_std_init(sc))))
|
|
|
|
return(ENXIO);
|
|
|
|
#endif
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Quiz controller for features and limits.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
if (amr_query_controller(sc))
|
|
|
|
return(ENXIO);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug(2, "controller query complete");
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Attach our 'real' SCSI channels to CAM.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
if (amr_cam_attach(sc))
|
1999-10-07 02:23:12 +00:00
|
|
|
return(ENXIO);
|
2000-08-30 07:52:50 +00:00
|
|
|
debug(2, "CAM attach done");
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Create the control device.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
sc->amr_dev_t = make_dev(&amr_cdevsw, device_get_unit(sc->amr_dev), UID_ROOT, GID_OPERATOR,
|
|
|
|
S_IRUSR | S_IWUSR, "amr%d", device_get_unit(sc->amr_dev));
|
|
|
|
sc->amr_dev_t->si_drv1 = sc;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Schedule ourselves to bring the controller up once interrupts are
|
|
|
|
* available.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
bzero(&sc->amr_ich, sizeof(struct intr_config_hook));
|
|
|
|
sc->amr_ich.ich_func = amr_startup;
|
|
|
|
sc->amr_ich.ich_arg = sc;
|
|
|
|
if (config_intrhook_establish(&sc->amr_ich) != 0) {
|
|
|
|
device_printf(sc->amr_dev, "can't establish configuration hook\n");
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Print a little information about the controller.
|
2000-04-01 00:35:15 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_describe_controller(sc);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug(2, "attach complete");
|
1999-10-07 02:23:12 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Locate disk resources and attach children to them.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static void
|
|
|
|
amr_startup(void *arg)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_softc *sc = (struct amr_softc *)arg;
|
1999-10-07 02:23:12 +00:00
|
|
|
struct amr_logdrive *dr;
|
|
|
|
int i, error;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(1);
|
|
|
|
|
|
|
|
/* pull ourselves off the intrhook chain */
|
|
|
|
config_intrhook_disestablish(&sc->amr_ich);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* get up-to-date drive information */
|
|
|
|
if (amr_query_controller(sc)) {
|
2000-08-30 07:52:50 +00:00
|
|
|
device_printf(sc->amr_dev, "can't scan controller for drives\n");
|
1999-10-07 02:23:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over available drives */
|
|
|
|
for (i = 0, dr = &sc->amr_drive[0]; (i < AMR_MAXLD) && (dr->al_size != 0xffffffff); i++, dr++) {
|
|
|
|
/* are we already attached to this drive? */
|
|
|
|
if (dr->al_disk == 0) {
|
|
|
|
/* generate geometry information */
|
|
|
|
if (dr->al_size > 0x200000) { /* extended translation? */
|
|
|
|
dr->al_heads = 255;
|
|
|
|
dr->al_sectors = 63;
|
|
|
|
} else {
|
|
|
|
dr->al_heads = 64;
|
|
|
|
dr->al_sectors = 32;
|
|
|
|
}
|
|
|
|
dr->al_cylinders = dr->al_size / (dr->al_heads * dr->al_sectors);
|
|
|
|
|
1999-12-03 08:41:24 +00:00
|
|
|
dr->al_disk = device_add_child(sc->amr_dev, NULL, -1);
|
1999-10-07 02:23:12 +00:00
|
|
|
if (dr->al_disk == 0)
|
|
|
|
device_printf(sc->amr_dev, "device_add_child failed\n");
|
1999-12-03 08:41:24 +00:00
|
|
|
device_set_ivars(dr->al_disk, dr);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_generic_attach(sc->amr_dev)) != 0)
|
|
|
|
device_printf(sc->amr_dev, "bus_generic_attach returned %d\n", error);
|
|
|
|
|
|
|
|
/* mark controller back up */
|
|
|
|
sc->amr_state &= ~AMR_STATE_SHUTDOWN;
|
|
|
|
|
|
|
|
/* interrupts will be enabled before we do anything more */
|
|
|
|
sc->amr_state |= AMR_STATE_INTEN;
|
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Start the timeout routine.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
/* sc->amr_timeout = timeout(amr_periodic, sc, hz);*/
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
return;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Free resources associated with a controller instance
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
void
|
|
|
|
amr_free(struct amr_softc *sc)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_command_cluster *acc;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* detach from CAM */
|
2002-12-11 20:59:46 +00:00
|
|
|
amr_cam_detach(sc);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* cancel status timeout */
|
|
|
|
untimeout(amr_periodic, sc, sc->amr_timeout);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* throw away any command buffers */
|
|
|
|
while ((acc = TAILQ_FIRST(&sc->amr_cmd_clusters)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&sc->amr_cmd_clusters, acc, acc_link);
|
|
|
|
amr_freecmd_cluster(acc);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2002-12-11 20:59:46 +00:00
|
|
|
|
|
|
|
/* destroy control device */
|
|
|
|
if( sc->amr_dev_t != (dev_t)NULL)
|
|
|
|
destroy_dev(sc->amr_dev_t);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Receive a bio structure from a child device and queue it on a particular
|
1999-10-07 02:23:12 +00:00
|
|
|
* disk resource, then poke the disk resource to start as much work as it can.
|
|
|
|
*/
|
|
|
|
int
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_submit_bio(struct amr_softc *sc, struct bio *bio)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(2);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_enqueue_bio(sc, bio);
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_startio(sc);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Accept an open operation on the control device.
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static int
|
2002-10-18 21:29:14 +00:00
|
|
|
amr_open(dev_t dev, int flags, int fmt, d_thread_t *td)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
2002-01-08 06:47:02 +00:00
|
|
|
struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(1);
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
sc->amr_state |= AMR_STATE_OPEN;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Accept the last close on the control device.
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static int
|
2002-10-18 21:29:14 +00:00
|
|
|
amr_close(dev_t dev, int flags, int fmt, d_thread_t *td)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
2002-01-08 06:47:02 +00:00
|
|
|
struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(1);
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
sc->amr_state &= ~AMR_STATE_OPEN;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Handle controller-specific control operations.
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static int
|
2002-10-18 21:29:14 +00:00
|
|
|
amr_ioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, d_thread_t *td)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_softc *sc = (struct amr_softc *)dev->si_drv1;
|
|
|
|
int *arg = (int *)addr;
|
|
|
|
struct amr_user_ioctl *au = (struct amr_user_ioctl *)addr;
|
|
|
|
struct amr_command *ac;
|
|
|
|
struct amr_mailbox_ioctl *mbi;
|
|
|
|
struct amr_passthrough *ap;
|
|
|
|
void *dp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
debug_called(1);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
dp = NULL;
|
|
|
|
ap = NULL;
|
|
|
|
ac = NULL;
|
1999-10-07 02:23:12 +00:00
|
|
|
switch(cmd) {
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
case AMR_IO_VERSION:
|
|
|
|
debug(1, "AMR_IO_VERSION");
|
|
|
|
*arg = AMR_IO_VERSION_NUMBER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMR_IO_COMMAND:
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(1, "AMR_IO_COMMAND 0x%x", au->au_cmd[0]);
|
2000-08-30 07:52:50 +00:00
|
|
|
/* handle inbound data buffer */
|
|
|
|
if (au->au_length != 0) {
|
2003-02-19 05:47:46 +00:00
|
|
|
if ((dp = malloc(au->au_length, M_DEVBUF, M_WAITOK)) == NULL) {
|
2000-08-30 07:52:50 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((error = copyin(au->au_buffer, dp, au->au_length)) != 0)
|
|
|
|
break;
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(2, "copyin %ld bytes from %p -> %p", au->au_length, au->au_buffer, dp);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle SCSI passthrough command */
|
|
|
|
if (au->au_cmd[0] == AMR_CMD_PASS) {
|
2003-02-19 05:47:46 +00:00
|
|
|
if ((ap = malloc(sizeof(*ap), M_DEVBUF, M_WAITOK | M_ZERO)) == NULL) {
|
2000-08-30 07:52:50 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy cdb */
|
|
|
|
ap->ap_cdb_length = au->au_cmd[2];
|
|
|
|
bcopy(&au->au_cmd[3], &ap->ap_cdb[0], ap->ap_cdb_length);
|
|
|
|
|
|
|
|
/* build passthrough */
|
|
|
|
ap->ap_timeout = au->au_cmd[ap->ap_cdb_length + 3] & 0x07;
|
|
|
|
ap->ap_ars = (au->au_cmd[ap->ap_cdb_length + 3] & 0x08) ? 1 : 0;
|
|
|
|
ap->ap_islogical = (au->au_cmd[ap->ap_cdb_length + 3] & 0x80) ? 1 : 0;
|
|
|
|
ap->ap_logical_drive_no = au->au_cmd[ap->ap_cdb_length + 4];
|
|
|
|
ap->ap_channel = au->au_cmd[ap->ap_cdb_length + 5];
|
|
|
|
ap->ap_scsi_id = au->au_cmd[ap->ap_cdb_length + 6];
|
|
|
|
ap->ap_request_sense_length = 14;
|
2002-10-18 21:29:14 +00:00
|
|
|
ap->ap_data_transfer_length = au->au_length;
|
2000-08-30 07:52:50 +00:00
|
|
|
/* XXX what about the request-sense area? does the caller want it? */
|
|
|
|
|
|
|
|
/* build command */
|
|
|
|
ac->ac_data = ap;
|
|
|
|
ac->ac_length = sizeof(*ap);
|
|
|
|
ac->ac_flags |= AMR_CMD_DATAOUT;
|
|
|
|
ac->ac_ccb_data = dp;
|
|
|
|
ac->ac_ccb_length = au->au_length;
|
|
|
|
if (au->au_direction & AMR_IO_READ)
|
|
|
|
ac->ac_flags |= AMR_CMD_CCB_DATAIN;
|
|
|
|
if (au->au_direction & AMR_IO_WRITE)
|
|
|
|
ac->ac_flags |= AMR_CMD_CCB_DATAOUT;
|
|
|
|
|
|
|
|
ac->ac_mailbox.mb_command = AMR_CMD_PASS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* direct command to controller */
|
|
|
|
mbi = (struct amr_mailbox_ioctl *)&ac->ac_mailbox;
|
|
|
|
|
|
|
|
/* copy pertinent mailbox items */
|
|
|
|
mbi->mb_command = au->au_cmd[0];
|
|
|
|
mbi->mb_channel = au->au_cmd[1];
|
|
|
|
mbi->mb_param = au->au_cmd[2];
|
|
|
|
mbi->mb_pad[0] = au->au_cmd[3];
|
|
|
|
mbi->mb_drive = au->au_cmd[4];
|
|
|
|
|
|
|
|
/* build the command */
|
|
|
|
ac->ac_data = dp;
|
|
|
|
ac->ac_length = au->au_length;
|
|
|
|
if (au->au_direction & AMR_IO_READ)
|
|
|
|
ac->ac_flags |= AMR_CMD_DATAIN;
|
|
|
|
if (au->au_direction & AMR_IO_WRITE)
|
|
|
|
ac->ac_flags |= AMR_CMD_DATAOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run the command */
|
|
|
|
if ((error = amr_wait_command(ac)) != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* copy out data and set status */
|
|
|
|
if (au->au_length != 0)
|
|
|
|
error = copyout(dp, au->au_buffer, au->au_length);
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(2, "copyout %ld bytes from %p -> %p", au->au_length, dp, au->au_buffer);
|
|
|
|
if (dp != NULL)
|
2002-12-11 20:59:46 +00:00
|
|
|
debug(2, "%16d", (int)dp);
|
2000-08-30 07:52:50 +00:00
|
|
|
au->au_status = ac->ac_status;
|
|
|
|
break;
|
2002-10-18 21:29:14 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
default:
|
|
|
|
debug(1, "unknown ioctl 0x%lx", cmd);
|
|
|
|
error = ENOIOCTL;
|
|
|
|
break;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
if (dp != NULL)
|
|
|
|
free(dp, M_DEVBUF);
|
|
|
|
if (ap != NULL)
|
|
|
|
free(ap, M_DEVBUF);
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
return(error);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Status Monitoring
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Perform a periodic check of the controller status
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_periodic(void *data)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = (struct amr_softc *)data;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(2);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* XXX perform periodic status checks here */
|
|
|
|
|
|
|
|
/* compensate for missed interrupts */
|
|
|
|
amr_done(sc);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
|
|
|
/* reschedule */
|
|
|
|
sc->amr_timeout = timeout(amr_periodic, sc, hz);
|
|
|
|
}
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Command Wrappers
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Interrogate the controller for the operational parameters we require.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_query_controller(struct amr_softc *sc)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_enquiry3 *aex;
|
|
|
|
struct amr_prodinfo *ap;
|
|
|
|
struct amr_enquiry *ae;
|
|
|
|
int ldrv;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* If we haven't found the real limit yet, let us have a couple of commands in
|
|
|
|
* order to be able to probe.
|
|
|
|
*/
|
|
|
|
if (sc->amr_maxio == 0)
|
|
|
|
sc->amr_maxio = 2;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2002-10-30 22:00:11 +00:00
|
|
|
/*
|
|
|
|
* Greater than 10 byte cdb support
|
|
|
|
*/
|
|
|
|
sc->support_ext_cdb = amr_support_ext_cdb(sc);
|
|
|
|
|
|
|
|
if(sc->support_ext_cdb) {
|
|
|
|
debug(2,"supports extended CDBs.");
|
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* Try to issue an ENQUIRY3 command
|
|
|
|
*/
|
|
|
|
if ((aex = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_ENQ3,
|
|
|
|
AMR_CONFIG_ENQ3_SOLICITED_FULL)) != NULL) {
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* Fetch current state of logical drives.
|
|
|
|
*/
|
|
|
|
for (ldrv = 0; ldrv < aex->ae_numldrives; ldrv++) {
|
|
|
|
sc->amr_drive[ldrv].al_size = aex->ae_drivesize[ldrv];
|
|
|
|
sc->amr_drive[ldrv].al_state = aex->ae_drivestate[ldrv];
|
|
|
|
sc->amr_drive[ldrv].al_properties = aex->ae_driveprop[ldrv];
|
|
|
|
debug(2, " drive %d: %d state %x properties %x\n", ldrv, sc->amr_drive[ldrv].al_size,
|
|
|
|
sc->amr_drive[ldrv].al_state, sc->amr_drive[ldrv].al_properties);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
free(aex, M_DEVBUF);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* Get product info for channel count.
|
2000-04-01 00:35:15 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
if ((ap = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_PRODUCT_INFO, 0)) == NULL) {
|
|
|
|
device_printf(sc->amr_dev, "can't obtain product data from controller\n");
|
|
|
|
return(1);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
sc->amr_maxdrives = 40;
|
|
|
|
sc->amr_maxchan = ap->ap_nschan;
|
|
|
|
sc->amr_maxio = ap->ap_maxio;
|
|
|
|
sc->amr_type |= AMR_TYPE_40LD;
|
|
|
|
free(ap, M_DEVBUF);
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
} else {
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
/* failed, try the 8LD ENQUIRY commands */
|
|
|
|
if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_EXT_ENQUIRY2, 0, 0)) == NULL) {
|
|
|
|
if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_ENQUIRY, 0, 0)) == NULL) {
|
|
|
|
device_printf(sc->amr_dev, "can't obtain configuration data from controller\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
ae->ae_signature = 0;
|
|
|
|
}
|
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Fetch current state of logical drives.
|
2000-04-01 00:35:15 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
for (ldrv = 0; ldrv < ae->ae_ldrv.al_numdrives; ldrv++) {
|
|
|
|
sc->amr_drive[ldrv].al_size = ae->ae_ldrv.al_size[ldrv];
|
|
|
|
sc->amr_drive[ldrv].al_state = ae->ae_ldrv.al_state[ldrv];
|
|
|
|
sc->amr_drive[ldrv].al_properties = ae->ae_ldrv.al_properties[ldrv];
|
|
|
|
debug(2, " drive %d: %d state %x properties %x\n", ldrv, sc->amr_drive[ldrv].al_size,
|
|
|
|
sc->amr_drive[ldrv].al_state, sc->amr_drive[ldrv].al_properties);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
sc->amr_maxdrives = 8;
|
|
|
|
sc->amr_maxchan = ae->ae_adapter.aa_channels;
|
|
|
|
sc->amr_maxio = ae->ae_adapter.aa_maxio;
|
|
|
|
free(ae, M_DEVBUF);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark remaining drives as unused.
|
|
|
|
*/
|
|
|
|
for (; ldrv < AMR_MAXLD; ldrv++)
|
|
|
|
sc->amr_drive[ldrv].al_size = 0xffffffff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cap the maximum number of outstanding I/Os. AMI's Linux driver doesn't trust
|
|
|
|
* the controller's reported value, and lockups have been seen when we do.
|
|
|
|
*/
|
|
|
|
sc->amr_maxio = imin(sc->amr_maxio, AMR_LIMITCMD);
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Run a generic enquiry-style command.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
amr_enquiry(struct amr_softc *sc, size_t bufsize, u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
void *result;
|
|
|
|
u_int8_t *mbox;
|
|
|
|
int error;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(1);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
error = 1;
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
/* get ourselves a command buffer */
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL)
|
|
|
|
goto out;
|
|
|
|
/* allocate the response structure */
|
|
|
|
if ((result = malloc(bufsize, M_DEVBUF, M_NOWAIT)) == NULL)
|
|
|
|
goto out;
|
2000-08-30 07:52:50 +00:00
|
|
|
/* set command flags */
|
1999-10-07 02:23:12 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* point the command at our data */
|
1999-10-07 02:23:12 +00:00
|
|
|
ac->ac_data = result;
|
|
|
|
ac->ac_length = bufsize;
|
|
|
|
|
|
|
|
/* build the command proper */
|
|
|
|
mbox = (u_int8_t *)&ac->ac_mailbox; /* XXX want a real structure for this? */
|
|
|
|
mbox[0] = cmd;
|
|
|
|
mbox[2] = cmdsub;
|
|
|
|
mbox[3] = cmdqual;
|
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/* can't assume that interrupts are going to work here, so play it safe */
|
2002-12-11 20:59:46 +00:00
|
|
|
if (sc->amr_poll_command(ac))
|
1999-10-07 02:23:12 +00:00
|
|
|
goto out;
|
|
|
|
error = ac->ac_status;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
if ((error != 0) && (result != NULL)) {
|
|
|
|
free(result, M_DEVBUF);
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Flush the controller's internal cache, return status.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
int
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_flush(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* get ourselves a command buffer */
|
|
|
|
error = 1;
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL)
|
|
|
|
goto out;
|
2000-08-30 07:52:50 +00:00
|
|
|
/* set command flags */
|
1999-10-07 02:23:12 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
|
|
|
|
|
|
|
|
/* build the command proper */
|
|
|
|
ac->ac_mailbox.mb_command = AMR_CMD_FLUSH;
|
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/* we have to poll, as the system may be going down or otherwise damaged */
|
2002-12-11 20:59:46 +00:00
|
|
|
if (sc->amr_poll_command(ac))
|
1999-10-07 02:23:12 +00:00
|
|
|
goto out;
|
|
|
|
error = ac->ac_status;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2002-10-30 22:00:11 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Detect extented cdb >> greater than 10 byte cdb support
|
|
|
|
* returns '1' means this support exist
|
|
|
|
* returns '0' means this support doesn't exist
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_support_ext_cdb(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
u_int8_t *mbox;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* get ourselves a command buffer */
|
|
|
|
error = 0;
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL)
|
|
|
|
goto out;
|
|
|
|
/* set command flags */
|
|
|
|
ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
|
|
|
|
|
|
|
|
/* build the command proper */
|
|
|
|
mbox = (u_int8_t *)&ac->ac_mailbox; /* XXX want a real structure for this? */
|
|
|
|
mbox[0] = 0xA4;
|
|
|
|
mbox[2] = 0x16;
|
|
|
|
|
|
|
|
|
|
|
|
/* we have to poll, as the system may be going down or otherwise damaged */
|
2002-12-11 20:59:46 +00:00
|
|
|
if (sc->amr_poll_command(ac))
|
2002-10-30 22:00:11 +00:00
|
|
|
goto out;
|
|
|
|
if( ac->ac_status == AMR_STATUS_SUCCESS ) {
|
|
|
|
error = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Try to find I/O work for the controller from one or more of the work queues.
|
1999-10-07 02:23:12 +00:00
|
|
|
*
|
2000-08-30 07:52:50 +00:00
|
|
|
* We make the assumption that if the controller is not ready to take a command
|
|
|
|
* at some given time, it will generate an interrupt at some later time when
|
|
|
|
* it is.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
void
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_startio(struct amr_softc *sc)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_command *ac;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* spin until something prevents us from doing any work */
|
|
|
|
for (;;) {
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* try to get a ready command */
|
|
|
|
ac = amr_dequeue_ready(sc);
|
|
|
|
|
|
|
|
/* if that failed, build a command from a bio */
|
|
|
|
if (ac == NULL)
|
|
|
|
(void)amr_bio_command(sc, &ac);
|
|
|
|
|
|
|
|
/* if that failed, build a command from a ccb */
|
|
|
|
if (ac == NULL)
|
|
|
|
(void)amr_cam_command(sc, &ac);
|
2002-10-18 21:29:14 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* if we don't have anything to do, give up */
|
|
|
|
if (ac == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* try to give the command to the controller; if this fails save it for later and give up */
|
|
|
|
if (amr_start(ac)) {
|
|
|
|
debug(2, "controller busy, command deferred");
|
|
|
|
amr_requeue_ready(ac); /* XXX schedule retry very soon? */
|
|
|
|
break;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Handle completion of an I/O command.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_completeio(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
|
|
|
|
if (ac->ac_status != AMR_STATUS_SUCCESS) { /* could be more verbose here? */
|
2000-08-30 07:52:50 +00:00
|
|
|
ac->ac_bio->bio_error = EIO;
|
|
|
|
ac->ac_bio->bio_flags |= BIO_ERROR;
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
device_printf(sc->amr_dev, "I/O error - 0x%x\n", ac->ac_status);
|
|
|
|
/* amr_printcommand(ac);*/
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
amrd_intr(ac->ac_bio);
|
|
|
|
amr_releasecmd(ac);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Command Processing
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Convert a bio off the top of the bio queue into a command.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_bio_command(struct amr_softc *sc, struct amr_command **acp)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
struct amrd_softc *amrd;
|
|
|
|
struct bio *bio;
|
|
|
|
int error;
|
|
|
|
int blkcount;
|
|
|
|
int driveno;
|
|
|
|
int cmd;
|
|
|
|
|
|
|
|
ac = NULL;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
/* get a bio to work on */
|
|
|
|
if ((bio = amr_dequeue_bio(sc)) == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* get a command */
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect the bio to the command */
|
|
|
|
ac->ac_complete = amr_completeio;
|
|
|
|
ac->ac_bio = bio;
|
|
|
|
ac->ac_data = bio->bio_data;
|
|
|
|
ac->ac_length = bio->bio_bcount;
|
|
|
|
if (BIO_IS_READ(bio)) {
|
|
|
|
ac->ac_flags |= AMR_CMD_DATAIN;
|
|
|
|
cmd = AMR_CMD_LREAD;
|
|
|
|
} else {
|
|
|
|
ac->ac_flags |= AMR_CMD_DATAOUT;
|
|
|
|
cmd = AMR_CMD_LWRITE;
|
|
|
|
}
|
2003-02-24 21:49:27 +00:00
|
|
|
amrd = (struct amrd_softc *)bio->bio_disk->d_drv1;
|
2000-08-30 07:52:50 +00:00
|
|
|
driveno = amrd->amrd_drive - sc->amr_drive;
|
|
|
|
blkcount = (bio->bio_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE;
|
|
|
|
|
|
|
|
ac->ac_mailbox.mb_command = cmd;
|
|
|
|
ac->ac_mailbox.mb_blkcount = blkcount;
|
|
|
|
ac->ac_mailbox.mb_lba = bio->bio_pblkno;
|
|
|
|
ac->ac_mailbox.mb_drive = driveno;
|
|
|
|
/* we fill in the s/g related data when the command is mapped */
|
|
|
|
|
|
|
|
if ((bio->bio_pblkno + blkcount) > sc->amr_drive[driveno].al_size)
|
2002-03-18 23:24:00 +00:00
|
|
|
device_printf(sc->amr_dev, "I/O beyond end of unit (%lld,%d > %lu)\n",
|
|
|
|
(long long)bio->bio_pblkno, blkcount,
|
|
|
|
(u_long)sc->amr_drive[driveno].al_size);
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (error != 0) {
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
if (bio != NULL) /* this breaks ordering... */
|
|
|
|
amr_enqueue_bio(sc, bio);
|
|
|
|
}
|
|
|
|
*acp = ac;
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Take a command, submit it to the controller and sleep until it completes
|
|
|
|
* or fails. Interrupts must be enabled, returns nonzero on error.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_wait_command(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
int error, count;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(1);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
ac->ac_complete = NULL;
|
2000-08-30 07:52:50 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_SLEEP;
|
1999-10-07 02:23:12 +00:00
|
|
|
if ((error = amr_start(ac)) != 0)
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
/* XXX better timeout? */
|
2000-08-30 07:52:50 +00:00
|
|
|
while ((ac->ac_flags & AMR_CMD_BUSY) && (count < 30)) {
|
|
|
|
tsleep(ac, PRIBIO | PCATCH, "amrwcmd", hz);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Take a command, submit it to the controller and busy-wait for it to return.
|
|
|
|
* Returns nonzero on error. Can be safely called with interrupts enabled.
|
|
|
|
*/
|
|
|
|
static int
|
2002-12-11 20:59:46 +00:00
|
|
|
amr_std_poll_command(struct amr_command *ac)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
2000-08-30 07:52:50 +00:00
|
|
|
int error, count;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(2);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
ac->ac_complete = NULL;
|
|
|
|
if ((error = amr_start(ac)) != 0)
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Poll for completion, although the interrupt handler may beat us to it.
|
|
|
|
* Note that the timeout here is somewhat arbitrary.
|
|
|
|
*/
|
|
|
|
amr_done(sc);
|
2000-08-30 07:52:50 +00:00
|
|
|
DELAY(1000);
|
|
|
|
} while ((ac->ac_flags & AMR_CMD_BUSY) && (count++ < 1000));
|
|
|
|
if (!(ac->ac_flags & AMR_CMD_BUSY)) {
|
1999-10-07 02:23:12 +00:00
|
|
|
error = 0;
|
|
|
|
} else {
|
2000-08-30 07:52:50 +00:00
|
|
|
/* XXX the slot is now marked permanently busy */
|
1999-10-07 02:23:12 +00:00
|
|
|
error = EIO;
|
2000-08-30 07:52:50 +00:00
|
|
|
device_printf(sc->amr_dev, "polled command timeout\n");
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2002-12-11 20:59:46 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Take a command, submit it to the controller and busy-wait for it to return.
|
|
|
|
* Returns nonzero on error. Can be safely called with interrupts enabled.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_quartz_poll_command(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
int s;
|
2003-01-09 21:02:28 +00:00
|
|
|
int error,count;
|
2002-12-11 20:59:46 +00:00
|
|
|
|
|
|
|
debug_called(2);
|
|
|
|
|
|
|
|
/* now we have a slot, we can map the command (unmapped in amr_complete) */
|
|
|
|
amr_mapcmd(ac);
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
2003-01-09 21:02:28 +00:00
|
|
|
count=0;
|
|
|
|
while (sc->amr_busyslots){
|
|
|
|
tsleep(sc, PRIBIO | PCATCH, "amrpoll", hz);
|
|
|
|
if(count++>10) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-11 20:59:46 +00:00
|
|
|
if(sc->amr_busyslots) {
|
2003-01-09 21:02:28 +00:00
|
|
|
device_printf(sc->amr_dev, "adapter is busy\n");
|
2002-12-11 20:59:46 +00:00
|
|
|
splx(s);
|
|
|
|
amr_unmapcmd(ac);
|
|
|
|
ac->ac_status=0;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(&ac->ac_mailbox, (void *)(uintptr_t)(volatile void *)sc->amr_mailbox, AMR_MBOX_CMDSIZE);
|
|
|
|
|
|
|
|
/* clear the poll/ack fields in the mailbox */
|
|
|
|
sc->amr_mailbox->mb_ident = 0xFE;
|
|
|
|
sc->amr_mailbox->mb_nstatus = 0xFF;
|
|
|
|
sc->amr_mailbox->mb_status = 0xFF;
|
|
|
|
sc->amr_mailbox->mb_poll = 0;
|
|
|
|
sc->amr_mailbox->mb_ack = 0;
|
2003-01-09 21:02:28 +00:00
|
|
|
sc->amr_mailbox->mb_busy = 1;
|
2002-12-11 20:59:46 +00:00
|
|
|
|
|
|
|
AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_SUBMIT);
|
|
|
|
|
|
|
|
while(sc->amr_mailbox->mb_nstatus == 0xFF);
|
|
|
|
while(sc->amr_mailbox->mb_status == 0xFF);
|
2002-12-13 17:27:44 +00:00
|
|
|
ac->ac_status=sc->amr_mailbox->mb_status;
|
|
|
|
error = (ac->ac_status !=AMR_STATUS_SUCCESS) ? 1:0;
|
2002-12-11 20:59:46 +00:00
|
|
|
while(sc->amr_mailbox->mb_poll != 0x77);
|
|
|
|
sc->amr_mailbox->mb_poll = 0;
|
|
|
|
sc->amr_mailbox->mb_ack = 0x77;
|
|
|
|
|
|
|
|
/* acknowledge that we have the commands */
|
|
|
|
AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_ACK);
|
2003-01-09 21:02:28 +00:00
|
|
|
while(AMR_QGET_IDB(sc) & AMR_QIDB_ACK);
|
2002-12-11 20:59:46 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* unmap the command's data buffer */
|
|
|
|
amr_unmapcmd(ac);
|
|
|
|
|
2002-12-13 17:27:44 +00:00
|
|
|
return(error);
|
2002-12-11 20:59:46 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Get a free command slot for a command if it doesn't already have one.
|
|
|
|
*
|
|
|
|
* May be safely called multiple times for a given command.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_getslot(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
2000-08-30 07:52:50 +00:00
|
|
|
int s, slot, limit, error;
|
|
|
|
|
|
|
|
debug_called(3);
|
|
|
|
|
|
|
|
/* if the command already has a slot, don't try to give it another one */
|
|
|
|
if (ac->ac_slot != 0)
|
|
|
|
return(0);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* enforce slot usage limit */
|
|
|
|
limit = (ac->ac_flags & AMR_CMD_PRIORITY) ? sc->amr_maxio : sc->amr_maxio - 4;
|
2000-08-30 07:52:50 +00:00
|
|
|
if (sc->amr_busyslots > limit)
|
1999-10-07 02:23:12 +00:00
|
|
|
return(EBUSY);
|
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Allocate a slot. XXX linear scan is slow
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
error = EBUSY;
|
1999-10-07 02:23:12 +00:00
|
|
|
s = splbio();
|
|
|
|
for (slot = 0; slot < sc->amr_maxio; slot++) {
|
2000-08-30 07:52:50 +00:00
|
|
|
if (sc->amr_busycmd[slot] == NULL) {
|
|
|
|
sc->amr_busycmd[slot] = ac;
|
|
|
|
sc->amr_busyslots++;
|
|
|
|
ac->ac_slot = slot;
|
|
|
|
error = 0;
|
1999-10-07 02:23:12 +00:00
|
|
|
break;
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
return(error);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Map/unmap (ac)'s data in the controller's addressable space as required.
|
|
|
|
*
|
|
|
|
* These functions may be safely called multiple times on a given command.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_setup_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error)
|
|
|
|
{
|
|
|
|
struct amr_command *ac = (struct amr_command *)arg;
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
struct amr_sgentry *sg;
|
|
|
|
int i;
|
2000-11-28 19:28:22 +00:00
|
|
|
u_int8_t *sgc;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* get base address of s/g table */
|
|
|
|
sg = sc->amr_sgtable + (ac->ac_slot * AMR_NSEG);
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* save data physical address */
|
1999-10-07 02:23:12 +00:00
|
|
|
ac->ac_dataphys = segs[0].ds_addr;
|
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
/* for AMR_CMD_CONFIG the s/g count goes elsewhere */
|
|
|
|
if (ac->ac_mailbox.mb_command == AMR_CMD_CONFIG) {
|
|
|
|
sgc = &(((struct amr_mailbox_ioctl *)&ac->ac_mailbox)->mb_param);
|
|
|
|
} else {
|
|
|
|
sgc = &ac->ac_mailbox.mb_nsgelem;
|
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* decide whether we need to populate the s/g table */
|
|
|
|
if (nsegments < 2) {
|
2000-11-28 19:28:22 +00:00
|
|
|
*sgc = 0;
|
2002-10-18 21:29:14 +00:00
|
|
|
ac->ac_mailbox.mb_nsgelem = 0;
|
2000-08-30 07:52:50 +00:00
|
|
|
ac->ac_mailbox.mb_physaddr = ac->ac_dataphys;
|
|
|
|
} else {
|
2002-10-18 21:29:14 +00:00
|
|
|
ac->ac_mailbox.mb_nsgelem = nsegments;
|
2000-11-28 19:28:22 +00:00
|
|
|
*sgc = nsegments;
|
2000-08-30 07:52:50 +00:00
|
|
|
ac->ac_mailbox.mb_physaddr = sc->amr_sgbusaddr + (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
|
|
|
|
for (i = 0; i < nsegments; i++, sg++) {
|
|
|
|
sg->sg_addr = segs[i].ds_addr;
|
|
|
|
sg->sg_count = segs[i].ds_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
amr_setup_ccbmap(void *arg, bus_dma_segment_t *segs, int nsegments, int error)
|
|
|
|
{
|
2002-10-18 21:29:14 +00:00
|
|
|
struct amr_command *ac = (struct amr_command *)arg;
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
struct amr_sgentry *sg;
|
|
|
|
struct amr_passthrough *ap = (struct amr_passthrough *)ac->ac_data;
|
2002-10-31 14:10:00 +00:00
|
|
|
struct amr_ext_passthrough *aep = (struct amr_ext_passthrough *)ac->ac_data;
|
2002-10-18 21:29:14 +00:00
|
|
|
int i;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
/* get base address of s/g table */
|
|
|
|
sg = sc->amr_sgtable + (ac->ac_slot * AMR_NSEG);
|
|
|
|
|
2002-10-18 21:29:14 +00:00
|
|
|
/* decide whether we need to populate the s/g table */
|
2002-10-30 22:00:11 +00:00
|
|
|
if( ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS ) {
|
|
|
|
if (nsegments < 2) {
|
|
|
|
aep->ap_no_sg_elements = 0;
|
|
|
|
aep->ap_data_transfer_address = segs[0].ds_addr;
|
|
|
|
} else {
|
|
|
|
/* save s/g table information in passthrough */
|
|
|
|
aep->ap_no_sg_elements = nsegments;
|
|
|
|
aep->ap_data_transfer_address = sc->amr_sgbusaddr + (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
|
|
|
|
/* populate s/g table (overwrites previous call which mapped the passthrough) */
|
|
|
|
for (i = 0; i < nsegments; i++, sg++) {
|
|
|
|
sg->sg_addr = segs[i].ds_addr;
|
|
|
|
sg->sg_count = segs[i].ds_len;
|
|
|
|
debug(3, " %d: 0x%x/%d", i, sg->sg_addr, sg->sg_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug(3, "slot %d %d segments at 0x%x, passthrough at 0x%x", ac->ac_slot,
|
|
|
|
aep->ap_no_sg_elements, aep->ap_data_transfer_address, ac->ac_dataphys);
|
2002-10-18 21:29:14 +00:00
|
|
|
} else {
|
2002-10-30 22:00:11 +00:00
|
|
|
if (nsegments < 2) {
|
|
|
|
ap->ap_no_sg_elements = 0;
|
|
|
|
ap->ap_data_transfer_address = segs[0].ds_addr;
|
|
|
|
} else {
|
|
|
|
/* save s/g table information in passthrough */
|
|
|
|
ap->ap_no_sg_elements = nsegments;
|
|
|
|
ap->ap_data_transfer_address = sc->amr_sgbusaddr + (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
|
|
|
|
/* populate s/g table (overwrites previous call which mapped the passthrough) */
|
|
|
|
for (i = 0; i < nsegments; i++, sg++) {
|
2002-10-18 21:29:14 +00:00
|
|
|
sg->sg_addr = segs[i].ds_addr;
|
|
|
|
sg->sg_count = segs[i].ds_len;
|
|
|
|
debug(3, " %d: 0x%x/%d", i, sg->sg_addr, sg->sg_count);
|
2002-10-30 22:00:11 +00:00
|
|
|
}
|
2002-10-18 21:29:14 +00:00
|
|
|
}
|
2002-10-30 22:00:11 +00:00
|
|
|
debug(3, "slot %d %d segments at 0x%x, passthrough at 0x%x", ac->ac_slot,
|
|
|
|
ap->ap_no_sg_elements, ap->ap_data_transfer_address, ac->ac_dataphys);
|
2002-10-18 21:29:14 +00:00
|
|
|
}
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
amr_mapcmd(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* if the command involves data at all, and hasn't been mapped */
|
|
|
|
if (!(ac->ac_flags & AMR_CMD_MAPPED)) {
|
|
|
|
|
|
|
|
if (ac->ac_data != NULL) {
|
|
|
|
/* map the data buffers into bus space and build the s/g list */
|
2002-10-18 21:29:14 +00:00
|
|
|
bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_dmamap, ac->ac_data, ac->ac_length,
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_setup_dmamap, ac, 0);
|
|
|
|
if (ac->ac_flags & AMR_CMD_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap, BUS_DMASYNC_PREREAD);
|
|
|
|
if (ac->ac_flags & AMR_CMD_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap, BUS_DMASYNC_PREWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ac->ac_ccb_data != NULL) {
|
2002-10-18 21:29:14 +00:00
|
|
|
bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_ccb_dmamap, ac->ac_ccb_data, ac->ac_ccb_length,
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_setup_ccbmap, ac, 0);
|
|
|
|
if (ac->ac_flags & AMR_CMD_CCB_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap, BUS_DMASYNC_PREREAD);
|
|
|
|
if (ac->ac_flags & AMR_CMD_CCB_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap, BUS_DMASYNC_PREWRITE);
|
|
|
|
}
|
|
|
|
ac->ac_flags |= AMR_CMD_MAPPED;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
amr_unmapcmd(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* if the command involved data at all and was mapped */
|
|
|
|
if (ac->ac_flags & AMR_CMD_MAPPED) {
|
|
|
|
|
|
|
|
if (ac->ac_data != NULL) {
|
|
|
|
if (ac->ac_flags & AMR_CMD_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap, BUS_DMASYNC_POSTREAD);
|
|
|
|
if (ac->ac_flags & AMR_CMD_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap, BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_dmamap);
|
|
|
|
}
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
if (ac->ac_ccb_data != NULL) {
|
|
|
|
if (ac->ac_flags & AMR_CMD_CCB_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap, BUS_DMASYNC_POSTREAD);
|
|
|
|
if (ac->ac_flags & AMR_CMD_CCB_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap, BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_ccb_dmamap);
|
|
|
|
}
|
|
|
|
ac->ac_flags &= ~AMR_CMD_MAPPED;
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Take a command and give it to the controller, returns 0 if successful, or
|
|
|
|
* EBUSY if the command should be retried later.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_start(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
2000-04-01 00:35:15 +00:00
|
|
|
int done, s, i;
|
2002-10-18 21:29:14 +00:00
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
debug_called(3);
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
/* mark command as busy so that polling consumer can tell */
|
|
|
|
ac->ac_flags |= AMR_CMD_BUSY;
|
|
|
|
|
|
|
|
/* get a command slot (freed in amr_done) */
|
|
|
|
if (amr_getslot(ac))
|
|
|
|
return(EBUSY);
|
|
|
|
|
|
|
|
/* now we have a slot, we can map the command (unmapped in amr_complete) */
|
|
|
|
amr_mapcmd(ac);
|
|
|
|
|
|
|
|
/* mark the new mailbox we are going to copy in as busy */
|
|
|
|
ac->ac_mailbox.mb_busy = 1;
|
|
|
|
|
|
|
|
/* clear the poll/ack fields in the mailbox */
|
|
|
|
sc->amr_mailbox->mb_poll = 0;
|
|
|
|
sc->amr_mailbox->mb_ack = 0;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the slot number so that we can locate this command when complete.
|
|
|
|
* Note that ident = 0 seems to be special, so we don't use it.
|
|
|
|
*/
|
|
|
|
ac->ac_mailbox.mb_ident = ac->ac_slot + 1;
|
|
|
|
|
2000-04-01 00:35:15 +00:00
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Spin waiting for the mailbox, give up after ~1 second. We expect the
|
|
|
|
* controller to be able to handle our I/O.
|
|
|
|
*
|
|
|
|
* XXX perhaps we should wait for less time, and count on the deferred command
|
|
|
|
* handling to deal with retries?
|
2000-04-01 00:35:15 +00:00
|
|
|
*/
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(4, "wait for mailbox");
|
2000-04-01 00:35:15 +00:00
|
|
|
for (i = 10000, done = 0; (i > 0) && !done; i--) {
|
1999-10-07 02:23:12 +00:00
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/* is the mailbox free? */
|
|
|
|
if (sc->amr_mailbox->mb_busy == 0) {
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(4, "got mailbox");
|
1999-10-07 02:23:12 +00:00
|
|
|
sc->amr_mailbox64->mb64_segment = 0;
|
2000-08-30 07:52:50 +00:00
|
|
|
bcopy(&ac->ac_mailbox, (void *)(uintptr_t)(volatile void *)sc->amr_mailbox, AMR_MBOX_CMDSIZE);
|
1999-10-07 02:23:12 +00:00
|
|
|
done = 1;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* not free, spin waiting */
|
1999-10-07 02:23:12 +00:00
|
|
|
} else {
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(4, "busy flag %x\n", sc->amr_mailbox->mb_busy);
|
2000-04-01 00:35:15 +00:00
|
|
|
/* this is somewhat ugly */
|
|
|
|
DELAY(100);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-04-01 00:35:15 +00:00
|
|
|
splx(s); /* drop spl to allow completion interrupts */
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now give the command to the controller
|
|
|
|
*/
|
1999-10-07 02:23:12 +00:00
|
|
|
if (done) {
|
2000-08-30 07:52:50 +00:00
|
|
|
if (sc->amr_submit_command(sc)) {
|
|
|
|
/* the controller wasn't ready to take the command, forget that we tried to post it */
|
|
|
|
sc->amr_mailbox->mb_busy = 0;
|
|
|
|
return(EBUSY);
|
|
|
|
}
|
2000-11-28 19:28:22 +00:00
|
|
|
debug(3, "posted command");
|
1999-10-07 02:23:12 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* The controller wouldn't take the command. Return the command as busy
|
|
|
|
* so that it is retried later.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
return(EBUSY);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Extract one or more completed commands from the controller (sc)
|
|
|
|
*
|
1999-10-26 23:18:57 +00:00
|
|
|
* Returns nonzero if any commands on the work queue were marked as completed.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
int
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_done(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
struct amr_mailbox mbox;
|
2000-08-30 07:52:50 +00:00
|
|
|
int i, idx, result;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* See if there's anything for us to do */
|
|
|
|
result = 0;
|
2000-04-01 00:35:15 +00:00
|
|
|
|
|
|
|
/* loop collecting completed commands */
|
|
|
|
for (;;) {
|
|
|
|
/* poll for a completed command's identifier and status */
|
|
|
|
if (sc->amr_get_work(sc, &mbox)) {
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
/* iterate over completed commands in this result */
|
|
|
|
for (i = 0; i < mbox.mb_nstatus; i++) {
|
|
|
|
/* get pointer to busy command */
|
|
|
|
idx = mbox.mb_completed[i] - 1;
|
|
|
|
ac = sc->amr_busycmd[idx];
|
|
|
|
|
|
|
|
/* really a busy command? */
|
|
|
|
if (ac != NULL) {
|
|
|
|
|
|
|
|
/* pull the command from the busy index */
|
|
|
|
sc->amr_busycmd[idx] = NULL;
|
2000-08-30 07:52:50 +00:00
|
|
|
sc->amr_busyslots--;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* save status for later use */
|
|
|
|
ac->ac_status = mbox.mb_status;
|
|
|
|
amr_enqueue_completed(ac);
|
|
|
|
debug(3, "completed command with status %x", mbox.mb_status);
|
|
|
|
} else {
|
|
|
|
device_printf(sc->amr_dev, "bad slot %d completed\n", idx);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-01 00:35:15 +00:00
|
|
|
} else {
|
2000-08-30 07:52:50 +00:00
|
|
|
break; /* no work */
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-01 00:35:15 +00:00
|
|
|
|
|
|
|
/* if we've completed any commands, try posting some more */
|
|
|
|
if (result)
|
|
|
|
amr_startio(sc);
|
|
|
|
|
|
|
|
/* handle completion and timeouts */
|
2000-08-30 07:52:50 +00:00
|
|
|
#if __FreeBSD_version >= 500005
|
|
|
|
if (sc->amr_state & AMR_STATE_INTEN)
|
|
|
|
taskqueue_enqueue(taskqueue_swi, &sc->amr_task_complete);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
amr_complete(sc, 0);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Do completion processing on done commands on (sc)
|
|
|
|
*/
|
|
|
|
static void
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_complete(void *context, int pending)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_softc *sc = (struct amr_softc *)context;
|
|
|
|
struct amr_command *ac;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-11-28 19:28:22 +00:00
|
|
|
debug_called(3);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* pull completed commands off the queue */
|
|
|
|
for (;;) {
|
|
|
|
ac = amr_dequeue_completed(sc);
|
|
|
|
if (ac == NULL)
|
|
|
|
break;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* unmap the command's data buffer */
|
|
|
|
amr_unmapcmd(ac);
|
2000-04-01 00:35:15 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/* unbusy the command */
|
|
|
|
ac->ac_flags &= ~AMR_CMD_BUSY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is there a completion handler?
|
|
|
|
*/
|
|
|
|
if (ac->ac_complete != NULL) {
|
|
|
|
ac->ac_complete(ac);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-30 07:52:50 +00:00
|
|
|
* Is someone sleeping on this one?
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
} else if (ac->ac_flags & AMR_CMD_SLEEP) {
|
|
|
|
wakeup(ac);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2003-01-09 21:02:28 +00:00
|
|
|
|
|
|
|
if(!sc->amr_busyslots) {
|
|
|
|
wakeup(sc);
|
|
|
|
}
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Command Buffer Management
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Get a new command buffer.
|
|
|
|
*
|
|
|
|
* This may return NULL in low-memory cases.
|
|
|
|
*
|
|
|
|
* If possible, we recycle a command buffer that's been used before.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_command *
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_alloccmd(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
struct amr_command *ac;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
ac = amr_dequeue_free(sc);
|
1999-10-07 02:23:12 +00:00
|
|
|
if (ac == NULL) {
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_alloccmd_cluster(sc);
|
|
|
|
ac = amr_dequeue_free(sc);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
if (ac == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
/* clear out significant fields */
|
|
|
|
ac->ac_slot = 0;
|
|
|
|
ac->ac_status = 0;
|
1999-10-07 02:23:12 +00:00
|
|
|
bzero(&ac->ac_mailbox, sizeof(struct amr_mailbox));
|
2000-08-30 07:52:50 +00:00
|
|
|
ac->ac_flags = 0;
|
|
|
|
ac->ac_bio = NULL;
|
|
|
|
ac->ac_data = NULL;
|
|
|
|
ac->ac_ccb_data = NULL;
|
|
|
|
ac->ac_complete = NULL;
|
1999-10-07 02:23:12 +00:00
|
|
|
return(ac);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Release a command buffer for recycling.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
void
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_releasecmd(struct amr_command *ac)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_enqueue_free(ac);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Allocate a new command cluster and initialise it.
|
1999-10-07 02:23:12 +00:00
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_alloccmd_cluster(struct amr_softc *sc)
|
1999-10-07 02:23:12 +00:00
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
struct amr_command_cluster *acc;
|
|
|
|
struct amr_command *ac;
|
|
|
|
int s, i;
|
|
|
|
|
|
|
|
acc = malloc(AMR_CMD_CLUSTERSIZE, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (acc != NULL) {
|
|
|
|
s = splbio();
|
|
|
|
TAILQ_INSERT_TAIL(&sc->amr_cmd_clusters, acc, acc_link);
|
|
|
|
splx(s);
|
|
|
|
for (i = 0; i < AMR_CMD_CLUSTERCOUNT; i++) {
|
|
|
|
ac = &acc->acc_command[i];
|
|
|
|
bzero(ac, sizeof(*ac));
|
|
|
|
ac->ac_sc = sc;
|
|
|
|
if (!bus_dmamap_create(sc->amr_buffer_dmat, 0, &ac->ac_dmamap) &&
|
|
|
|
!bus_dmamap_create(sc->amr_buffer_dmat, 0, &ac->ac_ccb_dmamap))
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Free a command cluster
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_freecmd_cluster(struct amr_command_cluster *acc)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = acc->acc_command[0].ac_sc;
|
|
|
|
int i;
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
for (i = 0; i < AMR_CMD_CLUSTERCOUNT; i++)
|
|
|
|
bus_dmamap_destroy(sc->amr_buffer_dmat, acc->acc_command[i].ac_dmamap);
|
|
|
|
free(acc, M_DEVBUF);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Interface-specific Shims
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Tell the controller that the mailbox contains a valid command
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
static int
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_quartz_submit_command(struct amr_softc *sc)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
if (AMR_QGET_IDB(sc) & AMR_QIDB_SUBMIT)
|
|
|
|
return(EBUSY);
|
1999-10-07 02:23:12 +00:00
|
|
|
AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_SUBMIT);
|
2000-08-30 07:52:50 +00:00
|
|
|
return(0);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
static int
|
1999-10-07 02:23:12 +00:00
|
|
|
amr_std_submit_command(struct amr_softc *sc)
|
|
|
|
{
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
if (AMR_SGET_MBSTAT(sc) & AMR_SMBOX_BUSYFLAG)
|
|
|
|
return(EBUSY);
|
1999-10-07 02:23:12 +00:00
|
|
|
AMR_SPOST_COMMAND(sc);
|
2000-08-30 07:52:50 +00:00
|
|
|
return(0);
|
1999-10-07 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Claim any work that the controller has completed; acknowledge completion,
|
|
|
|
* save details of the completion in (mbsave)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_quartz_get_work(struct amr_softc *sc, struct amr_mailbox *mbsave)
|
|
|
|
{
|
|
|
|
int s, worked;
|
|
|
|
u_int32_t outd;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
worked = 0;
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/* work waiting for us? */
|
|
|
|
if ((outd = AMR_QGET_ODB(sc)) == AMR_QODB_READY) {
|
|
|
|
|
|
|
|
/* save mailbox, which contains a list of completed commands */
|
2000-08-30 07:52:50 +00:00
|
|
|
bcopy((void *)(uintptr_t)(volatile void *)sc->amr_mailbox, mbsave, sizeof(*mbsave));
|
|
|
|
|
|
|
|
/* acknowledge interrupt */
|
|
|
|
AMR_QPUT_ODB(sc, AMR_QODB_READY);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* acknowledge that we have the commands */
|
|
|
|
AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_ACK);
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2000-09-11 23:19:13 +00:00
|
|
|
#ifndef AMR_QUARTZ_GOFASTER
|
2000-08-30 07:52:50 +00:00
|
|
|
/*
|
|
|
|
* This waits for the controller to notice that we've taken the
|
|
|
|
* command from it. It's very inefficient, and we shouldn't do it,
|
|
|
|
* but if we remove this code, we stop completing commands under
|
|
|
|
* load.
|
|
|
|
*
|
|
|
|
* Peter J says we shouldn't do this. The documentation says we
|
|
|
|
* should. Who is right?
|
|
|
|
*/
|
1999-10-07 02:23:12 +00:00
|
|
|
while(AMR_QGET_IDB(sc) & AMR_QIDB_ACK)
|
|
|
|
; /* XXX aiee! what if it dies? */
|
2000-08-30 07:52:50 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
worked = 1; /* got some work */
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(worked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
amr_std_get_work(struct amr_softc *sc, struct amr_mailbox *mbsave)
|
|
|
|
{
|
|
|
|
int s, worked;
|
|
|
|
u_int8_t istat;
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
debug_called(3);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
worked = 0;
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/* check for valid interrupt status */
|
|
|
|
istat = AMR_SGET_ISTAT(sc);
|
|
|
|
if ((istat & AMR_SINTR_VALID) != 0) {
|
|
|
|
AMR_SPUT_ISTAT(sc, istat); /* ack interrupt status */
|
|
|
|
|
|
|
|
/* save mailbox, which contains a list of completed commands */
|
2000-08-30 07:52:50 +00:00
|
|
|
bcopy((void *)(uintptr_t)(volatile void *)sc->amr_mailbox, mbsave, sizeof(*mbsave));
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
AMR_SACK_INTERRUPT(sc); /* acknowledge we have the mailbox */
|
|
|
|
worked = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(worked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Notify the controller of the mailbox location.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_std_attach_mailbox(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* program the mailbox physical address */
|
|
|
|
AMR_SBYTE_SET(sc, AMR_SMBOX_0, sc->amr_mailboxphys & 0xff);
|
|
|
|
AMR_SBYTE_SET(sc, AMR_SMBOX_1, (sc->amr_mailboxphys >> 8) & 0xff);
|
|
|
|
AMR_SBYTE_SET(sc, AMR_SMBOX_2, (sc->amr_mailboxphys >> 16) & 0xff);
|
|
|
|
AMR_SBYTE_SET(sc, AMR_SMBOX_3, (sc->amr_mailboxphys >> 24) & 0xff);
|
|
|
|
AMR_SBYTE_SET(sc, AMR_SMBOX_ENABLE, AMR_SMBOX_ADDR);
|
|
|
|
|
|
|
|
/* clear any outstanding interrupt and enable interrupts proper */
|
|
|
|
AMR_SACK_INTERRUPT(sc);
|
|
|
|
AMR_SENABLE_INTR(sc);
|
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#ifdef AMR_BOARD_INIT
|
|
|
|
/********************************************************************************
|
|
|
|
* Initialise the controller
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
amr_quartz_init(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
int status, ostatus;
|
|
|
|
|
|
|
|
device_printf(sc->amr_dev, "initial init status %x\n", AMR_QGET_INITSTATUS(sc));
|
|
|
|
|
|
|
|
AMR_QRESET(sc);
|
|
|
|
|
|
|
|
ostatus = 0xff;
|
|
|
|
while ((status = AMR_QGET_INITSTATUS(sc)) != AMR_QINIT_DONE) {
|
|
|
|
if (status != ostatus) {
|
|
|
|
device_printf(sc->amr_dev, "(%x) %s\n", status, amr_describe_code(amr_table_qinit, status));
|
|
|
|
ostatus = status;
|
|
|
|
}
|
|
|
|
switch (status) {
|
|
|
|
case AMR_QINIT_NOMEM:
|
|
|
|
return(ENOMEM);
|
|
|
|
|
|
|
|
case AMR_QINIT_SCAN:
|
|
|
|
/* XXX we could print channel/target here */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
amr_std_init(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
int status, ostatus;
|
|
|
|
|
|
|
|
device_printf(sc->amr_dev, "initial init status %x\n", AMR_SGET_INITSTATUS(sc));
|
|
|
|
|
|
|
|
AMR_SRESET(sc);
|
|
|
|
|
|
|
|
ostatus = 0xff;
|
|
|
|
while ((status = AMR_SGET_INITSTATUS(sc)) != AMR_SINIT_DONE) {
|
|
|
|
if (status != ostatus) {
|
|
|
|
device_printf(sc->amr_dev, "(%x) %s\n", status, amr_describe_code(amr_table_sinit, status));
|
|
|
|
ostatus = status;
|
|
|
|
}
|
|
|
|
switch (status) {
|
|
|
|
case AMR_SINIT_NOMEM:
|
|
|
|
return(ENOMEM);
|
|
|
|
|
|
|
|
case AMR_SINIT_INPROG:
|
|
|
|
/* XXX we could print channel/target here? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
Debugging
|
|
|
|
********************************************************************************
|
|
|
|
********************************************************************************/
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Identify the controller and print some information about it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_describe_controller(struct amr_softc *sc)
|
|
|
|
{
|
|
|
|
struct amr_prodinfo *ap;
|
|
|
|
struct amr_enquiry *ae;
|
|
|
|
char *prod;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to get 40LD product info, which tells us what the card is labelled as.
|
|
|
|
*/
|
|
|
|
if ((ap = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_PRODUCT_INFO, 0)) != NULL) {
|
2002-10-18 21:29:14 +00:00
|
|
|
device_printf(sc->amr_dev, "<LSILogic %.80s> Firmware %.16s, BIOS %.16s, %dMB RAM\n",
|
2000-08-30 07:52:50 +00:00
|
|
|
ap->ap_product, ap->ap_firmware, ap->ap_bios,
|
|
|
|
ap->ap_memsize);
|
|
|
|
|
|
|
|
free(ap, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try 8LD extended ENQUIRY to get controller signature, and use lookup table.
|
|
|
|
*/
|
|
|
|
if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_EXT_ENQUIRY2, 0, 0)) != NULL) {
|
|
|
|
prod = amr_describe_code(amr_table_adaptertype, ae->ae_signature);
|
|
|
|
|
|
|
|
} else if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_ENQUIRY, 0, 0)) != NULL) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to work it out based on the PCI signatures.
|
|
|
|
*/
|
|
|
|
switch (pci_get_device(sc->amr_dev)) {
|
|
|
|
case 0x9010:
|
|
|
|
prod = "Series 428";
|
|
|
|
break;
|
|
|
|
case 0x9060:
|
|
|
|
prod = "Series 434";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prod = "unknown controller";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prod = "unsupported controller";
|
|
|
|
}
|
2001-03-28 14:11:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HP NetRaid controllers have a special encoding of the firmware and
|
|
|
|
* BIOS versions. The AMI version seems to have it as strings whereas
|
|
|
|
* the HP version does it with a leading uppercase character and two
|
|
|
|
* binary numbers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(ae->ae_adapter.aa_firmware[2] >= 'A' &&
|
|
|
|
ae->ae_adapter.aa_firmware[2] <= 'Z' &&
|
|
|
|
ae->ae_adapter.aa_firmware[1] < ' ' &&
|
|
|
|
ae->ae_adapter.aa_firmware[0] < ' ' &&
|
|
|
|
ae->ae_adapter.aa_bios[2] >= 'A' &&
|
|
|
|
ae->ae_adapter.aa_bios[2] <= 'Z' &&
|
|
|
|
ae->ae_adapter.aa_bios[1] < ' ' &&
|
|
|
|
ae->ae_adapter.aa_bios[0] < ' ') {
|
|
|
|
|
|
|
|
/* this looks like we have an HP NetRaid version of the MegaRaid */
|
|
|
|
|
|
|
|
if(ae->ae_signature == AMR_SIG_438) {
|
2002-12-30 21:18:15 +00:00
|
|
|
/* the AMI 438 is a NetRaid 3si in HP-land */
|
2001-03-28 14:11:15 +00:00
|
|
|
prod = "HP NetRaid 3si";
|
|
|
|
}
|
|
|
|
|
|
|
|
device_printf(sc->amr_dev, "<%s> Firmware %c.%02d.%02d, BIOS %c.%02d.%02d, %dMB RAM\n",
|
|
|
|
prod, ae->ae_adapter.aa_firmware[2],
|
|
|
|
ae->ae_adapter.aa_firmware[1],
|
|
|
|
ae->ae_adapter.aa_firmware[0],
|
|
|
|
ae->ae_adapter.aa_bios[2],
|
|
|
|
ae->ae_adapter.aa_bios[1],
|
|
|
|
ae->ae_adapter.aa_bios[0],
|
|
|
|
ae->ae_adapter.aa_memorysize);
|
|
|
|
} else {
|
|
|
|
device_printf(sc->amr_dev, "<%s> Firmware %.4s, BIOS %.4s, %dMB RAM\n",
|
|
|
|
prod, ae->ae_adapter.aa_firmware, ae->ae_adapter.aa_bios,
|
|
|
|
ae->ae_adapter.aa_memorysize);
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
free(ae, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef AMR_DEBUG
|
1999-10-07 02:23:12 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Print the command (ac) in human-readable format
|
|
|
|
*/
|
2002-12-11 20:59:46 +00:00
|
|
|
#if 0
|
1999-10-07 02:23:12 +00:00
|
|
|
static void
|
|
|
|
amr_printcommand(struct amr_command *ac)
|
|
|
|
{
|
|
|
|
struct amr_softc *sc = ac->ac_sc;
|
|
|
|
struct amr_sgentry *sg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
device_printf(sc->amr_dev, "cmd %x ident %d drive %d\n",
|
|
|
|
ac->ac_mailbox.mb_command, ac->ac_mailbox.mb_ident, ac->ac_mailbox.mb_drive);
|
|
|
|
device_printf(sc->amr_dev, "blkcount %d lba %d\n",
|
|
|
|
ac->ac_mailbox.mb_blkcount, ac->ac_mailbox.mb_lba);
|
1999-12-12 20:53:31 +00:00
|
|
|
device_printf(sc->amr_dev, "virtaddr %p length %lu\n", ac->ac_data, (unsigned long)ac->ac_length);
|
2000-04-01 00:35:15 +00:00
|
|
|
device_printf(sc->amr_dev, "sg physaddr %08x nsg %d\n",
|
1999-10-07 02:23:12 +00:00
|
|
|
ac->ac_mailbox.mb_physaddr, ac->ac_mailbox.mb_nsgelem);
|
2000-08-30 07:52:50 +00:00
|
|
|
device_printf(sc->amr_dev, "ccb %p bio %p\n", ac->ac_ccb_data, ac->ac_bio);
|
1999-10-07 02:23:12 +00:00
|
|
|
|
|
|
|
/* get base address of s/g table */
|
|
|
|
sg = sc->amr_sgtable + (ac->ac_slot * AMR_NSEG);
|
|
|
|
for (i = 0; i < ac->ac_mailbox.mb_nsgelem; i++, sg++)
|
|
|
|
device_printf(sc->amr_dev, " %x/%d\n", sg->sg_addr, sg->sg_count);
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
#endif
|
2002-12-11 20:59:46 +00:00
|
|
|
#endif
|