2002-10-02 07:10:45 +04:00
|
|
|
/* $NetBSD: wds.c,v 1.52 2002/10/02 03:10:50 thorpej Exp $ */
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* aborts
|
|
|
|
* resets
|
|
|
|
*/
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
/*-
|
1998-02-04 08:12:46 +03:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-09-04 07:39:09 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Julian Highfield. All rights reserved.
|
1997-03-29 05:11:09 +03:00
|
|
|
* Portions copyright (c) 1994, 1996, 1997
|
|
|
|
* Charles M. Hannum. All rights reserved.
|
1996-03-29 23:53:30 +03:00
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
* This product includes software developed by Julian Highfield.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This driver is for the WD7000 family of SCSI controllers:
|
|
|
|
* the WD7000-ASC, a bus-mastering DMA controller,
|
|
|
|
* the WD7000-FASST2, an -ASC with new firmware and scatter-gather,
|
|
|
|
* and the WD7000-ASE, which was custom manufactured for Apollo
|
|
|
|
* workstations and seems to include an -ASC as well as floppy
|
|
|
|
* and ESDI interfaces.
|
|
|
|
*
|
|
|
|
* Loosely based on Theo Deraadt's unfinished attempt.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 07:10:45 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wds.c,v 1.52 2002/10/02 03:10:50 thorpej Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
|
|
|
#undef WDSDIAG
|
|
|
|
#ifdef DDB
|
|
|
|
#define integrate
|
|
|
|
#else
|
|
|
|
#define integrate static inline
|
|
|
|
#endif
|
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#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>
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
#include <machine/bus.h>
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
1997-03-29 05:11:09 +03:00
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
#include <dev/isa/wdsreg.h>
|
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
#define WDS_ISA_IOSIZE 8
|
|
|
|
|
1996-04-11 03:01:13 +04:00
|
|
|
#ifndef DDB
|
|
|
|
#define Debugger() panic("should call debugger here (wds.c)")
|
|
|
|
#endif /* ! DDB */
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
#define WDS_MAXXFER ((WDS_NSEG - 1) << PGSHIFT)
|
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
#define WDS_MBX_SIZE 16
|
|
|
|
|
|
|
|
#define WDS_SCB_MAX 32
|
|
|
|
#define SCB_HASH_SIZE 32 /* hash table size for phystokv */
|
|
|
|
#define SCB_HASH_SHIFT 9
|
|
|
|
#define SCB_HASH(x) ((((long)(x))>>SCB_HASH_SHIFT) & (SCB_HASH_SIZE - 1))
|
|
|
|
|
|
|
|
#define wds_nextmbx(wmb, mbx, mbio) \
|
|
|
|
if ((wmb) == &(mbx)->mbio[WDS_MBX_SIZE - 1]) \
|
|
|
|
(wmb) = &(mbx)->mbio[0]; \
|
|
|
|
else \
|
|
|
|
(wmb)++;
|
|
|
|
|
|
|
|
struct wds_mbx {
|
|
|
|
struct wds_mbx_out mbo[WDS_MBX_SIZE];
|
|
|
|
struct wds_mbx_in mbi[WDS_MBX_SIZE];
|
|
|
|
struct wds_mbx_out *cmbo; /* Collection Mail Box out */
|
|
|
|
struct wds_mbx_out *tmbo; /* Target Mail Box out */
|
|
|
|
struct wds_mbx_in *tmbi; /* Target Mail Box in */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wds_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_space_handle_t sc_ioh;
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dma_tag_t sc_dmat;
|
|
|
|
bus_dmamap_t sc_dmamap_mbox; /* maps the mailbox */
|
1997-03-29 05:11:09 +03:00
|
|
|
void *sc_ih;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
struct wds_mbx *sc_mbx;
|
|
|
|
#define wmbx (sc->sc_mbx)
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_scb *sc_scbhash[SCB_HASH_SIZE];
|
|
|
|
TAILQ_HEAD(, wds_scb) sc_free_scb, sc_waiting_scb;
|
|
|
|
int sc_numscbs, sc_mbofull;
|
1997-03-29 05:11:09 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_adapter sc_adapter;
|
|
|
|
struct scsipi_channel sc_channel;
|
1997-11-04 08:58:22 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
int sc_revision;
|
1997-09-04 07:39:09 +04:00
|
|
|
int sc_maxsegs;
|
1997-03-29 05:11:09 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wds_probe_data {
|
|
|
|
#ifdef notyet
|
|
|
|
int sc_irq, sc_drq;
|
|
|
|
#endif
|
|
|
|
int sc_scsi_dev;
|
1996-03-29 23:53:30 +03:00
|
|
|
};
|
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
integrate void
|
|
|
|
wds_wait __P((bus_space_tag_t, bus_space_handle_t, int, int, int));
|
|
|
|
int wds_cmd __P((bus_space_tag_t, bus_space_handle_t, u_char *, int));
|
1996-03-29 23:53:30 +03:00
|
|
|
integrate void wds_finish_scbs __P((struct wds_softc *));
|
|
|
|
int wdsintr __P((void *));
|
|
|
|
integrate void wds_reset_scb __P((struct wds_softc *, struct wds_scb *));
|
|
|
|
void wds_free_scb __P((struct wds_softc *, struct wds_scb *));
|
1997-10-29 03:30:00 +03:00
|
|
|
integrate int wds_init_scb __P((struct wds_softc *, struct wds_scb *));
|
2001-04-25 21:53:04 +04:00
|
|
|
struct wds_scb *wds_get_scb __P((struct wds_softc *));
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_scb *wds_scb_phys_kv __P((struct wds_softc *, u_long));
|
|
|
|
void wds_queue_scb __P((struct wds_softc *, struct wds_scb *));
|
|
|
|
void wds_collect_mbo __P((struct wds_softc *));
|
|
|
|
void wds_start_scbs __P((struct wds_softc *));
|
|
|
|
void wds_done __P((struct wds_softc *, struct wds_scb *, u_char));
|
1997-03-29 05:11:09 +03:00
|
|
|
int wds_find __P((bus_space_tag_t, bus_space_handle_t, struct wds_probe_data *));
|
|
|
|
void wds_attach __P((struct wds_softc *, struct wds_probe_data *));
|
1997-09-04 07:39:09 +04:00
|
|
|
void wds_init __P((struct wds_softc *, int));
|
1996-03-29 23:53:30 +03:00
|
|
|
void wds_inquire_setup_information __P((struct wds_softc *));
|
|
|
|
void wdsminphys __P((struct buf *));
|
2001-04-25 21:53:04 +04:00
|
|
|
void wds_scsipi_request __P((struct scsipi_channel *,
|
|
|
|
scsipi_adapter_req_t, void *));
|
1997-08-27 15:22:52 +04:00
|
|
|
int wds_poll __P((struct wds_softc *, struct scsipi_xfer *, int));
|
1996-03-29 23:53:30 +03:00
|
|
|
int wds_ipoll __P((struct wds_softc *, struct wds_scb *, int));
|
|
|
|
void wds_timeout __P((void *));
|
1997-09-04 07:39:09 +04:00
|
|
|
int wds_create_scbs __P((struct wds_softc *, void *, size_t));
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-11-30 18:18:58 +03:00
|
|
|
int wdsprobe __P((struct device *, struct cfdata *, void *));
|
1996-03-29 23:53:30 +03:00
|
|
|
void wdsattach __P((struct device *, struct device *, void *));
|
|
|
|
|
2002-10-02 06:00:07 +04:00
|
|
|
CFATTACH_DECL(wds, sizeof(struct wds_softc),
|
2002-10-02 07:10:45 +04:00
|
|
|
wdsprobe, wdsattach, NULL, NULL);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
#define WDS_ABORT_TIMEOUT 2000 /* time to wait for abort (mSec) */
|
|
|
|
|
|
|
|
integrate void
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_wait(iot, ioh, port, mask, val)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
int port;
|
1997-03-29 05:11:09 +03:00
|
|
|
int mask, val;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
while ((bus_space_read_1(iot, ioh, port) & mask) != val)
|
1996-03-29 23:53:30 +03:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a command to the board's I/O ports.
|
|
|
|
*/
|
|
|
|
int
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_cmd(iot, ioh, ibuf, icnt)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
u_char *ibuf;
|
|
|
|
int icnt;
|
|
|
|
{
|
|
|
|
u_char c;
|
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
while (icnt--) {
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_CMD, *ibuf++);
|
|
|
|
wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY);
|
|
|
|
c = bus_space_read_1(iot, ioh, WDS_STAT);
|
1996-03-29 23:53:30 +03:00
|
|
|
if (c & WDSS_REJ)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for the presence of a WD7000 SCSI controller.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wdsprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-11-30 18:18:58 +03:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct wds_probe_data wpd;
|
|
|
|
int rv;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_nirq < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_ndrq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
|
|
|
|
1997-10-19 22:56:39 +04:00
|
|
|
/* Disallow wildcarded i/o address. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
|
1997-10-19 22:56:39 +04:00
|
|
|
return (0);
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, WDS_ISA_IOSIZE, 0, &ioh))
|
1997-03-29 05:11:09 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
rv = wds_find(iot, ioh, &wpd);
|
|
|
|
|
|
|
|
bus_space_unmap(iot, ioh, WDS_ISA_IOSIZE);
|
|
|
|
|
|
|
|
if (rv) {
|
|
|
|
#ifdef notyet
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
|
|
|
|
ia->ia_irq[0].ir_irq != wpd.sc_irq)
|
1997-03-29 05:11:09 +03:00
|
|
|
return (0);
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT &&
|
|
|
|
ia->ia_drq[0].ir_drq != wpd.sc_drq)
|
1997-03-29 05:11:09 +03:00
|
|
|
return (0);
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
ia->ia_irq[0].ir_irq = wpd.sc_irq;
|
|
|
|
|
|
|
|
ia->ia_ndrq = 1;
|
|
|
|
ia->ia_drq[0].ir_drq = wpd.sc_drq;
|
1997-03-29 05:11:09 +03:00
|
|
|
#else
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
|
1997-03-29 05:11:09 +03:00
|
|
|
return (0);
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_drq[0].ir_drq == ISACF_DRQ_DEFAULT)
|
1997-03-29 05:11:09 +03:00
|
|
|
return (0);
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
ia->ia_ndrq = 1;
|
1996-03-29 23:53:30 +03:00
|
|
|
#endif
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = WDS_ISA_IOSIZE;
|
|
|
|
|
|
|
|
ia->ia_niomem = 0;
|
1997-03-29 05:11:09 +03:00
|
|
|
}
|
|
|
|
return (rv);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all available units.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wdsattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct wds_softc *sc = (void *)self;
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct wds_probe_data wpd;
|
|
|
|
isa_chipset_tag_t ic = ia->ia_ic;
|
1998-06-25 23:18:05 +04:00
|
|
|
int error;
|
1997-03-29 05:11:09 +03:00
|
|
|
|
|
|
|
printf("\n");
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, WDS_ISA_IOSIZE, 0, &ioh)) {
|
1997-10-20 22:43:03 +04:00
|
|
|
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
1997-09-26 06:50:18 +04:00
|
|
|
sc->sc_dmat = ia->ia_dmat;
|
1997-10-20 22:43:03 +04:00
|
|
|
if (!wds_find(iot, ioh, &wpd)) {
|
|
|
|
printf("%s: wds_find failed\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
1996-11-03 19:20:31 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_HCR, WDSH_DRQEN);
|
|
|
|
#ifdef notyet
|
1998-06-25 23:18:05 +04:00
|
|
|
if (wpd.sc_drq != -1) {
|
|
|
|
if ((error = isa_dmacascade(ic, wpd.sc_drq)) != 0) {
|
|
|
|
printf("%s: unable to cascade DRQ, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
sc->sc_ih = isa_intr_establish(ic, wpd.sc_irq, IST_EDGE, IPL_BIO,
|
|
|
|
wdsintr, sc);
|
|
|
|
#else
|
2002-01-08 00:46:56 +03:00
|
|
|
if ((error = isa_dmacascade(ic, ia->ia_drq[0].ir_drq)) != 0) {
|
|
|
|
printf("%s: unable to cascade DRQ, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return;
|
1998-06-25 23:18:05 +04:00
|
|
|
}
|
1997-03-29 05:11:09 +03:00
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
sc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
|
|
|
|
IPL_BIO, wdsintr, sc);
|
1997-03-29 05:11:09 +03:00
|
|
|
#endif
|
|
|
|
if (sc->sc_ih == NULL) {
|
|
|
|
printf("%s: couldn't establish interrupt\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wds_attach(sc, &wpd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wds_attach(sc, wpd)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_probe_data *wpd;
|
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_adapter *adapt = &sc->sc_adapter;
|
|
|
|
struct scsipi_channel *chan = &sc->sc_channel;
|
1997-03-29 05:11:09 +03:00
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
TAILQ_INIT(&sc->sc_free_scb);
|
|
|
|
TAILQ_INIT(&sc->sc_waiting_scb);
|
|
|
|
|
1998-11-20 00:53:32 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Fill in the scsipi_adapter.
|
1998-11-20 00:53:32 +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->adapt_max_periph = 1;
|
|
|
|
adapt->adapt_request = wds_scsipi_request;
|
|
|
|
adapt->adapt_minphys = minphys;
|
1998-11-20 00:53:32 +03:00
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Fill in the scsipi_channel.
|
1996-03-29 23:53:30 +03:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
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 = wpd->sc_scsi_dev;
|
|
|
|
|
|
|
|
wds_init(sc, 0);
|
|
|
|
wds_inquire_setup_information(sc);
|
|
|
|
|
|
|
|
/* XXX add support for GROW */
|
|
|
|
adapt->adapt_openings = sc->sc_numscbs;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
config_found(&sc->sc_dev, &sc->sc_channel, scsiprint);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
|
|
|
wds_finish_scbs(sc)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
{
|
|
|
|
struct wds_mbx_in *wmbi;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wmbi = wmbx->tmbi;
|
|
|
|
|
|
|
|
if (wmbi->stat == WDS_MBI_FREE) {
|
|
|
|
for (i = 0; i < WDS_MBX_SIZE; i++) {
|
|
|
|
if (wmbi->stat != WDS_MBI_FREE) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: mbi not in round-robin order\n",
|
1996-03-29 23:53:30 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto AGAIN;
|
|
|
|
}
|
|
|
|
wds_nextmbx(wmbi, wmbx, mbi);
|
|
|
|
}
|
|
|
|
#ifdef WDSDIAGnot
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: mbi interrupt with no full mailboxes\n",
|
1996-03-29 23:53:30 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AGAIN:
|
|
|
|
do {
|
|
|
|
scb = wds_scb_phys_kv(sc, phystol(wmbi->scb_addr));
|
|
|
|
if (!scb) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: bad mbi scb pointer; skipping\n",
|
1996-03-29 23:53:30 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WDSDEBUG
|
|
|
|
if (wds_debug) {
|
1997-08-27 15:22:52 +04:00
|
|
|
u_char *cp = &scb->scsipi_cmd;
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("op=%x %x %x %x %x %x\n",
|
1996-03-29 23:53:30 +03:00
|
|
|
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("stat %x for mbi addr = 0x%08x, ",
|
1996-03-29 23:53:30 +03:00
|
|
|
wmbi->stat, wmbi);
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("scb addr = 0x%x\n", scb);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
#endif /* WDSDEBUG */
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&scb->xs->xs_callout);
|
1996-03-29 23:53:30 +03:00
|
|
|
wds_done(sc, scb, wmbi->stat);
|
|
|
|
|
|
|
|
next:
|
|
|
|
wmbi->stat = WDS_MBI_FREE;
|
|
|
|
wds_nextmbx(wmbi, wmbx, mbi);
|
|
|
|
} while (wmbi->stat != WDS_MBI_FREE);
|
|
|
|
|
|
|
|
wmbx->tmbi = wmbi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an interrupt.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wdsintr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct wds_softc *sc = arg;
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-04-29 23:48:26 +04:00
|
|
|
u_char c;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/* Was it really an interrupt from the board? */
|
1997-03-29 05:11:09 +03:00
|
|
|
if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ) == 0)
|
1996-03-29 23:53:30 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Get the interrupt status byte. */
|
1997-03-29 05:11:09 +03:00
|
|
|
c = bus_space_read_1(iot, ioh, WDS_IRQSTAT) & WDSI_MASK;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/* Acknowledge (which resets) the interrupt. */
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_IRQACK, 0x00);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case WDSI_MSVC:
|
|
|
|
wds_finish_scbs(sc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WDSI_MFREE:
|
|
|
|
wds_start_scbs(sc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: unrecognized interrupt type %02x",
|
1996-04-29 23:48:26 +04:00
|
|
|
sc->sc_dev.dv_xname, c);
|
1996-03-29 23:53:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
|
|
|
wds_reset_scb(sc, scb)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
{
|
|
|
|
|
|
|
|
scb->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the command structure, the outgoing mailbox and the data buffer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_free_scb(sc, scb)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
wds_reset_scb(sc, scb);
|
|
|
|
TAILQ_INSERT_HEAD(&sc->sc_free_scb, scb, chain);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1997-10-29 03:30:00 +03:00
|
|
|
integrate int
|
1997-09-04 07:39:09 +04:00
|
|
|
wds_init_scb(sc, scb)
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_softc *sc;
|
1997-09-04 07:39:09 +04:00
|
|
|
struct wds_scb *scb;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dma_tag_t dmat = sc->sc_dmat;
|
1997-10-29 03:30:00 +03:00
|
|
|
int hashnum, error;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
/*
|
|
|
|
* XXX Should we put a DIAGNOSTIC check for multiple
|
|
|
|
* XXX SCB inits here?
|
|
|
|
*/
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(scb, 0, sizeof(struct wds_scb));
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/*
|
1997-09-04 07:39:09 +04:00
|
|
|
* Create DMA maps for this SCB.
|
1996-03-29 23:53:30 +03:00
|
|
|
*/
|
1997-10-29 03:30:00 +03:00
|
|
|
error = bus_dmamap_create(dmat, sizeof(struct wds_scb), 1,
|
|
|
|
sizeof(struct wds_scb), 0, BUS_DMA_NOWAIT, &scb->dmamap_self);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: can't create scb dmamap_self\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-10-29 03:30:00 +03:00
|
|
|
error = bus_dmamap_create(dmat, WDS_MAXXFER, WDS_NSEG, WDS_MAXXFER,
|
|
|
|
0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &scb->dmamap_xfer);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: can't create scb dmamap_xfer\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
bus_dmamap_destroy(dmat, scb->dmamap_self);
|
|
|
|
return (error);
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
/*
|
|
|
|
* Load the permanent DMA maps.
|
|
|
|
*/
|
1997-10-29 03:30:00 +03:00
|
|
|
error = bus_dmamap_load(dmat, scb->dmamap_self, scb,
|
|
|
|
sizeof(struct wds_scb), NULL, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: can't load scb dmamap_self\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
bus_dmamap_destroy(dmat, scb->dmamap_self);
|
|
|
|
bus_dmamap_destroy(dmat, scb->dmamap_xfer);
|
|
|
|
return (error);
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* put in the phystokv hash table
|
|
|
|
* Never gets taken out.
|
|
|
|
*/
|
1997-09-04 07:39:09 +04:00
|
|
|
scb->hashkey = scb->dmamap_self->dm_segs[0].ds_addr;
|
1996-03-29 23:53:30 +03:00
|
|
|
hashnum = SCB_HASH(scb->hashkey);
|
|
|
|
scb->nexthash = sc->sc_scbhash[hashnum];
|
|
|
|
sc->sc_scbhash[hashnum] = scb;
|
|
|
|
wds_reset_scb(sc, scb);
|
1997-10-29 03:30:00 +03:00
|
|
|
return (0);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
/*
|
|
|
|
* Create a set of scbs and add them to the free list.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wds_create_scbs(sc, mem, size)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
void *mem;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
int rseg, error;
|
|
|
|
|
|
|
|
if (sc->sc_numscbs >= WDS_SCB_MAX)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if ((scb = mem) != NULL)
|
|
|
|
goto have_mem;
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
size = PAGE_SIZE;
|
|
|
|
error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &seg,
|
|
|
|
1, &rseg, BUS_DMA_NOWAIT);
|
1997-10-29 03:30:00 +03:00
|
|
|
if (error) {
|
|
|
|
printf("%s: can't allocate memory for scbs\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-09-04 07:39:09 +04:00
|
|
|
return (error);
|
1997-10-29 03:30:00 +03:00
|
|
|
}
|
1997-09-04 07:39:09 +04:00
|
|
|
|
|
|
|
error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, size,
|
1998-02-04 03:32:55 +03:00
|
|
|
(caddr_t *)&scb, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
|
1997-09-04 07:39:09 +04:00
|
|
|
if (error) {
|
1997-10-29 03:30:00 +03:00
|
|
|
printf("%s: can't map memory for scbs\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dmamem_free(sc->sc_dmat, &seg, rseg);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
have_mem:
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(scb, 0, size);
|
1997-10-29 03:30:00 +03:00
|
|
|
while (size > sizeof(struct wds_scb) && sc->sc_numscbs < WDS_SCB_MAX) {
|
|
|
|
error = wds_init_scb(sc, scb);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: can't initialize scb\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
1997-09-04 07:39:09 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sc->sc_free_scb, scb, chain);
|
|
|
|
(caddr_t)scb += ALIGN(sizeof(struct wds_scb));
|
|
|
|
size -= ALIGN(sizeof(struct wds_scb));
|
1997-10-29 03:30:00 +03:00
|
|
|
sc->sc_numscbs++;
|
1997-09-04 07:39:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
/*
|
|
|
|
* Get a free scb
|
|
|
|
*
|
|
|
|
* If there are none, see if we can allocate a new one. If so, put it in
|
|
|
|
* the hash table too otherwise either return an error or sleep.
|
|
|
|
*/
|
|
|
|
struct wds_scb *
|
2001-04-25 21:53:04 +04:00
|
|
|
wds_get_scb(sc)
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_softc *sc;
|
|
|
|
{
|
|
|
|
struct wds_scb *scb;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
2001-04-25 21:53:04 +04:00
|
|
|
scb = TAILQ_FIRST(&sc->sc_free_scb);
|
|
|
|
if (scb != NULL) {
|
|
|
|
TAILQ_REMOVE(&sc->sc_free_scb, scb, chain);
|
|
|
|
scb->flags |= SCB_ALLOC;
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (scb);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wds_scb *
|
|
|
|
wds_scb_phys_kv(sc, scb_phys)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
u_long scb_phys;
|
|
|
|
{
|
|
|
|
int hashnum = SCB_HASH(scb_phys);
|
|
|
|
struct wds_scb *scb = sc->sc_scbhash[hashnum];
|
|
|
|
|
|
|
|
while (scb) {
|
|
|
|
if (scb->hashkey == scb_phys)
|
|
|
|
break;
|
|
|
|
/* XXX Check to see if it matches the sense command block. */
|
|
|
|
if (scb->hashkey == (scb_phys - sizeof(struct wds_cmd)))
|
|
|
|
break;
|
|
|
|
scb = scb->nexthash;
|
|
|
|
}
|
1997-09-26 08:00:09 +04:00
|
|
|
return (scb);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a SCB to be sent to the controller, and send it if possible.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_queue_scb(sc, scb)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->sc_waiting_scb, scb, chain);
|
|
|
|
wds_start_scbs(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Garbage collect mailboxes that are no longer in use.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_collect_mbo(sc)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
{
|
|
|
|
struct wds_mbx_out *wmbo; /* Mail Box Out pointer */
|
1996-10-11 01:21:52 +04:00
|
|
|
#ifdef WDSDIAG
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_scb *scb;
|
1996-10-11 01:21:52 +04:00
|
|
|
#endif
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
wmbo = wmbx->cmbo;
|
|
|
|
|
|
|
|
while (sc->sc_mbofull > 0) {
|
|
|
|
if (wmbo->cmd != WDS_MBO_FREE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef WDSDIAG
|
|
|
|
scb = wds_scb_phys_kv(sc, phystol(wmbo->scb_addr));
|
|
|
|
scb->flags &= ~SCB_SENDING;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
--sc->sc_mbofull;
|
|
|
|
wds_nextmbx(wmbo, wmbx, mbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
wmbx->cmbo = wmbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send as many SCBs as we have empty mailboxes for.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_start_scbs(sc)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_mbx_out *wmbo; /* Mail Box Out pointer */
|
|
|
|
struct wds_scb *scb;
|
|
|
|
u_char c;
|
|
|
|
|
|
|
|
wmbo = wmbx->tmbo;
|
|
|
|
|
1996-04-29 23:48:26 +04:00
|
|
|
while ((scb = sc->sc_waiting_scb.tqh_first) != NULL) {
|
1996-03-29 23:53:30 +03:00
|
|
|
if (sc->sc_mbofull >= WDS_MBX_SIZE) {
|
|
|
|
wds_collect_mbo(sc);
|
|
|
|
if (sc->sc_mbofull >= WDS_MBX_SIZE) {
|
|
|
|
c = WDSC_IRQMFREE;
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_cmd(iot, ioh, &c, sizeof c);
|
1996-03-29 23:53:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&sc->sc_waiting_scb, scb, chain);
|
|
|
|
#ifdef WDSDIAG
|
|
|
|
scb->flags |= SCB_SENDING;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Link scb to mbo. */
|
2001-04-25 21:53:04 +04:00
|
|
|
ltophys(scb->dmamap_self->dm_segs[0].ds_addr +
|
|
|
|
offsetof(struct wds_scb, cmd), wmbo->scb_addr);
|
1996-03-29 23:53:30 +03:00
|
|
|
/* XXX What about aborts? */
|
|
|
|
wmbo->cmd = WDS_MBO_START;
|
|
|
|
|
|
|
|
/* Tell the card to poll immediately. */
|
|
|
|
c = WDSC_MSTART(wmbo - wmbx->mbo);
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_cmd(sc->sc_iot, sc->sc_ioh, &c, sizeof c);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
if ((scb->flags & SCB_POLLED) == 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&scb->xs->xs_callout,
|
2002-04-05 22:27:45 +04:00
|
|
|
mstohz(scb->timeout), wds_timeout, scb);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
++sc->sc_mbofull;
|
|
|
|
wds_nextmbx(wmbo, wmbx, mbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
wmbx->tmbo = wmbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the result of a SCSI command.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_done(sc, scb, stat)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
u_char stat;
|
|
|
|
{
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dma_tag_t dmat = sc->sc_dmat;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = scb->xs;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/* XXXXX */
|
|
|
|
|
|
|
|
/* Don't release the SCB if it was an internal command. */
|
|
|
|
if (xs == 0) {
|
|
|
|
scb->flags |= SCB_DONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/*
|
|
|
|
* If we were a data transfer, unload the map that described
|
|
|
|
* the data buffer.
|
|
|
|
*/
|
|
|
|
if (xs->datalen) {
|
|
|
|
bus_dmamap_sync(dmat, scb->dmamap_xfer, 0,
|
|
|
|
scb->dmamap_xfer->dm_mapsize,
|
|
|
|
(xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(dmat, scb->dmamap_xfer);
|
|
|
|
}
|
|
|
|
if (xs->error == XS_NOERROR) {
|
|
|
|
/* If all went well, or an error is acceptable. */
|
|
|
|
if (stat == WDS_MBI_OK) {
|
|
|
|
/* OK, set the result */
|
|
|
|
xs->resid = 0;
|
|
|
|
} else {
|
|
|
|
/* Check the mailbox status. */
|
|
|
|
switch (stat) {
|
|
|
|
case WDS_MBI_OKERR:
|
|
|
|
/*
|
|
|
|
* SCSI error recorded in scb,
|
|
|
|
* counts as WDS_MBI_OK
|
|
|
|
*/
|
|
|
|
switch (scb->cmd.venderr) {
|
|
|
|
case 0x00:
|
|
|
|
printf("%s: Is this "
|
|
|
|
"an error?\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
/* Experiment. */
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
case 0x01:
|
1997-09-04 07:39:09 +04:00
|
|
|
#if 0
|
2001-04-25 21:53:04 +04:00
|
|
|
printf("%s: OK, see SCSI "
|
|
|
|
"error field.\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-09-04 07:39:09 +04:00
|
|
|
#endif
|
2001-04-25 21:53:04 +04:00
|
|
|
if (scb->cmd.stat == SCSI_CHECK ||
|
|
|
|
scb->cmd.stat == SCSI_BUSY) {
|
|
|
|
xs->status = scb->cmd.stat;
|
|
|
|
xs->error = XS_BUSY;
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
break;
|
2001-04-25 21:53:04 +04:00
|
|
|
case 0x40:
|
|
|
|
#if 0
|
|
|
|
printf("%s: DMA underrun!\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
1996-03-29 23:53:30 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* Hits this if the target
|
|
|
|
* returns fewer that datalen
|
|
|
|
* bytes (eg my CD-ROM, which
|
|
|
|
* returns a short version
|
|
|
|
* string, or if DMA is
|
|
|
|
* turned off etc.
|
1996-03-29 23:53:30 +03:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->resid = 0;
|
1996-03-29 23:53:30 +03:00
|
|
|
break;
|
2001-04-25 21:53:04 +04:00
|
|
|
default:
|
|
|
|
printf("%s: VENDOR ERROR "
|
|
|
|
"%02x, scsi %02x\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
scb->cmd.venderr,
|
|
|
|
scb->cmd.stat);
|
|
|
|
/* Experiment. */
|
1996-03-29 23:53:30 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
break;
|
|
|
|
case WDS_MBI_ETIME:
|
|
|
|
/*
|
|
|
|
* The documentation isn't clear on
|
|
|
|
* what conditions might generate this,
|
|
|
|
* but selection timeouts are the only
|
|
|
|
* one I can think of.
|
|
|
|
*/
|
|
|
|
xs->error = XS_SELTIMEOUT;
|
|
|
|
break;
|
|
|
|
case WDS_MBI_ERESET:
|
|
|
|
case WDS_MBI_ETARCMD:
|
|
|
|
case WDS_MBI_ERESEL:
|
|
|
|
case WDS_MBI_ESEL:
|
|
|
|
case WDS_MBI_EABORT:
|
|
|
|
case WDS_MBI_ESRESET:
|
|
|
|
case WDS_MBI_EHRESET:
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
} /* XS_NOERROR */
|
|
|
|
|
|
|
|
wds_free_scb(sc, scb);
|
1997-08-27 15:22:52 +04:00
|
|
|
scsipi_done(xs);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_find(iot, ioh, sc)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct wds_probe_data *sc;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* XXXXX */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sending a command causes the CMDRDY bit to clear.
|
|
|
|
*/
|
1997-03-29 05:11:09 +03:00
|
|
|
for (i = 5; i; i--) {
|
|
|
|
if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_RDY) != 0)
|
|
|
|
break;
|
|
|
|
delay(100);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
1997-03-29 05:11:09 +03:00
|
|
|
if (!i)
|
1997-05-02 00:10:57 +04:00
|
|
|
return 0;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_CMD, WDSC_NOOP);
|
|
|
|
if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_RDY) != 0)
|
1997-05-02 00:10:57 +04:00
|
|
|
return 0;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_HCR, WDSH_SCSIRESET|WDSH_ASCRESET);
|
1996-03-29 23:53:30 +03:00
|
|
|
delay(10000);
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_HCR, 0x00);
|
1996-03-29 23:53:30 +03:00
|
|
|
delay(500000);
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_wait(iot, ioh, WDS_STAT, WDSS_RDY, WDSS_RDY);
|
|
|
|
if (bus_space_read_1(iot, ioh, WDS_IRQSTAT) != 1)
|
|
|
|
if (bus_space_read_1(iot, ioh, WDS_IRQSTAT) != 7)
|
1997-05-02 00:10:57 +04:00
|
|
|
return 0;
|
1997-03-29 05:11:09 +03:00
|
|
|
|
|
|
|
for (i = 2000; i; i--) {
|
|
|
|
if ((bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_RDY) != 0)
|
|
|
|
break;
|
|
|
|
delay(100);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
1997-03-29 05:11:09 +03:00
|
|
|
if (!i)
|
1997-05-02 00:10:57 +04:00
|
|
|
return 0;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
if (sc) {
|
|
|
|
#ifdef notyet
|
|
|
|
sc->sc_irq = ...;
|
|
|
|
sc->sc_drq = ...;
|
|
|
|
#endif
|
1996-03-29 23:53:30 +03:00
|
|
|
/* XXX Can we do this better? */
|
|
|
|
sc->sc_scsi_dev = 7;
|
|
|
|
}
|
|
|
|
|
1997-05-02 00:10:57 +04:00
|
|
|
return 1;
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the board and driver.
|
|
|
|
*/
|
|
|
|
void
|
1997-09-04 07:39:09 +04:00
|
|
|
wds_init(sc, isreset)
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_softc *sc;
|
1997-09-04 07:39:09 +04:00
|
|
|
int isreset;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dma_segment_t seg;
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_setup init;
|
|
|
|
u_char c;
|
1997-09-04 07:39:09 +04:00
|
|
|
int i, rseg;
|
|
|
|
|
|
|
|
if (isreset)
|
|
|
|
goto doinit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the mailbox.
|
|
|
|
*/
|
2000-11-14 21:21:00 +03:00
|
|
|
if (bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0, &seg, 1,
|
1997-09-04 07:39:09 +04:00
|
|
|
&rseg, BUS_DMA_NOWAIT) ||
|
2000-11-14 21:21:00 +03:00
|
|
|
bus_dmamem_map(sc->sc_dmat, &seg, rseg, PAGE_SIZE,
|
1998-02-04 03:32:55 +03:00
|
|
|
(caddr_t *)&wmbx, BUS_DMA_NOWAIT|BUS_DMA_COHERENT))
|
1997-09-04 07:39:09 +04:00
|
|
|
panic("wds_init: can't create or map mailbox");
|
|
|
|
|
1997-09-26 08:00:09 +04:00
|
|
|
/*
|
|
|
|
* Since DMA memory allocation is always rounded up to a
|
|
|
|
* page size, create some scbs from the leftovers.
|
|
|
|
*/
|
|
|
|
if (wds_create_scbs(sc, ((caddr_t)wmbx) +
|
|
|
|
ALIGN(sizeof(struct wds_mbx)),
|
2000-11-14 21:21:00 +03:00
|
|
|
PAGE_SIZE - ALIGN(sizeof(struct wds_mbx))))
|
1997-09-26 08:00:09 +04:00
|
|
|
panic("wds_init: can't create scbs");
|
1997-09-04 07:39:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and load the mailbox DMA map.
|
|
|
|
*/
|
|
|
|
if (bus_dmamap_create(sc->sc_dmat, sizeof(struct wds_mbx), 1,
|
|
|
|
sizeof(struct wds_mbx), 0, BUS_DMA_NOWAIT, &sc->sc_dmamap_mbox) ||
|
|
|
|
bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap_mbox, wmbx,
|
|
|
|
sizeof(struct wds_mbx), NULL, BUS_DMA_NOWAIT))
|
|
|
|
panic("wds_ionit: can't craete or load mailbox dma map");
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
doinit:
|
1996-03-29 23:53:30 +03:00
|
|
|
/*
|
|
|
|
* Set up initial mail box for round-robin operation.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < WDS_MBX_SIZE; i++) {
|
|
|
|
wmbx->mbo[i].cmd = WDS_MBO_FREE;
|
1996-05-05 04:40:01 +04:00
|
|
|
wmbx->mbi[i].stat = WDS_MBI_FREE;
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
wmbx->cmbo = wmbx->tmbo = &wmbx->mbo[0];
|
|
|
|
wmbx->tmbi = &wmbx->mbi[0];
|
|
|
|
sc->sc_mbofull = 0;
|
|
|
|
|
|
|
|
init.opcode = WDSC_INIT;
|
2001-04-25 21:53:04 +04:00
|
|
|
init.scsi_id = sc->sc_channel.chan_id;
|
1996-03-29 23:53:30 +03:00
|
|
|
init.buson_t = 48;
|
|
|
|
init.busoff_t = 24;
|
|
|
|
init.xx = 0;
|
1997-09-04 07:39:09 +04:00
|
|
|
ltophys(sc->sc_dmamap_mbox->dm_segs[0].ds_addr, init.mbaddr);
|
1996-03-29 23:53:30 +03:00
|
|
|
init.nomb = init.nimb = WDS_MBX_SIZE;
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_cmd(iot, ioh, (u_char *)&init, sizeof init);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_wait(iot, ioh, WDS_STAT, WDSS_INIT, WDSS_INIT);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
c = WDSC_DISUNSOL;
|
1997-03-29 05:11:09 +03:00
|
|
|
wds_cmd(iot, ioh, &c, sizeof c);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the board's firmware revision information.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wds_inquire_setup_information(sc)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_scb *scb;
|
|
|
|
u_char *j;
|
|
|
|
int s;
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
sc->sc_maxsegs = 1;
|
1997-09-26 08:00:09 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scb = wds_get_scb(sc);
|
1997-09-26 08:00:09 +04:00
|
|
|
if (scb == 0)
|
|
|
|
panic("wds_inquire_setup_information: no scb available");
|
1997-09-04 07:39:09 +04:00
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
scb->xs = NULL;
|
|
|
|
scb->timeout = 40;
|
|
|
|
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(&scb->cmd, 0, sizeof scb->cmd);
|
1996-03-29 23:53:30 +03:00
|
|
|
scb->cmd.write = 0x80;
|
|
|
|
scb->cmd.opcode = WDSX_GETFIRMREV;
|
|
|
|
|
|
|
|
/* Will poll card, await result. */
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_write_1(iot, ioh, WDS_HCR, WDSH_DRQEN);
|
1996-03-29 23:53:30 +03:00
|
|
|
scb->flags |= SCB_POLLED;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
wds_queue_scb(sc, scb);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (wds_ipoll(sc, scb, scb->timeout))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Print the version number. */
|
1997-09-26 08:00:09 +04:00
|
|
|
printf("%s: version %x.%02x ", sc->sc_dev.dv_xname,
|
|
|
|
scb->cmd.targ, scb->cmd.scb.opcode);
|
1996-03-29 23:53:30 +03:00
|
|
|
sc->sc_revision = (scb->cmd.targ << 8) | scb->cmd.scb.opcode;
|
|
|
|
/* Print out the version string. */
|
|
|
|
j = 2 + &(scb->cmd.targ);
|
|
|
|
while ((*j >= 32) && (*j < 128)) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%c", *j);
|
1996-03-29 23:53:30 +03:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
/*
|
|
|
|
* Determine if we can use scatter/gather.
|
|
|
|
*/
|
|
|
|
if (sc->sc_revision >= 0x800)
|
|
|
|
sc->sc_maxsegs = WDS_NSEG;
|
|
|
|
|
1996-03-29 23:53:30 +03:00
|
|
|
out:
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("\n");
|
1997-09-04 07:39:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free up the resources used by this scb.
|
|
|
|
*/
|
1997-09-26 08:00:09 +04:00
|
|
|
wds_free_scb(sc, scb);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wdsminphys(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
|
1997-09-04 07:39:09 +04:00
|
|
|
if (bp->b_bcount > WDS_MAXXFER)
|
|
|
|
bp->b_bcount = WDS_MAXXFER;
|
1996-03-29 23:53:30 +03:00
|
|
|
minphys(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a SCSI command.
|
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
void
|
|
|
|
wds_scsipi_request(chan, req, arg)
|
|
|
|
struct scsipi_channel *chan;
|
|
|
|
scsipi_adapter_req_t req;
|
|
|
|
void *arg;
|
1996-03-29 23:53:30 +03:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_xfer *xs;
|
|
|
|
struct scsipi_periph *periph;
|
|
|
|
struct wds_softc *sc = (void *)chan->chan_adapter->adapt_dev;
|
1997-09-04 07:39:09 +04:00
|
|
|
bus_dma_tag_t dmat = sc->sc_dmat;
|
1996-03-29 23:53:30 +03:00
|
|
|
struct wds_scb *scb;
|
|
|
|
struct wds_scat_gath *sg;
|
1997-09-04 07:39:09 +04:00
|
|
|
int error, seg, flags, s;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
switch (req) {
|
|
|
|
case ADAPTER_REQ_RUN_XFER:
|
|
|
|
xs = arg;
|
|
|
|
periph = xs->xs_periph;
|
1997-11-04 08:58:22 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->xs_control & XS_CTL_RESET) {
|
|
|
|
/* XXX Fix me! */
|
|
|
|
printf("%s: reset!\n", sc->sc_dev.dv_xname);
|
|
|
|
wds_init(sc, 1);
|
|
|
|
scsipi_done(xs);
|
|
|
|
return;
|
|
|
|
}
|
1997-11-04 08:58:22 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->xs_control & XS_CTL_DATA_UIO) {
|
|
|
|
/* XXX Fix me! */
|
|
|
|
/*
|
|
|
|
* Let's not worry about UIO. There isn't any code
|
|
|
|
* for the non-SG boards anyway!
|
|
|
|
*/
|
|
|
|
printf("%s: UIO is untested and disabled!\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1997-11-04 08:58:22 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_done(xs);
|
|
|
|
return;
|
1997-11-04 08:58:22 +03:00
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
flags = xs->xs_control;
|
1997-11-04 08:58:22 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/* Get an SCB to use. */
|
|
|
|
scb = wds_get_scb(sc);
|
|
|
|
#ifdef DIAGNOSTIC
|
1997-11-04 08:58:22 +03:00
|
|
|
/*
|
2001-04-25 21:53:04 +04:00
|
|
|
* This should never happen as we track the resources
|
|
|
|
* in the mid-layer.
|
1997-11-04 08:58:22 +03:00
|
|
|
*/
|
2001-04-25 21:53:04 +04:00
|
|
|
if (scb == NULL) {
|
|
|
|
scsipi_printaddr(periph);
|
|
|
|
printf("unable to allocate scb\n");
|
|
|
|
panic("wds_scsipi_request");
|
1997-11-04 08:58:22 +03:00
|
|
|
}
|
2001-04-25 21:53:04 +04:00
|
|
|
#endif
|
1997-11-04 08:58:22 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scb->xs = xs;
|
|
|
|
scb->timeout = xs->timeout;
|
1997-11-04 08:58:22 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/* Zero out the command structure. */
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(&scb->cmd, 0, sizeof scb->cmd);
|
2001-07-19 00:52:47 +04:00
|
|
|
memcpy(&scb->cmd.scb, xs->cmd,
|
2001-04-25 21:53:04 +04:00
|
|
|
xs->cmdlen < 12 ? xs->cmdlen : 12);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/* Set up some of the command fields. */
|
|
|
|
scb->cmd.targ = (periph->periph_target << 5) |
|
|
|
|
periph->periph_lun;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/*
|
|
|
|
* NOTE: cmd.write may be OK as 0x40 (disable direction
|
|
|
|
* checking) on boards other than the WD-7000V-ASE. Need
|
|
|
|
* this for the ASE:
|
|
|
|
*/
|
|
|
|
scb->cmd.write = (xs->xs_control & XS_CTL_DATA_IN) ?
|
|
|
|
0x80 : 0x00;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (xs->datalen) {
|
|
|
|
sg = scb->scat_gath;
|
|
|
|
seg = 0;
|
1996-03-29 23:53:30 +03:00
|
|
|
#ifdef TFS
|
2001-04-25 21:53:04 +04:00
|
|
|
if (flags & XS_CTL_DATA_UIO) {
|
|
|
|
error = bus_dmamap_load_uio(dmat,
|
|
|
|
scb->dmamap_xfer, (struct uio *)xs->data,
|
2001-07-19 20:36:14 +04:00
|
|
|
BUS_DMA_NOWAIT |
|
|
|
|
((flags & XS_CTL_DATA_IN) ? BUS_DMA_READ :
|
|
|
|
BUS_DMA_WRITE));
|
2001-04-25 21:53:04 +04:00
|
|
|
} else
|
1996-03-29 23:53:30 +03:00
|
|
|
#endif /* TFS */
|
2001-04-25 21:53:04 +04:00
|
|
|
{
|
|
|
|
error = bus_dmamap_load(dmat,
|
|
|
|
scb->dmamap_xfer, xs->data, xs->datalen,
|
2001-07-19 20:36:14 +04:00
|
|
|
NULL, BUS_DMA_NOWAIT |
|
|
|
|
((flags & XS_CTL_DATA_IN) ? BUS_DMA_READ :
|
|
|
|
BUS_DMA_WRITE));
|
2001-04-25 21:53:04 +04:00
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
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;
|
|
|
|
printf("%s: error %d loading DMA map\n",
|
1997-09-04 07:39:09 +04:00
|
|
|
sc->sc_dev.dv_xname, error);
|
2001-04-25 21:53:04 +04:00
|
|
|
out_bad:
|
|
|
|
wds_free_scb(sc, scb);
|
|
|
|
scsipi_done(xs);
|
|
|
|
return;
|
1997-09-04 07:39:09 +04:00
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
bus_dmamap_sync(dmat, scb->dmamap_xfer, 0,
|
|
|
|
scb->dmamap_xfer->dm_mapsize,
|
|
|
|
(flags & XS_CTL_DATA_IN) ? BUS_DMASYNC_PREREAD :
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
if (sc->sc_maxsegs > 1) {
|
|
|
|
/*
|
|
|
|
* Load the hardware scatter/gather map with the
|
|
|
|
* contents of the DMA map.
|
|
|
|
*/
|
|
|
|
for (seg = 0;
|
|
|
|
seg < scb->dmamap_xfer->dm_nsegs; seg++) {
|
1997-09-04 07:39:09 +04:00
|
|
|
ltophys(scb->dmamap_xfer->dm_segs[seg].ds_addr,
|
2001-04-25 21:53:04 +04:00
|
|
|
scb->scat_gath[seg].seg_addr);
|
1997-09-04 07:39:09 +04:00
|
|
|
ltophys(scb->dmamap_xfer->dm_segs[seg].ds_len,
|
2001-04-25 21:53:04 +04:00
|
|
|
scb->scat_gath[seg].seg_len);
|
|
|
|
}
|
1997-09-04 07:39:09 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/*
|
|
|
|
* Set up for scatter/gather transfer.
|
|
|
|
*/
|
|
|
|
scb->cmd.opcode = WDSX_SCSISG;
|
|
|
|
ltophys(scb->dmamap_self->dm_segs[0].ds_addr +
|
|
|
|
offsetof(struct wds_scb, scat_gath),
|
|
|
|
scb->cmd.data);
|
|
|
|
ltophys(scb->dmamap_self->dm_nsegs *
|
|
|
|
sizeof(struct wds_scat_gath), scb->cmd.len);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This board is an ASC or an ASE, and the
|
|
|
|
* transfer has been mapped contig for us.
|
|
|
|
*/
|
|
|
|
scb->cmd.opcode = WDSX_SCSICMD;
|
|
|
|
ltophys(scb->dmamap_xfer->dm_segs[0].ds_addr,
|
|
|
|
scb->cmd.data);
|
|
|
|
ltophys(scb->dmamap_xfer->dm_segs[0].ds_len,
|
|
|
|
scb->cmd.len);
|
|
|
|
}
|
1997-09-04 07:39:09 +04:00
|
|
|
} else {
|
|
|
|
scb->cmd.opcode = WDSX_SCSICMD;
|
2001-04-25 21:53:04 +04:00
|
|
|
ltophys(0, scb->cmd.data);
|
|
|
|
ltophys(0, scb->cmd.len);
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scb->cmd.stat = 0x00;
|
|
|
|
scb->cmd.venderr = 0x00;
|
|
|
|
ltophys(0, scb->cmd.link);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/* XXX Do we really want to do this? */
|
|
|
|
if (flags & XS_CTL_POLL) {
|
|
|
|
/* Will poll card, await result. */
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
WDS_HCR, WDSH_DRQEN);
|
|
|
|
scb->flags |= SCB_POLLED;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Will send command, let interrupt routine
|
|
|
|
* handle result.
|
|
|
|
*/
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, WDS_HCR,
|
|
|
|
WDSH_IRQEN | WDSH_DRQEN);
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
s = splbio();
|
|
|
|
wds_queue_scb(sc, scb);
|
|
|
|
splx(s);
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if ((flags & XS_CTL_POLL) == 0)
|
|
|
|
return;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
if (wds_poll(sc, xs, scb->timeout)) {
|
1996-03-29 23:53:30 +03:00
|
|
|
wds_timeout(scb);
|
2001-04-25 21:53:04 +04:00
|
|
|
if (wds_poll(sc, xs, scb->timeout))
|
|
|
|
wds_timeout(scb);
|
|
|
|
}
|
|
|
|
return;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
case ADAPTER_REQ_GROW_RESOURCES:
|
|
|
|
/* XXX Not supported. */
|
|
|
|
return;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
case ADAPTER_REQ_SET_XFER_MODE:
|
|
|
|
/* XXX How do we do this? */
|
|
|
|
return;
|
|
|
|
}
|
1996-03-29 23:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll a particular unit, looking for a particular scb
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wds_poll(sc, xs, count)
|
|
|
|
struct wds_softc *sc;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs;
|
1996-03-29 23:53:30 +03:00
|
|
|
int count;
|
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/* timeouts are in msec, so we loop in 1000 usec cycles */
|
|
|
|
while (count) {
|
|
|
|
/*
|
|
|
|
* If we had interrupts enabled, would we
|
|
|
|
* have got an interrupt?
|
|
|
|
*/
|
1997-03-29 05:11:09 +03:00
|
|
|
if (bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ)
|
1996-03-29 23:53:30 +03:00
|
|
|
wdsintr(sc);
|
1999-10-01 03:04:39 +04:00
|
|
|
if (xs->xs_status & XS_STS_DONE)
|
1996-03-29 23:53:30 +03:00
|
|
|
return 0;
|
|
|
|
delay(1000); /* only happens in boot so ok */
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll a particular unit, looking for a particular scb
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wds_ipoll(sc, scb, count)
|
|
|
|
struct wds_softc *sc;
|
|
|
|
struct wds_scb *scb;
|
|
|
|
int count;
|
|
|
|
{
|
1997-03-29 05:11:09 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
/* timeouts are in msec, so we loop in 1000 usec cycles */
|
|
|
|
while (count) {
|
|
|
|
/*
|
|
|
|
* If we had interrupts enabled, would we
|
|
|
|
* have got an interrupt?
|
|
|
|
*/
|
1997-03-29 05:11:09 +03:00
|
|
|
if (bus_space_read_1(iot, ioh, WDS_STAT) & WDSS_IRQ)
|
1996-03-29 23:53:30 +03:00
|
|
|
wdsintr(sc);
|
|
|
|
if (scb->flags & SCB_DONE)
|
|
|
|
return 0;
|
|
|
|
delay(1000); /* only happens in boot so ok */
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wds_timeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct wds_scb *scb = arg;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = scb->xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = xs->xs_periph;
|
|
|
|
struct wds_softc *sc =
|
|
|
|
(void *)periph->periph_channel->chan_adapter->adapt_dev;
|
1996-03-29 23:53:30 +03:00
|
|
|
int s;
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
scsipi_printaddr(periph);
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("timed out");
|
1996-03-29 23:53:30 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
#ifdef WDSDIAG
|
|
|
|
/*
|
|
|
|
* If The scb's mbx is not free, then the board has gone south?
|
|
|
|
*/
|
|
|
|
wds_collect_mbo(sc);
|
|
|
|
if (scb->flags & SCB_SENDING) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: not taking commands!\n", sc->sc_dev.dv_xname);
|
1996-03-29 23:53:30 +03:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it has been through before, then
|
|
|
|
* a previous abort has failed, don't
|
|
|
|
* try abort again
|
|
|
|
*/
|
|
|
|
if (scb->flags & SCB_ABORT) {
|
|
|
|
/* abort timed out */
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" AGAIN\n");
|
1996-03-29 23:53:30 +03:00
|
|
|
/* XXX Must reset! */
|
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("\n");
|
1996-03-29 23:53:30 +03:00
|
|
|
scb->xs->error = XS_TIMEOUT;
|
|
|
|
scb->timeout = WDS_ABORT_TIMEOUT;
|
|
|
|
scb->flags |= SCB_ABORT;
|
|
|
|
wds_queue_scb(sc, scb);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|