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,
147 static char *probe_action_text[] = {
150 "PROBE_FULL_INQUIRY",
153 "PROBE_SUPPORTED_VPD_LIST",
156 "PROBE_TUR_FOR_NEGOTIATION",
157 "PROBE_INQUIRY_BASIC_DV1",
158 "PROBE_INQUIRY_BASIC_DV2",
163 #define PROBE_SET_ACTION(softc, newaction) \
166 text = probe_action_text; \
167 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \
168 ("Probe %s to %s\n", text[(softc)->action], \
169 text[(newaction)])); \
170 (softc)->action = (newaction); \
174 PROBE_INQUIRY_CKSUM = 0x01,
175 PROBE_SERIAL_CKSUM = 0x02,
176 PROBE_NO_ANNOUNCE = 0x04
180 TAILQ_HEAD(, ccb_hdr) request_ccbs;
186 struct cam_periph *periph;
189 static const char quantum[] = "QUANTUM";
190 static const char sony[] = "SONY";
191 static const char west_digital[] = "WDIGTL";
192 static const char samsung[] = "SAMSUNG";
193 static const char seagate[] = "SEAGATE";
194 static const char microp[] = "MICROP";
196 static struct scsi_quirk_entry scsi_quirk_table[] =
199 /* Reports QUEUE FULL for temporary resource shortages */
200 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
201 /*quirks*/0, /*mintags*/24, /*maxtags*/32
204 /* Reports QUEUE FULL for temporary resource shortages */
205 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
206 /*quirks*/0, /*mintags*/24, /*maxtags*/32
209 /* Reports QUEUE FULL for temporary resource shortages */
210 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
211 /*quirks*/0, /*mintags*/24, /*maxtags*/32
214 /* Broken tagged queuing drive */
215 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
216 /*quirks*/0, /*mintags*/0, /*maxtags*/0
219 /* Broken tagged queuing drive */
220 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
221 /*quirks*/0, /*mintags*/0, /*maxtags*/0
224 /* Broken tagged queuing drive */
225 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
226 /*quirks*/0, /*mintags*/0, /*maxtags*/0
230 * Unfortunately, the Quantum Atlas III has the same
231 * problem as the Atlas II drives above.
232 * Reported by: "Johan Granlund" <johan@granlund.nu>
234 * For future reference, the drive with the problem was:
235 * QUANTUM QM39100TD-SW N1B0
237 * It's possible that Quantum will fix the problem in later
238 * firmware revisions. If that happens, the quirk entry
239 * will need to be made specific to the firmware revisions
243 /* Reports QUEUE FULL for temporary resource shortages */
244 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
245 /*quirks*/0, /*mintags*/24, /*maxtags*/32
249 * 18 Gig Atlas III, same problem as the 9G version.
250 * Reported by: Andre Albsmeier
251 * <andre.albsmeier@mchp.siemens.de>
253 * For future reference, the drive with the problem was:
254 * QUANTUM QM318000TD-S N491
256 /* Reports QUEUE FULL for temporary resource shortages */
257 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
258 /*quirks*/0, /*mintags*/24, /*maxtags*/32
262 * Broken tagged queuing drive
263 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
264 * and: Martin Renters <martin@tdc.on.ca>
266 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
267 /*quirks*/0, /*mintags*/0, /*maxtags*/0
270 * The Seagate Medalist Pro drives have very poor write
271 * performance with anything more than 2 tags.
273 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
274 * Drive: <SEAGATE ST36530N 1444>
276 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
277 * Drive: <SEAGATE ST34520W 1281>
279 * No one has actually reported that the 9G version
280 * (ST39140*) of the Medalist Pro has the same problem, but
281 * we're assuming that it does because the 4G and 6.5G
282 * versions of the drive are broken.
285 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
286 /*quirks*/0, /*mintags*/2, /*maxtags*/2
289 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
290 /*quirks*/0, /*mintags*/2, /*maxtags*/2
293 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
294 /*quirks*/0, /*mintags*/2, /*maxtags*/2
298 * Slow when tagged queueing is enabled. Write performance
299 * steadily drops off with more and more concurrent
300 * transactions. Best sequential write performance with
301 * tagged queueing turned off and write caching turned on.
304 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
305 * Drive: DCAS-34330 w/ "S65A" firmware.
307 * The drive with the problem had the "S65A" firmware
308 * revision, and has also been reported (by Stephen J.
309 * Roznowski <sjr@home.net>) for a drive with the "S61A"
312 * Although no one has reported problems with the 2 gig
313 * version of the DCAS drive, the assumption is that it
314 * has the same problems as the 4 gig version. Therefore
315 * this quirk entries disables tagged queueing for all
318 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
319 /*quirks*/0, /*mintags*/0, /*maxtags*/0
322 /* Broken tagged queuing drive */
323 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
324 /*quirks*/0, /*mintags*/0, /*maxtags*/0
327 /* Broken tagged queuing drive */
328 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
329 /*quirks*/0, /*mintags*/0, /*maxtags*/0
332 /* This does not support other than LUN 0 */
333 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
334 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
338 * Broken tagged queuing drive.
340 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
343 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
344 /*quirks*/0, /*mintags*/0, /*maxtags*/0
348 * Slow when tagged queueing is enabled. (1.5MB/sec versus
350 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
351 * Best performance with these drives is achieved with
352 * tagged queueing turned off, and write caching turned on.
354 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
355 /*quirks*/0, /*mintags*/0, /*maxtags*/0
359 * Slow when tagged queueing is enabled. (1.5MB/sec versus
361 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
362 * Best performance with these drives is achieved with
363 * tagged queueing turned off, and write caching turned on.
365 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
366 /*quirks*/0, /*mintags*/0, /*maxtags*/0
370 * Doesn't handle queue full condition correctly,
371 * so we need to limit maxtags to what the device
372 * can handle instead of determining this automatically.
374 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
375 /*quirks*/0, /*mintags*/2, /*maxtags*/32
378 /* Really only one LUN */
379 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
380 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
383 /* I can't believe we need a quirk for DPT volumes. */
384 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
386 /*mintags*/0, /*maxtags*/255
390 * Many Sony CDROM drives don't like multi-LUN probing.
392 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
393 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
397 * This drive doesn't like multiple LUN probing.
398 * Submitted by: Parag Patel <parag@cgt.com>
400 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
401 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
404 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
405 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
409 * The 8200 doesn't like multi-lun probing, and probably
410 * don't like serial number requests either.
413 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
416 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
420 * Let's try the same as above, but for a drive that says
421 * it's an IPL-6860 but is actually an EXB 8200.
424 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
427 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
431 * These Hitachi drives don't like multi-lun probing.
432 * The PR submitter has a DK319H, but says that the Linux
433 * kernel has a similar work-around for the DK312 and DK314,
434 * so all DK31* drives are quirked here.
436 * Submitted by: Paul Haddad <paul@pth.com>
438 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
439 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
443 * The Hitachi CJ series with J8A8 firmware apparantly has
444 * problems with tagged commands.
446 * Reported by: amagai@nue.org
448 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
449 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
453 * These are the large storage arrays.
454 * Submitted by: William Carrel <william.carrel@infospace.com>
456 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
457 CAM_QUIRK_HILUNS, 2, 1024
461 * This old revision of the TDC3600 is also SCSI-1, and
462 * hangs upon serial number probing.
465 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
468 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
472 * Would repond to all LUNs if asked for.
475 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
478 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
482 * Would repond to all LUNs if asked for.
485 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
488 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
491 /* Submitted by: Matthew Dodd <winter@jurai.net> */
492 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
493 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
496 /* Submitted by: Matthew Dodd <winter@jurai.net> */
497 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
501 /* TeraSolutions special settings for TRC-22 RAID */
502 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
503 /*quirks*/0, /*mintags*/55, /*maxtags*/255
506 /* Veritas Storage Appliance */
507 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
508 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
512 * Would respond to all LUNs. Device type and removable
513 * flag are jumper-selectable.
515 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
518 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
521 /* EasyRAID E5A aka. areca ARC-6010 */
522 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
523 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
526 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
527 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
530 /* Default tagged queuing parameters for all devices */
532 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
533 /*vendor*/"*", /*product*/"*", /*revision*/"*"
535 /*quirks*/0, /*mintags*/2, /*maxtags*/255
539 static const int scsi_quirk_table_size =
540 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
542 static cam_status proberegister(struct cam_periph *periph,
544 static void probeschedule(struct cam_periph *probe_periph);
545 static int device_has_vpd(struct cam_ed *device, uint8_t page_id);
546 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
547 static void proberequestdefaultnegotiation(struct cam_periph *periph);
548 static int proberequestbackoff(struct cam_periph *periph,
549 struct cam_ed *device);
550 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
551 static int probe_strange_rpl_data(struct scsi_report_luns_data *rp,
553 static void probe_purge_old(struct cam_path *path,
554 struct scsi_report_luns_data *new);
555 static void probecleanup(struct cam_periph *periph);
556 static void scsi_find_quirk(struct cam_ed *device);
557 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
558 static void scsi_scan_lun(struct cam_periph *periph,
559 struct cam_path *path, cam_flags flags,
561 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
562 static struct cam_ed *
563 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
565 static void scsi_devise_transport(struct cam_path *path);
566 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
567 struct cam_ed *device,
569 static void scsi_toggle_tags(struct cam_path *path);
570 static void scsi_dev_async(u_int32_t async_code,
572 struct cam_et *target,
573 struct cam_ed *device,
575 static void scsi_action(union ccb *start_ccb);
576 static void scsi_announce_periph(struct cam_periph *periph);
578 static struct xpt_xport scsi_xport = {
579 .alloc_device = scsi_alloc_device,
580 .action = scsi_action,
581 .async = scsi_dev_async,
582 .announce = scsi_announce_periph,
588 return (&scsi_xport);
597 proberegister(struct cam_periph *periph, void *arg)
599 union ccb *request_ccb; /* CCB representing the probe request */
603 request_ccb = (union ccb *)arg;
604 if (periph == NULL) {
605 printf("proberegister: periph was NULL!!\n");
606 return(CAM_REQ_CMP_ERR);
609 if (request_ccb == NULL) {
610 printf("proberegister: no probe CCB, "
611 "can't register device\n");
612 return(CAM_REQ_CMP_ERR);
615 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
618 printf("proberegister: Unable to probe new device. "
619 "Unable to allocate softc\n");
620 return(CAM_REQ_CMP_ERR);
622 TAILQ_INIT(&softc->request_ccbs);
623 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
626 periph->softc = softc;
627 softc->periph = periph;
628 softc->action = PROBE_INVALID;
629 status = cam_periph_acquire(periph);
630 if (status != CAM_REQ_CMP) {
636 * Ensure we've waited at least a bus settle
637 * delay before attempting to probe the device.
638 * For HBAs that don't do bus resets, this won't make a difference.
640 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
643 * Ensure nobody slip in until probe finish.
645 cam_freeze_devq_arg(periph->path,
646 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
647 probeschedule(periph);
652 probeschedule(struct cam_periph *periph)
654 struct ccb_pathinq cpi;
658 softc = (probe_softc *)periph->softc;
659 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
661 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
662 cpi.ccb_h.func_code = XPT_PATH_INQ;
663 xpt_action((union ccb *)&cpi);
666 * If a device has gone away and another device, or the same one,
667 * is back in the same place, it should have a unit attention
668 * condition pending. It will not report the unit attention in
669 * response to an inquiry, which may leave invalid transfer
670 * negotiations in effect. The TUR will reveal the unit attention
671 * condition. Only send the TUR for lun 0, since some devices
672 * will get confused by commands other than inquiry to non-existent
673 * luns. If you think a device has gone away start your scan from
674 * lun 0. This will insure that any bogus transfer settings are
677 * If we haven't seen the device before and the controller supports
678 * some kind of transfer negotiation, negotiate with the first
679 * sent command if no bus reset was performed at startup. This
680 * ensures that the device is not confused by transfer negotiation
681 * settings left over by loader or BIOS action.
683 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
684 && (ccb->ccb_h.target_lun == 0)) {
685 PROBE_SET_ACTION(softc, PROBE_TUR);
686 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
687 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
688 proberequestdefaultnegotiation(periph);
689 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
691 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
694 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
695 softc->flags |= PROBE_NO_ANNOUNCE;
697 softc->flags &= ~PROBE_NO_ANNOUNCE;
699 xpt_schedule(periph, CAM_PRIORITY_XPT);
703 device_has_vpd(struct cam_ed *device, uint8_t page_id)
706 struct scsi_vpd_supported_pages *vpds;
708 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
709 num_pages = device->supported_vpds_len - SVPD_SUPPORTED_PAGES_HDR_LEN;
710 for (i = 0;i < num_pages;i++)
711 if (vpds->page_list[i] == page_id)
718 probestart(struct cam_periph *periph, union ccb *start_ccb)
720 /* Probe the device that our peripheral driver points to */
721 struct ccb_scsiio *csio;
724 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
726 softc = (probe_softc *)periph->softc;
727 csio = &start_ccb->csio;
730 switch (softc->action) {
732 case PROBE_TUR_FOR_NEGOTIATION:
735 scsi_test_unit_ready(csio,
744 case PROBE_FULL_INQUIRY:
745 case PROBE_INQUIRY_BASIC_DV1:
746 case PROBE_INQUIRY_BASIC_DV2:
749 struct scsi_inquiry_data *inq_buf;
751 inq_buf = &periph->path->device->inq_data;
754 * If the device is currently configured, we calculate an
755 * MD5 checksum of the inquiry data, and if the serial number
756 * length is greater than 0, add the serial number data
757 * into the checksum as well. Once the inquiry and the
758 * serial number check finish, we attempt to figure out
759 * whether we still have the same device.
761 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
763 MD5Init(&softc->context);
764 MD5Update(&softc->context, (unsigned char *)inq_buf,
765 sizeof(struct scsi_inquiry_data));
766 softc->flags |= PROBE_INQUIRY_CKSUM;
767 if (periph->path->device->serial_num_len > 0) {
768 MD5Update(&softc->context,
769 periph->path->device->serial_num,
770 periph->path->device->serial_num_len);
771 softc->flags |= PROBE_SERIAL_CKSUM;
773 MD5Final(softc->digest, &softc->context);
776 if (softc->action == PROBE_INQUIRY)
777 inquiry_len = SHORT_INQUIRY_LENGTH;
779 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
782 * Some parallel SCSI devices fail to send an
783 * ignore wide residue message when dealing with
784 * odd length inquiry requests. Round up to be
787 inquiry_len = roundup2(inquiry_len, 2);
789 if (softc->action == PROBE_INQUIRY_BASIC_DV1
790 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
791 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
793 if (inq_buf == NULL) {
794 xpt_print(periph->path, "malloc failure- skipping Basic"
795 "Domain Validation\n");
796 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
797 scsi_test_unit_ready(csio,
814 /*timeout*/60 * 1000);
817 case PROBE_REPORT_LUNS:
821 rp = malloc(periph->path->target->rpl_size,
822 M_CAMXPT, M_NOWAIT | M_ZERO);
824 struct scsi_inquiry_data *inq_buf;
825 inq_buf = &periph->path->device->inq_data;
826 xpt_print(periph->path,
827 "Unable to alloc report luns storage\n");
828 if (INQ_DATA_TQ_ENABLED(inq_buf))
829 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
831 PROBE_SET_ACTION(softc,
832 PROBE_SUPPORTED_VPD_LIST);
835 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
836 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
837 SSD_FULL_SIZE, 60000); break;
840 case PROBE_MODE_SENSE:
845 mode_buf_len = sizeof(struct scsi_mode_header_6)
846 + sizeof(struct scsi_mode_blk_desc)
847 + sizeof(struct scsi_control_page);
848 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
849 if (mode_buf != NULL) {
850 scsi_mode_sense(csio,
855 SMS_PAGE_CTRL_CURRENT,
856 SMS_CONTROL_MODE_PAGE,
863 xpt_print(periph->path, "Unable to mode sense control page - "
865 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
868 case PROBE_SUPPORTED_VPD_LIST:
870 struct scsi_vpd_supported_page_list *vpd_list;
871 struct cam_ed *device;
874 device = periph->path->device;
876 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
877 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
880 if (vpd_list != NULL) {
885 (u_int8_t *)vpd_list,
888 SVPD_SUPPORTED_PAGE_LIST,
890 /*timeout*/60 * 1000);
894 * We'll have to do without, let our probedone
895 * routine finish up for us.
897 start_ccb->csio.data_ptr = NULL;
898 probedone(periph, start_ccb);
901 case PROBE_DEVICE_ID:
903 struct scsi_vpd_device_id *devid;
904 struct cam_ed *device;
907 device = periph->path->device;
908 if (device_has_vpd(device, SVPD_DEVICE_ID))
909 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
918 SVPD_DEVICE_ID_MAX_SIZE,
922 /*timeout*/60 * 1000);
926 * We'll have to do without, let our probedone
927 * routine finish up for us.
929 start_ccb->csio.data_ptr = NULL;
930 probedone(periph, start_ccb);
933 case PROBE_SERIAL_NUM:
935 struct scsi_vpd_unit_serial_number *serial_buf;
936 struct cam_ed* device;
939 device = periph->path->device;
940 if (device->serial_num != NULL) {
941 free(device->serial_num, M_CAMXPT);
942 device->serial_num = NULL;
943 device->serial_num_len = 0;
946 if (device_has_vpd(device, SVPD_UNIT_SERIAL_NUMBER))
947 serial_buf = (struct scsi_vpd_unit_serial_number *)
948 malloc(sizeof(*serial_buf), M_CAMXPT,
951 if (serial_buf != NULL) {
956 (u_int8_t *)serial_buf,
959 SVPD_UNIT_SERIAL_NUMBER,
961 /*timeout*/60 * 1000);
965 * We'll have to do without, let our probedone
966 * routine finish up for us.
968 start_ccb->csio.data_ptr = NULL;
969 probedone(periph, start_ccb);
973 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_INFO,
974 ("probestart: invalid action state\n"));
978 xpt_action(start_ccb);
982 proberequestdefaultnegotiation(struct cam_periph *periph)
984 struct ccb_trans_settings cts;
986 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
987 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
988 cts.type = CTS_TYPE_USER_SETTINGS;
989 xpt_action((union ccb *)&cts);
990 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
993 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
994 cts.type = CTS_TYPE_CURRENT_SETTINGS;
995 xpt_action((union ccb *)&cts);
999 * Backoff Negotiation Code- only pertinent for SPI devices.
1002 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1004 struct ccb_trans_settings cts;
1005 struct ccb_trans_settings_spi *spi;
1007 memset(&cts, 0, sizeof (cts));
1008 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1009 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1010 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1011 xpt_action((union ccb *)&cts);
1012 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1014 xpt_print(periph->path,
1015 "failed to get current device settings\n");
1019 if (cts.transport != XPORT_SPI) {
1021 xpt_print(periph->path, "not SPI transport\n");
1025 spi = &cts.xport_specific.spi;
1028 * We cannot renegotiate sync rate if we don't have one.
1030 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1032 xpt_print(periph->path, "no sync rate known\n");
1038 * We'll assert that we don't have to touch PPR options- the
1039 * SIM will see what we do with period and offset and adjust
1040 * the PPR options as appropriate.
1044 * A sync rate with unknown or zero offset is nonsensical.
1045 * A sync period of zero means Async.
1047 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1048 || spi->sync_offset == 0 || spi->sync_period == 0) {
1050 xpt_print(periph->path, "no sync rate available\n");
1055 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1056 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1057 ("hit async: giving up on DV\n"));
1063 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1064 * We don't try to remember 'last' settings to see if the SIM actually
1065 * gets into the speed we want to set. We check on the SIM telling
1066 * us that a requested speed is bad, but otherwise don't try and
1067 * check the speed due to the asynchronous and handshake nature
1070 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1073 if (spi->sync_period >= 0xf) {
1074 spi->sync_period = 0;
1075 spi->sync_offset = 0;
1076 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1077 ("setting to async for DV\n"));
1079 * Once we hit async, we don't want to try
1080 * any more settings.
1082 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1083 } else if (bootverbose) {
1084 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1085 ("DV: period 0x%x\n", spi->sync_period));
1086 printf("setting period to 0x%x\n", spi->sync_period);
1088 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1089 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1090 xpt_action((union ccb *)&cts);
1091 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1094 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1095 ("DV: failed to set period 0x%x\n", spi->sync_period));
1096 if (spi->sync_period == 0) {
1103 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1106 probedone(struct cam_periph *periph, union ccb *done_ccb)
1109 struct cam_path *path;
1112 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1114 softc = (probe_softc *)periph->softc;
1115 path = done_ccb->ccb_h.path;
1116 priority = done_ccb->ccb_h.pinfo.priority;
1118 switch (softc->action) {
1121 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1123 if (cam_periph_error(done_ccb, 0,
1124 SF_NO_PRINT, NULL) == ERESTART)
1126 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1127 /* Don't wedge the queue */
1128 xpt_release_devq(done_ccb->ccb_h.path,
1132 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1133 xpt_release_ccb(done_ccb);
1134 xpt_schedule(periph, priority);
1138 case PROBE_FULL_INQUIRY:
1140 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1141 struct scsi_inquiry_data *inq_buf;
1142 u_int8_t periph_qual;
1144 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1145 inq_buf = &path->device->inq_data;
1147 periph_qual = SID_QUAL(inq_buf);
1149 if (periph_qual == SID_QUAL_LU_CONNECTED) {
1153 * We conservatively request only
1154 * SHORT_INQUIRY_LEN bytes of inquiry
1155 * information during our first try
1156 * at sending an INQUIRY. If the device
1157 * has more information to give,
1158 * perform a second request specifying
1159 * the amount of information the device
1160 * is willing to give.
1162 len = inq_buf->additional_length
1163 + offsetof(struct scsi_inquiry_data,
1164 additional_length) + 1;
1165 if (softc->action == PROBE_INQUIRY
1166 && len > SHORT_INQUIRY_LENGTH) {
1167 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1168 xpt_release_ccb(done_ccb);
1169 xpt_schedule(periph, priority);
1173 scsi_find_quirk(path->device);
1175 scsi_devise_transport(path);
1177 if (path->device->lun_id == 0 &&
1178 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1179 (SCSI_QUIRK(path->device)->quirks &
1180 CAM_QUIRK_NORPTLUNS) == 0) {
1181 PROBE_SET_ACTION(softc,
1184 * Start with room for *one* lun.
1186 periph->path->target->rpl_size = 16;
1187 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1188 PROBE_SET_ACTION(softc,
1191 PROBE_SET_ACTION(softc,
1192 PROBE_SUPPORTED_VPD_LIST);
1194 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1195 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1196 xpt_acquire_device(path->device);
1198 xpt_release_ccb(done_ccb);
1199 xpt_schedule(periph, priority);
1201 } else if (path->device->lun_id == 0 &&
1202 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1203 (SCSI_QUIRK(path->device)->quirks &
1204 CAM_QUIRK_NORPTLUNS) == 0) {
1205 if (path->device->flags &
1206 CAM_DEV_UNCONFIGURED) {
1207 path->device->flags &=
1208 ~CAM_DEV_UNCONFIGURED;
1209 xpt_acquire_device(path->device);
1211 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1212 periph->path->target->rpl_size = 16;
1213 xpt_release_ccb(done_ccb);
1214 xpt_schedule(periph, priority);
1217 } else if (cam_periph_error(done_ccb, 0,
1218 done_ccb->ccb_h.target_lun > 0
1219 ? SF_RETRY_UA|SF_QUIET_IR
1221 &softc->saved_ccb) == ERESTART) {
1223 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1224 /* Don't wedge the queue */
1225 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1229 * If we get to this point, we got an error status back
1230 * from the inquiry and the error status doesn't require
1231 * automatically retrying the command. Therefore, the
1232 * inquiry failed. If we had inquiry information before
1233 * for this device, but this latest inquiry command failed,
1234 * the device has probably gone away. If this device isn't
1235 * already marked unconfigured, notify the peripheral
1236 * drivers that this device is no more.
1238 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1239 /* Send the async notification. */
1240 xpt_async(AC_LOST_DEVICE, path, NULL);
1242 xpt_release_ccb(done_ccb);
1245 case PROBE_REPORT_LUNS:
1247 struct ccb_scsiio *csio;
1248 struct scsi_report_luns_data *lp;
1251 csio = &done_ccb->csio;
1253 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1254 nlun = scsi_4btoul(lp->length) / 8;
1255 maxlun = (csio->dxfer_len / 8) - 1;
1257 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1258 if (cam_periph_error(done_ccb, 0,
1259 done_ccb->ccb_h.target_lun > 0 ?
1260 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1261 &softc->saved_ccb) == ERESTART) {
1264 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1265 xpt_release_devq(done_ccb->ccb_h.path, 1,
1270 } else if (nlun > maxlun) {
1272 * Reallocate and retry to cover all luns
1274 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, path,
1275 ("reallocating REPORT_LUNS for %u luns\n", nlun));
1277 path->target->rpl_size = (nlun << 3) + 8;
1278 xpt_release_ccb(done_ccb);
1279 xpt_schedule(periph, priority);
1281 } else if (nlun == 0) {
1283 * If there don't appear to be any luns, bail.
1287 } else if (probe_strange_rpl_data(lp, maxlun)) {
1289 * If we can't understand the lun format
1290 * of any entry, bail.
1298 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, path,
1299 ("%u luns reported\n", nlun));
1301 CAM_GET_SIMPLE_LUN(lp, 0, lun);
1303 * If the first lun is not lun 0, then either there
1304 * is no lun 0 in the list, or the list is unsorted.
1307 for (idx = 0; idx < nlun; idx++) {
1308 CAM_GET_SIMPLE_LUN(lp, idx, lun);
1316 lp->luns[0].lundata, 8);
1317 memcpy(lp->luns[0].lundata,
1318 lp->luns[idx].lundata, 8);
1319 memcpy(lp->luns[idx].lundata,
1321 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
1322 path, ("lun 0 in position %u\n", idx));
1325 * There is no lun 0 in our list. Destroy
1326 * the validity of the inquiry data so we
1327 * bail here and now.
1329 path->device->flags &=
1330 ~CAM_DEV_INQUIRY_DATA_VALID;
1334 * If we have an old lun list, We can either
1335 * retest luns that appear to have been dropped,
1336 * or just nuke them. We'll opt for the latter.
1337 * This function will also install the new list
1338 * in the target structure.
1340 probe_purge_old(path, lp);
1343 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
1344 struct scsi_inquiry_data *inq_buf;
1345 inq_buf = &path->device->inq_data;
1346 if (INQ_DATA_TQ_ENABLED(inq_buf))
1347 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1349 PROBE_SET_ACTION(softc,
1350 PROBE_SUPPORTED_VPD_LIST);
1351 xpt_release_ccb(done_ccb);
1352 xpt_schedule(periph, priority);
1360 case PROBE_MODE_SENSE:
1362 struct ccb_scsiio *csio;
1363 struct scsi_mode_header_6 *mode_hdr;
1365 csio = &done_ccb->csio;
1366 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1367 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1368 struct scsi_control_page *page;
1371 offset = ((u_int8_t *)&mode_hdr[1])
1372 + mode_hdr->blk_desc_len;
1373 page = (struct scsi_control_page *)offset;
1374 path->device->queue_flags = page->queue_flags;
1375 } else if (cam_periph_error(done_ccb, 0,
1376 SF_RETRY_UA|SF_NO_PRINT,
1377 &softc->saved_ccb) == ERESTART) {
1379 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1380 /* Don't wedge the queue */
1381 xpt_release_devq(done_ccb->ccb_h.path,
1382 /*count*/1, /*run_queue*/TRUE);
1384 xpt_release_ccb(done_ccb);
1385 free(mode_hdr, M_CAMXPT);
1386 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1387 xpt_schedule(periph, priority);
1390 case PROBE_SUPPORTED_VPD_LIST:
1392 struct ccb_scsiio *csio;
1393 struct scsi_vpd_supported_page_list *page_list;
1395 csio = &done_ccb->csio;
1397 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1399 if (path->device->supported_vpds != NULL) {
1400 free(path->device->supported_vpds, M_CAMXPT);
1401 path->device->supported_vpds = NULL;
1402 path->device->supported_vpds_len = 0;
1405 if (page_list == NULL) {
1407 * Don't process the command as it was never sent
1409 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1411 path->device->supported_vpds_len = page_list->length +
1412 SVPD_SUPPORTED_PAGES_HDR_LEN;
1413 path->device->supported_vpds = (uint8_t *)page_list;
1414 xpt_release_ccb(done_ccb);
1415 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1416 xpt_schedule(periph, priority);
1418 } else if (cam_periph_error(done_ccb, 0,
1419 SF_RETRY_UA|SF_NO_PRINT,
1420 &softc->saved_ccb) == ERESTART) {
1422 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1423 /* Don't wedge the queue */
1424 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1429 free(page_list, M_CAMXPT);
1430 /* No VPDs available, skip to device check. */
1431 csio->data_ptr = NULL;
1432 goto probe_device_check;
1434 case PROBE_DEVICE_ID:
1436 struct scsi_vpd_device_id *devid;
1437 struct ccb_scsiio *csio;
1438 uint32_t length = 0;
1440 csio = &done_ccb->csio;
1441 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1443 /* Clean up from previous instance of this device */
1444 if (path->device->device_id != NULL) {
1445 path->device->device_id_len = 0;
1446 free(path->device->device_id, M_CAMXPT);
1447 path->device->device_id = NULL;
1450 if (devid == NULL) {
1451 /* Don't process the command as it was never sent */
1452 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1453 length = scsi_2btoul(devid->length);
1456 * NB: device_id_len is actual response
1457 * size, not buffer size.
1459 path->device->device_id_len = length +
1460 SVPD_DEVICE_ID_HDR_LEN;
1461 path->device->device_id = (uint8_t *)devid;
1463 } else if (cam_periph_error(done_ccb, 0,
1465 &softc->saved_ccb) == ERESTART) {
1467 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1468 /* Don't wedge the queue */
1469 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1473 /* Free the device id space if we don't use it */
1474 if (devid && length == 0)
1475 free(devid, M_CAMXPT);
1476 xpt_release_ccb(done_ccb);
1477 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1478 xpt_schedule(periph, priority);
1483 case PROBE_SERIAL_NUM:
1485 struct ccb_scsiio *csio;
1486 struct scsi_vpd_unit_serial_number *serial_buf;
1493 csio = &done_ccb->csio;
1494 priority = done_ccb->ccb_h.pinfo.priority;
1496 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1498 if (serial_buf == NULL) {
1500 * Don't process the command as it was never sent
1502 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
1503 && (serial_buf->length > 0)) {
1506 path->device->serial_num =
1507 (u_int8_t *)malloc((serial_buf->length + 1),
1508 M_CAMXPT, M_NOWAIT);
1509 if (path->device->serial_num != NULL) {
1510 memcpy(path->device->serial_num,
1511 serial_buf->serial_num,
1512 serial_buf->length);
1513 path->device->serial_num_len =
1515 path->device->serial_num[serial_buf->length]
1518 } else if (cam_periph_error(done_ccb, 0,
1519 SF_RETRY_UA|SF_NO_PRINT,
1520 &softc->saved_ccb) == ERESTART) {
1522 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1523 /* Don't wedge the queue */
1524 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1529 * Let's see if we have seen this device before.
1531 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1533 u_int8_t digest[16];
1538 (unsigned char *)&path->device->inq_data,
1539 sizeof(struct scsi_inquiry_data));
1542 MD5Update(&context, serial_buf->serial_num,
1543 serial_buf->length);
1545 MD5Final(digest, &context);
1546 if (bcmp(softc->digest, digest, 16) == 0)
1550 * XXX Do we need to do a TUR in order to ensure
1551 * that the device really hasn't changed???
1554 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1555 xpt_async(AC_LOST_DEVICE, path, NULL);
1557 if (serial_buf != NULL)
1558 free(serial_buf, M_CAMXPT);
1562 * Now that we have all the necessary
1563 * information to safely perform transfer
1564 * negotiations... Controllers don't perform
1565 * any negotiation or tagged queuing until
1566 * after the first XPT_SET_TRAN_SETTINGS ccb is
1567 * received. So, on a new device, just retrieve
1568 * the user settings, and set them as the current
1569 * settings to set the device up.
1571 proberequestdefaultnegotiation(periph);
1572 xpt_release_ccb(done_ccb);
1575 * Perform a TUR to allow the controller to
1576 * perform any necessary transfer negotiation.
1578 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1579 xpt_schedule(periph, priority);
1582 xpt_release_ccb(done_ccb);
1585 case PROBE_TUR_FOR_NEGOTIATION:
1586 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1588 if (cam_periph_error(done_ccb, 0, SF_RETRY_UA,
1594 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1595 /* Don't wedge the queue */
1596 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1600 * Do Domain Validation for lun 0 on devices that claim
1601 * to support Synchronous Transfer modes.
1603 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1604 && done_ccb->ccb_h.target_lun == 0
1605 && (path->device->inq_data.flags & SID_Sync) != 0
1606 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1607 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1608 ("Begin Domain Validation\n"));
1609 path->device->flags |= CAM_DEV_IN_DV;
1610 xpt_release_ccb(done_ccb);
1611 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1612 xpt_schedule(periph, priority);
1615 if (softc->action == PROBE_DV_EXIT) {
1616 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1617 ("Leave Domain Validation\n"));
1619 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1620 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1621 xpt_acquire_device(path->device);
1623 path->device->flags &=
1624 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1625 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1626 /* Inform the XPT that a new device has been found */
1627 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1628 xpt_action(done_ccb);
1629 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1632 xpt_release_ccb(done_ccb);
1634 case PROBE_INQUIRY_BASIC_DV1:
1635 case PROBE_INQUIRY_BASIC_DV2:
1637 struct scsi_inquiry_data *nbuf;
1638 struct ccb_scsiio *csio;
1640 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1641 /* Don't wedge the queue */
1642 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1645 csio = &done_ccb->csio;
1646 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1647 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1649 "inquiry data fails comparison at DV%d step\n",
1650 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1651 if (proberequestbackoff(periph, path->device)) {
1652 path->device->flags &= ~CAM_DEV_IN_DV;
1653 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1656 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1658 free(nbuf, M_CAMXPT);
1659 xpt_release_ccb(done_ccb);
1660 xpt_schedule(periph, priority);
1663 free(nbuf, M_CAMXPT);
1664 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1665 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1666 xpt_release_ccb(done_ccb);
1667 xpt_schedule(periph, priority);
1670 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1671 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
1672 ("Leave Domain Validation Successfully\n"));
1674 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1675 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1676 xpt_acquire_device(path->device);
1678 path->device->flags &=
1679 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1680 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1681 /* Inform the XPT that a new device has been found */
1682 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1683 xpt_action(done_ccb);
1684 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1687 xpt_release_ccb(done_ccb);
1691 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO,
1692 ("probedone: invalid action state\n"));
1696 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1697 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1698 done_ccb->ccb_h.status = CAM_REQ_CMP;
1700 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1701 cam_release_devq(periph->path,
1702 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1703 cam_periph_invalidate(periph);
1704 cam_periph_release_locked(periph);
1706 probeschedule(periph);
1711 probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
1714 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
1716 for (idx = 0; idx < nlun; idx++) {
1717 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
1725 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
1727 struct cam_path *tp;
1728 struct scsi_report_luns_data *old;
1729 u_int idx1, idx2, nlun_old, nlun_new, this_lun;
1732 if (path->target == NULL) {
1735 if (path->target->luns == NULL) {
1736 path->target->luns = new;
1739 old = path->target->luns;
1740 nlun_old = scsi_4btoul(old->length) / 8;
1741 nlun_new = scsi_4btoul(new->length) / 8;
1744 * We are not going to assume sorted lists. Deal.
1746 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1747 ol = old->luns[idx1].lundata;
1748 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1749 nl = new->luns[idx2].lundata;
1750 if (memcmp(nl, ol, 8) == 0) {
1754 if (idx2 < nlun_new) {
1758 * An 'old' item not in the 'new' list.
1759 * Nuke it. Except that if it is lun 0,
1760 * that would be what the probe state
1761 * machine is currently working on,
1762 * so we won't do that.
1764 * We also cannot nuke it if it is
1765 * not in a lun format we understand.
1767 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
1770 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1771 if (this_lun == 0) {
1774 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1775 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1776 xpt_async(AC_LOST_DEVICE, tp, NULL);
1780 free(old, M_CAMXPT);
1781 path->target->luns = new;
1785 probecleanup(struct cam_periph *periph)
1787 free(periph->softc, M_CAMXPT);
1791 scsi_find_quirk(struct cam_ed *device)
1793 struct scsi_quirk_entry *quirk;
1796 match = cam_quirkmatch((caddr_t)&device->inq_data,
1797 (caddr_t)scsi_quirk_table,
1798 sizeof(scsi_quirk_table) /
1799 sizeof(*scsi_quirk_table),
1800 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1803 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1805 quirk = (struct scsi_quirk_entry *)match;
1806 device->quirk = quirk;
1807 device->mintags = quirk->mintags;
1808 device->maxtags = quirk->maxtags;
1812 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1817 error = sysctl_handle_int(oidp, &bool, 0, req);
1818 if (error != 0 || req->newptr == NULL)
1820 if (bool == 0 || bool == 1) {
1829 union ccb *request_ccb;
1830 struct ccb_pathinq *cpi;
1833 } scsi_scan_bus_info;
1836 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1837 * As the scan progresses, scsi_scan_bus is used as the
1838 * callback on completion function.
1841 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1843 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1844 ("scsi_scan_bus\n"));
1845 switch (request_ccb->ccb_h.func_code) {
1849 scsi_scan_bus_info *scan_info;
1850 union ccb *work_ccb, *reset_ccb;
1851 struct cam_path *path;
1853 u_int low_target, max_target;
1856 /* Find out the characteristics of the bus */
1857 work_ccb = xpt_alloc_ccb_nowait();
1858 if (work_ccb == NULL) {
1859 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1860 xpt_done(request_ccb);
1863 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1864 request_ccb->ccb_h.pinfo.priority);
1865 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1866 xpt_action(work_ccb);
1867 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1868 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1869 xpt_free_ccb(work_ccb);
1870 xpt_done(request_ccb);
1874 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1876 * Can't scan the bus on an adapter that
1877 * cannot perform the initiator role.
1879 request_ccb->ccb_h.status = CAM_REQ_CMP;
1880 xpt_free_ccb(work_ccb);
1881 xpt_done(request_ccb);
1885 /* We may need to reset bus first, if we haven't done it yet. */
1886 if ((work_ccb->cpi.hba_inquiry &
1887 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1888 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1889 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1890 reset_ccb = xpt_alloc_ccb_nowait();
1891 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1893 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1894 xpt_action(reset_ccb);
1895 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1896 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1897 xpt_free_ccb(reset_ccb);
1898 xpt_free_ccb(work_ccb);
1899 xpt_done(request_ccb);
1902 xpt_free_ccb(reset_ccb);
1905 /* Save some state for use while we probe for devices */
1906 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1907 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1908 if (scan_info == NULL) {
1909 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1910 xpt_done(request_ccb);
1913 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE, request_ccb->ccb_h.path,
1914 ("SCAN start for %p\n", scan_info));
1915 scan_info->request_ccb = request_ccb;
1916 scan_info->cpi = &work_ccb->cpi;
1918 /* Cache on our stack so we can work asynchronously */
1919 max_target = scan_info->cpi->max_target;
1921 initiator_id = scan_info->cpi->initiator_id;
1925 * We can scan all targets in parallel, or do it sequentially.
1928 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1929 max_target = low_target = request_ccb->ccb_h.target_id;
1930 scan_info->counter = 0;
1931 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1933 scan_info->counter = 0;
1935 scan_info->counter = scan_info->cpi->max_target + 1;
1936 if (scan_info->cpi->initiator_id < scan_info->counter) {
1937 scan_info->counter--;
1941 for (i = low_target; i <= max_target; i++) {
1943 if (i == initiator_id)
1946 status = xpt_create_path(&path, xpt_periph,
1947 request_ccb->ccb_h.path_id,
1949 if (status != CAM_REQ_CMP) {
1950 printf("scsi_scan_bus: xpt_create_path failed"
1951 " with status %#x, bus scan halted\n",
1953 free(scan_info, M_CAMXPT);
1954 request_ccb->ccb_h.status = status;
1955 xpt_free_ccb(work_ccb);
1956 xpt_done(request_ccb);
1959 work_ccb = xpt_alloc_ccb_nowait();
1960 if (work_ccb == NULL) {
1961 xpt_free_ccb((union ccb *)scan_info->cpi);
1962 free(scan_info, M_CAMXPT);
1963 xpt_free_path(path);
1964 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1965 xpt_done(request_ccb);
1968 xpt_setup_ccb(&work_ccb->ccb_h, path,
1969 request_ccb->ccb_h.pinfo.priority);
1970 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1971 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
1972 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1973 work_ccb->crcn.flags = request_ccb->crcn.flags;
1974 xpt_action(work_ccb);
1981 struct cam_path *path, *oldpath;
1982 scsi_scan_bus_info *scan_info;
1983 struct cam_et *target;
1984 struct cam_ed *device;
1987 target_id_t target_id;
1990 oldpath = request_ccb->ccb_h.path;
1992 status = request_ccb->ccb_h.status & CAM_STATUS_MASK;
1993 /* Reuse the same CCB to query if a device was really found */
1994 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
1995 xpt_setup_ccb(&request_ccb->ccb_h, request_ccb->ccb_h.path,
1996 request_ccb->ccb_h.pinfo.priority);
1997 request_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
2000 path_id = request_ccb->ccb_h.path_id;
2001 target_id = request_ccb->ccb_h.target_id;
2002 lun_id = request_ccb->ccb_h.target_lun;
2003 xpt_action(request_ccb);
2005 target = request_ccb->ccb_h.path->target;
2010 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2013 * Make sure we skip over lun 0 if it's the first member
2014 * of the list as we've actually just finished probing
2017 CAM_GET_SIMPLE_LUN(target->luns, 0, first);
2018 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2019 scan_info->lunindex[target_id]++;
2022 if (scan_info->lunindex[target_id] < nluns) {
2023 CAM_GET_SIMPLE_LUN(target->luns,
2024 scan_info->lunindex[target_id], lun_id);
2026 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
2027 request_ccb->ccb_h.path,
2028 ("next lun to try at index %u is %u\n",
2029 scan_info->lunindex[target_id], lun_id));
2030 scan_info->lunindex[target_id]++;
2033 * We're done with scanning all luns.
2035 * Nuke the bogus device for lun 0 if lun 0
2036 * wasn't on the list.
2039 TAILQ_FOREACH(device,
2040 &target->ed_entries, links) {
2041 if (device->lun_id == 0) {
2046 xpt_release_device(device);
2050 } else if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
2054 * If we already probed lun 0 successfully, or
2055 * we have additional configured luns on this
2056 * target that might have "gone away", go onto
2060 * We may touch devices that we don't
2061 * hold references too, so ensure they
2062 * don't disappear out from under us.
2063 * The target above is referenced by the
2064 * path in the request ccb.
2067 device = TAILQ_FIRST(&target->ed_entries);
2068 if (device != NULL) {
2069 phl = CAN_SRCH_HI_SPARSE(device);
2070 if (device->lun_id == 0)
2071 device = TAILQ_NEXT(device, links);
2073 if ((lun_id != 0) || (device != NULL)) {
2074 if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl) {
2079 if (lun_id == request_ccb->ccb_h.target_lun
2080 || lun_id > scan_info->cpi->max_lun)
2084 device = request_ccb->ccb_h.path->device;
2086 if ((SCSI_QUIRK(device)->quirks &
2087 CAM_QUIRK_NOLUNS) == 0) {
2088 /* Try the next lun */
2089 if (lun_id < (CAM_SCSI2_MAXLUN-1)
2090 || CAN_SRCH_HI_DENSE(device)) {
2095 if (lun_id == request_ccb->ccb_h.target_lun
2096 || lun_id > scan_info->cpi->max_lun)
2101 * Check to see if we scan any further luns.
2107 * Free the current request path- we're done with it.
2109 xpt_free_path(oldpath);
2112 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2114 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2115 scan_info->counter++;
2116 if (scan_info->counter ==
2117 scan_info->cpi->initiator_id) {
2118 scan_info->counter++;
2120 if (scan_info->counter >=
2121 scan_info->cpi->max_target+1) {
2125 scan_info->counter--;
2126 if (scan_info->counter == 0) {
2131 xpt_free_ccb(request_ccb);
2132 xpt_free_ccb((union ccb *)scan_info->cpi);
2133 request_ccb = scan_info->request_ccb;
2134 CAM_DEBUG_PATH_PRINT(CAM_DEBUG_PROBE,
2135 request_ccb->ccb_h.path,
2136 ("SCAN done for %p\n", scan_info));
2137 free(scan_info, M_CAMXPT);
2138 request_ccb->ccb_h.status = CAM_REQ_CMP;
2139 xpt_done(request_ccb);
2143 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2144 xpt_free_ccb(request_ccb);
2147 status = xpt_create_path(&path, xpt_periph,
2148 scan_info->request_ccb->ccb_h.path_id,
2149 scan_info->counter, 0);
2150 if (status != CAM_REQ_CMP) {
2151 printf("scsi_scan_bus: xpt_create_path failed"
2152 " with status %#x, bus scan halted\n",
2154 xpt_free_ccb(request_ccb);
2155 xpt_free_ccb((union ccb *)scan_info->cpi);
2156 request_ccb = scan_info->request_ccb;
2157 free(scan_info, M_CAMXPT);
2158 request_ccb->ccb_h.status = status;
2159 xpt_done(request_ccb);
2162 xpt_setup_ccb(&request_ccb->ccb_h, path,
2163 request_ccb->ccb_h.pinfo.priority);
2164 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2165 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2166 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2167 request_ccb->crcn.flags =
2168 scan_info->request_ccb->crcn.flags;
2170 status = xpt_create_path(&path, xpt_periph,
2171 path_id, target_id, lun_id);
2173 * Free the old request path- we're done with it. We
2174 * do this *after* creating the new path so that
2175 * we don't remove a target that has our lun list
2176 * in the case that lun 0 is not present.
2178 xpt_free_path(oldpath);
2179 if (status != CAM_REQ_CMP) {
2180 printf("scsi_scan_bus: xpt_create_path failed "
2181 "with status %#x, halting LUN scan\n",
2185 xpt_setup_ccb(&request_ccb->ccb_h, path,
2186 request_ccb->ccb_h.pinfo.priority);
2187 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2188 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2189 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2190 request_ccb->crcn.flags =
2191 scan_info->request_ccb->crcn.flags;
2193 xpt_action(request_ccb);
2202 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2203 cam_flags flags, union ccb *request_ccb)
2205 struct ccb_pathinq cpi;
2207 struct cam_path *new_path;
2208 struct cam_periph *old_periph;
2210 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2212 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2213 cpi.ccb_h.func_code = XPT_PATH_INQ;
2214 xpt_action((union ccb *)&cpi);
2216 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2217 if (request_ccb != NULL) {
2218 request_ccb->ccb_h.status = cpi.ccb_h.status;
2219 xpt_done(request_ccb);
2224 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2226 * Can't scan the bus on an adapter that
2227 * cannot perform the initiator role.
2229 if (request_ccb != NULL) {
2230 request_ccb->ccb_h.status = CAM_REQ_CMP;
2231 xpt_done(request_ccb);
2236 if (request_ccb == NULL) {
2237 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
2238 if (request_ccb == NULL) {
2239 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2240 "can't continue\n");
2243 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
2244 if (new_path == NULL) {
2245 xpt_print(path, "scsi_scan_lun: can't allocate path, "
2246 "can't continue\n");
2247 free(request_ccb, M_CAMXPT);
2250 status = xpt_compile_path(new_path, xpt_periph,
2252 path->target->target_id,
2253 path->device->lun_id);
2255 if (status != CAM_REQ_CMP) {
2256 xpt_print(path, "scsi_scan_lun: can't compile path, "
2257 "can't continue\n");
2258 free(request_ccb, M_CAMXPT);
2259 free(new_path, M_CAMXPT);
2262 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2263 request_ccb->ccb_h.cbfcnp = xptscandone;
2264 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2265 request_ccb->crcn.flags = flags;
2268 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2271 softc = (probe_softc *)old_periph->softc;
2272 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
2275 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2276 probestart, "probe",
2278 request_ccb->ccb_h.path, NULL, 0,
2281 if (status != CAM_REQ_CMP) {
2282 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2283 "returned an error, can't continue probe\n");
2284 request_ccb->ccb_h.status = status;
2285 xpt_done(request_ccb);
2291 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2293 xpt_release_path(done_ccb->ccb_h.path);
2294 free(done_ccb->ccb_h.path, M_CAMXPT);
2295 free(done_ccb, M_CAMXPT);
2298 static struct cam_ed *
2299 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2301 struct cam_path path;
2302 struct scsi_quirk_entry *quirk;
2303 struct cam_ed *device;
2304 struct cam_ed *cur_device;
2306 device = xpt_alloc_device(bus, target, lun_id);
2311 * Take the default quirk entry until we have inquiry
2312 * data and can determine a better quirk to use.
2314 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2315 device->quirk = (void *)quirk;
2316 device->mintags = quirk->mintags;
2317 device->maxtags = quirk->maxtags;
2318 bzero(&device->inq_data, sizeof(device->inq_data));
2319 device->inq_flags = 0;
2320 device->queue_flags = 0;
2321 device->serial_num = NULL;
2322 device->serial_num_len = 0;
2323 device->device_id = NULL;
2324 device->device_id_len = 0;
2325 device->supported_vpds = NULL;
2326 device->supported_vpds_len = 0;
2329 * XXX should be limited by number of CCBs this bus can
2332 bus->sim->max_ccbs += device->ccbq.devq_openings;
2333 /* Insertion sort into our target's device list */
2334 cur_device = TAILQ_FIRST(&target->ed_entries);
2335 while (cur_device != NULL && cur_device->lun_id < lun_id)
2336 cur_device = TAILQ_NEXT(cur_device, links);
2337 if (cur_device != NULL) {
2338 TAILQ_INSERT_BEFORE(cur_device, device, links);
2340 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
2342 target->generation++;
2343 if (lun_id != CAM_LUN_WILDCARD) {
2344 xpt_compile_path(&path,
2349 scsi_devise_transport(&path);
2350 xpt_release_path(&path);
2357 scsi_devise_transport(struct cam_path *path)
2359 struct ccb_pathinq cpi;
2360 struct ccb_trans_settings cts;
2361 struct scsi_inquiry_data *inq_buf;
2363 /* Get transport information from the SIM */
2364 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2365 cpi.ccb_h.func_code = XPT_PATH_INQ;
2366 xpt_action((union ccb *)&cpi);
2369 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2370 inq_buf = &path->device->inq_data;
2371 path->device->protocol = PROTO_SCSI;
2372 path->device->protocol_version =
2373 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2374 path->device->transport = cpi.transport;
2375 path->device->transport_version = cpi.transport_version;
2378 * Any device not using SPI3 features should
2379 * be considered SPI2 or lower.
2381 if (inq_buf != NULL) {
2382 if (path->device->transport == XPORT_SPI
2383 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2384 && path->device->transport_version > 2)
2385 path->device->transport_version = 2;
2387 struct cam_ed* otherdev;
2389 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2391 otherdev = TAILQ_NEXT(otherdev, links)) {
2392 if (otherdev != path->device)
2396 if (otherdev != NULL) {
2398 * Initially assume the same versioning as
2399 * prior luns for this target.
2401 path->device->protocol_version =
2402 otherdev->protocol_version;
2403 path->device->transport_version =
2404 otherdev->transport_version;
2406 /* Until we know better, opt for safty */
2407 path->device->protocol_version = 2;
2408 if (path->device->transport == XPORT_SPI)
2409 path->device->transport_version = 2;
2411 path->device->transport_version = 0;
2417 * For a device compliant with SPC-2 we should be able
2418 * to determine the transport version supported by
2419 * scrutinizing the version descriptors in the
2423 /* Tell the controller what we think */
2424 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2425 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2426 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2427 cts.transport = path->device->transport;
2428 cts.transport_version = path->device->transport_version;
2429 cts.protocol = path->device->protocol;
2430 cts.protocol_version = path->device->protocol_version;
2431 cts.proto_specific.valid = 0;
2432 cts.xport_specific.valid = 0;
2433 xpt_action((union ccb *)&cts);
2437 scsi_dev_advinfo(union ccb *start_ccb)
2439 struct cam_ed *device;
2440 struct ccb_dev_advinfo *cdai;
2443 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2444 device = start_ccb->ccb_h.path->device;
2445 cdai = &start_ccb->cdai;
2446 switch(cdai->buftype) {
2447 case CDAI_TYPE_SCSI_DEVID:
2448 if (cdai->flags & CDAI_FLAG_STORE)
2450 cdai->provsiz = device->device_id_len;
2451 if (device->device_id_len == 0)
2453 amt = device->device_id_len;
2454 if (cdai->provsiz > cdai->bufsiz)
2456 memcpy(cdai->buf, device->device_id, amt);
2458 case CDAI_TYPE_SERIAL_NUM:
2459 if (cdai->flags & CDAI_FLAG_STORE)
2461 cdai->provsiz = device->serial_num_len;
2462 if (device->serial_num_len == 0)
2464 amt = device->serial_num_len;
2465 if (cdai->provsiz > cdai->bufsiz)
2467 memcpy(cdai->buf, device->serial_num, amt);
2469 case CDAI_TYPE_PHYS_PATH:
2470 if (cdai->flags & CDAI_FLAG_STORE) {
2471 if (device->physpath != NULL)
2472 free(device->physpath, M_CAMXPT);
2473 device->physpath_len = cdai->bufsiz;
2474 /* Clear existing buffer if zero length */
2475 if (cdai->bufsiz == 0)
2477 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2478 if (device->physpath == NULL) {
2479 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2482 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2484 cdai->provsiz = device->physpath_len;
2485 if (device->physpath_len == 0)
2487 amt = device->physpath_len;
2488 if (cdai->provsiz > cdai->bufsiz)
2490 memcpy(cdai->buf, device->physpath, amt);
2496 start_ccb->ccb_h.status = CAM_REQ_CMP;
2498 if (cdai->flags & CDAI_FLAG_STORE) {
2501 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
2503 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
2504 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2505 (void *)(uintptr_t)cdai->buftype);
2507 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
2512 scsi_action(union ccb *start_ccb)
2515 switch (start_ccb->ccb_h.func_code) {
2516 case XPT_SET_TRAN_SETTINGS:
2518 scsi_set_transfer_settings(&start_ccb->cts,
2519 start_ccb->ccb_h.path->device,
2520 /*async_update*/FALSE);
2525 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2528 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2529 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2532 case XPT_GET_TRAN_SETTINGS:
2534 struct cam_sim *sim;
2536 sim = start_ccb->ccb_h.path->bus->sim;
2537 (*(sim->sim_action))(sim, start_ccb);
2540 case XPT_DEV_ADVINFO:
2542 scsi_dev_advinfo(start_ccb);
2546 xpt_action_default(start_ccb);
2552 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
2555 struct ccb_pathinq cpi;
2556 struct ccb_trans_settings cur_cts;
2557 struct ccb_trans_settings_scsi *scsi;
2558 struct ccb_trans_settings_scsi *cur_scsi;
2559 struct cam_sim *sim;
2560 struct scsi_inquiry_data *inq_data;
2562 if (device == NULL) {
2563 cts->ccb_h.status = CAM_PATH_INVALID;
2564 xpt_done((union ccb *)cts);
2568 if (cts->protocol == PROTO_UNKNOWN
2569 || cts->protocol == PROTO_UNSPECIFIED) {
2570 cts->protocol = device->protocol;
2571 cts->protocol_version = device->protocol_version;
2574 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2575 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2576 cts->protocol_version = device->protocol_version;
2578 if (cts->protocol != device->protocol) {
2579 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
2580 cts->protocol, device->protocol);
2581 cts->protocol = device->protocol;
2584 if (cts->protocol_version > device->protocol_version) {
2586 xpt_print(cts->ccb_h.path, "Down reving Protocol "
2587 "Version from %d to %d?\n", cts->protocol_version,
2588 device->protocol_version);
2590 cts->protocol_version = device->protocol_version;
2593 if (cts->transport == XPORT_UNKNOWN
2594 || cts->transport == XPORT_UNSPECIFIED) {
2595 cts->transport = device->transport;
2596 cts->transport_version = device->transport_version;
2599 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2600 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2601 cts->transport_version = device->transport_version;
2603 if (cts->transport != device->transport) {
2604 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
2605 cts->transport, device->transport);
2606 cts->transport = device->transport;
2609 if (cts->transport_version > device->transport_version) {
2611 xpt_print(cts->ccb_h.path, "Down reving Transport "
2612 "Version from %d to %d?\n", cts->transport_version,
2613 device->transport_version);
2615 cts->transport_version = device->transport_version;
2618 sim = cts->ccb_h.path->bus->sim;
2621 * Nothing more of interest to do unless
2622 * this is a device connected via the
2625 if (cts->protocol != PROTO_SCSI) {
2626 if (async_update == FALSE)
2627 (*(sim->sim_action))(sim, (union ccb *)cts);
2631 inq_data = &device->inq_data;
2632 scsi = &cts->proto_specific.scsi;
2633 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2634 cpi.ccb_h.func_code = XPT_PATH_INQ;
2635 xpt_action((union ccb *)&cpi);
2637 /* SCSI specific sanity checking */
2638 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2639 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2640 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2641 || (device->mintags == 0)) {
2643 * Can't tag on hardware that doesn't support tags,
2644 * doesn't have it enabled, or has broken tag support.
2646 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2649 if (async_update == FALSE) {
2651 * Perform sanity checking against what the
2652 * controller and device can do.
2654 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
2655 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2656 cur_cts.type = cts->type;
2657 xpt_action((union ccb *)&cur_cts);
2658 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2661 cur_scsi = &cur_cts.proto_specific.scsi;
2662 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2663 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2664 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2666 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2667 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2670 /* SPI specific sanity checking */
2671 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2673 struct ccb_trans_settings_spi *spi;
2674 struct ccb_trans_settings_spi *cur_spi;
2676 spi = &cts->xport_specific.spi;
2678 cur_spi = &cur_cts.xport_specific.spi;
2680 /* Fill in any gaps in what the user gave us */
2681 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2682 spi->sync_period = cur_spi->sync_period;
2683 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2684 spi->sync_period = 0;
2685 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2686 spi->sync_offset = cur_spi->sync_offset;
2687 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2688 spi->sync_offset = 0;
2689 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2690 spi->ppr_options = cur_spi->ppr_options;
2691 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2692 spi->ppr_options = 0;
2693 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2694 spi->bus_width = cur_spi->bus_width;
2695 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2697 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2698 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2699 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2701 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2702 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2703 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2704 && (inq_data->flags & SID_Sync) == 0
2705 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2706 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2708 spi->sync_period = 0;
2709 spi->sync_offset = 0;
2712 switch (spi->bus_width) {
2713 case MSG_EXT_WDTR_BUS_32_BIT:
2714 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2715 || (inq_data->flags & SID_WBus32) != 0
2716 || cts->type == CTS_TYPE_USER_SETTINGS)
2717 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2719 /* Fall Through to 16-bit */
2720 case MSG_EXT_WDTR_BUS_16_BIT:
2721 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2722 || (inq_data->flags & SID_WBus16) != 0
2723 || cts->type == CTS_TYPE_USER_SETTINGS)
2724 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2725 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2728 /* Fall Through to 8-bit */
2729 default: /* New bus width?? */
2730 case MSG_EXT_WDTR_BUS_8_BIT:
2731 /* All targets can do this */
2732 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2736 spi3caps = cpi.xport_specific.spi.ppr_options;
2737 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2738 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2739 spi3caps &= inq_data->spi3data;
2741 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2742 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2744 if ((spi3caps & SID_SPI_IUS) == 0)
2745 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2747 if ((spi3caps & SID_SPI_QAS) == 0)
2748 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2750 /* No SPI Transfer settings are allowed unless we are wide */
2751 if (spi->bus_width == 0)
2752 spi->ppr_options = 0;
2754 if ((spi->valid & CTS_SPI_VALID_DISC)
2755 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2757 * Can't tag queue without disconnection.
2759 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2760 scsi->valid |= CTS_SCSI_VALID_TQ;
2764 * If we are currently performing tagged transactions to
2765 * this device and want to change its negotiation parameters,
2766 * go non-tagged for a bit to give the controller a chance to
2767 * negotiate unhampered by tag messages.
2769 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2770 && (device->inq_flags & SID_CmdQue) != 0
2771 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2772 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2773 CTS_SPI_VALID_SYNC_OFFSET|
2774 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2775 scsi_toggle_tags(cts->ccb_h.path);
2778 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2779 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2783 * If we are transitioning from tags to no-tags or
2784 * vice-versa, we need to carefully freeze and restart
2785 * the queue so that we don't overlap tagged and non-tagged
2786 * commands. We also temporarily stop tags if there is
2787 * a change in transfer negotiation settings to allow
2788 * "tag-less" negotiation.
2790 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2791 || (device->inq_flags & SID_CmdQue) != 0)
2792 device_tagenb = TRUE;
2794 device_tagenb = FALSE;
2796 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2797 && device_tagenb == FALSE)
2798 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2799 && device_tagenb == TRUE)) {
2801 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2803 * Delay change to use tags until after a
2804 * few commands have gone to this device so
2805 * the controller has time to perform transfer
2806 * negotiations without tagged messages getting
2809 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2810 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2812 xpt_stop_tags(cts->ccb_h.path);
2816 if (async_update == FALSE)
2817 (*(sim->sim_action))(sim, (union ccb *)cts);
2821 scsi_toggle_tags(struct cam_path *path)
2826 * Give controllers a chance to renegotiate
2827 * before starting tag operations. We
2828 * "toggle" tagged queuing off then on
2829 * which causes the tag enable command delay
2830 * counter to come into effect.
2833 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2834 || ((dev->inq_flags & SID_CmdQue) != 0
2835 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2836 struct ccb_trans_settings cts;
2838 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2839 cts.protocol = PROTO_SCSI;
2840 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2841 cts.transport = XPORT_UNSPECIFIED;
2842 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2843 cts.proto_specific.scsi.flags = 0;
2844 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2845 scsi_set_transfer_settings(&cts, path->device,
2846 /*async_update*/TRUE);
2847 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2848 scsi_set_transfer_settings(&cts, path->device,
2849 /*async_update*/TRUE);
2854 * Handle any per-device event notifications that require action by the XPT.
2857 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2858 struct cam_ed *device, void *async_arg)
2861 struct cam_path newpath;
2864 * We only need to handle events for real devices.
2866 if (target->target_id == CAM_TARGET_WILDCARD
2867 || device->lun_id == CAM_LUN_WILDCARD)
2871 * We need our own path with wildcards expanded to
2872 * handle certain types of events.
2874 if ((async_code == AC_SENT_BDR)
2875 || (async_code == AC_BUS_RESET)
2876 || (async_code == AC_INQ_CHANGED))
2877 status = xpt_compile_path(&newpath, NULL,
2882 status = CAM_REQ_CMP_ERR;
2884 if (status == CAM_REQ_CMP) {
2887 * Allow transfer negotiation to occur in a
2888 * tag free environment and after settle delay.
2890 if (async_code == AC_SENT_BDR
2891 || async_code == AC_BUS_RESET) {
2892 cam_freeze_devq(&newpath);
2893 cam_release_devq(&newpath,
2894 RELSIM_RELEASE_AFTER_TIMEOUT,
2896 /*timeout*/scsi_delay,
2897 /*getcount_only*/0);
2898 scsi_toggle_tags(&newpath);
2901 if (async_code == AC_INQ_CHANGED) {
2903 * We've sent a start unit command, or
2904 * something similar to a device that
2905 * may have caused its inquiry data to
2906 * change. So we re-scan the device to
2907 * refresh the inquiry data for it.
2909 scsi_scan_lun(newpath.periph, &newpath,
2910 CAM_EXPECT_INQ_CHANGE, NULL);
2912 xpt_release_path(&newpath);
2913 } else if (async_code == AC_LOST_DEVICE &&
2914 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2915 device->flags |= CAM_DEV_UNCONFIGURED;
2916 xpt_release_device(device);
2917 } else if (async_code == AC_TRANSFER_NEG) {
2918 struct ccb_trans_settings *settings;
2920 settings = (struct ccb_trans_settings *)async_arg;
2921 scsi_set_transfer_settings(settings, device,
2922 /*async_update*/TRUE);
2927 scsi_announce_periph(struct cam_periph *periph)
2929 struct ccb_pathinq cpi;
2930 struct ccb_trans_settings cts;
2931 struct cam_path *path = periph->path;
2936 mtx_assert(periph->sim->mtx, MA_OWNED);
2938 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2939 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2940 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2941 xpt_action((union ccb*)&cts);
2942 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2944 /* Ask the SIM for its base transfer speed */
2945 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2946 cpi.ccb_h.func_code = XPT_PATH_INQ;
2947 xpt_action((union ccb *)&cpi);
2948 /* Report connection speed */
2949 speed = cpi.base_transfer_speed;
2951 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2952 struct ccb_trans_settings_spi *spi =
2953 &cts.xport_specific.spi;
2955 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
2956 && spi->sync_offset != 0) {
2957 freq = scsi_calc_syncsrate(spi->sync_period);
2960 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
2961 speed *= (0x01 << spi->bus_width);
2963 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
2964 struct ccb_trans_settings_fc *fc =
2965 &cts.xport_specific.fc;
2967 if (fc->valid & CTS_FC_VALID_SPEED)
2968 speed = fc->bitrate;
2970 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
2971 struct ccb_trans_settings_sas *sas =
2972 &cts.xport_specific.sas;
2974 if (sas->valid & CTS_SAS_VALID_SPEED)
2975 speed = sas->bitrate;
2979 printf("%s%d: %d.%03dMB/s transfers",
2980 periph->periph_name, periph->unit_number,
2983 printf("%s%d: %dKB/s transfers", periph->periph_name,
2984 periph->unit_number, speed);
2985 /* Report additional information about SPI connections */
2986 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
2987 struct ccb_trans_settings_spi *spi;
2989 spi = &cts.xport_specific.spi;
2991 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
2993 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
2997 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
2998 && spi->bus_width > 0) {
3004 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3005 } else if (freq != 0) {
3009 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3010 struct ccb_trans_settings_fc *fc;
3012 fc = &cts.xport_specific.fc;
3013 if (fc->valid & CTS_FC_VALID_WWNN)
3014 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3015 if (fc->valid & CTS_FC_VALID_WWPN)
3016 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3017 if (fc->valid & CTS_FC_VALID_PORT)
3018 printf(" PortID 0x%x", fc->port);