2002-04-05 22:27:45 +04:00
|
|
|
/* $NetBSD: adv.c,v 1.31 2002/04/05 18:27:49 bouyer Exp $ */
|
1998-08-29 17:44:49 +04:00
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
/*
|
1998-09-26 20:02:56 +04:00
|
|
|
* Generic driver for the Advanced Systems Inc. Narrow SCSI controllers
|
1998-08-26 18:13:58 +04:00
|
|
|
*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Baldassare Dante Profeta <dante@mclink.it>
|
|
|
|
*
|
|
|
|
* 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:
|
1998-09-26 20:02:56 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
1998-08-26 18:13:58 +04:00
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-04-05 22:27:45 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: adv.c,v 1.31 2002/04/05 18:27:49 bouyer Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-08-26 18:13:58 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
2000-06-28 21:12:48 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
|
|
|
|
#include <dev/ic/advlib.h>
|
1999-02-25 23:21:33 +03:00
|
|
|
#include <dev/ic/adv.h>
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-09 09:28:58 +04:00
|
|
|
#ifndef DDB
|
|
|
|
#define Debugger() panic("should call debugger here (adv.c)")
|
|
|
|
#endif /* ! DDB */
|
|
|
|
|
1998-10-28 23:39:45 +03:00
|
|
|
|
|
|
|
/* #define ASC_DEBUG */
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
1999-08-07 11:20:15 +04:00
|
|
|
static int adv_alloc_control_data __P((ASC_SOFTC *));
|
2001-03-08 09:49:49 +03:00
|
|
|
static void adv_free_control_data __P((ASC_SOFTC *));
|
1998-08-26 18:13:58 +04:00
|
|
|
static int adv_create_ccbs __P((ASC_SOFTC *, ADV_CCB *, int));
|
|
|
|
static void adv_free_ccb __P((ASC_SOFTC *, ADV_CCB *));
|
|
|
|
static void adv_reset_ccb __P((ADV_CCB *));
|
|
|
|
static int adv_init_ccb __P((ASC_SOFTC *, ADV_CCB *));
|
2001-04-25 21:53:04 +04:00
|
|
|
static ADV_CCB *adv_get_ccb __P((ASC_SOFTC *));
|
1998-08-26 18:13:58 +04:00
|
|
|
static void adv_queue_ccb __P((ASC_SOFTC *, ADV_CCB *));
|
|
|
|
static void adv_start_ccbs __P((ASC_SOFTC *));
|
|
|
|
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
static void adv_scsipi_request __P((struct scsipi_channel *,
|
|
|
|
scsipi_adapter_req_t, void *));
|
1998-08-26 18:13:58 +04:00
|
|
|
static void advminphys __P((struct buf *));
|
|
|
|
static void adv_narrow_isr_callback __P((ASC_SOFTC *, ASC_QDONE_INFO *));
|
|
|
|
|
|
|
|
static int adv_poll __P((ASC_SOFTC *, struct scsipi_xfer *, int));
|
|
|
|
static void adv_timeout __P((void *));
|
|
|
|
static void adv_watchdog __P((void *));
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
#define ADV_ABORT_TIMEOUT 2000 /* time to wait for abort (mSec) */
|
|
|
|
#define ADV_WATCH_TIMEOUT 1000 /* time to wait for watchdog (mSec) */
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Control Blocks routines */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
1999-08-07 11:20:15 +04:00
|
|
|
adv_alloc_control_data(sc)
|
1998-08-26 18:13:58 +04:00
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
2001-03-08 09:49:49 +03:00
|
|
|
int error;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Allocate the control blocks.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat, sizeof(struct adv_control),
|
2001-03-08 09:49:49 +03:00
|
|
|
PAGE_SIZE, 0, &sc->sc_control_seg, 1,
|
|
|
|
&sc->sc_control_nsegs, BUS_DMA_NOWAIT)) != 0) {
|
1998-08-26 18:13:58 +04:00
|
|
|
printf("%s: unable to allocate control structures,"
|
|
|
|
" error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
return (error);
|
|
|
|
}
|
2001-03-08 09:49:49 +03:00
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_control_seg,
|
|
|
|
sc->sc_control_nsegs, sizeof(struct adv_control),
|
|
|
|
(caddr_t *) & sc->sc_control,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
1998-08-26 18:13:58 +04:00
|
|
|
printf("%s: unable to map control structures, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Create and load the DMA map used for the control blocks.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, sizeof(struct adv_control),
|
|
|
|
1, sizeof(struct adv_control), 0, BUS_DMA_NOWAIT,
|
|
|
|
&sc->sc_dmamap_control)) != 0) {
|
|
|
|
printf("%s: unable to create control DMA map, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap_control,
|
|
|
|
sc->sc_control, sizeof(struct adv_control), NULL,
|
|
|
|
BUS_DMA_NOWAIT)) != 0) {
|
|
|
|
printf("%s: unable to load control DMA map, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-08-07 11:20:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the overrun_buf address.
|
|
|
|
*/
|
|
|
|
sc->overrun_buf = sc->sc_dmamap_control->dm_segs[0].ds_addr +
|
|
|
|
offsetof(struct adv_control, overrun_buf);
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-03-08 09:49:49 +03:00
|
|
|
static void
|
|
|
|
adv_free_control_data(sc)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap_control);
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap_control);
|
|
|
|
sc->sc_dmamap_control = NULL;
|
|
|
|
|
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (caddr_t) sc->sc_control,
|
|
|
|
sizeof(struct adv_control));
|
|
|
|
bus_dmamem_free(sc->sc_dmat, &sc->sc_control_seg,
|
|
|
|
sc->sc_control_nsegs);
|
|
|
|
}
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a set of ccbs and add them to the free list. Called once
|
|
|
|
* by adv_init(). We return the number of CCBs successfully created.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
adv_create_ccbs(sc, ccbstore, count)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
ADV_CCB *ccbstore;
|
|
|
|
int count;
|
|
|
|
{
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
int i, error;
|
|
|
|
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(ccbstore, 0, sizeof(ADV_CCB) * count);
|
1998-08-26 18:13:58 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
ccb = &ccbstore[i];
|
|
|
|
if ((error = adv_init_ccb(sc, ccb)) != 0) {
|
|
|
|
printf("%s: unable to initialize ccb, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&sc->sc_free_ccb, ccb, chain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A ccb is put onto the free list.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adv_free_ccb(sc, ccb)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
adv_reset_ccb(ccb);
|
|
|
|
TAILQ_INSERT_HEAD(&sc->sc_free_ccb, ccb, chain);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_reset_ccb(ccb)
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
{
|
|
|
|
|
|
|
|
ccb->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
adv_init_ccb(sc, ccb)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
{
|
1999-02-25 23:21:33 +03:00
|
|
|
int hashnum, error;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&ccb->ccb_watchdog);
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Create the DMA map for this CCB.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
error = bus_dmamap_create(sc->sc_dmat,
|
|
|
|
(ASC_MAX_SG_LIST - 1) * PAGE_SIZE,
|
|
|
|
ASC_MAX_SG_LIST, (ASC_MAX_SG_LIST - 1) * PAGE_SIZE,
|
|
|
|
0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ccb->dmamap_xfer);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to create DMA map, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-02-25 23:21:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* put in the phystokv hash table
|
|
|
|
* Never gets taken out.
|
|
|
|
*/
|
|
|
|
ccb->hashkey = sc->sc_dmamap_control->dm_segs[0].ds_addr +
|
|
|
|
ADV_CCB_OFF(ccb);
|
|
|
|
hashnum = CCB_HASH(ccb->hashkey);
|
|
|
|
ccb->nexthash = sc->sc_ccbhash[hashnum];
|
|
|
|
sc->sc_ccbhash[hashnum] = ccb;
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
adv_reset_ccb(ccb);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a free ccb
|
|
|
|
*
|
|
|
|
* If there are none, see if we can allocate a new one
|
|
|
|
*/
|
|
|
|
static ADV_CCB *
|
2001-04-25 21:53:04 +04:00
|
|
|
adv_get_ccb(sc)
|
1998-08-26 18:13:58 +04:00
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
|
|
|
ADV_CCB *ccb = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
2001-04-25 21:53:04 +04:00
|
|
|
ccb = TAILQ_FIRST(&sc->sc_free_ccb);
|
|
|
|
if (ccb != NULL) {
|
|
|
|
TAILQ_REMOVE(&sc->sc_free_ccb, ccb, chain);
|
|
|
|
ccb->flags |= CCB_ALLOC;
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 23:21:33 +03:00
|
|
|
/*
|
|
|
|
* Given a physical address, find the ccb that it corresponds to.
|
|
|
|
*/
|
|
|
|
ADV_CCB *
|
|
|
|
adv_ccb_phys_kv(sc, ccb_phys)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
u_long ccb_phys;
|
|
|
|
{
|
|
|
|
int hashnum = CCB_HASH(ccb_phys);
|
|
|
|
ADV_CCB *ccb = sc->sc_ccbhash[hashnum];
|
|
|
|
|
|
|
|
while (ccb) {
|
|
|
|
if (ccb->hashkey == ccb_phys)
|
|
|
|
break;
|
|
|
|
ccb = ccb->nexthash;
|
|
|
|
}
|
|
|
|
return (ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
/*
|
|
|
|
* Queue a CCB to be sent to the controller, and send it if possible.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adv_queue_ccb(sc, ccb)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->sc_waiting_ccb, ccb, chain);
|
|
|
|
|
|
|
|
adv_start_ccbs(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_start_ccbs(sc)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
|
|
|
|
while ((ccb = sc->sc_waiting_ccb.tqh_first) != NULL) {
|
|
|
|
if (ccb->flags & CCB_WATCHDOG)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&ccb->ccb_watchdog);
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
if (AscExeScsiQueue(sc, &ccb->scsiq) == ASC_BUSY) {
|
|
|
|
ccb->flags |= CCB_WATCHDOG;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&ccb->ccb_watchdog,
|
|
|
|
(ADV_WATCH_TIMEOUT * hz) / 1000,
|
|
|
|
adv_watchdog, ccb);
|
1998-08-26 18:13:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&sc->sc_waiting_ccb, ccb, chain);
|
|
|
|
|
1999-10-01 03:04:39 +04:00
|
|
|
if ((ccb->xs->xs_control & XS_CTL_POLL) == 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&ccb->xs->xs_callout,
|
2002-04-05 22:27:45 +04:00
|
|
|
mstohz(ccb->timeout), adv_timeout, ccb);
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* SCSI layer interfacing routines */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
adv_init(sc)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
|
|
|
int warn;
|
|
|
|
|
1999-06-06 21:33:18 +04:00
|
|
|
if (!AscFindSignature(sc->sc_iot, sc->sc_ioh)) {
|
|
|
|
printf("adv_init: failed to find signature\n");
|
|
|
|
return (1);
|
|
|
|
}
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Read the board configuration
|
|
|
|
*/
|
1998-09-26 20:02:56 +04:00
|
|
|
AscInitASC_SOFTC(sc);
|
|
|
|
warn = AscInitFromEEP(sc);
|
|
|
|
if (warn) {
|
|
|
|
printf("%s -get: ", sc->sc_dev.dv_xname);
|
|
|
|
switch (warn) {
|
|
|
|
case -1:
|
|
|
|
printf("Chip is not halted\n");
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
case -2:
|
|
|
|
printf("Couldn't get MicroCode Start"
|
|
|
|
" address\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_IO_PORT_ROTATE:
|
|
|
|
printf("I/O port address modified\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_AUTO_CONFIG:
|
|
|
|
printf("I/O port increment switch enabled\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_EEPROM_CHKSUM:
|
|
|
|
printf("EEPROM checksum error\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_IRQ_MODIFIED:
|
|
|
|
printf("IRQ modified\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_CMD_QNG_CONFLICT:
|
|
|
|
printf("tag queuing enabled w/o disconnects\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("unknown warning %d\n", warn);
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
1998-09-26 20:02:56 +04:00
|
|
|
}
|
|
|
|
if (sc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
|
|
|
|
sc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
|
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Modify the board configuration
|
|
|
|
*/
|
1998-09-26 20:02:56 +04:00
|
|
|
warn = AscInitFromASC_SOFTC(sc);
|
|
|
|
if (warn) {
|
|
|
|
printf("%s -set: ", sc->sc_dev.dv_xname);
|
|
|
|
switch (warn) {
|
|
|
|
case ASC_WARN_CMD_QNG_CONFLICT:
|
|
|
|
printf("tag queuing enabled w/o disconnects\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_WARN_AUTO_CONFIG:
|
|
|
|
printf("I/O port increment switch enabled\n");
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
default:
|
|
|
|
printf("unknown warning %d\n", warn);
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
1998-09-26 20:02:56 +04:00
|
|
|
}
|
1999-03-04 23:15:53 +03:00
|
|
|
sc->isr_callback = (ASC_CALLBACK) adv_narrow_isr_callback;
|
1998-09-26 20:02:56 +04:00
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_attach(sc)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_adapter *adapt = &sc->sc_adapter;
|
|
|
|
struct scsipi_channel *chan = &sc->sc_channel;
|
1998-08-26 18:13:58 +04:00
|
|
|
int i, error;
|
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Initialize board RISC chip and enable interrupts.
|
|
|
|
*/
|
1998-09-26 20:02:56 +04:00
|
|
|
switch (AscInitDriver(sc)) {
|
|
|
|
case 0:
|
|
|
|
/* AllOK */
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
case 1:
|
|
|
|
panic("%s: bad signature", sc->sc_dev.dv_xname);
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
case 2:
|
|
|
|
panic("%s: unable to load MicroCode",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
case 3:
|
|
|
|
panic("%s: unable to initialize MicroCode",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
break;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
1998-09-26 20:02:56 +04:00
|
|
|
default:
|
|
|
|
panic("%s: unable to initialize board RISC chip",
|
|
|
|
sc->sc_dev.dv_xname);
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 00:43:00 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Fill in the scsipi_adapter.
|
1998-11-20 00:43:00 +03:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
memset(adapt, 0, sizeof(*adapt));
|
|
|
|
adapt->adapt_dev = &sc->sc_dev;
|
|
|
|
adapt->adapt_nchannels = 1;
|
|
|
|
/* adapt_openings initialized below */
|
|
|
|
/* adapt_max_periph initialized below */
|
|
|
|
adapt->adapt_request = adv_scsipi_request;
|
|
|
|
adapt->adapt_minphys = advminphys;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Fill in the scsipi_channel.
|
|
|
|
*/
|
|
|
|
memset(chan, 0, sizeof(*chan));
|
|
|
|
chan->chan_adapter = adapt;
|
|
|
|
chan->chan_bustype = &scsi_bustype;
|
|
|
|
chan->chan_channel = 0;
|
|
|
|
chan->chan_ntargets = 8;
|
|
|
|
chan->chan_nluns = 8;
|
|
|
|
chan->chan_id = sc->chip_scsi_id;
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&sc->sc_free_ccb);
|
|
|
|
TAILQ_INIT(&sc->sc_waiting_ccb);
|
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Allocate the Control Blocks and the overrun buffer.
|
|
|
|
*/
|
1999-08-07 11:20:15 +04:00
|
|
|
error = adv_alloc_control_data(sc);
|
1998-08-26 18:13:58 +04:00
|
|
|
if (error)
|
1999-06-06 21:33:18 +04:00
|
|
|
return; /* (error) */
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Create and initialize the Control Blocks.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
i = adv_create_ccbs(sc, sc->sc_control->ccbs, ADV_MAX_CCB);
|
|
|
|
if (i == 0) {
|
|
|
|
printf("%s: unable to create control blocks\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return; /* (ENOMEM) */ ;
|
|
|
|
} else if (i != ADV_MAX_CCB) {
|
|
|
|
printf("%s: WARNING: only %d of %d control blocks created\n",
|
|
|
|
sc->sc_dev.dv_xname, i, ADV_MAX_CCB);
|
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
|
|
|
|
adapt->adapt_openings = i;
|
|
|
|
adapt->adapt_max_periph = adapt->adapt_openings;
|
|
|
|
|
|
|
|
sc->sc_child = config_found(&sc->sc_dev, chan, scsiprint);
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
|
|
|
|
2001-03-08 09:49:49 +03:00
|
|
|
int
|
|
|
|
adv_detach(sc, flags)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (sc->sc_child != NULL)
|
|
|
|
rv = config_detach(sc->sc_child, flags);
|
|
|
|
|
|
|
|
adv_free_control_data(sc);
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
advminphys(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bp->b_bcount > ((ASC_MAX_SG_LIST - 1) * PAGE_SIZE))
|
|
|
|
bp->b_bcount = ((ASC_MAX_SG_LIST - 1) * PAGE_SIZE);
|
|
|
|
minphys(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start a scsi operation given the command and the data address. Also needs
|
|
|
|
* the unit, target and lu.
|
|
|
|
*/
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
static void
|
|
|
|
adv_scsipi_request(chan, req, arg)
|
|
|
|
struct scsipi_channel *chan;
|
|
|
|
scsipi_adapter_req_t req;
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct scsipi_xfer *xs;
|
|
|
|
struct scsipi_periph *periph;
|
|
|
|
ASC_SOFTC *sc = (void *)chan->chan_adapter->adapt_dev;
|
|
|
|
bus_dma_tag_t dmat = sc->sc_dmat;
|
|
|
|
ADV_CCB *ccb;
|
|
|
|
int s, flags, error, nsegs;
|
|
|
|
|
|
|
|
switch (req) {
|
|
|
|
case ADAPTER_REQ_RUN_XFER:
|
|
|
|
xs = arg;
|
|
|
|
periph = xs->xs_periph;
|
|
|
|
flags = xs->xs_control;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a CCB to use.
|
|
|
|
*/
|
|
|
|
ccb = adv_get_ccb(sc);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/*
|
|
|
|
* This should never happen as we track the resources
|
|
|
|
* in the mid-layer.
|
|
|
|
*/
|
|
|
|
if (ccb == NULL) {
|
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("unable to allocate ccb\n");
|
|
|
|
panic("adv_scsipi_request");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ccb->xs = xs;
|
|
|
|
ccb->timeout = xs->timeout;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build up the request
|
|
|
|
*/
|
|
|
|
memset(&ccb->scsiq, 0, sizeof(ASC_SCSI_Q));
|
|
|
|
|
|
|
|
ccb->scsiq.q2.ccb_ptr =
|
|
|
|
sc->sc_dmamap_control->dm_segs[0].ds_addr +
|
|
|
|
ADV_CCB_OFF(ccb);
|
|
|
|
|
|
|
|
ccb->scsiq.cdbptr = &xs->cmd->opcode;
|
|
|
|
ccb->scsiq.q2.cdb_len = xs->cmdlen;
|
|
|
|
ccb->scsiq.q1.target_id =
|
|
|
|
ASC_TID_TO_TARGET_ID(periph->periph_target);
|
|
|
|
ccb->scsiq.q1.target_lun = periph->periph_lun;
|
|
|
|
ccb->scsiq.q2.target_ix =
|
|
|
|
ASC_TIDLUN_TO_IX(periph->periph_target,
|
|
|
|
periph->periph_lun);
|
|
|
|
ccb->scsiq.q1.sense_addr =
|
|
|
|
sc->sc_dmamap_control->dm_segs[0].ds_addr +
|
|
|
|
ADV_CCB_OFF(ccb) + offsetof(struct adv_ccb, scsi_sense);
|
|
|
|
ccb->scsiq.q1.sense_len = sizeof(struct scsipi_sense_data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are any outstanding requests for the current
|
|
|
|
* target, then every 255th request send an ORDERED request.
|
|
|
|
* This heuristic tries to retain the benefit of request
|
|
|
|
* sorting while preventing request starvation. 255 is the
|
|
|
|
* max number of tags or pending commands a device may have
|
|
|
|
* outstanding.
|
|
|
|
*/
|
|
|
|
sc->reqcnt[periph->periph_target]++;
|
|
|
|
if (((sc->reqcnt[periph->periph_target] > 0) &&
|
|
|
|
(sc->reqcnt[periph->periph_target] % 255) == 0) ||
|
|
|
|
xs->bp == NULL || (xs->bp->b_flags & B_ASYNC) == 0) {
|
|
|
|
ccb->scsiq.q2.tag_code = M2_QTAG_MSG_ORDERED;
|
|
|
|
} else {
|
|
|
|
ccb->scsiq.q2.tag_code = M2_QTAG_MSG_SIMPLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xs->datalen) {
|
|
|
|
/*
|
|
|
|
* Map the DMA transfer.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
#ifdef TFS
|
2001-04-25 21:53:04 +04:00
|
|
|
if (flags & SCSI_DATA_UIO) {
|
|
|
|
error = bus_dmamap_load_uio(dmat,
|
|
|
|
ccb->dmamap_xfer, (struct uio *) xs->data,
|
|
|
|
((flags & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT :
|
2001-07-19 20:25:23 +04:00
|
|
|
BUS_DMA_WAITOK) | BUS_DMA_STREAMING |
|
|
|
|
((flags & XS_CTL_DATA_IN) ? BUS_DMA_READ :
|
|
|
|
BUS_DMA_WRITE));
|
2001-04-25 21:53:04 +04:00
|
|
|
} else
|
|
|
|
#endif /* TFS */
|
|
|
|
{
|
|
|
|
error = bus_dmamap_load(dmat, ccb->dmamap_xfer,
|
|
|
|
xs->data, xs->datalen, NULL,
|
|
|
|
((flags & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT :
|
2001-07-19 20:25:23 +04:00
|
|
|
BUS_DMA_WAITOK) | BUS_DMA_STREAMING |
|
|
|
|
((flags & XS_CTL_DATA_IN) ? BUS_DMA_READ :
|
|
|
|
BUS_DMA_WRITE));
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ENOMEM:
|
|
|
|
case EAGAIN:
|
|
|
|
xs->error = XS_RESOURCE_SHORTAGE;
|
|
|
|
goto out_bad;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
if (error == EFBIG) {
|
|
|
|
printf("%s: adv_scsi_cmd, more than %d"
|
|
|
|
" dma segments\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
ASC_MAX_SG_LIST);
|
|
|
|
} else {
|
|
|
|
printf("%s: adv_scsi_cmd, error %d"
|
|
|
|
" loading dma map\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
out_bad:
|
|
|
|
adv_free_ccb(sc, ccb);
|
|
|
|
scsipi_done(xs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(dmat, ccb->dmamap_xfer, 0,
|
|
|
|
ccb->dmamap_xfer->dm_mapsize,
|
|
|
|
(flags & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
memset(&ccb->sghead, 0, sizeof(ASC_SG_HEAD));
|
|
|
|
|
|
|
|
for (nsegs = 0;
|
|
|
|
nsegs < ccb->dmamap_xfer->dm_nsegs; nsegs++) {
|
|
|
|
ccb->sghead.sg_list[nsegs].addr =
|
|
|
|
ccb->dmamap_xfer->dm_segs[nsegs].ds_addr;
|
|
|
|
ccb->sghead.sg_list[nsegs].bytes =
|
|
|
|
ccb->dmamap_xfer->dm_segs[nsegs].ds_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccb->sghead.entry_cnt = ccb->scsiq.q1.sg_queue_cnt =
|
|
|
|
ccb->dmamap_xfer->dm_nsegs;
|
|
|
|
|
|
|
|
ccb->scsiq.q1.cntl |= ASC_QC_SG_HEAD;
|
|
|
|
ccb->scsiq.sg_head = &ccb->sghead;
|
|
|
|
ccb->scsiq.q1.data_addr = 0;
|
|
|
|
ccb->scsiq.q1.data_cnt = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No data xfer, use non S/G values.
|
|
|
|
*/
|
|
|
|
ccb->scsiq.q1.data_addr = 0;
|
|
|
|
ccb->scsiq.q1.data_cnt = 0;
|
|
|
|
}
|
|
|
|
|
1998-10-28 23:39:45 +03:00
|
|
|
#ifdef ASC_DEBUG
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("id = 0, lun = 0, cmd = 0, ccb = 0x0 \n",
|
|
|
|
periph->periph_target,
|
|
|
|
periph->periph_lun, xs->cmd->opcode,
|
|
|
|
(unsigned long)ccb);
|
1998-10-28 23:39:45 +03:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
s = splbio();
|
|
|
|
adv_queue_ccb(sc, ccb);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if ((flags & XS_CTL_POLL) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Not allowed to use interrupts, poll for completion. */
|
|
|
|
if (adv_poll(sc, xs, ccb->timeout)) {
|
|
|
|
adv_timeout(ccb);
|
|
|
|
if (adv_poll(sc, xs, ccb->timeout))
|
|
|
|
adv_timeout(ccb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_GROW_RESOURCES:
|
|
|
|
/* XXX Not supported. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ADAPTER_REQ_SET_XFER_MODE:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We can't really set the mode, but we know how to
|
|
|
|
* query what the firmware negotiated.
|
|
|
|
*/
|
|
|
|
struct scsipi_xfer_mode *xm = arg;
|
|
|
|
u_int8_t sdtr_data;
|
|
|
|
ASC_SCSI_BIT_ID_TYPE tid_bit;
|
|
|
|
|
|
|
|
tid_bit = ASC_TIX_TO_TARGET_ID(xm->xm_target);
|
|
|
|
|
|
|
|
xm->xm_mode = 0;
|
|
|
|
xm->xm_period = 0;
|
|
|
|
xm->xm_offset = 0;
|
|
|
|
|
|
|
|
if (sc->init_sdtr & tid_bit) {
|
|
|
|
xm->xm_mode |= PERIPH_CAP_SYNC;
|
|
|
|
sdtr_data = sc->sdtr_data[xm->xm_target];
|
|
|
|
xm->xm_period =
|
|
|
|
sc->sdtr_period_tbl[(sdtr_data >> 4) &
|
|
|
|
(sc->max_sdtr_index - 1)];
|
|
|
|
xm->xm_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->use_tagged_qng & tid_bit)
|
|
|
|
xm->xm_mode |= PERIPH_CAP_TQING;
|
|
|
|
|
|
|
|
scsipi_async_event(chan, ASYNC_EVENT_XFER_MODE, xm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-08-26 18:13:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
adv_intr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
ASC_SOFTC *sc = arg;
|
|
|
|
|
1998-10-28 23:39:45 +03:00
|
|
|
#ifdef ASC_DEBUG
|
|
|
|
int int_pend = FALSE;
|
|
|
|
|
|
|
|
if(ASC_IS_INT_PENDING(sc->sc_iot, sc->sc_ioh))
|
|
|
|
{
|
|
|
|
int_pend = TRUE;
|
|
|
|
printf("ISR - ");
|
|
|
|
}
|
|
|
|
#endif
|
1998-09-26 20:02:56 +04:00
|
|
|
AscISR(sc);
|
1998-10-28 23:39:45 +03:00
|
|
|
#ifdef ASC_DEBUG
|
|
|
|
if(int_pend)
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll a particular unit, looking for a particular xs
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
adv_poll(sc, xs, count)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
struct scsipi_xfer *xs;
|
|
|
|
int count;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* timeouts are in msec, so we loop in 1000 usec cycles */
|
|
|
|
while (count) {
|
|
|
|
adv_intr(sc);
|
1999-10-01 03:04:39 +04:00
|
|
|
if (xs->xs_status & XS_STS_DONE)
|
1998-08-26 18:13:58 +04:00
|
|
|
return (0);
|
|
|
|
delay(1000); /* only happens in boot so ok */
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_timeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
ADV_CCB *ccb = arg;
|
|
|
|
struct scsipi_xfer *xs = ccb->xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
|
|
|
ASC_SOFTC *sc =
|
|
|
|
(void *)periph->periph_channel->chan_adapter->adapt_dev;
|
1998-08-26 18:13:58 +04:00
|
|
|
int s;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1998-08-26 18:13:58 +04:00
|
|
|
printf("timed out");
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* If it has been through before, then a previous abort has failed,
|
|
|
|
* don't try abort again, reset the bus instead.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
if (ccb->flags & CCB_ABORT) {
|
|
|
|
/* abort timed out */
|
|
|
|
printf(" AGAIN. Resetting Bus\n");
|
|
|
|
/* Lets try resetting the bus! */
|
|
|
|
if (AscResetBus(sc) == ASC_ERROR) {
|
|
|
|
ccb->timeout = sc->scsi_reset_wait;
|
|
|
|
adv_queue_ccb(sc, ccb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
|
|
|
printf("\n");
|
1999-02-25 23:21:33 +03:00
|
|
|
AscAbortCCB(sc, ccb);
|
1998-08-26 18:13:58 +04:00
|
|
|
ccb->xs->error = XS_TIMEOUT;
|
|
|
|
ccb->timeout = ADV_ABORT_TIMEOUT;
|
|
|
|
ccb->flags |= CCB_ABORT;
|
|
|
|
adv_queue_ccb(sc, ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_watchdog(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
ADV_CCB *ccb = arg;
|
|
|
|
struct scsipi_xfer *xs = ccb->xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
|
|
|
ASC_SOFTC *sc =
|
|
|
|
(void *)periph->periph_channel->chan_adapter->adapt_dev;
|
1998-08-26 18:13:58 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
ccb->flags &= ~CCB_WATCHDOG;
|
|
|
|
adv_start_ccbs(sc);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
1999-02-25 23:21:33 +03:00
|
|
|
/* NARROW boards Interrupt callbacks */
|
1998-08-26 18:13:58 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* adv_narrow_isr_callback() - Second Level Interrupt Handler called by AscISR()
|
|
|
|
*
|
|
|
|
* Interrupt callback function for the Narrow SCSI Asc Library.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adv_narrow_isr_callback(sc, qdonep)
|
|
|
|
ASC_SOFTC *sc;
|
|
|
|
ASC_QDONE_INFO *qdonep;
|
|
|
|
{
|
|
|
|
bus_dma_tag_t dmat = sc->sc_dmat;
|
1999-02-25 23:21:33 +03:00
|
|
|
ADV_CCB *ccb;
|
|
|
|
struct scsipi_xfer *xs;
|
1998-08-26 18:13:58 +04:00
|
|
|
struct scsipi_sense_data *s1, *s2;
|
|
|
|
|
|
|
|
|
1999-02-25 23:21:33 +03:00
|
|
|
ccb = adv_ccb_phys_kv(sc, qdonep->d2.ccb_ptr);
|
|
|
|
xs = ccb->xs;
|
|
|
|
|
1998-10-28 23:39:45 +03:00
|
|
|
#ifdef ASC_DEBUG
|
|
|
|
printf(" - ccb=0x%lx, id=%d, lun=%d, cmd=%d, ",
|
|
|
|
(unsigned long)ccb,
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target,
|
|
|
|
xs->xs_periph->periph_lun, xs->cmd->opcode);
|
1998-10-28 23:39:45 +03:00
|
|
|
#endif
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&ccb->xs->xs_callout);
|
1998-08-26 18:13:58 +04:00
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* If we were a data transfer, unload the map that described
|
|
|
|
* the data buffer.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
if (xs->datalen) {
|
|
|
|
bus_dmamap_sync(dmat, ccb->dmamap_xfer, 0,
|
|
|
|
ccb->dmamap_xfer->dm_mapsize,
|
1999-10-01 03:04:39 +04:00
|
|
|
(xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
|
1998-08-26 18:13:58 +04:00
|
|
|
bus_dmamap_unload(dmat, ccb->dmamap_xfer);
|
|
|
|
}
|
|
|
|
if ((ccb->flags & CCB_ALLOC) == 0) {
|
|
|
|
printf("%s: exiting ccb not allocated!\n", sc->sc_dev.dv_xname);
|
|
|
|
Debugger();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* 'qdonep' contains the command's ending status.
|
|
|
|
*/
|
1998-10-28 23:39:45 +03:00
|
|
|
#ifdef ASC_DEBUG
|
|
|
|
printf("d_s=%d, h_s=%d", qdonep->d3.done_stat, qdonep->d3.host_stat);
|
|
|
|
#endif
|
1998-08-26 18:13:58 +04:00
|
|
|
switch (qdonep->d3.done_stat) {
|
|
|
|
case ASC_QD_NO_ERROR:
|
|
|
|
switch (qdonep->d3.host_stat) {
|
|
|
|
case ASC_QHSTA_NO_ERROR:
|
|
|
|
xs->error = XS_NOERROR;
|
|
|
|
xs->resid = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* QHSTA error occurred */
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* If an INQUIRY command completed successfully, then call
|
|
|
|
* the AscInquiryHandling() function to patch bugged boards.
|
|
|
|
*/
|
1998-08-26 18:13:58 +04:00
|
|
|
if ((xs->cmd->opcode == SCSICMD_Inquiry) &&
|
2001-04-25 21:53:04 +04:00
|
|
|
(xs->xs_periph->periph_lun == 0) &&
|
1998-08-26 18:13:58 +04:00
|
|
|
(xs->datalen - qdonep->remain_bytes) >= 8) {
|
|
|
|
AscInquiryHandling(sc,
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->xs_periph->periph_target & 0x7,
|
1998-08-26 18:13:58 +04:00
|
|
|
(ASC_SCSI_INQUIRY *) xs->data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_QD_WITH_ERROR:
|
|
|
|
switch (qdonep->d3.host_stat) {
|
|
|
|
case ASC_QHSTA_NO_ERROR:
|
|
|
|
if (qdonep->d3.scsi_stat == SS_CHK_CONDITION) {
|
|
|
|
s1 = &ccb->scsi_sense;
|
|
|
|
s2 = &xs->sense.scsi_sense;
|
|
|
|
*s2 = *s1;
|
|
|
|
xs->error = XS_SENSE;
|
1998-09-26 20:02:56 +04:00
|
|
|
} else {
|
1998-08-26 18:13:58 +04:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1998-09-26 20:02:56 +04:00
|
|
|
}
|
1998-08-26 18:13:58 +04:00
|
|
|
break;
|
|
|
|
|
2001-06-09 21:18:21 +04:00
|
|
|
case ASC_QHSTA_M_SEL_TIMEOUT:
|
2001-06-09 22:08:20 +04:00
|
|
|
xs->error = XS_SELTIMEOUT;
|
2001-06-09 21:18:21 +04:00
|
|
|
break;
|
|
|
|
|
1998-08-26 18:13:58 +04:00
|
|
|
default:
|
|
|
|
/* QHSTA error occurred */
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASC_QD_ABORTED_BY_HOST:
|
|
|
|
default:
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
adv_free_ccb(sc, ccb);
|
|
|
|
scsipi_done(xs);
|
|
|
|
}
|