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_NOVPDS 0x02
72 #define CAM_QUIRK_HILUNS 0x04
73 #define CAM_QUIRK_NOHILUNS 0x08
74 #define CAM_QUIRK_NORPTLUNS 0x10
78 #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk))
80 static int cam_srch_hi = 0;
81 TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi);
82 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
83 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
84 sysctl_cam_search_luns, "I",
85 "allow search above LUN 7 for SCSI3 and greater devices");
87 #define CAM_SCSI2_MAXLUN 8
88 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \
89 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
90 RPL_LUNDATA_ATYP_PERIPH) || \
91 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
92 RPL_LUNDATA_ATYP_FLAT))
93 #define CAM_GET_SIMPLE_LUN(lp, i, lval) \
94 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
95 RPL_LUNDATA_ATYP_PERIPH) { \
96 (lval) = (lp)->luns[(i)].lundata[1]; \
98 (lval) = (lp)->luns[(i)].lundata[0]; \
99 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \
101 (lval) |= (lp)->luns[(i)].lundata[1]; \
104 * If we're not quirked to search <= the first 8 luns
105 * and we are either quirked to search above lun 8,
106 * or we're > SCSI-2 and we've enabled hilun searching,
107 * or we're > SCSI-2 and the last lun was a success,
108 * we can look for luns above lun 8.
110 #define CAN_SRCH_HI_SPARSE(dv) \
111 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
112 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
113 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
115 #define CAN_SRCH_HI_DENSE(dv) \
116 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
117 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
118 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
120 static periph_init_t probe_periph_init;
122 static struct periph_driver probe_driver =
124 probe_periph_init, "probe",
125 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
129 PERIPHDRIVER_DECLARE(probe, probe_driver);
133 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
137 PROBE_SUPPORTED_VPD_LIST,
140 PROBE_TUR_FOR_NEGOTIATION,
141 PROBE_INQUIRY_BASIC_DV1,
142 PROBE_INQUIRY_BASIC_DV2,
148 static char *probe_action_text[] = {
151 "PROBE_FULL_INQUIRY",
154 "PROBE_SUPPORTED_VPD_LIST",
157 "PROBE_TUR_FOR_NEGOTIATION",
158 "PROBE_INQUIRY_BASIC_DV1",
159 "PROBE_INQUIRY_BASIC_DV2",
165 #define PROBE_SET_ACTION(softc, newaction) \
168 text = probe_action_text; \
169 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
170 ("Probe %s to %s\n", text[(softc)->action], \
171 text[(newaction)])); \
172 (softc)->action = (newaction); \
176 PROBE_INQUIRY_CKSUM = 0x01,
177 PROBE_SERIAL_CKSUM = 0x02,
178 PROBE_NO_ANNOUNCE = 0x04
182 TAILQ_HEAD(, ccb_hdr) request_ccbs;
188 struct cam_periph *periph;
191 static const char quantum[] = "QUANTUM";
192 static const char sony[] = "SONY";
193 static const char west_digital[] = "WDIGTL";
194 static const char samsung[] = "SAMSUNG";
195 static const char seagate[] = "SEAGATE";
196 static const char microp[] = "MICROP";
198 static struct scsi_quirk_entry scsi_quirk_table[] =
201 /* Reports QUEUE FULL for temporary resource shortages */
202 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
203 /*quirks*/0, /*mintags*/24, /*maxtags*/32
206 /* Reports QUEUE FULL for temporary resource shortages */
207 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
208 /*quirks*/0, /*mintags*/24, /*maxtags*/32
211 /* Reports QUEUE FULL for temporary resource shortages */
212 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
213 /*quirks*/0, /*mintags*/24, /*maxtags*/32
216 /* Broken tagged queuing drive */
217 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
218 /*quirks*/0, /*mintags*/0, /*maxtags*/0
221 /* Broken tagged queuing drive */
222 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
223 /*quirks*/0, /*mintags*/0, /*maxtags*/0
226 /* Broken tagged queuing drive */
227 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
228 /*quirks*/0, /*mintags*/0, /*maxtags*/0
232 * Unfortunately, the Quantum Atlas III has the same
233 * problem as the Atlas II drives above.
234 * Reported by: "Johan Granlund" <johan@granlund.nu>
236 * For future reference, the drive with the problem was:
237 * QUANTUM QM39100TD-SW N1B0
239 * It's possible that Quantum will fix the problem in later
240 * firmware revisions. If that happens, the quirk entry
241 * will need to be made specific to the firmware revisions
245 /* Reports QUEUE FULL for temporary resource shortages */
246 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
247 /*quirks*/0, /*mintags*/24, /*maxtags*/32
251 * 18 Gig Atlas III, same problem as the 9G version.
252 * Reported by: Andre Albsmeier
253 * <andre.albsmeier@mchp.siemens.de>
255 * For future reference, the drive with the problem was:
256 * QUANTUM QM318000TD-S N491
258 /* Reports QUEUE FULL for temporary resource shortages */
259 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
260 /*quirks*/0, /*mintags*/24, /*maxtags*/32
264 * Broken tagged queuing drive
265 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
266 * and: Martin Renters <martin@tdc.on.ca>
268 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
269 /*quirks*/0, /*mintags*/0, /*maxtags*/0
272 * The Seagate Medalist Pro drives have very poor write
273 * performance with anything more than 2 tags.
275 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
276 * Drive: <SEAGATE ST36530N 1444>
278 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
279 * Drive: <SEAGATE ST34520W 1281>
281 * No one has actually reported that the 9G version
282 * (ST39140*) of the Medalist Pro has the same problem, but
283 * we're assuming that it does because the 4G and 6.5G
284 * versions of the drive are broken.
287 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
288 /*quirks*/0, /*mintags*/2, /*maxtags*/2
291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
292 /*quirks*/0, /*mintags*/2, /*maxtags*/2
295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
296 /*quirks*/0, /*mintags*/2, /*maxtags*/2
300 * Experiences command timeouts under load with a
301 * tag count higher than 55.
303 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
304 /*quirks*/0, /*mintags*/2, /*maxtags*/55
308 * Slow when tagged queueing is enabled. Write performance
309 * steadily drops off with more and more concurrent
310 * transactions. Best sequential write performance with
311 * tagged queueing turned off and write caching turned on.
314 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
315 * Drive: DCAS-34330 w/ "S65A" firmware.
317 * The drive with the problem had the "S65A" firmware
318 * revision, and has also been reported (by Stephen J.
319 * Roznowski <sjr@home.net>) for a drive with the "S61A"
322 * Although no one has reported problems with the 2 gig
323 * version of the DCAS drive, the assumption is that it
324 * has the same problems as the 4 gig version. Therefore
325 * this quirk entries disables tagged queueing for all
328 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
329 /*quirks*/0, /*mintags*/0, /*maxtags*/0
332 /* Broken tagged queuing drive */
333 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
334 /*quirks*/0, /*mintags*/0, /*maxtags*/0
337 /* Broken tagged queuing drive */
338 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
339 /*quirks*/0, /*mintags*/0, /*maxtags*/0
342 /* This does not support other than LUN 0 */
343 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
344 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
348 * Broken tagged queuing drive.
350 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
353 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
354 /*quirks*/0, /*mintags*/0, /*maxtags*/0
358 * Slow when tagged queueing is enabled. (1.5MB/sec versus
360 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
361 * Best performance with these drives is achieved with
362 * tagged queueing turned off, and write caching turned on.
364 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
365 /*quirks*/0, /*mintags*/0, /*maxtags*/0
369 * Slow when tagged queueing is enabled. (1.5MB/sec versus
371 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
372 * Best performance with these drives is achieved with
373 * tagged queueing turned off, and write caching turned on.
375 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
376 /*quirks*/0, /*mintags*/0, /*maxtags*/0
380 * Doesn't handle queue full condition correctly,
381 * so we need to limit maxtags to what the device
382 * can handle instead of determining this automatically.
384 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
385 /*quirks*/0, /*mintags*/2, /*maxtags*/32
388 /* Really only one LUN */
389 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
390 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
393 /* I can't believe we need a quirk for DPT volumes. */
394 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
396 /*mintags*/0, /*maxtags*/255
400 * Many Sony CDROM drives don't like multi-LUN probing.
402 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
403 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
407 * This drive doesn't like multiple LUN probing.
408 * Submitted by: Parag Patel <parag@cgt.com>
410 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
411 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
414 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
415 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
419 * The 8200 doesn't like multi-lun probing, and probably
420 * don't like serial number requests either.
423 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
426 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
430 * Let's try the same as above, but for a drive that says
431 * it's an IPL-6860 but is actually an EXB 8200.
434 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
437 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
441 * These Hitachi drives don't like multi-lun probing.
442 * The PR submitter has a DK319H, but says that the Linux
443 * kernel has a similar work-around for the DK312 and DK314,
444 * so all DK31* drives are quirked here.
446 * Submitted by: Paul Haddad <paul@pth.com>
448 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
449 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
453 * The Hitachi CJ series with J8A8 firmware apparantly has
454 * problems with tagged commands.
456 * Reported by: amagai@nue.org
458 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
459 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
463 * These are the large storage arrays.
464 * Submitted by: William Carrel <william.carrel@infospace.com>
466 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
467 CAM_QUIRK_HILUNS, 2, 1024
471 * This old revision of the TDC3600 is also SCSI-1, and
472 * hangs upon serial number probing.
475 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
478 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
482 * Would repond to all LUNs if asked for.
485 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
488 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
492 * Would repond to all LUNs if asked for.
495 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
501 /* Submitted by: Matthew Dodd <winter@jurai.net> */
502 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
503 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
506 /* Submitted by: Matthew Dodd <winter@jurai.net> */
507 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
508 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
511 /* TeraSolutions special settings for TRC-22 RAID */
512 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
513 /*quirks*/0, /*mintags*/55, /*maxtags*/255
516 /* Veritas Storage Appliance */
517 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
518 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
522 * Would respond to all LUNs. Device type and removable
523 * flag are jumper-selectable.
525 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
528 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
531 /* EasyRAID E5A aka. areca ARC-6010 */
532 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
533 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
536 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
537 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
540 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
541 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
544 /* Default tagged queuing parameters for all devices */
546 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
547 /*vendor*/"*", /*product*/"*", /*revision*/"*"
549 /*quirks*/0, /*mintags*/2, /*maxtags*/255
553 static const int scsi_quirk_table_size =
554 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
556 static cam_status proberegister(struct cam_periph *periph,
558 static void probeschedule(struct cam_periph *probe_periph);
559 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
560 static void proberequestdefaultnegotiation(struct cam_periph *periph);
561 static int proberequestbackoff(struct cam_periph *periph,
562 struct cam_ed *device);
563 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
564 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
566 static void probe_purge_old(struct cam_path *path,
567 struct scsi_report_luns_data *new);
568 static void probecleanup(struct cam_periph *periph);
569 static void scsi_find_quirk(struct cam_ed *device);
570 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
571 static void scsi_scan_lun(struct cam_periph *periph,
572 struct cam_path *path, cam_flags flags,
574 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
575 static struct cam_ed *
576 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
578 static void scsi_devise_transport(struct cam_path *path);
579 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
580 struct cam_ed *device,
582 static void scsi_toggle_tags(struct cam_path *path);
583 static void scsi_dev_async(u_int32_t async_code,
585 struct cam_et *target,
586 struct cam_ed *device,
588 static void scsi_action(union ccb *start_ccb);
589 static void scsi_announce_periph(struct cam_periph *periph);
591 static struct xpt_xport scsi_xport = {
592 .alloc_device = scsi_alloc_device,
593 .action = scsi_action,
594 .async = scsi_dev_async,
595 .announce = scsi_announce_periph,
601 return (&scsi_xport);
610 proberegister(struct cam_periph *periph, void *arg)
612 union ccb *request_ccb; /* CCB representing the probe request */
616 request_ccb = (union ccb *)arg;
617 if (request_ccb == NULL) {
618 printf("proberegister: no probe CCB, "
619 "can't register device\n");
620 return(CAM_REQ_CMP_ERR);
623 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
626 printf("proberegister: Unable to probe new device. "
627 "Unable to allocate softc\n");
628 return(CAM_REQ_CMP_ERR);
630 TAILQ_INIT(&softc->request_ccbs);
631 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
634 periph->softc = softc;
635 softc->periph = periph;
636 softc->action = PROBE_INVALID;
637 status = cam_periph_acquire(periph);
638 if (status != CAM_REQ_CMP) {
641 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
644 * Ensure we've waited at least a bus settle
645 * delay before attempting to probe the device.
646 * For HBAs that don't do bus resets, this won't make a difference.
648 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
650 probeschedule(periph);
655 probeschedule(struct cam_periph *periph)
657 struct ccb_pathinq cpi;
661 softc = (probe_softc *)periph->softc;
662 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
664 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
665 cpi.ccb_h.func_code = XPT_PATH_INQ;
666 xpt_action((union ccb *)&cpi);
669 * If a device has gone away and another device, or the same one,
670 * is back in the same place, it should have a unit attention
671 * condition pending. It will not report the unit attention in
672 * response to an inquiry, which may leave invalid transfer
673 * negotiations in effect. The TUR will reveal the unit attention
674 * condition. Only send the TUR for lun 0, since some devices
675 * will get confused by commands other than inquiry to non-existent
676 * luns. If you think a device has gone away start your scan from
677 * lun 0. This will insure that any bogus transfer settings are
680 * If we haven't seen the device before and the controller supports
681 * some kind of transfer negotiation, negotiate with the first
682 * sent command if no bus reset was performed at startup. This
683 * ensures that the device is not confused by transfer negotiation
684 * settings left over by loader or BIOS action.
686 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
687 && (ccb->ccb_h.target_lun == 0)) {
688 PROBE_SET_ACTION(softc, PROBE_TUR);
689 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
690 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
691 proberequestdefaultnegotiation(periph);
692 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
694 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
697 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
698 softc->flags |= PROBE_NO_ANNOUNCE;
700 softc->flags &= ~PROBE_NO_ANNOUNCE;
702 xpt_schedule(periph, CAM_PRIORITY_XPT);
706 probestart(struct cam_periph *periph, union ccb *start_ccb)
708 /* Probe the device that our peripheral driver points to */
709 struct ccb_scsiio *csio;
712 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
714 softc = (probe_softc *)periph->softc;
715 csio = &start_ccb->csio;
718 switch (softc->action) {
720 case PROBE_TUR_FOR_NEGOTIATION:
723 scsi_test_unit_ready(csio,
732 case PROBE_FULL_INQUIRY:
733 case PROBE_INQUIRY_BASIC_DV1:
734 case PROBE_INQUIRY_BASIC_DV2:
737 struct scsi_inquiry_data *inq_buf;
739 inq_buf = &periph->path->device->inq_data;
742 * If the device is currently configured, we calculate an
743 * MD5 checksum of the inquiry data, and if the serial number
744 * length is greater than 0, add the serial number data
745 * into the checksum as well. Once the inquiry and the
746 * serial number check finish, we attempt to figure out
747 * whether we still have the same device.
749 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
751 MD5Init(&softc->context);
752 MD5Update(&softc->context, (unsigned char *)inq_buf,
753 sizeof(struct scsi_inquiry_data));
754 softc->flags |= PROBE_INQUIRY_CKSUM;
755 if (periph->path->device->serial_num_len > 0) {
756 MD5Update(&softc->context,
757 periph->path->device->serial_num,
758 periph->path->device->serial_num_len);
759 softc->flags |= PROBE_SERIAL_CKSUM;
761 MD5Final(softc->digest, &softc->context);
764 if (softc->action == PROBE_INQUIRY)
765 inquiry_len = SHORT_INQUIRY_LENGTH;
767 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
770 * Some parallel SCSI devices fail to send an
771 * ignore wide residue message when dealing with
772 * odd length inquiry requests. Round up to be
775 inquiry_len = roundup2(inquiry_len, 2);
777 if (softc->action == PROBE_INQUIRY_BASIC_DV1
778 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
779 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
781 if (inq_buf == NULL) {
782 xpt_print(periph->path, "malloc failure- skipping Basic"
783 "Domain Validation\n");
784 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
785 scsi_test_unit_ready(csio,
802 /*timeout*/60 * 1000);
805 case PROBE_REPORT_LUNS:
809 rp = malloc(periph->path->target->rpl_size,
810 M_CAMXPT, M_NOWAIT | M_ZERO);
812 struct scsi_inquiry_data *inq_buf;
813 inq_buf = &periph->path->device->inq_data;
814 xpt_print(periph->path,
815 "Unable to alloc report luns storage\n");
816 if (INQ_DATA_TQ_ENABLED(inq_buf))
817 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
819 PROBE_SET_ACTION(softc,
820 PROBE_SUPPORTED_VPD_LIST);
823 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
824 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
825 SSD_FULL_SIZE, 60000); break;
828 case PROBE_MODE_SENSE:
833 mode_buf_len = sizeof(struct scsi_mode_header_6)
834 + sizeof(struct scsi_mode_blk_desc)
835 + sizeof(struct scsi_control_page);
836 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
837 if (mode_buf != NULL) {
838 scsi_mode_sense(csio,
843 SMS_PAGE_CTRL_CURRENT,
844 SMS_CONTROL_MODE_PAGE,
851 xpt_print(periph->path, "Unable to mode sense control page - "
853 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
856 case PROBE_SUPPORTED_VPD_LIST:
858 struct scsi_vpd_supported_page_list *vpd_list;
859 struct cam_ed *device;
862 device = periph->path->device;
864 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
865 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
868 if (vpd_list != NULL) {
873 (u_int8_t *)vpd_list,
876 SVPD_SUPPORTED_PAGE_LIST,
878 /*timeout*/60 * 1000);
882 * We'll have to do without, let our probedone
883 * routine finish up for us.
885 start_ccb->csio.data_ptr = NULL;
886 cam_freeze_devq(periph->path);
887 probedone(periph, start_ccb);
890 case PROBE_DEVICE_ID:
892 struct scsi_vpd_device_id *devid;
895 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
896 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
905 SVPD_DEVICE_ID_MAX_SIZE,
909 /*timeout*/60 * 1000);
913 * We'll have to do without, let our probedone
914 * routine finish up for us.
916 start_ccb->csio.data_ptr = NULL;
917 cam_freeze_devq(periph->path);
918 probedone(periph, start_ccb);
921 case PROBE_SERIAL_NUM:
923 struct scsi_vpd_unit_serial_number *serial_buf;
924 struct cam_ed* device;
927 device = periph->path->device;
928 if (device->serial_num != NULL) {
929 free(device->serial_num, M_CAMXPT);
930 device->serial_num = NULL;
931 device->serial_num_len = 0;
934 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
935 serial_buf = (struct scsi_vpd_unit_serial_number *)
936 malloc(sizeof(*serial_buf), M_CAMXPT,
939 if (serial_buf != NULL) {
944 (u_int8_t *)serial_buf,
947 SVPD_UNIT_SERIAL_NUMBER,
949 /*timeout*/60 * 1000);
953 * We'll have to do without, let our probedone
954 * routine finish up for us.
956 start_ccb->csio.data_ptr = NULL;
957 cam_freeze_devq(periph->path);
958 probedone(periph, start_ccb);
962 panic("probestart: invalid action state 0x%x\n", softc->action);
964 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
965 xpt_action(start_ccb);
969 proberequestdefaultnegotiation(struct cam_periph *periph)
971 struct ccb_trans_settings cts;
973 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
974 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
975 cts.type = CTS_TYPE_USER_SETTINGS;
976 xpt_action((union ccb *)&cts);
977 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
980 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
981 cts.type = CTS_TYPE_CURRENT_SETTINGS;
982 xpt_action((union ccb *)&cts);
986 * Backoff Negotiation Code- only pertinent for SPI devices.
989 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
991 struct ccb_trans_settings cts;
992 struct ccb_trans_settings_spi *spi;
994 memset(&cts, 0, sizeof (cts));
995 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
996 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
997 cts.type = CTS_TYPE_CURRENT_SETTINGS;
998 xpt_action((union ccb *)&cts);
999 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1001 xpt_print(periph->path,
1002 "failed to get current device settings\n");
1006 if (cts.transport != XPORT_SPI) {
1008 xpt_print(periph->path, "not SPI transport\n");
1012 spi = &cts.xport_specific.spi;
1015 * We cannot renegotiate sync rate if we don't have one.
1017 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1019 xpt_print(periph->path, "no sync rate known\n");
1025 * We'll assert that we don't have to touch PPR options- the
1026 * SIM will see what we do with period and offset and adjust
1027 * the PPR options as appropriate.
1031 * A sync rate with unknown or zero offset is nonsensical.
1032 * A sync period of zero means Async.
1034 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1035 || spi->sync_offset == 0 || spi->sync_period == 0) {
1037 xpt_print(periph->path, "no sync rate available\n");
1042 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1043 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1044 ("hit async: giving up on DV\n"));
1050 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1051 * We don't try to remember 'last' settings to see if the SIM actually
1052 * gets into the speed we want to set. We check on the SIM telling
1053 * us that a requested speed is bad, but otherwise don't try and
1054 * check the speed due to the asynchronous and handshake nature
1057 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1060 if (spi->sync_period >= 0xf) {
1061 spi->sync_period = 0;
1062 spi->sync_offset = 0;
1063 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1064 ("setting to async for DV\n"));
1066 * Once we hit async, we don't want to try
1067 * any more settings.
1069 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1070 } else if (bootverbose) {
1071 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1072 ("DV: period 0x%x\n", spi->sync_period));
1073 printf("setting period to 0x%x\n", spi->sync_period);
1075 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1076 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1077 xpt_action((union ccb *)&cts);
1078 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1081 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1082 ("DV: failed to set period 0x%x\n", spi->sync_period));
1083 if (spi->sync_period == 0) {
1090 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1093 probedone(struct cam_periph *periph, union ccb *done_ccb)
1096 struct cam_path *path;
1099 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1101 softc = (probe_softc *)periph->softc;
1102 path = done_ccb->ccb_h.path;
1103 priority = done_ccb->ccb_h.pinfo.priority;
1105 switch (softc->action) {
1108 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1110 if (cam_periph_error(done_ccb, 0,
1111 SF_NO_PRINT, NULL) == ERESTART) {
1113 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1114 cam_release_devq(path, 0, 0, 0, FALSE);
1117 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1118 /* Don't wedge the queue */
1119 xpt_release_devq(done_ccb->ccb_h.path,
1123 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1124 xpt_release_ccb(done_ccb);
1125 xpt_schedule(periph, priority);
1129 case PROBE_FULL_INQUIRY:
1131 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1132 struct scsi_inquiry_data *inq_buf;
1133 u_int8_t periph_qual;
1135 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1136 inq_buf = &path->device->inq_data;
1138 periph_qual = SID_QUAL(inq_buf);
1140 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1144 * We conservatively request only
1145 * SHORT_INQUIRY_LEN bytes of inquiry
1146 * information during our first try
1147 * at sending an INQUIRY. If the device
1148 * has more information to give,
1149 * perform a second request specifying
1150 * the amount of information the device
1151 * is willing to give.
1153 len = inq_buf->additional_length
1154 + offsetof(struct scsi_inquiry_data,
1155 additional_length) + 1;
1156 if (softc->action == PROBE_INQUIRY
1157 && len > SHORT_INQUIRY_LENGTH) {
1158 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1159 xpt_release_ccb(done_ccb);
1160 xpt_schedule(periph, priority);
1164 scsi_find_quirk(path->device);
1166 scsi_devise_transport(path);
1168 if (path->device->lun_id == 0 &&
1169 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1170 (SCSI_QUIRK(path->device)->quirks &
1171 CAM_QUIRK_NORPTLUNS) == 0) {
1172 PROBE_SET_ACTION(softc,
1175 * Start with room for *one* lun.
1177 periph->path->target->rpl_size = 16;
1178 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1179 PROBE_SET_ACTION(softc,
1182 PROBE_SET_ACTION(softc,
1183 PROBE_SUPPORTED_VPD_LIST);
1185 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1186 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1187 xpt_acquire_device(path->device);
1189 xpt_release_ccb(done_ccb);
1190 xpt_schedule(periph, priority);
1192 } else if (path->device->lun_id == 0 &&
1193 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1194 (SCSI_QUIRK(path->device)->quirks &
1195 CAM_QUIRK_NORPTLUNS) == 0) {
1196 if (path->device->flags &
1197 CAM_DEV_UNCONFIGURED) {
1198 path->device->flags &=
1199 ~CAM_DEV_UNCONFIGURED;
1200 xpt_acquire_device(path->device);
1202 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1203 periph->path->target->rpl_size = 16;
1204 xpt_release_ccb(done_ccb);
1205 xpt_schedule(periph, priority);
1208 } else if (cam_periph_error(done_ccb, 0,
1209 done_ccb->ccb_h.target_lun > 0
1210 ? SF_RETRY_UA|SF_QUIET_IR
1212 &softc->saved_ccb) == ERESTART) {
1214 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1215 /* Don't wedge the queue */
1216 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1220 * If we get to this point, we got an error status back
1221 * from the inquiry and the error status doesn't require
1222 * automatically retrying the command. Therefore, the
1223 * inquiry failed. If we had inquiry information before
1224 * for this device, but this latest inquiry command failed,
1225 * the device has probably gone away. If this device isn't
1226 * already marked unconfigured, notify the peripheral
1227 * drivers that this device is no more.
1229 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1230 /* Send the async notification. */
1231 xpt_async(AC_LOST_DEVICE, path, NULL);
1232 PROBE_SET_ACTION(softc, PROBE_INVALID);
1234 xpt_release_ccb(done_ccb);
1237 case PROBE_REPORT_LUNS:
1239 struct ccb_scsiio *csio;
1240 struct scsi_report_luns_data *lp;
1243 csio = &done_ccb->csio;
1245 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1246 nlun = scsi_4btoul(lp->length) / 8;
1247 maxlun = (csio->dxfer_len / 8) - 1;
1249 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1250 if (cam_periph_error(done_ccb, 0,
1251 done_ccb->ccb_h.target_lun > 0 ?
1252 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1253 &softc->saved_ccb) == ERESTART) {
1256 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1257 xpt_release_devq(done_ccb->ccb_h.path, 1,
1262 } else if (nlun > maxlun) {
1264 * Reallocate and retry to cover all luns
1266 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1267 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1270 path->target->rpl_size = (nlun << 3) + 8;
1271 xpt_release_ccb(done_ccb);
1272 xpt_schedule(periph, priority);
1274 } else if (nlun == 0) {
1276 * If there don't appear to be any luns, bail.
1280 } else if (probe_strange_rpl_data(lp, maxlun)) {
1282 * If we can't understand the lun format
1283 * of any entry, bail.
1291 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1292 ("Probe: %u lun(s) reported\n", nlun));
1294 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1296 * If the first lun is not lun 0, then either there
1297 * is no lun 0 in the list, or the list is unsorted.
1300 for (idx = 0; idx < nlun; idx++) {
1301 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1309 lp->luns[0].lundata, 8);
1310 memcpy(lp->luns[0].lundata,
1311 lp->luns[idx].lundata, 8);
1312 memcpy(lp->luns[idx].lundata,
1314 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1315 ("lun 0 in position %u\n", idx));
1318 * There is no lun 0 in our list. Destroy
1319 * the validity of the inquiry data so we
1320 * bail here and now.
1322 path->device->flags &=
1323 ~CAM_DEV_INQUIRY_DATA_VALID;
1327 * If we have an old lun list, We can either
1328 * retest luns that appear to have been dropped,
1329 * or just nuke them. We'll opt for the latter.
1330 * This function will also install the new list
1331 * in the target structure.
1333 probe_purge_old(path, lp);
1336 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1337 struct scsi_inquiry_data *inq_buf;
1338 inq_buf = &path->device->inq_data;
1339 if (INQ_DATA_TQ_ENABLED(inq_buf))
1340 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1342 PROBE_SET_ACTION(softc,
1343 PROBE_SUPPORTED_VPD_LIST);
1344 xpt_release_ccb(done_ccb);
1345 xpt_schedule(periph, priority);
1353 case PROBE_MODE_SENSE:
1355 struct ccb_scsiio *csio;
1356 struct scsi_mode_header_6 *mode_hdr;
1358 csio = &done_ccb->csio;
1359 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1360 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1361 struct scsi_control_page *page;
1364 offset = ((u_int8_t *)&mode_hdr[1])
1365 + mode_hdr->blk_desc_len;
1366 page = (struct scsi_control_page *)offset;
1367 path->device->queue_flags = page->queue_flags;
1368 } else if (cam_periph_error(done_ccb, 0,
1369 SF_RETRY_UA|SF_NO_PRINT,
1370 &softc->saved_ccb) == ERESTART) {
1372 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1373 /* Don't wedge the queue */
1374 xpt_release_devq(done_ccb->ccb_h.path,
1375 /*count*/1, /*run_queue*/TRUE);
1377 xpt_release_ccb(done_ccb);
1378 free(mode_hdr, M_CAMXPT);
1379 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1380 xpt_schedule(periph, priority);
1383 case PROBE_SUPPORTED_VPD_LIST:
1385 struct ccb_scsiio *csio;
1386 struct scsi_vpd_supported_page_list *page_list;
1388 csio = &done_ccb->csio;
1390 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1392 if (path->device->supported_vpds != NULL) {
1393 free(path->device->supported_vpds, M_CAMXPT);
1394 path->device->supported_vpds = NULL;
1395 path->device->supported_vpds_len = 0;
1398 if (page_list == NULL) {
1400 * Don't process the command as it was never sent
1402 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1404 path->device->supported_vpds_len = page_list->length +
1405 SVPD_SUPPORTED_PAGES_HDR_LEN;
1406 path->device->supported_vpds = (uint8_t *)page_list;
1407 xpt_release_ccb(done_ccb);
1408 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1409 xpt_schedule(periph, priority);
1411 } else if (cam_periph_error(done_ccb, 0,
1412 SF_RETRY_UA|SF_NO_PRINT,
1413 &softc->saved_ccb) == ERESTART) {
1415 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1416 /* Don't wedge the queue */
1417 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1422 free(page_list, M_CAMXPT);
1423 /* No VPDs available, skip to device check. */
1424 csio->data_ptr = NULL;
1425 goto probe_device_check;
1427 case PROBE_DEVICE_ID:
1429 struct scsi_vpd_device_id *devid;
1430 struct ccb_scsiio *csio;
1431 uint32_t length = 0;
1433 csio = &done_ccb->csio;
1434 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1436 /* Clean up from previous instance of this device */
1437 if (path->device->device_id != NULL) {
1438 path->device->device_id_len = 0;
1439 free(path->device->device_id, M_CAMXPT);
1440 path->device->device_id = NULL;
1443 if (devid == NULL) {
1444 /* Don't process the command as it was never sent */
1445 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1446 length = scsi_2btoul(devid->length);
1449 * NB: device_id_len is actual response
1450 * size, not buffer size.
1452 path->device->device_id_len = length +
1453 SVPD_DEVICE_ID_HDR_LEN;
1454 path->device->device_id = (uint8_t *)devid;
1456 } else if (cam_periph_error(done_ccb, 0,
1458 &softc->saved_ccb) == ERESTART) {
1460 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1461 /* Don't wedge the queue */
1462 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1466 /* Free the device id space if we don't use it */
1467 if (devid && length == 0)
1468 free(devid, M_CAMXPT);
1469 xpt_release_ccb(done_ccb);
1470 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1471 xpt_schedule(periph, priority);
1476 case PROBE_SERIAL_NUM:
1478 struct ccb_scsiio *csio;
1479 struct scsi_vpd_unit_serial_number *serial_buf;
1486 csio = &done_ccb->csio;
1487 priority = done_ccb->ccb_h.pinfo.priority;
1489 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1491 if (serial_buf == NULL) {
1493 * Don't process the command as it was never sent
1495 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1496 && (serial_buf->length > 0)) {
1499 path->device->serial_num =
1500 (u_int8_t *)malloc((serial_buf->length + 1),
1501 M_CAMXPT, M_NOWAIT);
1502 if (path->device->serial_num != NULL) {
1503 memcpy(path->device->serial_num,
1504 serial_buf->serial_num,
1505 serial_buf->length);
1506 path->device->serial_num_len =
1508 path->device->serial_num[serial_buf->length]
1511 } else if (cam_periph_error(done_ccb, 0,
1512 SF_RETRY_UA|SF_NO_PRINT,
1513 &softc->saved_ccb) == ERESTART) {
1515 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1516 /* Don't wedge the queue */
1517 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1522 * Let's see if we have seen this device before.
1524 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1526 u_int8_t digest[16];
1531 (unsigned char *)&path->device->inq_data,
1532 sizeof(struct scsi_inquiry_data));
1535 MD5Update(&context, serial_buf->serial_num,
1536 serial_buf->length);
1538 MD5Final(digest, &context);
1539 if (bcmp(softc->digest, digest, 16) == 0)
1543 * XXX Do we need to do a TUR in order to ensure
1544 * that the device really hasn't changed???
1547 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1548 xpt_async(AC_LOST_DEVICE, path, NULL);
1550 if (serial_buf != NULL)
1551 free(serial_buf, M_CAMXPT);
1555 * Now that we have all the necessary
1556 * information to safely perform transfer
1557 * negotiations... Controllers don't perform
1558 * any negotiation or tagged queuing until
1559 * after the first XPT_SET_TRAN_SETTINGS ccb is
1560 * received. So, on a new device, just retrieve
1561 * the user settings, and set them as the current
1562 * settings to set the device up.
1564 proberequestdefaultnegotiation(periph);
1565 xpt_release_ccb(done_ccb);
1568 * Perform a TUR to allow the controller to
1569 * perform any necessary transfer negotiation.
1571 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1572 xpt_schedule(periph, priority);
1575 xpt_release_ccb(done_ccb);
1578 case PROBE_TUR_FOR_NEGOTIATION:
1580 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1581 cam_periph_error(done_ccb, 0,
1582 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1584 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1585 /* Don't wedge the queue */
1586 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1590 * Do Domain Validation for lun 0 on devices that claim
1591 * to support Synchronous Transfer modes.
1593 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1594 && done_ccb->ccb_h.target_lun == 0
1595 && (path->device->inq_data.flags & SID_Sync) != 0
1596 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1597 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1598 ("Begin Domain Validation\n"));
1599 path->device->flags |= CAM_DEV_IN_DV;
1600 xpt_release_ccb(done_ccb);
1601 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1602 xpt_schedule(periph, priority);
1605 if (softc->action == PROBE_DV_EXIT) {
1606 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1607 ("Leave Domain Validation\n"));
1609 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1610 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1611 xpt_acquire_device(path->device);
1613 path->device->flags &=
1614 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1615 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1616 /* Inform the XPT that a new device has been found */
1617 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1618 xpt_action(done_ccb);
1619 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1622 PROBE_SET_ACTION(softc, PROBE_DONE);
1623 xpt_release_ccb(done_ccb);
1625 case PROBE_INQUIRY_BASIC_DV1:
1626 case PROBE_INQUIRY_BASIC_DV2:
1628 struct scsi_inquiry_data *nbuf;
1629 struct ccb_scsiio *csio;
1631 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1632 cam_periph_error(done_ccb, 0,
1633 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1635 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1636 /* Don't wedge the queue */
1637 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1640 csio = &done_ccb->csio;
1641 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1642 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1644 "inquiry data fails comparison at DV%d step\n",
1645 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1646 if (proberequestbackoff(periph, path->device)) {
1647 path->device->flags &= ~CAM_DEV_IN_DV;
1648 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1651 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1653 free(nbuf, M_CAMXPT);
1654 xpt_release_ccb(done_ccb);
1655 xpt_schedule(periph, priority);
1658 free(nbuf, M_CAMXPT);
1659 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1660 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1661 xpt_release_ccb(done_ccb);
1662 xpt_schedule(periph, priority);
1665 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1666 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1667 ("Leave Domain Validation Successfully\n"));
1669 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1670 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1671 xpt_acquire_device(path->device);
1673 path->device->flags &=
1674 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1675 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1676 /* Inform the XPT that a new device has been found */
1677 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1678 xpt_action(done_ccb);
1679 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1682 PROBE_SET_ACTION(softc, PROBE_DONE);
1683 xpt_release_ccb(done_ccb);
1687 panic("probedone: invalid action state 0x%x\n", softc->action);
1689 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1690 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1691 done_ccb->ccb_h.status = CAM_REQ_CMP;
1693 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1694 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1695 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1696 cam_release_devq(path, 0, 0, 0, FALSE);
1697 cam_periph_invalidate(periph);
1698 cam_periph_release_locked(periph);
1700 probeschedule(periph);
1706 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1709 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1711 for (idx = 0; idx < nlun; idx++) {
1712 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1720 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1722 struct cam_path *tp;
1723 struct scsi_report_luns_data *old;
1724 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1727 if (path->target == NULL) {
1730 if (path->target->luns == NULL) {
1731 path->target->luns = new;
1734 old = path->target->luns;
1735 nlun_old = scsi_4btoul(old->length) / 8;
1736 nlun_new = scsi_4btoul(new->length) / 8;
1739 * We are not going to assume sorted lists. Deal.
1741 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1742 ol = old->luns[idx1].lundata;
1743 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1744 nl = new->luns[idx2].lundata;
1745 if (memcmp(nl, ol, 8) == 0) {
1749 if (idx2 < nlun_new) {
1753 * An 'old' item not in the 'new' list.
1754 * Nuke it. Except that if it is lun 0,
1755 * that would be what the probe state
1756 * machine is currently working on,
1757 * so we won't do that.
1759 * We also cannot nuke it if it is
1760 * not in a lun format we understand.
1762 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1765 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1766 if (this_lun == 0) {
1769 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1770 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1771 xpt_async(AC_LOST_DEVICE, tp, NULL);
1775 free(old, M_CAMXPT);
1776 path->target->luns = new;
1780 probecleanup(struct cam_periph *periph)
1782 free(periph->softc, M_CAMXPT);
1786 scsi_find_quirk(struct cam_ed *device)
1788 struct scsi_quirk_entry *quirk;
1791 match = cam_quirkmatch((caddr_t)&device->inq_data,
1792 (caddr_t)scsi_quirk_table,
1793 sizeof(scsi_quirk_table) /
1794 sizeof(*scsi_quirk_table),
1795 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1798 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1800 quirk = (struct scsi_quirk_entry *)match;
1801 device->quirk = quirk;
1802 device->mintags = quirk->mintags;
1803 device->maxtags = quirk->maxtags;
1807 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1812 error = sysctl_handle_int(oidp, &val, 0, req);
1813 if (error != 0 || req->newptr == NULL)
1815 if (val == 0 || val == 1) {
1824 union ccb *request_ccb;
1825 struct ccb_pathinq *cpi;
1828 } scsi_scan_bus_info;
1831 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1832 * As the scan progresses, scsi_scan_bus is used as the
1833 * callback on completion function.
1836 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1838 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1839 ("scsi_scan_bus\n"));
1840 switch (request_ccb->ccb_h.func_code) {
1844 scsi_scan_bus_info *scan_info;
1845 union ccb *work_ccb, *reset_ccb;
1846 struct cam_path *path;
1848 u_int low_target, max_target;
1851 /* Find out the characteristics of the bus */
1852 work_ccb = xpt_alloc_ccb_nowait();
1853 if (work_ccb == NULL) {
1854 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1855 xpt_done(request_ccb);
1858 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1859 request_ccb->ccb_h.pinfo.priority);
1860 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1861 xpt_action(work_ccb);
1862 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1863 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1864 xpt_free_ccb(work_ccb);
1865 xpt_done(request_ccb);
1869 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1871 * Can't scan the bus on an adapter that
1872 * cannot perform the initiator role.
1874 request_ccb->ccb_h.status = CAM_REQ_CMP;
1875 xpt_free_ccb(work_ccb);
1876 xpt_done(request_ccb);
1880 /* We may need to reset bus first, if we haven't done it yet. */
1881 if ((work_ccb->cpi.hba_inquiry &
1882 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1883 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1884 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1885 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1886 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1888 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1889 xpt_action(reset_ccb);
1890 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1891 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1892 xpt_free_ccb(reset_ccb);
1893 xpt_free_ccb(work_ccb);
1894 xpt_done(request_ccb);
1897 xpt_free_ccb(reset_ccb);
1900 /* Save some state for use while we probe for devices */
1901 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1902 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1903 if (scan_info == NULL) {
1904 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1905 xpt_done(request_ccb);
1908 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1909 ("SCAN start for %p\n", scan_info));
1910 scan_info->request_ccb = request_ccb;
1911 scan_info->cpi = &work_ccb->cpi;
1913 /* Cache on our stack so we can work asynchronously */
1914 max_target = scan_info->cpi->max_target;
1916 initiator_id = scan_info->cpi->initiator_id;
1920 * We can scan all targets in parallel, or do it sequentially.
1923 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1924 max_target = low_target = request_ccb->ccb_h.target_id;
1925 scan_info->counter = 0;
1926 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1928 scan_info->counter = 0;
1930 scan_info->counter = scan_info->cpi->max_target + 1;
1931 if (scan_info->cpi->initiator_id < scan_info->counter) {
1932 scan_info->counter--;
1936 for (i = low_target; i <= max_target; i++) {
1938 if (i == initiator_id)
1941 status = xpt_create_path(&path, NULL,
1942 request_ccb->ccb_h.path_id,
1944 if (status != CAM_REQ_CMP) {
1945 printf("scsi_scan_bus: xpt_create_path failed"
1946 " with status %#x, bus scan halted\n",
1948 free(scan_info, M_CAMXPT);
1949 request_ccb->ccb_h.status = status;
1950 xpt_free_ccb(work_ccb);
1951 xpt_done(request_ccb);
1954 work_ccb = xpt_alloc_ccb_nowait();
1955 if (work_ccb == NULL) {
1956 xpt_free_ccb((union ccb *)scan_info->cpi);
1957 free(scan_info, M_CAMXPT);
1958 xpt_free_path(path);
1959 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1960 xpt_done(request_ccb);
1963 xpt_setup_ccb(&work_ccb->ccb_h, path,
1964 request_ccb->ccb_h.pinfo.priority);
1965 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1966 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1967 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1968 work_ccb->crcn.flags = request_ccb->crcn.flags;
1969 xpt_action(work_ccb);
1976 struct cam_path *path, *oldpath;
1977 scsi_scan_bus_info *scan_info;
1978 struct cam_et *target;
1979 struct cam_ed *device;
1982 target_id_t target_id;
1985 oldpath = request_ccb->ccb_h.path;
1987 status = cam_ccb_status(request_ccb);
1988 /* Reuse the same CCB to query if a device was really found */
1989 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1990 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1991 request_ccb->ccb_h.pinfo.priority);
1992 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1995 path_id = request_ccb->ccb_h.path_id;
1996 target_id = request_ccb->ccb_h.target_id;
1997 lun_id = request_ccb->ccb_h.target_lun;
1998 xpt_action(request_ccb);
2000 target = request_ccb->ccb_h.path->target;
2005 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2008 * Make sure we skip over lun 0 if it's the first member
2009 * of the list as we've actually just finished probing
2012 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
2013 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2014 scan_info->lunindex[target_id]++;
2017 if (scan_info->lunindex[target_id] < nluns) {
2018 CAM_GET_SIMPLE_LUN(target->luns,
2019 scan_info->lunindex[target_id], lun_id);
2021 CAM_DEBUG(request_ccb->ccb_h.path,
2023 ("next lun to try at index %u is %u\n",
2024 scan_info->lunindex[target_id], lun_id));
2025 scan_info->lunindex[target_id]++;
2028 * We're done with scanning all luns.
2030 * Nuke the bogus device for lun 0 if lun 0
2031 * wasn't on the list.
2034 TAILQ_FOREACH(device,
2035 &target->ed_entries, links) {
2036 if (device->lun_id == 0) {
2041 xpt_release_device(device);
2045 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2049 * If we already probed lun 0 successfully, or
2050 * we have additional configured luns on this
2051 * target that might have "gone away", go onto
2055 * We may touch devices that we don't
2056 * hold references too, so ensure they
2057 * don't disappear out from under us.
2058 * The target above is referenced by the
2059 * path in the request ccb.
2062 device = TAILQ_FIRST(&target->ed_entries);
2063 if (device != NULL) {
2064 phl = CAN_SRCH_HI_SPARSE(device);
2065 if (device->lun_id == 0)
2066 device = TAILQ_NEXT(device, links);
2068 if ((lun_id != 0) || (device != NULL)) {
2069 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2074 if (lun_id == request_ccb->ccb_h.target_lun
2075 || lun_id > scan_info->cpi->max_lun)
2079 device = request_ccb->ccb_h.path->device;
2081 if ((SCSI_QUIRK(device)->quirks &
2082 CAM_QUIRK_NOLUNS) == 0) {
2083 /* Try the next lun */
2084 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2085 || CAN_SRCH_HI_DENSE(device)) {
2090 if (lun_id == request_ccb->ccb_h.target_lun
2091 || lun_id > scan_info->cpi->max_lun)
2096 * Check to see if we scan any further luns.
2102 * Free the current request path- we're done with it.
2104 xpt_free_path(oldpath);
2107 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2109 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2110 scan_info->counter++;
2111 if (scan_info->counter ==
2112 scan_info->cpi->initiator_id) {
2113 scan_info->counter++;
2115 if (scan_info->counter >=
2116 scan_info->cpi->max_target+1) {
2120 scan_info->counter--;
2121 if (scan_info->counter == 0) {
2126 xpt_free_ccb(request_ccb);
2127 xpt_free_ccb((union ccb *)scan_info->cpi);
2128 request_ccb = scan_info->request_ccb;
2129 CAM_DEBUG(request_ccb->ccb_h.path,
2131 ("SCAN done for %p\n", scan_info));
2132 free(scan_info, M_CAMXPT);
2133 request_ccb->ccb_h.status = CAM_REQ_CMP;
2134 xpt_done(request_ccb);
2138 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2139 xpt_free_ccb(request_ccb);
2142 status = xpt_create_path(&path, NULL,
2143 scan_info->request_ccb->ccb_h.path_id,
2144 scan_info->counter, 0);
2145 if (status != CAM_REQ_CMP) {
2146 printf("scsi_scan_bus: xpt_create_path failed"
2147 " with status %#x, bus scan halted\n",
2149 xpt_free_ccb(request_ccb);
2150 xpt_free_ccb((union ccb *)scan_info->cpi);
2151 request_ccb = scan_info->request_ccb;
2152 free(scan_info, M_CAMXPT);
2153 request_ccb->ccb_h.status = status;
2154 xpt_done(request_ccb);
2157 xpt_setup_ccb(&request_ccb->ccb_h, path,
2158 request_ccb->ccb_h.pinfo.priority);
2159 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2160 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2161 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2162 request_ccb->crcn.flags =
2163 scan_info->request_ccb->crcn.flags;
2165 status = xpt_create_path(&path, NULL,
2166 path_id, target_id, lun_id);
2168 * Free the old request path- we're done with it. We
2169 * do this *after* creating the new path so that
2170 * we don't remove a target that has our lun list
2171 * in the case that lun 0 is not present.
2173 xpt_free_path(oldpath);
2174 if (status != CAM_REQ_CMP) {
2175 printf("scsi_scan_bus: xpt_create_path failed "
2176 "with status %#x, halting LUN scan\n",
2180 xpt_setup_ccb(&request_ccb->ccb_h, path,
2181 request_ccb->ccb_h.pinfo.priority);
2182 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2183 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2184 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2185 request_ccb->crcn.flags =
2186 scan_info->request_ccb->crcn.flags;
2188 xpt_action(request_ccb);
2197 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2198 cam_flags flags, union ccb *request_ccb)
2200 struct ccb_pathinq cpi;
2202 struct cam_path *new_path;
2203 struct cam_periph *old_periph;
2205 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2207 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2208 cpi.ccb_h.func_code = XPT_PATH_INQ;
2209 xpt_action((union ccb *)&cpi);
2211 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2212 if (request_ccb != NULL) {
2213 request_ccb->ccb_h.status = cpi.ccb_h.status;
2214 xpt_done(request_ccb);
2219 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2221 * Can't scan the bus on an adapter that
2222 * cannot perform the initiator role.
2224 if (request_ccb != NULL) {
2225 request_ccb->ccb_h.status = CAM_REQ_CMP;
2226 xpt_done(request_ccb);
2231 if (request_ccb == NULL) {
2232 request_ccb = xpt_alloc_ccb_nowait();
2233 if (request_ccb == NULL) {
2234 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2235 "can't continue\n");
2238 status = xpt_create_path(&new_path, NULL,
2240 path->target->target_id,
2241 path->device->lun_id);
2242 if (status != CAM_REQ_CMP) {
2243 xpt_print(path, "scsi_scan_lun: can't create path, "
2244 "can't continue\n");
2245 xpt_free_ccb(request_ccb);
2248 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2249 request_ccb->ccb_h.cbfcnp = xptscandone;
2250 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2251 request_ccb->crcn.flags = flags;
2254 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2255 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2258 softc = (probe_softc *)old_periph->softc;
2259 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2260 &request_ccb->ccb_h, periph_links.tqe);
2262 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2263 xpt_done(request_ccb);
2266 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2267 probestart, "probe",
2269 request_ccb->ccb_h.path, NULL, 0,
2272 if (status != CAM_REQ_CMP) {
2273 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2274 "returned an error, can't continue probe\n");
2275 request_ccb->ccb_h.status = status;
2276 xpt_done(request_ccb);
2282 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2285 xpt_free_path(done_ccb->ccb_h.path);
2286 xpt_free_ccb(done_ccb);
2289 static struct cam_ed *
2290 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2292 struct cam_path path;
2293 struct scsi_quirk_entry *quirk;
2294 struct cam_ed *device;
2296 device = xpt_alloc_device(bus, target, lun_id);
2301 * Take the default quirk entry until we have inquiry
2302 * data and can determine a better quirk to use.
2304 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2305 device->quirk = (void *)quirk;
2306 device->mintags = quirk->mintags;
2307 device->maxtags = quirk->maxtags;
2308 bzero(&device->inq_data, sizeof(device->inq_data));
2309 device->inq_flags = 0;
2310 device->queue_flags = 0;
2311 device->serial_num = NULL;
2312 device->serial_num_len = 0;
2313 device->device_id = NULL;
2314 device->device_id_len = 0;
2315 device->supported_vpds = NULL;
2316 device->supported_vpds_len = 0;
2319 * XXX should be limited by number of CCBs this bus can
2322 bus->sim->max_ccbs += device->ccbq.devq_openings;
2323 if (lun_id != CAM_LUN_WILDCARD) {
2324 xpt_compile_path(&path,
2329 scsi_devise_transport(&path);
2330 xpt_release_path(&path);
2337 scsi_devise_transport(struct cam_path *path)
2339 struct ccb_pathinq cpi;
2340 struct ccb_trans_settings cts;
2341 struct scsi_inquiry_data *inq_buf;
2343 /* Get transport information from the SIM */
2344 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2345 cpi.ccb_h.func_code = XPT_PATH_INQ;
2346 xpt_action((union ccb *)&cpi);
2349 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2350 inq_buf = &path->device->inq_data;
2351 path->device->protocol = PROTO_SCSI;
2352 path->device->protocol_version =
2353 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2354 path->device->transport = cpi.transport;
2355 path->device->transport_version = cpi.transport_version;
2358 * Any device not using SPI3 features should
2359 * be considered SPI2 or lower.
2361 if (inq_buf != NULL) {
2362 if (path->device->transport == XPORT_SPI
2363 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2364 && path->device->transport_version > 2)
2365 path->device->transport_version = 2;
2367 struct cam_ed* otherdev;
2369 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2371 otherdev = TAILQ_NEXT(otherdev, links)) {
2372 if (otherdev != path->device)
2376 if (otherdev != NULL) {
2378 * Initially assume the same versioning as
2379 * prior luns for this target.
2381 path->device->protocol_version =
2382 otherdev->protocol_version;
2383 path->device->transport_version =
2384 otherdev->transport_version;
2386 /* Until we know better, opt for safty */
2387 path->device->protocol_version = 2;
2388 if (path->device->transport == XPORT_SPI)
2389 path->device->transport_version = 2;
2391 path->device->transport_version = 0;
2397 * For a device compliant with SPC-2 we should be able
2398 * to determine the transport version supported by
2399 * scrutinizing the version descriptors in the
2403 /* Tell the controller what we think */
2404 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2405 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2406 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2407 cts.transport = path->device->transport;
2408 cts.transport_version = path->device->transport_version;
2409 cts.protocol = path->device->protocol;
2410 cts.protocol_version = path->device->protocol_version;
2411 cts.proto_specific.valid = 0;
2412 cts.xport_specific.valid = 0;
2413 xpt_action((union ccb *)&cts);
2417 scsi_dev_advinfo(union ccb *start_ccb)
2419 struct cam_ed *device;
2420 struct ccb_dev_advinfo *cdai;
2423 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2424 device = start_ccb->ccb_h.path->device;
2425 cdai = &start_ccb->cdai;
2426 switch(cdai->buftype) {
2427 case CDAI_TYPE_SCSI_DEVID:
2428 if (cdai->flags & CDAI_FLAG_STORE)
2430 cdai->provsiz = device->device_id_len;
2431 if (device->device_id_len == 0)
2433 amt = device->device_id_len;
2434 if (cdai->provsiz > cdai->bufsiz)
2436 memcpy(cdai->buf, device->device_id, amt);
2438 case CDAI_TYPE_SERIAL_NUM:
2439 if (cdai->flags & CDAI_FLAG_STORE)
2441 cdai->provsiz = device->serial_num_len;
2442 if (device->serial_num_len == 0)
2444 amt = device->serial_num_len;
2445 if (cdai->provsiz > cdai->bufsiz)
2447 memcpy(cdai->buf, device->serial_num, amt);
2449 case CDAI_TYPE_PHYS_PATH:
2450 if (cdai->flags & CDAI_FLAG_STORE) {
2451 if (device->physpath != NULL) {
2452 free(device->physpath, M_CAMXPT);
2453 device->physpath = NULL;
2455 device->physpath_len = cdai->bufsiz;
2456 /* Clear existing buffer if zero length */
2457 if (cdai->bufsiz == 0)
2459 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2460 if (device->physpath == NULL) {
2461 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2464 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2466 cdai->provsiz = device->physpath_len;
2467 if (device->physpath_len == 0)
2469 amt = device->physpath_len;
2470 if (cdai->provsiz > cdai->bufsiz)
2472 memcpy(cdai->buf, device->physpath, amt);
2475 case CDAI_TYPE_RCAPLONG:
2476 if (cdai->flags & CDAI_FLAG_STORE) {
2477 if (device->rcap_buf != NULL) {
2478 free(device->rcap_buf, M_CAMXPT);
2479 device->rcap_buf = NULL;
2482 device->rcap_len = cdai->bufsiz;
2483 /* Clear existing buffer if zero length */
2484 if (cdai->bufsiz == 0)
2487 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2489 if (device->rcap_buf == NULL) {
2490 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2494 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2496 cdai->provsiz = device->rcap_len;
2497 if (device->rcap_len == 0)
2499 amt = device->rcap_len;
2500 if (cdai->provsiz > cdai->bufsiz)
2502 memcpy(cdai->buf, device->rcap_buf, amt);
2508 start_ccb->ccb_h.status = CAM_REQ_CMP;
2510 if (cdai->flags & CDAI_FLAG_STORE) {
2513 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
2515 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
2516 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2517 (void *)(uintptr_t)cdai->buftype);
2519 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
2524 scsi_action(union ccb *start_ccb)
2527 switch (start_ccb->ccb_h.func_code) {
2528 case XPT_SET_TRAN_SETTINGS:
2530 scsi_set_transfer_settings(&start_ccb->cts,
2531 start_ccb->ccb_h.path->device,
2532 /*async_update*/FALSE);
2537 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2540 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2541 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2544 case XPT_GET_TRAN_SETTINGS:
2546 struct cam_sim *sim;
2548 sim = start_ccb->ccb_h.path->bus->sim;
2549 (*(sim->sim_action))(sim, start_ccb);
2552 case XPT_DEV_ADVINFO:
2554 scsi_dev_advinfo(start_ccb);
2558 xpt_action_default(start_ccb);
2564 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2567 struct ccb_pathinq cpi;
2568 struct ccb_trans_settings cur_cts;
2569 struct ccb_trans_settings_scsi *scsi;
2570 struct ccb_trans_settings_scsi *cur_scsi;
2571 struct cam_sim *sim;
2572 struct scsi_inquiry_data *inq_data;
2574 if (device == NULL) {
2575 cts->ccb_h.status = CAM_PATH_INVALID;
2576 xpt_done((union ccb *)cts);
2580 if (cts->protocol == PROTO_UNKNOWN
2581 || cts->protocol == PROTO_UNSPECIFIED) {
2582 cts->protocol = device->protocol;
2583 cts->protocol_version = device->protocol_version;
2586 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2587 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2588 cts->protocol_version = device->protocol_version;
2590 if (cts->protocol != device->protocol) {
2591 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2592 cts->protocol, device->protocol);
2593 cts->protocol = device->protocol;
2596 if (cts->protocol_version > device->protocol_version) {
2598 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2599 "Version from %d to %d?\n", cts->protocol_version,
2600 device->protocol_version);
2602 cts->protocol_version = device->protocol_version;
2605 if (cts->transport == XPORT_UNKNOWN
2606 || cts->transport == XPORT_UNSPECIFIED) {
2607 cts->transport = device->transport;
2608 cts->transport_version = device->transport_version;
2611 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2612 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2613 cts->transport_version = device->transport_version;
2615 if (cts->transport != device->transport) {
2616 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2617 cts->transport, device->transport);
2618 cts->transport = device->transport;
2621 if (cts->transport_version > device->transport_version) {
2623 xpt_print(cts->ccb_h.path, "Down reving Transport "
2624 "Version from %d to %d?\n", cts->transport_version,
2625 device->transport_version);
2627 cts->transport_version = device->transport_version;
2630 sim = cts->ccb_h.path->bus->sim;
2633 * Nothing more of interest to do unless
2634 * this is a device connected via the
2637 if (cts->protocol != PROTO_SCSI) {
2638 if (async_update == FALSE)
2639 (*(sim->sim_action))(sim, (union ccb *)cts);
2643 inq_data = &device->inq_data;
2644 scsi = &cts->proto_specific.scsi;
2645 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2646 cpi.ccb_h.func_code = XPT_PATH_INQ;
2647 xpt_action((union ccb *)&cpi);
2649 /* SCSI specific sanity checking */
2650 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2651 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2652 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2653 || (device->mintags == 0)) {
2655 * Can't tag on hardware that doesn't support tags,
2656 * doesn't have it enabled, or has broken tag support.
2658 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2661 if (async_update == FALSE) {
2663 * Perform sanity checking against what the
2664 * controller and device can do.
2666 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2667 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2668 cur_cts.type = cts->type;
2669 xpt_action((union ccb *)&cur_cts);
2670 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2673 cur_scsi = &cur_cts.proto_specific.scsi;
2674 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2675 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2676 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2678 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2679 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2682 /* SPI specific sanity checking */
2683 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2685 struct ccb_trans_settings_spi *spi;
2686 struct ccb_trans_settings_spi *cur_spi;
2688 spi = &cts->xport_specific.spi;
2690 cur_spi = &cur_cts.xport_specific.spi;
2692 /* Fill in any gaps in what the user gave us */
2693 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2694 spi->sync_period = cur_spi->sync_period;
2695 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2696 spi->sync_period = 0;
2697 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2698 spi->sync_offset = cur_spi->sync_offset;
2699 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2700 spi->sync_offset = 0;
2701 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2702 spi->ppr_options = cur_spi->ppr_options;
2703 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2704 spi->ppr_options = 0;
2705 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2706 spi->bus_width = cur_spi->bus_width;
2707 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2709 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2710 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2711 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2713 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2714 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2715 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2716 && (inq_data->flags & SID_Sync) == 0
2717 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2718 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2720 spi->sync_period = 0;
2721 spi->sync_offset = 0;
2724 switch (spi->bus_width) {
2725 case MSG_EXT_WDTR_BUS_32_BIT:
2726 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2727 || (inq_data->flags & SID_WBus32) != 0
2728 || cts->type == CTS_TYPE_USER_SETTINGS)
2729 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2731 /* Fall Through to 16-bit */
2732 case MSG_EXT_WDTR_BUS_16_BIT:
2733 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2734 || (inq_data->flags & SID_WBus16) != 0
2735 || cts->type == CTS_TYPE_USER_SETTINGS)
2736 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2737 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2740 /* Fall Through to 8-bit */
2741 default: /* New bus width?? */
2742 case MSG_EXT_WDTR_BUS_8_BIT:
2743 /* All targets can do this */
2744 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2748 spi3caps = cpi.xport_specific.spi.ppr_options;
2749 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2750 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2751 spi3caps &= inq_data->spi3data;
2753 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2754 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2756 if ((spi3caps & SID_SPI_IUS) == 0)
2757 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2759 if ((spi3caps & SID_SPI_QAS) == 0)
2760 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2762 /* No SPI Transfer settings are allowed unless we are wide */
2763 if (spi->bus_width == 0)
2764 spi->ppr_options = 0;
2766 if ((spi->valid & CTS_SPI_VALID_DISC)
2767 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2769 * Can't tag queue without disconnection.
2771 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2772 scsi->valid |= CTS_SCSI_VALID_TQ;
2776 * If we are currently performing tagged transactions to
2777 * this device and want to change its negotiation parameters,
2778 * go non-tagged for a bit to give the controller a chance to
2779 * negotiate unhampered by tag messages.
2781 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2782 && (device->inq_flags & SID_CmdQue) != 0
2783 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2784 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2785 CTS_SPI_VALID_SYNC_OFFSET|
2786 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2787 scsi_toggle_tags(cts->ccb_h.path);
2790 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2791 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2795 * If we are transitioning from tags to no-tags or
2796 * vice-versa, we need to carefully freeze and restart
2797 * the queue so that we don't overlap tagged and non-tagged
2798 * commands. We also temporarily stop tags if there is
2799 * a change in transfer negotiation settings to allow
2800 * "tag-less" negotiation.
2802 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2803 || (device->inq_flags & SID_CmdQue) != 0)
2804 device_tagenb = TRUE;
2806 device_tagenb = FALSE;
2808 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2809 && device_tagenb == FALSE)
2810 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2811 && device_tagenb == TRUE)) {
2813 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2815 * Delay change to use tags until after a
2816 * few commands have gone to this device so
2817 * the controller has time to perform transfer
2818 * negotiations without tagged messages getting
2821 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2822 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2824 xpt_stop_tags(cts->ccb_h.path);
2828 if (async_update == FALSE)
2829 (*(sim->sim_action))(sim, (union ccb *)cts);
2833 scsi_toggle_tags(struct cam_path *path)
2838 * Give controllers a chance to renegotiate
2839 * before starting tag operations. We
2840 * "toggle" tagged queuing off then on
2841 * which causes the tag enable command delay
2842 * counter to come into effect.
2845 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2846 || ((dev->inq_flags & SID_CmdQue) != 0
2847 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2848 struct ccb_trans_settings cts;
2850 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2851 cts.protocol = PROTO_SCSI;
2852 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2853 cts.transport = XPORT_UNSPECIFIED;
2854 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2855 cts.proto_specific.scsi.flags = 0;
2856 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2857 scsi_set_transfer_settings(&cts, path->device,
2858 /*async_update*/TRUE);
2859 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2860 scsi_set_transfer_settings(&cts, path->device,
2861 /*async_update*/TRUE);
2866 * Handle any per-device event notifications that require action by the XPT.
2869 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2870 struct cam_ed *device, void *async_arg)
2873 struct cam_path newpath;
2876 * We only need to handle events for real devices.
2878 if (target->target_id == CAM_TARGET_WILDCARD
2879 || device->lun_id == CAM_LUN_WILDCARD)
2883 * We need our own path with wildcards expanded to
2884 * handle certain types of events.
2886 if ((async_code == AC_SENT_BDR)
2887 || (async_code == AC_BUS_RESET)
2888 || (async_code == AC_INQ_CHANGED))
2889 status = xpt_compile_path(&newpath, NULL,
2894 status = CAM_REQ_CMP_ERR;
2896 if (status == CAM_REQ_CMP) {
2899 * Allow transfer negotiation to occur in a
2900 * tag free environment and after settle delay.
2902 if (async_code == AC_SENT_BDR
2903 || async_code == AC_BUS_RESET) {
2904 cam_freeze_devq(&newpath);
2905 cam_release_devq(&newpath,
2906 RELSIM_RELEASE_AFTER_TIMEOUT,
2908 /*timeout*/scsi_delay,
2909 /*getcount_only*/0);
2910 scsi_toggle_tags(&newpath);
2913 if (async_code == AC_INQ_CHANGED) {
2915 * We've sent a start unit command, or
2916 * something similar to a device that
2917 * may have caused its inquiry data to
2918 * change. So we re-scan the device to
2919 * refresh the inquiry data for it.
2921 scsi_scan_lun(newpath.periph, &newpath,
2922 CAM_EXPECT_INQ_CHANGE, NULL);
2924 xpt_release_path(&newpath);
2925 } else if (async_code == AC_LOST_DEVICE &&
2926 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2927 device->flags |= CAM_DEV_UNCONFIGURED;
2928 xpt_release_device(device);
2929 } else if (async_code == AC_TRANSFER_NEG) {
2930 struct ccb_trans_settings *settings;
2932 settings = (struct ccb_trans_settings *)async_arg;
2933 scsi_set_transfer_settings(settings, device,
2934 /*async_update*/TRUE);
2939 scsi_announce_periph(struct cam_periph *periph)
2941 struct ccb_pathinq cpi;
2942 struct ccb_trans_settings cts;
2943 struct cam_path *path = periph->path;
2948 mtx_assert(periph->sim->mtx, MA_OWNED);
2950 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2951 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2952 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2953 xpt_action((union ccb*)&cts);
2954 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
2956 /* Ask the SIM for its base transfer speed */
2957 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2958 cpi.ccb_h.func_code = XPT_PATH_INQ;
2959 xpt_action((union ccb *)&cpi);
2960 /* Report connection speed */
2961 speed = cpi.base_transfer_speed;
2963 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2964 struct ccb_trans_settings_spi *spi =
2965 &cts.xport_specific.spi;
2967 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2968 && spi->sync_offset != 0) {
2969 freq = scsi_calc_syncsrate(spi->sync_period);
2972 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2973 speed *= (0x01 << spi->bus_width);
2975 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2976 struct ccb_trans_settings_fc *fc =
2977 &cts.xport_specific.fc;
2979 if (fc->valid & CTS_FC_VALID_SPEED)
2980 speed = fc->bitrate;
2982 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2983 struct ccb_trans_settings_sas *sas =
2984 &cts.xport_specific.sas;
2986 if (sas->valid & CTS_SAS_VALID_SPEED)
2987 speed = sas->bitrate;
2991 printf("%s%d: %d.%03dMB/s transfers",
2992 periph->periph_name, periph->unit_number,
2995 printf("%s%d: %dKB/s transfers", periph->periph_name,
2996 periph->unit_number, speed);
2997 /* Report additional information about SPI connections */
2998 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2999 struct ccb_trans_settings_spi *spi;
3001 spi = &cts.xport_specific.spi;
3003 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3005 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3009 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3010 && spi->bus_width > 0) {
3016 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3017 } else if (freq != 0) {
3021 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3022 struct ccb_trans_settings_fc *fc;
3024 fc = &cts.xport_specific.fc;
3025 if (fc->valid & CTS_FC_VALID_WWNN)
3026 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3027 if (fc->valid & CTS_FC_VALID_WWPN)
3028 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3029 if (fc->valid & CTS_FC_VALID_PORT)
3030 printf(" PortID 0x%x", fc->port);