2 * Implementation of the SCSI Transport
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_queue.h>
57 #include <cam/cam_periph.h>
58 #include <cam/cam_sim.h>
59 #include <cam/cam_xpt.h>
60 #include <cam/cam_xpt_sim.h>
61 #include <cam/cam_xpt_periph.h>
62 #include <cam/cam_xpt_internal.h>
63 #include <cam/cam_debug.h>
65 #include <cam/scsi/scsi_all.h>
66 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_pass.h>
68 #include <machine/stdarg.h> /* for xpt_print below */
71 struct scsi_quirk_entry {
72 struct scsi_inquiry_pattern inq_pat;
74 #define CAM_QUIRK_NOLUNS 0x01
75 #define CAM_QUIRK_NOSERIAL 0x02
76 #define CAM_QUIRK_HILUNS 0x04
77 #define CAM_QUIRK_NOHILUNS 0x08
81 #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk))
83 static int cam_srch_hi = 0;
84 TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi);
85 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
86 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
87 sysctl_cam_search_luns, "I",
88 "allow search above LUN 7 for SCSI3 and greater devices");
90 #define CAM_SCSI2_MAXLUN 8
92 * If we're not quirked to search <= the first 8 luns
93 * and we are either quirked to search above lun 8,
94 * or we're > SCSI-2 and we've enabled hilun searching,
95 * or we're > SCSI-2 and the last lun was a success,
96 * we can look for luns above lun 8.
98 #define CAN_SRCH_HI_SPARSE(dv) \
99 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
100 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
101 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
103 #define CAN_SRCH_HI_DENSE(dv) \
104 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
105 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
106 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
108 static periph_init_t probe_periph_init;
110 static struct periph_driver probe_driver =
112 probe_periph_init, "probe",
113 TAILQ_HEAD_INITIALIZER(probe_driver.units)
116 PERIPHDRIVER_DECLARE(probe, probe_driver);
120 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
125 PROBE_TUR_FOR_NEGOTIATION,
126 PROBE_INQUIRY_BASIC_DV1,
127 PROBE_INQUIRY_BASIC_DV2,
132 static char *probe_action_text[] = {
135 "PROBE_FULL_INQUIRY",
137 "PROBE_SERIAL_NUM_0",
138 "PROBE_SERIAL_NUM_1",
139 "PROBE_TUR_FOR_NEGOTIATION",
140 "PROBE_INQUIRY_BASIC_DV1",
141 "PROBE_INQUIRY_BASIC_DV2",
146 #define PROBE_SET_ACTION(softc, newaction) \
149 text = probe_action_text; \
150 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \
151 ("Probe %s to %s\n", text[(softc)->action], \
152 text[(newaction)])); \
153 (softc)->action = (newaction); \
157 PROBE_INQUIRY_CKSUM = 0x01,
158 PROBE_SERIAL_CKSUM = 0x02,
159 PROBE_NO_ANNOUNCE = 0x04
163 TAILQ_HEAD(, ccb_hdr) request_ccbs;
169 struct cam_periph *periph;
172 static const char quantum[] = "QUANTUM";
173 static const char sony[] = "SONY";
174 static const char west_digital[] = "WDIGTL";
175 static const char samsung[] = "SAMSUNG";
176 static const char seagate[] = "SEAGATE";
177 static const char microp[] = "MICROP";
179 static struct scsi_quirk_entry scsi_quirk_table[] =
182 /* Reports QUEUE FULL for temporary resource shortages */
183 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
184 /*quirks*/0, /*mintags*/24, /*maxtags*/32
187 /* Reports QUEUE FULL for temporary resource shortages */
188 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
189 /*quirks*/0, /*mintags*/24, /*maxtags*/32
192 /* Reports QUEUE FULL for temporary resource shortages */
193 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
194 /*quirks*/0, /*mintags*/24, /*maxtags*/32
197 /* Broken tagged queuing drive */
198 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
199 /*quirks*/0, /*mintags*/0, /*maxtags*/0
202 /* Broken tagged queuing drive */
203 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
204 /*quirks*/0, /*mintags*/0, /*maxtags*/0
207 /* Broken tagged queuing drive */
208 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
209 /*quirks*/0, /*mintags*/0, /*maxtags*/0
213 * Unfortunately, the Quantum Atlas III has the same
214 * problem as the Atlas II drives above.
215 * Reported by: "Johan Granlund" <johan@granlund.nu>
217 * For future reference, the drive with the problem was:
218 * QUANTUM QM39100TD-SW N1B0
220 * It's possible that Quantum will fix the problem in later
221 * firmware revisions. If that happens, the quirk entry
222 * will need to be made specific to the firmware revisions
226 /* Reports QUEUE FULL for temporary resource shortages */
227 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
228 /*quirks*/0, /*mintags*/24, /*maxtags*/32
232 * 18 Gig Atlas III, same problem as the 9G version.
233 * Reported by: Andre Albsmeier
234 * <andre.albsmeier@mchp.siemens.de>
236 * For future reference, the drive with the problem was:
237 * QUANTUM QM318000TD-S N491
239 /* Reports QUEUE FULL for temporary resource shortages */
240 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
241 /*quirks*/0, /*mintags*/24, /*maxtags*/32
245 * Broken tagged queuing drive
246 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
247 * and: Martin Renters <martin@tdc.on.ca>
249 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
250 /*quirks*/0, /*mintags*/0, /*maxtags*/0
253 * The Seagate Medalist Pro drives have very poor write
254 * performance with anything more than 2 tags.
256 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
257 * Drive: <SEAGATE ST36530N 1444>
259 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
260 * Drive: <SEAGATE ST34520W 1281>
262 * No one has actually reported that the 9G version
263 * (ST39140*) of the Medalist Pro has the same problem, but
264 * we're assuming that it does because the 4G and 6.5G
265 * versions of the drive are broken.
268 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
269 /*quirks*/0, /*mintags*/2, /*maxtags*/2
272 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
273 /*quirks*/0, /*mintags*/2, /*maxtags*/2
276 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
277 /*quirks*/0, /*mintags*/2, /*maxtags*/2
281 * Slow when tagged queueing is enabled. Write performance
282 * steadily drops off with more and more concurrent
283 * transactions. Best sequential write performance with
284 * tagged queueing turned off and write caching turned on.
287 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
288 * Drive: DCAS-34330 w/ "S65A" firmware.
290 * The drive with the problem had the "S65A" firmware
291 * revision, and has also been reported (by Stephen J.
292 * Roznowski <sjr@home.net>) for a drive with the "S61A"
295 * Although no one has reported problems with the 2 gig
296 * version of the DCAS drive, the assumption is that it
297 * has the same problems as the 4 gig version. Therefore
298 * this quirk entries disables tagged queueing for all
301 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
302 /*quirks*/0, /*mintags*/0, /*maxtags*/0
305 /* Broken tagged queuing drive */
306 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
307 /*quirks*/0, /*mintags*/0, /*maxtags*/0
310 /* Broken tagged queuing drive */
311 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
312 /*quirks*/0, /*mintags*/0, /*maxtags*/0
315 /* This does not support other than LUN 0 */
316 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
317 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
321 * Broken tagged queuing drive.
323 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
326 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
327 /*quirks*/0, /*mintags*/0, /*maxtags*/0
331 * Slow when tagged queueing is enabled. (1.5MB/sec versus
333 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
334 * Best performance with these drives is achieved with
335 * tagged queueing turned off, and write caching turned on.
337 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
338 /*quirks*/0, /*mintags*/0, /*maxtags*/0
342 * Slow when tagged queueing is enabled. (1.5MB/sec versus
344 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
345 * Best performance with these drives is achieved with
346 * tagged queueing turned off, and write caching turned on.
348 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
349 /*quirks*/0, /*mintags*/0, /*maxtags*/0
353 * Doesn't handle queue full condition correctly,
354 * so we need to limit maxtags to what the device
355 * can handle instead of determining this automatically.
357 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
358 /*quirks*/0, /*mintags*/2, /*maxtags*/32
361 /* Really only one LUN */
362 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
363 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
366 /* I can't believe we need a quirk for DPT volumes. */
367 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
369 /*mintags*/0, /*maxtags*/255
373 * Many Sony CDROM drives don't like multi-LUN probing.
375 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
376 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
380 * This drive doesn't like multiple LUN probing.
381 * Submitted by: Parag Patel <parag@cgt.com>
383 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
384 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
387 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
388 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
392 * The 8200 doesn't like multi-lun probing, and probably
393 * don't like serial number requests either.
396 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
399 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
403 * Let's try the same as above, but for a drive that says
404 * it's an IPL-6860 but is actually an EXB 8200.
407 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
410 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
414 * These Hitachi drives don't like multi-lun probing.
415 * The PR submitter has a DK319H, but says that the Linux
416 * kernel has a similar work-around for the DK312 and DK314,
417 * so all DK31* drives are quirked here.
419 * Submitted by: Paul Haddad <paul@pth.com>
421 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
422 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
426 * The Hitachi CJ series with J8A8 firmware apparantly has
427 * problems with tagged commands.
429 * Reported by: amagai@nue.org
431 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
432 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
436 * These are the large storage arrays.
437 * Submitted by: William Carrel <william.carrel@infospace.com>
439 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
440 CAM_QUIRK_HILUNS, 2, 1024
444 * This old revision of the TDC3600 is also SCSI-1, and
445 * hangs upon serial number probing.
448 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
451 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
455 * Would repond to all LUNs if asked for.
458 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
461 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
465 * Would repond to all LUNs if asked for.
468 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
471 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
474 /* Submitted by: Matthew Dodd <winter@jurai.net> */
475 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
476 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
479 /* Submitted by: Matthew Dodd <winter@jurai.net> */
480 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
481 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
484 /* TeraSolutions special settings for TRC-22 RAID */
485 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
486 /*quirks*/0, /*mintags*/55, /*maxtags*/255
489 /* Veritas Storage Appliance */
490 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
491 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
495 * Would respond to all LUNs. Device type and removable
496 * flag are jumper-selectable.
498 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
501 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
504 /* EasyRAID E5A aka. areca ARC-6010 */
505 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
506 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
509 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
510 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
513 /* Default tagged queuing parameters for all devices */
515 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
516 /*vendor*/"*", /*product*/"*", /*revision*/"*"
518 /*quirks*/0, /*mintags*/2, /*maxtags*/255
522 static const int scsi_quirk_table_size =
523 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
525 static cam_status proberegister(struct cam_periph *periph,
527 static void probeschedule(struct cam_periph *probe_periph);
528 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
529 static void proberequestdefaultnegotiation(struct cam_periph *periph);
530 static int proberequestbackoff(struct cam_periph *periph,
531 struct cam_ed *device);
532 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
533 static void probecleanup(struct cam_periph *periph);
534 static void scsi_find_quirk(struct cam_ed *device);
535 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
536 static void scsi_scan_lun(struct cam_periph *periph,
537 struct cam_path *path, cam_flags flags,
539 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
540 static struct cam_ed *
541 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
543 static void scsi_devise_transport(struct cam_path *path);
544 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
545 struct cam_ed *device,
547 static void scsi_toggle_tags(struct cam_path *path);
548 static void scsi_dev_async(u_int32_t async_code,
550 struct cam_et *target,
551 struct cam_ed *device,
553 static void scsi_action(union ccb *start_ccb);
555 static struct xpt_xport scsi_xport = {
556 .alloc_device = scsi_alloc_device,
557 .action = scsi_action,
558 .async = scsi_dev_async,
564 return (&scsi_xport);
573 proberegister(struct cam_periph *periph, void *arg)
575 union ccb *request_ccb; /* CCB representing the probe request */
579 request_ccb = (union ccb *)arg;
580 if (periph == NULL) {
581 printf("proberegister: periph was NULL!!\n");
582 return(CAM_REQ_CMP_ERR);
585 if (request_ccb == NULL) {
586 printf("proberegister: no probe CCB, "
587 "can't register device\n");
588 return(CAM_REQ_CMP_ERR);
591 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
594 printf("proberegister: Unable to probe new device. "
595 "Unable to allocate softc\n");
596 return(CAM_REQ_CMP_ERR);
598 TAILQ_INIT(&softc->request_ccbs);
599 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
602 periph->softc = softc;
603 softc->periph = periph;
604 softc->action = PROBE_INVALID;
605 status = cam_periph_acquire(periph);
606 if (status != CAM_REQ_CMP) {
612 * Ensure we've waited at least a bus settle
613 * delay before attempting to probe the device.
614 * For HBAs that don't do bus resets, this won't make a difference.
616 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
618 probeschedule(periph);
623 probeschedule(struct cam_periph *periph)
625 struct ccb_pathinq cpi;
629 softc = (probe_softc *)periph->softc;
630 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
632 xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
633 cpi.ccb_h.func_code = XPT_PATH_INQ;
634 xpt_action((union ccb *)&cpi);
637 * If a device has gone away and another device, or the same one,
638 * is back in the same place, it should have a unit attention
639 * condition pending. It will not report the unit attention in
640 * response to an inquiry, which may leave invalid transfer
641 * negotiations in effect. The TUR will reveal the unit attention
642 * condition. Only send the TUR for lun 0, since some devices
643 * will get confused by commands other than inquiry to non-existent
644 * luns. If you think a device has gone away start your scan from
645 * lun 0. This will insure that any bogus transfer settings are
648 * If we haven't seen the device before and the controller supports
649 * some kind of transfer negotiation, negotiate with the first
650 * sent command if no bus reset was performed at startup. This
651 * ensures that the device is not confused by transfer negotiation
652 * settings left over by loader or BIOS action.
654 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
655 && (ccb->ccb_h.target_lun == 0)) {
656 PROBE_SET_ACTION(softc, PROBE_TUR);
657 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
658 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
659 proberequestdefaultnegotiation(periph);
660 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
662 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
665 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
666 softc->flags |= PROBE_NO_ANNOUNCE;
668 softc->flags &= ~PROBE_NO_ANNOUNCE;
670 xpt_schedule(periph, ccb->ccb_h.pinfo.priority);
674 probestart(struct cam_periph *periph, union ccb *start_ccb)
676 /* Probe the device that our peripheral driver points to */
677 struct ccb_scsiio *csio;
680 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
682 softc = (probe_softc *)periph->softc;
683 csio = &start_ccb->csio;
685 switch (softc->action) {
687 case PROBE_TUR_FOR_NEGOTIATION:
690 scsi_test_unit_ready(csio,
699 case PROBE_FULL_INQUIRY:
700 case PROBE_INQUIRY_BASIC_DV1:
701 case PROBE_INQUIRY_BASIC_DV2:
704 struct scsi_inquiry_data *inq_buf;
706 inq_buf = &periph->path->device->inq_data;
709 * If the device is currently configured, we calculate an
710 * MD5 checksum of the inquiry data, and if the serial number
711 * length is greater than 0, add the serial number data
712 * into the checksum as well. Once the inquiry and the
713 * serial number check finish, we attempt to figure out
714 * whether we still have the same device.
716 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
718 MD5Init(&softc->context);
719 MD5Update(&softc->context, (unsigned char *)inq_buf,
720 sizeof(struct scsi_inquiry_data));
721 softc->flags |= PROBE_INQUIRY_CKSUM;
722 if (periph->path->device->serial_num_len > 0) {
723 MD5Update(&softc->context,
724 periph->path->device->serial_num,
725 periph->path->device->serial_num_len);
726 softc->flags |= PROBE_SERIAL_CKSUM;
728 MD5Final(softc->digest, &softc->context);
731 if (softc->action == PROBE_INQUIRY)
732 inquiry_len = SHORT_INQUIRY_LENGTH;
734 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
737 * Some parallel SCSI devices fail to send an
738 * ignore wide residue message when dealing with
739 * odd length inquiry requests. Round up to be
742 inquiry_len = roundup2(inquiry_len, 2);
744 if (softc->action == PROBE_INQUIRY_BASIC_DV1
745 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
746 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
748 if (inq_buf == NULL) {
749 xpt_print(periph->path, "malloc failure- skipping Basic"
750 "Domain Validation\n");
751 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
752 scsi_test_unit_ready(csio,
769 /*timeout*/60 * 1000);
772 case PROBE_MODE_SENSE:
777 mode_buf_len = sizeof(struct scsi_mode_header_6)
778 + sizeof(struct scsi_mode_blk_desc)
779 + sizeof(struct scsi_control_page);
780 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
781 if (mode_buf != NULL) {
782 scsi_mode_sense(csio,
787 SMS_PAGE_CTRL_CURRENT,
788 SMS_CONTROL_MODE_PAGE,
795 xpt_print(periph->path, "Unable to mode sense control page - "
797 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
800 case PROBE_SERIAL_NUM_0:
802 struct scsi_vpd_supported_page_list *vpd_list = NULL;
803 struct cam_ed *device;
805 device = periph->path->device;
806 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOSERIAL) == 0) {
807 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
811 if (vpd_list != NULL) {
816 (u_int8_t *)vpd_list,
819 SVPD_SUPPORTED_PAGE_LIST,
821 /*timeout*/60 * 1000);
825 * We'll have to do without, let our probedone
826 * routine finish up for us.
828 start_ccb->csio.data_ptr = NULL;
829 probedone(periph, start_ccb);
832 case PROBE_SERIAL_NUM_1:
834 struct scsi_vpd_unit_serial_number *serial_buf;
835 struct cam_ed* device;
838 device = periph->path->device;
839 if (device->serial_num != NULL) {
840 free(device->serial_num, M_CAMXPT);
841 device->serial_num = NULL;
842 device->serial_num_len = 0;
845 serial_buf = (struct scsi_vpd_unit_serial_number *)
846 malloc(sizeof(*serial_buf), M_CAMXPT, M_NOWAIT|M_ZERO);
848 if (serial_buf != NULL) {
853 (u_int8_t *)serial_buf,
856 SVPD_UNIT_SERIAL_NUMBER,
858 /*timeout*/60 * 1000);
862 * We'll have to do without, let our probedone
863 * routine finish up for us.
865 start_ccb->csio.data_ptr = NULL;
866 probedone(periph, start_ccb);
870 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_INFO,
871 ("probestart: invalid action state\n"));
875 xpt_action(start_ccb);
879 proberequestdefaultnegotiation(struct cam_periph *periph)
881 struct ccb_trans_settings cts;
883 xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
884 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
885 cts.type = CTS_TYPE_USER_SETTINGS;
886 xpt_action((union ccb *)&cts);
887 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
890 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
891 cts.type = CTS_TYPE_CURRENT_SETTINGS;
892 xpt_action((union ccb *)&cts);
896 * Backoff Negotiation Code- only pertinent for SPI devices.
899 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
901 struct ccb_trans_settings cts;
902 struct ccb_trans_settings_spi *spi;
904 memset(&cts, 0, sizeof (cts));
905 xpt_setup_ccb(&cts.ccb_h, periph->path, /*priority*/1);
906 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
907 cts.type = CTS_TYPE_CURRENT_SETTINGS;
908 xpt_action((union ccb *)&cts);
909 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
911 xpt_print(periph->path,
912 "failed to get current device settings\n");
916 if (cts.transport != XPORT_SPI) {
918 xpt_print(periph->path, "not SPI transport\n");
922 spi = &cts.xport_specific.spi;
925 * We cannot renegotiate sync rate if we don't have one.
927 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
929 xpt_print(periph->path, "no sync rate known\n");
935 * We'll assert that we don't have to touch PPR options- the
936 * SIM will see what we do with period and offset and adjust
937 * the PPR options as appropriate.
941 * A sync rate with unknown or zero offset is nonsensical.
942 * A sync period of zero means Async.
944 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
945 || spi->sync_offset == 0 || spi->sync_period == 0) {
947 xpt_print(periph->path, "no sync rate available\n");
952 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
953 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
954 ("hit async: giving up on DV\n"));
960 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
961 * We don't try to remember 'last' settings to see if the SIM actually
962 * gets into the speed we want to set. We check on the SIM telling
963 * us that a requested speed is bad, but otherwise don't try and
964 * check the speed due to the asynchronous and handshake nature
967 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
970 if (spi->sync_period >= 0xf) {
971 spi->sync_period = 0;
972 spi->sync_offset = 0;
973 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
974 ("setting to async for DV\n"));
976 * Once we hit async, we don't want to try
979 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
980 } else if (bootverbose) {
981 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
982 ("DV: period 0x%x\n", spi->sync_period));
983 printf("setting period to 0x%x\n", spi->sync_period);
985 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
986 cts.type = CTS_TYPE_CURRENT_SETTINGS;
987 xpt_action((union ccb *)&cts);
988 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
991 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
992 ("DV: failed to set period 0x%x\n", spi->sync_period));
993 if (spi->sync_period == 0) {
1001 probedone(struct cam_periph *periph, union ccb *done_ccb)
1004 struct cam_path *path;
1007 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1009 softc = (probe_softc *)periph->softc;
1010 path = done_ccb->ccb_h.path;
1011 priority = done_ccb->ccb_h.pinfo.priority;
1013 switch (softc->action) {
1016 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1018 if (cam_periph_error(done_ccb, 0,
1019 SF_NO_PRINT, NULL) == ERESTART)
1021 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1022 /* Don't wedge the queue */
1023 xpt_release_devq(done_ccb->ccb_h.path,
1027 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1028 xpt_release_ccb(done_ccb);
1029 xpt_schedule(periph, priority);
1033 case PROBE_FULL_INQUIRY:
1035 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1036 struct scsi_inquiry_data *inq_buf;
1037 u_int8_t periph_qual;
1039 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1040 inq_buf = &path->device->inq_data;
1042 periph_qual = SID_QUAL(inq_buf);
1044 switch(periph_qual) {
1045 case SID_QUAL_LU_CONNECTED:
1050 * We conservatively request only
1051 * SHORT_INQUIRY_LEN bytes of inquiry
1052 * information during our first try
1053 * at sending an INQUIRY. If the device
1054 * has more information to give,
1055 * perform a second request specifying
1056 * the amount of information the device
1057 * is willing to give.
1059 len = inq_buf->additional_length
1060 + offsetof(struct scsi_inquiry_data,
1061 additional_length) + 1;
1062 if (softc->action == PROBE_INQUIRY
1063 && len > SHORT_INQUIRY_LENGTH) {
1064 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1065 xpt_release_ccb(done_ccb);
1066 xpt_schedule(periph, priority);
1070 scsi_find_quirk(path->device);
1072 scsi_devise_transport(path);
1073 if (INQ_DATA_TQ_ENABLED(inq_buf))
1074 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1076 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1078 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1080 xpt_release_ccb(done_ccb);
1081 xpt_schedule(periph, priority);
1087 } else if (cam_periph_error(done_ccb, 0,
1088 done_ccb->ccb_h.target_lun > 0
1089 ? SF_RETRY_UA|SF_QUIET_IR
1091 &softc->saved_ccb) == ERESTART) {
1093 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1094 /* Don't wedge the queue */
1095 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1099 * If we get to this point, we got an error status back
1100 * from the inquiry and the error status doesn't require
1101 * automatically retrying the command. Therefore, the
1102 * inquiry failed. If we had inquiry information before
1103 * for this device, but this latest inquiry command failed,
1104 * the device has probably gone away. If this device isn't
1105 * already marked unconfigured, notify the peripheral
1106 * drivers that this device is no more.
1108 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1109 /* Send the async notification. */
1110 xpt_async(AC_LOST_DEVICE, path, NULL);
1112 xpt_release_ccb(done_ccb);
1115 case PROBE_MODE_SENSE:
1117 struct ccb_scsiio *csio;
1118 struct scsi_mode_header_6 *mode_hdr;
1120 csio = &done_ccb->csio;
1121 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1122 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1123 struct scsi_control_page *page;
1126 offset = ((u_int8_t *)&mode_hdr[1])
1127 + mode_hdr->blk_desc_len;
1128 page = (struct scsi_control_page *)offset;
1129 path->device->queue_flags = page->queue_flags;
1130 } else if (cam_periph_error(done_ccb, 0,
1131 SF_RETRY_UA|SF_NO_PRINT,
1132 &softc->saved_ccb) == ERESTART) {
1134 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1135 /* Don't wedge the queue */
1136 xpt_release_devq(done_ccb->ccb_h.path,
1137 /*count*/1, /*run_queue*/TRUE);
1139 xpt_release_ccb(done_ccb);
1140 free(mode_hdr, M_CAMXPT);
1141 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1142 xpt_schedule(periph, priority);
1145 case PROBE_SERIAL_NUM_0:
1147 struct ccb_scsiio *csio;
1148 struct scsi_vpd_supported_page_list *page_list;
1149 int length, serialnum_supported, i;
1151 serialnum_supported = 0;
1152 csio = &done_ccb->csio;
1154 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1156 if (page_list == NULL) {
1158 * Don't process the command as it was never sent
1160 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1161 && (page_list->length > 0)) {
1162 length = min(page_list->length,
1163 SVPD_SUPPORTED_PAGES_SIZE);
1164 for (i = 0; i < length; i++) {
1165 if (page_list->list[i] ==
1166 SVPD_UNIT_SERIAL_NUMBER) {
1167 serialnum_supported = 1;
1171 } else if (cam_periph_error(done_ccb, 0,
1172 SF_RETRY_UA|SF_NO_PRINT,
1173 &softc->saved_ccb) == ERESTART) {
1175 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1176 /* Don't wedge the queue */
1177 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1181 if (page_list != NULL)
1182 free(page_list, M_CAMXPT);
1184 if (serialnum_supported) {
1185 xpt_release_ccb(done_ccb);
1186 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_1);
1187 xpt_schedule(periph, priority);
1191 csio->data_ptr = NULL;
1195 case PROBE_SERIAL_NUM_1:
1197 struct ccb_scsiio *csio;
1198 struct scsi_vpd_unit_serial_number *serial_buf;
1205 csio = &done_ccb->csio;
1206 priority = done_ccb->ccb_h.pinfo.priority;
1208 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1210 /* Clean up from previous instance of this device */
1211 if (path->device->serial_num != NULL) {
1212 free(path->device->serial_num, M_CAMXPT);
1213 path->device->serial_num = NULL;
1214 path->device->serial_num_len = 0;
1217 if (serial_buf == NULL) {
1219 * Don't process the command as it was never sent
1221 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1222 && (serial_buf->length > 0)) {
1225 path->device->serial_num =
1226 (u_int8_t *)malloc((serial_buf->length + 1),
1227 M_CAMXPT, M_NOWAIT);
1228 if (path->device->serial_num != NULL) {
1229 bcopy(serial_buf->serial_num,
1230 path->device->serial_num,
1231 serial_buf->length);
1232 path->device->serial_num_len =
1234 path->device->serial_num[serial_buf->length]
1237 } else if (cam_periph_error(done_ccb, 0,
1238 SF_RETRY_UA|SF_NO_PRINT,
1239 &softc->saved_ccb) == ERESTART) {
1241 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1242 /* Don't wedge the queue */
1243 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1248 * Let's see if we have seen this device before.
1250 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1252 u_int8_t digest[16];
1257 (unsigned char *)&path->device->inq_data,
1258 sizeof(struct scsi_inquiry_data));
1261 MD5Update(&context, serial_buf->serial_num,
1262 serial_buf->length);
1264 MD5Final(digest, &context);
1265 if (bcmp(softc->digest, digest, 16) == 0)
1269 * XXX Do we need to do a TUR in order to ensure
1270 * that the device really hasn't changed???
1273 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1274 xpt_async(AC_LOST_DEVICE, path, NULL);
1276 if (serial_buf != NULL)
1277 free(serial_buf, M_CAMXPT);
1281 * Now that we have all the necessary
1282 * information to safely perform transfer
1283 * negotiations... Controllers don't perform
1284 * any negotiation or tagged queuing until
1285 * after the first XPT_SET_TRAN_SETTINGS ccb is
1286 * received. So, on a new device, just retrieve
1287 * the user settings, and set them as the current
1288 * settings to set the device up.
1290 proberequestdefaultnegotiation(periph);
1291 xpt_release_ccb(done_ccb);
1294 * Perform a TUR to allow the controller to
1295 * perform any necessary transfer negotiation.
1297 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1298 xpt_schedule(periph, priority);
1301 xpt_release_ccb(done_ccb);
1304 case PROBE_TUR_FOR_NEGOTIATION:
1305 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1307 if (cam_periph_error(done_ccb, 0, SF_RETRY_UA,
1313 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1314 /* Don't wedge the queue */
1315 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1319 * Do Domain Validation for lun 0 on devices that claim
1320 * to support Synchronous Transfer modes.
1322 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1323 && done_ccb->ccb_h.target_lun == 0
1324 && (path->device->inq_data.flags & SID_Sync) != 0
1325 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1326 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1327 ("Begin Domain Validation\n"));
1328 path->device->flags |= CAM_DEV_IN_DV;
1329 xpt_release_ccb(done_ccb);
1330 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1331 xpt_schedule(periph, priority);
1334 if (softc->action == PROBE_DV_EXIT) {
1335 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1336 ("Leave Domain Validation\n"));
1338 path->device->flags &=
1339 ~(CAM_DEV_UNCONFIGURED|CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1340 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1341 /* Inform the XPT that a new device has been found */
1342 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1343 xpt_action(done_ccb);
1344 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1347 xpt_release_ccb(done_ccb);
1349 case PROBE_INQUIRY_BASIC_DV1:
1350 case PROBE_INQUIRY_BASIC_DV2:
1352 struct scsi_inquiry_data *nbuf;
1353 struct ccb_scsiio *csio;
1355 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1356 /* Don't wedge the queue */
1357 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1360 csio = &done_ccb->csio;
1361 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1362 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1364 "inquiry data fails comparison at DV%d step\n",
1365 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1366 if (proberequestbackoff(periph, path->device)) {
1367 path->device->flags &= ~CAM_DEV_IN_DV;
1368 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1371 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1373 free(nbuf, M_CAMXPT);
1374 xpt_release_ccb(done_ccb);
1375 xpt_schedule(periph, priority);
1378 free(nbuf, M_CAMXPT);
1379 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1380 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1381 xpt_release_ccb(done_ccb);
1382 xpt_schedule(periph, priority);
1385 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1386 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1387 ("Leave Domain Validation Successfully\n"));
1389 path->device->flags &=
1390 ~(CAM_DEV_UNCONFIGURED|CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1391 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1392 /* Inform the XPT that a new device has been found */
1393 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1394 xpt_action(done_ccb);
1395 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1398 xpt_release_ccb(done_ccb);
1402 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO,
1403 ("probedone: invalid action state\n"));
1407 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1408 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1409 done_ccb->ccb_h.status = CAM_REQ_CMP;
1411 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1412 cam_periph_invalidate(periph);
1413 cam_periph_release_locked(periph);
1415 probeschedule(periph);
1420 probecleanup(struct cam_periph *periph)
1422 free(periph->softc, M_CAMXPT);
1426 scsi_find_quirk(struct cam_ed *device)
1428 struct scsi_quirk_entry *quirk;
1431 match = cam_quirkmatch((caddr_t)&device->inq_data,
1432 (caddr_t)scsi_quirk_table,
1433 sizeof(scsi_quirk_table) /
1434 sizeof(*scsi_quirk_table),
1435 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1438 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1440 quirk = (struct scsi_quirk_entry *)match;
1441 device->quirk = quirk;
1442 device->mintags = quirk->mintags;
1443 device->maxtags = quirk->maxtags;
1447 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1452 error = sysctl_handle_int(oidp, &bool, 0, req);
1453 if (error != 0 || req->newptr == NULL)
1455 if (bool == 0 || bool == 1) {
1464 union ccb *request_ccb;
1465 struct ccb_pathinq *cpi;
1467 } scsi_scan_bus_info;
1470 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1471 * As the scan progresses, scsi_scan_bus is used as the
1472 * callback on completion function.
1475 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1477 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1478 ("scsi_scan_bus\n"));
1479 switch (request_ccb->ccb_h.func_code) {
1482 scsi_scan_bus_info *scan_info;
1483 union ccb *work_ccb;
1484 struct cam_path *path;
1489 /* Find out the characteristics of the bus */
1490 work_ccb = xpt_alloc_ccb_nowait();
1491 if (work_ccb == NULL) {
1492 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1493 xpt_done(request_ccb);
1496 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1497 request_ccb->ccb_h.pinfo.priority);
1498 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1499 xpt_action(work_ccb);
1500 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1501 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1502 xpt_free_ccb(work_ccb);
1503 xpt_done(request_ccb);
1507 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1509 * Can't scan the bus on an adapter that
1510 * cannot perform the initiator role.
1512 request_ccb->ccb_h.status = CAM_REQ_CMP;
1513 xpt_free_ccb(work_ccb);
1514 xpt_done(request_ccb);
1518 /* Save some state for use while we probe for devices */
1519 scan_info = (scsi_scan_bus_info *)
1520 malloc(sizeof(scsi_scan_bus_info), M_CAMXPT, M_NOWAIT);
1521 if (scan_info == NULL) {
1522 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1523 xpt_done(request_ccb);
1526 scan_info->request_ccb = request_ccb;
1527 scan_info->cpi = &work_ccb->cpi;
1529 /* Cache on our stack so we can work asynchronously */
1530 max_target = scan_info->cpi->max_target;
1531 initiator_id = scan_info->cpi->initiator_id;
1535 * We can scan all targets in parallel, or do it sequentially.
1537 if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1539 scan_info->counter = 0;
1541 scan_info->counter = scan_info->cpi->max_target + 1;
1542 if (scan_info->cpi->initiator_id < scan_info->counter) {
1543 scan_info->counter--;
1547 for (i = 0; i <= max_target; i++) {
1549 if (i == initiator_id)
1552 status = xpt_create_path(&path, xpt_periph,
1553 request_ccb->ccb_h.path_id,
1555 if (status != CAM_REQ_CMP) {
1556 printf("scsi_scan_bus: xpt_create_path failed"
1557 " with status %#x, bus scan halted\n",
1559 free(scan_info, M_CAMXPT);
1560 request_ccb->ccb_h.status = status;
1561 xpt_free_ccb(work_ccb);
1562 xpt_done(request_ccb);
1565 work_ccb = xpt_alloc_ccb_nowait();
1566 if (work_ccb == NULL) {
1567 xpt_free_ccb((union ccb *)scan_info->cpi);
1568 free(scan_info, M_CAMXPT);
1569 xpt_free_path(path);
1570 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1571 xpt_done(request_ccb);
1574 xpt_setup_ccb(&work_ccb->ccb_h, path,
1575 request_ccb->ccb_h.pinfo.priority);
1576 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1577 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1578 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1579 work_ccb->crcn.flags = request_ccb->crcn.flags;
1580 xpt_action(work_ccb);
1587 struct cam_path *path;
1588 scsi_scan_bus_info *scan_info;
1590 target_id_t target_id;
1593 /* Reuse the same CCB to query if a device was really found */
1594 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1595 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1596 request_ccb->ccb_h.pinfo.priority);
1597 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1599 path_id = request_ccb->ccb_h.path_id;
1600 target_id = request_ccb->ccb_h.target_id;
1601 lun_id = request_ccb->ccb_h.target_lun;
1602 xpt_action(request_ccb);
1604 if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
1605 struct cam_ed *device;
1606 struct cam_et *target;
1610 * If we already probed lun 0 successfully, or
1611 * we have additional configured luns on this
1612 * target that might have "gone away", go onto
1615 target = request_ccb->ccb_h.path->target;
1617 * We may touch devices that we don't
1618 * hold references too, so ensure they
1619 * don't disappear out from under us.
1620 * The target above is referenced by the
1621 * path in the request ccb.
1624 device = TAILQ_FIRST(&target->ed_entries);
1625 if (device != NULL) {
1626 phl = CAN_SRCH_HI_SPARSE(device);
1627 if (device->lun_id == 0)
1628 device = TAILQ_NEXT(device, links);
1630 if ((lun_id != 0) || (device != NULL)) {
1631 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl)
1635 struct cam_ed *device;
1637 device = request_ccb->ccb_h.path->device;
1639 if ((SCSI_QUIRK(device)->quirks &
1640 CAM_QUIRK_NOLUNS) == 0) {
1641 /* Try the next lun */
1642 if (lun_id < (CAM_SCSI2_MAXLUN-1)
1643 || CAN_SRCH_HI_DENSE(device))
1649 * Free the current request path- we're done with it.
1651 xpt_free_path(request_ccb->ccb_h.path);
1654 * Check to see if we scan any further luns.
1656 if (lun_id == request_ccb->ccb_h.target_lun
1657 || lun_id > scan_info->cpi->max_lun) {
1662 if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1663 scan_info->counter++;
1664 if (scan_info->counter ==
1665 scan_info->cpi->initiator_id) {
1666 scan_info->counter++;
1668 if (scan_info->counter >=
1669 scan_info->cpi->max_target+1) {
1673 scan_info->counter--;
1674 if (scan_info->counter == 0) {
1679 xpt_free_ccb(request_ccb);
1680 xpt_free_ccb((union ccb *)scan_info->cpi);
1681 request_ccb = scan_info->request_ccb;
1682 free(scan_info, M_CAMXPT);
1683 request_ccb->ccb_h.status = CAM_REQ_CMP;
1684 xpt_done(request_ccb);
1688 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
1689 xpt_free_ccb(request_ccb);
1692 status = xpt_create_path(&path, xpt_periph,
1693 scan_info->request_ccb->ccb_h.path_id,
1694 scan_info->counter, 0);
1695 if (status != CAM_REQ_CMP) {
1696 printf("scsi_scan_bus: xpt_create_path failed"
1697 " with status %#x, bus scan halted\n",
1699 xpt_free_ccb(request_ccb);
1700 xpt_free_ccb((union ccb *)scan_info->cpi);
1701 request_ccb = scan_info->request_ccb;
1702 free(scan_info, M_CAMXPT);
1703 request_ccb->ccb_h.status = status;
1704 xpt_done(request_ccb);
1707 xpt_setup_ccb(&request_ccb->ccb_h, path,
1708 request_ccb->ccb_h.pinfo.priority);
1709 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1710 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1711 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1712 request_ccb->crcn.flags =
1713 scan_info->request_ccb->crcn.flags;
1715 status = xpt_create_path(&path, xpt_periph,
1716 path_id, target_id, lun_id);
1717 if (status != CAM_REQ_CMP) {
1718 printf("scsi_scan_bus: xpt_create_path failed "
1719 "with status %#x, halting LUN scan\n",
1723 xpt_setup_ccb(&request_ccb->ccb_h, path,
1724 request_ccb->ccb_h.pinfo.priority);
1725 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1726 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1727 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1728 request_ccb->crcn.flags =
1729 scan_info->request_ccb->crcn.flags;
1731 xpt_action(request_ccb);
1740 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
1741 cam_flags flags, union ccb *request_ccb)
1743 struct ccb_pathinq cpi;
1745 struct cam_path *new_path;
1746 struct cam_periph *old_periph;
1748 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1749 ("scsi_scan_lun\n"));
1751 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
1752 cpi.ccb_h.func_code = XPT_PATH_INQ;
1753 xpt_action((union ccb *)&cpi);
1755 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1756 if (request_ccb != NULL) {
1757 request_ccb->ccb_h.status = cpi.ccb_h.status;
1758 xpt_done(request_ccb);
1763 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1765 * Can't scan the bus on an adapter that
1766 * cannot perform the initiator role.
1768 if (request_ccb != NULL) {
1769 request_ccb->ccb_h.status = CAM_REQ_CMP;
1770 xpt_done(request_ccb);
1775 if (request_ccb == NULL) {
1776 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
1777 if (request_ccb == NULL) {
1778 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
1779 "can't continue\n");
1782 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
1783 if (new_path == NULL) {
1784 xpt_print(path, "scsi_scan_lun: can't allocate path, "
1785 "can't continue\n");
1786 free(request_ccb, M_CAMXPT);
1789 status = xpt_compile_path(new_path, xpt_periph,
1791 path->target->target_id,
1792 path->device->lun_id);
1794 if (status != CAM_REQ_CMP) {
1795 xpt_print(path, "scsi_scan_lun: can't compile path, "
1796 "can't continue\n");
1797 free(request_ccb, M_CAMXPT);
1798 free(new_path, M_CAMXPT);
1801 xpt_setup_ccb(&request_ccb->ccb_h, new_path, /*priority*/ 1);
1802 request_ccb->ccb_h.cbfcnp = xptscandone;
1803 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1804 request_ccb->crcn.flags = flags;
1807 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
1810 softc = (probe_softc *)old_periph->softc;
1811 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
1814 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1815 probestart, "probe",
1817 request_ccb->ccb_h.path, NULL, 0,
1820 if (status != CAM_REQ_CMP) {
1821 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
1822 "returned an error, can't continue probe\n");
1823 request_ccb->ccb_h.status = status;
1824 xpt_done(request_ccb);
1830 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1832 xpt_release_path(done_ccb->ccb_h.path);
1833 free(done_ccb->ccb_h.path, M_CAMXPT);
1834 free(done_ccb, M_CAMXPT);
1837 static struct cam_ed *
1838 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1840 struct cam_path path;
1841 struct scsi_quirk_entry *quirk;
1842 struct cam_ed *device;
1843 struct cam_ed *cur_device;
1845 device = xpt_alloc_device(bus, target, lun_id);
1850 * Take the default quirk entry until we have inquiry
1851 * data and can determine a better quirk to use.
1853 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
1854 device->quirk = (void *)quirk;
1855 device->mintags = quirk->mintags;
1856 device->maxtags = quirk->maxtags;
1857 bzero(&device->inq_data, sizeof(device->inq_data));
1858 device->inq_flags = 0;
1859 device->queue_flags = 0;
1860 device->serial_num = NULL;
1861 device->serial_num_len = 0;
1864 * XXX should be limited by number of CCBs this bus can
1867 bus->sim->max_ccbs += device->ccbq.devq_openings;
1868 /* Insertion sort into our target's device list */
1869 cur_device = TAILQ_FIRST(&target->ed_entries);
1870 while (cur_device != NULL && cur_device->lun_id < lun_id)
1871 cur_device = TAILQ_NEXT(cur_device, links);
1872 if (cur_device != NULL) {
1873 TAILQ_INSERT_BEFORE(cur_device, device, links);
1875 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
1877 target->generation++;
1878 if (lun_id != CAM_LUN_WILDCARD) {
1879 xpt_compile_path(&path,
1884 scsi_devise_transport(&path);
1885 xpt_release_path(&path);
1892 scsi_devise_transport(struct cam_path *path)
1894 struct ccb_pathinq cpi;
1895 struct ccb_trans_settings cts;
1896 struct scsi_inquiry_data *inq_buf;
1898 /* Get transport information from the SIM */
1899 xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
1900 cpi.ccb_h.func_code = XPT_PATH_INQ;
1901 xpt_action((union ccb *)&cpi);
1904 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1905 inq_buf = &path->device->inq_data;
1906 path->device->protocol = PROTO_SCSI;
1907 path->device->protocol_version =
1908 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1909 path->device->transport = cpi.transport;
1910 path->device->transport_version = cpi.transport_version;
1913 * Any device not using SPI3 features should
1914 * be considered SPI2 or lower.
1916 if (inq_buf != NULL) {
1917 if (path->device->transport == XPORT_SPI
1918 && (inq_buf->spi3data & SID_SPI_MASK) == 0
1919 && path->device->transport_version > 2)
1920 path->device->transport_version = 2;
1922 struct cam_ed* otherdev;
1924 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
1926 otherdev = TAILQ_NEXT(otherdev, links)) {
1927 if (otherdev != path->device)
1931 if (otherdev != NULL) {
1933 * Initially assume the same versioning as
1934 * prior luns for this target.
1936 path->device->protocol_version =
1937 otherdev->protocol_version;
1938 path->device->transport_version =
1939 otherdev->transport_version;
1941 /* Until we know better, opt for safty */
1942 path->device->protocol_version = 2;
1943 if (path->device->transport == XPORT_SPI)
1944 path->device->transport_version = 2;
1946 path->device->transport_version = 0;
1952 * For a device compliant with SPC-2 we should be able
1953 * to determine the transport version supported by
1954 * scrutinizing the version descriptors in the
1958 /* Tell the controller what we think */
1959 xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);
1960 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1961 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1962 cts.transport = path->device->transport;
1963 cts.transport_version = path->device->transport_version;
1964 cts.protocol = path->device->protocol;
1965 cts.protocol_version = path->device->protocol_version;
1966 cts.proto_specific.valid = 0;
1967 cts.xport_specific.valid = 0;
1968 xpt_action((union ccb *)&cts);
1972 scsi_action(union ccb *start_ccb)
1975 switch (start_ccb->ccb_h.func_code) {
1976 case XPT_SET_TRAN_SETTINGS:
1978 scsi_set_transfer_settings(&start_ccb->cts,
1979 start_ccb->ccb_h.path->device,
1980 /*async_update*/FALSE);
1984 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1987 scsi_scan_lun(start_ccb->ccb_h.path->periph,
1988 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1991 case XPT_GET_TRAN_SETTINGS:
1993 struct cam_sim *sim;
1995 sim = start_ccb->ccb_h.path->bus->sim;
1996 (*(sim->sim_action))(sim, start_ccb);
2000 xpt_action_default(start_ccb);
2006 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2009 struct ccb_pathinq cpi;
2010 struct ccb_trans_settings cur_cts;
2011 struct ccb_trans_settings_scsi *scsi;
2012 struct ccb_trans_settings_scsi *cur_scsi;
2013 struct cam_sim *sim;
2014 struct scsi_inquiry_data *inq_data;
2016 if (device == NULL) {
2017 cts->ccb_h.status = CAM_PATH_INVALID;
2018 xpt_done((union ccb *)cts);
2022 if (cts->protocol == PROTO_UNKNOWN
2023 || cts->protocol == PROTO_UNSPECIFIED) {
2024 cts->protocol = device->protocol;
2025 cts->protocol_version = device->protocol_version;
2028 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2029 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2030 cts->protocol_version = device->protocol_version;
2032 if (cts->protocol != device->protocol) {
2033 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2034 cts->protocol, device->protocol);
2035 cts->protocol = device->protocol;
2038 if (cts->protocol_version > device->protocol_version) {
2040 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2041 "Version from %d to %d?\n", cts->protocol_version,
2042 device->protocol_version);
2044 cts->protocol_version = device->protocol_version;
2047 if (cts->transport == XPORT_UNKNOWN
2048 || cts->transport == XPORT_UNSPECIFIED) {
2049 cts->transport = device->transport;
2050 cts->transport_version = device->transport_version;
2053 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2054 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2055 cts->transport_version = device->transport_version;
2057 if (cts->transport != device->transport) {
2058 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2059 cts->transport, device->transport);
2060 cts->transport = device->transport;
2063 if (cts->transport_version > device->transport_version) {
2065 xpt_print(cts->ccb_h.path, "Down reving Transport "
2066 "Version from %d to %d?\n", cts->transport_version,
2067 device->transport_version);
2069 cts->transport_version = device->transport_version;
2072 sim = cts->ccb_h.path->bus->sim;
2075 * Nothing more of interest to do unless
2076 * this is a device connected via the
2079 if (cts->protocol != PROTO_SCSI) {
2080 if (async_update == FALSE)
2081 (*(sim->sim_action))(sim, (union ccb *)cts);
2085 inq_data = &device->inq_data;
2086 scsi = &cts->proto_specific.scsi;
2087 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, /*priority*/1);
2088 cpi.ccb_h.func_code = XPT_PATH_INQ;
2089 xpt_action((union ccb *)&cpi);
2091 /* SCSI specific sanity checking */
2092 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2093 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2094 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2095 || (device->mintags == 0)) {
2097 * Can't tag on hardware that doesn't support tags,
2098 * doesn't have it enabled, or has broken tag support.
2100 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2103 if (async_update == FALSE) {
2105 * Perform sanity checking against what the
2106 * controller and device can do.
2108 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, /*priority*/1);
2109 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2110 cur_cts.type = cts->type;
2111 xpt_action((union ccb *)&cur_cts);
2112 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2115 cur_scsi = &cur_cts.proto_specific.scsi;
2116 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2117 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2118 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2120 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2121 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2124 /* SPI specific sanity checking */
2125 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2127 struct ccb_trans_settings_spi *spi;
2128 struct ccb_trans_settings_spi *cur_spi;
2130 spi = &cts->xport_specific.spi;
2132 cur_spi = &cur_cts.xport_specific.spi;
2134 /* Fill in any gaps in what the user gave us */
2135 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2136 spi->sync_period = cur_spi->sync_period;
2137 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2138 spi->sync_period = 0;
2139 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2140 spi->sync_offset = cur_spi->sync_offset;
2141 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2142 spi->sync_offset = 0;
2143 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2144 spi->ppr_options = cur_spi->ppr_options;
2145 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2146 spi->ppr_options = 0;
2147 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2148 spi->bus_width = cur_spi->bus_width;
2149 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2151 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2152 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2153 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2155 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2156 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2157 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2158 && (inq_data->flags & SID_Sync) == 0
2159 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2160 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2162 spi->sync_period = 0;
2163 spi->sync_offset = 0;
2166 switch (spi->bus_width) {
2167 case MSG_EXT_WDTR_BUS_32_BIT:
2168 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2169 || (inq_data->flags & SID_WBus32) != 0
2170 || cts->type == CTS_TYPE_USER_SETTINGS)
2171 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2173 /* Fall Through to 16-bit */
2174 case MSG_EXT_WDTR_BUS_16_BIT:
2175 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2176 || (inq_data->flags & SID_WBus16) != 0
2177 || cts->type == CTS_TYPE_USER_SETTINGS)
2178 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2179 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2182 /* Fall Through to 8-bit */
2183 default: /* New bus width?? */
2184 case MSG_EXT_WDTR_BUS_8_BIT:
2185 /* All targets can do this */
2186 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2190 spi3caps = cpi.xport_specific.spi.ppr_options;
2191 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2192 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2193 spi3caps &= inq_data->spi3data;
2195 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2196 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2198 if ((spi3caps & SID_SPI_IUS) == 0)
2199 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2201 if ((spi3caps & SID_SPI_QAS) == 0)
2202 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2204 /* No SPI Transfer settings are allowed unless we are wide */
2205 if (spi->bus_width == 0)
2206 spi->ppr_options = 0;
2208 if ((spi->valid & CTS_SPI_VALID_DISC)
2209 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2211 * Can't tag queue without disconnection.
2213 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2214 scsi->valid |= CTS_SCSI_VALID_TQ;
2218 * If we are currently performing tagged transactions to
2219 * this device and want to change its negotiation parameters,
2220 * go non-tagged for a bit to give the controller a chance to
2221 * negotiate unhampered by tag messages.
2223 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2224 && (device->inq_flags & SID_CmdQue) != 0
2225 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2226 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2227 CTS_SPI_VALID_SYNC_OFFSET|
2228 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2229 scsi_toggle_tags(cts->ccb_h.path);
2232 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2233 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2237 * If we are transitioning from tags to no-tags or
2238 * vice-versa, we need to carefully freeze and restart
2239 * the queue so that we don't overlap tagged and non-tagged
2240 * commands. We also temporarily stop tags if there is
2241 * a change in transfer negotiation settings to allow
2242 * "tag-less" negotiation.
2244 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2245 || (device->inq_flags & SID_CmdQue) != 0)
2246 device_tagenb = TRUE;
2248 device_tagenb = FALSE;
2250 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2251 && device_tagenb == FALSE)
2252 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2253 && device_tagenb == TRUE)) {
2255 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2257 * Delay change to use tags until after a
2258 * few commands have gone to this device so
2259 * the controller has time to perform transfer
2260 * negotiations without tagged messages getting
2263 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2264 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2266 struct ccb_relsim crs;
2268 xpt_freeze_devq(cts->ccb_h.path, /*count*/1);
2269 device->inq_flags &= ~SID_CmdQue;
2270 xpt_dev_ccbq_resize(cts->ccb_h.path,
2271 sim->max_dev_openings);
2272 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
2273 device->tag_delay_count = 0;
2275 xpt_setup_ccb(&crs.ccb_h, cts->ccb_h.path,
2277 crs.ccb_h.func_code = XPT_REL_SIMQ;
2278 crs.release_flags = RELSIM_RELEASE_AFTER_QEMPTY;
2280 = crs.release_timeout
2283 xpt_action((union ccb *)&crs);
2287 if (async_update == FALSE)
2288 (*(sim->sim_action))(sim, (union ccb *)cts);
2292 scsi_toggle_tags(struct cam_path *path)
2297 * Give controllers a chance to renegotiate
2298 * before starting tag operations. We
2299 * "toggle" tagged queuing off then on
2300 * which causes the tag enable command delay
2301 * counter to come into effect.
2304 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2305 || ((dev->inq_flags & SID_CmdQue) != 0
2306 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2307 struct ccb_trans_settings cts;
2309 xpt_setup_ccb(&cts.ccb_h, path, 1);
2310 cts.protocol = PROTO_SCSI;
2311 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2312 cts.transport = XPORT_UNSPECIFIED;
2313 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2314 cts.proto_specific.scsi.flags = 0;
2315 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2316 scsi_set_transfer_settings(&cts, path->device,
2317 /*async_update*/TRUE);
2318 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2319 scsi_set_transfer_settings(&cts, path->device,
2320 /*async_update*/TRUE);
2325 * Handle any per-device event notifications that require action by the XPT.
2328 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2329 struct cam_ed *device, void *async_arg)
2332 struct cam_path newpath;
2335 * We only need to handle events for real devices.
2337 if (target->target_id == CAM_TARGET_WILDCARD
2338 || device->lun_id == CAM_LUN_WILDCARD)
2342 * We need our own path with wildcards expanded to
2343 * handle certain types of events.
2345 if ((async_code == AC_SENT_BDR)
2346 || (async_code == AC_BUS_RESET)
2347 || (async_code == AC_INQ_CHANGED))
2348 status = xpt_compile_path(&newpath, NULL,
2353 status = CAM_REQ_CMP_ERR;
2355 if (status == CAM_REQ_CMP) {
2358 * Allow transfer negotiation to occur in a
2359 * tag free environment.
2361 if (async_code == AC_SENT_BDR
2362 || async_code == AC_BUS_RESET)
2363 scsi_toggle_tags(&newpath);
2365 if (async_code == AC_INQ_CHANGED) {
2367 * We've sent a start unit command, or
2368 * something similar to a device that
2369 * may have caused its inquiry data to
2370 * change. So we re-scan the device to
2371 * refresh the inquiry data for it.
2373 scsi_scan_lun(newpath.periph, &newpath,
2374 CAM_EXPECT_INQ_CHANGE, NULL);
2376 xpt_release_path(&newpath);
2377 } else if (async_code == AC_LOST_DEVICE) {
2378 device->flags |= CAM_DEV_UNCONFIGURED;
2379 } else if (async_code == AC_TRANSFER_NEG) {
2380 struct ccb_trans_settings *settings;
2382 settings = (struct ccb_trans_settings *)async_arg;
2383 scsi_set_transfer_settings(settings, device,
2384 /*async_update*/TRUE);