st.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Written by Julian Elischer (julian (at) tfs.com)
3 1.1 cgd * for TRW Financial Systems for use under the MACH(2.5) operating system.
4 1.1 cgd *
5 1.1 cgd * TRW Financial Systems, in accordance with their agreement with Carnegie
6 1.1 cgd * Mellon University, makes this software available to CMU to distribute
7 1.1 cgd * or use in any manner that they see fit as long as this message is kept with
8 1.1 cgd * the software. For this reason TFS also grants any other persons or
9 1.1 cgd * organisations permission to use or modify this software.
10 1.1 cgd *
11 1.1 cgd * TFS supplies this software to be publicly redistributed
12 1.1 cgd * on the understanding that TFS is not responsible for the correct
13 1.1 cgd * functioning of this software in any circumstances.
14 1.1 cgd *
15 1.1 cgd *
16 1.1 cgd * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
17 1.1 cgd * -------------------- ----- ----------------------
18 1.1 cgd * CURRENT PATCH LEVEL: 1 00098
19 1.1 cgd * -------------------- ----- ----------------------
20 1.1 cgd *
21 1.1 cgd * 16 Feb 93 Julian Elischer ADDED for SCSI system
22 1.1 cgd */
23 1.1 cgd
24 1.1 cgd /*
25 1.1 cgd * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
26 1.1 cgd */
27 1.1 cgd
28 1.1 cgd
29 1.1 cgd /*
30 1.1 cgd * To do:
31 1.1 cgd * work out some better way of guessing what a good timeout is going
32 1.1 cgd * to be depending on whether we expect to retension or not.
33 1.1 cgd *
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd #include <sys/types.h>
37 1.1 cgd #include <st.h>
38 1.1 cgd
39 1.1 cgd #include <sys/param.h>
40 1.1 cgd #include <sys/systm.h>
41 1.1 cgd
42 1.1 cgd #include <sys/errno.h>
43 1.1 cgd #include <sys/ioctl.h>
44 1.1 cgd #include <sys/buf.h>
45 1.1 cgd #include <sys/proc.h>
46 1.1 cgd #include <sys/user.h>
47 1.1 cgd #include <sys/mtio.h>
48 1.1 cgd
49 1.1 cgd #if defined(OSF)
50 1.1 cgd #define SECSIZE 512
51 1.1 cgd #endif /* defined(OSF) */
52 1.1 cgd
53 1.1 cgd #include <scsi/scsi_all.h>
54 1.1 cgd #include <scsi/scsi_tape.h>
55 1.1 cgd #include <scsi/scsiconf.h>
56 1.1 cgd
57 1.1 cgd
58 1.1 cgd long int ststrats,stqueues;
59 1.1 cgd
60 1.1 cgd
61 1.1 cgd #define PAGESIZ 4096
62 1.1 cgd #define STQSIZE 4
63 1.1 cgd #define ST_RETRIES 4
64 1.1 cgd
65 1.1 cgd
66 1.1 cgd #define MODE(z) ( (minor(z) & 0x03) )
67 1.1 cgd #define DSTY(z) ( ((minor(z) >> 2) & 0x03) )
68 1.1 cgd #define UNIT(z) ( (minor(z) >> 4) )
69 1.1 cgd
70 1.1 cgd #define DSTY_QIC120 3
71 1.1 cgd #define DSTY_QIC150 2
72 1.1 cgd #define DSTY_QIC525 1
73 1.1 cgd
74 1.1 cgd #define QIC120 0x0f
75 1.1 cgd #define QIC150 0x10
76 1.1 cgd #define QIC525 0x11
77 1.1 cgd
78 1.1 cgd
79 1.1 cgd
80 1.1 cgd
81 1.1 cgd #ifndef __386BSD__
82 1.1 cgd struct buf stbuf[NST][STQSIZE]; /* buffer for raw io (one per device) */
83 1.1 cgd struct buf *stbuf_free[NST]; /* queue of free buffers for raw io */
84 1.1 cgd #endif __386BSD__
85 1.1 cgd struct buf st_buf_queue[NST];
86 1.1 cgd int ststrategy();
87 1.1 cgd void stminphys();
88 1.1 cgd struct scsi_xfer st_scsi_xfer[NST];
89 1.1 cgd int st_xfer_block_wait[NST];
90 1.1 cgd
91 1.1 cgd #if defined(OSF)
92 1.1 cgd caddr_t st_window[NST];
93 1.1 cgd #endif /* defined(OSF) */
94 1.1 cgd #ifndef MACH
95 1.1 cgd #define ESUCCESS 0
96 1.1 cgd #endif MACH
97 1.1 cgd
98 1.1 cgd int st_info_valid[NST]; /* the info about the device is valid */
99 1.1 cgd int st_initialized[NST] ;
100 1.1 cgd int st_debug = 0;
101 1.1 cgd
102 1.1 cgd int stattach();
103 1.1 cgd int st_done();
104 1.1 cgd struct st_data
105 1.1 cgd {
106 1.1 cgd int flags;
107 1.1 cgd struct scsi_switch *sc_sw; /* address of scsi low level switch */
108 1.1 cgd int ctlr; /* so they know which one we want */
109 1.1 cgd int targ; /* our scsi target ID */
110 1.1 cgd int lu; /* out scsi lu */
111 1.1 cgd int blkmin; /* min blk size */
112 1.1 cgd int blkmax; /* max blk size */
113 1.1 cgd int numblks; /* nominal blocks capacity */
114 1.1 cgd int blksiz; /* nominal block size */
115 1.1 cgd }st_data[NST];
116 1.1 cgd #define ST_OPEN 0x01
117 1.1 cgd #define ST_NOREWIND 0x02
118 1.1 cgd #define ST_WRITTEN 0x04
119 1.1 cgd #define ST_FIXEDBLOCKS 0x10
120 1.1 cgd #define ST_AT_FILEMARK 0x20
121 1.1 cgd #define ST_AT_EOM 0x40
122 1.1 cgd
123 1.1 cgd #define ST_PER_ACTION (ST_AT_FILEMARK | ST_AT_EOM)
124 1.1 cgd #define ST_PER_OPEN (ST_OPEN | ST_NOREWIND | ST_WRITTEN | ST_PER_ACTION)
125 1.1 cgd #define ST_PER_MEDIA ST_FIXEDBLOCKS
126 1.1 cgd
127 1.1 cgd static int next_st_unit = 0;
128 1.1 cgd /***********************************************************************\
129 1.1 cgd * The routine called by the low level scsi routine when it discovers *
130 1.1 cgd * A device suitable for this driver *
131 1.1 cgd \***********************************************************************/
132 1.1 cgd
133 1.1 cgd int stattach(ctlr,targ,lu,scsi_switch)
134 1.1 cgd struct scsi_switch *scsi_switch;
135 1.1 cgd {
136 1.1 cgd int unit,i;
137 1.1 cgd unsigned char *tbl;
138 1.1 cgd struct st_data *st;
139 1.1 cgd
140 1.1 cgd if(scsi_debug & PRINTROUTINES) printf("stattach: ");
141 1.1 cgd /*******************************************************\
142 1.1 cgd * Check we have the resources for another drive *
143 1.1 cgd \*******************************************************/
144 1.1 cgd unit = next_st_unit++;
145 1.1 cgd if( unit >= NST)
146 1.1 cgd {
147 1.1 cgd printf("Too many scsi tapes..(%d > %d) reconfigure kernel",(unit + 1),NST);
148 1.1 cgd return(0);
149 1.1 cgd }
150 1.1 cgd st = st_data + unit;
151 1.1 cgd /*******************************************************\
152 1.1 cgd * Store information needed to contact our base driver *
153 1.1 cgd \*******************************************************/
154 1.1 cgd st->sc_sw = scsi_switch;
155 1.1 cgd st->ctlr = ctlr;
156 1.1 cgd st->targ = targ;
157 1.1 cgd st->lu = lu;
158 1.1 cgd
159 1.1 cgd /*******************************************************\
160 1.1 cgd * Use the subdriver to request information regarding *
161 1.1 cgd * the drive. We cannot use interrupts yet, so the *
162 1.1 cgd * request must specify this. *
163 1.1 cgd \*******************************************************/
164 1.1 cgd if((st_mode_sense(unit, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT)))
165 1.1 cgd {
166 1.1 cgd printf(" st%d: scsi tape drive, %d blocks of %d bytes\n",
167 1.1 cgd unit, st->numblks, st->blksiz);
168 1.1 cgd }
169 1.1 cgd else
170 1.1 cgd {
171 1.1 cgd printf(" st%d: scsi tape drive :- offline\n", unit);
172 1.1 cgd }
173 1.1 cgd /*******************************************************\
174 1.1 cgd * Set up the bufs for this device *
175 1.1 cgd \*******************************************************/
176 1.1 cgd #ifndef __386BSD__
177 1.1 cgd stbuf_free[unit] = (struct buf *)0;
178 1.1 cgd for (i = 1; i < STQSIZE; i++)
179 1.1 cgd {
180 1.1 cgd stbuf[unit][i].b_forw = stbuf_free[unit];
181 1.1 cgd stbuf_free[unit]=&stbuf[unit][i];
182 1.1 cgd }
183 1.1 cgd #endif __386BSD__
184 1.1 cgd st_buf_queue[unit].b_active = 0;
185 1.1 cgd st_buf_queue[unit].b_actf = st_buf_queue[unit].b_actl = 0;
186 1.1 cgd st_initialized[unit] = 1;
187 1.1 cgd
188 1.1 cgd #if defined(OSF)
189 1.1 cgd st_window[unit] = (caddr_t)alloc_kva(SECSIZE*256+PAGESIZ);
190 1.1 cgd #endif /* defined(OSF) */
191 1.1 cgd
192 1.1 cgd return;
193 1.1 cgd
194 1.1 cgd }
195 1.1 cgd
196 1.1 cgd
197 1.1 cgd
198 1.1 cgd /*******************************************************\
199 1.1 cgd * open the device. *
200 1.1 cgd \*******************************************************/
201 1.1 cgd stopen(dev)
202 1.1 cgd {
203 1.1 cgd int errcode = 0;
204 1.1 cgd int unit,mode,dsty;
205 1.1 cgd int dsty_code;
206 1.1 cgd struct st_data *st;
207 1.1 cgd unit = UNIT(dev);
208 1.1 cgd mode = MODE(dev);
209 1.1 cgd dsty = DSTY(dev);
210 1.1 cgd st = st_data + unit;
211 1.1 cgd
212 1.1 cgd /*******************************************************\
213 1.1 cgd * Check the unit is legal *
214 1.1 cgd \*******************************************************/
215 1.1 cgd if ( unit >= NST )
216 1.1 cgd {
217 1.1 cgd errcode = ENXIO;
218 1.1 cgd return(errcode);
219 1.1 cgd }
220 1.1 cgd /*******************************************************\
221 1.1 cgd * Only allow one at a time *
222 1.1 cgd \*******************************************************/
223 1.1 cgd if(st->flags & ST_OPEN)
224 1.1 cgd {
225 1.1 cgd errcode = ENXIO;
226 1.1 cgd goto bad;
227 1.1 cgd }
228 1.1 cgd /*******************************************************\
229 1.1 cgd * Set up the mode flags according to the minor number *
230 1.1 cgd * ensure all open flags are in a known state *
231 1.1 cgd \*******************************************************/
232 1.1 cgd st->flags &= ~ST_PER_OPEN;
233 1.1 cgd switch(mode)
234 1.1 cgd {
235 1.1 cgd case 2:
236 1.1 cgd case 0:
237 1.1 cgd st->flags &= ~ST_NOREWIND;
238 1.1 cgd break;
239 1.1 cgd case 3:
240 1.1 cgd case 1:
241 1.1 cgd st->flags |= ST_NOREWIND;
242 1.1 cgd break;
243 1.1 cgd default:
244 1.1 cgd printf("st%d: Bad mode (minor number)%d\n",unit,mode);
245 1.1 cgd return(EINVAL);
246 1.1 cgd }
247 1.1 cgd /*******************************************************\
248 1.1 cgd * Check density code: 0 is drive default *
249 1.1 cgd \*******************************************************/
250 1.1 cgd switch(dsty)
251 1.1 cgd {
252 1.1 cgd case 0: dsty_code = 0; break;
253 1.1 cgd case DSTY_QIC120: dsty_code = QIC120; break;
254 1.1 cgd case DSTY_QIC150: dsty_code = QIC150; break;
255 1.1 cgd case DSTY_QIC525: dsty_code = QIC525; break;
256 1.1 cgd default:
257 1.1 cgd printf("st%d: Bad density (minor number)%d\n",unit,dsty);
258 1.1 cgd return(EINVAL);
259 1.1 cgd }
260 1.1 cgd if(scsi_debug & (PRINTROUTINES | TRACEOPENS))
261 1.1 cgd printf("stopen: dev=0x%x (unit %d (of %d))\n"
262 1.1 cgd , dev, unit, NST);
263 1.1 cgd /*******************************************************\
264 1.1 cgd * Make sure the device has been initialised *
265 1.1 cgd \*******************************************************/
266 1.1 cgd
267 1.1 cgd if (!st_initialized[unit])
268 1.1 cgd return(ENXIO);
269 1.1 cgd /*******************************************************\
270 1.1 cgd * Check that it is still responding and ok. *
271 1.1 cgd \*******************************************************/
272 1.1 cgd
273 1.1 cgd if(scsi_debug & TRACEOPENS)
274 1.1 cgd printf("device is ");
275 1.1 cgd if (!(st_req_sense(unit, 0)))
276 1.1 cgd {
277 1.1 cgd errcode = ENXIO;
278 1.1 cgd if(scsi_debug & TRACEOPENS)
279 1.1 cgd printf("not responding\n");
280 1.1 cgd goto bad;
281 1.1 cgd }
282 1.1 cgd if(scsi_debug & TRACEOPENS)
283 1.1 cgd printf("ok\n");
284 1.1 cgd
285 1.1 cgd if(!(st_test_ready(unit,0)))
286 1.1 cgd {
287 1.1 cgd printf("st%d not ready\n",unit);
288 1.1 cgd return(EIO);
289 1.1 cgd }
290 1.1 cgd
291 1.1 cgd if(!st_info_valid[unit]) /* is media new? */
292 1.1 cgd if(!st_load(unit,LD_LOAD,0))
293 1.1 cgd {
294 1.1 cgd return(EIO);
295 1.1 cgd }
296 1.1 cgd
297 1.1 cgd if(!st_rd_blk_lim(unit,0))
298 1.1 cgd {
299 1.1 cgd return(EIO);
300 1.1 cgd }
301 1.1 cgd
302 1.1 cgd if(!st_mode_sense(unit,0))
303 1.1 cgd {
304 1.1 cgd return(EIO);
305 1.1 cgd }
306 1.1 cgd
307 1.1 cgd if(!st_mode_select(unit,0,dsty_code))
308 1.1 cgd {
309 1.1 cgd return(EIO);
310 1.1 cgd }
311 1.1 cgd
312 1.1 cgd st_info_valid[unit] = TRUE;
313 1.1 cgd
314 1.1 cgd st_prevent(unit,PR_PREVENT,0); /* who cares if it fails? */
315 1.1 cgd
316 1.1 cgd /*******************************************************\
317 1.1 cgd * Load the physical device parameters *
318 1.1 cgd \*******************************************************/
319 1.1 cgd if(scsi_debug & TRACEOPENS)
320 1.1 cgd printf("Params loaded ");
321 1.1 cgd
322 1.1 cgd
323 1.1 cgd st->flags |= ST_OPEN;
324 1.1 cgd
325 1.1 cgd bad:
326 1.1 cgd return(errcode);
327 1.1 cgd }
328 1.1 cgd
329 1.1 cgd /*******************************************************\
330 1.1 cgd * close the device.. only called if we are the LAST *
331 1.1 cgd * occurence of an open device *
332 1.1 cgd \*******************************************************/
333 1.1 cgd stclose(dev)
334 1.1 cgd {
335 1.1 cgd unsigned char unit,mode;
336 1.1 cgd struct st_data *st;
337 1.1 cgd
338 1.1 cgd unit = UNIT(dev);
339 1.1 cgd mode = MODE(dev);
340 1.1 cgd st = st_data + unit;
341 1.1 cgd
342 1.1 cgd if(scsi_debug & TRACEOPENS)
343 1.1 cgd printf("Closing device");
344 1.1 cgd if(st->flags & ST_WRITTEN)
345 1.1 cgd {
346 1.1 cgd st_write_filemarks(unit,1,0);
347 1.1 cgd }
348 1.1 cgd st->flags &= ~ST_WRITTEN;
349 1.1 cgd switch(mode)
350 1.1 cgd {
351 1.1 cgd case 0:
352 1.1 cgd st_rewind(unit,FALSE,SCSI_SILENT);
353 1.1 cgd st_prevent(unit,PR_ALLOW,SCSI_SILENT);
354 1.1 cgd break;
355 1.1 cgd case 1:
356 1.1 cgd st_prevent(unit,PR_ALLOW,SCSI_SILENT);
357 1.1 cgd break;
358 1.1 cgd case 2:
359 1.1 cgd st_rewind(unit,FALSE,SCSI_SILENT);
360 1.1 cgd st_prevent(unit,PR_ALLOW,SCSI_SILENT);
361 1.1 cgd st_load(unit,LD_UNLOAD,SCSI_SILENT);
362 1.1 cgd break;
363 1.1 cgd case 3:
364 1.1 cgd st_prevent(unit,PR_ALLOW,SCSI_SILENT);
365 1.1 cgd st_load(unit,LD_UNLOAD,SCSI_SILENT);
366 1.1 cgd break;
367 1.1 cgd default:
368 1.1 cgd printf("st%d:close: Bad mode (minor number)%d how's it open?\n"
369 1.1 cgd ,unit,mode);
370 1.1 cgd return(EINVAL);
371 1.1 cgd }
372 1.1 cgd st->flags &= ~ST_PER_OPEN;
373 1.1 cgd return(0);
374 1.1 cgd }
375 1.1 cgd
376 1.1 cgd #ifndef __386BSD__
377 1.1 cgd /*******************************************************\
378 1.1 cgd * Get ownership of this unit's buf *
379 1.1 cgd * If need be, sleep on it, until it comes free *
380 1.1 cgd \*******************************************************/
381 1.1 cgd struct buf *
382 1.1 cgd st_get_buf(unit) {
383 1.1 cgd struct buf *rc;
384 1.1 cgd
385 1.1 cgd while (!(rc = stbuf_free[unit]))
386 1.1 cgd sleep((caddr_t)&stbuf_free[unit], PRIBIO+1);
387 1.1 cgd stbuf_free[unit] = stbuf_free[unit]->b_forw;
388 1.1 cgd rc->b_error = 0;
389 1.1 cgd rc->b_resid = 0;
390 1.1 cgd rc->b_flags = 0;
391 1.1 cgd return(rc);
392 1.1 cgd }
393 1.1 cgd
394 1.1 cgd /*******************************************************\
395 1.1 cgd * Free this unit's buf, wake processes waiting for it *
396 1.1 cgd \*******************************************************/
397 1.1 cgd st_free_buf(unit,bp)
398 1.1 cgd struct buf *bp;
399 1.1 cgd {
400 1.1 cgd if (!stbuf_free[unit])
401 1.1 cgd wakeup((caddr_t)&stbuf_free[unit]);
402 1.1 cgd bp->b_forw = stbuf_free[unit];
403 1.1 cgd stbuf_free[unit] = bp;
404 1.1 cgd }
405 1.1 cgd
406 1.1 cgd
407 1.1 cgd /*******************************************************\
408 1.1 cgd * Get the buf for this unit and use physio to do it *
409 1.1 cgd \*******************************************************/
410 1.1 cgd stread(dev,uio)
411 1.1 cgd register short dev;
412 1.1 cgd struct uio *uio;
413 1.1 cgd {
414 1.1 cgd int unit = UNIT(dev);
415 1.1 cgd struct buf *bp = st_get_buf(unit);
416 1.1 cgd int rc;
417 1.1 cgd rc = physio(ststrategy, bp, dev, B_READ, stminphys, uio);
418 1.1 cgd st_free_buf(unit,bp);
419 1.1 cgd return(rc);
420 1.1 cgd }
421 1.1 cgd
422 1.1 cgd /*******************************************************\
423 1.1 cgd * Get the buf for this unit and use physio to do it *
424 1.1 cgd \*******************************************************/
425 1.1 cgd stwrite(dev,uio)
426 1.1 cgd dev_t dev;
427 1.1 cgd struct uio *uio;
428 1.1 cgd {
429 1.1 cgd int unit = UNIT(dev);
430 1.1 cgd struct buf *bp = st_get_buf(unit);
431 1.1 cgd int rc;
432 1.1 cgd
433 1.1 cgd rc = physio(ststrategy, bp, dev, B_WRITE, stminphys, uio);
434 1.1 cgd st_free_buf(unit,bp);
435 1.1 cgd return(rc);
436 1.1 cgd }
437 1.1 cgd
438 1.1 cgd
439 1.1 cgd #endif __386BSD__
440 1.1 cgd /*******************************************************\
441 1.1 cgd * trim the size of the transfer if needed, *
442 1.1 cgd * called by physio *
443 1.1 cgd * basically the smaller of our min and the scsi driver's*
444 1.1 cgd * minphys *
445 1.1 cgd \*******************************************************/
446 1.1 cgd void stminphys(bp)
447 1.1 cgd struct buf *bp;
448 1.1 cgd {
449 1.1 cgd (*(st_data[UNIT(bp->b_dev)].sc_sw->scsi_minphys))(bp);
450 1.1 cgd }
451 1.1 cgd
452 1.1 cgd /*******************************************************\
453 1.1 cgd * Actually translate the requested transfer into *
454 1.1 cgd * one the physical driver can understand *
455 1.1 cgd * The transfer is described by a buf and will include *
456 1.1 cgd * only one physical transfer. *
457 1.1 cgd \*******************************************************/
458 1.1 cgd
459 1.1 cgd int ststrategy(bp)
460 1.1 cgd struct buf *bp;
461 1.1 cgd {
462 1.1 cgd struct buf *dp;
463 1.1 cgd unsigned char unit;
464 1.1 cgd unsigned int opri;
465 1.1 cgd
466 1.1 cgd ststrats++;
467 1.1 cgd unit = UNIT((bp->b_dev));
468 1.1 cgd if(scsi_debug & PRINTROUTINES) printf("\nststrategy ");
469 1.1 cgd if(scsi_debug & SHOWREQUESTS) printf("st%d: %d bytes @ blk%d\n",
470 1.1 cgd unit,bp->b_bcount,bp->b_blkno);
471 1.1 cgd /*******************************************************\
472 1.1 cgd * If it's a null transfer, return immediatly *
473 1.1 cgd \*******************************************************/
474 1.1 cgd if (bp->b_bcount == 0) {
475 1.1 cgd goto done;
476 1.1 cgd }
477 1.1 cgd
478 1.1 cgd /*******************************************************\
479 1.1 cgd * Odd sized request on fixed drives are verboten *
480 1.1 cgd \*******************************************************/
481 1.1 cgd if((st_data[unit].flags & ST_FIXEDBLOCKS)
482 1.1 cgd && bp->b_bcount % st_data[unit].blkmin)
483 1.1 cgd {
484 1.1 cgd printf("st%d: bad request, must be multiple of %d\n",
485 1.1 cgd unit, st_data[unit].blkmin);
486 1.1 cgd bp->b_error = EIO;
487 1.1 cgd goto bad;
488 1.1 cgd }
489 1.1 cgd
490 1.1 cgd #ifdef __386BSD__
491 1.1 cgd stminphys(bp);
492 1.1 cgd #endif __386BSD__
493 1.1 cgd opri = splbio();
494 1.1 cgd dp = &st_buf_queue[unit];
495 1.1 cgd
496 1.1 cgd /*******************************************************\
497 1.1 cgd * Place it in the queue of disk activities for this tape*
498 1.1 cgd * at the end *
499 1.1 cgd \*******************************************************/
500 1.1 cgd while ( dp->b_actf)
501 1.1 cgd {
502 1.1 cgd dp = dp->b_actf;
503 1.1 cgd }
504 1.1 cgd dp->b_actf = bp;
505 1.1 cgd bp->b_actf = NULL;
506 1.1 cgd
507 1.1 cgd /*******************************************************\
508 1.1 cgd * Tell the device to get going on the transfer if it's *
509 1.1 cgd * not doing anything, otherwise just wait for completion*
510 1.1 cgd \*******************************************************/
511 1.1 cgd ststart(unit);
512 1.1 cgd
513 1.1 cgd splx(opri);
514 1.1 cgd return;
515 1.1 cgd bad:
516 1.1 cgd bp->b_flags |= B_ERROR;
517 1.1 cgd done:
518 1.1 cgd /*******************************************************\
519 1.1 cgd * Correctly set the buf to indicate a completed xfer *
520 1.1 cgd \*******************************************************/
521 1.1 cgd iodone(bp);
522 1.1 cgd return;
523 1.1 cgd }
524 1.1 cgd
525 1.1 cgd
526 1.1 cgd /***************************************************************\
527 1.1 cgd * ststart looks to see if there is a buf waiting for the device *
528 1.1 cgd * and that the device is not already busy. If both are true, *
529 1.1 cgd * It deques the buf and creates a scsi command to perform the *
530 1.1 cgd * transfer in the buf. The transfer request will call st_done *
531 1.1 cgd * on completion, which will in turn call this routine again *
532 1.1 cgd * so that the next queued transfer is performed. *
533 1.1 cgd * The bufs are queued by the strategy routine (ststrategy) *
534 1.1 cgd * *
535 1.1 cgd * This routine is also called after other non-queued requests *
536 1.1 cgd * have been made of the scsi driver, to ensure that the queue *
537 1.1 cgd * continues to be drained. *
538 1.1 cgd \***************************************************************/
539 1.1 cgd /* ststart() is called at splbio */
540 1.1 cgd ststart(unit)
541 1.1 cgd {
542 1.1 cgd int drivecount;
543 1.1 cgd register struct buf *bp = 0;
544 1.1 cgd register struct buf *dp;
545 1.1 cgd struct scsi_xfer *xs;
546 1.1 cgd struct scsi_rw_tape cmd;
547 1.1 cgd int blkno, nblk;
548 1.1 cgd struct st_data *st;
549 1.1 cgd
550 1.1 cgd
551 1.1 cgd st = st_data + unit;
552 1.1 cgd
553 1.1 cgd if(scsi_debug & PRINTROUTINES) printf("ststart%d ",unit);
554 1.1 cgd /*******************************************************\
555 1.1 cgd * See if there is a buf to do and we are not already *
556 1.1 cgd * doing one *
557 1.1 cgd \*******************************************************/
558 1.1 cgd xs=&st_scsi_xfer[unit];
559 1.1 cgd if(xs->flags & INUSE)
560 1.1 cgd {
561 1.1 cgd return; /* unit already underway */
562 1.1 cgd }
563 1.1 cgd trynext:
564 1.1 cgd if(st_xfer_block_wait[unit]) /* a special awaits, let it proceed first */
565 1.1 cgd {
566 1.1 cgd wakeup(&st_xfer_block_wait[unit]);
567 1.1 cgd return;
568 1.1 cgd }
569 1.1 cgd
570 1.1 cgd dp = &st_buf_queue[unit];
571 1.1 cgd if ((bp = dp->b_actf) != NULL)
572 1.1 cgd {
573 1.1 cgd dp->b_actf = bp->b_actf;
574 1.1 cgd }
575 1.1 cgd else /* no work to do */
576 1.1 cgd {
577 1.1 cgd return;
578 1.1 cgd }
579 1.1 cgd xs->flags = INUSE; /* Now ours */
580 1.1 cgd
581 1.1 cgd
582 1.1 cgd /*******************************************************\
583 1.1 cgd * We have a buf, now we should move the data into *
584 1.1 cgd * a scsi_xfer definition and try start it *
585 1.1 cgd \*******************************************************/
586 1.1 cgd
587 1.1 cgd /*******************************************************\
588 1.1 cgd * If we are at a filemark but have not reported it yet *
589 1.1 cgd * then we should report it now *
590 1.1 cgd \*******************************************************/
591 1.1 cgd if(st->flags & ST_AT_FILEMARK)
592 1.1 cgd {
593 1.1 cgd bp->b_error = 0;
594 1.1 cgd bp->b_flags |= B_ERROR; /* EOF*/
595 1.1 cgd st->flags &= ~ST_AT_FILEMARK;
596 1.1 cgd biodone(bp);
597 1.1 cgd xs->flags = 0; /* won't need it now */
598 1.1 cgd goto trynext;
599 1.1 cgd }
600 1.1 cgd /*******************************************************\
601 1.1 cgd * If we are at EOM but have not reported it yet *
602 1.1 cgd * then we should report it now *
603 1.1 cgd \*******************************************************/
604 1.1 cgd if(st->flags & ST_AT_EOM)
605 1.1 cgd {
606 1.1 cgd bp->b_error = EIO;
607 1.1 cgd bp->b_flags |= B_ERROR;
608 1.1 cgd st->flags &= ~ST_AT_EOM;
609 1.1 cgd biodone(bp);
610 1.1 cgd xs->flags = 0; /* won't need it now */
611 1.1 cgd goto trynext;
612 1.1 cgd }
613 1.1 cgd /*******************************************************\
614 1.1 cgd * Fill out the scsi command *
615 1.1 cgd \*******************************************************/
616 1.1 cgd bzero(&cmd, sizeof(cmd));
617 1.1 cgd if((bp->b_flags & B_READ) == B_WRITE)
618 1.1 cgd {
619 1.1 cgd st->flags |= ST_WRITTEN;
620 1.1 cgd xs->flags |= SCSI_DATA_OUT;
621 1.1 cgd }
622 1.1 cgd else
623 1.1 cgd {
624 1.1 cgd xs->flags |= SCSI_DATA_IN;
625 1.1 cgd }
626 1.1 cgd cmd.op_code = (bp->b_flags & B_READ)
627 1.1 cgd ? READ_COMMAND_TAPE
628 1.1 cgd : WRITE_COMMAND_TAPE;
629 1.1 cgd
630 1.1 cgd /*******************************************************\
631 1.1 cgd * Handle "fixed-block-mode" tape drives by using the *
632 1.1 cgd * block count instead of the length. *
633 1.1 cgd \*******************************************************/
634 1.1 cgd if(st->flags & ST_FIXEDBLOCKS)
635 1.1 cgd {
636 1.1 cgd cmd.fixed = 1;
637 1.1 cgd lto3b(bp->b_bcount/st->blkmin,cmd.len);
638 1.1 cgd }
639 1.1 cgd else
640 1.1 cgd {
641 1.1 cgd lto3b(bp->b_bcount,cmd.len);
642 1.1 cgd }
643 1.1 cgd
644 1.1 cgd /*******************************************************\
645 1.1 cgd * Fill out the scsi_xfer structure *
646 1.1 cgd * Note: we cannot sleep as we may be an interrupt *
647 1.1 cgd \*******************************************************/
648 1.1 cgd xs->flags |= SCSI_NOSLEEP;
649 1.1 cgd xs->adapter = st->ctlr;
650 1.1 cgd xs->targ = st->targ;
651 1.1 cgd xs->lu = st->lu;
652 1.1 cgd xs->retries = 1; /* can't retry on tape*/
653 1.1 cgd xs->timeout = 100000; /* allow 100 secs for retension */
654 1.1 cgd xs->cmd = (struct scsi_generic *)&cmd;
655 1.1 cgd xs->cmdlen = sizeof(cmd);
656 1.1 cgd xs->data = (u_char *)bp->b_un.b_addr;
657 1.1 cgd xs->datalen = bp->b_bcount;
658 1.1 cgd xs->resid = bp->b_bcount;
659 1.1 cgd xs->when_done = st_done;
660 1.1 cgd xs->done_arg = unit;
661 1.1 cgd xs->done_arg2 = (int)xs;
662 1.1 cgd xs->error = XS_NOERROR;
663 1.1 cgd xs->bp = bp;
664 1.1 cgd /*******************************************************\
665 1.1 cgd * Pass all this info to the scsi driver. *
666 1.1 cgd \*******************************************************/
667 1.1 cgd
668 1.1 cgd
669 1.1 cgd #if defined(OSF)||defined(FIX_ME)
670 1.1 cgd if (bp->b_flags & B_PHYS) {
671 1.1 cgd xs->data = (u_char*)map_pva_kva(bp->b_proc, bp->b_un.b_addr,
672 1.1 cgd bp->b_bcount, st_window[unit],
673 1.1 cgd (bp->b_flags&B_READ)?B_WRITE:B_READ);
674 1.1 cgd } else {
675 1.1 cgd xs->data = (u_char*)bp->b_un.b_addr;
676 1.1 cgd }
677 1.1 cgd #endif /* defined(OSF) */
678 1.1 cgd
679 1.1 cgd if ( (*(st->sc_sw->scsi_cmd))(xs) != SUCCESSFULLY_QUEUED)
680 1.1 cgd {
681 1.1 cgd printf("st%d: oops not queued",unit);
682 1.1 cgd xs->error = XS_DRIVER_STUFFUP;
683 1.1 cgd st_done(unit,xs);
684 1.1 cgd }
685 1.1 cgd stqueues++;
686 1.1 cgd }
687 1.1 cgd
688 1.1 cgd /*******************************************************\
689 1.1 cgd * This routine is called by the scsi interrupt when *
690 1.1 cgd * the transfer is complete.
691 1.1 cgd \*******************************************************/
692 1.1 cgd int st_done(unit,xs)
693 1.1 cgd int unit;
694 1.1 cgd struct scsi_xfer *xs;
695 1.1 cgd {
696 1.1 cgd struct buf *bp;
697 1.1 cgd int retval;
698 1.1 cgd
699 1.1 cgd if(scsi_debug & PRINTROUTINES) printf("st_done%d ",unit);
700 1.1 cgd if (! (xs->flags & INUSE))
701 1.1 cgd panic("scsi_xfer not in use!");
702 1.1 cgd if(bp = xs->bp)
703 1.1 cgd {
704 1.1 cgd switch(xs->error)
705 1.1 cgd {
706 1.1 cgd case XS_NOERROR:
707 1.1 cgd bp->b_flags &= ~B_ERROR;
708 1.1 cgd bp->b_error = 0;
709 1.1 cgd bp->b_resid = 0;
710 1.1 cgd break;
711 1.1 cgd case XS_SENSE:
712 1.1 cgd retval = (st_interpret_sense(unit,xs));
713 1.1 cgd if(retval)
714 1.1 cgd {
715 1.1 cgd /***************************************\
716 1.1 cgd * We have a real error, the bit should *
717 1.1 cgd * be set to indicate this. The return *
718 1.1 cgd * value will contain the unix error code*
719 1.1 cgd * that the error interpretation routine *
720 1.1 cgd * thought was suitable, so pass this *
721 1.1 cgd * value back in the buf structure. *
722 1.1 cgd * Furthermore we return information *
723 1.1 cgd * saying that no data was transferred *
724 1.1 cgd \***************************************/
725 1.1 cgd bp->b_flags |= B_ERROR;
726 1.1 cgd bp->b_error = retval;
727 1.1 cgd bp->b_resid = bp->b_bcount;
728 1.1 cgd st_data[unit].flags
729 1.1 cgd &= ~(ST_AT_FILEMARK|ST_AT_EOM);
730 1.1 cgd }
731 1.1 cgd else
732 1.1 cgd {
733 1.1 cgd /***********************************************\
734 1.1 cgd * The error interpretation code has declared *
735 1.1 cgd * that it wasn't a real error, or at least that *
736 1.1 cgd * we should be ignoring it if it was. *
737 1.1 cgd \***********************************************/
738 1.1 cgd if(xs->resid && ( xs->resid != xs->datalen ))
739 1.1 cgd {
740 1.1 cgd /***************************************\
741 1.1 cgd * Here we have the tricky part.. *
742 1.1 cgd * We successfully read less data than *
743 1.1 cgd * we requested. (but not 0) *
744 1.1 cgd *------for variable blocksize tapes:----*
745 1.1 cgd * UNDER 386BSD: *
746 1.1 cgd * We should legitimatly have the error *
747 1.1 cgd * bit set, with the error value set to *
748 1.1 cgd * zero.. This is to indicate to the *
749 1.1 cgd * physio code that while we didn't get *
750 1.1 cgd * as much information as was requested, *
751 1.1 cgd * we did reach the end of the record *
752 1.1 cgd * and so physio should not call us *
753 1.1 cgd * again for more data... we have it all *
754 1.1 cgd * SO SET THE ERROR BIT! *
755 1.1 cgd * *
756 1.1 cgd * UNDER MACH:(CMU) *
757 1.1 cgd * To indicate the same as above, we *
758 1.1 cgd * need only have a non 0 resid that is *
759 1.1 cgd * less than the b_bcount, but the *
760 1.1 cgd * ERROR BIT MUST BE CLEAR! (sigh) *
761 1.1 cgd * *
762 1.1 cgd * UNDER OSF1: *
763 1.1 cgd * To indicate the same as above, we *
764 1.1 cgd * need to have a non 0 resid that is *
765 1.1 cgd * less than the b_bcount, but the *
766 1.1 cgd * ERROR BIT MUST BE SET! (gasp)(sigh) *
767 1.1 cgd * *
768 1.1 cgd *-------for fixed blocksize device------*
769 1.1 cgd * We could have read some successful *
770 1.1 cgd * records before hitting *
771 1.1 cgd * the EOF or EOT. These must be passed *
772 1.1 cgd * to the user, before we report the *
773 1.1 cgd * EOx. Only if there is no data for the *
774 1.1 cgd * user do we report it now. (via an EIO *
775 1.1 cgd * for EOM and resid == count for EOF). *
776 1.1 cgd * We will report the EOx NEXT time.. *
777 1.1 cgd \***************************************/
778 1.1 cgd #ifdef MACH /*osf and cmu varieties */
779 1.1 cgd #ifdef OSF
780 1.1 cgd bp->b_flags |= B_ERROR;
781 1.1 cgd #else OSF
782 1.1 cgd bp->b_flags &= ~B_ERROR;
783 1.1 cgd #endif OSF
784 1.1 cgd #endif MACH
785 1.1 cgd #ifdef __386BSD__
786 1.1 cgd bp->b_flags |= B_ERROR;
787 1.1 cgd #endif __386BSD__
788 1.1 cgd bp->b_error = 0;
789 1.1 cgd bp->b_resid = xs->resid;
790 1.1 cgd if((st_data[unit].flags & ST_FIXEDBLOCKS))
791 1.1 cgd {
792 1.1 cgd bp->b_resid *= st_data[unit].blkmin;
793 1.1 cgd if( (st_data[unit].flags & ST_AT_EOM)
794 1.1 cgd && (bp->b_resid == bp->b_bcount))
795 1.1 cgd {
796 1.1 cgd bp->b_error = EIO;
797 1.1 cgd st_data[unit].flags
798 1.1 cgd &= ~ST_AT_EOM;
799 1.1 cgd }
800 1.1 cgd }
801 1.1 cgd xs->error = XS_NOERROR;
802 1.1 cgd break;
803 1.1 cgd }
804 1.1 cgd else
805 1.1 cgd {
806 1.1 cgd /***************************************\
807 1.1 cgd * We have come out of the error handler *
808 1.1 cgd * with no error code.. we have also *
809 1.1 cgd * not had an ili (would have gone to *
810 1.1 cgd * the previous clause). Now we need to *
811 1.1 cgd * distiguish between succesful read of *
812 1.1 cgd * no data (EOF or EOM) and successfull *
813 1.1 cgd * read of all requested data. *
814 1.1 cgd * At least all o/s agree that: *
815 1.1 cgd * 0 bytes read with no error is EOF *
816 1.1 cgd * 0 bytes read with an EIO is EOM *
817 1.1 cgd \***************************************/
818 1.1 cgd
819 1.1 cgd bp->b_resid = bp->b_bcount;
820 1.1 cgd if(st_data[unit].flags & ST_AT_FILEMARK)
821 1.1 cgd {
822 1.1 cgd st_data[unit].flags &= ~ST_AT_FILEMARK;
823 1.1 cgd bp->b_flags &= ~B_ERROR;
824 1.1 cgd bp->b_error = 0;
825 1.1 cgd break;
826 1.1 cgd }
827 1.1 cgd if(st_data[unit].flags & ST_AT_EOM)
828 1.1 cgd {
829 1.1 cgd bp->b_flags |= B_ERROR;
830 1.1 cgd bp->b_error = EIO;
831 1.1 cgd st_data[unit].flags &= ~ST_AT_EOM;
832 1.1 cgd break;
833 1.1 cgd }
834 1.1 cgd printf("st%d:error ignored\n" ,unit);
835 1.1 cgd }
836 1.1 cgd }
837 1.1 cgd break;
838 1.1 cgd
839 1.1 cgd case XS_TIMEOUT:
840 1.1 cgd printf("st%d timeout\n",unit);
841 1.1 cgd break;
842 1.1 cgd
843 1.1 cgd case XS_BUSY: /* should retry */ /* how? */
844 1.1 cgd /************************************************/
845 1.1 cgd /* SHOULD put buf back at head of queue */
846 1.1 cgd /* and decrement retry count in (*xs) */
847 1.1 cgd /* HOWEVER, this should work as a kludge */
848 1.1 cgd /************************************************/
849 1.1 cgd if(xs->retries--)
850 1.1 cgd {
851 1.1 cgd xs->flags &= ~ITSDONE;
852 1.1 cgd xs->error = XS_NOERROR;
853 1.1 cgd if ( (*(st_data[unit].sc_sw->scsi_cmd))(xs)
854 1.1 cgd == SUCCESSFULLY_QUEUED)
855 1.1 cgd { /* don't wake the job, ok? */
856 1.1 cgd return;
857 1.1 cgd }
858 1.1 cgd printf("device busy");
859 1.1 cgd xs->flags |= ITSDONE;
860 1.1 cgd }
861 1.1 cgd
862 1.1 cgd case XS_DRIVER_STUFFUP:
863 1.1 cgd bp->b_flags |= B_ERROR;
864 1.1 cgd bp->b_error = EIO;
865 1.1 cgd break;
866 1.1 cgd default:
867 1.1 cgd printf("st%d: unknown error category from scsi driver\n"
868 1.1 cgd ,unit);
869 1.1 cgd }
870 1.1 cgd biodone(bp);
871 1.1 cgd xs->flags = 0; /* no longer in use */
872 1.1 cgd ststart(unit); /* If there's another waiting.. do it */
873 1.1 cgd }
874 1.1 cgd else
875 1.1 cgd {
876 1.1 cgd wakeup(xs);
877 1.1 cgd }
878 1.1 cgd }
879 1.1 cgd /*******************************************************\
880 1.1 cgd * Perform special action on behalf of the user *
881 1.1 cgd * Knows about the internals of this device *
882 1.1 cgd \*******************************************************/
883 1.1 cgd stioctl(dev, cmd, arg, mode)
884 1.1 cgd dev_t dev;
885 1.1 cgd int cmd;
886 1.1 cgd caddr_t arg;
887 1.1 cgd {
888 1.1 cgd register i,j;
889 1.1 cgd unsigned int opri;
890 1.1 cgd int errcode = 0;
891 1.1 cgd unsigned char unit;
892 1.1 cgd int number,flags,ret;
893 1.1 cgd
894 1.1 cgd /*******************************************************\
895 1.1 cgd * Find the device that the user is talking about *
896 1.1 cgd \*******************************************************/
897 1.1 cgd flags = 0; /* give error messages, act on errors etc. */
898 1.1 cgd unit = UNIT(dev);
899 1.1 cgd
900 1.1 cgd switch(cmd)
901 1.1 cgd {
902 1.1 cgd
903 1.1 cgd case MTIOCGET:
904 1.1 cgd {
905 1.1 cgd struct mtget *g = (struct mtget *) arg;
906 1.1 cgd
907 1.1 cgd bzero(g, sizeof(struct mtget));
908 1.1 cgd g->mt_type = 0x7; /* Ultrix compat */ /*?*/
909 1.1 cgd ret=TRUE;
910 1.1 cgd break;
911 1.1 cgd }
912 1.1 cgd
913 1.1 cgd
914 1.1 cgd case MTIOCTOP:
915 1.1 cgd {
916 1.1 cgd struct mtop *mt = (struct mtop *) arg;
917 1.1 cgd
918 1.1 cgd if (st_debug)
919 1.1 cgd printf("[sctape_sstatus: %x %x]\n",
920 1.1 cgd mt->mt_op, mt->mt_count);
921 1.1 cgd
922 1.1 cgd
923 1.1 cgd
924 1.1 cgd /* compat: in U*x it is a short */
925 1.1 cgd number = mt->mt_count;
926 1.1 cgd switch ((short)(mt->mt_op))
927 1.1 cgd {
928 1.1 cgd case MTWEOF: /* write an end-of-file record */
929 1.1 cgd ret = st_write_filemarks(unit,number,flags);
930 1.1 cgd st_data[unit].flags &= ~ST_WRITTEN;
931 1.1 cgd break;
932 1.1 cgd case MTFSF: /* forward space file */
933 1.1 cgd ret = st_space(unit,number,SP_FILEMARKS,flags);
934 1.1 cgd break;
935 1.1 cgd case MTBSF: /* backward space file */
936 1.1 cgd ret = st_space(unit,-number,SP_FILEMARKS,flags);
937 1.1 cgd break;
938 1.1 cgd case MTFSR: /* forward space record */
939 1.1 cgd ret = st_space(unit,number,SP_BLKS,flags);
940 1.1 cgd break;
941 1.1 cgd case MTBSR: /* backward space record */
942 1.1 cgd ret = st_space(unit,-number,SP_BLKS,flags);
943 1.1 cgd break;
944 1.1 cgd case MTREW: /* rewind */
945 1.1 cgd ret = st_rewind(unit,FALSE,flags);
946 1.1 cgd break;
947 1.1 cgd case MTOFFL: /* rewind and put the drive offline */
948 1.1 cgd if((ret = st_rewind(unit,FALSE,flags)))
949 1.1 cgd {
950 1.1 cgd st_prevent(unit,PR_ALLOW,0);
951 1.1 cgd ret = st_load(unit,LD_UNLOAD,flags);
952 1.1 cgd }
953 1.1 cgd else
954 1.1 cgd {
955 1.1 cgd printf("rewind failed, unit still loaded\n");
956 1.1 cgd }
957 1.1 cgd break;
958 1.1 cgd case MTNOP: /* no operation, sets status only */
959 1.1 cgd case MTCACHE: /* enable controller cache */
960 1.1 cgd case MTNOCACHE: /* disable controller cache */
961 1.1 cgd ret = TRUE;;
962 1.1 cgd break;
963 1.1 cgd default:
964 1.1 cgd return EINVAL;
965 1.1 cgd }
966 1.1 cgd break;
967 1.1 cgd }
968 1.1 cgd case MTIOCIEOT:
969 1.1 cgd case MTIOCEEOT:
970 1.1 cgd ret=TRUE;
971 1.1 cgd break;
972 1.1 cgd }
973 1.1 cgd
974 1.1 cgd return(ret?ESUCCESS:EIO);
975 1.1 cgd }
976 1.1 cgd
977 1.1 cgd
978 1.1 cgd /*******************************************************\
979 1.1 cgd * Check with the device that it is ok, (via scsi driver)*
980 1.1 cgd \*******************************************************/
981 1.1 cgd st_req_sense(unit, flags)
982 1.1 cgd int flags;
983 1.1 cgd {
984 1.1 cgd struct scsi_sense_data sense;
985 1.1 cgd struct scsi_sense scsi_cmd;
986 1.1 cgd
987 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
988 1.1 cgd scsi_cmd.op_code = REQUEST_SENSE;
989 1.1 cgd scsi_cmd.length = sizeof(sense);
990 1.1 cgd
991 1.1 cgd if (st_scsi_cmd(unit,
992 1.1 cgd &scsi_cmd,
993 1.1 cgd sizeof(scsi_cmd),
994 1.1 cgd &sense,
995 1.1 cgd sizeof(sense),
996 1.1 cgd 100000,
997 1.1 cgd flags | SCSI_DATA_IN) != 0)
998 1.1 cgd {
999 1.1 cgd return(FALSE);
1000 1.1 cgd }
1001 1.1 cgd else
1002 1.1 cgd return(TRUE);
1003 1.1 cgd }
1004 1.1 cgd
1005 1.1 cgd /*******************************************************\
1006 1.1 cgd * Get scsi driver to send a "are you ready" command *
1007 1.1 cgd \*******************************************************/
1008 1.1 cgd st_test_ready(unit,flags)
1009 1.1 cgd int unit,flags;
1010 1.1 cgd {
1011 1.1 cgd struct scsi_test_unit_ready scsi_cmd;
1012 1.1 cgd
1013 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1014 1.1 cgd scsi_cmd.op_code = TEST_UNIT_READY;
1015 1.1 cgd
1016 1.1 cgd if (st_scsi_cmd(unit,
1017 1.1 cgd &scsi_cmd,
1018 1.1 cgd sizeof(scsi_cmd),
1019 1.1 cgd 0,
1020 1.1 cgd 0,
1021 1.1 cgd 100000,
1022 1.1 cgd flags) != 0) {
1023 1.1 cgd return(FALSE);
1024 1.1 cgd } else
1025 1.1 cgd return(TRUE);
1026 1.1 cgd }
1027 1.1 cgd
1028 1.1 cgd
1029 1.1 cgd #ifdef __STDC__
1030 1.1 cgd #define b2tol(a) (((unsigned)(a##_1) << 8) + (unsigned)a##_0 )
1031 1.1 cgd #else
1032 1.1 cgd #define b2tol(a) (((unsigned)(a/**/_1) << 8) + (unsigned)a/**/_0 )
1033 1.1 cgd #endif
1034 1.1 cgd
1035 1.1 cgd /*******************************************************\
1036 1.1 cgd * Ask the drive what it's min and max blk sizes are. *
1037 1.1 cgd \*******************************************************/
1038 1.1 cgd st_rd_blk_lim(unit, flags)
1039 1.1 cgd int unit,flags;
1040 1.1 cgd {
1041 1.1 cgd struct scsi_blk_limits scsi_cmd;
1042 1.1 cgd struct scsi_blk_limits_data scsi_blkl;
1043 1.1 cgd struct st_data *st = st_data + unit;
1044 1.1 cgd /*******************************************************\
1045 1.1 cgd * First check if we have it all loaded *
1046 1.1 cgd \*******************************************************/
1047 1.1 cgd if (st_info_valid[unit]) goto done;
1048 1.1 cgd
1049 1.1 cgd /*******************************************************\
1050 1.1 cgd * do a 'Read Block Limits' *
1051 1.1 cgd \*******************************************************/
1052 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1053 1.1 cgd scsi_cmd.op_code = READ_BLK_LIMITS;
1054 1.1 cgd
1055 1.1 cgd /*******************************************************\
1056 1.1 cgd * do the command, update the global values *
1057 1.1 cgd \*******************************************************/
1058 1.1 cgd if (st_scsi_cmd(unit,
1059 1.1 cgd &scsi_cmd,
1060 1.1 cgd sizeof(scsi_cmd),
1061 1.1 cgd &scsi_blkl,
1062 1.1 cgd sizeof(scsi_blkl),
1063 1.1 cgd 5000,
1064 1.1 cgd flags | SCSI_DATA_IN) != 0)
1065 1.1 cgd {
1066 1.1 cgd if(!(flags & SCSI_SILENT))
1067 1.1 cgd printf("could not get blk limits for unit %d\n", unit);
1068 1.1 cgd st_info_valid[unit] = FALSE;
1069 1.1 cgd return(FALSE);
1070 1.1 cgd }
1071 1.1 cgd if (st_debug)
1072 1.1 cgd {
1073 1.1 cgd printf(" (%d <= blksiz <= %d\n) ",
1074 1.1 cgd b2tol(scsi_blkl.min_length),
1075 1.1 cgd _3btol(&scsi_blkl.max_length_2));
1076 1.1 cgd }
1077 1.1 cgd st->blkmin = b2tol(scsi_blkl.min_length);
1078 1.1 cgd st->blkmax = _3btol(&scsi_blkl.max_length_2);
1079 1.1 cgd
1080 1.1 cgd done:
1081 1.1 cgd if(st->blkmin && (st->blkmin == st->blkmax))
1082 1.1 cgd {
1083 1.1 cgd st->flags |= ST_FIXEDBLOCKS;
1084 1.1 cgd }
1085 1.1 cgd return(TRUE);
1086 1.1 cgd }
1087 1.1 cgd /*******************************************************\
1088 1.1 cgd * Get the scsi driver to send a full inquiry to the *
1089 1.1 cgd * device and use the results to fill out the global *
1090 1.1 cgd * parameter structure. *
1091 1.1 cgd \*******************************************************/
1092 1.1 cgd st_mode_sense(unit, flags)
1093 1.1 cgd int unit,flags;
1094 1.1 cgd {
1095 1.1 cgd struct scsi_mode_sense scsi_cmd;
1096 1.1 cgd struct
1097 1.1 cgd {
1098 1.1 cgd struct scsi_mode_header_tape header;
1099 1.1 cgd struct blk_desc blk_desc;
1100 1.1 cgd }scsi_sense;
1101 1.1 cgd struct st_data *st = st_data + unit;
1102 1.1 cgd
1103 1.1 cgd /*******************************************************\
1104 1.1 cgd * First check if we have it all loaded *
1105 1.1 cgd \*******************************************************/
1106 1.1 cgd if (st_info_valid[unit]) return(TRUE);
1107 1.1 cgd /*******************************************************\
1108 1.1 cgd * First do a mode sense *
1109 1.1 cgd \*******************************************************/
1110 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1111 1.1 cgd scsi_cmd.op_code = MODE_SENSE;
1112 1.1 cgd scsi_cmd.length = sizeof(scsi_sense);
1113 1.1 cgd /*******************************************************\
1114 1.1 cgd * do the command, but we don't need the results *
1115 1.1 cgd * just print them for our interest's sake *
1116 1.1 cgd \*******************************************************/
1117 1.1 cgd if (st_scsi_cmd(unit,
1118 1.1 cgd &scsi_cmd,
1119 1.1 cgd sizeof(scsi_cmd),
1120 1.1 cgd &scsi_sense,
1121 1.1 cgd sizeof(scsi_sense),
1122 1.1 cgd 5000,
1123 1.1 cgd flags | SCSI_DATA_IN) != 0)
1124 1.1 cgd {
1125 1.1 cgd if(!(flags & SCSI_SILENT))
1126 1.1 cgd printf("could not mode sense for unit %d\n", unit);
1127 1.1 cgd st_info_valid[unit] = FALSE;
1128 1.1 cgd return(FALSE);
1129 1.1 cgd }
1130 1.1 cgd if (st_debug)
1131 1.1 cgd {
1132 1.1 cgd printf("unit %d: %d blocks of %d bytes, write %s, %sbuffered",
1133 1.1 cgd unit,
1134 1.1 cgd _3btol(&scsi_sense.blk_desc.nblocks),
1135 1.1 cgd _3btol(&scsi_sense.blk_desc.blklen),
1136 1.1 cgd (scsi_sense.header.write_protected ?
1137 1.1 cgd "protected" : "enabled"),
1138 1.1 cgd (scsi_sense.header.buf_mode ?
1139 1.1 cgd "" : "un")
1140 1.1 cgd );
1141 1.1 cgd }
1142 1.1 cgd st->numblks = _3btol(&scsi_sense.blk_desc.nblocks);
1143 1.1 cgd st->blksiz = _3btol(&scsi_sense.blk_desc.blklen);
1144 1.1 cgd return(TRUE);
1145 1.1 cgd }
1146 1.1 cgd
1147 1.1 cgd /*******************************************************\
1148 1.1 cgd * Get the scsi driver to send a full inquiry to the *
1149 1.1 cgd * device and use the results to fill out the global *
1150 1.1 cgd * parameter structure. *
1151 1.1 cgd \*******************************************************/
1152 1.1 cgd st_mode_select(unit, flags, dsty_code)
1153 1.1 cgd int unit,flags,dsty_code;
1154 1.1 cgd {
1155 1.1 cgd struct scsi_mode_select scsi_cmd;
1156 1.1 cgd struct
1157 1.1 cgd {
1158 1.1 cgd struct scsi_mode_header_tape header;
1159 1.1 cgd struct blk_desc blk_desc;
1160 1.1 cgd }dat;
1161 1.1 cgd struct st_data *st = st_data + unit;
1162 1.1 cgd
1163 1.1 cgd /*******************************************************\
1164 1.1 cgd * Set up for a mode select *
1165 1.1 cgd \*******************************************************/
1166 1.1 cgd bzero(&dat, sizeof(dat));
1167 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1168 1.1 cgd scsi_cmd.op_code = MODE_SELECT;
1169 1.1 cgd scsi_cmd.length = sizeof(dat);
1170 1.1 cgd dat.header.blk_desc_len = sizeof(struct blk_desc);
1171 1.1 cgd dat.header.buf_mode = 1;
1172 1.1 cgd dat.blk_desc.density = dsty_code;
1173 1.1 cgd if(st->flags & ST_FIXEDBLOCKS)
1174 1.1 cgd {
1175 1.1 cgd lto3b( st->blkmin , dat.blk_desc.blklen);
1176 1.1 cgd }
1177 1.1 cgd /* lto3b( st->numblks , dat.blk_desc.nblocks); use defaults!!!!
1178 1.1 cgd lto3b( st->blksiz , dat.blk_desc.blklen);
1179 1.1 cgd */
1180 1.1 cgd /*******************************************************\
1181 1.1 cgd * do the command *
1182 1.1 cgd \*******************************************************/
1183 1.1 cgd if (st_scsi_cmd(unit,
1184 1.1 cgd &scsi_cmd,
1185 1.1 cgd sizeof(scsi_cmd),
1186 1.1 cgd &dat,
1187 1.1 cgd sizeof(dat),
1188 1.1 cgd 5000,
1189 1.1 cgd flags | SCSI_DATA_OUT) != 0)
1190 1.1 cgd {
1191 1.1 cgd if(!(flags & SCSI_SILENT))
1192 1.1 cgd printf("could not mode select for unit %d\n", unit);
1193 1.1 cgd st_info_valid[unit] = FALSE;
1194 1.1 cgd return(FALSE);
1195 1.1 cgd }
1196 1.1 cgd return(TRUE);
1197 1.1 cgd }
1198 1.1 cgd
1199 1.1 cgd /*******************************************************\
1200 1.1 cgd * skip N blocks/filemarks/seq filemarks/eom *
1201 1.1 cgd \*******************************************************/
1202 1.1 cgd st_space(unit,number,what,flags)
1203 1.1 cgd int unit,number,what,flags;
1204 1.1 cgd {
1205 1.1 cgd struct scsi_space scsi_cmd;
1206 1.1 cgd
1207 1.1 cgd /* if we are at a filemark now, we soon won't be*/
1208 1.1 cgd st_data[unit].flags &= ~(ST_AT_FILEMARK | ST_AT_EOM);
1209 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1210 1.1 cgd scsi_cmd.op_code = SPACE;
1211 1.1 cgd scsi_cmd.code = what;
1212 1.1 cgd lto3b(number,scsi_cmd.number);
1213 1.1 cgd if (st_scsi_cmd(unit,
1214 1.1 cgd &scsi_cmd,
1215 1.1 cgd sizeof(scsi_cmd),
1216 1.1 cgd 0,
1217 1.1 cgd 0,
1218 1.1 cgd 600000, /* 10 mins enough? */
1219 1.1 cgd flags) != 0)
1220 1.1 cgd {
1221 1.1 cgd if(!(flags & SCSI_SILENT))
1222 1.1 cgd printf("could not space st%d\n", unit);
1223 1.1 cgd st_info_valid[unit] = FALSE;
1224 1.1 cgd return(FALSE);
1225 1.1 cgd }
1226 1.1 cgd return(TRUE);
1227 1.1 cgd }
1228 1.1 cgd /*******************************************************\
1229 1.1 cgd * write N filemarks *
1230 1.1 cgd \*******************************************************/
1231 1.1 cgd st_write_filemarks(unit,number,flags)
1232 1.1 cgd int unit,number,flags;
1233 1.1 cgd {
1234 1.1 cgd struct scsi_write_filemarks scsi_cmd;
1235 1.1 cgd
1236 1.1 cgd st_data[unit].flags &= ~(ST_AT_FILEMARK);
1237 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1238 1.1 cgd scsi_cmd.op_code = WRITE_FILEMARKS;
1239 1.1 cgd lto3b(number,scsi_cmd.number);
1240 1.1 cgd if (st_scsi_cmd(unit,
1241 1.1 cgd &scsi_cmd,
1242 1.1 cgd sizeof(scsi_cmd),
1243 1.1 cgd 0,
1244 1.1 cgd 0,
1245 1.1 cgd 100000, /* 10 secs.. (may need to repos head )*/
1246 1.1 cgd flags) != 0)
1247 1.1 cgd {
1248 1.1 cgd if(!(flags & SCSI_SILENT))
1249 1.1 cgd printf("could not write_filemarks st%d\n", unit);
1250 1.1 cgd st_info_valid[unit] = FALSE;
1251 1.1 cgd return(FALSE);
1252 1.1 cgd }
1253 1.1 cgd return(TRUE);
1254 1.1 cgd }
1255 1.1 cgd /*******************************************************\
1256 1.1 cgd * load /unload (with retension if true) *
1257 1.1 cgd \*******************************************************/
1258 1.1 cgd st_load(unit,type,flags)
1259 1.1 cgd int unit,type,flags;
1260 1.1 cgd {
1261 1.1 cgd struct scsi_load scsi_cmd;
1262 1.1 cgd
1263 1.1 cgd st_data[unit].flags &= ~(ST_AT_FILEMARK | ST_AT_EOM);
1264 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1265 1.1 cgd scsi_cmd.op_code = LOAD_UNLOAD;
1266 1.1 cgd scsi_cmd.load=type;
1267 1.1 cgd if (type == LD_LOAD)
1268 1.1 cgd {
1269 1.1 cgd /*scsi_cmd.reten=TRUE;*/
1270 1.1 cgd scsi_cmd.reten=FALSE;
1271 1.1 cgd }
1272 1.1 cgd else
1273 1.1 cgd {
1274 1.1 cgd scsi_cmd.reten=FALSE;
1275 1.1 cgd }
1276 1.1 cgd if (st_scsi_cmd(unit,
1277 1.1 cgd &scsi_cmd,
1278 1.1 cgd sizeof(scsi_cmd),
1279 1.1 cgd 0,
1280 1.1 cgd 0,
1281 1.1 cgd 30000, /* 30 secs */
1282 1.1 cgd flags) != 0)
1283 1.1 cgd {
1284 1.1 cgd if(!(flags & SCSI_SILENT))
1285 1.1 cgd printf("cannot load/unload st%d\n", unit);
1286 1.1 cgd st_info_valid[unit] = FALSE;
1287 1.1 cgd return(FALSE);
1288 1.1 cgd }
1289 1.1 cgd return(TRUE);
1290 1.1 cgd }
1291 1.1 cgd /*******************************************************\
1292 1.1 cgd * Prevent or allow the user to remove the tape *
1293 1.1 cgd \*******************************************************/
1294 1.1 cgd st_prevent(unit,type,flags)
1295 1.1 cgd int unit,type,flags;
1296 1.1 cgd {
1297 1.1 cgd struct scsi_prevent scsi_cmd;
1298 1.1 cgd
1299 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1300 1.1 cgd scsi_cmd.op_code = PREVENT_ALLOW;
1301 1.1 cgd scsi_cmd.prevent=type;
1302 1.1 cgd if (st_scsi_cmd(unit,
1303 1.1 cgd &scsi_cmd,
1304 1.1 cgd sizeof(scsi_cmd),
1305 1.1 cgd 0,
1306 1.1 cgd 0,
1307 1.1 cgd 5000,
1308 1.1 cgd flags) != 0)
1309 1.1 cgd {
1310 1.1 cgd if(!(flags & SCSI_SILENT))
1311 1.1 cgd printf("cannot prevent/allow on st%d\n", unit);
1312 1.1 cgd st_info_valid[unit] = FALSE;
1313 1.1 cgd return(FALSE);
1314 1.1 cgd }
1315 1.1 cgd return(TRUE);
1316 1.1 cgd }
1317 1.1 cgd /*******************************************************\
1318 1.1 cgd * Rewind the device *
1319 1.1 cgd \*******************************************************/
1320 1.1 cgd st_rewind(unit,immed,flags)
1321 1.1 cgd int unit,immed,flags;
1322 1.1 cgd {
1323 1.1 cgd struct scsi_rewind scsi_cmd;
1324 1.1 cgd
1325 1.1 cgd st_data[unit].flags &= ~(ST_AT_FILEMARK | ST_AT_EOM);
1326 1.1 cgd bzero(&scsi_cmd, sizeof(scsi_cmd));
1327 1.1 cgd scsi_cmd.op_code = REWIND;
1328 1.1 cgd scsi_cmd.immed=immed;
1329 1.1 cgd if (st_scsi_cmd(unit,
1330 1.1 cgd &scsi_cmd,
1331 1.1 cgd sizeof(scsi_cmd),
1332 1.1 cgd 0,
1333 1.1 cgd 0,
1334 1.1 cgd immed?5000:300000, /* 5 sec or 5 min */
1335 1.1 cgd flags) != 0)
1336 1.1 cgd {
1337 1.1 cgd if(!(flags & SCSI_SILENT))
1338 1.1 cgd printf("could not rewind st%d\n", unit);
1339 1.1 cgd st_info_valid[unit] = FALSE;
1340 1.1 cgd return(FALSE);
1341 1.1 cgd }
1342 1.1 cgd return(TRUE);
1343 1.1 cgd }
1344 1.1 cgd /*******************************************************\
1345 1.1 cgd * ask the scsi driver to perform a command for us. *
1346 1.1 cgd * Call it through the switch table, and tell it which *
1347 1.1 cgd * sub-unit we want, and what target and lu we wish to *
1348 1.1 cgd * talk to. Also tell it where to find the command *
1349 1.1 cgd * how long int is. *
1350 1.1 cgd * Also tell it where to read/write the data, and how *
1351 1.1 cgd * long the data is supposed to be *
1352 1.1 cgd \*******************************************************/
1353 1.1 cgd int st_scsi_cmd(unit,scsi_cmd,cmdlen,data_addr,datalen,timeout,flags)
1354 1.1 cgd
1355 1.1 cgd int unit,flags;
1356 1.1 cgd struct scsi_generic *scsi_cmd;
1357 1.1 cgd int cmdlen;
1358 1.1 cgd int timeout;
1359 1.1 cgd u_char *data_addr;
1360 1.1 cgd int datalen;
1361 1.1 cgd {
1362 1.1 cgd struct scsi_xfer *xs;
1363 1.1 cgd int retval;
1364 1.1 cgd int s;
1365 1.1 cgd struct st_data *st = st_data + unit;
1366 1.1 cgd
1367 1.1 cgd if(scsi_debug & PRINTROUTINES) printf("\nst_scsi_cmd%d ",unit);
1368 1.1 cgd if(st->sc_sw) /* If we have a scsi driver */
1369 1.1 cgd {
1370 1.1 cgd
1371 1.1 cgd xs = &(st_scsi_xfer[unit]);
1372 1.1 cgd if(!(flags & SCSI_NOMASK))
1373 1.1 cgd s = splbio();
1374 1.1 cgd st_xfer_block_wait[unit]++; /* there is someone waiting */
1375 1.1 cgd while (xs->flags & INUSE)
1376 1.1 cgd {
1377 1.1 cgd sleep(&st_xfer_block_wait[unit],PRIBIO+1);
1378 1.1 cgd }
1379 1.1 cgd st_xfer_block_wait[unit]--;
1380 1.1 cgd xs->flags = INUSE;
1381 1.1 cgd if(!(flags & SCSI_NOMASK))
1382 1.1 cgd splx(s);
1383 1.1 cgd
1384 1.1 cgd /*******************************************************\
1385 1.1 cgd * Fill out the scsi_xfer structure *
1386 1.1 cgd \*******************************************************/
1387 1.1 cgd xs->flags |= flags;
1388 1.1 cgd xs->adapter = st->ctlr;
1389 1.1 cgd xs->targ = st->targ;
1390 1.1 cgd xs->lu = st->lu;
1391 1.1 cgd xs->retries = ST_RETRIES;
1392 1.1 cgd xs->timeout = timeout;
1393 1.1 cgd xs->cmd = scsi_cmd;
1394 1.1 cgd xs->cmdlen = cmdlen;
1395 1.1 cgd xs->data = data_addr;
1396 1.1 cgd xs->datalen = datalen;
1397 1.1 cgd xs->resid = datalen;
1398 1.1 cgd xs->when_done = (flags & SCSI_NOMASK)
1399 1.1 cgd ?(int (*)())0
1400 1.1 cgd :st_done;
1401 1.1 cgd xs->done_arg = unit;
1402 1.1 cgd xs->done_arg2 = (int)xs;
1403 1.1 cgd retry: xs->error = XS_NOERROR;
1404 1.1 cgd xs->bp = 0;
1405 1.1 cgd retval = (*(st->sc_sw->scsi_cmd))(xs);
1406 1.1 cgd switch(retval)
1407 1.1 cgd {
1408 1.1 cgd case SUCCESSFULLY_QUEUED:
1409 1.1 cgd s = splbio();
1410 1.1 cgd while(!(xs->flags & ITSDONE))
1411 1.1 cgd sleep(xs,PRIBIO+1);
1412 1.1 cgd splx(s);
1413 1.1 cgd
1414 1.1 cgd case HAD_ERROR:
1415 1.1 cgd case COMPLETE:
1416 1.1 cgd switch(xs->error)
1417 1.1 cgd {
1418 1.1 cgd case XS_NOERROR:
1419 1.1 cgd retval = ESUCCESS;
1420 1.1 cgd break;
1421 1.1 cgd case XS_SENSE:
1422 1.1 cgd retval = (st_interpret_sense(unit,xs));
1423 1.1 cgd /* only useful for reads */
1424 1.1 cgd if (retval)
1425 1.1 cgd { /* error... don't care about filemarks */
1426 1.1 cgd st->flags &= ~(ST_AT_FILEMARK
1427 1.1 cgd | ST_AT_EOM);
1428 1.1 cgd }
1429 1.1 cgd else
1430 1.1 cgd {
1431 1.1 cgd xs->error = XS_NOERROR;
1432 1.1 cgd retval = ESUCCESS;
1433 1.1 cgd }
1434 1.1 cgd break;
1435 1.1 cgd case XS_DRIVER_STUFFUP:
1436 1.1 cgd retval = EIO;
1437 1.1 cgd break;
1438 1.1 cgd case XS_TIMEOUT:
1439 1.1 cgd if(xs->retries-- )
1440 1.1 cgd {
1441 1.1 cgd xs->flags &= ~ITSDONE;
1442 1.1 cgd goto retry;
1443 1.1 cgd }
1444 1.1 cgd retval = EIO;
1445 1.1 cgd break;
1446 1.1 cgd case XS_BUSY:
1447 1.1 cgd if(xs->retries-- )
1448 1.1 cgd {
1449 1.1 cgd xs->flags &= ~ITSDONE;
1450 1.1 cgd goto retry;
1451 1.1 cgd }
1452 1.1 cgd retval = EIO;
1453 1.1 cgd break;
1454 1.1 cgd default:
1455 1.1 cgd retval = EIO;
1456 1.1 cgd printf("st%d: unknown error category from scsi driver\n"
1457 1.1 cgd ,unit);
1458 1.1 cgd break;
1459 1.1 cgd }
1460 1.1 cgd break;
1461 1.1 cgd case TRY_AGAIN_LATER:
1462 1.1 cgd if(xs->retries-- )
1463 1.1 cgd {
1464 1.1 cgd xs->flags &= ~ITSDONE;
1465 1.1 cgd goto retry;
1466 1.1 cgd }
1467 1.1 cgd retval = EIO;
1468 1.1 cgd break;
1469 1.1 cgd default:
1470 1.1 cgd retval = EIO;
1471 1.1 cgd }
1472 1.1 cgd xs->flags = 0; /* it's free! */
1473 1.1 cgd ststart(unit);
1474 1.1 cgd }
1475 1.1 cgd else
1476 1.1 cgd {
1477 1.1 cgd printf("st%d: not set up\n",unit);
1478 1.1 cgd return(EINVAL);
1479 1.1 cgd }
1480 1.1 cgd return(retval);
1481 1.1 cgd }
1482 1.1 cgd /***************************************************************\
1483 1.1 cgd * Look at the returned sense and act on the error and detirmine *
1484 1.1 cgd * The unix error number to pass back... (0 = report no error) *
1485 1.1 cgd \***************************************************************/
1486 1.1 cgd
1487 1.1 cgd int st_interpret_sense(unit,xs)
1488 1.1 cgd int unit;
1489 1.1 cgd struct scsi_xfer *xs;
1490 1.1 cgd {
1491 1.1 cgd struct scsi_sense_data *sense;
1492 1.1 cgd int key;
1493 1.1 cgd int silent = xs->flags & SCSI_SILENT;
1494 1.1 cgd
1495 1.1 cgd /***************************************************************\
1496 1.1 cgd * If errors are ok, report a success *
1497 1.1 cgd \***************************************************************/
1498 1.1 cgd if(xs->flags & SCSI_ERR_OK) return(ESUCCESS);
1499 1.1 cgd
1500 1.1 cgd /***************************************************************\
1501 1.1 cgd * Get the sense fields and work out what CLASS *
1502 1.1 cgd \***************************************************************/
1503 1.1 cgd sense = &(xs->sense);
1504 1.1 cgd if(st_debug)
1505 1.1 cgd {
1506 1.1 cgd int count = 0;
1507 1.1 cgd printf("code%x class%x valid%x\n"
1508 1.1 cgd ,sense->error_code
1509 1.1 cgd ,sense->error_class
1510 1.1 cgd ,sense->valid);
1511 1.1 cgd printf("seg%x key%x ili%x eom%x fmark%x\n"
1512 1.1 cgd ,sense->ext.extended.segment
1513 1.1 cgd ,sense->ext.extended.sense_key
1514 1.1 cgd ,sense->ext.extended.ili
1515 1.1 cgd ,sense->ext.extended.eom
1516 1.1 cgd ,sense->ext.extended.filemark);
1517 1.1 cgd printf("info: %x %x %x %x followed by %d extra bytes\n"
1518 1.1 cgd ,sense->ext.extended.info[0]
1519 1.1 cgd ,sense->ext.extended.info[1]
1520 1.1 cgd ,sense->ext.extended.info[2]
1521 1.1 cgd ,sense->ext.extended.info[3]
1522 1.1 cgd ,sense->ext.extended.extra_len);
1523 1.1 cgd printf("extra: ");
1524 1.1 cgd while(count < sense->ext.extended.extra_len)
1525 1.1 cgd {
1526 1.1 cgd printf ("%x ",sense->ext.extended.extra_bytes[count++]);
1527 1.1 cgd }
1528 1.1 cgd printf("\n");
1529 1.1 cgd }
1530 1.1 cgd switch(sense->error_class)
1531 1.1 cgd {
1532 1.1 cgd /***************************************************************\
1533 1.1 cgd * If it's class 7, use the extended stuff and interpret the key *
1534 1.1 cgd \***************************************************************/
1535 1.1 cgd case 7:
1536 1.1 cgd {
1537 1.1 cgd if(sense->ext.extended.eom)
1538 1.1 cgd {
1539 1.1 cgd st_data[unit].flags |= ST_AT_EOM;
1540 1.1 cgd }
1541 1.1 cgd
1542 1.1 cgd if(sense->ext.extended.filemark)
1543 1.1 cgd {
1544 1.1 cgd st_data[unit].flags |= ST_AT_FILEMARK;
1545 1.1 cgd }
1546 1.1 cgd
1547 1.1 cgd if(sense->ext.extended.ili)
1548 1.1 cgd {
1549 1.1 cgd if(sense->valid)
1550 1.1 cgd {
1551 1.1 cgd /*******************************\
1552 1.1 cgd * In all ili cases, note that *
1553 1.1 cgd * the resid is non-0 AND not *
1554 1.1 cgd * unchanged. *
1555 1.1 cgd \*******************************/
1556 1.1 cgd xs->resid
1557 1.1 cgd = ntohl(*((long *)sense->ext.extended.info));
1558 1.1 cgd if(xs->bp)
1559 1.1 cgd {
1560 1.1 cgd if(xs->resid < 0)
1561 1.1 cgd { /* never on block devices */
1562 1.1 cgd /***********************\
1563 1.1 cgd * it's only really bad *
1564 1.1 cgd * if we have lost data *
1565 1.1 cgd * (the record was *
1566 1.1 cgd * bigger than the read) *
1567 1.1 cgd \***********************/
1568 1.1 cgd return(EIO);
1569 1.1 cgd }
1570 1.1 cgd }
1571 1.1 cgd }
1572 1.1 cgd else
1573 1.1 cgd { /* makes no sense.. complain */
1574 1.1 cgd printf("BAD length error?");
1575 1.1 cgd }
1576 1.1 cgd }/* there may be some other error. check the rest */
1577 1.1 cgd
1578 1.1 cgd key=sense->ext.extended.sense_key;
1579 1.1 cgd switch(key)
1580 1.1 cgd {
1581 1.1 cgd case 0x0:
1582 1.1 cgd return(ESUCCESS);
1583 1.1 cgd case 0x1:
1584 1.1 cgd if(!silent)
1585 1.1 cgd {
1586 1.1 cgd printf("st%d: soft error(corrected) ", unit);
1587 1.1 cgd if(sense->valid)
1588 1.1 cgd {
1589 1.1 cgd printf("block no. %d (decimal)\n",
1590 1.1 cgd (sense->ext.extended.info[0] <<24)|
1591 1.1 cgd (sense->ext.extended.info[1] <<16)|
1592 1.1 cgd (sense->ext.extended.info[2] <<8)|
1593 1.1 cgd (sense->ext.extended.info[3] ));
1594 1.1 cgd }
1595 1.1 cgd else
1596 1.1 cgd {
1597 1.1 cgd printf("\n");
1598 1.1 cgd }
1599 1.1 cgd }
1600 1.1 cgd return(ESUCCESS);
1601 1.1 cgd case 0x2:
1602 1.1 cgd if(!silent) printf("st%d: not ready\n ", unit);
1603 1.1 cgd return(ENODEV);
1604 1.1 cgd case 0x3:
1605 1.1 cgd if(!silent)
1606 1.1 cgd {
1607 1.1 cgd printf("st%d: medium error ", unit);
1608 1.1 cgd if(sense->valid)
1609 1.1 cgd {
1610 1.1 cgd printf("block no. %d (decimal)\n",
1611 1.1 cgd (sense->ext.extended.info[0] <<24)|
1612 1.1 cgd (sense->ext.extended.info[1] <<16)|
1613 1.1 cgd (sense->ext.extended.info[2] <<8)|
1614 1.1 cgd (sense->ext.extended.info[3] ));
1615 1.1 cgd }
1616 1.1 cgd else
1617 1.1 cgd {
1618 1.1 cgd printf("\n");
1619 1.1 cgd }
1620 1.1 cgd }
1621 1.1 cgd return(EIO);
1622 1.1 cgd case 0x4:
1623 1.1 cgd if(!silent) printf("st%d: non-media hardware failure\n ",
1624 1.1 cgd unit);
1625 1.1 cgd return(EIO);
1626 1.1 cgd case 0x5:
1627 1.1 cgd if(!silent) printf("st%d: illegal request\n ", unit);
1628 1.1 cgd return(EINVAL);
1629 1.1 cgd case 0x6:
1630 1.1 cgd if(!silent) printf("st%d: Unit attention.\n ", unit);
1631 1.1 cgd st_data[unit].flags &= ~(ST_AT_FILEMARK|ST_AT_EOM);
1632 1.1 cgd st_info_valid[unit] = FALSE;
1633 1.1 cgd if (st_data[unit].flags & ST_OPEN) /* TEMP!!!! */
1634 1.1 cgd return(EIO);
1635 1.1 cgd else
1636 1.1 cgd return(ESUCCESS);
1637 1.1 cgd case 0x7:
1638 1.1 cgd if(!silent)
1639 1.1 cgd {
1640 1.1 cgd printf("st%d: attempted protection violation "
1641 1.1 cgd , unit);
1642 1.1 cgd if(sense->valid)
1643 1.1 cgd {
1644 1.1 cgd printf("block no. %d (decimal)\n",
1645 1.1 cgd (sense->ext.extended.info[0] <<24)|
1646 1.1 cgd (sense->ext.extended.info[1] <<16)|
1647 1.1 cgd (sense->ext.extended.info[2] <<8)|
1648 1.1 cgd (sense->ext.extended.info[3] ));
1649 1.1 cgd }
1650 1.1 cgd else
1651 1.1 cgd {
1652 1.1 cgd printf("\n");
1653 1.1 cgd }
1654 1.1 cgd }
1655 1.1 cgd return(EACCES);
1656 1.1 cgd case 0x8:
1657 1.1 cgd if(!silent)
1658 1.1 cgd {
1659 1.1 cgd printf("st%d: block wrong state (worm)\n "
1660 1.1 cgd , unit);
1661 1.1 cgd if(sense->valid)
1662 1.1 cgd {
1663 1.1 cgd printf("block no. %d (decimal)\n",
1664 1.1 cgd (sense->ext.extended.info[0] <<24)|
1665 1.1 cgd (sense->ext.extended.info[1] <<16)|
1666 1.1 cgd (sense->ext.extended.info[2] <<8)|
1667 1.1 cgd (sense->ext.extended.info[3] ));
1668 1.1 cgd }
1669 1.1 cgd else
1670 1.1 cgd {
1671 1.1 cgd printf("\n");
1672 1.1 cgd }
1673 1.1 cgd }
1674 1.1 cgd return(EIO);
1675 1.1 cgd case 0x9:
1676 1.1 cgd if(!silent) printf("st%d: vendor unique\n",
1677 1.1 cgd unit);
1678 1.1 cgd return(EIO);
1679 1.1 cgd case 0xa:
1680 1.1 cgd if(!silent) printf("st%d: copy aborted\n ",
1681 1.1 cgd unit);
1682 1.1 cgd return(EIO);
1683 1.1 cgd case 0xb:
1684 1.1 cgd if(!silent) printf("st%d: command aborted\n ",
1685 1.1 cgd unit);
1686 1.1 cgd return(EIO);
1687 1.1 cgd case 0xc:
1688 1.1 cgd if(!silent)
1689 1.1 cgd {
1690 1.1 cgd printf("st%d: search returned\n ", unit);
1691 1.1 cgd if(sense->valid)
1692 1.1 cgd {
1693 1.1 cgd printf("block no. %d (decimal)\n",
1694 1.1 cgd (sense->ext.extended.info[0] <<24)|
1695 1.1 cgd (sense->ext.extended.info[1] <<16)|
1696 1.1 cgd (sense->ext.extended.info[2] <<8)|
1697 1.1 cgd (sense->ext.extended.info[3] ));
1698 1.1 cgd }
1699 1.1 cgd else
1700 1.1 cgd {
1701 1.1 cgd printf("\n");
1702 1.1 cgd }
1703 1.1 cgd }
1704 1.1 cgd return(ESUCCESS);
1705 1.1 cgd case 0xd:
1706 1.1 cgd if(!silent) printf("st%d: volume overflow\n ",
1707 1.1 cgd unit);
1708 1.1 cgd return(ENOSPC);
1709 1.1 cgd case 0xe:
1710 1.1 cgd if(!silent)
1711 1.1 cgd {
1712 1.1 cgd printf("st%d: verify miscompare\n ", unit);
1713 1.1 cgd if(sense->valid)
1714 1.1 cgd {
1715 1.1 cgd printf("block no. %d (decimal)\n",
1716 1.1 cgd (sense->ext.extended.info[0] <<24)|
1717 1.1 cgd (sense->ext.extended.info[1] <<16)|
1718 1.1 cgd (sense->ext.extended.info[2] <<8)|
1719 1.1 cgd (sense->ext.extended.info[3] ));
1720 1.1 cgd }
1721 1.1 cgd else
1722 1.1 cgd {
1723 1.1 cgd printf("\n");
1724 1.1 cgd }
1725 1.1 cgd }
1726 1.1 cgd return(EIO);
1727 1.1 cgd case 0xf:
1728 1.1 cgd if(!silent) printf("st%d: unknown error key\n ",
1729 1.1 cgd unit);
1730 1.1 cgd return(EIO);
1731 1.1 cgd }
1732 1.1 cgd break;
1733 1.1 cgd }
1734 1.1 cgd /***************************************************************\
1735 1.1 cgd * If it's NOT class 7, just report it. *
1736 1.1 cgd \***************************************************************/
1737 1.1 cgd case 0:
1738 1.1 cgd case 1:
1739 1.1 cgd case 2:
1740 1.1 cgd case 3:
1741 1.1 cgd case 4:
1742 1.1 cgd case 5:
1743 1.1 cgd case 6:
1744 1.1 cgd {
1745 1.1 cgd if(!silent) printf("st%d: error class %d code %d\n",
1746 1.1 cgd unit,
1747 1.1 cgd sense->error_class,
1748 1.1 cgd sense->error_code);
1749 1.1 cgd if(sense->valid)
1750 1.1 cgd if(!silent) printf("block no. %d (decimal)\n",
1751 1.1 cgd (sense->ext.unextended.blockhi <<16),
1752 1.1 cgd + (sense->ext.unextended.blockmed <<8),
1753 1.1 cgd + (sense->ext.unextended.blocklow ));
1754 1.1 cgd }
1755 1.1 cgd return(EIO);
1756 1.1 cgd }
1757 1.1 cgd }
1758 1.1 cgd
1759 1.1 cgd #if defined(OSF)
1760 1.1 cgd
1761 1.1 cgd stsize(dev_t dev)
1762 1.1 cgd {
1763 1.1 cgd printf("stsize() -- not implemented\n");
1764 1.1 cgd return(0);
1765 1.1 cgd }
1766 1.1 cgd
1767 1.1 cgd stdump()
1768 1.1 cgd {
1769 1.1 cgd printf("stdump() -- not implemented\n");
1770 1.1 cgd return(-1);
1771 1.1 cgd }
1772 1.1 cgd
1773 1.1 cgd #endif /* defined(OSF) */
1774 1.1 cgd
1775