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) {
763 MD5Init(&softc->context);
764 MD5Update(&softc->context, (unsigned char *)inq_buf,
765 sizeof(struct scsi_inquiry_data));
766 softc->flags |= PROBE_INQUIRY_CKSUM;
767 if (periph->path->device->serial_num_len > 0) {
768 MD5Update(&softc->context,
769 periph->path->device->serial_num,
770 periph->path->device->serial_num_len);
771 softc->flags |= PROBE_SERIAL_CKSUM;
773 MD5Final(softc->digest, &softc->context);
776 if (softc->action == PROBE_INQUIRY)
777 inquiry_len = SHORT_INQUIRY_LENGTH;
779 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
782 * Some parallel SCSI devices fail to send an
783 * ignore wide residue message when dealing with
784 * odd length inquiry requests. Round up to be
787 inquiry_len = roundup2(inquiry_len, 2);
789 if (softc->action == PROBE_INQUIRY_BASIC_DV1
790 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
791 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
793 if (inq_buf == NULL) {
794 xpt_print(periph->path, "malloc failure- skipping Basic"
795 "Domain Validation\n");
796 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
797 scsi_test_unit_ready(csio,
814 /*timeout*/60 * 1000);
817 case PROBE_REPORT_LUNS:
821 rp = malloc(periph->path->target->rpl_size,
822 M_CAMXPT, M_NOWAIT | M_ZERO);
824 struct scsi_inquiry_data *inq_buf;
825 inq_buf = &periph->path->device->inq_data;
826 xpt_print(periph->path,
827 "Unable to alloc report luns storage\n");
828 if (INQ_DATA_TQ_ENABLED(inq_buf))
829 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
831 PROBE_SET_ACTION(softc,
832 PROBE_SUPPORTED_VPD_LIST);
835 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
836 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
837 SSD_FULL_SIZE, 60000); break;
840 case PROBE_MODE_SENSE:
845 mode_buf_len = sizeof(struct scsi_mode_header_6)
846 + sizeof(struct scsi_mode_blk_desc)
847 + sizeof(struct scsi_control_page);
848 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
849 if (mode_buf != NULL) {
850 scsi_mode_sense(csio,
855 SMS_PAGE_CTRL_CURRENT,
856 SMS_CONTROL_MODE_PAGE,
863 xpt_print(periph->path, "Unable to mode sense control page - "
865 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
868 case PROBE_SUPPORTED_VPD_LIST:
870 struct scsi_vpd_supported_page_list *vpd_list;
871 struct cam_ed *device;
874 device = periph->path->device;
876 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
877 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
880 if (vpd_list != NULL) {
885 (u_int8_t *)vpd_list,
888 SVPD_SUPPORTED_PAGE_LIST,
890 /*timeout*/60 * 1000);
895 * We'll have to do without, let our probedone
896 * routine finish up for us.
898 start_ccb->csio.data_ptr = NULL;
899 cam_freeze_devq(periph->path);
900 cam_periph_doacquire(periph);
901 probedone(periph, start_ccb);
904 case PROBE_DEVICE_ID:
906 struct scsi_vpd_device_id *devid;
909 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
910 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
919 SVPD_DEVICE_ID_MAX_SIZE,
923 /*timeout*/60 * 1000);
928 case PROBE_SERIAL_NUM:
930 struct scsi_vpd_unit_serial_number *serial_buf;
931 struct cam_ed* device;
934 device = periph->path->device;
935 if (device->serial_num != NULL) {
936 free(device->serial_num, M_CAMXPT);
937 device->serial_num = NULL;
938 device->serial_num_len = 0;
941 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
942 serial_buf = (struct scsi_vpd_unit_serial_number *)
943 malloc(sizeof(*serial_buf), M_CAMXPT,
946 if (serial_buf != NULL) {
951 (u_int8_t *)serial_buf,
954 SVPD_UNIT_SERIAL_NUMBER,
956 /*timeout*/60 * 1000);
962 panic("probestart: invalid action state 0x%x\n", softc->action);
964 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
965 cam_periph_doacquire(periph);
966 xpt_action(start_ccb);
970 proberequestdefaultnegotiation(struct cam_periph *periph)
972 struct ccb_trans_settings cts;
974 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
975 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
976 cts.type = CTS_TYPE_USER_SETTINGS;
977 xpt_action((union ccb *)&cts);
978 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
981 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
982 cts.type = CTS_TYPE_CURRENT_SETTINGS;
983 xpt_action((union ccb *)&cts);
987 * Backoff Negotiation Code- only pertinent for SPI devices.
990 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
992 struct ccb_trans_settings cts;
993 struct ccb_trans_settings_spi *spi;
995 memset(&cts, 0, sizeof (cts));
996 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
997 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
998 cts.type = CTS_TYPE_CURRENT_SETTINGS;
999 xpt_action((union ccb *)&cts);
1000 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1002 xpt_print(periph->path,
1003 "failed to get current device settings\n");
1007 if (cts.transport != XPORT_SPI) {
1009 xpt_print(periph->path, "not SPI transport\n");
1013 spi = &cts.xport_specific.spi;
1016 * We cannot renegotiate sync rate if we don't have one.
1018 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1020 xpt_print(periph->path, "no sync rate known\n");
1026 * We'll assert that we don't have to touch PPR options- the
1027 * SIM will see what we do with period and offset and adjust
1028 * the PPR options as appropriate.
1032 * A sync rate with unknown or zero offset is nonsensical.
1033 * A sync period of zero means Async.
1035 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1036 || spi->sync_offset == 0 || spi->sync_period == 0) {
1038 xpt_print(periph->path, "no sync rate available\n");
1043 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1044 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1045 ("hit async: giving up on DV\n"));
1051 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1052 * We don't try to remember 'last' settings to see if the SIM actually
1053 * gets into the speed we want to set. We check on the SIM telling
1054 * us that a requested speed is bad, but otherwise don't try and
1055 * check the speed due to the asynchronous and handshake nature
1058 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1061 if (spi->sync_period >= 0xf) {
1062 spi->sync_period = 0;
1063 spi->sync_offset = 0;
1064 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1065 ("setting to async for DV\n"));
1067 * Once we hit async, we don't want to try
1068 * any more settings.
1070 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1071 } else if (bootverbose) {
1072 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1073 ("DV: period 0x%x\n", spi->sync_period));
1074 printf("setting period to 0x%x\n", spi->sync_period);
1076 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1077 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1078 xpt_action((union ccb *)&cts);
1079 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1082 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1083 ("DV: failed to set period 0x%x\n", spi->sync_period));
1084 if (spi->sync_period == 0) {
1091 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1094 probedone(struct cam_periph *periph, union ccb *done_ccb)
1097 struct cam_path *path;
1100 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1102 softc = (probe_softc *)periph->softc;
1103 path = done_ccb->ccb_h.path;
1104 priority = done_ccb->ccb_h.pinfo.priority;
1106 switch (softc->action) {
1109 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1111 if (cam_periph_error(done_ccb, 0,
1112 SF_NO_PRINT, NULL) == ERESTART) {
1114 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1115 cam_release_devq(path, 0, 0, 0, FALSE);
1118 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1119 /* Don't wedge the queue */
1120 xpt_release_devq(done_ccb->ccb_h.path,
1124 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1125 xpt_release_ccb(done_ccb);
1126 xpt_schedule(periph, priority);
1128 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1129 cam_release_devq(path, 0, 0, 0, FALSE);
1130 cam_periph_release_locked(periph);
1134 case PROBE_FULL_INQUIRY:
1136 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1137 struct scsi_inquiry_data *inq_buf;
1138 u_int8_t periph_qual;
1140 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1141 scsi_find_quirk(path->device);
1142 inq_buf = &path->device->inq_data;
1144 periph_qual = SID_QUAL(inq_buf);
1146 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1150 * We conservatively request only
1151 * SHORT_INQUIRY_LEN bytes of inquiry
1152 * information during our first try
1153 * at sending an INQUIRY. If the device
1154 * has more information to give,
1155 * perform a second request specifying
1156 * the amount of information the device
1157 * is willing to give.
1159 len = inq_buf->additional_length
1160 + offsetof(struct scsi_inquiry_data,
1161 additional_length) + 1;
1162 if (softc->action == PROBE_INQUIRY
1163 && len > SHORT_INQUIRY_LENGTH) {
1164 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1165 xpt_release_ccb(done_ccb);
1166 xpt_schedule(periph, priority);
1170 scsi_devise_transport(path);
1172 if (path->device->lun_id == 0 &&
1173 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1174 (SCSI_QUIRK(path->device)->quirks &
1175 CAM_QUIRK_NORPTLUNS) == 0) {
1176 PROBE_SET_ACTION(softc,
1179 * Start with room for *one* lun.
1181 periph->path->target->rpl_size = 16;
1182 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1183 PROBE_SET_ACTION(softc,
1186 PROBE_SET_ACTION(softc,
1187 PROBE_SUPPORTED_VPD_LIST);
1189 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1190 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1191 xpt_acquire_device(path->device);
1193 xpt_release_ccb(done_ccb);
1194 xpt_schedule(periph, priority);
1196 } else if (path->device->lun_id == 0 &&
1197 SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 &&
1198 (SCSI_QUIRK(path->device)->quirks &
1199 CAM_QUIRK_NORPTLUNS) == 0) {
1200 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1201 periph->path->target->rpl_size = 16;
1202 xpt_release_ccb(done_ccb);
1203 xpt_schedule(periph, priority);
1206 } else if (cam_periph_error(done_ccb, 0,
1207 done_ccb->ccb_h.target_lun > 0
1208 ? SF_RETRY_UA|SF_QUIET_IR
1210 &softc->saved_ccb) == ERESTART) {
1213 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1214 /* Don't wedge the queue */
1215 xpt_release_devq(done_ccb->ccb_h.path,
1216 /*count*/1, /*run_queue*/TRUE);
1218 path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID;
1221 * If we get to this point, we got an error status back
1222 * from the inquiry and the error status doesn't require
1223 * automatically retrying the command. Therefore, the
1224 * inquiry failed. If we had inquiry information before
1225 * for this device, but this latest inquiry command failed,
1226 * the device has probably gone away. If this device isn't
1227 * already marked unconfigured, notify the peripheral
1228 * drivers that this device is no more.
1230 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1231 /* Send the async notification. */
1232 xpt_async(AC_LOST_DEVICE, path, NULL);
1233 PROBE_SET_ACTION(softc, PROBE_INVALID);
1235 xpt_release_ccb(done_ccb);
1238 case PROBE_REPORT_LUNS:
1240 struct ccb_scsiio *csio;
1241 struct scsi_report_luns_data *lp;
1244 csio = &done_ccb->csio;
1246 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1247 nlun = scsi_4btoul(lp->length) / 8;
1248 maxlun = (csio->dxfer_len / 8) - 1;
1250 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1251 if (cam_periph_error(done_ccb, 0,
1252 done_ccb->ccb_h.target_lun > 0 ?
1253 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1254 &softc->saved_ccb) == ERESTART) {
1257 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1258 xpt_release_devq(done_ccb->ccb_h.path, 1,
1263 } else if (nlun > maxlun) {
1265 * Reallocate and retry to cover all luns
1267 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1268 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1271 path->target->rpl_size = (nlun << 3) + 8;
1272 xpt_release_ccb(done_ccb);
1273 xpt_schedule(periph, priority);
1275 } else if (nlun == 0) {
1277 * If there don't appear to be any luns, bail.
1285 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1286 ("Probe: %u lun(s) reported\n", nlun));
1288 CAM_GET_LUN(lp, 0, lun);
1290 * If the first lun is not lun 0, then either there
1291 * is no lun 0 in the list, or the list is unsorted.
1294 for (idx = 0; idx < nlun; idx++) {
1295 CAM_GET_LUN(lp, idx, lun);
1303 lp->luns[0].lundata, 8);
1304 memcpy(lp->luns[0].lundata,
1305 lp->luns[idx].lundata, 8);
1306 memcpy(lp->luns[idx].lundata,
1308 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1309 ("lun 0 in position %u\n", idx));
1313 * If we have an old lun list, We can either
1314 * retest luns that appear to have been dropped,
1315 * or just nuke them. We'll opt for the latter.
1316 * This function will also install the new list
1317 * in the target structure.
1319 probe_purge_old(path, lp, softc->flags);
1322 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID &&
1323 SID_QUAL(&path->device->inq_data) == SID_QUAL_LU_CONNECTED) {
1324 struct scsi_inquiry_data *inq_buf;
1325 inq_buf = &path->device->inq_data;
1326 if (INQ_DATA_TQ_ENABLED(inq_buf))
1327 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1329 PROBE_SET_ACTION(softc,
1330 PROBE_SUPPORTED_VPD_LIST);
1331 xpt_release_ccb(done_ccb);
1332 xpt_schedule(periph, priority);
1338 PROBE_SET_ACTION(softc, PROBE_INVALID);
1339 xpt_release_ccb(done_ccb);
1342 case PROBE_MODE_SENSE:
1344 struct ccb_scsiio *csio;
1345 struct scsi_mode_header_6 *mode_hdr;
1347 csio = &done_ccb->csio;
1348 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1349 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1350 struct scsi_control_page *page;
1353 offset = ((u_int8_t *)&mode_hdr[1])
1354 + mode_hdr->blk_desc_len;
1355 page = (struct scsi_control_page *)offset;
1356 path->device->queue_flags = page->queue_flags;
1357 } else if (cam_periph_error(done_ccb, 0,
1358 SF_RETRY_UA|SF_NO_PRINT,
1359 &softc->saved_ccb) == ERESTART) {
1361 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1362 /* Don't wedge the queue */
1363 xpt_release_devq(done_ccb->ccb_h.path,
1364 /*count*/1, /*run_queue*/TRUE);
1366 xpt_release_ccb(done_ccb);
1367 free(mode_hdr, M_CAMXPT);
1368 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1369 xpt_schedule(periph, priority);
1372 case PROBE_SUPPORTED_VPD_LIST:
1374 struct ccb_scsiio *csio;
1375 struct scsi_vpd_supported_page_list *page_list;
1377 csio = &done_ccb->csio;
1379 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1381 if (path->device->supported_vpds != NULL) {
1382 free(path->device->supported_vpds, M_CAMXPT);
1383 path->device->supported_vpds = NULL;
1384 path->device->supported_vpds_len = 0;
1387 if (page_list == NULL) {
1389 * Don't process the command as it was never sent
1391 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1393 path->device->supported_vpds_len = page_list->length +
1394 SVPD_SUPPORTED_PAGES_HDR_LEN;
1395 path->device->supported_vpds = (uint8_t *)page_list;
1396 xpt_release_ccb(done_ccb);
1397 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1398 xpt_schedule(periph, priority);
1400 } else if (cam_periph_error(done_ccb, 0,
1401 SF_RETRY_UA|SF_NO_PRINT,
1402 &softc->saved_ccb) == ERESTART) {
1404 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1405 /* Don't wedge the queue */
1406 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1411 free(page_list, M_CAMXPT);
1412 /* No VPDs available, skip to device check. */
1413 csio->data_ptr = NULL;
1414 goto probe_device_check;
1416 case PROBE_DEVICE_ID:
1418 struct scsi_vpd_device_id *devid;
1419 struct ccb_scsiio *csio;
1420 uint32_t length = 0;
1422 csio = &done_ccb->csio;
1423 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1425 /* Clean up from previous instance of this device */
1426 if (path->device->device_id != NULL) {
1427 path->device->device_id_len = 0;
1428 free(path->device->device_id, M_CAMXPT);
1429 path->device->device_id = NULL;
1432 if (devid == NULL) {
1433 /* Don't process the command as it was never sent */
1434 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1435 length = scsi_2btoul(devid->length);
1438 * NB: device_id_len is actual response
1439 * size, not buffer size.
1441 path->device->device_id_len = length +
1442 SVPD_DEVICE_ID_HDR_LEN;
1443 path->device->device_id = (uint8_t *)devid;
1445 } else if (cam_periph_error(done_ccb, 0,
1447 &softc->saved_ccb) == ERESTART) {
1449 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1450 /* Don't wedge the queue */
1451 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1455 /* Free the device id space if we don't use it */
1456 if (devid && length == 0)
1457 free(devid, M_CAMXPT);
1458 xpt_release_ccb(done_ccb);
1459 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1460 xpt_schedule(periph, priority);
1465 case PROBE_SERIAL_NUM:
1467 struct ccb_scsiio *csio;
1468 struct scsi_vpd_unit_serial_number *serial_buf;
1475 csio = &done_ccb->csio;
1476 priority = done_ccb->ccb_h.pinfo.priority;
1478 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1480 if (serial_buf == NULL) {
1482 * Don't process the command as it was never sent
1484 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1485 && (serial_buf->length > 0)) {
1488 path->device->serial_num =
1489 (u_int8_t *)malloc((serial_buf->length + 1),
1490 M_CAMXPT, M_NOWAIT);
1491 if (path->device->serial_num != NULL) {
1492 memcpy(path->device->serial_num,
1493 serial_buf->serial_num,
1494 serial_buf->length);
1495 path->device->serial_num_len =
1497 path->device->serial_num[serial_buf->length]
1500 } else if (cam_periph_error(done_ccb, 0,
1501 SF_RETRY_UA|SF_NO_PRINT,
1502 &softc->saved_ccb) == ERESTART) {
1504 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1505 /* Don't wedge the queue */
1506 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1511 * Let's see if we have seen this device before.
1513 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1515 u_int8_t digest[16];
1520 (unsigned char *)&path->device->inq_data,
1521 sizeof(struct scsi_inquiry_data));
1524 MD5Update(&context, serial_buf->serial_num,
1525 serial_buf->length);
1527 MD5Final(digest, &context);
1528 if (bcmp(softc->digest, digest, 16) == 0)
1532 * XXX Do we need to do a TUR in order to ensure
1533 * that the device really hasn't changed???
1536 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1537 xpt_async(AC_LOST_DEVICE, path, NULL);
1539 if (serial_buf != NULL)
1540 free(serial_buf, M_CAMXPT);
1544 * Now that we have all the necessary
1545 * information to safely perform transfer
1546 * negotiations... Controllers don't perform
1547 * any negotiation or tagged queuing until
1548 * after the first XPT_SET_TRAN_SETTINGS ccb is
1549 * received. So, on a new device, just retrieve
1550 * the user settings, and set them as the current
1551 * settings to set the device up.
1553 proberequestdefaultnegotiation(periph);
1554 xpt_release_ccb(done_ccb);
1557 * Perform a TUR to allow the controller to
1558 * perform any necessary transfer negotiation.
1560 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1561 xpt_schedule(periph, priority);
1564 xpt_release_ccb(done_ccb);
1567 case PROBE_TUR_FOR_NEGOTIATION:
1569 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1570 cam_periph_error(done_ccb, 0,
1571 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1573 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1574 /* Don't wedge the queue */
1575 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1579 * Do Domain Validation for lun 0 on devices that claim
1580 * to support Synchronous Transfer modes.
1582 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1583 && done_ccb->ccb_h.target_lun == 0
1584 && (path->device->inq_data.flags & SID_Sync) != 0
1585 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1586 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1587 ("Begin Domain Validation\n"));
1588 path->device->flags |= CAM_DEV_IN_DV;
1589 xpt_release_ccb(done_ccb);
1590 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1591 xpt_schedule(periph, priority);
1594 if (softc->action == PROBE_DV_EXIT) {
1595 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1596 ("Leave Domain Validation\n"));
1598 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1599 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1600 xpt_acquire_device(path->device);
1602 path->device->flags &=
1603 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1604 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1605 /* Inform the XPT that a new device has been found */
1606 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1607 xpt_action(done_ccb);
1608 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1611 PROBE_SET_ACTION(softc, PROBE_DONE);
1612 xpt_release_ccb(done_ccb);
1614 case PROBE_INQUIRY_BASIC_DV1:
1615 case PROBE_INQUIRY_BASIC_DV2:
1617 struct scsi_inquiry_data *nbuf;
1618 struct ccb_scsiio *csio;
1620 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1621 cam_periph_error(done_ccb, 0,
1622 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1624 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1625 /* Don't wedge the queue */
1626 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1629 csio = &done_ccb->csio;
1630 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1631 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1633 "inquiry data fails comparison at DV%d step\n",
1634 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1635 if (proberequestbackoff(periph, path->device)) {
1636 path->device->flags &= ~CAM_DEV_IN_DV;
1637 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1640 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1642 free(nbuf, M_CAMXPT);
1643 xpt_release_ccb(done_ccb);
1644 xpt_schedule(periph, priority);
1647 free(nbuf, M_CAMXPT);
1648 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1649 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1650 xpt_release_ccb(done_ccb);
1651 xpt_schedule(periph, priority);
1654 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1655 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1656 ("Leave Domain Validation Successfully\n"));
1658 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1659 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1660 xpt_acquire_device(path->device);
1662 path->device->flags &=
1663 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1664 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1665 /* Inform the XPT that a new device has been found */
1666 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1667 xpt_action(done_ccb);
1668 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1671 PROBE_SET_ACTION(softc, PROBE_DONE);
1672 xpt_release_ccb(done_ccb);
1676 panic("probedone: invalid action state 0x%x\n", softc->action);
1678 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1679 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1680 done_ccb->ccb_h.status = CAM_REQ_CMP;
1682 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1683 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1684 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1685 cam_release_devq(path, 0, 0, 0, FALSE);
1686 cam_periph_release_locked(periph);
1687 cam_periph_invalidate(periph);
1688 cam_periph_release_locked(periph);
1690 probeschedule(periph);
1696 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1699 struct cam_path *tp;
1700 struct scsi_report_luns_data *old;
1701 u_int idx1, idx2, nlun_old, nlun_new;
1705 if (path->target == NULL) {
1708 mtx_lock(&path->target->luns_mtx);
1709 old = path->target->luns;
1710 path->target->luns = new;
1711 mtx_unlock(&path->target->luns_mtx);
1714 nlun_old = scsi_4btoul(old->length) / 8;
1715 nlun_new = scsi_4btoul(new->length) / 8;
1718 * We are not going to assume sorted lists. Deal.
1720 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1721 ol = old->luns[idx1].lundata;
1722 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1723 nl = new->luns[idx2].lundata;
1724 if (memcmp(nl, ol, 8) == 0) {
1728 if (idx2 < nlun_new) {
1732 * An 'old' item not in the 'new' list.
1733 * Nuke it. Except that if it is lun 0,
1734 * that would be what the probe state
1735 * machine is currently working on,
1736 * so we won't do that.
1738 CAM_GET_LUN(old, idx1, this_lun);
1739 if (this_lun == 0) {
1744 * We also cannot nuke it if it is
1745 * not in a lun format we understand
1746 * and replace the LUN with a "simple" LUN
1747 * if that is all the HBA supports.
1749 if (!(flags & PROBE_EXTLUN)) {
1750 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1752 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1754 if (!CAM_LUN_ONLY_32BITS(old, idx1))
1757 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1758 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1759 xpt_async(AC_LOST_DEVICE, tp, NULL);
1763 free(old, M_CAMXPT);
1767 probecleanup(struct cam_periph *periph)
1769 free(periph->softc, M_CAMXPT);
1773 scsi_find_quirk(struct cam_ed *device)
1775 struct scsi_quirk_entry *quirk;
1778 match = cam_quirkmatch((caddr_t)&device->inq_data,
1779 (caddr_t)scsi_quirk_table,
1780 sizeof(scsi_quirk_table) /
1781 sizeof(*scsi_quirk_table),
1782 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1785 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1787 quirk = (struct scsi_quirk_entry *)match;
1788 device->quirk = quirk;
1789 device->mintags = quirk->mintags;
1790 device->maxtags = quirk->maxtags;
1794 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1799 error = sysctl_handle_int(oidp, &val, 0, req);
1800 if (error != 0 || req->newptr == NULL)
1802 if (val == 0 || val == 1) {
1811 union ccb *request_ccb;
1812 struct ccb_pathinq *cpi;
1815 } scsi_scan_bus_info;
1818 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1819 * As the scan progresses, scsi_scan_bus is used as the
1820 * callback on completion function.
1823 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1827 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1828 ("scsi_scan_bus\n"));
1829 switch (request_ccb->ccb_h.func_code) {
1833 scsi_scan_bus_info *scan_info;
1834 union ccb *work_ccb, *reset_ccb;
1835 struct cam_path *path;
1837 u_int low_target, max_target;
1840 /* Find out the characteristics of the bus */
1841 work_ccb = xpt_alloc_ccb_nowait();
1842 if (work_ccb == NULL) {
1843 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1844 xpt_done(request_ccb);
1847 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1848 request_ccb->ccb_h.pinfo.priority);
1849 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1850 xpt_action(work_ccb);
1851 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1852 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1853 xpt_free_ccb(work_ccb);
1854 xpt_done(request_ccb);
1858 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1860 * Can't scan the bus on an adapter that
1861 * cannot perform the initiator role.
1863 request_ccb->ccb_h.status = CAM_REQ_CMP;
1864 xpt_free_ccb(work_ccb);
1865 xpt_done(request_ccb);
1869 /* We may need to reset bus first, if we haven't done it yet. */
1870 if ((work_ccb->cpi.hba_inquiry &
1871 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1872 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1873 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1874 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1875 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1877 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1878 xpt_action(reset_ccb);
1879 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1880 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1881 xpt_free_ccb(reset_ccb);
1882 xpt_free_ccb(work_ccb);
1883 xpt_done(request_ccb);
1886 xpt_free_ccb(reset_ccb);
1889 /* Save some state for use while we probe for devices */
1890 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1891 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1892 if (scan_info == NULL) {
1893 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1894 xpt_free_ccb(work_ccb);
1895 xpt_done(request_ccb);
1898 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1899 ("SCAN start for %p\n", scan_info));
1900 scan_info->request_ccb = request_ccb;
1901 scan_info->cpi = &work_ccb->cpi;
1903 /* Cache on our stack so we can work asynchronously */
1904 max_target = scan_info->cpi->max_target;
1906 initiator_id = scan_info->cpi->initiator_id;
1910 * We can scan all targets in parallel, or do it sequentially.
1913 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1914 max_target = low_target = request_ccb->ccb_h.target_id;
1915 scan_info->counter = 0;
1916 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1918 scan_info->counter = 0;
1920 scan_info->counter = scan_info->cpi->max_target + 1;
1921 if (scan_info->cpi->initiator_id < scan_info->counter) {
1922 scan_info->counter--;
1925 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1928 for (i = low_target; i <= max_target; i++) {
1930 if (i == initiator_id)
1933 status = xpt_create_path(&path, NULL,
1934 request_ccb->ccb_h.path_id,
1936 if (status != CAM_REQ_CMP) {
1937 printf("scsi_scan_bus: xpt_create_path failed"
1938 " with status %#x, bus scan halted\n",
1940 free(scan_info, M_CAMXPT);
1941 request_ccb->ccb_h.status = status;
1942 xpt_free_ccb(work_ccb);
1943 xpt_done(request_ccb);
1946 work_ccb = xpt_alloc_ccb_nowait();
1947 if (work_ccb == NULL) {
1948 xpt_free_ccb((union ccb *)scan_info->cpi);
1949 free(scan_info, M_CAMXPT);
1950 xpt_free_path(path);
1951 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1952 xpt_done(request_ccb);
1955 xpt_setup_ccb(&work_ccb->ccb_h, path,
1956 request_ccb->ccb_h.pinfo.priority);
1957 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1958 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1959 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1960 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1961 work_ccb->crcn.flags = request_ccb->crcn.flags;
1962 xpt_action(work_ccb);
1971 struct cam_path *path, *oldpath;
1972 scsi_scan_bus_info *scan_info;
1973 struct cam_et *target;
1974 struct cam_ed *device, *nextdev;
1977 target_id_t target_id;
1980 oldpath = request_ccb->ccb_h.path;
1982 status = cam_ccb_status(request_ccb);
1983 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1984 path_id = request_ccb->ccb_h.path_id;
1985 target_id = request_ccb->ccb_h.target_id;
1986 lun_id = request_ccb->ccb_h.target_lun;
1987 target = request_ccb->ccb_h.path->target;
1990 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1992 mtx_lock(&target->luns_mtx);
1995 u_int nluns = scsi_4btoul(target->luns->length) / 8;
1998 * Make sure we skip over lun 0 if it's the first member
1999 * of the list as we've actually just finished probing
2002 CAM_GET_LUN(target->luns, 0, first);
2003 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2004 scan_info->lunindex[target_id]++;
2008 * Skip any LUNs that the HBA can't deal with.
2010 while (scan_info->lunindex[target_id] < nluns) {
2011 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2012 CAM_GET_LUN(target->luns,
2013 scan_info->lunindex[target_id],
2018 /* XXX print warning? */
2019 if (!CAM_LUN_ONLY_32BITS(target->luns,
2020 scan_info->lunindex[target_id]))
2022 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2023 scan_info->lunindex[target_id])) {
2024 CAM_GET_SIMPLE_LUN(target->luns,
2025 scan_info->lunindex[target_id],
2030 scan_info->lunindex[target_id]++;
2033 if (scan_info->lunindex[target_id] < nluns) {
2034 mtx_unlock(&target->luns_mtx);
2036 CAM_DEBUG(request_ccb->ccb_h.path,
2038 ("next lun to try at index %u is %jx\n",
2039 scan_info->lunindex[target_id],
2040 (uintmax_t)lun_id));
2041 scan_info->lunindex[target_id]++;
2043 mtx_unlock(&target->luns_mtx);
2044 /* We're done with scanning all luns. */
2047 mtx_unlock(&target->luns_mtx);
2048 device = request_ccb->ccb_h.path->device;
2049 /* Continue sequential LUN scan if: */
2050 /* -- we have more LUNs that need recheck */
2051 mtx_lock(&target->bus->eb_mtx);
2053 while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL)
2054 if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0)
2056 mtx_unlock(&target->bus->eb_mtx);
2057 if (nextdev != NULL) {
2059 /* -- stop if CAM_QUIRK_NOLUNS is set. */
2060 } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) {
2062 /* -- this LUN is connected and its SCSI version
2063 * allows more LUNs. */
2064 } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2065 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2066 CAN_SRCH_HI_DENSE(device))
2068 /* -- this LUN is disconnected, its SCSI version
2069 * allows more LUNs and we guess they may be. */
2070 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) {
2071 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2072 CAN_SRCH_HI_SPARSE(device))
2075 if (next_target == 0) {
2077 if (lun_id > scan_info->cpi->max_lun)
2083 * Check to see if we scan any further luns.
2089 * Free the current request path- we're done with it.
2091 xpt_free_path(oldpath);
2094 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2096 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2097 scan_info->counter++;
2098 if (scan_info->counter ==
2099 scan_info->cpi->initiator_id) {
2100 scan_info->counter++;
2102 if (scan_info->counter >=
2103 scan_info->cpi->max_target+1) {
2107 scan_info->counter--;
2108 if (scan_info->counter == 0) {
2114 xpt_free_ccb(request_ccb);
2115 xpt_free_ccb((union ccb *)scan_info->cpi);
2116 request_ccb = scan_info->request_ccb;
2117 CAM_DEBUG(request_ccb->ccb_h.path,
2119 ("SCAN done for %p\n", scan_info));
2120 free(scan_info, M_CAMXPT);
2121 request_ccb->ccb_h.status = CAM_REQ_CMP;
2122 xpt_done(request_ccb);
2126 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2128 xpt_free_ccb(request_ccb);
2131 status = xpt_create_path(&path, NULL,
2132 scan_info->request_ccb->ccb_h.path_id,
2133 scan_info->counter, 0);
2134 if (status != CAM_REQ_CMP) {
2136 printf("scsi_scan_bus: xpt_create_path failed"
2137 " with status %#x, bus scan halted\n",
2139 xpt_free_ccb(request_ccb);
2140 xpt_free_ccb((union ccb *)scan_info->cpi);
2141 request_ccb = scan_info->request_ccb;
2142 free(scan_info, M_CAMXPT);
2143 request_ccb->ccb_h.status = status;
2144 xpt_done(request_ccb);
2147 xpt_setup_ccb(&request_ccb->ccb_h, path,
2148 request_ccb->ccb_h.pinfo.priority);
2149 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2150 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2151 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2152 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2153 request_ccb->crcn.flags =
2154 scan_info->request_ccb->crcn.flags;
2156 status = xpt_create_path(&path, NULL,
2157 path_id, target_id, lun_id);
2159 * Free the old request path- we're done with it. We
2160 * do this *after* creating the new path so that
2161 * we don't remove a target that has our lun list
2162 * in the case that lun 0 is not present.
2164 xpt_free_path(oldpath);
2165 if (status != CAM_REQ_CMP) {
2166 printf("scsi_scan_bus: xpt_create_path failed "
2167 "with status %#x, halting LUN scan\n",
2171 xpt_setup_ccb(&request_ccb->ccb_h, path,
2172 request_ccb->ccb_h.pinfo.priority);
2173 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2174 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2175 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2176 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2177 request_ccb->crcn.flags =
2178 scan_info->request_ccb->crcn.flags;
2181 xpt_action(request_ccb);
2190 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2191 cam_flags flags, union ccb *request_ccb)
2193 struct ccb_pathinq cpi;
2195 struct cam_path *new_path;
2196 struct cam_periph *old_periph;
2199 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2201 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2202 cpi.ccb_h.func_code = XPT_PATH_INQ;
2203 xpt_action((union ccb *)&cpi);
2205 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2206 if (request_ccb != NULL) {
2207 request_ccb->ccb_h.status = cpi.ccb_h.status;
2208 xpt_done(request_ccb);
2213 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2215 * Can't scan the bus on an adapter that
2216 * cannot perform the initiator role.
2218 if (request_ccb != NULL) {
2219 request_ccb->ccb_h.status = CAM_REQ_CMP;
2220 xpt_done(request_ccb);
2225 if (request_ccb == NULL) {
2226 request_ccb = xpt_alloc_ccb_nowait();
2227 if (request_ccb == NULL) {
2228 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2229 "can't continue\n");
2232 status = xpt_create_path(&new_path, NULL,
2234 path->target->target_id,
2235 path->device->lun_id);
2236 if (status != CAM_REQ_CMP) {
2237 xpt_print(path, "scsi_scan_lun: can't create path, "
2238 "can't continue\n");
2239 xpt_free_ccb(request_ccb);
2242 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2243 request_ccb->ccb_h.cbfcnp = xptscandone;
2244 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2245 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2246 request_ccb->crcn.flags = flags;
2249 lock = (xpt_path_owned(path) == 0);
2251 xpt_path_lock(path);
2252 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2253 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2256 softc = (probe_softc *)old_periph->softc;
2257 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2258 &request_ccb->ccb_h, periph_links.tqe);
2260 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2261 xpt_done(request_ccb);
2264 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2265 probestart, "probe",
2267 request_ccb->ccb_h.path, NULL, 0,
2270 if (status != CAM_REQ_CMP) {
2271 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2272 "returned an error, can't continue probe\n");
2273 request_ccb->ccb_h.status = status;
2274 xpt_done(request_ccb);
2278 xpt_path_unlock(path);
2282 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2285 xpt_free_path(done_ccb->ccb_h.path);
2286 xpt_free_ccb(done_ccb);
2289 static struct cam_ed *
2290 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2292 struct scsi_quirk_entry *quirk;
2293 struct cam_ed *device;
2295 device = xpt_alloc_device(bus, target, lun_id);
2300 * Take the default quirk entry until we have inquiry
2301 * data and can determine a better quirk to use.
2303 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2304 device->quirk = (void *)quirk;
2305 device->mintags = quirk->mintags;
2306 device->maxtags = quirk->maxtags;
2307 bzero(&device->inq_data, sizeof(device->inq_data));
2308 device->inq_flags = 0;
2309 device->queue_flags = 0;
2310 device->serial_num = NULL;
2311 device->serial_num_len = 0;
2312 device->device_id = NULL;
2313 device->device_id_len = 0;
2314 device->supported_vpds = NULL;
2315 device->supported_vpds_len = 0;
2320 scsi_devise_transport(struct cam_path *path)
2322 struct ccb_pathinq cpi;
2323 struct ccb_trans_settings cts;
2324 struct scsi_inquiry_data *inq_buf;
2326 /* Get transport information from the SIM */
2327 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2328 cpi.ccb_h.func_code = XPT_PATH_INQ;
2329 xpt_action((union ccb *)&cpi);
2332 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2333 inq_buf = &path->device->inq_data;
2334 path->device->protocol = PROTO_SCSI;
2335 path->device->protocol_version =
2336 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2337 path->device->transport = cpi.transport;
2338 path->device->transport_version = cpi.transport_version;
2341 * Any device not using SPI3 features should
2342 * be considered SPI2 or lower.
2344 if (inq_buf != NULL) {
2345 if (path->device->transport == XPORT_SPI
2346 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2347 && path->device->transport_version > 2)
2348 path->device->transport_version = 2;
2350 struct cam_ed* otherdev;
2352 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2354 otherdev = TAILQ_NEXT(otherdev, links)) {
2355 if (otherdev != path->device)
2359 if (otherdev != NULL) {
2361 * Initially assume the same versioning as
2362 * prior luns for this target.
2364 path->device->protocol_version =
2365 otherdev->protocol_version;
2366 path->device->transport_version =
2367 otherdev->transport_version;
2369 /* Until we know better, opt for safty */
2370 path->device->protocol_version = 2;
2371 if (path->device->transport == XPORT_SPI)
2372 path->device->transport_version = 2;
2374 path->device->transport_version = 0;
2380 * For a device compliant with SPC-2 we should be able
2381 * to determine the transport version supported by
2382 * scrutinizing the version descriptors in the
2386 /* Tell the controller what we think */
2387 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2388 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2389 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2390 cts.transport = path->device->transport;
2391 cts.transport_version = path->device->transport_version;
2392 cts.protocol = path->device->protocol;
2393 cts.protocol_version = path->device->protocol_version;
2394 cts.proto_specific.valid = 0;
2395 cts.xport_specific.valid = 0;
2396 xpt_action((union ccb *)&cts);
2400 scsi_dev_advinfo(union ccb *start_ccb)
2402 struct cam_ed *device;
2403 struct ccb_dev_advinfo *cdai;
2406 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2407 device = start_ccb->ccb_h.path->device;
2408 cdai = &start_ccb->cdai;
2409 switch(cdai->buftype) {
2410 case CDAI_TYPE_SCSI_DEVID:
2411 if (cdai->flags & CDAI_FLAG_STORE)
2413 cdai->provsiz = device->device_id_len;
2414 if (device->device_id_len == 0)
2416 amt = device->device_id_len;
2417 if (cdai->provsiz > cdai->bufsiz)
2419 memcpy(cdai->buf, device->device_id, amt);
2421 case CDAI_TYPE_SERIAL_NUM:
2422 if (cdai->flags & CDAI_FLAG_STORE)
2424 cdai->provsiz = device->serial_num_len;
2425 if (device->serial_num_len == 0)
2427 amt = device->serial_num_len;
2428 if (cdai->provsiz > cdai->bufsiz)
2430 memcpy(cdai->buf, device->serial_num, amt);
2432 case CDAI_TYPE_PHYS_PATH:
2433 if (cdai->flags & CDAI_FLAG_STORE) {
2434 if (device->physpath != NULL) {
2435 free(device->physpath, M_CAMXPT);
2436 device->physpath = NULL;
2438 device->physpath_len = cdai->bufsiz;
2439 /* Clear existing buffer if zero length */
2440 if (cdai->bufsiz == 0)
2442 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2443 if (device->physpath == NULL) {
2444 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2447 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2449 cdai->provsiz = device->physpath_len;
2450 if (device->physpath_len == 0)
2452 amt = device->physpath_len;
2453 if (cdai->provsiz > cdai->bufsiz)
2455 memcpy(cdai->buf, device->physpath, amt);
2458 case CDAI_TYPE_RCAPLONG:
2459 if (cdai->flags & CDAI_FLAG_STORE) {
2460 if (device->rcap_buf != NULL) {
2461 free(device->rcap_buf, M_CAMXPT);
2462 device->rcap_buf = NULL;
2465 device->rcap_len = cdai->bufsiz;
2466 /* Clear existing buffer if zero length */
2467 if (cdai->bufsiz == 0)
2470 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2472 if (device->rcap_buf == NULL) {
2473 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2477 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2479 cdai->provsiz = device->rcap_len;
2480 if (device->rcap_len == 0)
2482 amt = device->rcap_len;
2483 if (cdai->provsiz > cdai->bufsiz)
2485 memcpy(cdai->buf, device->rcap_buf, amt);
2491 start_ccb->ccb_h.status = CAM_REQ_CMP;
2493 if (cdai->flags & CDAI_FLAG_STORE) {
2494 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2495 (void *)(uintptr_t)cdai->buftype);
2500 scsi_action(union ccb *start_ccb)
2503 switch (start_ccb->ccb_h.func_code) {
2504 case XPT_SET_TRAN_SETTINGS:
2506 scsi_set_transfer_settings(&start_ccb->cts,
2507 start_ccb->ccb_h.path,
2508 /*async_update*/FALSE);
2513 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2516 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2517 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2520 case XPT_DEV_ADVINFO:
2522 scsi_dev_advinfo(start_ccb);
2526 xpt_action_default(start_ccb);
2532 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2535 struct ccb_pathinq cpi;
2536 struct ccb_trans_settings cur_cts;
2537 struct ccb_trans_settings_scsi *scsi;
2538 struct ccb_trans_settings_scsi *cur_scsi;
2539 struct scsi_inquiry_data *inq_data;
2540 struct cam_ed *device;
2542 if (path == NULL || (device = path->device) == NULL) {
2543 cts->ccb_h.status = CAM_PATH_INVALID;
2544 xpt_done((union ccb *)cts);
2548 if (cts->protocol == PROTO_UNKNOWN
2549 || cts->protocol == PROTO_UNSPECIFIED) {
2550 cts->protocol = device->protocol;
2551 cts->protocol_version = device->protocol_version;
2554 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2555 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2556 cts->protocol_version = device->protocol_version;
2558 if (cts->protocol != device->protocol) {
2559 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2560 cts->protocol, device->protocol);
2561 cts->protocol = device->protocol;
2564 if (cts->protocol_version > device->protocol_version) {
2566 xpt_print(path, "Down reving Protocol "
2567 "Version from %d to %d?\n", cts->protocol_version,
2568 device->protocol_version);
2570 cts->protocol_version = device->protocol_version;
2573 if (cts->transport == XPORT_UNKNOWN
2574 || cts->transport == XPORT_UNSPECIFIED) {
2575 cts->transport = device->transport;
2576 cts->transport_version = device->transport_version;
2579 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2580 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2581 cts->transport_version = device->transport_version;
2583 if (cts->transport != device->transport) {
2584 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2585 cts->transport, device->transport);
2586 cts->transport = device->transport;
2589 if (cts->transport_version > device->transport_version) {
2591 xpt_print(path, "Down reving Transport "
2592 "Version from %d to %d?\n", cts->transport_version,
2593 device->transport_version);
2595 cts->transport_version = device->transport_version;
2599 * Nothing more of interest to do unless
2600 * this is a device connected via the
2603 if (cts->protocol != PROTO_SCSI) {
2604 if (async_update == FALSE)
2605 xpt_action_default((union ccb *)cts);
2609 inq_data = &device->inq_data;
2610 scsi = &cts->proto_specific.scsi;
2611 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2612 cpi.ccb_h.func_code = XPT_PATH_INQ;
2613 xpt_action((union ccb *)&cpi);
2615 /* SCSI specific sanity checking */
2616 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2617 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2618 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2619 || (device->mintags == 0)) {
2621 * Can't tag on hardware that doesn't support tags,
2622 * doesn't have it enabled, or has broken tag support.
2624 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2627 if (async_update == FALSE) {
2629 * Perform sanity checking against what the
2630 * controller and device can do.
2632 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2633 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2634 cur_cts.type = cts->type;
2635 xpt_action((union ccb *)&cur_cts);
2636 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2639 cur_scsi = &cur_cts.proto_specific.scsi;
2640 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2641 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2642 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2644 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2645 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2648 /* SPI specific sanity checking */
2649 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2651 struct ccb_trans_settings_spi *spi;
2652 struct ccb_trans_settings_spi *cur_spi;
2654 spi = &cts->xport_specific.spi;
2656 cur_spi = &cur_cts.xport_specific.spi;
2658 /* Fill in any gaps in what the user gave us */
2659 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2660 spi->sync_period = cur_spi->sync_period;
2661 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2662 spi->sync_period = 0;
2663 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2664 spi->sync_offset = cur_spi->sync_offset;
2665 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2666 spi->sync_offset = 0;
2667 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2668 spi->ppr_options = cur_spi->ppr_options;
2669 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2670 spi->ppr_options = 0;
2671 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2672 spi->bus_width = cur_spi->bus_width;
2673 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2675 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2676 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2677 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2679 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2680 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2681 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2682 && (inq_data->flags & SID_Sync) == 0
2683 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2684 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2686 spi->sync_period = 0;
2687 spi->sync_offset = 0;
2690 switch (spi->bus_width) {
2691 case MSG_EXT_WDTR_BUS_32_BIT:
2692 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2693 || (inq_data->flags & SID_WBus32) != 0
2694 || cts->type == CTS_TYPE_USER_SETTINGS)
2695 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2697 /* Fall Through to 16-bit */
2698 case MSG_EXT_WDTR_BUS_16_BIT:
2699 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2700 || (inq_data->flags & SID_WBus16) != 0
2701 || cts->type == CTS_TYPE_USER_SETTINGS)
2702 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2703 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2706 /* Fall Through to 8-bit */
2707 default: /* New bus width?? */
2708 case MSG_EXT_WDTR_BUS_8_BIT:
2709 /* All targets can do this */
2710 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2714 spi3caps = cpi.xport_specific.spi.ppr_options;
2715 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2716 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2717 spi3caps &= inq_data->spi3data;
2719 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2720 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2722 if ((spi3caps & SID_SPI_IUS) == 0)
2723 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2725 if ((spi3caps & SID_SPI_QAS) == 0)
2726 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2728 /* No SPI Transfer settings are allowed unless we are wide */
2729 if (spi->bus_width == 0)
2730 spi->ppr_options = 0;
2732 if ((spi->valid & CTS_SPI_VALID_DISC)
2733 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2735 * Can't tag queue without disconnection.
2737 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2738 scsi->valid |= CTS_SCSI_VALID_TQ;
2742 * If we are currently performing tagged transactions to
2743 * this device and want to change its negotiation parameters,
2744 * go non-tagged for a bit to give the controller a chance to
2745 * negotiate unhampered by tag messages.
2747 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2748 && (device->inq_flags & SID_CmdQue) != 0
2749 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2750 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2751 CTS_SPI_VALID_SYNC_OFFSET|
2752 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2753 scsi_toggle_tags(path);
2756 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2757 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2761 * If we are transitioning from tags to no-tags or
2762 * vice-versa, we need to carefully freeze and restart
2763 * the queue so that we don't overlap tagged and non-tagged
2764 * commands. We also temporarily stop tags if there is
2765 * a change in transfer negotiation settings to allow
2766 * "tag-less" negotiation.
2768 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2769 || (device->inq_flags & SID_CmdQue) != 0)
2770 device_tagenb = TRUE;
2772 device_tagenb = FALSE;
2774 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2775 && device_tagenb == FALSE)
2776 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2777 && device_tagenb == TRUE)) {
2779 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2781 * Delay change to use tags until after a
2782 * few commands have gone to this device so
2783 * the controller has time to perform transfer
2784 * negotiations without tagged messages getting
2787 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2788 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2790 xpt_stop_tags(path);
2794 if (async_update == FALSE)
2795 xpt_action_default((union ccb *)cts);
2799 scsi_toggle_tags(struct cam_path *path)
2804 * Give controllers a chance to renegotiate
2805 * before starting tag operations. We
2806 * "toggle" tagged queuing off then on
2807 * which causes the tag enable command delay
2808 * counter to come into effect.
2811 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2812 || ((dev->inq_flags & SID_CmdQue) != 0
2813 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2814 struct ccb_trans_settings cts;
2816 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2817 cts.protocol = PROTO_SCSI;
2818 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2819 cts.transport = XPORT_UNSPECIFIED;
2820 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2821 cts.proto_specific.scsi.flags = 0;
2822 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2823 scsi_set_transfer_settings(&cts, path,
2824 /*async_update*/TRUE);
2825 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2826 scsi_set_transfer_settings(&cts, path,
2827 /*async_update*/TRUE);
2832 * Handle any per-device event notifications that require action by the XPT.
2835 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2836 struct cam_ed *device, void *async_arg)
2839 struct cam_path newpath;
2842 * We only need to handle events for real devices.
2844 if (target->target_id == CAM_TARGET_WILDCARD
2845 || device->lun_id == CAM_LUN_WILDCARD)
2849 * We need our own path with wildcards expanded to
2850 * handle certain types of events.
2852 if ((async_code == AC_SENT_BDR)
2853 || (async_code == AC_BUS_RESET)
2854 || (async_code == AC_INQ_CHANGED))
2855 status = xpt_compile_path(&newpath, NULL,
2860 status = CAM_REQ_CMP_ERR;
2862 if (status == CAM_REQ_CMP) {
2865 * Allow transfer negotiation to occur in a
2866 * tag free environment and after settle delay.
2868 if (async_code == AC_SENT_BDR
2869 || async_code == AC_BUS_RESET) {
2870 cam_freeze_devq(&newpath);
2871 cam_release_devq(&newpath,
2872 RELSIM_RELEASE_AFTER_TIMEOUT,
2874 /*timeout*/scsi_delay,
2875 /*getcount_only*/0);
2876 scsi_toggle_tags(&newpath);
2879 if (async_code == AC_INQ_CHANGED) {
2881 * We've sent a start unit command, or
2882 * something similar to a device that
2883 * may have caused its inquiry data to
2884 * change. So we re-scan the device to
2885 * refresh the inquiry data for it.
2887 scsi_scan_lun(newpath.periph, &newpath,
2888 CAM_EXPECT_INQ_CHANGE, NULL);
2890 xpt_release_path(&newpath);
2891 } else if (async_code == AC_LOST_DEVICE &&
2892 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2893 device->flags |= CAM_DEV_UNCONFIGURED;
2894 xpt_release_device(device);
2895 } else if (async_code == AC_TRANSFER_NEG) {
2896 struct ccb_trans_settings *settings;
2897 struct cam_path path;
2899 settings = (struct ccb_trans_settings *)async_arg;
2900 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2902 scsi_set_transfer_settings(settings, &path,
2903 /*async_update*/TRUE);
2904 xpt_release_path(&path);
2909 scsi_announce_periph(struct cam_periph *periph)
2911 struct ccb_pathinq cpi;
2912 struct ccb_trans_settings cts;
2913 struct cam_path *path = periph->path;
2918 cam_periph_assert(periph, MA_OWNED);
2920 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2921 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2922 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2923 xpt_action((union ccb*)&cts);
2924 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
2926 /* Ask the SIM for its base transfer speed */
2927 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2928 cpi.ccb_h.func_code = XPT_PATH_INQ;
2929 xpt_action((union ccb *)&cpi);
2930 /* Report connection speed */
2931 speed = cpi.base_transfer_speed;
2933 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2934 struct ccb_trans_settings_spi *spi =
2935 &cts.xport_specific.spi;
2937 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2938 && spi->sync_offset != 0) {
2939 freq = scsi_calc_syncsrate(spi->sync_period);
2942 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2943 speed *= (0x01 << spi->bus_width);
2945 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2946 struct ccb_trans_settings_fc *fc =
2947 &cts.xport_specific.fc;
2949 if (fc->valid & CTS_FC_VALID_SPEED)
2950 speed = fc->bitrate;
2952 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2953 struct ccb_trans_settings_sas *sas =
2954 &cts.xport_specific.sas;
2956 if (sas->valid & CTS_SAS_VALID_SPEED)
2957 speed = sas->bitrate;
2961 printf("%s%d: %d.%03dMB/s transfers",
2962 periph->periph_name, periph->unit_number,
2965 printf("%s%d: %dKB/s transfers", periph->periph_name,
2966 periph->unit_number, speed);
2967 /* Report additional information about SPI connections */
2968 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2969 struct ccb_trans_settings_spi *spi;
2971 spi = &cts.xport_specific.spi;
2973 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2975 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2979 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2980 && spi->bus_width > 0) {
2986 printf("%dbit)", 8 * (0x01 << spi->bus_width));
2987 } else if (freq != 0) {
2991 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2992 struct ccb_trans_settings_fc *fc;
2994 fc = &cts.xport_specific.fc;
2995 if (fc->valid & CTS_FC_VALID_WWNN)
2996 printf(" WWNN 0x%llx", (long long) fc->wwnn);
2997 if (fc->valid & CTS_FC_VALID_WWPN)
2998 printf(" WWPN 0x%llx", (long long) fc->wwpn);
2999 if (fc->valid & CTS_FC_VALID_PORT)
3000 printf(" PortID 0x%x", fc->port);