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 apparantly 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 const int scsi_quirk_table_size =
560 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table);
562 static cam_status proberegister(struct cam_periph *periph,
564 static void probeschedule(struct cam_periph *probe_periph);
565 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
566 static void proberequestdefaultnegotiation(struct cam_periph *periph);
567 static int proberequestbackoff(struct cam_periph *periph,
568 struct cam_ed *device);
569 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
570 static void probe_purge_old(struct cam_path *path,
571 struct scsi_report_luns_data *new,
573 static void probecleanup(struct cam_periph *periph);
574 static void scsi_find_quirk(struct cam_ed *device);
575 static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
576 static void scsi_scan_lun(struct cam_periph *periph,
577 struct cam_path *path, cam_flags flags,
579 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
580 static struct cam_ed *
581 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target,
583 static void scsi_devise_transport(struct cam_path *path);
584 static void scsi_set_transfer_settings(struct ccb_trans_settings *cts,
585 struct cam_path *path,
587 static void scsi_toggle_tags(struct cam_path *path);
588 static void scsi_dev_async(u_int32_t async_code,
590 struct cam_et *target,
591 struct cam_ed *device,
593 static void scsi_action(union ccb *start_ccb);
594 static void scsi_announce_periph(struct cam_periph *periph);
596 static struct xpt_xport scsi_xport = {
597 .alloc_device = scsi_alloc_device,
598 .action = scsi_action,
599 .async = scsi_dev_async,
600 .announce = scsi_announce_periph,
606 return (&scsi_xport);
615 proberegister(struct cam_periph *periph, void *arg)
617 union ccb *request_ccb; /* CCB representing the probe request */
621 request_ccb = (union ccb *)arg;
622 if (request_ccb == NULL) {
623 printf("proberegister: no probe CCB, "
624 "can't register device\n");
625 return(CAM_REQ_CMP_ERR);
628 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
631 printf("proberegister: Unable to probe new device. "
632 "Unable to allocate softc\n");
633 return(CAM_REQ_CMP_ERR);
635 TAILQ_INIT(&softc->request_ccbs);
636 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
639 periph->softc = softc;
640 softc->periph = periph;
641 softc->action = PROBE_INVALID;
642 status = cam_periph_acquire(periph);
643 if (status != CAM_REQ_CMP) {
646 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
647 scsi_devise_transport(periph->path);
650 * Ensure we've waited at least a bus settle
651 * delay before attempting to probe the device.
652 * For HBAs that don't do bus resets, this won't make a difference.
654 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset,
656 probeschedule(periph);
661 probeschedule(struct cam_periph *periph)
663 struct ccb_pathinq cpi;
667 softc = (probe_softc *)periph->softc;
668 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
670 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
671 cpi.ccb_h.func_code = XPT_PATH_INQ;
672 xpt_action((union ccb *)&cpi);
675 * If a device has gone away and another device, or the same one,
676 * is back in the same place, it should have a unit attention
677 * condition pending. It will not report the unit attention in
678 * response to an inquiry, which may leave invalid transfer
679 * negotiations in effect. The TUR will reveal the unit attention
680 * condition. Only send the TUR for lun 0, since some devices
681 * will get confused by commands other than inquiry to non-existent
682 * luns. If you think a device has gone away start your scan from
683 * lun 0. This will insure that any bogus transfer settings are
686 * If we haven't seen the device before and the controller supports
687 * some kind of transfer negotiation, negotiate with the first
688 * sent command if no bus reset was performed at startup. This
689 * ensures that the device is not confused by transfer negotiation
690 * settings left over by loader or BIOS action.
692 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
693 && (ccb->ccb_h.target_lun == 0)) {
694 PROBE_SET_ACTION(softc, PROBE_TUR);
695 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0
696 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) {
697 proberequestdefaultnegotiation(periph);
698 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
700 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
703 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
704 softc->flags |= PROBE_NO_ANNOUNCE;
706 softc->flags &= ~PROBE_NO_ANNOUNCE;
708 if (cpi.hba_misc & PIM_EXTLUNS)
709 softc->flags |= PROBE_EXTLUN;
711 softc->flags &= ~PROBE_EXTLUN;
713 xpt_schedule(periph, CAM_PRIORITY_XPT);
717 probestart(struct cam_periph *periph, union ccb *start_ccb)
719 /* Probe the device that our peripheral driver points to */
720 struct ccb_scsiio *csio;
723 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
725 softc = (probe_softc *)periph->softc;
726 csio = &start_ccb->csio;
729 switch (softc->action) {
731 case PROBE_TUR_FOR_NEGOTIATION:
734 scsi_test_unit_ready(csio,
743 case PROBE_FULL_INQUIRY:
744 case PROBE_INQUIRY_BASIC_DV1:
745 case PROBE_INQUIRY_BASIC_DV2:
748 struct scsi_inquiry_data *inq_buf;
750 inq_buf = &periph->path->device->inq_data;
753 * If the device is currently configured, we calculate an
754 * MD5 checksum of the inquiry data, and if the serial number
755 * length is greater than 0, add the serial number data
756 * into the checksum as well. Once the inquiry and the
757 * serial number check finish, we attempt to figure out
758 * whether we still have the same device.
760 if (((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
761 && ((softc->flags & PROBE_INQUIRY_CKSUM) == 0)) {
763 MD5Init(&softc->context);
764 MD5Update(&softc->context, (unsigned char *)inq_buf,
765 sizeof(struct scsi_inquiry_data));
766 softc->flags |= PROBE_INQUIRY_CKSUM;
767 if (periph->path->device->serial_num_len > 0) {
768 MD5Update(&softc->context,
769 periph->path->device->serial_num,
770 periph->path->device->serial_num_len);
771 softc->flags |= PROBE_SERIAL_CKSUM;
773 MD5Final(softc->digest, &softc->context);
776 if (softc->action == PROBE_INQUIRY)
777 inquiry_len = SHORT_INQUIRY_LENGTH;
779 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
782 * Some parallel SCSI devices fail to send an
783 * ignore wide residue message when dealing with
784 * odd length inquiry requests. Round up to be
787 inquiry_len = roundup2(inquiry_len, 2);
789 if (softc->action == PROBE_INQUIRY_BASIC_DV1
790 || softc->action == PROBE_INQUIRY_BASIC_DV2) {
791 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT);
793 if (inq_buf == NULL) {
794 xpt_print(periph->path, "malloc failure- skipping Basic"
795 "Domain Validation\n");
796 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
797 scsi_test_unit_ready(csio,
814 /*timeout*/60 * 1000);
817 case PROBE_REPORT_LUNS:
821 rp = malloc(periph->path->target->rpl_size,
822 M_CAMXPT, M_NOWAIT | M_ZERO);
824 struct scsi_inquiry_data *inq_buf;
825 inq_buf = &periph->path->device->inq_data;
826 xpt_print(periph->path,
827 "Unable to alloc report luns storage\n");
828 if (INQ_DATA_TQ_ENABLED(inq_buf))
829 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
831 PROBE_SET_ACTION(softc,
832 PROBE_SUPPORTED_VPD_LIST);
835 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG,
836 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size,
837 SSD_FULL_SIZE, 60000); break;
840 case PROBE_MODE_SENSE:
845 mode_buf_len = sizeof(struct scsi_mode_header_6)
846 + sizeof(struct scsi_mode_blk_desc)
847 + sizeof(struct scsi_control_page);
848 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT);
849 if (mode_buf != NULL) {
850 scsi_mode_sense(csio,
855 SMS_PAGE_CTRL_CURRENT,
856 SMS_CONTROL_MODE_PAGE,
863 xpt_print(periph->path, "Unable to mode sense control page - "
865 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
868 case PROBE_SUPPORTED_VPD_LIST:
870 struct scsi_vpd_supported_page_list *vpd_list;
871 struct cam_ed *device;
874 device = periph->path->device;
876 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0)
877 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT,
880 if (vpd_list != NULL) {
885 (u_int8_t *)vpd_list,
888 SVPD_SUPPORTED_PAGE_LIST,
890 /*timeout*/60 * 1000);
895 * We'll have to do without, let our probedone
896 * routine finish up for us.
898 start_ccb->csio.data_ptr = NULL;
899 cam_freeze_devq(periph->path);
900 cam_periph_doacquire(periph);
901 probedone(periph, start_ccb);
904 case PROBE_DEVICE_ID:
906 struct scsi_vpd_device_id *devid;
909 if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID))
910 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT,
919 SVPD_DEVICE_ID_MAX_SIZE,
923 /*timeout*/60 * 1000);
928 case PROBE_EXTENDED_INQUIRY:
930 struct scsi_vpd_extended_inquiry_data *ext_inq;
933 if (scsi_vpd_supported_page(periph, SVPD_EXTENDED_INQUIRY_DATA))
934 ext_inq = malloc(sizeof(*ext_inq), M_CAMXPT,
937 if (ext_inq != NULL) {
945 SVPD_EXTENDED_INQUIRY_DATA,
947 /*timeout*/60 * 1000);
951 * We'll have to do without, let our probedone
952 * routine finish up for us.
956 case PROBE_SERIAL_NUM:
958 struct scsi_vpd_unit_serial_number *serial_buf;
959 struct cam_ed* device;
962 device = periph->path->device;
963 if (device->serial_num != NULL) {
964 free(device->serial_num, M_CAMXPT);
965 device->serial_num = NULL;
966 device->serial_num_len = 0;
969 if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER))
970 serial_buf = (struct scsi_vpd_unit_serial_number *)
971 malloc(sizeof(*serial_buf), M_CAMXPT,
974 if (serial_buf != NULL) {
979 (u_int8_t *)serial_buf,
982 SVPD_UNIT_SERIAL_NUMBER,
984 /*timeout*/60 * 1000);
990 panic("probestart: invalid action state 0x%x\n", softc->action);
992 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
993 cam_periph_doacquire(periph);
994 xpt_action(start_ccb);
998 proberequestdefaultnegotiation(struct cam_periph *periph)
1000 struct ccb_trans_settings cts;
1002 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1003 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1004 cts.type = CTS_TYPE_USER_SETTINGS;
1005 xpt_action((union ccb *)&cts);
1006 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1009 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1010 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1011 xpt_action((union ccb *)&cts);
1015 * Backoff Negotiation Code- only pertinent for SPI devices.
1018 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
1020 struct ccb_trans_settings cts;
1021 struct ccb_trans_settings_spi *spi;
1023 memset(&cts, 0, sizeof (cts));
1024 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1025 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1026 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1027 xpt_action((union ccb *)&cts);
1028 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1030 xpt_print(periph->path,
1031 "failed to get current device settings\n");
1035 if (cts.transport != XPORT_SPI) {
1037 xpt_print(periph->path, "not SPI transport\n");
1041 spi = &cts.xport_specific.spi;
1044 * We cannot renegotiate sync rate if we don't have one.
1046 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
1048 xpt_print(periph->path, "no sync rate known\n");
1054 * We'll assert that we don't have to touch PPR options- the
1055 * SIM will see what we do with period and offset and adjust
1056 * the PPR options as appropriate.
1060 * A sync rate with unknown or zero offset is nonsensical.
1061 * A sync period of zero means Async.
1063 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
1064 || spi->sync_offset == 0 || spi->sync_period == 0) {
1066 xpt_print(periph->path, "no sync rate available\n");
1071 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
1072 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1073 ("hit async: giving up on DV\n"));
1079 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
1080 * We don't try to remember 'last' settings to see if the SIM actually
1081 * gets into the speed we want to set. We check on the SIM telling
1082 * us that a requested speed is bad, but otherwise don't try and
1083 * check the speed due to the asynchronous and handshake nature
1086 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
1089 if (spi->sync_period >= 0xf) {
1090 spi->sync_period = 0;
1091 spi->sync_offset = 0;
1092 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1093 ("setting to async for DV\n"));
1095 * Once we hit async, we don't want to try
1096 * any more settings.
1098 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
1099 } else if (bootverbose) {
1100 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1101 ("DV: period 0x%x\n", spi->sync_period));
1102 printf("setting period to 0x%x\n", spi->sync_period);
1104 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1105 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1106 xpt_action((union ccb *)&cts);
1107 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) {
1110 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1111 ("DV: failed to set period 0x%x\n", spi->sync_period));
1112 if (spi->sync_period == 0) {
1119 #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP)
1122 probedone(struct cam_periph *periph, union ccb *done_ccb)
1125 struct cam_path *path;
1126 struct scsi_inquiry_data *inq_buf;
1129 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
1131 softc = (probe_softc *)periph->softc;
1132 path = done_ccb->ccb_h.path;
1133 priority = done_ccb->ccb_h.pinfo.priority;
1135 switch (softc->action) {
1138 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1140 if (cam_periph_error(done_ccb, 0,
1141 SF_NO_PRINT, NULL) == ERESTART) {
1143 /* Drop freeze taken due to CAM_DEV_QFREEZE */
1144 cam_release_devq(path, 0, 0, 0, FALSE);
1147 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1148 /* Don't wedge the queue */
1149 xpt_release_devq(done_ccb->ccb_h.path,
1153 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1154 xpt_release_ccb(done_ccb);
1155 xpt_schedule(periph, priority);
1157 /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */
1158 cam_release_devq(path, 0, 0, 0, FALSE);
1159 cam_periph_release_locked(periph);
1163 case PROBE_FULL_INQUIRY:
1165 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1166 u_int8_t periph_qual;
1168 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1169 scsi_find_quirk(path->device);
1170 inq_buf = &path->device->inq_data;
1172 periph_qual = SID_QUAL(inq_buf);
1174 if (periph_qual == SID_QUAL_LU_CONNECTED ||
1175 periph_qual == SID_QUAL_LU_OFFLINE) {
1179 * We conservatively request only
1180 * SHORT_INQUIRY_LEN bytes of inquiry
1181 * information during our first try
1182 * at sending an INQUIRY. If the device
1183 * has more information to give,
1184 * perform a second request specifying
1185 * the amount of information the device
1186 * is willing to give.
1188 len = inq_buf->additional_length
1189 + offsetof(struct scsi_inquiry_data,
1190 additional_length) + 1;
1191 if (softc->action == PROBE_INQUIRY
1192 && len > SHORT_INQUIRY_LENGTH) {
1193 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1194 xpt_release_ccb(done_ccb);
1195 xpt_schedule(periph, priority);
1199 scsi_devise_transport(path);
1201 if (path->device->lun_id == 0 &&
1202 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 &&
1203 (SCSI_QUIRK(path->device)->quirks &
1204 CAM_QUIRK_NORPTLUNS) == 0) {
1205 PROBE_SET_ACTION(softc,
1208 * Start with room for *one* lun.
1210 periph->path->target->rpl_size = 16;
1211 } else if (INQ_DATA_TQ_ENABLED(inq_buf))
1212 PROBE_SET_ACTION(softc,
1215 PROBE_SET_ACTION(softc,
1216 PROBE_SUPPORTED_VPD_LIST);
1218 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1219 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1220 xpt_acquire_device(path->device);
1222 xpt_release_ccb(done_ccb);
1223 xpt_schedule(periph, priority);
1225 } else if (path->device->lun_id == 0 &&
1226 SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 &&
1227 (SCSI_QUIRK(path->device)->quirks &
1228 CAM_QUIRK_NORPTLUNS) == 0) {
1229 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS);
1230 periph->path->target->rpl_size = 16;
1231 xpt_release_ccb(done_ccb);
1232 xpt_schedule(periph, priority);
1235 } else if (cam_periph_error(done_ccb, 0,
1236 done_ccb->ccb_h.target_lun > 0
1237 ? SF_RETRY_UA|SF_QUIET_IR
1239 &softc->saved_ccb) == ERESTART) {
1242 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1243 /* Don't wedge the queue */
1244 xpt_release_devq(done_ccb->ccb_h.path,
1245 /*count*/1, /*run_queue*/TRUE);
1247 path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID;
1250 * If we get to this point, we got an error status back
1251 * from the inquiry and the error status doesn't require
1252 * automatically retrying the command. Therefore, the
1253 * inquiry failed. If we had inquiry information before
1254 * for this device, but this latest inquiry command failed,
1255 * the device has probably gone away. If this device isn't
1256 * already marked unconfigured, notify the peripheral
1257 * drivers that this device is no more.
1259 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
1260 /* Send the async notification. */
1261 xpt_async(AC_LOST_DEVICE, path, NULL);
1262 PROBE_SET_ACTION(softc, PROBE_INVALID);
1264 xpt_release_ccb(done_ccb);
1267 case PROBE_REPORT_LUNS:
1269 struct ccb_scsiio *csio;
1270 struct scsi_report_luns_data *lp;
1273 csio = &done_ccb->csio;
1275 lp = (struct scsi_report_luns_data *)csio->data_ptr;
1276 nlun = scsi_4btoul(lp->length) / 8;
1277 maxlun = (csio->dxfer_len / 8) - 1;
1279 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1280 if (cam_periph_error(done_ccb, 0,
1281 done_ccb->ccb_h.target_lun > 0 ?
1282 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA,
1283 &softc->saved_ccb) == ERESTART) {
1286 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1287 xpt_release_devq(done_ccb->ccb_h.path, 1,
1292 } else if (nlun > maxlun) {
1294 * Reallocate and retry to cover all luns
1296 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1297 ("Probe: reallocating REPORT_LUNS for %u luns\n",
1300 path->target->rpl_size = (nlun << 3) + 8;
1301 xpt_release_ccb(done_ccb);
1302 xpt_schedule(periph, priority);
1304 } else if (nlun == 0) {
1306 * If there don't appear to be any luns, bail.
1314 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1315 ("Probe: %u lun(s) reported\n", nlun));
1317 CAM_GET_LUN(lp, 0, lun);
1319 * If the first lun is not lun 0, then either there
1320 * is no lun 0 in the list, or the list is unsorted.
1323 for (idx = 0; idx < nlun; idx++) {
1324 CAM_GET_LUN(lp, idx, lun);
1332 lp->luns[0].lundata, 8);
1333 memcpy(lp->luns[0].lundata,
1334 lp->luns[idx].lundata, 8);
1335 memcpy(lp->luns[idx].lundata,
1337 CAM_DEBUG(path, CAM_DEBUG_PROBE,
1338 ("lun 0 in position %u\n", idx));
1342 * If we have an old lun list, We can either
1343 * retest luns that appear to have been dropped,
1344 * or just nuke them. We'll opt for the latter.
1345 * This function will also install the new list
1346 * in the target structure.
1348 probe_purge_old(path, lp, softc->flags);
1351 inq_buf = &path->device->inq_data;
1352 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID &&
1353 (SID_QUAL(inq_buf) == SID_QUAL_LU_CONNECTED ||
1354 SID_QUAL(inq_buf) == SID_QUAL_LU_OFFLINE)) {
1355 if (INQ_DATA_TQ_ENABLED(inq_buf))
1356 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE);
1358 PROBE_SET_ACTION(softc,
1359 PROBE_SUPPORTED_VPD_LIST);
1360 xpt_release_ccb(done_ccb);
1361 xpt_schedule(periph, priority);
1367 PROBE_SET_ACTION(softc, PROBE_INVALID);
1368 xpt_release_ccb(done_ccb);
1371 case PROBE_MODE_SENSE:
1373 struct ccb_scsiio *csio;
1374 struct scsi_mode_header_6 *mode_hdr;
1376 csio = &done_ccb->csio;
1377 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr;
1378 if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) {
1379 struct scsi_control_page *page;
1382 offset = ((u_int8_t *)&mode_hdr[1])
1383 + mode_hdr->blk_desc_len;
1384 page = (struct scsi_control_page *)offset;
1385 path->device->queue_flags = page->queue_flags;
1386 } else if (cam_periph_error(done_ccb, 0,
1387 SF_RETRY_UA|SF_NO_PRINT,
1388 &softc->saved_ccb) == ERESTART) {
1390 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1391 /* Don't wedge the queue */
1392 xpt_release_devq(done_ccb->ccb_h.path,
1393 /*count*/1, /*run_queue*/TRUE);
1395 xpt_release_ccb(done_ccb);
1396 free(mode_hdr, M_CAMXPT);
1397 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST);
1398 xpt_schedule(periph, priority);
1401 case PROBE_SUPPORTED_VPD_LIST:
1403 struct ccb_scsiio *csio;
1404 struct scsi_vpd_supported_page_list *page_list;
1406 csio = &done_ccb->csio;
1408 (struct scsi_vpd_supported_page_list *)csio->data_ptr;
1410 if (path->device->supported_vpds != NULL) {
1411 free(path->device->supported_vpds, M_CAMXPT);
1412 path->device->supported_vpds = NULL;
1413 path->device->supported_vpds_len = 0;
1416 if (page_list == NULL) {
1418 * Don't process the command as it was never sent
1420 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1422 path->device->supported_vpds_len = page_list->length +
1423 SVPD_SUPPORTED_PAGES_HDR_LEN;
1424 path->device->supported_vpds = (uint8_t *)page_list;
1425 xpt_release_ccb(done_ccb);
1426 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID);
1427 xpt_schedule(periph, priority);
1429 } else if (cam_periph_error(done_ccb, 0,
1430 SF_RETRY_UA|SF_NO_PRINT,
1431 &softc->saved_ccb) == ERESTART) {
1433 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1434 /* Don't wedge the queue */
1435 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1440 free(page_list, M_CAMXPT);
1441 /* No VPDs available, skip to device check. */
1442 csio->data_ptr = NULL;
1443 goto probe_device_check;
1445 case PROBE_DEVICE_ID:
1447 struct scsi_vpd_device_id *devid;
1448 struct ccb_scsiio *csio;
1449 uint32_t length = 0;
1451 csio = &done_ccb->csio;
1452 devid = (struct scsi_vpd_device_id *)csio->data_ptr;
1454 /* Clean up from previous instance of this device */
1455 if (path->device->device_id != NULL) {
1456 path->device->device_id_len = 0;
1457 free(path->device->device_id, M_CAMXPT);
1458 path->device->device_id = NULL;
1461 if (devid == NULL) {
1462 /* Don't process the command as it was never sent */
1463 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1464 length = scsi_2btoul(devid->length);
1467 * NB: device_id_len is actual response
1468 * size, not buffer size.
1470 path->device->device_id_len = length +
1471 SVPD_DEVICE_ID_HDR_LEN;
1472 path->device->device_id = (uint8_t *)devid;
1474 } else if (cam_periph_error(done_ccb, 0,
1476 &softc->saved_ccb) == ERESTART) {
1478 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1479 /* Don't wedge the queue */
1480 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1484 /* Free the device id space if we don't use it */
1485 if (devid && length == 0)
1486 free(devid, M_CAMXPT);
1487 xpt_release_ccb(done_ccb);
1488 PROBE_SET_ACTION(softc, PROBE_EXTENDED_INQUIRY);
1489 xpt_schedule(periph, priority);
1492 case PROBE_EXTENDED_INQUIRY: {
1493 struct scsi_vpd_extended_inquiry_data *ext_inq;
1494 struct ccb_scsiio *csio;
1497 csio = &done_ccb->csio;
1498 ext_inq = (struct scsi_vpd_extended_inquiry_data *)
1500 if (path->device->ext_inq != NULL) {
1501 path->device->ext_inq_len = 0;
1502 free(path->device->ext_inq, M_CAMXPT);
1503 path->device->ext_inq = NULL;
1506 if (ext_inq == NULL) {
1507 /* Don't process the command as it was never sent */
1508 } else if (CCB_COMPLETED_OK(csio->ccb_h)) {
1509 length = scsi_2btoul(ext_inq->page_length) +
1510 __offsetof(struct scsi_vpd_extended_inquiry_data,
1512 length = min(length, sizeof(*ext_inq));
1513 length -= csio->resid;
1515 path->device->ext_inq_len = length;
1516 path->device->ext_inq = (uint8_t *)ext_inq;
1518 } else if (cam_periph_error(done_ccb, 0,
1520 &softc->saved_ccb) == ERESTART) {
1522 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1523 /* Don't wedge the queue */
1524 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1528 /* Free the device id space if we don't use it */
1529 if (ext_inq && length <= 0)
1530 free(ext_inq, M_CAMXPT);
1531 xpt_release_ccb(done_ccb);
1532 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM);
1533 xpt_schedule(periph, priority);
1538 case PROBE_SERIAL_NUM:
1540 struct ccb_scsiio *csio;
1541 struct scsi_vpd_unit_serial_number *serial_buf;
1548 csio = &done_ccb->csio;
1549 priority = done_ccb->ccb_h.pinfo.priority;
1551 (struct scsi_vpd_unit_serial_number *)csio->data_ptr;
1553 if (serial_buf == NULL) {
1555 * Don't process the command as it was never sent
1557 } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP
1558 && (serial_buf->length > 0)) {
1561 path->device->serial_num =
1562 (u_int8_t *)malloc((serial_buf->length + 1),
1563 M_CAMXPT, M_NOWAIT);
1564 if (path->device->serial_num != NULL) {
1565 memcpy(path->device->serial_num,
1566 serial_buf->serial_num,
1567 serial_buf->length);
1568 path->device->serial_num_len =
1570 path->device->serial_num[serial_buf->length]
1573 } else if (cam_periph_error(done_ccb, 0,
1574 SF_RETRY_UA|SF_NO_PRINT,
1575 &softc->saved_ccb) == ERESTART) {
1577 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1578 /* Don't wedge the queue */
1579 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1584 * Let's see if we have seen this device before.
1586 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) {
1588 u_int8_t digest[16];
1593 (unsigned char *)&path->device->inq_data,
1594 sizeof(struct scsi_inquiry_data));
1597 MD5Update(&context, serial_buf->serial_num,
1598 serial_buf->length);
1600 MD5Final(digest, &context);
1601 if (bcmp(softc->digest, digest, 16) == 0)
1605 * XXX Do we need to do a TUR in order to ensure
1606 * that the device really hasn't changed???
1609 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0))
1610 xpt_async(AC_LOST_DEVICE, path, NULL);
1612 if (serial_buf != NULL)
1613 free(serial_buf, M_CAMXPT);
1617 * Now that we have all the necessary
1618 * information to safely perform transfer
1619 * negotiations... Controllers don't perform
1620 * any negotiation or tagged queuing until
1621 * after the first XPT_SET_TRAN_SETTINGS ccb is
1622 * received. So, on a new device, just retrieve
1623 * the user settings, and set them as the current
1624 * settings to set the device up.
1626 proberequestdefaultnegotiation(periph);
1627 xpt_release_ccb(done_ccb);
1630 * Perform a TUR to allow the controller to
1631 * perform any necessary transfer negotiation.
1633 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1634 xpt_schedule(periph, priority);
1637 xpt_release_ccb(done_ccb);
1640 case PROBE_TUR_FOR_NEGOTIATION:
1642 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1643 cam_periph_error(done_ccb, 0,
1644 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1646 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1647 /* Don't wedge the queue */
1648 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1652 * Do Domain Validation for lun 0 on devices that claim
1653 * to support Synchronous Transfer modes.
1655 if (softc->action == PROBE_TUR_FOR_NEGOTIATION
1656 && done_ccb->ccb_h.target_lun == 0
1657 && (path->device->inq_data.flags & SID_Sync) != 0
1658 && (path->device->flags & CAM_DEV_IN_DV) == 0) {
1659 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1660 ("Begin Domain Validation\n"));
1661 path->device->flags |= CAM_DEV_IN_DV;
1662 xpt_release_ccb(done_ccb);
1663 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1);
1664 xpt_schedule(periph, priority);
1667 if (softc->action == PROBE_DV_EXIT) {
1668 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1669 ("Leave Domain Validation\n"));
1671 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1672 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1673 xpt_acquire_device(path->device);
1675 path->device->flags &=
1676 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1677 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1678 /* Inform the XPT that a new device has been found */
1679 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1680 xpt_action(done_ccb);
1681 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1684 PROBE_SET_ACTION(softc, PROBE_DONE);
1685 xpt_release_ccb(done_ccb);
1687 case PROBE_INQUIRY_BASIC_DV1:
1688 case PROBE_INQUIRY_BASIC_DV2:
1690 struct scsi_inquiry_data *nbuf;
1691 struct ccb_scsiio *csio;
1693 if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) {
1694 cam_periph_error(done_ccb, 0,
1695 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1697 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
1698 /* Don't wedge the queue */
1699 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
1702 csio = &done_ccb->csio;
1703 nbuf = (struct scsi_inquiry_data *)csio->data_ptr;
1704 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) {
1706 "inquiry data fails comparison at DV%d step\n",
1707 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2);
1708 if (proberequestbackoff(periph, path->device)) {
1709 path->device->flags &= ~CAM_DEV_IN_DV;
1710 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION);
1713 PROBE_SET_ACTION(softc, PROBE_DV_EXIT);
1715 free(nbuf, M_CAMXPT);
1716 xpt_release_ccb(done_ccb);
1717 xpt_schedule(periph, priority);
1720 free(nbuf, M_CAMXPT);
1721 if (softc->action == PROBE_INQUIRY_BASIC_DV1) {
1722 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2);
1723 xpt_release_ccb(done_ccb);
1724 xpt_schedule(periph, priority);
1727 if (softc->action == PROBE_INQUIRY_BASIC_DV2) {
1728 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE,
1729 ("Leave Domain Validation Successfully\n"));
1731 if (path->device->flags & CAM_DEV_UNCONFIGURED) {
1732 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1733 xpt_acquire_device(path->device);
1735 path->device->flags &=
1736 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM);
1737 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
1738 /* Inform the XPT that a new device has been found */
1739 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1740 xpt_action(done_ccb);
1741 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1744 PROBE_SET_ACTION(softc, PROBE_DONE);
1745 xpt_release_ccb(done_ccb);
1749 panic("probedone: invalid action state 0x%x\n", softc->action);
1751 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
1752 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe);
1753 done_ccb->ccb_h.status = CAM_REQ_CMP;
1755 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) {
1756 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1757 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1758 cam_release_devq(path, 0, 0, 0, FALSE);
1759 cam_periph_release_locked(periph);
1760 cam_periph_invalidate(periph);
1761 cam_periph_release_locked(periph);
1763 probeschedule(periph);
1769 probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
1772 struct cam_path *tp;
1773 struct scsi_report_luns_data *old;
1774 u_int idx1, idx2, nlun_old, nlun_new;
1778 if (path->target == NULL) {
1781 mtx_lock(&path->target->luns_mtx);
1782 old = path->target->luns;
1783 path->target->luns = new;
1784 mtx_unlock(&path->target->luns_mtx);
1787 nlun_old = scsi_4btoul(old->length) / 8;
1788 nlun_new = scsi_4btoul(new->length) / 8;
1791 * We are not going to assume sorted lists. Deal.
1793 for (idx1 = 0; idx1 < nlun_old; idx1++) {
1794 ol = old->luns[idx1].lundata;
1795 for (idx2 = 0; idx2 < nlun_new; idx2++) {
1796 nl = new->luns[idx2].lundata;
1797 if (memcmp(nl, ol, 8) == 0) {
1801 if (idx2 < nlun_new) {
1805 * An 'old' item not in the 'new' list.
1806 * Nuke it. Except that if it is lun 0,
1807 * that would be what the probe state
1808 * machine is currently working on,
1809 * so we won't do that.
1811 CAM_GET_LUN(old, idx1, this_lun);
1812 if (this_lun == 0) {
1817 * We also cannot nuke it if it is
1818 * not in a lun format we understand
1819 * and replace the LUN with a "simple" LUN
1820 * if that is all the HBA supports.
1822 if (!(flags & PROBE_EXTLUN)) {
1823 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
1825 CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
1828 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
1829 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
1830 xpt_async(AC_LOST_DEVICE, tp, NULL);
1834 free(old, M_CAMXPT);
1838 probecleanup(struct cam_periph *periph)
1840 free(periph->softc, M_CAMXPT);
1844 scsi_find_quirk(struct cam_ed *device)
1846 struct scsi_quirk_entry *quirk;
1849 match = cam_quirkmatch((caddr_t)&device->inq_data,
1850 (caddr_t)scsi_quirk_table,
1851 sizeof(scsi_quirk_table) /
1852 sizeof(*scsi_quirk_table),
1853 sizeof(*scsi_quirk_table), scsi_inquiry_match);
1856 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1858 quirk = (struct scsi_quirk_entry *)match;
1859 device->quirk = quirk;
1860 device->mintags = quirk->mintags;
1861 device->maxtags = quirk->maxtags;
1865 sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS)
1870 error = sysctl_handle_int(oidp, &val, 0, req);
1871 if (error != 0 || req->newptr == NULL)
1873 if (val == 0 || val == 1) {
1882 union ccb *request_ccb;
1883 struct ccb_pathinq *cpi;
1886 } scsi_scan_bus_info;
1889 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1890 * As the scan progresses, scsi_scan_bus is used as the
1891 * callback on completion function.
1894 scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1898 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1899 ("scsi_scan_bus\n"));
1900 switch (request_ccb->ccb_h.func_code) {
1904 scsi_scan_bus_info *scan_info;
1905 union ccb *work_ccb, *reset_ccb;
1906 struct cam_path *path;
1908 u_int low_target, max_target;
1911 /* Find out the characteristics of the bus */
1912 work_ccb = xpt_alloc_ccb_nowait();
1913 if (work_ccb == NULL) {
1914 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1915 xpt_done(request_ccb);
1918 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1919 request_ccb->ccb_h.pinfo.priority);
1920 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1921 xpt_action(work_ccb);
1922 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1923 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1924 xpt_free_ccb(work_ccb);
1925 xpt_done(request_ccb);
1929 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) {
1931 * Can't scan the bus on an adapter that
1932 * cannot perform the initiator role.
1934 request_ccb->ccb_h.status = CAM_REQ_CMP;
1935 xpt_free_ccb(work_ccb);
1936 xpt_done(request_ccb);
1940 /* We may need to reset bus first, if we haven't done it yet. */
1941 if ((work_ccb->cpi.hba_inquiry &
1942 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1943 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1944 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) &&
1945 (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) {
1946 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1948 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1949 xpt_action(reset_ccb);
1950 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1951 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1952 xpt_free_ccb(reset_ccb);
1953 xpt_free_ccb(work_ccb);
1954 xpt_done(request_ccb);
1957 xpt_free_ccb(reset_ccb);
1960 /* Save some state for use while we probe for devices */
1961 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) +
1962 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT);
1963 if (scan_info == NULL) {
1964 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1965 xpt_free_ccb(work_ccb);
1966 xpt_done(request_ccb);
1969 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1970 ("SCAN start for %p\n", scan_info));
1971 scan_info->request_ccb = request_ccb;
1972 scan_info->cpi = &work_ccb->cpi;
1974 /* Cache on our stack so we can work asynchronously */
1975 max_target = scan_info->cpi->max_target;
1977 initiator_id = scan_info->cpi->initiator_id;
1981 * We can scan all targets in parallel, or do it sequentially.
1984 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
1985 max_target = low_target = request_ccb->ccb_h.target_id;
1986 scan_info->counter = 0;
1987 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
1989 scan_info->counter = 0;
1991 scan_info->counter = scan_info->cpi->max_target + 1;
1992 if (scan_info->cpi->initiator_id < scan_info->counter) {
1993 scan_info->counter--;
1996 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1999 for (i = low_target; i <= max_target; i++) {
2001 if (i == initiator_id)
2004 status = xpt_create_path(&path, NULL,
2005 request_ccb->ccb_h.path_id,
2007 if (status != CAM_REQ_CMP) {
2008 printf("scsi_scan_bus: xpt_create_path failed"
2009 " with status %#x, bus scan halted\n",
2011 free(scan_info, M_CAMXPT);
2012 request_ccb->ccb_h.status = status;
2013 xpt_free_ccb(work_ccb);
2014 xpt_done(request_ccb);
2017 work_ccb = xpt_alloc_ccb_nowait();
2018 if (work_ccb == NULL) {
2019 xpt_free_ccb((union ccb *)scan_info->cpi);
2020 free(scan_info, M_CAMXPT);
2021 xpt_free_path(path);
2022 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2023 xpt_done(request_ccb);
2026 xpt_setup_ccb(&work_ccb->ccb_h, path,
2027 request_ccb->ccb_h.pinfo.priority);
2028 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2029 work_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2030 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
2031 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
2032 work_ccb->crcn.flags = request_ccb->crcn.flags;
2033 xpt_action(work_ccb);
2042 struct cam_path *path, *oldpath;
2043 scsi_scan_bus_info *scan_info;
2044 struct cam_et *target;
2045 struct cam_ed *device, *nextdev;
2048 target_id_t target_id;
2051 oldpath = request_ccb->ccb_h.path;
2053 status = cam_ccb_status(request_ccb);
2054 scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0;
2055 path_id = request_ccb->ccb_h.path_id;
2056 target_id = request_ccb->ccb_h.target_id;
2057 lun_id = request_ccb->ccb_h.target_lun;
2058 target = request_ccb->ccb_h.path->target;
2061 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
2063 mtx_lock(&target->luns_mtx);
2066 u_int nluns = scsi_4btoul(target->luns->length) / 8;
2069 * Make sure we skip over lun 0 if it's the first member
2070 * of the list as we've actually just finished probing
2073 CAM_GET_LUN(target->luns, 0, first);
2074 if (first == 0 && scan_info->lunindex[target_id] == 0) {
2075 scan_info->lunindex[target_id]++;
2079 * Skip any LUNs that the HBA can't deal with.
2081 while (scan_info->lunindex[target_id] < nluns) {
2082 if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
2083 CAM_GET_LUN(target->luns,
2084 scan_info->lunindex[target_id],
2089 if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
2090 scan_info->lunindex[target_id])) {
2091 CAM_GET_SIMPLE_LUN(target->luns,
2092 scan_info->lunindex[target_id],
2097 scan_info->lunindex[target_id]++;
2100 if (scan_info->lunindex[target_id] < nluns) {
2101 mtx_unlock(&target->luns_mtx);
2103 CAM_DEBUG(request_ccb->ccb_h.path,
2105 ("next lun to try at index %u is %jx\n",
2106 scan_info->lunindex[target_id],
2107 (uintmax_t)lun_id));
2108 scan_info->lunindex[target_id]++;
2110 mtx_unlock(&target->luns_mtx);
2111 /* We're done with scanning all luns. */
2114 mtx_unlock(&target->luns_mtx);
2115 device = request_ccb->ccb_h.path->device;
2116 /* Continue sequential LUN scan if: */
2117 /* -- we have more LUNs that need recheck */
2118 mtx_lock(&target->bus->eb_mtx);
2120 while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL)
2121 if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0)
2123 mtx_unlock(&target->bus->eb_mtx);
2124 if (nextdev != NULL) {
2126 /* -- stop if CAM_QUIRK_NOLUNS is set. */
2127 } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) {
2129 /* -- this LUN is connected and its SCSI version
2130 * allows more LUNs. */
2131 } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2132 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2133 CAN_SRCH_HI_DENSE(device))
2135 /* -- this LUN is disconnected, its SCSI version
2136 * allows more LUNs and we guess they may be. */
2137 } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) {
2138 if (lun_id < (CAM_SCSI2_MAXLUN-1) ||
2139 CAN_SRCH_HI_SPARSE(device))
2142 if (next_target == 0) {
2144 if (lun_id > scan_info->cpi->max_lun)
2150 * Check to see if we scan any further luns.
2156 * Free the current request path- we're done with it.
2158 xpt_free_path(oldpath);
2161 if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
2163 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
2164 scan_info->counter++;
2165 if (scan_info->counter ==
2166 scan_info->cpi->initiator_id) {
2167 scan_info->counter++;
2169 if (scan_info->counter >=
2170 scan_info->cpi->max_target+1) {
2174 scan_info->counter--;
2175 if (scan_info->counter == 0) {
2181 xpt_free_ccb(request_ccb);
2182 xpt_free_ccb((union ccb *)scan_info->cpi);
2183 request_ccb = scan_info->request_ccb;
2184 CAM_DEBUG(request_ccb->ccb_h.path,
2186 ("SCAN done for %p\n", scan_info));
2187 free(scan_info, M_CAMXPT);
2188 request_ccb->ccb_h.status = CAM_REQ_CMP;
2189 xpt_done(request_ccb);
2193 if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) {
2195 xpt_free_ccb(request_ccb);
2198 status = xpt_create_path(&path, NULL,
2199 scan_info->request_ccb->ccb_h.path_id,
2200 scan_info->counter, 0);
2201 if (status != CAM_REQ_CMP) {
2203 printf("scsi_scan_bus: xpt_create_path failed"
2204 " with status %#x, bus scan halted\n",
2206 xpt_free_ccb(request_ccb);
2207 xpt_free_ccb((union ccb *)scan_info->cpi);
2208 request_ccb = scan_info->request_ccb;
2209 free(scan_info, M_CAMXPT);
2210 request_ccb->ccb_h.status = status;
2211 xpt_done(request_ccb);
2214 xpt_setup_ccb(&request_ccb->ccb_h, path,
2215 request_ccb->ccb_h.pinfo.priority);
2216 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2217 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2218 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2219 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2220 request_ccb->crcn.flags =
2221 scan_info->request_ccb->crcn.flags;
2223 status = xpt_create_path(&path, NULL,
2224 path_id, target_id, lun_id);
2226 * Free the old request path- we're done with it. We
2227 * do this *after* creating the new path so that
2228 * we don't remove a target that has our lun list
2229 * in the case that lun 0 is not present.
2231 xpt_free_path(oldpath);
2232 if (status != CAM_REQ_CMP) {
2233 printf("scsi_scan_bus: xpt_create_path failed "
2234 "with status %#x, halting LUN scan\n",
2238 xpt_setup_ccb(&request_ccb->ccb_h, path,
2239 request_ccb->ccb_h.pinfo.priority);
2240 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2241 request_ccb->ccb_h.cbfcnp = scsi_scan_bus;
2242 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2243 request_ccb->ccb_h.ppriv_ptr0 = scan_info;
2244 request_ccb->crcn.flags =
2245 scan_info->request_ccb->crcn.flags;
2248 xpt_action(request_ccb);
2257 scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
2258 cam_flags flags, union ccb *request_ccb)
2260 struct ccb_pathinq cpi;
2262 struct cam_path *new_path;
2263 struct cam_periph *old_periph;
2266 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
2268 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2269 cpi.ccb_h.func_code = XPT_PATH_INQ;
2270 xpt_action((union ccb *)&cpi);
2272 if (cpi.ccb_h.status != CAM_REQ_CMP) {
2273 if (request_ccb != NULL) {
2274 request_ccb->ccb_h.status = cpi.ccb_h.status;
2275 xpt_done(request_ccb);
2280 if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) {
2282 * Can't scan the bus on an adapter that
2283 * cannot perform the initiator role.
2285 if (request_ccb != NULL) {
2286 request_ccb->ccb_h.status = CAM_REQ_CMP;
2287 xpt_done(request_ccb);
2292 if (request_ccb == NULL) {
2293 request_ccb = xpt_alloc_ccb_nowait();
2294 if (request_ccb == NULL) {
2295 xpt_print(path, "scsi_scan_lun: can't allocate CCB, "
2296 "can't continue\n");
2299 status = xpt_create_path(&new_path, NULL,
2301 path->target->target_id,
2302 path->device->lun_id);
2303 if (status != CAM_REQ_CMP) {
2304 xpt_print(path, "scsi_scan_lun: can't create path, "
2305 "can't continue\n");
2306 xpt_free_ccb(request_ccb);
2309 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
2310 request_ccb->ccb_h.cbfcnp = xptscandone;
2311 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
2312 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
2313 request_ccb->crcn.flags = flags;
2316 lock = (xpt_path_owned(path) == 0);
2318 xpt_path_lock(path);
2319 if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
2320 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
2323 softc = (probe_softc *)old_periph->softc;
2324 TAILQ_INSERT_TAIL(&softc->request_ccbs,
2325 &request_ccb->ccb_h, periph_links.tqe);
2327 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2328 xpt_done(request_ccb);
2331 status = cam_periph_alloc(proberegister, NULL, probecleanup,
2332 probestart, "probe",
2334 request_ccb->ccb_h.path, NULL, 0,
2337 if (status != CAM_REQ_CMP) {
2338 xpt_print(path, "scsi_scan_lun: cam_alloc_periph "
2339 "returned an error, can't continue probe\n");
2340 request_ccb->ccb_h.status = status;
2341 xpt_done(request_ccb);
2345 xpt_path_unlock(path);
2349 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
2352 xpt_free_path(done_ccb->ccb_h.path);
2353 xpt_free_ccb(done_ccb);
2356 static struct cam_ed *
2357 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
2359 struct scsi_quirk_entry *quirk;
2360 struct cam_ed *device;
2362 device = xpt_alloc_device(bus, target, lun_id);
2367 * Take the default quirk entry until we have inquiry
2368 * data and can determine a better quirk to use.
2370 quirk = &scsi_quirk_table[scsi_quirk_table_size - 1];
2371 device->quirk = (void *)quirk;
2372 device->mintags = quirk->mintags;
2373 device->maxtags = quirk->maxtags;
2374 bzero(&device->inq_data, sizeof(device->inq_data));
2375 device->inq_flags = 0;
2376 device->queue_flags = 0;
2377 device->serial_num = NULL;
2378 device->serial_num_len = 0;
2379 device->device_id = NULL;
2380 device->device_id_len = 0;
2381 device->supported_vpds = NULL;
2382 device->supported_vpds_len = 0;
2387 scsi_devise_transport(struct cam_path *path)
2389 struct ccb_pathinq cpi;
2390 struct ccb_trans_settings cts;
2391 struct scsi_inquiry_data *inq_buf;
2393 /* Get transport information from the SIM */
2394 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2395 cpi.ccb_h.func_code = XPT_PATH_INQ;
2396 xpt_action((union ccb *)&cpi);
2399 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
2400 inq_buf = &path->device->inq_data;
2401 path->device->protocol = PROTO_SCSI;
2402 path->device->protocol_version =
2403 inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version;
2404 path->device->transport = cpi.transport;
2405 path->device->transport_version = cpi.transport_version;
2408 * Any device not using SPI3 features should
2409 * be considered SPI2 or lower.
2411 if (inq_buf != NULL) {
2412 if (path->device->transport == XPORT_SPI
2413 && (inq_buf->spi3data & SID_SPI_MASK) == 0
2414 && path->device->transport_version > 2)
2415 path->device->transport_version = 2;
2417 struct cam_ed* otherdev;
2419 for (otherdev = TAILQ_FIRST(&path->target->ed_entries);
2421 otherdev = TAILQ_NEXT(otherdev, links)) {
2422 if (otherdev != path->device)
2426 if (otherdev != NULL) {
2428 * Initially assume the same versioning as
2429 * prior luns for this target.
2431 path->device->protocol_version =
2432 otherdev->protocol_version;
2433 path->device->transport_version =
2434 otherdev->transport_version;
2436 /* Until we know better, opt for safty */
2437 path->device->protocol_version = 2;
2438 if (path->device->transport == XPORT_SPI)
2439 path->device->transport_version = 2;
2441 path->device->transport_version = 0;
2447 * For a device compliant with SPC-2 we should be able
2448 * to determine the transport version supported by
2449 * scrutinizing the version descriptors in the
2453 /* Tell the controller what we think */
2454 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2455 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
2456 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2457 cts.transport = path->device->transport;
2458 cts.transport_version = path->device->transport_version;
2459 cts.protocol = path->device->protocol;
2460 cts.protocol_version = path->device->protocol_version;
2461 cts.proto_specific.valid = 0;
2462 cts.xport_specific.valid = 0;
2463 xpt_action((union ccb *)&cts);
2467 scsi_dev_advinfo(union ccb *start_ccb)
2469 struct cam_ed *device;
2470 struct ccb_dev_advinfo *cdai;
2473 start_ccb->ccb_h.status = CAM_REQ_INVALID;
2474 device = start_ccb->ccb_h.path->device;
2475 cdai = &start_ccb->cdai;
2476 switch(cdai->buftype) {
2477 case CDAI_TYPE_SCSI_DEVID:
2478 if (cdai->flags & CDAI_FLAG_STORE)
2480 cdai->provsiz = device->device_id_len;
2481 if (device->device_id_len == 0)
2483 amt = device->device_id_len;
2484 if (cdai->provsiz > cdai->bufsiz)
2486 memcpy(cdai->buf, device->device_id, amt);
2488 case CDAI_TYPE_SERIAL_NUM:
2489 if (cdai->flags & CDAI_FLAG_STORE)
2491 cdai->provsiz = device->serial_num_len;
2492 if (device->serial_num_len == 0)
2494 amt = device->serial_num_len;
2495 if (cdai->provsiz > cdai->bufsiz)
2497 memcpy(cdai->buf, device->serial_num, amt);
2499 case CDAI_TYPE_PHYS_PATH:
2500 if (cdai->flags & CDAI_FLAG_STORE) {
2501 if (device->physpath != NULL) {
2502 free(device->physpath, M_CAMXPT);
2503 device->physpath = NULL;
2505 device->physpath_len = cdai->bufsiz;
2506 /* Clear existing buffer if zero length */
2507 if (cdai->bufsiz == 0)
2509 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
2510 if (device->physpath == NULL) {
2511 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2514 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
2516 cdai->provsiz = device->physpath_len;
2517 if (device->physpath_len == 0)
2519 amt = device->physpath_len;
2520 if (cdai->provsiz > cdai->bufsiz)
2522 memcpy(cdai->buf, device->physpath, amt);
2525 case CDAI_TYPE_RCAPLONG:
2526 if (cdai->flags & CDAI_FLAG_STORE) {
2527 if (device->rcap_buf != NULL) {
2528 free(device->rcap_buf, M_CAMXPT);
2529 device->rcap_buf = NULL;
2532 device->rcap_len = cdai->bufsiz;
2533 /* Clear existing buffer if zero length */
2534 if (cdai->bufsiz == 0)
2537 device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT,
2539 if (device->rcap_buf == NULL) {
2540 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
2544 memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz);
2546 cdai->provsiz = device->rcap_len;
2547 if (device->rcap_len == 0)
2549 amt = device->rcap_len;
2550 if (cdai->provsiz > cdai->bufsiz)
2552 memcpy(cdai->buf, device->rcap_buf, amt);
2555 case CDAI_TYPE_EXT_INQ:
2557 * We fetch extended inquiry data during probe, if
2558 * available. We don't allow changing it.
2560 if (cdai->flags & CDAI_FLAG_STORE)
2562 cdai->provsiz = device->ext_inq_len;
2563 if (device->ext_inq_len == 0)
2565 amt = device->ext_inq_len;
2566 if (cdai->provsiz > cdai->bufsiz)
2568 memcpy(cdai->buf, device->ext_inq, amt);
2573 start_ccb->ccb_h.status = CAM_REQ_CMP;
2575 if (cdai->flags & CDAI_FLAG_STORE) {
2576 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
2577 (void *)(uintptr_t)cdai->buftype);
2582 scsi_action(union ccb *start_ccb)
2585 switch (start_ccb->ccb_h.func_code) {
2586 case XPT_SET_TRAN_SETTINGS:
2588 scsi_set_transfer_settings(&start_ccb->cts,
2589 start_ccb->ccb_h.path,
2590 /*async_update*/FALSE);
2595 scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
2598 scsi_scan_lun(start_ccb->ccb_h.path->periph,
2599 start_ccb->ccb_h.path, start_ccb->crcn.flags,
2602 case XPT_DEV_ADVINFO:
2604 scsi_dev_advinfo(start_ccb);
2608 xpt_action_default(start_ccb);
2614 scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
2617 struct ccb_pathinq cpi;
2618 struct ccb_trans_settings cur_cts;
2619 struct ccb_trans_settings_scsi *scsi;
2620 struct ccb_trans_settings_scsi *cur_scsi;
2621 struct scsi_inquiry_data *inq_data;
2622 struct cam_ed *device;
2624 if (path == NULL || (device = path->device) == NULL) {
2625 cts->ccb_h.status = CAM_PATH_INVALID;
2626 xpt_done((union ccb *)cts);
2630 if (cts->protocol == PROTO_UNKNOWN
2631 || cts->protocol == PROTO_UNSPECIFIED) {
2632 cts->protocol = device->protocol;
2633 cts->protocol_version = device->protocol_version;
2636 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
2637 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
2638 cts->protocol_version = device->protocol_version;
2640 if (cts->protocol != device->protocol) {
2641 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
2642 cts->protocol, device->protocol);
2643 cts->protocol = device->protocol;
2646 if (cts->protocol_version > device->protocol_version) {
2648 xpt_print(path, "Down reving Protocol "
2649 "Version from %d to %d?\n", cts->protocol_version,
2650 device->protocol_version);
2652 cts->protocol_version = device->protocol_version;
2655 if (cts->transport == XPORT_UNKNOWN
2656 || cts->transport == XPORT_UNSPECIFIED) {
2657 cts->transport = device->transport;
2658 cts->transport_version = device->transport_version;
2661 if (cts->transport_version == XPORT_VERSION_UNKNOWN
2662 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
2663 cts->transport_version = device->transport_version;
2665 if (cts->transport != device->transport) {
2666 xpt_print(path, "Uninitialized Transport %x:%x?\n",
2667 cts->transport, device->transport);
2668 cts->transport = device->transport;
2671 if (cts->transport_version > device->transport_version) {
2673 xpt_print(path, "Down reving Transport "
2674 "Version from %d to %d?\n", cts->transport_version,
2675 device->transport_version);
2677 cts->transport_version = device->transport_version;
2681 * Nothing more of interest to do unless
2682 * this is a device connected via the
2685 if (cts->protocol != PROTO_SCSI) {
2686 if (async_update == FALSE)
2687 xpt_action_default((union ccb *)cts);
2691 inq_data = &device->inq_data;
2692 scsi = &cts->proto_specific.scsi;
2693 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
2694 cpi.ccb_h.func_code = XPT_PATH_INQ;
2695 xpt_action((union ccb *)&cpi);
2697 /* SCSI specific sanity checking */
2698 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
2699 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
2700 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
2701 || (device->mintags == 0)) {
2703 * Can't tag on hardware that doesn't support tags,
2704 * doesn't have it enabled, or has broken tag support.
2706 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2709 if (async_update == FALSE) {
2711 * Perform sanity checking against what the
2712 * controller and device can do.
2714 xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE);
2715 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2716 cur_cts.type = cts->type;
2717 xpt_action((union ccb *)&cur_cts);
2718 if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) {
2721 cur_scsi = &cur_cts.proto_specific.scsi;
2722 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
2723 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2724 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
2726 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
2727 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2730 /* SPI specific sanity checking */
2731 if (cts->transport == XPORT_SPI && async_update == FALSE) {
2733 struct ccb_trans_settings_spi *spi;
2734 struct ccb_trans_settings_spi *cur_spi;
2736 spi = &cts->xport_specific.spi;
2738 cur_spi = &cur_cts.xport_specific.spi;
2740 /* Fill in any gaps in what the user gave us */
2741 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2742 spi->sync_period = cur_spi->sync_period;
2743 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
2744 spi->sync_period = 0;
2745 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2746 spi->sync_offset = cur_spi->sync_offset;
2747 if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
2748 spi->sync_offset = 0;
2749 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2750 spi->ppr_options = cur_spi->ppr_options;
2751 if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0)
2752 spi->ppr_options = 0;
2753 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2754 spi->bus_width = cur_spi->bus_width;
2755 if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0)
2757 if ((spi->valid & CTS_SPI_VALID_DISC) == 0) {
2758 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2759 spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB;
2761 if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0)
2762 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2763 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2764 && (inq_data->flags & SID_Sync) == 0
2765 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2766 || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) {
2768 spi->sync_period = 0;
2769 spi->sync_offset = 0;
2772 switch (spi->bus_width) {
2773 case MSG_EXT_WDTR_BUS_32_BIT:
2774 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2775 || (inq_data->flags & SID_WBus32) != 0
2776 || cts->type == CTS_TYPE_USER_SETTINGS)
2777 && (cpi.hba_inquiry & PI_WIDE_32) != 0)
2779 /* Fall Through to 16-bit */
2780 case MSG_EXT_WDTR_BUS_16_BIT:
2781 if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0
2782 || (inq_data->flags & SID_WBus16) != 0
2783 || cts->type == CTS_TYPE_USER_SETTINGS)
2784 && (cpi.hba_inquiry & PI_WIDE_16) != 0) {
2785 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2788 /* Fall Through to 8-bit */
2789 default: /* New bus width?? */
2790 case MSG_EXT_WDTR_BUS_8_BIT:
2791 /* All targets can do this */
2792 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2796 spi3caps = cpi.xport_specific.spi.ppr_options;
2797 if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0
2798 && cts->type == CTS_TYPE_CURRENT_SETTINGS)
2799 spi3caps &= inq_data->spi3data;
2801 if ((spi3caps & SID_SPI_CLOCK_DT) == 0)
2802 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2804 if ((spi3caps & SID_SPI_IUS) == 0)
2805 spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2807 if ((spi3caps & SID_SPI_QAS) == 0)
2808 spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
2810 /* No SPI Transfer settings are allowed unless we are wide */
2811 if (spi->bus_width == 0)
2812 spi->ppr_options = 0;
2814 if ((spi->valid & CTS_SPI_VALID_DISC)
2815 && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) {
2817 * Can't tag queue without disconnection.
2819 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2820 scsi->valid |= CTS_SCSI_VALID_TQ;
2824 * If we are currently performing tagged transactions to
2825 * this device and want to change its negotiation parameters,
2826 * go non-tagged for a bit to give the controller a chance to
2827 * negotiate unhampered by tag messages.
2829 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2830 && (device->inq_flags & SID_CmdQue) != 0
2831 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2832 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE|
2833 CTS_SPI_VALID_SYNC_OFFSET|
2834 CTS_SPI_VALID_BUS_WIDTH)) != 0)
2835 scsi_toggle_tags(path);
2838 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
2839 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2843 * If we are transitioning from tags to no-tags or
2844 * vice-versa, we need to carefully freeze and restart
2845 * the queue so that we don't overlap tagged and non-tagged
2846 * commands. We also temporarily stop tags if there is
2847 * a change in transfer negotiation settings to allow
2848 * "tag-less" negotiation.
2850 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2851 || (device->inq_flags & SID_CmdQue) != 0)
2852 device_tagenb = TRUE;
2854 device_tagenb = FALSE;
2856 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
2857 && device_tagenb == FALSE)
2858 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
2859 && device_tagenb == TRUE)) {
2861 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
2863 * Delay change to use tags until after a
2864 * few commands have gone to this device so
2865 * the controller has time to perform transfer
2866 * negotiations without tagged messages getting
2869 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2870 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2872 xpt_stop_tags(path);
2876 if (async_update == FALSE)
2877 xpt_action_default((union ccb *)cts);
2881 scsi_toggle_tags(struct cam_path *path)
2886 * Give controllers a chance to renegotiate
2887 * before starting tag operations. We
2888 * "toggle" tagged queuing off then on
2889 * which causes the tag enable command delay
2890 * counter to come into effect.
2893 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
2894 || ((dev->inq_flags & SID_CmdQue) != 0
2895 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) {
2896 struct ccb_trans_settings cts;
2898 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
2899 cts.protocol = PROTO_SCSI;
2900 cts.protocol_version = PROTO_VERSION_UNSPECIFIED;
2901 cts.transport = XPORT_UNSPECIFIED;
2902 cts.transport_version = XPORT_VERSION_UNSPECIFIED;
2903 cts.proto_specific.scsi.flags = 0;
2904 cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ;
2905 scsi_set_transfer_settings(&cts, path,
2906 /*async_update*/TRUE);
2907 cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB;
2908 scsi_set_transfer_settings(&cts, path,
2909 /*async_update*/TRUE);
2914 * Handle any per-device event notifications that require action by the XPT.
2917 scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2918 struct cam_ed *device, void *async_arg)
2921 struct cam_path newpath;
2924 * We only need to handle events for real devices.
2926 if (target->target_id == CAM_TARGET_WILDCARD
2927 || device->lun_id == CAM_LUN_WILDCARD)
2931 * We need our own path with wildcards expanded to
2932 * handle certain types of events.
2934 if ((async_code == AC_SENT_BDR)
2935 || (async_code == AC_BUS_RESET)
2936 || (async_code == AC_INQ_CHANGED))
2937 status = xpt_compile_path(&newpath, NULL,
2942 status = CAM_REQ_CMP_ERR;
2944 if (status == CAM_REQ_CMP) {
2947 * Allow transfer negotiation to occur in a
2948 * tag free environment and after settle delay.
2950 if (async_code == AC_SENT_BDR
2951 || async_code == AC_BUS_RESET) {
2952 cam_freeze_devq(&newpath);
2953 cam_release_devq(&newpath,
2954 RELSIM_RELEASE_AFTER_TIMEOUT,
2956 /*timeout*/scsi_delay,
2957 /*getcount_only*/0);
2958 scsi_toggle_tags(&newpath);
2961 if (async_code == AC_INQ_CHANGED) {
2963 * We've sent a start unit command, or
2964 * something similar to a device that
2965 * may have caused its inquiry data to
2966 * change. So we re-scan the device to
2967 * refresh the inquiry data for it.
2969 scsi_scan_lun(newpath.periph, &newpath,
2970 CAM_EXPECT_INQ_CHANGE, NULL);
2972 xpt_release_path(&newpath);
2973 } else if (async_code == AC_LOST_DEVICE &&
2974 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2975 device->flags |= CAM_DEV_UNCONFIGURED;
2976 xpt_release_device(device);
2977 } else if (async_code == AC_TRANSFER_NEG) {
2978 struct ccb_trans_settings *settings;
2979 struct cam_path path;
2981 settings = (struct ccb_trans_settings *)async_arg;
2982 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2984 scsi_set_transfer_settings(settings, &path,
2985 /*async_update*/TRUE);
2986 xpt_release_path(&path);
2991 scsi_announce_periph(struct cam_periph *periph)
2993 struct ccb_pathinq cpi;
2994 struct ccb_trans_settings cts;
2995 struct cam_path *path = periph->path;
3000 cam_periph_assert(periph, MA_OWNED);
3002 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
3003 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
3004 cts.type = CTS_TYPE_CURRENT_SETTINGS;
3005 xpt_action((union ccb*)&cts);
3006 if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP)
3008 /* Ask the SIM for its base transfer speed */
3009 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
3010 cpi.ccb_h.func_code = XPT_PATH_INQ;
3011 xpt_action((union ccb *)&cpi);
3012 /* Report connection speed */
3013 speed = cpi.base_transfer_speed;
3015 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3016 struct ccb_trans_settings_spi *spi =
3017 &cts.xport_specific.spi;
3019 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0
3020 && spi->sync_offset != 0) {
3021 freq = scsi_calc_syncsrate(spi->sync_period);
3024 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0)
3025 speed *= (0x01 << spi->bus_width);
3027 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3028 struct ccb_trans_settings_fc *fc =
3029 &cts.xport_specific.fc;
3031 if (fc->valid & CTS_FC_VALID_SPEED)
3032 speed = fc->bitrate;
3034 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) {
3035 struct ccb_trans_settings_sas *sas =
3036 &cts.xport_specific.sas;
3038 if (sas->valid & CTS_SAS_VALID_SPEED)
3039 speed = sas->bitrate;
3043 printf("%s%d: %d.%03dMB/s transfers",
3044 periph->periph_name, periph->unit_number,
3047 printf("%s%d: %dKB/s transfers", periph->periph_name,
3048 periph->unit_number, speed);
3049 /* Report additional information about SPI connections */
3050 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) {
3051 struct ccb_trans_settings_spi *spi;
3053 spi = &cts.xport_specific.spi;
3055 printf(" (%d.%03dMHz%s, offset %d", freq / 1000,
3057 (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
3061 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0
3062 && spi->bus_width > 0) {
3068 printf("%dbit)", 8 * (0x01 << spi->bus_width));
3069 } else if (freq != 0) {
3073 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) {
3074 struct ccb_trans_settings_fc *fc;
3076 fc = &cts.xport_specific.fc;
3077 if (fc->valid & CTS_FC_VALID_WWNN)
3078 printf(" WWNN 0x%llx", (long long) fc->wwnn);
3079 if (fc->valid & CTS_FC_VALID_WWPN)
3080 printf(" WWPN 0x%llx", (long long) fc->wwpn);
3081 if (fc->valid & CTS_FC_VALID_PORT)
3082 printf(" PortID 0x%x", fc->port);