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 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
82 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT | CTLFLAG_RWTUN, 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
87 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \
88 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
89 RPL_LUNDATA_ATYP_PERIPH) || \
90 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
91 RPL_LUNDATA_ATYP_FLAT))
92 #define CAM_GET_SIMPLE_LUN(lp, i, lval) \
93 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
94 RPL_LUNDATA_ATYP_PERIPH) { \
95 (lval) = (lp)->luns[(i)].lundata[1]; \
97 (lval) = (lp)->luns[(i)].lundata[0]; \
98 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \
100 (lval) |= (lp)->luns[(i)].lundata[1]; \
102 #define CAM_GET_LUN(lp, i, lval) \
103 (lval) = scsi_8btou64((lp)->luns[(i)].lundata); \
104 (lval) = CAM_EXTLUN_BYTE_SWIZZLE(lval);
107 * If we're not quirked to search <= the first 8 luns
108 * and we are either quirked to search above lun 8,
109 * or we're > SCSI-2 and we've enabled hilun searching,
110 * or we're > SCSI-2 and the last lun was a success,
111 * we can look for luns above lun 8.
113 #define CAN_SRCH_HI_SPARSE(dv) \
114 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
115 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
116 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
118 #define CAN_SRCH_HI_DENSE(dv) \
119 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
120 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
121 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
123 static periph_init_t probe_periph_init;
125 static struct periph_driver probe_driver =
127 probe_periph_init, "probe",
128 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
132 PERIPHDRIVER_DECLARE(probe, probe_driver);
136 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
140 PROBE_SUPPORTED_VPD_LIST,
143 PROBE_TUR_FOR_NEGOTIATION,
144 PROBE_INQUIRY_BASIC_DV1,
145 PROBE_INQUIRY_BASIC_DV2,
151 static char *probe_action_text[] = {
154 "PROBE_FULL_INQUIRY",
157 "PROBE_SUPPORTED_VPD_LIST",
160 "PROBE_TUR_FOR_NEGOTIATION",
161 "PROBE_INQUIRY_BASIC_DV1",
162 "PROBE_INQUIRY_BASIC_DV2",
168 #define PROBE_SET_ACTION(softc, newaction) \
171 text = probe_action_text; \
172 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
173 ("Probe %s to %s\n", text[(softc)->action], \
174 text[(newaction)])); \
175 (softc)->action = (newaction); \
179 PROBE_INQUIRY_CKSUM = 0x01,
180 PROBE_SERIAL_CKSUM = 0x02,
181 PROBE_NO_ANNOUNCE = 0x04,
186 TAILQ_HEAD(, ccb_hdr) request_ccbs;
192 struct cam_periph *periph;
195 static const char quantum[] = "QUANTUM";
196 static const char sony[] = "SONY";
197 static const char west_digital[] = "WDIGTL";
198 static const char samsung[] = "SAMSUNG";
199 static const char seagate[] = "SEAGATE";
200 static const char microp[] = "MICROP";
202 static struct scsi_quirk_entry scsi_quirk_table[] =
205 /* Reports QUEUE FULL for temporary resource shortages */
206 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
207 /*quirks*/0, /*mintags*/24, /*maxtags*/32
210 /* Reports QUEUE FULL for temporary resource shortages */
211 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
212 /*quirks*/0, /*mintags*/24, /*maxtags*/32
215 /* Reports QUEUE FULL for temporary resource shortages */
216 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
217 /*quirks*/0, /*mintags*/24, /*maxtags*/32
220 /* Broken tagged queuing drive */
221 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
222 /*quirks*/0, /*mintags*/0, /*maxtags*/0
225 /* Broken tagged queuing drive */
226 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
227 /*quirks*/0, /*mintags*/0, /*maxtags*/0
230 /* Broken tagged queuing drive */
231 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
232 /*quirks*/0, /*mintags*/0, /*maxtags*/0
236 * Unfortunately, the Quantum Atlas III has the same
237 * problem as the Atlas II drives above.
238 * Reported by: "Johan Granlund" <johan@granlund.nu>
240 * For future reference, the drive with the problem was:
241 * QUANTUM QM39100TD-SW N1B0
243 * It's possible that Quantum will fix the problem in later
244 * firmware revisions. If that happens, the quirk entry
245 * will need to be made specific to the firmware revisions
249 /* Reports QUEUE FULL for temporary resource shortages */
250 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
251 /*quirks*/0, /*mintags*/24, /*maxtags*/32
255 * 18 Gig Atlas III, same problem as the 9G version.
256 * Reported by: Andre Albsmeier
257 * <andre.albsmeier@mchp.siemens.de>
259 * For future reference, the drive with the problem was:
260 * QUANTUM QM318000TD-S N491
262 /* Reports QUEUE FULL for temporary resource shortages */
263 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
264 /*quirks*/0, /*mintags*/24, /*maxtags*/32
268 * Broken tagged queuing drive
269 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
270 * and: Martin Renters <martin@tdc.on.ca>
272 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
273 /*quirks*/0, /*mintags*/0, /*maxtags*/0
276 * The Seagate Medalist Pro drives have very poor write
277 * performance with anything more than 2 tags.
279 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
280 * Drive: <SEAGATE ST36530N 1444>
282 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
283 * Drive: <SEAGATE ST34520W 1281>
285 * No one has actually reported that the 9G version
286 * (ST39140*) of the Medalist Pro has the same problem, but
287 * we're assuming that it does because the 4G and 6.5G
288 * versions of the drive are broken.
291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
292 /*quirks*/0, /*mintags*/2, /*maxtags*/2
295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
296 /*quirks*/0, /*mintags*/2, /*maxtags*/2
299 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
300 /*quirks*/0, /*mintags*/2, /*maxtags*/2
304 * Experiences command timeouts under load with a
305 * tag count higher than 55.
307 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
308 /*quirks*/0, /*mintags*/2, /*maxtags*/55
312 * Slow when tagged queueing is enabled. Write performance
313 * steadily drops off with more and more concurrent
314 * transactions. Best sequential write performance with
315 * tagged queueing turned off and write caching turned on.
318 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
319 * Drive: DCAS-34330 w/ "S65A" firmware.
321 * The drive with the problem had the "S65A" firmware
322 * revision, and has also been reported (by Stephen J.
323 * Roznowski <sjr@home.net>) for a drive with the "S61A"
326 * Although no one has reported problems with the 2 gig
327 * version of the DCAS drive, the assumption is that it
328 * has the same problems as the 4 gig version. Therefore
329 * this quirk entries disables tagged queueing for all
332 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
333 /*quirks*/0, /*mintags*/0, /*maxtags*/0
336 /* Broken tagged queuing drive */
337 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
338 /*quirks*/0, /*mintags*/0, /*maxtags*/0
341 /* Broken tagged queuing drive */
342 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
343 /*quirks*/0, /*mintags*/0, /*maxtags*/0
346 /* This does not support other than LUN 0 */
347 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
348 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
352 * Broken tagged queuing drive.
354 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
357 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
358 /*quirks*/0, /*mintags*/0, /*maxtags*/0
362 * Slow when tagged queueing is enabled. (1.5MB/sec versus
364 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
365 * Best performance with these drives is achieved with
366 * tagged queueing turned off, and write caching turned on.
368 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
369 /*quirks*/0, /*mintags*/0, /*maxtags*/0
373 * Slow when tagged queueing is enabled. (1.5MB/sec versus
375 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
376 * Best performance with these drives is achieved with
377 * tagged queueing turned off, and write caching turned on.
379 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
380 /*quirks*/0, /*mintags*/0, /*maxtags*/0
384 * Doesn't handle queue full condition correctly,
385 * so we need to limit maxtags to what the device
386 * can handle instead of determining this automatically.
388 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
389 /*quirks*/0, /*mintags*/2, /*maxtags*/32
392 /* Really only one LUN */
393 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
394 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
397 /* I can't believe we need a quirk for DPT volumes. */
398 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
400 /*mintags*/0, /*maxtags*/255
404 * Many Sony CDROM drives don't like multi-LUN probing.
406 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
407 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
411 * This drive doesn't like multiple LUN probing.
412 * Submitted by: Parag Patel <parag@cgt.com>
414 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
415 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
418 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
419 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
423 * The 8200 doesn't like multi-lun probing, and probably
424 * don't like serial number requests either.
427 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
430 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
434 * Let's try the same as above, but for a drive that says
435 * it's an IPL-6860 but is actually an EXB 8200.
438 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
441 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
445 * These Hitachi drives don't like multi-lun probing.
446 * The PR submitter has a DK319H, but says that the Linux
447 * kernel has a similar work-around for the DK312 and DK314,
448 * so all DK31* drives are quirked here.
450 * Submitted by: Paul Haddad <paul@pth.com>
452 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
453 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
457 * The Hitachi CJ series with J8A8 firmware apparantly has
458 * problems with tagged commands.
460 * Reported by: amagai@nue.org
462 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
463 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
467 * These are the large storage arrays.
468 * Submitted by: William Carrel <william.carrel@infospace.com>
470 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
471 CAM_QUIRK_HILUNS, 2, 1024
475 * This old revision of the TDC3600 is also SCSI-1, and
476 * hangs upon serial number probing.
479 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
482 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
486 * Would repond to all LUNs if asked for.
489 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
492 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
496 * Would repond to all LUNs if asked for.
499 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
502 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
505 /* Submitted by: Matthew Dodd <winter@jurai.net> */
506 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
507 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
510 /* Submitted by: Matthew Dodd <winter@jurai.net> */
511 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
512 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
515 /* TeraSolutions special settings for TRC-22 RAID */
516 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
517 /*quirks*/0, /*mintags*/55, /*maxtags*/255
520 /* Veritas Storage Appliance */
521 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
522 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
526 * Would respond to all LUNs. Device type and removable
527 * flag are jumper-selectable.
529 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
532 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
535 /* EasyRAID E5A aka. areca ARC-6010 */
536 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
537 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
540 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
541 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
544 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
545 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
548 /* Default tagged queuing parameters for all devices */
550 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
551 /*vendor*/"*", /*product*/"*", /*revision*/"*"
553 /*quirks*/0, /*mintags*/2, /*maxtags*/255
557 static const int scsi_quirk_table_size =
558 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
560 static cam_status proberegister(struct cam_periph *periph,
562 static void probeschedule(struct cam_periph *probe_periph);
563 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
564 static void proberequestdefaultnegotiation(struct cam_periph *periph);
565 static int proberequestbackoff(struct cam_periph *periph,
566 struct cam_ed *device);
567 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
568 static void probe_purge_old(struct cam_path *path,
569 struct scsi_report_luns_data *new,
571 static void probecleanup(struct cam_periph *periph);
572 static void scsi_find_quirk(struct cam_ed *device);
573 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
574 static void scsi_scan_lun(struct cam_periph *periph,
575 struct cam_path *path, cam_flags flags,
577 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
578 static struct cam_ed *
579 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
581 static void scsi_devise_transport(struct cam_path *path);
582 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
583 struct cam_path *path,
585 static void scsi_toggle_tags(struct cam_path *path);
586 static void scsi_dev_async(u_int32_t async_code,
588 struct cam_et *target,
589 struct cam_ed *device,
591 static void scsi_action(union ccb *start_ccb);
592 static void scsi_announce_periph(struct cam_periph *periph);
594 static struct xpt_xport scsi_xport = {
595 .alloc_device = scsi_alloc_device,
596 .action = scsi_action,
597 .async = scsi_dev_async,
598 .announce = scsi_announce_periph,
604 return (&scsi_xport);
613 proberegister(struct cam_periph *periph, void *arg)
615 union ccb *request_ccb; /* CCB representing the probe request */
619 request_ccb = (union ccb *)arg;
620 if (request_ccb == NULL) {
621 printf("proberegister: no probe CCB, "
622 "can't register device\n");
623 return(CAM_REQ_CMP_ERR);
626 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
629 printf("proberegister: Unable to probe new device. "
630 "Unable to allocate softc\n");
631 return(CAM_REQ_CMP_ERR);
633 TAILQ_INIT(&softc->request_ccbs);
634 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
637 periph->softc = softc;
638 softc->periph = periph;
639 softc->action = PROBE_INVALID;
640 status = cam_periph_acquire(periph);
641 if (status != CAM_REQ_CMP) {
644 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
645 scsi_devise_transport(periph->path);
648 * Ensure we've waited at least a bus settle
649 * delay before attempting to probe the device.
650 * For HBAs that don't do bus resets, this won't make a difference.
652 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
654 probeschedule(periph);
659 probeschedule(struct cam_periph *periph)
661 struct ccb_pathinq cpi;
665 softc = (probe_softc *)periph->softc;
666 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
668 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
669 cpi.ccb_h.func_code = XPT_PATH_INQ;
670 xpt_action((union ccb *)&cpi);
673 * If a device has gone away and another device, or the same one,
674 * is back in the same place, it should have a unit attention
675 * condition pending. It will not report the unit attention in
676 * response to an inquiry, which may leave invalid transfer
677 * negotiations in effect. The TUR will reveal the unit attention
678 * condition. Only send the TUR for lun 0, since some devices
679 * will get confused by commands other than inquiry to non-existent
680 * luns. If you think a device has gone away start your scan from
681 * lun 0. This will insure that any bogus transfer settings are
684 * If we haven't seen the device before and the controller supports
685 * some kind of transfer negotiation, negotiate with the first
686 * sent command if no bus reset was performed at startup. This
687 * ensures that the device is not confused by transfer negotiation
688 * settings left over by loader or BIOS action.
690 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
691 && (ccb->ccb_h.target_lun == 0)) {
692 PROBE_SET_ACTION(softc, PROBE_TUR);
693 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
694 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
695 proberequestdefaultnegotiation(periph);
696 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
698 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
701 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
702 softc->flags |= PROBE_NO_ANNOUNCE;
704 softc->flags &= ~PROBE_NO_ANNOUNCE;
706 if (cpi.hba_misc & PIM_EXTLUNS)
707 softc->flags |= PROBE_EXTLUN;
709 softc->flags &= ~PROBE_EXTLUN;
711 xpt_schedule(periph, CAM_PRIORITY_XPT);
715 probestart(struct cam_periph *periph, union ccb *start_ccb)
717 /* Probe the device that our peripheral driver points to */
718 struct ccb_scsiio *csio;
721 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
723 softc = (probe_softc *)periph->softc;
724 csio = &start_ccb->csio;
727 switch (softc->action) {
729 case PROBE_TUR_FOR_NEGOTIATION:
732 scsi_test_unit_ready(csio,
741 case PROBE_FULL_INQUIRY:
742 case PROBE_INQUIRY_BASIC_DV1:
743 case PROBE_INQUIRY_BASIC_DV2:
746 struct scsi_inquiry_data *inq_buf;
748 inq_buf = &periph->path->device->inq_data;
751 * If the device is currently configured, we calculate an
752 * MD5 checksum of the inquiry data, and if the serial number
753 * length is greater than 0, add the serial number data
754 * into the checksum as well. Once the inquiry and the
755 * serial number check finish, we attempt to figure out
756 * whether we still have the same device.
758 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
760 MD5Init(&softc->context);
761 MD5Update(&softc->context, (unsigned char *)inq_buf,
762 sizeof(struct scsi_inquiry_data));
763 softc->flags |= PROBE_INQUIRY_CKSUM;
764 if (periph->path->device->serial_num_len > 0) {
765 MD5Update(&softc->context,
766 periph->path->device->serial_num,
767 periph->path->device->serial_num_len);
768 softc->flags |= PROBE_SERIAL_CKSUM;
770 MD5Final(softc->digest, &softc->context);
773 if (softc->action == PROBE_INQUIRY)
774 inquiry_len = SHORT_INQUIRY_LENGTH;
776 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
779 * Some parallel SCSI devices fail to send an
780 * ignore wide residue message when dealing with
781 * odd length inquiry requests. Round up to be
784 inquiry_len = roundup2(inquiry_len, 2);
786 if (softc->action == PROBE_INQUIRY_BASIC_DV1
787 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
788 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
790 if (inq_buf == NULL) {
791 xpt_print(periph->path, "malloc failure- skipping Basic"
792 "Domain Validation\n");
793 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
794 scsi_test_unit_ready(csio,
811 /*timeout*/60 * 1000);
814 case PROBE_REPORT_LUNS:
818 rp = malloc(periph->path->target->rpl_size,
819 M_CAMXPT, M_NOWAIT | M_ZERO);
821 struct scsi_inquiry_data *inq_buf;
822 inq_buf = &periph->path->device->inq_data;
823 xpt_print(periph->path,
824 "Unable to alloc report luns storage\n");
825 if (INQ_DATA_TQ_ENABLED(inq_buf))
826 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
828 PROBE_SET_ACTION(softc,
829 PROBE_SUPPORTED_VPD_LIST);
832 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
833 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
834 SSD_FULL_SIZE, 60000); break;
837 case PROBE_MODE_SENSE:
842 mode_buf_len = sizeof(struct scsi_mode_header_6)
843 + sizeof(struct scsi_mode_blk_desc)
844 + sizeof(struct scsi_control_page);
845 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
846 if (mode_buf != NULL) {
847 scsi_mode_sense(csio,
852 SMS_PAGE_CTRL_CURRENT,
853 SMS_CONTROL_MODE_PAGE,
860 xpt_print(periph->path, "Unable to mode sense control page - "
862 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
865 case PROBE_SUPPORTED_VPD_LIST:
867 struct scsi_vpd_supported_page_list *vpd_list;
868 struct cam_ed *device;
871 device = periph->path->device;
873 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
874 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
877 if (vpd_list != NULL) {
882 (u_int8_t *)vpd_list,
885 SVPD_SUPPORTED_PAGE_LIST,
887 /*timeout*/60 * 1000);
892 * We'll have to do without, let our probedone
893 * routine finish up for us.
895 start_ccb->csio.data_ptr = NULL;
896 cam_freeze_devq(periph->path);
897 cam_periph_doacquire(periph);
898 probedone(periph, start_ccb);
901 case PROBE_DEVICE_ID:
903 struct scsi_vpd_device_id *devid;
906 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
907 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
916 SVPD_DEVICE_ID_MAX_SIZE,
920 /*timeout*/60 * 1000);
925 case PROBE_SERIAL_NUM:
927 struct scsi_vpd_unit_serial_number *serial_buf;
928 struct cam_ed* device;
931 device = periph->path->device;
932 if (device->serial_num != NULL) {
933 free(device->serial_num, M_CAMXPT);
934 device->serial_num = NULL;
935 device->serial_num_len = 0;
938 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
939 serial_buf = (struct scsi_vpd_unit_serial_number *)
940 malloc(sizeof(*serial_buf), M_CAMXPT,
943 if (serial_buf != NULL) {
948 (u_int8_t *)serial_buf,
951 SVPD_UNIT_SERIAL_NUMBER,
953 /*timeout*/60 * 1000);
959 panic("probestart: invalid action state 0x%x\n", softc->action);
961 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
962 cam_periph_doacquire(periph);
963 xpt_action(start_ccb);
967 proberequestdefaultnegotiation(struct cam_periph *periph)
969 struct ccb_trans_settings cts;
971 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
972 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
973 cts.type = CTS_TYPE_USER_SETTINGS;
974 xpt_action((union ccb *)&cts);
975 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
978 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
979 cts.type = CTS_TYPE_CURRENT_SETTINGS;
980 xpt_action((union ccb *)&cts);
984 * Backoff Negotiation Code- only pertinent for SPI devices.
987 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
989 struct ccb_trans_settings cts;
990 struct ccb_trans_settings_spi *spi;
992 memset(&cts, 0, sizeof (cts));
993 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
994 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
995 cts.type = CTS_TYPE_CURRENT_SETTINGS;
996 xpt_action((union ccb *)&cts);
997 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
999 xpt_print(periph->path,
1000 "failed to get current device settings\n");
1004 if (cts.transport != XPORT_SPI) {
1006 xpt_print(periph->path, "not SPI transport\n");
1010 spi = &cts.xport_specific.spi;
1013 * We cannot renegotiate sync rate if we don't have one.
1015 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1017 xpt_print(periph->path, "no sync rate known\n");
1023 * We'll assert that we don't have to touch PPR options- the
1024 * SIM will see what we do with period and offset and adjust
1025 * the PPR options as appropriate.
1029 * A sync rate with unknown or zero offset is nonsensical.
1030 * A sync period of zero means Async.
1032 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1033 || spi->sync_offset == 0 || spi->sync_period == 0) {
1035 xpt_print(periph->path, "no sync rate available\n");
1040 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1041 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1042 ("hit async: giving up on DV\n"));
1048 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1049 * We don't try to remember 'last' settings to see if the SIM actually
1050 * gets into the speed we want to set. We check on the SIM telling
1051 * us that a requested speed is bad, but otherwise don't try and
1052 * check the speed due to the asynchronous and handshake nature
1055 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1058 if (spi->sync_period >= 0xf) {
1059 spi->sync_period = 0;
1060 spi->sync_offset = 0;
1061 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1062 ("setting to async for DV\n"));
1064 * Once we hit async, we don't want to try
1065 * any more settings.
1067 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1068 } else if (bootverbose) {
1069 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1070 ("DV: period 0x%x\n", spi->sync_period));
1071 printf("setting period to 0x%x\n", spi->sync_period);
1073 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1074 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1075 xpt_action((union ccb *)&cts);
1076 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1079 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1080 ("DV: failed to set period 0x%x\n", spi->sync_period));
1081 if (spi->sync_period == 0) {
1088 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1091 probedone(struct cam_periph *periph, union ccb *done_ccb)
1094 struct cam_path *path;
1097 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1099 softc = (probe_softc *)periph->softc;
1100 path = done_ccb->ccb_h.path;
1101 priority = done_ccb->ccb_h.pinfo.priority;
1103 switch (softc->action) {
1106 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1108 if (cam_periph_error(done_ccb, 0,
1109 SF_NO_PRINT, NULL) == ERESTART) {
1111 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1112 cam_release_devq(path, 0, 0, 0, FALSE);
1115 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1116 /* Don't wedge the queue */
1117 xpt_release_devq(done_ccb->ccb_h.path,
1121 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1122 xpt_release_ccb(done_ccb);
1123 xpt_schedule(periph, priority);
1125 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1126 cam_release_devq(path, 0, 0, 0, FALSE);
1127 cam_periph_release_locked(periph);
1131 case PROBE_FULL_INQUIRY:
1133 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1134 struct scsi_inquiry_data *inq_buf;
1135 u_int8_t periph_qual;
1137 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1138 inq_buf = &path->device->inq_data;
1140 periph_qual = SID_QUAL(inq_buf);
1142 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1146 * We conservatively request only
1147 * SHORT_INQUIRY_LEN bytes of inquiry
1148 * information during our first try
1149 * at sending an INQUIRY. If the device
1150 * has more information to give,
1151 * perform a second request specifying
1152 * the amount of information the device
1153 * is willing to give.
1155 len = inq_buf->additional_length
1156 + offsetof(struct scsi_inquiry_data,
1157 additional_length) + 1;
1158 if (softc->action == PROBE_INQUIRY
1159 && len > SHORT_INQUIRY_LENGTH) {
1160 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1161 xpt_release_ccb(done_ccb);
1162 xpt_schedule(periph, priority);
1166 scsi_find_quirk(path->device);
1168 scsi_devise_transport(path);
1170 if (path->device->lun_id == 0 &&
1171 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1172 (SCSI_QUIRK(path->device)->quirks &
1173 CAM_QUIRK_NORPTLUNS) == 0) {
1174 PROBE_SET_ACTION(softc,
1177 * Start with room for *one* lun.
1179 periph->path->target->rpl_size = 16;
1180 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1181 PROBE_SET_ACTION(softc,
1184 PROBE_SET_ACTION(softc,
1185 PROBE_SUPPORTED_VPD_LIST);
1187 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1188 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1189 xpt_acquire_device(path->device);
1191 xpt_release_ccb(done_ccb);
1192 xpt_schedule(periph, priority);
1194 } else if (path->device->lun_id == 0 &&
1195 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1196 (SCSI_QUIRK(path->device)->quirks &
1197 CAM_QUIRK_NORPTLUNS) == 0) {
1198 if (path->device->flags &
1199 CAM_DEV_UNCONFIGURED) {
1200 path->device->flags &=
1201 ~CAM_DEV_UNCONFIGURED;
1202 xpt_acquire_device(path->device);
1204 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1205 periph->path->target->rpl_size = 16;
1206 xpt_release_ccb(done_ccb);
1207 xpt_schedule(periph, priority);
1210 } else if (cam_periph_error(done_ccb, 0,
1211 done_ccb->ccb_h.target_lun > 0
1212 ? SF_RETRY_UA|SF_QUIET_IR
1214 &softc->saved_ccb) == ERESTART) {
1216 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1217 /* Don't wedge the queue */
1218 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1222 * If we get to this point, we got an error status back
1223 * from the inquiry and the error status doesn't require
1224 * automatically retrying the command. Therefore, the
1225 * inquiry failed. If we had inquiry information before
1226 * for this device, but this latest inquiry command failed,
1227 * the device has probably gone away. If this device isn't
1228 * already marked unconfigured, notify the peripheral
1229 * drivers that this device is no more.
1231 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1232 /* Send the async notification. */
1233 xpt_async(AC_LOST_DEVICE, path, NULL);
1234 PROBE_SET_ACTION(softc, PROBE_INVALID);
1236 xpt_release_ccb(done_ccb);
1239 case PROBE_REPORT_LUNS:
1241 struct ccb_scsiio *csio;
1242 struct scsi_report_luns_data *lp;
1245 csio = &done_ccb->csio;
1247 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1248 nlun = scsi_4btoul(lp->length) / 8;
1249 maxlun = (csio->dxfer_len / 8) - 1;
1251 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1252 if (cam_periph_error(done_ccb, 0,
1253 done_ccb->ccb_h.target_lun > 0 ?
1254 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1255 &softc->saved_ccb) == ERESTART) {
1258 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1259 xpt_release_devq(done_ccb->ccb_h.path, 1,
1264 } else if (nlun > maxlun) {
1266 * Reallocate and retry to cover all luns
1268 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1269 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1272 path->target->rpl_size = (nlun << 3) + 8;
1273 xpt_release_ccb(done_ccb);
1274 xpt_schedule(periph, priority);
1276 } else if (nlun == 0) {
1278 * If there don't appear to be any luns, bail.
1286 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1287 ("Probe: %u lun(s) reported\n", nlun));
1289 CAM_GET_LUN(lp, 0, lun);
1291 * If the first lun is not lun 0, then either there
1292 * is no lun 0 in the list, or the list is unsorted.
1295 for (idx = 0; idx < nlun; idx++) {
1296 CAM_GET_LUN(lp, idx, lun);
1304 lp->luns[0].lundata, 8);
1305 memcpy(lp->luns[0].lundata,
1306 lp->luns[idx].lundata, 8);
1307 memcpy(lp->luns[idx].lundata,
1309 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1310 ("lun 0 in position %u\n", idx));
1313 * There is no lun 0 in our list. Destroy
1314 * the validity of the inquiry data so we
1315 * bail here and now.
1317 path->device->flags &=
1318 ~CAM_DEV_INQUIRY_DATA_VALID;
1322 * If we have an old lun list, We can either
1323 * retest luns that appear to have been dropped,
1324 * or just nuke them. We'll opt for the latter.
1325 * This function will also install the new list
1326 * in the target structure.
1328 probe_purge_old(path, lp, softc->flags);
1331 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1332 struct scsi_inquiry_data *inq_buf;
1333 inq_buf = &path->device->inq_data;
1334 if (INQ_DATA_TQ_ENABLED(inq_buf))
1335 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1337 PROBE_SET_ACTION(softc,
1338 PROBE_SUPPORTED_VPD_LIST);
1339 xpt_release_ccb(done_ccb);
1340 xpt_schedule(periph, priority);
1348 case PROBE_MODE_SENSE:
1350 struct ccb_scsiio *csio;
1351 struct scsi_mode_header_6 *mode_hdr;
1353 csio = &done_ccb->csio;
1354 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1355 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1356 struct scsi_control_page *page;
1359 offset = ((u_int8_t *)&mode_hdr[1])
1360 + mode_hdr->blk_desc_len;
1361 page = (struct scsi_control_page *)offset;
1362 path->device->queue_flags = page->queue_flags;
1363 } else if (cam_periph_error(done_ccb, 0,
1364 SF_RETRY_UA|SF_NO_PRINT,
1365 &softc->saved_ccb) == ERESTART) {
1367 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1368 /* Don't wedge the queue */
1369 xpt_release_devq(done_ccb->ccb_h.path,
1370 /*count*/1, /*run_queue*/TRUE);
1372 xpt_release_ccb(done_ccb);
1373 free(mode_hdr, M_CAMXPT);
1374 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1375 xpt_schedule(periph, priority);
1378 case PROBE_SUPPORTED_VPD_LIST:
1380 struct ccb_scsiio *csio;
1381 struct scsi_vpd_supported_page_list *page_list;
1383 csio = &done_ccb->csio;
1385 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1387 if (path->device->supported_vpds != NULL) {
1388 free(path->device->supported_vpds, M_CAMXPT);
1389 path->device->supported_vpds = NULL;
1390 path->device->supported_vpds_len = 0;
1393 if (page_list == NULL) {
1395 * Don't process the command as it was never sent
1397 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1399 path->device->supported_vpds_len = page_list->length +
1400 SVPD_SUPPORTED_PAGES_HDR_LEN;
1401 path->device->supported_vpds = (uint8_t *)page_list;
1402 xpt_release_ccb(done_ccb);
1403 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1404 xpt_schedule(periph, priority);
1406 } else if (cam_periph_error(done_ccb, 0,
1407 SF_RETRY_UA|SF_NO_PRINT,
1408 &softc->saved_ccb) == ERESTART) {
1410 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1411 /* Don't wedge the queue */
1412 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1417 free(page_list, M_CAMXPT);
1418 /* No VPDs available, skip to device check. */
1419 csio->data_ptr = NULL;
1420 goto probe_device_check;
1422 case PROBE_DEVICE_ID:
1424 struct scsi_vpd_device_id *devid;
1425 struct ccb_scsiio *csio;
1426 uint32_t length = 0;
1428 csio = &done_ccb->csio;
1429 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1431 /* Clean up from previous instance of this device */
1432 if (path->device->device_id != NULL) {
1433 path->device->device_id_len = 0;
1434 free(path->device->device_id, M_CAMXPT);
1435 path->device->device_id = NULL;
1438 if (devid == NULL) {
1439 /* Don't process the command as it was never sent */
1440 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1441 length = scsi_2btoul(devid->length);
1444 * NB: device_id_len is actual response
1445 * size, not buffer size.
1447 path->device->device_id_len = length +
1448 SVPD_DEVICE_ID_HDR_LEN;
1449 path->device->device_id = (uint8_t *)devid;
1451 } else if (cam_periph_error(done_ccb, 0,
1453 &softc->saved_ccb) == ERESTART) {
1455 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1456 /* Don't wedge the queue */
1457 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1461 /* Free the device id space if we don't use it */
1462 if (devid && length == 0)
1463 free(devid, M_CAMXPT);
1464 xpt_release_ccb(done_ccb);
1465 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1466 xpt_schedule(periph, priority);
1471 case PROBE_SERIAL_NUM:
1473 struct ccb_scsiio *csio;
1474 struct scsi_vpd_unit_serial_number *serial_buf;
1481 csio = &done_ccb->csio;
1482 priority = done_ccb->ccb_h.pinfo.priority;
1484 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1486 if (serial_buf == NULL) {
1488 * Don't process the command as it was never sent
1490 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1491 && (serial_buf->length > 0)) {
1494 path->device->serial_num =
1495 (u_int8_t *)malloc((serial_buf->length + 1),
1496 M_CAMXPT, M_NOWAIT);
1497 if (path->device->serial_num != NULL) {
1498 memcpy(path->device->serial_num,
1499 serial_buf->serial_num,
1500 serial_buf->length);
1501 path->device->serial_num_len =
1503 path->device->serial_num[serial_buf->length]
1506 } else if (cam_periph_error(done_ccb, 0,
1507 SF_RETRY_UA|SF_NO_PRINT,
1508 &softc->saved_ccb) == ERESTART) {
1510 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1511 /* Don't wedge the queue */
1512 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1517 * Let's see if we have seen this device before.
1519 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1521 u_int8_t digest[16];
1526 (unsigned char *)&path->device->inq_data,
1527 sizeof(struct scsi_inquiry_data));
1530 MD5Update(&context, serial_buf->serial_num,
1531 serial_buf->length);
1533 MD5Final(digest, &context);
1534 if (bcmp(softc->digest, digest, 16) == 0)
1538 * XXX Do we need to do a TUR in order to ensure
1539 * that the device really hasn't changed???
1542 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1543 xpt_async(AC_LOST_DEVICE, path, NULL);
1545 if (serial_buf != NULL)
1546 free(serial_buf, M_CAMXPT);
1550 * Now that we have all the necessary
1551 * information to safely perform transfer
1552 * negotiations... Controllers don't perform
1553 * any negotiation or tagged queuing until
1554 * after the first XPT_SET_TRAN_SETTINGS ccb is
1555 * received. So, on a new device, just retrieve
1556 * the user settings, and set them as the current
1557 * settings to set the device up.
1559 proberequestdefaultnegotiation(periph);
1560 xpt_release_ccb(done_ccb);
1563 * Perform a TUR to allow the controller to
1564 * perform any necessary transfer negotiation.
1566 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1567 xpt_schedule(periph, priority);
1570 xpt_release_ccb(done_ccb);
1573 case PROBE_TUR_FOR_NEGOTIATION:
1575 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1576 cam_periph_error(done_ccb, 0,
1577 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1579 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1580 /* Don't wedge the queue */
1581 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1585 * Do Domain Validation for lun 0 on devices that claim
1586 * to support Synchronous Transfer modes.
1588 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1589 && done_ccb->ccb_h.target_lun == 0
1590 && (path->device->inq_data.flags & SID_Sync) != 0
1591 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1592 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1593 ("Begin Domain Validation\n"));
1594 path->device->flags |= CAM_DEV_IN_DV;
1595 xpt_release_ccb(done_ccb);
1596 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1597 xpt_schedule(periph, priority);
1600 if (softc->action == PROBE_DV_EXIT) {
1601 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1602 ("Leave Domain Validation\n"));
1604 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1605 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1606 xpt_acquire_device(path->device);
1608 path->device->flags &=
1609 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1610 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1611 /* Inform the XPT that a new device has been found */
1612 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1613 xpt_action(done_ccb);
1614 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1617 PROBE_SET_ACTION(softc, PROBE_DONE);
1618 xpt_release_ccb(done_ccb);
1620 case PROBE_INQUIRY_BASIC_DV1:
1621 case PROBE_INQUIRY_BASIC_DV2:
1623 struct scsi_inquiry_data *nbuf;
1624 struct ccb_scsiio *csio;
1626 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1627 cam_periph_error(done_ccb, 0,
1628 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1630 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1631 /* Don't wedge the queue */
1632 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1635 csio = &done_ccb->csio;
1636 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1637 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1639 "inquiry data fails comparison at DV%d step\n",
1640 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1641 if (proberequestbackoff(periph, path->device)) {
1642 path->device->flags &= ~CAM_DEV_IN_DV;
1643 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1646 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1648 free(nbuf, M_CAMXPT);
1649 xpt_release_ccb(done_ccb);
1650 xpt_schedule(periph, priority);
1653 free(nbuf, M_CAMXPT);
1654 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1655 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1656 xpt_release_ccb(done_ccb);
1657 xpt_schedule(periph, priority);
1660 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1661 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1662 ("Leave Domain Validation Successfully\n"));
1664 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1665 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1666 xpt_acquire_device(path->device);
1668 path->device->flags &=
1669 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1670 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1671 /* Inform the XPT that a new device has been found */
1672 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1673 xpt_action(done_ccb);
1674 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1677 PROBE_SET_ACTION(softc, PROBE_DONE);
1678 xpt_release_ccb(done_ccb);
1682 panic("probedone: invalid action state 0x%x\n", softc->action);
1684 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1685 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1686 done_ccb->ccb_h.status = CAM_REQ_CMP;
1688 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1689 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1690 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1691 cam_release_devq(path, 0, 0, 0, FALSE);
1692 cam_periph_release_locked(periph);
1693 cam_periph_invalidate(periph);
1694 cam_periph_release_locked(periph);
1696 probeschedule(periph);
1702 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1705 struct cam_path *tp;
1706 struct scsi_report_luns_data *old;
1707 u_int idx1, idx2, nlun_old, nlun_new;
1711 if (path->target == NULL) {
1714 mtx_lock(&path->target->luns_mtx);
1715 old = path->target->luns;
1716 path->target->luns = new;
1717 mtx_unlock(&path->target->luns_mtx);
1720 nlun_old = scsi_4btoul(old->length) / 8;
1721 nlun_new = scsi_4btoul(new->length) / 8;
1724 * We are not going to assume sorted lists. Deal.
1726 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1727 ol = old->luns[idx1].lundata;
1728 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1729 nl = new->luns[idx2].lundata;
1730 if (memcmp(nl, ol, 8) == 0) {
1734 if (idx2 < nlun_new) {
1738 * An 'old' item not in the 'new' list.
1739 * Nuke it. Except that if it is lun 0,
1740 * that would be what the probe state
1741 * machine is currently working on,
1742 * so we won't do that.
1744 CAM_GET_LUN(old, idx1, this_lun);
1745 if (this_lun == 0) {
1750 * We also cannot nuke it if it is
1751 * not in a lun format we understand
1752 * and replace the LUN with a "simple" LUN
1753 * if that is all the HBA supports.
1755 if (!(flags & PROBE_EXTLUN)) {
1756 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1758 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1761 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1762 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1763 xpt_async(AC_LOST_DEVICE, tp, NULL);
1767 free(old, M_CAMXPT);
1771 probecleanup(struct cam_periph *periph)
1773 free(periph->softc, M_CAMXPT);
1777 scsi_find_quirk(struct cam_ed *device)
1779 struct scsi_quirk_entry *quirk;
1782 match = cam_quirkmatch((caddr_t)&device->inq_data,
1783 (caddr_t)scsi_quirk_table,
1784 sizeof(scsi_quirk_table) /
1785 sizeof(*scsi_quirk_table),
1786 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1789 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1791 quirk = (struct scsi_quirk_entry *)match;
1792 device->quirk = quirk;
1793 device->mintags = quirk->mintags;
1794 device->maxtags = quirk->maxtags;
1798 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1803 error = sysctl_handle_int(oidp, &val, 0, req);
1804 if (error != 0 || req->newptr == NULL)
1806 if (val == 0 || val == 1) {
1815 union ccb *request_ccb;
1816 struct ccb_pathinq *cpi;
1819 } scsi_scan_bus_info;
1822 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1823 * As the scan progresses, scsi_scan_bus is used as the
1824 * callback on completion function.
1827 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1831 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1832 ("scsi_scan_bus\n"));
1833 switch (request_ccb->ccb_h.func_code) {
1837 scsi_scan_bus_info *scan_info;
1838 union ccb *work_ccb, *reset_ccb;
1839 struct cam_path *path;
1841 u_int low_target, max_target;
1844 /* Find out the characteristics of the bus */
1845 work_ccb = xpt_alloc_ccb_nowait();
1846 if (work_ccb == NULL) {
1847 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1848 xpt_done(request_ccb);
1851 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1852 request_ccb->ccb_h.pinfo.priority);
1853 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1854 xpt_action(work_ccb);
1855 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1856 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1857 xpt_free_ccb(work_ccb);
1858 xpt_done(request_ccb);
1862 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1864 * Can't scan the bus on an adapter that
1865 * cannot perform the initiator role.
1867 request_ccb->ccb_h.status = CAM_REQ_CMP;
1868 xpt_free_ccb(work_ccb);
1869 xpt_done(request_ccb);
1873 /* We may need to reset bus first, if we haven't done it yet. */
1874 if ((work_ccb->cpi.hba_inquiry &
1875 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1876 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1877 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1878 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1879 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1881 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1882 xpt_action(reset_ccb);
1883 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1884 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1885 xpt_free_ccb(reset_ccb);
1886 xpt_free_ccb(work_ccb);
1887 xpt_done(request_ccb);
1890 xpt_free_ccb(reset_ccb);
1893 /* Save some state for use while we probe for devices */
1894 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1895 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1896 if (scan_info == NULL) {
1897 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1898 xpt_free_ccb(work_ccb);
1899 xpt_done(request_ccb);
1902 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1903 ("SCAN start for %p\n", scan_info));
1904 scan_info->request_ccb = request_ccb;
1905 scan_info->cpi = &work_ccb->cpi;
1907 /* Cache on our stack so we can work asynchronously */
1908 max_target = scan_info->cpi->max_target;
1910 initiator_id = scan_info->cpi->initiator_id;
1914 * We can scan all targets in parallel, or do it sequentially.
1917 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1918 max_target = low_target = request_ccb->ccb_h.target_id;
1919 scan_info->counter = 0;
1920 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1922 scan_info->counter = 0;
1924 scan_info->counter = scan_info->cpi->max_target + 1;
1925 if (scan_info->cpi->initiator_id < scan_info->counter) {
1926 scan_info->counter--;
1929 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1932 for (i = low_target; i <= max_target; i++) {
1934 if (i == initiator_id)
1937 status = xpt_create_path(&path, NULL,
1938 request_ccb->ccb_h.path_id,
1940 if (status != CAM_REQ_CMP) {
1941 printf("scsi_scan_bus: xpt_create_path failed"
1942 " with status %#x, bus scan halted\n",
1944 free(scan_info, M_CAMXPT);
1945 request_ccb->ccb_h.status = status;
1946 xpt_free_ccb(work_ccb);
1947 xpt_done(request_ccb);
1950 work_ccb = xpt_alloc_ccb_nowait();
1951 if (work_ccb == NULL) {
1952 xpt_free_ccb((union ccb *)scan_info->cpi);
1953 free(scan_info, M_CAMXPT);
1954 xpt_free_path(path);
1955 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1956 xpt_done(request_ccb);
1959 xpt_setup_ccb(&work_ccb->ccb_h, path,
1960 request_ccb->ccb_h.pinfo.priority);
1961 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1962 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1963 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1964 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1965 work_ccb->crcn.flags = request_ccb->crcn.flags;
1966 xpt_action(work_ccb);
1975 struct cam_path *path, *oldpath;
1976 scsi_scan_bus_info *scan_info;
1977 struct cam_et *target;
1978 struct cam_ed *device;
1981 target_id_t target_id;
1984 oldpath = request_ccb->ccb_h.path;
1986 status = cam_ccb_status(request_ccb);
1987 /* Reuse the same CCB to query if a device was really found */
1988 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1989 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1990 request_ccb->ccb_h.pinfo.priority);
1991 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1994 path_id = request_ccb->ccb_h.path_id;
1995 target_id = request_ccb->ccb_h.target_id;
1996 lun_id = request_ccb->ccb_h.target_lun;
1997 xpt_action(request_ccb);
1999 target = request_ccb->ccb_h.path->target;
2002 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2004 mtx_lock(&target->luns_mtx);
2007 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2010 * Make sure we skip over lun 0 if it's the first member
2011 * of the list as we've actually just finished probing
2014 CAM_GET_LUN(target->luns, 0, first);
2015 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2016 scan_info->lunindex[target_id]++;
2020 * Skip any LUNs that the HBA can't deal with.
2022 while (scan_info->lunindex[target_id] < nluns) {
2023 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2024 CAM_GET_LUN(target->luns,
2025 scan_info->lunindex[target_id],
2030 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2031 scan_info->lunindex[target_id])) {
2032 CAM_GET_SIMPLE_LUN(target->luns,
2033 scan_info->lunindex[target_id],
2038 scan_info->lunindex[target_id]++;
2041 if (scan_info->lunindex[target_id] < nluns) {
2042 mtx_unlock(&target->luns_mtx);
2044 CAM_DEBUG(request_ccb->ccb_h.path,
2046 ("next lun to try at index %u is %jx\n",
2047 scan_info->lunindex[target_id],
2048 (uintmax_t)lun_id));
2049 scan_info->lunindex[target_id]++;
2051 mtx_unlock(&target->luns_mtx);
2053 * We're done with scanning all luns.
2055 * Nuke the bogus device for lun 0 if lun 0
2056 * wasn't on the list.
2059 TAILQ_FOREACH(device,
2060 &target->ed_entries, links) {
2061 if (device->lun_id == 0) {
2066 xpt_release_device(device);
2071 mtx_unlock(&target->luns_mtx);
2072 if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2076 * If we already probed lun 0 successfully, or
2077 * we have additional configured luns on this
2078 * target that might have "gone away", go onto
2082 * We may touch devices that we don't
2083 * hold references too, so ensure they
2084 * don't disappear out from under us.
2085 * The target above is referenced by the
2086 * path in the request ccb.
2089 device = TAILQ_FIRST(&target->ed_entries);
2090 if (device != NULL) {
2091 phl = CAN_SRCH_HI_SPARSE(device);
2092 if (device->lun_id == 0)
2093 device = TAILQ_NEXT(device, links);
2095 if ((lun_id != 0) || (device != NULL)) {
2096 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2101 if (lun_id == request_ccb->ccb_h.target_lun
2102 || lun_id > scan_info->cpi->max_lun)
2106 device = request_ccb->ccb_h.path->device;
2108 if ((SCSI_QUIRK(device)->quirks &
2109 CAM_QUIRK_NOLUNS) == 0) {
2110 /* Try the next lun */
2111 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2112 || CAN_SRCH_HI_DENSE(device)) {
2117 if (lun_id == request_ccb->ccb_h.target_lun
2118 || lun_id > scan_info->cpi->max_lun)
2124 * Check to see if we scan any further luns.
2130 * Free the current request path- we're done with it.
2132 xpt_free_path(oldpath);
2135 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2137 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2138 scan_info->counter++;
2139 if (scan_info->counter ==
2140 scan_info->cpi->initiator_id) {
2141 scan_info->counter++;
2143 if (scan_info->counter >=
2144 scan_info->cpi->max_target+1) {
2148 scan_info->counter--;
2149 if (scan_info->counter == 0) {
2155 xpt_free_ccb(request_ccb);
2156 xpt_free_ccb((union ccb *)scan_info->cpi);
2157 request_ccb = scan_info->request_ccb;
2158 CAM_DEBUG(request_ccb->ccb_h.path,
2160 ("SCAN done for %p\n", scan_info));
2161 free(scan_info, M_CAMXPT);
2162 request_ccb->ccb_h.status = CAM_REQ_CMP;
2163 xpt_done(request_ccb);
2167 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2169 xpt_free_ccb(request_ccb);
2172 status = xpt_create_path(&path, NULL,
2173 scan_info->request_ccb->ccb_h.path_id,
2174 scan_info->counter, 0);
2175 if (status != CAM_REQ_CMP) {
2177 printf("scsi_scan_bus: xpt_create_path failed"
2178 " with status %#x, bus scan halted\n",
2180 xpt_free_ccb(request_ccb);
2181 xpt_free_ccb((union ccb *)scan_info->cpi);
2182 request_ccb = scan_info->request_ccb;
2183 free(scan_info, M_CAMXPT);
2184 request_ccb->ccb_h.status = status;
2185 xpt_done(request_ccb);
2188 xpt_setup_ccb(&request_ccb->ccb_h, path,
2189 request_ccb->ccb_h.pinfo.priority);
2190 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2191 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2192 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2193 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2194 request_ccb->crcn.flags =
2195 scan_info->request_ccb->crcn.flags;
2197 status = xpt_create_path(&path, NULL,
2198 path_id, target_id, lun_id);
2200 * Free the old request path- we're done with it. We
2201 * do this *after* creating the new path so that
2202 * we don't remove a target that has our lun list
2203 * in the case that lun 0 is not present.
2205 xpt_free_path(oldpath);
2206 if (status != CAM_REQ_CMP) {
2207 printf("scsi_scan_bus: xpt_create_path failed "
2208 "with status %#x, halting LUN scan\n",
2212 xpt_setup_ccb(&request_ccb->ccb_h, path,
2213 request_ccb->ccb_h.pinfo.priority);
2214 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2215 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2216 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2217 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2218 request_ccb->crcn.flags =
2219 scan_info->request_ccb->crcn.flags;
2222 xpt_action(request_ccb);
2231 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2232 cam_flags flags, union ccb *request_ccb)
2234 struct ccb_pathinq cpi;
2236 struct cam_path *new_path;
2237 struct cam_periph *old_periph;
2240 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2242 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2243 cpi.ccb_h.func_code = XPT_PATH_INQ;
2244 xpt_action((union ccb *)&cpi);
2246 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2247 if (request_ccb != NULL) {
2248 request_ccb->ccb_h.status = cpi.ccb_h.status;
2249 xpt_done(request_ccb);
2254 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2256 * Can't scan the bus on an adapter that
2257 * cannot perform the initiator role.
2259 if (request_ccb != NULL) {
2260 request_ccb->ccb_h.status = CAM_REQ_CMP;
2261 xpt_done(request_ccb);
2266 if (request_ccb == NULL) {
2267 request_ccb = xpt_alloc_ccb_nowait();
2268 if (request_ccb == NULL) {
2269 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2270 "can't continue\n");
2273 status = xpt_create_path(&new_path, NULL,
2275 path->target->target_id,
2276 path->device->lun_id);
2277 if (status != CAM_REQ_CMP) {
2278 xpt_print(path, "scsi_scan_lun: can't create path, "
2279 "can't continue\n");
2280 xpt_free_ccb(request_ccb);
2283 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2284 request_ccb->ccb_h.cbfcnp = xptscandone;
2285 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2286 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2287 request_ccb->crcn.flags = flags;
2290 lock = (xpt_path_owned(path) == 0);
2292 xpt_path_lock(path);
2293 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2294 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2297 softc = (probe_softc *)old_periph->softc;
2298 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2299 &request_ccb->ccb_h, periph_links.tqe);
2301 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2302 xpt_done(request_ccb);
2305 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2306 probestart, "probe",
2308 request_ccb->ccb_h.path, NULL, 0,
2311 if (status != CAM_REQ_CMP) {
2312 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2313 "returned an error, can't continue probe\n");
2314 request_ccb->ccb_h.status = status;
2315 xpt_done(request_ccb);
2319 xpt_path_unlock(path);
2323 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2326 xpt_free_path(done_ccb->ccb_h.path);
2327 xpt_free_ccb(done_ccb);
2330 static struct cam_ed *
2331 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2333 struct scsi_quirk_entry *quirk;
2334 struct cam_ed *device;
2336 device = xpt_alloc_device(bus, target, lun_id);
2341 * Take the default quirk entry until we have inquiry
2342 * data and can determine a better quirk to use.
2344 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2345 device->quirk = (void *)quirk;
2346 device->mintags = quirk->mintags;
2347 device->maxtags = quirk->maxtags;
2348 bzero(&device->inq_data, sizeof(device->inq_data));
2349 device->inq_flags = 0;
2350 device->queue_flags = 0;
2351 device->serial_num = NULL;
2352 device->serial_num_len = 0;
2353 device->device_id = NULL;
2354 device->device_id_len = 0;
2355 device->supported_vpds = NULL;
2356 device->supported_vpds_len = 0;
2361 scsi_devise_transport(struct cam_path *path)
2363 struct ccb_pathinq cpi;
2364 struct ccb_trans_settings cts;
2365 struct scsi_inquiry_data *inq_buf;
2367 /* Get transport information from the SIM */
2368 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2369 cpi.ccb_h.func_code = XPT_PATH_INQ;
2370 xpt_action((union ccb *)&cpi);
2373 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2374 inq_buf = &path->device->inq_data;
2375 path->device->protocol = PROTO_SCSI;
2376 path->device->protocol_version =
2377 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2378 path->device->transport = cpi.transport;
2379 path->device->transport_version = cpi.transport_version;
2382 * Any device not using SPI3 features should
2383 * be considered SPI2 or lower.
2385 if (inq_buf != NULL) {
2386 if (path->device->transport == XPORT_SPI
2387 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2388 && path->device->transport_version > 2)
2389 path->device->transport_version = 2;
2391 struct cam_ed* otherdev;
2393 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2395 otherdev = TAILQ_NEXT(otherdev, links)) {
2396 if (otherdev != path->device)
2400 if (otherdev != NULL) {
2402 * Initially assume the same versioning as
2403 * prior luns for this target.
2405 path->device->protocol_version =
2406 otherdev->protocol_version;
2407 path->device->transport_version =
2408 otherdev->transport_version;
2410 /* Until we know better, opt for safty */
2411 path->device->protocol_version = 2;
2412 if (path->device->transport == XPORT_SPI)
2413 path->device->transport_version = 2;
2415 path->device->transport_version = 0;
2421 * For a device compliant with SPC-2 we should be able
2422 * to determine the transport version supported by
2423 * scrutinizing the version descriptors in the
2427 /* Tell the controller what we think */
2428 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2429 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2430 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2431 cts.transport = path->device->transport;
2432 cts.transport_version = path->device->transport_version;
2433 cts.protocol = path->device->protocol;
2434 cts.protocol_version = path->device->protocol_version;
2435 cts.proto_specific.valid = 0;
2436 cts.xport_specific.valid = 0;
2437 xpt_action((union ccb *)&cts);
2441 scsi_dev_advinfo(union ccb *start_ccb)
2443 struct cam_ed *device;
2444 struct ccb_dev_advinfo *cdai;
2447 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2448 device = start_ccb->ccb_h.path->device;
2449 cdai = &start_ccb->cdai;
2450 switch(cdai->buftype) {
2451 case CDAI_TYPE_SCSI_DEVID:
2452 if (cdai->flags & CDAI_FLAG_STORE)
2454 cdai->provsiz = device->device_id_len;
2455 if (device->device_id_len == 0)
2457 amt = device->device_id_len;
2458 if (cdai->provsiz > cdai->bufsiz)
2460 memcpy(cdai->buf, device->device_id, amt);
2462 case CDAI_TYPE_SERIAL_NUM:
2463 if (cdai->flags & CDAI_FLAG_STORE)
2465 cdai->provsiz = device->serial_num_len;
2466 if (device->serial_num_len == 0)
2468 amt = device->serial_num_len;
2469 if (cdai->provsiz > cdai->bufsiz)
2471 memcpy(cdai->buf, device->serial_num, amt);
2473 case CDAI_TYPE_PHYS_PATH:
2474 if (cdai->flags & CDAI_FLAG_STORE) {
2475 if (device->physpath != NULL) {
2476 free(device->physpath, M_CAMXPT);
2477 device->physpath = NULL;
2479 device->physpath_len = cdai->bufsiz;
2480 /* Clear existing buffer if zero length */
2481 if (cdai->bufsiz == 0)
2483 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2484 if (device->physpath == NULL) {
2485 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2488 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2490 cdai->provsiz = device->physpath_len;
2491 if (device->physpath_len == 0)
2493 amt = device->physpath_len;
2494 if (cdai->provsiz > cdai->bufsiz)
2496 memcpy(cdai->buf, device->physpath, amt);
2499 case CDAI_TYPE_RCAPLONG:
2500 if (cdai->flags & CDAI_FLAG_STORE) {
2501 if (device->rcap_buf != NULL) {
2502 free(device->rcap_buf, M_CAMXPT);
2503 device->rcap_buf = NULL;
2506 device->rcap_len = cdai->bufsiz;
2507 /* Clear existing buffer if zero length */
2508 if (cdai->bufsiz == 0)
2511 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2513 if (device->rcap_buf == NULL) {
2514 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2518 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2520 cdai->provsiz = device->rcap_len;
2521 if (device->rcap_len == 0)
2523 amt = device->rcap_len;
2524 if (cdai->provsiz > cdai->bufsiz)
2526 memcpy(cdai->buf, device->rcap_buf, amt);
2532 start_ccb->ccb_h.status = CAM_REQ_CMP;
2534 if (cdai->flags & CDAI_FLAG_STORE) {
2535 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2536 (void *)(uintptr_t)cdai->buftype);
2541 scsi_action(union ccb *start_ccb)
2544 switch (start_ccb->ccb_h.func_code) {
2545 case XPT_SET_TRAN_SETTINGS:
2547 scsi_set_transfer_settings(&start_ccb->cts,
2548 start_ccb->ccb_h.path,
2549 /*async_update*/FALSE);
2554 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2557 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2558 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2561 case XPT_DEV_ADVINFO:
2563 scsi_dev_advinfo(start_ccb);
2567 xpt_action_default(start_ccb);
2573 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2576 struct ccb_pathinq cpi;
2577 struct ccb_trans_settings cur_cts;
2578 struct ccb_trans_settings_scsi *scsi;
2579 struct ccb_trans_settings_scsi *cur_scsi;
2580 struct scsi_inquiry_data *inq_data;
2581 struct cam_ed *device;
2583 if (path == NULL || (device = path->device) == NULL) {
2584 cts->ccb_h.status = CAM_PATH_INVALID;
2585 xpt_done((union ccb *)cts);
2589 if (cts->protocol == PROTO_UNKNOWN
2590 || cts->protocol == PROTO_UNSPECIFIED) {
2591 cts->protocol = device->protocol;
2592 cts->protocol_version = device->protocol_version;
2595 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2596 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2597 cts->protocol_version = device->protocol_version;
2599 if (cts->protocol != device->protocol) {
2600 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2601 cts->protocol, device->protocol);
2602 cts->protocol = device->protocol;
2605 if (cts->protocol_version > device->protocol_version) {
2607 xpt_print(path, "Down reving Protocol "
2608 "Version from %d to %d?\n", cts->protocol_version,
2609 device->protocol_version);
2611 cts->protocol_version = device->protocol_version;
2614 if (cts->transport == XPORT_UNKNOWN
2615 || cts->transport == XPORT_UNSPECIFIED) {
2616 cts->transport = device->transport;
2617 cts->transport_version = device->transport_version;
2620 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2621 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2622 cts->transport_version = device->transport_version;
2624 if (cts->transport != device->transport) {
2625 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2626 cts->transport, device->transport);
2627 cts->transport = device->transport;
2630 if (cts->transport_version > device->transport_version) {
2632 xpt_print(path, "Down reving Transport "
2633 "Version from %d to %d?\n", cts->transport_version,
2634 device->transport_version);
2636 cts->transport_version = device->transport_version;
2640 * Nothing more of interest to do unless
2641 * this is a device connected via the
2644 if (cts->protocol != PROTO_SCSI) {
2645 if (async_update == FALSE)
2646 xpt_action_default((union ccb *)cts);
2650 inq_data = &device->inq_data;
2651 scsi = &cts->proto_specific.scsi;
2652 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2653 cpi.ccb_h.func_code = XPT_PATH_INQ;
2654 xpt_action((union ccb *)&cpi);
2656 /* SCSI specific sanity checking */
2657 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2658 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2659 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2660 || (device->mintags == 0)) {
2662 * Can't tag on hardware that doesn't support tags,
2663 * doesn't have it enabled, or has broken tag support.
2665 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2668 if (async_update == FALSE) {
2670 * Perform sanity checking against what the
2671 * controller and device can do.
2673 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2674 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2675 cur_cts.type = cts->type;
2676 xpt_action((union ccb *)&cur_cts);
2677 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2680 cur_scsi = &cur_cts.proto_specific.scsi;
2681 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2682 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2683 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2685 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2686 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2689 /* SPI specific sanity checking */
2690 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2692 struct ccb_trans_settings_spi *spi;
2693 struct ccb_trans_settings_spi *cur_spi;
2695 spi = &cts->xport_specific.spi;
2697 cur_spi = &cur_cts.xport_specific.spi;
2699 /* Fill in any gaps in what the user gave us */
2700 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2701 spi->sync_period = cur_spi->sync_period;
2702 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2703 spi->sync_period = 0;
2704 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2705 spi->sync_offset = cur_spi->sync_offset;
2706 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2707 spi->sync_offset = 0;
2708 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2709 spi->ppr_options = cur_spi->ppr_options;
2710 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2711 spi->ppr_options = 0;
2712 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2713 spi->bus_width = cur_spi->bus_width;
2714 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2716 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2717 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2718 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2720 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2721 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2722 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2723 && (inq_data->flags & SID_Sync) == 0
2724 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2725 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2727 spi->sync_period = 0;
2728 spi->sync_offset = 0;
2731 switch (spi->bus_width) {
2732 case MSG_EXT_WDTR_BUS_32_BIT:
2733 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2734 || (inq_data->flags & SID_WBus32) != 0
2735 || cts->type == CTS_TYPE_USER_SETTINGS)
2736 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2738 /* Fall Through to 16-bit */
2739 case MSG_EXT_WDTR_BUS_16_BIT:
2740 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2741 || (inq_data->flags & SID_WBus16) != 0
2742 || cts->type == CTS_TYPE_USER_SETTINGS)
2743 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2744 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2747 /* Fall Through to 8-bit */
2748 default: /* New bus width?? */
2749 case MSG_EXT_WDTR_BUS_8_BIT:
2750 /* All targets can do this */
2751 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2755 spi3caps = cpi.xport_specific.spi.ppr_options;
2756 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2757 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2758 spi3caps &= inq_data->spi3data;
2760 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2761 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2763 if ((spi3caps & SID_SPI_IUS) == 0)
2764 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2766 if ((spi3caps & SID_SPI_QAS) == 0)
2767 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2769 /* No SPI Transfer settings are allowed unless we are wide */
2770 if (spi->bus_width == 0)
2771 spi->ppr_options = 0;
2773 if ((spi->valid & CTS_SPI_VALID_DISC)
2774 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2776 * Can't tag queue without disconnection.
2778 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2779 scsi->valid |= CTS_SCSI_VALID_TQ;
2783 * If we are currently performing tagged transactions to
2784 * this device and want to change its negotiation parameters,
2785 * go non-tagged for a bit to give the controller a chance to
2786 * negotiate unhampered by tag messages.
2788 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2789 && (device->inq_flags & SID_CmdQue) != 0
2790 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2791 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2792 CTS_SPI_VALID_SYNC_OFFSET|
2793 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2794 scsi_toggle_tags(path);
2797 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2798 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2802 * If we are transitioning from tags to no-tags or
2803 * vice-versa, we need to carefully freeze and restart
2804 * the queue so that we don't overlap tagged and non-tagged
2805 * commands. We also temporarily stop tags if there is
2806 * a change in transfer negotiation settings to allow
2807 * "tag-less" negotiation.
2809 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2810 || (device->inq_flags & SID_CmdQue) != 0)
2811 device_tagenb = TRUE;
2813 device_tagenb = FALSE;
2815 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2816 && device_tagenb == FALSE)
2817 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2818 && device_tagenb == TRUE)) {
2820 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2822 * Delay change to use tags until after a
2823 * few commands have gone to this device so
2824 * the controller has time to perform transfer
2825 * negotiations without tagged messages getting
2828 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2829 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2831 xpt_stop_tags(path);
2835 if (async_update == FALSE)
2836 xpt_action_default((union ccb *)cts);
2840 scsi_toggle_tags(struct cam_path *path)
2845 * Give controllers a chance to renegotiate
2846 * before starting tag operations. We
2847 * "toggle" tagged queuing off then on
2848 * which causes the tag enable command delay
2849 * counter to come into effect.
2852 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2853 || ((dev->inq_flags & SID_CmdQue) != 0
2854 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2855 struct ccb_trans_settings cts;
2857 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2858 cts.protocol = PROTO_SCSI;
2859 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2860 cts.transport = XPORT_UNSPECIFIED;
2861 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2862 cts.proto_specific.scsi.flags = 0;
2863 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2864 scsi_set_transfer_settings(&cts, path,
2865 /*async_update*/TRUE);
2866 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2867 scsi_set_transfer_settings(&cts, path,
2868 /*async_update*/TRUE);
2873 * Handle any per-device event notifications that require action by the XPT.
2876 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2877 struct cam_ed *device, void *async_arg)
2880 struct cam_path newpath;
2883 * We only need to handle events for real devices.
2885 if (target->target_id == CAM_TARGET_WILDCARD
2886 || device->lun_id == CAM_LUN_WILDCARD)
2890 * We need our own path with wildcards expanded to
2891 * handle certain types of events.
2893 if ((async_code == AC_SENT_BDR)
2894 || (async_code == AC_BUS_RESET)
2895 || (async_code == AC_INQ_CHANGED))
2896 status = xpt_compile_path(&newpath, NULL,
2901 status = CAM_REQ_CMP_ERR;
2903 if (status == CAM_REQ_CMP) {
2906 * Allow transfer negotiation to occur in a
2907 * tag free environment and after settle delay.
2909 if (async_code == AC_SENT_BDR
2910 || async_code == AC_BUS_RESET) {
2911 cam_freeze_devq(&newpath);
2912 cam_release_devq(&newpath,
2913 RELSIM_RELEASE_AFTER_TIMEOUT,
2915 /*timeout*/scsi_delay,
2916 /*getcount_only*/0);
2917 scsi_toggle_tags(&newpath);
2920 if (async_code == AC_INQ_CHANGED) {
2922 * We've sent a start unit command, or
2923 * something similar to a device that
2924 * may have caused its inquiry data to
2925 * change. So we re-scan the device to
2926 * refresh the inquiry data for it.
2928 scsi_scan_lun(newpath.periph, &newpath,
2929 CAM_EXPECT_INQ_CHANGE, NULL);
2931 xpt_release_path(&newpath);
2932 } else if (async_code == AC_LOST_DEVICE &&
2933 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2934 device->flags |= CAM_DEV_UNCONFIGURED;
2935 xpt_release_device(device);
2936 } else if (async_code == AC_TRANSFER_NEG) {
2937 struct ccb_trans_settings *settings;
2938 struct cam_path path;
2940 settings = (struct ccb_trans_settings *)async_arg;
2941 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2943 scsi_set_transfer_settings(settings, &path,
2944 /*async_update*/TRUE);
2945 xpt_release_path(&path);
2950 scsi_announce_periph(struct cam_periph *periph)
2952 struct ccb_pathinq cpi;
2953 struct ccb_trans_settings cts;
2954 struct cam_path *path = periph->path;
2959 cam_periph_assert(periph, MA_OWNED);
2961 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2962 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2963 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2964 xpt_action((union ccb*)&cts);
2965 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
2967 /* Ask the SIM for its base transfer speed */
2968 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2969 cpi.ccb_h.func_code = XPT_PATH_INQ;
2970 xpt_action((union ccb *)&cpi);
2971 /* Report connection speed */
2972 speed = cpi.base_transfer_speed;
2974 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2975 struct ccb_trans_settings_spi *spi =
2976 &cts.xport_specific.spi;
2978 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2979 && spi->sync_offset != 0) {
2980 freq = scsi_calc_syncsrate(spi->sync_period);
2983 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2984 speed *= (0x01 << spi->bus_width);
2986 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2987 struct ccb_trans_settings_fc *fc =
2988 &cts.xport_specific.fc;
2990 if (fc->valid & CTS_FC_VALID_SPEED)
2991 speed = fc->bitrate;
2993 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2994 struct ccb_trans_settings_sas *sas =
2995 &cts.xport_specific.sas;
2997 if (sas->valid & CTS_SAS_VALID_SPEED)
2998 speed = sas->bitrate;
3002 printf("%s%d: %d.%03dMB/s transfers",
3003 periph->periph_name, periph->unit_number,
3006 printf("%s%d: %dKB/s transfers", periph->periph_name,
3007 periph->unit_number, speed);
3008 /* Report additional information about SPI connections */
3009 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3010 struct ccb_trans_settings_spi *spi;
3012 spi = &cts.xport_specific.spi;
3014 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3016 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3020 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3021 && spi->bus_width > 0) {
3027 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3028 } else if (freq != 0) {
3032 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3033 struct ccb_trans_settings_fc *fc;
3035 fc = &cts.xport_specific.fc;
3036 if (fc->valid & CTS_FC_VALID_WWNN)
3037 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3038 if (fc->valid & CTS_FC_VALID_WWPN)
3039 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3040 if (fc->valid & CTS_FC_VALID_PORT)
3041 printf(" PortID 0x%x", fc->port);