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 <cam/cam_ccb.h>
52 #include <cam/cam_queue.h>
53 #include <cam/cam_periph.h>
54 #include <cam/cam_sim.h>
55 #include <cam/cam_xpt.h>
56 #include <cam/cam_xpt_sim.h>
57 #include <cam/cam_xpt_periph.h>
58 #include <cam/cam_xpt_internal.h>
59 #include <cam/cam_debug.h>
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/scsi/scsi_message.h>
63 #include <cam/scsi/scsi_pass.h>
64 #include <machine/stdarg.h> /* for xpt_print below */
67 struct scsi_quirk_entry {
68 struct scsi_inquiry_pattern inq_pat;
70 #define CAM_QUIRK_NOLUNS 0x01
71 #define CAM_QUIRK_NOSERIAL 0x02
72 #define CAM_QUIRK_HILUNS 0x04
73 #define CAM_QUIRK_NOHILUNS 0x08
77 #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk))
79 static int cam_srch_hi = 0;
80 TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi);
81 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
82 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
83 sysctl_cam_search_luns, "I",
84 "allow search above LUN 7 for SCSI3 and greater devices");
86 #define CAM_SCSI2_MAXLUN 8
88 * If we're not quirked to search <= the first 8 luns
89 * and we are either quirked to search above lun 8,
90 * or we're > SCSI-2 and we've enabled hilun searching,
91 * or we're > SCSI-2 and the last lun was a success,
92 * we can look for luns above lun 8.
94 #define CAN_SRCH_HI_SPARSE(dv) \
95 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
96 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
97 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
99 #define CAN_SRCH_HI_DENSE(dv) \
100 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
101 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
102 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
104 static periph_init_t probe_periph_init;
106 static struct periph_driver probe_driver =
108 probe_periph_init, "probe",
109 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
113 PERIPHDRIVER_DECLARE(probe, probe_driver);
117 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
122 PROBE_TUR_FOR_NEGOTIATION,
123 PROBE_INQUIRY_BASIC_DV1,
124 PROBE_INQUIRY_BASIC_DV2,
129 static char *probe_action_text[] = {
132 "PROBE_FULL_INQUIRY",
134 "PROBE_SERIAL_NUM_0",
135 "PROBE_SERIAL_NUM_1",
136 "PROBE_TUR_FOR_NEGOTIATION",
137 "PROBE_INQUIRY_BASIC_DV1",
138 "PROBE_INQUIRY_BASIC_DV2",
143 #define PROBE_SET_ACTION(softc, newaction) \
146 text = probe_action_text; \
147 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \
148 ("Probe %s to %s\n", text[(softc)->action], \
149 text[(newaction)])); \
150 (softc)->action = (newaction); \
154 PROBE_INQUIRY_CKSUM = 0x01,
155 PROBE_SERIAL_CKSUM = 0x02,
156 PROBE_NO_ANNOUNCE = 0x04
160 TAILQ_HEAD(, ccb_hdr) request_ccbs;
166 struct cam_periph *periph;
169 static const char quantum[] = "QUANTUM";
170 static const char sony[] = "SONY";
171 static const char west_digital[] = "WDIGTL";
172 static const char samsung[] = "SAMSUNG";
173 static const char seagate[] = "SEAGATE";
174 static const char microp[] = "MICROP";
176 static struct scsi_quirk_entry scsi_quirk_table[] =
179 /* Reports QUEUE FULL for temporary resource shortages */
180 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
181 /*quirks*/0, /*mintags*/24, /*maxtags*/32
184 /* Reports QUEUE FULL for temporary resource shortages */
185 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
186 /*quirks*/0, /*mintags*/24, /*maxtags*/32
189 /* Reports QUEUE FULL for temporary resource shortages */
190 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
191 /*quirks*/0, /*mintags*/24, /*maxtags*/32
194 /* Broken tagged queuing drive */
195 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
196 /*quirks*/0, /*mintags*/0, /*maxtags*/0
199 /* Broken tagged queuing drive */
200 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
201 /*quirks*/0, /*mintags*/0, /*maxtags*/0
204 /* Broken tagged queuing drive */
205 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
206 /*quirks*/0, /*mintags*/0, /*maxtags*/0
210 * Unfortunately, the Quantum Atlas III has the same
211 * problem as the Atlas II drives above.
212 * Reported by: "Johan Granlund" <johan@granlund.nu>
214 * For future reference, the drive with the problem was:
215 * QUANTUM QM39100TD-SW N1B0
217 * It's possible that Quantum will fix the problem in later
218 * firmware revisions. If that happens, the quirk entry
219 * will need to be made specific to the firmware revisions
223 /* Reports QUEUE FULL for temporary resource shortages */
224 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
225 /*quirks*/0, /*mintags*/24, /*maxtags*/32
229 * 18 Gig Atlas III, same problem as the 9G version.
230 * Reported by: Andre Albsmeier
231 * <andre.albsmeier@mchp.siemens.de>
233 * For future reference, the drive with the problem was:
234 * QUANTUM QM318000TD-S N491
236 /* Reports QUEUE FULL for temporary resource shortages */
237 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
238 /*quirks*/0, /*mintags*/24, /*maxtags*/32
242 * Broken tagged queuing drive
243 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
244 * and: Martin Renters <martin@tdc.on.ca>
246 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
247 /*quirks*/0, /*mintags*/0, /*maxtags*/0
250 * The Seagate Medalist Pro drives have very poor write
251 * performance with anything more than 2 tags.
253 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
254 * Drive: <SEAGATE ST36530N 1444>
256 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
257 * Drive: <SEAGATE ST34520W 1281>
259 * No one has actually reported that the 9G version
260 * (ST39140*) of the Medalist Pro has the same problem, but
261 * we're assuming that it does because the 4G and 6.5G
262 * versions of the drive are broken.
265 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
266 /*quirks*/0, /*mintags*/2, /*maxtags*/2
269 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
270 /*quirks*/0, /*mintags*/2, /*maxtags*/2
273 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
274 /*quirks*/0, /*mintags*/2, /*maxtags*/2
278 * Slow when tagged queueing is enabled. Write performance
279 * steadily drops off with more and more concurrent
280 * transactions. Best sequential write performance with
281 * tagged queueing turned off and write caching turned on.
284 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
285 * Drive: DCAS-34330 w/ "S65A" firmware.
287 * The drive with the problem had the "S65A" firmware
288 * revision, and has also been reported (by Stephen J.
289 * Roznowski <sjr@home.net>) for a drive with the "S61A"
292 * Although no one has reported problems with the 2 gig
293 * version of the DCAS drive, the assumption is that it
294 * has the same problems as the 4 gig version. Therefore
295 * this quirk entries disables tagged queueing for all
298 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
299 /*quirks*/0, /*mintags*/0, /*maxtags*/0
302 /* Broken tagged queuing drive */
303 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
304 /*quirks*/0, /*mintags*/0, /*maxtags*/0
307 /* Broken tagged queuing drive */
308 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
309 /*quirks*/0, /*mintags*/0, /*maxtags*/0
312 /* This does not support other than LUN 0 */
313 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
314 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
318 * Broken tagged queuing drive.
320 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
323 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
324 /*quirks*/0, /*mintags*/0, /*maxtags*/0
328 * Slow when tagged queueing is enabled. (1.5MB/sec versus
330 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
331 * Best performance with these drives is achieved with
332 * tagged queueing turned off, and write caching turned on.
334 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
335 /*quirks*/0, /*mintags*/0, /*maxtags*/0
339 * Slow when tagged queueing is enabled. (1.5MB/sec versus
341 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
342 * Best performance with these drives is achieved with
343 * tagged queueing turned off, and write caching turned on.
345 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
346 /*quirks*/0, /*mintags*/0, /*maxtags*/0
350 * Doesn't handle queue full condition correctly,
351 * so we need to limit maxtags to what the device
352 * can handle instead of determining this automatically.
354 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
355 /*quirks*/0, /*mintags*/2, /*maxtags*/32
358 /* Really only one LUN */
359 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
360 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
363 /* I can't believe we need a quirk for DPT volumes. */
364 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
366 /*mintags*/0, /*maxtags*/255
370 * Many Sony CDROM drives don't like multi-LUN probing.
372 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
373 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
377 * This drive doesn't like multiple LUN probing.
378 * Submitted by: Parag Patel <parag@cgt.com>
380 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
381 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
384 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
385 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
389 * The 8200 doesn't like multi-lun probing, and probably
390 * don't like serial number requests either.
393 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
396 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
400 * Let's try the same as above, but for a drive that says
401 * it's an IPL-6860 but is actually an EXB 8200.
404 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
407 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
411 * These Hitachi drives don't like multi-lun probing.
412 * The PR submitter has a DK319H, but says that the Linux
413 * kernel has a similar work-around for the DK312 and DK314,
414 * so all DK31* drives are quirked here.
416 * Submitted by: Paul Haddad <paul@pth.com>
418 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
419 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
423 * The Hitachi CJ series with J8A8 firmware apparantly has
424 * problems with tagged commands.
426 * Reported by: amagai@nue.org
428 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
429 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
433 * These are the large storage arrays.
434 * Submitted by: William Carrel <william.carrel@infospace.com>
436 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
437 CAM_QUIRK_HILUNS, 2, 1024
441 * This old revision of the TDC3600 is also SCSI-1, and
442 * hangs upon serial number probing.
445 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
448 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
452 * Would repond to all LUNs if asked for.
455 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
458 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
462 * Would repond to all LUNs if asked for.
465 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
468 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
471 /* Submitted by: Matthew Dodd <winter@jurai.net> */
472 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
473 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
476 /* Submitted by: Matthew Dodd <winter@jurai.net> */
477 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
478 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
481 /* TeraSolutions special settings for TRC-22 RAID */
482 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
483 /*quirks*/0, /*mintags*/55, /*maxtags*/255
486 /* Veritas Storage Appliance */
487 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
488 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
492 * Would respond to all LUNs. Device type and removable
493 * flag are jumper-selectable.
495 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
501 /* EasyRAID E5A aka. areca ARC-6010 */
502 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
503 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
506 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
507 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
510 /* Default tagged queuing parameters for all devices */
512 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
513 /*vendor*/"*", /*product*/"*", /*revision*/"*"
515 /*quirks*/0, /*mintags*/2, /*maxtags*/255
519 static const int scsi_quirk_table_size =
520 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
522 static cam_status proberegister(struct cam_periph *periph,
524 static void probeschedule(struct cam_periph *probe_periph);
525 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
526 static void proberequestdefaultnegotiation(struct cam_periph *periph);
527 static int proberequestbackoff(struct cam_periph *periph,
528 struct cam_ed *device);
529 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
530 static void probecleanup(struct cam_periph *periph);
531 static void scsi_find_quirk(struct cam_ed *device);
532 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
533 static void scsi_scan_lun(struct cam_periph *periph,
534 struct cam_path *path, cam_flags flags,
536 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
537 static struct cam_ed *
538 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
540 static void scsi_devise_transport(struct cam_path *path);
541 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
542 struct cam_ed *device,
544 static void scsi_toggle_tags(struct cam_path *path);
545 static void scsi_dev_async(u_int32_t async_code,
547 struct cam_et *target,
548 struct cam_ed *device,
550 static void scsi_action(union ccb *start_ccb);
551 static void scsi_announce_periph(struct cam_periph *periph);
553 static struct xpt_xport scsi_xport = {
554 .alloc_device = scsi_alloc_device,
555 .action = scsi_action,
556 .async = scsi_dev_async,
557 .announce = scsi_announce_periph,
563 return (&scsi_xport);
572 proberegister(struct cam_periph *periph, void *arg)
574 union ccb *request_ccb; /* CCB representing the probe request */
578 request_ccb = (union ccb *)arg;
579 if (periph == NULL) {
580 printf("proberegister: periph was NULL!!\n");
581 return(CAM_REQ_CMP_ERR);
584 if (request_ccb == NULL) {
585 printf("proberegister: no probe CCB, "
586 "can't register device\n");
587 return(CAM_REQ_CMP_ERR);
590 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
593 printf("proberegister: Unable to probe new device. "
594 "Unable to allocate softc\n");
595 return(CAM_REQ_CMP_ERR);
597 TAILQ_INIT(&softc->request_ccbs);
598 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
601 periph->softc = softc;
602 softc->periph = periph;
603 softc->action = PROBE_INVALID;
604 status = cam_periph_acquire(periph);
605 if (status != CAM_REQ_CMP) {
611 * Ensure we've waited at least a bus settle
612 * delay before attempting to probe the device.
613 * For HBAs that don't do bus resets, this won't make a difference.
615 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
618 * Ensure nobody slip in until probe finish.
620 cam_freeze_devq_arg(periph->path,
621 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
622 probeschedule(periph);
627 probeschedule(struct cam_periph *periph)
629 struct ccb_pathinq cpi;
633 softc = (probe_softc *)periph->softc;
634 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
636 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
637 cpi.ccb_h.func_code = XPT_PATH_INQ;
638 xpt_action((union ccb *)&cpi);
641 * If a device has gone away and another device, or the same one,
642 * is back in the same place, it should have a unit attention
643 * condition pending. It will not report the unit attention in
644 * response to an inquiry, which may leave invalid transfer
645 * negotiations in effect. The TUR will reveal the unit attention
646 * condition. Only send the TUR for lun 0, since some devices
647 * will get confused by commands other than inquiry to non-existent
648 * luns. If you think a device has gone away start your scan from
649 * lun 0. This will insure that any bogus transfer settings are
652 * If we haven't seen the device before and the controller supports
653 * some kind of transfer negotiation, negotiate with the first
654 * sent command if no bus reset was performed at startup. This
655 * ensures that the device is not confused by transfer negotiation
656 * settings left over by loader or BIOS action.
658 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
659 && (ccb->ccb_h.target_lun == 0)) {
660 PROBE_SET_ACTION(softc, PROBE_TUR);
661 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
662 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
663 proberequestdefaultnegotiation(periph);
664 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
666 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
669 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
670 softc->flags |= PROBE_NO_ANNOUNCE;
672 softc->flags &= ~PROBE_NO_ANNOUNCE;
674 xpt_schedule(periph, CAM_PRIORITY_XPT);
678 probestart(struct cam_periph *periph, union ccb *start_ccb)
680 /* Probe the device that our peripheral driver points to */
681 struct ccb_scsiio *csio;
684 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
686 softc = (probe_softc *)periph->softc;
687 csio = &start_ccb->csio;
689 switch (softc->action) {
691 case PROBE_TUR_FOR_NEGOTIATION:
694 scsi_test_unit_ready(csio,
703 case PROBE_FULL_INQUIRY:
704 case PROBE_INQUIRY_BASIC_DV1:
705 case PROBE_INQUIRY_BASIC_DV2:
708 struct scsi_inquiry_data *inq_buf;
710 inq_buf = &periph->path->device->inq_data;
713 * If the device is currently configured, we calculate an
714 * MD5 checksum of the inquiry data, and if the serial number
715 * length is greater than 0, add the serial number data
716 * into the checksum as well. Once the inquiry and the
717 * serial number check finish, we attempt to figure out
718 * whether we still have the same device.
720 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
722 MD5Init(&softc->context);
723 MD5Update(&softc->context, (unsigned char *)inq_buf,
724 sizeof(struct scsi_inquiry_data));
725 softc->flags |= PROBE_INQUIRY_CKSUM;
726 if (periph->path->device->serial_num_len > 0) {
727 MD5Update(&softc->context,
728 periph->path->device->serial_num,
729 periph->path->device->serial_num_len);
730 softc->flags |= PROBE_SERIAL_CKSUM;
732 MD5Final(softc->digest, &softc->context);
735 if (softc->action == PROBE_INQUIRY)
736 inquiry_len = SHORT_INQUIRY_LENGTH;
738 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
741 * Some parallel SCSI devices fail to send an
742 * ignore wide residue message when dealing with
743 * odd length inquiry requests. Round up to be
746 inquiry_len = roundup2(inquiry_len, 2);
748 if (softc->action == PROBE_INQUIRY_BASIC_DV1
749 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
750 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
752 if (inq_buf == NULL) {
753 xpt_print(periph->path, "malloc failure- skipping Basic"
754 "Domain Validation\n");
755 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
756 scsi_test_unit_ready(csio,
773 /*timeout*/60 * 1000);
776 case PROBE_MODE_SENSE:
781 mode_buf_len = sizeof(struct scsi_mode_header_6)
782 + sizeof(struct scsi_mode_blk_desc)
783 + sizeof(struct scsi_control_page);
784 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
785 if (mode_buf != NULL) {
786 scsi_mode_sense(csio,
791 SMS_PAGE_CTRL_CURRENT,
792 SMS_CONTROL_MODE_PAGE,
799 xpt_print(periph->path, "Unable to mode sense control page - "
801 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
804 case PROBE_SERIAL_NUM_0:
806 struct scsi_vpd_supported_page_list *vpd_list = NULL;
807 struct cam_ed *device;
809 device = periph->path->device;
810 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOSERIAL) == 0) {
811 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
815 if (vpd_list != NULL) {
820 (u_int8_t *)vpd_list,
823 SVPD_SUPPORTED_PAGE_LIST,
825 /*timeout*/60 * 1000);
829 * We'll have to do without, let our probedone
830 * routine finish up for us.
832 start_ccb->csio.data_ptr = NULL;
833 probedone(periph, start_ccb);
836 case PROBE_SERIAL_NUM_1:
838 struct scsi_vpd_unit_serial_number *serial_buf;
839 struct cam_ed* device;
842 device = periph->path->device;
843 if (device->serial_num != NULL) {
844 free(device->serial_num, M_CAMXPT);
845 device->serial_num = NULL;
846 device->serial_num_len = 0;
849 serial_buf = (struct scsi_vpd_unit_serial_number *)
850 malloc(sizeof(*serial_buf), M_CAMXPT, M_NOWAIT|M_ZERO);
852 if (serial_buf != NULL) {
857 (u_int8_t *)serial_buf,
860 SVPD_UNIT_SERIAL_NUMBER,
862 /*timeout*/60 * 1000);
866 * We'll have to do without, let our probedone
867 * routine finish up for us.
869 start_ccb->csio.data_ptr = NULL;
870 probedone(periph, start_ccb);
874 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_INFO,
875 ("probestart: invalid action state\n"));
879 xpt_action(start_ccb);
883 proberequestdefaultnegotiation(struct cam_periph *periph)
885 struct ccb_trans_settings cts;
887 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
888 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
889 cts.type = CTS_TYPE_USER_SETTINGS;
890 xpt_action((union ccb *)&cts);
891 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
894 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
895 cts.type = CTS_TYPE_CURRENT_SETTINGS;
896 xpt_action((union ccb *)&cts);
900 * Backoff Negotiation Code- only pertinent for SPI devices.
903 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
905 struct ccb_trans_settings cts;
906 struct ccb_trans_settings_spi *spi;
908 memset(&cts, 0, sizeof (cts));
909 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
910 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
911 cts.type = CTS_TYPE_CURRENT_SETTINGS;
912 xpt_action((union ccb *)&cts);
913 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
915 xpt_print(periph->path,
916 "failed to get current device settings\n");
920 if (cts.transport != XPORT_SPI) {
922 xpt_print(periph->path, "not SPI transport\n");
926 spi = &cts.xport_specific.spi;
929 * We cannot renegotiate sync rate if we don't have one.
931 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
933 xpt_print(periph->path, "no sync rate known\n");
939 * We'll assert that we don't have to touch PPR options- the
940 * SIM will see what we do with period and offset and adjust
941 * the PPR options as appropriate.
945 * A sync rate with unknown or zero offset is nonsensical.
946 * A sync period of zero means Async.
948 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
949 || spi->sync_offset == 0 || spi->sync_period == 0) {
951 xpt_print(periph->path, "no sync rate available\n");
956 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
957 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
958 ("hit async: giving up on DV\n"));
964 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
965 * We don't try to remember 'last' settings to see if the SIM actually
966 * gets into the speed we want to set. We check on the SIM telling
967 * us that a requested speed is bad, but otherwise don't try and
968 * check the speed due to the asynchronous and handshake nature
971 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
974 if (spi->sync_period >= 0xf) {
975 spi->sync_period = 0;
976 spi->sync_offset = 0;
977 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
978 ("setting to async for DV\n"));
980 * Once we hit async, we don't want to try
983 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
984 } else if (bootverbose) {
985 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
986 ("DV: period 0x%x\n", spi->sync_period));
987 printf("setting period to 0x%x\n", spi->sync_period);
989 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
990 cts.type = CTS_TYPE_CURRENT_SETTINGS;
991 xpt_action((union ccb *)&cts);
992 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
995 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
996 ("DV: failed to set period 0x%x\n", spi->sync_period));
997 if (spi->sync_period == 0) {
1005 probedone(struct cam_periph *periph, union ccb *done_ccb)
1008 struct cam_path *path;
1011 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1013 softc = (probe_softc *)periph->softc;
1014 path = done_ccb->ccb_h.path;
1015 priority = done_ccb->ccb_h.pinfo.priority;
1017 switch (softc->action) {
1020 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1022 if (cam_periph_error(done_ccb, 0,
1023 SF_NO_PRINT, NULL) == ERESTART)
1025 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1026 /* Don't wedge the queue */
1027 xpt_release_devq(done_ccb->ccb_h.path,
1031 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1032 xpt_release_ccb(done_ccb);
1033 xpt_schedule(periph, priority);
1037 case PROBE_FULL_INQUIRY:
1039 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1040 struct scsi_inquiry_data *inq_buf;
1041 u_int8_t periph_qual;
1043 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1044 inq_buf = &path->device->inq_data;
1046 periph_qual = SID_QUAL(inq_buf);
1048 switch(periph_qual) {
1049 case SID_QUAL_LU_CONNECTED:
1054 * We conservatively request only
1055 * SHORT_INQUIRY_LEN bytes of inquiry
1056 * information during our first try
1057 * at sending an INQUIRY. If the device
1058 * has more information to give,
1059 * perform a second request specifying
1060 * the amount of information the device
1061 * is willing to give.
1063 len = inq_buf->additional_length
1064 + offsetof(struct scsi_inquiry_data,
1065 additional_length) + 1;
1066 if (softc->action == PROBE_INQUIRY
1067 && len > SHORT_INQUIRY_LENGTH) {
1068 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1069 xpt_release_ccb(done_ccb);
1070 xpt_schedule(periph, priority);
1074 scsi_find_quirk(path->device);
1076 scsi_devise_transport(path);
1077 if (INQ_DATA_TQ_ENABLED(inq_buf))
1078 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1080 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1082 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1083 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1084 xpt_acquire_device(path->device);
1086 xpt_release_ccb(done_ccb);
1087 xpt_schedule(periph, priority);
1093 } else if (cam_periph_error(done_ccb, 0,
1094 done_ccb->ccb_h.target_lun > 0
1095 ? SF_RETRY_UA|SF_QUIET_IR
1097 &softc->saved_ccb) == ERESTART) {
1099 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1100 /* Don't wedge the queue */
1101 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1105 * If we get to this point, we got an error status back
1106 * from the inquiry and the error status doesn't require
1107 * automatically retrying the command. Therefore, the
1108 * inquiry failed. If we had inquiry information before
1109 * for this device, but this latest inquiry command failed,
1110 * the device has probably gone away. If this device isn't
1111 * already marked unconfigured, notify the peripheral
1112 * drivers that this device is no more.
1114 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1115 /* Send the async notification. */
1116 xpt_async(AC_LOST_DEVICE, path, NULL);
1118 xpt_release_ccb(done_ccb);
1121 case PROBE_MODE_SENSE:
1123 struct ccb_scsiio *csio;
1124 struct scsi_mode_header_6 *mode_hdr;
1126 csio = &done_ccb->csio;
1127 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1128 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1129 struct scsi_control_page *page;
1132 offset = ((u_int8_t *)&mode_hdr[1])
1133 + mode_hdr->blk_desc_len;
1134 page = (struct scsi_control_page *)offset;
1135 path->device->queue_flags = page->queue_flags;
1136 } else if (cam_periph_error(done_ccb, 0,
1137 SF_RETRY_UA|SF_NO_PRINT,
1138 &softc->saved_ccb) == ERESTART) {
1140 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1141 /* Don't wedge the queue */
1142 xpt_release_devq(done_ccb->ccb_h.path,
1143 /*count*/1, /*run_queue*/TRUE);
1145 xpt_release_ccb(done_ccb);
1146 free(mode_hdr, M_CAMXPT);
1147 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1148 xpt_schedule(periph, priority);
1151 case PROBE_SERIAL_NUM_0:
1153 struct ccb_scsiio *csio;
1154 struct scsi_vpd_supported_page_list *page_list;
1155 int length, serialnum_supported, i;
1157 serialnum_supported = 0;
1158 csio = &done_ccb->csio;
1160 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1162 if (page_list == NULL) {
1164 * Don't process the command as it was never sent
1166 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1167 && (page_list->length > 0)) {
1168 length = min(page_list->length,
1169 SVPD_SUPPORTED_PAGES_SIZE);
1170 for (i = 0; i < length; i++) {
1171 if (page_list->list[i] ==
1172 SVPD_UNIT_SERIAL_NUMBER) {
1173 serialnum_supported = 1;
1177 } else if (cam_periph_error(done_ccb, 0,
1178 SF_RETRY_UA|SF_NO_PRINT,
1179 &softc->saved_ccb) == ERESTART) {
1181 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1182 /* Don't wedge the queue */
1183 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1187 if (page_list != NULL)
1188 free(page_list, M_CAMXPT);
1190 if (serialnum_supported) {
1191 xpt_release_ccb(done_ccb);
1192 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_1);
1193 xpt_schedule(periph, priority);
1197 csio->data_ptr = NULL;
1201 case PROBE_SERIAL_NUM_1:
1203 struct ccb_scsiio *csio;
1204 struct scsi_vpd_unit_serial_number *serial_buf;
1211 csio = &done_ccb->csio;
1212 priority = done_ccb->ccb_h.pinfo.priority;
1214 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1216 /* Clean up from previous instance of this device */
1217 if (path->device->serial_num != NULL) {
1218 free(path->device->serial_num, M_CAMXPT);
1219 path->device->serial_num = NULL;
1220 path->device->serial_num_len = 0;
1223 if (serial_buf == NULL) {
1225 * Don't process the command as it was never sent
1227 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1228 && (serial_buf->length > 0)) {
1231 path->device->serial_num =
1232 (u_int8_t *)malloc((serial_buf->length + 1),
1233 M_CAMXPT, M_NOWAIT);
1234 if (path->device->serial_num != NULL) {
1235 bcopy(serial_buf->serial_num,
1236 path->device->serial_num,
1237 serial_buf->length);
1238 path->device->serial_num_len =
1240 path->device->serial_num[serial_buf->length]
1243 } else if (cam_periph_error(done_ccb, 0,
1244 SF_RETRY_UA|SF_NO_PRINT,
1245 &softc->saved_ccb) == ERESTART) {
1247 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1248 /* Don't wedge the queue */
1249 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1254 * Let's see if we have seen this device before.
1256 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1258 u_int8_t digest[16];
1263 (unsigned char *)&path->device->inq_data,
1264 sizeof(struct scsi_inquiry_data));
1267 MD5Update(&context, serial_buf->serial_num,
1268 serial_buf->length);
1270 MD5Final(digest, &context);
1271 if (bcmp(softc->digest, digest, 16) == 0)
1275 * XXX Do we need to do a TUR in order to ensure
1276 * that the device really hasn't changed???
1279 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1280 xpt_async(AC_LOST_DEVICE, path, NULL);
1282 if (serial_buf != NULL)
1283 free(serial_buf, M_CAMXPT);
1287 * Now that we have all the necessary
1288 * information to safely perform transfer
1289 * negotiations... Controllers don't perform
1290 * any negotiation or tagged queuing until
1291 * after the first XPT_SET_TRAN_SETTINGS ccb is
1292 * received. So, on a new device, just retrieve
1293 * the user settings, and set them as the current
1294 * settings to set the device up.
1296 proberequestdefaultnegotiation(periph);
1297 xpt_release_ccb(done_ccb);
1300 * Perform a TUR to allow the controller to
1301 * perform any necessary transfer negotiation.
1303 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1304 xpt_schedule(periph, priority);
1307 xpt_release_ccb(done_ccb);
1310 case PROBE_TUR_FOR_NEGOTIATION:
1311 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1313 if (cam_periph_error(done_ccb, 0, SF_RETRY_UA,
1319 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1320 /* Don't wedge the queue */
1321 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1325 * Do Domain Validation for lun 0 on devices that claim
1326 * to support Synchronous Transfer modes.
1328 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1329 && done_ccb->ccb_h.target_lun == 0
1330 && (path->device->inq_data.flags & SID_Sync) != 0
1331 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1332 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1333 ("Begin Domain Validation\n"));
1334 path->device->flags |= CAM_DEV_IN_DV;
1335 xpt_release_ccb(done_ccb);
1336 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1337 xpt_schedule(periph, priority);
1340 if (softc->action == PROBE_DV_EXIT) {
1341 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1342 ("Leave Domain Validation\n"));
1344 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1345 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1346 xpt_acquire_device(path->device);
1348 path->device->flags &=
1349 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1350 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1351 /* Inform the XPT that a new device has been found */
1352 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1353 xpt_action(done_ccb);
1354 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1357 xpt_release_ccb(done_ccb);
1359 case PROBE_INQUIRY_BASIC_DV1:
1360 case PROBE_INQUIRY_BASIC_DV2:
1362 struct scsi_inquiry_data *nbuf;
1363 struct ccb_scsiio *csio;
1365 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1366 /* Don't wedge the queue */
1367 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1370 csio = &done_ccb->csio;
1371 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1372 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1374 "inquiry data fails comparison at DV%d step\n",
1375 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1376 if (proberequestbackoff(periph, path->device)) {
1377 path->device->flags &= ~CAM_DEV_IN_DV;
1378 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1381 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1383 free(nbuf, M_CAMXPT);
1384 xpt_release_ccb(done_ccb);
1385 xpt_schedule(periph, priority);
1388 free(nbuf, M_CAMXPT);
1389 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1390 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1391 xpt_release_ccb(done_ccb);
1392 xpt_schedule(periph, priority);
1395 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1396 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1397 ("Leave Domain Validation Successfully\n"));
1399 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1400 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1401 xpt_acquire_device(path->device);
1403 path->device->flags &=
1404 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1405 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1406 /* Inform the XPT that a new device has been found */
1407 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1408 xpt_action(done_ccb);
1409 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1412 xpt_release_ccb(done_ccb);
1416 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO,
1417 ("probedone: invalid action state\n"));
1421 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1422 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1423 done_ccb->ccb_h.status = CAM_REQ_CMP;
1425 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1426 cam_release_devq(periph->path,
1427 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1428 cam_periph_invalidate(periph);
1429 cam_periph_release_locked(periph);
1431 probeschedule(periph);
1436 probecleanup(struct cam_periph *periph)
1438 free(periph->softc, M_CAMXPT);
1442 scsi_find_quirk(struct cam_ed *device)
1444 struct scsi_quirk_entry *quirk;
1447 match = cam_quirkmatch((caddr_t)&device->inq_data,
1448 (caddr_t)scsi_quirk_table,
1449 sizeof(scsi_quirk_table) /
1450 sizeof(*scsi_quirk_table),
1451 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1454 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1456 quirk = (struct scsi_quirk_entry *)match;
1457 device->quirk = quirk;
1458 device->mintags = quirk->mintags;
1459 device->maxtags = quirk->maxtags;
1463 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1468 error = sysctl_handle_int(oidp, &bool, 0, req);
1469 if (error != 0 || req->newptr == NULL)
1471 if (bool == 0 || bool == 1) {
1480 union ccb *request_ccb;
1481 struct ccb_pathinq *cpi;
1483 } scsi_scan_bus_info;
1486 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1487 * As the scan progresses, scsi_scan_bus is used as the
1488 * callback on completion function.
1491 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1493 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1494 ("scsi_scan_bus\n"));
1495 switch (request_ccb->ccb_h.func_code) {
1498 scsi_scan_bus_info *scan_info;
1499 union ccb *work_ccb, *reset_ccb;
1500 struct cam_path *path;
1505 /* Find out the characteristics of the bus */
1506 work_ccb = xpt_alloc_ccb_nowait();
1507 if (work_ccb == NULL) {
1508 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1509 xpt_done(request_ccb);
1512 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1513 request_ccb->ccb_h.pinfo.priority);
1514 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1515 xpt_action(work_ccb);
1516 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1517 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1518 xpt_free_ccb(work_ccb);
1519 xpt_done(request_ccb);
1523 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1525 * Can't scan the bus on an adapter that
1526 * cannot perform the initiator role.
1528 request_ccb->ccb_h.status = CAM_REQ_CMP;
1529 xpt_free_ccb(work_ccb);
1530 xpt_done(request_ccb);
1534 /* We may need to reset bus first, if we haven't done it yet. */
1535 if ((work_ccb->cpi.hba_inquiry &
1536 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1537 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1538 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1539 reset_ccb = xpt_alloc_ccb_nowait();
1540 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1542 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1543 xpt_action(reset_ccb);
1544 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1545 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1546 xpt_free_ccb(reset_ccb);
1547 xpt_free_ccb(work_ccb);
1548 xpt_done(request_ccb);
1551 xpt_free_ccb(reset_ccb);
1554 /* Save some state for use while we probe for devices */
1555 scan_info = (scsi_scan_bus_info *)
1556 malloc(sizeof(scsi_scan_bus_info), M_CAMXPT, M_NOWAIT);
1557 if (scan_info == NULL) {
1558 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1559 xpt_done(request_ccb);
1562 scan_info->request_ccb = request_ccb;
1563 scan_info->cpi = &work_ccb->cpi;
1565 /* Cache on our stack so we can work asynchronously */
1566 max_target = scan_info->cpi->max_target;
1567 initiator_id = scan_info->cpi->initiator_id;
1571 * We can scan all targets in parallel, or do it sequentially.
1573 if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1575 scan_info->counter = 0;
1577 scan_info->counter = scan_info->cpi->max_target + 1;
1578 if (scan_info->cpi->initiator_id < scan_info->counter) {
1579 scan_info->counter--;
1583 for (i = 0; i <= max_target; i++) {
1585 if (i == initiator_id)
1588 status = xpt_create_path(&path, xpt_periph,
1589 request_ccb->ccb_h.path_id,
1591 if (status != CAM_REQ_CMP) {
1592 printf("scsi_scan_bus: xpt_create_path failed"
1593 " with status %#x, bus scan halted\n",
1595 free(scan_info, M_CAMXPT);
1596 request_ccb->ccb_h.status = status;
1597 xpt_free_ccb(work_ccb);
1598 xpt_done(request_ccb);
1601 work_ccb = xpt_alloc_ccb_nowait();
1602 if (work_ccb == NULL) {
1603 xpt_free_ccb((union ccb *)scan_info->cpi);
1604 free(scan_info, M_CAMXPT);
1605 xpt_free_path(path);
1606 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1607 xpt_done(request_ccb);
1610 xpt_setup_ccb(&work_ccb->ccb_h, path,
1611 request_ccb->ccb_h.pinfo.priority);
1612 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1613 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1614 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1615 work_ccb->crcn.flags = request_ccb->crcn.flags;
1616 xpt_action(work_ccb);
1623 struct cam_path *path;
1624 scsi_scan_bus_info *scan_info;
1626 target_id_t target_id;
1629 /* Reuse the same CCB to query if a device was really found */
1630 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1631 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1632 request_ccb->ccb_h.pinfo.priority);
1633 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1635 path_id = request_ccb->ccb_h.path_id;
1636 target_id = request_ccb->ccb_h.target_id;
1637 lun_id = request_ccb->ccb_h.target_lun;
1638 xpt_action(request_ccb);
1640 if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
1641 struct cam_ed *device;
1642 struct cam_et *target;
1646 * If we already probed lun 0 successfully, or
1647 * we have additional configured luns on this
1648 * target that might have "gone away", go onto
1651 target = request_ccb->ccb_h.path->target;
1653 * We may touch devices that we don't
1654 * hold references too, so ensure they
1655 * don't disappear out from under us.
1656 * The target above is referenced by the
1657 * path in the request ccb.
1660 device = TAILQ_FIRST(&target->ed_entries);
1661 if (device != NULL) {
1662 phl = CAN_SRCH_HI_SPARSE(device);
1663 if (device->lun_id == 0)
1664 device = TAILQ_NEXT(device, links);
1666 if ((lun_id != 0) || (device != NULL)) {
1667 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl)
1671 struct cam_ed *device;
1673 device = request_ccb->ccb_h.path->device;
1675 if ((SCSI_QUIRK(device)->quirks &
1676 CAM_QUIRK_NOLUNS) == 0) {
1677 /* Try the next lun */
1678 if (lun_id < (CAM_SCSI2_MAXLUN-1)
1679 || CAN_SRCH_HI_DENSE(device))
1685 * Free the current request path- we're done with it.
1687 xpt_free_path(request_ccb->ccb_h.path);
1690 * Check to see if we scan any further luns.
1692 if (lun_id == request_ccb->ccb_h.target_lun
1693 || lun_id > scan_info->cpi->max_lun) {
1698 if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1699 scan_info->counter++;
1700 if (scan_info->counter ==
1701 scan_info->cpi->initiator_id) {
1702 scan_info->counter++;
1704 if (scan_info->counter >=
1705 scan_info->cpi->max_target+1) {
1709 scan_info->counter--;
1710 if (scan_info->counter == 0) {
1715 xpt_free_ccb(request_ccb);
1716 xpt_free_ccb((union ccb *)scan_info->cpi);
1717 request_ccb = scan_info->request_ccb;
1718 free(scan_info, M_CAMXPT);
1719 request_ccb->ccb_h.status = CAM_REQ_CMP;
1720 xpt_done(request_ccb);
1724 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
1725 xpt_free_ccb(request_ccb);
1728 status = xpt_create_path(&path, xpt_periph,
1729 scan_info->request_ccb->ccb_h.path_id,
1730 scan_info->counter, 0);
1731 if (status != CAM_REQ_CMP) {
1732 printf("scsi_scan_bus: xpt_create_path failed"
1733 " with status %#x, bus scan halted\n",
1735 xpt_free_ccb(request_ccb);
1736 xpt_free_ccb((union ccb *)scan_info->cpi);
1737 request_ccb = scan_info->request_ccb;
1738 free(scan_info, M_CAMXPT);
1739 request_ccb->ccb_h.status = status;
1740 xpt_done(request_ccb);
1743 xpt_setup_ccb(&request_ccb->ccb_h, path,
1744 request_ccb->ccb_h.pinfo.priority);
1745 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1746 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1747 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1748 request_ccb->crcn.flags =
1749 scan_info->request_ccb->crcn.flags;
1751 status = xpt_create_path(&path, xpt_periph,
1752 path_id, target_id, lun_id);
1753 if (status != CAM_REQ_CMP) {
1754 printf("scsi_scan_bus: xpt_create_path failed "
1755 "with status %#x, halting LUN scan\n",
1759 xpt_setup_ccb(&request_ccb->ccb_h, path,
1760 request_ccb->ccb_h.pinfo.priority);
1761 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1762 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1763 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1764 request_ccb->crcn.flags =
1765 scan_info->request_ccb->crcn.flags;
1767 xpt_action(request_ccb);
1776 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
1777 cam_flags flags, union ccb *request_ccb)
1779 struct ccb_pathinq cpi;
1781 struct cam_path *new_path;
1782 struct cam_periph *old_periph;
1784 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
1786 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1787 cpi.ccb_h.func_code = XPT_PATH_INQ;
1788 xpt_action((union ccb *)&cpi);
1790 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1791 if (request_ccb != NULL) {
1792 request_ccb->ccb_h.status = cpi.ccb_h.status;
1793 xpt_done(request_ccb);
1798 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1800 * Can't scan the bus on an adapter that
1801 * cannot perform the initiator role.
1803 if (request_ccb != NULL) {
1804 request_ccb->ccb_h.status = CAM_REQ_CMP;
1805 xpt_done(request_ccb);
1810 if (request_ccb == NULL) {
1811 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
1812 if (request_ccb == NULL) {
1813 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
1814 "can't continue\n");
1817 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
1818 if (new_path == NULL) {
1819 xpt_print(path, "scsi_scan_lun: can't allocate path, "
1820 "can't continue\n");
1821 free(request_ccb, M_CAMXPT);
1824 status = xpt_compile_path(new_path, xpt_periph,
1826 path->target->target_id,
1827 path->device->lun_id);
1829 if (status != CAM_REQ_CMP) {
1830 xpt_print(path, "scsi_scan_lun: can't compile path, "
1831 "can't continue\n");
1832 free(request_ccb, M_CAMXPT);
1833 free(new_path, M_CAMXPT);
1836 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1837 request_ccb->ccb_h.cbfcnp = xptscandone;
1838 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1839 request_ccb->crcn.flags = flags;
1842 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
1845 softc = (probe_softc *)old_periph->softc;
1846 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
1849 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1850 probestart, "probe",
1852 request_ccb->ccb_h.path, NULL, 0,
1855 if (status != CAM_REQ_CMP) {
1856 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
1857 "returned an error, can't continue probe\n");
1858 request_ccb->ccb_h.status = status;
1859 xpt_done(request_ccb);
1865 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1867 xpt_release_path(done_ccb->ccb_h.path);
1868 free(done_ccb->ccb_h.path, M_CAMXPT);
1869 free(done_ccb, M_CAMXPT);
1872 static struct cam_ed *
1873 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1875 struct cam_path path;
1876 struct scsi_quirk_entry *quirk;
1877 struct cam_ed *device;
1878 struct cam_ed *cur_device;
1880 device = xpt_alloc_device(bus, target, lun_id);
1885 * Take the default quirk entry until we have inquiry
1886 * data and can determine a better quirk to use.
1888 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
1889 device->quirk = (void *)quirk;
1890 device->mintags = quirk->mintags;
1891 device->maxtags = quirk->maxtags;
1892 bzero(&device->inq_data, sizeof(device->inq_data));
1893 device->inq_flags = 0;
1894 device->queue_flags = 0;
1895 device->serial_num = NULL;
1896 device->serial_num_len = 0;
1899 * XXX should be limited by number of CCBs this bus can
1902 bus->sim->max_ccbs += device->ccbq.devq_openings;
1903 /* Insertion sort into our target's device list */
1904 cur_device = TAILQ_FIRST(&target->ed_entries);
1905 while (cur_device != NULL && cur_device->lun_id < lun_id)
1906 cur_device = TAILQ_NEXT(cur_device, links);
1907 if (cur_device != NULL) {
1908 TAILQ_INSERT_BEFORE(cur_device, device, links);
1910 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
1912 target->generation++;
1913 if (lun_id != CAM_LUN_WILDCARD) {
1914 xpt_compile_path(&path,
1919 scsi_devise_transport(&path);
1920 xpt_release_path(&path);
1927 scsi_devise_transport(struct cam_path *path)
1929 struct ccb_pathinq cpi;
1930 struct ccb_trans_settings cts;
1931 struct scsi_inquiry_data *inq_buf;
1933 /* Get transport information from the SIM */
1934 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1935 cpi.ccb_h.func_code = XPT_PATH_INQ;
1936 xpt_action((union ccb *)&cpi);
1939 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1940 inq_buf = &path->device->inq_data;
1941 path->device->protocol = PROTO_SCSI;
1942 path->device->protocol_version =
1943 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1944 path->device->transport = cpi.transport;
1945 path->device->transport_version = cpi.transport_version;
1948 * Any device not using SPI3 features should
1949 * be considered SPI2 or lower.
1951 if (inq_buf != NULL) {
1952 if (path->device->transport == XPORT_SPI
1953 && (inq_buf->spi3data & SID_SPI_MASK) == 0
1954 && path->device->transport_version > 2)
1955 path->device->transport_version = 2;
1957 struct cam_ed* otherdev;
1959 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
1961 otherdev = TAILQ_NEXT(otherdev, links)) {
1962 if (otherdev != path->device)
1966 if (otherdev != NULL) {
1968 * Initially assume the same versioning as
1969 * prior luns for this target.
1971 path->device->protocol_version =
1972 otherdev->protocol_version;
1973 path->device->transport_version =
1974 otherdev->transport_version;
1976 /* Until we know better, opt for safty */
1977 path->device->protocol_version = 2;
1978 if (path->device->transport == XPORT_SPI)
1979 path->device->transport_version = 2;
1981 path->device->transport_version = 0;
1987 * For a device compliant with SPC-2 we should be able
1988 * to determine the transport version supported by
1989 * scrutinizing the version descriptors in the
1993 /* Tell the controller what we think */
1994 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1995 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1996 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1997 cts.transport = path->device->transport;
1998 cts.transport_version = path->device->transport_version;
1999 cts.protocol = path->device->protocol;
2000 cts.protocol_version = path->device->protocol_version;
2001 cts.proto_specific.valid = 0;
2002 cts.xport_specific.valid = 0;
2003 xpt_action((union ccb *)&cts);
2007 scsi_action(union ccb *start_ccb)
2010 switch (start_ccb->ccb_h.func_code) {
2011 case XPT_SET_TRAN_SETTINGS:
2013 scsi_set_transfer_settings(&start_ccb->cts,
2014 start_ccb->ccb_h.path->device,
2015 /*async_update*/FALSE);
2019 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2022 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2023 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2026 case XPT_GET_TRAN_SETTINGS:
2028 struct cam_sim *sim;
2030 sim = start_ccb->ccb_h.path->bus->sim;
2031 (*(sim->sim_action))(sim, start_ccb);
2035 xpt_action_default(start_ccb);
2041 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2044 struct ccb_pathinq cpi;
2045 struct ccb_trans_settings cur_cts;
2046 struct ccb_trans_settings_scsi *scsi;
2047 struct ccb_trans_settings_scsi *cur_scsi;
2048 struct cam_sim *sim;
2049 struct scsi_inquiry_data *inq_data;
2051 if (device == NULL) {
2052 cts->ccb_h.status = CAM_PATH_INVALID;
2053 xpt_done((union ccb *)cts);
2057 if (cts->protocol == PROTO_UNKNOWN
2058 || cts->protocol == PROTO_UNSPECIFIED) {
2059 cts->protocol = device->protocol;
2060 cts->protocol_version = device->protocol_version;
2063 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2064 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2065 cts->protocol_version = device->protocol_version;
2067 if (cts->protocol != device->protocol) {
2068 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2069 cts->protocol, device->protocol);
2070 cts->protocol = device->protocol;
2073 if (cts->protocol_version > device->protocol_version) {
2075 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2076 "Version from %d to %d?\n", cts->protocol_version,
2077 device->protocol_version);
2079 cts->protocol_version = device->protocol_version;
2082 if (cts->transport == XPORT_UNKNOWN
2083 || cts->transport == XPORT_UNSPECIFIED) {
2084 cts->transport = device->transport;
2085 cts->transport_version = device->transport_version;
2088 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2089 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2090 cts->transport_version = device->transport_version;
2092 if (cts->transport != device->transport) {
2093 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2094 cts->transport, device->transport);
2095 cts->transport = device->transport;
2098 if (cts->transport_version > device->transport_version) {
2100 xpt_print(cts->ccb_h.path, "Down reving Transport "
2101 "Version from %d to %d?\n", cts->transport_version,
2102 device->transport_version);
2104 cts->transport_version = device->transport_version;
2107 sim = cts->ccb_h.path->bus->sim;
2110 * Nothing more of interest to do unless
2111 * this is a device connected via the
2114 if (cts->protocol != PROTO_SCSI) {
2115 if (async_update == FALSE)
2116 (*(sim->sim_action))(sim, (union ccb *)cts);
2120 inq_data = &device->inq_data;
2121 scsi = &cts->proto_specific.scsi;
2122 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2123 cpi.ccb_h.func_code = XPT_PATH_INQ;
2124 xpt_action((union ccb *)&cpi);
2126 /* SCSI specific sanity checking */
2127 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2128 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2129 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2130 || (device->mintags == 0)) {
2132 * Can't tag on hardware that doesn't support tags,
2133 * doesn't have it enabled, or has broken tag support.
2135 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2138 if (async_update == FALSE) {
2140 * Perform sanity checking against what the
2141 * controller and device can do.
2143 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2144 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2145 cur_cts.type = cts->type;
2146 xpt_action((union ccb *)&cur_cts);
2147 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2150 cur_scsi = &cur_cts.proto_specific.scsi;
2151 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2152 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2153 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2155 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2156 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2159 /* SPI specific sanity checking */
2160 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2162 struct ccb_trans_settings_spi *spi;
2163 struct ccb_trans_settings_spi *cur_spi;
2165 spi = &cts->xport_specific.spi;
2167 cur_spi = &cur_cts.xport_specific.spi;
2169 /* Fill in any gaps in what the user gave us */
2170 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2171 spi->sync_period = cur_spi->sync_period;
2172 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2173 spi->sync_period = 0;
2174 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2175 spi->sync_offset = cur_spi->sync_offset;
2176 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2177 spi->sync_offset = 0;
2178 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2179 spi->ppr_options = cur_spi->ppr_options;
2180 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2181 spi->ppr_options = 0;
2182 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2183 spi->bus_width = cur_spi->bus_width;
2184 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2186 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2187 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2188 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2190 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2191 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2192 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2193 && (inq_data->flags & SID_Sync) == 0
2194 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2195 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2197 spi->sync_period = 0;
2198 spi->sync_offset = 0;
2201 switch (spi->bus_width) {
2202 case MSG_EXT_WDTR_BUS_32_BIT:
2203 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2204 || (inq_data->flags & SID_WBus32) != 0
2205 || cts->type == CTS_TYPE_USER_SETTINGS)
2206 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2208 /* Fall Through to 16-bit */
2209 case MSG_EXT_WDTR_BUS_16_BIT:
2210 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2211 || (inq_data->flags & SID_WBus16) != 0
2212 || cts->type == CTS_TYPE_USER_SETTINGS)
2213 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2214 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2217 /* Fall Through to 8-bit */
2218 default: /* New bus width?? */
2219 case MSG_EXT_WDTR_BUS_8_BIT:
2220 /* All targets can do this */
2221 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2225 spi3caps = cpi.xport_specific.spi.ppr_options;
2226 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2227 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2228 spi3caps &= inq_data->spi3data;
2230 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2231 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2233 if ((spi3caps & SID_SPI_IUS) == 0)
2234 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2236 if ((spi3caps & SID_SPI_QAS) == 0)
2237 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2239 /* No SPI Transfer settings are allowed unless we are wide */
2240 if (spi->bus_width == 0)
2241 spi->ppr_options = 0;
2243 if ((spi->valid & CTS_SPI_VALID_DISC)
2244 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2246 * Can't tag queue without disconnection.
2248 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2249 scsi->valid |= CTS_SCSI_VALID_TQ;
2253 * If we are currently performing tagged transactions to
2254 * this device and want to change its negotiation parameters,
2255 * go non-tagged for a bit to give the controller a chance to
2256 * negotiate unhampered by tag messages.
2258 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2259 && (device->inq_flags & SID_CmdQue) != 0
2260 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2261 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2262 CTS_SPI_VALID_SYNC_OFFSET|
2263 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2264 scsi_toggle_tags(cts->ccb_h.path);
2267 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2268 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2272 * If we are transitioning from tags to no-tags or
2273 * vice-versa, we need to carefully freeze and restart
2274 * the queue so that we don't overlap tagged and non-tagged
2275 * commands. We also temporarily stop tags if there is
2276 * a change in transfer negotiation settings to allow
2277 * "tag-less" negotiation.
2279 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2280 || (device->inq_flags & SID_CmdQue) != 0)
2281 device_tagenb = TRUE;
2283 device_tagenb = FALSE;
2285 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2286 && device_tagenb == FALSE)
2287 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2288 && device_tagenb == TRUE)) {
2290 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2292 * Delay change to use tags until after a
2293 * few commands have gone to this device so
2294 * the controller has time to perform transfer
2295 * negotiations without tagged messages getting
2298 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2299 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2301 xpt_stop_tags(cts->ccb_h.path);
2305 if (async_update == FALSE)
2306 (*(sim->sim_action))(sim, (union ccb *)cts);
2310 scsi_toggle_tags(struct cam_path *path)
2315 * Give controllers a chance to renegotiate
2316 * before starting tag operations. We
2317 * "toggle" tagged queuing off then on
2318 * which causes the tag enable command delay
2319 * counter to come into effect.
2322 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2323 || ((dev->inq_flags & SID_CmdQue) != 0
2324 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2325 struct ccb_trans_settings cts;
2327 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2328 cts.protocol = PROTO_SCSI;
2329 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2330 cts.transport = XPORT_UNSPECIFIED;
2331 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2332 cts.proto_specific.scsi.flags = 0;
2333 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2334 scsi_set_transfer_settings(&cts, path->device,
2335 /*async_update*/TRUE);
2336 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2337 scsi_set_transfer_settings(&cts, path->device,
2338 /*async_update*/TRUE);
2343 * Handle any per-device event notifications that require action by the XPT.
2346 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2347 struct cam_ed *device, void *async_arg)
2350 struct cam_path newpath;
2353 * We only need to handle events for real devices.
2355 if (target->target_id == CAM_TARGET_WILDCARD
2356 || device->lun_id == CAM_LUN_WILDCARD)
2360 * We need our own path with wildcards expanded to
2361 * handle certain types of events.
2363 if ((async_code == AC_SENT_BDR)
2364 || (async_code == AC_BUS_RESET)
2365 || (async_code == AC_INQ_CHANGED))
2366 status = xpt_compile_path(&newpath, NULL,
2371 status = CAM_REQ_CMP_ERR;
2373 if (status == CAM_REQ_CMP) {
2376 * Allow transfer negotiation to occur in a
2377 * tag free environment and after settle delay.
2379 if (async_code == AC_SENT_BDR
2380 || async_code == AC_BUS_RESET) {
2381 cam_freeze_devq(&newpath);
2382 cam_release_devq(&newpath,
2383 RELSIM_RELEASE_AFTER_TIMEOUT,
2385 /*timeout*/scsi_delay,
2386 /*getcount_only*/0);
2387 scsi_toggle_tags(&newpath);
2390 if (async_code == AC_INQ_CHANGED) {
2392 * We've sent a start unit command, or
2393 * something similar to a device that
2394 * may have caused its inquiry data to
2395 * change. So we re-scan the device to
2396 * refresh the inquiry data for it.
2398 scsi_scan_lun(newpath.periph, &newpath,
2399 CAM_EXPECT_INQ_CHANGE, NULL);
2401 xpt_release_path(&newpath);
2402 } else if (async_code == AC_LOST_DEVICE &&
2403 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2404 device->flags |= CAM_DEV_UNCONFIGURED;
2405 xpt_release_device(device);
2406 } else if (async_code == AC_TRANSFER_NEG) {
2407 struct ccb_trans_settings *settings;
2409 settings = (struct ccb_trans_settings *)async_arg;
2410 scsi_set_transfer_settings(settings, device,
2411 /*async_update*/TRUE);
2416 scsi_announce_periph(struct cam_periph *periph)
2418 struct ccb_pathinq cpi;
2419 struct ccb_trans_settings cts;
2420 struct cam_path *path = periph->path;
2425 mtx_assert(periph->sim->mtx, MA_OWNED);
2427 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2428 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2429 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2430 xpt_action((union ccb*)&cts);
2431 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2433 /* Ask the SIM for its base transfer speed */
2434 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2435 cpi.ccb_h.func_code = XPT_PATH_INQ;
2436 xpt_action((union ccb *)&cpi);
2437 /* Report connection speed */
2438 speed = cpi.base_transfer_speed;
2440 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2441 struct ccb_trans_settings_spi *spi =
2442 &cts.xport_specific.spi;
2444 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2445 && spi->sync_offset != 0) {
2446 freq = scsi_calc_syncsrate(spi->sync_period);
2449 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2450 speed *= (0x01 << spi->bus_width);
2452 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2453 struct ccb_trans_settings_fc *fc =
2454 &cts.xport_specific.fc;
2456 if (fc->valid & CTS_FC_VALID_SPEED)
2457 speed = fc->bitrate;
2459 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2460 struct ccb_trans_settings_sas *sas =
2461 &cts.xport_specific.sas;
2463 if (sas->valid & CTS_SAS_VALID_SPEED)
2464 speed = sas->bitrate;
2468 printf("%s%d: %d.%03dMB/s transfers",
2469 periph->periph_name, periph->unit_number,
2472 printf("%s%d: %dKB/s transfers", periph->periph_name,
2473 periph->unit_number, speed);
2474 /* Report additional information about SPI connections */
2475 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2476 struct ccb_trans_settings_spi *spi;
2478 spi = &cts.xport_specific.spi;
2480 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2482 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2486 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2487 && spi->bus_width > 0) {
2493 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2494 } else if (freq != 0) {
2498 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2499 struct ccb_trans_settings_fc *fc;
2501 fc = &cts.xport_specific.fc;
2502 if (fc->valid & CTS_FC_VALID_WWNN)
2503 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2504 if (fc->valid & CTS_FC_VALID_WWPN)
2505 printf(" WWPN 0x%llx", (long long) fc->wwpn);
2506 if (fc->valid & CTS_FC_VALID_PORT)
2507 printf(" PortID 0x%x", fc->port);