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 */
139 PROBE_TUR_FOR_NEGOTIATION,
140 PROBE_INQUIRY_BASIC_DV1,
141 PROBE_INQUIRY_BASIC_DV2,
146 static char *probe_action_text[] = {
149 "PROBE_FULL_INQUIRY",
152 "PROBE_SERIAL_NUM_0",
153 "PROBE_SERIAL_NUM_1",
154 "PROBE_TUR_FOR_NEGOTIATION",
155 "PROBE_INQUIRY_BASIC_DV1",
156 "PROBE_INQUIRY_BASIC_DV2",
161 #define PROBE_SET_ACTION(softc, newaction) \
164 text = probe_action_text; \
165 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \
166 ("Probe %s to %s\n", text[(softc)->action], \
167 text[(newaction)])); \
168 (softc)->action = (newaction); \
172 PROBE_INQUIRY_CKSUM = 0x01,
173 PROBE_SERIAL_CKSUM = 0x02,
174 PROBE_NO_ANNOUNCE = 0x04
178 TAILQ_HEAD(, ccb_hdr) request_ccbs;
184 struct cam_periph *periph;
187 static const char quantum[] = "QUANTUM";
188 static const char sony[] = "SONY";
189 static const char west_digital[] = "WDIGTL";
190 static const char samsung[] = "SAMSUNG";
191 static const char seagate[] = "SEAGATE";
192 static const char microp[] = "MICROP";
194 static struct scsi_quirk_entry scsi_quirk_table[] =
197 /* Reports QUEUE FULL for temporary resource shortages */
198 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
199 /*quirks*/0, /*mintags*/24, /*maxtags*/32
202 /* Reports QUEUE FULL for temporary resource shortages */
203 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
204 /*quirks*/0, /*mintags*/24, /*maxtags*/32
207 /* Reports QUEUE FULL for temporary resource shortages */
208 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
209 /*quirks*/0, /*mintags*/24, /*maxtags*/32
212 /* Broken tagged queuing drive */
213 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
214 /*quirks*/0, /*mintags*/0, /*maxtags*/0
217 /* Broken tagged queuing drive */
218 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
219 /*quirks*/0, /*mintags*/0, /*maxtags*/0
222 /* Broken tagged queuing drive */
223 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
224 /*quirks*/0, /*mintags*/0, /*maxtags*/0
228 * Unfortunately, the Quantum Atlas III has the same
229 * problem as the Atlas II drives above.
230 * Reported by: "Johan Granlund" <johan@granlund.nu>
232 * For future reference, the drive with the problem was:
233 * QUANTUM QM39100TD-SW N1B0
235 * It's possible that Quantum will fix the problem in later
236 * firmware revisions. If that happens, the quirk entry
237 * will need to be made specific to the firmware revisions
241 /* Reports QUEUE FULL for temporary resource shortages */
242 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
243 /*quirks*/0, /*mintags*/24, /*maxtags*/32
247 * 18 Gig Atlas III, same problem as the 9G version.
248 * Reported by: Andre Albsmeier
249 * <andre.albsmeier@mchp.siemens.de>
251 * For future reference, the drive with the problem was:
252 * QUANTUM QM318000TD-S N491
254 /* Reports QUEUE FULL for temporary resource shortages */
255 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
256 /*quirks*/0, /*mintags*/24, /*maxtags*/32
260 * Broken tagged queuing drive
261 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
262 * and: Martin Renters <martin@tdc.on.ca>
264 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
265 /*quirks*/0, /*mintags*/0, /*maxtags*/0
268 * The Seagate Medalist Pro drives have very poor write
269 * performance with anything more than 2 tags.
271 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
272 * Drive: <SEAGATE ST36530N 1444>
274 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
275 * Drive: <SEAGATE ST34520W 1281>
277 * No one has actually reported that the 9G version
278 * (ST39140*) of the Medalist Pro has the same problem, but
279 * we're assuming that it does because the 4G and 6.5G
280 * versions of the drive are broken.
283 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
284 /*quirks*/0, /*mintags*/2, /*maxtags*/2
287 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
288 /*quirks*/0, /*mintags*/2, /*maxtags*/2
291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
292 /*quirks*/0, /*mintags*/2, /*maxtags*/2
296 * Slow when tagged queueing is enabled. Write performance
297 * steadily drops off with more and more concurrent
298 * transactions. Best sequential write performance with
299 * tagged queueing turned off and write caching turned on.
302 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
303 * Drive: DCAS-34330 w/ "S65A" firmware.
305 * The drive with the problem had the "S65A" firmware
306 * revision, and has also been reported (by Stephen J.
307 * Roznowski <sjr@home.net>) for a drive with the "S61A"
310 * Although no one has reported problems with the 2 gig
311 * version of the DCAS drive, the assumption is that it
312 * has the same problems as the 4 gig version. Therefore
313 * this quirk entries disables tagged queueing for all
316 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
317 /*quirks*/0, /*mintags*/0, /*maxtags*/0
320 /* Broken tagged queuing drive */
321 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
322 /*quirks*/0, /*mintags*/0, /*maxtags*/0
325 /* Broken tagged queuing drive */
326 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
327 /*quirks*/0, /*mintags*/0, /*maxtags*/0
330 /* This does not support other than LUN 0 */
331 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
332 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
336 * Broken tagged queuing drive.
338 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
341 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
342 /*quirks*/0, /*mintags*/0, /*maxtags*/0
346 * Slow when tagged queueing is enabled. (1.5MB/sec versus
348 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
349 * Best performance with these drives is achieved with
350 * tagged queueing turned off, and write caching turned on.
352 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
353 /*quirks*/0, /*mintags*/0, /*maxtags*/0
357 * Slow when tagged queueing is enabled. (1.5MB/sec versus
359 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
360 * Best performance with these drives is achieved with
361 * tagged queueing turned off, and write caching turned on.
363 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
364 /*quirks*/0, /*mintags*/0, /*maxtags*/0
368 * Doesn't handle queue full condition correctly,
369 * so we need to limit maxtags to what the device
370 * can handle instead of determining this automatically.
372 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
373 /*quirks*/0, /*mintags*/2, /*maxtags*/32
376 /* Really only one LUN */
377 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
378 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
381 /* I can't believe we need a quirk for DPT volumes. */
382 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
384 /*mintags*/0, /*maxtags*/255
388 * Many Sony CDROM drives don't like multi-LUN probing.
390 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
391 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
395 * This drive doesn't like multiple LUN probing.
396 * Submitted by: Parag Patel <parag@cgt.com>
398 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
399 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
402 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
403 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
407 * The 8200 doesn't like multi-lun probing, and probably
408 * don't like serial number requests either.
411 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
414 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
418 * Let's try the same as above, but for a drive that says
419 * it's an IPL-6860 but is actually an EXB 8200.
422 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
425 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
429 * These Hitachi drives don't like multi-lun probing.
430 * The PR submitter has a DK319H, but says that the Linux
431 * kernel has a similar work-around for the DK312 and DK314,
432 * so all DK31* drives are quirked here.
434 * Submitted by: Paul Haddad <paul@pth.com>
436 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
437 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
441 * The Hitachi CJ series with J8A8 firmware apparantly has
442 * problems with tagged commands.
444 * Reported by: amagai@nue.org
446 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
447 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
451 * These are the large storage arrays.
452 * Submitted by: William Carrel <william.carrel@infospace.com>
454 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
455 CAM_QUIRK_HILUNS, 2, 1024
459 * This old revision of the TDC3600 is also SCSI-1, and
460 * hangs upon serial number probing.
463 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
466 CAM_QUIRK_NOSERIAL, /*mintags*/0, /*maxtags*/0
470 * Would repond to all LUNs if asked for.
473 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
476 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
480 * Would repond to all LUNs if asked for.
483 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
486 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
489 /* Submitted by: Matthew Dodd <winter@jurai.net> */
490 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
491 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
494 /* Submitted by: Matthew Dodd <winter@jurai.net> */
495 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
496 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
499 /* TeraSolutions special settings for TRC-22 RAID */
500 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
501 /*quirks*/0, /*mintags*/55, /*maxtags*/255
504 /* Veritas Storage Appliance */
505 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
506 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
510 * Would respond to all LUNs. Device type and removable
511 * flag are jumper-selectable.
513 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
516 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
519 /* EasyRAID E5A aka. areca ARC-6010 */
520 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
521 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
524 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
525 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
528 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
529 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
532 /* Default tagged queuing parameters for all devices */
534 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
535 /*vendor*/"*", /*product*/"*", /*revision*/"*"
537 /*quirks*/0, /*mintags*/2, /*maxtags*/255
541 static const int scsi_quirk_table_size =
542 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
544 static cam_status proberegister(struct cam_periph *periph,
546 static void probeschedule(struct cam_periph *probe_periph);
547 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
548 static void proberequestdefaultnegotiation(struct cam_periph *periph);
549 static int proberequestbackoff(struct cam_periph *periph,
550 struct cam_ed *device);
551 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
552 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
554 static void probe_purge_old(struct cam_path *path,
555 struct scsi_report_luns_data *new);
556 static void probecleanup(struct cam_periph *periph);
557 static void scsi_find_quirk(struct cam_ed *device);
558 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
559 static void scsi_scan_lun(struct cam_periph *periph,
560 struct cam_path *path, cam_flags flags,
562 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
563 static struct cam_ed *
564 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
566 static void scsi_devise_transport(struct cam_path *path);
567 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
568 struct cam_ed *device,
570 static void scsi_toggle_tags(struct cam_path *path);
571 static void scsi_dev_async(u_int32_t async_code,
573 struct cam_et *target,
574 struct cam_ed *device,
576 static void scsi_action(union ccb *start_ccb);
577 static void scsi_announce_periph(struct cam_periph *periph);
579 static struct xpt_xport scsi_xport = {
580 .alloc_device = scsi_alloc_device,
581 .action = scsi_action,
582 .async = scsi_dev_async,
583 .announce = scsi_announce_periph,
589 return (&scsi_xport);
598 proberegister(struct cam_periph *periph, void *arg)
600 union ccb *request_ccb; /* CCB representing the probe request */
604 request_ccb = (union ccb *)arg;
605 if (periph == NULL) {
606 printf("proberegister: periph was NULL!!\n");
607 return(CAM_REQ_CMP_ERR);
610 if (request_ccb == NULL) {
611 printf("proberegister: no probe CCB, "
612 "can't register device\n");
613 return(CAM_REQ_CMP_ERR);
616 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
619 printf("proberegister: Unable to probe new device. "
620 "Unable to allocate softc\n");
621 return(CAM_REQ_CMP_ERR);
623 TAILQ_INIT(&softc->request_ccbs);
624 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
627 periph->softc = softc;
628 softc->periph = periph;
629 softc->action = PROBE_INVALID;
630 status = cam_periph_acquire(periph);
631 if (status != CAM_REQ_CMP) {
637 * Ensure we've waited at least a bus settle
638 * delay before attempting to probe the device.
639 * For HBAs that don't do bus resets, this won't make a difference.
641 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
644 * Ensure nobody slip in until probe finish.
646 cam_freeze_devq_arg(periph->path,
647 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
648 probeschedule(periph);
653 probeschedule(struct cam_periph *periph)
655 struct ccb_pathinq cpi;
659 softc = (probe_softc *)periph->softc;
660 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
662 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
663 cpi.ccb_h.func_code = XPT_PATH_INQ;
664 xpt_action((union ccb *)&cpi);
667 * If a device has gone away and another device, or the same one,
668 * is back in the same place, it should have a unit attention
669 * condition pending. It will not report the unit attention in
670 * response to an inquiry, which may leave invalid transfer
671 * negotiations in effect. The TUR will reveal the unit attention
672 * condition. Only send the TUR for lun 0, since some devices
673 * will get confused by commands other than inquiry to non-existent
674 * luns. If you think a device has gone away start your scan from
675 * lun 0. This will insure that any bogus transfer settings are
678 * If we haven't seen the device before and the controller supports
679 * some kind of transfer negotiation, negotiate with the first
680 * sent command if no bus reset was performed at startup. This
681 * ensures that the device is not confused by transfer negotiation
682 * settings left over by loader or BIOS action.
684 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
685 && (ccb->ccb_h.target_lun == 0)) {
686 PROBE_SET_ACTION(softc, PROBE_TUR);
687 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
688 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
689 proberequestdefaultnegotiation(periph);
690 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
692 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
695 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
696 softc->flags |= PROBE_NO_ANNOUNCE;
698 softc->flags &= ~PROBE_NO_ANNOUNCE;
700 xpt_schedule(periph, CAM_PRIORITY_XPT);
704 probestart(struct cam_periph *periph, union ccb *start_ccb)
706 /* Probe the device that our peripheral driver points to */
707 struct ccb_scsiio *csio;
710 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
712 softc = (probe_softc *)periph->softc;
713 csio = &start_ccb->csio;
716 switch (softc->action) {
718 case PROBE_TUR_FOR_NEGOTIATION:
721 scsi_test_unit_ready(csio,
730 case PROBE_FULL_INQUIRY:
731 case PROBE_INQUIRY_BASIC_DV1:
732 case PROBE_INQUIRY_BASIC_DV2:
735 struct scsi_inquiry_data *inq_buf;
737 inq_buf = &periph->path->device->inq_data;
740 * If the device is currently configured, we calculate an
741 * MD5 checksum of the inquiry data, and if the serial number
742 * length is greater than 0, add the serial number data
743 * into the checksum as well. Once the inquiry and the
744 * serial number check finish, we attempt to figure out
745 * whether we still have the same device.
747 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
749 MD5Init(&softc->context);
750 MD5Update(&softc->context, (unsigned char *)inq_buf,
751 sizeof(struct scsi_inquiry_data));
752 softc->flags |= PROBE_INQUIRY_CKSUM;
753 if (periph->path->device->serial_num_len > 0) {
754 MD5Update(&softc->context,
755 periph->path->device->serial_num,
756 periph->path->device->serial_num_len);
757 softc->flags |= PROBE_SERIAL_CKSUM;
759 MD5Final(softc->digest, &softc->context);
762 if (softc->action == PROBE_INQUIRY)
763 inquiry_len = SHORT_INQUIRY_LENGTH;
765 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
768 * Some parallel SCSI devices fail to send an
769 * ignore wide residue message when dealing with
770 * odd length inquiry requests. Round up to be
773 inquiry_len = roundup2(inquiry_len, 2);
775 if (softc->action == PROBE_INQUIRY_BASIC_DV1
776 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
777 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
779 if (inq_buf == NULL) {
780 xpt_print(periph->path, "malloc failure- skipping Basic"
781 "Domain Validation\n");
782 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
783 scsi_test_unit_ready(csio,
800 /*timeout*/60 * 1000);
803 case PROBE_REPORT_LUNS:
807 rp = malloc(periph->path->target->rpl_size,
808 M_CAMXPT, M_NOWAIT | M_ZERO);
810 struct scsi_inquiry_data *inq_buf;
811 inq_buf = &periph->path->device->inq_data;
812 xpt_print(periph->path,
813 "Unable to alloc report luns storage\n");
814 if (INQ_DATA_TQ_ENABLED(inq_buf))
815 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
817 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
820 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
821 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
822 SSD_FULL_SIZE, 60000); break;
825 case PROBE_MODE_SENSE:
830 mode_buf_len = sizeof(struct scsi_mode_header_6)
831 + sizeof(struct scsi_mode_blk_desc)
832 + sizeof(struct scsi_control_page);
833 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
834 if (mode_buf != NULL) {
835 scsi_mode_sense(csio,
840 SMS_PAGE_CTRL_CURRENT,
841 SMS_CONTROL_MODE_PAGE,
848 xpt_print(periph->path, "Unable to mode sense control page - "
850 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
853 case PROBE_SERIAL_NUM_0:
855 struct scsi_vpd_supported_page_list *vpd_list = NULL;
856 struct cam_ed *device;
858 device = periph->path->device;
859 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOSERIAL) == 0) {
860 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
864 if (vpd_list != NULL) {
869 (u_int8_t *)vpd_list,
872 SVPD_SUPPORTED_PAGE_LIST,
874 /*timeout*/60 * 1000);
878 * We'll have to do without, let our probedone
879 * routine finish up for us.
881 start_ccb->csio.data_ptr = NULL;
882 probedone(periph, start_ccb);
885 case PROBE_SERIAL_NUM_1:
887 struct scsi_vpd_unit_serial_number *serial_buf;
888 struct cam_ed* device;
891 device = periph->path->device;
892 if (device->serial_num != NULL) {
893 free(device->serial_num, M_CAMXPT);
894 device->serial_num = NULL;
895 device->serial_num_len = 0;
898 serial_buf = (struct scsi_vpd_unit_serial_number *)
899 malloc(sizeof(*serial_buf), M_CAMXPT, M_NOWAIT|M_ZERO);
901 if (serial_buf != NULL) {
906 (u_int8_t *)serial_buf,
909 SVPD_UNIT_SERIAL_NUMBER,
911 /*timeout*/60 * 1000);
915 * We'll have to do without, let our probedone
916 * routine finish up for us.
918 start_ccb->csio.data_ptr = NULL;
919 probedone(periph, start_ccb);
923 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_INFO,
924 ("probestart: invalid action state\n"));
928 xpt_action(start_ccb);
932 proberequestdefaultnegotiation(struct cam_periph *periph)
934 struct ccb_trans_settings cts;
936 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
937 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
938 cts.type = CTS_TYPE_USER_SETTINGS;
939 xpt_action((union ccb *)&cts);
940 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
943 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
944 cts.type = CTS_TYPE_CURRENT_SETTINGS;
945 xpt_action((union ccb *)&cts);
949 * Backoff Negotiation Code- only pertinent for SPI devices.
952 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
954 struct ccb_trans_settings cts;
955 struct ccb_trans_settings_spi *spi;
957 memset(&cts, 0, sizeof (cts));
958 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
959 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
960 cts.type = CTS_TYPE_CURRENT_SETTINGS;
961 xpt_action((union ccb *)&cts);
962 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
964 xpt_print(periph->path,
965 "failed to get current device settings\n");
969 if (cts.transport != XPORT_SPI) {
971 xpt_print(periph->path, "not SPI transport\n");
975 spi = &cts.xport_specific.spi;
978 * We cannot renegotiate sync rate if we don't have one.
980 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
982 xpt_print(periph->path, "no sync rate known\n");
988 * We'll assert that we don't have to touch PPR options- the
989 * SIM will see what we do with period and offset and adjust
990 * the PPR options as appropriate.
994 * A sync rate with unknown or zero offset is nonsensical.
995 * A sync period of zero means Async.
997 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
998 || spi->sync_offset == 0 || spi->sync_period == 0) {
1000 xpt_print(periph->path, "no sync rate available\n");
1005 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1006 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1007 ("hit async: giving up on DV\n"));
1013 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1014 * We don't try to remember 'last' settings to see if the SIM actually
1015 * gets into the speed we want to set. We check on the SIM telling
1016 * us that a requested speed is bad, but otherwise don't try and
1017 * check the speed due to the asynchronous and handshake nature
1020 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1023 if (spi->sync_period >= 0xf) {
1024 spi->sync_period = 0;
1025 spi->sync_offset = 0;
1026 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1027 ("setting to async for DV\n"));
1029 * Once we hit async, we don't want to try
1030 * any more settings.
1032 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1033 } else if (bootverbose) {
1034 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1035 ("DV: period 0x%x\n", spi->sync_period));
1036 printf("setting period to 0x%x\n", spi->sync_period);
1038 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1039 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1040 xpt_action((union ccb *)&cts);
1041 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1044 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1045 ("DV: failed to set period 0x%x\n", spi->sync_period));
1046 if (spi->sync_period == 0) {
1054 probedone(struct cam_periph *periph, union ccb *done_ccb)
1057 struct cam_path *path;
1060 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1062 softc = (probe_softc *)periph->softc;
1063 path = done_ccb->ccb_h.path;
1064 priority = done_ccb->ccb_h.pinfo.priority;
1066 switch (softc->action) {
1069 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1071 if (cam_periph_error(done_ccb, 0,
1072 SF_NO_PRINT, NULL) == ERESTART)
1074 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1075 /* Don't wedge the queue */
1076 xpt_release_devq(done_ccb->ccb_h.path,
1080 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1081 xpt_release_ccb(done_ccb);
1082 xpt_schedule(periph, priority);
1086 case PROBE_FULL_INQUIRY:
1088 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1089 struct scsi_inquiry_data *inq_buf;
1090 u_int8_t periph_qual;
1092 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1093 inq_buf = &path->device->inq_data;
1095 periph_qual = SID_QUAL(inq_buf);
1097 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1101 * We conservatively request only
1102 * SHORT_INQUIRY_LEN bytes of inquiry
1103 * information during our first try
1104 * at sending an INQUIRY. If the device
1105 * has more information to give,
1106 * perform a second request specifying
1107 * the amount of information the device
1108 * is willing to give.
1110 len = inq_buf->additional_length
1111 + offsetof(struct scsi_inquiry_data,
1112 additional_length) + 1;
1113 if (softc->action == PROBE_INQUIRY
1114 && len > SHORT_INQUIRY_LENGTH) {
1115 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1116 xpt_release_ccb(done_ccb);
1117 xpt_schedule(periph, priority);
1121 scsi_find_quirk(path->device);
1123 scsi_devise_transport(path);
1125 if (path->device->lun_id == 0 &&
1126 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1127 (SCSI_QUIRK(path->device)->quirks &
1128 CAM_QUIRK_NORPTLUNS) == 0) {
1129 PROBE_SET_ACTION(softc,
1132 * Start with room for *one* lun.
1134 periph->path->target->rpl_size = 16;
1135 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1136 PROBE_SET_ACTION(softc,
1139 PROBE_SET_ACTION(softc,
1140 PROBE_SERIAL_NUM_0);
1142 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1143 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1144 xpt_acquire_device(path->device);
1146 xpt_release_ccb(done_ccb);
1147 xpt_schedule(periph, priority);
1149 } else if (path->device->lun_id == 0 &&
1150 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1151 (SCSI_QUIRK(path->device)->quirks &
1152 CAM_QUIRK_NORPTLUNS) == 0) {
1153 if (path->device->flags &
1154 CAM_DEV_UNCONFIGURED) {
1155 path->device->flags &=
1156 ~CAM_DEV_UNCONFIGURED;
1157 xpt_acquire_device(path->device);
1159 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1160 periph->path->target->rpl_size = 16;
1161 xpt_release_ccb(done_ccb);
1162 xpt_schedule(periph, priority);
1165 } else if (cam_periph_error(done_ccb, 0,
1166 done_ccb->ccb_h.target_lun > 0
1167 ? SF_RETRY_UA|SF_QUIET_IR
1169 &softc->saved_ccb) == ERESTART) {
1171 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1172 /* Don't wedge the queue */
1173 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1177 * If we get to this point, we got an error status back
1178 * from the inquiry and the error status doesn't require
1179 * automatically retrying the command. Therefore, the
1180 * inquiry failed. If we had inquiry information before
1181 * for this device, but this latest inquiry command failed,
1182 * the device has probably gone away. If this device isn't
1183 * already marked unconfigured, notify the peripheral
1184 * drivers that this device is no more.
1186 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1187 /* Send the async notification. */
1188 xpt_async(AC_LOST_DEVICE, path, NULL);
1190 xpt_release_ccb(done_ccb);
1193 case PROBE_REPORT_LUNS:
1195 struct ccb_scsiio *csio;
1196 struct scsi_report_luns_data *lp;
1199 csio = &done_ccb->csio;
1201 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1202 nlun = scsi_4btoul(lp->length) / 8;
1203 maxlun = (csio->dxfer_len / 8) - 1;
1205 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1206 if (cam_periph_error(done_ccb, 0,
1207 done_ccb->ccb_h.target_lun > 0 ?
1208 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1209 &softc->saved_ccb) == ERESTART) {
1212 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1213 xpt_release_devq(done_ccb->ccb_h.path, 1,
1218 } else if (nlun > maxlun) {
1220 * Reallocate and retry to cover all luns
1222 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, path,
1223 ("reallocating REPORT_LUNS for %u luns\n", nlun));
1225 path->target->rpl_size = (nlun << 3) + 8;
1226 xpt_release_ccb(done_ccb);
1227 xpt_schedule(periph, priority);
1229 } else if (nlun == 0) {
1231 * If there don't appear to be any luns, bail.
1235 } else if (probe_strange_rpl_data(lp, maxlun)) {
1237 * If we can't understand the lun format
1238 * of any entry, bail.
1246 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, path,
1247 ("%u luns reported\n", nlun));
1249 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1251 * If the first lun is not lun 0, then either there
1252 * is no lun 0 in the list, or the list is unsorted.
1255 for (idx = 0; idx < nlun; idx++) {
1256 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1264 lp->luns[0].lundata, 8);
1265 memcpy(lp->luns[0].lundata,
1266 lp->luns[idx].lundata, 8);
1267 memcpy(lp->luns[idx].lundata,
1269 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
1270 path, ("lun 0 in position %u\n", idx));
1273 * There is no lun 0 in our list. Destroy
1274 * the validity of the inquiry data so we
1275 * bail here and now.
1277 path->device->flags &=
1278 ~CAM_DEV_INQUIRY_DATA_VALID;
1282 * If we have an old lun list, We can either
1283 * retest luns that appear to have been dropped,
1284 * or just nuke them. We'll opt for the latter.
1285 * This function will also install the new list
1286 * in the target structure.
1288 probe_purge_old(path, lp);
1291 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1292 struct scsi_inquiry_data *inq_buf;
1293 inq_buf = &path->device->inq_data;
1294 if (INQ_DATA_TQ_ENABLED(inq_buf))
1295 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1297 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1298 xpt_release_ccb(done_ccb);
1299 xpt_schedule(periph, priority);
1307 case PROBE_MODE_SENSE:
1309 struct ccb_scsiio *csio;
1310 struct scsi_mode_header_6 *mode_hdr;
1312 csio = &done_ccb->csio;
1313 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1314 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1315 struct scsi_control_page *page;
1318 offset = ((u_int8_t *)&mode_hdr[1])
1319 + mode_hdr->blk_desc_len;
1320 page = (struct scsi_control_page *)offset;
1321 path->device->queue_flags = page->queue_flags;
1322 } else if (cam_periph_error(done_ccb, 0,
1323 SF_RETRY_UA|SF_NO_PRINT,
1324 &softc->saved_ccb) == ERESTART) {
1326 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1327 /* Don't wedge the queue */
1328 xpt_release_devq(done_ccb->ccb_h.path,
1329 /*count*/1, /*run_queue*/TRUE);
1331 xpt_release_ccb(done_ccb);
1332 free(mode_hdr, M_CAMXPT);
1333 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_0);
1334 xpt_schedule(periph, priority);
1337 case PROBE_SERIAL_NUM_0:
1339 struct ccb_scsiio *csio;
1340 struct scsi_vpd_supported_page_list *page_list;
1341 int length, serialnum_supported, i;
1343 serialnum_supported = 0;
1344 csio = &done_ccb->csio;
1346 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1348 if (page_list == NULL) {
1350 * Don't process the command as it was never sent
1352 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1353 && (page_list->length > 0)) {
1354 length = min(page_list->length,
1355 SVPD_SUPPORTED_PAGES_SIZE);
1356 for (i = 0; i < length; i++) {
1357 if (page_list->list[i] ==
1358 SVPD_UNIT_SERIAL_NUMBER) {
1359 serialnum_supported = 1;
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, /*count*/1,
1373 if (page_list != NULL)
1374 free(page_list, M_CAMXPT);
1376 if (serialnum_supported) {
1377 xpt_release_ccb(done_ccb);
1378 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM_1);
1379 xpt_schedule(periph, priority);
1383 csio->data_ptr = NULL;
1387 case PROBE_SERIAL_NUM_1:
1389 struct ccb_scsiio *csio;
1390 struct scsi_vpd_unit_serial_number *serial_buf;
1397 csio = &done_ccb->csio;
1398 priority = done_ccb->ccb_h.pinfo.priority;
1400 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1402 /* Clean up from previous instance of this device */
1403 if (path->device->serial_num != NULL) {
1404 free(path->device->serial_num, M_CAMXPT);
1405 path->device->serial_num = NULL;
1406 path->device->serial_num_len = 0;
1409 if (serial_buf == NULL) {
1411 * Don't process the command as it was never sent
1413 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1414 && (serial_buf->length > 0)) {
1417 path->device->serial_num =
1418 (u_int8_t *)malloc((serial_buf->length + 1),
1419 M_CAMXPT, M_NOWAIT);
1420 if (path->device->serial_num != NULL) {
1421 bcopy(serial_buf->serial_num,
1422 path->device->serial_num,
1423 serial_buf->length);
1424 path->device->serial_num_len =
1426 path->device->serial_num[serial_buf->length]
1429 } else if (cam_periph_error(done_ccb, 0,
1430 SF_RETRY_UA|SF_NO_PRINT,
1431 &softc->saved_ccb) == ERESTART) {
1433 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1434 /* Don't wedge the queue */
1435 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1440 * Let's see if we have seen this device before.
1442 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1444 u_int8_t digest[16];
1449 (unsigned char *)&path->device->inq_data,
1450 sizeof(struct scsi_inquiry_data));
1453 MD5Update(&context, serial_buf->serial_num,
1454 serial_buf->length);
1456 MD5Final(digest, &context);
1457 if (bcmp(softc->digest, digest, 16) == 0)
1461 * XXX Do we need to do a TUR in order to ensure
1462 * that the device really hasn't changed???
1465 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1466 xpt_async(AC_LOST_DEVICE, path, NULL);
1468 if (serial_buf != NULL)
1469 free(serial_buf, M_CAMXPT);
1473 * Now that we have all the necessary
1474 * information to safely perform transfer
1475 * negotiations... Controllers don't perform
1476 * any negotiation or tagged queuing until
1477 * after the first XPT_SET_TRAN_SETTINGS ccb is
1478 * received. So, on a new device, just retrieve
1479 * the user settings, and set them as the current
1480 * settings to set the device up.
1482 proberequestdefaultnegotiation(periph);
1483 xpt_release_ccb(done_ccb);
1486 * Perform a TUR to allow the controller to
1487 * perform any necessary transfer negotiation.
1489 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1490 xpt_schedule(periph, priority);
1493 xpt_release_ccb(done_ccb);
1496 case PROBE_TUR_FOR_NEGOTIATION:
1497 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1499 if (cam_periph_error(done_ccb, 0, SF_RETRY_UA,
1505 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1506 /* Don't wedge the queue */
1507 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1511 * Do Domain Validation for lun 0 on devices that claim
1512 * to support Synchronous Transfer modes.
1514 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1515 && done_ccb->ccb_h.target_lun == 0
1516 && (path->device->inq_data.flags & SID_Sync) != 0
1517 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1518 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1519 ("Begin Domain Validation\n"));
1520 path->device->flags |= CAM_DEV_IN_DV;
1521 xpt_release_ccb(done_ccb);
1522 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1523 xpt_schedule(periph, priority);
1526 if (softc->action == PROBE_DV_EXIT) {
1527 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1528 ("Leave Domain Validation\n"));
1530 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1531 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1532 xpt_acquire_device(path->device);
1534 path->device->flags &=
1535 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1536 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1537 /* Inform the XPT that a new device has been found */
1538 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1539 xpt_action(done_ccb);
1540 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1543 xpt_release_ccb(done_ccb);
1545 case PROBE_INQUIRY_BASIC_DV1:
1546 case PROBE_INQUIRY_BASIC_DV2:
1548 struct scsi_inquiry_data *nbuf;
1549 struct ccb_scsiio *csio;
1551 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1552 /* Don't wedge the queue */
1553 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1556 csio = &done_ccb->csio;
1557 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1558 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1560 "inquiry data fails comparison at DV%d step\n",
1561 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1562 if (proberequestbackoff(periph, path->device)) {
1563 path->device->flags &= ~CAM_DEV_IN_DV;
1564 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1567 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1569 free(nbuf, M_CAMXPT);
1570 xpt_release_ccb(done_ccb);
1571 xpt_schedule(periph, priority);
1574 free(nbuf, M_CAMXPT);
1575 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1576 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1577 xpt_release_ccb(done_ccb);
1578 xpt_schedule(periph, priority);
1581 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1582 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1583 ("Leave Domain Validation Successfully\n"));
1585 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1586 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1587 xpt_acquire_device(path->device);
1589 path->device->flags &=
1590 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1591 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1592 /* Inform the XPT that a new device has been found */
1593 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1594 xpt_action(done_ccb);
1595 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1598 xpt_release_ccb(done_ccb);
1602 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO,
1603 ("probedone: invalid action state\n"));
1607 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1608 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1609 done_ccb->ccb_h.status = CAM_REQ_CMP;
1611 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1612 cam_periph_invalidate(periph);
1613 cam_release_devq(periph->path,
1614 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1615 cam_periph_release_locked(periph);
1617 probeschedule(periph);
1622 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1625 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1627 for (idx = 0; idx < nlun; idx++) {
1628 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1636 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1638 struct cam_path *tp;
1639 struct scsi_report_luns_data *old;
1640 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1643 if (path->target == NULL) {
1646 if (path->target->luns == NULL) {
1647 path->target->luns = new;
1650 old = path->target->luns;
1651 nlun_old = scsi_4btoul(old->length) / 8;
1652 nlun_new = scsi_4btoul(new->length) / 8;
1655 * We are not going to assume sorted lists. Deal.
1657 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1658 ol = old->luns[idx1].lundata;
1659 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1660 nl = new->luns[idx2].lundata;
1661 if (memcmp(nl, ol, 8) == 0) {
1665 if (idx2 < nlun_new) {
1669 * An 'old' item not in the 'new' list.
1670 * Nuke it. Except that if it is lun 0,
1671 * that would be what the probe state
1672 * machine is currently working on,
1673 * so we won't do that.
1675 * We also cannot nuke it if it is
1676 * not in a lun format we understand.
1678 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1681 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1682 if (this_lun == 0) {
1685 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1686 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1687 xpt_async(AC_LOST_DEVICE, tp, NULL);
1691 free(old, M_CAMXPT);
1692 path->target->luns = new;
1696 probecleanup(struct cam_periph *periph)
1698 free(periph->softc, M_CAMXPT);
1702 scsi_find_quirk(struct cam_ed *device)
1704 struct scsi_quirk_entry *quirk;
1707 match = cam_quirkmatch((caddr_t)&device->inq_data,
1708 (caddr_t)scsi_quirk_table,
1709 sizeof(scsi_quirk_table) /
1710 sizeof(*scsi_quirk_table),
1711 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1714 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1716 quirk = (struct scsi_quirk_entry *)match;
1717 device->quirk = quirk;
1718 device->mintags = quirk->mintags;
1719 device->maxtags = quirk->maxtags;
1723 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1728 error = sysctl_handle_int(oidp, &val, 0, req);
1729 if (error != 0 || req->newptr == NULL)
1731 if (val == 0 || val == 1) {
1740 union ccb *request_ccb;
1741 struct ccb_pathinq *cpi;
1744 } scsi_scan_bus_info;
1747 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1748 * As the scan progresses, scsi_scan_bus is used as the
1749 * callback on completion function.
1752 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1754 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1755 ("scsi_scan_bus\n"));
1756 switch (request_ccb->ccb_h.func_code) {
1760 scsi_scan_bus_info *scan_info;
1761 union ccb *work_ccb, *reset_ccb;
1762 struct cam_path *path;
1764 u_int low_target, max_target;
1767 /* Find out the characteristics of the bus */
1768 work_ccb = xpt_alloc_ccb_nowait();
1769 if (work_ccb == NULL) {
1770 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1771 xpt_done(request_ccb);
1774 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1775 request_ccb->ccb_h.pinfo.priority);
1776 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1777 xpt_action(work_ccb);
1778 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1779 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1780 xpt_free_ccb(work_ccb);
1781 xpt_done(request_ccb);
1785 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1787 * Can't scan the bus on an adapter that
1788 * cannot perform the initiator role.
1790 request_ccb->ccb_h.status = CAM_REQ_CMP;
1791 xpt_free_ccb(work_ccb);
1792 xpt_done(request_ccb);
1796 /* We may need to reset bus first, if we haven't done it yet. */
1797 if ((work_ccb->cpi.hba_inquiry &
1798 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1799 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1800 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1801 reset_ccb = xpt_alloc_ccb_nowait();
1802 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1804 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1805 xpt_action(reset_ccb);
1806 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1807 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1808 xpt_free_ccb(reset_ccb);
1809 xpt_free_ccb(work_ccb);
1810 xpt_done(request_ccb);
1813 xpt_free_ccb(reset_ccb);
1816 /* Save some state for use while we probe for devices */
1817 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1818 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1819 if (scan_info == NULL) {
1820 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1821 xpt_done(request_ccb);
1824 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, request_ccb->ccb_h.path,
1825 ("SCAN start for %p\n", scan_info));
1826 scan_info->request_ccb = request_ccb;
1827 scan_info->cpi = &work_ccb->cpi;
1829 /* Cache on our stack so we can work asynchronously */
1830 max_target = scan_info->cpi->max_target;
1832 initiator_id = scan_info->cpi->initiator_id;
1836 * We can scan all targets in parallel, or do it sequentially.
1839 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1840 max_target = low_target = request_ccb->ccb_h.target_id;
1841 scan_info->counter = 0;
1842 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1844 scan_info->counter = 0;
1846 scan_info->counter = scan_info->cpi->max_target + 1;
1847 if (scan_info->cpi->initiator_id < scan_info->counter) {
1848 scan_info->counter--;
1852 for (i = low_target; i <= max_target; i++) {
1854 if (i == initiator_id)
1857 status = xpt_create_path(&path, xpt_periph,
1858 request_ccb->ccb_h.path_id,
1860 if (status != CAM_REQ_CMP) {
1861 printf("scsi_scan_bus: xpt_create_path failed"
1862 " with status %#x, bus scan halted\n",
1864 free(scan_info, M_CAMXPT);
1865 request_ccb->ccb_h.status = status;
1866 xpt_free_ccb(work_ccb);
1867 xpt_done(request_ccb);
1870 work_ccb = xpt_alloc_ccb_nowait();
1871 if (work_ccb == NULL) {
1872 xpt_free_ccb((union ccb *)scan_info->cpi);
1873 free(scan_info, M_CAMXPT);
1874 xpt_free_path(path);
1875 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1876 xpt_done(request_ccb);
1879 xpt_setup_ccb(&work_ccb->ccb_h, path,
1880 request_ccb->ccb_h.pinfo.priority);
1881 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1882 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1883 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1884 work_ccb->crcn.flags = request_ccb->crcn.flags;
1885 xpt_action(work_ccb);
1892 struct cam_path *path, *oldpath;
1893 scsi_scan_bus_info *scan_info;
1894 struct cam_et *target;
1895 struct cam_ed *device;
1898 target_id_t target_id;
1901 oldpath = request_ccb->ccb_h.path;
1903 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
1904 /* Reuse the same CCB to query if a device was really found */
1905 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1906 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1907 request_ccb->ccb_h.pinfo.priority);
1908 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1911 path_id = request_ccb->ccb_h.path_id;
1912 target_id = request_ccb->ccb_h.target_id;
1913 lun_id = request_ccb->ccb_h.target_lun;
1914 xpt_action(request_ccb);
1916 target = request_ccb->ccb_h.path->target;
1921 u_int nluns = scsi_4btoul(target->luns->length) / 8;
1924 * Make sure we skip over lun 0 if it's the first member
1925 * of the list as we've actually just finished probing
1928 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
1929 if (first == 0 && scan_info->lunindex[target_id] == 0) {
1930 scan_info->lunindex[target_id]++;
1933 if (scan_info->lunindex[target_id] < nluns) {
1934 CAM_GET_SIMPLE_LUN(target->luns,
1935 scan_info->lunindex[target_id], lun_id);
1937 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
1938 request_ccb->ccb_h.path,
1939 ("next lun to try at index %u is %u\n",
1940 scan_info->lunindex[target_id], lun_id));
1941 scan_info->lunindex[target_id]++;
1944 * We're done with scanning all luns.
1946 * Nuke the bogus device for lun 0 if lun 0
1947 * wasn't on the list.
1950 TAILQ_FOREACH(device,
1951 &target->ed_entries, links) {
1952 if (device->lun_id == 0) {
1957 xpt_release_device(device);
1961 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
1965 * If we already probed lun 0 successfully, or
1966 * we have additional configured luns on this
1967 * target that might have "gone away", go onto
1971 * We may touch devices that we don't
1972 * hold references too, so ensure they
1973 * don't disappear out from under us.
1974 * The target above is referenced by the
1975 * path in the request ccb.
1978 device = TAILQ_FIRST(&target->ed_entries);
1979 if (device != NULL) {
1980 phl = CAN_SRCH_HI_SPARSE(device);
1981 if (device->lun_id == 0)
1982 device = TAILQ_NEXT(device, links);
1984 if ((lun_id != 0) || (device != NULL)) {
1985 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
1990 if (lun_id == request_ccb->ccb_h.target_lun
1991 || lun_id > scan_info->cpi->max_lun)
1995 device = request_ccb->ccb_h.path->device;
1997 if ((SCSI_QUIRK(device)->quirks &
1998 CAM_QUIRK_NOLUNS) == 0) {
1999 /* Try the next lun */
2000 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2001 || CAN_SRCH_HI_DENSE(device)) {
2006 if (lun_id == request_ccb->ccb_h.target_lun
2007 || lun_id > scan_info->cpi->max_lun)
2012 * Check to see if we scan any further luns.
2018 * Free the current request path- we're done with it.
2020 xpt_free_path(oldpath);
2023 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2025 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2026 scan_info->counter++;
2027 if (scan_info->counter ==
2028 scan_info->cpi->initiator_id) {
2029 scan_info->counter++;
2031 if (scan_info->counter >=
2032 scan_info->cpi->max_target+1) {
2036 scan_info->counter--;
2037 if (scan_info->counter == 0) {
2042 xpt_free_ccb(request_ccb);
2043 xpt_free_ccb((union ccb *)scan_info->cpi);
2044 request_ccb = scan_info->request_ccb;
2045 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
2046 request_ccb->ccb_h.path,
2047 ("SCAN done for %p\n", scan_info));
2048 free(scan_info, M_CAMXPT);
2049 request_ccb->ccb_h.status = CAM_REQ_CMP;
2050 xpt_done(request_ccb);
2054 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2055 xpt_free_ccb(request_ccb);
2058 status = xpt_create_path(&path, xpt_periph,
2059 scan_info->request_ccb->ccb_h.path_id,
2060 scan_info->counter, 0);
2061 if (status != CAM_REQ_CMP) {
2062 printf("scsi_scan_bus: xpt_create_path failed"
2063 " with status %#x, bus scan halted\n",
2065 xpt_free_ccb(request_ccb);
2066 xpt_free_ccb((union ccb *)scan_info->cpi);
2067 request_ccb = scan_info->request_ccb;
2068 free(scan_info, M_CAMXPT);
2069 request_ccb->ccb_h.status = status;
2070 xpt_done(request_ccb);
2073 xpt_setup_ccb(&request_ccb->ccb_h, path,
2074 request_ccb->ccb_h.pinfo.priority);
2075 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2076 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2077 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2078 request_ccb->crcn.flags =
2079 scan_info->request_ccb->crcn.flags;
2081 status = xpt_create_path(&path, xpt_periph,
2082 path_id, target_id, lun_id);
2084 * Free the old request path- we're done with it. We
2085 * do this *after* creating the new path so that
2086 * we don't remove a target that has our lun list
2087 * in the case that lun 0 is not present.
2089 xpt_free_path(oldpath);
2090 if (status != CAM_REQ_CMP) {
2091 printf("scsi_scan_bus: xpt_create_path failed "
2092 "with status %#x, halting LUN scan\n",
2096 xpt_setup_ccb(&request_ccb->ccb_h, path,
2097 request_ccb->ccb_h.pinfo.priority);
2098 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2099 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2100 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2101 request_ccb->crcn.flags =
2102 scan_info->request_ccb->crcn.flags;
2104 xpt_action(request_ccb);
2113 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2114 cam_flags flags, union ccb *request_ccb)
2116 struct ccb_pathinq cpi;
2118 struct cam_path *new_path;
2119 struct cam_periph *old_periph;
2121 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2123 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2124 cpi.ccb_h.func_code = XPT_PATH_INQ;
2125 xpt_action((union ccb *)&cpi);
2127 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2128 if (request_ccb != NULL) {
2129 request_ccb->ccb_h.status = cpi.ccb_h.status;
2130 xpt_done(request_ccb);
2135 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2137 * Can't scan the bus on an adapter that
2138 * cannot perform the initiator role.
2140 if (request_ccb != NULL) {
2141 request_ccb->ccb_h.status = CAM_REQ_CMP;
2142 xpt_done(request_ccb);
2147 if (request_ccb == NULL) {
2148 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
2149 if (request_ccb == NULL) {
2150 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2151 "can't continue\n");
2154 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
2155 if (new_path == NULL) {
2156 xpt_print(path, "scsi_scan_lun: can't allocate path, "
2157 "can't continue\n");
2158 free(request_ccb, M_CAMXPT);
2161 status = xpt_compile_path(new_path, xpt_periph,
2163 path->target->target_id,
2164 path->device->lun_id);
2166 if (status != CAM_REQ_CMP) {
2167 xpt_print(path, "scsi_scan_lun: can't compile path, "
2168 "can't continue\n");
2169 free(request_ccb, M_CAMXPT);
2170 free(new_path, M_CAMXPT);
2173 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2174 request_ccb->ccb_h.cbfcnp = xptscandone;
2175 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2176 request_ccb->crcn.flags = flags;
2179 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2180 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2183 softc = (probe_softc *)old_periph->softc;
2184 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2185 &request_ccb->ccb_h, periph_links.tqe);
2187 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2188 xpt_done(request_ccb);
2191 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2192 probestart, "probe",
2194 request_ccb->ccb_h.path, NULL, 0,
2197 if (status != CAM_REQ_CMP) {
2198 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2199 "returned an error, can't continue probe\n");
2200 request_ccb->ccb_h.status = status;
2201 xpt_done(request_ccb);
2207 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2209 xpt_release_path(done_ccb->ccb_h.path);
2210 free(done_ccb->ccb_h.path, M_CAMXPT);
2211 free(done_ccb, M_CAMXPT);
2214 static struct cam_ed *
2215 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2217 struct cam_path path;
2218 struct scsi_quirk_entry *quirk;
2219 struct cam_ed *device;
2220 struct cam_ed *cur_device;
2222 device = xpt_alloc_device(bus, target, lun_id);
2227 * Take the default quirk entry until we have inquiry
2228 * data and can determine a better quirk to use.
2230 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2231 device->quirk = (void *)quirk;
2232 device->mintags = quirk->mintags;
2233 device->maxtags = quirk->maxtags;
2234 bzero(&device->inq_data, sizeof(device->inq_data));
2235 device->inq_flags = 0;
2236 device->queue_flags = 0;
2237 device->serial_num = NULL;
2238 device->serial_num_len = 0;
2241 * XXX should be limited by number of CCBs this bus can
2244 bus->sim->max_ccbs += device->ccbq.devq_openings;
2245 /* Insertion sort into our target's device list */
2246 cur_device = TAILQ_FIRST(&target->ed_entries);
2247 while (cur_device != NULL && cur_device->lun_id < lun_id)
2248 cur_device = TAILQ_NEXT(cur_device, links);
2249 if (cur_device != NULL) {
2250 TAILQ_INSERT_BEFORE(cur_device, device, links);
2252 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
2254 target->generation++;
2255 if (lun_id != CAM_LUN_WILDCARD) {
2256 xpt_compile_path(&path,
2261 scsi_devise_transport(&path);
2262 xpt_release_path(&path);
2269 scsi_devise_transport(struct cam_path *path)
2271 struct ccb_pathinq cpi;
2272 struct ccb_trans_settings cts;
2273 struct scsi_inquiry_data *inq_buf;
2275 /* Get transport information from the SIM */
2276 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2277 cpi.ccb_h.func_code = XPT_PATH_INQ;
2278 xpt_action((union ccb *)&cpi);
2281 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2282 inq_buf = &path->device->inq_data;
2283 path->device->protocol = PROTO_SCSI;
2284 path->device->protocol_version =
2285 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2286 path->device->transport = cpi.transport;
2287 path->device->transport_version = cpi.transport_version;
2290 * Any device not using SPI3 features should
2291 * be considered SPI2 or lower.
2293 if (inq_buf != NULL) {
2294 if (path->device->transport == XPORT_SPI
2295 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2296 && path->device->transport_version > 2)
2297 path->device->transport_version = 2;
2299 struct cam_ed* otherdev;
2301 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2303 otherdev = TAILQ_NEXT(otherdev, links)) {
2304 if (otherdev != path->device)
2308 if (otherdev != NULL) {
2310 * Initially assume the same versioning as
2311 * prior luns for this target.
2313 path->device->protocol_version =
2314 otherdev->protocol_version;
2315 path->device->transport_version =
2316 otherdev->transport_version;
2318 /* Until we know better, opt for safty */
2319 path->device->protocol_version = 2;
2320 if (path->device->transport == XPORT_SPI)
2321 path->device->transport_version = 2;
2323 path->device->transport_version = 0;
2329 * For a device compliant with SPC-2 we should be able
2330 * to determine the transport version supported by
2331 * scrutinizing the version descriptors in the
2335 /* Tell the controller what we think */
2336 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2337 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2338 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2339 cts.transport = path->device->transport;
2340 cts.transport_version = path->device->transport_version;
2341 cts.protocol = path->device->protocol;
2342 cts.protocol_version = path->device->protocol_version;
2343 cts.proto_specific.valid = 0;
2344 cts.xport_specific.valid = 0;
2345 xpt_action((union ccb *)&cts);
2349 scsi_action(union ccb *start_ccb)
2352 switch (start_ccb->ccb_h.func_code) {
2353 case XPT_SET_TRAN_SETTINGS:
2355 scsi_set_transfer_settings(&start_ccb->cts,
2356 start_ccb->ccb_h.path->device,
2357 /*async_update*/FALSE);
2362 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2365 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2366 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2369 case XPT_GET_TRAN_SETTINGS:
2371 struct cam_sim *sim;
2373 sim = start_ccb->ccb_h.path->bus->sim;
2374 (*(sim->sim_action))(sim, start_ccb);
2378 xpt_action_default(start_ccb);
2384 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2387 struct ccb_pathinq cpi;
2388 struct ccb_trans_settings cur_cts;
2389 struct ccb_trans_settings_scsi *scsi;
2390 struct ccb_trans_settings_scsi *cur_scsi;
2391 struct cam_sim *sim;
2392 struct scsi_inquiry_data *inq_data;
2394 if (device == NULL) {
2395 cts->ccb_h.status = CAM_PATH_INVALID;
2396 xpt_done((union ccb *)cts);
2400 if (cts->protocol == PROTO_UNKNOWN
2401 || cts->protocol == PROTO_UNSPECIFIED) {
2402 cts->protocol = device->protocol;
2403 cts->protocol_version = device->protocol_version;
2406 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2407 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2408 cts->protocol_version = device->protocol_version;
2410 if (cts->protocol != device->protocol) {
2411 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2412 cts->protocol, device->protocol);
2413 cts->protocol = device->protocol;
2416 if (cts->protocol_version > device->protocol_version) {
2418 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2419 "Version from %d to %d?\n", cts->protocol_version,
2420 device->protocol_version);
2422 cts->protocol_version = device->protocol_version;
2425 if (cts->transport == XPORT_UNKNOWN
2426 || cts->transport == XPORT_UNSPECIFIED) {
2427 cts->transport = device->transport;
2428 cts->transport_version = device->transport_version;
2431 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2432 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2433 cts->transport_version = device->transport_version;
2435 if (cts->transport != device->transport) {
2436 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2437 cts->transport, device->transport);
2438 cts->transport = device->transport;
2441 if (cts->transport_version > device->transport_version) {
2443 xpt_print(cts->ccb_h.path, "Down reving Transport "
2444 "Version from %d to %d?\n", cts->transport_version,
2445 device->transport_version);
2447 cts->transport_version = device->transport_version;
2450 sim = cts->ccb_h.path->bus->sim;
2453 * Nothing more of interest to do unless
2454 * this is a device connected via the
2457 if (cts->protocol != PROTO_SCSI) {
2458 if (async_update == FALSE)
2459 (*(sim->sim_action))(sim, (union ccb *)cts);
2463 inq_data = &device->inq_data;
2464 scsi = &cts->proto_specific.scsi;
2465 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2466 cpi.ccb_h.func_code = XPT_PATH_INQ;
2467 xpt_action((union ccb *)&cpi);
2469 /* SCSI specific sanity checking */
2470 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2471 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2472 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2473 || (device->mintags == 0)) {
2475 * Can't tag on hardware that doesn't support tags,
2476 * doesn't have it enabled, or has broken tag support.
2478 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2481 if (async_update == FALSE) {
2483 * Perform sanity checking against what the
2484 * controller and device can do.
2486 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2487 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2488 cur_cts.type = cts->type;
2489 xpt_action((union ccb *)&cur_cts);
2490 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2493 cur_scsi = &cur_cts.proto_specific.scsi;
2494 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2495 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2496 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2498 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2499 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2502 /* SPI specific sanity checking */
2503 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2505 struct ccb_trans_settings_spi *spi;
2506 struct ccb_trans_settings_spi *cur_spi;
2508 spi = &cts->xport_specific.spi;
2510 cur_spi = &cur_cts.xport_specific.spi;
2512 /* Fill in any gaps in what the user gave us */
2513 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2514 spi->sync_period = cur_spi->sync_period;
2515 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2516 spi->sync_period = 0;
2517 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2518 spi->sync_offset = cur_spi->sync_offset;
2519 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2520 spi->sync_offset = 0;
2521 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2522 spi->ppr_options = cur_spi->ppr_options;
2523 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2524 spi->ppr_options = 0;
2525 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2526 spi->bus_width = cur_spi->bus_width;
2527 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2529 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2530 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2531 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2533 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2534 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2535 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2536 && (inq_data->flags & SID_Sync) == 0
2537 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2538 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2540 spi->sync_period = 0;
2541 spi->sync_offset = 0;
2544 switch (spi->bus_width) {
2545 case MSG_EXT_WDTR_BUS_32_BIT:
2546 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2547 || (inq_data->flags & SID_WBus32) != 0
2548 || cts->type == CTS_TYPE_USER_SETTINGS)
2549 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2551 /* Fall Through to 16-bit */
2552 case MSG_EXT_WDTR_BUS_16_BIT:
2553 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2554 || (inq_data->flags & SID_WBus16) != 0
2555 || cts->type == CTS_TYPE_USER_SETTINGS)
2556 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2557 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2560 /* Fall Through to 8-bit */
2561 default: /* New bus width?? */
2562 case MSG_EXT_WDTR_BUS_8_BIT:
2563 /* All targets can do this */
2564 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2568 spi3caps = cpi.xport_specific.spi.ppr_options;
2569 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2570 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2571 spi3caps &= inq_data->spi3data;
2573 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2574 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2576 if ((spi3caps & SID_SPI_IUS) == 0)
2577 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2579 if ((spi3caps & SID_SPI_QAS) == 0)
2580 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2582 /* No SPI Transfer settings are allowed unless we are wide */
2583 if (spi->bus_width == 0)
2584 spi->ppr_options = 0;
2586 if ((spi->valid & CTS_SPI_VALID_DISC)
2587 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2589 * Can't tag queue without disconnection.
2591 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2592 scsi->valid |= CTS_SCSI_VALID_TQ;
2596 * If we are currently performing tagged transactions to
2597 * this device and want to change its negotiation parameters,
2598 * go non-tagged for a bit to give the controller a chance to
2599 * negotiate unhampered by tag messages.
2601 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2602 && (device->inq_flags & SID_CmdQue) != 0
2603 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2604 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2605 CTS_SPI_VALID_SYNC_OFFSET|
2606 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2607 scsi_toggle_tags(cts->ccb_h.path);
2610 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2611 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2615 * If we are transitioning from tags to no-tags or
2616 * vice-versa, we need to carefully freeze and restart
2617 * the queue so that we don't overlap tagged and non-tagged
2618 * commands. We also temporarily stop tags if there is
2619 * a change in transfer negotiation settings to allow
2620 * "tag-less" negotiation.
2622 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2623 || (device->inq_flags & SID_CmdQue) != 0)
2624 device_tagenb = TRUE;
2626 device_tagenb = FALSE;
2628 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2629 && device_tagenb == FALSE)
2630 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2631 && device_tagenb == TRUE)) {
2633 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2635 * Delay change to use tags until after a
2636 * few commands have gone to this device so
2637 * the controller has time to perform transfer
2638 * negotiations without tagged messages getting
2641 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2642 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2644 xpt_stop_tags(cts->ccb_h.path);
2648 if (async_update == FALSE)
2649 (*(sim->sim_action))(sim, (union ccb *)cts);
2653 scsi_toggle_tags(struct cam_path *path)
2658 * Give controllers a chance to renegotiate
2659 * before starting tag operations. We
2660 * "toggle" tagged queuing off then on
2661 * which causes the tag enable command delay
2662 * counter to come into effect.
2665 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2666 || ((dev->inq_flags & SID_CmdQue) != 0
2667 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2668 struct ccb_trans_settings cts;
2670 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2671 cts.protocol = PROTO_SCSI;
2672 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2673 cts.transport = XPORT_UNSPECIFIED;
2674 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2675 cts.proto_specific.scsi.flags = 0;
2676 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2677 scsi_set_transfer_settings(&cts, path->device,
2678 /*async_update*/TRUE);
2679 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2680 scsi_set_transfer_settings(&cts, path->device,
2681 /*async_update*/TRUE);
2686 * Handle any per-device event notifications that require action by the XPT.
2689 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2690 struct cam_ed *device, void *async_arg)
2693 struct cam_path newpath;
2696 * We only need to handle events for real devices.
2698 if (target->target_id == CAM_TARGET_WILDCARD
2699 || device->lun_id == CAM_LUN_WILDCARD)
2703 * We need our own path with wildcards expanded to
2704 * handle certain types of events.
2706 if ((async_code == AC_SENT_BDR)
2707 || (async_code == AC_BUS_RESET)
2708 || (async_code == AC_INQ_CHANGED))
2709 status = xpt_compile_path(&newpath, NULL,
2714 status = CAM_REQ_CMP_ERR;
2716 if (status == CAM_REQ_CMP) {
2719 * Allow transfer negotiation to occur in a
2720 * tag free environment and after settle delay.
2722 if (async_code == AC_SENT_BDR
2723 || async_code == AC_BUS_RESET) {
2724 cam_freeze_devq(&newpath);
2725 cam_release_devq(&newpath,
2726 RELSIM_RELEASE_AFTER_TIMEOUT,
2728 /*timeout*/scsi_delay,
2729 /*getcount_only*/0);
2730 scsi_toggle_tags(&newpath);
2733 if (async_code == AC_INQ_CHANGED) {
2735 * We've sent a start unit command, or
2736 * something similar to a device that
2737 * may have caused its inquiry data to
2738 * change. So we re-scan the device to
2739 * refresh the inquiry data for it.
2741 scsi_scan_lun(newpath.periph, &newpath,
2742 CAM_EXPECT_INQ_CHANGE, NULL);
2744 xpt_release_path(&newpath);
2745 } else if (async_code == AC_LOST_DEVICE &&
2746 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2747 device->flags |= CAM_DEV_UNCONFIGURED;
2748 xpt_release_device(device);
2749 } else if (async_code == AC_TRANSFER_NEG) {
2750 struct ccb_trans_settings *settings;
2752 settings = (struct ccb_trans_settings *)async_arg;
2753 scsi_set_transfer_settings(settings, device,
2754 /*async_update*/TRUE);
2759 scsi_announce_periph(struct cam_periph *periph)
2761 struct ccb_pathinq cpi;
2762 struct ccb_trans_settings cts;
2763 struct cam_path *path = periph->path;
2768 mtx_assert(periph->sim->mtx, MA_OWNED);
2770 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2771 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2772 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2773 xpt_action((union ccb*)&cts);
2774 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2776 /* Ask the SIM for its base transfer speed */
2777 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2778 cpi.ccb_h.func_code = XPT_PATH_INQ;
2779 xpt_action((union ccb *)&cpi);
2780 /* Report connection speed */
2781 speed = cpi.base_transfer_speed;
2783 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2784 struct ccb_trans_settings_spi *spi =
2785 &cts.xport_specific.spi;
2787 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2788 && spi->sync_offset != 0) {
2789 freq = scsi_calc_syncsrate(spi->sync_period);
2792 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2793 speed *= (0x01 << spi->bus_width);
2795 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2796 struct ccb_trans_settings_fc *fc =
2797 &cts.xport_specific.fc;
2799 if (fc->valid & CTS_FC_VALID_SPEED)
2800 speed = fc->bitrate;
2802 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2803 struct ccb_trans_settings_sas *sas =
2804 &cts.xport_specific.sas;
2806 if (sas->valid & CTS_SAS_VALID_SPEED)
2807 speed = sas->bitrate;
2811 printf("%s%d: %d.%03dMB/s transfers",
2812 periph->periph_name, periph->unit_number,
2815 printf("%s%d: %dKB/s transfers", periph->periph_name,
2816 periph->unit_number, speed);
2817 /* Report additional information about SPI connections */
2818 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2819 struct ccb_trans_settings_spi *spi;
2821 spi = &cts.xport_specific.spi;
2823 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2825 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2829 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2830 && spi->bus_width > 0) {
2836 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2837 } else if (freq != 0) {
2841 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2842 struct ccb_trans_settings_fc *fc;
2844 fc = &cts.xport_specific.fc;
2845 if (fc->valid & CTS_FC_VALID_WWNN)
2846 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2847 if (fc->valid & CTS_FC_VALID_WWPN)
2848 printf(" WWPN 0x%llx", (long long) fc->wwpn);
2849 if (fc->valid & CTS_FC_VALID_PORT)
2850 printf(" PortID 0x%x", fc->port);