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 aprobe_periph_init;
76 static struct periph_driver aprobe_driver =
78 aprobe_periph_init, "aprobe",
79 TAILQ_HEAD_INITIALIZER(aprobe_driver.units), /* generation */ 0,
83 PERIPHDRIVER_DECLARE(aprobe, aprobe_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;
142 aprobe_action action;
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 aproberegister(struct cam_periph *periph, void *arg);
166 static void aprobeschedule(struct cam_periph *probe_periph);
167 static void aprobestart(struct cam_periph *periph, union ccb *start_ccb);
168 static void aproberequestdefaultnegotiation(struct cam_periph *periph);
169 static void aprobedone(struct cam_periph *periph, union ccb *done_ccb);
170 static void aprobecleanup(struct cam_periph *periph);
171 static void ata_find_quirk(struct cam_ed *device);
172 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
173 static void ata_scan_lun(struct cam_periph *periph,
174 struct cam_path *path, cam_flags flags,
176 static void axptscandone(struct cam_periph *periph, union ccb *done_ccb);
177 static struct cam_ed *
178 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
180 static void ata_device_transport(struct cam_path *path);
181 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
182 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
183 struct cam_path *path,
185 static void ata_dev_async(u_int32_t async_code,
187 struct cam_et *target,
188 struct cam_ed *device,
190 static void ata_action(union ccb *start_ccb);
191 static void ata_announce_periph(struct cam_periph *periph);
192 static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
193 static void ata_proto_announce(struct cam_ed *device);
194 static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
195 static void ata_proto_denounce(struct cam_ed *device);
196 static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
197 static void ata_proto_debug_out(union ccb *ccb);
198 static void semb_proto_announce(struct cam_ed *device);
199 static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
200 static void semb_proto_denounce(struct cam_ed *device);
201 static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
203 static int ata_dma = 1;
204 static int atapi_dma = 1;
206 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
207 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
209 static struct xpt_xport_ops ata_xport_ops = {
210 .alloc_device = ata_alloc_device,
211 .action = ata_action,
212 .async = ata_dev_async,
213 .announce = ata_announce_periph,
214 .announce_sbuf = ata_announce_periph_sbuf,
216 #define ATA_XPT_XPORT(x, X) \
217 static struct xpt_xport ata_xport_ ## x = { \
218 .xport = XPORT_ ## X, \
220 .ops = &ata_xport_ops, \
222 CAM_XPT_XPORT(ata_xport_ ## x);
224 ATA_XPT_XPORT(ata, ATA);
225 ATA_XPT_XPORT(sata, SATA);
227 #undef ATA_XPORT_XPORT
229 static struct xpt_proto_ops ata_proto_ops_ata = {
230 .announce = ata_proto_announce,
231 .announce_sbuf = ata_proto_announce_sbuf,
232 .denounce = ata_proto_denounce,
233 .denounce_sbuf = ata_proto_denounce_sbuf,
234 .debug_out = ata_proto_debug_out,
236 static struct xpt_proto ata_proto_ata = {
239 .ops = &ata_proto_ops_ata,
242 static struct xpt_proto_ops ata_proto_ops_satapm = {
243 .announce = ata_proto_announce,
244 .announce_sbuf = ata_proto_announce_sbuf,
245 .denounce = ata_proto_denounce,
246 .denounce_sbuf = ata_proto_denounce_sbuf,
247 .debug_out = ata_proto_debug_out,
249 static struct xpt_proto ata_proto_satapm = {
250 .proto = PROTO_SATAPM,
252 .ops = &ata_proto_ops_satapm,
255 static struct xpt_proto_ops ata_proto_ops_semb = {
256 .announce = semb_proto_announce,
257 .announce_sbuf = semb_proto_announce_sbuf,
258 .denounce = semb_proto_denounce,
259 .denounce_sbuf = semb_proto_denounce_sbuf,
260 .debug_out = ata_proto_debug_out,
262 static struct xpt_proto ata_proto_semb = {
265 .ops = &ata_proto_ops_semb,
268 CAM_XPT_PROTO(ata_proto_ata);
269 CAM_XPT_PROTO(ata_proto_satapm);
270 CAM_XPT_PROTO(ata_proto_semb);
273 aprobe_periph_init(void)
278 aproberegister(struct cam_periph *periph, void *arg)
280 union ccb *request_ccb; /* CCB representing the probe request */
283 request_ccb = (union ccb *)arg;
284 if (request_ccb == NULL) {
285 printf("proberegister: no probe CCB, "
286 "can't register device\n");
287 return(CAM_REQ_CMP_ERR);
290 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
293 printf("proberegister: Unable to probe new device. "
294 "Unable to allocate softc\n");
295 return(CAM_REQ_CMP_ERR);
297 TAILQ_INIT(&softc->request_ccbs);
298 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
301 periph->softc = softc;
302 softc->periph = periph;
303 softc->action = PROBE_INVALID;
304 if (cam_periph_acquire(periph) != 0)
305 return (CAM_REQ_CMP_ERR);
307 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
308 ata_device_transport(periph->path);
309 aprobeschedule(periph);
314 aprobeschedule(struct cam_periph *periph)
319 softc = (probe_softc *)periph->softc;
320 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
322 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
323 periph->path->device->protocol == PROTO_SATAPM ||
324 periph->path->device->protocol == PROTO_SEMB)
325 PROBE_SET_ACTION(softc, PROBE_RESET);
327 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
329 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
330 softc->flags |= PROBE_NO_ANNOUNCE;
332 softc->flags &= ~PROBE_NO_ANNOUNCE;
334 xpt_schedule(periph, CAM_PRIORITY_XPT);
338 aprobestart(struct cam_periph *periph, union ccb *start_ccb)
340 struct ccb_trans_settings cts;
341 struct ccb_ataio *ataio;
342 struct ccb_scsiio *csio;
344 struct cam_path *path;
345 struct ata_params *ident_buf;
348 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobestart\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 (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 (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.sata.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. */
462 oif = path->device->inq_flags;
464 path->device->inq_flags &= ~SID_DMA;
466 path->device->inq_flags |= SID_DMA;
467 if (path->device->inq_flags != oif)
468 xpt_async(AC_GETDEV_CHANGED, path, NULL);
469 cam_fill_ataio(ataio,
472 /*flags*/CAM_DIR_NONE,
477 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
481 cam_fill_ataio(ataio,
489 ata_28bit_cmd(ataio, ATA_SETFEATURES,
490 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
494 cam_fill_ataio(ataio,
502 ata_28bit_cmd(ataio, ATA_SETFEATURES,
503 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
507 cam_fill_ataio(ataio,
515 ata_28bit_cmd(ataio, ATA_SETFEATURES,
516 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
520 /* Remember what transport thinks about AEN. */
521 oif = path->device->inq_flags;
522 if (softc->caps & CTS_SATA_CAPS_H_AN)
523 path->device->inq_flags |= SID_AEN;
525 path->device->inq_flags &= ~SID_AEN;
526 if (path->device->inq_flags != oif)
527 xpt_async(AC_GETDEV_CHANGED, path, NULL);
528 cam_fill_ataio(ataio,
536 ata_28bit_cmd(ataio, ATA_SETFEATURES,
537 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
540 case PROBE_SET_MULTI:
542 u_int sectors, bytecount;
544 bytecount = 8192; /* SATA maximum */
545 /* Fetch user bytecount from SIM. */
546 bzero(&cts, sizeof(cts));
547 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
548 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
549 cts.type = CTS_TYPE_USER_SETTINGS;
550 xpt_action((union ccb *)&cts);
551 if (path->device->transport == XPORT_ATA) {
552 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
553 bytecount = cts.xport_specific.ata.bytecount;
555 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
556 bytecount = cts.xport_specific.sata.bytecount;
558 /* Honor device capabilities. */
559 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
560 bytecount / ata_logical_sector_size(ident_buf)));
561 /* Report bytecount to SIM. */
562 bzero(&cts, sizeof(cts));
563 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
564 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
565 cts.type = CTS_TYPE_CURRENT_SETTINGS;
566 if (path->device->transport == XPORT_ATA) {
567 cts.xport_specific.ata.bytecount = sectors *
568 ata_logical_sector_size(ident_buf);
569 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
571 cts.xport_specific.sata.bytecount = sectors *
572 ata_logical_sector_size(ident_buf);
573 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
575 xpt_action((union ccb *)&cts);
576 /* Fetch current bytecount from SIM. */
577 bzero(&cts, sizeof(cts));
578 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
579 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
580 cts.type = CTS_TYPE_CURRENT_SETTINGS;
581 xpt_action((union ccb *)&cts);
582 if (path->device->transport == XPORT_ATA) {
583 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
584 bytecount = cts.xport_specific.ata.bytecount;
586 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
587 bytecount = cts.xport_specific.sata.bytecount;
589 sectors = bytecount / ata_logical_sector_size(ident_buf);
591 cam_fill_ataio(ataio,
599 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
606 bytecount = 8192; /* SATA maximum */
607 /* Fetch user bytecount from SIM. */
608 bzero(&cts, sizeof(cts));
609 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
610 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
611 cts.type = CTS_TYPE_USER_SETTINGS;
612 xpt_action((union ccb *)&cts);
613 if (path->device->transport == XPORT_ATA) {
614 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
615 bytecount = cts.xport_specific.ata.bytecount;
617 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
618 bytecount = cts.xport_specific.sata.bytecount;
620 /* Honor device capabilities. */
622 bytecount = max(2, min(65534, bytecount));
623 if (ident_buf->satacapabilities != 0x0000 &&
624 ident_buf->satacapabilities != 0xffff) {
625 bytecount = min(8192, bytecount);
627 /* Report bytecount to SIM. */
628 bzero(&cts, sizeof(cts));
629 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
630 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
631 cts.type = CTS_TYPE_CURRENT_SETTINGS;
632 if (path->device->transport == XPORT_ATA) {
633 cts.xport_specific.ata.bytecount = bytecount;
634 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
636 cts.xport_specific.sata.bytecount = bytecount;
637 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
639 xpt_action((union ccb *)&cts);
642 case PROBE_FULL_INQUIRY:
645 struct scsi_inquiry_data *inq_buf =
646 &path->device->inq_data;
648 if (softc->action == PROBE_INQUIRY)
649 inquiry_len = SHORT_INQUIRY_LENGTH;
651 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
653 * Some parallel SCSI devices fail to send an
654 * ignore wide residue message when dealing with
655 * odd length inquiry requests. Round up to be
658 inquiry_len = roundup2(inquiry_len, 2);
668 /*timeout*/60 * 1000);
672 cam_fill_ataio(ataio,
675 /*flags*/CAM_DIR_NONE,
680 ata_pm_read_cmd(ataio, 0, 15);
683 cam_fill_ataio(ataio,
686 /*flags*/CAM_DIR_NONE,
691 ata_pm_read_cmd(ataio, 1, 15);
693 case PROBE_IDENTIFY_SES:
694 cam_fill_ataio(ataio,
699 /*data_ptr*/(u_int8_t *)&softc->ident_data,
700 /*dxfer_len*/sizeof(softc->ident_data),
702 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
703 sizeof(softc->ident_data) / 4);
705 case PROBE_IDENTIFY_SAFTE:
706 cam_fill_ataio(ataio,
711 /*data_ptr*/(u_int8_t *)&softc->ident_data,
712 /*dxfer_len*/sizeof(softc->ident_data),
714 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
715 sizeof(softc->ident_data) / 4);
718 panic("aprobestart: invalid action state 0x%x\n", softc->action);
720 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
721 xpt_action(start_ccb);
725 aproberequestdefaultnegotiation(struct cam_periph *periph)
727 struct ccb_trans_settings cts;
729 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
730 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
731 cts.type = CTS_TYPE_USER_SETTINGS;
732 xpt_action((union ccb *)&cts);
733 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
735 cts.xport_specific.valid = 0;
736 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
737 cts.type = CTS_TYPE_CURRENT_SETTINGS;
738 xpt_action((union ccb *)&cts);
742 aprobedone(struct cam_periph *periph, union ccb *done_ccb)
744 struct ccb_trans_settings cts;
745 struct ata_params *ident_buf;
746 struct scsi_inquiry_data *inq_buf;
748 struct cam_path *path;
752 int changed, found = 1;
753 static const uint8_t fake_device_id_hdr[8] =
754 {0, SVPD_DEVICE_ID, 0, 12,
755 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
757 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobedone\n"));
759 softc = (probe_softc *)periph->softc;
760 path = done_ccb->ccb_h.path;
761 priority = done_ccb->ccb_h.pinfo.priority;
762 ident_buf = &path->device->ident_data;
763 inq_buf = &path->device->inq_data;
765 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
766 if (cam_periph_error(done_ccb,
767 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
770 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
771 cam_release_devq(path, 0, 0, 0, FALSE);
774 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
775 /* Don't wedge the queue */
776 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
778 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
779 if (softc->restart) {
781 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
784 if (softc->faults < 10)
789 /* Old PIO2 devices may not support mode setting. */
790 } else if (softc->action == PROBE_SETMODE &&
791 status == CAM_ATA_STATUS_ERROR &&
792 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
793 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
797 * Some old WD SATA disks report supported and enabled
798 * device-initiated interface power management, but return
799 * ABORT on attempt to disable it.
801 } else if (softc->action == PROBE_SETPM &&
802 status == CAM_ATA_STATUS_ERROR) {
806 * Some old WD SATA disks have broken SPINUP handling.
807 * If we really fail to spin up the disk, then there will be
808 * some media access errors later on, but at least we will
809 * have a device to interact with for recovery attempts.
811 } else if (softc->action == PROBE_SPINUP &&
812 status == CAM_ATA_STATUS_ERROR) {
816 * Some HP SATA disks report supported DMA Auto-Activation,
817 * but return ABORT on attempt to enable it.
819 } else if (softc->action == PROBE_SETDMAAA &&
820 status == CAM_ATA_STATUS_ERROR) {
824 * SES and SAF-TE SEPs have different IDENTIFY commands,
825 * but SATA specification doesn't tell how to identify them.
826 * Until better way found, just try another if first fail.
828 } else if (softc->action == PROBE_IDENTIFY_SES &&
829 status == CAM_ATA_STATUS_ERROR) {
830 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
831 xpt_release_ccb(done_ccb);
832 xpt_schedule(periph, priority);
837 * If we get to this point, we got an error status back
838 * from the inquiry and the error status doesn't require
839 * automatically retrying the command. Therefore, the
840 * inquiry failed. If we had inquiry information before
841 * for this device, but this latest inquiry command failed,
842 * the device has probably gone away. If this device isn't
843 * already marked unconfigured, notify the peripheral
844 * drivers that this device is no more.
846 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
847 xpt_async(AC_LOST_DEVICE, path, NULL);
848 PROBE_SET_ACTION(softc, PROBE_INVALID);
855 switch (softc->action) {
858 int sign = (done_ccb->ataio.res.lba_high << 8) +
859 done_ccb->ataio.res.lba_mid;
860 CAM_DEBUG(path, CAM_DEBUG_PROBE,
861 ("SIGNATURE: %04x\n", sign));
862 if (sign == 0x0000 &&
863 done_ccb->ccb_h.target_id != 15) {
864 path->device->protocol = PROTO_ATA;
865 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
866 } else if (sign == 0x9669 &&
867 done_ccb->ccb_h.target_id == 15) {
868 /* Report SIM that PM is present. */
869 bzero(&cts, sizeof(cts));
870 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
871 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
872 cts.type = CTS_TYPE_CURRENT_SETTINGS;
873 cts.xport_specific.sata.pm_present = 1;
874 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
875 xpt_action((union ccb *)&cts);
876 path->device->protocol = PROTO_SATAPM;
877 PROBE_SET_ACTION(softc, PROBE_PM_PID);
878 } else if (sign == 0xc33c &&
879 done_ccb->ccb_h.target_id != 15) {
880 path->device->protocol = PROTO_SEMB;
881 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
882 } else if (sign == 0xeb14 &&
883 done_ccb->ccb_h.target_id != 15) {
884 path->device->protocol = PROTO_SCSI;
885 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
887 if (done_ccb->ccb_h.target_id != 15) {
889 "Unexpected signature 0x%04x\n", sign);
893 xpt_release_ccb(done_ccb);
894 xpt_schedule(periph, priority);
899 struct ccb_pathinq cpi;
903 * Convert to host byte order, and fix the strings.
905 ident_buf = &softc->ident_data;
906 ata_param_fixup(ident_buf);
909 * Allow others to veto this ATA disk attachment. This
910 * is mainly used by VMs, whose disk controllers may
911 * share the disks with the simulated ATA controllers.
913 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
918 /* Device may need spin-up before IDENTIFY become valid. */
919 if ((ident_buf->specconf == 0x37c8 ||
920 ident_buf->specconf == 0x738c) &&
921 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
922 softc->spinup == 0)) {
923 PROBE_SET_ACTION(softc, PROBE_SPINUP);
924 xpt_release_ccb(done_ccb);
925 xpt_schedule(periph, priority);
928 ident_buf = &path->device->ident_data;
930 /* Check that it is the same device as we know. */
931 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
932 if (bcmp(softc->ident_data.model, ident_buf->model,
933 sizeof(ident_buf->model)) ||
934 bcmp(softc->ident_data.serial, ident_buf->serial,
935 sizeof(ident_buf->serial))) {
936 /* The device was replaced. */
938 xpt_async(AC_LOST_DEVICE, path, NULL);
939 } else if (bcmp(&softc->ident_data, ident_buf,
940 sizeof(*ident_buf))) {
941 /* The device is the same, but has changed. */
944 /* Nothing has changed. */
948 /* This is a new device. */
953 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
955 /* Clean up from previous instance of this device */
956 if (path->device->serial_num != NULL) {
957 free(path->device->serial_num, M_CAMXPT);
958 path->device->serial_num = NULL;
959 path->device->serial_num_len = 0;
961 if (path->device->device_id != NULL) {
962 free(path->device->device_id, M_CAMXPT);
963 path->device->device_id = NULL;
964 path->device->device_id_len = 0;
966 path->device->serial_num =
967 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
969 if (path->device->serial_num != NULL) {
970 bcopy(ident_buf->serial,
971 path->device->serial_num,
972 sizeof(ident_buf->serial));
973 path->device->serial_num[sizeof(ident_buf->serial)]
975 path->device->serial_num_len =
976 strlen(path->device->serial_num);
978 if (ident_buf->enabled.extension &
979 ATA_SUPPORT_64BITWWN) {
980 path->device->device_id =
981 malloc(16, M_CAMXPT, M_NOWAIT);
982 if (path->device->device_id != NULL) {
983 path->device->device_id_len = 16;
984 bcopy(&fake_device_id_hdr,
985 path->device->device_id, 8);
986 bcopy(ident_buf->wwn,
987 path->device->device_id + 8, 8);
988 ata_bswap(path->device->device_id + 8, 8);
991 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
994 xpt_async(AC_GETDEV_CHANGED, path, NULL);
995 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
996 path->device->mintags = 2;
997 path->device->maxtags =
998 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1000 ata_find_quirk(path->device);
1001 if (path->device->mintags != 0 &&
1002 path->bus->sim->max_tagged_dev_openings != 0) {
1003 /* Check if the SIM does not want queued commands. */
1004 xpt_path_inq(&cpi, path);
1005 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1006 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1007 /* Report SIM which tags are allowed. */
1008 bzero(&cts, sizeof(cts));
1009 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1010 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1011 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1012 cts.xport_specific.sata.tags = path->device->maxtags;
1013 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1014 xpt_action((union ccb *)&cts);
1017 ata_device_transport(path);
1019 aproberequestdefaultnegotiation(periph);
1020 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1021 xpt_release_ccb(done_ccb);
1022 xpt_schedule(periph, priority);
1027 xpt_print(path, "Spin-up done\n");
1029 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1030 xpt_release_ccb(done_ccb);
1031 xpt_schedule(periph, priority);
1034 /* Set supported bits. */
1035 bzero(&cts, sizeof(cts));
1036 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1037 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1038 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1039 xpt_action((union ccb *)&cts);
1040 if (path->device->transport == XPORT_SATA &&
1041 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1042 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1043 else if (path->device->transport == XPORT_ATA &&
1044 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1045 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1048 if (path->device->transport == XPORT_SATA &&
1049 ident_buf->satacapabilities != 0xffff) {
1050 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1051 caps |= CTS_SATA_CAPS_D_PMREQ;
1052 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1053 caps |= CTS_SATA_CAPS_D_APST;
1055 /* Mask unwanted bits. */
1056 bzero(&cts, sizeof(cts));
1057 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1058 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1059 cts.type = CTS_TYPE_USER_SETTINGS;
1060 xpt_action((union ccb *)&cts);
1061 if (path->device->transport == XPORT_SATA &&
1062 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1063 caps &= cts.xport_specific.sata.caps;
1064 else if (path->device->transport == XPORT_ATA &&
1065 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1066 caps &= cts.xport_specific.ata.caps;
1070 * Remember what transport thinks about 48-bit DMA. If
1071 * capability information is not provided or transport is
1072 * SATA, we take support for granted.
1074 oif = path->device->inq_flags;
1075 if (!(path->device->inq_flags & SID_DMA) ||
1076 (path->device->transport == XPORT_ATA &&
1077 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1078 !(caps & CTS_ATA_CAPS_H_DMA48)))
1079 path->device->inq_flags &= ~SID_DMA48;
1081 path->device->inq_flags |= SID_DMA48;
1082 if (path->device->inq_flags != oif)
1083 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1084 /* Store result to SIM. */
1085 bzero(&cts, sizeof(cts));
1086 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1087 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1088 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1089 if (path->device->transport == XPORT_SATA) {
1090 cts.xport_specific.sata.caps = caps;
1091 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1093 cts.xport_specific.ata.caps = caps;
1094 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1096 xpt_action((union ccb *)&cts);
1098 if (path->device->transport != XPORT_SATA)
1100 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1101 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1102 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1103 PROBE_SET_ACTION(softc, PROBE_SETPM);
1104 xpt_release_ccb(done_ccb);
1105 xpt_schedule(periph, priority);
1110 if (ident_buf->satacapabilities != 0xffff &&
1111 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1112 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1113 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1114 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1115 xpt_release_ccb(done_ccb);
1116 xpt_schedule(periph, priority);
1121 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1122 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1123 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1124 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1125 xpt_release_ccb(done_ccb);
1126 xpt_schedule(periph, priority);
1130 case PROBE_SETDMAAA:
1131 if (path->device->protocol != PROTO_ATA &&
1132 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1133 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1134 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1135 PROBE_SET_ACTION(softc, PROBE_SETAN);
1136 xpt_release_ccb(done_ccb);
1137 xpt_schedule(periph, priority);
1143 if (path->device->protocol == PROTO_ATA) {
1144 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1146 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1148 xpt_release_ccb(done_ccb);
1149 xpt_schedule(periph, priority);
1151 case PROBE_SET_MULTI:
1152 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1153 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1154 xpt_acquire_device(path->device);
1155 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1156 xpt_action(done_ccb);
1157 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1159 PROBE_SET_ACTION(softc, PROBE_DONE);
1162 case PROBE_FULL_INQUIRY:
1164 u_int8_t periph_qual, len;
1166 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1168 periph_qual = SID_QUAL(inq_buf);
1170 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1171 periph_qual != SID_QUAL_LU_OFFLINE)
1175 * We conservatively request only
1176 * SHORT_INQUIRY_LEN bytes of inquiry
1177 * information during our first try
1178 * at sending an INQUIRY. If the device
1179 * has more information to give,
1180 * perform a second request specifying
1181 * the amount of information the device
1182 * is willing to give.
1184 len = inq_buf->additional_length
1185 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1186 if (softc->action == PROBE_INQUIRY
1187 && len > SHORT_INQUIRY_LENGTH) {
1188 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1189 xpt_release_ccb(done_ccb);
1190 xpt_schedule(periph, priority);
1194 ata_device_transport(path);
1195 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1196 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1197 xpt_acquire_device(path->device);
1198 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1199 xpt_action(done_ccb);
1200 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1202 PROBE_SET_ACTION(softc, PROBE_DONE);
1206 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1207 bzero(ident_buf, sizeof(*ident_buf));
1208 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1209 (done_ccb->ataio.res.lba_mid << 16) +
1210 (done_ccb->ataio.res.lba_low << 8) +
1211 done_ccb->ataio.res.sector_count;
1212 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1213 snprintf(ident_buf->model, sizeof(ident_buf->model),
1214 "Port Multiplier %08x", softc->pm_pid);
1215 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1216 xpt_release_ccb(done_ccb);
1217 xpt_schedule(periph, priority);
1220 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1221 (done_ccb->ataio.res.lba_mid << 16) +
1222 (done_ccb->ataio.res.lba_low << 8) +
1223 done_ccb->ataio.res.sector_count;
1224 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1225 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1226 "%04x", softc->pm_prv);
1227 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1228 ata_device_transport(path);
1229 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1230 aproberequestdefaultnegotiation(periph);
1231 /* Set supported bits. */
1232 bzero(&cts, sizeof(cts));
1233 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1234 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1235 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1236 xpt_action((union ccb *)&cts);
1237 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1238 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1241 /* All PMPs must support PM requests. */
1242 caps |= CTS_SATA_CAPS_D_PMREQ;
1243 /* Mask unwanted bits. */
1244 bzero(&cts, sizeof(cts));
1245 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1246 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1247 cts.type = CTS_TYPE_USER_SETTINGS;
1248 xpt_action((union ccb *)&cts);
1249 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1250 caps &= cts.xport_specific.sata.caps;
1253 /* Remember what transport thinks about AEN. */
1254 oif = path->device->inq_flags;
1255 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1256 path->device->inq_flags |= SID_AEN;
1258 path->device->inq_flags &= ~SID_AEN;
1259 /* Store result to SIM. */
1260 bzero(&cts, sizeof(cts));
1261 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1262 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1263 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1264 cts.xport_specific.sata.caps = caps;
1265 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1266 xpt_action((union ccb *)&cts);
1268 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1269 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1270 xpt_acquire_device(path->device);
1271 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1272 xpt_action(done_ccb);
1273 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1275 if (path->device->inq_flags != oif)
1276 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1277 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1278 xpt_action(done_ccb);
1279 xpt_async(AC_SCSI_AEN, path, done_ccb);
1281 PROBE_SET_ACTION(softc, PROBE_DONE);
1283 case PROBE_IDENTIFY_SES:
1284 case PROBE_IDENTIFY_SAFTE:
1285 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1286 /* Check that it is the same device. */
1287 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1288 /* Device changed. */
1290 xpt_async(AC_LOST_DEVICE, path, NULL);
1292 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1298 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1299 /* Clean up from previous instance of this device */
1300 if (path->device->device_id != NULL) {
1301 free(path->device->device_id, M_CAMXPT);
1302 path->device->device_id = NULL;
1303 path->device->device_id_len = 0;
1305 path->device->device_id =
1306 malloc(16, M_CAMXPT, M_NOWAIT);
1307 if (path->device->device_id != NULL) {
1308 path->device->device_id_len = 16;
1309 bcopy(&fake_device_id_hdr,
1310 path->device->device_id, 8);
1311 bcopy(((uint8_t*)ident_buf) + 2,
1312 path->device->device_id + 8, 8);
1315 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1317 ata_device_transport(path);
1319 aproberequestdefaultnegotiation(periph);
1321 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1322 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1323 xpt_acquire_device(path->device);
1324 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1325 xpt_action(done_ccb);
1326 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1328 PROBE_SET_ACTION(softc, PROBE_DONE);
1331 panic("aprobedone: invalid action state 0x%x\n", softc->action);
1334 if (softc->restart) {
1336 xpt_release_ccb(done_ccb);
1337 aprobeschedule(periph);
1340 xpt_release_ccb(done_ccb);
1341 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1342 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1343 TAILQ_REMOVE(&softc->request_ccbs,
1344 &done_ccb->ccb_h, periph_links.tqe);
1345 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1348 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1349 cam_release_devq(path, 0, 0, 0, FALSE);
1350 cam_periph_invalidate(periph);
1351 cam_periph_release_locked(periph);
1355 aprobecleanup(struct cam_periph *periph)
1357 free(periph->softc, M_CAMXPT);
1361 ata_find_quirk(struct cam_ed *device)
1363 struct ata_quirk_entry *quirk;
1366 match = cam_quirkmatch((caddr_t)&device->ident_data,
1367 (caddr_t)ata_quirk_table,
1368 nitems(ata_quirk_table),
1369 sizeof(*ata_quirk_table), ata_identify_match);
1372 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1374 quirk = (struct ata_quirk_entry *)match;
1375 device->quirk = quirk;
1376 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1377 device->mintags = quirk->mintags;
1378 device->maxtags = quirk->maxtags;
1383 union ccb *request_ccb;
1384 struct ccb_pathinq *cpi;
1386 } ata_scan_bus_info;
1389 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1390 * As the scan progresses, xpt_scan_bus is used as the
1391 * callback on completion function.
1394 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1396 struct cam_path *path;
1397 ata_scan_bus_info *scan_info;
1398 union ccb *work_ccb, *reset_ccb;
1402 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1403 ("xpt_scan_bus\n"));
1404 switch (request_ccb->ccb_h.func_code) {
1407 /* Find out the characteristics of the bus */
1408 work_ccb = xpt_alloc_ccb_nowait();
1409 if (work_ccb == NULL) {
1410 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1411 xpt_done(request_ccb);
1414 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1415 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1416 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1417 xpt_free_ccb(work_ccb);
1418 xpt_done(request_ccb);
1422 /* We may need to reset bus first, if we haven't done it yet. */
1423 if ((work_ccb->cpi.hba_inquiry &
1424 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1425 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1426 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1427 reset_ccb = xpt_alloc_ccb_nowait();
1428 if (reset_ccb == NULL) {
1429 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1430 xpt_free_ccb(work_ccb);
1431 xpt_done(request_ccb);
1434 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1436 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1437 xpt_action(reset_ccb);
1438 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1439 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1440 xpt_free_ccb(reset_ccb);
1441 xpt_free_ccb(work_ccb);
1442 xpt_done(request_ccb);
1445 xpt_free_ccb(reset_ccb);
1448 /* Save some state for use while we probe for devices */
1449 scan_info = (ata_scan_bus_info *)
1450 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1451 if (scan_info == NULL) {
1452 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1453 xpt_free_ccb(work_ccb);
1454 xpt_done(request_ccb);
1457 scan_info->request_ccb = request_ccb;
1458 scan_info->cpi = &work_ccb->cpi;
1459 /* If PM supported, probe it first. */
1460 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1461 scan_info->counter = scan_info->cpi->max_target;
1463 scan_info->counter = 0;
1465 work_ccb = xpt_alloc_ccb_nowait();
1466 if (work_ccb == NULL) {
1467 free(scan_info, M_CAMXPT);
1468 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1469 xpt_done(request_ccb);
1472 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1475 work_ccb = request_ccb;
1476 /* Reuse the same CCB to query if a device was really found */
1477 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1478 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1480 /* If there is PMP... */
1481 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1482 (scan_info->counter == scan_info->cpi->max_target)) {
1483 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1484 /* everything else will be probed by it */
1485 /* Free the current request path- we're done with it. */
1486 xpt_free_path(work_ccb->ccb_h.path);
1489 struct ccb_trans_settings cts;
1491 /* Report SIM that PM is absent. */
1492 bzero(&cts, sizeof(cts));
1493 xpt_setup_ccb(&cts.ccb_h,
1494 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1495 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1496 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1497 cts.xport_specific.sata.pm_present = 0;
1498 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1499 xpt_action((union ccb *)&cts);
1502 /* Free the current request path- we're done with it. */
1503 xpt_free_path(work_ccb->ccb_h.path);
1504 if (scan_info->counter ==
1505 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1506 0 : scan_info->cpi->max_target)) {
1509 xpt_free_ccb(work_ccb);
1510 xpt_free_ccb((union ccb *)scan_info->cpi);
1511 request_ccb = scan_info->request_ccb;
1512 free(scan_info, M_CAMXPT);
1513 request_ccb->ccb_h.status = CAM_REQ_CMP;
1514 xpt_done(request_ccb);
1517 /* Take next device. Wrap from max (PMP) to 0. */
1518 scan_info->counter = (scan_info->counter + 1 ) %
1519 (scan_info->cpi->max_target + 1);
1521 status = xpt_create_path(&path, NULL,
1522 scan_info->request_ccb->ccb_h.path_id,
1523 scan_info->counter, 0);
1524 if (status != CAM_REQ_CMP) {
1525 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1527 printf("xpt_scan_bus: xpt_create_path failed"
1528 " with status %#x, bus scan halted\n",
1530 xpt_free_ccb(work_ccb);
1531 xpt_free_ccb((union ccb *)scan_info->cpi);
1532 request_ccb = scan_info->request_ccb;
1533 free(scan_info, M_CAMXPT);
1534 request_ccb->ccb_h.status = status;
1535 xpt_done(request_ccb);
1538 xpt_setup_ccb(&work_ccb->ccb_h, path,
1539 scan_info->request_ccb->ccb_h.pinfo.priority);
1540 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1541 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1542 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1543 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1544 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1546 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1548 xpt_action(work_ccb);
1558 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1559 cam_flags flags, union ccb *request_ccb)
1561 struct ccb_pathinq cpi;
1563 struct cam_path *new_path;
1564 struct cam_periph *old_periph;
1567 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1569 xpt_path_inq(&cpi, path);
1570 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1571 if (request_ccb != NULL) {
1572 request_ccb->ccb_h.status = cpi.ccb_h.status;
1573 xpt_done(request_ccb);
1578 if (request_ccb == NULL) {
1579 request_ccb = xpt_alloc_ccb_nowait();
1580 if (request_ccb == NULL) {
1581 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1582 "can't continue\n");
1585 status = xpt_create_path(&new_path, NULL,
1587 path->target->target_id,
1588 path->device->lun_id);
1589 if (status != CAM_REQ_CMP) {
1590 xpt_print(path, "xpt_scan_lun: can't create path, "
1591 "can't continue\n");
1592 xpt_free_ccb(request_ccb);
1595 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1596 request_ccb->ccb_h.cbfcnp = axptscandone;
1597 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1598 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1599 request_ccb->crcn.flags = flags;
1602 lock = (xpt_path_owned(path) == 0);
1604 xpt_path_lock(path);
1605 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1606 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1609 softc = (probe_softc *)old_periph->softc;
1610 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1611 &request_ccb->ccb_h, periph_links.tqe);
1614 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1615 xpt_done(request_ccb);
1618 status = cam_periph_alloc(aproberegister, NULL, aprobecleanup,
1619 aprobestart, "aprobe",
1621 request_ccb->ccb_h.path, NULL, 0,
1624 if (status != CAM_REQ_CMP) {
1625 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1626 "returned an error, can't continue probe\n");
1627 request_ccb->ccb_h.status = status;
1628 xpt_done(request_ccb);
1632 xpt_path_unlock(path);
1636 axptscandone(struct cam_periph *periph, union ccb *done_ccb)
1639 xpt_free_path(done_ccb->ccb_h.path);
1640 xpt_free_ccb(done_ccb);
1643 static struct cam_ed *
1644 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1646 struct ata_quirk_entry *quirk;
1647 struct cam_ed *device;
1649 device = xpt_alloc_device(bus, target, lun_id);
1654 * Take the default quirk entry until we have inquiry
1655 * data and can determine a better quirk to use.
1657 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1658 device->quirk = (void *)quirk;
1659 device->mintags = 0;
1660 device->maxtags = 0;
1661 bzero(&device->inq_data, sizeof(device->inq_data));
1662 device->inq_flags = 0;
1663 device->queue_flags = 0;
1664 device->serial_num = NULL;
1665 device->serial_num_len = 0;
1670 ata_device_transport(struct cam_path *path)
1672 struct ccb_pathinq cpi;
1673 struct ccb_trans_settings cts;
1674 struct scsi_inquiry_data *inq_buf = NULL;
1675 struct ata_params *ident_buf = NULL;
1677 /* Get transport information from the SIM */
1678 xpt_path_inq(&cpi, path);
1680 path->device->transport = cpi.transport;
1681 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1682 inq_buf = &path->device->inq_data;
1683 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1684 ident_buf = &path->device->ident_data;
1685 if (path->device->protocol == PROTO_ATA) {
1686 path->device->protocol_version = ident_buf ?
1687 ata_version(ident_buf->version_major) : cpi.protocol_version;
1688 } else if (path->device->protocol == PROTO_SCSI) {
1689 path->device->protocol_version = inq_buf ?
1690 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1692 path->device->transport_version = ident_buf ?
1693 ata_version(ident_buf->version_major) : cpi.transport_version;
1695 /* Tell the controller what we think */
1696 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1697 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1698 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1699 cts.transport = path->device->transport;
1700 cts.transport_version = path->device->transport_version;
1701 cts.protocol = path->device->protocol;
1702 cts.protocol_version = path->device->protocol_version;
1703 cts.proto_specific.valid = 0;
1705 if (path->device->transport == XPORT_ATA) {
1706 cts.xport_specific.ata.atapi =
1707 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1708 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1709 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1710 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1712 cts.xport_specific.sata.atapi =
1713 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1714 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1715 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1716 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1719 cts.xport_specific.valid = 0;
1720 xpt_action((union ccb *)&cts);
1724 ata_dev_advinfo(union ccb *start_ccb)
1726 struct cam_ed *device;
1727 struct ccb_dev_advinfo *cdai;
1730 xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
1731 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1732 device = start_ccb->ccb_h.path->device;
1733 cdai = &start_ccb->cdai;
1734 switch(cdai->buftype) {
1735 case CDAI_TYPE_SCSI_DEVID:
1736 if (cdai->flags & CDAI_FLAG_STORE)
1738 cdai->provsiz = device->device_id_len;
1739 if (device->device_id_len == 0)
1741 amt = device->device_id_len;
1742 if (cdai->provsiz > cdai->bufsiz)
1744 memcpy(cdai->buf, device->device_id, amt);
1746 case CDAI_TYPE_SERIAL_NUM:
1747 if (cdai->flags & CDAI_FLAG_STORE)
1749 cdai->provsiz = device->serial_num_len;
1750 if (device->serial_num_len == 0)
1752 amt = device->serial_num_len;
1753 if (cdai->provsiz > cdai->bufsiz)
1755 memcpy(cdai->buf, device->serial_num, amt);
1757 case CDAI_TYPE_PHYS_PATH:
1758 if (cdai->flags & CDAI_FLAG_STORE) {
1759 if (device->physpath != NULL)
1760 free(device->physpath, M_CAMXPT);
1761 device->physpath_len = cdai->bufsiz;
1762 /* Clear existing buffer if zero length */
1763 if (cdai->bufsiz == 0)
1765 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1766 if (device->physpath == NULL) {
1767 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1770 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1772 cdai->provsiz = device->physpath_len;
1773 if (device->physpath_len == 0)
1775 amt = device->physpath_len;
1776 if (cdai->provsiz > cdai->bufsiz)
1778 memcpy(cdai->buf, device->physpath, amt);
1784 start_ccb->ccb_h.status = CAM_REQ_CMP;
1786 if (cdai->flags & CDAI_FLAG_STORE) {
1787 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1788 (void *)(uintptr_t)cdai->buftype);
1793 ata_action(union ccb *start_ccb)
1796 switch (start_ccb->ccb_h.func_code) {
1797 case XPT_SET_TRAN_SETTINGS:
1799 ata_set_transfer_settings(&start_ccb->cts,
1800 start_ccb->ccb_h.path,
1801 /*async_update*/FALSE);
1806 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1809 ata_scan_lun(start_ccb->ccb_h.path->periph,
1810 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1813 case XPT_GET_TRAN_SETTINGS:
1815 ata_get_transfer_settings(&start_ccb->cts);
1820 struct cam_ed *device;
1823 device = start_ccb->ccb_h.path->device;
1824 if (device->protocol == PROTO_SCSI &&
1825 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1827 device->ident_data.config & ATA_PROTO_MASK;
1830 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1831 (p == ATA_PROTO_ATAPI_16) ? 16 :
1832 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1834 if (start_ccb->csio.cdb_len > maxlen) {
1835 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1836 xpt_done(start_ccb);
1839 xpt_action_default(start_ccb);
1842 case XPT_DEV_ADVINFO:
1844 ata_dev_advinfo(start_ccb);
1848 xpt_action_default(start_ccb);
1854 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1856 struct ccb_trans_settings_ata *ata;
1857 struct ccb_trans_settings_scsi *scsi;
1858 struct cam_ed *device;
1860 device = cts->ccb_h.path->device;
1861 xpt_action_default((union ccb *)cts);
1863 if (cts->protocol == PROTO_UNKNOWN ||
1864 cts->protocol == PROTO_UNSPECIFIED) {
1865 cts->protocol = device->protocol;
1866 cts->protocol_version = device->protocol_version;
1869 if (cts->protocol == PROTO_ATA) {
1870 ata = &cts->proto_specific.ata;
1871 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1872 ata->valid |= CTS_ATA_VALID_TQ;
1873 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1874 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1875 (device->inq_flags & SID_CmdQue) != 0)
1876 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1879 if (cts->protocol == PROTO_SCSI) {
1880 scsi = &cts->proto_specific.scsi;
1881 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1882 scsi->valid |= CTS_SCSI_VALID_TQ;
1883 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1884 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1885 (device->inq_flags & SID_CmdQue) != 0)
1886 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1890 if (cts->transport == XPORT_UNKNOWN ||
1891 cts->transport == XPORT_UNSPECIFIED) {
1892 cts->transport = device->transport;
1893 cts->transport_version = device->transport_version;
1898 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1901 struct ccb_pathinq cpi;
1902 struct ccb_trans_settings_ata *ata;
1903 struct ccb_trans_settings_scsi *scsi;
1904 struct ata_params *ident_data;
1905 struct scsi_inquiry_data *inq_data;
1906 struct cam_ed *device;
1908 if (path == NULL || (device = path->device) == NULL) {
1909 cts->ccb_h.status = CAM_PATH_INVALID;
1910 xpt_done((union ccb *)cts);
1914 if (cts->protocol == PROTO_UNKNOWN
1915 || cts->protocol == PROTO_UNSPECIFIED) {
1916 cts->protocol = device->protocol;
1917 cts->protocol_version = device->protocol_version;
1920 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1921 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1922 cts->protocol_version = device->protocol_version;
1924 if (cts->protocol != device->protocol) {
1925 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1926 cts->protocol, device->protocol);
1927 cts->protocol = device->protocol;
1930 if (cts->protocol_version > device->protocol_version) {
1932 xpt_print(path, "Down reving Protocol "
1933 "Version from %d to %d?\n", cts->protocol_version,
1934 device->protocol_version);
1936 cts->protocol_version = device->protocol_version;
1939 if (cts->transport == XPORT_UNKNOWN
1940 || cts->transport == XPORT_UNSPECIFIED) {
1941 cts->transport = device->transport;
1942 cts->transport_version = device->transport_version;
1945 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1946 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1947 cts->transport_version = device->transport_version;
1949 if (cts->transport != device->transport) {
1950 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1951 cts->transport, device->transport);
1952 cts->transport = device->transport;
1955 if (cts->transport_version > device->transport_version) {
1957 xpt_print(path, "Down reving Transport "
1958 "Version from %d to %d?\n", cts->transport_version,
1959 device->transport_version);
1961 cts->transport_version = device->transport_version;
1964 ident_data = &device->ident_data;
1965 inq_data = &device->inq_data;
1966 if (cts->protocol == PROTO_ATA)
1967 ata = &cts->proto_specific.ata;
1970 if (cts->protocol == PROTO_SCSI)
1971 scsi = &cts->proto_specific.scsi;
1974 xpt_path_inq(&cpi, path);
1976 /* Sanity checking */
1977 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1978 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1979 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1980 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1981 || (device->mintags == 0)) {
1983 * Can't tag on hardware that doesn't support tags,
1984 * doesn't have it enabled, or has broken tag support.
1987 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1989 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1992 /* Start/stop tags use. */
1993 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1994 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1995 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1998 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1999 (device->inq_flags & SID_CmdQue) != 0);
2001 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
2003 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2005 if (newt && !nowt) {
2007 * Delay change to use tags until after a
2008 * few commands have gone to this device so
2009 * the controller has time to perform transfer
2010 * negotiations without tagged messages getting
2013 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2014 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2015 } else if (nowt && !newt)
2016 xpt_stop_tags(path);
2019 if (async_update == FALSE)
2020 xpt_action_default((union ccb *)cts);
2024 * Handle any per-device event notifications that require action by the XPT.
2027 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2028 struct cam_ed *device, void *async_arg)
2031 struct cam_path newpath;
2034 * We only need to handle events for real devices.
2036 if (target->target_id == CAM_TARGET_WILDCARD
2037 || device->lun_id == CAM_LUN_WILDCARD)
2041 * We need our own path with wildcards expanded to
2042 * handle certain types of events.
2044 if ((async_code == AC_SENT_BDR)
2045 || (async_code == AC_BUS_RESET)
2046 || (async_code == AC_INQ_CHANGED))
2047 status = xpt_compile_path(&newpath, NULL,
2052 status = CAM_REQ_CMP_ERR;
2054 if (status == CAM_REQ_CMP) {
2055 if (async_code == AC_INQ_CHANGED) {
2057 * We've sent a start unit command, or
2058 * something similar to a device that
2059 * may have caused its inquiry data to
2060 * change. So we re-scan the device to
2061 * refresh the inquiry data for it.
2063 ata_scan_lun(newpath.periph, &newpath,
2064 CAM_EXPECT_INQ_CHANGE, NULL);
2066 /* We need to reinitialize device after reset. */
2067 ata_scan_lun(newpath.periph, &newpath,
2070 xpt_release_path(&newpath);
2071 } else if (async_code == AC_LOST_DEVICE &&
2072 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2073 device->flags |= CAM_DEV_UNCONFIGURED;
2074 xpt_release_device(device);
2075 } else if (async_code == AC_TRANSFER_NEG) {
2076 struct ccb_trans_settings *settings;
2077 struct cam_path path;
2079 settings = (struct ccb_trans_settings *)async_arg;
2080 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2082 ata_set_transfer_settings(settings, &path,
2083 /*async_update*/TRUE);
2084 xpt_release_path(&path);
2089 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2091 struct ccb_pathinq cpi;
2092 struct cam_path *path = periph->path;
2094 cam_periph_assert(periph, MA_OWNED);
2096 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2097 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2098 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2099 xpt_action((union ccb*)cts);
2100 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2102 /* Ask the SIM for its base transfer speed */
2103 xpt_path_inq(&cpi, path);
2104 /* Report connection speed */
2105 *speed = cpi.base_transfer_speed;
2106 if (cts->transport == XPORT_ATA) {
2107 struct ccb_trans_settings_pata *pata =
2108 &cts->xport_specific.ata;
2110 if (pata->valid & CTS_ATA_VALID_MODE)
2111 *speed = ata_mode2speed(pata->mode);
2113 if (cts->transport == XPORT_SATA) {
2114 struct ccb_trans_settings_sata *sata =
2115 &cts->xport_specific.sata;
2117 if (sata->valid & CTS_SATA_VALID_REVISION)
2118 *speed = ata_revision2speed(sata->revision);
2123 ata_announce_periph(struct cam_periph *periph)
2125 struct ccb_trans_settings cts;
2128 _ata_announce_periph(periph, &cts, &speed);
2129 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2134 printf("%s%d: %d.%03dMB/s transfers",
2135 periph->periph_name, periph->unit_number,
2138 printf("%s%d: %dKB/s transfers", periph->periph_name,
2139 periph->unit_number, speed);
2140 /* Report additional information about connection */
2141 if (cts.transport == XPORT_ATA) {
2142 struct ccb_trans_settings_pata *pata =
2143 &cts.xport_specific.ata;
2146 if (pata->valid & CTS_ATA_VALID_MODE)
2147 printf("%s, ", ata_mode2string(pata->mode));
2148 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2149 printf("ATAPI %dbytes, ", pata->atapi);
2150 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2151 printf("PIO %dbytes", pata->bytecount);
2154 if (cts.transport == XPORT_SATA) {
2155 struct ccb_trans_settings_sata *sata =
2156 &cts.xport_specific.sata;
2159 if (sata->valid & CTS_SATA_VALID_REVISION)
2160 printf("SATA %d.x, ", sata->revision);
2163 if (sata->valid & CTS_SATA_VALID_MODE)
2164 printf("%s, ", ata_mode2string(sata->mode));
2165 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2166 printf("ATAPI %dbytes, ", sata->atapi);
2167 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2168 printf("PIO %dbytes", sata->bytecount);
2175 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2177 struct ccb_trans_settings cts;
2180 _ata_announce_periph(periph, &cts, &speed);
2181 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2186 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2187 periph->periph_name, periph->unit_number,
2190 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2191 periph->unit_number, speed);
2192 /* Report additional information about connection */
2193 if (cts.transport == XPORT_ATA) {
2194 struct ccb_trans_settings_pata *pata =
2195 &cts.xport_specific.ata;
2197 sbuf_printf(sb, " (");
2198 if (pata->valid & CTS_ATA_VALID_MODE)
2199 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2200 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2201 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2202 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2203 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2204 sbuf_printf(sb, ")");
2206 if (cts.transport == XPORT_SATA) {
2207 struct ccb_trans_settings_sata *sata =
2208 &cts.xport_specific.sata;
2210 sbuf_printf(sb, " (");
2211 if (sata->valid & CTS_SATA_VALID_REVISION)
2212 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2214 sbuf_printf(sb, "SATA, ");
2215 if (sata->valid & CTS_SATA_VALID_MODE)
2216 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2217 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2218 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2219 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2220 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2221 sbuf_printf(sb, ")");
2223 sbuf_printf(sb, "\n");
2227 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2229 ata_print_ident_sbuf(&device->ident_data, sb);
2233 ata_proto_announce(struct cam_ed *device)
2235 ata_print_ident(&device->ident_data);
2239 ata_proto_denounce(struct cam_ed *device)
2241 ata_print_ident_short(&device->ident_data);
2245 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2247 ata_print_ident_short_sbuf(&device->ident_data, sb);
2251 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2253 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2257 semb_proto_announce(struct cam_ed *device)
2259 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2263 semb_proto_denounce(struct cam_ed *device)
2265 semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
2269 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2271 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2275 ata_proto_debug_out(union ccb *ccb)
2277 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2279 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2282 CAM_DEBUG(ccb->ccb_h.path,
2283 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2284 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));