2 * Implementation of the Common Access Method Transport (XPT) layer.
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/types.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
41 #include <sys/fcntl.h>
43 #include <sys/interrupt.h>
47 #include <sys/mutex.h>
48 #include <sys/sysctl.h>
51 #include <pc98/pc98/pc98_machdep.h> /* geometry translation */
55 #include <cam/cam_ccb.h>
56 #include <cam/cam_periph.h>
57 #include <cam/cam_sim.h>
58 #include <cam/cam_xpt.h>
59 #include <cam/cam_xpt_sim.h>
60 #include <cam/cam_xpt_periph.h>
61 #include <cam/cam_debug.h>
63 #include <cam/scsi/scsi_all.h>
64 #include <cam/scsi/scsi_message.h>
65 #include <cam/scsi/scsi_pass.h>
68 /* Datastructures internal to the xpt layer */
69 MALLOC_DEFINE(M_CAMXPT, "CAM XPT", "CAM XPT buffers");
72 * Definition of an async handler callback block. These are used to add
73 * SIMs and peripherals to the async callback lists.
76 SLIST_ENTRY(async_node) links;
77 u_int32_t event_enable; /* Async Event enables */
78 void (*callback)(void *arg, u_int32_t code,
79 struct cam_path *path, void *args);
83 SLIST_HEAD(async_list, async_node);
84 SLIST_HEAD(periph_list, cam_periph);
85 static STAILQ_HEAD(highpowerlist, ccb_hdr) highpowerq;
88 * This is the maximum number of high powered commands (e.g. start unit)
89 * that can be outstanding at a particular time.
91 #ifndef CAM_MAX_HIGHPOWER
92 #define CAM_MAX_HIGHPOWER 4
95 /* number of high powered commands that can go through right now */
96 static int num_highpower = CAM_MAX_HIGHPOWER;
99 * Structure for queueing a device in a run queue.
100 * There is one run queue for allocating new ccbs,
101 * and another for sending ccbs to the controller.
103 struct cam_ed_qinfo {
105 struct cam_ed *device;
109 * The CAM EDT (Existing Device Table) contains the device information for
110 * all devices for all busses in the system. The table contains a
111 * cam_ed structure for each device on the bus.
114 TAILQ_ENTRY(cam_ed) links;
115 struct cam_ed_qinfo alloc_ccb_entry;
116 struct cam_ed_qinfo send_ccb_entry;
117 struct cam_et *target;
120 * Queue of type drivers wanting to do
121 * work on this device.
123 struct cam_ccbq ccbq; /* Queue of pending ccbs */
124 struct async_list asyncs; /* Async callback info for this B/T/L */
125 struct periph_list periphs; /* All attached devices */
126 u_int generation; /* Generation number */
127 struct cam_periph *owner; /* Peripheral driver's ownership tag */
128 struct xpt_quirk_entry *quirk; /* Oddities about this device */
129 /* Storage for the inquiry data */
130 #ifdef CAM_NEW_TRAN_CODE
132 u_int protocol_version;
134 u_int transport_version;
135 #endif /* CAM_NEW_TRAN_CODE */
136 struct scsi_inquiry_data inq_data;
137 u_int8_t inq_flags; /*
138 * Current settings for inquiry flags.
139 * This allows us to override settings
140 * like disconnection and tagged
141 * queuing for a device.
143 u_int8_t queue_flags; /* Queue flags from the control page */
144 u_int8_t serial_num_len;
145 u_int8_t *serial_num;
146 u_int32_t qfrozen_cnt;
148 #define CAM_DEV_UNCONFIGURED 0x01
149 #define CAM_DEV_REL_TIMEOUT_PENDING 0x02
150 #define CAM_DEV_REL_ON_COMPLETE 0x04
151 #define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08
152 #define CAM_DEV_RESIZE_QUEUE_NEEDED 0x10
153 #define CAM_DEV_TAG_AFTER_COUNT 0x20
154 #define CAM_DEV_INQUIRY_DATA_VALID 0x40
155 u_int32_t tag_delay_count;
156 #define CAM_TAG_DELAY_COUNT 5
157 u_int32_t tag_saved_openings;
159 struct callout_handle c_handle;
163 * Each target is represented by an ET (Existing Target). These
164 * entries are created when a target is successfully probed with an
165 * identify, and removed when a device fails to respond after a number
166 * of retries, or a bus rescan finds the device missing.
169 TAILQ_HEAD(, cam_ed) ed_entries;
170 TAILQ_ENTRY(cam_et) links;
172 target_id_t target_id;
175 struct timeval last_reset;
179 * Each bus is represented by an EB (Existing Bus). These entries
180 * are created by calls to xpt_bus_register and deleted by calls to
181 * xpt_bus_deregister.
184 TAILQ_HEAD(, cam_et) et_entries;
185 TAILQ_ENTRY(cam_eb) links;
188 struct timeval last_reset;
190 #define CAM_EB_RUNQ_SCHEDULED 0x01
196 struct cam_periph *periph;
198 struct cam_et *target;
199 struct cam_ed *device;
202 struct xpt_quirk_entry {
203 struct scsi_inquiry_pattern inq_pat;
205 #define CAM_QUIRK_NOLUNS 0x01
206 #define CAM_QUIRK_NOSERIAL 0x02
207 #define CAM_QUIRK_HILUNS 0x04
208 #define CAM_QUIRK_NOHILUNS 0x08
213 static int cam_srch_hi = 0;
214 TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi);
215 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
216 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
217 sysctl_cam_search_luns, "I",
218 "allow search above LUN 7 for SCSI3 and greater devices");
220 #define CAM_SCSI2_MAXLUN 8
222 * If we're not quirked to search <= the first 8 luns
223 * and we are either quirked to search above lun 8,
224 * or we're > SCSI-2 and we've enabled hilun searching,
225 * or we're > SCSI-2 and the last lun was a success,
226 * we can look for luns above lun 8.
228 #define CAN_SRCH_HI_SPARSE(dv) \
229 (((dv->quirk->quirks & CAM_QUIRK_NOHILUNS) == 0) \
230 && ((dv->quirk->quirks & CAM_QUIRK_HILUNS) \
231 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
233 #define CAN_SRCH_HI_DENSE(dv) \
234 (((dv->quirk->quirks & CAM_QUIRK_NOHILUNS) == 0) \
235 && ((dv->quirk->quirks & CAM_QUIRK_HILUNS) \
236 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
244 u_int32_t generation;
247 static const char quantum[] = "QUANTUM";
248 static const char sony[] = "SONY";
249 static const char west_digital[] = "WDIGTL";
250 static const char samsung[] = "SAMSUNG";
251 static const char seagate[] = "SEAGATE";
252 static const char microp[] = "MICROP";
254 static struct xpt_quirk_entry xpt_quirk_table[] =
257 /* Reports QUEUE FULL for temporary resource shortages */
258 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
259 /*quirks*/0, /*mintags*/24, /*maxtags*/32
262 /* Reports QUEUE FULL for temporary resource shortages */
263 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
264 /*quirks*/0, /*mintags*/24, /*maxtags*/32
267 /* Reports QUEUE FULL for temporary resource shortages */
268 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
269 /*quirks*/0, /*mintags*/24, /*maxtags*/32
272 /* Broken tagged queuing drive */
273 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
274 /*quirks*/0, /*mintags*/0, /*maxtags*/0
277 /* Broken tagged queuing drive */
278 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
279 /*quirks*/0, /*mintags*/0, /*maxtags*/0
282 /* Broken tagged queuing drive */
283 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
284 /*quirks*/0, /*mintags*/0, /*maxtags*/0
288 * Unfortunately, the Quantum Atlas III has the same
289 * problem as the Atlas II drives above.
290 * Reported by: "Johan Granlund" <johan@granlund.nu>
292 * For future reference, the drive with the problem was:
293 * QUANTUM QM39100TD-SW N1B0
295 * It's possible that Quantum will fix the problem in later
296 * firmware revisions. If that happens, the quirk entry
297 * will need to be made specific to the firmware revisions
301 /* Reports QUEUE FULL for temporary resource shortages */
302 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
303 /*quirks*/0, /*mintags*/24, /*maxtags*/32
307 * 18 Gig Atlas III, same problem as the 9G version.
308 * Reported by: Andre Albsmeier
309 * <andre.albsmeier@mchp.siemens.de>
311 * For future reference, the drive with the problem was:
312 * QUANTUM QM318000TD-S N491
314 /* Reports QUEUE FULL for temporary resource shortages */
315 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
316 /*quirks*/0, /*mintags*/24, /*maxtags*/32
320 * Broken tagged queuing drive
321 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
322 * and: Martin Renters <martin@tdc.on.ca>
324 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
325 /*quirks*/0, /*mintags*/0, /*maxtags*/0
328 * The Seagate Medalist Pro drives have very poor write
329 * performance with anything more than 2 tags.
331 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
332 * Drive: <SEAGATE ST36530N 1444>
334 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
335 * Drive: <SEAGATE ST34520W 1281>
337 * No one has actually reported that the 9G version
338 * (ST39140*) of the Medalist Pro has the same problem, but
339 * we're assuming that it does because the 4G and 6.5G
340 * versions of the drive are broken.
343 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
344 /*quirks*/0, /*mintags*/2, /*maxtags*/2
347 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
348 /*quirks*/0, /*mintags*/2, /*maxtags*/2
351 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
352 /*quirks*/0, /*mintags*/2, /*maxtags*/2
356 * Slow when tagged queueing is enabled. Write performance
357 * steadily drops off with more and more concurrent
358 * transactions. Best sequential write performance with
359 * tagged queueing turned off and write caching turned on.
362 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
363 * Drive: DCAS-34330 w/ "S65A" firmware.
365 * The drive with the problem had the "S65A" firmware
366 * revision, and has also been reported (by Stephen J.
367 * Roznowski <sjr@home.net>) for a drive with the "S61A"
370 * Although no one has reported problems with the 2 gig
371 * version of the DCAS drive, the assumption is that it
372 * has the same problems as the 4 gig version. Therefore
373 * this quirk entries disables tagged queueing for all
376 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
377 /*quirks*/0, /*mintags*/0, /*maxtags*/0
380 /* Broken tagged queuing drive */
381 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
382 /*quirks*/0, /*mintags*/0, /*maxtags*/0
385 /* Broken tagged queuing drive */
386 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
387 /*quirks*/0, /*mintags*/0, /*maxtags*/0
391 * Broken tagged queuing drive.
393 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
396 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
397 /*quirks*/0, /*mintags*/0, /*maxtags*/0
401 * Slow when tagged queueing is enabled. (1.5MB/sec versus
403 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
404 * Best performance with these drives is achieved with
405 * tagged queueing turned off, and write caching turned on.
407 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
408 /*quirks*/0, /*mintags*/0, /*maxtags*/0
412 * Slow when tagged queueing is enabled. (1.5MB/sec versus
414 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
415 * Best performance with these drives is achieved with
416 * tagged queueing turned off, and write caching turned on.
418 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
419 /*quirks*/0, /*mintags*/0, /*maxtags*/0
423 * Doesn't handle queue full condition correctly,
424 * so we need to limit maxtags to what the device
425 * can handle instead of determining this automatically.
427 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
428 /*quirks*/0, /*mintags*/2, /*maxtags*/32
431 /* Really only one LUN */
432 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
433 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
436 /* I can't believe we need a quirk for DPT volumes. */
437 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
438 CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS,
439 /*mintags*/0, /*maxtags*/255
443 * Many Sony CDROM drives don't like multi-LUN probing.
445 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
446 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
450 * This drive doesn't like multiple LUN probing.
451 * Submitted by: Parag Patel <parag@cgt.com>
453 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
454 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
457 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
458 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
462 * The 8200 doesn't like multi-lun probing, and probably
463 * don't like serial number requests either.
466 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
469 CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
473 * Let's try the same as above, but for a drive that says
474 * it's an IPL-6860 but is actually an EXB 8200.
477 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
480 CAM_QUIRK_NOSERIAL|CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
484 * These Hitachi drives don't like multi-lun probing.
485 * The PR submitter has a DK319H, but says that the Linux
486 * kernel has a similar work-around for the DK312 and DK314,
487 * so all DK31* drives are quirked here.
489 * Submitted by: Paul Haddad <paul@pth.com>
491 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
492 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
496 * The Hitachi CJ series with J8A8 firmware apparantly has
497 * problems with tagged commands.
499 * Reported by: amagai@nue.org
501 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
502 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
506 * These are the large storage arrays.
507 * Submitted by: William Carrel <william.carrel@infospace.com>
509 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
510 CAM_QUIRK_HILUNS, 2, 1024
514 * This old revision of the TDC3600 is also SCSI-1, and
515 * hangs upon serial number probing.
518 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
521 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
525 * Maxtor Personal Storage 3000XT (Firewire)
526 * hangs upon serial number probing.
529 T_DIRECT, SIP_MEDIA_FIXED, "Maxtor",
532 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
536 * Would repond to all LUNs if asked for.
539 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
542 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
546 * Would repond to all LUNs if asked for.
549 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
552 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
555 /* Submitted by: Matthew Dodd <winter@jurai.net> */
556 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
557 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
560 /* Submitted by: Matthew Dodd <winter@jurai.net> */
561 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
562 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
565 /* TeraSolutions special settings for TRC-22 RAID */
566 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
567 /*quirks*/0, /*mintags*/55, /*maxtags*/255
570 /* Veritas Storage Appliance */
571 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
572 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
576 * Would respond to all LUNs. Device type and removable
577 * flag are jumper-selectable.
579 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
582 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
585 /* EasyRAID E5A aka. areca ARC-6010 */
586 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
587 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
590 /* Default tagged queuing parameters for all devices */
592 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
593 /*vendor*/"*", /*product*/"*", /*revision*/"*"
595 /*quirks*/0, /*mintags*/2, /*maxtags*/255
599 static const int xpt_quirk_table_size =
600 sizeof(xpt_quirk_table) / sizeof(*xpt_quirk_table);
604 DM_RET_FLAG_MASK = 0x0f,
607 DM_RET_DESCEND = 0x20,
609 DM_RET_ACTION_MASK = 0xf0
617 } xpt_traverse_depth;
619 struct xpt_traverse_config {
620 xpt_traverse_depth depth;
625 typedef int xpt_busfunc_t (struct cam_eb *bus, void *arg);
626 typedef int xpt_targetfunc_t (struct cam_et *target, void *arg);
627 typedef int xpt_devicefunc_t (struct cam_ed *device, void *arg);
628 typedef int xpt_periphfunc_t (struct cam_periph *periph, void *arg);
629 typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
631 /* Transport layer configuration information */
632 static struct xpt_softc xsoftc;
634 /* Queues for our software interrupt handler */
635 typedef TAILQ_HEAD(cam_isrq, ccb_hdr) cam_isrq_t;
636 static cam_isrq_t cam_bioq;
637 static struct mtx cam_bioq_lock;
639 /* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */
640 static SLIST_HEAD(,ccb_hdr) ccb_freeq;
641 static u_int xpt_max_ccbs; /*
642 * Maximum size of ccb pool. Modified as
643 * devices are added/removed or have their
644 * opening counts changed.
646 static u_int xpt_ccb_count; /* Current count of allocated ccbs */
648 struct cam_periph *xpt_periph;
650 static periph_init_t xpt_periph_init;
652 static periph_init_t probe_periph_init;
654 static struct periph_driver xpt_driver =
656 xpt_periph_init, "xpt",
657 TAILQ_HEAD_INITIALIZER(xpt_driver.units)
660 static struct periph_driver probe_driver =
662 probe_periph_init, "probe",
663 TAILQ_HEAD_INITIALIZER(probe_driver.units)
666 PERIPHDRIVER_DECLARE(xpt, xpt_driver);
667 PERIPHDRIVER_DECLARE(probe, probe_driver);
670 static d_open_t xptopen;
671 static d_close_t xptclose;
672 static d_ioctl_t xptioctl;
674 static struct cdevsw xpt_cdevsw = {
675 .d_version = D_VERSION,
676 .d_flags = D_NEEDGIANT,
683 static struct intr_config_hook *xpt_config_hook;
685 static void dead_sim_action(struct cam_sim *sim, union ccb *ccb);
686 static void dead_sim_poll(struct cam_sim *sim);
688 /* Dummy SIM that is used when the real one has gone. */
689 static struct cam_sim cam_dead_sim = {
690 .sim_action = dead_sim_action,
691 .sim_poll = dead_sim_poll,
692 .sim_name = "dead_sim",
695 #define SIM_DEAD(sim) ((sim) == &cam_dead_sim)
697 /* Registered busses */
698 static TAILQ_HEAD(,cam_eb) xpt_busses;
699 static u_int bus_generation;
701 /* Storage for debugging datastructures */
703 struct cam_path *cam_dpath;
704 u_int32_t cam_dflags;
705 u_int32_t cam_debug_delay;
708 /* Pointers to software interrupt handlers */
709 static void *cambio_ih;
711 #if defined(CAM_DEBUG_FLAGS) && !defined(CAMDEBUG)
712 #error "You must have options CAMDEBUG to use options CAM_DEBUG_FLAGS"
716 * In order to enable the CAM_DEBUG_* options, the user must have CAMDEBUG
717 * enabled. Also, the user must have either none, or all of CAM_DEBUG_BUS,
718 * CAM_DEBUG_TARGET, and CAM_DEBUG_LUN specified.
720 #if defined(CAM_DEBUG_BUS) || defined(CAM_DEBUG_TARGET) \
721 || defined(CAM_DEBUG_LUN)
723 #if !defined(CAM_DEBUG_BUS) || !defined(CAM_DEBUG_TARGET) \
724 || !defined(CAM_DEBUG_LUN)
725 #error "You must define all or none of CAM_DEBUG_BUS, CAM_DEBUG_TARGET \
727 #endif /* !CAM_DEBUG_BUS || !CAM_DEBUG_TARGET || !CAM_DEBUG_LUN */
728 #else /* !CAMDEBUG */
729 #error "You must use options CAMDEBUG if you use the CAM_DEBUG_* options"
730 #endif /* CAMDEBUG */
731 #endif /* CAM_DEBUG_BUS || CAM_DEBUG_TARGET || CAM_DEBUG_LUN */
733 /* Our boot-time initialization hook */
734 static int cam_module_event_handler(module_t, int /*modeventtype_t*/, void *);
736 static moduledata_t cam_moduledata = {
738 cam_module_event_handler,
742 static void xpt_init(void *);
744 DECLARE_MODULE(cam, cam_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND);
745 MODULE_VERSION(cam, 1);
748 static cam_status xpt_compile_path(struct cam_path *new_path,
749 struct cam_periph *perph,
751 target_id_t target_id,
754 static void xpt_release_path(struct cam_path *path);
756 static void xpt_async_bcast(struct async_list *async_head,
757 u_int32_t async_code,
758 struct cam_path *path,
760 static void xpt_dev_async(u_int32_t async_code,
762 struct cam_et *target,
763 struct cam_ed *device,
765 static path_id_t xptnextfreepathid(void);
766 static path_id_t xptpathid(const char *sim_name, int sim_unit, int sim_bus);
767 static union ccb *xpt_get_ccb(struct cam_ed *device);
768 static int xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,
769 u_int32_t new_priority);
770 static void xpt_run_dev_allocq(struct cam_eb *bus);
771 static void xpt_run_dev_sendq(struct cam_eb *bus);
772 static timeout_t xpt_release_devq_timeout;
773 static timeout_t xpt_release_simq_timeout;
774 static void xpt_release_bus(struct cam_eb *bus);
775 static void xpt_release_devq_device(struct cam_ed *dev, u_int count,
777 static struct cam_et*
778 xpt_alloc_target(struct cam_eb *bus, target_id_t target_id);
779 static void xpt_release_target(struct cam_eb *bus, struct cam_et *target);
780 static struct cam_ed*
781 xpt_alloc_device(struct cam_eb *bus, struct cam_et *target,
783 static void xpt_release_device(struct cam_eb *bus, struct cam_et *target,
784 struct cam_ed *device);
785 static u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
786 static struct cam_eb*
787 xpt_find_bus(path_id_t path_id);
788 static struct cam_et*
789 xpt_find_target(struct cam_eb *bus, target_id_t target_id);
790 static struct cam_ed*
791 xpt_find_device(struct cam_et *target, lun_id_t lun_id);
792 static void xpt_scan_bus(struct cam_periph *periph, union ccb *ccb);
793 static void xpt_scan_lun(struct cam_periph *periph,
794 struct cam_path *path, cam_flags flags,
796 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
797 static xpt_busfunc_t xptconfigbuscountfunc;
798 static xpt_busfunc_t xptconfigfunc;
799 static void xpt_config(void *arg);
800 static xpt_devicefunc_t xptpassannouncefunc;
801 static void xpt_finishconfig(struct cam_periph *periph, union ccb *ccb);
802 static void xptaction(struct cam_sim *sim, union ccb *work_ccb);
803 static void xptpoll(struct cam_sim *sim);
804 static void camisr(void *);
806 static void xptstart(struct cam_periph *periph, union ccb *work_ccb);
807 static void xptasync(struct cam_periph *periph,
808 u_int32_t code, cam_path *path);
810 static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns,
811 u_int num_patterns, struct cam_eb *bus);
812 static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns,
814 struct cam_ed *device);
815 static dev_match_ret xptperiphmatch(struct dev_match_pattern *patterns,
817 struct cam_periph *periph);
818 static xpt_busfunc_t xptedtbusfunc;
819 static xpt_targetfunc_t xptedttargetfunc;
820 static xpt_devicefunc_t xptedtdevicefunc;
821 static xpt_periphfunc_t xptedtperiphfunc;
822 static xpt_pdrvfunc_t xptplistpdrvfunc;
823 static xpt_periphfunc_t xptplistperiphfunc;
824 static int xptedtmatch(struct ccb_dev_match *cdm);
825 static int xptperiphlistmatch(struct ccb_dev_match *cdm);
826 static int xptbustraverse(struct cam_eb *start_bus,
827 xpt_busfunc_t *tr_func, void *arg);
828 static int xpttargettraverse(struct cam_eb *bus,
829 struct cam_et *start_target,
830 xpt_targetfunc_t *tr_func, void *arg);
831 static int xptdevicetraverse(struct cam_et *target,
832 struct cam_ed *start_device,
833 xpt_devicefunc_t *tr_func, void *arg);
834 static int xptperiphtraverse(struct cam_ed *device,
835 struct cam_periph *start_periph,
836 xpt_periphfunc_t *tr_func, void *arg);
837 static int xptpdrvtraverse(struct periph_driver **start_pdrv,
838 xpt_pdrvfunc_t *tr_func, void *arg);
839 static int xptpdperiphtraverse(struct periph_driver **pdrv,
840 struct cam_periph *start_periph,
841 xpt_periphfunc_t *tr_func,
843 static xpt_busfunc_t xptdefbusfunc;
844 static xpt_targetfunc_t xptdeftargetfunc;
845 static xpt_devicefunc_t xptdefdevicefunc;
846 static xpt_periphfunc_t xptdefperiphfunc;
847 static int xpt_for_all_busses(xpt_busfunc_t *tr_func, void *arg);
849 static int xpt_for_all_targets(xpt_targetfunc_t *tr_func,
852 static int xpt_for_all_devices(xpt_devicefunc_t *tr_func,
855 static int xpt_for_all_periphs(xpt_periphfunc_t *tr_func,
858 static xpt_devicefunc_t xptsetasyncfunc;
859 static xpt_busfunc_t xptsetasyncbusfunc;
860 static cam_status xptregister(struct cam_periph *periph,
862 static cam_status proberegister(struct cam_periph *periph,
864 static void probeschedule(struct cam_periph *probe_periph);
865 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
866 static void proberequestdefaultnegotiation(struct cam_periph *periph);
867 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
868 static void probecleanup(struct cam_periph *periph);
869 static void xpt_find_quirk(struct cam_ed *device);
870 #ifdef CAM_NEW_TRAN_CODE
871 static void xpt_devise_transport(struct cam_path *path);
872 #endif /* CAM_NEW_TRAN_CODE */
873 static void xpt_set_transfer_settings(struct ccb_trans_settings *cts,
874 struct cam_ed *device,
876 static void xpt_toggle_tags(struct cam_path *path);
877 static void xpt_start_tags(struct cam_path *path);
878 static __inline int xpt_schedule_dev_allocq(struct cam_eb *bus,
880 static __inline int xpt_schedule_dev_sendq(struct cam_eb *bus,
882 static __inline int periph_is_queued(struct cam_periph *periph);
883 static __inline int device_is_alloc_queued(struct cam_ed *device);
884 static __inline int device_is_send_queued(struct cam_ed *device);
885 static __inline int dev_allocq_is_runnable(struct cam_devq *devq);
888 xpt_schedule_dev_allocq(struct cam_eb *bus, struct cam_ed *dev)
892 if (dev->ccbq.devq_openings > 0) {
893 if ((dev->flags & CAM_DEV_RESIZE_QUEUE_NEEDED) != 0) {
894 cam_ccbq_resize(&dev->ccbq,
895 dev->ccbq.dev_openings
896 + dev->ccbq.dev_active);
897 dev->flags &= ~CAM_DEV_RESIZE_QUEUE_NEEDED;
900 * The priority of a device waiting for CCB resources
901 * is that of the the highest priority peripheral driver
904 retval = xpt_schedule_dev(&bus->sim->devq->alloc_queue,
905 &dev->alloc_ccb_entry.pinfo,
906 CAMQ_GET_HEAD(&dev->drvq)->priority);
915 xpt_schedule_dev_sendq(struct cam_eb *bus, struct cam_ed *dev)
919 if (dev->ccbq.dev_openings > 0) {
921 * The priority of a device waiting for controller
922 * resources is that of the the highest priority CCB
926 xpt_schedule_dev(&bus->sim->devq->send_queue,
927 &dev->send_ccb_entry.pinfo,
928 CAMQ_GET_HEAD(&dev->ccbq.queue)->priority);
936 periph_is_queued(struct cam_periph *periph)
938 return (periph->pinfo.index != CAM_UNQUEUED_INDEX);
942 device_is_alloc_queued(struct cam_ed *device)
944 return (device->alloc_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);
948 device_is_send_queued(struct cam_ed *device)
950 return (device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX);
954 dev_allocq_is_runnable(struct cam_devq *devq)
958 * Have space to do more work.
959 * Allowed to do work.
961 return ((devq->alloc_queue.qfrozen_cnt == 0)
962 && (devq->alloc_queue.entries > 0)
963 && (devq->alloc_openings > 0));
969 make_dev(&xpt_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "xpt0");
979 xptdone(struct cam_periph *periph, union ccb *done_ccb)
981 /* Caller will release the CCB */
982 wakeup(&done_ccb->ccb_h.cbfcnp);
986 xptopen(struct cdev *dev, int flags, int fmt, struct thread *td)
990 unit = minor(dev) & 0xff;
993 * Only allow read-write access.
995 if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0))
999 * We don't allow nonblocking access.
1001 if ((flags & O_NONBLOCK) != 0) {
1002 printf("xpt%d: can't do nonblocking access\n", unit);
1007 * We only have one transport layer right now. If someone accesses
1008 * us via something other than minor number 1, point out their
1012 printf("xptopen: got invalid xpt unit %d\n", unit);
1016 /* Mark ourselves open */
1017 xsoftc.flags |= XPT_FLAG_OPEN;
1023 xptclose(struct cdev *dev, int flag, int fmt, struct thread *td)
1027 unit = minor(dev) & 0xff;
1030 * We only have one transport layer right now. If someone accesses
1031 * us via something other than minor number 1, point out their
1035 printf("xptclose: got invalid xpt unit %d\n", unit);
1039 /* Mark ourselves closed */
1040 xsoftc.flags &= ~XPT_FLAG_OPEN;
1046 xptioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
1051 unit = minor(dev) & 0xff;
1054 * We only have one transport layer right now. If someone accesses
1055 * us via something other than minor number 1, point out their
1059 printf("xptioctl: got invalid xpt unit %d\n", unit);
1065 * For the transport layer CAMIOCOMMAND ioctl, we really only want
1066 * to accept CCB types that don't quite make sense to send through a
1067 * passthrough driver. XPT_PATH_INQ is an exception to this, as stated
1070 case CAMIOCOMMAND: {
1074 inccb = (union ccb *)addr;
1076 switch(inccb->ccb_h.func_code) {
1079 if ((inccb->ccb_h.target_id != CAM_TARGET_WILDCARD)
1080 || (inccb->ccb_h.target_lun != CAM_LUN_WILDCARD)) {
1089 ccb = xpt_alloc_ccb();
1092 * Create a path using the bus, target, and lun the
1095 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph,
1096 inccb->ccb_h.path_id,
1097 inccb->ccb_h.target_id,
1098 inccb->ccb_h.target_lun) !=
1104 /* Ensure all of our fields are correct */
1105 xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path,
1106 inccb->ccb_h.pinfo.priority);
1107 xpt_merge_ccb(ccb, inccb);
1108 ccb->ccb_h.cbfcnp = xptdone;
1109 cam_periph_runccb(ccb, NULL, 0, 0, NULL);
1110 bcopy(ccb, inccb, sizeof(union ccb));
1111 xpt_free_path(ccb->ccb_h.path);
1119 * This is an immediate CCB, so it's okay to
1120 * allocate it on the stack.
1124 * Create a path using the bus, target, and lun the
1127 if (xpt_create_path(&ccb.ccb_h.path, xpt_periph,
1128 inccb->ccb_h.path_id,
1129 inccb->ccb_h.target_id,
1130 inccb->ccb_h.target_lun) !=
1135 /* Ensure all of our fields are correct */
1136 xpt_setup_ccb(&ccb.ccb_h, ccb.ccb_h.path,
1137 inccb->ccb_h.pinfo.priority);
1138 xpt_merge_ccb(&ccb, inccb);
1139 ccb.ccb_h.cbfcnp = xptdone;
1141 bcopy(&ccb, inccb, sizeof(union ccb));
1142 xpt_free_path(ccb.ccb_h.path);
1146 case XPT_DEV_MATCH: {
1147 struct cam_periph_map_info mapinfo;
1148 struct cam_path *old_path;
1151 * We can't deal with physical addresses for this
1152 * type of transaction.
1154 if (inccb->ccb_h.flags & CAM_DATA_PHYS) {
1160 * Save this in case the caller had it set to
1161 * something in particular.
1163 old_path = inccb->ccb_h.path;
1166 * We really don't need a path for the matching
1167 * code. The path is needed because of the
1168 * debugging statements in xpt_action(). They
1169 * assume that the CCB has a valid path.
1171 inccb->ccb_h.path = xpt_periph->path;
1173 bzero(&mapinfo, sizeof(mapinfo));
1176 * Map the pattern and match buffers into kernel
1177 * virtual address space.
1179 error = cam_periph_mapmem(inccb, &mapinfo);
1182 inccb->ccb_h.path = old_path;
1187 * This is an immediate CCB, we can send it on directly.
1192 * Map the buffers back into user space.
1194 cam_periph_unmapmem(inccb, &mapinfo);
1196 inccb->ccb_h.path = old_path;
1208 * This is the getpassthru ioctl. It takes a XPT_GDEVLIST ccb as input,
1209 * with the periphal driver name and unit name filled in. The other
1210 * fields don't really matter as input. The passthrough driver name
1211 * ("pass"), and unit number are passed back in the ccb. The current
1212 * device generation number, and the index into the device peripheral
1213 * driver list, and the status are also passed back. Note that
1214 * since we do everything in one pass, unlike the XPT_GDEVLIST ccb,
1215 * we never return a status of CAM_GDEVLIST_LIST_CHANGED. It is
1216 * (or rather should be) impossible for the device peripheral driver
1217 * list to change since we look at the whole thing in one pass, and
1218 * we do it with splcam protection.
1221 case CAMGETPASSTHRU: {
1223 struct cam_periph *periph;
1224 struct periph_driver **p_drv;
1227 u_int cur_generation;
1228 int base_periph_found;
1232 ccb = (union ccb *)addr;
1233 unit = ccb->cgdl.unit_number;
1234 name = ccb->cgdl.periph_name;
1236 * Every 100 devices, we want to drop our spl protection to
1237 * give the software interrupt handler a chance to run.
1238 * Most systems won't run into this check, but this should
1239 * avoid starvation in the software interrupt handler in
1244 ccb = (union ccb *)addr;
1246 base_periph_found = 0;
1249 * Sanity check -- make sure we don't get a null peripheral
1252 if (*ccb->cgdl.periph_name == '\0') {
1257 /* Keep the list from changing while we traverse it */
1260 cur_generation = xsoftc.generation;
1262 /* first find our driver in the list of drivers */
1263 for (p_drv = periph_drivers; *p_drv != NULL; p_drv++)
1264 if (strcmp((*p_drv)->driver_name, name) == 0)
1267 if (*p_drv == NULL) {
1269 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1270 ccb->cgdl.status = CAM_GDEVLIST_ERROR;
1271 *ccb->cgdl.periph_name = '\0';
1272 ccb->cgdl.unit_number = 0;
1278 * Run through every peripheral instance of this driver
1279 * and check to see whether it matches the unit passed
1280 * in by the user. If it does, get out of the loops and
1281 * find the passthrough driver associated with that
1282 * peripheral driver.
1284 for (periph = TAILQ_FIRST(&(*p_drv)->units); periph != NULL;
1285 periph = TAILQ_NEXT(periph, unit_links)) {
1287 if (periph->unit_number == unit) {
1289 } else if (--splbreaknum == 0) {
1293 if (cur_generation != xsoftc.generation)
1298 * If we found the peripheral driver that the user passed
1299 * in, go through all of the peripheral drivers for that
1300 * particular device and look for a passthrough driver.
1302 if (periph != NULL) {
1303 struct cam_ed *device;
1306 base_periph_found = 1;
1307 device = periph->path->device;
1308 for (i = 0, periph = SLIST_FIRST(&device->periphs);
1310 periph = SLIST_NEXT(periph, periph_links), i++) {
1312 * Check to see whether we have a
1313 * passthrough device or not.
1315 if (strcmp(periph->periph_name, "pass") == 0) {
1317 * Fill in the getdevlist fields.
1319 strcpy(ccb->cgdl.periph_name,
1320 periph->periph_name);
1321 ccb->cgdl.unit_number =
1322 periph->unit_number;
1323 if (SLIST_NEXT(periph, periph_links))
1325 CAM_GDEVLIST_MORE_DEVS;
1328 CAM_GDEVLIST_LAST_DEVICE;
1329 ccb->cgdl.generation =
1331 ccb->cgdl.index = i;
1333 * Fill in some CCB header fields
1334 * that the user may want.
1336 ccb->ccb_h.path_id =
1337 periph->path->bus->path_id;
1338 ccb->ccb_h.target_id =
1339 periph->path->target->target_id;
1340 ccb->ccb_h.target_lun =
1341 periph->path->device->lun_id;
1342 ccb->ccb_h.status = CAM_REQ_CMP;
1349 * If the periph is null here, one of two things has
1350 * happened. The first possibility is that we couldn't
1351 * find the unit number of the particular peripheral driver
1352 * that the user is asking about. e.g. the user asks for
1353 * the passthrough driver for "da11". We find the list of
1354 * "da" peripherals all right, but there is no unit 11.
1355 * The other possibility is that we went through the list
1356 * of peripheral drivers attached to the device structure,
1357 * but didn't find one with the name "pass". Either way,
1358 * we return ENOENT, since we couldn't find something.
1360 if (periph == NULL) {
1361 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1362 ccb->cgdl.status = CAM_GDEVLIST_ERROR;
1363 *ccb->cgdl.periph_name = '\0';
1364 ccb->cgdl.unit_number = 0;
1367 * It is unfortunate that this is even necessary,
1368 * but there are many, many clueless users out there.
1369 * If this is true, the user is looking for the
1370 * passthrough driver, but doesn't have one in his
1373 if (base_periph_found == 1) {
1374 printf("xptioctl: pass driver is not in the "
1376 printf("xptioctl: put \"device pass0\" in "
1377 "your kernel config file\n");
1392 cam_module_event_handler(module_t mod, int what, void *arg)
1394 if (what == MOD_LOAD) {
1396 } else if (what == MOD_UNLOAD) {
1405 /* Functions accessed by the peripheral drivers */
1410 struct cam_sim *xpt_sim;
1411 struct cam_path *path;
1412 struct cam_devq *devq;
1415 TAILQ_INIT(&xpt_busses);
1416 TAILQ_INIT(&cam_bioq);
1417 SLIST_INIT(&ccb_freeq);
1418 STAILQ_INIT(&highpowerq);
1420 mtx_init(&cam_bioq_lock, "CAM BIOQ lock", NULL, MTX_DEF);
1423 * The xpt layer is, itself, the equivelent of a SIM.
1424 * Allow 16 ccbs in the ccb pool for it. This should
1425 * give decent parallelism when we probe busses and
1426 * perform other XPT functions.
1428 devq = cam_simq_alloc(16);
1429 xpt_sim = cam_sim_alloc(xptaction,
1434 /*max_dev_transactions*/0,
1435 /*max_tagged_dev_transactions*/0,
1439 xpt_bus_register(xpt_sim, /*bus #*/0);
1442 * Looking at the XPT from the SIM layer, the XPT is
1443 * the equivelent of a peripheral driver. Allocate
1444 * a peripheral driver entry for us.
1446 if ((status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
1447 CAM_TARGET_WILDCARD,
1448 CAM_LUN_WILDCARD)) != CAM_REQ_CMP) {
1449 printf("xpt_init: xpt_create_path failed with status %#x,"
1450 " failing attach\n", status);
1454 cam_periph_alloc(xptregister, NULL, NULL, NULL, "xpt", CAM_PERIPH_BIO,
1455 path, NULL, 0, NULL);
1456 xpt_free_path(path);
1458 xpt_sim->softc = xpt_periph;
1461 * Register a callback for when interrupts are enabled.
1464 (struct intr_config_hook *)malloc(sizeof(struct intr_config_hook),
1465 M_TEMP, M_NOWAIT | M_ZERO);
1466 if (xpt_config_hook == NULL) {
1467 printf("xpt_init: Cannot malloc config hook "
1468 "- failing attach\n");
1472 xpt_config_hook->ich_func = xpt_config;
1473 if (config_intrhook_establish(xpt_config_hook) != 0) {
1474 free (xpt_config_hook, M_TEMP);
1475 printf("xpt_init: config_intrhook_establish failed "
1476 "- failing attach\n");
1479 /* Install our software interrupt handlers */
1480 swi_add(NULL, "cambio", camisr, &cam_bioq, SWI_CAMBIO, 0, &cambio_ih);
1484 xptregister(struct cam_periph *periph, void *arg)
1486 if (periph == NULL) {
1487 printf("xptregister: periph was NULL!!\n");
1488 return(CAM_REQ_CMP_ERR);
1491 periph->softc = NULL;
1493 xpt_periph = periph;
1495 return(CAM_REQ_CMP);
1499 xpt_add_periph(struct cam_periph *periph)
1501 struct cam_ed *device;
1503 struct periph_list *periph_head;
1507 device = periph->path->device;
1509 periph_head = &device->periphs;
1511 status = CAM_REQ_CMP;
1513 if (device != NULL) {
1517 * Make room for this peripheral
1518 * so it will fit in the queue
1519 * when it's scheduled to run
1522 status = camq_resize(&device->drvq,
1523 device->drvq.array_size + 1);
1525 device->generation++;
1527 SLIST_INSERT_HEAD(periph_head, periph, periph_links);
1532 xsoftc.generation++;
1538 xpt_remove_periph(struct cam_periph *periph)
1540 struct cam_ed *device;
1544 device = periph->path->device;
1546 if (device != NULL) {
1548 struct periph_list *periph_head;
1550 periph_head = &device->periphs;
1552 /* Release the slot for this peripheral */
1554 camq_resize(&device->drvq, device->drvq.array_size - 1);
1556 device->generation++;
1558 SLIST_REMOVE(periph_head, periph, cam_periph, periph_links);
1563 xsoftc.generation++;
1567 #ifdef CAM_NEW_TRAN_CODE
1570 xpt_announce_periph(struct cam_periph *periph, char *announce_string)
1572 struct ccb_pathinq cpi;
1573 struct ccb_trans_settings cts;
1574 struct cam_path *path;
1582 path = periph->path;
1584 * To ensure that this is printed in one piece,
1585 * mask out CAM interrupts.
1588 printf("%s%d at %s%d bus %d target %d lun %d\n",
1589 periph->periph_name, periph->unit_number,
1590 path->bus->sim->sim_name,
1591 path->bus->sim->unit_number,
1592 path->bus->sim->bus_id,
1593 path->target->target_id,
1594 path->device->lun_id);
1595 printf("%s%d: ", periph->periph_name, periph->unit_number);
1596 scsi_print_inquiry(&path->device->inq_data);
1597 if (bootverbose && path->device->serial_num_len > 0) {
1598 /* Don't wrap the screen - print only the first 60 chars */
1599 printf("%s%d: Serial Number %.60s\n", periph->periph_name,
1600 periph->unit_number, path->device->serial_num);
1602 xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
1603 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1604 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1605 xpt_action((union ccb*)&cts);
1607 /* Ask the SIM for its base transfer speed */
1608 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
1609 cpi.ccb_h.func_code = XPT_PATH_INQ;
1610 xpt_action((union ccb *)&cpi);
1612 speed = cpi.base_transfer_speed;
1614 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
1615 struct ccb_trans_settings_spi *spi;
1617 spi = &cts.xport_specific.spi;
1618 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
1619 && spi->sync_offset != 0) {
1620 freq = scsi_calc_syncsrate(spi->sync_period);
1624 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
1625 speed *= (0x01 << spi->bus_width);
1628 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
1629 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1630 if (fc->valid & CTS_FC_VALID_SPEED) {
1631 speed = fc->bitrate;
1635 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
1636 struct ccb_trans_settings_sas *sas = &cts.xport_specific.sas;
1637 if (sas->valid & CTS_SAS_VALID_SPEED) {
1638 speed = sas->bitrate;
1644 printf("%s%d: %d.%03dMB/s transfers",
1645 periph->periph_name, periph->unit_number,
1648 printf("%s%d: %dKB/s transfers", periph->periph_name,
1649 periph->unit_number, speed);
1650 /* Report additional information about SPI connections */
1651 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
1652 struct ccb_trans_settings_spi *spi;
1654 spi = &cts.xport_specific.spi;
1656 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
1658 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
1662 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
1663 && spi->bus_width > 0) {
1669 printf("%dbit)", 8 * (0x01 << spi->bus_width));
1670 } else if (freq != 0) {
1674 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
1675 struct ccb_trans_settings_fc *fc;
1677 fc = &cts.xport_specific.fc;
1678 if (fc->valid & CTS_FC_VALID_WWNN)
1679 printf(" WWNN 0x%llx", (long long) fc->wwnn);
1680 if (fc->valid & CTS_FC_VALID_WWPN)
1681 printf(" WWPN 0x%llx", (long long) fc->wwpn);
1682 if (fc->valid & CTS_FC_VALID_PORT)
1683 printf(" PortID 0x%x", fc->port);
1686 if (path->device->inq_flags & SID_CmdQue
1687 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
1688 printf("\n%s%d: Tagged Queueing Enabled",
1689 periph->periph_name, periph->unit_number);
1694 * We only want to print the caller's announce string if they've
1697 if (announce_string != NULL)
1698 printf("%s%d: %s\n", periph->periph_name,
1699 periph->unit_number, announce_string);
1702 #else /* CAM_NEW_TRAN_CODE */
1704 xpt_announce_periph(struct cam_periph *periph, char *announce_string)
1708 struct cam_path *path;
1709 struct ccb_trans_settings cts;
1713 path = periph->path;
1715 * To ensure that this is printed in one piece,
1716 * mask out CAM interrupts.
1719 printf("%s%d at %s%d bus %d target %d lun %d\n",
1720 periph->periph_name, periph->unit_number,
1721 path->bus->sim->sim_name,
1722 path->bus->sim->unit_number,
1723 path->bus->sim->bus_id,
1724 path->target->target_id,
1725 path->device->lun_id);
1726 printf("%s%d: ", periph->periph_name, periph->unit_number);
1727 scsi_print_inquiry(&path->device->inq_data);
1729 && (path->device->serial_num_len > 0)) {
1730 /* Don't wrap the screen - print only the first 60 chars */
1731 printf("%s%d: Serial Number %.60s\n", periph->periph_name,
1732 periph->unit_number, path->device->serial_num);
1734 xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
1735 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1736 cts.flags = CCB_TRANS_CURRENT_SETTINGS;
1737 xpt_action((union ccb*)&cts);
1738 if (cts.ccb_h.status == CAM_REQ_CMP) {
1742 if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1743 && cts.sync_offset != 0) {
1744 freq = scsi_calc_syncsrate(cts.sync_period);
1747 struct ccb_pathinq cpi;
1749 /* Ask the SIM for its base transfer speed */
1750 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
1751 cpi.ccb_h.func_code = XPT_PATH_INQ;
1752 xpt_action((union ccb *)&cpi);
1754 speed = cpi.base_transfer_speed;
1757 if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0)
1758 speed *= (0x01 << cts.bus_width);
1761 printf("%s%d: %d.%03dMB/s transfers",
1762 periph->periph_name, periph->unit_number,
1765 printf("%s%d: %dKB/s transfers", periph->periph_name,
1766 periph->unit_number, speed);
1767 if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1768 && cts.sync_offset != 0) {
1769 printf(" (%d.%03dMHz, offset %d", freq / 1000,
1770 freq % 1000, cts.sync_offset);
1772 if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0
1773 && cts.bus_width > 0) {
1774 if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1775 && cts.sync_offset != 0) {
1780 printf("%dbit)", 8 * (0x01 << cts.bus_width));
1781 } else if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0
1782 && cts.sync_offset != 0) {
1786 if (path->device->inq_flags & SID_CmdQue
1787 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
1788 printf(", Tagged Queueing Enabled");
1792 } else if (path->device->inq_flags & SID_CmdQue
1793 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
1794 printf("%s%d: Tagged Queueing Enabled\n",
1795 periph->periph_name, periph->unit_number);
1799 * We only want to print the caller's announce string if they've
1802 if (announce_string != NULL)
1803 printf("%s%d: %s\n", periph->periph_name,
1804 periph->unit_number, announce_string);
1808 #endif /* CAM_NEW_TRAN_CODE */
1810 static dev_match_ret
1811 xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns,
1814 dev_match_ret retval;
1817 retval = DM_RET_NONE;
1820 * If we aren't given something to match against, that's an error.
1823 return(DM_RET_ERROR);
1826 * If there are no match entries, then this bus matches no
1829 if ((patterns == NULL) || (num_patterns == 0))
1830 return(DM_RET_DESCEND | DM_RET_COPY);
1832 for (i = 0; i < num_patterns; i++) {
1833 struct bus_match_pattern *cur_pattern;
1836 * If the pattern in question isn't for a bus node, we
1837 * aren't interested. However, we do indicate to the
1838 * calling routine that we should continue descending the
1839 * tree, since the user wants to match against lower-level
1842 if (patterns[i].type != DEV_MATCH_BUS) {
1843 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
1844 retval |= DM_RET_DESCEND;
1848 cur_pattern = &patterns[i].pattern.bus_pattern;
1851 * If they want to match any bus node, we give them any
1854 if (cur_pattern->flags == BUS_MATCH_ANY) {
1855 /* set the copy flag */
1856 retval |= DM_RET_COPY;
1859 * If we've already decided on an action, go ahead
1862 if ((retval & DM_RET_ACTION_MASK) != DM_RET_NONE)
1867 * Not sure why someone would do this...
1869 if (cur_pattern->flags == BUS_MATCH_NONE)
1872 if (((cur_pattern->flags & BUS_MATCH_PATH) != 0)
1873 && (cur_pattern->path_id != bus->path_id))
1876 if (((cur_pattern->flags & BUS_MATCH_BUS_ID) != 0)
1877 && (cur_pattern->bus_id != bus->sim->bus_id))
1880 if (((cur_pattern->flags & BUS_MATCH_UNIT) != 0)
1881 && (cur_pattern->unit_number != bus->sim->unit_number))
1884 if (((cur_pattern->flags & BUS_MATCH_NAME) != 0)
1885 && (strncmp(cur_pattern->dev_name, bus->sim->sim_name,
1890 * If we get to this point, the user definitely wants
1891 * information on this bus. So tell the caller to copy the
1894 retval |= DM_RET_COPY;
1897 * If the return action has been set to descend, then we
1898 * know that we've already seen a non-bus matching
1899 * expression, therefore we need to further descend the tree.
1900 * This won't change by continuing around the loop, so we
1901 * go ahead and return. If we haven't seen a non-bus
1902 * matching expression, we keep going around the loop until
1903 * we exhaust the matching expressions. We'll set the stop
1904 * flag once we fall out of the loop.
1906 if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)
1911 * If the return action hasn't been set to descend yet, that means
1912 * we haven't seen anything other than bus matching patterns. So
1913 * tell the caller to stop descending the tree -- the user doesn't
1914 * want to match against lower level tree elements.
1916 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
1917 retval |= DM_RET_STOP;
1922 static dev_match_ret
1923 xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns,
1924 struct cam_ed *device)
1926 dev_match_ret retval;
1929 retval = DM_RET_NONE;
1932 * If we aren't given something to match against, that's an error.
1935 return(DM_RET_ERROR);
1938 * If there are no match entries, then this device matches no
1941 if ((patterns == NULL) || (num_patterns == 0))
1942 return(DM_RET_DESCEND | DM_RET_COPY);
1944 for (i = 0; i < num_patterns; i++) {
1945 struct device_match_pattern *cur_pattern;
1948 * If the pattern in question isn't for a device node, we
1949 * aren't interested.
1951 if (patterns[i].type != DEV_MATCH_DEVICE) {
1952 if ((patterns[i].type == DEV_MATCH_PERIPH)
1953 && ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE))
1954 retval |= DM_RET_DESCEND;
1958 cur_pattern = &patterns[i].pattern.device_pattern;
1961 * If they want to match any device node, we give them any
1964 if (cur_pattern->flags == DEV_MATCH_ANY) {
1965 /* set the copy flag */
1966 retval |= DM_RET_COPY;
1970 * If we've already decided on an action, go ahead
1973 if ((retval & DM_RET_ACTION_MASK) != DM_RET_NONE)
1978 * Not sure why someone would do this...
1980 if (cur_pattern->flags == DEV_MATCH_NONE)
1983 if (((cur_pattern->flags & DEV_MATCH_PATH) != 0)
1984 && (cur_pattern->path_id != device->target->bus->path_id))
1987 if (((cur_pattern->flags & DEV_MATCH_TARGET) != 0)
1988 && (cur_pattern->target_id != device->target->target_id))
1991 if (((cur_pattern->flags & DEV_MATCH_LUN) != 0)
1992 && (cur_pattern->target_lun != device->lun_id))
1995 if (((cur_pattern->flags & DEV_MATCH_INQUIRY) != 0)
1996 && (cam_quirkmatch((caddr_t)&device->inq_data,
1997 (caddr_t)&cur_pattern->inq_pat,
1998 1, sizeof(cur_pattern->inq_pat),
1999 scsi_static_inquiry_match) == NULL))
2003 * If we get to this point, the user definitely wants
2004 * information on this device. So tell the caller to copy
2007 retval |= DM_RET_COPY;
2010 * If the return action has been set to descend, then we
2011 * know that we've already seen a peripheral matching
2012 * expression, therefore we need to further descend the tree.
2013 * This won't change by continuing around the loop, so we
2014 * go ahead and return. If we haven't seen a peripheral
2015 * matching expression, we keep going around the loop until
2016 * we exhaust the matching expressions. We'll set the stop
2017 * flag once we fall out of the loop.
2019 if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)
2024 * If the return action hasn't been set to descend yet, that means
2025 * we haven't seen any peripheral matching patterns. So tell the
2026 * caller to stop descending the tree -- the user doesn't want to
2027 * match against lower level tree elements.
2029 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
2030 retval |= DM_RET_STOP;
2036 * Match a single peripheral against any number of match patterns.
2038 static dev_match_ret
2039 xptperiphmatch(struct dev_match_pattern *patterns, u_int num_patterns,
2040 struct cam_periph *periph)
2042 dev_match_ret retval;
2046 * If we aren't given something to match against, that's an error.
2049 return(DM_RET_ERROR);
2052 * If there are no match entries, then this peripheral matches no
2055 if ((patterns == NULL) || (num_patterns == 0))
2056 return(DM_RET_STOP | DM_RET_COPY);
2059 * There aren't any nodes below a peripheral node, so there's no
2060 * reason to descend the tree any further.
2062 retval = DM_RET_STOP;
2064 for (i = 0; i < num_patterns; i++) {
2065 struct periph_match_pattern *cur_pattern;
2068 * If the pattern in question isn't for a peripheral, we
2069 * aren't interested.
2071 if (patterns[i].type != DEV_MATCH_PERIPH)
2074 cur_pattern = &patterns[i].pattern.periph_pattern;
2077 * If they want to match on anything, then we will do so.
2079 if (cur_pattern->flags == PERIPH_MATCH_ANY) {
2080 /* set the copy flag */
2081 retval |= DM_RET_COPY;
2084 * We've already set the return action to stop,
2085 * since there are no nodes below peripherals in
2092 * Not sure why someone would do this...
2094 if (cur_pattern->flags == PERIPH_MATCH_NONE)
2097 if (((cur_pattern->flags & PERIPH_MATCH_PATH) != 0)
2098 && (cur_pattern->path_id != periph->path->bus->path_id))
2102 * For the target and lun id's, we have to make sure the
2103 * target and lun pointers aren't NULL. The xpt peripheral
2104 * has a wildcard target and device.
2106 if (((cur_pattern->flags & PERIPH_MATCH_TARGET) != 0)
2107 && ((periph->path->target == NULL)
2108 ||(cur_pattern->target_id != periph->path->target->target_id)))
2111 if (((cur_pattern->flags & PERIPH_MATCH_LUN) != 0)
2112 && ((periph->path->device == NULL)
2113 || (cur_pattern->target_lun != periph->path->device->lun_id)))
2116 if (((cur_pattern->flags & PERIPH_MATCH_UNIT) != 0)
2117 && (cur_pattern->unit_number != periph->unit_number))
2120 if (((cur_pattern->flags & PERIPH_MATCH_NAME) != 0)
2121 && (strncmp(cur_pattern->periph_name, periph->periph_name,
2126 * If we get to this point, the user definitely wants
2127 * information on this peripheral. So tell the caller to
2128 * copy the data out.
2130 retval |= DM_RET_COPY;
2133 * The return action has already been set to stop, since
2134 * peripherals don't have any nodes below them in the EDT.
2140 * If we get to this point, the peripheral that was passed in
2141 * doesn't match any of the patterns.
2147 xptedtbusfunc(struct cam_eb *bus, void *arg)
2149 struct ccb_dev_match *cdm;
2150 dev_match_ret retval;
2152 cdm = (struct ccb_dev_match *)arg;
2155 * If our position is for something deeper in the tree, that means
2156 * that we've already seen this node. So, we keep going down.
2158 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2159 && (cdm->pos.cookie.bus == bus)
2160 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2161 && (cdm->pos.cookie.target != NULL))
2162 retval = DM_RET_DESCEND;
2164 retval = xptbusmatch(cdm->patterns, cdm->num_patterns, bus);
2167 * If we got an error, bail out of the search.
2169 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
2170 cdm->status = CAM_DEV_MATCH_ERROR;
2175 * If the copy flag is set, copy this bus out.
2177 if (retval & DM_RET_COPY) {
2180 spaceleft = cdm->match_buf_len - (cdm->num_matches *
2181 sizeof(struct dev_match_result));
2184 * If we don't have enough space to put in another
2185 * match result, save our position and tell the
2186 * user there are more devices to check.
2188 if (spaceleft < sizeof(struct dev_match_result)) {
2189 bzero(&cdm->pos, sizeof(cdm->pos));
2190 cdm->pos.position_type =
2191 CAM_DEV_POS_EDT | CAM_DEV_POS_BUS;
2193 cdm->pos.cookie.bus = bus;
2194 cdm->pos.generations[CAM_BUS_GENERATION]=
2196 cdm->status = CAM_DEV_MATCH_MORE;
2199 j = cdm->num_matches;
2201 cdm->matches[j].type = DEV_MATCH_BUS;
2202 cdm->matches[j].result.bus_result.path_id = bus->path_id;
2203 cdm->matches[j].result.bus_result.bus_id = bus->sim->bus_id;
2204 cdm->matches[j].result.bus_result.unit_number =
2205 bus->sim->unit_number;
2206 strncpy(cdm->matches[j].result.bus_result.dev_name,
2207 bus->sim->sim_name, DEV_IDLEN);
2211 * If the user is only interested in busses, there's no
2212 * reason to descend to the next level in the tree.
2214 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
2218 * If there is a target generation recorded, check it to
2219 * make sure the target list hasn't changed.
2221 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2222 && (bus == cdm->pos.cookie.bus)
2223 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2224 && (cdm->pos.generations[CAM_TARGET_GENERATION] != 0)
2225 && (cdm->pos.generations[CAM_TARGET_GENERATION] !=
2227 cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
2231 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2232 && (cdm->pos.cookie.bus == bus)
2233 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2234 && (cdm->pos.cookie.target != NULL))
2235 return(xpttargettraverse(bus,
2236 (struct cam_et *)cdm->pos.cookie.target,
2237 xptedttargetfunc, arg));
2239 return(xpttargettraverse(bus, NULL, xptedttargetfunc, arg));
2243 xptedttargetfunc(struct cam_et *target, void *arg)
2245 struct ccb_dev_match *cdm;
2247 cdm = (struct ccb_dev_match *)arg;
2250 * If there is a device list generation recorded, check it to
2251 * make sure the device list hasn't changed.
2253 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2254 && (cdm->pos.cookie.bus == target->bus)
2255 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2256 && (cdm->pos.cookie.target == target)
2257 && (cdm->pos.position_type & CAM_DEV_POS_DEVICE)
2258 && (cdm->pos.generations[CAM_DEV_GENERATION] != 0)
2259 && (cdm->pos.generations[CAM_DEV_GENERATION] !=
2260 target->generation)) {
2261 cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
2265 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2266 && (cdm->pos.cookie.bus == target->bus)
2267 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2268 && (cdm->pos.cookie.target == target)
2269 && (cdm->pos.position_type & CAM_DEV_POS_DEVICE)
2270 && (cdm->pos.cookie.device != NULL))
2271 return(xptdevicetraverse(target,
2272 (struct cam_ed *)cdm->pos.cookie.device,
2273 xptedtdevicefunc, arg));
2275 return(xptdevicetraverse(target, NULL, xptedtdevicefunc, arg));
2279 xptedtdevicefunc(struct cam_ed *device, void *arg)
2282 struct ccb_dev_match *cdm;
2283 dev_match_ret retval;
2285 cdm = (struct ccb_dev_match *)arg;
2288 * If our position is for something deeper in the tree, that means
2289 * that we've already seen this node. So, we keep going down.
2291 if ((cdm->pos.position_type & CAM_DEV_POS_DEVICE)
2292 && (cdm->pos.cookie.device == device)
2293 && (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
2294 && (cdm->pos.cookie.periph != NULL))
2295 retval = DM_RET_DESCEND;
2297 retval = xptdevicematch(cdm->patterns, cdm->num_patterns,
2300 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
2301 cdm->status = CAM_DEV_MATCH_ERROR;
2306 * If the copy flag is set, copy this device out.
2308 if (retval & DM_RET_COPY) {
2311 spaceleft = cdm->match_buf_len - (cdm->num_matches *
2312 sizeof(struct dev_match_result));
2315 * If we don't have enough space to put in another
2316 * match result, save our position and tell the
2317 * user there are more devices to check.
2319 if (spaceleft < sizeof(struct dev_match_result)) {
2320 bzero(&cdm->pos, sizeof(cdm->pos));
2321 cdm->pos.position_type =
2322 CAM_DEV_POS_EDT | CAM_DEV_POS_BUS |
2323 CAM_DEV_POS_TARGET | CAM_DEV_POS_DEVICE;
2325 cdm->pos.cookie.bus = device->target->bus;
2326 cdm->pos.generations[CAM_BUS_GENERATION]=
2328 cdm->pos.cookie.target = device->target;
2329 cdm->pos.generations[CAM_TARGET_GENERATION] =
2330 device->target->bus->generation;
2331 cdm->pos.cookie.device = device;
2332 cdm->pos.generations[CAM_DEV_GENERATION] =
2333 device->target->generation;
2334 cdm->status = CAM_DEV_MATCH_MORE;
2337 j = cdm->num_matches;
2339 cdm->matches[j].type = DEV_MATCH_DEVICE;
2340 cdm->matches[j].result.device_result.path_id =
2341 device->target->bus->path_id;
2342 cdm->matches[j].result.device_result.target_id =
2343 device->target->target_id;
2344 cdm->matches[j].result.device_result.target_lun =
2346 bcopy(&device->inq_data,
2347 &cdm->matches[j].result.device_result.inq_data,
2348 sizeof(struct scsi_inquiry_data));
2350 /* Let the user know whether this device is unconfigured */
2351 if (device->flags & CAM_DEV_UNCONFIGURED)
2352 cdm->matches[j].result.device_result.flags =
2353 DEV_RESULT_UNCONFIGURED;
2355 cdm->matches[j].result.device_result.flags =
2360 * If the user isn't interested in peripherals, don't descend
2361 * the tree any further.
2363 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
2367 * If there is a peripheral list generation recorded, make sure
2368 * it hasn't changed.
2370 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2371 && (device->target->bus == cdm->pos.cookie.bus)
2372 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2373 && (device->target == cdm->pos.cookie.target)
2374 && (cdm->pos.position_type & CAM_DEV_POS_DEVICE)
2375 && (device == cdm->pos.cookie.device)
2376 && (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
2377 && (cdm->pos.generations[CAM_PERIPH_GENERATION] != 0)
2378 && (cdm->pos.generations[CAM_PERIPH_GENERATION] !=
2379 device->generation)){
2380 cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
2384 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2385 && (cdm->pos.cookie.bus == device->target->bus)
2386 && (cdm->pos.position_type & CAM_DEV_POS_TARGET)
2387 && (cdm->pos.cookie.target == device->target)
2388 && (cdm->pos.position_type & CAM_DEV_POS_DEVICE)
2389 && (cdm->pos.cookie.device == device)
2390 && (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
2391 && (cdm->pos.cookie.periph != NULL))
2392 return(xptperiphtraverse(device,
2393 (struct cam_periph *)cdm->pos.cookie.periph,
2394 xptedtperiphfunc, arg));
2396 return(xptperiphtraverse(device, NULL, xptedtperiphfunc, arg));
2400 xptedtperiphfunc(struct cam_periph *periph, void *arg)
2402 struct ccb_dev_match *cdm;
2403 dev_match_ret retval;
2405 cdm = (struct ccb_dev_match *)arg;
2407 retval = xptperiphmatch(cdm->patterns, cdm->num_patterns, periph);
2409 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
2410 cdm->status = CAM_DEV_MATCH_ERROR;
2415 * If the copy flag is set, copy this peripheral out.
2417 if (retval & DM_RET_COPY) {
2420 spaceleft = cdm->match_buf_len - (cdm->num_matches *
2421 sizeof(struct dev_match_result));
2424 * If we don't have enough space to put in another
2425 * match result, save our position and tell the
2426 * user there are more devices to check.
2428 if (spaceleft < sizeof(struct dev_match_result)) {
2429 bzero(&cdm->pos, sizeof(cdm->pos));
2430 cdm->pos.position_type =
2431 CAM_DEV_POS_EDT | CAM_DEV_POS_BUS |
2432 CAM_DEV_POS_TARGET | CAM_DEV_POS_DEVICE |
2435 cdm->pos.cookie.bus = periph->path->bus;
2436 cdm->pos.generations[CAM_BUS_GENERATION]=
2438 cdm->pos.cookie.target = periph->path->target;
2439 cdm->pos.generations[CAM_TARGET_GENERATION] =
2440 periph->path->bus->generation;
2441 cdm->pos.cookie.device = periph->path->device;
2442 cdm->pos.generations[CAM_DEV_GENERATION] =
2443 periph->path->target->generation;
2444 cdm->pos.cookie.periph = periph;
2445 cdm->pos.generations[CAM_PERIPH_GENERATION] =
2446 periph->path->device->generation;
2447 cdm->status = CAM_DEV_MATCH_MORE;
2451 j = cdm->num_matches;
2453 cdm->matches[j].type = DEV_MATCH_PERIPH;
2454 cdm->matches[j].result.periph_result.path_id =
2455 periph->path->bus->path_id;
2456 cdm->matches[j].result.periph_result.target_id =
2457 periph->path->target->target_id;
2458 cdm->matches[j].result.periph_result.target_lun =
2459 periph->path->device->lun_id;
2460 cdm->matches[j].result.periph_result.unit_number =
2461 periph->unit_number;
2462 strncpy(cdm->matches[j].result.periph_result.periph_name,
2463 periph->periph_name, DEV_IDLEN);
2470 xptedtmatch(struct ccb_dev_match *cdm)
2474 cdm->num_matches = 0;
2477 * Check the bus list generation. If it has changed, the user
2478 * needs to reset everything and start over.
2480 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2481 && (cdm->pos.generations[CAM_BUS_GENERATION] != 0)
2482 && (cdm->pos.generations[CAM_BUS_GENERATION] != bus_generation)) {
2483 cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
2487 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2488 && (cdm->pos.cookie.bus != NULL))
2489 ret = xptbustraverse((struct cam_eb *)cdm->pos.cookie.bus,
2490 xptedtbusfunc, cdm);
2492 ret = xptbustraverse(NULL, xptedtbusfunc, cdm);
2495 * If we get back 0, that means that we had to stop before fully
2496 * traversing the EDT. It also means that one of the subroutines
2497 * has set the status field to the proper value. If we get back 1,
2498 * we've fully traversed the EDT and copied out any matching entries.
2501 cdm->status = CAM_DEV_MATCH_LAST;
2507 xptplistpdrvfunc(struct periph_driver **pdrv, void *arg)
2509 struct ccb_dev_match *cdm;
2511 cdm = (struct ccb_dev_match *)arg;
2513 if ((cdm->pos.position_type & CAM_DEV_POS_PDPTR)
2514 && (cdm->pos.cookie.pdrv == pdrv)
2515 && (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
2516 && (cdm->pos.generations[CAM_PERIPH_GENERATION] != 0)
2517 && (cdm->pos.generations[CAM_PERIPH_GENERATION] !=
2518 (*pdrv)->generation)) {
2519 cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
2523 if ((cdm->pos.position_type & CAM_DEV_POS_PDPTR)
2524 && (cdm->pos.cookie.pdrv == pdrv)
2525 && (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
2526 && (cdm->pos.cookie.periph != NULL))
2527 return(xptpdperiphtraverse(pdrv,
2528 (struct cam_periph *)cdm->pos.cookie.periph,
2529 xptplistperiphfunc, arg));
2531 return(xptpdperiphtraverse(pdrv, NULL,xptplistperiphfunc, arg));
2535 xptplistperiphfunc(struct cam_periph *periph, void *arg)
2537 struct ccb_dev_match *cdm;
2538 dev_match_ret retval;
2540 cdm = (struct ccb_dev_match *)arg;
2542 retval = xptperiphmatch(cdm->patterns, cdm->num_patterns, periph);
2544 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
2545 cdm->status = CAM_DEV_MATCH_ERROR;
2550 * If the copy flag is set, copy this peripheral out.
2552 if (retval & DM_RET_COPY) {
2555 spaceleft = cdm->match_buf_len - (cdm->num_matches *
2556 sizeof(struct dev_match_result));
2559 * If we don't have enough space to put in another
2560 * match result, save our position and tell the
2561 * user there are more devices to check.
2563 if (spaceleft < sizeof(struct dev_match_result)) {
2564 struct periph_driver **pdrv;
2567 bzero(&cdm->pos, sizeof(cdm->pos));
2568 cdm->pos.position_type =
2569 CAM_DEV_POS_PDRV | CAM_DEV_POS_PDPTR |
2573 * This may look a bit non-sensical, but it is
2574 * actually quite logical. There are very few
2575 * peripheral drivers, and bloating every peripheral
2576 * structure with a pointer back to its parent
2577 * peripheral driver linker set entry would cost
2578 * more in the long run than doing this quick lookup.
2580 for (pdrv = periph_drivers; *pdrv != NULL; pdrv++) {
2581 if (strcmp((*pdrv)->driver_name,
2582 periph->periph_name) == 0)
2586 if (*pdrv == NULL) {
2587 cdm->status = CAM_DEV_MATCH_ERROR;
2591 cdm->pos.cookie.pdrv = pdrv;
2593 * The periph generation slot does double duty, as
2594 * does the periph pointer slot. They are used for
2595 * both edt and pdrv lookups and positioning.
2597 cdm->pos.cookie.periph = periph;
2598 cdm->pos.generations[CAM_PERIPH_GENERATION] =
2599 (*pdrv)->generation;
2600 cdm->status = CAM_DEV_MATCH_MORE;
2604 j = cdm->num_matches;
2606 cdm->matches[j].type = DEV_MATCH_PERIPH;
2607 cdm->matches[j].result.periph_result.path_id =
2608 periph->path->bus->path_id;
2611 * The transport layer peripheral doesn't have a target or
2614 if (periph->path->target)
2615 cdm->matches[j].result.periph_result.target_id =
2616 periph->path->target->target_id;
2618 cdm->matches[j].result.periph_result.target_id = -1;
2620 if (periph->path->device)
2621 cdm->matches[j].result.periph_result.target_lun =
2622 periph->path->device->lun_id;
2624 cdm->matches[j].result.periph_result.target_lun = -1;
2626 cdm->matches[j].result.periph_result.unit_number =
2627 periph->unit_number;
2628 strncpy(cdm->matches[j].result.periph_result.periph_name,
2629 periph->periph_name, DEV_IDLEN);
2636 xptperiphlistmatch(struct ccb_dev_match *cdm)
2640 cdm->num_matches = 0;
2643 * At this point in the edt traversal function, we check the bus
2644 * list generation to make sure that no busses have been added or
2645 * removed since the user last sent a XPT_DEV_MATCH ccb through.
2646 * For the peripheral driver list traversal function, however, we
2647 * don't have to worry about new peripheral driver types coming or
2648 * going; they're in a linker set, and therefore can't change
2649 * without a recompile.
2652 if ((cdm->pos.position_type & CAM_DEV_POS_PDPTR)
2653 && (cdm->pos.cookie.pdrv != NULL))
2654 ret = xptpdrvtraverse(
2655 (struct periph_driver **)cdm->pos.cookie.pdrv,
2656 xptplistpdrvfunc, cdm);
2658 ret = xptpdrvtraverse(NULL, xptplistpdrvfunc, cdm);
2661 * If we get back 0, that means that we had to stop before fully
2662 * traversing the peripheral driver tree. It also means that one of
2663 * the subroutines has set the status field to the proper value. If
2664 * we get back 1, we've fully traversed the EDT and copied out any
2668 cdm->status = CAM_DEV_MATCH_LAST;
2674 xptbustraverse(struct cam_eb *start_bus, xpt_busfunc_t *tr_func, void *arg)
2676 struct cam_eb *bus, *next_bus;
2681 for (bus = (start_bus ? start_bus : TAILQ_FIRST(&xpt_busses));
2684 next_bus = TAILQ_NEXT(bus, links);
2686 retval = tr_func(bus, arg);
2695 xpttargettraverse(struct cam_eb *bus, struct cam_et *start_target,
2696 xpt_targetfunc_t *tr_func, void *arg)
2698 struct cam_et *target, *next_target;
2702 for (target = (start_target ? start_target :
2703 TAILQ_FIRST(&bus->et_entries));
2704 target != NULL; target = next_target) {
2706 next_target = TAILQ_NEXT(target, links);
2708 retval = tr_func(target, arg);
2718 xptdevicetraverse(struct cam_et *target, struct cam_ed *start_device,
2719 xpt_devicefunc_t *tr_func, void *arg)
2721 struct cam_ed *device, *next_device;
2725 for (device = (start_device ? start_device :
2726 TAILQ_FIRST(&target->ed_entries));
2728 device = next_device) {
2730 next_device = TAILQ_NEXT(device, links);
2732 retval = tr_func(device, arg);
2742 xptperiphtraverse(struct cam_ed *device, struct cam_periph *start_periph,
2743 xpt_periphfunc_t *tr_func, void *arg)
2745 struct cam_periph *periph, *next_periph;
2750 for (periph = (start_periph ? start_periph :
2751 SLIST_FIRST(&device->periphs));
2753 periph = next_periph) {
2755 next_periph = SLIST_NEXT(periph, periph_links);
2757 retval = tr_func(periph, arg);
2766 xptpdrvtraverse(struct periph_driver **start_pdrv,
2767 xpt_pdrvfunc_t *tr_func, void *arg)
2769 struct periph_driver **pdrv;
2775 * We don't traverse the peripheral driver list like we do the
2776 * other lists, because it is a linker set, and therefore cannot be
2777 * changed during runtime. If the peripheral driver list is ever
2778 * re-done to be something other than a linker set (i.e. it can
2779 * change while the system is running), the list traversal should
2780 * be modified to work like the other traversal functions.
2782 for (pdrv = (start_pdrv ? start_pdrv : periph_drivers);
2783 *pdrv != NULL; pdrv++) {
2784 retval = tr_func(pdrv, arg);
2794 xptpdperiphtraverse(struct periph_driver **pdrv,
2795 struct cam_periph *start_periph,
2796 xpt_periphfunc_t *tr_func, void *arg)
2798 struct cam_periph *periph, *next_periph;
2803 for (periph = (start_periph ? start_periph :
2804 TAILQ_FIRST(&(*pdrv)->units)); periph != NULL;
2805 periph = next_periph) {
2807 next_periph = TAILQ_NEXT(periph, unit_links);
2809 retval = tr_func(periph, arg);
2817 xptdefbusfunc(struct cam_eb *bus, void *arg)
2819 struct xpt_traverse_config *tr_config;
2821 tr_config = (struct xpt_traverse_config *)arg;
2823 if (tr_config->depth == XPT_DEPTH_BUS) {
2824 xpt_busfunc_t *tr_func;
2826 tr_func = (xpt_busfunc_t *)tr_config->tr_func;
2828 return(tr_func(bus, tr_config->tr_arg));
2830 return(xpttargettraverse(bus, NULL, xptdeftargetfunc, arg));
2834 xptdeftargetfunc(struct cam_et *target, void *arg)
2836 struct xpt_traverse_config *tr_config;
2838 tr_config = (struct xpt_traverse_config *)arg;
2840 if (tr_config->depth == XPT_DEPTH_TARGET) {
2841 xpt_targetfunc_t *tr_func;
2843 tr_func = (xpt_targetfunc_t *)tr_config->tr_func;
2845 return(tr_func(target, tr_config->tr_arg));
2847 return(xptdevicetraverse(target, NULL, xptdefdevicefunc, arg));
2851 xptdefdevicefunc(struct cam_ed *device, void *arg)
2853 struct xpt_traverse_config *tr_config;
2855 tr_config = (struct xpt_traverse_config *)arg;
2857 if (tr_config->depth == XPT_DEPTH_DEVICE) {
2858 xpt_devicefunc_t *tr_func;
2860 tr_func = (xpt_devicefunc_t *)tr_config->tr_func;
2862 return(tr_func(device, tr_config->tr_arg));
2864 return(xptperiphtraverse(device, NULL, xptdefperiphfunc, arg));
2868 xptdefperiphfunc(struct cam_periph *periph, void *arg)
2870 struct xpt_traverse_config *tr_config;
2871 xpt_periphfunc_t *tr_func;
2873 tr_config = (struct xpt_traverse_config *)arg;
2875 tr_func = (xpt_periphfunc_t *)tr_config->tr_func;
2878 * Unlike the other default functions, we don't check for depth
2879 * here. The peripheral driver level is the last level in the EDT,
2880 * so if we're here, we should execute the function in question.
2882 return(tr_func(periph, tr_config->tr_arg));
2886 * Execute the given function for every bus in the EDT.
2889 xpt_for_all_busses(xpt_busfunc_t *tr_func, void *arg)
2891 struct xpt_traverse_config tr_config;
2893 tr_config.depth = XPT_DEPTH_BUS;
2894 tr_config.tr_func = tr_func;
2895 tr_config.tr_arg = arg;
2897 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2902 * Execute the given function for every target in the EDT.
2905 xpt_for_all_targets(xpt_targetfunc_t *tr_func, void *arg)
2907 struct xpt_traverse_config tr_config;
2909 tr_config.depth = XPT_DEPTH_TARGET;
2910 tr_config.tr_func = tr_func;
2911 tr_config.tr_arg = arg;
2913 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2915 #endif /* notusedyet */
2918 * Execute the given function for every device in the EDT.
2921 xpt_for_all_devices(xpt_devicefunc_t *tr_func, void *arg)
2923 struct xpt_traverse_config tr_config;
2925 tr_config.depth = XPT_DEPTH_DEVICE;
2926 tr_config.tr_func = tr_func;
2927 tr_config.tr_arg = arg;
2929 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2934 * Execute the given function for every peripheral in the EDT.
2937 xpt_for_all_periphs(xpt_periphfunc_t *tr_func, void *arg)
2939 struct xpt_traverse_config tr_config;
2941 tr_config.depth = XPT_DEPTH_PERIPH;
2942 tr_config.tr_func = tr_func;
2943 tr_config.tr_arg = arg;
2945 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2947 #endif /* notusedyet */
2950 xptsetasyncfunc(struct cam_ed *device, void *arg)
2952 struct cam_path path;
2953 struct ccb_getdev cgd;
2954 struct async_node *cur_entry;
2956 cur_entry = (struct async_node *)arg;
2959 * Don't report unconfigured devices (Wildcard devs,
2960 * devices only for target mode, device instances
2961 * that have been invalidated but are waiting for
2962 * their last reference count to be released).
2964 if ((device->flags & CAM_DEV_UNCONFIGURED) != 0)
2967 xpt_compile_path(&path,
2969 device->target->bus->path_id,
2970 device->target->target_id,
2972 xpt_setup_ccb(&cgd.ccb_h, &path, /*priority*/1);
2973 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
2974 xpt_action((union ccb *)&cgd);
2975 cur_entry->callback(cur_entry->callback_arg,
2978 xpt_release_path(&path);
2984 xptsetasyncbusfunc(struct cam_eb *bus, void *arg)
2986 struct cam_path path;
2987 struct ccb_pathinq cpi;
2988 struct async_node *cur_entry;
2990 cur_entry = (struct async_node *)arg;
2992 xpt_compile_path(&path, /*periph*/NULL,
2994 CAM_TARGET_WILDCARD,
2996 xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
2997 cpi.ccb_h.func_code = XPT_PATH_INQ;
2998 xpt_action((union ccb *)&cpi);
2999 cur_entry->callback(cur_entry->callback_arg,
3002 xpt_release_path(&path);
3008 xpt_action(union ccb *start_ccb)
3014 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_action\n"));
3016 start_ccb->ccb_h.status = CAM_REQ_INPROG;
3018 iopl = splsoftcam();
3019 switch (start_ccb->ccb_h.func_code) {
3022 #ifdef CAM_NEW_TRAN_CODE
3023 struct cam_ed *device;
3024 #endif /* CAM_NEW_TRAN_CODE */
3026 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3027 struct cam_path *path;
3029 path = start_ccb->ccb_h.path;
3033 * For the sake of compatibility with SCSI-1
3034 * devices that may not understand the identify
3035 * message, we include lun information in the
3036 * second byte of all commands. SCSI-1 specifies
3037 * that luns are a 3 bit value and reserves only 3
3038 * bits for lun information in the CDB. Later
3039 * revisions of the SCSI spec allow for more than 8
3040 * luns, but have deprecated lun information in the
3041 * CDB. So, if the lun won't fit, we must omit.
3043 * Also be aware that during initial probing for devices,
3044 * the inquiry information is unknown but initialized to 0.
3045 * This means that this code will be exercised while probing
3046 * devices with an ANSI revision greater than 2.
3048 #ifdef CAM_NEW_TRAN_CODE
3049 device = start_ccb->ccb_h.path->device;
3050 if (device->protocol_version <= SCSI_REV_2
3051 #else /* CAM_NEW_TRAN_CODE */
3052 if (SID_ANSI_REV(&start_ccb->ccb_h.path->device->inq_data) <= 2
3053 #endif /* CAM_NEW_TRAN_CODE */
3054 && start_ccb->ccb_h.target_lun < 8
3055 && (start_ccb->ccb_h.flags & CAM_CDB_POINTER) == 0) {
3057 start_ccb->csio.cdb_io.cdb_bytes[1] |=
3058 start_ccb->ccb_h.target_lun << 5;
3060 start_ccb->csio.scsi_status = SCSI_STATUS_OK;
3061 CAM_DEBUG(path, CAM_DEBUG_CDB,("%s. CDB: %s\n",
3062 scsi_op_desc(start_ccb->csio.cdb_io.cdb_bytes[0],
3063 &path->device->inq_data),
3064 scsi_cdb_string(start_ccb->csio.cdb_io.cdb_bytes,
3065 cdb_str, sizeof(cdb_str))));
3069 case XPT_CONT_TARGET_IO:
3070 start_ccb->csio.sense_resid = 0;
3071 start_ccb->csio.resid = 0;
3076 struct cam_path *path;
3077 struct cam_sim *sim;
3081 path = start_ccb->ccb_h.path;
3084 sim = path->bus->sim;
3085 if (SIM_DEAD(sim)) {
3086 /* The SIM has gone; just execute the CCB directly. */
3087 cam_ccbq_send_ccb(&path->device->ccbq, start_ccb);
3088 (*(sim->sim_action))(sim, start_ccb);
3093 cam_ccbq_insert_ccb(&path->device->ccbq, start_ccb);
3094 if (path->device->qfrozen_cnt == 0)
3095 runq = xpt_schedule_dev_sendq(path->bus, path->device);
3100 xpt_run_dev_sendq(path->bus);
3103 case XPT_SET_TRAN_SETTINGS:
3105 xpt_set_transfer_settings(&start_ccb->cts,
3106 start_ccb->ccb_h.path->device,
3107 /*async_update*/FALSE);
3110 case XPT_CALC_GEOMETRY:
3112 struct cam_sim *sim;
3114 /* Filter out garbage */
3115 if (start_ccb->ccg.block_size == 0
3116 || start_ccb->ccg.volume_size == 0) {
3117 start_ccb->ccg.cylinders = 0;
3118 start_ccb->ccg.heads = 0;
3119 start_ccb->ccg.secs_per_track = 0;
3120 start_ccb->ccb_h.status = CAM_REQ_CMP;
3125 * In a PC-98 system, geometry translation depens on
3126 * the "real" device geometry obtained from mode page 4.
3127 * SCSI geometry translation is performed in the
3128 * initialization routine of the SCSI BIOS and the result
3129 * stored in host memory. If the translation is available
3130 * in host memory, use it. If not, rely on the default
3131 * translation the device driver performs.
3133 if (scsi_da_bios_params(&start_ccb->ccg) != 0) {
3134 start_ccb->ccb_h.status = CAM_REQ_CMP;
3138 sim = start_ccb->ccb_h.path->bus->sim;
3139 (*(sim->sim_action))(sim, start_ccb);
3144 union ccb* abort_ccb;
3147 abort_ccb = start_ccb->cab.abort_ccb;
3148 if (XPT_FC_IS_DEV_QUEUED(abort_ccb)) {
3150 if (abort_ccb->ccb_h.pinfo.index >= 0) {
3151 struct cam_ccbq *ccbq;
3153 ccbq = &abort_ccb->ccb_h.path->device->ccbq;
3154 cam_ccbq_remove_ccb(ccbq, abort_ccb);
3155 abort_ccb->ccb_h.status =
3156 CAM_REQ_ABORTED|CAM_DEV_QFRZN;
3157 xpt_freeze_devq(abort_ccb->ccb_h.path, 1);
3159 xpt_done(abort_ccb);
3161 start_ccb->ccb_h.status = CAM_REQ_CMP;
3164 if (abort_ccb->ccb_h.pinfo.index == CAM_UNQUEUED_INDEX
3165 && (abort_ccb->ccb_h.status & CAM_SIM_QUEUED) == 0) {
3167 * We've caught this ccb en route to
3168 * the SIM. Flag it for abort and the
3169 * SIM will do so just before starting
3170 * real work on the CCB.
3172 abort_ccb->ccb_h.status =
3173 CAM_REQ_ABORTED|CAM_DEV_QFRZN;
3174 xpt_freeze_devq(abort_ccb->ccb_h.path, 1);
3175 start_ccb->ccb_h.status = CAM_REQ_CMP;
3179 if (XPT_FC_IS_QUEUED(abort_ccb)
3180 && (abort_ccb->ccb_h.pinfo.index == CAM_DONEQ_INDEX)) {
3182 * It's already completed but waiting
3183 * for our SWI to get to it.
3185 start_ccb->ccb_h.status = CAM_UA_ABORT;
3189 * If we weren't able to take care of the abort request
3190 * in the XPT, pass the request down to the SIM for processing.
3194 case XPT_ACCEPT_TARGET_IO:
3196 case XPT_IMMED_NOTIFY:
3197 case XPT_NOTIFY_ACK:
3198 case XPT_GET_TRAN_SETTINGS:
3201 struct cam_sim *sim;
3203 sim = start_ccb->ccb_h.path->bus->sim;
3204 (*(sim->sim_action))(sim, start_ccb);
3209 struct cam_sim *sim;
3211 sim = start_ccb->ccb_h.path->bus->sim;
3212 (*(sim->sim_action))(sim, start_ccb);
3215 case XPT_PATH_STATS:
3216 start_ccb->cpis.last_reset =
3217 start_ccb->ccb_h.path->bus->last_reset;
3218 start_ccb->ccb_h.status = CAM_REQ_CMP;
3225 dev = start_ccb->ccb_h.path->device;
3227 if ((dev->flags & CAM_DEV_UNCONFIGURED) != 0) {
3228 start_ccb->ccb_h.status = CAM_DEV_NOT_THERE;
3230 struct ccb_getdev *cgd;
3234 cgd = &start_ccb->cgd;
3235 bus = cgd->ccb_h.path->bus;
3236 tar = cgd->ccb_h.path->target;
3237 cgd->inq_data = dev->inq_data;
3238 cgd->ccb_h.status = CAM_REQ_CMP;
3239 cgd->serial_num_len = dev->serial_num_len;
3240 if ((dev->serial_num_len > 0)
3241 && (dev->serial_num != NULL))
3242 bcopy(dev->serial_num, cgd->serial_num,
3243 dev->serial_num_len);
3248 case XPT_GDEV_STATS:
3253 dev = start_ccb->ccb_h.path->device;
3255 if ((dev->flags & CAM_DEV_UNCONFIGURED) != 0) {
3256 start_ccb->ccb_h.status = CAM_DEV_NOT_THERE;
3258 struct ccb_getdevstats *cgds;
3262 cgds = &start_ccb->cgds;
3263 bus = cgds->ccb_h.path->bus;
3264 tar = cgds->ccb_h.path->target;
3265 cgds->dev_openings = dev->ccbq.dev_openings;
3266 cgds->dev_active = dev->ccbq.dev_active;
3267 cgds->devq_openings = dev->ccbq.devq_openings;
3268 cgds->devq_queued = dev->ccbq.queue.entries;
3269 cgds->held = dev->ccbq.held;
3270 cgds->last_reset = tar->last_reset;
3271 cgds->maxtags = dev->quirk->maxtags;
3272 cgds->mintags = dev->quirk->mintags;
3273 if (timevalcmp(&tar->last_reset, &bus->last_reset, <))
3274 cgds->last_reset = bus->last_reset;
3275 cgds->ccb_h.status = CAM_REQ_CMP;
3282 struct cam_periph *nperiph;
3283 struct periph_list *periph_head;
3284 struct ccb_getdevlist *cgdl;
3287 struct cam_ed *device;
3294 * Don't want anyone mucking with our data.
3297 device = start_ccb->ccb_h.path->device;
3298 periph_head = &device->periphs;
3299 cgdl = &start_ccb->cgdl;
3302 * Check and see if the list has changed since the user
3303 * last requested a list member. If so, tell them that the
3304 * list has changed, and therefore they need to start over
3305 * from the beginning.
3307 if ((cgdl->index != 0) &&
3308 (cgdl->generation != device->generation)) {
3309 cgdl->status = CAM_GDEVLIST_LIST_CHANGED;
3315 * Traverse the list of peripherals and attempt to find
3316 * the requested peripheral.
3318 for (nperiph = SLIST_FIRST(periph_head), i = 0;
3319 (nperiph != NULL) && (i <= cgdl->index);
3320 nperiph = SLIST_NEXT(nperiph, periph_links), i++) {
3321 if (i == cgdl->index) {
3322 strncpy(cgdl->periph_name,
3323 nperiph->periph_name,
3325 cgdl->unit_number = nperiph->unit_number;
3330 cgdl->status = CAM_GDEVLIST_ERROR;
3335 if (nperiph == NULL)
3336 cgdl->status = CAM_GDEVLIST_LAST_DEVICE;
3338 cgdl->status = CAM_GDEVLIST_MORE_DEVS;
3341 cgdl->generation = device->generation;
3344 cgdl->ccb_h.status = CAM_REQ_CMP;
3350 dev_pos_type position_type;
3351 struct ccb_dev_match *cdm;
3353 cdm = &start_ccb->cdm;
3356 * Prevent EDT changes while we traverse it.
3360 * There are two ways of getting at information in the EDT.
3361 * The first way is via the primary EDT tree. It starts
3362 * with a list of busses, then a list of targets on a bus,
3363 * then devices/luns on a target, and then peripherals on a
3364 * device/lun. The "other" way is by the peripheral driver
3365 * lists. The peripheral driver lists are organized by
3366 * peripheral driver. (obviously) So it makes sense to
3367 * use the peripheral driver list if the user is looking
3368 * for something like "da1", or all "da" devices. If the
3369 * user is looking for something on a particular bus/target
3370 * or lun, it's generally better to go through the EDT tree.
3373 if (cdm->pos.position_type != CAM_DEV_POS_NONE)
3374 position_type = cdm->pos.position_type;
3378 position_type = CAM_DEV_POS_NONE;
3380 for (i = 0; i < cdm->num_patterns; i++) {
3381 if ((cdm->patterns[i].type == DEV_MATCH_BUS)
3382 ||(cdm->patterns[i].type == DEV_MATCH_DEVICE)){
3383 position_type = CAM_DEV_POS_EDT;
3388 if (cdm->num_patterns == 0)
3389 position_type = CAM_DEV_POS_EDT;
3390 else if (position_type == CAM_DEV_POS_NONE)
3391 position_type = CAM_DEV_POS_PDRV;
3394 switch(position_type & CAM_DEV_POS_TYPEMASK) {
3395 case CAM_DEV_POS_EDT:
3398 case CAM_DEV_POS_PDRV:
3399 xptperiphlistmatch(cdm);
3402 cdm->status = CAM_DEV_MATCH_ERROR;
3408 if (cdm->status == CAM_DEV_MATCH_ERROR)
3409 start_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
3411 start_ccb->ccb_h.status = CAM_REQ_CMP;
3417 struct ccb_setasync *csa;
3418 struct async_node *cur_entry;
3419 struct async_list *async_head;
3423 csa = &start_ccb->csa;
3424 added = csa->event_enable;
3425 async_head = &csa->ccb_h.path->device->asyncs;
3428 * If there is already an entry for us, simply
3432 cur_entry = SLIST_FIRST(async_head);
3433 while (cur_entry != NULL) {
3434 if ((cur_entry->callback_arg == csa->callback_arg)
3435 && (cur_entry->callback == csa->callback))
3437 cur_entry = SLIST_NEXT(cur_entry, links);
3440 if (cur_entry != NULL) {
3442 * If the request has no flags set,
3445 added &= ~cur_entry->event_enable;
3446 if (csa->event_enable == 0) {
3447 SLIST_REMOVE(async_head, cur_entry,
3449 csa->ccb_h.path->device->refcount--;
3450 free(cur_entry, M_CAMXPT);
3452 cur_entry->event_enable = csa->event_enable;
3455 cur_entry = malloc(sizeof(*cur_entry), M_CAMXPT,
3457 if (cur_entry == NULL) {
3459 csa->ccb_h.status = CAM_RESRC_UNAVAIL;
3462 cur_entry->event_enable = csa->event_enable;
3463 cur_entry->callback_arg = csa->callback_arg;
3464 cur_entry->callback = csa->callback;
3465 SLIST_INSERT_HEAD(async_head, cur_entry, links);
3466 csa->ccb_h.path->device->refcount++;
3469 if ((added & AC_FOUND_DEVICE) != 0) {
3471 * Get this peripheral up to date with all
3472 * the currently existing devices.
3474 xpt_for_all_devices(xptsetasyncfunc, cur_entry);
3476 if ((added & AC_PATH_REGISTERED) != 0) {
3478 * Get this peripheral up to date with all
3479 * the currently existing busses.
3481 xpt_for_all_busses(xptsetasyncbusfunc, cur_entry);
3484 start_ccb->ccb_h.status = CAM_REQ_CMP;
3489 struct ccb_relsim *crs;
3493 crs = &start_ccb->crs;
3494 dev = crs->ccb_h.path->device;
3497 crs->ccb_h.status = CAM_DEV_NOT_THERE;
3503 if ((crs->release_flags & RELSIM_ADJUST_OPENINGS) != 0) {
3505 if ((dev->inq_data.flags & SID_CmdQue) != 0) {
3507 /* Don't ever go below one opening */
3508 if (crs->openings > 0) {
3509 xpt_dev_ccbq_resize(crs->ccb_h.path,
3513 xpt_print_path(crs->ccb_h.path);
3514 printf("tagged openings "
3522 if ((crs->release_flags & RELSIM_RELEASE_AFTER_TIMEOUT) != 0) {
3524 if ((dev->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0) {
3527 * Just extend the old timeout and decrement
3528 * the freeze count so that a single timeout
3529 * is sufficient for releasing the queue.
3531 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3532 untimeout(xpt_release_devq_timeout,
3533 dev, dev->c_handle);
3536 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3540 timeout(xpt_release_devq_timeout,
3542 (crs->release_timeout * hz) / 1000);
3544 dev->flags |= CAM_DEV_REL_TIMEOUT_PENDING;
3548 if ((crs->release_flags & RELSIM_RELEASE_AFTER_CMDCMPLT) != 0) {
3550 if ((dev->flags & CAM_DEV_REL_ON_COMPLETE) != 0) {
3552 * Decrement the freeze count so that a single
3553 * completion is still sufficient to unfreeze
3556 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3559 dev->flags |= CAM_DEV_REL_ON_COMPLETE;
3560 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3564 if ((crs->release_flags & RELSIM_RELEASE_AFTER_QEMPTY) != 0) {
3566 if ((dev->flags & CAM_DEV_REL_ON_QUEUE_EMPTY) != 0
3567 || (dev->ccbq.dev_active == 0)) {
3569 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3572 dev->flags |= CAM_DEV_REL_ON_QUEUE_EMPTY;
3573 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3578 if ((start_ccb->ccb_h.flags & CAM_DEV_QFREEZE) == 0) {
3580 xpt_release_devq(crs->ccb_h.path, /*count*/1,
3583 start_ccb->crs.qfrozen_cnt = dev->qfrozen_cnt;
3584 start_ccb->ccb_h.status = CAM_REQ_CMP;
3588 xpt_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
3591 xpt_scan_lun(start_ccb->ccb_h.path->periph,
3592 start_ccb->ccb_h.path, start_ccb->crcn.flags,
3600 #ifdef CAM_DEBUG_DELAY
3601 cam_debug_delay = CAM_DEBUG_DELAY;
3603 cam_dflags = start_ccb->cdbg.flags;
3604 if (cam_dpath != NULL) {
3605 xpt_free_path(cam_dpath);
3609 if (cam_dflags != CAM_DEBUG_NONE) {
3610 if (xpt_create_path(&cam_dpath, xpt_periph,
3611 start_ccb->ccb_h.path_id,
3612 start_ccb->ccb_h.target_id,
3613 start_ccb->ccb_h.target_lun) !=
3615 start_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
3616 cam_dflags = CAM_DEBUG_NONE;
3618 start_ccb->ccb_h.status = CAM_REQ_CMP;
3619 xpt_print_path(cam_dpath);
3620 printf("debugging flags now %x\n", cam_dflags);
3624 start_ccb->ccb_h.status = CAM_REQ_CMP;
3627 #else /* !CAMDEBUG */
3628 start_ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3629 #endif /* CAMDEBUG */
3633 if ((start_ccb->ccb_h.flags & CAM_DEV_QFREEZE) != 0)
3634 xpt_freeze_devq(start_ccb->ccb_h.path, 1);
3635 start_ccb->ccb_h.status = CAM_REQ_CMP;
3642 start_ccb->ccb_h.status = CAM_PROVIDE_FAIL;
3649 xpt_polled_action(union ccb *start_ccb)
3653 struct cam_sim *sim;
3654 struct cam_devq *devq;
3659 timeout = start_ccb->ccb_h.timeout;
3660 sim = start_ccb->ccb_h.path->bus->sim;
3662 dev = start_ccb->ccb_h.path->device;
3667 * Steal an opening so that no other queued requests
3668 * can get it before us while we simulate interrupts.
3670 dev->ccbq.devq_openings--;
3671 dev->ccbq.dev_openings--;
3673 while(((devq != NULL && devq->send_openings <= 0) ||
3674 dev->ccbq.dev_openings < 0) && (--timeout > 0)) {
3676 (*(sim->sim_poll))(sim);
3680 dev->ccbq.devq_openings++;
3681 dev->ccbq.dev_openings++;
3684 xpt_action(start_ccb);
3685 while(--timeout > 0) {
3686 (*(sim->sim_poll))(sim);
3688 if ((start_ccb->ccb_h.status & CAM_STATUS_MASK)
3695 * XXX Is it worth adding a sim_timeout entry
3696 * point so we can attempt recovery? If
3697 * this is only used for dumps, I don't think
3700 start_ccb->ccb_h.status = CAM_CMD_TIMEOUT;
3703 start_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
3709 * Schedule a peripheral driver to receive a ccb when it's
3710 * target device has space for more transactions.
3713 xpt_schedule(struct cam_periph *perph, u_int32_t new_priority)
3715 struct cam_ed *device;
3716 union ccb *work_ccb;
3722 CAM_DEBUG(perph->path, CAM_DEBUG_TRACE, ("xpt_schedule\n"));
3723 device = perph->path->device;
3725 if (periph_is_queued(perph)) {
3726 /* Simply reorder based on new priority */
3727 CAM_DEBUG(perph->path, CAM_DEBUG_SUBTRACE,
3728 (" change priority to %d\n", new_priority));
3729 if (new_priority < perph->pinfo.priority) {
3730 camq_change_priority(&device->drvq,
3735 } else if (SIM_DEAD(perph->path->bus->sim)) {
3736 /* The SIM is gone so just call periph_start directly. */
3737 work_ccb = xpt_get_ccb(perph->path->device);
3739 if (work_ccb == NULL)
3741 xpt_setup_ccb(&work_ccb->ccb_h, perph->path, new_priority);
3742 perph->pinfo.priority = new_priority;
3743 perph->periph_start(perph, work_ccb);
3746 /* New entry on the queue */
3747 CAM_DEBUG(perph->path, CAM_DEBUG_SUBTRACE,
3748 (" added periph to queue\n"));
3749 perph->pinfo.priority = new_priority;
3750 perph->pinfo.generation = ++device->drvq.generation;
3751 camq_insert(&device->drvq, &perph->pinfo);
3752 runq = xpt_schedule_dev_allocq(perph->path->bus, device);
3756 CAM_DEBUG(perph->path, CAM_DEBUG_SUBTRACE,
3757 (" calling xpt_run_devq\n"));
3758 xpt_run_dev_allocq(perph->path->bus);
3764 * Schedule a device to run on a given queue.
3765 * If the device was inserted as a new entry on the queue,
3766 * return 1 meaning the device queue should be run. If we
3767 * were already queued, implying someone else has already
3768 * started the queue, return 0 so the caller doesn't attempt
3769 * to run the queue. Must be run at either splsoftcam
3770 * (or splcam since that encompases splsoftcam).
3773 xpt_schedule_dev(struct camq *queue, cam_pinfo *pinfo,
3774 u_int32_t new_priority)
3777 u_int32_t old_priority;
3779 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_schedule_dev\n"));
3781 old_priority = pinfo->priority;
3784 * Are we already queued?
3786 if (pinfo->index != CAM_UNQUEUED_INDEX) {
3787 /* Simply reorder based on new priority */
3788 if (new_priority < old_priority) {
3789 camq_change_priority(queue, pinfo->index,
3791 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3792 ("changed priority to %d\n",
3797 /* New entry on the queue */
3798 if (new_priority < old_priority)
3799 pinfo->priority = new_priority;
3801 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3802 ("Inserting onto queue\n"));
3803 pinfo->generation = ++queue->generation;
3804 camq_insert(queue, pinfo);
3811 xpt_run_dev_allocq(struct cam_eb *bus)
3813 struct cam_devq *devq;
3816 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_dev_allocq\n"));
3817 devq = bus->sim->devq;
3819 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3820 (" qfrozen_cnt == 0x%x, entries == %d, "
3821 "openings == %d, active == %d\n",
3822 devq->alloc_queue.qfrozen_cnt,
3823 devq->alloc_queue.entries,
3824 devq->alloc_openings,
3825 devq->alloc_active));
3828 devq->alloc_queue.qfrozen_cnt++;
3829 while ((devq->alloc_queue.entries > 0)
3830 && (devq->alloc_openings > 0)
3831 && (devq->alloc_queue.qfrozen_cnt <= 1)) {
3832 struct cam_ed_qinfo *qinfo;
3833 struct cam_ed *device;
3834 union ccb *work_ccb;
3835 struct cam_periph *drv;
3838 qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->alloc_queue,
3840 device = qinfo->device;
3842 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3843 ("running device %p\n", device));
3845 drvq = &device->drvq;
3848 if (drvq->entries <= 0) {
3849 panic("xpt_run_dev_allocq: "
3850 "Device on queue without any work to do");
3853 if ((work_ccb = xpt_get_ccb(device)) != NULL) {
3854 devq->alloc_openings--;
3855 devq->alloc_active++;
3856 drv = (struct cam_periph*)camq_remove(drvq, CAMQ_HEAD);
3858 xpt_setup_ccb(&work_ccb->ccb_h, drv->path,
3859 drv->pinfo.priority);
3860 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3861 ("calling periph start\n"));
3862 drv->periph_start(drv, work_ccb);
3865 * Malloc failure in alloc_ccb
3868 * XXX add us to a list to be run from free_ccb
3869 * if we don't have any ccbs active on this
3870 * device queue otherwise we may never get run
3876 /* Raise IPL for possible insertion and test at top of loop */
3879 if (drvq->entries > 0) {
3880 /* We have more work. Attempt to reschedule */
3881 xpt_schedule_dev_allocq(bus, device);
3884 devq->alloc_queue.qfrozen_cnt--;
3889 xpt_run_dev_sendq(struct cam_eb *bus)
3891 struct cam_devq *devq;
3894 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_dev_sendq\n"));
3896 devq = bus->sim->devq;
3899 devq->send_queue.qfrozen_cnt++;
3902 while ((devq->send_queue.entries > 0)
3903 && (devq->send_openings > 0)) {
3904 struct cam_ed_qinfo *qinfo;
3905 struct cam_ed *device;
3906 union ccb *work_ccb;
3907 struct cam_sim *sim;
3911 if (devq->send_queue.qfrozen_cnt > 1) {
3916 qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->send_queue,
3918 device = qinfo->device;
3921 * If the device has been "frozen", don't attempt
3924 if (device->qfrozen_cnt > 0) {
3929 CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
3930 ("running device %p\n", device));
3932 work_ccb = cam_ccbq_peek_ccb(&device->ccbq, CAMQ_HEAD);
3933 if (work_ccb == NULL) {
3934 printf("device on run queue with no ccbs???\n");
3939 if ((work_ccb->ccb_h.flags & CAM_HIGH_POWER) != 0) {
3941 if (num_highpower <= 0) {
3943 * We got a high power command, but we
3944 * don't have any available slots. Freeze
3945 * the device queue until we have a slot
3948 device->qfrozen_cnt++;
3949 STAILQ_INSERT_TAIL(&highpowerq,
3957 * Consume a high power slot while
3963 devq->active_dev = device;
3964 cam_ccbq_remove_ccb(&device->ccbq, work_ccb);
3966 cam_ccbq_send_ccb(&device->ccbq, work_ccb);
3969 devq->send_openings--;
3970 devq->send_active++;
3972 if (device->ccbq.queue.entries > 0)
3973 xpt_schedule_dev_sendq(bus, device);
3975 if (work_ccb && (work_ccb->ccb_h.flags & CAM_DEV_QFREEZE) != 0){
3977 * The client wants to freeze the queue
3978 * after this CCB is sent.
3981 device->qfrozen_cnt++;
3987 /* In Target mode, the peripheral driver knows best... */
3988 if (work_ccb->ccb_h.func_code == XPT_SCSI_IO) {
3989 if ((device->inq_flags & SID_CmdQue) != 0
3990 && work_ccb->csio.tag_action != CAM_TAG_ACTION_NONE)
3991 work_ccb->ccb_h.flags |= CAM_TAG_ACTION_VALID;
3994 * Clear this in case of a retried CCB that
3995 * failed due to a rejected tag.
3997 work_ccb->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
4001 * Device queues can be shared among multiple sim instances
4002 * that reside on different busses. Use the SIM in the queue
4003 * CCB's path, rather than the one in the bus that was passed
4004 * into this function.
4006 sim = work_ccb->ccb_h.path->bus->sim;
4007 (*(sim->sim_action))(sim, work_ccb);
4010 devq->active_dev = NULL;
4012 /* Raise IPL for possible insertion and test at top of loop */
4017 devq->send_queue.qfrozen_cnt--;
4022 * This function merges stuff from the slave ccb into the master ccb, while
4023 * keeping important fields in the master ccb constant.
4026 xpt_merge_ccb(union ccb *master_ccb, union ccb *slave_ccb)
4031 * Pull fields that are valid for peripheral drivers to set
4032 * into the master CCB along with the CCB "payload".
4034 master_ccb->ccb_h.retry_count = slave_ccb->ccb_h.retry_count;
4035 master_ccb->ccb_h.func_code = slave_ccb->ccb_h.func_code;
4036 master_ccb->ccb_h.timeout = slave_ccb->ccb_h.timeout;
4037 master_ccb->ccb_h.flags = slave_ccb->ccb_h.flags;
4038 bcopy(&(&slave_ccb->ccb_h)[1], &(&master_ccb->ccb_h)[1],
4039 sizeof(union ccb) - sizeof(struct ccb_hdr));
4043 xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
4047 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_setup_ccb\n"));
4048 ccb_h->pinfo.priority = priority;
4050 ccb_h->path_id = path->bus->path_id;
4052 ccb_h->target_id = path->target->target_id;
4054 ccb_h->target_id = CAM_TARGET_WILDCARD;
4056 ccb_h->target_lun = path->device->lun_id;
4057 ccb_h->pinfo.generation = ++path->device->ccbq.queue.generation;
4059 ccb_h->target_lun = CAM_TARGET_WILDCARD;
4061 ccb_h->pinfo.index = CAM_UNQUEUED_INDEX;
4065 /* Path manipulation functions */
4067 xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph,
4068 path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
4070 struct cam_path *path;
4075 path = (struct cam_path *)malloc(sizeof(*path), M_CAMXPT, M_NOWAIT);
4078 status = CAM_RESRC_UNAVAIL;
4081 status = xpt_compile_path(path, perph, path_id, target_id, lun_id);
4082 if (status != CAM_REQ_CMP) {
4083 free(path, M_CAMXPT);
4086 *new_path_ptr = path;
4091 xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph,
4092 path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
4095 struct cam_et *target;
4096 struct cam_ed *device;
4100 status = CAM_REQ_CMP; /* Completed without error */
4101 target = NULL; /* Wildcarded */
4102 device = NULL; /* Wildcarded */
4105 * We will potentially modify the EDT, so block interrupts
4106 * that may attempt to create cam paths.
4109 bus = xpt_find_bus(path_id);
4111 status = CAM_PATH_INVALID;
4113 target = xpt_find_target(bus, target_id);
4114 if (target == NULL) {
4116 struct cam_et *new_target;
4118 new_target = xpt_alloc_target(bus, target_id);
4119 if (new_target == NULL) {
4120 status = CAM_RESRC_UNAVAIL;
4122 target = new_target;
4125 if (target != NULL) {
4126 device = xpt_find_device(target, lun_id);
4127 if (device == NULL) {
4129 struct cam_ed *new_device;
4131 new_device = xpt_alloc_device(bus,
4134 if (new_device == NULL) {
4135 status = CAM_RESRC_UNAVAIL;
4137 device = new_device;
4145 * Only touch the user's data if we are successful.
4147 if (status == CAM_REQ_CMP) {
4148 new_path->periph = perph;
4149 new_path->bus = bus;
4150 new_path->target = target;
4151 new_path->device = device;
4152 CAM_DEBUG(new_path, CAM_DEBUG_TRACE, ("xpt_compile_path\n"));
4155 xpt_release_device(bus, target, device);
4157 xpt_release_target(bus, target);
4159 xpt_release_bus(bus);
4165 xpt_release_path(struct cam_path *path)
4167 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_release_path\n"));
4168 if (path->device != NULL) {
4169 xpt_release_device(path->bus, path->target, path->device);
4170 path->device = NULL;
4172 if (path->target != NULL) {
4173 xpt_release_target(path->bus, path->target);
4174 path->target = NULL;
4176 if (path->bus != NULL) {
4177 xpt_release_bus(path->bus);
4183 xpt_free_path(struct cam_path *path)
4187 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_free_path\n"));
4188 xpt_release_path(path);
4189 free(path, M_CAMXPT);
4194 * Return -1 for failure, 0 for exact match, 1 for match with wildcards
4195 * in path1, 2 for match with wildcards in path2.
4198 xpt_path_comp(struct cam_path *path1, struct cam_path *path2)
4204 if (path1->bus != path2->bus) {
4205 if (path1->bus->path_id == CAM_BUS_WILDCARD)
4207 else if (path2->bus->path_id == CAM_BUS_WILDCARD)
4212 if (path1->target != path2->target) {
4213 if (path1->target->target_id == CAM_TARGET_WILDCARD) {
4216 } else if (path2->target->target_id == CAM_TARGET_WILDCARD)
4221 if (path1->device != path2->device) {
4222 if (path1->device->lun_id == CAM_LUN_WILDCARD) {
4225 } else if (path2->device->lun_id == CAM_LUN_WILDCARD)
4234 xpt_print_path(struct cam_path *path)
4239 printf("(nopath): ");
4241 if (path->periph != NULL)
4242 printf("(%s%d:", path->periph->periph_name,
4243 path->periph->unit_number);
4245 printf("(noperiph:");
4247 if (path->bus != NULL)
4248 printf("%s%d:%d:", path->bus->sim->sim_name,
4249 path->bus->sim->unit_number,
4250 path->bus->sim->bus_id);
4254 if (path->target != NULL)
4255 printf("%d:", path->target->target_id);
4259 if (path->device != NULL)
4260 printf("%d): ", path->device->lun_id);
4267 xpt_path_string(struct cam_path *path, char *str, size_t str_len)
4273 sbuf_new(&sb, str, str_len, 0);
4276 sbuf_printf(&sb, "(nopath): ");
4278 if (path->periph != NULL)
4279 sbuf_printf(&sb, "(%s%d:", path->periph->periph_name,
4280 path->periph->unit_number);
4282 sbuf_printf(&sb, "(noperiph:");
4284 if (path->bus != NULL)
4285 sbuf_printf(&sb, "%s%d:%d:", path->bus->sim->sim_name,
4286 path->bus->sim->unit_number,
4287 path->bus->sim->bus_id);
4289 sbuf_printf(&sb, "nobus:");
4291 if (path->target != NULL)
4292 sbuf_printf(&sb, "%d:", path->target->target_id);
4294 sbuf_printf(&sb, "X:");
4296 if (path->device != NULL)
4297 sbuf_printf(&sb, "%d): ", path->device->lun_id);
4299 sbuf_printf(&sb, "X): ");
4303 return(sbuf_len(&sb));
4307 xpt_path_path_id(struct cam_path *path)
4311 return(path->bus->path_id);
4315 xpt_path_target_id(struct cam_path *path)
4319 if (path->target != NULL)
4320 return (path->target->target_id);
4322 return (CAM_TARGET_WILDCARD);
4326 xpt_path_lun_id(struct cam_path *path)
4330 if (path->device != NULL)
4331 return (path->device->lun_id);
4333 return (CAM_LUN_WILDCARD);
4337 xpt_path_sim(struct cam_path *path)
4341 return (path->bus->sim);
4345 xpt_path_periph(struct cam_path *path)
4349 return (path->periph);
4353 * Release a CAM control block for the caller. Remit the cost of the structure
4354 * to the device referenced by the path. If the this device had no 'credits'
4355 * and peripheral drivers have registered async callbacks for this notification
4359 xpt_release_ccb(union ccb *free_ccb)
4362 struct cam_path *path;
4363 struct cam_ed *device;
4368 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_release_ccb\n"));
4369 path = free_ccb->ccb_h.path;
4370 device = path->device;
4373 cam_ccbq_release_opening(&device->ccbq);
4374 if (xpt_ccb_count > xpt_max_ccbs) {
4375 xpt_free_ccb(free_ccb);
4378 SLIST_INSERT_HEAD(&ccb_freeq, &free_ccb->ccb_h, xpt_links.sle);
4380 if (bus->sim->devq == NULL) {
4384 bus->sim->devq->alloc_openings++;
4385 bus->sim->devq->alloc_active--;
4386 /* XXX Turn this into an inline function - xpt_run_device?? */
4387 if ((device_is_alloc_queued(device) == 0)
4388 && (device->drvq.entries > 0)) {
4389 xpt_schedule_dev_allocq(bus, device);
4392 if (dev_allocq_is_runnable(bus->sim->devq))
4393 xpt_run_dev_allocq(bus);
4396 /* Functions accessed by SIM drivers */
4399 * A sim structure, listing the SIM entry points and instance
4400 * identification info is passed to xpt_bus_register to hook the SIM
4401 * into the CAM framework. xpt_bus_register creates a cam_eb entry
4402 * for this new bus and places it in the array of busses and assigns
4403 * it a path_id. The path_id may be influenced by "hard wiring"
4404 * information specified by the user. Once interrupt services are
4405 * availible, the bus will be probed.
4408 xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
4410 struct cam_eb *new_bus;
4411 struct cam_eb *old_bus;
4412 struct ccb_pathinq cpi;
4418 new_bus = (struct cam_eb *)malloc(sizeof(*new_bus),
4419 M_CAMXPT, M_NOWAIT);
4420 if (new_bus == NULL) {
4421 /* Couldn't satisfy request */
4422 return (CAM_RESRC_UNAVAIL);
4425 if (strcmp(sim->sim_name, "xpt") != 0) {
4428 xptpathid(sim->sim_name, sim->unit_number, sim->bus_id);
4431 TAILQ_INIT(&new_bus->et_entries);
4432 new_bus->path_id = sim->path_id;
4434 timevalclear(&new_bus->last_reset);
4436 new_bus->refcount = 1; /* Held until a bus_deregister event */
4437 new_bus->generation = 0;
4439 old_bus = TAILQ_FIRST(&xpt_busses);
4440 while (old_bus != NULL
4441 && old_bus->path_id < new_bus->path_id)
4442 old_bus = TAILQ_NEXT(old_bus, links);
4443 if (old_bus != NULL)
4444 TAILQ_INSERT_BEFORE(old_bus, new_bus, links);
4446 TAILQ_INSERT_TAIL(&xpt_busses, new_bus, links);
4450 /* Notify interested parties */
4451 if (sim->path_id != CAM_XPT_PATH_ID) {
4452 struct cam_path path;
4454 xpt_compile_path(&path, /*periph*/NULL, sim->path_id,
4455 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
4456 xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
4457 cpi.ccb_h.func_code = XPT_PATH_INQ;
4458 xpt_action((union ccb *)&cpi);
4459 xpt_async(AC_PATH_REGISTERED, &path, &cpi);
4460 xpt_release_path(&path);
4462 return (CAM_SUCCESS);
4466 xpt_bus_deregister(path_id_t pathid)
4468 struct cam_path bus_path;
4469 struct cam_ed *device;
4470 struct cam_ed_qinfo *qinfo;
4471 struct cam_devq *devq;
4472 struct cam_periph *periph;
4473 struct cam_sim *ccbsim;
4474 union ccb *work_ccb;
4479 status = xpt_compile_path(&bus_path, NULL, pathid,
4480 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
4481 if (status != CAM_REQ_CMP)
4484 xpt_async(AC_LOST_DEVICE, &bus_path, NULL);
4485 xpt_async(AC_PATH_DEREGISTERED, &bus_path, NULL);
4487 /* The SIM may be gone, so use a dummy SIM for any stray operations. */
4488 devq = bus_path.bus->sim->devq;
4489 bus_path.bus->sim = &cam_dead_sim;
4491 /* Execute any pending operations now. */
4492 while ((qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->send_queue,
4493 CAMQ_HEAD)) != NULL ||
4494 (qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->alloc_queue,
4495 CAMQ_HEAD)) != NULL) {
4497 device = qinfo->device;
4498 work_ccb = cam_ccbq_peek_ccb(&device->ccbq, CAMQ_HEAD);
4499 if (work_ccb != NULL) {
4500 devq->active_dev = device;
4501 cam_ccbq_remove_ccb(&device->ccbq, work_ccb);
4502 cam_ccbq_send_ccb(&device->ccbq, work_ccb);
4503 ccbsim = work_ccb->ccb_h.path->bus->sim;
4504 (*(ccbsim->sim_action))(ccbsim, work_ccb);
4507 periph = (struct cam_periph *)camq_remove(&device->drvq,
4510 xpt_schedule(periph, periph->pinfo.priority);
4511 } while (work_ccb != NULL || periph != NULL);
4514 /* Make sure all completed CCBs are processed. */
4515 while (!TAILQ_EMPTY(&cam_bioq)) {
4518 /* Repeat the async's for the benefit of any new devices. */
4519 xpt_async(AC_LOST_DEVICE, &bus_path, NULL);
4520 xpt_async(AC_PATH_DEREGISTERED, &bus_path, NULL);
4523 /* Release the reference count held while registered. */
4524 xpt_release_bus(bus_path.bus);
4525 xpt_release_path(&bus_path);
4527 /* Recheck for more completed CCBs. */
4528 while (!TAILQ_EMPTY(&cam_bioq))
4531 return (CAM_REQ_CMP);
4535 xptnextfreepathid(void)
4542 bus = TAILQ_FIRST(&xpt_busses);
4544 /* Find an unoccupied pathid */
4546 && bus->path_id <= pathid) {
4547 if (bus->path_id == pathid)
4549 bus = TAILQ_NEXT(bus, links);
4553 * Ensure that this pathid is not reserved for
4554 * a bus that may be registered in the future.
4556 if (resource_string_value("scbus", pathid, "at", &strval) == 0) {
4558 /* Start the search over */
4565 xptpathid(const char *sim_name, int sim_unit, int sim_bus)
4572 pathid = CAM_XPT_PATH_ID;
4573 snprintf(buf, sizeof(buf), "%s%d", sim_name, sim_unit);
4575 while ((resource_find_match(&i, &dname, &dunit, "at", buf)) == 0) {
4576 if (strcmp(dname, "scbus")) {
4577 /* Avoid a bit of foot shooting. */
4580 if (dunit < 0) /* unwired?! */
4582 if (resource_int_value("scbus", dunit, "bus", &val) == 0) {
4583 if (sim_bus == val) {
4587 } else if (sim_bus == 0) {
4588 /* Unspecified matches bus 0 */
4592 printf("Ambiguous scbus configuration for %s%d "
4593 "bus %d, cannot wire down. The kernel "
4594 "config entry for scbus%d should "
4595 "specify a controller bus.\n"
4596 "Scbus will be assigned dynamically.\n",
4597 sim_name, sim_unit, sim_bus, dunit);
4602 if (pathid == CAM_XPT_PATH_ID)
4603 pathid = xptnextfreepathid();
4608 xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
4611 struct cam_et *target, *next_target;
4612 struct cam_ed *device, *next_device;
4617 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_async\n"));
4620 * Most async events come from a CAM interrupt context. In
4621 * a few cases, the error recovery code at the peripheral layer,
4622 * which may run from our SWI or a process context, may signal
4623 * deferred events with a call to xpt_async. Ensure async
4624 * notifications are serialized by blocking cam interrupts.
4630 if (async_code == AC_BUS_RESET) {
4634 /* Update our notion of when the last reset occurred */
4635 microtime(&bus->last_reset);
4639 for (target = TAILQ_FIRST(&bus->et_entries);
4641 target = next_target) {
4643 next_target = TAILQ_NEXT(target, links);
4645 if (path->target != target
4646 && path->target->target_id != CAM_TARGET_WILDCARD
4647 && target->target_id != CAM_TARGET_WILDCARD)
4650 if (async_code == AC_SENT_BDR) {
4653 /* Update our notion of when the last reset occurred */
4655 microtime(&path->target->last_reset);
4659 for (device = TAILQ_FIRST(&target->ed_entries);
4661 device = next_device) {
4663 next_device = TAILQ_NEXT(device, links);
4665 if (path->device != device
4666 && path->device->lun_id != CAM_LUN_WILDCARD
4667 && device->lun_id != CAM_LUN_WILDCARD)
4670 xpt_dev_async(async_code, bus, target,
4673 xpt_async_bcast(&device->asyncs, async_code,
4679 * If this wasn't a fully wildcarded async, tell all
4680 * clients that want all async events.
4682 if (bus != xpt_periph->path->bus)
4683 xpt_async_bcast(&xpt_periph->path->device->asyncs, async_code,
4689 xpt_async_bcast(struct async_list *async_head,
4690 u_int32_t async_code,
4691 struct cam_path *path, void *async_arg)
4693 struct async_node *cur_entry;
4695 cur_entry = SLIST_FIRST(async_head);
4696 while (cur_entry != NULL) {
4697 struct async_node *next_entry;
4699 * Grab the next list entry before we call the current
4700 * entry's callback. This is because the callback function
4701 * can delete its async callback entry.
4703 next_entry = SLIST_NEXT(cur_entry, links);
4704 if ((cur_entry->event_enable & async_code) != 0)
4705 cur_entry->callback(cur_entry->callback_arg,
4708 cur_entry = next_entry;
4713 * Handle any per-device event notifications that require action by the XPT.
4716 xpt_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
4717 struct cam_ed *device, void *async_arg)
4720 struct cam_path newpath;
4723 * We only need to handle events for real devices.
4725 if (target->target_id == CAM_TARGET_WILDCARD
4726 || device->lun_id == CAM_LUN_WILDCARD)
4730 * We need our own path with wildcards expanded to
4731 * handle certain types of events.
4733 if ((async_code == AC_SENT_BDR)
4734 || (async_code == AC_BUS_RESET)
4735 || (async_code == AC_INQ_CHANGED))
4736 status = xpt_compile_path(&newpath, NULL,
4741 status = CAM_REQ_CMP_ERR;
4743 if (status == CAM_REQ_CMP) {
4746 * Allow transfer negotiation to occur in a
4747 * tag free environment.
4749 if (async_code == AC_SENT_BDR
4750 || async_code == AC_BUS_RESET)
4751 xpt_toggle_tags(&newpath);
4753 if (async_code == AC_INQ_CHANGED) {
4755 * We've sent a start unit command, or
4756 * something similar to a device that
4757 * may have caused its inquiry data to
4758 * change. So we re-scan the device to
4759 * refresh the inquiry data for it.
4761 xpt_scan_lun(newpath.periph, &newpath,
4762 CAM_EXPECT_INQ_CHANGE, NULL);
4764 xpt_release_path(&newpath);
4765 } else if (async_code == AC_LOST_DEVICE) {
4766 device->flags |= CAM_DEV_UNCONFIGURED;
4767 } else if (async_code == AC_TRANSFER_NEG) {
4768 struct ccb_trans_settings *settings;
4770 settings = (struct ccb_trans_settings *)async_arg;
4771 xpt_set_transfer_settings(settings, device,
4772 /*async_update*/TRUE);
4777 xpt_freeze_devq(struct cam_path *path, u_int count)
4780 struct ccb_hdr *ccbh;
4785 path->device->qfrozen_cnt += count;
4788 * Mark the last CCB in the queue as needing
4789 * to be requeued if the driver hasn't
4790 * changed it's state yet. This fixes a race
4791 * where a ccb is just about to be queued to
4792 * a controller driver when it's interrupt routine
4793 * freezes the queue. To completly close the
4794 * hole, controller drives must check to see
4795 * if a ccb's status is still CAM_REQ_INPROG
4796 * under spl protection just before they queue
4797 * the CCB. See ahc_action/ahc_freeze_devq for
4800 ccbh = TAILQ_LAST(&path->device->ccbq.active_ccbs, ccb_hdr_tailq);
4801 if (ccbh && ccbh->status == CAM_REQ_INPROG)
4802 ccbh->status = CAM_REQUEUE_REQ;
4804 return (path->device->qfrozen_cnt);
4808 xpt_freeze_simq(struct cam_sim *sim, u_int count)
4812 sim->devq->send_queue.qfrozen_cnt += count;
4813 if (sim->devq->active_dev != NULL) {
4814 struct ccb_hdr *ccbh;
4816 ccbh = TAILQ_LAST(&sim->devq->active_dev->ccbq.active_ccbs,
4818 if (ccbh && ccbh->status == CAM_REQ_INPROG)
4819 ccbh->status = CAM_REQUEUE_REQ;
4821 return (sim->devq->send_queue.qfrozen_cnt);
4825 xpt_release_devq_timeout(void *arg)
4827 struct cam_ed *device;
4829 device = (struct cam_ed *)arg;
4831 xpt_release_devq_device(device, /*count*/1, /*run_queue*/TRUE);
4835 xpt_release_devq(struct cam_path *path, u_int count, int run_queue)
4839 xpt_release_devq_device(path->device, count, run_queue);
4843 xpt_release_devq_device(struct cam_ed *dev, u_int count, int run_queue)
4851 if (dev->qfrozen_cnt > 0) {
4853 count = (count > dev->qfrozen_cnt) ? dev->qfrozen_cnt : count;
4854 dev->qfrozen_cnt -= count;
4855 if (dev->qfrozen_cnt == 0) {
4858 * No longer need to wait for a successful
4859 * command completion.
4861 dev->flags &= ~CAM_DEV_REL_ON_COMPLETE;
4864 * Remove any timeouts that might be scheduled
4865 * to release this queue.
4867 if ((dev->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0) {
4868 untimeout(xpt_release_devq_timeout, dev,
4870 dev->flags &= ~CAM_DEV_REL_TIMEOUT_PENDING;
4874 * Now that we are unfrozen schedule the
4875 * device so any pending transactions are
4878 if ((dev->ccbq.queue.entries > 0)
4879 && (xpt_schedule_dev_sendq(dev->target->bus, dev))
4880 && (run_queue != 0)) {
4887 xpt_run_dev_sendq(dev->target->bus);
4892 xpt_release_simq(struct cam_sim *sim, int run_queue)
4899 sendq = &(sim->devq->send_queue);
4901 if (sendq->qfrozen_cnt > 0) {
4903 sendq->qfrozen_cnt--;
4904 if (sendq->qfrozen_cnt == 0) {
4908 * If there is a timeout scheduled to release this
4909 * sim queue, remove it. The queue frozen count is
4912 if ((sim->flags & CAM_SIM_REL_TIMEOUT_PENDING) != 0){
4913 untimeout(xpt_release_simq_timeout, sim,
4915 sim->flags &= ~CAM_SIM_REL_TIMEOUT_PENDING;
4917 bus = xpt_find_bus(sim->path_id);
4922 * Now that we are unfrozen run the send queue.
4924 xpt_run_dev_sendq(bus);
4926 xpt_release_bus(bus);
4934 xpt_release_simq_timeout(void *arg)
4936 struct cam_sim *sim;
4938 sim = (struct cam_sim *)arg;
4939 xpt_release_simq(sim, /* run_queue */ TRUE);
4943 xpt_done(union ccb *done_ccb)
4949 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_done\n"));
4950 if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) != 0) {
4952 * Queue up the request for handling by our SWI handler
4953 * any of the "non-immediate" type of ccbs.
4955 switch (done_ccb->ccb_h.path->periph->type) {
4956 case CAM_PERIPH_BIO:
4957 mtx_lock(&cam_bioq_lock);
4958 TAILQ_INSERT_TAIL(&cam_bioq, &done_ccb->ccb_h,
4960 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4961 mtx_unlock(&cam_bioq_lock);
4962 swi_sched(cambio_ih, 0);
4965 panic("unknown periph type %d",
4966 done_ccb->ccb_h.path->periph->type);
4979 new_ccb = malloc(sizeof(*new_ccb), M_CAMXPT, M_WAITOK);
4984 xpt_alloc_ccb_nowait()
4990 new_ccb = malloc(sizeof(*new_ccb), M_CAMXPT, M_NOWAIT);
4995 xpt_free_ccb(union ccb *free_ccb)
4997 free(free_ccb, M_CAMXPT);
5002 /* Private XPT functions */
5005 * Get a CAM control block for the caller. Charge the structure to the device
5006 * referenced by the path. If the this device has no 'credits' then the
5007 * device already has the maximum number of outstanding operations under way
5008 * and we return NULL. If we don't have sufficient resources to allocate more
5009 * ccbs, we also return NULL.
5012 xpt_get_ccb(struct cam_ed *device)
5018 if ((new_ccb = (union ccb *)SLIST_FIRST(&ccb_freeq)) == NULL) {
5019 new_ccb = xpt_alloc_ccb_nowait();
5020 if (new_ccb == NULL) {
5024 callout_handle_init(&new_ccb->ccb_h.timeout_ch);
5025 SLIST_INSERT_HEAD(&ccb_freeq, &new_ccb->ccb_h,
5029 cam_ccbq_take_opening(&device->ccbq);
5030 SLIST_REMOVE_HEAD(&ccb_freeq, xpt_links.sle);
5036 xpt_release_bus(struct cam_eb *bus)
5041 if ((--bus->refcount == 0)
5042 && (TAILQ_FIRST(&bus->et_entries) == NULL)) {
5043 TAILQ_REMOVE(&xpt_busses, bus, links);
5046 free(bus, M_CAMXPT);
5051 static struct cam_et *
5052 xpt_alloc_target(struct cam_eb *bus, target_id_t target_id)
5054 struct cam_et *target;
5056 target = (struct cam_et *)malloc(sizeof(*target), M_CAMXPT, M_NOWAIT);
5057 if (target != NULL) {
5058 struct cam_et *cur_target;
5060 TAILQ_INIT(&target->ed_entries);
5062 target->target_id = target_id;
5063 target->refcount = 1;
5064 target->generation = 0;
5065 timevalclear(&target->last_reset);
5067 * Hold a reference to our parent bus so it
5068 * will not go away before we do.
5072 /* Insertion sort into our bus's target list */
5073 cur_target = TAILQ_FIRST(&bus->et_entries);
5074 while (cur_target != NULL && cur_target->target_id < target_id)
5075 cur_target = TAILQ_NEXT(cur_target, links);
5077 if (cur_target != NULL) {
5078 TAILQ_INSERT_BEFORE(cur_target, target, links);
5080 TAILQ_INSERT_TAIL(&bus->et_entries, target, links);
5088 xpt_release_target(struct cam_eb *bus, struct cam_et *target)
5093 if ((--target->refcount == 0)
5094 && (TAILQ_FIRST(&target->ed_entries) == NULL)) {
5095 TAILQ_REMOVE(&bus->et_entries, target, links);
5098 free(target, M_CAMXPT);
5099 xpt_release_bus(bus);
5104 static struct cam_ed *
5105 xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
5107 #ifdef CAM_NEW_TRAN_CODE
5108 struct cam_path path;
5109 #endif /* CAM_NEW_TRAN_CODE */
5110 struct cam_ed *device;
5111 struct cam_devq *devq;
5114 if (SIM_DEAD(bus->sim))
5117 /* Make space for us in the device queue on our bus */
5118 devq = bus->sim->devq;
5119 status = cam_devq_resize(devq, devq->alloc_queue.array_size + 1);
5121 if (status != CAM_REQ_CMP) {
5124 device = (struct cam_ed *)malloc(sizeof(*device),
5125 M_CAMXPT, M_NOWAIT);
5128 if (device != NULL) {
5129 struct cam_ed *cur_device;
5131 cam_init_pinfo(&device->alloc_ccb_entry.pinfo);
5132 device->alloc_ccb_entry.device = device;
5133 cam_init_pinfo(&device->send_ccb_entry.pinfo);
5134 device->send_ccb_entry.device = device;
5135 device->target = target;
5136 device->lun_id = lun_id;
5137 /* Initialize our queues */
5138 if (camq_init(&device->drvq, 0) != 0) {
5139 free(device, M_CAMXPT);
5142 if (cam_ccbq_init(&device->ccbq,
5143 bus->sim->max_dev_openings) != 0) {
5144 camq_fini(&device->drvq);
5145 free(device, M_CAMXPT);
5148 SLIST_INIT(&device->asyncs);
5149 SLIST_INIT(&device->periphs);
5150 device->generation = 0;
5151 device->owner = NULL;
5153 * Take the default quirk entry until we have inquiry
5154 * data and can determine a better quirk to use.
5156 device->quirk = &xpt_quirk_table[xpt_quirk_table_size - 1];
5157 bzero(&device->inq_data, sizeof(device->inq_data));
5158 device->inq_flags = 0;
5159 device->queue_flags = 0;
5160 device->serial_num = NULL;
5161 device->serial_num_len = 0;
5162 device->qfrozen_cnt = 0;
5163 device->flags = CAM_DEV_UNCONFIGURED;
5164 device->tag_delay_count = 0;
5165 device->tag_saved_openings = 0;
5166 device->refcount = 1;
5167 callout_handle_init(&device->c_handle);
5170 * Hold a reference to our parent target so it
5171 * will not go away before we do.
5176 * XXX should be limited by number of CCBs this bus can
5179 xpt_max_ccbs += device->ccbq.devq_openings;
5180 /* Insertion sort into our target's device list */
5181 cur_device = TAILQ_FIRST(&target->ed_entries);
5182 while (cur_device != NULL && cur_device->lun_id < lun_id)
5183 cur_device = TAILQ_NEXT(cur_device, links);
5184 if (cur_device != NULL) {
5185 TAILQ_INSERT_BEFORE(cur_device, device, links);
5187 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
5189 target->generation++;
5190 #ifdef CAM_NEW_TRAN_CODE
5191 if (lun_id != CAM_LUN_WILDCARD) {
5192 xpt_compile_path(&path,
5197 xpt_devise_transport(&path);
5198 xpt_release_path(&path);
5200 #endif /* CAM_NEW_TRAN_CODE */
5206 xpt_release_device(struct cam_eb *bus, struct cam_et *target,
5207 struct cam_ed *device)
5212 if ((--device->refcount == 0)
5213 && ((device->flags & CAM_DEV_UNCONFIGURED) != 0)) {
5214 struct cam_devq *devq;
5216 if (device->alloc_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX
5217 || device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX)
5218 panic("Removing device while still queued for ccbs");
5220 if ((device->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0)
5221 untimeout(xpt_release_devq_timeout, device,
5224 TAILQ_REMOVE(&target->ed_entries, device,links);
5225 target->generation++;
5226 xpt_max_ccbs -= device->ccbq.devq_openings;
5227 if (!SIM_DEAD(bus->sim)) {
5228 /* Release our slot in the devq */
5229 devq = bus->sim->devq;
5230 cam_devq_resize(devq, devq->alloc_queue.array_size - 1);
5233 camq_fini(&device->drvq);
5234 camq_fini(&device->ccbq.queue);
5235 free(device, M_CAMXPT);
5236 xpt_release_target(bus, target);
5242 xpt_dev_ccbq_resize(struct cam_path *path, int newopenings)
5252 diff = newopenings - (dev->ccbq.dev_active + dev->ccbq.dev_openings);
5253 result = cam_ccbq_resize(&dev->ccbq, newopenings);
5254 if (result == CAM_REQ_CMP && (diff < 0)) {
5255 dev->flags |= CAM_DEV_RESIZE_QUEUE_NEEDED;
5257 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
5258 || (dev->inq_flags & SID_CmdQue) != 0)
5259 dev->tag_saved_openings = newopenings;
5260 /* Adjust the global limit */
5261 xpt_max_ccbs += diff;
5266 static struct cam_eb *
5267 xpt_find_bus(path_id_t path_id)
5271 for (bus = TAILQ_FIRST(&xpt_busses);
5273 bus = TAILQ_NEXT(bus, links)) {
5274 if (bus->path_id == path_id) {
5282 static struct cam_et *
5283 xpt_find_target(struct cam_eb *bus, target_id_t target_id)
5285 struct cam_et *target;
5287 for (target = TAILQ_FIRST(&bus->et_entries);
5289 target = TAILQ_NEXT(target, links)) {
5290 if (target->target_id == target_id) {
5298 static struct cam_ed *
5299 xpt_find_device(struct cam_et *target, lun_id_t lun_id)
5301 struct cam_ed *device;
5303 for (device = TAILQ_FIRST(&target->ed_entries);
5305 device = TAILQ_NEXT(device, links)) {
5306 if (device->lun_id == lun_id) {
5315 union ccb *request_ccb;
5316 struct ccb_pathinq *cpi;
5318 } xpt_scan_bus_info;
5321 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
5322 * As the scan progresses, xpt_scan_bus is used as the
5323 * callback on completion function.
5326 xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
5328 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
5329 ("xpt_scan_bus\n"));
5330 switch (request_ccb->ccb_h.func_code) {
5333 xpt_scan_bus_info *scan_info;
5334 union ccb *work_ccb;
5335 struct cam_path *path;
5340 /* Find out the characteristics of the bus */
5341 work_ccb = xpt_alloc_ccb();
5342 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
5343 request_ccb->ccb_h.pinfo.priority);
5344 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
5345 xpt_action(work_ccb);
5346 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
5347 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
5348 xpt_free_ccb(work_ccb);
5349 xpt_done(request_ccb);
5353 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
5355 * Can't scan the bus on an adapter that
5356 * cannot perform the initiator role.
5358 request_ccb->ccb_h.status = CAM_REQ_CMP;
5359 xpt_free_ccb(work_ccb);
5360 xpt_done(request_ccb);
5364 /* Save some state for use while we probe for devices */
5365 scan_info = (xpt_scan_bus_info *)
5366 malloc(sizeof(xpt_scan_bus_info), M_TEMP, M_WAITOK);
5367 scan_info->request_ccb = request_ccb;
5368 scan_info->cpi = &work_ccb->cpi;
5370 /* Cache on our stack so we can work asynchronously */
5371 max_target = scan_info->cpi->max_target;
5372 initiator_id = scan_info->cpi->initiator_id;
5375 * Don't count the initiator if the
5376 * initiator is addressable.
5378 scan_info->pending_count = max_target + 1;
5379 if (initiator_id <= max_target)
5380 scan_info->pending_count--;
5382 for (i = 0; i <= max_target; i++) {
5384 if (i == initiator_id)
5387 status = xpt_create_path(&path, xpt_periph,
5388 request_ccb->ccb_h.path_id,
5390 if (status != CAM_REQ_CMP) {
5391 printf("xpt_scan_bus: xpt_create_path failed"
5392 " with status %#x, bus scan halted\n",
5396 work_ccb = xpt_alloc_ccb();
5397 xpt_setup_ccb(&work_ccb->ccb_h, path,
5398 request_ccb->ccb_h.pinfo.priority);
5399 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
5400 work_ccb->ccb_h.cbfcnp = xpt_scan_bus;
5401 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
5402 work_ccb->crcn.flags = request_ccb->crcn.flags;
5403 xpt_action(work_ccb);
5409 xpt_scan_bus_info *scan_info;
5411 target_id_t target_id;
5414 /* Reuse the same CCB to query if a device was really found */
5415 scan_info = (xpt_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
5416 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
5417 request_ccb->ccb_h.pinfo.priority);
5418 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
5420 path_id = request_ccb->ccb_h.path_id;
5421 target_id = request_ccb->ccb_h.target_id;
5422 lun_id = request_ccb->ccb_h.target_lun;
5423 xpt_action(request_ccb);
5425 if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
5426 struct cam_ed *device;
5427 struct cam_et *target;
5431 * If we already probed lun 0 successfully, or
5432 * we have additional configured luns on this
5433 * target that might have "gone away", go onto
5436 target = request_ccb->ccb_h.path->target;
5438 * We may touch devices that we don't
5439 * hold references too, so ensure they
5440 * don't disappear out from under us.
5441 * The target above is referenced by the
5442 * path in the request ccb.
5446 device = TAILQ_FIRST(&target->ed_entries);
5447 if (device != NULL) {
5448 phl = CAN_SRCH_HI_SPARSE(device);
5449 if (device->lun_id == 0)
5450 device = TAILQ_NEXT(device, links);
5453 if ((lun_id != 0) || (device != NULL)) {
5454 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl)
5458 struct cam_ed *device;
5460 device = request_ccb->ccb_h.path->device;
5462 if ((device->quirk->quirks & CAM_QUIRK_NOLUNS) == 0) {
5463 /* Try the next lun */
5464 if (lun_id < (CAM_SCSI2_MAXLUN-1)
5465 || CAN_SRCH_HI_DENSE(device))
5470 xpt_free_path(request_ccb->ccb_h.path);
5473 if ((lun_id == request_ccb->ccb_h.target_lun)
5474 || lun_id > scan_info->cpi->max_lun) {
5477 xpt_free_ccb(request_ccb);
5478 scan_info->pending_count--;
5479 if (scan_info->pending_count == 0) {
5480 xpt_free_ccb((union ccb *)scan_info->cpi);
5481 request_ccb = scan_info->request_ccb;
5482 free(scan_info, M_TEMP);
5483 request_ccb->ccb_h.status = CAM_REQ_CMP;
5484 xpt_done(request_ccb);
5487 /* Try the next device */
5488 struct cam_path *path;
5491 status = xpt_create_path(&path, xpt_periph,
5492 path_id, target_id, lun_id);
5493 if (status != CAM_REQ_CMP) {
5494 printf("xpt_scan_bus: xpt_create_path failed "
5495 "with status %#x, halting LUN scan\n",
5497 xpt_free_ccb(request_ccb);
5498 scan_info->pending_count--;
5499 if (scan_info->pending_count == 0) {
5501 (union ccb *)scan_info->cpi);
5502 request_ccb = scan_info->request_ccb;
5503 free(scan_info, M_TEMP);
5504 request_ccb->ccb_h.status = CAM_REQ_CMP;
5505 xpt_done(request_ccb);
5509 xpt_setup_ccb(&request_ccb->ccb_h, path,
5510 request_ccb->ccb_h.pinfo.priority);
5511 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
5512 request_ccb->ccb_h.cbfcnp = xpt_scan_bus;
5513 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
5514 request_ccb->crcn.flags =
5515 scan_info->request_ccb->crcn.flags;
5516 xpt_action(request_ccb);
5531 PROBE_TUR_FOR_NEGOTIATION
5535 PROBE_INQUIRY_CKSUM = 0x01,
5536 PROBE_SERIAL_CKSUM = 0x02,
5537 PROBE_NO_ANNOUNCE = 0x04
5541 TAILQ_HEAD(, ccb_hdr) request_ccbs;
5542 probe_action action;
5543 union ccb saved_ccb;
5546 u_int8_t digest[16];
5550 xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
5551 cam_flags flags, union ccb *request_ccb)
5553 struct ccb_pathinq cpi;
5555 struct cam_path *new_path;
5556 struct cam_periph *old_periph;
5559 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
5560 ("xpt_scan_lun\n"));
5562 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
5563 cpi.ccb_h.func_code = XPT_PATH_INQ;
5564 xpt_action((union ccb *)&cpi);
5566 if (cpi.ccb_h.status != CAM_REQ_CMP) {
5567 if (request_ccb != NULL) {
5568 request_ccb->ccb_h.status = cpi.ccb_h.status;
5569 xpt_done(request_ccb);
5574 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
5576 * Can't scan the bus on an adapter that
5577 * cannot perform the initiator role.
5579 if (request_ccb != NULL) {
5580 request_ccb->ccb_h.status = CAM_REQ_CMP;
5581 xpt_done(request_ccb);
5586 if (request_ccb == NULL) {
5587 request_ccb = malloc(sizeof(union ccb), M_TEMP, M_NOWAIT);
5588 if (request_ccb == NULL) {
5589 xpt_print_path(path);
5590 printf("xpt_scan_lun: can't allocate CCB, can't "
5594 new_path = malloc(sizeof(*new_path), M_TEMP, M_NOWAIT);
5595 if (new_path == NULL) {
5596 xpt_print_path(path);
5597 printf("xpt_scan_lun: can't allocate path, can't "
5599 free(request_ccb, M_TEMP);
5602 status = xpt_compile_path(new_path, xpt_periph,
5604 path->target->target_id,
5605 path->device->lun_id);
5607 if (status != CAM_REQ_CMP) {
5608 xpt_print_path(path);
5609 printf("xpt_scan_lun: can't compile path, can't "
5611 free(request_ccb, M_TEMP);
5612 free(new_path, M_TEMP);
5615 xpt_setup_ccb(&request_ccb->ccb_h, new_path, /*priority*/ 1);
5616 request_ccb->ccb_h.cbfcnp = xptscandone;
5617 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
5618 request_ccb->crcn.flags = flags;
5622 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
5625 softc = (probe_softc *)old_periph->softc;
5626 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
5629 status = cam_periph_alloc(proberegister, NULL, probecleanup,
5630 probestart, "probe",
5632 request_ccb->ccb_h.path, NULL, 0,
5635 if (status != CAM_REQ_CMP) {
5636 xpt_print_path(path);
5637 printf("xpt_scan_lun: cam_alloc_periph returned an "
5638 "error, can't continue probe\n");
5639 request_ccb->ccb_h.status = status;
5640 xpt_done(request_ccb);
5647 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
5649 xpt_release_path(done_ccb->ccb_h.path);
5650 free(done_ccb->ccb_h.path, M_TEMP);
5651 free(done_ccb, M_TEMP);
5655 proberegister(struct cam_periph *periph, void *arg)
5657 union ccb *request_ccb; /* CCB representing the probe request */
5660 request_ccb = (union ccb *)arg;
5661 if (periph == NULL) {
5662 printf("proberegister: periph was NULL!!\n");
5663 return(CAM_REQ_CMP_ERR);
5666 if (request_ccb == NULL) {
5667 printf("proberegister: no probe CCB, "
5668 "can't register device\n");
5669 return(CAM_REQ_CMP_ERR);
5672 softc = (probe_softc *)malloc(sizeof(*softc), M_TEMP, M_NOWAIT);
5674 if (softc == NULL) {
5675 printf("proberegister: Unable to probe new device. "
5676 "Unable to allocate softc\n");
5677 return(CAM_REQ_CMP_ERR);
5679 TAILQ_INIT(&softc->request_ccbs);
5680 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
5683 periph->softc = softc;
5684 cam_periph_acquire(periph);
5686 * Ensure we've waited at least a bus settle
5687 * delay before attempting to probe the device.
5688 * For HBAs that don't do bus resets, this won't make a difference.
5690 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
5692 probeschedule(periph);
5693 return(CAM_REQ_CMP);
5697 probeschedule(struct cam_periph *periph)
5699 struct ccb_pathinq cpi;
5703 softc = (probe_softc *)periph->softc;
5704 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
5706 xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
5707 cpi.ccb_h.func_code = XPT_PATH_INQ;
5708 xpt_action((union ccb *)&cpi);
5711 * If a device has gone away and another device, or the same one,
5712 * is back in the same place, it should have a unit attention
5713 * condition pending. It will not report the unit attention in
5714 * response to an inquiry, which may leave invalid transfer
5715 * negotiations in effect. The TUR will reveal the unit attention
5716 * condition. Only send the TUR for lun 0, since some devices
5717 * will get confused by commands other than inquiry to non-existent
5718 * luns. If you think a device has gone away start your scan from
5719 * lun 0. This will insure that any bogus transfer settings are
5722 * If we haven't seen the device before and the controller supports
5723 * some kind of transfer negotiation, negotiate with the first
5724 * sent command if no bus reset was performed at startup. This
5725 * ensures that the device is not confused by transfer negotiation
5726 * settings left over by loader or BIOS action.
5728 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
5729 && (ccb->ccb_h.target_lun == 0)) {
5730 softc->action = PROBE_TUR;
5731 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
5732 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
5733 proberequestdefaultnegotiation(periph);
5734 softc->action = PROBE_INQUIRY;
5736 softc->action = PROBE_INQUIRY;
5739 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
5740 softc->flags |= PROBE_NO_ANNOUNCE;
5742 softc->flags &= ~PROBE_NO_ANNOUNCE;
5744 xpt_schedule(periph, ccb->ccb_h.pinfo.priority);
5748 probestart(struct cam_periph *periph, union ccb *start_ccb)
5750 /* Probe the device that our peripheral driver points to */
5751 struct ccb_scsiio *csio;
5754 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
5756 softc = (probe_softc *)periph->softc;
5757 csio = &start_ccb->csio;
5759 switch (softc->action) {
5761 case PROBE_TUR_FOR_NEGOTIATION:
5763 scsi_test_unit_ready(csio,
5772 case PROBE_FULL_INQUIRY:
5775 struct scsi_inquiry_data *inq_buf;
5777 inq_buf = &periph->path->device->inq_data;
5779 * If the device is currently configured, we calculate an
5780 * MD5 checksum of the inquiry data, and if the serial number
5781 * length is greater than 0, add the serial number data
5782 * into the checksum as well. Once the inquiry and the
5783 * serial number check finish, we attempt to figure out
5784 * whether we still have the same device.
5786 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
5788 MD5Init(&softc->context);
5789 MD5Update(&softc->context, (unsigned char *)inq_buf,
5790 sizeof(struct scsi_inquiry_data));
5791 softc->flags |= PROBE_INQUIRY_CKSUM;
5792 if (periph->path->device->serial_num_len > 0) {
5793 MD5Update(&softc->context,
5794 periph->path->device->serial_num,
5795 periph->path->device->serial_num_len);
5796 softc->flags |= PROBE_SERIAL_CKSUM;
5798 MD5Final(softc->digest, &softc->context);
5801 if (softc->action == PROBE_INQUIRY)
5802 inquiry_len = SHORT_INQUIRY_LENGTH;
5804 inquiry_len = inq_buf->additional_length
5805 + offsetof(struct scsi_inquiry_data,
5806 additional_length) + 1;
5809 * Some parallel SCSI devices fail to send an
5810 * ignore wide residue message when dealing with
5811 * odd length inquiry requests. Round up to be
5814 inquiry_len = roundup2(inquiry_len, 2);
5820 (u_int8_t *)inq_buf,
5825 /*timeout*/60 * 1000);
5828 case PROBE_MODE_SENSE:
5833 mode_buf_len = sizeof(struct scsi_mode_header_6)
5834 + sizeof(struct scsi_mode_blk_desc)
5835 + sizeof(struct scsi_control_page);
5836 mode_buf = malloc(mode_buf_len, M_TEMP, M_NOWAIT);
5837 if (mode_buf != NULL) {
5838 scsi_mode_sense(csio,
5843 SMS_PAGE_CTRL_CURRENT,
5844 SMS_CONTROL_MODE_PAGE,
5851 xpt_print_path(periph->path);
5852 printf("Unable to mode sense control page - malloc failure\n");
5853 softc->action = PROBE_SERIAL_NUM;
5856 case PROBE_SERIAL_NUM:
5858 struct scsi_vpd_unit_serial_number *serial_buf;
5859 struct cam_ed* device;
5862 device = periph->path->device;
5863 device->serial_num = NULL;
5864 device->serial_num_len = 0;
5866 if ((device->quirk->quirks & CAM_QUIRK_NOSERIAL) == 0)
5867 serial_buf = (struct scsi_vpd_unit_serial_number *)
5868 malloc(sizeof(*serial_buf), M_TEMP,
5871 if (serial_buf != NULL) {
5876 (u_int8_t *)serial_buf,
5877 sizeof(*serial_buf),
5879 SVPD_UNIT_SERIAL_NUMBER,
5881 /*timeout*/60 * 1000);
5885 * We'll have to do without, let our probedone
5886 * routine finish up for us.
5888 start_ccb->csio.data_ptr = NULL;
5889 probedone(periph, start_ccb);
5893 xpt_action(start_ccb);
5897 proberequestdefaultnegotiation(struct cam_periph *periph)
5899 struct ccb_trans_settings cts;
5901 xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
5902 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
5903 #ifdef CAM_NEW_TRAN_CODE
5904 cts.type = CTS_TYPE_USER_SETTINGS;
5905 #else /* CAM_NEW_TRAN_CODE */
5906 cts.flags = CCB_TRANS_USER_SETTINGS;
5907 #endif /* CAM_NEW_TRAN_CODE */
5908 xpt_action((union ccb *)&cts);
5909 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
5910 #ifdef CAM_NEW_TRAN_CODE
5911 cts.type = CTS_TYPE_CURRENT_SETTINGS;
5912 #else /* CAM_NEW_TRAN_CODE */
5913 cts.flags &= ~CCB_TRANS_USER_SETTINGS;
5914 cts.flags |= CCB_TRANS_CURRENT_SETTINGS;
5915 #endif /* CAM_NEW_TRAN_CODE */
5916 xpt_action((union ccb *)&cts);
5920 probedone(struct cam_periph *periph, union ccb *done_ccb)
5923 struct cam_path *path;
5926 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
5928 softc = (probe_softc *)periph->softc;
5929 path = done_ccb->ccb_h.path;
5930 priority = done_ccb->ccb_h.pinfo.priority;
5932 switch (softc->action) {
5935 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5937 if (cam_periph_error(done_ccb, 0,
5938 SF_NO_PRINT, NULL) == ERESTART)
5940 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5941 /* Don't wedge the queue */
5942 xpt_release_devq(done_ccb->ccb_h.path,
5946 softc->action = PROBE_INQUIRY;
5947 xpt_release_ccb(done_ccb);
5948 xpt_schedule(periph, priority);
5952 case PROBE_FULL_INQUIRY:
5954 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5955 struct scsi_inquiry_data *inq_buf;
5956 u_int8_t periph_qual;
5958 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
5959 inq_buf = &path->device->inq_data;
5961 periph_qual = SID_QUAL(inq_buf);
5963 switch(periph_qual) {
5964 case SID_QUAL_LU_CONNECTED:
5969 * We conservatively request only
5970 * SHORT_INQUIRY_LEN bytes of inquiry
5971 * information during our first try
5972 * at sending an INQUIRY. If the device
5973 * has more information to give,
5974 * perform a second request specifying
5975 * the amount of information the device
5976 * is willing to give.
5978 len = inq_buf->additional_length
5979 + offsetof(struct scsi_inquiry_data,
5980 additional_length) + 1;
5981 if (softc->action == PROBE_INQUIRY
5982 && len > SHORT_INQUIRY_LENGTH) {
5983 softc->action = PROBE_FULL_INQUIRY;
5984 xpt_release_ccb(done_ccb);
5985 xpt_schedule(periph, priority);
5989 xpt_find_quirk(path->device);
5991 #ifdef CAM_NEW_TRAN_CODE
5992 xpt_devise_transport(path);
5993 #endif /* CAM_NEW_TRAN_CODE */
5994 if ((inq_buf->flags & SID_CmdQue) != 0)
5995 softc->action = PROBE_MODE_SENSE;
5997 softc->action = PROBE_SERIAL_NUM;
5999 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
6001 xpt_release_ccb(done_ccb);
6002 xpt_schedule(periph, priority);
6008 } else if (cam_periph_error(done_ccb, 0,
6009 done_ccb->ccb_h.target_lun > 0
6010 ? SF_RETRY_UA|SF_QUIET_IR
6012 &softc->saved_ccb) == ERESTART) {
6014 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
6015 /* Don't wedge the queue */
6016 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
6020 * If we get to this point, we got an error status back
6021 * from the inquiry and the error status doesn't require
6022 * automatically retrying the command. Therefore, the
6023 * inquiry failed. If we had inquiry information before
6024 * for this device, but this latest inquiry command failed,
6025 * the device has probably gone away. If this device isn't
6026 * already marked unconfigured, notify the peripheral
6027 * drivers that this device is no more.
6029 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
6030 /* Send the async notification. */
6031 xpt_async(AC_LOST_DEVICE, path, NULL);
6033 xpt_release_ccb(done_ccb);
6036 case PROBE_MODE_SENSE:
6038 struct ccb_scsiio *csio;
6039 struct scsi_mode_header_6 *mode_hdr;
6041 csio = &done_ccb->csio;
6042 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
6043 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
6044 struct scsi_control_page *page;
6047 offset = ((u_int8_t *)&mode_hdr[1])
6048 + mode_hdr->blk_desc_len;
6049 page = (struct scsi_control_page *)offset;
6050 path->device->queue_flags = page->queue_flags;
6051 } else if (cam_periph_error(done_ccb, 0,
6052 SF_RETRY_UA|SF_NO_PRINT,
6053 &softc->saved_ccb) == ERESTART) {
6055 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
6056 /* Don't wedge the queue */
6057 xpt_release_devq(done_ccb->ccb_h.path,
6058 /*count*/1, /*run_queue*/TRUE);
6060 xpt_release_ccb(done_ccb);
6061 free(mode_hdr, M_TEMP);
6062 softc->action = PROBE_SERIAL_NUM;
6063 xpt_schedule(periph, priority);
6066 case PROBE_SERIAL_NUM:
6068 struct ccb_scsiio *csio;
6069 struct scsi_vpd_unit_serial_number *serial_buf;
6076 csio = &done_ccb->csio;
6077 priority = done_ccb->ccb_h.pinfo.priority;
6079 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
6081 /* Clean up from previous instance of this device */
6082 if (path->device->serial_num != NULL) {
6083 free(path->device->serial_num, M_CAMXPT);
6084 path->device->serial_num = NULL;
6085 path->device->serial_num_len = 0;
6088 if (serial_buf == NULL) {
6090 * Don't process the command as it was never sent
6092 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
6093 && (serial_buf->length > 0)) {
6096 path->device->serial_num =
6097 (u_int8_t *)malloc((serial_buf->length + 1),
6098 M_CAMXPT, M_NOWAIT);
6099 if (path->device->serial_num != NULL) {
6100 bcopy(serial_buf->serial_num,
6101 path->device->serial_num,
6102 serial_buf->length);
6103 path->device->serial_num_len =
6105 path->device->serial_num[serial_buf->length]
6108 } else if (cam_periph_error(done_ccb, 0,
6109 SF_RETRY_UA|SF_NO_PRINT,
6110 &softc->saved_ccb) == ERESTART) {
6112 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
6113 /* Don't wedge the queue */
6114 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
6119 * Let's see if we have seen this device before.
6121 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
6123 u_int8_t digest[16];
6128 (unsigned char *)&path->device->inq_data,
6129 sizeof(struct scsi_inquiry_data));
6132 MD5Update(&context, serial_buf->serial_num,
6133 serial_buf->length);
6135 MD5Final(digest, &context);
6136 if (bcmp(softc->digest, digest, 16) == 0)
6140 * XXX Do we need to do a TUR in order to ensure
6141 * that the device really hasn't changed???
6144 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
6145 xpt_async(AC_LOST_DEVICE, path, NULL);
6147 if (serial_buf != NULL)
6148 free(serial_buf, M_TEMP);
6152 * Now that we have all the necessary
6153 * information to safely perform transfer
6154 * negotiations... Controllers don't perform
6155 * any negotiation or tagged queuing until
6156 * after the first XPT_SET_TRAN_SETTINGS ccb is
6157 * received. So, on a new device, just retreive
6158 * the user settings, and set them as the current
6159 * settings to set the device up.
6161 proberequestdefaultnegotiation(periph);
6162 xpt_release_ccb(done_ccb);
6165 * Perform a TUR to allow the controller to
6166 * perform any necessary transfer negotiation.
6168 softc->action = PROBE_TUR_FOR_NEGOTIATION;
6169 xpt_schedule(periph, priority);
6172 xpt_release_ccb(done_ccb);
6175 case PROBE_TUR_FOR_NEGOTIATION:
6176 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
6177 /* Don't wedge the queue */
6178 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
6182 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
6184 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
6185 /* Inform the XPT that a new device has been found */
6186 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
6187 xpt_action(done_ccb);
6189 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
6192 xpt_release_ccb(done_ccb);
6195 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
6196 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
6197 done_ccb->ccb_h.status = CAM_REQ_CMP;
6199 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
6200 cam_periph_invalidate(periph);
6201 cam_periph_release(periph);
6203 probeschedule(periph);
6208 probecleanup(struct cam_periph *periph)
6210 free(periph->softc, M_TEMP);
6214 xpt_find_quirk(struct cam_ed *device)
6218 match = cam_quirkmatch((caddr_t)&device->inq_data,
6219 (caddr_t)xpt_quirk_table,
6220 sizeof(xpt_quirk_table)/sizeof(*xpt_quirk_table),
6221 sizeof(*xpt_quirk_table), scsi_inquiry_match);
6224 panic("xpt_find_quirk: device didn't match wildcard entry!!");
6226 device->quirk = (struct xpt_quirk_entry *)match;
6230 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
6235 error = sysctl_handle_int(oidp, &bool, sizeof(bool), req);
6236 if (error != 0 || req->newptr == NULL)
6238 if (bool == 0 || bool == 1) {
6246 #ifdef CAM_NEW_TRAN_CODE
6249 xpt_devise_transport(struct cam_path *path)
6251 struct ccb_pathinq cpi;
6252 struct ccb_trans_settings cts;
6253 struct scsi_inquiry_data *inq_buf;
6255 /* Get transport information from the SIM */
6256 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
6257 cpi.ccb_h.func_code = XPT_PATH_INQ;
6258 xpt_action((union ccb *)&cpi);
6261 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
6262 inq_buf = &path->device->inq_data;
6263 path->device->protocol = PROTO_SCSI;
6264 path->device->protocol_version =
6265 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
6266 path->device->transport = cpi.transport;
6267 path->device->transport_version = cpi.transport_version;
6270 * Any device not using SPI3 features should
6271 * be considered SPI2 or lower.
6273 if (inq_buf != NULL) {
6274 if (path->device->transport == XPORT_SPI
6275 && (inq_buf->spi3data & SID_SPI_MASK) == 0
6276 && path->device->transport_version > 2)
6277 path->device->transport_version = 2;
6279 struct cam_ed* otherdev;
6281 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
6283 otherdev = TAILQ_NEXT(otherdev, links)) {
6284 if (otherdev != path->device)
6288 if (otherdev != NULL) {
6290 * Initially assume the same versioning as
6291 * prior luns for this target.
6293 path->device->protocol_version =
6294 otherdev->protocol_version;
6295 path->device->transport_version =
6296 otherdev->transport_version;
6298 /* Until we know better, opt for safty */
6299 path->device->protocol_version = 2;
6300 if (path->device->transport == XPORT_SPI)
6301 path->device->transport_version = 2;
6303 path->device->transport_version = 0;
6309 * For a device compliant with SPC-2 we should be able
6310 * to determine the transport version supported by
6311 * scrutinizing the version descriptors in the
6315 /* Tell the controller what we think */
6316 xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
6317 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
6318 cts.type = CTS_TYPE_CURRENT_SETTINGS;
6319 cts.transport = path->device->transport;
6320 cts.transport_version = path->device->transport_version;
6321 cts.protocol = path->device->protocol;
6322 cts.protocol_version = path->device->protocol_version;
6323 cts.proto_specific.valid = 0;
6324 cts.xport_specific.valid = 0;
6325 xpt_action((union ccb *)&cts);
6329 xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
6332 struct ccb_pathinq cpi;
6333 struct ccb_trans_settings cur_cts;
6334 struct ccb_trans_settings_scsi *scsi;
6335 struct ccb_trans_settings_scsi *cur_scsi;
6336 struct cam_sim *sim;
6337 struct scsi_inquiry_data *inq_data;
6339 if (device == NULL) {
6340 cts->ccb_h.status = CAM_PATH_INVALID;
6341 xpt_done((union ccb *)cts);
6345 if (cts->protocol == PROTO_UNKNOWN
6346 || cts->protocol == PROTO_UNSPECIFIED) {
6347 cts->protocol = device->protocol;
6348 cts->protocol_version = device->protocol_version;
6351 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
6352 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
6353 cts->protocol_version = device->protocol_version;
6355 if (cts->protocol != device->protocol) {
6356 xpt_print_path(cts->ccb_h.path);
6357 printf("Uninitialized Protocol %x:%x?\n",
6358 cts->protocol, device->protocol);
6359 cts->protocol = device->protocol;
6362 if (cts->protocol_version > device->protocol_version) {
6364 xpt_print_path(cts->ccb_h.path);
6365 printf("Down reving Protocol Version from %d to %d?\n",
6366 cts->protocol_version, device->protocol_version);
6368 cts->protocol_version = device->protocol_version;
6371 if (cts->transport == XPORT_UNKNOWN
6372 || cts->transport == XPORT_UNSPECIFIED) {
6373 cts->transport = device->transport;
6374 cts->transport_version = device->transport_version;
6377 if (cts->transport_version == XPORT_VERSION_UNKNOWN
6378 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
6379 cts->transport_version = device->transport_version;
6381 if (cts->transport != device->transport) {
6382 xpt_print_path(cts->ccb_h.path);
6383 printf("Uninitialized Transport %x:%x?\n",
6384 cts->transport, device->transport);
6385 cts->transport = device->transport;
6388 if (cts->transport_version > device->transport_version) {
6390 xpt_print_path(cts->ccb_h.path);
6391 printf("Down reving Transport Version from %d to %d?\n",
6392 cts->transport_version,
6393 device->transport_version);
6395 cts->transport_version = device->transport_version;
6398 sim = cts->ccb_h.path->bus->sim;
6401 * Nothing more of interest to do unless
6402 * this is a device connected via the
6405 if (cts->protocol != PROTO_SCSI) {
6406 if (async_update == FALSE)
6407 (*(sim->sim_action))(sim, (union ccb *)cts);
6411 inq_data = &device->inq_data;
6412 scsi = &cts->proto_specific.scsi;
6413 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
6414 cpi.ccb_h.func_code = XPT_PATH_INQ;
6415 xpt_action((union ccb *)&cpi);
6417 /* SCSI specific sanity checking */
6418 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
6419 || (inq_data->flags & SID_CmdQue) == 0
6420 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
6421 || (device->quirk->mintags == 0)) {
6423 * Can't tag on hardware that doesn't support tags,
6424 * doesn't have it enabled, or has broken tag support.
6426 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
6429 if (async_update == FALSE) {
6431 * Perform sanity checking against what the
6432 * controller and device can do.
6434 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, /*priority*/1);
6435 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
6436 cur_cts.type = cts->type;
6437 xpt_action((union ccb *)&cur_cts);
6439 cur_scsi = &cur_cts.proto_specific.scsi;
6440 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
6441 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
6442 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
6444 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
6445 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
6448 /* SPI specific sanity checking */
6449 if (cts->transport == XPORT_SPI && async_update == FALSE) {
6451 struct ccb_trans_settings_spi *spi;
6452 struct ccb_trans_settings_spi *cur_spi;
6454 spi = &cts->xport_specific.spi;
6456 cur_spi = &cur_cts.xport_specific.spi;
6458 /* Fill in any gaps in what the user gave us */
6459 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
6460 spi->sync_period = cur_spi->sync_period;
6461 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
6462 spi->sync_period = 0;
6463 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
6464 spi->sync_offset = cur_spi->sync_offset;
6465 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
6466 spi->sync_offset = 0;
6467 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
6468 spi->ppr_options = cur_spi->ppr_options;
6469 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
6470 spi->ppr_options = 0;
6471 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
6472 spi->bus_width = cur_spi->bus_width;
6473 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
6475 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
6476 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
6477 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
6479 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
6480 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
6481 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
6482 && (inq_data->flags & SID_Sync) == 0
6483 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
6484 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)
6485 || (cur_spi->sync_offset == 0)
6486 || (cur_spi->sync_period == 0)) {
6488 spi->sync_period = 0;
6489 spi->sync_offset = 0;
6492 switch (spi->bus_width) {
6493 case MSG_EXT_WDTR_BUS_32_BIT:
6494 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
6495 || (inq_data->flags & SID_WBus32) != 0
6496 || cts->type == CTS_TYPE_USER_SETTINGS)
6497 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
6499 /* Fall Through to 16-bit */
6500 case MSG_EXT_WDTR_BUS_16_BIT:
6501 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
6502 || (inq_data->flags & SID_WBus16) != 0
6503 || cts->type == CTS_TYPE_USER_SETTINGS)
6504 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
6505 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
6508 /* Fall Through to 8-bit */
6509 default: /* New bus width?? */
6510 case MSG_EXT_WDTR_BUS_8_BIT:
6511 /* All targets can do this */
6512 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
6516 spi3caps = cpi.xport_specific.spi.ppr_options;
6517 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
6518 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
6519 spi3caps &= inq_data->spi3data;
6521 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
6522 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
6524 if ((spi3caps & SID_SPI_IUS) == 0)
6525 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
6527 if ((spi3caps & SID_SPI_QAS) == 0)
6528 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
6530 /* No SPI Transfer settings are allowed unless we are wide */
6531 if (spi->bus_width == 0)
6532 spi->ppr_options = 0;
6534 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0) {
6536 * Can't tag queue without disconnection.
6538 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
6539 scsi->valid |= CTS_SCSI_VALID_TQ;
6543 * If we are currently performing tagged transactions to
6544 * this device and want to change its negotiation parameters,
6545 * go non-tagged for a bit to give the controller a chance to
6546 * negotiate unhampered by tag messages.
6548 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
6549 && (device->inq_flags & SID_CmdQue) != 0
6550 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
6551 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
6552 CTS_SPI_VALID_SYNC_OFFSET|
6553 CTS_SPI_VALID_BUS_WIDTH)) != 0)
6554 xpt_toggle_tags(cts->ccb_h.path);
6557 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
6558 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
6562 * If we are transitioning from tags to no-tags or
6563 * vice-versa, we need to carefully freeze and restart
6564 * the queue so that we don't overlap tagged and non-tagged
6565 * commands. We also temporarily stop tags if there is
6566 * a change in transfer negotiation settings to allow
6567 * "tag-less" negotiation.
6569 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
6570 || (device->inq_flags & SID_CmdQue) != 0)
6571 device_tagenb = TRUE;
6573 device_tagenb = FALSE;
6575 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
6576 && device_tagenb == FALSE)
6577 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
6578 && device_tagenb == TRUE)) {
6580 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
6582 * Delay change to use tags until after a
6583 * few commands have gone to this device so
6584 * the controller has time to perform transfer
6585 * negotiations without tagged messages getting
6588 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
6589 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
6591 struct ccb_relsim crs;
6593 xpt_freeze_devq(cts->ccb_h.path, /*count*/1);
6594 device->inq_flags &= ~SID_CmdQue;
6595 xpt_dev_ccbq_resize(cts->ccb_h.path,
6596 sim->max_dev_openings);
6597 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
6598 device->tag_delay_count = 0;
6600 xpt_setup_ccb(&crs.ccb_h, cts->ccb_h.path,
6602 crs.ccb_h.func_code = XPT_REL_SIMQ;
6603 crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
6605 = crs.release_timeout
6608 xpt_action((union ccb *)&crs);
6612 if (async_update == FALSE)
6613 (*(sim->sim_action))(sim, (union ccb *)cts);
6616 #else /* CAM_NEW_TRAN_CODE */
6619 xpt_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
6622 struct cam_sim *sim;
6625 sim = cts->ccb_h.path->bus->sim;
6626 if (async_update == FALSE) {
6627 struct scsi_inquiry_data *inq_data;
6628 struct ccb_pathinq cpi;
6629 struct ccb_trans_settings cur_cts;
6631 if (device == NULL) {
6632 cts->ccb_h.status = CAM_PATH_INVALID;
6633 xpt_done((union ccb *)cts);
6638 * Perform sanity checking against what the
6639 * controller and device can do.
6641 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
6642 cpi.ccb_h.func_code = XPT_PATH_INQ;
6643 xpt_action((union ccb *)&cpi);
6644 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, /*priority*/1);
6645 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
6646 cur_cts.flags = CCB_TRANS_CURRENT_SETTINGS;
6647 xpt_action((union ccb *)&cur_cts);
6648 inq_data = &device->inq_data;
6650 /* Fill in any gaps in what the user gave us */
6651 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) == 0)
6652 cts->sync_period = cur_cts.sync_period;
6653 if ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) == 0)
6654 cts->sync_offset = cur_cts.sync_offset;
6655 if ((cts->valid & CCB_TRANS_BUS_WIDTH_VALID) == 0)
6656 cts->bus_width = cur_cts.bus_width;
6657 if ((cts->valid & CCB_TRANS_DISC_VALID) == 0) {
6658 cts->flags &= ~CCB_TRANS_DISC_ENB;
6659 cts->flags |= cur_cts.flags & CCB_TRANS_DISC_ENB;
6661 if ((cts->valid & CCB_TRANS_TQ_VALID) == 0) {
6662 cts->flags &= ~CCB_TRANS_TAG_ENB;
6663 cts->flags |= cur_cts.flags & CCB_TRANS_TAG_ENB;
6666 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
6667 && (inq_data->flags & SID_Sync) == 0)
6668 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)
6669 || (cts->sync_offset == 0)
6670 || (cts->sync_period == 0)) {
6672 cts->sync_period = 0;
6673 cts->sync_offset = 0;
6674 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
6675 && (inq_data->spi3data & SID_SPI_CLOCK_DT) == 0
6676 && cts->sync_period <= 0x9) {
6678 * Don't allow DT transmission rates if the
6679 * device does not support it.
6681 cts->sync_period = 0xa;
6684 switch (cts->bus_width) {
6685 case MSG_EXT_WDTR_BUS_32_BIT:
6686 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
6687 || (inq_data->flags & SID_WBus32) != 0)
6688 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
6690 /* FALLTHROUGH to 16-bit */
6691 case MSG_EXT_WDTR_BUS_16_BIT:
6692 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
6693 || (inq_data->flags & SID_WBus16) != 0)
6694 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
6695 cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
6698 /* FALLTHROUGH to 8-bit */
6699 default: /* New bus width?? */
6700 case MSG_EXT_WDTR_BUS_8_BIT:
6701 /* All targets can do this */
6702 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
6706 if ((cts->flags & CCB_TRANS_DISC_ENB) == 0) {
6708 * Can't tag queue without disconnection.
6710 cts->flags &= ~CCB_TRANS_TAG_ENB;
6711 cts->valid |= CCB_TRANS_TQ_VALID;
6714 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
6715 || (inq_data->flags & SID_CmdQue) == 0
6716 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
6717 || (device->quirk->mintags == 0)) {
6719 * Can't tag on hardware that doesn't support,
6720 * doesn't have it enabled, or has broken tag support.
6722 cts->flags &= ~CCB_TRANS_TAG_ENB;
6727 if ((cts->valid & CCB_TRANS_TQ_VALID) != 0) {
6731 * If we are transitioning from tags to no-tags or
6732 * vice-versa, we need to carefully freeze and restart
6733 * the queue so that we don't overlap tagged and non-tagged
6734 * commands. We also temporarily stop tags if there is
6735 * a change in transfer negotiation settings to allow
6736 * "tag-less" negotiation.
6738 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
6739 || (device->inq_flags & SID_CmdQue) != 0)
6740 device_tagenb = TRUE;
6742 device_tagenb = FALSE;
6744 if (((cts->flags & CCB_TRANS_TAG_ENB) != 0
6745 && device_tagenb == FALSE)
6746 || ((cts->flags & CCB_TRANS_TAG_ENB) == 0
6747 && device_tagenb == TRUE)) {
6749 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0) {
6751 * Delay change to use tags until after a
6752 * few commands have gone to this device so
6753 * the controller has time to perform transfer
6754 * negotiations without tagged messages getting
6757 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
6758 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
6760 xpt_freeze_devq(cts->ccb_h.path, /*count*/1);
6762 device->inq_flags &= ~SID_CmdQue;
6763 xpt_dev_ccbq_resize(cts->ccb_h.path,
6764 sim->max_dev_openings);
6765 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
6766 device->tag_delay_count = 0;
6771 if (async_update == FALSE) {
6773 * If we are currently performing tagged transactions to
6774 * this device and want to change its negotiation parameters,
6775 * go non-tagged for a bit to give the controller a chance to
6776 * negotiate unhampered by tag messages.
6778 if ((device->inq_flags & SID_CmdQue) != 0
6779 && (cts->flags & (CCB_TRANS_SYNC_RATE_VALID|
6780 CCB_TRANS_SYNC_OFFSET_VALID|
6781 CCB_TRANS_BUS_WIDTH_VALID)) != 0)
6782 xpt_toggle_tags(cts->ccb_h.path);
6784 (*(sim->sim_action))(sim, (union ccb *)cts);
6788 struct ccb_relsim crs;
6790 xpt_setup_ccb(&crs.ccb_h, cts->ccb_h.path,
6792 crs.ccb_h.func_code = XPT_REL_SIMQ;
6793 crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
6795 = crs.release_timeout
6798 xpt_action((union ccb *)&crs);
6803 #endif /* CAM_NEW_TRAN_CODE */
6806 xpt_toggle_tags(struct cam_path *path)
6811 * Give controllers a chance to renegotiate
6812 * before starting tag operations. We
6813 * "toggle" tagged queuing off then on
6814 * which causes the tag enable command delay
6815 * counter to come into effect.
6818 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
6819 || ((dev->inq_flags & SID_CmdQue) != 0
6820 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
6821 struct ccb_trans_settings cts;
6823 xpt_setup_ccb(&cts.ccb_h, path, 1);
6824 #ifdef CAM_NEW_TRAN_CODE
6825 cts.protocol = PROTO_SCSI;
6826 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
6827 cts.transport = XPORT_UNSPECIFIED;
6828 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
6829 cts.proto_specific.scsi.flags = 0;
6830 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
6831 #else /* CAM_NEW_TRAN_CODE */
6833 cts.valid = CCB_TRANS_TQ_VALID;
6834 #endif /* CAM_NEW_TRAN_CODE */
6835 xpt_set_transfer_settings(&cts, path->device,
6836 /*async_update*/TRUE);
6837 #ifdef CAM_NEW_TRAN_CODE
6838 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
6839 #else /* CAM_NEW_TRAN_CODE */
6840 cts.flags = CCB_TRANS_TAG_ENB;
6841 #endif /* CAM_NEW_TRAN_CODE */
6842 xpt_set_transfer_settings(&cts, path->device,
6843 /*async_update*/TRUE);
6848 xpt_start_tags(struct cam_path *path)
6850 struct ccb_relsim crs;
6851 struct cam_ed *device;
6852 struct cam_sim *sim;
6855 device = path->device;
6856 sim = path->bus->sim;
6857 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
6858 xpt_freeze_devq(path, /*count*/1);
6859 device->inq_flags |= SID_CmdQue;
6860 if (device->tag_saved_openings != 0)
6861 newopenings = device->tag_saved_openings;
6863 newopenings = min(device->quirk->maxtags,
6864 sim->max_tagged_dev_openings);
6865 xpt_dev_ccbq_resize(path, newopenings);
6866 xpt_setup_ccb(&crs.ccb_h, path, /*priority*/1);
6867 crs.ccb_h.func_code = XPT_REL_SIMQ;
6868 crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
6870 = crs.release_timeout
6873 xpt_action((union ccb *)&crs);
6876 static int busses_to_config;
6877 static int busses_to_reset;
6880 xptconfigbuscountfunc(struct cam_eb *bus, void *arg)
6882 if (bus->path_id != CAM_XPT_PATH_ID) {
6883 struct cam_path path;
6884 struct ccb_pathinq cpi;
6888 xpt_compile_path(&path, NULL, bus->path_id,
6889 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
6890 xpt_setup_ccb(&cpi.ccb_h, &path, /*priority*/1);
6891 cpi.ccb_h.func_code = XPT_PATH_INQ;
6892 xpt_action((union ccb *)&cpi);
6893 can_negotiate = cpi.hba_inquiry;
6894 can_negotiate &= (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE);
6895 if ((cpi.hba_misc & PIM_NOBUSRESET) == 0
6898 xpt_release_path(&path);
6905 xptconfigfunc(struct cam_eb *bus, void *arg)
6907 struct cam_path *path;
6908 union ccb *work_ccb;
6910 if (bus->path_id != CAM_XPT_PATH_ID) {
6914 work_ccb = xpt_alloc_ccb();
6915 if ((status = xpt_create_path(&path, xpt_periph, bus->path_id,
6916 CAM_TARGET_WILDCARD,
6917 CAM_LUN_WILDCARD)) !=CAM_REQ_CMP){
6918 printf("xptconfigfunc: xpt_create_path failed with "
6919 "status %#x for bus %d\n", status, bus->path_id);
6920 printf("xptconfigfunc: halting bus configuration\n");
6921 xpt_free_ccb(work_ccb);
6923 xpt_finishconfig(xpt_periph, NULL);
6926 xpt_setup_ccb(&work_ccb->ccb_h, path, /*priority*/1);
6927 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
6928 xpt_action(work_ccb);
6929 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
6930 printf("xptconfigfunc: CPI failed on bus %d "
6931 "with status %d\n", bus->path_id,
6932 work_ccb->ccb_h.status);
6933 xpt_finishconfig(xpt_periph, work_ccb);
6937 can_negotiate = work_ccb->cpi.hba_inquiry;
6938 can_negotiate &= (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE);
6939 if ((work_ccb->cpi.hba_misc & PIM_NOBUSRESET) == 0
6940 && (can_negotiate != 0)) {
6941 xpt_setup_ccb(&work_ccb->ccb_h, path, /*priority*/1);
6942 work_ccb->ccb_h.func_code = XPT_RESET_BUS;
6943 work_ccb->ccb_h.cbfcnp = NULL;
6944 CAM_DEBUG(path, CAM_DEBUG_SUBTRACE,
6945 ("Resetting Bus\n"));
6946 xpt_action(work_ccb);
6947 xpt_finishconfig(xpt_periph, work_ccb);
6949 /* Act as though we performed a successful BUS RESET */
6950 work_ccb->ccb_h.func_code = XPT_RESET_BUS;
6951 xpt_finishconfig(xpt_periph, work_ccb);
6959 xpt_config(void *arg)
6962 * Now that interrupts are enabled, go find our devices
6966 /* Setup debugging flags and path */
6967 #ifdef CAM_DEBUG_FLAGS
6968 cam_dflags = CAM_DEBUG_FLAGS;
6969 #else /* !CAM_DEBUG_FLAGS */
6970 cam_dflags = CAM_DEBUG_NONE;
6971 #endif /* CAM_DEBUG_FLAGS */
6972 #ifdef CAM_DEBUG_BUS
6973 if (cam_dflags != CAM_DEBUG_NONE) {
6974 if (xpt_create_path(&cam_dpath, xpt_periph,
6975 CAM_DEBUG_BUS, CAM_DEBUG_TARGET,
6976 CAM_DEBUG_LUN) != CAM_REQ_CMP) {
6977 printf("xpt_config: xpt_create_path() failed for debug"
6978 " target %d:%d:%d, debugging disabled\n",
6979 CAM_DEBUG_BUS, CAM_DEBUG_TARGET, CAM_DEBUG_LUN);
6980 cam_dflags = CAM_DEBUG_NONE;
6984 #else /* !CAM_DEBUG_BUS */
6986 #endif /* CAM_DEBUG_BUS */
6987 #endif /* CAMDEBUG */
6990 * Scan all installed busses.
6992 xpt_for_all_busses(xptconfigbuscountfunc, NULL);
6994 if (busses_to_config == 0) {
6995 /* Call manually because we don't have any busses */
6996 xpt_finishconfig(xpt_periph, NULL);
6998 if (busses_to_reset > 0 && scsi_delay >= 2000) {
6999 printf("Waiting %d seconds for SCSI "
7000 "devices to settle\n", scsi_delay/1000);
7002 xpt_for_all_busses(xptconfigfunc, NULL);
7007 * If the given device only has one peripheral attached to it, and if that
7008 * peripheral is the passthrough driver, announce it. This insures that the
7009 * user sees some sort of announcement for every peripheral in their system.
7012 xptpassannouncefunc(struct cam_ed *device, void *arg)
7014 struct cam_periph *periph;
7017 for (periph = SLIST_FIRST(&device->periphs), i = 0; periph != NULL;
7018 periph = SLIST_NEXT(periph, periph_links), i++);
7020 periph = SLIST_FIRST(&device->periphs);
7022 && (strncmp(periph->periph_name, "pass", 4) == 0))
7023 xpt_announce_periph(periph, NULL);
7029 xpt_finishconfig(struct cam_periph *periph, union ccb *done_ccb)
7031 struct periph_driver **p_drv;
7034 if (done_ccb != NULL) {
7035 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE,
7036 ("xpt_finishconfig\n"));
7037 switch(done_ccb->ccb_h.func_code) {
7039 if (done_ccb->ccb_h.status == CAM_REQ_CMP) {
7040 done_ccb->ccb_h.func_code = XPT_SCAN_BUS;
7041 done_ccb->ccb_h.cbfcnp = xpt_finishconfig;
7042 done_ccb->crcn.flags = 0;
7043 xpt_action(done_ccb);
7049 xpt_free_path(done_ccb->ccb_h.path);
7055 if (busses_to_config == 0) {
7056 /* Register all the peripheral drivers */
7057 /* XXX This will have to change when we have loadable modules */
7058 p_drv = periph_drivers;
7059 for (i = 0; p_drv[i] != NULL; i++) {
7060 (*p_drv[i]->init)();
7064 * Check for devices with no "standard" peripheral driver
7065 * attached. For any devices like that, announce the
7066 * passthrough driver so the user will see something.
7068 xpt_for_all_devices(xptpassannouncefunc, NULL);
7070 /* Release our hook so that the boot can continue. */
7071 config_intrhook_disestablish(xpt_config_hook);
7072 free(xpt_config_hook, M_TEMP);
7073 xpt_config_hook = NULL;
7075 if (done_ccb != NULL)
7076 xpt_free_ccb(done_ccb);
7080 xptaction(struct cam_sim *sim, union ccb *work_ccb)
7082 CAM_DEBUG(work_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xptaction\n"));
7084 switch (work_ccb->ccb_h.func_code) {
7085 /* Common cases first */
7086 case XPT_PATH_INQ: /* Path routing inquiry */
7088 struct ccb_pathinq *cpi;
7090 cpi = &work_ccb->cpi;
7091 cpi->version_num = 1; /* XXX??? */
7092 cpi->hba_inquiry = 0;
7093 cpi->target_sprt = 0;
7095 cpi->hba_eng_cnt = 0;
7096 cpi->max_target = 0;
7098 cpi->initiator_id = 0;
7099 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
7100 strncpy(cpi->hba_vid, "", HBA_IDLEN);
7101 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
7102 cpi->unit_number = sim->unit_number;
7103 cpi->bus_id = sim->bus_id;
7104 cpi->base_transfer_speed = 0;
7105 #ifdef CAM_NEW_TRAN_CODE
7106 cpi->protocol = PROTO_UNSPECIFIED;
7107 cpi->protocol_version = PROTO_VERSION_UNSPECIFIED;
7108 cpi->transport = XPORT_UNSPECIFIED;
7109 cpi->transport_version = XPORT_VERSION_UNSPECIFIED;
7110 #endif /* CAM_NEW_TRAN_CODE */
7111 cpi->ccb_h.status = CAM_REQ_CMP;
7116 work_ccb->ccb_h.status = CAM_REQ_INVALID;
7123 * The xpt as a "controller" has no interrupt sources, so polling
7127 xptpoll(struct cam_sim *sim)
7132 camisr(void *V_queue)
7134 cam_isrq_t *oqueue = V_queue;
7137 struct ccb_hdr *ccb_h;
7140 * Transfer the ccb_bioq list to a temporary list so we can operate
7141 * on it without needing to lock/unlock on every loop. The concat
7142 * function with re-init the real list for us.
7145 mtx_lock(&cam_bioq_lock);
7147 TAILQ_CONCAT(&queue, oqueue, sim_links.tqe);
7148 mtx_unlock(&cam_bioq_lock);
7150 while ((ccb_h = TAILQ_FIRST(&queue)) != NULL) {
7153 TAILQ_REMOVE(&queue, ccb_h, sim_links.tqe);
7154 ccb_h->pinfo.index = CAM_UNQUEUED_INDEX;
7157 CAM_DEBUG(ccb_h->path, CAM_DEBUG_TRACE,
7162 if (ccb_h->flags & CAM_HIGH_POWER) {
7163 struct highpowerlist *hphead;
7164 union ccb *send_ccb;
7166 hphead = &highpowerq;
7168 send_ccb = (union ccb *)STAILQ_FIRST(hphead);
7171 * Increment the count since this command is done.
7176 * Any high powered commands queued up?
7178 if (send_ccb != NULL) {
7180 STAILQ_REMOVE_HEAD(hphead, xpt_links.stqe);
7182 xpt_release_devq(send_ccb->ccb_h.path,
7183 /*count*/1, /*runqueue*/TRUE);
7186 if ((ccb_h->func_code & XPT_FC_USER_CCB) == 0) {
7189 dev = ccb_h->path->device;
7192 cam_ccbq_ccb_done(&dev->ccbq, (union ccb *)ccb_h);
7194 if (!SIM_DEAD(ccb_h->path->bus->sim)) {
7195 ccb_h->path->bus->sim->devq->send_active--;
7196 ccb_h->path->bus->sim->devq->send_openings++;
7200 if (((dev->flags & CAM_DEV_REL_ON_COMPLETE) != 0
7201 && (ccb_h->status&CAM_STATUS_MASK) != CAM_REQUEUE_REQ)
7202 || ((dev->flags & CAM_DEV_REL_ON_QUEUE_EMPTY) != 0
7203 && (dev->ccbq.dev_active == 0))) {
7205 xpt_release_devq(ccb_h->path, /*count*/1,
7209 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
7210 && (--dev->tag_delay_count == 0))
7211 xpt_start_tags(ccb_h->path);
7213 if ((dev->ccbq.queue.entries > 0)
7214 && (dev->qfrozen_cnt == 0)
7215 && (device_is_send_queued(dev) == 0)) {
7216 runq = xpt_schedule_dev_sendq(ccb_h->path->bus,
7221 if (ccb_h->status & CAM_RELEASE_SIMQ) {
7222 xpt_release_simq(ccb_h->path->bus->sim,
7224 ccb_h->status &= ~CAM_RELEASE_SIMQ;
7228 if ((ccb_h->flags & CAM_DEV_QFRZDIS)
7229 && (ccb_h->status & CAM_DEV_QFRZN)) {
7230 xpt_release_devq(ccb_h->path, /*count*/1,
7232 ccb_h->status &= ~CAM_DEV_QFRZN;
7234 xpt_run_dev_sendq(ccb_h->path->bus);
7237 /* Call the peripheral driver's callback */
7238 (*ccb_h->cbfcnp)(ccb_h->path->periph, (union ccb *)ccb_h);
7240 /* Raise IPL for while test */
7247 dead_sim_action(struct cam_sim *sim, union ccb *ccb)
7250 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
7255 dead_sim_poll(struct cam_sim *sim)