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