2002-05-16 06:50:53 +04:00
|
|
|
/* $NetBSD: siop.c,v 1.61 2002/05/16 02:50:53 thorpej Exp $ */
|
2000-04-21 21:56:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Manuel Bouyer.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
2002-04-24 00:41:13 +04:00
|
|
|
* This product includes software developed by Manuel Bouyer.
|
2000-04-27 18:06:57 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
2000-04-21 21:56:58 +04:00
|
|
|
*
|
2000-05-15 11:48:24 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
2000-04-21 21:56:58 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* SYM53c7/8xx PCI-SCSI I/O Processors driver */
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-05-16 06:50:53 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: siop.c,v 1.61 2002/05/16 02:50:53 thorpej Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2000-04-21 21:56:58 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2000-04-21 21:56:58 +04:00
|
|
|
#include <machine/endian.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/microcode/siop/siop.out>
|
|
|
|
|
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsi_message.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
|
|
|
|
#include <dev/ic/siopreg.h>
|
2000-05-15 11:48:24 +04:00
|
|
|
#include <dev/ic/siopvar_common.h>
|
2002-04-20 04:15:54 +04:00
|
|
|
#include <dev/ic/siopvar.h>
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2002-04-18 16:03:15 +04:00
|
|
|
#include "opt_siop.h"
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifndef DEBUG
|
2000-10-07 00:07:10 +04:00
|
|
|
#undef DEBUG
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
|
|
|
#undef SIOP_DEBUG
|
|
|
|
#undef SIOP_DEBUG_DR
|
|
|
|
#undef SIOP_DEBUG_INTR
|
|
|
|
#undef SIOP_DEBUG_SCHED
|
2000-04-25 20:27:05 +04:00
|
|
|
#undef DUMP_SCRIPT
|
|
|
|
|
|
|
|
#define SIOP_STATS
|
|
|
|
|
2000-04-21 21:56:58 +04:00
|
|
|
#ifndef SIOP_DEFAULT_TARGET
|
|
|
|
#define SIOP_DEFAULT_TARGET 7
|
|
|
|
#endif
|
|
|
|
|
2000-05-23 21:08:07 +04:00
|
|
|
/* number of cmd descriptors per block */
|
2000-11-14 21:21:00 +03:00
|
|
|
#define SIOP_NCMDPB (PAGE_SIZE / sizeof(struct siop_xfer))
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
/* Number of scheduler slot (needs to match script) */
|
|
|
|
#define SIOP_NSLOTS 40
|
|
|
|
|
2000-04-21 21:56:58 +04:00
|
|
|
void siop_reset __P((struct siop_softc *));
|
2000-04-25 20:27:05 +04:00
|
|
|
void siop_handle_reset __P((struct siop_softc *));
|
2000-10-18 21:06:52 +04:00
|
|
|
int siop_handle_qtag_reject __P((struct siop_cmd *));
|
2000-04-25 20:27:05 +04:00
|
|
|
void siop_scsicmd_end __P((struct siop_cmd *));
|
2001-04-25 21:53:04 +04:00
|
|
|
void siop_unqueue __P((struct siop_softc *, int, int));
|
|
|
|
static void siop_start __P((struct siop_softc *, struct siop_cmd *));
|
2000-04-21 21:56:58 +04:00
|
|
|
void siop_timeout __P((void *));
|
|
|
|
int siop_scsicmd __P((struct scsipi_xfer *));
|
2001-04-25 21:53:04 +04:00
|
|
|
void siop_scsipi_request __P((struct scsipi_channel *,
|
|
|
|
scsipi_adapter_req_t, void *));
|
2000-04-25 20:27:05 +04:00
|
|
|
void siop_dump_script __P((struct siop_softc *));
|
2001-10-15 00:37:28 +04:00
|
|
|
void siop_morecbd __P((struct siop_softc *));
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lunsw *siop_get_lunsw __P((struct siop_softc *));
|
|
|
|
void siop_add_reselsw __P((struct siop_softc *, int));
|
2002-04-20 04:15:54 +04:00
|
|
|
void siop_update_scntl3 __P((struct siop_softc *,
|
|
|
|
struct siop_common_target *));
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
#ifdef SIOP_STATS
|
|
|
|
static int siop_stat_intr = 0;
|
|
|
|
static int siop_stat_intr_shortxfer = 0;
|
|
|
|
static int siop_stat_intr_sdp = 0;
|
|
|
|
static int siop_stat_intr_done = 0;
|
|
|
|
static int siop_stat_intr_xferdisc = 0;
|
2000-10-23 18:56:16 +04:00
|
|
|
static int siop_stat_intr_lunresel = 0;
|
2000-10-24 03:18:10 +04:00
|
|
|
static int siop_stat_intr_qfull = 0;
|
2000-04-25 20:27:05 +04:00
|
|
|
void siop_printstats __P((void));
|
|
|
|
#define INCSTAT(x) x++
|
|
|
|
#else
|
|
|
|
#define INCSTAT(x)
|
|
|
|
#endif
|
|
|
|
|
2000-10-19 00:06:54 +04:00
|
|
|
static __inline__ void siop_script_sync __P((struct siop_softc *, int));
|
|
|
|
static __inline__ void
|
|
|
|
siop_script_sync(sc, ops)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
int ops;
|
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
if ((sc->sc_c.features & SF_CHIP_RAM) == 0)
|
|
|
|
bus_dmamap_sync(sc->sc_c.sc_dmat, sc->sc_c.sc_scriptdma, 0,
|
2000-11-14 21:21:00 +03:00
|
|
|
PAGE_SIZE, ops);
|
2000-10-19 00:06:54 +04:00
|
|
|
}
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
static __inline__ u_int32_t siop_script_read __P((struct siop_softc *, u_int));
|
2000-10-18 21:06:52 +04:00
|
|
|
static __inline__ u_int32_t
|
|
|
|
siop_script_read(sc, offset)
|
|
|
|
struct siop_softc *sc;
|
2000-10-23 18:56:16 +04:00
|
|
|
u_int offset;
|
2000-10-18 21:06:52 +04:00
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_RAM) {
|
|
|
|
return bus_space_read_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh,
|
|
|
|
offset * 4);
|
2000-10-18 21:06:52 +04:00
|
|
|
} else {
|
2002-04-20 04:15:54 +04:00
|
|
|
return le32toh(sc->sc_c.sc_script[offset]);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
static __inline__ void siop_script_write __P((struct siop_softc *, u_int,
|
2000-10-18 21:06:52 +04:00
|
|
|
u_int32_t));
|
2000-10-06 20:35:13 +04:00
|
|
|
static __inline__ void
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_script_write(sc, offset, val)
|
2000-10-06 20:35:13 +04:00
|
|
|
struct siop_softc *sc;
|
2000-10-23 18:56:16 +04:00
|
|
|
u_int offset;
|
2000-10-18 21:06:52 +04:00
|
|
|
u_int32_t val;
|
2000-10-06 20:35:13 +04:00
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_RAM) {
|
|
|
|
bus_space_write_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh,
|
|
|
|
offset * 4, val);
|
2000-10-18 21:06:52 +04:00
|
|
|
} else {
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[offset] = htole32(val);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
|
|
|
|
2000-04-21 21:56:58 +04:00
|
|
|
void
|
|
|
|
siop_attach(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
2002-04-23 21:33:27 +04:00
|
|
|
if (siop_common_attach(&sc->sc_c) != 0)
|
|
|
|
return;
|
2000-04-21 21:56:58 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&sc->free_list);
|
2000-05-23 21:08:07 +04:00
|
|
|
TAILQ_INIT(&sc->cmds);
|
2000-10-18 21:06:52 +04:00
|
|
|
TAILQ_INIT(&sc->lunsw_list);
|
2000-10-06 20:39:04 +04:00
|
|
|
sc->sc_currschedslot = 0;
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("%s: script size = %d, PHY addr=0x%x, VIRT=%p\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, (int)sizeof(siop_script),
|
|
|
|
(u_int32_t)sc->sc_c.sc_scriptaddr, sc->sc_c.sc_script);
|
2000-04-21 21:56:58 +04:00
|
|
|
#endif
|
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_adapt.adapt_max_periph = SIOP_NTAG - 1;
|
|
|
|
sc->sc_c.sc_adapt.adapt_request = siop_scsipi_request;
|
|
|
|
|
2000-07-24 19:15:00 +04:00
|
|
|
/* Do a bus reset, so that devices fall back to narrow/async */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_resetbus(&sc->sc_c);
|
2000-07-24 19:15:00 +04:00
|
|
|
/*
|
|
|
|
* siop_reset() will reset the chip, thus clearing pending interrupts
|
|
|
|
*/
|
2000-04-21 21:56:58 +04:00
|
|
|
siop_reset(sc);
|
2000-04-25 20:27:05 +04:00
|
|
|
#ifdef DUMP_SCRIPT
|
|
|
|
siop_dump_script(sc);
|
|
|
|
#endif
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
config_found((struct device*)sc, &sc->sc_c.sc_chan, scsiprint);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_reset(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
2000-04-27 00:00:31 +04:00
|
|
|
int i, j;
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lunsw *lunsw;
|
2000-04-27 00:00:31 +04:00
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_common_reset(&sc->sc_c);
|
2000-04-21 21:56:58 +04:00
|
|
|
|
|
|
|
/* copy and patch the script */
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_RAM) {
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh, 0,
|
2000-05-25 14:10:54 +04:00
|
|
|
siop_script, sizeof(siop_script) / sizeof(siop_script[0]));
|
2000-10-06 20:35:13 +04:00
|
|
|
for (j = 0; j <
|
2000-10-18 21:06:52 +04:00
|
|
|
(sizeof(E_abs_msgin_Used) / sizeof(E_abs_msgin_Used[0]));
|
2000-10-06 20:35:13 +04:00
|
|
|
j++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh,
|
2000-10-18 21:06:52 +04:00
|
|
|
E_abs_msgin_Used[j] * 4,
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_scriptaddr + Ent_msgin_space);
|
2000-10-06 20:35:13 +04:00
|
|
|
}
|
2002-04-23 14:38:37 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_LED0) {
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt,
|
|
|
|
sc->sc_c.sc_ramh,
|
|
|
|
Ent_led_on1, siop_led_on,
|
|
|
|
sizeof(siop_led_on) / sizeof(siop_led_on[0]));
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt,
|
|
|
|
sc->sc_c.sc_ramh,
|
|
|
|
Ent_led_on2, siop_led_on,
|
|
|
|
sizeof(siop_led_on) / sizeof(siop_led_on[0]));
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt,
|
|
|
|
sc->sc_c.sc_ramh,
|
|
|
|
Ent_led_off, siop_led_off,
|
|
|
|
sizeof(siop_led_off) / sizeof(siop_led_off[0]));
|
|
|
|
}
|
2000-05-25 14:10:54 +04:00
|
|
|
} else {
|
|
|
|
for (j = 0;
|
|
|
|
j < (sizeof(siop_script) / sizeof(siop_script[0])); j++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[j] = htole32(siop_script[j]);
|
2000-05-25 14:10:54 +04:00
|
|
|
}
|
2000-10-06 20:35:13 +04:00
|
|
|
for (j = 0; j <
|
2000-10-18 21:06:52 +04:00
|
|
|
(sizeof(E_abs_msgin_Used) / sizeof(E_abs_msgin_Used[0]));
|
2000-10-06 20:35:13 +04:00
|
|
|
j++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[E_abs_msgin_Used[j]] =
|
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_msgin_space);
|
2000-05-25 14:10:54 +04:00
|
|
|
}
|
2002-04-23 14:38:37 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_LED0) {
|
|
|
|
for (j = 0; j < (sizeof(siop_led_on) /
|
|
|
|
sizeof(siop_led_on[0])); j++)
|
|
|
|
sc->sc_c.sc_script[
|
|
|
|
Ent_led_on1 / sizeof(siop_led_on[0]) + j
|
|
|
|
] = htole32(siop_led_on[j]);
|
|
|
|
for (j = 0; j < (sizeof(siop_led_on) /
|
|
|
|
sizeof(siop_led_on[0])); j++)
|
|
|
|
sc->sc_c.sc_script[
|
|
|
|
Ent_led_on2 / sizeof(siop_led_on[0]) + j
|
|
|
|
] = htole32(siop_led_on[j]);
|
|
|
|
for (j = 0; j < (sizeof(siop_led_off) /
|
|
|
|
sizeof(siop_led_off[0])); j++)
|
|
|
|
sc->sc_c.sc_script[
|
|
|
|
Ent_led_off / sizeof(siop_led_off[0]) + j
|
|
|
|
] = htole32(siop_led_off[j]);
|
|
|
|
}
|
2000-04-27 00:00:31 +04:00
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->script_free_lo = sizeof(siop_script) / sizeof(siop_script[0]);
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->script_free_hi = sc->sc_c.ram_size / 4;
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2000-10-18 21:06:52 +04:00
|
|
|
/* free used and unused lun switches */
|
|
|
|
while((lunsw = TAILQ_FIRST(&sc->lunsw_list)) != NULL) {
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("%s: free lunsw at offset %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, lunsw->lunsw_off);
|
2000-10-18 21:06:52 +04:00
|
|
|
#endif
|
|
|
|
TAILQ_REMOVE(&sc->lunsw_list, lunsw, next);
|
|
|
|
free(lunsw, M_DEVBUF);
|
2000-10-06 20:35:13 +04:00
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
TAILQ_INIT(&sc->lunsw_list);
|
|
|
|
/* restore reselect switch */
|
2002-04-20 04:15:54 +04:00
|
|
|
for (i = 0; i < sc->sc_c.sc_chan.chan_ntargets; i++) {
|
|
|
|
struct siop_target *target;
|
|
|
|
if (sc->sc_c.targets[i] == NULL)
|
2000-10-18 21:06:52 +04:00
|
|
|
continue;
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("%s: restore sw for target %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, i);
|
2000-10-18 21:06:52 +04:00
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
target = (struct siop_target *)sc->sc_c.targets[i];
|
|
|
|
free(target->lunsw, M_DEVBUF);
|
|
|
|
target->lunsw = siop_get_lunsw(sc);
|
|
|
|
if (target->lunsw == NULL) {
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("%s: can't alloc lunsw for target %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, i);
|
2000-10-18 21:06:52 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
siop_add_reselsw(sc, i);
|
2000-10-06 20:35:13 +04:00
|
|
|
}
|
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
/* start script */
|
2002-04-20 04:15:54 +04:00
|
|
|
if ((sc->sc_c.features & SF_CHIP_RAM) == 0) {
|
|
|
|
bus_dmamap_sync(sc->sc_c.sc_dmat, sc->sc_c.sc_scriptdma, 0,
|
|
|
|
PAGE_SIZE, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2000-06-20 21:16:22 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSP,
|
|
|
|
sc->sc_c.sc_scriptaddr + Ent_reselect);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define CALL_SCRIPT(ent) do {\
|
|
|
|
printf ("start script DSA 0x%lx DSP 0x%lx\n", \
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.dsa, \
|
|
|
|
sc->sc_c.sc_scriptaddr + ent); \
|
|
|
|
bus_space_write_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSP, sc->sc_c.sc_scriptaddr + ent); \
|
2000-04-21 21:56:58 +04:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define CALL_SCRIPT(ent) do {\
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSP, sc->sc_c.sc_scriptaddr + ent); \
|
2000-04-21 21:56:58 +04:00
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
siop_intr(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct siop_softc *sc = v;
|
2000-05-02 23:03:02 +04:00
|
|
|
struct siop_target *siop_target;
|
2000-04-21 21:56:58 +04:00
|
|
|
struct siop_cmd *siop_cmd;
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lun *siop_lun;
|
2000-04-21 21:56:58 +04:00
|
|
|
struct scsipi_xfer *xs;
|
2000-10-23 18:56:16 +04:00
|
|
|
int istat, sist, sstat1, dstat;
|
2000-04-21 21:56:58 +04:00
|
|
|
u_int32_t irqcode;
|
|
|
|
int need_reset = 0;
|
2000-10-23 18:56:16 +04:00
|
|
|
int offset, target, lun, tag;
|
2000-04-25 20:27:05 +04:00
|
|
|
bus_addr_t dsa;
|
2000-05-23 21:08:07 +04:00
|
|
|
struct siop_cbd *cbdp;
|
2000-10-23 18:56:16 +04:00
|
|
|
int freetarget = 0;
|
2001-02-11 21:04:49 +03:00
|
|
|
int restart = 0;
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
istat = bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_ISTAT);
|
2000-04-25 20:27:05 +04:00
|
|
|
if ((istat & (ISTAT_INTF | ISTAT_DIP | ISTAT_SIP)) == 0)
|
|
|
|
return 0;
|
|
|
|
INCSTAT(siop_stat_intr);
|
2000-04-21 21:56:58 +04:00
|
|
|
if (istat & ISTAT_INTF) {
|
|
|
|
printf("INTRF\n");
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_ISTAT, ISTAT_INTF);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2002-04-26 00:05:10 +04:00
|
|
|
if ((istat &(ISTAT_DIP | ISTAT_SIP | ISTAT_ABRT)) ==
|
|
|
|
(ISTAT_DIP | ISTAT_ABRT)) {
|
|
|
|
/* clear abort */
|
|
|
|
bus_space_write_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_ISTAT, 0);
|
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
/* use DSA to find the current siop_cmd */
|
2002-04-20 04:15:54 +04:00
|
|
|
dsa = bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSA);
|
2000-05-23 21:08:07 +04:00
|
|
|
for (cbdp = TAILQ_FIRST(&sc->cmds); cbdp != NULL;
|
|
|
|
cbdp = TAILQ_NEXT(cbdp, next)) {
|
|
|
|
if (dsa >= cbdp->xferdma->dm_segs[0].ds_addr &&
|
2000-11-14 21:21:00 +03:00
|
|
|
dsa < cbdp->xferdma->dm_segs[0].ds_addr + PAGE_SIZE) {
|
2000-05-23 21:08:07 +04:00
|
|
|
dsa -= cbdp->xferdma->dm_segs[0].ds_addr;
|
|
|
|
siop_cmd = &cbdp->cmds[dsa / sizeof(struct siop_xfer)];
|
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cbdp == NULL) {
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_cmd = NULL;
|
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
if (siop_cmd) {
|
2002-04-20 04:15:54 +04:00
|
|
|
xs = siop_cmd->cmd_c.xs;
|
|
|
|
siop_target = (struct siop_target *)siop_cmd->cmd_c.siop_target;
|
|
|
|
target = siop_cmd->cmd_c.xs->xs_periph->periph_target;
|
|
|
|
lun = siop_cmd->cmd_c.xs->xs_periph->periph_lun;
|
|
|
|
tag = siop_cmd->cmd_c.tag;
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_lun = siop_target->siop_lun[lun];
|
2000-10-18 21:06:52 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.status != CMDST_ACTIVE) {
|
2001-06-21 20:55:20 +04:00
|
|
|
printf("siop_cmd (lun %d) for DSA 0x%x "
|
|
|
|
"not active (%d)\n", lun, (u_int)dsa,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.status);
|
2000-10-18 21:06:52 +04:00
|
|
|
xs = NULL;
|
|
|
|
siop_target = NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
target = -1;
|
2000-10-18 21:06:52 +04:00
|
|
|
lun = -1;
|
2000-10-23 18:56:16 +04:00
|
|
|
tag = -1;
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_lun = NULL;
|
|
|
|
siop_cmd = NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
} else if (siop_lun->siop_tag[tag].active != siop_cmd) {
|
|
|
|
printf("siop_cmd (lun %d tag %d) not in siop_lun "
|
|
|
|
"active (%p != %p)\n", lun, tag, siop_cmd,
|
|
|
|
siop_lun->siop_tag[tag].active);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
xs = NULL;
|
|
|
|
siop_target = NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
target = -1;
|
2000-10-18 21:06:52 +04:00
|
|
|
lun = -1;
|
2000-10-23 18:56:16 +04:00
|
|
|
tag = -1;
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_lun = NULL;
|
|
|
|
}
|
2000-04-21 21:56:58 +04:00
|
|
|
if (istat & ISTAT_DIP) {
|
2002-04-20 04:15:54 +04:00
|
|
|
dstat = bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSTAT);
|
2002-04-26 00:05:10 +04:00
|
|
|
if (dstat & DSTAT_ABRT) {
|
|
|
|
/* was probably generated by a bus reset IOCTL */
|
|
|
|
if ((dstat & DSTAT_DFE) == 0)
|
|
|
|
siop_clearfifo(&sc->sc_c);
|
|
|
|
goto reset;
|
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
if (dstat & DSTAT_SSI) {
|
|
|
|
printf("single step dsp 0x%08x dsa 0x08%x\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
(int)(bus_space_read_4(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_DSP) -
|
|
|
|
sc->sc_c.sc_scriptaddr),
|
|
|
|
bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSA));
|
2000-04-25 20:27:05 +04:00
|
|
|
if ((dstat & ~(DSTAT_DFE | DSTAT_SSI)) == 0 &&
|
|
|
|
(istat & ISTAT_SIP) == 0) {
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_DCNTL,
|
|
|
|
bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_DCNTL) | DCNTL_STD);
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2002-04-26 00:05:10 +04:00
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
if (dstat & ~(DSTAT_SIR | DSTAT_DFE | DSTAT_SSI)) {
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("DMA IRQ:");
|
|
|
|
if (dstat & DSTAT_IID)
|
|
|
|
printf(" Illegal instruction");
|
|
|
|
if (dstat & DSTAT_BF)
|
|
|
|
printf(" bus fault");
|
|
|
|
if (dstat & DSTAT_MDPE)
|
|
|
|
printf(" parity");
|
|
|
|
if (dstat & DSTAT_DFE)
|
|
|
|
printf(" dma fifo empty");
|
2002-04-26 00:05:10 +04:00
|
|
|
else
|
|
|
|
siop_clearfifo(&sc->sc_c);
|
2000-04-21 21:56:58 +04:00
|
|
|
printf(", DSP=0x%x DSA=0x%x: ",
|
2002-04-20 04:15:54 +04:00
|
|
|
(int)(bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSP) - sc->sc_c.sc_scriptaddr),
|
|
|
|
bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSA));
|
2000-04-25 20:27:05 +04:00
|
|
|
if (siop_cmd)
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("last msg_in=0x%x status=0x%x\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_in[0],
|
|
|
|
le32toh(siop_cmd->cmd_tables->status));
|
2000-06-13 00:13:41 +04:00
|
|
|
else
|
|
|
|
printf("%s: current DSA invalid\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-04-21 21:56:58 +04:00
|
|
|
need_reset = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (istat & ISTAT_SIP) {
|
|
|
|
if (istat & ISTAT_DIP)
|
2000-05-04 20:56:13 +04:00
|
|
|
delay(10);
|
2000-10-23 18:56:16 +04:00
|
|
|
/*
|
|
|
|
* Can't read sist0 & sist1 independantly, or we have to
|
|
|
|
* insert delay
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
sist = bus_space_read_2(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_SIST0);
|
|
|
|
sstat1 = bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_SSTAT1);
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_INTR
|
|
|
|
printf("scsi interrupt, sist=0x%x sstat1=0x%x "
|
|
|
|
"DSA=0x%x DSP=0x%lx\n", sist,
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_SSTAT1),
|
|
|
|
bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSA),
|
|
|
|
(u_long)(bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSP) -
|
|
|
|
sc->sc_c.sc_scriptaddr));
|
2000-04-21 21:56:58 +04:00
|
|
|
#endif
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sist & SIST0_RST) {
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_handle_reset(sc);
|
|
|
|
/* no table to flush here */
|
2000-04-21 21:56:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sist & SIST0_SGE) {
|
2000-04-21 21:56:58 +04:00
|
|
|
if (siop_cmd)
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(xs->xs_periph);
|
2000-04-21 21:56:58 +04:00
|
|
|
else
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s:", sc->sc_c.sc_dev.dv_xname);
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("scsi gross error\n");
|
|
|
|
goto reset;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if ((sist & SIST0_MA) && need_reset == 0) {
|
2000-04-21 21:56:58 +04:00
|
|
|
if (siop_cmd) {
|
2000-05-04 20:56:13 +04:00
|
|
|
int scratcha0;
|
2002-04-20 04:15:54 +04:00
|
|
|
dstat = bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_DSTAT);
|
2000-04-26 00:02:33 +04:00
|
|
|
/*
|
|
|
|
* first restore DSA, in case we were in a S/G
|
|
|
|
* operation.
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSA, siop_cmd->cmd_c.dsa);
|
|
|
|
scratcha0 = bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_SCRATCHA);
|
2000-04-21 21:56:58 +04:00
|
|
|
switch (sstat1 & SSTAT1_PHASE_MASK) {
|
|
|
|
case SSTAT1_PHASE_STATUS:
|
|
|
|
/*
|
|
|
|
* previous phase may be aborted for any reason
|
|
|
|
* ( for example, the target has less data to
|
|
|
|
* transfer than requested). Just go to status
|
|
|
|
* and the command should terminate.
|
|
|
|
*/
|
2000-04-25 20:27:05 +04:00
|
|
|
INCSTAT(siop_stat_intr_shortxfer);
|
2000-05-04 20:56:13 +04:00
|
|
|
if ((dstat & DSTAT_DFE) == 0)
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_clearfifo(&sc->sc_c);
|
2000-04-25 20:27:05 +04:00
|
|
|
/* no table to flush here */
|
2000-10-18 21:06:52 +04:00
|
|
|
CALL_SCRIPT(Ent_status);
|
2000-04-21 21:56:58 +04:00
|
|
|
return 1;
|
|
|
|
case SSTAT1_PHASE_MSGIN:
|
|
|
|
/*
|
|
|
|
* target may be ready to disconnect
|
|
|
|
* Save data pointers just in case.
|
|
|
|
*/
|
2000-04-25 20:27:05 +04:00
|
|
|
INCSTAT(siop_stat_intr_xferdisc);
|
2000-05-04 20:56:13 +04:00
|
|
|
if (scratcha0 & A_flag_data)
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_sdp(&siop_cmd->cmd_c);
|
2000-05-04 20:56:13 +04:00
|
|
|
else if ((dstat & DSTAT_DFE) == 0)
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_clearfifo(&sc->sc_c);
|
|
|
|
bus_space_write_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_SCRATCHA,
|
2000-05-04 20:56:13 +04:00
|
|
|
scratcha0 & ~A_flag_data);
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD |
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
2000-04-21 21:56:58 +04:00
|
|
|
CALL_SCRIPT(Ent_msgin);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("%s: unexpected phase mismatch %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
2000-04-21 21:56:58 +04:00
|
|
|
sstat1 & SSTAT1_PHASE_MASK);
|
|
|
|
} else {
|
|
|
|
printf("%s: phase mismatch without command\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
need_reset = 1;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sist & SIST0_PAR) {
|
2000-04-21 21:56:58 +04:00
|
|
|
/* parity error, reset */
|
|
|
|
if (siop_cmd)
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(xs->xs_periph);
|
2000-04-21 21:56:58 +04:00
|
|
|
else
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s:", sc->sc_c.sc_dev.dv_xname);
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("parity error\n");
|
2000-05-05 13:32:48 +04:00
|
|
|
goto reset;
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if ((sist & (SIST1_STO << 8)) && need_reset == 0) {
|
2000-04-21 21:56:58 +04:00
|
|
|
/* selection time out, assume there's no device here */
|
|
|
|
if (siop_cmd) {
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.status = CMDST_DONE;
|
2000-04-21 21:56:58 +04:00
|
|
|
xs->error = XS_SELTIMEOUT;
|
2000-10-18 21:06:52 +04:00
|
|
|
freetarget = 1;
|
2000-04-21 21:56:58 +04:00
|
|
|
goto end;
|
|
|
|
} else {
|
|
|
|
printf("%s: selection timeout without "
|
2002-04-20 04:15:54 +04:00
|
|
|
"command\n", sc->sc_c.sc_dev.dv_xname);
|
2000-04-21 21:56:58 +04:00
|
|
|
need_reset = 1;
|
|
|
|
}
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sist & SIST0_UDC) {
|
2000-04-21 21:56:58 +04:00
|
|
|
/*
|
|
|
|
* unexpected disconnect. Usually the target signals
|
|
|
|
* a fatal condition this way. Attempt to get sense.
|
|
|
|
*/
|
2000-10-24 03:18:10 +04:00
|
|
|
if (siop_cmd) {
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->status =
|
2000-10-24 03:18:10 +04:00
|
|
|
htole32(SCSI_CHECK);
|
|
|
|
goto end;
|
|
|
|
}
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("%s: unexpected disconnect without "
|
2002-04-20 04:15:54 +04:00
|
|
|
"command\n", sc->sc_c.sc_dev.dv_xname);
|
2000-04-25 20:27:05 +04:00
|
|
|
goto reset;
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sist & (SIST1_SBMC << 8)) {
|
2000-06-13 00:13:41 +04:00
|
|
|
/* SCSI bus mode change */
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_modechange(&sc->sc_c) == 0 || need_reset == 1)
|
2000-06-13 00:13:41 +04:00
|
|
|
goto reset;
|
|
|
|
if ((istat & ISTAT_DIP) && (dstat & DSTAT_SIR)) {
|
|
|
|
/*
|
|
|
|
* we have a script interrupt, it will
|
|
|
|
* restart the script.
|
|
|
|
*/
|
|
|
|
goto scintr;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* else we have to restart it ourselve, at the
|
|
|
|
* interrupted instruction.
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSP,
|
|
|
|
bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
2000-06-13 00:13:41 +04:00
|
|
|
SIOP_DSP) - 8);
|
|
|
|
return 1;
|
|
|
|
}
|
2000-04-21 21:56:58 +04:00
|
|
|
/* Else it's an unhandled exeption (for now). */
|
2000-10-23 18:56:16 +04:00
|
|
|
printf("%s: unhandled scsi interrupt, sist=0x%x sstat1=0x%x "
|
2002-04-20 04:15:54 +04:00
|
|
|
"DSA=0x%x DSP=0x%x\n", sc->sc_c.sc_dev.dv_xname, sist,
|
|
|
|
bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_SSTAT1),
|
|
|
|
bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh, SIOP_DSA),
|
|
|
|
(int)(bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSP) - sc->sc_c.sc_scriptaddr));
|
2000-04-21 21:56:58 +04:00
|
|
|
if (siop_cmd) {
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.status = CMDST_DONE;
|
2000-04-21 21:56:58 +04:00
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
need_reset = 1;
|
|
|
|
}
|
|
|
|
if (need_reset) {
|
|
|
|
reset:
|
|
|
|
/* fatal error, reset the bus */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_resetbus(&sc->sc_c);
|
2000-04-25 20:27:05 +04:00
|
|
|
/* no table to flush here */
|
2000-04-21 21:56:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-06-13 00:13:41 +04:00
|
|
|
scintr:
|
2000-04-21 21:56:58 +04:00
|
|
|
if ((istat & ISTAT_DIP) && (dstat & DSTAT_SIR)) { /* script interrupt */
|
2002-04-20 04:15:54 +04:00
|
|
|
irqcode = bus_space_read_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
2000-04-21 21:56:58 +04:00
|
|
|
SIOP_DSPS);
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_INTR
|
2000-04-25 20:27:05 +04:00
|
|
|
printf("script interrupt 0x%x\n", irqcode);
|
|
|
|
#endif
|
|
|
|
/*
|
2000-10-18 21:06:52 +04:00
|
|
|
* no command, or an inactive command is only valid for a
|
|
|
|
* reselect interrupt
|
2000-04-25 20:27:05 +04:00
|
|
|
*/
|
2000-10-18 21:06:52 +04:00
|
|
|
if ((irqcode & 0x80) == 0) {
|
|
|
|
if (siop_cmd == NULL) {
|
2001-04-30 06:17:55 +04:00
|
|
|
printf(
|
|
|
|
"%s: script interrupt (0x%x) with invalid DSA !!!\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, irqcode);
|
2000-10-18 21:06:52 +04:00
|
|
|
goto reset;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.status != CMDST_ACTIVE) {
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("%s: command with invalid status "
|
|
|
|
"(IRQ code 0x%x current status %d) !\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
|
|
|
irqcode, siop_cmd->cmd_c.status);
|
2000-10-18 21:06:52 +04:00
|
|
|
xs = NULL;
|
|
|
|
}
|
2000-05-02 23:03:02 +04:00
|
|
|
}
|
2000-04-21 21:56:58 +04:00
|
|
|
switch(irqcode) {
|
|
|
|
case A_int_err:
|
2000-04-25 20:27:05 +04:00
|
|
|
printf("error, DSP=0x%x\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
(int)(bus_space_read_4(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_DSP) - sc->sc_c.sc_scriptaddr));
|
2000-04-25 20:27:05 +04:00
|
|
|
if (xs) {
|
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
goto end;
|
|
|
|
} else {
|
|
|
|
goto reset;
|
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
case A_int_reseltarg:
|
|
|
|
printf("%s: reselect with invalid target\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-10-18 21:06:52 +04:00
|
|
|
goto reset;
|
2000-10-23 18:56:16 +04:00
|
|
|
case A_int_resellun:
|
|
|
|
INCSTAT(siop_stat_intr_lunresel);
|
2002-04-20 04:15:54 +04:00
|
|
|
target = bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_SCRATCHA) & 0xf;
|
|
|
|
lun = bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
2000-10-23 18:56:16 +04:00
|
|
|
SIOP_SCRATCHA + 1);
|
2002-04-20 04:15:54 +04:00
|
|
|
tag = bus_space_read_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
2000-10-23 18:56:16 +04:00
|
|
|
SIOP_SCRATCHA + 2);
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target =
|
|
|
|
(struct siop_target *)sc->sc_c.targets[target];
|
2000-10-23 18:56:16 +04:00
|
|
|
if (siop_target == NULL) {
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s: reselect with invalid target %d\n",
|
|
|
|
sc->sc_c.sc_dev.dv_xname, target);
|
2000-10-23 18:56:16 +04:00
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
siop_lun = siop_target->siop_lun[lun];
|
|
|
|
if (siop_lun == NULL) {
|
|
|
|
printf("%s: target %d reselect with invalid "
|
2002-04-20 04:15:54 +04:00
|
|
|
"lun %d\n", sc->sc_c.sc_dev.dv_xname,
|
2000-10-23 18:56:16 +04:00
|
|
|
target, lun);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
if (siop_lun->siop_tag[tag].active == NULL) {
|
|
|
|
printf("%s: target %d lun %d tag %d reselect "
|
2002-04-20 04:15:54 +04:00
|
|
|
"without command\n",
|
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
2000-10-23 18:56:16 +04:00
|
|
|
target, lun, tag);
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
siop_cmd = siop_lun->siop_tag[tag].active;
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_DSP, siop_cmd->cmd_c.dsa +
|
|
|
|
sizeof(struct siop_common_xfer) +
|
2000-10-23 18:56:16 +04:00
|
|
|
Ent_ldsa_reload_dsa);
|
2001-01-27 01:00:01 +03:00
|
|
|
siop_table_sync(siop_cmd, BUS_DMASYNC_PREWRITE);
|
2000-10-23 18:56:16 +04:00
|
|
|
return 1;
|
2000-10-18 21:06:52 +04:00
|
|
|
case A_int_reseltag:
|
|
|
|
printf("%s: reselect with invalid tag\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-10-18 21:06:52 +04:00
|
|
|
goto reset;
|
2000-04-21 21:56:58 +04:00
|
|
|
case A_int_msgin:
|
2000-10-18 21:06:52 +04:00
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
int msgin = bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_SFBR);
|
2000-10-18 21:06:52 +04:00
|
|
|
if (msgin == MSG_MESSAGE_REJECT) {
|
2000-05-04 20:56:13 +04:00
|
|
|
int msg, extmsg;
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_tables->msg_out[0] & 0x80) {
|
2000-05-04 20:56:13 +04:00
|
|
|
/*
|
|
|
|
* message was part of a identify +
|
|
|
|
* something else. Identify shoudl't
|
|
|
|
* have been rejected.
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
msg =
|
|
|
|
siop_cmd->cmd_tables->msg_out[1];
|
2000-05-04 20:56:13 +04:00
|
|
|
extmsg =
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_out[3];
|
2000-05-04 20:56:13 +04:00
|
|
|
} else {
|
2002-04-20 04:15:54 +04:00
|
|
|
msg = siop_cmd->cmd_tables->msg_out[0];
|
2000-05-04 20:56:13 +04:00
|
|
|
extmsg =
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_out[2];
|
2000-05-04 20:56:13 +04:00
|
|
|
}
|
|
|
|
if (msg == MSG_MESSAGE_REJECT) {
|
2000-04-25 20:27:05 +04:00
|
|
|
/* MSG_REJECT for a MSG_REJECT !*/
|
2000-05-04 21:18:27 +04:00
|
|
|
if (xs)
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(xs->xs_periph);
|
2000-05-04 21:18:27 +04:00
|
|
|
else
|
|
|
|
printf("%s: ",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-05-04 21:18:27 +04:00
|
|
|
printf("our reject message was "
|
|
|
|
"rejected\n");
|
2000-04-25 20:27:05 +04:00
|
|
|
goto reset;
|
|
|
|
}
|
2000-05-04 20:56:13 +04:00
|
|
|
if (msg == MSG_EXTENDED &&
|
|
|
|
extmsg == MSG_EXT_WDTR) {
|
2000-05-04 21:18:27 +04:00
|
|
|
/* WDTR rejected, initiate sync */
|
2002-04-20 04:15:54 +04:00
|
|
|
if ((siop_target->target_c.flags &
|
|
|
|
TARF_SYNC) == 0) {
|
|
|
|
siop_target->target_c.status =
|
|
|
|
TARST_OK;
|
|
|
|
siop_update_xfer_mode(&sc->sc_c,
|
2001-04-25 21:53:04 +04:00
|
|
|
target);
|
2000-07-24 19:15:00 +04:00
|
|
|
/* no table to flush here */
|
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->target_c.status =
|
|
|
|
TARST_SYNC_NEG;
|
|
|
|
siop_sdtr_msg(&siop_cmd->cmd_c, 0,
|
2002-04-23 21:33:27 +04:00
|
|
|
sc->sc_c.st_minsync,
|
|
|
|
sc->sc_c.maxoff);
|
2000-05-04 21:18:27 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD |
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_send_msgout);
|
|
|
|
return 1;
|
2000-05-04 20:56:13 +04:00
|
|
|
} else if (msg == MSG_EXTENDED &&
|
|
|
|
extmsg == MSG_EXT_SDTR) {
|
2000-05-02 23:03:02 +04:00
|
|
|
/* sync rejected */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->target_c.offset = 0;
|
|
|
|
siop_target->target_c.period = 0;
|
|
|
|
siop_target->target_c.status = TARST_OK;
|
|
|
|
siop_update_xfer_mode(&sc->sc_c,
|
|
|
|
target);
|
2000-05-04 21:18:27 +04:00
|
|
|
/* no table to flush here */
|
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
|
|
|
return 1;
|
2000-10-23 18:56:16 +04:00
|
|
|
} else if (msg == MSG_SIMPLE_Q_TAG ||
|
|
|
|
msg == MSG_HEAD_OF_Q_TAG ||
|
|
|
|
msg == MSG_ORDERED_Q_TAG) {
|
|
|
|
if (siop_handle_qtag_reject(
|
|
|
|
siop_cmd) == -1)
|
|
|
|
goto reset;
|
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
|
|
|
return 1;
|
2000-05-04 21:18:27 +04:00
|
|
|
}
|
|
|
|
if (xs)
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(xs->xs_periph);
|
2000-05-04 21:18:27 +04:00
|
|
|
else
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s: ",
|
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-05-04 21:18:27 +04:00
|
|
|
if (msg == MSG_EXTENDED) {
|
|
|
|
printf("scsi message reject, extended "
|
|
|
|
"message sent was 0x%x\n", extmsg);
|
|
|
|
} else {
|
|
|
|
printf("scsi message reject, message "
|
|
|
|
"sent was 0x%x\n", msg);
|
2000-05-02 23:03:02 +04:00
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
/* no table to flush here */
|
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
|
|
|
return 1;
|
|
|
|
}
|
2000-05-04 21:18:27 +04:00
|
|
|
if (xs)
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(xs->xs_periph);
|
2000-05-04 21:18:27 +04:00
|
|
|
else
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s: ", sc->sc_c.sc_dev.dv_xname);
|
2000-05-04 20:56:13 +04:00
|
|
|
printf("unhandled message 0x%x\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_in[0]);
|
|
|
|
siop_cmd->cmd_tables->msg_out[0] = MSG_MESSAGE_REJECT;
|
|
|
|
siop_cmd->cmd_tables->t_msgout.count= htole32(1);
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_send_msgout);
|
|
|
|
return 1;
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
case A_int_extmsgin:
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_INTR
|
2000-04-25 20:27:05 +04:00
|
|
|
printf("extended message: msg 0x%x len %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_in[2],
|
|
|
|
siop_cmd->cmd_tables->msg_in[1]);
|
2000-04-25 20:27:05 +04:00
|
|
|
#endif
|
2002-04-23 16:55:26 +04:00
|
|
|
if (siop_cmd->cmd_tables->msg_in[1] >
|
|
|
|
sizeof(siop_cmd->cmd_tables->msg_in) - 2)
|
2000-05-04 20:56:13 +04:00
|
|
|
printf("%s: extended message too big (%d)\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
|
|
|
siop_cmd->cmd_tables->msg_in[1]);
|
|
|
|
siop_cmd->cmd_tables->t_extmsgdata.count =
|
|
|
|
htole32(siop_cmd->cmd_tables->msg_in[1] - 1);
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_get_extmsgdata);
|
|
|
|
return 1;
|
|
|
|
case A_int_extmsgdata:
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_INTR
|
2000-04-25 20:27:05 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("extended message: 0x%x, data:",
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_in[2]);
|
|
|
|
for (i = 3; i < 2 + siop_cmd->cmd_tables->msg_in[1];
|
2000-04-25 20:27:05 +04:00
|
|
|
i++)
|
|
|
|
printf(" 0x%x",
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_in[i]);
|
2000-04-25 20:27:05 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_tables->msg_in[2] == MSG_EXT_WDTR) {
|
|
|
|
switch (siop_wdtr_neg(&siop_cmd->cmd_c)) {
|
2000-05-15 11:48:24 +04:00
|
|
|
case SIOP_NEG_MSGOUT:
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_update_scntl3(sc,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.siop_target);
|
2000-05-15 11:48:24 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD |
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_send_msgout);
|
2000-10-18 21:06:52 +04:00
|
|
|
return(1);
|
2000-07-24 19:15:00 +04:00
|
|
|
case SIOP_NEG_ACK:
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_update_scntl3(sc,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.siop_target);
|
2000-07-24 19:15:00 +04:00
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
2000-10-18 21:06:52 +04:00
|
|
|
return(1);
|
2000-05-15 11:48:24 +04:00
|
|
|
default:
|
|
|
|
panic("invalid retval from "
|
|
|
|
"siop_wdtr_neg()");
|
|
|
|
}
|
2000-05-02 23:03:02 +04:00
|
|
|
return(1);
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_tables->msg_in[2] == MSG_EXT_SDTR) {
|
|
|
|
switch (siop_sdtr_neg(&siop_cmd->cmd_c)) {
|
2000-05-15 11:48:24 +04:00
|
|
|
case SIOP_NEG_MSGOUT:
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_update_scntl3(sc,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.siop_target);
|
2000-05-15 11:48:24 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD |
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_send_msgout);
|
2000-10-18 21:06:52 +04:00
|
|
|
return(1);
|
2000-05-15 11:48:24 +04:00
|
|
|
case SIOP_NEG_ACK:
|
2000-10-18 21:06:52 +04:00
|
|
|
siop_update_scntl3(sc,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.siop_target);
|
2000-05-15 11:48:24 +04:00
|
|
|
CALL_SCRIPT(Ent_msgin_ack);
|
2000-10-18 21:06:52 +04:00
|
|
|
return(1);
|
2000-05-15 11:48:24 +04:00
|
|
|
default:
|
|
|
|
panic("invalid retval from "
|
|
|
|
"siop_wdtr_neg()");
|
|
|
|
}
|
2000-05-02 23:03:02 +04:00
|
|
|
return(1);
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
2000-05-02 23:03:02 +04:00
|
|
|
/* send a message reject */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_tables->msg_out[0] = MSG_MESSAGE_REJECT;
|
|
|
|
siop_cmd->cmd_tables->t_msgout.count = htole32(1);
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
CALL_SCRIPT(Ent_send_msgout);
|
|
|
|
return 1;
|
2000-04-21 21:56:58 +04:00
|
|
|
case A_int_disc:
|
2000-04-25 20:27:05 +04:00
|
|
|
INCSTAT(siop_stat_intr_sdp);
|
2002-04-20 04:15:54 +04:00
|
|
|
offset = bus_space_read_1(sc->sc_c.sc_rt,
|
|
|
|
sc->sc_c.sc_rh, SIOP_SCRATCHA + 1);
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_DR
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("disconnect offset %d\n", offset);
|
|
|
|
#endif
|
|
|
|
if (offset > SIOP_NSG) {
|
|
|
|
printf("%s: bad offset for disconnect (%d)\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, offset);
|
2000-04-21 21:56:58 +04:00
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* offset == SIOP_NSG may be a valid condition if
|
|
|
|
* we get a sdp when the xfer is done.
|
|
|
|
* Don't call memmove in this case.
|
|
|
|
*/
|
|
|
|
if (offset < SIOP_NSG) {
|
2002-04-20 04:15:54 +04:00
|
|
|
memmove(&siop_cmd->cmd_tables->data[0],
|
|
|
|
&siop_cmd->cmd_tables->data[offset],
|
2000-04-21 21:56:58 +04:00
|
|
|
(SIOP_NSG - offset) * sizeof(scr_table_t));
|
2000-04-25 20:27:05 +04:00
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
CALL_SCRIPT(Ent_script_sched);
|
2000-04-21 21:56:58 +04:00
|
|
|
return 1;
|
|
|
|
case A_int_resfail:
|
|
|
|
printf("reselect failed\n");
|
2000-10-18 21:06:52 +04:00
|
|
|
CALL_SCRIPT(Ent_script_sched);
|
2000-04-21 21:56:58 +04:00
|
|
|
return 1;
|
|
|
|
case A_int_done:
|
2000-04-25 20:27:05 +04:00
|
|
|
if (xs == NULL) {
|
2000-05-04 20:56:13 +04:00
|
|
|
printf("%s: done without command, DSA=0x%lx\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
|
|
|
(u_long)siop_cmd->cmd_c.dsa);
|
|
|
|
siop_cmd->cmd_c.status = CMDST_FREE;
|
2000-10-18 21:06:52 +04:00
|
|
|
CALL_SCRIPT(Ent_script_sched);
|
2000-04-25 20:27:05 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_INTR
|
2000-05-04 20:56:13 +04:00
|
|
|
printf("done, DSA=0x%lx target id 0x%x last msg "
|
2002-04-20 04:15:54 +04:00
|
|
|
"in=0x%x status=0x%x\n", (u_long)siop_cmd->cmd_c.dsa,
|
|
|
|
le32toh(siop_cmd->cmd_tables->id),
|
|
|
|
siop_cmd->cmd_tables->msg_in[0],
|
|
|
|
le32toh(siop_cmd->cmd_tables->status));
|
2000-04-21 21:56:58 +04:00
|
|
|
#endif
|
2000-04-25 20:27:05 +04:00
|
|
|
INCSTAT(siop_stat_intr_done);
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.status = CMDST_DONE;
|
2000-04-21 21:56:58 +04:00
|
|
|
goto end;
|
|
|
|
default:
|
|
|
|
printf("unknown irqcode %x\n", irqcode);
|
2000-10-23 18:56:16 +04:00
|
|
|
if (xs) {
|
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
goto reset;
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
/* We just should't get there */
|
|
|
|
panic("siop_intr: I shouldn't be there !");
|
|
|
|
return 1;
|
2000-04-21 21:56:58 +04:00
|
|
|
end:
|
2001-02-11 21:04:49 +03:00
|
|
|
/*
|
|
|
|
* restart the script now if command completed properly
|
2001-04-25 21:53:04 +04:00
|
|
|
* Otherwise wait for siop_scsicmd_end(), we may need to cleanup the
|
|
|
|
* queue
|
2001-02-11 21:04:49 +03:00
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
xs->status = le32toh(siop_cmd->cmd_tables->status);
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->status == SCSI_OK)
|
2001-02-11 21:04:49 +03:00
|
|
|
CALL_SCRIPT(Ent_script_sched);
|
|
|
|
else
|
|
|
|
restart = 1;
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_lun->siop_tag[tag].active = NULL;
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_scsicmd_end(siop_cmd);
|
2002-04-20 04:15:54 +04:00
|
|
|
if (freetarget && siop_target->target_c.status == TARST_PROBING)
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_del_dev(sc, target, lun);
|
2001-02-11 21:04:49 +03:00
|
|
|
if (restart)
|
|
|
|
CALL_SCRIPT(Ent_script_sched);
|
2001-05-23 19:51:32 +04:00
|
|
|
if (sc->sc_flags & SCF_CHAN_NOSLOT) {
|
|
|
|
/* a command terminated, so we have free slots now */
|
|
|
|
sc->sc_flags &= ~SCF_CHAN_NOSLOT;
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_channel_thaw(&sc->sc_c.sc_chan, 1);
|
2001-05-23 19:51:32 +04:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_scsicmd_end(siop_cmd)
|
|
|
|
struct siop_cmd *siop_cmd;
|
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
struct scsipi_xfer *xs = siop_cmd->cmd_c.xs;
|
|
|
|
struct siop_softc *sc = (struct siop_softc *)siop_cmd->cmd_c.siop_sc;
|
2000-04-25 20:27:05 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch(xs->status) {
|
2000-10-24 03:18:10 +04:00
|
|
|
case SCSI_OK:
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_NOERROR;
|
2000-10-24 03:18:10 +04:00
|
|
|
break;
|
|
|
|
case SCSI_BUSY:
|
|
|
|
xs->error = XS_BUSY;
|
|
|
|
break;
|
|
|
|
case SCSI_CHECK:
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_BUSY;
|
|
|
|
/* remove commands in the queue and scheduler */
|
|
|
|
siop_unqueue(sc, xs->xs_periph->periph_target,
|
|
|
|
xs->xs_periph->periph_lun);
|
2000-10-24 03:18:10 +04:00
|
|
|
break;
|
|
|
|
case SCSI_QUEUE_FULL:
|
|
|
|
INCSTAT(siop_stat_intr_qfull);
|
|
|
|
#ifdef SIOP_DEBUG
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s:%d:%d: queue full (tag %d)\n",
|
|
|
|
sc->sc_c.sc_dev.dv_xname,
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
2002-04-20 04:15:54 +04:00
|
|
|
xs->xs_periph->periph_lun, siop_cmd->cmd_c.tag);
|
2000-10-24 03:18:10 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_BUSY;
|
|
|
|
break;
|
2000-10-24 03:18:10 +04:00
|
|
|
case SCSI_SIOP_NOCHECK:
|
|
|
|
/*
|
|
|
|
* don't check status, xs->error is already valid
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case SCSI_SIOP_NOSTATUS:
|
|
|
|
/*
|
|
|
|
* the status byte was not updated, cmd was
|
|
|
|
* aborted
|
|
|
|
*/
|
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) {
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_sync(sc->sc_c.sc_dmat, siop_cmd->cmd_c.dmamap_data, 0,
|
|
|
|
siop_cmd->cmd_c.dmamap_data->dm_mapsize,
|
2000-04-21 21:56:58 +04:00
|
|
|
(xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_unload(sc->sc_c.sc_dmat, siop_cmd->cmd_c.dmamap_data);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_unload(sc->sc_c.sc_dmat, siop_cmd->cmd_c.dmamap_cmd);
|
|
|
|
callout_stop(&siop_cmd->cmd_c.xs->xs_callout);
|
|
|
|
siop_cmd->cmd_c.status = CMDST_FREE;
|
2001-04-25 21:53:04 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->free_list, siop_cmd, next);
|
2000-04-21 21:56:58 +04:00
|
|
|
xs->resid = 0;
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_done (xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_unqueue(sc, target, lun)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
int target;
|
|
|
|
int lun;
|
|
|
|
{
|
|
|
|
int slot, tag;
|
|
|
|
struct siop_cmd *siop_cmd;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_lun *siop_lun =
|
|
|
|
((struct siop_target *)sc->sc_c.targets[target])->siop_lun[lun];
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
/* first make sure to read valid data */
|
|
|
|
siop_script_sync(sc, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
|
|
|
for (tag = 1; tag < SIOP_NTAG; tag++) {
|
|
|
|
/* look for commands in the scheduler, not yet started */
|
|
|
|
if (siop_lun->siop_tag[tag].active == NULL)
|
|
|
|
continue;
|
|
|
|
siop_cmd = siop_lun->siop_tag[tag].active;
|
|
|
|
for (slot = 0; slot <= sc->sc_currschedslot; slot++) {
|
|
|
|
if (siop_script_read(sc,
|
|
|
|
(Ent_script_sched_slot0 / 4) + slot * 2 + 1) ==
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.dsa +
|
|
|
|
sizeof(struct siop_common_xfer) +
|
2001-04-25 21:53:04 +04:00
|
|
|
Ent_ldsa_select)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (slot > sc->sc_currschedslot)
|
|
|
|
continue; /* didn't find it */
|
|
|
|
if (siop_script_read(sc,
|
|
|
|
(Ent_script_sched_slot0 / 4) + slot * 2) == 0x80000000)
|
|
|
|
continue; /* already started */
|
|
|
|
/* clear the slot */
|
|
|
|
siop_script_write(sc, (Ent_script_sched_slot0 / 4) + slot * 2,
|
|
|
|
0x80000000);
|
|
|
|
/* ask to requeue */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.xs->error = XS_REQUEUE;
|
|
|
|
siop_cmd->cmd_c.xs->status = SCSI_SIOP_NOCHECK;
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_lun->siop_tag[tag].active = NULL;
|
|
|
|
siop_scsicmd_end(siop_cmd);
|
|
|
|
}
|
|
|
|
/* update sc_currschedslot */
|
|
|
|
sc->sc_currschedslot = 0;
|
|
|
|
for (slot = SIOP_NSLOTS - 1; slot >= 0; slot--) {
|
|
|
|
if (siop_script_read(sc,
|
|
|
|
(Ent_script_sched_slot0 / 4) + slot * 2) != 0x80000000)
|
|
|
|
sc->sc_currschedslot = slot;
|
|
|
|
}
|
2000-05-02 23:03:02 +04:00
|
|
|
}
|
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
/*
|
2000-10-18 21:06:52 +04:00
|
|
|
* handle a rejected queue tag message: the command will run untagged,
|
|
|
|
* has to adjust the reselect script.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
siop_handle_qtag_reject(siop_cmd)
|
|
|
|
struct siop_cmd *siop_cmd;
|
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_softc *sc = (struct siop_softc *)siop_cmd->cmd_c.siop_sc;
|
|
|
|
int target = siop_cmd->cmd_c.xs->xs_periph->periph_target;
|
|
|
|
int lun = siop_cmd->cmd_c.xs->xs_periph->periph_lun;
|
|
|
|
int tag = siop_cmd->cmd_tables->msg_out[2];
|
|
|
|
struct siop_lun *siop_lun =
|
|
|
|
((struct siop_target*)sc->sc_c.targets[target])->siop_lun[lun];
|
2000-10-23 18:56:16 +04:00
|
|
|
|
2000-10-24 03:18:10 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("%s:%d:%d: tag message %d (%d) rejected (status %d)\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun, tag, siop_cmd->cmd_c.tag,
|
|
|
|
siop_cmd->cmd_c.status);
|
2000-10-24 03:18:10 +04:00
|
|
|
#endif
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
if (siop_lun->siop_tag[0].active != NULL) {
|
2000-10-24 03:18:10 +04:00
|
|
|
printf("%s: untagged command already running for target %d "
|
2002-04-20 04:15:54 +04:00
|
|
|
"lun %d (status %d)\n", sc->sc_c.sc_dev.dv_xname,
|
|
|
|
target, lun, siop_lun->siop_tag[0].active->cmd_c.status);
|
2000-10-23 18:56:16 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* clear tag slot */
|
|
|
|
siop_lun->siop_tag[tag].active = NULL;
|
|
|
|
/* add command to non-tagged slot */
|
|
|
|
siop_lun->siop_tag[0].active = siop_cmd;
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.tag = 0;
|
2000-10-23 18:56:16 +04:00
|
|
|
/* adjust reselect script if there is one */
|
|
|
|
if (siop_lun->siop_tag[0].reseloff > 0) {
|
|
|
|
siop_script_write(sc,
|
|
|
|
siop_lun->siop_tag[0].reseloff + 1,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.dsa + sizeof(struct siop_common_xfer) +
|
2000-10-23 18:56:16 +04:00
|
|
|
Ent_ldsa_reload_dsa);
|
2001-01-27 01:00:01 +03:00
|
|
|
siop_table_sync(siop_cmd, BUS_DMASYNC_PREWRITE);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle a bus reset: reset chip, unqueue all active commands, free all
|
|
|
|
* target struct and report loosage to upper layer.
|
2000-04-25 20:27:05 +04:00
|
|
|
* As the upper layer may requeue immediatly we have to first store
|
|
|
|
* all active commands in a temporary queue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
siop_handle_reset(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct siop_cmd *siop_cmd;
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lun *siop_lun;
|
2000-10-23 18:56:16 +04:00
|
|
|
int target, lun, tag;
|
2000-04-25 20:27:05 +04:00
|
|
|
/*
|
|
|
|
* scsi bus reset. reset the chip and restart
|
|
|
|
* the queue. Need to clean up all active commands
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s: scsi bus reset\n", sc->sc_c.sc_dev.dv_xname);
|
2000-04-25 20:27:05 +04:00
|
|
|
/* stop, reset and restart the chip */
|
|
|
|
siop_reset(sc);
|
2001-04-25 21:53:04 +04:00
|
|
|
if (sc->sc_flags & SCF_CHAN_NOSLOT) {
|
|
|
|
/* chip has been reset, all slots are free now */
|
|
|
|
sc->sc_flags &= ~SCF_CHAN_NOSLOT;
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_channel_thaw(&sc->sc_c.sc_chan, 1);
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
2000-10-24 03:18:10 +04:00
|
|
|
/*
|
|
|
|
* Process all commands: first commmands being executed
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
for (target = 0; target < sc->sc_c.sc_chan.chan_ntargets;
|
2000-05-02 23:03:02 +04:00
|
|
|
target++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.targets[target] == NULL)
|
2000-05-02 23:03:02 +04:00
|
|
|
continue;
|
|
|
|
for (lun = 0; lun < 8; lun++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target =
|
|
|
|
(struct siop_target *)sc->sc_c.targets[target];
|
|
|
|
siop_lun = siop_target->siop_lun[lun];
|
2000-10-18 21:06:52 +04:00
|
|
|
if (siop_lun == NULL)
|
|
|
|
continue;
|
2000-10-23 18:56:16 +04:00
|
|
|
for (tag = 0; tag <
|
2002-04-20 04:15:54 +04:00
|
|
|
((sc->sc_c.targets[target]->flags & TARF_TAG) ?
|
2000-10-24 03:18:10 +04:00
|
|
|
SIOP_NTAG : 1);
|
2000-10-23 18:56:16 +04:00
|
|
|
tag++) {
|
|
|
|
siop_cmd = siop_lun->siop_tag[tag].active;
|
|
|
|
if (siop_cmd == NULL)
|
|
|
|
continue;
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_printaddr(siop_cmd->cmd_c.xs->xs_periph);
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("command with tag id %d reset\n", tag);
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.xs->error =
|
|
|
|
(siop_cmd->cmd_c.flags & CMDFL_TIMEOUT) ?
|
2001-04-25 21:53:04 +04:00
|
|
|
XS_TIMEOUT : XS_RESET;
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.xs->status = SCSI_SIOP_NOCHECK;
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_lun->siop_tag[tag].active = NULL;
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.status = CMDST_DONE;
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_scsicmd_end(siop_cmd);
|
2000-10-23 18:56:16 +04:00
|
|
|
}
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.targets[target]->status = TARST_ASYNC;
|
|
|
|
sc->sc_c.targets[target]->flags &= ~TARF_ISWIDE;
|
|
|
|
sc->sc_c.targets[target]->period =
|
|
|
|
sc->sc_c.targets[target]->offset = 0;
|
|
|
|
siop_update_xfer_mode(&sc->sc_c, target);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_async_event(&sc->sc_c.sc_chan, ASYNC_EVENT_RESET, NULL);
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
void
|
|
|
|
siop_scsipi_request(chan, req, arg)
|
|
|
|
struct scsipi_channel *chan;
|
|
|
|
scsipi_adapter_req_t req;
|
|
|
|
void *arg;
|
2000-04-21 21:56:58 +04:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_xfer *xs;
|
|
|
|
struct scsipi_periph *periph;
|
|
|
|
struct siop_softc *sc = (void *)chan->chan_adapter->adapt_dev;
|
2000-04-21 21:56:58 +04:00
|
|
|
struct siop_cmd *siop_cmd;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target;
|
2000-04-21 21:56:58 +04:00
|
|
|
int s, error, i;
|
2001-04-25 21:53:04 +04:00
|
|
|
int target;
|
|
|
|
int lun;
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch (req) {
|
|
|
|
case ADAPTER_REQ_RUN_XFER:
|
|
|
|
xs = arg;
|
|
|
|
periph = xs->xs_periph;
|
|
|
|
target = periph->periph_target;
|
|
|
|
lun = periph->periph_lun;
|
|
|
|
|
|
|
|
s = splbio();
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_SCHED
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("starting cmd for %d:%d\n", target, lun);
|
2000-04-21 21:56:58 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_cmd = TAILQ_FIRST(&sc->free_list);
|
|
|
|
if (siop_cmd == NULL) {
|
|
|
|
xs->error = XS_RESOURCE_SHORTAGE;
|
|
|
|
scsipi_done(xs);
|
|
|
|
splx(s);
|
|
|
|
return;
|
2000-05-23 21:08:07 +04:00
|
|
|
}
|
2001-10-15 00:37:28 +04:00
|
|
|
TAILQ_REMOVE(&sc->free_list, siop_cmd, next);
|
2000-04-21 21:56:58 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.status != CMDST_FREE)
|
2001-04-25 21:53:04 +04:00
|
|
|
panic("siop_scsicmd: new cmd not free");
|
2000-04-21 21:56:58 +04:00
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target = (struct siop_target*)sc->sc_c.targets[target];
|
|
|
|
if (siop_target == NULL) {
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: alloc siop_target for target %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target);
|
2000-10-18 21:06:52 +04:00
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.targets[target] =
|
2001-04-25 21:53:04 +04:00
|
|
|
malloc(sizeof(struct siop_target),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.targets[target] == NULL) {
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: can't malloc memory for "
|
2002-04-20 04:15:54 +04:00
|
|
|
"target %d\n", sc->sc_c.sc_dev.dv_xname,
|
|
|
|
target);
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_RESOURCE_SHORTAGE;
|
|
|
|
scsipi_done(xs);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target =
|
|
|
|
(struct siop_target*)sc->sc_c.targets[target];
|
|
|
|
siop_target->target_c.status = TARST_PROBING;
|
|
|
|
siop_target->target_c.flags = 0;
|
|
|
|
siop_target->target_c.id =
|
|
|
|
sc->sc_c.clock_div << 24; /* scntl3 */
|
|
|
|
siop_target->target_c.id |= target << 16; /* id */
|
|
|
|
/* siop_target->target_c.id |= 0x0 << 8; scxfer is 0 */
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
/* get a lun switch script */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->lunsw = siop_get_lunsw(sc);
|
|
|
|
if (siop_target->lunsw == NULL) {
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: can't alloc lunsw for target %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target);
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_RESOURCE_SHORTAGE;
|
|
|
|
scsipi_done(xs);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i=0; i < 8; i++)
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->siop_lun[i] = NULL;
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_add_reselsw(sc, target);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_target->siop_lun[lun] == NULL) {
|
|
|
|
siop_target->siop_lun[lun] =
|
2002-01-12 19:03:11 +03:00
|
|
|
malloc(sizeof(struct siop_lun), M_DEVBUF,
|
|
|
|
M_NOWAIT|M_ZERO);
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_target->siop_lun[lun] == NULL) {
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: can't alloc siop_lun for "
|
|
|
|
"target %d lun %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun);
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_RESOURCE_SHORTAGE;
|
|
|
|
scsipi_done(xs);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.siop_target = sc->sc_c.targets[target];
|
|
|
|
siop_cmd->cmd_c.xs = xs;
|
|
|
|
siop_cmd->cmd_c.flags = 0;
|
|
|
|
siop_cmd->cmd_c.status = CMDST_READY;
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
/* load the DMA maps */
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_load(sc->sc_c.sc_dmat,
|
|
|
|
siop_cmd->cmd_c.dmamap_cmd,
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->cmd, xs->cmdlen, NULL, BUS_DMA_NOWAIT);
|
2000-04-21 21:56:58 +04:00
|
|
|
if (error) {
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: unable to load cmd DMA map: %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-04-21 21:56:58 +04:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_done(xs);
|
2000-10-18 21:06:52 +04:00
|
|
|
splx(s);
|
2001-04-25 21:53:04 +04:00
|
|
|
return;
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) {
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_load(sc->sc_c.sc_dmat,
|
|
|
|
siop_cmd->cmd_c.dmamap_data, xs->data, xs->datalen,
|
2001-07-19 20:25:23 +04:00
|
|
|
NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
|
|
|
|
((xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMA_READ : BUS_DMA_WRITE));
|
2001-04-25 21:53:04 +04:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to load cmd DMA map: %d",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
scsipi_done(xs);
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_unload(sc->sc_c.sc_dmat,
|
|
|
|
siop_cmd->cmd_c.dmamap_cmd);
|
2001-04-25 21:53:04 +04:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_sync(sc->sc_c.sc_dmat,
|
|
|
|
siop_cmd->cmd_c.dmamap_data, 0,
|
|
|
|
siop_cmd->cmd_c.dmamap_data->dm_mapsize,
|
2001-04-25 21:53:04 +04:00
|
|
|
(xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_sync(sc->sc_c.sc_dmat, siop_cmd->cmd_c.dmamap_cmd, 0,
|
|
|
|
siop_cmd->cmd_c.dmamap_cmd->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
2001-04-25 21:53:04 +04:00
|
|
|
|
2002-04-22 19:48:55 +04:00
|
|
|
if (xs->xs_tag_type) {
|
|
|
|
/* use tag_id + 1, tag 0 is reserved for untagged cmds*/
|
|
|
|
siop_cmd->cmd_c.tag = xs->xs_tag_id + 1;
|
|
|
|
} else {
|
|
|
|
siop_cmd->cmd_c.tag = 0;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_setuptables(&siop_cmd->cmd_c);
|
|
|
|
siop_table_sync(siop_cmd,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_start(sc, siop_cmd);
|
|
|
|
if (xs->xs_control & XS_CTL_POLL) {
|
|
|
|
/* poll for command completion */
|
|
|
|
while ((xs->xs_status & XS_STS_DONE) == 0) {
|
|
|
|
delay(1000);
|
|
|
|
siop_intr(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_GROW_RESOURCES:
|
2001-10-15 00:37:28 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s grow resources (%d)\n", sc->sc_c.sc_dev.dv_xname,
|
|
|
|
sc->sc_c.sc_adapt.adapt_openings);
|
2001-10-15 00:37:28 +04:00
|
|
|
#endif
|
|
|
|
siop_morecbd(sc);
|
2001-04-25 21:53:04 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_SET_XFER_MODE:
|
|
|
|
{
|
|
|
|
struct scsipi_xfer_mode *xm = arg;
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.targets[xm->xm_target] == NULL)
|
2001-04-25 21:53:04 +04:00
|
|
|
return;
|
|
|
|
s = splbio();
|
|
|
|
if (xm->xm_mode & PERIPH_CAP_TQING)
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.targets[xm->xm_target]->flags |= TARF_TAG;
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((xm->xm_mode & PERIPH_CAP_WIDE16) &&
|
2002-04-20 04:15:54 +04:00
|
|
|
(sc->sc_c.features & SF_BUS_WIDE))
|
|
|
|
sc->sc_c.targets[xm->xm_target]->flags |= TARF_WIDE;
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xm->xm_mode & PERIPH_CAP_SYNC)
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.targets[xm->xm_target]->flags |= TARF_SYNC;
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((xm->xm_mode & (PERIPH_CAP_SYNC | PERIPH_CAP_WIDE16)) ||
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.targets[xm->xm_target]->status == TARST_PROBING)
|
|
|
|
sc->sc_c.targets[xm->xm_target]->status =
|
2001-04-25 21:53:04 +04:00
|
|
|
TARST_ASYNC;
|
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
for (lun = 0; lun < sc->sc_c.sc_chan.chan_nluns; lun++) {
|
2002-05-16 06:50:53 +04:00
|
|
|
if (scsipi_lookup_periph(chan,
|
|
|
|
xm->xm_target, lun) != NULL) {
|
2001-04-25 21:53:04 +04:00
|
|
|
/* allocate a lun sw entry for this device */
|
|
|
|
siop_add_dev(sc, xm->xm_target, lun);
|
2002-05-16 06:50:53 +04:00
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
|
2000-05-15 11:48:24 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
static void
|
|
|
|
siop_start(sc, siop_cmd)
|
2000-04-21 21:56:58 +04:00
|
|
|
struct siop_softc *sc;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct siop_cmd *siop_cmd;
|
2000-04-21 21:56:58 +04:00
|
|
|
{
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lun *siop_lun;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_xfer *siop_xfer;
|
2000-04-25 20:27:05 +04:00
|
|
|
u_int32_t dsa;
|
2000-04-21 21:56:58 +04:00
|
|
|
int timeout;
|
2001-04-25 21:53:04 +04:00
|
|
|
int target, lun, slot;
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
/*
|
|
|
|
* first make sure to read valid data
|
|
|
|
*/
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_script_sync(sc, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
|
2000-04-25 20:27:05 +04:00
|
|
|
|
|
|
|
/*
|
2000-05-05 13:05:44 +04:00
|
|
|
* The queue management here is a bit tricky: the script always looks
|
|
|
|
* at the slot from first to last, so if we always use the first
|
|
|
|
* free slot commands can stay at the tail of the queue ~forever.
|
|
|
|
* The algorithm used here is to restart from the head when we know
|
|
|
|
* that the queue is empty, and only add commands after the last one.
|
|
|
|
* When we're at the end of the queue wait for the script to clear it.
|
|
|
|
* The best thing to do here would be to implement a circular queue,
|
|
|
|
* but using only 53c720 features this can be "interesting".
|
|
|
|
* A mid-way solution could be to implement 2 queues and swap orders.
|
2000-04-25 20:27:05 +04:00
|
|
|
*/
|
2000-10-06 20:39:04 +04:00
|
|
|
slot = sc->sc_currschedslot;
|
2000-05-05 13:05:44 +04:00
|
|
|
/*
|
2000-10-23 18:56:16 +04:00
|
|
|
* If the instruction is 0x80000000 (JUMP foo, IF FALSE) the slot is
|
|
|
|
* free. As this is the last used slot, all previous slots are free,
|
2001-04-25 21:53:04 +04:00
|
|
|
* we can restart from 0.
|
2000-05-05 13:05:44 +04:00
|
|
|
*/
|
2000-10-23 18:56:16 +04:00
|
|
|
if (siop_script_read(sc, (Ent_script_sched_slot0 / 4) + slot * 2) ==
|
|
|
|
0x80000000) {
|
2001-04-25 21:53:04 +04:00
|
|
|
slot = sc->sc_currschedslot = 0;
|
2000-05-05 13:05:44 +04:00
|
|
|
} else {
|
|
|
|
slot++;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
target = siop_cmd->cmd_c.xs->xs_periph->periph_target;
|
|
|
|
lun = siop_cmd->cmd_c.xs->xs_periph->periph_lun;
|
|
|
|
siop_lun =
|
|
|
|
((struct siop_target*)sc->sc_c.targets[target])->siop_lun[lun];
|
2001-04-25 21:53:04 +04:00
|
|
|
/* if non-tagged command active, panic: this shouldn't happen */
|
|
|
|
if (siop_lun->siop_tag[0].active != NULL) {
|
|
|
|
panic("siop_start: tagged cmd while untagged running");
|
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2001-04-25 21:53:04 +04:00
|
|
|
/* sanity check the tag if needed */
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.flags & CMDFL_TAG) {
|
|
|
|
if (siop_lun->siop_tag[siop_cmd->cmd_c.tag].active != NULL)
|
2001-04-25 21:53:04 +04:00
|
|
|
panic("siop_start: tag not free");
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.tag >= SIOP_NTAG) {
|
|
|
|
scsipi_printaddr(siop_cmd->cmd_c.xs->xs_periph);
|
|
|
|
printf(": tag id %d\n", siop_cmd->cmd_c.tag);
|
2001-04-25 21:53:04 +04:00
|
|
|
panic("siop_start: invalid tag id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* find a free scheduler slot and load it.
|
|
|
|
*/
|
|
|
|
for (; slot < SIOP_NSLOTS; slot++) {
|
2000-10-23 18:56:16 +04:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* If cmd if 0x80000000 the slot is free
|
2000-10-23 18:56:16 +04:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
if (siop_script_read(sc,
|
|
|
|
(Ent_script_sched_slot0 / 4) + slot * 2) ==
|
|
|
|
0x80000000)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (slot == SIOP_NSLOTS) {
|
2001-02-11 21:04:49 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* no more free slot, no need to continue. freeze the queue
|
|
|
|
* and requeue this command.
|
2001-02-11 21:04:49 +03:00
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_channel_freeze(&sc->sc_c.sc_chan, 1);
|
2001-04-25 21:53:04 +04:00
|
|
|
sc->sc_flags |= SCF_CHAN_NOSLOT;
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.xs->error = XS_REQUEUE;
|
|
|
|
siop_cmd->cmd_c.xs->status = SCSI_SIOP_NOCHECK;
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_scsicmd_end(siop_cmd);
|
|
|
|
return;
|
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG_SCHED
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("using slot %d for DSA 0x%lx\n", slot,
|
2002-04-20 04:15:54 +04:00
|
|
|
(u_long)siop_cmd->cmd_c.dsa);
|
2000-10-24 03:18:10 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
/* mark command as active */
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_cmd->cmd_c.status == CMDST_READY)
|
|
|
|
siop_cmd->cmd_c.status = CMDST_ACTIVE;
|
2001-04-25 21:53:04 +04:00
|
|
|
else
|
|
|
|
panic("siop_start: bad status");
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_lun->siop_tag[siop_cmd->cmd_c.tag].active = siop_cmd;
|
2001-04-25 21:53:04 +04:00
|
|
|
/* patch scripts with DSA addr */
|
2002-04-20 04:15:54 +04:00
|
|
|
dsa = siop_cmd->cmd_c.dsa;
|
2001-04-25 21:53:04 +04:00
|
|
|
/* first reselect switch, if we have an entry */
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_lun->siop_tag[siop_cmd->cmd_c.tag].reseloff > 0)
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_script_write(sc,
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_lun->siop_tag[siop_cmd->cmd_c.tag].reseloff + 1,
|
|
|
|
dsa + sizeof(struct siop_common_xfer) +
|
2001-04-25 21:53:04 +04:00
|
|
|
Ent_ldsa_reload_dsa);
|
|
|
|
/* CMD script: MOVE MEMORY addr */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_xfer = (struct siop_xfer*)siop_cmd->cmd_tables;
|
|
|
|
siop_xfer->resel[E_ldsa_abs_slot_Used[0]] =
|
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_script_sched_slot0 + slot * 8);
|
2001-04-25 21:53:04 +04:00
|
|
|
siop_table_sync(siop_cmd, BUS_DMASYNC_PREWRITE);
|
|
|
|
/* scheduler slot: JUMP ldsa_select */
|
|
|
|
siop_script_write(sc,
|
|
|
|
(Ent_script_sched_slot0 / 4) + slot * 2 + 1,
|
2002-04-20 04:15:54 +04:00
|
|
|
dsa + sizeof(struct siop_common_xfer) + Ent_ldsa_select);
|
2001-04-25 21:53:04 +04:00
|
|
|
/* handle timeout */
|
2002-04-20 04:15:54 +04:00
|
|
|
if ((siop_cmd->cmd_c.xs->xs_control & XS_CTL_POLL) == 0) {
|
2001-04-25 21:53:04 +04:00
|
|
|
/* start exire timer */
|
2002-04-20 04:15:54 +04:00
|
|
|
timeout = mstohz(siop_cmd->cmd_c.xs->timeout);
|
2001-04-25 21:53:04 +04:00
|
|
|
if (timeout == 0)
|
|
|
|
timeout = 1;
|
2002-04-20 04:15:54 +04:00
|
|
|
callout_reset( &siop_cmd->cmd_c.xs->xs_callout,
|
2001-04-25 21:53:04 +04:00
|
|
|
timeout, siop_timeout, siop_cmd);
|
2000-10-24 03:18:10 +04:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
/*
|
|
|
|
* Change JUMP cmd so that this slot will be handled
|
|
|
|
*/
|
|
|
|
siop_script_write(sc, (Ent_script_sched_slot0 / 4) + slot * 2,
|
|
|
|
0x80080000);
|
|
|
|
sc->sc_currschedslot = slot;
|
2000-10-24 03:18:10 +04:00
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
/* make sure SCRIPT processor will read valid data */
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_script_sync(sc,BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2000-04-25 20:27:05 +04:00
|
|
|
/* Signal script it has some work to do */
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_1(sc->sc_c.sc_rt, sc->sc_c.sc_rh,
|
|
|
|
SIOP_ISTAT, ISTAT_SIGP);
|
2000-04-25 20:27:05 +04:00
|
|
|
/* and wait for IRQ */
|
|
|
|
return;
|
2000-04-21 21:56:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_timeout(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct siop_cmd *siop_cmd = v;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_softc *sc = (struct siop_softc *)siop_cmd->cmd_c.siop_sc;
|
2000-04-21 21:56:58 +04:00
|
|
|
int s;
|
|
|
|
|
2002-04-20 04:15:54 +04:00
|
|
|
scsipi_printaddr(siop_cmd->cmd_c.xs->xs_periph);
|
2000-04-21 21:56:58 +04:00
|
|
|
printf("command timeout\n");
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
/* reset the scsi bus */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_resetbus(&sc->sc_c);
|
2000-04-21 21:56:58 +04:00
|
|
|
|
2000-05-06 04:44:00 +04:00
|
|
|
/* deactivate callout */
|
2002-04-20 04:15:54 +04:00
|
|
|
callout_stop(&siop_cmd->cmd_c.xs->xs_callout);
|
2000-10-18 21:06:52 +04:00
|
|
|
/* mark command as being timed out; siop_intr will handle it */
|
2000-04-21 21:56:58 +04:00
|
|
|
/*
|
|
|
|
* mark command has being timed out and just return;
|
|
|
|
* the bus reset will generate an interrupt,
|
|
|
|
* it will be handled in siop_intr()
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_cmd->cmd_c.flags |= CMDFL_TIMEOUT;
|
2000-04-21 21:56:58 +04:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
void
|
|
|
|
siop_dump_script(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
|
|
|
int i;
|
2000-11-14 21:21:00 +03:00
|
|
|
for (i = 0; i < PAGE_SIZE / 4; i += 2) {
|
2000-04-27 00:00:31 +04:00
|
|
|
printf("0x%04x: 0x%08x 0x%08x", i * 4,
|
2002-04-20 04:15:54 +04:00
|
|
|
le32toh(sc->sc_c.sc_script[i]),
|
|
|
|
le32toh(sc->sc_c.sc_script[i+1]));
|
|
|
|
if ((le32toh(sc->sc_c.sc_script[i]) & 0xe0000000) ==
|
|
|
|
0xc0000000) {
|
2000-04-25 20:27:05 +04:00
|
|
|
i++;
|
2002-04-20 04:15:54 +04:00
|
|
|
printf(" 0x%08x", le32toh(sc->sc_c.sc_script[i+1]));
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-15 00:37:28 +04:00
|
|
|
void
|
2000-05-23 21:08:07 +04:00
|
|
|
siop_morecbd(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
2002-03-02 00:37:03 +03:00
|
|
|
int error, i, j, s;
|
2000-05-23 21:08:07 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
int rseg;
|
|
|
|
struct siop_cbd *newcbd;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_xfer *xfer;
|
2000-10-18 21:06:52 +04:00
|
|
|
bus_addr_t dsa;
|
|
|
|
u_int32_t *scr;
|
2000-05-23 21:08:07 +04:00
|
|
|
|
|
|
|
/* allocate a new list head */
|
2002-01-12 19:03:11 +03:00
|
|
|
newcbd = malloc(sizeof(struct siop_cbd), M_DEVBUF, M_NOWAIT|M_ZERO);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (newcbd == NULL) {
|
|
|
|
printf("%s: can't allocate memory for command descriptors "
|
2002-04-20 04:15:54 +04:00
|
|
|
"head\n", sc->sc_c.sc_dev.dv_xname);
|
2001-10-15 00:37:28 +04:00
|
|
|
return;
|
2000-05-23 21:08:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate cmd list */
|
2002-01-12 19:03:11 +03:00
|
|
|
newcbd->cmds = malloc(sizeof(struct siop_cmd) * SIOP_NCMDPB,
|
|
|
|
M_DEVBUF, M_NOWAIT|M_ZERO);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (newcbd->cmds == NULL) {
|
|
|
|
printf("%s: can't allocate memory for command descriptors\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad3;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamem_alloc(sc->sc_c.sc_dmat, PAGE_SIZE, PAGE_SIZE, 0, &seg,
|
2000-11-14 21:21:00 +03:00
|
|
|
1, &rseg, BUS_DMA_NOWAIT);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to allocate cbd DMA memory, error = %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad2;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamem_map(sc->sc_c.sc_dmat, &seg, rseg, PAGE_SIZE,
|
2000-05-23 21:08:07 +04:00
|
|
|
(caddr_t *)&newcbd->xfers, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to map cbd DMA memory, error = %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad2;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_create(sc->sc_c.sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, 0,
|
2000-05-23 21:08:07 +04:00
|
|
|
BUS_DMA_NOWAIT, &newcbd->xferdma);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to create cbd DMA map, error = %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad1;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_load(sc->sc_c.sc_dmat, newcbd->xferdma, newcbd->xfers,
|
2000-11-14 21:21:00 +03:00
|
|
|
PAGE_SIZE, NULL, BUS_DMA_NOWAIT);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (error) {
|
2000-05-25 14:10:54 +04:00
|
|
|
printf("%s: unable to load cbd DMA map, error = %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad0;
|
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
#ifdef DEBUG
|
2002-04-20 04:15:54 +04:00
|
|
|
printf("%s: alloc newcdb at PHY addr 0x%lx\n", sc->sc_c.sc_dev.dv_xname,
|
2000-10-18 21:06:52 +04:00
|
|
|
(unsigned long)newcbd->xferdma->dm_segs[0].ds_addr);
|
|
|
|
#endif
|
2000-05-23 21:08:07 +04:00
|
|
|
for (i = 0; i < SIOP_NCMDPB; i++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_create(sc->sc_c.sc_dmat, MAXPHYS, SIOP_NSG,
|
2000-05-23 21:08:07 +04:00
|
|
|
MAXPHYS, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
2002-04-20 04:15:54 +04:00
|
|
|
&newcbd->cmds[i].cmd_c.dmamap_data);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to create data DMA map for cbd: "
|
|
|
|
"error %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad0;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
error = bus_dmamap_create(sc->sc_c.sc_dmat,
|
2000-05-23 21:08:07 +04:00
|
|
|
sizeof(struct scsipi_generic), 1,
|
|
|
|
sizeof(struct scsipi_generic), 0,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
2002-04-20 04:15:54 +04:00
|
|
|
&newcbd->cmds[i].cmd_c.dmamap_cmd);
|
2000-05-23 21:08:07 +04:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to create cmd DMA map for cbd %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, error);
|
2000-05-23 21:08:07 +04:00
|
|
|
goto bad0;
|
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
newcbd->cmds[i].cmd_c.siop_sc = &sc->sc_c;
|
2000-05-23 21:08:07 +04:00
|
|
|
newcbd->cmds[i].siop_cbdp = newcbd;
|
2002-04-20 04:15:54 +04:00
|
|
|
xfer = &newcbd->xfers[i];
|
|
|
|
newcbd->cmds[i].cmd_tables = (struct siop_common_xfer *)xfer;
|
|
|
|
memset(newcbd->cmds[i].cmd_tables, 0, sizeof(struct siop_xfer));
|
|
|
|
dsa = newcbd->xferdma->dm_segs[0].ds_addr +
|
2000-05-23 21:08:07 +04:00
|
|
|
i * sizeof(struct siop_xfer);
|
2002-04-20 04:15:54 +04:00
|
|
|
newcbd->cmds[i].cmd_c.dsa = dsa;
|
|
|
|
newcbd->cmds[i].cmd_c.status = CMDST_FREE;
|
|
|
|
xfer->siop_tables.t_msgout.count= htole32(1);
|
|
|
|
xfer->siop_tables.t_msgout.addr = htole32(dsa);
|
|
|
|
xfer->siop_tables.t_msgin.count= htole32(1);
|
2002-04-23 16:55:26 +04:00
|
|
|
xfer->siop_tables.t_msgin.addr = htole32(dsa +
|
|
|
|
offsetof(struct siop_common_xfer, msg_in));
|
2002-04-20 04:15:54 +04:00
|
|
|
xfer->siop_tables.t_extmsgin.count= htole32(2);
|
2002-04-23 16:55:26 +04:00
|
|
|
xfer->siop_tables.t_extmsgin.addr = htole32(dsa +
|
|
|
|
offsetof(struct siop_common_xfer, msg_in) + 1);
|
|
|
|
xfer->siop_tables.t_extmsgdata.addr = htole32(dsa +
|
|
|
|
offsetof(struct siop_common_xfer, msg_in) + 3);
|
2002-04-20 04:15:54 +04:00
|
|
|
xfer->siop_tables.t_status.count= htole32(1);
|
2002-04-23 16:55:26 +04:00
|
|
|
xfer->siop_tables.t_status.addr = htole32(dsa +
|
|
|
|
offsetof(struct siop_common_xfer, status));
|
2000-10-23 18:56:16 +04:00
|
|
|
/* The select/reselect script */
|
2002-04-20 04:15:54 +04:00
|
|
|
scr = &xfer->resel[0];
|
2000-10-18 21:06:52 +04:00
|
|
|
for (j = 0; j < sizeof(load_dsa) / sizeof(load_dsa[0]); j++)
|
|
|
|
scr[j] = htole32(load_dsa[j]);
|
|
|
|
/*
|
|
|
|
* 0x78000000 is a 'move data8 to reg'. data8 is the second
|
|
|
|
* octet, reg offset is the third.
|
|
|
|
*/
|
|
|
|
scr[Ent_rdsa0 / 4] =
|
|
|
|
htole32(0x78100000 | ((dsa & 0x000000ff) << 8));
|
|
|
|
scr[Ent_rdsa1 / 4] =
|
|
|
|
htole32(0x78110000 | ( dsa & 0x0000ff00 ));
|
|
|
|
scr[Ent_rdsa2 / 4] =
|
|
|
|
htole32(0x78120000 | ((dsa & 0x00ff0000) >> 8));
|
|
|
|
scr[Ent_rdsa3 / 4] =
|
|
|
|
htole32(0x78130000 | ((dsa & 0xff000000) >> 16));
|
2000-10-23 18:56:16 +04:00
|
|
|
scr[E_ldsa_abs_reselected_Used[0]] =
|
2002-04-20 04:15:54 +04:00
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_reselected);
|
2000-10-23 18:56:16 +04:00
|
|
|
scr[E_ldsa_abs_reselect_Used[0]] =
|
2002-04-20 04:15:54 +04:00
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_reselect);
|
2000-10-23 18:56:16 +04:00
|
|
|
scr[E_ldsa_abs_selected_Used[0]] =
|
2002-04-20 04:15:54 +04:00
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_selected);
|
2000-10-23 18:56:16 +04:00
|
|
|
scr[E_ldsa_abs_data_Used[0]] =
|
2002-04-20 04:15:54 +04:00
|
|
|
htole32(dsa + sizeof(struct siop_common_xfer) +
|
2000-10-23 18:56:16 +04:00
|
|
|
Ent_ldsa_data);
|
|
|
|
/* JUMP foo, IF FALSE - used by MOVE MEMORY to clear the slot */
|
|
|
|
scr[Ent_ldsa_data / 4] = htole32(0x80000000);
|
2002-03-02 00:37:03 +03:00
|
|
|
s = splbio();
|
2000-05-23 21:08:07 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->free_list, &newcbd->cmds[i], next);
|
2002-03-02 00:37:03 +03:00
|
|
|
splx(s);
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("tables[%d]: in=0x%x out=0x%x status=0x%x\n", i,
|
2002-04-20 04:15:54 +04:00
|
|
|
le32toh(newcbd->cmds[i].cmd_tables->t_msgin.addr),
|
|
|
|
le32toh(newcbd->cmds[i].cmd_tables->t_msgout.addr),
|
|
|
|
le32toh(newcbd->cmds[i].cmd_tables->t_status.addr));
|
2000-05-23 21:08:07 +04:00
|
|
|
#endif
|
|
|
|
}
|
2002-03-02 00:37:03 +03:00
|
|
|
s = splbio();
|
2000-05-23 21:08:07 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->cmds, newcbd, next);
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_adapt.adapt_openings += SIOP_NCMDPB;
|
2002-03-02 00:37:03 +03:00
|
|
|
splx(s);
|
2001-10-15 00:37:28 +04:00
|
|
|
return;
|
2000-05-23 21:08:07 +04:00
|
|
|
bad0:
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamap_unload(sc->sc_c.sc_dmat, newcbd->xferdma);
|
|
|
|
bus_dmamap_destroy(sc->sc_c.sc_dmat, newcbd->xferdma);
|
2000-05-23 21:08:07 +04:00
|
|
|
bad1:
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_dmamem_free(sc->sc_c.sc_dmat, &seg, rseg);
|
2000-05-23 21:08:07 +04:00
|
|
|
bad2:
|
|
|
|
free(newcbd->cmds, M_DEVBUF);
|
|
|
|
bad3:
|
|
|
|
free(newcbd, M_DEVBUF);
|
2001-10-15 00:37:28 +04:00
|
|
|
return;
|
2000-05-23 21:08:07 +04:00
|
|
|
}
|
|
|
|
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lunsw *
|
|
|
|
siop_get_lunsw(sc)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
{
|
|
|
|
struct siop_lunsw *lunsw;
|
|
|
|
int i;
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
if (sc->script_free_lo + (sizeof(lun_switch) / sizeof(lun_switch[0])) >=
|
|
|
|
sc->script_free_hi)
|
|
|
|
return NULL;
|
2000-10-18 21:06:52 +04:00
|
|
|
lunsw = TAILQ_FIRST(&sc->lunsw_list);
|
|
|
|
if (lunsw != NULL) {
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("siop_get_lunsw got lunsw at offset %d\n",
|
|
|
|
lunsw->lunsw_off);
|
|
|
|
#endif
|
|
|
|
TAILQ_REMOVE(&sc->lunsw_list, lunsw, next);
|
|
|
|
return lunsw;
|
|
|
|
}
|
2002-01-12 19:03:11 +03:00
|
|
|
lunsw = malloc(sizeof(struct siop_lunsw), M_DEVBUF, M_NOWAIT|M_ZERO);
|
2000-10-18 21:06:52 +04:00
|
|
|
if (lunsw == NULL)
|
|
|
|
return NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("allocating lunsw at offset %d\n", sc->script_free_lo);
|
2000-10-18 21:06:52 +04:00
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_RAM) {
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh,
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->script_free_lo * 4, lun_switch,
|
2000-10-18 21:06:52 +04:00
|
|
|
sizeof(lun_switch) / sizeof(lun_switch[0]));
|
2002-04-20 04:15:54 +04:00
|
|
|
bus_space_write_4(sc->sc_c.sc_ramt, sc->sc_c.sc_ramh,
|
2000-10-23 18:56:16 +04:00
|
|
|
(sc->script_free_lo + E_abs_lunsw_return_Used[0]) * 4,
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_scriptaddr + Ent_lunsw_return);
|
2000-10-18 21:06:52 +04:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < sizeof(lun_switch) / sizeof(lun_switch[0]);
|
|
|
|
i++)
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[sc->script_free_lo + i] =
|
2000-10-18 21:06:52 +04:00
|
|
|
htole32(lun_switch[i]);
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[
|
|
|
|
sc->script_free_lo + E_abs_lunsw_return_Used[0]] =
|
|
|
|
htole32(sc->sc_c.sc_scriptaddr + Ent_lunsw_return);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2000-10-23 18:56:16 +04:00
|
|
|
lunsw->lunsw_off = sc->script_free_lo;
|
|
|
|
lunsw->lunsw_size = sizeof(lun_switch) / sizeof(lun_switch[0]);
|
|
|
|
sc->script_free_lo += lunsw->lunsw_size;
|
|
|
|
siop_script_sync(sc, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
2000-10-18 21:06:52 +04:00
|
|
|
return lunsw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_add_reselsw(sc, target)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
int target;
|
|
|
|
{
|
|
|
|
int i;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target;
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_lun *siop_lun;
|
2002-04-20 04:15:54 +04:00
|
|
|
|
|
|
|
siop_target = (struct siop_target *)sc->sc_c.targets[target];
|
2000-10-19 00:06:54 +04:00
|
|
|
/*
|
|
|
|
* add an entry to resel switch
|
|
|
|
*/
|
|
|
|
siop_script_sync(sc, BUS_DMASYNC_POSTWRITE);
|
2000-10-18 21:06:52 +04:00
|
|
|
for (i = 0; i < 15; i++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->reseloff = Ent_resel_targ0 / 4 + i * 2;
|
|
|
|
if ((siop_script_read(sc, siop_target->reseloff) & 0xff)
|
2000-10-18 21:06:52 +04:00
|
|
|
== 0xff) { /* it's free */
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
2000-10-18 21:06:52 +04:00
|
|
|
printf("siop: target %d slot %d offset %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
target, i, siop_target->reseloff);
|
2000-10-18 21:06:52 +04:00
|
|
|
#endif
|
|
|
|
/* JUMP abs_foo, IF target | 0x80; */
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_script_write(sc, siop_target->reseloff,
|
2000-10-18 21:06:52 +04:00
|
|
|
0x800c0080 | target);
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_script_write(sc, siop_target->reseloff + 1,
|
|
|
|
sc->sc_c.sc_scriptaddr +
|
|
|
|
siop_target->lunsw->lunsw_off * 4 +
|
2000-10-19 11:22:06 +04:00
|
|
|
Ent_lun_switch_entry);
|
2000-10-18 21:06:52 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 15) /* no free slot, shouldn't happen */
|
|
|
|
panic("siop: resel switch full");
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->sc_ntargets++;
|
2000-10-18 21:06:52 +04:00
|
|
|
for (i = 0; i < 8; i++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_lun = siop_target->siop_lun[i];
|
2000-10-23 18:56:16 +04:00
|
|
|
if (siop_lun == NULL)
|
|
|
|
continue;
|
|
|
|
if (siop_lun->reseloff > 0) {
|
|
|
|
siop_lun->reseloff = 0;
|
|
|
|
siop_add_dev(sc, target, i);
|
|
|
|
}
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_update_scntl3(sc, sc->sc_c.targets[target]);
|
2000-10-19 00:06:54 +04:00
|
|
|
siop_script_sync(sc, BUS_DMASYNC_PREWRITE);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_update_scntl3(sc, _siop_target)
|
2000-10-18 21:06:52 +04:00
|
|
|
struct siop_softc *sc;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_common_target *_siop_target;
|
2000-10-18 21:06:52 +04:00
|
|
|
{
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target = (struct siop_target *)_siop_target;
|
2000-10-18 21:06:52 +04:00
|
|
|
/* MOVE target->id >> 24 TO SCNTL3 */
|
|
|
|
siop_script_write(sc,
|
|
|
|
siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4),
|
2002-04-20 04:15:54 +04:00
|
|
|
0x78030000 | ((siop_target->target_c.id >> 16) & 0x0000ff00));
|
2000-10-18 21:06:52 +04:00
|
|
|
/* MOVE target->id >> 8 TO SXFER */
|
|
|
|
siop_script_write(sc,
|
|
|
|
siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4) + 2,
|
2002-04-20 04:15:54 +04:00
|
|
|
0x78050000 | (siop_target->target_c.id & 0x0000ff00));
|
2000-10-19 00:06:54 +04:00
|
|
|
siop_script_sync(sc, BUS_DMASYNC_PREWRITE);
|
2000-10-18 21:06:52 +04:00
|
|
|
}
|
|
|
|
|
2000-10-23 18:56:16 +04:00
|
|
|
void
|
|
|
|
siop_add_dev(sc, target, lun)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
int target;
|
|
|
|
int lun;
|
|
|
|
{
|
|
|
|
struct siop_lunsw *lunsw;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target =
|
|
|
|
(struct siop_target *)sc->sc_c.targets[target];
|
|
|
|
struct siop_lun *siop_lun = siop_target->siop_lun[lun];
|
2000-10-23 18:56:16 +04:00
|
|
|
int i, ntargets;
|
|
|
|
|
|
|
|
if (siop_lun->reseloff > 0)
|
|
|
|
return;
|
2002-04-20 04:15:54 +04:00
|
|
|
lunsw = siop_target->lunsw;
|
2000-10-23 18:56:16 +04:00
|
|
|
if ((lunsw->lunsw_off + lunsw->lunsw_size) < sc->script_free_lo) {
|
|
|
|
/*
|
|
|
|
* can't extend this slot. Probably not worth trying to deal
|
|
|
|
* with this case
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("%s:%d:%d: can't allocate a lun sw slot\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun);
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* count how many free targets we still have to probe */
|
2002-04-20 04:15:54 +04:00
|
|
|
ntargets = sc->sc_c.sc_chan.chan_ntargets - 1 - sc->sc_ntargets;
|
2000-10-23 18:56:16 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we need 8 bytes for the lun sw additionnal entry, and
|
|
|
|
* eventually sizeof(tag_switch) for the tag switch entry.
|
|
|
|
* Keep enouth free space for the free targets that could be
|
|
|
|
* probed later.
|
|
|
|
*/
|
|
|
|
if (sc->script_free_lo + 2 +
|
|
|
|
(ntargets * sizeof(lun_switch) / sizeof(lun_switch[0])) >=
|
2002-04-20 04:15:54 +04:00
|
|
|
((siop_target->target_c.flags & TARF_TAG) ?
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->script_free_hi - (sizeof(tag_switch) / sizeof(tag_switch[0])) :
|
|
|
|
sc->script_free_hi)) {
|
|
|
|
/*
|
|
|
|
* not enouth space, probably not worth dealing with it.
|
|
|
|
* We can hold 13 tagged-queuing capable devices in the 4k RAM.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("%s:%d:%d: not enouth memory for a lun sw slot\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun);
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("%s:%d:%d: allocate lun sw entry\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun);
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
|
|
|
/* INT int_resellun */
|
|
|
|
siop_script_write(sc, sc->script_free_lo, 0x98080000);
|
|
|
|
siop_script_write(sc, sc->script_free_lo + 1, A_int_resellun);
|
|
|
|
/* Now the slot entry: JUMP abs_foo, IF lun */
|
|
|
|
siop_script_write(sc, sc->script_free_lo - 2,
|
|
|
|
0x800c0000 | lun);
|
|
|
|
siop_script_write(sc, sc->script_free_lo - 1, 0);
|
|
|
|
siop_lun->reseloff = sc->script_free_lo - 2;
|
|
|
|
lunsw->lunsw_size += 2;
|
|
|
|
sc->script_free_lo += 2;
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_target->target_c.flags & TARF_TAG) {
|
2000-10-23 18:56:16 +04:00
|
|
|
/* we need a tag switch */
|
|
|
|
sc->script_free_hi -=
|
|
|
|
sizeof(tag_switch) / sizeof(tag_switch[0]);
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.features & SF_CHIP_RAM) {
|
|
|
|
bus_space_write_region_4(sc->sc_c.sc_ramt,
|
|
|
|
sc->sc_c.sc_ramh,
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->script_free_hi * 4, tag_switch,
|
|
|
|
sizeof(tag_switch) / sizeof(tag_switch[0]));
|
|
|
|
} else {
|
|
|
|
for(i = 0;
|
|
|
|
i < sizeof(tag_switch) / sizeof(tag_switch[0]);
|
|
|
|
i++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_script[sc->script_free_hi + i] =
|
2000-10-23 18:56:16 +04:00
|
|
|
htole32(tag_switch[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
siop_script_write(sc,
|
|
|
|
siop_lun->reseloff + 1,
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_scriptaddr + sc->script_free_hi * 4 +
|
2000-10-23 18:56:16 +04:00
|
|
|
Ent_tag_switch_entry);
|
|
|
|
|
|
|
|
for (i = 0; i < SIOP_NTAG; i++) {
|
|
|
|
siop_lun->siop_tag[i].reseloff =
|
|
|
|
sc->script_free_hi + (Ent_resel_tag0 / 4) + i * 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* non-tag case; just work with the lun switch */
|
|
|
|
siop_lun->siop_tag[0].reseloff =
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target->siop_lun[lun]->reseloff;
|
2000-10-23 18:56:16 +04:00
|
|
|
}
|
|
|
|
siop_script_sync(sc, BUS_DMASYNC_PREWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
siop_del_dev(sc, target, lun)
|
|
|
|
struct siop_softc *sc;
|
|
|
|
int target;
|
|
|
|
int lun;
|
|
|
|
{
|
|
|
|
int i;
|
2002-04-20 04:15:54 +04:00
|
|
|
struct siop_target *siop_target;
|
2000-10-23 18:56:16 +04:00
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("%s:%d:%d: free lun sw entry\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun);
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
2002-04-20 04:15:54 +04:00
|
|
|
if (sc->sc_c.targets[target] == NULL)
|
2000-10-23 18:56:16 +04:00
|
|
|
return;
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_target = (struct siop_target *)sc->sc_c.targets[target];
|
|
|
|
free(siop_target->siop_lun[lun], M_DEVBUF);
|
|
|
|
siop_target->siop_lun[lun] = NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
/* XXX compact sw entry too ? */
|
|
|
|
/* check if we can free the whole target */
|
|
|
|
for (i = 0; i < 8; i++) {
|
2002-04-20 04:15:54 +04:00
|
|
|
if (siop_target->siop_lun[i] != NULL)
|
2000-10-23 18:56:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef SIOP_DEBUG
|
|
|
|
printf("%s: free siop_target for target %d lun %d lunsw offset %d\n",
|
2002-04-20 04:15:54 +04:00
|
|
|
sc->sc_c.sc_dev.dv_xname, target, lun,
|
|
|
|
sc->sc_c.targets[target]->lunsw->lunsw_off);
|
2000-10-23 18:56:16 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* nothing here, free the target struct and resel
|
|
|
|
* switch entry
|
|
|
|
*/
|
2002-04-20 04:15:54 +04:00
|
|
|
siop_script_write(sc, siop_target->reseloff, 0x800c00ff);
|
2000-10-23 18:56:16 +04:00
|
|
|
siop_script_sync(sc, BUS_DMASYNC_PREWRITE);
|
2002-04-20 04:15:54 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->lunsw_list, siop_target->lunsw, next);
|
|
|
|
free(sc->sc_c.targets[target], M_DEVBUF);
|
|
|
|
sc->sc_c.targets[target] = NULL;
|
2000-10-23 18:56:16 +04:00
|
|
|
sc->sc_ntargets--;
|
|
|
|
}
|
|
|
|
|
2000-04-25 20:27:05 +04:00
|
|
|
#ifdef SIOP_STATS
|
|
|
|
void
|
|
|
|
siop_printstats()
|
|
|
|
{
|
|
|
|
printf("siop_stat_intr %d\n", siop_stat_intr);
|
|
|
|
printf("siop_stat_intr_shortxfer %d\n", siop_stat_intr_shortxfer);
|
|
|
|
printf("siop_stat_intr_xferdisc %d\n", siop_stat_intr_xferdisc);
|
|
|
|
printf("siop_stat_intr_sdp %d\n", siop_stat_intr_sdp);
|
|
|
|
printf("siop_stat_intr_done %d\n", siop_stat_intr_done);
|
2000-10-23 18:56:16 +04:00
|
|
|
printf("siop_stat_intr_lunresel %d\n", siop_stat_intr_lunresel);
|
2000-10-24 03:18:10 +04:00
|
|
|
printf("siop_stat_intr_qfull %d\n", siop_stat_intr_qfull);
|
2000-04-25 20:27:05 +04:00
|
|
|
}
|
|
|
|
#endif
|