2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/endian.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>
42 #include <sys/interrupt.h>
45 #include <sys/eventhandler.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/ata/ata_all.h>
64 #include <machine/stdarg.h> /* for xpt_print below */
67 struct ata_quirk_entry {
68 struct scsi_inquiry_pattern inq_pat;
70 #define CAM_QUIRK_MAXTAGS 0x01
75 static periph_init_t probe_periph_init;
77 static struct periph_driver probe_driver =
79 probe_periph_init, "aprobe",
80 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
84 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
101 PROBE_IDENTIFY_SAFTE,
106 static char *probe_action_text[] = {
117 "PROBE_FULL_INQUIRY",
120 "PROBE_IDENTIFY_SES",
121 "PROBE_IDENTIFY_SAFTE",
126 #define PROBE_SET_ACTION(softc, newaction) \
129 text = probe_action_text; \
130 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
131 ("Probe %s to %s\n", text[(softc)->action], \
132 text[(newaction)])); \
133 (softc)->action = (newaction); \
137 PROBE_NO_ANNOUNCE = 0x04
141 TAILQ_HEAD(, ccb_hdr) request_ccbs;
142 struct ata_params ident_data;
151 struct cam_periph *periph;
154 static struct ata_quirk_entry ata_quirk_table[] =
157 /* Default tagged queuing parameters for all devices */
159 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
160 /*vendor*/"*", /*product*/"*", /*revision*/"*"
162 /*quirks*/0, /*mintags*/0, /*maxtags*/0
166 static cam_status proberegister(struct cam_periph *periph,
168 static void probeschedule(struct cam_periph *probe_periph);
169 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
170 static void proberequestdefaultnegotiation(struct cam_periph *periph);
171 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
172 static void probecleanup(struct cam_periph *periph);
173 static void ata_find_quirk(struct cam_ed *device);
174 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
175 static void ata_scan_lun(struct cam_periph *periph,
176 struct cam_path *path, cam_flags flags,
178 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
179 static struct cam_ed *
180 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
182 static void ata_device_transport(struct cam_path *path);
183 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
184 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
185 struct cam_path *path,
187 static void ata_dev_async(u_int32_t async_code,
189 struct cam_et *target,
190 struct cam_ed *device,
192 static void ata_action(union ccb *start_ccb);
193 static void ata_announce_periph(struct cam_periph *periph);
194 static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
195 static void ata_proto_announce(struct cam_ed *device);
196 static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
197 static void ata_proto_denounce(struct cam_ed *device);
198 static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
199 static void ata_proto_debug_out(union ccb *ccb);
200 static void semb_proto_announce(struct cam_ed *device);
201 static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
202 static void semb_proto_denounce(struct cam_ed *device);
203 static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
205 static int ata_dma = 1;
206 static int atapi_dma = 1;
208 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
209 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
211 static struct xpt_xport_ops ata_xport_ops = {
212 .alloc_device = ata_alloc_device,
213 .action = ata_action,
214 .async = ata_dev_async,
215 .announce = ata_announce_periph,
216 .announce_sbuf = ata_announce_periph_sbuf,
218 #define ATA_XPT_XPORT(x, X) \
219 static struct xpt_xport ata_xport_ ## x = { \
220 .xport = XPORT_ ## X, \
222 .ops = &ata_xport_ops, \
224 CAM_XPT_XPORT(ata_xport_ ## x);
226 ATA_XPT_XPORT(ata, ATA);
227 ATA_XPT_XPORT(sata, SATA);
229 #undef ATA_XPORT_XPORT
231 static struct xpt_proto_ops ata_proto_ops_ata = {
232 .announce = ata_proto_announce,
233 .announce_sbuf = ata_proto_announce_sbuf,
234 .denounce = ata_proto_denounce,
235 .denounce_sbuf = ata_proto_denounce_sbuf,
236 .debug_out = ata_proto_debug_out,
238 static struct xpt_proto ata_proto_ata = {
241 .ops = &ata_proto_ops_ata,
244 static struct xpt_proto_ops ata_proto_ops_satapm = {
245 .announce = ata_proto_announce,
246 .announce_sbuf = ata_proto_announce_sbuf,
247 .denounce = ata_proto_denounce,
248 .denounce_sbuf = ata_proto_denounce_sbuf,
249 .debug_out = ata_proto_debug_out,
251 static struct xpt_proto ata_proto_satapm = {
252 .proto = PROTO_SATAPM,
254 .ops = &ata_proto_ops_satapm,
257 static struct xpt_proto_ops ata_proto_ops_semb = {
258 .announce = semb_proto_announce,
259 .announce_sbuf = semb_proto_announce_sbuf,
260 .denounce = semb_proto_denounce,
261 .denounce_sbuf = semb_proto_denounce_sbuf,
262 .debug_out = ata_proto_debug_out,
264 static struct xpt_proto ata_proto_semb = {
267 .ops = &ata_proto_ops_semb,
270 CAM_XPT_PROTO(ata_proto_ata);
271 CAM_XPT_PROTO(ata_proto_satapm);
272 CAM_XPT_PROTO(ata_proto_semb);
280 proberegister(struct cam_periph *periph, void *arg)
282 union ccb *request_ccb; /* CCB representing the probe request */
285 request_ccb = (union ccb *)arg;
286 if (request_ccb == NULL) {
287 printf("proberegister: no probe CCB, "
288 "can't register device\n");
289 return(CAM_REQ_CMP_ERR);
292 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
295 printf("proberegister: Unable to probe new device. "
296 "Unable to allocate softc\n");
297 return(CAM_REQ_CMP_ERR);
299 TAILQ_INIT(&softc->request_ccbs);
300 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
303 periph->softc = softc;
304 softc->periph = periph;
305 softc->action = PROBE_INVALID;
306 if (cam_periph_acquire(periph) != 0)
307 return (CAM_REQ_CMP_ERR);
309 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
310 ata_device_transport(periph->path);
311 probeschedule(periph);
316 probeschedule(struct cam_periph *periph)
321 softc = (probe_softc *)periph->softc;
322 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
324 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
325 periph->path->device->protocol == PROTO_SATAPM ||
326 periph->path->device->protocol == PROTO_SEMB)
327 PROBE_SET_ACTION(softc, PROBE_RESET);
329 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
331 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
332 softc->flags |= PROBE_NO_ANNOUNCE;
334 softc->flags &= ~PROBE_NO_ANNOUNCE;
336 xpt_schedule(periph, CAM_PRIORITY_XPT);
340 probestart(struct cam_periph *periph, union ccb *start_ccb)
342 struct ccb_trans_settings cts;
343 struct ccb_ataio *ataio;
344 struct ccb_scsiio *csio;
346 struct cam_path *path;
347 struct ata_params *ident_buf;
349 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
351 softc = (probe_softc *)periph->softc;
352 path = start_ccb->ccb_h.path;
353 ataio = &start_ccb->ataio;
354 csio = &start_ccb->csio;
355 ident_buf = &periph->path->device->ident_data;
357 if (softc->restart) {
359 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
360 path->device->protocol == PROTO_SATAPM ||
361 path->device->protocol == PROTO_SEMB)
362 softc->action = PROBE_RESET;
364 softc->action = PROBE_IDENTIFY;
366 switch (softc->action) {
368 cam_fill_ataio(ataio,
371 /*flags*/CAM_DIR_NONE,
376 ata_reset_cmd(ataio);
379 cam_fill_ataio(ataio,
384 /*data_ptr*/(u_int8_t *)&softc->ident_data,
385 /*dxfer_len*/sizeof(softc->ident_data),
387 if (periph->path->device->protocol == PROTO_ATA)
388 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
390 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
394 xpt_print(path, "Spinning up device\n");
395 cam_fill_ataio(ataio,
398 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
403 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
410 /* Fetch user modes from SIM. */
411 bzero(&cts, sizeof(cts));
412 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
413 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
414 cts.type = CTS_TYPE_USER_SETTINGS;
415 xpt_action((union ccb *)&cts);
416 if (path->device->transport == XPORT_ATA) {
417 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
418 mode = cts.xport_specific.ata.mode;
420 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
421 mode = cts.xport_specific.sata.mode;
423 if (periph->path->device->protocol == PROTO_ATA) {
424 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
427 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
431 /* Honor device capabilities. */
432 wantmode = mode = ata_max_mode(ident_buf, mode);
433 /* Report modes to SIM. */
434 bzero(&cts, sizeof(cts));
435 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
436 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
437 cts.type = CTS_TYPE_CURRENT_SETTINGS;
438 if (path->device->transport == XPORT_ATA) {
439 cts.xport_specific.ata.mode = mode;
440 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
442 cts.xport_specific.sata.mode = mode;
443 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
445 xpt_action((union ccb *)&cts);
446 /* Fetch current modes from SIM. */
447 bzero(&cts, sizeof(cts));
448 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
449 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
450 cts.type = CTS_TYPE_CURRENT_SETTINGS;
451 xpt_action((union ccb *)&cts);
452 if (path->device->transport == XPORT_ATA) {
453 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
454 mode = cts.xport_specific.ata.mode;
456 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
457 mode = cts.xport_specific.sata.mode;
459 /* If SIM disagree - renegotiate. */
460 if (mode != wantmode)
462 /* Remember what transport thinks about DMA. */
464 path->device->inq_flags &= ~SID_DMA;
466 path->device->inq_flags |= SID_DMA;
467 xpt_async(AC_GETDEV_CHANGED, path, NULL);
468 cam_fill_ataio(ataio,
471 /*flags*/CAM_DIR_NONE,
476 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
480 cam_fill_ataio(ataio,
488 ata_28bit_cmd(ataio, ATA_SETFEATURES,
489 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
493 cam_fill_ataio(ataio,
501 ata_28bit_cmd(ataio, ATA_SETFEATURES,
502 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
506 cam_fill_ataio(ataio,
514 ata_28bit_cmd(ataio, ATA_SETFEATURES,
515 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
519 /* Remember what transport thinks about AEN. */
520 if (softc->caps & CTS_SATA_CAPS_H_AN)
521 path->device->inq_flags |= SID_AEN;
523 path->device->inq_flags &= ~SID_AEN;
524 xpt_async(AC_GETDEV_CHANGED, path, NULL);
525 cam_fill_ataio(ataio,
533 ata_28bit_cmd(ataio, ATA_SETFEATURES,
534 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
537 case PROBE_SET_MULTI:
539 u_int sectors, bytecount;
541 bytecount = 8192; /* SATA maximum */
542 /* Fetch user bytecount from SIM. */
543 bzero(&cts, sizeof(cts));
544 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
545 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
546 cts.type = CTS_TYPE_USER_SETTINGS;
547 xpt_action((union ccb *)&cts);
548 if (path->device->transport == XPORT_ATA) {
549 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
550 bytecount = cts.xport_specific.ata.bytecount;
552 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
553 bytecount = cts.xport_specific.sata.bytecount;
555 /* Honor device capabilities. */
556 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
557 bytecount / ata_logical_sector_size(ident_buf)));
558 /* Report bytecount to SIM. */
559 bzero(&cts, sizeof(cts));
560 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
561 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
562 cts.type = CTS_TYPE_CURRENT_SETTINGS;
563 if (path->device->transport == XPORT_ATA) {
564 cts.xport_specific.ata.bytecount = sectors *
565 ata_logical_sector_size(ident_buf);
566 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
568 cts.xport_specific.sata.bytecount = sectors *
569 ata_logical_sector_size(ident_buf);
570 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
572 xpt_action((union ccb *)&cts);
573 /* Fetch current bytecount from SIM. */
574 bzero(&cts, sizeof(cts));
575 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
576 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
577 cts.type = CTS_TYPE_CURRENT_SETTINGS;
578 xpt_action((union ccb *)&cts);
579 if (path->device->transport == XPORT_ATA) {
580 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
581 bytecount = cts.xport_specific.ata.bytecount;
583 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
584 bytecount = cts.xport_specific.sata.bytecount;
586 sectors = bytecount / ata_logical_sector_size(ident_buf);
588 cam_fill_ataio(ataio,
596 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
603 bytecount = 8192; /* SATA maximum */
604 /* Fetch user bytecount from SIM. */
605 bzero(&cts, sizeof(cts));
606 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
607 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
608 cts.type = CTS_TYPE_USER_SETTINGS;
609 xpt_action((union ccb *)&cts);
610 if (path->device->transport == XPORT_ATA) {
611 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
612 bytecount = cts.xport_specific.ata.bytecount;
614 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
615 bytecount = cts.xport_specific.sata.bytecount;
617 /* Honor device capabilities. */
619 bytecount = max(2, min(65534, bytecount));
620 if (ident_buf->satacapabilities != 0x0000 &&
621 ident_buf->satacapabilities != 0xffff) {
622 bytecount = min(8192, bytecount);
624 /* Report bytecount to SIM. */
625 bzero(&cts, sizeof(cts));
626 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
627 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
628 cts.type = CTS_TYPE_CURRENT_SETTINGS;
629 if (path->device->transport == XPORT_ATA) {
630 cts.xport_specific.ata.bytecount = bytecount;
631 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
633 cts.xport_specific.sata.bytecount = bytecount;
634 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
636 xpt_action((union ccb *)&cts);
639 case PROBE_FULL_INQUIRY:
642 struct scsi_inquiry_data *inq_buf =
643 &periph->path->device->inq_data;
645 if (softc->action == PROBE_INQUIRY)
646 inquiry_len = SHORT_INQUIRY_LENGTH;
648 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
650 * Some parallel SCSI devices fail to send an
651 * ignore wide residue message when dealing with
652 * odd length inquiry requests. Round up to be
655 inquiry_len = roundup2(inquiry_len, 2);
665 /*timeout*/60 * 1000);
669 cam_fill_ataio(ataio,
672 /*flags*/CAM_DIR_NONE,
677 ata_pm_read_cmd(ataio, 0, 15);
680 cam_fill_ataio(ataio,
683 /*flags*/CAM_DIR_NONE,
688 ata_pm_read_cmd(ataio, 1, 15);
690 case PROBE_IDENTIFY_SES:
691 cam_fill_ataio(ataio,
696 /*data_ptr*/(u_int8_t *)&softc->ident_data,
697 /*dxfer_len*/sizeof(softc->ident_data),
699 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
700 sizeof(softc->ident_data) / 4);
702 case PROBE_IDENTIFY_SAFTE:
703 cam_fill_ataio(ataio,
708 /*data_ptr*/(u_int8_t *)&softc->ident_data,
709 /*dxfer_len*/sizeof(softc->ident_data),
711 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
712 sizeof(softc->ident_data) / 4);
715 panic("probestart: invalid action state 0x%x\n", softc->action);
717 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
718 xpt_action(start_ccb);
722 proberequestdefaultnegotiation(struct cam_periph *periph)
724 struct ccb_trans_settings cts;
726 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
727 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
728 cts.type = CTS_TYPE_USER_SETTINGS;
729 xpt_action((union ccb *)&cts);
730 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
732 cts.xport_specific.valid = 0;
733 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
734 cts.type = CTS_TYPE_CURRENT_SETTINGS;
735 xpt_action((union ccb *)&cts);
739 probedone(struct cam_periph *periph, union ccb *done_ccb)
741 struct ccb_trans_settings cts;
742 struct ata_params *ident_buf;
743 struct scsi_inquiry_data *inq_buf;
745 struct cam_path *path;
749 int changed = 1, found = 1;
750 static const uint8_t fake_device_id_hdr[8] =
751 {0, SVPD_DEVICE_ID, 0, 12,
752 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
754 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
756 softc = (probe_softc *)periph->softc;
757 path = done_ccb->ccb_h.path;
758 priority = done_ccb->ccb_h.pinfo.priority;
759 ident_buf = &path->device->ident_data;
760 inq_buf = &path->device->inq_data;
762 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
763 if (cam_periph_error(done_ccb,
764 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
767 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
768 cam_release_devq(path, 0, 0, 0, FALSE);
771 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
772 /* Don't wedge the queue */
773 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
775 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
776 if (softc->restart) {
778 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
781 if (softc->faults < 10)
786 /* Old PIO2 devices may not support mode setting. */
787 } else if (softc->action == PROBE_SETMODE &&
788 status == CAM_ATA_STATUS_ERROR &&
789 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
790 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
794 * Some old WD SATA disks report supported and enabled
795 * device-initiated interface power management, but return
796 * ABORT on attempt to disable it.
798 } else if (softc->action == PROBE_SETPM &&
799 status == CAM_ATA_STATUS_ERROR) {
803 * Some old WD SATA disks have broken SPINUP handling.
804 * If we really fail to spin up the disk, then there will be
805 * some media access errors later on, but at least we will
806 * have a device to interact with for recovery attempts.
808 } else if (softc->action == PROBE_SPINUP &&
809 status == CAM_ATA_STATUS_ERROR) {
813 * Some HP SATA disks report supported DMA Auto-Activation,
814 * but return ABORT on attempt to enable it.
816 } else if (softc->action == PROBE_SETDMAAA &&
817 status == CAM_ATA_STATUS_ERROR) {
821 * SES and SAF-TE SEPs have different IDENTIFY commands,
822 * but SATA specification doesn't tell how to identify them.
823 * Until better way found, just try another if first fail.
825 } else if (softc->action == PROBE_IDENTIFY_SES &&
826 status == CAM_ATA_STATUS_ERROR) {
827 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
828 xpt_release_ccb(done_ccb);
829 xpt_schedule(periph, priority);
834 * If we get to this point, we got an error status back
835 * from the inquiry and the error status doesn't require
836 * automatically retrying the command. Therefore, the
837 * inquiry failed. If we had inquiry information before
838 * for this device, but this latest inquiry command failed,
839 * the device has probably gone away. If this device isn't
840 * already marked unconfigured, notify the peripheral
841 * drivers that this device is no more.
843 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
844 xpt_async(AC_LOST_DEVICE, path, NULL);
845 PROBE_SET_ACTION(softc, PROBE_INVALID);
852 switch (softc->action) {
855 int sign = (done_ccb->ataio.res.lba_high << 8) +
856 done_ccb->ataio.res.lba_mid;
857 CAM_DEBUG(path, CAM_DEBUG_PROBE,
858 ("SIGNATURE: %04x\n", sign));
859 if (sign == 0x0000 &&
860 done_ccb->ccb_h.target_id != 15) {
861 path->device->protocol = PROTO_ATA;
862 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
863 } else if (sign == 0x9669 &&
864 done_ccb->ccb_h.target_id == 15) {
865 /* Report SIM that PM is present. */
866 bzero(&cts, sizeof(cts));
867 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
868 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
869 cts.type = CTS_TYPE_CURRENT_SETTINGS;
870 cts.xport_specific.sata.pm_present = 1;
871 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
872 xpt_action((union ccb *)&cts);
873 path->device->protocol = PROTO_SATAPM;
874 PROBE_SET_ACTION(softc, PROBE_PM_PID);
875 } else if (sign == 0xc33c &&
876 done_ccb->ccb_h.target_id != 15) {
877 path->device->protocol = PROTO_SEMB;
878 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
879 } else if (sign == 0xeb14 &&
880 done_ccb->ccb_h.target_id != 15) {
881 path->device->protocol = PROTO_SCSI;
882 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
884 if (done_ccb->ccb_h.target_id != 15) {
886 "Unexpected signature 0x%04x\n", sign);
890 xpt_release_ccb(done_ccb);
891 xpt_schedule(periph, priority);
896 struct ccb_pathinq cpi;
900 ident_buf = &softc->ident_data;
901 for (ptr = (int16_t *)ident_buf;
902 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
903 *ptr = le16toh(*ptr);
907 * Allow others to veto this ATA disk attachment. This
908 * is mainly used by VMs, whose disk controllers may
909 * share the disks with the simulated ATA controllers.
911 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
916 if (strncmp(ident_buf->model, "FX", 2) &&
917 strncmp(ident_buf->model, "NEC", 3) &&
918 strncmp(ident_buf->model, "Pioneer", 7) &&
919 strncmp(ident_buf->model, "SHARP", 5)) {
920 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
921 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
922 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
924 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
925 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
926 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
927 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
928 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
929 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
930 /* Device may need spin-up before IDENTIFY become valid. */
931 if ((ident_buf->specconf == 0x37c8 ||
932 ident_buf->specconf == 0x738c) &&
933 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
934 softc->spinup == 0)) {
935 PROBE_SET_ACTION(softc, PROBE_SPINUP);
936 xpt_release_ccb(done_ccb);
937 xpt_schedule(periph, priority);
940 ident_buf = &path->device->ident_data;
941 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
942 /* Check that it is the same device. */
943 if (bcmp(softc->ident_data.model, ident_buf->model,
944 sizeof(ident_buf->model)) ||
945 bcmp(softc->ident_data.revision, ident_buf->revision,
946 sizeof(ident_buf->revision)) ||
947 bcmp(softc->ident_data.serial, ident_buf->serial,
948 sizeof(ident_buf->serial))) {
949 /* Device changed. */
950 xpt_async(AC_LOST_DEVICE, path, NULL);
952 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
957 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
958 /* Clean up from previous instance of this device */
959 if (path->device->serial_num != NULL) {
960 free(path->device->serial_num, M_CAMXPT);
961 path->device->serial_num = NULL;
962 path->device->serial_num_len = 0;
964 if (path->device->device_id != NULL) {
965 free(path->device->device_id, M_CAMXPT);
966 path->device->device_id = NULL;
967 path->device->device_id_len = 0;
969 path->device->serial_num =
970 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
972 if (path->device->serial_num != NULL) {
973 bcopy(ident_buf->serial,
974 path->device->serial_num,
975 sizeof(ident_buf->serial));
976 path->device->serial_num[sizeof(ident_buf->serial)]
978 path->device->serial_num_len =
979 strlen(path->device->serial_num);
981 if (ident_buf->enabled.extension &
982 ATA_SUPPORT_64BITWWN) {
983 path->device->device_id =
984 malloc(16, M_CAMXPT, M_NOWAIT);
985 if (path->device->device_id != NULL) {
986 path->device->device_id_len = 16;
987 bcopy(&fake_device_id_hdr,
988 path->device->device_id, 8);
989 bcopy(ident_buf->wwn,
990 path->device->device_id + 8, 8);
991 ata_bswap(path->device->device_id + 8, 8);
995 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
996 xpt_async(AC_GETDEV_CHANGED, path, NULL);
998 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
999 path->device->mintags = 2;
1000 path->device->maxtags =
1001 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1003 ata_find_quirk(path->device);
1004 if (path->device->mintags != 0 &&
1005 path->bus->sim->max_tagged_dev_openings != 0) {
1006 /* Check if the SIM does not want queued commands. */
1007 xpt_path_inq(&cpi, path);
1008 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1009 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1010 /* Report SIM which tags are allowed. */
1011 bzero(&cts, sizeof(cts));
1012 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1013 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1014 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1015 cts.xport_specific.sata.tags = path->device->maxtags;
1016 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1017 xpt_action((union ccb *)&cts);
1020 ata_device_transport(path);
1022 proberequestdefaultnegotiation(periph);
1023 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1024 xpt_release_ccb(done_ccb);
1025 xpt_schedule(periph, priority);
1030 xpt_print(path, "Spin-up done\n");
1032 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1033 xpt_release_ccb(done_ccb);
1034 xpt_schedule(periph, priority);
1037 /* Set supported bits. */
1038 bzero(&cts, sizeof(cts));
1039 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1040 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1041 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1042 xpt_action((union ccb *)&cts);
1043 if (path->device->transport == XPORT_SATA &&
1044 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1045 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1046 else if (path->device->transport == XPORT_ATA &&
1047 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1048 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1051 if (path->device->transport == XPORT_SATA &&
1052 ident_buf->satacapabilities != 0xffff) {
1053 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1054 caps |= CTS_SATA_CAPS_D_PMREQ;
1055 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1056 caps |= CTS_SATA_CAPS_D_APST;
1058 /* Mask unwanted bits. */
1059 bzero(&cts, sizeof(cts));
1060 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1061 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1062 cts.type = CTS_TYPE_USER_SETTINGS;
1063 xpt_action((union ccb *)&cts);
1064 if (path->device->transport == XPORT_SATA &&
1065 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1066 caps &= cts.xport_specific.sata.caps;
1067 else if (path->device->transport == XPORT_ATA &&
1068 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1069 caps &= cts.xport_specific.ata.caps;
1073 * Remember what transport thinks about 48-bit DMA. If
1074 * capability information is not provided or transport is
1075 * SATA, we take support for granted.
1077 if (!(path->device->inq_flags & SID_DMA) ||
1078 (path->device->transport == XPORT_ATA &&
1079 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1080 !(caps & CTS_ATA_CAPS_H_DMA48)))
1081 path->device->inq_flags &= ~SID_DMA48;
1083 path->device->inq_flags |= SID_DMA48;
1084 /* Store result to SIM. */
1085 bzero(&cts, sizeof(cts));
1086 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1087 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1088 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1089 if (path->device->transport == XPORT_SATA) {
1090 cts.xport_specific.sata.caps = caps;
1091 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1093 cts.xport_specific.ata.caps = caps;
1094 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1096 xpt_action((union ccb *)&cts);
1098 if (path->device->transport != XPORT_SATA)
1100 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1101 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1102 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1103 PROBE_SET_ACTION(softc, PROBE_SETPM);
1104 xpt_release_ccb(done_ccb);
1105 xpt_schedule(periph, priority);
1110 if (ident_buf->satacapabilities != 0xffff &&
1111 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1112 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1113 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1114 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1115 xpt_release_ccb(done_ccb);
1116 xpt_schedule(periph, priority);
1121 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1122 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1123 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1124 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1125 xpt_release_ccb(done_ccb);
1126 xpt_schedule(periph, priority);
1130 case PROBE_SETDMAAA:
1131 if (path->device->protocol != PROTO_ATA &&
1132 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1133 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1134 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1135 PROBE_SET_ACTION(softc, PROBE_SETAN);
1136 xpt_release_ccb(done_ccb);
1137 xpt_schedule(periph, priority);
1143 if (path->device->protocol == PROTO_ATA) {
1144 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1146 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1148 xpt_release_ccb(done_ccb);
1149 xpt_schedule(periph, priority);
1151 case PROBE_SET_MULTI:
1152 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1153 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1154 xpt_acquire_device(path->device);
1155 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1156 xpt_action(done_ccb);
1157 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1159 PROBE_SET_ACTION(softc, PROBE_DONE);
1162 case PROBE_FULL_INQUIRY:
1164 u_int8_t periph_qual, len;
1166 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1168 periph_qual = SID_QUAL(inq_buf);
1170 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1171 periph_qual != SID_QUAL_LU_OFFLINE)
1175 * We conservatively request only
1176 * SHORT_INQUIRY_LEN bytes of inquiry
1177 * information during our first try
1178 * at sending an INQUIRY. If the device
1179 * has more information to give,
1180 * perform a second request specifying
1181 * the amount of information the device
1182 * is willing to give.
1184 len = inq_buf->additional_length
1185 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1186 if (softc->action == PROBE_INQUIRY
1187 && len > SHORT_INQUIRY_LENGTH) {
1188 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1189 xpt_release_ccb(done_ccb);
1190 xpt_schedule(periph, priority);
1194 ata_device_transport(path);
1195 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1196 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1197 xpt_acquire_device(path->device);
1198 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1199 xpt_action(done_ccb);
1200 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1202 PROBE_SET_ACTION(softc, PROBE_DONE);
1206 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1207 bzero(ident_buf, sizeof(*ident_buf));
1208 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1209 (done_ccb->ataio.res.lba_mid << 16) +
1210 (done_ccb->ataio.res.lba_low << 8) +
1211 done_ccb->ataio.res.sector_count;
1212 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1213 snprintf(ident_buf->model, sizeof(ident_buf->model),
1214 "Port Multiplier %08x", softc->pm_pid);
1215 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1216 xpt_release_ccb(done_ccb);
1217 xpt_schedule(periph, priority);
1220 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1221 (done_ccb->ataio.res.lba_mid << 16) +
1222 (done_ccb->ataio.res.lba_low << 8) +
1223 done_ccb->ataio.res.sector_count;
1224 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1225 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1226 "%04x", softc->pm_prv);
1227 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1228 ata_device_transport(path);
1229 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1230 proberequestdefaultnegotiation(periph);
1231 /* Set supported bits. */
1232 bzero(&cts, sizeof(cts));
1233 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1234 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1235 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1236 xpt_action((union ccb *)&cts);
1237 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1238 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1241 /* All PMPs must support PM requests. */
1242 caps |= CTS_SATA_CAPS_D_PMREQ;
1243 /* Mask unwanted bits. */
1244 bzero(&cts, sizeof(cts));
1245 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1246 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1247 cts.type = CTS_TYPE_USER_SETTINGS;
1248 xpt_action((union ccb *)&cts);
1249 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1250 caps &= cts.xport_specific.sata.caps;
1253 /* Remember what transport thinks about AEN. */
1254 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1255 path->device->inq_flags |= SID_AEN;
1257 path->device->inq_flags &= ~SID_AEN;
1258 /* Store result to SIM. */
1259 bzero(&cts, sizeof(cts));
1260 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1261 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1262 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1263 cts.xport_specific.sata.caps = caps;
1264 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1265 xpt_action((union ccb *)&cts);
1267 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1268 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1269 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1270 xpt_acquire_device(path->device);
1271 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1272 xpt_action(done_ccb);
1273 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1275 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1276 xpt_action(done_ccb);
1277 xpt_async(AC_SCSI_AEN, path, done_ccb);
1279 PROBE_SET_ACTION(softc, PROBE_DONE);
1281 case PROBE_IDENTIFY_SES:
1282 case PROBE_IDENTIFY_SAFTE:
1283 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1284 /* Check that it is the same device. */
1285 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1286 /* Device changed. */
1287 xpt_async(AC_LOST_DEVICE, path, NULL);
1289 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1294 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1295 /* Clean up from previous instance of this device */
1296 if (path->device->device_id != NULL) {
1297 free(path->device->device_id, M_CAMXPT);
1298 path->device->device_id = NULL;
1299 path->device->device_id_len = 0;
1301 path->device->device_id =
1302 malloc(16, M_CAMXPT, M_NOWAIT);
1303 if (path->device->device_id != NULL) {
1304 path->device->device_id_len = 16;
1305 bcopy(&fake_device_id_hdr,
1306 path->device->device_id, 8);
1307 bcopy(((uint8_t*)ident_buf) + 2,
1308 path->device->device_id + 8, 8);
1311 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1313 ata_device_transport(path);
1315 proberequestdefaultnegotiation(periph);
1317 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1318 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1319 xpt_acquire_device(path->device);
1320 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1321 xpt_action(done_ccb);
1322 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1324 PROBE_SET_ACTION(softc, PROBE_DONE);
1327 panic("probedone: invalid action state 0x%x\n", softc->action);
1330 if (softc->restart) {
1332 xpt_release_ccb(done_ccb);
1333 probeschedule(periph);
1336 xpt_release_ccb(done_ccb);
1337 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1338 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1339 TAILQ_REMOVE(&softc->request_ccbs,
1340 &done_ccb->ccb_h, periph_links.tqe);
1341 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1344 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1345 cam_release_devq(path, 0, 0, 0, FALSE);
1346 cam_periph_invalidate(periph);
1347 cam_periph_release_locked(periph);
1351 probecleanup(struct cam_periph *periph)
1353 free(periph->softc, M_CAMXPT);
1357 ata_find_quirk(struct cam_ed *device)
1359 struct ata_quirk_entry *quirk;
1362 match = cam_quirkmatch((caddr_t)&device->ident_data,
1363 (caddr_t)ata_quirk_table,
1364 nitems(ata_quirk_table),
1365 sizeof(*ata_quirk_table), ata_identify_match);
1368 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1370 quirk = (struct ata_quirk_entry *)match;
1371 device->quirk = quirk;
1372 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1373 device->mintags = quirk->mintags;
1374 device->maxtags = quirk->maxtags;
1379 union ccb *request_ccb;
1380 struct ccb_pathinq *cpi;
1382 } ata_scan_bus_info;
1385 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1386 * As the scan progresses, xpt_scan_bus is used as the
1387 * callback on completion function.
1390 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1392 struct cam_path *path;
1393 ata_scan_bus_info *scan_info;
1394 union ccb *work_ccb, *reset_ccb;
1398 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1399 ("xpt_scan_bus\n"));
1400 switch (request_ccb->ccb_h.func_code) {
1403 /* Find out the characteristics of the bus */
1404 work_ccb = xpt_alloc_ccb_nowait();
1405 if (work_ccb == NULL) {
1406 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1407 xpt_done(request_ccb);
1410 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1411 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1412 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1413 xpt_free_ccb(work_ccb);
1414 xpt_done(request_ccb);
1418 /* We may need to reset bus first, if we haven't done it yet. */
1419 if ((work_ccb->cpi.hba_inquiry &
1420 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1421 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1422 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1423 reset_ccb = xpt_alloc_ccb_nowait();
1424 if (reset_ccb == NULL) {
1425 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1426 xpt_free_ccb(work_ccb);
1427 xpt_done(request_ccb);
1430 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1432 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1433 xpt_action(reset_ccb);
1434 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1435 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1436 xpt_free_ccb(reset_ccb);
1437 xpt_free_ccb(work_ccb);
1438 xpt_done(request_ccb);
1441 xpt_free_ccb(reset_ccb);
1444 /* Save some state for use while we probe for devices */
1445 scan_info = (ata_scan_bus_info *)
1446 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1447 if (scan_info == NULL) {
1448 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1449 xpt_free_ccb(work_ccb);
1450 xpt_done(request_ccb);
1453 scan_info->request_ccb = request_ccb;
1454 scan_info->cpi = &work_ccb->cpi;
1455 /* If PM supported, probe it first. */
1456 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1457 scan_info->counter = scan_info->cpi->max_target;
1459 scan_info->counter = 0;
1461 work_ccb = xpt_alloc_ccb_nowait();
1462 if (work_ccb == NULL) {
1463 free(scan_info, M_CAMXPT);
1464 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1465 xpt_done(request_ccb);
1468 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1471 work_ccb = request_ccb;
1472 /* Reuse the same CCB to query if a device was really found */
1473 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1474 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1476 /* If there is PMP... */
1477 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1478 (scan_info->counter == scan_info->cpi->max_target)) {
1479 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1480 /* everything else will be probed by it */
1481 /* Free the current request path- we're done with it. */
1482 xpt_free_path(work_ccb->ccb_h.path);
1485 struct ccb_trans_settings cts;
1487 /* Report SIM that PM is absent. */
1488 bzero(&cts, sizeof(cts));
1489 xpt_setup_ccb(&cts.ccb_h,
1490 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1491 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1492 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1493 cts.xport_specific.sata.pm_present = 0;
1494 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1495 xpt_action((union ccb *)&cts);
1498 /* Free the current request path- we're done with it. */
1499 xpt_free_path(work_ccb->ccb_h.path);
1500 if (scan_info->counter ==
1501 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1502 0 : scan_info->cpi->max_target)) {
1505 xpt_free_ccb(work_ccb);
1506 xpt_free_ccb((union ccb *)scan_info->cpi);
1507 request_ccb = scan_info->request_ccb;
1508 free(scan_info, M_CAMXPT);
1509 request_ccb->ccb_h.status = CAM_REQ_CMP;
1510 xpt_done(request_ccb);
1513 /* Take next device. Wrap from max (PMP) to 0. */
1514 scan_info->counter = (scan_info->counter + 1 ) %
1515 (scan_info->cpi->max_target + 1);
1517 status = xpt_create_path(&path, NULL,
1518 scan_info->request_ccb->ccb_h.path_id,
1519 scan_info->counter, 0);
1520 if (status != CAM_REQ_CMP) {
1521 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1523 printf("xpt_scan_bus: xpt_create_path failed"
1524 " with status %#x, bus scan halted\n",
1526 xpt_free_ccb(work_ccb);
1527 xpt_free_ccb((union ccb *)scan_info->cpi);
1528 request_ccb = scan_info->request_ccb;
1529 free(scan_info, M_CAMXPT);
1530 request_ccb->ccb_h.status = status;
1531 xpt_done(request_ccb);
1534 xpt_setup_ccb(&work_ccb->ccb_h, path,
1535 scan_info->request_ccb->ccb_h.pinfo.priority);
1536 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1537 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1538 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1539 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1540 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1542 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1544 xpt_action(work_ccb);
1554 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1555 cam_flags flags, union ccb *request_ccb)
1557 struct ccb_pathinq cpi;
1559 struct cam_path *new_path;
1560 struct cam_periph *old_periph;
1563 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1565 xpt_path_inq(&cpi, path);
1566 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1567 if (request_ccb != NULL) {
1568 request_ccb->ccb_h.status = cpi.ccb_h.status;
1569 xpt_done(request_ccb);
1574 if (request_ccb == NULL) {
1575 request_ccb = xpt_alloc_ccb_nowait();
1576 if (request_ccb == NULL) {
1577 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1578 "can't continue\n");
1581 status = xpt_create_path(&new_path, NULL,
1583 path->target->target_id,
1584 path->device->lun_id);
1585 if (status != CAM_REQ_CMP) {
1586 xpt_print(path, "xpt_scan_lun: can't create path, "
1587 "can't continue\n");
1588 xpt_free_ccb(request_ccb);
1591 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1592 request_ccb->ccb_h.cbfcnp = xptscandone;
1593 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1594 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1595 request_ccb->crcn.flags = flags;
1598 lock = (xpt_path_owned(path) == 0);
1600 xpt_path_lock(path);
1601 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1602 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1605 softc = (probe_softc *)old_periph->softc;
1606 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1607 &request_ccb->ccb_h, periph_links.tqe);
1610 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1611 xpt_done(request_ccb);
1614 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1615 probestart, "aprobe",
1617 request_ccb->ccb_h.path, NULL, 0,
1620 if (status != CAM_REQ_CMP) {
1621 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1622 "returned an error, can't continue probe\n");
1623 request_ccb->ccb_h.status = status;
1624 xpt_done(request_ccb);
1628 xpt_path_unlock(path);
1632 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1635 xpt_free_path(done_ccb->ccb_h.path);
1636 xpt_free_ccb(done_ccb);
1639 static struct cam_ed *
1640 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1642 struct ata_quirk_entry *quirk;
1643 struct cam_ed *device;
1645 device = xpt_alloc_device(bus, target, lun_id);
1650 * Take the default quirk entry until we have inquiry
1651 * data and can determine a better quirk to use.
1653 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1654 device->quirk = (void *)quirk;
1655 device->mintags = 0;
1656 device->maxtags = 0;
1657 bzero(&device->inq_data, sizeof(device->inq_data));
1658 device->inq_flags = 0;
1659 device->queue_flags = 0;
1660 device->serial_num = NULL;
1661 device->serial_num_len = 0;
1666 ata_device_transport(struct cam_path *path)
1668 struct ccb_pathinq cpi;
1669 struct ccb_trans_settings cts;
1670 struct scsi_inquiry_data *inq_buf = NULL;
1671 struct ata_params *ident_buf = NULL;
1673 /* Get transport information from the SIM */
1674 xpt_path_inq(&cpi, path);
1676 path->device->transport = cpi.transport;
1677 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1678 inq_buf = &path->device->inq_data;
1679 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1680 ident_buf = &path->device->ident_data;
1681 if (path->device->protocol == PROTO_ATA) {
1682 path->device->protocol_version = ident_buf ?
1683 ata_version(ident_buf->version_major) : cpi.protocol_version;
1684 } else if (path->device->protocol == PROTO_SCSI) {
1685 path->device->protocol_version = inq_buf ?
1686 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1688 path->device->transport_version = ident_buf ?
1689 ata_version(ident_buf->version_major) : cpi.transport_version;
1691 /* Tell the controller what we think */
1692 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1693 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1694 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1695 cts.transport = path->device->transport;
1696 cts.transport_version = path->device->transport_version;
1697 cts.protocol = path->device->protocol;
1698 cts.protocol_version = path->device->protocol_version;
1699 cts.proto_specific.valid = 0;
1701 if (path->device->transport == XPORT_ATA) {
1702 cts.xport_specific.ata.atapi =
1703 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1704 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1705 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1706 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1708 cts.xport_specific.sata.atapi =
1709 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1710 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1711 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1712 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1715 cts.xport_specific.valid = 0;
1716 xpt_action((union ccb *)&cts);
1720 ata_dev_advinfo(union ccb *start_ccb)
1722 struct cam_ed *device;
1723 struct ccb_dev_advinfo *cdai;
1726 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1727 device = start_ccb->ccb_h.path->device;
1728 cdai = &start_ccb->cdai;
1729 switch(cdai->buftype) {
1730 case CDAI_TYPE_SCSI_DEVID:
1731 if (cdai->flags & CDAI_FLAG_STORE)
1733 cdai->provsiz = device->device_id_len;
1734 if (device->device_id_len == 0)
1736 amt = device->device_id_len;
1737 if (cdai->provsiz > cdai->bufsiz)
1739 memcpy(cdai->buf, device->device_id, amt);
1741 case CDAI_TYPE_SERIAL_NUM:
1742 if (cdai->flags & CDAI_FLAG_STORE)
1744 cdai->provsiz = device->serial_num_len;
1745 if (device->serial_num_len == 0)
1747 amt = device->serial_num_len;
1748 if (cdai->provsiz > cdai->bufsiz)
1750 memcpy(cdai->buf, device->serial_num, amt);
1752 case CDAI_TYPE_PHYS_PATH:
1753 if (cdai->flags & CDAI_FLAG_STORE) {
1754 if (device->physpath != NULL)
1755 free(device->physpath, M_CAMXPT);
1756 device->physpath_len = cdai->bufsiz;
1757 /* Clear existing buffer if zero length */
1758 if (cdai->bufsiz == 0)
1760 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1761 if (device->physpath == NULL) {
1762 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1765 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1767 cdai->provsiz = device->physpath_len;
1768 if (device->physpath_len == 0)
1770 amt = device->physpath_len;
1771 if (cdai->provsiz > cdai->bufsiz)
1773 memcpy(cdai->buf, device->physpath, amt);
1779 start_ccb->ccb_h.status = CAM_REQ_CMP;
1781 if (cdai->flags & CDAI_FLAG_STORE) {
1782 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1783 (void *)(uintptr_t)cdai->buftype);
1788 ata_action(union ccb *start_ccb)
1791 switch (start_ccb->ccb_h.func_code) {
1792 case XPT_SET_TRAN_SETTINGS:
1794 ata_set_transfer_settings(&start_ccb->cts,
1795 start_ccb->ccb_h.path,
1796 /*async_update*/FALSE);
1801 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1804 ata_scan_lun(start_ccb->ccb_h.path->periph,
1805 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1808 case XPT_GET_TRAN_SETTINGS:
1810 ata_get_transfer_settings(&start_ccb->cts);
1815 struct cam_ed *device;
1818 device = start_ccb->ccb_h.path->device;
1819 if (device->protocol == PROTO_SCSI &&
1820 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1822 device->ident_data.config & ATA_PROTO_MASK;
1825 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1826 (p == ATA_PROTO_ATAPI_16) ? 16 :
1827 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1829 if (start_ccb->csio.cdb_len > maxlen) {
1830 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1831 xpt_done(start_ccb);
1834 xpt_action_default(start_ccb);
1837 case XPT_DEV_ADVINFO:
1839 ata_dev_advinfo(start_ccb);
1843 xpt_action_default(start_ccb);
1849 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1851 struct ccb_trans_settings_ata *ata;
1852 struct ccb_trans_settings_scsi *scsi;
1853 struct cam_ed *device;
1855 device = cts->ccb_h.path->device;
1856 xpt_action_default((union ccb *)cts);
1858 if (cts->protocol == PROTO_UNKNOWN ||
1859 cts->protocol == PROTO_UNSPECIFIED) {
1860 cts->protocol = device->protocol;
1861 cts->protocol_version = device->protocol_version;
1864 if (cts->protocol == PROTO_ATA) {
1865 ata = &cts->proto_specific.ata;
1866 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1867 ata->valid |= CTS_ATA_VALID_TQ;
1868 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1869 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1870 (device->inq_flags & SID_CmdQue) != 0)
1871 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1874 if (cts->protocol == PROTO_SCSI) {
1875 scsi = &cts->proto_specific.scsi;
1876 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1877 scsi->valid |= CTS_SCSI_VALID_TQ;
1878 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1879 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1880 (device->inq_flags & SID_CmdQue) != 0)
1881 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1885 if (cts->transport == XPORT_UNKNOWN ||
1886 cts->transport == XPORT_UNSPECIFIED) {
1887 cts->transport = device->transport;
1888 cts->transport_version = device->transport_version;
1893 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1896 struct ccb_pathinq cpi;
1897 struct ccb_trans_settings_ata *ata;
1898 struct ccb_trans_settings_scsi *scsi;
1899 struct ata_params *ident_data;
1900 struct scsi_inquiry_data *inq_data;
1901 struct cam_ed *device;
1903 if (path == NULL || (device = path->device) == NULL) {
1904 cts->ccb_h.status = CAM_PATH_INVALID;
1905 xpt_done((union ccb *)cts);
1909 if (cts->protocol == PROTO_UNKNOWN
1910 || cts->protocol == PROTO_UNSPECIFIED) {
1911 cts->protocol = device->protocol;
1912 cts->protocol_version = device->protocol_version;
1915 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1916 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1917 cts->protocol_version = device->protocol_version;
1919 if (cts->protocol != device->protocol) {
1920 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1921 cts->protocol, device->protocol);
1922 cts->protocol = device->protocol;
1925 if (cts->protocol_version > device->protocol_version) {
1927 xpt_print(path, "Down reving Protocol "
1928 "Version from %d to %d?\n", cts->protocol_version,
1929 device->protocol_version);
1931 cts->protocol_version = device->protocol_version;
1934 if (cts->transport == XPORT_UNKNOWN
1935 || cts->transport == XPORT_UNSPECIFIED) {
1936 cts->transport = device->transport;
1937 cts->transport_version = device->transport_version;
1940 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1941 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1942 cts->transport_version = device->transport_version;
1944 if (cts->transport != device->transport) {
1945 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1946 cts->transport, device->transport);
1947 cts->transport = device->transport;
1950 if (cts->transport_version > device->transport_version) {
1952 xpt_print(path, "Down reving Transport "
1953 "Version from %d to %d?\n", cts->transport_version,
1954 device->transport_version);
1956 cts->transport_version = device->transport_version;
1959 ident_data = &device->ident_data;
1960 inq_data = &device->inq_data;
1961 if (cts->protocol == PROTO_ATA)
1962 ata = &cts->proto_specific.ata;
1965 if (cts->protocol == PROTO_SCSI)
1966 scsi = &cts->proto_specific.scsi;
1969 xpt_path_inq(&cpi, path);
1971 /* Sanity checking */
1972 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1973 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1974 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1975 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1976 || (device->mintags == 0)) {
1978 * Can't tag on hardware that doesn't support tags,
1979 * doesn't have it enabled, or has broken tag support.
1982 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1984 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1987 /* Start/stop tags use. */
1988 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1989 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1990 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1993 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1994 (device->inq_flags & SID_CmdQue) != 0);
1996 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1998 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2000 if (newt && !nowt) {
2002 * Delay change to use tags until after a
2003 * few commands have gone to this device so
2004 * the controller has time to perform transfer
2005 * negotiations without tagged messages getting
2008 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2009 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2010 } else if (nowt && !newt)
2011 xpt_stop_tags(path);
2014 if (async_update == FALSE)
2015 xpt_action_default((union ccb *)cts);
2019 * Handle any per-device event notifications that require action by the XPT.
2022 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2023 struct cam_ed *device, void *async_arg)
2026 struct cam_path newpath;
2029 * We only need to handle events for real devices.
2031 if (target->target_id == CAM_TARGET_WILDCARD
2032 || device->lun_id == CAM_LUN_WILDCARD)
2036 * We need our own path with wildcards expanded to
2037 * handle certain types of events.
2039 if ((async_code == AC_SENT_BDR)
2040 || (async_code == AC_BUS_RESET)
2041 || (async_code == AC_INQ_CHANGED))
2042 status = xpt_compile_path(&newpath, NULL,
2047 status = CAM_REQ_CMP_ERR;
2049 if (status == CAM_REQ_CMP) {
2050 if (async_code == AC_INQ_CHANGED) {
2052 * We've sent a start unit command, or
2053 * something similar to a device that
2054 * may have caused its inquiry data to
2055 * change. So we re-scan the device to
2056 * refresh the inquiry data for it.
2058 ata_scan_lun(newpath.periph, &newpath,
2059 CAM_EXPECT_INQ_CHANGE, NULL);
2061 /* We need to reinitialize device after reset. */
2062 ata_scan_lun(newpath.periph, &newpath,
2065 xpt_release_path(&newpath);
2066 } else if (async_code == AC_LOST_DEVICE &&
2067 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2068 device->flags |= CAM_DEV_UNCONFIGURED;
2069 xpt_release_device(device);
2070 } else if (async_code == AC_TRANSFER_NEG) {
2071 struct ccb_trans_settings *settings;
2072 struct cam_path path;
2074 settings = (struct ccb_trans_settings *)async_arg;
2075 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2077 ata_set_transfer_settings(settings, &path,
2078 /*async_update*/TRUE);
2079 xpt_release_path(&path);
2084 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2086 struct ccb_pathinq cpi;
2087 struct cam_path *path = periph->path;
2089 cam_periph_assert(periph, MA_OWNED);
2091 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2092 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2093 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2094 xpt_action((union ccb*)cts);
2095 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2097 /* Ask the SIM for its base transfer speed */
2098 xpt_path_inq(&cpi, path);
2099 /* Report connection speed */
2100 *speed = cpi.base_transfer_speed;
2101 if (cts->transport == XPORT_ATA) {
2102 struct ccb_trans_settings_pata *pata =
2103 &cts->xport_specific.ata;
2105 if (pata->valid & CTS_ATA_VALID_MODE)
2106 *speed = ata_mode2speed(pata->mode);
2108 if (cts->transport == XPORT_SATA) {
2109 struct ccb_trans_settings_sata *sata =
2110 &cts->xport_specific.sata;
2112 if (sata->valid & CTS_SATA_VALID_REVISION)
2113 *speed = ata_revision2speed(sata->revision);
2118 ata_announce_periph(struct cam_periph *periph)
2120 struct ccb_trans_settings cts;
2123 _ata_announce_periph(periph, &cts, &speed);
2124 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2129 printf("%s%d: %d.%03dMB/s transfers",
2130 periph->periph_name, periph->unit_number,
2133 printf("%s%d: %dKB/s transfers", periph->periph_name,
2134 periph->unit_number, speed);
2135 /* Report additional information about connection */
2136 if (cts.transport == XPORT_ATA) {
2137 struct ccb_trans_settings_pata *pata =
2138 &cts.xport_specific.ata;
2141 if (pata->valid & CTS_ATA_VALID_MODE)
2142 printf("%s, ", ata_mode2string(pata->mode));
2143 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2144 printf("ATAPI %dbytes, ", pata->atapi);
2145 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2146 printf("PIO %dbytes", pata->bytecount);
2149 if (cts.transport == XPORT_SATA) {
2150 struct ccb_trans_settings_sata *sata =
2151 &cts.xport_specific.sata;
2154 if (sata->valid & CTS_SATA_VALID_REVISION)
2155 printf("SATA %d.x, ", sata->revision);
2158 if (sata->valid & CTS_SATA_VALID_MODE)
2159 printf("%s, ", ata_mode2string(sata->mode));
2160 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2161 printf("ATAPI %dbytes, ", sata->atapi);
2162 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2163 printf("PIO %dbytes", sata->bytecount);
2170 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2172 struct ccb_trans_settings cts;
2175 _ata_announce_periph(periph, &cts, &speed);
2176 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2181 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2182 periph->periph_name, periph->unit_number,
2185 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2186 periph->unit_number, speed);
2187 /* Report additional information about connection */
2188 if (cts.transport == XPORT_ATA) {
2189 struct ccb_trans_settings_pata *pata =
2190 &cts.xport_specific.ata;
2192 sbuf_printf(sb, " (");
2193 if (pata->valid & CTS_ATA_VALID_MODE)
2194 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2195 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2196 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2197 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2198 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2199 sbuf_printf(sb, ")");
2201 if (cts.transport == XPORT_SATA) {
2202 struct ccb_trans_settings_sata *sata =
2203 &cts.xport_specific.sata;
2205 sbuf_printf(sb, " (");
2206 if (sata->valid & CTS_SATA_VALID_REVISION)
2207 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2209 sbuf_printf(sb, "SATA, ");
2210 if (sata->valid & CTS_SATA_VALID_MODE)
2211 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2212 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2213 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2214 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2215 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2216 sbuf_printf(sb, ")");
2218 sbuf_printf(sb, "\n");
2222 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2224 ata_print_ident_sbuf(&device->ident_data, sb);
2228 ata_proto_announce(struct cam_ed *device)
2230 ata_print_ident(&device->ident_data);
2234 ata_proto_denounce(struct cam_ed *device)
2236 ata_print_ident_short(&device->ident_data);
2240 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2242 ata_print_ident_short_sbuf(&device->ident_data, sb);
2246 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2248 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2252 semb_proto_announce(struct cam_ed *device)
2254 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2258 semb_proto_denounce(struct cam_ed *device)
2260 semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
2264 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2266 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2270 ata_proto_debug_out(union ccb *ccb)
2272 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2274 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2277 CAM_DEBUG(ccb->ccb_h.path,
2278 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2279 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));