2 * Implementation of the SCSI Transport
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/types.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
41 #include <sys/fcntl.h>
43 #include <sys/interrupt.h>
47 #include <sys/mutex.h>
48 #include <sys/sysctl.h>
51 #include <cam/cam_ccb.h>
52 #include <cam/cam_queue.h>
53 #include <cam/cam_periph.h>
54 #include <cam/cam_sim.h>
55 #include <cam/cam_xpt.h>
56 #include <cam/cam_xpt_sim.h>
57 #include <cam/cam_xpt_periph.h>
58 #include <cam/cam_xpt_internal.h>
59 #include <cam/cam_debug.h>
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/scsi/scsi_message.h>
63 #include <cam/scsi/scsi_pass.h>
64 #include <machine/stdarg.h> /* for xpt_print below */
67 struct scsi_quirk_entry {
68 struct scsi_inquiry_pattern inq_pat;
70 #define CAM_QUIRK_NOLUNS 0x01
71 #define CAM_QUIRK_NOSERIAL 0x02
72 #define CAM_QUIRK_HILUNS 0x04
73 #define CAM_QUIRK_NOHILUNS 0x08
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,
139 PROBE_TUR_FOR_NEGOTIATION,
140 PROBE_INQUIRY_BASIC_DV1,
141 PROBE_INQUIRY_BASIC_DV2,
147 static char *probe_action_text[] = {
150 "PROBE_FULL_INQUIRY",
153 "PROBE_SUPPORTED_VPD_LIST",
155 "PROBE_TUR_FOR_NEGOTIATION",
156 "PROBE_INQUIRY_BASIC_DV1",
157 "PROBE_INQUIRY_BASIC_DV2",
163 #define PROBE_SET_ACTION(softc, newaction) \
166 text = probe_action_text; \
167 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
168 ("Probe %s to %s\n", text[(softc)->action], \
169 text[(newaction)])); \
170 (softc)->action = (newaction); \
174 PROBE_INQUIRY_CKSUM = 0x01,
175 PROBE_SERIAL_CKSUM = 0x02,
176 PROBE_NO_ANNOUNCE = 0x04
180 TAILQ_HEAD(, ccb_hdr) request_ccbs;
186 struct cam_periph *periph;
189 static const char quantum[] = "QUANTUM";
190 static const char sony[] = "SONY";
191 static const char west_digital[] = "WDIGTL";
192 static const char samsung[] = "SAMSUNG";
193 static const char seagate[] = "SEAGATE";
194 static const char microp[] = "MICROP";
196 static struct scsi_quirk_entry scsi_quirk_table[] =
199 /* Reports QUEUE FULL for temporary resource shortages */
200 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
201 /*quirks*/0, /*mintags*/24, /*maxtags*/32
204 /* Reports QUEUE FULL for temporary resource shortages */
205 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
206 /*quirks*/0, /*mintags*/24, /*maxtags*/32
209 /* Reports QUEUE FULL for temporary resource shortages */
210 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
211 /*quirks*/0, /*mintags*/24, /*maxtags*/32
214 /* Broken tagged queuing drive */
215 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
216 /*quirks*/0, /*mintags*/0, /*maxtags*/0
219 /* Broken tagged queuing drive */
220 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
221 /*quirks*/0, /*mintags*/0, /*maxtags*/0
224 /* Broken tagged queuing drive */
225 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
226 /*quirks*/0, /*mintags*/0, /*maxtags*/0
230 * Unfortunately, the Quantum Atlas III has the same
231 * problem as the Atlas II drives above.
232 * Reported by: "Johan Granlund" <johan@granlund.nu>
234 * For future reference, the drive with the problem was:
235 * QUANTUM QM39100TD-SW N1B0
237 * It's possible that Quantum will fix the problem in later
238 * firmware revisions. If that happens, the quirk entry
239 * will need to be made specific to the firmware revisions
243 /* Reports QUEUE FULL for temporary resource shortages */
244 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
245 /*quirks*/0, /*mintags*/24, /*maxtags*/32
249 * 18 Gig Atlas III, same problem as the 9G version.
250 * Reported by: Andre Albsmeier
251 * <andre.albsmeier@mchp.siemens.de>
253 * For future reference, the drive with the problem was:
254 * QUANTUM QM318000TD-S N491
256 /* Reports QUEUE FULL for temporary resource shortages */
257 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
258 /*quirks*/0, /*mintags*/24, /*maxtags*/32
262 * Broken tagged queuing drive
263 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
264 * and: Martin Renters <martin@tdc.on.ca>
266 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
267 /*quirks*/0, /*mintags*/0, /*maxtags*/0
270 * The Seagate Medalist Pro drives have very poor write
271 * performance with anything more than 2 tags.
273 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
274 * Drive: <SEAGATE ST36530N 1444>
276 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
277 * Drive: <SEAGATE ST34520W 1281>
279 * No one has actually reported that the 9G version
280 * (ST39140*) of the Medalist Pro has the same problem, but
281 * we're assuming that it does because the 4G and 6.5G
282 * versions of the drive are broken.
285 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
286 /*quirks*/0, /*mintags*/2, /*maxtags*/2
289 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
290 /*quirks*/0, /*mintags*/2, /*maxtags*/2
293 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
294 /*quirks*/0, /*mintags*/2, /*maxtags*/2
298 * Experiences command timeouts under load with a
299 * tag count higher than 55.
301 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
302 /*quirks*/0, /*mintags*/2, /*maxtags*/55
306 * Slow when tagged queueing is enabled. Write performance
307 * steadily drops off with more and more concurrent
308 * transactions. Best sequential write performance with
309 * tagged queueing turned off and write caching turned on.
312 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
313 * Drive: DCAS-34330 w/ "S65A" firmware.
315 * The drive with the problem had the "S65A" firmware
316 * revision, and has also been reported (by Stephen J.
317 * Roznowski <sjr@home.net>) for a drive with the "S61A"
320 * Although no one has reported problems with the 2 gig
321 * version of the DCAS drive, the assumption is that it
322 * has the same problems as the 4 gig version. Therefore
323 * this quirk entries disables tagged queueing for all
326 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
327 /*quirks*/0, /*mintags*/0, /*maxtags*/0
330 /* Broken tagged queuing drive */
331 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
332 /*quirks*/0, /*mintags*/0, /*maxtags*/0
335 /* Broken tagged queuing drive */
336 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
337 /*quirks*/0, /*mintags*/0, /*maxtags*/0
340 /* This does not support other than LUN 0 */
341 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
342 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
346 * Broken tagged queuing drive.
348 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
351 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
352 /*quirks*/0, /*mintags*/0, /*maxtags*/0
356 * Slow when tagged queueing is enabled. (1.5MB/sec versus
358 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
359 * Best performance with these drives is achieved with
360 * tagged queueing turned off, and write caching turned on.
362 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
363 /*quirks*/0, /*mintags*/0, /*maxtags*/0
367 * Slow when tagged queueing is enabled. (1.5MB/sec versus
369 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
370 * Best performance with these drives is achieved with
371 * tagged queueing turned off, and write caching turned on.
373 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
374 /*quirks*/0, /*mintags*/0, /*maxtags*/0
378 * Doesn't handle queue full condition correctly,
379 * so we need to limit maxtags to what the device
380 * can handle instead of determining this automatically.
382 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
383 /*quirks*/0, /*mintags*/2, /*maxtags*/32
386 /* Really only one LUN */
387 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
388 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
391 /* I can't believe we need a quirk for DPT volumes. */
392 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
394 /*mintags*/0, /*maxtags*/255
398 * Many Sony CDROM drives don't like multi-LUN probing.
400 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
401 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
405 * This drive doesn't like multiple LUN probing.
406 * Submitted by: Parag Patel <parag@cgt.com>
408 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
409 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
412 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
413 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
417 * The 8200 doesn't like multi-lun probing, and probably
418 * don't like serial number requests either.
421 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
424 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
428 * Let's try the same as above, but for a drive that says
429 * it's an IPL-6860 but is actually an EXB 8200.
432 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
435 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
439 * These Hitachi drives don't like multi-lun probing.
440 * The PR submitter has a DK319H, but says that the Linux
441 * kernel has a similar work-around for the DK312 and DK314,
442 * so all DK31* drives are quirked here.
444 * Submitted by: Paul Haddad <paul@pth.com>
446 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
447 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
451 * The Hitachi CJ series with J8A8 firmware apparantly has
452 * problems with tagged commands.
454 * Reported by: amagai@nue.org
456 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
457 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
461 * These are the large storage arrays.
462 * Submitted by: William Carrel <william.carrel@infospace.com>
464 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
465 CAM_QUIRK_HILUNS, 2, 1024
469 * This old revision of the TDC3600 is also SCSI-1, and
470 * hangs upon serial number probing.
473 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
476 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
480 * Would repond to all LUNs if asked for.
483 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
486 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
490 * Would repond to all LUNs if asked for.
493 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
496 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
499 /* Submitted by: Matthew Dodd <winter@jurai.net> */
500 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
501 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
504 /* Submitted by: Matthew Dodd <winter@jurai.net> */
505 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
506 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
509 /* TeraSolutions special settings for TRC-22 RAID */
510 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
511 /*quirks*/0, /*mintags*/55, /*maxtags*/255
514 /* Veritas Storage Appliance */
515 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
516 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
520 * Would respond to all LUNs. Device type and removable
521 * flag are jumper-selectable.
523 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
526 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
529 /* EasyRAID E5A aka. areca ARC-6010 */
530 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
531 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
534 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
535 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
538 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
539 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
542 /* Default tagged queuing parameters for all devices */
544 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
545 /*vendor*/"*", /*product*/"*", /*revision*/"*"
547 /*quirks*/0, /*mintags*/2, /*maxtags*/255
551 static const int scsi_quirk_table_size =
552 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
554 static cam_status proberegister(struct cam_periph *periph,
556 static void probeschedule(struct cam_periph *probe_periph);
557 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
558 static void proberequestdefaultnegotiation(struct cam_periph *periph);
559 static int proberequestbackoff(struct cam_periph *periph,
560 struct cam_ed *device);
561 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
562 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
564 static void probe_purge_old(struct cam_path *path,
565 struct scsi_report_luns_data *new);
566 static void probecleanup(struct cam_periph *periph);
567 static void scsi_find_quirk(struct cam_ed *device);
568 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
569 static void scsi_scan_lun(struct cam_periph *periph,
570 struct cam_path *path, cam_flags flags,
572 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
573 static struct cam_ed *
574 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
576 static void scsi_devise_transport(struct cam_path *path);
577 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
578 struct cam_ed *device,
580 static void scsi_toggle_tags(struct cam_path *path);
581 static void scsi_dev_async(u_int32_t async_code,
583 struct cam_et *target,
584 struct cam_ed *device,
586 static void scsi_action(union ccb *start_ccb);
587 static void scsi_announce_periph(struct cam_periph *periph);
589 static struct xpt_xport scsi_xport = {
590 .alloc_device = scsi_alloc_device,
591 .action = scsi_action,
592 .async = scsi_dev_async,
593 .announce = scsi_announce_periph,
599 return (&scsi_xport);
608 proberegister(struct cam_periph *periph, void *arg)
610 union ccb *request_ccb; /* CCB representing the probe request */
614 request_ccb = (union ccb *)arg;
615 if (periph == NULL) {
616 printf("proberegister: periph was NULL!!\n");
617 return(CAM_REQ_CMP_ERR);
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"));
647 * Ensure we've waited at least a bus settle
648 * delay before attempting to probe the device.
649 * For HBAs that don't do bus resets, this won't make a difference.
651 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
654 * Ensure nobody slip in until probe finish.
656 cam_freeze_devq_arg(periph->path,
657 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
658 probeschedule(periph);
663 probeschedule(struct cam_periph *periph)
665 struct ccb_pathinq cpi;
669 softc = (probe_softc *)periph->softc;
670 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
672 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
673 cpi.ccb_h.func_code = XPT_PATH_INQ;
674 xpt_action((union ccb *)&cpi);
677 * If a device has gone away and another device, or the same one,
678 * is back in the same place, it should have a unit attention
679 * condition pending. It will not report the unit attention in
680 * response to an inquiry, which may leave invalid transfer
681 * negotiations in effect. The TUR will reveal the unit attention
682 * condition. Only send the TUR for lun 0, since some devices
683 * will get confused by commands other than inquiry to non-existent
684 * luns. If you think a device has gone away start your scan from
685 * lun 0. This will insure that any bogus transfer settings are
688 * If we haven't seen the device before and the controller supports
689 * some kind of transfer negotiation, negotiate with the first
690 * sent command if no bus reset was performed at startup. This
691 * ensures that the device is not confused by transfer negotiation
692 * settings left over by loader or BIOS action.
694 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
695 && (ccb->ccb_h.target_lun == 0)) {
696 PROBE_SET_ACTION(softc, PROBE_TUR);
697 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
698 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
699 proberequestdefaultnegotiation(periph);
700 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
702 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
705 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
706 softc->flags |= PROBE_NO_ANNOUNCE;
708 softc->flags &= ~PROBE_NO_ANNOUNCE;
710 xpt_schedule(periph, CAM_PRIORITY_XPT);
714 probestart(struct cam_periph *periph, union ccb *start_ccb)
716 /* Probe the device that our peripheral driver points to */
717 struct ccb_scsiio *csio;
720 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
722 softc = (probe_softc *)periph->softc;
723 csio = &start_ccb->csio;
726 switch (softc->action) {
728 case PROBE_TUR_FOR_NEGOTIATION:
731 scsi_test_unit_ready(csio,
740 case PROBE_FULL_INQUIRY:
741 case PROBE_INQUIRY_BASIC_DV1:
742 case PROBE_INQUIRY_BASIC_DV2:
745 struct scsi_inquiry_data *inq_buf;
747 inq_buf = &periph->path->device->inq_data;
750 * If the device is currently configured, we calculate an
751 * MD5 checksum of the inquiry data, and if the serial number
752 * length is greater than 0, add the serial number data
753 * into the checksum as well. Once the inquiry and the
754 * serial number check finish, we attempt to figure out
755 * whether we still have the same device.
757 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
759 MD5Init(&softc->context);
760 MD5Update(&softc->context, (unsigned char *)inq_buf,
761 sizeof(struct scsi_inquiry_data));
762 softc->flags |= PROBE_INQUIRY_CKSUM;
763 if (periph->path->device->serial_num_len > 0) {
764 MD5Update(&softc->context,
765 periph->path->device->serial_num,
766 periph->path->device->serial_num_len);
767 softc->flags |= PROBE_SERIAL_CKSUM;
769 MD5Final(softc->digest, &softc->context);
772 if (softc->action == PROBE_INQUIRY)
773 inquiry_len = SHORT_INQUIRY_LENGTH;
775 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
778 * Some parallel SCSI devices fail to send an
779 * ignore wide residue message when dealing with
780 * odd length inquiry requests. Round up to be
783 inquiry_len = roundup2(inquiry_len, 2);
785 if (softc->action == PROBE_INQUIRY_BASIC_DV1
786 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
787 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
789 if (inq_buf == NULL) {
790 xpt_print(periph->path, "malloc failure- skipping Basic"
791 "Domain Validation\n");
792 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
793 scsi_test_unit_ready(csio,
810 /*timeout*/60 * 1000);
813 case PROBE_REPORT_LUNS:
817 rp = malloc(periph->path->target->rpl_size,
818 M_CAMXPT, M_NOWAIT | M_ZERO);
820 struct scsi_inquiry_data *inq_buf;
821 inq_buf = &periph->path->device->inq_data;
822 xpt_print(periph->path,
823 "Unable to alloc report luns storage\n");
824 if (INQ_DATA_TQ_ENABLED(inq_buf))
825 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
827 PROBE_SET_ACTION(softc,
828 PROBE_SUPPORTED_VPD_LIST);
831 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
832 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
833 SSD_FULL_SIZE, 60000); break;
836 case PROBE_MODE_SENSE:
841 mode_buf_len = sizeof(struct scsi_mode_header_6)
842 + sizeof(struct scsi_mode_blk_desc)
843 + sizeof(struct scsi_control_page);
844 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
845 if (mode_buf != NULL) {
846 scsi_mode_sense(csio,
851 SMS_PAGE_CTRL_CURRENT,
852 SMS_CONTROL_MODE_PAGE,
859 xpt_print(periph->path, "Unable to mode sense control page - "
861 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
864 case PROBE_SUPPORTED_VPD_LIST:
866 struct scsi_vpd_supported_page_list *vpd_list = NULL;
867 struct cam_ed *device;
869 device = periph->path->device;
870 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOSERIAL) == 0) {
871 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
875 if (vpd_list != NULL) {
880 (u_int8_t *)vpd_list,
883 SVPD_SUPPORTED_PAGE_LIST,
885 /*timeout*/60 * 1000);
889 * We'll have to do without, let our probedone
890 * routine finish up for us.
892 start_ccb->csio.data_ptr = NULL;
893 probedone(periph, start_ccb);
896 case PROBE_SERIAL_NUM:
898 struct scsi_vpd_unit_serial_number *serial_buf;
899 struct cam_ed* device;
902 device = periph->path->device;
903 if (device->serial_num != NULL) {
904 free(device->serial_num, M_CAMXPT);
905 device->serial_num = NULL;
906 device->serial_num_len = 0;
909 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
910 serial_buf = (struct scsi_vpd_unit_serial_number *)
911 malloc(sizeof(*serial_buf), M_CAMXPT,
914 if (serial_buf != NULL) {
919 (u_int8_t *)serial_buf,
922 SVPD_UNIT_SERIAL_NUMBER,
924 /*timeout*/60 * 1000);
928 * We'll have to do without, let our probedone
929 * routine finish up for us.
931 start_ccb->csio.data_ptr = NULL;
932 probedone(periph, start_ccb);
936 panic("probestart: invalid action state 0x%x\n", softc->action);
938 xpt_action(start_ccb);
942 proberequestdefaultnegotiation(struct cam_periph *periph)
944 struct ccb_trans_settings cts;
946 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
947 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
948 cts.type = CTS_TYPE_USER_SETTINGS;
949 xpt_action((union ccb *)&cts);
950 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
953 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
954 cts.type = CTS_TYPE_CURRENT_SETTINGS;
955 xpt_action((union ccb *)&cts);
959 * Backoff Negotiation Code- only pertinent for SPI devices.
962 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
964 struct ccb_trans_settings cts;
965 struct ccb_trans_settings_spi *spi;
967 memset(&cts, 0, sizeof (cts));
968 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
969 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
970 cts.type = CTS_TYPE_CURRENT_SETTINGS;
971 xpt_action((union ccb *)&cts);
972 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
974 xpt_print(periph->path,
975 "failed to get current device settings\n");
979 if (cts.transport != XPORT_SPI) {
981 xpt_print(periph->path, "not SPI transport\n");
985 spi = &cts.xport_specific.spi;
988 * We cannot renegotiate sync rate if we don't have one.
990 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
992 xpt_print(periph->path, "no sync rate known\n");
998 * We'll assert that we don't have to touch PPR options- the
999 * SIM will see what we do with period and offset and adjust
1000 * the PPR options as appropriate.
1004 * A sync rate with unknown or zero offset is nonsensical.
1005 * A sync period of zero means Async.
1007 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1008 || spi->sync_offset == 0 || spi->sync_period == 0) {
1010 xpt_print(periph->path, "no sync rate available\n");
1015 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1016 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1017 ("hit async: giving up on DV\n"));
1023 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1024 * We don't try to remember 'last' settings to see if the SIM actually
1025 * gets into the speed we want to set. We check on the SIM telling
1026 * us that a requested speed is bad, but otherwise don't try and
1027 * check the speed due to the asynchronous and handshake nature
1030 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1033 if (spi->sync_period >= 0xf) {
1034 spi->sync_period = 0;
1035 spi->sync_offset = 0;
1036 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1037 ("setting to async for DV\n"));
1039 * Once we hit async, we don't want to try
1040 * any more settings.
1042 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1043 } else if (bootverbose) {
1044 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1045 ("DV: period 0x%x\n", spi->sync_period));
1046 printf("setting period to 0x%x\n", spi->sync_period);
1048 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1049 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1050 xpt_action((union ccb *)&cts);
1051 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1054 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1055 ("DV: failed to set period 0x%x\n", spi->sync_period));
1056 if (spi->sync_period == 0) {
1064 probedone(struct cam_periph *periph, union ccb *done_ccb)
1067 struct cam_path *path;
1070 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1072 softc = (probe_softc *)periph->softc;
1073 path = done_ccb->ccb_h.path;
1074 priority = done_ccb->ccb_h.pinfo.priority;
1076 switch (softc->action) {
1079 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1081 if (cam_periph_error(done_ccb, 0,
1082 SF_NO_PRINT, NULL) == ERESTART)
1084 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1085 /* Don't wedge the queue */
1086 xpt_release_devq(done_ccb->ccb_h.path,
1090 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1091 xpt_release_ccb(done_ccb);
1092 xpt_schedule(periph, priority);
1096 case PROBE_FULL_INQUIRY:
1098 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1099 struct scsi_inquiry_data *inq_buf;
1100 u_int8_t periph_qual;
1102 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1103 inq_buf = &path->device->inq_data;
1105 periph_qual = SID_QUAL(inq_buf);
1107 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1111 * We conservatively request only
1112 * SHORT_INQUIRY_LEN bytes of inquiry
1113 * information during our first try
1114 * at sending an INQUIRY. If the device
1115 * has more information to give,
1116 * perform a second request specifying
1117 * the amount of information the device
1118 * is willing to give.
1120 len = inq_buf->additional_length
1121 + offsetof(struct scsi_inquiry_data,
1122 additional_length) + 1;
1123 if (softc->action == PROBE_INQUIRY
1124 && len > SHORT_INQUIRY_LENGTH) {
1125 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1126 xpt_release_ccb(done_ccb);
1127 xpt_schedule(periph, priority);
1131 scsi_find_quirk(path->device);
1133 scsi_devise_transport(path);
1135 if (path->device->lun_id == 0 &&
1136 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1137 (SCSI_QUIRK(path->device)->quirks &
1138 CAM_QUIRK_NORPTLUNS) == 0) {
1139 PROBE_SET_ACTION(softc,
1142 * Start with room for *one* lun.
1144 periph->path->target->rpl_size = 16;
1145 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1146 PROBE_SET_ACTION(softc,
1149 PROBE_SET_ACTION(softc,
1150 PROBE_SUPPORTED_VPD_LIST);
1152 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1153 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1154 xpt_acquire_device(path->device);
1156 xpt_release_ccb(done_ccb);
1157 xpt_schedule(periph, priority);
1159 } else if (path->device->lun_id == 0 &&
1160 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1161 (SCSI_QUIRK(path->device)->quirks &
1162 CAM_QUIRK_NORPTLUNS) == 0) {
1163 if (path->device->flags &
1164 CAM_DEV_UNCONFIGURED) {
1165 path->device->flags &=
1166 ~CAM_DEV_UNCONFIGURED;
1167 xpt_acquire_device(path->device);
1169 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1170 periph->path->target->rpl_size = 16;
1171 xpt_release_ccb(done_ccb);
1172 xpt_schedule(periph, priority);
1175 } else if (cam_periph_error(done_ccb, 0,
1176 done_ccb->ccb_h.target_lun > 0
1177 ? SF_RETRY_UA|SF_QUIET_IR
1179 &softc->saved_ccb) == ERESTART) {
1181 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1182 /* Don't wedge the queue */
1183 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1187 * If we get to this point, we got an error status back
1188 * from the inquiry and the error status doesn't require
1189 * automatically retrying the command. Therefore, the
1190 * inquiry failed. If we had inquiry information before
1191 * for this device, but this latest inquiry command failed,
1192 * the device has probably gone away. If this device isn't
1193 * already marked unconfigured, notify the peripheral
1194 * drivers that this device is no more.
1196 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1197 /* Send the async notification. */
1198 xpt_async(AC_LOST_DEVICE, path, NULL);
1199 PROBE_SET_ACTION(softc, PROBE_INVALID);
1201 xpt_release_ccb(done_ccb);
1204 case PROBE_REPORT_LUNS:
1206 struct ccb_scsiio *csio;
1207 struct scsi_report_luns_data *lp;
1210 csio = &done_ccb->csio;
1212 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1213 nlun = scsi_4btoul(lp->length) / 8;
1214 maxlun = (csio->dxfer_len / 8) - 1;
1216 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1217 if (cam_periph_error(done_ccb, 0,
1218 done_ccb->ccb_h.target_lun > 0 ?
1219 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1220 &softc->saved_ccb) == ERESTART) {
1223 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1224 xpt_release_devq(done_ccb->ccb_h.path, 1,
1229 } else if (nlun > maxlun) {
1231 * Reallocate and retry to cover all luns
1233 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1234 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1237 path->target->rpl_size = (nlun << 3) + 8;
1238 xpt_release_ccb(done_ccb);
1239 xpt_schedule(periph, priority);
1241 } else if (nlun == 0) {
1243 * If there don't appear to be any luns, bail.
1247 } else if (probe_strange_rpl_data(lp, maxlun)) {
1249 * If we can't understand the lun format
1250 * of any entry, bail.
1258 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1259 ("Probe: %u lun(s) reported\n", nlun));
1261 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1263 * If the first lun is not lun 0, then either there
1264 * is no lun 0 in the list, or the list is unsorted.
1267 for (idx = 0; idx < nlun; idx++) {
1268 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1276 lp->luns[0].lundata, 8);
1277 memcpy(lp->luns[0].lundata,
1278 lp->luns[idx].lundata, 8);
1279 memcpy(lp->luns[idx].lundata,
1281 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1282 ("lun 0 in position %u\n", idx));
1285 * There is no lun 0 in our list. Destroy
1286 * the validity of the inquiry data so we
1287 * bail here and now.
1289 path->device->flags &=
1290 ~CAM_DEV_INQUIRY_DATA_VALID;
1294 * If we have an old lun list, We can either
1295 * retest luns that appear to have been dropped,
1296 * or just nuke them. We'll opt for the latter.
1297 * This function will also install the new list
1298 * in the target structure.
1300 probe_purge_old(path, lp);
1303 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1304 struct scsi_inquiry_data *inq_buf;
1305 inq_buf = &path->device->inq_data;
1306 if (INQ_DATA_TQ_ENABLED(inq_buf))
1307 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1309 PROBE_SET_ACTION(softc,
1310 PROBE_SUPPORTED_VPD_LIST);
1311 xpt_release_ccb(done_ccb);
1312 xpt_schedule(periph, priority);
1320 case PROBE_MODE_SENSE:
1322 struct ccb_scsiio *csio;
1323 struct scsi_mode_header_6 *mode_hdr;
1325 csio = &done_ccb->csio;
1326 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1327 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1328 struct scsi_control_page *page;
1331 offset = ((u_int8_t *)&mode_hdr[1])
1332 + mode_hdr->blk_desc_len;
1333 page = (struct scsi_control_page *)offset;
1334 path->device->queue_flags = page->queue_flags;
1335 } else if (cam_periph_error(done_ccb, 0,
1336 SF_RETRY_UA|SF_NO_PRINT,
1337 &softc->saved_ccb) == ERESTART) {
1339 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1340 /* Don't wedge the queue */
1341 xpt_release_devq(done_ccb->ccb_h.path,
1342 /*count*/1, /*run_queue*/TRUE);
1344 xpt_release_ccb(done_ccb);
1345 free(mode_hdr, M_CAMXPT);
1346 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1347 xpt_schedule(periph, priority);
1350 case PROBE_SUPPORTED_VPD_LIST:
1352 struct ccb_scsiio *csio;
1353 struct scsi_vpd_supported_page_list *page_list;
1355 csio = &done_ccb->csio;
1357 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1359 if (path->device->supported_vpds != NULL) {
1360 free(path->device->supported_vpds, M_CAMXPT);
1361 path->device->supported_vpds = NULL;
1362 path->device->supported_vpds_len = 0;
1365 if (page_list == NULL) {
1367 * Don't process the command as it was never sent
1369 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1371 path->device->supported_vpds_len = page_list->length +
1372 SVPD_SUPPORTED_PAGES_HDR_LEN;
1373 path->device->supported_vpds = (uint8_t *)page_list;
1375 xpt_release_ccb(done_ccb);
1376 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1377 xpt_schedule(periph, priority);
1380 } else if (cam_periph_error(done_ccb, 0,
1381 SF_RETRY_UA|SF_NO_PRINT,
1382 &softc->saved_ccb) == ERESTART) {
1384 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1385 /* Don't wedge the queue */
1386 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1390 if (page_list != NULL)
1391 free(page_list, M_CAMXPT);
1393 /* No VPDs available, skip to device check. */
1394 csio->data_ptr = NULL;
1398 case PROBE_SERIAL_NUM:
1400 struct ccb_scsiio *csio;
1401 struct scsi_vpd_unit_serial_number *serial_buf;
1408 csio = &done_ccb->csio;
1409 priority = done_ccb->ccb_h.pinfo.priority;
1411 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1413 /* Clean up from previous instance of this device */
1414 if (path->device->serial_num != NULL) {
1415 free(path->device->serial_num, M_CAMXPT);
1416 path->device->serial_num = NULL;
1417 path->device->serial_num_len = 0;
1420 if (serial_buf == NULL) {
1422 * Don't process the command as it was never sent
1424 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1425 && (serial_buf->length > 0)) {
1428 path->device->serial_num =
1429 (u_int8_t *)malloc((serial_buf->length + 1),
1430 M_CAMXPT, M_NOWAIT);
1431 if (path->device->serial_num != NULL) {
1432 bcopy(serial_buf->serial_num,
1433 path->device->serial_num,
1434 serial_buf->length);
1435 path->device->serial_num_len =
1437 path->device->serial_num[serial_buf->length]
1440 } else if (cam_periph_error(done_ccb, 0,
1441 SF_RETRY_UA|SF_NO_PRINT,
1442 &softc->saved_ccb) == ERESTART) {
1444 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1445 /* Don't wedge the queue */
1446 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1451 * Let's see if we have seen this device before.
1453 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1455 u_int8_t digest[16];
1460 (unsigned char *)&path->device->inq_data,
1461 sizeof(struct scsi_inquiry_data));
1464 MD5Update(&context, serial_buf->serial_num,
1465 serial_buf->length);
1467 MD5Final(digest, &context);
1468 if (bcmp(softc->digest, digest, 16) == 0)
1472 * XXX Do we need to do a TUR in order to ensure
1473 * that the device really hasn't changed???
1476 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1477 xpt_async(AC_LOST_DEVICE, path, NULL);
1479 if (serial_buf != NULL)
1480 free(serial_buf, M_CAMXPT);
1484 * Now that we have all the necessary
1485 * information to safely perform transfer
1486 * negotiations... Controllers don't perform
1487 * any negotiation or tagged queuing until
1488 * after the first XPT_SET_TRAN_SETTINGS ccb is
1489 * received. So, on a new device, just retrieve
1490 * the user settings, and set them as the current
1491 * settings to set the device up.
1493 proberequestdefaultnegotiation(periph);
1494 xpt_release_ccb(done_ccb);
1497 * Perform a TUR to allow the controller to
1498 * perform any necessary transfer negotiation.
1500 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1501 xpt_schedule(periph, priority);
1504 xpt_release_ccb(done_ccb);
1507 case PROBE_TUR_FOR_NEGOTIATION:
1508 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1510 if (cam_periph_error(done_ccb, 0, SF_RETRY_UA,
1516 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1517 /* Don't wedge the queue */
1518 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1522 * Do Domain Validation for lun 0 on devices that claim
1523 * to support Synchronous Transfer modes.
1525 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1526 && done_ccb->ccb_h.target_lun == 0
1527 && (path->device->inq_data.flags & SID_Sync) != 0
1528 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1529 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1530 ("Begin Domain Validation\n"));
1531 path->device->flags |= CAM_DEV_IN_DV;
1532 xpt_release_ccb(done_ccb);
1533 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1534 xpt_schedule(periph, priority);
1537 if (softc->action == PROBE_DV_EXIT) {
1538 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1539 ("Leave Domain Validation\n"));
1541 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1542 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1543 xpt_acquire_device(path->device);
1545 path->device->flags &=
1546 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1547 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1548 /* Inform the XPT that a new device has been found */
1549 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1550 xpt_action(done_ccb);
1551 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1554 PROBE_SET_ACTION(softc, PROBE_DONE);
1555 xpt_release_ccb(done_ccb);
1557 case PROBE_INQUIRY_BASIC_DV1:
1558 case PROBE_INQUIRY_BASIC_DV2:
1560 struct scsi_inquiry_data *nbuf;
1561 struct ccb_scsiio *csio;
1563 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1564 /* Don't wedge the queue */
1565 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1568 csio = &done_ccb->csio;
1569 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1570 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1572 "inquiry data fails comparison at DV%d step\n",
1573 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1574 if (proberequestbackoff(periph, path->device)) {
1575 path->device->flags &= ~CAM_DEV_IN_DV;
1576 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1579 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1581 free(nbuf, M_CAMXPT);
1582 xpt_release_ccb(done_ccb);
1583 xpt_schedule(periph, priority);
1586 free(nbuf, M_CAMXPT);
1587 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1588 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1589 xpt_release_ccb(done_ccb);
1590 xpt_schedule(periph, priority);
1593 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1594 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1595 ("Leave Domain Validation Successfully\n"));
1597 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1598 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1599 xpt_acquire_device(path->device);
1601 path->device->flags &=
1602 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1603 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1604 /* Inform the XPT that a new device has been found */
1605 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1606 xpt_action(done_ccb);
1607 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1610 PROBE_SET_ACTION(softc, PROBE_DONE);
1611 xpt_release_ccb(done_ccb);
1615 panic("probedone: invalid action state 0x%x\n", softc->action);
1617 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1618 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1619 done_ccb->ccb_h.status = CAM_REQ_CMP;
1621 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1622 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1623 cam_periph_invalidate(periph);
1624 cam_release_devq(periph->path,
1625 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1626 cam_periph_release_locked(periph);
1628 probeschedule(periph);
1633 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1636 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1638 for (idx = 0; idx < nlun; idx++) {
1639 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1647 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1649 struct cam_path *tp;
1650 struct scsi_report_luns_data *old;
1651 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1654 if (path->target == NULL) {
1657 if (path->target->luns == NULL) {
1658 path->target->luns = new;
1661 old = path->target->luns;
1662 nlun_old = scsi_4btoul(old->length) / 8;
1663 nlun_new = scsi_4btoul(new->length) / 8;
1666 * We are not going to assume sorted lists. Deal.
1668 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1669 ol = old->luns[idx1].lundata;
1670 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1671 nl = new->luns[idx2].lundata;
1672 if (memcmp(nl, ol, 8) == 0) {
1676 if (idx2 < nlun_new) {
1680 * An 'old' item not in the 'new' list.
1681 * Nuke it. Except that if it is lun 0,
1682 * that would be what the probe state
1683 * machine is currently working on,
1684 * so we won't do that.
1686 * We also cannot nuke it if it is
1687 * not in a lun format we understand.
1689 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1692 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1693 if (this_lun == 0) {
1696 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1697 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1698 xpt_async(AC_LOST_DEVICE, tp, NULL);
1702 free(old, M_CAMXPT);
1703 path->target->luns = new;
1707 probecleanup(struct cam_periph *periph)
1709 free(periph->softc, M_CAMXPT);
1713 scsi_find_quirk(struct cam_ed *device)
1715 struct scsi_quirk_entry *quirk;
1718 match = cam_quirkmatch((caddr_t)&device->inq_data,
1719 (caddr_t)scsi_quirk_table,
1720 sizeof(scsi_quirk_table) /
1721 sizeof(*scsi_quirk_table),
1722 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1725 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1727 quirk = (struct scsi_quirk_entry *)match;
1728 device->quirk = quirk;
1729 device->mintags = quirk->mintags;
1730 device->maxtags = quirk->maxtags;
1734 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1739 error = sysctl_handle_int(oidp, &val, 0, req);
1740 if (error != 0 || req->newptr == NULL)
1742 if (val == 0 || val == 1) {
1751 union ccb *request_ccb;
1752 struct ccb_pathinq *cpi;
1755 } scsi_scan_bus_info;
1758 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1759 * As the scan progresses, scsi_scan_bus is used as the
1760 * callback on completion function.
1763 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1765 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1766 ("scsi_scan_bus\n"));
1767 switch (request_ccb->ccb_h.func_code) {
1771 scsi_scan_bus_info *scan_info;
1772 union ccb *work_ccb, *reset_ccb;
1773 struct cam_path *path;
1775 u_int low_target, max_target;
1778 /* Find out the characteristics of the bus */
1779 work_ccb = xpt_alloc_ccb_nowait();
1780 if (work_ccb == NULL) {
1781 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1782 xpt_done(request_ccb);
1785 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1786 request_ccb->ccb_h.pinfo.priority);
1787 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1788 xpt_action(work_ccb);
1789 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1790 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1791 xpt_free_ccb(work_ccb);
1792 xpt_done(request_ccb);
1796 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1798 * Can't scan the bus on an adapter that
1799 * cannot perform the initiator role.
1801 request_ccb->ccb_h.status = CAM_REQ_CMP;
1802 xpt_free_ccb(work_ccb);
1803 xpt_done(request_ccb);
1807 /* We may need to reset bus first, if we haven't done it yet. */
1808 if ((work_ccb->cpi.hba_inquiry &
1809 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1810 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1811 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1812 reset_ccb = xpt_alloc_ccb_nowait();
1813 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1815 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1816 xpt_action(reset_ccb);
1817 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1818 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1819 xpt_free_ccb(reset_ccb);
1820 xpt_free_ccb(work_ccb);
1821 xpt_done(request_ccb);
1824 xpt_free_ccb(reset_ccb);
1827 /* Save some state for use while we probe for devices */
1828 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1829 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1830 if (scan_info == NULL) {
1831 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1832 xpt_done(request_ccb);
1835 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1836 ("SCAN start for %p\n", scan_info));
1837 scan_info->request_ccb = request_ccb;
1838 scan_info->cpi = &work_ccb->cpi;
1840 /* Cache on our stack so we can work asynchronously */
1841 max_target = scan_info->cpi->max_target;
1843 initiator_id = scan_info->cpi->initiator_id;
1847 * We can scan all targets in parallel, or do it sequentially.
1850 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1851 max_target = low_target = request_ccb->ccb_h.target_id;
1852 scan_info->counter = 0;
1853 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1855 scan_info->counter = 0;
1857 scan_info->counter = scan_info->cpi->max_target + 1;
1858 if (scan_info->cpi->initiator_id < scan_info->counter) {
1859 scan_info->counter--;
1863 for (i = low_target; i <= max_target; i++) {
1865 if (i == initiator_id)
1868 status = xpt_create_path(&path, xpt_periph,
1869 request_ccb->ccb_h.path_id,
1871 if (status != CAM_REQ_CMP) {
1872 printf("scsi_scan_bus: xpt_create_path failed"
1873 " with status %#x, bus scan halted\n",
1875 free(scan_info, M_CAMXPT);
1876 request_ccb->ccb_h.status = status;
1877 xpt_free_ccb(work_ccb);
1878 xpt_done(request_ccb);
1881 work_ccb = xpt_alloc_ccb_nowait();
1882 if (work_ccb == NULL) {
1883 xpt_free_ccb((union ccb *)scan_info->cpi);
1884 free(scan_info, M_CAMXPT);
1885 xpt_free_path(path);
1886 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1887 xpt_done(request_ccb);
1890 xpt_setup_ccb(&work_ccb->ccb_h, path,
1891 request_ccb->ccb_h.pinfo.priority);
1892 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1893 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1894 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1895 work_ccb->crcn.flags = request_ccb->crcn.flags;
1896 xpt_action(work_ccb);
1903 struct cam_path *path, *oldpath;
1904 scsi_scan_bus_info *scan_info;
1905 struct cam_et *target;
1906 struct cam_ed *device;
1909 target_id_t target_id;
1912 oldpath = request_ccb->ccb_h.path;
1914 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
1915 /* Reuse the same CCB to query if a device was really found */
1916 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1917 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1918 request_ccb->ccb_h.pinfo.priority);
1919 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1922 path_id = request_ccb->ccb_h.path_id;
1923 target_id = request_ccb->ccb_h.target_id;
1924 lun_id = request_ccb->ccb_h.target_lun;
1925 xpt_action(request_ccb);
1927 target = request_ccb->ccb_h.path->target;
1932 u_int nluns = scsi_4btoul(target->luns->length) / 8;
1935 * Make sure we skip over lun 0 if it's the first member
1936 * of the list as we've actually just finished probing
1939 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
1940 if (first == 0 && scan_info->lunindex[target_id] == 0) {
1941 scan_info->lunindex[target_id]++;
1944 if (scan_info->lunindex[target_id] < nluns) {
1945 CAM_GET_SIMPLE_LUN(target->luns,
1946 scan_info->lunindex[target_id], lun_id);
1948 CAM_DEBUG(request_ccb->ccb_h.path,
1950 ("next lun to try at index %u is %u\n",
1951 scan_info->lunindex[target_id], lun_id));
1952 scan_info->lunindex[target_id]++;
1955 * We're done with scanning all luns.
1957 * Nuke the bogus device for lun 0 if lun 0
1958 * wasn't on the list.
1961 TAILQ_FOREACH(device,
1962 &target->ed_entries, links) {
1963 if (device->lun_id == 0) {
1968 xpt_release_device(device);
1972 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
1976 * If we already probed lun 0 successfully, or
1977 * we have additional configured luns on this
1978 * target that might have "gone away", go onto
1982 * We may touch devices that we don't
1983 * hold references too, so ensure they
1984 * don't disappear out from under us.
1985 * The target above is referenced by the
1986 * path in the request ccb.
1989 device = TAILQ_FIRST(&target->ed_entries);
1990 if (device != NULL) {
1991 phl = CAN_SRCH_HI_SPARSE(device);
1992 if (device->lun_id == 0)
1993 device = TAILQ_NEXT(device, links);
1995 if ((lun_id != 0) || (device != NULL)) {
1996 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2001 if (lun_id == request_ccb->ccb_h.target_lun
2002 || lun_id > scan_info->cpi->max_lun)
2006 device = request_ccb->ccb_h.path->device;
2008 if ((SCSI_QUIRK(device)->quirks &
2009 CAM_QUIRK_NOLUNS) == 0) {
2010 /* Try the next lun */
2011 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2012 || CAN_SRCH_HI_DENSE(device)) {
2017 if (lun_id == request_ccb->ccb_h.target_lun
2018 || lun_id > scan_info->cpi->max_lun)
2023 * Check to see if we scan any further luns.
2029 * Free the current request path- we're done with it.
2031 xpt_free_path(oldpath);
2034 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2036 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2037 scan_info->counter++;
2038 if (scan_info->counter ==
2039 scan_info->cpi->initiator_id) {
2040 scan_info->counter++;
2042 if (scan_info->counter >=
2043 scan_info->cpi->max_target+1) {
2047 scan_info->counter--;
2048 if (scan_info->counter == 0) {
2053 xpt_free_ccb(request_ccb);
2054 xpt_free_ccb((union ccb *)scan_info->cpi);
2055 request_ccb = scan_info->request_ccb;
2056 CAM_DEBUG(request_ccb->ccb_h.path,
2058 ("SCAN done for %p\n", scan_info));
2059 free(scan_info, M_CAMXPT);
2060 request_ccb->ccb_h.status = CAM_REQ_CMP;
2061 xpt_done(request_ccb);
2065 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2066 xpt_free_ccb(request_ccb);
2069 status = xpt_create_path(&path, xpt_periph,
2070 scan_info->request_ccb->ccb_h.path_id,
2071 scan_info->counter, 0);
2072 if (status != CAM_REQ_CMP) {
2073 printf("scsi_scan_bus: xpt_create_path failed"
2074 " with status %#x, bus scan halted\n",
2076 xpt_free_ccb(request_ccb);
2077 xpt_free_ccb((union ccb *)scan_info->cpi);
2078 request_ccb = scan_info->request_ccb;
2079 free(scan_info, M_CAMXPT);
2080 request_ccb->ccb_h.status = status;
2081 xpt_done(request_ccb);
2084 xpt_setup_ccb(&request_ccb->ccb_h, path,
2085 request_ccb->ccb_h.pinfo.priority);
2086 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2087 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2088 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2089 request_ccb->crcn.flags =
2090 scan_info->request_ccb->crcn.flags;
2092 status = xpt_create_path(&path, xpt_periph,
2093 path_id, target_id, lun_id);
2095 * Free the old request path- we're done with it. We
2096 * do this *after* creating the new path so that
2097 * we don't remove a target that has our lun list
2098 * in the case that lun 0 is not present.
2100 xpt_free_path(oldpath);
2101 if (status != CAM_REQ_CMP) {
2102 printf("scsi_scan_bus: xpt_create_path failed "
2103 "with status %#x, halting LUN scan\n",
2107 xpt_setup_ccb(&request_ccb->ccb_h, path,
2108 request_ccb->ccb_h.pinfo.priority);
2109 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2110 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2111 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2112 request_ccb->crcn.flags =
2113 scan_info->request_ccb->crcn.flags;
2115 xpt_action(request_ccb);
2124 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2125 cam_flags flags, union ccb *request_ccb)
2127 struct ccb_pathinq cpi;
2129 struct cam_path *new_path;
2130 struct cam_periph *old_periph;
2132 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2134 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2135 cpi.ccb_h.func_code = XPT_PATH_INQ;
2136 xpt_action((union ccb *)&cpi);
2138 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2139 if (request_ccb != NULL) {
2140 request_ccb->ccb_h.status = cpi.ccb_h.status;
2141 xpt_done(request_ccb);
2146 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2148 * Can't scan the bus on an adapter that
2149 * cannot perform the initiator role.
2151 if (request_ccb != NULL) {
2152 request_ccb->ccb_h.status = CAM_REQ_CMP;
2153 xpt_done(request_ccb);
2158 if (request_ccb == NULL) {
2159 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
2160 if (request_ccb == NULL) {
2161 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2162 "can't continue\n");
2165 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
2166 if (new_path == NULL) {
2167 xpt_print(path, "scsi_scan_lun: can't allocate path, "
2168 "can't continue\n");
2169 free(request_ccb, M_CAMXPT);
2172 status = xpt_compile_path(new_path, xpt_periph,
2174 path->target->target_id,
2175 path->device->lun_id);
2177 if (status != CAM_REQ_CMP) {
2178 xpt_print(path, "scsi_scan_lun: can't compile path, "
2179 "can't continue\n");
2180 free(request_ccb, M_CAMXPT);
2181 free(new_path, M_CAMXPT);
2184 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2185 request_ccb->ccb_h.cbfcnp = xptscandone;
2186 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2187 request_ccb->crcn.flags = flags;
2190 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2191 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2194 softc = (probe_softc *)old_periph->softc;
2195 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2196 &request_ccb->ccb_h, periph_links.tqe);
2198 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2199 xpt_done(request_ccb);
2202 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2203 probestart, "probe",
2205 request_ccb->ccb_h.path, NULL, 0,
2208 if (status != CAM_REQ_CMP) {
2209 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2210 "returned an error, can't continue probe\n");
2211 request_ccb->ccb_h.status = status;
2212 xpt_done(request_ccb);
2218 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2220 xpt_release_path(done_ccb->ccb_h.path);
2221 free(done_ccb->ccb_h.path, M_CAMXPT);
2222 free(done_ccb, M_CAMXPT);
2225 static struct cam_ed *
2226 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2228 struct cam_path path;
2229 struct scsi_quirk_entry *quirk;
2230 struct cam_ed *device;
2231 struct cam_ed *cur_device;
2233 device = xpt_alloc_device(bus, target, lun_id);
2238 * Take the default quirk entry until we have inquiry
2239 * data and can determine a better quirk to use.
2241 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2242 device->quirk = (void *)quirk;
2243 device->mintags = quirk->mintags;
2244 device->maxtags = quirk->maxtags;
2245 bzero(&device->inq_data, sizeof(device->inq_data));
2246 device->inq_flags = 0;
2247 device->queue_flags = 0;
2248 device->serial_num = NULL;
2249 device->serial_num_len = 0;
2250 device->supported_vpds = NULL;
2251 device->supported_vpds_len = 0;
2254 * XXX should be limited by number of CCBs this bus can
2257 bus->sim->max_ccbs += device->ccbq.devq_openings;
2258 /* Insertion sort into our target's device list */
2259 cur_device = TAILQ_FIRST(&target->ed_entries);
2260 while (cur_device != NULL && cur_device->lun_id < lun_id)
2261 cur_device = TAILQ_NEXT(cur_device, links);
2262 if (cur_device != NULL) {
2263 TAILQ_INSERT_BEFORE(cur_device, device, links);
2265 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
2267 target->generation++;
2268 if (lun_id != CAM_LUN_WILDCARD) {
2269 xpt_compile_path(&path,
2274 scsi_devise_transport(&path);
2275 xpt_release_path(&path);
2282 scsi_devise_transport(struct cam_path *path)
2284 struct ccb_pathinq cpi;
2285 struct ccb_trans_settings cts;
2286 struct scsi_inquiry_data *inq_buf;
2288 /* Get transport information from the SIM */
2289 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2290 cpi.ccb_h.func_code = XPT_PATH_INQ;
2291 xpt_action((union ccb *)&cpi);
2294 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2295 inq_buf = &path->device->inq_data;
2296 path->device->protocol = PROTO_SCSI;
2297 path->device->protocol_version =
2298 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2299 path->device->transport = cpi.transport;
2300 path->device->transport_version = cpi.transport_version;
2303 * Any device not using SPI3 features should
2304 * be considered SPI2 or lower.
2306 if (inq_buf != NULL) {
2307 if (path->device->transport == XPORT_SPI
2308 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2309 && path->device->transport_version > 2)
2310 path->device->transport_version = 2;
2312 struct cam_ed* otherdev;
2314 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2316 otherdev = TAILQ_NEXT(otherdev, links)) {
2317 if (otherdev != path->device)
2321 if (otherdev != NULL) {
2323 * Initially assume the same versioning as
2324 * prior luns for this target.
2326 path->device->protocol_version =
2327 otherdev->protocol_version;
2328 path->device->transport_version =
2329 otherdev->transport_version;
2331 /* Until we know better, opt for safty */
2332 path->device->protocol_version = 2;
2333 if (path->device->transport == XPORT_SPI)
2334 path->device->transport_version = 2;
2336 path->device->transport_version = 0;
2342 * For a device compliant with SPC-2 we should be able
2343 * to determine the transport version supported by
2344 * scrutinizing the version descriptors in the
2348 /* Tell the controller what we think */
2349 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2350 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2351 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2352 cts.transport = path->device->transport;
2353 cts.transport_version = path->device->transport_version;
2354 cts.protocol = path->device->protocol;
2355 cts.protocol_version = path->device->protocol_version;
2356 cts.proto_specific.valid = 0;
2357 cts.xport_specific.valid = 0;
2358 xpt_action((union ccb *)&cts);
2362 scsi_action(union ccb *start_ccb)
2365 switch (start_ccb->ccb_h.func_code) {
2366 case XPT_SET_TRAN_SETTINGS:
2368 scsi_set_transfer_settings(&start_ccb->cts,
2369 start_ccb->ccb_h.path->device,
2370 /*async_update*/FALSE);
2375 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2378 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2379 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2382 case XPT_GET_TRAN_SETTINGS:
2384 struct cam_sim *sim;
2386 sim = start_ccb->ccb_h.path->bus->sim;
2387 (*(sim->sim_action))(sim, start_ccb);
2391 xpt_action_default(start_ccb);
2397 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2400 struct ccb_pathinq cpi;
2401 struct ccb_trans_settings cur_cts;
2402 struct ccb_trans_settings_scsi *scsi;
2403 struct ccb_trans_settings_scsi *cur_scsi;
2404 struct cam_sim *sim;
2405 struct scsi_inquiry_data *inq_data;
2407 if (device == NULL) {
2408 cts->ccb_h.status = CAM_PATH_INVALID;
2409 xpt_done((union ccb *)cts);
2413 if (cts->protocol == PROTO_UNKNOWN
2414 || cts->protocol == PROTO_UNSPECIFIED) {
2415 cts->protocol = device->protocol;
2416 cts->protocol_version = device->protocol_version;
2419 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2420 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2421 cts->protocol_version = device->protocol_version;
2423 if (cts->protocol != device->protocol) {
2424 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2425 cts->protocol, device->protocol);
2426 cts->protocol = device->protocol;
2429 if (cts->protocol_version > device->protocol_version) {
2431 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2432 "Version from %d to %d?\n", cts->protocol_version,
2433 device->protocol_version);
2435 cts->protocol_version = device->protocol_version;
2438 if (cts->transport == XPORT_UNKNOWN
2439 || cts->transport == XPORT_UNSPECIFIED) {
2440 cts->transport = device->transport;
2441 cts->transport_version = device->transport_version;
2444 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2445 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2446 cts->transport_version = device->transport_version;
2448 if (cts->transport != device->transport) {
2449 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2450 cts->transport, device->transport);
2451 cts->transport = device->transport;
2454 if (cts->transport_version > device->transport_version) {
2456 xpt_print(cts->ccb_h.path, "Down reving Transport "
2457 "Version from %d to %d?\n", cts->transport_version,
2458 device->transport_version);
2460 cts->transport_version = device->transport_version;
2463 sim = cts->ccb_h.path->bus->sim;
2466 * Nothing more of interest to do unless
2467 * this is a device connected via the
2470 if (cts->protocol != PROTO_SCSI) {
2471 if (async_update == FALSE)
2472 (*(sim->sim_action))(sim, (union ccb *)cts);
2476 inq_data = &device->inq_data;
2477 scsi = &cts->proto_specific.scsi;
2478 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2479 cpi.ccb_h.func_code = XPT_PATH_INQ;
2480 xpt_action((union ccb *)&cpi);
2482 /* SCSI specific sanity checking */
2483 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2484 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2485 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2486 || (device->mintags == 0)) {
2488 * Can't tag on hardware that doesn't support tags,
2489 * doesn't have it enabled, or has broken tag support.
2491 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2494 if (async_update == FALSE) {
2496 * Perform sanity checking against what the
2497 * controller and device can do.
2499 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2500 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2501 cur_cts.type = cts->type;
2502 xpt_action((union ccb *)&cur_cts);
2503 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2506 cur_scsi = &cur_cts.proto_specific.scsi;
2507 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2508 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2509 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2511 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2512 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2515 /* SPI specific sanity checking */
2516 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2518 struct ccb_trans_settings_spi *spi;
2519 struct ccb_trans_settings_spi *cur_spi;
2521 spi = &cts->xport_specific.spi;
2523 cur_spi = &cur_cts.xport_specific.spi;
2525 /* Fill in any gaps in what the user gave us */
2526 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2527 spi->sync_period = cur_spi->sync_period;
2528 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2529 spi->sync_period = 0;
2530 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2531 spi->sync_offset = cur_spi->sync_offset;
2532 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2533 spi->sync_offset = 0;
2534 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2535 spi->ppr_options = cur_spi->ppr_options;
2536 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2537 spi->ppr_options = 0;
2538 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2539 spi->bus_width = cur_spi->bus_width;
2540 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2542 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2543 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2544 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2546 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2547 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2548 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2549 && (inq_data->flags & SID_Sync) == 0
2550 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2551 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2553 spi->sync_period = 0;
2554 spi->sync_offset = 0;
2557 switch (spi->bus_width) {
2558 case MSG_EXT_WDTR_BUS_32_BIT:
2559 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2560 || (inq_data->flags & SID_WBus32) != 0
2561 || cts->type == CTS_TYPE_USER_SETTINGS)
2562 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2564 /* Fall Through to 16-bit */
2565 case MSG_EXT_WDTR_BUS_16_BIT:
2566 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2567 || (inq_data->flags & SID_WBus16) != 0
2568 || cts->type == CTS_TYPE_USER_SETTINGS)
2569 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2570 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2573 /* Fall Through to 8-bit */
2574 default: /* New bus width?? */
2575 case MSG_EXT_WDTR_BUS_8_BIT:
2576 /* All targets can do this */
2577 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2581 spi3caps = cpi.xport_specific.spi.ppr_options;
2582 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2583 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2584 spi3caps &= inq_data->spi3data;
2586 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2587 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2589 if ((spi3caps & SID_SPI_IUS) == 0)
2590 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2592 if ((spi3caps & SID_SPI_QAS) == 0)
2593 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2595 /* No SPI Transfer settings are allowed unless we are wide */
2596 if (spi->bus_width == 0)
2597 spi->ppr_options = 0;
2599 if ((spi->valid & CTS_SPI_VALID_DISC)
2600 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2602 * Can't tag queue without disconnection.
2604 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2605 scsi->valid |= CTS_SCSI_VALID_TQ;
2609 * If we are currently performing tagged transactions to
2610 * this device and want to change its negotiation parameters,
2611 * go non-tagged for a bit to give the controller a chance to
2612 * negotiate unhampered by tag messages.
2614 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2615 && (device->inq_flags & SID_CmdQue) != 0
2616 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2617 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2618 CTS_SPI_VALID_SYNC_OFFSET|
2619 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2620 scsi_toggle_tags(cts->ccb_h.path);
2623 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2624 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2628 * If we are transitioning from tags to no-tags or
2629 * vice-versa, we need to carefully freeze and restart
2630 * the queue so that we don't overlap tagged and non-tagged
2631 * commands. We also temporarily stop tags if there is
2632 * a change in transfer negotiation settings to allow
2633 * "tag-less" negotiation.
2635 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2636 || (device->inq_flags & SID_CmdQue) != 0)
2637 device_tagenb = TRUE;
2639 device_tagenb = FALSE;
2641 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2642 && device_tagenb == FALSE)
2643 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2644 && device_tagenb == TRUE)) {
2646 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2648 * Delay change to use tags until after a
2649 * few commands have gone to this device so
2650 * the controller has time to perform transfer
2651 * negotiations without tagged messages getting
2654 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2655 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2657 xpt_stop_tags(cts->ccb_h.path);
2661 if (async_update == FALSE)
2662 (*(sim->sim_action))(sim, (union ccb *)cts);
2666 scsi_toggle_tags(struct cam_path *path)
2671 * Give controllers a chance to renegotiate
2672 * before starting tag operations. We
2673 * "toggle" tagged queuing off then on
2674 * which causes the tag enable command delay
2675 * counter to come into effect.
2678 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2679 || ((dev->inq_flags & SID_CmdQue) != 0
2680 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2681 struct ccb_trans_settings cts;
2683 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2684 cts.protocol = PROTO_SCSI;
2685 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2686 cts.transport = XPORT_UNSPECIFIED;
2687 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2688 cts.proto_specific.scsi.flags = 0;
2689 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2690 scsi_set_transfer_settings(&cts, path->device,
2691 /*async_update*/TRUE);
2692 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2693 scsi_set_transfer_settings(&cts, path->device,
2694 /*async_update*/TRUE);
2699 * Handle any per-device event notifications that require action by the XPT.
2702 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2703 struct cam_ed *device, void *async_arg)
2706 struct cam_path newpath;
2709 * We only need to handle events for real devices.
2711 if (target->target_id == CAM_TARGET_WILDCARD
2712 || device->lun_id == CAM_LUN_WILDCARD)
2716 * We need our own path with wildcards expanded to
2717 * handle certain types of events.
2719 if ((async_code == AC_SENT_BDR)
2720 || (async_code == AC_BUS_RESET)
2721 || (async_code == AC_INQ_CHANGED))
2722 status = xpt_compile_path(&newpath, NULL,
2727 status = CAM_REQ_CMP_ERR;
2729 if (status == CAM_REQ_CMP) {
2732 * Allow transfer negotiation to occur in a
2733 * tag free environment and after settle delay.
2735 if (async_code == AC_SENT_BDR
2736 || async_code == AC_BUS_RESET) {
2737 cam_freeze_devq(&newpath);
2738 cam_release_devq(&newpath,
2739 RELSIM_RELEASE_AFTER_TIMEOUT,
2741 /*timeout*/scsi_delay,
2742 /*getcount_only*/0);
2743 scsi_toggle_tags(&newpath);
2746 if (async_code == AC_INQ_CHANGED) {
2748 * We've sent a start unit command, or
2749 * something similar to a device that
2750 * may have caused its inquiry data to
2751 * change. So we re-scan the device to
2752 * refresh the inquiry data for it.
2754 scsi_scan_lun(newpath.periph, &newpath,
2755 CAM_EXPECT_INQ_CHANGE, NULL);
2757 xpt_release_path(&newpath);
2758 } else if (async_code == AC_LOST_DEVICE &&
2759 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2760 device->flags |= CAM_DEV_UNCONFIGURED;
2761 xpt_release_device(device);
2762 } else if (async_code == AC_TRANSFER_NEG) {
2763 struct ccb_trans_settings *settings;
2765 settings = (struct ccb_trans_settings *)async_arg;
2766 scsi_set_transfer_settings(settings, device,
2767 /*async_update*/TRUE);
2772 scsi_announce_periph(struct cam_periph *periph)
2774 struct ccb_pathinq cpi;
2775 struct ccb_trans_settings cts;
2776 struct cam_path *path = periph->path;
2781 mtx_assert(periph->sim->mtx, MA_OWNED);
2783 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2784 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2785 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2786 xpt_action((union ccb*)&cts);
2787 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2789 /* Ask the SIM for its base transfer speed */
2790 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2791 cpi.ccb_h.func_code = XPT_PATH_INQ;
2792 xpt_action((union ccb *)&cpi);
2793 /* Report connection speed */
2794 speed = cpi.base_transfer_speed;
2796 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2797 struct ccb_trans_settings_spi *spi =
2798 &cts.xport_specific.spi;
2800 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2801 && spi->sync_offset != 0) {
2802 freq = scsi_calc_syncsrate(spi->sync_period);
2805 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2806 speed *= (0x01 << spi->bus_width);
2808 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2809 struct ccb_trans_settings_fc *fc =
2810 &cts.xport_specific.fc;
2812 if (fc->valid & CTS_FC_VALID_SPEED)
2813 speed = fc->bitrate;
2815 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2816 struct ccb_trans_settings_sas *sas =
2817 &cts.xport_specific.sas;
2819 if (sas->valid & CTS_SAS_VALID_SPEED)
2820 speed = sas->bitrate;
2824 printf("%s%d: %d.%03dMB/s transfers",
2825 periph->periph_name, periph->unit_number,
2828 printf("%s%d: %dKB/s transfers", periph->periph_name,
2829 periph->unit_number, speed);
2830 /* Report additional information about SPI connections */
2831 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2832 struct ccb_trans_settings_spi *spi;
2834 spi = &cts.xport_specific.spi;
2836 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2838 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2842 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2843 && spi->bus_width > 0) {
2849 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2850 } else if (freq != 0) {
2854 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2855 struct ccb_trans_settings_fc *fc;
2857 fc = &cts.xport_specific.fc;
2858 if (fc->valid & CTS_FC_VALID_WWNN)
2859 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2860 if (fc->valid & CTS_FC_VALID_WWPN)
2861 printf(" WWPN 0x%llx", (long long) fc->wwpn);
2862 if (fc->valid & CTS_FC_VALID_PORT)
2863 printf(" PortID 0x%x", fc->port);