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;
348 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
350 softc = (probe_softc *)periph->softc;
351 path = start_ccb->ccb_h.path;
352 ataio = &start_ccb->ataio;
353 csio = &start_ccb->csio;
354 ident_buf = &periph->path->device->ident_data;
356 if (softc->restart) {
358 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
359 path->device->protocol == PROTO_SATAPM ||
360 path->device->protocol == PROTO_SEMB)
361 softc->action = PROBE_RESET;
363 softc->action = PROBE_IDENTIFY;
365 switch (softc->action) {
367 cam_fill_ataio(ataio,
370 /*flags*/CAM_DIR_NONE,
375 ata_reset_cmd(ataio);
378 cam_fill_ataio(ataio,
383 /*data_ptr*/(u_int8_t *)&softc->ident_data,
384 /*dxfer_len*/sizeof(softc->ident_data),
386 if (periph->path->device->protocol == PROTO_ATA)
387 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
389 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
393 xpt_print(path, "Spinning up device\n");
394 cam_fill_ataio(ataio,
397 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
402 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
409 /* Fetch user modes from SIM. */
410 bzero(&cts, sizeof(cts));
411 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
412 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
413 cts.type = CTS_TYPE_USER_SETTINGS;
414 xpt_action((union ccb *)&cts);
415 if (path->device->transport == XPORT_ATA) {
416 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
417 mode = cts.xport_specific.ata.mode;
419 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
420 mode = cts.xport_specific.sata.mode;
422 if (periph->path->device->protocol == PROTO_ATA) {
423 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
426 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
430 /* Honor device capabilities. */
431 wantmode = mode = ata_max_mode(ident_buf, mode);
432 /* Report modes to SIM. */
433 bzero(&cts, sizeof(cts));
434 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
435 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
436 cts.type = CTS_TYPE_CURRENT_SETTINGS;
437 if (path->device->transport == XPORT_ATA) {
438 cts.xport_specific.ata.mode = mode;
439 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
441 cts.xport_specific.sata.mode = mode;
442 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
444 xpt_action((union ccb *)&cts);
445 /* Fetch current modes from SIM. */
446 bzero(&cts, sizeof(cts));
447 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
448 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
449 cts.type = CTS_TYPE_CURRENT_SETTINGS;
450 xpt_action((union ccb *)&cts);
451 if (path->device->transport == XPORT_ATA) {
452 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
453 mode = cts.xport_specific.ata.mode;
455 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
456 mode = cts.xport_specific.sata.mode;
458 /* If SIM disagree - renegotiate. */
459 if (mode != wantmode)
461 /* Remember what transport thinks about DMA. */
463 path->device->inq_flags &= ~SID_DMA;
465 path->device->inq_flags |= SID_DMA;
466 xpt_async(AC_GETDEV_CHANGED, path, NULL);
467 cam_fill_ataio(ataio,
470 /*flags*/CAM_DIR_NONE,
475 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
479 cam_fill_ataio(ataio,
487 ata_28bit_cmd(ataio, ATA_SETFEATURES,
488 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
492 cam_fill_ataio(ataio,
500 ata_28bit_cmd(ataio, ATA_SETFEATURES,
501 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
505 cam_fill_ataio(ataio,
513 ata_28bit_cmd(ataio, ATA_SETFEATURES,
514 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
518 /* Remember what transport thinks about AEN. */
519 if (softc->caps & CTS_SATA_CAPS_H_AN)
520 path->device->inq_flags |= SID_AEN;
522 path->device->inq_flags &= ~SID_AEN;
523 xpt_async(AC_GETDEV_CHANGED, path, NULL);
524 cam_fill_ataio(ataio,
532 ata_28bit_cmd(ataio, ATA_SETFEATURES,
533 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
536 case PROBE_SET_MULTI:
538 u_int sectors, bytecount;
540 bytecount = 8192; /* SATA maximum */
541 /* Fetch user bytecount from SIM. */
542 bzero(&cts, sizeof(cts));
543 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
544 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
545 cts.type = CTS_TYPE_USER_SETTINGS;
546 xpt_action((union ccb *)&cts);
547 if (path->device->transport == XPORT_ATA) {
548 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
549 bytecount = cts.xport_specific.ata.bytecount;
551 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
552 bytecount = cts.xport_specific.sata.bytecount;
554 /* Honor device capabilities. */
555 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
556 bytecount / ata_logical_sector_size(ident_buf)));
557 /* Report bytecount to SIM. */
558 bzero(&cts, sizeof(cts));
559 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
560 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
561 cts.type = CTS_TYPE_CURRENT_SETTINGS;
562 if (path->device->transport == XPORT_ATA) {
563 cts.xport_specific.ata.bytecount = sectors *
564 ata_logical_sector_size(ident_buf);
565 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
567 cts.xport_specific.sata.bytecount = sectors *
568 ata_logical_sector_size(ident_buf);
569 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
571 xpt_action((union ccb *)&cts);
572 /* Fetch current bytecount from SIM. */
573 bzero(&cts, sizeof(cts));
574 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
575 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
576 cts.type = CTS_TYPE_CURRENT_SETTINGS;
577 xpt_action((union ccb *)&cts);
578 if (path->device->transport == XPORT_ATA) {
579 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
580 bytecount = cts.xport_specific.ata.bytecount;
582 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
583 bytecount = cts.xport_specific.sata.bytecount;
585 sectors = bytecount / ata_logical_sector_size(ident_buf);
587 cam_fill_ataio(ataio,
595 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
602 bytecount = 8192; /* SATA maximum */
603 /* Fetch user bytecount from SIM. */
604 bzero(&cts, sizeof(cts));
605 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
606 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
607 cts.type = CTS_TYPE_USER_SETTINGS;
608 xpt_action((union ccb *)&cts);
609 if (path->device->transport == XPORT_ATA) {
610 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
611 bytecount = cts.xport_specific.ata.bytecount;
613 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
614 bytecount = cts.xport_specific.sata.bytecount;
616 /* Honor device capabilities. */
618 bytecount = max(2, min(65534, bytecount));
619 if (ident_buf->satacapabilities != 0x0000 &&
620 ident_buf->satacapabilities != 0xffff) {
621 bytecount = min(8192, bytecount);
623 /* Report bytecount to SIM. */
624 bzero(&cts, sizeof(cts));
625 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
626 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
627 cts.type = CTS_TYPE_CURRENT_SETTINGS;
628 if (path->device->transport == XPORT_ATA) {
629 cts.xport_specific.ata.bytecount = bytecount;
630 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
632 cts.xport_specific.sata.bytecount = bytecount;
633 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
635 xpt_action((union ccb *)&cts);
638 case PROBE_FULL_INQUIRY:
641 struct scsi_inquiry_data *inq_buf =
642 &periph->path->device->inq_data;
644 if (softc->action == PROBE_INQUIRY)
645 inquiry_len = SHORT_INQUIRY_LENGTH;
647 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
649 * Some parallel SCSI devices fail to send an
650 * ignore wide residue message when dealing with
651 * odd length inquiry requests. Round up to be
654 inquiry_len = roundup2(inquiry_len, 2);
664 /*timeout*/60 * 1000);
668 cam_fill_ataio(ataio,
671 /*flags*/CAM_DIR_NONE,
676 ata_pm_read_cmd(ataio, 0, 15);
679 cam_fill_ataio(ataio,
682 /*flags*/CAM_DIR_NONE,
687 ata_pm_read_cmd(ataio, 1, 15);
689 case PROBE_IDENTIFY_SES:
690 cam_fill_ataio(ataio,
695 /*data_ptr*/(u_int8_t *)&softc->ident_data,
696 /*dxfer_len*/sizeof(softc->ident_data),
698 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
699 sizeof(softc->ident_data) / 4);
701 case PROBE_IDENTIFY_SAFTE:
702 cam_fill_ataio(ataio,
707 /*data_ptr*/(u_int8_t *)&softc->ident_data,
708 /*dxfer_len*/sizeof(softc->ident_data),
710 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
711 sizeof(softc->ident_data) / 4);
714 panic("probestart: invalid action state 0x%x\n", softc->action);
716 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
717 xpt_action(start_ccb);
721 proberequestdefaultnegotiation(struct cam_periph *periph)
723 struct ccb_trans_settings cts;
725 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
726 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
727 cts.type = CTS_TYPE_USER_SETTINGS;
728 xpt_action((union ccb *)&cts);
729 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
731 cts.xport_specific.valid = 0;
732 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
733 cts.type = CTS_TYPE_CURRENT_SETTINGS;
734 xpt_action((union ccb *)&cts);
738 probedone(struct cam_periph *periph, union ccb *done_ccb)
740 struct ccb_trans_settings cts;
741 struct ata_params *ident_buf;
742 struct scsi_inquiry_data *inq_buf;
744 struct cam_path *path;
748 int changed = 1, found = 1;
749 static const uint8_t fake_device_id_hdr[8] =
750 {0, SVPD_DEVICE_ID, 0, 12,
751 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
753 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
755 softc = (probe_softc *)periph->softc;
756 path = done_ccb->ccb_h.path;
757 priority = done_ccb->ccb_h.pinfo.priority;
758 ident_buf = &path->device->ident_data;
759 inq_buf = &path->device->inq_data;
761 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
762 if (cam_periph_error(done_ccb,
763 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
766 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
767 cam_release_devq(path, 0, 0, 0, FALSE);
770 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
771 /* Don't wedge the queue */
772 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
774 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
775 if (softc->restart) {
777 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
780 if (softc->faults < 10)
785 /* Old PIO2 devices may not support mode setting. */
786 } else if (softc->action == PROBE_SETMODE &&
787 status == CAM_ATA_STATUS_ERROR &&
788 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
789 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
793 * Some old WD SATA disks report supported and enabled
794 * device-initiated interface power management, but return
795 * ABORT on attempt to disable it.
797 } else if (softc->action == PROBE_SETPM &&
798 status == CAM_ATA_STATUS_ERROR) {
802 * Some old WD SATA disks have broken SPINUP handling.
803 * If we really fail to spin up the disk, then there will be
804 * some media access errors later on, but at least we will
805 * have a device to interact with for recovery attempts.
807 } else if (softc->action == PROBE_SPINUP &&
808 status == CAM_ATA_STATUS_ERROR) {
812 * Some HP SATA disks report supported DMA Auto-Activation,
813 * but return ABORT on attempt to enable it.
815 } else if (softc->action == PROBE_SETDMAAA &&
816 status == CAM_ATA_STATUS_ERROR) {
820 * SES and SAF-TE SEPs have different IDENTIFY commands,
821 * but SATA specification doesn't tell how to identify them.
822 * Until better way found, just try another if first fail.
824 } else if (softc->action == PROBE_IDENTIFY_SES &&
825 status == CAM_ATA_STATUS_ERROR) {
826 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
827 xpt_release_ccb(done_ccb);
828 xpt_schedule(periph, priority);
833 * If we get to this point, we got an error status back
834 * from the inquiry and the error status doesn't require
835 * automatically retrying the command. Therefore, the
836 * inquiry failed. If we had inquiry information before
837 * for this device, but this latest inquiry command failed,
838 * the device has probably gone away. If this device isn't
839 * already marked unconfigured, notify the peripheral
840 * drivers that this device is no more.
842 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
843 xpt_async(AC_LOST_DEVICE, path, NULL);
844 PROBE_SET_ACTION(softc, PROBE_INVALID);
851 switch (softc->action) {
854 int sign = (done_ccb->ataio.res.lba_high << 8) +
855 done_ccb->ataio.res.lba_mid;
856 CAM_DEBUG(path, CAM_DEBUG_PROBE,
857 ("SIGNATURE: %04x\n", sign));
858 if (sign == 0x0000 &&
859 done_ccb->ccb_h.target_id != 15) {
860 path->device->protocol = PROTO_ATA;
861 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
862 } else if (sign == 0x9669 &&
863 done_ccb->ccb_h.target_id == 15) {
864 /* Report SIM that PM is present. */
865 bzero(&cts, sizeof(cts));
866 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
867 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
868 cts.type = CTS_TYPE_CURRENT_SETTINGS;
869 cts.xport_specific.sata.pm_present = 1;
870 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
871 xpt_action((union ccb *)&cts);
872 path->device->protocol = PROTO_SATAPM;
873 PROBE_SET_ACTION(softc, PROBE_PM_PID);
874 } else if (sign == 0xc33c &&
875 done_ccb->ccb_h.target_id != 15) {
876 path->device->protocol = PROTO_SEMB;
877 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
878 } else if (sign == 0xeb14 &&
879 done_ccb->ccb_h.target_id != 15) {
880 path->device->protocol = PROTO_SCSI;
881 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
883 if (done_ccb->ccb_h.target_id != 15) {
885 "Unexpected signature 0x%04x\n", sign);
889 xpt_release_ccb(done_ccb);
890 xpt_schedule(periph, priority);
895 struct ccb_pathinq cpi;
899 ident_buf = &softc->ident_data;
900 for (ptr = (int16_t *)ident_buf;
901 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
902 *ptr = le16toh(*ptr);
906 * Allow others to veto this ATA disk attachment. This
907 * is mainly used by VMs, whose disk controllers may
908 * share the disks with the simulated ATA controllers.
910 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
915 if (strncmp(ident_buf->model, "FX", 2) &&
916 strncmp(ident_buf->model, "NEC", 3) &&
917 strncmp(ident_buf->model, "Pioneer", 7) &&
918 strncmp(ident_buf->model, "SHARP", 5)) {
919 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
920 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
921 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
923 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
924 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
925 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
926 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
927 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
928 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
929 /* Device may need spin-up before IDENTIFY become valid. */
930 if ((ident_buf->specconf == 0x37c8 ||
931 ident_buf->specconf == 0x738c) &&
932 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
933 softc->spinup == 0)) {
934 PROBE_SET_ACTION(softc, PROBE_SPINUP);
935 xpt_release_ccb(done_ccb);
936 xpt_schedule(periph, priority);
939 ident_buf = &path->device->ident_data;
940 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
941 /* Check that it is the same device. */
942 if (bcmp(softc->ident_data.model, ident_buf->model,
943 sizeof(ident_buf->model)) ||
944 bcmp(softc->ident_data.revision, ident_buf->revision,
945 sizeof(ident_buf->revision)) ||
946 bcmp(softc->ident_data.serial, ident_buf->serial,
947 sizeof(ident_buf->serial))) {
948 /* Device changed. */
949 xpt_async(AC_LOST_DEVICE, path, NULL);
951 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
956 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
957 /* Clean up from previous instance of this device */
958 if (path->device->serial_num != NULL) {
959 free(path->device->serial_num, M_CAMXPT);
960 path->device->serial_num = NULL;
961 path->device->serial_num_len = 0;
963 if (path->device->device_id != NULL) {
964 free(path->device->device_id, M_CAMXPT);
965 path->device->device_id = NULL;
966 path->device->device_id_len = 0;
968 path->device->serial_num =
969 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
971 if (path->device->serial_num != NULL) {
972 bcopy(ident_buf->serial,
973 path->device->serial_num,
974 sizeof(ident_buf->serial));
975 path->device->serial_num[sizeof(ident_buf->serial)]
977 path->device->serial_num_len =
978 strlen(path->device->serial_num);
980 if (ident_buf->enabled.extension &
981 ATA_SUPPORT_64BITWWN) {
982 path->device->device_id =
983 malloc(16, M_CAMXPT, M_NOWAIT);
984 if (path->device->device_id != NULL) {
985 path->device->device_id_len = 16;
986 bcopy(&fake_device_id_hdr,
987 path->device->device_id, 8);
988 bcopy(ident_buf->wwn,
989 path->device->device_id + 8, 8);
990 ata_bswap(path->device->device_id + 8, 8);
994 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
995 xpt_async(AC_GETDEV_CHANGED, path, NULL);
997 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
998 path->device->mintags = 2;
999 path->device->maxtags =
1000 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1002 ata_find_quirk(path->device);
1003 if (path->device->mintags != 0 &&
1004 path->bus->sim->max_tagged_dev_openings != 0) {
1005 /* Check if the SIM does not want queued commands. */
1006 xpt_path_inq(&cpi, path);
1007 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1008 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1009 /* Report SIM which tags are allowed. */
1010 bzero(&cts, sizeof(cts));
1011 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1012 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1013 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1014 cts.xport_specific.sata.tags = path->device->maxtags;
1015 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1016 xpt_action((union ccb *)&cts);
1019 ata_device_transport(path);
1021 proberequestdefaultnegotiation(periph);
1022 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1023 xpt_release_ccb(done_ccb);
1024 xpt_schedule(periph, priority);
1029 xpt_print(path, "Spin-up done\n");
1031 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1032 xpt_release_ccb(done_ccb);
1033 xpt_schedule(periph, priority);
1036 /* Set supported bits. */
1037 bzero(&cts, sizeof(cts));
1038 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1039 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1040 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1041 xpt_action((union ccb *)&cts);
1042 if (path->device->transport == XPORT_SATA &&
1043 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1044 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1045 else if (path->device->transport == XPORT_ATA &&
1046 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1047 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1050 if (path->device->transport == XPORT_SATA &&
1051 ident_buf->satacapabilities != 0xffff) {
1052 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1053 caps |= CTS_SATA_CAPS_D_PMREQ;
1054 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1055 caps |= CTS_SATA_CAPS_D_APST;
1057 /* Mask unwanted bits. */
1058 bzero(&cts, sizeof(cts));
1059 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1060 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1061 cts.type = CTS_TYPE_USER_SETTINGS;
1062 xpt_action((union ccb *)&cts);
1063 if (path->device->transport == XPORT_SATA &&
1064 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1065 caps &= cts.xport_specific.sata.caps;
1066 else if (path->device->transport == XPORT_ATA &&
1067 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1068 caps &= cts.xport_specific.ata.caps;
1072 * Remember what transport thinks about 48-bit DMA. If
1073 * capability information is not provided or transport is
1074 * SATA, we take support for granted.
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 /* Store result to SIM. */
1084 bzero(&cts, sizeof(cts));
1085 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1086 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1087 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1088 if (path->device->transport == XPORT_SATA) {
1089 cts.xport_specific.sata.caps = caps;
1090 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1092 cts.xport_specific.ata.caps = caps;
1093 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1095 xpt_action((union ccb *)&cts);
1097 if (path->device->transport != XPORT_SATA)
1099 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1100 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1101 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1102 PROBE_SET_ACTION(softc, PROBE_SETPM);
1103 xpt_release_ccb(done_ccb);
1104 xpt_schedule(periph, priority);
1109 if (ident_buf->satacapabilities != 0xffff &&
1110 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1111 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1112 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1113 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1114 xpt_release_ccb(done_ccb);
1115 xpt_schedule(periph, priority);
1120 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1121 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1122 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1123 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1124 xpt_release_ccb(done_ccb);
1125 xpt_schedule(periph, priority);
1129 case PROBE_SETDMAAA:
1130 if (path->device->protocol != PROTO_ATA &&
1131 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1132 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1133 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1134 PROBE_SET_ACTION(softc, PROBE_SETAN);
1135 xpt_release_ccb(done_ccb);
1136 xpt_schedule(periph, priority);
1142 if (path->device->protocol == PROTO_ATA) {
1143 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1145 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1147 xpt_release_ccb(done_ccb);
1148 xpt_schedule(periph, priority);
1150 case PROBE_SET_MULTI:
1151 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1152 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1153 xpt_acquire_device(path->device);
1154 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1155 xpt_action(done_ccb);
1156 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1158 PROBE_SET_ACTION(softc, PROBE_DONE);
1161 case PROBE_FULL_INQUIRY:
1163 u_int8_t periph_qual, len;
1165 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1167 periph_qual = SID_QUAL(inq_buf);
1169 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1170 periph_qual != SID_QUAL_LU_OFFLINE)
1174 * We conservatively request only
1175 * SHORT_INQUIRY_LEN bytes of inquiry
1176 * information during our first try
1177 * at sending an INQUIRY. If the device
1178 * has more information to give,
1179 * perform a second request specifying
1180 * the amount of information the device
1181 * is willing to give.
1183 len = inq_buf->additional_length
1184 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1185 if (softc->action == PROBE_INQUIRY
1186 && len > SHORT_INQUIRY_LENGTH) {
1187 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1188 xpt_release_ccb(done_ccb);
1189 xpt_schedule(periph, priority);
1193 ata_device_transport(path);
1194 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1195 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1196 xpt_acquire_device(path->device);
1197 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1198 xpt_action(done_ccb);
1199 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1201 PROBE_SET_ACTION(softc, PROBE_DONE);
1205 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1206 bzero(ident_buf, sizeof(*ident_buf));
1207 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1208 (done_ccb->ataio.res.lba_mid << 16) +
1209 (done_ccb->ataio.res.lba_low << 8) +
1210 done_ccb->ataio.res.sector_count;
1211 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1212 snprintf(ident_buf->model, sizeof(ident_buf->model),
1213 "Port Multiplier %08x", softc->pm_pid);
1214 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1215 xpt_release_ccb(done_ccb);
1216 xpt_schedule(periph, priority);
1219 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1220 (done_ccb->ataio.res.lba_mid << 16) +
1221 (done_ccb->ataio.res.lba_low << 8) +
1222 done_ccb->ataio.res.sector_count;
1223 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1224 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1225 "%04x", softc->pm_prv);
1226 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1227 ata_device_transport(path);
1228 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1229 proberequestdefaultnegotiation(periph);
1230 /* Set supported bits. */
1231 bzero(&cts, sizeof(cts));
1232 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1233 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1234 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1235 xpt_action((union ccb *)&cts);
1236 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1237 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1240 /* All PMPs must support PM requests. */
1241 caps |= CTS_SATA_CAPS_D_PMREQ;
1242 /* Mask unwanted bits. */
1243 bzero(&cts, sizeof(cts));
1244 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1245 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1246 cts.type = CTS_TYPE_USER_SETTINGS;
1247 xpt_action((union ccb *)&cts);
1248 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1249 caps &= cts.xport_specific.sata.caps;
1252 /* Remember what transport thinks about AEN. */
1253 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1254 path->device->inq_flags |= SID_AEN;
1256 path->device->inq_flags &= ~SID_AEN;
1257 /* Store result to SIM. */
1258 bzero(&cts, sizeof(cts));
1259 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1260 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1261 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1262 cts.xport_specific.sata.caps = caps;
1263 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1264 xpt_action((union ccb *)&cts);
1266 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1267 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1268 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1269 xpt_acquire_device(path->device);
1270 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1271 xpt_action(done_ccb);
1272 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1274 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1275 xpt_action(done_ccb);
1276 xpt_async(AC_SCSI_AEN, path, done_ccb);
1278 PROBE_SET_ACTION(softc, PROBE_DONE);
1280 case PROBE_IDENTIFY_SES:
1281 case PROBE_IDENTIFY_SAFTE:
1282 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1283 /* Check that it is the same device. */
1284 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1285 /* Device changed. */
1286 xpt_async(AC_LOST_DEVICE, path, NULL);
1288 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1293 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1294 /* Clean up from previous instance of this device */
1295 if (path->device->device_id != NULL) {
1296 free(path->device->device_id, M_CAMXPT);
1297 path->device->device_id = NULL;
1298 path->device->device_id_len = 0;
1300 path->device->device_id =
1301 malloc(16, M_CAMXPT, M_NOWAIT);
1302 if (path->device->device_id != NULL) {
1303 path->device->device_id_len = 16;
1304 bcopy(&fake_device_id_hdr,
1305 path->device->device_id, 8);
1306 bcopy(((uint8_t*)ident_buf) + 2,
1307 path->device->device_id + 8, 8);
1310 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1312 ata_device_transport(path);
1314 proberequestdefaultnegotiation(periph);
1316 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1317 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1318 xpt_acquire_device(path->device);
1319 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1320 xpt_action(done_ccb);
1321 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1323 PROBE_SET_ACTION(softc, PROBE_DONE);
1326 panic("probedone: invalid action state 0x%x\n", softc->action);
1329 if (softc->restart) {
1331 xpt_release_ccb(done_ccb);
1332 probeschedule(periph);
1335 xpt_release_ccb(done_ccb);
1336 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1337 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1338 TAILQ_REMOVE(&softc->request_ccbs,
1339 &done_ccb->ccb_h, periph_links.tqe);
1340 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1343 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1344 cam_release_devq(path, 0, 0, 0, FALSE);
1345 cam_periph_invalidate(periph);
1346 cam_periph_release_locked(periph);
1350 probecleanup(struct cam_periph *periph)
1352 free(periph->softc, M_CAMXPT);
1356 ata_find_quirk(struct cam_ed *device)
1358 struct ata_quirk_entry *quirk;
1361 match = cam_quirkmatch((caddr_t)&device->ident_data,
1362 (caddr_t)ata_quirk_table,
1363 nitems(ata_quirk_table),
1364 sizeof(*ata_quirk_table), ata_identify_match);
1367 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1369 quirk = (struct ata_quirk_entry *)match;
1370 device->quirk = quirk;
1371 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1372 device->mintags = quirk->mintags;
1373 device->maxtags = quirk->maxtags;
1378 union ccb *request_ccb;
1379 struct ccb_pathinq *cpi;
1381 } ata_scan_bus_info;
1384 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1385 * As the scan progresses, xpt_scan_bus is used as the
1386 * callback on completion function.
1389 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1391 struct cam_path *path;
1392 ata_scan_bus_info *scan_info;
1393 union ccb *work_ccb, *reset_ccb;
1397 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1398 ("xpt_scan_bus\n"));
1399 switch (request_ccb->ccb_h.func_code) {
1402 /* Find out the characteristics of the bus */
1403 work_ccb = xpt_alloc_ccb_nowait();
1404 if (work_ccb == NULL) {
1405 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1406 xpt_done(request_ccb);
1409 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1410 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1411 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1412 xpt_free_ccb(work_ccb);
1413 xpt_done(request_ccb);
1417 /* We may need to reset bus first, if we haven't done it yet. */
1418 if ((work_ccb->cpi.hba_inquiry &
1419 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1420 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1421 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1422 reset_ccb = xpt_alloc_ccb_nowait();
1423 if (reset_ccb == NULL) {
1424 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1425 xpt_free_ccb(work_ccb);
1426 xpt_done(request_ccb);
1429 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1431 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1432 xpt_action(reset_ccb);
1433 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1434 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1435 xpt_free_ccb(reset_ccb);
1436 xpt_free_ccb(work_ccb);
1437 xpt_done(request_ccb);
1440 xpt_free_ccb(reset_ccb);
1443 /* Save some state for use while we probe for devices */
1444 scan_info = (ata_scan_bus_info *)
1445 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1446 if (scan_info == NULL) {
1447 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1448 xpt_free_ccb(work_ccb);
1449 xpt_done(request_ccb);
1452 scan_info->request_ccb = request_ccb;
1453 scan_info->cpi = &work_ccb->cpi;
1454 /* If PM supported, probe it first. */
1455 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1456 scan_info->counter = scan_info->cpi->max_target;
1458 scan_info->counter = 0;
1460 work_ccb = xpt_alloc_ccb_nowait();
1461 if (work_ccb == NULL) {
1462 free(scan_info, M_CAMXPT);
1463 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1464 xpt_done(request_ccb);
1467 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1470 work_ccb = request_ccb;
1471 /* Reuse the same CCB to query if a device was really found */
1472 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1473 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1475 /* If there is PMP... */
1476 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1477 (scan_info->counter == scan_info->cpi->max_target)) {
1478 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1479 /* everything else will be probed by it */
1480 /* Free the current request path- we're done with it. */
1481 xpt_free_path(work_ccb->ccb_h.path);
1484 struct ccb_trans_settings cts;
1486 /* Report SIM that PM is absent. */
1487 bzero(&cts, sizeof(cts));
1488 xpt_setup_ccb(&cts.ccb_h,
1489 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1490 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1491 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1492 cts.xport_specific.sata.pm_present = 0;
1493 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1494 xpt_action((union ccb *)&cts);
1497 /* Free the current request path- we're done with it. */
1498 xpt_free_path(work_ccb->ccb_h.path);
1499 if (scan_info->counter ==
1500 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1501 0 : scan_info->cpi->max_target)) {
1504 xpt_free_ccb(work_ccb);
1505 xpt_free_ccb((union ccb *)scan_info->cpi);
1506 request_ccb = scan_info->request_ccb;
1507 free(scan_info, M_CAMXPT);
1508 request_ccb->ccb_h.status = CAM_REQ_CMP;
1509 xpt_done(request_ccb);
1512 /* Take next device. Wrap from max (PMP) to 0. */
1513 scan_info->counter = (scan_info->counter + 1 ) %
1514 (scan_info->cpi->max_target + 1);
1516 status = xpt_create_path(&path, NULL,
1517 scan_info->request_ccb->ccb_h.path_id,
1518 scan_info->counter, 0);
1519 if (status != CAM_REQ_CMP) {
1520 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1522 printf("xpt_scan_bus: xpt_create_path failed"
1523 " with status %#x, bus scan halted\n",
1525 xpt_free_ccb(work_ccb);
1526 xpt_free_ccb((union ccb *)scan_info->cpi);
1527 request_ccb = scan_info->request_ccb;
1528 free(scan_info, M_CAMXPT);
1529 request_ccb->ccb_h.status = status;
1530 xpt_done(request_ccb);
1533 xpt_setup_ccb(&work_ccb->ccb_h, path,
1534 scan_info->request_ccb->ccb_h.pinfo.priority);
1535 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1536 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1537 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1538 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1539 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1541 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1543 xpt_action(work_ccb);
1553 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1554 cam_flags flags, union ccb *request_ccb)
1556 struct ccb_pathinq cpi;
1558 struct cam_path *new_path;
1559 struct cam_periph *old_periph;
1562 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1564 xpt_path_inq(&cpi, path);
1565 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1566 if (request_ccb != NULL) {
1567 request_ccb->ccb_h.status = cpi.ccb_h.status;
1568 xpt_done(request_ccb);
1573 if (request_ccb == NULL) {
1574 request_ccb = xpt_alloc_ccb_nowait();
1575 if (request_ccb == NULL) {
1576 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1577 "can't continue\n");
1580 status = xpt_create_path(&new_path, NULL,
1582 path->target->target_id,
1583 path->device->lun_id);
1584 if (status != CAM_REQ_CMP) {
1585 xpt_print(path, "xpt_scan_lun: can't create path, "
1586 "can't continue\n");
1587 xpt_free_ccb(request_ccb);
1590 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1591 request_ccb->ccb_h.cbfcnp = xptscandone;
1592 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1593 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1594 request_ccb->crcn.flags = flags;
1597 lock = (xpt_path_owned(path) == 0);
1599 xpt_path_lock(path);
1600 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1601 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1604 softc = (probe_softc *)old_periph->softc;
1605 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1606 &request_ccb->ccb_h, periph_links.tqe);
1609 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1610 xpt_done(request_ccb);
1613 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1614 probestart, "aprobe",
1616 request_ccb->ccb_h.path, NULL, 0,
1619 if (status != CAM_REQ_CMP) {
1620 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1621 "returned an error, can't continue probe\n");
1622 request_ccb->ccb_h.status = status;
1623 xpt_done(request_ccb);
1627 xpt_path_unlock(path);
1631 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1634 xpt_free_path(done_ccb->ccb_h.path);
1635 xpt_free_ccb(done_ccb);
1638 static struct cam_ed *
1639 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1641 struct ata_quirk_entry *quirk;
1642 struct cam_ed *device;
1644 device = xpt_alloc_device(bus, target, lun_id);
1649 * Take the default quirk entry until we have inquiry
1650 * data and can determine a better quirk to use.
1652 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1653 device->quirk = (void *)quirk;
1654 device->mintags = 0;
1655 device->maxtags = 0;
1656 bzero(&device->inq_data, sizeof(device->inq_data));
1657 device->inq_flags = 0;
1658 device->queue_flags = 0;
1659 device->serial_num = NULL;
1660 device->serial_num_len = 0;
1665 ata_device_transport(struct cam_path *path)
1667 struct ccb_pathinq cpi;
1668 struct ccb_trans_settings cts;
1669 struct scsi_inquiry_data *inq_buf = NULL;
1670 struct ata_params *ident_buf = NULL;
1672 /* Get transport information from the SIM */
1673 xpt_path_inq(&cpi, path);
1675 path->device->transport = cpi.transport;
1676 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1677 inq_buf = &path->device->inq_data;
1678 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1679 ident_buf = &path->device->ident_data;
1680 if (path->device->protocol == PROTO_ATA) {
1681 path->device->protocol_version = ident_buf ?
1682 ata_version(ident_buf->version_major) : cpi.protocol_version;
1683 } else if (path->device->protocol == PROTO_SCSI) {
1684 path->device->protocol_version = inq_buf ?
1685 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1687 path->device->transport_version = ident_buf ?
1688 ata_version(ident_buf->version_major) : cpi.transport_version;
1690 /* Tell the controller what we think */
1691 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1692 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1693 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1694 cts.transport = path->device->transport;
1695 cts.transport_version = path->device->transport_version;
1696 cts.protocol = path->device->protocol;
1697 cts.protocol_version = path->device->protocol_version;
1698 cts.proto_specific.valid = 0;
1700 if (path->device->transport == XPORT_ATA) {
1701 cts.xport_specific.ata.atapi =
1702 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1703 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1704 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1705 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1707 cts.xport_specific.sata.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.sata.valid = CTS_SATA_VALID_ATAPI;
1714 cts.xport_specific.valid = 0;
1715 xpt_action((union ccb *)&cts);
1719 ata_dev_advinfo(union ccb *start_ccb)
1721 struct cam_ed *device;
1722 struct ccb_dev_advinfo *cdai;
1725 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1726 device = start_ccb->ccb_h.path->device;
1727 cdai = &start_ccb->cdai;
1728 switch(cdai->buftype) {
1729 case CDAI_TYPE_SCSI_DEVID:
1730 if (cdai->flags & CDAI_FLAG_STORE)
1732 cdai->provsiz = device->device_id_len;
1733 if (device->device_id_len == 0)
1735 amt = device->device_id_len;
1736 if (cdai->provsiz > cdai->bufsiz)
1738 memcpy(cdai->buf, device->device_id, amt);
1740 case CDAI_TYPE_SERIAL_NUM:
1741 if (cdai->flags & CDAI_FLAG_STORE)
1743 cdai->provsiz = device->serial_num_len;
1744 if (device->serial_num_len == 0)
1746 amt = device->serial_num_len;
1747 if (cdai->provsiz > cdai->bufsiz)
1749 memcpy(cdai->buf, device->serial_num, amt);
1751 case CDAI_TYPE_PHYS_PATH:
1752 if (cdai->flags & CDAI_FLAG_STORE) {
1753 if (device->physpath != NULL)
1754 free(device->physpath, M_CAMXPT);
1755 device->physpath_len = cdai->bufsiz;
1756 /* Clear existing buffer if zero length */
1757 if (cdai->bufsiz == 0)
1759 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1760 if (device->physpath == NULL) {
1761 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1764 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1766 cdai->provsiz = device->physpath_len;
1767 if (device->physpath_len == 0)
1769 amt = device->physpath_len;
1770 if (cdai->provsiz > cdai->bufsiz)
1772 memcpy(cdai->buf, device->physpath, amt);
1778 start_ccb->ccb_h.status = CAM_REQ_CMP;
1780 if (cdai->flags & CDAI_FLAG_STORE) {
1781 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1782 (void *)(uintptr_t)cdai->buftype);
1787 ata_action(union ccb *start_ccb)
1790 switch (start_ccb->ccb_h.func_code) {
1791 case XPT_SET_TRAN_SETTINGS:
1793 ata_set_transfer_settings(&start_ccb->cts,
1794 start_ccb->ccb_h.path,
1795 /*async_update*/FALSE);
1800 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1803 ata_scan_lun(start_ccb->ccb_h.path->periph,
1804 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1807 case XPT_GET_TRAN_SETTINGS:
1809 ata_get_transfer_settings(&start_ccb->cts);
1814 struct cam_ed *device;
1817 device = start_ccb->ccb_h.path->device;
1818 if (device->protocol == PROTO_SCSI &&
1819 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1821 device->ident_data.config & ATA_PROTO_MASK;
1824 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1825 (p == ATA_PROTO_ATAPI_16) ? 16 :
1826 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1828 if (start_ccb->csio.cdb_len > maxlen) {
1829 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1830 xpt_done(start_ccb);
1833 xpt_action_default(start_ccb);
1836 case XPT_DEV_ADVINFO:
1838 ata_dev_advinfo(start_ccb);
1842 xpt_action_default(start_ccb);
1848 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1850 struct ccb_trans_settings_ata *ata;
1851 struct ccb_trans_settings_scsi *scsi;
1852 struct cam_ed *device;
1854 device = cts->ccb_h.path->device;
1855 xpt_action_default((union ccb *)cts);
1857 if (cts->protocol == PROTO_UNKNOWN ||
1858 cts->protocol == PROTO_UNSPECIFIED) {
1859 cts->protocol = device->protocol;
1860 cts->protocol_version = device->protocol_version;
1863 if (cts->protocol == PROTO_ATA) {
1864 ata = &cts->proto_specific.ata;
1865 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1866 ata->valid |= CTS_ATA_VALID_TQ;
1867 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1868 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1869 (device->inq_flags & SID_CmdQue) != 0)
1870 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1873 if (cts->protocol == PROTO_SCSI) {
1874 scsi = &cts->proto_specific.scsi;
1875 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1876 scsi->valid |= CTS_SCSI_VALID_TQ;
1877 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1878 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1879 (device->inq_flags & SID_CmdQue) != 0)
1880 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1884 if (cts->transport == XPORT_UNKNOWN ||
1885 cts->transport == XPORT_UNSPECIFIED) {
1886 cts->transport = device->transport;
1887 cts->transport_version = device->transport_version;
1892 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1895 struct ccb_pathinq cpi;
1896 struct ccb_trans_settings_ata *ata;
1897 struct ccb_trans_settings_scsi *scsi;
1898 struct ata_params *ident_data;
1899 struct scsi_inquiry_data *inq_data;
1900 struct cam_ed *device;
1902 if (path == NULL || (device = path->device) == NULL) {
1903 cts->ccb_h.status = CAM_PATH_INVALID;
1904 xpt_done((union ccb *)cts);
1908 if (cts->protocol == PROTO_UNKNOWN
1909 || cts->protocol == PROTO_UNSPECIFIED) {
1910 cts->protocol = device->protocol;
1911 cts->protocol_version = device->protocol_version;
1914 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1915 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1916 cts->protocol_version = device->protocol_version;
1918 if (cts->protocol != device->protocol) {
1919 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1920 cts->protocol, device->protocol);
1921 cts->protocol = device->protocol;
1924 if (cts->protocol_version > device->protocol_version) {
1926 xpt_print(path, "Down reving Protocol "
1927 "Version from %d to %d?\n", cts->protocol_version,
1928 device->protocol_version);
1930 cts->protocol_version = device->protocol_version;
1933 if (cts->transport == XPORT_UNKNOWN
1934 || cts->transport == XPORT_UNSPECIFIED) {
1935 cts->transport = device->transport;
1936 cts->transport_version = device->transport_version;
1939 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1940 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1941 cts->transport_version = device->transport_version;
1943 if (cts->transport != device->transport) {
1944 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1945 cts->transport, device->transport);
1946 cts->transport = device->transport;
1949 if (cts->transport_version > device->transport_version) {
1951 xpt_print(path, "Down reving Transport "
1952 "Version from %d to %d?\n", cts->transport_version,
1953 device->transport_version);
1955 cts->transport_version = device->transport_version;
1958 ident_data = &device->ident_data;
1959 inq_data = &device->inq_data;
1960 if (cts->protocol == PROTO_ATA)
1961 ata = &cts->proto_specific.ata;
1964 if (cts->protocol == PROTO_SCSI)
1965 scsi = &cts->proto_specific.scsi;
1968 xpt_path_inq(&cpi, path);
1970 /* Sanity checking */
1971 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1972 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1973 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1974 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1975 || (device->mintags == 0)) {
1977 * Can't tag on hardware that doesn't support tags,
1978 * doesn't have it enabled, or has broken tag support.
1981 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1983 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1986 /* Start/stop tags use. */
1987 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1988 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1989 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1992 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1993 (device->inq_flags & SID_CmdQue) != 0);
1995 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1997 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1999 if (newt && !nowt) {
2001 * Delay change to use tags until after a
2002 * few commands have gone to this device so
2003 * the controller has time to perform transfer
2004 * negotiations without tagged messages getting
2007 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2008 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2009 } else if (nowt && !newt)
2010 xpt_stop_tags(path);
2013 if (async_update == FALSE)
2014 xpt_action_default((union ccb *)cts);
2018 * Handle any per-device event notifications that require action by the XPT.
2021 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2022 struct cam_ed *device, void *async_arg)
2025 struct cam_path newpath;
2028 * We only need to handle events for real devices.
2030 if (target->target_id == CAM_TARGET_WILDCARD
2031 || device->lun_id == CAM_LUN_WILDCARD)
2035 * We need our own path with wildcards expanded to
2036 * handle certain types of events.
2038 if ((async_code == AC_SENT_BDR)
2039 || (async_code == AC_BUS_RESET)
2040 || (async_code == AC_INQ_CHANGED))
2041 status = xpt_compile_path(&newpath, NULL,
2046 status = CAM_REQ_CMP_ERR;
2048 if (status == CAM_REQ_CMP) {
2049 if (async_code == AC_INQ_CHANGED) {
2051 * We've sent a start unit command, or
2052 * something similar to a device that
2053 * may have caused its inquiry data to
2054 * change. So we re-scan the device to
2055 * refresh the inquiry data for it.
2057 ata_scan_lun(newpath.periph, &newpath,
2058 CAM_EXPECT_INQ_CHANGE, NULL);
2060 /* We need to reinitialize device after reset. */
2061 ata_scan_lun(newpath.periph, &newpath,
2064 xpt_release_path(&newpath);
2065 } else if (async_code == AC_LOST_DEVICE &&
2066 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2067 device->flags |= CAM_DEV_UNCONFIGURED;
2068 xpt_release_device(device);
2069 } else if (async_code == AC_TRANSFER_NEG) {
2070 struct ccb_trans_settings *settings;
2071 struct cam_path path;
2073 settings = (struct ccb_trans_settings *)async_arg;
2074 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2076 ata_set_transfer_settings(settings, &path,
2077 /*async_update*/TRUE);
2078 xpt_release_path(&path);
2083 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2085 struct ccb_pathinq cpi;
2086 struct cam_path *path = periph->path;
2088 cam_periph_assert(periph, MA_OWNED);
2090 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2091 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2092 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2093 xpt_action((union ccb*)cts);
2094 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2096 /* Ask the SIM for its base transfer speed */
2097 xpt_path_inq(&cpi, path);
2098 /* Report connection speed */
2099 *speed = cpi.base_transfer_speed;
2100 if (cts->transport == XPORT_ATA) {
2101 struct ccb_trans_settings_pata *pata =
2102 &cts->xport_specific.ata;
2104 if (pata->valid & CTS_ATA_VALID_MODE)
2105 *speed = ata_mode2speed(pata->mode);
2107 if (cts->transport == XPORT_SATA) {
2108 struct ccb_trans_settings_sata *sata =
2109 &cts->xport_specific.sata;
2111 if (sata->valid & CTS_SATA_VALID_REVISION)
2112 *speed = ata_revision2speed(sata->revision);
2117 ata_announce_periph(struct cam_periph *periph)
2119 struct ccb_trans_settings cts;
2122 _ata_announce_periph(periph, &cts, &speed);
2123 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2128 printf("%s%d: %d.%03dMB/s transfers",
2129 periph->periph_name, periph->unit_number,
2132 printf("%s%d: %dKB/s transfers", periph->periph_name,
2133 periph->unit_number, speed);
2134 /* Report additional information about connection */
2135 if (cts.transport == XPORT_ATA) {
2136 struct ccb_trans_settings_pata *pata =
2137 &cts.xport_specific.ata;
2140 if (pata->valid & CTS_ATA_VALID_MODE)
2141 printf("%s, ", ata_mode2string(pata->mode));
2142 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2143 printf("ATAPI %dbytes, ", pata->atapi);
2144 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2145 printf("PIO %dbytes", pata->bytecount);
2148 if (cts.transport == XPORT_SATA) {
2149 struct ccb_trans_settings_sata *sata =
2150 &cts.xport_specific.sata;
2153 if (sata->valid & CTS_SATA_VALID_REVISION)
2154 printf("SATA %d.x, ", sata->revision);
2157 if (sata->valid & CTS_SATA_VALID_MODE)
2158 printf("%s, ", ata_mode2string(sata->mode));
2159 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2160 printf("ATAPI %dbytes, ", sata->atapi);
2161 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2162 printf("PIO %dbytes", sata->bytecount);
2169 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2171 struct ccb_trans_settings cts;
2174 _ata_announce_periph(periph, &cts, &speed);
2175 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2180 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2181 periph->periph_name, periph->unit_number,
2184 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2185 periph->unit_number, speed);
2186 /* Report additional information about connection */
2187 if (cts.transport == XPORT_ATA) {
2188 struct ccb_trans_settings_pata *pata =
2189 &cts.xport_specific.ata;
2191 sbuf_printf(sb, " (");
2192 if (pata->valid & CTS_ATA_VALID_MODE)
2193 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2194 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2195 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2196 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2197 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2198 sbuf_printf(sb, ")");
2200 if (cts.transport == XPORT_SATA) {
2201 struct ccb_trans_settings_sata *sata =
2202 &cts.xport_specific.sata;
2204 sbuf_printf(sb, " (");
2205 if (sata->valid & CTS_SATA_VALID_REVISION)
2206 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2208 sbuf_printf(sb, "SATA, ");
2209 if (sata->valid & CTS_SATA_VALID_MODE)
2210 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2211 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2212 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2213 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2214 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2215 sbuf_printf(sb, ")");
2217 sbuf_printf(sb, "\n");
2221 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2223 ata_print_ident_sbuf(&device->ident_data, sb);
2227 ata_proto_announce(struct cam_ed *device)
2229 ata_print_ident(&device->ident_data);
2233 ata_proto_denounce(struct cam_ed *device)
2235 ata_print_ident_short(&device->ident_data);
2239 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2241 ata_print_ident_short_sbuf(&device->ident_data, sb);
2245 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2247 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2251 semb_proto_announce(struct cam_ed *device)
2253 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2257 semb_proto_denounce(struct cam_ed *device)
2259 semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
2263 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2265 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2269 ata_proto_debug_out(union ccb *ccb)
2271 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2273 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2276 CAM_DEBUG(ccb->ccb_h.path,
2277 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2278 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));