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 (periph == NULL) {
619 printf("proberegister: periph was NULL!!\n");
620 return(CAM_REQ_CMP_ERR);
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"));
650 * Ensure we've waited at least a bus settle
651 * delay before attempting to probe the device.
652 * For HBAs that don't do bus resets, this won't make a difference.
654 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
657 * Ensure nobody slip in until probe finish.
659 cam_freeze_devq_arg(periph->path,
660 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
661 probeschedule(periph);
666 probeschedule(struct cam_periph *periph)
668 struct ccb_pathinq cpi;
672 softc = (probe_softc *)periph->softc;
673 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
675 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
676 cpi.ccb_h.func_code = XPT_PATH_INQ;
677 xpt_action((union ccb *)&cpi);
680 * If a device has gone away and another device, or the same one,
681 * is back in the same place, it should have a unit attention
682 * condition pending. It will not report the unit attention in
683 * response to an inquiry, which may leave invalid transfer
684 * negotiations in effect. The TUR will reveal the unit attention
685 * condition. Only send the TUR for lun 0, since some devices
686 * will get confused by commands other than inquiry to non-existent
687 * luns. If you think a device has gone away start your scan from
688 * lun 0. This will insure that any bogus transfer settings are
691 * If we haven't seen the device before and the controller supports
692 * some kind of transfer negotiation, negotiate with the first
693 * sent command if no bus reset was performed at startup. This
694 * ensures that the device is not confused by transfer negotiation
695 * settings left over by loader or BIOS action.
697 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
698 && (ccb->ccb_h.target_lun == 0)) {
699 PROBE_SET_ACTION(softc, PROBE_TUR);
700 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
701 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
702 proberequestdefaultnegotiation(periph);
703 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
705 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
708 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
709 softc->flags |= PROBE_NO_ANNOUNCE;
711 softc->flags &= ~PROBE_NO_ANNOUNCE;
713 xpt_schedule(periph, CAM_PRIORITY_XPT);
717 device_has_vpd(struct cam_ed *device, uint8_t page_id)
720 struct scsi_vpd_supported_pages *vpds;
722 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
723 num_pages = device->supported_vpds_len - SVPD_SUPPORTED_PAGES_HDR_LEN;
724 for (i = 0;i < num_pages;i++)
725 if (vpds->page_list[i] == page_id)
732 probestart(struct cam_periph *periph, union ccb *start_ccb)
734 /* Probe the device that our peripheral driver points to */
735 struct ccb_scsiio *csio;
738 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
740 softc = (probe_softc *)periph->softc;
741 csio = &start_ccb->csio;
744 switch (softc->action) {
746 case PROBE_TUR_FOR_NEGOTIATION:
749 scsi_test_unit_ready(csio,
758 case PROBE_FULL_INQUIRY:
759 case PROBE_INQUIRY_BASIC_DV1:
760 case PROBE_INQUIRY_BASIC_DV2:
763 struct scsi_inquiry_data *inq_buf;
765 inq_buf = &periph->path->device->inq_data;
768 * If the device is currently configured, we calculate an
769 * MD5 checksum of the inquiry data, and if the serial number
770 * length is greater than 0, add the serial number data
771 * into the checksum as well. Once the inquiry and the
772 * serial number check finish, we attempt to figure out
773 * whether we still have the same device.
775 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
777 MD5Init(&softc->context);
778 MD5Update(&softc->context, (unsigned char *)inq_buf,
779 sizeof(struct scsi_inquiry_data));
780 softc->flags |= PROBE_INQUIRY_CKSUM;
781 if (periph->path->device->serial_num_len > 0) {
782 MD5Update(&softc->context,
783 periph->path->device->serial_num,
784 periph->path->device->serial_num_len);
785 softc->flags |= PROBE_SERIAL_CKSUM;
787 MD5Final(softc->digest, &softc->context);
790 if (softc->action == PROBE_INQUIRY)
791 inquiry_len = SHORT_INQUIRY_LENGTH;
793 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
796 * Some parallel SCSI devices fail to send an
797 * ignore wide residue message when dealing with
798 * odd length inquiry requests. Round up to be
801 inquiry_len = roundup2(inquiry_len, 2);
803 if (softc->action == PROBE_INQUIRY_BASIC_DV1
804 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
805 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
807 if (inq_buf == NULL) {
808 xpt_print(periph->path, "malloc failure- skipping Basic"
809 "Domain Validation\n");
810 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
811 scsi_test_unit_ready(csio,
828 /*timeout*/60 * 1000);
831 case PROBE_REPORT_LUNS:
835 rp = malloc(periph->path->target->rpl_size,
836 M_CAMXPT, M_NOWAIT | M_ZERO);
838 struct scsi_inquiry_data *inq_buf;
839 inq_buf = &periph->path->device->inq_data;
840 xpt_print(periph->path,
841 "Unable to alloc report luns storage\n");
842 if (INQ_DATA_TQ_ENABLED(inq_buf))
843 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
845 PROBE_SET_ACTION(softc,
846 PROBE_SUPPORTED_VPD_LIST);
849 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
850 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
851 SSD_FULL_SIZE, 60000); break;
854 case PROBE_MODE_SENSE:
859 mode_buf_len = sizeof(struct scsi_mode_header_6)
860 + sizeof(struct scsi_mode_blk_desc)
861 + sizeof(struct scsi_control_page);
862 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
863 if (mode_buf != NULL) {
864 scsi_mode_sense(csio,
869 SMS_PAGE_CTRL_CURRENT,
870 SMS_CONTROL_MODE_PAGE,
877 xpt_print(periph->path, "Unable to mode sense control page - "
879 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
882 case PROBE_SUPPORTED_VPD_LIST:
884 struct scsi_vpd_supported_page_list *vpd_list;
885 struct cam_ed *device;
888 device = periph->path->device;
890 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
891 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
894 if (vpd_list != NULL) {
899 (u_int8_t *)vpd_list,
902 SVPD_SUPPORTED_PAGE_LIST,
904 /*timeout*/60 * 1000);
908 * We'll have to do without, let our probedone
909 * routine finish up for us.
911 start_ccb->csio.data_ptr = NULL;
912 probedone(periph, start_ccb);
915 case PROBE_DEVICE_ID:
917 struct scsi_vpd_device_id *devid;
918 struct cam_ed *device;
921 device = periph->path->device;
922 if (device_has_vpd(device, SVPD_DEVICE_ID))
923 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
932 SVPD_DEVICE_ID_MAX_SIZE,
936 /*timeout*/60 * 1000);
940 * We'll have to do without, let our probedone
941 * routine finish up for us.
943 start_ccb->csio.data_ptr = NULL;
944 probedone(periph, start_ccb);
947 case PROBE_SERIAL_NUM:
949 struct scsi_vpd_unit_serial_number *serial_buf;
950 struct cam_ed* device;
953 device = periph->path->device;
954 if (device->serial_num != NULL) {
955 free(device->serial_num, M_CAMXPT);
956 device->serial_num = NULL;
957 device->serial_num_len = 0;
960 if (device_has_vpd(device, SVPD_UNIT_SERIAL_NUMBER))
961 serial_buf = (struct scsi_vpd_unit_serial_number *)
962 malloc(sizeof(*serial_buf), M_CAMXPT,
965 if (serial_buf != NULL) {
970 (u_int8_t *)serial_buf,
973 SVPD_UNIT_SERIAL_NUMBER,
975 /*timeout*/60 * 1000);
979 * We'll have to do without, let our probedone
980 * routine finish up for us.
982 start_ccb->csio.data_ptr = NULL;
983 probedone(periph, start_ccb);
987 panic("probestart: invalid action state 0x%x\n", softc->action);
989 xpt_action(start_ccb);
993 proberequestdefaultnegotiation(struct cam_periph *periph)
995 struct ccb_trans_settings cts;
997 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
998 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
999 cts.type = CTS_TYPE_USER_SETTINGS;
1000 xpt_action((union ccb *)&cts);
1001 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1004 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1005 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1006 xpt_action((union ccb *)&cts);
1010 * Backoff Negotiation Code- only pertinent for SPI devices.
1013 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1015 struct ccb_trans_settings cts;
1016 struct ccb_trans_settings_spi *spi;
1018 memset(&cts, 0, sizeof (cts));
1019 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1020 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1021 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1022 xpt_action((union ccb *)&cts);
1023 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1025 xpt_print(periph->path,
1026 "failed to get current device settings\n");
1030 if (cts.transport != XPORT_SPI) {
1032 xpt_print(periph->path, "not SPI transport\n");
1036 spi = &cts.xport_specific.spi;
1039 * We cannot renegotiate sync rate if we don't have one.
1041 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1043 xpt_print(periph->path, "no sync rate known\n");
1049 * We'll assert that we don't have to touch PPR options- the
1050 * SIM will see what we do with period and offset and adjust
1051 * the PPR options as appropriate.
1055 * A sync rate with unknown or zero offset is nonsensical.
1056 * A sync period of zero means Async.
1058 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1059 || spi->sync_offset == 0 || spi->sync_period == 0) {
1061 xpt_print(periph->path, "no sync rate available\n");
1066 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1067 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1068 ("hit async: giving up on DV\n"));
1074 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1075 * We don't try to remember 'last' settings to see if the SIM actually
1076 * gets into the speed we want to set. We check on the SIM telling
1077 * us that a requested speed is bad, but otherwise don't try and
1078 * check the speed due to the asynchronous and handshake nature
1081 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1084 if (spi->sync_period >= 0xf) {
1085 spi->sync_period = 0;
1086 spi->sync_offset = 0;
1087 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1088 ("setting to async for DV\n"));
1090 * Once we hit async, we don't want to try
1091 * any more settings.
1093 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1094 } else if (bootverbose) {
1095 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1096 ("DV: period 0x%x\n", spi->sync_period));
1097 printf("setting period to 0x%x\n", spi->sync_period);
1099 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1100 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1101 xpt_action((union ccb *)&cts);
1102 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1105 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1106 ("DV: failed to set period 0x%x\n", spi->sync_period));
1107 if (spi->sync_period == 0) {
1114 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1117 probedone(struct cam_periph *periph, union ccb *done_ccb)
1120 struct cam_path *path;
1123 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1125 softc = (probe_softc *)periph->softc;
1126 path = done_ccb->ccb_h.path;
1127 priority = done_ccb->ccb_h.pinfo.priority;
1129 switch (softc->action) {
1132 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1134 if (cam_periph_error(done_ccb, 0,
1135 SF_NO_PRINT, NULL) == ERESTART)
1137 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1138 /* Don't wedge the queue */
1139 xpt_release_devq(done_ccb->ccb_h.path,
1143 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1144 xpt_release_ccb(done_ccb);
1145 xpt_schedule(periph, priority);
1149 case PROBE_FULL_INQUIRY:
1151 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1152 struct scsi_inquiry_data *inq_buf;
1153 u_int8_t periph_qual;
1155 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1156 inq_buf = &path->device->inq_data;
1158 periph_qual = SID_QUAL(inq_buf);
1160 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1164 * We conservatively request only
1165 * SHORT_INQUIRY_LEN bytes of inquiry
1166 * information during our first try
1167 * at sending an INQUIRY. If the device
1168 * has more information to give,
1169 * perform a second request specifying
1170 * the amount of information the device
1171 * is willing to give.
1173 len = inq_buf->additional_length
1174 + offsetof(struct scsi_inquiry_data,
1175 additional_length) + 1;
1176 if (softc->action == PROBE_INQUIRY
1177 && len > SHORT_INQUIRY_LENGTH) {
1178 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1179 xpt_release_ccb(done_ccb);
1180 xpt_schedule(periph, priority);
1184 scsi_find_quirk(path->device);
1186 scsi_devise_transport(path);
1188 if (path->device->lun_id == 0 &&
1189 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1190 (SCSI_QUIRK(path->device)->quirks &
1191 CAM_QUIRK_NORPTLUNS) == 0) {
1192 PROBE_SET_ACTION(softc,
1195 * Start with room for *one* lun.
1197 periph->path->target->rpl_size = 16;
1198 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1199 PROBE_SET_ACTION(softc,
1202 PROBE_SET_ACTION(softc,
1203 PROBE_SUPPORTED_VPD_LIST);
1205 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1206 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1207 xpt_acquire_device(path->device);
1209 xpt_release_ccb(done_ccb);
1210 xpt_schedule(periph, priority);
1212 } else if (path->device->lun_id == 0 &&
1213 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1214 (SCSI_QUIRK(path->device)->quirks &
1215 CAM_QUIRK_NORPTLUNS) == 0) {
1216 if (path->device->flags &
1217 CAM_DEV_UNCONFIGURED) {
1218 path->device->flags &=
1219 ~CAM_DEV_UNCONFIGURED;
1220 xpt_acquire_device(path->device);
1222 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1223 periph->path->target->rpl_size = 16;
1224 xpt_release_ccb(done_ccb);
1225 xpt_schedule(periph, priority);
1228 } else if (cam_periph_error(done_ccb, 0,
1229 done_ccb->ccb_h.target_lun > 0
1230 ? SF_RETRY_UA|SF_QUIET_IR
1232 &softc->saved_ccb) == ERESTART) {
1234 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1235 /* Don't wedge the queue */
1236 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1240 * If we get to this point, we got an error status back
1241 * from the inquiry and the error status doesn't require
1242 * automatically retrying the command. Therefore, the
1243 * inquiry failed. If we had inquiry information before
1244 * for this device, but this latest inquiry command failed,
1245 * the device has probably gone away. If this device isn't
1246 * already marked unconfigured, notify the peripheral
1247 * drivers that this device is no more.
1249 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1250 /* Send the async notification. */
1251 xpt_async(AC_LOST_DEVICE, path, NULL);
1252 PROBE_SET_ACTION(softc, PROBE_INVALID);
1254 xpt_release_ccb(done_ccb);
1257 case PROBE_REPORT_LUNS:
1259 struct ccb_scsiio *csio;
1260 struct scsi_report_luns_data *lp;
1263 csio = &done_ccb->csio;
1265 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1266 nlun = scsi_4btoul(lp->length) / 8;
1267 maxlun = (csio->dxfer_len / 8) - 1;
1269 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1270 if (cam_periph_error(done_ccb, 0,
1271 done_ccb->ccb_h.target_lun > 0 ?
1272 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1273 &softc->saved_ccb) == ERESTART) {
1276 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1277 xpt_release_devq(done_ccb->ccb_h.path, 1,
1282 } else if (nlun > maxlun) {
1284 * Reallocate and retry to cover all luns
1286 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1287 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1290 path->target->rpl_size = (nlun << 3) + 8;
1291 xpt_release_ccb(done_ccb);
1292 xpt_schedule(periph, priority);
1294 } else if (nlun == 0) {
1296 * If there don't appear to be any luns, bail.
1300 } else if (probe_strange_rpl_data(lp, maxlun)) {
1302 * If we can't understand the lun format
1303 * of any entry, bail.
1311 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1312 ("Probe: %u lun(s) reported\n", nlun));
1314 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1316 * If the first lun is not lun 0, then either there
1317 * is no lun 0 in the list, or the list is unsorted.
1320 for (idx = 0; idx < nlun; idx++) {
1321 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1329 lp->luns[0].lundata, 8);
1330 memcpy(lp->luns[0].lundata,
1331 lp->luns[idx].lundata, 8);
1332 memcpy(lp->luns[idx].lundata,
1334 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1335 ("lun 0 in position %u\n", idx));
1338 * There is no lun 0 in our list. Destroy
1339 * the validity of the inquiry data so we
1340 * bail here and now.
1342 path->device->flags &=
1343 ~CAM_DEV_INQUIRY_DATA_VALID;
1347 * If we have an old lun list, We can either
1348 * retest luns that appear to have been dropped,
1349 * or just nuke them. We'll opt for the latter.
1350 * This function will also install the new list
1351 * in the target structure.
1353 probe_purge_old(path, lp);
1356 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1357 struct scsi_inquiry_data *inq_buf;
1358 inq_buf = &path->device->inq_data;
1359 if (INQ_DATA_TQ_ENABLED(inq_buf))
1360 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1362 PROBE_SET_ACTION(softc,
1363 PROBE_SUPPORTED_VPD_LIST);
1364 xpt_release_ccb(done_ccb);
1365 xpt_schedule(periph, priority);
1373 case PROBE_MODE_SENSE:
1375 struct ccb_scsiio *csio;
1376 struct scsi_mode_header_6 *mode_hdr;
1378 csio = &done_ccb->csio;
1379 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1380 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1381 struct scsi_control_page *page;
1384 offset = ((u_int8_t *)&mode_hdr[1])
1385 + mode_hdr->blk_desc_len;
1386 page = (struct scsi_control_page *)offset;
1387 path->device->queue_flags = page->queue_flags;
1388 } else if (cam_periph_error(done_ccb, 0,
1389 SF_RETRY_UA|SF_NO_PRINT,
1390 &softc->saved_ccb) == ERESTART) {
1392 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1393 /* Don't wedge the queue */
1394 xpt_release_devq(done_ccb->ccb_h.path,
1395 /*count*/1, /*run_queue*/TRUE);
1397 xpt_release_ccb(done_ccb);
1398 free(mode_hdr, M_CAMXPT);
1399 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1400 xpt_schedule(periph, priority);
1403 case PROBE_SUPPORTED_VPD_LIST:
1405 struct ccb_scsiio *csio;
1406 struct scsi_vpd_supported_page_list *page_list;
1408 csio = &done_ccb->csio;
1410 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1412 if (path->device->supported_vpds != NULL) {
1413 free(path->device->supported_vpds, M_CAMXPT);
1414 path->device->supported_vpds = NULL;
1415 path->device->supported_vpds_len = 0;
1418 if (page_list == NULL) {
1420 * Don't process the command as it was never sent
1422 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1424 path->device->supported_vpds_len = page_list->length +
1425 SVPD_SUPPORTED_PAGES_HDR_LEN;
1426 path->device->supported_vpds = (uint8_t *)page_list;
1427 xpt_release_ccb(done_ccb);
1428 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1429 xpt_schedule(periph, priority);
1431 } else if (cam_periph_error(done_ccb, 0,
1432 SF_RETRY_UA|SF_NO_PRINT,
1433 &softc->saved_ccb) == ERESTART) {
1435 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1436 /* Don't wedge the queue */
1437 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1442 free(page_list, M_CAMXPT);
1443 /* No VPDs available, skip to device check. */
1444 csio->data_ptr = NULL;
1445 goto probe_device_check;
1447 case PROBE_DEVICE_ID:
1449 struct scsi_vpd_device_id *devid;
1450 struct ccb_scsiio *csio;
1451 uint32_t length = 0;
1453 csio = &done_ccb->csio;
1454 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1456 /* Clean up from previous instance of this device */
1457 if (path->device->device_id != NULL) {
1458 path->device->device_id_len = 0;
1459 free(path->device->device_id, M_CAMXPT);
1460 path->device->device_id = NULL;
1463 if (devid == NULL) {
1464 /* Don't process the command as it was never sent */
1465 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1466 length = scsi_2btoul(devid->length);
1469 * NB: device_id_len is actual response
1470 * size, not buffer size.
1472 path->device->device_id_len = length +
1473 SVPD_DEVICE_ID_HDR_LEN;
1474 path->device->device_id = (uint8_t *)devid;
1476 } else if (cam_periph_error(done_ccb, 0,
1478 &softc->saved_ccb) == ERESTART) {
1480 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1481 /* Don't wedge the queue */
1482 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1486 /* Free the device id space if we don't use it */
1487 if (devid && length == 0)
1488 free(devid, M_CAMXPT);
1489 xpt_release_ccb(done_ccb);
1490 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1491 xpt_schedule(periph, priority);
1496 case PROBE_SERIAL_NUM:
1498 struct ccb_scsiio *csio;
1499 struct scsi_vpd_unit_serial_number *serial_buf;
1506 csio = &done_ccb->csio;
1507 priority = done_ccb->ccb_h.pinfo.priority;
1509 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1511 if (serial_buf == NULL) {
1513 * Don't process the command as it was never sent
1515 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1516 && (serial_buf->length > 0)) {
1519 path->device->serial_num =
1520 (u_int8_t *)malloc((serial_buf->length + 1),
1521 M_CAMXPT, M_NOWAIT);
1522 if (path->device->serial_num != NULL) {
1523 memcpy(path->device->serial_num,
1524 serial_buf->serial_num,
1525 serial_buf->length);
1526 path->device->serial_num_len =
1528 path->device->serial_num[serial_buf->length]
1531 } else if (cam_periph_error(done_ccb, 0,
1532 SF_RETRY_UA|SF_NO_PRINT,
1533 &softc->saved_ccb) == ERESTART) {
1535 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1536 /* Don't wedge the queue */
1537 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1542 * Let's see if we have seen this device before.
1544 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1546 u_int8_t digest[16];
1551 (unsigned char *)&path->device->inq_data,
1552 sizeof(struct scsi_inquiry_data));
1555 MD5Update(&context, serial_buf->serial_num,
1556 serial_buf->length);
1558 MD5Final(digest, &context);
1559 if (bcmp(softc->digest, digest, 16) == 0)
1563 * XXX Do we need to do a TUR in order to ensure
1564 * that the device really hasn't changed???
1567 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1568 xpt_async(AC_LOST_DEVICE, path, NULL);
1570 if (serial_buf != NULL)
1571 free(serial_buf, M_CAMXPT);
1575 * Now that we have all the necessary
1576 * information to safely perform transfer
1577 * negotiations... Controllers don't perform
1578 * any negotiation or tagged queuing until
1579 * after the first XPT_SET_TRAN_SETTINGS ccb is
1580 * received. So, on a new device, just retrieve
1581 * the user settings, and set them as the current
1582 * settings to set the device up.
1584 proberequestdefaultnegotiation(periph);
1585 xpt_release_ccb(done_ccb);
1588 * Perform a TUR to allow the controller to
1589 * perform any necessary transfer negotiation.
1591 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1592 xpt_schedule(periph, priority);
1595 xpt_release_ccb(done_ccb);
1598 case PROBE_TUR_FOR_NEGOTIATION:
1600 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1601 cam_periph_error(done_ccb, 0,
1602 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1604 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1605 /* Don't wedge the queue */
1606 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1610 * Do Domain Validation for lun 0 on devices that claim
1611 * to support Synchronous Transfer modes.
1613 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1614 && done_ccb->ccb_h.target_lun == 0
1615 && (path->device->inq_data.flags & SID_Sync) != 0
1616 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1617 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1618 ("Begin Domain Validation\n"));
1619 path->device->flags |= CAM_DEV_IN_DV;
1620 xpt_release_ccb(done_ccb);
1621 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1622 xpt_schedule(periph, priority);
1625 if (softc->action == PROBE_DV_EXIT) {
1626 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1627 ("Leave Domain Validation\n"));
1629 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1630 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1631 xpt_acquire_device(path->device);
1633 path->device->flags &=
1634 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1635 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1636 /* Inform the XPT that a new device has been found */
1637 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1638 xpt_action(done_ccb);
1639 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1642 PROBE_SET_ACTION(softc, PROBE_DONE);
1643 xpt_release_ccb(done_ccb);
1645 case PROBE_INQUIRY_BASIC_DV1:
1646 case PROBE_INQUIRY_BASIC_DV2:
1648 struct scsi_inquiry_data *nbuf;
1649 struct ccb_scsiio *csio;
1651 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1652 cam_periph_error(done_ccb, 0,
1653 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1655 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1656 /* Don't wedge the queue */
1657 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1660 csio = &done_ccb->csio;
1661 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1662 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1664 "inquiry data fails comparison at DV%d step\n",
1665 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1666 if (proberequestbackoff(periph, path->device)) {
1667 path->device->flags &= ~CAM_DEV_IN_DV;
1668 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1671 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1673 free(nbuf, M_CAMXPT);
1674 xpt_release_ccb(done_ccb);
1675 xpt_schedule(periph, priority);
1678 free(nbuf, M_CAMXPT);
1679 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1680 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1681 xpt_release_ccb(done_ccb);
1682 xpt_schedule(periph, priority);
1685 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1686 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1687 ("Leave Domain Validation Successfully\n"));
1689 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1690 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1691 xpt_acquire_device(path->device);
1693 path->device->flags &=
1694 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1695 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1696 /* Inform the XPT that a new device has been found */
1697 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1698 xpt_action(done_ccb);
1699 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1702 PROBE_SET_ACTION(softc, PROBE_DONE);
1703 xpt_release_ccb(done_ccb);
1707 panic("probedone: invalid action state 0x%x\n", softc->action);
1709 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1710 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1711 done_ccb->ccb_h.status = CAM_REQ_CMP;
1713 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1714 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1715 cam_periph_invalidate(periph);
1716 cam_release_devq(periph->path,
1717 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1718 cam_periph_release_locked(periph);
1720 probeschedule(periph);
1725 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1728 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1730 for (idx = 0; idx < nlun; idx++) {
1731 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1739 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1741 struct cam_path *tp;
1742 struct scsi_report_luns_data *old;
1743 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1746 if (path->target == NULL) {
1749 if (path->target->luns == NULL) {
1750 path->target->luns = new;
1753 old = path->target->luns;
1754 nlun_old = scsi_4btoul(old->length) / 8;
1755 nlun_new = scsi_4btoul(new->length) / 8;
1758 * We are not going to assume sorted lists. Deal.
1760 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1761 ol = old->luns[idx1].lundata;
1762 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1763 nl = new->luns[idx2].lundata;
1764 if (memcmp(nl, ol, 8) == 0) {
1768 if (idx2 < nlun_new) {
1772 * An 'old' item not in the 'new' list.
1773 * Nuke it. Except that if it is lun 0,
1774 * that would be what the probe state
1775 * machine is currently working on,
1776 * so we won't do that.
1778 * We also cannot nuke it if it is
1779 * not in a lun format we understand.
1781 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1784 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1785 if (this_lun == 0) {
1788 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1789 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1790 xpt_async(AC_LOST_DEVICE, tp, NULL);
1794 free(old, M_CAMXPT);
1795 path->target->luns = new;
1799 probecleanup(struct cam_periph *periph)
1801 free(periph->softc, M_CAMXPT);
1805 scsi_find_quirk(struct cam_ed *device)
1807 struct scsi_quirk_entry *quirk;
1810 match = cam_quirkmatch((caddr_t)&device->inq_data,
1811 (caddr_t)scsi_quirk_table,
1812 sizeof(scsi_quirk_table) /
1813 sizeof(*scsi_quirk_table),
1814 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1817 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1819 quirk = (struct scsi_quirk_entry *)match;
1820 device->quirk = quirk;
1821 device->mintags = quirk->mintags;
1822 device->maxtags = quirk->maxtags;
1826 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1831 error = sysctl_handle_int(oidp, &val, 0, req);
1832 if (error != 0 || req->newptr == NULL)
1834 if (val == 0 || val == 1) {
1843 union ccb *request_ccb;
1844 struct ccb_pathinq *cpi;
1847 } scsi_scan_bus_info;
1850 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1851 * As the scan progresses, scsi_scan_bus is used as the
1852 * callback on completion function.
1855 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1857 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1858 ("scsi_scan_bus\n"));
1859 switch (request_ccb->ccb_h.func_code) {
1863 scsi_scan_bus_info *scan_info;
1864 union ccb *work_ccb, *reset_ccb;
1865 struct cam_path *path;
1867 u_int low_target, max_target;
1870 /* Find out the characteristics of the bus */
1871 work_ccb = xpt_alloc_ccb_nowait();
1872 if (work_ccb == NULL) {
1873 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1874 xpt_done(request_ccb);
1877 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1878 request_ccb->ccb_h.pinfo.priority);
1879 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1880 xpt_action(work_ccb);
1881 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1882 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1883 xpt_free_ccb(work_ccb);
1884 xpt_done(request_ccb);
1888 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1890 * Can't scan the bus on an adapter that
1891 * cannot perform the initiator role.
1893 request_ccb->ccb_h.status = CAM_REQ_CMP;
1894 xpt_free_ccb(work_ccb);
1895 xpt_done(request_ccb);
1899 /* We may need to reset bus first, if we haven't done it yet. */
1900 if ((work_ccb->cpi.hba_inquiry &
1901 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1902 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1903 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1904 reset_ccb = xpt_alloc_ccb_nowait();
1905 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1907 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1908 xpt_action(reset_ccb);
1909 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1910 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1911 xpt_free_ccb(reset_ccb);
1912 xpt_free_ccb(work_ccb);
1913 xpt_done(request_ccb);
1916 xpt_free_ccb(reset_ccb);
1919 /* Save some state for use while we probe for devices */
1920 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1921 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1922 if (scan_info == NULL) {
1923 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1924 xpt_done(request_ccb);
1927 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1928 ("SCAN start for %p\n", scan_info));
1929 scan_info->request_ccb = request_ccb;
1930 scan_info->cpi = &work_ccb->cpi;
1932 /* Cache on our stack so we can work asynchronously */
1933 max_target = scan_info->cpi->max_target;
1935 initiator_id = scan_info->cpi->initiator_id;
1939 * We can scan all targets in parallel, or do it sequentially.
1942 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1943 max_target = low_target = request_ccb->ccb_h.target_id;
1944 scan_info->counter = 0;
1945 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1947 scan_info->counter = 0;
1949 scan_info->counter = scan_info->cpi->max_target + 1;
1950 if (scan_info->cpi->initiator_id < scan_info->counter) {
1951 scan_info->counter--;
1955 for (i = low_target; i <= max_target; i++) {
1957 if (i == initiator_id)
1960 status = xpt_create_path(&path, xpt_periph,
1961 request_ccb->ccb_h.path_id,
1963 if (status != CAM_REQ_CMP) {
1964 printf("scsi_scan_bus: xpt_create_path failed"
1965 " with status %#x, bus scan halted\n",
1967 free(scan_info, M_CAMXPT);
1968 request_ccb->ccb_h.status = status;
1969 xpt_free_ccb(work_ccb);
1970 xpt_done(request_ccb);
1973 work_ccb = xpt_alloc_ccb_nowait();
1974 if (work_ccb == NULL) {
1975 xpt_free_ccb((union ccb *)scan_info->cpi);
1976 free(scan_info, M_CAMXPT);
1977 xpt_free_path(path);
1978 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1979 xpt_done(request_ccb);
1982 xpt_setup_ccb(&work_ccb->ccb_h, path,
1983 request_ccb->ccb_h.pinfo.priority);
1984 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1985 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1986 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1987 work_ccb->crcn.flags = request_ccb->crcn.flags;
1988 xpt_action(work_ccb);
1995 struct cam_path *path, *oldpath;
1996 scsi_scan_bus_info *scan_info;
1997 struct cam_et *target;
1998 struct cam_ed *device;
2001 target_id_t target_id;
2004 oldpath = request_ccb->ccb_h.path;
2006 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
2007 /* Reuse the same CCB to query if a device was really found */
2008 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
2009 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
2010 request_ccb->ccb_h.pinfo.priority);
2011 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
2014 path_id = request_ccb->ccb_h.path_id;
2015 target_id = request_ccb->ccb_h.target_id;
2016 lun_id = request_ccb->ccb_h.target_lun;
2017 xpt_action(request_ccb);
2019 target = request_ccb->ccb_h.path->target;
2024 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2027 * Make sure we skip over lun 0 if it's the first member
2028 * of the list as we've actually just finished probing
2031 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
2032 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2033 scan_info->lunindex[target_id]++;
2036 if (scan_info->lunindex[target_id] < nluns) {
2037 CAM_GET_SIMPLE_LUN(target->luns,
2038 scan_info->lunindex[target_id], lun_id);
2040 CAM_DEBUG(request_ccb->ccb_h.path,
2042 ("next lun to try at index %u is %u\n",
2043 scan_info->lunindex[target_id], lun_id));
2044 scan_info->lunindex[target_id]++;
2047 * We're done with scanning all luns.
2049 * Nuke the bogus device for lun 0 if lun 0
2050 * wasn't on the list.
2053 TAILQ_FOREACH(device,
2054 &target->ed_entries, links) {
2055 if (device->lun_id == 0) {
2060 xpt_release_device(device);
2064 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2068 * If we already probed lun 0 successfully, or
2069 * we have additional configured luns on this
2070 * target that might have "gone away", go onto
2074 * We may touch devices that we don't
2075 * hold references too, so ensure they
2076 * don't disappear out from under us.
2077 * The target above is referenced by the
2078 * path in the request ccb.
2081 device = TAILQ_FIRST(&target->ed_entries);
2082 if (device != NULL) {
2083 phl = CAN_SRCH_HI_SPARSE(device);
2084 if (device->lun_id == 0)
2085 device = TAILQ_NEXT(device, links);
2087 if ((lun_id != 0) || (device != NULL)) {
2088 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2093 if (lun_id == request_ccb->ccb_h.target_lun
2094 || lun_id > scan_info->cpi->max_lun)
2098 device = request_ccb->ccb_h.path->device;
2100 if ((SCSI_QUIRK(device)->quirks &
2101 CAM_QUIRK_NOLUNS) == 0) {
2102 /* Try the next lun */
2103 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2104 || CAN_SRCH_HI_DENSE(device)) {
2109 if (lun_id == request_ccb->ccb_h.target_lun
2110 || lun_id > scan_info->cpi->max_lun)
2115 * Check to see if we scan any further luns.
2121 * Free the current request path- we're done with it.
2123 xpt_free_path(oldpath);
2126 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2128 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2129 scan_info->counter++;
2130 if (scan_info->counter ==
2131 scan_info->cpi->initiator_id) {
2132 scan_info->counter++;
2134 if (scan_info->counter >=
2135 scan_info->cpi->max_target+1) {
2139 scan_info->counter--;
2140 if (scan_info->counter == 0) {
2145 xpt_free_ccb(request_ccb);
2146 xpt_free_ccb((union ccb *)scan_info->cpi);
2147 request_ccb = scan_info->request_ccb;
2148 CAM_DEBUG(request_ccb->ccb_h.path,
2150 ("SCAN done for %p\n", scan_info));
2151 free(scan_info, M_CAMXPT);
2152 request_ccb->ccb_h.status = CAM_REQ_CMP;
2153 xpt_done(request_ccb);
2157 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2158 xpt_free_ccb(request_ccb);
2161 status = xpt_create_path(&path, xpt_periph,
2162 scan_info->request_ccb->ccb_h.path_id,
2163 scan_info->counter, 0);
2164 if (status != CAM_REQ_CMP) {
2165 printf("scsi_scan_bus: xpt_create_path failed"
2166 " with status %#x, bus scan halted\n",
2168 xpt_free_ccb(request_ccb);
2169 xpt_free_ccb((union ccb *)scan_info->cpi);
2170 request_ccb = scan_info->request_ccb;
2171 free(scan_info, M_CAMXPT);
2172 request_ccb->ccb_h.status = status;
2173 xpt_done(request_ccb);
2176 xpt_setup_ccb(&request_ccb->ccb_h, path,
2177 request_ccb->ccb_h.pinfo.priority);
2178 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2179 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2180 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2181 request_ccb->crcn.flags =
2182 scan_info->request_ccb->crcn.flags;
2184 status = xpt_create_path(&path, xpt_periph,
2185 path_id, target_id, lun_id);
2187 * Free the old request path- we're done with it. We
2188 * do this *after* creating the new path so that
2189 * we don't remove a target that has our lun list
2190 * in the case that lun 0 is not present.
2192 xpt_free_path(oldpath);
2193 if (status != CAM_REQ_CMP) {
2194 printf("scsi_scan_bus: xpt_create_path failed "
2195 "with status %#x, halting LUN scan\n",
2199 xpt_setup_ccb(&request_ccb->ccb_h, path,
2200 request_ccb->ccb_h.pinfo.priority);
2201 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2202 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2203 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2204 request_ccb->crcn.flags =
2205 scan_info->request_ccb->crcn.flags;
2207 xpt_action(request_ccb);
2216 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2217 cam_flags flags, union ccb *request_ccb)
2219 struct ccb_pathinq cpi;
2221 struct cam_path *new_path;
2222 struct cam_periph *old_periph;
2224 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2226 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2227 cpi.ccb_h.func_code = XPT_PATH_INQ;
2228 xpt_action((union ccb *)&cpi);
2230 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2231 if (request_ccb != NULL) {
2232 request_ccb->ccb_h.status = cpi.ccb_h.status;
2233 xpt_done(request_ccb);
2238 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2240 * Can't scan the bus on an adapter that
2241 * cannot perform the initiator role.
2243 if (request_ccb != NULL) {
2244 request_ccb->ccb_h.status = CAM_REQ_CMP;
2245 xpt_done(request_ccb);
2250 if (request_ccb == NULL) {
2251 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
2252 if (request_ccb == NULL) {
2253 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2254 "can't continue\n");
2257 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
2258 if (new_path == NULL) {
2259 xpt_print(path, "scsi_scan_lun: can't allocate path, "
2260 "can't continue\n");
2261 free(request_ccb, M_CAMXPT);
2264 status = xpt_compile_path(new_path, xpt_periph,
2266 path->target->target_id,
2267 path->device->lun_id);
2269 if (status != CAM_REQ_CMP) {
2270 xpt_print(path, "scsi_scan_lun: can't compile path, "
2271 "can't continue\n");
2272 free(request_ccb, M_CAMXPT);
2273 free(new_path, M_CAMXPT);
2276 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2277 request_ccb->ccb_h.cbfcnp = xptscandone;
2278 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2279 request_ccb->crcn.flags = flags;
2282 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2283 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2286 softc = (probe_softc *)old_periph->softc;
2287 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2288 &request_ccb->ccb_h, periph_links.tqe);
2290 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2291 xpt_done(request_ccb);
2294 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2295 probestart, "probe",
2297 request_ccb->ccb_h.path, NULL, 0,
2300 if (status != CAM_REQ_CMP) {
2301 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2302 "returned an error, can't continue probe\n");
2303 request_ccb->ccb_h.status = status;
2304 xpt_done(request_ccb);
2310 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2312 xpt_release_path(done_ccb->ccb_h.path);
2313 free(done_ccb->ccb_h.path, M_CAMXPT);
2314 free(done_ccb, M_CAMXPT);
2317 static struct cam_ed *
2318 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2320 struct cam_path path;
2321 struct scsi_quirk_entry *quirk;
2322 struct cam_ed *device;
2323 struct cam_ed *cur_device;
2325 device = xpt_alloc_device(bus, target, lun_id);
2330 * Take the default quirk entry until we have inquiry
2331 * data and can determine a better quirk to use.
2333 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2334 device->quirk = (void *)quirk;
2335 device->mintags = quirk->mintags;
2336 device->maxtags = quirk->maxtags;
2337 bzero(&device->inq_data, sizeof(device->inq_data));
2338 device->inq_flags = 0;
2339 device->queue_flags = 0;
2340 device->serial_num = NULL;
2341 device->serial_num_len = 0;
2342 device->device_id = NULL;
2343 device->device_id_len = 0;
2344 device->supported_vpds = NULL;
2345 device->supported_vpds_len = 0;
2348 * XXX should be limited by number of CCBs this bus can
2351 bus->sim->max_ccbs += device->ccbq.devq_openings;
2352 /* Insertion sort into our target's device list */
2353 cur_device = TAILQ_FIRST(&target->ed_entries);
2354 while (cur_device != NULL && cur_device->lun_id < lun_id)
2355 cur_device = TAILQ_NEXT(cur_device, links);
2356 if (cur_device != NULL) {
2357 TAILQ_INSERT_BEFORE(cur_device, device, links);
2359 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
2361 target->generation++;
2362 if (lun_id != CAM_LUN_WILDCARD) {
2363 xpt_compile_path(&path,
2368 scsi_devise_transport(&path);
2369 xpt_release_path(&path);
2376 scsi_devise_transport(struct cam_path *path)
2378 struct ccb_pathinq cpi;
2379 struct ccb_trans_settings cts;
2380 struct scsi_inquiry_data *inq_buf;
2382 /* Get transport information from the SIM */
2383 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2384 cpi.ccb_h.func_code = XPT_PATH_INQ;
2385 xpt_action((union ccb *)&cpi);
2388 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2389 inq_buf = &path->device->inq_data;
2390 path->device->protocol = PROTO_SCSI;
2391 path->device->protocol_version =
2392 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2393 path->device->transport = cpi.transport;
2394 path->device->transport_version = cpi.transport_version;
2397 * Any device not using SPI3 features should
2398 * be considered SPI2 or lower.
2400 if (inq_buf != NULL) {
2401 if (path->device->transport == XPORT_SPI
2402 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2403 && path->device->transport_version > 2)
2404 path->device->transport_version = 2;
2406 struct cam_ed* otherdev;
2408 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2410 otherdev = TAILQ_NEXT(otherdev, links)) {
2411 if (otherdev != path->device)
2415 if (otherdev != NULL) {
2417 * Initially assume the same versioning as
2418 * prior luns for this target.
2420 path->device->protocol_version =
2421 otherdev->protocol_version;
2422 path->device->transport_version =
2423 otherdev->transport_version;
2425 /* Until we know better, opt for safty */
2426 path->device->protocol_version = 2;
2427 if (path->device->transport == XPORT_SPI)
2428 path->device->transport_version = 2;
2430 path->device->transport_version = 0;
2436 * For a device compliant with SPC-2 we should be able
2437 * to determine the transport version supported by
2438 * scrutinizing the version descriptors in the
2442 /* Tell the controller what we think */
2443 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2444 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2445 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2446 cts.transport = path->device->transport;
2447 cts.transport_version = path->device->transport_version;
2448 cts.protocol = path->device->protocol;
2449 cts.protocol_version = path->device->protocol_version;
2450 cts.proto_specific.valid = 0;
2451 cts.xport_specific.valid = 0;
2452 xpt_action((union ccb *)&cts);
2456 scsi_dev_advinfo(union ccb *start_ccb)
2458 struct cam_ed *device;
2459 struct ccb_dev_advinfo *cdai;
2462 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2463 device = start_ccb->ccb_h.path->device;
2464 cdai = &start_ccb->cdai;
2465 switch(cdai->buftype) {
2466 case CDAI_TYPE_SCSI_DEVID:
2467 if (cdai->flags & CDAI_FLAG_STORE)
2469 cdai->provsiz = device->device_id_len;
2470 if (device->device_id_len == 0)
2472 amt = device->device_id_len;
2473 if (cdai->provsiz > cdai->bufsiz)
2475 memcpy(cdai->buf, device->device_id, amt);
2477 case CDAI_TYPE_SERIAL_NUM:
2478 if (cdai->flags & CDAI_FLAG_STORE)
2480 cdai->provsiz = device->serial_num_len;
2481 if (device->serial_num_len == 0)
2483 amt = device->serial_num_len;
2484 if (cdai->provsiz > cdai->bufsiz)
2486 memcpy(cdai->buf, device->serial_num, amt);
2488 case CDAI_TYPE_PHYS_PATH:
2489 if (cdai->flags & CDAI_FLAG_STORE) {
2490 if (device->physpath != NULL)
2491 free(device->physpath, M_CAMXPT);
2492 device->physpath_len = cdai->bufsiz;
2493 /* Clear existing buffer if zero length */
2494 if (cdai->bufsiz == 0)
2496 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2497 if (device->physpath == NULL) {
2498 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2501 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2503 cdai->provsiz = device->physpath_len;
2504 if (device->physpath_len == 0)
2506 amt = device->physpath_len;
2507 if (cdai->provsiz > cdai->bufsiz)
2509 memcpy(cdai->buf, device->physpath, amt);
2515 start_ccb->ccb_h.status = CAM_REQ_CMP;
2517 if (cdai->flags & CDAI_FLAG_STORE) {
2520 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
2522 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
2523 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2524 (void *)(uintptr_t)cdai->buftype);
2526 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
2531 scsi_action(union ccb *start_ccb)
2534 switch (start_ccb->ccb_h.func_code) {
2535 case XPT_SET_TRAN_SETTINGS:
2537 scsi_set_transfer_settings(&start_ccb->cts,
2538 start_ccb->ccb_h.path->device,
2539 /*async_update*/FALSE);
2544 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2547 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2548 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2551 case XPT_GET_TRAN_SETTINGS:
2553 struct cam_sim *sim;
2555 sim = start_ccb->ccb_h.path->bus->sim;
2556 (*(sim->sim_action))(sim, start_ccb);
2559 case XPT_DEV_ADVINFO:
2561 scsi_dev_advinfo(start_ccb);
2565 xpt_action_default(start_ccb);
2571 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2574 struct ccb_pathinq cpi;
2575 struct ccb_trans_settings cur_cts;
2576 struct ccb_trans_settings_scsi *scsi;
2577 struct ccb_trans_settings_scsi *cur_scsi;
2578 struct cam_sim *sim;
2579 struct scsi_inquiry_data *inq_data;
2581 if (device == NULL) {
2582 cts->ccb_h.status = CAM_PATH_INVALID;
2583 xpt_done((union ccb *)cts);
2587 if (cts->protocol == PROTO_UNKNOWN
2588 || cts->protocol == PROTO_UNSPECIFIED) {
2589 cts->protocol = device->protocol;
2590 cts->protocol_version = device->protocol_version;
2593 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2594 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2595 cts->protocol_version = device->protocol_version;
2597 if (cts->protocol != device->protocol) {
2598 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2599 cts->protocol, device->protocol);
2600 cts->protocol = device->protocol;
2603 if (cts->protocol_version > device->protocol_version) {
2605 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2606 "Version from %d to %d?\n", cts->protocol_version,
2607 device->protocol_version);
2609 cts->protocol_version = device->protocol_version;
2612 if (cts->transport == XPORT_UNKNOWN
2613 || cts->transport == XPORT_UNSPECIFIED) {
2614 cts->transport = device->transport;
2615 cts->transport_version = device->transport_version;
2618 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2619 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2620 cts->transport_version = device->transport_version;
2622 if (cts->transport != device->transport) {
2623 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2624 cts->transport, device->transport);
2625 cts->transport = device->transport;
2628 if (cts->transport_version > device->transport_version) {
2630 xpt_print(cts->ccb_h.path, "Down reving Transport "
2631 "Version from %d to %d?\n", cts->transport_version,
2632 device->transport_version);
2634 cts->transport_version = device->transport_version;
2637 sim = cts->ccb_h.path->bus->sim;
2640 * Nothing more of interest to do unless
2641 * this is a device connected via the
2644 if (cts->protocol != PROTO_SCSI) {
2645 if (async_update == FALSE)
2646 (*(sim->sim_action))(sim, (union ccb *)cts);
2650 inq_data = &device->inq_data;
2651 scsi = &cts->proto_specific.scsi;
2652 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2653 cpi.ccb_h.func_code = XPT_PATH_INQ;
2654 xpt_action((union ccb *)&cpi);
2656 /* SCSI specific sanity checking */
2657 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2658 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2659 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2660 || (device->mintags == 0)) {
2662 * Can't tag on hardware that doesn't support tags,
2663 * doesn't have it enabled, or has broken tag support.
2665 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2668 if (async_update == FALSE) {
2670 * Perform sanity checking against what the
2671 * controller and device can do.
2673 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2674 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2675 cur_cts.type = cts->type;
2676 xpt_action((union ccb *)&cur_cts);
2677 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2680 cur_scsi = &cur_cts.proto_specific.scsi;
2681 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2682 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2683 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2685 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2686 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2689 /* SPI specific sanity checking */
2690 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2692 struct ccb_trans_settings_spi *spi;
2693 struct ccb_trans_settings_spi *cur_spi;
2695 spi = &cts->xport_specific.spi;
2697 cur_spi = &cur_cts.xport_specific.spi;
2699 /* Fill in any gaps in what the user gave us */
2700 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2701 spi->sync_period = cur_spi->sync_period;
2702 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2703 spi->sync_period = 0;
2704 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2705 spi->sync_offset = cur_spi->sync_offset;
2706 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2707 spi->sync_offset = 0;
2708 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2709 spi->ppr_options = cur_spi->ppr_options;
2710 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2711 spi->ppr_options = 0;
2712 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2713 spi->bus_width = cur_spi->bus_width;
2714 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2716 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2717 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2718 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2720 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2721 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2722 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2723 && (inq_data->flags & SID_Sync) == 0
2724 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2725 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2727 spi->sync_period = 0;
2728 spi->sync_offset = 0;
2731 switch (spi->bus_width) {
2732 case MSG_EXT_WDTR_BUS_32_BIT:
2733 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2734 || (inq_data->flags & SID_WBus32) != 0
2735 || cts->type == CTS_TYPE_USER_SETTINGS)
2736 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2738 /* Fall Through to 16-bit */
2739 case MSG_EXT_WDTR_BUS_16_BIT:
2740 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2741 || (inq_data->flags & SID_WBus16) != 0
2742 || cts->type == CTS_TYPE_USER_SETTINGS)
2743 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2744 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2747 /* Fall Through to 8-bit */
2748 default: /* New bus width?? */
2749 case MSG_EXT_WDTR_BUS_8_BIT:
2750 /* All targets can do this */
2751 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2755 spi3caps = cpi.xport_specific.spi.ppr_options;
2756 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2757 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2758 spi3caps &= inq_data->spi3data;
2760 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2761 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2763 if ((spi3caps & SID_SPI_IUS) == 0)
2764 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2766 if ((spi3caps & SID_SPI_QAS) == 0)
2767 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2769 /* No SPI Transfer settings are allowed unless we are wide */
2770 if (spi->bus_width == 0)
2771 spi->ppr_options = 0;
2773 if ((spi->valid & CTS_SPI_VALID_DISC)
2774 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2776 * Can't tag queue without disconnection.
2778 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2779 scsi->valid |= CTS_SCSI_VALID_TQ;
2783 * If we are currently performing tagged transactions to
2784 * this device and want to change its negotiation parameters,
2785 * go non-tagged for a bit to give the controller a chance to
2786 * negotiate unhampered by tag messages.
2788 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2789 && (device->inq_flags & SID_CmdQue) != 0
2790 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2791 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2792 CTS_SPI_VALID_SYNC_OFFSET|
2793 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2794 scsi_toggle_tags(cts->ccb_h.path);
2797 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2798 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2802 * If we are transitioning from tags to no-tags or
2803 * vice-versa, we need to carefully freeze and restart
2804 * the queue so that we don't overlap tagged and non-tagged
2805 * commands. We also temporarily stop tags if there is
2806 * a change in transfer negotiation settings to allow
2807 * "tag-less" negotiation.
2809 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2810 || (device->inq_flags & SID_CmdQue) != 0)
2811 device_tagenb = TRUE;
2813 device_tagenb = FALSE;
2815 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2816 && device_tagenb == FALSE)
2817 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2818 && device_tagenb == TRUE)) {
2820 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2822 * Delay change to use tags until after a
2823 * few commands have gone to this device so
2824 * the controller has time to perform transfer
2825 * negotiations without tagged messages getting
2828 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2829 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2831 xpt_stop_tags(cts->ccb_h.path);
2835 if (async_update == FALSE)
2836 (*(sim->sim_action))(sim, (union ccb *)cts);
2840 scsi_toggle_tags(struct cam_path *path)
2845 * Give controllers a chance to renegotiate
2846 * before starting tag operations. We
2847 * "toggle" tagged queuing off then on
2848 * which causes the tag enable command delay
2849 * counter to come into effect.
2852 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2853 || ((dev->inq_flags & SID_CmdQue) != 0
2854 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2855 struct ccb_trans_settings cts;
2857 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2858 cts.protocol = PROTO_SCSI;
2859 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2860 cts.transport = XPORT_UNSPECIFIED;
2861 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2862 cts.proto_specific.scsi.flags = 0;
2863 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2864 scsi_set_transfer_settings(&cts, path->device,
2865 /*async_update*/TRUE);
2866 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2867 scsi_set_transfer_settings(&cts, path->device,
2868 /*async_update*/TRUE);
2873 * Handle any per-device event notifications that require action by the XPT.
2876 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2877 struct cam_ed *device, void *async_arg)
2880 struct cam_path newpath;
2883 * We only need to handle events for real devices.
2885 if (target->target_id == CAM_TARGET_WILDCARD
2886 || device->lun_id == CAM_LUN_WILDCARD)
2890 * We need our own path with wildcards expanded to
2891 * handle certain types of events.
2893 if ((async_code == AC_SENT_BDR)
2894 || (async_code == AC_BUS_RESET)
2895 || (async_code == AC_INQ_CHANGED))
2896 status = xpt_compile_path(&newpath, NULL,
2901 status = CAM_REQ_CMP_ERR;
2903 if (status == CAM_REQ_CMP) {
2906 * Allow transfer negotiation to occur in a
2907 * tag free environment and after settle delay.
2909 if (async_code == AC_SENT_BDR
2910 || async_code == AC_BUS_RESET) {
2911 cam_freeze_devq(&newpath);
2912 cam_release_devq(&newpath,
2913 RELSIM_RELEASE_AFTER_TIMEOUT,
2915 /*timeout*/scsi_delay,
2916 /*getcount_only*/0);
2917 scsi_toggle_tags(&newpath);
2920 if (async_code == AC_INQ_CHANGED) {
2922 * We've sent a start unit command, or
2923 * something similar to a device that
2924 * may have caused its inquiry data to
2925 * change. So we re-scan the device to
2926 * refresh the inquiry data for it.
2928 scsi_scan_lun(newpath.periph, &newpath,
2929 CAM_EXPECT_INQ_CHANGE, NULL);
2931 xpt_release_path(&newpath);
2932 } else if (async_code == AC_LOST_DEVICE &&
2933 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2934 device->flags |= CAM_DEV_UNCONFIGURED;
2935 xpt_release_device(device);
2936 } else if (async_code == AC_TRANSFER_NEG) {
2937 struct ccb_trans_settings *settings;
2939 settings = (struct ccb_trans_settings *)async_arg;
2940 scsi_set_transfer_settings(settings, device,
2941 /*async_update*/TRUE);
2946 scsi_announce_periph(struct cam_periph *periph)
2948 struct ccb_pathinq cpi;
2949 struct ccb_trans_settings cts;
2950 struct cam_path *path = periph->path;
2955 mtx_assert(periph->sim->mtx, MA_OWNED);
2957 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2958 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2959 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2960 xpt_action((union ccb*)&cts);
2961 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2963 /* Ask the SIM for its base transfer speed */
2964 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2965 cpi.ccb_h.func_code = XPT_PATH_INQ;
2966 xpt_action((union ccb *)&cpi);
2967 /* Report connection speed */
2968 speed = cpi.base_transfer_speed;
2970 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2971 struct ccb_trans_settings_spi *spi =
2972 &cts.xport_specific.spi;
2974 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2975 && spi->sync_offset != 0) {
2976 freq = scsi_calc_syncsrate(spi->sync_period);
2979 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2980 speed *= (0x01 << spi->bus_width);
2982 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2983 struct ccb_trans_settings_fc *fc =
2984 &cts.xport_specific.fc;
2986 if (fc->valid & CTS_FC_VALID_SPEED)
2987 speed = fc->bitrate;
2989 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2990 struct ccb_trans_settings_sas *sas =
2991 &cts.xport_specific.sas;
2993 if (sas->valid & CTS_SAS_VALID_SPEED)
2994 speed = sas->bitrate;
2998 printf("%s%d: %d.%03dMB/s transfers",
2999 periph->periph_name, periph->unit_number,
3002 printf("%s%d: %dKB/s transfers", periph->periph_name,
3003 periph->unit_number, speed);
3004 /* Report additional information about SPI connections */
3005 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3006 struct ccb_trans_settings_spi *spi;
3008 spi = &cts.xport_specific.spi;
3010 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3012 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3016 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3017 && spi->bus_width > 0) {
3023 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3024 } else if (freq != 0) {
3028 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3029 struct ccb_trans_settings_fc *fc;
3031 fc = &cts.xport_specific.fc;
3032 if (fc->valid & CTS_FC_VALID_WWNN)
3033 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3034 if (fc->valid & CTS_FC_VALID_WWPN)
3035 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3036 if (fc->valid & CTS_FC_VALID_PORT)
3037 printf(" PortID 0x%x", fc->port);