scsi.c revision 1.5 1 1.5 tsutsui /* $NetBSD: scsi.c,v 1.5 2003/11/14 16:52:40 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * This is reported to fix some odd failures when disklabeling
5 1.1 thorpej * SCSI disks in SYS_INST.
6 1.1 thorpej */
7 1.1 thorpej #define SLOWSCSI
8 1.1 thorpej
9 1.1 thorpej /*
10 1.1 thorpej * Copyright (c) 1990, 1993
11 1.1 thorpej * The Regents of the University of California. All rights reserved.
12 1.4 agc *
13 1.4 agc * This code is derived from software contributed to Berkeley by
14 1.4 agc * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
15 1.4 agc * Programming Group of the University of Utah Computer Science Department.
16 1.4 agc *
17 1.4 agc * Redistribution and use in source and binary forms, with or without
18 1.4 agc * modification, are permitted provided that the following conditions
19 1.4 agc * are met:
20 1.4 agc * 1. Redistributions of source code must retain the above copyright
21 1.4 agc * notice, this list of conditions and the following disclaimer.
22 1.4 agc * 2. Redistributions in binary form must reproduce the above copyright
23 1.4 agc * notice, this list of conditions and the following disclaimer in the
24 1.4 agc * documentation and/or other materials provided with the distribution.
25 1.4 agc * 3. Neither the name of the University nor the names of its contributors
26 1.4 agc * may be used to endorse or promote products derived from this software
27 1.4 agc * without specific prior written permission.
28 1.4 agc *
29 1.4 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 1.4 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 1.4 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.4 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 1.4 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 1.4 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 1.4 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 1.4 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 1.4 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 1.4 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 1.4 agc * SUCH DAMAGE.
40 1.4 agc *
41 1.4 agc * from: Utah $Hdr: scsi.c 1.3 90/01/27$
42 1.4 agc *
43 1.4 agc * @(#)scsi.c 8.1 (Berkeley) 6/10/93
44 1.4 agc */
45 1.4 agc /*
46 1.4 agc * Copyright (c) 1988 University of Utah.
47 1.1 thorpej *
48 1.1 thorpej * This code is derived from software contributed to Berkeley by
49 1.1 thorpej * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
50 1.1 thorpej * Programming Group of the University of Utah Computer Science Department.
51 1.1 thorpej *
52 1.1 thorpej * Redistribution and use in source and binary forms, with or without
53 1.1 thorpej * modification, are permitted provided that the following conditions
54 1.1 thorpej * are met:
55 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
56 1.1 thorpej * notice, this list of conditions and the following disclaimer.
57 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
58 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
59 1.1 thorpej * documentation and/or other materials provided with the distribution.
60 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
61 1.1 thorpej * must display the following acknowledgement:
62 1.1 thorpej * This product includes software developed by the University of
63 1.1 thorpej * California, Berkeley and its contributors.
64 1.1 thorpej * 4. Neither the name of the University nor the names of its contributors
65 1.1 thorpej * may be used to endorse or promote products derived from this software
66 1.1 thorpej * without specific prior written permission.
67 1.1 thorpej *
68 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
69 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
72 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 1.1 thorpej * SUCH DAMAGE.
79 1.1 thorpej *
80 1.1 thorpej * from: Utah $Hdr: scsi.c 1.3 90/01/27$
81 1.1 thorpej *
82 1.1 thorpej * @(#)scsi.c 8.1 (Berkeley) 6/10/93
83 1.1 thorpej */
84 1.1 thorpej
85 1.1 thorpej /*
86 1.1 thorpej * SCSI bus driver for standalone programs.
87 1.1 thorpej */
88 1.1 thorpej
89 1.1 thorpej #include <sys/param.h>
90 1.1 thorpej #include <sys/reboot.h>
91 1.1 thorpej
92 1.1 thorpej #include <lib/libsa/stand.h>
93 1.1 thorpej
94 1.1 thorpej #define _IOCTL_
95 1.1 thorpej
96 1.1 thorpej #include <hp300/stand/common/device.h>
97 1.3 tsutsui #include <hp300/stand/common/scsireg.h>
98 1.1 thorpej #include <hp300/stand/common/scsivar.h>
99 1.1 thorpej #include <hp300/stand/common/samachdep.h>
100 1.1 thorpej
101 1.5 tsutsui static void scsireset(int);
102 1.5 tsutsui static int issue_select(volatile struct scsidevice *, u_char, u_char);
103 1.5 tsutsui static int wait_for_select(volatile struct scsidevice *hd);
104 1.5 tsutsui static int ixfer_start(volatile struct scsidevice *, int, u_char, int);
105 1.5 tsutsui static int ixfer_out(volatile struct scsidevice *, int, u_char *);
106 1.5 tsutsui static int ixfer_in(volatile struct scsidevice *hd, int, u_char *);
107 1.5 tsutsui static int scsiicmd(struct scsi_softc *, int, u_char *, int, u_char *, int,
108 1.5 tsutsui u_char);
109 1.5 tsutsui
110 1.1 thorpej struct scsi_softc scsi_softc[NSCSI];
111 1.1 thorpej
112 1.5 tsutsui
113 1.1 thorpej int scsi_cmd_wait = 50000; /* use the "real" driver init_wait value */
114 1.1 thorpej int scsi_data_wait = 50000; /* use the "real" driver init_wait value */
115 1.1 thorpej
116 1.5 tsutsui void
117 1.1 thorpej scsiinit()
118 1.1 thorpej {
119 1.5 tsutsui struct hp_hw *hw;
120 1.5 tsutsui struct scsi_softc *hs;
121 1.5 tsutsui int i;
122 1.1 thorpej static int waitset = 0;
123 1.1 thorpej
124 1.1 thorpej i = 0;
125 1.1 thorpej for (hw = sc_table; i < NSCSI && hw < &sc_table[MAXCTLRS]; hw++) {
126 1.1 thorpej if (!HW_ISSCSI(hw))
127 1.1 thorpej continue;
128 1.1 thorpej hs = &scsi_softc[i];
129 1.1 thorpej hs->sc_addr = hw->hw_kva;
130 1.1 thorpej scsireset(i);
131 1.1 thorpej if (howto & RB_ASKNAME)
132 1.1 thorpej printf("scsi%d at sc%d\n", i, hw->hw_sc);
133 1.1 thorpej hw->hw_pa = (caddr_t) i; /* XXX for autoconfig */
134 1.1 thorpej hs->sc_alive = 1;
135 1.1 thorpej i++;
136 1.1 thorpej }
137 1.1 thorpej /*
138 1.1 thorpej * Adjust the wait values
139 1.1 thorpej */
140 1.1 thorpej if (!waitset) {
141 1.1 thorpej scsi_cmd_wait *= cpuspeed;
142 1.1 thorpej scsi_data_wait *= cpuspeed;
143 1.1 thorpej waitset = 1;
144 1.1 thorpej }
145 1.1 thorpej }
146 1.1 thorpej
147 1.5 tsutsui int
148 1.1 thorpej scsialive(unit)
149 1.5 tsutsui int unit;
150 1.1 thorpej {
151 1.1 thorpej if (unit >= NSCSI || scsi_softc[unit].sc_alive == 0)
152 1.5 tsutsui return 0;
153 1.5 tsutsui return 1;
154 1.1 thorpej }
155 1.1 thorpej
156 1.5 tsutsui static void
157 1.1 thorpej scsireset(unit)
158 1.5 tsutsui int unit;
159 1.1 thorpej {
160 1.5 tsutsui volatile struct scsidevice *hd;
161 1.5 tsutsui struct scsi_softc *hs;
162 1.1 thorpej u_int i;
163 1.1 thorpej
164 1.1 thorpej hs = &scsi_softc[unit];
165 1.5 tsutsui hd = (void *)hs->sc_addr;
166 1.1 thorpej hd->scsi_id = 0xFF;
167 1.1 thorpej DELAY(100);
168 1.1 thorpej /*
169 1.1 thorpej * Disable interrupts then reset the FUJI chip.
170 1.1 thorpej */
171 1.1 thorpej hd->scsi_csr = 0;
172 1.1 thorpej hd->scsi_sctl = SCTL_DISABLE | SCTL_CTRLRST;
173 1.1 thorpej hd->scsi_scmd = 0;
174 1.1 thorpej hd->scsi_tmod = 0;
175 1.1 thorpej hd->scsi_pctl = 0;
176 1.1 thorpej hd->scsi_temp = 0;
177 1.1 thorpej hd->scsi_tch = 0;
178 1.1 thorpej hd->scsi_tcm = 0;
179 1.1 thorpej hd->scsi_tcl = 0;
180 1.1 thorpej hd->scsi_ints = 0;
181 1.1 thorpej
182 1.1 thorpej /*
183 1.1 thorpej * Configure the FUJI chip with its SCSI address, all
184 1.1 thorpej * interrupts enabled & appropriate parity.
185 1.1 thorpej */
186 1.1 thorpej i = (~hd->scsi_hconf) & 0x7;
187 1.1 thorpej hs->sc_scsi_addr = 1 << i;
188 1.1 thorpej hd->scsi_bdid = i;
189 1.1 thorpej if (hd->scsi_hconf & HCONF_PARITY)
190 1.1 thorpej hd->scsi_sctl = SCTL_DISABLE | SCTL_ABRT_ENAB |
191 1.1 thorpej SCTL_SEL_ENAB | SCTL_RESEL_ENAB |
192 1.1 thorpej SCTL_INTR_ENAB | SCTL_PARITY_ENAB;
193 1.1 thorpej else
194 1.1 thorpej hd->scsi_sctl = SCTL_DISABLE | SCTL_ABRT_ENAB |
195 1.1 thorpej SCTL_SEL_ENAB | SCTL_RESEL_ENAB |
196 1.1 thorpej SCTL_INTR_ENAB;
197 1.1 thorpej hd->scsi_sctl &=~ SCTL_DISABLE;
198 1.1 thorpej }
199 1.1 thorpej
200 1.1 thorpej
201 1.5 tsutsui void
202 1.1 thorpej scsiabort(hs, hd)
203 1.5 tsutsui struct scsi_softc *hs;
204 1.5 tsutsui volatile struct scsidevice *hd;
205 1.1 thorpej {
206 1.1 thorpej printf("scsi%d error: scsiabort\n", hs - scsi_softc);
207 1.1 thorpej
208 1.1 thorpej scsireset(hs - scsi_softc);
209 1.1 thorpej DELAY(1000000);
210 1.1 thorpej }
211 1.1 thorpej
212 1.1 thorpej static int
213 1.1 thorpej issue_select(hd, target, our_addr)
214 1.5 tsutsui volatile struct scsidevice *hd;
215 1.1 thorpej u_char target, our_addr;
216 1.1 thorpej {
217 1.1 thorpej if (hd->scsi_ssts & (SSTS_INITIATOR|SSTS_TARGET|SSTS_BUSY))
218 1.5 tsutsui return 1;
219 1.1 thorpej
220 1.1 thorpej if (hd->scsi_ints & INTS_DISCON)
221 1.1 thorpej hd->scsi_ints = INTS_DISCON;
222 1.1 thorpej
223 1.1 thorpej hd->scsi_pctl = 0;
224 1.1 thorpej hd->scsi_temp = (1 << target) | our_addr;
225 1.1 thorpej /* select timeout is hardcoded to 2ms */
226 1.1 thorpej hd->scsi_tch = 0;
227 1.1 thorpej hd->scsi_tcm = 32;
228 1.1 thorpej hd->scsi_tcl = 4;
229 1.1 thorpej
230 1.1 thorpej hd->scsi_scmd = SCMD_SELECT;
231 1.5 tsutsui return 0;
232 1.1 thorpej }
233 1.1 thorpej
234 1.1 thorpej static int
235 1.1 thorpej wait_for_select(hd)
236 1.5 tsutsui volatile struct scsidevice *hd;
237 1.1 thorpej {
238 1.5 tsutsui int wait;
239 1.1 thorpej u_char ints;
240 1.1 thorpej
241 1.1 thorpej wait = scsi_data_wait;
242 1.1 thorpej while ((ints = hd->scsi_ints) == 0) {
243 1.1 thorpej if (--wait < 0)
244 1.5 tsutsui return 1;
245 1.1 thorpej DELAY(1);
246 1.1 thorpej }
247 1.1 thorpej hd->scsi_ints = ints;
248 1.5 tsutsui return !(hd->scsi_ssts & SSTS_INITIATOR);
249 1.1 thorpej }
250 1.1 thorpej
251 1.1 thorpej static int
252 1.1 thorpej ixfer_start(hd, len, phase, wait)
253 1.5 tsutsui volatile struct scsidevice *hd;
254 1.1 thorpej int len;
255 1.1 thorpej u_char phase;
256 1.5 tsutsui int wait;
257 1.1 thorpej {
258 1.1 thorpej
259 1.1 thorpej hd->scsi_tch = len >> 16;
260 1.1 thorpej hd->scsi_tcm = len >> 8;
261 1.1 thorpej hd->scsi_tcl = len;
262 1.1 thorpej hd->scsi_pctl = phase;
263 1.1 thorpej hd->scsi_tmod = 0; /*XXX*/
264 1.1 thorpej hd->scsi_scmd = SCMD_XFR | SCMD_PROG_XFR;
265 1.1 thorpej
266 1.1 thorpej /* wait for xfer to start or svc_req interrupt */
267 1.1 thorpej while ((hd->scsi_ssts & SSTS_BUSY) == 0) {
268 1.1 thorpej if (hd->scsi_ints || --wait < 0)
269 1.5 tsutsui return 0;
270 1.1 thorpej DELAY(1);
271 1.1 thorpej }
272 1.5 tsutsui return 1;
273 1.1 thorpej }
274 1.1 thorpej
275 1.1 thorpej static int
276 1.1 thorpej ixfer_out(hd, len, buf)
277 1.5 tsutsui volatile struct scsidevice *hd;
278 1.1 thorpej int len;
279 1.5 tsutsui u_char *buf;
280 1.1 thorpej {
281 1.5 tsutsui int wait = scsi_data_wait;
282 1.1 thorpej
283 1.1 thorpej for (; len > 0; --len) {
284 1.1 thorpej while (hd->scsi_ssts & SSTS_DREG_FULL) {
285 1.1 thorpej if (hd->scsi_ints || --wait < 0)
286 1.5 tsutsui return len;
287 1.1 thorpej DELAY(1);
288 1.1 thorpej }
289 1.1 thorpej hd->scsi_dreg = *buf++;
290 1.1 thorpej }
291 1.5 tsutsui return 0;
292 1.1 thorpej }
293 1.1 thorpej
294 1.1 thorpej static int
295 1.1 thorpej ixfer_in(hd, len, buf)
296 1.5 tsutsui volatile struct scsidevice *hd;
297 1.1 thorpej int len;
298 1.5 tsutsui u_char *buf;
299 1.1 thorpej {
300 1.5 tsutsui int wait = scsi_data_wait;
301 1.1 thorpej
302 1.1 thorpej for (; len > 0; --len) {
303 1.1 thorpej while (hd->scsi_ssts & SSTS_DREG_EMPTY) {
304 1.1 thorpej if (hd->scsi_ints || --wait < 0) {
305 1.1 thorpej while (! (hd->scsi_ssts & SSTS_DREG_EMPTY)) {
306 1.1 thorpej *buf++ = hd->scsi_dreg;
307 1.1 thorpej --len;
308 1.1 thorpej }
309 1.5 tsutsui return len;
310 1.1 thorpej }
311 1.1 thorpej DELAY(1);
312 1.1 thorpej }
313 1.1 thorpej *buf++ = hd->scsi_dreg;
314 1.1 thorpej }
315 1.5 tsutsui return len;
316 1.1 thorpej }
317 1.1 thorpej
318 1.1 thorpej static int
319 1.1 thorpej scsiicmd(hs, target, cbuf, clen, buf, len, xferphase)
320 1.1 thorpej struct scsi_softc *hs;
321 1.1 thorpej int target;
322 1.1 thorpej u_char *cbuf;
323 1.1 thorpej int clen;
324 1.1 thorpej u_char *buf;
325 1.1 thorpej int len;
326 1.1 thorpej u_char xferphase;
327 1.1 thorpej {
328 1.5 tsutsui volatile struct scsidevice *hd = (void *)hs->sc_addr;
329 1.1 thorpej u_char phase, ints;
330 1.5 tsutsui int wait;
331 1.1 thorpej
332 1.1 thorpej /* select the SCSI bus (it's an error if bus isn't free) */
333 1.1 thorpej if (issue_select(hd, target, hs->sc_scsi_addr))
334 1.5 tsutsui return -2;
335 1.1 thorpej if (wait_for_select(hd))
336 1.5 tsutsui return -2;
337 1.1 thorpej /*
338 1.1 thorpej * Wait for a phase change (or error) then let the device
339 1.1 thorpej * sequence us through the various SCSI phases.
340 1.1 thorpej */
341 1.1 thorpej hs->sc_stat = -1;
342 1.1 thorpej phase = CMD_PHASE;
343 1.1 thorpej while (1) {
344 1.1 thorpej wait = scsi_cmd_wait;
345 1.1 thorpej switch (phase) {
346 1.1 thorpej
347 1.1 thorpej case CMD_PHASE:
348 1.1 thorpej if (ixfer_start(hd, clen, phase, wait))
349 1.1 thorpej if (ixfer_out(hd, clen, cbuf))
350 1.1 thorpej goto abort;
351 1.1 thorpej phase = xferphase;
352 1.1 thorpej break;
353 1.1 thorpej
354 1.1 thorpej case DATA_IN_PHASE:
355 1.1 thorpej if (len <= 0)
356 1.1 thorpej goto abort;
357 1.1 thorpej wait = scsi_data_wait;
358 1.1 thorpej if (ixfer_start(hd, len, phase, wait) ||
359 1.1 thorpej !(hd->scsi_ssts & SSTS_DREG_EMPTY))
360 1.1 thorpej ixfer_in(hd, len, buf);
361 1.1 thorpej phase = STATUS_PHASE;
362 1.1 thorpej break;
363 1.1 thorpej
364 1.1 thorpej case DATA_OUT_PHASE:
365 1.1 thorpej if (len <= 0)
366 1.1 thorpej goto abort;
367 1.1 thorpej wait = scsi_data_wait;
368 1.1 thorpej if (ixfer_start(hd, len, phase, wait))
369 1.1 thorpej if (ixfer_out(hd, len, buf))
370 1.1 thorpej goto abort;
371 1.1 thorpej phase = STATUS_PHASE;
372 1.1 thorpej break;
373 1.1 thorpej
374 1.1 thorpej case STATUS_PHASE:
375 1.1 thorpej wait = scsi_data_wait;
376 1.1 thorpej if (ixfer_start(hd, sizeof(hs->sc_stat), phase, wait) ||
377 1.1 thorpej !(hd->scsi_ssts & SSTS_DREG_EMPTY))
378 1.1 thorpej ixfer_in(hd, sizeof(hs->sc_stat), &hs->sc_stat);
379 1.1 thorpej phase = MESG_IN_PHASE;
380 1.1 thorpej break;
381 1.1 thorpej
382 1.1 thorpej case MESG_IN_PHASE:
383 1.1 thorpej if (ixfer_start(hd, sizeof(hs->sc_msg), phase, wait) ||
384 1.1 thorpej !(hd->scsi_ssts & SSTS_DREG_EMPTY)) {
385 1.5 tsutsui ixfer_in(hd, sizeof(hs->sc_msg),
386 1.5 tsutsui (u_char *)&hs->sc_msg);
387 1.1 thorpej hd->scsi_scmd = SCMD_RST_ACK;
388 1.1 thorpej }
389 1.1 thorpej phase = BUS_FREE_PHASE;
390 1.1 thorpej break;
391 1.1 thorpej
392 1.1 thorpej case BUS_FREE_PHASE:
393 1.1 thorpej goto out;
394 1.1 thorpej
395 1.1 thorpej default:
396 1.1 thorpej printf("scsi%d: unexpected scsi phase %d\n",
397 1.1 thorpej hs - scsi_softc, phase);
398 1.1 thorpej goto abort;
399 1.1 thorpej }
400 1.1 thorpej #ifdef SLOWSCSI
401 1.1 thorpej /*
402 1.2 wiz * XXX we have weird transient problems with booting from
403 1.1 thorpej * slow scsi disks on fast machines. I have never been
404 1.1 thorpej * able to pin the problem down, but a large delay here
405 1.1 thorpej * seems to always work.
406 1.1 thorpej */
407 1.1 thorpej DELAY(1000);
408 1.1 thorpej #endif
409 1.1 thorpej /* wait for last command to complete */
410 1.1 thorpej while ((ints = hd->scsi_ints) == 0) {
411 1.1 thorpej if (--wait < 0)
412 1.1 thorpej goto abort;
413 1.1 thorpej DELAY(1);
414 1.1 thorpej }
415 1.1 thorpej hd->scsi_ints = ints;
416 1.1 thorpej if (ints & INTS_SRV_REQ)
417 1.1 thorpej phase = hd->scsi_psns & PHASE;
418 1.1 thorpej else if (ints & INTS_DISCON)
419 1.1 thorpej goto out;
420 1.1 thorpej else if ((ints & INTS_CMD_DONE) == 0)
421 1.1 thorpej goto abort;
422 1.1 thorpej }
423 1.1 thorpej abort:
424 1.1 thorpej scsiabort(hs, hd);
425 1.1 thorpej out:
426 1.5 tsutsui return hs->sc_stat;
427 1.1 thorpej }
428 1.1 thorpej
429 1.1 thorpej int
430 1.1 thorpej scsi_test_unit_rdy(ctlr, slave)
431 1.1 thorpej int ctlr, slave;
432 1.1 thorpej {
433 1.5 tsutsui struct scsi_softc *hs = &scsi_softc[ctlr];
434 1.1 thorpej static struct scsi_cdb6 cdb = { CMD_TEST_UNIT_READY };
435 1.1 thorpej
436 1.5 tsutsui return scsiicmd(hs, slave, (u_char *)&cdb, sizeof(cdb), NULL, 0,
437 1.5 tsutsui STATUS_PHASE);
438 1.1 thorpej }
439 1.1 thorpej
440 1.1 thorpej int
441 1.1 thorpej scsi_request_sense(ctlr, slave, buf, len)
442 1.1 thorpej int ctlr, slave;
443 1.1 thorpej u_char *buf;
444 1.5 tsutsui unsigned int len;
445 1.1 thorpej {
446 1.5 tsutsui struct scsi_softc *hs = &scsi_softc[ctlr];
447 1.1 thorpej static struct scsi_cdb6 cdb = { CMD_REQUEST_SENSE };
448 1.1 thorpej
449 1.1 thorpej cdb.len = len;
450 1.5 tsutsui return scsiicmd(hs, slave, (u_char *)&cdb, sizeof(cdb), buf, len,
451 1.5 tsutsui DATA_IN_PHASE);
452 1.1 thorpej }
453 1.1 thorpej
454 1.1 thorpej int
455 1.1 thorpej scsi_read_capacity(ctlr, slave, buf, len)
456 1.1 thorpej int ctlr, slave;
457 1.1 thorpej u_char *buf;
458 1.5 tsutsui unsigned int len;
459 1.1 thorpej {
460 1.5 tsutsui struct scsi_softc *hs = &scsi_softc[ctlr];
461 1.1 thorpej static struct scsi_cdb10 cdb = { CMD_READ_CAPACITY };
462 1.1 thorpej
463 1.5 tsutsui return scsiicmd(hs, slave, (u_char *)&cdb, sizeof(cdb), buf, len,
464 1.5 tsutsui DATA_IN_PHASE);
465 1.1 thorpej }
466 1.1 thorpej
467 1.1 thorpej int
468 1.1 thorpej scsi_tt_read(ctlr, slave, buf, len, blk, nblk)
469 1.1 thorpej int ctlr, slave;
470 1.1 thorpej u_char *buf;
471 1.1 thorpej u_int len;
472 1.1 thorpej daddr_t blk;
473 1.1 thorpej u_int nblk;
474 1.1 thorpej {
475 1.5 tsutsui struct scsi_softc *hs = &scsi_softc[ctlr];
476 1.1 thorpej struct scsi_cdb10 cdb;
477 1.1 thorpej
478 1.5 tsutsui memset(&cdb, 0, sizeof(cdb));
479 1.1 thorpej cdb.cmd = CMD_READ_EXT;
480 1.1 thorpej cdb.lbah = blk >> 24;
481 1.1 thorpej cdb.lbahm = blk >> 16;
482 1.1 thorpej cdb.lbalm = blk >> 8;
483 1.1 thorpej cdb.lbal = blk;
484 1.1 thorpej cdb.lenh = nblk >> (8 + DEV_BSHIFT);
485 1.1 thorpej cdb.lenl = nblk >> DEV_BSHIFT;
486 1.5 tsutsui return scsiicmd(hs, slave, (u_char *)&cdb, sizeof(cdb), buf, len,
487 1.5 tsutsui DATA_IN_PHASE);
488 1.1 thorpej }
489 1.1 thorpej
490 1.1 thorpej int
491 1.1 thorpej scsi_tt_write(ctlr, slave, buf, len, blk, nblk)
492 1.1 thorpej int ctlr, slave;
493 1.1 thorpej u_char *buf;
494 1.1 thorpej u_int len;
495 1.1 thorpej daddr_t blk;
496 1.1 thorpej u_int nblk;
497 1.1 thorpej {
498 1.5 tsutsui struct scsi_softc *hs = &scsi_softc[ctlr];
499 1.1 thorpej struct scsi_cdb10 cdb;
500 1.1 thorpej
501 1.5 tsutsui memset(&cdb, 0, sizeof(cdb));
502 1.1 thorpej cdb.cmd = CMD_WRITE_EXT;
503 1.1 thorpej cdb.lbah = blk >> 24;
504 1.1 thorpej cdb.lbahm = blk >> 16;
505 1.1 thorpej cdb.lbalm = blk >> 8;
506 1.1 thorpej cdb.lbal = blk;
507 1.1 thorpej cdb.lenh = nblk >> (8 + DEV_BSHIFT);
508 1.1 thorpej cdb.lenl = nblk >> DEV_BSHIFT;
509 1.5 tsutsui return scsiicmd(hs, slave, (u_char *)&cdb, sizeof(cdb), buf, len,
510 1.5 tsutsui DATA_OUT_PHASE);
511 1.1 thorpej }
512