1*471aeecfSnaddy /* $OpenBSD: tcds.c,v 1.10 2022/04/06 18:59:30 naddy Exp $ */
2aa76beb5Smiod /* $NetBSD: tcds.c,v 1.3 2001/11/13 06:26:10 lukem Exp $ */
3aa76beb5Smiod
4aa76beb5Smiod /*-
5aa76beb5Smiod * Copyright (c) 1998 The NetBSD Foundation, Inc.
6aa76beb5Smiod * All rights reserved.
7aa76beb5Smiod *
8aa76beb5Smiod * This code is derived from software contributed to The NetBSD Foundation
9aa76beb5Smiod * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10aa76beb5Smiod * NASA Ames Research Center.
11aa76beb5Smiod *
12aa76beb5Smiod * Redistribution and use in source and binary forms, with or without
13aa76beb5Smiod * modification, are permitted provided that the following conditions
14aa76beb5Smiod * are met:
15aa76beb5Smiod * 1. Redistributions of source code must retain the above copyright
16aa76beb5Smiod * notice, this list of conditions and the following disclaimer.
17aa76beb5Smiod * 2. Redistributions in binary form must reproduce the above copyright
18aa76beb5Smiod * notice, this list of conditions and the following disclaimer in the
19aa76beb5Smiod * documentation and/or other materials provided with the distribution.
20aa76beb5Smiod *
21aa76beb5Smiod * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22aa76beb5Smiod * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23aa76beb5Smiod * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24aa76beb5Smiod * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25aa76beb5Smiod * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26aa76beb5Smiod * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27aa76beb5Smiod * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28aa76beb5Smiod * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29aa76beb5Smiod * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30aa76beb5Smiod * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31aa76beb5Smiod * POSSIBILITY OF SUCH DAMAGE.
32aa76beb5Smiod */
33aa76beb5Smiod
34aa76beb5Smiod /*
35aa76beb5Smiod * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
36aa76beb5Smiod * All rights reserved.
37aa76beb5Smiod *
38aa76beb5Smiod * Author: Keith Bostic, Chris G. Demetriou
39aa76beb5Smiod *
40aa76beb5Smiod * Permission to use, copy, modify and distribute this software and
41aa76beb5Smiod * its documentation is hereby granted, provided that both the copyright
42aa76beb5Smiod * notice and this permission notice appear in all copies of the
43aa76beb5Smiod * software, derivative works or modified versions, and any portions
44aa76beb5Smiod * thereof, and that both notices appear in supporting documentation.
45aa76beb5Smiod *
46aa76beb5Smiod * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47aa76beb5Smiod * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48aa76beb5Smiod * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49aa76beb5Smiod *
50aa76beb5Smiod * Carnegie Mellon requests users of this software to return to
51aa76beb5Smiod *
52aa76beb5Smiod * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53aa76beb5Smiod * School of Computer Science
54aa76beb5Smiod * Carnegie Mellon University
55aa76beb5Smiod * Pittsburgh PA 15213-3890
56aa76beb5Smiod *
57aa76beb5Smiod * any improvements or extensions that they make and grant Carnegie the
58aa76beb5Smiod * rights to redistribute these changes.
59aa76beb5Smiod */
60aa76beb5Smiod
61aa76beb5Smiod #include <sys/param.h>
62aa76beb5Smiod #include <sys/kernel.h>
63aa76beb5Smiod #include <sys/systm.h>
64aa76beb5Smiod #include <sys/device.h>
65aa76beb5Smiod #include <sys/malloc.h>
66aa76beb5Smiod
67aa76beb5Smiod #ifdef __alpha__
68aa76beb5Smiod #include <machine/rpb.h>
69aa76beb5Smiod #endif /* __alpha__ */
70aa76beb5Smiod
71aa76beb5Smiod #include <scsi/scsi_all.h>
72aa76beb5Smiod #include <scsi/scsiconf.h>
73aa76beb5Smiod
74aa76beb5Smiod #include <dev/ic/ncr53c9xvar.h>
75aa76beb5Smiod
76aa76beb5Smiod #include <machine/bus.h>
77aa76beb5Smiod
78aa76beb5Smiod #include <dev/tc/tcvar.h>
79aa76beb5Smiod #include <dev/tc/tcdsreg.h>
80aa76beb5Smiod #include <dev/tc/tcdsvar.h>
81aa76beb5Smiod
82aa76beb5Smiod struct tcds_softc {
83aa76beb5Smiod struct device sc_dv;
84aa76beb5Smiod bus_space_tag_t sc_bst;
85aa76beb5Smiod bus_space_handle_t sc_bsh;
86aa76beb5Smiod bus_dma_tag_t sc_dmat;
87aa76beb5Smiod void *sc_cookie;
88aa76beb5Smiod int sc_flags;
89aa76beb5Smiod struct tcds_slotconfig sc_slots[2];
90aa76beb5Smiod };
91aa76beb5Smiod
92aa76beb5Smiod /* sc_flags */
93aa76beb5Smiod #define TCDSF_BASEBOARD 0x01 /* baseboard on DEC 3000 */
94aa76beb5Smiod #define TCDSF_FASTSCSI 0x02 /* supports Fast SCSI */
95aa76beb5Smiod
96aa76beb5Smiod /* Definition of the driver for autoconfig. */
97aa76beb5Smiod int tcdsmatch(struct device *, void *, void *);
98aa76beb5Smiod void tcdsattach(struct device *, struct device *, void *);
99aa76beb5Smiod int tcdsprint(void *, const char *);
100aa76beb5Smiod int tcdssubmatch(struct device *, void *, void *);
101aa76beb5Smiod
102*471aeecfSnaddy const struct cfattach tcds_ca = {
103aa76beb5Smiod sizeof(struct tcds_softc), tcdsmatch, tcdsattach,
104aa76beb5Smiod };
105aa76beb5Smiod
106aa76beb5Smiod struct cfdriver tcds_cd = {
107aa76beb5Smiod NULL, "tcds", DV_DULL,
108aa76beb5Smiod };
109aa76beb5Smiod
110aa76beb5Smiod /*static*/ int tcds_intr(void *);
111aa76beb5Smiod /*static*/ int tcds_intrnull(void *);
112aa76beb5Smiod
113aa76beb5Smiod struct tcds_device {
114aa76beb5Smiod const char *td_name;
115aa76beb5Smiod int td_flags;
116aa76beb5Smiod } tcds_devices[] = {
117aa76beb5Smiod #ifdef __alpha__
118aa76beb5Smiod { "PMAZ-DS ", TCDSF_BASEBOARD },
119aa76beb5Smiod { "PMAZ-FS ", TCDSF_BASEBOARD|TCDSF_FASTSCSI },
120aa76beb5Smiod #endif /* __alpha__ */
121aa76beb5Smiod { "PMAZB-AA", 0 },
122aa76beb5Smiod { "PMAZC-AA", TCDSF_FASTSCSI },
123aa76beb5Smiod { NULL, 0 },
124aa76beb5Smiod };
125aa76beb5Smiod
126aa76beb5Smiod struct tcds_device *tcds_lookup(const char *);
127aa76beb5Smiod void tcds_params(struct tcds_softc *, int, int *, int *);
128aa76beb5Smiod
129aa76beb5Smiod struct tcds_device *
tcds_lookup(modname)130aa76beb5Smiod tcds_lookup(modname)
131aa76beb5Smiod const char *modname;
132aa76beb5Smiod {
133aa76beb5Smiod struct tcds_device *td;
134aa76beb5Smiod
135aa76beb5Smiod for (td = tcds_devices; td->td_name != NULL; td++)
136aa76beb5Smiod if (strncmp(td->td_name, modname, TC_ROM_LLEN) == 0)
137aa76beb5Smiod return (td);
138aa76beb5Smiod
139aa76beb5Smiod return (NULL);
140aa76beb5Smiod }
141aa76beb5Smiod
142aa76beb5Smiod int
tcdsmatch(parent,cfdata,aux)143aa76beb5Smiod tcdsmatch(parent, cfdata, aux)
144aa76beb5Smiod struct device *parent;
145aa76beb5Smiod void *cfdata, *aux;
146aa76beb5Smiod {
147aa76beb5Smiod struct tc_attach_args *ta = aux;
148aa76beb5Smiod
149aa76beb5Smiod return (tcds_lookup(ta->ta_modname) != NULL);
150aa76beb5Smiod }
151aa76beb5Smiod
152aa76beb5Smiod void
tcdsattach(parent,self,aux)153aa76beb5Smiod tcdsattach(parent, self, aux)
154aa76beb5Smiod struct device *parent, *self;
155aa76beb5Smiod void *aux;
156aa76beb5Smiod {
157aa76beb5Smiod struct tcds_softc *sc = (struct tcds_softc *)self;
158aa76beb5Smiod struct tc_attach_args *ta = aux;
159aa76beb5Smiod struct tcdsdev_attach_args tcdsdev;
160aa76beb5Smiod struct tcds_slotconfig *slotc;
161aa76beb5Smiod struct tcds_device *td;
162aa76beb5Smiod bus_space_handle_t sbsh[2];
163aa76beb5Smiod int i, gpi2;
164aa76beb5Smiod
165aa76beb5Smiod td = tcds_lookup(ta->ta_modname);
166aa76beb5Smiod if (td == NULL)
167bc84bce2Skrw panic("tcdsattach: impossible");
168aa76beb5Smiod
169aa76beb5Smiod printf(": TurboChannel Dual SCSI");
170aa76beb5Smiod if (td->td_flags & TCDSF_BASEBOARD)
171aa76beb5Smiod printf(" (baseboard)");
172aa76beb5Smiod printf("\n");
173aa76beb5Smiod
174aa76beb5Smiod sc->sc_flags = td->td_flags;
175aa76beb5Smiod
176aa76beb5Smiod sc->sc_bst = ta->ta_memt;
177aa76beb5Smiod sc->sc_dmat = ta->ta_dmat;
178aa76beb5Smiod
179aa76beb5Smiod /*
180aa76beb5Smiod * Map the device.
181aa76beb5Smiod */
182aa76beb5Smiod if (bus_space_map(sc->sc_bst, ta->ta_addr,
183aa76beb5Smiod (TCDS_SCSI1_OFFSET + 0x100), 0, &sc->sc_bsh)) {
184aa76beb5Smiod printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
185aa76beb5Smiod return;
186aa76beb5Smiod }
187aa76beb5Smiod
188aa76beb5Smiod /*
189aa76beb5Smiod * Now, slice off two subregions for the individual NCR SCSI chips.
190aa76beb5Smiod */
191aa76beb5Smiod if (bus_space_subregion(sc->sc_bst, sc->sc_bsh, TCDS_SCSI0_OFFSET,
192aa76beb5Smiod 0x100, &sbsh[0]) ||
193aa76beb5Smiod bus_space_subregion(sc->sc_bst, sc->sc_bsh, TCDS_SCSI1_OFFSET,
194aa76beb5Smiod 0x100, &sbsh[1])) {
195aa76beb5Smiod printf("%s: unable to subregion SCSI chip space\n",
196aa76beb5Smiod sc->sc_dv.dv_xname);
197aa76beb5Smiod return;
198aa76beb5Smiod }
199aa76beb5Smiod
200aa76beb5Smiod sc->sc_cookie = ta->ta_cookie;
201aa76beb5Smiod
2022ab7ce79Smiod tc_intr_establish(parent, sc->sc_cookie, IPL_BIO, tcds_intr, sc,
2032ab7ce79Smiod self->dv_xname);
204aa76beb5Smiod
205aa76beb5Smiod /*
206aa76beb5Smiod * XXX
207aa76beb5Smiod * IMER apparently has some random (or, not so random, but still
208aa76beb5Smiod * not useful) bits set in it when the system boots. Clear it.
209aa76beb5Smiod */
210aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER, 0);
211aa76beb5Smiod
212aa76beb5Smiod /* XXX Initial contents of CIR? */
213aa76beb5Smiod
214aa76beb5Smiod /*
215aa76beb5Smiod * Remember if GPI2 is set in the CIR; we'll need it later.
216aa76beb5Smiod */
217aa76beb5Smiod gpi2 = (bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR) &
218aa76beb5Smiod TCDS_CIR_GPI_2) != 0;
219aa76beb5Smiod
220aa76beb5Smiod /*
221a209c929Smiod * Set up the per-slot definitions for later use.
222aa76beb5Smiod */
223aa76beb5Smiod
224aa76beb5Smiod /* fill in common information first */
225aa76beb5Smiod for (i = 0; i < 2; i++) {
226aa76beb5Smiod slotc = &sc->sc_slots[i];
227aa76beb5Smiod bzero(slotc, sizeof *slotc); /* clear everything */
228aa76beb5Smiod
229aa76beb5Smiod slotc->sc_slot = i;
230aa76beb5Smiod slotc->sc_bst = sc->sc_bst;
231aa76beb5Smiod slotc->sc_bsh = sc->sc_bsh;
232aa76beb5Smiod slotc->sc_intrhand = tcds_intrnull;
233aa76beb5Smiod slotc->sc_intrarg = (void *)(long)i;
234aa76beb5Smiod }
235aa76beb5Smiod
236aa76beb5Smiod /* information for slot 0 */
237aa76beb5Smiod slotc = &sc->sc_slots[0];
238aa76beb5Smiod slotc->sc_resetbits = TCDS_CIR_SCSI0_RESET;
239aa76beb5Smiod slotc->sc_intrmaskbits =
240aa76beb5Smiod TCDS_IMER_SCSI0_MASK | TCDS_IMER_SCSI0_ENB;
241aa76beb5Smiod slotc->sc_intrbits = TCDS_CIR_SCSI0_INT;
242aa76beb5Smiod slotc->sc_dmabits = TCDS_CIR_SCSI0_DMAENA;
243aa76beb5Smiod slotc->sc_errorbits = 0; /* XXX */
244aa76beb5Smiod slotc->sc_sda = TCDS_SCSI0_DMA_ADDR;
245aa76beb5Smiod slotc->sc_dic = TCDS_SCSI0_DMA_INTR;
246aa76beb5Smiod slotc->sc_dud0 = TCDS_SCSI0_DMA_DUD0;
247aa76beb5Smiod slotc->sc_dud1 = TCDS_SCSI0_DMA_DUD1;
248aa76beb5Smiod
249aa76beb5Smiod /* information for slot 1 */
250aa76beb5Smiod slotc = &sc->sc_slots[1];
251aa76beb5Smiod slotc->sc_resetbits = TCDS_CIR_SCSI1_RESET;
252aa76beb5Smiod slotc->sc_intrmaskbits =
253aa76beb5Smiod TCDS_IMER_SCSI1_MASK | TCDS_IMER_SCSI1_ENB;
254aa76beb5Smiod slotc->sc_intrbits = TCDS_CIR_SCSI1_INT;
255aa76beb5Smiod slotc->sc_dmabits = TCDS_CIR_SCSI1_DMAENA;
256aa76beb5Smiod slotc->sc_errorbits = 0; /* XXX */
257aa76beb5Smiod slotc->sc_sda = TCDS_SCSI1_DMA_ADDR;
258aa76beb5Smiod slotc->sc_dic = TCDS_SCSI1_DMA_INTR;
259aa76beb5Smiod slotc->sc_dud0 = TCDS_SCSI1_DMA_DUD0;
260aa76beb5Smiod slotc->sc_dud1 = TCDS_SCSI1_DMA_DUD1;
261aa76beb5Smiod
262aa76beb5Smiod /* find the hardware attached to the TCDS ASIC */
263aa76beb5Smiod for (i = 0; i < 2; i++) {
264aa76beb5Smiod tcds_params(sc, i, &tcdsdev.tcdsda_id,
265aa76beb5Smiod &tcdsdev.tcdsda_fast);
266aa76beb5Smiod
267aa76beb5Smiod tcdsdev.tcdsda_bst = sc->sc_bst;
268aa76beb5Smiod tcdsdev.tcdsda_bsh = sbsh[i];
269aa76beb5Smiod tcdsdev.tcdsda_dmat = sc->sc_dmat;
270aa76beb5Smiod tcdsdev.tcdsda_chip = i;
271aa76beb5Smiod tcdsdev.tcdsda_sc = &sc->sc_slots[i];
272aa76beb5Smiod /*
273aa76beb5Smiod * Determine the chip frequency. TCDSF_FASTSCSI will be set
274aa76beb5Smiod * for TC option cards. For baseboard chips, GPI2 is set, for a
275aa76beb5Smiod * 25MHz clock, else a 40MHz clock.
276aa76beb5Smiod */
277aa76beb5Smiod if ((sc->sc_flags & TCDSF_BASEBOARD && gpi2 == 0) ||
278aa76beb5Smiod sc->sc_flags & TCDSF_FASTSCSI) {
279aa76beb5Smiod tcdsdev.tcdsda_freq = 40000000;
280aa76beb5Smiod tcdsdev.tcdsda_period = tcdsdev.tcdsda_fast ? 4 : 8;
281aa76beb5Smiod } else {
282aa76beb5Smiod tcdsdev.tcdsda_freq = 25000000;
283aa76beb5Smiod tcdsdev.tcdsda_period = 5;
284aa76beb5Smiod }
285aa76beb5Smiod if (sc->sc_flags & TCDSF_BASEBOARD)
286aa76beb5Smiod tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C94;
287aa76beb5Smiod else
288aa76beb5Smiod tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C96;
289aa76beb5Smiod
290aa76beb5Smiod tcds_scsi_reset(tcdsdev.tcdsda_sc);
291aa76beb5Smiod
292aa76beb5Smiod config_found_sm(self, &tcdsdev, tcdsprint, tcdssubmatch);
293aa76beb5Smiod #ifdef __alpha__
294aa76beb5Smiod /*
295aa76beb5Smiod * The second SCSI chip isn't present on the baseboard TCDS
296aa76beb5Smiod * on the DEC Alpha 3000/300 series.
297aa76beb5Smiod */
298aa76beb5Smiod if (sc->sc_flags & TCDSF_BASEBOARD &&
299aa76beb5Smiod cputype == ST_DEC_3000_300)
300aa76beb5Smiod break;
301aa76beb5Smiod #endif /* __alpha__ */
302aa76beb5Smiod }
303aa76beb5Smiod }
304aa76beb5Smiod
305aa76beb5Smiod int
tcdssubmatch(parent,vcf,aux)306aa76beb5Smiod tcdssubmatch(parent, vcf, aux)
307aa76beb5Smiod struct device *parent;
308aa76beb5Smiod void *vcf, *aux;
309aa76beb5Smiod {
310aa76beb5Smiod struct tcdsdev_attach_args *tcdsdev = aux;
311aa76beb5Smiod struct cfdata *cf = vcf;
312aa76beb5Smiod
313aa76beb5Smiod if (cf->cf_loc[0] != -1 &&
314aa76beb5Smiod cf->cf_loc[0] != tcdsdev->tcdsda_chip)
315aa76beb5Smiod return (0);
316aa76beb5Smiod
317aa76beb5Smiod return ((*cf->cf_attach->ca_match)(parent, vcf, aux));
318aa76beb5Smiod }
319aa76beb5Smiod
320aa76beb5Smiod int
tcdsprint(aux,pnp)321aa76beb5Smiod tcdsprint(aux, pnp)
322aa76beb5Smiod void *aux;
323aa76beb5Smiod const char *pnp;
324aa76beb5Smiod {
325aa76beb5Smiod struct tcdsdev_attach_args *tcdsdev = aux;
326aa76beb5Smiod
327aa76beb5Smiod /* Only ASCs can attach to TCDSs; easy. */
328aa76beb5Smiod if (pnp)
329aa76beb5Smiod printf("asc at %s", pnp);
330aa76beb5Smiod
331aa76beb5Smiod printf(" chip %d", tcdsdev->tcdsda_chip);
332aa76beb5Smiod
333aa76beb5Smiod return (UNCONF);
334aa76beb5Smiod }
335aa76beb5Smiod
336aa76beb5Smiod void
tcds_intr_establish(tcds,slot,func,arg,name)3372ab7ce79Smiod tcds_intr_establish(tcds, slot, func, arg, name)
338aa76beb5Smiod struct device *tcds;
339aa76beb5Smiod int slot;
340aa76beb5Smiod int (*func)(void *);
341aa76beb5Smiod void *arg;
3422ab7ce79Smiod const char *name;
343aa76beb5Smiod {
344aa76beb5Smiod struct tcds_softc *sc = (struct tcds_softc *)tcds;
345aa76beb5Smiod
346aa76beb5Smiod if (sc->sc_slots[slot].sc_intrhand != tcds_intrnull)
347aa76beb5Smiod panic("tcds_intr_establish: chip %d twice", slot);
348aa76beb5Smiod
349aa76beb5Smiod sc->sc_slots[slot].sc_intrhand = func;
350aa76beb5Smiod sc->sc_slots[slot].sc_intrarg = arg;
3514667bebbSmatthew evcount_attach(&sc->sc_slots[slot].sc_count, name, NULL);
3522ab7ce79Smiod
353aa76beb5Smiod tcds_scsi_reset(&sc->sc_slots[slot]);
354aa76beb5Smiod }
355aa76beb5Smiod
356aa76beb5Smiod void
tcds_intr_disestablish(tcds,slot)357aa76beb5Smiod tcds_intr_disestablish(tcds, slot)
358aa76beb5Smiod struct device *tcds;
359aa76beb5Smiod int slot;
360aa76beb5Smiod {
361aa76beb5Smiod struct tcds_softc *sc = (struct tcds_softc *)tcds;
362aa76beb5Smiod
363aa76beb5Smiod if (sc->sc_slots[slot].sc_intrhand == tcds_intrnull)
364aa76beb5Smiod panic("tcds_intr_disestablish: chip %d missing intr",
365aa76beb5Smiod slot);
366aa76beb5Smiod
367aa76beb5Smiod sc->sc_slots[slot].sc_intrhand = tcds_intrnull;
368aa76beb5Smiod sc->sc_slots[slot].sc_intrarg = (void *)(u_long)slot;
3692ab7ce79Smiod evcount_detach(&sc->sc_slots[slot].sc_count);
370aa76beb5Smiod
371aa76beb5Smiod tcds_dma_enable(&sc->sc_slots[slot], 0);
372aa76beb5Smiod tcds_scsi_enable(&sc->sc_slots[slot], 0);
373aa76beb5Smiod }
374aa76beb5Smiod
375aa76beb5Smiod int
tcds_intrnull(val)376aa76beb5Smiod tcds_intrnull(val)
377aa76beb5Smiod void *val;
378aa76beb5Smiod {
379aa76beb5Smiod
380bc84bce2Skrw panic("tcds_intrnull: uncaught TCDS intr for chip %lu",
381aa76beb5Smiod (u_long)val);
382aa76beb5Smiod }
383aa76beb5Smiod
384aa76beb5Smiod void
tcds_scsi_reset(sc)385aa76beb5Smiod tcds_scsi_reset(sc)
386aa76beb5Smiod struct tcds_slotconfig *sc;
387aa76beb5Smiod {
388aa76beb5Smiod u_int32_t cir;
389aa76beb5Smiod
390aa76beb5Smiod tcds_dma_enable(sc, 0);
391aa76beb5Smiod tcds_scsi_enable(sc, 0);
392aa76beb5Smiod
393aa76beb5Smiod cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
394aa76beb5Smiod TCDS_CIR_CLR(cir, sc->sc_resetbits);
395aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
396aa76beb5Smiod
397aa76beb5Smiod DELAY(1);
398aa76beb5Smiod
399aa76beb5Smiod cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
400aa76beb5Smiod TCDS_CIR_SET(cir, sc->sc_resetbits);
401aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
402aa76beb5Smiod
403aa76beb5Smiod tcds_scsi_enable(sc, 1);
404aa76beb5Smiod tcds_dma_enable(sc, 1);
405aa76beb5Smiod }
406aa76beb5Smiod
407aa76beb5Smiod void
tcds_scsi_enable(sc,on)408aa76beb5Smiod tcds_scsi_enable(sc, on)
409aa76beb5Smiod struct tcds_slotconfig *sc;
410aa76beb5Smiod int on;
411aa76beb5Smiod {
412aa76beb5Smiod u_int32_t imer;
413aa76beb5Smiod
414aa76beb5Smiod imer = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER);
415aa76beb5Smiod
416aa76beb5Smiod if (on)
417aa76beb5Smiod imer |= sc->sc_intrmaskbits;
418aa76beb5Smiod else
419aa76beb5Smiod imer &= ~sc->sc_intrmaskbits;
420aa76beb5Smiod
421aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_IMER, imer);
422aa76beb5Smiod }
423aa76beb5Smiod
424aa76beb5Smiod void
tcds_dma_enable(sc,on)425aa76beb5Smiod tcds_dma_enable(sc, on)
426aa76beb5Smiod struct tcds_slotconfig *sc;
427aa76beb5Smiod int on;
428aa76beb5Smiod {
429aa76beb5Smiod u_int32_t cir;
430aa76beb5Smiod
431aa76beb5Smiod cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
432aa76beb5Smiod
433aa76beb5Smiod /* XXX Clear/set IOSLOT/PBS bits. */
434aa76beb5Smiod if (on)
435aa76beb5Smiod TCDS_CIR_SET(cir, sc->sc_dmabits);
436aa76beb5Smiod else
437aa76beb5Smiod TCDS_CIR_CLR(cir, sc->sc_dmabits);
438aa76beb5Smiod
439aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, cir);
440aa76beb5Smiod }
441aa76beb5Smiod
442aa76beb5Smiod int
tcds_scsi_isintr(sc,clear)443aa76beb5Smiod tcds_scsi_isintr(sc, clear)
444aa76beb5Smiod struct tcds_slotconfig *sc;
445aa76beb5Smiod int clear;
446aa76beb5Smiod {
447aa76beb5Smiod u_int32_t cir;
448aa76beb5Smiod
449aa76beb5Smiod cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
450aa76beb5Smiod
451aa76beb5Smiod if ((cir & sc->sc_intrbits) != 0) {
452aa76beb5Smiod if (clear) {
453aa76beb5Smiod TCDS_CIR_CLR(cir, sc->sc_intrbits);
454aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR,
455aa76beb5Smiod cir);
456aa76beb5Smiod }
457aa76beb5Smiod return (1);
458aa76beb5Smiod } else
459aa76beb5Smiod return (0);
460aa76beb5Smiod }
461aa76beb5Smiod
462aa76beb5Smiod int
tcds_scsi_iserr(sc)463aa76beb5Smiod tcds_scsi_iserr(sc)
464aa76beb5Smiod struct tcds_slotconfig *sc;
465aa76beb5Smiod {
466aa76beb5Smiod u_int32_t cir;
467aa76beb5Smiod
468aa76beb5Smiod cir = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
469aa76beb5Smiod return ((cir & sc->sc_errorbits) != 0);
470aa76beb5Smiod }
471aa76beb5Smiod
472aa76beb5Smiod int
tcds_intr(arg)473aa76beb5Smiod tcds_intr(arg)
474aa76beb5Smiod void *arg;
475aa76beb5Smiod {
476aa76beb5Smiod struct tcds_softc *sc = arg;
477aa76beb5Smiod u_int32_t ir, ir0;
478aa76beb5Smiod
479aa76beb5Smiod /*
480aa76beb5Smiod * XXX
481aa76beb5Smiod * Copy and clear (gag!) the interrupts.
482aa76beb5Smiod */
483aa76beb5Smiod ir = ir0 = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR);
484aa76beb5Smiod TCDS_CIR_CLR(ir0, TCDS_CIR_ALLINTR);
485aa76beb5Smiod bus_space_write_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR, ir0);
486aa76beb5Smiod tc_syncbus();
487aa76beb5Smiod
488aa76beb5Smiod #define CHECKINTR(slot) \
489aa76beb5Smiod if (ir & sc->sc_slots[slot].sc_intrbits) { \
49084b67413Saaron sc->sc_slots[slot].sc_count.ec_count++; \
491aa76beb5Smiod (void)(*sc->sc_slots[slot].sc_intrhand) \
492aa76beb5Smiod (sc->sc_slots[slot].sc_intrarg); \
493aa76beb5Smiod }
494aa76beb5Smiod CHECKINTR(0);
495aa76beb5Smiod CHECKINTR(1);
496aa76beb5Smiod #undef CHECKINTR
497aa76beb5Smiod
498aa76beb5Smiod #ifdef DIAGNOSTIC
499aa76beb5Smiod /*
500aa76beb5Smiod * Interrupts not currently handled, but would like to know if they
501aa76beb5Smiod * occur.
502aa76beb5Smiod *
503aa76beb5Smiod * XXX
504aa76beb5Smiod * Don't know if we have to set the interrupt mask and enable bits
505aa76beb5Smiod * in the IMER to allow some of them to happen?
506aa76beb5Smiod */
507aa76beb5Smiod #define PRINTINTR(msg, bits) \
508aa76beb5Smiod if (ir & bits) \
509aa76beb5Smiod printf("%s: %s", sc->sc_dv.dv_xname, msg);
510aa76beb5Smiod PRINTINTR("SCSI0 DREQ interrupt.\n", TCDS_CIR_SCSI0_DREQ);
511aa76beb5Smiod PRINTINTR("SCSI1 DREQ interrupt.\n", TCDS_CIR_SCSI1_DREQ);
512aa76beb5Smiod PRINTINTR("SCSI0 prefetch interrupt.\n", TCDS_CIR_SCSI0_PREFETCH);
513aa76beb5Smiod PRINTINTR("SCSI1 prefetch interrupt.\n", TCDS_CIR_SCSI1_PREFETCH);
514aa76beb5Smiod PRINTINTR("SCSI0 DMA error.\n", TCDS_CIR_SCSI0_DMA);
515aa76beb5Smiod PRINTINTR("SCSI1 DMA error.\n", TCDS_CIR_SCSI1_DMA);
516aa76beb5Smiod PRINTINTR("SCSI0 DB parity error.\n", TCDS_CIR_SCSI0_DB);
517aa76beb5Smiod PRINTINTR("SCSI1 DB parity error.\n", TCDS_CIR_SCSI1_DB);
518aa76beb5Smiod PRINTINTR("SCSI0 DMA buffer parity error.\n", TCDS_CIR_SCSI0_DMAB_PAR);
519aa76beb5Smiod PRINTINTR("SCSI1 DMA buffer parity error.\n", TCDS_CIR_SCSI1_DMAB_PAR);
520aa76beb5Smiod PRINTINTR("SCSI0 DMA read parity error.\n", TCDS_CIR_SCSI0_DMAR_PAR);
521aa76beb5Smiod PRINTINTR("SCSI1 DMA read parity error.\n", TCDS_CIR_SCSI1_DMAR_PAR);
522aa76beb5Smiod PRINTINTR("TC write parity error.\n", TCDS_CIR_TCIOW_PAR);
523aa76beb5Smiod PRINTINTR("TC I/O address parity error.\n", TCDS_CIR_TCIOA_PAR);
524aa76beb5Smiod #undef PRINTINTR
525aa76beb5Smiod #endif
526aa76beb5Smiod
527641d5c7cSmpi tc_mb();
528aa76beb5Smiod
529aa76beb5Smiod return (1);
530aa76beb5Smiod }
531aa76beb5Smiod
532aa76beb5Smiod void
tcds_params(sc,chip,idp,fastp)533aa76beb5Smiod tcds_params(sc, chip, idp, fastp)
534aa76beb5Smiod struct tcds_softc *sc;
535aa76beb5Smiod int chip, *idp, *fastp;
536aa76beb5Smiod {
537aa76beb5Smiod int id, fast;
538aa76beb5Smiod u_int32_t ids;
539aa76beb5Smiod
540aa76beb5Smiod #ifdef __alpha__
541aa76beb5Smiod if (sc->sc_flags & TCDSF_BASEBOARD) {
542aa76beb5Smiod extern u_int8_t dec_3000_scsiid[], dec_3000_scsifast[];
543aa76beb5Smiod
544aa76beb5Smiod id = dec_3000_scsiid[chip];
545aa76beb5Smiod fast = dec_3000_scsifast[chip];
546aa76beb5Smiod } else
547aa76beb5Smiod #endif /* __alpha__ */
548aa76beb5Smiod {
549aa76beb5Smiod /*
550aa76beb5Smiod * SCSI IDs are stored in the EEPROM, along with whether or
551aa76beb5Smiod * not the device is "fast". Chip 0 is the high nibble,
552aa76beb5Smiod * chip 1 the low nibble.
553aa76beb5Smiod */
554aa76beb5Smiod ids = bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_EEPROM_IDS);
555aa76beb5Smiod if (chip == 0)
556aa76beb5Smiod ids >>= 4;
557aa76beb5Smiod
558aa76beb5Smiod id = ids & 0x7;
559aa76beb5Smiod fast = ids & 0x8;
560aa76beb5Smiod }
561aa76beb5Smiod
562aa76beb5Smiod if (id < 0 || id > 7) {
563aa76beb5Smiod printf("%s: WARNING: bad SCSI ID %d for chip %d, using 7\n",
564aa76beb5Smiod sc->sc_dv.dv_xname, id, chip);
565aa76beb5Smiod id = 7;
566aa76beb5Smiod }
567aa76beb5Smiod
568aa76beb5Smiod if (fast)
569aa76beb5Smiod printf("%s: fast mode set for chip %d\n",
570aa76beb5Smiod sc->sc_dv.dv_xname, chip);
571aa76beb5Smiod
572aa76beb5Smiod *idp = id;
573aa76beb5Smiod *fastp = fast;
574aa76beb5Smiod }
575