1 /* $NetBSD: csc.c,v 1.14 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 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.14 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 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(pdp, cf, auxp) 81 struct device *pdp; 82 struct cfdata *cf; 83 void *auxp; 84 { 85 struct podule_attach_args *pa = (struct podule_attach_args *)auxp; 86 87 /* Look for the card */ 88 if (pa->pa_product == PODULE_CUMANA_SCSI2) 89 return 1; 90 91 /* PowerROM */ 92 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI && 93 podulebus_initloader(pa) == 0 && 94 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI2) 95 return 1; 96 97 return 0; 98 } 99 100 void 101 cscattach(pdp, dp, auxp) 102 struct device *pdp; 103 struct device *dp; 104 void *auxp; 105 { 106 struct csc_softc *sc = (struct csc_softc *)dp; 107 struct podule_attach_args *pa; 108 csc_regmap_p rp = &sc->sc_regmap; 109 vu_char *fas; 110 int loop; 111 112 pa = (struct podule_attach_args *)auxp; 113 114 if (pa->pa_podule_number == -1) 115 panic("Podule has disappeared !"); 116 117 sc->sc_specific.sc_podule_number = pa->pa_podule_number; 118 sc->sc_specific.sc_podule = pa->pa_podule; 119 sc->sc_specific.sc_iobase = 120 (vu_char *)sc->sc_specific.sc_podule->mod_base; 121 122 rp->status0 = &sc->sc_specific.sc_iobase[CSC_STATUS0]; 123 rp->alatch = &sc->sc_specific.sc_iobase[CSC_ALATCH]; 124 rp->dack = (vu_short *)&sc->sc_specific.sc_iobase[CSC_DACK]; 125 fas = &sc->sc_specific.sc_iobase[CSC_FAS_OFFSET_BASE]; 126 127 rp->FAS216.sfas_tc_low = &fas[CSC_FAS_OFFSET_TCL]; 128 rp->FAS216.sfas_tc_mid = &fas[CSC_FAS_OFFSET_TCM]; 129 rp->FAS216.sfas_fifo = &fas[CSC_FAS_OFFSET_FIFO]; 130 rp->FAS216.sfas_command = &fas[CSC_FAS_OFFSET_COMMAND]; 131 rp->FAS216.sfas_dest_id = &fas[CSC_FAS_OFFSET_DESTID]; 132 rp->FAS216.sfas_timeout = &fas[CSC_FAS_OFFSET_TIMEOUT]; 133 rp->FAS216.sfas_syncper = &fas[CSC_FAS_OFFSET_PERIOD]; 134 rp->FAS216.sfas_syncoff = &fas[CSC_FAS_OFFSET_OFFSET]; 135 rp->FAS216.sfas_config1 = &fas[CSC_FAS_OFFSET_CONFIG1]; 136 rp->FAS216.sfas_clkconv = &fas[CSC_FAS_OFFSET_CLKCONV]; 137 rp->FAS216.sfas_test = &fas[CSC_FAS_OFFSET_TEST]; 138 rp->FAS216.sfas_config2 = &fas[CSC_FAS_OFFSET_CONFIG2]; 139 rp->FAS216.sfas_config3 = &fas[CSC_FAS_OFFSET_CONFIG3]; 140 rp->FAS216.sfas_tc_high = &fas[CSC_FAS_OFFSET_TCH]; 141 rp->FAS216.sfas_fifo_bot = &fas[CSC_FAS_OFFSET_FIFOBOT]; 142 143 sc->sc_softc.sc_fas = (sfas_regmap_p)rp; 144 sc->sc_softc.sc_spec = &sc->sc_specific; 145 146 sc->sc_softc.sc_led = csc_led; 147 148 sc->sc_softc.sc_setup_dma = csc_setup_dma; 149 sc->sc_softc.sc_build_dma_chain = csc_build_dma_chain; 150 sc->sc_softc.sc_need_bump = csc_need_bump; 151 152 sc->sc_softc.sc_clock_freq = 8; /* Cumana runs at 8MHz */ 153 sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */ 154 sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/; 155 sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */ 156 157 sc->sc_softc.sc_bump_sz = PAGE_SIZE; 158 sc->sc_softc.sc_bump_pa = 0x0; 159 160 sfasinitialize((struct sfas_softc *)sc); 161 162 sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev; 163 sc->sc_softc.sc_adapter.adapt_nchannels = 1; 164 sc->sc_softc.sc_adapter.adapt_openings = 7; 165 sc->sc_softc.sc_adapter.adapt_max_periph = 1; 166 sc->sc_softc.sc_adapter.adapt_ioctl = NULL; 167 sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys; 168 sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request; 169 170 sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter; 171 sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype; 172 sc->sc_softc.sc_channel.chan_channel = 0; 173 sc->sc_softc.sc_channel.chan_ntargets = 8; 174 sc->sc_softc.sc_channel.chan_nluns = 8; 175 sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id; 176 177 /* Provide an override for the host id */ 178 (void)get_bootconf_option(boot_args, "csc.hostid", 179 BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id); 180 181 printf(": host=%d", sc->sc_softc.sc_channel.chan_id); 182 183 /* initialise the alatch */ 184 sc->sc_specific.sc_alatch_defs = (CSC_POLL?0:CSC_ALATCH_DEFS_INTEN); 185 for (loop = 0; loop < 8; loop ++) { 186 if(loop != 3) 187 *rp->alatch = (loop << 1) | 188 ((sc->sc_specific.sc_alatch_defs & (1 << loop))?1:0); 189 } 190 191 #if CSC_POLL == 0 192 evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL, 193 dp->dv_xname, "intr"); 194 sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, 195 csc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt); 196 if (sc->sc_softc.sc_ih == NULL) 197 panic("%s: Cannot install IRQ handler", dp->dv_xname); 198 #else 199 printf(" polling"); 200 sc->sc_softc.sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY; 201 #endif 202 printf("\n"); 203 204 /* attach all scsi units on us */ 205 config_found(dp, &sc->sc_softc.sc_channel, scsiprint); 206 } 207 208 209 int 210 csc_intr(arg) 211 void *arg; 212 { 213 struct sfas_softc *dev = arg; 214 csc_regmap_p rp; 215 int quickints; 216 217 rp = (csc_regmap_p)dev->sc_fas; 218 219 if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) { 220 quickints = 16; 221 do { 222 dev->sc_status = *rp->FAS216.sfas_status; 223 dev->sc_interrupt = *rp->FAS216.sfas_interrupt; 224 225 if (dev->sc_interrupt & SFAS_INT_RESELECTED) { 226 dev->sc_resel[0] = *rp->FAS216.sfas_fifo; 227 dev->sc_resel[1] = *rp->FAS216.sfas_fifo; 228 } 229 sfasintr(dev); 230 231 } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) 232 && --quickints); 233 } 234 235 return(0); /* Pass interrupt on down the chain */ 236 } 237 238 /* Load transfer address into DMA register */ 239 void 240 csc_set_dma_adr(sc, ptr) 241 struct sfas_softc *sc; 242 void *ptr; 243 { 244 return; 245 } 246 247 /* Set DMA transfer counter */ 248 void 249 csc_set_dma_tc(sc, len) 250 struct sfas_softc *sc; 251 unsigned int len; 252 { 253 *sc->sc_fas->sfas_tc_low = len; len >>= 8; 254 *sc->sc_fas->sfas_tc_mid = len; len >>= 8; 255 *sc->sc_fas->sfas_tc_high = len; 256 } 257 258 /* Set DMA mode */ 259 void 260 csc_set_dma_mode(sc, mode) 261 struct sfas_softc *sc; 262 int mode; 263 { 264 } 265 266 /* Initialize DMA for transfer */ 267 int 268 csc_setup_dma(sc, ptr, len, mode) 269 void *sc; 270 void *ptr; 271 int len; 272 int mode; 273 { 274 275 return (0); 276 } 277 278 /* Check if address and len is ok for DMA transfer */ 279 int 280 csc_need_bump(sc, ptr, len) 281 void *sc; 282 void *ptr; 283 int len; 284 { 285 int p; 286 287 p = (int)ptr & 0x03; 288 289 if (p) { 290 p = 4-p; 291 292 if (len < 256) 293 p = len; 294 } 295 296 return(p); 297 } 298 299 /* Interrupt driven routines */ 300 int 301 csc_build_dma_chain(sc, chain, p, l) 302 void *sc; 303 void *chain; 304 void *p; 305 int l; 306 { 307 return(0); 308 } 309 310 /* Turn on/off led */ 311 void 312 csc_led(v, mode) 313 void *v; 314 int mode; 315 { 316 struct sfas_softc *sc = v; 317 csc_regmap_p rp; 318 319 rp = (csc_regmap_p)sc->sc_fas; 320 321 if (mode) { 322 sc->sc_led_status++; 323 } else { 324 if (sc->sc_led_status) 325 sc->sc_led_status--; 326 } 327 } 328