summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authormycroft <mycroft@NetBSD.org>1996-05-16 03:44:13 +0000
committermycroft <mycroft@NetBSD.org>1996-05-16 03:44:13 +0000
commit19b0b9502feed509656dc9fc0468eca32b5c240f (patch)
treec1674b66aa8f12b4f4b2f0a2938969a55445e7c5 /sys/dev
parent81ba0732e0dbe34001ff1df285387e18bf3e642b (diff)
New version, with changes from Justin Gibbs and Noriyuki Soda.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/eisa/ahc_eisa.c537
-rw-r--r--sys/dev/eisa/files.eisa7
-rw-r--r--sys/dev/isa/aha284x.c189
-rw-r--r--sys/dev/isa/files.isa9
-rw-r--r--sys/dev/microcode/aic7xxx/Makefile.inc2
-rw-r--r--sys/dev/microcode/aic7xxx/aic7xxx.seq2017
-rw-r--r--sys/dev/microcode/aic7xxx/aic7xxx_asm.c186
-rw-r--r--sys/dev/pci/ahc_pci.c715
-rw-r--r--sys/dev/pci/aic7870.c115
-rw-r--r--sys/dev/pci/files.pci11
10 files changed, 2288 insertions, 1500 deletions
diff --git a/sys/dev/eisa/ahc_eisa.c b/sys/dev/eisa/ahc_eisa.c
new file mode 100644
index 00000000000..e0fb34856f6
--- /dev/null
+++ b/sys/dev/eisa/ahc_eisa.c
@@ -0,0 +1,537 @@
+/*
+ * Product specific probe and attach routines for:
+ * 27/284X and aic7770 motherboard SCSI controllers
+ *
+ * Copyright (c) 1994, 1995, 1996 Justin T. Gibbs.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice immediately at the beginning of the file, without modification,
+ * 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. 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 AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: ahc_eisa.c,v 1.1 1996/05/16 03:48:14 mycroft Exp $
+ */
+
+#if defined(__FreeBSD__)
+#include <eisa.h>
+#endif
+#if NEISA > 0 || defined(__NetBSD__)
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#if defined(__FreeBSD__)
+#include <sys/devconf.h>
+#endif
+#include <sys/kernel.h>
+
+#if defined(__NetBSD__)
+#include <sys/device.h>
+#include <machine/bus.h>
+#include <machine/intr.h>
+#endif /* defined(__NetBSD__) */
+
+#include <scsi/scsi_all.h>
+#include <scsi/scsiconf.h>
+
+#if defined(__FreeBSD__)
+
+#include <machine/clock.h>
+
+#include <i386/eisa/eisaconf.h>
+#include <i386/scsi/aic7xxx.h>
+#include <dev/aic7xxx/aic7xxx_reg.h>
+
+#define EISA_DEVICE_ID_ADAPTEC_AIC7770 0x04907770
+#define EISA_DEVICE_ID_ADAPTEC_274x 0x04907771
+#define EISA_DEVICE_ID_ADAPTEC_284xB 0x04907756 /* BIOS enabled */
+#define EISA_DEVICE_ID_ADAPTEC_284x 0x04907757 /* BIOS disabled*/
+
+#elif defined(__NetBSD__)
+
+#include <dev/eisa/eisareg.h>
+#include <dev/eisa/eisavar.h>
+#include <dev/eisa/eisadevs.h>
+
+#include <dev/ic/aic7xxxreg.h>
+#include <dev/ic/aic7xxxvar.h>
+
+#endif /* defined(__NetBSD__) */
+
+#define AHC_EISA_SLOT_OFFSET 0xc00
+#define AHC_EISA_IOSIZE 0x100
+#define INTDEF 0x5cul /* Interrupt Definition Register */
+
+#if defined(__FreeBSD__)
+
+static int aic7770probe __P((void));
+static int aic7770_attach __P((struct eisa_device *e_dev));
+
+static struct eisa_driver ahc_eisa_driver = {
+ "ahc",
+ aic7770probe,
+ aic7770_attach,
+ /*shutdown*/NULL,
+ &ahc_unit
+ };
+
+DATA_SET (eisadriver_set, ahc_eisa_driver);
+
+static struct kern_devconf kdc_aic7770 = {
+ 0, 0, 0, /* filled in by dev_attach */
+ "ahc", 0, { MDDT_EISA, 0, "bio" },
+ eisa_generic_externalize, 0, 0, EISA_EXTERNALLEN,
+ &kdc_eisa0, /* parent */
+ 0, /* parentdata */
+ DC_UNCONFIGURED, /* always start out here */
+ NULL,
+ DC_CLS_MISC /* host adapters aren't special */
+};
+
+
+static char *aic7770_match __P((eisa_id_t type));
+
+static char*
+aic7770_match(type)
+ eisa_id_t type;
+{
+ switch(type) {
+ case EISA_DEVICE_ID_ADAPTEC_AIC7770:
+ return ("Adaptec aic7770 SCSI host adapter");
+ break;
+ case EISA_DEVICE_ID_ADAPTEC_274x:
+ return ("Adaptec 274X SCSI host adapter");
+ break;
+ case EISA_DEVICE_ID_ADAPTEC_284xB:
+ case EISA_DEVICE_ID_ADAPTEC_284x:
+ return ("Adaptec 284X SCSI host adapter");
+ break;
+ default:
+ break;
+ }
+ return (NULL);
+}
+
+static int
+aic7770probe(void)
+{
+ u_long iobase;
+ char intdef;
+ u_long irq;
+ struct eisa_device *e_dev = NULL;
+ int count;
+
+ count = 0;
+ while ((e_dev = eisa_match_dev(e_dev, aic7770_match))) {
+ iobase = (e_dev->ioconf.slot * EISA_SLOT_SIZE)
+ + AHC_EISA_SLOT_OFFSET;
+ ahc_reset(iobase);
+
+ eisa_add_iospace(e_dev, iobase, AHC_EISA_IOSIZE, RESVADDR_NONE);
+ intdef = inb(INTDEF + iobase);
+ switch (intdef & 0xf) {
+ case 9:
+ irq = 9;
+ break;
+ case 10:
+ irq = 10;
+ break;
+ case 11:
+ irq = 11;
+ break;
+ case 12:
+ irq = 12;
+ break;
+ case 14:
+ irq = 14;
+ break;
+ case 15:
+ irq = 15;
+ break;
+ default:
+ printf("aic7770 at slot %d: illegal "
+ "irq setting %d\n", e_dev->ioconf.slot,
+ intdef);
+ continue;
+ }
+ eisa_add_intr(e_dev, irq);
+ eisa_registerdev(e_dev, &ahc_eisa_driver, &kdc_aic7770);
+ if(e_dev->id == EISA_DEVICE_ID_ADAPTEC_284xB
+ || e_dev->id == EISA_DEVICE_ID_ADAPTEC_284x) {
+ /* Our real parent is the isa bus. Say so. */
+ e_dev->kdc->kdc_parent = &kdc_isa0;
+ }
+ count++;
+ }
+ return count;
+}
+
+#elif defined(__NetBSD__)
+
+#define bootverbose 1
+
+int ahc_eisa_match __P((struct device *, void *, void *));
+void ahc_eisa_attach __P((struct device *, struct device *, void *));
+
+
+struct cfattach ahc_eisa_ca = {
+ sizeof(struct ahc_data), ahc_eisa_match, ahc_eisa_attach
+};
+
+/*
+ * Return irq setting of the board, otherwise -1.
+ */
+int
+ahc_eisa_irq(bc, ioh)
+ bus_chipset_tag_t bc;
+ bus_io_handle_t ioh;
+{
+ int irq;
+ u_char intdef;
+
+ ahc_reset("ahc_eisa", bc, ioh);
+ intdef = bus_io_read_1(bc, ioh, INTDEF);
+ switch (irq = (intdef & 0xf)) {
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 14:
+ case 15:
+ break;
+ default:
+ printf("ahc_eisa_irq: illegal irq setting %d\n", intdef);
+ return -1;
+ }
+
+ /* Note that we are going and return (to probe) */
+ return irq;
+}
+
+/*
+ * Check the slots looking for a board we recognise
+ * If we find one, note it's address (slot) and call
+ * the actual probe routine to check it out.
+ */
+int
+ahc_eisa_match(parent, match, aux)
+ struct device *parent;
+ void *match, *aux;
+{
+ struct eisa_attach_args *ea = aux;
+ bus_io_handle_t ioh;
+ int irq;
+
+ /* must match one of our known ID strings */
+ if (strcmp(ea->ea_idstring, "ADP7770") &&
+ strcmp(ea->ea_idstring, "ADP7771") &&
+ strcmp(ea->ea_idstring, "ADP7756") && /* XXX - not EISA, but VL */
+ strcmp(ea->ea_idstring, "ADP7757")) /* XXX - not EISA, but VL */
+ return (0);
+
+#ifdef notyet
+ if (bus_io_map(ea->ea_bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE,
+ &ioh))
+ return (0);
+ /* This won't compile as-is, anyway. */
+ bus_io_write_1(ea->ea_bc, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
+ delay(10);
+ bus_io_write_1(ea->ea_bc, ioh, EISA_CONTROL, EISA_ENABLE);
+ /* Wait for reset? */
+ delay(1000);
+ bus_io_unmap(ea->ea_bc, ioh, EISA_SLOT_SIZE);
+#endif
+
+ if (bus_io_map(ea->ea_bc,
+ EISA_SLOT_ADDR(ea->ea_slot) + AHC_EISA_SLOT_OFFSET,
+ AHC_EISA_IOSIZE, &ioh))
+ return (0);
+ irq = ahc_eisa_irq(ea->ea_bc, ioh);
+ bus_io_unmap(ea->ea_bc, ioh, EISA_SLOT_SIZE);
+ return (irq >= 0);
+}
+
+#endif /* defined(__NetBSD__) */
+
+#if defined(__FreeBSD__)
+static int
+aic7770_attach(e_dev)
+ struct eisa_device *e_dev;
+#elif defined(__NetBSD__)
+void
+ahc_eisa_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+#endif
+{
+ ahc_type type;
+
+#if defined(__FreeBSD__)
+ struct ahc_data *ahc;
+ resvaddr_t *iospace;
+ int unit = e_dev->unit;
+ int irq = ffs(e_dev->ioconf.irq) - 1;
+
+ iospace = e_dev->ioconf.ioaddrs.lh_first;
+
+ if(!iospace)
+ return -1;
+
+ switch(e_dev->id) {
+ case EISA_DEVICE_ID_ADAPTEC_AIC7770:
+ type = AHC_AIC7770;
+ break;
+ case EISA_DEVICE_ID_ADAPTEC_274x:
+ type = AHC_274;
+ break;
+ case EISA_DEVICE_ID_ADAPTEC_284xB:
+ case EISA_DEVICE_ID_ADAPTEC_284x:
+ type = AHC_284;
+ break;
+ default:
+ printf("aic7770_attach: Unknown device type!\n");
+ return -1;
+ break;
+ }
+
+ if(!(ahc = ahc_alloc(unit, iospace->addr, type, AHC_FNONE)))
+ return -1;
+
+ eisa_reg_start(e_dev);
+ if(eisa_reg_iospace(e_dev, iospace)) {
+ ahc_free(ahc);
+ return -1;
+ }
+
+ /*
+ * The IRQMS bit enables level sensitive interrupts. Only allow
+ * IRQ sharing if it's set.
+ */
+ if(eisa_reg_intr(e_dev, irq, ahc_intr, (void *)ahc, &bio_imask,
+ /*shared ==*/ahc->pause & IRQMS)) {
+ ahc_free(ahc);
+ return -1;
+ }
+ eisa_reg_end(e_dev);
+
+#elif defined(__NetBSD__)
+
+ struct ahc_data *ahc = (void *)self;
+ const char *model;
+ struct eisa_attach_args *ea = aux;
+ bus_io_handle_t ioh;
+ eisa_intr_handle_t ih;
+ const char *intrstr;
+ int irq;
+
+ if (bus_io_map(ea->ea_bc,
+ EISA_SLOT_ADDR(ea->ea_slot) + AHC_EISA_SLOT_OFFSET,
+ AHC_EISA_IOSIZE, &ioh))
+ panic("ahc_eisa_attach: could not map I/O addresses");
+ if ((irq = ahc_eisa_irq(ea->ea_bc, ioh)) < 0)
+ panic("ahc_eisa_attach: ahc_eisa_irq failed!");
+
+ if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
+ model = EISA_PRODUCT_ADP7770;
+ type = AHC_AIC7770;
+ } else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
+ model = EISA_PRODUCT_ADP7771;
+ type = AHC_274;
+ } else if (strcmp(ea->ea_idstring, "ADP7756") == 0) {
+ model = EISA_PRODUCT_ADP7756;
+ type = AHC_284;
+ } else if (strcmp(ea->ea_idstring, "ADP7757") == 0) {
+ model = EISA_PRODUCT_ADP7757;
+ type = AHC_284;
+ } else {
+ panic("ahc_eisa_attach: Unknown device type %s\n",
+ ea->ea_idstring);
+ }
+ printf(": %s\n", model);
+
+ ahc_construct(ahc, ea->ea_bc, ioh, type, AHC_FNONE);
+ if (eisa_intr_map(ea->ea_ec, irq, &ih)) {
+ printf("%s: couldn't map interrupt (%d)\n",
+ ahc->sc_dev.dv_xname, irq);
+ return;
+ }
+#endif /* defined(__NetBSD__) */
+
+ /*
+ * Tell the user what type of interrupts we're using.
+ * usefull for debugging irq problems
+ */
+ if(bootverbose) {
+ printf(
+ "%s: Using %s Interrupts\n",
+ ahc_name(ahc),
+ ahc->pause & IRQMS ?
+ "Level Sensitive" : "Edge Triggered");
+ }
+
+ /*
+ * Now that we know we own the resources we need, do the
+ * card initialization.
+ *
+ * First, the aic7770 card specific setup.
+ */
+ switch( ahc->type ) {
+ case AHC_AIC7770:
+ case AHC_274:
+ {
+ u_char biosctrl = AHC_INB(ahc, HA_274_BIOSCTRL);
+
+ /* Get the primary channel information */
+ ahc->flags |= (biosctrl & CHANNEL_B_PRIMARY);
+
+ if((biosctrl & BIOSMODE) == BIOSDISABLED)
+ ahc->flags |= AHC_USEDEFAULTS;
+ break;
+ }
+ case AHC_284:
+ {
+ /* XXX
+ * All values are automagically intialized at
+ * POST for these cards, so we can always rely
+ * on the Scratch Ram values. However, we should
+ * read the SEEPROM here (Dan has the code to do
+ * it) so we can say what kind of translation the
+ * BIOS is using. Printing out the geometry could
+ * save a lot of users the grief of failed installs.
+ */
+ break;
+ }
+ default:
+ break;
+ }
+
+ /*
+ * See if we have a Rev E or higher aic7770. Anything below a
+ * Rev E will have a R/O autoflush disable configuration bit.
+ * It's still not clear exactly what is differenent about the Rev E.
+ * We think it allows 8 bit entries in the QOUTFIFO to support
+ * "paging" SCBs so you can have more than 4 commands active at
+ * once.
+ */
+ {
+ char *id_string;
+ u_char sblkctl;
+ u_char sblkctl_orig;
+
+ sblkctl_orig = AHC_INB(ahc, SBLKCTL);
+ sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
+ AHC_OUTB(ahc, SBLKCTL, sblkctl);
+ sblkctl = AHC_INB(ahc, SBLKCTL);
+ if(sblkctl != sblkctl_orig)
+ {
+ id_string = "aic7770 >= Rev E, ";
+ /*
+ * Ensure autoflush is enabled
+ */
+ sblkctl &= ~AUTOFLUSHDIS;
+ AHC_OUTB(ahc, SBLKCTL, sblkctl);
+
+ /* Allow paging on this adapter */
+ ahc->flags |= AHC_PAGESCBS;
+ }
+ else
+ id_string = "aic7770 <= Rev C, ";
+
+ printf("%s: %s", ahc_name(ahc), id_string);
+ }
+
+ /* Setup the FIFO threshold and the bus off time */
+ {
+ u_char hostconf = AHC_INB(ahc, HOSTCONF);
+ AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
+ AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
+ }
+
+ /*
+ * Generic aic7xxx initialization.
+ */
+ if(ahc_init(ahc)){
+#if defined(__FreeBSD__)
+ ahc_free(ahc);
+ /*
+ * The board's IRQ line is not yet enabled so it's safe
+ * to release the irq.
+ */
+ eisa_release_intr(e_dev, irq, ahc_intr);
+ return -1;
+#elif defined(__NetBSD__)
+ ahc_free(ahc);
+ return;
+#endif
+ }
+
+ /*
+ * Enable the board's BUS drivers
+ */
+ AHC_OUTB(ahc, BCTL, ENABLE);
+
+#if defined(__FreeBSD__)
+ /*
+ * Enable our interrupt handler.
+ */
+ if(eisa_enable_intr(e_dev, irq)) {
+ ahc_free(ahc);
+ eisa_release_intr(e_dev, irq, ahc_intr);
+ return -1;
+ }
+
+ e_dev->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
+#elif defined(__NetBSD__)
+ intrstr = eisa_intr_string(ea->ea_ec, ih);
+ /*
+ * The IRQMS bit enables level sensitive interrupts only allow
+ * IRQ sharing if its set.
+ */
+ ahc->sc_ih = eisa_intr_establish(ea->ea_ec, ih,
+ ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc
+#ifdef __OpenBSD__
+ , ahc->sc_dev.dv_xname
+#endif
+ );
+ if (ahc->sc_ih == NULL) {
+ printf("%s: couldn't establish interrupt",
+ ahc->sc_dev.dv_xname);
+ if (intrstr != NULL)
+ printf(" at %s", intrstr);
+ printf("\n");
+ ahc_free(ahc);
+ return;
+ }
+ if (intrstr != NULL)
+ printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
+ intrstr);
+#endif /* defined(__NetBSD__) */
+
+ /* Attach sub-devices - always succeeds */
+ ahc_attach(ahc);
+
+#if defined(__FreeBSD__)
+ return 0;
+#endif
+}
+
+#endif /* NEISA > 0 */
diff --git a/sys/dev/eisa/files.eisa b/sys/dev/eisa/files.eisa
index 317b14846d8..df9b6240ef8 100644
--- a/sys/dev/eisa/files.eisa
+++ b/sys/dev/eisa/files.eisa
@@ -1,4 +1,4 @@
-# $NetBSD: files.eisa,v 1.8 1996/04/25 02:16:39 thorpej Exp $
+# $NetBSD: files.eisa,v 1.9 1996/05/16 03:48:16 mycroft Exp $
#
# Config.new file and device description for machine-independent EISA code.
# Included by ports that need it. Requires that the SCSI files be
@@ -13,6 +13,11 @@ device ahb: scsi
attach ahb at eisa
file dev/eisa/aha1742.c ahb
+# Adaptec AHA-27/284X and aic7770 motherboard SCSI controllers
+# device declaration in sys/conf/files
+attach ahc at eisa with ahc_eisa
+file dev/eisa/ahc_eisa.c ahc_eisa
+
# 3Com 3c579 and 3c509 masquerading as EISA Ethernet Controllers
# device declaration in sys/conf/files
attach ep at eisa with ep_eisa
diff --git a/sys/dev/isa/aha284x.c b/sys/dev/isa/aha284x.c
deleted file mode 100644
index 7b197efc40b..00000000000
--- a/sys/dev/isa/aha284x.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* $NetBSD: aha284x.c,v 1.5 1996/05/12 23:51:31 mycroft Exp $ */
-
-/*
- * Copyright (c) 1996 Michael Graff. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Michael Graff.
- * 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.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/device.h>
-
-#include <scsi/scsi_all.h>
-#include <scsi/scsiconf.h>
-
-#include <dev/isa/isavar.h>
-
-#include <dev/ic/aic7xxxvar.h>
-
-#include <machine/intr.h>
-#include <machine/pio.h>
-
-static int ahe_probe __P((struct device *, void *, void *));
-static void ahe_attach __P((struct device *, struct device *, void *));
-
-struct cfattach ahe_ca = {
- sizeof(struct ahc_softc), ahe_probe, ahe_attach
-};
-
-struct cfdriver ahe_cd = {
- NULL, "ahe", DV_DULL
-};
-
-/*
- * shouldn't this be in aic7xxxvar.h?
- */
-int ahcintr __P((void *));
-
-/*
- * Standard EISA Host ID regs (Offset from slot base)
- * These seem to work on the aha284x as well (VLB card)
- */
-#define HID0 0xC80 /* 0,1: msb of ID2, 2-7: ID1 */
-#define HID1 0xC81 /* 0-4: ID3, 5-7: LSB ID2 */
-#define HID2 0xC82 /* product */
-#define HID3 0xC83 /* firmware revision */
-
-#define CHAR1(B1,B2) (((B1>>2) & 0x1F) | '@')
-#define CHAR2(B1,B2) (((B1<<3) & 0x18) | ((B2>>5) & 0x7)|'@')
-#define CHAR3(B1,B2) ((B2 & 0x1F) | '@')
-
-typedef struct {
- ahc_type type;
- unsigned char id; /* The Last EISA Host ID reg */
-} aic7770_sig;
-
-aic7770_sig valid_ids[] = {
- /* Entries of other tested adaptors should be added here */
- { AHC_274, 0x70 }, /*aic7770 on Motherboard*/
- { AHC_274, 0x71 }, /*274x*/
- { AHC_284, 0x56 }, /*284x, BIOS enabled*/
- { AHC_284, 0x57 } /*284x, BIOS disabled*/
-};
-
-int
-ahe_probe(parent, match, aux)
- struct device *parent;
- void *match, *aux;
-{
- struct ahc_softc *ahc = match;
- struct isa_attach_args *ia = aux;
-
- char intdef;
- int iobase;
- u_char sig_id[4];
- int i;
-
-#ifdef NEWCONFIG
- if (ia->ia_iobase == IOBASEUNK)
- return 0;
-#endif
-
- /*
- * Make the offsets the same as for EISA
- *
- * I have NO idea why the values in aic7xxx.c are all 0xc00 too
- * high, but this hack fixes it. This is the same hack that's in
- * the 294x pci code.
- */
- iobase = ia->ia_iobase - 0xc00;
-
- for (i = 0; i < sizeof(sig_id); i++) {
- /*
- * An outb is required to prime these
- * registers on VL cards
- */
- outb(iobase + HID0, HID0 + i);
- sig_id[i] = inb(iobase + HID0 + i);
- }
-
- if (sig_id[0] == 0xff)
- return 0;
-
- if (CHAR1(sig_id[0], sig_id[1]) != 'A'
- || CHAR2(sig_id[0], sig_id[1]) != 'D'
- || CHAR3(sig_id[0], sig_id[1]) != 'P'
- || sig_id[2] != 0x77)
- return 0;
-
- ahc->type = 0;
-
- for (i = 0; i < sizeof(valid_ids)/sizeof(aic7770_sig); i++)
- if (sig_id[3] == valid_ids[i].id) {
- ahc->type = valid_ids[i].type;
- break;
- }
-
- if (ahc->type == 0)
- printf("%s: Unknown board type 0x%02x\n",
- ahc->sc_dev.dv_xname, sig_id[3]);
-
- if (ahcprobe(ahc, iobase) == 0)
- return 0;
-
- /*
- * set up some other isa variables and make certain the irq the
- * card is set at matches the one in the configuration file,
- * it is wa defined there
- */
-
- ia->ia_iosize = 0x100; /* address range for the card */
-
- if (ia->ia_irq == IRQUNK)
- ia->ia_irq = ahc->sc_irq; /* probed from the card */
- else
- if (ia->ia_irq != ahc->sc_irq) {
- printf("%s: irq mismatch; kernel configured %d != board configured %d\n",
- ahc->sc_dev.dv_xname, ia->ia_irq, ahc->sc_irq);
- return 0;
- }
-
- /* Must be ok... */
- return 1;
-}
-
-void
-ahe_attach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
-{
- struct ahc_softc *ahc = (void *)self;
- struct isa_attach_args *ia = aux;
-
-#ifdef NEWCONFIG
- isa_establish(&ahc->sc_id, &ahc->sc_dev);
-#endif
- ahc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
- IPL_BIO, ahcintr, ahc);
-
- /*
- * attach the devices on the bus
- */
- ahcattach(ahc);
-}
diff --git a/sys/dev/isa/files.isa b/sys/dev/isa/files.isa
index 2bc1f30f3b2..790e0309d8f 100644
--- a/sys/dev/isa/files.isa
+++ b/sys/dev/isa/files.isa
@@ -1,4 +1,4 @@
-# $NetBSD: files.isa,v 1.20 1996/05/07 01:50:09 thorpej Exp $
+# $NetBSD: files.isa,v 1.21 1996/05/16 03:45:55 mycroft Exp $
#
# Config.new file and device description for machine-independent ISA code.
# Included by ports that need it. Requires that the SCSI files be
@@ -69,16 +69,11 @@ device aha: scsi, isadma
attach aha at isa
file dev/isa/aha.c aha
-# Adapctec AIC-6[32]60 ICs
+# Adaptec AIC-6[32]60 ICs
device aic: scsi, isadma
attach aic at isa
file dev/isa/aic6360.c aic
-# Adaptec 7770-based EISA, VLB, etc. controllers
-device ahe: scsi, aic7xxx
-attach ahe at isa
-file dev/isa/aha284x.c ahe
-
# BusLogic BT-74x EISA family (XXX; should be EISA. it's special)
device bt: scsi, isadma
attach bt at isa
diff --git a/sys/dev/microcode/aic7xxx/Makefile.inc b/sys/dev/microcode/aic7xxx/Makefile.inc
index 75385b50755..53c83a444ab 100644
--- a/sys/dev/microcode/aic7xxx/Makefile.inc
+++ b/sys/dev/microcode/aic7xxx/Makefile.inc
@@ -4,7 +4,7 @@ PATH: $S/dev/microcode/aic7xxx
aic7xxx.o: aic7xxx_seq.h
aic7xxx_seq.h: aic7xxx_asm $S/dev/microcode/aic7xxx/aic7xxx.seq
- ./aic7xxx_asm -v -o ${.TARGET} $S/dev/microcode/aic7xxx/aic7xxx.seq
+ ./aic7xxx_asm -o ${.TARGET} $S/dev/microcode/aic7xxx/aic7xxx.seq
aic7xxx_asm: $S/dev/microcode/aic7xxx/aic7xxx_asm.c
diff --git a/sys/dev/microcode/aic7xxx/aic7xxx.seq b/sys/dev/microcode/aic7xxx/aic7xxx.seq
index 242115929b8..a91617030d6 100644
--- a/sys/dev/microcode/aic7xxx/aic7xxx.seq
+++ b/sys/dev/microcode/aic7xxx/aic7xxx.seq
@@ -1,1262 +1,1105 @@
-##+M#########################################################################
-# Adaptec 274x/284x/294x device driver for Linux and FreeBSD.
-#
-# Copyright (c) 1994 John Aycock
-# The University of Calgary Department of Computer Science.
-# All rights reserved.
-#
-# Modifications/enhancements:
-# Copyright (c) 1994, 1995 Justin Gibbs. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions, and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of Calgary
-# Department of Computer Science and its contributors.
-# 4. Neither the name of the University 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# FreeBSD, Twin, Wide, 2 command per target support, tagged queuing and other
-# optimizations provided by Justin T. Gibbs (gibbs@FreeBSD.org)
-#
-##-M#########################################################################
-
-VERSION AIC7XXX_SEQ_VER "$Id: aic7xxx.seq,v 1.1 1995/10/09 09:49:37 mycroft Exp $"
-
-SCBMASK = 0x1f
-
-SCSISEQ = 0x00
-ENRSELI = 0x10
-SXFRCTL0 = 0x01
-SXFRCTL1 = 0x02
-SCSISIGI = 0x03
-SCSISIGO = 0x03
-SCSIRATE = 0x04
-SCSIID = 0x05
-SCSIDATL = 0x06
-STCNT = 0x08
-STCNT+0 = 0x08
-STCNT+1 = 0x09
-STCNT+2 = 0x0a
-CLRSINT0 = 0x0b
-SSTAT0 = 0x0b
-SELDO = 0x40
-SELDI = 0x20
-CLRSINT1 = 0x0c
-SSTAT1 = 0x0c
-SIMODE1 = 0x11
-SCSIBUSL = 0x12
-SHADDR = 0x14
-SELID = 0x19
-SBLKCTL = 0x1f
-SEQCTL = 0x60
-A = 0x64 # == ACCUM
-SINDEX = 0x65
-DINDEX = 0x66
-ALLZEROS = 0x6a
-NONE = 0x6a
-SINDIR = 0x6c
-DINDIR = 0x6d
-FUNCTION1 = 0x6e
-HADDR = 0x88
-HADDR+1 = 0x89
-HADDR+2 = 0x8a
-HADDR+3 = 0x8b
-HCNT = 0x8c
-HCNT+0 = 0x8c
-HCNT+1 = 0x8d
-HCNT+2 = 0x8e
-SCBPTR = 0x90
-INTSTAT = 0x91
-DFCNTRL = 0x93
-DFSTATUS = 0x94
-DFDAT = 0x99
-QINFIFO = 0x9b
-QINCNT = 0x9c
-QOUTFIFO = 0x9d
-
-SCSICONF_A = 0x5a
-SCSICONF_B = 0x5b
-
-# The two reserved bytes at SCBARRAY+1[23] are expected to be set to
-# zero, and the reserved bit in SCBARRAY+0 is used as an internal flag
-# to indicate whether or not to reload scatter-gather parameters after
-# a disconnect. We also use bits 6 & 7 to indicate whether or not to
-# initiate SDTR or WDTR repectively when starting this command.
-#
-SCBARRAY+0 = 0xa0
-
-DISCONNECTED = 0x04
-NEEDDMA = 0x08
-SG_LOAD = 0x10
-TAG_ENB = 0x20
-NEEDSDTR = 0x40
-NEEDWDTR = 0x80
-
-SCBARRAY+1 = 0xa1
-SCBARRAY+2 = 0xa2
-SCBARRAY+3 = 0xa3
-SCBARRAY+4 = 0xa4
-SCBARRAY+5 = 0xa5
-SCBARRAY+6 = 0xa6
-SCBARRAY+7 = 0xa7
-SCBARRAY+8 = 0xa8
-SCBARRAY+9 = 0xa9
-SCBARRAY+10 = 0xaa
-SCBARRAY+11 = 0xab
-SCBARRAY+12 = 0xac
-SCBARRAY+13 = 0xad
-SCBARRAY+14 = 0xae
-SCBARRAY+15 = 0xaf
-SCBARRAY+16 = 0xb0
-SCBARRAY+17 = 0xb1
-SCBARRAY+18 = 0xb2
-SCBARRAY+19 = 0xb3
-SCBARRAY+20 = 0xb4
-SCBARRAY+21 = 0xb5
-SCBARRAY+22 = 0xb6
-SCBARRAY+23 = 0xb7
-SCBARRAY+24 = 0xb8
-SCBARRAY+25 = 0xb9
-SCBARRAY+26 = 0xba
-SCBARRAY+27 = 0xbb
-SCBARRAY+28 = 0xbc
-SCBARRAY+29 = 0xbd
-SCBARRAY+30 = 0xbe
-
-BAD_PHASE = 0x01 # unknown scsi bus phase
-CMDCMPLT = 0x02 # Command Complete
-SEND_REJECT = 0x11 # sending a message reject
-NO_IDENT = 0x21 # no IDENTIFY after reconnect
-NO_MATCH = 0x31 # no cmd match for reconnect
-MSG_SDTR = 0x41 # SDTR message recieved
-MSG_WDTR = 0x51 # WDTR message recieved
-MSG_REJECT = 0x61 # Reject message recieved
-BAD_STATUS = 0x71 # Bad status from target
-RESIDUAL = 0x81 # Residual byte count != 0
-ABORT_TAG = 0x91 # Sent an ABORT_TAG message
-
-# The host adapter card (at least the BIOS) uses 20-2f for SCSI
-# device information, 32-33 and 5a-5f as well. As it turns out, the
-# BIOS trashes 20-2f, writing the synchronous negotiation results
-# on top of the BIOS values, so we re-use those for our per-target
-# scratchspace (actually a value that can be copied directly into
-# SCSIRATE). The kernel driver will enable synchronous negotiation
-# for all targets that have a value other than 0 in the lower four
-# bits of the target scratch space. This should work irregardless of
-# whether the bios has been installed. NEEDWDTR and NEEDSDTR are the top
-# two bits of the SCB control byte. The kernel driver will set these
-# when a WDTR or SDTR message should be sent to the target the SCB's
-# command references.
-#
-# REJBYTE contains the first byte of a MESSAGE IN message, so the driver
-# can report an intelligible error if a message is rejected.
-#
-# FLAGS's high bit is true if we are currently handling a reselect;
-# its next-highest bit is true ONLY IF we've seen an IDENTIFY message
-# from the reselecting target. If we haven't had IDENTIFY, then we have
-# no idea what the lun is, and we can't select the right SCB register
-# bank, so force a kernel panic if the target attempts a data in/out or
-# command phase instead of corrupting something. FLAGS also contains
-# configuration bits so that we can optimize for TWIN and WIDE controllers
-# as well as the MAX_SYNC bit which we set when we want to negotiate for
-# 10MHz irregardless of what the per target scratch space says.
-#
-# Note that SG_NEXT occupies four bytes.
-#
-SYNCNEG = 0x20
-
-REJBYTE = 0x31
-DISC_DSB_A = 0x32
-DISC_DSB_B = 0x33
-
-MSG_LEN = 0x34
-MSG_START+0 = 0x35
-MSG_START+1 = 0x36
-MSG_START+2 = 0x37
-MSG_START+3 = 0x38
-MSG_START+4 = 0x39
-MSG_START+5 = 0x3a
--MSG_START+0 = 0xcb # 2's complement of MSG_START+0
-
-ARG_1 = 0x4a # sdtr conversion args & return
-BUS_16_BIT = 0x01
-RETURN_1 = 0x4a
-
-SIGSTATE = 0x4b # value written to SCSISIGO
-
-# Linux users should use 0xc (12) for SG_SIZEOF
-SG_SIZEOF = 0x8 # sizeof(struct ahc_dma)
-#SG_SIZEOF = 0xc # sizeof(struct scatterlist)
-SCB_SIZEOF = 0x13 # sizeof SCB to DMA (19 bytes)
-
-SG_NOLOAD = 0x4c # load SG pointer/length?
-SG_COUNT = 0x4d # working value of SG count
-SG_NEXT = 0x4e # working value of SG pointer
-SG_NEXT+0 = 0x4e
-SG_NEXT+1 = 0x4f
-SG_NEXT+2 = 0x50
-SG_NEXT+3 = 0x51
-
-SCBCOUNT = 0x52 # the actual number of SCBs
-FLAGS = 0x53 # Device configuration flags
-TWIN_BUS = 0x01
-WIDE_BUS = 0x02
-MAX_SYNC = 0x08
-ACTIVE_MSG = 0x20
-IDENTIFY_SEEN = 0x40
-RESELECTED = 0x80
-
-ACTIVE_A = 0x54
-ACTIVE_B = 0x55
-SAVED_TCL = 0x56 # Temporary storage for the
- # target/channel/lun of a
- # reconnecting target
-
-# After starting the selection hardware, we return to the "poll_for_work"
-# loop so that we can check for reconnecting targets as well as for our
-# selection to complete just in case the reselection wins bus arbitration.
-# The problem with this is that we must keep track of the SCB that we've
-# already pulled from the QINFIFO and started the selection on just in case
-# the reselection wins so that we can retry the selection at a later time.
-# This problem cannot be resolved by holding a single entry in scratch
-# ram since a reconnecting target can request sense and this will create
-# yet another SCB waiting for selection. The solution used here is to
-# use byte 31 of the SCB as a psuedo-next pointer and to thread a list
-# of SCBs that are awaiting selection. Since 0 is a valid SCB offset,
-# SCB_LIST_NULL is 0x10 which is out of range. The kernel driver must
-# add an entry to this list everytime a request sense occurs. The sequencer
-# will automatically consume the entries.
-
-WAITING_SCBH = 0x57 # head of list of SCBs awaiting
- # selection
-WAITING_SCBT = 0x58 # tail of list of SCBs awaiting
- # selection
-SCB_LIST_NULL = 0x10
-
-
-# Poll QINCNT for work - the lower bits contain
-# the number of entries in the Queue In FIFO.
-#
+/*+M***********************************************************************
+ *Adaptec 274x/284x/294x device driver for Linux and FreeBSD.
+ *
+ *Copyright (c) 1994 John Aycock
+ * The University of Calgary Department of Computer Science.
+ * All rights reserved.
+ *
+ *FreeBSD, Twin, Wide, 2 command per target support, tagged queuing,
+ *SCB paging and other optimizations:
+ *Copyright (c) 1994, 1995, 1996 Justin Gibbs. All rights reserved.
+ *
+ *Redistribution and use in source and binary forms, with or without
+ *modification, are permitted provided that the following conditions
+ *are met:
+ *1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ *2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of Calgary
+ * Department of Computer Science and its contributors.
+ *4. Neither the name of the University 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ *ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ *OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ *OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ *SUCH DAMAGE.
+ *
+ *-M************************************************************************/
+
+VERSION AIC7XXX_SEQ_VER "$Id: aic7xxx.seq,v 1.2 1996/05/16 03:51:45 mycroft Exp $"
+
+#if defined(__NetBSD__)
+#include "../../../../dev/ic/aic7xxxreg.h"
+#elif defined(__FreeBSD__)
+#include "../../dev/aic7xxx/aic7xxx_reg.h"
+#endif
+
+/*
+ * We can't just use ACCUM in the sequencer code because it
+ * must be treated specially by the assembler, and it currently
+ * looks for the symbol 'A'. This is the only register defined in
+ * the assembler's symbol space.
+ */
+A = ACCUM
+
+/* After starting the selection hardware, we check for reconnecting targets
+ * as well as for our selection to complete just in case the reselection wins
+ * bus arbitration. The problem with this is that we must keep track of the
+ * SCB that we've already pulled from the QINFIFO and started the selection
+ * on just in case the reselection wins so that we can retry the selection at
+ * a later time. This problem cannot be resolved by holding a single entry
+ * in scratch ram since a reconnecting target can request sense and this will
+ * create yet another SCB waiting for selection. The solution used here is to
+ * use byte 27 of the SCB as a psuedo-next pointer and to thread a list
+ * of SCBs that are awaiting selection. Since 0-0xfe are valid SCB offsets,
+ * SCB_LIST_NULL is 0xff which is out of range. The kernel driver must
+ * add an entry to this list everytime a request sense occurs. The sequencer
+ * will automatically consume the entries.
+ */
+
+/*
+ * We assume that the kernel driver may reset us at any time, even in the
+ * middle of a DMA, so clear DFCNTRL too.
+ */
+reset:
+ clr DFCNTRL
+ clr SCSISIGO /* De-assert BSY */
+/*
+ * We jump to start after every bus free.
+ */
start:
- test WAITING_SCBH,SCB_LIST_NULL jz start_waiting
+ and FLAGS,0x0f /* clear target specific flags */
+ mvi SCSISEQ,ENRSELI /* Always allow reselection */
poll_for_work:
- test FLAGS,TWIN_BUS jz start2 # Are we a twin channel device?
-# For fairness, we check the other bus first, since we just finished a
-# transaction on the current channel.
- xor SBLKCTL,0x08 # Toggle to the other bus
+ /*
+ * Are we a twin channel device?
+ * For fairness, we check the other bus first,
+ * since we just finished a transaction on the
+ * current channel.
+ */
+ test FLAGS,TWIN_BUS jz start2
+ xor SBLKCTL,SELBUSB /* Toggle to the other bus */
test SSTAT0,SELDI jnz reselect
- test SSTAT0,SELDO jnz select
- xor SBLKCTL,0x08 # Toggle to the original bus
+ xor SBLKCTL,SELBUSB /* Toggle to the original bus */
start2:
test SSTAT0,SELDI jnz reselect
- test SSTAT0,SELDO jnz select
- test WAITING_SCBH,SCB_LIST_NULL jz start_waiting
- test QINCNT,SCBMASK jz poll_for_work
-
-# We have at least one queued SCB now and we don't have any
-# SCBs in the list of SCBs awaiting selection. Set the SCB
-# pointer from the FIFO so we see the right bank of SCB
-# registers, then set SCSI options and set the initiator and
-# target SCSI IDs.
-#
+ cmp WAITING_SCBH,SCB_LIST_NULL jne start_waiting
+ mov A, QCNTMASK
+ test QINCNT,A jz poll_for_work
+
+/*
+ * We have at least one queued SCB now and we don't have any
+ * SCBs in the list of SCBs awaiting selection. Set the SCB
+ * pointer from the FIFO so we see the right bank of SCB
+ * registers.
+ */
mov SCBPTR,QINFIFO
-# If the control byte of this SCB has the NEEDDMA flag set, we have
-# yet to DMA it from host memory
-
-test SCBARRAY+0,NEEDDMA jz test_busy
- clr HCNT+2
- clr HCNT+1
- mvi HCNT+0,SCB_SIZEOF
-
- mvi DINDEX,HADDR
- mvi SCBARRAY+26 call bcopy_4
-
- mvi DFCNTRL,0xd # HDMAEN|DIRECTION|FIFORESET
-
-# Wait for DMA from host memory to data FIFO to complete, then disable
-# DMA and wait for it to acknowledge that it's off.
-#
- call dma_finish
-
-# Copy the SCB from the FIFO to the SCBARRAY
-
- mvi DINDEX, SCBARRAY+0
- call bcopy_3_dfdat
- call bcopy_4_dfdat
- call bcopy_4_dfdat
- call bcopy_4_dfdat
- call bcopy_4_dfdat
-
-# See if there is not already an active SCB for this target. This code
-# locks out on a per target basis instead of target/lun. Although this
-# is not ideal for devices that have multiple luns active at the same
-# time, it is faster than looping through all SCB's looking for active
-# commands. It may be benificial to make findscb a more general procedure
-# to see if the added cost of the search is negligible. This code also
-# assumes that the kernel driver will clear the active flags on board
-# initialization, board reset, and a target's SELTO.
+/*
+ * See if there is not already an active SCB for this target. This code
+ * locks out on a per target basis instead of target/lun. Although this
+ * is not ideal for devices that have multiple luns active at the same
+ * time, it is faster than looping through all SCB's looking for active
+ * commands. It may be benificial to make findscb a more general procedure
+ * to see if the added cost of the search is negligible. This code also
+ * assumes that the kernel driver will clear the active flags on board
+ * initialization, board reset, and a target SELTO. Tagged commands
+ * don't set the active bits since you can queue more than one command
+ * at a time. We do, however, look to see if there are any non-tagged
+ * I/Os in progress, and requeue the command if there are. Tagged and
+ * non-tagged commands cannot be mixed to a single target.
+ */
test_busy:
- test SCBARRAY+0,0x20 jnz start_scb
- and FUNCTION1,0x70,SCBARRAY+1
+ mov FUNCTION1,SCB_TCL
mov A,FUNCTION1
- test SCBARRAY+1,0x88 jz test_a # Id < 8 && A channel
+ test SCB_TCL,0x88 jz test_a /* Id < 8 && A channel */
test ACTIVE_B,A jnz requeue
- or ACTIVE_B,A # Mark the current target as busy
+ test SCB_CONTROL,TAG_ENB jnz start_scb
+ /* Mark the current target as busy */
+ or ACTIVE_B,A
jmp start_scb
-# Place the currently active back on the queue for later processing
+/* Place the currently active SCB back on the queue for later processing */
requeue:
mov QINFIFO, SCBPTR
jmp poll_for_work
-# Pull the first entry off of the waiting for selection list
+/*
+ * Pull the first entry off of the waiting for selection list
+ * We don't have to "test_busy" because only transactions that
+ * have passed that test can be in the waiting_scb list.
+ */
start_waiting:
mov SCBPTR,WAITING_SCBH
- jmp start_scb
+ jmp start_scb2
test_a:
- test ACTIVE_A,A jnz requeue
- or ACTIVE_A,A # Mark the current target as busy
+ test ACTIVE_A,A jnz requeue
+ test SCB_CONTROL,TAG_ENB jnz start_scb
+ /* Mark the current target as busy */
+ or ACTIVE_A,A
start_scb:
- and SINDEX,0xf7,SBLKCTL #Clear the channel select bit
- and A,0x08,SCBARRAY+1 #Get new channel bit
- or SINDEX,A
- mov SBLKCTL,SINDEX # select channel
- mov SCBARRAY+1 call initialize_scsiid
-
-# Enable selection phase as an initiator, and do automatic ATN
-# after the selection. We do this now so that we can overlap the
-# rest of our work to set up this target with the arbitration and
-# selection bus phases.
-#
-start_selection:
- or SCSISEQ,0x48 # ENSELO|ENAUTOATNO
+ mov SCB_NEXT,WAITING_SCBH
mov WAITING_SCBH, SCBPTR
- clr SG_NOLOAD
- and FLAGS,0x3f # !RESELECTING
-
-# As soon as we get a successful selection, the target should go
-# into the message out phase since we have ATN asserted. Prepare
-# the message to send, locking out the device driver. If the device
-# driver hasn't beaten us with an ABORT or RESET message, then tack
-# on an SDTR negotiation if required.
-#
-# Messages are stored in scratch RAM starting with a flag byte (high bit
-# set means active message), one length byte, and then the message itself.
-#
- mov SCBARRAY+1 call disconnect # disconnect ok?
-
- and SINDEX,0x7,SCBARRAY+1 # lun
- or SINDEX,A # return value from disconnect
- or SINDEX,0x80 call mk_mesg # IDENTIFY message
-
- mov A,SINDEX
- test SCBARRAY+0,0xe0 jz !message # WDTR, SDTR or TAG??
- cmp MSG_START+0,A jne !message # did driver beat us?
-
-# Tag Message if Tag enabled in SCB control block. Use SCBPTR as the tag
-# value
+start_scb2:
+ and SINDEX,0xf7,SBLKCTL /* Clear the channel select bit */
+ and A,0x08,SCB_TCL /* Get new channel bit */
+ or SINDEX,A
+ mov SBLKCTL,SINDEX /* select channel */
+ mov SCB_TCL call initialize_scsiid
+
+/*
+ * Enable selection phase as an initiator, and do automatic ATN
+ * after the selection. We do this now so that we can overlap the
+ * rest of our work to set up this target with the arbitration and
+ * selection bus phases.
+ */
+start_selection:
+ mvi SCSISEQ,0x58 /* ENSELO|ENAUTOATNO|ENRSELI */
+
+/*
+ * As soon as we get a successful selection, the target should go
+ * into the message out phase since we have ATN asserted. Prepare
+ * the message to send.
+ *
+ * Messages are stored in scratch RAM starting with a length byte
+ * followed by the message itself.
+ */
+ test SCB_CMDLEN,0xff jnz mk_identify /* 0 Length Command? */
+
+/*
+ * The kernel has sent us an SCB with no command attached. This implies
+ * that the kernel wants to send a message of some sort to this target,
+ * so we interrupt the driver, allow it to fill the message buffer, and
+ * then go back into the arbitration loop
+ */
+ mvi INTSTAT,AWAITING_MSG
+ jmp wait_for_selection
+
+mk_identify:
+ and A,DISCENB,SCB_CONTROL /* mask off disconnect privledge */
+
+ and MSG0,0x7,SCB_TCL /* lun */
+ or MSG0,A /* or in disconnect privledge */
+ or MSG0,MSG_IDENTIFY
+ mvi MSG_LEN, 1
+
+ test SCB_CONTROL,0xb0 jz !message /* WDTR, SDTR or TAG?? */
+/*
+ * Send a tag message if TAG_ENB is set in the SCB control block.
+ * Use SCB_TAG (the position in the kernel's SCB array) as the tag value.
+ */
mk_tag:
- mvi DINDEX, MSG_START+1
- test SCBARRAY+0,TAG_ENB jz mk_tag_done
- and A,0x23,SCBARRAY+0
- mov DINDIR,A
- mov DINDIR,SCBPTR
+ mvi DINDEX, MSG1
+ test SCB_CONTROL,TAG_ENB jz mk_tag_done
+ and DINDIR,0x23,SCB_CONTROL
+ mov DINDIR,SCB_TAG
- add MSG_LEN,-MSG_START+0,DINDEX # update message length
+ add MSG_LEN,COMP_MSG0,DINDEX /* update message length */
mk_tag_done:
- mov DINDEX call mk_dtr # build DTR message if needed
+ test SCB_CONTROL,0x90 jz !message /* NEEDWDTR|NEEDSDTR */
+ mov DINDEX call mk_dtr /* build DTR message if needed */
!message:
- jmp poll_for_work
-
-# Reselection has been initiated by a target. Make a note that we've been
-# reselected, but haven't seen an IDENTIFY message from the target
-# yet.
-#
+wait_for_selection:
+ test SSTAT0,SELDO jnz select
+ test SSTAT0,SELDI jz wait_for_selection
+
+/*
+ * Reselection has been initiated by a target. Make a note that we've been
+ * reselected, but haven't seen an IDENTIFY message from the target
+ * yet.
+ */
reselect:
+ clr MSG_LEN /* Don't have anything in the mesg buffer */
mov SELID call initialize_scsiid
- and FLAGS,0x3f # reselected, no IDENTIFY
- or FLAGS,RESELECTED jmp select2
-
-# After the selection, remove this SCB from the "waiting for selection"
-# list. This is achieved by simply moving our "next" pointer into
-# WAITING_SCBH and setting our next pointer to null so that the next
-# time this SCB is used, we don't get confused.
-#
+ or FLAGS,RESELECTED
+ jmp select2
+
+/*
+ * After the selection, remove this SCB from the "waiting for selection"
+ * list. This is achieved by simply moving our "next" pointer into
+ * WAITING_SCBH. Our next pointer will be set to null the next time this
+ * SCB is used, so don't bother with it now.
+ */
select:
- or SCBARRAY+0,NEEDDMA
- mov WAITING_SCBH,SCBARRAY+30
- mvi SCBARRAY+30,SCB_LIST_NULL
+ mov WAITING_SCBH,SCB_NEXT
+ or FLAGS,SELECTED
select2:
- call initialize_for_target
- mvi SCSISEQ,ENRSELI
- mvi CLRSINT0,0x60 # CLRSELDI|CLRSELDO
- mvi CLRSINT1,0x8 # CLRBUSFREE
-
-# Main loop for information transfer phases. If BSY is false, then
-# we have a bus free condition, expected or not. Otherwise, wait
-# for the target to assert REQ before checking MSG, C/D and I/O
-# for the bus phase.
-#
-# We can't simply look at the values of SCSISIGI here (if we want
-# to do synchronous data transfer), because the target won't assert
-# REQ if it's already sent us some data that we haven't acknowledged
-# yet.
-#
+/*
+ * Set CLRCHN here before the target has entered a data transfer mode -
+ * with synchronous SCSI, if you do it later, you blow away some
+ * data in the SCSI FIFO that the target has already sent to you.
+ */
+ or SXFRCTL0,CLRCHN
+/*
+ * Initialize SCSIRATE with the appropriate value for this target.
+ */
+ call ndx_dtr
+ mov SCSIRATE,SINDIR
+
+ mvi SCSISEQ,ENAUTOATNP /*
+ * ATN on parity errors
+ * for "in" phases
+ */
+ mvi CLRSINT1,CLRBUSFREE
+ mvi CLRSINT0,0x60 /* CLRSELDI|CLRSELDO */
+
+/*
+ * Main loop for information transfer phases. If BSY is false, then
+ * we have a bus free condition, expected or not. Otherwise, wait
+ * for the target to assert REQ before checking MSG, C/D and I/O
+ * for the bus phase.
+ *
+ */
ITloop:
- test SSTAT1,0x8 jnz p_busfree # BUSFREE
- test SSTAT1,0x1 jz ITloop # REQINIT
+ test SSTAT1,BUSFREE jnz p_busfree
+ test SSTAT1,REQINIT jz ITloop
- and A,0xe0,SCSISIGI # CDI|IOI|MSGI
+ and A,PHASE_MASK,SCSISIGI
+ mov LASTPHASE,A
+ mov SCSISIGO,A
cmp ALLZEROS,A je p_dataout
- cmp A,0x40 je p_datain
- cmp A,0x80 je p_command
- cmp A,0xc0 je p_status
- cmp A,0xa0 je p_mesgout
- cmp A,0xe0 je p_mesgin
+ cmp A,P_DATAIN je p_datain
+ cmp A,P_COMMAND je p_command
+ cmp A,P_MESGOUT je p_mesgout
+ cmp A,P_STATUS je p_status
+ cmp A,P_MESGIN je p_mesgin
- mvi INTSTAT,BAD_PHASE # unknown - signal driver
+ mvi INTSTAT,BAD_PHASE /* unknown phase - signal driver */
p_dataout:
- mvi 0 call scsisig # !CDO|!IOO|!MSGO
- call assert
- call sg_load
-
- mvi DINDEX,HADDR
- mvi SCBARRAY+19 call bcopy_4
-
-# mvi DINDEX,HCNT # implicit since HCNT is next to HADDR
- mvi SCBARRAY+23 call bcopy_3
-
- mvi DINDEX,STCNT
- mvi SCBARRAY+23 call bcopy_3
-
-# If we are the last SG block, don't set wideodd.
- test SCBARRAY+18,0xff jnz p_dataout_wideodd
- mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN|
- # DIRECTION|FIFORESET
- jmp p_dataout_rest
-
-p_dataout_wideodd:
- mvi 0xbd call dma # WIDEODD|SCSIEN|SDMAEN|HDMAEN|
- # DIRECTION|FIFORESET
-
-p_dataout_rest:
-# After a DMA finishes, save the final transfer pointer and count
-# back into the SCB, in case a device disconnects in the middle of
-# a transfer. Use SHADDR and STCNT instead of HADDR and HCNT, since
-# it's a reflection of how many bytes were transferred on the SCSI
-# (as opposed to the host) bus.
-#
- mvi DINDEX,SCBARRAY+23
- mvi STCNT call bcopy_3
+ mvi DMAPARAMS,0x7d /*
+ * WIDEODD|SCSIEN|SDMAEN|HDMAEN|
+ * DIRECTION|FIFORESET
+ */
+ jmp data_phase_init
+
+/*
+ * If we re-enter the data phase after going through another phase, the
+ * STCNT may have been cleared, so restore it from the residual field.
+ */
+data_phase_reinit:
+ mov STCNT0,SCB_RESID_DCNT0
+ mov STCNT1,SCB_RESID_DCNT1
+ mov STCNT2,SCB_RESID_DCNT2
+ jmp data_phase_loop
- mvi DINDEX,SCBARRAY+19
- mvi SHADDR call bcopy_4
+p_datain:
+ mvi DMAPARAMS,0x79 /*
+ * WIDEODD|SCSIEN|SDMAEN|HDMAEN|
+ * !DIRECTION|FIFORESET
+ */
+data_phase_init:
+ call assert
- call sg_advance
- mov SCBARRAY+18,SG_COUNT # residual S/G count
+ test FLAGS, DPHASE jnz data_phase_reinit
+ call sg_scb2ram
+ or FLAGS, DPHASE /* We have seen a data phase */
- jmp ITloop
+data_phase_loop:
+/* If we are the last SG block, don't set wideodd. */
+ cmp SG_COUNT,0x01 jne data_phase_wideodd
+ and DMAPARAMS, 0xbf /* Turn off WIDEODD */
+data_phase_wideodd:
+ mov DMAPARAMS call dma
-p_datain:
- mvi 0x40 call scsisig # !CDO|IOO|!MSGO
- call assert
- call sg_load
+/* Exit if we had an underrun */
+ test SSTAT0,SDONE jz data_phase_finish /* underrun STCNT != 0 */
- mvi DINDEX,HADDR
- mvi SCBARRAY+19 call bcopy_4
+/*
+ * Advance the scatter-gather pointers if needed
+ */
+sg_advance:
+ dec SG_COUNT /* one less segment to go */
-# mvi DINDEX,HCNT # implicit since HCNT is next to HADDR
- mvi SCBARRAY+23 call bcopy_3
+ test SG_COUNT, 0xff jz data_phase_finish /* Are we done? */
- mvi DINDEX,STCNT
- mvi SCBARRAY+23 call bcopy_3
+ clr A /* add sizeof(struct scatter) */
+ add SG_NEXT0,SG_SIZEOF,SG_NEXT0
+ adc SG_NEXT1,A,SG_NEXT1
-# If we are the last SG block, don't set wideodd.
- test SCBARRAY+18,0xff jnz p_datain_wideodd
- mvi 0x39 call dma # SCSIEN|SDMAEN|HDMAEN|
- # !DIRECTION|FIFORESET
- jmp p_datain_rest
-p_datain_wideodd:
- mvi 0xb9 call dma # WIDEODD|SCSIEN|SDMAEN|HDMAEN|
- # !DIRECTION|FIFORESET
-p_datain_rest:
- mvi DINDEX,SCBARRAY+23
- mvi STCNT call bcopy_3
+/*
+ * Load a struct scatter and set up the data address and length.
+ * If the working value of the SG count is nonzero, then
+ * we need to load a new set of values.
+ *
+ * This, like all DMA's, assumes little-endian host data storage.
+ */
+sg_load:
+ clr HCNT2
+ clr HCNT1
+ mvi HCNT0,SG_SIZEOF
- mvi DINDEX,SCBARRAY+19
- mvi SHADDR call bcopy_4
+ mov HADDR0,SG_NEXT0
+ mov HADDR1,SG_NEXT1
+ mov HADDR2,SG_NEXT2
+ mov HADDR3,SG_NEXT3
- call sg_advance
- mov SCBARRAY+18,SG_COUNT # residual S/G count
+ or DFCNTRL,0xd /* HDMAEN|DIRECTION|FIFORESET */
+/*
+ * Wait for DMA from host memory to data FIFO to complete, then disable
+ * DMA and wait for it to acknowledge that it's off.
+ */
+dma_finish:
+ test DFSTATUS,HDONE jz dma_finish
+ /* Turn off DMA preserving WIDEODD */
+ and DFCNTRL,WIDEODD
+dma_finish2:
+ test DFCNTRL,HDMAENACK jnz dma_finish2
+
+/*
+ * Copy data from FIFO into SCB data pointer and data count. This assumes
+ * that the struct scatterlist has this structure (this and sizeof(struct
+ * scatterlist) == 12 are asserted in aic7xxx.c for the Linux driver):
+ *
+ * struct scatterlist {
+ * char *address; four bytes, little-endian order
+ * ... four bytes, ignored
+ * unsigned short length; two bytes, little-endian order
+ * }
+ *
+ *
+ * In FreeBSD, the scatter list entry is only 8 bytes.
+ *
+ * struct ahc_dma_seg {
+ * physaddr addr; four bytes, little-endian order
+ * long len; four bytes, little endian order
+ * };
+ */
+
+ mov HADDR0,DFDAT
+ mov HADDR1,DFDAT
+ mov HADDR2,DFDAT
+ mov HADDR3,DFDAT
+/*
+ * For Linux, we must throw away four bytes since there is a 32bit gap
+ * in the middle of a struct scatterlist.
+ */
+#ifdef __linux__
+ mov NONE,DFDAT
+ mov NONE,DFDAT
+ mov NONE,DFDAT
+ mov NONE,DFDAT
+#endif
+ mov HCNT0,DFDAT
+ mov HCNT1,DFDAT
+ mov HCNT2,DFDAT
+
+/* Load STCNT as well. It is a mirror of HCNT */
+ mov STCNT0,HCNT0
+ mov STCNT1,HCNT1
+ mov STCNT2,HCNT2
+ test SSTAT1,PHASEMIS jz data_phase_loop
+
+data_phase_finish:
+/*
+ * After a DMA finishes, save the SG and STCNT residuals back into the SCB
+ * We use STCNT instead of HCNT, since it's a reflection of how many bytes
+ * were transferred on the SCSI (as opposed to the host) bus.
+ */
+ mov SCB_RESID_DCNT0,STCNT0
+ mov SCB_RESID_DCNT1,STCNT1
+ mov SCB_RESID_DCNT2,STCNT2
+ mov SCB_RESID_SGCNT, SG_COUNT
jmp ITloop
-# Command phase. Set up the DMA registers and let 'er rip - the
-# two bytes after the SCB SCSI_cmd_length are zeroed by the driver,
-# so we can copy those three bytes directly into HCNT.
-#
+/*
+ * Command phase. Set up the DMA registers and let 'er rip.
+ */
p_command:
- mvi 0x80 call scsisig # CDO|!IOO|!MSGO
call assert
- mvi DINDEX,HADDR
- mvi SCBARRAY+7 call bcopy_4
-
-# mvi DINDEX,HCNT # implicit since HCNT is next to HADDR
- mvi SCBARRAY+11 call bcopy_3
-
- mvi DINDEX,STCNT
- mvi SCBARRAY+11 call bcopy_3
+/*
+ * Load HADDR and HCNT.
+ */
+ mov HADDR0, SCB_CMDPTR0
+ mov HADDR1, SCB_CMDPTR1
+ mov HADDR2, SCB_CMDPTR2
+ mov HADDR3, SCB_CMDPTR3
+ mov HCNT0, SCB_CMDLEN
+ clr HCNT1
+ clr HCNT2
+
+ mov STCNT0, HCNT0
+ mov STCNT1, HCNT1
+ mov STCNT2, HCNT2
mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN|
# DIRECTION|FIFORESET
jmp ITloop
-# Status phase. Wait for the data byte to appear, then read it
-# and store it into the SCB.
-#
+/*
+ * Status phase. Wait for the data byte to appear, then read it
+ * and store it into the SCB.
+ */
p_status:
- mvi 0xc0 call scsisig # CDO|IOO|!MSGO
-
- mvi SCBARRAY+14 call inb_first
- jmp p_mesgin_done
+ mvi SCB_TARGET_STATUS call inb_first
+ jmp mesgin_done
-# Message out phase. If there is no active message, but the target
-# took us into this phase anyway, build a no-op message and send it.
-#
+/*
+ * Message out phase. If there is not an active message, but the target
+ * took us into this phase anyway, build a no-op message and send it.
+ */
p_mesgout:
- mvi 0xa0 call scsisig # CDO|!IOO|MSGO
- mvi 0x8 call mk_mesg # build NOP message
-
- clr STCNT+2
- clr STCNT+1
-
-# Set up automatic PIO transfer from MSG_START. Bit 3 in
-# SXFRCTL0 (SPIOEN) is already on.
-#
- mvi SINDEX,MSG_START+0
+ test MSG_LEN, 0xff jnz p_mesgout_start
+ mvi MSG_NOP call mk_mesg /* build NOP message */
+
+p_mesgout_start:
+/*
+ * Set up automatic PIO transfer from MSG0. Bit 3 in
+ * SXFRCTL0 (SPIOEN) is already on.
+ */
+ mvi SINDEX,MSG0
mov DINDEX,MSG_LEN
-# When target asks for a byte, drop ATN if it's the last one in
-# the message. Otherwise, keep going until the message is exhausted.
-# (We can't use outb for this since it wants the input in SINDEX.)
-#
-# Keep an eye out for a phase change, in case the target issues
-# a MESSAGE REJECT.
-#
-p_mesgout2:
- test SSTAT0,0x2 jz p_mesgout2 # SPIORDY
- test SSTAT1,0x10 jnz p_mesgout6 # PHASEMIS
-
- cmp DINDEX,1 jne p_mesgout3 # last byte?
- mvi CLRSINT1,0x40 # CLRATNO - drop ATN
-
-# Write a byte to the SCSI bus. The AIC-7770 refuses to automatically
-# send ACKs in automatic PIO or DMA mode unless you make sure that the
-# "expected" bus phase in SCSISIGO matches the actual bus phase. This
-# behaviour is completely undocumented and caused me several days of
-# grief.
-#
-# After plugging in different drives to test with and using a longer
-# SCSI cable, I found that I/O in Automatic PIO mode ceased to function,
-# especially when transferring >1 byte. It seems to be much more stable
-# if STCNT is set to one before the transfer, and SDONE (in SSTAT0) is
-# polled for transfer completion - for both output _and_ input. The
-# only theory I have is that SPIORDY doesn't drop right away when SCSIDATL
-# is accessed (like the documentation says it does), and that on a longer
-# cable run, the sequencer code was fast enough to loop back and see
-# an SPIORDY that hadn't dropped yet.
-#
-p_mesgout3:
- mvi STCNT+0, 0x01
+/*
+ * When target asks for a byte, drop ATN if it's the last one in
+ * the message. Otherwise, keep going until the message is exhausted.
+ *
+ * Keep an eye out for a phase change, in case the target issues
+ * a MESSAGE REJECT.
+ */
+p_mesgout_loop:
+ test SSTAT1,PHASEMIS jnz p_mesgout_phasemis
+ test SSTAT0,SPIORDY jz p_mesgout_loop
+ cmp DINDEX,1 jne p_mesgout_outb /* last byte? */
+ mvi CLRSINT1,CLRATNO /* drop ATN */
+p_mesgout_outb:
+ dec DINDEX
+ or CLRSINT0, CLRSPIORDY
mov SCSIDATL,SINDIR
-
+
p_mesgout4:
- test SSTAT0,0x4 jz p_mesgout4 # SDONE
- dec DINDEX
- test DINDEX,0xff jnz p_mesgout2
+ test DINDEX,0xff jnz p_mesgout_loop
-# If the next bus phase after ATN drops is a message out, it means
-# that the target is requesting that the last message(s) be resent.
-#
-p_mesgout5:
- test SSTAT1,0x8 jnz p_mesgout6 # BUSFREE
- test SSTAT1,0x1 jz p_mesgout5 # REQINIT
+/*
+ * If the next bus phase after ATN drops is a message out, it means
+ * that the target is requesting that the last message(s) be resent.
+ */
+p_mesgout_snoop:
+ test SSTAT1,BUSFREE jnz p_mesgout_done
+ test SSTAT1,REQINIT jz p_mesgout_snoop
- and A,0xe0,SCSISIGI # CDI|IOI|MSGI
- cmp A,0xa0 jne p_mesgout6
- mvi 0x10 call scsisig # ATNO - re-assert ATN
+ test SSTAT1,PHASEMIS jnz p_mesgout_done
+
+ or SCSISIGO,ATNO /* turn on ATNO */
jmp ITloop
-p_mesgout6:
- mvi CLRSINT1,0x40 # CLRATNO - in case of PHASEMIS
- and FLAGS,0xdf # no active msg
+p_mesgout_phasemis:
+ mvi CLRSINT1,CLRATNO /* Be sure to turn ATNO off */
+p_mesgout_done:
+ clr MSG_LEN /* no active msg */
jmp ITloop
-# Message in phase. Bytes are read using Automatic PIO mode, but not
-# using inb. This alleviates a race condition, namely that if ATN had
-# to be asserted under Automatic PIO mode, it had to beat the SCSI
-# circuitry sending an ACK to the target. This showed up under heavy
-# loads and really confused things, since ABORT commands wouldn't be
-# seen by the drive after an IDENTIFY message in until it had changed
-# to a data I/O phase.
-#
+/*
+ * Message in phase. Bytes are read using Automatic PIO mode.
+ */
p_mesgin:
- mvi 0xe0 call scsisig # CDO|IOO|MSGO
- mvi A call inb_first # read the 1st message byte
- mvi REJBYTE,A # save it for the driver
-
- cmp ALLZEROS,A jne p_mesgin1
-
-# We got a "command complete" message, so put the SCB pointer
-# into the Queue Out, and trigger a completion interrupt.
-# Check status for non zero return and interrupt driver if needed
-# This allows the driver to interpret errors only when they occur
-# instead of always uploading the scb. If the status is SCSI_CHECK,
-# the driver will download a new scb requesting sense to replace
-# the old one, modify the "waiting for selection" SCB list and set
-# RETURN_1 to 0x80. If RETURN_1 is set to 0x80 the sequencer imediately
-# jumps to main loop where it will run down the waiting SCB list.
-# If the kernel driver does not wish to request sense, it need
-# only clear RETURN_1, and the command is allowed to complete. We don't
-# bother to post to the QOUTFIFO in the error case since it would require
-# extra work in the kernel driver to ensure that the entry was removed
-# before the command complete code tried processing it.
-
-# First check for residuals
- test SCBARRAY+15,0xff jnz resid
- test SCBARRAY+16,0xff jnz resid
- test SCBARRAY+17,0xff jnz resid
+ mvi A call inb_first /* read the 1st message byte */
+ mov REJBYTE,A /* save it for the driver */
+
+ test A,MSG_IDENTIFY jnz mesgin_identify
+ cmp A,MSG_DISCONNECT je mesgin_disconnect
+ cmp A,MSG_SDPTRS je mesgin_sdptrs
+ cmp ALLZEROS,A je mesgin_complete
+ cmp A,MSG_RDPTRS je mesgin_rdptrs
+ cmp A,MSG_EXTENDED je mesgin_extended
+ cmp A,MSG_REJECT je mesgin_reject
+
+rej_mesgin:
+/*
+ * We have no idea what this message in is, and there's no way
+ * to pass it up to the kernel, so we issue a message reject and
+ * hope for the best. Since we're now using manual PIO mode to
+ * read in the message, there should no longer be a race condition
+ * present when we assert ATN. In any case, rejection should be a
+ * rare occurrence - signal the driver when it happens.
+ */
+ or SCSISIGO,ATNO /* turn on ATNO */
+ mvi INTSTAT,SEND_REJECT /* let driver know */
+
+ mvi MSG_REJECT call mk_mesg
+
+mesgin_done:
+ call inb_last /*ack & turn auto PIO back on*/
+ jmp ITloop
+
+
+mesgin_complete:
+/*
+ * We got a "command complete" message, so put the SCB_TAG into QUEUEOUT,
+ * and trigger a completion interrupt. Check status for non zero return
+ * and interrupt driver if needed. This allows the driver to interpret
+ * errors only when they occur instead of always uploading the scb. If
+ * the status is SCSI_CHECK, the driver will download a new scb requesting
+ * sense to replace the old one, modify the "waiting for selection" SCB list
+ * and set RETURN_1 to SEND_SENSE. If RETURN_1 is set to SEND_SENSE the
+ * sequencer imediately jumps to main loop where it will run down the waiting
+ * SCB list and process the sense request. If the kernel driver does not
+ * wish to request sense, it need only clear RETURN_1, and the command is
+ * allowed to complete. We don't bother to post to the QOUTFIFO in the
+ * error case since it would require extra work in the kernel driver to
+ * ensure that the entry was removed before the command complete code tried
+ * processing it.
+ *
+ * First check for residuals
+ */
+ test SCB_RESID_SGCNT,0xff jz check_status
+/*
+ * If we have a residual count, interrupt and tell the host. Other
+ * alternatives are to pause the sequencer on all command completes (yuck),
+ * dma the resid directly to the host (slick, we may have space to do it now)
+ * or have the sequencer pause itself when it encounters a non-zero resid
+ * (unecessary pause just to flag the command -yuck-, but takes one instruction
+ * and since it shouldn't happen that often is good enough for our purposes).
+ */
+resid:
+ mvi INTSTAT,RESIDUAL
check_status:
- test SCBARRAY+14,0xff jz status_ok # 0 Status?
- mvi INTSTAT,BAD_STATUS # let driver know
- test RETURN_1, 0x80 jz status_ok
- jmp p_mesgin_done
+ test SCB_TARGET_STATUS,0xff jz status_ok /* Good Status? */
+ mvi INTSTAT,BAD_STATUS /* let driver know */
+ cmp RETURN_1, SEND_SENSE jne status_ok
+ jmp mesgin_done
status_ok:
-# First, mark this target as free.
- test SCBARRAY+0,0x20 jnz complete # Tagged command
- and FUNCTION1,0x70,SCBARRAY+1
+/* First, mark this target as free. */
+ test SCB_CONTROL,TAG_ENB jnz test_immediate /*
+ * Tagged commands
+ * don't busy the
+ * target.
+ */
+ mov FUNCTION1,SCB_TCL
mov A,FUNCTION1
- test SCBARRAY+1,0x88 jz clear_a
+ test SCB_TCL,0x88 jz clear_a
xor ACTIVE_B,A
- jmp complete
+ jmp test_immediate
clear_a:
xor ACTIVE_A,A
+test_immediate:
+ test SCB_CMDLEN,0xff jnz complete /* Immediate message complete */
+/*
+ * Pause the sequencer until the driver gets around to handling the command
+ * complete. This is so that any action that might require carefull timing
+ * with the completion of this command can occur.
+ */
+ mvi INTSTAT,IMMEDDONE
+ jmp start
complete:
- mov QOUTFIFO,SCBPTR
+ mov QOUTFIFO,SCB_TAG
mvi INTSTAT,CMDCMPLT
- jmp p_mesgin_done
+ jmp mesgin_done
-# If we have a residual count, interrupt and tell the host. Other
-# alternatives are to pause the sequencer on all command completes (yuck),
-# dma the resid directly to the host (slick, but a ton of instructions), or
-# have the sequencer pause itself when it encounters a non-zero resid
-# (unecessary pause just to flag the command -- yuck, but takes few instructions
-# and since it shouldn't happen that often is good enough for our purposes).
-resid:
- mvi INTSTAT,RESIDUAL
- jmp check_status
-
-# Is it an extended message? We only support the synchronous and wide data
-# transfer request messages, which will probably be in response to
-# WDTR or SDTR message outs from us. If it's not SDTR or WDTR, reject it -
-# apparently this can be done after any message in byte, according
-# to the SCSI-2 spec.
-#
-p_mesgin1:
- cmp A,1 jne p_mesgin2 # extended message code?
-
- mvi ARG_1 call inb_next # extended message length
- mvi A call inb_next # extended message code
+/*
+ * Is it an extended message? We only support the synchronous and wide data
+ * transfer request messages, which will probably be in response to
+ * WDTR or SDTR message outs from us. If it's not SDTR or WDTR, reject it -
+ * apparently this can be done after any message in byte, according
+ * to the SCSI-2 spec.
+ */
+mesgin_extended:
+ mvi ARG_1 call inb_next /* extended message length */
+ mvi REJBYTE_EXT call inb_next /* extended message code */
- cmp A,1 je p_mesginSDTR # Syncronous negotiation message
- cmp A,3 je p_mesginWDTR # Wide negotiation message
- jmp p_mesginN
+ cmp REJBYTE_EXT,MSG_SDTR je p_mesginSDTR
+ cmp REJBYTE_EXT,MSG_WDTR je p_mesginWDTR
+ jmp rej_mesgin
p_mesginWDTR:
- cmp ARG_1,2 jne p_mesginN # extended mesg length = 2
- mvi A call inb_next # Width of bus
- mvi INTSTAT,MSG_WDTR # let driver know
- test RETURN_1,0x80 jz p_mesgin_done# Do we need to send WDTR?
-
-# We didn't initiate the wide negotiation, so we must respond to the request
- and RETURN_1,0x7f # Clear the SEND_WDTR Flag
- or FLAGS,ACTIVE_MSG
- mvi DINDEX,MSG_START+0
- mvi MSG_START+0 call mk_wdtr # build WDTR message
- or SINDEX,0x10,SIGSTATE # turn on ATNO
- call scsisig
- jmp p_mesgin_done
+ cmp ARG_1,2 jne rej_mesgin /* extended mesg length=2 */
+ mvi ARG_1 call inb_next /* Width of bus */
+ mvi INTSTAT,WDTR_MSG /* let driver know */
+ test RETURN_1,0xff jz mesgin_done /* Do we need to send WDTR? */
+ cmp RETURN_1,SEND_REJ je rej_mesgin /*
+ * Bus width was too large
+ * Reject it.
+ */
+
+/* We didn't initiate the wide negotiation, so we must respond to the request */
+ and RETURN_1,0x7f /* Clear the SEND_WDTR Flag */
+ mvi DINDEX,MSG0
+ mvi MSG0 call mk_wdtr /* build WDTR message */
+ or SCSISIGO,ATNO /* turn on ATNO */
+ jmp mesgin_done
p_mesginSDTR:
- cmp ARG_1,3 jne p_mesginN # extended mesg length = 3
- mvi ARG_1 call inb_next # xfer period
- mvi A call inb_next # REQ/ACK offset
- mvi INTSTAT,MSG_SDTR # call driver to convert
-
- test RETURN_1,0xc0 jz p_mesgin_done# Do we need to mk_sdtr or rej?
- test RETURN_1,0x40 jnz p_mesginN # Requested SDTR too small - rej
- or FLAGS,ACTIVE_MSG
- mvi DINDEX, MSG_START+0
- mvi MSG_START+0 call mk_sdtr
- or SINDEX,0x10,SIGSTATE # turn on ATNO
- call scsisig
- jmp p_mesgin_done
-
-# Is it a disconnect message? Set a flag in the SCB to remind us
-# and await the bus going free.
-#
-p_mesgin2:
- cmp A,4 jne p_mesgin3 # disconnect code?
-
- or SCBARRAY+0,0x4 # set "disconnected" bit
- jmp p_mesgin_done
-
-# Save data pointers message? Copy working values into the SCB,
-# usually in preparation for a disconnect.
-#
-p_mesgin3:
- cmp A,2 jne p_mesgin4 # save data pointers code?
-
+ cmp ARG_1,3 jne rej_mesgin /* extended mesg length=3 */
+ mvi ARG_1 call inb_next /* xfer period */
+ mvi A call inb_next /* REQ/ACK offset */
+ mvi INTSTAT,SDTR_MSG /* call driver to convert */
+
+ test RETURN_1,0xff jz mesgin_done /* Do we need to mk_sdtr/rej */
+ cmp RETURN_1,SEND_REJ je rej_mesgin /*
+ * Requested SDTR too small
+ * Reject it.
+ */
+ clr ARG_1 /* Use the scratch ram rate */
+ mvi DINDEX, MSG0
+ mvi MSG0 call mk_sdtr
+ or SCSISIGO,ATNO /* turn on ATNO */
+ jmp mesgin_done
+
+/*
+ * Is it a disconnect message? Set a flag in the SCB to remind us
+ * and await the bus going free.
+ */
+mesgin_disconnect:
+ or SCB_CONTROL,DISCONNECTED
+ test FLAGS, PAGESCBS jz mesgin_done
+/*
+ * Link this SCB into the DISCONNECTED list. This list holds the
+ * candidates for paging out an SCB if one is needed for a new command.
+ * Modifying the disconnected list is a critical(pause dissabled) section.
+ */
+ mvi SCB_PREV, SCB_LIST_NULL
+ mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
+ mov SCB_NEXT, DISCONNECTED_SCBH
+ mov DISCONNECTED_SCBH, SCBPTR
+ cmp SCB_NEXT,SCB_LIST_NULL je linkdone
+ mov SCBPTR,SCB_NEXT
+ mov SCB_PREV,DISCONNECTED_SCBH
+ mov SCBPTR,DISCONNECTED_SCBH
+linkdone:
+ mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
+ jmp mesgin_done
+
+/*
+ * Save data pointers message? Copy working values into the SCB,
+ * usually in preparation for a disconnect.
+ */
+mesgin_sdptrs:
call sg_ram2scb
- jmp p_mesgin_done
-
-# Restore pointers message? Data pointers are recopied from the
-# SCB anyway at the start of any DMA operation, so the only thing
-# to copy is the scatter-gather values.
-#
-p_mesgin4:
- cmp A,3 jne p_mesgin5 # restore pointers code?
-
- call sg_scb2ram
- jmp p_mesgin_done
-
-# Identify message? For a reconnecting target, this tells us the lun
-# that the reconnection is for - find the correct SCB and switch to it,
-# clearing the "disconnected" bit so we don't "find" it by accident later.
-#
-p_mesgin5:
- test A,0x80 jz p_mesgin6 # identify message?
-
- test A,0x78 jnz p_mesginN # !DiscPriv|!LUNTAR|!Reserved
-
- and A,0x07 # lun in lower three bits
+ jmp mesgin_done
+
+/*
+ * Restore pointers message? Data pointers are recopied from the
+ * SCB anytime we enter a data phase for the first time, so all
+ * we need to do is clear the DPHASE flag and let the data phase
+ * code do the rest.
+ */
+mesgin_rdptrs:
+ and FLAGS,0xef /*
+ * !DPHASE we'll reload them
+ * the next time through
+ */
+ jmp mesgin_done
+
+/*
+ * Identify message? For a reconnecting target, this tells us the lun
+ * that the reconnection is for - find the correct SCB and switch to it,
+ * clearing the "disconnected" bit so we don't "find" it by accident later.
+ */
+mesgin_identify:
+ test A,0x78 jnz rej_mesgin /*!DiscPriv|!LUNTAR|!Reserved*/
+
+ and A,0x07 /* lun in lower three bits */
or SAVED_TCL,A,SELID
and SAVED_TCL,0xf7
- and A,0x08,SBLKCTL # B Channel??
+ and A,SELBUSB,SBLKCTL /* B Channel?? */
or SAVED_TCL,A
- call inb_last # ACK
- mov ALLZEROS call findSCB
+ call inb_last /* ACK */
+
+/*
+ * Here we "snoop" the bus looking for a SIMPLE QUEUE TAG message.
+ * If we get one, we use the tag returned to switch to find the proper
+ * SCB. With SCB paging, this requires using findSCB for both tagged
+ * and non-tagged transactions since the SCB may exist in any slot.
+ * If we're not using SCB paging, we can use the tag as the direct
+ * index to the SCB.
+ */
+ mvi ARG_1,SCB_LIST_NULL /* Default to no-tag */
+snoop_tag_loop:
+ test SSTAT1,BUSFREE jnz use_findSCB
+ test SSTAT1,REQINIT jz snoop_tag_loop
+ test SSTAT1,PHASEMIS jnz use_findSCB
+ mvi A call inb_first
+ cmp A,MSG_SIMPLE_TAG jne use_findSCB
+get_tag:
+ mvi ARG_1 call inb_next /* tag value */
+/*
+ * See if the tag is in range. The tag is < SCBCOUNT if we add
+ * the complement of SCBCOUNT to the incomming tag and there is
+ * no carry.
+ */
+ mov A,COMP_SCBCOUNT
+ add SINDEX,A,ARG_1
+ jc abort_tag
+
+/*
+ * Ensure that the SCB the tag points to is for an SCB transaction
+ * to the reconnecting target.
+ */
+ test FLAGS, PAGESCBS jz index_by_tag
+ call inb_last /* Ack Tag */
+use_findSCB:
+ mov ALLZEROS call findSCB /* Have to search */
setup_SCB:
- and SCBARRAY+0,0xfb # clear disconnect bit in SCB
- or FLAGS,IDENTIFY_SEEN # make note of IDENTIFY
-
- call sg_scb2ram # implied restore pointers
- # required on reselect
+ and SCB_CONTROL,0xfb /* clear disconnect bit in SCB */
+ or FLAGS,IDENTIFY_SEEN /* make note of IDENTIFY */
jmp ITloop
-get_tag:
- mvi A call inb_first
- cmp A,0x20 jne return # Simple Tag message?
- mvi A call inb_next
- call inb_last
- test A,0xf0 jnz abort_tag # Tag in range?
- mov SCBPTR,A
+index_by_tag:
+ mov SCBPTR,ARG_1
mov A,SAVED_TCL
- cmp SCBARRAY+1,A jne abort_tag
- test SCBARRAY+0,TAG_ENB jz abort_tag
- ret
-abort_tag:
- or SINDEX,0x10,SIGSTATE # turn on ATNO
- call scsisig
- mvi INTSTAT,ABORT_TAG # let driver know
- mvi 0xd call mk_mesg # ABORT TAG message
- ret
-
-# Message reject? Let the kernel driver handle this. If we have an
-# outstanding WDTR or SDTR negotiation, assume that it's a response from
-# the target selecting 8bit or asynchronous transfer, otherwise just ignore
-# it since we have no clue what it pertains to.
-#
-p_mesgin6:
- cmp A,7 jne p_mesgin7 # message reject code?
-
- mvi INTSTAT, MSG_REJECT
- jmp p_mesgin_done
-
-# [ ADD MORE MESSAGE HANDLING HERE ]
-#
-p_mesgin7:
-
-# We have no idea what this message in is, and there's no way
-# to pass it up to the kernel, so we issue a message reject and
-# hope for the best. Since we're now using manual PIO mode to
-# read in the message, there should no longer be a race condition
-# present when we assert ATN. In any case, rejection should be a
-# rare occurrence - signal the driver when it happens.
-#
-p_mesginN:
- or SINDEX,0x10,SIGSTATE # turn on ATNO
- call scsisig
- mvi INTSTAT,SEND_REJECT # let driver know
-
- mvi 0x7 call mk_mesg # MESSAGE REJECT message
-
-p_mesgin_done:
- call inb_last # ack & turn auto PIO back on
- jmp ITloop
-
+ cmp SCB_TCL,A jne abort_tag
+ test SCB_CONTROL,TAG_ENB jz abort_tag
+ call inb_last /* Ack Successful tag */
+ jmp setup_SCB
-# Bus free phase. It might be useful to interrupt the device
-# driver if we aren't expecting this. For now, make sure that
-# ATN isn't being asserted and look for a new command.
-#
+abort_tag:
+ or SCSISIGO,ATNO /* turn on ATNO */
+ mvi INTSTAT,ABORT_TAG /* let driver know */
+ mvi MSG_ABORT_TAG call mk_mesg /* ABORT TAG message */
+ jmp mesgin_done
+
+/*
+ * Message reject? Let the kernel driver handle this. If we have an
+ * outstanding WDTR or SDTR negotiation, assume that it's a response from
+ * the target selecting 8bit or asynchronous transfer, otherwise just ignore
+ * it since we have no clue what it pertains to.
+ */
+mesgin_reject:
+ mvi INTSTAT, REJECT_MSG
+ jmp mesgin_done
+
+/*
+ * [ ADD MORE MESSAGE HANDLING HERE ]
+ */
+
+/*
+ * Bus free phase. It might be useful to interrupt the device
+ * driver if we aren't expecting this. For now, make sure that
+ * ATN isn't being asserted and look for a new command.
+ */
p_busfree:
- mvi CLRSINT1,0x40 # CLRATNO
- clr SIGSTATE
+ mvi CLRSINT1,CLRATNO
+ clr LASTPHASE
+
+/*
+ * if this is an immediate command, perform a psuedo command complete to
+ * notify the driver.
+ */
+ test SCB_CMDLEN,0xff jz status_ok
jmp start
-# Instead of a generic bcopy routine that requires an argument, we unroll
-# the two cases that are actually used, and call them explicitly. This
-# not only reduces the overhead of doing a bcopy by 2/3rds, but ends up
-# saving space in the program since you don't have to put the argument
-# into the accumulator before the call. Both functions expect DINDEX to
-# contain the destination address and SINDEX to contain the source
-# address.
-bcopy_3:
- mov DINDIR,SINDIR
- mov DINDIR,SINDIR
- mov DINDIR,SINDIR ret
-
-bcopy_4:
- mov DINDIR,SINDIR
- mov DINDIR,SINDIR
- mov DINDIR,SINDIR
- mov DINDIR,SINDIR ret
-
-bcopy_3_dfdat:
- mov DINDIR,DFDAT
- mov DINDIR,DFDAT
- mov DINDIR,DFDAT ret
-
-bcopy_4_dfdat:
- mov DINDIR,DFDAT
- mov DINDIR,DFDAT
- mov DINDIR,DFDAT
- mov DINDIR,DFDAT ret
-
-# Locking the driver out, build a one-byte message passed in SINDEX
-# if there is no active message already. SINDEX is returned intact.
-#
+/*
+ * Locking the driver out, build a one-byte message passed in SINDEX
+ * if there is no active message already. SINDEX is returned intact.
+ */
mk_mesg:
- mvi SEQCTL,0x50 # PAUSEDIS|FASTMODE
- test FLAGS,ACTIVE_MSG jnz mk_mesg1 # active message?
-
- or FLAGS,ACTIVE_MSG # if not, there is now
- mvi MSG_LEN,1 # length = 1
- mov MSG_START+0,SINDEX # 1-byte message
+ mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
+ test MSG_LEN,0xff jz mk_mesg1 /* Should always succeed */
+
+ /*
+ * Hmmm. For some reason the mesg buffer is in use.
+ * Tell the driver. It should look at SINDEX to find
+ * out what we wanted to use the buffer for and resolve
+ * the conflict.
+ */
+ mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
+ mvi INTSTAT,MSG_BUFFER_BUSY
mk_mesg1:
- mvi SEQCTL,0x10 ret # !PAUSEDIS|FASTMODE
-
-# Carefully read data in Automatic PIO mode. I first tried this using
-# Manual PIO mode, but it gave me continual underrun errors, probably
-# indicating that I did something wrong, but I feel more secure leaving
-# Automatic PIO on all the time.
-#
-# According to Adaptec's documentation, an ACK is not sent on input from
-# the target until SCSIDATL is read from. So we wait until SCSIDATL is
-# latched (the usual way), then read the data byte directly off the bus
-# using SCSIBUSL. When we have pulled the ATN line, or we just want to
-# acknowledge the byte, then we do a dummy read from SCISDATL. The SCSI
-# spec guarantees that the target will hold the data byte on the bus until
-# we send our ACK.
-#
-# The assumption here is that these are called in a particular sequence,
-# and that REQ is already set when inb_first is called. inb_{first,next}
-# use the same calling convention as inb.
-#
-inb_first:
- clr STCNT+2
- clr STCNT+1
- mov DINDEX,SINDEX
- mov DINDIR,SCSIBUSL ret # read byte directly from bus
+ mvi MSG_LEN,1 /* length = 1 */
+ mov MSG0,SINDEX /* 1-byte message */
+ mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
+
+/*
+ * Functions to read data in Automatic PIO mode.
+ *
+ * According to Adaptec's documentation, an ACK is not sent on input from
+ * the target until SCSIDATL is read from. So we wait until SCSIDATL is
+ * latched (the usual way), then read the data byte directly off the bus
+ * using SCSIBUSL. When we have pulled the ATN line, or we just want to
+ * acknowledge the byte, then we do a dummy read from SCISDATL. The SCSI
+ * spec guarantees that the target will hold the data byte on the bus until
+ * we send our ACK.
+ *
+ * The assumption here is that these are called in a particular sequence,
+ * and that REQ is already set when inb_first is called. inb_{first,next}
+ * use the same calling convention as inb.
+ */
inb_next:
- mov DINDEX,SINDEX # save SINDEX
-
- mvi STCNT+0,1 # xfer one byte
- mov NONE,SCSIDATL # dummy read from latch to ACK
-inb_next1:
- test SSTAT0,0x4 jz inb_next1 # SDONE
-inb_next2:
- test SSTAT0,0x2 jz inb_next2 # SPIORDY - wait for next byte
- mov DINDIR,SCSIBUSL ret # read byte directly from bus
-
+ or CLRSINT0, CLRSPIORDY
+ mov NONE,SCSIDATL /*dummy read from latch to ACK*/
+inb_next_wait:
+ test SSTAT1,PHASEMIS jnz mesgin_phasemis
+ test SSTAT0,SPIORDY jz inb_next_wait /* wait for next byte */
+inb_first:
+ mov DINDEX,SINDEX
+ mov DINDIR,SCSIBUSL ret /*read byte directly from bus*/
inb_last:
- mvi STCNT+0,1 # ACK with dummy read
- mov NONE,SCSIDATL
-inb_last1:
- test SSTAT0,0x4 jz inb_last1 # wait for completion
- ret
+ mov NONE,SCSIDATL ret /*dummy read from latch to ACK*/
-# DMA data transfer. HADDR and HCNT must be loaded first, and
-# SINDEX should contain the value to load DFCNTRL with - 0x3d for
-# host->scsi, or 0x39 for scsi->host. The SCSI channel is cleared
-# during initialization.
-#
+mesgin_phasemis:
+/*
+ * We expected to receive another byte, but the target changed phase
+ */
+ mvi INTSTAT, MSGIN_PHASEMIS
+ jmp ITloop
+
+/*
+ * DMA data transfer. HADDR and HCNT must be loaded first, and
+ * SINDEX should contain the value to load DFCNTRL with - 0x3d for
+ * host->scsi, or 0x39 for scsi->host. The SCSI channel is cleared
+ * during initialization.
+ */
dma:
mov DFCNTRL,SINDEX
dma1:
-dma2:
- test SSTAT0,0x1 jnz dma3 # DMADONE
- test SSTAT1,0x10 jz dma1 # PHASEMIS, ie. underrun
-
-# We will be "done" DMAing when the transfer count goes to zero, or
-# the target changes the phase (in light of this, it makes sense that
-# the DMA circuitry doesn't ACK when PHASEMIS is active). If we are
-# doing a SCSI->Host transfer, the data FIFO should be flushed auto-
-# magically on STCNT=0 or a phase change, so just wait for FIFO empty
-# status.
-#
+ test SSTAT0,DMADONE jnz dma3
+ test SSTAT1,PHASEMIS jz dma1 /* ie. underrun */
+
+/*
+ * We will be "done" DMAing when the transfer count goes to zero, or
+ * the target changes the phase (in light of this, it makes sense that
+ * the DMA circuitry doesn't ACK when PHASEMIS is active). If we are
+ * doing a SCSI->Host transfer, the data FIFO should be flushed auto-
+ * magically on STCNT=0 or a phase change, so just wait for FIFO empty
+ * status.
+ */
dma3:
- test SINDEX,0x4 jnz dma5 # DIRECTION
+ test SINDEX,DIRECTION jnz dma5
dma4:
- test DFSTATUS,0x1 jz dma4 # !FIFOEMP
+ test DFSTATUS,FIFOEMP jz dma4
-# Now shut the DMA enables off, and copy STCNT (ie. the underrun
-# amount, if any) to the SCB registers; SG_COUNT will get copied to
-# the SCB's residual S/G count field after sg_advance is called. Make
-# sure that the DMA enables are actually off first lest we get an ILLSADDR.
-#
+/*
+ * Now shut the DMA enables off and make sure that the DMA enables are
+ * actually off first lest we get an ILLSADDR.
+ */
dma5:
- clr DFCNTRL # disable DMA
+ /* disable DMA, but maintain WIDEODD */
+ and DFCNTRL,WIDEODD
dma6:
- test DFCNTRL,0x38 jnz dma6 # SCSIENACK|SDMAENACK|HDMAENACK
-
- mvi DINDEX,SCBARRAY+15
- mvi STCNT call bcopy_3
-
- ret
-
-dma_finish:
- test DFSTATUS,0x8 jz dma_finish # HDONE
+ test DFCNTRL,0x38 jnz dma6 /* SCSIENACK|SDMAENACK|HDMAENACK */
- clr DFCNTRL # disable DMA
-dma_finish2:
- test DFCNTRL,0x8 jnz dma_finish2 # HDMAENACK
ret
-# Common SCSI initialization for selection and reselection. Expects
-# the target SCSI ID to be in the upper four bits of SINDEX, and A's
-# contents are stomped on return.
-#
+/*
+ * Common SCSI initialization for selection and reselection. Expects
+ * the target SCSI ID to be in the upper four bits of SINDEX, and A's
+ * contents are stomped on return.
+ */
initialize_scsiid:
- and SINDEX,0xf0 # Get target ID
+ and SINDEX,0xf0 /* Get target ID */
and A,0x0f,SCSIID
or SINDEX,A
mov SCSIID,SINDEX ret
-initialize_for_target:
-# Turn on Automatic PIO mode now, before we expect to see a REQ
-# from the target. It shouldn't hurt anything to leave it on. Set
-# CLRCHN here before the target has entered a data transfer mode -
-# with synchronous SCSI, if you do it later, you blow away some
-# data in the SCSI FIFO that the target has already sent to you.
-#
- clr SIGSTATE
-
- mvi SXFRCTL0,0x8a # DFON|SPIOEN|CLRCHN
-
-# Initialize scatter-gather pointers by setting up the working copy
-# in scratch RAM.
-#
- call sg_scb2ram
-
-# Initialize SCSIRATE with the appropriate value for this target.
-#
- call ndx_dtr
- mov SCSIRATE,SINDIR ret
-
-# Assert that if we've been reselected, then we've seen an IDENTIFY
-# message.
-#
+/*
+ * Assert that if we've been reselected, then we've seen an IDENTIFY
+ * message.
+ */
assert:
- test FLAGS,RESELECTED jz return # reselected?
- test FLAGS,IDENTIFY_SEEN jnz return # seen IDENTIFY?
-
- mvi INTSTAT,NO_IDENT ret # no - cause a kernel panic
-
-# Find out if disconnection is ok from the information the BIOS has left
-# us. The tcl from SCBARRAY+1 should be in SINDEX; A will
-# contain either 0x40 (disconnection ok) or 0x00 (disconnection not ok)
-# on exit.
-#
-# To allow for wide or twin busses, we check the upper bit of the target ID
-# and the channel ID and look at the appropriate disconnect register.
-#
-disconnect:
- and FUNCTION1,0x70,SINDEX # strip off extra just in case
- mov A,FUNCTION1
- test SINDEX, 0x88 jz disconnect_a
-
- test DISC_DSB_B,A jz disconnect1 # bit nonzero if DISabled
- clr A ret
-
-disconnect_a:
- test DISC_DSB_A,A jz disconnect1 # bit nonzero if DISabled
- clr A ret
-
-disconnect1:
- mvi A,0x40 ret
-
-# Locate the SCB matching the target ID/channel/lun in SAVED_TCL and switch
-# the SCB to it. Have the kernel print a warning message if it can't be
-# found, and generate an ABORT message to the target. SINDEX should be
-# cleared on call.
-#
+ test FLAGS,RESELECTED jz return /* reselected? */
+ test FLAGS,IDENTIFY_SEEN jnz return /* seen IDENTIFY? */
+
+ mvi INTSTAT,NO_IDENT ret /* no - cause a kernel panic */
+
+/*
+ * Locate the SCB matching the target ID/channel/lun in SAVED_TCL, and the tag
+ * value in ARG_1. If ARG_1 == SCB_LIST_NULL, we're looking for a non-tagged
+ * SCB. Have the kernel print a warning message if it can't be found, and
+ * generate an ABORT/ABORT_TAG message to the target. SINDEX should be
+ * cleared on call.
+ */
findSCB:
mov A,SAVED_TCL
- mov SCBPTR,SINDEX # switch to new SCB
- cmp SCBARRAY+1,A jne findSCB1 # target ID/channel/lun match?
- test SCBARRAY+0,0x4 jz findSCB1 # should be disconnected
- test SCBARRAY+0,TAG_ENB jnz get_tag
- ret
+ mov SCBPTR,SINDEX /* switch to next SCB */
+ mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
+ cmp SCB_TCL,A jne findSCB1 /* target ID/channel/lun match? */
+ test SCB_CONTROL,DISCONNECTED jz findSCB1 /*should be disconnected*/
+ test SCB_CONTROL,TAG_ENB jnz findTaggedSCB
+ cmp ARG_1,SCB_LIST_NULL je foundSCB
+ jmp findSCB1
+findTaggedSCB:
+ mov A, ARG_1 /* Tag passed in ARG_1 */
+ cmp SCB_TAG,A jne findSCB1 /* Found it? */
+foundSCB:
+ test FLAGS,PAGESCBS jz foundSCB_ret
+/* Remove this SCB from the disconnection list */
+ cmp SCB_NEXT,SCB_LIST_NULL je unlink_prev
+ mov SAVED_LINKPTR, SCB_PREV
+ mov SCBPTR, SCB_NEXT
+ mov SCB_PREV, SAVED_LINKPTR
+ mov SCBPTR, SINDEX
+unlink_prev:
+ cmp SCB_PREV,SCB_LIST_NULL je rHead/* At the head of the list */
+ mov SAVED_LINKPTR, SCB_NEXT
+ mov SCBPTR, SCB_PREV
+ mov SCB_NEXT, SAVED_LINKPTR
+ mov SCBPTR, SINDEX
+ mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
+rHead:
+ mov DISCONNECTED_SCBH,SCB_NEXT
+foundSCB_ret:
+ mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
findSCB1:
+ mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
inc SINDEX
mov A,SCBCOUNT
cmp SINDEX,A jne findSCB
- mvi INTSTAT,NO_MATCH # not found - signal kernel
- mvi 0x6 call mk_mesg # ABORT message
-
- or SINDEX,0x10,SIGSTATE # assert ATNO
- call scsisig
- ret
+ mvi INTSTAT,NO_MATCH /* not found - signal kernel */
+ cmp RETURN_1,SCB_PAGEDIN je return
+ or SCSISIGO,ATNO /* assert ATNO */
+ cmp ARG_1,SCB_LIST_NULL jne find_abort_tag
+ mvi MSG_ABORT call mk_mesg
+ jmp ITloop
+find_abort_tag:
+ mvi MSG_ABORT_TAG call mk_mesg
+ jmp ITloop
-# Make a working copy of the scatter-gather parameters in the SCB.
-#
+/*
+ * Make a working copy of the scatter-gather parameters from the SCB.
+ */
sg_scb2ram:
- mov SG_COUNT,SCBARRAY+2
-
- mvi DINDEX,SG_NEXT
- mvi SCBARRAY+3 call bcopy_4
-
- mvi SG_NOLOAD,0x80
- test SCBARRAY+0,0x10 jnz return # don't reload s/g?
- clr SG_NOLOAD ret
-
-# Copying RAM values back to SCB, for Save Data Pointers message.
-#
+ mov HADDR0, SCB_DATAPTR0
+ mov HADDR1, SCB_DATAPTR1
+ mov HADDR2, SCB_DATAPTR2
+ mov HADDR3, SCB_DATAPTR3
+ mov HCNT0, SCB_DATACNT0
+ mov HCNT1, SCB_DATACNT1
+ mov HCNT2, SCB_DATACNT2
+
+ mov STCNT0, HCNT0
+ mov STCNT1, HCNT1
+ mov STCNT2, HCNT2
+
+ mov SG_COUNT,SCB_SGCOUNT
+
+ mov SG_NEXT0, SCB_SGPTR0
+ mov SG_NEXT1, SCB_SGPTR1
+ mov SG_NEXT2, SCB_SGPTR2
+ mov SG_NEXT3, SCB_SGPTR3 ret
+
+/*
+ * Copying RAM values back to SCB, for Save Data Pointers message, but
+ * only if we've actually been into a data phase to change them. This
+ * protects against bogus data in scratch ram and the residual counts
+ * since they are only initialized when we go into data_in or data_out.
+ */
sg_ram2scb:
- mov SCBARRAY+2,SG_COUNT
+ test FLAGS, DPHASE jz return
+ mov SCB_SGCOUNT,SG_COUNT
- mvi DINDEX,SCBARRAY+3
- mvi SG_NEXT call bcopy_4
-
- and SCBARRAY+0,0xef,SCBARRAY+0
- test SG_NOLOAD,0x80 jz return # reload s/g?
- or SCBARRAY+0,SG_LOAD ret
-
-# Load a struct scatter if needed and set up the data address and
-# length. If the working value of the SG count is nonzero, then
-# we need to load a new set of values.
-#
-# This, like the above DMA, assumes a little-endian host data storage.
-#
-sg_load:
- test SG_COUNT,0xff jz return # SG being used?
- test SG_NOLOAD,0x80 jnz return # don't reload s/g?
-
- clr HCNT+2
- clr HCNT+1
- mvi HCNT+0,SG_SIZEOF
-
- mvi DINDEX,HADDR
- mvi SG_NEXT call bcopy_4
-
- mvi DFCNTRL,0xd # HDMAEN|DIRECTION|FIFORESET
-
-# Wait for DMA from host memory to data FIFO to complete, then disable
-# DMA and wait for it to acknowledge that it's off.
-#
-
- call dma_finish
-
-# Copy data from FIFO into SCB data pointer and data count. This assumes
-# that the struct scatterlist has this structure (this and sizeof(struct
-# scatterlist) == 12 are asserted in aic7xxx.c):
-#
-# struct scatterlist {
-# char *address; /* four bytes, little-endian order */
-# ... /* four bytes, ignored */
-# unsigned short length; /* two bytes, little-endian order */
-# }
-#
-
-# Not in FreeBSD. the scatter list entry is only 8 bytes.
-#
-# struct ahc_dma_seg {
-# physaddr addr; /* four bytes, little-endian order */
-# long len; /* four bytes, little endian order */
-# };
-#
-
- mvi DINDEX, SCBARRAY+19
- call bcopy_4_dfdat
-
-# For Linux, we must throw away four bytes since there is a 32bit gap
-# in the middle of a struct scatterlist
-# mov NONE,DFDAT
-# mov NONE,DFDAT
-# mov NONE,DFDAT
-# mov NONE,DFDAT
-
- call bcopy_3_dfdat #Only support 24 bit length.
- ret
-
-# Advance the scatter-gather pointers only IF NEEDED. If SG is enabled,
-# and the SCSI transfer count is zero (note that this should be called
-# right after a DMA finishes), then move the working copies of the SG
-# pointer/length along. If the SCSI transfer count is not zero, then
-# presumably the target is disconnecting - do not reload the SG values
-# next time.
-#
-sg_advance:
- test SG_COUNT,0xff jz return # s/g enabled?
-
- test STCNT+0,0xff jnz sg_advance1 # SCSI transfer count nonzero?
- test STCNT+1,0xff jnz sg_advance1
- test STCNT+2,0xff jnz sg_advance1
-
- clr SG_NOLOAD # reload s/g next time
- dec SG_COUNT # one less segment to go
-
- clr A # add sizeof(struct scatter)
- add SG_NEXT+0,SG_SIZEOF,SG_NEXT+0
- adc SG_NEXT+1,A,SG_NEXT+1
- adc SG_NEXT+2,A,SG_NEXT+2
- adc SG_NEXT+3,A,SG_NEXT+3 ret
-
-sg_advance1:
- mvi SG_NOLOAD,0x80 ret # don't reload s/g next time
-
-# Add the array base SYNCNEG to the target offset (the target address
-# is in SCSIID), and return the result in SINDEX. The accumulator
-# contains the 3->8 decoding of the target ID on return.
-#
+ mov SCB_SGPTR0,SG_NEXT0
+ mov SCB_SGPTR1,SG_NEXT1
+ mov SCB_SGPTR2,SG_NEXT2
+ mov SCB_SGPTR3,SG_NEXT3
+
+ mov SCB_DATAPTR0,SHADDR0
+ mov SCB_DATAPTR1,SHADDR1
+ mov SCB_DATAPTR2,SHADDR2
+ mov SCB_DATAPTR3,SHADDR3
+
+/*
+ * Use the residual number since STCNT is corrupted by any message transfer
+ */
+ mov SCB_DATACNT0,SCB_RESID_DCNT0
+ mov SCB_DATACNT1,SCB_RESID_DCNT1
+ mov SCB_DATACNT2,SCB_RESID_DCNT2 ret
+
+/*
+ * Add the array base TARG_SCRATCH to the target offset (the target address
+ * is in SCSIID), and return the result in SINDEX. The accumulator
+ * contains the 3->8 decoding of the target ID on return.
+ */
ndx_dtr:
shr A,SCSIID,4
- test SBLKCTL,0x08 jz ndx_dtr_2
- or A,0x08 # Channel B entries add 8
+ test SBLKCTL,SELBUSB jz ndx_dtr_2
+ or A,0x08 /* Channel B entries add 8 */
ndx_dtr_2:
- add SINDEX,SYNCNEG,A
-
- and FUNCTION1,0x70,SCSIID # 3-bit target address decode
- mov A,FUNCTION1 ret
-
-# If we need to negotiate transfer parameters, build the WDTR or SDTR message
-# starting at the address passed in SINDEX. DINDEX is modified on return.
-# The SCSI-II spec requires that Wide negotiation occur first and you can
-# only negotiat one or the other at a time otherwise in the event of a message
-# reject, you wouldn't be able to tell which message was the culpret.
-#
+ add SINDEX,TARG_SCRATCH,A ret
+
+/*
+ * If we need to negotiate transfer parameters, build the WDTR or SDTR message
+ * starting at the address passed in SINDEX. DINDEX is modified on return.
+ * The SCSI-II spec requires that Wide negotiation occur first and you can
+ * only negotiat one or the other at a time otherwise in the event of a message
+ * reject, you wouldn't be able to tell which message was the culpret.
+ */
mk_dtr:
- test SCBARRAY+0,0xc0 jz return # NEEDWDTR|NEEDSDTR
- test SCBARRAY+0,NEEDWDTR jnz mk_wdtr_16bit
- or FLAGS, MAX_SYNC # Force an offset of 15
+ test SCB_CONTROL,NEEDWDTR jnz mk_wdtr_16bit
+ mvi ARG_1, MAXOFFSET /* Force an offset of 15 or 8 if WIDE */
mk_sdtr:
- mvi DINDIR,1 # extended message
- mvi DINDIR,3 # extended message length = 3
- mvi DINDIR,1 # SDTR code
+ mvi DINDIR,1 /* extended message */
+ mvi DINDIR,3 /* extended message length = 3 */
+ mvi DINDIR,1 /* SDTR code */
call sdtr_to_rate
- mov DINDIR,RETURN_1 # REQ/ACK transfer period
- test FLAGS, MAX_SYNC jnz mk_sdtr_max_sync
- and DINDIR,0xf,SINDIR # Sync Offset
+ mov DINDIR,RETURN_1 /* REQ/ACK transfer period */
+ cmp ARG_1, MAXOFFSET je mk_sdtr_max_offset
+ and DINDIR,0x0f,SINDIR /* Sync Offset */
mk_sdtr_done:
- add MSG_LEN,-MSG_START+0,DINDEX ret # update message length
+ add MSG_LEN,COMP_MSG0,DINDEX ret /* update message length */
+
+mk_sdtr_max_offset:
+/*
+ * We're initiating sync negotiation, so request the max offset we can (15 or 8)
+ */
+ /* Talking to a WIDE device? */
+ test SCSIRATE, WIDEXFER jnz wmax_offset
+ mvi DINDIR, MAX_OFFSET_8BIT
+ jmp mk_sdtr_done
-mk_sdtr_max_sync:
-# We're initiating sync negotiation, so request the max offset we can (15)
- mvi DINDIR, 0x0f
- xor FLAGS, MAX_SYNC
+wmax_offset:
+ mvi DINDIR, MAX_OFFSET_16BIT
jmp mk_sdtr_done
mk_wdtr_16bit:
mvi ARG_1,BUS_16_BIT
mk_wdtr:
- mvi DINDIR,1 # extended message
- mvi DINDIR,2 # extended message length = 2
- mvi DINDIR,3 # WDTR code
- mov DINDIR,ARG_1 # bus width
+ mvi DINDIR,1 /* extended message */
+ mvi DINDIR,2 /* extended message length = 2 */
+ mvi DINDIR,3 /* WDTR code */
+ mov DINDIR,ARG_1 /* bus width */
- add MSG_LEN,-MSG_START+0,DINDEX ret # update message length
+ add MSG_LEN,COMP_MSG0,DINDEX ret /* update message length */
-# Set SCSI bus control signal state. This also saves the last-written
-# value into a location where the higher-level driver can read it - if
-# it has to send an ABORT or RESET message, then it needs to know this
-# so it can assert ATN without upsetting SCSISIGO. The new value is
-# expected in SINDEX. Change the actual state last to avoid contention
-# from the driver.
-#
-scsisig:
- mov SIGSTATE,SINDEX
- mov SCSISIGO,SINDEX ret
-
sdtr_to_rate:
- call ndx_dtr # index scratch space for target
+ call ndx_dtr /* index scratch space for target */
shr A,SINDIR,0x4
- dec SINDEX #Preserve SINDEX
+ dec SINDEX /* Preserve SINDEX */
and A,0x7
clr RETURN_1
sdtr_to_rate_loop:
test A,0x0f jz sdtr_to_rate_done
- add RETURN_1,0x18
+ add RETURN_1,0x19
dec A
jmp sdtr_to_rate_loop
sdtr_to_rate_done:
shr RETURN_1,0x2
- add RETURN_1,0x18 ret
-
+ add RETURN_1,0x19
+ test SXFRCTL0,ULTRAEN jz return
+ shr RETURN_1,0x1
return:
ret
diff --git a/sys/dev/microcode/aic7xxx/aic7xxx_asm.c b/sys/dev/microcode/aic7xxx/aic7xxx_asm.c
index e2d2c3dd6e5..5e6bddb4b45 100644
--- a/sys/dev/microcode/aic7xxx/aic7xxx_asm.c
+++ b/sys/dev/microcode/aic7xxx/aic7xxx_asm.c
@@ -43,12 +43,13 @@
* are token separators.
*
*-M*************************************************************************/
-static char id[] = "$Id: aic7xxx_asm.c,v 1.2 1996/04/29 19:30:50 christos Exp $";
+static char id[] = "$Id: aic7xxx_asm.c,v 1.3 1996/05/16 03:51:48 mycroft Exp $";
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#define MEMORY 448
#define MAXLINE 1024
@@ -67,45 +68,17 @@ static char id[] = "$Id: aic7xxx_asm.c,v 1.2 1996/04/29 19:30:50 christos Exp $"
int debug;
int lineno, LC;
char *filename;
-FILE *ifp, *ofp;
unsigned char M[MEMORY][4];
-typedef struct sym_t {
- struct sym_t *next; /* MUST BE FIRST */
- char *name;
- int value;
- int npatch;
- int *patch;
-} sym_t;
-
-void error __P((char *));
-void *Malloc __P((size_t));
-void *Realloc __P((void *, size_t));
-char *Strdup __P((const char *));
-
-void define __P((char *, int));
-sym_t *lookup __P((char *));
-void patch __P((sym_t *, int));
-void backpatch __P((void));
-void output __P((FILE *));
-char **getl __P((int *));
-int eval_operand __P((char **, int));
-int eval_sdi __P((char **, int));
-int eval_addr __P((char **, int));
-int crack __P((char **, int));
-void assemble __P((void));
-
-void
-error(s)
- char *s;
+void
+error(char *s)
{
fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno);
exit(EXIT_FAILURE);
}
void *
-Malloc(size)
- size_t size;
+Malloc(size_t size)
{
void *p = malloc(size);
if (!p)
@@ -114,9 +87,7 @@ Malloc(size)
}
void *
-Realloc(ptr, size)
- void *ptr;
- size_t size;
+Realloc(void *ptr, size_t size)
{
void *p = realloc(ptr, size);
if (!p)
@@ -125,21 +96,25 @@ Realloc(ptr, size)
}
char *
-Strdup(s)
- const char *s;
+Strdup(char *s)
{
- size_t l = strlen(s) + 1;
- char *p = Malloc(l);
- memcpy(p, s, l);
+ char *p = (char *)Malloc(strlen(s) + 1);
+ strcpy(p, s);
return(p);
}
+typedef struct sym_t {
+ struct sym_t *next; /* MUST BE FIRST */
+ char *name;
+ int value;
+ int npatch;
+ int *patch;
+} sym_t;
+
sym_t *head;
void
-define(name, value)
- char *name;
- int value;
+define(char *name, int value)
{
sym_t *p, *q;
@@ -166,8 +141,7 @@ define(name, value)
}
sym_t *
-lookup(name)
- char *name;
+lookup(char *name)
{
sym_t *p;
@@ -177,10 +151,8 @@ lookup(name)
return(NULL);
}
-void
-patch(p, location)
- sym_t *p;
- int location;
+void
+patch(sym_t *p, int location)
{
p->npatch += 1;
p->patch = (int *)Realloc(p->patch, p->npatch * sizeof(int *));
@@ -188,7 +160,7 @@ patch(p, location)
p->patch[p->npatch - 1] = location;
}
-void backpatch()
+void backpatch(void)
{
int i;
sym_t *p;
@@ -228,8 +200,7 @@ void backpatch()
* since the sequencer RAM is loaded that way.
*/
void
-output(fp)
- FILE *fp;
+output(FILE *fp)
{
int i;
@@ -243,8 +214,7 @@ output(fp)
}
char **
-getl(n)
- int *n;
+getl(int *n)
{
int i;
char *p, *quote;
@@ -253,7 +223,7 @@ getl(n)
i = 0;
- while (fgets(buf, sizeof(buf), ifp)) {
+ while (fgets(buf, sizeof(buf), stdin)) {
lineno += 1;
@@ -274,7 +244,7 @@ rescan:
else
error("too many tokens");
if (quote) {
- quote++;
+ quote++;
p = strchr(quote, '\"');
if (!p)
error("unterminated string constant");
@@ -286,7 +256,7 @@ rescan:
else
error("too many tokens");
goto rescan;
- }
+ }
if (i) {
*n = i;
return(a);
@@ -366,10 +336,8 @@ struct {
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
-int
-eval_operand(a, spec)
- char **a;
- int spec;
+int
+eval_operand(char **a, int spec)
{
int i;
unsigned int want = spec & (LO|LA|LX);
@@ -405,9 +373,7 @@ eval_operand(a, spec)
}
int
-eval_sdi(a, spec)
- char **a;
- int spec;
+eval_sdi(char **a, int spec)
{
sym_t *p;
unsigned val;
@@ -477,9 +443,7 @@ eval_sdi(a, spec)
}
int
-eval_addr(a, spec)
- char **a;
- int spec;
+eval_addr(char **a, int spec)
{
sym_t *p;
@@ -504,9 +468,7 @@ eval_addr(a, spec)
}
int
-crack(a, n)
- char **a;
- int n;
+crack(char **a, int n)
{
int i;
int I_imm, I_addr;
@@ -574,7 +536,7 @@ crack(a, n)
#undef A
void
-assemble()
+assemble(FILE *ofile)
{
int n;
char **a;
@@ -597,7 +559,7 @@ assemble()
continue;
if (n == 3 && !strcmp("VERSION", *a))
- fprintf(ofp, "#define %s \"%s\"\n", a[1], a[2]);
+ fprintf(ofile, "#define %s \"%s\"\n", a[1], a[2]);
else {
if (n == 3 && !strcmp("=", a[1]))
define(*a, strtol(a[2], NULL, 0));
@@ -607,7 +569,7 @@ assemble()
}
backpatch();
- output(ofp);
+ output(ofile);
if (debug)
output(stderr);
@@ -615,12 +577,15 @@ assemble()
int
main(int argc, char **argv)
-{ int my_version_print_flag;
+{
int c;
+ int pid;
+ int ifile;
+ FILE *ofile;
+ int fd[2];
- my_version_print_flag=0;
-
- while ((c = getopt(argc, argv, "dho:vD")) != EOF) {
+ ofile = NULL;
+ while ((c = getopt(argc, argv, "dho:vD:")) != EOF) {
switch (c) {
case 'd':
debug = !0;
@@ -637,23 +602,20 @@ main(int argc, char **argv)
break;
}
case 'o':
- ofp = fopen(optarg, "w");
- if (!ofp) {
+
+ if ((ofile = fopen(optarg, "w")) == NULL) {
perror(optarg);
exit(EXIT_FAILURE);
}
break;
case 'h':
- printf("usage: %s [-d] [-Dname] [-ooutput] input\n",
+ printf("usage: %s [-d] [-Dname] [-ooutput] input\n",
*argv);
exit(EXIT_SUCCESS);
break;
case 'v':
- if (!my_version_print_flag)
- { printf("%s\n",id);
-
- my_version_print_flag=1;
- }
+ printf("%s\n", id);
+ exit(EXIT_SUCCESS);
break;
default:
exit(EXIT_FAILURE);
@@ -662,28 +624,62 @@ main(int argc, char **argv)
}
if (argc - optind != 1) {
- if (my_version_print_flag)
- { exit(EXIT_SUCCESS);
- }
fprintf(stderr, "%s: must have one input file\n", *argv);
exit(EXIT_FAILURE);
}
filename = argv[optind];
- ifp = fopen(filename, "r");
- if (!ifp) {
+
+ if ((ifile = open(filename, O_RDONLY)) < 0) {
perror(filename);
exit(EXIT_FAILURE);
}
- if (!ofp) {
- ofp = fopen(ADOTOUT, "w");
- if (!ofp) {
+ if (!ofile) {
+ if ((ofile = fopen(ADOTOUT, "w")) == NULL) {
perror(ADOTOUT);
exit(EXIT_FAILURE);
}
}
- assemble();
- exit(EXIT_SUCCESS);
+ if (pipe(fd) < 0) {
+ perror("pipe failed");
+ exit(1);
+ }
+
+ if ((pid = fork()) < 0 ) {
+ perror("fork failed");
+ exit(1);
+ }
+ else if (pid > 0) { /* Parent */
+ close(fd[1]); /* Close write end */
+ if (fd[0] != STDIN_FILENO) {
+ if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO) {
+ perror("dup2 error on stdin");
+ exit(EXIT_FAILURE);
+ }
+ close(fd[0]);
+ }
+ assemble(ofile);
+ exit(EXIT_SUCCESS);
+ }
+ else { /* Child */
+ close(fd[0]); /* Close Read end */
+ if (fd[1] != STDOUT_FILENO) {
+ if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
+ perror("dup2 error on stdout");
+ exit(EXIT_FAILURE);
+ }
+ close(fd[1]);
+ }
+ if (ifile != STDIN_FILENO) {
+ if (dup2(ifile, STDIN_FILENO) != STDIN_FILENO) {
+ perror("dup2 error on stdin");
+ exit(EXIT_FAILURE);
+ }
+ close(ifile);
+ }
+ execl("/usr/bin/cpp", "/usr/bin/cpp", "-P", "-", "-", NULL);
+ }
+ return(EXIT_SUCCESS);
}
diff --git a/sys/dev/pci/ahc_pci.c b/sys/dev/pci/ahc_pci.c
new file mode 100644
index 00000000000..385d3505e01
--- /dev/null
+++ b/sys/dev/pci/ahc_pci.c
@@ -0,0 +1,715 @@
+/*
+ * Product specific probe and attach routines for:
+ * 3940, 2940, aic7880, aic7870, aic7860 and aic7850 SCSI controllers
+ *
+ * Copyright (c) 1995, 1996 Justin T. Gibbs.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice immediately at the beginning of the file, without modification,
+ * 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. 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 AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: ahc_pci.c,v 1.1 1996/05/16 03:44:13 mycroft Exp $
+ */
+
+#if defined(__FreeBSD__)
+#include <pci.h>
+#endif
+#if NPCI > 0 || defined(__NetBSD__)
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/queue.h>
+#if defined(__NetBSD__)
+#include <sys/device.h>
+#include <machine/bus.h>
+#ifdef __alpha__
+#include <machine/intr.h>
+#endif
+#endif /* defined(__NetBSD__) */
+
+#include <scsi/scsi_all.h>
+#include <scsi/scsiconf.h>
+
+#if defined(__FreeBSD__)
+
+#include <pci/pcireg.h>
+#include <pci/pcivar.h>
+
+#include <machine/clock.h>
+
+#include <i386/scsi/aic7xxx.h>
+#include <i386/scsi/93cx6.h>
+
+#include <dev/aic7xxx/aic7xxx_reg.h>
+
+#define PCI_BASEADR0 PCI_MAP_REG_START
+
+#elif defined(__NetBSD__)
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/ic/aic7xxxreg.h>
+#include <dev/ic/aic7xxxvar.h>
+#include <dev/ic/smc93cx6var.h>
+
+#define bootverbose 1
+#define PCI_BASEADR0 PCI_MAPREG_START
+
+#endif /* defined(__NetBSD__) */
+
+#define PCI_DEVICE_ID_ADAPTEC_3940U 0x82789004ul
+#define PCI_DEVICE_ID_ADAPTEC_2944U 0x84789004ul
+#define PCI_DEVICE_ID_ADAPTEC_2940U 0x81789004ul
+#define PCI_DEVICE_ID_ADAPTEC_3940 0x72789004ul
+#define PCI_DEVICE_ID_ADAPTEC_2944 0x74789004ul
+#define PCI_DEVICE_ID_ADAPTEC_2940 0x71789004ul
+#define PCI_DEVICE_ID_ADAPTEC_AIC7880 0x80789004ul
+#define PCI_DEVICE_ID_ADAPTEC_AIC7870 0x70789004ul
+#define PCI_DEVICE_ID_ADAPTEC_AIC7860 0x60789004ul
+#define PCI_DEVICE_ID_ADAPTEC_AIC7855 0x55789004ul
+#define PCI_DEVICE_ID_ADAPTEC_AIC7850 0x50789004ul
+
+#define DEVCONFIG 0x40
+#define MPORTMODE 0x00000400ul /* aic7870 only */
+#define RAMPSM 0x00000200ul /* aic7870 only */
+#define VOLSENSE 0x00000100ul
+#define SCBRAMSEL 0x00000080ul
+#define MRDCEN 0x00000040ul
+#define EXTSCBTIME 0x00000020ul /* aic7870 only */
+#define EXTSCBPEN 0x00000010ul /* aic7870 only */
+#define BERREN 0x00000008ul
+#define DACEN 0x00000004ul
+#define STPWLEVEL 0x00000002ul
+#define DIFACTNEGEN 0x00000001ul /* aic7870 only */
+
+#define CSIZE_LATTIME 0x0c
+#define CACHESIZE 0x0000003ful /* only 5 bits */
+#define LATTIME 0x0000ff00ul
+
+/*
+ * Define the format of the aic78X0 SEEPROM registers (16 bits).
+ *
+ */
+
+struct seeprom_config {
+
+/*
+ * SCSI ID Configuration Flags
+ */
+#define CFXFER 0x0007 /* synchronous transfer rate */
+#define CFSYNCH 0x0008 /* enable synchronous transfer */
+#define CFDISC 0x0010 /* enable disconnection */
+#define CFWIDEB 0x0020 /* wide bus device */
+/* UNUSED 0x00C0 */
+#define CFSTART 0x0100 /* send start unit SCSI command */
+#define CFINCBIOS 0x0200 /* include in BIOS scan */
+#define CFRNFOUND 0x0400 /* report even if not found */
+/* UNUSED 0xf800 */
+ u_int16_t device_flags[16]; /* words 0-15 */
+
+/*
+ * BIOS Control Bits
+ */
+#define CFSUPREM 0x0001 /* support all removeable drives */
+#define CFSUPREMB 0x0002 /* support removeable drives for boot only */
+#define CFBIOSEN 0x0004 /* BIOS enabled */
+/* UNUSED 0x0008 */
+#define CFSM2DRV 0x0010 /* support more than two drives */
+/* UNUSED 0x0060 */
+#define CFEXTEND 0x0080 /* extended translation enabled */
+/* UNUSED 0xff00 */
+ u_int16_t bios_control; /* word 16 */
+
+/*
+ * Host Adapter Control Bits
+ */
+/* UNUSED 0x0001 */
+#define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
+#define CFSTERM 0x0004 /* SCSI low byte termination (non-wide cards) */
+#define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
+#define CFSPARITY 0x0010 /* SCSI parity */
+/* UNUSED 0x0020 */
+#define CFRESETB 0x0040 /* reset SCSI bus at IC initialization */
+/* UNUSED 0xff80 */
+ u_int16_t adapter_control; /* word 17 */
+
+/*
+ * Bus Release, Host Adapter ID
+ */
+#define CFSCSIID 0x000f /* host adapter SCSI ID */
+/* UNUSED 0x00f0 */
+#define CFBRTIME 0xff00 /* bus release time */
+ u_int16_t brtime_id; /* word 18 */
+
+/*
+ * Maximum targets
+ */
+#define CFMAXTARG 0x00ff /* maximum targets */
+/* UNUSED 0xff00 */
+ u_int16_t max_targets; /* word 19 */
+
+ u_int16_t res_1[11]; /* words 20-30 */
+ u_int16_t checksum; /* word 31 */
+};
+
+static void load_seeprom __P((struct ahc_data *ahc));
+
+static u_char aic3940_count;
+
+#if defined(__FreeBSD__)
+
+static char* aic7870_probe __P((pcici_t tag, pcidi_t type));
+static void aic7870_attach __P((pcici_t config_id, int unit));
+
+static struct pci_device ahc_pci_driver = {
+ "ahc",
+ aic7870_probe,
+ aic7870_attach,
+ &ahc_unit,
+ NULL
+};
+
+DATA_SET (pcidevice_set, ahc_pci_driver);
+
+static char*
+aic7870_probe (pcici_t tag, pcidi_t type)
+{
+ switch(type) {
+ case PCI_DEVICE_ID_ADAPTEC_3940U:
+ return ("Adaptec 3940 Ultra SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_3940:
+ return ("Adaptec 3940 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2944U:
+ return ("Adaptec 2944 Ultra SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2940U:
+ return ("Adaptec 2940 Ultra SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2944:
+ return ("Adaptec 2944 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2940:
+ return ("Adaptec 2940 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7880:
+ return ("Adaptec aic7880 Ultra SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7870:
+ return ("Adaptec aic7870 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7860:
+ return ("Adaptec aic7860 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7855:
+ return ("Adaptec aic7855 SCSI host adapter");
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7850:
+ return ("Adaptec aic7850 SCSI host adapter");
+ break;
+ default:
+ break;
+ }
+ return (0);
+
+}
+
+#elif defined(__NetBSD__)
+
+int ahc_pci_probe __P((struct device *, void *, void *));
+void ahc_pci_attach __P((struct device *, struct device *, void *));
+
+struct cfattach ahc_pci_ca = {
+ sizeof(struct ahc_data), ahc_pci_probe, ahc_pci_attach
+};
+
+int
+ahc_pci_probe(parent, match, aux)
+ struct device *parent;
+ void *match, *aux;
+{
+ struct pci_attach_args *pa = aux;
+
+ switch (pa->pa_id) {
+ case PCI_DEVICE_ID_ADAPTEC_3940U:
+ case PCI_DEVICE_ID_ADAPTEC_2944U:
+ case PCI_DEVICE_ID_ADAPTEC_2940U:
+ case PCI_DEVICE_ID_ADAPTEC_3940:
+ case PCI_DEVICE_ID_ADAPTEC_2944:
+ case PCI_DEVICE_ID_ADAPTEC_2940:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7880:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7870:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7860:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7855:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7850:
+ return 1;
+ }
+ return 0;
+}
+#endif /* defined(__NetBSD__) */
+
+#if defined(__FreeBSD__)
+static void
+aic7870_attach(config_id, unit)
+ pcici_t config_id;
+ int unit;
+#elif defined(__NetBSD__)
+void
+ahc_pci_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+#endif
+{
+#if defined(__FreeBSD__)
+ u_long io_port;
+#elif defined(__NetBSD__)
+ struct pci_attach_args *pa = aux;
+ struct ahc_data *ahc = (void *)self;
+ int unit = ahc->sc_dev.dv_unit;
+ bus_io_addr_t iobase;
+ bus_io_size_t iosize;
+ bus_io_handle_t ioh;
+ pci_intr_handle_t ih;
+ const char *intrstr;
+#endif
+ u_long id;
+ unsigned opri = 0;
+ ahc_type ahc_t = AHC_NONE;
+ ahc_flag ahc_f = AHC_FNONE;
+#if defined(__FreeBSD__)
+ struct ahc_data *ahc;
+#endif
+ u_char ultra_enb = 0;
+ u_char our_id = 0;
+
+#if defined(__FreeBSD__)
+ if(!(io_port = pci_conf_read(config_id, PCI_BASEADR0)))
+ return;
+ /*
+ * The first bit of PCI_BASEADR0 is always
+ * set hence we mask it off.
+ */
+ io_port &= 0xfffffffe;
+#elif defined(__NetBSD__)
+ if (pci_io_find(pa->pa_pc, pa->pa_tag, PCI_BASEADR0, &iobase, &iosize))
+ return;
+ if (bus_io_map(pa->pa_bc, iobase, iosize, &ioh))
+ return;
+#endif
+
+#if defined(__FreeBSD__)
+ switch ((id = pci_conf_read(config_id, PCI_ID_REG))) {
+#elif defined(__NetBSD__)
+ switch (id = pa->pa_id) {
+#endif
+ case PCI_DEVICE_ID_ADAPTEC_3940U:
+ case PCI_DEVICE_ID_ADAPTEC_3940:
+ if (id == PCI_DEVICE_ID_ADAPTEC_3940U)
+ ahc_t = AHC_394U;
+ else
+ ahc_t = AHC_394;
+ aic3940_count++;
+ if(!(aic3940_count & 0x01))
+ /* Even count implies second channel */
+ ahc_f |= AHC_CHNLB;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2944U:
+ case PCI_DEVICE_ID_ADAPTEC_2940U:
+ ahc_t = AHC_294U;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_2944:
+ case PCI_DEVICE_ID_ADAPTEC_2940:
+ ahc_t = AHC_294;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7880:
+ ahc_t = AHC_AIC7880;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7870:
+ ahc_t = AHC_AIC7870;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7860:
+ ahc_t = AHC_AIC7860;
+ break;
+ case PCI_DEVICE_ID_ADAPTEC_AIC7855:
+ case PCI_DEVICE_ID_ADAPTEC_AIC7850:
+ ahc_t = AHC_AIC7850;
+ break;
+ default:
+ break;
+ }
+
+ /* On all PCI adapters, we allow SCB paging */
+ ahc_f |= AHC_PAGESCBS;
+
+ /* Remeber how the card was setup in case there is no SEEPROM */
+#if defined(__FreeBSD__)
+ our_id = inb(SCSIID + io_port) & OID;
+ if(ahc_t & AHC_ULTRA)
+ ultra_enb = inb(SXFRCTL0 + io_port) & ULTRAEN;
+#else
+ our_id = bus_io_read_1(pa->pa_bc, ioh, SCSIID) & OID;
+ if(ahc_t & AHC_ULTRA)
+ ultra_enb = bus_io_read_1(pa->pa_bc, ioh, SXFRCTL0) & ULTRAEN;
+#endif
+
+#if defined(__FreeBSD__)
+ ahc_reset(io_port);
+#elif defined(__NetBSD__)
+ printf("\n");
+ ahc_reset(ahc->sc_dev.dv_xname, pa->pa_bc, ioh);
+#endif
+
+ if(ahc_t & AHC_AIC7870){
+#if defined(__FreeBSD__)
+ u_long devconfig = pci_conf_read(config_id, DEVCONFIG);
+#elif defined(__NetBSD__)
+ u_long devconfig =
+ pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
+#endif
+
+ if(devconfig & (RAMPSM)) {
+ /*
+ * External SRAM present. Have the probe walk
+ * the SCBs to see how much SRAM we have and set
+ * the number of SCBs accordingly. We have to
+ * turn off SCBRAMSEL to access the external
+ * SCB SRAM.
+ *
+ * It seems that early versions of the aic7870
+ * didn't use these bits, hence the hack for the
+ * 3940 above. I would guess that recent 3940s
+ * using later aic7870 or aic7880 chips do
+ * actually set RAMPSM.
+ *
+ * The documentation isn't clear, but it sounds
+ * like the value written to devconfig must not
+ * have RAMPSM set. The second sixteen bits of
+ * the register are R/O anyway, so it shouldn't
+ * affect RAMPSM either way.
+ */
+ devconfig &= ~(RAMPSM|SCBRAMSEL);
+#if defined(__FreeBSD__)
+ pci_conf_write(config_id, DEVCONFIG, devconfig);
+#elif defined(__NetBSD__)
+ pci_conf_write(pa->pa_pc, pa->pa_tag,
+ DEVCONFIG, devconfig);
+#endif
+ }
+ }
+
+ /*
+ * Ensure that we are using good values for the PCI burst size
+ * and latency timer.
+ */
+ {
+#if defined(__FreeBSD__)
+ u_long csize_lattime = pci_conf_read(config_id, CSIZE_LATTIME);
+#elif defined(__NetBSD__)
+ u_long csize_lattime =
+ pci_conf_read(pa->pa_pc, pa->pa_tag, CSIZE_LATTIME);
+#endif
+
+ if((csize_lattime & CACHESIZE) == 0) {
+ /* default to 8DWDs. What's the PCI define for this? */
+ csize_lattime |= 8;
+ }
+ if((csize_lattime & LATTIME) == 0) {
+ /* Default to 64 PCLKS (is this a good value?) */
+ /* This may also be availble in the SEEPROM?? */
+ csize_lattime |= (64 << 8);
+ }
+ if(bootverbose)
+ printf("ahc%d: BurstLen = %ldDWDs, "
+ "Latency Timer = %ldPCLKS\n",
+ unit,
+ csize_lattime & CACHESIZE,
+ (csize_lattime >> 8) & 0xff);
+#if defined(__FreeBSD__)
+ pci_conf_write(config_id, CSIZE_LATTIME, csize_lattime);
+#elif defined(__NetBSD__)
+ pci_conf_write(pa->pa_pc, pa->pa_tag, CSIZE_LATTIME,
+ csize_lattime);
+#endif
+ }
+
+#if defined(__FreeBSD__)
+ if(!(ahc = ahc_alloc(unit, io_port, ahc_t, ahc_f)))
+ return; /* XXX PCI code should take return status */
+
+ if(!(pci_map_int(config_id, ahc_intr, (void *)ahc, &bio_imask))) {
+ ahc_free(ahc);
+ return;
+ }
+#elif defined(__NetBSD__)
+ ahc_construct(ahc, pa->pa_bc, ioh, ahc_t, ahc_f);
+
+ if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
+ pa->pa_intrline, &ih)) {
+ printf("%s: couldn't map interrupt\n", ahc->sc_dev.dv_xname);
+ ahc_free(ahc);
+ return;
+ }
+ intrstr = pci_intr_string(pa->pa_pc, ih);
+ ahc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ahc_intr, ahc
+#ifdef __OpenBSD__
+ , ahc->sc_dev.dv_xname
+#endif
+ );
+ if (ahc->sc_ih == NULL) {
+ printf("%s: couldn't establish interrupt",
+ ahc->sc_dev.dv_xname);
+ if (intrstr != NULL)
+ printf(" at %s", intrstr);
+ printf("\n");
+ ahc_free(ahc);
+ return;
+ }
+ if (intrstr != NULL)
+ printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
+ intrstr);
+#endif
+ /*
+ * Protect ourself from spurrious interrupts during
+ * intialization.
+ */
+ opri = splbio();
+
+ /*
+ * Do aic7870/aic7880/aic7850 specific initialization
+ */
+ {
+ u_char sblkctl;
+ char *id_string;
+
+ switch(ahc->type) {
+ case AHC_394U:
+ case AHC_294U:
+ case AHC_AIC7880:
+ {
+ id_string = "aic7880 ";
+ load_seeprom(ahc);
+ break;
+ }
+ case AHC_394:
+ case AHC_294:
+ case AHC_AIC7870:
+ {
+ id_string = "aic7870 ";
+ load_seeprom(ahc);
+ break;
+ }
+ case AHC_AIC7860:
+ {
+ id_string = "aic7860 ";
+ /*
+ * Use defaults, if the chip wasn't initialized by
+ * a BIOS.
+ */
+ ahc->flags |= AHC_USEDEFAULTS;
+ break;
+ }
+ case AHC_AIC7850:
+ {
+ id_string = "aic7850 ";
+ /*
+ * Use defaults, if the chip wasn't initialized by
+ * a BIOS.
+ */
+ ahc->flags |= AHC_USEDEFAULTS;
+ break;
+ }
+ default:
+ {
+ printf("ahc: Unknown controller type. Ignoring.\n");
+ ahc_free(ahc);
+ splx(opri);
+ return;
+ }
+ }
+
+ /*
+ * Take the LED out of diagnostic mode
+ */
+ sblkctl = AHC_INB(ahc, SBLKCTL);
+ AHC_OUTB(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
+
+ /*
+ * I don't know where this is set in the SEEPROM or by the
+ * BIOS, so we default to 100%.
+ */
+ AHC_OUTB(ahc, DSPCISTATUS, DFTHRSH_100);
+
+ if(ahc->flags & AHC_USEDEFAULTS) {
+ /*
+ * PCI Adapter default setup
+ * Should only be used if the adapter does not have
+ * an SEEPROM.
+ */
+ /* See if someone else set us up already */
+ u_long i;
+ for(i = TARG_SCRATCH; i < 0x60; i++) {
+ if(AHC_INB(ahc, i) != 0xff)
+ break;
+ }
+ if(i != 0x60) {
+ printf("%s: Using left over BIOS settings\n",
+ ahc_name(ahc));
+ ahc->flags &= ~AHC_USEDEFAULTS;
+ }
+ else
+ our_id = 0x07;
+ AHC_OUTB(ahc, SCSICONF,
+ (our_id & 0x07)|ENSPCHK|RESET_SCSI);
+ /* In case we are a wide card */
+ AHC_OUTB(ahc, SCSICONF + 1, our_id);
+
+ if(!ultra_enb || (ahc->flags & AHC_USEDEFAULTS)) {
+ /*
+ * If there wasn't a BIOS or the board
+ * wasn't in this mode to begin with,
+ * turn off ultra.
+ */
+ ahc->type &= ~AHC_ULTRA;
+ }
+ }
+
+ printf("%s: %s", ahc_name(ahc), id_string);
+ }
+
+ if(ahc_init(ahc)){
+ ahc_free(ahc);
+ splx(opri);
+ return; /* XXX PCI code should take return status */
+ }
+ splx(opri);
+
+ ahc_attach(ahc);
+ return;
+}
+
+/*
+ * Read the SEEPROM. Return 0 on failure
+ */
+void
+load_seeprom(ahc)
+ struct ahc_data *ahc;
+{
+ struct seeprom_descriptor sd;
+ struct seeprom_config sc;
+ u_short *scarray = (u_short *)&sc;
+ u_short checksum = 0;
+ u_char scsi_conf;
+ u_char host_id;
+ int have_seeprom;
+
+#if defined(__FreeBSD__)
+ sd.sd_iobase = ahc->baseport + SEECTL;
+#elif defined(__NetBSD__)
+ sd.sd_bc = ahc->sc_bc;
+ sd.sd_ioh = ahc->sc_ioh;
+ sd.sd_offset = SEECTL;
+#endif
+ sd.sd_MS = SEEMS;
+ sd.sd_RDY = SEERDY;
+ sd.sd_CS = SEECS;
+ sd.sd_CK = SEECK;
+ sd.sd_DO = SEEDO;
+ sd.sd_DI = SEEDI;
+
+ if(bootverbose)
+ printf("%s: Reading SEEPROM...", ahc_name(ahc));
+ have_seeprom = acquire_seeprom(&sd);
+ if (have_seeprom) {
+ have_seeprom = read_seeprom(&sd,
+ (u_int16_t *)&sc,
+ ahc->flags & AHC_CHNLB,
+ sizeof(sc)/2);
+ release_seeprom(&sd);
+ if (have_seeprom) {
+ /* Check checksum */
+ int i;
+
+ for (i = 0;i < (sizeof(sc)/2 - 1);i = i + 1)
+ checksum = checksum + scarray[i];
+ if (checksum != sc.checksum) {
+ if(bootverbose)
+ printf ("checksum error");
+ have_seeprom = 0;
+ }
+ else if(bootverbose)
+ printf("done.\n");
+ }
+ }
+ if (!have_seeprom) {
+ if(bootverbose)
+ printf("\n%s: No SEEPROM availible\n", ahc_name(ahc));
+ ahc->flags |= AHC_USEDEFAULTS;
+ }
+ else {
+ /*
+ * Put the data we've collected down into SRAM
+ * where ahc_init will find it.
+ */
+ int i;
+ int max_targ = sc.max_targets & CFMAXTARG;
+
+ for(i = 0; i <= max_targ; i++){
+ u_char target_settings;
+ target_settings = (sc.device_flags[i] & CFXFER) << 4;
+ if (sc.device_flags[i] & CFSYNCH)
+ target_settings |= SOFS;
+ if (sc.device_flags[i] & CFWIDEB)
+ target_settings |= WIDEXFER;
+ if (sc.device_flags[i] & CFDISC)
+ ahc->discenable |= (0x01 << i);
+ AHC_OUTB(ahc, TARG_SCRATCH+i, target_settings);
+ }
+ AHC_OUTB(ahc, DISC_DSB, ~(ahc->discenable & 0xff));
+ AHC_OUTB(ahc, DISC_DSB + 1, ~((ahc->discenable >> 8) & 0xff));
+
+ host_id = sc.brtime_id & CFSCSIID;
+
+ scsi_conf = (host_id & 0x7);
+ if(sc.adapter_control & CFSPARITY)
+ scsi_conf |= ENSPCHK;
+ if(sc.adapter_control & CFRESETB)
+ scsi_conf |= RESET_SCSI;
+
+ if(ahc->type & AHC_ULTRA) {
+ /* Should we enable Ultra mode? */
+ if(!(sc.adapter_control & CFULTRAEN))
+ /* Treat us as a non-ultra card */
+ ahc->type &= ~AHC_ULTRA;
+ }
+ /* Set the host ID */
+ AHC_OUTB(ahc, SCSICONF, scsi_conf);
+ /* In case we are a wide card */
+ AHC_OUTB(ahc, SCSICONF + 1, host_id);
+ }
+}
+
+#endif /* NPCI > 0 */
diff --git a/sys/dev/pci/aic7870.c b/sys/dev/pci/aic7870.c
deleted file mode 100644
index 5ca207d34e5..00000000000
--- a/sys/dev/pci/aic7870.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/* $NetBSD: aic7870.c,v 1.9 1996/05/13 00:03:02 mycroft Exp $ */
-
-/*
- * Product specific probe and attach routines for:
- * 294X and aic7870 motherboard SCSI controllers
- *
- * Copyright (c) 1995 Justin T. Gibbs
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice immediately at the beginning of the file, without modification,
- * 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. Absolutely no warranty of function or purpose is made by the author
- * Justin T. Gibbs.
- * 4. Modifications may be freely made to this file if the above conditions
- * are met.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/device.h>
-
-#include <machine/intr.h>
-
-#include <scsi/scsi_all.h>
-#include <scsi/scsiconf.h>
-
-#include <dev/pci/pcireg.h>
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcidevs.h>
-
-#include <dev/ic/aic7xxxvar.h>
-
-
-#define PCI_BASEADR0 PCI_MAPREG_START
-#define PCI_VENDORID(x) ((x) & 0xFFFF)
-#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
-
-static int aic7870_probe __P((struct device *, void *, void *));
-static void aic7870_attach __P((struct device *, struct device *, void *));
-
-struct cfattach ahc_ca = {
- sizeof(struct ahc_softc), aic7870_probe, aic7870_attach
-};
-
-struct cfdriver ahc_cd = {
- NULL, "ahc", DV_DULL
-};
-
-int ahcintr __P((void *));
-
-
-int
-aic7870_probe(parent, match, aux)
- struct device *parent;
- void *match, *aux;
-{
- struct pci_attach_args *pa = aux;
-
- if (PCI_VENDORID(pa->pa_id) != PCI_VENDOR_ADP)
- return 0;
-
- switch (PCI_CHIPID(pa->pa_id)) {
- case PCI_PRODUCT_ADP_AIC7870:
- case PCI_PRODUCT_ADP_2940:
- case PCI_PRODUCT_ADP_2940U:
- return 1;
- default:
- return 0;
- }
-}
-
-void
-aic7870_attach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
-{
- struct pci_attach_args *pa = aux;
- struct ahc_softc *ahc = (void *)self;
- int iobase;
-
- switch (PCI_CHIPID(pa->pa_id)) {
- case PCI_PRODUCT_ADP_AIC7870:
- ahc->type = AHC_AIC7870;
- break;
-
- case PCI_PRODUCT_ADP_2940:
- case PCI_PRODUCT_ADP_2940U:
- ahc->type = AHC_294;
- break;
- }
-
- if (pci_map_io(pa->pa_tag, PCI_BASEADR0, &iobase))
- return;
-
- /*
- * Make the offsets the same as for EISA
- */
- iobase -= 0xc00ul;
-
- if (ahcprobe(ahc, iobase) == 0)
- return;
-
- ahcattach(ahc);
-
- ahc->sc_ih = pci_map_int(pa->pa_tag, IPL_BIO, ahcintr, ahc);
-}
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci
index 0d0c9d8ac92..187c2efcb10 100644
--- a/sys/dev/pci/files.pci
+++ b/sys/dev/pci/files.pci
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.15 1996/05/07 02:03:07 thorpej Exp $
+# $NetBSD: files.pci,v 1.16 1996/05/16 03:44:16 mycroft Exp $
#
# Config.new file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -9,10 +9,11 @@ attach pci at pcibus
file dev/pci/pci.c pci needs-flag
file dev/pci/pci_subr.c pci
-# Adaptec 7870 chips
-device ahc: scsi, aic7xxx
-attach ahc at pci
-file dev/pci/aic7870.c ahc
+# Adaptec 3940, 2940, and aic78[5678]0 SCSI controllers
+# device declaration in sys/conf/files
+attach ahc at pci with ahc_pci
+file dev/pci/ahc_pci.c ahc_pci
+file dev/ic/smc93cx6.c ahc_pci
# Ethernet driver for DC21040-based boards
device de: ether, ifnet