1 /* $NetBSD: csa.c,v 1.6 2002/10/02 03:31:59 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Mark Brinicombe of Causality Limited. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Cumana SCSI 1 driver using the generic NCR5380 driver 41 */ 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/kernel.h> 46 #include <sys/device.h> 47 #include <sys/buf.h> 48 #include <dev/scsipi/scsi_all.h> 49 #include <dev/scsipi/scsipi_all.h> 50 #include <dev/scsipi/scsiconf.h> 51 52 #include <dev/ic/ncr5380reg.h> 53 #include <dev/ic/ncr5380var.h> 54 55 #include <machine/io.h> 56 #include <machine/intr.h> 57 #include <machine/bootconfig.h> 58 59 #include <acorn32/podulebus/podulebus.h> 60 #include <dev/podulebus/podules.h> 61 #include <dev/podulebus/powerromreg.h> 62 63 #define CSA_NCR5380_OFFSET 0x2100 64 #define CSA_CTRL_OFFSET 0x2000 - 2308 65 #define CSA_DIRWRITE 0x02 66 #define CSA_DIRREAD 0x00 67 #define CSA_16BITS 0x00 68 #define CSA_8BITS 0x10 69 #define CSA_XXX 0x40 70 #define CSA_DATA_OFFSET 0x2000 71 #define CSA_INTR_OFFSET 0x2000 72 #define CSA_INTR_MASK 0x80 73 #define CSA_STAT_OFFSET 0x2004 74 #define CSA_STAT_DRQ 0x40 75 #define CSA_STAT_END 0x80 76 77 void csa_attach __P((struct device *, struct device *, void *)); 78 int csa_match __P((struct device *, struct cfdata *, void *)); 79 80 /* 81 * Cumana SCSI 1 softc structure. 82 * 83 * Contains the generic ncr5380 device node, podule information and global information 84 * required by the driver. 85 */ 86 87 struct csa_softc { 88 struct ncr5380_softc sc_ncr5380; 89 void *sc_ih; 90 struct evcnt sc_intrcnt; 91 int sc_podule_number; 92 podule_t *sc_podule; 93 volatile u_char *sc_irqstatus; 94 u_char sc_irqmask; 95 volatile u_char *sc_ctrl; 96 volatile u_char *sc_status; 97 volatile u_char *sc_data; 98 }; 99 100 CFATTACH_DECL(csa, sizeof(struct csa_softc), 101 csa_match, csa_attach, NULL, NULL); 102 103 int csa_intr __P((void *arg)); 104 105 /* 106 * Card probe function 107 * 108 * Just match the manufacturer and podule ID's 109 */ 110 111 int 112 csa_match(parent, cf, aux) 113 struct device *parent; 114 struct cfdata *cf; 115 void *aux; 116 { 117 struct podule_attach_args *pa = aux; 118 119 if (pa->pa_product == PODULE_CUMANA_SCSI1) 120 return(1); 121 122 /* PowerROM */ 123 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI && 124 podulebus_initloader(pa) == 0 && 125 (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 || 126 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16)) 127 return 1; 128 129 return 0; 130 } 131 132 /* 133 * Card attach function 134 * 135 */ 136 137 void 138 csa_attach(parent, self, aux) 139 struct device *parent, *self; 140 void *aux; 141 { 142 struct csa_softc *sc = (struct csa_softc *)self; 143 struct podule_attach_args *pa = aux; 144 u_char *iobase; 145 char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8]; 146 147 /* Note the podule number and validate */ 148 149 if (pa->pa_podule_number == -1) 150 panic("Podule has disappeared !"); 151 152 sc->sc_podule_number = pa->pa_podule_number; 153 sc->sc_podule = pa->pa_podule; 154 podules[sc->sc_podule_number].attached = 1; 155 156 sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING; 157 sc->sc_ncr5380.sc_min_dma_len = 0; 158 sc->sc_ncr5380.sc_no_disconnect = 0x00; 159 sc->sc_ncr5380.sc_parity_disable = 0x00; 160 161 sc->sc_ncr5380.sc_dma_alloc = NULL; 162 sc->sc_ncr5380.sc_dma_free = NULL; 163 sc->sc_ncr5380.sc_dma_poll = NULL; 164 sc->sc_ncr5380.sc_dma_setup = NULL; 165 sc->sc_ncr5380.sc_dma_start = NULL; 166 sc->sc_ncr5380.sc_dma_eop = NULL; 167 sc->sc_ncr5380.sc_dma_stop = NULL; 168 sc->sc_ncr5380.sc_intr_on = NULL; 169 sc->sc_ncr5380.sc_intr_off = NULL; 170 171 iobase = (u_char *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET; 172 sc->sc_ncr5380.sci_r0 = iobase + 0; 173 sc->sc_ncr5380.sci_r1 = iobase + 4; 174 sc->sc_ncr5380.sci_r2 = iobase + 8; 175 sc->sc_ncr5380.sci_r3 = iobase + 12; 176 sc->sc_ncr5380.sci_r4 = iobase + 16; 177 sc->sc_ncr5380.sci_r5 = iobase + 20; 178 sc->sc_ncr5380.sci_r6 = iobase + 24; 179 sc->sc_ncr5380.sci_r7 = iobase + 28; 180 181 sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380; 182 183 sc->sc_ctrl = (u_char *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET; 184 sc->sc_status = (u_char *)pa->pa_podule->slow_base + CSA_STAT_OFFSET; 185 sc->sc_data = (u_char *)pa->pa_podule->slow_base + CSA_DATA_OFFSET; 186 187 sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in; 188 sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out; 189 190 /* Provide an override for the host id */ 191 sc->sc_ncr5380.sc_channel.chan_id = 7; 192 sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname); 193 (void)get_bootconf_option(boot_args, hi_option, 194 BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id); 195 sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys; 196 197 printf(": host=%d, using 8 bit PIO", 198 sc->sc_ncr5380.sc_channel.chan_id); 199 200 sc->sc_irqstatus = (u_char *)pa->pa_podule->slow_base + CSA_INTR_OFFSET; 201 sc->sc_irqmask = CSA_INTR_MASK; 202 203 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 204 self->dv_xname, "intr"); 205 sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc, 206 &sc->sc_intrcnt); 207 if (sc->sc_ih == NULL) 208 sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING; 209 210 if (sc->sc_ncr5380.sc_flags & NCR5380_FORCE_POLLING) 211 printf(", polling"); 212 printf("\n"); 213 *sc->sc_ctrl = 0; 214 215 ncr5380_attach(&sc->sc_ncr5380); 216 } 217 218 int 219 csa_intr(arg) 220 void *arg; 221 { 222 struct csa_softc *sc = arg; 223 224 if ((*sc->sc_irqstatus) & sc->sc_irqmask) 225 (void)ncr5380_intr(&sc->sc_ncr5380); 226 227 return(0); 228 } 229