1 /* $NetBSD: csc.c,v 1.16 2009/05/12 06:54:10 cegger 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 Scott Stevens. 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-2 driver uses the SFAS216 generic driver 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: csc.c,v 1.16 2009/05/12 06:54:10 cegger Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/device.h> 43 44 #include <uvm/uvm_extern.h> 45 46 #include <dev/scsipi/scsi_all.h> 47 #include <dev/scsipi/scsipi_all.h> 48 #include <dev/scsipi/scsiconf.h> 49 #include <machine/io.h> 50 #include <machine/intr.h> 51 #include <machine/bootconfig.h> 52 #include <acorn32/podulebus/podulebus.h> 53 #include <acorn32/podulebus/sfasreg.h> 54 #include <acorn32/podulebus/sfasvar.h> 55 #include <acorn32/podulebus/cscreg.h> 56 #include <acorn32/podulebus/cscvar.h> 57 #include <dev/podulebus/podules.h> 58 #include <dev/podulebus/powerromreg.h> 59 60 int cscmatch(struct device *, struct cfdata *, void *); 61 void cscattach(struct device *, struct device *, void *); 62 63 CFATTACH_DECL(csc, sizeof(struct csc_softc), 64 cscmatch, cscattach, NULL, NULL); 65 66 int csc_intr(void *); 67 int csc_setup_dma(void *, void *, int, int); 68 int csc_build_dma_chain(void *, void *, void *, int); 69 int csc_need_bump(void *, void *, int); 70 void csc_led(void *, int); 71 72 void csc_set_dma_adr(struct sfas_softc *, void *); 73 void csc_set_dma_tc(struct sfas_softc *, unsigned int); 74 void csc_set_dma_mode(struct sfas_softc *, int); 75 76 /* 77 * if we are a Cumana SCSI-2 card 78 */ 79 int 80 cscmatch(struct device *pdp, struct cfdata *cf, void *auxp) 81 { 82 struct podule_attach_args *pa = (struct podule_attach_args *)auxp; 83 84 /* Look for the card */ 85 if (pa->pa_product == PODULE_CUMANA_SCSI2) 86 return 1; 87 88 /* PowerROM */ 89 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI && 90 podulebus_initloader(pa) == 0 && 91 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI2) 92 return 1; 93 94 return 0; 95 } 96 97 void 98 cscattach(struct device *pdp, struct device *dp, void *auxp) 99 { 100 struct csc_softc *sc = (struct csc_softc *)dp; 101 struct podule_attach_args *pa; 102 csc_regmap_p rp = &sc->sc_regmap; 103 vu_char *fas; 104 int loop; 105 106 pa = (struct podule_attach_args *)auxp; 107 108 if (pa->pa_podule_number == -1) 109 panic("Podule has disappeared !"); 110 111 sc->sc_specific.sc_podule_number = pa->pa_podule_number; 112 sc->sc_specific.sc_podule = pa->pa_podule; 113 sc->sc_specific.sc_iobase = 114 (vu_char *)sc->sc_specific.sc_podule->mod_base; 115 116 rp->status0 = &sc->sc_specific.sc_iobase[CSC_STATUS0]; 117 rp->alatch = &sc->sc_specific.sc_iobase[CSC_ALATCH]; 118 rp->dack = (vu_short *)&sc->sc_specific.sc_iobase[CSC_DACK]; 119 fas = &sc->sc_specific.sc_iobase[CSC_FAS_OFFSET_BASE]; 120 121 rp->FAS216.sfas_tc_low = &fas[CSC_FAS_OFFSET_TCL]; 122 rp->FAS216.sfas_tc_mid = &fas[CSC_FAS_OFFSET_TCM]; 123 rp->FAS216.sfas_fifo = &fas[CSC_FAS_OFFSET_FIFO]; 124 rp->FAS216.sfas_command = &fas[CSC_FAS_OFFSET_COMMAND]; 125 rp->FAS216.sfas_dest_id = &fas[CSC_FAS_OFFSET_DESTID]; 126 rp->FAS216.sfas_timeout = &fas[CSC_FAS_OFFSET_TIMEOUT]; 127 rp->FAS216.sfas_syncper = &fas[CSC_FAS_OFFSET_PERIOD]; 128 rp->FAS216.sfas_syncoff = &fas[CSC_FAS_OFFSET_OFFSET]; 129 rp->FAS216.sfas_config1 = &fas[CSC_FAS_OFFSET_CONFIG1]; 130 rp->FAS216.sfas_clkconv = &fas[CSC_FAS_OFFSET_CLKCONV]; 131 rp->FAS216.sfas_test = &fas[CSC_FAS_OFFSET_TEST]; 132 rp->FAS216.sfas_config2 = &fas[CSC_FAS_OFFSET_CONFIG2]; 133 rp->FAS216.sfas_config3 = &fas[CSC_FAS_OFFSET_CONFIG3]; 134 rp->FAS216.sfas_tc_high = &fas[CSC_FAS_OFFSET_TCH]; 135 rp->FAS216.sfas_fifo_bot = &fas[CSC_FAS_OFFSET_FIFOBOT]; 136 137 sc->sc_softc.sc_fas = (sfas_regmap_p)rp; 138 sc->sc_softc.sc_spec = &sc->sc_specific; 139 140 sc->sc_softc.sc_led = csc_led; 141 142 sc->sc_softc.sc_setup_dma = csc_setup_dma; 143 sc->sc_softc.sc_build_dma_chain = csc_build_dma_chain; 144 sc->sc_softc.sc_need_bump = csc_need_bump; 145 146 sc->sc_softc.sc_clock_freq = 8; /* Cumana runs at 8MHz */ 147 sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */ 148 sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/; 149 sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */ 150 151 sc->sc_softc.sc_bump_sz = PAGE_SIZE; 152 sc->sc_softc.sc_bump_pa = 0x0; 153 154 sfasinitialize((struct sfas_softc *)sc); 155 156 sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev; 157 sc->sc_softc.sc_adapter.adapt_nchannels = 1; 158 sc->sc_softc.sc_adapter.adapt_openings = 7; 159 sc->sc_softc.sc_adapter.adapt_max_periph = 1; 160 sc->sc_softc.sc_adapter.adapt_ioctl = NULL; 161 sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys; 162 sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request; 163 164 sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter; 165 sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype; 166 sc->sc_softc.sc_channel.chan_channel = 0; 167 sc->sc_softc.sc_channel.chan_ntargets = 8; 168 sc->sc_softc.sc_channel.chan_nluns = 8; 169 sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id; 170 171 /* Provide an override for the host id */ 172 (void)get_bootconf_option(boot_args, "csc.hostid", 173 BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id); 174 175 printf(": host=%d", sc->sc_softc.sc_channel.chan_id); 176 177 /* initialise the alatch */ 178 sc->sc_specific.sc_alatch_defs = (CSC_POLL?0:CSC_ALATCH_DEFS_INTEN); 179 for (loop = 0; loop < 8; loop ++) { 180 if(loop != 3) 181 *rp->alatch = (loop << 1) | 182 ((sc->sc_specific.sc_alatch_defs & (1 << loop))?1:0); 183 } 184 185 #if CSC_POLL == 0 186 evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL, 187 device_xname(dp), "intr"); 188 sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, 189 csc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt); 190 if (sc->sc_softc.sc_ih == NULL) 191 panic("%s: Cannot install IRQ handler", dp->dv_xname); 192 #else 193 printf(" polling"); 194 sc->sc_softc.sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY; 195 #endif 196 printf("\n"); 197 198 /* attach all scsi units on us */ 199 config_found(dp, &sc->sc_softc.sc_channel, scsiprint); 200 } 201 202 203 int 204 csc_intr(void *arg) 205 { 206 struct sfas_softc *dev = arg; 207 csc_regmap_p rp; 208 int quickints; 209 210 rp = (csc_regmap_p)dev->sc_fas; 211 212 if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) { 213 quickints = 16; 214 do { 215 dev->sc_status = *rp->FAS216.sfas_status; 216 dev->sc_interrupt = *rp->FAS216.sfas_interrupt; 217 218 if (dev->sc_interrupt & SFAS_INT_RESELECTED) { 219 dev->sc_resel[0] = *rp->FAS216.sfas_fifo; 220 dev->sc_resel[1] = *rp->FAS216.sfas_fifo; 221 } 222 sfasintr(dev); 223 224 } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) 225 && --quickints); 226 } 227 228 return(0); /* Pass interrupt on down the chain */ 229 } 230 231 /* Load transfer address into DMA register */ 232 void 233 csc_set_dma_adr(struct sfas_softc *sc, void *ptr) 234 { 235 return; 236 } 237 238 /* Set DMA transfer counter */ 239 void 240 csc_set_dma_tc(struct sfas_softc *sc, unsigned int len) 241 { 242 *sc->sc_fas->sfas_tc_low = len; len >>= 8; 243 *sc->sc_fas->sfas_tc_mid = len; len >>= 8; 244 *sc->sc_fas->sfas_tc_high = len; 245 } 246 247 /* Set DMA mode */ 248 void 249 csc_set_dma_mode(struct sfas_softc *sc, int mode) 250 { 251 } 252 253 /* Initialize DMA for transfer */ 254 int 255 csc_setup_dma(void *sc, void *ptr, int len, int mode) 256 { 257 258 return (0); 259 } 260 261 /* Check if address and len is ok for DMA transfer */ 262 int 263 csc_need_bump(void *sc, void *ptr, int len) 264 { 265 int p; 266 267 p = (int)ptr & 0x03; 268 269 if (p) { 270 p = 4-p; 271 272 if (len < 256) 273 p = len; 274 } 275 276 return(p); 277 } 278 279 /* Interrupt driven routines */ 280 int 281 csc_build_dma_chain(void *sc, void *chain, void *p, int l) 282 { 283 return(0); 284 } 285 286 /* Turn on/off led */ 287 void 288 csc_led(void *v, int mode) 289 { 290 struct sfas_softc *sc = v; 291 csc_regmap_p rp; 292 293 rp = (csc_regmap_p)sc->sc_fas; 294 295 if (mode) { 296 sc->sc_led_status++; 297 } else { 298 if (sc->sc_led_status) 299 sc->sc_led_status--; 300 } 301 } 302