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 static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS);
82 SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT | CTLFLAG_RWTUN, 0, 0,
83 sysctl_cam_search_luns, "I",
84 "allow search above LUN 7 for SCSI3 and greater devices");
86 #define CAM_SCSI2_MAXLUN 8
87 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \
88 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
89 RPL_LUNDATA_ATYP_PERIPH) || \
90 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
91 RPL_LUNDATA_ATYP_FLAT))
92 #define CAM_GET_SIMPLE_LUN(lp, i, lval) \
93 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \
94 RPL_LUNDATA_ATYP_PERIPH) { \
95 (lval) = (lp)->luns[(i)].lundata[1]; \
97 (lval) = (lp)->luns[(i)].lundata[0]; \
98 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \
100 (lval) |= (lp)->luns[(i)].lundata[1]; \
102 #define CAM_GET_LUN(lp, i, lval) \
103 (lval) = scsi_8btou64((lp)->luns[(i)].lundata); \
104 (lval) = CAM_EXTLUN_BYTE_SWIZZLE(lval);
107 * If we're not quirked to search <= the first 8 luns
108 * and we are either quirked to search above lun 8,
109 * or we're > SCSI-2 and we've enabled hilun searching,
110 * or we're > SCSI-2 and the last lun was a success,
111 * we can look for luns above lun 8.
113 #define CAN_SRCH_HI_SPARSE(dv) \
114 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
115 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
116 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi)))
118 #define CAN_SRCH_HI_DENSE(dv) \
119 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \
120 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \
121 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2)))
123 static periph_init_t probe_periph_init;
125 static struct periph_driver probe_driver =
127 probe_periph_init, "probe",
128 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
132 PERIPHDRIVER_DECLARE(probe, probe_driver);
136 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */
140 PROBE_SUPPORTED_VPD_LIST,
142 PROBE_EXTENDED_INQUIRY,
144 PROBE_TUR_FOR_NEGOTIATION,
145 PROBE_INQUIRY_BASIC_DV1,
146 PROBE_INQUIRY_BASIC_DV2,
152 static char *probe_action_text[] = {
155 "PROBE_FULL_INQUIRY",
158 "PROBE_SUPPORTED_VPD_LIST",
160 "PROBE_EXTENDED_INQUIRY",
162 "PROBE_TUR_FOR_NEGOTIATION",
163 "PROBE_INQUIRY_BASIC_DV1",
164 "PROBE_INQUIRY_BASIC_DV2",
170 #define PROBE_SET_ACTION(softc, newaction) \
173 text = probe_action_text; \
174 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
175 ("Probe %s to %s\n", text[(softc)->action], \
176 text[(newaction)])); \
177 (softc)->action = (newaction); \
181 PROBE_INQUIRY_CKSUM = 0x01,
182 PROBE_SERIAL_CKSUM = 0x02,
183 PROBE_NO_ANNOUNCE = 0x04,
188 TAILQ_HEAD(, ccb_hdr) request_ccbs;
194 struct cam_periph *periph;
197 static const char quantum[] = "QUANTUM";
198 static const char sony[] = "SONY";
199 static const char west_digital[] = "WDIGTL";
200 static const char samsung[] = "SAMSUNG";
201 static const char seagate[] = "SEAGATE";
202 static const char microp[] = "MICROP";
204 static struct scsi_quirk_entry scsi_quirk_table[] =
207 /* Reports QUEUE FULL for temporary resource shortages */
208 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" },
209 /*quirks*/0, /*mintags*/24, /*maxtags*/32
212 /* Reports QUEUE FULL for temporary resource shortages */
213 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" },
214 /*quirks*/0, /*mintags*/24, /*maxtags*/32
217 /* Reports QUEUE FULL for temporary resource shortages */
218 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" },
219 /*quirks*/0, /*mintags*/24, /*maxtags*/32
222 /* Broken tagged queuing drive */
223 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" },
224 /*quirks*/0, /*mintags*/0, /*maxtags*/0
227 /* Broken tagged queuing drive */
228 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" },
229 /*quirks*/0, /*mintags*/0, /*maxtags*/0
232 /* Broken tagged queuing drive */
233 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" },
234 /*quirks*/0, /*mintags*/0, /*maxtags*/0
238 * Unfortunately, the Quantum Atlas III has the same
239 * problem as the Atlas II drives above.
240 * Reported by: "Johan Granlund" <johan@granlund.nu>
242 * For future reference, the drive with the problem was:
243 * QUANTUM QM39100TD-SW N1B0
245 * It's possible that Quantum will fix the problem in later
246 * firmware revisions. If that happens, the quirk entry
247 * will need to be made specific to the firmware revisions
251 /* Reports QUEUE FULL for temporary resource shortages */
252 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" },
253 /*quirks*/0, /*mintags*/24, /*maxtags*/32
257 * 18 Gig Atlas III, same problem as the 9G version.
258 * Reported by: Andre Albsmeier
259 * <andre.albsmeier@mchp.siemens.de>
261 * For future reference, the drive with the problem was:
262 * QUANTUM QM318000TD-S N491
264 /* Reports QUEUE FULL for temporary resource shortages */
265 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" },
266 /*quirks*/0, /*mintags*/24, /*maxtags*/32
270 * Broken tagged queuing drive
271 * Reported by: Bret Ford <bford@uop.cs.uop.edu>
272 * and: Martin Renters <martin@tdc.on.ca>
274 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" },
275 /*quirks*/0, /*mintags*/0, /*maxtags*/0
278 * The Seagate Medalist Pro drives have very poor write
279 * performance with anything more than 2 tags.
281 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl>
282 * Drive: <SEAGATE ST36530N 1444>
284 * Reported by: Jeremy Lea <reg@shale.csir.co.za>
285 * Drive: <SEAGATE ST34520W 1281>
287 * No one has actually reported that the 9G version
288 * (ST39140*) of the Medalist Pro has the same problem, but
289 * we're assuming that it does because the 4G and 6.5G
290 * versions of the drive are broken.
293 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"},
294 /*quirks*/0, /*mintags*/2, /*maxtags*/2
297 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"},
298 /*quirks*/0, /*mintags*/2, /*maxtags*/2
301 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"},
302 /*quirks*/0, /*mintags*/2, /*maxtags*/2
306 * Experiences command timeouts under load with a
307 * tag count higher than 55.
309 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"},
310 /*quirks*/0, /*mintags*/2, /*maxtags*/55
314 * Slow when tagged queueing is enabled. Write performance
315 * steadily drops off with more and more concurrent
316 * transactions. Best sequential write performance with
317 * tagged queueing turned off and write caching turned on.
320 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp>
321 * Drive: DCAS-34330 w/ "S65A" firmware.
323 * The drive with the problem had the "S65A" firmware
324 * revision, and has also been reported (by Stephen J.
325 * Roznowski <sjr@home.net>) for a drive with the "S61A"
328 * Although no one has reported problems with the 2 gig
329 * version of the DCAS drive, the assumption is that it
330 * has the same problems as the 4 gig version. Therefore
331 * this quirk entries disables tagged queueing for all
334 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" },
335 /*quirks*/0, /*mintags*/0, /*maxtags*/0
338 /* Broken tagged queuing drive */
339 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" },
340 /*quirks*/0, /*mintags*/0, /*maxtags*/0
343 /* Broken tagged queuing drive */
344 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" },
345 /*quirks*/0, /*mintags*/0, /*maxtags*/0
348 /* This does not support other than LUN 0 */
349 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" },
350 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
354 * Broken tagged queuing drive.
356 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp>
359 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" },
360 /*quirks*/0, /*mintags*/0, /*maxtags*/0
364 * Slow when tagged queueing is enabled. (1.5MB/sec versus
366 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
367 * Best performance with these drives is achieved with
368 * tagged queueing turned off, and write caching turned on.
370 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" },
371 /*quirks*/0, /*mintags*/0, /*maxtags*/0
375 * Slow when tagged queueing is enabled. (1.5MB/sec versus
377 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>
378 * Best performance with these drives is achieved with
379 * tagged queueing turned off, and write caching turned on.
381 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" },
382 /*quirks*/0, /*mintags*/0, /*maxtags*/0
386 * Doesn't handle queue full condition correctly,
387 * so we need to limit maxtags to what the device
388 * can handle instead of determining this automatically.
390 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" },
391 /*quirks*/0, /*mintags*/2, /*maxtags*/32
394 /* Really only one LUN */
395 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" },
396 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
399 /* I can't believe we need a quirk for DPT volumes. */
400 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" },
402 /*mintags*/0, /*maxtags*/255
406 * Many Sony CDROM drives don't like multi-LUN probing.
408 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" },
409 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
413 * This drive doesn't like multiple LUN probing.
414 * Submitted by: Parag Patel <parag@cgt.com>
416 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" },
417 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
420 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" },
421 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
425 * The 8200 doesn't like multi-lun probing, and probably
426 * don't like serial number requests either.
429 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
432 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
436 * Let's try the same as above, but for a drive that says
437 * it's an IPL-6860 but is actually an EXB 8200.
440 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE",
443 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
447 * These Hitachi drives don't like multi-lun probing.
448 * The PR submitter has a DK319H, but says that the Linux
449 * kernel has a similar work-around for the DK312 and DK314,
450 * so all DK31* drives are quirked here.
452 * Submitted by: Paul Haddad <paul@pth.com>
454 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" },
455 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255
459 * The Hitachi CJ series with J8A8 firmware apparently has
460 * problems with tagged commands.
462 * Reported by: amagai@nue.org
464 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" },
465 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
469 * These are the large storage arrays.
470 * Submitted by: William Carrel <william.carrel@infospace.com>
472 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" },
473 CAM_QUIRK_HILUNS, 2, 1024
477 * This old revision of the TDC3600 is also SCSI-1, and
478 * hangs upon serial number probing.
481 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG",
484 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0
488 * Would repond to all LUNs if asked for.
491 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER",
494 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
498 * Would repond to all LUNs if asked for.
501 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY",
504 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
507 /* Submitted by: Matthew Dodd <winter@jurai.net> */
508 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" },
509 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
512 /* Submitted by: Matthew Dodd <winter@jurai.net> */
513 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" },
514 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
517 /* TeraSolutions special settings for TRC-22 RAID */
518 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" },
519 /*quirks*/0, /*mintags*/55, /*maxtags*/255
522 /* Veritas Storage Appliance */
523 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" },
524 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024
528 * Would respond to all LUNs. Device type and removable
529 * flag are jumper-selectable.
531 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix",
534 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
537 /* EasyRAID E5A aka. areca ARC-6010 */
538 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" },
539 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255
542 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" },
543 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0
546 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" },
547 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255
550 /* Default tagged queuing parameters for all devices */
552 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
553 /*vendor*/"*", /*product*/"*", /*revision*/"*"
555 /*quirks*/0, /*mintags*/2, /*maxtags*/255
559 static cam_status proberegister(struct cam_periph *periph,
561 static void probeschedule(struct cam_periph *probe_periph);
562 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
563 static void proberequestdefaultnegotiation(struct cam_periph *periph);
564 static int proberequestbackoff(struct cam_periph *periph,
565 struct cam_ed *device);
566 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
567 static void probe_purge_old(struct cam_path *path,
568 struct scsi_report_luns_data *new,
570 static void probecleanup(struct cam_periph *periph);
571 static void scsi_find_quirk(struct cam_ed *device);
572 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
573 static void scsi_scan_lun(struct cam_periph *periph,
574 struct cam_path *path, cam_flags flags,
576 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
577 static struct cam_ed *
578 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
580 static void scsi_devise_transport(struct cam_path *path);
581 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
582 struct cam_path *path,
584 static void scsi_toggle_tags(struct cam_path *path);
585 static void scsi_dev_async(u_int32_t async_code,
587 struct cam_et *target,
588 struct cam_ed *device,
590 static void scsi_action(union ccb *start_ccb);
591 static void scsi_announce_periph(struct cam_periph *periph);
592 static void scsi_proto_announce(struct cam_ed *device);
593 static void scsi_proto_denounce(struct cam_ed *device);
594 static void scsi_proto_debug_out(union ccb *ccb);
596 static struct xpt_xport_ops scsi_xport_ops = {
597 .alloc_device = scsi_alloc_device,
598 .action = scsi_action,
599 .async = scsi_dev_async,
600 .announce = scsi_announce_periph,
602 #define SCSI_XPT_XPORT(x, X) \
603 static struct xpt_xport scsi_xport_ ## x = { \
604 .xport = XPORT_ ## X, \
606 .ops = &scsi_xport_ops, \
608 CAM_XPT_XPORT(scsi_xport_ ## x);
610 SCSI_XPT_XPORT(spi, SPI);
611 SCSI_XPT_XPORT(sas, SAS);
612 SCSI_XPT_XPORT(fc, FC);
613 SCSI_XPT_XPORT(usb, USB);
614 SCSI_XPT_XPORT(iscsi, ISCSI);
615 SCSI_XPT_XPORT(srp, SRP);
616 SCSI_XPT_XPORT(ppb, PPB);
618 #undef SCSI_XPORT_XPORT
620 static struct xpt_proto_ops scsi_proto_ops = {
621 .announce = scsi_proto_announce,
622 .denounce = scsi_proto_denounce,
623 .debug_out = scsi_proto_debug_out,
625 static struct xpt_proto scsi_proto = {
628 .ops = &scsi_proto_ops,
630 CAM_XPT_PROTO(scsi_proto);
638 proberegister(struct cam_periph *periph, void *arg)
640 union ccb *request_ccb; /* CCB representing the probe request */
644 request_ccb = (union ccb *)arg;
645 if (request_ccb == NULL) {
646 printf("proberegister: no probe CCB, "
647 "can't register device\n");
648 return(CAM_REQ_CMP_ERR);
651 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
654 printf("proberegister: Unable to probe new device. "
655 "Unable to allocate softc\n");
656 return(CAM_REQ_CMP_ERR);
658 TAILQ_INIT(&softc->request_ccbs);
659 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
662 periph->softc = softc;
663 softc->periph = periph;
664 softc->action = PROBE_INVALID;
665 status = cam_periph_acquire(periph);
666 if (status != CAM_REQ_CMP) {
669 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
670 scsi_devise_transport(periph->path);
673 * Ensure we've waited at least a bus settle
674 * delay before attempting to probe the device.
675 * For HBAs that don't do bus resets, this won't make a difference.
677 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
679 probeschedule(periph);
684 probeschedule(struct cam_periph *periph)
686 struct ccb_pathinq cpi;
690 softc = (probe_softc *)periph->softc;
691 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
693 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
694 cpi.ccb_h.func_code = XPT_PATH_INQ;
695 xpt_action((union ccb *)&cpi);
698 * If a device has gone away and another device, or the same one,
699 * is back in the same place, it should have a unit attention
700 * condition pending. It will not report the unit attention in
701 * response to an inquiry, which may leave invalid transfer
702 * negotiations in effect. The TUR will reveal the unit attention
703 * condition. Only send the TUR for lun 0, since some devices
704 * will get confused by commands other than inquiry to non-existent
705 * luns. If you think a device has gone away start your scan from
706 * lun 0. This will insure that any bogus transfer settings are
709 * If we haven't seen the device before and the controller supports
710 * some kind of transfer negotiation, negotiate with the first
711 * sent command if no bus reset was performed at startup. This
712 * ensures that the device is not confused by transfer negotiation
713 * settings left over by loader or BIOS action.
715 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
716 && (ccb->ccb_h.target_lun == 0)) {
717 PROBE_SET_ACTION(softc, PROBE_TUR);
718 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
719 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
720 proberequestdefaultnegotiation(periph);
721 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
723 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
726 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
727 softc->flags |= PROBE_NO_ANNOUNCE;
729 softc->flags &= ~PROBE_NO_ANNOUNCE;
731 if (cpi.hba_misc & PIM_EXTLUNS)
732 softc->flags |= PROBE_EXTLUN;
734 softc->flags &= ~PROBE_EXTLUN;
736 xpt_schedule(periph, CAM_PRIORITY_XPT);
740 probestart(struct cam_periph *periph, union ccb *start_ccb)
742 /* Probe the device that our peripheral driver points to */
743 struct ccb_scsiio *csio;
746 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
748 softc = (probe_softc *)periph->softc;
749 csio = &start_ccb->csio;
752 switch (softc->action) {
754 case PROBE_TUR_FOR_NEGOTIATION:
757 scsi_test_unit_ready(csio,
766 case PROBE_FULL_INQUIRY:
767 case PROBE_INQUIRY_BASIC_DV1:
768 case PROBE_INQUIRY_BASIC_DV2:
771 struct scsi_inquiry_data *inq_buf;
773 inq_buf = &periph->path->device->inq_data;
776 * If the device is currently configured, we calculate an
777 * MD5 checksum of the inquiry data, and if the serial number
778 * length is greater than 0, add the serial number data
779 * into the checksum as well. Once the inquiry and the
780 * serial number check finish, we attempt to figure out
781 * whether we still have the same device.
783 if (((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
784 && ((softc->flags & PROBE_INQUIRY_CKSUM) == 0)) {
786 MD5Init(&softc->context);
787 MD5Update(&softc->context, (unsigned char *)inq_buf,
788 sizeof(struct scsi_inquiry_data));
789 softc->flags |= PROBE_INQUIRY_CKSUM;
790 if (periph->path->device->serial_num_len > 0) {
791 MD5Update(&softc->context,
792 periph->path->device->serial_num,
793 periph->path->device->serial_num_len);
794 softc->flags |= PROBE_SERIAL_CKSUM;
796 MD5Final(softc->digest, &softc->context);
799 if (softc->action == PROBE_INQUIRY)
800 inquiry_len = SHORT_INQUIRY_LENGTH;
802 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
805 * Some parallel SCSI devices fail to send an
806 * ignore wide residue message when dealing with
807 * odd length inquiry requests. Round up to be
810 inquiry_len = roundup2(inquiry_len, 2);
812 if (softc->action == PROBE_INQUIRY_BASIC_DV1
813 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
814 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
816 if (inq_buf == NULL) {
817 xpt_print(periph->path, "malloc failure- skipping Basic"
818 "Domain Validation\n");
819 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
820 scsi_test_unit_ready(csio,
837 /*timeout*/60 * 1000);
840 case PROBE_REPORT_LUNS:
844 rp = malloc(periph->path->target->rpl_size,
845 M_CAMXPT, M_NOWAIT | M_ZERO);
847 struct scsi_inquiry_data *inq_buf;
848 inq_buf = &periph->path->device->inq_data;
849 xpt_print(periph->path,
850 "Unable to alloc report luns storage\n");
851 if (INQ_DATA_TQ_ENABLED(inq_buf))
852 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
854 PROBE_SET_ACTION(softc,
855 PROBE_SUPPORTED_VPD_LIST);
858 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
859 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
860 SSD_FULL_SIZE, 60000); break;
863 case PROBE_MODE_SENSE:
868 mode_buf_len = sizeof(struct scsi_mode_header_6)
869 + sizeof(struct scsi_mode_blk_desc)
870 + sizeof(struct scsi_control_page);
871 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
872 if (mode_buf != NULL) {
873 scsi_mode_sense(csio,
878 SMS_PAGE_CTRL_CURRENT,
879 SMS_CONTROL_MODE_PAGE,
886 xpt_print(periph->path, "Unable to mode sense control page - "
888 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
891 case PROBE_SUPPORTED_VPD_LIST:
893 struct scsi_vpd_supported_page_list *vpd_list;
894 struct cam_ed *device;
897 device = periph->path->device;
899 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
900 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
903 if (vpd_list != NULL) {
908 (u_int8_t *)vpd_list,
911 SVPD_SUPPORTED_PAGE_LIST,
913 /*timeout*/60 * 1000);
918 * We'll have to do without, let our probedone
919 * routine finish up for us.
921 start_ccb->csio.data_ptr = NULL;
922 cam_freeze_devq(periph->path);
923 cam_periph_doacquire(periph);
924 probedone(periph, start_ccb);
927 case PROBE_DEVICE_ID:
929 struct scsi_vpd_device_id *devid;
932 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
933 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
942 SVPD_DEVICE_ID_MAX_SIZE,
946 /*timeout*/60 * 1000);
951 case PROBE_EXTENDED_INQUIRY:
953 struct scsi_vpd_extended_inquiry_data *ext_inq;
956 if (scsi_vpd_supported_page(periph, SVPD_EXTENDED_INQUIRY_DATA))
957 ext_inq = malloc(sizeof(*ext_inq), M_CAMXPT,
960 if (ext_inq != NULL) {
968 SVPD_EXTENDED_INQUIRY_DATA,
970 /*timeout*/60 * 1000);
974 * We'll have to do without, let our probedone
975 * routine finish up for us.
979 case PROBE_SERIAL_NUM:
981 struct scsi_vpd_unit_serial_number *serial_buf;
982 struct cam_ed* device;
985 device = periph->path->device;
986 if (device->serial_num != NULL) {
987 free(device->serial_num, M_CAMXPT);
988 device->serial_num = NULL;
989 device->serial_num_len = 0;
992 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
993 serial_buf = (struct scsi_vpd_unit_serial_number *)
994 malloc(sizeof(*serial_buf), M_CAMXPT,
997 if (serial_buf != NULL) {
1002 (u_int8_t *)serial_buf,
1003 sizeof(*serial_buf),
1005 SVPD_UNIT_SERIAL_NUMBER,
1007 /*timeout*/60 * 1000);
1013 panic("probestart: invalid action state 0x%x\n", softc->action);
1015 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
1016 cam_periph_doacquire(periph);
1017 xpt_action(start_ccb);
1021 proberequestdefaultnegotiation(struct cam_periph *periph)
1023 struct ccb_trans_settings cts;
1025 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1026 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1027 cts.type = CTS_TYPE_USER_SETTINGS;
1028 xpt_action((union ccb *)&cts);
1029 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1032 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1033 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1034 xpt_action((union ccb *)&cts);
1038 * Backoff Negotiation Code- only pertinent for SPI devices.
1041 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1043 struct ccb_trans_settings cts;
1044 struct ccb_trans_settings_spi *spi;
1046 memset(&cts, 0, sizeof (cts));
1047 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1048 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1049 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1050 xpt_action((union ccb *)&cts);
1051 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1053 xpt_print(periph->path,
1054 "failed to get current device settings\n");
1058 if (cts.transport != XPORT_SPI) {
1060 xpt_print(periph->path, "not SPI transport\n");
1064 spi = &cts.xport_specific.spi;
1067 * We cannot renegotiate sync rate if we don't have one.
1069 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1071 xpt_print(periph->path, "no sync rate known\n");
1077 * We'll assert that we don't have to touch PPR options- the
1078 * SIM will see what we do with period and offset and adjust
1079 * the PPR options as appropriate.
1083 * A sync rate with unknown or zero offset is nonsensical.
1084 * A sync period of zero means Async.
1086 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1087 || spi->sync_offset == 0 || spi->sync_period == 0) {
1089 xpt_print(periph->path, "no sync rate available\n");
1094 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1095 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1096 ("hit async: giving up on DV\n"));
1102 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1103 * We don't try to remember 'last' settings to see if the SIM actually
1104 * gets into the speed we want to set. We check on the SIM telling
1105 * us that a requested speed is bad, but otherwise don't try and
1106 * check the speed due to the asynchronous and handshake nature
1109 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1112 if (spi->sync_period >= 0xf) {
1113 spi->sync_period = 0;
1114 spi->sync_offset = 0;
1115 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1116 ("setting to async for DV\n"));
1118 * Once we hit async, we don't want to try
1119 * any more settings.
1121 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1122 } else if (bootverbose) {
1123 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1124 ("DV: period 0x%x\n", spi->sync_period));
1125 printf("setting period to 0x%x\n", spi->sync_period);
1127 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1128 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1129 xpt_action((union ccb *)&cts);
1130 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1133 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1134 ("DV: failed to set period 0x%x\n", spi->sync_period));
1135 if (spi->sync_period == 0) {
1142 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1145 probedone(struct cam_periph *periph, union ccb *done_ccb)
1148 struct cam_path *path;
1149 struct scsi_inquiry_data *inq_buf;
1152 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1154 softc = (probe_softc *)periph->softc;
1155 path = done_ccb->ccb_h.path;
1156 priority = done_ccb->ccb_h.pinfo.priority;
1158 switch (softc->action) {
1161 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1163 if (cam_periph_error(done_ccb, 0,
1164 SF_NO_PRINT, NULL) == ERESTART) {
1166 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1167 cam_release_devq(path, 0, 0, 0, FALSE);
1170 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1171 /* Don't wedge the queue */
1172 xpt_release_devq(done_ccb->ccb_h.path,
1176 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1177 xpt_release_ccb(done_ccb);
1178 xpt_schedule(periph, priority);
1180 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1181 cam_release_devq(path, 0, 0, 0, FALSE);
1182 cam_periph_release_locked(periph);
1186 case PROBE_FULL_INQUIRY:
1188 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1189 u_int8_t periph_qual;
1191 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1192 scsi_find_quirk(path->device);
1193 inq_buf = &path->device->inq_data;
1195 periph_qual = SID_QUAL(inq_buf);
1197 if (periph_qual == SID_QUAL_LU_CONNECTED ||
1198 periph_qual == SID_QUAL_LU_OFFLINE) {
1202 * We conservatively request only
1203 * SHORT_INQUIRY_LEN bytes of inquiry
1204 * information during our first try
1205 * at sending an INQUIRY. If the device
1206 * has more information to give,
1207 * perform a second request specifying
1208 * the amount of information the device
1209 * is willing to give.
1211 len = inq_buf->additional_length
1212 + offsetof(struct scsi_inquiry_data,
1213 additional_length) + 1;
1214 if (softc->action == PROBE_INQUIRY
1215 && len > SHORT_INQUIRY_LENGTH) {
1216 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1217 xpt_release_ccb(done_ccb);
1218 xpt_schedule(periph, priority);
1222 scsi_devise_transport(path);
1224 if (path->device->lun_id == 0 &&
1225 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1226 (SCSI_QUIRK(path->device)->quirks &
1227 CAM_QUIRK_NORPTLUNS) == 0) {
1228 PROBE_SET_ACTION(softc,
1231 * Start with room for *one* lun.
1233 periph->path->target->rpl_size = 16;
1234 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1235 PROBE_SET_ACTION(softc,
1238 PROBE_SET_ACTION(softc,
1239 PROBE_SUPPORTED_VPD_LIST);
1241 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1242 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1243 xpt_acquire_device(path->device);
1245 xpt_release_ccb(done_ccb);
1246 xpt_schedule(periph, priority);
1248 } else if (path->device->lun_id == 0 &&
1249 SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 &&
1250 (SCSI_QUIRK(path->device)->quirks &
1251 CAM_QUIRK_NORPTLUNS) == 0) {
1252 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1253 periph->path->target->rpl_size = 16;
1254 xpt_release_ccb(done_ccb);
1255 xpt_schedule(periph, priority);
1258 } else if (cam_periph_error(done_ccb, 0,
1259 done_ccb->ccb_h.target_lun > 0
1260 ? SF_RETRY_UA|SF_QUIET_IR
1262 &softc->saved_ccb) == ERESTART) {
1265 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1266 /* Don't wedge the queue */
1267 xpt_release_devq(done_ccb->ccb_h.path,
1268 /*count*/1, /*run_queue*/TRUE);
1270 path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID;
1273 * If we get to this point, we got an error status back
1274 * from the inquiry and the error status doesn't require
1275 * automatically retrying the command. Therefore, the
1276 * inquiry failed. If we had inquiry information before
1277 * for this device, but this latest inquiry command failed,
1278 * the device has probably gone away. If this device isn't
1279 * already marked unconfigured, notify the peripheral
1280 * drivers that this device is no more.
1282 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1283 /* Send the async notification. */
1284 xpt_async(AC_LOST_DEVICE, path, NULL);
1285 PROBE_SET_ACTION(softc, PROBE_INVALID);
1287 xpt_release_ccb(done_ccb);
1290 case PROBE_REPORT_LUNS:
1292 struct ccb_scsiio *csio;
1293 struct scsi_report_luns_data *lp;
1296 csio = &done_ccb->csio;
1298 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1299 nlun = scsi_4btoul(lp->length) / 8;
1300 maxlun = (csio->dxfer_len / 8) - 1;
1302 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1303 if (cam_periph_error(done_ccb, 0,
1304 done_ccb->ccb_h.target_lun > 0 ?
1305 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1306 &softc->saved_ccb) == ERESTART) {
1309 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1310 xpt_release_devq(done_ccb->ccb_h.path, 1,
1315 } else if (nlun > maxlun) {
1317 * Reallocate and retry to cover all luns
1319 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1320 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1323 path->target->rpl_size = (nlun << 3) + 8;
1324 xpt_release_ccb(done_ccb);
1325 xpt_schedule(periph, priority);
1327 } else if (nlun == 0) {
1329 * If there don't appear to be any luns, bail.
1337 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1338 ("Probe: %u lun(s) reported\n", nlun));
1340 CAM_GET_LUN(lp, 0, lun);
1342 * If the first lun is not lun 0, then either there
1343 * is no lun 0 in the list, or the list is unsorted.
1346 for (idx = 0; idx < nlun; idx++) {
1347 CAM_GET_LUN(lp, idx, lun);
1355 lp->luns[0].lundata, 8);
1356 memcpy(lp->luns[0].lundata,
1357 lp->luns[idx].lundata, 8);
1358 memcpy(lp->luns[idx].lundata,
1360 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1361 ("lun 0 in position %u\n", idx));
1365 * If we have an old lun list, We can either
1366 * retest luns that appear to have been dropped,
1367 * or just nuke them. We'll opt for the latter.
1368 * This function will also install the new list
1369 * in the target structure.
1371 probe_purge_old(path, lp, softc->flags);
1374 inq_buf = &path->device->inq_data;
1375 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID &&
1376 (SID_QUAL(inq_buf) == SID_QUAL_LU_CONNECTED ||
1377 SID_QUAL(inq_buf) == SID_QUAL_LU_OFFLINE)) {
1378 if (INQ_DATA_TQ_ENABLED(inq_buf))
1379 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1381 PROBE_SET_ACTION(softc,
1382 PROBE_SUPPORTED_VPD_LIST);
1383 xpt_release_ccb(done_ccb);
1384 xpt_schedule(periph, priority);
1390 PROBE_SET_ACTION(softc, PROBE_INVALID);
1391 xpt_release_ccb(done_ccb);
1394 case PROBE_MODE_SENSE:
1396 struct ccb_scsiio *csio;
1397 struct scsi_mode_header_6 *mode_hdr;
1399 csio = &done_ccb->csio;
1400 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1401 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1402 struct scsi_control_page *page;
1405 offset = ((u_int8_t *)&mode_hdr[1])
1406 + mode_hdr->blk_desc_len;
1407 page = (struct scsi_control_page *)offset;
1408 path->device->queue_flags = page->queue_flags;
1409 } else if (cam_periph_error(done_ccb, 0,
1410 SF_RETRY_UA|SF_NO_PRINT,
1411 &softc->saved_ccb) == ERESTART) {
1413 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1414 /* Don't wedge the queue */
1415 xpt_release_devq(done_ccb->ccb_h.path,
1416 /*count*/1, /*run_queue*/TRUE);
1418 xpt_release_ccb(done_ccb);
1419 free(mode_hdr, M_CAMXPT);
1420 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1421 xpt_schedule(periph, priority);
1424 case PROBE_SUPPORTED_VPD_LIST:
1426 struct ccb_scsiio *csio;
1427 struct scsi_vpd_supported_page_list *page_list;
1429 csio = &done_ccb->csio;
1431 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1433 if (path->device->supported_vpds != NULL) {
1434 free(path->device->supported_vpds, M_CAMXPT);
1435 path->device->supported_vpds = NULL;
1436 path->device->supported_vpds_len = 0;
1439 if (page_list == NULL) {
1441 * Don't process the command as it was never sent
1443 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1445 path->device->supported_vpds_len = page_list->length +
1446 SVPD_SUPPORTED_PAGES_HDR_LEN;
1447 path->device->supported_vpds = (uint8_t *)page_list;
1448 xpt_release_ccb(done_ccb);
1449 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1450 xpt_schedule(periph, priority);
1452 } else if (cam_periph_error(done_ccb, 0,
1453 SF_RETRY_UA|SF_NO_PRINT,
1454 &softc->saved_ccb) == ERESTART) {
1456 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1457 /* Don't wedge the queue */
1458 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1463 free(page_list, M_CAMXPT);
1464 /* No VPDs available, skip to device check. */
1465 csio->data_ptr = NULL;
1466 goto probe_device_check;
1468 case PROBE_DEVICE_ID:
1470 struct scsi_vpd_device_id *devid;
1471 struct ccb_scsiio *csio;
1472 uint32_t length = 0;
1474 csio = &done_ccb->csio;
1475 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1477 /* Clean up from previous instance of this device */
1478 if (path->device->device_id != NULL) {
1479 path->device->device_id_len = 0;
1480 free(path->device->device_id, M_CAMXPT);
1481 path->device->device_id = NULL;
1484 if (devid == NULL) {
1485 /* Don't process the command as it was never sent */
1486 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1487 length = scsi_2btoul(devid->length);
1490 * NB: device_id_len is actual response
1491 * size, not buffer size.
1493 path->device->device_id_len = length +
1494 SVPD_DEVICE_ID_HDR_LEN;
1495 path->device->device_id = (uint8_t *)devid;
1497 } else if (cam_periph_error(done_ccb, 0,
1499 &softc->saved_ccb) == ERESTART) {
1501 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1502 /* Don't wedge the queue */
1503 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1507 /* Free the device id space if we don't use it */
1508 if (devid && length == 0)
1509 free(devid, M_CAMXPT);
1510 xpt_release_ccb(done_ccb);
1511 PROBE_SET_ACTION(softc, PROBE_EXTENDED_INQUIRY);
1512 xpt_schedule(periph, priority);
1515 case PROBE_EXTENDED_INQUIRY: {
1516 struct scsi_vpd_extended_inquiry_data *ext_inq;
1517 struct ccb_scsiio *csio;
1520 csio = &done_ccb->csio;
1521 ext_inq = (struct scsi_vpd_extended_inquiry_data *)
1523 if (path->device->ext_inq != NULL) {
1524 path->device->ext_inq_len = 0;
1525 free(path->device->ext_inq, M_CAMXPT);
1526 path->device->ext_inq = NULL;
1529 if (ext_inq == NULL) {
1530 /* Don't process the command as it was never sent */
1531 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1532 length = scsi_2btoul(ext_inq->page_length) +
1533 __offsetof(struct scsi_vpd_extended_inquiry_data,
1535 length = min(length, sizeof(*ext_inq));
1536 length -= csio->resid;
1538 path->device->ext_inq_len = length;
1539 path->device->ext_inq = (uint8_t *)ext_inq;
1541 } else if (cam_periph_error(done_ccb, 0,
1543 &softc->saved_ccb) == ERESTART) {
1545 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1546 /* Don't wedge the queue */
1547 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1551 /* Free the device id space if we don't use it */
1552 if (ext_inq && length <= 0)
1553 free(ext_inq, M_CAMXPT);
1554 xpt_release_ccb(done_ccb);
1555 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1556 xpt_schedule(periph, priority);
1561 case PROBE_SERIAL_NUM:
1563 struct ccb_scsiio *csio;
1564 struct scsi_vpd_unit_serial_number *serial_buf;
1571 csio = &done_ccb->csio;
1572 priority = done_ccb->ccb_h.pinfo.priority;
1574 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1576 if (serial_buf == NULL) {
1578 * Don't process the command as it was never sent
1580 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1581 && (serial_buf->length > 0)) {
1584 path->device->serial_num =
1585 (u_int8_t *)malloc((serial_buf->length + 1),
1586 M_CAMXPT, M_NOWAIT);
1587 if (path->device->serial_num != NULL) {
1590 start = strspn(serial_buf->serial_num, " ");
1591 slen = serial_buf->length - start;
1594 * SPC5r05 says that an all-space serial
1595 * number means no product serial number
1600 memcpy(path->device->serial_num,
1601 &serial_buf->serial_num[start], slen);
1602 path->device->serial_num_len = slen;
1603 path->device->serial_num[slen] = '\0';
1605 } else if (cam_periph_error(done_ccb, 0,
1606 SF_RETRY_UA|SF_NO_PRINT,
1607 &softc->saved_ccb) == ERESTART) {
1609 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1610 /* Don't wedge the queue */
1611 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1616 * Let's see if we have seen this device before.
1618 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1620 u_int8_t digest[16];
1625 (unsigned char *)&path->device->inq_data,
1626 sizeof(struct scsi_inquiry_data));
1629 MD5Update(&context, path->device->serial_num,
1630 path->device->serial_num_len);
1632 MD5Final(digest, &context);
1633 if (bcmp(softc->digest, digest, 16) == 0)
1637 * XXX Do we need to do a TUR in order to ensure
1638 * that the device really hasn't changed???
1641 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1642 xpt_async(AC_LOST_DEVICE, path, NULL);
1644 if (serial_buf != NULL)
1645 free(serial_buf, M_CAMXPT);
1649 * Now that we have all the necessary
1650 * information to safely perform transfer
1651 * negotiations... Controllers don't perform
1652 * any negotiation or tagged queuing until
1653 * after the first XPT_SET_TRAN_SETTINGS ccb is
1654 * received. So, on a new device, just retrieve
1655 * the user settings, and set them as the current
1656 * settings to set the device up.
1658 proberequestdefaultnegotiation(periph);
1659 xpt_release_ccb(done_ccb);
1662 * Perform a TUR to allow the controller to
1663 * perform any necessary transfer negotiation.
1665 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1666 xpt_schedule(periph, priority);
1669 xpt_release_ccb(done_ccb);
1672 case PROBE_TUR_FOR_NEGOTIATION:
1674 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1675 cam_periph_error(done_ccb, 0,
1676 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1678 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1679 /* Don't wedge the queue */
1680 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1684 * Do Domain Validation for lun 0 on devices that claim
1685 * to support Synchronous Transfer modes.
1687 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1688 && done_ccb->ccb_h.target_lun == 0
1689 && (path->device->inq_data.flags & SID_Sync) != 0
1690 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1691 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1692 ("Begin Domain Validation\n"));
1693 path->device->flags |= CAM_DEV_IN_DV;
1694 xpt_release_ccb(done_ccb);
1695 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1696 xpt_schedule(periph, priority);
1699 if (softc->action == PROBE_DV_EXIT) {
1700 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1701 ("Leave Domain Validation\n"));
1703 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1704 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1705 xpt_acquire_device(path->device);
1707 path->device->flags &=
1708 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1709 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1710 /* Inform the XPT that a new device has been found */
1711 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1712 xpt_action(done_ccb);
1713 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1716 PROBE_SET_ACTION(softc, PROBE_DONE);
1717 xpt_release_ccb(done_ccb);
1719 case PROBE_INQUIRY_BASIC_DV1:
1720 case PROBE_INQUIRY_BASIC_DV2:
1722 struct scsi_inquiry_data *nbuf;
1723 struct ccb_scsiio *csio;
1725 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1726 cam_periph_error(done_ccb, 0,
1727 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1729 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1730 /* Don't wedge the queue */
1731 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1734 csio = &done_ccb->csio;
1735 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1736 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1738 "inquiry data fails comparison at DV%d step\n",
1739 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1740 if (proberequestbackoff(periph, path->device)) {
1741 path->device->flags &= ~CAM_DEV_IN_DV;
1742 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1745 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1747 free(nbuf, M_CAMXPT);
1748 xpt_release_ccb(done_ccb);
1749 xpt_schedule(periph, priority);
1752 free(nbuf, M_CAMXPT);
1753 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1754 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1755 xpt_release_ccb(done_ccb);
1756 xpt_schedule(periph, priority);
1759 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1760 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1761 ("Leave Domain Validation Successfully\n"));
1763 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1764 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1765 xpt_acquire_device(path->device);
1767 path->device->flags &=
1768 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1769 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1770 /* Inform the XPT that a new device has been found */
1771 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1772 xpt_action(done_ccb);
1773 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1776 PROBE_SET_ACTION(softc, PROBE_DONE);
1777 xpt_release_ccb(done_ccb);
1781 panic("probedone: invalid action state 0x%x\n", softc->action);
1783 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1784 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1785 done_ccb->ccb_h.status = CAM_REQ_CMP;
1787 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1788 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1789 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1790 cam_release_devq(path, 0, 0, 0, FALSE);
1791 cam_periph_release_locked(periph);
1792 cam_periph_invalidate(periph);
1793 cam_periph_release_locked(periph);
1795 probeschedule(periph);
1801 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1804 struct cam_path *tp;
1805 struct scsi_report_luns_data *old;
1806 u_int idx1, idx2, nlun_old, nlun_new;
1810 if (path->target == NULL) {
1813 mtx_lock(&path->target->luns_mtx);
1814 old = path->target->luns;
1815 path->target->luns = new;
1816 mtx_unlock(&path->target->luns_mtx);
1819 nlun_old = scsi_4btoul(old->length) / 8;
1820 nlun_new = scsi_4btoul(new->length) / 8;
1823 * We are not going to assume sorted lists. Deal.
1825 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1826 ol = old->luns[idx1].lundata;
1827 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1828 nl = new->luns[idx2].lundata;
1829 if (memcmp(nl, ol, 8) == 0) {
1833 if (idx2 < nlun_new) {
1837 * An 'old' item not in the 'new' list.
1838 * Nuke it. Except that if it is lun 0,
1839 * that would be what the probe state
1840 * machine is currently working on,
1841 * so we won't do that.
1843 CAM_GET_LUN(old, idx1, this_lun);
1844 if (this_lun == 0) {
1849 * We also cannot nuke it if it is
1850 * not in a lun format we understand
1851 * and replace the LUN with a "simple" LUN
1852 * if that is all the HBA supports.
1854 if (!(flags & PROBE_EXTLUN)) {
1855 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1857 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1860 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1861 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1862 xpt_async(AC_LOST_DEVICE, tp, NULL);
1866 free(old, M_CAMXPT);
1870 probecleanup(struct cam_periph *periph)
1872 free(periph->softc, M_CAMXPT);
1876 scsi_find_quirk(struct cam_ed *device)
1878 struct scsi_quirk_entry *quirk;
1881 match = cam_quirkmatch((caddr_t)&device->inq_data,
1882 (caddr_t)scsi_quirk_table,
1883 nitems(scsi_quirk_table),
1884 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1887 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1889 quirk = (struct scsi_quirk_entry *)match;
1890 device->quirk = quirk;
1891 device->mintags = quirk->mintags;
1892 device->maxtags = quirk->maxtags;
1896 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1901 error = sysctl_handle_int(oidp, &val, 0, req);
1902 if (error != 0 || req->newptr == NULL)
1904 if (val == 0 || val == 1) {
1913 union ccb *request_ccb;
1914 struct ccb_pathinq *cpi;
1917 } scsi_scan_bus_info;
1920 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1921 * As the scan progresses, scsi_scan_bus is used as the
1922 * callback on completion function.
1925 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1929 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1930 ("scsi_scan_bus\n"));
1931 switch (request_ccb->ccb_h.func_code) {
1935 scsi_scan_bus_info *scan_info;
1936 union ccb *work_ccb, *reset_ccb;
1937 struct cam_path *path;
1939 u_int low_target, max_target;
1942 /* Find out the characteristics of the bus */
1943 work_ccb = xpt_alloc_ccb_nowait();
1944 if (work_ccb == NULL) {
1945 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1946 xpt_done(request_ccb);
1949 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1950 request_ccb->ccb_h.pinfo.priority);
1951 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1952 xpt_action(work_ccb);
1953 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1954 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1955 xpt_free_ccb(work_ccb);
1956 xpt_done(request_ccb);
1960 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1962 * Can't scan the bus on an adapter that
1963 * cannot perform the initiator role.
1965 request_ccb->ccb_h.status = CAM_REQ_CMP;
1966 xpt_free_ccb(work_ccb);
1967 xpt_done(request_ccb);
1971 /* We may need to reset bus first, if we haven't done it yet. */
1972 if ((work_ccb->cpi.hba_inquiry &
1973 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1974 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1975 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1976 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1977 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1979 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1980 xpt_action(reset_ccb);
1981 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1982 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1983 xpt_free_ccb(reset_ccb);
1984 xpt_free_ccb(work_ccb);
1985 xpt_done(request_ccb);
1988 xpt_free_ccb(reset_ccb);
1991 /* Save some state for use while we probe for devices */
1992 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1993 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1994 if (scan_info == NULL) {
1995 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1996 xpt_free_ccb(work_ccb);
1997 xpt_done(request_ccb);
2000 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
2001 ("SCAN start for %p\n", scan_info));
2002 scan_info->request_ccb = request_ccb;
2003 scan_info->cpi = &work_ccb->cpi;
2005 /* Cache on our stack so we can work asynchronously */
2006 max_target = scan_info->cpi->max_target;
2008 initiator_id = scan_info->cpi->initiator_id;
2012 * We can scan all targets in parallel, or do it sequentially.
2015 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2016 max_target = low_target = request_ccb->ccb_h.target_id;
2017 scan_info->counter = 0;
2018 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2020 scan_info->counter = 0;
2022 scan_info->counter = scan_info->cpi->max_target + 1;
2023 if (scan_info->cpi->initiator_id < scan_info->counter) {
2024 scan_info->counter--;
2027 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2030 for (i = low_target; i <= max_target; i++) {
2032 if (i == initiator_id)
2035 status = xpt_create_path(&path, NULL,
2036 request_ccb->ccb_h.path_id,
2038 if (status != CAM_REQ_CMP) {
2039 printf("scsi_scan_bus: xpt_create_path failed"
2040 " with status %#x, bus scan halted\n",
2042 free(scan_info, M_CAMXPT);
2043 request_ccb->ccb_h.status = status;
2044 xpt_free_ccb(work_ccb);
2045 xpt_done(request_ccb);
2048 work_ccb = xpt_alloc_ccb_nowait();
2049 if (work_ccb == NULL) {
2050 xpt_free_ccb((union ccb *)scan_info->cpi);
2051 free(scan_info, M_CAMXPT);
2052 xpt_free_path(path);
2053 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2054 xpt_done(request_ccb);
2057 xpt_setup_ccb(&work_ccb->ccb_h, path,
2058 request_ccb->ccb_h.pinfo.priority);
2059 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2060 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2061 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
2062 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
2063 work_ccb->crcn.flags = request_ccb->crcn.flags;
2064 xpt_action(work_ccb);
2073 struct cam_path *path, *oldpath;
2074 scsi_scan_bus_info *scan_info;
2075 struct cam_et *target;
2076 struct cam_ed *device, *nextdev;
2079 target_id_t target_id;
2082 oldpath = request_ccb->ccb_h.path;
2084 status = cam_ccb_status(request_ccb);
2085 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
2086 path_id = request_ccb->ccb_h.path_id;
2087 target_id = request_ccb->ccb_h.target_id;
2088 lun_id = request_ccb->ccb_h.target_lun;
2089 target = request_ccb->ccb_h.path->target;
2092 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2094 mtx_lock(&target->luns_mtx);
2097 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2100 * Make sure we skip over lun 0 if it's the first member
2101 * of the list as we've actually just finished probing
2104 CAM_GET_LUN(target->luns, 0, first);
2105 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2106 scan_info->lunindex[target_id]++;
2110 * Skip any LUNs that the HBA can't deal with.
2112 while (scan_info->lunindex[target_id] < nluns) {
2113 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2114 CAM_GET_LUN(target->luns,
2115 scan_info->lunindex[target_id],
2120 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2121 scan_info->lunindex[target_id])) {
2122 CAM_GET_SIMPLE_LUN(target->luns,
2123 scan_info->lunindex[target_id],
2128 scan_info->lunindex[target_id]++;
2131 if (scan_info->lunindex[target_id] < nluns) {
2132 mtx_unlock(&target->luns_mtx);
2134 CAM_DEBUG(request_ccb->ccb_h.path,
2136 ("next lun to try at index %u is %jx\n",
2137 scan_info->lunindex[target_id],
2138 (uintmax_t)lun_id));
2139 scan_info->lunindex[target_id]++;
2141 mtx_unlock(&target->luns_mtx);
2142 /* We're done with scanning all luns. */
2145 mtx_unlock(&target->luns_mtx);
2146 device = request_ccb->ccb_h.path->device;
2147 /* Continue sequential LUN scan if: */
2148 /* -- we have more LUNs that need recheck */
2149 mtx_lock(&target->bus->eb_mtx);
2151 while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL)
2152 if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0)
2154 mtx_unlock(&target->bus->eb_mtx);
2155 if (nextdev != NULL) {
2157 /* -- stop if CAM_QUIRK_NOLUNS is set. */
2158 } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) {
2160 /* -- this LUN is connected and its SCSI version
2161 * allows more LUNs. */
2162 } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2163 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2164 CAN_SRCH_HI_DENSE(device))
2166 /* -- this LUN is disconnected, its SCSI version
2167 * allows more LUNs and we guess they may be. */
2168 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) {
2169 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2170 CAN_SRCH_HI_SPARSE(device))
2173 if (next_target == 0) {
2175 if (lun_id > scan_info->cpi->max_lun)
2181 * Check to see if we scan any further luns.
2187 * Free the current request path- we're done with it.
2189 xpt_free_path(oldpath);
2192 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2194 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2195 scan_info->counter++;
2196 if (scan_info->counter ==
2197 scan_info->cpi->initiator_id) {
2198 scan_info->counter++;
2200 if (scan_info->counter >=
2201 scan_info->cpi->max_target+1) {
2205 scan_info->counter--;
2206 if (scan_info->counter == 0) {
2212 xpt_free_ccb(request_ccb);
2213 xpt_free_ccb((union ccb *)scan_info->cpi);
2214 request_ccb = scan_info->request_ccb;
2215 CAM_DEBUG(request_ccb->ccb_h.path,
2217 ("SCAN done for %p\n", scan_info));
2218 free(scan_info, M_CAMXPT);
2219 request_ccb->ccb_h.status = CAM_REQ_CMP;
2220 xpt_done(request_ccb);
2224 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2226 xpt_free_ccb(request_ccb);
2229 status = xpt_create_path(&path, NULL,
2230 scan_info->request_ccb->ccb_h.path_id,
2231 scan_info->counter, 0);
2232 if (status != CAM_REQ_CMP) {
2234 printf("scsi_scan_bus: xpt_create_path failed"
2235 " with status %#x, bus scan halted\n",
2237 xpt_free_ccb(request_ccb);
2238 xpt_free_ccb((union ccb *)scan_info->cpi);
2239 request_ccb = scan_info->request_ccb;
2240 free(scan_info, M_CAMXPT);
2241 request_ccb->ccb_h.status = status;
2242 xpt_done(request_ccb);
2245 xpt_setup_ccb(&request_ccb->ccb_h, path,
2246 request_ccb->ccb_h.pinfo.priority);
2247 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2248 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2249 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2250 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2251 request_ccb->crcn.flags =
2252 scan_info->request_ccb->crcn.flags;
2254 status = xpt_create_path(&path, NULL,
2255 path_id, target_id, lun_id);
2257 * Free the old request path- we're done with it. We
2258 * do this *after* creating the new path so that
2259 * we don't remove a target that has our lun list
2260 * in the case that lun 0 is not present.
2262 xpt_free_path(oldpath);
2263 if (status != CAM_REQ_CMP) {
2264 printf("scsi_scan_bus: xpt_create_path failed "
2265 "with status %#x, halting LUN scan\n",
2269 xpt_setup_ccb(&request_ccb->ccb_h, path,
2270 request_ccb->ccb_h.pinfo.priority);
2271 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2272 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2273 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2274 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2275 request_ccb->crcn.flags =
2276 scan_info->request_ccb->crcn.flags;
2279 xpt_action(request_ccb);
2288 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2289 cam_flags flags, union ccb *request_ccb)
2291 struct ccb_pathinq cpi;
2293 struct cam_path *new_path;
2294 struct cam_periph *old_periph;
2297 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2299 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2300 cpi.ccb_h.func_code = XPT_PATH_INQ;
2301 xpt_action((union ccb *)&cpi);
2303 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2304 if (request_ccb != NULL) {
2305 request_ccb->ccb_h.status = cpi.ccb_h.status;
2306 xpt_done(request_ccb);
2311 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2313 * Can't scan the bus on an adapter that
2314 * cannot perform the initiator role.
2316 if (request_ccb != NULL) {
2317 request_ccb->ccb_h.status = CAM_REQ_CMP;
2318 xpt_done(request_ccb);
2323 if (request_ccb == NULL) {
2324 request_ccb = xpt_alloc_ccb_nowait();
2325 if (request_ccb == NULL) {
2326 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2327 "can't continue\n");
2330 status = xpt_create_path(&new_path, NULL,
2332 path->target->target_id,
2333 path->device->lun_id);
2334 if (status != CAM_REQ_CMP) {
2335 xpt_print(path, "scsi_scan_lun: can't create path, "
2336 "can't continue\n");
2337 xpt_free_ccb(request_ccb);
2340 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2341 request_ccb->ccb_h.cbfcnp = xptscandone;
2342 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2343 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2344 request_ccb->crcn.flags = flags;
2347 lock = (xpt_path_owned(path) == 0);
2349 xpt_path_lock(path);
2350 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2351 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2354 softc = (probe_softc *)old_periph->softc;
2355 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2356 &request_ccb->ccb_h, periph_links.tqe);
2358 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2359 xpt_done(request_ccb);
2362 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2363 probestart, "probe",
2365 request_ccb->ccb_h.path, NULL, 0,
2368 if (status != CAM_REQ_CMP) {
2369 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2370 "returned an error, can't continue probe\n");
2371 request_ccb->ccb_h.status = status;
2372 xpt_done(request_ccb);
2376 xpt_path_unlock(path);
2380 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2383 xpt_free_path(done_ccb->ccb_h.path);
2384 xpt_free_ccb(done_ccb);
2387 static struct cam_ed *
2388 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2390 struct scsi_quirk_entry *quirk;
2391 struct cam_ed *device;
2393 device = xpt_alloc_device(bus, target, lun_id);
2398 * Take the default quirk entry until we have inquiry
2399 * data and can determine a better quirk to use.
2401 quirk = &scsi_quirk_table[nitems(scsi_quirk_table) - 1];
2402 device->quirk = (void *)quirk;
2403 device->mintags = quirk->mintags;
2404 device->maxtags = quirk->maxtags;
2405 bzero(&device->inq_data, sizeof(device->inq_data));
2406 device->inq_flags = 0;
2407 device->queue_flags = 0;
2408 device->serial_num = NULL;
2409 device->serial_num_len = 0;
2410 device->device_id = NULL;
2411 device->device_id_len = 0;
2412 device->supported_vpds = NULL;
2413 device->supported_vpds_len = 0;
2418 scsi_devise_transport(struct cam_path *path)
2420 struct ccb_pathinq cpi;
2421 struct ccb_trans_settings cts;
2422 struct scsi_inquiry_data *inq_buf;
2424 /* Get transport information from the SIM */
2425 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2426 cpi.ccb_h.func_code = XPT_PATH_INQ;
2427 xpt_action((union ccb *)&cpi);
2430 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2431 inq_buf = &path->device->inq_data;
2432 path->device->protocol = PROTO_SCSI;
2433 path->device->protocol_version =
2434 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2435 path->device->transport = cpi.transport;
2436 path->device->transport_version = cpi.transport_version;
2439 * Any device not using SPI3 features should
2440 * be considered SPI2 or lower.
2442 if (inq_buf != NULL) {
2443 if (path->device->transport == XPORT_SPI
2444 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2445 && path->device->transport_version > 2)
2446 path->device->transport_version = 2;
2448 struct cam_ed* otherdev;
2450 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2452 otherdev = TAILQ_NEXT(otherdev, links)) {
2453 if (otherdev != path->device)
2457 if (otherdev != NULL) {
2459 * Initially assume the same versioning as
2460 * prior luns for this target.
2462 path->device->protocol_version =
2463 otherdev->protocol_version;
2464 path->device->transport_version =
2465 otherdev->transport_version;
2467 /* Until we know better, opt for safety */
2468 path->device->protocol_version = 2;
2469 if (path->device->transport == XPORT_SPI)
2470 path->device->transport_version = 2;
2472 path->device->transport_version = 0;
2478 * For a device compliant with SPC-2 we should be able
2479 * to determine the transport version supported by
2480 * scrutinizing the version descriptors in the
2484 /* Tell the controller what we think */
2485 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2486 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2487 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2488 cts.transport = path->device->transport;
2489 cts.transport_version = path->device->transport_version;
2490 cts.protocol = path->device->protocol;
2491 cts.protocol_version = path->device->protocol_version;
2492 cts.proto_specific.valid = 0;
2493 cts.xport_specific.valid = 0;
2494 xpt_action((union ccb *)&cts);
2498 scsi_dev_advinfo(union ccb *start_ccb)
2500 struct cam_ed *device;
2501 struct ccb_dev_advinfo *cdai;
2504 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2505 device = start_ccb->ccb_h.path->device;
2506 cdai = &start_ccb->cdai;
2507 switch(cdai->buftype) {
2508 case CDAI_TYPE_SCSI_DEVID:
2509 if (cdai->flags & CDAI_FLAG_STORE)
2511 cdai->provsiz = device->device_id_len;
2512 if (device->device_id_len == 0)
2514 amt = device->device_id_len;
2515 if (cdai->provsiz > cdai->bufsiz)
2517 memcpy(cdai->buf, device->device_id, amt);
2519 case CDAI_TYPE_SERIAL_NUM:
2520 if (cdai->flags & CDAI_FLAG_STORE)
2522 cdai->provsiz = device->serial_num_len;
2523 if (device->serial_num_len == 0)
2525 amt = device->serial_num_len;
2526 if (cdai->provsiz > cdai->bufsiz)
2528 memcpy(cdai->buf, device->serial_num, amt);
2530 case CDAI_TYPE_PHYS_PATH:
2531 if (cdai->flags & CDAI_FLAG_STORE) {
2532 if (device->physpath != NULL) {
2533 free(device->physpath, M_CAMXPT);
2534 device->physpath = NULL;
2536 device->physpath_len = cdai->bufsiz;
2537 /* Clear existing buffer if zero length */
2538 if (cdai->bufsiz == 0)
2540 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2541 if (device->physpath == NULL) {
2542 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2545 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2547 cdai->provsiz = device->physpath_len;
2548 if (device->physpath_len == 0)
2550 amt = device->physpath_len;
2551 if (cdai->provsiz > cdai->bufsiz)
2553 memcpy(cdai->buf, device->physpath, amt);
2556 case CDAI_TYPE_RCAPLONG:
2557 if (cdai->flags & CDAI_FLAG_STORE) {
2558 if (device->rcap_buf != NULL) {
2559 free(device->rcap_buf, M_CAMXPT);
2560 device->rcap_buf = NULL;
2563 device->rcap_len = cdai->bufsiz;
2564 /* Clear existing buffer if zero length */
2565 if (cdai->bufsiz == 0)
2568 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2570 if (device->rcap_buf == NULL) {
2571 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2575 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2577 cdai->provsiz = device->rcap_len;
2578 if (device->rcap_len == 0)
2580 amt = device->rcap_len;
2581 if (cdai->provsiz > cdai->bufsiz)
2583 memcpy(cdai->buf, device->rcap_buf, amt);
2586 case CDAI_TYPE_EXT_INQ:
2588 * We fetch extended inquiry data during probe, if
2589 * available. We don't allow changing it.
2591 if (cdai->flags & CDAI_FLAG_STORE)
2593 cdai->provsiz = device->ext_inq_len;
2594 if (device->ext_inq_len == 0)
2596 amt = device->ext_inq_len;
2597 if (cdai->provsiz > cdai->bufsiz)
2599 memcpy(cdai->buf, device->ext_inq, amt);
2604 start_ccb->ccb_h.status = CAM_REQ_CMP;
2606 if (cdai->flags & CDAI_FLAG_STORE) {
2607 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2608 (void *)(uintptr_t)cdai->buftype);
2613 scsi_action(union ccb *start_ccb)
2616 switch (start_ccb->ccb_h.func_code) {
2617 case XPT_SET_TRAN_SETTINGS:
2619 scsi_set_transfer_settings(&start_ccb->cts,
2620 start_ccb->ccb_h.path,
2621 /*async_update*/FALSE);
2626 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2629 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2630 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2633 case XPT_DEV_ADVINFO:
2635 scsi_dev_advinfo(start_ccb);
2639 xpt_action_default(start_ccb);
2645 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2648 struct ccb_pathinq cpi;
2649 struct ccb_trans_settings cur_cts;
2650 struct ccb_trans_settings_scsi *scsi;
2651 struct ccb_trans_settings_scsi *cur_scsi;
2652 struct scsi_inquiry_data *inq_data;
2653 struct cam_ed *device;
2655 if (path == NULL || (device = path->device) == NULL) {
2656 cts->ccb_h.status = CAM_PATH_INVALID;
2657 xpt_done((union ccb *)cts);
2661 if (cts->protocol == PROTO_UNKNOWN
2662 || cts->protocol == PROTO_UNSPECIFIED) {
2663 cts->protocol = device->protocol;
2664 cts->protocol_version = device->protocol_version;
2667 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2668 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2669 cts->protocol_version = device->protocol_version;
2671 if (cts->protocol != device->protocol) {
2672 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2673 cts->protocol, device->protocol);
2674 cts->protocol = device->protocol;
2677 if (cts->protocol_version > device->protocol_version) {
2679 xpt_print(path, "Down reving Protocol "
2680 "Version from %d to %d?\n", cts->protocol_version,
2681 device->protocol_version);
2683 cts->protocol_version = device->protocol_version;
2686 if (cts->transport == XPORT_UNKNOWN
2687 || cts->transport == XPORT_UNSPECIFIED) {
2688 cts->transport = device->transport;
2689 cts->transport_version = device->transport_version;
2692 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2693 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2694 cts->transport_version = device->transport_version;
2696 if (cts->transport != device->transport) {
2697 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2698 cts->transport, device->transport);
2699 cts->transport = device->transport;
2702 if (cts->transport_version > device->transport_version) {
2704 xpt_print(path, "Down reving Transport "
2705 "Version from %d to %d?\n", cts->transport_version,
2706 device->transport_version);
2708 cts->transport_version = device->transport_version;
2712 * Nothing more of interest to do unless
2713 * this is a device connected via the
2716 if (cts->protocol != PROTO_SCSI) {
2717 if (async_update == FALSE)
2718 xpt_action_default((union ccb *)cts);
2722 inq_data = &device->inq_data;
2723 scsi = &cts->proto_specific.scsi;
2724 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2725 cpi.ccb_h.func_code = XPT_PATH_INQ;
2726 xpt_action((union ccb *)&cpi);
2728 /* SCSI specific sanity checking */
2729 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2730 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2731 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2732 || (device->mintags == 0)) {
2734 * Can't tag on hardware that doesn't support tags,
2735 * doesn't have it enabled, or has broken tag support.
2737 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2740 if (async_update == FALSE) {
2742 * Perform sanity checking against what the
2743 * controller and device can do.
2745 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2746 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2747 cur_cts.type = cts->type;
2748 xpt_action((union ccb *)&cur_cts);
2749 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2752 cur_scsi = &cur_cts.proto_specific.scsi;
2753 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2754 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2755 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2757 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2758 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2761 /* SPI specific sanity checking */
2762 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2764 struct ccb_trans_settings_spi *spi;
2765 struct ccb_trans_settings_spi *cur_spi;
2767 spi = &cts->xport_specific.spi;
2769 cur_spi = &cur_cts.xport_specific.spi;
2771 /* Fill in any gaps in what the user gave us */
2772 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2773 spi->sync_period = cur_spi->sync_period;
2774 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2775 spi->sync_period = 0;
2776 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2777 spi->sync_offset = cur_spi->sync_offset;
2778 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2779 spi->sync_offset = 0;
2780 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2781 spi->ppr_options = cur_spi->ppr_options;
2782 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2783 spi->ppr_options = 0;
2784 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2785 spi->bus_width = cur_spi->bus_width;
2786 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2788 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2789 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2790 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2792 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2793 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2794 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2795 && (inq_data->flags & SID_Sync) == 0
2796 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2797 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2799 spi->sync_period = 0;
2800 spi->sync_offset = 0;
2803 switch (spi->bus_width) {
2804 case MSG_EXT_WDTR_BUS_32_BIT:
2805 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2806 || (inq_data->flags & SID_WBus32) != 0
2807 || cts->type == CTS_TYPE_USER_SETTINGS)
2808 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2810 /* Fall Through to 16-bit */
2811 case MSG_EXT_WDTR_BUS_16_BIT:
2812 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2813 || (inq_data->flags & SID_WBus16) != 0
2814 || cts->type == CTS_TYPE_USER_SETTINGS)
2815 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2816 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2819 /* Fall Through to 8-bit */
2820 default: /* New bus width?? */
2821 case MSG_EXT_WDTR_BUS_8_BIT:
2822 /* All targets can do this */
2823 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2827 spi3caps = cpi.xport_specific.spi.ppr_options;
2828 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2829 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2830 spi3caps &= inq_data->spi3data;
2832 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2833 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2835 if ((spi3caps & SID_SPI_IUS) == 0)
2836 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2838 if ((spi3caps & SID_SPI_QAS) == 0)
2839 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2841 /* No SPI Transfer settings are allowed unless we are wide */
2842 if (spi->bus_width == 0)
2843 spi->ppr_options = 0;
2845 if ((spi->valid & CTS_SPI_VALID_DISC)
2846 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2848 * Can't tag queue without disconnection.
2850 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2851 scsi->valid |= CTS_SCSI_VALID_TQ;
2855 * If we are currently performing tagged transactions to
2856 * this device and want to change its negotiation parameters,
2857 * go non-tagged for a bit to give the controller a chance to
2858 * negotiate unhampered by tag messages.
2860 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2861 && (device->inq_flags & SID_CmdQue) != 0
2862 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2863 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2864 CTS_SPI_VALID_SYNC_OFFSET|
2865 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2866 scsi_toggle_tags(path);
2869 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2870 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2874 * If we are transitioning from tags to no-tags or
2875 * vice-versa, we need to carefully freeze and restart
2876 * the queue so that we don't overlap tagged and non-tagged
2877 * commands. We also temporarily stop tags if there is
2878 * a change in transfer negotiation settings to allow
2879 * "tag-less" negotiation.
2881 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2882 || (device->inq_flags & SID_CmdQue) != 0)
2883 device_tagenb = TRUE;
2885 device_tagenb = FALSE;
2887 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2888 && device_tagenb == FALSE)
2889 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2890 && device_tagenb == TRUE)) {
2892 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2894 * Delay change to use tags until after a
2895 * few commands have gone to this device so
2896 * the controller has time to perform transfer
2897 * negotiations without tagged messages getting
2900 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2901 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2903 xpt_stop_tags(path);
2907 if (async_update == FALSE)
2908 xpt_action_default((union ccb *)cts);
2912 scsi_toggle_tags(struct cam_path *path)
2917 * Give controllers a chance to renegotiate
2918 * before starting tag operations. We
2919 * "toggle" tagged queuing off then on
2920 * which causes the tag enable command delay
2921 * counter to come into effect.
2924 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2925 || ((dev->inq_flags & SID_CmdQue) != 0
2926 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2927 struct ccb_trans_settings cts;
2929 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2930 cts.protocol = PROTO_SCSI;
2931 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2932 cts.transport = XPORT_UNSPECIFIED;
2933 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2934 cts.proto_specific.scsi.flags = 0;
2935 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2936 scsi_set_transfer_settings(&cts, path,
2937 /*async_update*/TRUE);
2938 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2939 scsi_set_transfer_settings(&cts, path,
2940 /*async_update*/TRUE);
2945 * Handle any per-device event notifications that require action by the XPT.
2948 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2949 struct cam_ed *device, void *async_arg)
2952 struct cam_path newpath;
2955 * We only need to handle events for real devices.
2957 if (target->target_id == CAM_TARGET_WILDCARD
2958 || device->lun_id == CAM_LUN_WILDCARD)
2962 * We need our own path with wildcards expanded to
2963 * handle certain types of events.
2965 if ((async_code == AC_SENT_BDR)
2966 || (async_code == AC_BUS_RESET)
2967 || (async_code == AC_INQ_CHANGED))
2968 status = xpt_compile_path(&newpath, NULL,
2973 status = CAM_REQ_CMP_ERR;
2975 if (status == CAM_REQ_CMP) {
2978 * Allow transfer negotiation to occur in a
2979 * tag free environment and after settle delay.
2981 if (async_code == AC_SENT_BDR
2982 || async_code == AC_BUS_RESET) {
2983 cam_freeze_devq(&newpath);
2984 cam_release_devq(&newpath,
2985 RELSIM_RELEASE_AFTER_TIMEOUT,
2987 /*timeout*/scsi_delay,
2988 /*getcount_only*/0);
2989 scsi_toggle_tags(&newpath);
2992 if (async_code == AC_INQ_CHANGED) {
2994 * We've sent a start unit command, or
2995 * something similar to a device that
2996 * may have caused its inquiry data to
2997 * change. So we re-scan the device to
2998 * refresh the inquiry data for it.
3000 scsi_scan_lun(newpath.periph, &newpath,
3001 CAM_EXPECT_INQ_CHANGE, NULL);
3003 xpt_release_path(&newpath);
3004 } else if (async_code == AC_LOST_DEVICE &&
3005 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
3006 device->flags |= CAM_DEV_UNCONFIGURED;
3007 xpt_release_device(device);
3008 } else if (async_code == AC_TRANSFER_NEG) {
3009 struct ccb_trans_settings *settings;
3010 struct cam_path path;
3012 settings = (struct ccb_trans_settings *)async_arg;
3013 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
3015 scsi_set_transfer_settings(settings, &path,
3016 /*async_update*/TRUE);
3017 xpt_release_path(&path);
3022 scsi_announce_periph(struct cam_periph *periph)
3024 struct ccb_pathinq cpi;
3025 struct ccb_trans_settings cts;
3026 struct cam_path *path = periph->path;
3031 cam_periph_assert(periph, MA_OWNED);
3033 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
3034 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
3035 cts.type = CTS_TYPE_CURRENT_SETTINGS;
3036 xpt_action((union ccb*)&cts);
3037 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
3039 /* Ask the SIM for its base transfer speed */
3040 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
3041 cpi.ccb_h.func_code = XPT_PATH_INQ;
3042 xpt_action((union ccb *)&cpi);
3043 /* Report connection speed */
3044 speed = cpi.base_transfer_speed;
3046 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3047 struct ccb_trans_settings_spi *spi =
3048 &cts.xport_specific.spi;
3050 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
3051 && spi->sync_offset != 0) {
3052 freq = scsi_calc_syncsrate(spi->sync_period);
3055 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
3056 speed *= (0x01 << spi->bus_width);
3058 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3059 struct ccb_trans_settings_fc *fc =
3060 &cts.xport_specific.fc;
3062 if (fc->valid & CTS_FC_VALID_SPEED)
3063 speed = fc->bitrate;
3065 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
3066 struct ccb_trans_settings_sas *sas =
3067 &cts.xport_specific.sas;
3069 if (sas->valid & CTS_SAS_VALID_SPEED)
3070 speed = sas->bitrate;
3074 printf("%s%d: %d.%03dMB/s transfers",
3075 periph->periph_name, periph->unit_number,
3078 printf("%s%d: %dKB/s transfers", periph->periph_name,
3079 periph->unit_number, speed);
3080 /* Report additional information about SPI connections */
3081 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3082 struct ccb_trans_settings_spi *spi;
3084 spi = &cts.xport_specific.spi;
3086 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3088 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3092 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3093 && spi->bus_width > 0) {
3099 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3100 } else if (freq != 0) {
3104 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3105 struct ccb_trans_settings_fc *fc;
3107 fc = &cts.xport_specific.fc;
3108 if (fc->valid & CTS_FC_VALID_WWNN)
3109 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3110 if (fc->valid & CTS_FC_VALID_WWPN)
3111 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3112 if (fc->valid & CTS_FC_VALID_PORT)
3113 printf(" PortID 0x%x", fc->port);
3119 scsi_proto_announce(struct cam_ed *device)
3121 scsi_print_inquiry(&device->inq_data);
3125 scsi_proto_denounce(struct cam_ed *device)
3127 scsi_print_inquiry_short(&device->inq_data);
3131 scsi_proto_debug_out(union ccb *ccb)
3133 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3134 struct cam_ed *device;
3136 if (ccb->ccb_h.func_code != XPT_SCSI_IO)
3139 device = ccb->ccb_h.path->device;
3140 CAM_DEBUG(ccb->ccb_h.path,
3141 CAM_DEBUG_CDB,("%s. CDB: %s\n",
3142 scsi_op_desc(ccb->csio.cdb_io.cdb_bytes[0], &device->inq_data),
3143 scsi_cdb_string(ccb->csio.cdb_io.cdb_bytes, cdb_str, sizeof(cdb_str))));