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>
44 #include <sys/eventhandler.h>
46 #include <sys/mutex.h>
47 #include <sys/sysctl.h>
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_queue.h>
52 #include <cam/cam_periph.h>
53 #include <cam/cam_sim.h>
54 #include <cam/cam_xpt.h>
55 #include <cam/cam_xpt_sim.h>
56 #include <cam/cam_xpt_periph.h>
57 #include <cam/cam_xpt_internal.h>
58 #include <cam/cam_debug.h>
60 #include <cam/scsi/scsi_all.h>
61 #include <cam/scsi/scsi_message.h>
62 #include <cam/ata/ata_all.h>
63 #include <machine/stdarg.h> /* for xpt_print below */
66 struct ata_quirk_entry {
67 struct scsi_inquiry_pattern inq_pat;
69 #define CAM_QUIRK_MAXTAGS 0x01
74 static periph_init_t probe_periph_init;
76 static struct periph_driver probe_driver =
78 probe_periph_init, "aprobe",
79 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
83 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
100 PROBE_IDENTIFY_SAFTE,
105 static char *probe_action_text[] = {
116 "PROBE_FULL_INQUIRY",
119 "PROBE_IDENTIFY_SES",
120 "PROBE_IDENTIFY_SAFTE",
125 #define PROBE_SET_ACTION(softc, newaction) \
128 text = probe_action_text; \
129 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
130 ("Probe %s to %s\n", text[(softc)->action], \
131 text[(newaction)])); \
132 (softc)->action = (newaction); \
136 PROBE_NO_ANNOUNCE = 0x04
140 TAILQ_HEAD(, ccb_hdr) request_ccbs;
141 struct ata_params ident_data;
150 struct cam_periph *periph;
153 static struct ata_quirk_entry ata_quirk_table[] =
156 /* Default tagged queuing parameters for all devices */
158 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
159 /*vendor*/"*", /*product*/"*", /*revision*/"*"
161 /*quirks*/0, /*mintags*/0, /*maxtags*/0
165 static cam_status proberegister(struct cam_periph *periph,
167 static void probeschedule(struct cam_periph *probe_periph);
168 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
169 static void proberequestdefaultnegotiation(struct cam_periph *periph);
170 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
171 static void probecleanup(struct cam_periph *periph);
172 static void ata_find_quirk(struct cam_ed *device);
173 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
174 static void ata_scan_lun(struct cam_periph *periph,
175 struct cam_path *path, cam_flags flags,
177 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
178 static struct cam_ed *
179 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
181 static void ata_device_transport(struct cam_path *path);
182 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
183 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
184 struct cam_path *path,
186 static void ata_dev_async(u_int32_t async_code,
188 struct cam_et *target,
189 struct cam_ed *device,
191 static void ata_action(union ccb *start_ccb);
192 static void ata_announce_periph(struct cam_periph *periph);
193 static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
194 static void ata_proto_announce(struct cam_ed *device);
195 static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
196 static void ata_proto_denounce(struct cam_ed *device);
197 static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
198 static void ata_proto_debug_out(union ccb *ccb);
199 static void semb_proto_announce(struct cam_ed *device);
200 static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
201 static void semb_proto_denounce(struct cam_ed *device);
202 static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
204 static int ata_dma = 1;
205 static int atapi_dma = 1;
207 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
208 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
210 static struct xpt_xport_ops ata_xport_ops = {
211 .alloc_device = ata_alloc_device,
212 .action = ata_action,
213 .async = ata_dev_async,
214 .announce = ata_announce_periph,
215 .announce_sbuf = ata_announce_periph_sbuf,
217 #define ATA_XPT_XPORT(x, X) \
218 static struct xpt_xport ata_xport_ ## x = { \
219 .xport = XPORT_ ## X, \
221 .ops = &ata_xport_ops, \
223 CAM_XPT_XPORT(ata_xport_ ## x);
225 ATA_XPT_XPORT(ata, ATA);
226 ATA_XPT_XPORT(sata, SATA);
228 #undef ATA_XPORT_XPORT
230 static struct xpt_proto_ops ata_proto_ops_ata = {
231 .announce = ata_proto_announce,
232 .announce_sbuf = ata_proto_announce_sbuf,
233 .denounce = ata_proto_denounce,
234 .denounce_sbuf = ata_proto_denounce_sbuf,
235 .debug_out = ata_proto_debug_out,
237 static struct xpt_proto ata_proto_ata = {
240 .ops = &ata_proto_ops_ata,
243 static struct xpt_proto_ops ata_proto_ops_satapm = {
244 .announce = ata_proto_announce,
245 .announce_sbuf = ata_proto_announce_sbuf,
246 .denounce = ata_proto_denounce,
247 .denounce_sbuf = ata_proto_denounce_sbuf,
248 .debug_out = ata_proto_debug_out,
250 static struct xpt_proto ata_proto_satapm = {
251 .proto = PROTO_SATAPM,
253 .ops = &ata_proto_ops_satapm,
256 static struct xpt_proto_ops ata_proto_ops_semb = {
257 .announce = semb_proto_announce,
258 .announce_sbuf = semb_proto_announce_sbuf,
259 .denounce = semb_proto_denounce,
260 .denounce_sbuf = semb_proto_denounce_sbuf,
261 .debug_out = ata_proto_debug_out,
263 static struct xpt_proto ata_proto_semb = {
266 .ops = &ata_proto_ops_semb,
269 CAM_XPT_PROTO(ata_proto_ata);
270 CAM_XPT_PROTO(ata_proto_satapm);
271 CAM_XPT_PROTO(ata_proto_semb);
279 proberegister(struct cam_periph *periph, void *arg)
281 union ccb *request_ccb; /* CCB representing the probe request */
284 request_ccb = (union ccb *)arg;
285 if (request_ccb == NULL) {
286 printf("proberegister: no probe CCB, "
287 "can't register device\n");
288 return(CAM_REQ_CMP_ERR);
291 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
294 printf("proberegister: Unable to probe new device. "
295 "Unable to allocate softc\n");
296 return(CAM_REQ_CMP_ERR);
298 TAILQ_INIT(&softc->request_ccbs);
299 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
302 periph->softc = softc;
303 softc->periph = periph;
304 softc->action = PROBE_INVALID;
305 if (cam_periph_acquire(periph) != 0)
306 return (CAM_REQ_CMP_ERR);
308 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
309 ata_device_transport(periph->path);
310 probeschedule(periph);
315 probeschedule(struct cam_periph *periph)
320 softc = (probe_softc *)periph->softc;
321 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
323 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
324 periph->path->device->protocol == PROTO_SATAPM ||
325 periph->path->device->protocol == PROTO_SEMB)
326 PROBE_SET_ACTION(softc, PROBE_RESET);
328 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
330 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
331 softc->flags |= PROBE_NO_ANNOUNCE;
333 softc->flags &= ~PROBE_NO_ANNOUNCE;
335 xpt_schedule(periph, CAM_PRIORITY_XPT);
339 probestart(struct cam_periph *periph, union ccb *start_ccb)
341 struct ccb_trans_settings cts;
342 struct ccb_ataio *ataio;
343 struct ccb_scsiio *csio;
345 struct cam_path *path;
346 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 (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 (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.sata.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. */
463 oif = path->device->inq_flags;
465 path->device->inq_flags &= ~SID_DMA;
467 path->device->inq_flags |= SID_DMA;
468 if (path->device->inq_flags != oif)
469 xpt_async(AC_GETDEV_CHANGED, path, NULL);
470 cam_fill_ataio(ataio,
473 /*flags*/CAM_DIR_NONE,
478 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
482 cam_fill_ataio(ataio,
490 ata_28bit_cmd(ataio, ATA_SETFEATURES,
491 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
495 cam_fill_ataio(ataio,
503 ata_28bit_cmd(ataio, ATA_SETFEATURES,
504 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
508 cam_fill_ataio(ataio,
516 ata_28bit_cmd(ataio, ATA_SETFEATURES,
517 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
521 /* Remember what transport thinks about AEN. */
522 oif = path->device->inq_flags;
523 if (softc->caps & CTS_SATA_CAPS_H_AN)
524 path->device->inq_flags |= SID_AEN;
526 path->device->inq_flags &= ~SID_AEN;
527 if (path->device->inq_flags != oif)
528 xpt_async(AC_GETDEV_CHANGED, path, NULL);
529 cam_fill_ataio(ataio,
537 ata_28bit_cmd(ataio, ATA_SETFEATURES,
538 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
541 case PROBE_SET_MULTI:
543 u_int sectors, bytecount;
545 bytecount = 8192; /* SATA maximum */
546 /* Fetch user bytecount from SIM. */
547 bzero(&cts, sizeof(cts));
548 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
549 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
550 cts.type = CTS_TYPE_USER_SETTINGS;
551 xpt_action((union ccb *)&cts);
552 if (path->device->transport == XPORT_ATA) {
553 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
554 bytecount = cts.xport_specific.ata.bytecount;
556 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
557 bytecount = cts.xport_specific.sata.bytecount;
559 /* Honor device capabilities. */
560 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
561 bytecount / ata_logical_sector_size(ident_buf)));
562 /* Report bytecount to SIM. */
563 bzero(&cts, sizeof(cts));
564 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
565 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
566 cts.type = CTS_TYPE_CURRENT_SETTINGS;
567 if (path->device->transport == XPORT_ATA) {
568 cts.xport_specific.ata.bytecount = sectors *
569 ata_logical_sector_size(ident_buf);
570 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
572 cts.xport_specific.sata.bytecount = sectors *
573 ata_logical_sector_size(ident_buf);
574 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
576 xpt_action((union ccb *)&cts);
577 /* Fetch current bytecount from SIM. */
578 bzero(&cts, sizeof(cts));
579 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
580 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
581 cts.type = CTS_TYPE_CURRENT_SETTINGS;
582 xpt_action((union ccb *)&cts);
583 if (path->device->transport == XPORT_ATA) {
584 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
585 bytecount = cts.xport_specific.ata.bytecount;
587 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
588 bytecount = cts.xport_specific.sata.bytecount;
590 sectors = bytecount / ata_logical_sector_size(ident_buf);
592 cam_fill_ataio(ataio,
600 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
607 bytecount = 8192; /* SATA maximum */
608 /* Fetch user bytecount from SIM. */
609 bzero(&cts, sizeof(cts));
610 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
611 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
612 cts.type = CTS_TYPE_USER_SETTINGS;
613 xpt_action((union ccb *)&cts);
614 if (path->device->transport == XPORT_ATA) {
615 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
616 bytecount = cts.xport_specific.ata.bytecount;
618 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
619 bytecount = cts.xport_specific.sata.bytecount;
621 /* Honor device capabilities. */
623 bytecount = max(2, min(65534, bytecount));
624 if (ident_buf->satacapabilities != 0x0000 &&
625 ident_buf->satacapabilities != 0xffff) {
626 bytecount = min(8192, bytecount);
628 /* Report bytecount to SIM. */
629 bzero(&cts, sizeof(cts));
630 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
631 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
632 cts.type = CTS_TYPE_CURRENT_SETTINGS;
633 if (path->device->transport == XPORT_ATA) {
634 cts.xport_specific.ata.bytecount = bytecount;
635 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
637 cts.xport_specific.sata.bytecount = bytecount;
638 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
640 xpt_action((union ccb *)&cts);
643 case PROBE_FULL_INQUIRY:
646 struct scsi_inquiry_data *inq_buf =
647 &path->device->inq_data;
649 if (softc->action == PROBE_INQUIRY)
650 inquiry_len = SHORT_INQUIRY_LENGTH;
652 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
654 * Some parallel SCSI devices fail to send an
655 * ignore wide residue message when dealing with
656 * odd length inquiry requests. Round up to be
659 inquiry_len = roundup2(inquiry_len, 2);
669 /*timeout*/60 * 1000);
673 cam_fill_ataio(ataio,
676 /*flags*/CAM_DIR_NONE,
681 ata_pm_read_cmd(ataio, 0, 15);
684 cam_fill_ataio(ataio,
687 /*flags*/CAM_DIR_NONE,
692 ata_pm_read_cmd(ataio, 1, 15);
694 case PROBE_IDENTIFY_SES:
695 cam_fill_ataio(ataio,
700 /*data_ptr*/(u_int8_t *)&softc->ident_data,
701 /*dxfer_len*/sizeof(softc->ident_data),
703 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
704 sizeof(softc->ident_data) / 4);
706 case PROBE_IDENTIFY_SAFTE:
707 cam_fill_ataio(ataio,
712 /*data_ptr*/(u_int8_t *)&softc->ident_data,
713 /*dxfer_len*/sizeof(softc->ident_data),
715 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
716 sizeof(softc->ident_data) / 4);
719 panic("probestart: invalid action state 0x%x\n", softc->action);
721 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
722 xpt_action(start_ccb);
726 proberequestdefaultnegotiation(struct cam_periph *periph)
728 struct ccb_trans_settings cts;
730 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
731 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
732 cts.type = CTS_TYPE_USER_SETTINGS;
733 xpt_action((union ccb *)&cts);
734 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
736 cts.xport_specific.valid = 0;
737 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
738 cts.type = CTS_TYPE_CURRENT_SETTINGS;
739 xpt_action((union ccb *)&cts);
743 probedone(struct cam_periph *periph, union ccb *done_ccb)
745 struct ccb_trans_settings cts;
746 struct ata_params *ident_buf;
747 struct scsi_inquiry_data *inq_buf;
749 struct cam_path *path;
753 int changed, found = 1;
754 static const uint8_t fake_device_id_hdr[8] =
755 {0, SVPD_DEVICE_ID, 0, 12,
756 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
758 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
760 softc = (probe_softc *)periph->softc;
761 path = done_ccb->ccb_h.path;
762 priority = done_ccb->ccb_h.pinfo.priority;
763 ident_buf = &path->device->ident_data;
764 inq_buf = &path->device->inq_data;
766 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
767 if (cam_periph_error(done_ccb,
768 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
771 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
772 cam_release_devq(path, 0, 0, 0, FALSE);
775 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
776 /* Don't wedge the queue */
777 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
779 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
780 if (softc->restart) {
782 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
785 if (softc->faults < 10)
790 /* Old PIO2 devices may not support mode setting. */
791 } else if (softc->action == PROBE_SETMODE &&
792 status == CAM_ATA_STATUS_ERROR &&
793 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
794 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
798 * Some old WD SATA disks report supported and enabled
799 * device-initiated interface power management, but return
800 * ABORT on attempt to disable it.
802 } else if (softc->action == PROBE_SETPM &&
803 status == CAM_ATA_STATUS_ERROR) {
807 * Some old WD SATA disks have broken SPINUP handling.
808 * If we really fail to spin up the disk, then there will be
809 * some media access errors later on, but at least we will
810 * have a device to interact with for recovery attempts.
812 } else if (softc->action == PROBE_SPINUP &&
813 status == CAM_ATA_STATUS_ERROR) {
817 * Some HP SATA disks report supported DMA Auto-Activation,
818 * but return ABORT on attempt to enable it.
820 } else if (softc->action == PROBE_SETDMAAA &&
821 status == CAM_ATA_STATUS_ERROR) {
825 * SES and SAF-TE SEPs have different IDENTIFY commands,
826 * but SATA specification doesn't tell how to identify them.
827 * Until better way found, just try another if first fail.
829 } else if (softc->action == PROBE_IDENTIFY_SES &&
830 status == CAM_ATA_STATUS_ERROR) {
831 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
832 xpt_release_ccb(done_ccb);
833 xpt_schedule(periph, priority);
838 * If we get to this point, we got an error status back
839 * from the inquiry and the error status doesn't require
840 * automatically retrying the command. Therefore, the
841 * inquiry failed. If we had inquiry information before
842 * for this device, but this latest inquiry command failed,
843 * the device has probably gone away. If this device isn't
844 * already marked unconfigured, notify the peripheral
845 * drivers that this device is no more.
847 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
848 xpt_async(AC_LOST_DEVICE, path, NULL);
849 PROBE_SET_ACTION(softc, PROBE_INVALID);
856 switch (softc->action) {
859 int sign = (done_ccb->ataio.res.lba_high << 8) +
860 done_ccb->ataio.res.lba_mid;
861 CAM_DEBUG(path, CAM_DEBUG_PROBE,
862 ("SIGNATURE: %04x\n", sign));
863 if (sign == 0x0000 &&
864 done_ccb->ccb_h.target_id != 15) {
865 path->device->protocol = PROTO_ATA;
866 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
867 } else if (sign == 0x9669 &&
868 done_ccb->ccb_h.target_id == 15) {
869 /* Report SIM that PM is present. */
870 bzero(&cts, sizeof(cts));
871 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
872 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
873 cts.type = CTS_TYPE_CURRENT_SETTINGS;
874 cts.xport_specific.sata.pm_present = 1;
875 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
876 xpt_action((union ccb *)&cts);
877 path->device->protocol = PROTO_SATAPM;
878 PROBE_SET_ACTION(softc, PROBE_PM_PID);
879 } else if (sign == 0xc33c &&
880 done_ccb->ccb_h.target_id != 15) {
881 path->device->protocol = PROTO_SEMB;
882 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
883 } else if (sign == 0xeb14 &&
884 done_ccb->ccb_h.target_id != 15) {
885 path->device->protocol = PROTO_SCSI;
886 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
888 if (done_ccb->ccb_h.target_id != 15) {
890 "Unexpected signature 0x%04x\n", sign);
894 xpt_release_ccb(done_ccb);
895 xpt_schedule(periph, priority);
900 struct ccb_pathinq cpi;
904 * Convert to host byte order, and fix the strings.
906 ident_buf = &softc->ident_data;
907 ata_param_fixup(ident_buf);
910 * Allow others to veto this ATA disk attachment. This
911 * is mainly used by VMs, whose disk controllers may
912 * share the disks with the simulated ATA controllers.
914 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
919 /* Device may need spin-up before IDENTIFY become valid. */
920 if ((ident_buf->specconf == 0x37c8 ||
921 ident_buf->specconf == 0x738c) &&
922 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
923 softc->spinup == 0)) {
924 PROBE_SET_ACTION(softc, PROBE_SPINUP);
925 xpt_release_ccb(done_ccb);
926 xpt_schedule(periph, priority);
929 ident_buf = &path->device->ident_data;
931 /* Check that it is the same device as we know. */
932 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
933 if (bcmp(softc->ident_data.model, ident_buf->model,
934 sizeof(ident_buf->model)) ||
935 bcmp(softc->ident_data.serial, ident_buf->serial,
936 sizeof(ident_buf->serial))) {
937 /* The device was replaced. */
939 xpt_async(AC_LOST_DEVICE, path, NULL);
940 } else if (bcmp(&softc->ident_data, ident_buf,
941 sizeof(*ident_buf))) {
942 /* The device is the same, but has changed. */
945 /* Nothing has changed. */
949 /* This is a new device. */
954 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
956 /* Clean up from previous instance of this device */
957 if (path->device->serial_num != NULL) {
958 free(path->device->serial_num, M_CAMXPT);
959 path->device->serial_num = NULL;
960 path->device->serial_num_len = 0;
962 if (path->device->device_id != NULL) {
963 free(path->device->device_id, M_CAMXPT);
964 path->device->device_id = NULL;
965 path->device->device_id_len = 0;
967 path->device->serial_num =
968 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
970 if (path->device->serial_num != NULL) {
971 bcopy(ident_buf->serial,
972 path->device->serial_num,
973 sizeof(ident_buf->serial));
974 path->device->serial_num[sizeof(ident_buf->serial)]
976 path->device->serial_num_len =
977 strlen(path->device->serial_num);
979 if (ident_buf->enabled.extension &
980 ATA_SUPPORT_64BITWWN) {
981 path->device->device_id =
982 malloc(16, M_CAMXPT, M_NOWAIT);
983 if (path->device->device_id != NULL) {
984 path->device->device_id_len = 16;
985 bcopy(&fake_device_id_hdr,
986 path->device->device_id, 8);
987 bcopy(ident_buf->wwn,
988 path->device->device_id + 8, 8);
989 ata_bswap(path->device->device_id + 8, 8);
992 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
995 xpt_async(AC_GETDEV_CHANGED, path, NULL);
996 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
997 path->device->mintags = 2;
998 path->device->maxtags =
999 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1001 ata_find_quirk(path->device);
1002 if (path->device->mintags != 0 &&
1003 path->bus->sim->max_tagged_dev_openings != 0) {
1004 /* Check if the SIM does not want queued commands. */
1005 xpt_path_inq(&cpi, path);
1006 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1007 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1008 /* Report SIM which tags are allowed. */
1009 bzero(&cts, sizeof(cts));
1010 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1011 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1012 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1013 cts.xport_specific.sata.tags = path->device->maxtags;
1014 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1015 xpt_action((union ccb *)&cts);
1018 ata_device_transport(path);
1020 proberequestdefaultnegotiation(periph);
1021 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1022 xpt_release_ccb(done_ccb);
1023 xpt_schedule(periph, priority);
1028 xpt_print(path, "Spin-up done\n");
1030 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1031 xpt_release_ccb(done_ccb);
1032 xpt_schedule(periph, priority);
1035 /* Set supported bits. */
1036 bzero(&cts, sizeof(cts));
1037 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1038 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1039 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1040 xpt_action((union ccb *)&cts);
1041 if (path->device->transport == XPORT_SATA &&
1042 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1043 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1044 else if (path->device->transport == XPORT_ATA &&
1045 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1046 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1049 if (path->device->transport == XPORT_SATA &&
1050 ident_buf->satacapabilities != 0xffff) {
1051 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1052 caps |= CTS_SATA_CAPS_D_PMREQ;
1053 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1054 caps |= CTS_SATA_CAPS_D_APST;
1056 /* Mask unwanted bits. */
1057 bzero(&cts, sizeof(cts));
1058 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1059 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1060 cts.type = CTS_TYPE_USER_SETTINGS;
1061 xpt_action((union ccb *)&cts);
1062 if (path->device->transport == XPORT_SATA &&
1063 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1064 caps &= cts.xport_specific.sata.caps;
1065 else if (path->device->transport == XPORT_ATA &&
1066 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1067 caps &= cts.xport_specific.ata.caps;
1071 * Remember what transport thinks about 48-bit DMA. If
1072 * capability information is not provided or transport is
1073 * SATA, we take support for granted.
1075 oif = path->device->inq_flags;
1076 if (!(path->device->inq_flags & SID_DMA) ||
1077 (path->device->transport == XPORT_ATA &&
1078 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1079 !(caps & CTS_ATA_CAPS_H_DMA48)))
1080 path->device->inq_flags &= ~SID_DMA48;
1082 path->device->inq_flags |= SID_DMA48;
1083 if (path->device->inq_flags != oif)
1084 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1085 /* Store result to SIM. */
1086 bzero(&cts, sizeof(cts));
1087 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1088 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1089 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1090 if (path->device->transport == XPORT_SATA) {
1091 cts.xport_specific.sata.caps = caps;
1092 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1094 cts.xport_specific.ata.caps = caps;
1095 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1097 xpt_action((union ccb *)&cts);
1099 if (path->device->transport != XPORT_SATA)
1101 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1102 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1103 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1104 PROBE_SET_ACTION(softc, PROBE_SETPM);
1105 xpt_release_ccb(done_ccb);
1106 xpt_schedule(periph, priority);
1111 if (ident_buf->satacapabilities != 0xffff &&
1112 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1113 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1114 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1115 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1116 xpt_release_ccb(done_ccb);
1117 xpt_schedule(periph, priority);
1122 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1123 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1124 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1125 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1126 xpt_release_ccb(done_ccb);
1127 xpt_schedule(periph, priority);
1131 case PROBE_SETDMAAA:
1132 if (path->device->protocol != PROTO_ATA &&
1133 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1134 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1135 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1136 PROBE_SET_ACTION(softc, PROBE_SETAN);
1137 xpt_release_ccb(done_ccb);
1138 xpt_schedule(periph, priority);
1144 if (path->device->protocol == PROTO_ATA) {
1145 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1147 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1149 xpt_release_ccb(done_ccb);
1150 xpt_schedule(periph, priority);
1152 case PROBE_SET_MULTI:
1153 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1154 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1155 xpt_acquire_device(path->device);
1156 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1157 xpt_action(done_ccb);
1158 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1160 PROBE_SET_ACTION(softc, PROBE_DONE);
1163 case PROBE_FULL_INQUIRY:
1165 u_int8_t periph_qual, len;
1167 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1169 periph_qual = SID_QUAL(inq_buf);
1171 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1172 periph_qual != SID_QUAL_LU_OFFLINE)
1176 * We conservatively request only
1177 * SHORT_INQUIRY_LEN bytes of inquiry
1178 * information during our first try
1179 * at sending an INQUIRY. If the device
1180 * has more information to give,
1181 * perform a second request specifying
1182 * the amount of information the device
1183 * is willing to give.
1185 len = inq_buf->additional_length
1186 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1187 if (softc->action == PROBE_INQUIRY
1188 && len > SHORT_INQUIRY_LENGTH) {
1189 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1190 xpt_release_ccb(done_ccb);
1191 xpt_schedule(periph, priority);
1195 ata_device_transport(path);
1196 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1197 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1198 xpt_acquire_device(path->device);
1199 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1200 xpt_action(done_ccb);
1201 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1203 PROBE_SET_ACTION(softc, PROBE_DONE);
1207 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1208 bzero(ident_buf, sizeof(*ident_buf));
1209 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1210 (done_ccb->ataio.res.lba_mid << 16) +
1211 (done_ccb->ataio.res.lba_low << 8) +
1212 done_ccb->ataio.res.sector_count;
1213 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1214 snprintf(ident_buf->model, sizeof(ident_buf->model),
1215 "Port Multiplier %08x", softc->pm_pid);
1216 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1217 xpt_release_ccb(done_ccb);
1218 xpt_schedule(periph, priority);
1221 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1222 (done_ccb->ataio.res.lba_mid << 16) +
1223 (done_ccb->ataio.res.lba_low << 8) +
1224 done_ccb->ataio.res.sector_count;
1225 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1226 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1227 "%04x", softc->pm_prv);
1228 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1229 ata_device_transport(path);
1230 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1231 proberequestdefaultnegotiation(periph);
1232 /* Set supported bits. */
1233 bzero(&cts, sizeof(cts));
1234 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1235 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1236 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1237 xpt_action((union ccb *)&cts);
1238 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1239 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1242 /* All PMPs must support PM requests. */
1243 caps |= CTS_SATA_CAPS_D_PMREQ;
1244 /* Mask unwanted bits. */
1245 bzero(&cts, sizeof(cts));
1246 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1247 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1248 cts.type = CTS_TYPE_USER_SETTINGS;
1249 xpt_action((union ccb *)&cts);
1250 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1251 caps &= cts.xport_specific.sata.caps;
1254 /* Remember what transport thinks about AEN. */
1255 oif = path->device->inq_flags;
1256 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1257 path->device->inq_flags |= SID_AEN;
1259 path->device->inq_flags &= ~SID_AEN;
1260 /* Store result to SIM. */
1261 bzero(&cts, sizeof(cts));
1262 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1263 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1264 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1265 cts.xport_specific.sata.caps = caps;
1266 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1267 xpt_action((union ccb *)&cts);
1269 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1270 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1271 xpt_acquire_device(path->device);
1272 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1273 xpt_action(done_ccb);
1274 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1276 if (path->device->inq_flags != oif)
1277 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1278 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1279 xpt_action(done_ccb);
1280 xpt_async(AC_SCSI_AEN, path, done_ccb);
1282 PROBE_SET_ACTION(softc, PROBE_DONE);
1284 case PROBE_IDENTIFY_SES:
1285 case PROBE_IDENTIFY_SAFTE:
1286 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1287 /* Check that it is the same device. */
1288 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1289 /* Device changed. */
1291 xpt_async(AC_LOST_DEVICE, path, NULL);
1293 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1299 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1300 /* Clean up from previous instance of this device */
1301 if (path->device->device_id != NULL) {
1302 free(path->device->device_id, M_CAMXPT);
1303 path->device->device_id = NULL;
1304 path->device->device_id_len = 0;
1306 path->device->device_id =
1307 malloc(16, M_CAMXPT, M_NOWAIT);
1308 if (path->device->device_id != NULL) {
1309 path->device->device_id_len = 16;
1310 bcopy(&fake_device_id_hdr,
1311 path->device->device_id, 8);
1312 bcopy(((uint8_t*)ident_buf) + 2,
1313 path->device->device_id + 8, 8);
1316 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1318 ata_device_transport(path);
1320 proberequestdefaultnegotiation(periph);
1322 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1323 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1324 xpt_acquire_device(path->device);
1325 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1326 xpt_action(done_ccb);
1327 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1329 PROBE_SET_ACTION(softc, PROBE_DONE);
1332 panic("probedone: invalid action state 0x%x\n", softc->action);
1335 if (softc->restart) {
1337 xpt_release_ccb(done_ccb);
1338 probeschedule(periph);
1341 xpt_release_ccb(done_ccb);
1342 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1343 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1344 TAILQ_REMOVE(&softc->request_ccbs,
1345 &done_ccb->ccb_h, periph_links.tqe);
1346 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1349 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1350 cam_release_devq(path, 0, 0, 0, FALSE);
1351 cam_periph_invalidate(periph);
1352 cam_periph_release_locked(periph);
1356 probecleanup(struct cam_periph *periph)
1358 free(periph->softc, M_CAMXPT);
1362 ata_find_quirk(struct cam_ed *device)
1364 struct ata_quirk_entry *quirk;
1367 match = cam_quirkmatch((caddr_t)&device->ident_data,
1368 (caddr_t)ata_quirk_table,
1369 nitems(ata_quirk_table),
1370 sizeof(*ata_quirk_table), ata_identify_match);
1373 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1375 quirk = (struct ata_quirk_entry *)match;
1376 device->quirk = quirk;
1377 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1378 device->mintags = quirk->mintags;
1379 device->maxtags = quirk->maxtags;
1384 union ccb *request_ccb;
1385 struct ccb_pathinq *cpi;
1387 } ata_scan_bus_info;
1390 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1391 * As the scan progresses, xpt_scan_bus is used as the
1392 * callback on completion function.
1395 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1397 struct cam_path *path;
1398 ata_scan_bus_info *scan_info;
1399 union ccb *work_ccb, *reset_ccb;
1403 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1404 ("xpt_scan_bus\n"));
1405 switch (request_ccb->ccb_h.func_code) {
1408 /* Find out the characteristics of the bus */
1409 work_ccb = xpt_alloc_ccb_nowait();
1410 if (work_ccb == NULL) {
1411 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1412 xpt_done(request_ccb);
1415 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1416 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1417 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1418 xpt_free_ccb(work_ccb);
1419 xpt_done(request_ccb);
1423 /* We may need to reset bus first, if we haven't done it yet. */
1424 if ((work_ccb->cpi.hba_inquiry &
1425 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1426 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1427 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1428 reset_ccb = xpt_alloc_ccb_nowait();
1429 if (reset_ccb == NULL) {
1430 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1431 xpt_free_ccb(work_ccb);
1432 xpt_done(request_ccb);
1435 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1437 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1438 xpt_action(reset_ccb);
1439 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1440 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1441 xpt_free_ccb(reset_ccb);
1442 xpt_free_ccb(work_ccb);
1443 xpt_done(request_ccb);
1446 xpt_free_ccb(reset_ccb);
1449 /* Save some state for use while we probe for devices */
1450 scan_info = (ata_scan_bus_info *)
1451 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1452 if (scan_info == NULL) {
1453 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1454 xpt_free_ccb(work_ccb);
1455 xpt_done(request_ccb);
1458 scan_info->request_ccb = request_ccb;
1459 scan_info->cpi = &work_ccb->cpi;
1460 /* If PM supported, probe it first. */
1461 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1462 scan_info->counter = scan_info->cpi->max_target;
1464 scan_info->counter = 0;
1466 work_ccb = xpt_alloc_ccb_nowait();
1467 if (work_ccb == NULL) {
1468 free(scan_info, M_CAMXPT);
1469 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1470 xpt_done(request_ccb);
1473 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1476 work_ccb = request_ccb;
1477 /* Reuse the same CCB to query if a device was really found */
1478 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1479 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1481 /* If there is PMP... */
1482 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1483 (scan_info->counter == scan_info->cpi->max_target)) {
1484 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1485 /* everything else will be probed by it */
1486 /* Free the current request path- we're done with it. */
1487 xpt_free_path(work_ccb->ccb_h.path);
1490 struct ccb_trans_settings cts;
1492 /* Report SIM that PM is absent. */
1493 bzero(&cts, sizeof(cts));
1494 xpt_setup_ccb(&cts.ccb_h,
1495 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1496 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1497 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1498 cts.xport_specific.sata.pm_present = 0;
1499 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1500 xpt_action((union ccb *)&cts);
1503 /* Free the current request path- we're done with it. */
1504 xpt_free_path(work_ccb->ccb_h.path);
1505 if (scan_info->counter ==
1506 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1507 0 : scan_info->cpi->max_target)) {
1510 xpt_free_ccb(work_ccb);
1511 xpt_free_ccb((union ccb *)scan_info->cpi);
1512 request_ccb = scan_info->request_ccb;
1513 free(scan_info, M_CAMXPT);
1514 request_ccb->ccb_h.status = CAM_REQ_CMP;
1515 xpt_done(request_ccb);
1518 /* Take next device. Wrap from max (PMP) to 0. */
1519 scan_info->counter = (scan_info->counter + 1 ) %
1520 (scan_info->cpi->max_target + 1);
1522 status = xpt_create_path(&path, NULL,
1523 scan_info->request_ccb->ccb_h.path_id,
1524 scan_info->counter, 0);
1525 if (status != CAM_REQ_CMP) {
1526 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1528 printf("xpt_scan_bus: xpt_create_path failed"
1529 " with status %#x, bus scan halted\n",
1531 xpt_free_ccb(work_ccb);
1532 xpt_free_ccb((union ccb *)scan_info->cpi);
1533 request_ccb = scan_info->request_ccb;
1534 free(scan_info, M_CAMXPT);
1535 request_ccb->ccb_h.status = status;
1536 xpt_done(request_ccb);
1539 xpt_setup_ccb(&work_ccb->ccb_h, path,
1540 scan_info->request_ccb->ccb_h.pinfo.priority);
1541 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1542 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1543 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1544 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1545 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1547 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1549 xpt_action(work_ccb);
1559 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1560 cam_flags flags, union ccb *request_ccb)
1562 struct ccb_pathinq cpi;
1564 struct cam_path *new_path;
1565 struct cam_periph *old_periph;
1568 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1570 xpt_path_inq(&cpi, path);
1571 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1572 if (request_ccb != NULL) {
1573 request_ccb->ccb_h.status = cpi.ccb_h.status;
1574 xpt_done(request_ccb);
1579 if (request_ccb == NULL) {
1580 request_ccb = xpt_alloc_ccb_nowait();
1581 if (request_ccb == NULL) {
1582 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1583 "can't continue\n");
1586 status = xpt_create_path(&new_path, NULL,
1588 path->target->target_id,
1589 path->device->lun_id);
1590 if (status != CAM_REQ_CMP) {
1591 xpt_print(path, "xpt_scan_lun: can't create path, "
1592 "can't continue\n");
1593 xpt_free_ccb(request_ccb);
1596 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1597 request_ccb->ccb_h.cbfcnp = xptscandone;
1598 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1599 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1600 request_ccb->crcn.flags = flags;
1603 lock = (xpt_path_owned(path) == 0);
1605 xpt_path_lock(path);
1606 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1607 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1610 softc = (probe_softc *)old_periph->softc;
1611 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1612 &request_ccb->ccb_h, periph_links.tqe);
1615 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1616 xpt_done(request_ccb);
1619 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1620 probestart, "aprobe",
1622 request_ccb->ccb_h.path, NULL, 0,
1625 if (status != CAM_REQ_CMP) {
1626 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1627 "returned an error, can't continue probe\n");
1628 request_ccb->ccb_h.status = status;
1629 xpt_done(request_ccb);
1633 xpt_path_unlock(path);
1637 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1640 xpt_free_path(done_ccb->ccb_h.path);
1641 xpt_free_ccb(done_ccb);
1644 static struct cam_ed *
1645 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1647 struct ata_quirk_entry *quirk;
1648 struct cam_ed *device;
1650 device = xpt_alloc_device(bus, target, lun_id);
1655 * Take the default quirk entry until we have inquiry
1656 * data and can determine a better quirk to use.
1658 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1659 device->quirk = (void *)quirk;
1660 device->mintags = 0;
1661 device->maxtags = 0;
1662 bzero(&device->inq_data, sizeof(device->inq_data));
1663 device->inq_flags = 0;
1664 device->queue_flags = 0;
1665 device->serial_num = NULL;
1666 device->serial_num_len = 0;
1671 ata_device_transport(struct cam_path *path)
1673 struct ccb_pathinq cpi;
1674 struct ccb_trans_settings cts;
1675 struct scsi_inquiry_data *inq_buf = NULL;
1676 struct ata_params *ident_buf = NULL;
1678 /* Get transport information from the SIM */
1679 xpt_path_inq(&cpi, path);
1681 path->device->transport = cpi.transport;
1682 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1683 inq_buf = &path->device->inq_data;
1684 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1685 ident_buf = &path->device->ident_data;
1686 if (path->device->protocol == PROTO_ATA) {
1687 path->device->protocol_version = ident_buf ?
1688 ata_version(ident_buf->version_major) : cpi.protocol_version;
1689 } else if (path->device->protocol == PROTO_SCSI) {
1690 path->device->protocol_version = inq_buf ?
1691 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1693 path->device->transport_version = ident_buf ?
1694 ata_version(ident_buf->version_major) : cpi.transport_version;
1696 /* Tell the controller what we think */
1697 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1698 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1699 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1700 cts.transport = path->device->transport;
1701 cts.transport_version = path->device->transport_version;
1702 cts.protocol = path->device->protocol;
1703 cts.protocol_version = path->device->protocol_version;
1704 cts.proto_specific.valid = 0;
1706 if (path->device->transport == XPORT_ATA) {
1707 cts.xport_specific.ata.atapi =
1708 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1709 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1710 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1711 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1713 cts.xport_specific.sata.atapi =
1714 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1715 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1716 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1717 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1720 cts.xport_specific.valid = 0;
1721 xpt_action((union ccb *)&cts);
1725 ata_dev_advinfo(union ccb *start_ccb)
1727 struct cam_ed *device;
1728 struct ccb_dev_advinfo *cdai;
1731 xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
1732 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1733 device = start_ccb->ccb_h.path->device;
1734 cdai = &start_ccb->cdai;
1735 switch(cdai->buftype) {
1736 case CDAI_TYPE_SCSI_DEVID:
1737 if (cdai->flags & CDAI_FLAG_STORE)
1739 cdai->provsiz = device->device_id_len;
1740 if (device->device_id_len == 0)
1742 amt = device->device_id_len;
1743 if (cdai->provsiz > cdai->bufsiz)
1745 memcpy(cdai->buf, device->device_id, amt);
1747 case CDAI_TYPE_SERIAL_NUM:
1748 if (cdai->flags & CDAI_FLAG_STORE)
1750 cdai->provsiz = device->serial_num_len;
1751 if (device->serial_num_len == 0)
1753 amt = device->serial_num_len;
1754 if (cdai->provsiz > cdai->bufsiz)
1756 memcpy(cdai->buf, device->serial_num, amt);
1758 case CDAI_TYPE_PHYS_PATH:
1759 if (cdai->flags & CDAI_FLAG_STORE) {
1760 if (device->physpath != NULL)
1761 free(device->physpath, M_CAMXPT);
1762 device->physpath_len = cdai->bufsiz;
1763 /* Clear existing buffer if zero length */
1764 if (cdai->bufsiz == 0)
1766 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1767 if (device->physpath == NULL) {
1768 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1771 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1773 cdai->provsiz = device->physpath_len;
1774 if (device->physpath_len == 0)
1776 amt = device->physpath_len;
1777 if (cdai->provsiz > cdai->bufsiz)
1779 memcpy(cdai->buf, device->physpath, amt);
1785 start_ccb->ccb_h.status = CAM_REQ_CMP;
1787 if (cdai->flags & CDAI_FLAG_STORE) {
1788 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1789 (void *)(uintptr_t)cdai->buftype);
1794 ata_action(union ccb *start_ccb)
1797 switch (start_ccb->ccb_h.func_code) {
1798 case XPT_SET_TRAN_SETTINGS:
1800 ata_set_transfer_settings(&start_ccb->cts,
1801 start_ccb->ccb_h.path,
1802 /*async_update*/FALSE);
1807 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1810 ata_scan_lun(start_ccb->ccb_h.path->periph,
1811 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1814 case XPT_GET_TRAN_SETTINGS:
1816 ata_get_transfer_settings(&start_ccb->cts);
1821 struct cam_ed *device;
1824 device = start_ccb->ccb_h.path->device;
1825 if (device->protocol == PROTO_SCSI &&
1826 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1828 device->ident_data.config & ATA_PROTO_MASK;
1831 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1832 (p == ATA_PROTO_ATAPI_16) ? 16 :
1833 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1835 if (start_ccb->csio.cdb_len > maxlen) {
1836 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1837 xpt_done(start_ccb);
1840 xpt_action_default(start_ccb);
1843 case XPT_DEV_ADVINFO:
1845 ata_dev_advinfo(start_ccb);
1849 xpt_action_default(start_ccb);
1855 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1857 struct ccb_trans_settings_ata *ata;
1858 struct ccb_trans_settings_scsi *scsi;
1859 struct cam_ed *device;
1861 device = cts->ccb_h.path->device;
1862 xpt_action_default((union ccb *)cts);
1864 if (cts->protocol == PROTO_UNKNOWN ||
1865 cts->protocol == PROTO_UNSPECIFIED) {
1866 cts->protocol = device->protocol;
1867 cts->protocol_version = device->protocol_version;
1870 if (cts->protocol == PROTO_ATA) {
1871 ata = &cts->proto_specific.ata;
1872 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1873 ata->valid |= CTS_ATA_VALID_TQ;
1874 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1875 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1876 (device->inq_flags & SID_CmdQue) != 0)
1877 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1880 if (cts->protocol == PROTO_SCSI) {
1881 scsi = &cts->proto_specific.scsi;
1882 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1883 scsi->valid |= CTS_SCSI_VALID_TQ;
1884 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1885 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1886 (device->inq_flags & SID_CmdQue) != 0)
1887 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1891 if (cts->transport == XPORT_UNKNOWN ||
1892 cts->transport == XPORT_UNSPECIFIED) {
1893 cts->transport = device->transport;
1894 cts->transport_version = device->transport_version;
1899 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1902 struct ccb_pathinq cpi;
1903 struct ccb_trans_settings_ata *ata;
1904 struct ccb_trans_settings_scsi *scsi;
1905 struct ata_params *ident_data;
1906 struct scsi_inquiry_data *inq_data;
1907 struct cam_ed *device;
1909 if (path == NULL || (device = path->device) == NULL) {
1910 cts->ccb_h.status = CAM_PATH_INVALID;
1911 xpt_done((union ccb *)cts);
1915 if (cts->protocol == PROTO_UNKNOWN
1916 || cts->protocol == PROTO_UNSPECIFIED) {
1917 cts->protocol = device->protocol;
1918 cts->protocol_version = device->protocol_version;
1921 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1922 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1923 cts->protocol_version = device->protocol_version;
1925 if (cts->protocol != device->protocol) {
1926 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1927 cts->protocol, device->protocol);
1928 cts->protocol = device->protocol;
1931 if (cts->protocol_version > device->protocol_version) {
1933 xpt_print(path, "Down reving Protocol "
1934 "Version from %d to %d?\n", cts->protocol_version,
1935 device->protocol_version);
1937 cts->protocol_version = device->protocol_version;
1940 if (cts->transport == XPORT_UNKNOWN
1941 || cts->transport == XPORT_UNSPECIFIED) {
1942 cts->transport = device->transport;
1943 cts->transport_version = device->transport_version;
1946 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1947 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1948 cts->transport_version = device->transport_version;
1950 if (cts->transport != device->transport) {
1951 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1952 cts->transport, device->transport);
1953 cts->transport = device->transport;
1956 if (cts->transport_version > device->transport_version) {
1958 xpt_print(path, "Down reving Transport "
1959 "Version from %d to %d?\n", cts->transport_version,
1960 device->transport_version);
1962 cts->transport_version = device->transport_version;
1965 ident_data = &device->ident_data;
1966 inq_data = &device->inq_data;
1967 if (cts->protocol == PROTO_ATA)
1968 ata = &cts->proto_specific.ata;
1971 if (cts->protocol == PROTO_SCSI)
1972 scsi = &cts->proto_specific.scsi;
1975 xpt_path_inq(&cpi, path);
1977 /* Sanity checking */
1978 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1979 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1980 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1981 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1982 || (device->mintags == 0)) {
1984 * Can't tag on hardware that doesn't support tags,
1985 * doesn't have it enabled, or has broken tag support.
1988 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1990 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1993 /* Start/stop tags use. */
1994 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1995 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1996 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1999 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
2000 (device->inq_flags & SID_CmdQue) != 0);
2002 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
2004 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2006 if (newt && !nowt) {
2008 * Delay change to use tags until after a
2009 * few commands have gone to this device so
2010 * the controller has time to perform transfer
2011 * negotiations without tagged messages getting
2014 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2015 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2016 } else if (nowt && !newt)
2017 xpt_stop_tags(path);
2020 if (async_update == FALSE)
2021 xpt_action_default((union ccb *)cts);
2025 * Handle any per-device event notifications that require action by the XPT.
2028 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2029 struct cam_ed *device, void *async_arg)
2032 struct cam_path newpath;
2035 * We only need to handle events for real devices.
2037 if (target->target_id == CAM_TARGET_WILDCARD
2038 || device->lun_id == CAM_LUN_WILDCARD)
2042 * We need our own path with wildcards expanded to
2043 * handle certain types of events.
2045 if ((async_code == AC_SENT_BDR)
2046 || (async_code == AC_BUS_RESET)
2047 || (async_code == AC_INQ_CHANGED))
2048 status = xpt_compile_path(&newpath, NULL,
2053 status = CAM_REQ_CMP_ERR;
2055 if (status == CAM_REQ_CMP) {
2056 if (async_code == AC_INQ_CHANGED) {
2058 * We've sent a start unit command, or
2059 * something similar to a device that
2060 * may have caused its inquiry data to
2061 * change. So we re-scan the device to
2062 * refresh the inquiry data for it.
2064 ata_scan_lun(newpath.periph, &newpath,
2065 CAM_EXPECT_INQ_CHANGE, NULL);
2067 /* We need to reinitialize device after reset. */
2068 ata_scan_lun(newpath.periph, &newpath,
2071 xpt_release_path(&newpath);
2072 } else if (async_code == AC_LOST_DEVICE &&
2073 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2074 device->flags |= CAM_DEV_UNCONFIGURED;
2075 xpt_release_device(device);
2076 } else if (async_code == AC_TRANSFER_NEG) {
2077 struct ccb_trans_settings *settings;
2078 struct cam_path path;
2080 settings = (struct ccb_trans_settings *)async_arg;
2081 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2083 ata_set_transfer_settings(settings, &path,
2084 /*async_update*/TRUE);
2085 xpt_release_path(&path);
2090 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2092 struct ccb_pathinq cpi;
2093 struct cam_path *path = periph->path;
2095 cam_periph_assert(periph, MA_OWNED);
2097 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2098 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2099 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2100 xpt_action((union ccb*)cts);
2101 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2103 /* Ask the SIM for its base transfer speed */
2104 xpt_path_inq(&cpi, path);
2105 /* Report connection speed */
2106 *speed = cpi.base_transfer_speed;
2107 if (cts->transport == XPORT_ATA) {
2108 struct ccb_trans_settings_pata *pata =
2109 &cts->xport_specific.ata;
2111 if (pata->valid & CTS_ATA_VALID_MODE)
2112 *speed = ata_mode2speed(pata->mode);
2114 if (cts->transport == XPORT_SATA) {
2115 struct ccb_trans_settings_sata *sata =
2116 &cts->xport_specific.sata;
2118 if (sata->valid & CTS_SATA_VALID_REVISION)
2119 *speed = ata_revision2speed(sata->revision);
2124 ata_announce_periph(struct cam_periph *periph)
2126 struct ccb_trans_settings cts;
2129 _ata_announce_periph(periph, &cts, &speed);
2130 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2135 printf("%s%d: %d.%03dMB/s transfers",
2136 periph->periph_name, periph->unit_number,
2139 printf("%s%d: %dKB/s transfers", periph->periph_name,
2140 periph->unit_number, speed);
2141 /* Report additional information about connection */
2142 if (cts.transport == XPORT_ATA) {
2143 struct ccb_trans_settings_pata *pata =
2144 &cts.xport_specific.ata;
2147 if (pata->valid & CTS_ATA_VALID_MODE)
2148 printf("%s, ", ata_mode2string(pata->mode));
2149 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2150 printf("ATAPI %dbytes, ", pata->atapi);
2151 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2152 printf("PIO %dbytes", pata->bytecount);
2155 if (cts.transport == XPORT_SATA) {
2156 struct ccb_trans_settings_sata *sata =
2157 &cts.xport_specific.sata;
2160 if (sata->valid & CTS_SATA_VALID_REVISION)
2161 printf("SATA %d.x, ", sata->revision);
2164 if (sata->valid & CTS_SATA_VALID_MODE)
2165 printf("%s, ", ata_mode2string(sata->mode));
2166 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2167 printf("ATAPI %dbytes, ", sata->atapi);
2168 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2169 printf("PIO %dbytes", sata->bytecount);
2176 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2178 struct ccb_trans_settings cts;
2181 _ata_announce_periph(periph, &cts, &speed);
2182 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2187 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2188 periph->periph_name, periph->unit_number,
2191 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2192 periph->unit_number, speed);
2193 /* Report additional information about connection */
2194 if (cts.transport == XPORT_ATA) {
2195 struct ccb_trans_settings_pata *pata =
2196 &cts.xport_specific.ata;
2198 sbuf_printf(sb, " (");
2199 if (pata->valid & CTS_ATA_VALID_MODE)
2200 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2201 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2202 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2203 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2204 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2205 sbuf_printf(sb, ")");
2207 if (cts.transport == XPORT_SATA) {
2208 struct ccb_trans_settings_sata *sata =
2209 &cts.xport_specific.sata;
2211 sbuf_printf(sb, " (");
2212 if (sata->valid & CTS_SATA_VALID_REVISION)
2213 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2215 sbuf_printf(sb, "SATA, ");
2216 if (sata->valid & CTS_SATA_VALID_MODE)
2217 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2218 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2219 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2220 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2221 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2222 sbuf_printf(sb, ")");
2224 sbuf_printf(sb, "\n");
2228 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2230 ata_print_ident_sbuf(&device->ident_data, sb);
2234 ata_proto_announce(struct cam_ed *device)
2236 ata_print_ident(&device->ident_data);
2240 ata_proto_denounce(struct cam_ed *device)
2242 ata_print_ident_short(&device->ident_data);
2246 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2248 ata_print_ident_short_sbuf(&device->ident_data, sb);
2252 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2254 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2258 semb_proto_announce(struct cam_ed *device)
2260 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2264 semb_proto_denounce(struct cam_ed *device)
2266 semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
2270 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2272 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2276 ata_proto_debug_out(union ccb *ccb)
2278 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2280 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2283 CAM_DEBUG(ccb->ccb_h.path,
2284 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2285 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));