1 /* $NetBSD: csc.c,v 1.15 2009/03/14 15:35:58 dsl Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Cumana SCSI-2 driver uses the SFAS216 generic driver
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: csc.c,v 1.15 2009/03/14 15:35:58 dsl Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/device.h>
44 #include <uvm/uvm_extern.h>
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>
60 int cscmatch(struct device
*, struct cfdata
*, void *);
61 void cscattach(struct device
*, struct device
*, void *);
63 CFATTACH_DECL(csc
, sizeof(struct csc_softc
),
64 cscmatch
, cscattach
, NULL
, NULL
);
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);
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);
77 * if we are a Cumana SCSI-2 card
80 cscmatch(struct device
*pdp
, struct cfdata
*cf
, void *auxp
)
82 struct podule_attach_args
*pa
= (struct podule_attach_args
*)auxp
;
84 /* Look for the card */
85 if (pa
->pa_product
== PODULE_CUMANA_SCSI2
)
89 if (pa
->pa_product
== PODULE_ALSYSTEMS_SCSI
&&
90 podulebus_initloader(pa
) == 0 &&
91 podloader_callloader(pa
, 0, 0) == PRID_CUMANA_SCSI2
)
98 cscattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
100 struct csc_softc
*sc
= (struct csc_softc
*)dp
;
101 struct podule_attach_args
*pa
;
102 csc_regmap_p rp
= &sc
->sc_regmap
;
106 pa
= (struct podule_attach_args
*)auxp
;
108 if (pa
->pa_podule_number
== -1)
109 panic("Podule has disappeared !");
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
;
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
];
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
];
137 sc
->sc_softc
.sc_fas
= (sfas_regmap_p
)rp
;
138 sc
->sc_softc
.sc_spec
= &sc
->sc_specific
;
140 sc
->sc_softc
.sc_led
= csc_led
;
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
;
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 */
151 sc
->sc_softc
.sc_bump_sz
= PAGE_SIZE
;
152 sc
->sc_softc
.sc_bump_pa
= 0x0;
154 sfasinitialize((struct sfas_softc
*)sc
);
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
;
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
;
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
);
175 printf(": host=%d", sc
->sc_softc
.sc_channel
.chan_id
);
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
++) {
181 *rp
->alatch
= (loop
<< 1) |
182 ((sc
->sc_specific
.sc_alatch_defs
& (1 << loop
))?1: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
);
194 sc
->sc_softc
.sc_adapter
.adapt_flags
|= SCSIPI_ADAPT_POLL_ONLY
;
198 /* attach all scsi units on us */
199 config_found(dp
, &sc
->sc_softc
.sc_channel
, scsiprint
);
206 struct sfas_softc
*dev
= arg
;
210 rp
= (csc_regmap_p
)dev
->sc_fas
;
212 if (*rp
->FAS216
.sfas_status
& SFAS_STAT_INTERRUPT_PENDING
) {
215 dev
->sc_status
= *rp
->FAS216
.sfas_status
;
216 dev
->sc_interrupt
= *rp
->FAS216
.sfas_interrupt
;
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
;
224 } while((*rp
->FAS216
.sfas_status
& SFAS_STAT_INTERRUPT_PENDING
)
228 return(0); /* Pass interrupt on down the chain */
231 /* Load transfer address into DMA register */
233 csc_set_dma_adr(struct sfas_softc
*sc
, void *ptr
)
238 /* Set DMA transfer counter */
240 csc_set_dma_tc(struct sfas_softc
*sc
, unsigned int len
)
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
;
249 csc_set_dma_mode(struct sfas_softc
*sc
, int mode
)
253 /* Initialize DMA for transfer */
255 csc_setup_dma(void *sc
, void *ptr
, int len
, int mode
)
261 /* Check if address and len is ok for DMA transfer */
263 csc_need_bump(void *sc
, void *ptr
, int len
)
279 /* Interrupt driven routines */
281 csc_build_dma_chain(void *sc
, void *chain
, void *p
, int l
)
286 /* Turn on/off led */
288 csc_led(void *v
, int mode
)
290 struct sfas_softc
*sc
= v
;
293 rp
= (csc_regmap_p
)sc
->sc_fas
;
298 if (sc
->sc_led_status
)