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, &val, 0, req);
1469 if (error != 0 || req->newptr == NULL)
1471 if (val == 0 || val == 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) {
1499 scsi_scan_bus_info *scan_info;
1500 union ccb *work_ccb, *reset_ccb;
1501 struct cam_path *path;
1503 u_int low_target, max_target;
1506 /* Find out the characteristics of the bus */
1507 work_ccb = xpt_alloc_ccb_nowait();
1508 if (work_ccb == NULL) {
1509 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1510 xpt_done(request_ccb);
1513 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1514 request_ccb->ccb_h.pinfo.priority);
1515 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1516 xpt_action(work_ccb);
1517 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1518 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1519 xpt_free_ccb(work_ccb);
1520 xpt_done(request_ccb);
1524 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1526 * Can't scan the bus on an adapter that
1527 * cannot perform the initiator role.
1529 request_ccb->ccb_h.status = CAM_REQ_CMP;
1530 xpt_free_ccb(work_ccb);
1531 xpt_done(request_ccb);
1535 /* We may need to reset bus first, if we haven't done it yet. */
1536 if ((work_ccb->cpi.hba_inquiry &
1537 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1538 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1539 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1540 reset_ccb = xpt_alloc_ccb_nowait();
1541 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1543 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1544 xpt_action(reset_ccb);
1545 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1546 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1547 xpt_free_ccb(reset_ccb);
1548 xpt_free_ccb(work_ccb);
1549 xpt_done(request_ccb);
1552 xpt_free_ccb(reset_ccb);
1555 /* Save some state for use while we probe for devices */
1556 scan_info = (scsi_scan_bus_info *)
1557 malloc(sizeof(scsi_scan_bus_info), M_CAMXPT, M_NOWAIT);
1558 if (scan_info == NULL) {
1559 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1560 xpt_done(request_ccb);
1563 scan_info->request_ccb = request_ccb;
1564 scan_info->cpi = &work_ccb->cpi;
1566 /* Cache on our stack so we can work asynchronously */
1567 max_target = scan_info->cpi->max_target;
1569 initiator_id = scan_info->cpi->initiator_id;
1573 * We can scan all targets in parallel, or do it sequentially.
1576 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1577 max_target = low_target = request_ccb->ccb_h.target_id;
1578 scan_info->counter = 0;
1579 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1581 scan_info->counter = 0;
1583 scan_info->counter = scan_info->cpi->max_target + 1;
1584 if (scan_info->cpi->initiator_id < scan_info->counter) {
1585 scan_info->counter--;
1589 for (i = low_target; i <= max_target; i++) {
1591 if (i == initiator_id)
1594 status = xpt_create_path(&path, xpt_periph,
1595 request_ccb->ccb_h.path_id,
1597 if (status != CAM_REQ_CMP) {
1598 printf("scsi_scan_bus: xpt_create_path failed"
1599 " with status %#x, bus scan halted\n",
1601 free(scan_info, M_CAMXPT);
1602 request_ccb->ccb_h.status = status;
1603 xpt_free_ccb(work_ccb);
1604 xpt_done(request_ccb);
1607 work_ccb = xpt_alloc_ccb_nowait();
1608 if (work_ccb == NULL) {
1609 xpt_free_ccb((union ccb *)scan_info->cpi);
1610 free(scan_info, M_CAMXPT);
1611 xpt_free_path(path);
1612 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1613 xpt_done(request_ccb);
1616 xpt_setup_ccb(&work_ccb->ccb_h, path,
1617 request_ccb->ccb_h.pinfo.priority);
1618 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1619 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1620 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1621 work_ccb->crcn.flags = request_ccb->crcn.flags;
1622 xpt_action(work_ccb);
1629 struct cam_path *path;
1630 scsi_scan_bus_info *scan_info;
1632 target_id_t target_id;
1635 /* Reuse the same CCB to query if a device was really found */
1636 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1637 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1638 request_ccb->ccb_h.pinfo.priority);
1639 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1641 path_id = request_ccb->ccb_h.path_id;
1642 target_id = request_ccb->ccb_h.target_id;
1643 lun_id = request_ccb->ccb_h.target_lun;
1644 xpt_action(request_ccb);
1646 if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
1647 struct cam_ed *device;
1648 struct cam_et *target;
1652 * If we already probed lun 0 successfully, or
1653 * we have additional configured luns on this
1654 * target that might have "gone away", go onto
1657 target = request_ccb->ccb_h.path->target;
1659 * We may touch devices that we don't
1660 * hold references too, so ensure they
1661 * don't disappear out from under us.
1662 * The target above is referenced by the
1663 * path in the request ccb.
1666 device = TAILQ_FIRST(&target->ed_entries);
1667 if (device != NULL) {
1668 phl = CAN_SRCH_HI_SPARSE(device);
1669 if (device->lun_id == 0)
1670 device = TAILQ_NEXT(device, links);
1672 if ((lun_id != 0) || (device != NULL)) {
1673 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl)
1677 struct cam_ed *device;
1679 device = request_ccb->ccb_h.path->device;
1681 if ((SCSI_QUIRK(device)->quirks &
1682 CAM_QUIRK_NOLUNS) == 0) {
1683 /* Try the next lun */
1684 if (lun_id < (CAM_SCSI2_MAXLUN-1)
1685 || CAN_SRCH_HI_DENSE(device))
1691 * Free the current request path- we're done with it.
1693 xpt_free_path(request_ccb->ccb_h.path);
1696 * Check to see if we scan any further luns.
1698 if (lun_id == request_ccb->ccb_h.target_lun
1699 || lun_id > scan_info->cpi->max_lun) {
1704 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1706 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1707 scan_info->counter++;
1708 if (scan_info->counter ==
1709 scan_info->cpi->initiator_id) {
1710 scan_info->counter++;
1712 if (scan_info->counter >=
1713 scan_info->cpi->max_target+1) {
1717 scan_info->counter--;
1718 if (scan_info->counter == 0) {
1723 xpt_free_ccb(request_ccb);
1724 xpt_free_ccb((union ccb *)scan_info->cpi);
1725 request_ccb = scan_info->request_ccb;
1726 free(scan_info, M_CAMXPT);
1727 request_ccb->ccb_h.status = CAM_REQ_CMP;
1728 xpt_done(request_ccb);
1732 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
1733 xpt_free_ccb(request_ccb);
1736 status = xpt_create_path(&path, xpt_periph,
1737 scan_info->request_ccb->ccb_h.path_id,
1738 scan_info->counter, 0);
1739 if (status != CAM_REQ_CMP) {
1740 printf("scsi_scan_bus: xpt_create_path failed"
1741 " with status %#x, bus scan halted\n",
1743 xpt_free_ccb(request_ccb);
1744 xpt_free_ccb((union ccb *)scan_info->cpi);
1745 request_ccb = scan_info->request_ccb;
1746 free(scan_info, M_CAMXPT);
1747 request_ccb->ccb_h.status = status;
1748 xpt_done(request_ccb);
1751 xpt_setup_ccb(&request_ccb->ccb_h, path,
1752 request_ccb->ccb_h.pinfo.priority);
1753 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1754 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1755 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1756 request_ccb->crcn.flags =
1757 scan_info->request_ccb->crcn.flags;
1759 status = xpt_create_path(&path, xpt_periph,
1760 path_id, target_id, lun_id);
1761 if (status != CAM_REQ_CMP) {
1762 printf("scsi_scan_bus: xpt_create_path failed "
1763 "with status %#x, halting LUN scan\n",
1767 xpt_setup_ccb(&request_ccb->ccb_h, path,
1768 request_ccb->ccb_h.pinfo.priority);
1769 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1770 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1771 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
1772 request_ccb->crcn.flags =
1773 scan_info->request_ccb->crcn.flags;
1775 xpt_action(request_ccb);
1784 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
1785 cam_flags flags, union ccb *request_ccb)
1787 struct ccb_pathinq cpi;
1789 struct cam_path *new_path;
1790 struct cam_periph *old_periph;
1792 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
1794 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1795 cpi.ccb_h.func_code = XPT_PATH_INQ;
1796 xpt_action((union ccb *)&cpi);
1798 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1799 if (request_ccb != NULL) {
1800 request_ccb->ccb_h.status = cpi.ccb_h.status;
1801 xpt_done(request_ccb);
1806 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1808 * Can't scan the bus on an adapter that
1809 * cannot perform the initiator role.
1811 if (request_ccb != NULL) {
1812 request_ccb->ccb_h.status = CAM_REQ_CMP;
1813 xpt_done(request_ccb);
1818 if (request_ccb == NULL) {
1819 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
1820 if (request_ccb == NULL) {
1821 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
1822 "can't continue\n");
1825 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
1826 if (new_path == NULL) {
1827 xpt_print(path, "scsi_scan_lun: can't allocate path, "
1828 "can't continue\n");
1829 free(request_ccb, M_CAMXPT);
1832 status = xpt_compile_path(new_path, xpt_periph,
1834 path->target->target_id,
1835 path->device->lun_id);
1837 if (status != CAM_REQ_CMP) {
1838 xpt_print(path, "scsi_scan_lun: can't compile path, "
1839 "can't continue\n");
1840 free(request_ccb, M_CAMXPT);
1841 free(new_path, M_CAMXPT);
1844 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1845 request_ccb->ccb_h.cbfcnp = xptscandone;
1846 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1847 request_ccb->crcn.flags = flags;
1850 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
1853 softc = (probe_softc *)old_periph->softc;
1854 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
1857 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1858 probestart, "probe",
1860 request_ccb->ccb_h.path, NULL, 0,
1863 if (status != CAM_REQ_CMP) {
1864 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
1865 "returned an error, can't continue probe\n");
1866 request_ccb->ccb_h.status = status;
1867 xpt_done(request_ccb);
1873 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1875 xpt_release_path(done_ccb->ccb_h.path);
1876 free(done_ccb->ccb_h.path, M_CAMXPT);
1877 free(done_ccb, M_CAMXPT);
1880 static struct cam_ed *
1881 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1883 struct cam_path path;
1884 struct scsi_quirk_entry *quirk;
1885 struct cam_ed *device;
1886 struct cam_ed *cur_device;
1888 device = xpt_alloc_device(bus, target, lun_id);
1893 * Take the default quirk entry until we have inquiry
1894 * data and can determine a better quirk to use.
1896 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
1897 device->quirk = (void *)quirk;
1898 device->mintags = quirk->mintags;
1899 device->maxtags = quirk->maxtags;
1900 bzero(&device->inq_data, sizeof(device->inq_data));
1901 device->inq_flags = 0;
1902 device->queue_flags = 0;
1903 device->serial_num = NULL;
1904 device->serial_num_len = 0;
1907 * XXX should be limited by number of CCBs this bus can
1910 bus->sim->max_ccbs += device->ccbq.devq_openings;
1911 /* Insertion sort into our target's device list */
1912 cur_device = TAILQ_FIRST(&target->ed_entries);
1913 while (cur_device != NULL && cur_device->lun_id < lun_id)
1914 cur_device = TAILQ_NEXT(cur_device, links);
1915 if (cur_device != NULL) {
1916 TAILQ_INSERT_BEFORE(cur_device, device, links);
1918 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
1920 target->generation++;
1921 if (lun_id != CAM_LUN_WILDCARD) {
1922 xpt_compile_path(&path,
1927 scsi_devise_transport(&path);
1928 xpt_release_path(&path);
1935 scsi_devise_transport(struct cam_path *path)
1937 struct ccb_pathinq cpi;
1938 struct ccb_trans_settings cts;
1939 struct scsi_inquiry_data *inq_buf;
1941 /* Get transport information from the SIM */
1942 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1943 cpi.ccb_h.func_code = XPT_PATH_INQ;
1944 xpt_action((union ccb *)&cpi);
1947 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1948 inq_buf = &path->device->inq_data;
1949 path->device->protocol = PROTO_SCSI;
1950 path->device->protocol_version =
1951 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1952 path->device->transport = cpi.transport;
1953 path->device->transport_version = cpi.transport_version;
1956 * Any device not using SPI3 features should
1957 * be considered SPI2 or lower.
1959 if (inq_buf != NULL) {
1960 if (path->device->transport == XPORT_SPI
1961 && (inq_buf->spi3data & SID_SPI_MASK) == 0
1962 && path->device->transport_version > 2)
1963 path->device->transport_version = 2;
1965 struct cam_ed* otherdev;
1967 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
1969 otherdev = TAILQ_NEXT(otherdev, links)) {
1970 if (otherdev != path->device)
1974 if (otherdev != NULL) {
1976 * Initially assume the same versioning as
1977 * prior luns for this target.
1979 path->device->protocol_version =
1980 otherdev->protocol_version;
1981 path->device->transport_version =
1982 otherdev->transport_version;
1984 /* Until we know better, opt for safty */
1985 path->device->protocol_version = 2;
1986 if (path->device->transport == XPORT_SPI)
1987 path->device->transport_version = 2;
1989 path->device->transport_version = 0;
1995 * For a device compliant with SPC-2 we should be able
1996 * to determine the transport version supported by
1997 * scrutinizing the version descriptors in the
2001 /* Tell the controller what we think */
2002 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2003 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2004 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2005 cts.transport = path->device->transport;
2006 cts.transport_version = path->device->transport_version;
2007 cts.protocol = path->device->protocol;
2008 cts.protocol_version = path->device->protocol_version;
2009 cts.proto_specific.valid = 0;
2010 cts.xport_specific.valid = 0;
2011 xpt_action((union ccb *)&cts);
2015 scsi_action(union ccb *start_ccb)
2018 switch (start_ccb->ccb_h.func_code) {
2019 case XPT_SET_TRAN_SETTINGS:
2021 scsi_set_transfer_settings(&start_ccb->cts,
2022 start_ccb->ccb_h.path->device,
2023 /*async_update*/FALSE);
2028 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2031 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2032 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2035 case XPT_GET_TRAN_SETTINGS:
2037 struct cam_sim *sim;
2039 sim = start_ccb->ccb_h.path->bus->sim;
2040 (*(sim->sim_action))(sim, start_ccb);
2044 xpt_action_default(start_ccb);
2050 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2053 struct ccb_pathinq cpi;
2054 struct ccb_trans_settings cur_cts;
2055 struct ccb_trans_settings_scsi *scsi;
2056 struct ccb_trans_settings_scsi *cur_scsi;
2057 struct cam_sim *sim;
2058 struct scsi_inquiry_data *inq_data;
2060 if (device == NULL) {
2061 cts->ccb_h.status = CAM_PATH_INVALID;
2062 xpt_done((union ccb *)cts);
2066 if (cts->protocol == PROTO_UNKNOWN
2067 || cts->protocol == PROTO_UNSPECIFIED) {
2068 cts->protocol = device->protocol;
2069 cts->protocol_version = device->protocol_version;
2072 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2073 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2074 cts->protocol_version = device->protocol_version;
2076 if (cts->protocol != device->protocol) {
2077 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2078 cts->protocol, device->protocol);
2079 cts->protocol = device->protocol;
2082 if (cts->protocol_version > device->protocol_version) {
2084 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2085 "Version from %d to %d?\n", cts->protocol_version,
2086 device->protocol_version);
2088 cts->protocol_version = device->protocol_version;
2091 if (cts->transport == XPORT_UNKNOWN
2092 || cts->transport == XPORT_UNSPECIFIED) {
2093 cts->transport = device->transport;
2094 cts->transport_version = device->transport_version;
2097 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2098 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2099 cts->transport_version = device->transport_version;
2101 if (cts->transport != device->transport) {
2102 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2103 cts->transport, device->transport);
2104 cts->transport = device->transport;
2107 if (cts->transport_version > device->transport_version) {
2109 xpt_print(cts->ccb_h.path, "Down reving Transport "
2110 "Version from %d to %d?\n", cts->transport_version,
2111 device->transport_version);
2113 cts->transport_version = device->transport_version;
2116 sim = cts->ccb_h.path->bus->sim;
2119 * Nothing more of interest to do unless
2120 * this is a device connected via the
2123 if (cts->protocol != PROTO_SCSI) {
2124 if (async_update == FALSE)
2125 (*(sim->sim_action))(sim, (union ccb *)cts);
2129 inq_data = &device->inq_data;
2130 scsi = &cts->proto_specific.scsi;
2131 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2132 cpi.ccb_h.func_code = XPT_PATH_INQ;
2133 xpt_action((union ccb *)&cpi);
2135 /* SCSI specific sanity checking */
2136 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2137 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2138 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2139 || (device->mintags == 0)) {
2141 * Can't tag on hardware that doesn't support tags,
2142 * doesn't have it enabled, or has broken tag support.
2144 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2147 if (async_update == FALSE) {
2149 * Perform sanity checking against what the
2150 * controller and device can do.
2152 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2153 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2154 cur_cts.type = cts->type;
2155 xpt_action((union ccb *)&cur_cts);
2156 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2159 cur_scsi = &cur_cts.proto_specific.scsi;
2160 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2161 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2162 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2164 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2165 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2168 /* SPI specific sanity checking */
2169 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2171 struct ccb_trans_settings_spi *spi;
2172 struct ccb_trans_settings_spi *cur_spi;
2174 spi = &cts->xport_specific.spi;
2176 cur_spi = &cur_cts.xport_specific.spi;
2178 /* Fill in any gaps in what the user gave us */
2179 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2180 spi->sync_period = cur_spi->sync_period;
2181 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2182 spi->sync_period = 0;
2183 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2184 spi->sync_offset = cur_spi->sync_offset;
2185 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2186 spi->sync_offset = 0;
2187 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2188 spi->ppr_options = cur_spi->ppr_options;
2189 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2190 spi->ppr_options = 0;
2191 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2192 spi->bus_width = cur_spi->bus_width;
2193 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2195 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2196 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2197 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2199 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2200 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2201 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2202 && (inq_data->flags & SID_Sync) == 0
2203 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2204 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2206 spi->sync_period = 0;
2207 spi->sync_offset = 0;
2210 switch (spi->bus_width) {
2211 case MSG_EXT_WDTR_BUS_32_BIT:
2212 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2213 || (inq_data->flags & SID_WBus32) != 0
2214 || cts->type == CTS_TYPE_USER_SETTINGS)
2215 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2217 /* Fall Through to 16-bit */
2218 case MSG_EXT_WDTR_BUS_16_BIT:
2219 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2220 || (inq_data->flags & SID_WBus16) != 0
2221 || cts->type == CTS_TYPE_USER_SETTINGS)
2222 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2223 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2226 /* Fall Through to 8-bit */
2227 default: /* New bus width?? */
2228 case MSG_EXT_WDTR_BUS_8_BIT:
2229 /* All targets can do this */
2230 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2234 spi3caps = cpi.xport_specific.spi.ppr_options;
2235 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2236 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2237 spi3caps &= inq_data->spi3data;
2239 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2240 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2242 if ((spi3caps & SID_SPI_IUS) == 0)
2243 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2245 if ((spi3caps & SID_SPI_QAS) == 0)
2246 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2248 /* No SPI Transfer settings are allowed unless we are wide */
2249 if (spi->bus_width == 0)
2250 spi->ppr_options = 0;
2252 if ((spi->valid & CTS_SPI_VALID_DISC)
2253 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2255 * Can't tag queue without disconnection.
2257 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2258 scsi->valid |= CTS_SCSI_VALID_TQ;
2262 * If we are currently performing tagged transactions to
2263 * this device and want to change its negotiation parameters,
2264 * go non-tagged for a bit to give the controller a chance to
2265 * negotiate unhampered by tag messages.
2267 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2268 && (device->inq_flags & SID_CmdQue) != 0
2269 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2270 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2271 CTS_SPI_VALID_SYNC_OFFSET|
2272 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2273 scsi_toggle_tags(cts->ccb_h.path);
2276 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2277 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2281 * If we are transitioning from tags to no-tags or
2282 * vice-versa, we need to carefully freeze and restart
2283 * the queue so that we don't overlap tagged and non-tagged
2284 * commands. We also temporarily stop tags if there is
2285 * a change in transfer negotiation settings to allow
2286 * "tag-less" negotiation.
2288 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2289 || (device->inq_flags & SID_CmdQue) != 0)
2290 device_tagenb = TRUE;
2292 device_tagenb = FALSE;
2294 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2295 && device_tagenb == FALSE)
2296 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2297 && device_tagenb == TRUE)) {
2299 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2301 * Delay change to use tags until after a
2302 * few commands have gone to this device so
2303 * the controller has time to perform transfer
2304 * negotiations without tagged messages getting
2307 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2308 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2310 xpt_stop_tags(cts->ccb_h.path);
2314 if (async_update == FALSE)
2315 (*(sim->sim_action))(sim, (union ccb *)cts);
2319 scsi_toggle_tags(struct cam_path *path)
2324 * Give controllers a chance to renegotiate
2325 * before starting tag operations. We
2326 * "toggle" tagged queuing off then on
2327 * which causes the tag enable command delay
2328 * counter to come into effect.
2331 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2332 || ((dev->inq_flags & SID_CmdQue) != 0
2333 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2334 struct ccb_trans_settings cts;
2336 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2337 cts.protocol = PROTO_SCSI;
2338 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2339 cts.transport = XPORT_UNSPECIFIED;
2340 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2341 cts.proto_specific.scsi.flags = 0;
2342 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2343 scsi_set_transfer_settings(&cts, path->device,
2344 /*async_update*/TRUE);
2345 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2346 scsi_set_transfer_settings(&cts, path->device,
2347 /*async_update*/TRUE);
2352 * Handle any per-device event notifications that require action by the XPT.
2355 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2356 struct cam_ed *device, void *async_arg)
2359 struct cam_path newpath;
2362 * We only need to handle events for real devices.
2364 if (target->target_id == CAM_TARGET_WILDCARD
2365 || device->lun_id == CAM_LUN_WILDCARD)
2369 * We need our own path with wildcards expanded to
2370 * handle certain types of events.
2372 if ((async_code == AC_SENT_BDR)
2373 || (async_code == AC_BUS_RESET)
2374 || (async_code == AC_INQ_CHANGED))
2375 status = xpt_compile_path(&newpath, NULL,
2380 status = CAM_REQ_CMP_ERR;
2382 if (status == CAM_REQ_CMP) {
2385 * Allow transfer negotiation to occur in a
2386 * tag free environment and after settle delay.
2388 if (async_code == AC_SENT_BDR
2389 || async_code == AC_BUS_RESET) {
2390 cam_freeze_devq(&newpath);
2391 cam_release_devq(&newpath,
2392 RELSIM_RELEASE_AFTER_TIMEOUT,
2394 /*timeout*/scsi_delay,
2395 /*getcount_only*/0);
2396 scsi_toggle_tags(&newpath);
2399 if (async_code == AC_INQ_CHANGED) {
2401 * We've sent a start unit command, or
2402 * something similar to a device that
2403 * may have caused its inquiry data to
2404 * change. So we re-scan the device to
2405 * refresh the inquiry data for it.
2407 scsi_scan_lun(newpath.periph, &newpath,
2408 CAM_EXPECT_INQ_CHANGE, NULL);
2410 xpt_release_path(&newpath);
2411 } else if (async_code == AC_LOST_DEVICE &&
2412 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2413 device->flags |= CAM_DEV_UNCONFIGURED;
2414 xpt_release_device(device);
2415 } else if (async_code == AC_TRANSFER_NEG) {
2416 struct ccb_trans_settings *settings;
2418 settings = (struct ccb_trans_settings *)async_arg;
2419 scsi_set_transfer_settings(settings, device,
2420 /*async_update*/TRUE);
2425 scsi_announce_periph(struct cam_periph *periph)
2427 struct ccb_pathinq cpi;
2428 struct ccb_trans_settings cts;
2429 struct cam_path *path = periph->path;
2434 mtx_assert(periph->sim->mtx, MA_OWNED);
2436 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2437 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2438 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2439 xpt_action((union ccb*)&cts);
2440 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2442 /* Ask the SIM for its base transfer speed */
2443 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2444 cpi.ccb_h.func_code = XPT_PATH_INQ;
2445 xpt_action((union ccb *)&cpi);
2446 /* Report connection speed */
2447 speed = cpi.base_transfer_speed;
2449 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2450 struct ccb_trans_settings_spi *spi =
2451 &cts.xport_specific.spi;
2453 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2454 && spi->sync_offset != 0) {
2455 freq = scsi_calc_syncsrate(spi->sync_period);
2458 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2459 speed *= (0x01 << spi->bus_width);
2461 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2462 struct ccb_trans_settings_fc *fc =
2463 &cts.xport_specific.fc;
2465 if (fc->valid & CTS_FC_VALID_SPEED)
2466 speed = fc->bitrate;
2468 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2469 struct ccb_trans_settings_sas *sas =
2470 &cts.xport_specific.sas;
2472 if (sas->valid & CTS_SAS_VALID_SPEED)
2473 speed = sas->bitrate;
2477 printf("%s%d: %d.%03dMB/s transfers",
2478 periph->periph_name, periph->unit_number,
2481 printf("%s%d: %dKB/s transfers", periph->periph_name,
2482 periph->unit_number, speed);
2483 /* Report additional information about SPI connections */
2484 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2485 struct ccb_trans_settings_spi *spi;
2487 spi = &cts.xport_specific.spi;
2489 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2491 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2495 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2496 && spi->bus_width > 0) {
2502 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2503 } else if (freq != 0) {
2507 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2508 struct ccb_trans_settings_fc *fc;
2510 fc = &cts.xport_specific.fc;
2511 if (fc->valid & CTS_FC_VALID_WWNN)
2512 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2513 if (fc->valid & CTS_FC_VALID_WWPN)
2514 printf(" WWPN 0x%llx", (long long) fc->wwpn);
2515 if (fc->valid & CTS_FC_VALID_PORT)
2516 printf(" PortID 0x%x", fc->port);