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]; \
104 * If we're not quirked to search <= the first 8 luns
105 * and we are either quirked to search above lun 8,
106 * or we're > SCSI-2 and we've enabled hilun searching,
107 * or we're > SCSI-2 and the last lun was a success,
108 * we can look for luns above lun 8.
110 #define CAN_SRCH_HI_SPARSE(dv) \
111 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
112 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
113 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
115 #define CAN_SRCH_HI_DENSE(dv) \
116 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
117 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
118 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
120 static periph_init_t probe_periph_init;
122 static struct periph_driver probe_driver =
124 probe_periph_init, "probe",
125 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
129 PERIPHDRIVER_DECLARE(probe, probe_driver);
133 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
137 PROBE_SUPPORTED_VPD_LIST,
140 PROBE_TUR_FOR_NEGOTIATION,
141 PROBE_INQUIRY_BASIC_DV1,
142 PROBE_INQUIRY_BASIC_DV2,
148 static char *probe_action_text[] = {
151 "PROBE_FULL_INQUIRY",
154 "PROBE_SUPPORTED_VPD_LIST",
157 "PROBE_TUR_FOR_NEGOTIATION",
158 "PROBE_INQUIRY_BASIC_DV1",
159 "PROBE_INQUIRY_BASIC_DV2",
165 #define PROBE_SET_ACTION(softc, newaction) \
168 text = probe_action_text; \
169 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
170 ("Probe %s to %s\n", text[(softc)->action], \
171 text[(newaction)])); \
172 (softc)->action = (newaction); \
176 PROBE_INQUIRY_CKSUM = 0x01,
177 PROBE_SERIAL_CKSUM = 0x02,
178 PROBE_NO_ANNOUNCE = 0x04
182 TAILQ_HEAD(, ccb_hdr) request_ccbs;
188 struct cam_periph *periph;
191 static const char quantum[] = "QUANTUM";
192 static const char sony[] = "SONY";
193 static const char west_digital[] = "WDIGTL";
194 static const char samsung[] = "SAMSUNG";
195 static const char seagate[] = "SEAGATE";
196 static const char microp[] = "MICROP";
198 static struct scsi_quirk_entry scsi_quirk_table[] =
201 /* Reports QUEUE FULL for temporary resource shortages */
202 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
203 /*quirks*/0, /*mintags*/24, /*maxtags*/32
206 /* Reports QUEUE FULL for temporary resource shortages */
207 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
208 /*quirks*/0, /*mintags*/24, /*maxtags*/32
211 /* Reports QUEUE FULL for temporary resource shortages */
212 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
213 /*quirks*/0, /*mintags*/24, /*maxtags*/32
216 /* Broken tagged queuing drive */
217 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
218 /*quirks*/0, /*mintags*/0, /*maxtags*/0
221 /* Broken tagged queuing drive */
222 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
223 /*quirks*/0, /*mintags*/0, /*maxtags*/0
226 /* Broken tagged queuing drive */
227 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
228 /*quirks*/0, /*mintags*/0, /*maxtags*/0
232 * Unfortunately, the Quantum Atlas III has the same
233 * problem as the Atlas II drives above.
234 * Reported by: "Johan Granlund" <johan@granlund.nu>
236 * For future reference, the drive with the problem was:
237 * QUANTUM QM39100TD-SW N1B0
239 * It's possible that Quantum will fix the problem in later
240 * firmware revisions. If that happens, the quirk entry
241 * will need to be made specific to the firmware revisions
245 /* Reports QUEUE FULL for temporary resource shortages */
246 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
247 /*quirks*/0, /*mintags*/24, /*maxtags*/32
251 * 18 Gig Atlas III, same problem as the 9G version.
252 * Reported by: Andre Albsmeier
253 * <andre.albsmeier@mchp.siemens.de>
255 * For future reference, the drive with the problem was:
256 * QUANTUM QM318000TD-S N491
258 /* Reports QUEUE FULL for temporary resource shortages */
259 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
260 /*quirks*/0, /*mintags*/24, /*maxtags*/32
264 * Broken tagged queuing drive
265 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
266 * and: Martin Renters <martin@tdc.on.ca>
268 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
269 /*quirks*/0, /*mintags*/0, /*maxtags*/0
272 * The Seagate Medalist Pro drives have very poor write
273 * performance with anything more than 2 tags.
275 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
276 * Drive: <SEAGATE ST36530N 1444>
278 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
279 * Drive: <SEAGATE ST34520W 1281>
281 * No one has actually reported that the 9G version
282 * (ST39140*) of the Medalist Pro has the same problem, but
283 * we're assuming that it does because the 4G and 6.5G
284 * versions of the drive are broken.
287 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
288 /*quirks*/0, /*mintags*/2, /*maxtags*/2
291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
292 /*quirks*/0, /*mintags*/2, /*maxtags*/2
295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
296 /*quirks*/0, /*mintags*/2, /*maxtags*/2
300 * Experiences command timeouts under load with a
301 * tag count higher than 55.
303 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
304 /*quirks*/0, /*mintags*/2, /*maxtags*/55
308 * Slow when tagged queueing is enabled. Write performance
309 * steadily drops off with more and more concurrent
310 * transactions. Best sequential write performance with
311 * tagged queueing turned off and write caching turned on.
314 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
315 * Drive: DCAS-34330 w/ "S65A" firmware.
317 * The drive with the problem had the "S65A" firmware
318 * revision, and has also been reported (by Stephen J.
319 * Roznowski <sjr@home.net>) for a drive with the "S61A"
322 * Although no one has reported problems with the 2 gig
323 * version of the DCAS drive, the assumption is that it
324 * has the same problems as the 4 gig version. Therefore
325 * this quirk entries disables tagged queueing for all
328 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
329 /*quirks*/0, /*mintags*/0, /*maxtags*/0
332 /* Broken tagged queuing drive */
333 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
334 /*quirks*/0, /*mintags*/0, /*maxtags*/0
337 /* Broken tagged queuing drive */
338 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
339 /*quirks*/0, /*mintags*/0, /*maxtags*/0
342 /* This does not support other than LUN 0 */
343 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
344 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
348 * Broken tagged queuing drive.
350 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
353 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
354 /*quirks*/0, /*mintags*/0, /*maxtags*/0
358 * Slow when tagged queueing is enabled. (1.5MB/sec versus
360 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
361 * Best performance with these drives is achieved with
362 * tagged queueing turned off, and write caching turned on.
364 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
365 /*quirks*/0, /*mintags*/0, /*maxtags*/0
369 * Slow when tagged queueing is enabled. (1.5MB/sec versus
371 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
372 * Best performance with these drives is achieved with
373 * tagged queueing turned off, and write caching turned on.
375 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
376 /*quirks*/0, /*mintags*/0, /*maxtags*/0
380 * Doesn't handle queue full condition correctly,
381 * so we need to limit maxtags to what the device
382 * can handle instead of determining this automatically.
384 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
385 /*quirks*/0, /*mintags*/2, /*maxtags*/32
388 /* Really only one LUN */
389 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
390 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
393 /* I can't believe we need a quirk for DPT volumes. */
394 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
396 /*mintags*/0, /*maxtags*/255
400 * Many Sony CDROM drives don't like multi-LUN probing.
402 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
403 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
407 * This drive doesn't like multiple LUN probing.
408 * Submitted by: Parag Patel <parag@cgt.com>
410 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
411 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
414 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
415 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
419 * The 8200 doesn't like multi-lun probing, and probably
420 * don't like serial number requests either.
423 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
426 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
430 * Let's try the same as above, but for a drive that says
431 * it's an IPL-6860 but is actually an EXB 8200.
434 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
437 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
441 * These Hitachi drives don't like multi-lun probing.
442 * The PR submitter has a DK319H, but says that the Linux
443 * kernel has a similar work-around for the DK312 and DK314,
444 * so all DK31* drives are quirked here.
446 * Submitted by: Paul Haddad <paul@pth.com>
448 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
449 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
453 * The Hitachi CJ series with J8A8 firmware apparantly has
454 * problems with tagged commands.
456 * Reported by: amagai@nue.org
458 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
459 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
463 * These are the large storage arrays.
464 * Submitted by: William Carrel <william.carrel@infospace.com>
466 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
467 CAM_QUIRK_HILUNS, 2, 1024
471 * This old revision of the TDC3600 is also SCSI-1, and
472 * hangs upon serial number probing.
475 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
478 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
482 * Would repond to all LUNs if asked for.
485 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
488 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
492 * Would repond to all LUNs if asked for.
495 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
501 /* Submitted by: Matthew Dodd <winter@jurai.net> */
502 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
503 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
506 /* Submitted by: Matthew Dodd <winter@jurai.net> */
507 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
508 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
511 /* TeraSolutions special settings for TRC-22 RAID */
512 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
513 /*quirks*/0, /*mintags*/55, /*maxtags*/255
516 /* Veritas Storage Appliance */
517 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
518 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
522 * Would respond to all LUNs. Device type and removable
523 * flag are jumper-selectable.
525 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
528 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
531 /* EasyRAID E5A aka. areca ARC-6010 */
532 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
533 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
536 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
537 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
540 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
541 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
544 /* Default tagged queuing parameters for all devices */
546 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
547 /*vendor*/"*", /*product*/"*", /*revision*/"*"
549 /*quirks*/0, /*mintags*/2, /*maxtags*/255
553 static const int scsi_quirk_table_size =
554 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
556 static cam_status proberegister(struct cam_periph *periph,
558 static void probeschedule(struct cam_periph *probe_periph);
559 static int device_has_vpd(struct cam_ed *device, uint8_t page_id);
560 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
561 static void proberequestdefaultnegotiation(struct cam_periph *periph);
562 static int proberequestbackoff(struct cam_periph *periph,
563 struct cam_ed *device);
564 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
565 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
567 static void probe_purge_old(struct cam_path *path,
568 struct scsi_report_luns_data *new);
569 static void probecleanup(struct cam_periph *periph);
570 static void scsi_find_quirk(struct cam_ed *device);
571 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
572 static void scsi_scan_lun(struct cam_periph *periph,
573 struct cam_path *path, cam_flags flags,
575 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
576 static struct cam_ed *
577 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
579 static void scsi_devise_transport(struct cam_path *path);
580 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
581 struct cam_ed *device,
583 static void scsi_toggle_tags(struct cam_path *path);
584 static void scsi_dev_async(u_int32_t async_code,
586 struct cam_et *target,
587 struct cam_ed *device,
589 static void scsi_action(union ccb *start_ccb);
590 static void scsi_announce_periph(struct cam_periph *periph);
592 static struct xpt_xport scsi_xport = {
593 .alloc_device = scsi_alloc_device,
594 .action = scsi_action,
595 .async = scsi_dev_async,
596 .announce = scsi_announce_periph,
602 return (&scsi_xport);
611 proberegister(struct cam_periph *periph, void *arg)
613 union ccb *request_ccb; /* CCB representing the probe request */
617 request_ccb = (union ccb *)arg;
618 if (request_ccb == NULL) {
619 printf("proberegister: no probe CCB, "
620 "can't register device\n");
621 return(CAM_REQ_CMP_ERR);
624 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
627 printf("proberegister: Unable to probe new device. "
628 "Unable to allocate softc\n");
629 return(CAM_REQ_CMP_ERR);
631 TAILQ_INIT(&softc->request_ccbs);
632 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
635 periph->softc = softc;
636 softc->periph = periph;
637 softc->action = PROBE_INVALID;
638 status = cam_periph_acquire(periph);
639 if (status != CAM_REQ_CMP) {
642 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
645 * Ensure we've waited at least a bus settle
646 * delay before attempting to probe the device.
647 * For HBAs that don't do bus resets, this won't make a difference.
649 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
652 * Ensure nobody slip in until probe finish.
654 cam_freeze_devq_arg(periph->path,
655 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
656 probeschedule(periph);
661 probeschedule(struct cam_periph *periph)
663 struct ccb_pathinq cpi;
667 softc = (probe_softc *)periph->softc;
668 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
670 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
671 cpi.ccb_h.func_code = XPT_PATH_INQ;
672 xpt_action((union ccb *)&cpi);
675 * If a device has gone away and another device, or the same one,
676 * is back in the same place, it should have a unit attention
677 * condition pending. It will not report the unit attention in
678 * response to an inquiry, which may leave invalid transfer
679 * negotiations in effect. The TUR will reveal the unit attention
680 * condition. Only send the TUR for lun 0, since some devices
681 * will get confused by commands other than inquiry to non-existent
682 * luns. If you think a device has gone away start your scan from
683 * lun 0. This will insure that any bogus transfer settings are
686 * If we haven't seen the device before and the controller supports
687 * some kind of transfer negotiation, negotiate with the first
688 * sent command if no bus reset was performed at startup. This
689 * ensures that the device is not confused by transfer negotiation
690 * settings left over by loader or BIOS action.
692 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
693 && (ccb->ccb_h.target_lun == 0)) {
694 PROBE_SET_ACTION(softc, PROBE_TUR);
695 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
696 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
697 proberequestdefaultnegotiation(periph);
698 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
700 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
703 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
704 softc->flags |= PROBE_NO_ANNOUNCE;
706 softc->flags &= ~PROBE_NO_ANNOUNCE;
708 xpt_schedule(periph, CAM_PRIORITY_XPT);
712 device_has_vpd(struct cam_ed *device, uint8_t page_id)
715 struct scsi_vpd_supported_pages *vpds;
717 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
718 num_pages = device->supported_vpds_len - SVPD_SUPPORTED_PAGES_HDR_LEN;
719 for (i = 0;i < num_pages;i++)
720 if (vpds->page_list[i] == page_id)
727 probestart(struct cam_periph *periph, union ccb *start_ccb)
729 /* Probe the device that our peripheral driver points to */
730 struct ccb_scsiio *csio;
733 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
735 softc = (probe_softc *)periph->softc;
736 csio = &start_ccb->csio;
739 switch (softc->action) {
741 case PROBE_TUR_FOR_NEGOTIATION:
744 scsi_test_unit_ready(csio,
753 case PROBE_FULL_INQUIRY:
754 case PROBE_INQUIRY_BASIC_DV1:
755 case PROBE_INQUIRY_BASIC_DV2:
758 struct scsi_inquiry_data *inq_buf;
760 inq_buf = &periph->path->device->inq_data;
763 * If the device is currently configured, we calculate an
764 * MD5 checksum of the inquiry data, and if the serial number
765 * length is greater than 0, add the serial number data
766 * into the checksum as well. Once the inquiry and the
767 * serial number check finish, we attempt to figure out
768 * whether we still have the same device.
770 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
772 MD5Init(&softc->context);
773 MD5Update(&softc->context, (unsigned char *)inq_buf,
774 sizeof(struct scsi_inquiry_data));
775 softc->flags |= PROBE_INQUIRY_CKSUM;
776 if (periph->path->device->serial_num_len > 0) {
777 MD5Update(&softc->context,
778 periph->path->device->serial_num,
779 periph->path->device->serial_num_len);
780 softc->flags |= PROBE_SERIAL_CKSUM;
782 MD5Final(softc->digest, &softc->context);
785 if (softc->action == PROBE_INQUIRY)
786 inquiry_len = SHORT_INQUIRY_LENGTH;
788 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
791 * Some parallel SCSI devices fail to send an
792 * ignore wide residue message when dealing with
793 * odd length inquiry requests. Round up to be
796 inquiry_len = roundup2(inquiry_len, 2);
798 if (softc->action == PROBE_INQUIRY_BASIC_DV1
799 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
800 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
802 if (inq_buf == NULL) {
803 xpt_print(periph->path, "malloc failure- skipping Basic"
804 "Domain Validation\n");
805 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
806 scsi_test_unit_ready(csio,
823 /*timeout*/60 * 1000);
826 case PROBE_REPORT_LUNS:
830 rp = malloc(periph->path->target->rpl_size,
831 M_CAMXPT, M_NOWAIT | M_ZERO);
833 struct scsi_inquiry_data *inq_buf;
834 inq_buf = &periph->path->device->inq_data;
835 xpt_print(periph->path,
836 "Unable to alloc report luns storage\n");
837 if (INQ_DATA_TQ_ENABLED(inq_buf))
838 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
840 PROBE_SET_ACTION(softc,
841 PROBE_SUPPORTED_VPD_LIST);
844 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
845 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
846 SSD_FULL_SIZE, 60000); break;
849 case PROBE_MODE_SENSE:
854 mode_buf_len = sizeof(struct scsi_mode_header_6)
855 + sizeof(struct scsi_mode_blk_desc)
856 + sizeof(struct scsi_control_page);
857 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
858 if (mode_buf != NULL) {
859 scsi_mode_sense(csio,
864 SMS_PAGE_CTRL_CURRENT,
865 SMS_CONTROL_MODE_PAGE,
872 xpt_print(periph->path, "Unable to mode sense control page - "
874 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
877 case PROBE_SUPPORTED_VPD_LIST:
879 struct scsi_vpd_supported_page_list *vpd_list;
880 struct cam_ed *device;
883 device = periph->path->device;
885 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
886 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
889 if (vpd_list != NULL) {
894 (u_int8_t *)vpd_list,
897 SVPD_SUPPORTED_PAGE_LIST,
899 /*timeout*/60 * 1000);
903 * We'll have to do without, let our probedone
904 * routine finish up for us.
906 start_ccb->csio.data_ptr = NULL;
907 probedone(periph, start_ccb);
910 case PROBE_DEVICE_ID:
912 struct scsi_vpd_device_id *devid;
913 struct cam_ed *device;
916 device = periph->path->device;
917 if (device_has_vpd(device, SVPD_DEVICE_ID))
918 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
927 SVPD_DEVICE_ID_MAX_SIZE,
931 /*timeout*/60 * 1000);
935 * We'll have to do without, let our probedone
936 * routine finish up for us.
938 start_ccb->csio.data_ptr = NULL;
939 probedone(periph, start_ccb);
942 case PROBE_SERIAL_NUM:
944 struct scsi_vpd_unit_serial_number *serial_buf;
945 struct cam_ed* device;
948 device = periph->path->device;
949 if (device->serial_num != NULL) {
950 free(device->serial_num, M_CAMXPT);
951 device->serial_num = NULL;
952 device->serial_num_len = 0;
955 if (device_has_vpd(device, SVPD_UNIT_SERIAL_NUMBER))
956 serial_buf = (struct scsi_vpd_unit_serial_number *)
957 malloc(sizeof(*serial_buf), M_CAMXPT,
960 if (serial_buf != NULL) {
965 (u_int8_t *)serial_buf,
968 SVPD_UNIT_SERIAL_NUMBER,
970 /*timeout*/60 * 1000);
974 * We'll have to do without, let our probedone
975 * routine finish up for us.
977 start_ccb->csio.data_ptr = NULL;
978 probedone(periph, start_ccb);
982 panic("probestart: invalid action state 0x%x\n", softc->action);
984 xpt_action(start_ccb);
988 proberequestdefaultnegotiation(struct cam_periph *periph)
990 struct ccb_trans_settings cts;
992 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
993 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
994 cts.type = CTS_TYPE_USER_SETTINGS;
995 xpt_action((union ccb *)&cts);
996 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
999 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1000 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1001 xpt_action((union ccb *)&cts);
1005 * Backoff Negotiation Code- only pertinent for SPI devices.
1008 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1010 struct ccb_trans_settings cts;
1011 struct ccb_trans_settings_spi *spi;
1013 memset(&cts, 0, sizeof (cts));
1014 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1015 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1016 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1017 xpt_action((union ccb *)&cts);
1018 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1020 xpt_print(periph->path,
1021 "failed to get current device settings\n");
1025 if (cts.transport != XPORT_SPI) {
1027 xpt_print(periph->path, "not SPI transport\n");
1031 spi = &cts.xport_specific.spi;
1034 * We cannot renegotiate sync rate if we don't have one.
1036 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1038 xpt_print(periph->path, "no sync rate known\n");
1044 * We'll assert that we don't have to touch PPR options- the
1045 * SIM will see what we do with period and offset and adjust
1046 * the PPR options as appropriate.
1050 * A sync rate with unknown or zero offset is nonsensical.
1051 * A sync period of zero means Async.
1053 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1054 || spi->sync_offset == 0 || spi->sync_period == 0) {
1056 xpt_print(periph->path, "no sync rate available\n");
1061 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1062 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1063 ("hit async: giving up on DV\n"));
1069 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1070 * We don't try to remember 'last' settings to see if the SIM actually
1071 * gets into the speed we want to set. We check on the SIM telling
1072 * us that a requested speed is bad, but otherwise don't try and
1073 * check the speed due to the asynchronous and handshake nature
1076 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1079 if (spi->sync_period >= 0xf) {
1080 spi->sync_period = 0;
1081 spi->sync_offset = 0;
1082 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1083 ("setting to async for DV\n"));
1085 * Once we hit async, we don't want to try
1086 * any more settings.
1088 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1089 } else if (bootverbose) {
1090 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1091 ("DV: period 0x%x\n", spi->sync_period));
1092 printf("setting period to 0x%x\n", spi->sync_period);
1094 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1095 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1096 xpt_action((union ccb *)&cts);
1097 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1100 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1101 ("DV: failed to set period 0x%x\n", spi->sync_period));
1102 if (spi->sync_period == 0) {
1109 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1112 probedone(struct cam_periph *periph, union ccb *done_ccb)
1115 struct cam_path *path;
1118 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1120 softc = (probe_softc *)periph->softc;
1121 path = done_ccb->ccb_h.path;
1122 priority = done_ccb->ccb_h.pinfo.priority;
1124 switch (softc->action) {
1127 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1129 if (cam_periph_error(done_ccb, 0,
1130 SF_NO_PRINT, NULL) == ERESTART)
1132 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1133 /* Don't wedge the queue */
1134 xpt_release_devq(done_ccb->ccb_h.path,
1138 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1139 xpt_release_ccb(done_ccb);
1140 xpt_schedule(periph, priority);
1144 case PROBE_FULL_INQUIRY:
1146 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1147 struct scsi_inquiry_data *inq_buf;
1148 u_int8_t periph_qual;
1150 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1151 inq_buf = &path->device->inq_data;
1153 periph_qual = SID_QUAL(inq_buf);
1155 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1159 * We conservatively request only
1160 * SHORT_INQUIRY_LEN bytes of inquiry
1161 * information during our first try
1162 * at sending an INQUIRY. If the device
1163 * has more information to give,
1164 * perform a second request specifying
1165 * the amount of information the device
1166 * is willing to give.
1168 len = inq_buf->additional_length
1169 + offsetof(struct scsi_inquiry_data,
1170 additional_length) + 1;
1171 if (softc->action == PROBE_INQUIRY
1172 && len > SHORT_INQUIRY_LENGTH) {
1173 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1174 xpt_release_ccb(done_ccb);
1175 xpt_schedule(periph, priority);
1179 scsi_find_quirk(path->device);
1181 scsi_devise_transport(path);
1183 if (path->device->lun_id == 0 &&
1184 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1185 (SCSI_QUIRK(path->device)->quirks &
1186 CAM_QUIRK_NORPTLUNS) == 0) {
1187 PROBE_SET_ACTION(softc,
1190 * Start with room for *one* lun.
1192 periph->path->target->rpl_size = 16;
1193 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1194 PROBE_SET_ACTION(softc,
1197 PROBE_SET_ACTION(softc,
1198 PROBE_SUPPORTED_VPD_LIST);
1200 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1201 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1202 xpt_acquire_device(path->device);
1204 xpt_release_ccb(done_ccb);
1205 xpt_schedule(periph, priority);
1207 } else if (path->device->lun_id == 0 &&
1208 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1209 (SCSI_QUIRK(path->device)->quirks &
1210 CAM_QUIRK_NORPTLUNS) == 0) {
1211 if (path->device->flags &
1212 CAM_DEV_UNCONFIGURED) {
1213 path->device->flags &=
1214 ~CAM_DEV_UNCONFIGURED;
1215 xpt_acquire_device(path->device);
1217 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1218 periph->path->target->rpl_size = 16;
1219 xpt_release_ccb(done_ccb);
1220 xpt_schedule(periph, priority);
1223 } else if (cam_periph_error(done_ccb, 0,
1224 done_ccb->ccb_h.target_lun > 0
1225 ? SF_RETRY_UA|SF_QUIET_IR
1227 &softc->saved_ccb) == ERESTART) {
1229 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1230 /* Don't wedge the queue */
1231 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1235 * If we get to this point, we got an error status back
1236 * from the inquiry and the error status doesn't require
1237 * automatically retrying the command. Therefore, the
1238 * inquiry failed. If we had inquiry information before
1239 * for this device, but this latest inquiry command failed,
1240 * the device has probably gone away. If this device isn't
1241 * already marked unconfigured, notify the peripheral
1242 * drivers that this device is no more.
1244 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1245 /* Send the async notification. */
1246 xpt_async(AC_LOST_DEVICE, path, NULL);
1247 PROBE_SET_ACTION(softc, PROBE_INVALID);
1249 xpt_release_ccb(done_ccb);
1252 case PROBE_REPORT_LUNS:
1254 struct ccb_scsiio *csio;
1255 struct scsi_report_luns_data *lp;
1258 csio = &done_ccb->csio;
1260 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1261 nlun = scsi_4btoul(lp->length) / 8;
1262 maxlun = (csio->dxfer_len / 8) - 1;
1264 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1265 if (cam_periph_error(done_ccb, 0,
1266 done_ccb->ccb_h.target_lun > 0 ?
1267 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1268 &softc->saved_ccb) == ERESTART) {
1271 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1272 xpt_release_devq(done_ccb->ccb_h.path, 1,
1277 } else if (nlun > maxlun) {
1279 * Reallocate and retry to cover all luns
1281 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1282 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1285 path->target->rpl_size = (nlun << 3) + 8;
1286 xpt_release_ccb(done_ccb);
1287 xpt_schedule(periph, priority);
1289 } else if (nlun == 0) {
1291 * If there don't appear to be any luns, bail.
1295 } else if (probe_strange_rpl_data(lp, maxlun)) {
1297 * If we can't understand the lun format
1298 * of any entry, bail.
1306 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1307 ("Probe: %u lun(s) reported\n", nlun));
1309 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1311 * If the first lun is not lun 0, then either there
1312 * is no lun 0 in the list, or the list is unsorted.
1315 for (idx = 0; idx < nlun; idx++) {
1316 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1324 lp->luns[0].lundata, 8);
1325 memcpy(lp->luns[0].lundata,
1326 lp->luns[idx].lundata, 8);
1327 memcpy(lp->luns[idx].lundata,
1329 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1330 ("lun 0 in position %u\n", idx));
1333 * There is no lun 0 in our list. Destroy
1334 * the validity of the inquiry data so we
1335 * bail here and now.
1337 path->device->flags &=
1338 ~CAM_DEV_INQUIRY_DATA_VALID;
1342 * If we have an old lun list, We can either
1343 * retest luns that appear to have been dropped,
1344 * or just nuke them. We'll opt for the latter.
1345 * This function will also install the new list
1346 * in the target structure.
1348 probe_purge_old(path, lp);
1351 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1352 struct scsi_inquiry_data *inq_buf;
1353 inq_buf = &path->device->inq_data;
1354 if (INQ_DATA_TQ_ENABLED(inq_buf))
1355 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1357 PROBE_SET_ACTION(softc,
1358 PROBE_SUPPORTED_VPD_LIST);
1359 xpt_release_ccb(done_ccb);
1360 xpt_schedule(periph, priority);
1368 case PROBE_MODE_SENSE:
1370 struct ccb_scsiio *csio;
1371 struct scsi_mode_header_6 *mode_hdr;
1373 csio = &done_ccb->csio;
1374 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1375 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1376 struct scsi_control_page *page;
1379 offset = ((u_int8_t *)&mode_hdr[1])
1380 + mode_hdr->blk_desc_len;
1381 page = (struct scsi_control_page *)offset;
1382 path->device->queue_flags = page->queue_flags;
1383 } else if (cam_periph_error(done_ccb, 0,
1384 SF_RETRY_UA|SF_NO_PRINT,
1385 &softc->saved_ccb) == ERESTART) {
1387 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1388 /* Don't wedge the queue */
1389 xpt_release_devq(done_ccb->ccb_h.path,
1390 /*count*/1, /*run_queue*/TRUE);
1392 xpt_release_ccb(done_ccb);
1393 free(mode_hdr, M_CAMXPT);
1394 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1395 xpt_schedule(periph, priority);
1398 case PROBE_SUPPORTED_VPD_LIST:
1400 struct ccb_scsiio *csio;
1401 struct scsi_vpd_supported_page_list *page_list;
1403 csio = &done_ccb->csio;
1405 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1407 if (path->device->supported_vpds != NULL) {
1408 free(path->device->supported_vpds, M_CAMXPT);
1409 path->device->supported_vpds = NULL;
1410 path->device->supported_vpds_len = 0;
1413 if (page_list == NULL) {
1415 * Don't process the command as it was never sent
1417 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1419 path->device->supported_vpds_len = page_list->length +
1420 SVPD_SUPPORTED_PAGES_HDR_LEN;
1421 path->device->supported_vpds = (uint8_t *)page_list;
1422 xpt_release_ccb(done_ccb);
1423 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1424 xpt_schedule(periph, priority);
1426 } else if (cam_periph_error(done_ccb, 0,
1427 SF_RETRY_UA|SF_NO_PRINT,
1428 &softc->saved_ccb) == ERESTART) {
1430 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1431 /* Don't wedge the queue */
1432 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1437 free(page_list, M_CAMXPT);
1438 /* No VPDs available, skip to device check. */
1439 csio->data_ptr = NULL;
1440 goto probe_device_check;
1442 case PROBE_DEVICE_ID:
1444 struct scsi_vpd_device_id *devid;
1445 struct ccb_scsiio *csio;
1446 uint32_t length = 0;
1448 csio = &done_ccb->csio;
1449 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1451 /* Clean up from previous instance of this device */
1452 if (path->device->device_id != NULL) {
1453 path->device->device_id_len = 0;
1454 free(path->device->device_id, M_CAMXPT);
1455 path->device->device_id = NULL;
1458 if (devid == NULL) {
1459 /* Don't process the command as it was never sent */
1460 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1461 length = scsi_2btoul(devid->length);
1464 * NB: device_id_len is actual response
1465 * size, not buffer size.
1467 path->device->device_id_len = length +
1468 SVPD_DEVICE_ID_HDR_LEN;
1469 path->device->device_id = (uint8_t *)devid;
1471 } else if (cam_periph_error(done_ccb, 0,
1473 &softc->saved_ccb) == ERESTART) {
1475 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1476 /* Don't wedge the queue */
1477 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1481 /* Free the device id space if we don't use it */
1482 if (devid && length == 0)
1483 free(devid, M_CAMXPT);
1484 xpt_release_ccb(done_ccb);
1485 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1486 xpt_schedule(periph, priority);
1491 case PROBE_SERIAL_NUM:
1493 struct ccb_scsiio *csio;
1494 struct scsi_vpd_unit_serial_number *serial_buf;
1501 csio = &done_ccb->csio;
1502 priority = done_ccb->ccb_h.pinfo.priority;
1504 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1506 if (serial_buf == NULL) {
1508 * Don't process the command as it was never sent
1510 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1511 && (serial_buf->length > 0)) {
1514 path->device->serial_num =
1515 (u_int8_t *)malloc((serial_buf->length + 1),
1516 M_CAMXPT, M_NOWAIT);
1517 if (path->device->serial_num != NULL) {
1518 memcpy(path->device->serial_num,
1519 serial_buf->serial_num,
1520 serial_buf->length);
1521 path->device->serial_num_len =
1523 path->device->serial_num[serial_buf->length]
1526 } else if (cam_periph_error(done_ccb, 0,
1527 SF_RETRY_UA|SF_NO_PRINT,
1528 &softc->saved_ccb) == ERESTART) {
1530 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1531 /* Don't wedge the queue */
1532 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1537 * Let's see if we have seen this device before.
1539 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1541 u_int8_t digest[16];
1546 (unsigned char *)&path->device->inq_data,
1547 sizeof(struct scsi_inquiry_data));
1550 MD5Update(&context, serial_buf->serial_num,
1551 serial_buf->length);
1553 MD5Final(digest, &context);
1554 if (bcmp(softc->digest, digest, 16) == 0)
1558 * XXX Do we need to do a TUR in order to ensure
1559 * that the device really hasn't changed???
1562 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1563 xpt_async(AC_LOST_DEVICE, path, NULL);
1565 if (serial_buf != NULL)
1566 free(serial_buf, M_CAMXPT);
1570 * Now that we have all the necessary
1571 * information to safely perform transfer
1572 * negotiations... Controllers don't perform
1573 * any negotiation or tagged queuing until
1574 * after the first XPT_SET_TRAN_SETTINGS ccb is
1575 * received. So, on a new device, just retrieve
1576 * the user settings, and set them as the current
1577 * settings to set the device up.
1579 proberequestdefaultnegotiation(periph);
1580 xpt_release_ccb(done_ccb);
1583 * Perform a TUR to allow the controller to
1584 * perform any necessary transfer negotiation.
1586 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1587 xpt_schedule(periph, priority);
1590 xpt_release_ccb(done_ccb);
1593 case PROBE_TUR_FOR_NEGOTIATION:
1595 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1596 cam_periph_error(done_ccb, 0,
1597 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1599 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1600 /* Don't wedge the queue */
1601 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1605 * Do Domain Validation for lun 0 on devices that claim
1606 * to support Synchronous Transfer modes.
1608 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1609 && done_ccb->ccb_h.target_lun == 0
1610 && (path->device->inq_data.flags & SID_Sync) != 0
1611 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1612 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1613 ("Begin Domain Validation\n"));
1614 path->device->flags |= CAM_DEV_IN_DV;
1615 xpt_release_ccb(done_ccb);
1616 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1617 xpt_schedule(periph, priority);
1620 if (softc->action == PROBE_DV_EXIT) {
1621 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1622 ("Leave Domain Validation\n"));
1624 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1625 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1626 xpt_acquire_device(path->device);
1628 path->device->flags &=
1629 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1630 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1631 /* Inform the XPT that a new device has been found */
1632 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1633 xpt_action(done_ccb);
1634 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1637 PROBE_SET_ACTION(softc, PROBE_DONE);
1638 xpt_release_ccb(done_ccb);
1640 case PROBE_INQUIRY_BASIC_DV1:
1641 case PROBE_INQUIRY_BASIC_DV2:
1643 struct scsi_inquiry_data *nbuf;
1644 struct ccb_scsiio *csio;
1646 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1647 cam_periph_error(done_ccb, 0,
1648 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1650 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1651 /* Don't wedge the queue */
1652 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1655 csio = &done_ccb->csio;
1656 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1657 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1659 "inquiry data fails comparison at DV%d step\n",
1660 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1661 if (proberequestbackoff(periph, path->device)) {
1662 path->device->flags &= ~CAM_DEV_IN_DV;
1663 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1666 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1668 free(nbuf, M_CAMXPT);
1669 xpt_release_ccb(done_ccb);
1670 xpt_schedule(periph, priority);
1673 free(nbuf, M_CAMXPT);
1674 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1675 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1676 xpt_release_ccb(done_ccb);
1677 xpt_schedule(periph, priority);
1680 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1681 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1682 ("Leave Domain Validation Successfully\n"));
1684 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1685 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1686 xpt_acquire_device(path->device);
1688 path->device->flags &=
1689 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1690 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1691 /* Inform the XPT that a new device has been found */
1692 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1693 xpt_action(done_ccb);
1694 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1697 PROBE_SET_ACTION(softc, PROBE_DONE);
1698 xpt_release_ccb(done_ccb);
1702 panic("probedone: invalid action state 0x%x\n", softc->action);
1704 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1705 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1706 done_ccb->ccb_h.status = CAM_REQ_CMP;
1708 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1709 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1710 cam_periph_invalidate(periph);
1711 cam_release_devq(periph->path,
1712 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1713 cam_periph_release_locked(periph);
1715 probeschedule(periph);
1720 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1723 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1725 for (idx = 0; idx < nlun; idx++) {
1726 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1734 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1736 struct cam_path *tp;
1737 struct scsi_report_luns_data *old;
1738 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1741 if (path->target == NULL) {
1744 if (path->target->luns == NULL) {
1745 path->target->luns = new;
1748 old = path->target->luns;
1749 nlun_old = scsi_4btoul(old->length) / 8;
1750 nlun_new = scsi_4btoul(new->length) / 8;
1753 * We are not going to assume sorted lists. Deal.
1755 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1756 ol = old->luns[idx1].lundata;
1757 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1758 nl = new->luns[idx2].lundata;
1759 if (memcmp(nl, ol, 8) == 0) {
1763 if (idx2 < nlun_new) {
1767 * An 'old' item not in the 'new' list.
1768 * Nuke it. Except that if it is lun 0,
1769 * that would be what the probe state
1770 * machine is currently working on,
1771 * so we won't do that.
1773 * We also cannot nuke it if it is
1774 * not in a lun format we understand.
1776 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1779 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1780 if (this_lun == 0) {
1783 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1784 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1785 xpt_async(AC_LOST_DEVICE, tp, NULL);
1789 free(old, M_CAMXPT);
1790 path->target->luns = new;
1794 probecleanup(struct cam_periph *periph)
1796 free(periph->softc, M_CAMXPT);
1800 scsi_find_quirk(struct cam_ed *device)
1802 struct scsi_quirk_entry *quirk;
1805 match = cam_quirkmatch((caddr_t)&device->inq_data,
1806 (caddr_t)scsi_quirk_table,
1807 sizeof(scsi_quirk_table) /
1808 sizeof(*scsi_quirk_table),
1809 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1812 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1814 quirk = (struct scsi_quirk_entry *)match;
1815 device->quirk = quirk;
1816 device->mintags = quirk->mintags;
1817 device->maxtags = quirk->maxtags;
1821 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1826 error = sysctl_handle_int(oidp, &val, 0, req);
1827 if (error != 0 || req->newptr == NULL)
1829 if (val == 0 || val == 1) {
1838 union ccb *request_ccb;
1839 struct ccb_pathinq *cpi;
1842 } scsi_scan_bus_info;
1845 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1846 * As the scan progresses, scsi_scan_bus is used as the
1847 * callback on completion function.
1850 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1852 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1853 ("scsi_scan_bus\n"));
1854 switch (request_ccb->ccb_h.func_code) {
1858 scsi_scan_bus_info *scan_info;
1859 union ccb *work_ccb, *reset_ccb;
1860 struct cam_path *path;
1862 u_int low_target, max_target;
1865 /* Find out the characteristics of the bus */
1866 work_ccb = xpt_alloc_ccb_nowait();
1867 if (work_ccb == NULL) {
1868 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1869 xpt_done(request_ccb);
1872 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1873 request_ccb->ccb_h.pinfo.priority);
1874 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1875 xpt_action(work_ccb);
1876 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1877 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1878 xpt_free_ccb(work_ccb);
1879 xpt_done(request_ccb);
1883 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1885 * Can't scan the bus on an adapter that
1886 * cannot perform the initiator role.
1888 request_ccb->ccb_h.status = CAM_REQ_CMP;
1889 xpt_free_ccb(work_ccb);
1890 xpt_done(request_ccb);
1894 /* We may need to reset bus first, if we haven't done it yet. */
1895 if ((work_ccb->cpi.hba_inquiry &
1896 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1897 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1898 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1899 reset_ccb = xpt_alloc_ccb_nowait();
1900 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1902 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1903 xpt_action(reset_ccb);
1904 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1905 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1906 xpt_free_ccb(reset_ccb);
1907 xpt_free_ccb(work_ccb);
1908 xpt_done(request_ccb);
1911 xpt_free_ccb(reset_ccb);
1914 /* Save some state for use while we probe for devices */
1915 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1916 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1917 if (scan_info == NULL) {
1918 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1919 xpt_done(request_ccb);
1922 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1923 ("SCAN start for %p\n", scan_info));
1924 scan_info->request_ccb = request_ccb;
1925 scan_info->cpi = &work_ccb->cpi;
1927 /* Cache on our stack so we can work asynchronously */
1928 max_target = scan_info->cpi->max_target;
1930 initiator_id = scan_info->cpi->initiator_id;
1934 * We can scan all targets in parallel, or do it sequentially.
1937 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1938 max_target = low_target = request_ccb->ccb_h.target_id;
1939 scan_info->counter = 0;
1940 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1942 scan_info->counter = 0;
1944 scan_info->counter = scan_info->cpi->max_target + 1;
1945 if (scan_info->cpi->initiator_id < scan_info->counter) {
1946 scan_info->counter--;
1950 for (i = low_target; i <= max_target; i++) {
1952 if (i == initiator_id)
1955 status = xpt_create_path(&path, xpt_periph,
1956 request_ccb->ccb_h.path_id,
1958 if (status != CAM_REQ_CMP) {
1959 printf("scsi_scan_bus: xpt_create_path failed"
1960 " with status %#x, bus scan halted\n",
1962 free(scan_info, M_CAMXPT);
1963 request_ccb->ccb_h.status = status;
1964 xpt_free_ccb(work_ccb);
1965 xpt_done(request_ccb);
1968 work_ccb = xpt_alloc_ccb_nowait();
1969 if (work_ccb == NULL) {
1970 xpt_free_ccb((union ccb *)scan_info->cpi);
1971 free(scan_info, M_CAMXPT);
1972 xpt_free_path(path);
1973 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1974 xpt_done(request_ccb);
1977 xpt_setup_ccb(&work_ccb->ccb_h, path,
1978 request_ccb->ccb_h.pinfo.priority);
1979 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1980 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1981 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1982 work_ccb->crcn.flags = request_ccb->crcn.flags;
1983 xpt_action(work_ccb);
1990 struct cam_path *path, *oldpath;
1991 scsi_scan_bus_info *scan_info;
1992 struct cam_et *target;
1993 struct cam_ed *device;
1996 target_id_t target_id;
1999 oldpath = request_ccb->ccb_h.path;
2001 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
2002 /* Reuse the same CCB to query if a device was really found */
2003 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
2004 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
2005 request_ccb->ccb_h.pinfo.priority);
2006 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
2009 path_id = request_ccb->ccb_h.path_id;
2010 target_id = request_ccb->ccb_h.target_id;
2011 lun_id = request_ccb->ccb_h.target_lun;
2012 xpt_action(request_ccb);
2014 target = request_ccb->ccb_h.path->target;
2019 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2022 * Make sure we skip over lun 0 if it's the first member
2023 * of the list as we've actually just finished probing
2026 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
2027 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2028 scan_info->lunindex[target_id]++;
2031 if (scan_info->lunindex[target_id] < nluns) {
2032 CAM_GET_SIMPLE_LUN(target->luns,
2033 scan_info->lunindex[target_id], lun_id);
2035 CAM_DEBUG(request_ccb->ccb_h.path,
2037 ("next lun to try at index %u is %u\n",
2038 scan_info->lunindex[target_id], lun_id));
2039 scan_info->lunindex[target_id]++;
2042 * We're done with scanning all luns.
2044 * Nuke the bogus device for lun 0 if lun 0
2045 * wasn't on the list.
2048 TAILQ_FOREACH(device,
2049 &target->ed_entries, links) {
2050 if (device->lun_id == 0) {
2055 xpt_release_device(device);
2059 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2063 * If we already probed lun 0 successfully, or
2064 * we have additional configured luns on this
2065 * target that might have "gone away", go onto
2069 * We may touch devices that we don't
2070 * hold references too, so ensure they
2071 * don't disappear out from under us.
2072 * The target above is referenced by the
2073 * path in the request ccb.
2076 device = TAILQ_FIRST(&target->ed_entries);
2077 if (device != NULL) {
2078 phl = CAN_SRCH_HI_SPARSE(device);
2079 if (device->lun_id == 0)
2080 device = TAILQ_NEXT(device, links);
2082 if ((lun_id != 0) || (device != NULL)) {
2083 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2088 if (lun_id == request_ccb->ccb_h.target_lun
2089 || lun_id > scan_info->cpi->max_lun)
2093 device = request_ccb->ccb_h.path->device;
2095 if ((SCSI_QUIRK(device)->quirks &
2096 CAM_QUIRK_NOLUNS) == 0) {
2097 /* Try the next lun */
2098 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2099 || CAN_SRCH_HI_DENSE(device)) {
2104 if (lun_id == request_ccb->ccb_h.target_lun
2105 || lun_id > scan_info->cpi->max_lun)
2110 * Check to see if we scan any further luns.
2116 * Free the current request path- we're done with it.
2118 xpt_free_path(oldpath);
2121 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2123 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2124 scan_info->counter++;
2125 if (scan_info->counter ==
2126 scan_info->cpi->initiator_id) {
2127 scan_info->counter++;
2129 if (scan_info->counter >=
2130 scan_info->cpi->max_target+1) {
2134 scan_info->counter--;
2135 if (scan_info->counter == 0) {
2140 xpt_free_ccb(request_ccb);
2141 xpt_free_ccb((union ccb *)scan_info->cpi);
2142 request_ccb = scan_info->request_ccb;
2143 CAM_DEBUG(request_ccb->ccb_h.path,
2145 ("SCAN done for %p\n", scan_info));
2146 free(scan_info, M_CAMXPT);
2147 request_ccb->ccb_h.status = CAM_REQ_CMP;
2148 xpt_done(request_ccb);
2152 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2153 xpt_free_ccb(request_ccb);
2156 status = xpt_create_path(&path, xpt_periph,
2157 scan_info->request_ccb->ccb_h.path_id,
2158 scan_info->counter, 0);
2159 if (status != CAM_REQ_CMP) {
2160 printf("scsi_scan_bus: xpt_create_path failed"
2161 " with status %#x, bus scan halted\n",
2163 xpt_free_ccb(request_ccb);
2164 xpt_free_ccb((union ccb *)scan_info->cpi);
2165 request_ccb = scan_info->request_ccb;
2166 free(scan_info, M_CAMXPT);
2167 request_ccb->ccb_h.status = status;
2168 xpt_done(request_ccb);
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.ppriv_ptr0 = scan_info;
2176 request_ccb->crcn.flags =
2177 scan_info->request_ccb->crcn.flags;
2179 status = xpt_create_path(&path, xpt_periph,
2180 path_id, target_id, lun_id);
2182 * Free the old request path- we're done with it. We
2183 * do this *after* creating the new path so that
2184 * we don't remove a target that has our lun list
2185 * in the case that lun 0 is not present.
2187 xpt_free_path(oldpath);
2188 if (status != CAM_REQ_CMP) {
2189 printf("scsi_scan_bus: xpt_create_path failed "
2190 "with status %#x, halting LUN scan\n",
2194 xpt_setup_ccb(&request_ccb->ccb_h, path,
2195 request_ccb->ccb_h.pinfo.priority);
2196 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2197 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2198 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2199 request_ccb->crcn.flags =
2200 scan_info->request_ccb->crcn.flags;
2202 xpt_action(request_ccb);
2211 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2212 cam_flags flags, union ccb *request_ccb)
2214 struct ccb_pathinq cpi;
2216 struct cam_path *new_path;
2217 struct cam_periph *old_periph;
2219 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2221 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2222 cpi.ccb_h.func_code = XPT_PATH_INQ;
2223 xpt_action((union ccb *)&cpi);
2225 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2226 if (request_ccb != NULL) {
2227 request_ccb->ccb_h.status = cpi.ccb_h.status;
2228 xpt_done(request_ccb);
2233 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2235 * Can't scan the bus on an adapter that
2236 * cannot perform the initiator role.
2238 if (request_ccb != NULL) {
2239 request_ccb->ccb_h.status = CAM_REQ_CMP;
2240 xpt_done(request_ccb);
2245 if (request_ccb == NULL) {
2246 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
2247 if (request_ccb == NULL) {
2248 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2249 "can't continue\n");
2252 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
2253 if (new_path == NULL) {
2254 xpt_print(path, "scsi_scan_lun: can't allocate path, "
2255 "can't continue\n");
2256 free(request_ccb, M_CAMXPT);
2259 status = xpt_compile_path(new_path, xpt_periph,
2261 path->target->target_id,
2262 path->device->lun_id);
2264 if (status != CAM_REQ_CMP) {
2265 xpt_print(path, "scsi_scan_lun: can't compile path, "
2266 "can't continue\n");
2267 free(request_ccb, M_CAMXPT);
2268 free(new_path, M_CAMXPT);
2271 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2272 request_ccb->ccb_h.cbfcnp = xptscandone;
2273 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2274 request_ccb->crcn.flags = flags;
2277 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2278 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2281 softc = (probe_softc *)old_periph->softc;
2282 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2283 &request_ccb->ccb_h, periph_links.tqe);
2285 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2286 xpt_done(request_ccb);
2289 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2290 probestart, "probe",
2292 request_ccb->ccb_h.path, NULL, 0,
2295 if (status != CAM_REQ_CMP) {
2296 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2297 "returned an error, can't continue probe\n");
2298 request_ccb->ccb_h.status = status;
2299 xpt_done(request_ccb);
2305 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2307 xpt_release_path(done_ccb->ccb_h.path);
2308 free(done_ccb->ccb_h.path, M_CAMXPT);
2309 free(done_ccb, M_CAMXPT);
2312 static struct cam_ed *
2313 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2315 struct cam_path path;
2316 struct scsi_quirk_entry *quirk;
2317 struct cam_ed *device;
2318 struct cam_ed *cur_device;
2320 device = xpt_alloc_device(bus, target, lun_id);
2325 * Take the default quirk entry until we have inquiry
2326 * data and can determine a better quirk to use.
2328 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2329 device->quirk = (void *)quirk;
2330 device->mintags = quirk->mintags;
2331 device->maxtags = quirk->maxtags;
2332 bzero(&device->inq_data, sizeof(device->inq_data));
2333 device->inq_flags = 0;
2334 device->queue_flags = 0;
2335 device->serial_num = NULL;
2336 device->serial_num_len = 0;
2337 device->device_id = NULL;
2338 device->device_id_len = 0;
2339 device->supported_vpds = NULL;
2340 device->supported_vpds_len = 0;
2343 * XXX should be limited by number of CCBs this bus can
2346 bus->sim->max_ccbs += device->ccbq.devq_openings;
2347 /* Insertion sort into our target's device list */
2348 cur_device = TAILQ_FIRST(&target->ed_entries);
2349 while (cur_device != NULL && cur_device->lun_id < lun_id)
2350 cur_device = TAILQ_NEXT(cur_device, links);
2351 if (cur_device != NULL) {
2352 TAILQ_INSERT_BEFORE(cur_device, device, links);
2354 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
2356 target->generation++;
2357 if (lun_id != CAM_LUN_WILDCARD) {
2358 xpt_compile_path(&path,
2363 scsi_devise_transport(&path);
2364 xpt_release_path(&path);
2371 scsi_devise_transport(struct cam_path *path)
2373 struct ccb_pathinq cpi;
2374 struct ccb_trans_settings cts;
2375 struct scsi_inquiry_data *inq_buf;
2377 /* Get transport information from the SIM */
2378 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2379 cpi.ccb_h.func_code = XPT_PATH_INQ;
2380 xpt_action((union ccb *)&cpi);
2383 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2384 inq_buf = &path->device->inq_data;
2385 path->device->protocol = PROTO_SCSI;
2386 path->device->protocol_version =
2387 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2388 path->device->transport = cpi.transport;
2389 path->device->transport_version = cpi.transport_version;
2392 * Any device not using SPI3 features should
2393 * be considered SPI2 or lower.
2395 if (inq_buf != NULL) {
2396 if (path->device->transport == XPORT_SPI
2397 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2398 && path->device->transport_version > 2)
2399 path->device->transport_version = 2;
2401 struct cam_ed* otherdev;
2403 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2405 otherdev = TAILQ_NEXT(otherdev, links)) {
2406 if (otherdev != path->device)
2410 if (otherdev != NULL) {
2412 * Initially assume the same versioning as
2413 * prior luns for this target.
2415 path->device->protocol_version =
2416 otherdev->protocol_version;
2417 path->device->transport_version =
2418 otherdev->transport_version;
2420 /* Until we know better, opt for safty */
2421 path->device->protocol_version = 2;
2422 if (path->device->transport == XPORT_SPI)
2423 path->device->transport_version = 2;
2425 path->device->transport_version = 0;
2431 * For a device compliant with SPC-2 we should be able
2432 * to determine the transport version supported by
2433 * scrutinizing the version descriptors in the
2437 /* Tell the controller what we think */
2438 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2439 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2440 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2441 cts.transport = path->device->transport;
2442 cts.transport_version = path->device->transport_version;
2443 cts.protocol = path->device->protocol;
2444 cts.protocol_version = path->device->protocol_version;
2445 cts.proto_specific.valid = 0;
2446 cts.xport_specific.valid = 0;
2447 xpt_action((union ccb *)&cts);
2451 scsi_dev_advinfo(union ccb *start_ccb)
2453 struct cam_ed *device;
2454 struct ccb_dev_advinfo *cdai;
2457 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2458 device = start_ccb->ccb_h.path->device;
2459 cdai = &start_ccb->cdai;
2460 switch(cdai->buftype) {
2461 case CDAI_TYPE_SCSI_DEVID:
2462 if (cdai->flags & CDAI_FLAG_STORE)
2464 cdai->provsiz = device->device_id_len;
2465 if (device->device_id_len == 0)
2467 amt = device->device_id_len;
2468 if (cdai->provsiz > cdai->bufsiz)
2470 memcpy(cdai->buf, device->device_id, amt);
2472 case CDAI_TYPE_SERIAL_NUM:
2473 if (cdai->flags & CDAI_FLAG_STORE)
2475 cdai->provsiz = device->serial_num_len;
2476 if (device->serial_num_len == 0)
2478 amt = device->serial_num_len;
2479 if (cdai->provsiz > cdai->bufsiz)
2481 memcpy(cdai->buf, device->serial_num, amt);
2483 case CDAI_TYPE_PHYS_PATH:
2484 if (cdai->flags & CDAI_FLAG_STORE) {
2485 if (device->physpath != NULL)
2486 free(device->physpath, M_CAMXPT);
2487 device->physpath_len = cdai->bufsiz;
2488 /* Clear existing buffer if zero length */
2489 if (cdai->bufsiz == 0)
2491 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2492 if (device->physpath == NULL) {
2493 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2496 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2498 cdai->provsiz = device->physpath_len;
2499 if (device->physpath_len == 0)
2501 amt = device->physpath_len;
2502 if (cdai->provsiz > cdai->bufsiz)
2504 memcpy(cdai->buf, device->physpath, amt);
2510 start_ccb->ccb_h.status = CAM_REQ_CMP;
2512 if (cdai->flags & CDAI_FLAG_STORE) {
2515 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
2517 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
2518 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2519 (void *)(uintptr_t)cdai->buftype);
2521 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
2526 scsi_action(union ccb *start_ccb)
2529 switch (start_ccb->ccb_h.func_code) {
2530 case XPT_SET_TRAN_SETTINGS:
2532 scsi_set_transfer_settings(&start_ccb->cts,
2533 start_ccb->ccb_h.path->device,
2534 /*async_update*/FALSE);
2539 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2542 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2543 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2546 case XPT_GET_TRAN_SETTINGS:
2548 struct cam_sim *sim;
2550 sim = start_ccb->ccb_h.path->bus->sim;
2551 (*(sim->sim_action))(sim, start_ccb);
2554 case XPT_DEV_ADVINFO:
2556 scsi_dev_advinfo(start_ccb);
2560 xpt_action_default(start_ccb);
2566 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2569 struct ccb_pathinq cpi;
2570 struct ccb_trans_settings cur_cts;
2571 struct ccb_trans_settings_scsi *scsi;
2572 struct ccb_trans_settings_scsi *cur_scsi;
2573 struct cam_sim *sim;
2574 struct scsi_inquiry_data *inq_data;
2576 if (device == NULL) {
2577 cts->ccb_h.status = CAM_PATH_INVALID;
2578 xpt_done((union ccb *)cts);
2582 if (cts->protocol == PROTO_UNKNOWN
2583 || cts->protocol == PROTO_UNSPECIFIED) {
2584 cts->protocol = device->protocol;
2585 cts->protocol_version = device->protocol_version;
2588 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2589 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2590 cts->protocol_version = device->protocol_version;
2592 if (cts->protocol != device->protocol) {
2593 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2594 cts->protocol, device->protocol);
2595 cts->protocol = device->protocol;
2598 if (cts->protocol_version > device->protocol_version) {
2600 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2601 "Version from %d to %d?\n", cts->protocol_version,
2602 device->protocol_version);
2604 cts->protocol_version = device->protocol_version;
2607 if (cts->transport == XPORT_UNKNOWN
2608 || cts->transport == XPORT_UNSPECIFIED) {
2609 cts->transport = device->transport;
2610 cts->transport_version = device->transport_version;
2613 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2614 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2615 cts->transport_version = device->transport_version;
2617 if (cts->transport != device->transport) {
2618 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2619 cts->transport, device->transport);
2620 cts->transport = device->transport;
2623 if (cts->transport_version > device->transport_version) {
2625 xpt_print(cts->ccb_h.path, "Down reving Transport "
2626 "Version from %d to %d?\n", cts->transport_version,
2627 device->transport_version);
2629 cts->transport_version = device->transport_version;
2632 sim = cts->ccb_h.path->bus->sim;
2635 * Nothing more of interest to do unless
2636 * this is a device connected via the
2639 if (cts->protocol != PROTO_SCSI) {
2640 if (async_update == FALSE)
2641 (*(sim->sim_action))(sim, (union ccb *)cts);
2645 inq_data = &device->inq_data;
2646 scsi = &cts->proto_specific.scsi;
2647 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2648 cpi.ccb_h.func_code = XPT_PATH_INQ;
2649 xpt_action((union ccb *)&cpi);
2651 /* SCSI specific sanity checking */
2652 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2653 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2654 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2655 || (device->mintags == 0)) {
2657 * Can't tag on hardware that doesn't support tags,
2658 * doesn't have it enabled, or has broken tag support.
2660 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2663 if (async_update == FALSE) {
2665 * Perform sanity checking against what the
2666 * controller and device can do.
2668 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2669 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2670 cur_cts.type = cts->type;
2671 xpt_action((union ccb *)&cur_cts);
2672 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2675 cur_scsi = &cur_cts.proto_specific.scsi;
2676 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2677 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2678 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2680 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2681 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2684 /* SPI specific sanity checking */
2685 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2687 struct ccb_trans_settings_spi *spi;
2688 struct ccb_trans_settings_spi *cur_spi;
2690 spi = &cts->xport_specific.spi;
2692 cur_spi = &cur_cts.xport_specific.spi;
2694 /* Fill in any gaps in what the user gave us */
2695 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2696 spi->sync_period = cur_spi->sync_period;
2697 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2698 spi->sync_period = 0;
2699 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2700 spi->sync_offset = cur_spi->sync_offset;
2701 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2702 spi->sync_offset = 0;
2703 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2704 spi->ppr_options = cur_spi->ppr_options;
2705 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2706 spi->ppr_options = 0;
2707 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2708 spi->bus_width = cur_spi->bus_width;
2709 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2711 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2712 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2713 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2715 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2716 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2717 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2718 && (inq_data->flags & SID_Sync) == 0
2719 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2720 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2722 spi->sync_period = 0;
2723 spi->sync_offset = 0;
2726 switch (spi->bus_width) {
2727 case MSG_EXT_WDTR_BUS_32_BIT:
2728 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2729 || (inq_data->flags & SID_WBus32) != 0
2730 || cts->type == CTS_TYPE_USER_SETTINGS)
2731 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2733 /* Fall Through to 16-bit */
2734 case MSG_EXT_WDTR_BUS_16_BIT:
2735 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2736 || (inq_data->flags & SID_WBus16) != 0
2737 || cts->type == CTS_TYPE_USER_SETTINGS)
2738 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2739 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2742 /* Fall Through to 8-bit */
2743 default: /* New bus width?? */
2744 case MSG_EXT_WDTR_BUS_8_BIT:
2745 /* All targets can do this */
2746 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2750 spi3caps = cpi.xport_specific.spi.ppr_options;
2751 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2752 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2753 spi3caps &= inq_data->spi3data;
2755 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2756 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2758 if ((spi3caps & SID_SPI_IUS) == 0)
2759 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2761 if ((spi3caps & SID_SPI_QAS) == 0)
2762 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2764 /* No SPI Transfer settings are allowed unless we are wide */
2765 if (spi->bus_width == 0)
2766 spi->ppr_options = 0;
2768 if ((spi->valid & CTS_SPI_VALID_DISC)
2769 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2771 * Can't tag queue without disconnection.
2773 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2774 scsi->valid |= CTS_SCSI_VALID_TQ;
2778 * If we are currently performing tagged transactions to
2779 * this device and want to change its negotiation parameters,
2780 * go non-tagged for a bit to give the controller a chance to
2781 * negotiate unhampered by tag messages.
2783 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2784 && (device->inq_flags & SID_CmdQue) != 0
2785 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2786 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2787 CTS_SPI_VALID_SYNC_OFFSET|
2788 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2789 scsi_toggle_tags(cts->ccb_h.path);
2792 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2793 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2797 * If we are transitioning from tags to no-tags or
2798 * vice-versa, we need to carefully freeze and restart
2799 * the queue so that we don't overlap tagged and non-tagged
2800 * commands. We also temporarily stop tags if there is
2801 * a change in transfer negotiation settings to allow
2802 * "tag-less" negotiation.
2804 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2805 || (device->inq_flags & SID_CmdQue) != 0)
2806 device_tagenb = TRUE;
2808 device_tagenb = FALSE;
2810 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2811 && device_tagenb == FALSE)
2812 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2813 && device_tagenb == TRUE)) {
2815 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2817 * Delay change to use tags until after a
2818 * few commands have gone to this device so
2819 * the controller has time to perform transfer
2820 * negotiations without tagged messages getting
2823 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2824 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2826 xpt_stop_tags(cts->ccb_h.path);
2830 if (async_update == FALSE)
2831 (*(sim->sim_action))(sim, (union ccb *)cts);
2835 scsi_toggle_tags(struct cam_path *path)
2840 * Give controllers a chance to renegotiate
2841 * before starting tag operations. We
2842 * "toggle" tagged queuing off then on
2843 * which causes the tag enable command delay
2844 * counter to come into effect.
2847 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2848 || ((dev->inq_flags & SID_CmdQue) != 0
2849 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2850 struct ccb_trans_settings cts;
2852 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2853 cts.protocol = PROTO_SCSI;
2854 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2855 cts.transport = XPORT_UNSPECIFIED;
2856 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2857 cts.proto_specific.scsi.flags = 0;
2858 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2859 scsi_set_transfer_settings(&cts, path->device,
2860 /*async_update*/TRUE);
2861 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2862 scsi_set_transfer_settings(&cts, path->device,
2863 /*async_update*/TRUE);
2868 * Handle any per-device event notifications that require action by the XPT.
2871 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2872 struct cam_ed *device, void *async_arg)
2875 struct cam_path newpath;
2878 * We only need to handle events for real devices.
2880 if (target->target_id == CAM_TARGET_WILDCARD
2881 || device->lun_id == CAM_LUN_WILDCARD)
2885 * We need our own path with wildcards expanded to
2886 * handle certain types of events.
2888 if ((async_code == AC_SENT_BDR)
2889 || (async_code == AC_BUS_RESET)
2890 || (async_code == AC_INQ_CHANGED))
2891 status = xpt_compile_path(&newpath, NULL,
2896 status = CAM_REQ_CMP_ERR;
2898 if (status == CAM_REQ_CMP) {
2901 * Allow transfer negotiation to occur in a
2902 * tag free environment and after settle delay.
2904 if (async_code == AC_SENT_BDR
2905 || async_code == AC_BUS_RESET) {
2906 cam_freeze_devq(&newpath);
2907 cam_release_devq(&newpath,
2908 RELSIM_RELEASE_AFTER_TIMEOUT,
2910 /*timeout*/scsi_delay,
2911 /*getcount_only*/0);
2912 scsi_toggle_tags(&newpath);
2915 if (async_code == AC_INQ_CHANGED) {
2917 * We've sent a start unit command, or
2918 * something similar to a device that
2919 * may have caused its inquiry data to
2920 * change. So we re-scan the device to
2921 * refresh the inquiry data for it.
2923 scsi_scan_lun(newpath.periph, &newpath,
2924 CAM_EXPECT_INQ_CHANGE, NULL);
2926 xpt_release_path(&newpath);
2927 } else if (async_code == AC_LOST_DEVICE &&
2928 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2929 device->flags |= CAM_DEV_UNCONFIGURED;
2930 xpt_release_device(device);
2931 } else if (async_code == AC_TRANSFER_NEG) {
2932 struct ccb_trans_settings *settings;
2934 settings = (struct ccb_trans_settings *)async_arg;
2935 scsi_set_transfer_settings(settings, device,
2936 /*async_update*/TRUE);
2941 scsi_announce_periph(struct cam_periph *periph)
2943 struct ccb_pathinq cpi;
2944 struct ccb_trans_settings cts;
2945 struct cam_path *path = periph->path;
2950 mtx_assert(periph->sim->mtx, MA_OWNED);
2952 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2953 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2954 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2955 xpt_action((union ccb*)&cts);
2956 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2958 /* Ask the SIM for its base transfer speed */
2959 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2960 cpi.ccb_h.func_code = XPT_PATH_INQ;
2961 xpt_action((union ccb *)&cpi);
2962 /* Report connection speed */
2963 speed = cpi.base_transfer_speed;
2965 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2966 struct ccb_trans_settings_spi *spi =
2967 &cts.xport_specific.spi;
2969 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2970 && spi->sync_offset != 0) {
2971 freq = scsi_calc_syncsrate(spi->sync_period);
2974 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2975 speed *= (0x01 << spi->bus_width);
2977 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2978 struct ccb_trans_settings_fc *fc =
2979 &cts.xport_specific.fc;
2981 if (fc->valid & CTS_FC_VALID_SPEED)
2982 speed = fc->bitrate;
2984 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2985 struct ccb_trans_settings_sas *sas =
2986 &cts.xport_specific.sas;
2988 if (sas->valid & CTS_SAS_VALID_SPEED)
2989 speed = sas->bitrate;
2993 printf("%s%d: %d.%03dMB/s transfers",
2994 periph->periph_name, periph->unit_number,
2997 printf("%s%d: %dKB/s transfers", periph->periph_name,
2998 periph->unit_number, speed);
2999 /* Report additional information about SPI connections */
3000 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3001 struct ccb_trans_settings_spi *spi;
3003 spi = &cts.xport_specific.spi;
3005 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3007 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3011 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3012 && spi->bus_width > 0) {
3018 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3019 } else if (freq != 0) {
3023 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3024 struct ccb_trans_settings_fc *fc;
3026 fc = &cts.xport_specific.fc;
3027 if (fc->valid & CTS_FC_VALID_WWNN)
3028 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3029 if (fc->valid & CTS_FC_VALID_WWPN)
3030 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3031 if (fc->valid & CTS_FC_VALID_PORT)
3032 printf(" PortID 0x%x", fc->port);