siop_common.c revision 1.1 1 1.1 bouyer /* $NetBSD: siop_common.c,v 1.1 2000/05/15 07:48:25 bouyer Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2000 Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.1 bouyer * must display the following acknowledgement:
16 1.1 bouyer * This product includes software developed by Manuel Bouyer
17 1.1 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.1 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer *
31 1.1 bouyer */
32 1.1 bouyer
33 1.1 bouyer /* SYM53c7/8xx PCI-SCSI I/O Processors driver */
34 1.1 bouyer
35 1.1 bouyer #include <sys/param.h>
36 1.1 bouyer #include <sys/systm.h>
37 1.1 bouyer #include <sys/device.h>
38 1.1 bouyer #include <sys/malloc.h>
39 1.1 bouyer #include <sys/buf.h>
40 1.1 bouyer #include <sys/kernel.h>
41 1.1 bouyer #include <sys/scsiio.h>
42 1.1 bouyer
43 1.1 bouyer #include <machine/endian.h>
44 1.1 bouyer #include <machine/bus.h>
45 1.1 bouyer
46 1.1 bouyer #include <vm/vm.h>
47 1.1 bouyer #include <vm/vm_param.h>
48 1.1 bouyer #include <vm/vm_kern.h>
49 1.1 bouyer
50 1.1 bouyer #include <dev/scsipi/scsi_all.h>
51 1.1 bouyer #include <dev/scsipi/scsi_message.h>
52 1.1 bouyer #include <dev/scsipi/scsipi_all.h>
53 1.1 bouyer
54 1.1 bouyer #include <dev/scsipi/scsiconf.h>
55 1.1 bouyer
56 1.1 bouyer #include <dev/ic/siopreg.h>
57 1.1 bouyer #include <dev/ic/siopvar.h>
58 1.1 bouyer #include <dev/ic/siopvar_common.h>
59 1.1 bouyer
60 1.1 bouyer #define DEBUG
61 1.1 bouyer
62 1.1 bouyer void
63 1.1 bouyer siop_common_reset(sc)
64 1.1 bouyer struct siop_softc *sc;
65 1.1 bouyer {
66 1.1 bouyer u_int32_t stest3;
67 1.1 bouyer
68 1.1 bouyer /* reset the chip */
69 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_ISTAT, ISTAT_SRST);
70 1.1 bouyer delay(1000);
71 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_ISTAT, 0);
72 1.1 bouyer
73 1.1 bouyer /* init registers */
74 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL0,
75 1.1 bouyer SCNTL0_ARB_MASK | SCNTL0_EPC | SCNTL0_AAP);
76 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL1, 0);
77 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL3, sc->clock_div);
78 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCXFER, 0);
79 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DIEN, 0xff);
80 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SIEN0,
81 1.1 bouyer 0xff & ~(SIEN0_CMP | SIEN0_SEL | SIEN0_RSL));
82 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SIEN1,
83 1.1 bouyer 0xff & ~(SIEN1_HTH | SIEN1_GEN));
84 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST2, 0);
85 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST3, STEST3_TE);
86 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STIME0,
87 1.1 bouyer (0xb << STIME0_SEL_SHIFT));
88 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCID,
89 1.1 bouyer sc->sc_link.scsipi_scsi.adapter_target | SCID_RRE);
90 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_RESPID0,
91 1.1 bouyer 1 << sc->sc_link.scsipi_scsi.adapter_target);
92 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DCNTL,
93 1.1 bouyer (sc->features & SF_CHIP_PF) ? DCNTL_COM | DCNTL_PFEN : DCNTL_COM);
94 1.1 bouyer
95 1.1 bouyer /* enable clock doubler or quadruler if appropriate */
96 1.1 bouyer if (sc->features & (SF_CHIP_DBLR | SF_CHIP_QUAD)) {
97 1.1 bouyer stest3 = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_STEST3);
98 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST1,
99 1.1 bouyer STEST1_DBLEN);
100 1.1 bouyer if (sc->features & SF_CHIP_QUAD) {
101 1.1 bouyer /* wait for PPL to lock */
102 1.1 bouyer while ((bus_space_read_1(sc->sc_rt, sc->sc_rh,
103 1.1 bouyer SIOP_STEST4) & STEST4_LOCK) == 0)
104 1.1 bouyer delay(10);
105 1.1 bouyer } else {
106 1.1 bouyer /* data sheet says 20us - more won't hurt */
107 1.1 bouyer delay(100);
108 1.1 bouyer }
109 1.1 bouyer /* halt scsi clock, select doubler/quad, restart clock */
110 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST3,
111 1.1 bouyer stest3 | STEST3_HSC);
112 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST1,
113 1.1 bouyer STEST1_DBLEN | STEST1_DBLSEL);
114 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST3, stest3);
115 1.1 bouyer } else {
116 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_STEST1, 0);
117 1.1 bouyer }
118 1.1 bouyer if (sc->features & SF_CHIP_FIFO)
119 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST5,
120 1.1 bouyer bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST5) |
121 1.1 bouyer CTEST5_DFS);
122 1.1 bouyer
123 1.1 bouyer sc->sc_reset(sc);
124 1.1 bouyer }
125 1.1 bouyer
126 1.1 bouyer int
127 1.1 bouyer siop_wdtr_neg(siop_cmd)
128 1.1 bouyer struct siop_cmd *siop_cmd;
129 1.1 bouyer {
130 1.1 bouyer struct siop_softc *sc = siop_cmd->siop_target->siop_sc;
131 1.1 bouyer struct siop_target *siop_target = siop_cmd->siop_target;
132 1.1 bouyer int target = siop_cmd->xs->sc_link->scsipi_scsi.target;
133 1.1 bouyer
134 1.1 bouyer if (siop_target->status == TARST_WIDE_NEG) {
135 1.1 bouyer /* we initiated wide negotiation */
136 1.1 bouyer switch (siop_cmd->siop_table->msg_in[3]) {
137 1.1 bouyer case MSG_EXT_WDTR_BUS_8_BIT:
138 1.1 bouyer printf("%s: target %d using 8bit transfers\n",
139 1.1 bouyer sc->sc_dev.dv_xname, target);
140 1.1 bouyer siop_target->flags &= ~SF_BUS_WIDE;
141 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_EWS << 24);
142 1.1 bouyer break;
143 1.1 bouyer case MSG_EXT_WDTR_BUS_16_BIT:
144 1.1 bouyer if (sc->features & SF_BUS_WIDE) {
145 1.1 bouyer printf("%s: target %d using 16bit transfers\n",
146 1.1 bouyer sc->sc_dev.dv_xname, target);
147 1.1 bouyer siop_target->flags |= TARF_WIDE;
148 1.1 bouyer sc->targets[target]->id |= (SCNTL3_EWS << 24);
149 1.1 bouyer break;
150 1.1 bouyer }
151 1.1 bouyer /* FALLTHROUH */
152 1.1 bouyer default:
153 1.1 bouyer /*
154 1.1 bouyer * hum, we got more than what we can handle, shoudn't
155 1.1 bouyer * happen. Reject, and stay async
156 1.1 bouyer */
157 1.1 bouyer siop_target->flags &= ~TARF_WIDE;
158 1.1 bouyer siop_target->status = TARST_OK;
159 1.1 bouyer printf("%s: rejecting invalid wide negotiation from "
160 1.1 bouyer "target %d (%d)\n", sc->sc_dev.dv_xname, target,
161 1.1 bouyer siop_cmd->siop_table->msg_in[3]);
162 1.1 bouyer siop_cmd->siop_table->t_msgout.count= htole32(1);
163 1.1 bouyer siop_cmd->siop_table->t_msgout.addr =
164 1.1 bouyer htole32(siop_cmd->dsa);
165 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_MESSAGE_REJECT;
166 1.1 bouyer return SIOP_NEG_MSGOUT;
167 1.1 bouyer }
168 1.1 bouyer siop_cmd->siop_table->id =
169 1.1 bouyer htole32(sc->targets[target]->id);
170 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh,
171 1.1 bouyer SIOP_SCNTL3,
172 1.1 bouyer (sc->targets[target]->id >> 24) & 0xff);
173 1.1 bouyer /* we now need to do sync */
174 1.1 bouyer siop_target->status = TARST_SYNC_NEG;
175 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_EXTENDED;
176 1.1 bouyer siop_cmd->siop_table->msg_out[1] = MSG_EXT_SDTR_LEN;
177 1.1 bouyer siop_cmd->siop_table->msg_out[2] = MSG_EXT_SDTR;
178 1.1 bouyer siop_cmd->siop_table->msg_out[3] = sc->minsync;
179 1.1 bouyer siop_cmd->siop_table->msg_out[4] = sc->maxoff;
180 1.1 bouyer siop_cmd->siop_table->t_msgout.count =
181 1.1 bouyer htole32(MSG_EXT_SDTR_LEN + 2);
182 1.1 bouyer siop_cmd->siop_table->t_msgout.addr = htole32(siop_cmd->dsa);
183 1.1 bouyer return SIOP_NEG_MSGOUT;
184 1.1 bouyer } else {
185 1.1 bouyer /* target initiated wide negotiation */
186 1.1 bouyer if (siop_cmd->siop_table->msg_in[3] >= MSG_EXT_WDTR_BUS_16_BIT
187 1.1 bouyer && (sc->features & SF_BUS_WIDE)) {
188 1.1 bouyer printf("%s: target %d using 16bit transfers\n",
189 1.1 bouyer sc->sc_dev.dv_xname, target);
190 1.1 bouyer siop_target->flags |= TARF_WIDE;
191 1.1 bouyer sc->targets[target]->id |= SCNTL3_EWS << 24;
192 1.1 bouyer siop_cmd->siop_table->msg_out[3] =
193 1.1 bouyer MSG_EXT_WDTR_BUS_16_BIT;
194 1.1 bouyer } else {
195 1.1 bouyer printf("%s: target %d using 8bit transfers\n",
196 1.1 bouyer sc->sc_dev.dv_xname, target);
197 1.1 bouyer siop_target->flags &= ~SF_BUS_WIDE;
198 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_EWS << 24);
199 1.1 bouyer siop_cmd->siop_table->msg_out[3] =
200 1.1 bouyer MSG_EXT_WDTR_BUS_8_BIT;
201 1.1 bouyer }
202 1.1 bouyer siop_cmd->siop_table->id =
203 1.1 bouyer htole32(sc->targets[target]->id);
204 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL3,
205 1.1 bouyer (sc->targets[target]->id >> 24) & 0xff);
206 1.1 bouyer /*
207 1.1 bouyer * we did reset wide parameters, so fall back to async,
208 1.1 bouyer * but don't shedule a sync neg, target should initiate it
209 1.1 bouyer */
210 1.1 bouyer siop_target->status = TARST_OK;
211 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_EXTENDED;
212 1.1 bouyer siop_cmd->siop_table->msg_out[1] = MSG_EXT_WDTR_LEN;
213 1.1 bouyer siop_cmd->siop_table->msg_out[2] = MSG_EXT_WDTR;
214 1.1 bouyer siop_cmd->siop_table->t_msgout.count=
215 1.1 bouyer htole32(MSG_EXT_WDTR_LEN + 2);
216 1.1 bouyer siop_cmd->siop_table->t_msgout.addr = htole32(siop_cmd->dsa);
217 1.1 bouyer return SIOP_NEG_MSGOUT;
218 1.1 bouyer }
219 1.1 bouyer }
220 1.1 bouyer
221 1.1 bouyer int
222 1.1 bouyer siop_sdtr_neg(siop_cmd)
223 1.1 bouyer struct siop_cmd *siop_cmd;
224 1.1 bouyer {
225 1.1 bouyer struct siop_softc *sc = siop_cmd->siop_target->siop_sc;
226 1.1 bouyer struct siop_target *siop_target = siop_cmd->siop_target;
227 1.1 bouyer int target = siop_cmd->xs->sc_link->scsipi_scsi.target;
228 1.1 bouyer int sync, offset, i;
229 1.1 bouyer int send_msgout = 0;
230 1.1 bouyer
231 1.1 bouyer sync = siop_cmd->siop_table->msg_in[3];
232 1.1 bouyer offset = siop_cmd->siop_table->msg_in[4];
233 1.1 bouyer
234 1.1 bouyer if (siop_target->status == TARST_SYNC_NEG) {
235 1.1 bouyer /* we initiated sync negotiation */
236 1.1 bouyer siop_target->status = TARST_OK;
237 1.1 bouyer #ifdef DEBUG
238 1.1 bouyer printf("sdtr: sync %d offset %d\n", sync, offset);
239 1.1 bouyer #endif
240 1.1 bouyer if (offset > sc->maxoff || sync < sc->minsync ||
241 1.1 bouyer sync > sc->maxsync)
242 1.1 bouyer goto reject;
243 1.1 bouyer for (i = 0; i < sizeof(scf_period) / sizeof(scf_period[0]);
244 1.1 bouyer i++) {
245 1.1 bouyer if (sc->clock_period != scf_period[i].clock)
246 1.1 bouyer continue;
247 1.1 bouyer if (scf_period[i].period == sync) {
248 1.1 bouyer /* ok, found it. we now are sync. */
249 1.1 bouyer printf("%s: target %d now synchronous at "
250 1.1 bouyer "%sMhz, offset %d\n", sc->sc_dev.dv_xname,
251 1.1 bouyer target, scf_period[i].rate, offset);
252 1.1 bouyer sc->targets[target]->id &=
253 1.1 bouyer ~(SCNTL3_SCF_MASK << 24);
254 1.1 bouyer sc->targets[target]->id |= scf_period[i].scf
255 1.1 bouyer << (24 + SCNTL3_SCF_SHIFT);
256 1.1 bouyer if (sync < 25) /* Ultra */
257 1.1 bouyer sc->targets[target]->id |=
258 1.1 bouyer SCNTL3_ULTRA << 24;
259 1.1 bouyer else
260 1.1 bouyer sc->targets[target]->id &=
261 1.1 bouyer ~(SCNTL3_ULTRA << 24);
262 1.1 bouyer sc->targets[target]->id &=
263 1.1 bouyer ~(SCXFER_MO_MASK << 8);
264 1.1 bouyer sc->targets[target]->id |=
265 1.1 bouyer (offset & SCXFER_MO_MASK) << 8;
266 1.1 bouyer goto end;
267 1.1 bouyer }
268 1.1 bouyer }
269 1.1 bouyer /*
270 1.1 bouyer * we didn't find it in our table, do async and send reject
271 1.1 bouyer * msg
272 1.1 bouyer */
273 1.1 bouyer reject:
274 1.1 bouyer send_msgout = 1;
275 1.1 bouyer siop_cmd->siop_table->t_msgout.count= htole32(1);
276 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_MESSAGE_REJECT;
277 1.1 bouyer printf("%s: target %d asynchronous\n", sc->sc_dev.dv_xname,
278 1.1 bouyer target);
279 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_SCF_MASK << 24);
280 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_ULTRA << 24);
281 1.1 bouyer sc->targets[target]->id &= ~(SCXFER_MO_MASK << 8);
282 1.1 bouyer } else { /* target initiated sync neg */
283 1.1 bouyer #ifdef DEBUG
284 1.1 bouyer printf("sdtr (target): sync %d offset %d\n", sync, offset);
285 1.1 bouyer #endif
286 1.1 bouyer if (offset == 0 || sync > sc->maxsync) { /* async */
287 1.1 bouyer goto async;
288 1.1 bouyer }
289 1.1 bouyer if (offset > sc->maxoff)
290 1.1 bouyer offset = sc->maxoff;
291 1.1 bouyer if (sync < sc->minsync)
292 1.1 bouyer sync = sc->minsync;
293 1.1 bouyer /* look for sync period */
294 1.1 bouyer for (i = 0; i < sizeof(scf_period) / sizeof(scf_period[0]);
295 1.1 bouyer i++) {
296 1.1 bouyer if (sc->clock_period != scf_period[i].clock)
297 1.1 bouyer continue;
298 1.1 bouyer if (scf_period[i].period == sync) {
299 1.1 bouyer /* ok, found it. we now are sync. */
300 1.1 bouyer printf("%s: target %d now synchronous at "
301 1.1 bouyer "%sMhz, offset %d\n", sc->sc_dev.dv_xname,
302 1.1 bouyer target, scf_period[i].rate, offset);
303 1.1 bouyer sc->targets[target]->id &=
304 1.1 bouyer ~(SCNTL3_SCF_MASK << 24);
305 1.1 bouyer sc->targets[target]->id |= scf_period[i].scf
306 1.1 bouyer << (24 + SCNTL3_SCF_SHIFT);
307 1.1 bouyer if (sync < 25) /* Ultra */
308 1.1 bouyer sc->targets[target]->id |=
309 1.1 bouyer SCNTL3_ULTRA << 24;
310 1.1 bouyer else
311 1.1 bouyer sc->targets[target]->id &=
312 1.1 bouyer ~(SCNTL3_ULTRA << 24);
313 1.1 bouyer sc->targets[target]->id &=
314 1.1 bouyer ~(SCXFER_MO_MASK << 8);
315 1.1 bouyer sc->targets[target]->id |=
316 1.1 bouyer (offset & SCXFER_MO_MASK) << 8;
317 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_EXTENDED;
318 1.1 bouyer siop_cmd->siop_table->msg_out[1] =
319 1.1 bouyer MSG_EXT_SDTR_LEN;
320 1.1 bouyer siop_cmd->siop_table->msg_out[2] = MSG_EXT_SDTR;
321 1.1 bouyer siop_cmd->siop_table->msg_out[3] = sync;
322 1.1 bouyer siop_cmd->siop_table->msg_out[4] = offset;
323 1.1 bouyer siop_cmd->siop_table->t_msgout.count=
324 1.1 bouyer htole32(MSG_EXT_SDTR_LEN + 2);
325 1.1 bouyer send_msgout = 1;
326 1.1 bouyer goto end;
327 1.1 bouyer }
328 1.1 bouyer }
329 1.1 bouyer async:
330 1.1 bouyer printf("%s: target %d asynchronous\n",
331 1.1 bouyer sc->sc_dev.dv_xname, target);
332 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_SCF_MASK << 24);
333 1.1 bouyer sc->targets[target]->id &= ~(SCNTL3_ULTRA << 24);
334 1.1 bouyer sc->targets[target]->id &= ~(SCXFER_MO_MASK << 8);
335 1.1 bouyer siop_cmd->siop_table->msg_out[0] = MSG_EXTENDED;
336 1.1 bouyer siop_cmd->siop_table->msg_out[1] = MSG_EXT_SDTR_LEN;
337 1.1 bouyer siop_cmd->siop_table->msg_out[2] = MSG_EXT_SDTR;
338 1.1 bouyer siop_cmd->siop_table->msg_out[3] = 0;
339 1.1 bouyer siop_cmd->siop_table->msg_out[4] = 0;
340 1.1 bouyer siop_cmd->siop_table->t_msgout.count=
341 1.1 bouyer htole32(MSG_EXT_SDTR_LEN + 2);
342 1.1 bouyer send_msgout = 1;
343 1.1 bouyer }
344 1.1 bouyer end:
345 1.1 bouyer #ifdef DEBUG
346 1.1 bouyer printf("id now 0x%x\n", sc->targets[target]->id);
347 1.1 bouyer #endif
348 1.1 bouyer siop_cmd->siop_table->id = htole32(sc->targets[target]->id);
349 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL3,
350 1.1 bouyer (sc->targets[target]->id >> 24) & 0xff);
351 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCXFER,
352 1.1 bouyer (sc->targets[target]->id >> 8) & 0xff);
353 1.1 bouyer if (send_msgout) {
354 1.1 bouyer siop_cmd->siop_table->t_msgout.addr = htole32(siop_cmd->dsa);
355 1.1 bouyer return SIOP_NEG_MSGOUT;
356 1.1 bouyer } else {
357 1.1 bouyer return SIOP_NEG_ACK;
358 1.1 bouyer }
359 1.1 bouyer }
360 1.1 bouyer
361 1.1 bouyer void
362 1.1 bouyer siop_minphys(bp)
363 1.1 bouyer struct buf *bp;
364 1.1 bouyer {
365 1.1 bouyer minphys(bp);
366 1.1 bouyer }
367 1.1 bouyer
368 1.1 bouyer int
369 1.1 bouyer siop_ioctl(link, cmd, arg, flag, p)
370 1.1 bouyer struct scsipi_link *link;
371 1.1 bouyer u_long cmd;
372 1.1 bouyer caddr_t arg;
373 1.1 bouyer int flag;
374 1.1 bouyer struct proc *p;
375 1.1 bouyer {
376 1.1 bouyer struct siop_softc *sc = link->adapter_softc;
377 1.1 bouyer u_int8_t scntl1;
378 1.1 bouyer int s;
379 1.1 bouyer
380 1.1 bouyer switch (cmd) {
381 1.1 bouyer case SCBUSIORESET:
382 1.1 bouyer s = splbio();
383 1.1 bouyer scntl1 = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL1);
384 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL1,
385 1.1 bouyer scntl1 | SCNTL1_RST);
386 1.1 bouyer /* minimum 25 us, more time won't hurt */
387 1.1 bouyer delay(100);
388 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_SCNTL1, scntl1);
389 1.1 bouyer splx(s);
390 1.1 bouyer return (0);
391 1.1 bouyer default:
392 1.1 bouyer return (ENOTTY);
393 1.1 bouyer }
394 1.1 bouyer }
395 1.1 bouyer
396 1.1 bouyer void
397 1.1 bouyer siop_sdp(siop_cmd)
398 1.1 bouyer struct siop_cmd *siop_cmd;
399 1.1 bouyer {
400 1.1 bouyer /* save data pointer. Handle async only for now */
401 1.1 bouyer int offset, dbc, sstat;
402 1.1 bouyer struct siop_softc *sc = siop_cmd->siop_target->siop_sc;
403 1.1 bouyer scr_table_t *table; /* table to patch */
404 1.1 bouyer
405 1.1 bouyer if ((siop_cmd->xs->xs_control & (XS_CTL_DATA_OUT | XS_CTL_DATA_IN))
406 1.1 bouyer == 0)
407 1.1 bouyer return; /* no data pointers to save */
408 1.1 bouyer offset = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_SCRATCHA + 1);
409 1.1 bouyer if (offset >= SIOP_NSG) {
410 1.1 bouyer printf("%s: bad offset in siop_sdp (%d)\n",
411 1.1 bouyer sc->sc_dev.dv_xname, offset);
412 1.1 bouyer return;
413 1.1 bouyer }
414 1.1 bouyer table = &siop_cmd->siop_table->data[offset];
415 1.1 bouyer #ifdef DEBUG_DR
416 1.1 bouyer printf("sdp: offset %d count=%d addr=0x%x ", offset,
417 1.1 bouyer table->count, table->addr);
418 1.1 bouyer #endif
419 1.1 bouyer dbc = bus_space_read_4(sc->sc_rt, sc->sc_rh, SIOP_DBC) & 0x00ffffff;
420 1.1 bouyer if (siop_cmd->xs->xs_control & XS_CTL_DATA_OUT) {
421 1.1 bouyer /* need to account stale data in FIFO */
422 1.1 bouyer int dfifo = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_DFIFO);
423 1.1 bouyer if (sc->features & SF_CHIP_FIFO) {
424 1.1 bouyer dfifo |= (bus_space_read_1(sc->sc_rt, sc->sc_rh,
425 1.1 bouyer SIOP_CTEST5) & CTEST5_BOMASK) << 8;
426 1.1 bouyer dbc += (dfifo - (dbc & 0x3ff)) & 0x3ff;
427 1.1 bouyer } else {
428 1.1 bouyer dbc += (dfifo - (dbc & 0x7f)) & 0x7f;
429 1.1 bouyer }
430 1.1 bouyer sstat = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_SSTAT0);
431 1.1 bouyer if (sstat & SSTAT0_OLF)
432 1.1 bouyer dbc++;
433 1.1 bouyer if (sstat & SSTAT0_ORF)
434 1.1 bouyer dbc++;
435 1.1 bouyer if (siop_cmd->siop_target->flags & TARF_WIDE) {
436 1.1 bouyer sstat = bus_space_read_1(sc->sc_rt, sc->sc_rh,
437 1.1 bouyer SIOP_SSTAT2);
438 1.1 bouyer if (sstat & SSTAT2_OLF1)
439 1.1 bouyer dbc++;
440 1.1 bouyer if (sstat & SSTAT2_ORF1)
441 1.1 bouyer dbc++;
442 1.1 bouyer }
443 1.1 bouyer /* clear the FIFO */
444 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3,
445 1.1 bouyer bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3) |
446 1.1 bouyer CTEST3_CLF);
447 1.1 bouyer }
448 1.1 bouyer table->addr =
449 1.1 bouyer htole32(le32toh(table->addr) + le32toh(table->count) - dbc);
450 1.1 bouyer table->count = htole32(dbc);
451 1.1 bouyer #ifdef DEBUG_DR
452 1.1 bouyer printf("now count=%d addr=0x%x\n", table->count, table->addr);
453 1.1 bouyer #endif
454 1.1 bouyer }
455 1.1 bouyer
456 1.1 bouyer void
457 1.1 bouyer siop_clearfifo(sc)
458 1.1 bouyer struct siop_softc *sc;
459 1.1 bouyer {
460 1.1 bouyer int timeout = 0;
461 1.1 bouyer int ctest3 = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3);
462 1.1 bouyer
463 1.1 bouyer #ifdef DEBUG_INTR
464 1.1 bouyer printf("DMA fifo not empty !\n");
465 1.1 bouyer #endif
466 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3,
467 1.1 bouyer ctest3 | CTEST3_CLF);
468 1.1 bouyer while ((bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3) &
469 1.1 bouyer CTEST3_CLF) != 0) {
470 1.1 bouyer delay(1);
471 1.1 bouyer if (++timeout > 1000) {
472 1.1 bouyer printf("clear fifo failed\n");
473 1.1 bouyer bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3,
474 1.1 bouyer bus_space_read_1(sc->sc_rt, sc->sc_rh,
475 1.1 bouyer SIOP_CTEST3) & ~CTEST3_CLF);
476 1.1 bouyer return;
477 1.1 bouyer }
478 1.1 bouyer }
479 1.1 bouyer }
480