-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
cam_xpt.c
6985 lines (6156 loc) · 182 KB
/
cam_xpt.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
/*
* Implementation of the Common Access Method Transport (XPT) layer.
*
* Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
* Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
* All rights reserved.
*
* 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,
* without modification, immediately at the beginning of the file.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/md5.h>
#include <sys/devicestat.h>
#include <sys/interrupt.h>
#include <sys/sbuf.h>
#ifdef PC98
#include <pc98/pc98/pc98_machdep.h> /* geometry translation */
#endif
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_periph.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_debug.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>
#include <cam/scsi/scsi_pass.h>
#include "opt_cam.h"
/* Datastructures internal to the xpt layer */
/*
* Definition of an async handler callback block. These are used to add
* SIMs and peripherals to the async callback lists.
*/
struct async_node {
SLIST_ENTRY(async_node) links;
u_int32_t event_enable; /* Async Event enables */
void (*callback)(void *arg, u_int32_t code,
struct cam_path *path, void *args);
void *callback_arg;
};
SLIST_HEAD(async_list, async_node);
SLIST_HEAD(periph_list, cam_periph);
static STAILQ_HEAD(highpowerlist, ccb_hdr) highpowerq;
/*
* This is the maximum number of high powered commands (e.g. start unit)
* that can be outstanding at a particular time.
*/
#ifndef CAM_MAX_HIGHPOWER
#define CAM_MAX_HIGHPOWER 4
#endif
/* number of high powered commands that can go through right now */
static int num_highpower = CAM_MAX_HIGHPOWER;
/*
* Structure for queueing a device in a run queue.
* There is one run queue for allocating new ccbs,
* and another for sending ccbs to the controller.
*/
struct cam_ed_qinfo {
cam_pinfo pinfo;
struct cam_ed *device;
};
/*
* The CAM EDT (Existing Device Table) contains the device information for
* all devices for all busses in the system. The table contains a
* cam_ed structure for each device on the bus.
*/
struct cam_ed {
TAILQ_ENTRY(cam_ed) links;
struct cam_ed_qinfo alloc_ccb_entry;
struct cam_ed_qinfo send_ccb_entry;
struct cam_et *target;
lun_id_t lun_id;
struct camq drvq; /*
* Queue of type drivers wanting to do
* work on this device.
*/
struct cam_ccbq ccbq; /* Queue of pending ccbs */
struct async_list asyncs; /* Async callback info for this B/T/L */
struct periph_list periphs; /* All attached devices */
u_int generation; /* Generation number */
struct cam_periph *owner; /* Peripheral driver's ownership tag */
struct xpt_quirk_entry *quirk; /* Oddities about this device */
/* Storage for the inquiry data */
#ifdef CAM_NEW_TRAN_CODE
cam_proto protocol;
u_int protocol_version;
cam_xport transport;
u_int transport_version;
#endif /* CAM_NEW_TRAN_CODE */
struct scsi_inquiry_data inq_data;
u_int8_t inq_flags; /*
* Current settings for inquiry flags.
* This allows us to override settings
* like disconnection and tagged
* queuing for a device.
*/
u_int8_t queue_flags; /* Queue flags from the control page */
u_int8_t serial_num_len;
u_int8_t *serial_num;
u_int32_t qfrozen_cnt;
u_int32_t flags;
#define CAM_DEV_UNCONFIGURED 0x01
#define CAM_DEV_REL_TIMEOUT_PENDING 0x02
#define CAM_DEV_REL_ON_COMPLETE 0x04
#define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08
#define CAM_DEV_RESIZE_QUEUE_NEEDED 0x10
#define CAM_DEV_TAG_AFTER_COUNT 0x20
#define CAM_DEV_INQUIRY_DATA_VALID 0x40
u_int32_t tag_delay_count;
#define CAM_TAG_DELAY_COUNT 5
u_int32_t refcount;
struct callout_handle c_handle;
};
/*
* Each target is represented by an ET (Existing Target). These
* entries are created when a target is successfully probed with an
* identify, and removed when a device fails to respond after a number
* of retries, or a bus rescan finds the device missing.
*/
struct cam_et {
TAILQ_HEAD(, cam_ed) ed_entries;
TAILQ_ENTRY(cam_et) links;
struct cam_eb *bus;
target_id_t target_id;
u_int32_t refcount;
u_int generation;
struct timeval last_reset;
};
/*
* Each bus is represented by an EB (Existing Bus). These entries
* are created by calls to xpt_bus_register and deleted by calls to
* xpt_bus_deregister.
*/
struct cam_eb {
TAILQ_HEAD(, cam_et) et_entries;
TAILQ_ENTRY(cam_eb) links;
path_id_t path_id;
struct cam_sim *sim;
struct timeval last_reset;
u_int32_t flags;
#define CAM_EB_RUNQ_SCHEDULED 0x01
u_int32_t refcount;
u_int generation;
};
struct cam_path {
struct cam_periph *periph;
struct cam_eb *bus;
struct cam_et *target;
struct cam_ed *device;
};
struct xpt_quirk_entry {
struct scsi_inquiry_pattern inq_pat;
u_int8_t quirks;
#define CAM_QUIRK_NOLUNS 0x01
#define CAM_QUIRK_NOSERIAL 0x02
#define CAM_QUIRK_HILUNS 0x04
u_int mintags;
u_int maxtags;
};
#define CAM_SCSI2_MAXLUN 8
typedef enum {
XPT_FLAG_OPEN = 0x01
} xpt_flags;
struct xpt_softc {
xpt_flags flags;
u_int32_t generation;
};
static const char quantum[] = "QUANTUM";
static const char sony[] = "SONY";
static const char west_digital[] = "WDIGTL";
static const char samsung[] = "SAMSUNG";
static const char seagate[] = "SEAGATE";
static const char microp[] = "MICROP";
static struct xpt_quirk_entry xpt_quirk_table[] =
{
{
/* Reports QUEUE FULL for temporary resource shortages */
{ T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
/*quirks*/0, /*mintags*/24, /*maxtags*/32
},
{
/* Reports QUEUE FULL for temporary resource shortages */
{ T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
/*quirks*/0, /*mintags*/24, /*maxtags*/32
},
{
/* Reports QUEUE FULL for temporary resource shortages */
{ T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
/*quirks*/0, /*mintags*/24, /*maxtags*/32
},
{
/* Broken tagged queuing drive */
{ T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/* Broken tagged queuing drive */
{ T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/* Broken tagged queuing drive */
{ T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/*
* Unfortunately, the Quantum Atlas III has the same
* problem as the Atlas II drives above.
* Reported by: "Johan Granlund" <johan@granlund.nu>
*
* For future reference, the drive with the problem was:
* QUANTUM QM39100TD-SW N1B0
*
* It's possible that Quantum will fix the problem in later
* firmware revisions. If that happens, the quirk entry
* will need to be made specific to the firmware revisions
* with the problem.
*
*/
/* Reports QUEUE FULL for temporary resource shortages */
{ T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
/*quirks*/0, /*mintags*/24, /*maxtags*/32
},
{
/*
* 18 Gig Atlas III, same problem as the 9G version.
* Reported by: Andre Albsmeier
* <andre.albsmeier@mchp.siemens.de>
*
* For future reference, the drive with the problem was:
* QUANTUM QM318000TD-S N491
*/
/* Reports QUEUE FULL for temporary resource shortages */
{ T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
/*quirks*/0, /*mintags*/24, /*maxtags*/32
},
{
/*
* Broken tagged queuing drive
* Reported by: Bret Ford <bford@uop.cs.uop.edu>
* and: Martin Renters <martin@tdc.on.ca>
*/
{ T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
/*
* The Seagate Medalist Pro drives have very poor write
* performance with anything more than 2 tags.
*
* Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
* Drive: <SEAGATE ST36530N 1444>
*
* Reported by: Jeremy Lea <reg@shale.csir.co.za>
* Drive: <SEAGATE ST34520W 1281>
*
* No one has actually reported that the 9G version
* (ST39140*) of the Medalist Pro has the same problem, but
* we're assuming that it does because the 4G and 6.5G
* versions of the drive are broken.
*/
{
{ T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
/*quirks*/0, /*mintags*/2, /*maxtags*/2
},
{
{ T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
/*quirks*/0, /*mintags*/2, /*maxtags*/2
},
{
{ T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
/*quirks*/0, /*mintags*/2, /*maxtags*/2
},
{
/*
* Slow when tagged queueing is enabled. Write performance
* steadily drops off with more and more concurrent
* transactions. Best sequential write performance with
* tagged queueing turned off and write caching turned on.
*
* PR: kern/10398
* Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
* Drive: DCAS-34330 w/ "S65A" firmware.
*
* The drive with the problem had the "S65A" firmware
* revision, and has also been reported (by Stephen J.
* Roznowski <sjr@home.net>) for a drive with the "S61A"
* firmware revision.
*
* Although no one has reported problems with the 2 gig
* version of the DCAS drive, the assumption is that it
* has the same problems as the 4 gig version. Therefore
* this quirk entries disables tagged queueing for all
* DCAS drives.
*/
{ T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/* Broken tagged queuing drive */
{ T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/* Broken tagged queuing drive */
{ T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/*
* Broken tagged queuing drive.
* Submitted by:
* NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
* in PR kern/9535
*/
{ T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/*
* Slow when tagged queueing is enabled. (1.5MB/sec versus
* 8MB/sec.)
* Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
* Best performance with these drives is achieved with
* tagged queueing turned off, and write caching turned on.
*/
{ T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/*
* Slow when tagged queueing is enabled. (1.5MB/sec versus
* 8MB/sec.)
* Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
* Best performance with these drives is achieved with
* tagged queueing turned off, and write caching turned on.
*/
{ T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
/*quirks*/0, /*mintags*/0, /*maxtags*/0
},
{
/*
* Doesn't handle queue full condition correctly,
* so we need to limit maxtags to what the device
* can handle instead of determining this automatically.
*/
{ T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
/*quirks*/0, /*mintags*/2, /*maxtags*/32
},
{
/* Really only one LUN */
{ T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/* I can't believe we need a quirk for DPT volumes. */
{ T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS,
/*mintags*/0, /*maxtags*/255
},
{
/*
* Many Sony CDROM drives don't like multi-LUN probing.
*/
{ T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/*
* This drive doesn't like multiple LUN probing.
* Submitted by: Parag Patel <parag@cgt.com>
*/
{ T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
{ T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/*
* The 8200 doesn't like multi-lun probing, and probably
* don't like serial number requests either.
*/
{
T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
"EXB-8200*", "*"
},
CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/*
* Let's try the same as above, but for a drive that says
* it's an IPL-6860 but is actually an EXB 8200.
*/
{
T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
"IPL-6860*", "*"
},
CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/*
* These Hitachi drives don't like multi-lun probing.
* The PR submitter has a DK319H, but says that the Linux
* kernel has a similar work-around for the DK312 and DK314,
* so all DK31* drives are quirked here.
* PR: misc/18793
* Submitted by: Paul Haddad <paul@pth.com>
*/
{ T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
},
{
/*
* This old revision of the TDC3600 is also SCSI-1, and
* hangs upon serial number probing.
*/
{
T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
" TDC 3600", "U07:"
},
CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
},
{
/*
* Would repond to all LUNs if asked for.
*/
{
T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
"CP150", "*"
},
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/*
* Would repond to all LUNs if asked for.
*/
{
T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
"96X2*", "*"
},
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/* Submitted by: Matthew Dodd <winter@jurai.net> */
{ T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/* Submitted by: Matthew Dodd <winter@jurai.net> */
{ T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/* TeraSolutions special settings for TRC-22 RAID */
{ T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
/*quirks*/0, /*mintags*/55, /*maxtags*/255
},
{
/*
* Would respond to all LUNs. Device type and removable
* flag are jumper-selectable.
*/
{ T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
"Tahiti 1", "*"
},
CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
},
{
/* Default tagged queuing parameters for all devices */
{
T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
/*vendor*/"*", /*product*/"*", /*revision*/"*"
},
/*quirks*/0, /*mintags*/2, /*maxtags*/255
},
};
static const int xpt_quirk_table_size =
sizeof(xpt_quirk_table) / sizeof(*xpt_quirk_table);
typedef enum {
DM_RET_COPY = 0x01,
DM_RET_FLAG_MASK = 0x0f,
DM_RET_NONE = 0x00,
DM_RET_STOP = 0x10,
DM_RET_DESCEND = 0x20,
DM_RET_ERROR = 0x30,
DM_RET_ACTION_MASK = 0xf0
} dev_match_ret;
typedef enum {
XPT_DEPTH_BUS,
XPT_DEPTH_TARGET,
XPT_DEPTH_DEVICE,
XPT_DEPTH_PERIPH
} xpt_traverse_depth;
struct xpt_traverse_config {
xpt_traverse_depth depth;
void *tr_func;
void *tr_arg;
};
typedef int xpt_busfunc_t (struct cam_eb *bus, void *arg);
typedef int xpt_targetfunc_t (struct cam_et *target, void *arg);
typedef int xpt_devicefunc_t (struct cam_ed *device, void *arg);
typedef int xpt_periphfunc_t (struct cam_periph *periph, void *arg);
typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
/* Transport layer configuration information */
static struct xpt_softc xsoftc;
/* Queues for our software interrupt handler */
typedef TAILQ_HEAD(cam_isrq, ccb_hdr) cam_isrq_t;
static cam_isrq_t cam_bioq;
static cam_isrq_t cam_netq;
/* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */
static SLIST_HEAD(,ccb_hdr) ccb_freeq;
static u_int xpt_max_ccbs; /*
* Maximum size of ccb pool. Modified as
* devices are added/removed or have their
* opening counts changed.
*/
static u_int xpt_ccb_count; /* Current count of allocated ccbs */
struct cam_periph *xpt_periph;
static periph_init_t xpt_periph_init;
static periph_init_t probe_periph_init;
static struct periph_driver xpt_driver =
{
xpt_periph_init, "xpt",
TAILQ_HEAD_INITIALIZER(xpt_driver.units)
};
static struct periph_driver probe_driver =
{
probe_periph_init, "probe",
TAILQ_HEAD_INITIALIZER(probe_driver.units)
};
PERIPHDRIVER_DECLARE(xpt, xpt_driver);
PERIPHDRIVER_DECLARE(probe, probe_driver);
#define XPT_CDEV_MAJOR 104
static d_open_t xptopen;
static d_close_t xptclose;
static d_ioctl_t xptioctl;
static struct cdevsw xpt_cdevsw = {
/* open */ xptopen,
/* close */ xptclose,
/* read */ noread,
/* write */ nowrite,
/* ioctl */ xptioctl,
/* poll */ nopoll,
/* mmap */ nommap,
/* strategy */ nostrategy,
/* name */ "xpt",
/* maj */ XPT_CDEV_MAJOR,
/* dump */ nodump,
/* psize */ nopsize,
/* flags */ 0,
};
static struct intr_config_hook *xpt_config_hook;
/* Registered busses */
static TAILQ_HEAD(,cam_eb) xpt_busses;
static u_int bus_generation;
/* Storage for debugging datastructures */
#ifdef CAMDEBUG
struct cam_path *cam_dpath;
u_int32_t cam_dflags;
u_int32_t cam_debug_delay;
#endif
/* Pointers to software interrupt handlers */
void *camnet_ih;
void *cambio_ih;
#if defined(CAM_DEBUG_FLAGS) && !defined(CAMDEBUG)
#error "You must have options CAMDEBUG to use options CAM_DEBUG_FLAGS"
#endif
/*
* In order to enable the CAM_DEBUG_* options, the user must have CAMDEBUG
* enabled. Also, the user must have either none, or all of CAM_DEBUG_BUS,
* CAM_DEBUG_TARGET, and CAM_DEBUG_LUN specified.
*/
#if defined(CAM_DEBUG_BUS) || defined(CAM_DEBUG_TARGET) \
|| defined(CAM_DEBUG_LUN)
#ifdef CAMDEBUG
#if !defined(CAM_DEBUG_BUS) || !defined(CAM_DEBUG_TARGET) \
|| !defined(CAM_DEBUG_LUN)
#error "You must define all or none of CAM_DEBUG_BUS, CAM_DEBUG_TARGET \
and CAM_DEBUG_LUN"
#endif /* !CAM_DEBUG_BUS || !CAM_DEBUG_TARGET || !CAM_DEBUG_LUN */
#else /* !CAMDEBUG */
#error "You must use options CAMDEBUG if you use the CAM_DEBUG_* options"
#endif /* CAMDEBUG */
#endif /* CAM_DEBUG_BUS || CAM_DEBUG_TARGET || CAM_DEBUG_LUN */
/* Our boot-time initialization hook */
static int cam_module_event_handler(module_t, int /*modeventtype_t*/, void *);
static moduledata_t cam_moduledata = {
"cam",
cam_module_event_handler,
NULL
};
static void xpt_init(void *);
DECLARE_MODULE(cam, cam_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND);
MODULE_VERSION(cam, 1);
static cam_status xpt_compile_path(struct cam_path *new_path,
struct cam_periph *perph,
path_id_t path_id,
target_id_t target_id,
lun_id_t lun_id);
static void xpt_release_path(struct cam_path *path);
static void xpt_async_bcast(struct async_list *async_head,
u_int32_t async_code,
struct cam_path *path,
void *async_arg);
static void xpt_dev_async(u_int32_t async_code,
struct cam_eb *bus,
struct cam_et *target,
struct cam_ed *device,
void *async_arg);
static path_id_t xptnextfreepathid(void);
static path_id_t xptpathid(const char *sim_name, int sim_unit, int sim_bus);
static union ccb *xpt_get_ccb(struct cam_ed *device);
static int xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,
u_int32_t new_priority);
static void xpt_run_dev_allocq(struct cam_eb *bus);
static void xpt_run_dev_sendq(struct cam_eb *bus);
static timeout_t xpt_release_devq_timeout;
static timeout_t xpt_release_simq_timeout;
static void xpt_release_bus(struct cam_eb *bus);
static void xpt_release_devq_device(struct cam_ed *dev, u_int count,
int run_queue);
static struct cam_et*
xpt_alloc_target(struct cam_eb *bus, target_id_t target_id);
static void xpt_release_target(struct cam_eb *bus, struct cam_et *target);
static struct cam_ed*
xpt_alloc_device(struct cam_eb *bus, struct cam_et *target,
lun_id_t lun_id);
static void xpt_release_device(struct cam_eb *bus, struct cam_et *target,
struct cam_ed *device);
static u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
static struct cam_eb*
xpt_find_bus(path_id_t path_id);
static struct cam_et*
xpt_find_target(struct cam_eb *bus, target_id_t target_id);
static struct cam_ed*
xpt_find_device(struct cam_et *target, lun_id_t lun_id);
static void xpt_scan_bus(struct cam_periph *periph, union ccb *ccb);
static void xpt_scan_lun(struct cam_periph *periph,
struct cam_path *path, cam_flags flags,
union ccb *ccb);
static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
static xpt_busfunc_t xptconfigbuscountfunc;
static xpt_busfunc_t xptconfigfunc;
static void xpt_config(void *arg);
static xpt_devicefunc_t xptpassannouncefunc;
static void xpt_finishconfig(struct cam_periph *periph, union ccb *ccb);
static void xptaction(struct cam_sim *sim, union ccb *work_ccb);
static void xptpoll(struct cam_sim *sim);
static void camisr(void *);
#if 0
static void xptstart(struct cam_periph *periph, union ccb *work_ccb);
static void xptasync(struct cam_periph *periph,
u_int32_t code, cam_path *path);
#endif
static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns,
u_int num_patterns, struct cam_eb *bus);
static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns,
u_int num_patterns,
struct cam_ed *device);
static dev_match_ret xptperiphmatch(struct dev_match_pattern *patterns,
u_int num_patterns,
struct cam_periph *periph);
static xpt_busfunc_t xptedtbusfunc;
static xpt_targetfunc_t xptedttargetfunc;
static xpt_devicefunc_t xptedtdevicefunc;
static xpt_periphfunc_t xptedtperiphfunc;
static xpt_pdrvfunc_t xptplistpdrvfunc;
static xpt_periphfunc_t xptplistperiphfunc;
static int xptedtmatch(struct ccb_dev_match *cdm);
static int xptperiphlistmatch(struct ccb_dev_match *cdm);
static int xptbustraverse(struct cam_eb *start_bus,
xpt_busfunc_t *tr_func, void *arg);
static int xpttargettraverse(struct cam_eb *bus,
struct cam_et *start_target,
xpt_targetfunc_t *tr_func, void *arg);
static int xptdevicetraverse(struct cam_et *target,
struct cam_ed *start_device,
xpt_devicefunc_t *tr_func, void *arg);
static int xptperiphtraverse(struct cam_ed *device,
struct cam_periph *start_periph,
xpt_periphfunc_t *tr_func, void *arg);
static int xptpdrvtraverse(struct periph_driver **start_pdrv,
xpt_pdrvfunc_t *tr_func, void *arg);
static int xptpdperiphtraverse(struct periph_driver **pdrv,
struct cam_periph *start_periph,
xpt_periphfunc_t *tr_func,
void *arg);
static xpt_busfunc_t xptdefbusfunc;
static xpt_targetfunc_t xptdeftargetfunc;
static xpt_devicefunc_t xptdefdevicefunc;
static xpt_periphfunc_t xptdefperiphfunc;
static int xpt_for_all_busses(xpt_busfunc_t *tr_func, void *arg);
#ifdef notusedyet
static int xpt_for_all_targets(xpt_targetfunc_t *tr_func,
void *arg);
#endif
static int xpt_for_all_devices(xpt_devicefunc_t *tr_func,
void *arg);
#ifdef notusedyet
static int xpt_for_all_periphs(xpt_periphfunc_t *tr_func,
void *arg);
#endif
static xpt_devicefunc_t xptsetasyncfunc;
static xpt_busfunc_t xptsetasyncbusfunc;
static cam_status xptregister(struct cam_periph *periph,
void *arg);
static cam_status proberegister(struct cam_periph *periph,
void *arg);
static void probeschedule(struct cam_periph *probe_periph);
static void probestart(struct cam_periph *periph, union ccb *start_ccb);
static void proberequestdefaultnegotiation(struct cam_periph *periph);
static void probedone(struct cam_periph *periph, union ccb *done_ccb);
static void probecleanup(struct cam_periph *periph);
static void xpt_find_quirk(struct cam_ed *device);
#ifdef CAM_NEW_TRAN_CODE
static void xpt_devise_transport(struct cam_path *path);
#endif /* CAM_NEW_TRAN_CODE */
static void xpt_set_transfer_settings(struct ccb_trans_settings *cts,
struct cam_ed *device,
int async_update);
static void xpt_toggle_tags(struct cam_path *path);
static void xpt_start_tags(struct cam_path *path);
static __inline int xpt_schedule_dev_allocq(struct cam_eb *bus,
struct cam_ed *dev);
static __inline int xpt_schedule_dev_sendq(struct cam_eb *bus,
struct cam_ed *dev);
static __inline int periph_is_queued(struct cam_periph *periph);
static __inline int device_is_alloc_queued(struct cam_ed *device);
static __inline int device_is_send_queued(struct cam_ed *device);
static __inline int dev_allocq_is_runnable(struct cam_devq *devq);
static __inline int
xpt_schedule_dev_allocq(struct cam_eb *bus, struct cam_ed *dev)
{
int retval;
if (dev->ccbq.devq_openings > 0) {
if ((dev->flags & CAM_DEV_RESIZE_QUEUE_NEEDED) != 0) {
cam_ccbq_resize(&dev->ccbq,
dev->ccbq.dev_openings
+ dev->ccbq.dev_active);
dev->flags &= ~CAM_DEV_RESIZE_QUEUE_NEEDED;
}
/*
* The priority of a device waiting for CCB resources
* is that of the the highest priority peripheral driver
* enqueued.
*/
retval = xpt_schedule_dev(&bus->sim->devq->alloc_queue,
&dev->alloc_ccb_entry.pinfo,
CAMQ_GET_HEAD(&dev->drvq)->priority);
} else {
retval = 0;
}
return (retval);
}
static __inline int
xpt_schedule_dev_sendq(struct cam_eb *bus, struct cam_ed *dev)
{
int retval;
if (dev->ccbq.dev_openings > 0) {
/*
* The priority of a device waiting for controller
* resources is that of the the highest priority CCB
* enqueued.
*/
retval =
xpt_schedule_dev(&bus->sim->devq->send_queue,
&dev->send_ccb_entry.pinfo,
CAMQ_GET_HEAD(&dev->ccbq.queue)->priority);
} else {
retval = 0;
}
return (retval);
}
static __inline int
periph_is_queued(struct cam_periph *periph)
{
return (periph->pinfo.index != CAM_UNQUEUED_INDEX);
}
static __inline int
device_is_alloc_queued(struct cam_ed *device)
{
return (device->alloc_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);
}
static __inline int
device_is_send_queued(struct cam_ed *device)
{
return (device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);
}
static __inline int
dev_allocq_is_runnable(struct cam_devq *devq)
{
/*
* Have work to do.
* Have space to do more work.
* Allowed to do work.
*/
return ((devq->alloc_queue.qfrozen_cnt == 0)
&& (devq->alloc_queue.entries > 0)
&& (devq->alloc_openings > 0));
}
static void
xpt_periph_init()
{
make_dev(&xpt_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "xpt0");
}
static void
probe_periph_init()
{
}
static void
xptdone(struct cam_periph *periph, union ccb *done_ccb)
{
/* Caller will release the CCB */
wakeup(&done_ccb->ccb_h.cbfcnp);
}
static int
xptopen(dev_t dev, int flags, int fmt, struct proc *p)
{
int unit;
unit = minor(dev) & 0xff;
/*
* Only allow read-write access.
*/
if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0))
return(EPERM);
/*
* We don't allow nonblocking access.
*/
if ((flags & O_NONBLOCK) != 0) {
printf("xpt%d: can't do nonblocking accesss\n", unit);
return(ENODEV);
}
/*
* We only have one transport layer right now. If someone accesses
* us via something other than minor number 1, point out their
* mistake.
*/
if (unit != 0) {
printf("xptopen: got invalid xpt unit %d\n", unit);
return(ENXIO);
}
/* Mark ourselves open */
xsoftc.flags |= XPT_FLAG_OPEN;
return(0);
}
static int
xptclose(dev_t dev, int flag, int fmt, struct proc *p)
{
int unit;
unit = minor(dev) & 0xff;
/*
* We only have one transport layer right now. If someone accesses
* us via something other than minor number 1, point out their
* mistake.
*/
if (unit != 0) {
printf("xptclose: got invalid xpt unit %d\n", unit);
return(ENXIO);
}
/* Mark ourselves closed */
xsoftc.flags &= ~XPT_FLAG_OPEN;
return(0);
}
static int
xptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
{
int unit, error;
error = 0;
unit = minor(dev) & 0xff;
/*
* We only have one transport layer right now. If someone accesses
* us via something other than minor number 1, point out their
* mistake.
*/
if (unit != 0) {
printf("xptioctl: got invalid xpt unit %d\n", unit);
return(ENXIO);
}
switch(cmd) {
/*
* For the transport layer CAMIOCOMMAND ioctl, we really only want
* to accept CCB types that don't quite make sense to send through a
* passthrough driver. XPT_PATH_INQ is an exception to this, as stated
* in the CAM spec.
*/
case CAMIOCOMMAND: {
union ccb *ccb;
union ccb *inccb;
inccb = (union ccb *)addr;