2 * Implementation of the SCSI Transport
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
7 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/types.h>
39 #include <sys/malloc.h>
40 #include <sys/kernel.h>
43 #include <sys/fcntl.h>
45 #include <sys/interrupt.h>
49 #include <sys/mutex.h>
50 #include <sys/sysctl.h>
53 #include <cam/cam_ccb.h>
54 #include <cam/cam_queue.h>
55 #include <cam/cam_periph.h>
56 #include <cam/cam_sim.h>
57 #include <cam/cam_xpt.h>
58 #include <cam/cam_xpt_sim.h>
59 #include <cam/cam_xpt_periph.h>
60 #include <cam/cam_xpt_internal.h>
61 #include <cam/cam_debug.h>
63 #include <cam/scsi/scsi_all.h>
64 #include <cam/scsi/scsi_message.h>
65 #include <cam/scsi/scsi_pass.h>
66 #include <machine/stdarg.h> /* for xpt_print below */
69 struct scsi_quirk_entry {
70 struct scsi_inquiry_pattern inq_pat;
72 #define CAM_QUIRK_NOLUNS 0x01
73 #define CAM_QUIRK_NOVPDS 0x02
74 #define CAM_QUIRK_HILUNS 0x04
75 #define CAM_QUIRK_NOHILUNS 0x08
76 #define CAM_QUIRK_NORPTLUNS 0x10
80 #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk))
82 static int cam_srch_hi = 0;
83 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
84 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT | CTLFLAG_RWTUN, 0, 0,
85 sysctl_cam_search_luns, "I",
86 "allow search above LUN 7 for SCSI3 and greater devices");
88 #define CAM_SCSI2_MAXLUN 8
89 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \
90 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
91 RPL_LUNDATA_ATYP_PERIPH) || \
92 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
93 RPL_LUNDATA_ATYP_FLAT))
94 #define CAM_GET_SIMPLE_LUN(lp, i, lval) \
95 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
96 RPL_LUNDATA_ATYP_PERIPH) { \
97 (lval) = (lp)->luns[(i)].lundata[1]; \
99 (lval) = (lp)->luns[(i)].lundata[0]; \
100 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \
102 (lval) |= (lp)->luns[(i)].lundata[1]; \
104 #define CAM_GET_LUN(lp, i, lval) \
105 (lval) = scsi_8btou64((lp)->luns[(i)].lundata); \
106 (lval) = CAM_EXTLUN_BYTE_SWIZZLE(lval);
109 * If we're not quirked to search <= the first 8 luns
110 * and we are either quirked to search above lun 8,
111 * or we're > SCSI-2 and we've enabled hilun searching,
112 * or we're > SCSI-2 and the last lun was a success,
113 * we can look for luns above lun 8.
115 #define CAN_SRCH_HI_SPARSE(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 && cam_srch_hi)))
120 #define CAN_SRCH_HI_DENSE(dv) \
121 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
122 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
123 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
125 static periph_init_t probe_periph_init;
127 static struct periph_driver probe_driver =
129 probe_periph_init, "probe",
130 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
134 PERIPHDRIVER_DECLARE(probe, probe_driver);
138 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
142 PROBE_SUPPORTED_VPD_LIST,
144 PROBE_EXTENDED_INQUIRY,
146 PROBE_TUR_FOR_NEGOTIATION,
147 PROBE_INQUIRY_BASIC_DV1,
148 PROBE_INQUIRY_BASIC_DV2,
154 static char *probe_action_text[] = {
157 "PROBE_FULL_INQUIRY",
160 "PROBE_SUPPORTED_VPD_LIST",
162 "PROBE_EXTENDED_INQUIRY",
164 "PROBE_TUR_FOR_NEGOTIATION",
165 "PROBE_INQUIRY_BASIC_DV1",
166 "PROBE_INQUIRY_BASIC_DV2",
172 #define PROBE_SET_ACTION(softc, newaction) \
175 text = probe_action_text; \
176 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
177 ("Probe %s to %s\n", text[(softc)->action], \
178 text[(newaction)])); \
179 (softc)->action = (newaction); \
183 PROBE_INQUIRY_CKSUM = 0x01,
184 PROBE_SERIAL_CKSUM = 0x02,
185 PROBE_NO_ANNOUNCE = 0x04,
190 TAILQ_HEAD(, ccb_hdr) request_ccbs;
196 struct cam_periph *periph;
199 static const char quantum[] = "QUANTUM";
200 static const char sony[] = "SONY";
201 static const char west_digital[] = "WDIGTL";
202 static const char samsung[] = "SAMSUNG";
203 static const char seagate[] = "SEAGATE";
204 static const char microp[] = "MICROP";
206 static struct scsi_quirk_entry scsi_quirk_table[] =
209 /* Reports QUEUE FULL for temporary resource shortages */
210 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
211 /*quirks*/0, /*mintags*/24, /*maxtags*/32
214 /* Reports QUEUE FULL for temporary resource shortages */
215 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
216 /*quirks*/0, /*mintags*/24, /*maxtags*/32
219 /* Reports QUEUE FULL for temporary resource shortages */
220 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
221 /*quirks*/0, /*mintags*/24, /*maxtags*/32
224 /* Broken tagged queuing drive */
225 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
226 /*quirks*/0, /*mintags*/0, /*maxtags*/0
229 /* Broken tagged queuing drive */
230 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
231 /*quirks*/0, /*mintags*/0, /*maxtags*/0
234 /* Broken tagged queuing drive */
235 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
236 /*quirks*/0, /*mintags*/0, /*maxtags*/0
240 * Unfortunately, the Quantum Atlas III has the same
241 * problem as the Atlas II drives above.
242 * Reported by: "Johan Granlund" <johan@granlund.nu>
244 * For future reference, the drive with the problem was:
245 * QUANTUM QM39100TD-SW N1B0
247 * It's possible that Quantum will fix the problem in later
248 * firmware revisions. If that happens, the quirk entry
249 * will need to be made specific to the firmware revisions
253 /* Reports QUEUE FULL for temporary resource shortages */
254 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
255 /*quirks*/0, /*mintags*/24, /*maxtags*/32
259 * 18 Gig Atlas III, same problem as the 9G version.
260 * Reported by: Andre Albsmeier
261 * <andre.albsmeier@mchp.siemens.de>
263 * For future reference, the drive with the problem was:
264 * QUANTUM QM318000TD-S N491
266 /* Reports QUEUE FULL for temporary resource shortages */
267 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
268 /*quirks*/0, /*mintags*/24, /*maxtags*/32
272 * Broken tagged queuing drive
273 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
274 * and: Martin Renters <martin@tdc.on.ca>
276 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
277 /*quirks*/0, /*mintags*/0, /*maxtags*/0
280 * The Seagate Medalist Pro drives have very poor write
281 * performance with anything more than 2 tags.
283 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
284 * Drive: <SEAGATE ST36530N 1444>
286 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
287 * Drive: <SEAGATE ST34520W 1281>
289 * No one has actually reported that the 9G version
290 * (ST39140*) of the Medalist Pro has the same problem, but
291 * we're assuming that it does because the 4G and 6.5G
292 * versions of the drive are broken.
295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
296 /*quirks*/0, /*mintags*/2, /*maxtags*/2
299 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
300 /*quirks*/0, /*mintags*/2, /*maxtags*/2
303 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
304 /*quirks*/0, /*mintags*/2, /*maxtags*/2
308 * Experiences command timeouts under load with a
309 * tag count higher than 55.
311 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
312 /*quirks*/0, /*mintags*/2, /*maxtags*/55
316 * Slow when tagged queueing is enabled. Write performance
317 * steadily drops off with more and more concurrent
318 * transactions. Best sequential write performance with
319 * tagged queueing turned off and write caching turned on.
322 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
323 * Drive: DCAS-34330 w/ "S65A" firmware.
325 * The drive with the problem had the "S65A" firmware
326 * revision, and has also been reported (by Stephen J.
327 * Roznowski <sjr@home.net>) for a drive with the "S61A"
330 * Although no one has reported problems with the 2 gig
331 * version of the DCAS drive, the assumption is that it
332 * has the same problems as the 4 gig version. Therefore
333 * this quirk entries disables tagged queueing for all
336 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
337 /*quirks*/0, /*mintags*/0, /*maxtags*/0
340 /* Broken tagged queuing drive */
341 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
342 /*quirks*/0, /*mintags*/0, /*maxtags*/0
345 /* Broken tagged queuing drive */
346 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
347 /*quirks*/0, /*mintags*/0, /*maxtags*/0
350 /* This does not support other than LUN 0 */
351 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
352 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
356 * Broken tagged queuing drive.
358 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
361 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
362 /*quirks*/0, /*mintags*/0, /*maxtags*/0
366 * Slow when tagged queueing is enabled. (1.5MB/sec versus
368 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
369 * Best performance with these drives is achieved with
370 * tagged queueing turned off, and write caching turned on.
372 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
373 /*quirks*/0, /*mintags*/0, /*maxtags*/0
377 * Slow when tagged queueing is enabled. (1.5MB/sec versus
379 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
380 * Best performance with these drives is achieved with
381 * tagged queueing turned off, and write caching turned on.
383 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
384 /*quirks*/0, /*mintags*/0, /*maxtags*/0
388 * Doesn't handle queue full condition correctly,
389 * so we need to limit maxtags to what the device
390 * can handle instead of determining this automatically.
392 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
393 /*quirks*/0, /*mintags*/2, /*maxtags*/32
396 /* Really only one LUN */
397 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
398 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
401 /* I can't believe we need a quirk for DPT volumes. */
402 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
404 /*mintags*/0, /*maxtags*/255
408 * Many Sony CDROM drives don't like multi-LUN probing.
410 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
411 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
415 * This drive doesn't like multiple LUN probing.
416 * Submitted by: Parag Patel <parag@cgt.com>
418 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
419 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
422 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
423 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
427 * The 8200 doesn't like multi-lun probing, and probably
428 * don't like serial number requests either.
431 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
434 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
438 * Let's try the same as above, but for a drive that says
439 * it's an IPL-6860 but is actually an EXB 8200.
442 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
445 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
449 * These Hitachi drives don't like multi-lun probing.
450 * The PR submitter has a DK319H, but says that the Linux
451 * kernel has a similar work-around for the DK312 and DK314,
452 * so all DK31* drives are quirked here.
454 * Submitted by: Paul Haddad <paul@pth.com>
456 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
457 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
461 * The Hitachi CJ series with J8A8 firmware apparently has
462 * problems with tagged commands.
464 * Reported by: amagai@nue.org
466 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
467 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
471 * These are the large storage arrays.
472 * Submitted by: William Carrel <william.carrel@infospace.com>
474 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
475 CAM_QUIRK_HILUNS, 2, 1024
479 * This old revision of the TDC3600 is also SCSI-1, and
480 * hangs upon serial number probing.
483 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
486 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
490 * Would repond to all LUNs if asked for.
493 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
496 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
500 * Would repond to all LUNs if asked for.
503 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
506 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
509 /* Submitted by: Matthew Dodd <winter@jurai.net> */
510 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
511 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
514 /* Submitted by: Matthew Dodd <winter@jurai.net> */
515 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
516 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
519 /* TeraSolutions special settings for TRC-22 RAID */
520 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
521 /*quirks*/0, /*mintags*/55, /*maxtags*/255
524 /* Veritas Storage Appliance */
525 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
526 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
530 * Would respond to all LUNs. Device type and removable
531 * flag are jumper-selectable.
533 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
536 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
539 /* EasyRAID E5A aka. areca ARC-6010 */
540 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
541 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
544 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
545 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
548 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
549 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
552 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic", "STORAGE DEVICE*", "120?" },
553 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
556 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic", "MassStorageClass", "1533" },
557 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
560 /* Default tagged queuing parameters for all devices */
562 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
563 /*vendor*/"*", /*product*/"*", /*revision*/"*"
565 /*quirks*/0, /*mintags*/2, /*maxtags*/255
569 static cam_status proberegister(struct cam_periph *periph,
571 static void probeschedule(struct cam_periph *probe_periph);
572 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
573 static void proberequestdefaultnegotiation(struct cam_periph *periph);
574 static int proberequestbackoff(struct cam_periph *periph,
575 struct cam_ed *device);
576 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
577 static void probe_purge_old(struct cam_path *path,
578 struct scsi_report_luns_data *new,
580 static void probecleanup(struct cam_periph *periph);
581 static void scsi_find_quirk(struct cam_ed *device);
582 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
583 static void scsi_scan_lun(struct cam_periph *periph,
584 struct cam_path *path, cam_flags flags,
586 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
587 static struct cam_ed *
588 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
590 static void scsi_devise_transport(struct cam_path *path);
591 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
592 struct cam_path *path,
594 static void scsi_toggle_tags(struct cam_path *path);
595 static void scsi_dev_async(u_int32_t async_code,
597 struct cam_et *target,
598 struct cam_ed *device,
600 static void scsi_action(union ccb *start_ccb);
601 static void scsi_announce_periph(struct cam_periph *periph);
602 static void scsi_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
603 static void scsi_proto_announce(struct cam_ed *device);
604 static void scsi_proto_announce_sbuf(struct cam_ed *device,
606 static void scsi_proto_denounce(struct cam_ed *device);
607 static void scsi_proto_denounce_sbuf(struct cam_ed *device,
609 static void scsi_proto_debug_out(union ccb *ccb);
610 static void _scsi_announce_periph(struct cam_periph *, u_int *, u_int *, struct ccb_trans_settings *);
612 static struct xpt_xport_ops scsi_xport_ops = {
613 .alloc_device = scsi_alloc_device,
614 .action = scsi_action,
615 .async = scsi_dev_async,
616 .announce = scsi_announce_periph,
617 .announce_sbuf = scsi_announce_periph_sbuf,
619 #define SCSI_XPT_XPORT(x, X) \
620 static struct xpt_xport scsi_xport_ ## x = { \
621 .xport = XPORT_ ## X, \
623 .ops = &scsi_xport_ops, \
625 CAM_XPT_XPORT(scsi_xport_ ## x);
627 SCSI_XPT_XPORT(spi, SPI);
628 SCSI_XPT_XPORT(sas, SAS);
629 SCSI_XPT_XPORT(fc, FC);
630 SCSI_XPT_XPORT(usb, USB);
631 SCSI_XPT_XPORT(iscsi, ISCSI);
632 SCSI_XPT_XPORT(srp, SRP);
633 SCSI_XPT_XPORT(ppb, PPB);
635 #undef SCSI_XPORT_XPORT
637 static struct xpt_proto_ops scsi_proto_ops = {
638 .announce = scsi_proto_announce,
639 .announce_sbuf = scsi_proto_announce_sbuf,
640 .denounce = scsi_proto_denounce,
641 .denounce_sbuf = scsi_proto_denounce_sbuf,
642 .debug_out = scsi_proto_debug_out,
644 static struct xpt_proto scsi_proto = {
647 .ops = &scsi_proto_ops,
649 CAM_XPT_PROTO(scsi_proto);
657 proberegister(struct cam_periph *periph, void *arg)
659 union ccb *request_ccb; /* CCB representing the probe request */
663 request_ccb = (union ccb *)arg;
664 if (request_ccb == NULL) {
665 printf("proberegister: no probe CCB, "
666 "can't register device\n");
667 return(CAM_REQ_CMP_ERR);
670 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
673 printf("proberegister: Unable to probe new device. "
674 "Unable to allocate softc\n");
675 return(CAM_REQ_CMP_ERR);
677 TAILQ_INIT(&softc->request_ccbs);
678 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
681 periph->softc = softc;
682 softc->periph = periph;
683 softc->action = PROBE_INVALID;
684 status = cam_periph_acquire(periph);
685 if (status != CAM_REQ_CMP) {
688 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
689 scsi_devise_transport(periph->path);
692 * Ensure we've waited at least a bus settle
693 * delay before attempting to probe the device.
694 * For HBAs that don't do bus resets, this won't make a difference.
696 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
698 probeschedule(periph);
703 probeschedule(struct cam_periph *periph)
705 struct ccb_pathinq cpi;
709 softc = (probe_softc *)periph->softc;
710 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
712 xpt_path_inq(&cpi, periph->path);
715 * If a device has gone away and another device, or the same one,
716 * is back in the same place, it should have a unit attention
717 * condition pending. It will not report the unit attention in
718 * response to an inquiry, which may leave invalid transfer
719 * negotiations in effect. The TUR will reveal the unit attention
720 * condition. Only send the TUR for lun 0, since some devices
721 * will get confused by commands other than inquiry to non-existent
722 * luns. If you think a device has gone away start your scan from
723 * lun 0. This will insure that any bogus transfer settings are
726 * If we haven't seen the device before and the controller supports
727 * some kind of transfer negotiation, negotiate with the first
728 * sent command if no bus reset was performed at startup. This
729 * ensures that the device is not confused by transfer negotiation
730 * settings left over by loader or BIOS action.
732 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
733 && (ccb->ccb_h.target_lun == 0)) {
734 PROBE_SET_ACTION(softc, PROBE_TUR);
735 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
736 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
737 proberequestdefaultnegotiation(periph);
738 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
740 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
743 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
744 softc->flags |= PROBE_NO_ANNOUNCE;
746 softc->flags &= ~PROBE_NO_ANNOUNCE;
748 if (cpi.hba_misc & PIM_EXTLUNS)
749 softc->flags |= PROBE_EXTLUN;
751 softc->flags &= ~PROBE_EXTLUN;
753 xpt_schedule(periph, CAM_PRIORITY_XPT);
757 probestart(struct cam_periph *periph, union ccb *start_ccb)
759 /* Probe the device that our peripheral driver points to */
760 struct ccb_scsiio *csio;
763 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
765 softc = (probe_softc *)periph->softc;
766 csio = &start_ccb->csio;
769 switch (softc->action) {
771 case PROBE_TUR_FOR_NEGOTIATION:
774 scsi_test_unit_ready(csio,
783 case PROBE_FULL_INQUIRY:
784 case PROBE_INQUIRY_BASIC_DV1:
785 case PROBE_INQUIRY_BASIC_DV2:
788 struct scsi_inquiry_data *inq_buf;
790 inq_buf = &periph->path->device->inq_data;
793 * If the device is currently configured, we calculate an
794 * MD5 checksum of the inquiry data, and if the serial number
795 * length is greater than 0, add the serial number data
796 * into the checksum as well. Once the inquiry and the
797 * serial number check finish, we attempt to figure out
798 * whether we still have the same device.
800 if (((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
801 && ((softc->flags & PROBE_INQUIRY_CKSUM) == 0)) {
803 MD5Init(&softc->context);
804 MD5Update(&softc->context, (unsigned char *)inq_buf,
805 sizeof(struct scsi_inquiry_data));
806 softc->flags |= PROBE_INQUIRY_CKSUM;
807 if (periph->path->device->serial_num_len > 0) {
808 MD5Update(&softc->context,
809 periph->path->device->serial_num,
810 periph->path->device->serial_num_len);
811 softc->flags |= PROBE_SERIAL_CKSUM;
813 MD5Final(softc->digest, &softc->context);
816 if (softc->action == PROBE_INQUIRY)
817 inquiry_len = SHORT_INQUIRY_LENGTH;
819 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
822 * Some parallel SCSI devices fail to send an
823 * ignore wide residue message when dealing with
824 * odd length inquiry requests. Round up to be
827 inquiry_len = roundup2(inquiry_len, 2);
829 if (softc->action == PROBE_INQUIRY_BASIC_DV1
830 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
831 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
833 if (inq_buf == NULL) {
834 xpt_print(periph->path, "malloc failure- skipping Basic"
835 "Domain Validation\n");
836 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
837 scsi_test_unit_ready(csio,
854 /*timeout*/60 * 1000);
857 case PROBE_REPORT_LUNS:
861 rp = malloc(periph->path->target->rpl_size,
862 M_CAMXPT, M_NOWAIT | M_ZERO);
864 struct scsi_inquiry_data *inq_buf;
865 inq_buf = &periph->path->device->inq_data;
866 xpt_print(periph->path,
867 "Unable to alloc report luns storage\n");
868 if (INQ_DATA_TQ_ENABLED(inq_buf))
869 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
871 PROBE_SET_ACTION(softc,
872 PROBE_SUPPORTED_VPD_LIST);
875 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
876 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
877 SSD_FULL_SIZE, 60000); break;
880 case PROBE_MODE_SENSE:
885 mode_buf_len = sizeof(struct scsi_mode_header_6)
886 + sizeof(struct scsi_mode_blk_desc)
887 + sizeof(struct scsi_control_page);
888 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
889 if (mode_buf != NULL) {
890 scsi_mode_sense(csio,
895 SMS_PAGE_CTRL_CURRENT,
896 SMS_CONTROL_MODE_PAGE,
903 xpt_print(periph->path, "Unable to mode sense control page - "
905 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
908 case PROBE_SUPPORTED_VPD_LIST:
910 struct scsi_vpd_supported_page_list *vpd_list;
911 struct cam_ed *device;
914 device = periph->path->device;
916 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
917 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
920 if (vpd_list != NULL) {
925 (u_int8_t *)vpd_list,
928 SVPD_SUPPORTED_PAGE_LIST,
930 /*timeout*/60 * 1000);
935 * We'll have to do without, let our probedone
936 * routine finish up for us.
938 start_ccb->csio.data_ptr = NULL;
939 cam_freeze_devq(periph->path);
940 cam_periph_doacquire(periph);
941 probedone(periph, start_ccb);
944 case PROBE_DEVICE_ID:
946 struct scsi_vpd_device_id *devid;
949 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
950 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
959 SVPD_DEVICE_ID_MAX_SIZE,
963 /*timeout*/60 * 1000);
968 case PROBE_EXTENDED_INQUIRY:
970 struct scsi_vpd_extended_inquiry_data *ext_inq;
973 if (scsi_vpd_supported_page(periph, SVPD_EXTENDED_INQUIRY_DATA))
974 ext_inq = malloc(sizeof(*ext_inq), M_CAMXPT,
977 if (ext_inq != NULL) {
985 SVPD_EXTENDED_INQUIRY_DATA,
987 /*timeout*/60 * 1000);
991 * We'll have to do without, let our probedone
992 * routine finish up for us.
996 case PROBE_SERIAL_NUM:
998 struct scsi_vpd_unit_serial_number *serial_buf;
999 struct cam_ed* device;
1002 device = periph->path->device;
1003 if (device->serial_num != NULL) {
1004 free(device->serial_num, M_CAMXPT);
1005 device->serial_num = NULL;
1006 device->serial_num_len = 0;
1009 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
1010 serial_buf = (struct scsi_vpd_unit_serial_number *)
1011 malloc(sizeof(*serial_buf), M_CAMXPT,
1014 if (serial_buf != NULL) {
1019 (u_int8_t *)serial_buf,
1020 sizeof(*serial_buf),
1022 SVPD_UNIT_SERIAL_NUMBER,
1024 /*timeout*/60 * 1000);
1030 panic("probestart: invalid action state 0x%x\n", softc->action);
1032 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
1033 cam_periph_doacquire(periph);
1034 xpt_action(start_ccb);
1038 proberequestdefaultnegotiation(struct cam_periph *periph)
1040 struct ccb_trans_settings cts;
1042 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1043 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1044 cts.type = CTS_TYPE_USER_SETTINGS;
1045 xpt_action((union ccb *)&cts);
1046 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1049 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1050 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1051 xpt_action((union ccb *)&cts);
1055 * Backoff Negotiation Code- only pertinent for SPI devices.
1058 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1060 struct ccb_trans_settings cts;
1061 struct ccb_trans_settings_spi *spi;
1063 memset(&cts, 0, sizeof (cts));
1064 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1065 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1066 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1067 xpt_action((union ccb *)&cts);
1068 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1070 xpt_print(periph->path,
1071 "failed to get current device settings\n");
1075 if (cts.transport != XPORT_SPI) {
1077 xpt_print(periph->path, "not SPI transport\n");
1081 spi = &cts.xport_specific.spi;
1084 * We cannot renegotiate sync rate if we don't have one.
1086 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1088 xpt_print(periph->path, "no sync rate known\n");
1094 * We'll assert that we don't have to touch PPR options- the
1095 * SIM will see what we do with period and offset and adjust
1096 * the PPR options as appropriate.
1100 * A sync rate with unknown or zero offset is nonsensical.
1101 * A sync period of zero means Async.
1103 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1104 || spi->sync_offset == 0 || spi->sync_period == 0) {
1106 xpt_print(periph->path, "no sync rate available\n");
1111 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1112 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1113 ("hit async: giving up on DV\n"));
1119 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1120 * We don't try to remember 'last' settings to see if the SIM actually
1121 * gets into the speed we want to set. We check on the SIM telling
1122 * us that a requested speed is bad, but otherwise don't try and
1123 * check the speed due to the asynchronous and handshake nature
1126 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1129 if (spi->sync_period >= 0xf) {
1130 spi->sync_period = 0;
1131 spi->sync_offset = 0;
1132 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1133 ("setting to async for DV\n"));
1135 * Once we hit async, we don't want to try
1136 * any more settings.
1138 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1139 } else if (bootverbose) {
1140 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1141 ("DV: period 0x%x\n", spi->sync_period));
1142 printf("setting period to 0x%x\n", spi->sync_period);
1144 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1145 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1146 xpt_action((union ccb *)&cts);
1147 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1150 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1151 ("DV: failed to set period 0x%x\n", spi->sync_period));
1152 if (spi->sync_period == 0) {
1159 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1162 probedone(struct cam_periph *periph, union ccb *done_ccb)
1165 struct cam_path *path;
1166 struct scsi_inquiry_data *inq_buf;
1169 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1171 softc = (probe_softc *)periph->softc;
1172 path = done_ccb->ccb_h.path;
1173 priority = done_ccb->ccb_h.pinfo.priority;
1174 cam_periph_assert(periph, MA_OWNED);
1176 switch (softc->action) {
1179 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1181 if (cam_periph_error(done_ccb, 0, SF_NO_PRINT) ==
1184 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1185 cam_release_devq(path, 0, 0, 0, FALSE);
1188 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1189 /* Don't wedge the queue */
1190 xpt_release_devq(done_ccb->ccb_h.path,
1194 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1195 xpt_release_ccb(done_ccb);
1196 xpt_schedule(periph, priority);
1198 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1199 cam_release_devq(path, 0, 0, 0, FALSE);
1200 cam_periph_release_locked(periph);
1204 case PROBE_FULL_INQUIRY:
1206 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1207 u_int8_t periph_qual;
1209 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1210 scsi_find_quirk(path->device);
1211 inq_buf = &path->device->inq_data;
1213 periph_qual = SID_QUAL(inq_buf);
1215 if (periph_qual == SID_QUAL_LU_CONNECTED ||
1216 periph_qual == SID_QUAL_LU_OFFLINE) {
1220 * We conservatively request only
1221 * SHORT_INQUIRY_LEN bytes of inquiry
1222 * information during our first try
1223 * at sending an INQUIRY. If the device
1224 * has more information to give,
1225 * perform a second request specifying
1226 * the amount of information the device
1227 * is willing to give.
1229 len = inq_buf->additional_length
1230 + offsetof(struct scsi_inquiry_data,
1231 additional_length) + 1;
1232 if (softc->action == PROBE_INQUIRY
1233 && len > SHORT_INQUIRY_LENGTH) {
1234 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1235 xpt_release_ccb(done_ccb);
1236 xpt_schedule(periph, priority);
1240 scsi_devise_transport(path);
1242 if (path->device->lun_id == 0 &&
1243 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1244 (SCSI_QUIRK(path->device)->quirks &
1245 CAM_QUIRK_NORPTLUNS) == 0) {
1246 PROBE_SET_ACTION(softc,
1249 * Start with room for *one* lun.
1251 periph->path->target->rpl_size = 16;
1252 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1253 PROBE_SET_ACTION(softc,
1256 PROBE_SET_ACTION(softc,
1257 PROBE_SUPPORTED_VPD_LIST);
1259 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1260 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1261 xpt_acquire_device(path->device);
1263 xpt_release_ccb(done_ccb);
1264 xpt_schedule(periph, priority);
1266 } else if (path->device->lun_id == 0 &&
1267 SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 &&
1268 (SCSI_QUIRK(path->device)->quirks &
1269 CAM_QUIRK_NORPTLUNS) == 0) {
1270 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1271 periph->path->target->rpl_size = 16;
1272 xpt_release_ccb(done_ccb);
1273 xpt_schedule(periph, priority);
1276 } else if (cam_periph_error(done_ccb, 0,
1277 done_ccb->ccb_h.target_lun > 0
1278 ? SF_RETRY_UA|SF_QUIET_IR
1279 : SF_RETRY_UA) == ERESTART) {
1282 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1283 /* Don't wedge the queue */
1284 xpt_release_devq(done_ccb->ccb_h.path,
1285 /*count*/1, /*run_queue*/TRUE);
1287 path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID;
1290 * If we get to this point, we got an error status back
1291 * from the inquiry and the error status doesn't require
1292 * automatically retrying the command. Therefore, the
1293 * inquiry failed. If we had inquiry information before
1294 * for this device, but this latest inquiry command failed,
1295 * the device has probably gone away. If this device isn't
1296 * already marked unconfigured, notify the peripheral
1297 * drivers that this device is no more.
1299 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1300 /* Send the async notification. */
1301 xpt_async(AC_LOST_DEVICE, path, NULL);
1302 PROBE_SET_ACTION(softc, PROBE_INVALID);
1304 xpt_release_ccb(done_ccb);
1307 case PROBE_REPORT_LUNS:
1309 struct ccb_scsiio *csio;
1310 struct scsi_report_luns_data *lp;
1313 csio = &done_ccb->csio;
1315 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1316 nlun = scsi_4btoul(lp->length) / 8;
1317 maxlun = (csio->dxfer_len / 8) - 1;
1319 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1320 if (cam_periph_error(done_ccb, 0,
1321 done_ccb->ccb_h.target_lun > 0 ?
1322 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA) ==
1326 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1327 xpt_release_devq(done_ccb->ccb_h.path, 1,
1332 } else if (nlun > maxlun) {
1334 * Reallocate and retry to cover all luns
1336 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1337 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1340 path->target->rpl_size = (nlun << 3) + 8;
1341 xpt_release_ccb(done_ccb);
1342 xpt_schedule(periph, priority);
1344 } else if (nlun == 0) {
1346 * If there don't appear to be any luns, bail.
1354 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1355 ("Probe: %u lun(s) reported\n", nlun));
1357 CAM_GET_LUN(lp, 0, lun);
1359 * If the first lun is not lun 0, then either there
1360 * is no lun 0 in the list, or the list is unsorted.
1363 for (idx = 0; idx < nlun; idx++) {
1364 CAM_GET_LUN(lp, idx, lun);
1372 lp->luns[0].lundata, 8);
1373 memcpy(lp->luns[0].lundata,
1374 lp->luns[idx].lundata, 8);
1375 memcpy(lp->luns[idx].lundata,
1377 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1378 ("lun 0 in position %u\n", idx));
1382 * If we have an old lun list, We can either
1383 * retest luns that appear to have been dropped,
1384 * or just nuke them. We'll opt for the latter.
1385 * This function will also install the new list
1386 * in the target structure.
1388 probe_purge_old(path, lp, softc->flags);
1391 inq_buf = &path->device->inq_data;
1392 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID &&
1393 (SID_QUAL(inq_buf) == SID_QUAL_LU_CONNECTED ||
1394 SID_QUAL(inq_buf) == SID_QUAL_LU_OFFLINE)) {
1395 if (INQ_DATA_TQ_ENABLED(inq_buf))
1396 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1398 PROBE_SET_ACTION(softc,
1399 PROBE_SUPPORTED_VPD_LIST);
1400 xpt_release_ccb(done_ccb);
1401 xpt_schedule(periph, priority);
1407 PROBE_SET_ACTION(softc, PROBE_INVALID);
1408 xpt_release_ccb(done_ccb);
1411 case PROBE_MODE_SENSE:
1413 struct ccb_scsiio *csio;
1414 struct scsi_mode_header_6 *mode_hdr;
1416 csio = &done_ccb->csio;
1417 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1418 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1419 struct scsi_control_page *page;
1422 offset = ((u_int8_t *)&mode_hdr[1])
1423 + mode_hdr->blk_desc_len;
1424 page = (struct scsi_control_page *)offset;
1425 path->device->queue_flags = page->queue_flags;
1426 } else if (cam_periph_error(done_ccb, 0,
1427 SF_RETRY_UA|SF_NO_PRINT) == ERESTART) {
1429 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1430 /* Don't wedge the queue */
1431 xpt_release_devq(done_ccb->ccb_h.path,
1432 /*count*/1, /*run_queue*/TRUE);
1434 xpt_release_ccb(done_ccb);
1435 free(mode_hdr, M_CAMXPT);
1436 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1437 xpt_schedule(periph, priority);
1440 case PROBE_SUPPORTED_VPD_LIST:
1442 struct ccb_scsiio *csio;
1443 struct scsi_vpd_supported_page_list *page_list;
1445 csio = &done_ccb->csio;
1447 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1449 if (path->device->supported_vpds != NULL) {
1450 free(path->device->supported_vpds, M_CAMXPT);
1451 path->device->supported_vpds = NULL;
1452 path->device->supported_vpds_len = 0;
1455 if (page_list == NULL) {
1457 * Don't process the command as it was never sent
1459 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1461 path->device->supported_vpds_len = page_list->length +
1462 SVPD_SUPPORTED_PAGES_HDR_LEN;
1463 path->device->supported_vpds = (uint8_t *)page_list;
1464 xpt_release_ccb(done_ccb);
1465 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1466 xpt_schedule(periph, priority);
1468 } else if (cam_periph_error(done_ccb, 0,
1469 SF_RETRY_UA|SF_NO_PRINT) == ERESTART) {
1471 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1472 /* Don't wedge the queue */
1473 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1478 free(page_list, M_CAMXPT);
1479 /* No VPDs available, skip to device check. */
1480 csio->data_ptr = NULL;
1481 goto probe_device_check;
1483 case PROBE_DEVICE_ID:
1485 struct scsi_vpd_device_id *devid;
1486 struct ccb_scsiio *csio;
1487 uint32_t length = 0;
1489 csio = &done_ccb->csio;
1490 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1492 /* Clean up from previous instance of this device */
1493 if (path->device->device_id != NULL) {
1494 path->device->device_id_len = 0;
1495 free(path->device->device_id, M_CAMXPT);
1496 path->device->device_id = NULL;
1499 if (devid == NULL) {
1500 /* Don't process the command as it was never sent */
1501 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1502 length = scsi_2btoul(devid->length);
1505 * NB: device_id_len is actual response
1506 * size, not buffer size.
1508 path->device->device_id_len = length +
1509 SVPD_DEVICE_ID_HDR_LEN;
1510 path->device->device_id = (uint8_t *)devid;
1512 } else if (cam_periph_error(done_ccb, 0,
1513 SF_RETRY_UA) == ERESTART) {
1515 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1516 /* Don't wedge the queue */
1517 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1521 /* Free the device id space if we don't use it */
1522 if (devid && length == 0)
1523 free(devid, M_CAMXPT);
1524 xpt_release_ccb(done_ccb);
1525 PROBE_SET_ACTION(softc, PROBE_EXTENDED_INQUIRY);
1526 xpt_schedule(periph, priority);
1529 case PROBE_EXTENDED_INQUIRY: {
1530 struct scsi_vpd_extended_inquiry_data *ext_inq;
1531 struct ccb_scsiio *csio;
1534 csio = &done_ccb->csio;
1535 ext_inq = (struct scsi_vpd_extended_inquiry_data *)
1537 if (path->device->ext_inq != NULL) {
1538 path->device->ext_inq_len = 0;
1539 free(path->device->ext_inq, M_CAMXPT);
1540 path->device->ext_inq = NULL;
1543 if (ext_inq == NULL) {
1544 /* Don't process the command as it was never sent */
1545 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1546 length = scsi_2btoul(ext_inq->page_length) +
1547 __offsetof(struct scsi_vpd_extended_inquiry_data,
1549 length = min(length, sizeof(*ext_inq));
1550 length -= csio->resid;
1552 path->device->ext_inq_len = length;
1553 path->device->ext_inq = (uint8_t *)ext_inq;
1555 } else if (cam_periph_error(done_ccb, 0, SF_RETRY_UA) ==
1558 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1559 /* Don't wedge the queue */
1560 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1564 /* Free the device id space if we don't use it */
1565 if (ext_inq && length <= 0)
1566 free(ext_inq, M_CAMXPT);
1567 xpt_release_ccb(done_ccb);
1568 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1569 xpt_schedule(periph, priority);
1574 case PROBE_SERIAL_NUM:
1576 struct ccb_scsiio *csio;
1577 struct scsi_vpd_unit_serial_number *serial_buf;
1584 csio = &done_ccb->csio;
1585 priority = done_ccb->ccb_h.pinfo.priority;
1587 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1589 if (serial_buf == NULL) {
1591 * Don't process the command as it was never sent
1593 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1594 && (serial_buf->length > 0)) {
1597 path->device->serial_num =
1598 (u_int8_t *)malloc((serial_buf->length + 1),
1599 M_CAMXPT, M_NOWAIT);
1600 if (path->device->serial_num != NULL) {
1603 start = strspn(serial_buf->serial_num, " ");
1604 slen = serial_buf->length - start;
1607 * SPC5r05 says that an all-space serial
1608 * number means no product serial number
1613 memcpy(path->device->serial_num,
1614 &serial_buf->serial_num[start], slen);
1615 path->device->serial_num_len = slen;
1616 path->device->serial_num[slen] = '\0';
1618 } else if (cam_periph_error(done_ccb, 0,
1619 SF_RETRY_UA|SF_NO_PRINT) == ERESTART) {
1621 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1622 /* Don't wedge the queue */
1623 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1628 * Let's see if we have seen this device before.
1630 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1632 u_int8_t digest[16];
1637 (unsigned char *)&path->device->inq_data,
1638 sizeof(struct scsi_inquiry_data));
1641 MD5Update(&context, path->device->serial_num,
1642 path->device->serial_num_len);
1644 MD5Final(digest, &context);
1645 if (bcmp(softc->digest, digest, 16) == 0)
1649 * XXX Do we need to do a TUR in order to ensure
1650 * that the device really hasn't changed???
1653 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1654 xpt_async(AC_LOST_DEVICE, path, NULL);
1656 if (serial_buf != NULL)
1657 free(serial_buf, M_CAMXPT);
1661 * Now that we have all the necessary
1662 * information to safely perform transfer
1663 * negotiations... Controllers don't perform
1664 * any negotiation or tagged queuing until
1665 * after the first XPT_SET_TRAN_SETTINGS ccb is
1666 * received. So, on a new device, just retrieve
1667 * the user settings, and set them as the current
1668 * settings to set the device up.
1670 proberequestdefaultnegotiation(periph);
1671 xpt_release_ccb(done_ccb);
1674 * Perform a TUR to allow the controller to
1675 * perform any necessary transfer negotiation.
1677 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1678 xpt_schedule(periph, priority);
1681 xpt_release_ccb(done_ccb);
1684 case PROBE_TUR_FOR_NEGOTIATION:
1686 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1687 cam_periph_error(done_ccb, 0,
1688 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY);
1690 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1691 /* Don't wedge the queue */
1692 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1696 * Do Domain Validation for lun 0 on devices that claim
1697 * to support Synchronous Transfer modes.
1699 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1700 && done_ccb->ccb_h.target_lun == 0
1701 && (path->device->inq_data.flags & SID_Sync) != 0
1702 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1703 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1704 ("Begin Domain Validation\n"));
1705 path->device->flags |= CAM_DEV_IN_DV;
1706 xpt_release_ccb(done_ccb);
1707 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1708 xpt_schedule(periph, priority);
1711 if (softc->action == PROBE_DV_EXIT) {
1712 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1713 ("Leave Domain Validation\n"));
1715 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1716 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1717 xpt_acquire_device(path->device);
1719 path->device->flags &=
1720 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1721 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1722 /* Inform the XPT that a new device has been found */
1723 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1724 xpt_action(done_ccb);
1725 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1728 PROBE_SET_ACTION(softc, PROBE_DONE);
1729 xpt_release_ccb(done_ccb);
1731 case PROBE_INQUIRY_BASIC_DV1:
1732 case PROBE_INQUIRY_BASIC_DV2:
1734 struct scsi_inquiry_data *nbuf;
1735 struct ccb_scsiio *csio;
1737 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1738 cam_periph_error(done_ccb, 0,
1739 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY);
1741 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1742 /* Don't wedge the queue */
1743 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1746 csio = &done_ccb->csio;
1747 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1748 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1750 "inquiry data fails comparison at DV%d step\n",
1751 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1752 if (proberequestbackoff(periph, path->device)) {
1753 path->device->flags &= ~CAM_DEV_IN_DV;
1754 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1757 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1759 free(nbuf, M_CAMXPT);
1760 xpt_release_ccb(done_ccb);
1761 xpt_schedule(periph, priority);
1764 free(nbuf, M_CAMXPT);
1765 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1766 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1767 xpt_release_ccb(done_ccb);
1768 xpt_schedule(periph, priority);
1771 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1772 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1773 ("Leave Domain Validation Successfully\n"));
1775 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1776 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1777 xpt_acquire_device(path->device);
1779 path->device->flags &=
1780 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1781 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1782 /* Inform the XPT that a new device has been found */
1783 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1784 xpt_action(done_ccb);
1785 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1788 PROBE_SET_ACTION(softc, PROBE_DONE);
1789 xpt_release_ccb(done_ccb);
1793 panic("probedone: invalid action state 0x%x\n", softc->action);
1795 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1796 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1797 done_ccb->ccb_h.status = CAM_REQ_CMP;
1799 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1800 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1801 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1802 cam_release_devq(path, 0, 0, 0, FALSE);
1803 cam_periph_release_locked(periph);
1804 cam_periph_invalidate(periph);
1805 cam_periph_release_locked(periph);
1807 probeschedule(periph);
1813 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1816 struct cam_path *tp;
1817 struct scsi_report_luns_data *old;
1818 u_int idx1, idx2, nlun_old, nlun_new;
1822 if (path->target == NULL) {
1825 mtx_lock(&path->target->luns_mtx);
1826 old = path->target->luns;
1827 path->target->luns = new;
1828 mtx_unlock(&path->target->luns_mtx);
1831 nlun_old = scsi_4btoul(old->length) / 8;
1832 nlun_new = scsi_4btoul(new->length) / 8;
1835 * We are not going to assume sorted lists. Deal.
1837 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1838 ol = old->luns[idx1].lundata;
1839 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1840 nl = new->luns[idx2].lundata;
1841 if (memcmp(nl, ol, 8) == 0) {
1845 if (idx2 < nlun_new) {
1849 * An 'old' item not in the 'new' list.
1850 * Nuke it. Except that if it is lun 0,
1851 * that would be what the probe state
1852 * machine is currently working on,
1853 * so we won't do that.
1855 CAM_GET_LUN(old, idx1, this_lun);
1856 if (this_lun == 0) {
1861 * We also cannot nuke it if it is
1862 * not in a lun format we understand
1863 * and replace the LUN with a "simple" LUN
1864 * if that is all the HBA supports.
1866 if (!(flags & PROBE_EXTLUN)) {
1867 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1869 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1872 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1873 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1874 xpt_async(AC_LOST_DEVICE, tp, NULL);
1878 free(old, M_CAMXPT);
1882 probecleanup(struct cam_periph *periph)
1884 free(periph->softc, M_CAMXPT);
1888 scsi_find_quirk(struct cam_ed *device)
1890 struct scsi_quirk_entry *quirk;
1893 match = cam_quirkmatch((caddr_t)&device->inq_data,
1894 (caddr_t)scsi_quirk_table,
1895 nitems(scsi_quirk_table),
1896 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1899 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1901 quirk = (struct scsi_quirk_entry *)match;
1902 device->quirk = quirk;
1903 device->mintags = quirk->mintags;
1904 device->maxtags = quirk->maxtags;
1908 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1913 error = sysctl_handle_int(oidp, &val, 0, req);
1914 if (error != 0 || req->newptr == NULL)
1916 if (val == 0 || val == 1) {
1925 union ccb *request_ccb;
1926 struct ccb_pathinq *cpi;
1929 } scsi_scan_bus_info;
1932 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1933 * As the scan progresses, scsi_scan_bus is used as the
1934 * callback on completion function.
1937 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1941 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1942 ("scsi_scan_bus\n"));
1943 switch (request_ccb->ccb_h.func_code) {
1947 scsi_scan_bus_info *scan_info;
1948 union ccb *work_ccb, *reset_ccb;
1949 struct cam_path *path;
1951 u_int low_target, max_target;
1954 /* Find out the characteristics of the bus */
1955 work_ccb = xpt_alloc_ccb_nowait();
1956 if (work_ccb == NULL) {
1957 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1958 xpt_done(request_ccb);
1961 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1962 request_ccb->ccb_h.pinfo.priority);
1963 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1964 xpt_action(work_ccb);
1965 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1966 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1967 xpt_free_ccb(work_ccb);
1968 xpt_done(request_ccb);
1972 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1974 * Can't scan the bus on an adapter that
1975 * cannot perform the initiator role.
1977 request_ccb->ccb_h.status = CAM_REQ_CMP;
1978 xpt_free_ccb(work_ccb);
1979 xpt_done(request_ccb);
1983 /* We may need to reset bus first, if we haven't done it yet. */
1984 if ((work_ccb->cpi.hba_inquiry &
1985 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1986 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1987 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1988 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1989 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1991 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1992 xpt_action(reset_ccb);
1993 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1994 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1995 xpt_free_ccb(reset_ccb);
1996 xpt_free_ccb(work_ccb);
1997 xpt_done(request_ccb);
2000 xpt_free_ccb(reset_ccb);
2003 /* Save some state for use while we probe for devices */
2004 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
2005 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
2006 if (scan_info == NULL) {
2007 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2008 xpt_free_ccb(work_ccb);
2009 xpt_done(request_ccb);
2012 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
2013 ("SCAN start for %p\n", scan_info));
2014 scan_info->request_ccb = request_ccb;
2015 scan_info->cpi = &work_ccb->cpi;
2017 /* Cache on our stack so we can work asynchronously */
2018 max_target = scan_info->cpi->max_target;
2020 initiator_id = scan_info->cpi->initiator_id;
2024 * We can scan all targets in parallel, or do it sequentially.
2027 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2028 max_target = low_target = request_ccb->ccb_h.target_id;
2029 scan_info->counter = 0;
2030 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2032 scan_info->counter = 0;
2034 scan_info->counter = scan_info->cpi->max_target + 1;
2035 if (scan_info->cpi->initiator_id < scan_info->counter) {
2036 scan_info->counter--;
2039 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2042 for (i = low_target; i <= max_target; i++) {
2044 if (i == initiator_id)
2047 status = xpt_create_path(&path, NULL,
2048 request_ccb->ccb_h.path_id,
2050 if (status != CAM_REQ_CMP) {
2051 printf("scsi_scan_bus: xpt_create_path failed"
2052 " with status %#x, bus scan halted\n",
2054 free(scan_info, M_CAMXPT);
2055 request_ccb->ccb_h.status = status;
2056 xpt_free_ccb(work_ccb);
2057 xpt_done(request_ccb);
2060 work_ccb = xpt_alloc_ccb_nowait();
2061 if (work_ccb == NULL) {
2062 xpt_free_ccb((union ccb *)scan_info->cpi);
2063 free(scan_info, M_CAMXPT);
2064 xpt_free_path(path);
2065 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2066 xpt_done(request_ccb);
2069 xpt_setup_ccb(&work_ccb->ccb_h, path,
2070 request_ccb->ccb_h.pinfo.priority);
2071 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2072 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2073 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
2074 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
2075 work_ccb->crcn.flags = request_ccb->crcn.flags;
2076 xpt_action(work_ccb);
2085 struct cam_path *path, *oldpath;
2086 scsi_scan_bus_info *scan_info;
2087 struct cam_et *target;
2088 struct cam_ed *device, *nextdev;
2091 target_id_t target_id;
2094 oldpath = request_ccb->ccb_h.path;
2096 status = cam_ccb_status(request_ccb);
2097 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
2098 path_id = request_ccb->ccb_h.path_id;
2099 target_id = request_ccb->ccb_h.target_id;
2100 lun_id = request_ccb->ccb_h.target_lun;
2101 target = request_ccb->ccb_h.path->target;
2104 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2106 mtx_lock(&target->luns_mtx);
2109 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2112 * Make sure we skip over lun 0 if it's the first member
2113 * of the list as we've actually just finished probing
2116 CAM_GET_LUN(target->luns, 0, first);
2117 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2118 scan_info->lunindex[target_id]++;
2122 * Skip any LUNs that the HBA can't deal with.
2124 while (scan_info->lunindex[target_id] < nluns) {
2125 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2126 CAM_GET_LUN(target->luns,
2127 scan_info->lunindex[target_id],
2132 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2133 scan_info->lunindex[target_id])) {
2134 CAM_GET_SIMPLE_LUN(target->luns,
2135 scan_info->lunindex[target_id],
2140 scan_info->lunindex[target_id]++;
2143 if (scan_info->lunindex[target_id] < nluns) {
2144 mtx_unlock(&target->luns_mtx);
2146 CAM_DEBUG(request_ccb->ccb_h.path,
2148 ("next lun to try at index %u is %jx\n",
2149 scan_info->lunindex[target_id],
2150 (uintmax_t)lun_id));
2151 scan_info->lunindex[target_id]++;
2153 mtx_unlock(&target->luns_mtx);
2154 /* We're done with scanning all luns. */
2157 mtx_unlock(&target->luns_mtx);
2158 device = request_ccb->ccb_h.path->device;
2159 /* Continue sequential LUN scan if: */
2160 /* -- we have more LUNs that need recheck */
2161 mtx_lock(&target->bus->eb_mtx);
2163 while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL)
2164 if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0)
2166 mtx_unlock(&target->bus->eb_mtx);
2167 if (nextdev != NULL) {
2169 /* -- stop if CAM_QUIRK_NOLUNS is set. */
2170 } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) {
2172 /* -- this LUN is connected and its SCSI version
2173 * allows more LUNs. */
2174 } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2175 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2176 CAN_SRCH_HI_DENSE(device))
2178 /* -- this LUN is disconnected, its SCSI version
2179 * allows more LUNs and we guess they may be. */
2180 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) {
2181 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2182 CAN_SRCH_HI_SPARSE(device))
2185 if (next_target == 0) {
2187 if (lun_id > scan_info->cpi->max_lun)
2193 * Check to see if we scan any further luns.
2199 * Free the current request path- we're done with it.
2201 xpt_free_path(oldpath);
2204 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2206 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2207 scan_info->counter++;
2208 if (scan_info->counter ==
2209 scan_info->cpi->initiator_id) {
2210 scan_info->counter++;
2212 if (scan_info->counter >=
2213 scan_info->cpi->max_target+1) {
2217 scan_info->counter--;
2218 if (scan_info->counter == 0) {
2224 xpt_free_ccb(request_ccb);
2225 xpt_free_ccb((union ccb *)scan_info->cpi);
2226 request_ccb = scan_info->request_ccb;
2227 CAM_DEBUG(request_ccb->ccb_h.path,
2229 ("SCAN done for %p\n", scan_info));
2230 free(scan_info, M_CAMXPT);
2231 request_ccb->ccb_h.status = CAM_REQ_CMP;
2232 xpt_done(request_ccb);
2236 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2238 xpt_free_ccb(request_ccb);
2241 status = xpt_create_path(&path, NULL,
2242 scan_info->request_ccb->ccb_h.path_id,
2243 scan_info->counter, 0);
2244 if (status != CAM_REQ_CMP) {
2246 printf("scsi_scan_bus: xpt_create_path failed"
2247 " with status %#x, bus scan halted\n",
2249 xpt_free_ccb(request_ccb);
2250 xpt_free_ccb((union ccb *)scan_info->cpi);
2251 request_ccb = scan_info->request_ccb;
2252 free(scan_info, M_CAMXPT);
2253 request_ccb->ccb_h.status = status;
2254 xpt_done(request_ccb);
2257 xpt_setup_ccb(&request_ccb->ccb_h, path,
2258 request_ccb->ccb_h.pinfo.priority);
2259 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2260 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2261 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2262 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2263 request_ccb->crcn.flags =
2264 scan_info->request_ccb->crcn.flags;
2266 status = xpt_create_path(&path, NULL,
2267 path_id, target_id, lun_id);
2269 * Free the old request path- we're done with it. We
2270 * do this *after* creating the new path so that
2271 * we don't remove a target that has our lun list
2272 * in the case that lun 0 is not present.
2274 xpt_free_path(oldpath);
2275 if (status != CAM_REQ_CMP) {
2276 printf("scsi_scan_bus: xpt_create_path failed "
2277 "with status %#x, halting LUN scan\n",
2281 xpt_setup_ccb(&request_ccb->ccb_h, path,
2282 request_ccb->ccb_h.pinfo.priority);
2283 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2284 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2285 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2286 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2287 request_ccb->crcn.flags =
2288 scan_info->request_ccb->crcn.flags;
2291 xpt_action(request_ccb);
2300 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2301 cam_flags flags, union ccb *request_ccb)
2303 struct ccb_pathinq cpi;
2305 struct cam_path *new_path;
2306 struct cam_periph *old_periph;
2309 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2311 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2312 cpi.ccb_h.func_code = XPT_PATH_INQ;
2313 xpt_action((union ccb *)&cpi);
2315 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2316 if (request_ccb != NULL) {
2317 request_ccb->ccb_h.status = cpi.ccb_h.status;
2318 xpt_done(request_ccb);
2323 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2325 * Can't scan the bus on an adapter that
2326 * cannot perform the initiator role.
2328 if (request_ccb != NULL) {
2329 request_ccb->ccb_h.status = CAM_REQ_CMP;
2330 xpt_done(request_ccb);
2335 if (request_ccb == NULL) {
2336 request_ccb = xpt_alloc_ccb_nowait();
2337 if (request_ccb == NULL) {
2338 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2339 "can't continue\n");
2342 status = xpt_create_path(&new_path, NULL,
2344 path->target->target_id,
2345 path->device->lun_id);
2346 if (status != CAM_REQ_CMP) {
2347 xpt_print(path, "scsi_scan_lun: can't create path, "
2348 "can't continue\n");
2349 xpt_free_ccb(request_ccb);
2352 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2353 request_ccb->ccb_h.cbfcnp = xptscandone;
2354 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2355 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2356 request_ccb->crcn.flags = flags;
2359 lock = (xpt_path_owned(path) == 0);
2361 xpt_path_lock(path);
2362 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2363 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2366 softc = (probe_softc *)old_periph->softc;
2367 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2368 &request_ccb->ccb_h, periph_links.tqe);
2370 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2371 xpt_done(request_ccb);
2374 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2375 probestart, "probe",
2377 request_ccb->ccb_h.path, NULL, 0,
2380 if (status != CAM_REQ_CMP) {
2381 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2382 "returned an error, can't continue probe\n");
2383 request_ccb->ccb_h.status = status;
2384 xpt_done(request_ccb);
2388 xpt_path_unlock(path);
2392 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2395 xpt_free_path(done_ccb->ccb_h.path);
2396 xpt_free_ccb(done_ccb);
2399 static struct cam_ed *
2400 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2402 struct scsi_quirk_entry *quirk;
2403 struct cam_ed *device;
2405 device = xpt_alloc_device(bus, target, lun_id);
2410 * Take the default quirk entry until we have inquiry
2411 * data and can determine a better quirk to use.
2413 quirk = &scsi_quirk_table[nitems(scsi_quirk_table) - 1];
2414 device->quirk = (void *)quirk;
2415 device->mintags = quirk->mintags;
2416 device->maxtags = quirk->maxtags;
2417 bzero(&device->inq_data, sizeof(device->inq_data));
2418 device->inq_flags = 0;
2419 device->queue_flags = 0;
2420 device->serial_num = NULL;
2421 device->serial_num_len = 0;
2422 device->device_id = NULL;
2423 device->device_id_len = 0;
2424 device->supported_vpds = NULL;
2425 device->supported_vpds_len = 0;
2430 scsi_devise_transport(struct cam_path *path)
2432 struct ccb_pathinq cpi;
2433 struct ccb_trans_settings cts;
2434 struct scsi_inquiry_data *inq_buf;
2436 /* Get transport information from the SIM */
2437 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2438 cpi.ccb_h.func_code = XPT_PATH_INQ;
2439 xpt_action((union ccb *)&cpi);
2442 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2443 inq_buf = &path->device->inq_data;
2444 path->device->protocol = PROTO_SCSI;
2445 path->device->protocol_version =
2446 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2447 path->device->transport = cpi.transport;
2448 path->device->transport_version = cpi.transport_version;
2451 * Any device not using SPI3 features should
2452 * be considered SPI2 or lower.
2454 if (inq_buf != NULL) {
2455 if (path->device->transport == XPORT_SPI
2456 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2457 && path->device->transport_version > 2)
2458 path->device->transport_version = 2;
2460 struct cam_ed* otherdev;
2462 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2464 otherdev = TAILQ_NEXT(otherdev, links)) {
2465 if (otherdev != path->device)
2469 if (otherdev != NULL) {
2471 * Initially assume the same versioning as
2472 * prior luns for this target.
2474 path->device->protocol_version =
2475 otherdev->protocol_version;
2476 path->device->transport_version =
2477 otherdev->transport_version;
2479 /* Until we know better, opt for safety */
2480 path->device->protocol_version = 2;
2481 if (path->device->transport == XPORT_SPI)
2482 path->device->transport_version = 2;
2484 path->device->transport_version = 0;
2490 * For a device compliant with SPC-2 we should be able
2491 * to determine the transport version supported by
2492 * scrutinizing the version descriptors in the
2496 /* Tell the controller what we think */
2497 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2498 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2499 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2500 cts.transport = path->device->transport;
2501 cts.transport_version = path->device->transport_version;
2502 cts.protocol = path->device->protocol;
2503 cts.protocol_version = path->device->protocol_version;
2504 cts.proto_specific.valid = 0;
2505 cts.xport_specific.valid = 0;
2506 xpt_action((union ccb *)&cts);
2510 scsi_dev_advinfo(union ccb *start_ccb)
2512 struct cam_ed *device;
2513 struct ccb_dev_advinfo *cdai;
2516 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2517 device = start_ccb->ccb_h.path->device;
2518 cdai = &start_ccb->cdai;
2519 switch(cdai->buftype) {
2520 case CDAI_TYPE_SCSI_DEVID:
2521 if (cdai->flags & CDAI_FLAG_STORE)
2523 cdai->provsiz = device->device_id_len;
2524 if (device->device_id_len == 0)
2526 amt = device->device_id_len;
2527 if (cdai->provsiz > cdai->bufsiz)
2529 memcpy(cdai->buf, device->device_id, amt);
2531 case CDAI_TYPE_SERIAL_NUM:
2532 if (cdai->flags & CDAI_FLAG_STORE)
2534 cdai->provsiz = device->serial_num_len;
2535 if (device->serial_num_len == 0)
2537 amt = device->serial_num_len;
2538 if (cdai->provsiz > cdai->bufsiz)
2540 memcpy(cdai->buf, device->serial_num, amt);
2542 case CDAI_TYPE_PHYS_PATH:
2543 if (cdai->flags & CDAI_FLAG_STORE) {
2544 if (device->physpath != NULL) {
2545 free(device->physpath, M_CAMXPT);
2546 device->physpath = NULL;
2547 device->physpath_len = 0;
2549 /* Clear existing buffer if zero length */
2550 if (cdai->bufsiz == 0)
2552 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2553 if (device->physpath == NULL) {
2554 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2557 device->physpath_len = cdai->bufsiz;
2558 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2560 cdai->provsiz = device->physpath_len;
2561 if (device->physpath_len == 0)
2563 amt = device->physpath_len;
2564 if (cdai->provsiz > cdai->bufsiz)
2566 memcpy(cdai->buf, device->physpath, amt);
2569 case CDAI_TYPE_RCAPLONG:
2570 if (cdai->flags & CDAI_FLAG_STORE) {
2571 if (device->rcap_buf != NULL) {
2572 free(device->rcap_buf, M_CAMXPT);
2573 device->rcap_buf = NULL;
2576 device->rcap_len = cdai->bufsiz;
2577 /* Clear existing buffer if zero length */
2578 if (cdai->bufsiz == 0)
2581 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2583 if (device->rcap_buf == NULL) {
2584 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2588 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2590 cdai->provsiz = device->rcap_len;
2591 if (device->rcap_len == 0)
2593 amt = device->rcap_len;
2594 if (cdai->provsiz > cdai->bufsiz)
2596 memcpy(cdai->buf, device->rcap_buf, amt);
2599 case CDAI_TYPE_EXT_INQ:
2601 * We fetch extended inquiry data during probe, if
2602 * available. We don't allow changing it.
2604 if (cdai->flags & CDAI_FLAG_STORE)
2606 cdai->provsiz = device->ext_inq_len;
2607 if (device->ext_inq_len == 0)
2609 amt = device->ext_inq_len;
2610 if (cdai->provsiz > cdai->bufsiz)
2612 memcpy(cdai->buf, device->ext_inq, amt);
2617 start_ccb->ccb_h.status = CAM_REQ_CMP;
2619 if (cdai->flags & CDAI_FLAG_STORE) {
2620 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2621 (void *)(uintptr_t)cdai->buftype);
2626 scsi_action(union ccb *start_ccb)
2629 switch (start_ccb->ccb_h.func_code) {
2630 case XPT_SET_TRAN_SETTINGS:
2632 scsi_set_transfer_settings(&start_ccb->cts,
2633 start_ccb->ccb_h.path,
2634 /*async_update*/FALSE);
2639 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2642 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2643 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2646 case XPT_DEV_ADVINFO:
2648 scsi_dev_advinfo(start_ccb);
2652 xpt_action_default(start_ccb);
2658 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2661 struct ccb_pathinq cpi;
2662 struct ccb_trans_settings cur_cts;
2663 struct ccb_trans_settings_scsi *scsi;
2664 struct ccb_trans_settings_scsi *cur_scsi;
2665 struct scsi_inquiry_data *inq_data;
2666 struct cam_ed *device;
2668 if (path == NULL || (device = path->device) == NULL) {
2669 cts->ccb_h.status = CAM_PATH_INVALID;
2670 xpt_done((union ccb *)cts);
2674 if (cts->protocol == PROTO_UNKNOWN
2675 || cts->protocol == PROTO_UNSPECIFIED) {
2676 cts->protocol = device->protocol;
2677 cts->protocol_version = device->protocol_version;
2680 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2681 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2682 cts->protocol_version = device->protocol_version;
2684 if (cts->protocol != device->protocol) {
2685 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2686 cts->protocol, device->protocol);
2687 cts->protocol = device->protocol;
2690 if (cts->protocol_version > device->protocol_version) {
2692 xpt_print(path, "Down reving Protocol "
2693 "Version from %d to %d?\n", cts->protocol_version,
2694 device->protocol_version);
2696 cts->protocol_version = device->protocol_version;
2699 if (cts->transport == XPORT_UNKNOWN
2700 || cts->transport == XPORT_UNSPECIFIED) {
2701 cts->transport = device->transport;
2702 cts->transport_version = device->transport_version;
2705 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2706 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2707 cts->transport_version = device->transport_version;
2709 if (cts->transport != device->transport) {
2710 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2711 cts->transport, device->transport);
2712 cts->transport = device->transport;
2715 if (cts->transport_version > device->transport_version) {
2717 xpt_print(path, "Down reving Transport "
2718 "Version from %d to %d?\n", cts->transport_version,
2719 device->transport_version);
2721 cts->transport_version = device->transport_version;
2725 * Nothing more of interest to do unless
2726 * this is a device connected via the
2729 if (cts->protocol != PROTO_SCSI) {
2730 if (async_update == FALSE)
2731 xpt_action_default((union ccb *)cts);
2735 inq_data = &device->inq_data;
2736 scsi = &cts->proto_specific.scsi;
2737 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2738 cpi.ccb_h.func_code = XPT_PATH_INQ;
2739 xpt_action((union ccb *)&cpi);
2741 /* SCSI specific sanity checking */
2742 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2743 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2744 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2745 || (device->mintags == 0)) {
2747 * Can't tag on hardware that doesn't support tags,
2748 * doesn't have it enabled, or has broken tag support.
2750 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2753 if (async_update == FALSE) {
2755 * Perform sanity checking against what the
2756 * controller and device can do.
2758 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2759 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2760 cur_cts.type = cts->type;
2761 xpt_action((union ccb *)&cur_cts);
2762 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2765 cur_scsi = &cur_cts.proto_specific.scsi;
2766 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2767 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2768 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2770 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2771 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2774 /* SPI specific sanity checking */
2775 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2777 struct ccb_trans_settings_spi *spi;
2778 struct ccb_trans_settings_spi *cur_spi;
2780 spi = &cts->xport_specific.spi;
2782 cur_spi = &cur_cts.xport_specific.spi;
2784 /* Fill in any gaps in what the user gave us */
2785 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2786 spi->sync_period = cur_spi->sync_period;
2787 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2788 spi->sync_period = 0;
2789 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2790 spi->sync_offset = cur_spi->sync_offset;
2791 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2792 spi->sync_offset = 0;
2793 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2794 spi->ppr_options = cur_spi->ppr_options;
2795 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2796 spi->ppr_options = 0;
2797 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2798 spi->bus_width = cur_spi->bus_width;
2799 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2801 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2802 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2803 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2805 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2806 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2807 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2808 && (inq_data->flags & SID_Sync) == 0
2809 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2810 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2812 spi->sync_period = 0;
2813 spi->sync_offset = 0;
2816 switch (spi->bus_width) {
2817 case MSG_EXT_WDTR_BUS_32_BIT:
2818 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2819 || (inq_data->flags & SID_WBus32) != 0
2820 || cts->type == CTS_TYPE_USER_SETTINGS)
2821 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2823 /* Fall Through to 16-bit */
2824 case MSG_EXT_WDTR_BUS_16_BIT:
2825 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2826 || (inq_data->flags & SID_WBus16) != 0
2827 || cts->type == CTS_TYPE_USER_SETTINGS)
2828 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2829 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2832 /* Fall Through to 8-bit */
2833 default: /* New bus width?? */
2834 case MSG_EXT_WDTR_BUS_8_BIT:
2835 /* All targets can do this */
2836 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2840 spi3caps = cpi.xport_specific.spi.ppr_options;
2841 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2842 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2843 spi3caps &= inq_data->spi3data;
2845 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2846 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2848 if ((spi3caps & SID_SPI_IUS) == 0)
2849 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2851 if ((spi3caps & SID_SPI_QAS) == 0)
2852 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2854 /* No SPI Transfer settings are allowed unless we are wide */
2855 if (spi->bus_width == 0)
2856 spi->ppr_options = 0;
2858 if ((spi->valid & CTS_SPI_VALID_DISC)
2859 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2861 * Can't tag queue without disconnection.
2863 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2864 scsi->valid |= CTS_SCSI_VALID_TQ;
2868 * If we are currently performing tagged transactions to
2869 * this device and want to change its negotiation parameters,
2870 * go non-tagged for a bit to give the controller a chance to
2871 * negotiate unhampered by tag messages.
2873 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2874 && (device->inq_flags & SID_CmdQue) != 0
2875 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2876 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2877 CTS_SPI_VALID_SYNC_OFFSET|
2878 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2879 scsi_toggle_tags(path);
2882 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2883 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2887 * If we are transitioning from tags to no-tags or
2888 * vice-versa, we need to carefully freeze and restart
2889 * the queue so that we don't overlap tagged and non-tagged
2890 * commands. We also temporarily stop tags if there is
2891 * a change in transfer negotiation settings to allow
2892 * "tag-less" negotiation.
2894 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2895 || (device->inq_flags & SID_CmdQue) != 0)
2896 device_tagenb = TRUE;
2898 device_tagenb = FALSE;
2900 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2901 && device_tagenb == FALSE)
2902 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2903 && device_tagenb == TRUE)) {
2905 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2907 * Delay change to use tags until after a
2908 * few commands have gone to this device so
2909 * the controller has time to perform transfer
2910 * negotiations without tagged messages getting
2913 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2914 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2916 xpt_stop_tags(path);
2920 if (async_update == FALSE)
2921 xpt_action_default((union ccb *)cts);
2925 scsi_toggle_tags(struct cam_path *path)
2930 * Give controllers a chance to renegotiate
2931 * before starting tag operations. We
2932 * "toggle" tagged queuing off then on
2933 * which causes the tag enable command delay
2934 * counter to come into effect.
2937 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2938 || ((dev->inq_flags & SID_CmdQue) != 0
2939 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2940 struct ccb_trans_settings cts;
2942 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2943 cts.protocol = PROTO_SCSI;
2944 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2945 cts.transport = XPORT_UNSPECIFIED;
2946 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2947 cts.proto_specific.scsi.flags = 0;
2948 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2949 scsi_set_transfer_settings(&cts, path,
2950 /*async_update*/TRUE);
2951 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2952 scsi_set_transfer_settings(&cts, path,
2953 /*async_update*/TRUE);
2958 * Handle any per-device event notifications that require action by the XPT.
2961 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2962 struct cam_ed *device, void *async_arg)
2965 struct cam_path newpath;
2968 * We only need to handle events for real devices.
2970 if (target->target_id == CAM_TARGET_WILDCARD
2971 || device->lun_id == CAM_LUN_WILDCARD)
2975 * We need our own path with wildcards expanded to
2976 * handle certain types of events.
2978 if ((async_code == AC_SENT_BDR)
2979 || (async_code == AC_BUS_RESET)
2980 || (async_code == AC_INQ_CHANGED))
2981 status = xpt_compile_path(&newpath, NULL,
2986 status = CAM_REQ_CMP_ERR;
2988 if (status == CAM_REQ_CMP) {
2991 * Allow transfer negotiation to occur in a
2992 * tag free environment and after settle delay.
2994 if (async_code == AC_SENT_BDR
2995 || async_code == AC_BUS_RESET) {
2996 cam_freeze_devq(&newpath);
2997 cam_release_devq(&newpath,
2998 RELSIM_RELEASE_AFTER_TIMEOUT,
3000 /*timeout*/scsi_delay,
3001 /*getcount_only*/0);
3002 scsi_toggle_tags(&newpath);
3005 if (async_code == AC_INQ_CHANGED) {
3007 * We've sent a start unit command, or
3008 * something similar to a device that
3009 * may have caused its inquiry data to
3010 * change. So we re-scan the device to
3011 * refresh the inquiry data for it.
3013 scsi_scan_lun(newpath.periph, &newpath,
3014 CAM_EXPECT_INQ_CHANGE, NULL);
3016 xpt_release_path(&newpath);
3017 } else if (async_code == AC_LOST_DEVICE &&
3018 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
3019 device->flags |= CAM_DEV_UNCONFIGURED;
3020 xpt_release_device(device);
3021 } else if (async_code == AC_TRANSFER_NEG) {
3022 struct ccb_trans_settings *settings;
3023 struct cam_path path;
3025 settings = (struct ccb_trans_settings *)async_arg;
3026 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
3028 scsi_set_transfer_settings(settings, &path,
3029 /*async_update*/TRUE);
3030 xpt_release_path(&path);
3035 _scsi_announce_periph(struct cam_periph *periph, u_int *speed, u_int *freq, struct ccb_trans_settings *cts)
3037 struct ccb_pathinq cpi;
3038 struct cam_path *path = periph->path;
3040 cam_periph_assert(periph, MA_OWNED);
3042 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
3043 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
3044 cts->type = CTS_TYPE_CURRENT_SETTINGS;
3045 xpt_action((union ccb*)cts);
3046 if (cam_ccb_status((union ccb *)cts) != CAM_REQ_CMP)
3049 /* Ask the SIM for its base transfer speed */
3050 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
3051 cpi.ccb_h.func_code = XPT_PATH_INQ;
3052 xpt_action((union ccb *)&cpi);
3054 /* Report connection speed */
3055 *speed = cpi.base_transfer_speed;
3058 if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_SPI) {
3059 struct ccb_trans_settings_spi *spi =
3060 &cts->xport_specific.spi;
3062 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
3063 && spi->sync_offset != 0) {
3064 *freq = scsi_calc_syncsrate(spi->sync_period);
3067 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
3068 *speed *= (0x01 << spi->bus_width);
3070 if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_FC) {
3071 struct ccb_trans_settings_fc *fc =
3072 &cts->xport_specific.fc;
3074 if (fc->valid & CTS_FC_VALID_SPEED)
3075 *speed = fc->bitrate;
3077 if (cts->ccb_h.status == CAM_REQ_CMP && cts->transport == XPORT_SAS) {
3078 struct ccb_trans_settings_sas *sas =
3079 &cts->xport_specific.sas;
3081 if (sas->valid & CTS_SAS_VALID_SPEED)
3082 *speed = sas->bitrate;
3087 scsi_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
3089 struct ccb_trans_settings cts;
3090 u_int speed, freq, mb;
3092 _scsi_announce_periph(periph, &speed, &freq, &cts);
3093 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
3098 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
3099 periph->periph_name, periph->unit_number,
3102 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
3103 periph->unit_number, speed);
3104 /* Report additional information about SPI connections */
3105 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3106 struct ccb_trans_settings_spi *spi;
3108 spi = &cts.xport_specific.spi;
3110 sbuf_printf(sb, " (%d.%03dMHz%s, offset %d", freq / 1000,
3112 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3116 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3117 && spi->bus_width > 0) {
3119 sbuf_printf(sb, ", ");
3121 sbuf_printf(sb, " (");
3123 sbuf_printf(sb, "%dbit)", 8 * (0x01 << spi->bus_width));
3124 } else if (freq != 0) {
3125 sbuf_printf(sb, ")");
3128 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3129 struct ccb_trans_settings_fc *fc;
3131 fc = &cts.xport_specific.fc;
3132 if (fc->valid & CTS_FC_VALID_WWNN)
3133 sbuf_printf(sb, " WWNN 0x%llx", (long long) fc->wwnn);
3134 if (fc->valid & CTS_FC_VALID_WWPN)
3135 sbuf_printf(sb, " WWPN 0x%llx", (long long) fc->wwpn);
3136 if (fc->valid & CTS_FC_VALID_PORT)
3137 sbuf_printf(sb, " PortID 0x%x", fc->port);
3139 sbuf_printf(sb, "\n");
3143 scsi_announce_periph(struct cam_periph *periph)
3145 struct ccb_trans_settings cts;
3146 u_int speed, freq, mb;
3148 _scsi_announce_periph(periph, &speed, &freq, &cts);
3149 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
3154 printf("%s%d: %d.%03dMB/s transfers",
3155 periph->periph_name, periph->unit_number,
3158 printf("%s%d: %dKB/s transfers", periph->periph_name,
3159 periph->unit_number, speed);
3160 /* Report additional information about SPI connections */
3161 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3162 struct ccb_trans_settings_spi *spi;
3164 spi = &cts.xport_specific.spi;
3166 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3168 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3172 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3173 && spi->bus_width > 0) {
3179 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3180 } else if (freq != 0) {
3184 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3185 struct ccb_trans_settings_fc *fc;
3187 fc = &cts.xport_specific.fc;
3188 if (fc->valid & CTS_FC_VALID_WWNN)
3189 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3190 if (fc->valid & CTS_FC_VALID_WWPN)
3191 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3192 if (fc->valid & CTS_FC_VALID_PORT)
3193 printf(" PortID 0x%x", fc->port);
3199 scsi_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
3201 scsi_print_inquiry_sbuf(sb, &device->inq_data);
3205 scsi_proto_announce(struct cam_ed *device)
3207 scsi_print_inquiry(&device->inq_data);
3211 scsi_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
3213 scsi_print_inquiry_short_sbuf(sb, &device->inq_data);
3217 scsi_proto_denounce(struct cam_ed *device)
3219 scsi_print_inquiry_short(&device->inq_data);
3223 scsi_proto_debug_out(union ccb *ccb)
3225 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3226 struct cam_ed *device;
3228 if (ccb->ccb_h.func_code != XPT_SCSI_IO)
3231 device = ccb->ccb_h.path->device;
3232 CAM_DEBUG(ccb->ccb_h.path,
3233 CAM_DEBUG_CDB,("%s. CDB: %s\n",
3234 scsi_op_desc(scsiio_cdb_ptr(&ccb->csio)[0], &device->inq_data),
3235 scsi_cdb_string(scsiio_cdb_ptr(&ccb->csio), cdb_str, sizeof(cdb_str))));