-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscsiconf.c
1274 lines (1128 loc) · 37.1 KB
/
scsiconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
* Simulation Facility, NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Originally written by Julian Elischer ([email protected])
* for TRW Financial Systems for use under the MACH(2.5) operating system.
*
* TRW Financial Systems, in accordance with their agreement with Carnegie
* Mellon University, makes this software available to CMU to distribute
* or use in any manner that they see fit as long as this message is kept with
* the software. For this reason TFS also grants any other persons or
* organisations permission to use or modify this software.
*
* TFS supplies this software to be publicly redistributed
* on the understanding that TFS is not responsible for the correct
* functioning of this software in any circumstances.
*
* Ported to run under 386BSD by Julian Elischer ([email protected]) Sept 1992
*/
#ifdef DEBUG_SCSICONF
#define USE_SERIAL_OUTPUT
#endif
#include "port.h"
#include "port_bsd.h"
#include <string.h>
#ifdef PORT_AMIGA
#include "device.h"
#include "scsi_all.h"
#include "scsipi_all.h"
#include "scsipiconf.h"
#else /* !PORT_AMIGA */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/kthread.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/once.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/scsiio.h>
#include <sys/queue.h>
#include <sys/atomic.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
#include "locators.h"
static const struct scsipi_periphsw scsi_probe_dev = {
NULL,
NULL,
NULL,
NULL,
};
struct scsi_initq {
struct scsipi_channel *sc_channel;
TAILQ_ENTRY(scsi_initq) scsi_initq;
};
static ONCE_DECL(scsi_conf_ctrl);
static TAILQ_HEAD(, scsi_initq) scsi_initq_head;
static kmutex_t scsibus_qlock;
static kcondvar_t scsibus_qcv;
static int scsi_probe_device(struct scsibus_softc *, int, int);
static int scsibusmatch(device_t, cfdata_t, void *);
static void scsibusattach(device_t, device_t, void *);
static int scsibusdetach(device_t, int flags);
static int scsibusrescan(device_t, const char *, const int *);
static void scsidevdetached(device_t, device_t);
CFATTACH_DECL3_NEW(scsibus, sizeof(struct scsibus_softc),
scsibusmatch, scsibusattach, scsibusdetach, NULL,
scsibusrescan, scsidevdetached, DVF_DETACH_SHUTDOWN);
extern struct cfdriver scsibus_cd;
static dev_type_open(scsibusopen);
static dev_type_close(scsibusclose);
static dev_type_ioctl(scsibusioctl);
const struct cdevsw scsibus_cdevsw = {
.d_open = scsibusopen,
.d_close = scsibusclose,
.d_read = noread,
.d_write = nowrite,
.d_ioctl = scsibusioctl,
.d_stop = nostop,
.d_tty = notty,
.d_poll = nopoll,
.d_mmap = nommap,
.d_kqfilter = nokqfilter,
.d_discard = nodiscard,
.d_flag = D_OTHER | D_MPSAFE
};
static int scsibusprint(void *, const char *);
static void scsibus_discover_thread(void *);
static void scsibus_config(struct scsibus_softc *);
const struct scsipi_bustype scsi_bustype = {
.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
SCSIPI_BUSTYPE_SCSI_PSCSI),
.bustype_cmd = scsi_scsipi_cmd,
.bustype_interpret_sense = scsipi_interpret_sense,
.bustype_printaddr = scsi_print_addr,
.bustype_kill_pending = scsi_kill_pending,
.bustype_async_event_xfer_mode = scsi_async_event_xfer_mode,
};
const struct scsipi_bustype scsi_fc_bustype = {
.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
SCSIPI_BUSTYPE_SCSI_FC),
.bustype_cmd = scsi_scsipi_cmd,
.bustype_interpret_sense = scsipi_interpret_sense,
.bustype_printaddr = scsi_print_addr,
.bustype_kill_pending = scsi_kill_pending,
.bustype_async_event_xfer_mode = scsi_fc_sas_async_event_xfer_mode,
};
const struct scsipi_bustype scsi_sas_bustype = {
.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
SCSIPI_BUSTYPE_SCSI_SAS),
.bustype_cmd = scsi_scsipi_cmd,
.bustype_interpret_sense = scsipi_interpret_sense,
.bustype_printaddr = scsi_print_addr,
.bustype_kill_pending = scsi_kill_pending,
.bustype_async_event_xfer_mode = scsi_fc_sas_async_event_xfer_mode,
};
const struct scsipi_bustype scsi_usb_bustype = {
.bustype_type = SCSIPI_BUSTYPE_BUSTYPE(SCSIPI_BUSTYPE_SCSI,
SCSIPI_BUSTYPE_SCSI_USB),
.bustype_cmd = scsi_scsipi_cmd,
.bustype_interpret_sense = scsipi_interpret_sense,
.bustype_printaddr = scsi_print_addr,
.bustype_kill_pending = scsi_kill_pending,
.bustype_async_event_xfer_mode = NULL,
};
#define aprint_naive printf
#define aprint_normal printf
int aprint_error_dev(device_t self, const char *fmt, ...)
{
int rc;
va_list args;
printf("%s: ", device_xname(self));
va_start(args, fmt);
rc = vprintf(fmt, args);
va_end(args);
return (rc);
}
static int
scsibus_init(void)
{
TAILQ_INIT(&scsi_initq_head);
mutex_init(&scsibus_qlock, MUTEX_DEFAULT, IPL_NONE);
cv_init(&scsibus_qcv, "scsinitq");
return 0;
}
int
scsiprint(void *aux, const char *pnp)
{
struct scsipi_channel *chan = aux;
struct scsipi_adapter *adapt = chan->chan_adapter;
/* only "scsibus"es can attach to "scsi"s; easy. */
if (pnp)
aprint_normal("scsibus at %s", pnp);
/* don't print channel if the controller says there can be only one. */
if (adapt->adapt_nchannels != 1)
aprint_normal(" channel %d", chan->chan_channel);
return (UNCONF);
}
static int
scsibusmatch(device_t parent, cfdata_t cf, void *aux)
{
#if 0
struct scsipi_channel *chan = aux;
if (SCSIPI_BUSTYPE_TYPE(chan->chan_bustype->bustype_type) !=
SCSIPI_BUSTYPE_SCSI)
return 0;
if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel &&
cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
return (0);
#endif
return (1);
}
static void
scsibusattach(device_t parent, device_t self, void *aux)
{
struct scsibus_softc *sc = device_private(self);
struct scsipi_channel *chan = aux;
struct scsi_initq *scsi_initq;
#if 0
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
#endif
sc->sc_dev = self;
sc->sc_channel = chan;
chan->chan_name = device_xname(sc->sc_dev);
aprint_naive(": SCSI bus\n");
aprint_normal(": %d target%s, %d lun%s per target\n",
chan->chan_ntargets,
chan->chan_ntargets == 1 ? "" : "s",
chan->chan_nluns,
chan->chan_nluns == 1 ? "" : "s");
/*
* XXX
* newer adapters support more than 256 outstanding commands
* per periph and don't use the tag (they eventually allocate one
* internally). Right now scsipi always allocate a tag and
* is limited to 256 tags, per scsi specs.
* this should be revisited
*/
if (chan->chan_flags & SCSIPI_CHAN_OPENINGS) {
if (chan->chan_max_periph > 256)
chan->chan_max_periph = 256;
#ifndef PORT_AMIGA
} else {
if (chan->chan_adapter->adapt_max_periph > 256)
chan->chan_adapter->adapt_max_periph = 256;
#endif
}
#if 0
if (atomic_inc_uint_nv(&chan_running(chan)) == 1)
mutex_init(chan_mtx(chan), MUTEX_DEFAULT, IPL_BIO);
#endif
cv_init(&chan->chan_cv_thr, "scshut");
cv_init(&chan->chan_cv_comp, "sccomp");
cv_init(&chan->chan_cv_xs, "xscmd");
if (scsipi_adapter_addref(chan->chan_adapter))
return;
#define RUN_ONCE(o, fn) \
(__predict_true((o)->o_status == ONCE_DONE) ? \
((o)->o_error) : _init_once((o), (fn)))
RUN_ONCE(&scsi_conf_ctrl, scsibus_init);
/* Initialize the channel structure first */
chan->chan_init_cb = NULL;
chan->chan_init_cb_arg = NULL;
#ifdef PORT_AMIGA
NOTE: Code is not currently enabled
scsi_initq = AllocMem(sizeof(*scsi_initq), MEMF_PUBLIC);
#else
scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK);
#endif
scsi_initq->sc_channel = chan;
TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq);
config_pending_incr(sc->sc_dev);
if (scsipi_channel_init(chan)) {
aprint_error_dev(sc->sc_dev, "failed to init channel\n");
return;
}
/*
* Create the discover thread
*/
if (kthread_create(PRI_NONE, 0, NULL, scsibus_discover_thread, sc,
&chan->chan_dthread, "%s-d", chan->chan_name)) {
aprint_error_dev(sc->sc_dev, "unable to create discovery "
"thread for channel %d\n", chan->chan_channel);
return;
}
}
static void
scsibus_discover_thread(void *arg)
{
struct scsibus_softc *sc = arg;
scsibus_config(sc);
sc->sc_channel->chan_dthread = NULL;
kthread_exit(0);
}
static void
scsibus_config(struct scsibus_softc *sc)
{
struct scsipi_channel *chan = sc->sc_channel;
struct scsi_initq *scsi_initq;
#ifndef SCSI_DELAY
#define SCSI_DELAY 2
#endif
if ((chan->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 &&
SCSI_DELAY > 0) {
aprint_normal_dev(sc->sc_dev,
"waiting %d seconds for devices to settle...\n",
SCSI_DELAY);
/* ...an identifier we know no one will use... */
#ifdef PORT_AMIGA
NOTE: Code is not currently enabled
delay(SCSI_DELAY * 1000000);
#else
kpause("scsidly", false, SCSI_DELAY * hz, NULL);
#endif
}
#if 0
/* Make sure the devices probe in scsibus order to avoid jitter. */
mutex_enter(&scsibus_qlock);
for (;;) {
scsi_initq = TAILQ_FIRST(&scsi_initq_head);
if (scsi_initq->sc_channel == chan)
break;
cv_wait(&scsibus_qcv, &scsibus_qlock);
}
mutex_exit(&scsibus_qlock);
#endif
scsi_probe_bus(sc, -1, -1);
mutex_enter(&scsibus_qlock);
TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq);
cv_broadcast(&scsibus_qcv);
mutex_exit(&scsibus_qlock);
#ifdef PORT_AMIGA
NOTE: Code is not currently enabled
FreeMem(scsi_initq, sizeof(*scsi_initq));
#else
free(scsi_initq, M_DEVBUF);
#endif
scsipi_adapter_delref(chan->chan_adapter);
config_pending_decr(sc->sc_dev);
}
static int
scsibusdetach(device_t self, int flags)
{
struct scsibus_softc *sc = device_private(self);
struct scsipi_channel *chan = sc->sc_channel;
int error;
/*
* Defer while discovery thread is running
*/
#ifdef PORT_AMIGA
NOTE: Code is not currently enabled
while (chan->chan_dthread != NULL)
delay(1000000);
#else
while (chan->chan_dthread != NULL)
kpause("scsibusdet", false, hz, NULL);
#endif
/*
* Detach all of the periphs.
*/
error = scsipi_target_detach(chan, -1, -1, flags);
if (error)
return error;
pmf_device_deregister(self);
/*
* Shut down the channel.
*/
scsipi_channel_shutdown(chan);
cv_destroy(&chan->chan_cv_xs);
cv_destroy(&chan->chan_cv_comp);
cv_destroy(&chan->chan_cv_thr);
#if 0
if (atomic_dec_uint_nv(&chan_running(chan)) == 0)
mutex_destroy(chan_mtx(chan));
#endif
return 0;
}
/*
* Probe the requested scsi bus. It must be already set up.
* target and lun optionally narrow the search if not -1
*/
int
scsi_probe_bus(struct scsibus_softc *sc, int target, int lun)
{
struct scsipi_channel *chan = sc->sc_channel;
int maxtarget, mintarget, maxlun, minlun;
int error;
if (target == -1) {
maxtarget = chan->chan_ntargets - 1;
mintarget = 0;
} else {
if (target < 0 || target >= chan->chan_ntargets)
return (EINVAL);
maxtarget = mintarget = target;
}
if (lun == -1) {
maxlun = chan->chan_nluns - 1;
minlun = 0;
} else {
if (lun < 0 || lun >= chan->chan_nluns)
return (EINVAL);
maxlun = minlun = lun;
}
/*
* Some HBAs provide an abstracted view of the bus; give them an
* opportunity to re-scan it before we do.
*/
scsipi_adapter_ioctl(chan, SCBUSIOLLSCAN, NULL, 0, curproc);
if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
goto ret;
for (target = mintarget; target <= maxtarget; target++) {
if (target == chan->chan_id)
continue;
for (lun = minlun; lun <= maxlun; lun++) {
/*
* See if there's a device present, and configure it.
*/
if (scsi_probe_device(sc, target, lun) == 0)
break;
/* otherwise something says we should look further */
}
/*
* Now that we've discovered all of the LUNs on this
* I_T Nexus, update the xfer mode for all of them
* that we know about.
*/
scsipi_set_xfer_mode(chan, target, 1);
}
scsipi_adapter_delref(chan->chan_adapter);
ret:
return (error);
}
static int
scsibusrescan(device_t sc, const char *ifattr, const int *locators)
{
KASSERT(ifattr && !strcmp(ifattr, "scsibus"));
KASSERT(locators);
return (scsi_probe_bus(device_private(sc),
locators[SCSIBUSCF_TARGET], locators[SCSIBUSCF_LUN]));
}
static void
scsidevdetached(device_t self, device_t child)
{
struct scsibus_softc *sc = device_private(self);
struct scsipi_channel *chan = sc->sc_channel;
struct scsipi_periph *periph;
int target, lun;
target = device_locator(child, SCSIBUSCF_TARGET);
lun = device_locator(child, SCSIBUSCF_LUN);
mutex_enter(chan_mtx(chan));
periph = scsipi_lookup_periph_locked(chan, target, lun);
KASSERT(periph != NULL && periph->periph_dev == child);
scsipi_remove_periph(chan, periph);
scsipi_free_periph(periph);
mutex_exit(chan_mtx(chan));
}
/*
* Print out autoconfiguration information for a subdevice.
*
* This is a slight abuse of 'standard' autoconfiguration semantics,
* because 'print' functions don't normally print the colon and
* device information. However, in this case that's better than
* either printing redundant information before the attach message,
* or having the device driver call a special function to print out
* the standard device information.
*/
static int
scsibusprint(void *aux, const char *pnp)
{
struct scsipibus_attach_args *sa = aux;
struct scsipi_inquiry_pattern *inqbuf;
u_int8_t type;
const char *dtype;
char vendor[33], product[65], revision[17];
int target, lun;
if (pnp != NULL)
aprint_normal("%s", pnp);
inqbuf = &sa->sa_inqbuf;
target = sa->sa_periph->periph_target;
lun = sa->sa_periph->periph_lun;
type = inqbuf->type & SID_TYPE;
dtype = scsipi_dtype(type);
strnvisx(vendor, sizeof(vendor), inqbuf->vendor, 8,
VIS_TRIM|VIS_SAFE|VIS_OCTAL);
strnvisx(product, sizeof(product), inqbuf->product, 16,
VIS_TRIM|VIS_SAFE|VIS_OCTAL);
strnvisx(revision, sizeof(revision), inqbuf->revision, 4,
VIS_TRIM|VIS_SAFE|VIS_OCTAL);
aprint_normal(" target %d lun %d: <%s, %s, %s> %s %s%s",
target, lun, vendor, product, revision, dtype,
inqbuf->removable ? "removable" : "fixed",
(sa->sa_periph->periph_opcs != NULL)
? " timeout-info" : "");
return (UNCONF);
}
static const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
{{T_DIRECT, T_REMOV,
"Apple ", "iPod ", ""}, PQUIRK_START},
{{T_CDROM, T_REMOV,
"CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"CHINON ", "CD-ROM CDS-435 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"GENERIC ", "CRD-BP2 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:502", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"OLYMPUS ", "CDS620E ", "1.1d"},
PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOCAPACITY},
{{T_CDROM, T_REMOV,
"PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"PLEXTOR ", "CD-ROM PX-4XCS ", "1.01"},
PQUIRK_NOLUNS|PQUIRK_NOSYNC},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-76S", ""},
PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOWIDE},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"TOSHIBA ", "XM-4101TASUNSLCD", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
/* "IBM CDRM00201 !F" 0724 is an IBM OEM Toshiba XM-4101BME */
{{T_CDROM, T_REMOV,
"IBM ", "CDRM00201 !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
{{T_CDROM, T_REMOV,
"ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"JVC ", "R2626", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"YAMAHA", "CRW8424S", ""}, PQUIRK_NOLUNS},
{{T_CDROM, T_REMOV,
"NEC ", "CD-ROM DRIVE:222", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
{{T_DIRECT, T_FIXED,
"MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE},
{{T_OPTICAL, T_REMOV,
"EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE},
{{T_DIRECT, T_FIXED,
"ADAPTEC ", "ACB-4000", ""}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE|PQUIRK_NOMODESENSE},
{{T_DIRECT, T_FIXED,
"DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"EMULEX ", "MD21/S2 ESDI", "A00"},
PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"MICROP", "1548-15MZ1077801", "HZ2P"}, PQUIRK_NOTAG},
{{T_DIRECT, T_FIXED,
"HP ", "C372", ""}, PQUIRK_NOTAG},
{{T_DIRECT, T_FIXED,
"IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"IBM ", "0663H", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"IBM", "0664", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
/* improperly report DT-only sync mode */
"IBM ", "DXHS36D", ""},
PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16},
{{T_DIRECT, T_FIXED,
"IBM ", "DXHS18Y", ""},
PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16},
{{T_DIRECT, T_FIXED,
"IBM ", "H3171-S2", ""},
PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE},
/* Broken IBM disk */
{{T_DIRECT, T_FIXED,
"" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"Initio ", "", ""}, PQUIRK_NOBIGMODESENSE},
{{T_DIRECT, T_FIXED,
"JMicron ", "Generic ", ""}, PQUIRK_NOFUA},
{{T_DIRECT, T_REMOV,
"MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE},
{{T_DIRECT, T_FIXED,
"MICROP", "1991-27MZ", ""}, PQUIRK_NOTAG},
{{T_DIRECT, T_FIXED,
"MST ", "SnapLink ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"QUANTUM ", "ATLAS IV 9 WLS", "0A0A"}, PQUIRK_CAP_NODT},
{{T_DIRECT, T_FIXED,
"RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST318404LC ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST336753LC ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST336753LW ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST336754LC ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST39236LC ", ""}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST15150N ", ""}, PQUIRK_NOTAG},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST32430N", ""}, PQUIRK_CAP_SYNC},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "SX910800N", ""}, PQUIRK_NOTAG},
{{T_DIRECT, T_FIXED,
"TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS},
{{T_DIRECT, T_FIXED,
"MICROP ", "1924", ""}, PQUIRK_CAP_SYNC},
{{T_DIRECT, T_FIXED,
"FUJITSU ", "M2266", ""}, PQUIRK_CAP_SYNC},
{{T_DIRECT, T_FIXED,
"FUJITSU ", "M2624S-512 ", ""}, PQUIRK_CAP_SYNC},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "SX336704LC" , ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
{{T_DIRECT, T_FIXED,
"SEAGATE ", "SX173404LC", ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
{{T_DIRECT, T_REMOV,
"IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
{{T_DIRECT, T_REMOV,
"INSITE", "I325VM", ""}, PQUIRK_NOLUNS},
/* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
{{T_SEQUENTIAL, T_REMOV,
" ", " ", " "}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"EMULEX ", "MT-02 QIC ", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
{{T_SEQUENTIAL, T_REMOV,
"SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS},
/* Following entry reported as a Tandberg 3600; ref. PR1933 */
{{T_SEQUENTIAL, T_REMOV,
"ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS},
/* Following entry for a Cipher ST150S; ref. PR4171 */
{{T_SEQUENTIAL, T_REMOV,
"ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS},
{{T_SEQUENTIAL, T_REMOV,
"WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
{{T_SEQUENTIAL, T_REMOV,
"WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
{{T_SEQUENTIAL, T_REMOV,
"WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
{{T_SEQUENTIAL, T_REMOV,
"TEAC ", "MT-2ST/N50 ", ""}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS},
{{T_SCANNER, T_FIXED,
"ULTIMA ", "A6000C ", ""}, PQUIRK_NOLUNS},
{{T_PROCESSOR, T_FIXED,
"ESG-SHV", "SCA HSBP M15", ""}, PQUIRK_NOLUNS},
{{T_PROCESSOR, T_FIXED,
"SYMBIOS", "", ""}, PQUIRK_NOLUNS},
{{T_PROCESSOR, T_FIXED,
"LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS},
{{T_CHANGER, T_REMOV,
"SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS},
{{T_ENCLOSURE, T_FIXED,
"SUN ", "SENA ", ""}, PQUIRK_NOLUNS},
};
#endif /* !PORT_AMIGA */
/*
* given a target and lun, ask the device what
* it is, and find the correct driver table
* entry.
*/
#ifdef PORT_AMIGA
int
scsi_probe_device(struct scsipi_channel *chan, int target, int lun, struct scsipi_periph *periph, int *failed)
#else
static int
scsi_probe_device(struct scsibus_softc *sc, int target, int lun)
#endif
{
#ifdef PORT_AMIGA
struct scsipi_inquiry_data inqbuf;
int checkdtype, docontinue, quirks;
*failed = 0; // Default to success
#else /* !PORT_AMIGA */
struct scsipi_channel *chan = sc->sc_channel;
struct scsipi_periph *periph;
struct scsipi_inquiry_data inqbuf;
const struct scsi_quirk_inquiry_pattern *finger;
int priority;
int checkdtype, docontinue, quirks;
struct scsipibus_attach_args sa;
cfdata_t cf;
int locs[SCSIBUSCF_NLOCS];
#endif
/*
* Assume no more LUNs to search after this one.
* If we successfully get Inquiry data and after
* merging quirks we find we can probe for more
* LUNs, we will.
*/
docontinue = 0;
/* Skip this slot if it is already attached. */
if (scsipi_lookup_periph(chan, target, lun) != NULL)
return (docontinue);
#ifdef PORT_AMIGA
periph->periph_channel = chan;
#else
periph = scsipi_alloc_periph(M_WAITOK);
periph->periph_channel = chan;
periph->periph_switch = &scsi_probe_dev;
#endif
periph->periph_target = target;
periph->periph_lun = lun;
#ifndef PORT_AMIGA
periph->periph_quirks = chan->chan_defquirks;
#endif
#ifdef SCSIPI_DEBUG
if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI &&
SCSIPI_DEBUG_TARGET == target &&
SCSIPI_DEBUG_LUN == lun)
periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
#endif
/*
* Ask the device what it is
*/
#ifdef SCSI_2_DEF
/* some devices need to be told to go to SCSI2 */
/* However some just explode if you tell them this.. leave it out */
scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
#endif /* SCSI_2_DEF */
/* Now go ask the device all about itself. */
memset(&inqbuf, 0, sizeof(inqbuf));
{
u_int8_t *extension = &inqbuf.flags1;
int len = 0;
while (len < 3)
extension[len++] = '\0';
while (len < 3 + 28)
extension[len++] = ' ';
while (len < 3 + 28 + 20)
extension[len++] = '\0';
while (len < 3 + 28 + 20 + 1)
extension[len++] = '\0';
while (len < 3 + 28 + 20 + 1 + 1)
extension[len++] = '\0';
while (len < 3 + 28 + 20 + 1 + 1 + (8*2))
extension[len++] = ' ';
}
if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY | XS_CTL_SILENT)) {
#ifdef PORT_AMIGA
*failed = ERROR_INQUIRY_FAILED;
#endif
goto bad;
}
periph->periph_type = inqbuf.device & SID_TYPE;
if (inqbuf.dev_qual2 & SID_REMOVABLE)
periph->periph_flags |= PERIPH_REMOVABLE;
periph->periph_version = inqbuf.version & SID_ANSII;
/*
* Any device qualifier that has the top bit set (qualifier&4 != 0)
* is vendor specific and won't match in this switch.
* All we do here is throw out bad/negative responses.
*/
checkdtype = 0;
switch (inqbuf.device & SID_QUAL) {
case SID_QUAL_LU_PRESENT:
checkdtype = 1;
break;
case SID_QUAL_LU_NOTPRESENT:
case SID_QUAL_reserved:
case SID_QUAL_LU_NOT_SUPP:
#ifdef PORT_AMIGA
*failed = ERROR_BAD_UNIT;
#endif
goto bad;
default:
break;
}
#ifdef PORT_AMIGA
periph->periph_flags |= PERIPH_MEDIA_LOADED;
#endif
#ifndef PORT_AMIGA
/* Let the adapter driver handle the device separately if it wants. */
if (chan->chan_adapter->adapt_accesschk != NULL &&
(*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf))
goto bad;
#endif
if (checkdtype) {
switch (periph->periph_type) {
case T_DIRECT:
case T_SEQUENTIAL: