2000-09-13 03:20:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
2001-08-03 00:50:30 +00:00
|
|
|
* Copyright (c) 2001 Scott Long
|
2000-09-13 03:20:35 +00:00
|
|
|
* Copyright (c) 2000 BSDi
|
2001-08-03 00:50:30 +00:00
|
|
|
* Copyright (c) 2001 Adaptec, Inc.
|
2000-09-13 03:20:35 +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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-09-13 03:20:35 +00:00
|
|
|
/*
|
|
|
|
* Driver for the Adaptec 'FSA' family of PCI/SCSI RAID adapters.
|
|
|
|
*/
|
2005-10-08 15:55:09 +00:00
|
|
|
#define AAC_DRIVERNAME "aac"
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-08-05 06:20:13 +00:00
|
|
|
#include "opt_aac.h"
|
|
|
|
|
2001-08-29 23:34:05 +00:00
|
|
|
/* #include <stddef.h> */
|
2000-09-13 03:20:35 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-08-29 23:34:05 +00:00
|
|
|
#include <sys/kthread.h>
|
2001-08-05 07:26:31 +00:00
|
|
|
#include <sys/sysctl.h>
|
2001-12-02 03:47:33 +00:00
|
|
|
#include <sys/poll.h>
|
2003-04-01 15:06:26 +00:00
|
|
|
#include <sys/ioccom.h>
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/signalvar.h>
|
2000-12-27 13:14:56 +00:00
|
|
|
#include <sys/time.h>
|
2001-08-29 23:34:05 +00:00
|
|
|
#include <sys/eventhandler.h>
|
2005-10-08 15:55:09 +00:00
|
|
|
#include <sys/rman.h>
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2005-03-19 06:29:32 +00:00
|
|
|
#include <sys/bus_dma.h>
|
2000-09-13 03:20:35 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
2000-09-13 03:20:35 +00:00
|
|
|
#include <dev/aac/aacreg.h>
|
2004-12-09 22:20:25 +00:00
|
|
|
#include <sys/aac_ioctl.h>
|
2000-09-13 03:20:35 +00:00
|
|
|
#include <dev/aac/aacvar.h>
|
|
|
|
#include <dev/aac/aac_tables.h>
|
|
|
|
|
|
|
|
static void aac_startup(void *arg);
|
2001-09-05 20:43:02 +00:00
|
|
|
static void aac_add_container(struct aac_softc *sc,
|
2002-04-24 05:12:50 +00:00
|
|
|
struct aac_mntinforesp *mir, int f);
|
2002-04-27 01:31:17 +00:00
|
|
|
static void aac_get_bus_info(struct aac_softc *sc);
|
2009-02-21 15:40:03 +00:00
|
|
|
static void aac_daemon(void *arg);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
/* Command Processing */
|
2000-12-27 13:14:56 +00:00
|
|
|
static void aac_timeout(struct aac_softc *sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
static void aac_complete(void *context, int pending);
|
|
|
|
static int aac_bio_command(struct aac_softc *sc, struct aac_command **cmp);
|
|
|
|
static void aac_bio_complete(struct aac_command *cm);
|
2004-04-14 19:11:29 +00:00
|
|
|
static int aac_wait_command(struct aac_command *cm);
|
2003-02-05 23:24:25 +00:00
|
|
|
static void aac_command_thread(struct aac_softc *sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
/* Command Buffer Management */
|
2003-07-09 21:16:23 +00:00
|
|
|
static void aac_map_command_sg(void *arg, bus_dma_segment_t *segs,
|
|
|
|
int nseg, int error);
|
2001-08-03 00:50:30 +00:00
|
|
|
static void aac_map_command_helper(void *arg, bus_dma_segment_t *segs,
|
|
|
|
int nseg, int error);
|
2000-12-27 13:14:56 +00:00
|
|
|
static int aac_alloc_commands(struct aac_softc *sc);
|
2003-02-19 21:38:29 +00:00
|
|
|
static void aac_free_commands(struct aac_softc *sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
static void aac_unmap_command(struct aac_command *cm);
|
|
|
|
|
|
|
|
/* Hardware Interface */
|
2008-03-24 16:38:47 +00:00
|
|
|
static int aac_alloc(struct aac_softc *sc);
|
2001-08-03 00:50:30 +00:00
|
|
|
static void aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg,
|
|
|
|
int error);
|
2002-02-06 01:34:09 +00:00
|
|
|
static int aac_check_firmware(struct aac_softc *sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
static int aac_init(struct aac_softc *sc);
|
|
|
|
static int aac_sync_command(struct aac_softc *sc, u_int32_t command,
|
2001-08-03 00:50:30 +00:00
|
|
|
u_int32_t arg0, u_int32_t arg1, u_int32_t arg2,
|
|
|
|
u_int32_t arg3, u_int32_t *sp);
|
2008-03-24 16:38:47 +00:00
|
|
|
static int aac_setup_intr(struct aac_softc *sc);
|
2001-08-03 00:50:30 +00:00
|
|
|
static int aac_enqueue_fib(struct aac_softc *sc, int queue,
|
2001-08-05 06:20:13 +00:00
|
|
|
struct aac_command *cm);
|
2001-08-03 00:50:30 +00:00
|
|
|
static int aac_dequeue_fib(struct aac_softc *sc, int queue,
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t *fib_size, struct aac_fib **fib_addr);
|
2001-08-29 23:34:05 +00:00
|
|
|
static int aac_enqueue_response(struct aac_softc *sc, int queue,
|
|
|
|
struct aac_fib *fib);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
/* StrongARM interface */
|
|
|
|
static int aac_sa_get_fwstatus(struct aac_softc *sc);
|
|
|
|
static void aac_sa_qnotify(struct aac_softc *sc, int qbit);
|
|
|
|
static int aac_sa_get_istatus(struct aac_softc *sc);
|
|
|
|
static void aac_sa_clear_istatus(struct aac_softc *sc, int mask);
|
|
|
|
static void aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command,
|
2001-08-03 00:50:30 +00:00
|
|
|
u_int32_t arg0, u_int32_t arg1,
|
|
|
|
u_int32_t arg2, u_int32_t arg3);
|
2003-03-26 17:50:11 +00:00
|
|
|
static int aac_sa_get_mailbox(struct aac_softc *sc, int mb);
|
2000-09-13 03:20:35 +00:00
|
|
|
static void aac_sa_set_interrupts(struct aac_softc *sc, int enable);
|
|
|
|
|
|
|
|
struct aac_interface aac_sa_interface = {
|
2001-09-05 20:43:02 +00:00
|
|
|
aac_sa_get_fwstatus,
|
|
|
|
aac_sa_qnotify,
|
|
|
|
aac_sa_get_istatus,
|
|
|
|
aac_sa_clear_istatus,
|
|
|
|
aac_sa_set_mailbox,
|
2003-03-26 17:50:11 +00:00
|
|
|
aac_sa_get_mailbox,
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_sa_set_interrupts,
|
|
|
|
NULL, NULL, NULL
|
2000-09-13 03:20:35 +00:00
|
|
|
};
|
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/* i960Rx interface */
|
2000-09-13 03:20:35 +00:00
|
|
|
static int aac_rx_get_fwstatus(struct aac_softc *sc);
|
|
|
|
static void aac_rx_qnotify(struct aac_softc *sc, int qbit);
|
|
|
|
static int aac_rx_get_istatus(struct aac_softc *sc);
|
|
|
|
static void aac_rx_clear_istatus(struct aac_softc *sc, int mask);
|
|
|
|
static void aac_rx_set_mailbox(struct aac_softc *sc, u_int32_t command,
|
2001-08-03 00:50:30 +00:00
|
|
|
u_int32_t arg0, u_int32_t arg1,
|
|
|
|
u_int32_t arg2, u_int32_t arg3);
|
2003-03-26 17:50:11 +00:00
|
|
|
static int aac_rx_get_mailbox(struct aac_softc *sc, int mb);
|
2000-09-13 03:20:35 +00:00
|
|
|
static void aac_rx_set_interrupts(struct aac_softc *sc, int enable);
|
2005-10-08 15:55:09 +00:00
|
|
|
static int aac_rx_send_command(struct aac_softc *sc, struct aac_command *cm);
|
|
|
|
static int aac_rx_get_outb_queue(struct aac_softc *sc);
|
|
|
|
static void aac_rx_set_outb_queue(struct aac_softc *sc, int index);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
struct aac_interface aac_rx_interface = {
|
2001-09-05 20:43:02 +00:00
|
|
|
aac_rx_get_fwstatus,
|
|
|
|
aac_rx_qnotify,
|
|
|
|
aac_rx_get_istatus,
|
|
|
|
aac_rx_clear_istatus,
|
|
|
|
aac_rx_set_mailbox,
|
2003-03-26 17:50:11 +00:00
|
|
|
aac_rx_get_mailbox,
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_rx_set_interrupts,
|
|
|
|
aac_rx_send_command,
|
|
|
|
aac_rx_get_outb_queue,
|
|
|
|
aac_rx_set_outb_queue
|
2000-09-13 03:20:35 +00:00
|
|
|
};
|
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/* Rocket/MIPS interface */
|
2004-08-13 01:44:09 +00:00
|
|
|
static int aac_rkt_get_fwstatus(struct aac_softc *sc);
|
|
|
|
static void aac_rkt_qnotify(struct aac_softc *sc, int qbit);
|
|
|
|
static int aac_rkt_get_istatus(struct aac_softc *sc);
|
|
|
|
static void aac_rkt_clear_istatus(struct aac_softc *sc, int mask);
|
|
|
|
static void aac_rkt_set_mailbox(struct aac_softc *sc, u_int32_t command,
|
|
|
|
u_int32_t arg0, u_int32_t arg1,
|
|
|
|
u_int32_t arg2, u_int32_t arg3);
|
|
|
|
static int aac_rkt_get_mailbox(struct aac_softc *sc, int mb);
|
|
|
|
static void aac_rkt_set_interrupts(struct aac_softc *sc, int enable);
|
2005-10-08 15:55:09 +00:00
|
|
|
static int aac_rkt_send_command(struct aac_softc *sc, struct aac_command *cm);
|
|
|
|
static int aac_rkt_get_outb_queue(struct aac_softc *sc);
|
|
|
|
static void aac_rkt_set_outb_queue(struct aac_softc *sc, int index);
|
2004-08-13 01:44:09 +00:00
|
|
|
|
|
|
|
struct aac_interface aac_rkt_interface = {
|
|
|
|
aac_rkt_get_fwstatus,
|
|
|
|
aac_rkt_qnotify,
|
|
|
|
aac_rkt_get_istatus,
|
|
|
|
aac_rkt_clear_istatus,
|
|
|
|
aac_rkt_set_mailbox,
|
|
|
|
aac_rkt_get_mailbox,
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_rkt_set_interrupts,
|
|
|
|
aac_rkt_send_command,
|
|
|
|
aac_rkt_get_outb_queue,
|
|
|
|
aac_rkt_set_outb_queue
|
2004-08-13 01:44:09 +00:00
|
|
|
};
|
|
|
|
|
2000-09-13 03:20:35 +00:00
|
|
|
/* Debugging and Diagnostics */
|
|
|
|
static void aac_describe_controller(struct aac_softc *sc);
|
2001-08-30 13:09:09 +00:00
|
|
|
static char *aac_describe_code(struct aac_code_lookup *table,
|
2001-08-03 00:50:30 +00:00
|
|
|
u_int32_t code);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
/* Management Interface */
|
|
|
|
static d_open_t aac_open;
|
|
|
|
static d_ioctl_t aac_ioctl;
|
2001-12-02 03:47:33 +00:00
|
|
|
static d_poll_t aac_poll;
|
2010-09-16 17:49:10 +00:00
|
|
|
static void aac_cdevpriv_dtor(void *arg);
|
2001-08-03 00:50:30 +00:00
|
|
|
static int aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib);
|
2008-03-20 17:59:19 +00:00
|
|
|
static int aac_ioctl_send_raw_srb(struct aac_softc *sc, caddr_t arg);
|
2001-08-03 00:50:30 +00:00
|
|
|
static void aac_handle_aif(struct aac_softc *sc,
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_fib *fib);
|
2001-08-06 04:34:47 +00:00
|
|
|
static int aac_rev_check(struct aac_softc *sc, caddr_t udata);
|
2007-12-07 00:22:23 +00:00
|
|
|
static int aac_open_aif(struct aac_softc *sc, caddr_t arg);
|
|
|
|
static int aac_close_aif(struct aac_softc *sc, caddr_t arg);
|
2001-08-06 04:34:47 +00:00
|
|
|
static int aac_getnext_aif(struct aac_softc *sc, caddr_t arg);
|
2007-12-07 00:22:23 +00:00
|
|
|
static int aac_return_aif(struct aac_softc *sc,
|
|
|
|
struct aac_fib_context *ctx, caddr_t uptr);
|
2001-08-29 23:34:05 +00:00
|
|
|
static int aac_query_disk(struct aac_softc *sc, caddr_t uptr);
|
2005-10-08 15:55:09 +00:00
|
|
|
static int aac_get_pci_info(struct aac_softc *sc, caddr_t uptr);
|
2008-03-28 19:07:25 +00:00
|
|
|
static int aac_supported_features(struct aac_softc *sc, caddr_t uptr);
|
2005-10-08 15:55:09 +00:00
|
|
|
static void aac_ioctl_event(struct aac_softc *sc,
|
2009-10-27 19:37:37 +00:00
|
|
|
struct aac_event *event, void *arg);
|
2008-03-24 16:38:47 +00:00
|
|
|
static struct aac_mntinforesp *
|
|
|
|
aac_get_container_info(struct aac_softc *sc, struct aac_fib *fib, int cid);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
static struct cdevsw aac_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2010-09-16 17:49:10 +00:00
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = aac_open,
|
|
|
|
.d_ioctl = aac_ioctl,
|
|
|
|
.d_poll = aac_poll,
|
|
|
|
.d_name = "aac",
|
2000-09-13 03:20:35 +00:00
|
|
|
};
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_AACBUF, "aacbuf", "Buffers for the AAC driver");
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-08-05 07:26:31 +00:00
|
|
|
/* sysctl node */
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_hw, OID_AUTO, aac, CTLFLAG_RD, 0, "AAC driver parameters");
|
2001-08-05 07:26:31 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Device Interface
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize the controller and softc
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
aac_attach(struct aac_softc *sc)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
int error, unit;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize per-controller queues.
|
2001-09-05 20:43:02 +00:00
|
|
|
*/
|
|
|
|
aac_initq_free(sc);
|
|
|
|
aac_initq_ready(sc);
|
|
|
|
aac_initq_busy(sc);
|
|
|
|
aac_initq_bio(sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize command-completion task.
|
2001-09-05 20:43:02 +00:00
|
|
|
*/
|
|
|
|
TASK_INIT(&sc->aac_task_complete, 0, aac_complete, sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* mark controller as suspended until we get ourselves organised */
|
|
|
|
sc->aac_state |= AAC_STATE_SUSPEND;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2002-02-06 01:34:09 +00:00
|
|
|
/*
|
|
|
|
* Check that the firmware on the card is supported.
|
|
|
|
*/
|
|
|
|
if ((error = aac_check_firmware(sc)) != 0)
|
|
|
|
return(error);
|
|
|
|
|
2003-07-01 15:52:06 +00:00
|
|
|
/*
|
|
|
|
* Initialize locks
|
|
|
|
*/
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_init(&sc->aac_aifq_lock, "AAC AIF lock", NULL, MTX_DEF);
|
|
|
|
mtx_init(&sc->aac_io_lock, "AAC I/O lock", NULL, MTX_DEF);
|
|
|
|
mtx_init(&sc->aac_container_lock, "AAC container lock", NULL, MTX_DEF);
|
2003-07-01 15:52:06 +00:00
|
|
|
TAILQ_INIT(&sc->aac_container_tqh);
|
2005-12-28 21:18:55 +00:00
|
|
|
TAILQ_INIT(&sc->aac_ev_cmfree);
|
2003-07-01 15:52:06 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
/* Initialize the clock daemon callout. */
|
|
|
|
callout_init_mtx(&sc->aac_daemontime, &sc->aac_io_lock, 0);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize the adapter.
|
2001-09-05 20:43:02 +00:00
|
|
|
*/
|
2008-03-24 16:38:47 +00:00
|
|
|
if ((error = aac_alloc(sc)) != 0)
|
|
|
|
return(error);
|
2001-09-05 20:43:02 +00:00
|
|
|
if ((error = aac_init(sc)) != 0)
|
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2005-10-08 15:55:09 +00:00
|
|
|
* Allocate and connect our interrupt.
|
|
|
|
*/
|
2008-03-24 16:38:47 +00:00
|
|
|
if ((error = aac_setup_intr(sc)) != 0)
|
|
|
|
return(error);
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2001-09-05 20:43:02 +00:00
|
|
|
* Print a little information about the controller.
|
|
|
|
*/
|
|
|
|
aac_describe_controller(sc);
|
|
|
|
|
2012-02-13 16:48:49 +00:00
|
|
|
/*
|
|
|
|
* Add sysctls.
|
|
|
|
*/
|
|
|
|
SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->aac_dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->aac_dev)),
|
|
|
|
OID_AUTO, "firmware_build", CTLFLAG_RD,
|
|
|
|
&sc->aac_revision.buildNumber, 0,
|
|
|
|
"firmware build number");
|
|
|
|
|
2001-12-02 03:47:33 +00:00
|
|
|
/*
|
2003-02-26 04:46:21 +00:00
|
|
|
* Register to probe our containers later.
|
2001-12-02 03:47:33 +00:00
|
|
|
*/
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_ich.ich_func = aac_startup;
|
|
|
|
sc->aac_ich.ich_arg = sc;
|
|
|
|
if (config_intrhook_establish(&sc->aac_ich) != 0) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"can't establish configuration hook\n");
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the control device.
|
|
|
|
*/
|
|
|
|
unit = device_get_unit(sc->aac_dev);
|
2002-12-27 17:52:16 +00:00
|
|
|
sc->aac_dev_t = make_dev(&aac_cdevsw, unit, UID_ROOT, GID_OPERATOR,
|
|
|
|
0640, "aac%d", unit);
|
2001-09-05 20:43:02 +00:00
|
|
|
(void)make_dev_alias(sc->aac_dev_t, "afa%d", unit);
|
|
|
|
(void)make_dev_alias(sc->aac_dev_t, "hpn%d", unit);
|
|
|
|
sc->aac_dev_t->si_drv1 = sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Create the AIF thread */
|
2007-10-20 23:23:23 +00:00
|
|
|
if (kproc_create((void(*)(void *))aac_command_thread, sc,
|
2005-10-08 15:55:09 +00:00
|
|
|
&sc->aifthread, 0, 0, "aac%daif", unit))
|
2008-03-26 15:28:56 +00:00
|
|
|
panic("Could not create AIF thread");
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Register the shutdown method to only be called post-dump */
|
2003-02-06 00:07:12 +00:00
|
|
|
if ((sc->eh = EVENTHANDLER_REGISTER(shutdown_final, aac_shutdown,
|
|
|
|
sc->aac_dev, SHUTDOWN_PRI_DEFAULT)) == NULL)
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"shutdown event registration failed\n");
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2002-04-27 01:31:17 +00:00
|
|
|
/* Register with CAM for the non-DASD devices */
|
2003-03-26 17:50:11 +00:00
|
|
|
if ((sc->flags & AAC_FLAGS_ENABLE_CAM) != 0) {
|
2003-02-05 23:24:25 +00:00
|
|
|
TAILQ_INIT(&sc->aac_sim_tqh);
|
2002-04-27 01:31:17 +00:00
|
|
|
aac_get_bus_info(sc);
|
2003-02-05 23:24:25 +00:00
|
|
|
}
|
2002-04-27 01:31:17 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2009-10-28 13:50:28 +00:00
|
|
|
callout_reset(&sc->aac_daemontime, 60 * hz, aac_daemon, sc);
|
2009-02-21 15:40:03 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
static void
|
|
|
|
aac_daemon(void *arg)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
struct aac_softc *sc;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
mtx_assert(&sc->aac_io_lock, MA_OWNED);
|
|
|
|
|
|
|
|
if (callout_pending(&sc->aac_daemontime) ||
|
|
|
|
callout_active(&sc->aac_daemontime) == 0)
|
|
|
|
return;
|
|
|
|
getmicrotime(&tv);
|
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
|
|
|
*(uint32_t *)fib->data = tv.tv_sec;
|
|
|
|
aac_sync_fib(sc, SendHostTime, 0, fib, sizeof(uint32_t));
|
|
|
|
aac_release_sync_fib(sc);
|
|
|
|
callout_schedule(&sc->aac_daemontime, 30 * 60 * hz);
|
|
|
|
}
|
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
void
|
|
|
|
aac_add_event(struct aac_softc *sc, struct aac_event *event)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (event->ev_type & AAC_EVENT_MASK) {
|
|
|
|
case AAC_EVENT_CMFREE:
|
|
|
|
TAILQ_INSERT_TAIL(&sc->aac_ev_cmfree, event, ev_links);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(sc->aac_dev, "aac_add event: unknown event %d\n",
|
|
|
|
event->ev_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-24 16:38:47 +00:00
|
|
|
/*
|
|
|
|
* Request information of container #cid
|
|
|
|
*/
|
|
|
|
static struct aac_mntinforesp *
|
|
|
|
aac_get_container_info(struct aac_softc *sc, struct aac_fib *fib, int cid)
|
|
|
|
{
|
|
|
|
struct aac_mntinfo *mi;
|
|
|
|
|
|
|
|
mi = (struct aac_mntinfo *)&fib->data[0];
|
2008-03-25 21:39:06 +00:00
|
|
|
/* use 64-bit LBA if enabled */
|
|
|
|
mi->Command = (sc->flags & AAC_FLAGS_LBA_64BIT) ?
|
|
|
|
VM_NameServe64 : VM_NameServe;
|
2008-03-24 16:38:47 +00:00
|
|
|
mi->MntType = FT_FILESYS;
|
|
|
|
mi->MntCount = cid;
|
|
|
|
|
|
|
|
if (aac_sync_fib(sc, ContainerCommand, 0, fib,
|
|
|
|
sizeof(struct aac_mntinfo))) {
|
2010-09-16 23:33:24 +00:00
|
|
|
device_printf(sc->aac_dev, "Error probing container %d\n", cid);
|
2008-03-24 16:38:47 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((struct aac_mntinforesp *)&fib->data[0]);
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Probe for containers, create disks.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_startup(void *arg)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2002-04-24 05:12:50 +00:00
|
|
|
struct aac_fib *fib;
|
2008-03-24 16:38:47 +00:00
|
|
|
struct aac_mntinforesp *mir;
|
2003-06-03 02:10:55 +00:00
|
|
|
int count = 0, i = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = (struct aac_softc *)arg;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* disconnect ourselves from the intrhook chain */
|
|
|
|
config_intrhook_disestablish(&sc->aac_ich);
|
2000-12-27 13:14:56 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-06-02 18:15:48 +00:00
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
2002-04-24 05:12:50 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* loop over possible containers */
|
|
|
|
do {
|
2008-03-24 16:38:47 +00:00
|
|
|
if ((mir = aac_get_container_info(sc, fib, i)) == NULL)
|
2001-09-05 20:43:02 +00:00
|
|
|
continue;
|
2008-03-24 16:38:47 +00:00
|
|
|
if (i == 0)
|
|
|
|
count = mir->MntRespCount;
|
2002-04-24 05:12:50 +00:00
|
|
|
aac_add_container(sc, mir, 0);
|
2001-09-05 20:43:02 +00:00
|
|
|
i++;
|
2003-06-03 02:10:55 +00:00
|
|
|
} while ((i < count) && (i < AAC_MAX_CONTAINERS));
|
2002-04-24 05:12:50 +00:00
|
|
|
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* poke the bus to actually attach the child devices */
|
|
|
|
if (bus_generic_attach(sc->aac_dev))
|
|
|
|
device_printf(sc->aac_dev, "bus_generic_attach failed\n");
|
|
|
|
|
|
|
|
/* mark the controller up */
|
|
|
|
sc->aac_state &= ~AAC_STATE_SUSPEND;
|
|
|
|
|
|
|
|
/* enable interrupts now */
|
|
|
|
AAC_UNMASK_INTERRUPTS(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Create a device to represent a new container
|
2001-09-05 20:43:02 +00:00
|
|
|
*/
|
|
|
|
static void
|
2002-04-24 05:12:50 +00:00
|
|
|
aac_add_container(struct aac_softc *sc, struct aac_mntinforesp *mir, int f)
|
2001-09-05 20:43:02 +00:00
|
|
|
{
|
|
|
|
struct aac_container *co;
|
|
|
|
device_t child;
|
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2001-09-05 20:43:02 +00:00
|
|
|
* Check container volume type for validity. Note that many of
|
|
|
|
* the possible types may never show up.
|
|
|
|
*/
|
|
|
|
if ((mir->Status == ST_OK) && (mir->MntTable[0].VolType != CT_NONE)) {
|
2003-02-06 00:37:37 +00:00
|
|
|
co = (struct aac_container *)malloc(sizeof *co, M_AACBUF,
|
|
|
|
M_NOWAIT | M_ZERO);
|
2001-09-05 20:43:02 +00:00
|
|
|
if (co == NULL)
|
2008-03-26 15:28:56 +00:00
|
|
|
panic("Out of memory?!");
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_INIT_B, "id %x name '%.16s' size %u type %d",
|
2001-09-05 20:43:02 +00:00
|
|
|
mir->MntTable[0].ObjectId,
|
|
|
|
mir->MntTable[0].FileSystemName,
|
|
|
|
mir->MntTable[0].Capacity, mir->MntTable[0].VolType);
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2002-04-27 01:31:17 +00:00
|
|
|
if ((child = device_add_child(sc->aac_dev, "aacd", -1)) == NULL)
|
2001-09-05 20:43:02 +00:00
|
|
|
device_printf(sc->aac_dev, "device_add_child failed\n");
|
|
|
|
else
|
|
|
|
device_set_ivars(child, co);
|
|
|
|
device_set_desc(child, aac_describe_code(aac_container_types,
|
|
|
|
mir->MntTable[0].VolType));
|
|
|
|
co->co_disk = child;
|
|
|
|
co->co_found = f;
|
|
|
|
bcopy(&mir->MntTable[0], &co->co_mntobj,
|
|
|
|
sizeof(struct aac_mntobj));
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_container_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
TAILQ_INSERT_TAIL(&sc->aac_container_tqh, co, co_link);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_container_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 16:38:47 +00:00
|
|
|
/*
|
|
|
|
* Allocate resources associated with (sc)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_alloc(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
|
|
|
|
2008-03-24 16:38:47 +00:00
|
|
|
/*
|
|
|
|
* Create DMA tag for mapping buffers into controller-addressable space.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
(sc->flags & AAC_FLAGS_SG_64BIT) ?
|
|
|
|
BUS_SPACE_MAXADDR :
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MAXBSIZE, /* maxsize */
|
|
|
|
sc->aac_sg_tablesize, /* nsegments */
|
|
|
|
MAXBSIZE, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
|
|
|
busdma_lock_mutex, /* lockfunc */
|
|
|
|
&sc->aac_io_lock, /* lockfuncarg */
|
|
|
|
&sc->aac_buffer_dmat)) {
|
|
|
|
device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create DMA tag for mapping FIBs into controller-addressable space..
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
(sc->flags & AAC_FLAGS_4GB_WINDOW) ?
|
|
|
|
BUS_SPACE_MAXADDR_32BIT :
|
|
|
|
0x7fffffff, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
sc->aac_max_fibs_alloc *
|
|
|
|
sc->aac_max_fib_size, /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
sc->aac_max_fibs_alloc *
|
|
|
|
sc->aac_max_fib_size, /* maxsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* No locking needed */
|
|
|
|
&sc->aac_fib_dmat)) {
|
2010-01-07 21:01:37 +00:00
|
|
|
device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n");
|
2008-03-24 16:38:47 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create DMA tag for the common structure and allocate it.
|
|
|
|
*/
|
|
|
|
if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
|
|
|
|
1, 0, /* algnmnt, boundary */
|
|
|
|
(sc->flags & AAC_FLAGS_4GB_WINDOW) ?
|
|
|
|
BUS_SPACE_MAXADDR_32BIT :
|
|
|
|
0x7fffffff, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
8192 + sizeof(struct aac_common), /* maxsize */
|
|
|
|
1, /* nsegments */
|
|
|
|
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* No locking needed */
|
|
|
|
&sc->aac_common_dmat)) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"can't allocate common structure DMA tag\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common,
|
|
|
|
BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) {
|
|
|
|
device_printf(sc->aac_dev, "can't allocate common structure\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work around a bug in the 2120 and 2200 that cannot DMA commands
|
|
|
|
* below address 8192 in physical memory.
|
|
|
|
* XXX If the padding is not needed, can it be put to use instead
|
|
|
|
* of ignored?
|
|
|
|
*/
|
|
|
|
(void)bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap,
|
|
|
|
sc->aac_common, 8192 + sizeof(*sc->aac_common),
|
|
|
|
aac_common_map, sc, 0);
|
|
|
|
|
|
|
|
if (sc->aac_common_busaddr < 8192) {
|
|
|
|
sc->aac_common = (struct aac_common *)
|
|
|
|
((uint8_t *)sc->aac_common + 8192);
|
|
|
|
sc->aac_common_busaddr += 8192;
|
|
|
|
}
|
|
|
|
bzero(sc->aac_common, sizeof(*sc->aac_common));
|
|
|
|
|
|
|
|
/* Allocate some FIBs and associated command structs */
|
|
|
|
TAILQ_INIT(&sc->aac_fibmap_tqh);
|
|
|
|
sc->aac_commands = malloc(sc->aac_max_fibs * sizeof(struct aac_command),
|
|
|
|
M_AACBUF, M_WAITOK|M_ZERO);
|
2009-12-08 05:35:51 +00:00
|
|
|
while (sc->total_fibs < sc->aac_max_fibs) {
|
2008-03-24 16:38:47 +00:00
|
|
|
if (aac_alloc_commands(sc) != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sc->total_fibs == 0)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Free all of the resources associated with (sc)
|
|
|
|
*
|
|
|
|
* Should not be called if the controller is active.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
aac_free(struct aac_softc *sc)
|
|
|
|
{
|
2003-02-10 00:34:24 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* remove the control device */
|
|
|
|
if (sc->aac_dev_t != NULL)
|
|
|
|
destroy_dev(sc->aac_dev_t);
|
|
|
|
|
|
|
|
/* throw away any FIB buffers, discard the FIB DMA tag */
|
2003-02-19 21:38:29 +00:00
|
|
|
aac_free_commands(sc);
|
2001-09-05 20:43:02 +00:00
|
|
|
if (sc->aac_fib_dmat)
|
|
|
|
bus_dma_tag_destroy(sc->aac_fib_dmat);
|
|
|
|
|
2003-02-10 00:34:24 +00:00
|
|
|
free(sc->aac_commands, M_AACBUF);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* destroy the common area */
|
|
|
|
if (sc->aac_common) {
|
|
|
|
bus_dmamap_unload(sc->aac_common_dmat, sc->aac_common_dmamap);
|
|
|
|
bus_dmamem_free(sc->aac_common_dmat, sc->aac_common,
|
|
|
|
sc->aac_common_dmamap);
|
|
|
|
}
|
|
|
|
if (sc->aac_common_dmat)
|
|
|
|
bus_dma_tag_destroy(sc->aac_common_dmat);
|
|
|
|
|
|
|
|
/* disconnect the interrupt handler */
|
|
|
|
if (sc->aac_intr)
|
|
|
|
bus_teardown_intr(sc->aac_dev, sc->aac_irq, sc->aac_intr);
|
|
|
|
if (sc->aac_irq != NULL)
|
|
|
|
bus_release_resource(sc->aac_dev, SYS_RES_IRQ, sc->aac_irq_rid,
|
|
|
|
sc->aac_irq);
|
|
|
|
|
|
|
|
/* destroy data-transfer DMA tag */
|
|
|
|
if (sc->aac_buffer_dmat)
|
|
|
|
bus_dma_tag_destroy(sc->aac_buffer_dmat);
|
|
|
|
|
|
|
|
/* destroy the parent DMA tag */
|
|
|
|
if (sc->aac_parent_dmat)
|
|
|
|
bus_dma_tag_destroy(sc->aac_parent_dmat);
|
|
|
|
|
|
|
|
/* release the register window mapping */
|
2009-02-21 15:40:03 +00:00
|
|
|
if (sc->aac_regs_res0 != NULL)
|
|
|
|
bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
|
|
|
|
sc->aac_regs_rid0, sc->aac_regs_res0);
|
|
|
|
if (sc->aac_hwif == AAC_HWIF_NARK && sc->aac_regs_res1 != NULL)
|
2001-09-05 20:43:02 +00:00
|
|
|
bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
|
2009-02-21 15:40:03 +00:00
|
|
|
sc->aac_regs_rid1, sc->aac_regs_res1);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Disconnect from the controller completely, in preparation for unload.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aac_detach(device_t dev)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2003-02-05 23:24:25 +00:00
|
|
|
struct aac_container *co;
|
|
|
|
struct aac_sim *sim;
|
2001-09-05 20:43:02 +00:00
|
|
|
int error;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = device_get_softc(dev);
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
callout_drain(&sc->aac_daemontime);
|
|
|
|
|
2011-06-10 20:23:56 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
while (sc->aifflags & AAC_AIFFLAGS_RUNNING) {
|
|
|
|
sc->aifflags |= AAC_AIFFLAGS_EXIT;
|
|
|
|
wakeup(sc->aifthread);
|
|
|
|
msleep(sc->aac_dev, &sc->aac_io_lock, PUSER, "aacdch", 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
KASSERT((sc->aifflags & AAC_AIFFLAGS_RUNNING) == 0,
|
|
|
|
("%s: invalid detach state", __func__));
|
|
|
|
|
2003-02-05 23:24:25 +00:00
|
|
|
/* Remove the child containers */
|
2003-02-06 00:37:37 +00:00
|
|
|
while ((co = TAILQ_FIRST(&sc->aac_container_tqh)) != NULL) {
|
2003-02-05 23:24:25 +00:00
|
|
|
error = device_delete_child(dev, co->co_disk);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-02-20 23:13:48 +00:00
|
|
|
TAILQ_REMOVE(&sc->aac_container_tqh, co, co_link);
|
2003-02-06 00:37:37 +00:00
|
|
|
free(co, M_AACBUF);
|
2003-02-05 23:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the CAM SIMs */
|
2003-02-06 00:37:37 +00:00
|
|
|
while ((sim = TAILQ_FIRST(&sc->aac_sim_tqh)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&sc->aac_sim_tqh, sim, sim_link);
|
2003-02-05 23:24:25 +00:00
|
|
|
error = device_delete_child(dev, sim->sim_dev);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-02-06 00:37:37 +00:00
|
|
|
free(sim, M_AACBUF);
|
2003-02-05 23:24:25 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if ((error = aac_shutdown(dev)))
|
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-06 00:07:12 +00:00
|
|
|
EVENTHANDLER_DEREGISTER(shutdown_final, sc->eh);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
aac_free(sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2004-08-12 05:31:17 +00:00
|
|
|
mtx_destroy(&sc->aac_aifq_lock);
|
|
|
|
mtx_destroy(&sc->aac_io_lock);
|
|
|
|
mtx_destroy(&sc->aac_container_lock);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Bring the controller down to a dormant state and detach all child devices.
|
|
|
|
*
|
|
|
|
* This function is called before detach or system shutdown.
|
|
|
|
*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Note that we can assume that the bioq on the controller is empty, as we won't
|
2000-09-13 03:20:35 +00:00
|
|
|
* allow shutdown if any device is open.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aac_shutdown(device_t dev)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2002-04-24 05:12:50 +00:00
|
|
|
struct aac_fib *fib;
|
|
|
|
struct aac_close_command *cc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = device_get_softc(dev);
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_state |= AAC_STATE_SUSPEND;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2001-09-05 20:43:02 +00:00
|
|
|
* Send a Container shutdown followed by a HostShutdown FIB to the
|
|
|
|
* controller to convince it that we don't want to talk to it anymore.
|
|
|
|
* We've been closed and all I/O completed already
|
2001-08-29 23:34:05 +00:00
|
|
|
*/
|
2001-09-05 20:43:02 +00:00
|
|
|
device_printf(sc->aac_dev, "shutting down controller...");
|
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-06-02 18:15:48 +00:00
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
2002-04-24 05:12:50 +00:00
|
|
|
cc = (struct aac_close_command *)&fib->data[0];
|
|
|
|
|
2002-05-03 00:07:50 +00:00
|
|
|
bzero(cc, sizeof(struct aac_close_command));
|
2002-04-24 05:12:50 +00:00
|
|
|
cc->Command = VM_CloseAll;
|
|
|
|
cc->ContainerId = 0xffffffff;
|
|
|
|
if (aac_sync_fib(sc, ContainerCommand, 0, fib,
|
|
|
|
sizeof(struct aac_close_command)))
|
2001-09-05 20:43:02 +00:00
|
|
|
printf("FAILED.\n");
|
2003-02-05 23:24:25 +00:00
|
|
|
else
|
|
|
|
printf("done\n");
|
|
|
|
#if 0
|
2001-09-05 20:43:02 +00:00
|
|
|
else {
|
2002-04-24 05:12:50 +00:00
|
|
|
fib->data[0] = 0;
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* XXX Issuing this command to the controller makes it shut down
|
|
|
|
* but also keeps it from coming back up without a reset of the
|
|
|
|
* PCI bus. This is not desirable if you are just unloading the
|
|
|
|
* driver module with the intent to reload it later.
|
|
|
|
*/
|
2002-04-24 05:12:50 +00:00
|
|
|
if (aac_sync_fib(sc, FsaHostShutdown, AAC_FIBSTATE_SHUTDOWN,
|
|
|
|
fib, 1)) {
|
2001-09-05 20:43:02 +00:00
|
|
|
printf("FAILED.\n");
|
|
|
|
} else {
|
|
|
|
printf("done.\n");
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
2003-02-05 23:24:25 +00:00
|
|
|
#endif
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
AAC_MASK_INTERRUPTS(sc);
|
2004-08-12 04:47:32 +00:00
|
|
|
aac_release_sync_fib(sc);
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Bring the controller to a quiescent state, ready for system suspend.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aac_suspend(device_t dev)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_state |= AAC_STATE_SUSPEND;
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
AAC_MASK_INTERRUPTS(sc);
|
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Bring the controller back to a state ready for operation.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aac_resume(device_t dev)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_state &= ~AAC_STATE_SUSPEND;
|
|
|
|
AAC_UNMASK_INTERRUPTS(sc);
|
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2005-10-08 15:55:09 +00:00
|
|
|
* Interrupt handler for NEW_COMM interface.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
void
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_new_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct aac_softc *sc;
|
|
|
|
u_int32_t index, fast;
|
|
|
|
struct aac_command *cm;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = (struct aac_softc *)arg;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
while (1) {
|
|
|
|
index = AAC_GET_OUTB_QUEUE(sc);
|
|
|
|
if (index == 0xffffffff)
|
|
|
|
index = AAC_GET_OUTB_QUEUE(sc);
|
|
|
|
if (index == 0xffffffff)
|
|
|
|
break;
|
|
|
|
if (index & 2) {
|
|
|
|
if (index == 0xfffffffe) {
|
|
|
|
/* XXX This means that the controller wants
|
|
|
|
* more work. Ignore it for now.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* AIF */
|
|
|
|
fib = (struct aac_fib *)malloc(sizeof *fib, M_AACBUF,
|
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (fib == NULL) {
|
|
|
|
/* If we're really this short on memory,
|
|
|
|
* hopefully breaking out of the handler will
|
|
|
|
* allow something to get freed. This
|
|
|
|
* actually sucks a whole lot.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index &= ~2;
|
|
|
|
for (i = 0; i < sizeof(struct aac_fib)/4; ++i)
|
2009-02-21 15:40:03 +00:00
|
|
|
((u_int32_t *)fib)[i] = AAC_MEM1_GETREG4(sc, index + i*4);
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_handle_aif(sc, fib);
|
|
|
|
free(fib, M_AACBUF);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AIF memory is owned by the adapter, so let it
|
|
|
|
* know that we are done with it.
|
|
|
|
*/
|
|
|
|
AAC_SET_OUTB_QUEUE(sc, index);
|
|
|
|
AAC_CLEAR_ISTATUS(sc, AAC_DB_RESPONSE_READY);
|
|
|
|
} else {
|
|
|
|
fast = index & 1;
|
|
|
|
cm = sc->aac_commands + (index >> 2);
|
|
|
|
fib = cm->cm_fib;
|
|
|
|
if (fast) {
|
|
|
|
fib->Header.XferState |= AAC_FIBSTATE_DONEADAP;
|
|
|
|
*((u_int32_t *)(fib->data)) = AAC_ERROR_NORMAL;
|
|
|
|
}
|
|
|
|
aac_remove_busy(cm);
|
|
|
|
aac_unmap_command(cm);
|
|
|
|
cm->cm_flags |= AAC_CMD_COMPLETED;
|
|
|
|
|
|
|
|
/* is there a completion handler? */
|
|
|
|
if (cm->cm_complete != NULL) {
|
|
|
|
cm->cm_complete(cm);
|
|
|
|
} else {
|
|
|
|
/* assume that someone is sleeping on this
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
wakeup(cm);
|
|
|
|
}
|
|
|
|
sc->flags &= ~AAC_QUEUE_FRZN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* see if we can start some more I/O */
|
|
|
|
if ((sc->flags & AAC_QUEUE_FRZN) == 0)
|
|
|
|
aac_startio(sc);
|
|
|
|
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
}
|
|
|
|
|
2009-10-29 14:53:45 +00:00
|
|
|
/*
|
|
|
|
* Interrupt filter for !NEW_COMM interface.
|
|
|
|
*/
|
2007-02-23 12:19:07 +00:00
|
|
|
int
|
2009-10-29 14:53:45 +00:00
|
|
|
aac_filter(void *arg)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2003-02-05 23:24:25 +00:00
|
|
|
u_int16_t reason;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = (struct aac_softc *)arg;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2003-01-11 01:59:21 +00:00
|
|
|
/*
|
2004-01-30 07:04:39 +00:00
|
|
|
* Read the status register directly. This is faster than taking the
|
|
|
|
* driver lock and reading the queues directly. It also saves having
|
|
|
|
* to turn parts of the driver lock into a spin mutex, which would be
|
|
|
|
* ugly.
|
2003-01-11 01:59:21 +00:00
|
|
|
*/
|
2004-01-30 07:04:39 +00:00
|
|
|
reason = AAC_GET_ISTATUS(sc);
|
2003-01-11 01:59:21 +00:00
|
|
|
AAC_CLEAR_ISTATUS(sc, reason);
|
|
|
|
|
2004-01-30 07:04:39 +00:00
|
|
|
/* handle completion processing */
|
2003-01-11 01:59:21 +00:00
|
|
|
if (reason & AAC_DB_RESPONSE_READY)
|
2004-01-30 07:04:39 +00:00
|
|
|
taskqueue_enqueue_fast(taskqueue_fast, &sc->aac_task_complete);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2004-01-30 07:04:39 +00:00
|
|
|
/* controller wants to talk to us */
|
|
|
|
if (reason & (AAC_DB_PRINTF | AAC_DB_COMMAND_READY)) {
|
|
|
|
/*
|
|
|
|
* XXX Make sure that we don't get fooled by strange messages
|
|
|
|
* that start with a NULL.
|
|
|
|
*/
|
|
|
|
if ((reason & AAC_DB_PRINTF) &&
|
2005-10-08 15:55:09 +00:00
|
|
|
(sc->aac_common->ac_printf[0] == 0))
|
2004-01-30 07:04:39 +00:00
|
|
|
sc->aac_common->ac_printf[0] = 32;
|
2003-02-05 23:24:25 +00:00
|
|
|
|
2004-01-30 07:04:39 +00:00
|
|
|
/*
|
|
|
|
* This might miss doing the actual wakeup. However, the
|
2004-02-07 03:26:38 +00:00
|
|
|
* msleep that this is waking up has a timeout, so it will
|
2004-01-30 07:04:39 +00:00
|
|
|
* wake up eventually. AIFs and printfs are low enough
|
|
|
|
* priority that they can handle hanging out for a few seconds
|
|
|
|
* if needed.
|
|
|
|
*/
|
2003-02-05 23:24:25 +00:00
|
|
|
wakeup(sc->aifthread);
|
2004-01-30 07:04:39 +00:00
|
|
|
}
|
2007-02-23 12:19:07 +00:00
|
|
|
return (FILTER_HANDLED);
|
2003-01-11 01:59:21 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Command Processing
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Start as much queued I/O as possible on the controller
|
|
|
|
*/
|
2002-04-27 01:31:17 +00:00
|
|
|
void
|
2000-09-13 03:20:35 +00:00
|
|
|
aac_startio(struct aac_softc *sc)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
2004-06-01 05:32:26 +00:00
|
|
|
int error;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
for (;;) {
|
2004-06-01 05:32:26 +00:00
|
|
|
/*
|
|
|
|
* This flag might be set if the card is out of resources.
|
|
|
|
* Checking it here prevents an infinite loop of deferrals.
|
|
|
|
*/
|
|
|
|
if (sc->flags & AAC_QUEUE_FRZN)
|
|
|
|
break;
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2005-11-13 17:26:36 +00:00
|
|
|
* Try to get a command that's been put off for lack of
|
2001-09-05 20:43:02 +00:00
|
|
|
* resources
|
|
|
|
*/
|
|
|
|
cm = aac_dequeue_ready(sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2005-11-13 17:26:36 +00:00
|
|
|
* Try to build a command off the bio queue (ignore error
|
2001-09-05 20:43:02 +00:00
|
|
|
* return)
|
|
|
|
*/
|
|
|
|
if (cm == NULL)
|
|
|
|
aac_bio_command(sc, &cm);
|
|
|
|
|
|
|
|
/* nothing to do? */
|
|
|
|
if (cm == NULL)
|
|
|
|
break;
|
|
|
|
|
2004-06-01 05:32:26 +00:00
|
|
|
/* don't map more than once */
|
|
|
|
if (cm->cm_flags & AAC_CMD_MAPPED)
|
|
|
|
panic("aac: command %p already mapped", cm);
|
|
|
|
|
2004-02-07 10:30:22 +00:00
|
|
|
/*
|
2004-06-01 05:32:26 +00:00
|
|
|
* Set up the command to go to the controller. If there are no
|
|
|
|
* data buffers associated with the command then it can bypass
|
|
|
|
* busdma.
|
2004-02-07 10:30:22 +00:00
|
|
|
*/
|
2004-06-01 05:32:26 +00:00
|
|
|
if (cm->cm_datalen != 0) {
|
|
|
|
error = bus_dmamap_load(sc->aac_buffer_dmat,
|
|
|
|
cm->cm_datamap, cm->cm_data,
|
|
|
|
cm->cm_datalen,
|
|
|
|
aac_map_command_sg, cm, 0);
|
|
|
|
if (error == EINPROGRESS) {
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_COMM_B, "freezing queue\n");
|
2004-06-01 05:32:26 +00:00
|
|
|
sc->flags |= AAC_QUEUE_FRZN;
|
|
|
|
error = 0;
|
2004-06-01 15:50:11 +00:00
|
|
|
} else if (error != 0)
|
2004-06-01 05:32:26 +00:00
|
|
|
panic("aac_startio: unexpected error %d from "
|
2008-03-26 15:28:56 +00:00
|
|
|
"busdma", error);
|
2004-06-01 05:32:26 +00:00
|
|
|
} else
|
|
|
|
aac_map_command_sg(cm, NULL, 0, 0);
|
2003-07-09 21:16:23 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Handle notification of one or more FIBs coming from the controller.
|
|
|
|
*/
|
|
|
|
static void
|
2003-02-05 23:24:25 +00:00
|
|
|
aac_command_thread(struct aac_softc *sc)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_fib *fib;
|
|
|
|
u_int32_t fib_size;
|
2004-01-30 07:04:39 +00:00
|
|
|
int size, retval;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-02-07 03:26:38 +00:00
|
|
|
sc->aifflags = AAC_AIFFLAGS_RUNNING;
|
|
|
|
|
|
|
|
while ((sc->aifflags & AAC_AIFFLAGS_EXIT) == 0) {
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2004-02-07 03:26:38 +00:00
|
|
|
retval = 0;
|
|
|
|
if ((sc->aifflags & AAC_AIFFLAGS_PENDING) == 0)
|
|
|
|
retval = msleep(sc->aifthread, &sc->aac_io_lock, PRIBIO,
|
|
|
|
"aifthd", AAC_PERIODIC_INTERVAL * hz);
|
2003-02-05 23:24:25 +00:00
|
|
|
|
2004-01-30 07:04:39 +00:00
|
|
|
/*
|
|
|
|
* First see if any FIBs need to be allocated. This needs
|
|
|
|
* to be called without the driver lock because contigmalloc
|
2011-06-10 20:23:56 +00:00
|
|
|
* can sleep.
|
2004-01-30 07:04:39 +00:00
|
|
|
*/
|
2003-02-26 04:46:21 +00:00
|
|
|
if ((sc->aifflags & AAC_AIFFLAGS_ALLOCFIBS) != 0) {
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2004-02-07 03:26:38 +00:00
|
|
|
aac_alloc_commands(sc);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-02-07 10:30:22 +00:00
|
|
|
sc->aifflags &= ~AAC_AIFFLAGS_ALLOCFIBS;
|
2004-02-07 03:26:38 +00:00
|
|
|
aac_startio(sc);
|
2003-02-26 04:46:21 +00:00
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2004-01-30 07:04:39 +00:00
|
|
|
/*
|
|
|
|
* While we're here, check to see if any commands are stuck.
|
|
|
|
* This is pretty low-priority, so it's ok if it doesn't
|
|
|
|
* always fire.
|
|
|
|
*/
|
|
|
|
if (retval == EWOULDBLOCK)
|
|
|
|
aac_timeout(sc);
|
|
|
|
|
|
|
|
/* Check the hardware printf message buffer */
|
|
|
|
if (sc->aac_common->ac_printf[0] != 0)
|
|
|
|
aac_print_printf(sc);
|
|
|
|
|
|
|
|
/* Also check to see if the adapter has a command for us. */
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM)
|
|
|
|
continue;
|
|
|
|
for (;;) {
|
|
|
|
if (aac_dequeue_fib(sc, AAC_HOST_NORM_CMD_QUEUE,
|
2005-11-13 17:26:36 +00:00
|
|
|
&fib_size, &fib))
|
2005-10-08 15:55:09 +00:00
|
|
|
break;
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
AAC_PRINT_FIB(sc, fib);
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
switch (fib->Header.Command) {
|
|
|
|
case AifRequest:
|
|
|
|
aac_handle_aif(sc, fib);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(sc->aac_dev, "unknown command "
|
|
|
|
"from controller\n");
|
|
|
|
break;
|
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if ((fib->Header.XferState == 0) ||
|
2005-10-08 15:55:09 +00:00
|
|
|
(fib->Header.StructType != AAC_FIBTYPE_TFIB)) {
|
2001-09-05 20:43:02 +00:00
|
|
|
break;
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2003-02-05 23:24:25 +00:00
|
|
|
/* Return the AIF to the controller. */
|
2001-09-05 20:43:02 +00:00
|
|
|
if (fib->Header.XferState & AAC_FIBSTATE_FROMADAP) {
|
|
|
|
fib->Header.XferState |= AAC_FIBSTATE_DONEHOST;
|
|
|
|
*(AAC_FSAStatus*)fib->data = ST_OK;
|
|
|
|
|
|
|
|
/* XXX Compute the Size field? */
|
|
|
|
size = fib->Header.Size;
|
|
|
|
if (size > sizeof(struct aac_fib)) {
|
2002-04-27 01:31:17 +00:00
|
|
|
size = sizeof(struct aac_fib);
|
2001-09-05 20:43:02 +00:00
|
|
|
fib->Header.Size = size;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Since we did not generate this command, it
|
|
|
|
* cannot go through the normal
|
|
|
|
* enqueue->startio chain.
|
|
|
|
*/
|
|
|
|
aac_enqueue_response(sc,
|
2005-10-08 15:55:09 +00:00
|
|
|
AAC_ADAP_NORM_RESP_QUEUE,
|
|
|
|
fib);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
sc->aifflags &= ~AAC_AIFFLAGS_RUNNING;
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
wakeup(sc->aac_dev);
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2007-10-20 23:23:23 +00:00
|
|
|
kproc_exit(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2003-02-19 21:58:34 +00:00
|
|
|
* Process completed commands.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-02-19 21:58:34 +00:00
|
|
|
aac_complete(void *context, int pending)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2003-02-19 21:58:34 +00:00
|
|
|
struct aac_softc *sc;
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
u_int32_t fib_size;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-19 21:58:34 +00:00
|
|
|
sc = (struct aac_softc *)context;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2003-02-19 21:58:34 +00:00
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2003-02-26 04:46:21 +00:00
|
|
|
|
2003-02-19 21:58:34 +00:00
|
|
|
/* pull completed commands off the queue */
|
2001-09-05 20:43:02 +00:00
|
|
|
for (;;) {
|
|
|
|
/* look for completed FIBs on our queue */
|
|
|
|
if (aac_dequeue_fib(sc, AAC_HOST_NORM_RESP_QUEUE, &fib_size,
|
2005-10-08 15:55:09 +00:00
|
|
|
&fib))
|
2001-09-05 20:43:02 +00:00
|
|
|
break; /* nothing to do */
|
2003-02-19 21:58:34 +00:00
|
|
|
|
2004-02-07 17:40:38 +00:00
|
|
|
/* get the command, unmap and hand off for processing */
|
2003-02-19 23:33:56 +00:00
|
|
|
cm = sc->aac_commands + fib->Header.SenderData;
|
2001-09-05 20:43:02 +00:00
|
|
|
if (cm == NULL) {
|
|
|
|
AAC_PRINT_FIB(sc, fib);
|
2003-02-19 21:58:34 +00:00
|
|
|
break;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2010-09-14 01:51:04 +00:00
|
|
|
if ((cm->cm_flags & AAC_CMD_TIMEDOUT) != 0)
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"COMMAND %p COMPLETED AFTER %d SECONDS\n",
|
|
|
|
cm, (int)(time_uptime-cm->cm_timestamp));
|
|
|
|
|
2003-02-19 21:58:34 +00:00
|
|
|
aac_remove_busy(cm);
|
2005-10-08 15:55:09 +00:00
|
|
|
|
|
|
|
aac_unmap_command(cm);
|
2001-09-05 20:43:02 +00:00
|
|
|
cm->cm_flags |= AAC_CMD_COMPLETED;
|
|
|
|
|
|
|
|
/* is there a completion handler? */
|
|
|
|
if (cm->cm_complete != NULL) {
|
|
|
|
cm->cm_complete(cm);
|
|
|
|
} else {
|
|
|
|
/* assume that someone is sleeping on this command */
|
|
|
|
wakeup(cm);
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
2000-12-27 13:14:56 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* see if we can start some more I/O */
|
2003-07-09 21:16:23 +00:00
|
|
|
sc->flags &= ~AAC_QUEUE_FRZN;
|
2001-09-05 20:43:02 +00:00
|
|
|
aac_startio(sc);
|
2003-02-26 04:46:21 +00:00
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Handle a bio submitted from a disk device.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
aac_submit_bio(struct bio *bp)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_disk *ad;
|
|
|
|
struct aac_softc *sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-26 02:50:27 +00:00
|
|
|
ad = (struct aac_disk *)bp->bio_disk->d_drv1;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = ad->ad_controller;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* queue the BIO and try to get some work done */
|
|
|
|
aac_enqueue_bio(sc, bp);
|
|
|
|
aac_startio(sc);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Get a bio and build a command to go with it.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_bio_command(struct aac_softc *sc, struct aac_command **cmp)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
struct aac_disk *ad;
|
|
|
|
struct bio *bp;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* get the resources we will need */
|
|
|
|
cm = NULL;
|
2004-02-07 03:26:38 +00:00
|
|
|
bp = NULL;
|
2001-09-05 20:43:02 +00:00
|
|
|
if (aac_alloc_command(sc, &cm)) /* get a command */
|
|
|
|
goto fail;
|
2004-02-07 03:26:38 +00:00
|
|
|
if ((bp = aac_dequeue_bio(sc)) == NULL)
|
|
|
|
goto fail;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* fill out the command */
|
|
|
|
cm->cm_data = (void *)bp->bio_data;
|
|
|
|
cm->cm_datalen = bp->bio_bcount;
|
|
|
|
cm->cm_complete = aac_bio_complete;
|
|
|
|
cm->cm_private = bp;
|
2005-09-14 05:46:28 +00:00
|
|
|
cm->cm_timestamp = time_uptime;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* build the FIB */
|
|
|
|
fib = cm->cm_fib;
|
2003-03-30 21:47:16 +00:00
|
|
|
fib->Header.Size = sizeof(struct aac_fib_header);
|
2005-11-13 17:26:36 +00:00
|
|
|
fib->Header.XferState =
|
|
|
|
AAC_FIBSTATE_HOSTOWNED |
|
|
|
|
AAC_FIBSTATE_INITIALISED |
|
|
|
|
AAC_FIBSTATE_EMPTY |
|
2003-01-11 01:59:21 +00:00
|
|
|
AAC_FIBSTATE_FROMHOST |
|
|
|
|
AAC_FIBSTATE_REXPECTED |
|
|
|
|
AAC_FIBSTATE_NORM |
|
|
|
|
AAC_FIBSTATE_ASYNC |
|
|
|
|
AAC_FIBSTATE_FAST_RESPONSE;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* build the read/write request */
|
2003-02-26 02:50:27 +00:00
|
|
|
ad = (struct aac_disk *)bp->bio_disk->d_drv1;
|
2003-03-30 21:47:16 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_RAW_IO) {
|
|
|
|
struct aac_raw_io *raw;
|
|
|
|
raw = (struct aac_raw_io *)&fib->data[0];
|
|
|
|
fib->Header.Command = RawIo;
|
|
|
|
raw->BlockNumber = (u_int64_t)bp->bio_pblkno;
|
|
|
|
raw->ByteCount = bp->bio_bcount;
|
|
|
|
raw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
|
|
|
|
raw->BpTotal = 0;
|
|
|
|
raw->BpComplete = 0;
|
|
|
|
fib->Header.Size += sizeof(struct aac_raw_io);
|
|
|
|
cm->cm_sgtable = (struct aac_sg_table *)&raw->SgMapRaw;
|
|
|
|
if (bp->bio_cmd == BIO_READ) {
|
|
|
|
raw->Flags = 1;
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAIN;
|
|
|
|
} else {
|
|
|
|
raw->Flags = 0;
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAOUT;
|
|
|
|
}
|
|
|
|
} else if ((sc->flags & AAC_FLAGS_SG_64BIT) == 0) {
|
2003-03-30 21:47:16 +00:00
|
|
|
fib->Header.Command = ContainerCommand;
|
|
|
|
if (bp->bio_cmd == BIO_READ) {
|
|
|
|
struct aac_blockread *br;
|
|
|
|
br = (struct aac_blockread *)&fib->data[0];
|
|
|
|
br->Command = VM_CtBlockRead;
|
|
|
|
br->ContainerId = ad->ad_container->co_mntobj.ObjectId;
|
|
|
|
br->BlockNumber = bp->bio_pblkno;
|
|
|
|
br->ByteCount = bp->bio_bcount;
|
|
|
|
fib->Header.Size += sizeof(struct aac_blockread);
|
|
|
|
cm->cm_sgtable = &br->SgMap;
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAIN;
|
|
|
|
} else {
|
|
|
|
struct aac_blockwrite *bw;
|
|
|
|
bw = (struct aac_blockwrite *)&fib->data[0];
|
|
|
|
bw->Command = VM_CtBlockWrite;
|
|
|
|
bw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
|
|
|
|
bw->BlockNumber = bp->bio_pblkno;
|
|
|
|
bw->ByteCount = bp->bio_bcount;
|
|
|
|
bw->Stable = CUNSTABLE;
|
|
|
|
fib->Header.Size += sizeof(struct aac_blockwrite);
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAOUT;
|
|
|
|
cm->cm_sgtable = &bw->SgMap;
|
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
} else {
|
2003-03-30 21:47:16 +00:00
|
|
|
fib->Header.Command = ContainerCommand64;
|
|
|
|
if (bp->bio_cmd == BIO_READ) {
|
|
|
|
struct aac_blockread64 *br;
|
|
|
|
br = (struct aac_blockread64 *)&fib->data[0];
|
|
|
|
br->Command = VM_CtHostRead64;
|
|
|
|
br->ContainerId = ad->ad_container->co_mntobj.ObjectId;
|
|
|
|
br->SectorCount = bp->bio_bcount / AAC_BLOCK_SIZE;
|
|
|
|
br->BlockNumber = bp->bio_pblkno;
|
|
|
|
br->Pad = 0;
|
|
|
|
br->Flags = 0;
|
|
|
|
fib->Header.Size += sizeof(struct aac_blockread64);
|
2008-03-25 18:34:04 +00:00
|
|
|
cm->cm_flags |= AAC_CMD_DATAIN;
|
2004-07-28 06:21:53 +00:00
|
|
|
cm->cm_sgtable = (struct aac_sg_table *)&br->SgMap64;
|
2003-03-30 21:47:16 +00:00
|
|
|
} else {
|
|
|
|
struct aac_blockwrite64 *bw;
|
|
|
|
bw = (struct aac_blockwrite64 *)&fib->data[0];
|
|
|
|
bw->Command = VM_CtHostWrite64;
|
|
|
|
bw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
|
|
|
|
bw->SectorCount = bp->bio_bcount / AAC_BLOCK_SIZE;
|
|
|
|
bw->BlockNumber = bp->bio_pblkno;
|
|
|
|
bw->Pad = 0;
|
|
|
|
bw->Flags = 0;
|
|
|
|
fib->Header.Size += sizeof(struct aac_blockwrite64);
|
2008-03-25 18:34:04 +00:00
|
|
|
cm->cm_flags |= AAC_CMD_DATAOUT;
|
2004-07-28 06:21:53 +00:00
|
|
|
cm->cm_sgtable = (struct aac_sg_table *)&bw->SgMap64;
|
2003-03-30 21:47:16 +00:00
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
*cmp = cm;
|
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
fail:
|
2005-10-08 15:55:09 +00:00
|
|
|
if (bp != NULL)
|
|
|
|
aac_enqueue_bio(sc, bp);
|
2001-09-05 20:43:02 +00:00
|
|
|
if (cm != NULL)
|
|
|
|
aac_release_command(cm);
|
|
|
|
return(ENOMEM);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Handle a bio-instigated command that has been completed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_bio_complete(struct aac_command *cm)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_blockread_response *brr;
|
|
|
|
struct aac_blockwrite_response *bwr;
|
|
|
|
struct bio *bp;
|
|
|
|
AAC_FSAStatus status;
|
|
|
|
|
|
|
|
/* fetch relevant status and then release the command */
|
|
|
|
bp = (struct bio *)cm->cm_private;
|
2003-03-01 05:07:19 +00:00
|
|
|
if (bp->bio_cmd == BIO_READ) {
|
2001-09-05 20:43:02 +00:00
|
|
|
brr = (struct aac_blockread_response *)&cm->cm_fib->data[0];
|
|
|
|
status = brr->Status;
|
|
|
|
} else {
|
|
|
|
bwr = (struct aac_blockwrite_response *)&cm->cm_fib->data[0];
|
|
|
|
status = bwr->Status;
|
|
|
|
}
|
|
|
|
aac_release_command(cm);
|
|
|
|
|
|
|
|
/* fix up the bio based on status */
|
|
|
|
if (status == ST_OK) {
|
|
|
|
bp->bio_resid = 0;
|
|
|
|
} else {
|
|
|
|
bp->bio_error = EIO;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
/* pass an error string out to the disk layer */
|
|
|
|
bp->bio_driver1 = aac_describe_code(aac_command_status_table,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
aac_biodone(bp);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Submit a command to the controller, return when it completes.
|
2001-12-02 03:47:33 +00:00
|
|
|
* XXX This is very dangerous! If the card has gone out to lunch, we could
|
|
|
|
* be stuck here forever. At the same time, signals are not caught
|
2004-04-14 19:11:29 +00:00
|
|
|
* because there is a risk that a signal could wakeup the sleep before
|
|
|
|
* the card has a chance to complete the command. Since there is no way
|
|
|
|
* to cancel a command that is in progress, we can't protect against the
|
|
|
|
* card completing a command late and spamming the command and data
|
|
|
|
* memory. So, we are held hostage until the command completes.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static int
|
2004-04-14 19:11:29 +00:00
|
|
|
aac_wait_command(struct aac_command *cm)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2003-02-26 04:46:21 +00:00
|
|
|
struct aac_softc *sc;
|
2004-04-14 19:11:29 +00:00
|
|
|
int error;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2003-02-26 04:46:21 +00:00
|
|
|
sc = cm->cm_sc;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2003-02-26 04:46:21 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Put the command on the ready queue and get things going */
|
|
|
|
aac_enqueue_ready(cm);
|
2003-02-26 04:46:21 +00:00
|
|
|
aac_startio(sc);
|
2004-04-14 19:11:29 +00:00
|
|
|
error = msleep(cm, &sc->aac_io_lock, PRIBIO, "aacwait", 0);
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
*Command Buffer Management
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Allocate a command.
|
|
|
|
*/
|
2002-04-27 01:31:17 +00:00
|
|
|
int
|
2000-09-13 03:20:35 +00:00
|
|
|
aac_alloc_command(struct aac_softc *sc, struct aac_command **cmp)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-10 00:34:24 +00:00
|
|
|
if ((cm = aac_dequeue_free(sc)) == NULL) {
|
2003-03-30 21:47:16 +00:00
|
|
|
if (sc->total_fibs < sc->aac_max_fibs) {
|
2011-06-10 20:23:56 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2003-03-30 21:47:16 +00:00
|
|
|
sc->aifflags |= AAC_AIFFLAGS_ALLOCFIBS;
|
2011-06-10 20:23:56 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2003-03-30 21:47:16 +00:00
|
|
|
wakeup(sc->aifthread);
|
|
|
|
}
|
2003-02-26 04:46:21 +00:00
|
|
|
return (EBUSY);
|
2003-02-10 00:34:24 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
*cmp = cm;
|
|
|
|
return(0);
|
2000-12-27 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Release a command back to the freelist.
|
|
|
|
*/
|
2002-04-27 01:31:17 +00:00
|
|
|
void
|
2000-12-27 13:14:56 +00:00
|
|
|
aac_release_command(struct aac_command *cm)
|
|
|
|
{
|
2005-10-08 15:55:09 +00:00
|
|
|
struct aac_event *event;
|
|
|
|
struct aac_softc *sc;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
sc = cm->cm_sc;
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2008-03-14 21:59:11 +00:00
|
|
|
/* (re)initialize the command/FIB */
|
2001-09-05 20:43:02 +00:00
|
|
|
cm->cm_sgtable = NULL;
|
|
|
|
cm->cm_flags = 0;
|
|
|
|
cm->cm_complete = NULL;
|
|
|
|
cm->cm_private = NULL;
|
2010-02-23 21:41:13 +00:00
|
|
|
cm->cm_queue = AAC_ADAP_NORM_CMD_QUEUE;
|
2001-09-05 20:43:02 +00:00
|
|
|
cm->cm_fib->Header.XferState = AAC_FIBSTATE_EMPTY;
|
|
|
|
cm->cm_fib->Header.StructType = AAC_FIBTYPE_TFIB;
|
|
|
|
cm->cm_fib->Header.Flags = 0;
|
2005-10-08 15:55:09 +00:00
|
|
|
cm->cm_fib->Header.SenderSize = cm->cm_sc->aac_max_fib_size;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2001-09-05 20:43:02 +00:00
|
|
|
* These are duplicated in aac_start to cover the case where an
|
|
|
|
* intermediate stage may have destroyed them. They're left
|
2008-03-14 21:59:11 +00:00
|
|
|
* initialized here for debugging purposes only.
|
2001-09-05 20:43:02 +00:00
|
|
|
*/
|
2003-01-11 01:59:21 +00:00
|
|
|
cm->cm_fib->Header.ReceiverFibAddress = (u_int32_t)cm->cm_fibphys;
|
|
|
|
cm->cm_fib->Header.SenderData = 0;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
aac_enqueue_free(cm);
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2011-02-03 02:14:53 +00:00
|
|
|
if ((event = TAILQ_FIRST(&sc->aac_ev_cmfree)) != NULL) {
|
2005-10-08 15:55:09 +00:00
|
|
|
TAILQ_REMOVE(&sc->aac_ev_cmfree, event, ev_links);
|
|
|
|
event->ev_callback(sc, event, event->ev_arg);
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Map helper for command/FIB allocation.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-12-27 13:14:56 +00:00
|
|
|
aac_map_command_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2005-10-08 15:55:09 +00:00
|
|
|
uint64_t *fibphys;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
fibphys = (uint64_t *)arg;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-10 00:34:24 +00:00
|
|
|
*fibphys = segs[0].ds_addr;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Allocate and initialize commands/FIBs for this adapter.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
2000-12-27 13:14:56 +00:00
|
|
|
static int
|
|
|
|
aac_alloc_commands(struct aac_softc *sc)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
2003-02-10 00:34:24 +00:00
|
|
|
struct aac_fibmap *fm;
|
2005-10-08 15:55:09 +00:00
|
|
|
uint64_t fibphys;
|
2003-02-10 00:34:24 +00:00
|
|
|
int i, error;
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->total_fibs + sc->aac_max_fibs_alloc > sc->aac_max_fibs)
|
2003-02-10 00:34:24 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
|
2003-02-19 21:38:29 +00:00
|
|
|
fm = malloc(sizeof(struct aac_fibmap), M_AACBUF, M_NOWAIT|M_ZERO);
|
2003-03-26 17:50:11 +00:00
|
|
|
if (fm == NULL)
|
|
|
|
return (ENOMEM);
|
2003-02-10 00:34:24 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* allocate the FIBs in DMAable memory and load them */
|
2003-02-10 00:34:24 +00:00
|
|
|
if (bus_dmamem_alloc(sc->aac_fib_dmat, (void **)&fm->aac_fibs,
|
|
|
|
BUS_DMA_NOWAIT, &fm->aac_fibmap)) {
|
2003-02-05 23:24:25 +00:00
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"Not enough contiguous memory available.\n");
|
2003-02-19 21:38:29 +00:00
|
|
|
free(fm, M_AACBUF);
|
2002-08-30 05:02:07 +00:00
|
|
|
return (ENOMEM);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2003-01-23 01:01:44 +00:00
|
|
|
|
2003-07-09 21:16:23 +00:00
|
|
|
/* Ignore errors since this doesn't bounce */
|
2005-11-13 17:26:36 +00:00
|
|
|
(void)bus_dmamap_load(sc->aac_fib_dmat, fm->aac_fibmap, fm->aac_fibs,
|
2005-10-08 15:55:09 +00:00
|
|
|
sc->aac_max_fibs_alloc * sc->aac_max_fib_size,
|
2003-07-09 21:16:23 +00:00
|
|
|
aac_map_command_helper, &fibphys, 0);
|
2003-01-23 01:01:44 +00:00
|
|
|
|
2008-03-14 21:59:11 +00:00
|
|
|
/* initialize constant fields in the command structure */
|
2005-10-08 15:55:09 +00:00
|
|
|
bzero(fm->aac_fibs, sc->aac_max_fibs_alloc * sc->aac_max_fib_size);
|
|
|
|
for (i = 0; i < sc->aac_max_fibs_alloc; i++) {
|
2003-02-19 21:38:29 +00:00
|
|
|
cm = sc->aac_commands + sc->total_fibs;
|
2003-02-10 00:34:24 +00:00
|
|
|
fm->aac_commands = cm;
|
2001-09-05 20:43:02 +00:00
|
|
|
cm->cm_sc = sc;
|
2005-10-08 15:55:09 +00:00
|
|
|
cm->cm_fib = (struct aac_fib *)
|
|
|
|
((u_int8_t *)fm->aac_fibs + i*sc->aac_max_fib_size);
|
|
|
|
cm->cm_fibphys = fibphys + i*sc->aac_max_fib_size;
|
2003-02-19 23:33:56 +00:00
|
|
|
cm->cm_index = sc->total_fibs;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2003-02-10 00:34:24 +00:00
|
|
|
if ((error = bus_dmamap_create(sc->aac_buffer_dmat, 0,
|
2006-04-08 06:05:29 +00:00
|
|
|
&cm->cm_datamap)) != 0)
|
2003-02-19 21:38:29 +00:00
|
|
|
break;
|
2006-04-08 06:05:29 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
aac_release_command(cm);
|
2003-02-19 21:38:29 +00:00
|
|
|
sc->total_fibs++;
|
2006-04-08 06:05:29 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2003-02-10 00:34:24 +00:00
|
|
|
|
2003-02-19 21:38:29 +00:00
|
|
|
if (i > 0) {
|
2006-04-08 06:05:29 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2003-02-19 21:38:29 +00:00
|
|
|
TAILQ_INSERT_TAIL(&sc->aac_fibmap_tqh, fm, fm_link);
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_COMM_B, "total_fibs= %d\n", sc->total_fibs);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2003-02-19 21:38:29 +00:00
|
|
|
return (0);
|
2005-11-13 17:26:36 +00:00
|
|
|
}
|
2003-02-10 00:34:24 +00:00
|
|
|
|
2003-02-19 21:38:29 +00:00
|
|
|
bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap);
|
|
|
|
bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap);
|
|
|
|
free(fm, M_AACBUF);
|
|
|
|
return (ENOMEM);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Free FIBs owned by this adapter.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-02-19 21:38:29 +00:00
|
|
|
aac_free_commands(struct aac_softc *sc)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2003-02-19 21:38:29 +00:00
|
|
|
struct aac_fibmap *fm;
|
2003-02-10 00:34:24 +00:00
|
|
|
struct aac_command *cm;
|
2001-09-05 20:43:02 +00:00
|
|
|
int i;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-02-19 21:38:29 +00:00
|
|
|
while ((fm = TAILQ_FIRST(&sc->aac_fibmap_tqh)) != NULL) {
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2003-02-19 21:38:29 +00:00
|
|
|
TAILQ_REMOVE(&sc->aac_fibmap_tqh, fm, fm_link);
|
|
|
|
/*
|
|
|
|
* We check against total_fibs to handle partially
|
|
|
|
* allocated blocks.
|
|
|
|
*/
|
2005-10-08 15:55:09 +00:00
|
|
|
for (i = 0; i < sc->aac_max_fibs_alloc && sc->total_fibs--; i++) {
|
2003-02-19 21:38:29 +00:00
|
|
|
cm = fm->aac_commands + i;
|
|
|
|
bus_dmamap_destroy(sc->aac_buffer_dmat, cm->cm_datamap);
|
|
|
|
}
|
|
|
|
bus_dmamap_unload(sc->aac_fib_dmat, fm->aac_fibmap);
|
|
|
|
bus_dmamem_free(sc->aac_fib_dmat, fm->aac_fibs, fm->aac_fibmap);
|
|
|
|
free(fm, M_AACBUF);
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Command-mapping helper function - populate this command's s/g table.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_map_command_sg(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
2003-07-09 21:16:23 +00:00
|
|
|
struct aac_softc *sc;
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cm = (struct aac_command *)arg;
|
2003-07-09 21:16:23 +00:00
|
|
|
sc = cm->cm_sc;
|
2001-09-05 20:43:02 +00:00
|
|
|
fib = cm->cm_fib;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/* copy into the FIB */
|
2003-03-30 21:47:16 +00:00
|
|
|
if (cm->cm_sgtable != NULL) {
|
2005-10-08 15:55:09 +00:00
|
|
|
if (fib->Header.Command == RawIo) {
|
|
|
|
struct aac_sg_tableraw *sg;
|
|
|
|
sg = (struct aac_sg_tableraw *)cm->cm_sgtable;
|
|
|
|
sg->SgCount = nseg;
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
sg->SgEntryRaw[i].SgAddress = segs[i].ds_addr;
|
|
|
|
sg->SgEntryRaw[i].SgByteCount = segs[i].ds_len;
|
|
|
|
sg->SgEntryRaw[i].Next = 0;
|
|
|
|
sg->SgEntryRaw[i].Prev = 0;
|
|
|
|
sg->SgEntryRaw[i].Flags = 0;
|
|
|
|
}
|
|
|
|
/* update the FIB size for the s/g count */
|
|
|
|
fib->Header.Size += nseg*sizeof(struct aac_sg_entryraw);
|
|
|
|
} else if ((cm->cm_sc->flags & AAC_FLAGS_SG_64BIT) == 0) {
|
2003-03-30 21:47:16 +00:00
|
|
|
struct aac_sg_table *sg;
|
|
|
|
sg = cm->cm_sgtable;
|
|
|
|
sg->SgCount = nseg;
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
sg->SgEntry[i].SgAddress = segs[i].ds_addr;
|
|
|
|
sg->SgEntry[i].SgByteCount = segs[i].ds_len;
|
|
|
|
}
|
|
|
|
/* update the FIB size for the s/g count */
|
2005-10-08 15:55:09 +00:00
|
|
|
fib->Header.Size += nseg*sizeof(struct aac_sg_entry);
|
2003-03-30 21:47:16 +00:00
|
|
|
} else {
|
|
|
|
struct aac_sg_table64 *sg;
|
|
|
|
sg = (struct aac_sg_table64 *)cm->cm_sgtable;
|
|
|
|
sg->SgCount = nseg;
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
sg->SgEntry64[i].SgAddress = segs[i].ds_addr;
|
|
|
|
sg->SgEntry64[i].SgByteCount = segs[i].ds_len;
|
|
|
|
}
|
|
|
|
/* update the FIB size for the s/g count */
|
|
|
|
fib->Header.Size += nseg*sizeof(struct aac_sg_entry64);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2003-07-09 21:16:23 +00:00
|
|
|
/* Fix up the address values in the FIB. Use the command array index
|
|
|
|
* instead of a pointer since these fields are only 32 bits. Shift
|
2005-11-13 17:26:36 +00:00
|
|
|
* the SenderFibAddress over to make room for the fast response bit
|
2005-10-08 15:55:09 +00:00
|
|
|
* and for the AIF bit
|
2003-07-09 21:16:23 +00:00
|
|
|
*/
|
2005-10-08 15:55:09 +00:00
|
|
|
cm->cm_fib->Header.SenderFibAddress = (cm->cm_index << 2);
|
|
|
|
cm->cm_fib->Header.ReceiverFibAddress = (u_int32_t)cm->cm_fibphys;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-07-09 21:16:23 +00:00
|
|
|
/* save a pointer to the command for speedy reverse-lookup */
|
|
|
|
cm->cm_fib->Header.SenderData = cm->cm_index;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2003-07-09 21:16:23 +00:00
|
|
|
if (cm->cm_flags & AAC_CMD_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
if (cm->cm_flags & AAC_CMD_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
cm->cm_flags |= AAC_CMD_MAPPED;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM) {
|
|
|
|
int count = 10000000L;
|
|
|
|
while (AAC_SEND_COMMAND(sc, cm) != 0) {
|
|
|
|
if (--count == 0) {
|
|
|
|
aac_unmap_command(cm);
|
|
|
|
sc->flags |= AAC_QUEUE_FRZN;
|
|
|
|
aac_requeue_ready(cm);
|
|
|
|
}
|
|
|
|
DELAY(5); /* wait 5 usec. */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Put the FIB on the outbound queue */
|
|
|
|
if (aac_enqueue_fib(sc, cm->cm_queue, cm) == EBUSY) {
|
|
|
|
aac_unmap_command(cm);
|
|
|
|
sc->flags |= AAC_QUEUE_FRZN;
|
|
|
|
aac_requeue_ready(cm);
|
|
|
|
}
|
2004-02-07 10:30:22 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-07-09 21:16:23 +00:00
|
|
|
return;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Unmap a command from controller-visible space.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_unmap_command(struct aac_command *cm)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = cm->cm_sc;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if (!(cm->cm_flags & AAC_CMD_MAPPED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cm->cm_datalen != 0) {
|
|
|
|
if (cm->cm_flags & AAC_CMD_DATAIN)
|
|
|
|
bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
if (cm->cm_flags & AAC_CMD_DATAOUT)
|
|
|
|
bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
bus_dmamap_unload(sc->aac_buffer_dmat, cm->cm_datamap);
|
|
|
|
}
|
|
|
|
cm->cm_flags &= ~AAC_CMD_MAPPED;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Hardware Interface
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize the adapter.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct aac_softc *)arg;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_common_busaddr = segs[0].ds_addr;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2002-02-06 01:34:09 +00:00
|
|
|
static int
|
|
|
|
aac_check_firmware(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 16:38:47 +00:00
|
|
|
u_int32_t code, major, minor, options = 0, atu_size = 0;
|
2005-10-14 16:22:45 +00:00
|
|
|
int status;
|
2008-03-24 16:38:47 +00:00
|
|
|
time_t then;
|
2002-02-06 01:34:09 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2008-03-24 16:38:47 +00:00
|
|
|
/*
|
|
|
|
* Wait for the adapter to come ready.
|
|
|
|
*/
|
|
|
|
then = time_uptime;
|
|
|
|
do {
|
|
|
|
code = AAC_GET_FWSTATUS(sc);
|
|
|
|
if (code & AAC_SELF_TEST_FAILED) {
|
|
|
|
device_printf(sc->aac_dev, "FATAL: selftest failed\n");
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
if (code & AAC_KERNEL_PANIC) {
|
|
|
|
device_printf(sc->aac_dev,
|
2008-03-26 15:28:56 +00:00
|
|
|
"FATAL: controller kernel panic");
|
2008-03-24 16:38:47 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
if (time_uptime > (then + AAC_BOOT_TIMEOUT)) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"FATAL: controller not coming ready, "
|
|
|
|
"status %x\n", code);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
} while (!(code & AAC_UP_AND_RUNNING));
|
2002-02-06 01:34:09 +00:00
|
|
|
|
2003-03-26 17:50:11 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the firmware version numbers. Dell PERC2/QC cards with
|
|
|
|
* firmware version 1.x are not compatible with this driver.
|
|
|
|
*/
|
|
|
|
if (sc->flags & AAC_FLAGS_PERC2QC) {
|
2002-02-06 01:34:09 +00:00
|
|
|
if (aac_sync_command(sc, AAC_MONKER_GETKERNVER, 0, 0, 0, 0,
|
|
|
|
NULL)) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"Error reading firmware version\n");
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These numbers are stored as ASCII! */
|
2003-03-26 17:50:11 +00:00
|
|
|
major = (AAC_GET_MAILBOX(sc, 1) & 0xff) - 0x30;
|
|
|
|
minor = (AAC_GET_MAILBOX(sc, 2) & 0xff) - 0x30;
|
2002-02-06 01:34:09 +00:00
|
|
|
if (major == 1) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"Firmware version %d.%d is not supported.\n",
|
|
|
|
major, minor);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 17:50:11 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the capabilities/supported options word so we know what
|
2005-10-14 16:22:45 +00:00
|
|
|
* work-arounds to enable. Some firmware revs don't support this
|
|
|
|
* command.
|
2003-03-26 17:50:11 +00:00
|
|
|
*/
|
2005-10-14 16:22:45 +00:00
|
|
|
if (aac_sync_command(sc, AAC_MONKER_GETINFO, 0, 0, 0, 0, &status)) {
|
|
|
|
if (status != AAC_SRB_STS_INVALID_REQUEST) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"RequestAdapterInfo failed\n");
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options = AAC_GET_MAILBOX(sc, 1);
|
|
|
|
atu_size = AAC_GET_MAILBOX(sc, 2);
|
|
|
|
sc->supported_options = options;
|
|
|
|
|
|
|
|
if ((options & AAC_SUPPORTED_4GB_WINDOW) != 0 &&
|
|
|
|
(sc->flags & AAC_FLAGS_NO4GB) == 0)
|
|
|
|
sc->flags |= AAC_FLAGS_4GB_WINDOW;
|
|
|
|
if (options & AAC_SUPPORTED_NONDASD)
|
|
|
|
sc->flags |= AAC_FLAGS_ENABLE_CAM;
|
|
|
|
if ((options & AAC_SUPPORTED_SGMAP_HOST64) != 0
|
|
|
|
&& (sizeof(bus_addr_t) > 4)) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"Enabling 64-bit address support\n");
|
|
|
|
sc->flags |= AAC_FLAGS_SG_64BIT;
|
|
|
|
}
|
|
|
|
if ((options & AAC_SUPPORTED_NEW_COMM)
|
|
|
|
&& sc->aac_if.aif_send_command)
|
|
|
|
sc->flags |= AAC_FLAGS_NEW_COMM;
|
|
|
|
if (options & AAC_SUPPORTED_64BIT_ARRAYSIZE)
|
|
|
|
sc->flags |= AAC_FLAGS_ARRAY_64BIT;
|
2003-03-26 17:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for broken hardware that does a lower number of commands */
|
2005-11-13 17:26:36 +00:00
|
|
|
sc->aac_max_fibs = (sc->flags & AAC_FLAGS_256FIBS ? 256:512);
|
2005-10-08 15:55:09 +00:00
|
|
|
|
|
|
|
/* Remap mem. resource, if required */
|
2005-11-13 17:26:36 +00:00
|
|
|
if ((sc->flags & AAC_FLAGS_NEW_COMM) &&
|
2009-02-21 15:40:03 +00:00
|
|
|
atu_size > rman_get_size(sc->aac_regs_res1)) {
|
2005-10-08 15:55:09 +00:00
|
|
|
bus_release_resource(
|
|
|
|
sc->aac_dev, SYS_RES_MEMORY,
|
2009-02-21 15:40:03 +00:00
|
|
|
sc->aac_regs_rid1, sc->aac_regs_res1);
|
|
|
|
sc->aac_regs_res1 = bus_alloc_resource(
|
|
|
|
sc->aac_dev, SYS_RES_MEMORY, &sc->aac_regs_rid1,
|
2005-11-13 17:26:36 +00:00
|
|
|
0ul, ~0ul, atu_size, RF_ACTIVE);
|
2009-02-21 15:40:03 +00:00
|
|
|
if (sc->aac_regs_res1 == NULL) {
|
|
|
|
sc->aac_regs_res1 = bus_alloc_resource_any(
|
2005-10-08 15:55:09 +00:00
|
|
|
sc->aac_dev, SYS_RES_MEMORY,
|
2009-02-21 15:40:03 +00:00
|
|
|
&sc->aac_regs_rid1, RF_ACTIVE);
|
|
|
|
if (sc->aac_regs_res1 == NULL) {
|
2005-10-08 15:55:09 +00:00
|
|
|
device_printf(sc->aac_dev,
|
2005-10-08 22:41:57 +00:00
|
|
|
"couldn't allocate register window\n");
|
2005-10-08 15:55:09 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
sc->flags &= ~AAC_FLAGS_NEW_COMM;
|
|
|
|
}
|
2009-02-21 15:40:03 +00:00
|
|
|
sc->aac_btag1 = rman_get_bustag(sc->aac_regs_res1);
|
|
|
|
sc->aac_bhandle1 = rman_get_bushandle(sc->aac_regs_res1);
|
|
|
|
|
|
|
|
if (sc->aac_hwif == AAC_HWIF_NARK) {
|
|
|
|
sc->aac_regs_res0 = sc->aac_regs_res1;
|
|
|
|
sc->aac_regs_rid0 = sc->aac_regs_rid1;
|
|
|
|
sc->aac_btag0 = sc->aac_btag1;
|
|
|
|
sc->aac_bhandle0 = sc->aac_bhandle1;
|
|
|
|
}
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
2003-03-26 17:50:11 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
/* Read preferred settings */
|
|
|
|
sc->aac_max_fib_size = sizeof(struct aac_fib);
|
|
|
|
sc->aac_max_sectors = 128; /* 64KB */
|
|
|
|
if (sc->flags & AAC_FLAGS_SG_64BIT)
|
2005-10-14 16:22:45 +00:00
|
|
|
sc->aac_sg_tablesize = (AAC_FIB_DATASIZE
|
2007-10-15 17:34:58 +00:00
|
|
|
- sizeof(struct aac_blockwrite64))
|
|
|
|
/ sizeof(struct aac_sg_entry64);
|
2005-10-08 15:55:09 +00:00
|
|
|
else
|
2005-10-14 16:22:45 +00:00
|
|
|
sc->aac_sg_tablesize = (AAC_FIB_DATASIZE
|
2007-10-15 17:34:58 +00:00
|
|
|
- sizeof(struct aac_blockwrite))
|
|
|
|
/ sizeof(struct aac_sg_entry);
|
2005-10-14 16:22:45 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
if (!aac_sync_command(sc, AAC_MONKER_GETCOMMPREF, 0, 0, 0, 0, NULL)) {
|
|
|
|
options = AAC_GET_MAILBOX(sc, 1);
|
|
|
|
sc->aac_max_fib_size = (options & 0xFFFF);
|
|
|
|
sc->aac_max_sectors = (options >> 16) << 1;
|
|
|
|
options = AAC_GET_MAILBOX(sc, 2);
|
|
|
|
sc->aac_sg_tablesize = (options >> 16);
|
|
|
|
options = AAC_GET_MAILBOX(sc, 3);
|
|
|
|
sc->aac_max_fibs = (options & 0xFFFF);
|
|
|
|
}
|
|
|
|
if (sc->aac_max_fib_size > PAGE_SIZE)
|
|
|
|
sc->aac_max_fib_size = PAGE_SIZE;
|
|
|
|
sc->aac_max_fibs_alloc = PAGE_SIZE / sc->aac_max_fib_size;
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2008-03-20 17:59:19 +00:00
|
|
|
if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
|
|
|
|
sc->flags |= AAC_FLAGS_RAW_IO;
|
|
|
|
device_printf(sc->aac_dev, "Enable Raw I/O\n");
|
|
|
|
}
|
2008-03-25 21:39:06 +00:00
|
|
|
if ((sc->flags & AAC_FLAGS_RAW_IO) &&
|
|
|
|
(sc->flags & AAC_FLAGS_ARRAY_64BIT)) {
|
|
|
|
sc->flags |= AAC_FLAGS_LBA_64BIT;
|
|
|
|
device_printf(sc->aac_dev, "Enable 64-bit array\n");
|
|
|
|
}
|
2008-03-20 17:59:19 +00:00
|
|
|
|
2002-02-06 01:34:09 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-13 03:20:35 +00:00
|
|
|
static int
|
|
|
|
aac_init(struct aac_softc *sc)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_adapter_init *ip;
|
2008-03-24 16:38:47 +00:00
|
|
|
u_int32_t qoffset;
|
2003-03-26 17:50:11 +00:00
|
|
|
int error;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Fill in the init structure. This tells the adapter about the
|
|
|
|
* physical location of various important shared data structures.
|
|
|
|
*/
|
|
|
|
ip = &sc->aac_common->ac_init;
|
|
|
|
ip->InitStructRevision = AAC_INIT_STRUCT_REVISION;
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
|
|
|
|
ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_4;
|
|
|
|
sc->flags |= AAC_FLAGS_RAW_IO;
|
|
|
|
}
|
2003-01-11 01:59:21 +00:00
|
|
|
ip->MiniPortRevision = AAC_INIT_STRUCT_MINIPORT_REVISION;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
ip->AdapterFibsPhysicalAddress = sc->aac_common_busaddr +
|
|
|
|
offsetof(struct aac_common, ac_fibs);
|
2003-04-28 06:16:20 +00:00
|
|
|
ip->AdapterFibsVirtualAddress = 0;
|
2001-09-05 20:43:02 +00:00
|
|
|
ip->AdapterFibsSize = AAC_ADAPTER_FIBS * sizeof(struct aac_fib);
|
|
|
|
ip->AdapterFibAlign = sizeof(struct aac_fib);
|
|
|
|
|
|
|
|
ip->PrintfBufferAddress = sc->aac_common_busaddr +
|
|
|
|
offsetof(struct aac_common, ac_printf);
|
|
|
|
ip->PrintfBufferSize = AAC_PRINTF_BUFSIZE;
|
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
2003-07-09 19:19:16 +00:00
|
|
|
* The adapter assumes that pages are 4K in size, except on some
|
|
|
|
* broken firmware versions that do the page->byte conversion twice,
|
|
|
|
* therefore 'assuming' that this value is in 16MB units (2^24).
|
|
|
|
* Round up since the granularity is so high.
|
|
|
|
*/
|
2003-01-11 01:59:21 +00:00
|
|
|
ip->HostPhysMemPages = ctob(physmem) / AAC_PAGE_SIZE;
|
2003-07-09 19:19:16 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_BROKEN_MEMMAP) {
|
|
|
|
ip->HostPhysMemPages =
|
|
|
|
(ip->HostPhysMemPages + AAC_PAGE_SIZE) / AAC_PAGE_SIZE;
|
2003-07-09 19:30:30 +00:00
|
|
|
}
|
2005-09-14 05:46:28 +00:00
|
|
|
ip->HostElapsedSeconds = time_uptime; /* reset later if invalid */
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
ip->InitFlags = 0;
|
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM) {
|
2010-04-13 01:16:15 +00:00
|
|
|
ip->InitFlags |= AAC_INITFLAGS_NEW_COMM_SUPPORTED;
|
2005-10-08 15:55:09 +00:00
|
|
|
device_printf(sc->aac_dev, "New comm. interface enabled\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ip->MaxIoCommands = sc->aac_max_fibs;
|
|
|
|
ip->MaxIoSize = sc->aac_max_sectors << 9;
|
|
|
|
ip->MaxFibSize = sc->aac_max_fib_size;
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2008-03-14 21:59:11 +00:00
|
|
|
* Initialize FIB queues. Note that it appears that the layout of the
|
2001-09-05 20:43:02 +00:00
|
|
|
* indexes and the segmentation of the entries may be mandated by the
|
|
|
|
* adapter, which is only told about the base of the queue index fields.
|
|
|
|
*
|
|
|
|
* The initial values of the indices are assumed to inform the adapter
|
2005-11-13 17:26:36 +00:00
|
|
|
* of the sizes of the respective queues, and theoretically it could
|
2001-09-05 20:43:02 +00:00
|
|
|
* work out the entire layout of the queue structures from this. We
|
|
|
|
* take the easy route and just lay this area out like everyone else
|
|
|
|
* does.
|
|
|
|
*
|
2005-11-13 17:26:36 +00:00
|
|
|
* The Linux driver uses a much more complex scheme whereby several
|
|
|
|
* header records are kept for each queue. We use a couple of generic
|
2001-09-05 20:43:02 +00:00
|
|
|
* list manipulation functions which 'know' the size of each list by
|
|
|
|
* virtue of a table.
|
|
|
|
*/
|
2003-08-19 21:31:45 +00:00
|
|
|
qoffset = offsetof(struct aac_common, ac_qbuf) + AAC_QUEUE_ALIGN;
|
2003-09-01 00:20:29 +00:00
|
|
|
qoffset &= ~(AAC_QUEUE_ALIGN - 1);
|
|
|
|
sc->aac_queues =
|
|
|
|
(struct aac_queue_table *)((uintptr_t)sc->aac_common + qoffset);
|
2003-08-19 21:31:45 +00:00
|
|
|
ip->CommHeaderAddress = sc->aac_common_busaddr + qoffset;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_NORM_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_NORM_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_HIGH_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_HIGH_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_NORM_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_NORM_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_HIGH_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX] =
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_HIGH_CMD_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_NORM_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_NORM_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_HIGH_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_HOST_HIGH_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_NORM_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_NORM_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_HIGH_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX]=
|
2001-08-03 00:50:30 +00:00
|
|
|
AAC_ADAP_HIGH_RESP_ENTRIES;
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_HOST_NORM_CMD_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_HostNormCmdQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_HOST_HIGH_CMD_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_HostHighCmdQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_ADAP_NORM_CMD_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_AdapNormCmdQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_ADAP_HIGH_CMD_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_AdapHighCmdQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_HOST_NORM_RESP_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_HostNormRespQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_HOST_HIGH_RESP_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_HostHighRespQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_ADAP_NORM_RESP_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_AdapNormRespQueue[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_qentries[AAC_ADAP_HIGH_RESP_QUEUE] =
|
2001-08-03 00:50:30 +00:00
|
|
|
&sc->aac_queues->qt_AdapHighRespQueue[0];
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Do controller-type-specific initialisation
|
|
|
|
*/
|
|
|
|
switch (sc->aac_hwif) {
|
|
|
|
case AAC_HWIF_I960RX:
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_ODBR, ~0);
|
2001-09-05 20:43:02 +00:00
|
|
|
break;
|
2004-08-13 01:44:09 +00:00
|
|
|
case AAC_HWIF_RKT:
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_ODBR, ~0);
|
2004-08-13 01:44:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the init structure to the controller.
|
|
|
|
*/
|
2005-11-13 17:26:36 +00:00
|
|
|
if (aac_sync_command(sc, AAC_MONKER_INITSTRUCT,
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_common_busaddr +
|
|
|
|
offsetof(struct aac_common, ac_init), 0, 0, 0,
|
|
|
|
NULL)) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"error establishing init structure\n");
|
2003-03-26 17:50:11 +00:00
|
|
|
error = EIO;
|
|
|
|
goto out;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 17:50:11 +00:00
|
|
|
error = 0;
|
|
|
|
out:
|
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 16:38:47 +00:00
|
|
|
static int
|
|
|
|
aac_setup_intr(struct aac_softc *sc)
|
|
|
|
{
|
|
|
|
sc->aac_irq_rid = 0;
|
|
|
|
if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ,
|
|
|
|
&sc->aac_irq_rid,
|
|
|
|
RF_SHAREABLE |
|
|
|
|
RF_ACTIVE)) == NULL) {
|
|
|
|
device_printf(sc->aac_dev, "can't allocate interrupt\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM) {
|
|
|
|
if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
|
2010-04-13 00:33:07 +00:00
|
|
|
INTR_MPSAFE|INTR_TYPE_BIO, NULL,
|
2008-03-24 16:38:47 +00:00
|
|
|
aac_new_intr, sc, &sc->aac_intr)) {
|
|
|
|
device_printf(sc->aac_dev, "can't set up interrupt\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
|
2009-10-29 14:53:45 +00:00
|
|
|
INTR_TYPE_BIO, aac_filter, NULL,
|
2008-03-24 16:38:47 +00:00
|
|
|
sc, &sc->aac_intr)) {
|
|
|
|
device_printf(sc->aac_dev,
|
2009-10-29 14:53:45 +00:00
|
|
|
"can't set up interrupt filter\n");
|
|
|
|
return (EINVAL);
|
2008-03-24 16:38:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Send a synchronous command to the controller and wait for a result.
|
2005-10-08 15:55:09 +00:00
|
|
|
* Indicate if the controller completed the command with an error status.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_sync_command(struct aac_softc *sc, u_int32_t command,
|
2000-12-27 13:14:56 +00:00
|
|
|
u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3,
|
|
|
|
u_int32_t *sp)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
time_t then;
|
|
|
|
u_int32_t status;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* populate the mailbox */
|
|
|
|
AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* ensure the sync command doorbell flag is cleared */
|
|
|
|
AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* then set it to signal the adapter */
|
|
|
|
AAC_QNOTIFY(sc, AAC_DB_SYNC_COMMAND);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* spin waiting for the command to complete */
|
2005-09-14 05:46:28 +00:00
|
|
|
then = time_uptime;
|
2001-09-05 20:43:02 +00:00
|
|
|
do {
|
2005-09-14 05:46:28 +00:00
|
|
|
if (time_uptime > (then + AAC_IMMEDIATE_TIMEOUT)) {
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_ERROR_B, "timed out");
|
2001-09-05 20:43:02 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
} while (!(AAC_GET_ISTATUS(sc) & AAC_DB_SYNC_COMMAND));
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* clear the completion flag */
|
|
|
|
AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* get the command status */
|
2003-03-26 17:50:11 +00:00
|
|
|
status = AAC_GET_MAILBOX(sc, 0);
|
2001-09-05 20:43:02 +00:00
|
|
|
if (sp != NULL)
|
|
|
|
*sp = status;
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2005-10-14 16:22:45 +00:00
|
|
|
if (status != AAC_SRB_STS_SUCCESS)
|
2005-10-08 15:55:09 +00:00
|
|
|
return (-1);
|
2001-09-05 20:43:02 +00:00
|
|
|
return(0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2002-04-24 05:12:50 +00:00
|
|
|
int
|
2005-11-13 17:26:36 +00:00
|
|
|
aac_sync_fib(struct aac_softc *sc, u_int32_t command, u_int32_t xferstate,
|
2002-04-24 05:12:50 +00:00
|
|
|
struct aac_fib *fib, u_int16_t datasize)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_assert(&sc->aac_io_lock, MA_OWNED);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
if (datasize > AAC_FIB_DATASIZE)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the sync FIB
|
|
|
|
*/
|
|
|
|
fib->Header.XferState = AAC_FIBSTATE_HOSTOWNED |
|
|
|
|
AAC_FIBSTATE_INITIALISED |
|
|
|
|
AAC_FIBSTATE_EMPTY;
|
|
|
|
fib->Header.XferState |= xferstate;
|
|
|
|
fib->Header.Command = command;
|
|
|
|
fib->Header.StructType = AAC_FIBTYPE_TFIB;
|
2008-03-20 20:33:48 +00:00
|
|
|
fib->Header.Size = sizeof(struct aac_fib_header) + datasize;
|
2001-09-05 20:43:02 +00:00
|
|
|
fib->Header.SenderSize = sizeof(struct aac_fib);
|
2003-08-19 21:31:45 +00:00
|
|
|
fib->Header.SenderFibAddress = 0; /* Not needed */
|
2001-09-05 20:43:02 +00:00
|
|
|
fib->Header.ReceiverFibAddress = sc->aac_common_busaddr +
|
|
|
|
offsetof(struct aac_common,
|
|
|
|
ac_sync_fib);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the FIB to the controller, wait for a response.
|
|
|
|
*/
|
|
|
|
if (aac_sync_command(sc, AAC_MONKER_SYNCFIB,
|
|
|
|
fib->Header.ReceiverFibAddress, 0, 0, 0, NULL)) {
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_ERROR_B, "IO error");
|
2001-09-05 20:43:02 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
2002-04-24 05:12:50 +00:00
|
|
|
return (0);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Adapter-space FIB queue manipulation
|
|
|
|
*
|
|
|
|
* Note that the queue implementation here is a little funky; neither the PI or
|
|
|
|
* CI will ever be zero. This behaviour is a controller feature.
|
|
|
|
*/
|
|
|
|
static struct {
|
2001-09-05 20:43:02 +00:00
|
|
|
int size;
|
|
|
|
int notify;
|
2000-09-13 03:20:35 +00:00
|
|
|
} aac_qinfo[] = {
|
2001-09-05 20:43:02 +00:00
|
|
|
{AAC_HOST_NORM_CMD_ENTRIES, AAC_DB_COMMAND_NOT_FULL},
|
|
|
|
{AAC_HOST_HIGH_CMD_ENTRIES, 0},
|
|
|
|
{AAC_ADAP_NORM_CMD_ENTRIES, AAC_DB_COMMAND_READY},
|
|
|
|
{AAC_ADAP_HIGH_CMD_ENTRIES, 0},
|
|
|
|
{AAC_HOST_NORM_RESP_ENTRIES, AAC_DB_RESPONSE_NOT_FULL},
|
|
|
|
{AAC_HOST_HIGH_RESP_ENTRIES, 0},
|
|
|
|
{AAC_ADAP_NORM_RESP_ENTRIES, AAC_DB_RESPONSE_READY},
|
|
|
|
{AAC_ADAP_HIGH_RESP_ENTRIES, 0}
|
2000-09-13 03:20:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2001-08-03 00:50:30 +00:00
|
|
|
* Atomically insert an entry into the nominated queue, returns 0 on success or
|
|
|
|
* EBUSY if the queue is full.
|
2000-09-13 03:20:35 +00:00
|
|
|
*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Note: it would be more efficient to defer notifying the controller in
|
2001-09-05 20:43:02 +00:00
|
|
|
* the case where we may be inserting several entries in rapid succession,
|
|
|
|
* but implementing this usefully may be difficult (it would involve a
|
|
|
|
* separate queue/notify interface).
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-08-05 06:20:13 +00:00
|
|
|
aac_enqueue_fib(struct aac_softc *sc, int queue, struct aac_command *cm)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t pi, ci;
|
2003-03-01 05:07:19 +00:00
|
|
|
int error;
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t fib_size;
|
|
|
|
u_int32_t fib_addr;
|
2001-08-05 06:20:13 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
fib_size = cm->cm_fib->Header.Size;
|
2001-09-05 20:43:02 +00:00
|
|
|
fib_addr = cm->cm_fib->Header.ReceiverFibAddress;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* get the producer/consumer indices */
|
|
|
|
pi = sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX];
|
|
|
|
ci = sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX];
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* wrap the queue? */
|
|
|
|
if (pi >= aac_qinfo[queue].size)
|
|
|
|
pi = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* check for queue full */
|
|
|
|
if ((pi + 1) == ci) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2004-06-01 15:50:11 +00:00
|
|
|
/*
|
|
|
|
* To avoid a race with its completion interrupt, place this command on
|
|
|
|
* the busy queue prior to advertising it to the controller.
|
|
|
|
*/
|
|
|
|
aac_enqueue_busy(cm);
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* populate queue entry */
|
|
|
|
(sc->aac_qentries[queue] + pi)->aq_fib_size = fib_size;
|
|
|
|
(sc->aac_qentries[queue] + pi)->aq_fib_addr = fib_addr;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* update producer index */
|
|
|
|
sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX] = pi + 1;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* notify the adapter if we know how */
|
|
|
|
if (aac_qinfo[queue].notify != 0)
|
|
|
|
AAC_QNOTIFY(sc, aac_qinfo[queue].notify);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
error = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
out:
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-29 23:34:05 +00:00
|
|
|
* Atomically remove one entry from the nominated queue, returns 0 on
|
|
|
|
* success or ENOENT if the queue is empty.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-08-03 00:50:30 +00:00
|
|
|
aac_dequeue_fib(struct aac_softc *sc, int queue, u_int32_t *fib_size,
|
|
|
|
struct aac_fib **fib_addr)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t pi, ci;
|
2003-04-28 06:16:20 +00:00
|
|
|
u_int32_t fib_index;
|
2003-03-01 05:07:19 +00:00
|
|
|
int error;
|
2001-09-05 20:43:02 +00:00
|
|
|
int notify;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* get the producer/consumer indices */
|
|
|
|
pi = sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX];
|
|
|
|
ci = sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX];
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* check for queue empty */
|
|
|
|
if (ci == pi) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-09-16 16:07:15 +00:00
|
|
|
|
|
|
|
/* wrap the pi so the following test works */
|
|
|
|
if (pi >= aac_qinfo[queue].size)
|
|
|
|
pi = 0;
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
notify = 0;
|
|
|
|
if (ci == pi + 1)
|
|
|
|
notify++;
|
2001-08-05 06:20:13 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* wrap the queue? */
|
|
|
|
if (ci >= aac_qinfo[queue].size)
|
|
|
|
ci = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* fetch the entry */
|
|
|
|
*fib_size = (sc->aac_qentries[queue] + ci)->aq_fib_size;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2003-04-28 06:16:20 +00:00
|
|
|
switch (queue) {
|
|
|
|
case AAC_HOST_NORM_CMD_QUEUE:
|
|
|
|
case AAC_HOST_HIGH_CMD_QUEUE:
|
|
|
|
/*
|
|
|
|
* The aq_fib_addr is only 32 bits wide so it can't be counted
|
|
|
|
* on to hold an address. For AIF's, the adapter assumes
|
|
|
|
* that it's giving us an address into the array of AIF fibs.
|
|
|
|
* Therefore, we have to convert it to an index.
|
|
|
|
*/
|
|
|
|
fib_index = (sc->aac_qentries[queue] + ci)->aq_fib_addr /
|
|
|
|
sizeof(struct aac_fib);
|
|
|
|
*fib_addr = &sc->aac_common->ac_fibs[fib_index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AAC_HOST_NORM_RESP_QUEUE:
|
|
|
|
case AAC_HOST_HIGH_RESP_QUEUE:
|
|
|
|
{
|
|
|
|
struct aac_command *cm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As above, an index is used instead of an actual address.
|
|
|
|
* Gotta shift the index to account for the fast response
|
|
|
|
* bit. No other correction is needed since this value was
|
|
|
|
* originally provided by the driver via the SenderFibAddress
|
|
|
|
* field.
|
|
|
|
*/
|
|
|
|
fib_index = (sc->aac_qentries[queue] + ci)->aq_fib_addr;
|
2005-10-08 15:55:09 +00:00
|
|
|
cm = sc->aac_commands + (fib_index >> 2);
|
2003-04-28 06:16:20 +00:00
|
|
|
*fib_addr = cm->cm_fib;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is this a fast response? If it is, update the fib fields in
|
|
|
|
* local memory since the whole fib isn't DMA'd back up.
|
|
|
|
*/
|
|
|
|
if (fib_index & 0x01) {
|
|
|
|
(*fib_addr)->Header.XferState |= AAC_FIBSTATE_DONEADAP;
|
|
|
|
*((u_int32_t*)((*fib_addr)->data)) = AAC_ERROR_NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic("Invalid queue in aac_dequeue_fib()");
|
|
|
|
break;
|
2003-01-11 01:59:21 +00:00
|
|
|
}
|
2003-04-28 06:16:20 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* update consumer index */
|
|
|
|
sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX] = ci + 1;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* if we have made the queue un-full, notify the adapter */
|
|
|
|
if (notify && (aac_qinfo[queue].notify != 0))
|
|
|
|
AAC_QNOTIFY(sc, aac_qinfo[queue].notify);
|
|
|
|
error = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
out:
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2001-08-29 23:34:05 +00:00
|
|
|
* Put our response to an Adapter Initialed Fib on the response queue
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_enqueue_response(struct aac_softc *sc, int queue, struct aac_fib *fib)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t pi, ci;
|
2003-03-01 05:07:19 +00:00
|
|
|
int error;
|
2001-09-05 20:43:02 +00:00
|
|
|
u_int32_t fib_size;
|
|
|
|
u_int32_t fib_addr;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Tell the adapter where the FIB is */
|
2005-11-13 17:26:36 +00:00
|
|
|
fib_size = fib->Header.Size;
|
2001-09-05 20:43:02 +00:00
|
|
|
fib_addr = fib->Header.SenderFibAddress;
|
|
|
|
fib->Header.ReceiverFibAddress = fib_addr;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* get the producer/consumer indices */
|
|
|
|
pi = sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX];
|
|
|
|
ci = sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX];
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* wrap the queue? */
|
|
|
|
if (pi >= aac_qinfo[queue].size)
|
|
|
|
pi = 0;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* check for queue full */
|
|
|
|
if ((pi + 1) == ci) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* populate queue entry */
|
|
|
|
(sc->aac_qentries[queue] + pi)->aq_fib_size = fib_size;
|
|
|
|
(sc->aac_qentries[queue] + pi)->aq_fib_addr = fib_addr;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* update producer index */
|
|
|
|
sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX] = pi + 1;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* notify the adapter if we know how */
|
|
|
|
if (aac_qinfo[queue].notify != 0)
|
|
|
|
AAC_QNOTIFY(sc, aac_qinfo[queue].notify);
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
error = 0;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
|
|
|
out:
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2001-08-29 23:34:05 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Check for commands that have been outstanding for a suspiciously long time,
|
|
|
|
* and complain about them.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_timeout(struct aac_softc *sc)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
time_t deadline;
|
2004-09-16 02:37:40 +00:00
|
|
|
int timedout, code;
|
2000-12-27 13:14:56 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2003-02-05 23:24:25 +00:00
|
|
|
* Traverse the busy command list, bitch about late commands once
|
2001-09-05 20:43:02 +00:00
|
|
|
* only.
|
|
|
|
*/
|
2004-09-16 02:37:40 +00:00
|
|
|
timedout = 0;
|
2005-09-14 05:46:28 +00:00
|
|
|
deadline = time_uptime - AAC_CMD_TIMEOUT;
|
2001-09-05 20:43:02 +00:00
|
|
|
TAILQ_FOREACH(cm, &sc->aac_busy, cm_link) {
|
|
|
|
if ((cm->cm_timestamp < deadline)
|
2010-09-14 01:51:04 +00:00
|
|
|
&& !(cm->cm_flags & AAC_CMD_TIMEDOUT)) {
|
2001-09-05 20:43:02 +00:00
|
|
|
cm->cm_flags |= AAC_CMD_TIMEDOUT;
|
|
|
|
device_printf(sc->aac_dev,
|
2010-02-17 22:28:37 +00:00
|
|
|
"COMMAND %p (TYPE %d) TIMEOUT AFTER %d SECONDS\n",
|
|
|
|
cm, cm->cm_fib->Header.Command,
|
|
|
|
(int)(time_uptime-cm->cm_timestamp));
|
2001-09-05 20:43:02 +00:00
|
|
|
AAC_PRINT_FIB(sc, cm->cm_fib);
|
2004-09-16 02:37:40 +00:00
|
|
|
timedout++;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-12-27 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 02:37:40 +00:00
|
|
|
if (timedout) {
|
|
|
|
code = AAC_GET_FWSTATUS(sc);
|
|
|
|
if (code != AAC_UP_AND_RUNNING) {
|
|
|
|
device_printf(sc->aac_dev, "WARNING! Controller is no "
|
|
|
|
"longer running! code= 0x%x\n", code);
|
|
|
|
}
|
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
return;
|
2000-12-27 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Interface Function Vectors
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Read the current firmware status word.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_sa_get_fwstatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, AAC_SA_FWSTATUS));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
aac_rx_get_fwstatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-23 18:22:06 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, sc->flags & AAC_FLAGS_NEW_COMM ?
|
|
|
|
AAC_RX_OMR0 : AAC_RX_FWSTATUS));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static int
|
|
|
|
aac_rkt_get_fwstatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-23 18:22:06 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, sc->flags & AAC_FLAGS_NEW_COMM ?
|
|
|
|
AAC_RKT_OMR0 : AAC_RKT_FWSTATUS));
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Notify the controller of a change in a given queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_sa_qnotify(struct aac_softc *sc, int qbit)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG2(sc, AAC_SA_DOORBELL1_SET, qbit);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rx_qnotify(struct aac_softc *sc, int qbit)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_IDBR, qbit);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static void
|
|
|
|
aac_rkt_qnotify(struct aac_softc *sc, int qbit)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_IDBR, qbit);
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Get the interrupt reason bits
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_sa_get_istatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG2(sc, AAC_SA_DOORBELL0));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
aac_rx_get_istatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, AAC_RX_ODBR));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static int
|
|
|
|
aac_rkt_get_istatus(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, AAC_RKT_ODBR));
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Clear some interrupt reason bits
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_sa_clear_istatus(struct aac_softc *sc, int mask)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG2(sc, AAC_SA_DOORBELL0_CLEAR, mask);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rx_clear_istatus(struct aac_softc *sc, int mask)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_ODBR, mask);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static void
|
|
|
|
aac_rkt_clear_istatus(struct aac_softc *sc, int mask)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_ODBR, mask);
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Populate the mailbox and set the command word
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command,
|
|
|
|
u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, AAC_SA_MAILBOX, command);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_SA_MAILBOX + 4, arg0);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_SA_MAILBOX + 8, arg1);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_SA_MAILBOX + 12, arg2);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_SA_MAILBOX + 16, arg3);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rx_set_mailbox(struct aac_softc *sc, u_int32_t command,
|
|
|
|
u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RX_MAILBOX, command);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RX_MAILBOX + 4, arg0);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RX_MAILBOX + 8, arg1);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RX_MAILBOX + 12, arg2);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RX_MAILBOX + 16, arg3);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static void
|
|
|
|
aac_rkt_set_mailbox(struct aac_softc *sc, u_int32_t command, u_int32_t arg0,
|
|
|
|
u_int32_t arg1, u_int32_t arg2, u_int32_t arg3)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RKT_MAILBOX, command);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RKT_MAILBOX + 4, arg0);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RKT_MAILBOX + 8, arg1);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RKT_MAILBOX + 12, arg2);
|
|
|
|
AAC_MEM1_SETREG4(sc, AAC_RKT_MAILBOX + 16, arg3);
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Fetch the immediate command status word
|
|
|
|
*/
|
|
|
|
static int
|
2003-03-26 17:50:11 +00:00
|
|
|
aac_sa_get_mailbox(struct aac_softc *sc, int mb)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM1_GETREG4(sc, AAC_SA_MAILBOX + (mb * 4)));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-26 17:50:11 +00:00
|
|
|
aac_rx_get_mailbox(struct aac_softc *sc, int mb)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM1_GETREG4(sc, AAC_RX_MAILBOX + (mb * 4)));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static int
|
|
|
|
aac_rkt_get_mailbox(struct aac_softc *sc, int mb)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM1_GETREG4(sc, AAC_RKT_MAILBOX + (mb * 4)));
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Set/clear interrupt masks
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_sa_set_interrupts(struct aac_softc *sc, int enable)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "%sable interrupts", enable ? "en" : "dis");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if (enable) {
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG2((sc), AAC_SA_MASK0_CLEAR, AAC_DB_INTERRUPTS);
|
2001-09-05 20:43:02 +00:00
|
|
|
} else {
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG2((sc), AAC_SA_MASK0_SET, ~0);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rx_set_interrupts(struct aac_softc *sc, int enable)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "%sable interrupts", enable ? "en" : "dis");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if (enable) {
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM)
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_OIMR, ~AAC_DB_INT_NEW_COMM);
|
2005-10-08 15:55:09 +00:00
|
|
|
else
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_OIMR, ~AAC_DB_INTERRUPTS);
|
2001-09-05 20:43:02 +00:00
|
|
|
} else {
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_OIMR, ~0);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 01:44:09 +00:00
|
|
|
static void
|
|
|
|
aac_rkt_set_interrupts(struct aac_softc *sc, int enable)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "%sable interrupts", enable ? "en" : "dis");
|
2004-08-13 01:44:09 +00:00
|
|
|
|
|
|
|
if (enable) {
|
2005-10-08 15:55:09 +00:00
|
|
|
if (sc->flags & AAC_FLAGS_NEW_COMM)
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_OIMR, ~AAC_DB_INT_NEW_COMM);
|
2005-10-08 15:55:09 +00:00
|
|
|
else
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_OIMR, ~AAC_DB_INTERRUPTS);
|
2004-08-13 01:44:09 +00:00
|
|
|
} else {
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_OIMR, ~0);
|
2004-08-13 01:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
/*
|
|
|
|
* New comm. interface: Send command functions
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_rx_send_command(struct aac_softc *sc, struct aac_command *cm)
|
|
|
|
{
|
|
|
|
u_int32_t index, device;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "send command (new comm.)");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
index = AAC_MEM0_GETREG4(sc, AAC_RX_IQUE);
|
2005-10-08 15:55:09 +00:00
|
|
|
if (index == 0xffffffffL)
|
2009-02-21 15:40:03 +00:00
|
|
|
index = AAC_MEM0_GETREG4(sc, AAC_RX_IQUE);
|
2005-10-08 15:55:09 +00:00
|
|
|
if (index == 0xffffffffL)
|
|
|
|
return index;
|
|
|
|
aac_enqueue_busy(cm);
|
|
|
|
device = index;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, (u_int32_t)(cm->cm_fibphys & 0xffffffffUL));
|
2005-10-08 15:55:09 +00:00
|
|
|
device += 4;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, (u_int32_t)(cm->cm_fibphys >> 32));
|
2005-10-08 15:55:09 +00:00
|
|
|
device += 4;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, cm->cm_fib->Header.Size);
|
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_IQUE, index);
|
2005-10-08 15:55:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
aac_rkt_send_command(struct aac_softc *sc, struct aac_command *cm)
|
|
|
|
{
|
|
|
|
u_int32_t index, device;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "send command (new comm.)");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
index = AAC_MEM0_GETREG4(sc, AAC_RKT_IQUE);
|
2005-10-08 15:55:09 +00:00
|
|
|
if (index == 0xffffffffL)
|
2009-02-21 15:40:03 +00:00
|
|
|
index = AAC_MEM0_GETREG4(sc, AAC_RKT_IQUE);
|
2005-10-08 15:55:09 +00:00
|
|
|
if (index == 0xffffffffL)
|
|
|
|
return index;
|
|
|
|
aac_enqueue_busy(cm);
|
|
|
|
device = index;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, (u_int32_t)(cm->cm_fibphys & 0xffffffffUL));
|
2005-10-08 15:55:09 +00:00
|
|
|
device += 4;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, (u_int32_t)(cm->cm_fibphys >> 32));
|
2005-10-08 15:55:09 +00:00
|
|
|
device += 4;
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM1_SETREG4(sc, device, cm->cm_fib->Header.Size);
|
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_IQUE, index);
|
2005-10-08 15:55:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-13 17:26:36 +00:00
|
|
|
/*
|
|
|
|
* New comm. interface: get, set outbound queue index
|
2005-10-08 15:55:09 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_rx_get_outb_queue(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, AAC_RX_OQUE));
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
aac_rkt_get_outb_queue(struct aac_softc *sc)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
return(AAC_MEM0_GETREG4(sc, AAC_RKT_OQUE));
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rx_set_outb_queue(struct aac_softc *sc, int index)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RX_OQUE, index);
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aac_rkt_set_outb_queue(struct aac_softc *sc, int index)
|
|
|
|
{
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
2009-02-21 15:40:03 +00:00
|
|
|
AAC_MEM0_SETREG4(sc, AAC_RKT_OQUE, index);
|
2005-10-08 15:55:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Debugging and Diagnostics
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Print some information about the controller.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_describe_controller(struct aac_softc *sc)
|
|
|
|
{
|
2002-04-24 05:12:50 +00:00
|
|
|
struct aac_fib *fib;
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_adapter_info *info;
|
2007-12-07 18:05:41 +00:00
|
|
|
char *adapter_type = "Adaptec RAID controller";
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2005-10-10 20:13:31 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-06-02 18:15:48 +00:00
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
2002-04-24 05:12:50 +00:00
|
|
|
|
|
|
|
fib->data[0] = 0;
|
|
|
|
if (aac_sync_fib(sc, RequestAdapterInfo, 0, fib, 1)) {
|
2001-09-05 20:43:02 +00:00
|
|
|
device_printf(sc->aac_dev, "RequestAdapterInfo failed\n");
|
2002-04-27 01:31:17 +00:00
|
|
|
aac_release_sync_fib(sc);
|
2005-10-10 20:13:31 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the kernel revision structure for later use */
|
2005-11-13 17:26:36 +00:00
|
|
|
info = (struct aac_adapter_info *)&fib->data[0];
|
2001-09-05 20:43:02 +00:00
|
|
|
sc->aac_revision = info->KernelRevision;
|
2002-04-27 01:31:17 +00:00
|
|
|
|
2004-09-12 03:19:32 +00:00
|
|
|
if (bootverbose) {
|
2005-06-01 07:11:17 +00:00
|
|
|
device_printf(sc->aac_dev, "%s %dMHz, %dMB memory "
|
2005-11-13 17:26:36 +00:00
|
|
|
"(%dMB cache, %dMB execution), %s\n",
|
2004-09-12 03:19:32 +00:00
|
|
|
aac_describe_code(aac_cpu_variant, info->CpuVariant),
|
2005-11-13 17:26:36 +00:00
|
|
|
info->ClockSpeed, info->TotalMem / (1024 * 1024),
|
2005-06-01 07:11:17 +00:00
|
|
|
info->BufferMem / (1024 * 1024),
|
|
|
|
info->ExecutionMem / (1024 * 1024),
|
2004-09-12 03:19:32 +00:00
|
|
|
aac_describe_code(aac_battery_platform,
|
|
|
|
info->batteryPlatform));
|
|
|
|
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"Kernel %d.%d-%d, Build %d, S/N %6X\n",
|
|
|
|
info->KernelRevision.external.comp.major,
|
|
|
|
info->KernelRevision.external.comp.minor,
|
|
|
|
info->KernelRevision.external.comp.dash,
|
|
|
|
info->KernelRevision.buildNumber,
|
|
|
|
(u_int32_t)(info->SerialNumber & 0xffffff));
|
2003-03-26 17:50:11 +00:00
|
|
|
|
|
|
|
device_printf(sc->aac_dev, "Supported Options=%b\n",
|
|
|
|
sc->supported_options,
|
|
|
|
"\20"
|
|
|
|
"\1SNAPSHOT"
|
|
|
|
"\2CLUSTERS"
|
|
|
|
"\3WCACHE"
|
|
|
|
"\4DATA64"
|
|
|
|
"\5HOSTTIME"
|
|
|
|
"\6RAID50"
|
|
|
|
"\7WINDOW4GB"
|
|
|
|
"\10SCSIUPGD"
|
|
|
|
"\11SOFTERR"
|
|
|
|
"\12NORECOND"
|
|
|
|
"\13SGMAP64"
|
|
|
|
"\14ALARM"
|
2005-10-08 15:55:09 +00:00
|
|
|
"\15NONDASD"
|
|
|
|
"\16SCSIMGT"
|
|
|
|
"\17RAIDSCSI"
|
|
|
|
"\21ADPTINFO"
|
|
|
|
"\22NEWCOMM"
|
|
|
|
"\23ARRAY64BIT"
|
|
|
|
"\24HEATSENSOR");
|
2003-03-26 17:50:11 +00:00
|
|
|
}
|
2008-04-01 20:53:32 +00:00
|
|
|
|
|
|
|
if (sc->supported_options & AAC_SUPPORTED_SUPPLEMENT_ADAPTER_INFO) {
|
|
|
|
fib->data[0] = 0;
|
|
|
|
if (aac_sync_fib(sc, RequestSupplementAdapterInfo, 0, fib, 1))
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"RequestSupplementAdapterInfo failed\n");
|
|
|
|
else
|
|
|
|
adapter_type = ((struct aac_supplement_adapter_info *)
|
|
|
|
&fib->data[0])->AdapterTypeText;
|
|
|
|
}
|
|
|
|
device_printf(sc->aac_dev, "%s, aac driver %d.%d.%d-%d\n",
|
|
|
|
adapter_type,
|
2010-02-14 17:14:11 +00:00
|
|
|
AAC_DRIVER_MAJOR_VERSION, AAC_DRIVER_MINOR_VERSION,
|
|
|
|
AAC_DRIVER_BUGFIX_LEVEL, AAC_DRIVER_BUILD);
|
2008-04-01 20:53:32 +00:00
|
|
|
|
2004-09-12 03:19:32 +00:00
|
|
|
aac_release_sync_fib(sc);
|
2005-10-10 20:13:31 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Look up a text description of a numeric error code and return a pointer to
|
|
|
|
* same.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
aac_describe_code(struct aac_code_lookup *table, u_int32_t code)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
int i;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
for (i = 0; table[i].string != NULL; i++)
|
|
|
|
if (table[i].code == code)
|
|
|
|
return(table[i].string);
|
|
|
|
return(table[i + 1].string);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Management Interface
|
|
|
|
*/
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
aac_open(struct cdev *dev, int flags, int fmt, struct thread *td)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_softc *sc;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
sc = dev->si_drv1;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2010-09-15 14:24:21 +00:00
|
|
|
device_busy(sc->aac_dev);
|
2010-09-16 17:49:10 +00:00
|
|
|
devfs_set_cdevpriv(sc, aac_cdevpriv_dtor);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
return 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
aac_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
union aac_statrequest *as;
|
|
|
|
struct aac_softc *sc;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
as = (union aac_statrequest *)arg;
|
|
|
|
sc = dev->si_drv1;
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case AACIO_STATS:
|
|
|
|
switch (as->as_item) {
|
|
|
|
case AACQ_FREE:
|
|
|
|
case AACQ_BIO:
|
|
|
|
case AACQ_READY:
|
|
|
|
case AACQ_BUSY:
|
|
|
|
bcopy(&sc->aac_qstat[as->as_item], &as->as_qstat,
|
|
|
|
sizeof(struct aac_qstat));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
2000-12-27 13:14:56 +00:00
|
|
|
break;
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
case FSACTL_SENDFIB:
|
2008-03-20 17:59:19 +00:00
|
|
|
case FSACTL_SEND_LARGE_FIB:
|
2001-09-05 20:43:02 +00:00
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_SENDFIB:
|
2008-03-20 17:59:19 +00:00
|
|
|
case FSACTL_LNX_SEND_LARGE_FIB:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_SENDFIB");
|
2001-09-05 20:43:02 +00:00
|
|
|
error = aac_ioctl_sendfib(sc, arg);
|
|
|
|
break;
|
2008-03-20 17:59:19 +00:00
|
|
|
case FSACTL_SEND_RAW_SRB:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_SEND_RAW_SRB:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_SEND_RAW_SRB");
|
2008-03-20 17:59:19 +00:00
|
|
|
error = aac_ioctl_send_raw_srb(sc, arg);
|
|
|
|
break;
|
2001-09-05 20:43:02 +00:00
|
|
|
case FSACTL_AIF_THREAD:
|
|
|
|
case FSACTL_LNX_AIF_THREAD:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_AIF_THREAD");
|
2001-09-05 20:43:02 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
case FSACTL_OPEN_GET_ADAPTER_FIB:
|
|
|
|
arg = *(caddr_t*)arg;
|
2001-12-02 03:47:33 +00:00
|
|
|
case FSACTL_LNX_OPEN_GET_ADAPTER_FIB:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_OPEN_GET_ADAPTER_FIB");
|
2007-12-07 00:22:23 +00:00
|
|
|
error = aac_open_aif(sc, arg);
|
2001-09-05 20:43:02 +00:00
|
|
|
break;
|
|
|
|
case FSACTL_GET_NEXT_ADAPTER_FIB:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_GET_NEXT_ADAPTER_FIB:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_NEXT_ADAPTER_FIB");
|
2001-09-05 20:43:02 +00:00
|
|
|
error = aac_getnext_aif(sc, arg);
|
|
|
|
break;
|
|
|
|
case FSACTL_CLOSE_GET_ADAPTER_FIB:
|
2007-12-07 00:22:23 +00:00
|
|
|
arg = *(caddr_t*)arg;
|
2001-09-05 20:43:02 +00:00
|
|
|
case FSACTL_LNX_CLOSE_GET_ADAPTER_FIB:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_CLOSE_GET_ADAPTER_FIB");
|
2007-12-07 00:22:23 +00:00
|
|
|
error = aac_close_aif(sc, arg);
|
2001-09-05 20:43:02 +00:00
|
|
|
break;
|
|
|
|
case FSACTL_MINIPORT_REV_CHECK:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_MINIPORT_REV_CHECK:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_MINIPORT_REV_CHECK");
|
2001-09-05 20:43:02 +00:00
|
|
|
error = aac_rev_check(sc, arg);
|
|
|
|
break;
|
|
|
|
case FSACTL_QUERY_DISK:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_QUERY_DISK:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_QUERY_DISK");
|
2001-09-05 20:43:02 +00:00
|
|
|
error = aac_query_disk(sc, arg);
|
2005-10-08 15:55:09 +00:00
|
|
|
break;
|
2001-09-05 20:43:02 +00:00
|
|
|
case FSACTL_DELETE_DISK:
|
|
|
|
case FSACTL_LNX_DELETE_DISK:
|
|
|
|
/*
|
|
|
|
* We don't trust the underland to tell us when to delete a
|
2005-11-13 17:26:36 +00:00
|
|
|
* container, rather we rely on an AIF coming from the
|
2001-09-05 20:43:02 +00:00
|
|
|
* controller
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
break;
|
2005-10-08 15:55:09 +00:00
|
|
|
case FSACTL_GET_PCI_INFO:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_GET_PCI_INFO:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_PCI_INFO");
|
2005-10-08 15:55:09 +00:00
|
|
|
error = aac_get_pci_info(sc, arg);
|
|
|
|
break;
|
2008-03-28 19:07:25 +00:00
|
|
|
case FSACTL_GET_FEATURES:
|
|
|
|
arg = *(caddr_t*)arg;
|
|
|
|
case FSACTL_LNX_GET_FEATURES:
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "FSACTL_GET_FEATURES");
|
|
|
|
error = aac_supported_features(sc, arg);
|
|
|
|
break;
|
2001-09-05 20:43:02 +00:00
|
|
|
default:
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "unsupported cmd 0x%lx\n", cmd);
|
2001-09-05 20:43:02 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 03:47:33 +00:00
|
|
|
static int
|
2009-05-20 17:29:21 +00:00
|
|
|
aac_poll(struct cdev *dev, int poll_events, struct thread *td)
|
2001-12-02 03:47:33 +00:00
|
|
|
{
|
|
|
|
struct aac_softc *sc;
|
2008-06-24 03:26:41 +00:00
|
|
|
struct aac_fib_context *ctx;
|
2001-12-02 03:47:33 +00:00
|
|
|
int revents;
|
|
|
|
|
|
|
|
sc = dev->si_drv1;
|
|
|
|
revents = 0;
|
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_aifq_lock);
|
2001-12-02 03:47:33 +00:00
|
|
|
if ((poll_events & (POLLRDNORM | POLLIN)) != 0) {
|
2008-06-24 03:26:41 +00:00
|
|
|
for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
|
|
|
|
if (ctx->ctx_idx != sc->aifq_idx || ctx->ctx_wrap) {
|
|
|
|
revents |= poll_events & (POLLIN | POLLRDNORM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-12-02 03:47:33 +00:00
|
|
|
}
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
2001-12-02 03:47:33 +00:00
|
|
|
|
|
|
|
if (revents == 0) {
|
|
|
|
if (poll_events & (POLLIN | POLLRDNORM))
|
|
|
|
selrecord(td, &sc->rcv_select);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
static void
|
|
|
|
aac_ioctl_event(struct aac_softc *sc, struct aac_event *event, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (event->ev_type) {
|
|
|
|
case AAC_EVENT_CMFREE:
|
2007-12-19 14:33:40 +00:00
|
|
|
mtx_assert(&sc->aac_io_lock, MA_OWNED);
|
2007-02-14 09:10:37 +00:00
|
|
|
if (aac_alloc_command(sc, (struct aac_command **)arg)) {
|
2005-10-08 15:55:09 +00:00
|
|
|
aac_add_event(sc, event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(event, M_AACBUF);
|
2005-10-08 22:41:57 +00:00
|
|
|
wakeup(arg);
|
2005-10-08 15:55:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Send a FIB supplied from userspace
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
int size, error;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
cm = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a command
|
|
|
|
*/
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
if (aac_alloc_command(sc, &cm)) {
|
2005-10-08 15:55:09 +00:00
|
|
|
struct aac_event *event;
|
|
|
|
|
|
|
|
event = malloc(sizeof(struct aac_event), M_AACBUF,
|
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (event == NULL) {
|
|
|
|
error = EBUSY;
|
2007-12-20 21:13:58 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2005-10-08 15:55:09 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
event->ev_type = AAC_EVENT_CMFREE;
|
|
|
|
event->ev_callback = aac_ioctl_event;
|
|
|
|
event->ev_arg = &cm;
|
|
|
|
aac_add_event(sc, event);
|
2005-10-08 22:41:57 +00:00
|
|
|
msleep(&cm, &sc->aac_io_lock, 0, "sendfib", 0);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2006-04-08 06:05:29 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch the FIB header, then re-copy to get data as well.
|
|
|
|
*/
|
|
|
|
if ((error = copyin(ufib, cm->cm_fib,
|
|
|
|
sizeof(struct aac_fib_header))) != 0)
|
|
|
|
goto out;
|
|
|
|
size = cm->cm_fib->Header.Size + sizeof(struct aac_fib_header);
|
2008-03-20 17:59:19 +00:00
|
|
|
if (size > sc->aac_max_fib_size) {
|
|
|
|
device_printf(sc->aac_dev, "incoming FIB oversized (%d > %d)\n",
|
|
|
|
size, sc->aac_max_fib_size);
|
|
|
|
size = sc->aac_max_fib_size;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
if ((error = copyin(ufib, cm->cm_fib, size)) != 0)
|
|
|
|
goto out;
|
|
|
|
cm->cm_fib->Header.Size = size;
|
2005-09-14 05:46:28 +00:00
|
|
|
cm->cm_timestamp = time_uptime;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass the FIB to the controller, wait for it to complete.
|
|
|
|
*/
|
2006-04-08 06:05:29 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2007-12-20 21:13:58 +00:00
|
|
|
error = aac_wait_command(cm);
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
if (error != 0) {
|
2003-02-05 23:24:25 +00:00
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"aac_wait_command return %d\n", error);
|
2001-09-05 20:43:02 +00:00
|
|
|
goto out;
|
2001-12-02 03:47:33 +00:00
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the FIB and data back out to the caller.
|
|
|
|
*/
|
|
|
|
size = cm->cm_fib->Header.Size;
|
2008-03-20 17:59:19 +00:00
|
|
|
if (size > sc->aac_max_fib_size) {
|
|
|
|
device_printf(sc->aac_dev, "outbound FIB oversized (%d > %d)\n",
|
|
|
|
size, sc->aac_max_fib_size);
|
|
|
|
size = sc->aac_max_fib_size;
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
error = copyout(cm->cm_fib, ufib, size);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
|
|
|
out:
|
2001-09-05 20:43:02 +00:00
|
|
|
if (cm != NULL) {
|
2007-12-20 21:13:58 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
aac_release_command(cm);
|
2007-12-20 21:13:58 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2008-03-20 17:59:19 +00:00
|
|
|
/*
|
|
|
|
* Send a passthrough FIB supplied from userspace
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_ioctl_send_raw_srb(struct aac_softc *sc, caddr_t arg)
|
|
|
|
{
|
2010-03-14 22:38:18 +00:00
|
|
|
struct aac_command *cm;
|
|
|
|
struct aac_event *event;
|
|
|
|
struct aac_fib *fib;
|
|
|
|
struct aac_srb *srbcmd, *user_srb;
|
|
|
|
struct aac_sg_entry *sge;
|
|
|
|
struct aac_sg_entry64 *sge64;
|
|
|
|
void *srb_sg_address, *ureply;
|
|
|
|
uint32_t fibsize, srb_sg_bytecount;
|
|
|
|
int error, transfer_data;
|
|
|
|
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
|
|
|
|
|
|
|
cm = NULL;
|
|
|
|
transfer_data = 0;
|
|
|
|
fibsize = 0;
|
|
|
|
user_srb = (struct aac_srb *)arg;
|
|
|
|
|
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
if (aac_alloc_command(sc, &cm)) {
|
|
|
|
event = malloc(sizeof(struct aac_event), M_AACBUF,
|
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (event == NULL) {
|
|
|
|
error = EBUSY;
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
event->ev_type = AAC_EVENT_CMFREE;
|
|
|
|
event->ev_callback = aac_ioctl_event;
|
|
|
|
event->ev_arg = &cm;
|
|
|
|
aac_add_event(sc, event);
|
|
|
|
msleep(cm, &sc->aac_io_lock, 0, "aacraw", 0);
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
|
|
|
|
cm->cm_data = NULL;
|
|
|
|
fib = cm->cm_fib;
|
|
|
|
srbcmd = (struct aac_srb *)fib->data;
|
|
|
|
error = copyin(&user_srb->data_len, &fibsize, sizeof(uint32_t));
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
if (fibsize > (sc->aac_max_fib_size - sizeof(struct aac_fib_header))) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
error = copyin(user_srb, srbcmd, fibsize);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
srbcmd->function = 0;
|
|
|
|
srbcmd->retry_limit = 0;
|
|
|
|
if (srbcmd->sg_map.SgCount > 1) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve correct SG entries. */
|
|
|
|
if (fibsize == (sizeof(struct aac_srb) +
|
|
|
|
srbcmd->sg_map.SgCount * sizeof(struct aac_sg_entry))) {
|
|
|
|
sge = srbcmd->sg_map.SgEntry;
|
|
|
|
sge64 = NULL;
|
|
|
|
srb_sg_bytecount = sge->SgByteCount;
|
2010-03-15 14:20:16 +00:00
|
|
|
srb_sg_address = (void *)(uintptr_t)sge->SgAddress;
|
2010-03-14 22:38:18 +00:00
|
|
|
}
|
|
|
|
#ifdef __amd64__
|
|
|
|
else if (fibsize == (sizeof(struct aac_srb) +
|
|
|
|
srbcmd->sg_map.SgCount * sizeof(struct aac_sg_entry64))) {
|
|
|
|
sge = NULL;
|
|
|
|
sge64 = (struct aac_sg_entry64 *)srbcmd->sg_map.SgEntry;
|
|
|
|
srb_sg_bytecount = sge64->SgByteCount;
|
|
|
|
srb_sg_address = (void *)sge64->SgAddress;
|
|
|
|
if (sge64->SgAddress > 0xffffffffull &&
|
|
|
|
(sc->flags & AAC_FLAGS_SG_64BIT) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ureply = (char *)arg + fibsize;
|
|
|
|
srbcmd->data_len = srb_sg_bytecount;
|
|
|
|
if (srbcmd->sg_map.SgCount == 1)
|
|
|
|
transfer_data = 1;
|
|
|
|
|
|
|
|
cm->cm_sgtable = (struct aac_sg_table *)&srbcmd->sg_map;
|
|
|
|
if (transfer_data) {
|
|
|
|
cm->cm_datalen = srb_sg_bytecount;
|
|
|
|
cm->cm_data = malloc(cm->cm_datalen, M_AACBUF, M_NOWAIT);
|
|
|
|
if (cm->cm_data == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (srbcmd->flags & AAC_SRB_FLAGS_DATA_IN)
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAIN;
|
|
|
|
if (srbcmd->flags & AAC_SRB_FLAGS_DATA_OUT) {
|
|
|
|
cm->cm_flags |= AAC_CMD_DATAOUT;
|
|
|
|
error = copyin(srb_sg_address, cm->cm_data,
|
|
|
|
cm->cm_datalen);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fib->Header.Size = sizeof(struct aac_fib_header) +
|
|
|
|
sizeof(struct aac_srb);
|
|
|
|
fib->Header.XferState =
|
|
|
|
AAC_FIBSTATE_HOSTOWNED |
|
|
|
|
AAC_FIBSTATE_INITIALISED |
|
|
|
|
AAC_FIBSTATE_EMPTY |
|
|
|
|
AAC_FIBSTATE_FROMHOST |
|
|
|
|
AAC_FIBSTATE_REXPECTED |
|
|
|
|
AAC_FIBSTATE_NORM |
|
|
|
|
AAC_FIBSTATE_ASYNC |
|
|
|
|
AAC_FIBSTATE_FAST_RESPONSE;
|
|
|
|
fib->Header.Command = (sc->flags & AAC_FLAGS_SG_64BIT) != 0 ?
|
|
|
|
ScsiPortCommandU64 : ScsiPortCommand;
|
|
|
|
|
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
aac_wait_command(cm);
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
|
|
|
|
if (transfer_data && (srbcmd->flags & AAC_SRB_FLAGS_DATA_IN) != 0) {
|
|
|
|
error = copyout(cm->cm_data, srb_sg_address, cm->cm_datalen);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
error = copyout(fib->data, ureply, sizeof(struct aac_srb_response));
|
|
|
|
out:
|
|
|
|
if (cm != NULL) {
|
|
|
|
if (cm->cm_data != NULL)
|
|
|
|
free(cm->cm_data, M_AACBUF);
|
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
aac_release_command(cm);
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
|
|
|
}
|
|
|
|
return(error);
|
2008-03-20 17:59:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 17:49:10 +00:00
|
|
|
/*
|
|
|
|
* cdevpriv interface private destructor.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
aac_cdevpriv_dtor(void *arg)
|
|
|
|
{
|
|
|
|
struct aac_softc *sc;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
device_unbusy(sc->aac_dev);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Handle an AIF sent to us by the controller; queue it for later reference.
|
2001-08-29 23:34:05 +00:00
|
|
|
* If the queue fills up, then drop the older entries.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static void
|
2001-08-29 23:34:05 +00:00
|
|
|
aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_aif_command *aif;
|
|
|
|
struct aac_container *co, *co_next;
|
2007-12-07 00:22:23 +00:00
|
|
|
struct aac_fib_context *ctx;
|
2008-03-24 16:38:47 +00:00
|
|
|
struct aac_mntinforesp *mir;
|
2007-12-07 00:22:23 +00:00
|
|
|
int next, current, found;
|
2003-06-03 02:10:55 +00:00
|
|
|
int count = 0, added = 0, i = 0;
|
2010-09-29 14:22:00 +00:00
|
|
|
uint32_t channel;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
aif = (struct aac_aif_command*)&fib->data[0];
|
|
|
|
aac_print_aif(sc, aif);
|
|
|
|
|
|
|
|
/* Is it an event that we should care about? */
|
|
|
|
switch (aif->command) {
|
|
|
|
case AifCmdEventNotify:
|
|
|
|
switch (aif->data.EN.type) {
|
|
|
|
case AifEnAddContainer:
|
|
|
|
case AifEnDeleteContainer:
|
|
|
|
/*
|
2005-11-13 17:26:36 +00:00
|
|
|
* A container was added or deleted, but the message
|
2001-09-05 20:43:02 +00:00
|
|
|
* doesn't tell us anything else! Re-enumerate the
|
|
|
|
* containers and sort things out.
|
|
|
|
*/
|
2004-06-02 18:15:48 +00:00
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
2001-09-05 20:43:02 +00:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Ask the controller for its containers one at
|
|
|
|
* a time.
|
|
|
|
* XXX What if the controller's list changes
|
|
|
|
* midway through this enumaration?
|
|
|
|
* XXX This should be done async.
|
|
|
|
*/
|
2008-03-24 16:38:47 +00:00
|
|
|
if ((mir = aac_get_container_info(sc, fib, i)) == NULL)
|
2001-09-05 20:43:02 +00:00
|
|
|
continue;
|
2008-03-24 16:38:47 +00:00
|
|
|
if (i == 0)
|
|
|
|
count = mir->MntRespCount;
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Check the container against our list.
|
|
|
|
* co->co_found was already set to 0 in a
|
|
|
|
* previous run.
|
|
|
|
*/
|
2002-04-24 05:12:50 +00:00
|
|
|
if ((mir->Status == ST_OK) &&
|
|
|
|
(mir->MntTable[0].VolType != CT_NONE)) {
|
2001-09-05 20:43:02 +00:00
|
|
|
found = 0;
|
|
|
|
TAILQ_FOREACH(co,
|
2005-11-13 17:26:36 +00:00
|
|
|
&sc->aac_container_tqh,
|
2001-09-05 20:43:02 +00:00
|
|
|
co_link) {
|
|
|
|
if (co->co_mntobj.ObjectId ==
|
2002-04-24 05:12:50 +00:00
|
|
|
mir->MntTable[0].ObjectId) {
|
2001-09-05 20:43:02 +00:00
|
|
|
co->co_found = 1;
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the container matched, continue
|
|
|
|
* in the list.
|
|
|
|
*/
|
|
|
|
if (found) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a new container. Do all the
|
2003-02-05 23:24:25 +00:00
|
|
|
* appropriate things to set it up.
|
|
|
|
*/
|
2002-04-24 05:12:50 +00:00
|
|
|
aac_add_container(sc, mir, 1);
|
2001-09-05 20:43:02 +00:00
|
|
|
added = 1;
|
|
|
|
}
|
|
|
|
i++;
|
2003-06-03 02:10:55 +00:00
|
|
|
} while ((i < count) && (i < AAC_MAX_CONTAINERS));
|
2002-04-24 05:12:50 +00:00
|
|
|
aac_release_sync_fib(sc);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through our list of containers and see which ones
|
|
|
|
* were not marked 'found'. Since the controller didn't
|
|
|
|
* list them they must have been deleted. Do the
|
|
|
|
* appropriate steps to destroy the device. Also reset
|
|
|
|
* the co->co_found field.
|
|
|
|
*/
|
|
|
|
co = TAILQ_FIRST(&sc->aac_container_tqh);
|
|
|
|
while (co != NULL) {
|
|
|
|
if (co->co_found == 0) {
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-09-05 20:43:02 +00:00
|
|
|
device_delete_child(sc->aac_dev,
|
|
|
|
co->co_disk);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
co_next = TAILQ_NEXT(co, co_link);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_container_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
TAILQ_REMOVE(&sc->aac_container_tqh, co,
|
|
|
|
co_link);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_container_lock);
|
2004-08-12 05:09:17 +00:00
|
|
|
free(co, M_AACBUF);
|
2001-09-05 20:43:02 +00:00
|
|
|
co = co_next;
|
|
|
|
} else {
|
|
|
|
co->co_found = 0;
|
|
|
|
co = TAILQ_NEXT(co, co_link);
|
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Attach the newly created containers */
|
2005-10-08 15:55:09 +00:00
|
|
|
if (added) {
|
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-09-05 20:43:02 +00:00
|
|
|
bus_generic_attach(sc->aac_dev);
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2005-10-08 15:55:09 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
|
|
|
}
|
2005-11-13 17:26:36 +00:00
|
|
|
|
2002-10-20 16:00:43 +00:00
|
|
|
break;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2010-09-29 14:22:00 +00:00
|
|
|
case AifEnEnclosureManagement:
|
|
|
|
switch (aif->data.EN.data.EEE.eventType) {
|
|
|
|
case AIF_EM_DRIVE_INSERTION:
|
|
|
|
case AIF_EM_DRIVE_REMOVAL:
|
|
|
|
channel = aif->data.EN.data.EEE.unitID;
|
|
|
|
if (sc->cam_rescan_cb != NULL)
|
|
|
|
sc->cam_rescan_cb(sc,
|
|
|
|
(channel >> 24) & 0xF,
|
|
|
|
(channel & 0xFFFF));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AifEnAddJBOD:
|
|
|
|
case AifEnDeleteJBOD:
|
|
|
|
channel = aif->data.EN.data.ECE.container;
|
|
|
|
if (sc->cam_rescan_cb != NULL)
|
|
|
|
sc->cam_rescan_cb(sc, (channel >> 24) & 0xF,
|
|
|
|
AAC_CAM_TARGET_WILDCARD);
|
|
|
|
break;
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
|
|
|
|
default:
|
2001-09-05 20:43:02 +00:00
|
|
|
break;
|
2001-08-29 23:34:05 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/* Copy the AIF data to the AIF queue for ioctl retrieval */
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_aifq_lock);
|
2007-12-07 00:22:23 +00:00
|
|
|
current = sc->aifq_idx;
|
|
|
|
next = (current + 1) % AAC_AIFQ_LENGTH;
|
|
|
|
if (next == 0)
|
|
|
|
sc->aifq_filled = 1;
|
|
|
|
bcopy(fib, &sc->aac_aifq[current], sizeof(struct aac_fib));
|
|
|
|
/* modify AIF contexts */
|
|
|
|
if (sc->aifq_filled) {
|
|
|
|
for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
|
|
|
|
if (next == ctx->ctx_idx)
|
|
|
|
ctx->ctx_wrap = 1;
|
|
|
|
else if (current == ctx->ctx_idx && ctx->ctx_wrap)
|
|
|
|
ctx->ctx_idx = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->aifq_idx = next;
|
|
|
|
/* On the off chance that someone is sleeping for an aif... */
|
|
|
|
if (sc->aac_state & AAC_STATE_AIF_SLEEPER)
|
|
|
|
wakeup(sc->aac_aifq);
|
|
|
|
/* Wakeup any poll()ers */
|
|
|
|
selwakeuppri(&sc->rcv_select, PRIBIO);
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
return;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Return the Revision of the driver to userspace and check to see if the
|
2001-08-29 23:34:05 +00:00
|
|
|
* userspace app is possibly compatible. This is extremely bogus since
|
|
|
|
* our driver doesn't follow Adaptec's versioning system. Cheat by just
|
|
|
|
* returning what the card reported.
|
2000-09-13 03:20:35 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-08-06 04:34:47 +00:00
|
|
|
aac_rev_check(struct aac_softc *sc, caddr_t udata)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_rev_check rev_check;
|
|
|
|
struct aac_rev_check_resp rev_check_resp;
|
|
|
|
int error = 0;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Copyin the revision struct from userspace
|
|
|
|
*/
|
|
|
|
if ((error = copyin(udata, (caddr_t)&rev_check,
|
2001-08-03 00:50:30 +00:00
|
|
|
sizeof(struct aac_rev_check))) != 0) {
|
2001-09-05 20:43:02 +00:00
|
|
|
return error;
|
|
|
|
}
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_IOCTL_COMMANDS_B, "Userland revision= %d\n",
|
2001-09-05 20:43:02 +00:00
|
|
|
rev_check.callingRevision.buildNumber);
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
|
|
|
* Doctor up the response struct.
|
|
|
|
*/
|
|
|
|
rev_check_resp.possiblyCompatible = 1;
|
2010-02-14 17:14:11 +00:00
|
|
|
rev_check_resp.adapterSWRevision.external.comp.major =
|
|
|
|
AAC_DRIVER_MAJOR_VERSION;
|
|
|
|
rev_check_resp.adapterSWRevision.external.comp.minor =
|
|
|
|
AAC_DRIVER_MINOR_VERSION;
|
|
|
|
rev_check_resp.adapterSWRevision.external.comp.type =
|
|
|
|
AAC_DRIVER_TYPE;
|
|
|
|
rev_check_resp.adapterSWRevision.external.comp.dash =
|
|
|
|
AAC_DRIVER_BUGFIX_LEVEL;
|
2001-09-05 20:43:02 +00:00
|
|
|
rev_check_resp.adapterSWRevision.buildNumber =
|
2010-02-14 17:14:11 +00:00
|
|
|
AAC_DRIVER_BUILD;
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
return(copyout((caddr_t)&rev_check_resp, udata,
|
|
|
|
sizeof(struct aac_rev_check_resp)));
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-07 00:22:23 +00:00
|
|
|
/*
|
|
|
|
* Pass the fib context to the caller
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_open_aif(struct aac_softc *sc, caddr_t arg)
|
|
|
|
{
|
|
|
|
struct aac_fib_context *fibctx, *ctx;
|
|
|
|
int error = 0;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2007-12-07 00:22:23 +00:00
|
|
|
|
|
|
|
fibctx = malloc(sizeof(struct aac_fib_context), M_AACBUF, M_NOWAIT|M_ZERO);
|
|
|
|
if (fibctx == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
mtx_lock(&sc->aac_aifq_lock);
|
|
|
|
/* all elements are already 0, add to queue */
|
|
|
|
if (sc->fibctx == NULL)
|
|
|
|
sc->fibctx = fibctx;
|
|
|
|
else {
|
|
|
|
for (ctx = sc->fibctx; ctx->next; ctx = ctx->next)
|
|
|
|
;
|
|
|
|
ctx->next = fibctx;
|
|
|
|
fibctx->prev = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* evaluate unique value */
|
|
|
|
fibctx->unique = (*(u_int32_t *)&fibctx & 0xffffffff);
|
|
|
|
ctx = sc->fibctx;
|
|
|
|
while (ctx != fibctx) {
|
|
|
|
if (ctx->unique == fibctx->unique) {
|
|
|
|
fibctx->unique++;
|
|
|
|
ctx = sc->fibctx;
|
|
|
|
} else {
|
|
|
|
ctx = ctx->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
|
|
|
|
|
|
|
error = copyout(&fibctx->unique, (void *)arg, sizeof(u_int32_t));
|
|
|
|
if (error)
|
|
|
|
aac_close_aif(sc, (caddr_t)ctx);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the caller's fib context
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_close_aif(struct aac_softc *sc, caddr_t arg)
|
|
|
|
{
|
|
|
|
struct aac_fib_context *ctx;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2007-12-07 00:22:23 +00:00
|
|
|
|
|
|
|
mtx_lock(&sc->aac_aifq_lock);
|
|
|
|
for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
|
|
|
|
if (ctx->unique == *(uint32_t *)&arg) {
|
|
|
|
if (ctx == sc->fibctx)
|
|
|
|
sc->fibctx = NULL;
|
|
|
|
else {
|
|
|
|
ctx->prev->next = ctx->next;
|
|
|
|
if (ctx->next)
|
|
|
|
ctx->next->prev = ctx->prev;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
|
|
|
if (ctx)
|
|
|
|
free(ctx, M_AACBUF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-09-13 03:20:35 +00:00
|
|
|
* Pass the caller the next AIF in their queue
|
|
|
|
*/
|
|
|
|
static int
|
2001-08-06 04:34:47 +00:00
|
|
|
aac_getnext_aif(struct aac_softc *sc, caddr_t arg)
|
2000-09-13 03:20:35 +00:00
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct get_adapter_fib_ioctl agf;
|
2007-12-07 00:22:23 +00:00
|
|
|
struct aac_fib_context *ctx;
|
2003-03-01 05:07:19 +00:00
|
|
|
int error;
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-09-13 03:20:35 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
if ((error = copyin(arg, &agf, sizeof(agf))) == 0) {
|
2007-12-07 00:22:23 +00:00
|
|
|
for (ctx = sc->fibctx; ctx; ctx = ctx->next) {
|
|
|
|
if (agf.AdapterFibContext == ctx->unique)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ctx)
|
|
|
|
return (EFAULT);
|
|
|
|
|
|
|
|
error = aac_return_aif(sc, ctx, agf.AifFib);
|
|
|
|
if (error == EAGAIN && agf.Wait) {
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_AIF_B, "aac_getnext_aif(): waiting for AIF");
|
2007-12-07 00:22:23 +00:00
|
|
|
sc->aac_state |= AAC_STATE_AIF_SLEEPER;
|
|
|
|
while (error == EAGAIN) {
|
|
|
|
error = tsleep(sc->aac_aifq, PRIBIO |
|
|
|
|
PCATCH, "aacaif", 0);
|
|
|
|
if (error == 0)
|
|
|
|
error = aac_return_aif(sc, ctx, agf.AifFib);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2007-12-07 00:22:23 +00:00
|
|
|
sc->aac_state &= ~AAC_STATE_AIF_SLEEPER;
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2000-09-13 03:20:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2000-12-27 13:14:56 +00:00
|
|
|
* Hand the next AIF off the top of the queue out to userspace.
|
|
|
|
*/
|
|
|
|
static int
|
2007-12-07 00:22:23 +00:00
|
|
|
aac_return_aif(struct aac_softc *sc, struct aac_fib_context *ctx, caddr_t uptr)
|
2000-12-27 13:14:56 +00:00
|
|
|
{
|
2007-12-07 00:22:23 +00:00
|
|
|
int current, error;
|
2000-12-27 13:14:56 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2000-12-27 13:14:56 +00:00
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_aifq_lock);
|
2007-12-07 00:22:23 +00:00
|
|
|
current = ctx->ctx_idx;
|
|
|
|
if (current == sc->aifq_idx && !ctx->ctx_wrap) {
|
|
|
|
/* empty */
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
2003-10-17 21:44:06 +00:00
|
|
|
return (EAGAIN);
|
2001-09-05 20:43:02 +00:00
|
|
|
}
|
2007-12-07 00:22:23 +00:00
|
|
|
error =
|
|
|
|
copyout(&sc->aac_aifq[current], (void *)uptr, sizeof(struct aac_fib));
|
2003-10-17 21:44:06 +00:00
|
|
|
if (error)
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"aac_return_aif: copyout returned %d\n", error);
|
2007-12-07 00:22:23 +00:00
|
|
|
else {
|
|
|
|
ctx->ctx_wrap = 0;
|
|
|
|
ctx->ctx_idx = (current + 1) % AAC_AIFQ_LENGTH;
|
|
|
|
}
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_aifq_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
return(error);
|
2000-12-27 13:14:56 +00:00
|
|
|
}
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2005-10-08 15:55:09 +00:00
|
|
|
static int
|
|
|
|
aac_get_pci_info(struct aac_softc *sc, caddr_t uptr)
|
|
|
|
{
|
|
|
|
struct aac_pci_info {
|
|
|
|
u_int32_t bus;
|
|
|
|
u_int32_t slot;
|
|
|
|
} pciinf;
|
|
|
|
int error;
|
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2005-10-08 15:55:09 +00:00
|
|
|
|
|
|
|
pciinf.bus = pci_get_bus(sc->aac_dev);
|
|
|
|
pciinf.slot = pci_get_slot(sc->aac_dev);
|
|
|
|
|
|
|
|
error = copyout((caddr_t)&pciinf, uptr,
|
|
|
|
sizeof(struct aac_pci_info));
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-03-28 19:07:25 +00:00
|
|
|
static int
|
|
|
|
aac_supported_features(struct aac_softc *sc, caddr_t uptr)
|
|
|
|
{
|
|
|
|
struct aac_features f;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
|
|
|
|
|
|
|
if ((error = copyin(uptr, &f, sizeof (f))) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the management driver receives FSACTL_GET_FEATURES ioctl with
|
|
|
|
* ALL zero in the featuresState, the driver will return the current
|
|
|
|
* state of all the supported features, the data field will not be
|
|
|
|
* valid.
|
|
|
|
* When the management driver receives FSACTL_GET_FEATURES ioctl with
|
|
|
|
* a specific bit set in the featuresState, the driver will return the
|
|
|
|
* current state of this specific feature and whatever data that are
|
|
|
|
* associated with the feature in the data field or perform whatever
|
|
|
|
* action needed indicates in the data field.
|
|
|
|
*/
|
2009-09-09 04:04:09 +00:00
|
|
|
if (f.feat.fValue == 0) {
|
2008-03-28 19:07:25 +00:00
|
|
|
f.feat.fBits.largeLBA =
|
|
|
|
(sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0;
|
|
|
|
/* TODO: In the future, add other features state here as well */
|
|
|
|
} else {
|
|
|
|
if (f.feat.fBits.largeLBA)
|
|
|
|
f.feat.fBits.largeLBA =
|
|
|
|
(sc->flags & AAC_FLAGS_LBA_64BIT) ? 1 : 0;
|
|
|
|
/* TODO: Add other features state and data in the future */
|
|
|
|
}
|
|
|
|
|
|
|
|
error = copyout(&f, uptr, sizeof (f));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
/*
|
2001-08-29 23:34:05 +00:00
|
|
|
* Give the userland some information about the container. The AAC arch
|
|
|
|
* expects the driver to be a SCSI passthrough type driver, so it expects
|
|
|
|
* the containers to have b:t:l numbers. Fake it.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
aac_query_disk(struct aac_softc *sc, caddr_t uptr)
|
|
|
|
{
|
2001-09-05 20:43:02 +00:00
|
|
|
struct aac_query_disk query_disk;
|
|
|
|
struct aac_container *co;
|
|
|
|
struct aac_disk *disk;
|
|
|
|
int error, id;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2008-03-24 19:23:33 +00:00
|
|
|
fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
disk = NULL;
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
error = copyin(uptr, (caddr_t)&query_disk,
|
|
|
|
sizeof(struct aac_query_disk));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2001-08-29 23:34:05 +00:00
|
|
|
|
2001-09-05 20:43:02 +00:00
|
|
|
id = query_disk.ContainerNumber;
|
|
|
|
if (id == -1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_lock(&sc->aac_container_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
TAILQ_FOREACH(co, &sc->aac_container_tqh, co_link) {
|
|
|
|
if (co->co_mntobj.ObjectId == id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-20 16:00:43 +00:00
|
|
|
if (co == NULL) {
|
2001-09-05 20:43:02 +00:00
|
|
|
query_disk.Valid = 0;
|
|
|
|
query_disk.Locked = 0;
|
|
|
|
query_disk.Deleted = 1; /* XXX is this right? */
|
2002-10-20 16:00:43 +00:00
|
|
|
} else {
|
|
|
|
disk = device_get_softc(co->co_disk);
|
|
|
|
query_disk.Valid = 1;
|
|
|
|
query_disk.Locked =
|
|
|
|
(disk->ad_flags & AAC_DISK_OPEN) ? 1 : 0;
|
|
|
|
query_disk.Deleted = 0;
|
|
|
|
query_disk.Bus = device_get_unit(sc->aac_dev);
|
|
|
|
query_disk.Target = disk->unit;
|
|
|
|
query_disk.Lun = 0;
|
|
|
|
query_disk.UnMapped = 0;
|
2003-02-26 02:50:27 +00:00
|
|
|
sprintf(&query_disk.diskDeviceName[0], "%s%d",
|
2009-10-27 19:37:37 +00:00
|
|
|
disk->ad_disk->d_name, disk->ad_disk->d_unit);
|
2002-10-20 16:00:43 +00:00
|
|
|
}
|
2004-08-12 05:05:06 +00:00
|
|
|
mtx_unlock(&sc->aac_container_lock);
|
2001-09-05 20:43:02 +00:00
|
|
|
|
|
|
|
error = copyout((caddr_t)&query_disk, uptr,
|
|
|
|
sizeof(struct aac_query_disk));
|
|
|
|
|
|
|
|
return (error);
|
2001-08-29 23:34:05 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 01:31:17 +00:00
|
|
|
static void
|
|
|
|
aac_get_bus_info(struct aac_softc *sc)
|
|
|
|
{
|
|
|
|
struct aac_fib *fib;
|
|
|
|
struct aac_ctcfg *c_cmd;
|
|
|
|
struct aac_ctcfg_resp *c_resp;
|
|
|
|
struct aac_vmioctl *vmi;
|
|
|
|
struct aac_vmi_businf_resp *vmi_resp;
|
|
|
|
struct aac_getbusinf businfo;
|
2003-02-05 23:24:25 +00:00
|
|
|
struct aac_sim *caminf;
|
2002-04-27 01:31:17 +00:00
|
|
|
device_t child;
|
|
|
|
int i, found, error;
|
|
|
|
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_lock(&sc->aac_io_lock);
|
2004-06-02 18:15:48 +00:00
|
|
|
aac_alloc_sync_fib(sc, &fib);
|
2002-04-27 01:31:17 +00:00
|
|
|
c_cmd = (struct aac_ctcfg *)&fib->data[0];
|
2002-05-03 00:07:50 +00:00
|
|
|
bzero(c_cmd, sizeof(struct aac_ctcfg));
|
2002-04-27 01:31:17 +00:00
|
|
|
|
|
|
|
c_cmd->Command = VM_ContainerConfig;
|
|
|
|
c_cmd->cmd = CT_GET_SCSI_METHOD;
|
|
|
|
c_cmd->param = 0;
|
|
|
|
|
|
|
|
error = aac_sync_fib(sc, ContainerCommand, 0, fib,
|
|
|
|
sizeof(struct aac_ctcfg));
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->aac_dev, "Error %d sending "
|
|
|
|
"VM_ContainerConfig command\n", error);
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2002-04-27 01:31:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_resp = (struct aac_ctcfg_resp *)&fib->data[0];
|
|
|
|
if (c_resp->Status != ST_OK) {
|
|
|
|
device_printf(sc->aac_dev, "VM_ContainerConfig returned 0x%x\n",
|
|
|
|
c_resp->Status);
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2002-04-27 01:31:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->scsi_method_id = c_resp->param;
|
|
|
|
|
|
|
|
vmi = (struct aac_vmioctl *)&fib->data[0];
|
2002-05-03 00:07:50 +00:00
|
|
|
bzero(vmi, sizeof(struct aac_vmioctl));
|
|
|
|
|
2002-04-27 01:31:17 +00:00
|
|
|
vmi->Command = VM_Ioctl;
|
|
|
|
vmi->ObjType = FT_DRIVE;
|
|
|
|
vmi->MethId = sc->scsi_method_id;
|
|
|
|
vmi->ObjId = 0;
|
|
|
|
vmi->IoctlCmd = GetBusInfo;
|
|
|
|
|
|
|
|
error = aac_sync_fib(sc, ContainerCommand, 0, fib,
|
2008-03-20 20:33:48 +00:00
|
|
|
sizeof(struct aac_vmi_businf_resp));
|
2002-04-27 01:31:17 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(sc->aac_dev, "Error %d sending VMIoctl command\n",
|
|
|
|
error);
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2002-04-27 01:31:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmi_resp = (struct aac_vmi_businf_resp *)&fib->data[0];
|
|
|
|
if (vmi_resp->Status != ST_OK) {
|
|
|
|
device_printf(sc->aac_dev, "VM_Ioctl returned %d\n",
|
|
|
|
vmi_resp->Status);
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2002-04-27 01:31:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(&vmi_resp->BusInf, &businfo, sizeof(struct aac_getbusinf));
|
|
|
|
aac_release_sync_fib(sc);
|
2005-10-31 00:12:19 +00:00
|
|
|
mtx_unlock(&sc->aac_io_lock);
|
2002-04-27 01:31:17 +00:00
|
|
|
|
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < businfo.BusCount; i++) {
|
|
|
|
if (businfo.BusValid[i] != AAC_BUS_VALID)
|
|
|
|
continue;
|
|
|
|
|
2003-02-06 00:37:37 +00:00
|
|
|
caminf = (struct aac_sim *)malloc( sizeof(struct aac_sim),
|
|
|
|
M_AACBUF, M_NOWAIT | M_ZERO);
|
2005-03-19 06:29:32 +00:00
|
|
|
if (caminf == NULL) {
|
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"No memory to add passthrough bus %d\n", i);
|
|
|
|
break;
|
2005-10-08 15:55:09 +00:00
|
|
|
};
|
2002-04-27 01:31:17 +00:00
|
|
|
|
|
|
|
child = device_add_child(sc->aac_dev, "aacp", -1);
|
|
|
|
if (child == NULL) {
|
2005-03-19 06:29:32 +00:00
|
|
|
device_printf(sc->aac_dev,
|
|
|
|
"device_add_child failed for passthrough bus %d\n",
|
|
|
|
i);
|
|
|
|
free(caminf, M_AACBUF);
|
2005-11-13 17:26:36 +00:00
|
|
|
break;
|
2002-04-27 01:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
caminf->TargetsPerBus = businfo.TargetsPerBus;
|
|
|
|
caminf->BusNumber = i;
|
|
|
|
caminf->InitiatorBusId = businfo.InitiatorBusId[i];
|
|
|
|
caminf->aac_sc = sc;
|
2003-02-06 03:31:02 +00:00
|
|
|
caminf->sim_dev = child;
|
2002-04-27 01:31:17 +00:00
|
|
|
|
|
|
|
device_set_ivars(child, caminf);
|
|
|
|
device_set_desc(child, "SCSI Passthrough Bus");
|
2003-02-05 23:24:25 +00:00
|
|
|
TAILQ_INSERT_TAIL(&sc->aac_sim_tqh, caminf, sim_link);
|
2002-04-27 01:31:17 +00:00
|
|
|
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
bus_generic_attach(sc->aac_dev);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|