hcsc.c revision 1.1 1 1.1 bjh21 /* $NetBSD: hcsc.c,v 1.1 2001/05/26 23:01:19 bjh21 Exp $ */
2 1.1 bjh21
3 1.1 bjh21 /*
4 1.1 bjh21 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 bjh21 * All rights reserved.
6 1.1 bjh21 *
7 1.1 bjh21 * This code is derived from software contributed to The NetBSD Foundation
8 1.1 bjh21 * by Mark Brinicombe of Causality Limited.
9 1.1 bjh21 *
10 1.1 bjh21 * Redistribution and use in source and binary forms, with or without
11 1.1 bjh21 * modification, are permitted provided that the following conditions
12 1.1 bjh21 * are met:
13 1.1 bjh21 * 1. Redistributions of source code must retain the above copyright
14 1.1 bjh21 * notice, this list of conditions and the following disclaimer.
15 1.1 bjh21 * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 bjh21 * notice, this list of conditions and the following disclaimer in the
17 1.1 bjh21 * documentation and/or other materials provided with the distribution.
18 1.1 bjh21 * 3. All advertising materials mentioning features or use of this software
19 1.1 bjh21 * must display the following acknowledgement:
20 1.1 bjh21 * This product includes software developed by the NetBSD
21 1.1 bjh21 * Foundation, Inc. and its contributors.
22 1.1 bjh21 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 bjh21 * contributors may be used to endorse or promote products derived
24 1.1 bjh21 * from this software without specific prior written permission.
25 1.1 bjh21 *
26 1.1 bjh21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 bjh21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 bjh21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 bjh21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 bjh21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 bjh21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 bjh21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 bjh21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 bjh21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 bjh21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 bjh21 * POSSIBILITY OF SUCH DAMAGE.
37 1.1 bjh21 */
38 1.1 bjh21
39 1.1 bjh21 /*
40 1.1 bjh21 * HCCS 8-bit SCSI driver using the generic NCR5380 driver
41 1.1 bjh21 */
42 1.1 bjh21
43 1.1 bjh21 #include <sys/param.h>
44 1.1 bjh21
45 1.1 bjh21 __KERNEL_RCSID(0, "$NetBSD: hcsc.c,v 1.1 2001/05/26 23:01:19 bjh21 Exp $");
46 1.1 bjh21
47 1.1 bjh21 #include <sys/systm.h>
48 1.1 bjh21 #include <sys/kernel.h>
49 1.1 bjh21 #include <sys/device.h>
50 1.1 bjh21 #include <sys/buf.h>
51 1.1 bjh21 #include <dev/scsipi/scsi_all.h>
52 1.1 bjh21 #include <dev/scsipi/scsipi_all.h>
53 1.1 bjh21 #include <dev/scsipi/scsiconf.h>
54 1.1 bjh21
55 1.1 bjh21 #include <dev/ic/ncr5380reg.h>
56 1.1 bjh21 #include <dev/ic/ncr5380var.h>
57 1.1 bjh21
58 1.1 bjh21 #include <machine/bootconfig.h>
59 1.1 bjh21
60 1.1 bjh21 #include <dev/podulebus/podulebus.h>
61 1.1 bjh21 #include <dev/podulebus/podules.h>
62 1.1 bjh21
63 1.1 bjh21 void hcsc_attach (struct device *, struct device *, void *);
64 1.1 bjh21 int hcsc_match (struct device *, struct cfdata *, void *);
65 1.1 bjh21
66 1.1 bjh21 /*
67 1.1 bjh21 * HCCS 8-bit SCSI softc structure.
68 1.1 bjh21 *
69 1.1 bjh21 * Contains the generic ncr5380 device node, podule information and
70 1.1 bjh21 * global information required by the driver.
71 1.1 bjh21 */
72 1.1 bjh21
73 1.1 bjh21 struct hcsc_softc {
74 1.1 bjh21 struct ncr5380_softc sc_ncr5380;
75 1.1 bjh21 void *sc_ih;
76 1.1 bjh21 struct evcnt sc_intrcnt;
77 1.1 bjh21 };
78 1.1 bjh21
79 1.1 bjh21 struct cfattach hcsc_ca = {
80 1.1 bjh21 sizeof(struct hcsc_softc), hcsc_match, hcsc_attach
81 1.1 bjh21 };
82 1.1 bjh21
83 1.1 bjh21 /*
84 1.1 bjh21 * Card probe function
85 1.1 bjh21 *
86 1.1 bjh21 * Just match the manufacturer and podule ID's
87 1.1 bjh21 */
88 1.1 bjh21
89 1.1 bjh21 int
90 1.1 bjh21 hcsc_match(struct device *parent, struct cfdata *cf, void *aux)
91 1.1 bjh21 {
92 1.1 bjh21 struct podulebus_attach_args *pa = aux;
93 1.1 bjh21
94 1.1 bjh21 if (matchpodule(pa, MANUFACTURER_HCCS, PODULE_HCCS_IDESCSI, -1) == 0)
95 1.1 bjh21 return(0);
96 1.1 bjh21
97 1.1 bjh21 return(1);
98 1.1 bjh21 }
99 1.1 bjh21
100 1.1 bjh21 /*
101 1.1 bjh21 * Card attach function
102 1.1 bjh21 *
103 1.1 bjh21 */
104 1.1 bjh21
105 1.1 bjh21 void
106 1.1 bjh21 hcsc_attach(struct device *parent, struct device *self, void *aux)
107 1.1 bjh21 {
108 1.1 bjh21 struct hcsc_softc *sc = (struct hcsc_softc *)self;
109 1.1 bjh21 struct podulebus_attach_args *pa = aux;
110 1.1 bjh21 u_char *iobase;
111 1.1 bjh21 char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
112 1.1 bjh21
113 1.1 bjh21 sc->sc_ncr5380.sc_min_dma_len = 0;
114 1.1 bjh21 sc->sc_ncr5380.sc_no_disconnect = 0xff;
115 1.1 bjh21 sc->sc_ncr5380.sc_parity_disable = 0xff;
116 1.1 bjh21
117 1.1 bjh21 sc->sc_ncr5380.sc_dma_alloc = NULL;
118 1.1 bjh21 sc->sc_ncr5380.sc_dma_free = NULL;
119 1.1 bjh21 sc->sc_ncr5380.sc_dma_poll = NULL;
120 1.1 bjh21 sc->sc_ncr5380.sc_dma_setup = NULL;
121 1.1 bjh21 sc->sc_ncr5380.sc_dma_start = NULL;
122 1.1 bjh21 sc->sc_ncr5380.sc_dma_eop = NULL;
123 1.1 bjh21 sc->sc_ncr5380.sc_dma_stop = NULL;
124 1.1 bjh21 sc->sc_ncr5380.sc_intr_on = NULL;
125 1.1 bjh21 sc->sc_ncr5380.sc_intr_off = NULL;
126 1.1 bjh21
127 1.1 bjh21 #ifdef NCR5380_USE_BUS_SPACE
128 1.1 bjh21 sc->sc_ncr5380.sc_regt = pa->pa_fast_t;
129 1.1 bjh21 bus_space_map(sc->sc_ncr5380.sc_regt, pa->pa_fast_base + 0x2000, 8, 0,
130 1.1 bjh21 &sc->sc_ncr5380.sc_regh);
131 1.1 bjh21 sc->sc_ncr5380.sci_r0 = 0;
132 1.1 bjh21 sc->sc_ncr5380.sci_r1 = 1;
133 1.1 bjh21 sc->sc_ncr5380.sci_r2 = 2;
134 1.1 bjh21 sc->sc_ncr5380.sci_r3 = 3;
135 1.1 bjh21 sc->sc_ncr5380.sci_r4 = 4;
136 1.1 bjh21 sc->sc_ncr5380.sci_r5 = 5;
137 1.1 bjh21 sc->sc_ncr5380.sci_r6 = 6;
138 1.1 bjh21 sc->sc_ncr5380.sci_r7 = 7;
139 1.1 bjh21 #else
140 1.1 bjh21 iobase = (u_char *)pa->pa_fast_base + 0x2000;
141 1.1 bjh21 sc->sc_ncr5380.sci_r0 = iobase + 0;
142 1.1 bjh21 sc->sc_ncr5380.sci_r1 = iobase + 4;
143 1.1 bjh21 sc->sc_ncr5380.sci_r2 = iobase + 8;
144 1.1 bjh21 sc->sc_ncr5380.sci_r3 = iobase + 12;
145 1.1 bjh21 sc->sc_ncr5380.sci_r4 = iobase + 16;
146 1.1 bjh21 sc->sc_ncr5380.sci_r5 = iobase + 20;
147 1.1 bjh21 sc->sc_ncr5380.sci_r6 = iobase + 24;
148 1.1 bjh21 sc->sc_ncr5380.sci_r7 = iobase + 28;
149 1.1 bjh21 #endif
150 1.1 bjh21
151 1.1 bjh21 sc->sc_ncr5380.sc_rev = NCR_VARIANT_DP8490;
152 1.1 bjh21
153 1.1 bjh21 sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
154 1.1 bjh21 sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
155 1.1 bjh21
156 1.1 bjh21 /* Provide an override for the host id */
157 1.1 bjh21 sc->sc_ncr5380.sc_channel.chan_id = 7;
158 1.1 bjh21 sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
159 1.1 bjh21 (void)get_bootconf_option(boot_args, hi_option,
160 1.1 bjh21 BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
161 1.1 bjh21 sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
162 1.1 bjh21
163 1.1 bjh21 printf(": host=%d, using 8 bit PIO\n",
164 1.1 bjh21 sc->sc_ncr5380.sc_channel.chan_id);
165 1.1 bjh21
166 1.1 bjh21 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
167 1.1 bjh21 self->dv_xname, "intr");
168 1.1 bjh21 sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, ncr5380_intr,
169 1.1 bjh21 sc, &sc->sc_intrcnt);
170 1.1 bjh21
171 1.1 bjh21 ncr5380_attach(&sc->sc_ncr5380);
172 1.1 bjh21 }
173