2 * Implementation of the SCSI Transport
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/types.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
41 #include <sys/fcntl.h>
43 #include <sys/interrupt.h>
47 #include <sys/mutex.h>
48 #include <sys/sysctl.h>
51 #include <cam/cam_ccb.h>
52 #include <cam/cam_queue.h>
53 #include <cam/cam_periph.h>
54 #include <cam/cam_sim.h>
55 #include <cam/cam_xpt.h>
56 #include <cam/cam_xpt_sim.h>
57 #include <cam/cam_xpt_periph.h>
58 #include <cam/cam_xpt_internal.h>
59 #include <cam/cam_debug.h>
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/scsi/scsi_message.h>
63 #include <cam/scsi/scsi_pass.h>
64 #include <machine/stdarg.h> /* for xpt_print below */
67 struct scsi_quirk_entry {
68 struct scsi_inquiry_pattern inq_pat;
70 #define CAM_QUIRK_NOLUNS 0x01
71 #define CAM_QUIRK_NOVPDS 0x02
72 #define CAM_QUIRK_HILUNS 0x04
73 #define CAM_QUIRK_NOHILUNS 0x08
74 #define CAM_QUIRK_NORPTLUNS 0x10
78 #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk))
80 static int cam_srch_hi = 0;
81 TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi);
82 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
83 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
84 sysctl_cam_search_luns, "I",
85 "allow search above LUN 7 for SCSI3 and greater devices");
87 #define CAM_SCSI2_MAXLUN 8
88 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \
89 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
90 RPL_LUNDATA_ATYP_PERIPH) || \
91 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
92 RPL_LUNDATA_ATYP_FLAT))
93 #define CAM_GET_SIMPLE_LUN(lp, i, lval) \
94 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
95 RPL_LUNDATA_ATYP_PERIPH) { \
96 (lval) = (lp)->luns[(i)].lundata[1]; \
98 (lval) = (lp)->luns[(i)].lundata[0]; \
99 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \
101 (lval) |= (lp)->luns[(i)].lundata[1]; \
103 #define CAM_GET_LUN(lp, i, lval) \
104 (lval) = scsi_4btoul((lp)->luns[(i)].lundata); \
105 (lval) = ((lval) >> 16) | ((lval) << 16);
106 #define CAM_LUN_ONLY_32BITS(lp, i) \
107 (scsi_4btoul(&((lp)->luns[(i)].lundata[4])) == 0)
110 * If we're not quirked to search <= the first 8 luns
111 * and we are either quirked to search above lun 8,
112 * or we're > SCSI-2 and we've enabled hilun searching,
113 * or we're > SCSI-2 and the last lun was a success,
114 * we can look for luns above lun 8.
116 #define CAN_SRCH_HI_SPARSE(dv) \
117 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
118 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
119 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
121 #define CAN_SRCH_HI_DENSE(dv) \
122 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
123 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
124 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
126 static periph_init_t probe_periph_init;
128 static struct periph_driver probe_driver =
130 probe_periph_init, "probe",
131 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
135 PERIPHDRIVER_DECLARE(probe, probe_driver);
139 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
143 PROBE_SUPPORTED_VPD_LIST,
146 PROBE_TUR_FOR_NEGOTIATION,
147 PROBE_INQUIRY_BASIC_DV1,
148 PROBE_INQUIRY_BASIC_DV2,
154 static char *probe_action_text[] = {
157 "PROBE_FULL_INQUIRY",
160 "PROBE_SUPPORTED_VPD_LIST",
163 "PROBE_TUR_FOR_NEGOTIATION",
164 "PROBE_INQUIRY_BASIC_DV1",
165 "PROBE_INQUIRY_BASIC_DV2",
171 #define PROBE_SET_ACTION(softc, newaction) \
174 text = probe_action_text; \
175 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
176 ("Probe %s to %s\n", text[(softc)->action], \
177 text[(newaction)])); \
178 (softc)->action = (newaction); \
182 PROBE_INQUIRY_CKSUM = 0x01,
183 PROBE_SERIAL_CKSUM = 0x02,
184 PROBE_NO_ANNOUNCE = 0x04,
189 TAILQ_HEAD(, ccb_hdr) request_ccbs;
195 struct cam_periph *periph;
198 static const char quantum[] = "QUANTUM";
199 static const char sony[] = "SONY";
200 static const char west_digital[] = "WDIGTL";
201 static const char samsung[] = "SAMSUNG";
202 static const char seagate[] = "SEAGATE";
203 static const char microp[] = "MICROP";
205 static struct scsi_quirk_entry scsi_quirk_table[] =
208 /* Reports QUEUE FULL for temporary resource shortages */
209 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
210 /*quirks*/0, /*mintags*/24, /*maxtags*/32
213 /* Reports QUEUE FULL for temporary resource shortages */
214 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
215 /*quirks*/0, /*mintags*/24, /*maxtags*/32
218 /* Reports QUEUE FULL for temporary resource shortages */
219 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
220 /*quirks*/0, /*mintags*/24, /*maxtags*/32
223 /* Broken tagged queuing drive */
224 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
225 /*quirks*/0, /*mintags*/0, /*maxtags*/0
228 /* Broken tagged queuing drive */
229 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
230 /*quirks*/0, /*mintags*/0, /*maxtags*/0
233 /* Broken tagged queuing drive */
234 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
235 /*quirks*/0, /*mintags*/0, /*maxtags*/0
239 * Unfortunately, the Quantum Atlas III has the same
240 * problem as the Atlas II drives above.
241 * Reported by: "Johan Granlund" <johan@granlund.nu>
243 * For future reference, the drive with the problem was:
244 * QUANTUM QM39100TD-SW N1B0
246 * It's possible that Quantum will fix the problem in later
247 * firmware revisions. If that happens, the quirk entry
248 * will need to be made specific to the firmware revisions
252 /* Reports QUEUE FULL for temporary resource shortages */
253 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
254 /*quirks*/0, /*mintags*/24, /*maxtags*/32
258 * 18 Gig Atlas III, same problem as the 9G version.
259 * Reported by: Andre Albsmeier
260 * <andre.albsmeier@mchp.siemens.de>
262 * For future reference, the drive with the problem was:
263 * QUANTUM QM318000TD-S N491
265 /* Reports QUEUE FULL for temporary resource shortages */
266 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
267 /*quirks*/0, /*mintags*/24, /*maxtags*/32
271 * Broken tagged queuing drive
272 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
273 * and: Martin Renters <martin@tdc.on.ca>
275 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
276 /*quirks*/0, /*mintags*/0, /*maxtags*/0
279 * The Seagate Medalist Pro drives have very poor write
280 * performance with anything more than 2 tags.
282 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
283 * Drive: <SEAGATE ST36530N 1444>
285 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
286 * Drive: <SEAGATE ST34520W 1281>
288 * No one has actually reported that the 9G version
289 * (ST39140*) of the Medalist Pro has the same problem, but
290 * we're assuming that it does because the 4G and 6.5G
291 * versions of the drive are broken.
294 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
295 /*quirks*/0, /*mintags*/2, /*maxtags*/2
298 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
299 /*quirks*/0, /*mintags*/2, /*maxtags*/2
302 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
303 /*quirks*/0, /*mintags*/2, /*maxtags*/2
307 * Experiences command timeouts under load with a
308 * tag count higher than 55.
310 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
311 /*quirks*/0, /*mintags*/2, /*maxtags*/55
315 * Slow when tagged queueing is enabled. Write performance
316 * steadily drops off with more and more concurrent
317 * transactions. Best sequential write performance with
318 * tagged queueing turned off and write caching turned on.
321 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
322 * Drive: DCAS-34330 w/ "S65A" firmware.
324 * The drive with the problem had the "S65A" firmware
325 * revision, and has also been reported (by Stephen J.
326 * Roznowski <sjr@home.net>) for a drive with the "S61A"
329 * Although no one has reported problems with the 2 gig
330 * version of the DCAS drive, the assumption is that it
331 * has the same problems as the 4 gig version. Therefore
332 * this quirk entries disables tagged queueing for all
335 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
336 /*quirks*/0, /*mintags*/0, /*maxtags*/0
339 /* Broken tagged queuing drive */
340 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
341 /*quirks*/0, /*mintags*/0, /*maxtags*/0
344 /* Broken tagged queuing drive */
345 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
346 /*quirks*/0, /*mintags*/0, /*maxtags*/0
349 /* This does not support other than LUN 0 */
350 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
351 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
355 * Broken tagged queuing drive.
357 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
360 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
361 /*quirks*/0, /*mintags*/0, /*maxtags*/0
365 * Slow when tagged queueing is enabled. (1.5MB/sec versus
367 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
368 * Best performance with these drives is achieved with
369 * tagged queueing turned off, and write caching turned on.
371 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
372 /*quirks*/0, /*mintags*/0, /*maxtags*/0
376 * Slow when tagged queueing is enabled. (1.5MB/sec versus
378 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
379 * Best performance with these drives is achieved with
380 * tagged queueing turned off, and write caching turned on.
382 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
383 /*quirks*/0, /*mintags*/0, /*maxtags*/0
387 * Doesn't handle queue full condition correctly,
388 * so we need to limit maxtags to what the device
389 * can handle instead of determining this automatically.
391 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
392 /*quirks*/0, /*mintags*/2, /*maxtags*/32
395 /* Really only one LUN */
396 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
397 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
400 /* I can't believe we need a quirk for DPT volumes. */
401 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
403 /*mintags*/0, /*maxtags*/255
407 * Many Sony CDROM drives don't like multi-LUN probing.
409 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
410 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
414 * This drive doesn't like multiple LUN probing.
415 * Submitted by: Parag Patel <parag@cgt.com>
417 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
418 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
421 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
422 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
426 * The 8200 doesn't like multi-lun probing, and probably
427 * don't like serial number requests either.
430 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
433 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
437 * Let's try the same as above, but for a drive that says
438 * it's an IPL-6860 but is actually an EXB 8200.
441 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
444 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
448 * These Hitachi drives don't like multi-lun probing.
449 * The PR submitter has a DK319H, but says that the Linux
450 * kernel has a similar work-around for the DK312 and DK314,
451 * so all DK31* drives are quirked here.
453 * Submitted by: Paul Haddad <paul@pth.com>
455 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
456 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
460 * The Hitachi CJ series with J8A8 firmware apparantly has
461 * problems with tagged commands.
463 * Reported by: amagai@nue.org
465 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
466 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
470 * These are the large storage arrays.
471 * Submitted by: William Carrel <william.carrel@infospace.com>
473 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
474 CAM_QUIRK_HILUNS, 2, 1024
478 * This old revision of the TDC3600 is also SCSI-1, and
479 * hangs upon serial number probing.
482 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
485 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
489 * Would repond to all LUNs if asked for.
492 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
495 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
499 * Would repond to all LUNs if asked for.
502 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
505 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
508 /* Submitted by: Matthew Dodd <winter@jurai.net> */
509 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
510 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
513 /* Submitted by: Matthew Dodd <winter@jurai.net> */
514 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
515 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
518 /* TeraSolutions special settings for TRC-22 RAID */
519 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
520 /*quirks*/0, /*mintags*/55, /*maxtags*/255
523 /* Veritas Storage Appliance */
524 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
525 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
529 * Would respond to all LUNs. Device type and removable
530 * flag are jumper-selectable.
532 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
535 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
538 /* EasyRAID E5A aka. areca ARC-6010 */
539 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
540 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
543 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
544 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
547 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
548 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
551 /* Default tagged queuing parameters for all devices */
553 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
554 /*vendor*/"*", /*product*/"*", /*revision*/"*"
556 /*quirks*/0, /*mintags*/2, /*maxtags*/255
560 static const int scsi_quirk_table_size =
561 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
563 static cam_status proberegister(struct cam_periph *periph,
565 static void probeschedule(struct cam_periph *probe_periph);
566 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
567 static void proberequestdefaultnegotiation(struct cam_periph *periph);
568 static int proberequestbackoff(struct cam_periph *periph,
569 struct cam_ed *device);
570 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
571 static void probe_purge_old(struct cam_path *path,
572 struct scsi_report_luns_data *new,
574 static void probecleanup(struct cam_periph *periph);
575 static void scsi_find_quirk(struct cam_ed *device);
576 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
577 static void scsi_scan_lun(struct cam_periph *periph,
578 struct cam_path *path, cam_flags flags,
580 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
581 static struct cam_ed *
582 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
584 static void scsi_devise_transport(struct cam_path *path);
585 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
586 struct cam_path *path,
588 static void scsi_toggle_tags(struct cam_path *path);
589 static void scsi_dev_async(u_int32_t async_code,
591 struct cam_et *target,
592 struct cam_ed *device,
594 static void scsi_action(union ccb *start_ccb);
595 static void scsi_announce_periph(struct cam_periph *periph);
597 static struct xpt_xport scsi_xport = {
598 .alloc_device = scsi_alloc_device,
599 .action = scsi_action,
600 .async = scsi_dev_async,
601 .announce = scsi_announce_periph,
607 return (&scsi_xport);
616 proberegister(struct cam_periph *periph, void *arg)
618 union ccb *request_ccb; /* CCB representing the probe request */
622 request_ccb = (union ccb *)arg;
623 if (request_ccb == NULL) {
624 printf("proberegister: no probe CCB, "
625 "can't register device\n");
626 return(CAM_REQ_CMP_ERR);
629 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
632 printf("proberegister: Unable to probe new device. "
633 "Unable to allocate softc\n");
634 return(CAM_REQ_CMP_ERR);
636 TAILQ_INIT(&softc->request_ccbs);
637 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
640 periph->softc = softc;
641 softc->periph = periph;
642 softc->action = PROBE_INVALID;
643 status = cam_periph_acquire(periph);
644 if (status != CAM_REQ_CMP) {
647 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
648 scsi_devise_transport(periph->path);
651 * Ensure we've waited at least a bus settle
652 * delay before attempting to probe the device.
653 * For HBAs that don't do bus resets, this won't make a difference.
655 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
657 probeschedule(periph);
662 probeschedule(struct cam_periph *periph)
664 struct ccb_pathinq cpi;
668 softc = (probe_softc *)periph->softc;
669 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
671 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
672 cpi.ccb_h.func_code = XPT_PATH_INQ;
673 xpt_action((union ccb *)&cpi);
676 * If a device has gone away and another device, or the same one,
677 * is back in the same place, it should have a unit attention
678 * condition pending. It will not report the unit attention in
679 * response to an inquiry, which may leave invalid transfer
680 * negotiations in effect. The TUR will reveal the unit attention
681 * condition. Only send the TUR for lun 0, since some devices
682 * will get confused by commands other than inquiry to non-existent
683 * luns. If you think a device has gone away start your scan from
684 * lun 0. This will insure that any bogus transfer settings are
687 * If we haven't seen the device before and the controller supports
688 * some kind of transfer negotiation, negotiate with the first
689 * sent command if no bus reset was performed at startup. This
690 * ensures that the device is not confused by transfer negotiation
691 * settings left over by loader or BIOS action.
693 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
694 && (ccb->ccb_h.target_lun == 0)) {
695 PROBE_SET_ACTION(softc, PROBE_TUR);
696 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
697 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
698 proberequestdefaultnegotiation(periph);
699 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
701 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
704 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
705 softc->flags |= PROBE_NO_ANNOUNCE;
707 softc->flags &= ~PROBE_NO_ANNOUNCE;
709 if (cpi.hba_misc & PIM_EXTLUNS)
710 softc->flags |= PROBE_EXTLUN;
712 softc->flags &= ~PROBE_EXTLUN;
714 xpt_schedule(periph, CAM_PRIORITY_XPT);
718 probestart(struct cam_periph *periph, union ccb *start_ccb)
720 /* Probe the device that our peripheral driver points to */
721 struct ccb_scsiio *csio;
724 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
726 softc = (probe_softc *)periph->softc;
727 csio = &start_ccb->csio;
730 switch (softc->action) {
732 case PROBE_TUR_FOR_NEGOTIATION:
735 scsi_test_unit_ready(csio,
744 case PROBE_FULL_INQUIRY:
745 case PROBE_INQUIRY_BASIC_DV1:
746 case PROBE_INQUIRY_BASIC_DV2:
749 struct scsi_inquiry_data *inq_buf;
751 inq_buf = &periph->path->device->inq_data;
754 * If the device is currently configured, we calculate an
755 * MD5 checksum of the inquiry data, and if the serial number
756 * length is greater than 0, add the serial number data
757 * into the checksum as well. Once the inquiry and the
758 * serial number check finish, we attempt to figure out
759 * whether we still have the same device.
761 if (((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
762 && ((softc->flags & PROBE_INQUIRY_CKSUM) == 0)) {
764 MD5Init(&softc->context);
765 MD5Update(&softc->context, (unsigned char *)inq_buf,
766 sizeof(struct scsi_inquiry_data));
767 softc->flags |= PROBE_INQUIRY_CKSUM;
768 if (periph->path->device->serial_num_len > 0) {
769 MD5Update(&softc->context,
770 periph->path->device->serial_num,
771 periph->path->device->serial_num_len);
772 softc->flags |= PROBE_SERIAL_CKSUM;
774 MD5Final(softc->digest, &softc->context);
777 if (softc->action == PROBE_INQUIRY)
778 inquiry_len = SHORT_INQUIRY_LENGTH;
780 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
783 * Some parallel SCSI devices fail to send an
784 * ignore wide residue message when dealing with
785 * odd length inquiry requests. Round up to be
788 inquiry_len = roundup2(inquiry_len, 2);
790 if (softc->action == PROBE_INQUIRY_BASIC_DV1
791 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
792 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
794 if (inq_buf == NULL) {
795 xpt_print(periph->path, "malloc failure- skipping Basic"
796 "Domain Validation\n");
797 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
798 scsi_test_unit_ready(csio,
815 /*timeout*/60 * 1000);
818 case PROBE_REPORT_LUNS:
822 rp = malloc(periph->path->target->rpl_size,
823 M_CAMXPT, M_NOWAIT | M_ZERO);
825 struct scsi_inquiry_data *inq_buf;
826 inq_buf = &periph->path->device->inq_data;
827 xpt_print(periph->path,
828 "Unable to alloc report luns storage\n");
829 if (INQ_DATA_TQ_ENABLED(inq_buf))
830 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
832 PROBE_SET_ACTION(softc,
833 PROBE_SUPPORTED_VPD_LIST);
836 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
837 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
838 SSD_FULL_SIZE, 60000); break;
841 case PROBE_MODE_SENSE:
846 mode_buf_len = sizeof(struct scsi_mode_header_6)
847 + sizeof(struct scsi_mode_blk_desc)
848 + sizeof(struct scsi_control_page);
849 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
850 if (mode_buf != NULL) {
851 scsi_mode_sense(csio,
856 SMS_PAGE_CTRL_CURRENT,
857 SMS_CONTROL_MODE_PAGE,
864 xpt_print(periph->path, "Unable to mode sense control page - "
866 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
869 case PROBE_SUPPORTED_VPD_LIST:
871 struct scsi_vpd_supported_page_list *vpd_list;
872 struct cam_ed *device;
875 device = periph->path->device;
877 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
878 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
881 if (vpd_list != NULL) {
886 (u_int8_t *)vpd_list,
889 SVPD_SUPPORTED_PAGE_LIST,
891 /*timeout*/60 * 1000);
896 * We'll have to do without, let our probedone
897 * routine finish up for us.
899 start_ccb->csio.data_ptr = NULL;
900 cam_freeze_devq(periph->path);
901 cam_periph_doacquire(periph);
902 probedone(periph, start_ccb);
905 case PROBE_DEVICE_ID:
907 struct scsi_vpd_device_id *devid;
910 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
911 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
920 SVPD_DEVICE_ID_MAX_SIZE,
924 /*timeout*/60 * 1000);
929 case PROBE_SERIAL_NUM:
931 struct scsi_vpd_unit_serial_number *serial_buf;
932 struct cam_ed* device;
935 device = periph->path->device;
936 if (device->serial_num != NULL) {
937 free(device->serial_num, M_CAMXPT);
938 device->serial_num = NULL;
939 device->serial_num_len = 0;
942 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
943 serial_buf = (struct scsi_vpd_unit_serial_number *)
944 malloc(sizeof(*serial_buf), M_CAMXPT,
947 if (serial_buf != NULL) {
952 (u_int8_t *)serial_buf,
955 SVPD_UNIT_SERIAL_NUMBER,
957 /*timeout*/60 * 1000);
963 panic("probestart: invalid action state 0x%x\n", softc->action);
965 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
966 cam_periph_doacquire(periph);
967 xpt_action(start_ccb);
971 proberequestdefaultnegotiation(struct cam_periph *periph)
973 struct ccb_trans_settings cts;
975 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
976 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
977 cts.type = CTS_TYPE_USER_SETTINGS;
978 xpt_action((union ccb *)&cts);
979 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
982 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
983 cts.type = CTS_TYPE_CURRENT_SETTINGS;
984 xpt_action((union ccb *)&cts);
988 * Backoff Negotiation Code- only pertinent for SPI devices.
991 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
993 struct ccb_trans_settings cts;
994 struct ccb_trans_settings_spi *spi;
996 memset(&cts, 0, sizeof (cts));
997 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
998 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
999 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1000 xpt_action((union ccb *)&cts);
1001 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1003 xpt_print(periph->path,
1004 "failed to get current device settings\n");
1008 if (cts.transport != XPORT_SPI) {
1010 xpt_print(periph->path, "not SPI transport\n");
1014 spi = &cts.xport_specific.spi;
1017 * We cannot renegotiate sync rate if we don't have one.
1019 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1021 xpt_print(periph->path, "no sync rate known\n");
1027 * We'll assert that we don't have to touch PPR options- the
1028 * SIM will see what we do with period and offset and adjust
1029 * the PPR options as appropriate.
1033 * A sync rate with unknown or zero offset is nonsensical.
1034 * A sync period of zero means Async.
1036 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1037 || spi->sync_offset == 0 || spi->sync_period == 0) {
1039 xpt_print(periph->path, "no sync rate available\n");
1044 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1045 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1046 ("hit async: giving up on DV\n"));
1052 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1053 * We don't try to remember 'last' settings to see if the SIM actually
1054 * gets into the speed we want to set. We check on the SIM telling
1055 * us that a requested speed is bad, but otherwise don't try and
1056 * check the speed due to the asynchronous and handshake nature
1059 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1062 if (spi->sync_period >= 0xf) {
1063 spi->sync_period = 0;
1064 spi->sync_offset = 0;
1065 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1066 ("setting to async for DV\n"));
1068 * Once we hit async, we don't want to try
1069 * any more settings.
1071 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1072 } else if (bootverbose) {
1073 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1074 ("DV: period 0x%x\n", spi->sync_period));
1075 printf("setting period to 0x%x\n", spi->sync_period);
1077 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1078 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1079 xpt_action((union ccb *)&cts);
1080 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1083 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1084 ("DV: failed to set period 0x%x\n", spi->sync_period));
1085 if (spi->sync_period == 0) {
1092 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1095 probedone(struct cam_periph *periph, union ccb *done_ccb)
1098 struct cam_path *path;
1101 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1103 softc = (probe_softc *)periph->softc;
1104 path = done_ccb->ccb_h.path;
1105 priority = done_ccb->ccb_h.pinfo.priority;
1107 switch (softc->action) {
1110 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1112 if (cam_periph_error(done_ccb, 0,
1113 SF_NO_PRINT, NULL) == ERESTART) {
1115 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1116 cam_release_devq(path, 0, 0, 0, FALSE);
1119 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1120 /* Don't wedge the queue */
1121 xpt_release_devq(done_ccb->ccb_h.path,
1125 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1126 xpt_release_ccb(done_ccb);
1127 xpt_schedule(periph, priority);
1129 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1130 cam_release_devq(path, 0, 0, 0, FALSE);
1131 cam_periph_release_locked(periph);
1135 case PROBE_FULL_INQUIRY:
1137 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1138 struct scsi_inquiry_data *inq_buf;
1139 u_int8_t periph_qual;
1141 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1142 scsi_find_quirk(path->device);
1143 inq_buf = &path->device->inq_data;
1145 periph_qual = SID_QUAL(inq_buf);
1147 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1151 * We conservatively request only
1152 * SHORT_INQUIRY_LEN bytes of inquiry
1153 * information during our first try
1154 * at sending an INQUIRY. If the device
1155 * has more information to give,
1156 * perform a second request specifying
1157 * the amount of information the device
1158 * is willing to give.
1160 len = inq_buf->additional_length
1161 + offsetof(struct scsi_inquiry_data,
1162 additional_length) + 1;
1163 if (softc->action == PROBE_INQUIRY
1164 && len > SHORT_INQUIRY_LENGTH) {
1165 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1166 xpt_release_ccb(done_ccb);
1167 xpt_schedule(periph, priority);
1171 scsi_devise_transport(path);
1173 if (path->device->lun_id == 0 &&
1174 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1175 (SCSI_QUIRK(path->device)->quirks &
1176 CAM_QUIRK_NORPTLUNS) == 0) {
1177 PROBE_SET_ACTION(softc,
1180 * Start with room for *one* lun.
1182 periph->path->target->rpl_size = 16;
1183 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1184 PROBE_SET_ACTION(softc,
1187 PROBE_SET_ACTION(softc,
1188 PROBE_SUPPORTED_VPD_LIST);
1190 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1191 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1192 xpt_acquire_device(path->device);
1194 xpt_release_ccb(done_ccb);
1195 xpt_schedule(periph, priority);
1197 } else if (path->device->lun_id == 0 &&
1198 SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 &&
1199 (SCSI_QUIRK(path->device)->quirks &
1200 CAM_QUIRK_NORPTLUNS) == 0) {
1201 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1202 periph->path->target->rpl_size = 16;
1203 xpt_release_ccb(done_ccb);
1204 xpt_schedule(periph, priority);
1207 } else if (cam_periph_error(done_ccb, 0,
1208 done_ccb->ccb_h.target_lun > 0
1209 ? SF_RETRY_UA|SF_QUIET_IR
1211 &softc->saved_ccb) == ERESTART) {
1214 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1215 /* Don't wedge the queue */
1216 xpt_release_devq(done_ccb->ccb_h.path,
1217 /*count*/1, /*run_queue*/TRUE);
1219 path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID;
1222 * If we get to this point, we got an error status back
1223 * from the inquiry and the error status doesn't require
1224 * automatically retrying the command. Therefore, the
1225 * inquiry failed. If we had inquiry information before
1226 * for this device, but this latest inquiry command failed,
1227 * the device has probably gone away. If this device isn't
1228 * already marked unconfigured, notify the peripheral
1229 * drivers that this device is no more.
1231 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1232 /* Send the async notification. */
1233 xpt_async(AC_LOST_DEVICE, path, NULL);
1234 PROBE_SET_ACTION(softc, PROBE_INVALID);
1236 xpt_release_ccb(done_ccb);
1239 case PROBE_REPORT_LUNS:
1241 struct ccb_scsiio *csio;
1242 struct scsi_report_luns_data *lp;
1245 csio = &done_ccb->csio;
1247 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1248 nlun = scsi_4btoul(lp->length) / 8;
1249 maxlun = (csio->dxfer_len / 8) - 1;
1251 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1252 if (cam_periph_error(done_ccb, 0,
1253 done_ccb->ccb_h.target_lun > 0 ?
1254 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1255 &softc->saved_ccb) == ERESTART) {
1258 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1259 xpt_release_devq(done_ccb->ccb_h.path, 1,
1264 } else if (nlun > maxlun) {
1266 * Reallocate and retry to cover all luns
1268 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1269 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1272 path->target->rpl_size = (nlun << 3) + 8;
1273 xpt_release_ccb(done_ccb);
1274 xpt_schedule(periph, priority);
1276 } else if (nlun == 0) {
1278 * If there don't appear to be any luns, bail.
1286 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1287 ("Probe: %u lun(s) reported\n", nlun));
1289 CAM_GET_LUN(lp, 0, lun);
1291 * If the first lun is not lun 0, then either there
1292 * is no lun 0 in the list, or the list is unsorted.
1295 for (idx = 0; idx < nlun; idx++) {
1296 CAM_GET_LUN(lp, idx, lun);
1304 lp->luns[0].lundata, 8);
1305 memcpy(lp->luns[0].lundata,
1306 lp->luns[idx].lundata, 8);
1307 memcpy(lp->luns[idx].lundata,
1309 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1310 ("lun 0 in position %u\n", idx));
1314 * If we have an old lun list, We can either
1315 * retest luns that appear to have been dropped,
1316 * or just nuke them. We'll opt for the latter.
1317 * This function will also install the new list
1318 * in the target structure.
1320 probe_purge_old(path, lp, softc->flags);
1323 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID &&
1324 SID_QUAL(&path->device->inq_data) == SID_QUAL_LU_CONNECTED) {
1325 struct scsi_inquiry_data *inq_buf;
1326 inq_buf = &path->device->inq_data;
1327 if (INQ_DATA_TQ_ENABLED(inq_buf))
1328 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1330 PROBE_SET_ACTION(softc,
1331 PROBE_SUPPORTED_VPD_LIST);
1332 xpt_release_ccb(done_ccb);
1333 xpt_schedule(periph, priority);
1339 PROBE_SET_ACTION(softc, PROBE_INVALID);
1340 xpt_release_ccb(done_ccb);
1343 case PROBE_MODE_SENSE:
1345 struct ccb_scsiio *csio;
1346 struct scsi_mode_header_6 *mode_hdr;
1348 csio = &done_ccb->csio;
1349 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1350 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1351 struct scsi_control_page *page;
1354 offset = ((u_int8_t *)&mode_hdr[1])
1355 + mode_hdr->blk_desc_len;
1356 page = (struct scsi_control_page *)offset;
1357 path->device->queue_flags = page->queue_flags;
1358 } else if (cam_periph_error(done_ccb, 0,
1359 SF_RETRY_UA|SF_NO_PRINT,
1360 &softc->saved_ccb) == ERESTART) {
1362 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1363 /* Don't wedge the queue */
1364 xpt_release_devq(done_ccb->ccb_h.path,
1365 /*count*/1, /*run_queue*/TRUE);
1367 xpt_release_ccb(done_ccb);
1368 free(mode_hdr, M_CAMXPT);
1369 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1370 xpt_schedule(periph, priority);
1373 case PROBE_SUPPORTED_VPD_LIST:
1375 struct ccb_scsiio *csio;
1376 struct scsi_vpd_supported_page_list *page_list;
1378 csio = &done_ccb->csio;
1380 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1382 if (path->device->supported_vpds != NULL) {
1383 free(path->device->supported_vpds, M_CAMXPT);
1384 path->device->supported_vpds = NULL;
1385 path->device->supported_vpds_len = 0;
1388 if (page_list == NULL) {
1390 * Don't process the command as it was never sent
1392 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1394 path->device->supported_vpds_len = page_list->length +
1395 SVPD_SUPPORTED_PAGES_HDR_LEN;
1396 path->device->supported_vpds = (uint8_t *)page_list;
1397 xpt_release_ccb(done_ccb);
1398 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1399 xpt_schedule(periph, priority);
1401 } else if (cam_periph_error(done_ccb, 0,
1402 SF_RETRY_UA|SF_NO_PRINT,
1403 &softc->saved_ccb) == ERESTART) {
1405 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1406 /* Don't wedge the queue */
1407 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1412 free(page_list, M_CAMXPT);
1413 /* No VPDs available, skip to device check. */
1414 csio->data_ptr = NULL;
1415 goto probe_device_check;
1417 case PROBE_DEVICE_ID:
1419 struct scsi_vpd_device_id *devid;
1420 struct ccb_scsiio *csio;
1421 uint32_t length = 0;
1423 csio = &done_ccb->csio;
1424 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1426 /* Clean up from previous instance of this device */
1427 if (path->device->device_id != NULL) {
1428 path->device->device_id_len = 0;
1429 free(path->device->device_id, M_CAMXPT);
1430 path->device->device_id = NULL;
1433 if (devid == NULL) {
1434 /* Don't process the command as it was never sent */
1435 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1436 length = scsi_2btoul(devid->length);
1439 * NB: device_id_len is actual response
1440 * size, not buffer size.
1442 path->device->device_id_len = length +
1443 SVPD_DEVICE_ID_HDR_LEN;
1444 path->device->device_id = (uint8_t *)devid;
1446 } else if (cam_periph_error(done_ccb, 0,
1448 &softc->saved_ccb) == ERESTART) {
1450 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1451 /* Don't wedge the queue */
1452 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1456 /* Free the device id space if we don't use it */
1457 if (devid && length == 0)
1458 free(devid, M_CAMXPT);
1459 xpt_release_ccb(done_ccb);
1460 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1461 xpt_schedule(periph, priority);
1466 case PROBE_SERIAL_NUM:
1468 struct ccb_scsiio *csio;
1469 struct scsi_vpd_unit_serial_number *serial_buf;
1476 csio = &done_ccb->csio;
1477 priority = done_ccb->ccb_h.pinfo.priority;
1479 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1481 if (serial_buf == NULL) {
1483 * Don't process the command as it was never sent
1485 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1486 && (serial_buf->length > 0)) {
1489 path->device->serial_num =
1490 (u_int8_t *)malloc((serial_buf->length + 1),
1491 M_CAMXPT, M_NOWAIT);
1492 if (path->device->serial_num != NULL) {
1493 memcpy(path->device->serial_num,
1494 serial_buf->serial_num,
1495 serial_buf->length);
1496 path->device->serial_num_len =
1498 path->device->serial_num[serial_buf->length]
1501 } else if (cam_periph_error(done_ccb, 0,
1502 SF_RETRY_UA|SF_NO_PRINT,
1503 &softc->saved_ccb) == ERESTART) {
1505 } else 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,
1512 * Let's see if we have seen this device before.
1514 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1516 u_int8_t digest[16];
1521 (unsigned char *)&path->device->inq_data,
1522 sizeof(struct scsi_inquiry_data));
1525 MD5Update(&context, serial_buf->serial_num,
1526 serial_buf->length);
1528 MD5Final(digest, &context);
1529 if (bcmp(softc->digest, digest, 16) == 0)
1533 * XXX Do we need to do a TUR in order to ensure
1534 * that the device really hasn't changed???
1537 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1538 xpt_async(AC_LOST_DEVICE, path, NULL);
1540 if (serial_buf != NULL)
1541 free(serial_buf, M_CAMXPT);
1545 * Now that we have all the necessary
1546 * information to safely perform transfer
1547 * negotiations... Controllers don't perform
1548 * any negotiation or tagged queuing until
1549 * after the first XPT_SET_TRAN_SETTINGS ccb is
1550 * received. So, on a new device, just retrieve
1551 * the user settings, and set them as the current
1552 * settings to set the device up.
1554 proberequestdefaultnegotiation(periph);
1555 xpt_release_ccb(done_ccb);
1558 * Perform a TUR to allow the controller to
1559 * perform any necessary transfer negotiation.
1561 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1562 xpt_schedule(periph, priority);
1565 xpt_release_ccb(done_ccb);
1568 case PROBE_TUR_FOR_NEGOTIATION:
1570 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1571 cam_periph_error(done_ccb, 0,
1572 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1574 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1575 /* Don't wedge the queue */
1576 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1580 * Do Domain Validation for lun 0 on devices that claim
1581 * to support Synchronous Transfer modes.
1583 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1584 && done_ccb->ccb_h.target_lun == 0
1585 && (path->device->inq_data.flags & SID_Sync) != 0
1586 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1587 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1588 ("Begin Domain Validation\n"));
1589 path->device->flags |= CAM_DEV_IN_DV;
1590 xpt_release_ccb(done_ccb);
1591 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1592 xpt_schedule(periph, priority);
1595 if (softc->action == PROBE_DV_EXIT) {
1596 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1597 ("Leave Domain Validation\n"));
1599 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1600 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1601 xpt_acquire_device(path->device);
1603 path->device->flags &=
1604 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1605 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1606 /* Inform the XPT that a new device has been found */
1607 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1608 xpt_action(done_ccb);
1609 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1612 PROBE_SET_ACTION(softc, PROBE_DONE);
1613 xpt_release_ccb(done_ccb);
1615 case PROBE_INQUIRY_BASIC_DV1:
1616 case PROBE_INQUIRY_BASIC_DV2:
1618 struct scsi_inquiry_data *nbuf;
1619 struct ccb_scsiio *csio;
1621 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1622 cam_periph_error(done_ccb, 0,
1623 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1625 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1626 /* Don't wedge the queue */
1627 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1630 csio = &done_ccb->csio;
1631 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1632 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1634 "inquiry data fails comparison at DV%d step\n",
1635 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1636 if (proberequestbackoff(periph, path->device)) {
1637 path->device->flags &= ~CAM_DEV_IN_DV;
1638 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1641 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1643 free(nbuf, M_CAMXPT);
1644 xpt_release_ccb(done_ccb);
1645 xpt_schedule(periph, priority);
1648 free(nbuf, M_CAMXPT);
1649 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1650 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1651 xpt_release_ccb(done_ccb);
1652 xpt_schedule(periph, priority);
1655 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1656 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1657 ("Leave Domain Validation Successfully\n"));
1659 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1660 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1661 xpt_acquire_device(path->device);
1663 path->device->flags &=
1664 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1665 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1666 /* Inform the XPT that a new device has been found */
1667 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1668 xpt_action(done_ccb);
1669 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1672 PROBE_SET_ACTION(softc, PROBE_DONE);
1673 xpt_release_ccb(done_ccb);
1677 panic("probedone: invalid action state 0x%x\n", softc->action);
1679 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1680 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1681 done_ccb->ccb_h.status = CAM_REQ_CMP;
1683 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1684 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1685 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1686 cam_release_devq(path, 0, 0, 0, FALSE);
1687 cam_periph_release_locked(periph);
1688 cam_periph_invalidate(periph);
1689 cam_periph_release_locked(periph);
1691 probeschedule(periph);
1697 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1700 struct cam_path *tp;
1701 struct scsi_report_luns_data *old;
1702 u_int idx1, idx2, nlun_old, nlun_new;
1706 if (path->target == NULL) {
1709 mtx_lock(&path->target->luns_mtx);
1710 old = path->target->luns;
1711 path->target->luns = new;
1712 mtx_unlock(&path->target->luns_mtx);
1715 nlun_old = scsi_4btoul(old->length) / 8;
1716 nlun_new = scsi_4btoul(new->length) / 8;
1719 * We are not going to assume sorted lists. Deal.
1721 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1722 ol = old->luns[idx1].lundata;
1723 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1724 nl = new->luns[idx2].lundata;
1725 if (memcmp(nl, ol, 8) == 0) {
1729 if (idx2 < nlun_new) {
1733 * An 'old' item not in the 'new' list.
1734 * Nuke it. Except that if it is lun 0,
1735 * that would be what the probe state
1736 * machine is currently working on,
1737 * so we won't do that.
1739 CAM_GET_LUN(old, idx1, this_lun);
1740 if (this_lun == 0) {
1745 * We also cannot nuke it if it is
1746 * not in a lun format we understand
1747 * and replace the LUN with a "simple" LUN
1748 * if that is all the HBA supports.
1750 if (!(flags & PROBE_EXTLUN)) {
1751 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1753 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1755 if (!CAM_LUN_ONLY_32BITS(old, idx1))
1758 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1759 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1760 xpt_async(AC_LOST_DEVICE, tp, NULL);
1764 free(old, M_CAMXPT);
1768 probecleanup(struct cam_periph *periph)
1770 free(periph->softc, M_CAMXPT);
1774 scsi_find_quirk(struct cam_ed *device)
1776 struct scsi_quirk_entry *quirk;
1779 match = cam_quirkmatch((caddr_t)&device->inq_data,
1780 (caddr_t)scsi_quirk_table,
1781 sizeof(scsi_quirk_table) /
1782 sizeof(*scsi_quirk_table),
1783 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1786 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1788 quirk = (struct scsi_quirk_entry *)match;
1789 device->quirk = quirk;
1790 device->mintags = quirk->mintags;
1791 device->maxtags = quirk->maxtags;
1795 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1800 error = sysctl_handle_int(oidp, &val, 0, req);
1801 if (error != 0 || req->newptr == NULL)
1803 if (val == 0 || val == 1) {
1812 union ccb *request_ccb;
1813 struct ccb_pathinq *cpi;
1816 } scsi_scan_bus_info;
1819 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1820 * As the scan progresses, scsi_scan_bus is used as the
1821 * callback on completion function.
1824 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1828 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1829 ("scsi_scan_bus\n"));
1830 switch (request_ccb->ccb_h.func_code) {
1834 scsi_scan_bus_info *scan_info;
1835 union ccb *work_ccb, *reset_ccb;
1836 struct cam_path *path;
1838 u_int low_target, max_target;
1841 /* Find out the characteristics of the bus */
1842 work_ccb = xpt_alloc_ccb_nowait();
1843 if (work_ccb == NULL) {
1844 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1845 xpt_done(request_ccb);
1848 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1849 request_ccb->ccb_h.pinfo.priority);
1850 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1851 xpt_action(work_ccb);
1852 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1853 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1854 xpt_free_ccb(work_ccb);
1855 xpt_done(request_ccb);
1859 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1861 * Can't scan the bus on an adapter that
1862 * cannot perform the initiator role.
1864 request_ccb->ccb_h.status = CAM_REQ_CMP;
1865 xpt_free_ccb(work_ccb);
1866 xpt_done(request_ccb);
1870 /* We may need to reset bus first, if we haven't done it yet. */
1871 if ((work_ccb->cpi.hba_inquiry &
1872 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1873 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1874 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1875 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1876 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1878 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1879 xpt_action(reset_ccb);
1880 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1881 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1882 xpt_free_ccb(reset_ccb);
1883 xpt_free_ccb(work_ccb);
1884 xpt_done(request_ccb);
1887 xpt_free_ccb(reset_ccb);
1890 /* Save some state for use while we probe for devices */
1891 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1892 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1893 if (scan_info == NULL) {
1894 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1895 xpt_free_ccb(work_ccb);
1896 xpt_done(request_ccb);
1899 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1900 ("SCAN start for %p\n", scan_info));
1901 scan_info->request_ccb = request_ccb;
1902 scan_info->cpi = &work_ccb->cpi;
1904 /* Cache on our stack so we can work asynchronously */
1905 max_target = scan_info->cpi->max_target;
1907 initiator_id = scan_info->cpi->initiator_id;
1911 * We can scan all targets in parallel, or do it sequentially.
1914 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1915 max_target = low_target = request_ccb->ccb_h.target_id;
1916 scan_info->counter = 0;
1917 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1919 scan_info->counter = 0;
1921 scan_info->counter = scan_info->cpi->max_target + 1;
1922 if (scan_info->cpi->initiator_id < scan_info->counter) {
1923 scan_info->counter--;
1926 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1929 for (i = low_target; i <= max_target; i++) {
1931 if (i == initiator_id)
1934 status = xpt_create_path(&path, NULL,
1935 request_ccb->ccb_h.path_id,
1937 if (status != CAM_REQ_CMP) {
1938 printf("scsi_scan_bus: xpt_create_path failed"
1939 " with status %#x, bus scan halted\n",
1941 free(scan_info, M_CAMXPT);
1942 request_ccb->ccb_h.status = status;
1943 xpt_free_ccb(work_ccb);
1944 xpt_done(request_ccb);
1947 work_ccb = xpt_alloc_ccb_nowait();
1948 if (work_ccb == NULL) {
1949 xpt_free_ccb((union ccb *)scan_info->cpi);
1950 free(scan_info, M_CAMXPT);
1951 xpt_free_path(path);
1952 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1953 xpt_done(request_ccb);
1956 xpt_setup_ccb(&work_ccb->ccb_h, path,
1957 request_ccb->ccb_h.pinfo.priority);
1958 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1959 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1960 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1961 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1962 work_ccb->crcn.flags = request_ccb->crcn.flags;
1963 xpt_action(work_ccb);
1972 struct cam_path *path, *oldpath;
1973 scsi_scan_bus_info *scan_info;
1974 struct cam_et *target;
1975 struct cam_ed *device, *nextdev;
1978 target_id_t target_id;
1981 oldpath = request_ccb->ccb_h.path;
1983 status = cam_ccb_status(request_ccb);
1984 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1985 path_id = request_ccb->ccb_h.path_id;
1986 target_id = request_ccb->ccb_h.target_id;
1987 lun_id = request_ccb->ccb_h.target_lun;
1988 target = request_ccb->ccb_h.path->target;
1991 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1993 mtx_lock(&target->luns_mtx);
1996 u_int nluns = scsi_4btoul(target->luns->length) / 8;
1999 * Make sure we skip over lun 0 if it's the first member
2000 * of the list as we've actually just finished probing
2003 CAM_GET_LUN(target->luns, 0, first);
2004 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2005 scan_info->lunindex[target_id]++;
2009 * Skip any LUNs that the HBA can't deal with.
2011 while (scan_info->lunindex[target_id] < nluns) {
2012 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2013 CAM_GET_LUN(target->luns,
2014 scan_info->lunindex[target_id],
2019 /* XXX print warning? */
2020 if (!CAM_LUN_ONLY_32BITS(target->luns,
2021 scan_info->lunindex[target_id]))
2023 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2024 scan_info->lunindex[target_id])) {
2025 CAM_GET_SIMPLE_LUN(target->luns,
2026 scan_info->lunindex[target_id],
2031 scan_info->lunindex[target_id]++;
2034 if (scan_info->lunindex[target_id] < nluns) {
2035 mtx_unlock(&target->luns_mtx);
2037 CAM_DEBUG(request_ccb->ccb_h.path,
2039 ("next lun to try at index %u is %jx\n",
2040 scan_info->lunindex[target_id],
2041 (uintmax_t)lun_id));
2042 scan_info->lunindex[target_id]++;
2044 mtx_unlock(&target->luns_mtx);
2045 /* We're done with scanning all luns. */
2048 mtx_unlock(&target->luns_mtx);
2049 device = request_ccb->ccb_h.path->device;
2050 /* Continue sequential LUN scan if: */
2051 /* -- we have more LUNs that need recheck */
2052 mtx_lock(&target->bus->eb_mtx);
2054 while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL)
2055 if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0)
2057 mtx_unlock(&target->bus->eb_mtx);
2058 if (nextdev != NULL) {
2060 /* -- stop if CAM_QUIRK_NOLUNS is set. */
2061 } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) {
2063 /* -- this LUN is connected and its SCSI version
2064 * allows more LUNs. */
2065 } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2066 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2067 CAN_SRCH_HI_DENSE(device))
2069 /* -- this LUN is disconnected, its SCSI version
2070 * allows more LUNs and we guess they may be. */
2071 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) {
2072 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2073 CAN_SRCH_HI_SPARSE(device))
2076 if (next_target == 0) {
2078 if (lun_id > scan_info->cpi->max_lun)
2084 * Check to see if we scan any further luns.
2090 * Free the current request path- we're done with it.
2092 xpt_free_path(oldpath);
2095 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2097 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2098 scan_info->counter++;
2099 if (scan_info->counter ==
2100 scan_info->cpi->initiator_id) {
2101 scan_info->counter++;
2103 if (scan_info->counter >=
2104 scan_info->cpi->max_target+1) {
2108 scan_info->counter--;
2109 if (scan_info->counter == 0) {
2115 xpt_free_ccb(request_ccb);
2116 xpt_free_ccb((union ccb *)scan_info->cpi);
2117 request_ccb = scan_info->request_ccb;
2118 CAM_DEBUG(request_ccb->ccb_h.path,
2120 ("SCAN done for %p\n", scan_info));
2121 free(scan_info, M_CAMXPT);
2122 request_ccb->ccb_h.status = CAM_REQ_CMP;
2123 xpt_done(request_ccb);
2127 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2129 xpt_free_ccb(request_ccb);
2132 status = xpt_create_path(&path, NULL,
2133 scan_info->request_ccb->ccb_h.path_id,
2134 scan_info->counter, 0);
2135 if (status != CAM_REQ_CMP) {
2137 printf("scsi_scan_bus: xpt_create_path failed"
2138 " with status %#x, bus scan halted\n",
2140 xpt_free_ccb(request_ccb);
2141 xpt_free_ccb((union ccb *)scan_info->cpi);
2142 request_ccb = scan_info->request_ccb;
2143 free(scan_info, M_CAMXPT);
2144 request_ccb->ccb_h.status = status;
2145 xpt_done(request_ccb);
2148 xpt_setup_ccb(&request_ccb->ccb_h, path,
2149 request_ccb->ccb_h.pinfo.priority);
2150 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2151 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2152 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2153 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2154 request_ccb->crcn.flags =
2155 scan_info->request_ccb->crcn.flags;
2157 status = xpt_create_path(&path, NULL,
2158 path_id, target_id, lun_id);
2160 * Free the old request path- we're done with it. We
2161 * do this *after* creating the new path so that
2162 * we don't remove a target that has our lun list
2163 * in the case that lun 0 is not present.
2165 xpt_free_path(oldpath);
2166 if (status != CAM_REQ_CMP) {
2167 printf("scsi_scan_bus: xpt_create_path failed "
2168 "with status %#x, halting LUN scan\n",
2172 xpt_setup_ccb(&request_ccb->ccb_h, path,
2173 request_ccb->ccb_h.pinfo.priority);
2174 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2175 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2176 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2177 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2178 request_ccb->crcn.flags =
2179 scan_info->request_ccb->crcn.flags;
2182 xpt_action(request_ccb);
2191 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2192 cam_flags flags, union ccb *request_ccb)
2194 struct ccb_pathinq cpi;
2196 struct cam_path *new_path;
2197 struct cam_periph *old_periph;
2200 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2202 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2203 cpi.ccb_h.func_code = XPT_PATH_INQ;
2204 xpt_action((union ccb *)&cpi);
2206 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2207 if (request_ccb != NULL) {
2208 request_ccb->ccb_h.status = cpi.ccb_h.status;
2209 xpt_done(request_ccb);
2214 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2216 * Can't scan the bus on an adapter that
2217 * cannot perform the initiator role.
2219 if (request_ccb != NULL) {
2220 request_ccb->ccb_h.status = CAM_REQ_CMP;
2221 xpt_done(request_ccb);
2226 if (request_ccb == NULL) {
2227 request_ccb = xpt_alloc_ccb_nowait();
2228 if (request_ccb == NULL) {
2229 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2230 "can't continue\n");
2233 status = xpt_create_path(&new_path, NULL,
2235 path->target->target_id,
2236 path->device->lun_id);
2237 if (status != CAM_REQ_CMP) {
2238 xpt_print(path, "scsi_scan_lun: can't create path, "
2239 "can't continue\n");
2240 xpt_free_ccb(request_ccb);
2243 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2244 request_ccb->ccb_h.cbfcnp = xptscandone;
2245 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2246 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2247 request_ccb->crcn.flags = flags;
2250 lock = (xpt_path_owned(path) == 0);
2252 xpt_path_lock(path);
2253 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2254 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2257 softc = (probe_softc *)old_periph->softc;
2258 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2259 &request_ccb->ccb_h, periph_links.tqe);
2261 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2262 xpt_done(request_ccb);
2265 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2266 probestart, "probe",
2268 request_ccb->ccb_h.path, NULL, 0,
2271 if (status != CAM_REQ_CMP) {
2272 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2273 "returned an error, can't continue probe\n");
2274 request_ccb->ccb_h.status = status;
2275 xpt_done(request_ccb);
2279 xpt_path_unlock(path);
2283 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2286 xpt_free_path(done_ccb->ccb_h.path);
2287 xpt_free_ccb(done_ccb);
2290 static struct cam_ed *
2291 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2293 struct scsi_quirk_entry *quirk;
2294 struct cam_ed *device;
2296 device = xpt_alloc_device(bus, target, lun_id);
2301 * Take the default quirk entry until we have inquiry
2302 * data and can determine a better quirk to use.
2304 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2305 device->quirk = (void *)quirk;
2306 device->mintags = quirk->mintags;
2307 device->maxtags = quirk->maxtags;
2308 bzero(&device->inq_data, sizeof(device->inq_data));
2309 device->inq_flags = 0;
2310 device->queue_flags = 0;
2311 device->serial_num = NULL;
2312 device->serial_num_len = 0;
2313 device->device_id = NULL;
2314 device->device_id_len = 0;
2315 device->supported_vpds = NULL;
2316 device->supported_vpds_len = 0;
2321 scsi_devise_transport(struct cam_path *path)
2323 struct ccb_pathinq cpi;
2324 struct ccb_trans_settings cts;
2325 struct scsi_inquiry_data *inq_buf;
2327 /* Get transport information from the SIM */
2328 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2329 cpi.ccb_h.func_code = XPT_PATH_INQ;
2330 xpt_action((union ccb *)&cpi);
2333 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2334 inq_buf = &path->device->inq_data;
2335 path->device->protocol = PROTO_SCSI;
2336 path->device->protocol_version =
2337 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2338 path->device->transport = cpi.transport;
2339 path->device->transport_version = cpi.transport_version;
2342 * Any device not using SPI3 features should
2343 * be considered SPI2 or lower.
2345 if (inq_buf != NULL) {
2346 if (path->device->transport == XPORT_SPI
2347 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2348 && path->device->transport_version > 2)
2349 path->device->transport_version = 2;
2351 struct cam_ed* otherdev;
2353 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2355 otherdev = TAILQ_NEXT(otherdev, links)) {
2356 if (otherdev != path->device)
2360 if (otherdev != NULL) {
2362 * Initially assume the same versioning as
2363 * prior luns for this target.
2365 path->device->protocol_version =
2366 otherdev->protocol_version;
2367 path->device->transport_version =
2368 otherdev->transport_version;
2370 /* Until we know better, opt for safty */
2371 path->device->protocol_version = 2;
2372 if (path->device->transport == XPORT_SPI)
2373 path->device->transport_version = 2;
2375 path->device->transport_version = 0;
2381 * For a device compliant with SPC-2 we should be able
2382 * to determine the transport version supported by
2383 * scrutinizing the version descriptors in the
2387 /* Tell the controller what we think */
2388 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2389 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2390 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2391 cts.transport = path->device->transport;
2392 cts.transport_version = path->device->transport_version;
2393 cts.protocol = path->device->protocol;
2394 cts.protocol_version = path->device->protocol_version;
2395 cts.proto_specific.valid = 0;
2396 cts.xport_specific.valid = 0;
2397 xpt_action((union ccb *)&cts);
2401 scsi_dev_advinfo(union ccb *start_ccb)
2403 struct cam_ed *device;
2404 struct ccb_dev_advinfo *cdai;
2407 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2408 device = start_ccb->ccb_h.path->device;
2409 cdai = &start_ccb->cdai;
2410 switch(cdai->buftype) {
2411 case CDAI_TYPE_SCSI_DEVID:
2412 if (cdai->flags & CDAI_FLAG_STORE)
2414 cdai->provsiz = device->device_id_len;
2415 if (device->device_id_len == 0)
2417 amt = device->device_id_len;
2418 if (cdai->provsiz > cdai->bufsiz)
2420 memcpy(cdai->buf, device->device_id, amt);
2422 case CDAI_TYPE_SERIAL_NUM:
2423 if (cdai->flags & CDAI_FLAG_STORE)
2425 cdai->provsiz = device->serial_num_len;
2426 if (device->serial_num_len == 0)
2428 amt = device->serial_num_len;
2429 if (cdai->provsiz > cdai->bufsiz)
2431 memcpy(cdai->buf, device->serial_num, amt);
2433 case CDAI_TYPE_PHYS_PATH:
2434 if (cdai->flags & CDAI_FLAG_STORE) {
2435 if (device->physpath != NULL) {
2436 free(device->physpath, M_CAMXPT);
2437 device->physpath = NULL;
2439 device->physpath_len = cdai->bufsiz;
2440 /* Clear existing buffer if zero length */
2441 if (cdai->bufsiz == 0)
2443 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2444 if (device->physpath == NULL) {
2445 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2448 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2450 cdai->provsiz = device->physpath_len;
2451 if (device->physpath_len == 0)
2453 amt = device->physpath_len;
2454 if (cdai->provsiz > cdai->bufsiz)
2456 memcpy(cdai->buf, device->physpath, amt);
2459 case CDAI_TYPE_RCAPLONG:
2460 if (cdai->flags & CDAI_FLAG_STORE) {
2461 if (device->rcap_buf != NULL) {
2462 free(device->rcap_buf, M_CAMXPT);
2463 device->rcap_buf = NULL;
2466 device->rcap_len = cdai->bufsiz;
2467 /* Clear existing buffer if zero length */
2468 if (cdai->bufsiz == 0)
2471 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2473 if (device->rcap_buf == NULL) {
2474 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2478 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2480 cdai->provsiz = device->rcap_len;
2481 if (device->rcap_len == 0)
2483 amt = device->rcap_len;
2484 if (cdai->provsiz > cdai->bufsiz)
2486 memcpy(cdai->buf, device->rcap_buf, amt);
2492 start_ccb->ccb_h.status = CAM_REQ_CMP;
2494 if (cdai->flags & CDAI_FLAG_STORE) {
2495 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2496 (void *)(uintptr_t)cdai->buftype);
2501 scsi_action(union ccb *start_ccb)
2504 switch (start_ccb->ccb_h.func_code) {
2505 case XPT_SET_TRAN_SETTINGS:
2507 scsi_set_transfer_settings(&start_ccb->cts,
2508 start_ccb->ccb_h.path,
2509 /*async_update*/FALSE);
2514 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2517 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2518 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2521 case XPT_DEV_ADVINFO:
2523 scsi_dev_advinfo(start_ccb);
2527 xpt_action_default(start_ccb);
2533 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2536 struct ccb_pathinq cpi;
2537 struct ccb_trans_settings cur_cts;
2538 struct ccb_trans_settings_scsi *scsi;
2539 struct ccb_trans_settings_scsi *cur_scsi;
2540 struct scsi_inquiry_data *inq_data;
2541 struct cam_ed *device;
2543 if (path == NULL || (device = path->device) == NULL) {
2544 cts->ccb_h.status = CAM_PATH_INVALID;
2545 xpt_done((union ccb *)cts);
2549 if (cts->protocol == PROTO_UNKNOWN
2550 || cts->protocol == PROTO_UNSPECIFIED) {
2551 cts->protocol = device->protocol;
2552 cts->protocol_version = device->protocol_version;
2555 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2556 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2557 cts->protocol_version = device->protocol_version;
2559 if (cts->protocol != device->protocol) {
2560 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2561 cts->protocol, device->protocol);
2562 cts->protocol = device->protocol;
2565 if (cts->protocol_version > device->protocol_version) {
2567 xpt_print(path, "Down reving Protocol "
2568 "Version from %d to %d?\n", cts->protocol_version,
2569 device->protocol_version);
2571 cts->protocol_version = device->protocol_version;
2574 if (cts->transport == XPORT_UNKNOWN
2575 || cts->transport == XPORT_UNSPECIFIED) {
2576 cts->transport = device->transport;
2577 cts->transport_version = device->transport_version;
2580 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2581 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2582 cts->transport_version = device->transport_version;
2584 if (cts->transport != device->transport) {
2585 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2586 cts->transport, device->transport);
2587 cts->transport = device->transport;
2590 if (cts->transport_version > device->transport_version) {
2592 xpt_print(path, "Down reving Transport "
2593 "Version from %d to %d?\n", cts->transport_version,
2594 device->transport_version);
2596 cts->transport_version = device->transport_version;
2600 * Nothing more of interest to do unless
2601 * this is a device connected via the
2604 if (cts->protocol != PROTO_SCSI) {
2605 if (async_update == FALSE)
2606 xpt_action_default((union ccb *)cts);
2610 inq_data = &device->inq_data;
2611 scsi = &cts->proto_specific.scsi;
2612 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2613 cpi.ccb_h.func_code = XPT_PATH_INQ;
2614 xpt_action((union ccb *)&cpi);
2616 /* SCSI specific sanity checking */
2617 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2618 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2619 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2620 || (device->mintags == 0)) {
2622 * Can't tag on hardware that doesn't support tags,
2623 * doesn't have it enabled, or has broken tag support.
2625 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2628 if (async_update == FALSE) {
2630 * Perform sanity checking against what the
2631 * controller and device can do.
2633 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2634 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2635 cur_cts.type = cts->type;
2636 xpt_action((union ccb *)&cur_cts);
2637 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2640 cur_scsi = &cur_cts.proto_specific.scsi;
2641 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2642 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2643 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2645 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2646 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2649 /* SPI specific sanity checking */
2650 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2652 struct ccb_trans_settings_spi *spi;
2653 struct ccb_trans_settings_spi *cur_spi;
2655 spi = &cts->xport_specific.spi;
2657 cur_spi = &cur_cts.xport_specific.spi;
2659 /* Fill in any gaps in what the user gave us */
2660 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2661 spi->sync_period = cur_spi->sync_period;
2662 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2663 spi->sync_period = 0;
2664 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2665 spi->sync_offset = cur_spi->sync_offset;
2666 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2667 spi->sync_offset = 0;
2668 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2669 spi->ppr_options = cur_spi->ppr_options;
2670 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2671 spi->ppr_options = 0;
2672 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2673 spi->bus_width = cur_spi->bus_width;
2674 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2676 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2677 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2678 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2680 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2681 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2682 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2683 && (inq_data->flags & SID_Sync) == 0
2684 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2685 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2687 spi->sync_period = 0;
2688 spi->sync_offset = 0;
2691 switch (spi->bus_width) {
2692 case MSG_EXT_WDTR_BUS_32_BIT:
2693 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2694 || (inq_data->flags & SID_WBus32) != 0
2695 || cts->type == CTS_TYPE_USER_SETTINGS)
2696 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2698 /* Fall Through to 16-bit */
2699 case MSG_EXT_WDTR_BUS_16_BIT:
2700 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2701 || (inq_data->flags & SID_WBus16) != 0
2702 || cts->type == CTS_TYPE_USER_SETTINGS)
2703 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2704 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2707 /* Fall Through to 8-bit */
2708 default: /* New bus width?? */
2709 case MSG_EXT_WDTR_BUS_8_BIT:
2710 /* All targets can do this */
2711 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2715 spi3caps = cpi.xport_specific.spi.ppr_options;
2716 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2717 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2718 spi3caps &= inq_data->spi3data;
2720 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2721 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2723 if ((spi3caps & SID_SPI_IUS) == 0)
2724 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2726 if ((spi3caps & SID_SPI_QAS) == 0)
2727 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2729 /* No SPI Transfer settings are allowed unless we are wide */
2730 if (spi->bus_width == 0)
2731 spi->ppr_options = 0;
2733 if ((spi->valid & CTS_SPI_VALID_DISC)
2734 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2736 * Can't tag queue without disconnection.
2738 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2739 scsi->valid |= CTS_SCSI_VALID_TQ;
2743 * If we are currently performing tagged transactions to
2744 * this device and want to change its negotiation parameters,
2745 * go non-tagged for a bit to give the controller a chance to
2746 * negotiate unhampered by tag messages.
2748 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2749 && (device->inq_flags & SID_CmdQue) != 0
2750 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2751 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2752 CTS_SPI_VALID_SYNC_OFFSET|
2753 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2754 scsi_toggle_tags(path);
2757 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2758 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2762 * If we are transitioning from tags to no-tags or
2763 * vice-versa, we need to carefully freeze and restart
2764 * the queue so that we don't overlap tagged and non-tagged
2765 * commands. We also temporarily stop tags if there is
2766 * a change in transfer negotiation settings to allow
2767 * "tag-less" negotiation.
2769 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2770 || (device->inq_flags & SID_CmdQue) != 0)
2771 device_tagenb = TRUE;
2773 device_tagenb = FALSE;
2775 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2776 && device_tagenb == FALSE)
2777 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2778 && device_tagenb == TRUE)) {
2780 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2782 * Delay change to use tags until after a
2783 * few commands have gone to this device so
2784 * the controller has time to perform transfer
2785 * negotiations without tagged messages getting
2788 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2789 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2791 xpt_stop_tags(path);
2795 if (async_update == FALSE)
2796 xpt_action_default((union ccb *)cts);
2800 scsi_toggle_tags(struct cam_path *path)
2805 * Give controllers a chance to renegotiate
2806 * before starting tag operations. We
2807 * "toggle" tagged queuing off then on
2808 * which causes the tag enable command delay
2809 * counter to come into effect.
2812 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2813 || ((dev->inq_flags & SID_CmdQue) != 0
2814 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2815 struct ccb_trans_settings cts;
2817 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2818 cts.protocol = PROTO_SCSI;
2819 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2820 cts.transport = XPORT_UNSPECIFIED;
2821 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2822 cts.proto_specific.scsi.flags = 0;
2823 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2824 scsi_set_transfer_settings(&cts, path,
2825 /*async_update*/TRUE);
2826 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2827 scsi_set_transfer_settings(&cts, path,
2828 /*async_update*/TRUE);
2833 * Handle any per-device event notifications that require action by the XPT.
2836 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2837 struct cam_ed *device, void *async_arg)
2840 struct cam_path newpath;
2843 * We only need to handle events for real devices.
2845 if (target->target_id == CAM_TARGET_WILDCARD
2846 || device->lun_id == CAM_LUN_WILDCARD)
2850 * We need our own path with wildcards expanded to
2851 * handle certain types of events.
2853 if ((async_code == AC_SENT_BDR)
2854 || (async_code == AC_BUS_RESET)
2855 || (async_code == AC_INQ_CHANGED))
2856 status = xpt_compile_path(&newpath, NULL,
2861 status = CAM_REQ_CMP_ERR;
2863 if (status == CAM_REQ_CMP) {
2866 * Allow transfer negotiation to occur in a
2867 * tag free environment and after settle delay.
2869 if (async_code == AC_SENT_BDR
2870 || async_code == AC_BUS_RESET) {
2871 cam_freeze_devq(&newpath);
2872 cam_release_devq(&newpath,
2873 RELSIM_RELEASE_AFTER_TIMEOUT,
2875 /*timeout*/scsi_delay,
2876 /*getcount_only*/0);
2877 scsi_toggle_tags(&newpath);
2880 if (async_code == AC_INQ_CHANGED) {
2882 * We've sent a start unit command, or
2883 * something similar to a device that
2884 * may have caused its inquiry data to
2885 * change. So we re-scan the device to
2886 * refresh the inquiry data for it.
2888 scsi_scan_lun(newpath.periph, &newpath,
2889 CAM_EXPECT_INQ_CHANGE, NULL);
2891 xpt_release_path(&newpath);
2892 } else if (async_code == AC_LOST_DEVICE &&
2893 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2894 device->flags |= CAM_DEV_UNCONFIGURED;
2895 xpt_release_device(device);
2896 } else if (async_code == AC_TRANSFER_NEG) {
2897 struct ccb_trans_settings *settings;
2898 struct cam_path path;
2900 settings = (struct ccb_trans_settings *)async_arg;
2901 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2903 scsi_set_transfer_settings(settings, &path,
2904 /*async_update*/TRUE);
2905 xpt_release_path(&path);
2910 scsi_announce_periph(struct cam_periph *periph)
2912 struct ccb_pathinq cpi;
2913 struct ccb_trans_settings cts;
2914 struct cam_path *path = periph->path;
2919 cam_periph_assert(periph, MA_OWNED);
2921 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2922 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2923 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2924 xpt_action((union ccb*)&cts);
2925 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
2927 /* Ask the SIM for its base transfer speed */
2928 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2929 cpi.ccb_h.func_code = XPT_PATH_INQ;
2930 xpt_action((union ccb *)&cpi);
2931 /* Report connection speed */
2932 speed = cpi.base_transfer_speed;
2934 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2935 struct ccb_trans_settings_spi *spi =
2936 &cts.xport_specific.spi;
2938 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2939 && spi->sync_offset != 0) {
2940 freq = scsi_calc_syncsrate(spi->sync_period);
2943 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2944 speed *= (0x01 << spi->bus_width);
2946 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2947 struct ccb_trans_settings_fc *fc =
2948 &cts.xport_specific.fc;
2950 if (fc->valid & CTS_FC_VALID_SPEED)
2951 speed = fc->bitrate;
2953 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2954 struct ccb_trans_settings_sas *sas =
2955 &cts.xport_specific.sas;
2957 if (sas->valid & CTS_SAS_VALID_SPEED)
2958 speed = sas->bitrate;
2962 printf("%s%d: %d.%03dMB/s transfers",
2963 periph->periph_name, periph->unit_number,
2966 printf("%s%d: %dKB/s transfers", periph->periph_name,
2967 periph->unit_number, speed);
2968 /* Report additional information about SPI connections */
2969 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2970 struct ccb_trans_settings_spi *spi;
2972 spi = &cts.xport_specific.spi;
2974 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2976 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2980 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2981 && spi->bus_width > 0) {
2987 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2988 } else if (freq != 0) {
2992 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2993 struct ccb_trans_settings_fc *fc;
2995 fc = &cts.xport_specific.fc;
2996 if (fc->valid & CTS_FC_VALID_WWNN)
2997 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2998 if (fc->valid & CTS_FC_VALID_WWPN)
2999 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3000 if (fc->valid & CTS_FC_VALID_PORT)
3001 printf(" PortID 0x%x", fc->port);