Print this page
6621014 Support multipathing to tape devices
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/io/scsi/targets/st.c
+++ new/usr/src/uts/common/io/scsi/targets/st.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "@(#)st.c 1.275 08/02/26 SMI"
27 +#pragma ident "@(#)st.c 1.276 08/03/03 SMI"
28 28
29 29 /*
30 30 * SCSI SCSA-compliant and not-so-DDI-compliant Tape Driver
31 31 */
32 32
33 33 #if defined(lint) && !defined(DEBUG)
34 34 #define DEBUG 1
35 35 #endif
36 36
37 37 #include <sys/modctl.h>
38 38 #include <sys/scsi/scsi.h>
39 39 #include <sys/mtio.h>
40 40 #include <sys/scsi/targets/stdef.h>
41 41 #include <sys/file.h>
42 42 #include <sys/kstat.h>
43 43 #include <sys/ddidmareq.h>
44 44 #include <sys/ddi.h>
45 45 #include <sys/sunddi.h>
46 46 #include <sys/byteorder.h>
47 47
48 48 #define IOSP KSTAT_IO_PTR(un->un_stats)
49 49 /*
50 50 * stats maintained only for reads/writes as commands
51 51 * like rewind etc skew the wait/busy times
52 52 */
53 53 #define IS_RW(bp) ((bp)->b_bcount > 0)
54 54 #define ST_DO_KSTATS(bp, kstat_function) \
55 55 if ((bp != un->un_sbufp) && un->un_stats && IS_RW(bp)) { \
56 56 kstat_function(IOSP); \
57 57 }
58 58
59 59 #define ST_DO_ERRSTATS(un, x) \
60 60 if (un->un_errstats) { \
61 61 struct st_errstats *stp; \
62 62 stp = (struct st_errstats *)un->un_errstats->ks_data; \
63 63 stp->x.value.ul++; \
64 64 }
65 65
66 66 #define FILL_SCSI1_LUN(devp, pkt) \
67 67 if ((devp)->sd_inq->inq_ansi == 0x1) { \
68 68 int _lun; \
69 69 _lun = ddi_prop_get_int(DDI_DEV_T_ANY, (devp)->sd_dev, \
70 70 DDI_PROP_DONTPASS, SCSI_ADDR_PROP_LUN, 0); \
71 71 if (_lun > 0) { \
72 72 ((union scsi_cdb *)(pkt)->pkt_cdbp)->scc_lun = \
73 73 _lun; \
74 74 } \
75 75 }
76 76
77 77 /*
78 78 * get an available contig mem header, cp.
79 79 * when big_enough is true, we will return NULL, if no big enough
80 80 * contig mem is found.
81 81 * when big_enough is false, we will try to find cp containing big
82 82 * enough contig mem. if not found, we will ruturn the last cp available.
83 83 *
84 84 * used by st_get_contig_mem()
85 85 */
86 86 #define ST_GET_CONTIG_MEM_HEAD(un, cp, len, big_enough) { \
87 87 struct contig_mem *tmp_cp = NULL; \
88 88 for ((cp) = (un)->un_contig_mem; \
89 89 (cp) != NULL; \
90 90 tmp_cp = (cp), (cp) = (cp)->cm_next) { \
91 91 if (((cp)->cm_len >= (len)) || \
92 92 (!(big_enough) && ((cp)->cm_next == NULL))) { \
93 93 if (tmp_cp == NULL) { \
94 94 (un)->un_contig_mem = (cp)->cm_next; \
95 95 } else { \
96 96 tmp_cp->cm_next = (cp)->cm_next; \
97 97 } \
98 98 (cp)->cm_next = NULL; \
99 99 (un)->un_contig_mem_available_num--; \
100 100 break; \
101 101 } \
102 102 } \
103 103 }
104 104
105 105 #define ST_NUM_MEMBERS(array) (sizeof (array) / sizeof (array[0]))
106 106 #define COPY_POS(dest, source) bcopy(source, dest, sizeof (tapepos_t))
107 107 #define ISALNUM(byte) \
108 108 (((byte) >= 'a' && (byte) <= 'z') || \
109 109 ((byte) >= 'A' && (byte) <= 'Z') || \
110 110 ((byte) >= '0' && (byte) <= '9'))
111 111
112 112 #define ONE_K 1024
113 113
114 114 /*
115 115 * Global External Data Definitions
116 116 */
117 117 extern struct scsi_key_strings scsi_cmds[];
118 118 extern uchar_t scsi_cdb_size[];
119 119
120 120 /*
121 121 * Local Static Data
122 122 */
123 123 static void *st_state;
124 124 static char *const st_label = "st";
125 125 static volatile dev_info_t *st_lastdev;
126 126 static volatile int st_recov_sz = sizeof (recov_info);
127 127
128 128 #ifdef __x86
129 129 /*
130 130 * We need to use below DMA attr to alloc physically contiguous
131 131 * memory to do I/O in big block size
132 132 */
133 133 static ddi_dma_attr_t st_contig_mem_dma_attr = {
134 134 DMA_ATTR_V0, /* version number */
135 135 0x0, /* lowest usable address */
136 136 0xFFFFFFFFull, /* high DMA address range */
137 137 0xFFFFFFFFull, /* DMA counter register */
138 138 1, /* DMA address alignment */
139 139 1, /* DMA burstsizes */
140 140 1, /* min effective DMA size */
141 141 0xFFFFFFFFull, /* max DMA xfer size */
142 142 0xFFFFFFFFull, /* segment boundary */
143 143 1, /* s/g list length */
144 144 1, /* granularity of device */
145 145 0 /* DMA transfer flags */
146 146 };
147 147
148 148 static ddi_device_acc_attr_t st_acc_attr = {
149 149 DDI_DEVICE_ATTR_V0,
150 150 DDI_NEVERSWAP_ACC,
151 151 DDI_STRICTORDER_ACC
152 152 };
153 153
154 154 /* set limitation for the number of contig_mem */
155 155 static int st_max_contig_mem_num = ST_MAX_CONTIG_MEM_NUM;
156 156 #endif
157 157
158 158 /*
159 159 * Tunable parameters
160 160 *
161 161 * DISCLAIMER
162 162 * ----------
163 163 * These parameters are intended for use only in system testing; if you use
164 164 * them in production systems, you do so at your own risk. Altering any
165 165 * variable not listed below may cause unpredictable system behavior.
166 166 *
167 167 * st_check_media_time
168 168 *
169 169 * Three second state check
170 170 *
171 171 * st_allow_large_xfer
172 172 *
173 173 * Gated with ST_NO_RECSIZE_LIMIT
174 174 *
175 175 * 0 - Transfers larger than 64KB will not be allowed
176 176 * regardless of the setting of ST_NO_RECSIZE_LIMIT
177 177 * 1 - Transfers larger than 64KB will be allowed
178 178 * if ST_NO_RECSIZE_LIMIT is TRUE for the drive
179 179 *
180 180 * st_report_soft_errors_on_close
181 181 *
182 182 * Gated with ST_SOFT_ERROR_REPORTING
183 183 *
184 184 * 0 - Errors will not be reported on close regardless
185 185 * of the setting of ST_SOFT_ERROR_REPORTING
186 186 *
187 187 * 1 - Errors will be reported on close if
188 188 * ST_SOFT_ERROR_REPORTING is TRUE for the drive
189 189 */
190 190 static int st_selection_retry_count = ST_SEL_RETRY_COUNT;
191 191 static int st_retry_count = ST_RETRY_COUNT;
192 192
193 193 static int st_io_time = ST_IO_TIME;
194 194 static int st_long_timeout_x = ST_LONG_TIMEOUT_X;
195 195
196 196 static int st_space_time = ST_SPACE_TIME;
197 197 static int st_long_space_time_x = ST_LONG_SPACE_TIME_X;
198 198
199 199 static int st_error_level = SCSI_ERR_RETRYABLE;
200 200 static int st_check_media_time = 3000000; /* 3 Second State Check */
201 201
202 202 static int st_max_throttle = ST_MAX_THROTTLE;
203 203
204 204 static clock_t st_wait_cmds_complete = ST_WAIT_CMDS_COMPLETE;
205 205
206 206 static int st_allow_large_xfer = 1;
207 207 static int st_report_soft_errors_on_close = 1;
208 208
209 209 /*
210 210 * End of tunable parameters list
211 211 */
212 212
213 213
214 214
215 215 /*
216 216 * Asynchronous I/O and persistent errors, refer to PSARC/1995/228
217 217 *
218 218 * Asynchronous I/O's main offering is that it is a non-blocking way to do
219 219 * reads and writes. The driver will queue up all the requests it gets and
220 220 * have them ready to transport to the HBA. Unfortunately, we cannot always
221 221 * just ship the I/O requests to the HBA, as there errors and exceptions
222 222 * that may happen when we don't want the HBA to continue. Therein comes
223 223 * the flush-on-errors capability. If the HBA supports it, then st will
224 224 * send in st_max_throttle I/O requests at the same time.
225 225 *
226 226 * Persistent errors : This was also reasonably simple. In the interrupt
227 227 * routines, if there was an error or exception (FM, LEOT, media error,
228 228 * transport error), the persistent error bits are set and shuts everything
229 229 * down, but setting the throttle to zero. If we hit and exception in the
230 230 * HBA, and flush-on-errors were set, we wait for all outstanding I/O's to
231 231 * come back (with CMD_ABORTED), then flush all bp's in the wait queue with
232 232 * the appropriate error, and this will preserve order. Of course, depending
233 233 * on the exception we have to show a zero read or write before we show
234 234 * errors back to the application.
235 235 */
236 236
237 237 extern const int st_ndrivetypes; /* defined in st_conf.c */
238 238 extern const struct st_drivetype st_drivetypes[];
239 239 extern const char st_conf_version[];
240 240
241 241 #ifdef STDEBUG
242 242 static int st_soft_error_report_debug = 0;
243 243 volatile int st_debug = 0;
244 244 #endif
245 245
246 246 #define ST_MT02_NAME "Emulex MT02 QIC-11/24 "
247 247
248 248 static const struct vid_drivetype {
249 249 char *vid;
250 250 char type;
251 251 } st_vid_dt[] = {
252 252 {"LTO-CVE ", MT_LTO},
253 253 {"QUANTUM ", MT_ISDLT},
254 254 {"SONY ", MT_ISAIT},
255 255 {"STK ", MT_ISSTK9840}
256 256 };
257 257
258 258 static const struct driver_minor_data {
259 259 char *name;
260 260 int minor;
261 261 } st_minor_data[] = {
262 262 /*
263 263 * The top 4 entries are for the default densities,
264 264 * don't alter their position.
265 265 */
266 266 {"", 0},
267 267 {"n", MT_NOREWIND},
268 268 {"b", MT_BSD},
269 269 {"bn", MT_NOREWIND | MT_BSD},
270 270 {"l", MT_DENSITY1},
271 271 {"m", MT_DENSITY2},
272 272 {"h", MT_DENSITY3},
273 273 {"c", MT_DENSITY4},
274 274 {"u", MT_DENSITY4},
275 275 {"ln", MT_DENSITY1 | MT_NOREWIND},
276 276 {"mn", MT_DENSITY2 | MT_NOREWIND},
277 277 {"hn", MT_DENSITY3 | MT_NOREWIND},
278 278 {"cn", MT_DENSITY4 | MT_NOREWIND},
279 279 {"un", MT_DENSITY4 | MT_NOREWIND},
280 280 {"lb", MT_DENSITY1 | MT_BSD},
281 281 {"mb", MT_DENSITY2 | MT_BSD},
282 282 {"hb", MT_DENSITY3 | MT_BSD},
283 283 {"cb", MT_DENSITY4 | MT_BSD},
284 284 {"ub", MT_DENSITY4 | MT_BSD},
285 285 {"lbn", MT_DENSITY1 | MT_NOREWIND | MT_BSD},
286 286 {"mbn", MT_DENSITY2 | MT_NOREWIND | MT_BSD},
287 287 {"hbn", MT_DENSITY3 | MT_NOREWIND | MT_BSD},
288 288 {"cbn", MT_DENSITY4 | MT_NOREWIND | MT_BSD},
289 289 {"ubn", MT_DENSITY4 | MT_NOREWIND | MT_BSD}
290 290 };
291 291
292 292 /* strings used in many debug and warning messages */
293 293 static const char wr_str[] = "write";
294 294 static const char rd_str[] = "read";
295 295 static const char wrg_str[] = "writing";
296 296 static const char rdg_str[] = "reading";
297 297 static const char *space_strs[] = {
298 298 "records",
299 299 "filemarks",
300 300 "sequential filemarks",
301 301 "eod",
302 302 "setmarks",
303 303 "sequential setmarks",
304 304 "Reserved",
305 305 "Reserved"
306 306 };
307 307 static const char *load_strs[] = {
308 308 "unload", /* LD_UNLOAD 0 */
309 309 "load", /* LD_LOAD 1 */
310 310 "retension", /* LD_RETEN 2 */
311 311 "load reten", /* LD_LOAD | LD_RETEN 3 */
312 312 "eod", /* LD_EOT 4 */
313 313 "load EOD", /* LD_LOAD | LD_EOT 5 */
314 314 "reten EOD", /* LD_RETEN | LD_EOT 6 */
315 315 "load reten EOD" /* LD_LOAD|LD_RETEN|LD_EOT 7 */
316 316 "hold", /* LD_HOLD 8 */
317 317 "load and hold" /* LD_LOAD | LD_HOLD 9 */
318 318 };
319 319
320 320 const char *bogusID = "Unknown Media ID";
321 321
322 322 /* default density offsets in the table above */
323 323 #define DEF_BLANK 0
324 324 #define DEF_NOREWIND 1
325 325 #define DEF_BSD 2
326 326 #define DEF_BSD_NR 3
327 327
328 328 /* Sense Key, ASC/ASCQ for which tape ejection is needed */
329 329
330 330 static struct tape_failure_code {
331 331 uchar_t key;
332 332 uchar_t add_code;
333 333 uchar_t qual_code;
334 334 } st_tape_failure_code[] = {
335 335 { KEY_HARDWARE_ERROR, 0x15, 0x01},
336 336 { KEY_HARDWARE_ERROR, 0x44, 0x00},
337 337 { KEY_HARDWARE_ERROR, 0x53, 0x00},
338 338 { KEY_HARDWARE_ERROR, 0x53, 0x01},
339 339 { KEY_NOT_READY, 0x53, 0x00},
340 340 { 0xff}
341 341 };
342 342
343 343 /* clean bit position and mask */
344 344
345 345 static struct cln_bit_position {
346 346 ushort_t cln_bit_byte;
347 347 uchar_t cln_bit_mask;
348 348 } st_cln_bit_position[] = {
349 349 { 21, 0x08},
350 350 { 70, 0xc0},
351 351 { 18, 0x81} /* 80 bit indicates in bit mode, 1 bit clean light is on */
352 352 };
353 353
354 354 /*
355 355 * architecture dependent allocation restrictions. For x86, we'll set
356 356 * dma_attr_addr_hi to st_max_phys_addr and dma_attr_sgllen to
357 357 * st_sgl_size during _init().
358 358 */
359 359 #if defined(__sparc)
360 360 static ddi_dma_attr_t st_alloc_attr = {
361 361 DMA_ATTR_V0, /* version number */
362 362 0x0, /* lowest usable address */
363 363 0xFFFFFFFFull, /* high DMA address range */
364 364 0xFFFFFFFFull, /* DMA counter register */
365 365 1, /* DMA address alignment */
366 366 1, /* DMA burstsizes */
367 367 1, /* min effective DMA size */
368 368 0xFFFFFFFFull, /* max DMA xfer size */
369 369 0xFFFFFFFFull, /* segment boundary */
370 370 1, /* s/g list length */
371 371 512, /* granularity of device */
372 372 0 /* DMA transfer flags */
373 373 };
374 374 #elif defined(__x86)
375 375 static ddi_dma_attr_t st_alloc_attr = {
376 376 DMA_ATTR_V0, /* version number */
377 377 0x0, /* lowest usable address */
378 378 0x0, /* high DMA address range [set in _init()] */
379 379 0xFFFFull, /* DMA counter register */
380 380 512, /* DMA address alignment */
381 381 1, /* DMA burstsizes */
382 382 1, /* min effective DMA size */
383 383 0xFFFFFFFFull, /* max DMA xfer size */
384 384 0xFFFFFFFFull, /* segment boundary */
385 385 0, /* s/g list length */
386 386 512, /* granularity of device [set in _init()] */
387 387 0 /* DMA transfer flags */
388 388 };
389 389 uint64_t st_max_phys_addr = 0xFFFFFFFFull;
390 390 int st_sgl_size = 0xF;
391 391
392 392 #endif
393 393
394 394 /*
395 395 * Configuration Data:
396 396 *
397 397 * Device driver ops vector
398 398 */
399 399 static int st_aread(dev_t dev, struct aio_req *aio, cred_t *cred_p);
400 400 static int st_awrite(dev_t dev, struct aio_req *aio, cred_t *cred_p);
401 401 static int st_read(dev_t dev, struct uio *uio_p, cred_t *cred_p);
402 402 static int st_write(dev_t dev, struct uio *uio_p, cred_t *cred_p);
403 403 static int st_open(dev_t *devp, int flag, int otyp, cred_t *cred_p);
404 404 static int st_close(dev_t dev, int flag, int otyp, cred_t *cred_p);
405 405 static int st_strategy(struct buf *bp);
406 406 static int st_queued_strategy(buf_t *bp);
407 407 static int st_ioctl(dev_t dev, int cmd, intptr_t arg, int flag,
408 408 cred_t *cred_p, int *rval_p);
409 409 extern int nulldev(), nodev();
410 410
411 411 static struct cb_ops st_cb_ops = {
412 412 st_open, /* open */
413 413 st_close, /* close */
414 414 st_queued_strategy, /* strategy Not Block device but async checks */
415 415 nodev, /* print */
416 416 nodev, /* dump */
417 417 st_read, /* read */
418 418 st_write, /* write */
419 419 st_ioctl, /* ioctl */
420 420 nodev, /* devmap */
421 421 nodev, /* mmap */
422 422 nodev, /* segmap */
423 423 nochpoll, /* poll */
424 424 ddi_prop_op, /* cb_prop_op */
425 425 0, /* streamtab */
426 426 D_64BIT | D_MP | D_NEW | D_HOTPLUG |
427 427 D_OPEN_RETURNS_EINTR, /* cb_flag */
428 428 CB_REV, /* cb_rev */
429 429 st_aread, /* async I/O read entry point */
430 430 st_awrite /* async I/O write entry point */
431 431
432 432 };
433 433
434 434 static int st_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
435 435 void **result);
436 436 static int st_probe(dev_info_t *dev);
437 437 static int st_attach(dev_info_t *dev, ddi_attach_cmd_t cmd);
438 438 static int st_detach(dev_info_t *dev, ddi_detach_cmd_t cmd);
439 439
440 440 static struct dev_ops st_ops = {
441 441 DEVO_REV, /* devo_rev, */
442 442 0, /* refcnt */
443 443 st_info, /* info */
444 444 nulldev, /* identify */
445 445 st_probe, /* probe */
446 446 st_attach, /* attach */
447 447 st_detach, /* detach */
448 448 nodev, /* reset */
449 449 &st_cb_ops, /* driver operations */
450 450 (struct bus_ops *)0, /* bus operations */
451 451 nulldev /* power */
452 452 };
453 453
454 454 /*
455 455 * Local Function Declarations
456 456 */
457 457 static char *st_print_scsi_cmd(char cmd);
458 458 static void st_print_cdb(dev_info_t *dip, char *label, uint_t level,
459 459 char *title, char *cdb);
460 460 static void st_clean_print(dev_info_t *dev, char *label, uint_t level,
461 461 char *title, char *data, int len);
462 462 static int st_doattach(struct scsi_device *devp, int (*canwait)());
463 463 static void st_known_tape_type(struct scsi_tape *un);
464 464 static int st_get_conf_from_st_dot_conf(struct scsi_tape *, char *,
465 465 struct st_drivetype *);
466 466 static int st_get_conf_from_st_conf_dot_c(struct scsi_tape *, char *,
467 467 struct st_drivetype *);
468 468 static int st_get_conf_from_tape_drive(struct scsi_tape *, char *,
469 469 struct st_drivetype *);
470 470 static int st_get_densities_from_tape_drive(struct scsi_tape *,
471 471 struct st_drivetype *);
472 472 static int st_get_timeout_values_from_tape_drive(struct scsi_tape *,
473 473 struct st_drivetype *);
474 474 static int st_get_timeouts_value(struct scsi_tape *, uchar_t, ushort_t *,
475 475 ushort_t);
476 476 static int st_get_default_conf(struct scsi_tape *, char *,
477 477 struct st_drivetype *);
478 478 static int st_rw(dev_t dev, struct uio *uio, int flag);
479 479 static int st_arw(dev_t dev, struct aio_req *aio, int flag);
480 480 static int st_find_eod(struct scsi_tape *un);
481 481 static int st_check_density_or_wfm(dev_t dev, int wfm, int mode, int stepflag);
482 482 static int st_uscsi_cmd(struct scsi_tape *un, struct uscsi_cmd *, int flag);
483 483 static int st_mtioctop(struct scsi_tape *un, intptr_t arg, int flag);
484 484 static int st_mtiocltop(struct scsi_tape *un, intptr_t arg, int flag);
485 485 static int st_do_mtioctop(struct scsi_tape *un, struct mtlop *mtop);
486 486 static void st_start(struct scsi_tape *un);
487 487 static int st_handle_start_busy(struct scsi_tape *un, struct buf *bp,
488 488 clock_t timeout_interval, int queued);
489 489 static int st_handle_intr_busy(struct scsi_tape *un, struct buf *bp,
490 490 clock_t timeout_interval);
491 491 static int st_handle_intr_retry_lcmd(struct scsi_tape *un, struct buf *bp);
492 492 static void st_done_and_mutex_exit(struct scsi_tape *un, struct buf *bp);
493 493 static void st_init(struct scsi_tape *un);
494 494 static void st_make_cmd(struct scsi_tape *un, struct buf *bp,
495 495 int (*func)(caddr_t));
496 496 static void st_make_uscsi_cmd(struct scsi_tape *, struct uscsi_cmd *,
497 497 struct buf *bp, int (*func)(caddr_t));
498 498 static void st_intr(struct scsi_pkt *pkt);
499 499 static void st_set_state(struct scsi_tape *un, buf_t *bp);
500 500 static void st_test_append(struct buf *bp);
501 501 static int st_runout(caddr_t);
502 502 static int st_cmd(struct scsi_tape *un, int com, int64_t count, int wait);
503 503 static int st_setup_cmd(struct scsi_tape *un, buf_t *bp, int com,
504 504 int64_t count);
505 505 static int st_set_compression(struct scsi_tape *un);
506 506 static int st_write_fm(dev_t dev, int wfm);
507 507 static int st_determine_generic(struct scsi_tape *un);
508 508 static int st_determine_density(struct scsi_tape *un, int rw);
509 509 static int st_get_density(struct scsi_tape *un);
510 510 static int st_set_density(struct scsi_tape *un);
511 511 static int st_loadtape(struct scsi_tape *un);
512 512 static int st_modesense(struct scsi_tape *un);
513 513 static int st_modeselect(struct scsi_tape *un);
514 514 static errstate st_handle_incomplete(struct scsi_tape *un, struct buf *bp);
515 515 static int st_wrongtapetype(struct scsi_tape *un);
516 516 static errstate st_check_error(struct scsi_tape *un, struct scsi_pkt *pkt);
517 517 static errstate st_handle_sense(struct scsi_tape *un, struct buf *bp,
518 518 tapepos_t *);
519 519 static errstate st_handle_autosense(struct scsi_tape *un, struct buf *bp,
520 520 tapepos_t *);
521 521 static int st_get_error_entry(struct scsi_tape *un, intptr_t arg, int flag);
522 522 static void st_update_error_stack(struct scsi_tape *un, struct scsi_pkt *pkt,
523 523 struct scsi_arq_status *cmd);
524 524 static void st_empty_error_stack(struct scsi_tape *un);
525 525 static errstate st_decode_sense(struct scsi_tape *un, struct buf *bp, int amt,
526 526 struct scsi_status *, tapepos_t *);
527 527 static int st_report_soft_errors(dev_t dev, int flag);
528 528 static void st_delayed_cv_broadcast(void *arg);
529 529 static int st_check_media(dev_t dev, enum mtio_state state);
530 530 static int st_media_watch_cb(caddr_t arg, struct scsi_watch_result *resultp);
531 531 static void st_intr_restart(void *arg);
532 532 static void st_start_restart(void *arg);
533 533 static int st_gen_mode_sense(struct scsi_tape *un, ubufunc_t ubf, int page,
534 534 struct seq_mode *page_data, int page_size);
535 535 static int st_change_block_size(struct scsi_tape *un, uint32_t nblksz);
536 536 static int st_gen_mode_select(struct scsi_tape *un, ubufunc_t ubf,
537 537 struct seq_mode *page_data, int page_size);
538 538 static int st_read_block_limits(struct scsi_tape *un,
539 539 struct read_blklim *read_blk);
540 540 static int st_report_density_support(struct scsi_tape *un,
541 541 uchar_t *density_data, size_t buflen);
542 542 static int st_report_supported_operation(struct scsi_tape *un,
543 543 uchar_t *oper_data, uchar_t option_code, ushort_t service_action);
544 544 static int st_tape_init(struct scsi_tape *un);
545 545 static void st_flush(struct scsi_tape *un);
546 546 static void st_set_pe_errno(struct scsi_tape *un);
547 547 static void st_hba_unflush(struct scsi_tape *un);
548 548 static void st_turn_pe_on(struct scsi_tape *un);
549 549 static void st_turn_pe_off(struct scsi_tape *un);
550 550 static void st_set_pe_flag(struct scsi_tape *un);
551 551 static void st_clear_pe(struct scsi_tape *un);
552 552 static void st_wait_for_io(struct scsi_tape *un);
553 553 static int st_set_devconfig_page(struct scsi_tape *un, int compression_on);
554 554 static int st_set_datacomp_page(struct scsi_tape *un, int compression_on);
555 555 static int st_reserve_release(struct scsi_tape *un, int command, ubufunc_t ubf);
556 556 static int st_check_cdb_for_need_to_reserve(struct scsi_tape *un, uchar_t *cdb);
557 557 static int st_check_cmd_for_need_to_reserve(struct scsi_tape *un, uchar_t cmd,
558 558 int count);
559 559 static int st_take_ownership(struct scsi_tape *un);
560 560 static int st_check_asc_ascq(struct scsi_tape *un);
561 561 static int st_check_clean_bit(struct scsi_tape *un);
562 562 static int st_check_alert_flags(struct scsi_tape *un);
563 563 static int st_check_sequential_clean_bit(struct scsi_tape *un);
564 564 static int st_check_sense_clean_bit(struct scsi_tape *un);
565 565 static int st_clear_unit_attentions(dev_t dev_instance, int max_trys);
566 566 static void st_calculate_timeouts(struct scsi_tape *un);
567 567 static writablity st_is_drive_worm(struct scsi_tape *un);
568 568 static int st_read_attributes(struct scsi_tape *un, uint16_t attribute,
569 569 void *buf, size_t size, ubufunc_t bufunc);
570 570 static int st_get_special_inquiry(struct scsi_tape *un, uchar_t size,
571 571 caddr_t dest, uchar_t page);
572 572 static int st_update_block_pos(struct scsi_tape *un, bufunc_t bf,
573 573 int post_space);
574 574 static int st_interpret_read_pos(struct scsi_tape const *un, tapepos_t *dest,
575 575 read_p_types type, size_t data_sz, const caddr_t responce, int post_space);
576 576 static int st_get_read_pos(struct scsi_tape *un, buf_t *bp);
577 577 static int st_logical_block_locate(struct scsi_tape *un, ubufunc_t ubf,
578 578 tapepos_t *pos, uint64_t lblk, uchar_t partition);
579 579 static int st_mtfsf_ioctl(struct scsi_tape *un, int files);
580 580 static int st_mtfsr_ioctl(struct scsi_tape *un, int count);
581 581 static int st_mtbsf_ioctl(struct scsi_tape *un, int files);
582 582 static int st_mtnbsf_ioctl(struct scsi_tape *un, int count);
583 583 static int st_mtbsr_ioctl(struct scsi_tape *un, int num);
584 584 static int st_mtfsfm_ioctl(struct scsi_tape *un, int cnt);
585 585 static int st_mtbsfm_ioctl(struct scsi_tape *un, int cnt);
586 586 static int st_backward_space_files(struct scsi_tape *un, int count,
587 587 int infront);
588 588 static int st_forward_space_files(struct scsi_tape *un, int files);
589 589 static int st_scenic_route_to_begining_of_file(struct scsi_tape *un,
590 590 int32_t fileno);
591 591 static int st_space_to_begining_of_file(struct scsi_tape *un);
592 592 static int st_space_records(struct scsi_tape *un, int records);
593 593 static int st_get_media_identification(struct scsi_tape *un, ubufunc_t bufunc);
594 594 static errstate st_command_recovery(struct scsi_tape *un, struct scsi_pkt *pkt,
595 595 errstate onentry);
596 596 static void st_recover(void *arg);
597 597 static void st_recov_cb(struct scsi_pkt *pkt);
598 598 static int st_rcmd(struct scsi_tape *un, int com, int64_t count, int wait);
599 599 static int st_uscsi_rcmd(struct scsi_tape *un, struct uscsi_cmd *ucmd,
600 600 int flag);
601 601 static void st_add_recovery_info_to_pkt(struct scsi_tape *un, buf_t *bp,
602 602 struct scsi_pkt *cmd);
603 603 static int st_check_mode_for_change(struct scsi_tape *un, ubufunc_t ubf);
604 604 static int st_test_path_to_device(struct scsi_tape *un);
605 605 static int st_recovery_read_pos(struct scsi_tape *un, read_p_types type,
606 606 read_pos_data_t *raw);
607 607 static int st_recovery_get_position(struct scsi_tape *un, tapepos_t *read,
608 608 read_pos_data_t *raw);
609 609 static int st_compare_expected_position(struct scsi_tape *un, st_err_info *ei,
610 610 cmd_attribute const * cmd_att, tapepos_t *read);
611 611 static errstate st_recover_reissue_pkt(struct scsi_tape *us,
612 612 struct scsi_pkt *pkt);
613 613 static int st_transport(struct scsi_tape *un, struct scsi_pkt *pkt);
614 614 static buf_t *st_remove_from_queue(buf_t **head, buf_t **tail, buf_t *bp);
615 615 static void st_add_to_queue(buf_t **head, buf_t **tail, buf_t *end, buf_t *bp);
616 616 static int st_reset(struct scsi_tape *un, int reset_type);
617 617 static void st_reset_notification(caddr_t arg);
618 618 static const cmd_attribute *st_lookup_cmd_attribute(unsigned char cmd);
619 619
620 620 #ifdef __x86
621 621 /*
622 622 * routines for I/O in big block size
623 623 */
624 624 static void st_release_contig_mem(struct scsi_tape *un, struct contig_mem *cp);
625 625 static struct contig_mem *st_get_contig_mem(struct scsi_tape *un, size_t len,
626 626 int alloc_flags);
627 627 static int st_bigblk_xfer_done(struct buf *bp);
628 628 static struct buf *st_get_bigblk_bp(struct buf *bp);
629 629 #endif
630 630 static void st_print_position(dev_info_t *dev, char *label, uint_t level,
631 631 const char *comment, tapepos_t *pos);
632 632
633 633 /*
634 634 * error statistics create/update functions
635 635 */
636 636 static int st_create_errstats(struct scsi_tape *, int);
637 637 static int st_validate_tapemarks(struct scsi_tape *un, ubufunc_t ubf,
638 638 tapepos_t *pos);
639 639
640 640 #ifdef STDEBUG
641 641 static void st_debug_cmds(struct scsi_tape *un, int com, int count, int wait);
642 642 static char *st_dev_name(dev_t dev);
643 643 #endif /* STDEBUG */
644 644
645 645 #if !defined(lint)
646 646 _NOTE(SCHEME_PROTECTS_DATA("unique per pkt",
647 647 scsi_pkt buf uio scsi_cdb uscsi_cmd))
648 648 _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", scsi_extended_sense scsi_status))
649 649 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device))
|
↓ open down ↓ |
612 lines elided |
↑ open up ↑ |
650 650 _NOTE(DATA_READABLE_WITHOUT_LOCK(st_drivetype scsi_address))
651 651 #endif
652 652
653 653 /*
654 654 * autoconfiguration routines.
655 655 */
656 656 char _depends_on[] = "misc/scsi";
657 657
658 658 static struct modldrv modldrv = {
659 659 &mod_driverops, /* Type of module. This one is a driver */
660 - "SCSI tape Driver 1.275", /* Name of the module. */
660 + "SCSI tape Driver 1.276", /* Name of the module. */
661 661 &st_ops /* driver ops */
662 662 };
663 663
664 664 static struct modlinkage modlinkage = {
665 665 MODREV_1, &modldrv, NULL
666 666 };
667 667
668 668 /*
669 669 * Notes on Post Reset Behavior in the tape driver:
670 670 *
671 671 * When the tape drive is opened, the driver attempts to make sure that
672 672 * the tape head is positioned exactly where it was left when it was last
673 673 * closed provided the medium is not changed. If the tape drive is
674 674 * opened in O_NDELAY mode, the repositioning (if necessary for any loss
675 675 * of position due to reset) will happen when the first tape operation or
676 676 * I/O occurs. The repositioning (if required) may not be possible under
677 677 * certain situations such as when the device firmware not able to report
678 678 * the medium change in the REQUEST SENSE data because of a reset or a
679 679 * misbehaving bus not allowing the reposition to happen. In such
680 680 * extraordinary situations, where the driver fails to position the head
681 681 * at its original position, it will fail the open the first time, to
682 682 * save the applications from overwriting the data. All further attempts
683 683 * to open the tape device will result in the driver attempting to load
684 684 * the tape at BOT (beginning of tape). Also a warning message to
685 685 * indicate that further attempts to open the tape device may result in
686 686 * the tape being loaded at BOT will be printed on the console. If the
687 687 * tape device is opened in O_NDELAY mode, failure to restore the
688 688 * original tape head position, will result in the failure of the first
689 689 * tape operation or I/O, Further, the driver will invalidate its
690 690 * internal tape position which will necessitate the applications to
691 691 * validate the position by using either a tape positioning ioctl (such
692 692 * as MTREW) or closing and reopening the tape device.
693 693 *
694 694 */
695 695
696 696 int
697 697 _init(void)
698 698 {
699 699 int e;
700 700
701 701 if (((e = ddi_soft_state_init(&st_state,
702 702 sizeof (struct scsi_tape), ST_MAXUNIT)) != 0)) {
703 703 return (e);
704 704 }
705 705
706 706 if ((e = mod_install(&modlinkage)) != 0) {
707 707 ddi_soft_state_fini(&st_state);
708 708 }
709 709
710 710 #if defined(__x86)
711 711 /* set the max physical address for iob allocs on x86 */
712 712 st_alloc_attr.dma_attr_addr_hi = st_max_phys_addr;
713 713
714 714 /*
715 715 * set the sgllen for iob allocs on x86. If this is set less than
716 716 * the number of pages the buffer will take (taking into account
717 717 * alignment), it would force the allocator to try and allocate
718 718 * contiguous pages.
719 719 */
720 720 st_alloc_attr.dma_attr_sgllen = st_sgl_size;
721 721 #endif
722 722
723 723 return (e);
724 724 }
725 725
726 726 int
727 727 _fini(void)
728 728 {
729 729 int e;
730 730
731 731 if ((e = mod_remove(&modlinkage)) != 0) {
732 732 return (e);
733 733 }
734 734
735 735 ddi_soft_state_fini(&st_state);
736 736
737 737 return (e);
738 738 }
739 739
740 740 int
741 741 _info(struct modinfo *modinfop)
742 742 {
743 743 return (mod_info(&modlinkage, modinfop));
744 744 }
745 745
746 746
747 747 static int
748 748 st_probe(dev_info_t *devi)
749 749 {
750 750 int instance;
751 751 struct scsi_device *devp;
752 752 int rval;
753 753
754 754 #if !defined(__sparc)
755 755 char *tape_prop;
756 756 int tape_prop_len;
757 757 #endif
758 758
759 759 ST_ENTR(devi, st_probe);
760 760
761 761 /* If self identifying device */
762 762 if (ddi_dev_is_sid(devi) == DDI_SUCCESS) {
763 763 return (DDI_PROBE_DONTCARE);
764 764 }
765 765
766 766 #if !defined(__sparc)
767 767 /*
768 768 * Since some x86 HBAs have devnodes that look like SCSI as
769 769 * far as we can tell but aren't really SCSI (DADK, like mlx)
770 770 * we check for the presence of the "tape" property.
771 771 */
772 772 if (ddi_prop_op(DDI_DEV_T_NONE, devi, PROP_LEN_AND_VAL_ALLOC,
773 773 DDI_PROP_CANSLEEP, "tape",
774 774 (caddr_t)&tape_prop, &tape_prop_len) != DDI_PROP_SUCCESS) {
775 775 return (DDI_PROBE_FAILURE);
776 776 }
777 777 if (strncmp(tape_prop, "sctp", tape_prop_len) != 0) {
778 778 kmem_free(tape_prop, tape_prop_len);
779 779 return (DDI_PROBE_FAILURE);
780 780 }
781 781 kmem_free(tape_prop, tape_prop_len);
782 782 #endif
783 783
784 784 devp = ddi_get_driver_private(devi);
785 785 instance = ddi_get_instance(devi);
786 786
787 787 if (ddi_get_soft_state(st_state, instance) != NULL) {
788 788 return (DDI_PROBE_PARTIAL);
789 789 }
790 790
791 791
792 792 /*
793 793 * Turn around and call probe routine to see whether
794 794 * we actually have a tape at this SCSI nexus.
795 795 */
796 796 if (scsi_probe(devp, NULL_FUNC) == SCSIPROBE_EXISTS) {
797 797
798 798 /*
799 799 * In checking the whole inq_dtype byte we are looking at both
800 800 * the Peripheral Qualifier and the Peripheral Device Type.
801 801 * For this driver we are only interested in sequential devices
802 802 * that are connected or capable if connecting to this logical
803 803 * unit.
804 804 */
805 805 if (devp->sd_inq->inq_dtype ==
806 806 (DTYPE_SEQUENTIAL | DPQ_POSSIBLE)) {
807 807 ST_DEBUG6(devi, st_label, SCSI_DEBUG,
808 808 "probe exists\n");
809 809 rval = DDI_PROBE_SUCCESS;
810 810 } else {
811 811 rval = DDI_PROBE_FAILURE;
812 812 }
813 813 } else {
814 814 ST_DEBUG6(devi, st_label, SCSI_DEBUG,
815 815 "probe failure: nothing there\n");
816 816 rval = DDI_PROBE_FAILURE;
817 817 }
818 818 scsi_unprobe(devp);
819 819 return (rval);
820 820 }
821 821
822 822 static int
823 823 st_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
824 824 {
825 825 int instance;
826 826 int wide;
827 827 int dev_instance;
828 828 int ret_status;
829 829 struct scsi_device *devp;
830 830 int node_ix;
831 831 struct scsi_tape *un;
832 832
833 833 ST_ENTR(devi, st_attach);
834 834
835 835 devp = ddi_get_driver_private(devi);
836 836 instance = ddi_get_instance(devi);
837 837
838 838 switch (cmd) {
839 839 case DDI_ATTACH:
840 840 if (ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
841 841 "tape-command-recovery-disable", 0) != 0) {
842 842 st_recov_sz = sizeof (pkt_info);
843 843 }
844 844 if (st_doattach(devp, SLEEP_FUNC) == DDI_FAILURE) {
845 845 return (DDI_FAILURE);
846 846 }
847 847 break;
848 848 case DDI_RESUME:
849 849 /*
850 850 * Suspend/Resume
851 851 *
852 852 * When the driver suspended, there might be
853 853 * outstanding cmds and therefore we need to
854 854 * reset the suspended flag and resume the scsi
855 855 * watch thread and restart commands and timeouts
856 856 */
857 857
858 858 if (!(un = ddi_get_soft_state(st_state, instance))) {
859 859 return (DDI_FAILURE);
860 860 }
861 861 dev_instance = ((un->un_dev == 0) ? MTMINOR(instance) :
862 862 un->un_dev);
863 863
864 864 mutex_enter(ST_MUTEX);
865 865
866 866 un->un_throttle = un->un_max_throttle;
867 867 un->un_tids_at_suspend = 0;
868 868 un->un_pwr_mgmt = ST_PWR_NORMAL;
869 869
870 870 if (un->un_swr_token) {
871 871 scsi_watch_resume(un->un_swr_token);
872 872 }
873 873
874 874 /*
875 875 * Restart timeouts
876 876 */
877 877 if ((un->un_tids_at_suspend & ST_DELAY_TID) != 0) {
878 878 mutex_exit(ST_MUTEX);
879 879 un->un_delay_tid = timeout(
880 880 st_delayed_cv_broadcast, un,
881 881 drv_usectohz((clock_t)
882 882 MEDIA_ACCESS_DELAY));
883 883 mutex_enter(ST_MUTEX);
884 884 }
885 885
886 886 if (un->un_tids_at_suspend & ST_HIB_TID) {
887 887 mutex_exit(ST_MUTEX);
888 888 un->un_hib_tid = timeout(st_intr_restart, un,
889 889 ST_STATUS_BUSY_TIMEOUT);
890 890 mutex_enter(ST_MUTEX);
891 891 }
892 892
893 893 ret_status = st_clear_unit_attentions(dev_instance, 5);
894 894
895 895 /*
896 896 * now check if we need to restore the tape position
897 897 */
898 898 if ((un->un_suspend_pos.pmode != invalid) &&
899 899 ((un->un_suspend_pos.fileno > 0) ||
900 900 (un->un_suspend_pos.blkno > 0)) ||
901 901 (un->un_suspend_pos.lgclblkno > 0)) {
902 902 if (ret_status != 0) {
903 903 /*
904 904 * tape didn't get good TUR
905 905 * just print out error messages
906 906 */
907 907 scsi_log(ST_DEVINFO, st_label, CE_WARN,
908 908 "st_attach-RESUME: tape failure "
909 909 " tape position will be lost");
910 910 } else {
911 911 /* this prints errors */
912 912 (void) st_validate_tapemarks(un,
913 913 st_uscsi_cmd, &un->un_suspend_pos);
914 914 }
915 915 /*
916 916 * there are no retries, if there is an error
917 917 * we don't know if the tape has changed
918 918 */
919 919 un->un_suspend_pos.pmode = invalid;
920 920 }
921 921
922 922 /* now we are ready to start up any queued I/Os */
923 923 if (un->un_ncmds || un->un_quef) {
924 924 st_start(un);
925 925 }
926 926
927 927 cv_broadcast(&un->un_suspend_cv);
928 928 mutex_exit(ST_MUTEX);
929 929 return (DDI_SUCCESS);
930 930
931 931 default:
932 932 return (DDI_FAILURE);
933 933 }
934 934
935 935 un = ddi_get_soft_state(st_state, instance);
936 936
937 937 ST_DEBUG(devi, st_label, SCSI_DEBUG,
938 938 "st_attach: instance=%x\n", instance);
939 939
940 940 /*
941 941 * Add a zero-length attribute to tell the world we support
942 942 * kernel ioctls (for layered drivers)
943 943 */
944 944 (void) ddi_prop_create(DDI_DEV_T_NONE, devi, DDI_PROP_CANSLEEP,
945 945 DDI_KERNEL_IOCTL, NULL, 0);
946 946
947 947 ddi_report_dev((dev_info_t *)devi);
948 948
949 949 /*
950 950 * If it's a SCSI-2 tape drive which supports wide,
951 951 * tell the host adapter to use wide.
952 952 */
953 953 wide = ((devp->sd_inq->inq_rdf == RDF_SCSI2) &&
954 954 (devp->sd_inq->inq_wbus16 || devp->sd_inq->inq_wbus32)) ? 1 : 0;
955 955
956 956 if (scsi_ifsetcap(ROUTE, "wide-xfer", wide, 1) == 1) {
957 957 ST_DEBUG(devi, st_label, SCSI_DEBUG,
958 958 "Wide Transfer %s\n", wide ? "enabled" : "disabled");
959 959 }
960 960
961 961 /*
962 962 * enable autorequest sense; keep the rq packet around in case
963 963 * the autorequest sense fails because of a busy condition
964 964 * do a getcap first in case the capability is not variable
965 965 */
966 966 if (scsi_ifgetcap(ROUTE, "auto-rqsense", 1) == 1) {
967 967 un->un_arq_enabled = 1;
968 968 } else {
969 969 un->un_arq_enabled =
970 970 ((scsi_ifsetcap(ROUTE, "auto-rqsense", 1, 1) == 1) ? 1 : 0);
971 971 }
972 972
973 973 ST_DEBUG(devi, st_label, SCSI_DEBUG, "auto request sense %s\n",
974 974 (un->un_arq_enabled ? "enabled" : "disabled"));
975 975
976 976 un->un_untagged_qing =
977 977 (scsi_ifgetcap(ROUTE, "untagged-qing", 0) == 1);
978 978
979 979 /*
980 980 * XXX - This is just for 2.6. to tell users that write buffering
981 981 * has gone away.
982 982 */
983 983 if (un->un_arq_enabled && un->un_untagged_qing) {
984 984 if (ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
985 985 "tape-driver-buffering", 0) != 0) {
986 986 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
987 987 "Write Data Buffering has been depricated. Your "
988 988 "applications should continue to work normally.\n"
989 989 " But, they should ported to use Asynchronous "
990 990 " I/O\n"
991 991 " For more information, read about "
992 992 " tape-driver-buffering "
993 993 "property in the st(7d) man page\n");
994 994 }
995 995 }
996 996
997 997 un->un_max_throttle = un->un_throttle = un->un_last_throttle = 1;
998 998 un->un_flush_on_errors = 0;
999 999 un->un_mkr_pkt = (struct scsi_pkt *)NULL;
1000 1000
1001 1001 ST_DEBUG(devi, st_label, SCSI_DEBUG,
1002 1002 "throttle=%x, max_throttle = %x\n",
1003 1003 un->un_throttle, un->un_max_throttle);
1004 1004
1005 1005 /* initialize persistent errors to nil */
1006 1006 un->un_persistence = 0;
1007 1007 un->un_persist_errors = 0;
1008 1008
1009 1009 /*
1010 1010 * Get dma-max from HBA driver. If it is not defined, use 64k
1011 1011 */
1012 1012 un->un_maxdma = scsi_ifgetcap(&devp->sd_address, "dma-max", 1);
1013 1013 if (un->un_maxdma == -1) {
1014 1014 ST_DEBUG(devi, st_label, SCSI_DEBUG,
1015 1015 "Received a value that looked like -1. Using 64k maxdma");
1016 1016 un->un_maxdma = (64 * ONE_K);
1017 1017 }
1018 1018
1019 1019 #ifdef __x86
1020 1020 /*
1021 1021 * for x86, the device may be able to DMA more than the system will
1022 1022 * allow under some circumstances. We need account for both the HBA's
1023 1023 * and system's contraints.
1024 1024 *
1025 1025 * Get the maximum DMA under worse case conditions. e.g. looking at the
1026 1026 * device constraints, the max copy buffer size, and the worse case
1027 1027 * fragmentation. NOTE: this may differ from dma-max since dma-max
1028 1028 * doesn't take the worse case framentation into account.
1029 1029 *
1030 1030 * e.g. a device may be able to DMA 16MBytes, but can only DMA 1MByte
1031 1031 * if none of the pages are contiguous. Keeping track of both of these
1032 1032 * values allows us to support larger tape block sizes on some devices.
1033 1033 */
1034 1034 un->un_maxdma_arch = scsi_ifgetcap(&devp->sd_address, "dma-max-arch",
1035 1035 1);
1036 1036
1037 1037 /*
1038 1038 * If the dma-max-arch capability is not implemented, or the value
1039 1039 * comes back higher than what was reported in dma-max, use dma-max.
1040 1040 */
1041 1041 if ((un->un_maxdma_arch == -1) ||
1042 1042 ((uint_t)un->un_maxdma < (uint_t)un->un_maxdma_arch)) {
1043 1043 un->un_maxdma_arch = un->un_maxdma;
1044 1044 }
1045 1045 #endif
1046 1046
1047 1047 /*
|
↓ open down ↓ |
377 lines elided |
↑ open up ↑ |
1048 1048 * Get the max allowable cdb size
1049 1049 */
1050 1050 un->un_max_cdb_sz =
1051 1051 scsi_ifgetcap(&devp->sd_address, "max-cdb-length", 1);
1052 1052 if (un->un_max_cdb_sz < CDB_GROUP0) {
1053 1053 ST_DEBUG(devi, st_label, SCSI_DEBUG,
1054 1054 "HBA reported max-cdb-length as %d\n", un->un_max_cdb_sz);
1055 1055 un->un_max_cdb_sz = CDB_GROUP4; /* optimistic default */
1056 1056 }
1057 1057
1058 + if (strcmp(ddi_driver_name(ddi_get_parent(ST_DEVINFO)), "scsi_vhci")) {
1059 + un->un_multipath = 0;
1060 + } else {
1061 + un->un_multipath = 1;
1062 + }
1063 +
1058 1064 un->un_maxbsize = MAXBSIZE_UNKNOWN;
1059 1065
1060 1066 un->un_mediastate = MTIO_NONE;
1061 1067 un->un_HeadClean = TAPE_ALERT_SUPPORT_UNKNOWN;
1062 1068
1063 1069 /*
1064 1070 * initialize kstats
1065 1071 */
1066 1072 un->un_stats = kstat_create("st", instance, NULL, "tape",
1067 1073 KSTAT_TYPE_IO, 1, KSTAT_FLAG_PERSISTENT);
1068 1074 if (un->un_stats) {
1069 1075 un->un_stats->ks_lock = ST_MUTEX;
1070 1076 kstat_install(un->un_stats);
1071 1077 }
1072 1078 (void) st_create_errstats(un, instance);
1073 1079
1074 1080 /*
1075 1081 * find the drive type for this target
1076 1082 */
1077 1083 mutex_enter(ST_MUTEX);
1078 1084 un->un_dev = MT_TEM_DEV(instance);
1079 1085 st_known_tape_type(un);
1080 1086 un->un_dev = 0;
1081 1087 mutex_exit(ST_MUTEX);
1082 1088
1083 1089 for (node_ix = 0; node_ix < ST_NUM_MEMBERS(st_minor_data); node_ix++) {
1084 1090 int minor;
1085 1091 char *name;
1086 1092
1087 1093 name = st_minor_data[node_ix].name;
1088 1094 minor = st_minor_data[node_ix].minor;
1089 1095
1090 1096 /*
1091 1097 * For default devices set the density to the
1092 1098 * preferred default density for this device.
1093 1099 */
1094 1100 if (node_ix <= DEF_BSD_NR) {
1095 1101 minor |= un->un_dp->default_density;
1096 1102 }
1097 1103 minor |= MTMINOR(instance);
1098 1104
1099 1105 if (ddi_create_minor_node(devi, name, S_IFCHR, minor,
1100 1106 DDI_NT_TAPE, NULL) == DDI_SUCCESS) {
1101 1107 continue;
1102 1108 }
1103 1109
1104 1110 ddi_remove_minor_node(devi, NULL);
1105 1111
1106 1112 (void) scsi_reset_notify(ROUTE, SCSI_RESET_CANCEL,
1107 1113 st_reset_notification, (caddr_t)un);
1108 1114 cv_destroy(&un->un_clscv);
1109 1115 cv_destroy(&un->un_sbuf_cv);
1110 1116 cv_destroy(&un->un_queue_cv);
1111 1117 cv_destroy(&un->un_state_cv);
1112 1118 #ifdef __x86
1113 1119 cv_destroy(&un->un_contig_mem_cv);
1114 1120 #endif
1115 1121 cv_destroy(&un->un_suspend_cv);
1116 1122 cv_destroy(&un->un_tape_busy_cv);
1117 1123 cv_destroy(&un->un_recov_buf_cv);
1118 1124 if (un->un_recov_taskq) {
1119 1125 ddi_taskq_destroy(un->un_recov_taskq);
1120 1126 }
1121 1127 if (un->un_sbufp) {
1122 1128 freerbuf(un->un_sbufp);
1123 1129 }
1124 1130 if (un->un_recov_buf) {
1125 1131 freerbuf(un->un_recov_buf);
1126 1132 }
1127 1133 if (un->un_uscsi_rqs_buf) {
1128 1134 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1129 1135 }
1130 1136 if (un->un_mspl) {
1131 1137 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1132 1138 }
1133 1139 if (un->un_dp_size) {
1134 1140 kmem_free(un->un_dp, un->un_dp_size);
1135 1141 }
1136 1142 if (un->un_state) {
1137 1143 kstat_delete(un->un_stats);
1138 1144 }
1139 1145 if (un->un_errstats) {
1140 1146 kstat_delete(un->un_errstats);
1141 1147 }
1142 1148
1143 1149 scsi_destroy_pkt(un->un_rqs);
1144 1150 scsi_free_consistent_buf(un->un_rqs_bp);
1145 1151 ddi_soft_state_free(st_state, instance);
1146 1152 devp->sd_private = NULL;
1147 1153 devp->sd_sense = NULL;
1148 1154
1149 1155 ddi_prop_remove_all(devi);
1150 1156 return (DDI_FAILURE);
1151 1157 }
1152 1158
1153 1159 return (DDI_SUCCESS);
1154 1160 }
1155 1161
1156 1162 /*
1157 1163 * st_detach:
1158 1164 *
1159 1165 * we allow a detach if and only if:
1160 1166 * - no tape is currently inserted
1161 1167 * - tape position is at BOT or unknown
1162 1168 * (if it is not at BOT then a no rewind
1163 1169 * device was opened and we have to preserve state)
1164 1170 * - it must be in a closed state : no timeouts or scsi_watch requests
1165 1171 * will exist if it is closed, so we don't need to check for
1166 1172 * them here.
1167 1173 */
1168 1174 /*ARGSUSED*/
1169 1175 static int
1170 1176 st_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
1171 1177 {
1172 1178 int instance;
1173 1179 struct scsi_device *devp;
1174 1180 struct scsi_tape *un;
1175 1181 clock_t wait_cmds_complete;
1176 1182
1177 1183 ST_ENTR(devi, st_detach);
1178 1184
1179 1185 instance = ddi_get_instance(devi);
1180 1186
1181 1187 if (!(un = ddi_get_soft_state(st_state, instance))) {
1182 1188 return (DDI_FAILURE);
1183 1189 }
1184 1190
1185 1191 mutex_enter(ST_MUTEX);
1186 1192
1187 1193 /*
1188 1194 * Clear error entry stack
1189 1195 */
1190 1196 st_empty_error_stack(un);
1191 1197
1192 1198 mutex_exit(ST_MUTEX);
1193 1199
1194 1200 switch (cmd) {
1195 1201
1196 1202 case DDI_DETACH:
1197 1203 /*
1198 1204 * Undo what we did in st_attach & st_doattach,
1199 1205 * freeing resources and removing things we installed.
1200 1206 * The system framework guarantees we are not active
1201 1207 * with this devinfo node in any other entry points at
1202 1208 * this time.
1203 1209 */
1204 1210
1205 1211 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
1206 1212 "st_detach: instance=%x, un=%p\n", instance,
1207 1213 (void *)un);
1208 1214
|
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
1209 1215 if (((un->un_dp->options & ST_UNLOADABLE) == 0) ||
1210 1216 (un->un_ncmds != 0) || (un->un_quef != NULL) ||
1211 1217 (un->un_state != ST_STATE_CLOSED)) {
1212 1218 /*
1213 1219 * we cannot unload some targets because the
1214 1220 * inquiry returns junk unless immediately
1215 1221 * after a reset
1216 1222 */
1217 1223 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
1218 1224 "cannot unload instance %x\n", instance);
1225 + un->un_unit_attention_flags |= 4;
1219 1226 return (DDI_FAILURE);
1220 1227 }
1221 1228
1222 1229 /*
1223 1230 * if the tape has been removed then we may unload;
1224 1231 * do a test unit ready and if it returns NOT READY
1225 1232 * then we assume that it is safe to unload.
1226 1233 * as a side effect, pmode may be set to invalid if the
1227 1234 * the test unit ready fails;
1228 1235 * also un_state may be set to non-closed, so reset it
1229 1236 */
1230 1237 if ((un->un_dev) && /* Been opened since attach */
1231 1238 ((un->un_pos.pmode == legacy) &&
1232 1239 (un->un_pos.fileno > 0) || /* Known position not rewound */
1233 1240 (un->un_pos.blkno != 0)) || /* Or within first file */
1234 1241 ((un->un_pos.pmode == logical) &&
1235 1242 (un->un_pos.lgclblkno > 0))) {
1236 1243 mutex_enter(ST_MUTEX);
1237 1244 /*
1238 1245 * Send Test Unit Ready in the hopes that if
1239 1246 * the drive is not in the state we think it is.
1240 1247 * And the state will be changed so it can be detached.
1241 1248 * If the command fails to reach the device and
1242 1249 * the drive was not rewound or unloaded we want
1243 1250 * to fail the detach till a user command fails
1244 1251 * where after the detach will succead.
1245 1252 */
1246 1253 (void) st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
1247 1254 /*
1248 1255 * After TUR un_state may be set to non-closed,
1249 1256 * so reset it back.
1250 1257 */
1251 1258 un->un_state = ST_STATE_CLOSED;
1252 1259 mutex_exit(ST_MUTEX);
1253 1260 }
1254 1261 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
1255 1262 "un_status=%x, fileno=%x, blkno=%x\n",
1256 1263 un->un_status, un->un_pos.fileno, un->un_pos.blkno);
1257 1264
1258 1265 /*
1259 1266 * check again:
1260 1267 * if we are not at BOT then it is not safe to unload
1261 1268 */
1262 1269 if ((un->un_dev) && /* Been opened since attach */
1263 1270 (((un->un_pos.pmode == legacy) &&
|
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
1264 1271 (un->un_pos.fileno > 0) || /* Known position not rewound */
1265 1272 (un->un_pos.blkno != 0)) || /* Or within first file */
1266 1273 ((un->un_pos.pmode == logical) &&
1267 1274 (un->un_pos.lgclblkno > 0)))) {
1268 1275
1269 1276 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
1270 1277 "cannot detach: pmode=%d fileno=0x%x, blkno=0x%x"
1271 1278 " lgclblkno=0x%"PRIx64"\n", un->un_pos.pmode,
1272 1279 un->un_pos.fileno, un->un_pos.blkno,
1273 1280 un->un_pos.lgclblkno);
1281 + un->un_unit_attention_flags |= 4;
1274 1282 return (DDI_FAILURE);
1275 1283 }
1276 1284
1277 1285 /*
1278 1286 * Just To make sure that we have released the
1279 1287 * tape unit .
1280 1288 */
1281 1289 if (un->un_dev && (un->un_rsvd_status & ST_RESERVE) &&
1282 1290 !DEVI_IS_DEVICE_REMOVED(devi)) {
1283 1291 mutex_enter(ST_MUTEX);
1284 1292 (void) st_reserve_release(un, ST_RELEASE, st_uscsi_cmd);
1285 1293 mutex_exit(ST_MUTEX);
1286 1294 }
1287 1295
1288 1296 /*
1289 1297 * now remove other data structures allocated in st_doattach()
1290 1298 */
1291 1299 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
1292 1300 "destroying/freeing\n");
1293 1301
1294 1302 (void) scsi_reset_notify(ROUTE, SCSI_RESET_CANCEL,
1295 1303 st_reset_notification, (caddr_t)un);
1296 1304 cv_destroy(&un->un_clscv);
1297 1305 cv_destroy(&un->un_sbuf_cv);
1298 1306 cv_destroy(&un->un_queue_cv);
1299 1307 cv_destroy(&un->un_suspend_cv);
1300 1308 cv_destroy(&un->un_tape_busy_cv);
1301 1309 cv_destroy(&un->un_recov_buf_cv);
1302 1310
1303 1311 if (un->un_recov_taskq) {
1304 1312 ddi_taskq_destroy(un->un_recov_taskq);
1305 1313 }
1306 1314
1307 1315 if (un->un_hib_tid) {
1308 1316 (void) untimeout(un->un_hib_tid);
1309 1317 un->un_hib_tid = 0;
1310 1318 }
1311 1319
1312 1320 if (un->un_delay_tid) {
1313 1321 (void) untimeout(un->un_delay_tid);
1314 1322 un->un_delay_tid = 0;
1315 1323 }
1316 1324 cv_destroy(&un->un_state_cv);
1317 1325
1318 1326 #ifdef __x86
1319 1327 cv_destroy(&un->un_contig_mem_cv);
1320 1328
1321 1329 if (un->un_contig_mem_hdl != NULL) {
1322 1330 ddi_dma_free_handle(&un->un_contig_mem_hdl);
1323 1331 }
1324 1332 #endif
1325 1333 if (un->un_sbufp) {
1326 1334 freerbuf(un->un_sbufp);
1327 1335 }
1328 1336 if (un->un_recov_buf) {
1329 1337 freerbuf(un->un_recov_buf);
1330 1338 }
1331 1339 if (un->un_uscsi_rqs_buf) {
1332 1340 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1333 1341 }
1334 1342 if (un->un_mspl) {
1335 1343 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1336 1344 }
1337 1345 if (un->un_rqs) {
1338 1346 scsi_destroy_pkt(un->un_rqs);
1339 1347 scsi_free_consistent_buf(un->un_rqs_bp);
1340 1348 }
1341 1349 if (un->un_mkr_pkt) {
1342 1350 scsi_destroy_pkt(un->un_mkr_pkt);
1343 1351 }
1344 1352 if (un->un_arq_enabled) {
1345 1353 (void) scsi_ifsetcap(ROUTE, "auto-rqsense", 0, 1);
1346 1354 }
1347 1355 if (un->un_dp_size) {
1348 1356 kmem_free(un->un_dp, un->un_dp_size);
1349 1357 }
1350 1358 if (un->un_stats) {
1351 1359 kstat_delete(un->un_stats);
1352 1360 un->un_stats = (kstat_t *)0;
1353 1361 }
1354 1362 if (un->un_errstats) {
1355 1363 kstat_delete(un->un_errstats);
1356 1364 un->un_errstats = (kstat_t *)0;
1357 1365 }
1358 1366 if (un->un_media_id_len) {
1359 1367 kmem_free(un->un_media_id, un->un_media_id_len);
1360 1368 }
1361 1369 devp = ST_SCSI_DEVP;
1362 1370 ddi_soft_state_free(st_state, instance);
1363 1371 devp->sd_private = NULL;
1364 1372 devp->sd_sense = NULL;
1365 1373 scsi_unprobe(devp);
1366 1374 ddi_prop_remove_all(devi);
1367 1375 ddi_remove_minor_node(devi, NULL);
1368 1376 ST_DEBUG(0, st_label, SCSI_DEBUG, "st_detach done\n");
1369 1377 return (DDI_SUCCESS);
1370 1378
1371 1379 case DDI_SUSPEND:
1372 1380
1373 1381 /*
1374 1382 * Suspend/Resume
1375 1383 *
1376 1384 * To process DDI_SUSPEND, we must do the following:
1377 1385 *
1378 1386 * - check ddi_removing_power to see if power will be turned
1379 1387 * off. if so, return DDI_FAILURE
1380 1388 * - check if we are already suspended,
1381 1389 * if so, return DDI_FAILURE
1382 1390 * - check if device state is CLOSED,
1383 1391 * if not, return DDI_FAILURE.
1384 1392 * - wait until outstanding operations complete
1385 1393 * - save tape state
1386 1394 * - block new operations
1387 1395 * - cancel pending timeouts
1388 1396 *
1389 1397 */
1390 1398
1391 1399 if (ddi_removing_power(devi)) {
1392 1400 return (DDI_FAILURE);
1393 1401 }
1394 1402 mutex_enter(ST_MUTEX);
1395 1403
1396 1404 /*
1397 1405 * Shouldn't already be suspended, if so return failure
1398 1406 */
1399 1407 if (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
1400 1408 mutex_exit(ST_MUTEX);
1401 1409 return (DDI_FAILURE);
1402 1410 }
1403 1411 if (un->un_state != ST_STATE_CLOSED) {
1404 1412 mutex_exit(ST_MUTEX);
1405 1413 return (DDI_FAILURE);
1406 1414 }
1407 1415
1408 1416 /*
1409 1417 * Wait for all outstanding I/O's to complete
1410 1418 *
1411 1419 * we wait on both ncmds and the wait queue for times
1412 1420 * when we are flushing after persistent errors are
1413 1421 * flagged, which is when ncmds can be 0, and the
1414 1422 * queue can still have I/O's. This way we preserve
1415 1423 * order of biodone's.
1416 1424 */
1417 1425 wait_cmds_complete = ddi_get_lbolt();
1418 1426 wait_cmds_complete +=
1419 1427 st_wait_cmds_complete * drv_usectohz(1000000);
1420 1428 while (un->un_ncmds || un->un_quef ||
1421 1429 (un->un_state == ST_STATE_RESOURCE_WAIT)) {
1422 1430
1423 1431 if (cv_timedwait(&un->un_tape_busy_cv, ST_MUTEX,
1424 1432 wait_cmds_complete) == -1) {
1425 1433 /*
1426 1434 * Time expired then cancel the command
1427 1435 */
1428 1436 if (st_reset(un, RESET_LUN) == 0) {
1429 1437 if (un->un_last_throttle) {
1430 1438 un->un_throttle =
1431 1439 un->un_last_throttle;
1432 1440 }
1433 1441 mutex_exit(ST_MUTEX);
1434 1442 return (DDI_FAILURE);
1435 1443 } else {
1436 1444 break;
1437 1445 }
1438 1446 }
1439 1447 }
1440 1448
1441 1449 /*
1442 1450 * DDI_SUSPEND says that the system "may" power down, we
1443 1451 * remember the file and block number before rewinding.
1444 1452 * we also need to save state before issuing
1445 1453 * any WRITE_FILE_MARK command.
1446 1454 */
1447 1455 (void) st_update_block_pos(un, st_cmd, 0);
1448 1456 COPY_POS(&un->un_suspend_pos, &un->un_pos);
1449 1457
1450 1458
1451 1459 /*
1452 1460 * Issue a zero write file fmk command to tell the drive to
1453 1461 * flush any buffered tape marks
1454 1462 */
1455 1463 (void) st_cmd(un, SCMD_WRITE_FILE_MARK, 0, SYNC_CMD);
1456 1464
1457 1465 /*
1458 1466 * Because not all tape drives correctly implement buffer
1459 1467 * flushing with the zero write file fmk command, issue a
1460 1468 * synchronous rewind command to force data flushing.
1461 1469 * st_validate_tapemarks() will do a rewind during DDI_RESUME
1462 1470 * anyway.
1463 1471 */
1464 1472 (void) st_cmd(un, SCMD_REWIND, 0, SYNC_CMD);
1465 1473
1466 1474 /* stop any new operations */
1467 1475 un->un_pwr_mgmt = ST_PWR_SUSPENDED;
1468 1476 un->un_throttle = 0;
1469 1477
1470 1478 /*
1471 1479 * cancel any outstanding timeouts
1472 1480 */
1473 1481 if (un->un_delay_tid) {
1474 1482 timeout_id_t temp_id = un->un_delay_tid;
1475 1483 un->un_delay_tid = 0;
1476 1484 un->un_tids_at_suspend |= ST_DELAY_TID;
1477 1485 mutex_exit(ST_MUTEX);
1478 1486 (void) untimeout(temp_id);
1479 1487 mutex_enter(ST_MUTEX);
1480 1488 }
1481 1489
1482 1490 if (un->un_hib_tid) {
1483 1491 timeout_id_t temp_id = un->un_hib_tid;
1484 1492 un->un_hib_tid = 0;
1485 1493 un->un_tids_at_suspend |= ST_HIB_TID;
1486 1494 mutex_exit(ST_MUTEX);
1487 1495 (void) untimeout(temp_id);
1488 1496 mutex_enter(ST_MUTEX);
1489 1497 }
1490 1498
1491 1499 /*
1492 1500 * Suspend the scsi_watch_thread
1493 1501 */
1494 1502 if (un->un_swr_token) {
1495 1503 opaque_t temp_token = un->un_swr_token;
1496 1504 mutex_exit(ST_MUTEX);
1497 1505 scsi_watch_suspend(temp_token);
1498 1506 } else {
1499 1507 mutex_exit(ST_MUTEX);
1500 1508 }
1501 1509
1502 1510 return (DDI_SUCCESS);
1503 1511
1504 1512 default:
1505 1513 ST_DEBUG(0, st_label, SCSI_DEBUG, "st_detach failed\n");
1506 1514 return (DDI_FAILURE);
1507 1515 }
1508 1516 }
1509 1517
1510 1518
1511 1519 /* ARGSUSED */
1512 1520 static int
1513 1521 st_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
1514 1522 {
1515 1523 dev_t dev;
1516 1524 struct scsi_tape *un;
1517 1525 int instance, error;
1518 1526
1519 1527 ST_ENTR(dip, st_info);
1520 1528
1521 1529 switch (infocmd) {
1522 1530 case DDI_INFO_DEVT2DEVINFO:
1523 1531 dev = (dev_t)arg;
1524 1532 instance = MTUNIT(dev);
1525 1533 if ((un = ddi_get_soft_state(st_state, instance)) == NULL)
1526 1534 return (DDI_FAILURE);
1527 1535 *result = (void *) ST_DEVINFO;
1528 1536 error = DDI_SUCCESS;
1529 1537 break;
1530 1538 case DDI_INFO_DEVT2INSTANCE:
1531 1539 dev = (dev_t)arg;
1532 1540 instance = MTUNIT(dev);
1533 1541 *result = (void *)(uintptr_t)instance;
1534 1542 error = DDI_SUCCESS;
1535 1543 break;
1536 1544 default:
1537 1545 error = DDI_FAILURE;
1538 1546 }
1539 1547 return (error);
1540 1548 }
1541 1549
1542 1550 static int
1543 1551 st_doattach(struct scsi_device *devp, int (*canwait)())
1544 1552 {
1545 1553 struct scsi_tape *un = NULL;
1546 1554 recov_info *ri;
1547 1555 int km_flags = (canwait != NULL_FUNC) ? KM_SLEEP : KM_NOSLEEP;
1548 1556 int instance;
1549 1557 size_t rlen;
1550 1558
1551 1559 ST_FUNC(devp->sd_dev, st_doattach);
1552 1560 /*
1553 1561 * Call the routine scsi_probe to do some of the dirty work.
1554 1562 * If the INQUIRY command succeeds, the field sd_inq in the
1555 1563 * device structure will be filled in.
1556 1564 */
1557 1565 ST_DEBUG(devp->sd_dev, st_label, SCSI_DEBUG,
1558 1566 "st_doattach(): probing\n");
1559 1567
1560 1568 if (scsi_probe(devp, canwait) == SCSIPROBE_EXISTS) {
1561 1569
1562 1570 /*
1563 1571 * In checking the whole inq_dtype byte we are looking at both
1564 1572 * the Peripheral Qualifier and the Peripheral Device Type.
1565 1573 * For this driver we are only interested in sequential devices
1566 1574 * that are connected or capable if connecting to this logical
1567 1575 * unit.
1568 1576 */
1569 1577 if (devp->sd_inq->inq_dtype ==
1570 1578 (DTYPE_SEQUENTIAL | DPQ_POSSIBLE)) {
1571 1579 ST_DEBUG(devp->sd_dev, st_label, SCSI_DEBUG,
1572 1580 "probe exists\n");
1573 1581 } else {
1574 1582 /* Something there but not a tape device */
1575 1583 scsi_unprobe(devp);
1576 1584 return (DDI_FAILURE);
1577 1585 }
1578 1586 } else {
1579 1587 /* Nothing there */
1580 1588 ST_DEBUG(devp->sd_dev, st_label, SCSI_DEBUG,
1581 1589 "probe failure: nothing there\n");
1582 1590 scsi_unprobe(devp);
1583 1591 return (DDI_FAILURE);
1584 1592 }
1585 1593
1586 1594
1587 1595 /*
1588 1596 * The actual unit is present.
1589 1597 * Now is the time to fill in the rest of our info..
1590 1598 */
1591 1599 instance = ddi_get_instance(devp->sd_dev);
1592 1600
1593 1601 if (ddi_soft_state_zalloc(st_state, instance) != DDI_SUCCESS) {
1594 1602 goto error;
1595 1603 }
1596 1604 un = ddi_get_soft_state(st_state, instance);
1597 1605
1598 1606 ASSERT(un != NULL);
1599 1607
1600 1608 un->un_rqs_bp = scsi_alloc_consistent_buf(&devp->sd_address, NULL,
1601 1609 MAX_SENSE_LENGTH, B_READ, canwait, NULL);
1602 1610 if (un->un_rqs_bp == NULL) {
1603 1611 goto error;
1604 1612 }
1605 1613 un->un_rqs = scsi_init_pkt(&devp->sd_address, NULL, un->un_rqs_bp,
1606 1614 CDB_GROUP0, 1, st_recov_sz, PKT_CONSISTENT, canwait, NULL);
1607 1615 if (!un->un_rqs) {
1608 1616 goto error;
1609 1617 }
1610 1618 ASSERT(un->un_rqs->pkt_resid == 0);
1611 1619 devp->sd_sense =
1612 1620 (struct scsi_extended_sense *)un->un_rqs_bp->b_un.b_addr;
1613 1621 ASSERT(geterror(un->un_rqs_bp) == NULL);
1614 1622
1615 1623 (void) scsi_setup_cdb((union scsi_cdb *)un->un_rqs->pkt_cdbp,
1616 1624 SCMD_REQUEST_SENSE, 0, MAX_SENSE_LENGTH, 0);
1617 1625 FILL_SCSI1_LUN(devp, un->un_rqs);
1618 1626 un->un_rqs->pkt_flags |= (FLAG_SENSING | FLAG_HEAD | FLAG_NODISCON);
1619 1627 un->un_rqs->pkt_time = st_io_time;
1620 1628 un->un_rqs->pkt_comp = st_intr;
1621 1629 ri = (recov_info *)un->un_rqs->pkt_private;
1622 1630 if (st_recov_sz == sizeof (recov_info)) {
1623 1631 ri->privatelen = sizeof (recov_info);
1624 1632 } else {
1625 1633 ri->privatelen = sizeof (pkt_info);
1626 1634 }
1627 1635
1628 1636 un->un_sbufp = getrbuf(km_flags);
1629 1637 un->un_recov_buf = getrbuf(km_flags);
1630 1638
1631 1639 un->un_uscsi_rqs_buf = kmem_alloc(SENSE_LENGTH, KM_SLEEP);
1632 1640
1633 1641 /*
1634 1642 * use i_ddi_mem_alloc() for now until we have an interface to allocate
1635 1643 * memory for DMA which doesn't require a DMA handle. ddi_iopb_alloc()
1636 1644 * is obsolete and we want more flexibility in controlling the DMA
1637 1645 * address constraints.
1638 1646 */
1639 1647 (void) i_ddi_mem_alloc(devp->sd_dev, &st_alloc_attr,
1640 1648 sizeof (struct seq_mode), ((km_flags == KM_SLEEP) ? 1 : 0), 0,
1641 1649 NULL, (caddr_t *)&un->un_mspl, &rlen, NULL);
1642 1650
1643 1651 (void) i_ddi_mem_alloc(devp->sd_dev, &st_alloc_attr,
1644 1652 sizeof (read_pos_data_t), ((km_flags == KM_SLEEP) ? 1 : 0), 0,
1645 1653 NULL, (caddr_t *)&un->un_read_pos_data, &rlen, NULL);
1646 1654
1647 1655 if (!un->un_sbufp || !un->un_mspl || !un->un_read_pos_data) {
1648 1656 ST_DEBUG6(devp->sd_dev, st_label, SCSI_DEBUG,
1649 1657 "probe partial failure: no space\n");
1650 1658 goto error;
1651 1659 }
1652 1660
1653 1661 bzero(un->un_mspl, sizeof (struct seq_mode));
1654 1662
1655 1663 cv_init(&un->un_sbuf_cv, NULL, CV_DRIVER, NULL);
1656 1664 cv_init(&un->un_queue_cv, NULL, CV_DRIVER, NULL);
1657 1665 cv_init(&un->un_clscv, NULL, CV_DRIVER, NULL);
1658 1666 cv_init(&un->un_state_cv, NULL, CV_DRIVER, NULL);
1659 1667 #ifdef __x86
1660 1668 cv_init(&un->un_contig_mem_cv, NULL, CV_DRIVER, NULL);
1661 1669 #endif
1662 1670
1663 1671 /* Initialize power managemnet condition variable */
1664 1672 cv_init(&un->un_suspend_cv, NULL, CV_DRIVER, NULL);
1665 1673 cv_init(&un->un_tape_busy_cv, NULL, CV_DRIVER, NULL);
1666 1674 cv_init(&un->un_recov_buf_cv, NULL, CV_DRIVER, NULL);
1667 1675
1668 1676 un->un_recov_taskq = ddi_taskq_create(devp->sd_dev,
1669 1677 "un_recov_taskq", 1, TASKQ_DEFAULTPRI, km_flags);
1670 1678
1671 1679 ASSERT(un->un_recov_taskq != NULL);
1672 1680
1673 1681 un->un_pos.pmode = invalid;
1674 1682 un->un_sd = devp;
1675 1683 un->un_swr_token = (opaque_t)NULL;
1676 1684 un->un_comp_page = ST_DEV_DATACOMP_PAGE | ST_DEV_CONFIG_PAGE;
1677 1685 un->un_wormable = st_is_drive_worm;
1678 1686 un->un_media_id_method = st_get_media_identification;
1679 1687 /*
1680 1688 * setting long a initial as it contains logical file info.
1681 1689 * support for long format is mandatory but many drive don't do it.
1682 1690 */
1683 1691 un->un_read_pos_type = LONG_POS;
1684 1692
1685 1693 un->un_suspend_pos.pmode = invalid;
1686 1694
1687 1695 #ifdef __x86
1688 1696 if (ddi_dma_alloc_handle(ST_DEVINFO, &st_contig_mem_dma_attr,
1689 1697 DDI_DMA_SLEEP, NULL, &un->un_contig_mem_hdl) != DDI_SUCCESS) {
1690 1698 ST_DEBUG6(devp->sd_dev, st_label, SCSI_DEBUG,
1691 1699 "allocation of contiguous memory dma handle failed!");
1692 1700 un->un_contig_mem_hdl = NULL;
1693 1701 goto error;
1694 1702 }
1695 1703 #endif
1696 1704
1697 1705 /*
1698 1706 * Since this driver manages devices with "remote" hardware,
1699 1707 * i.e. the devices themselves have no "reg" properties,
1700 1708 * the SUSPEND/RESUME commands in detach/attach will not be
1701 1709 * called by the power management framework unless we request
1702 1710 * it by creating a "pm-hardware-state" property and setting it
1703 1711 * to value "needs-suspend-resume".
1704 1712 */
1705 1713 if (ddi_prop_update_string(DDI_DEV_T_NONE, devp->sd_dev,
1706 1714 "pm-hardware-state", "needs-suspend-resume") !=
1707 1715 DDI_PROP_SUCCESS) {
1708 1716
1709 1717 ST_DEBUG(devp->sd_dev, st_label, SCSI_DEBUG,
1710 1718 "ddi_prop_update(\"pm-hardware-state\") failed\n");
1711 1719 goto error;
1712 1720 }
1713 1721
1714 1722 if (ddi_prop_create(DDI_DEV_T_NONE, devp->sd_dev, DDI_PROP_CANSLEEP,
1715 1723 "no-involuntary-power-cycles", NULL, 0) != DDI_PROP_SUCCESS) {
1716 1724
1717 1725 ST_DEBUG(devp->sd_dev, st_label, SCSI_DEBUG,
1718 1726 "ddi_prop_create(\"no-involuntary-power-cycles\") "
1719 1727 "failed\n");
1720 1728 goto error;
1721 1729 }
1722 1730
1723 1731 (void) scsi_reset_notify(ROUTE, SCSI_RESET_NOTIFY,
1724 1732 st_reset_notification, (caddr_t)un);
1725 1733
1726 1734 ST_DEBUG6(devp->sd_dev, st_label, SCSI_DEBUG, "attach success\n");
1727 1735 return (DDI_SUCCESS);
1728 1736
1729 1737 error:
1730 1738 devp->sd_sense = NULL;
1731 1739
1732 1740 ddi_remove_minor_node(devp->sd_dev, NULL);
1733 1741 if (un) {
1734 1742 if (un->un_mspl) {
1735 1743 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1736 1744 }
1737 1745 if (un->un_read_pos_data) {
1738 1746 i_ddi_mem_free((caddr_t)un->un_read_pos_data, 0);
1739 1747 }
1740 1748 if (un->un_sbufp) {
1741 1749 freerbuf(un->un_sbufp);
1742 1750 }
1743 1751 if (un->un_recov_buf) {
1744 1752 freerbuf(un->un_recov_buf);
1745 1753 }
1746 1754 if (un->un_uscsi_rqs_buf) {
1747 1755 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1748 1756 }
1749 1757 #ifdef __x86
1750 1758 if (un->un_contig_mem_hdl != NULL) {
1751 1759 ddi_dma_free_handle(&un->un_contig_mem_hdl);
1752 1760 }
1753 1761 #endif
1754 1762 if (un->un_rqs) {
1755 1763 scsi_destroy_pkt(un->un_rqs);
1756 1764 }
1757 1765
1758 1766 if (un->un_rqs_bp) {
1759 1767 scsi_free_consistent_buf(un->un_rqs_bp);
1760 1768 }
1761 1769
1762 1770 ddi_soft_state_free(st_state, instance);
1763 1771 devp->sd_private = NULL;
1764 1772 }
1765 1773
1766 1774 if (devp->sd_inq) {
1767 1775 scsi_unprobe(devp);
1768 1776 }
1769 1777 return (DDI_FAILURE);
1770 1778 }
1771 1779
1772 1780 typedef int
1773 1781 (*cfg_functp)(struct scsi_tape *, char *vidpid, struct st_drivetype *);
1774 1782
1775 1783 static cfg_functp config_functs[] = {
1776 1784 st_get_conf_from_st_dot_conf,
1777 1785 st_get_conf_from_st_conf_dot_c,
1778 1786 st_get_conf_from_tape_drive,
1779 1787 st_get_default_conf
1780 1788 };
1781 1789
1782 1790
1783 1791 /*
1784 1792 * determine tape type, using tape-config-list or built-in table or
1785 1793 * use a generic tape config entry
1786 1794 */
1787 1795 static void
1788 1796 st_known_tape_type(struct scsi_tape *un)
1789 1797 {
1790 1798 struct st_drivetype *dp;
1791 1799 cfg_functp *config_funct;
1792 1800 uchar_t reserved;
1793 1801
1794 1802 ST_FUNC(ST_DEVINFO, st_known_tape_type);
1795 1803
1796 1804 reserved = (un->un_rsvd_status & ST_RESERVE) ? ST_RESERVE
1797 1805 : ST_RELEASE;
1798 1806
1799 1807 /*
1800 1808 * XXX: Emulex MT-02 (and emulators) predates SCSI-1 and has
1801 1809 * no vid & pid inquiry data. So, we provide one.
1802 1810 */
1803 1811 if (ST_INQUIRY->inq_len == 0 ||
1804 1812 (bcmp("\0\0\0\0\0\0\0\0", ST_INQUIRY->inq_vid, 8) == 0)) {
1805 1813 (void) strcpy((char *)ST_INQUIRY->inq_vid, ST_MT02_NAME);
1806 1814 }
1807 1815
1808 1816 if (un->un_dp_size == 0) {
1809 1817 un->un_dp_size = sizeof (struct st_drivetype);
1810 1818 dp = kmem_zalloc((size_t)un->un_dp_size, KM_SLEEP);
1811 1819 un->un_dp = dp;
1812 1820 } else {
1813 1821 dp = un->un_dp;
1814 1822 }
1815 1823
1816 1824 un->un_dp->non_motion_timeout = st_io_time;
1817 1825 /*
1818 1826 * Loop through the configuration methods till one works.
1819 1827 */
1820 1828 for (config_funct = &config_functs[0]; ; config_funct++) {
1821 1829 if ((*config_funct)(un, ST_INQUIRY->inq_vid, dp)) {
1822 1830 break;
1823 1831 }
1824 1832 }
1825 1833
1826 1834 /*
1827 1835 * If we didn't just make up this configuration and
1828 1836 * all the density codes are the same..
1829 1837 * Set Auto Density over ride.
1830 1838 */
1831 1839 if (*config_funct != st_get_default_conf) {
1832 1840 /*
1833 1841 * If this device is one that is configured and all
1834 1842 * densities are the same, This saves doing gets and set
1835 1843 * that yield nothing.
1836 1844 */
1837 1845 if ((dp->densities[0]) == (dp->densities[1]) &&
1838 1846 (dp->densities[0]) == (dp->densities[2]) &&
1839 1847 (dp->densities[0]) == (dp->densities[3])) {
1840 1848
1841 1849 dp->options |= ST_AUTODEN_OVERRIDE;
1842 1850 }
1843 1851 }
1844 1852
1845 1853
1846 1854 /*
1847 1855 * Store tape drive characteristics.
1848 1856 */
1849 1857 un->un_status = 0;
1850 1858 un->un_attached = 1;
1851 1859 un->un_init_options = dp->options;
1852 1860
1853 1861 /* setup operation time-outs based on options */
1854 1862 st_calculate_timeouts(un);
1855 1863
|
↓ open down ↓ |
572 lines elided |
↑ open up ↑ |
1856 1864 /* make sure if we are supposed to be variable, make it variable */
1857 1865 if (dp->options & ST_VARIABLE) {
1858 1866 dp->bsize = 0;
1859 1867 }
1860 1868
1861 1869 if (reserved != ((un->un_rsvd_status & ST_RESERVE) ? ST_RESERVE
1862 1870 : ST_RELEASE)) {
1863 1871 (void) st_reserve_release(un, reserved, st_uscsi_cmd);
1864 1872 }
1865 1873
1866 - un->un_unit_attention_flags = 1;
1874 + un->un_unit_attention_flags |= 1;
1867 1875
1868 1876 scsi_log(ST_DEVINFO, st_label, CE_NOTE, "?<%s>\n", dp->name);
1869 1877
1870 1878 }
1871 1879
1872 1880
1873 1881 typedef struct {
1874 1882 int mask;
1875 1883 int bottom;
1876 1884 int top;
1877 1885 char *name;
1878 1886 } conf_limit;
1879 1887
1880 1888 static const conf_limit conf_limits[] = {
1881 1889
1882 1890 -1, 1, 2, "conf version",
1883 1891 -1, MT_ISTS, ST_LAST_TYPE, "drive type",
1884 1892 -1, 0, 0xffffff, "block size",
1885 1893 ST_VALID_OPTS, 0, ST_VALID_OPTS, "options",
1886 1894 -1, 0, 4, "number of densities",
1887 1895 -1, 0, UINT8_MAX, "density code",
1888 1896 -1, 0, 3, "default density",
1889 1897 -1, 0, UINT16_MAX, "non motion timeout",
1890 1898 -1, 0, UINT16_MAX, "I/O timeout",
1891 1899 -1, 0, UINT16_MAX, "space timeout",
1892 1900 -1, 0, UINT16_MAX, "load timeout",
1893 1901 -1, 0, UINT16_MAX, "unload timeout",
1894 1902 -1, 0, UINT16_MAX, "erase timeout",
1895 1903 0, 0, 0, NULL
1896 1904 };
1897 1905
1898 1906 static int
1899 1907 st_validate_conf_data(struct scsi_tape *un, int *list, int list_len,
1900 1908 const char *conf_name)
1901 1909 {
1902 1910 int dens;
1903 1911 int ndens;
1904 1912 int value;
1905 1913 int type;
1906 1914 int count;
1907 1915 const conf_limit *limit = &conf_limits[0];
1908 1916
1909 1917 ST_FUNC(ST_DEVINFO, st_validate_conf_data);
1910 1918
1911 1919 ST_DEBUG3(ST_DEVINFO, st_label, CE_NOTE,
1912 1920 "Checking %d entrys total with %d densities\n", list_len, list[4]);
1913 1921
1914 1922 count = list_len;
1915 1923 type = *list;
1916 1924 for (; count && limit->name; count--, list++, limit++) {
1917 1925
1918 1926 value = *list;
1919 1927 if (value & ~limit->mask) {
1920 1928 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1921 1929 "%s %s value invalid bits set: 0x%X\n",
1922 1930 conf_name, limit->name, value & ~limit->mask);
1923 1931 *list &= limit->mask;
1924 1932 } else if (value < limit->bottom) {
1925 1933 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1926 1934 "%s %s value too low: value = %d limit %d\n",
1927 1935 conf_name, limit->name, value, limit->bottom);
1928 1936 } else if (value > limit->top) {
1929 1937 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1930 1938 "%s %s value too high: value = %d limit %d\n",
1931 1939 conf_name, limit->name, value, limit->top);
1932 1940 } else {
1933 1941 ST_DEBUG3(ST_DEVINFO, st_label, CE_CONT,
1934 1942 "%s %s value = 0x%X\n",
1935 1943 conf_name, limit->name, value);
1936 1944 }
1937 1945
1938 1946 /* If not the number of densities continue */
1939 1947 if (limit != &conf_limits[4]) {
1940 1948 continue;
1941 1949 }
1942 1950
1943 1951 /* If number of densities is not in range can't use config */
1944 1952 if (value < limit->bottom || value > limit->top) {
1945 1953 return (-1);
1946 1954 }
1947 1955
1948 1956 ndens = min(value, NDENSITIES);
1949 1957 if ((type == 1) && (list_len - ndens) != 6) {
1950 1958 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1951 1959 "%s conf version 1 with %d densities has %d items"
1952 1960 " should have %d",
1953 1961 conf_name, ndens, list_len, 6 + ndens);
1954 1962 } else if ((type == 2) && (list_len - ndens) != 13) {
1955 1963 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1956 1964 "%s conf version 2 with %d densities has %d items"
1957 1965 " should have %d",
1958 1966 conf_name, ndens, list_len, 13 + ndens);
1959 1967 }
1960 1968
1961 1969 limit++;
1962 1970 for (dens = 0; dens < ndens && count; dens++) {
1963 1971 count--;
1964 1972 list++;
1965 1973 value = *list;
1966 1974 if (value < limit->bottom) {
1967 1975 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1968 1976 "%s density[%d] value too low: value ="
1969 1977 " 0x%X limit 0x%X\n",
1970 1978 conf_name, dens, value, limit->bottom);
1971 1979 } else if (value > limit->top) {
1972 1980 scsi_log(ST_DEVINFO, st_label, CE_NOTE,
1973 1981 "%s density[%d] value too high: value ="
1974 1982 " 0x%X limit 0x%X\n",
1975 1983 conf_name, dens, value, limit->top);
1976 1984 } else {
1977 1985 ST_DEBUG3(ST_DEVINFO, st_label, CE_CONT,
1978 1986 "%s density[%d] value = 0x%X\n",
1979 1987 conf_name, dens, value);
1980 1988 }
1981 1989 }
1982 1990 }
1983 1991
1984 1992 return (0);
1985 1993 }
1986 1994
1987 1995 static int
1988 1996 st_get_conf_from_st_dot_conf(struct scsi_tape *un, char *vidpid,
1989 1997 struct st_drivetype *dp)
1990 1998 {
1991 1999 caddr_t config_list = NULL;
1992 2000 caddr_t data_list = NULL;
1993 2001 int *data_ptr;
1994 2002 caddr_t vidptr, prettyptr, datanameptr;
1995 2003 size_t vidlen, prettylen, datanamelen, tripletlen = 0;
1996 2004 int config_list_len, data_list_len, len, i;
1997 2005 int version;
1998 2006 int found = 0;
1999 2007
2000 2008 ST_FUNC(ST_DEVINFO, st_get_conf_from_st_dot_conf);
2001 2009
2002 2010 /*
2003 2011 * Determine type of tape controller. Type is determined by
2004 2012 * checking the vendor ids of the earlier inquiry command and
2005 2013 * comparing those with vids in tape-config-list defined in st.conf
2006 2014 */
2007 2015 if (ddi_getlongprop(DDI_DEV_T_ANY, ST_DEVINFO, DDI_PROP_DONTPASS,
2008 2016 "tape-config-list", (caddr_t)&config_list, &config_list_len)
2009 2017 != DDI_PROP_SUCCESS) {
2010 2018 return (found);
2011 2019 }
2012 2020
2013 2021 ST_DEBUG6(ST_DEVINFO, st_label, SCSI_DEBUG,
2014 2022 "st_get_conf_from_st_dot_conf(): st.conf has tape-config-list\n");
2015 2023
2016 2024 /*
2017 2025 * Compare vids in each triplet - if it matches, get value for
2018 2026 * data_name and contruct a st_drivetype struct
2019 2027 * tripletlen is not set yet!
2020 2028 */
2021 2029 for (len = config_list_len, vidptr = config_list;
2022 2030 len > 0;
2023 2031 vidptr += tripletlen, len -= tripletlen) {
2024 2032
2025 2033 vidlen = strlen(vidptr);
2026 2034 prettyptr = vidptr + vidlen + 1;
2027 2035 prettylen = strlen(prettyptr);
2028 2036 datanameptr = prettyptr + prettylen + 1;
2029 2037 datanamelen = strlen(datanameptr);
2030 2038 tripletlen = vidlen + prettylen + datanamelen + 3;
2031 2039
2032 2040 if (vidlen == 0) {
2033 2041 continue;
2034 2042 }
2035 2043
2036 2044 /*
2037 2045 * If inquiry vid dosen't match this triplets vid,
2038 2046 * try the next.
2039 2047 */
2040 2048 if (strncasecmp(vidpid, vidptr, vidlen)) {
2041 2049 continue;
2042 2050 }
2043 2051
2044 2052 /*
2045 2053 * if prettylen is zero then use the vid string
2046 2054 */
2047 2055 if (prettylen == 0) {
2048 2056 prettyptr = vidptr;
2049 2057 prettylen = vidlen;
2050 2058 }
2051 2059
2052 2060 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
2053 2061 "vid = %s, pretty=%s, dataname = %s\n",
2054 2062 vidptr, prettyptr, datanameptr);
2055 2063
2056 2064 /*
2057 2065 * get the data list
2058 2066 */
2059 2067 if (ddi_getlongprop(DDI_DEV_T_ANY, ST_DEVINFO, 0,
2060 2068 datanameptr, (caddr_t)&data_list,
2061 2069 &data_list_len) != DDI_PROP_SUCCESS) {
2062 2070 /*
2063 2071 * Error in getting property value
2064 2072 * print warning!
2065 2073 */
2066 2074 scsi_log(ST_DEVINFO, st_label, CE_WARN,
2067 2075 "data property (%s) has no value\n",
2068 2076 datanameptr);
2069 2077 continue;
2070 2078 }
2071 2079
2072 2080 /*
2073 2081 * now initialize the st_drivetype struct
2074 2082 */
2075 2083 (void) strncpy(dp->name, prettyptr, ST_NAMESIZE - 1);
2076 2084 dp->length = (int)min(vidlen, (VIDPIDLEN - 1));
2077 2085 (void) strncpy(dp->vid, vidptr, dp->length);
2078 2086 data_ptr = (int *)data_list;
2079 2087 /*
2080 2088 * check if data is enough for version, type,
2081 2089 * bsize, options, # of densities, density1,
2082 2090 * density2, ..., default_density
2083 2091 */
2084 2092 if ((data_list_len < 5 * sizeof (int)) ||
2085 2093 (data_list_len < 6 * sizeof (int) +
2086 2094 *(data_ptr + 4) * sizeof (int))) {
2087 2095 /*
2088 2096 * print warning and skip to next triplet.
2089 2097 */
2090 2098 scsi_log(ST_DEVINFO, st_label, CE_WARN,
2091 2099 "data property (%s) incomplete\n",
2092 2100 datanameptr);
2093 2101 kmem_free(data_list, data_list_len);
2094 2102 continue;
2095 2103 }
2096 2104
2097 2105 if (st_validate_conf_data(un, data_ptr,
2098 2106 data_list_len / sizeof (int), datanameptr)) {
2099 2107 kmem_free(data_list, data_list_len);
2100 2108 scsi_log(ST_DEVINFO, st_label, CE_WARN,
2101 2109 "data property (%s) rejected\n",
2102 2110 datanameptr);
2103 2111 continue;
2104 2112 }
2105 2113
2106 2114 /*
2107 2115 * check version
2108 2116 */
2109 2117 version = *data_ptr++;
2110 2118 if (version != 1 && version != 2) {
2111 2119 /* print warning but accept it */
2112 2120 scsi_log(ST_DEVINFO, st_label, CE_WARN,
2113 2121 "Version # for data property (%s) "
2114 2122 "not set to 1 or 2\n", datanameptr);
2115 2123 }
2116 2124
2117 2125 dp->type = *data_ptr++;
2118 2126 dp->bsize = *data_ptr++;
2119 2127 dp->options = *data_ptr++;
2120 2128 dp->options |= ST_DYNAMIC;
2121 2129 len = *data_ptr++;
2122 2130 for (i = 0; i < NDENSITIES; i++) {
2123 2131 if (i < len) {
2124 2132 dp->densities[i] = *data_ptr++;
2125 2133 }
2126 2134 }
2127 2135 dp->default_density = *data_ptr << 3;
2128 2136 if (version == 2 &&
2129 2137 data_list_len >= (13 + len) * sizeof (int)) {
2130 2138 data_ptr++;
2131 2139 dp->non_motion_timeout = *data_ptr++;
2132 2140 dp->io_timeout = *data_ptr++;
2133 2141 dp->rewind_timeout = *data_ptr++;
2134 2142 dp->space_timeout = *data_ptr++;
2135 2143 dp->load_timeout = *data_ptr++;
2136 2144 dp->unload_timeout = *data_ptr++;
2137 2145 dp->erase_timeout = *data_ptr++;
2138 2146 }
2139 2147 kmem_free(data_list, data_list_len);
2140 2148 found = 1;
2141 2149 ST_DEBUG(ST_DEVINFO, st_label, SCSI_DEBUG,
2142 2150 "found in st.conf: vid = %s, pretty=%s\n",
2143 2151 dp->vid, dp->name);
2144 2152 break;
2145 2153 }
2146 2154
2147 2155 /*
2148 2156 * free up the memory allocated by ddi_getlongprop
2149 2157 */
2150 2158 if (config_list) {
2151 2159 kmem_free(config_list, config_list_len);
2152 2160 }
2153 2161 return (found);
2154 2162 }
2155 2163
2156 2164 static int
2157 2165 st_get_conf_from_st_conf_dot_c(struct scsi_tape *un, char *vidpid,
2158 2166 struct st_drivetype *dp)
2159 2167 {
2160 2168 int i;
2161 2169
2162 2170 ST_FUNC(ST_DEVINFO, st_get_conf_from_st_conf_dot_c);
2163 2171 /*
2164 2172 * Determine type of tape controller. Type is determined by
2165 2173 * checking the result of the earlier inquiry command and
2166 2174 * comparing vendor ids with strings in a table declared in st_conf.c.
2167 2175 */
2168 2176 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2169 2177 "st_get_conf_from_st_conf_dot_c(): looking at st_drivetypes\n");
2170 2178
2171 2179 for (i = 0; i < st_ndrivetypes; i++) {
2172 2180 if (st_drivetypes[i].length == 0) {
2173 2181 continue;
2174 2182 }
2175 2183 if (strncasecmp(vidpid, st_drivetypes[i].vid,
2176 2184 st_drivetypes[i].length)) {
2177 2185 continue;
2178 2186 }
2179 2187 bcopy(&st_drivetypes[i], dp, sizeof (st_drivetypes[i]));
2180 2188 return (1);
2181 2189 }
2182 2190 return (0);
2183 2191 }
2184 2192
2185 2193 static int
2186 2194 st_get_conf_from_tape_drive(struct scsi_tape *un, char *vidpid,
2187 2195 struct st_drivetype *dp)
2188 2196 {
2189 2197 int bsize;
2190 2198 ulong_t maxbsize;
2191 2199 caddr_t buf;
2192 2200 struct st_drivetype *tem_dp;
2193 2201 struct read_blklim *blklim;
2194 2202 int rval;
2195 2203 int i;
2196 2204
2197 2205 ST_FUNC(ST_DEVINFO, st_get_conf_from_tape_drive);
2198 2206
2199 2207 /*
2200 2208 * Determine the type of tape controller. Type is determined by
2201 2209 * sending SCSI commands to tape drive and deriving the type from
2202 2210 * the returned data.
2203 2211 */
2204 2212 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2205 2213 "st_get_conf_from_tape_drive(): asking tape drive\n");
2206 2214
2207 2215 tem_dp = kmem_zalloc(sizeof (struct st_drivetype), KM_SLEEP);
2208 2216
2209 2217 /*
2210 2218 * Make up a name
2211 2219 */
2212 2220 bcopy(vidpid, tem_dp->name, VIDPIDLEN);
2213 2221 tem_dp->name[VIDPIDLEN] = '\0';
2214 2222 tem_dp->length = min(strlen(ST_INQUIRY->inq_vid), (VIDPIDLEN - 1));
2215 2223 (void) strncpy(tem_dp->vid, ST_INQUIRY->inq_vid, tem_dp->length);
2216 2224 /*
2217 2225 * 'clean' vendor and product strings of non-printing chars
2218 2226 */
2219 2227 for (i = 0; i < VIDPIDLEN - 1; i ++) {
2220 2228 if (tem_dp->name[i] < ' ' || tem_dp->name[i] > '~') {
2221 2229 tem_dp->name[i] = '.';
2222 2230 }
2223 2231 }
2224 2232
2225 2233 /*
2226 2234 * MODE SENSE to determine block size.
2227 2235 */
2228 2236 un->un_dp->options |= ST_MODE_SEL_COMP | ST_UNLOADABLE;
2229 2237 rval = st_modesense(un);
2230 2238 if (rval) {
2231 2239 if (rval == EACCES) {
2232 2240 un->un_dp->type = ST_TYPE_INVALID;
2233 2241 rval = 1;
2234 2242 } else {
2235 2243 un->un_dp->options &= ~ST_MODE_SEL_COMP;
2236 2244 rval = 0;
2237 2245 }
2238 2246 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2239 2247 "st_get_conf_from_tape_drive(): fail to mode sense\n");
2240 2248 goto exit;
2241 2249 }
2242 2250
2243 2251 /* Can mode sense page 0x10 or 0xf */
2244 2252 tem_dp->options |= ST_MODE_SEL_COMP;
2245 2253 bsize = (un->un_mspl->high_bl << 16) |
2246 2254 (un->un_mspl->mid_bl << 8) |
2247 2255 (un->un_mspl->low_bl);
2248 2256
2249 2257 if (bsize == 0) {
2250 2258 tem_dp->options |= ST_VARIABLE;
2251 2259 tem_dp->bsize = 0;
2252 2260 } else if (bsize > ST_MAXRECSIZE_FIXED) {
2253 2261 rval = st_change_block_size(un, 0);
2254 2262 if (rval) {
2255 2263 if (rval == EACCES) {
2256 2264 un->un_dp->type = ST_TYPE_INVALID;
2257 2265 rval = 1;
2258 2266 } else {
2259 2267 rval = 0;
2260 2268 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2261 2269 "st_get_conf_from_tape_drive(): "
2262 2270 "Fixed record size is too large and"
2263 2271 "cannot switch to variable record size");
2264 2272 }
2265 2273 goto exit;
2266 2274 }
2267 2275 tem_dp->options |= ST_VARIABLE;
2268 2276 } else {
2269 2277 rval = st_change_block_size(un, 0);
2270 2278 if (rval == 0) {
2271 2279 tem_dp->options |= ST_VARIABLE;
2272 2280 tem_dp->bsize = 0;
2273 2281 } else if (rval != EACCES) {
2274 2282 tem_dp->bsize = bsize;
2275 2283 } else {
2276 2284 un->un_dp->type = ST_TYPE_INVALID;
2277 2285 rval = 1;
2278 2286 goto exit;
2279 2287 }
2280 2288 }
2281 2289
2282 2290 /*
2283 2291 * If READ BLOCk LIMITS works and upper block size limit is
2284 2292 * more than 64K, ST_NO_RECSIZE_LIMIT is supported.
2285 2293 */
2286 2294 blklim = kmem_zalloc(sizeof (struct read_blklim), KM_SLEEP);
2287 2295 rval = st_read_block_limits(un, blklim);
2288 2296 if (rval) {
2289 2297 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2290 2298 "st_get_conf_from_tape_drive(): "
2291 2299 "fail to read block limits.\n");
2292 2300 rval = 0;
2293 2301 kmem_free(blklim, sizeof (struct read_blklim));
2294 2302 goto exit;
2295 2303 }
2296 2304 maxbsize = (blklim->max_hi << 16) +
2297 2305 (blklim->max_mid << 8) + blklim->max_lo;
2298 2306 if (maxbsize > ST_MAXRECSIZE_VARIABLE) {
2299 2307 tem_dp->options |= ST_NO_RECSIZE_LIMIT;
2300 2308 }
2301 2309 kmem_free(blklim, sizeof (struct read_blklim));
2302 2310
2303 2311 /*
2304 2312 * Inquiry VPD page 0xb0 to see if the tape drive supports WORM
2305 2313 */
2306 2314 buf = kmem_zalloc(6, KM_SLEEP);
2307 2315 rval = st_get_special_inquiry(un, 6, buf, 0xb0);
2308 2316 if (rval) {
2309 2317 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2310 2318 "st_get_conf_from_tape_drive(): "
2311 2319 "fail to read vitial inquiry.\n");
2312 2320 rval = 0;
2313 2321 kmem_free(buf, 6);
2314 2322 goto exit;
2315 2323 }
2316 2324 if (buf[4] & 1) {
2317 2325 tem_dp->options |= ST_WORMABLE;
2318 2326 }
2319 2327 kmem_free(buf, 6);
2320 2328
2321 2329 /* Assume BSD BSR KNOWS_EOD */
2322 2330 tem_dp->options |= ST_BSF | ST_BSR | ST_KNOWS_EOD | ST_UNLOADABLE;
2323 2331 tem_dp->max_rretries = -1;
2324 2332 tem_dp->max_wretries = -1;
2325 2333
2326 2334 /*
2327 2335 * Decide the densities supported by tape drive by sending
2328 2336 * REPORT DENSITY SUPPORT command.
2329 2337 */
2330 2338 if (st_get_densities_from_tape_drive(un, tem_dp) == 0) {
2331 2339 goto exit;
2332 2340 }
2333 2341
2334 2342 /*
2335 2343 * Decide the timeout values for several commands by sending
2336 2344 * REPORT SUPPORTED OPERATION CODES command.
2337 2345 */
2338 2346 rval = st_get_timeout_values_from_tape_drive(un, tem_dp);
2339 2347 if (rval == 0 || ((rval == 1) && (tem_dp->type == ST_TYPE_INVALID))) {
2340 2348 goto exit;
2341 2349 }
2342 2350
2343 2351 bcopy(tem_dp, dp, sizeof (struct st_drivetype));
2344 2352 rval = 1;
2345 2353
2346 2354 exit:
2347 2355 un->un_status = KEY_NO_SENSE;
2348 2356 kmem_free(tem_dp, sizeof (struct st_drivetype));
2349 2357 return (rval);
2350 2358 }
2351 2359
2352 2360 static int
2353 2361 st_get_densities_from_tape_drive(struct scsi_tape *un,
2354 2362 struct st_drivetype *dp)
2355 2363 {
2356 2364 int i, p;
2357 2365 size_t buflen;
2358 2366 ushort_t des_len;
2359 2367 uchar_t *den_header;
2360 2368 uchar_t num_den;
2361 2369 uchar_t den[NDENSITIES];
2362 2370 uchar_t deflt[NDENSITIES];
2363 2371 struct report_density_desc *den_desc;
2364 2372
2365 2373 ST_FUNC(ST_DEVINFO, st_get_densities_from_type_drive);
2366 2374
2367 2375 /*
2368 2376 * Since we have no idea how many densitiy support entries
2369 2377 * will be returned, we send the command firstly assuming
2370 2378 * there is only one. Then we can decide the number of
2371 2379 * entries by available density support length. If multiple
2372 2380 * entries exist, we will resend the command with enough
2373 2381 * buffer size.
2374 2382 */
2375 2383 buflen = sizeof (struct report_density_header) +
2376 2384 sizeof (struct report_density_desc);
2377 2385 den_header = kmem_zalloc(buflen, KM_SLEEP);
2378 2386 if (st_report_density_support(un, den_header, buflen) != 0) {
2379 2387 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2380 2388 "st_get_conf_from_tape_drive(): fail to report density.\n");
2381 2389 kmem_free(den_header, buflen);
2382 2390 return (0);
2383 2391 }
2384 2392 des_len =
2385 2393 BE_16(((struct report_density_header *)den_header)->ava_dens_len);
2386 2394 num_den = (des_len - 2) / sizeof (struct report_density_desc);
2387 2395
2388 2396 if (num_den > 1) {
2389 2397 kmem_free(den_header, buflen);
2390 2398 buflen = sizeof (struct report_density_header) +
2391 2399 sizeof (struct report_density_desc) * num_den;
2392 2400 den_header = kmem_zalloc(buflen, KM_SLEEP);
2393 2401 if (st_report_density_support(un, den_header, buflen) != 0) {
2394 2402 ST_DEBUG2(ST_DEVINFO, st_label, SCSI_DEBUG,
2395 2403 "st_get_conf_from_tape_drive(): "
2396 2404 "fail to report density.\n");
2397 2405 kmem_free(den_header, buflen);
2398 2406 return (0);
2399 2407 }
2400 2408 }
2401 2409
2402 2410 den_desc = (struct report_density_desc *)(den_header
2403 2411 + sizeof (struct report_density_header));
2404 2412
2405 2413 /*
2406 2414 * Decide the drive type by assigning organization
2407 2415 */
2408 2416 for (i = 0; i < ST_NUM_MEMBERS(st_vid_dt); i ++) {
2409 2417 if (strncmp(st_vid_dt[i].vid, (char *)(den_desc->ass_org),
2410 2418 8) == 0) {
2411 2419 dp->type = st_vid_dt[i].type;
2412 2420 break;
2413 2421 }
2414 2422