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 void probestart(struct cam_periph *periph, union ccb *start_ccb);
560 static void proberequestdefaultnegotiation(struct cam_periph *periph);
561 static int proberequestbackoff(struct cam_periph *periph,
562 struct cam_ed *device);
563 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
564 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
566 static void probe_purge_old(struct cam_path *path,
567 struct scsi_report_luns_data *new);
568 static void probecleanup(struct cam_periph *periph);
569 static void scsi_find_quirk(struct cam_ed *device);
570 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
571 static void scsi_scan_lun(struct cam_periph *periph,
572 struct cam_path *path, cam_flags flags,
574 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
575 static struct cam_ed *
576 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
578 static void scsi_devise_transport(struct cam_path *path);
579 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
580 struct cam_ed *device,
582 static void scsi_toggle_tags(struct cam_path *path);
583 static void scsi_dev_async(u_int32_t async_code,
585 struct cam_et *target,
586 struct cam_ed *device,
588 static void scsi_action(union ccb *start_ccb);
589 static void scsi_announce_periph(struct cam_periph *periph);
591 static struct xpt_xport scsi_xport = {
592 .alloc_device = scsi_alloc_device,
593 .action = scsi_action,
594 .async = scsi_dev_async,
595 .announce = scsi_announce_periph,
601 return (&scsi_xport);
610 proberegister(struct cam_periph *periph, void *arg)
612 union ccb *request_ccb; /* CCB representing the probe request */
616 request_ccb = (union ccb *)arg;
617 if (request_ccb == NULL) {
618 printf("proberegister: no probe CCB, "
619 "can't register device\n");
620 return(CAM_REQ_CMP_ERR);
623 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
626 printf("proberegister: Unable to probe new device. "
627 "Unable to allocate softc\n");
628 return(CAM_REQ_CMP_ERR);
630 TAILQ_INIT(&softc->request_ccbs);
631 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
634 periph->softc = softc;
635 softc->periph = periph;
636 softc->action = PROBE_INVALID;
637 status = cam_periph_acquire(periph);
638 if (status != CAM_REQ_CMP) {
641 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
644 * Ensure we've waited at least a bus settle
645 * delay before attempting to probe the device.
646 * For HBAs that don't do bus resets, this won't make a difference.
648 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
651 * Ensure nobody slip in until probe finish.
653 cam_freeze_devq_arg(periph->path,
654 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
655 probeschedule(periph);
660 probeschedule(struct cam_periph *periph)
662 struct ccb_pathinq cpi;
666 softc = (probe_softc *)periph->softc;
667 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
669 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
670 cpi.ccb_h.func_code = XPT_PATH_INQ;
671 xpt_action((union ccb *)&cpi);
674 * If a device has gone away and another device, or the same one,
675 * is back in the same place, it should have a unit attention
676 * condition pending. It will not report the unit attention in
677 * response to an inquiry, which may leave invalid transfer
678 * negotiations in effect. The TUR will reveal the unit attention
679 * condition. Only send the TUR for lun 0, since some devices
680 * will get confused by commands other than inquiry to non-existent
681 * luns. If you think a device has gone away start your scan from
682 * lun 0. This will insure that any bogus transfer settings are
685 * If we haven't seen the device before and the controller supports
686 * some kind of transfer negotiation, negotiate with the first
687 * sent command if no bus reset was performed at startup. This
688 * ensures that the device is not confused by transfer negotiation
689 * settings left over by loader or BIOS action.
691 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
692 && (ccb->ccb_h.target_lun == 0)) {
693 PROBE_SET_ACTION(softc, PROBE_TUR);
694 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
695 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
696 proberequestdefaultnegotiation(periph);
697 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
699 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
702 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
703 softc->flags |= PROBE_NO_ANNOUNCE;
705 softc->flags &= ~PROBE_NO_ANNOUNCE;
707 xpt_schedule(periph, CAM_PRIORITY_XPT);
711 probestart(struct cam_periph *periph, union ccb *start_ccb)
713 /* Probe the device that our peripheral driver points to */
714 struct ccb_scsiio *csio;
717 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
719 softc = (probe_softc *)periph->softc;
720 csio = &start_ccb->csio;
723 switch (softc->action) {
725 case PROBE_TUR_FOR_NEGOTIATION:
728 scsi_test_unit_ready(csio,
737 case PROBE_FULL_INQUIRY:
738 case PROBE_INQUIRY_BASIC_DV1:
739 case PROBE_INQUIRY_BASIC_DV2:
742 struct scsi_inquiry_data *inq_buf;
744 inq_buf = &periph->path->device->inq_data;
747 * If the device is currently configured, we calculate an
748 * MD5 checksum of the inquiry data, and if the serial number
749 * length is greater than 0, add the serial number data
750 * into the checksum as well. Once the inquiry and the
751 * serial number check finish, we attempt to figure out
752 * whether we still have the same device.
754 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
756 MD5Init(&softc->context);
757 MD5Update(&softc->context, (unsigned char *)inq_buf,
758 sizeof(struct scsi_inquiry_data));
759 softc->flags |= PROBE_INQUIRY_CKSUM;
760 if (periph->path->device->serial_num_len > 0) {
761 MD5Update(&softc->context,
762 periph->path->device->serial_num,
763 periph->path->device->serial_num_len);
764 softc->flags |= PROBE_SERIAL_CKSUM;
766 MD5Final(softc->digest, &softc->context);
769 if (softc->action == PROBE_INQUIRY)
770 inquiry_len = SHORT_INQUIRY_LENGTH;
772 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
775 * Some parallel SCSI devices fail to send an
776 * ignore wide residue message when dealing with
777 * odd length inquiry requests. Round up to be
780 inquiry_len = roundup2(inquiry_len, 2);
782 if (softc->action == PROBE_INQUIRY_BASIC_DV1
783 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
784 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
786 if (inq_buf == NULL) {
787 xpt_print(periph->path, "malloc failure- skipping Basic"
788 "Domain Validation\n");
789 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
790 scsi_test_unit_ready(csio,
807 /*timeout*/60 * 1000);
810 case PROBE_REPORT_LUNS:
814 rp = malloc(periph->path->target->rpl_size,
815 M_CAMXPT, M_NOWAIT | M_ZERO);
817 struct scsi_inquiry_data *inq_buf;
818 inq_buf = &periph->path->device->inq_data;
819 xpt_print(periph->path,
820 "Unable to alloc report luns storage\n");
821 if (INQ_DATA_TQ_ENABLED(inq_buf))
822 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
824 PROBE_SET_ACTION(softc,
825 PROBE_SUPPORTED_VPD_LIST);
828 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
829 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
830 SSD_FULL_SIZE, 60000); break;
833 case PROBE_MODE_SENSE:
838 mode_buf_len = sizeof(struct scsi_mode_header_6)
839 + sizeof(struct scsi_mode_blk_desc)
840 + sizeof(struct scsi_control_page);
841 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
842 if (mode_buf != NULL) {
843 scsi_mode_sense(csio,
848 SMS_PAGE_CTRL_CURRENT,
849 SMS_CONTROL_MODE_PAGE,
856 xpt_print(periph->path, "Unable to mode sense control page - "
858 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
861 case PROBE_SUPPORTED_VPD_LIST:
863 struct scsi_vpd_supported_page_list *vpd_list;
864 struct cam_ed *device;
867 device = periph->path->device;
869 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
870 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
873 if (vpd_list != NULL) {
878 (u_int8_t *)vpd_list,
881 SVPD_SUPPORTED_PAGE_LIST,
883 /*timeout*/60 * 1000);
887 * We'll have to do without, let our probedone
888 * routine finish up for us.
890 start_ccb->csio.data_ptr = NULL;
891 probedone(periph, start_ccb);
894 case PROBE_DEVICE_ID:
896 struct scsi_vpd_device_id *devid;
899 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
900 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
909 SVPD_DEVICE_ID_MAX_SIZE,
913 /*timeout*/60 * 1000);
917 * We'll have to do without, let our probedone
918 * routine finish up for us.
920 start_ccb->csio.data_ptr = NULL;
921 probedone(periph, start_ccb);
924 case PROBE_SERIAL_NUM:
926 struct scsi_vpd_unit_serial_number *serial_buf;
927 struct cam_ed* device;
930 device = periph->path->device;
931 if (device->serial_num != NULL) {
932 free(device->serial_num, M_CAMXPT);
933 device->serial_num = NULL;
934 device->serial_num_len = 0;
937 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
938 serial_buf = (struct scsi_vpd_unit_serial_number *)
939 malloc(sizeof(*serial_buf), M_CAMXPT,
942 if (serial_buf != NULL) {
947 (u_int8_t *)serial_buf,
950 SVPD_UNIT_SERIAL_NUMBER,
952 /*timeout*/60 * 1000);
956 * We'll have to do without, let our probedone
957 * routine finish up for us.
959 start_ccb->csio.data_ptr = NULL;
960 probedone(periph, start_ccb);
964 panic("probestart: invalid action state 0x%x\n", softc->action);
966 xpt_action(start_ccb);
970 proberequestdefaultnegotiation(struct cam_periph *periph)
972 struct ccb_trans_settings cts;
974 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
975 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
976 cts.type = CTS_TYPE_USER_SETTINGS;
977 xpt_action((union ccb *)&cts);
978 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
981 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
982 cts.type = CTS_TYPE_CURRENT_SETTINGS;
983 xpt_action((union ccb *)&cts);
987 * Backoff Negotiation Code- only pertinent for SPI devices.
990 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
992 struct ccb_trans_settings cts;
993 struct ccb_trans_settings_spi *spi;
995 memset(&cts, 0, sizeof (cts));
996 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
997 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
998 cts.type = CTS_TYPE_CURRENT_SETTINGS;
999 xpt_action((union ccb *)&cts);
1000 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1002 xpt_print(periph->path,
1003 "failed to get current device settings\n");
1007 if (cts.transport != XPORT_SPI) {
1009 xpt_print(periph->path, "not SPI transport\n");
1013 spi = &cts.xport_specific.spi;
1016 * We cannot renegotiate sync rate if we don't have one.
1018 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1020 xpt_print(periph->path, "no sync rate known\n");
1026 * We'll assert that we don't have to touch PPR options- the
1027 * SIM will see what we do with period and offset and adjust
1028 * the PPR options as appropriate.
1032 * A sync rate with unknown or zero offset is nonsensical.
1033 * A sync period of zero means Async.
1035 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1036 || spi->sync_offset == 0 || spi->sync_period == 0) {
1038 xpt_print(periph->path, "no sync rate available\n");
1043 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1044 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1045 ("hit async: giving up on DV\n"));
1051 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1052 * We don't try to remember 'last' settings to see if the SIM actually
1053 * gets into the speed we want to set. We check on the SIM telling
1054 * us that a requested speed is bad, but otherwise don't try and
1055 * check the speed due to the asynchronous and handshake nature
1058 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1061 if (spi->sync_period >= 0xf) {
1062 spi->sync_period = 0;
1063 spi->sync_offset = 0;
1064 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1065 ("setting to async for DV\n"));
1067 * Once we hit async, we don't want to try
1068 * any more settings.
1070 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1071 } else if (bootverbose) {
1072 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1073 ("DV: period 0x%x\n", spi->sync_period));
1074 printf("setting period to 0x%x\n", spi->sync_period);
1076 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1077 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1078 xpt_action((union ccb *)&cts);
1079 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1082 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1083 ("DV: failed to set period 0x%x\n", spi->sync_period));
1084 if (spi->sync_period == 0) {
1091 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1094 probedone(struct cam_periph *periph, union ccb *done_ccb)
1097 struct cam_path *path;
1100 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1102 softc = (probe_softc *)periph->softc;
1103 path = done_ccb->ccb_h.path;
1104 priority = done_ccb->ccb_h.pinfo.priority;
1106 switch (softc->action) {
1109 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1111 if (cam_periph_error(done_ccb, 0,
1112 SF_NO_PRINT, NULL) == ERESTART)
1114 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1115 /* Don't wedge the queue */
1116 xpt_release_devq(done_ccb->ccb_h.path,
1120 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1121 xpt_release_ccb(done_ccb);
1122 xpt_schedule(periph, priority);
1126 case PROBE_FULL_INQUIRY:
1128 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1129 struct scsi_inquiry_data *inq_buf;
1130 u_int8_t periph_qual;
1132 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1133 inq_buf = &path->device->inq_data;
1135 periph_qual = SID_QUAL(inq_buf);
1137 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1141 * We conservatively request only
1142 * SHORT_INQUIRY_LEN bytes of inquiry
1143 * information during our first try
1144 * at sending an INQUIRY. If the device
1145 * has more information to give,
1146 * perform a second request specifying
1147 * the amount of information the device
1148 * is willing to give.
1150 len = inq_buf->additional_length
1151 + offsetof(struct scsi_inquiry_data,
1152 additional_length) + 1;
1153 if (softc->action == PROBE_INQUIRY
1154 && len > SHORT_INQUIRY_LENGTH) {
1155 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1156 xpt_release_ccb(done_ccb);
1157 xpt_schedule(periph, priority);
1161 scsi_find_quirk(path->device);
1163 scsi_devise_transport(path);
1165 if (path->device->lun_id == 0 &&
1166 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1167 (SCSI_QUIRK(path->device)->quirks &
1168 CAM_QUIRK_NORPTLUNS) == 0) {
1169 PROBE_SET_ACTION(softc,
1172 * Start with room for *one* lun.
1174 periph->path->target->rpl_size = 16;
1175 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1176 PROBE_SET_ACTION(softc,
1179 PROBE_SET_ACTION(softc,
1180 PROBE_SUPPORTED_VPD_LIST);
1182 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1183 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1184 xpt_acquire_device(path->device);
1186 xpt_release_ccb(done_ccb);
1187 xpt_schedule(periph, priority);
1189 } else if (path->device->lun_id == 0 &&
1190 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1191 (SCSI_QUIRK(path->device)->quirks &
1192 CAM_QUIRK_NORPTLUNS) == 0) {
1193 if (path->device->flags &
1194 CAM_DEV_UNCONFIGURED) {
1195 path->device->flags &=
1196 ~CAM_DEV_UNCONFIGURED;
1197 xpt_acquire_device(path->device);
1199 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1200 periph->path->target->rpl_size = 16;
1201 xpt_release_ccb(done_ccb);
1202 xpt_schedule(periph, priority);
1205 } else if (cam_periph_error(done_ccb, 0,
1206 done_ccb->ccb_h.target_lun > 0
1207 ? SF_RETRY_UA|SF_QUIET_IR
1209 &softc->saved_ccb) == ERESTART) {
1211 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1212 /* Don't wedge the queue */
1213 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1217 * If we get to this point, we got an error status back
1218 * from the inquiry and the error status doesn't require
1219 * automatically retrying the command. Therefore, the
1220 * inquiry failed. If we had inquiry information before
1221 * for this device, but this latest inquiry command failed,
1222 * the device has probably gone away. If this device isn't
1223 * already marked unconfigured, notify the peripheral
1224 * drivers that this device is no more.
1226 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1227 /* Send the async notification. */
1228 xpt_async(AC_LOST_DEVICE, path, NULL);
1229 PROBE_SET_ACTION(softc, PROBE_INVALID);
1231 xpt_release_ccb(done_ccb);
1234 case PROBE_REPORT_LUNS:
1236 struct ccb_scsiio *csio;
1237 struct scsi_report_luns_data *lp;
1240 csio = &done_ccb->csio;
1242 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1243 nlun = scsi_4btoul(lp->length) / 8;
1244 maxlun = (csio->dxfer_len / 8) - 1;
1246 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1247 if (cam_periph_error(done_ccb, 0,
1248 done_ccb->ccb_h.target_lun > 0 ?
1249 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1250 &softc->saved_ccb) == ERESTART) {
1253 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1254 xpt_release_devq(done_ccb->ccb_h.path, 1,
1259 } else if (nlun > maxlun) {
1261 * Reallocate and retry to cover all luns
1263 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1264 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1267 path->target->rpl_size = (nlun << 3) + 8;
1268 xpt_release_ccb(done_ccb);
1269 xpt_schedule(periph, priority);
1271 } else if (nlun == 0) {
1273 * If there don't appear to be any luns, bail.
1277 } else if (probe_strange_rpl_data(lp, maxlun)) {
1279 * If we can't understand the lun format
1280 * of any entry, bail.
1288 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1289 ("Probe: %u lun(s) reported\n", nlun));
1291 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1293 * If the first lun is not lun 0, then either there
1294 * is no lun 0 in the list, or the list is unsorted.
1297 for (idx = 0; idx < nlun; idx++) {
1298 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1306 lp->luns[0].lundata, 8);
1307 memcpy(lp->luns[0].lundata,
1308 lp->luns[idx].lundata, 8);
1309 memcpy(lp->luns[idx].lundata,
1311 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1312 ("lun 0 in position %u\n", idx));
1315 * There is no lun 0 in our list. Destroy
1316 * the validity of the inquiry data so we
1317 * bail here and now.
1319 path->device->flags &=
1320 ~CAM_DEV_INQUIRY_DATA_VALID;
1324 * If we have an old lun list, We can either
1325 * retest luns that appear to have been dropped,
1326 * or just nuke them. We'll opt for the latter.
1327 * This function will also install the new list
1328 * in the target structure.
1330 probe_purge_old(path, lp);
1333 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1334 struct scsi_inquiry_data *inq_buf;
1335 inq_buf = &path->device->inq_data;
1336 if (INQ_DATA_TQ_ENABLED(inq_buf))
1337 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1339 PROBE_SET_ACTION(softc,
1340 PROBE_SUPPORTED_VPD_LIST);
1341 xpt_release_ccb(done_ccb);
1342 xpt_schedule(periph, priority);
1350 case PROBE_MODE_SENSE:
1352 struct ccb_scsiio *csio;
1353 struct scsi_mode_header_6 *mode_hdr;
1355 csio = &done_ccb->csio;
1356 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1357 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1358 struct scsi_control_page *page;
1361 offset = ((u_int8_t *)&mode_hdr[1])
1362 + mode_hdr->blk_desc_len;
1363 page = (struct scsi_control_page *)offset;
1364 path->device->queue_flags = page->queue_flags;
1365 } else if (cam_periph_error(done_ccb, 0,
1366 SF_RETRY_UA|SF_NO_PRINT,
1367 &softc->saved_ccb) == ERESTART) {
1369 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1370 /* Don't wedge the queue */
1371 xpt_release_devq(done_ccb->ccb_h.path,
1372 /*count*/1, /*run_queue*/TRUE);
1374 xpt_release_ccb(done_ccb);
1375 free(mode_hdr, M_CAMXPT);
1376 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1377 xpt_schedule(periph, priority);
1380 case PROBE_SUPPORTED_VPD_LIST:
1382 struct ccb_scsiio *csio;
1383 struct scsi_vpd_supported_page_list *page_list;
1385 csio = &done_ccb->csio;
1387 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1389 if (path->device->supported_vpds != NULL) {
1390 free(path->device->supported_vpds, M_CAMXPT);
1391 path->device->supported_vpds = NULL;
1392 path->device->supported_vpds_len = 0;
1395 if (page_list == NULL) {
1397 * Don't process the command as it was never sent
1399 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1401 path->device->supported_vpds_len = page_list->length +
1402 SVPD_SUPPORTED_PAGES_HDR_LEN;
1403 path->device->supported_vpds = (uint8_t *)page_list;
1404 xpt_release_ccb(done_ccb);
1405 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1406 xpt_schedule(periph, priority);
1408 } else if (cam_periph_error(done_ccb, 0,
1409 SF_RETRY_UA|SF_NO_PRINT,
1410 &softc->saved_ccb) == ERESTART) {
1412 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1413 /* Don't wedge the queue */
1414 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1419 free(page_list, M_CAMXPT);
1420 /* No VPDs available, skip to device check. */
1421 csio->data_ptr = NULL;
1422 goto probe_device_check;
1424 case PROBE_DEVICE_ID:
1426 struct scsi_vpd_device_id *devid;
1427 struct ccb_scsiio *csio;
1428 uint32_t length = 0;
1430 csio = &done_ccb->csio;
1431 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1433 /* Clean up from previous instance of this device */
1434 if (path->device->device_id != NULL) {
1435 path->device->device_id_len = 0;
1436 free(path->device->device_id, M_CAMXPT);
1437 path->device->device_id = NULL;
1440 if (devid == NULL) {
1441 /* Don't process the command as it was never sent */
1442 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1443 length = scsi_2btoul(devid->length);
1446 * NB: device_id_len is actual response
1447 * size, not buffer size.
1449 path->device->device_id_len = length +
1450 SVPD_DEVICE_ID_HDR_LEN;
1451 path->device->device_id = (uint8_t *)devid;
1453 } else if (cam_periph_error(done_ccb, 0,
1455 &softc->saved_ccb) == ERESTART) {
1457 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1458 /* Don't wedge the queue */
1459 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1463 /* Free the device id space if we don't use it */
1464 if (devid && length == 0)
1465 free(devid, M_CAMXPT);
1466 xpt_release_ccb(done_ccb);
1467 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1468 xpt_schedule(periph, priority);
1473 case PROBE_SERIAL_NUM:
1475 struct ccb_scsiio *csio;
1476 struct scsi_vpd_unit_serial_number *serial_buf;
1483 csio = &done_ccb->csio;
1484 priority = done_ccb->ccb_h.pinfo.priority;
1486 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1488 if (serial_buf == NULL) {
1490 * Don't process the command as it was never sent
1492 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1493 && (serial_buf->length > 0)) {
1496 path->device->serial_num =
1497 (u_int8_t *)malloc((serial_buf->length + 1),
1498 M_CAMXPT, M_NOWAIT);
1499 if (path->device->serial_num != NULL) {
1500 memcpy(path->device->serial_num,
1501 serial_buf->serial_num,
1502 serial_buf->length);
1503 path->device->serial_num_len =
1505 path->device->serial_num[serial_buf->length]
1508 } else if (cam_periph_error(done_ccb, 0,
1509 SF_RETRY_UA|SF_NO_PRINT,
1510 &softc->saved_ccb) == ERESTART) {
1512 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1513 /* Don't wedge the queue */
1514 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1519 * Let's see if we have seen this device before.
1521 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1523 u_int8_t digest[16];
1528 (unsigned char *)&path->device->inq_data,
1529 sizeof(struct scsi_inquiry_data));
1532 MD5Update(&context, serial_buf->serial_num,
1533 serial_buf->length);
1535 MD5Final(digest, &context);
1536 if (bcmp(softc->digest, digest, 16) == 0)
1540 * XXX Do we need to do a TUR in order to ensure
1541 * that the device really hasn't changed???
1544 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1545 xpt_async(AC_LOST_DEVICE, path, NULL);
1547 if (serial_buf != NULL)
1548 free(serial_buf, M_CAMXPT);
1552 * Now that we have all the necessary
1553 * information to safely perform transfer
1554 * negotiations... Controllers don't perform
1555 * any negotiation or tagged queuing until
1556 * after the first XPT_SET_TRAN_SETTINGS ccb is
1557 * received. So, on a new device, just retrieve
1558 * the user settings, and set them as the current
1559 * settings to set the device up.
1561 proberequestdefaultnegotiation(periph);
1562 xpt_release_ccb(done_ccb);
1565 * Perform a TUR to allow the controller to
1566 * perform any necessary transfer negotiation.
1568 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1569 xpt_schedule(periph, priority);
1572 xpt_release_ccb(done_ccb);
1575 case PROBE_TUR_FOR_NEGOTIATION:
1577 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1578 cam_periph_error(done_ccb, 0,
1579 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1581 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1582 /* Don't wedge the queue */
1583 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1587 * Do Domain Validation for lun 0 on devices that claim
1588 * to support Synchronous Transfer modes.
1590 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1591 && done_ccb->ccb_h.target_lun == 0
1592 && (path->device->inq_data.flags & SID_Sync) != 0
1593 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1594 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1595 ("Begin Domain Validation\n"));
1596 path->device->flags |= CAM_DEV_IN_DV;
1597 xpt_release_ccb(done_ccb);
1598 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1599 xpt_schedule(periph, priority);
1602 if (softc->action == PROBE_DV_EXIT) {
1603 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1604 ("Leave Domain Validation\n"));
1606 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1607 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1608 xpt_acquire_device(path->device);
1610 path->device->flags &=
1611 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1612 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1613 /* Inform the XPT that a new device has been found */
1614 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1615 xpt_action(done_ccb);
1616 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1619 PROBE_SET_ACTION(softc, PROBE_DONE);
1620 xpt_release_ccb(done_ccb);
1622 case PROBE_INQUIRY_BASIC_DV1:
1623 case PROBE_INQUIRY_BASIC_DV2:
1625 struct scsi_inquiry_data *nbuf;
1626 struct ccb_scsiio *csio;
1628 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1629 cam_periph_error(done_ccb, 0,
1630 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1632 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1633 /* Don't wedge the queue */
1634 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1637 csio = &done_ccb->csio;
1638 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1639 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1641 "inquiry data fails comparison at DV%d step\n",
1642 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1643 if (proberequestbackoff(periph, path->device)) {
1644 path->device->flags &= ~CAM_DEV_IN_DV;
1645 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1648 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1650 free(nbuf, M_CAMXPT);
1651 xpt_release_ccb(done_ccb);
1652 xpt_schedule(periph, priority);
1655 free(nbuf, M_CAMXPT);
1656 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1657 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1658 xpt_release_ccb(done_ccb);
1659 xpt_schedule(periph, priority);
1662 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1663 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1664 ("Leave Domain Validation Successfully\n"));
1666 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1667 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1668 xpt_acquire_device(path->device);
1670 path->device->flags &=
1671 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1672 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1673 /* Inform the XPT that a new device has been found */
1674 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1675 xpt_action(done_ccb);
1676 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1679 PROBE_SET_ACTION(softc, PROBE_DONE);
1680 xpt_release_ccb(done_ccb);
1684 panic("probedone: invalid action state 0x%x\n", softc->action);
1686 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1687 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1688 done_ccb->ccb_h.status = CAM_REQ_CMP;
1690 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1691 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1692 cam_periph_invalidate(periph);
1693 cam_release_devq(periph->path,
1694 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1695 cam_periph_release_locked(periph);
1697 probeschedule(periph);
1702 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1705 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1707 for (idx = 0; idx < nlun; idx++) {
1708 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1716 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1718 struct cam_path *tp;
1719 struct scsi_report_luns_data *old;
1720 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1723 if (path->target == NULL) {
1726 if (path->target->luns == NULL) {
1727 path->target->luns = new;
1730 old = path->target->luns;
1731 nlun_old = scsi_4btoul(old->length) / 8;
1732 nlun_new = scsi_4btoul(new->length) / 8;
1735 * We are not going to assume sorted lists. Deal.
1737 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1738 ol = old->luns[idx1].lundata;
1739 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1740 nl = new->luns[idx2].lundata;
1741 if (memcmp(nl, ol, 8) == 0) {
1745 if (idx2 < nlun_new) {
1749 * An 'old' item not in the 'new' list.
1750 * Nuke it. Except that if it is lun 0,
1751 * that would be what the probe state
1752 * machine is currently working on,
1753 * so we won't do that.
1755 * We also cannot nuke it if it is
1756 * not in a lun format we understand.
1758 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1761 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1762 if (this_lun == 0) {
1765 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1766 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1767 xpt_async(AC_LOST_DEVICE, tp, NULL);
1771 free(old, M_CAMXPT);
1772 path->target->luns = new;
1776 probecleanup(struct cam_periph *periph)
1778 free(periph->softc, M_CAMXPT);
1782 scsi_find_quirk(struct cam_ed *device)
1784 struct scsi_quirk_entry *quirk;
1787 match = cam_quirkmatch((caddr_t)&device->inq_data,
1788 (caddr_t)scsi_quirk_table,
1789 sizeof(scsi_quirk_table) /
1790 sizeof(*scsi_quirk_table),
1791 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1794 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1796 quirk = (struct scsi_quirk_entry *)match;
1797 device->quirk = quirk;
1798 device->mintags = quirk->mintags;
1799 device->maxtags = quirk->maxtags;
1803 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1808 error = sysctl_handle_int(oidp, &val, 0, req);
1809 if (error != 0 || req->newptr == NULL)
1811 if (val == 0 || val == 1) {
1820 union ccb *request_ccb;
1821 struct ccb_pathinq *cpi;
1824 } scsi_scan_bus_info;
1827 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1828 * As the scan progresses, scsi_scan_bus is used as the
1829 * callback on completion function.
1832 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1834 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1835 ("scsi_scan_bus\n"));
1836 switch (request_ccb->ccb_h.func_code) {
1840 scsi_scan_bus_info *scan_info;
1841 union ccb *work_ccb, *reset_ccb;
1842 struct cam_path *path;
1844 u_int low_target, max_target;
1847 /* Find out the characteristics of the bus */
1848 work_ccb = xpt_alloc_ccb_nowait();
1849 if (work_ccb == NULL) {
1850 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1851 xpt_done(request_ccb);
1854 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1855 request_ccb->ccb_h.pinfo.priority);
1856 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1857 xpt_action(work_ccb);
1858 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1859 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1860 xpt_free_ccb(work_ccb);
1861 xpt_done(request_ccb);
1865 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1867 * Can't scan the bus on an adapter that
1868 * cannot perform the initiator role.
1870 request_ccb->ccb_h.status = CAM_REQ_CMP;
1871 xpt_free_ccb(work_ccb);
1872 xpt_done(request_ccb);
1876 /* We may need to reset bus first, if we haven't done it yet. */
1877 if ((work_ccb->cpi.hba_inquiry &
1878 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1879 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1880 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1881 reset_ccb = xpt_alloc_ccb_nowait();
1882 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1884 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1885 xpt_action(reset_ccb);
1886 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1887 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1888 xpt_free_ccb(reset_ccb);
1889 xpt_free_ccb(work_ccb);
1890 xpt_done(request_ccb);
1893 xpt_free_ccb(reset_ccb);
1896 /* Save some state for use while we probe for devices */
1897 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1898 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1899 if (scan_info == NULL) {
1900 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1901 xpt_done(request_ccb);
1904 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1905 ("SCAN start for %p\n", scan_info));
1906 scan_info->request_ccb = request_ccb;
1907 scan_info->cpi = &work_ccb->cpi;
1909 /* Cache on our stack so we can work asynchronously */
1910 max_target = scan_info->cpi->max_target;
1912 initiator_id = scan_info->cpi->initiator_id;
1916 * We can scan all targets in parallel, or do it sequentially.
1919 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1920 max_target = low_target = request_ccb->ccb_h.target_id;
1921 scan_info->counter = 0;
1922 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1924 scan_info->counter = 0;
1926 scan_info->counter = scan_info->cpi->max_target + 1;
1927 if (scan_info->cpi->initiator_id < scan_info->counter) {
1928 scan_info->counter--;
1932 for (i = low_target; i <= max_target; i++) {
1934 if (i == initiator_id)
1937 status = xpt_create_path(&path, NULL,
1938 request_ccb->ccb_h.path_id,
1940 if (status != CAM_REQ_CMP) {
1941 printf("scsi_scan_bus: xpt_create_path failed"
1942 " with status %#x, bus scan halted\n",
1944 free(scan_info, M_CAMXPT);
1945 request_ccb->ccb_h.status = status;
1946 xpt_free_ccb(work_ccb);
1947 xpt_done(request_ccb);
1950 work_ccb = xpt_alloc_ccb_nowait();
1951 if (work_ccb == NULL) {
1952 xpt_free_ccb((union ccb *)scan_info->cpi);
1953 free(scan_info, M_CAMXPT);
1954 xpt_free_path(path);
1955 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1956 xpt_done(request_ccb);
1959 xpt_setup_ccb(&work_ccb->ccb_h, path,
1960 request_ccb->ccb_h.pinfo.priority);
1961 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1962 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1963 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1964 work_ccb->crcn.flags = request_ccb->crcn.flags;
1965 xpt_action(work_ccb);
1972 struct cam_path *path, *oldpath;
1973 scsi_scan_bus_info *scan_info;
1974 struct cam_et *target;
1975 struct cam_ed *device;
1978 target_id_t target_id;
1981 oldpath = request_ccb->ccb_h.path;
1983 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
1984 /* Reuse the same CCB to query if a device was really found */
1985 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1986 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1987 request_ccb->ccb_h.pinfo.priority);
1988 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1991 path_id = request_ccb->ccb_h.path_id;
1992 target_id = request_ccb->ccb_h.target_id;
1993 lun_id = request_ccb->ccb_h.target_lun;
1994 xpt_action(request_ccb);
1996 target = request_ccb->ccb_h.path->target;
2001 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2004 * Make sure we skip over lun 0 if it's the first member
2005 * of the list as we've actually just finished probing
2008 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
2009 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2010 scan_info->lunindex[target_id]++;
2013 if (scan_info->lunindex[target_id] < nluns) {
2014 CAM_GET_SIMPLE_LUN(target->luns,
2015 scan_info->lunindex[target_id], lun_id);
2017 CAM_DEBUG(request_ccb->ccb_h.path,
2019 ("next lun to try at index %u is %u\n",
2020 scan_info->lunindex[target_id], lun_id));
2021 scan_info->lunindex[target_id]++;
2024 * We're done with scanning all luns.
2026 * Nuke the bogus device for lun 0 if lun 0
2027 * wasn't on the list.
2030 TAILQ_FOREACH(device,
2031 &target->ed_entries, links) {
2032 if (device->lun_id == 0) {
2037 xpt_release_device(device);
2041 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2045 * If we already probed lun 0 successfully, or
2046 * we have additional configured luns on this
2047 * target that might have "gone away", go onto
2051 * We may touch devices that we don't
2052 * hold references too, so ensure they
2053 * don't disappear out from under us.
2054 * The target above is referenced by the
2055 * path in the request ccb.
2058 device = TAILQ_FIRST(&target->ed_entries);
2059 if (device != NULL) {
2060 phl = CAN_SRCH_HI_SPARSE(device);
2061 if (device->lun_id == 0)
2062 device = TAILQ_NEXT(device, links);
2064 if ((lun_id != 0) || (device != NULL)) {
2065 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2070 if (lun_id == request_ccb->ccb_h.target_lun
2071 || lun_id > scan_info->cpi->max_lun)
2075 device = request_ccb->ccb_h.path->device;
2077 if ((SCSI_QUIRK(device)->quirks &
2078 CAM_QUIRK_NOLUNS) == 0) {
2079 /* Try the next lun */
2080 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2081 || CAN_SRCH_HI_DENSE(device)) {
2086 if (lun_id == request_ccb->ccb_h.target_lun
2087 || lun_id > scan_info->cpi->max_lun)
2092 * Check to see if we scan any further luns.
2098 * Free the current request path- we're done with it.
2100 xpt_free_path(oldpath);
2103 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2105 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2106 scan_info->counter++;
2107 if (scan_info->counter ==
2108 scan_info->cpi->initiator_id) {
2109 scan_info->counter++;
2111 if (scan_info->counter >=
2112 scan_info->cpi->max_target+1) {
2116 scan_info->counter--;
2117 if (scan_info->counter == 0) {
2122 xpt_free_ccb(request_ccb);
2123 xpt_free_ccb((union ccb *)scan_info->cpi);
2124 request_ccb = scan_info->request_ccb;
2125 CAM_DEBUG(request_ccb->ccb_h.path,
2127 ("SCAN done for %p\n", scan_info));
2128 free(scan_info, M_CAMXPT);
2129 request_ccb->ccb_h.status = CAM_REQ_CMP;
2130 xpt_done(request_ccb);
2134 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2135 xpt_free_ccb(request_ccb);
2138 status = xpt_create_path(&path, NULL,
2139 scan_info->request_ccb->ccb_h.path_id,
2140 scan_info->counter, 0);
2141 if (status != CAM_REQ_CMP) {
2142 printf("scsi_scan_bus: xpt_create_path failed"
2143 " with status %#x, bus scan halted\n",
2145 xpt_free_ccb(request_ccb);
2146 xpt_free_ccb((union ccb *)scan_info->cpi);
2147 request_ccb = scan_info->request_ccb;
2148 free(scan_info, M_CAMXPT);
2149 request_ccb->ccb_h.status = status;
2150 xpt_done(request_ccb);
2153 xpt_setup_ccb(&request_ccb->ccb_h, path,
2154 request_ccb->ccb_h.pinfo.priority);
2155 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2156 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2157 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2158 request_ccb->crcn.flags =
2159 scan_info->request_ccb->crcn.flags;
2161 status = xpt_create_path(&path, NULL,
2162 path_id, target_id, lun_id);
2164 * Free the old request path- we're done with it. We
2165 * do this *after* creating the new path so that
2166 * we don't remove a target that has our lun list
2167 * in the case that lun 0 is not present.
2169 xpt_free_path(oldpath);
2170 if (status != CAM_REQ_CMP) {
2171 printf("scsi_scan_bus: xpt_create_path failed "
2172 "with status %#x, halting LUN scan\n",
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 xpt_action(request_ccb);
2193 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2194 cam_flags flags, union ccb *request_ccb)
2196 struct ccb_pathinq cpi;
2198 struct cam_path *new_path;
2199 struct cam_periph *old_periph;
2201 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2203 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2204 cpi.ccb_h.func_code = XPT_PATH_INQ;
2205 xpt_action((union ccb *)&cpi);
2207 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2208 if (request_ccb != NULL) {
2209 request_ccb->ccb_h.status = cpi.ccb_h.status;
2210 xpt_done(request_ccb);
2215 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2217 * Can't scan the bus on an adapter that
2218 * cannot perform the initiator role.
2220 if (request_ccb != NULL) {
2221 request_ccb->ccb_h.status = CAM_REQ_CMP;
2222 xpt_done(request_ccb);
2227 if (request_ccb == NULL) {
2228 request_ccb = xpt_alloc_ccb_nowait();
2229 if (request_ccb == NULL) {
2230 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2231 "can't continue\n");
2234 status = xpt_create_path(&new_path, NULL,
2236 path->target->target_id,
2237 path->device->lun_id);
2238 if (status != CAM_REQ_CMP) {
2239 xpt_print(path, "scsi_scan_lun: can't create path, "
2240 "can't continue\n");
2241 xpt_free_ccb(request_ccb);
2244 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2245 request_ccb->ccb_h.cbfcnp = xptscandone;
2246 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2247 request_ccb->crcn.flags = flags;
2250 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2251 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2254 softc = (probe_softc *)old_periph->softc;
2255 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2256 &request_ccb->ccb_h, periph_links.tqe);
2258 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2259 xpt_done(request_ccb);
2262 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2263 probestart, "probe",
2265 request_ccb->ccb_h.path, NULL, 0,
2268 if (status != CAM_REQ_CMP) {
2269 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2270 "returned an error, can't continue probe\n");
2271 request_ccb->ccb_h.status = status;
2272 xpt_done(request_ccb);
2278 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2281 xpt_free_path(done_ccb->ccb_h.path);
2282 xpt_free_ccb(done_ccb);
2285 static struct cam_ed *
2286 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2288 struct cam_path path;
2289 struct scsi_quirk_entry *quirk;
2290 struct cam_ed *device;
2292 device = xpt_alloc_device(bus, target, lun_id);
2297 * Take the default quirk entry until we have inquiry
2298 * data and can determine a better quirk to use.
2300 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2301 device->quirk = (void *)quirk;
2302 device->mintags = quirk->mintags;
2303 device->maxtags = quirk->maxtags;
2304 bzero(&device->inq_data, sizeof(device->inq_data));
2305 device->inq_flags = 0;
2306 device->queue_flags = 0;
2307 device->serial_num = NULL;
2308 device->serial_num_len = 0;
2309 device->device_id = NULL;
2310 device->device_id_len = 0;
2311 device->supported_vpds = NULL;
2312 device->supported_vpds_len = 0;
2315 * XXX should be limited by number of CCBs this bus can
2318 bus->sim->max_ccbs += device->ccbq.devq_openings;
2319 if (lun_id != CAM_LUN_WILDCARD) {
2320 xpt_compile_path(&path,
2325 scsi_devise_transport(&path);
2326 xpt_release_path(&path);
2333 scsi_devise_transport(struct cam_path *path)
2335 struct ccb_pathinq cpi;
2336 struct ccb_trans_settings cts;
2337 struct scsi_inquiry_data *inq_buf;
2339 /* Get transport information from the SIM */
2340 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2341 cpi.ccb_h.func_code = XPT_PATH_INQ;
2342 xpt_action((union ccb *)&cpi);
2345 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2346 inq_buf = &path->device->inq_data;
2347 path->device->protocol = PROTO_SCSI;
2348 path->device->protocol_version =
2349 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2350 path->device->transport = cpi.transport;
2351 path->device->transport_version = cpi.transport_version;
2354 * Any device not using SPI3 features should
2355 * be considered SPI2 or lower.
2357 if (inq_buf != NULL) {
2358 if (path->device->transport == XPORT_SPI
2359 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2360 && path->device->transport_version > 2)
2361 path->device->transport_version = 2;
2363 struct cam_ed* otherdev;
2365 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2367 otherdev = TAILQ_NEXT(otherdev, links)) {
2368 if (otherdev != path->device)
2372 if (otherdev != NULL) {
2374 * Initially assume the same versioning as
2375 * prior luns for this target.
2377 path->device->protocol_version =
2378 otherdev->protocol_version;
2379 path->device->transport_version =
2380 otherdev->transport_version;
2382 /* Until we know better, opt for safty */
2383 path->device->protocol_version = 2;
2384 if (path->device->transport == XPORT_SPI)
2385 path->device->transport_version = 2;
2387 path->device->transport_version = 0;
2393 * For a device compliant with SPC-2 we should be able
2394 * to determine the transport version supported by
2395 * scrutinizing the version descriptors in the
2399 /* Tell the controller what we think */
2400 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2401 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2402 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2403 cts.transport = path->device->transport;
2404 cts.transport_version = path->device->transport_version;
2405 cts.protocol = path->device->protocol;
2406 cts.protocol_version = path->device->protocol_version;
2407 cts.proto_specific.valid = 0;
2408 cts.xport_specific.valid = 0;
2409 xpt_action((union ccb *)&cts);
2413 scsi_dev_advinfo(union ccb *start_ccb)
2415 struct cam_ed *device;
2416 struct ccb_dev_advinfo *cdai;
2419 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2420 device = start_ccb->ccb_h.path->device;
2421 cdai = &start_ccb->cdai;
2422 switch(cdai->buftype) {
2423 case CDAI_TYPE_SCSI_DEVID:
2424 if (cdai->flags & CDAI_FLAG_STORE)
2426 cdai->provsiz = device->device_id_len;
2427 if (device->device_id_len == 0)
2429 amt = device->device_id_len;
2430 if (cdai->provsiz > cdai->bufsiz)
2432 memcpy(cdai->buf, device->device_id, amt);
2434 case CDAI_TYPE_SERIAL_NUM:
2435 if (cdai->flags & CDAI_FLAG_STORE)
2437 cdai->provsiz = device->serial_num_len;
2438 if (device->serial_num_len == 0)
2440 amt = device->serial_num_len;
2441 if (cdai->provsiz > cdai->bufsiz)
2443 memcpy(cdai->buf, device->serial_num, amt);
2445 case CDAI_TYPE_PHYS_PATH:
2446 if (cdai->flags & CDAI_FLAG_STORE) {
2447 if (device->physpath != NULL) {
2448 free(device->physpath, M_CAMXPT);
2449 device->physpath = NULL;
2451 device->physpath_len = cdai->bufsiz;
2452 /* Clear existing buffer if zero length */
2453 if (cdai->bufsiz == 0)
2455 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2456 if (device->physpath == NULL) {
2457 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2460 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2462 cdai->provsiz = device->physpath_len;
2463 if (device->physpath_len == 0)
2465 amt = device->physpath_len;
2466 if (cdai->provsiz > cdai->bufsiz)
2468 memcpy(cdai->buf, device->physpath, amt);
2471 case CDAI_TYPE_RCAPLONG:
2472 if (cdai->flags & CDAI_FLAG_STORE) {
2473 if (device->rcap_buf != NULL) {
2474 free(device->rcap_buf, M_CAMXPT);
2475 device->rcap_buf = NULL;
2478 device->rcap_len = cdai->bufsiz;
2479 /* Clear existing buffer if zero length */
2480 if (cdai->bufsiz == 0)
2483 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2485 if (device->rcap_buf == NULL) {
2486 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2490 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2492 cdai->provsiz = device->rcap_len;
2493 if (device->rcap_len == 0)
2495 amt = device->rcap_len;
2496 if (cdai->provsiz > cdai->bufsiz)
2498 memcpy(cdai->buf, device->rcap_buf, amt);
2504 start_ccb->ccb_h.status = CAM_REQ_CMP;
2506 if (cdai->flags & CDAI_FLAG_STORE) {
2509 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
2511 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
2512 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2513 (void *)(uintptr_t)cdai->buftype);
2515 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
2520 scsi_action(union ccb *start_ccb)
2523 switch (start_ccb->ccb_h.func_code) {
2524 case XPT_SET_TRAN_SETTINGS:
2526 scsi_set_transfer_settings(&start_ccb->cts,
2527 start_ccb->ccb_h.path->device,
2528 /*async_update*/FALSE);
2533 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2536 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2537 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2540 case XPT_GET_TRAN_SETTINGS:
2542 struct cam_sim *sim;
2544 sim = start_ccb->ccb_h.path->bus->sim;
2545 (*(sim->sim_action))(sim, start_ccb);
2548 case XPT_DEV_ADVINFO:
2550 scsi_dev_advinfo(start_ccb);
2554 xpt_action_default(start_ccb);
2560 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2563 struct ccb_pathinq cpi;
2564 struct ccb_trans_settings cur_cts;
2565 struct ccb_trans_settings_scsi *scsi;
2566 struct ccb_trans_settings_scsi *cur_scsi;
2567 struct cam_sim *sim;
2568 struct scsi_inquiry_data *inq_data;
2570 if (device == NULL) {
2571 cts->ccb_h.status = CAM_PATH_INVALID;
2572 xpt_done((union ccb *)cts);
2576 if (cts->protocol == PROTO_UNKNOWN
2577 || cts->protocol == PROTO_UNSPECIFIED) {
2578 cts->protocol = device->protocol;
2579 cts->protocol_version = device->protocol_version;
2582 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2583 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2584 cts->protocol_version = device->protocol_version;
2586 if (cts->protocol != device->protocol) {
2587 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2588 cts->protocol, device->protocol);
2589 cts->protocol = device->protocol;
2592 if (cts->protocol_version > device->protocol_version) {
2594 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2595 "Version from %d to %d?\n", cts->protocol_version,
2596 device->protocol_version);
2598 cts->protocol_version = device->protocol_version;
2601 if (cts->transport == XPORT_UNKNOWN
2602 || cts->transport == XPORT_UNSPECIFIED) {
2603 cts->transport = device->transport;
2604 cts->transport_version = device->transport_version;
2607 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2608 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2609 cts->transport_version = device->transport_version;
2611 if (cts->transport != device->transport) {
2612 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2613 cts->transport, device->transport);
2614 cts->transport = device->transport;
2617 if (cts->transport_version > device->transport_version) {
2619 xpt_print(cts->ccb_h.path, "Down reving Transport "
2620 "Version from %d to %d?\n", cts->transport_version,
2621 device->transport_version);
2623 cts->transport_version = device->transport_version;
2626 sim = cts->ccb_h.path->bus->sim;
2629 * Nothing more of interest to do unless
2630 * this is a device connected via the
2633 if (cts->protocol != PROTO_SCSI) {
2634 if (async_update == FALSE)
2635 (*(sim->sim_action))(sim, (union ccb *)cts);
2639 inq_data = &device->inq_data;
2640 scsi = &cts->proto_specific.scsi;
2641 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2642 cpi.ccb_h.func_code = XPT_PATH_INQ;
2643 xpt_action((union ccb *)&cpi);
2645 /* SCSI specific sanity checking */
2646 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2647 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2648 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2649 || (device->mintags == 0)) {
2651 * Can't tag on hardware that doesn't support tags,
2652 * doesn't have it enabled, or has broken tag support.
2654 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2657 if (async_update == FALSE) {
2659 * Perform sanity checking against what the
2660 * controller and device can do.
2662 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2663 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2664 cur_cts.type = cts->type;
2665 xpt_action((union ccb *)&cur_cts);
2666 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2669 cur_scsi = &cur_cts.proto_specific.scsi;
2670 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2671 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2672 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2674 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2675 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2678 /* SPI specific sanity checking */
2679 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2681 struct ccb_trans_settings_spi *spi;
2682 struct ccb_trans_settings_spi *cur_spi;
2684 spi = &cts->xport_specific.spi;
2686 cur_spi = &cur_cts.xport_specific.spi;
2688 /* Fill in any gaps in what the user gave us */
2689 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2690 spi->sync_period = cur_spi->sync_period;
2691 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2692 spi->sync_period = 0;
2693 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2694 spi->sync_offset = cur_spi->sync_offset;
2695 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2696 spi->sync_offset = 0;
2697 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2698 spi->ppr_options = cur_spi->ppr_options;
2699 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2700 spi->ppr_options = 0;
2701 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2702 spi->bus_width = cur_spi->bus_width;
2703 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2705 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2706 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2707 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2709 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2710 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2711 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2712 && (inq_data->flags & SID_Sync) == 0
2713 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2714 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2716 spi->sync_period = 0;
2717 spi->sync_offset = 0;
2720 switch (spi->bus_width) {
2721 case MSG_EXT_WDTR_BUS_32_BIT:
2722 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2723 || (inq_data->flags & SID_WBus32) != 0
2724 || cts->type == CTS_TYPE_USER_SETTINGS)
2725 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2727 /* Fall Through to 16-bit */
2728 case MSG_EXT_WDTR_BUS_16_BIT:
2729 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2730 || (inq_data->flags & SID_WBus16) != 0
2731 || cts->type == CTS_TYPE_USER_SETTINGS)
2732 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2733 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2736 /* Fall Through to 8-bit */
2737 default: /* New bus width?? */
2738 case MSG_EXT_WDTR_BUS_8_BIT:
2739 /* All targets can do this */
2740 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2744 spi3caps = cpi.xport_specific.spi.ppr_options;
2745 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2746 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2747 spi3caps &= inq_data->spi3data;
2749 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2750 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2752 if ((spi3caps & SID_SPI_IUS) == 0)
2753 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2755 if ((spi3caps & SID_SPI_QAS) == 0)
2756 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2758 /* No SPI Transfer settings are allowed unless we are wide */
2759 if (spi->bus_width == 0)
2760 spi->ppr_options = 0;
2762 if ((spi->valid & CTS_SPI_VALID_DISC)
2763 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2765 * Can't tag queue without disconnection.
2767 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2768 scsi->valid |= CTS_SCSI_VALID_TQ;
2772 * If we are currently performing tagged transactions to
2773 * this device and want to change its negotiation parameters,
2774 * go non-tagged for a bit to give the controller a chance to
2775 * negotiate unhampered by tag messages.
2777 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2778 && (device->inq_flags & SID_CmdQue) != 0
2779 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2780 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2781 CTS_SPI_VALID_SYNC_OFFSET|
2782 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2783 scsi_toggle_tags(cts->ccb_h.path);
2786 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2787 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2791 * If we are transitioning from tags to no-tags or
2792 * vice-versa, we need to carefully freeze and restart
2793 * the queue so that we don't overlap tagged and non-tagged
2794 * commands. We also temporarily stop tags if there is
2795 * a change in transfer negotiation settings to allow
2796 * "tag-less" negotiation.
2798 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2799 || (device->inq_flags & SID_CmdQue) != 0)
2800 device_tagenb = TRUE;
2802 device_tagenb = FALSE;
2804 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2805 && device_tagenb == FALSE)
2806 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2807 && device_tagenb == TRUE)) {
2809 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2811 * Delay change to use tags until after a
2812 * few commands have gone to this device so
2813 * the controller has time to perform transfer
2814 * negotiations without tagged messages getting
2817 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2818 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2820 xpt_stop_tags(cts->ccb_h.path);
2824 if (async_update == FALSE)
2825 (*(sim->sim_action))(sim, (union ccb *)cts);
2829 scsi_toggle_tags(struct cam_path *path)
2834 * Give controllers a chance to renegotiate
2835 * before starting tag operations. We
2836 * "toggle" tagged queuing off then on
2837 * which causes the tag enable command delay
2838 * counter to come into effect.
2841 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2842 || ((dev->inq_flags & SID_CmdQue) != 0
2843 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2844 struct ccb_trans_settings cts;
2846 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2847 cts.protocol = PROTO_SCSI;
2848 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2849 cts.transport = XPORT_UNSPECIFIED;
2850 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2851 cts.proto_specific.scsi.flags = 0;
2852 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2853 scsi_set_transfer_settings(&cts, path->device,
2854 /*async_update*/TRUE);
2855 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2856 scsi_set_transfer_settings(&cts, path->device,
2857 /*async_update*/TRUE);
2862 * Handle any per-device event notifications that require action by the XPT.
2865 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2866 struct cam_ed *device, void *async_arg)
2869 struct cam_path newpath;
2872 * We only need to handle events for real devices.
2874 if (target->target_id == CAM_TARGET_WILDCARD
2875 || device->lun_id == CAM_LUN_WILDCARD)
2879 * We need our own path with wildcards expanded to
2880 * handle certain types of events.
2882 if ((async_code == AC_SENT_BDR)
2883 || (async_code == AC_BUS_RESET)
2884 || (async_code == AC_INQ_CHANGED))
2885 status = xpt_compile_path(&newpath, NULL,
2890 status = CAM_REQ_CMP_ERR;
2892 if (status == CAM_REQ_CMP) {
2895 * Allow transfer negotiation to occur in a
2896 * tag free environment and after settle delay.
2898 if (async_code == AC_SENT_BDR
2899 || async_code == AC_BUS_RESET) {
2900 cam_freeze_devq(&newpath);
2901 cam_release_devq(&newpath,
2902 RELSIM_RELEASE_AFTER_TIMEOUT,
2904 /*timeout*/scsi_delay,
2905 /*getcount_only*/0);
2906 scsi_toggle_tags(&newpath);
2909 if (async_code == AC_INQ_CHANGED) {
2911 * We've sent a start unit command, or
2912 * something similar to a device that
2913 * may have caused its inquiry data to
2914 * change. So we re-scan the device to
2915 * refresh the inquiry data for it.
2917 scsi_scan_lun(newpath.periph, &newpath,
2918 CAM_EXPECT_INQ_CHANGE, NULL);
2920 xpt_release_path(&newpath);
2921 } else if (async_code == AC_LOST_DEVICE &&
2922 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2923 device->flags |= CAM_DEV_UNCONFIGURED;
2924 xpt_release_device(device);
2925 } else if (async_code == AC_TRANSFER_NEG) {
2926 struct ccb_trans_settings *settings;
2928 settings = (struct ccb_trans_settings *)async_arg;
2929 scsi_set_transfer_settings(settings, device,
2930 /*async_update*/TRUE);
2935 scsi_announce_periph(struct cam_periph *periph)
2937 struct ccb_pathinq cpi;
2938 struct ccb_trans_settings cts;
2939 struct cam_path *path = periph->path;
2944 mtx_assert(periph->sim->mtx, MA_OWNED);
2946 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2947 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2948 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2949 xpt_action((union ccb*)&cts);
2950 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2952 /* Ask the SIM for its base transfer speed */
2953 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2954 cpi.ccb_h.func_code = XPT_PATH_INQ;
2955 xpt_action((union ccb *)&cpi);
2956 /* Report connection speed */
2957 speed = cpi.base_transfer_speed;
2959 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2960 struct ccb_trans_settings_spi *spi =
2961 &cts.xport_specific.spi;
2963 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2964 && spi->sync_offset != 0) {
2965 freq = scsi_calc_syncsrate(spi->sync_period);
2968 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2969 speed *= (0x01 << spi->bus_width);
2971 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2972 struct ccb_trans_settings_fc *fc =
2973 &cts.xport_specific.fc;
2975 if (fc->valid & CTS_FC_VALID_SPEED)
2976 speed = fc->bitrate;
2978 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2979 struct ccb_trans_settings_sas *sas =
2980 &cts.xport_specific.sas;
2982 if (sas->valid & CTS_SAS_VALID_SPEED)
2983 speed = sas->bitrate;
2987 printf("%s%d: %d.%03dMB/s transfers",
2988 periph->periph_name, periph->unit_number,
2991 printf("%s%d: %dKB/s transfers", periph->periph_name,
2992 periph->unit_number, speed);
2993 /* Report additional information about SPI connections */
2994 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2995 struct ccb_trans_settings_spi *spi;
2997 spi = &cts.xport_specific.spi;
2999 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3001 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3005 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3006 && spi->bus_width > 0) {
3012 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3013 } else if (freq != 0) {
3017 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3018 struct ccb_trans_settings_fc *fc;
3020 fc = &cts.xport_specific.fc;
3021 if (fc->valid & CTS_FC_VALID_WWNN)
3022 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3023 if (fc->valid & CTS_FC_VALID_WWPN)
3024 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3025 if (fc->valid & CTS_FC_VALID_PORT)
3026 printf(" PortID 0x%x", fc->port);